#glsl-shader #spir-v #glsl #hlsl #opengl #vulkan #graphics

app shader-reflect

SPIR-V/GLSL/HLSL 着色器接口反射到 JSON。(命令行界面)

8 个版本

0.2.9 2024 年 7 月 6 日
0.2.7 2024 年 3 月 23 日
0.2.4 2023 年 12 月 26 日
0.2.3 2023 年 6 月 1 日
0.2.0 2022 年 10 月 3 日

#525图形 API

MIT/Apache

120KB
3K SLoC

Shader Reflect

Crate

shader-reflect 是着色器反射库 spirq 的命令行界面。它从 SPIR-V 着色器二进制文件生成反射 JSON。您可以使用以下命令安装 shader-reflect

cargo install shader-reflect

用法

运行以下命令以将 GLSL/HLSL 着色器源SPIR-V 二进制文件 反射为 JSON 报告

# GLSL Shader source.
shader-reflect assets/spirv-spec.frag
# SPIR-V binary.
shader-reflect assets/spirv-spec.frag.spv

或者如果您想要反射所有声明的资源,即使它们在着色器中从未使用过。

shader-reflect assets/spirv-spec.frag.spv --reference-all-resources

请运行 shader-reflect -h 以获取所有可用的命令行选项的详细说明。

Light weight SPIR-V query utility for graphics. (CLI)

Usage: shader-reflect [OPTIONS] <IN_PATH>

Arguments:
  <IN_PATH>  Input SPIR-V file paths.

Options:
  -o, --out-path <OUT_PATH>        Output JSON file path. The output is printed to stdout if this path is not given.
      --reference-all-resources    Reference all resources even they are never used by the entry points. By default, only the referenced resources are reflected.
      --combine-image-samplers     Combine separate sampled image and sampler at a same descriptor set and binding. By default, they are listed as separate objects.
      --generate-unique-names      Generate unique names for every resource variable, structure types, and type members. By default, the names are assigned with debug annotations in the input SPIR-V.
  -I <INCLUDE_DIRECTORIES>         The base directories of standard includes (`#include <...>`) in compilation of GLSL or HLSL shader sources.
  -D <DEFINITIONS>                 Compiler definitions in compilation of GLSL or HLSL shader sources.
  -e, --entry-point <ENTRY_POINT>  Shader entry point function name in compilation of GLSL or HLSL shader.
  -h, --help                       Print help information
  -V, --version                    Print version information

支持的着色器类型

shader-reflect 支持Vulkan中所有可用的着色器类型,包括光线追踪着色器和网格着色器。从着色器源编译时,着色器类型根据扩展名推断。扩展名遵循 glslangValidator 的约定。

扩展 着色器阶段
.vert 顶点着色器
.tesc 曲面控制着色器(或 hull 着色器)
.tese 曲面评估着色器(或 domain 着色器)
.geom 几何着色器
.frag 片段着色器
.comp 计算着色器
.mesh 网格着色器
.task 任务着色器
.rgen 光线生成着色器
.rint 交点着色器
.rahit 任何击中着色器
.rchit 最近击中着色器
.rmiss 丢失着色器
.rcall 可调用着色器

可以将后缀 .glsl.hlsl 添加到文件名中,以显式指定着色语言。默认情况下,shader-reflect 假设使用 GLSL。例如,foo.vertbar.frag.glsl 被视为 GLSL 着色器;baz.comp.hlsl 被视为 HLSL 着色器。

示例输出

spirv-spec.frag.spv 二进制文件在 spirq 仓库中给出以下输出

{
  "EntryPoint": "main",
  "ExecutionModel": "Fragment",
  "Variables": {
    "Inputs": [
      {
        "Name": "_42",
        "Location": 2,
        "Component": 0,
        "Type": "vec4<f32>"
      },
      {
        "Name": "_57",
        "Location": 1,
        "Component": 0,
        "Type": "vec4<f32>"
      },
      {
        "Name": "_33",
        "Location": 0,
        "Component": 0,
        "Type": "vec4<f32>"
      }
    ],
    "Outputs": [
      {
        "Name": "_31",
        "Location": 0,
        "Component": 0,
        "Type": "vec4<f32>"
      }
    ],
    "Descriptors": [
      {
        "Name": "_20",
        "Set": 0,
        "Binding": 0,
        "DescriptorType": "UniformBuffer",
        "Type": {
          "Kind": "Struct",
          "Members": [
            {
              "Name": "_18_0",
              "Offset": 0,
              "MemberType": {
                "Kind": "Struct",
                "Members": [
                  {
                    "Name": "_17_0",
                    "Offset": 0,
                    "MemberType": "u32"
                  },
                  {
                    "Name": "_17_1",
                    "Offset": 16,
                    "MemberType": {
                      "Kind": "Array",
                      "ElementType": "vec4<f32>",
                      "Count": 5,
                      "Stride": 16
                    }
                  },
                  {
                    "Name": "_17_2",
                    "Offset": 96,
                    "MemberType": "i32"
                  }
                ]
              }
            },
            {
              "Name": "_18_1",
              "Offset": 112,
              "MemberType": "u32"
            }
          ]
        },
        "Count": 1
      }
    ],
    "PushConstants": [],
    "SpecConstants": []
  }
}

依赖项

~33MB
~722K SLoC