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..a79963e9b7 --- /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 %18 "main" %16 %12 +OpExecutionMode %18 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 %16 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 +%17 = OpTypePointer Output %6 +%16 = OpVariable %17 Output +%19 = OpTypeFunction %2 +%20 = OpTypePointer PushConstant %11 +%21 = OpConstant %10 0 +%23 = OpConstant %4 0.0 +%25 = OpTypePointer Function %6 +%26 = OpConstantNull %6 +%28 = OpTypePointer Function %3 +%29 = OpConstantNull %3 +%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 +%18 = OpFunction %2 None %19 +%15 = OpLabel +%24 = OpVariable %25 Function %26 +%27 = OpVariable %28 Function %29 +%22 = OpAccessChain %20 %12 %21 +OpBranch %30 +%30 = OpLabel +%32 = OpAccessChain %31 %22 %21 +%33 = OpLoad %9 %32 +%35 = OpAccessChain %34 %33 %21 +%36 = OpLoad %6 %35 Aligned 16 +OpStore %24 %36 +%39 = OpAccessChain %37 %22 %38 +%40 = OpLoad %9 %39 +%43 = OpAccessChain %41 %40 %42 +%44 = OpLoad %7 %43 Aligned 4 +%46 = OpAccessChain %45 %44 %21 +%47 = OpLoad %3 %46 Aligned 8 +OpStore %27 %47 +%48 = OpLoad %6 %24 +%49 = OpLoad %3 %27 +%50 = OpCompositeConstruct %6 %49 %23 %23 +%51 = OpFAdd %6 %48 %50 +OpStore %16 %51 +OpReturn +OpFunctionEnd \ No newline at end of file diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 2bc7f45444..8469b115fe 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -781,6 +781,7 @@ fn convert_wgsl() { "const-exprs", Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL, ), + ("buffer-pointer", Targets::SPIRV), ]; for &(name, targets) in inputs.iter() {