Skip to content

Commit

Permalink
spirv-hopper: Add non 32-bit support
Browse files Browse the repository at this point in the history
  • Loading branch information
spencer-lunarg committed Jul 5, 2023
1 parent bc9d55d commit 1b4eb58
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build-android/known_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"name": "SPIRV-Tools",
"url": "https://github.com/KhronosGroup/SPIRV-Tools.git",
"sub_dir": "shaderc/third_party/spirv-tools",
"commit": "04cdb2d344706052c7a2d359294e830ebac63e74"
"commit": "870fd1e17aff8ede9aa12e647754780067306fe6"
},
{
"name": "SPIRV-Headers",
Expand Down
4 changes: 2 additions & 2 deletions scripts/known_good.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
"-DSPIRV_SKIP_TESTS=ON",
"-DSPIRV_SKIP_EXECUTABLES=ON"
],
"commit": "04cdb2d344706052c7a2d359294e830ebac63e74"
"commit": "870fd1e17aff8ede9aa12e647754780067306fe6"
},
{
"name": "SPIRV-Reflect",
"url": "https://github.com/KhronosGroup/SPIRV-Reflect.git",
"sub_dir": "SPIRV-Reflect",
"install_dir": "SPIRV-Reflect",
"build_step": "skip",
"commit": "87442baff70befd0523a0e7148fc4e68b71f4bb9",
"commit": "8f91541618da0c756a556f00fde722fae0c1b412",
"optional": [
"tests"
]
Expand Down
24 changes: 20 additions & 4 deletions tests/spirv_hopper/pass_through_shaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

static constexpr bool IsFloatFormat(SpvReflectFormat format) {
switch (format) {
case SPV_REFLECT_FORMAT_R16_SFLOAT:
case SPV_REFLECT_FORMAT_R16G16_SFLOAT:
case SPV_REFLECT_FORMAT_R16G16B16_SFLOAT:
case SPV_REFLECT_FORMAT_R16G16B16A16_SFLOAT:
case SPV_REFLECT_FORMAT_R32_SFLOAT:
case SPV_REFLECT_FORMAT_R32G32_SFLOAT:
case SPV_REFLECT_FORMAT_R32G32B32_SFLOAT:
Expand Down Expand Up @@ -52,26 +56,33 @@ std::string Hopper::GetTypeDescription(SpvReflectTypeDescription& description, S
}
}

const bool isSigned = (description.traits.numeric.scalar.signedness != 0);
const bool is32Bit = (description.traits.numeric.scalar.width == 32);
const std::string width = is32Bit ? "" : std::to_string(description.traits.numeric.scalar.width);

switch (description.op) {
case SpvOp::SpvOpTypeBool: {
type += "bool";
break;
}
case SpvOp::SpvOpTypeFloat: {
type += "float";
type += is32Bit ? "" : (width + "_t");
break;
}
case SpvOp::SpvOpTypeInt: {
if (description.traits.numeric.scalar.signedness == 0) {
type += "u";
}
type += !isSigned ? "u" : "";
type += "int";
type += is32Bit ? "" : (width + "_t");
break;
}
case SpvOp::SpvOpTypeVector: {
if (!IsFloatFormat(format)) {
type += (description.traits.numeric.scalar.signedness == 0) ? "u" : "i";
type += isSigned ? "i" : "u";
} else if (!is32Bit) {
type += "f";
}
type += is32Bit ? "" : width;
type += "vec";
const uint32_t component_count = description.traits.numeric.vector.component_count;
type += std::to_string(component_count);
Expand Down Expand Up @@ -146,6 +157,11 @@ bool Hopper::CreatePassThroughVertex() {
BuildOrderedVariableMap(input_variables, variable_ordered_map);

std::string shader = "#version 450\n";
// Add extensions regardless, keeps things simple
shader += "#extension GL_EXT_shader_explicit_arithmetic_types: enable\n";
shader += "#extension GL_EXT_shader_16bit_storage: enable\n";
shader += "#extension GL_EXT_shader_8bit_storage: enable\n";

for (auto entry : variable_ordered_map) {
const SpvReflectInterfaceVariable& variable = *entry.second;
if (IsBuiltinType(variable)) {
Expand Down

0 comments on commit 1b4eb58

Please sign in to comment.