wgpu/tests/in/bounds-check-image-restrict.wgsl
João Capucho 0aa7681165
glsl-out: Implement bounds checks for ImageLoad (#1889)
* glsl-out: Implement bounds checks for `ImageLoad`

* Enable image bounds check snapshot tests for GLSL.

In addition to the snapshot.rs changes, this entails adding an entry
point function to `bounds-check-image-restrict.wgsl` and
`bounds-check-image-rzsw.wgsl`, including appropriate data in the
param.ron files.

* Apply comments

Snapshot test changes:
Co-authored-by: Jim Blandy <jimb@red-bean.com>
2022-05-30 12:13:58 -07:00

105 lines
3.2 KiB
WebGPU Shading Language

@group(0) @binding(0)
var image_1d: texture_1d<f32>;
fn test_textureLoad_1d(coords: i32, level: i32) -> vec4<f32> {
return textureLoad(image_1d, coords, level);
}
@group(0) @binding(1)
var image_2d: texture_2d<f32>;
fn test_textureLoad_2d(coords: vec2<i32>, level: i32) -> vec4<f32> {
return textureLoad(image_2d, coords, level);
}
@group(0) @binding(2)
var image_2d_array: texture_2d_array<f32>;
fn test_textureLoad_2d_array(coords: vec2<i32>, index: i32, level: i32) -> vec4<f32> {
return textureLoad(image_2d_array, coords, index, level);
}
@group(0) @binding(3)
var image_3d: texture_3d<f32>;
fn test_textureLoad_3d(coords: vec3<i32>, level: i32) -> vec4<f32> {
return textureLoad(image_3d, coords, level);
}
@group(0) @binding(4)
var image_multisampled_2d: texture_multisampled_2d<f32>;
fn test_textureLoad_multisampled_2d(coords: vec2<i32>, _sample: i32) -> vec4<f32> {
return textureLoad(image_multisampled_2d, coords, _sample);
}
@group(0) @binding(5)
var image_depth_2d: texture_depth_2d;
fn test_textureLoad_depth_2d(coords: vec2<i32>, level: i32) -> f32 {
return textureLoad(image_depth_2d, coords, level);
}
@group(0) @binding(6)
var image_depth_2d_array: texture_depth_2d_array;
fn test_textureLoad_depth_2d_array(coords: vec2<i32>, index: i32, level: i32) -> f32 {
return textureLoad(image_depth_2d_array, coords, index, level);
}
@group(0) @binding(7)
var image_depth_multisampled_2d: texture_depth_multisampled_2d;
fn test_textureLoad_depth_multisampled_2d(coords: vec2<i32>, _sample: i32) -> f32 {
return textureLoad(image_depth_multisampled_2d, coords, _sample);
}
@group(0) @binding(8)
var image_storage_1d: texture_storage_1d<rgba8unorm, write>;
fn test_textureStore_1d(coords: i32, value: vec4<f32>) {
textureStore(image_storage_1d, coords, value);
}
@group(0) @binding(9)
var image_storage_2d: texture_storage_2d<rgba8unorm, write>;
fn test_textureStore_2d(coords: vec2<i32>, value: vec4<f32>) {
textureStore(image_storage_2d, coords, value);
}
@group(0) @binding(10)
var image_storage_2d_array: texture_storage_2d_array<rgba8unorm, write>;
fn test_textureStore_2d_array(coords: vec2<i32>, array_index: i32, value: vec4<f32>) {
textureStore(image_storage_2d_array, coords, array_index, value);
}
@group(0) @binding(11)
var image_storage_3d: texture_storage_3d<rgba8unorm, write>;
fn test_textureStore_3d(coords: vec3<i32>, value: vec4<f32>) {
textureStore(image_storage_3d, coords, value);
}
// GLSL output requires that we identify an entry point, so
// that it can tell what "in" and "out" globals to write.
@fragment
fn fragment_shader() -> @location(0) vec4<f32> {
test_textureLoad_1d(0, 0);
test_textureLoad_2d(vec2<i32>(), 0);
test_textureLoad_2d_array(vec2<i32>(), 0, 0);
test_textureLoad_3d(vec3<i32>(), 0);
test_textureLoad_multisampled_2d(vec2<i32>(), 0);
// Not yet implemented for GLSL:
// test_textureLoad_depth_2d(vec2<i32>(), 0);
// test_textureLoad_depth_2d_array(vec2<i32>(), 0, 0);
// test_textureLoad_depth_multisampled_2d(vec2<i32>(), 0);
test_textureStore_1d(0, vec4<f32>());
test_textureStore_2d(vec2<i32>(), vec4<f32>());
test_textureStore_2d_array(vec2<i32>(), 0, vec4<f32>());
test_textureStore_3d(vec3<i32>(), vec4<f32>());
return vec4<f32>(0.,0.,0.,0.);
}