Skip to content

Commit

Permalink
Add struct codegen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wpmed92 committed Aug 23, 2024
1 parent 9f7e3cf commit d7820e0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
11 changes: 1 addition & 10 deletions example/passthrough_fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
layout(location = 0) out vec4 outColor;

// Demonstrate struct handling
struct Color {
float r;
float g;
float b;
float a;
}

void main() {
Color color = Color(1.0, 0.0, 0.0, 1.0);
outColor = vec4(color.r, color.g, color.b, color.a);
outColor = vec4(1.0, 0.0, 0.0, 1.0);
return;
}
1 change: 0 additions & 1 deletion lib/CodeGen/MLIRCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ void MLIRCodeGen::createVariable(shaderpulse::Type *type,
typeContext = varType;

if (inGlobalScope) {
std::cout << "In global scope" << std::endl;
spirv::StorageClass storageClass;

if (auto st = getSpirvStorageClass(varType->getQualifier(TypeQualifierKind::Storage))) {
Expand Down
33 changes: 33 additions & 0 deletions test/CodeGen/structs.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
struct MyStruct {
float a;
int b;
uint c;
bool d;
}

void main() {
// CHECK: %0 = spirv.CompositeConstruct %cst_f32, %cst2_si32, %cst3_ui32, %true : (f32, si32, ui32, i1) -> !spirv.struct<(f32, si32, ui32, i1)>
MyStruct myStruct = MyStruct(0.1, 2, 3u, true);

// CHECK: %3 = spirv.CompositeExtract %2[0 : i32] : !spirv.struct<(f32, si32, ui32, i1)>
// CHECK-NEXT: %4 = spirv.Variable : !spirv.ptr<f32, Function>
// CHECK-NEXT: spirv.Store "Function" %4, %3 : f32
float a = myStruct.a;

// CHECK: %6 = spirv.CompositeExtract %5[1 : i32] : !spirv.struct<(f32, si32, ui32, i1)>
// CHECK-NEXT: %7 = spirv.Variable : !spirv.ptr<si32, Function>
// CHECK-NEXT: spirv.Store "Function" %7, %6 : si32
int b = myStruct.b;

// CHECK: %9 = spirv.CompositeExtract %8[2 : i32] : !spirv.struct<(f32, si32, ui32, i1)>
// CHECK-NEXT: %10 = spirv.Variable : !spirv.ptr<ui32, Function>
// CHECK-NEXT: spirv.Store "Function" %10, %9 : ui32
uint c = myStruct.c;

// CHECK: %12 = spirv.CompositeExtract %11[3 : i32] : !spirv.struct<(f32, si32, ui32, i1)>
// CHECK-NEXT: %13 = spirv.Variable : !spirv.ptr<i1, Function>
// CHECK-NEXT: spirv.Store "Function" %13, %12 : i1
bool d = myStruct.d;

return;
}

0 comments on commit d7820e0

Please sign in to comment.