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

Enable support for 3D textures #2481

Closed
wants to merge 1 commit into from
Closed

Enable support for 3D textures #2481

wants to merge 1 commit into from

Conversation

ryanw
Copy link

@ryanw ryanw commented Feb 15, 2022

Currently when attempting to create a 3D texture it panics with: internal error: entered unreachable code

But simply adding D3 to the match seems to work just fine. I've tested as far as creating a 3D texture and inspecting it using RenderDoc.

Here's an example of creating a texture that is fixed by this change:

device.create_texture(&wgpu::TextureDescriptor {
        label: Some("Voxel texture"),
        size: wgpu::Extent3d {
                width: 128,
                height: 128,
                depth_or_array_layers: 128,
        },
        mip_level_count: 1,
        sample_count: 1,
        dimension: wgpu::TextureDimension::D3,
        format: wgpu::TextureFormat::Rgba8UnormSrgb,
        usage: wgpu::TextureUsages::TEXTURE_BINDING
                | wgpu::TextureUsages::COPY_SRC
                | wgpu::TextureUsages::COPY_DST
                | wgpu::TextureUsages::RENDER_ATTACHMENT,
});

A 3D texture inside RenderDoc:
image

@@ -730,7 +730,7 @@ impl<A: HalApi> Device<A> {
let dimension = match desc.dimension {
wgt::TextureDimension::D1 => wgt::TextureViewDimension::D1,
wgt::TextureDimension::D2 => wgt::TextureViewDimension::D2,
wgt::TextureDimension::D3 => unreachable!(),
wgt::TextureDimension::D3 => wgt::TextureViewDimension::D3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it's not that simple. The matter of fact is that 3D textures aren't really renderable in baseline WebGPU. Creating 2D views of them is not portable. See gpuweb/gpuweb#2303 for a starting point.

In this case, we are missing a validation check that would see that the RENDER_ATTACHMENT usage is requested for a 3D texture and complain. This code path here is truly unreachable therefore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed gpuweb/gpuweb#2603 to address this in the spec. We'll still need to add the relevant validation code on our side.

FYI, your workaround should be making it a 2D array texture instead of 3D.

@kvark kvark closed this in #2482 Feb 15, 2022
cwfitzgerald pushed a commit that referenced this pull request Oct 25, 2023
…2481)

The `front::wgsl::lowerer::RuntimeExpressionContext::local_table`
field does not need to be a mutable reference, as expressions never
introduce new local bindings.
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 this pull request may close these issues.

2 participants