4 releases
0.2.1 | Oct 14, 2024 |
---|---|
0.2.0 | Oct 4, 2024 |
0.1.1 | Oct 1, 2024 |
0.1.0 | Sep 30, 2024 |
#390 in Graphics APIs
725 downloads per month
27KB
531 lines
SPIRV Combined Image Sampler Splitter
It is commonly known that WebGpu does not support combined image samplers. This makes adding WebGpu support for existing OpenGL or Vulkan renderers impossible without workarounds. This is one such workaround. By reading and modifying SPIRV byte code, combined image samplers can be split into their respective texture and sampler. Special edge cases such as the use of combined image samplers in function parameters and nested functions are also handled.
layout(set = 0, binding = 0) uniform sampler2D u_texture;
// is converted into...
layout(set = 0, binding = 0) uniform texture2D u_texture;
layout(set = 0, binding = 1) uniform sampler u_sampler;
Enjoy!
Library Usage
let spv_bytes: Vec<u8> = fs::read("in.spv").unwrap();
let spv: Vec<u32> = spirv_combimgsampsplitter::u8_slice_to_u32_vec(&spv_bytes);
let out_spv: Vec<u32> = spirv_combimgsampsplitter::combimgsampsplitter(&spv).unwrap();
let out_spv_bytes = spirv_combimgsampsplitter::u32_slice_to_u8_vec(&out_spv);
fs::write("out.spv", out_spv_bytes).unwrap();
CLI Usage
spirv_combimgsampsplitter in.spv out.spv
# or
cargo r -- in.spv out.spv