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

TextureFormat::R16Uint isn't usable #3014

Open
aloucks opened this issue Oct 23, 2021 · 3 comments
Open

TextureFormat::R16Uint isn't usable #3014

aloucks opened this issue Oct 23, 2021 · 3 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@aloucks
Copy link
Contributor

aloucks commented Oct 23, 2021

Bevy version

pipelined-rendering branch: 432ce72

Operating system & version

Windows 10

What you did

Tried to use TextureFormat::R16Uint with utexture2D and texelFetch.

My preference would be to use R16unorm, but it doesn't currently exist. I'm attempting to use R16Uint as a work-around and normalize it in the shader.

Related:
gfx-rs/wgpu#1934
gfx-rs/wgpu#2107

What you expected to happen

The shader would source data via texelFetch.

What actually happened

WGPU Error

Oct 23 12:15:20.140 ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_render_pipeline
    error matching VERTEX shader requirements against the pipeline
    shader global ResourceBinding { group: 2, binding: 3 } is not available in the layout pipeline layout
    texture class Sampled { kind: Float, multi: false } doesn't match the shader Sampled { kind: Uint, multi: false }

Additional information

#version 450
#extension GL_EXT_samplerless_texture_functions : require

layout(set = 2, binding = 3) uniform utexture2D ChunkMaterial_height_map;

void main() {
    // ...
    uvec4 height_sample = texelFetch(ChunkMaterial_height_map, ivec2(v_UV.x, v_UV.y), 0);
}
let mut height_texture = Texture::new(size, dimension, height_data, TextureFormat::R16Uint);

It looks like the issue is that the sample type is hard coded instead of reflected:

ReflectDescriptorType::SampledImage => (
&binding.name,
BindType::Texture {
view_dimension: reflect_dimension(type_description),
sample_type: TextureSampleType::Float { filterable: true },
multisampled: false,
},
),

@aloucks aloucks added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 23, 2021
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Oct 23, 2021
@aloucks
Copy link
Contributor Author

aloucks commented Oct 23, 2021

After debugging this further, I noticed that the image format on the reflected binding is Undefined. There's isn't anything to derive the sample type from. Should bevy expose the TextureSampleType as an attribute of the Texture?

ReflectDescriptorBinding {
    spirv_id: 66,
    name: "ChunkMaterial_height_map",
    binding: 3,
    input_attachment_index: 0,
    set: 2,
    descriptor_type: SampledImage,
    resource_type: ShaderResourceView,
    image: ReflectImageTraits {
        dim: Type2d,
        depth: 0,
        arrayed: 0,
        ms: 0,
        sampled: 1,
        image_format: Undefined,
    },
    block: ReflectBlockVariable {
        spirv_id: 0,
        name: "",
        offset: 0,
        absolute_offset: 0,
        size: 0,
        padded_size: 0,
        decoration_flags: NONE,
        numeric: ReflectNumericTraits {
            scalar: ReflectNumericTraitsScalar {
                width: 0,
                signedness: 0,
            },
            vector: ReflectNumericTraitsVector {
                component_count: 0,
            },
            matrix: ReflectNumericTraitsMatrix {
                column_count: 0,
                row_count: 0,
                stride: 0,
            },
        },
        array: ReflectArrayTraits {
            dims: [],
            stride: 0,
        },
        members: [],
        type_description: None,
    },
    array: ReflectBindingArrayTraits {
        dims: [],
    },
    count: 1,
    uav_counter_id: 4294967295,
    uav_counter_binding: None,
    type_description: Some(
        ReflectTypeDescription {
            id: 64,
            op: ReflectOp(
                TypeImage,
            ),
            type_name: "",
            struct_member_name: "",
            storage_class: Undefined,
            type_flags: EXTERNAL_IMAGE,
            decoration_flags: NONE,
            traits: ReflectTypeDescriptionTraits {
                numeric: ReflectNumericTraits {
                    scalar: ReflectNumericTraitsScalar {
                        width: 0,
                        signedness: 0,
                    },
                    vector: ReflectNumericTraitsVector {
                        component_count: 0,
                    },
                    matrix: ReflectNumericTraitsMatrix {
                        column_count: 0,
                        row_count: 0,
                        stride: 0,
                    },
                },
                image: ReflectImageTraits {
                    dim: Type2d,
                    depth: 0,
                    arrayed: 0,
                    ms: 0,
                    sampled: 1,
                    image_format: Undefined,
                },
                array: ReflectArrayTraits {
                    dims: [],
                    stride: 0,
                },
            },
            members: [],
        },
    ),
    word_offset: (
        346,
        342,
    ),
    internal_data: 0x000001d49dd4f8e0,
}

@aloucks
Copy link
Contributor Author

aloucks commented Oct 23, 2021

As a hacky work-around, I attempted to update shader_refect.rs to have:

fn reflect_sample_type(binding: &ReflectDescriptorBinding) -> TextureSampleType {
    if binding.name.contains("height") {
        TextureSampleType::Uint
    } else {
        TextureSampleType::Float { filterable: true }
    }
}

// and set the sample_type via

BindType::Texture {
    view_dimension: reflect_dimension(type_description),
    sample_type: reflect_sample_type(binding),
    multisampled: false,
},

This got me past the WGPU error, but then the process aborted:

Oct 23 13:02:53.906  INFO naga::front::spv: Generated by 524296 version 10000
Oct 23 13:02:53.907  INFO naga::front::spv: Patching...
Oct 23 13:02:53.907  INFO naga::front::spv: Generated by 524296 version 10000    
Oct 23 13:02:53.907  INFO naga::front::spv: Patching...
error: process didn't exit successfully: `target\release\test5.exe` (exit code: 0xc000041d)

@kvark I had a similar process abort when trying to use R16Float. Could this be an issue with naga?

@kvark
Copy link

kvark commented Oct 24, 2021

No idea why it aborts. Could you catch it in a debugger and see the call stack?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

3 participants