From 2e0f8f28a781c285e96670e515d8fab24c484ce8 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 12 Sep 2017 09:56:41 -0700 Subject: Get IR working for `AdaptiveTessellationCS40/Render` test I had expected this to be the first case where control-flow instructions were needed, but it turns out that we aren't testing that entry point right now. The real work/fix here ended up being handling of the `row_major` layout qualifier on a matrix inside a `cbuffer`. The existing AST-based code was passing it through easily (although I don't believe it was handling the layout rules right). Getting it working in the IR involved beefing up the type-layout behavior so that it can handle explicit layout qualifiers (at least for matrix layout) which should also improve the layout computation for non-square matrices with nonstandard layout in the AST-based path. There are still some annoying things left to do: - The `row_major` and `column_major` layout qualifiers in HLSL/GLSL mean different things (well, they mean the reverse of one another) so I need to validate that the GLSL case is working remotely correctly. - The layout logic isn't handling other explicit-layout cases as supported by GLSL (but of course GLSL is a far lower priority than HLSL/Slang) - There is currently no way to pass in an explicit matrix layout flag to Slang to control the default behavior. - Any client who was using Slang for HLSL pass-through and then applying a non-default flag on their HLSL->* compilation will get nasty unexpected behavior when the IR goes live - and they are already dealing with nasty behavior around non-square matrices not matching layout between Slang and the downstream. - The logic that gleans layout modes from a variable declaration is currently only being applied for fields of structure types (which applies to `cbuffer` declarations as well), and not to global-scope uniform variables. - We need test cases for all of this. --- source/slang/emit.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 40366c43c..209436da4 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -4416,6 +4416,16 @@ emitDeclImpl(decl, nullptr); emit("]"); break; + case kIROp_Mul_Vector_Matrix: + case kIROp_Mul_Matrix_Vector: + case kIROp_Mul_Matrix_Matrix: + emit("mul("); + emitIROperand(context, inst->getArg(1)); + emit(", "); + emitIROperand(context, inst->getArg(2)); + emit(")"); + break; + default: emit("/* uhandled */"); break; @@ -4575,6 +4585,34 @@ emitDeclImpl(decl, nullptr); emit("};\n"); } + void emitIRVarModifiers( + EmitContext* context, + VarLayout* layout) + { + if (!layout) + return; + + // We need to handle the case where the variable has + // a matrix type, and has been given a non-standard + // layout attribute (for HLSL, `row_major` is the + // non-standard layout). + // + if (auto matrixTypeLayout = layout->typeLayout.As()) + { + switch (matrixTypeLayout->mode) + { + case kMatrixLayoutMode_ColumnMajor: + emit("column_major "); + break; + + case kMatrixLayoutMode_RowMajor: + emit("row_major "); + break; + } + + } + } + void emitIRParameterBlock( EmitContext* context, IRVar* varDecl, @@ -4624,7 +4662,7 @@ emitDeclImpl(decl, nullptr); auto fieldLayout = structTypeLayout->fields[fieldIndex++]; - + emitIRVarModifiers(context, fieldLayout); auto fieldType = ff->getFieldType(); emitIRType(context, fieldType, getName(ff)); @@ -4662,6 +4700,11 @@ emitDeclImpl(decl, nullptr); break; } + // Need to emit appropriate modifiers here. + + auto layout = getVarLayout(context, varDecl); + + emitIRVarModifiers(context, layout); emitIRType(context, varType, getName(varDecl)); -- cgit v1.2.3