diff --git a/tests/in/buffer-pointer.param.ron b/tests/in/buffer-pointer.param.ron new file mode 100644 index 0000000000..58f4bf62b5 --- /dev/null +++ b/tests/in/buffer-pointer.param.ron @@ -0,0 +1,6 @@ +( + god_mode: true, + spv: ( + version: (1, 5), + ), +) diff --git a/tests/in/buffer-pointer.wgsl b/tests/in/buffer-pointer.wgsl new file mode 100644 index 0000000000..457c12394c --- /dev/null +++ b/tests/in/buffer-pointer.wgsl @@ -0,0 +1,28 @@ +struct OtherStruct { + data: vec2, +} + +struct MyBuffer { + data: vec4, + sub_buffer: ptr, // Custom alignment = 8 +} + +// TODO: recursive references +// struct MyBuffer2 { +// data: f32, +// next: ptr, +// } + +struct PushConstants { + buf1: ptr, // Default alignment = 16 + four_bytes: u32, // Test struct member offset + buf2: ptr, // Custom alignment = 4 +} +var pc: PushConstants; + +@fragment +fn main() -> @location(0) vec4 { + var d1 = (*pc.buf1).data; + var d2 = (*(*pc.buf2).sub_buffer).data; + return d1 + vec4(d2, 0.0, 0.0); +} diff --git a/tests/out/spv/buffer-pointer.spvasm b/tests/out/spv/buffer-pointer.spvasm new file mode 100644 index 0000000000..f5014ceba7 --- /dev/null +++ b/tests/out/spv/buffer-pointer.spvasm @@ -0,0 +1,75 @@ +; SPIR-V +; Version: 1.5 +; Generator: rspirv +; Bound: 52 +OpCapability Shader +OpCapability PhysicalStorageBufferAddresses +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel PhysicalStorageBuffer64 GLSL450 +OpEntryPoint Fragment %24 "main" %22 %12 +OpExecutionMode %24 OriginUpperLeft +OpMemberDecorate %5 0 Offset 0 +OpMemberDecorate %8 0 Offset 0 +OpMemberDecorate %8 1 Offset 16 +OpMemberDecorate %11 0 Offset 0 +OpMemberDecorate %11 1 Offset 8 +OpMemberDecorate %11 2 Offset 16 +OpDecorate %13 Block +OpMemberDecorate %13 0 Offset 0 +OpDecorate %22 Location 0 +%2 = OpTypeVoid +%4 = OpTypeFloat 32 +%3 = OpTypeVector %4 2 +%5 = OpTypeStruct %3 +%6 = OpTypeVector %4 4 +%7 = OpTypePointer PhysicalStorageBuffer %5 +%8 = OpTypeStruct %6 %7 +%9 = OpTypePointer PhysicalStorageBuffer %8 +%10 = OpTypeInt 32 0 +%11 = OpTypeStruct %9 %10 %9 +%13 = OpTypeStruct %11 +%14 = OpTypePointer PushConstant %13 +%12 = OpVariable %14 PushConstant +%16 = OpTypePointer Function %6 +%17 = OpConstantNull %6 +%19 = OpTypePointer Function %3 +%20 = OpConstantNull %3 +%23 = OpTypePointer Output %6 +%22 = OpVariable %23 Output +%25 = OpTypeFunction %2 +%26 = OpTypePointer PushConstant %11 +%27 = OpConstant %10 0 +%29 = OpConstant %4 0.0 +%31 = OpTypePointer PushConstant %9 +%34 = OpTypePointer PhysicalStorageBuffer %6 +%37 = OpTypePointer PushConstant %9 +%38 = OpConstant %10 2 +%41 = OpTypePointer PhysicalStorageBuffer %7 +%42 = OpConstant %10 1 +%45 = OpTypePointer PhysicalStorageBuffer %3 +%24 = OpFunction %2 None %25 +%21 = OpLabel +%15 = OpVariable %16 Function %17 +%18 = OpVariable %19 Function %20 +%28 = OpAccessChain %26 %12 %27 +OpBranch %30 +%30 = OpLabel +%32 = OpAccessChain %31 %28 %27 +%33 = OpLoad %9 %32 +%35 = OpAccessChain %34 %33 %27 +%36 = OpLoad %6 %35 Aligned 16 +OpStore %15 %36 +%39 = OpAccessChain %37 %28 %38 +%40 = OpLoad %9 %39 +%43 = OpAccessChain %41 %40 %42 +%44 = OpLoad %7 %43 Aligned 4 +%46 = OpAccessChain %45 %44 %27 +%47 = OpLoad %3 %46 Aligned 8 +OpStore %18 %47 +%48 = OpLoad %6 %15 +%49 = OpLoad %3 %18 +%50 = OpCompositeConstruct %6 %49 %29 %29 +%51 = OpFAdd %6 %48 %50 +OpStore %22 %51 +OpReturn +OpFunctionEnd \ No newline at end of file diff --git a/tests/snapshots.rs b/tests/snapshots.rs index e1e1144139..296cbadc12 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -611,6 +611,7 @@ fn convert_wgsl() { "constructors", Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL, ), + ("buffer-pointer", Targets::SPIRV), ]; for &(name, targets) in inputs.iter() {