summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-09-01 01:25:31 -0700
committerGitHub <noreply@github.com>2023-09-01 01:25:31 -0700
commit9c11a87f8f811a9a110d73a24ab93443ea347506 (patch)
tree9b1b0f154cff0faf7efd8d77fcd7f7911aea4a44 /source
parentb7d19330c2d42937835d674758a05af3891e025b (diff)
Fix GLSL code gen around RayQuery and HitObject types. (#3173)
* Update slang-llvm. * Fix. * fix. * Fix unit tests for multi-thread execution. * Fix tests. * fixes. * update tests. * Add gfx-smoke to linux expected failure list. * Try fix test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/core/slang-process.h2
-rw-r--r--source/core/unix/slang-unix-process.cpp5
-rw-r--r--source/core/windows/slang-win-process.cpp6
-rw-r--r--source/slang/slang-check-decl.cpp33
-rw-r--r--source/slang/slang-check-overload.cpp5
-rw-r--r--source/slang/slang-emit-glsl.cpp3
-rw-r--r--source/slang/slang-ir-inline.cpp2
-rw-r--r--source/slang/slang-ir-lower-buffer-element-type.cpp65
-rw-r--r--source/slang/slang-ir-specialize-resources.cpp4
9 files changed, 86 insertions, 39 deletions
diff --git a/source/core/slang-process.h b/source/core/slang-process.h
index 0beb78c06..c36064ac3 100644
--- a/source/core/slang-process.h
+++ b/source/core/slang-process.h
@@ -73,6 +73,8 @@ public:
/// Get the clock tick.
static uint64_t getClockTick();
+ static uint32_t getId();
+
protected:
int32_t m_returnValue = 0; ///< Value returned if process terminated
RefPtr<Stream> m_streams[Index(StdStreamType::CountOf)]; ///< Streams to communicate with the process
diff --git a/source/core/unix/slang-unix-process.cpp b/source/core/unix/slang-unix-process.cpp
index 428bef874..3ab113d83 100644
--- a/source/core/unix/slang-unix-process.cpp
+++ b/source/core/unix/slang-unix-process.cpp
@@ -649,4 +649,9 @@ closePipes:
return SLANG_OK;
}
+uint32_t Process::getId()
+{
+ return getpid();
+}
+
} // namespace Slang
diff --git a/source/core/windows/slang-win-process.cpp b/source/core/windows/slang-win-process.cpp
index e577da0fa..38f733015 100644
--- a/source/core/windows/slang-win-process.cpp
+++ b/source/core/windows/slang-win-process.cpp
@@ -561,4 +561,10 @@ static const uint64_t g_frequency = _getClockFrequency();
return counter.QuadPart;
}
+uint32_t Process::getId()
+{
+ return _getpid();
+}
+
+
} // namespace Slang
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index f25821dac..76ab8655a 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -5615,6 +5615,39 @@ namespace Slang
paramDecl->type = typeExpr;
checkMeshOutputDecl(paramDecl);
}
+
+ if (auto declRefType = as<DeclRefType>(paramDecl->type.type))
+ {
+ if (declRefType->getDeclRef().getDecl()->findModifier<NonCopyableTypeAttribute>())
+ {
+ // Always pass a non-copyable type by reference.
+ // Remove all existing direction modifiers, and replace them with a single Ref modifier.
+ List<Modifier*> newModifiers;
+ bool hasRefModifier = false;
+ for (auto modifier : paramDecl->modifiers)
+ {
+ if (as<InModifier>(modifier) || as<InOutModifier>(modifier) || as<OutModifier>(modifier))
+ {
+ continue;
+ }
+ if (as<RefModifier>(modifier))
+ {
+ hasRefModifier = true;
+ }
+ newModifiers.add(modifier);
+ }
+ if (!hasRefModifier)
+ newModifiers.add(this->getASTBuilder()->create<RefModifier>());
+ paramDecl->modifiers.first = newModifiers.getFirst();
+ for (Index i = 0; i < newModifiers.getCount(); i++)
+ {
+ if (i < newModifiers.getCount() - 1)
+ newModifiers[i]->next = newModifiers[i + 1];
+ else
+ newModifiers[i]->next = nullptr;
+ }
+ }
+ }
}
// This checks that the declaration is marked as "out" and changes the hlsl
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index c13e74f69..50da2d3eb 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -508,10 +508,11 @@ namespace Slang
return nullptr;
}
- if (paramDeclRef.getDecl()->findModifier<OutModifier>())
+ if (paramDeclRef.getDecl()->findModifier<OutModifier>() ||
+ paramDeclRef.getDecl()->findModifier<RefModifier>())
{
// Function parameters marked with `out`, `inout`,
- // or `in out` are all mutable in a way where
+ // `in out` or `ref` are all mutable in a way where
// the result of mutations will be visible to the
// caller.
//
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index 3cde9f467..c651c8735 100644
--- a/source/slang/slang-emit-glsl.cpp
+++ b/source/slang/slang-emit-glsl.cpp
@@ -2204,6 +2204,7 @@ void GLSLSourceEmitter::emitTypeImpl(IRType* type, const StringSliceLoc* nameAnd
{
if (auto refType = as<IRRefType>(type))
{
+ _requireGLSLExtension(UnownedStringSlice("GL_EXT_spirv_intrinsics"));
m_writer->emit("spirv_by_reference ");
type = refType->getValueType();
}
@@ -2214,11 +2215,13 @@ void GLSLSourceEmitter::emitParamTypeImpl(IRType* type, String const& name)
{
if (auto refType = as<IRRefType>(type))
{
+ _requireGLSLExtension(UnownedStringSlice("GL_EXT_spirv_intrinsics"));
m_writer->emit("spirv_by_reference ");
type = refType->getValueType();
}
else if (auto spirvLiteralType = as<IRSPIRVLiteralType>(type))
{
+ _requireGLSLExtension(UnownedStringSlice("GL_EXT_spirv_intrinsics"));
m_writer->emit("spirv_literal ");
type = spirvLiteralType->getValueType();
}
diff --git a/source/slang/slang-ir-inline.cpp b/source/slang/slang-ir-inline.cpp
index fd9ec495b..5479a98ff 100644
--- a/source/slang/slang-ir-inline.cpp
+++ b/source/slang/slang-ir-inline.cpp
@@ -861,8 +861,6 @@ struct GLSLResourceReturnFunctionInliningPass : InliningPassBase
auto outValueType = outType->getValueType();
if (isResourceType(outValueType))
return true;
- if (isIllegalGLSLParameterType(outValueType))
- return true;
}
return false;
}
diff --git a/source/slang/slang-ir-lower-buffer-element-type.cpp b/source/slang/slang-ir-lower-buffer-element-type.cpp
index bc8e47e91..af25cacd0 100644
--- a/source/slang/slang-ir-lower-buffer-element-type.cpp
+++ b/source/slang/slang-ir-lower-buffer-element-type.cpp
@@ -403,43 +403,46 @@ namespace Slang
return info;
}
- switch (target->getTarget())
+ if (target->shouldEmitSPIRVDirectly())
{
- case CodeGenTarget::SPIRV:
- case CodeGenTarget::SPIRVAssembly:
- if (as<IRBoolType>(type))
+ switch (target->getTarget())
{
- // Bool is an abstract type in SPIRV, so we need to lower them into an int.
- info.loweredType = builder.getIntType();
- // Create unpack func.
+ case CodeGenTarget::SPIRV:
+ case CodeGenTarget::SPIRVAssembly:
+ if (as<IRBoolType>(type))
{
- builder.setInsertAfter(type);
- info.convertLoweredToOriginal = builder.createFunc();
- builder.setInsertInto(info.convertLoweredToOriginal);
- builder.addNameHintDecoration(info.convertLoweredToOriginal, UnownedStringSlice("unpackStorage"));
- info.convertLoweredToOriginal->setFullType(builder.getFuncType(1, (IRType**)&info.loweredType, type));
- builder.emitBlock();
- auto loweredParam = builder.emitParam(info.loweredType);
- auto result = builder.emitCast(type, loweredParam);
- builder.emitReturn(result);
- }
+ // Bool is an abstract type in SPIRV, so we need to lower them into an int.
+ info.loweredType = builder.getIntType();
+ // Create unpack func.
+ {
+ builder.setInsertAfter(type);
+ info.convertLoweredToOriginal = builder.createFunc();
+ builder.setInsertInto(info.convertLoweredToOriginal);
+ builder.addNameHintDecoration(info.convertLoweredToOriginal, UnownedStringSlice("unpackStorage"));
+ info.convertLoweredToOriginal->setFullType(builder.getFuncType(1, (IRType**)&info.loweredType, type));
+ builder.emitBlock();
+ auto loweredParam = builder.emitParam(info.loweredType);
+ auto result = builder.emitCast(type, loweredParam);
+ builder.emitReturn(result);
+ }
- // Create pack func.
- {
- builder.setInsertAfter(info.convertLoweredToOriginal);
- info.convertOriginalToLowered = builder.createFunc();
- builder.setInsertInto(info.convertOriginalToLowered);
- builder.addNameHintDecoration(info.convertOriginalToLowered, UnownedStringSlice("packStorage"));
- info.convertOriginalToLowered->setFullType(builder.getFuncType(1, (IRType**)&type, info.loweredType));
- builder.emitBlock();
- auto param = builder.emitParam(type);
- auto result = builder.emitCast(info.loweredType, param);
- builder.emitReturn(result);
+ // Create pack func.
+ {
+ builder.setInsertAfter(info.convertLoweredToOriginal);
+ info.convertOriginalToLowered = builder.createFunc();
+ builder.setInsertInto(info.convertOriginalToLowered);
+ builder.addNameHintDecoration(info.convertOriginalToLowered, UnownedStringSlice("packStorage"));
+ info.convertOriginalToLowered->setFullType(builder.getFuncType(1, (IRType**)&type, info.loweredType));
+ builder.emitBlock();
+ auto param = builder.emitParam(type);
+ auto result = builder.emitCast(info.loweredType, param);
+ builder.emitReturn(result);
+ }
}
+ break;
+ default:
+ break;
}
- break;
- default:
- break;
}
info.loweredType = type;
diff --git a/source/slang/slang-ir-specialize-resources.cpp b/source/slang/slang-ir-specialize-resources.cpp
index 839e5e08e..620c4e508 100644
--- a/source/slang/slang-ir-specialize-resources.cpp
+++ b/source/slang/slang-ir-specialize-resources.cpp
@@ -1228,10 +1228,6 @@ bool isIllegalGLSLParameterType(IRType* type)
}
if (as<IRMeshOutputType>(type))
return true;
- if (as<IRRayQueryType>(type))
- return true;
- if (as<IRHitObjectType>(type))
- return true;
return false;
}