Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AccessQualifier to Image #28

Closed
schell opened this issue Oct 10, 2024 · 1 comment
Closed

Add AccessQualifier to Image #28

schell opened this issue Oct 10, 2024 · 1 comment
Assignees

Comments

@schell
Copy link
Contributor

schell commented Oct 10, 2024

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:

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);
    }
}
@schell
Copy link
Contributor Author

schell commented Oct 12, 2024

I think I was barking up the wrong tree. It seems the problem is likely with wgpu, and I'm not sure it's possible to use Image::write on any storage texture with wgpu until something gets fixed, but I'll die on that hill later.

I'll close this and if we ever need it again we can resurrect it later.

@schell schell closed this as completed Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant