Skip to content

Commit 61f2358

Browse files
Added SHADER_RESOURCE_TYPE_INLINE_CONSTANTS enum value (#672)
1 parent 1c3ac22 commit 61f2358

File tree

11 files changed

+66
-31
lines changed

11 files changed

+66
-31
lines changed

Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ const Char* GetShaderVariableTypeLiteralName(SHADER_RESOURCE_VARIABLE_TYPE VarTy
862862

863863
const Char* GetShaderResourceTypeLiteralName(SHADER_RESOURCE_TYPE ResourceType, bool bGetFullName)
864864
{
865-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource type");
865+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource type");
866866
switch (ResourceType)
867867
{
868868
// clang-format off
@@ -874,6 +874,7 @@ const Char* GetShaderResourceTypeLiteralName(SHADER_RESOURCE_TYPE ResourceType,
874874
case SHADER_RESOURCE_TYPE_BUFFER_UAV: return bGetFullName ? "SHADER_RESOURCE_TYPE_BUFFER_UAV" : "buffer UAV";
875875
case SHADER_RESOURCE_TYPE_SAMPLER: return bGetFullName ? "SHADER_RESOURCE_TYPE_SAMPLER" : "sampler";
876876
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: return bGetFullName ? "SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT" : "input attachment";
877+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS: return bGetFullName ? "SHADER_RESOURCE_TYPE_INLINE_CONSTANTS" : "inline constants";
877878
case SHADER_RESOURCE_TYPE_ACCEL_STRUCT: return bGetFullName ? "SHADER_RESOURCE_TYPE_ACCEL_STRUCT" : "acceleration structure";
878879
// clang-format on
879880
default:
@@ -1804,7 +1805,7 @@ String GetLayoutElementString(const LayoutElement& Element)
18041805

18051806
PIPELINE_RESOURCE_FLAGS GetValidPipelineResourceFlags(SHADER_RESOURCE_TYPE ResourceType)
18061807
{
1807-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource type");
1808+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource type");
18081809
switch (ResourceType)
18091810
{
18101811
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
@@ -1828,6 +1829,9 @@ PIPELINE_RESOURCE_FLAGS GetValidPipelineResourceFlags(SHADER_RESOURCE_TYPE Resou
18281829
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT:
18291830
return PIPELINE_RESOURCE_FLAG_GENERAL_INPUT_ATTACHMENT;
18301831

1832+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS:
1833+
return PIPELINE_RESOURCE_FLAG_NONE;
1834+
18311835
case SHADER_RESOURCE_TYPE_ACCEL_STRUCT:
18321836
return PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY;
18331837

Graphics/GraphicsEngine/interface/Shader.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,16 @@ DILIGENT_TYPED_ENUM(SHADER_RESOURCE_TYPE, Uint8)
723723
/// Input attachment in a render pass
724724
SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT,
725725

726+
/// Inline constants (aka push constants in Vulkan or root constants in Direct3D12)
727+
728+
/// In Vulkan/Direct3D12, inline constants are not bound via descriptor sets or root
729+
/// signatures but are set directly in command buffers / command lists. As such, they
730+
/// are very cheap to set and are intended for small pieces of frequently changing data.
731+
///
732+
/// In legacy APIs (Direct3D11/OpenGL), inline constants are emulated using regular
733+
/// constant buffers.
734+
SHADER_RESOURCE_TYPE_INLINE_CONSTANTS,
735+
726736
/// Acceleration structure
727737
SHADER_RESOURCE_TYPE_ACCEL_STRUCT,
728738

Graphics/GraphicsEngineD3D11/src/PipelineResourceSignatureD3D11Impl.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2024 Diligent Graphics LLC
2+
* Copyright 2019-2025 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -90,17 +90,18 @@ PipelineResourceSignatureD3D11Impl::PipelineResourceSignatureD3D11Impl(IReferenc
9090

9191
D3D11_RESOURCE_RANGE PipelineResourceSignatureD3D11Impl::ShaderResourceTypeToRange(SHADER_RESOURCE_TYPE Type)
9292
{
93-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource type");
93+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource type");
9494
switch (Type)
9595
{
9696
// clang-format off
97-
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER: return D3D11_RESOURCE_RANGE_CBV;
98-
case SHADER_RESOURCE_TYPE_TEXTURE_SRV: return D3D11_RESOURCE_RANGE_SRV;
99-
case SHADER_RESOURCE_TYPE_BUFFER_SRV: return D3D11_RESOURCE_RANGE_SRV;
100-
case SHADER_RESOURCE_TYPE_TEXTURE_UAV: return D3D11_RESOURCE_RANGE_UAV;
101-
case SHADER_RESOURCE_TYPE_BUFFER_UAV: return D3D11_RESOURCE_RANGE_UAV;
102-
case SHADER_RESOURCE_TYPE_SAMPLER: return D3D11_RESOURCE_RANGE_SAMPLER;
103-
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: return D3D11_RESOURCE_RANGE_SRV;
97+
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER: return D3D11_RESOURCE_RANGE_CBV;
98+
case SHADER_RESOURCE_TYPE_TEXTURE_SRV: return D3D11_RESOURCE_RANGE_SRV;
99+
case SHADER_RESOURCE_TYPE_BUFFER_SRV: return D3D11_RESOURCE_RANGE_SRV;
100+
case SHADER_RESOURCE_TYPE_TEXTURE_UAV: return D3D11_RESOURCE_RANGE_UAV;
101+
case SHADER_RESOURCE_TYPE_BUFFER_UAV: return D3D11_RESOURCE_RANGE_UAV;
102+
case SHADER_RESOURCE_TYPE_SAMPLER: return D3D11_RESOURCE_RANGE_SAMPLER;
103+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS: return D3D11_RESOURCE_RANGE_CBV;
104+
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: return D3D11_RESOURCE_RANGE_SRV;
104105
// clang-format on
105106
default:
106107
UNEXPECTED("Unsupported resource type");

Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ D3DShaderResourceCounters ShaderVariableManagerD3D11::CountResources(
121121
[&](Uint32 Index) //
122122
{
123123
const PipelineResourceDesc& ResDesc = Signature.GetResourceDesc(Index);
124-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource range");
124+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource range");
125125
switch (ResDesc.ResourceType)
126126
{
127127
// clang-format off
@@ -132,6 +132,7 @@ D3DShaderResourceCounters ShaderVariableManagerD3D11::CountResources(
132132
case SHADER_RESOURCE_TYPE_BUFFER_UAV: ++Counters.NumBufUAVs; break;
133133
case SHADER_RESOURCE_TYPE_SAMPLER: ++Counters.NumSamplers; break;
134134
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: ++Counters.NumTexSRVs; break;
135+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS: ++Counters.NumCBs; break;
135136
// clang-format on
136137
default:
137138
UNEXPECTED("Unsupported resource type.");
@@ -215,7 +216,7 @@ void ShaderVariableManagerD3D11::Initialize(const PipelineResourceSignatureD3D11
215216
[&](Uint32 Index) //
216217
{
217218
const PipelineResourceDesc& ResDesc = Signature.GetResourceDesc(Index);
218-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource range");
219+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource range");
219220
switch (ResDesc.ResourceType)
220221
{
221222
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
@@ -249,6 +250,11 @@ void ShaderVariableManagerD3D11::Initialize(const PipelineResourceSignatureD3D11
249250
new (&GetResource<SamplerBindInfo>(sam++)) SamplerBindInfo{*this, Index};
250251
break;
251252

253+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS:
254+
// Initialize CB for inline constants in place, increment CB counter
255+
new (&GetResource<ConstBuffBindInfo>(cb++)) ConstBuffBindInfo{*this, Index};
256+
break;
257+
252258
default:
253259
UNEXPECTED("Unsupported resource type.");
254260
}

Graphics/GraphicsEngineD3D12/src/D3D12TypeConversions.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -849,20 +849,25 @@ DXGI_FORMAT TypeToRayTracingVertexFormat(VALUE_TYPE ValueType, Uint32 ComponentC
849849

850850
D3D12_DESCRIPTOR_RANGE_TYPE ResourceTypeToD3D12DescriptorRangeType(SHADER_RESOURCE_TYPE ResType)
851851
{
852-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new resource type");
852+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new resource type");
853853

854854
switch (ResType)
855855
{
856-
// clang-format off
857-
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER: return D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
858-
case SHADER_RESOURCE_TYPE_TEXTURE_SRV: return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
859-
case SHADER_RESOURCE_TYPE_BUFFER_SRV: return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
860-
case SHADER_RESOURCE_TYPE_TEXTURE_UAV: return D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
861-
case SHADER_RESOURCE_TYPE_BUFFER_UAV: return D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
862-
case SHADER_RESOURCE_TYPE_SAMPLER: return D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
863-
case SHADER_RESOURCE_TYPE_ACCEL_STRUCT: return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
864-
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT:return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
865-
// clang-format on
856+
// clang-format off
857+
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER: return D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
858+
case SHADER_RESOURCE_TYPE_TEXTURE_SRV: return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
859+
case SHADER_RESOURCE_TYPE_BUFFER_SRV: return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
860+
case SHADER_RESOURCE_TYPE_TEXTURE_UAV: return D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
861+
case SHADER_RESOURCE_TYPE_BUFFER_UAV: return D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
862+
case SHADER_RESOURCE_TYPE_SAMPLER: return D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
863+
case SHADER_RESOURCE_TYPE_ACCEL_STRUCT: return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
864+
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
865+
// clang-format on
866+
867+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS:
868+
UNEXPECTED("Inline constants do not have a descriptor range type");
869+
return static_cast<D3D12_DESCRIPTOR_RANGE_TYPE>(-1);
870+
866871
default:
867872
UNEXPECTED("Unknown resource type");
868873
return static_cast<D3D12_DESCRIPTOR_RANGE_TYPE>(-1);

Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ bool PipelineResourceSignatureD3D12Impl::DvpValidateCommittedResource(const Devi
773773
}
774774
}
775775

776-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource type");
776+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource type");
777777
switch (ResDesc.ResourceType)
778778
{
779779
case SHADER_RESOURCE_TYPE_TEXTURE_SRV:

Graphics/GraphicsEngineD3D12/src/ShaderResourceCacheD3D12.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ void ShaderResourceCacheD3D12::DbgValidateDynamicBuffersMask() const
485485

486486
void ShaderResourceCacheD3D12::Resource::TransitionResource(CommandContext& Ctx)
487487
{
488-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update this function to handle the new resource type");
488+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update this function to handle the new resource type");
489489
switch (Type)
490490
{
491491
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
@@ -543,6 +543,7 @@ void ShaderResourceCacheD3D12::Resource::TransitionResource(CommandContext& Ctx)
543543
break;
544544

545545
case SHADER_RESOURCE_TYPE_SAMPLER:
546+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS:
546547
// Nothing to transition
547548
break;
548549

@@ -569,7 +570,7 @@ void ShaderResourceCacheD3D12::Resource::TransitionResource(CommandContext& Ctx)
569570
#ifdef DILIGENT_DEVELOPMENT
570571
void ShaderResourceCacheD3D12::Resource::DvpVerifyResourceState()
571572
{
572-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update this function to handle the new resource type");
573+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update this function to handle the new resource type");
573574
switch (Type)
574575
{
575576
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
@@ -657,6 +658,7 @@ void ShaderResourceCacheD3D12::Resource::DvpVerifyResourceState()
657658
break;
658659

659660
case SHADER_RESOURCE_TYPE_SAMPLER:
661+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS:
660662
// No resource
661663
break;
662664

Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void BindResourceHelper::operator()(const BindResourceInfo& BindInfo) const
570570
VERIFY_EXPR(m_ArrayIndex == BindInfo.ArrayIndex);
571571
if (BindInfo.pObject != nullptr)
572572
{
573-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update this function to handle the new resource type");
573+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update this function to handle the new resource type");
574574
switch (m_ResDesc.ResourceType)
575575
{
576576
case SHADER_RESOURCE_TYPE_CONSTANT_BUFFER:
@@ -598,6 +598,10 @@ void BindResourceHelper::operator()(const BindResourceInfo& BindInfo) const
598598
CacheSampler(BindInfo);
599599
break;
600600

601+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS:
602+
UNSUPPORTED("Not yet implemented");
603+
break;
604+
601605
case SHADER_RESOURCE_TYPE_ACCEL_STRUCT:
602606
CacheAccelStruct(BindInfo);
603607
break;

Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const char* GetBindingRangeName(BINDING_RANGE Range)
5555

5656
BINDING_RANGE PipelineResourceToBindingRange(const PipelineResourceDesc& Desc)
5757
{
58-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource type");
58+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource type");
5959
switch (Desc.ResourceType)
6060
{
6161
// clang-format off
@@ -65,6 +65,7 @@ BINDING_RANGE PipelineResourceToBindingRange(const PipelineResourceDesc& Desc)
6565
case SHADER_RESOURCE_TYPE_TEXTURE_UAV: return BINDING_RANGE_IMAGE;
6666
case SHADER_RESOURCE_TYPE_BUFFER_UAV: return (Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) ? BINDING_RANGE_IMAGE : BINDING_RANGE_STORAGE_BUFFER;
6767
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: return BINDING_RANGE_TEXTURE;
68+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS: return BINDING_RANGE_UNIFORM_BUFFER;
6869
// clang-format on
6970
case SHADER_RESOURCE_TYPE_SAMPLER:
7071
case SHADER_RESOURCE_TYPE_ACCEL_STRUCT:

Graphics/ShaderTools/src/DXBCUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ void RemapShaderResources(const DXBCUtils::TResourceBindingMap& ResourceMap, con
939939
Iter->second.ArraySize >= Res.BindCount);
940940

941941
#ifdef DILIGENT_DEBUG
942-
static_assert(SHADER_RESOURCE_TYPE_LAST == 8, "Please update the switch below to handle the new shader resource type");
942+
static_assert(SHADER_RESOURCE_TYPE_LAST == 9, "Please update the switch below to handle the new shader resource type");
943943
switch (Iter->second.ResType)
944944
{
945945
// clang-format off
@@ -950,6 +950,7 @@ void RemapShaderResources(const DXBCUtils::TResourceBindingMap& ResourceMap, con
950950
case SHADER_RESOURCE_TYPE_BUFFER_UAV: VERIFY_EXPR(ResType == RES_TYPE_UAV); break;
951951
case SHADER_RESOURCE_TYPE_SAMPLER: VERIFY_EXPR(ResType == RES_TYPE_SAMPLER); break;
952952
case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: VERIFY_EXPR(ResType == RES_TYPE_SRV); break;
953+
case SHADER_RESOURCE_TYPE_INLINE_CONSTANTS: VERIFY_EXPR(ResType == RES_TYPE_CBV); break;
953954
// clang-format on
954955
default: UNEXPECTED("Unsupported shader resource type.");
955956
}

0 commit comments

Comments
 (0)