Skip to content
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

Fix Varying Variable Location Assignments With Hull Shaders #4915

Conversation

ArielG-NV
Copy link
Contributor

@ArielG-NV ArielG-NV commented Aug 26, 2024

Fixes: #4913
Fixes: #4540

Changes:

  1. Added kIROp_ControlBarrier to HLSL/GLSL emitting.
  2. Added a method to track 'used' and 'unused' varying's for when legalizing GLSL. This allows us to assign correct offsets to automatically added varying's variables.
    • Added a getLSBZero logic to UIntSet for efficient LSBZero finding logic

Notes:

Fixes: shader-slang#4913
Fixes: shader-slang#4540

Changes:
1. Added `kIROp_ControlBarrier` to HLSL/GLSL emitting.
2. Added a method to track 'used' and 'unused' varyings for when legalizing GLSL. This allows us to assign correct offsets to automatically added varyings
    * Added a `ZeroLSB` check to UIntSet for this purpose
@ArielG-NV ArielG-NV added the pr: non-breaking PRs without breaking changes label Aug 26, 2024
@@ -500,6 +500,11 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
{
switch (inst->getOp())
{
case kIROp_ControlBarrier:
{
m_writer->emit("GroupMemoryBarrier();\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GroupMemoryBatrierWithGroupSync.

Otherwise this is just a memory barrier not a control barrier.

Stage stage;
IRFunc* entryPointFunc;

//Dictionary<ResourceType, Dictionary<Space, BindingIndex>>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more description to the comment as it currently looks too much like a left over debug code.

@@ -265,7 +265,8 @@ struct GLSLLegalizationContext
Stage stage;
IRFunc* entryPointFunc;

//Dictionary<ResourceType, Dictionary<Space, BindingIndex>>
/// This dictionary stores for 'VaryingIn/VaryingOut' ('Dictionary<LayoutResourceKind, ...>') all used
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would a varying in/out has a space binding? They should only have a single location number, so it appears to me that Dictionary<LayoutResourceKind, UIntSet> is sufficient.

Copy link
Contributor Author

@ArielG-NV ArielG-NV Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would a varying in/out has a space binding?

I am worried about some random crash or invalid code-gen due to a non '0' space for an edge case.

varying's should not have a space other than 0, although, I did not see anywhere that the GLSL legalization code to ensure any of this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can safely assume this, because there is no way in spirv/glsl to specify a "space" for a varying inout.

Copy link
Contributor Author

@ArielG-NV ArielG-NV Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add this change then👍

@ArielG-NV ArielG-NV merged commit f0ba756 into shader-slang:master Aug 26, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: non-breaking PRs without breaking changes
Projects
None yet
2 participants