Skip to content

Add initial proposal for cbuffer contexts #497

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

llvm-beanz
Copy link
Collaborator

This adds an initial rough proposal for simplifying cbuffers in HLSL 202x.

This adds an initial rough proposal for simplifying cbuffers in HLSL
202x.
[FXC @ ShaderPlayground](https://shader-playground.timjones.io/22396dd8aec3318b3e9a598c612f156e)
[DXC @ Compiler Explorer](https://godbolt.org/z/WYK7jvvfP)

In DXC, `a` and `b` are referenced directly with no namespace qualifications,
Copy link
Member

@hekota hekota Apr 29, 2025

Choose a reason for hiding this comment

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

It is actually possible to reference a and b in DXC by both qualified and unqualifies names as long as the namespace contains more than just a cbuffer: https://godbolt.org/z/Ph57WYexr. Which is clearly a bug.
(filed in microsoft/DirectXShaderCompiler#4514 and microsoft/DirectXShaderCompiler#7322)

A `cbuffer` may only be declared at translation unit or namespace scope. A
`cbuffer` may only contain variable (or empty) declarations. All declarations
within a `cbuffer` declare names in the immediate enclosing scope.

Copy link
Member

Choose a reason for hiding this comment

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

Would it be worth to enumerate types of declarations that will no longer be allowed? Functions, records, static & groupshared var decls...

Copy link
Member

Choose a reason for hiding this comment

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

And maybe add a note at the beginning that cbuffer should be a collection of constants provided for the shader and that other declarations do not make sense to be included in this context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants