diff --git a/AnKi/Gr/CommandBuffer.h b/AnKi/Gr/CommandBuffer.h index 8f4f847fc..71b3a8635 100644 --- a/AnKi/Gr/CommandBuffer.h +++ b/AnKi/Gr/CommandBuffer.h @@ -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); diff --git a/AnKi/Gr/Common.cpp b/AnKi/Gr/Common.cpp index b1c7ff722..da57ad3b4 100644 --- a/AnKi/Gr/Common.cpp +++ b/AnKi/Gr/Common.cpp @@ -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; @@ -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; diff --git a/AnKi/Gr/Common.h b/AnKi/Gr/Common.h index 231c998d5..2c751504c 100644 --- a/AnKi/Gr/Common.h +++ b/AnKi/Gr/Common.h @@ -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; @@ -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; @@ -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 m_bindings; + Array2d m_bindings; - Array m_bindingCounts = {}; + Array 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]; diff --git a/AnKi/Gr/D3D/D3DCommandBuffer.cpp b/AnKi/Gr/D3D/D3DCommandBuffer.cpp index bdcef13c4..a2bb67fca 100644 --- a/AnKi/Gr/D3D/D3DCommandBuffer.cpp +++ b/AnKi/Gr/D3D/D3DCommandBuffer.cpp @@ -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); diff --git a/AnKi/Gr/D3D/D3DDescriptor.cpp b/AnKi/Gr/D3D/D3DDescriptor.cpp index b316a14e4..94e74a19a 100644 --- a/AnKi/Gr/D3D/D3DDescriptor.cpp +++ b/AnKi/Gr/D3D/D3DDescriptor.cpp @@ -263,9 +263,9 @@ Error RootSignatureFactory::getOrCreateRootSignature(const ShaderReflection& ref GrDynamicArray rootParameters; // Create the tables - Array, kMaxBindingsPerDescriptorSet * 2> tableRanges; // One per descriptor table + Array, 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) { @@ -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; @@ -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) { @@ -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++; @@ -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()) { @@ -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()) @@ -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()) diff --git a/AnKi/Gr/D3D/D3DDescriptor.h b/AnKi/Gr/D3D/D3DDescriptor.h index f307b0fbf..77d0169b8 100644 --- a/AnKi/Gr/D3D/D3DDescriptor.h +++ b/AnKi/Gr/D3D/D3DDescriptor.h @@ -289,7 +289,7 @@ class RootSignature ID3D12RootSignature* m_rootSignature = nullptr; - Array m_spaces; + Array m_spaces; U32 m_rootConstantsSize = kMaxU32; U8 m_rootConstantsParameterIdx = kMaxU8; @@ -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; @@ -482,9 +482,9 @@ class DescriptorState }; const RootSignature* m_rootSignature = nullptr; - Array m_spaces; + Array m_spaces; - Array m_rootConsts; + Array m_rootConsts; U32 m_rootConstSize = 0; Bool m_rootSignatureNeedsRebinding = true; diff --git a/AnKi/Gr/D3D/D3DGrManager.cpp b/AnKi/Gr/D3D/D3DGrManager.cpp index 713eadb38..7a3d7c9ca 100644 --- a/AnKi/Gr/D3D/D3DGrManager.cpp +++ b/AnKi/Gr/D3D/D3DGrManager.cpp @@ -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; // ? diff --git a/AnKi/Gr/Vulkan/VkCommandBuffer.cpp b/AnKi/Gr/Vulkan/VkCommandBuffer.cpp index c77e17ee9..677bdf3c9 100644 --- a/AnKi/Gr/Vulkan/VkCommandBuffer.cpp +++ b/AnKi/Gr/Vulkan/VkCommandBuffer.cpp @@ -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(self.getBoundProgram()).getReflection().m_descriptor.m_pushConstantsSize == dataSize + ANKI_ASSERT(static_cast(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) diff --git a/AnKi/Gr/Vulkan/VkDescriptor.cpp b/AnKi/Gr/Vulkan/VkDescriptor.cpp index 671f6e04b..1575dbf52 100644 --- a/AnKi/Gr/Vulkan/VkDescriptor.cpp +++ b/AnKi/Gr/Vulkan/VkDescriptor.cpp @@ -346,7 +346,7 @@ Error PipelineLayoutFactory2::getOrCreateDescriptorSetLayout(ConstWeakArray bindings; + Array bindings; U64 hash; if(reflBindings.getSize()) @@ -386,7 +386,7 @@ Error PipelineLayoutFactory2::getOrCreateDescriptorSetLayout(ConstWeakArray(GrMemoryPool::getSingleton()); m_dsLayouts.emplace(hash, layout); - Array vkBindings; + Array vkBindings; VkDescriptorSetLayoutCreateInfo ci = {}; ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; @@ -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]) { @@ -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; @@ -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 dirtySets(false); + BitSet dirtySets(false); for(U32 iset = 0; iset < m_pipelineLayout->m_dsetCount; ++iset) { @@ -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) { diff --git a/AnKi/Gr/Vulkan/VkDescriptor.h b/AnKi/Gr/Vulkan/VkDescriptor.h index 1155f7dca..2796e9014 100644 --- a/AnKi/Gr/Vulkan/VkDescriptor.h +++ b/AnKi/Gr/Vulkan/VkDescriptor.h @@ -112,8 +112,8 @@ class PipelineLayout2 private: VkPipelineLayout m_handle = VK_NULL_HANDLE; ShaderReflectionDescriptorRelated m_refl; - Array m_dsetLayouts = {}; - Array m_descriptorCounts = {}; + Array m_dsetLayouts = {}; + Array m_descriptorCounts = {}; U8 m_dsetCount = 0; }; @@ -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) { @@ -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; @@ -331,10 +331,10 @@ class DescriptorState const PipelineLayout2* m_pipelineLayout = nullptr; VkPipelineBindPoint m_pipelineBindPoint = VK_PIPELINE_BIND_POINT_MAX_ENUM; - Array m_sets; - Array m_vkDsets = {}; + Array m_sets; + Array m_vkDsets = {}; - Array m_pushConsts; + Array m_pushConsts; U32 m_pushConstSize = 0; Bool m_pushConstantsDirty = true; diff --git a/AnKi/Gr/Vulkan/VkShaderProgram.cpp b/AnKi/Gr/Vulkan/VkShaderProgram.cpp index 12d1c88c2..d4e548690 100644 --- a/AnKi/Gr/Vulkan/VkShaderProgram.cpp +++ b/AnKi/Gr/Vulkan/VkShaderProgram.cpp @@ -455,7 +455,7 @@ void ShaderProgramImpl::rewriteSpirv(ShaderReflectionDescriptorRelated& refl, Gr // Find a binding for the bindless DS if(refl.m_hasVkBindlessDescriptorSet) { - for(U8 iset = 0; iset < kMaxDescriptorSets; ++iset) + for(U8 iset = 0; iset < kMaxRegisterSpaces; ++iset) { if(refl.m_bindingCounts[iset] == 0) { @@ -468,7 +468,7 @@ void ShaderProgramImpl::rewriteSpirv(ShaderReflectionDescriptorRelated& refl, Gr // Re-write all SPIRVs and compute the new bindings rewrittenSpirvs.resize(m_shaders.getSize()); Bool hasBindless = false; - Array vkBindingCount = {}; + Array vkBindingCount = {}; for(U32 ishader = 0; ishader < m_shaders.getSize(); ++ishader) { ConstWeakArray inSpirv = static_cast(*m_shaders[ishader]).m_spirvBin; @@ -480,14 +480,14 @@ void ShaderProgramImpl::rewriteSpirv(ShaderReflectionDescriptorRelated& refl, Gr visitSpirv(WeakArray(outSpv), [&](U32 cmd, WeakArray instructions) { if(cmd == spv::OpDecorate && instructions[1] == spv::DecorationBinding && instructions[2] >= kDxcVkBindingShifts[0][HlslResourceType::kFirst] - && instructions[2] < kDxcVkBindingShifts[kMaxDescriptorSets - 1][HlslResourceType::kCount - 1]) + && instructions[2] < kDxcVkBindingShifts[kMaxRegisterSpaces - 1][HlslResourceType::kCount - 1]) { const U32 binding = instructions[2]; // Look at the binding and derive a few things. See the DXC compilation on what they mean - U32 set = kMaxDescriptorSets; + U32 set = kMaxRegisterSpaces; HlslResourceType hlslResourceType = HlslResourceType::kCount; - for(set = 0; set < kMaxDescriptorSets; ++set) + for(set = 0; set < kMaxRegisterSpaces; ++set) { for(HlslResourceType hlslResourceType_ : EnumIterable()) { @@ -504,7 +504,7 @@ void ShaderProgramImpl::rewriteSpirv(ShaderReflectionDescriptorRelated& refl, Gr } } - ANKI_ASSERT(set < kMaxDescriptorSets); + ANKI_ASSERT(set < kMaxRegisterSpaces); ANKI_ASSERT(hlslResourceType < HlslResourceType::kCount); const U32 registerBindingPoint = binding - kDxcVkBindingShifts[set][hlslResourceType]; diff --git a/AnKi/Renderer/Bloom.cpp b/AnKi/Renderer/Bloom.cpp index c6f031716..50123071b 100644 --- a/AnKi/Renderer/Bloom.cpp +++ b/AnKi/Renderer/Bloom.cpp @@ -116,7 +116,7 @@ void Bloom::populateRenderGraph(RenderingContext& ctx) rgraphCtx.bindSrv(0, 0, getRenderer().getDownscaleBlur().getRt(), inputTexSubresource); const Vec4 consts(g_bloomThresholdCVar.get(), g_bloomScaleCVar.get(), 0.0f, 0.0f); - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); rgraphCtx.bindUav(0, 0, getRenderer().getTonemapping().getRt()); diff --git a/AnKi/Renderer/ClusterBinning.cpp b/AnKi/Renderer/ClusterBinning.cpp index 677e78c38..593ae8674 100644 --- a/AnKi/Renderer/ClusterBinning.cpp +++ b/AnKi/Renderer/ClusterBinning.cpp @@ -82,7 +82,7 @@ void ClusterBinning::populateRenderGraph(RenderingContext& ctx) cmdb.bindShaderProgram(m_jobSetupGrProg.get()); const UVec4 consts(getRenderer().getTileCounts().x() * getRenderer().getTileCounts().y()); - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); for(GpuSceneNonRenderableObjectType type : EnumIterable()) { @@ -161,7 +161,7 @@ void ClusterBinning::populateRenderGraph(RenderingContext& ctx) cmdb.bindSrv(1, 0, BufferView(&GpuSceneBuffer::getSingleton().getBuffer(), objBufferOffset, objBufferRange)); cmdb.bindUav(0, 0, m_runCtx.m_clustersBuffer); - struct ClusterBinningUniforms + struct ClusterBinningConstants { Vec3 m_cameraOrigin; F32 m_zSplitCountOverFrustumLength; @@ -178,23 +178,23 @@ void ClusterBinning::populateRenderGraph(RenderingContext& ctx) I32 m_padding2; Mat4 m_invertedViewProjMat; - } unis; + } consts; - unis.m_cameraOrigin = ctx.m_matrices.m_cameraTransform.getTranslationPart().xyz(); - unis.m_zSplitCountOverFrustumLength = F32(getRenderer().getZSplitCount()) / (ctx.m_cameraFar - ctx.m_cameraNear); - unis.m_renderingSize = Vec2(getRenderer().getInternalResolution()); - unis.m_tileCountX = getRenderer().getTileCounts().x(); - unis.m_tileCount = getRenderer().getTileCounts().x() * getRenderer().getTileCounts().y(); + consts.m_cameraOrigin = ctx.m_matrices.m_cameraTransform.getTranslationPart().xyz(); + consts.m_zSplitCountOverFrustumLength = F32(getRenderer().getZSplitCount()) / (ctx.m_cameraFar - ctx.m_cameraNear); + consts.m_renderingSize = Vec2(getRenderer().getInternalResolution()); + consts.m_tileCountX = getRenderer().getTileCounts().x(); + consts.m_tileCount = getRenderer().getTileCounts().x() * getRenderer().getTileCounts().y(); Plane nearPlane; extractClipPlane(ctx.m_matrices.m_viewProjection, FrustumPlaneType::kNear, nearPlane); - unis.m_nearPlaneWorld = Vec4(nearPlane.getNormal().xyz(), nearPlane.getOffset()); + consts.m_nearPlaneWorld = Vec4(nearPlane.getNormal().xyz(), nearPlane.getOffset()); - unis.m_zSplitCountMinusOne = getRenderer().getZSplitCount() - 1; + consts.m_zSplitCountMinusOne = getRenderer().getZSplitCount() - 1; - unis.m_invertedViewProjMat = ctx.m_matrices.m_invertedViewProjectionJitter; + consts.m_invertedViewProjMat = ctx.m_matrices.m_invertedViewProjectionJitter; - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.dispatchComputeIndirect(BufferView(indirectArgsBuff).setOffset(indirectArgsBuffOffset).setRange(sizeof(DispatchIndirectArgs))); diff --git a/AnKi/Renderer/Common.h b/AnKi/Renderer/Common.h index c90cb3dff..ffc51c496 100644 --- a/AnKi/Renderer/Common.h +++ b/AnKi/Renderer/Common.h @@ -87,7 +87,7 @@ class RenderingContext Array m_dirLightTextureMatrices; - BufferView m_globalRenderingUniformsBuffer; + BufferView m_globalRenderingConstantsBuffer; RenderingContext(StackMemoryPool* pool) : m_renderGraphDescr(pool) diff --git a/AnKi/Renderer/Dbg.cpp b/AnKi/Renderer/Dbg.cpp index caecbd7c7..7f2787efe 100644 --- a/AnKi/Renderer/Dbg.cpp +++ b/AnKi/Renderer/Dbg.cpp @@ -125,15 +125,15 @@ void Dbg::drawNonRenderable(GpuSceneNonRenderableObjectType type, U32 objCount, m_nonRenderablesProg->getOrCreateVariant(variantInitInfo, variant); cmdb.bindShaderProgram(&variant->getProgram()); - class Uniforms + class Constants { public: Mat4 m_viewProjMat; Mat3x4 m_camTrf; - } unis; - unis.m_viewProjMat = ctx.m_matrices.m_viewProjection; - unis.m_camTrf = ctx.m_matrices.m_cameraTransform; - cmdb.setPushConstants(&unis, sizeof(unis)); + } consts; + consts.m_viewProjMat = ctx.m_matrices.m_viewProjection; + consts.m_camTrf = ctx.m_matrices.m_cameraTransform; + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.bindSrv(1, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(type)); cmdb.bindSrv(2, 0, getRenderer().getPrimaryNonRenderableVisibility().getVisibleIndicesBuffer(type)); @@ -173,16 +173,16 @@ void Dbg::run(RenderPassWorkContext& rgraphCtx, const RenderingContext& ctx) m_renderablesProg->getOrCreateVariant(variantInitInfo, variant); cmdb.bindShaderProgram(&variant->getProgram()); - class Uniforms + class Constants { public: Vec4 m_color; Mat4 m_viewProjMat; - } unis; - unis.m_color = Vec4(1.0f, 0.0f, 1.0f, 1.0f); - unis.m_viewProjMat = ctx.m_matrices.m_viewProjection; + } consts; + consts.m_color = Vec4(1.0f, 0.0f, 1.0f, 1.0f); + consts.m_viewProjMat = ctx.m_matrices.m_viewProjection; - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.bindVertexBuffer(0, BufferView(m_cubeVertsBuffer.get()), sizeof(Vec3)); cmdb.setVertexAttribute(VertexAttributeSemantic::kPosition, 0, Format::kR32G32B32_Sfloat, 0); cmdb.bindIndexBuffer(BufferView(m_cubeIndicesBuffer.get()), IndexType::kU16); diff --git a/AnKi/Renderer/DepthDownscale.cpp b/AnKi/Renderer/DepthDownscale.cpp index 8afd7fd5c..e48f5401b 100644 --- a/AnKi/Renderer/DepthDownscale.cpp +++ b/AnKi/Renderer/DepthDownscale.cpp @@ -108,12 +108,12 @@ void DepthDownscale::populateRenderGraph(RenderingContext& ctx) varAU4(rectInfo) = initAU4(0, 0, getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y()); SpdSetup(dispatchThreadGroupCountXY, workGroupOffset, numWorkGroupsAndMips, rectInfo, m_mipCount); - DepthDownscaleUniforms pc; + DepthDownscaleConstants pc; pc.m_threadgroupCount = numWorkGroupsAndMips[0]; pc.m_mipmapCount = numWorkGroupsAndMips[1]; pc.m_srcTexSizeOverOne = 1.0f / Vec2(getRenderer().getInternalResolution()); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); for(U32 mip = 0; mip < kMaxMipsSinglePassDownsamplerCanProduce; ++mip) { diff --git a/AnKi/Renderer/DownscaleBlur.cpp b/AnKi/Renderer/DownscaleBlur.cpp index a56f68a46..7a61e3361 100644 --- a/AnKi/Renderer/DownscaleBlur.cpp +++ b/AnKi/Renderer/DownscaleBlur.cpp @@ -135,7 +135,7 @@ void DownscaleBlur::run(U32 passIdx, RenderPassWorkContext& rgraphCtx) if(g_preferComputeCVar.get()) { const Vec4 fbSize(F32(vpWidth), F32(vpHeight), 0.0f, 0.0f); - cmdb.setPushConstants(&fbSize, sizeof(fbSize)); + cmdb.setFastConstants(&fbSize, sizeof(fbSize)); rgraphCtx.bindUav(1, 0, m_runCtx.m_rt, TextureSubresourceDesc::surface(passIdx, 0, 0)); diff --git a/AnKi/Renderer/FinalComposite.cpp b/AnKi/Renderer/FinalComposite.cpp index 447d79c56..eb55519d2 100644 --- a/AnKi/Renderer/FinalComposite.cpp +++ b/AnKi/Renderer/FinalComposite.cpp @@ -150,7 +150,7 @@ void FinalComposite::run(RenderPassWorkContext& rgraphCtx) } const UVec4 pc(g_motionBlurSamplesCVar.get(), floatBitsToUint(g_filmGrainStrengthCVar.get()), getRenderer().getFrameCount() & kMaxU32, 0); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); } else { diff --git a/AnKi/Renderer/ForwardShading.cpp b/AnKi/Renderer/ForwardShading.cpp index 9fb8004ef..f04b6c9cf 100644 --- a/AnKi/Renderer/ForwardShading.cpp +++ b/AnKi/Renderer/ForwardShading.cpp @@ -64,7 +64,7 @@ void ForwardShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgr DepthDownscale::kQuarterInternalResolution); rgraphCtx.bindSrv(ANKI_MATERIAL_REGISTER_LIGHT_VOLUME, 0, getRenderer().getVolumetricLightingAccumulation().getRt()); - cmdb.bindConstantBuffer(ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_UNIFORMS, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_CONSTANTS, 0, ctx.m_globalRenderingConstantsBuffer); cmdb.bindSrv(ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_POINT_LIGHTS, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight)); diff --git a/AnKi/Renderer/GBufferPost.cpp b/AnKi/Renderer/GBufferPost.cpp index 79b2494cc..43e3d9d8b 100644 --- a/AnKi/Renderer/GBufferPost.cpp +++ b/AnKi/Renderer/GBufferPost.cpp @@ -62,7 +62,7 @@ void GBufferPost::populateRenderGraph(RenderingContext& ctx) cmdb.bindSampler(1, 0, getRenderer().getSamplers().m_trilinearRepeat.get()); - cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); cmdb.bindSrv(0, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kDecal)); cmdb.bindSrv(1, 0, getRenderer().getClusterBinning().getClustersBuffer()); diff --git a/AnKi/Renderer/IndirectDiffuseProbes.cpp b/AnKi/Renderer/IndirectDiffuseProbes.cpp index ebe91829f..a03e41bd2 100644 --- a/AnKi/Renderer/IndirectDiffuseProbes.cpp +++ b/AnKi/Renderer/IndirectDiffuseProbes.cpp @@ -421,7 +421,7 @@ void IndirectDiffuseProbes::populateRenderGraph(RenderingContext& rctx) dsInfo.m_gbufferDepthRenderTarget = gbufferDepthRt; dsInfo.m_directionalLightShadowmapRenderTarget = shadowsRt; dsInfo.m_skyLutRenderTarget = (getRenderer().getSky().isEnabled()) ? getRenderer().getSky().getSkyLutRt() : RenderTargetHandle(); - dsInfo.m_globalRendererConsts = rctx.m_globalRenderingUniformsBuffer; + dsInfo.m_globalRendererConsts = rctx.m_globalRenderingConstantsBuffer; dsInfo.m_renderpassContext = &rgraphCtx; m_lightShading.m_deferred.drawLights(dsInfo); @@ -463,15 +463,15 @@ void IndirectDiffuseProbes::populateRenderGraph(RenderingContext& rctx) public: IVec3 m_volumeTexel; I32 m_nextTexelOffsetInU; - } unis; + } consts; U32 x, y, z; unflatten3dArrayIndex(probeToRefresh->getCellCountsPerDimension().x(), probeToRefresh->getCellCountsPerDimension().y(), probeToRefresh->getCellCountsPerDimension().z(), cellIdx, x, y, z); - unis.m_volumeTexel = IVec3(x, y, z); + consts.m_volumeTexel = IVec3(x, y, z); - unis.m_nextTexelOffsetInU = probeToRefresh->getCellCountsPerDimension().x(); - cmdb.setPushConstants(&unis, sizeof(unis)); + consts.m_nextTexelOffsetInU = probeToRefresh->getCellCountsPerDimension().x(); + cmdb.setFastConstants(&consts, sizeof(consts)); // Dispatch cmdb.dispatchCompute(1, 1, 1); diff --git a/AnKi/Renderer/LensFlare.cpp b/AnKi/Renderer/LensFlare.cpp index d48bfbe41..191a1ce08 100644 --- a/AnKi/Renderer/LensFlare.cpp +++ b/AnKi/Renderer/LensFlare.cpp @@ -72,7 +72,7 @@ void LensFlare::populateRenderGraph(RenderingContext& ctx) cmdb.bindShaderProgram(m_updateIndirectBuffGrProg.get()); - cmdb.setPushConstants(&ctx.m_matrices.m_viewProjectionJitter, sizeof(ctx.m_matrices.m_viewProjectionJitter)); + cmdb.setFastConstants(&ctx.m_matrices.m_viewProjectionJitter, sizeof(ctx.m_matrices.m_viewProjectionJitter)); // Write flare info Vec4* flarePositions = allocateAndBindSrvStructuredBuffer(cmdb, 0, 0, flareCount); diff --git a/AnKi/Renderer/LightShading.cpp b/AnKi/Renderer/LightShading.cpp index c9479b9da..cd60b6f15 100644 --- a/AnKi/Renderer/LightShading.cpp +++ b/AnKi/Renderer/LightShading.cpp @@ -108,7 +108,7 @@ void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgrap cmdb.setDepthWrite(false); // Bind all - cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); cmdb.bindSrv(0, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight)); cmdb.bindSrv(1, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight)); cmdb.bindSrv(2, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kGlobalIlluminationProbe)); @@ -145,7 +145,7 @@ void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgrap cmdb.bindShaderProgram(m_skybox.m_grProgs[0].get()); const Vec4 color((sky) ? sky->getSolidColor() : Vec3(0.0f), 0.0); - cmdb.setPushConstants(&color, sizeof(color)); + cmdb.setFastConstants(&color, sizeof(color)); } else if(sky->getSkyboxType() == SkyboxType::kImage2D) { @@ -171,7 +171,7 @@ void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgrap pc.m_scale = sky->getImageScale(); pc.m_bias = sky->getImageBias(); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearRepeatAnisoResolutionScalingBias.get()); cmdb.bindSrv(0, 0, TextureView(&sky->getImageResource().getTexture(), TextureSubresourceDesc::all())); @@ -182,7 +182,7 @@ void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgrap cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get()); rgraphCtx.bindSrv(0, 0, getRenderer().getSky().getSkyLutRt()); - cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); } drawQuad(cmdb); @@ -202,20 +202,20 @@ void LightShading::run(const RenderingContext& ctx, RenderPassWorkContext& rgrap rgraphCtx.bindSrv(0, 0, getRenderer().getGBuffer().getDepthRt()); rgraphCtx.bindSrv(1, 0, getRenderer().getVolumetricFog().getRt()); - class PushConsts + class Consts { public: F32 m_zSplitCount; F32 m_finalZSplit; F32 m_near; F32 m_far; - } regs; - regs.m_zSplitCount = F32(getRenderer().getZSplitCount()); - regs.m_finalZSplit = F32(getRenderer().getVolumetricFog().getFinalClusterInZ()); - regs.m_near = ctx.m_cameraNear; - regs.m_far = ctx.m_cameraFar; + } consts; + consts.m_zSplitCount = F32(getRenderer().getZSplitCount()); + consts.m_finalZSplit = F32(getRenderer().getVolumetricFog().getFinalClusterInZ()); + consts.m_near = ctx.m_cameraNear; + consts.m_far = ctx.m_cameraFar; - cmdb.setPushConstants(®s, sizeof(regs)); + cmdb.setFastConstants(&consts, sizeof(consts)); // finalPixelColor = pixelWithoutFog * transmitance + inScattering (see the shader) cmdb.setBlendFactors(0, BlendFactor::kOne, BlendFactor::kSrcAlpha); diff --git a/AnKi/Renderer/MotionVectors.cpp b/AnKi/Renderer/MotionVectors.cpp index 5e47608cc..52f691813 100644 --- a/AnKi/Renderer/MotionVectors.cpp +++ b/AnKi/Renderer/MotionVectors.cpp @@ -75,14 +75,14 @@ void MotionVectors::populateRenderGraph(RenderingContext& ctx) rgraphCtx.bindSrv(0, 0, getRenderer().getGBuffer().getDepthRt()); rgraphCtx.bindSrv(1, 0, getRenderer().getGBuffer().getColorRt(3)); - class Uniforms + class Constants { public: Mat4 m_currentViewProjMat; Mat4 m_currentInvViewProjMat; Mat4 m_prevViewProjMat; } * pc; - pc = allocateAndBindConstants(cmdb, 0, 0); + pc = allocateAndBindConstants(cmdb, 0, 0); pc->m_currentViewProjMat = ctx.m_matrices.m_viewProjection; pc->m_currentInvViewProjMat = ctx.m_matrices.m_invertedViewProjection; diff --git a/AnKi/Renderer/ProbeReflections.cpp b/AnKi/Renderer/ProbeReflections.cpp index df7a049ac..745041ee6 100644 --- a/AnKi/Renderer/ProbeReflections.cpp +++ b/AnKi/Renderer/ProbeReflections.cpp @@ -401,7 +401,7 @@ void ProbeReflections::populateRenderGraph(RenderingContext& rctx) dsInfo.m_directionalLightShadowmapRenderTarget = shadowMapRt; } dsInfo.m_skyLutRenderTarget = (getRenderer().getSky().isEnabled()) ? getRenderer().getSky().getSkyLutRt() : RenderTargetHandle(); - dsInfo.m_globalRendererConsts = rctx.m_globalRenderingUniformsBuffer; + dsInfo.m_globalRendererConsts = rctx.m_globalRenderingConstantsBuffer; dsInfo.m_renderpassContext = &rgraphCtx; m_lightShading.m_deferred.drawLights(dsInfo); diff --git a/AnKi/Renderer/Renderer.cpp b/AnKi/Renderer/Renderer.cpp index 05642a750..4c222ae91 100644 --- a/AnKi/Renderer/Renderer.cpp +++ b/AnKi/Renderer/Renderer.cpp @@ -298,8 +298,8 @@ Error Renderer::populateRenderGraph(RenderingContext& ctx) ctx.m_cameraFar = cam.getFar(); // Allocate global constants - GlobalRendererUniforms* globalUnis; - ctx.m_globalRenderingUniformsBuffer = RebarTransientMemoryPool::getSingleton().allocateFrame(1, globalUnis); + GlobalRendererConstants* globalUnis; + ctx.m_globalRenderingConstantsBuffer = RebarTransientMemoryPool::getSingleton().allocateFrame(1, globalUnis); // Import RTs first m_downscaleBlur->importRenderTargets(ctx); @@ -353,39 +353,39 @@ Error Renderer::populateRenderGraph(RenderingContext& ctx) return Error::kNone; } -void Renderer::writeGlobalRendererConstants(RenderingContext& ctx, GlobalRendererUniforms& unis) +void Renderer::writeGlobalRendererConstants(RenderingContext& ctx, GlobalRendererConstants& consts) { ANKI_TRACE_SCOPED_EVENT(RWriteGlobalRendererConstants); - unis.m_renderingSize = Vec2(F32(m_internalResolution.x()), F32(m_internalResolution.y())); + consts.m_renderingSize = Vec2(F32(m_internalResolution.x()), F32(m_internalResolution.y())); - unis.m_time = F32(HighRezTimer::getCurrentTime()); - unis.m_frame = m_frameCount & kMaxU32; + consts.m_time = F32(HighRezTimer::getCurrentTime()); + consts.m_frame = m_frameCount & kMaxU32; Plane nearPlane; extractClipPlane(ctx.m_matrices.m_viewProjection, FrustumPlaneType::kNear, nearPlane); - unis.m_nearPlaneWSpace = Vec4(nearPlane.getNormal().xyz(), nearPlane.getOffset()); - unis.m_near = ctx.m_cameraNear; - unis.m_far = ctx.m_cameraFar; - unis.m_cameraPosition = ctx.m_matrices.m_cameraTransform.getTranslationPart().xyz(); + consts.m_nearPlaneWSpace = Vec4(nearPlane.getNormal().xyz(), nearPlane.getOffset()); + consts.m_near = ctx.m_cameraNear; + consts.m_far = ctx.m_cameraFar; + consts.m_cameraPosition = ctx.m_matrices.m_cameraTransform.getTranslationPart().xyz(); - unis.m_tileCounts = m_tileCounts; - unis.m_zSplitCount = m_zSplitCount; - unis.m_zSplitCountOverFrustumLength = F32(m_zSplitCount) / (ctx.m_cameraFar - ctx.m_cameraNear); - unis.m_zSplitMagic.x() = (ctx.m_cameraNear - ctx.m_cameraFar) / (ctx.m_cameraNear * F32(m_zSplitCount)); - unis.m_zSplitMagic.y() = ctx.m_cameraFar / (ctx.m_cameraNear * F32(m_zSplitCount)); - unis.m_lightVolumeLastZSplit = min(g_volumetricLightingAccumulationFinalZSplitCVar.get() - 1, m_zSplitCount); + consts.m_tileCounts = m_tileCounts; + consts.m_zSplitCount = m_zSplitCount; + consts.m_zSplitCountOverFrustumLength = F32(m_zSplitCount) / (ctx.m_cameraFar - ctx.m_cameraNear); + consts.m_zSplitMagic.x() = (ctx.m_cameraNear - ctx.m_cameraFar) / (ctx.m_cameraNear * F32(m_zSplitCount)); + consts.m_zSplitMagic.y() = ctx.m_cameraFar / (ctx.m_cameraNear * F32(m_zSplitCount)); + consts.m_lightVolumeLastZSplit = min(g_volumetricLightingAccumulationFinalZSplitCVar.get() - 1, m_zSplitCount); - unis.m_reflectionProbesMipCount = F32(m_probeReflections->getReflectionTextureMipmapCount()); + consts.m_reflectionProbesMipCount = F32(m_probeReflections->getReflectionTextureMipmapCount()); - unis.m_matrices = ctx.m_matrices; - unis.m_previousMatrices = ctx.m_prevMatrices; + consts.m_matrices = ctx.m_matrices; + consts.m_previousMatrices = ctx.m_prevMatrices; // Directional light const LightComponent* dirLight = SceneGraph::getSingleton().getDirectionalLight(); if(dirLight) { - DirectionalLight& out = unis.m_directionalLight; + DirectionalLight& out = consts.m_directionalLight; const U32 shadowCascadeCount = (dirLight->getShadowEnabled()) ? g_shadowCascadeCountCVar.get() : 0; out.m_diffuseColor = dirLight->getDiffuseColor().xyz(); @@ -404,7 +404,7 @@ void Renderer::writeGlobalRendererConstants(RenderingContext& ctx, GlobalRendere } else { - unis.m_directionalLight.m_shadowCascadeCount_31bit_active_1bit = 0; + consts.m_directionalLight.m_shadowCascadeCount_31bit_active_1bit = 0; } } @@ -561,7 +561,7 @@ TexturePtr Renderer::createAndClearRenderTarget(const TextureInitInfo& inf, Text cmdb->bindShaderProgram(&variant->getProgram()); - cmdb->setPushConstants(&clearVal.m_colorf[0], sizeof(clearVal.m_colorf)); + cmdb->setFastConstants(&clearVal.m_colorf[0], sizeof(clearVal.m_colorf)); const TextureView view(tex.get(), TextureSubresourceDesc::surface(mip, face, layer)); diff --git a/AnKi/Renderer/Renderer.h b/AnKi/Renderer/Renderer.h index 73fa66b1d..92463ca10 100644 --- a/AnKi/Renderer/Renderer.h +++ b/AnKi/Renderer/Renderer.h @@ -243,7 +243,7 @@ class Renderer void updatePipelineStats(); #endif - void writeGlobalRendererConstants(RenderingContext& ctx, GlobalRendererUniforms& unis); + void writeGlobalRendererConstants(RenderingContext& ctx, GlobalRendererConstants& consts); }; /// @} diff --git a/AnKi/Renderer/RtShadows.cpp b/AnKi/Renderer/RtShadows.cpp index d654a0f0f..4f0ec11b7 100644 --- a/AnKi/Renderer/RtShadows.cpp +++ b/AnKi/Renderer/RtShadows.cpp @@ -266,13 +266,13 @@ void RtShadows::populateRenderGraph(RenderingContext& ctx) cmdb.bindSrv(3, 0, BufferView(&m_rtLibraryGrProg->getShaderGroupHandlesGpuBuffer())); cmdb.bindUav(0, 0, sbtBuffer); - RtShadowsSbtBuildUniforms unis = {}; + RtShadowsSbtBuildConstants consts = {}; ANKI_ASSERT(m_sbtRecordSize % 4 == 0); - unis.m_sbtRecordDwordSize = m_sbtRecordSize / 4; + consts.m_sbtRecordDwordSize = m_sbtRecordSize / 4; const U32 shaderHandleSize = GrManager::getSingleton().getDeviceCapabilities().m_shaderGroupHandleSize; ANKI_ASSERT(shaderHandleSize % 4 == 0); - unis.m_shaderHandleDwordSize = shaderHandleSize / 4; - cmdb.setPushConstants(&unis, sizeof(unis)); + consts.m_shaderHandleDwordSize = shaderHandleSize / 4; + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.dispatchComputeIndirect(sbtBuildIndirectArgsBuffer); }); @@ -303,12 +303,12 @@ void RtShadows::populateRenderGraph(RenderingContext& ctx) // Allocate, set and bind global uniforms { - MaterialGlobalUniforms* globalUniforms; - const RebarAllocation globalUniformsToken = RebarTransientMemoryPool::getSingleton().allocateFrame(1, globalUniforms); + MaterialGlobalConstants* globalConstants; + const RebarAllocation globalConstantsToken = RebarTransientMemoryPool::getSingleton().allocateFrame(1, globalConstants); - memset(globalUniforms, 0, sizeof(*globalUniforms)); // Don't care for now + memset(globalConstants, 0, sizeof(*globalConstants)); // Don't care for now - cmdb.bindConstantBuffer(ANKI_MATERIAL_REGISTER_GLOBAL_UNIFORMS, 0, globalUniformsToken); + cmdb.bindConstantBuffer(ANKI_MATERIAL_REGISTER_GLOBAL_CONSTANTS, 0, globalConstantsToken); } // More globals @@ -323,7 +323,7 @@ void RtShadows::populateRenderGraph(RenderingContext& ctx) Format::k##fmt); #include - cmdb.bindConstantBuffer(0, 2, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(0, 2, ctx.m_globalRenderingConstantsBuffer); cmdb.bindSampler(0, 2, getRenderer().getSamplers().m_trilinearRepeat.get()); @@ -407,7 +407,7 @@ void RtShadows::populateRenderGraph(RenderingContext& ctx) rgraphCtx.bindUav(1, 0, m_runCtx.m_varianceRts[1]); const Mat4& invProjMat = ctx.m_matrices.m_projectionJitter.getInverse(); - cmdb.setPushConstants(&invProjMat, sizeof(invProjMat)); + cmdb.setFastConstants(&invProjMat, sizeof(invProjMat)); dispatchPPCompute(cmdb, 8, 8, getRenderer().getInternalResolution().x() / 2, getRenderer().getInternalResolution().y() / 2); }); @@ -472,7 +472,7 @@ void RtShadows::populateRenderGraph(RenderingContext& ctx) } const Mat4& invProjMat = ctx.m_matrices.m_projectionJitter.getInverse(); - cmdb.setPushConstants(&invProjMat, sizeof(invProjMat)); + cmdb.setFastConstants(&invProjMat, sizeof(invProjMat)); dispatchPPCompute(cmdb, 8, 8, getRenderer().getInternalResolution().x() / 2, getRenderer().getInternalResolution().y() / 2); }); @@ -523,12 +523,12 @@ void RtShadows::runDenoise(const RenderingContext& ctx, RenderPassWorkContext& r rgraphCtx.bindUav(0, 0, (horizontal) ? m_runCtx.m_intermediateShadowsRts[1] : m_runCtx.m_historyRt); - RtShadowsDenoiseUniforms consts; + RtShadowsDenoiseConstants consts; consts.m_invViewProjMat = ctx.m_matrices.m_invertedViewProjectionJitter; consts.m_time = F32(GlobalFrameIndex::getSingleton().m_value % 0xFFFFu); consts.m_minSampleCount = 8; consts.m_maxSampleCount = 32; - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); dispatchPPCompute(cmdb, 8, 8, getRenderer().getInternalResolution().x() / 2, getRenderer().getInternalResolution().y() / 2); } diff --git a/AnKi/Renderer/Scale.cpp b/AnKi/Renderer/Scale.cpp index 0d603999f..e49a6f42d 100644 --- a/AnKi/Renderer/Scale.cpp +++ b/AnKi/Renderer/Scale.cpp @@ -326,7 +326,7 @@ void Scale::runFsrOrBilinearScaling(RenderPassWorkContext& rgraphCtx) pc.m_viewportSize = getRenderer().getPostProcessResolution(); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); } else if(preferCompute) { @@ -339,7 +339,7 @@ void Scale::runFsrOrBilinearScaling(RenderPassWorkContext& rgraphCtx) pc.m_viewportSize = Vec2(getRenderer().getPostProcessResolution()); pc.m_viewportSizeU = getRenderer().getPostProcessResolution(); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); } if(preferCompute) @@ -389,7 +389,7 @@ void Scale::runRcasSharpening(RenderPassWorkContext& rgraphCtx) pc.m_viewportSize = getRenderer().getPostProcessResolution(); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); if(preferCompute) { @@ -449,7 +449,7 @@ void Scale::runTonemapping(RenderPassWorkContext& rgraphCtx) } pc; pc.m_viewportSizeOverOne = 1.0f / Vec2(getRenderer().getPostProcessResolution()); pc.m_viewportSize = getRenderer().getPostProcessResolution(); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); rgraphCtx.bindUav(1, 0, outRt); dispatchPPCompute(cmdb, 8, 8, getRenderer().getPostProcessResolution().x(), getRenderer().getPostProcessResolution().y()); diff --git a/AnKi/Renderer/ShadowMapping.cpp b/AnKi/Renderer/ShadowMapping.cpp index 56fb75846..a00ea3384 100644 --- a/AnKi/Renderer/ShadowMapping.cpp +++ b/AnKi/Renderer/ShadowMapping.cpp @@ -554,7 +554,7 @@ BufferView ShadowMapping::createVetVisibilityPass(CString passName, const LightC cmdb.bindShaderProgram(m_vetVisibilityGrProg.get()); const UVec4 lightIndex(lightc.getGpuSceneLightAllocation().getIndex()); - cmdb.setPushConstants(&lightIndex, sizeof(lightIndex)); + cmdb.setFastConstants(&lightIndex, sizeof(lightIndex)); cmdb.bindSrv(0, 0, hashBuff); cmdb.bindUav(0, 0, mdiBuff.isValid() ? mdiBuff : BufferView(&getRenderer().getDummyBuffer()).setRange(sizeof(U32))); diff --git a/AnKi/Renderer/ShadowmapsResolve.cpp b/AnKi/Renderer/ShadowmapsResolve.cpp index a9da36309..affa2c6ec 100644 --- a/AnKi/Renderer/ShadowmapsResolve.cpp +++ b/AnKi/Renderer/ShadowmapsResolve.cpp @@ -111,7 +111,7 @@ void ShadowmapsResolve::run(RenderPassWorkContext& rgraphCtx, RenderingContext& cmdb.bindShaderProgram(m_grProg.get()); - cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); cmdb.bindSrv(0, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight)); cmdb.bindSrv(1, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight)); rgraphCtx.bindSrv(2, 0, getRenderer().getShadowMapping().getShadowmapRt()); @@ -139,7 +139,7 @@ void ShadowmapsResolve::run(RenderPassWorkContext& rgraphCtx, RenderingContext& if(g_preferComputeCVar.get() || g_shadowMappingPcfCVar.get()) { const Vec4 consts(F32(m_rtDescr.m_width), F32(m_rtDescr.m_height), 0.0f, 0.0f); - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); } if(g_preferComputeCVar.get()) diff --git a/AnKi/Renderer/Sky.cpp b/AnKi/Renderer/Sky.cpp index ebbdb6d9e..5dac1b2d0 100644 --- a/AnKi/Renderer/Sky.cpp +++ b/AnKi/Renderer/Sky.cpp @@ -161,7 +161,7 @@ void Sky::populateRenderGraph(RenderingContext& ctx) rgraphCtx.bindSrv(1, 0, multipleScatteringLutRt); cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get()); rgraphCtx.bindUav(0, 0, m_runCtx.m_skyLutRt); - cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); dispatchPPCompute(cmdb, 8, 8, kSkyLutSize.x(), kSkyLutSize.y()); }); @@ -181,7 +181,7 @@ void Sky::populateRenderGraph(RenderingContext& ctx) cmdb.bindShaderProgram(m_computeSunColorGrProg.get()); rgraphCtx.bindSrv(0, 0, transmittanceLutRt); - cmdb.bindUav(0, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindUav(0, 0, ctx.m_globalRenderingConstantsBuffer); cmdb.dispatchCompute(1, 1, 1); }); diff --git a/AnKi/Renderer/Ssao.cpp b/AnKi/Renderer/Ssao.cpp index 26290396a..24ce72327 100644 --- a/AnKi/Renderer/Ssao.cpp +++ b/AnKi/Renderer/Ssao.cpp @@ -139,7 +139,7 @@ void Ssao::populateRenderGraph(RenderingContext& ctx) const UVec2 rez = (g_ssaoQuarterRez.get()) ? getRenderer().getInternalResolution() / 2u : getRenderer().getInternalResolution(); - SsaoUniforms consts; + SsaoConstants consts; consts.m_radius = g_ssaoRadiusCVar.get(); consts.m_sampleCount = g_ssaoSampleCountCVar.get(); consts.m_viewportSizef = Vec2(rez); @@ -151,7 +151,7 @@ void Ssao::populateRenderGraph(RenderingContext& ctx) consts.m_frameCount = getRenderer().getFrameCount() % kMaxU32; consts.m_ssaoPower = g_ssaoPower.get(); consts.m_viewMat = ctx.m_matrices.m_view; - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); if(g_preferComputeCVar.get()) { @@ -199,10 +199,10 @@ void Ssao::populateRenderGraph(RenderingContext& ctx) const UVec2 rez = (g_ssaoQuarterRez.get()) ? getRenderer().getInternalResolution() / 2u : getRenderer().getInternalResolution(); - SsaoSpatialDenoiseUniforms consts; + SsaoSpatialDenoiseConstants consts; computeLinearizeDepthOptimal(ctx.m_cameraNear, ctx.m_cameraFar, consts.m_linearizeDepthParams.x(), consts.m_linearizeDepthParams.y()); consts.m_viewToWorldMat = ctx.m_matrices.m_cameraTransform; - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); if(g_preferComputeCVar.get()) { diff --git a/AnKi/Renderer/Ssr.cpp b/AnKi/Renderer/Ssr.cpp index 13f24ad82..767e9b3c2 100644 --- a/AnKi/Renderer/Ssr.cpp +++ b/AnKi/Renderer/Ssr.cpp @@ -115,7 +115,7 @@ void Ssr::populateRenderGraph(RenderingContext& ctx) cmdb.bindShaderProgram(m_ssrGrProg.get()); - SsrUniforms consts = {}; + SsrConstants consts = {}; consts.m_viewportSizef = Vec2(rez); consts.m_frameCount = getRenderer().getFrameCount() % kMaxU32; consts.m_maxIterations = g_ssrMaxIterationsCVar.get(); @@ -126,7 +126,7 @@ void Ssr::populateRenderGraph(RenderingContext& ctx) consts.m_unprojectionParameters = ctx.m_matrices.m_unprojectionParameters; consts.m_prevViewProjMatMulInvViewProjMat = ctx.m_prevMatrices.m_viewProjection * ctx.m_matrices.m_viewProjectionJitter.getInverse(); consts.m_normalMat = Mat3x4(Vec3(0.0f), ctx.m_matrices.m_view.getRotationPart()); - *allocateAndBindConstants(cmdb, 0, 0) = consts; + *allocateAndBindConstants(cmdb, 0, 0) = consts; cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get()); rgraphCtx.bindSrv(0, 0, getRenderer().getGBuffer().getColorRt(1)); diff --git a/AnKi/Renderer/Utils/Drawer.cpp b/AnKi/Renderer/Utils/Drawer.cpp index 9a146beba..14d6840cd 100644 --- a/AnKi/Renderer/Utils/Drawer.cpp +++ b/AnKi/Renderer/Utils/Drawer.cpp @@ -31,20 +31,20 @@ void RenderableDrawer::setState(const RenderableDrawerArguments& args, CommandBu { // Allocate, set and bind global uniforms { - MaterialGlobalUniforms* globalUniforms; - const RebarAllocation globalUniformsToken = RebarTransientMemoryPool::getSingleton().allocateFrame(1, globalUniforms); + MaterialGlobalConstants* globalConstants; + const RebarAllocation globalConstantsToken = RebarTransientMemoryPool::getSingleton().allocateFrame(1, globalConstants); - globalUniforms->m_viewProjectionMatrix = args.m_viewProjectionMatrix; - globalUniforms->m_previousViewProjectionMatrix = args.m_previousViewProjectionMatrix; - static_assert(sizeof(globalUniforms->m_viewTransform) == sizeof(args.m_viewMatrix)); - memcpy(&globalUniforms->m_viewTransform, &args.m_viewMatrix, sizeof(args.m_viewMatrix)); - static_assert(sizeof(globalUniforms->m_cameraTransform) == sizeof(args.m_cameraTransform)); - memcpy(&globalUniforms->m_cameraTransform, &args.m_cameraTransform, sizeof(args.m_cameraTransform)); + globalConstants->m_viewProjectionMatrix = args.m_viewProjectionMatrix; + globalConstants->m_previousViewProjectionMatrix = args.m_previousViewProjectionMatrix; + static_assert(sizeof(globalConstants->m_viewTransform) == sizeof(args.m_viewMatrix)); + memcpy(&globalConstants->m_viewTransform, &args.m_viewMatrix, sizeof(args.m_viewMatrix)); + static_assert(sizeof(globalConstants->m_cameraTransform) == sizeof(args.m_cameraTransform)); + memcpy(&globalConstants->m_cameraTransform, &args.m_cameraTransform, sizeof(args.m_cameraTransform)); ANKI_ASSERT(args.m_viewport != UVec4(0u)); - globalUniforms->m_viewport = Vec4(args.m_viewport); + globalConstants->m_viewport = Vec4(args.m_viewport); - cmdb.bindConstantBuffer(ANKI_MATERIAL_REGISTER_GLOBAL_UNIFORMS, 0, globalUniformsToken); + cmdb.bindConstantBuffer(ANKI_MATERIAL_REGISTER_GLOBAL_CONSTANTS, 0, globalConstantsToken); } // More globals @@ -124,7 +124,7 @@ void RenderableDrawer::drawMdi(const RenderableDrawerArguments& args, CommandBuf if(bMeshlets && meshShaderHwSupport) { const UVec4 consts(bucketIdx); - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.drawMeshTasksIndirect(BufferView(args.m_mesh.m_dispatchMeshIndirectArgsBuffer) .incrementOffset(sizeof(DispatchIndirectArgs) * bucketIdx) diff --git a/AnKi/Renderer/Utils/GpuVisibility.cpp b/AnKi/Renderer/Utils/GpuVisibility.cpp index aac08976a..76af1b140 100644 --- a/AnKi/Renderer/Utils/GpuVisibility.cpp +++ b/AnKi/Renderer/Utils/GpuVisibility.cpp @@ -666,24 +666,24 @@ void GpuVisibility::populateRenderGraphInternal(Bool distanceBased, BaseGpuVisib if(frustumTestData) { - FrustumGpuVisibilityUniforms* unis = allocateAndBindConstants(cmdb, 0, 0); + FrustumGpuVisibilityConsts* consts = allocateAndBindConstants(cmdb, 0, 0); Array planes; extractClipPlanes(frustumTestData->m_viewProjMat, planes); for(U32 i = 0; i < 6; ++i) { - unis->m_clipPlanes[i] = Vec4(planes[i].getNormal().xyz(), planes[i].getOffset()); + consts->m_clipPlanes[i] = Vec4(planes[i].getNormal().xyz(), planes[i].getOffset()); } ANKI_ASSERT(kMaxLodCount == 3); - unis->m_maxLodDistances[0] = lodDistances[0]; - unis->m_maxLodDistances[1] = lodDistances[1]; - unis->m_maxLodDistances[2] = kMaxF32; - unis->m_maxLodDistances[3] = kMaxF32; + consts->m_maxLodDistances[0] = lodDistances[0]; + consts->m_maxLodDistances[1] = lodDistances[1]; + consts->m_maxLodDistances[2] = kMaxF32; + consts->m_maxLodDistances[3] = kMaxF32; - unis->m_lodReferencePoint = lodReferencePoint; - unis->m_viewProjectionMat = frustumTestData->m_viewProjMat; - unis->m_finalRenderTargetSize = Vec2(frustumTestData->m_finalRenderTargetSize); + consts->m_lodReferencePoint = lodReferencePoint; + consts->m_viewProjectionMat = frustumTestData->m_viewProjMat; + consts->m_finalRenderTargetSize = Vec2(frustumTestData->m_finalRenderTargetSize); if(frustumTestData->m_hzbRt.isValid()) { @@ -693,18 +693,18 @@ void GpuVisibility::populateRenderGraphInternal(Bool distanceBased, BaseGpuVisib } else { - DistanceGpuVisibilityUniforms unis; - unis.m_pointOfTest = distTestData->m_pointOfTest; - unis.m_testRadius = distTestData->m_testRadius; + DistanceGpuVisibilityConstants consts; + consts.m_pointOfTest = distTestData->m_pointOfTest; + consts.m_testRadius = distTestData->m_testRadius; - unis.m_maxLodDistances[0] = lodDistances[0]; - unis.m_maxLodDistances[1] = lodDistances[1]; - unis.m_maxLodDistances[2] = kMaxF32; - unis.m_maxLodDistances[3] = kMaxF32; + consts.m_maxLodDistances[0] = lodDistances[0]; + consts.m_maxLodDistances[1] = lodDistances[1]; + consts.m_maxLodDistances[2] = kMaxF32; + consts.m_maxLodDistances[3] = kMaxF32; - unis.m_lodReferencePoint = lodReferencePoint; + consts.m_lodReferencePoint = lodReferencePoint; - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); } dispatchPPCompute(cmdb, 64, 1, aabbCount, 1); @@ -798,12 +798,12 @@ void GpuVisibility::populateRenderGraphInternal(Bool distanceBased, BaseGpuVisib if(!passthrough) { - GpuVisibilityMeshletUniforms consts; + GpuVisibilityMeshletConstants consts; consts.m_viewProjectionMatrix = frustumTestData->m_viewProjMat; consts.m_cameraPos = lodReferencePoint; consts.m_viewportSizef = Vec2(frustumTestData->m_finalRenderTargetSize); - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); } cmdb.dispatchComputeIndirect( @@ -875,11 +875,11 @@ void GpuVisibility::populateRenderGraphStage3(FrustumGpuVisibilityInput& in, Gpu cmdb.bindUav(3, 0, m_outOfMemoryReadbackBuffer); - GpuVisibilityMeshletUniforms consts; + GpuVisibilityMeshletConstants consts; consts.m_viewProjectionMatrix = in.m_viewProjectionMatrix; consts.m_cameraPos = in.m_lodReferencePoint; consts.m_viewportSizef = Vec2(in.m_viewportSize); - cmdb.setPushConstants(&consts, sizeof(consts)); + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.dispatchComputeIndirect(BufferView(stage1And2Mem.m_gpuVisIndirectDispatchArgs) .incrementOffset(sizeof(DispatchIndirectArgs) * U32(GpuVisibilityIndirectDispatches::k3rdStageMeshlets)) @@ -1041,14 +1041,14 @@ void GpuVisibilityNonRenderables::populateRenderGraph(GpuVisibilityNonRenderable } cmdb.bindSrv(0, 0, objBuffer); - GpuVisibilityNonRenderableUniforms unis; + GpuVisibilityNonRenderableConstants consts; Array planes; extractClipPlanes(viewProjectionMat, planes); for(U32 i = 0; i < 6; ++i) { - unis.m_clipPlanes[i] = Vec4(planes[i].getNormal().xyz(), planes[i].getOffset()); + consts.m_clipPlanes[i] = Vec4(planes[i].getNormal().xyz(), planes[i].getOffset()); } - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); rgraph.bindUav(0, 0, visibleIndicesBuffHandle); cmdb.bindUav(1, 0, BufferView(counterBuffer.get(), counterBufferOffset, sizeof(U32) * kCountersPerDispatch)); @@ -1113,24 +1113,24 @@ void GpuVisibilityAccelerationStructures::pupulateRenderGraph(GpuVisibilityAccel cmdb.bindShaderProgram(m_visibilityGrProg.get()); - GpuVisibilityAccelerationStructuresUniforms unis; + GpuVisibilityAccelerationStructuresConstants consts; Array planes; extractClipPlanes(viewProjMat, planes); for(U32 i = 0; i < 6; ++i) { - unis.m_clipPlanes[i] = Vec4(planes[i].getNormal().xyz(), planes[i].getOffset()); + consts.m_clipPlanes[i] = Vec4(planes[i].getNormal().xyz(), planes[i].getOffset()); } - unis.m_pointOfTest = pointOfTest; - unis.m_testRadius = testRadius; + consts.m_pointOfTest = pointOfTest; + consts.m_testRadius = testRadius; ANKI_ASSERT(kMaxLodCount == 3); - unis.m_maxLodDistances[0] = lodDistances[0]; - unis.m_maxLodDistances[1] = lodDistances[1]; - unis.m_maxLodDistances[2] = kMaxF32; - unis.m_maxLodDistances[3] = kMaxF32; + consts.m_maxLodDistances[0] = lodDistances[0]; + consts.m_maxLodDistances[1] = lodDistances[1]; + consts.m_maxLodDistances[2] = kMaxF32; + consts.m_maxLodDistances[3] = kMaxF32; - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.bindSrv(0, 0, GpuSceneArrays::RenderableBoundingVolumeRt::getSingleton().getBufferView()); cmdb.bindSrv(1, 0, GpuSceneArrays::Renderable::getSingleton().getBufferView()); diff --git a/AnKi/Renderer/Utils/HzbGenerator.cpp b/AnKi/Renderer/Utils/HzbGenerator.cpp index 66f7653d3..443e832ca 100644 --- a/AnKi/Renderer/Utils/HzbGenerator.cpp +++ b/AnKi/Renderer/Utils/HzbGenerator.cpp @@ -120,7 +120,7 @@ void HzbGenerator::populateRenderGraphInternal(ConstWeakArray dis varAU4(rectInfo) = initAU4(0, 0, in.m_dstHzbRtSize.x() * 2, in.m_dstHzbRtSize.y() * 2); SpdSetup(dispatchThreadGroupCountXY, workGroupOffset, numWorkGroupsAndMips, rectInfo, mipsToCompute); - struct Uniforms + struct Constants { Vec2 m_invSrcTexSize; U32 m_threadGroupCount; @@ -131,7 +131,7 @@ void HzbGenerator::populateRenderGraphInternal(ConstWeakArray dis pc.m_threadGroupCount = numWorkGroupsAndMips[0]; pc.m_mipmapCount = numWorkGroupsAndMips[1]; - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); for(U32 mip = 0; mip < kMaxMipsSinglePassDownsamplerCanProduce; ++mip) { @@ -271,7 +271,7 @@ void HzbGenerator::populateRenderGraphDirectionalLight(const HzbDirectionalLight rgraphCtx.bindSrv(0, 0, maxDepthRt); - struct Uniforms + struct Constants { Mat4 m_reprojectionMat; @@ -279,13 +279,13 @@ void HzbGenerator::populateRenderGraphDirectionalLight(const HzbDirectionalLight F32 m_cascadeMaxDepth; F32 m_padding0; F32 m_padding1; - } unis; + } consts; - unis.m_reprojectionMat = lightViewProjMat * invViewProjMat; - unis.m_cascadeMinDepth = cascadeMinDepth; - unis.m_cascadeMaxDepth = cascadeMaxDepth; + consts.m_reprojectionMat = lightViewProjMat * invViewProjMat; + consts.m_cascadeMinDepth = cascadeMinDepth; + consts.m_cascadeMaxDepth = cascadeMaxDepth; - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); cmdb.bindIndexBuffer(BufferView(m_boxIndexBuffer.get()), IndexType::kU16); diff --git a/AnKi/Renderer/Utils/TraditionalDeferredShading.cpp b/AnKi/Renderer/Utils/TraditionalDeferredShading.cpp index 40cabc1c6..47b97d57a 100644 --- a/AnKi/Renderer/Utils/TraditionalDeferredShading.cpp +++ b/AnKi/Renderer/Utils/TraditionalDeferredShading.cpp @@ -62,15 +62,15 @@ void TraditionalDeferredLightShading::drawLights(TraditionalDeferredLightShading cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_nearestNearestClamp.get()); rgraphCtx.bindSrv(0, 0, info.m_gbufferDepthRenderTarget, info.m_gbufferDepthRenderTargetSubresource); - TraditionalDeferredSkyboxUniforms unis = {}; - unis.m_invertedViewProjectionMat = info.m_invViewProjectionMatrix; - unis.m_cameraPos = info.m_cameraPosWSpace.xyz(); - unis.m_scale = skyc->getImageScale(); - unis.m_bias = skyc->getImageBias(); + TraditionalDeferredSkyboxConstants consts = {}; + consts.m_invertedViewProjectionMat = info.m_invViewProjectionMatrix; + consts.m_cameraPos = info.m_cameraPosWSpace.xyz(); + consts.m_scale = skyc->getImageScale(); + consts.m_bias = skyc->getImageBias(); if(skyc->getSkyboxType() == SkyboxType::kSolidColor) { - unis.m_solidColor = skyc->getSolidColor(); + consts.m_solidColor = skyc->getSolidColor(); } else if(skyc->getSkyboxType() == SkyboxType::kImage2D) { @@ -85,22 +85,22 @@ void TraditionalDeferredLightShading::drawLights(TraditionalDeferredLightShading cmdb.bindConstantBuffer(0, 0, info.m_globalRendererConsts); - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); drawQuad(cmdb); } // Light shading { - TraditionalDeferredShadingUniforms* unis = allocateAndBindConstants(cmdb, 0, 0); + TraditionalDeferredShadingConstants* consts = allocateAndBindConstants(cmdb, 0, 0); - unis->m_invViewProjMat = info.m_invViewProjectionMatrix; - unis->m_cameraPos = info.m_cameraPosWSpace.xyz(); + consts->m_invViewProjMat = info.m_invViewProjectionMatrix; + consts->m_cameraPos = info.m_cameraPosWSpace.xyz(); if(dirLightc) { - unis->m_dirLight.m_effectiveShadowDistance = info.m_effectiveShadowDistance; - unis->m_dirLight.m_lightMatrix = info.m_dirLightMatrix; + consts->m_dirLight.m_effectiveShadowDistance = info.m_effectiveShadowDistance; + consts->m_dirLight.m_lightMatrix = info.m_dirLightMatrix; } cmdb.bindSrv(0, 0, info.m_visibleLightsBuffer); diff --git a/AnKi/Renderer/VolumetricFog.cpp b/AnKi/Renderer/VolumetricFog.cpp index 7c24739ff..8099b3447 100644 --- a/AnKi/Renderer/VolumetricFog.cpp +++ b/AnKi/Renderer/VolumetricFog.cpp @@ -65,17 +65,17 @@ void VolumetricFog::populateRenderGraph(RenderingContext& ctx) const SkyboxComponent* sky = SceneGraph::getSingleton().getSkybox(); - VolumetricFogUniforms regs; - regs.m_fogDiffuse = (sky) ? sky->getFogDiffuseColor() : Vec3(0.0f); - regs.m_fogScatteringCoeff = (sky) ? sky->getFogScatteringCoefficient() : 0.0f; - regs.m_fogAbsorptionCoeff = (sky) ? sky->getFogAbsorptionCoefficient() : 0.0f; - regs.m_near = ctx.m_cameraNear; - regs.m_far = ctx.m_cameraFar; - regs.m_zSplitCountf = F32(getRenderer().getZSplitCount()); - regs.m_volumeSize = UVec3(m_volumeSize); - regs.m_maxZSplitsToProcessf = F32(m_finalZSplit + 1); - - cmdb.setPushConstants(®s, sizeof(regs)); + VolumetricFogConstants consts; + consts.m_fogDiffuse = (sky) ? sky->getFogDiffuseColor() : Vec3(0.0f); + consts.m_fogScatteringCoeff = (sky) ? sky->getFogScatteringCoefficient() : 0.0f; + consts.m_fogAbsorptionCoeff = (sky) ? sky->getFogAbsorptionCoefficient() : 0.0f; + consts.m_near = ctx.m_cameraNear; + consts.m_far = ctx.m_cameraFar; + consts.m_zSplitCountf = F32(getRenderer().getZSplitCount()); + consts.m_volumeSize = UVec3(m_volumeSize); + consts.m_maxZSplitsToProcessf = F32(m_finalZSplit + 1); + + cmdb.setFastConstants(&consts, sizeof(consts)); dispatchPPCompute(cmdb, 8, 8, m_volumeSize[0], m_volumeSize[1]); }); diff --git a/AnKi/Renderer/VolumetricLightingAccumulation.cpp b/AnKi/Renderer/VolumetricLightingAccumulation.cpp index b3a04339b..6f8899f93 100644 --- a/AnKi/Renderer/VolumetricLightingAccumulation.cpp +++ b/AnKi/Renderer/VolumetricLightingAccumulation.cpp @@ -105,7 +105,7 @@ void VolumetricLightingAccumulation::populateRenderGraph(RenderingContext& ctx) rgraphCtx.bindSrv(1, 0, m_runCtx.m_rts[0]); - cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingUniformsBuffer); + cmdb.bindConstantBuffer(0, 0, ctx.m_globalRenderingConstantsBuffer); cmdb.bindSrv(2, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight)); cmdb.bindSrv(3, 0, getRenderer().getClusterBinning().getPackedObjectsBuffer(GpuSceneNonRenderableObjectType::kLight)); rgraphCtx.bindSrv(4, 0, getRenderer().getShadowMapping().getShadowmapRt()); @@ -115,34 +115,34 @@ void VolumetricLightingAccumulation::populateRenderGraph(RenderingContext& ctx) const SkyboxComponent* sky = SceneGraph::getSingleton().getSkybox(); - VolumetricLightingUniforms unis; + VolumetricLightingConstants consts; if(!sky) { - unis.m_minHeight = 0.0f; - unis.m_oneOverMaxMinusMinHeight = 0.0f; - unis.m_densityAtMinHeight = 0.0f; - unis.m_densityAtMaxHeight = 0.0f; + consts.m_minHeight = 0.0f; + consts.m_oneOverMaxMinusMinHeight = 0.0f; + consts.m_densityAtMinHeight = 0.0f; + consts.m_densityAtMaxHeight = 0.0f; } else if(sky->getHeightOfMaxFogDensity() > sky->getHeightOfMaxFogDensity()) { - unis.m_minHeight = sky->getHeightOfMinFogDensity(); - unis.m_oneOverMaxMinusMinHeight = 1.0f / (sky->getHeightOfMaxFogDensity() - unis.m_minHeight + kEpsilonf); - unis.m_densityAtMinHeight = sky->getMinFogDensity(); - unis.m_densityAtMaxHeight = sky->getMaxFogDensity(); + consts.m_minHeight = sky->getHeightOfMinFogDensity(); + consts.m_oneOverMaxMinusMinHeight = 1.0f / (sky->getHeightOfMaxFogDensity() - consts.m_minHeight + kEpsilonf); + consts.m_densityAtMinHeight = sky->getMinFogDensity(); + consts.m_densityAtMaxHeight = sky->getMaxFogDensity(); } else { - unis.m_minHeight = sky->getHeightOfMaxFogDensity(); - unis.m_oneOverMaxMinusMinHeight = 1.0f / (sky->getHeightOfMinFogDensity() - unis.m_minHeight + kEpsilonf); - unis.m_densityAtMinHeight = sky->getMaxFogDensity(); - unis.m_densityAtMaxHeight = sky->getMinFogDensity(); + consts.m_minHeight = sky->getHeightOfMaxFogDensity(); + consts.m_oneOverMaxMinusMinHeight = 1.0f / (sky->getHeightOfMinFogDensity() - consts.m_minHeight + kEpsilonf); + consts.m_densityAtMinHeight = sky->getMaxFogDensity(); + consts.m_densityAtMaxHeight = sky->getMinFogDensity(); } - unis.m_volumeSize = UVec3(m_volumeSize); + consts.m_volumeSize = UVec3(m_volumeSize); const U32 finalZSplit = min(getRenderer().getZSplitCount() - 1, g_volumetricLightingAccumulationFinalZSplitCVar.get()); - unis.m_maxZSplitsToProcessf = F32(finalZSplit + 1); + consts.m_maxZSplitsToProcessf = F32(finalZSplit + 1); - cmdb.setPushConstants(&unis, sizeof(unis)); + cmdb.setFastConstants(&consts, sizeof(consts)); dispatchPPCompute(cmdb, 8, 8, 8, m_volumeSize[0], m_volumeSize[1], m_volumeSize[2]); }); diff --git a/AnKi/Renderer/VrsSriGeneration.cpp b/AnKi/Renderer/VrsSriGeneration.cpp index 139b25d0e..911f5f13e 100644 --- a/AnKi/Renderer/VrsSriGeneration.cpp +++ b/AnKi/Renderer/VrsSriGeneration.cpp @@ -144,7 +144,7 @@ void VrsSriGeneration::populateRenderGraph(RenderingContext& ctx) cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_nearestNearestClamp.get()); rgraphCtx.bindUav(0, 0, m_runCtx.m_rt); const Vec4 pc(1.0f / Vec2(getRenderer().getInternalResolution()), g_vrsThresholdCVar.get(), 0.0f); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); const U32 fakeWorkgroupSizeXorY = m_sriTexelDimension; dispatchPPCompute(cmdb, fakeWorkgroupSizeXorY, fakeWorkgroupSizeXorY, getRenderer().getInternalResolution().x(), @@ -171,7 +171,7 @@ void VrsSriGeneration::populateRenderGraph(RenderingContext& ctx) cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_nearestNearestClamp.get()); rgraphCtx.bindUav(0, 0, m_runCtx.m_downscaledRt); const Vec4 pc(1.0f / Vec2(rezDownscaled), 0.0f, 0.0f); - cmdb.setPushConstants(&pc, sizeof(pc)); + cmdb.setFastConstants(&pc, sizeof(pc)); dispatchPPCompute(cmdb, 8, 8, rezDownscaled.x(), rezDownscaled.y()); }); diff --git a/AnKi/Resource/MaterialResource.cpp b/AnKi/Resource/MaterialResource.cpp index 8886df7b3..8b0ab3726 100644 --- a/AnKi/Resource/MaterialResource.cpp +++ b/AnKi/Resource/MaterialResource.cpp @@ -85,7 +85,7 @@ MaterialResource::MaterialResource() MaterialResource::~MaterialResource() { - ResourceMemoryPool::getSingleton().free(m_prefilledLocalUniforms); + ResourceMemoryPool::getSingleton().free(m_prefilledLocalConstants); } const MaterialVariable* MaterialResource::tryFindVariableInternal(CString name) const @@ -149,7 +149,7 @@ Error MaterialResource::load(const ResourceFilename& filename, Bool async) m_vars = std::move(newVars); } - prefillLocalUniforms(); + prefillLocalConstants(); return Error::kNone; } @@ -375,30 +375,30 @@ Error MaterialResource::createVars() const ShaderBinary& binary = m_prog->getBinary(); // Find struct - const ShaderBinaryStruct* localUniformsStruct = nullptr; + const ShaderBinaryStruct* localConstantsStruct = nullptr; for(const ShaderBinaryStruct& strct : binary.m_structs) { - if(CString(strct.m_name.getBegin()) == "AnKiLocalUniforms") + if(CString(strct.m_name.getBegin()) == "AnKiLocalConstants") { - localUniformsStruct = &strct; + localConstantsStruct = &strct; break; } } // Create vars - for(U32 i = 0; localUniformsStruct && i < localUniformsStruct->m_members.getSize(); ++i) + for(U32 i = 0; localConstantsStruct && i < localConstantsStruct->m_members.getSize(); ++i) { - const ShaderBinaryStructMember& member = localUniformsStruct->m_members[i]; + const ShaderBinaryStructMember& member = localConstantsStruct->m_members[i]; const CString memberName = member.m_name.getBegin(); MaterialVariable& var = *m_vars.emplaceBack(); zeroMemory(var); var.m_name = memberName; var.m_dataType = member.m_type; - var.m_offsetInLocalUniforms = member.m_offset; + var.m_offsetInLocalConstants = member.m_offset; } - m_localUniformsSize = (localUniformsStruct) ? localUniformsStruct->m_size : 0; + m_localConstantsSize = (localConstantsStruct) ? localConstantsStruct->m_size : 0; return Error::kNone; } @@ -476,15 +476,15 @@ Error MaterialResource::parseInput(XmlElement inputEl, Bool async, BitSet<128>& return Error::kNone; } -void MaterialResource::prefillLocalUniforms() +void MaterialResource::prefillLocalConstants() { - if(m_localUniformsSize == 0) + if(m_localConstantsSize == 0) { return; } - m_prefilledLocalUniforms = ResourceMemoryPool::getSingleton().allocate(m_localUniformsSize, 1); - memset(m_prefilledLocalUniforms, 0, m_localUniformsSize); + m_prefilledLocalConstants = ResourceMemoryPool::getSingleton().allocate(m_localConstantsSize, 1); + memset(m_prefilledLocalConstants, 0, m_localConstantsSize); for(const MaterialVariable& var : m_vars) { @@ -492,8 +492,8 @@ void MaterialResource::prefillLocalUniforms() { #define ANKI_SVDT_MACRO(type, baseType, rowCount, columnCount, isIntagralType) \ case ShaderVariableDataType::k##type: \ - ANKI_ASSERT(var.m_offsetInLocalUniforms + sizeof(type) <= m_localUniformsSize); \ - memcpy(static_cast(m_prefilledLocalUniforms) + var.m_offsetInLocalUniforms, &var.m_##type, sizeof(type)); \ + ANKI_ASSERT(var.m_offsetInLocalConstants + sizeof(type) <= m_localConstantsSize); \ + memcpy(static_cast(m_prefilledLocalConstants) + var.m_offsetInLocalConstants, &var.m_##type, sizeof(type)); \ break; #include #undef ANKI_SVDT_MACRO diff --git a/AnKi/Resource/MaterialResource.h b/AnKi/Resource/MaterialResource.h index 492606e2f..aaa123feb 100644 --- a/AnKi/Resource/MaterialResource.h +++ b/AnKi/Resource/MaterialResource.h @@ -56,7 +56,7 @@ class MaterialVariable MaterialVariable& operator=(MaterialVariable&& b) { m_name = std::move(b.m_name); - m_offsetInLocalUniforms = b.m_offsetInLocalUniforms; + m_offsetInLocalConstants = b.m_offsetInLocalConstants; m_dataType = b.m_dataType; m_Mat4 = b.m_Mat4; m_image = std::move(b.m_image); @@ -77,15 +77,15 @@ class MaterialVariable return m_dataType; } - U32 getOffsetInLocalUniforms() const + U32 getOffsetInLocalConstants() const { - ANKI_ASSERT(m_offsetInLocalUniforms != kMaxU32); - return m_offsetInLocalUniforms; + ANKI_ASSERT(m_offsetInLocalConstants != kMaxU32); + return m_offsetInLocalConstants; } protected: ResourceString m_name; - U32 m_offsetInLocalUniforms = kMaxU32; + U32 m_offsetInLocalConstants = kMaxU32; ShaderVariableDataType m_dataType = ShaderVariableDataType::kNone; /// Values @@ -175,7 +175,7 @@ class MaterialVariant /// /// /// [ -/// +/// /// ] /// /// @endcode @@ -214,9 +214,9 @@ class MaterialResource : public ResourceObject const MaterialVariant& getOrCreateVariant(const RenderingKey& key) const; /// Get a buffer with prefilled uniforms. - ConstWeakArray getPrefilledLocalUniforms() const + ConstWeakArray getPrefilledLocalConstants() const { - return ConstWeakArray(static_cast(m_prefilledLocalUniforms), m_localUniformsSize); + return ConstWeakArray(static_cast(m_prefilledLocalConstants), m_localConstantsSize); } private: @@ -245,8 +245,8 @@ class MaterialResource : public ResourceObject ResourceDynamicArray m_vars; - void* m_prefilledLocalUniforms = nullptr; - U32 m_localUniformsSize = 0; + void* m_prefilledLocalConstants = nullptr; + U32 m_localConstantsSize = 0; U32 m_presentBuildinMutatorMask = 0; @@ -259,7 +259,7 @@ class MaterialResource : public ResourceObject Error parseInput(XmlElement inputEl, Bool async, BitSet<128>& varsSet); Error findBuiltinMutators(); Error createVars(); - void prefillLocalUniforms(); + void prefillLocalConstants(); const MaterialVariable* tryFindVariableInternal(CString name) const; diff --git a/AnKi/Scene/Components/GlobalIlluminationProbeComponent.cpp b/AnKi/Scene/Components/GlobalIlluminationProbeComponent.cpp index 3ee4e4337..642c8bea1 100644 --- a/AnKi/Scene/Components/GlobalIlluminationProbeComponent.cpp +++ b/AnKi/Scene/Components/GlobalIlluminationProbeComponent.cpp @@ -76,7 +76,7 @@ Error GlobalIlluminationProbeComponent::update(SceneComponentUpdateInfo& info, B cmdb->bindUav(0, 0, TextureView(m_volTex.get(), TextureSubresourceDesc::all())); const Vec4 clearColor(0.0f); - cmdb->setPushConstants(&clearColor, sizeof(clearColor)); + cmdb->setFastConstants(&clearColor, sizeof(clearColor)); UVec3 wgSize; wgSize.x() = (8 - 1 + m_volTex->getWidth()) / 8; diff --git a/AnKi/Scene/Components/ModelComponent.cpp b/AnKi/Scene/Components/ModelComponent.cpp index 10265ff2f..93024cb1a 100644 --- a/AnKi/Scene/Components/ModelComponent.cpp +++ b/AnKi/Scene/Components/ModelComponent.cpp @@ -27,7 +27,7 @@ ModelComponent::~ModelComponent() void ModelComponent::freeGpuScene() { - GpuSceneBuffer::getSingleton().deferredFree(m_gpuSceneUniforms); + GpuSceneBuffer::getSingleton().deferredFree(m_gpuSceneConstants); for(PatchInfo& patch : m_patchInfos) { @@ -69,12 +69,12 @@ void ModelComponent::loadModelResource(CString filename) U32 uniformsSize = 0; for(U32 i = 0; i < modelPatchCount; ++i) { - const U32 size = U32(m_model->getModelPatches()[i].getMaterial()->getPrefilledLocalUniforms().getSizeInBytes()); + const U32 size = U32(m_model->getModelPatches()[i].getMaterial()->getPrefilledLocalConstants().getSizeInBytes()); ANKI_ASSERT((size % 4) == 0); uniformsSize += size; } - m_gpuSceneUniforms = GpuSceneBuffer::getSingleton().allocate(uniformsSize, 4); + m_gpuSceneConstants = GpuSceneBuffer::getSingleton().allocate(uniformsSize, 4); uniformsSize = 0; // Init the patches @@ -87,8 +87,8 @@ void ModelComponent::loadModelResource(CString filename) m_castsShadow = m_castsShadow || in.getMaterial()->castsShadow(); m_presentRenderingTechniques |= in.getMaterial()->getRenderingTechniques(); - out.m_gpuSceneUniformsOffset = m_gpuSceneUniforms.getOffset() + uniformsSize; - uniformsSize += U32(in.getMaterial()->getPrefilledLocalUniforms().getSizeInBytes()); + out.m_gpuSceneConstantsOffset = m_gpuSceneConstants.getOffset() + uniformsSize; + uniformsSize += U32(in.getMaterial()->getPrefilledLocalConstants().getSizeInBytes()); out.m_gpuSceneMeshLods.allocate(); out.m_gpuSceneRenderable.allocate(); @@ -206,7 +206,7 @@ Error ModelComponent::update(SceneComponentUpdateInfo& info, Bool& updated) // Upload the GpuSceneRenderable GpuSceneRenderable gpuRenderable = {}; gpuRenderable.m_worldTransformsIndex = m_gpuSceneTransforms.getIndex() * 2; - gpuRenderable.m_uniformsOffset = m_patchInfos[i].m_gpuSceneUniformsOffset; + gpuRenderable.m_constantsOffset = m_patchInfos[i].m_gpuSceneConstantsOffset; gpuRenderable.m_meshLodsIndex = m_patchInfos[i].m_gpuSceneMeshLods.getIndex() * kMaxLodCount; gpuRenderable.m_boneTransformsOffset = (hasSkin) ? m_skinComponent->getBoneTransformsGpuSceneOffset() : 0; gpuRenderable.m_particleEmitterIndex = kMaxU32; @@ -221,21 +221,21 @@ Error ModelComponent::update(SceneComponentUpdateInfo& info, Bool& updated) } // Upload the uniforms - DynamicArray> allUniforms(info.m_framePool); - allUniforms.resize(m_gpuSceneUniforms.getAllocatedSize() / 4); + DynamicArray> allConstants(info.m_framePool); + allConstants.resize(m_gpuSceneConstants.getAllocatedSize() / 4); U32 count = 0; for(U32 i = 0; i < modelPatchCount; ++i) { const ModelPatch& patch = m_model->getModelPatches()[i]; const MaterialResource& mtl = *patch.getMaterial(); - memcpy(&allUniforms[count], mtl.getPrefilledLocalUniforms().getBegin(), mtl.getPrefilledLocalUniforms().getSizeInBytes()); + memcpy(&allConstants[count], mtl.getPrefilledLocalConstants().getBegin(), mtl.getPrefilledLocalConstants().getSizeInBytes()); - count += U32(mtl.getPrefilledLocalUniforms().getSizeInBytes() / 4); + count += U32(mtl.getPrefilledLocalConstants().getSizeInBytes() / 4); } - ANKI_ASSERT(count * 4 == m_gpuSceneUniforms.getAllocatedSize()); - GpuSceneMicroPatcher::getSingleton().newCopy(*info.m_framePool, m_gpuSceneUniforms.getOffset(), m_gpuSceneUniforms.getAllocatedSize(), - &allUniforms[0]); + ANKI_ASSERT(count * 4 == m_gpuSceneConstants.getAllocatedSize()); + GpuSceneMicroPatcher::getSingleton().newCopy(*info.m_framePool, m_gpuSceneConstants.getOffset(), m_gpuSceneConstants.getAllocatedSize(), + &allConstants[0]); } // Upload transforms diff --git a/AnKi/Scene/Components/ModelComponent.h b/AnKi/Scene/Components/ModelComponent.h index 436100e40..e673d09d2 100644 --- a/AnKi/Scene/Components/ModelComponent.h +++ b/AnKi/Scene/Components/ModelComponent.h @@ -48,7 +48,7 @@ class ModelComponent final : public SceneComponent class PatchInfo { public: - U32 m_gpuSceneUniformsOffset = kMaxU32; + U32 m_gpuSceneConstantsOffset = kMaxU32; GpuSceneArrays::MeshLod::Allocation m_gpuSceneMeshLods; GpuSceneArrays::Renderable::Allocation m_gpuSceneRenderable; @@ -66,7 +66,7 @@ class ModelComponent final : public SceneComponent ModelResourcePtr m_model; // GPU scene part 1 - GpuSceneBufferAllocation m_gpuSceneUniforms; + GpuSceneBufferAllocation m_gpuSceneConstants; GpuSceneArrays::Transform::Allocation m_gpuSceneTransforms; // Other stuff diff --git a/AnKi/Scene/Components/ParticleEmitterComponent.cpp b/AnKi/Scene/Components/ParticleEmitterComponent.cpp index 40e1f0f59..ea177294b 100644 --- a/AnKi/Scene/Components/ParticleEmitterComponent.cpp +++ b/AnKi/Scene/Components/ParticleEmitterComponent.cpp @@ -272,7 +272,7 @@ void ParticleEmitterComponent::loadParticleEmitterResource(CString filename) GpuSceneBuffer::getSingleton().deferredFree(m_gpuScenePositions); GpuSceneBuffer::getSingleton().deferredFree(m_gpuSceneScales); GpuSceneBuffer::getSingleton().deferredFree(m_gpuSceneAlphas); - GpuSceneBuffer::getSingleton().deferredFree(m_gpuSceneUniforms); + GpuSceneBuffer::getSingleton().deferredFree(m_gpuSceneConstants); for(RenderStateBucketIndex& idx : m_renderStateBuckets) { @@ -304,8 +304,8 @@ void ParticleEmitterComponent::loadParticleEmitterResource(CString filename) m_gpuScenePositions = GpuSceneBuffer::getSingleton().allocate(sizeof(Vec3) * m_props.m_maxNumOfParticles, alignof(F32)); m_gpuSceneAlphas = GpuSceneBuffer::getSingleton().allocate(sizeof(F32) * m_props.m_maxNumOfParticles, alignof(F32)); m_gpuSceneScales = GpuSceneBuffer::getSingleton().allocate(sizeof(F32) * m_props.m_maxNumOfParticles, alignof(F32)); - m_gpuSceneUniforms = - GpuSceneBuffer::getSingleton().allocate(m_particleEmitterResource->getMaterial()->getPrefilledLocalUniforms().getSizeInBytes(), alignof(U32)); + m_gpuSceneConstants = GpuSceneBuffer::getSingleton().allocate( + m_particleEmitterResource->getMaterial()->getPrefilledLocalConstants().getSizeInBytes(), alignof(U32)); // Allocate buckets for(RenderingTechnique t : @@ -374,8 +374,9 @@ Error ParticleEmitterComponent::update(SceneComponentUpdateInfo& info, Bool& upd m_gpuSceneParticleEmitter.uploadToGpuScene(particles); // Upload uniforms - patcher.newCopy(*info.m_framePool, m_gpuSceneUniforms, m_particleEmitterResource->getMaterial()->getPrefilledLocalUniforms().getSizeInBytes(), - m_particleEmitterResource->getMaterial()->getPrefilledLocalUniforms().getBegin()); + patcher.newCopy(*info.m_framePool, m_gpuSceneConstants, + m_particleEmitterResource->getMaterial()->getPrefilledLocalConstants().getSizeInBytes(), + m_particleEmitterResource->getMaterial()->getPrefilledLocalConstants().getBegin()); // Upload mesh LODs GpuSceneMeshLod meshLod = {}; @@ -398,7 +399,7 @@ Error ParticleEmitterComponent::update(SceneComponentUpdateInfo& info, Bool& upd // Upload the GpuSceneRenderable GpuSceneRenderable renderable = {}; renderable.m_boneTransformsOffset = 0; - renderable.m_uniformsOffset = m_gpuSceneUniforms.getOffset(); + renderable.m_constantsOffset = m_gpuSceneConstants.getOffset(); renderable.m_meshLodsIndex = m_gpuSceneMeshLods.getIndex() * kMaxLodCount; renderable.m_particleEmitterIndex = m_gpuSceneParticleEmitter.getIndex(); renderable.m_worldTransformsIndex = 0; diff --git a/AnKi/Scene/Components/ParticleEmitterComponent.h b/AnKi/Scene/Components/ParticleEmitterComponent.h index 336a0c67e..5961b8d72 100644 --- a/AnKi/Scene/Components/ParticleEmitterComponent.h +++ b/AnKi/Scene/Components/ParticleEmitterComponent.h @@ -65,7 +65,7 @@ class ParticleEmitterComponent : public SceneComponent GpuSceneBufferAllocation m_gpuScenePositions; GpuSceneBufferAllocation m_gpuSceneAlphas; GpuSceneBufferAllocation m_gpuSceneScales; - GpuSceneBufferAllocation m_gpuSceneUniforms; + GpuSceneBufferAllocation m_gpuSceneConstants; GpuSceneArrays::ParticleEmitter::Allocation m_gpuSceneParticleEmitter; GpuSceneArrays::Renderable::Allocation m_gpuSceneRenderable; GpuSceneArrays::MeshLod::Allocation m_gpuSceneMeshLods; diff --git a/AnKi/ShaderCompiler/Dxc.cpp b/AnKi/ShaderCompiler/Dxc.cpp index f07415ff5..950598396 100644 --- a/AnKi/ShaderCompiler/Dxc.cpp +++ b/AnKi/ShaderCompiler/Dxc.cpp @@ -112,7 +112,7 @@ static Error compileHlsl(CString src, ShaderType shaderType, Bool compileWith16b // dxcArgs.emplaceBack("-fvk-support-nonzero-base-instance"); // Match DX12's behavior, SV_INSTANCEID starts from zero // Shift the bindings in order to identify the registers when doing reflection - for(U32 ds = 0; ds < kMaxDescriptorSets; ++ds) + for(U32 ds = 0; ds < kMaxRegisterSpaces; ++ds) { dxcArgs.emplaceBack("-fvk-b-shift"); dxcArgs.emplaceBack(ShaderCompilerString().sprintf("%u", kDxcVkBindingShifts[ds][HlslResourceType::kCbv])); diff --git a/AnKi/ShaderCompiler/Dxc.h b/AnKi/ShaderCompiler/Dxc.h index 37c063df7..a0bd8f56d 100644 --- a/AnKi/ShaderCompiler/Dxc.h +++ b/AnKi/ShaderCompiler/Dxc.h @@ -14,7 +14,7 @@ namespace anki { /// @addtogroup shader_compiler /// @{ -inline constexpr Array2d kDxcVkBindingShifts = { +inline constexpr Array2d kDxcVkBindingShifts = { {{1000, 2000, 3000, 4000}, {5000, 6000, 7000, 8000}, {9000, 10000, 11000, 12000}}}; // !!!!WARNING!!!! Need to change HLSL if you change the value bellow diff --git a/AnKi/ShaderCompiler/ShaderCompiler.cpp b/AnKi/ShaderCompiler/ShaderCompiler.cpp index 1ed73172e..72ad33f5a 100644 --- a/AnKi/ShaderCompiler/ShaderCompiler.cpp +++ b/AnKi/ShaderCompiler/ShaderCompiler.cpp @@ -124,7 +124,7 @@ Error doReflectionSpirv(ConstWeakArray spirv, ShaderType type, ShaderReflect const U32 set = spvc.get_decoration(id, spv::Decoration::DecorationDescriptorSet); const U32 binding = spvc.get_decoration(id, spv::Decoration::DecorationBinding); - if(set >= kMaxDescriptorSets && set != kDxcVkBindlessRegisterSpace) + if(set >= kMaxRegisterSpaces && set != kDxcVkBindlessRegisterSpace) { errorStr.sprintf("Exceeded set for: %s", r.name.c_str()); return Error::kUserData; @@ -249,7 +249,7 @@ Error doReflectionSpirv(ConstWeakArray spirv, ShaderType type, ShaderReflect return err; } - for(U32 i = 0; i < kMaxDescriptorSets; ++i) + for(U32 i = 0; i < kMaxRegisterSpaces; ++i) { std::sort(refl.m_descriptor.m_bindings[i].getBegin(), refl.m_descriptor.m_bindings[i].getBegin() + refl.m_descriptor.m_bindingCounts[i]); } @@ -270,13 +270,13 @@ Error doReflectionSpirv(ConstWeakArray spirv, ShaderType type, ShaderReflect if(rsrc.push_constant_buffers.size() == 1) { const U32 blockSize = U32(spvc.get_declared_struct_size(spvc.get_type(rsrc.push_constant_buffers[0].base_type_id))); - if(blockSize == 0 || (blockSize % 16) != 0 || blockSize > kMaxU8) + if(blockSize == 0 || (blockSize % 16) != 0 || blockSize > kMaxFastConstantsSize) { errorStr.sprintf("Incorrect push constants size"); return Error::kUserData; } - refl.m_descriptor.m_pushConstantsSize = blockSize; + refl.m_descriptor.m_fastConstantsSize = blockSize; } // Attribs @@ -477,7 +477,7 @@ Error doReflectionDxil(ConstWeakArray dxil, ShaderType type, ShaderReflectio (isLib) ? funcReflections[ifunc]->GetConstantBufferByName(bindDesc.Name) : dxRefl->GetConstantBufferByName(bindDesc.Name); D3D12_SHADER_BUFFER_DESC desc; ANKI_REFL_CHECK(cbuffer->GetDesc(&desc)); - refl.m_descriptor.m_pushConstantsSize = desc.Size; + refl.m_descriptor.m_fastConstantsSize = desc.Size; continue; } @@ -566,7 +566,7 @@ Error doReflectionDxil(ConstWeakArray dxil, ShaderType type, ShaderReflectio } } - for(U32 i = 0; i < kMaxDescriptorSets; ++i) + for(U32 i = 0; i < kMaxRegisterSpaces; ++i) { std::sort(refl.m_descriptor.m_bindings[i].getBegin(), refl.m_descriptor.m_bindings[i].getBegin() + refl.m_descriptor.m_bindingCounts[i]); } diff --git a/AnKi/ShaderCompiler/ShaderParser.cpp b/AnKi/ShaderCompiler/ShaderParser.cpp index f49edef06..32cf07206 100644 --- a/AnKi/ShaderCompiler/ShaderParser.cpp +++ b/AnKi/ShaderCompiler/ShaderParser.cpp @@ -871,9 +871,7 @@ void ShaderParser::generateAnkiShaderHeader(ShaderType shaderType, ShaderCompile { header.destroy(); - header += ShaderCompilerString().sprintf("#define kMaxBindlessTextures %uu\n" - "#define kMaxBindlessReadonlyTextureBuffers %uu\n", - kMaxBindlessTextures, kMaxBindlessReadonlyTextureBuffers); + header += ShaderCompilerString().sprintf("#define kMaxBindlessTextures %uu\n", kMaxBindlessTextures); for(ShaderType type : EnumIterable()) { diff --git a/AnKi/Shaders/Blit.ankiprog b/AnKi/Shaders/Blit.ankiprog index 321946587..a6be6487a 100644 --- a/AnKi/Shaders/Blit.ankiprog +++ b/AnKi/Shaders/Blit.ankiprog @@ -20,12 +20,12 @@ Texture2D g_inputTex : register(t0); # if USE_COMPUTE RWTexture2D g_storageTex : register(u0); -struct Uniforms +struct Consts { Vec2 m_viewportSize; UVec2 m_viewportSizeU; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Consts, g_consts) # endif # if USE_COMPUTE @@ -35,12 +35,12 @@ RVec3 main(VertOut input) : SV_TARGET0 # endif { # if USE_COMPUTE - if(skipOutOfBoundsInvocations(UVec2(8, 8), g_unis.m_viewportSizeU, svDispatchThreadId.xy)) + if(skipOutOfBoundsInvocations(UVec2(8, 8), g_consts.m_viewportSizeU, svDispatchThreadId.xy)) { return; } - const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5) / g_unis.m_viewportSize; + const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5) / g_consts.m_viewportSize; # else const Vec2 uv = input.m_uv; # endif diff --git a/AnKi/Shaders/Bloom.ankiprog b/AnKi/Shaders/Bloom.ankiprog index 37d7e017c..d254d4056 100644 --- a/AnKi/Shaders/Bloom.ankiprog +++ b/AnKi/Shaders/Bloom.ankiprog @@ -14,14 +14,14 @@ Texture2D g_inTex : register(t0); # define TONEMAPPING_REGISTER u0 # include -struct Uniforms +struct Consts { RF32 m_threshold; F32 m_scale; F32 m_padding0; F32 m_padding1; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Consts, g_consts) # if ANKI_COMPUTE_SHADER # define THREADGROUP_SIZE_X 8 @@ -51,7 +51,7 @@ RVec3 main(VertOut input) : SV_TARGET0 color += g_inTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0, IVec2(-1, +1)).rgb * weight; color += g_inTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0, IVec2(+1, -1)).rgb * weight; - color = tonemap(color, readExposureAndAverageLuminance().y, g_unis.m_threshold) * g_unis.m_scale; + color = tonemap(color, readExposureAndAverageLuminance().y, g_consts.m_threshold) * g_consts.m_scale; # if ANKI_COMPUTE_SHADER g_storageTex[svDispatchThreadId] = RVec4(color, 0.0); diff --git a/AnKi/Shaders/ClearTextureCompute.ankiprog b/AnKi/Shaders/ClearTextureCompute.ankiprog index 8e25d89cc..c461cb296 100644 --- a/AnKi/Shaders/ClearTextureCompute.ankiprog +++ b/AnKi/Shaders/ClearTextureCompute.ankiprog @@ -11,7 +11,7 @@ #pragma anki technique_start comp #include -struct Uniforms +struct Consts { #if COMPONENT_TYPE == 0 Vec4 m_clearColor; @@ -20,7 +20,7 @@ struct Uniforms #endif }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Consts, g_consts) #if TEXTURE_DIMENSIONS == 2 # if COMPONENT_TYPE == 0 @@ -47,7 +47,7 @@ RWTexture3D g_storageTex : register(u0); return; } - g_storageTex[svDispatchThreadId.xy] = g_unis.m_clearColor; + g_storageTex[svDispatchThreadId.xy] = g_consts.m_clearColor; #else UVec3 texSize; g_storageTex.GetDimensions(texSize.x, texSize.y, texSize.z); @@ -57,7 +57,7 @@ RWTexture3D g_storageTex : register(u0); return; } - g_storageTex[svDispatchThreadId] = g_unis.m_clearColor; + g_storageTex[svDispatchThreadId] = g_consts.m_clearColor; #endif } diff --git a/AnKi/Shaders/ClusterBinning.ankiprog b/AnKi/Shaders/ClusterBinning.ankiprog index 90179eb5b..f23b7027f 100644 --- a/AnKi/Shaders/ClusterBinning.ankiprog +++ b/AnKi/Shaders/ClusterBinning.ankiprog @@ -26,7 +26,7 @@ typedef GpuSceneGlobalIlluminationProbe GpuSceneType; # error See file #endif -struct ClusterBinningUniforms +struct ClusterBinningConstants { Vec3 m_cameraOrigin; F32 m_zSplitCountOverFrustumLength; @@ -44,7 +44,7 @@ struct ClusterBinningUniforms Mat4 m_invertedViewProjMat; }; -ANKI_PUSH_CONSTANTS(ClusterBinningUniforms, g_unis) +ANKI_FAST_CONSTANTS(ClusterBinningConstants, g_consts) StructuredBuffer g_visibleObjectIds : register(t0); // 1st index is the count and then the indices to the g_objects StructuredBuffer g_objects : register(t1); @@ -62,25 +62,25 @@ constexpr UVec2 kSampleLocations[kSampleCount] = {LOCATION(1, -3), LOCATION(-1, [numthreads(THREADGROUP_SIZE, 1, 1)] void main(UVec2 svDispatchThreadId : SV_DISPATCHTHREADID) { - const U32 dispatchThreadIdX = min(svDispatchThreadId.x, g_unis.m_tileCount * kSampleCount); + const U32 dispatchThreadIdX = min(svDispatchThreadId.x, g_consts.m_tileCount * kSampleCount); const U32 tileIdx = dispatchThreadIdX / kSampleCount; const U32 sampleIdx = dispatchThreadIdX % kSampleCount; const U32 visibleObjectIdx = svDispatchThreadId.y; ANKI_ASSERT(visibleObjectIdx < kMaxVisibleClusteredObjects[OBJECT_TYPE]); - const UVec2 tileXY = UVec2(tileIdx % g_unis.m_tileCountX, tileIdx / g_unis.m_tileCountX); + const UVec2 tileXY = UVec2(tileIdx % g_consts.m_tileCountX, tileIdx / g_consts.m_tileCountX); // This is a pixel in one of the main framebuffers of the renderer, eg the gbuffer's framebuffers const UVec2 pixel = tileXY * kClusteredShadingTileSize + kSampleLocations[sampleIdx]; - const Vec2 uv = Vec2(pixel) / g_unis.m_renderingSize; + const Vec2 uv = Vec2(pixel) / g_consts.m_renderingSize; const Vec2 ndc = uvToNdc(uv); // Unproject the sample in world space - const Vec4 farWorldPos4 = mul(g_unis.m_invertedViewProjMat, Vec4(ndc, 1.0, 1.0)); + const Vec4 farWorldPos4 = mul(g_consts.m_invertedViewProjMat, Vec4(ndc, 1.0, 1.0)); const Vec3 farWorldPos = farWorldPos4.xyz / farWorldPos4.w; // Create the ray that will test the clusterer objects - const Vec3 rayOrigin = g_unis.m_cameraOrigin; + const Vec3 rayOrigin = g_consts.m_cameraOrigin; const Vec3 rayDir = normalize(farWorldPos - rayOrigin); // Do collision @@ -181,8 +181,8 @@ constexpr UVec2 kSampleLocations[kSampleCount] = {LOCATION(1, -3), LOCATION(-1, // Compute and set the Z splits const Vec3 hitpointA = rayDir * t0 + rayOrigin; const Vec3 hitpointB = rayDir * t1 + rayOrigin; - const F32 distFromNearPlaneA = testPlanePoint(g_unis.m_nearPlaneWorld.xyz, g_unis.m_nearPlaneWorld.w, hitpointA); - const F32 distFromNearPlaneB = testPlanePoint(g_unis.m_nearPlaneWorld.xyz, g_unis.m_nearPlaneWorld.w, hitpointB); + const F32 distFromNearPlaneA = testPlanePoint(g_consts.m_nearPlaneWorld.xyz, g_consts.m_nearPlaneWorld.w, hitpointA); + const F32 distFromNearPlaneB = testPlanePoint(g_consts.m_nearPlaneWorld.xyz, g_consts.m_nearPlaneWorld.w, hitpointB); F32 minDistFromNearPlane; F32 maxDistFromNearPlane; @@ -197,27 +197,27 @@ constexpr UVec2 kSampleLocations[kSampleCount] = {LOCATION(1, -3), LOCATION(-1, maxDistFromNearPlane = distFromNearPlaneA; } - const I32 startZSplit = max(I32(minDistFromNearPlane * g_unis.m_zSplitCountOverFrustumLength), 0); - const I32 endZSplit = clamp(I32(maxDistFromNearPlane * g_unis.m_zSplitCountOverFrustumLength), 0, g_unis.m_zSplitCountMinusOne); + const I32 startZSplit = max(I32(minDistFromNearPlane * g_consts.m_zSplitCountOverFrustumLength), 0); + const I32 endZSplit = clamp(I32(maxDistFromNearPlane * g_consts.m_zSplitCountOverFrustumLength), 0, g_consts.m_zSplitCountMinusOne); for(I32 i = startZSplit; i <= endZSplit; ++i) { #if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT if((U32)obj.m_flags & (U32)GpuSceneLightFlag::kPointLight) { - InterlockedOr(g_clusters[g_unis.m_tileCount + i].m_pointLightsMask[maskArrayIdx], mask); + InterlockedOr(g_clusters[g_consts.m_tileCount + i].m_pointLightsMask[maskArrayIdx], mask); } else { - InterlockedOr(g_clusters[g_unis.m_tileCount + i].m_spotLightsMask[maskArrayIdx], mask); + InterlockedOr(g_clusters[g_consts.m_tileCount + i].m_spotLightsMask[maskArrayIdx], mask); } #elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_DECAL - InterlockedOr(g_clusters[g_unis.m_tileCount + i].m_decalsMask[maskArrayIdx], mask); + InterlockedOr(g_clusters[g_consts.m_tileCount + i].m_decalsMask[maskArrayIdx], mask); #elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_FOG_DENSITY_VOLUME - InterlockedOr(g_clusters[g_unis.m_tileCount + i].m_fogDensityVolumesMask, mask); + InterlockedOr(g_clusters[g_consts.m_tileCount + i].m_fogDensityVolumesMask, mask); #elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_REFLECTION_PROBE - InterlockedOr(g_clusters[g_unis.m_tileCount + i].m_reflectionProbesMask, mask); + InterlockedOr(g_clusters[g_consts.m_tileCount + i].m_reflectionProbesMask, mask); #elif OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_GLOBAL_ILLUMINATION_PROBE - InterlockedOr(g_clusters[g_unis.m_tileCount + i].m_giProbesMask, mask); + InterlockedOr(g_clusters[g_consts.m_tileCount + i].m_giProbesMask, mask); #else # error See file #endif diff --git a/AnKi/Shaders/ClusterBinningSetup.ankiprog b/AnKi/Shaders/ClusterBinningSetup.ankiprog index 2f16a6f44..be7f01619 100644 --- a/AnKi/Shaders/ClusterBinningSetup.ankiprog +++ b/AnKi/Shaders/ClusterBinningSetup.ankiprog @@ -16,14 +16,14 @@ StructuredBuffer g_visibleIndices[(U32)GpuSceneNonRenderableObjectType::kCo // binning dispatches and the rest GpuSceneNonRenderableObjectType::kCount for the packing dispatches RWStructuredBuffer g_indirectArgs : register(u0); -struct Uniforms +struct Constants { U32 m_tileCount; U32 m_padding1; U32 m_padding2; U32 m_padding3; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) constexpr U32 kSampleCount = 8; constexpr U32 kClusterBinningThreadgroupSize = 64; @@ -41,7 +41,7 @@ constexpr U32 kPackVisiblesThreadgroupSize = 64; const U32 objCount = min(kMaxVisibleClusteredObjects[(U32)type], g_visibleIndices[(U32)type][0]); DispatchIndirectArgs args; - args.m_threadGroupCountX = (g_unis.m_tileCount * kSampleCount + kClusterBinningThreadgroupSize - 1) / kClusterBinningThreadgroupSize; + args.m_threadGroupCountX = (g_consts.m_tileCount * kSampleCount + kClusterBinningThreadgroupSize - 1) / kClusterBinningThreadgroupSize; args.m_threadGroupCountY = objCount; args.m_threadGroupCountZ = 1; diff --git a/AnKi/Shaders/ClusteredShadingFunctions.hlsl b/AnKi/Shaders/ClusteredShadingFunctions.hlsl index 2af3a2f8a..11ff9de70 100644 --- a/AnKi/Shaders/ClusteredShadingFunctions.hlsl +++ b/AnKi/Shaders/ClusteredShadingFunctions.hlsl @@ -97,7 +97,7 @@ Cluster mergeClusters(Cluster tileCluster, Cluster zCluster) } /// Get the final cluster after ORing and ANDing the masks. -Cluster getClusterFragCoord(StructuredBuffer clusters, GlobalRendererUniforms consts, Vec3 fragCoord) +Cluster getClusterFragCoord(StructuredBuffer clusters, GlobalRendererConstants consts, Vec3 fragCoord) { const Cluster tileCluster = clusters[computeTileClusterIndexFragCoord(fragCoord.xy, consts.m_tileCounts.x)]; const Cluster zCluster = clusters[computeZSplitClusterIndex(fragCoord.z, consts.m_zSplitCount, consts.m_zSplitMagic.x, consts.m_zSplitMagic.y) diff --git a/AnKi/Shaders/Common.hlsl b/AnKi/Shaders/Common.hlsl index 6d5b0824c..d56170e70 100644 --- a/AnKi/Shaders/Common.hlsl +++ b/AnKi/Shaders/Common.hlsl @@ -14,9 +14,9 @@ #endif #if ANKI_GR_BACKEND_VULKAN -# define ANKI_PUSH_CONSTANTS(type, var) [[vk::push_constant]] ConstantBuffer var; +# define ANKI_FAST_CONSTANTS(type, var) [[vk::push_constant]] ConstantBuffer var; #else -# define ANKI_PUSH_CONSTANTS(type, var) ConstantBuffer var : register(b0, space3000); +# define ANKI_FAST_CONSTANTS(type, var) ConstantBuffer var : register(b0, space3000); #endif #if ANKI_GR_BACKEND_VULKAN diff --git a/AnKi/Shaders/DbgBillboard.ankiprog b/AnKi/Shaders/DbgBillboard.ankiprog index 748c56a9d..6872b3d80 100644 --- a/AnKi/Shaders/DbgBillboard.ankiprog +++ b/AnKi/Shaders/DbgBillboard.ankiprog @@ -13,13 +13,13 @@ constexpr F32 kAlpha = 1.0f; constexpr F32 kBillboardScale = 0.25f; -struct Uniforms +struct Constants { Mat4 m_viewProjMat; Mat3x4 m_camTrf; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) #if OBJECT_TYPE == ANKI_GPU_SCENE_NON_RENDERABLE_OBJECT_TYPE_LIGHT typedef LightUnion ClusteredType; @@ -85,9 +85,9 @@ VertOut main(VertIn input) #endif // Rotate towards the camera and apply translation - const Vec3 worldPos = mul(g_unis.m_camTrf, Vec4((output.m_uv * 2.0 - 1.0) * kBillboardScale, 0.0, 0.0)) + localPos; + const Vec3 worldPos = mul(g_consts.m_camTrf, Vec4((output.m_uv * 2.0 - 1.0) * kBillboardScale, 0.0, 0.0)) + localPos; - output.m_svPosition = mul(g_unis.m_viewProjMat, Vec4(worldPos, 1.0)); + output.m_svPosition = mul(g_consts.m_viewProjMat, Vec4(worldPos, 1.0)); } else { diff --git a/AnKi/Shaders/DbgRenderables.ankiprog b/AnKi/Shaders/DbgRenderables.ankiprog index 17bf9aa1c..85b554942 100644 --- a/AnKi/Shaders/DbgRenderables.ankiprog +++ b/AnKi/Shaders/DbgRenderables.ankiprog @@ -8,13 +8,13 @@ #include #include -struct Uniforms +struct Constants { Vec4 m_color; Mat4 m_viewProjMat; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) StructuredBuffer g_renderableBoundingVolumes : register(t1); StructuredBuffer g_visibleRenderableBoundingVolumeIndices : register(t2); @@ -42,7 +42,7 @@ VertOut main(VertIn input) const GpuSceneRenderableBoundingVolume bvol = g_renderableBoundingVolumes[g_visibleRenderableBoundingVolumeIndices[input.m_svInstanceId + 1]]; const Vec3 boxCenter = (bvol.m_aabbMin + bvol.m_aabbMax) * 0.5f; Vec3 localPos = input.m_position * (bvol.m_aabbMax - boxCenter) + boxCenter; - output.m_svPosition = mul(g_unis.m_viewProjMat, Vec4(localPos, 1.0)); + output.m_svPosition = mul(g_consts.m_viewProjMat, Vec4(localPos, 1.0)); } else { @@ -76,11 +76,11 @@ Vec4 main(VertOut input) : SV_TARGET0 const Bool depthTestFailed = input.m_svPosition.z >= depthRef; if(depthTestFailed) { - return g_unis.m_color * 0.5; + return g_consts.m_color * 0.5; } #endif // Write the color - return g_unis.m_color; + return g_consts.m_color; } #pragma anki technique_end frag diff --git a/AnKi/Shaders/DepthDownscale.ankiprog b/AnKi/Shaders/DepthDownscale.ankiprog index 79b189626..7bd2e6b42 100644 --- a/AnKi/Shaders/DepthDownscale.ankiprog +++ b/AnKi/Shaders/DepthDownscale.ankiprog @@ -9,7 +9,7 @@ #include #include -ANKI_PUSH_CONSTANTS(DepthDownscaleUniforms, g_unis) +ANKI_FAST_CONSTANTS(DepthDownscaleConstants, g_consts) globallycoherent RWStructuredBuffer g_spdCounter : register(u0); RWTexture2D g_dstStorageTextures[kMaxMipsSinglePassDownsamplerCanProduce] : register(u1); @@ -28,7 +28,7 @@ groupshared AF1 s_spdIntermediateR[16][16]; AF4 SpdLoadSourceImage(AU2 p, AU1 slice) { ANKI_MAYBE_UNUSED(slice); - const AF2 textureCoord = Vec2(p) * g_unis.m_srcTexSizeOverOne + g_unis.m_srcTexSizeOverOne; + const AF2 textureCoord = Vec2(p) * g_consts.m_srcTexSizeOverOne + g_consts.m_srcTexSizeOverOne; return AF4(g_srcTex.SampleLevel(u_linearAnyClampSampler, textureCoord, 0.0).r, 0.0, 0.0, 0.0); } @@ -89,7 +89,7 @@ AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3) { const U32 slice = 0u; const UVec2 offset = UVec2(0, 0); - SpdDownsample(AU2(svGroupId.xy), AU1(svGroupIndex), AU1(g_unis.m_mipmapCount), AU1(g_unis.m_threadgroupCount), slice, offset); + SpdDownsample(AU2(svGroupId.xy), AU1(svGroupIndex), AU1(g_consts.m_mipmapCount), AU1(g_consts.m_threadgroupCount), slice, offset); } #pragma anki technique_end comp diff --git a/AnKi/Shaders/DownscaleBlur.ankiprog b/AnKi/Shaders/DownscaleBlur.ankiprog index 948ee9858..edc2e4fa2 100644 --- a/AnKi/Shaders/DownscaleBlur.ankiprog +++ b/AnKi/Shaders/DownscaleBlur.ankiprog @@ -14,12 +14,12 @@ Texture2D g_tex : register(t0); # define TONEMAPPING_REGISTER u0 # include -struct Uniforms +struct Constants { Vec2 m_fbSize; UVec2 m_padding; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) # if ANKI_COMPUTE_SHADER RWTexture2D g_storageTex : register(u1); @@ -32,7 +32,7 @@ RVec3 main(VertOut input) : SV_TARGET0 # endif { # if ANKI_COMPUTE_SHADER - const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5) / g_unis.m_fbSize; + const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5) / g_consts.m_fbSize; # else const Vec2 uv = input.m_uv; # endif diff --git a/AnKi/Shaders/FinalComposite.ankiprog b/AnKi/Shaders/FinalComposite.ankiprog index 50e41a017..d73e73cf7 100644 --- a/AnKi/Shaders/FinalComposite.ankiprog +++ b/AnKi/Shaders/FinalComposite.ankiprog @@ -28,14 +28,14 @@ Texture2D g_depthRt : register(t4); Texture2D g_dbgOutlineRt : register(t5); #endif -struct Uniforms +struct Constants { U32 m_motionBlurSamples; F32 m_filmGrainStrength; U32 m_frameCount; U32 m_padding; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) RVec3 colorGrading(RVec3 color) { @@ -55,9 +55,10 @@ RVec3 main(VertOut input) : SV_TARGET0 const Vec2 uv = input.m_uv; RVec3 outColor; - if(g_unis.m_motionBlurSamples > 0u) + if(g_consts.m_motionBlurSamples > 0u) { - outColor = motionBlur(g_motionVectorsRt, g_nearestAnyClampSampler, g_lightShadingRt, g_linearAnyClampSampler, uv, g_unis.m_motionBlurSamples); + outColor = + motionBlur(g_motionVectorsRt, g_nearestAnyClampSampler, g_lightShadingRt, g_linearAnyClampSampler, uv, g_consts.m_motionBlurSamples); } else { @@ -73,7 +74,7 @@ RVec3 main(VertOut input) : SV_TARGET0 #if FILM_GRAIN const F32 dt = 1.0; - outColor = filmGrain(outColor, uv, g_unis.m_filmGrainStrength, F32(g_unis.m_frameCount % 0xFFFFu) * dt); + outColor = filmGrain(outColor, uv, g_consts.m_filmGrainStrength, F32(g_consts.m_frameCount % 0xFFFFu) * dt); #endif #if DBG_ENABLED diff --git a/AnKi/Shaders/ForwardShadingCommon.hlsl b/AnKi/Shaders/ForwardShadingCommon.hlsl index 04b2e6a5b..7d3fa7c78 100644 --- a/AnKi/Shaders/ForwardShadingCommon.hlsl +++ b/AnKi/Shaders/ForwardShadingCommon.hlsl @@ -45,7 +45,7 @@ Vec3 computeLightColorHigh(Vec3 diffCol, Vec3 worldPos, Vec4 svPosition) Vec3 outColor = Vec3(0.0, 0.0, 0.0); // Find the cluster and then the light counts - Cluster cluster = getClusterFragCoord(g_clusters, g_globalRendererUniforms, svPosition.xyz); + Cluster cluster = getClusterFragCoord(g_clusters, g_globalRendererConstants, svPosition.xyz); // Point lights U32 idx = 0; @@ -98,9 +98,9 @@ RVec3 computeLightColorLow(RVec3 diffCol, RVec3 worldPos, Vec4 svPosition) { ANKI_MAYBE_UNUSED(worldPos); - const Vec2 uv = svPosition.xy / g_globalRendererUniforms.m_renderingSize; - const F32 linearDepth = linearizeDepth(svPosition.z, g_globalRendererUniforms.m_near, g_globalRendererUniforms.m_far); - const F32 w = linearDepth * (F32(g_globalRendererUniforms.m_zSplitCount) / F32(g_globalRendererUniforms.m_lightVolumeLastZSplit + 1u)); + const Vec2 uv = svPosition.xy / g_globalRendererConstants.m_renderingSize; + const F32 linearDepth = linearizeDepth(svPosition.z, g_globalRendererConstants.m_near, g_globalRendererConstants.m_far); + const F32 w = linearDepth * (F32(g_globalRendererConstants.m_zSplitCount) / F32(g_globalRendererConstants.m_lightVolumeLastZSplit + 1u)); const Vec3 uvw = Vec3(uv, w); const RVec3 light = g_lightVol.SampleLevel(g_linearAnyClampSampler, uvw, 0.0).rgb; @@ -114,13 +114,13 @@ void particleAlpha(RVec4 color, RVec4 scaleColor, RVec4 biasColor, out FragOut o void fog(RVec3 color, RF32 fogAlphaScale, RF32 fogDistanceOfMaxThikness, F32 zVSpace, Vec2 svPosition, out FragOut output) { - const Vec2 screenSize = 1.0 / g_globalRendererUniforms.m_renderingSize; + const Vec2 screenSize = 1.0 / g_globalRendererConstants.m_renderingSize; const Vec2 texCoords = svPosition * screenSize; const F32 depth = g_gbufferDepthTex.Sample(g_linearAnyClampSampler, texCoords, 0.0).r; F32 zFeatherFactor; - const Vec4 fragPosVspace4 = mul(g_globalRendererUniforms.m_matrices.m_invertedProjectionJitter, Vec4(Vec3(uvToNdc(texCoords), depth), 1.0)); + const Vec4 fragPosVspace4 = mul(g_globalRendererConstants.m_matrices.m_invertedProjectionJitter, Vec4(Vec3(uvToNdc(texCoords), depth), 1.0)); const F32 sceneZVspace = fragPosVspace4.z / fragPosVspace4.w; const F32 diff = max(0.0, zVSpace - sceneZVspace); diff --git a/AnKi/Shaders/ForwardShadingFog.ankiprog b/AnKi/Shaders/ForwardShadingFog.ankiprog index 2583d124e..b98ef77d2 100644 --- a/AnKi/Shaders/ForwardShadingFog.ankiprog +++ b/AnKi/Shaders/ForwardShadingFog.ankiprog @@ -6,7 +6,7 @@ #include #include -#pragma anki struct AnKiLocalUniforms +#pragma anki struct AnKiLocalConstants #pragma anki member RVec3 m_fogColor #pragma anki member RF32 m_fogAlphaScale #pragma anki member RF32 m_fogDistanceOfMaxThikness @@ -22,7 +22,7 @@ struct VertOut { Vec4 m_svPosition : SV_POSITION; F32 m_zVSpace : ZVSPACE; - nointerpolation U32 m_uniformsOffset : UNIFORMS; + nointerpolation U32 m_constantsOffset : CONSTANTS_OFFSET; }; #pragma anki technique_start vert Forward @@ -37,12 +37,12 @@ VertOut main(VertIn input) const UnpackedMeshVertex vertex = loadVertex(mesh, input.m_svVertexId, false); const Vec3 worldPos = mul(worldTransform, Vec4(vertex.m_position, 1.0)); - output.m_svPosition = mul(g_globalUniforms.m_viewProjectionMatrix, Vec4(worldPos, 1.0)); + output.m_svPosition = mul(g_globalConstants.m_viewProjectionMatrix, Vec4(worldPos, 1.0)); - const Vec3 viewPos = mul(g_globalUniforms.m_viewTransform, Vec4(worldPos, 1.0)); + const Vec3 viewPos = mul(g_globalConstants.m_viewTransform, Vec4(worldPos, 1.0)); output.m_zVSpace = viewPos.z; - output.m_uniformsOffset = renderable.m_uniformsOffset; + output.m_constantsOffset = renderable.m_constantsOffset; return output; } @@ -54,9 +54,9 @@ VertOut main(VertIn input) FragOut main(VertOut input) { FragOut output = (FragOut)0; - const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(g_gpuScene, input.m_uniformsOffset); + const AnKiLocalConstants localConstants = loadAnKiLocalConstants(g_gpuScene, input.m_constantsOffset); - fog(localUniforms.m_fogColor, localUniforms.m_fogAlphaScale, localUniforms.m_fogDistanceOfMaxThikness, input.m_svPosition, input.m_zVSpace, + fog(localConstants.m_fogColor, localConstants.m_fogAlphaScale, localConstants.m_fogDistanceOfMaxThikness, input.m_svPosition, input.m_zVSpace, output); return output; diff --git a/AnKi/Shaders/ForwardShadingGenericTransparent.ankiprog b/AnKi/Shaders/ForwardShadingGenericTransparent.ankiprog index d2bc49176..3f896c092 100644 --- a/AnKi/Shaders/ForwardShadingGenericTransparent.ankiprog +++ b/AnKi/Shaders/ForwardShadingGenericTransparent.ankiprog @@ -8,7 +8,7 @@ #include -#pragma anki struct AnKiLocalUniforms +#pragma anki struct AnKiLocalConstants #pragma anki member U32 m_texture #pragma anki member RVec4 m_colorScale #pragma anki member RVec4 m_colorBias @@ -25,7 +25,7 @@ struct VertOut Vec2 m_uv : TEXCOORD; Vec3 m_worldPosition : WORLD_POSITION; Vec4 m_svPosition : SV_POSITION; - nointerpolation U32 m_uniformsOffset : UNIFORMS_OFFSET; + nointerpolation U32 m_constantsOffset : CONSTANTS_OFFSET; }; #pragma anki technique_start vert Forward @@ -41,10 +41,10 @@ VertOut main(VertIn input) output.m_worldPosition = mul(worldTransform, Vec4(vertex.m_position, 1.0)); - output.m_svPosition = mul(g_globalUniforms.m_viewProjectionMatrix, Vec4(output.m_worldPosition, 1.0)); + output.m_svPosition = mul(g_globalConstants.m_viewProjectionMatrix, Vec4(output.m_worldPosition, 1.0)); output.m_uv = vertex.m_uv; - output.m_uniformsOffset = renderable.m_uniformsOffset; + output.m_constantsOffset = renderable.m_constantsOffset; return output; } @@ -57,19 +57,19 @@ FragOut main(VertOut input) ANKI_MAYBE_UNUSED(input); FragOut output; - const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(g_gpuScene, WaveReadLaneFirst(input.m_uniformsOffset)); + const AnKiLocalConstants localConstants = loadAnKiLocalConstants(g_gpuScene, WaveReadLaneFirst(input.m_constantsOffset)); output.m_color = RVec4(1.0, 1.0, 1.0, 1.0); #if TEXTURE == 1 - output.m_color = getBindlessTexture2DRVec4(localUniforms.m_texture).Sample(g_globalSampler, input.m_uv); + output.m_color = getBindlessTexture2DRVec4(localConstants.m_texture).Sample(g_globalSampler, input.m_uv); #endif #if LIGHT == 1 output.m_color.rgb = computeLightColorLow(output.m_color.rgb, input.m_worldPosition, input.m_svPosition); #endif - output.m_color = output.m_color * localUniforms.m_colorScale + localUniforms.m_colorBias; + output.m_color = output.m_color * localConstants.m_colorScale + localConstants.m_colorBias; return output; } diff --git a/AnKi/Shaders/ForwardShadingParticles.ankiprog b/AnKi/Shaders/ForwardShadingParticles.ankiprog index 83bc0b63a..2d9ec2cb6 100644 --- a/AnKi/Shaders/ForwardShadingParticles.ankiprog +++ b/AnKi/Shaders/ForwardShadingParticles.ankiprog @@ -16,14 +16,14 @@ struct VertIn struct VertOut { - nointerpolation U32 m_uniformsOffset : UNIS_OFFSET; + nointerpolation U32 m_constantsOffset : UNIS_OFFSET; nointerpolation RF32 m_alpha : ALPHA; Vec2 m_uv : TEXCOORD; Vec3 m_worldPos : WORLD_POS; Vec4 m_svPosition : SV_POSITION; }; -#pragma anki struct AnKiLocalUniforms +#pragma anki struct AnKiLocalConstants #pragma anki member F32 m_animationPeriod #pragma anki member Vec4 m_colorScale #pragma anki member Vec4 m_colorBias @@ -57,12 +57,12 @@ VertOut main(VertIn input) + meshLod.m_positionTranslation; // Apply the particle scale, rotate the mesh to face the camera (billboard) and finally apply the particle position - output.m_worldPos = mul(g_globalUniforms.m_cameraTransform, Vec4(localPos * particleScale, 0.0)) + particlePos; + output.m_worldPos = mul(g_globalConstants.m_cameraTransform, Vec4(localPos * particleScale, 0.0)) + particlePos; - output.m_svPosition = mul(g_globalUniforms.m_viewProjectionMatrix, Vec4(output.m_worldPos, 1.0)); + output.m_svPosition = mul(g_globalConstants.m_viewProjectionMatrix, Vec4(output.m_worldPos, 1.0)); output.m_alpha = particleAlpha; - output.m_uniformsOffset = instance.m_uniformsOffset; + output.m_constantsOffset = instance.m_constantsOffset; return output; } @@ -73,22 +73,22 @@ VertOut main(VertIn input) FragOut main(VertOut input) { FragOut output = (FragOut)0; - const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(g_gpuScene, WaveReadLaneFirst(input.m_uniformsOffset)); + const AnKiLocalConstants localConstants = loadAnKiLocalConstants(g_gpuScene, WaveReadLaneFirst(input.m_constantsOffset)); #if ANIMATED_TEXTURE == 1 - RVec4 texCol = readAnimatedTextureRgba(getBindlessTexture2DArrayRVec4(localUniforms.m_diffuseMap), g_globalSampler, - localUniforms.m_animationPeriod, input.m_uv, g_globalRendererUniforms.m_time); + RVec4 texCol = readAnimatedTextureRgba(getBindlessTexture2DArrayRVec4(localConstants.m_diffuseMap), g_globalSampler, + localConstants.m_animationPeriod, input.m_uv, g_globalRendererConstants.m_time); #else - RVec4 texCol = getBindlessTexture2DRVec4(localUniforms.m_diffuseMap).Sample(g_globalSampler, input.m_uv); + RVec4 texCol = getBindlessTexture2DRVec4(localConstants.m_diffuseMap).Sample(g_globalSampler, input.m_uv); #endif #if LIGHT texCol.rgb = computeLightColorLow(texCol.rgb, input.m_worldPos, input.m_svPosition); #endif - RVec4 colScale = localUniforms.m_colorScale; + RVec4 colScale = localConstants.m_colorScale; colScale.a *= input.m_alpha; - particleAlpha(texCol, colScale, localUniforms.m_colorBias, output); + particleAlpha(texCol, colScale, localConstants.m_colorBias, output); return output; } diff --git a/AnKi/Shaders/Fsr.ankiprog b/AnKi/Shaders/Fsr.ankiprog index 5c64fe72a..39f74bf62 100644 --- a/AnKi/Shaders/Fsr.ankiprog +++ b/AnKi/Shaders/Fsr.ankiprog @@ -18,7 +18,7 @@ Texture2D g_tex : register(t0); RWTexture2D g_storageTex : register(u0); # endif -struct Uniforms +struct Constants { UVec4 m_fsrConsts0; UVec4 m_fsrConsts1; @@ -28,7 +28,7 @@ struct Uniforms UVec2 m_padding; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) // FSR begin # define A_GPU 1 @@ -85,7 +85,7 @@ Vec3 main(VertOut input) : SV_TARGET0 # endif { # if ANKI_COMPUTE_SHADER - if(any(svDispatchThreadId >= g_unis.m_viewportSize)) + if(any(svDispatchThreadId >= g_consts.m_viewportSize)) { return; } @@ -97,11 +97,11 @@ Vec3 main(VertOut input) : SV_TARGET0 HVec3 color; # if SHARPEN - FsrRcasH(color.r, color.g, color.b, uv, g_unis.m_fsrConsts0); + FsrRcasH(color.r, color.g, color.b, uv, g_consts.m_fsrConsts0); # elif FSR_QUALITY == 0 - FsrEasuL(color, uv, g_unis.m_fsrConsts0, g_unis.m_fsrConsts1, g_unis.m_fsrConsts2, g_unis.m_fsrConsts3); + FsrEasuL(color, uv, g_consts.m_fsrConsts0, g_consts.m_fsrConsts1, g_consts.m_fsrConsts2, g_consts.m_fsrConsts3); # else - FsrEasuH(color, uv, g_unis.m_fsrConsts0, g_unis.m_fsrConsts1, g_unis.m_fsrConsts2, g_unis.m_fsrConsts3); + FsrEasuH(color, uv, g_consts.m_fsrConsts0, g_consts.m_fsrConsts1, g_consts.m_fsrConsts2, g_consts.m_fsrConsts3); # endif # if ANKI_COMPUTE_SHADER diff --git a/AnKi/Shaders/GBufferGeneric.ankiprog b/AnKi/Shaders/GBufferGeneric.ankiprog index b3ccc93c9..f73d00cdb 100644 --- a/AnKi/Shaders/GBufferGeneric.ankiprog +++ b/AnKi/Shaders/GBufferGeneric.ankiprog @@ -67,7 +67,7 @@ #define PRIMITIVE_NO_SAMPLING_POINTS_CULLING 1 #define PRIMITIVE_ANY_CULLING (PRIMITIVE_BACKFACE_CULLING || PRIMITIVE_NO_SAMPLING_POINTS_CULLING) -#pragma anki struct AnKiLocalUniforms +#pragma anki struct AnKiLocalConstants #pragma anki member U32 m_diffuseTex #pragma anki member U32 m_normalTex @@ -117,7 +117,7 @@ struct VertOut nointerpolation U32 m_meshletIndex : MESHLET_INDEX; #endif - nointerpolation U32 m_uniformsOffset : UNIS_OFFSET; + nointerpolation U32 m_constantsOffset : UNIS_OFFSET; }; struct MeshPerVertOut @@ -144,7 +144,7 @@ struct MeshPerVertOut struct MeshPerPrimitiveOut { - U32 m_uniformsOffset : UNIS_OFFSET; + U32 m_constantsOffset : UNIS_OFFSET; #if VISUALIZE_MESHLETS U32 m_meshletIndex : MESHLET_INDEX; @@ -217,7 +217,7 @@ void velocity(Mat3x4 worldTransform, Mat3x4 prevWorldTransform, Vec3 prevLocalPo # endif Vec4 v4 = Vec4(mul(trf, Vec4(prevLocalPos, 1.0)), 1.0); - v4 = mul(g_globalUniforms.m_previousViewProjectionMatrix, v4); + v4 = mul(g_globalConstants.m_previousViewProjectionMatrix, v4); prevClipXyw = v4.xyw; crntClipXyw = svPosition.xyw; @@ -254,7 +254,7 @@ VertOut main(VertIn input) UnpackedMeshVertex vert = loadVertex(meshlet, localIdx, ANKI_BONES); - const U32 uniformsOffset = instance.m_uniformsOffset; + const U32 constantsOffset = instance.m_constantsOffset; const U32 worldTransformsIndex = instance.m_worldTransformsIndex_25bit_meshletPrimitiveCount_7bit >> 7u; const U32 boneTransformsOffset = instance.m_boneTransformsOffsetOrParticleEmitterIndex; @@ -267,7 +267,7 @@ VertOut main(VertIn input) const GpuSceneMeshLod mesh = g_meshLods[instance.m_meshLodIndex]; UnpackedMeshVertex vert = loadVertex(mesh, input.m_svVertexId, ANKI_BONES); - const U32 uniformsOffset = instance.m_uniformsOffset; + const U32 constantsOffset = instance.m_constantsOffset; const U32 worldTransformsIndex = instance.m_worldTransformsIndex; const U32 boneTransformsOffset = instance.m_boneTransformsOffsetOrParticleEmitterIndex; # endif // SW_MESHLETS @@ -282,7 +282,7 @@ VertOut main(VertIn input) # endif Vec3 prevPos = vert.m_position; ANKI_MAYBE_UNUSED(prevPos); - output.m_uniformsOffset = uniformsOffset; + output.m_constantsOffset = constantsOffset; // Do stuff # if ANKI_BONES @@ -290,7 +290,7 @@ VertOut main(VertIn input) # endif const Vec3 worldPos = mul(worldTransform, Vec4(vert.m_position, 1.0)); - output.m_svPosition = mul(g_globalUniforms.m_viewProjectionMatrix, Vec4(worldPos, 1.0)); + output.m_svPosition = mul(g_globalConstants.m_viewProjectionMatrix, Vec4(worldPos, 1.0)); # if NORMAL_MAPPING output.m_worldPos = worldPos; @@ -323,10 +323,10 @@ constexpr int g_trick = 0; // Trick the formatter main(U32 svGroupId : SV_GROUPID, U32 svGroupIndex : SV_GROUPINDEX, out vertices MeshPerVertOut verts[kMaxVerticesPerMeshlet], out primitives MeshPerPrimitiveOut primitives[kMaxPrimitivesPerMeshlet], out indices UVec3 indices[kMaxPrimitivesPerMeshlet]) { - const U32 instanceIdx = g_firstMeshlet[g_pushConsts.m_bucketIndex] + svGroupId; + const U32 instanceIdx = g_firstMeshlet[g_consts.m_bucketIndex] + svGroupId; const GpuSceneMeshletInstance instance = g_meshletInstances[instanceIdx]; - const U32 uniformsOffset = instance.m_uniformsOffset; + const U32 constantsOffset = instance.m_constantsOffset; const U32 worldTransformsIndex = instance.m_worldTransformsIndex_25bit_meshletPrimitiveCount_7bit >> 7u; const U32 boneTransformsOffset = instance.m_boneTransformsOffsetOrParticleEmitterIndex; ANKI_MAYBE_UNUSED(boneTransformsOffset); @@ -365,9 +365,9 @@ main(U32 svGroupId : SV_GROUPID, U32 svGroupIndex : SV_GROUPINDEX, out vertices # endif const Vec3 worldPos = mul(worldTransform, Vec4(vert.m_position, 1.0)); - output.m_svPosition = mul(g_globalUniforms.m_viewProjectionMatrix, Vec4(worldPos, 1.0f)); + output.m_svPosition = mul(g_globalConstants.m_viewProjectionMatrix, Vec4(worldPos, 1.0f)); # if PRIMITIVE_ANY_CULLING - s_windowCoords[idx] = ndcToUv(output.m_svPosition.xy / output.m_svPosition.w) * g_globalUniforms.m_viewport.zw; + s_windowCoords[idx] = ndcToUv(output.m_svPosition.xy / output.m_svPosition.w) * g_globalConstants.m_viewport.zw; s_clipW[idx] = output.m_svPosition.w; # endif @@ -431,7 +431,7 @@ main(U32 svGroupId : SV_GROUPID, U32 svGroupIndex : SV_GROUPINDEX, out vertices primitives[idx].m_cullPrimitive = cull; # endif - primitives[idx].m_uniformsOffset = uniformsOffset; + primitives[idx].m_constantsOffset = constantsOffset; # if VISUALIZE_MESHLETS primitives[idx].m_meshletIndex = relativeMeshletIdx; # endif @@ -468,14 +468,14 @@ void main( ) { # if ANKI_TECHNIQUE_ShadowsMeshShaders - const U32 uniformsOffset = primInput.m_uniformsOffset; + const U32 constantsOffset = primInput.m_constantsOffset; # else - const U32 uniformsOffset = vertInput.m_uniformsOffset; + const U32 constantsOffset = vertInput.m_constantsOffset; # endif - const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(g_gpuScene, uniformsOffset); - const RVec4 diffColorA = BINDLESS(localUniforms.m_diffuseTex).Sample(g_globalSampler, vertInput.m_uv); - if(diffColorA.a * localUniforms.m_diffuseScale.a < 0.5f) + const AnKiLocalConstants localConstants = loadAnKiLocalConstants(g_gpuScene, constantsOffset); + const RVec4 diffColorA = BINDLESS(localConstants.m_diffuseTex).Sample(g_globalSampler, vertInput.m_uv); + if(diffColorA.a * localConstants.m_diffuseScale.a < 0.5f) { discard; } @@ -492,12 +492,12 @@ FragOut main( ) { # if ANKI_TECHNIQUE_GBufferMeshShaders - const U32 uniformsOffset = primInput.m_uniformsOffset; + const U32 constantsOffset = primInput.m_constantsOffset; # else - const U32 uniformsOffset = vertInput.m_uniformsOffset; + const U32 constantsOffset = vertInput.m_constantsOffset; # endif - const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(g_gpuScene, uniformsOffset); + const AnKiLocalConstants localConstants = loadAnKiLocalConstants(g_gpuScene, constantsOffset); # if REALLY_USING_PARALLAX // TODO @@ -508,7 +508,7 @@ FragOut main( ANKI_MAYBE_UNUSED(uv); # if DIFFUSE_TEX - const RVec4 diffColorA = BINDLESS(localUniforms.m_diffuseTex).Sample(g_globalSampler, uv) * localUniforms.m_diffuseScale; + const RVec4 diffColorA = BINDLESS(localConstants.m_diffuseTex).Sample(g_globalSampler, uv) * localConstants.m_diffuseScale; const RVec3 diffColor = diffColorA.rgb; # if REALLY_ALPHA_TEST if(diffColorA.a < 0.5f) @@ -517,36 +517,36 @@ FragOut main( } # endif # else - const RVec3 diffColor = localUniforms.m_diffuseScale; + const RVec3 diffColor = localConstants.m_diffuseScale; # endif # if SPECULAR_TEX - const RVec3 specColor = BINDLESS(localUniforms.m_specularTex).Sample(g_globalSampler, uv).rgb * localUniforms.m_specularScale; + const RVec3 specColor = BINDLESS(localConstants.m_specularTex).Sample(g_globalSampler, uv).rgb * localConstants.m_specularScale; # else - const RVec3 specColor = localUniforms.m_specularScale; + const RVec3 specColor = localConstants.m_specularScale; # endif # if ROUGHNESS_METALNESS_TEX - const RVec3 comp = BINDLESS(localUniforms.m_roughnessMetalnessTex).Sample(g_globalSampler, uv).rgb; - const RF32 roughness = comp.g * localUniforms.m_roughnessScale; - const RF32 metallic = comp.b * localUniforms.m_metalnessScale; + const RVec3 comp = BINDLESS(localConstants.m_roughnessMetalnessTex).Sample(g_globalSampler, uv).rgb; + const RF32 roughness = comp.g * localConstants.m_roughnessScale; + const RF32 metallic = comp.b * localConstants.m_metalnessScale; # else - const RF32 roughness = localUniforms.m_roughnessScale; - const RF32 metallic = localUniforms.m_metalnessScale; + const RF32 roughness = localConstants.m_roughnessScale; + const RF32 metallic = localConstants.m_metalnessScale; # endif # if NORMAL_TEX - const RVec3 nAtTangentspace = normalize((BINDLESS(localUniforms.m_normalTex).Sample(g_globalSampler, uv).rgb - 0.5) * 2.0); - const Vec3 viewDir = normalize(g_globalUniforms.m_cameraTransform.getTranslationPart() - vertInput.m_worldPos); + const RVec3 nAtTangentspace = normalize((BINDLESS(localConstants.m_normalTex).Sample(g_globalSampler, uv).rgb - 0.5) * 2.0); + const Vec3 viewDir = normalize(g_globalConstants.m_cameraTransform.getTranslationPart() - vertInput.m_worldPos); const RVec3 normal = perturbNormal(nAtTangentspace, viewDir, uv, normalize(vertInput.m_normal)); # else const RVec3 normal = normalize(vertInput.m_normal); # endif # if EMISSIVE_TEX - const RVec3 emission = BINDLESS(localUniforms.m_emissiveTex).Sample(g_globalSampler, uv).rgb * localUniforms.m_emissionScale; + const RVec3 emission = BINDLESS(localConstants.m_emissiveTex).Sample(g_globalSampler, uv).rgb * localConstants.m_emissionScale; # else - const RVec3 emission = localUniforms.m_emissionScale; + const RVec3 emission = localConstants.m_emissionScale; # endif # if ANKI_VELOCITY || ANKI_BONES @@ -564,7 +564,7 @@ FragOut main( g.m_normal = normal; g.m_f0 = specColor; g.m_roughness = roughness; - g.m_subsurface = localUniforms.m_subsurface; + g.m_subsurface = localConstants.m_subsurface; g.m_emission = emission; g.m_metallic = metallic; g.m_velocity = velocity; @@ -636,9 +636,9 @@ FragOut main( const Vec2 uv = vert0.m_uv * bary.x + vert1.m_uv * bary.y + vert2.m_uv * bary.z; - const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(g_gpuScene, g_gpuSceneRenderable.m_uniformsOffset); + const AnKiLocalConstants localConstants = loadAnKiLocalConstants(g_gpuScene, g_gpuSceneRenderable.m_constantsOffset); const RVec4 diffColorA = - getBindlessTexture2DRVec4(localUniforms.m_diffuseTex).SampleLevel(g_globalSampler, uv, 0.0) * localUniforms.m_diffuseScale; + getBindlessTexture2DRVec4(localConstants.m_diffuseTex).SampleLevel(g_globalSampler, uv, 0.0) * localConstants.m_diffuseScale; if(diffColorA.a < 1.0) { diff --git a/AnKi/Shaders/GBufferGpuParticles.ankiprog b/AnKi/Shaders/GBufferGpuParticles.ankiprog index 14db0fceb..443f2c3df 100644 --- a/AnKi/Shaders/GBufferGpuParticles.ankiprog +++ b/AnKi/Shaders/GBufferGpuParticles.ankiprog @@ -5,7 +5,7 @@ #include -#pragma anki struct AnKiLocalUniforms +#pragma anki struct AnKiLocalConstants #pragma anki member RVec3 m_diffColor #pragma anki member RF32 m_roughness #pragma anki member RVec3 m_specColor @@ -24,7 +24,7 @@ struct VertOut { nointerpolation Vec2 m_velocity : VELOCITY; nointerpolation RF32 m_lifeFactor : LIFE_FACTOR; - nointerpolation U32 m_uniformsOffset : UNIFORMS_OFFSET; + nointerpolation U32 m_constantsOffset : CONSTANTS_OFFSET; Vec4 m_svPosition : SV_POSITION; }; @@ -60,8 +60,8 @@ VertOut main(VertIn input) const F32 startingLife = g_gpuScene.Load(offset); // Position - const Vec4 clipPos = mul(g_globalUniforms.m_viewProjectionMatrix, Vec4(pos, 1.0)); - const Vec4 prevClipPos = mul(g_globalUniforms.m_viewProjectionMatrix, Vec4(prevPos, 1.0)); + const Vec4 clipPos = mul(g_globalConstants.m_viewProjectionMatrix, Vec4(pos, 1.0)); + const Vec4 prevClipPos = mul(g_globalConstants.m_viewProjectionMatrix, Vec4(prevPos, 1.0)); output.m_svPosition = clipPos; @@ -72,7 +72,7 @@ VertOut main(VertIn input) // Misc output.m_lifeFactor = saturate(1.0 - (life / startingLife)); - output.m_uniformsOffset = renderable.m_uniformsOffset; + output.m_constantsOffset = renderable.m_constantsOffset; return output; } @@ -84,19 +84,19 @@ VertOut main(VertIn input) FragOut main(VertOut input) { FragOut output; - const AnKiLocalUniforms localUniforms = loadAnKiLocalUniforms(g_gpuScene, input.m_uniformsOffset); + const AnKiLocalConstants localConstants = loadAnKiLocalConstants(g_gpuScene, input.m_constantsOffset); GbufferInfo g; - g.m_diffuse = localUniforms.m_diffColor; + g.m_diffuse = localConstants.m_diffColor; - const Mat3x4 camTrf = g_globalUniforms.m_cameraTransform; + const Mat3x4 camTrf = g_globalConstants.m_cameraTransform; g.m_normal = normalize(Vec3(camTrf.m_row0[2], camTrf.m_row1[2], camTrf.m_row2[2])); - g.m_f0 = localUniforms.m_specColor; - g.m_roughness = localUniforms.m_roughness; + g.m_f0 = localConstants.m_specColor; + g.m_roughness = localConstants.m_roughness; g.m_subsurface = 0.0; - g.m_emission = lerp(localUniforms.m_initialEmission, localUniforms.m_finalEmission, input.m_lifeFactor); - g.m_metallic = localUniforms.m_metallic; + g.m_emission = lerp(localConstants.m_initialEmission, localConstants.m_finalEmission, input.m_lifeFactor); + g.m_metallic = localConstants.m_metallic; g.m_velocity = input.m_velocity; packGBuffer(g, output.m_color0, output.m_color1, output.m_color2, output.m_color3); return output; diff --git a/AnKi/Shaders/GBufferPost.ankiprog b/AnKi/Shaders/GBufferPost.ankiprog index b510e1e40..48b721ec3 100644 --- a/AnKi/Shaders/GBufferPost.ankiprog +++ b/AnKi/Shaders/GBufferPost.ankiprog @@ -18,7 +18,7 @@ SamplerState g_nearestAnyClampSampler : register(s0); Texture2D g_depthTex : register(t0); SamplerState g_trilinearRepeatSampler : register(s1); -ConstantBuffer g_globalUniforms : register(b0); +ConstantBuffer g_globalConstants : register(b0); StructuredBuffer g_decals : register(t1); StructuredBuffer g_clusters : register(t2); @@ -45,11 +45,11 @@ FragOut main(VertOut input) // Get worldPos const F32 depth = g_depthTex.SampleLevel(g_nearestAnyClampSampler, uv, 0.0).r; const Vec2 ndc = uvToNdc(uv); - const Vec4 worldPos4 = mul(g_globalUniforms.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_globalConstants.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; // Get the cluster - Cluster cluster = getClusterFragCoord(g_clusters, g_globalUniforms, Vec3(input.m_svPosition.xy, depth)); + Cluster cluster = getClusterFragCoord(g_clusters, g_globalConstants, Vec3(input.m_svPosition.xy, depth)); // Make the decalsMask uniform across the wave because we are accessing bindless textures later on U32 decalsMask = cluster.m_decalsMask[0]; diff --git a/AnKi/Shaders/GpuVisibilityAccelerationStructures.ankiprog b/AnKi/Shaders/GpuVisibilityAccelerationStructures.ankiprog index 0abd2b4b7..c9c2729b0 100644 --- a/AnKi/Shaders/GpuVisibilityAccelerationStructures.ankiprog +++ b/AnKi/Shaders/GpuVisibilityAccelerationStructures.ankiprog @@ -23,7 +23,7 @@ globallycoherent RWStructuredBuffer g_counterBuffer : register(u2); // 2 co RWStructuredBuffer g_nextDispatchIndirectArgs : register(u3); -ANKI_PUSH_CONSTANTS(GpuVisibilityAccelerationStructuresUniforms, g_unis) +ANKI_FAST_CONSTANTS(GpuVisibilityAccelerationStructuresConstants, g_consts) #define NUMTHREADS 64 @@ -44,7 +44,7 @@ ANKI_PUSH_CONSTANTS(GpuVisibilityAccelerationStructuresUniforms, g_unis) bvolume = g_renderableBoundingVolumes[bvolumeIdx]; sphereCenter = (bvolume.m_aabbMin + bvolume.m_aabbMax) * 0.5f; - visible = testSphereSphereCollision(sphereCenter, bvolume.m_sphereRadius, g_unis.m_pointOfTest, g_unis.m_testRadius); + visible = testSphereSphereCollision(sphereCenter, bvolume.m_sphereRadius, g_consts.m_pointOfTest, g_consts.m_testRadius); } // All good, write the instance @@ -52,16 +52,16 @@ ANKI_PUSH_CONSTANTS(GpuVisibilityAccelerationStructuresUniforms, g_unis) { // LOD selection U32 lod; - const Bool insideCameraFrustum = frustumTest(g_unis.m_clipPlanes, sphereCenter, bvolume.m_sphereRadius); + const Bool insideCameraFrustum = frustumTest(g_consts.m_clipPlanes, sphereCenter, bvolume.m_sphereRadius); if(insideCameraFrustum) { // Visible by the camera, need to match the camera LODs - const F32 distFromLodPoint = length(sphereCenter - g_unis.m_pointOfTest) - bvolume.m_sphereRadius; - if(distFromLodPoint < g_unis.m_maxLodDistances[0]) + const F32 distFromLodPoint = length(sphereCenter - g_consts.m_pointOfTest) - bvolume.m_sphereRadius; + if(distFromLodPoint < g_consts.m_maxLodDistances[0]) { lod = 0u; } - else if(distFromLodPoint < g_unis.m_maxLodDistances[1]) + else if(distFromLodPoint < g_consts.m_maxLodDistances[1]) { lod = 1u; } diff --git a/AnKi/Shaders/GpuVisibilityNonRenderables.ankiprog b/AnKi/Shaders/GpuVisibilityNonRenderables.ankiprog index ff1ae973d..a48a0aba6 100644 --- a/AnKi/Shaders/GpuVisibilityNonRenderables.ankiprog +++ b/AnKi/Shaders/GpuVisibilityNonRenderables.ankiprog @@ -32,7 +32,7 @@ typedef GpuSceneGlobalIlluminationProbe ObjectType; StructuredBuffer g_objects : register(t0); RWStructuredBuffer g_visibleIndices : register(u0); // 1st element is the count. What follows is indices -ANKI_PUSH_CONSTANTS(GpuVisibilityNonRenderableUniforms, g_unis) +ANKI_FAST_CONSTANTS(GpuVisibilityNonRenderableConstants, g_consts) constexpr U32 kVisibleObjCounterIdx = 1; constexpr U32 kThreadgroupCounterIdx = 0; @@ -96,7 +96,7 @@ Vec4 getSphere(GpuSceneGlobalIlluminationProbe l) if(!skip) { const Vec4 sphere = getSphere(g_objects[svDispatchThreadId]); - skip = !frustumTest(g_unis.m_clipPlanes, sphere.xyz, sphere.w); + skip = !frustumTest(g_consts.m_clipPlanes, sphere.xyz, sphere.w); } // Add the object diff --git a/AnKi/Shaders/GpuVisibilityStage1.ankiprog b/AnKi/Shaders/GpuVisibilityStage1.ankiprog index afc643a64..de96e3978 100644 --- a/AnKi/Shaders/GpuVisibilityStage1.ankiprog +++ b/AnKi/Shaders/GpuVisibilityStage1.ankiprog @@ -60,9 +60,9 @@ RWStructuredBuffer g_hash : register(u8); #endif #if DISTANCE_TEST == 0 -ConstantBuffer g_unis : register(b0); +ConstantBuffer g_consts : register(b0); #else -ANKI_PUSH_CONSTANTS(DistanceGpuVisibilityUniforms, g_unis) +ANKI_FAST_CONSTANTS(DistanceGpuVisibilityConstants, g_consts) #endif #if HZB_TEST @@ -78,7 +78,7 @@ Bool isVisible(GpuSceneRenderableBoundingVolume bvolume) #if DISTANCE_TEST == 0 // Frustum test // - if(!frustumTest(g_unis.m_clipPlanes, sphereCenter, sphereRadius)) + if(!frustumTest(g_consts.m_clipPlanes, sphereCenter, sphereRadius)) { return false; } @@ -87,7 +87,7 @@ Bool isVisible(GpuSceneRenderableBoundingVolume bvolume) // Vec2 minNdc, maxNdc; F32 aabbMinDepth; - projectAabb(bvolume.m_aabbMin, bvolume.m_aabbMax, g_unis.m_viewProjectionMat, minNdc, maxNdc, aabbMinDepth); + projectAabb(bvolume.m_aabbMin, bvolume.m_aabbMax, g_consts.m_viewProjectionMat, minNdc, maxNdc, aabbMinDepth); if(any(minNdc > 1.0f) || any(maxNdc < -1.0f)) { @@ -95,8 +95,8 @@ Bool isVisible(GpuSceneRenderableBoundingVolume bvolume) return false; } - const Vec2 windowCoordsMin = ndcToUv(minNdc) * g_unis.m_finalRenderTargetSize; - const Vec2 windowCoordsMax = ndcToUv(maxNdc) * g_unis.m_finalRenderTargetSize; + const Vec2 windowCoordsMin = ndcToUv(minNdc) * g_consts.m_finalRenderTargetSize; + const Vec2 windowCoordsMax = ndcToUv(maxNdc) * g_consts.m_finalRenderTargetSize; if(any(round(windowCoordsMin) == round(windowCoordsMax))) { // Doesn't touch the sampling points @@ -113,7 +113,7 @@ Bool isVisible(GpuSceneRenderableBoundingVolume bvolume) # endif // HZB_TEST #else // DISTANCE_TEST == 1 - if(!testSphereSphereCollision(sphereCenter, sphereRadius, g_unis.m_pointOfTest, g_unis.m_testRadius)) + if(!testSphereSphereCollision(sphereCenter, sphereRadius, g_consts.m_pointOfTest, g_consts.m_testRadius)) { return false; } @@ -158,14 +158,14 @@ Bool isVisible(GpuSceneRenderableBoundingVolume bvolume) // const Vec3 sphereCenter = (bvolume.m_aabbMin + bvolume.m_aabbMax) * 0.5f; const F32 sphereRadius = bvolume.m_sphereRadius; - const F32 distFromLodPoint = length(sphereCenter - g_unis.m_lodReferencePoint) - sphereRadius; + const F32 distFromLodPoint = length(sphereCenter - g_consts.m_lodReferencePoint) - sphereRadius; U32 lod; - if(distFromLodPoint < g_unis.m_maxLodDistances[0]) + if(distFromLodPoint < g_consts.m_maxLodDistances[0]) { lod = 0u; } - else if(distFromLodPoint < g_unis.m_maxLodDistances[1]) + else if(distFromLodPoint < g_consts.m_maxLodDistances[1]) { lod = 1u; } diff --git a/AnKi/Shaders/GpuVisibilityStage2And3.ankiprog b/AnKi/Shaders/GpuVisibilityStage2And3.ankiprog index 11ba85d5b..4ba6a00f6 100644 --- a/AnKi/Shaders/GpuVisibilityStage2And3.ankiprog +++ b/AnKi/Shaders/GpuVisibilityStage2And3.ankiprog @@ -95,7 +95,7 @@ RWStructuredBuffer g_outOfMemoryBuffer : register(u4); UVec4 instanceVertex; instanceVertex.x = renderable.m_worldTransformsIndex; - instanceVertex.y = renderable.m_uniformsOffset; + instanceVertex.y = renderable.m_constantsOffset; instanceVertex.z = meshLodIndex; instanceVertex.w = renderable.m_boneTransformsOffset; SBUFF(g_instanceRateRenderables, instanceIndex) = instanceVertex; @@ -114,7 +114,7 @@ RWStructuredBuffer g_outOfMemoryBuffer : register(u4); UVec4 instanceVertex; instanceVertex.x = renderable.m_worldTransformsIndex; - instanceVertex.y = renderable.m_uniformsOffset; + instanceVertex.y = renderable.m_constantsOffset; instanceVertex.z = meshLodIndex; instanceVertex.w = renderable.m_particleEmitterIndex; SBUFF(g_instanceRateRenderables, instanceIndex) = instanceVertex; @@ -164,7 +164,7 @@ RWStructuredBuffer g_meshletsFailedHzb : regist RWStructuredBuffer g_gpuVisIndirectDispatchArgs : register(u5); #endif -ANKI_PUSH_CONSTANTS(GpuVisibilityMeshletUniforms, g_unis) +ANKI_FAST_CONSTANTS(GpuVisibilityMeshletConstants, g_consts) Bool cullMeshlet(GpuSceneRenderable renderable, const MeshletBoundingVolume meshletBoundingVol, out Bool meshletCulledByHzb) { @@ -175,14 +175,14 @@ Bool cullMeshlet(GpuSceneRenderable renderable, const MeshletBoundingVolume mesh # if MESHLET_BACKFACE_CULLING const Vec4 coneDirAndAng = unpackSnorm4x8(meshletBoundingVol.m_coneDirection_R8G8B8_Snorm_cosHalfAngle_R8_Snorm); - if(cullBackfaceMeshlet(coneDirAndAng.xyz, coneDirAndAng.w, meshletBoundingVol.m_coneApex, worldTransform, g_unis.m_cameraPos)) + if(cullBackfaceMeshlet(coneDirAndAng.xyz, coneDirAndAng.w, meshletBoundingVol.m_coneApex, worldTransform, g_consts.m_cameraPos)) { return true; } # endif const Mat4 wordTransform4 = {worldTransform.m_row0, worldTransform.m_row1, worldTransform.m_row2, Vec4(0.0f, 0.0f, 0.0f, 1.0f)}; - const Mat4 mvp = mul(g_unis.m_viewProjectionMatrix, wordTransform4); + const Mat4 mvp = mul(g_consts.m_viewProjectionMatrix, wordTransform4); Vec2 minNdc, maxNdc; F32 aabbMinDepth; @@ -198,8 +198,8 @@ Bool cullMeshlet(GpuSceneRenderable renderable, const MeshletBoundingVolume mesh # if MESHLET_NO_SAMPLING_POINT_CULLING // Sampling points test - const Vec2 windowCoordsMin = ndcToUv(minNdc) * g_unis.m_viewportSizef; - const Vec2 windowCoordsMax = ndcToUv(maxNdc) * g_unis.m_viewportSizef; + const Vec2 windowCoordsMin = ndcToUv(minNdc) * g_consts.m_viewportSizef; + const Vec2 windowCoordsMax = ndcToUv(maxNdc) * g_consts.m_viewportSizef; if(any(round(windowCoordsMin) == round(windowCoordsMax))) { return true; @@ -264,7 +264,7 @@ Bool cullMeshlet(GpuSceneRenderable renderable, const MeshletBoundingVolume mesh GpuSceneMeshletInstance instance; instance.m_worldTransformsIndex_25bit_meshletPrimitiveCount_7bit = renderable.m_worldTransformsIndex << 7u; instance.m_worldTransformsIndex_25bit_meshletPrimitiveCount_7bit |= meshletBoundingVol.m_primitiveCount; - instance.m_uniformsOffset = renderable.m_uniformsOffset; + instance.m_constantsOffset = renderable.m_constantsOffset; instance.m_boneTransformsOffsetOrParticleEmitterIndex = renderable.m_boneTransformsOffset; instance.m_meshletGeometryDescriptorIndex = meshLod.m_firstMeshletGeometryDescriptor + meshletIdx; diff --git a/AnKi/Shaders/HzbGenPyramid.ankiprog b/AnKi/Shaders/HzbGenPyramid.ankiprog index 8cc7af1e9..85ff3524a 100644 --- a/AnKi/Shaders/HzbGenPyramid.ankiprog +++ b/AnKi/Shaders/HzbGenPyramid.ankiprog @@ -9,13 +9,13 @@ #pragma anki technique_start comp #include -struct Uniforms +struct Constants { Vec2 m_invSrcTexSize; U32 m_threadGroupCount; U32 m_mipmapCount; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) globallycoherent RWStructuredBuffer g_spdCounter : register(u0); globallycoherent RWTexture2D g_dstStorageTextures[kMaxMipsSinglePassDownsamplerCanProduce] : register(u1); @@ -38,7 +38,7 @@ groupshared AF1 s_spdIntermediateR[16][16]; AF4 SpdLoadSourceImage(AU2 p, AU1 slice) { ANKI_MAYBE_UNUSED(slice); - const AF2 uv = p * g_unis.m_invSrcTexSize + g_unis.m_invSrcTexSize; + const AF2 uv = p * g_consts.m_invSrcTexSize + g_consts.m_invSrcTexSize; #if MIN_MAX_SAMPLER const F32 f = g_srcTex.SampleLevel(g_minMaxAnyClampSampler, uv, 0.0).r; @@ -111,7 +111,7 @@ AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3) { const U32 slice = 0u; const UVec2 offset = UVec2(0, 0); - SpdDownsample(AU2(svGroupId.xy), AU1(svGroupIndex), AU1(g_unis.m_mipmapCount), AU1(g_unis.m_threadGroupCount), slice, offset); + SpdDownsample(AU2(svGroupId.xy), AU1(svGroupIndex), AU1(g_consts.m_mipmapCount), AU1(g_consts.m_threadGroupCount), slice, offset); } #pragma anki technique_end comp diff --git a/AnKi/Shaders/HzbMaxDepthProject.ankiprog b/AnKi/Shaders/HzbMaxDepthProject.ankiprog index 991b4a412..08c8a728a 100644 --- a/AnKi/Shaders/HzbMaxDepthProject.ankiprog +++ b/AnKi/Shaders/HzbMaxDepthProject.ankiprog @@ -11,7 +11,7 @@ Texture2D g_maxDepthRt : register(t0); -struct Uniforms +struct Constants { Mat4 m_reprojectionMat; @@ -20,7 +20,7 @@ struct Uniforms F32 m_padding0; F32 m_padding1; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) Vec4 main(U32 svVertexId : SV_VERTEXID, U32 svInstanceId : SV_INSTANCEID) : SV_POSITION { @@ -30,8 +30,8 @@ Vec4 main(U32 svVertexId : SV_VERTEXID, U32 svInstanceId : SV_INSTANCEID) : SV_P const U32 tileX = svInstanceId % maxDepthRtSize.x; const U32 tileY = svInstanceId / maxDepthRtSize.x; - const F32 maxDepth = min(g_maxDepthRt[UVec2(tileX, tileY)].x, g_unis.m_cascadeMaxDepth); - const F32 minDepth = g_unis.m_cascadeMinDepth; + const F32 maxDepth = min(g_maxDepthRt[UVec2(tileX, tileY)].x, g_consts.m_cascadeMaxDepth); + const F32 minDepth = g_consts.m_cascadeMinDepth; if(maxDepth <= minDepth) { @@ -63,7 +63,7 @@ Vec4 main(U32 svVertexId : SV_VERTEXID, U32 svInstanceId : SV_INSTANCEID) : SV_P ndc.xy = uvToNdc(saturate(ndc.xy)); // Unproject and project - return mul(g_unis.m_reprojectionMat, Vec4(ndc, 1.0)); + return mul(g_consts.m_reprojectionMat, Vec4(ndc, 1.0)); } #pragma anki technique_end vert diff --git a/AnKi/Shaders/Include/GpuSceneFunctions.h b/AnKi/Shaders/Include/GpuSceneFunctions.h index 0d66aee44..13b0bb7fd 100644 --- a/AnKi/Shaders/Include/GpuSceneFunctions.h +++ b/AnKi/Shaders/Include/GpuSceneFunctions.h @@ -13,7 +13,7 @@ inline GpuSceneRenderableInstance unpackGpuSceneRenderableVertex(UVec4 x) { GpuSceneRenderableInstance o; o.m_worldTransformsIndex = x[0]; - o.m_uniformsOffset = x[1]; + o.m_constantsOffset = x[1]; o.m_meshLodIndex = x[2]; o.m_boneTransformsOffsetOrParticleEmitterIndex = x[3]; return o; @@ -23,7 +23,7 @@ inline GpuSceneMeshletInstance unpackGpuSceneMeshletInstance(UVec4 x) { GpuSceneMeshletInstance o; o.m_worldTransformsIndex_25bit_meshletPrimitiveCount_7bit = x[0]; - o.m_uniformsOffset = x[1]; + o.m_constantsOffset = x[1]; o.m_meshletGeometryDescriptorIndex = x[2]; o.m_boneTransformsOffsetOrParticleEmitterIndex = x[3]; return o; diff --git a/AnKi/Shaders/Include/GpuSceneTypes.h b/AnKi/Shaders/Include/GpuSceneTypes.h index f0696a256..8d8b223a0 100644 --- a/AnKi/Shaders/Include/GpuSceneTypes.h +++ b/AnKi/Shaders/Include/GpuSceneTypes.h @@ -20,7 +20,7 @@ constexpr F32 kSomeFarDistance = 100000.0f; struct GpuSceneRenderable { U32 m_worldTransformsIndex; ///< First index points to the crnt transform and the 2nd to the previous. - U32 m_uniformsOffset; + U32 m_constantsOffset; U32 m_meshLodsIndex; ///< Points to the array of GpuSceneMeshLod. kMaxLodCount are reserved for each renderable. U32 m_boneTransformsOffset; ///< Array of Mat3x4 or 0 if its not a skin. U32 m_particleEmitterIndex; ///< Index to the GpuSceneParticleEmitter array or kMaxU32 if it's not an emitter. @@ -32,7 +32,7 @@ struct GpuSceneRenderable struct GpuSceneRenderableInstance { U32 m_worldTransformsIndex; - U32 m_uniformsOffset; + U32 m_constantsOffset; U32 m_meshLodIndex; ///< Points to a single GpuSceneMeshLod in the mesh lods. U32 m_boneTransformsOffsetOrParticleEmitterIndex; }; @@ -42,7 +42,7 @@ static_assert(sizeof(GpuSceneRenderableInstance) == sizeof(UVec4)); struct GpuSceneMeshletInstance { U32 m_worldTransformsIndex_25bit_meshletPrimitiveCount_7bit; - U32 m_uniformsOffset; + U32 m_constantsOffset; U32 m_meshletGeometryDescriptorIndex; ///< Index in the UGB. U32 m_boneTransformsOffsetOrParticleEmitterIndex; }; diff --git a/AnKi/Shaders/Include/GpuVisibilityTypes.h b/AnKi/Shaders/Include/GpuVisibilityTypes.h index 7996b19a4..0d366ae4d 100644 --- a/AnKi/Shaders/Include/GpuVisibilityTypes.h +++ b/AnKi/Shaders/Include/GpuVisibilityTypes.h @@ -9,7 +9,7 @@ ANKI_BEGIN_NAMESPACE -struct FrustumGpuVisibilityUniforms +struct FrustumGpuVisibilityConsts { Vec4 m_clipPlanes[6u]; @@ -23,7 +23,7 @@ struct FrustumGpuVisibilityUniforms Vec2 m_finalRenderTargetSize; }; -struct DistanceGpuVisibilityUniforms +struct DistanceGpuVisibilityConstants { Vec3 m_pointOfTest; F32 m_testRadius; @@ -34,12 +34,12 @@ struct DistanceGpuVisibilityUniforms F32 m_padding3; }; -struct GpuVisibilityNonRenderableUniforms +struct GpuVisibilityNonRenderableConstants { Vec4 m_clipPlanes[6u]; }; -struct GpuVisibilityAccelerationStructuresUniforms +struct GpuVisibilityAccelerationStructuresConstants { Vec4 m_clipPlanes[6u]; @@ -66,7 +66,7 @@ struct GpuVisibilityVisibleMeshletDesc U32 m_lod_2bit_meshletIndex_30bit; }; -struct GpuVisibilityMeshletUniforms +struct GpuVisibilityMeshletConstants { Mat4 m_viewProjectionMatrix; diff --git a/AnKi/Shaders/Include/MaterialTypes.h b/AnKi/Shaders/Include/MaterialTypes.h index 642dc7665..20368ea6a 100644 --- a/AnKi/Shaders/Include/MaterialTypes.h +++ b/AnKi/Shaders/Include/MaterialTypes.h @@ -10,7 +10,7 @@ ANKI_BEGIN_NAMESPACE /// Common data for all materials. -struct MaterialGlobalUniforms +struct MaterialGlobalConstants { Mat4 m_viewProjectionMatrix; Mat4 m_previousViewProjectionMatrix; @@ -19,10 +19,10 @@ struct MaterialGlobalUniforms Vec4 m_viewport; }; -static_assert(sizeof(MaterialGlobalUniforms) == 15 * sizeof(Vec4)); +static_assert(sizeof(MaterialGlobalConstants) == 15 * sizeof(Vec4)); #define ANKI_MATERIAL_REGISTER_TILINEAR_REPEAT_SAMPLER 0 -#define ANKI_MATERIAL_REGISTER_GLOBAL_UNIFORMS 0 +#define ANKI_MATERIAL_REGISTER_GLOBAL_CONSTANTS 0 #define ANKI_MATERIAL_REGISTER_GPU_SCENE 0 #define ANKI_MATERIAL_REGISTER_MESHLET_BOUNDING_VOLUMES 1 ///< Points to the unified geom buffer @@ -40,7 +40,7 @@ static_assert(sizeof(MaterialGlobalUniforms) == 15 * sizeof(Vec4)); #define ANKI_MATERIAL_REGISTER_SHADOW_SAMPLER 3 #define ANKI_MATERIAL_REGISTER_SCENE_DEPTH 9 #define ANKI_MATERIAL_REGISTER_LIGHT_VOLUME 10 -#define ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_UNIFORMS 1 +#define ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_CONSTANTS 1 #define ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_POINT_LIGHTS 11 #define ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_SPOT_LIGHTS 12 #define ANKI_MATERIAL_REGISTER_SHADOW_ATLAS 13 diff --git a/AnKi/Shaders/Include/MiscRendererTypes.h b/AnKi/Shaders/Include/MiscRendererTypes.h index 1d07c3535..4f3c8113b 100644 --- a/AnKi/Shaders/Include/MiscRendererTypes.h +++ b/AnKi/Shaders/Include/MiscRendererTypes.h @@ -59,7 +59,7 @@ struct CommonMatrices }; /// Common constants for all passes. -struct GlobalRendererUniforms +struct GlobalRendererConstants { Vec2 m_renderingSize; F32 m_time; @@ -89,7 +89,7 @@ struct GlobalRendererUniforms }; // RT shadows -struct RtShadowsDenoiseUniforms +struct RtShadowsDenoiseConstants { Mat4 m_invViewProjMat; @@ -99,7 +99,7 @@ struct RtShadowsDenoiseUniforms F32 m_padding2; }; -struct RtShadowsSbtBuildUniforms +struct RtShadowsSbtBuildConstants { U32 m_shaderHandleDwordSize; U32 m_sbtRecordDwordSize; @@ -116,7 +116,7 @@ struct LensFlareSprite }; // Depth downscale -struct DepthDownscaleUniforms +struct DepthDownscaleConstants { Vec2 m_srcTexSizeOverOne; U32 m_threadgroupCount; @@ -124,7 +124,7 @@ struct DepthDownscaleUniforms }; // Screen space reflections uniforms -struct SsrUniforms +struct SsrConstants { Vec2 m_viewportSizef; U32 m_frameCount; @@ -143,7 +143,7 @@ struct SsrUniforms }; // Vol fog -struct VolumetricFogUniforms +struct VolumetricFogConstants { RVec3 m_fogDiffuse; RF32 m_fogScatteringCoeff; @@ -158,7 +158,7 @@ struct VolumetricFogUniforms }; // Vol lighting -struct VolumetricLightingUniforms +struct VolumetricLightingConstants { RF32 m_densityAtMinHeight; RF32 m_densityAtMaxHeight; @@ -170,7 +170,7 @@ struct VolumetricLightingUniforms }; // SSAO -struct SsaoUniforms +struct SsaoConstants { RF32 m_radius; ///< In meters. U32 m_sampleCount; @@ -190,7 +190,7 @@ struct SsaoUniforms Mat3x4 m_viewMat; }; -struct SsaoSpatialDenoiseUniforms +struct SsaoSpatialDenoiseConstants { Mat3x4 m_viewToWorldMat; diff --git a/AnKi/Shaders/Include/TraditionalDeferredShadingTypes.h b/AnKi/Shaders/Include/TraditionalDeferredShadingTypes.h index 35f1cdb37..c28b11697 100644 --- a/AnKi/Shaders/Include/TraditionalDeferredShadingTypes.h +++ b/AnKi/Shaders/Include/TraditionalDeferredShadingTypes.h @@ -17,7 +17,7 @@ struct TraditionalDeferredShadingDirectionalLight Mat4 m_lightMatrix; }; -struct TraditionalDeferredShadingUniforms +struct TraditionalDeferredShadingConstants { // Use these to get the correct face UVs Vec2 m_inputTexUvScale; @@ -31,7 +31,7 @@ struct TraditionalDeferredShadingUniforms TraditionalDeferredShadingDirectionalLight m_dirLight; }; -struct TraditionalDeferredSkyboxUniforms +struct TraditionalDeferredSkyboxConstants { RVec3 m_solidColor; F32 m_padding1; diff --git a/AnKi/Shaders/IrradianceDice.ankiprog b/AnKi/Shaders/IrradianceDice.ankiprog index a803e7f7f..93ea63deb 100644 --- a/AnKi/Shaders/IrradianceDice.ankiprog +++ b/AnKi/Shaders/IrradianceDice.ankiprog @@ -29,13 +29,13 @@ TextureCube g_gbufferTex[3u] : register(t1); #if STORE_LOCATION == 0 RWTexture3D g_irradianceVolume : register(u0); -struct Uniforms +struct Constants { IVec3 m_volumeTexel; I32 m_nextTexelOffsetInU; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) #else struct BufferOut { @@ -197,13 +197,14 @@ RVec3 sampleLightShadingTexture(const U32 face, UVec3 svGroupThreadId) const UVec3 subvolumeSize = UVec3(volumeSize.x / 6u, volumeSize.y, volumeSize.z); const U32 cellIdx = - g_unis.m_volumeTexel.z * subvolumeSize.x * subvolumeSize.y + g_unis.m_volumeTexel.y * subvolumeSize.x + g_unis.m_volumeTexel.x; + g_consts.m_volumeTexel.z * subvolumeSize.x * subvolumeSize.y + g_consts.m_volumeTexel.y * subvolumeSize.x + g_consts.m_volumeTexel.x; const RF32 headmapFactor = F32(cellIdx) / F32(subvolumeSize.x * subvolumeSize.y * subvolumeSize.z); const RVec3 toStoreValue = heatmap(headmapFactor); #endif #if STORE_LOCATION == 0 - const UVec3 storeUvw = UVec3(g_unis.m_volumeTexel.x + I32(f) * g_unis.m_nextTexelOffsetInU, g_unis.m_volumeTexel.y, g_unis.m_volumeTexel.z); + const UVec3 storeUvw = + UVec3(g_consts.m_volumeTexel.x + I32(f) * g_consts.m_nextTexelOffsetInU, g_consts.m_volumeTexel.y, g_consts.m_volumeTexel.z); g_irradianceVolume[storeUvw] = Vec4(toStoreValue, 0.0); #else g_irradianceDisceResults[0].m_val[f] = toStoreValue.xyzx; diff --git a/AnKi/Shaders/LensFlareUpdateIndirectInfo.ankiprog b/AnKi/Shaders/LensFlareUpdateIndirectInfo.ankiprog index 47716a12e..c0fb13546 100644 --- a/AnKi/Shaders/LensFlareUpdateIndirectInfo.ankiprog +++ b/AnKi/Shaders/LensFlareUpdateIndirectInfo.ankiprog @@ -8,7 +8,7 @@ #define THREAD_COUNT_SQRT 8 -ANKI_PUSH_CONSTANTS(Mat4, g_mvp) +ANKI_FAST_CONSTANTS(Mat4, g_mvp) StructuredBuffer g_flarePositions : register(t0); RWStructuredBuffer g_indirectInfo : register(u0); SamplerState g_nearestAnyClampSampler : register(s0); diff --git a/AnKi/Shaders/LightShading.ankiprog b/AnKi/Shaders/LightShading.ankiprog index 592815fbc..ad30df1cf 100644 --- a/AnKi/Shaders/LightShading.ankiprog +++ b/AnKi/Shaders/LightShading.ankiprog @@ -14,7 +14,7 @@ #include #include -ConstantBuffer g_globalUniforms : register(b0); +ConstantBuffer g_globalConstants : register(b0); StructuredBuffer g_pointLights : register(t0); StructuredBuffer g_spotLights : register(t1); StructuredBuffer g_giProbes : register(t2); @@ -54,13 +54,13 @@ RVec3 main(VertOut input) : SV_TARGET0 } // Get world position - const Vec4 worldPos4 = mul(g_globalUniforms.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_globalConstants.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; - const RVec3 viewDir = normalize(g_globalUniforms.m_cameraPosition - worldPos); + const RVec3 viewDir = normalize(g_globalConstants.m_cameraPosition - worldPos); // Get the cluster - Cluster cluster = getClusterFragCoord(g_clusters, g_globalUniforms, Vec3(input.m_svPosition.xy, depth)); + Cluster cluster = getClusterFragCoord(g_clusters, g_globalConstants, Vec3(input.m_svPosition.xy, depth)); // return clusterHeatmap(cluster, 1u << (U32)GpuSceneNonRenderableObjectType::kLight, 3); @@ -133,7 +133,7 @@ RVec3 main(VertOut input) : SV_TARGET0 [branch] if(ssr.w < 0.9f) { const Vec3 reflDir = reflect(-viewDir, gbuffer.m_normal); - const RF32 reflLod = (g_globalUniforms.m_reflectionProbesMipCount - 1.0f) * gbuffer.m_roughness; + const RF32 reflLod = (g_globalConstants.m_reflectionProbesMipCount - 1.0f) * gbuffer.m_roughness; RVec3 probeColor = 0.0f; const U32 oneProbe = WaveActiveAllTrue(countbits(cluster.m_reflectionProbesMask) == 1); @@ -191,7 +191,7 @@ RVec3 main(VertOut input) : SV_TARGET0 U32 resolvedSmIdx = 0u; // Dir light - const DirectionalLight dirLight = g_globalUniforms.m_directionalLight; + const DirectionalLight dirLight = g_globalConstants.m_directionalLight; if(dirLight.m_shadowCascadeCount_31bit_active_1bit & 1u) { RF32 shadowFactor; diff --git a/AnKi/Shaders/LightShadingApplyFog.ankiprog b/AnKi/Shaders/LightShadingApplyFog.ankiprog index 4b38ab07b..8f0dab99d 100644 --- a/AnKi/Shaders/LightShadingApplyFog.ankiprog +++ b/AnKi/Shaders/LightShadingApplyFog.ankiprog @@ -16,14 +16,14 @@ SamplerState g_linearAnyClampSampler : register(s1); Texture2D g_depthRt : register(t0); Texture3D g_fogVolume : register(t1); -struct Uniforms +struct Constants { F32 m_zSplitCount; F32 m_finalZSplit; F32 m_near; F32 m_far; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) RVec4 main(VertOut input) : SV_TARGET0 { @@ -32,8 +32,8 @@ RVec4 main(VertOut input) : SV_TARGET0 // Compute W coordinate const F32 depth = g_depthRt.SampleLevel(g_nearestAnyClampSampler, uv, 0.0).r; - const F32 linearDepth = linearizeDepth(depth, g_unis.m_near, g_unis.m_far); - uvw.z = linearDepth * (g_unis.m_zSplitCount / (g_unis.m_finalZSplit + 1.0f)); + const F32 linearDepth = linearizeDepth(depth, g_consts.m_near, g_consts.m_far); + uvw.z = linearDepth * (g_consts.m_zSplitCount / (g_consts.m_finalZSplit + 1.0f)); // Compute UV coordinates uvw.xy = uv; diff --git a/AnKi/Shaders/LightShadingSkybox.ankiprog b/AnKi/Shaders/LightShadingSkybox.ankiprog index 88f9220c2..0d6a2473f 100644 --- a/AnKi/Shaders/LightShadingSkybox.ankiprog +++ b/AnKi/Shaders/LightShadingSkybox.ankiprog @@ -19,18 +19,18 @@ #include #if METHOD == 0 -struct Uniforms +struct Constants { RVec3 m_solidColor; F32 m_padding; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) #elif METHOD == 1 SamplerState g_trilinearAnySampler : register(s0); Texture2D g_envMapTex : register(t0); -struct Uniforms +struct Constants { Mat4 m_invertedViewProjectionJitterMat; @@ -44,11 +44,11 @@ struct Uniforms F32 m_padding2; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) #else SamplerState g_linearAnyClampSampler : register(s0); Texture2D g_skyLut : register(t0); -ConstantBuffer g_unis : register(b0); +ConstantBuffer g_consts : register(b0); #endif RVec3 main(VertOut input) : SV_TARGET0 @@ -56,14 +56,14 @@ RVec3 main(VertOut input) : SV_TARGET0 const Vec2 uv = input.m_uv; #if METHOD == 0 ANKI_MAYBE_UNUSED(uv); - return g_unis.m_solidColor; + return g_consts.m_solidColor; #elif METHOD == 1 const F32 depth = 1.0; const Vec2 ndc = uvToNdc(uv); - const Vec4 worldPos4 = mul(g_unis.m_invertedViewProjectionJitterMat, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_consts.m_invertedViewProjectionJitterMat, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; - const Vec3 eyeToFrag = normalize(worldPos - g_unis.m_cameraPos); + const Vec3 eyeToFrag = normalize(worldPos - g_consts.m_cameraPos); const Vec2 uv3 = equirectangularMapping(eyeToFrag); @@ -75,17 +75,17 @@ RVec3 main(VertOut input) : SV_TARGET0 const F32 bias = (maxD > 0.9) ? -100.0f : 0.0f; - return g_envMapTex.SampleBias(g_trilinearAnySampler, uv3, bias).rgb * g_unis.m_scale + g_unis.m_bias; + return g_envMapTex.SampleBias(g_trilinearAnySampler, uv3, bias).rgb * g_consts.m_scale + g_consts.m_bias; #else const F32 depth = 1.0; const Vec2 ndc = uvToNdc(uv); - const Vec4 worldPos4 = mul(g_unis.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_consts.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; - const Vec3 eyeToFrag = normalize(worldPos - g_unis.m_cameraPosition); + const Vec3 eyeToFrag = normalize(worldPos - g_consts.m_cameraPosition); - return computeSkyColor(g_skyLut, g_linearAnyClampSampler, eyeToFrag, -g_unis.m_directionalLight.m_direction, g_unis.m_directionalLight.m_power, - true); + return computeSkyColor(g_skyLut, g_linearAnyClampSampler, eyeToFrag, -g_consts.m_directionalLight.m_direction, + g_consts.m_directionalLight.m_power, true); #endif } diff --git a/AnKi/Shaders/MaterialShadersCommon.hlsl b/AnKi/Shaders/MaterialShadersCommon.hlsl index f53fbba2d..3dc4eb74c 100644 --- a/AnKi/Shaders/MaterialShadersCommon.hlsl +++ b/AnKi/Shaders/MaterialShadersCommon.hlsl @@ -17,7 +17,7 @@ #define ANKI_REG(type, binding) _ANKI_REG(type, binding) SamplerState g_globalSampler : register(ANKI_REG(s, ANKI_MATERIAL_REGISTER_TILINEAR_REPEAT_SAMPLER)); -ConstantBuffer g_globalUniforms : register(ANKI_REG(b, ANKI_MATERIAL_REGISTER_GLOBAL_UNIFORMS)); +ConstantBuffer g_globalConstants : register(ANKI_REG(b, ANKI_MATERIAL_REGISTER_GLOBAL_CONSTANTS)); ByteAddressBuffer g_gpuScene : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_GPU_SCENE)); // Unified geom: @@ -35,12 +35,12 @@ SamplerState g_nearestClampSampler : register(ANKI_REG(s, ANKI_MATERIAL_REGISTER StructuredBuffer g_firstMeshlet : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_FIRST_MESHLET)); #if ANKI_MESH_SHADER -struct PushConsts +struct Consts { UVec3 m_padding; U32 m_bucketIndex; }; -ANKI_PUSH_CONSTANTS(PushConsts, g_pushConsts) +ANKI_FAST_CONSTANTS(Consts, g_consts) #endif // FW shading specific @@ -52,7 +52,7 @@ Texture2D g_gbufferDepthTex : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_SCENE_ Texture3D g_lightVol : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_LIGHT_VOLUME)); SamplerComparisonState g_shadowSampler : register(ANKI_REG(s, ANKI_MATERIAL_REGISTER_SHADOW_SAMPLER)); -ConstantBuffer g_globalRendererUniforms : register(ANKI_REG(b, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_UNIFORMS)); +ConstantBuffer g_globalRendererConstants : register(ANKI_REG(b, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_CONSTANTS)); StructuredBuffer g_clusters : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_CLUSTERS)); StructuredBuffer g_pointLights : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_POINT_LIGHTS)); StructuredBuffer g_spotLights : register(ANKI_REG(t, ANKI_MATERIAL_REGISTER_CLUSTER_SHADING_SPOT_LIGHTS)); diff --git a/AnKi/Shaders/MotionVectors.ankiprog b/AnKi/Shaders/MotionVectors.ankiprog index 84cf5f189..29056cad3 100644 --- a/AnKi/Shaders/MotionVectors.ankiprog +++ b/AnKi/Shaders/MotionVectors.ankiprog @@ -16,14 +16,14 @@ SamplerState g_nearesetAnyClampSampler : register(s0); Texture2D g_currentDepthTex : register(t0); Texture2D g_velocityTex : register(t1); -struct Uniforms +struct Constants { Mat4 m_currentViewProjMat; Mat4 m_currentInvViewProjMat; Mat4 m_prevViewProjMat; }; -ConstantBuffer g_unis : register(b0); +ConstantBuffer g_consts : register(b0); # if ANKI_COMPUTE_SHADER RWTexture2D g_motionVectorsStorageTex : register(u0); @@ -60,13 +60,13 @@ FragOut main(VertOut input) // Don't use a reprojection matrix or other kind of optimizations. Due to numerical precision it produces slightly off result. Big enough to // create slight visual issues. Do it the hard way. const F32 depth = g_currentDepthTex.SampleLevel(g_nearesetAnyClampSampler, uv, 0.0).r; - const Vec4 v4 = mul(g_unis.m_currentInvViewProjMat, Vec4(uvToNdc(uv), depth, 1.0)); + const Vec4 v4 = mul(g_consts.m_currentInvViewProjMat, Vec4(uvToNdc(uv), depth, 1.0)); const Vec3 worldPos = v4.xyz / v4.w; - Vec4 clipPos = mul(g_unis.m_currentViewProjMat, Vec4(worldPos, 1.0)); + Vec4 clipPos = mul(g_consts.m_currentViewProjMat, Vec4(worldPos, 1.0)); clipPos.xy /= clipPos.w; - Vec4 prevClipPos = mul(g_unis.m_prevViewProjMat, Vec4(worldPos, 1.0)); + Vec4 prevClipPos = mul(g_consts.m_prevViewProjMat, Vec4(worldPos, 1.0)); prevClipPos.xy /= prevClipPos.w; const Vec2 diff = (prevClipPos.xy - clipPos.xy) * 0.5f; // aka uvToNdc(prevClipPos.xy) - uvToNdc(clipPos.xy) diff --git a/AnKi/Shaders/RtShadows.ankiprog b/AnKi/Shaders/RtShadows.ankiprog index bc36374be..f7a07b26d 100644 --- a/AnKi/Shaders/RtShadows.ankiprog +++ b/AnKi/Shaders/RtShadows.ankiprog @@ -15,7 +15,7 @@ #define SPACE space2 -ConstantBuffer g_globalRendererUniforms : register(b0, SPACE); +ConstantBuffer g_globalRendererConstants : register(b0, SPACE); SamplerState g_trilinearRepeatSampler : register(s0, SPACE); @@ -53,7 +53,7 @@ F32 trace(const Vec3 rayOrigin, const Vec3 rayDir, F32 tMax) Vec3 genRandomDirection(U32 rayIdx, Vec2 uv) { - const U32 frameIdx = g_globalRendererUniforms.m_frame * RAYS_PER_PIXEL + rayIdx; + const U32 frameIdx = g_globalRendererConstants.m_frame * RAYS_PER_PIXEL + rayIdx; Vec2 noiseTexSize; g_blueNoiseTex.GetDimensions(noiseTexSize.x, noiseTexSize.y); @@ -71,7 +71,7 @@ Vec3 genRandomDirection(U32 rayIdx, Vec2 uv) const Vec2 uv = (Vec2(DispatchRaysIndex().xy) + 0.5) / Vec2(DispatchRaysDimensions().xy); const Vec2 ndc = uvToNdc(uv); const F32 depth = g_depthRt.SampleLevel(g_linearAnyClampSampler, uv, 0.0).r; - const Vec4 worldPos4 = mul(g_globalRendererUniforms.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_globalRendererConstants.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; if(depth == 1.0) @@ -86,7 +86,7 @@ Vec3 genRandomDirection(U32 rayIdx, Vec2 uv) // Dir light F32 shadowFactor = 0.0f; - const DirectionalLight dirLight = g_globalRendererUniforms.m_directionalLight; + const DirectionalLight dirLight = g_globalRendererConstants.m_directionalLight; for(U32 i = 0; i < RAYS_PER_PIXEL; ++i) { const Vec3 dirLightPos = worldPos + -dirLight.m_direction * 10.0 + genRandomDirection(i, uv); diff --git a/AnKi/Shaders/RtShadowsDenoise.ankiprog b/AnKi/Shaders/RtShadowsDenoise.ankiprog index 638dce5ef..1e61fecca 100644 --- a/AnKi/Shaders/RtShadowsDenoise.ankiprog +++ b/AnKi/Shaders/RtShadowsDenoise.ankiprog @@ -20,11 +20,11 @@ Texture2D g_momentsTex : register(t3); Texture2D g_historyLengthTex : register(t4); RWTexture2D g_storageTex : register(u0); -ANKI_PUSH_CONSTANTS(RtShadowsDenoiseUniforms, g_unis) +ANKI_FAST_CONSTANTS(RtShadowsDenoiseConstants, g_consts) Vec3 unproject(Vec2 ndc, F32 depth) { - const Vec4 worldPos4 = mul(g_unis.m_invViewProjMat, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_consts.m_invViewProjMat, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; return worldPos; } @@ -82,12 +82,12 @@ F32 computeVarianceCenter(Vec2 uv) if(historyLength < 2.0) { // Worst case - sampleCount = g_unis.m_maxSampleCount; + sampleCount = g_consts.m_maxSampleCount; } else if(historyLength > 4.0 && varianceCenter < 0.0001) { // Best case - sampleCount = g_unis.m_minSampleCount; + sampleCount = g_consts.m_minSampleCount; } else { @@ -96,7 +96,7 @@ F32 computeVarianceCenter(Vec2 uv) F32 blur = varianceCenter * 100.0; blur = min(1.0, blur); - const F32 sampleCountf = lerp(F32(g_unis.m_minSampleCount), F32(g_unis.m_maxSampleCount), blur); + const F32 sampleCountf = lerp(F32(g_consts.m_minSampleCount), F32(g_consts.m_maxSampleCount), blur); sampleCount = U32(sampleCountf); } diff --git a/AnKi/Shaders/RtShadowsSbtBuild.ankiprog b/AnKi/Shaders/RtShadowsSbtBuild.ankiprog index 7ad7a2959..31504d0c1 100644 --- a/AnKi/Shaders/RtShadowsSbtBuild.ankiprog +++ b/AnKi/Shaders/RtShadowsSbtBuild.ankiprog @@ -17,7 +17,7 @@ StructuredBuffer g_shaderHandles : register(t3); RWStructuredBuffer g_sbtBuffer : register(u0); -ANKI_PUSH_CONSTANTS(RtShadowsSbtBuildUniforms, g_unis) +ANKI_FAST_CONSTANTS(RtShadowsSbtBuildConstants, g_consts) #define NUMTHREADS 64 @@ -31,19 +31,19 @@ ANKI_PUSH_CONSTANTS(RtShadowsSbtBuildUniforms, g_unis) const GpuSceneRenderable renderable = g_renderables[g_visibleRenderableIndices[svDispatchThreadId + 1]]; - U32 sbtDwordOffset = g_unis.m_sbtRecordDwordSize * 2; // Skip raygen and miss shaders which are first - sbtDwordOffset += g_unis.m_sbtRecordDwordSize * svDispatchThreadId; + U32 sbtDwordOffset = g_consts.m_sbtRecordDwordSize * 2; // Skip raygen and miss shaders which are first + sbtDwordOffset += g_consts.m_sbtRecordDwordSize * svDispatchThreadId; // Copy the handle - for(U32 i = 0; i < g_unis.m_shaderHandleDwordSize; ++i) + for(U32 i = 0; i < g_consts.m_shaderHandleDwordSize; ++i) { - g_sbtBuffer[sbtDwordOffset] = g_shaderHandles[renderable.m_rtShadowsShaderHandleIndex * g_unis.m_shaderHandleDwordSize + i]; + g_sbtBuffer[sbtDwordOffset] = g_shaderHandles[renderable.m_rtShadowsShaderHandleIndex * g_consts.m_shaderHandleDwordSize + i]; ++sbtDwordOffset; } // Copy the GpuSceneRenderableInstance g_sbtBuffer[sbtDwordOffset++] = renderable.m_worldTransformsIndex; - g_sbtBuffer[sbtDwordOffset++] = renderable.m_uniformsOffset; + g_sbtBuffer[sbtDwordOffset++] = renderable.m_constantsOffset; g_sbtBuffer[sbtDwordOffset++] = renderable.m_meshLodsIndex; g_sbtBuffer[sbtDwordOffset] = 0; } diff --git a/AnKi/Shaders/RtShadowsSvgfAtrous.ankiprog b/AnKi/Shaders/RtShadowsSvgfAtrous.ankiprog index 4bfa9331f..41ac6510c 100644 --- a/AnKi/Shaders/RtShadowsSvgfAtrous.ankiprog +++ b/AnKi/Shaders/RtShadowsSvgfAtrous.ankiprog @@ -21,7 +21,7 @@ RWTexture2D g_shadowStorageTex : register(u0); RWTexture2D g_varianceStorageTex : register(u1); #endif -ANKI_PUSH_CONSTANTS(Mat4, g_invProjMat) +ANKI_FAST_CONSTANTS(Mat4, g_invProjMat) constexpr I32 kConvolutionRadius = 2; constexpr F32 kKernelWeights[kConvolutionRadius + 1] = {1.0, 2.0 / 3.0, 1.0 / 6.0}; diff --git a/AnKi/Shaders/RtShadowsSvgfVariance.ankiprog b/AnKi/Shaders/RtShadowsSvgfVariance.ankiprog index 8cc8fb946..f93b00dad 100644 --- a/AnKi/Shaders/RtShadowsSvgfVariance.ankiprog +++ b/AnKi/Shaders/RtShadowsSvgfVariance.ankiprog @@ -18,7 +18,7 @@ Texture2D g_depthTex : register(t3); RWTexture2D g_shadowUav : register(u0); RWTexture2D g_varianceUav : register(u1); -ANKI_PUSH_CONSTANTS(Mat4, g_invProjMat) +ANKI_FAST_CONSTANTS(Mat4, g_invProjMat) constexpr I32 kConvolutionRadius = 1; diff --git a/AnKi/Shaders/ShadowMappingVetVisibility.ankiprog b/AnKi/Shaders/ShadowMappingVetVisibility.ankiprog index 37070ad0f..1cef55e17 100644 --- a/AnKi/Shaders/ShadowMappingVetVisibility.ankiprog +++ b/AnKi/Shaders/ShadowMappingVetVisibility.ankiprog @@ -19,7 +19,7 @@ RWStructuredBuffer g_clearTileIndirectArgs : register(u3); RWStructuredBuffer g_dispatchMeshIndirectArgs : register(u4); RWStructuredBuffer g_drawIndirectArgs : register(u5); -struct Uniforms +struct Constants { U32 m_lightIndex; U32 m_padding0; @@ -27,7 +27,7 @@ struct Uniforms U32 m_padding2; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) groupshared U32 s_renderLight; @@ -35,7 +35,7 @@ groupshared U32 s_renderLight; { if(svGroupIndex == 0) { - const GpuSceneLight light = g_lights[g_unis.m_lightIndex]; + const GpuSceneLight light = g_lights[g_consts.m_lightIndex]; const U32 crntHash = g_lightHashes[light.m_visibleRenderablesHashIndex].m_hash; s_renderLight = crntHash != g_hash[0].m_renderablesHash || g_hash[0].m_containsDeformable == 1; diff --git a/AnKi/Shaders/ShadowmapsResolve.ankiprog b/AnKi/Shaders/ShadowmapsResolve.ankiprog index 51a40c574..dc96323bd 100644 --- a/AnKi/Shaders/ShadowmapsResolve.ankiprog +++ b/AnKi/Shaders/ShadowmapsResolve.ankiprog @@ -12,7 +12,7 @@ # define DEBUG_CASCADES 0 -ConstantBuffer g_globalUniforms : register(b0); +ConstantBuffer g_globalConstants : register(b0); StructuredBuffer g_pointLights : register(t0); StructuredBuffer g_spotLights : register(t1); Texture2D g_shadowAtlasTex : register(t2); @@ -32,14 +32,14 @@ Texture2D g_dirLightResolvedShadowsTex : register(t6); RWTexture2D g_storageTex : register(u0); # endif -struct Uniforms +struct Constants { Vec2 m_framebufferSize; F32 m_padding0; F32 m_padding1; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) Vec3 computeDebugShadowCascadeColor(U32 cascade) { @@ -68,8 +68,8 @@ RVec4 main(VertOut input) : SV_TARGET0 # endif { # if ANKI_COMPUTE_SHADER - svDispatchThreadId = min(svDispatchThreadId, UVec2(g_unis.m_framebufferSize - 1.0f)); // Just to be sure - const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5) / g_unis.m_framebufferSize; + svDispatchThreadId = min(svDispatchThreadId, UVec2(g_consts.m_framebufferSize - 1.0f)); // Just to be sure + const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5) / g_consts.m_framebufferSize; # else const Vec2 uv = input.m_uv; # endif @@ -79,21 +79,21 @@ RVec4 main(VertOut input) : SV_TARGET0 Vec2 noiseTexSize; g_noiseTex.GetDimensions(noiseTexSize.x, noiseTexSize.y); - const Vec2 noiseUv = g_unis.m_framebufferSize / noiseTexSize * uv; + const Vec2 noiseUv = g_consts.m_framebufferSize / noiseTexSize * uv; RVec3 noise = g_noiseTex.SampleLevel(g_trilinearRepeatSampler, noiseUv, 0.0).rgb; - noise = animateBlueNoise(noise, g_globalUniforms.m_frame % 16u); + noise = animateBlueNoise(noise, g_globalConstants.m_frame % 16u); const RF32 randFactor = noise.x; # endif // World position const Vec2 ndc = uvToNdc(uv); const F32 depth = g_depthRt.SampleLevel(g_linearAnyClampSampler, uv, 0.0).r; - const Vec4 worldPos4 = mul(g_globalUniforms.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_globalConstants.m_matrices.m_invertedViewProjectionJitter, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; // Cluster - const Vec2 fragCoord = uv * g_globalUniforms.m_renderingSize; - Cluster cluster = getClusterFragCoord(g_clusters, g_globalUniforms, Vec3(fragCoord, depth)); + const Vec2 fragCoord = uv * g_globalConstants.m_renderingSize; + Cluster cluster = getClusterFragCoord(g_clusters, g_globalConstants, Vec3(fragCoord, depth)); // Layers U32 shadowCasterCountPerFragment = 0u; @@ -105,13 +105,13 @@ RVec4 main(VertOut input) : SV_TARGET0 shadowFactors[0] = g_dirLightResolvedShadowsTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0f).x; ++shadowCasterCountPerFragment; # else - const DirectionalLight dirLight = g_globalUniforms.m_directionalLight; + const DirectionalLight dirLight = g_globalConstants.m_directionalLight; if(dirLight.m_shadowCascadeCount_31bit_active_1bit != 0u) { const U32 shadowCascadeCount = dirLight.m_shadowCascadeCount_31bit_active_1bit >> 1u; const RF32 positiveZViewSpace = - testPlanePoint(g_globalUniforms.m_nearPlaneWSpace.xyz, g_globalUniforms.m_nearPlaneWSpace.w, worldPos) + g_globalUniforms.m_near; + testPlanePoint(g_globalConstants.m_nearPlaneWSpace.xyz, g_globalConstants.m_nearPlaneWSpace.w, worldPos) + g_globalConstants.m_near; const F32 lastCascadeDistance = dirLight.m_shadowCascadeDistances[shadowCascadeCount - 1u]; RF32 shadowFactor; diff --git a/AnKi/Shaders/Sky.ankiprog b/AnKi/Shaders/Sky.ankiprog index 76e26f945..d136e1a35 100644 --- a/AnKi/Shaders/Sky.ankiprog +++ b/AnKi/Shaders/Sky.ankiprog @@ -329,7 +329,7 @@ Texture2D g_tLutTex : register(t0); Texture2D g_mLutTex : register(t1); SamplerState g_linearAnyClampSampler : register(s0); RWTexture2D g_skyLutStorageTex : register(u0); -ConstantBuffer g_globalUniforms : register(b0); +ConstantBuffer g_globalConstants : register(b0); Vec3 raymarchScattering(Vec3 pos, Vec3 rayDir, Vec3 dirToSun, F32 tMax, F32 numSteps) { @@ -402,7 +402,7 @@ Vec3 raymarchScattering(Vec3 pos, Vec3 rayDir, Vec3 dirToSun, F32 tMax, F32 numS const F32 cosAltitude = cos(altitudeAngle); const Vec3 rayDir = Vec3(cosAltitude * sin(azimuthAngle), sin(altitudeAngle), -cosAltitude * cos(azimuthAngle)); - const F32 sunAltitude = (0.5f * kPi) - acos(dot(-g_globalUniforms.m_directionalLight.m_direction, up)); + const F32 sunAltitude = (0.5f * kPi) - acos(dot(-g_globalConstants.m_directionalLight.m_direction, up)); const Vec3 dirToSun = Vec3(0.0f, sin(sunAltitude), -cos(sunAltitude)); const F32 atmoDist = rayIntersectSphere(kViewPos, rayDir, kAtmosphereRadiusMM); @@ -424,14 +424,14 @@ Vec3 raymarchScattering(Vec3 pos, Vec3 rayDir, Vec3 dirToSun, F32 tMax, F32 numS #include Texture2D g_tLutTex : register(t0); -globallycoherent RWStructuredBuffer g_globalUniforms : register(u0); +globallycoherent RWStructuredBuffer g_globalConstants : register(u0); [numthreads(1, 1, 1)] void main(UVec2 svDispatchThreadId : SV_DISPATCHTHREADID) { - const Vec3 sunTransmittance = getValFromTLut(g_tLutTex, kViewPos, -g_globalUniforms[0].m_directionalLight.m_direction); - const F32 sunPower = g_globalUniforms[0].m_directionalLight.m_power; + const Vec3 sunTransmittance = getValFromTLut(g_tLutTex, kViewPos, -g_globalConstants[0].m_directionalLight.m_direction); + const F32 sunPower = g_globalConstants[0].m_directionalLight.m_power; - g_globalUniforms[0].m_directionalLight.m_diffuseColor = Vec4(sunPower * sunTransmittance, 0.0f); + g_globalConstants[0].m_directionalLight.m_diffuseColor = Vec4(sunPower * sunTransmittance, 0.0f); } #pragma anki technique_end comp ComputeSunColor diff --git a/AnKi/Shaders/Ssao.ankiprog b/AnKi/Shaders/Ssao.ankiprog index ff38bed27..31969360a 100644 --- a/AnKi/Shaders/Ssao.ankiprog +++ b/AnKi/Shaders/Ssao.ankiprog @@ -30,22 +30,23 @@ SamplerState g_linearAnyClampSampler : register(s1); RWTexture2D g_bentNormalsAndSsaoStorageTex : register(u0); # endif -ANKI_PUSH_CONSTANTS(SsaoUniforms, g_unis) +ANKI_FAST_CONSTANTS(SsaoConstants, g_consts) Vec3 unproject(Vec2 ndc) { const F32 d = g_depthTex.SampleLevel(g_linearAnyClampSampler, ndcToUv(ndc), 0.0).r; - return cheapPerspectiveUnprojection(g_unis.m_unprojectionParameters, ndc, d); + return cheapPerspectiveUnprojection(g_consts.m_unprojectionParameters, ndc, d); } Vec4 project(Vec4 p) { - return cheapPerspectiveProjection(g_unis.m_projectionMat00, g_unis.m_projectionMat11, g_unis.m_projectionMat22, g_unis.m_projectionMat23, p); + return cheapPerspectiveProjection(g_consts.m_projectionMat00, g_consts.m_projectionMat11, g_consts.m_projectionMat22, g_consts.m_projectionMat23, + p); } RF32 computeFalloff(RF32 len) { - return sqrt(1.0f - min(1.0f, len / g_unis.m_radius)); + return sqrt(1.0f - min(1.0f, len / g_consts.m_radius)); } # if ANKI_COMPUTE_SHADER @@ -55,7 +56,7 @@ RVec4 main(VertOut input) : SV_TARGET0 # endif { # if ANKI_COMPUTE_SHADER - const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5) / g_unis.m_viewportSizef; + const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5) / g_consts.m_viewportSizef; # else const UVec2 svDispatchThreadId = input.m_svPosition; ANKI_MAYBE_UNUSED(svDispatchThreadId); @@ -64,23 +65,23 @@ RVec4 main(VertOut input) : SV_TARGET0 const Vec2 ndc = uvToNdc(uv); const F32 depth = g_depthTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0).r; - const Vec3 Pc = cheapPerspectiveUnprojection(g_unis.m_unprojectionParameters, ndc, depth); + const Vec3 Pc = cheapPerspectiveUnprojection(g_consts.m_unprojectionParameters, ndc, depth); const RVec3 V = normalize(-Pc); // View vector // Get noise # if 0 Vec2 noiseTexSize; g_noiseTex.GetDimensions(noiseTexSize.x, noiseTexSize.y); - const RVec2 noiseUv = Vec2(g_unis.m_viewportSizef) / noiseTexSize * uv; - const RVec2 noise2 = animateBlueNoise(g_noiseTex.SampleLevel(g_trilinearRepeatSampler, noiseUv, 0.0).xyz, g_unis.m_frameCount).yx; + const RVec2 noiseUv = Vec2(g_consts.m_viewportSizef) / noiseTexSize * uv; + const RVec2 noise2 = animateBlueNoise(g_noiseTex.SampleLevel(g_trilinearRepeatSampler, noiseUv, 0.0).xyz, g_consts.m_frameCount).yx; # else - const RVec2 noise2 = spatioTemporalNoise(svDispatchThreadId, g_unis.m_frameCount); + const RVec2 noise2 = spatioTemporalNoise(svDispatchThreadId, g_consts.m_frameCount); # endif // Rand slice direction const RF32 randAng = noise2.x * kPi; # if 0 - const RF32 aspect = g_unis.m_viewportSizef.x / g_unis.m_viewportSizef.y; + const RF32 aspect = g_consts.m_viewportSizef.x / g_consts.m_viewportSizef.y; const RVec2 dir2d = normalize(Vec2(cos(randAng), sin(randAng)) * Vec2(1.0f, aspect)); # else const RVec2 dir2d = Vec2(cos(randAng), sin(randAng)); @@ -88,7 +89,7 @@ RVec4 main(VertOut input) : SV_TARGET0 // Project the view normal to the slice const Vec3 worldNormal = unpackNormalFromGBuffer(g_gbufferRt2.SampleLevel(g_linearAnyClampSampler, uv, 0.0)); - const RVec3 viewNormal = mul(g_unis.m_viewMat, Vec4(worldNormal, 0.0)); + const RVec3 viewNormal = mul(g_consts.m_viewMat, Vec4(worldNormal, 0.0)); const RVec3 directionVec = RVec3(dir2d, 0.0f); const RVec3 orthoDirectionVec = directionVec - (dot(directionVec, V) * V); @@ -100,13 +101,13 @@ RVec4 main(VertOut input) : SV_TARGET0 const RF32 n = -signNorm * fastAcos(cosNorm); // Find the projected radius - const Vec3 sphereLimit = Pc + Vec3(g_unis.m_radius, 0.0, 0.0); + const Vec3 sphereLimit = Pc + Vec3(g_consts.m_radius, 0.0, 0.0); const Vec4 projSphereLimit = project(Vec4(sphereLimit, 1.0)); const Vec2 projSphereLimit2 = projSphereLimit.xy / projSphereLimit.w; const RF32 projRadius = length(projSphereLimit2 - ndc); // Compute the inner integral (Slide 54) - const U32 stepCount = max(1u, g_unis.m_sampleCount / 2u); + const U32 stepCount = max(1u, g_consts.m_sampleCount / 2u); const RF32 lowHorizonCos1 = cos(n - kPi / 2.0f); const RF32 lowHorizonCos2 = cos(n + kPi / 2.0f); @@ -146,7 +147,7 @@ RVec4 main(VertOut input) : SV_TARGET0 Vd *= projectedNormalVecLength; // Apply power - Vd = pow(Vd, g_unis.m_ssaoPower); + Vd = pow(Vd, g_consts.m_ssaoPower); // Compute bent normal: see "Algorithm 2 Extension that computes bent normals b." const RF32 t0 = @@ -180,7 +181,7 @@ Texture2D g_depthTex : register(t1); RWTexture2D g_bentNormalsAndSsaoStorageTex : register(u0); # endif -ANKI_PUSH_CONSTANTS(SsaoSpatialDenoiseUniforms, g_unis) +ANKI_FAST_CONSTANTS(SsaoSpatialDenoiseConstants, g_consts) F32 computeWeight(F32 depth, F32 refDepth) { @@ -190,8 +191,8 @@ F32 computeWeight(F32 depth, F32 refDepth) void sampleTex(Vec2 uv, IVec2 offset, F32 refDepth, inout RF32 ssao, inout RVec3 bentNormal, inout F32 weight) { - const F32 linearDepth = linearizeDepthOptimal(g_depthTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0, offset).x, g_unis.m_linearizeDepthParams.x, - g_unis.m_linearizeDepthParams.y); + const F32 linearDepth = linearizeDepthOptimal(g_depthTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0, offset).x, + g_consts.m_linearizeDepthParams.x, g_consts.m_linearizeDepthParams.y); const RVec4 bentNormalAndSsao = g_bentNormalsAndSsaoTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0, offset); const F32 w = computeWeight(refDepth, linearDepth); ssao += bentNormalAndSsao.w * w; @@ -219,8 +220,8 @@ RVec4 main(VertOut input) : SV_TARGET0 const RVec4 refBentNormalAndSsao = g_bentNormalsAndSsaoTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0); RF32 ssao = refBentNormalAndSsao.w; RVec3 bentNormal = refBentNormalAndSsao.xyz; - const F32 refDepth = linearizeDepthOptimal(g_depthTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0).x, g_unis.m_linearizeDepthParams.x, - g_unis.m_linearizeDepthParams.y); + const F32 refDepth = linearizeDepthOptimal(g_depthTex.SampleLevel(g_linearAnyClampSampler, uv, 0.0).x, g_consts.m_linearizeDepthParams.x, + g_consts.m_linearizeDepthParams.y); F32 weight = computeWeight(0.0f, 0.0f); // Highest weight that this function can give // Sample taps @@ -249,7 +250,7 @@ RVec4 main(VertOut input) : SV_TARGET0 bentNormal /= weight; bentNormal = normalize(bentNormal); - bentNormal = mul(g_unis.m_viewToWorldMat, Vec4(bentNormal, 0.0f)); + bentNormal = mul(g_consts.m_viewToWorldMat, Vec4(bentNormal, 0.0f)); // Write value # if ANKI_COMPUTE_SHADER diff --git a/AnKi/Shaders/Ssr.ankiprog b/AnKi/Shaders/Ssr.ankiprog index 1406d933f..65dad2d2e 100644 --- a/AnKi/Shaders/Ssr.ankiprog +++ b/AnKi/Shaders/Ssr.ankiprog @@ -20,7 +20,7 @@ # define EXTRA_REJECTION 1 -ConstantBuffer g_unis : register(b0); +ConstantBuffer g_consts : register(b0); SamplerState g_trilinearClampSampler : register(s0); Texture2D g_gbufferRt1 : register(t0); @@ -39,7 +39,7 @@ RVec4 main(VertOut input) : SV_TARGET0 # endif { # if ANKI_COMPUTE_SHADER - const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5f) / g_unis.m_viewportSizef; + const Vec2 uv = (Vec2(svDispatchThreadId) + 0.5f) / g_consts.m_viewportSizef; # else const UVec2 svDispatchThreadId = UVec2(input.m_svPosition.xy); const Vec2 uv = input.m_uv; @@ -53,18 +53,18 @@ RVec4 main(VertOut input) : SV_TARGET0 const F32 depth = g_depthRt.SampleLevel(g_trilinearClampSampler, uv, 0.0).r; // Rand idx - const RVec2 noise2 = spatioTemporalNoise(svDispatchThreadId, g_unis.m_frameCount); + const RVec2 noise2 = spatioTemporalNoise(svDispatchThreadId, g_consts.m_frameCount); // Get view pos - const Vec3 viewPos = cheapPerspectiveUnprojection(g_unis.m_unprojectionParameters, uvToNdc(uv), depth); + const Vec3 viewPos = cheapPerspectiveUnprojection(g_consts.m_unprojectionParameters, uvToNdc(uv), depth); // Compute refl vector const Vec3 viewDir = -normalize(viewPos); - const Vec3 viewNormal = mul(g_unis.m_normalMat, Vec4(worldNormal, 0.0)); + const Vec3 viewNormal = mul(g_consts.m_normalMat, Vec4(worldNormal, 0.0)); const Vec3 reflDir = reflect(-viewDir, viewNormal); // Is rough enough to deserve SSR? - RF32 ssrAttenuation = saturate(1.0f - pow(roughness / g_unis.m_roughnessCutoff, 16.0f)); + RF32 ssrAttenuation = saturate(1.0f - pow(roughness / g_consts.m_roughnessCutoff, 16.0f)); // Do the heavy work Vec3 hitPoint; @@ -72,19 +72,19 @@ RVec4 main(VertOut input) : SV_TARGET0 if(ssrAttenuation > kEpsilonF32) { const U32 lod = 8u; // Use the max LOD for ray marching - const U32 stepIncrement = g_unis.m_stepIncrement; + const U32 stepIncrement = g_consts.m_stepIncrement; const F32 stepIncrementf = F32(stepIncrement); const F32 minStepf = min(4.0f, stepIncrementf); const U32 initialStepIncrement = U32(lerp(minStepf, stepIncrementf, noise2.x)); RF32 hitAttenuation; - raymarchGroundTruth(viewPos, reflDir, uv, depth, g_unis.m_projMat00_11_22_23, g_unis.m_maxIterations, g_depthRt, g_trilinearClampSampler, + raymarchGroundTruth(viewPos, reflDir, uv, depth, g_consts.m_projMat00_11_22_23, g_consts.m_maxIterations, g_depthRt, g_trilinearClampSampler, F32(lod), stepIncrement, initialStepIncrement, hitPoint, hitAttenuation); ssrAttenuation *= hitAttenuation; // Compute the hit point in viewspace const F32 depth = g_depthRt.SampleLevel(g_trilinearClampSampler, hitPoint.xy, 0.0).r; - hitPointViewSpace = cheapPerspectiveUnprojection(g_unis.m_unprojectionParameters, uvToNdc(hitPoint.xy), depth); + hitPointViewSpace = cheapPerspectiveUnprojection(g_consts.m_unprojectionParameters, uvToNdc(hitPoint.xy), depth); } else { @@ -96,7 +96,7 @@ RVec4 main(VertOut input) : SV_TARGET0 [branch] if(ssrAttenuation > 0.0) { const Vec3 gbufferNormal = unpackNormalFromGBuffer(g_gbufferRt2.SampleLevel(g_trilinearClampSampler, hitPoint.xy, 0.0)); - const Vec3 hitNormal = mul(g_unis.m_normalMat, Vec4(gbufferNormal, 0.0)); + const Vec3 hitNormal = mul(g_consts.m_normalMat, Vec4(gbufferNormal, 0.0)); RF32 backFaceAttenuation; rejectBackFaces(reflDir, hitNormal, backFaceAttenuation); @@ -106,7 +106,7 @@ RVec4 main(VertOut input) : SV_TARGET0 // Reject far from hit point [branch] if(ssrAttenuation > 0.0) { - const Vec3 reflRayHitPointVSpace = cheapPerspectiveUnprojection(g_unis.m_unprojectionParameters, uvToNdc(hitPoint.xy), hitPoint.z); + const Vec3 reflRayHitPointVSpace = cheapPerspectiveUnprojection(g_consts.m_unprojectionParameters, uvToNdc(hitPoint.xy), hitPoint.z); const RF32 rejectionMeters = 0.5f; const RF32 diff = length(reflRayHitPointVSpace - hitPointViewSpace); @@ -127,12 +127,12 @@ RVec4 main(VertOut input) : SV_TARGET0 const RF32 coneAngle = pow(roughness - kMinRoughness, 4.0) * kPi / 4.0f; // Not physically correct const RF32 oppositeLen = tan(coneAngle / 2.0f) * adjacentLen; const Vec3 projectedOpposite = - cheapPerspectiveProjection(g_unis.m_projMat00_11_22_23, Vec4(hitPointViewSpace + Vec3(oppositeLen, 0.0f, 0.0f), 1.0f)); + cheapPerspectiveProjection(g_consts.m_projMat00_11_22_23, Vec4(hitPointViewSpace + Vec3(oppositeLen, 0.0f, 0.0f), 1.0f)); const F32 uvDistance = abs(ndcToUv(projectedOpposite.x) - hitPoint.x); const RF32 mip = max(0.0f, log2(uvDistance * lightShadingTexSize.x + kEpsilonF32)); // Reproject the hit point because you are reading the previous frame - const Vec4 v4 = mul(g_unis.m_prevViewProjMatMulInvViewProjMat, Vec4(uvToNdc(hitPoint.xy), hitPoint.z, 1.0)); + const Vec4 v4 = mul(g_consts.m_prevViewProjMatMulInvViewProjMat, Vec4(uvToNdc(hitPoint.xy), hitPoint.z, 1.0)); hitPoint.xy = ndcToUv(v4.xy / v4.w); // Read the light buffer diff --git a/AnKi/Shaders/Tonemap.ankiprog b/AnKi/Shaders/Tonemap.ankiprog index 63594b259..53f23857c 100644 --- a/AnKi/Shaders/Tonemap.ankiprog +++ b/AnKi/Shaders/Tonemap.ankiprog @@ -21,13 +21,13 @@ RWTexture2D g_storageTex : register(u1); # define THREADGROUP_SIZE_SQRT 8 # endif -struct Uniforms +struct Constants { Vec2 m_viewportSizeOverOne; UVec2 m_viewportSize; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) # if ANKI_COMPUTE_SHADER [numthreads(THREADGROUP_SIZE_SQRT, THREADGROUP_SIZE_SQRT, 1)] void main(UVec3 svDispatchThreadId : SV_DISPATCHTHREADID) @@ -36,12 +36,12 @@ RVec3 main(VertOut input) : SV_TARGET0 # endif { # if ANKI_COMPUTE_SHADER - if(skipOutOfBoundsInvocations(UVec2(THREADGROUP_SIZE_SQRT, THREADGROUP_SIZE_SQRT), g_unis.m_viewportSize, svDispatchThreadId.xy)) + if(skipOutOfBoundsInvocations(UVec2(THREADGROUP_SIZE_SQRT, THREADGROUP_SIZE_SQRT), g_consts.m_viewportSize, svDispatchThreadId.xy)) { return; } - const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5f) * g_unis.m_viewportSizeOverOne; + const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5f) * g_consts.m_viewportSizeOverOne; # else const Vec2 uv = input.m_uv; # endif diff --git a/AnKi/Shaders/TraditionalDeferredShading.ankiprog b/AnKi/Shaders/TraditionalDeferredShading.ankiprog index 376e06584..70dcac881 100644 --- a/AnKi/Shaders/TraditionalDeferredShading.ankiprog +++ b/AnKi/Shaders/TraditionalDeferredShading.ankiprog @@ -20,7 +20,7 @@ #include #include -ConstantBuffer g_unis : register(b0); +ConstantBuffer g_consts : register(b0); StructuredBuffer g_visibleLightIds : register(t0); StructuredBuffer g_lights : register(t1); @@ -35,7 +35,7 @@ Texture2D g_depthTex : register(t5); SamplerComparisonState g_shadowMapSampler : register(s1); Texture2D g_shadowMap : register(t6); -ConstantBuffer g_globalRendererConsts : register(b1); +ConstantBuffer g_globalRendererConsts : register(b1); RVec3 main(VertOut input) : SV_TARGET0 { @@ -52,26 +52,26 @@ RVec3 main(VertOut input) : SV_TARGET0 g_gbufferTex2.SampleLevel(g_gbufferSampler, uv, 0.0), gbuffer); gbuffer.m_subsurface = max(gbuffer.m_subsurface, kSubsurfaceMin * 8.0); - const Vec4 worldPos4 = mul(g_unis.m_invViewProjMat, Vec4(uvToNdc(uv), depth, 1.0)); + const Vec4 worldPos4 = mul(g_consts.m_invViewProjMat, Vec4(uvToNdc(uv), depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; // Compute diff const Vec3 diffC = diffuseLobe(gbuffer.m_diffuse); Vec3 outColor = gbuffer.m_emission; - const Vec3 viewDir = normalize(g_unis.m_cameraPos - worldPos); + const Vec3 viewDir = normalize(g_consts.m_cameraPos - worldPos); ANKI_MAYBE_UNUSED(viewDir); // Dir light if(g_globalRendererConsts.m_directionalLight.m_shadowCascadeCount_31bit_active_1bit & 1u) { - const F32 dist = length(g_unis.m_cameraPos - worldPos); + const F32 dist = length(g_consts.m_cameraPos - worldPos); RF32 shadowFactor; - if(dist < g_unis.m_dirLight.m_effectiveShadowDistance) + if(dist < g_consts.m_dirLight.m_effectiveShadowDistance) { // Acceptable distance - shadowFactor = computeShadowFactorDirLight(g_unis.m_dirLight.m_lightMatrix, worldPos, g_shadowMap, g_shadowMapSampler); + shadowFactor = computeShadowFactorDirLight(g_consts.m_dirLight.m_lightMatrix, worldPos, g_shadowMap, g_shadowMapSampler); } else { diff --git a/AnKi/Shaders/TraditionalDeferredShadingSkybox.ankiprog b/AnKi/Shaders/TraditionalDeferredShadingSkybox.ankiprog index b256d8874..1ac97af5b 100644 --- a/AnKi/Shaders/TraditionalDeferredShadingSkybox.ankiprog +++ b/AnKi/Shaders/TraditionalDeferredShadingSkybox.ankiprog @@ -18,7 +18,7 @@ #include #include -ANKI_PUSH_CONSTANTS(TraditionalDeferredSkyboxUniforms, g_unis) +ANKI_FAST_CONSTANTS(TraditionalDeferredSkyboxConstants, g_consts) SamplerState g_nearestAnyClampSampler : register(s0); Texture2D g_depthTex : register(t0); @@ -31,7 +31,7 @@ SamplerState g_linearAnyClampSampler : register(s1); Texture2D g_skyLut : register(t1); #endif -ConstantBuffer g_globalRendererConsts : register(b0); +ConstantBuffer g_globalRendererConsts : register(b0); RVec3 main(VertOut input) : SV_TARGET0 { @@ -44,23 +44,23 @@ RVec3 main(VertOut input) : SV_TARGET0 #if METHOD == 0 ANKI_MAYBE_UNUSED(uv); - return g_unis.m_solidColor; + return g_consts.m_solidColor; #elif METHOD == 1 const F32 depthFar = 1.0; const Vec2 ndc = uvToNdc(uv); - const Vec4 worldPos4 = mul(g_unis.m_invertedViewProjectionMat, Vec4(ndc, depthFar, 1.0)); + const Vec4 worldPos4 = mul(g_consts.m_invertedViewProjectionMat, Vec4(ndc, depthFar, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; - const Vec3 eyeToFrag = normalize(worldPos - g_unis.m_cameraPos); + const Vec3 eyeToFrag = normalize(worldPos - g_consts.m_cameraPos); const Vec2 uv2 = equirectangularMapping(eyeToFrag); - return g_envMapTex.Sample(g_trilinearAnySampler, uv2).rgb * g_unis.m_scale + g_unis.m_bias; + return g_envMapTex.Sample(g_trilinearAnySampler, uv2).rgb * g_consts.m_scale + g_consts.m_bias; #else const Vec2 ndc = uvToNdc(uv); - const Vec4 worldPos4 = mul(g_unis.m_invertedViewProjectionMat, Vec4(ndc, depth, 1.0)); + const Vec4 worldPos4 = mul(g_consts.m_invertedViewProjectionMat, Vec4(ndc, depth, 1.0)); const Vec3 worldPos = worldPos4.xyz / worldPos4.w; - const Vec3 eyeToFrag = normalize(worldPos - g_unis.m_cameraPos); + const Vec3 eyeToFrag = normalize(worldPos - g_consts.m_cameraPos); const F32 sunPower = computeLuminance(g_globalRendererConsts.m_directionalLight.m_diffuseColor); diff --git a/AnKi/Shaders/Ui.ankiprog b/AnKi/Shaders/Ui.ankiprog index 47620db93..53267a427 100644 --- a/AnKi/Shaders/Ui.ankiprog +++ b/AnKi/Shaders/Ui.ankiprog @@ -27,11 +27,11 @@ struct VertOut #pragma anki technique_start vert -struct Uniforms +struct Constants { Vec4 m_transform; // x: x scale, y: y scale, z: x transl, w: y transl }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) VertOut main(VertIn input) { @@ -42,7 +42,7 @@ VertOut main(VertIn input) #endif output.m_color = input.m_color; - const Vec2 pos = g_unis.m_transform.xy * input.m_position + g_unis.m_transform.zw; + const Vec2 pos = g_consts.m_transform.xy * input.m_position + g_consts.m_transform.zw; output.m_svPosition = Vec4(pos, 0.0, 1.0); return output; diff --git a/AnKi/Shaders/UiVisualizeImage.ankiprog b/AnKi/Shaders/UiVisualizeImage.ankiprog index 54c8905e4..2a287cfad 100644 --- a/AnKi/Shaders/UiVisualizeImage.ankiprog +++ b/AnKi/Shaders/UiVisualizeImage.ankiprog @@ -7,14 +7,14 @@ #include -struct Uniforms +struct Constants { Vec4 m_transform; // x: x scale, y: y scale, z: x transl, w: y transl Vec4 m_colorScale; Vec4 m_depth; // Used in 3D textures. }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) struct VertIn { @@ -39,7 +39,7 @@ VertOut main(VertIn input) output.m_uv = input.m_uv; output.m_color = input.m_color; - const Vec2 pos = g_unis.m_transform.xy * input.m_position + g_unis.m_transform.zw; + const Vec2 pos = g_consts.m_transform.xy * input.m_position + g_consts.m_transform.zw; output.m_svPosition = Vec4(pos, 0.0, 1.0); return output; @@ -60,11 +60,11 @@ RVec4 main(VertOut input) : SV_TARGET0 #if TEXTURE_TYPE == 0 const RVec4 rgba = g_tex2d.Sample(g_trilinearRepeatSampler, input.m_uv); #else - const RVec4 rgba = g_tex3d.Sample(g_trilinearRepeatSampler, Vec3(input.m_uv, g_unis.m_depth.x)); + const RVec4 rgba = g_tex3d.Sample(g_trilinearRepeatSampler, Vec3(input.m_uv, g_consts.m_depth.x)); #endif - RVec3 outColor = input.m_color.rgb * rgba.rgb * g_unis.m_colorScale.rgb; + RVec3 outColor = input.m_color.rgb * rgba.rgb * g_consts.m_colorScale.rgb; - if(g_unis.m_colorScale.a == 1.0) + if(g_consts.m_colorScale.a == 1.0) { // Draw a pattern to visualize alpha F32 alphaPattern = ((U32(input.m_svPosition.x) / 16u) & 1u) == 1u ? 1.0 : 0.75; diff --git a/AnKi/Shaders/VolumetricFogAccumulation.ankiprog b/AnKi/Shaders/VolumetricFogAccumulation.ankiprog index d596ae2d6..ecfe100a4 100644 --- a/AnKi/Shaders/VolumetricFogAccumulation.ankiprog +++ b/AnKi/Shaders/VolumetricFogAccumulation.ankiprog @@ -12,43 +12,43 @@ SamplerState g_linearAnyClampSampler : register(s0); Texture3D g_lightVolume : register(t0); RWTexture3D g_fogVolume : register(u0); -ANKI_PUSH_CONSTANTS(VolumetricFogUniforms, g_unis) +ANKI_FAST_CONSTANTS(VolumetricFogConstants, g_consts) [numthreads(8, 8, 1)] void main(UVec3 svDispatchThreadId : SV_DISPATCHTHREADID) { - if(any(svDispatchThreadId.xy >= g_unis.m_volumeSize.xy)) + if(any(svDispatchThreadId.xy >= g_consts.m_volumeSize.xy)) { return; } - const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5) / Vec2(g_unis.m_volumeSize.xy); + const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5) / Vec2(g_consts.m_volumeSize.xy); RVec4 colorAndDensityFront = 0.0; - [loop] for(U32 i = 0u; i < g_unis.m_volumeSize.z; ++i) + [loop] for(U32 i = 0u; i < g_consts.m_volumeSize.z; ++i) { const RF32 fi = F32(i); // Compute the linear depth - const RF32 maxLinearDepth = g_unis.m_maxZSplitsToProcessf / g_unis.m_zSplitCountf; - const RF32 linearDepthFraction = maxLinearDepth / F32(g_unis.m_volumeSize.z); + const RF32 maxLinearDepth = g_consts.m_maxZSplitsToProcessf / g_consts.m_zSplitCountf; + const RF32 linearDepthFraction = maxLinearDepth / F32(g_consts.m_volumeSize.z); const RF32 linearDepthNear = fi * linearDepthFraction; const RF32 linearDepthFar = (fi + 1.0) * linearDepthFraction; // Compute the min and max Z in view space if this cluster fragment - const RF32 zVSpaceNear = -linearDepthNear * (g_unis.m_far - g_unis.m_near) + g_unis.m_near; - const RF32 zVSpaceFar = -linearDepthFar * (g_unis.m_far - g_unis.m_near) + g_unis.m_near; + const RF32 zVSpaceNear = -linearDepthNear * (g_consts.m_far - g_consts.m_near) + g_consts.m_near; + const RF32 zVSpaceFar = -linearDepthFar * (g_consts.m_far - g_consts.m_near) + g_consts.m_near; // Compute the thikness of this fragment const RF32 layerThinkness = abs(zVSpaceNear - zVSpaceFar); // Read the light value and the fog density from the fog volumes - const RF32 w = (fi + 0.5) / F32(g_unis.m_volumeSize.z); + const RF32 w = (fi + 0.5) / F32(g_consts.m_volumeSize.z); RVec4 lightAndFogDensity = g_lightVolume.SampleLevel(g_linearAnyClampSampler, Vec3(uv, w), 0.0); - lightAndFogDensity.xyz *= g_unis.m_fogDiffuse / kPi; + lightAndFogDensity.xyz *= g_consts.m_fogDiffuse / kPi; // Scattering & absorption - const RF32 scattering = lightAndFogDensity.w * g_unis.m_fogScatteringCoeff * layerThinkness; - const RF32 absorption = lightAndFogDensity.w * g_unis.m_fogAbsorptionCoeff * layerThinkness; + const RF32 scattering = lightAndFogDensity.w * g_consts.m_fogScatteringCoeff * layerThinkness; + const RF32 absorption = lightAndFogDensity.w * g_consts.m_fogAbsorptionCoeff * layerThinkness; // Integrate const RVec4 colorAndDensityBack = Vec4(lightAndFogDensity.xyz * scattering, scattering + absorption); diff --git a/AnKi/Shaders/VolumetricLightingAccumulation.ankiprog b/AnKi/Shaders/VolumetricLightingAccumulation.ankiprog index 00ab1f1a1..4c6708b0f 100644 --- a/AnKi/Shaders/VolumetricLightingAccumulation.ankiprog +++ b/AnKi/Shaders/VolumetricLightingAccumulation.ankiprog @@ -22,7 +22,7 @@ RWTexture3D g_volume : register(u0); Texture2D g_noiseTex : register(t0); Texture3D g_prevVolume : register(t1); -ConstantBuffer g_globalUniforms : register(b0); +ConstantBuffer g_globalConstants : register(b0); StructuredBuffer g_pointLights : register(t2); StructuredBuffer g_spotLights : register(t3); Texture2D g_shadowAtlasTex : register(t4); @@ -30,14 +30,14 @@ StructuredBuffer g_giProbes : register(t5); StructuredBuffer g_fogDensityVolumes : register(t6); StructuredBuffer g_clusters : register(t7); -ANKI_PUSH_CONSTANTS(VolumetricLightingUniforms, g_fogUnis) +ANKI_FAST_CONSTANTS(VolumetricLightingConstants, g_fogUnis) static Vec3 g_svDispatchThreadId; Vec3 readRand() { Vec3 random = g_noiseTex.SampleLevel(g_linearAnyRepeatSampler, (g_svDispatchThreadId.xy + 0.5) / 64.0, 0.0).rgb; - random = animateBlueNoise(random, g_globalUniforms.m_frame); + random = animateBlueNoise(random, g_globalConstants.m_frame); return random; } @@ -45,7 +45,7 @@ Vec3 readRand() Vec3 worldPosInsideClusterAndZViewSpace(Vec3 relativePos, out F32 negativeZViewSpace, out Vec3 uvw) { // Compute the linear depth - const F32 maxLinearDepth = g_fogUnis.m_maxZSplitsToProcessf / F32(g_globalUniforms.m_zSplitCount); + const F32 maxLinearDepth = g_fogUnis.m_maxZSplitsToProcessf / F32(g_globalConstants.m_zSplitCount); const F32 linearDepthFraction = maxLinearDepth / F32(g_fogUnis.m_volumeSize.z); const F32 linearDepthNear = g_svDispatchThreadId.z * linearDepthFraction; const F32 linearDepthFar = (g_svDispatchThreadId.z + 1.0) * linearDepthFraction; @@ -53,16 +53,16 @@ Vec3 worldPosInsideClusterAndZViewSpace(Vec3 relativePos, out F32 negativeZViewS uvw.z = linearDepth; // Z view space - negativeZViewSpace = linearDepth * (g_globalUniforms.m_far - g_globalUniforms.m_near) + g_globalUniforms.m_near; + negativeZViewSpace = linearDepth * (g_globalConstants.m_far - g_globalConstants.m_near) + g_globalConstants.m_near; const F32 zViewSpace = -negativeZViewSpace; // Get the position in view space const Vec2 uv = lerp(g_svDispatchThreadId.xy, g_svDispatchThreadId.xy + 1.0, relativePos.xy) / Vec2(g_fogUnis.m_volumeSize.xy); uvw.xy = uv; - const Vec2 xyViewSpace = uvToNdc(uv) * g_globalUniforms.m_matrices.m_unprojectionParameters.xy * zViewSpace; + const Vec2 xyViewSpace = uvToNdc(uv) * g_globalConstants.m_matrices.m_unprojectionParameters.xy * zViewSpace; // Get the final world pos - const Vec3 worldPos = mul(g_globalUniforms.m_matrices.m_cameraTransform, Vec4(xyViewSpace, zViewSpace, 1.0)); + const Vec3 worldPos = mul(g_globalConstants.m_matrices.m_cameraTransform, Vec4(xyViewSpace, zViewSpace, 1.0)); return worldPos; } @@ -92,10 +92,10 @@ Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpa ANKI_MAYBE_UNUSED(negativeZViewSpace); Vec3 color = 0.0; - const Vec3 viewDir = normalize(g_globalUniforms.m_cameraPosition - worldPos); + const Vec3 viewDir = normalize(g_globalConstants.m_cameraPosition - worldPos); // Dir light - const DirectionalLight dirLight = g_globalUniforms.m_directionalLight; + const DirectionalLight dirLight = g_globalConstants.m_directionalLight; if(dirLight.m_shadowCascadeCount_31bit_active_1bit & 1u) { F32 factor = phaseFunction(viewDir, dirLight.m_direction, kPhaseFunctionAnisotropy); @@ -255,12 +255,12 @@ Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpa const Vec3 worldPos = worldPosInsideClusterAndZViewSpace(readRand(), negativeZViewSpace, uvw); // Get the cluster - const UVec2 tileIdxXY = UVec2(uvw.xy * Vec2(g_globalUniforms.m_tileCounts)); - const U32 tileIdx = tileIdxXY.y * g_globalUniforms.m_tileCounts.x + tileIdxXY.x; + const UVec2 tileIdxXY = UVec2(uvw.xy * Vec2(g_globalConstants.m_tileCounts)); + const U32 tileIdx = tileIdxXY.y * g_globalConstants.m_tileCounts.x + tileIdxXY.x; Cluster cluster = g_clusters[tileIdx]; - const U32 zSplitIdx = U32(uvw.z * F32(g_globalUniforms.m_zSplitCount)); - const Cluster split = g_clusters[g_globalUniforms.m_tileCounts.x * g_globalUniforms.m_tileCounts.y + zSplitIdx]; + const U32 zSplitIdx = U32(uvw.z * F32(g_globalConstants.m_zSplitCount)); + const Cluster split = g_clusters[g_globalConstants.m_tileCounts.x * g_globalConstants.m_tileCounts.y + zSplitIdx]; cluster = mergeClusters(cluster, split); @@ -273,14 +273,14 @@ Vec4 accumulateLightsAndFog(Cluster cluster, Vec3 worldPos, F32 negativeZViewSpa const Vec3 midWPos = worldPosInsideCluster(Vec3(0.5, 0.5, 0.5)); // Project - const Vec4 prevClipPos4 = mul(g_globalUniforms.m_previousMatrices.m_viewProjection, Vec4(midWPos, 1.0)); + const Vec4 prevClipPos4 = mul(g_globalConstants.m_previousMatrices.m_viewProjection, Vec4(midWPos, 1.0)); const Vec3 prevClipPos = prevClipPos4.xyz / prevClipPos4.w; // Read prev if(all(prevClipPos.xy > -1.0) && all(prevClipPos.xy < 1.0)) { - const F32 linearDepth = linearizeDepth(prevClipPos.z, g_globalUniforms.m_near, g_globalUniforms.m_far); - const Vec3 uvw = Vec3(ndcToUv(prevClipPos.xy), linearDepth * (F32(g_globalUniforms.m_zSplitCount) / g_fogUnis.m_maxZSplitsToProcessf)); + const F32 linearDepth = linearizeDepth(prevClipPos.z, g_globalConstants.m_near, g_globalConstants.m_far); + const Vec3 uvw = Vec3(ndcToUv(prevClipPos.xy), linearDepth * (F32(g_globalConstants.m_zSplitCount) / g_fogUnis.m_maxZSplitsToProcessf)); const Vec4 history = g_prevVolume.SampleLevel(g_linearAnyClampSampler, uvw, 0.0); lightAndFog = lerp(history, lightAndFog, 1.0 / 16.0); } diff --git a/AnKi/Shaders/VrsSriDownscale.ankiprog b/AnKi/Shaders/VrsSriDownscale.ankiprog index 1781e1771..52904e75d 100644 --- a/AnKi/Shaders/VrsSriDownscale.ankiprog +++ b/AnKi/Shaders/VrsSriDownscale.ankiprog @@ -11,17 +11,17 @@ Texture2D g_inputTex : register(t0); SamplerState g_nearestAnyClampSampler : register(s0); RWTexture2D g_storageTex : register(u0); -struct Uniforms +struct Constants { Vec2 m_oneOverViewportSize; F32 m_padding0; F32 m_padding1; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) [numthreads(8, 8, 1)] void main(UVec3 svDispatchThreadId : SV_DISPATCHTHREADID) { - const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5) * g_unis.m_oneOverViewportSize; + const Vec2 uv = (Vec2(svDispatchThreadId.xy) + 0.5) * g_consts.m_oneOverViewportSize; const UVec4 rates = g_inputTex.GatherRed(g_nearestAnyClampSampler, uv); diff --git a/AnKi/Shaders/VrsSriGenerationCompute.ankiprog b/AnKi/Shaders/VrsSriGenerationCompute.ankiprog index b8019f089..3dba23811 100644 --- a/AnKi/Shaders/VrsSriGenerationCompute.ankiprog +++ b/AnKi/Shaders/VrsSriGenerationCompute.ankiprog @@ -31,14 +31,14 @@ SamplerState g_nearestClampSampler : register(s0); RWTexture2D g_sriStorageTex : register(u0); -struct Uniforms +struct Constants { Vec2 m_oneOverViewportSize; F32 m_threshold; F32 m_padding0; }; -ANKI_PUSH_CONSTANTS(Uniforms, g_unis) +ANKI_FAST_CONSTANTS(Constants, g_consts) #if SHARED_MEMORY // Ideally, we'd be able to calculate the min/max/average using subgroup operations, but there's no guarantee @@ -67,7 +67,7 @@ RF32 computeLuma(RVec3 color) ANKI_COMPUTE_WAVE_INDEX_INSIDE_THREADGROUP(svGroupIndex, s_waveIndexInsideThreadGroup, waveIndexInsideThreadGroup, wavesPerThreadGroup); #endif - const Vec2 uv = (Vec2(svDispatchThreadId.xy) * Vec2(REGION_SIZE_X, REGION_SIZE_Y) + 0.5) * g_unis.m_oneOverViewportSize; + const Vec2 uv = (Vec2(svDispatchThreadId.xy) * Vec2(REGION_SIZE_X, REGION_SIZE_Y) + 0.5) * g_consts.m_oneOverViewportSize; #if SRI_TEXEL_DIMENSION == 8 // Get luminance. @@ -175,7 +175,7 @@ RF32 computeLuma(RVec3 color) // Determine shading rate. const RF32 avgLuma = averageLuma / RF32(THREADGROUP_SIZE_X * THREADGROUP_SIZE_Y); const RVec2 lumaDiff = maxDerivative / avgLuma; - const RF32 threshold1 = g_unis.m_threshold; + const RF32 threshold1 = g_consts.m_threshold; const RF32 threshold2 = threshold1 * 0.4; UVec2 rate; diff --git a/AnKi/Ui/Canvas.cpp b/AnKi/Ui/Canvas.cpp index 2e9c36c3c..7f518a5a8 100644 --- a/AnKi/Ui/Canvas.cpp +++ b/AnKi/Ui/Canvas.cpp @@ -297,21 +297,21 @@ void Canvas::appendToCommandBufferInternal(CommandBuffer& cmdb) { public: Vec4 m_transform; - Array m_extra; + Array m_extra; } pc; pc.m_transform.x() = 2.0f / drawData.DisplaySize.x; pc.m_transform.y() = -2.0f / drawData.DisplaySize.y; pc.m_transform.z() = (drawData.DisplayPos.x / drawData.DisplaySize.x) * 2.0f - 1.0f; pc.m_transform.w() = -((drawData.DisplayPos.y / drawData.DisplaySize.y) * 2.0f - 1.0f); - U32 extraPushConstantsSize = 0; - if(data && data->m_extraPushConstantsSize) + U32 extraFastConstantsSize = 0; + if(data && data->m_extraFastConstantsSize) { - ANKI_ASSERT(data->m_extraPushConstantsSize <= sizeof(data->m_extraPushConstants)); - memcpy(&pc.m_extra[0], data->m_extraPushConstants.getBegin(), data->m_extraPushConstantsSize); + ANKI_ASSERT(data->m_extraFastConstantsSize <= sizeof(data->m_extraFastConstants)); + memcpy(&pc.m_extra[0], data->m_extraFastConstants.getBegin(), data->m_extraFastConstantsSize); - extraPushConstantsSize = data->m_extraPushConstantsSize; + extraFastConstantsSize = data->m_extraFastConstantsSize; } - cmdb.setPushConstants(&pc, sizeof(Vec4) + extraPushConstantsSize); + cmdb.setFastConstants(&pc, sizeof(Vec4) + extraFastConstantsSize); // Draw cmdb.drawIndexed(PrimitiveTopology::kTriangles, pcmd.ElemCount, 1, idxOffset, vertOffset); diff --git a/AnKi/Ui/Common.h b/AnKi/Ui/Common.h index 1f2439a4e..639bd4870 100644 --- a/AnKi/Ui/Common.h +++ b/AnKi/Ui/Common.h @@ -73,16 +73,16 @@ class UiImageIdData public: TextureView m_textureView; ShaderProgramPtr m_customProgram; - U8 m_extraPushConstantsSize = 0; - Array m_extraPushConstants; + U8 m_extraFastConstantsSize = 0; + Array m_extraFastConstants; Bool m_pointSampling = false; - void setExtraPushConstants(const void* ptr, PtrSize pushConstantSize) + void setExtraFastConstants(const void* ptr, PtrSize fastConstantsSize) { ANKI_ASSERT(ptr); - ANKI_ASSERT(pushConstantSize > 0 && pushConstantSize < sizeof(m_extraPushConstants)); - m_extraPushConstantsSize = U8(pushConstantSize); - memcpy(m_extraPushConstants.getBegin(), ptr, pushConstantSize); + ANKI_ASSERT(fastConstantsSize > 0 && fastConstantsSize < sizeof(m_extraFastConstants)); + m_extraFastConstantsSize = U8(fastConstantsSize); + memcpy(m_extraFastConstants.getBegin(), ptr, fastConstantsSize); } }; diff --git a/Tests/Gr/Gr.cpp b/Tests/Gr/Gr.cpp index 106a1b867..1240f5951 100644 --- a/Tests/Gr/Gr.cpp +++ b/Tests/Gr/Gr.cpp @@ -223,11 +223,11 @@ struct Foo2 uint4 m_val; }; #if defined(__spirv__) -[[vk::push_constant]] ConstantBuffer g_pushConsts; +[[vk::push_constant]] ConstantBuffer g_consts; [[vk::binding(0, 1000000)]] Texture2D g_bindless[]; #else -ConstantBuffer g_pushConsts : register(b0, space3000); +ConstantBuffer g_consts : register(b0, space3000); #endif SamplerState g_sampler : register(s2); @@ -245,9 +245,9 @@ void main() g_rwtex[0][uint2(0, 0)] = g_consts.m_val; #if defined(__spirv__) - Texture2D tex = g_bindless[g_pushConsts.m_val.x]; + Texture2D tex = g_bindless[g_consts.m_val.x]; #else - Texture2D tex = ResourceDescriptorHeap[g_pushConsts.m_val.x]; + Texture2D tex = ResourceDescriptorHeap[g_consts.m_val.x]; #endif g_rwtex[1][uint2(0, 0)] = tex.SampleLevel(g_sampler, 0.0f, 0.0f); @@ -332,7 +332,7 @@ void main() cmdb->bindSampler(2, 0, sampler.get()); const UVec4 pc(bindlessIdx); - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); cmdb->dispatchCompute(1, 1, 1); cmdb->endRecording(); @@ -461,7 +461,7 @@ float4 main(float4 svPosition : SV_POSITION, float2 uv : TEXCOORDS, uint svPrimI cmdb->beginRenderPass({TextureView(presentTex.get(), TextureSubresourceDesc::firstSurface())}); const Vec4 viewport(0.0f, 0.0f, F32(NativeWindow::getSingleton().getWidth()), F32(NativeWindow::getSingleton().getHeight())); - cmdb->setPushConstants(&viewport, sizeof(viewport)); + cmdb->setFastConstants(&viewport, sizeof(viewport)); cmdb->bindSrv(0, 0, TextureView(tex.get(), TextureSubresourceDesc::all())); cmdb->bindSampler(0, 0, sampler.get()); @@ -740,9 +740,9 @@ struct A }; #if defined(__spirv__) -[[vk::push_constant]] ConstantBuffer g_pushConsts; +[[vk::push_constant]] ConstantBuffer g_consts; #else -ConstantBuffer g_pushConsts : register(b0, space3000); +ConstantBuffer g_consts : register(b0, space3000); #endif struct VertOut @@ -760,13 +760,13 @@ VertOut main(uint svVertexId : SV_VERTEXID) switch(svVertexId) { case 0: - color = g_pushConsts.m_color[0]; + color = g_consts.m_color[0]; break; case 1: - color = g_pushConsts.m_color[1]; + color = g_consts.m_color[1]; break; default: - color = g_pushConsts.m_color[2]; + color = g_consts.m_color[2]; }; o.m_color = color.xyz; @@ -774,7 +774,7 @@ VertOut main(uint svVertexId : SV_VERTEXID) const float2 kPositions[3] = {float2(-1.0, 1.0), float2(0.0, -1.0), float2(1.0, 1.0)}; float2x2 rot = float2x2( - g_pushConsts.m_rotation2d.x, g_pushConsts.m_rotation2d.y, g_pushConsts.m_rotation2d.z, g_pushConsts.m_rotation2d.w); + g_consts.m_rotation2d.x, g_consts.m_rotation2d.y, g_consts.m_rotation2d.z, g_consts.m_rotation2d.w); float2 pos = mul(rot, kPositions[svVertexId % 3]); o.m_svPosition = float4(pos, 0.0, 1.0); @@ -838,7 +838,7 @@ float4 main(VertOut i) : SV_TARGET0 pc.m_color[1] = Vec4(0.0, 1.0, 0.0, 0.0); pc.m_color[2] = Vec4(0.0, 0.0, 1.0, 0.0); - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); cmdb->draw(PrimitiveTopology::kTriangles, 3); cmdb->endRenderPass(); @@ -1149,7 +1149,7 @@ void main() cmdb->beginRenderPass(fb.get(), {TextureUsageBit::kRtvDsvWrite}, {}); Vec4 pc(F32(g_win->getWidth()), F32(g_win->getHeight()), 0.0f, 0.0f); - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); // cmdb->bindTextureAndSampler(0, 0, aView.get(), sampler.get()); // cmdb->bindTextureAndSampler(0, 1, bView.get(), sampler.get()); @@ -1997,7 +1997,7 @@ void main() Mat4 m_mat = Mat4(0.0f); } pc; pc.m_mat(0, 1) = 0.5f; - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); cmdb->bindStorageBuffer(0, 0, resultBuff.get(), 0, resultBuff->getSize()); TexturePtr presentTex = g_gr->acquireNextPresentableTexture(); @@ -2204,7 +2204,7 @@ void main() const U32 idx1 = viewB->getOrCreateBindlessTextureIndex(); const U32 idx2 = viewC->getOrCreateBindlessTextureIndex(); UVec4 pc(idx0, idx1, idx2, 0); - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); cmdb->bindAllBindless(0); @@ -2472,7 +2472,7 @@ void main() } pc; pc.m_vp = projMat * viewMat; pc.m_cameraPos = cameraPos; - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); if(useRayTracing) { @@ -3322,7 +3322,7 @@ void main() pc.m_lightCount = lightCount; pc.m_frame = i; - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); const U32 sbtRecordSize = g_gr->getDeviceCapabilities().m_sbtRecordAlignment; cmdb->traceRays(BufferView(sbt.get()), sbtRecordSize, U32(GeomWhat::kCount) * 2, 2, WIDTH, HEIGHT, 1); diff --git a/Tests/Gr/GrWorkGraphs.cpp b/Tests/Gr/GrWorkGraphs.cpp index 0f791be1c..f86b1fc0a 100644 --- a/Tests/Gr/GrWorkGraphs.cpp +++ b/Tests/Gr/GrWorkGraphs.cpp @@ -299,9 +299,9 @@ StructuredBuffer g_objects : register(t0); StructuredBuffer g_positions : register(t1); #if defined(__spirv__) -[[vk::push_constant]] ConstantBuffer g_pushConsts; +[[vk::push_constant]] ConstantBuffer g_consts; #else -ConstantBuffer g_pushConsts : register(b0, space3000); +ConstantBuffer g_consts : register(b0, space3000); #endif #define THREAD_COUNT 64u @@ -311,7 +311,7 @@ groupshared Aabb g_aabb; [NumThreads(THREAD_COUNT, 1, 1)] void main(uint svDispatchThreadId : SV_DispatchThreadId, uint svGroupIndex : SV_GroupIndex) { - const Object obj = g_objects[g_pushConsts.m_objectIndex]; + const Object obj = g_objects[g_consts.m_objectIndex]; svDispatchThreadId = min(svDispatchThreadId, obj.m_positionCount - 1); @@ -331,8 +331,8 @@ void main(uint svDispatchThreadId : SV_DispatchThreadId, uint svGroupIndex : SV_ Barrier(GROUP_SHARED_MEMORY, GROUP_SCOPE | GROUP_SYNC); - InterlockedMin(g_aabbs[g_pushConsts.m_objectIndex].m_min, g_aabb.m_min); - InterlockedMax(g_aabbs[g_pushConsts.m_objectIndex].m_max, g_aabb.m_max); + InterlockedMin(g_aabbs[g_consts.m_objectIndex].m_min, g_aabb.m_min); + InterlockedMax(g_aabbs[g_consts.m_objectIndex].m_max, g_aabb.m_max); } )"; @@ -463,7 +463,7 @@ void main(uint svDispatchThreadId : SV_DispatchThreadId, uint svGroupIndex : SV_ for(U32 iobj = 0; iobj < kObjectCount; ++iobj) { const UVec4 pc(iobj); - cmdb->setPushConstants(&pc, sizeof(pc)); + cmdb->setFastConstants(&pc, sizeof(pc)); cmdb->dispatchCompute((objects[iobj].m_positionCount + kThreadCount - 1) / kThreadCount, 1, 1); } diff --git a/Tools/Image/ImageViewerMain.cpp b/Tools/Image/ImageViewerMain.cpp index 7ea2cea7d..2fb296acf 100644 --- a/Tools/Image/ImageViewerMain.cpp +++ b/Tools/Image/ImageViewerMain.cpp @@ -205,8 +205,8 @@ class TextureViewerUiNode : public SceneNode pc.m_depth = Vec4((m_depth + 0.5f) / F32(grTex.getDepth())); m_imageIdExtra.m_customProgram = m_imageGrProgram; - m_imageIdExtra.m_extraPushConstantsSize = U8(sizeof(pc)); - m_imageIdExtra.setExtraPushConstants(&pc, sizeof(pc)); + m_imageIdExtra.m_extraFastConstantsSize = U8(sizeof(pc)); + m_imageIdExtra.setExtraFastConstants(&pc, sizeof(pc)); m_imageIdExtra.m_pointSampling = m_pointSampling; ImGui::Image(UiImageId(&m_imageIdExtra), imageSize, Vec2(0.0f, 1.0f), Vec2(1.0f, 0.0f), Vec4(1.0f), Vec4(0.0f, 0.0f, 0.0f, 1.0f));