summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-09-07 16:37:55 -0700
committerGitHub <noreply@github.com>2023-09-07 16:37:55 -0700
commit818f07558c44c3b7f5618460d20c1374df2f1262 (patch)
tree8c0f5ce483428db17c493b351883464a64d49295 /source
parent6804680b7da2133f04513293836f70ff61d03b77 (diff)
Fix GLSL output for `gl_ClipDistance` input builtin. (#3193)
* Fix GLSL output for `gl_ClipDistance` input builtin. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-signal.cpp2
-rw-r--r--source/slang/slang-container-pool.h2
-rw-r--r--source/slang/slang-emit-glsl.cpp8
-rw-r--r--source/slang/slang-ir-glsl-legalize.cpp130
-rw-r--r--source/slang/slang.cpp8
5 files changed, 90 insertions, 60 deletions
diff --git a/source/core/slang-signal.cpp b/source/core/slang-signal.cpp
index cdf2a1179..d8218b379 100644
--- a/source/core/slang-signal.cpp
+++ b/source/core/slang-signal.cpp
@@ -52,7 +52,7 @@ SLANG_RETURN_NEVER void handleSignal(SignalType type, char const* message)
switch (type)
{
case SignalType::InvalidOperation: throw InvalidOperationException(_getMessage(type, message));
- case SignalType::AbortCompilation: throw AbortCompilationException();
+ case SignalType::AbortCompilation: throw AbortCompilationException(_getMessage(type, message));
default: throw InternalError(_getMessage(type, message));
}
#else
diff --git a/source/slang/slang-container-pool.h b/source/slang/slang-container-pool.h
index addeb1607..0b7a56694 100644
--- a/source/slang/slang-container-pool.h
+++ b/source/slang/slang-container-pool.h
@@ -25,7 +25,7 @@ struct ObjectPool
{
auto id = m_pool.alloc(1);
if (id == -1)
- SLANG_ABORT_COMPILATION("container pool allocation failure.");
+ SLANG_UNEXPECTED("container pool allocation failure.");
return &m_objects[id];
}
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index 94c85409f..c097de5b9 100644
--- a/source/slang/slang-emit-glsl.cpp
+++ b/source/slang/slang-emit-glsl.cpp
@@ -874,15 +874,15 @@ void GLSLSourceEmitter::_maybeEmitGLSLBuiltin(IRGlobalParam* var, UnownedStringS
}
else if (name == "gl_ClipDistance")
{
+ // Is this an output? We do not need to define input.
auto varType = var->getDataType();
if (auto outType = as<IROutType>(varType))
{
varType = outType->getValueType();
+ m_writer->emit("out ");
+ emitType(varType, getName(var));
+ m_writer->emit(";\n\n");
}
-
- m_writer->emit("out ");
- emitType(varType, getName(var));
- m_writer->emit(";\n\n");
}
}
diff --git a/source/slang/slang-ir-glsl-legalize.cpp b/source/slang/slang-ir-glsl-legalize.cpp
index 4c5b58882..23ddfc50f 100644
--- a/source/slang/slang-ir-glsl-legalize.cpp
+++ b/source/slang/slang-ir-glsl-legalize.cpp
@@ -934,6 +934,65 @@ GLSLSystemValueInfo* getGLSLSystemValueInfo(
return nullptr;
}
+void createVarLayoutForLegalizedGlobalParam(
+ IRInst* globalParam,
+ IRBuilder* builder,
+ IRVarLayout* inVarLayout,
+ IRTypeLayout* typeLayout,
+ LayoutResourceKind kind,
+ UInt bindingIndex,
+ UInt bindingSpace,
+ GlobalVaryingDeclarator* declarator,
+ IRInst* leafVar,
+ GLSLSystemValueInfo* systemValueInfo)
+{
+ // We need to construct a fresh layout for the variable, even
+ // if the original had its own layout, because it might be
+ // an `inout` parameter, and we only want to deal with the case
+ // described by our `kind` parameter.
+ //
+ IRVarLayout::Builder varLayoutBuilder(builder, typeLayout);
+ varLayoutBuilder.cloneEverythingButOffsetsFrom(inVarLayout);
+ auto varOffsetInfo = varLayoutBuilder.findOrAddResourceInfo(kind);
+ varOffsetInfo->offset = bindingIndex;
+ varOffsetInfo->space = bindingSpace;
+ IRVarLayout* varLayout = varLayoutBuilder.build();
+ builder->addLayoutDecoration(globalParam, varLayout);
+
+ if (leafVar)
+ {
+ if (auto interpolationModeDecor = leafVar->findDecoration<IRInterpolationModeDecoration>())
+ {
+ builder->addInterpolationModeDecoration(globalParam, interpolationModeDecor->getMode());
+ }
+
+ }
+
+ if (declarator && declarator->flavor == GlobalVaryingDeclarator::Flavor::meshOutputPrimitives)
+ {
+ builder->addDecoration(globalParam, kIROp_GLSLPrimitivesRateDecoration);
+ }
+
+ if (systemValueInfo)
+ {
+ builder->addImportDecoration(globalParam, UnownedTerminatedStringSlice(systemValueInfo->name));
+
+ if (auto outerArrayName = systemValueInfo->outerArrayName)
+ {
+ builder->addGLSLOuterArrayDecoration(globalParam, UnownedTerminatedStringSlice(outerArrayName));
+ }
+
+ switch (systemValueInfo->kind)
+ {
+ case GLSLSystemValueKind::PositionOutput:
+ builder->addGLPositionOutputDecoration(globalParam);
+ break;
+ default:
+ break;
+ }
+ }
+}
+
ScalarizedVal createSimpleGLSLGlobalVarying(
GLSLLegalizationContext* context,
CodeGenContext* codeGenContext,
@@ -975,9 +1034,9 @@ ScalarizedVal createSimpleGLSLGlobalVarying(
{
// If declarator is set we have a problem, because we can't have an array of arrays
// so for now that's just an error
- if (kind != LayoutResourceKind::VaryingOutput)
+ if (kind != LayoutResourceKind::VaryingOutput && kind != LayoutResourceKind::VaryingInput)
{
- SLANG_ABORT_COMPILATION("Can't handle anything but VaryingOutput.");
+ SLANG_UNIMPLEMENTED_X("Can't handle anything but VaryingOutput and VaryingInput.");
}
// Let's see if it has been already created
@@ -1005,17 +1064,18 @@ ScalarizedVal createSimpleGLSLGlobalVarying(
type,
0);
- IRType* paramType = builder->getOutType(arrayType);
+ IRType* paramType = kind == LayoutResourceKind::VaryingOutput
+ ? (IRType*)builder->getOutType(arrayType)
+ : arrayType;
auto globalParam = addGlobalParam(builder->getModule(), paramType);
moveValueBefore(globalParam, builder->getFunc());
-
+
builder->addImportDecoration(globalParam, systemValueName);
- // We can't run layout here, because we don't actually no the size yet
- // We could run at the end though
+ createVarLayoutForLegalizedGlobalParam(
+ globalParam, builder, inVarLayout, inTypeLayout, kind, bindingIndex, bindingSpace, declarator, leafVar, systemValueInfo);
- //
semanticGlobalTmp.globalParam = globalParam;
semanticGlobal = &context->systemNameToGlobalMap.getOrAddValue(systemValueName, semanticGlobalTmp);
@@ -1107,18 +1167,6 @@ ScalarizedVal createSimpleGLSLGlobalVarying(
}
}
- // We need to construct a fresh layout for the variable, even
- // if the original had its own layout, because it might be
- // an `inout` parameter, and we only want to deal with the case
- // described by our `kind` parameter.
- //
- IRVarLayout::Builder varLayoutBuilder(builder, typeLayout);
- varLayoutBuilder.cloneEverythingButOffsetsFrom(inVarLayout);
- auto varOffsetInfo = varLayoutBuilder.findOrAddResourceInfo(kind);
- varOffsetInfo->offset = bindingIndex;
- varOffsetInfo->space = bindingSpace;
- IRVarLayout* varLayout = varLayoutBuilder.build();
-
// We are going to be creating a global parameter to replace
// the function parameter, but we need to handle the case
// where the parameter represents a varying *output* and not
@@ -1134,27 +1182,17 @@ ScalarizedVal createSimpleGLSLGlobalVarying(
auto globalParam = addGlobalParam(builder->getModule(), paramType);
moveValueBefore(globalParam, builder->getFunc());
- if( leafVar )
- {
- if( auto interpolationModeDecor = leafVar->findDecoration<IRInterpolationModeDecoration>() )
- {
- builder->addInterpolationModeDecoration(globalParam, interpolationModeDecor->getMode());
- }
- }
-
ScalarizedVal val = isOutput ? ScalarizedVal::address(globalParam) : ScalarizedVal::value(globalParam);
- if( systemValueInfo )
+ if (systemValueInfo)
{
- builder->addImportDecoration(globalParam, UnownedTerminatedStringSlice(systemValueInfo->name));
-
- if( auto fromType = systemValueInfo->requiredType )
+ if (auto fromType = systemValueInfo->requiredType)
{
// We may need to adapt from the declared type to/from
// the actual type of the GLSL global.
auto toType = inType;
- if( !isTypeEqual(fromType, toType ))
+ if (!isTypeEqual(fromType, toType))
{
RefPtr<ScalarizedTypeAdapterValImpl> typeAdapter = new ScalarizedTypeAdapterValImpl;
typeAdapter->actualType = systemValueInfo->requiredType;
@@ -1164,29 +1202,10 @@ ScalarizedVal createSimpleGLSLGlobalVarying(
val = ScalarizedVal::typeAdapter(typeAdapter);
}
}
-
- if(auto outerArrayName = systemValueInfo->outerArrayName)
- {
- builder->addGLSLOuterArrayDecoration(globalParam, UnownedTerminatedStringSlice(outerArrayName));
- }
-
- switch (systemValueInfo->kind)
- {
- case GLSLSystemValueKind::PositionOutput:
- builder->addGLPositionOutputDecoration(globalParam);
- break;
- default:
- break;
- }
}
- if(declarator && declarator->flavor == GlobalVaryingDeclarator::Flavor::meshOutputPrimitives)
- {
- builder->addDecoration(globalParam, kIROp_GLSLPrimitivesRateDecoration);
- }
-
- builder->addLayoutDecoration(globalParam, varLayout);
-
+ createVarLayoutForLegalizedGlobalParam(
+ globalParam, builder, inVarLayout, typeLayout, kind, bindingIndex, bindingSpace, declarator, leafVar, systemValueInfo);
return val;
}
@@ -1828,6 +1847,11 @@ IRInst* materializeValue(
}
break;
+ case ScalarizedVal::Flavor::arrayIndex:
+ {
+ auto element = builder->emitElementExtract(val.irValue, as<ScalarizedArrayIndexValImpl>(val.impl)->index);
+ return element;
+ }
case ScalarizedVal::Flavor::tuple:
{
//auto tupleVal = as<ScalarizedTupleValImpl>(val.impl);
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index ae008cebb..38ebcccd6 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -5287,11 +5287,17 @@ SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile()
{
res = executeActions();
}
- catch (const AbortCompilationException&)
+ catch (const AbortCompilationException& e)
{
// This situation indicates a fatal (but not necessarily internal) error
// that forced compilation to terminate. There should already have been
// a diagnostic produced, so we don't need to add one here.
+ if (getSink()->getErrorCount() == 0)
+ {
+ // If for some reason we didn't output any diagnostic, something is
+ // going wrong, but we want to make sure we at least output something.
+ getSink()->diagnose(SourceLoc(), Diagnostics::compilationAbortedDueToException, typeid(e).name(), e.Message);
+ }
}
catch (const Exception& e)
{