Description
I'm working on occlusion culling and can't seem to write to a texture in my compute shader. wgpu
wants the storage texture to be write-only, but there's no way to express that from my rust-gpu
shader.
Specifically we need to add AccessQualifier
to the Image
type variables.
Related to:
- Add
AccessQualifier
s toImage
, theImage!
macro and codegen EmbarkStudios/rust-gpu#1116 - spirv-std/
Image!
should exposeAccessQualifier
. EmbarkStudios/rust-gpu#1097
And in one of those issues @eddyb says:
That is, this is an OpenCL feature, not a Vulkan one, and wgpu couldn't possibly make use of it (unless they misunderstood the specification, too?).
But it looks like this is used in Vulkan, at least in compute. And I'm hitting it in my use of wgpu
.
I expect that I can try to tackle this, unless someone gets to it first.
Expected Behaviour
I expect to be able to specify that an Image
is read-only, write-only, or read and write.
Example & Steps To Reproduce
Create a shader that uses a texture that gets written to. Try to use that shader in a wgpu
compute pipeline.
My specific pipeline validation error is this:
wgpu error: Validation Error
Caused by:
In Device::create_compute_pipeline, label = 'compute-occlusion-copy-depth-to-pyramid'
Error matching shader requirements against the pipeline
Shader global ResourceBinding { group: 0, binding: 2 } is not available in the pipeline layout
Texture class Storage { format: R32Float, access: StorageAccess(STORE) } doesn't match the shader Storage { format: R32Float, access: StorageAccess(LOAD | STORE) }
But yours would be different.
I should also add that simply marking my storage texture as LOAD | STORE
(read+write) from wgpu
is not an option for me as I am targeting WebGPU, and read+write storage textures is a native-only opt-in feature ;).
Shader
pub type DepthImage2d = Image!(2D, type=f32, sampled=true, depth=true);
pub type DepthPyramidImage = Image!(2D, format = r32f, sampled = true, depth = false);
pub type DepthPyramidImageMut = Image!(2D, format = r32f, sampled = false, depth = false); // this needs to be write-only
/// Copies a depth texture to the top mip of a pyramid of mips.
#[spirv(compute(threads(32)))]
pub fn compute_copy_depth_to_pyramid(
#[spirv(descriptor_set = 0, binding = 0, storage_buffer)] desc: &PyramidDescriptor,
#[spirv(descriptor_set = 0, binding = 1)] depth_texture: &DepthImage2d,
#[spirv(descriptor_set = 0, binding = 2)] mip: &DepthPyramidImageMut,
#[spirv(global_invocation_id)] global_id: UVec3,
) {
if desc.should_skip_invocation(global_id) {
return;
}
let depth: Vec4 = depth_texture.fetch_with(global_id.xy(), sample_with::lod(0));
unsafe {
mip.write(global_id.xy(), depth);
}
}