diff --git a/example/passthrough_fragment.glsl b/example/passthrough_fragment.glsl index 26fdc79..5ec12f4 100644 --- a/example/passthrough_fragment.glsl +++ b/example/passthrough_fragment.glsl @@ -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; } diff --git a/lib/CodeGen/MLIRCodeGen.cpp b/lib/CodeGen/MLIRCodeGen.cpp index 9671792..0531ce4 100644 --- a/lib/CodeGen/MLIRCodeGen.cpp +++ b/lib/CodeGen/MLIRCodeGen.cpp @@ -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))) { diff --git a/test/CodeGen/structs.glsl b/test/CodeGen/structs.glsl new file mode 100644 index 0000000..1580171 --- /dev/null +++ b/test/CodeGen/structs.glsl @@ -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 + // 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 + // 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 + // 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 + // CHECK-NEXT: spirv.Store "Function" %13, %12 : i1 + bool d = myStruct.d; + + return; +}