[GPU] Use uint4 for loop/bool constants to meet std140 packing requirements.
This commit is contained in:
parent
2bd9bae0f4
commit
83a9cb3435
|
@ -118,16 +118,18 @@ void SpirvShaderTranslator::StartTranslation() {
|
||||||
// Uniform constants.
|
// Uniform constants.
|
||||||
Id float_consts_type =
|
Id float_consts_type =
|
||||||
b.makeArrayType(vec4_float_type_, b.makeUintConstant(512), 1);
|
b.makeArrayType(vec4_float_type_, b.makeUintConstant(512), 1);
|
||||||
Id loop_consts_type = b.makeArrayType(uint_type_, b.makeUintConstant(32), 1);
|
Id loop_consts_type =
|
||||||
Id bool_consts_type = b.makeArrayType(uint_type_, b.makeUintConstant(8), 1);
|
b.makeArrayType(vec4_uint_type_, b.makeUintConstant(8), 1);
|
||||||
|
Id bool_consts_type =
|
||||||
|
b.makeArrayType(vec4_uint_type_, b.makeUintConstant(2), 1);
|
||||||
|
|
||||||
// Strides
|
// Strides
|
||||||
b.addDecoration(float_consts_type, spv::Decoration::DecorationArrayStride,
|
b.addDecoration(float_consts_type, spv::Decoration::DecorationArrayStride,
|
||||||
4 * sizeof(float));
|
4 * sizeof(float));
|
||||||
b.addDecoration(loop_consts_type, spv::Decoration::DecorationArrayStride,
|
b.addDecoration(loop_consts_type, spv::Decoration::DecorationArrayStride,
|
||||||
sizeof(uint32_t));
|
4 * sizeof(uint32_t));
|
||||||
b.addDecoration(bool_consts_type, spv::Decoration::DecorationArrayStride,
|
b.addDecoration(bool_consts_type, spv::Decoration::DecorationArrayStride,
|
||||||
sizeof(uint32_t));
|
4 * sizeof(uint32_t));
|
||||||
|
|
||||||
Id consts_struct_type = b.makeStructType(
|
Id consts_struct_type = b.makeStructType(
|
||||||
{float_consts_type, loop_consts_type, bool_consts_type}, "consts_type");
|
{float_consts_type, loop_consts_type, bool_consts_type}, "consts_type");
|
||||||
|
@ -824,9 +826,11 @@ void SpirvShaderTranslator::ProcessExecInstructionBegin(
|
||||||
// Based off of bool_consts
|
// Based off of bool_consts
|
||||||
std::vector<Id> offsets;
|
std::vector<Id> offsets;
|
||||||
offsets.push_back(b.makeUintConstant(2)); // bool_consts
|
offsets.push_back(b.makeUintConstant(2)); // bool_consts
|
||||||
offsets.push_back(b.makeUintConstant(instr.bool_constant_index / 32));
|
uint32_t bitfield_index = instr.bool_constant_index / 32;
|
||||||
|
offsets.push_back(b.makeUintConstant(bitfield_index / 4));
|
||||||
auto v = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
auto v = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
||||||
consts_, offsets);
|
consts_, offsets);
|
||||||
|
v = b.createCompositeExtract(v, vec4_uint_type_, bitfield_index % 4);
|
||||||
v = b.createLoad(v);
|
v = b.createLoad(v);
|
||||||
|
|
||||||
// Bitfield extract the bool constant.
|
// Bitfield extract the bool constant.
|
||||||
|
@ -836,6 +840,7 @@ void SpirvShaderTranslator::ProcessExecInstructionBegin(
|
||||||
b.makeUintConstant(instr.bool_constant_index % 32),
|
b.makeUintConstant(instr.bool_constant_index % 32),
|
||||||
b.makeUintConstant(1));
|
b.makeUintConstant(1));
|
||||||
|
|
||||||
|
// Conditional branch
|
||||||
auto cond = b.createBinOp(spv::Op::OpIEqual, bool_type_, v,
|
auto cond = b.createBinOp(spv::Op::OpIEqual, bool_type_, v,
|
||||||
b.makeUintConstant(instr.condition ? 1 : 0));
|
b.makeUintConstant(instr.condition ? 1 : 0));
|
||||||
*/
|
*/
|
||||||
|
@ -923,9 +928,11 @@ void SpirvShaderTranslator::ProcessLoopStartInstruction(
|
||||||
|
|
||||||
std::vector<Id> offsets;
|
std::vector<Id> offsets;
|
||||||
offsets.push_back(b.makeUintConstant(1)); // loop_consts
|
offsets.push_back(b.makeUintConstant(1)); // loop_consts
|
||||||
offsets.push_back(b.makeUintConstant(instr.loop_constant_index));
|
offsets.push_back(b.makeUintConstant(instr.loop_constant_index / 4));
|
||||||
auto loop_const = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
auto loop_const = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
||||||
consts_, offsets);
|
consts_, offsets);
|
||||||
|
loop_const = b.createCompositeExtract(loop_const, vec4_uint_type_,
|
||||||
|
instr.loop_constant_index % 4);
|
||||||
loop_const = b.createLoad(loop_const);
|
loop_const = b.createLoad(loop_const);
|
||||||
|
|
||||||
// uint loop_count_value = loop_const & 0xFF;
|
// uint loop_count_value = loop_const & 0xFF;
|
||||||
|
@ -1029,9 +1036,11 @@ void SpirvShaderTranslator::ProcessLoopEndInstruction(
|
||||||
|
|
||||||
std::vector<Id> offsets;
|
std::vector<Id> offsets;
|
||||||
offsets.push_back(b.makeUintConstant(1)); // loop_consts
|
offsets.push_back(b.makeUintConstant(1)); // loop_consts
|
||||||
offsets.push_back(b.makeUintConstant(instr.loop_constant_index));
|
offsets.push_back(b.makeUintConstant(instr.loop_constant_index / 4));
|
||||||
auto loop_const = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
auto loop_const = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
||||||
consts_, offsets);
|
consts_, offsets);
|
||||||
|
loop_const = b.createCompositeExtract(loop_const, vec4_uint_type_,
|
||||||
|
instr.loop_constant_index % 4);
|
||||||
loop_const = b.createLoad(loop_const);
|
loop_const = b.createLoad(loop_const);
|
||||||
|
|
||||||
// uint loop_aL_value = (loop_const >> 16) & 0xFF;
|
// uint loop_aL_value = (loop_const >> 16) & 0xFF;
|
||||||
|
@ -1101,14 +1110,16 @@ void SpirvShaderTranslator::ProcessJumpInstruction(
|
||||||
// Based off of bool_consts
|
// Based off of bool_consts
|
||||||
std::vector<Id> offsets;
|
std::vector<Id> offsets;
|
||||||
offsets.push_back(b.makeUintConstant(2)); // bool_consts
|
offsets.push_back(b.makeUintConstant(2)); // bool_consts
|
||||||
offsets.push_back(b.makeUintConstant(instr.bool_constant_index / 32));
|
uint32_t bitfield_index = instr.bool_constant_index / 32;
|
||||||
|
offsets.push_back(b.makeUintConstant(bitfield_index / 4));
|
||||||
auto v = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
auto v = b.createAccessChain(spv::StorageClass::StorageClassUniform,
|
||||||
consts_, offsets);
|
consts_, offsets);
|
||||||
|
v = b.createCompositeExtract(v, vec4_uint_type_, bitfield_index % 4);
|
||||||
v = b.createLoad(v);
|
v = b.createLoad(v);
|
||||||
|
|
||||||
|
// Bitfield extract the bool constant.
|
||||||
// FIXME: NVidia's compiler seems to be broken on this instruction?
|
// FIXME: NVidia's compiler seems to be broken on this instruction?
|
||||||
/*
|
/*
|
||||||
// Bitfield extract the bool constant.
|
|
||||||
v = b.createTriOp(spv::Op::OpBitFieldUExtract, uint_type_, v,
|
v = b.createTriOp(spv::Op::OpBitFieldUExtract, uint_type_, v,
|
||||||
b.makeUintConstant(instr.bool_constant_index % 32),
|
b.makeUintConstant(instr.bool_constant_index % 32),
|
||||||
b.makeUintConstant(1));
|
b.makeUintConstant(1));
|
||||||
|
|
Loading…
Reference in New Issue