Skip to content

HLSL: Fix #pragma pack_matrix(row_major) not work on global uniforms#2268

Merged
johnkslang merged 2 commits intoKhronosGroup:masterfrom
lriki:hlsl-pack_matrix
Jul 2, 2020
Merged

HLSL: Fix #pragma pack_matrix(row_major) not work on global uniforms#2268
johnkslang merged 2 commits intoKhronosGroup:masterfrom
lriki:hlsl-pack_matrix

Conversation

@lriki
Copy link
Copy Markdown
Contributor

@lriki lriki commented Jun 12, 2020

I created the following file.

// test.frag (HLSL)
#pragma pack_matrix(row_major)

float4x4 _CameraProjectionMatrix;

cbuffer LNRenderViewBuffer
{
    float4x4 ln_Projection;
};

float4 main() : SV_TARGET
{
    float4 c = float4(1, 0, 0, 1);
    c = mul(c, _CameraProjectionMatrix);
    c = mul(c, ln_Projection);
    return c;
}

Compiled with glslangValidator and output with spirv-dis as follows.

glslangValidator -e main -o test.spv -V -D test.frag
spirv-dis test.spv
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 8
; Bound: 51
; Schema: 0
               OpCapability Shader
          %1 = OpExtInstImport "GLSL.std.450"
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %main "main" %_entryPointOutput
               OpExecutionMode %main OriginUpperLeft
               OpSource HLSL 500
               OpName %main "main"
               OpName %_Global "$Global"
               OpMemberName %_Global 0 "_CameraProjectionMatrix"
               OpName %_ ""
               OpName %LNRenderViewBuffer "LNRenderViewBuffer"
               OpMemberName %LNRenderViewBuffer 0 "ln_Projection"
               OpName %__0 ""
               OpName %_entryPointOutput "@entryPointOutput"
               OpMemberDecorate %_Global 0 RowMajor                  <<<< ❌ 
               OpMemberDecorate %_Global 0 Offset 0
               OpMemberDecorate %_Global 0 MatrixStride 16
               OpDecorate %_Global Block
               OpDecorate %_ DescriptorSet 0
               OpDecorate %_ Binding 0
               OpMemberDecorate %LNRenderViewBuffer 0 ColMajor       <<<< 🆗 
               OpMemberDecorate %LNRenderViewBuffer 0 Offset 0
               OpMemberDecorate %LNRenderViewBuffer 0 MatrixStride 16

This is different from the output of dxc.

dxc -spirv -T ps_6_0 -E main test.frag -Fo test-dxc.spv
spirv-dis test-dxc.spv
; SPIR-V
; Version: 1.0
; Generator: Google spiregg; 0
; Bound: 28
; Schema: 0
               OpCapability Shader
               OpMemoryModel Logical GLSL450
               OpEntryPoint Fragment %main "main" %out_var_SV_TARGET
               OpExecutionMode %main OriginUpperLeft
               OpSource HLSL 600
               OpName %type__Globals "type.$Globals"
               OpMemberName %type__Globals 0 "_CameraProjectionMatrix"
               OpName %_Globals "$Globals"
               OpName %type_LNRenderViewBuffer "type.LNRenderViewBuffer"
               OpMemberName %type_LNRenderViewBuffer 0 "ln_Projection"
               OpName %LNRenderViewBuffer "LNRenderViewBuffer"
               OpName %out_var_SV_TARGET "out.var.SV_TARGET"
               OpName %main "main"
               OpDecorate %out_var_SV_TARGET Location 0
               OpDecorate %_Globals DescriptorSet 0
               OpDecorate %_Globals Binding 0
               OpDecorate %LNRenderViewBuffer DescriptorSet 0
               OpDecorate %LNRenderViewBuffer Binding 1
               OpMemberDecorate %type__Globals 0 Offset 0
               OpMemberDecorate %type__Globals 0 MatrixStride 16
               OpMemberDecorate %type__Globals 0 ColMajor                  <<<< 🆗 
               OpDecorate %type__Globals Block
               OpMemberDecorate %type_LNRenderViewBuffer 0 Offset 0
               OpMemberDecorate %type_LNRenderViewBuffer 0 MatrixStride 16
               OpMemberDecorate %type_LNRenderViewBuffer 0 ColMajorv       <<<< 🆗 

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jun 12, 2020

CLA assistant check
All committers have signed the CLA.

@lriki lriki force-pushed the hlsl-pack_matrix branch from 6e462ef to eac36e8 Compare June 19, 2020 03:35
@johnkslang
Copy link
Copy Markdown
Contributor

Could you please add at least one test that shows a test-result change displayed by this code change Thanks.

@lriki
Copy link
Copy Markdown
Contributor Author

lriki commented Jun 25, 2020

Thanks for the review!

I added a test.

@lriki lriki force-pushed the hlsl-pack_matrix branch from 5b37eef to 1ee750a Compare June 25, 2020 08:54
@johnkslang johnkslang merged commit a70f7de into KhronosGroup:master Jul 2, 2020
dgkoch added a commit to dgkoch/glslang that referenced this pull request Nov 23, 2020
dgkoch added a commit to dgkoch/glslang that referenced this pull request Nov 23, 2020
johnkslang pushed a commit that referenced this pull request Nov 23, 2020
* Fix traceRay/executeCallable to have id instead of constant.

Update to final (non-provisional) SPIR-V capabilities
(includes review feedback)
- Change visibilty of findLinkerObjects.

See merge request GLSL/glslang!78

* Add support for OpConvertUToAccelerationStructureKHR.

GLSL : https://gitlab.khronos.org/GLSL/GLSL/-/merge_requests/60

SPV : https://gitlab.khronos.org/spirv/spirv-extensions/-/merge_requests/182

See merge request GLSL/glslang!77

* Add volatile qualifier to certain builtins for ray tracing.

See merge request GLSL/glslang!81

* make gl_RayTmaxEXT volatile in intersection shader

Vulkan Issue #2268

* Add testing for layouts on SBT

vulkan/vulkan#2230

- no layout specified should be same as std430
- explicitly test std140, std430, scalar layouts

See merge request GLSL/glslang!86

* Support for new opcodes OpIgnoreIntersectionKHR and OpTerminateRayKHR

vulkan/vulkan#2374

Add support for ignoreIntersectionEXT and terminateRayEXT as block
terminator statements.

See merge request GLSL/glslang!87

* Fix code-generation issues with global ray query variables

See merge request GLSL/glslang!88

* update dependencies for spirv-headers and tools

And update mesh shader results

* Fix indeterminate argument ordering

Authored-by: David Neto <dneto@google.com>

Co-authored-by: Ashwin Lele (NVIDIA Corporation) <alele@nvidia.com>
Co-authored-by: Neslisah <Neslisah.Torosdagli@amd.com>
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

Successfully merging this pull request may close these issues.

3 participants