在WGSL中可以使用mat4x4<f32>作为统一的数据类型吗?
在这样做时,我会得到以下错误:
Shader validation error:
┌─ Shader:18:4
│
18 │ var<uniform> model: mat4x4<f32>;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ naga::GlobalVariable [1]
Global variable [1] 'model' is invalid
Type isn't compatible with the storage class包装在一个结构是很好的,并实现了我的需要,但似乎多余。矩阵类型可以直接使用吗?
发布于 2022-07-20 01:49:42
我觉得那是个纳加虫。以下内容似乎在Tint中正确编译。
@group(0) @binding(0)
var<uniform> model: mat4x4<f32>;
@compute @workgroup_size(1)
fn main() {
var f = model[0][0];
}统一应接受任何可构造的、主机共享的类型(如向量、矩阵、结构等)。
发布于 2022-07-21 14:06:51
WGSL过去需要一个结构作为统一或存储缓冲区的类型。但是WGSL现在更灵活了,Naga的(那个版本)还没有赶上。
发布于 2022-07-26 09:22:20
如果能看到你的代码就好了。“它在我的机器上工作”:(naga 0.9.0,wgpu 0.13.1,winit 0.26.1)
@group(0) @binding(0)
var<uniform> color: mat4x4<f32>;
@fragment
fn fs_main(@builtin(position) coord_in: vec4<f32>) -> @location(0) vec4<f32> {
return vec4<f32>(color.y);
}生锈的一面:
let color_uniform: [[f32; 4]; 4] = [
[1.0, 0.0, 0.0, 1.0],
[0.0, 0.5, 0.0, 1.0],
[0.0, 0.0, 1.0, 1.0],
[1.0, 1.0, 0.0, 1.0],
];
let uniform_buffer = device.create_buffer_init(
&wgpu::util::BufferInitDescriptor {
label: Some("Uniform Buffer"),
contents: bytemuck::cast_slice(&[color_uniform]),
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
}
);https://stackoverflow.com/questions/72271750
复制相似问题