Skip to content

Commit

Permalink
More refactoring and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
godlikepanos committed Aug 16, 2024
1 parent 373ddc7 commit 1e9f47b
Show file tree
Hide file tree
Showing 115 changed files with 735 additions and 734 deletions.
4 changes: 2 additions & 2 deletions AnKi/Gr/CommandBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ class CommandBuffer : public GrObject
/// Bind a buffer.
void bindUav(U32 reg, U32 space, const BufferView& buffer, Format fmt = Format::kNone);

/// Set push constants.
void setPushConstants(const void* data, U32 dataSize);
/// Set push constants (Vulkan) or root constants (D3D).
void setFastConstants(const void* data, U32 dataSize);

/// Bind a program.
void bindShaderProgram(ShaderProgram* prog);
Expand Down
22 changes: 11 additions & 11 deletions AnKi/Gr/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,23 @@ Error ShaderReflection::linkShaderReflection(const ShaderReflection& a, const Sh
ShaderReflection c;

memcpy(&c.m_descriptor, &a.m_descriptor, sizeof(a.m_descriptor));
for(U32 set = 0; set < kMaxDescriptorSets; ++set)
for(U32 space = 0; space < kMaxRegisterSpaces; ++space)
{
for(U32 binding = 0; binding < b.m_descriptor.m_bindingCounts[set]; ++binding)
for(U32 binding = 0; binding < b.m_descriptor.m_bindingCounts[space]; ++binding)
{
// Search for the binding in a
const ShaderReflectionBinding& bbinding = b.m_descriptor.m_bindings[set][binding];
const ShaderReflectionBinding& bbinding = b.m_descriptor.m_bindings[space][binding];
Bool bindingFoundOnA = false;
for(U32 binding2 = 0; binding2 < a.m_descriptor.m_bindingCounts[set]; ++binding2)
for(U32 binding2 = 0; binding2 < a.m_descriptor.m_bindingCounts[space]; ++binding2)
{
const ShaderReflectionBinding& abinding = a.m_descriptor.m_bindings[set][binding2];
const ShaderReflectionBinding& abinding = a.m_descriptor.m_bindings[space][binding2];

if(abinding.m_registerBindingPoint == bbinding.m_registerBindingPoint
&& descriptorTypeToHlslResourceType(abinding.m_type) == descriptorTypeToHlslResourceType(bbinding.m_type))
{
if(abinding != bbinding)
{
ANKI_GR_LOGE("Can't link shader reflection because of different bindings. Set %u binding %u", set, binding);
ANKI_GR_LOGE("Can't link shader reflection because of different bindings. Space %u binding %u", space, binding);
return Error::kFunctionFailed;
}
bindingFoundOnA = true;
Expand All @@ -154,18 +154,18 @@ Error ShaderReflection::linkShaderReflection(const ShaderReflection& a, const Sh

if(!bindingFoundOnA)
{
c.m_descriptor.m_bindings[set][c.m_descriptor.m_bindingCounts[set]++] = bbinding;
c.m_descriptor.m_bindings[space][c.m_descriptor.m_bindingCounts[space]++] = bbinding;
}
}
}

if(a.m_descriptor.m_pushConstantsSize != 0 && b.m_descriptor.m_pushConstantsSize != 0
&& a.m_descriptor.m_pushConstantsSize != b.m_descriptor.m_pushConstantsSize)
if(a.m_descriptor.m_fastConstantsSize != 0 && b.m_descriptor.m_fastConstantsSize != 0
&& a.m_descriptor.m_fastConstantsSize != b.m_descriptor.m_fastConstantsSize)
{
ANKI_GR_LOGE("Can't link shader reflection because push constant size doesn't match");
ANKI_GR_LOGE("Can't link shader reflection because fast constant size doesn't match");
return Error::kFunctionFailed;
}
c.m_descriptor.m_pushConstantsSize = max(a.m_descriptor.m_pushConstantsSize, b.m_descriptor.m_pushConstantsSize);
c.m_descriptor.m_fastConstantsSize = max(a.m_descriptor.m_fastConstantsSize, b.m_descriptor.m_fastConstantsSize);

c.m_descriptor.m_hasVkBindlessDescriptorSet = a.m_descriptor.m_hasVkBindlessDescriptorSet || b.m_descriptor.m_hasVkBindlessDescriptorSet;

Expand Down
21 changes: 10 additions & 11 deletions AnKi/Gr/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ ANKI_DEFINE_SUBMODULE_UTIL_CONTAINERS(Gr, GrMemoryPool)

// Some constants
constexpr U32 kMaxColorRenderTargets = 4;
constexpr U32 kMaxDescriptorSets = 3; ///< Groups that can be bound at the same time.
constexpr U32 kMaxBindingsPerDescriptorSet = 32;
constexpr U32 kMaxRegisterSpaces = 3; ///< Groups that can be bound at the same time.
constexpr U32 kMaxBindingsPerRegisterSpace = 32;
constexpr U32 kMaxFramesInFlight = 3; ///< Triple buffering.
constexpr U32 kMaxGrObjectNameLength = 61;
constexpr U32 kMaxBindlessTextures = 512;
constexpr U32 kMaxBindlessReadonlyTextureBuffers = 512;
constexpr U32 kMaxPushConstantSize = 128; ///< Thanks AMD!!
constexpr U32 kMaxFastConstantsSize = 128; ///< Thanks AMD!!

/// The number of commands in a command buffer that make it a small batch command buffer.
constexpr U32 kCommandBufferSmallBatchMaxCommands = 100;
Expand Down Expand Up @@ -162,8 +161,8 @@ class GpuDeviceCapabilities
/// The max visible range of texture buffers inside the shaders.
PtrSize m_textureBufferMaxRange = 0;

/// Max push constant size.
PtrSize m_pushConstantsSize = 128;
/// Max push/root constant size.
PtrSize m_fastConstantsSize = 128;

/// The max combined size of shared variables (with paddings) in compute shaders.
PtrSize m_computeSharedMemorySize = 16_KB;
Expand Down Expand Up @@ -962,20 +961,20 @@ class ShaderReflectionDescriptorRelated
{
public:
/// The D3D backend expects bindings inside a space need to be ordered by HLSL type and then by register.
Array2d<ShaderReflectionBinding, kMaxDescriptorSets, kMaxBindingsPerDescriptorSet> m_bindings;
Array2d<ShaderReflectionBinding, kMaxRegisterSpaces, kMaxBindingsPerRegisterSpace> m_bindings;

Array<U8, kMaxDescriptorSets> m_bindingCounts = {};
Array<U8, kMaxRegisterSpaces> m_bindingCounts = {};

U32 m_pushConstantsSize = 0;
U32 m_fastConstantsSize = 0;

Bool m_hasVkBindlessDescriptorSet = false; ///< Filled by the shader compiler.
U8 m_vkBindlessDescriptorSet = kMaxU8; ///< Filled by the VK backend.

void validate() const
{
for(U32 set = 0; set < kMaxDescriptorSets; ++set)
for(U32 set = 0; set < kMaxRegisterSpaces; ++set)
{
for(U32 ibinding = 0; ibinding < kMaxBindingsPerDescriptorSet; ++ibinding)
for(U32 ibinding = 0; ibinding < kMaxBindingsPerRegisterSpace; ++ibinding)
{
const ShaderReflectionBinding& binding = m_bindings[set][ibinding];

Expand Down
2 changes: 1 addition & 1 deletion AnKi/Gr/D3D/D3DCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ Bool CommandBuffer::isEmpty() const
return self.m_commandCount == 0;
}

void CommandBuffer::setPushConstants(const void* data, U32 dataSize)
void CommandBuffer::setFastConstants(const void* data, U32 dataSize)
{
ANKI_D3D_SELF(CommandBufferImpl);
self.m_descriptors.setRootConstants(data, dataSize);
Expand Down
20 changes: 10 additions & 10 deletions AnKi/Gr/D3D/D3DDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ Error RootSignatureFactory::getOrCreateRootSignature(const ShaderReflection& ref
GrDynamicArray<D3D12_ROOT_PARAMETER1> rootParameters;

// Create the tables
Array<GrDynamicArray<D3D12_DESCRIPTOR_RANGE1>, kMaxBindingsPerDescriptorSet * 2> tableRanges; // One per descriptor table
Array<GrDynamicArray<D3D12_DESCRIPTOR_RANGE1>, kMaxBindingsPerRegisterSpace * 2> tableRanges; // One per descriptor table
U32 tableRangesCount = 0;
for(U32 space = 0; space < kMaxDescriptorSets; ++space)
for(U32 space = 0; space < kMaxRegisterSpaces; ++space)
{
if(refl.m_descriptor.m_bindingCounts[space] == 0)
{
Expand Down Expand Up @@ -339,13 +339,13 @@ Error RootSignatureFactory::getOrCreateRootSignature(const ShaderReflection& ref
}

// Root constants
if(refl.m_descriptor.m_pushConstantsSize)
if(refl.m_descriptor.m_fastConstantsSize)
{
D3D12_ROOT_PARAMETER1& rootParam = *rootParameters.emplaceBack();
rootParam = {};
rootParam.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS;
ANKI_ASSERT((refl.m_descriptor.m_pushConstantsSize % 4) == 0);
rootParam.Constants.Num32BitValues = refl.m_descriptor.m_pushConstantsSize / 4;
ANKI_ASSERT((refl.m_descriptor.m_fastConstantsSize % 4) == 0);
rootParam.Constants.Num32BitValues = refl.m_descriptor.m_fastConstantsSize / 4;
rootParam.Constants.RegisterSpace = 3000;
rootParam.Constants.ShaderRegister = 0;
rootParam.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL;
Expand Down Expand Up @@ -377,7 +377,7 @@ Error RootSignatureFactory::getOrCreateRootSignature(const ShaderReflection& ref
signature->m_rootSignature = dxRootSig;

U8 rootParameterIdx = 0;
for(U32 spaceIdx = 0; spaceIdx < kMaxDescriptorSets; ++spaceIdx)
for(U32 spaceIdx = 0; spaceIdx < kMaxRegisterSpaces; ++spaceIdx)
{
if(refl.m_descriptor.m_bindingCounts[spaceIdx] == 0)
{
Expand Down Expand Up @@ -430,7 +430,7 @@ Error RootSignatureFactory::getOrCreateRootSignature(const ShaderReflection& ref
}
}

signature->m_rootConstantsSize = refl.m_descriptor.m_pushConstantsSize;
signature->m_rootConstantsSize = refl.m_descriptor.m_fastConstantsSize;
if(signature->m_rootConstantsSize)
{
signature->m_rootConstantsParameterIdx = rootParameterIdx++;
Expand Down Expand Up @@ -462,7 +462,7 @@ void DescriptorState::bindRootSignature(const RootSignature* rootSignature, Bool
return;
}

for(U32 space = 0; space < kMaxDescriptorSets; ++space)
for(U32 space = 0; space < kMaxRegisterSpaces; ++space)
{
if(!rootSignature->m_spaces[space].isEmpty())
{
Expand Down Expand Up @@ -496,7 +496,7 @@ void DescriptorState::flush(ID3D12GraphicsCommandList& cmdList)
}

// Populate the heaps
for(U32 spaceIdx = 0; spaceIdx < kMaxDescriptorSets; ++spaceIdx)
for(U32 spaceIdx = 0; spaceIdx < kMaxRegisterSpaces; ++spaceIdx)
{
const RootSignature::Space& rootSignatureSpace = m_rootSignature->m_spaces[spaceIdx];
if(rootSignatureSpace.isEmpty())
Expand Down Expand Up @@ -718,7 +718,7 @@ void DescriptorState::flush(ID3D12GraphicsCommandList& cmdList)
}

// Bind root parameters
for(U32 spaceIdx = 0; spaceIdx < kMaxDescriptorSets; ++spaceIdx)
for(U32 spaceIdx = 0; spaceIdx < kMaxRegisterSpaces; ++spaceIdx)
{
const RootSignature::Space& rootSignatureSpace = m_rootSignature->m_spaces[spaceIdx];
if(rootSignatureSpace.isEmpty())
Expand Down
8 changes: 4 additions & 4 deletions AnKi/Gr/D3D/D3DDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class RootSignature

ID3D12RootSignature* m_rootSignature = nullptr;

Array<Space, kMaxDescriptorSets> m_spaces;
Array<Space, kMaxRegisterSpaces> m_spaces;

U32 m_rootConstantsSize = kMaxU32;
U8 m_rootConstantsParameterIdx = kMaxU8;
Expand Down Expand Up @@ -415,7 +415,7 @@ class DescriptorState

void setRootConstants(const void* data, U32 dataSize)
{
ANKI_ASSERT(data && dataSize && dataSize <= kMaxPushConstantSize);
ANKI_ASSERT(data && dataSize && dataSize <= kMaxFastConstantsSize);
memcpy(m_rootConsts.getBegin(), data, dataSize);
m_rootConstSize = dataSize;
m_rootConstsDirty = true;
Expand Down Expand Up @@ -482,9 +482,9 @@ class DescriptorState
};

const RootSignature* m_rootSignature = nullptr;
Array<Space, kMaxDescriptorSets> m_spaces;
Array<Space, kMaxRegisterSpaces> m_spaces;

Array<U8, kMaxPushConstantSize> m_rootConsts;
Array<U8, kMaxFastConstantsSize> m_rootConsts;
U32 m_rootConstSize = 0;

Bool m_rootSignatureNeedsRebinding = true;
Expand Down
2 changes: 1 addition & 1 deletion AnKi/Gr/D3D/D3DGrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ Error GrManagerImpl::initInternal(const GrManagerInitInfo& init)
m_capabilities.m_storageBufferMaxRange = 1 << D3D12_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP;
m_capabilities.m_texelBufferBindOffsetAlignment = 32;
m_capabilities.m_textureBufferMaxRange = kMaxU32; // ?
m_capabilities.m_pushConstantsSize = kMaxPushConstantSize;
m_capabilities.m_fastConstantsSize = kMaxFastConstantsSize;
m_capabilities.m_computeSharedMemorySize = D3D12_CS_TGSM_REGISTER_COUNT * sizeof(F32);
m_capabilities.m_accelerationStructureBuildScratchOffsetAlignment = 32; // ?
m_capabilities.m_sbtRecordAlignment = 32; // ?
Expand Down
6 changes: 3 additions & 3 deletions AnKi/Gr/Vulkan/VkCommandBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,15 +1081,15 @@ Bool CommandBuffer::isEmpty() const
return self.isEmpty();
}

void CommandBuffer::setPushConstants(const void* data, U32 dataSize)
void CommandBuffer::setFastConstants(const void* data, U32 dataSize)
{
ANKI_VK_SELF(CommandBufferImpl);
ANKI_ASSERT(data && dataSize && dataSize % 16 == 0);
ANKI_ASSERT(static_cast<const ShaderProgramImpl&>(self.getBoundProgram()).getReflection().m_descriptor.m_pushConstantsSize == dataSize
ANKI_ASSERT(static_cast<const ShaderProgramImpl&>(self.getBoundProgram()).getReflection().m_descriptor.m_fastConstantsSize == dataSize
&& "The bound program should have push constants equal to the \"dataSize\" parameter");

self.commandCommon();
self.m_descriptorState.setPushConstants(data, dataSize);
self.m_descriptorState.setFastConstants(data, dataSize);
}

void CommandBuffer::setLineWidth(F32 width)
Expand Down
16 changes: 8 additions & 8 deletions AnKi/Gr/Vulkan/VkDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ Error PipelineLayoutFactory2::getOrCreateDescriptorSetLayout(ConstWeakArray<Shad
ANKI_END_PACKED_STRUCT

// Compute the hash for the layout
Array<DSBinding, kMaxBindingsPerDescriptorSet> bindings;
Array<DSBinding, kMaxBindingsPerRegisterSpace> bindings;
U64 hash;

if(reflBindings.getSize())
Expand Down Expand Up @@ -386,7 +386,7 @@ Error PipelineLayoutFactory2::getOrCreateDescriptorSetLayout(ConstWeakArray<Shad
layout = newInstance<DescriptorSetLayout>(GrMemoryPool::getSingleton());
m_dsLayouts.emplace(hash, layout);

Array<VkDescriptorSetLayoutBinding, kMaxBindingsPerDescriptorSet> vkBindings;
Array<VkDescriptorSetLayoutBinding, kMaxBindingsPerRegisterSpace> vkBindings;
VkDescriptorSetLayoutCreateInfo ci = {};
ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;

Expand Down Expand Up @@ -433,7 +433,7 @@ Error PipelineLayoutFactory2::getOrCreatePipelineLayout(const ShaderReflectionDe

// Find dset count
layout->m_dsetCount = 0;
for(U8 iset = 0; iset < kMaxDescriptorSets; ++iset)
for(U8 iset = 0; iset < kMaxRegisterSpaces; ++iset)
{
if(refl.m_bindingCounts[iset])
{
Expand Down Expand Up @@ -473,10 +473,10 @@ Error PipelineLayoutFactory2::getOrCreatePipelineLayout(const ShaderReflectionDe
ci.setLayoutCount = layout->m_dsetCount;

VkPushConstantRange pushConstantRange;
if(refl.m_pushConstantsSize > 0)
if(refl.m_fastConstantsSize > 0)
{
pushConstantRange.offset = 0;
pushConstantRange.size = refl.m_pushConstantsSize;
pushConstantRange.size = refl.m_fastConstantsSize;
pushConstantRange.stageFlags = VK_SHADER_STAGE_ALL;
ci.pushConstantRangeCount = 1;
ci.pPushConstantRanges = &pushConstantRange;
Expand All @@ -495,7 +495,7 @@ void DescriptorState::flush(VkCommandBuffer cmdb, DescriptorAllocator& dalloc)
const ShaderReflectionDescriptorRelated& refl = m_pipelineLayout->getReflection();

// Small opt to bind the high frequency sets as little as possible
BitSet<kMaxDescriptorSets> dirtySets(false);
BitSet<kMaxRegisterSpaces> dirtySets(false);

for(U32 iset = 0; iset < m_pipelineLayout->m_dsetCount; ++iset)
{
Expand Down Expand Up @@ -608,9 +608,9 @@ void DescriptorState::flush(VkCommandBuffer cmdb, DescriptorAllocator& dalloc)
}

// Set push consts
if(refl.m_pushConstantsSize)
if(refl.m_fastConstantsSize)
{
ANKI_ASSERT(refl.m_pushConstantsSize == m_pushConstSize && "Possibly forgot to set push constants");
ANKI_ASSERT(refl.m_fastConstantsSize == m_pushConstSize && "Possibly forgot to set push constants");

if(m_pushConstantsDirty)
{
Expand Down
16 changes: 8 additions & 8 deletions AnKi/Gr/Vulkan/VkDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ class PipelineLayout2
private:
VkPipelineLayout m_handle = VK_NULL_HANDLE;
ShaderReflectionDescriptorRelated m_refl;
Array<VkDescriptorSetLayout, kMaxDescriptorSets> m_dsetLayouts = {};
Array<U32, kMaxDescriptorSets> m_descriptorCounts = {};
Array<VkDescriptorSetLayout, kMaxRegisterSpaces> m_dsetLayouts = {};
Array<U32, kMaxRegisterSpaces> m_descriptorCounts = {};
U8 m_dsetCount = 0;
};

Expand Down Expand Up @@ -162,7 +162,7 @@ class DescriptorState
{
m_pipelineLayout = layout;
m_pipelineBindPoint = bindPoint;
m_pushConstantsDirty = m_pushConstantsDirty || (m_pushConstSize != m_pipelineLayout->m_refl.m_pushConstantsSize);
m_pushConstantsDirty = m_pushConstantsDirty || (m_pushConstSize != m_pipelineLayout->m_refl.m_fastConstantsSize);

for(U32 iset = 0; iset < m_pipelineLayout->m_dsetCount; ++iset)
{
Expand Down Expand Up @@ -280,9 +280,9 @@ class DescriptorState
#endif
}

void setPushConstants(const void* data, U32 dataSize)
void setFastConstants(const void* data, U32 dataSize)
{
ANKI_ASSERT(data && dataSize && dataSize <= kMaxPushConstantSize);
ANKI_ASSERT(data && dataSize && dataSize <= kMaxFastConstantsSize);
memcpy(m_pushConsts.getBegin(), data, dataSize);
m_pushConstSize = dataSize;
m_pushConstantsDirty = true;
Expand Down Expand Up @@ -331,10 +331,10 @@ class DescriptorState

const PipelineLayout2* m_pipelineLayout = nullptr;
VkPipelineBindPoint m_pipelineBindPoint = VK_PIPELINE_BIND_POINT_MAX_ENUM;
Array<DescriptorSet, kMaxDescriptorSets> m_sets;
Array<VkDescriptorSet, kMaxDescriptorSets> m_vkDsets = {};
Array<DescriptorSet, kMaxRegisterSpaces> m_sets;
Array<VkDescriptorSet, kMaxRegisterSpaces> m_vkDsets = {};

Array<U8, kMaxPushConstantSize> m_pushConsts;
Array<U8, kMaxFastConstantsSize> m_pushConsts;
U32 m_pushConstSize = 0;
Bool m_pushConstantsDirty = true;

Expand Down
Loading

0 comments on commit 1e9f47b

Please sign in to comment.