[SPIR-V] Don't bother setting up vertex bindings if they aren't used.
This commit is contained in:
parent
be687f5f27
commit
a3cf3a7694
|
@ -223,32 +223,34 @@ void SpirvShaderTranslator::StartTranslation() {
|
||||||
// Vertex inputs/outputs
|
// Vertex inputs/outputs
|
||||||
// Inputs: 32 SSBOs on DS 2 binding 0
|
// Inputs: 32 SSBOs on DS 2 binding 0
|
||||||
|
|
||||||
// Runtime array for vertex data
|
if (!vertex_bindings().empty()) {
|
||||||
Id vtx_t = b.makeRuntimeArray(uint_type_);
|
// Runtime array for vertex data
|
||||||
b.addDecoration(vtx_t, spv::Decoration::DecorationArrayStride,
|
Id vtx_t = b.makeRuntimeArray(uint_type_);
|
||||||
sizeof(uint32_t));
|
b.addDecoration(vtx_t, spv::Decoration::DecorationArrayStride,
|
||||||
|
sizeof(uint32_t));
|
||||||
|
|
||||||
Id vtx_s = b.makeStructType({vtx_t}, "vertex_type");
|
Id vtx_s = b.makeStructType({vtx_t}, "vertex_type");
|
||||||
b.addDecoration(vtx_s, spv::Decoration::DecorationBufferBlock);
|
b.addDecoration(vtx_s, spv::Decoration::DecorationBufferBlock);
|
||||||
|
|
||||||
// Describe the actual data
|
// Describe the actual data
|
||||||
b.addMemberName(vtx_s, 0, "data");
|
b.addMemberName(vtx_s, 0, "data");
|
||||||
b.addMemberDecoration(vtx_s, 0, spv::Decoration::DecorationOffset, 0);
|
b.addMemberDecoration(vtx_s, 0, spv::Decoration::DecorationOffset, 0);
|
||||||
|
|
||||||
// Create the vertex bindings variable.
|
// Create the vertex bindings variable.
|
||||||
Id vtx_a_t = b.makeArrayType(
|
Id vtx_a_t = b.makeArrayType(
|
||||||
vtx_s, b.makeUintConstant(uint32_t(vertex_bindings().size())), 0);
|
vtx_s, b.makeUintConstant(uint32_t(vertex_bindings().size())), 0);
|
||||||
vtx_ = b.createVariable(spv::StorageClass::StorageClassUniform, vtx_a_t,
|
vtx_ = b.createVariable(spv::StorageClass::StorageClassUniform, vtx_a_t,
|
||||||
"vertex_bindings");
|
"vertex_bindings");
|
||||||
|
|
||||||
// DS 2 binding 0
|
// DS 2 binding 0
|
||||||
b.addDecoration(vtx_, spv::Decoration::DecorationDescriptorSet, 2);
|
b.addDecoration(vtx_, spv::Decoration::DecorationDescriptorSet, 2);
|
||||||
b.addDecoration(vtx_, spv::Decoration::DecorationBinding, 0);
|
b.addDecoration(vtx_, spv::Decoration::DecorationBinding, 0);
|
||||||
b.addDecoration(vtx_, spv::Decoration::DecorationNonWritable);
|
b.addDecoration(vtx_, spv::Decoration::DecorationNonWritable);
|
||||||
|
|
||||||
// Set up the map from binding -> ssbo index
|
// Set up the map from binding -> ssbo index
|
||||||
for (const auto& binding : vertex_bindings()) {
|
for (const auto& binding : vertex_bindings()) {
|
||||||
vtx_binding_map_[binding.fetch_constant] = binding.binding_index;
|
vtx_binding_map_[binding.fetch_constant] = binding.binding_index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outputs
|
// Outputs
|
||||||
|
@ -1462,10 +1464,14 @@ void SpirvShaderTranslator::ProcessVertexFetchInstruction(
|
||||||
spv::StorageClass::StorageClassUniform, data_ptr, {vertex_idx});
|
spv::StorageClass::StorageClassUniform, data_ptr, {vertex_idx});
|
||||||
auto vertex_data = b.createLoad(vertex_ptr);
|
auto vertex_data = b.createLoad(vertex_ptr);
|
||||||
|
|
||||||
|
assert_true(instr.attributes.is_integer);
|
||||||
|
assert_true(instr.attributes.is_signed);
|
||||||
vertex = b.createUnaryOp(spv::Op::OpBitcast, float_type_, vertex_data);
|
vertex = b.createUnaryOp(spv::Op::OpBitcast, float_type_, vertex_data);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VertexFormat::k_32_32_FLOAT: {
|
case VertexFormat::k_32_32_FLOAT: {
|
||||||
|
assert_true(instr.attributes.is_integer);
|
||||||
|
assert_true(instr.attributes.is_signed);
|
||||||
spv::Id components[2] = {};
|
spv::Id components[2] = {};
|
||||||
for (uint32_t i = 0; i < 2; i++) {
|
for (uint32_t i = 0; i < 2; i++) {
|
||||||
auto index = b.createBinOp(spv::Op::OpIAdd, int_type_, vertex_idx,
|
auto index = b.createBinOp(spv::Op::OpIAdd, int_type_, vertex_idx,
|
||||||
|
@ -1481,7 +1487,10 @@ void SpirvShaderTranslator::ProcessVertexFetchInstruction(
|
||||||
vertex = b.createCompositeConstruct(vec2_float_type_,
|
vertex = b.createCompositeConstruct(vec2_float_type_,
|
||||||
{components[0], components[1]});
|
{components[0], components[1]});
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VertexFormat::k_32_32_32_FLOAT: {
|
case VertexFormat::k_32_32_32_FLOAT: {
|
||||||
|
assert_true(instr.attributes.is_integer);
|
||||||
|
assert_true(instr.attributes.is_signed);
|
||||||
spv::Id components[3] = {};
|
spv::Id components[3] = {};
|
||||||
for (uint32_t i = 0; i < 3; i++) {
|
for (uint32_t i = 0; i < 3; i++) {
|
||||||
auto index = b.createBinOp(spv::Op::OpIAdd, int_type_, vertex_idx,
|
auto index = b.createBinOp(spv::Op::OpIAdd, int_type_, vertex_idx,
|
||||||
|
@ -1499,6 +1508,8 @@ void SpirvShaderTranslator::ProcessVertexFetchInstruction(
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case VertexFormat::k_32_32_32_32_FLOAT: {
|
case VertexFormat::k_32_32_32_32_FLOAT: {
|
||||||
|
assert_true(instr.attributes.is_integer);
|
||||||
|
assert_true(instr.attributes.is_signed);
|
||||||
spv::Id components[4] = {};
|
spv::Id components[4] = {};
|
||||||
for (uint32_t i = 0; i < 4; i++) {
|
for (uint32_t i = 0; i < 4; i++) {
|
||||||
auto index = b.createBinOp(spv::Op::OpIAdd, int_type_, vertex_idx,
|
auto index = b.createBinOp(spv::Op::OpIAdd, int_type_, vertex_idx,
|
||||||
|
|
Loading…
Reference in New Issue