summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-spirv.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-10-02 03:33:58 -0700
committerGitHub <noreply@github.com>2023-10-02 18:33:58 +0800
commitccf2611c024ab12dcccd978f3f501d4ee9fc52bc (patch)
treef4df843e3b46886005d6bfbae34dc3bcc6fb8321 /source/slang/slang-emit-spirv.cpp
parent6138de5f084cafdc98381237c2d8bed7c8804f1c (diff)
Add SPIRV intrinsics for ShaderExecutionReordering and RW/Buffer. (#3252)
* Add SPIRV intrinsics for ShaderExecutionReordering. * Add intrinsics for `Buffer` and `RWBuffer`. * Various spirv fixes. * Marshal bool vector type. * Inline global constants + OpFOrdNotEqual->OpFUnordNotEqual. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index 6bd781e62..104fab339 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -1378,6 +1378,11 @@ struct SPIRVEmitContext
requireSPIRVCapability(SpvCapabilityRayQueryKHR);
return emitOpTypeRayQuery(inst);
+ case kIROp_HitObjectType:
+ ensureExtensionDeclaration(UnownedStringSlice("SPV_NV_shader_invocation_reorder"));
+ requireSPIRVCapability(SpvCapabilityShaderInvocationReorderNV);
+ return emitOpTypeHitObject(inst);
+
case kIROp_FuncType:
// > OpTypeFunction
//
@@ -2263,6 +2268,12 @@ struct SPIRVEmitContext
case kIROp_Rsh:
case kIROp_Lsh:
return emitArithmetic(parent, inst);
+ case kIROp_GlobalValueRef:
+ {
+ auto inner = ensureInst(inst->getOperand(0));
+ registerInst(inst, inner);
+ return inner;
+ }
case kIROp_Return:
if (as<IRReturn>(inst)->getVal()->getOp() == kIROp_VoidLit)
return emitOpReturn(parent, inst);
@@ -3938,14 +3949,33 @@ struct SPIRVEmitContext
SLANG_ASSERT(!as<IRVectorType>(fromTypeV) == !as<IRVectorType>(toTypeV));
const auto fromType = dropVector(fromTypeV);
const auto toType = dropVector(toTypeV);
- SLANG_ASSERT(isIntegralType(fromType));
SLANG_ASSERT(isFloatingType(toType));
- const auto fromInfo = getIntTypeInfo(fromType);
+ if (isIntegralType(fromType))
+ {
+ const auto fromInfo = getIntTypeInfo(fromType);
- return fromInfo.isSigned
- ? emitOpConvertSToF(parent, inst, toTypeV, inst->getOperand(0))
- : emitOpConvertUToF(parent, inst, toTypeV, inst->getOperand(0));
+ return fromInfo.isSigned
+ ? emitOpConvertSToF(parent, inst, toTypeV, inst->getOperand(0))
+ : emitOpConvertUToF(parent, inst, toTypeV, inst->getOperand(0));
+ }
+ else if (as<IRBoolType>(fromType))
+ {
+ IRBuilder builder(inst);
+ builder.setInsertBefore(inst);
+ auto one = builder.getFloatValue(toType, 1.0f);
+ auto zero = builder.getFloatValue(toType, 0.0f);
+ if (as<IRVectorType>(toTypeV))
+ {
+ one = builder.emitMakeVectorFromScalar(toTypeV, one);
+ zero = builder.emitMakeVectorFromScalar(toTypeV, zero);
+ }
+ return emitInst(parent, inst, SpvOpSelect, inst->getFullType(), kResultID, inst->getOperand(0), one, zero);
+ }
+ else
+ {
+ SLANG_UNREACHABLE("unknown from type");
+ }
}
SpvInst* emitFloatToIntCast(SpvInstParent* parent, IRCastFloatToInt* inst)
@@ -4206,7 +4236,7 @@ struct SPIRVEmitContext
opCode = isFloatingPoint ? SpvOpFOrdEqual : isBool ? SpvOpLogicalEqual : SpvOpIEqual;
break;
case kIROp_Neq:
- opCode = isFloatingPoint ? SpvOpFOrdNotEqual
+ opCode = isFloatingPoint ? SpvOpFUnordNotEqual
: isBool ? SpvOpLogicalNotEqual : SpvOpINotEqual;
break;
case kIROp_Geq: