Skip to content

Commit

Permalink
Add WGSL test for buffer pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeagc committed Sep 9, 2023
1 parent 451c5dd commit ec893fe
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/in/buffer-pointer.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(
god_mode: true,
spv: (
version: (1, 5),
),
)
28 changes: 28 additions & 0 deletions tests/in/buffer-pointer.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
struct OtherStruct {
data: vec2<f32>,
}

struct MyBuffer {
data: vec4<f32>,
sub_buffer: ptr<buffer, OtherStruct, 8>, // Custom alignment = 8
}

// TODO: recursive references
// struct MyBuffer2 {
// data: f32,
// next: ptr<buffer, MyBuffer2>,
// }

struct PushConstants {
buf1: ptr<buffer, MyBuffer>, // Default alignment = 16
four_bytes: u32, // Test struct member offset
buf2: ptr<buffer, MyBuffer, 4>, // Custom alignment = 4
}
var<push_constant> pc: PushConstants;

@fragment
fn main() -> @location(0) vec4<f32> {
var d1 = (*pc.buf1).data;
var d2 = (*(*pc.buf2).sub_buffer).data;
return d1 + vec4<f32>(d2, 0.0, 0.0);
}
75 changes: 75 additions & 0 deletions tests/out/spv/buffer-pointer.spvasm
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,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() {
Expand Down

0 comments on commit ec893fe

Please sign in to comment.