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

Ability to access default values for parameters in a constant buffer #2380

Closed
GregSlazinski opened this issue Jul 29, 2019 · 3 comments
Closed

Comments

@GregSlazinski
Copy link

In HLSL I can do this:

cbuffer XX 
{
   float x;
   float2 param[2]={float2(0,1), float2(2,3)};
}

But when converting to Spir-V the default value information is lost.

Feature Request:
Please make this work for SPIR-V too, because now I have to compile the shader 2 times, non-Spir-V to get default values and Spir-V to generate GLSL code.
Thank you

Also posted here:
KhronosGroup/SPIRV-Headers#125
KhronosGroup/SPIRV-Cross#1094

@tristanlabelle
Copy link
Contributor

tristanlabelle commented Jul 29, 2019

HLSL should warn/error on this because the initializers are ignored. You shouldn't see their values anywhere in the generated DXIL code, or SPIR-V code. I filed this bug on the issue: #2384. If you are able to observe the initializer values being taken into account anywhere, that would be bug-worthy. Otherwise, I think there is nothing for SPIR-V to do here, just a missing warning we need to add to the common semantic validation.

@ehsannas
Copy link
Contributor

Yup! Thanks @MrTrillian

@GregSlazinski
Copy link
Author

GregSlazinski commented Jul 30, 2019

@MrTrillian are you saying default values are always ignored in DXC?
No matter if compiling to dx byte code or spirv?
However this functionality was present in FXC, and it was very useful for me.
Also the default value API is available in both dx11 and dx12 reflection api.
See
https://docs.microsoft.com/en-au/windows/win32/api/d3d11shader/ns-d3d11shader-_d3d11_shader_variable_desc
And
https://docs.microsoft.com/en-us/windows/win32/api/d3d12shader/ns-d3d12shader-_d3d12_shader_variable_desc
So if this functionality is missing, can you please reopen this issue as a feature request to add it?

Please see this example code :
I have a bunch of constants defined in hlsl

BUFFER(Blend)
   const Vec2 BlendOfs4[4]=
   {
      Vec2( 0.5f, -1.5f),
      Vec2(-1.5f, -0.5f),
      Vec2( 1.5f,  0.5f),
      Vec2(-0.5f,  1.5f),
   };
 /*const Vec2 BlendOfs5[5]=
   {
      Vec2(-0.5f, -1.5f),
      Vec2(-1.5f, -0.5f),
      Vec2( 1.5f, -0.5f),
      Vec2(-0.5f,  1.5f),
      Vec2( 1.5f,  1.5f),
   };*/
   const Vec2 BlendOfs6[6]=
   {
      Vec2( 0.5f, -2.5f),

      Vec2(-0.5f, -0.5f),
      Vec2( 1.5f, -0.5f),

      Vec2(-2.5f,  0.5f),

      Vec2(-0.5f,  1.5f),
      Vec2( 1.5f,  1.5f),
   };
   const Vec2 BlendOfs8[8]=
   {
      Vec2(-1.5f, -2.5f),

      Vec2( 0.5f, -1.5f),
      Vec2( 2.5f, -1.5f),

      Vec2(-1.5f, -0.5f),

      Vec2( 1.5f,  0.5f),

      Vec2(-2.5f,  1.5f),
      Vec2(-0.5f,  1.5f),

      Vec2( 1.5f,  2.5f),
   };
 /*const Vec2 BlendOfs9[9]=
   {
      Vec2(-2.5f, -2.5f),
      Vec2(-0.5f, -2.5f),
      Vec2( 1.5f, -2.5f),
      Vec2(-2.5f, -0.5f),
      Vec2(-0.5f, -0.5f),
      Vec2( 1.5f, -0.5f),
      Vec2(-2.5f,  1.5f),
      Vec2(-0.5f,  1.5f),
      Vec2( 1.5f,  1.5f),
   };*/
   const Vec2 BlendOfs12[12]=
   {
      Vec2( 0.5f, -3.5f),

      Vec2(-1.5f, -2.5f),

      Vec2( 0.5f, -1.5f),
      Vec2( 2.5f, -1.5f),

      Vec2(-3.5f, -0.5f),
      Vec2(-1.5f, -0.5f),

      Vec2( 1.5f,  0.5f),
      Vec2( 3.5f,  0.5f),

      Vec2(-2.5f,  1.5f),
      Vec2(-0.5f,  1.5f),

      Vec2( 1.5f,  2.5f),

      Vec2(-0.5f,  3.5f),
   };
 /*const Vec2 BlendOfs13[13]=
   {
      Vec2(-0.5f, -3.5f),
      Vec2( 1.5f, -2.5f),
      Vec2(-0.5f, -1.5f),
      Vec2(-3.5f, -0.5f),
      Vec2(-1.5f, -0.5f),
      Vec2( 1.5f, -0.5f),
      Vec2( 3.5f, -0.5f),
      Vec2(-2.5f,  1.5f),
      Vec2(-0.5f,  1.5f),
      Vec2( 1.5f,  1.5f),
      Vec2( 3.5f,  1.5f),
      Vec2(-0.5f,  3.5f),
      Vec2( 1.5f,  3.5f),
   };*/
BUFFER_END

It's extremely useful to be able to define default values in hlsl so I can just extract them from reflection api.
If I had to store the values on the cpu side then it's easy to make mistake if for example I decide to change array size length on the hlsl but forget to change it on cpu as well. This way I have defined everything in one place so risk of introducing bugs is smaller.

@GregSlazinski GregSlazinski changed the title [SPIRV] Ability to access default values for parameters in a constant buffer (UBO) Ability to access default values for parameters in a constant buffer (UBO) Aug 2, 2019
@GregSlazinski GregSlazinski changed the title Ability to access default values for parameters in a constant buffer (UBO) Ability to access default values for parameters in a constant buffer Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants