mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[glsl-in] Add support for texture arguments
This commit is contained in:
committed by
Dzmitry Malyshau
parent
4da665d3ba
commit
2bb15eb0a8
@@ -1673,8 +1673,9 @@ impl Parser {
|
||||
allow_deref: bool,
|
||||
) -> Result<Handle<crate::Expression>, Error<'a>> {
|
||||
let mut needs_deref = match ctx.expressions[handle] {
|
||||
crate::Expression::LocalVariable(_) | crate::Expression::GlobalVariable(_) => {
|
||||
allow_deref
|
||||
crate::Expression::LocalVariable(_) => allow_deref,
|
||||
crate::Expression::GlobalVariable(var) => {
|
||||
ctx.global_vars[var].class != crate::StorageClass::Handle && allow_deref
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
13
tests/in/texture-arg.wgsl
Normal file
13
tests/in/texture-arg.wgsl
Normal file
@@ -0,0 +1,13 @@
|
||||
[[group(0), binding(0)]]
|
||||
var Texture: texture_2d<f32>;
|
||||
[[group(0), binding(1)]]
|
||||
var Sampler: sampler;
|
||||
|
||||
fn test(Passed_Texture: texture_2d<f32>, Passed_Sampler: sampler) -> vec4<f32> {
|
||||
return textureSample(Passed_Texture, Passed_Sampler, vec2<f32>(0.0, 0.0));
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() -> [[location(0)]] vec4<f32> {
|
||||
return test(Texture, Sampler);
|
||||
}
|
||||
19
tests/out/glsl/texture-arg.main.Fragment.glsl
Normal file
19
tests/out/glsl/texture-arg.main.Fragment.glsl
Normal file
@@ -0,0 +1,19 @@
|
||||
#version 310 es
|
||||
|
||||
precision highp float;
|
||||
|
||||
uniform highp sampler2D _group_0_binding_0;
|
||||
|
||||
layout(location = 0) out vec4 _fs2p_location0;
|
||||
|
||||
vec4 test(highp sampler2D Passed_Texture, ) {
|
||||
vec4 _expr7 = texture(Passed_Texture, vec2(vec2(0.0, 0.0)));
|
||||
return _expr7;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec4 _expr2 = test(_group_0_binding_0, );
|
||||
_fs2p_location0 = _expr2;
|
||||
return;
|
||||
}
|
||||
|
||||
22
tests/out/msl/texture-arg.msl
Normal file
22
tests/out/msl/texture-arg.msl
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
|
||||
metal::float4 test(
|
||||
metal::texture2d<float, metal::access::sample> Passed_Texture,
|
||||
metal::sampler Passed_Sampler
|
||||
) {
|
||||
metal::float4 _e7 = Passed_Texture.sample(Passed_Sampler, metal::float2(0.0, 0.0));
|
||||
return _e7;
|
||||
}
|
||||
|
||||
struct main1Output {
|
||||
metal::float4 member [[color(0)]];
|
||||
};
|
||||
fragment main1Output main1(
|
||||
metal::texture2d<float, metal::access::sample> Texture [[user(fake0)]]
|
||||
, metal::sampler Sampler [[user(fake0)]]
|
||||
) {
|
||||
metal::float4 _e2 = test(Texture, Sampler);
|
||||
return main1Output { _e2 };
|
||||
}
|
||||
15
tests/out/wgsl/texture-arg.wgsl
Normal file
15
tests/out/wgsl/texture-arg.wgsl
Normal file
@@ -0,0 +1,15 @@
|
||||
[[group(0), binding(0)]]
|
||||
var Texture: texture_2d<f32>;
|
||||
[[group(0), binding(1)]]
|
||||
var Sampler: sampler;
|
||||
|
||||
fn test(Passed_Texture: texture_2d<f32>, Passed_Sampler: sampler) -> vec4<f32> {
|
||||
let _e7: vec4<f32> = textureSample(Passed_Texture, Passed_Sampler, vec2<f32>(0.0, 0.0));
|
||||
return _e7;
|
||||
}
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() -> [[location(0)]] vec4<f32> {
|
||||
let _e2: vec4<f32> = test(Texture, Sampler);
|
||||
return _e2;
|
||||
}
|
||||
@@ -380,6 +380,10 @@ fn convert_wgsl() {
|
||||
Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::WGSL,
|
||||
),
|
||||
("bounds-check-zero", Targets::SPIRV),
|
||||
(
|
||||
"texture-arg",
|
||||
Targets::METAL | Targets::GLSL | Targets::WGSL,
|
||||
),
|
||||
];
|
||||
|
||||
for &(name, targets) in inputs.iter() {
|
||||
|
||||
Reference in New Issue
Block a user