ClampFragDepth: switch params to a struct.
Change the input params from two std::optional<uint32_t> to
a single std::optional<struct>.
Bug: dawn:2185
Change-Id: I3c8c29335fe45b6f8427de8fa33f573f92519651
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/174520
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/opengl/ShaderModuleGL.cpp b/src/dawn/native/opengl/ShaderModuleGL.cpp
index aa5768b..5801211 100644
--- a/src/dawn/native/opengl/ShaderModuleGL.cpp
+++ b/src/dawn/native/opengl/ShaderModuleGL.cpp
@@ -296,9 +296,8 @@
}
if (usesFragDepth) {
- req.tintOptions.min_depth_offset = 4 * PipelineLayout::PushConstantLocation::MinDepth;
-
- req.tintOptions.max_depth_offset = 4 * PipelineLayout::PushConstantLocation::MaxDepth;
+ req.tintOptions.depth_range_offsets = {4 * PipelineLayout::PushConstantLocation::MinDepth,
+ 4 * PipelineLayout::PushConstantLocation::MaxDepth};
}
req.disableSymbolRenaming = GetDevice()->IsToggleEnabled(Toggle::DisableSymbolRenaming);
diff --git a/src/tint/api/options/BUILD.bazel b/src/tint/api/options/BUILD.bazel
index 9a16e95..c7eba70 100644
--- a/src/tint/api/options/BUILD.bazel
+++ b/src/tint/api/options/BUILD.bazel
@@ -44,6 +44,7 @@
hdrs = [
"array_length_from_uniform.h",
"binding_remapper.h",
+ "depth_range_offsets.h",
"external_texture.h",
"pixel_local.h",
"texture_builtins_from_uniform.h",
diff --git a/src/tint/api/options/BUILD.cmake b/src/tint/api/options/BUILD.cmake
index 045323e..1f0fffa 100644
--- a/src/tint/api/options/BUILD.cmake
+++ b/src/tint/api/options/BUILD.cmake
@@ -41,6 +41,7 @@
tint_add_target(tint_api_options lib
api/options/array_length_from_uniform.h
api/options/binding_remapper.h
+ api/options/depth_range_offsets.h
api/options/external_texture.h
api/options/options.cc
api/options/pixel_local.h
diff --git a/src/tint/api/options/BUILD.gn b/src/tint/api/options/BUILD.gn
index f9f9b46..cc35c71 100644
--- a/src/tint/api/options/BUILD.gn
+++ b/src/tint/api/options/BUILD.gn
@@ -46,6 +46,7 @@
sources = [
"array_length_from_uniform.h",
"binding_remapper.h",
+ "depth_range_offsets.h",
"external_texture.h",
"options.cc",
"pixel_local.h",
diff --git a/src/tint/api/options/depth_range_offsets.h b/src/tint/api/options/depth_range_offsets.h
new file mode 100644
index 0000000..1abe2a5
--- /dev/null
+++ b/src/tint/api/options/depth_range_offsets.h
@@ -0,0 +1,49 @@
+// Copyright 2024 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef SRC_TINT_API_OPTIONS_DEPTH_RANGE_OFFSETS_H_
+#define SRC_TINT_API_OPTIONS_DEPTH_RANGE_OFFSETS_H_
+
+#include <unordered_map>
+
+#include "src/tint/api/common/binding_point.h"
+
+namespace tint {
+
+/// Options used to specify the offsets of the min_depth and max_depth push constants.
+struct DepthRangeOffsets {
+ /// A map of old binding point to new binding point
+ uint32_t min = 0;
+ uint32_t max = 0;
+
+ /// Reflect the fields of this class so that it can be used by tint::ForeachField()
+ TINT_REFLECT(DepthRangeOffsets, min, max);
+};
+
+} // namespace tint
+
+#endif // SRC_TINT_API_OPTIONS_DEPTH_RANGE_OFFSETS_H_
diff --git a/src/tint/cmd/tint/main.cc b/src/tint/cmd/tint/main.cc
index 1601a76..8db9a64 100644
--- a/src/tint/cmd/tint/main.cc
+++ b/src/tint/cmd/tint/main.cc
@@ -1089,8 +1089,7 @@
offset += 4;
}
if (entry_point.frag_depth_used) {
- gen_options.min_depth_offset = offset + 0;
- gen_options.max_depth_offset = offset + 4;
+ gen_options.depth_range_offsets = {offset + 0, offset + 4};
offset += 8;
}
diff --git a/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc b/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc
index 764b779..5020b17 100644
--- a/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc
@@ -254,8 +254,8 @@
data.Add<ast::transform::OffsetFirstIndex::Config>(std::nullopt, options.first_instance_offset);
- data.Add<ast::transform::ClampFragDepth::Config>(options.min_depth_offset,
- options.max_depth_offset);
+ data.Add<ast::transform::ClampFragDepth::Config>(options.depth_range_offsets);
+
SanitizedResult result;
ast::transform::DataMap outputs;
result.program = manager.Run(in, data, outputs);
diff --git a/src/tint/lang/glsl/writer/common/options.h b/src/tint/lang/glsl/writer/common/options.h
index 62cd80c..19aa11d 100644
--- a/src/tint/lang/glsl/writer/common/options.h
+++ b/src/tint/lang/glsl/writer/common/options.h
@@ -33,6 +33,7 @@
#include <unordered_map>
#include "src/tint/api/options/binding_remapper.h"
+#include "src/tint/api/options/depth_range_offsets.h"
#include "src/tint/api/options/external_texture.h"
#include "src/tint/api/options/texture_builtins_from_uniform.h"
#include "src/tint/lang/glsl/writer/common/version.h"
@@ -82,11 +83,8 @@
/// Offset of the firstInstance push constant.
std::optional<int32_t> first_instance_offset;
- /// Offset of the minDepth push constant.
- std::optional<uint32_t> min_depth_offset;
-
- /// Offset of the maxDepth push constant.
- std::optional<uint32_t> max_depth_offset;
+ /// Offsets of the minDepth and maxDepth push constants.
+ std::optional<DepthRangeOffsets> depth_range_offsets;
/// Options used to map WGSL textureNumLevels/textureNumSamples builtins to internal uniform
/// buffer values. If not specified, emits corresponding GLSL builtins
@@ -104,8 +102,7 @@
binding_remapper_options,
external_texture_options,
first_instance_offset,
- min_depth_offset,
- max_depth_offset,
+ depth_range_offsets,
texture_builtins_from_uniform);
};
diff --git a/src/tint/lang/spirv/writer/ast_printer/ast_printer.cc b/src/tint/lang/spirv/writer/ast_printer/ast_printer.cc
index c782db5..1d75ad5 100644
--- a/src/tint/lang/spirv/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/spirv/writer/ast_printer/ast_printer.cc
@@ -66,7 +66,7 @@
if (options.clamp_frag_depth) {
manager.Add<ast::transform::ClampFragDepth>();
- data.Add<ast::transform::ClampFragDepth::Config>(0, 4);
+ data.Add<ast::transform::ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
}
manager.Add<ast::transform::DisableUniformityAnalysis>();
diff --git a/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.cc b/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.cc
index 2b5e6a2..66bf672 100644
--- a/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.cc
+++ b/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.cc
@@ -67,7 +67,7 @@
/// @returns the new program or SkipTransform if the transform is not required
Transform::ApplyResult Run(const DataMap& inputs) {
const Config* cfg = inputs.Get<Config>();
- if (!cfg || !cfg->min_depth_offset.has_value() || !cfg->max_depth_offset.has_value()) {
+ if (!cfg || !cfg->offsets.has_value()) {
return SkipTransform;
}
@@ -87,8 +87,8 @@
// return clamp(v, push_constants.min, push_constants.max_depth);
// }
- push_constant_helper.InsertMember("min_depth", b.ty.f32(), *cfg->min_depth_offset);
- push_constant_helper.InsertMember("max_depth", b.ty.f32(), *cfg->max_depth_offset);
+ push_constant_helper.InsertMember("min_depth", b.ty.f32(), cfg->offsets->min);
+ push_constant_helper.InsertMember("max_depth", b.ty.f32(), cfg->offsets->max);
Symbol buffer_name = push_constant_helper.Run();
@@ -221,9 +221,7 @@
return State{src}.Run(inputs);
}
-ClampFragDepth::Config::Config(std::optional<uint32_t> min_depth_off,
- std::optional<uint32_t> max_depth_off)
- : min_depth_offset(min_depth_off), max_depth_offset(max_depth_off) {}
+ClampFragDepth::Config::Config(std::optional<tint::DepthRangeOffsets> off) : offsets(off) {}
ClampFragDepth::Config::~Config() = default;
diff --git a/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.h b/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.h
index 599b91c..03972a0 100644
--- a/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.h
+++ b/src/tint/lang/wgsl/ast/transform/clamp_frag_depth.h
@@ -28,6 +28,7 @@
#ifndef SRC_TINT_LANG_WGSL_AST_TRANSFORM_CLAMP_FRAG_DEPTH_H_
#define SRC_TINT_LANG_WGSL_AST_TRANSFORM_CLAMP_FRAG_DEPTH_H_
+#include "src/tint/api/options/depth_range_offsets.h"
#include "src/tint/lang/wgsl/ast/transform/transform.h"
namespace tint::ast::transform {
@@ -72,18 +73,14 @@
/// Transform configuration options
struct Config final : public Castable<Config, ast::transform::Data> {
/// Constructor
- /// @param min_depth_off Offset of the minDepth push constant
- /// @param max_depth_off Offset of the maxDepth push constant
- Config(std::optional<uint32_t> min_depth_off, std::optional<uint32_t> max_depth_off);
+ /// @param off Offsets of the min_depth and max_depth push constants
+ explicit Config(std::optional<tint::DepthRangeOffsets> off);
/// Destructor
~Config() override;
- /// Offset of the min_depth push constant
- std::optional<uint32_t> min_depth_offset;
-
- /// Offset of the min_depth push constant
- std::optional<uint32_t> max_depth_offset;
+ /// Offsets of the min_depth and max_depth push constants
+ std::optional<tint::DepthRangeOffsets> offsets;
};
/// @copydoc ast::transform::Transform::Apply
diff --git a/src/tint/lang/wgsl/ast/transform/clamp_frag_depth_test.cc b/src/tint/lang/wgsl/ast/transform/clamp_frag_depth_test.cc
index 97f1f31..027c19d 100644
--- a/src/tint/lang/wgsl/ast/transform/clamp_frag_depth_test.cc
+++ b/src/tint/lang/wgsl/ast/transform/clamp_frag_depth_test.cc
@@ -50,19 +50,6 @@
EXPECT_FALSE(ShouldRun<ClampFragDepth>(src));
}
-TEST_F(ClampFragDepthTest, ShouldRunNoMin) {
- auto* src = R"(
- @fragment fn main() -> @builtin(frag_depth) f32 {
- return 0.0;
- }
- )";
-
- DataMap config;
- config.Add<ClampFragDepth::Config>(std::nullopt, 4);
-
- EXPECT_FALSE(ShouldRun<ClampFragDepth>(src, config));
-}
-
TEST_F(ClampFragDepthTest, ShouldRunNoMinNoMax) {
auto* src = R"(
@fragment fn main() -> @builtin(frag_depth) f32 {
@@ -71,7 +58,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, std::nullopt);
+ config.Add<ClampFragDepth::Config>(std::nullopt);
EXPECT_FALSE(ShouldRun<ClampFragDepth>(src, config));
}
@@ -84,7 +71,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
EXPECT_TRUE(ShouldRun<ClampFragDepth>(src, config));
}
@@ -132,7 +119,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(4, 8);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{4, 8});
auto got = Run<ClampFragDepth>(src, config);
EXPECT_EQ(expect, str(got));
@@ -146,7 +133,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
EXPECT_TRUE(ShouldRun<ClampFragDepth>(src, config));
}
@@ -164,7 +151,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
EXPECT_TRUE(ShouldRun<ClampFragDepth>(src, config));
}
@@ -199,7 +186,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
auto got = Run<ClampFragDepth>(src, config);
EXPECT_EQ(expect, str(got));
}
@@ -240,7 +227,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
auto got = Run<ClampFragDepth>(src, config);
EXPECT_EQ(expect, str(got));
}
@@ -283,7 +270,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
auto got = Run<ClampFragDepth>(src, config);
EXPECT_EQ(expect, str(got));
}
@@ -331,7 +318,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
auto got = Run<ClampFragDepth>(src, config);
EXPECT_EQ(expect, str(got));
}
@@ -409,7 +396,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
auto got = Run<ClampFragDepth>(src, config);
EXPECT_EQ(expect, str(got));
}
@@ -469,7 +456,7 @@
)";
DataMap config;
- config.Add<ClampFragDepth::Config>(0, 4);
+ config.Add<ClampFragDepth::Config>(tint::DepthRangeOffsets{0, 4});
auto got = Run<ClampFragDepth>(src, config);
EXPECT_EQ(expect, str(got));
}