Skip to content

Commit

Permalink
Fixed various warnings and errors when compiling NVRHI with Clang on …
Browse files Browse the repository at this point in the history
…Windows.
  • Loading branch information
apanteleev committed Jul 3, 2024
1 parent 6945d2a commit 55b0dd4
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 109 deletions.
2 changes: 0 additions & 2 deletions include/nvrhi/common/containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ struct static_vector : private std::array<T, _max_elements>
assert(size <= max_elements);
}

static_vector(const static_vector& other) = default;

static_vector(std::initializer_list<T> il)
: current_size(0)
{
Expand Down
76 changes: 2 additions & 74 deletions src/d3d11/d3d11-graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ namespace nvrhi::d3d11
arraysAreDifferent(m_CurrentViewports.scissorRects, state.viewport.scissorRects);

const bool updateBlendState = !m_CurrentGraphicsStateValid ||
pipeline->requiresBlendFactor && state.blendConstantColor != m_CurrentBlendConstantColor;
(pipeline->requiresBlendFactor && state.blendConstantColor != m_CurrentBlendConstantColor);
const bool updateStencilRef = !m_CurrentGraphicsStateValid ||
pipeline->desc.renderState.depthStencilState.dynamicStencilRef && state.dynamicStencilRefValue != m_CurrentStencilRefValue;
(pipeline->desc.renderState.depthStencilState.dynamicStencilRef && state.dynamicStencilRefValue != m_CurrentStencilRefValue);

const bool updateIndexBuffer = !m_CurrentGraphicsStateValid || m_CurrentIndexBufferBinding != state.indexBuffer;
const bool updateVertexBuffers = !m_CurrentGraphicsStateValid || arraysAreDifferent(m_CurrentVertexBufferBindings, state.vertexBuffers);
Expand Down Expand Up @@ -406,78 +406,6 @@ namespace nvrhi::d3d11
}
}

namespace
{
//Unfortunately we can't memcmp the structs since they have padding bytes in them
inline bool operator!=(const D3D11_RENDER_TARGET_BLEND_DESC& lhsrt, const D3D11_RENDER_TARGET_BLEND_DESC& rhsrt)
{
if (lhsrt.BlendEnable != rhsrt.BlendEnable ||
lhsrt.SrcBlend != rhsrt.SrcBlend ||
lhsrt.DestBlend != rhsrt.DestBlend ||
lhsrt.BlendOp != rhsrt.BlendOp ||
lhsrt.SrcBlendAlpha != rhsrt.SrcBlendAlpha ||
lhsrt.DestBlendAlpha != rhsrt.DestBlendAlpha ||
lhsrt.BlendOpAlpha != rhsrt.BlendOpAlpha ||
lhsrt.RenderTargetWriteMask != rhsrt.RenderTargetWriteMask)
return true;
return false;
}

inline bool operator!=(const D3D11_BLEND_DESC& lhs, const D3D11_BLEND_DESC& rhs)
{
if (lhs.AlphaToCoverageEnable != rhs.AlphaToCoverageEnable ||
lhs.IndependentBlendEnable != rhs.IndependentBlendEnable)
return true;
for (size_t i = 0; i < sizeof(lhs.RenderTarget) / sizeof(lhs.RenderTarget[0]); i++)
{
if (lhs.RenderTarget[i] != rhs.RenderTarget[i])
return true;
}
return false;
}

inline bool operator!=(const D3D11_RASTERIZER_DESC& lhs, const D3D11_RASTERIZER_DESC& rhs)
{
if (lhs.FillMode != rhs.FillMode ||
lhs.CullMode != rhs.CullMode ||
lhs.FrontCounterClockwise != rhs.FrontCounterClockwise ||
lhs.DepthBias != rhs.DepthBias ||
lhs.DepthBiasClamp != rhs.DepthBiasClamp ||
lhs.SlopeScaledDepthBias != rhs.SlopeScaledDepthBias ||
lhs.DepthClipEnable != rhs.DepthClipEnable ||
lhs.ScissorEnable != rhs.ScissorEnable ||
lhs.MultisampleEnable != rhs.MultisampleEnable ||
lhs.AntialiasedLineEnable != rhs.AntialiasedLineEnable)
return true;

return false;
}

inline bool operator!=(const D3D11_DEPTH_STENCILOP_DESC& lhs, const D3D11_DEPTH_STENCILOP_DESC& rhs)
{
if (lhs.StencilFailOp != rhs.StencilFailOp ||
lhs.StencilDepthFailOp != rhs.StencilDepthFailOp ||
lhs.StencilPassOp != rhs.StencilPassOp ||
lhs.StencilFunc != rhs.StencilFunc)
return true;
return false;
}
inline bool operator!=(const D3D11_DEPTH_STENCIL_DESC& lhs, const D3D11_DEPTH_STENCIL_DESC& rhs)
{
if (lhs.DepthEnable != rhs.DepthEnable ||
lhs.DepthWriteMask != rhs.DepthWriteMask ||
lhs.DepthFunc != rhs.DepthFunc ||
lhs.StencilEnable != rhs.StencilEnable ||
lhs.StencilReadMask != rhs.StencilReadMask ||
lhs.StencilWriteMask != rhs.StencilWriteMask ||
lhs.FrontFace != rhs.FrontFace ||
lhs.FrontFace != rhs.BackFace)
return true;

return false;
}
}

