Spir-V WIP.

This commit is contained in:
Branimir Karadžić 2016-03-05 00:17:06 -08:00
parent 5fab86f3ef
commit e14c5b1c3e
8 changed files with 909 additions and 613 deletions

View file

@ -3728,8 +3728,9 @@ BX_PRAGMA_DIAGNOSTIC_POP();
{
bx::MemoryReader rd(_code, _size);
bx::Error err;
DxbcContext dxbc;
read(&rd, dxbc);
read(&rd, dxbc, &err);
struct FindDepthOp
{

View file

@ -2238,7 +2238,8 @@ data.NumQualityLevels = 0;
bx::StaticMemoryBlockWriter wr(temp->data, temp->size);
DxbcContext dxbc;
read(&rd, dxbc);
bx::Error err;
read(&rd, dxbc, &err);
bool patchShader = true;
if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
@ -2246,7 +2247,7 @@ data.NumQualityLevels = 0;
union { uint32_t offset; void* ptr; } cast = { 0 };
filter(dxbc.shader, dxbc.shader, patchCb0, cast.ptr);
write(&wr, dxbc);
write(&wr, dxbc, &err);
dxbcHash(temp->data + 20, temp->size - 20, temp->data + 4);
@ -2280,7 +2281,7 @@ data.NumQualityLevels = 0;
uint32_t(program.m_vsh->m_size)/16
};
filter(dxbc.shader, dxbc.shader, patchCb0, cast.ptr);
write(&wr, dxbc);
write(&wr, dxbc, &err);
dxbcHash(temp->data + 20, temp->size - 20, temp->data + 4);
desc.PS.pShaderBytecode = temp->data;

View file

@ -274,12 +274,12 @@ namespace bgfx
};
BX_STATIC_ASSERT(BX_COUNTOF(s_dx9bcDeclUsage) == Dx9bcDeclUsage::Count);
int32_t read(bx::ReaderI* _reader, Dx9bcSubOperand& _subOperand)
int32_t read(bx::ReaderI* _reader, Dx9bcSubOperand& _subOperand, bx::Error* _err)
{
int32_t size = 0;
uint32_t token;
size += bx::read(_reader, token);
size += bx::read(_reader, token, _err);
_subOperand.type = Dx9bcOperandType::Enum( ( (token & UINT32_C(0x70000000) ) >> 28)
| ( (token & UINT32_C(0x00001800) ) >> 8) );
@ -289,7 +289,7 @@ namespace bgfx
return size;
}
int32_t write(bx::WriterI* _writer, const Dx9bcSubOperand& _subOperand)
int32_t write(bx::WriterI* _writer, const Dx9bcSubOperand& _subOperand, bx::Error* _err)
{
int32_t size = 0;
@ -298,17 +298,17 @@ namespace bgfx
token |= (_subOperand.type << 8) & UINT32_C(0x00001800);
token |= _subOperand.regIndex & UINT32_C(0x000007ff);
token |= (_subOperand.swizzleBits << 16) & UINT32_C(0x00ff0000);
size += bx::write(_writer, token);
size += bx::write(_writer, token, _err);
return size;
}
int32_t read(bx::ReaderI* _reader, Dx9bcOperand& _operand)
int32_t read(bx::ReaderI* _reader, Dx9bcOperand& _operand, bx::Error* _err)
{
int32_t size = 0;
uint32_t token;
size += bx::read(_reader, token);
size += bx::read(_reader, token, _err);
_operand.type = Dx9bcOperandType::Enum( ( (token & UINT32_C(0x70000000) ) >> 28)
| ( (token & UINT32_C(0x00001800) ) >> 8) );
@ -339,13 +339,13 @@ namespace bgfx
if (Dx9bcOperandAddrMode::Relative == _operand.addrMode)
{
size += read(_reader, _operand.subOperand);
size += read(_reader, _operand.subOperand, _err);
}
return size;
}
int32_t write(bx::WriterI* _writer, const Dx9bcOperand& _operand)
int32_t write(bx::WriterI* _writer, const Dx9bcOperand& _operand, bx::Error* _err)
{
int32_t size = 0;
@ -354,22 +354,22 @@ namespace bgfx
token |= (_operand.type << 8) & UINT32_C(0x00001800);
token |= _operand.regIndex & UINT32_C(0x000007ff);
token |= (_operand.addrMode << 13) & UINT32_C(0x00002000);
size += bx::write(_writer, token);
size += bx::write(_writer, token, _err);
if (Dx9bcOperandAddrMode::Relative == _operand.addrMode)
{
size += write(_writer, _operand.subOperand);
size += write(_writer, _operand.subOperand, _err);
}
return size;
}
int32_t read(bx::ReaderI* _reader, Dx9bcInstruction& _instruction)
int32_t read(bx::ReaderI* _reader, Dx9bcInstruction& _instruction, bx::Error* _err)
{
int32_t size = 0;
uint32_t token;
size += bx::read(_reader, token);
size += bx::read(_reader, token, _err);
_instruction.opcode = Dx9bcOpcode::Enum( (token & UINT32_C(0x0000ffff) ) );
@ -395,7 +395,7 @@ namespace bgfx
for (int32_t ii = 0, num = _instruction.length-1; ii < num; ++ii)
{
uint32_t tmp;
size += bx::read(_reader, tmp);
size += bx::read(_reader, tmp, _err);
}
}
@ -436,24 +436,24 @@ namespace bgfx
if (valuesBeforeOpcode
&& 0 < info.numValues)
{
size += read(_reader, _instruction.value, info.numValues*sizeof(uint32_t) );
size += read(_reader, _instruction.value, info.numValues*sizeof(uint32_t), _err);
}
_instruction.operand[0].destination = true;
switch (_instruction.numOperands)
{
case 6: size += read(_reader, _instruction.operand[currOp++]);
case 5: size += read(_reader, _instruction.operand[currOp++]);
case 4: size += read(_reader, _instruction.operand[currOp++]);
case 3: size += read(_reader, _instruction.operand[currOp++]);
case 2: size += read(_reader, _instruction.operand[currOp++]);
case 1: size += read(_reader, _instruction.operand[currOp++]);
case 6: size += read(_reader, _instruction.operand[currOp++], _err);
case 5: size += read(_reader, _instruction.operand[currOp++], _err);
case 4: size += read(_reader, _instruction.operand[currOp++], _err);
case 3: size += read(_reader, _instruction.operand[currOp++], _err);
case 2: size += read(_reader, _instruction.operand[currOp++], _err);
case 1: size += read(_reader, _instruction.operand[currOp++], _err);
case 0:
if (!valuesBeforeOpcode
&& 0 < info.numValues)
{
size += read(_reader, _instruction.value, info.numValues*sizeof(uint32_t) );
size += read(_reader, _instruction.value, info.numValues*sizeof(uint32_t), _err);
}
break;
@ -469,7 +469,7 @@ namespace bgfx
return size;
}
int32_t write(bx::WriterI* _writer, const Dx9bcInstruction& _instruction)
int32_t write(bx::WriterI* _writer, const Dx9bcInstruction& _instruction, bx::Error* _err)
{
int32_t size = 0;
@ -477,17 +477,17 @@ namespace bgfx
token |= _instruction.opcode & UINT32_C(0x0000ffff);
token |= (_instruction.specific << 16) & UINT32_C(0x00ff0000);
token |= ( (_instruction.length - 1) << 24) & UINT32_C(0x0f000000);
size += bx::write(_writer, token);
size += bx::write(_writer, token, _err);
uint32_t currOp = 0;
switch (_instruction.numOperands)
{
case 6: size += write(_writer, _instruction.operand[currOp++]);
case 5: size += write(_writer, _instruction.operand[currOp++]);
case 4: size += write(_writer, _instruction.operand[currOp++]);
case 3: size += write(_writer, _instruction.operand[currOp++]);
case 2: size += write(_writer, _instruction.operand[currOp++]);
case 1: size += write(_writer, _instruction.operand[currOp++]);
case 6: size += write(_writer, _instruction.operand[currOp++], _err);
case 5: size += write(_writer, _instruction.operand[currOp++], _err);
case 4: size += write(_writer, _instruction.operand[currOp++], _err);
case 3: size += write(_writer, _instruction.operand[currOp++], _err);
case 2: size += write(_writer, _instruction.operand[currOp++], _err);
case 1: size += write(_writer, _instruction.operand[currOp++], _err);
case 0:
break;
}
@ -626,7 +626,7 @@ namespace bgfx
return size;
}
int32_t read(bx::ReaderSeekerI* _reader, Dx9bcShader& _shader)
int32_t read(bx::ReaderSeekerI* _reader, Dx9bcShader& _shader, bx::Error* _err)
{
int32_t size = 0;
int64_t offset = bx::seek(_reader);
@ -634,7 +634,7 @@ namespace bgfx
for (;;)
{
Dx9bcInstruction instruction;
int32_t length = read(_reader, instruction);
int32_t length = read(_reader, instruction, _err);
size += length;
if (Dx9bcOpcode::Count > instruction.opcode)
@ -662,22 +662,22 @@ namespace bgfx
bx::seek(_reader, offset, bx::Whence::Begin);
_shader.byteCode.resize(size);
bx::read(_reader, _shader.byteCode.data(), size);
bx::read(_reader, _shader.byteCode.data(), size, _err);
return size;
}
int32_t write(bx::WriterI* _writer, const Dx9bcShader& _shader)
int32_t write(bx::WriterI* _writer, const Dx9bcShader& _shader, bx::Error* _err)
{
BX_UNUSED(_writer, _shader);
BX_UNUSED(_writer, _shader, _err);
return 0;
}
int32_t read(bx::ReaderSeekerI* _reader, Dx9bc& _bc)
int32_t read(bx::ReaderSeekerI* _reader, Dx9bc& _bc, bx::Error* _err)
{
int32_t size = 0;
size += bx::read(_reader, _bc.version);
size += bx::read(_reader, _bc.version, _err);
bool pixelShader = (0xffff0000 == (_bc.version & 0xffff0000) );
uint32_t versionMajor = (_bc.version>>8)&0xff;
@ -689,27 +689,29 @@ namespace bgfx
, versionMinor
);
size += read(_reader, _bc.shader);
size += read(_reader, _bc.shader, _err);
return size;
}
int32_t write(bx::WriterSeekerI* _writer, const Dx9bc& _dxbc)
int32_t write(bx::WriterSeekerI* _writer, const Dx9bc& _dxbc, bx::Error* _err)
{
BX_UNUSED(_writer, _dxbc);
BX_UNUSED(_writer, _dxbc, _err);
return 0;
}
void parse(const Dx9bcShader& _src, Dx9bcParseFn _fn, void* _userData)
void parse(const Dx9bcShader& _src, Dx9bcParseFn _fn, void* _userData, bx::Error* _err)
{
BX_ERROR_SCOPE(_err);
bx::MemoryReader reader(_src.byteCode.data(), uint32_t(_src.byteCode.size() ) );
//BX_TRACE("parse %d", _src.byteCode.size());
bx::Error err;
for (uint32_t token = 0, numTokens = uint32_t(_src.byteCode.size() / sizeof(uint32_t) ); token < numTokens;)
{
Dx9bcInstruction instruction;
uint32_t size = read(&reader, instruction);
uint32_t size = read(&reader, instruction, _err);
BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size);
bool cont = _fn(token * sizeof(uint32_t), instruction, _userData);
@ -722,8 +724,10 @@ namespace bgfx
}
}
void filter(Dx9bcShader& _dst, const Dx9bcShader& _src, Dx9bcFilterFn _fn, void* _userData)
void filter(Dx9bcShader& _dst, const Dx9bcShader& _src, Dx9bcFilterFn _fn, void* _userData, bx::Error* _err)
{
BX_ERROR_SCOPE(_err);
bx::MemoryReader reader(_src.byteCode.data(), uint32_t(_src.byteCode.size() ) );
bx::MemoryBlock mb(g_allocator);
@ -732,7 +736,7 @@ namespace bgfx
for (uint32_t token = 0, numTokens = uint32_t(_src.byteCode.size() / sizeof(uint32_t) ); token < numTokens;)
{
Dx9bcInstruction instruction;
uint32_t size = read(&reader, instruction);
uint32_t size = read(&reader, instruction, _err);
BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size);
_fn(instruction, _userData);

View file

@ -226,8 +226,8 @@ namespace bgfx
int32_t value[4];
};
int32_t read(bx::ReaderI* _reader, Dx9bcInstruction& _instruction);
int32_t write(bx::WriterI* _writer, const Dx9bcInstruction& _instruction);
int32_t read(bx::ReaderI* _reader, Dx9bcInstruction& _instruction, bx::Error* _err);
int32_t write(bx::WriterI* _writer, const Dx9bcInstruction& _instruction, bx::Error* _err);
int32_t toString(char* _out, int32_t _size, const Dx9bcInstruction& _instruction);
struct Dx9bcShader
@ -235,8 +235,8 @@ namespace bgfx
stl::vector<uint8_t> byteCode;
};
int32_t read(bx::ReaderSeekerI* _reader, Dx9bcShader& _shader);
int32_t write(bx::WriterI* _writer, const Dx9bcShader& _shader);
int32_t read(bx::ReaderSeekerI* _reader, Dx9bcShader& _shader, bx::Error* _err);
int32_t write(bx::WriterI* _writer, const Dx9bcShader& _shader, bx::Error* _err);
struct Dx9bc
{
@ -244,14 +244,14 @@ namespace bgfx
Dx9bcShader shader;
};
int32_t read(bx::ReaderSeekerI* _reader, Dx9bc& _dx9bc);
int32_t write(bx::WriterSeekerI* _writer, const Dx9bc& _dx9bc);
int32_t read(bx::ReaderSeekerI* _reader, Dx9bc& _dx9bc, bx::Error* _err);
int32_t write(bx::WriterSeekerI* _writer, const Dx9bc& _dx9bc, bx::Error* _err);
typedef bool (*Dx9bcParseFn)(uint32_t _offset, const Dx9bcInstruction& _instruction, void* _userData);
void parse(const Dx9bcShader& _src, Dx9bcParseFn _fn, void* _userData);
void parse(const Dx9bcShader& _src, Dx9bcParseFn _fn, void* _userData, bx::Error* _err = NULL);
typedef void (*Dx9bcFilterFn)(Dx9bcInstruction& _instruction, void* _userData);
void filter(Dx9bcShader& _dst, const Dx9bcShader& _src, Dx9bcFilterFn _fn, void* _userData);
void filter(Dx9bcShader& _dst, const Dx9bcShader& _src, Dx9bcFilterFn _fn, void* _userData, bx::Error* _err = NULL);
} // namespace bgfx

