Skip to content

Commit 0c61209

Browse files
IShaderResourceVariable: add SetInlineConstants method plumbing (#672)
1 parent 4a20552 commit 0c61209

File tree

12 files changed

+111
-3
lines changed

12 files changed

+111
-3
lines changed

Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,21 @@ struct ShaderVariableBase : public ResourceVariableBaseInterface
713713
}
714714

715715

716+
virtual void DILIGENT_CALL_TYPE SetInlineConstants(const void* pConstants,
717+
Uint32 FirstConstant,
718+
Uint32 NumConstants) override final
719+
{
720+
#ifdef DILIGENT_DEVELOPMENT
721+
{
722+
const PipelineResourceDesc& Desc = GetDesc();
723+
DEV_CHECK_ERR(Desc.ResourceType == SHADER_RESOURCE_TYPE_INLINE_CONSTANTS,
724+
"SetInlineConstants() is only allowed for inline constant variables.");
725+
}
726+
#endif
727+
728+
static_cast<ThisImplType*>(this)->SetConstants(pConstants, FirstConstant, NumConstants);
729+
}
730+
716731
virtual SHADER_RESOURCE_VARIABLE_TYPE DILIGENT_CALL_TYPE GetType() const override final
717732
{
718733
return GetDesc().VarType;

Graphics/GraphicsEngine/interface/ShaderResourceVariable.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ DILIGENT_BEGIN_INTERFACE(IShaderResourceVariable, IObject)
250250
Uint32 ArrayIndex DEFAULT_VALUE(0)) PURE;
251251

252252

253+
/// For inline constant variables, sets the constant values
254+
255+
/// \param [in] pConstants - pointer to the array of 32-bit constant values.
256+
/// \param [in] FirstConstant - index of the first 32-bit constant to set.
257+
/// \param [in] NumConstants - number of 32-bit constants to set.
258+
VIRTUAL void METHOD(SetInlineConstants)(THIS_
259+
const void* pConstants,
260+
Uint32 FirstConstant,
261+
Uint32 NumConstants) PURE;
262+
263+
253264
/// Returns the shader resource variable type
254265
VIRTUAL SHADER_RESOURCE_VARIABLE_TYPE METHOD(GetType)(THIS) CONST PURE;
255266

Graphics/GraphicsEngineD3D11/include/ShaderVariableManagerD3D11.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ class ShaderVariableManagerD3D11 : ShaderVariableManagerBase<EngineD3D11ImplTrai
130130
{
131131
UNSUPPORTED("Dynamic offset may only be set for constant buffers.");
132132
}
133+
134+
void SetConstants(const void* pConstants, Uint32 FirstConstant, Uint32 NumConstants)
135+
{
136+
UNSUPPORTED("Inline constants may only be set for constant buffers.");
137+
}
133138
};
134139

135140
struct ConstBuffBindInfo final : ShaderVariableD3D11Base<ConstBuffBindInfo, D3D11_RESOURCE_RANGE_CBV>
@@ -141,6 +146,8 @@ class ShaderVariableManagerD3D11 : ShaderVariableManagerBase<EngineD3D11ImplTrai
141146
void BindResource(const BindResourceInfo& BindInfo);
142147

143148
void SetDynamicOffset(Uint32 ArrayIndex, Uint32 Offset);
149+
150+
void SetConstants(const void* pConstants, Uint32 FirstConstant, Uint32 NumConstants);
144151
};
145152

146153
struct TexSRVBindInfo final : ShaderVariableD3D11Base<TexSRVBindInfo, D3D11_RESOURCE_RANGE_SRV>

Graphics/GraphicsEngineD3D11/src/ShaderVariableManagerD3D11.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ void ShaderVariableManagerD3D11::ConstBuffBindInfo::SetDynamicOffset(Uint32 Arra
306306
m_ParentManager.m_ResourceCache.SetDynamicCBOffset(Attr.BindPoints + ArrayIndex, Offset);
307307
}
308308

309+
void ShaderVariableManagerD3D11::ConstBuffBindInfo::SetConstants(const void* pConstants, Uint32 FirstConstant, Uint32 NumConstants)
310+
{
311+
UNSUPPORTED("Not yet implemented");
312+
}
313+
309314
void ShaderVariableManagerD3D11::TexSRVBindInfo::BindResource(const BindResourceInfo& BindInfo)
310315
{
311316
const PipelineResourceDesc& Desc = GetDesc();

Graphics/GraphicsEngineD3D12/include/ShaderVariableManagerD3D12.hpp

Lines changed: 13 additions & 1 deletion
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");
@@ -104,6 +104,11 @@ class ShaderVariableManagerD3D12 : public ShaderVariableManagerBase<EngineD3D12I
104104
Uint32 ArrayIndex,
105105
Uint32 BufferDynamicOffset);
106106

107+
void SetInlineConstants(Uint32 ResIndex,
108+
const void* pConstants,
109+
Uint32 FirstConstant,
110+
Uint32 NumConstants);
111+
107112
IDeviceObject* Get(Uint32 ArrayIndex,
108113
Uint32 ResIndex) const;
109114

