|
@@ -175,29 +175,43 @@ void Translator::createStageIOVariables(
|
|
// Translate DXIL input signature to SPIR-V stage input vars.
|
|
// Translate DXIL input signature to SPIR-V stage input vars.
|
|
for (const std::unique_ptr<hlsl::DxilSignatureElement> &elem :
|
|
for (const std::unique_ptr<hlsl::DxilSignatureElement> &elem :
|
|
inputSignature) {
|
|
inputSignature) {
|
|
- clang::spirv::SpirvVariable *var = spvBuilder.addStageIOVar(
|
|
|
|
- toSpirvType(elem.get()), spv::StorageClass::Input,
|
|
|
|
- elem->GetSemanticName(), false, {});
|
|
|
|
- unsigned id = elem->GetID();
|
|
|
|
- interfaceVars.push_back(var);
|
|
|
|
- inputSignatureElementMap[id] = var;
|
|
|
|
-
|
|
|
|
- // Use unique DXIL signature element ID as SPIR-V Location.
|
|
|
|
- spvBuilder.decorateLocation(var, id);
|
|
|
|
|
|
+ createStageIOVariable(elem.get());
|
|
}
|
|
}
|
|
|
|
|
|
// Translate DXIL input signature to SPIR-V stage ouput vars.
|
|
// Translate DXIL input signature to SPIR-V stage ouput vars.
|
|
for (const std::unique_ptr<hlsl::DxilSignatureElement> &elem :
|
|
for (const std::unique_ptr<hlsl::DxilSignatureElement> &elem :
|
|
outputSignature) {
|
|
outputSignature) {
|
|
- clang::spirv::SpirvVariable *var = spvBuilder.addStageIOVar(
|
|
|
|
- toSpirvType(elem.get()), spv::StorageClass::Output,
|
|
|
|
- elem->GetSemanticName(), false, {});
|
|
|
|
- unsigned id = elem->GetID();
|
|
|
|
- interfaceVars.push_back(var);
|
|
|
|
- outputSignatureElementMap[id] = var;
|
|
|
|
|
|
+ createStageIOVariable(elem.get());
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Translator::createStageIOVariable(hlsl::DxilSignatureElement *elem) {
|
|
|
|
+ const spirv::SpirvType *spirvType = toSpirvType(elem);
|
|
|
|
+ spv::StorageClass storageClass =
|
|
|
|
+ elem->IsInput() ? spv::StorageClass::Input : spv::StorageClass::Output;
|
|
|
|
+ const unsigned id = elem->GetID();
|
|
|
|
+ spirv::SpirvVariable *var = nullptr;
|
|
|
|
+ switch (elem->GetKind()) {
|
|
|
|
+ case hlsl::Semantic::Kind::Position: {
|
|
|
|
+ var = spvBuilder.addStageBuiltinVar(spirvType, storageClass,
|
|
|
|
+ spv::BuiltIn::Position, false, {});
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ default: {
|
|
|
|
+ var = spvBuilder.addStageIOVar(spirvType, storageClass,
|
|
|
|
+ elem->GetSemanticName(), false, {});
|
|
|
|
|
|
// Use unique DXIL signature element ID as SPIR-V Location.
|
|
// Use unique DXIL signature element ID as SPIR-V Location.
|
|
spvBuilder.decorateLocation(var, id);
|
|
spvBuilder.decorateLocation(var, id);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ interfaceVars.push_back(var);
|
|
|
|
+
|
|
|
|
+ if (storageClass == spv::StorageClass::Input) {
|
|
|
|
+ inputSignatureElementMap[id] = var;
|
|
|
|
+ } else {
|
|
|
|
+ outputSignatureElementMap[id] = var;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -264,26 +278,33 @@ void Translator::createInstruction(llvm::Instruction &instruction) {
|
|
switch (dxilOpcode) {
|
|
switch (dxilOpcode) {
|
|
case hlsl::DXIL::OpCode::LoadInput: {
|
|
case hlsl::DXIL::OpCode::LoadInput: {
|
|
createLoadInputInstruction(callInstruction);
|
|
createLoadInputInstruction(callInstruction);
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
case hlsl::DXIL::OpCode::StoreOutput: {
|
|
case hlsl::DXIL::OpCode::StoreOutput: {
|
|
createStoreOutputInstruction(callInstruction);
|
|
createStoreOutputInstruction(callInstruction);
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
case hlsl::DXIL::OpCode::ThreadId: {
|
|
case hlsl::DXIL::OpCode::ThreadId: {
|
|
createThreadIdInstruction(callInstruction);
|
|
createThreadIdInstruction(callInstruction);
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
case hlsl::DXIL::OpCode::CreateHandle: {
|
|
case hlsl::DXIL::OpCode::CreateHandle: {
|
|
createHandleInstruction(callInstruction);
|
|
createHandleInstruction(callInstruction);
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
case hlsl::DXIL::OpCode::BufferLoad: {
|
|
case hlsl::DXIL::OpCode::BufferLoad: {
|
|
createBufferLoadInstruction(callInstruction);
|
|
createBufferLoadInstruction(callInstruction);
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
case hlsl::DXIL::OpCode::BufferStore: {
|
|
case hlsl::DXIL::OpCode::BufferStore: {
|
|
createBufferStoreInstruction(callInstruction);
|
|
createBufferStoreInstruction(callInstruction);
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
default: {
|
|
default: {
|
|
emitError("Unhandled DXIL opcode: %0")
|
|
emitError("Unhandled DXIL opcode: %0")
|
|
<< hlsl::OP::GetOpCodeName(dxilOpcode);
|
|
<< hlsl::OP::GetOpCodeName(dxilOpcode);
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Handle binary operator instructions.
|
|
// Handle binary operator instructions.
|
|
@@ -415,7 +436,8 @@ void Translator::createBinaryOpInstruction(llvm::BinaryOperator &instruction) {
|
|
|
|
|
|
result = spvBuilder.createBinaryOp(spv::Op::OpShiftLeftLogical, uint32, val,
|
|
result = spvBuilder.createBinaryOp(spv::Op::OpShiftLeftLogical, uint32, val,
|
|
spvShift, {});
|
|
spvShift, {});
|
|
- } break;
|
|
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
default: {
|
|
default: {
|
|
emitError("Unhandled LLVM binary opcode: %0") << opcode;
|
|
emitError("Unhandled LLVM binary opcode: %0") << opcode;
|
|
return;
|
|
return;
|