ID3D11BlendState* Device::getBlendState(const BlendState& blendState)
{
size_t hash = 0;
Expand Down
24 changes: 24 additions & 0 deletions src/d3d11/d3d11-resource-bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,49 +333,69 @@ void CommandList::bindGraphicsResourceSets(
if ((stagesToBind & ShaderType::Vertex) != 0)
{
if (m_Context.immediateContext1)
{
D3D11_SET_ARRAY1(VSSetConstantBuffers1, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers, set->constantBufferOffsets, set->constantBufferCounts);
}
else
{
D3D11_SET_ARRAY(VSSetConstantBuffers, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers);
}
D3D11_SET_ARRAY(VSSetShaderResources, set->minSRVSlot, set->maxSRVSlot, set->SRVs);
D3D11_SET_ARRAY(VSSetSamplers, set->minSamplerSlot, set->maxSamplerSlot, set->samplers);
}

if ((stagesToBind & ShaderType::Hull) != 0)
{
if (m_Context.immediateContext1)
{
D3D11_SET_ARRAY1(HSSetConstantBuffers1, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers, set->constantBufferOffsets, set->constantBufferCounts);
}
else
{
D3D11_SET_ARRAY(HSSetConstantBuffers, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers);
}
D3D11_SET_ARRAY(HSSetShaderResources, set->minSRVSlot, set->maxSRVSlot, set->SRVs);
D3D11_SET_ARRAY(HSSetSamplers, set->minSamplerSlot, set->maxSamplerSlot, set->samplers);
}

if ((stagesToBind & ShaderType::Domain) != 0)
{
if (m_Context.immediateContext1)
{
D3D11_SET_ARRAY1(DSSetConstantBuffers1, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers, set->constantBufferOffsets, set->constantBufferCounts);
}
else
{
D3D11_SET_ARRAY(DSSetConstantBuffers, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers);
}
D3D11_SET_ARRAY(DSSetShaderResources, set->minSRVSlot, set->maxSRVSlot, set->SRVs);
D3D11_SET_ARRAY(DSSetSamplers, set->minSamplerSlot, set->maxSamplerSlot, set->samplers);
}

if ((stagesToBind & ShaderType::Geometry) != 0)
{
if (m_Context.immediateContext1)
{
D3D11_SET_ARRAY1(GSSetConstantBuffers1, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers, set->constantBufferOffsets, set->constantBufferCounts);
}
else
{
D3D11_SET_ARRAY(GSSetConstantBuffers, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers);
}
D3D11_SET_ARRAY(GSSetShaderResources, set->minSRVSlot, set->maxSRVSlot, set->SRVs);
D3D11_SET_ARRAY(GSSetSamplers, set->minSamplerSlot, set->maxSamplerSlot, set->samplers);
}

if ((stagesToBind & ShaderType::Pixel) != 0)
{
if (m_Context.immediateContext1)
{
D3D11_SET_ARRAY1(PSSetConstantBuffers1, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers, set->constantBufferOffsets, set->constantBufferCounts);
}
else
{
D3D11_SET_ARRAY(PSSetConstantBuffers, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers);
}
D3D11_SET_ARRAY(PSSetShaderResources, set->minSRVSlot, set->maxSRVSlot, set->SRVs);
D3D11_SET_ARRAY(PSSetSamplers, set->minSamplerSlot, set->maxSamplerSlot, set->samplers);
}
Expand Down Expand Up @@ -458,9 +478,13 @@ void CommandList::bindComputeResourceSets(
continue;

if (m_Context.immediateContext1)
{
D3D11_SET_ARRAY1(CSSetConstantBuffers1, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers, set->constantBufferOffsets, set->constantBufferCounts);
}
else
{
D3D11_SET_ARRAY(CSSetConstantBuffers, set->minConstantBufferSlot, set->maxConstantBufferSlot, set->constantBuffers);
}
D3D11_SET_ARRAY(CSSetShaderResources, set->minSRVSlot, set->maxSRVSlot, set->SRVs);
D3D11_SET_ARRAY(CSSetSamplers, set->minSamplerSlot, set->maxSamplerSlot, set->samplers);

Expand Down
14 changes: 5 additions & 9 deletions src/d3d12/d3d12-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ namespace nvrhi::d3d12
struct Context;

typedef uint32_t RootParameterIndex;
typedef uint32_t OptionalResourceState; // D3D12_RESOURCE_STATES + unknown value

constexpr DescriptorIndex c_InvalidDescriptorIndex = ~0u;
constexpr D3D12_RESOURCE_STATES c_ResourceStateUnknown = D3D12_RESOURCE_STATES(~0u);
constexpr OptionalResourceState c_ResourceStateUnknown = ~0u;

D3D12_SHADER_VISIBILITY convertShaderStage(ShaderType s);
D3D12_BLEND convertBlendValue(BlendFactor value);
Expand All @@ -90,7 +91,6 @@ namespace nvrhi::d3d12
D3D12_SHADING_RATE_COMBINER convertShadingRateCombiner(ShadingRateCombiner combiner);

void WaitForFence(ID3D12Fence* fence, uint64_t value, HANDLE event);
bool IsBlendFactorRequired(BlendFactor value);
uint32_t calcSubresource(uint32_t MipSlice, uint32_t ArraySlice, uint32_t PlaneSlice, uint32_t MipLevels, uint32_t ArraySize);
void TranslateBlendState(const BlendState& inState, D3D12_BLEND_DESC& outState);
void TranslateDepthStencilState(const DepthStencilState& inState, D3D12_DEPTH_STENCIL_DESC& outState);
Expand Down Expand Up @@ -608,7 +608,7 @@ namespace nvrhi::d3d12
class TextureState
{
public:
std::vector<D3D12_RESOURCE_STATES> subresourceStates;
std::vector<OptionalResourceState> subresourceStates;
bool enableUavBarriers = true;
bool firstUavBarrierPlaced = false;
bool permanentTransition = false;
Expand All @@ -622,7 +622,7 @@ namespace nvrhi::d3d12
class BufferState
{
public:
D3D12_RESOURCE_STATES state = c_ResourceStateUnknown;
OptionalResourceState state = c_ResourceStateUnknown;
bool enableUavBarriers = true;
bool firstUavBarrierPlaced = false;
D3D12_GPU_VIRTUAL_ADDRESS volatileData = 0;
Expand Down Expand Up @@ -679,18 +679,14 @@ namespace nvrhi::d3d12
bool allowUpdate = false;
bool compacted = false;

OpacityMicromap(const Context& context)
: m_Context(context)
OpacityMicromap()
{ }

Object getNativeObject(ObjectType objectType) override;

const rt::OpacityMicromapDesc& getDesc() const override { return desc; }
bool isCompacted() const override { return compacted; }
uint64_t getDeviceAddress() const override;

private:
const Context& m_Context;
};

class AccelStruct : public RefCounter<rt::IAccelStruct>
Expand Down
3 changes: 3 additions & 0 deletions src/d3d12/d3d12-graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ namespace nvrhi::d3d12
break;
case PrimitiveType::TriangleList:
case PrimitiveType::TriangleStrip:
case PrimitiveType::TriangleFan:
case PrimitiveType::TriangleListWithAdjacency:
case PrimitiveType::TriangleStripWithAdjacency:
desc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
break;
case PrimitiveType::PatchList:
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ namespace nvrhi::d3d12
if (status != S_OK)
return nullptr;

OpacityMicromap* om = new OpacityMicromap(m_Context);
OpacityMicromap* om = new OpacityMicromap();
om->desc = desc;
om->compacted = false;

Expand Down
16 changes: 8 additions & 8 deletions src/d3d12/d3d12-resource-bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ namespace nvrhi::d3d12
a = GetNormalizedResourceType(a);
b = GetNormalizedResourceType(b);

if (a == ResourceType::TypedBuffer_SRV && b == ResourceType::Texture_SRV ||
b == ResourceType::TypedBuffer_SRV && a == ResourceType::Texture_SRV ||
a == ResourceType::TypedBuffer_SRV && b == ResourceType::RayTracingAccelStruct ||
a == ResourceType::Texture_SRV && b == ResourceType::RayTracingAccelStruct ||
b == ResourceType::TypedBuffer_SRV && a == ResourceType::RayTracingAccelStruct ||
b == ResourceType::Texture_SRV && a == ResourceType::RayTracingAccelStruct)
if ((a == ResourceType::TypedBuffer_SRV && b == ResourceType::Texture_SRV) ||
(b == ResourceType::TypedBuffer_SRV && a == ResourceType::Texture_SRV) ||
(a == ResourceType::TypedBuffer_SRV && b == ResourceType::RayTracingAccelStruct) ||
(a == ResourceType::Texture_SRV && b == ResourceType::RayTracingAccelStruct) ||
(b == ResourceType::TypedBuffer_SRV && a == ResourceType::RayTracingAccelStruct) ||
(b == ResourceType::Texture_SRV && a == ResourceType::RayTracingAccelStruct))
return true;

if (a == ResourceType::TypedBuffer_UAV && b == ResourceType::Texture_UAV ||
b == ResourceType::TypedBuffer_UAV && a == ResourceType::Texture_UAV)
if ((a == ResourceType::TypedBuffer_UAV && b == ResourceType::Texture_UAV) ||
(b == ResourceType::TypedBuffer_UAV && a == ResourceType::Texture_UAV))
return true;

return false;
Expand Down
8 changes: 4 additions & 4 deletions src/d3d12/d3d12-upload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ namespace nvrhi::d3d12
uint64_t bestInstance = VersionGetInstance(bestChunk->version);

// Compare chunks: submitted is better than current, old is better than new, large is better than small
if (candidateSubmitted && !bestSubmitted ||
candidateSubmitted == bestSubmitted && candidateInstance < bestInstance ||
candidateSubmitted == bestSubmitted && candidateInstance == bestInstance
&& candidateChunk->bufferSize > bestChunk->bufferSize)
if ((candidateSubmitted && !bestSubmitted) ||
(candidateSubmitted == bestSubmitted && candidateInstance < bestInstance) ||
(candidateSubmitted == bestSubmitted && candidateInstance == bestInstance
&& candidateChunk->bufferSize > bestChunk->bufferSize))
{
bestChunk = candidateChunk;
}
Expand Down
12 changes: 3 additions & 9 deletions src/vulkan/vulkan-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ namespace nvrhi::vulkan
class Heap : public MemoryResource, public RefCounter<IHeap>
{
public:
explicit Heap(const VulkanContext& context, VulkanAllocator& allocator)
: m_Context(context)
, m_Allocator(allocator)
explicit Heap(VulkanAllocator& allocator)
: m_Allocator(allocator)
{ }

~Heap() override;
Expand All @@ -328,7 +327,6 @@ namespace nvrhi::vulkan
const HeapDesc& getDesc() override { return desc; }

private:
const VulkanContext& m_Context;
VulkanAllocator& m_Allocator;
};

Expand Down Expand Up @@ -1017,8 +1015,7 @@ namespace nvrhi::vulkan
bool allowUpdate = false;
bool compacted = false;

explicit OpacityMicromap(const VulkanContext& context)
: m_Context(context)
explicit OpacityMicromap()
{ }

~OpacityMicromap() override;
Expand All @@ -1027,9 +1024,6 @@ namespace nvrhi::vulkan
const rt::OpacityMicromapDesc& getDesc() const override { return desc; }
bool isCompacted() const override { return compacted; }
uint64_t getDeviceAddress() const override;

private:
const VulkanContext& m_Context;
};

class Device : public RefCounter<nvrhi::vulkan::IDevice>
Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vulkan-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ namespace nvrhi::vulkan
return nullptr;
}

Heap* heap = new Heap(m_Context, m_Allocator);
Heap* heap = new Heap(m_Allocator);
heap->desc = d;
heap->managed = true;

Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vulkan-raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace nvrhi::vulkan

m_Context.device.getMicromapBuildSizesEXT(vk::AccelerationStructureBuildTypeKHR::eDevice, &buildInfo, &buildSize);

OpacityMicromap* om = new OpacityMicromap(m_Context);
OpacityMicromap* om = new OpacityMicromap();
om->desc = desc;
om->compacted = false;

Expand Down

0 comments on commit 55b0dd4

Please sign in to comment.