SpirV grammar parser: Add result id operand and version info

This commit is contained in:
Jérôme Leclercq 2021-03-13 15:59:41 +01:00
parent f694eb767f
commit 593d80c80e
3 changed files with 800 additions and 156 deletions

View File

@ -15,6 +15,8 @@ ACTION.Function = function()
print("Done")
io.write("Parsing... ")
local result, err = json.decode(content)
assert(result, err)
@ -34,16 +36,26 @@ ACTION.Function = function()
local operandByInstruction = {}
for _, instruction in pairs(instructions) do
if (instruction.operands) then
local resultId
local firstId = #operands
local operandCount = #instruction.operands
for _, operand in pairs(instruction.operands) do
for i, operand in pairs(instruction.operands) do
table.insert(operands, operand)
if (operand.kind == "IdResult") then
assert(not resultId, "unexpected operand with two IdResult")
resultId = i - 1
end
end
operandByInstruction[instruction.opcode] = { firstId = firstId, count = operandCount }
operandByInstruction[instruction.opcode] = { firstId = firstId, count = operandCount, resultId = resultId }
end
end
print("Done")
io.write("Generating... ")
local headerFile = io.open("../include/Nazara/Shader/SpirvData.hpp", "w+")
assert(headerFile, "failed to open Spir-V header")
@ -65,6 +77,15 @@ ACTION.Function = function()
namespace Nz
{
]])
headerFile:write([[
constexpr UInt32 SpirvMagicNumber = ]] .. result.magic_number .. [[;
constexpr UInt32 SpirvMajorVersion = ]] .. result.major_version .. [[;
constexpr UInt32 SpirvMinorVersion = ]] .. result.minor_version .. [[;
constexpr UInt32 SpirvRevision = ]] .. result.revision .. [[;
constexpr UInt32 SpirvVersion = (SpirvMajorVersion << 16) | (SpirvMinorVersion << 8);
]])
-- SpirV operations
@ -155,6 +176,7 @@ headerFile:write([[
SpirvOp op;
const char* name;
const Operand* operands;
const Operand* resultOperand;
std::size_t minOperandCount;
};
@ -210,12 +232,14 @@ namespace Nz
for _, instruction in pairs(instructions) do
local opByInstruction = operandByInstruction[instruction.opcode]
local resultId = opByInstruction and opByInstruction.resultId or nil
sourceFile:write([[
{
SpirvOp::]] .. instruction.opname .. [[,
R"(]] .. instruction.opname .. [[)",
]] .. (opByInstruction and "&s_operands[" .. opByInstruction.firstId .. "]" or "nullptr") .. [[,
]] .. (resultId and "&s_operands[" .. opByInstruction.firstId + resultId .. "]" or "nullptr") .. [[,
]] .. (opByInstruction and opByInstruction.count or "0") .. [[,
},
]])
@ -243,4 +267,5 @@ namespace Nz
}
]])
print("Done")
end

View File

@ -15,6 +15,12 @@
namespace Nz
{
constexpr UInt32 SpirvMagicNumber = 0x07230203;
constexpr UInt32 SpirvMajorVersion = 1;
constexpr UInt32 SpirvMinorVersion = 5;
constexpr UInt32 SpirvRevision = 4;
constexpr UInt32 SpirvVersion = (SpirvMajorVersion << 16) | (SpirvMinorVersion << 8);
enum class SpirvOp
{
OpNop = 0,
@ -442,6 +448,8 @@ namespace Nz
OpAsmCallINTEL = 5611,
OpAtomicFMinEXT = 5614,
OpAtomicFMaxEXT = 5615,
OpAssumeTrueKHR = 5630,
OpExpectKHR = 5631,
OpDecorateString = 5632,
OpDecorateStringGOOGLE = 5632,
OpMemberDecorateString = 5633,
@ -1178,6 +1186,7 @@ namespace Nz
{
Export = 0,
Import = 1,
LinkOnceODR = 2,
};
enum class SpirvAccessQualifier
@ -1636,6 +1645,7 @@ namespace Nz
AtomicFloat16MinMaxEXT = 5616,
VectorComputeINTEL = 5617,
VectorAnyINTEL = 5619,
ExpectAssumeKHR = 5629,
SubgroupAvcMotionEstimationINTEL = 5696,
SubgroupAvcMotionEstimationIntraINTEL = 5697,
SubgroupAvcMotionEstimationChromaINTEL = 5698,
@ -1691,6 +1701,7 @@ namespace Nz
SpirvOp op;
const char* name;
const Operand* operands;
const Operand* resultOperand;
std::size_t minOperandCount;
};

File diff suppressed because it is too large Load Diff