SpirV grammar parser: Add result id operand and version info
This commit is contained in:
parent
f694eb767f
commit
593d80c80e
|
|
@ -15,6 +15,8 @@ ACTION.Function = function()
|
||||||
|
|
||||||
print("Done")
|
print("Done")
|
||||||
|
|
||||||
|
io.write("Parsing... ")
|
||||||
|
|
||||||
local result, err = json.decode(content)
|
local result, err = json.decode(content)
|
||||||
assert(result, err)
|
assert(result, err)
|
||||||
|
|
||||||
|
|
@ -34,16 +36,26 @@ ACTION.Function = function()
|
||||||
local operandByInstruction = {}
|
local operandByInstruction = {}
|
||||||
for _, instruction in pairs(instructions) do
|
for _, instruction in pairs(instructions) do
|
||||||
if (instruction.operands) then
|
if (instruction.operands) then
|
||||||
|
local resultId
|
||||||
local firstId = #operands
|
local firstId = #operands
|
||||||
local operandCount = #instruction.operands
|
local operandCount = #instruction.operands
|
||||||
for _, operand in pairs(instruction.operands) do
|
for i, operand in pairs(instruction.operands) do
|
||||||
table.insert(operands, operand)
|
table.insert(operands, operand)
|
||||||
|
|
||||||
|
if (operand.kind == "IdResult") then
|
||||||
|
assert(not resultId, "unexpected operand with two IdResult")
|
||||||
|
resultId = i - 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
operandByInstruction[instruction.opcode] = { firstId = firstId, count = operandCount }
|
operandByInstruction[instruction.opcode] = { firstId = firstId, count = operandCount, resultId = resultId }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
print("Done")
|
||||||
|
|
||||||
|
io.write("Generating... ")
|
||||||
|
|
||||||
local headerFile = io.open("../include/Nazara/Shader/SpirvData.hpp", "w+")
|
local headerFile = io.open("../include/Nazara/Shader/SpirvData.hpp", "w+")
|
||||||
assert(headerFile, "failed to open Spir-V header")
|
assert(headerFile, "failed to open Spir-V header")
|
||||||
|
|
||||||
|
|
@ -65,6 +77,15 @@ ACTION.Function = function()
|
||||||
|
|
||||||
namespace Nz
|
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
|
-- SpirV operations
|
||||||
|
|
@ -155,6 +176,7 @@ headerFile:write([[
|
||||||
SpirvOp op;
|
SpirvOp op;
|
||||||
const char* name;
|
const char* name;
|
||||||
const Operand* operands;
|
const Operand* operands;
|
||||||
|
const Operand* resultOperand;
|
||||||
std::size_t minOperandCount;
|
std::size_t minOperandCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -210,12 +232,14 @@ namespace Nz
|
||||||
|
|
||||||
for _, instruction in pairs(instructions) do
|
for _, instruction in pairs(instructions) do
|
||||||
local opByInstruction = operandByInstruction[instruction.opcode]
|
local opByInstruction = operandByInstruction[instruction.opcode]
|
||||||
|
local resultId = opByInstruction and opByInstruction.resultId or nil
|
||||||
|
|
||||||
sourceFile:write([[
|
sourceFile:write([[
|
||||||
{
|
{
|
||||||
SpirvOp::]] .. instruction.opname .. [[,
|
SpirvOp::]] .. instruction.opname .. [[,
|
||||||
R"(]] .. instruction.opname .. [[)",
|
R"(]] .. instruction.opname .. [[)",
|
||||||
]] .. (opByInstruction and "&s_operands[" .. opByInstruction.firstId .. "]" or "nullptr") .. [[,
|
]] .. (opByInstruction and "&s_operands[" .. opByInstruction.firstId .. "]" or "nullptr") .. [[,
|
||||||
|
]] .. (resultId and "&s_operands[" .. opByInstruction.firstId + resultId .. "]" or "nullptr") .. [[,
|
||||||
]] .. (opByInstruction and opByInstruction.count or "0") .. [[,
|
]] .. (opByInstruction and opByInstruction.count or "0") .. [[,
|
||||||
},
|
},
|
||||||
]])
|
]])
|
||||||
|
|
@ -243,4 +267,5 @@ namespace Nz
|
||||||
}
|
}
|
||||||
]])
|
]])
|
||||||
|
|
||||||
|
print("Done")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,12 @@
|
||||||
|
|
||||||
namespace Nz
|
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
|
enum class SpirvOp
|
||||||
{
|
{
|
||||||
OpNop = 0,
|
OpNop = 0,
|
||||||
|
|
@ -442,6 +448,8 @@ namespace Nz
|
||||||
OpAsmCallINTEL = 5611,
|
OpAsmCallINTEL = 5611,
|
||||||
OpAtomicFMinEXT = 5614,
|
OpAtomicFMinEXT = 5614,
|
||||||
OpAtomicFMaxEXT = 5615,
|
OpAtomicFMaxEXT = 5615,
|
||||||
|
OpAssumeTrueKHR = 5630,
|
||||||
|
OpExpectKHR = 5631,
|
||||||
OpDecorateString = 5632,
|
OpDecorateString = 5632,
|
||||||
OpDecorateStringGOOGLE = 5632,
|
OpDecorateStringGOOGLE = 5632,
|
||||||
OpMemberDecorateString = 5633,
|
OpMemberDecorateString = 5633,
|
||||||
|
|
@ -1178,6 +1186,7 @@ namespace Nz
|
||||||
{
|
{
|
||||||
Export = 0,
|
Export = 0,
|
||||||
Import = 1,
|
Import = 1,
|
||||||
|
LinkOnceODR = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SpirvAccessQualifier
|
enum class SpirvAccessQualifier
|
||||||
|
|
@ -1636,6 +1645,7 @@ namespace Nz
|
||||||
AtomicFloat16MinMaxEXT = 5616,
|
AtomicFloat16MinMaxEXT = 5616,
|
||||||
VectorComputeINTEL = 5617,
|
VectorComputeINTEL = 5617,
|
||||||
VectorAnyINTEL = 5619,
|
VectorAnyINTEL = 5619,
|
||||||
|
ExpectAssumeKHR = 5629,
|
||||||
SubgroupAvcMotionEstimationINTEL = 5696,
|
SubgroupAvcMotionEstimationINTEL = 5696,
|
||||||
SubgroupAvcMotionEstimationIntraINTEL = 5697,
|
SubgroupAvcMotionEstimationIntraINTEL = 5697,
|
||||||
SubgroupAvcMotionEstimationChromaINTEL = 5698,
|
SubgroupAvcMotionEstimationChromaINTEL = 5698,
|
||||||
|
|
@ -1691,6 +1701,7 @@ namespace Nz
|
||||||
SpirvOp op;
|
SpirvOp op;
|
||||||
const char* name;
|
const char* name;
|
||||||
const Operand* operands;
|
const Operand* operands;
|
||||||
|
const Operand* resultOperand;
|
||||||
std::size_t minOperandCount;
|
std::size_t minOperandCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue