-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support multiple unbounded arrays within a single SRG #25
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,9 @@ namespace AZ::ShaderCompiler | |
BindingPair m_registerBinding; | ||
int m_registerRange = -1; | ||
int m_num32BitConstants = -1; | ||
|
||
int m_spillSpace = -1; | ||
|
||
// This flag is added so m_registerRange can take the value | ||
// of 1 and at the same time We do not forget that m_uid refers | ||
// to an unbounded array. | ||
|
@@ -98,6 +101,10 @@ namespace AZ::ShaderCompiler | |
int GetAccumulated(BindingType r) const; | ||
|
||
int m_space = 0; //<! logical space | ||
|
||
// See: MultiBindingLocationMarker::m_unboundedSpillSpace | ||
int m_unboundedSpillSpace; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's initialize this just to be safe. |
||
|
||
int m_registerPos[BindingType::EndEnumeratorSentinel_] = {0}; //!< register index, one by type. | ||
int m_accumulated[BindingType::EndEnumeratorSentinel_] = {0}; //!< Counter for total usage independently from space increments | ||
int m_accumulatedUnused[BindingType::EndEnumeratorSentinel_] = {0}; //!< Counter for holes created by indices unification | ||
|
@@ -109,21 +116,28 @@ namespace AZ::ShaderCompiler | |
class MultiBindingLocationMaker | ||
{ | ||
public: | ||
MultiBindingLocationMaker(const Options& options) | ||
: m_options(options) | ||
MultiBindingLocationMaker(const Options& options, int& unboundedSpillSpace) | ||
: m_options{ options } | ||
, m_unboundedSpillSpace{ unboundedSpillSpace } | ||
Comment on lines
+119
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer unboundedSpillSpace be a pointer instead of a reference, to make it obvious what's going on at the call site. Calling "MultiBindingLocationMaker(options, &unboundedSpillSpaceValue)" is a more clear than calling "MultiBindingLocationMaker(options, unboundedSpillSpaceValue)" |
||
{} | ||
|
||
void SignalIncrementSpace(std::function<void(int, int)> warningMessageFunctionForMinDescOvershoot); | ||
|
||
void SignalUnifyIndices(); | ||
|
||
void SignalRegisterIncrement(BindingType regType, int count = 1); | ||
void SignalRegisterIncrement(BindingType regType, int count, bool isUnbounded); | ||
|
||
BindingPair GetCurrent(BindingType regType); | ||
|
||
SingleBindingLocationTracker m_untainted; | ||
SingleBindingLocationTracker m_merged; | ||
Options m_options; | ||
|
||
// On some platforms (DX12), descriptor arrays occupy an individual register slot, and spaces are used | ||
// to prevent overlapping ranges. When an unbounded array is encountered, we immediately assign it to | ||
// the value of this member variable and increment. This is initialized in the constructor because the | ||
// space we spill to must not collide with any other SRG declared in the shader. | ||
int& m_unboundedSpillSpace; | ||
}; | ||
|
||
//! This class intends to be a base umbrella for compiler back-end services. | ||
|
@@ -174,6 +188,9 @@ namespace AZ::ShaderCompiler | |
std::ostream& m_out; | ||
IntermediateRepresentation* m_ir; | ||
TokenStream* m_tokens; | ||
|
||
// See MultiBindingLocationMaker::m_unboundedSpillSpace | ||
mutable int m_unboundedSpillSpace; | ||
}; | ||
|
||
// independent utility functions | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
ShaderResourceGroupSemantic slot1 | ||
{ | ||
FrequencyId = 1; | ||
}; | ||
|
||
struct MyStruct | ||
{ | ||
float4 m_a; | ||
float4 m_b; | ||
}; | ||
|
||
|
||
ShaderResourceGroup SRG1 : slot1 | ||
{ | ||
|
||
Texture2D<float4> m_texSRVa[]; // t0+, space1000 | ||
Texture2D<float4> m_texSRVb[]; // t0+, space1001 | ||
RWTexture2D<float4> m_texUAVa[]; // u0+, space1002 | ||
RWTexture2D<float4> m_texUAVb[]; // u0+, space1003 | ||
Sampler m_samplera[]; // s0+, space1004 | ||
Sampler m_samplerb[]; // s0+, space1005 | ||
ConstantBuffer<MyStruct> m_structArraya[]; // b0+, space1006 | ||
ConstantBuffer<MyStruct> m_structArrayb[]; // b0+, space1007 | ||
Comment on lines
+16
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be an Emission test instead, so we can check the appropriate spaces are used in the generated output? |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that m_unboundedSpillSpace is a mutable member, so it can be assigned here in a const function. Why can't this just be a local variable instead? Is it used after the BuildSignatureDescription function closes? If so, please add a code comment about what's going on, as this is unexpected.