summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/hlsl.meta.slang5
-rw-r--r--source/slang/slang-emit-c-like.cpp2
-rw-r--r--source/slang/slang-ir-inst-defs.h6
-rw-r--r--source/slang/slang-ir-ssa.cpp13
-rw-r--r--source/slang/slang-ir.cpp1
-rw-r--r--source/slang/slang-type-layout.cpp11
6 files changed, 38 insertions, 0 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 8a7c3a010..69fc6bea0 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -4041,6 +4041,11 @@ static const CANDIDATE_TYPE CANDIDATE_PROCEDURAL_PRIMITIVE = 1;
__target_intrinsic(hlsl, RayQuery)
struct RayQuery <let rayFlags : RAY_FLAG = RAY_FLAG_NONE>
{
+ // Initialize the query object in a "fresh" state.
+ //
+ __intrinsic_op($(kIROp_DefaultConstruct))
+ __init();
+
// Initialize a ray-tracing query.
//
// This method may be called on a "fresh" ray query, or
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 4c6c89ef5..a7637a63e 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -2037,6 +2037,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
break;
case kIROp_undefined:
+ case kIROp_DefaultConstruct:
m_writer->emit(getName(inst));
break;
@@ -2464,6 +2465,7 @@ void CLikeSourceEmitter::_emitInst(IRInst* inst)
break;
case kIROp_undefined:
+ case kIROp_DefaultConstruct:
{
auto type = inst->getDataType();
emitType(type, getName(inst));
diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h
index e01121d36..ca3ca6dae 100644
--- a/source/slang/slang-ir-inst-defs.h
+++ b/source/slang/slang-ir-inst-defs.h
@@ -216,6 +216,12 @@ INST_RANGE(Constant, BoolLit, StringLit)
INST(undefined, undefined, 0, 0)
+// A `defaultConstruct` operation creates an initialized
+// value of the result type, and can only be used for types
+// where default construction is a meaningful thing to do.
+//
+INST(DefaultConstruct, defaultConstruct, 0, 0)
+
INST(Specialize, specialize, 2, 0)
INST(lookup_interface_method, lookup_interface_method, 2, 0)
INST(lookup_witness_table, lookup_witness_table, 2, 0)
diff --git a/source/slang/slang-ir-ssa.cpp b/source/slang/slang-ir-ssa.cpp
index 19f85eaa9..7c849e36a 100644
--- a/source/slang/slang-ir-ssa.cpp
+++ b/source/slang/slang-ir-ssa.cpp
@@ -776,6 +776,19 @@ IRInst* readVar(
return val;
}
+ if( blockInfo->block == var->parent )
+ {
+ // If this is the block that actually *introduces*
+ // the variable, then there is no reason to keep
+ // searching, because its value cannot have been
+ // established in a predecessor block.
+ //
+ auto type = var->getDataType()->getValueType();
+ val = blockInfo->builder.emitUndefined(type);
+ writeVar(context, blockInfo, var, val);
+ return val;
+ }
+
// Otherwise we need to try to non-trivial/recursive
// case of lookup.
return readVarRec(context, blockInfo, var);
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index a5e0de0c5..32034fec8 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -5171,6 +5171,7 @@ namespace Slang
case kIROp_Nop:
case kIROp_undefined:
+ case kIROp_DefaultConstruct:
case kIROp_Specialize:
case kIROp_lookup_interface_method:
case kIROp_getAddr:
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp
index b01b275f9..8b4c80554 100644
--- a/source/slang/slang-type-layout.cpp
+++ b/source/slang/slang-type-layout.cpp
@@ -3641,6 +3641,17 @@ static TypeLayoutResult _createTypeLayout(
return TypeLayoutResult(typeLayout, SimpleLayoutInfo());
}
+ else if( auto enumDeclRef = declRef.as<EnumDecl>() )
+ {
+ // We lay out an enumeration type as its tag type.
+ //
+ // TODO: This code doesn't handle the case where we might
+ // have a generic `enum` (or an `enum` inside another generic
+ // type), and where the tag type of the `enum` depends on
+ // one or more of the generic parameters.
+ //
+ return _createTypeLayout(context, enumDeclRef.getDecl()->tagType);
+ }
}
else if (auto errorType = as<ErrorType>(type))
{