From d52376a65f37fcbbb67428b917fd3819436b6dfb Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 2 May 2023 20:29:38 -0700 Subject: Various dxc/fxc compatibility fixes. (#2863) * Various dxc/fxc compatibility fixes. * Cleanup. * Fix test cases. * Fix comments. --------- Co-authored-by: Yong He --- source/slang/slang-emit-glsl.cpp | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'source/slang/slang-emit-glsl.cpp') diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp index 0abd78137..bc170dadc 100644 --- a/source/slang/slang-emit-glsl.cpp +++ b/source/slang/slang-emit-glsl.cpp @@ -339,16 +339,25 @@ void GLSLSourceEmitter::_emitGLSLParameterGroup(IRGlobalParam* varDecl, IRUnifor m_writer->emit("_S"); m_writer->emit(m_uniqueIDCounter++); - m_writer->emit("\n{\n"); - m_writer->indent(); auto elementType = type->getElementType(); - - emitType(elementType, "_data"); - m_writer->emit(";\n"); - - m_writer->dedent(); - m_writer->emit("} "); + auto structType = as(elementType); + if (!as(type) && structType) + { + // We need to emit the fields of the struct as individual variables + // in the constant buffer. + // + emitStructDeclarationsBlock(structType, true); + } + else + { + m_writer->emit("\n{\n"); + m_writer->indent(); + emitType(elementType, "_data"); + m_writer->emit(";\n"); + m_writer->dedent(); + m_writer->emit("} "); + } m_writer->emit(getName(varDecl)); @@ -794,7 +803,7 @@ void GLSLSourceEmitter::_maybeEmitGLSLBuiltin(IRGlobalParam* var, UnownedStringS m_writer->emit("out"); m_writer->emit(" "); m_writer->emit(elementTypeName); - emitStructDeclarationsBlock(elementType); + emitStructDeclarationsBlock(elementType, false); m_writer->emit(" "); m_writer->emit(name); emitArrayBrackets(arrayType); @@ -1157,7 +1166,7 @@ void GLSLSourceEmitter::_emitGLSLPerVertexVaryingFragmentInput(IRGlobalParam* pa // _emitType(type, &arrayDeclarator); - emitSemantics(param); + emitSemantics(param, false); emitLayoutSemantics(param); @@ -2372,6 +2381,17 @@ void GLSLSourceEmitter::emitInterpolationModifiersImpl(IRInst* varInst, IRType* } } +void GLSLSourceEmitter::emitPackOffsetModifier(IRInst* varInst, IRType* valueType, IRPackOffsetDecoration* decoration) +{ + SLANG_UNUSED(varInst); + SLANG_UNUSED(valueType); + + _requireGLSLExtension(UnownedStringSlice::fromLiteral("GL_ARB_enhanced_layouts")); + m_writer->emit("layout(offset = "); + m_writer->emit(decoration->getRegisterOffset()->getValue() * 16 + decoration->getComponentOffset()->getValue() * 4); + m_writer->emit(")\n"); +} + void GLSLSourceEmitter::emitMeshOutputModifiersImpl(IRInst* varInst) { if(varInst->findDecoration()) -- cgit v1.2.3