Skip to content

[SPIR-V] Improperly aligned OpLoad/OpStore for structures with 64-bit scalar types #8572

Description

@krisvers

Description
When using vk::RawBufferLoad<T> when T is a structure containing at least one 64-bit scalar (such as uint64_t or double, but not uint2 or float2), the generated SPIR-V improperly tries to load from the address using a 4-byte alignment which should be 8-byte.

Steps to Reproduce

  • Source Code: https://godbolt.org/z/o9e1djnce
    Or Simplified Code:
    struct StructureWith64BitScalarMember {
      uint64_t member;
      double member2; //also fails
    };
    
    void main() {
      uint64_t someAddress;
      /* line below produces invalid SPIR-V */
      StructureWith64BitScalarMember data64 = vk::RawBufferLoad<StructureWith64BitScalarMember>(someAddress);
      vk::RawBufferStore<StructureWith64BitScalarMember>(someAddress, data64);
    }
  • Command Run: dxc.exe -T cs_6_0 -E main -spirv source.hlsl -Fo out.spv (note: my dxc executable was sourced from LunarG's VulkanSDK version 1.4.335.0)

Actual Behavior 1

StructureWith64BitScalarMember data64 = vk::RawBufferLoad<StructureWith64BitScalarMember>(someAddress);

The above HLSL code (see the source code link in Steps to Reproduce) compiles to %75 = OpLoad %StructureWith64BitScalarMember %74 Aligned 4, which is then validated within DXC's pipeline and is found to be invalid.

fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-PhysicalStorageBuffer64-06314] Memory accesses Aligned operand value 4 is too small, the largest scalar type is 8 bytes.
  %75 = OpLoad %StructureWith64BitScalarMember %74 Aligned 4

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Actual Behavior 2

vk::RawBufferStore<StructureWith64BitScalarMember>(someAddress, data64);

The above HLSL code (see the source code link in Steps to Reproduce) compiles to OpStore %57 %58 Aligned 4, which is then validated within DXC's pipeline and is found to be invalid.

fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-PhysicalStorageBuffer64-06314] Memory accesses Aligned operand value 4 is too small, the largest scalar type is 8 bytes.
  OpStore %57 %58 Aligned 4

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

Environment

  • DXC version: dxcompiler.dll: 1.10 - 1.8.0.5123 (3f85295cf)
  • Host Operating System: Windows 11 25H2 (OS Build 26200.8655)

NOTE
Both actual behaviors are not visible at the same time. This is because when a single SPIR-V validation check fails, no further validation is continued. So, when the load is determined to be invalid, it doesn't attempt to report the equally as invalid store later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crashneeds-triageAwaiting triagespirvWork related to SPIR-V

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions