From 0e28cd02710e6a8e989e89fd1f9b4ebf85892f99 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 8 Aug 2023 06:02:29 +0800 Subject: Unify Type and Constant sections for SPIR-V (#3057) Types can depend on constants (for example fixed sized arrays) Co-authored-by: Yong He --- source/slang/slang-emit-spirv.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index b6e1d15c0..1386de4eb 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -78,8 +78,7 @@ enum class SpvLogicalSectionID DebugStringsAndSource, DebugNames, Annotations, - Types, - Constants, + ConstantsAndTypes, GlobalVariables, FunctionDeclarations, FunctionDefinitions, @@ -719,7 +718,7 @@ struct SPIRVEmitContext SpvWord valHighWord; memcpy(&valHighWord, (char*)(&val) + 4, sizeof(SpvWord)); result = emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), nullptr, SpvOpConstant, type, @@ -731,7 +730,7 @@ struct SPIRVEmitContext default: { result = emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), nullptr, SpvOpConstant, type, @@ -758,7 +757,7 @@ struct SPIRVEmitContext SpvWord valHighWord; memcpy(&valHighWord, (char*)(&val) + 4, sizeof(SpvWord)); result = emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), nullptr, SpvOpConstant, type, @@ -769,7 +768,7 @@ struct SPIRVEmitContext else { result = emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), nullptr, SpvOpConstant, type, @@ -997,7 +996,7 @@ struct SPIRVEmitContext return result; } result = emitInstCustomOperandFunc( - getSection(SpvLogicalSectionID::Types), typeInst, opcode, [&]() { + getSection(SpvLogicalSectionID::ConstantsAndTypes), typeInst, opcode, [&]() { emitOperand(kResultID); for (auto op : operands) { @@ -1081,7 +1080,7 @@ struct SPIRVEmitContext case kIROp_StructType: { auto spvStructType = emitInstCustomOperandFunc( - getSection(SpvLogicalSectionID::Types), inst, SpvOpTypeStruct, [&]() { + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpTypeStruct, [&]() { emitOperand(kResultID); for (auto field : static_cast(inst)->getFields()) { @@ -1108,7 +1107,7 @@ struct SPIRVEmitContext static_cast(matrixType->getRowCount())->getValue(), nullptr); auto matrixSPVType = emitInst( - getSection(SpvLogicalSectionID::Types), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpTypeMatrix, kResultID, @@ -1146,7 +1145,7 @@ struct SPIRVEmitContext { auto elementType = static_cast(inst)->getElementType(); auto runtimeArrayType = emitInst( - getSection(SpvLogicalSectionID::Types), + getSection(SpvLogicalSectionID::ConstantsAndTypes), nullptr, SpvOpTypeRuntimeArray, kResultID, @@ -1177,7 +1176,7 @@ struct SPIRVEmitContext // with the result-type operand coming first, // followed by operand sfor all the parameter types. // - return emitInst(getSection(SpvLogicalSectionID::Types), inst, SpvOpTypeFunction, kResultID, OperandsOf(inst)); + return emitInst(getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpTypeFunction, kResultID, OperandsOf(inst)); case kIROp_RateQualifiedType: { @@ -1765,7 +1764,7 @@ struct SPIRVEmitContext case BaseType::IntPtr: case BaseType::UIntPtr: return emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpConstant, inst->getDataType(), @@ -1774,7 +1773,7 @@ struct SPIRVEmitContext (SpvWord)((value >> 32) & 0xFFFFFFFF)); default: return emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpConstant, inst->getDataType(), @@ -1789,7 +1788,7 @@ struct SPIRVEmitContext { case BaseType::Half: return emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpConstant, inst->getDataType(), @@ -1797,7 +1796,7 @@ struct SPIRVEmitContext (SpvWord)(FloatToHalf((float)value))); case BaseType::Float: return emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpConstant, inst->getDataType(), @@ -1807,7 +1806,7 @@ struct SPIRVEmitContext { auto ival = DoubleAsInt64(value); return emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpConstant, inst->getDataType(), @@ -1824,7 +1823,7 @@ struct SPIRVEmitContext if (as(inst)->getValue()) { return emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpConstantTrue, inst->getDataType(), @@ -1833,7 +1832,7 @@ struct SPIRVEmitContext else { return emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), inst, SpvOpConstantFalse, inst->getDataType(), @@ -2301,7 +2300,7 @@ struct SPIRVEmitContext auto element1 = emitFloatConstant(constant.floatValues[0], floatType); auto element2 = emitFloatConstant(constant.floatValues[1], floatType); result = emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), nullptr, SpvOpConstantComposite, builder.getVectorType(floatType, builder.getIntValue(builder.getIntType(), 2)), @@ -2319,7 +2318,7 @@ struct SPIRVEmitContext auto element1 = emitIntConstant((IRIntegerValue)constant.intValues[0], uintType); auto element2 = emitIntConstant((IRIntegerValue)constant.intValues[1], uintType); result = emitInst( - getSection(SpvLogicalSectionID::Constants), + getSection(SpvLogicalSectionID::ConstantsAndTypes), nullptr, SpvOpConstantComposite, builder.getVectorType(uintType, builder.getIntValue(builder.getIntType(), 2)), -- cgit v1.2.3