docs/src/spirv-minimization.md
When debugging problems with SPIR-V generated by rust-gpu, you occasionally need to reduce the SPIR-V in order to make it easily shareable with others. We've created a short guide on how to do that.
In order to build and validate SPIR-V you're going to install SPIR-V tools.
SPIR-V has some amount of required boilerplate in order to be considered valid, we've created a small template to help to get started. This file creates a single empty vertex entry-point with a single floating-point constant.
; bug.spvasm
OpCapability Shader
OpCapability VulkanMemoryModel
OpMemoryModel Logical Vulkan
; == Entry-points ==
OpEntryPoint Vertex %vert_fn "vert"
; == Types ==
%void = OpTypeVoid
%f32 = OpTypeFloat 32
; Function Types
%void_fn = OpTypeFunction %void
; == Constants ==
%f32_1 = OpConstant %f32 1
; == Functions ==
%vert_fn = OpFunction %void None %void_fn
%block = OpLabel
OpReturn
OpFunctionEnd
Assemble your spirv with spirv-as ./bug.spvasm, this will produce a
out.spv file containing the assembled code.
The assembled code also needs to be validated with spirv-val out.spv
Once the code has been validated as having no issues, you can use
spirv-cross to compile the code to various outputs.
spirv-cross out.spvspirv-cross --hlsl out.spvspirv-cross --msl out.spvspirv-cross -V out.spv