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

Specifying root signatures from HLSL #330

Open
turanszkij opened this issue Oct 1, 2024 · 1 comment
Open

Specifying root signatures from HLSL #330

turanszkij opened this issue Oct 1, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@turanszkij
Copy link

turanszkij commented Oct 1, 2024

Hello,

Currently we need to use strings in HLSL when defining a root signature within the shader. This seems to originate from the time when HLSL was preparing to support DX12 features a long time ago. This feels like a workaround solution made for the old shader compiler and not a real language feature. The problem is that it is very easy to make a mistake in the string define, like leaving out a comma in a big multiline root signature definition. The error reporting is also hard to understand when making a mistake in the root signature string, especially if this string is long and multiline.

It would be great if there was a proper HLSL syntax to specify the root signature.

For example, a current string-style root signature:

"RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT), " \
"RootConstants(num32BitConstants=12, b999), " \
"CBV(b0), " \
"DescriptorTable( " \
	"UAV(u0, numDescriptors = 16, flags = DESCRIPTORS_VOLATILE | DATA_STATIC_WHILE_SET_AT_EXECUTE)" \
")," \
"DescriptorTable( " \
	"Sampler(s0, space = 1, offset = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)" \
")," \
"DescriptorTable( " \
	"SRV(t0, space = 2, offset = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE | DATA_VOLATILE)" \
"), " \
"StaticSampler(s100, addressU = TEXTURE_ADDRESS_CLAMP, addressV = TEXTURE_ADDRESS_CLAMP, addressW = TEXTURE_ADDRESS_CLAMP, filter = FILTER_MIN_MAG_MIP_LINEAR)" 

Could be rewritten with a new syntax that is not just a big string, but more structured:

struct MyRootSignature
{
  RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
  RootConstants(num32BitConstants=12, b999);
  CBV(b0);
  DescriptorTable(
	UAV(u0, numDescriptors = 16, flags = DESCRIPTORS_VOLATILE | DATA_STATIC_WHILE_SET_AT_EXECUTE)
  );
  DescriptorTable(
	Sampler(s0, space = 1, offset = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)
  );
  DescriptorTable(
	SRV(t0, space = 2, offset = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE | DATA_VOLATILE)
  );
  StaticSampler(s100, addressU = TEXTURE_ADDRESS_CLAMP, addressV = TEXTURE_ADDRESS_CLAMP, addressW = TEXTURE_ADDRESS_CLAMP, filter = FILTER_MIN_MAG_MIP_LINEAR);
};

And then this struct can easily be added to the rootsig declaration for a shader:

[RootSignature(MyRootSignature)]

The shader compiler also allows to specify a root signature define as a compile argument (-rootsig-define <value>), this is very useful too. Currently it needs a define that expands to a string, but it should accept the new root signature syntax as well.

The proposed syntax is just a really first attempt, I don't think it's very important that it would look like that.

Best regards,
Janos

@krupitskas
Copy link

Agree with Janos.
I think almost everyone came up with custom solution to simplify shader manufacturing. Would be great to standardize RootSignature object and deprecate string definition.

@damyanp damyanp added this to the HLSL Backlog milestone Oct 1, 2024
@damyanp damyanp moved this to Triaged in HLSL Triage Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Triaged
Development

No branches or pull requests

3 participants