View file

@ -552,7 +552,7 @@ namespace bgfx
#define DXBC_MAX_NAME_STRING 512
int32_t readString(bx::ReaderSeekerI* _reader, int64_t _offset, char* _out, uint32_t _max = DXBC_MAX_NAME_STRING)
int32_t readString(bx::ReaderSeekerI* _reader, int64_t _offset, char* _out, uint32_t _max, bx::Error* _err)
{
int64_t oldOffset = bx::seek(_reader);
bx::seek(_reader, _offset, bx::Whence::Begin);
@ -562,7 +562,7 @@ namespace bgfx
for (uint32_t ii = 0; ii < _max-1; ++ii)
{
char ch;
size += bx::read(_reader, ch);
size += bx::read(_reader, ch, _err);
*_out++ = ch;
if ('\0' == ch)
@ -755,7 +755,7 @@ namespace bgfx
memcpy(_digest, hash, 16);
}
int32_t read(bx::ReaderI* _reader, DxbcSubOperand& _subOperand)
int32_t read(bx::ReaderI* _reader, DxbcSubOperand& _subOperand, bx::Error* _err)
{
uint32_t token;
int32_t size = 0;
@ -773,7 +773,7 @@ namespace bgfx
// |+------------------------------- addressing mode 2
// +-------------------------------- extended
size += bx::read(_reader, token);
size += bx::read(_reader, token, _err);
_subOperand.type = DxbcOperandType::Enum( (token & UINT32_C(0x000ff000) ) >> 12);
_subOperand.numAddrModes = uint8_t( (token & UINT32_C(0x00300000) ) >> 20);
_subOperand.addrMode = uint8_t( (token & UINT32_C(0x01c00000) ) >> 22);
@ -784,7 +784,7 @@ namespace bgfx
switch (_subOperand.addrMode)
{
case DxbcOperandAddrMode::Imm32:
size += bx::read(_reader, _subOperand.regIndex);
size += bx::read(_reader, _subOperand.regIndex, _err);
break;
case DxbcOperandAddrMode::Reg:
@ -796,7 +796,7 @@ namespace bgfx
case DxbcOperandAddrMode::RegImm32:
{
size += bx::read(_reader, _subOperand.regIndex);
size += bx::read(_reader, _subOperand.regIndex, _err);
DxbcSubOperand subOperand;
size += read(_reader, subOperand);
@ -805,8 +805,8 @@ namespace bgfx
case DxbcOperandAddrMode::RegImm64:
{
size += bx::read(_reader, _subOperand.regIndex);
size += bx::read(_reader, _subOperand.regIndex);
size += bx::read(_reader, _subOperand.regIndex, _err);
size += bx::read(_reader, _subOperand.regIndex, _err);
DxbcSubOperand subOperand;
size += read(_reader, subOperand);
@ -821,7 +821,7 @@ namespace bgfx
return size;
}
int32_t write(bx::WriterI* _writer, const DxbcSubOperand& _subOperand)
int32_t write(bx::WriterI* _writer, const DxbcSubOperand& _subOperand, bx::Error* _err)
{
int32_t size = 0;
@ -832,12 +832,12 @@ namespace bgfx
token |= (_subOperand.mode << 2) & UINT32_C(0x0000000c);
token |= (_subOperand.modeBits << 4) & UINT32_C(0x00000ff0);
token |= _subOperand.num & UINT32_C(0x00000003);
size += bx::write(_writer, token);
size += bx::write(_writer, token, _err);
switch (_subOperand.addrMode)
{
case DxbcOperandAddrMode::Imm32:
size += bx::write(_writer, _subOperand.regIndex);
size += bx::write(_writer, _subOperand.regIndex, _err);
break;
case DxbcOperandAddrMode::Reg:
@ -849,7 +849,7 @@ namespace bgfx
case DxbcOperandAddrMode::RegImm32:
{
size += bx::write(_writer, _subOperand.regIndex);
size += bx::write(_writer, _subOperand.regIndex, _err);
DxbcSubOperand subOperand;
size += write(_writer, subOperand);
@ -858,8 +858,8 @@ namespace bgfx
case DxbcOperandAddrMode::RegImm64:
{
size += bx::write(_writer, _subOperand.regIndex);
size += bx::write(_writer, _subOperand.regIndex);
size += bx::write(_writer, _subOperand.regIndex, _err);
size += bx::write(_writer, _subOperand.regIndex, _err);
DxbcSubOperand subOperand;
size += write(_writer, subOperand);
@ -874,12 +874,12 @@ namespace bgfx
return size;
}
int32_t read(bx::ReaderI* _reader, DxbcOperand& _operand)
int32_t read(bx::ReaderI* _reader, DxbcOperand& _operand, bx::Error* _err)
{
int32_t size = 0;
uint32_t token;
size += bx::read(_reader, token);
size += bx::read(_reader, token, _err);
// 0 1 2 3
// 76543210765432107654321076543210
@ -906,7 +906,7 @@ namespace bgfx
if (_operand.extended)
{
size += bx::read(_reader, _operand.extBits);
size += bx::read(_reader, _operand.extBits, _err);
}
switch (_operand.type)
@ -915,7 +915,7 @@ namespace bgfx
_operand.num = 2 == _operand.num ? 4 : _operand.num;
for (uint32_t ii = 0; ii < _operand.num; ++ii)
{
size += bx::read(_reader, _operand.un.imm32[ii]);
size += bx::read(_reader, _operand.un.imm32[ii], _err);
}
break;
@ -923,7 +923,7 @@ namespace bgfx
_operand.num = 2 == _operand.num ? 4 : _operand.num;
for (uint32_t ii = 0; ii < _operand.num; ++ii)
{
size += bx::read(_reader, _operand.un.imm64[ii]);
size += bx::read(_reader, _operand.un.imm64[ii], _err);
}
break;
@ -936,16 +936,16 @@ namespace bgfx
switch (_operand.addrMode[ii])
{
case DxbcOperandAddrMode::Imm32:
size += bx::read(_reader, _operand.regIndex[ii]);
size += bx::read(_reader, _operand.regIndex[ii], _err);
break;
case DxbcOperandAddrMode::Reg:
size += read(_reader, _operand.subOperand[ii]);
size += read(_reader, _operand.subOperand[ii], _err);
break;
case DxbcOperandAddrMode::RegImm32:
size += bx::read(_reader, _operand.regIndex[ii]);
size += read(_reader, _operand.subOperand[ii]);
size += bx::read(_reader, _operand.regIndex[ii], _err);
size += read(_reader, _operand.subOperand[ii], _err);
break;
default:
@ -957,7 +957,7 @@ namespace bgfx
return size;
}
int32_t write(bx::WriterI* _writer, const DxbcOperand& _operand)
int32_t write(bx::WriterI* _writer, const DxbcOperand& _operand, bx::Error* _err)
{
int32_t size = 0;
@ -973,7 +973,7 @@ namespace bgfx
token |= (4 == _operand.num ? 2 : _operand.num) & UINT32_C(0x00000003);
token |= ( (_operand.modeBits & "\x0f\xff\x03\x00"[_operand.mode]) << 4) & UINT32_C(0x00000ff0);
size += bx::write(_writer, token);
size += bx::write(_writer, token, _err);
if (_operand.extended)
{
@ -985,14 +985,14 @@ namespace bgfx
case DxbcOperandType::Imm32:
for (uint32_t ii = 0; ii < _operand.num; ++ii)
{
size += bx::write(_writer, _operand.un.imm32[ii]);
size += bx::write(_writer, _operand.un.imm32[ii], _err);
}
break;
case DxbcOperandType::Imm64:
for (uint32_t ii = 0; ii < _operand.num; ++ii)
{
size += bx::write(_writer, _operand.un.imm64[ii]);
size += bx::write(_writer, _operand.un.imm64[ii], _err);
}
break;
@ -1005,16 +1005,16 @@ namespace bgfx
switch (_operand.addrMode[ii])
{
case DxbcOperandAddrMode::Imm32:
size += bx::write(_writer, _operand.regIndex[ii]);
size += bx::write(_writer, _operand.regIndex[ii], _err);
break;
case DxbcOperandAddrMode::Reg:
size += write(_writer, _operand.subOperand[ii]);
size += write(_writer, _operand.subOperand[ii], _err);
break;
case DxbcOperandAddrMode::RegImm32:
size += bx::write(_writer, _operand.regIndex[ii]);
size += write(_writer, _operand.subOperand[ii]);
size += bx::write(_writer, _operand.regIndex[ii], _err);
size += write(_writer, _operand.subOperand[ii], _err);
break;
default:
@ -1026,12 +1026,12 @@ namespace bgfx
return size;
}
int32_t read(bx::ReaderI* _reader, DxbcInstruction& _instruction)
int32_t read(bx::ReaderI* _reader, DxbcInstruction& _instruction, bx::Error* _err)
{
uint32_t size = 0;
uint32_t token;
size += bx::read(_reader, token);
size += bx::read(_reader, token, _err);
// 0 1 2 3
// 76543210765432107654321076543210
@ -1077,7 +1077,7 @@ namespace bgfx
for (uint32_t ii = 0, num = (_instruction.length-2)/4; ii < num; ++ii)
{
char temp[16];
size += bx::read(_reader, temp, 16);
size += bx::read(_reader, temp, 16, _err);
}
}
@ -1190,7 +1190,7 @@ namespace bgfx
uint32_t extBits;
size += bx::read(_reader, extBits);
extended = 0 != (extBits & UINT32_C(0x80000000) );
_instruction.extended[ii] = DxbcInstruction::ExtendedType::Enum(extBits & UINT32_C(0x0000001f) );
_instruction.extended[ii ] = DxbcInstruction::ExtendedType::Enum(extBits & UINT32_C(0x0000001f) );
_instruction.extended[ii+1] = DxbcInstruction::ExtendedType::Count;
switch (_instruction.extended[ii])
@ -1244,7 +1244,7 @@ namespace bgfx
case DxbcOpcode::DCL_FUNCTION_TABLE:
{
uint32_t tableId;
size += read(_reader, tableId);
size += read(_reader, tableId, _err);
uint32_t num;
size += read(_reader, num);
@ -1252,7 +1252,7 @@ namespace bgfx
for (uint32_t ii = 0; ii < num; ++ii)
{
uint32_t bodyId;
size += read(_reader, bodyId);
size += read(_reader, bodyId, _err);
}
}
break;
@ -1260,10 +1260,10 @@ namespace bgfx
case DxbcOpcode::DCL_INTERFACE:
{
uint32_t interfaceId;
size += read(_reader, interfaceId);
size += read(_reader, interfaceId, _err);
uint32_t num;
size += read(_reader, num);
size += read(_reader, num, _err);
BX_CHECK(false, "not implemented.");
}
@ -1279,16 +1279,16 @@ namespace bgfx
_instruction.numOperands = info.numOperands;
switch (info.numOperands)
{
case 6: size += read(_reader, _instruction.operand[currOp++]);
case 5: size += read(_reader, _instruction.operand[currOp++]);
case 4: size += read(_reader, _instruction.operand[currOp++]);
case 3: size += read(_reader, _instruction.operand[currOp++]);
case 2: size += read(_reader, _instruction.operand[currOp++]);
case 1: size += read(_reader, _instruction.operand[currOp++]);
case 6: size += read(_reader, _instruction.operand[currOp++], _err);
case 5: size += read(_reader, _instruction.operand[currOp++], _err);
case 4: size += read(_reader, _instruction.operand[currOp++], _err);
case 3: size += read(_reader, _instruction.operand[currOp++], _err);
case 2: size += read(_reader, _instruction.operand[currOp++], _err);
case 1: size += read(_reader, _instruction.operand[currOp++], _err);
case 0:
if (0 < info.numValues)
{
size += read(_reader, _instruction.value, info.numValues*sizeof(uint32_t) );
size += read(_reader, _instruction.value, info.numValues*sizeof(uint32_t), _err);
}
break;
@ -1304,7 +1304,7 @@ namespace bgfx
return size;
}
int32_t write(bx::WriterI* _writer, const DxbcInstruction& _instruction)
int32_t write(bx::WriterI* _writer, const DxbcInstruction& _instruction, bx::Error* _err)
{
uint32_t token = 0;
token |= (_instruction.opcode ) & UINT32_C(0x000007ff);
@ -1366,7 +1366,7 @@ namespace bgfx
uint32_t size =0;
size += bx::write(_writer, token);
;
for (uint32_t ii = 0; _instruction.extended[ii] != DxbcInstruction::ExtendedType::Count; ++ii)
{
// 0 1 2 3
@ -1427,18 +1427,18 @@ namespace bgfx
break;
}
size += bx::write(_writer, token);
size += bx::write(_writer, token, _err);
}
for (uint32_t ii = 0; ii < _instruction.numOperands; ++ii)
{
size += write(_writer, _instruction.operand[ii]);
size += write(_writer, _instruction.operand[ii], _err);
}
const DxbcOpcodeInfo& info = s_dxbcOpcodeInfo[_instruction.opcode];
if (0 < info.numValues)
{
size += bx::write(_writer, _instruction.value, info.numValues*sizeof(uint32_t) );
size += bx::write(_writer, _instruction.value, info.numValues*sizeof(uint32_t), _err);
}
return size;
@ -1609,15 +1609,15 @@ namespace bgfx
return size;
}
int32_t read(bx::ReaderSeekerI* _reader, DxbcSignature& _signature)
int32_t read(bx::ReaderSeekerI* _reader, DxbcSignature& _signature, bx::Error* _err)
{
int32_t size = 0;
int64_t offset = bx::seek(_reader);
uint32_t num;
size += bx::read(_reader, num);
size += bx::read(_reader, _signature.key);
size += bx::read(_reader, num, _err);
size += bx::read(_reader, _signature.key, _err);
for (uint32_t ii = 0; ii < num; ++ii)
{
@ -1627,20 +1627,20 @@ namespace bgfx
size += bx::read(_reader, nameOffset);
char name[DXBC_MAX_NAME_STRING];
readString(_reader, offset + nameOffset, name);
readString(_reader, offset + nameOffset, name, DXBC_MAX_NAME_STRING, _err);
element.name = name;
size += bx::read(_reader, element.semanticIndex);
size += bx::read(_reader, element.valueType);
size += bx::read(_reader, element.componentType);
size += bx::read(_reader, element.registerIndex);
size += bx::read(_reader, element.mask);
size += bx::read(_reader, element.readWriteMask);
size += bx::read(_reader, element.stream);
size += bx::read(_reader, element.semanticIndex, _err);
size += bx::read(_reader, element.valueType, _err);
size += bx::read(_reader, element.componentType, _err);
size += bx::read(_reader, element.registerIndex, _err);
size += bx::read(_reader, element.mask, _err);
size += bx::read(_reader, element.readWriteMask, _err);
size += bx::read(_reader, element.stream, _err);
// padding
uint8_t padding;
size += bx::read(_reader, padding);
size += bx::read(_reader, padding, _err);
_signature.elements.push_back(element);
}
@ -1648,13 +1648,13 @@ namespace bgfx
return size;
}
int32_t write(bx::WriterI* _writer, const DxbcSignature& _signature)
int32_t write(bx::WriterI* _writer, const DxbcSignature& _signature, bx::Error* _err)
{
int32_t size = 0;
const uint32_t num = uint32_t(_signature.elements.size() );
size += bx::write(_writer, num);
size += bx::write(_writer, _signature.key);
size += bx::write(_writer, num, _err);
size += bx::write(_writer, _signature.key, _err);
typedef stl::unordered_map<stl::string, uint32_t> NameOffsetMap;
NameOffsetMap nom;
@ -1669,7 +1669,7 @@ namespace bgfx
if (it == nom.end() )
{
nom.insert(stl::make_pair(element.name, nameOffset) );
size += bx::write(_writer, nameOffset);
size += bx::write(_writer, nameOffset, _err);
nameOffset += uint32_t(element.name.size() + 1);
}
else
@ -1677,15 +1677,14 @@ namespace bgfx
size += bx::write(_writer, it->second);
}
size += bx::write(_writer, element.semanticIndex);
size += bx::write(_writer, element.valueType);
size += bx::write(_writer, element.componentType);
size += bx::write(_writer, element.registerIndex);
size += bx::write(_writer, element.mask);
size += bx::write(_writer, element.readWriteMask);
size += bx::write(_writer, element.stream);
size += bx::write(_writer, pad);
size += bx::write(_writer, element.semanticIndex, _err);
size += bx::write(_writer, element.valueType, _err);
size += bx::write(_writer, element.componentType, _err);
size += bx::write(_writer, element.registerIndex, _err);
size += bx::write(_writer, element.mask, _err);
size += bx::write(_writer, element.readWriteMask, _err);
size += bx::write(_writer, element.stream, _err);
size += bx::write(_writer, pad, _err);
}
uint32_t len = 0;
@ -1696,42 +1695,42 @@ namespace bgfx
if (it != nom.end() )
{
nom.erase(it);
size += bx::write(_writer, element.name.c_str(), uint32_t(element.name.size() + 1) );
size += bx::write(_writer, element.name.c_str(), uint32_t(element.name.size() + 1), _err);
len += uint32_t(element.name.size() + 1);
}
}
// align 4 bytes
size += bx::writeRep(_writer, 0xab, (len+3)/4*4 - len);
size += bx::writeRep(_writer, 0xab, (len+3)/4*4 - len, _err);
return size;
}
int32_t read(bx::ReaderSeekerI* _reader, DxbcShader& _shader)
int32_t read(bx::ReaderSeekerI* _reader, DxbcShader& _shader, bx::Error* _err)
{
int32_t size = 0;
size += bx::read(_reader, _shader.version);
size += bx::read(_reader, _shader.version, _err);
uint32_t bcLength;
size += bx::read(_reader, bcLength);
size += bx::read(_reader, bcLength, _err);
uint32_t len = (bcLength-2)*sizeof(uint32_t);
_shader.byteCode.resize(len);
size += bx::read(_reader, _shader.byteCode.data(), len);
size += bx::read(_reader, _shader.byteCode.data(), len, _err);
return size;
}
int32_t write(bx::WriterI* _writer, const DxbcShader& _shader)
int32_t write(bx::WriterI* _writer, const DxbcShader& _shader, bx::Error* _err)
{
const uint32_t len = uint32_t(_shader.byteCode.size() );
const uint32_t bcLength = len / sizeof(uint32_t) + 2;
int32_t size = 0;
size += bx::write(_writer, _shader.version);
size += bx::write(_writer, bcLength);
size += bx::write(_writer, _shader.byteCode.data(), len);
size += bx::write(_writer, _shader.version, _err);
size += bx::write(_writer, bcLength, _err);
size += bx::write(_writer, _shader.byteCode.data(), len, _err);
return size;
}
@ -1743,10 +1742,10 @@ namespace bgfx
#define DXBC_CHUNK_INPUT_SIGNATURE BX_MAKEFOURCC('I', 'S', 'G', 'N')
#define DXBC_CHUNK_OUTPUT_SIGNATURE BX_MAKEFOURCC('O', 'S', 'G', 'N')
int32_t read(bx::ReaderSeekerI* _reader, DxbcContext& _dxbc)
int32_t read(bx::ReaderSeekerI* _reader, DxbcContext& _dxbc, bx::Error* _err)
{
int32_t size = 0;
size += bx::read(_reader, _dxbc.header);
size += bx::read(_reader, _dxbc.header, _err);
_dxbc.shader.shex = false;
for (uint32_t ii = 0; ii < _dxbc.header.numChunks; ++ii)
@ -1754,15 +1753,15 @@ namespace bgfx
bx::seek(_reader, sizeof(DxbcContext::Header) + ii*sizeof(uint32_t), bx::Whence::Begin);
uint32_t chunkOffset;
size += bx::read(_reader, chunkOffset);
size += bx::read(_reader, chunkOffset, _err);
bx::seek(_reader, chunkOffset, bx::Whence::Begin);
uint32_t fourcc;
size += bx::read(_reader, fourcc);
size += bx::read(_reader, fourcc, _err);
uint32_t chunkSize;
size += bx::read(_reader, chunkSize);
size += bx::read(_reader, chunkSize, _err);
switch (fourcc)
{
@ -1771,18 +1770,18 @@ namespace bgfx
// fallthrough
case DXBC_CHUNK_SHADER:
size += read(_reader, _dxbc.shader);
size += read(_reader, _dxbc.shader, _err);
break;
case BX_MAKEFOURCC('I', 'S', 'G', '1'):
case DXBC_CHUNK_INPUT_SIGNATURE:
size += read(_reader, _dxbc.inputSignature);
size += read(_reader, _dxbc.inputSignature, _err);
break;
case BX_MAKEFOURCC('O', 'S', 'G', '1'):
case BX_MAKEFOURCC('O', 'S', 'G', '5'):
case DXBC_CHUNK_OUTPUT_SIGNATURE:
size += read(_reader, _dxbc.outputSignature);
size += read(_reader, _dxbc.outputSignature, _err);
break;
case BX_MAKEFOURCC('A', 'o', 'n', '9'): // Contains DX9BC for feature level 9.x (*s_4_0_level_9_*) shaders.
@ -1816,43 +1815,43 @@ namespace bgfx
return size;
}
int32_t write(bx::WriterSeekerI* _writer, const DxbcContext& _dxbc)
int32_t write(bx::WriterSeekerI* _writer, const DxbcContext& _dxbc, bx::Error* _err)
{
int32_t size = 0;
int64_t dxbcOffset = bx::seek(_writer);
size += bx::write(_writer, DXBC_CHUNK_HEADER);
size += bx::writeRep(_writer, 0, 16);
size += bx::writeRep(_writer, 0, 16, _err);
size += bx::write(_writer, UINT32_C(1) );
size += bx::write(_writer, UINT32_C(1), _err);
int64_t sizeOffset = bx::seek(_writer);
size += bx::writeRep(_writer, 0, 4);
size += bx::writeRep(_writer, 0, 4, _err);
uint32_t numChunks = 3;
size += bx::write(_writer, numChunks);
size += bx::write(_writer, numChunks, _err);
int64_t chunksOffsets = bx::seek(_writer);
size += bx::writeRep(_writer, 0, numChunks*sizeof(uint32_t) );
size += bx::writeRep(_writer, 0, numChunks*sizeof(uint32_t), _err);
uint32_t chunkOffset[3];
uint32_t chunkSize[3];
chunkOffset[0] = uint32_t(bx::seek(_writer) - dxbcOffset);
size += write(_writer, DXBC_CHUNK_INPUT_SIGNATURE);
size += write(_writer, UINT32_C(0) );
chunkSize[0] = write(_writer, _dxbc.inputSignature);
size += write(_writer, DXBC_CHUNK_INPUT_SIGNATURE, _err);
size += write(_writer, UINT32_C(0), _err);
chunkSize[0] = write(_writer, _dxbc.inputSignature, _err);
chunkOffset[1] = uint32_t(bx::seek(_writer) - dxbcOffset);
size += write(_writer, DXBC_CHUNK_OUTPUT_SIGNATURE);
size += write(_writer, UINT32_C(0) );
chunkSize[1] = write(_writer, _dxbc.outputSignature);
size += write(_writer, DXBC_CHUNK_OUTPUT_SIGNATURE, _err);
size += write(_writer, UINT32_C(0), _err);
chunkSize[1] = write(_writer, _dxbc.outputSignature, _err);
chunkOffset[2] = uint32_t(bx::seek(_writer) - dxbcOffset);
size += write(_writer, _dxbc.shader.shex ? DXBC_CHUNK_SHADER_EX : DXBC_CHUNK_SHADER);
size += write(_writer, UINT32_C(0) );
chunkSize[2] = write(_writer, _dxbc.shader);
size += write(_writer, _dxbc.shader.shex ? DXBC_CHUNK_SHADER_EX : DXBC_CHUNK_SHADER, _err);
size += write(_writer, UINT32_C(0), _err);
chunkSize[2] = write(_writer, _dxbc.shader, _err);
size += 0
+ chunkSize[0]
@ -1863,15 +1862,15 @@ namespace bgfx
int64_t eof = bx::seek(_writer);
bx::seek(_writer, sizeOffset, bx::Whence::Begin);
bx::write(_writer, size);
bx::write(_writer, size, _err);
bx::seek(_writer, chunksOffsets, bx::Whence::Begin);
bx::write(_writer, chunkOffset, sizeof(chunkOffset) );
bx::write(_writer, chunkOffset, sizeof(chunkOffset), _err);
for (uint32_t ii = 0; ii < BX_COUNTOF(chunkOffset); ++ii)
{
bx::seek(_writer, chunkOffset[ii]+4, bx::Whence::Begin);
bx::write(_writer, chunkSize[ii]);
bx::write(_writer, chunkSize[ii], _err);
}
bx::seek(_writer, eof, bx::Whence::Begin);
@ -1879,14 +1878,16 @@ namespace bgfx
return size;
}
void parse(const DxbcShader& _src, DxbcParseFn _fn, void* _userData)
void parse(const DxbcShader& _src, DxbcParseFn _fn, void* _userData, bx::Error* _err)
{
BX_ERROR_SCOPE(_err);
bx::MemoryReader reader(_src.byteCode.data(), uint32_t(_src.byteCode.size() ) );
for (uint32_t token = 0, numTokens = uint32_t(_src.byteCode.size() / sizeof(uint32_t) ); token < numTokens;)
{
DxbcInstruction instruction;
uint32_t size = read(&reader, instruction);
uint32_t size = read(&reader, instruction, _err);
BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size);
bool cont = _fn(token * sizeof(uint32_t), instruction, _userData);
@ -1899,8 +1900,10 @@ namespace bgfx
}
}
void filter(DxbcShader& _dst, const DxbcShader& _src, DxbcFilterFn _fn, void* _userData)
void filter(DxbcShader& _dst, const DxbcShader& _src, DxbcFilterFn _fn, void* _userData, bx::Error* _err)
{
BX_ERROR_SCOPE(_err);
bx::MemoryReader reader(_src.byteCode.data(), uint32_t(_src.byteCode.size() ) );
bx::MemoryBlock mb(g_allocator);
@ -1909,12 +1912,12 @@ namespace bgfx
for (uint32_t token = 0, numTokens = uint32_t(_src.byteCode.size() / sizeof(uint32_t) ); token < numTokens;)
{
DxbcInstruction instruction;
uint32_t size = read(&reader, instruction);
uint32_t size = read(&reader, instruction, _err);
BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size);
_fn(instruction, _userData);
write(&writer, instruction);
write(&writer, instruction, _err);
token += instruction.length;
}

View file

@ -540,8 +540,8 @@ namespace bgfx
DxbcOperand operand[6];
};
int32_t read(bx::ReaderI* _reader, DxbcInstruction& _instruction);
int32_t write(bx::WriterI* _writer, const DxbcInstruction& _instruction);
int32_t read(bx::ReaderI* _reader, DxbcInstruction& _instruction, bx::Error* _err);
int32_t write(bx::WriterI* _writer, const DxbcInstruction& _instruction, bx::Error* _err);
int32_t toString(char* _out, int32_t _size, const DxbcInstruction& _instruction);
struct DxbcSignature
@ -562,8 +562,8 @@ namespace bgfx
stl::vector<Element> elements;
};
int32_t read(bx::ReaderSeekerI* _reader, DxbcSignature& _signature);
int32_t write(bx::WriterI* _writer, const DxbcSignature& _signature);
int32_t read(bx::ReaderSeekerI* _reader, DxbcSignature& _signature, bx::Error* _err);
int32_t write(bx::WriterI* _writer, const DxbcSignature& _signature, bx::Error* _err);
struct DxbcShader
{
@ -572,14 +572,14 @@ namespace bgfx
bool shex;
};
int32_t read(bx::ReaderSeekerI* _reader, DxbcShader& _shader);
int32_t write(bx::WriterI* _writer, const DxbcShader& _shader);
int32_t read(bx::ReaderSeekerI* _reader, DxbcShader& _shader, bx::Error* _err);
int32_t write(bx::WriterI* _writer, const DxbcShader& _shader, bx::Error* _err);
typedef bool (*DxbcParseFn)(uint32_t _offset, const DxbcInstruction& _instruction, void* _userData);
void parse(const DxbcShader& _src, DxbcParseFn _fn, void* _userData);
void parse(const DxbcShader& _src, DxbcParseFn _fn, void* _userData, bx::Error* _err = NULL);
typedef void (*DxbcFilterFn)(DxbcInstruction& _instruction, void* _userData);
void filter(DxbcShader& _dst, const DxbcShader& _src, DxbcFilterFn _fn, void* _userData);
void filter(DxbcShader& _dst, const DxbcShader& _src, DxbcFilterFn _fn, void* _userData, bx::Error* _err = NULL);
struct DxbcContext
{
@ -598,8 +598,8 @@ namespace bgfx
DxbcShader shader;
};
int32_t read(bx::ReaderSeekerI* _reader, DxbcContext& _dxbc);
int32_t write(bx::WriterSeekerI* _writer, const DxbcContext& _dxbc);
int32_t read(bx::ReaderSeekerI* _reader, DxbcContext& _dxbc, bx::Error* _err);
int32_t write(bx::WriterSeekerI* _writer, const DxbcContext& _dxbc, bx::Error* _err);
/// Calculate DXBC hash from data.
void dxbcHash(const void* _data, uint32_t _size, void* _digest);

File diff suppressed because it is too large Load diff

View file

@ -8,11 +8,14 @@
#include <bx/readerwriter.h>
BX_ERROR_RESULT(BGFX_SHADER_SPIRV_INVALID_HEADER, BX_MAKEFOURCC('S', 'H', 0, 1) );
BX_ERROR_RESULT(BGFX_SHADER_SPIRV_INVALID_INSTRUCTION, BX_MAKEFOURCC('S', 'H', 0, 2) );
namespace bgfx
{
// Reference: https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html
struct SpirvOpcode
struct SpvOpcode
{
enum Enum
{
@ -25,13 +28,16 @@ namespace bgfx
MemberName,
String,
Line,
Invalid9,
Extension,
ExtInstImport,
ExtInst,
Invalid13,
MemoryModel,
EntryPoint,
ExecutionMode,
Capability,
Invalid18,
TypeVoid,
TypeBool,
TypeInt,
@ -53,21 +59,25 @@ namespace bgfx
TypeQueue,
TypePipe,
TypeForwardPointer,
Invalid40,
ConstantTrue,
ConstantFalse,
Constant,
ConstantComposite,
ConstantSampler,
ConstantNull,
Invalid47,
SpecConstantTrue,
SpecConstantFalse,
SpecConstant,
SpecConstantComposite,
SpecConstantOp,
Invalid53,
Function,
FunctionParameter,
FunctionEnd,
FunctionCall,
Invalid58,
Variable,
ImageTexelPointer,
Load,
@ -85,6 +95,7 @@ namespace bgfx
DecorationGroup,
GroupDecorate,
GroupMemberDecorate,
Invalid76,
VectorExtractDynamic,
VectorInsertDynamic,
VectorShuffle,
@ -93,6 +104,7 @@ namespace bgfx
CompositeInsert,
CopyObject,
Transpose,
Invalid85,
SampledImage,
ImageSampleImplicitLod,
ImageSampleExplicitLod,
@ -115,6 +127,7 @@ namespace bgfx
ImageQueryLod,
ImageQueryLevels,
ImageQuerySamples,
Invalid108,
ConvertFToU,
ConvertFToS,
ConvertSToF,
@ -131,6 +144,7 @@ namespace bgfx
GenericCastToPtr,
GenericCastToPtrExplicit,
Bitcast,
Invalid125,
SNegate,
FNegate,
IAdd,
@ -158,6 +172,7 @@ namespace bgfx
ISubBorrow,
UMulExtended,
SMulExtended,
Invalid153,
Any,
All,
IsNan,
@ -196,6 +211,8 @@ namespace bgfx
FUnordLessThanEqual,
FOrdGreaterThanEqual,
FUnordGreaterThanEqual,
Invalid192,
Invalid193,
ShiftRightLogical,
ShiftRightArithmetic,
ShiftLeftLogical,
@ -208,6 +225,7 @@ namespace bgfx
BitFieldUExtract,
BitReverse,
BitCount,
Invalid206,
DPdx,
DPdy,
Fwidth,
@ -217,12 +235,17 @@ namespace bgfx
DPdxCoarse,
DPdyCoarse,
FwidthCoarse,
Invalid216,
Invalid217,
EmitVertex,
EndPrimitive,
EmitStreamVertex,
EndStreamPrimitive,
Invalid222,
Invalid223,
ControlBarrier,
MemoryBarrier,
Invalid226,
AtomicLoad,
AtomicStore,
AtomicExchange,
@ -239,6 +262,8 @@ namespace bgfx
AtomicAnd,
AtomicOr,
AtomicXor,
Invalid243,
Invalid244,
Phi,
LoopMerge,
SelectionMerge,
@ -252,6 +277,7 @@ namespace bgfx
Unreachable,
LifetimeStart,
LifetimeStop,
Invalid258,
GroupAsyncCopy,
GroupWaitEvents,
GroupAll,
@ -265,6 +291,8 @@ namespace bgfx
GroupFMax,
GroupUMax,
GroupSMax,
Invalid272,
Invalid273,
ReadPipe,
WritePipe,
ReservedReadPipe,
@ -280,6 +308,8 @@ namespace bgfx
GroupReserveWritePipePackets,
GroupCommitReadPipe,
GroupCommitWritePipe,
Invalid289,
Invalid290,
EnqueueMarker,
EnqueueKernel,
GetKernelNDrangeSubGroupCount,
@ -360,10 +390,12 @@ namespace bgfx
SubgroupLocalInvocationId,
VertexIndex,
InstanceIndex,
Count
};
};
struct SpirvExecutionModel
struct SpvExecutionModel
{
enum Enum
{
@ -379,7 +411,19 @@ namespace bgfx
};
};
struct SpirvMemoryModel
struct SpvAddressingModel
{
enum Enum
{
Logical,
Physical32,
Physical64,
Count
};
};
struct SpvMemoryModel
{
enum Enum
{
@ -391,7 +435,7 @@ namespace bgfx
};
};
struct SpirvStorageClass
struct SpvStorageClass
{
enum Enum
{
@ -407,10 +451,12 @@ namespace bgfx
PushConstant,
AtomicCounter,
Image,
Count
};
};
struct SpirvResourceDim
struct SpvResourceDim
{
enum Enum
{
@ -424,7 +470,7 @@ namespace bgfx
};
};
struct SpirvDecoration
struct SpvDecoration
{
enum Enum
{
@ -476,52 +522,90 @@ namespace bgfx
};
};
struct SpirvOperand
struct SpvOperand
{
};
struct SpirvInstruction
{
SpirvOpcode::Enum opcode;
uint16_t length;
uint8_t numOperands;
SpirvOperand operand[6];
union
enum Enum
{
struct ResultTypeId
{
uint32_t resultType;
uint32_t id;
};
AccessQualifier,
AddressingModel,
Base,
Capability,
Component,
ComponentType,
Composite,
Condition,
Coordinate,
Decoration,
Dim,
Dref,
ExecutionModel,
Function,
FunctionControl,
Id,
IdRep,
ImageFormat,
ImageOperands,
LiteralNumber,
LiteralRep,
LiteralString,
Matrix,
MemoryAccess,
MemoryModel,
Object,
Pointer,
SampledType,
SampledImage,
SamplerAddressingMode,
SamplerFilterMode,
Scalar,
SourceLanguage,
StorageClass,
StructureType,
Vector,
ResultTypeId constant;
ResultTypeId constantComposite;
Count
};
uint32_t value[8];
} un;
Enum type;
uint32_t data[4];
uint32_t target;
stl::string literalString;
};
int32_t read(bx::ReaderI* _reader, SpirvInstruction& _instruction);
int32_t write(bx::WriterI* _writer, const SpirvInstruction& _instruction);
int32_t toString(char* _out, int32_t _size, const SpirvInstruction& _instruction);
struct SpvInstruction
{
SpvOpcode::Enum opcode;
uint16_t length;
uint16_t numOperands;
struct SpirvShader
uint32_t type;
uint32_t result;
bool hasType;
bool hasResult;
SpvOperand operand[8];
};
int32_t read(bx::ReaderI* _reader, SpvInstruction& _instruction, bx::Error* _err);
int32_t write(bx::WriterI* _writer, const SpvInstruction& _instruction, bx::Error* _err);
int32_t toString(char* _out, int32_t _size, const SpvInstruction& _instruction);
struct SpvShader
{
stl::vector<uint8_t> byteCode;
};
int32_t read(bx::ReaderSeekerI* _reader, SpirvShader& _shader);
int32_t write(bx::WriterI* _writer, const SpirvShader& _shader);
int32_t read(bx::ReaderSeekerI* _reader, SpvShader& _shader, bx::Error* _err);
int32_t write(bx::WriterI* _writer, const SpvShader& _shader, bx::Error* _err);
typedef bool (*SpirvParseFn)(uint32_t _offset, const SpirvInstruction& _instruction, void* _userData);
void parse(const SpirvShader& _src, SpirvParseFn _fn, void* _userData);
typedef bool (*SpirvParseFn)(uint32_t _offset, const SpvInstruction& _instruction, void* _userData);
void parse(const SpvShader& _src, SpirvParseFn _fn, void* _userData, bx::Error* _err = NULL);
typedef void (*SpirvFilterFn)(SpirvInstruction& _instruction, void* _userData);
void filter(SpirvShader& _dst, const SpirvShader& _src, SpirvFilterFn _fn, void* _userData);
typedef void (*SpirvFilterFn)(SpvInstruction& _instruction, void* _userData);
void filter(SpvShader& _dst, const SpvShader& _src, SpirvFilterFn _fn, void* _userData, bx::Error* _err = NULL);
struct Spirv
struct SpirV
{
struct Header
{
@ -533,11 +617,11 @@ namespace bgfx
};
Header header;
SpirvShader shader;
SpvShader shader;
};
int32_t read(bx::ReaderSeekerI* _reader, Spirv& _spirv);
int32_t write(bx::WriterSeekerI* _writer, const Spirv& _spirv);
int32_t read(bx::ReaderSeekerI* _reader, SpirV& _spirv, bx::Error* _err);
int32_t write(bx::WriterSeekerI* _writer, const SpirV& _spirv, bx::Error* _err);
} // namespace bgfx