From 6ea03bb3afbd1988aba0cf9f68bc76668ae57686 Mon Sep 17 00:00:00 2001 From: Vsevolod Livinskiy Date: Sat, 6 Feb 2016 17:08:17 +0300 Subject: [PATCH] Fix for struct with undound members --- expr.cpp | 5 ++++- tests/struct-test-128.ispc | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/struct-test-128.ispc diff --git a/expr.cpp b/expr.cpp index ce31defd..99648f91 100644 --- a/expr.cpp +++ b/expr.cpp @@ -6784,9 +6784,12 @@ lUniformValueToVarying(FunctionEmitContext *ctx, llvm::Value *value, type->GetAsVaryingType()->LLVMType(g->ctx); llvm::Value *retValue = llvm::UndefValue::get(llvmType); + const StructType *structType = CastType(type->GetAsVaryingType()); + for (int i = 0; i < collectionType->GetElementCount(); ++i) { llvm::Value *v = ctx->ExtractInst(value, i, "get_element"); - if (collectionType->GetElementType(i)->IsVaryingType()) + // If struct has "bound uniform" member, we don't need to cast it to varying + if (!(structType != NULL && structType->GetElementType(i)->IsUniformType())) v = lUniformValueToVarying(ctx, v, collectionType->GetElementType(i)); retValue = ctx->InsertInst(retValue, v, i, "set_element"); } diff --git a/tests/struct-test-128.ispc b/tests/struct-test-128.ispc new file mode 100644 index 00000000..d20cc8ff --- /dev/null +++ b/tests/struct-test-128.ispc @@ -0,0 +1,21 @@ + +export uniform int width() { return programCount; } + + +struct Foo { + float x; +}; + +export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) { + float a = aFOO[programIndex]; + uniform Foo struct_1; + struct_1.x = b; + varying Foo struct_2 = struct_1; + RET[programIndex] = struct_2.x; +} + + +export void result(uniform float RET[]) { + RET[programIndex] = 5; +} +