mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-08-08 21:19:14 +00:00
Removes the texture_external overload for textureSample and replaces it with a texture_external overload of textureSampleLevel to match merged spec. Adds a transform that adds the implicit level parameter to textureSampleLevel. Modifies unit tests to reflect change. Bug: dawn:728 Change-Id: I2dbc9232b4343db1075be79fda0054231860f3b1 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50701 Commit-Queue: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
108 lines
2.8 KiB
C++
108 lines
2.8 KiB
C++
// Copyright 2021 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "src/transform/external_texture_transform.h"
|
|
|
|
#include "src/transform/test_helper.h"
|
|
|
|
namespace tint {
|
|
namespace transform {
|
|
namespace {
|
|
|
|
using ExternalTextureTransformTest = TransformTest;
|
|
|
|
TEST_F(ExternalTextureTransformTest, SampleLevelSinglePlane) {
|
|
auto* src = R"(
|
|
[[group(0), binding(0)]] var s : sampler;
|
|
|
|
[[group(0), binding(1)]] var t : texture_external;
|
|
|
|
[[stage(fragment)]]
|
|
fn main([[builtin(position)]] coord : vec4<f32>) -> [[location(0)]] vec4<f32> {
|
|
return textureSampleLevel(t, s, (coord.xy / vec2<f32>(4.0, 4.0)));
|
|
}
|
|
)";
|
|
|
|
auto* expect = R"(
|
|
[[group(0), binding(0)]] var s : sampler;
|
|
|
|
[[group(0), binding(1)]] var t : texture_2d<f32>;
|
|
|
|
[[stage(fragment)]]
|
|
fn main([[builtin(position)]] coord : vec4<f32>) -> [[location(0)]] vec4<f32> {
|
|
return textureSampleLevel(t, s, (coord.xy / vec2<f32>(4.0, 4.0)), 0.0);
|
|
}
|
|
)";
|
|
|
|
auto got = Run<ExternalTextureTransform>(src);
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
}
|
|
|
|
TEST_F(ExternalTextureTransformTest, LoadSinglePlane) {
|
|
auto* src = R"(
|
|
[[group(0), binding(0)]] var t : texture_external;
|
|
|
|
[[stage(fragment)]]
|
|
fn main([[builtin(position)]] coord : vec4<f32>) -> [[location(0)]] vec4<f32> {
|
|
return textureLoad(t, vec2<i32>(1, 1));
|
|
}
|
|
)";
|
|
|
|
auto* expect = R"(
|
|
[[group(0), binding(0)]] var t : texture_2d<f32>;
|
|
|
|
[[stage(fragment)]]
|
|
fn main([[builtin(position)]] coord : vec4<f32>) -> [[location(0)]] vec4<f32> {
|
|
return textureLoad(t, vec2<i32>(1, 1), 0);
|
|
}
|
|
)";
|
|
|
|
auto got = Run<ExternalTextureTransform>(src);
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
}
|
|
|
|
TEST_F(ExternalTextureTransformTest, DimensionsSinglePlane) {
|
|
auto* src = R"(
|
|
[[group(0), binding(0)]] var t : texture_external;
|
|
|
|
[[stage(fragment)]]
|
|
fn main([[builtin(position)]] coord : vec4<f32>) -> [[location(0)]] vec4<f32> {
|
|
var dim : vec2<i32>;
|
|
dim = textureDimensions(t);
|
|
return vec4<f32>(0.0, 0.0, 0.0, 0.0);
|
|
}
|
|
)";
|
|
|
|
auto* expect = R"(
|
|
[[group(0), binding(0)]] var t : texture_2d<f32>;
|
|
|
|
[[stage(fragment)]]
|
|
fn main([[builtin(position)]] coord : vec4<f32>) -> [[location(0)]] vec4<f32> {
|
|
var dim : vec2<i32>;
|
|
dim = textureDimensions(t);
|
|
return vec4<f32>(0.0, 0.0, 0.0, 0.0);
|
|
}
|
|
)";
|
|
|
|
auto got = Run<ExternalTextureTransform>(src);
|
|
|
|
EXPECT_EQ(expect, str(got));
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace transform
|
|
} // namespace tint
|