mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-22 03:43:55 +00:00
parent
ba39fd47c3
commit
0e66930aff
@ -1670,12 +1670,18 @@ fn texture_call(
|
||||
meta: SourceMetadata,
|
||||
) -> Result<Handle<Expression>> {
|
||||
if let Some(sampler) = ctx.samplers.get(&image).copied() {
|
||||
let mut array_index = comps.array_index;
|
||||
|
||||
if let Some(ref mut array_index_expr) = array_index {
|
||||
ctx.conversion(array_index_expr, meta, Sk::Sint, 4)?;
|
||||
}
|
||||
|
||||
Ok(ctx.add_expression(
|
||||
Expression::ImageSample {
|
||||
image,
|
||||
sampler,
|
||||
coordinate: comps.coordinate,
|
||||
array_index: comps.array_index,
|
||||
array_index,
|
||||
offset: None,
|
||||
level,
|
||||
depth_ref: comps.depth_ref,
|
||||
|
@ -834,6 +834,25 @@ impl Context {
|
||||
.and_then(|(kind, width)| type_power(kind, width)))
|
||||
}
|
||||
|
||||
pub fn conversion(
|
||||
&mut self,
|
||||
expr: &mut Handle<Expression>,
|
||||
meta: SourceMetadata,
|
||||
kind: ScalarKind,
|
||||
width: crate::Bytes,
|
||||
) -> Result<()> {
|
||||
*expr = self.expressions.append(
|
||||
Expression::As {
|
||||
expr: *expr,
|
||||
kind,
|
||||
convert: Some(width),
|
||||
},
|
||||
meta.as_span(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn implicit_conversion(
|
||||
&mut self,
|
||||
parser: &mut Parser,
|
||||
@ -847,14 +866,7 @@ impl Context {
|
||||
self.expr_power(parser, *expr, meta)?,
|
||||
) {
|
||||
if tgt_power > expr_power {
|
||||
*expr = self.expressions.append(
|
||||
Expression::As {
|
||||
expr: *expr,
|
||||
kind,
|
||||
convert: Some(width),
|
||||
},
|
||||
meta.as_span(),
|
||||
)
|
||||
self.conversion(expr, meta, kind, width)?;
|
||||
}
|
||||
}
|
||||
|
||||
@ -882,25 +894,11 @@ impl Context {
|
||||
) {
|
||||
match left_power.cmp(&right_power) {
|
||||
std::cmp::Ordering::Less => {
|
||||
*left = self.expressions.append(
|
||||
Expression::As {
|
||||
expr: *left,
|
||||
kind: right_kind,
|
||||
convert: Some(right_width),
|
||||
},
|
||||
left_meta.as_span(),
|
||||
)
|
||||
self.conversion(left, left_meta, right_kind, right_width)?;
|
||||
}
|
||||
std::cmp::Ordering::Equal => {}
|
||||
std::cmp::Ordering::Greater => {
|
||||
*right = self.expressions.append(
|
||||
Expression::As {
|
||||
expr: *right,
|
||||
kind: left_kind,
|
||||
convert: Some(left_width),
|
||||
},
|
||||
right_meta.as_span(),
|
||||
)
|
||||
self.conversion(right, right_meta, left_kind, left_width)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,14 +131,14 @@ pub fn parse_type(type_name: &str) -> Option<Type> {
|
||||
|
||||
let (dim, arrayed, class) = match size {
|
||||
"1D" => (ImageDimension::D1, false, sampled(false)),
|
||||
"1DArray" => (ImageDimension::D1, false, sampled(false)),
|
||||
"1DArray" => (ImageDimension::D1, true, sampled(false)),
|
||||
"2D" => (ImageDimension::D2, false, sampled(false)),
|
||||
"2DArray" => (ImageDimension::D2, false, sampled(false)),
|
||||
"2DMS" => (ImageDimension::D2, true, sampled(true)),
|
||||
"2DArray" => (ImageDimension::D2, true, sampled(false)),
|
||||
"2DMS" => (ImageDimension::D2, false, sampled(true)),
|
||||
"2DMSArray" => (ImageDimension::D2, true, sampled(true)),
|
||||
"3D" => (ImageDimension::D3, false, sampled(false)),
|
||||
"Cube" => (ImageDimension::Cube, false, sampled(false)),
|
||||
"CubeArray" => (ImageDimension::D2, false, sampled(false)),
|
||||
"CubeArray" => (ImageDimension::D2, true, sampled(false)),
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
|
12
tests/in/glsl/samplers.frag
Normal file
12
tests/in/glsl/samplers.frag
Normal file
@ -0,0 +1,12 @@
|
||||
#version 440 core
|
||||
precision mediump float;
|
||||
|
||||
layout(set = 1, binding = 0) uniform texture2DArray tex;
|
||||
layout(set = 1, binding = 1) uniform sampler samp;
|
||||
|
||||
layout(location = 0) in vec2 v_TexCoord;
|
||||
layout(location = 0) out vec4 o_color;
|
||||
|
||||
void main() {
|
||||
o_color.rgba = texture(sampler2DArray(tex, samp), vec3(v_TexCoord, 0.0));
|
||||
}
|
31
tests/out/wgsl/samplers-frag.wgsl
Normal file
31
tests/out/wgsl/samplers-frag.wgsl
Normal file
@ -0,0 +1,31 @@
|
||||
struct FragmentOutput {
|
||||
[[location(0)]] o_color: vec4<f32>;
|
||||
};
|
||||
|
||||
[[group(1), binding(0)]]
|
||||
var tex: texture_2d_array<f32>;
|
||||
[[group(1), binding(1)]]
|
||||
var samp: sampler;
|
||||
var<private> v_TexCoord1: vec2<f32>;
|
||||
var<private> o_color: vec4<f32>;
|
||||
|
||||
fn main1() {
|
||||
let _e4: vec4<f32> = o_color;
|
||||
let _e6: vec2<f32> = v_TexCoord1;
|
||||
let _e9: vec2<f32> = v_TexCoord1;
|
||||
let _e11: vec3<f32> = vec3<f32>(_e9, 0.0);
|
||||
let _e15: vec4<f32> = textureSample(tex, samp, _e11.xy, i32(_e11.z));
|
||||
o_color.x = _e15.x;
|
||||
o_color.y = _e15.y;
|
||||
o_color.z = _e15.z;
|
||||
o_color.w = _e15.w;
|
||||
return;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main([[location(0)]] v_TexCoord: vec2<f32>) -> FragmentOutput {
|
||||
v_TexCoord1 = v_TexCoord;
|
||||
main1();
|
||||
let _e11: vec4<f32> = o_color;
|
||||
return FragmentOutput(_e11);
|
||||
}
|
Loading…
Reference in New Issue
Block a user