@@ -192,6 +197,13 @@ class ShaderVariableD3D12Impl final : public ShaderVariableBase<ShaderVariableD3
192197
m_ParentManager.SetBufferDynamicOffset(m_ResIndex, ArrayIndex, BufferRangeOffset);
193198
}
194199

200+
void SetConstants(const void* pConstants,
201+
Uint32 FirstConstant,
202+
Uint32 NumConstants)
203+
{
204+
m_ParentManager.SetInlineConstants(m_ResIndex, pConstants, FirstConstant, NumConstants);
205+
}
206+
195207
private:
196208
using ResourceAttribs = PipelineResourceAttribsD3D12;
197209
const ResourceAttribs& GetAttribs() const

Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,14 @@ void ShaderVariableManagerD3D12::SetBufferDynamicOffset(Uint32 ResIndex,
673673
m_ResourceCache.SetBufferDynamicOffset(RootIndex, OffsetFromTableStart, BufferDynamicOffset);
674674
}
675675

676+
void ShaderVariableManagerD3D12::SetInlineConstants(Uint32 ResIndex,
677+
const void* pConstants,
678+
Uint32 FirstConstant,
679+
Uint32 NumConstants)
680+
{
681+
UNSUPPORTED("Not implemented yet");
682+
}
683+
676684
IDeviceObject* ShaderVariableManagerD3D12::Get(Uint32 ArrayIndex,
677685
Uint32 ResIndex) const
678686
{

Graphics/GraphicsEngineOpenGL/include/ShaderVariableManagerGL.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ class ShaderVariableManagerGL : ShaderVariableManagerBase<EngineGLImplTraits, vo
114114
{
115115
UNSUPPORTED("Dynamic offset may only be set for uniform and storage buffers");
116116
}
117+
118+
void SetConstants(const void* pConstants, Uint32 FirstConstant, Uint32 NumConstants)
119+
{
120+
UNSUPPORTED("Inline constants may only be set for uniform buffers");
121+
}
117122
};
118123

119124

@@ -133,6 +138,8 @@ class ShaderVariableManagerGL : ShaderVariableManagerBase<EngineGLImplTraits, vo
133138
}
134139

135140
void SetDynamicOffset(Uint32 ArrayIndex, Uint32 Offset);
141+
142+
void SetConstants(const void* pConstants, Uint32 FirstConstant, Uint32 NumConstants);
136143
};
137144

138145

Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ void ShaderVariableManagerGL::UniformBuffBindInfo::SetDynamicOffset(Uint32 Array
223223
m_ParentManager.m_ResourceCache.SetDynamicUBOffset(Attr.CacheOffset + ArrayIndex, Offset);
224224
}
225225

226+
void ShaderVariableManagerGL::UniformBuffBindInfo::SetConstants(const void* pConstants, Uint32 FirstConstant, Uint32 NumConstants)
227+
{
228+
UNSUPPORTED("Not yet implemented");
229+
}
226230

227231
void ShaderVariableManagerGL::TextureBindInfo::BindResource(const BindResourceInfo& BindInfo)
228232
{

Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2022 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");
@@ -98,6 +98,11 @@ class ShaderVariableManagerVk : ShaderVariableManagerBase<EngineVkImplTraits, Sh
9898
Uint32 ArrayIndex,
9999
Uint32 BufferDynamicOffset);
100100

101+
void SetInlineConstants(Uint32 ResIndex,
102+
const void* pConstants,
103+
Uint32 FirstConstant,
104+
Uint32 NumConstants);
105+
101106
IDeviceObject* Get(Uint32 ArrayIndex,
102107
Uint32 ResIndex) const;
103108

@@ -167,6 +172,13 @@ class ShaderVariableVkImpl final : public ShaderVariableBase<ShaderVariableVkImp
167172
{
168173
m_ParentManager.SetBufferDynamicOffset(m_ResIndex, ArrayIndex, BufferDynamicOffset);
169174
}
175+
176+
void SetConstants(const void* pConstants,
177+
Uint32 FirstConstant,
178+
Uint32 NumConstants)
179+
{
180+
m_ParentManager.SetInlineConstants(m_ResIndex, pConstants, FirstConstant, NumConstants);
181+
}
170182
};
171183

172184
} // namespace Diligent

Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,14 @@ void ShaderVariableManagerVk::SetBufferDynamicOffset(Uint32 ResIndex,
650650
m_ResourceCache.SetDynamicBufferOffset(Attribs.DescrSet, DstResCacheOffset, BufferDynamicOffset);
651651
}
652652

653+
void ShaderVariableManagerVk::SetInlineConstants(Uint32 ResIndex,
654+
const void* pConstants,
655+
Uint32 FirstConstant,
656+
Uint32 NumConstants)
657+
{
658+
UNSUPPORTED("Not yet implemented");
659+
}
660+
653661
IDeviceObject* ShaderVariableManagerVk::Get(Uint32 ArrayIndex, Uint32 ResIndex) const
654662
{
655663
const PipelineResourceDesc& ResDesc = GetResourceDesc(ResIndex);

0 commit comments

Comments
 (0)