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

Emit execution mode of type per entry point once. Emit SPIRV capability once per shader program. #4189

Conversation

ArielG-NV
Copy link
Collaborator

Added a dictionary<SpvWord,Hash> && wrapper to function like requireSPIRVCapabilities to ensure we don't emit multiple execution modes. This wrapper is called requireSPIRVExecutionMode.

Change a method of adding a SPIRV capability to use requireSPIRVCapabilities to be more correct (only emit 1 capability op).

fixes: #4185

Added a dictionary<SpvWord,Hash<ExecutionMode>> to ensure we don't emit multiple.
@ArielG-NV ArielG-NV added the pr: non-breaking PRs without breaking changes label May 17, 2024
@@ -2765,14 +2765,14 @@ struct SPIRVEmitContext
if (isQuad)
{
verifyComputeDerivativeGroupModifiers(this->m_sink, inst->sourceLoc, true, false, numThreadsDecor);
emitOpExecutionMode(getSection(SpvLogicalSectionID::ExecutionModes), nullptr, entryPoint, SpvExecutionModeDerivativeGroupQuadsNV);
emitOpCapability(getSection(SpvLogicalSectionID::Capabilities), nullptr, SpvCapabilityComputeDerivativeGroupQuadsNV);
requireSPIRVExecutionMode(nullptr, getID(ensureInst(entryPoint)), SpvExecutionModeDerivativeGroupQuadsNV);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we just do getID(entryPoint)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can make it so getID(IRInst) calls getID(ensureInst(entryPoint))?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just use getIRInstSpvID.

csyonghe
csyonghe previously approved these changes May 17, 2024
csyonghe
csyonghe previously approved these changes May 17, 2024
Comment on lines 6150 to 6156
emitOpExecutionMode(
getSection(SpvLogicalSectionID::ExecutionModes),
parentInst,
entryPoint,
executionMode,
ops...
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can replace this lines to

emitInst(getSection(SpvLogicalSectionID::ExecutionModes),
    parentInst,
    SpvOpExecutionMode,
    entryPoint,
    executionMode,
    ops...);

and remove the function emitOpExecutionMode().
Because the function is used only once here.
And the body is not doing anything much.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can remove it for now.
If someone else has a reason for the design to keep the wrapper, it should be trivial to add back anyways.

Comment on lines 13 to 14
// CHECK_SPV_QUAD_C-COUNT-1: DerivativeGroupQuadsNV
// CHECK_SPV_QUAD_C-COUNT-1: "SPV_NV_compute_shader_derivatives"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think -COUNT-1 will do what you want.
You will need to do,

// CHECK_SPV_QUAD_C: DerivativeGroupQuadsNV
// CHECK_SPV_QUAD_C-NOT: DerivativeGroupQuadsNV
// CHECK_SPV_QUAD_C: "SPV_NV_compute_shader_derivatives"
// CHECK_SPV_QUAD_C-NOT: "SPV_NV_compute_shader_derivatives"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I checked-- You are correct.
Thank-you for catching this.

@csyonghe csyonghe merged commit 07c29d8 into shader-slang:master May 20, 2024
17 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
Development

Successfully merging this pull request may close these issues.

Add OpCapability only once
3 participants