hecrj / wgpu_glyph

A fast text renderer for wgpu (https://github.com/gfx-rs/wgpu)
https://docs.rs/wgpu_glyph
MIT License
443 stars 77 forks source link

My Uniform Overrides Internal Transform Uniform #35

Closed PolyMeilex closed 4 years ago

PolyMeilex commented 4 years ago

Hi I encountered a problem when using wgpu with DX12. The following issue did not appear when using wgpu with Vulcan on linux.

As soon as I create a bind group it overrides one inside of glyph. In this case, it is transform uniform. For example if I edit examples/hello.rs like so:

... [Begining Of The File]
let mut glyph_brush = GlyphBrushBuilder::using_font_bytes(inconsolata)
        .expect("Load fonts")
        .build(&device, render_format);

//Here I create my uniform, that should not interrupt glyph inner workings
{
        let data = TransformUniform::default();

        let bind_group_layout_descriptor = wgpu::BindGroupLayoutDescriptor {
            label: Some("new_1"),
            bindings: &[wgpu::BindGroupLayoutEntry {
                binding: 1,
                visibility: wgpu::ShaderStage::VERTEX,
                ty: wgpu::BindingType::UniformBuffer { dynamic: false },
            }],
        };

        let buffer = device.create_buffer_with_data(
            &data.as_bytes(),
            wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
        );

        let bind_group_layout =
            device.create_bind_group_layout(&bind_group_layout_descriptor);

        let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
            label: Some("new_2"),
            layout: &bind_group_layout,
            bindings: &[wgpu::Binding {
                binding: 1,
                resource: wgpu::BindingResource::Buffer {
                    buffer: &buffer,
                    range: 0..std::mem::size_of_val(&data)
                        as wgpu::BufferAddress,
                },
            }],
        });
}

#[repr(C)]
#[derive(Clone, Copy, AsBytes)]
struct TransformUniform {
    transform: [f32; 16],
}
impl Default for TransformUniform {
    fn default() -> Self {
        Self {
            // Here I intentionally create projection with wrong size to demonstrate that it affects glyph
            transform: orthographic_projection(100.0, 100.0),
        }
    }
}

... [Rest Of The File]

It gives me output like this ing Same Code on Linux with Vulcan ing

This issue is probably not wgpu-glyph related and should be submitted to main wgpu repo, but I decided to ask here first in case I made some stupid mistake related to my small wgpu knowledge

PolyMeilex commented 4 years ago

I installed windows 10 on a second hard drive, and it turns out that this only happens inside of Virtualbox. Closing down for this reason.