[SPIR-V] Don't bother setting up vertex bindings if they aren't used.

This commit is contained in:
DrChat 2018-02-19 12:45:17 -06:00
parent be687f5f27
commit a3cf3a7694
1 changed files with 32 additions and 21 deletions

View File

@ -223,6 +223,7 @@ 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
if (!vertex_bindings().empty()) {
// Runtime array for vertex data // Runtime array for vertex data
Id vtx_t = b.makeRuntimeArray(uint_type_); Id vtx_t = b.makeRuntimeArray(uint_type_);
b.addDecoration(vtx_t, spv::Decoration::DecorationArrayStride, b.addDecoration(vtx_t, spv::Decoration::DecorationArrayStride,
@ -250,6 +251,7 @@ void SpirvShaderTranslator::StartTranslation() {
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
interpolators_ = b.createVariable(spv::StorageClass::StorageClassOutput, interpolators_ = b.createVariable(spv::StorageClass::StorageClassOutput,
@ -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,