mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-17 09:22:39 +00:00
[wgsl-out] Create baking expression for texture function
This commit is contained in:
parent
96ec0b61e7
commit
b4aa966575
@ -571,8 +571,16 @@ impl<W: Write> Writer<W> {
|
||||
match *stmt {
|
||||
Statement::Emit(ref range) => {
|
||||
for handle in range.clone() {
|
||||
let min_ref_count = func_ctx.expressions[handle].bake_ref_count();
|
||||
if min_ref_count <= func_ctx.info[handle].ref_count {
|
||||
let expr = &func_ctx.expressions[handle];
|
||||
let min_ref_count = expr.bake_ref_count();
|
||||
// Forcefully creating baking expressions in some cases to help with readability
|
||||
let required_baking_expr = match *expr {
|
||||
Expression::ImageLoad { .. }
|
||||
| Expression::ImageQuery { .. }
|
||||
| Expression::ImageSample { .. } => true,
|
||||
_ => false,
|
||||
};
|
||||
if min_ref_count <= func_ctx.info[handle].ref_count || required_baking_expr {
|
||||
write!(self.out, "{}", INDENT.repeat(indent))?;
|
||||
self.start_baking_expr(module, handle, &func_ctx)?;
|
||||
self.write_expr(module, handle, &func_ctx)?;
|
||||
@ -843,8 +851,11 @@ impl<W: Write> Writer<W> {
|
||||
};
|
||||
|
||||
match *resolved {
|
||||
TypeInner::Vector { .. }
|
||||
| TypeInner::Matrix { .. }
|
||||
TypeInner::Vector { .. } => {
|
||||
// Write vector access as a swizzle
|
||||
write!(self.out, ".{}", COMPONENTS[index as usize])?
|
||||
}
|
||||
TypeInner::Matrix { .. }
|
||||
| TypeInner::Array { .. }
|
||||
| TypeInner::ValuePointer { .. } => write!(self.out, "[{}]", index)?,
|
||||
TypeInner::Struct { .. } => {
|
||||
|
@ -19,13 +19,33 @@ var image_aa: texture_multisampled_2d<f32>;
|
||||
|
||||
[[stage(compute), workgroup_size(16, 1, 1)]]
|
||||
fn main([[builtin(local_invocation_id)]] local_id: vec3<u32>) {
|
||||
let _e10: vec2<i32> = ((textureDimensions(image_src) * vec2<i32>(local_id.xy)) % vec2<i32>(10, 20));
|
||||
let _e3: vec2<i32> = textureDimensions(image_src);
|
||||
let _e10: vec2<i32> = ((_e3 * vec2<i32>(local_id.xy)) % vec2<i32>(10, 20));
|
||||
let _e11: vec4<u32> = textureLoad(image_src, _e10);
|
||||
textureStore(image_dst, _e10[0], _e11);
|
||||
textureStore(image_dst, _e10.x, _e11);
|
||||
return;
|
||||
}
|
||||
|
||||
[[stage(vertex)]]
|
||||
fn queries() -> [[builtin(position)]] vec4<f32> {
|
||||
return vec4<f32>(f32(((((((((((((((((((textureDimensions(image_1d) + textureDimensions(image_2d)[1]) + textureDimensions(image_2d, 1)[1]) + textureDimensions(image_2d_array)[1]) + textureDimensions(image_2d_array, 1)[1]) + textureNumLayers(image_2d_array)) + textureDimensions(image_cube)[1]) + textureDimensions(image_cube, 1)[1]) + textureDimensions(image_cube_array)[1]) + textureDimensions(image_cube_array, 1)[1]) + textureNumLayers(image_cube_array)) + textureDimensions(image_3d)[2]) + textureDimensions(image_3d, 1)[2]) + textureNumSamples(image_aa)) + textureNumLevels(image_2d)) + textureNumLevels(image_2d_array)) + textureNumLevels(image_3d)) + textureNumLevels(image_cube)) + textureNumLevels(image_cube_array))));
|
||||
let _e9: i32 = textureDimensions(image_1d);
|
||||
let _e10: vec2<i32> = textureDimensions(image_2d);
|
||||
let _e11: i32 = textureNumLevels(image_2d);
|
||||
let _e13: vec2<i32> = textureDimensions(image_2d, 1);
|
||||
let _e14: vec2<i32> = textureDimensions(image_2d_array);
|
||||
let _e15: i32 = textureNumLevels(image_2d_array);
|
||||
let _e17: vec2<i32> = textureDimensions(image_2d_array, 1);
|
||||
let _e18: i32 = textureNumLayers(image_2d_array);
|
||||
let _e19: vec3<i32> = textureDimensions(image_cube);
|
||||
let _e20: i32 = textureNumLevels(image_cube);
|
||||
let _e22: vec3<i32> = textureDimensions(image_cube, 1);
|
||||
let _e23: vec3<i32> = textureDimensions(image_cube_array);
|
||||
let _e24: i32 = textureNumLevels(image_cube_array);
|
||||
let _e26: vec3<i32> = textureDimensions(image_cube_array, 1);
|
||||
let _e27: i32 = textureNumLayers(image_cube_array);
|
||||
let _e28: vec3<i32> = textureDimensions(image_3d);
|
||||
let _e29: i32 = textureNumLevels(image_3d);
|
||||
let _e31: vec3<i32> = textureDimensions(image_3d, 1);
|
||||
let _e32: i32 = textureNumSamples(image_aa);
|
||||
return vec4<f32>(f32(((((((((((((((((((_e9 + _e10.y) + _e13.y) + _e14.y) + _e17.y) + _e18) + _e19.y) + _e22.y) + _e23.y) + _e26.y) + _e27) + _e28.z) + _e31.z) + _e32) + _e11) + _e15) + _e29) + _e20) + _e24)));
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ var a_pos: vec2<f32>;
|
||||
fn main() {
|
||||
v_uv = a_uv;
|
||||
let _e13: vec2<f32> = a_pos;
|
||||
perVertexStruct.gl_Position = vec4<f32>(_e13[0], _e13[1], 0.0, 1.0);
|
||||
perVertexStruct.gl_Position = vec4<f32>(_e13.x, _e13.y, 0.0, 1.0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ fn main([[location(0)]] pos: vec2<f32>, [[location(1)]] uv1: vec2<f32>) -> Verte
|
||||
[[stage(fragment)]]
|
||||
fn main1([[location(0), interpolate(perspective)]] uv2: vec2<f32>) -> [[location(0)]] vec4<f32> {
|
||||
let _e4: vec4<f32> = textureSample(u_texture, u_sampler, uv2);
|
||||
if ((_e4[3] == 0.0)) {
|
||||
if ((_e4.w == 0.0)) {
|
||||
discard;
|
||||
}
|
||||
return (_e4[3] * _e4);
|
||||
return (_e4.w * _e4);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user