Add toggle to disable Tint polyfills on integer division and modulo
This patch adds a toggle to disable Tint polyfills on integer division
and modulo to investigate the potential performance issues about these
polyfills.
Note that this toggle should always be disabled to follow the latest
WebGPU SPEC.
Bug: tint:2128
Change-Id: I819da528e4932f6b0ec27e06029ecfd2ca0c7fad
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/168321
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/Toggles.cpp b/src/dawn/native/Toggles.cpp
index 878f5e2..28dd974 100644
--- a/src/dawn/native/Toggles.cpp
+++ b/src/dawn/native/Toggles.cpp
@@ -500,6 +500,10 @@
"Make the Instance expose the experimental features but not the unsage ones, so that safe "
"experimental features can be used without the need for allow_unsafe_apis",
"https://crbug.com/dawn/2260", ToggleStage::Instance}},
+ {Toggle::DisablePolyfillsOnIntegerDivisonAndModulo,
+ {"disable_polyfills_on_integer_div_and_mod",
+ "Disable the Tint polyfills on integer division and modulo.", "https://crbug.com/tint/2128",
+ ToggleStage::Device}},
{Toggle::NoWorkaroundSampleMaskBecomesZeroForAllButLastColorTarget,
{"no_workaround_sample_mask_becomes_zero_for_all_but_last_color_target",
"MacOS 12.0+ Intel has a bug where the sample mask is only applied for the last color "
diff --git a/src/dawn/native/Toggles.h b/src/dawn/native/Toggles.h
index a5ecc3d..193fca8 100644
--- a/src/dawn/native/Toggles.h
+++ b/src/dawn/native/Toggles.h
@@ -125,6 +125,7 @@
PolyFillPacked4x8DotProduct,
ExposeWGSLTestingFeatures,
ExposeWGSLExperimentalFeatures,
+ DisablePolyfillsOnIntegerDivisonAndModulo,
// Unresolved issues.
NoWorkaroundSampleMaskBecomesZeroForAllButLastColorTarget,
diff --git a/src/dawn/native/d3d12/ShaderModuleD3D12.cpp b/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
index 184af9e..63d01f3 100644
--- a/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
+++ b/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
@@ -317,6 +317,8 @@
device->IsToggleEnabled(Toggle::D3D12PolyfillReflectVec2F32);
req.hlsl.tintOptions.polyfill_dot_4x8_packed =
device->IsToggleEnabled(Toggle::PolyFillPacked4x8DotProduct);
+ req.hlsl.tintOptions.disable_polyfill_integer_div_mod =
+ device->IsToggleEnabled(Toggle::DisablePolyfillsOnIntegerDivisonAndModulo);
const CombinedLimits& limits = device->GetLimits();
req.hlsl.limits = LimitsForCompilationRequest::Create(limits.v1);
diff --git a/src/dawn/native/metal/ShaderModuleMTL.mm b/src/dawn/native/metal/ShaderModuleMTL.mm
index 984ae87..80c561c 100644
--- a/src/dawn/native/metal/ShaderModuleMTL.mm
+++ b/src/dawn/native/metal/ShaderModuleMTL.mm
@@ -270,6 +270,8 @@
req.tintOptions.array_length_from_uniform = std::move(arrayLengthFromUniform);
req.tintOptions.pixel_local_options = std::move(pixelLocal);
req.tintOptions.bindings = std::move(bindings);
+ req.tintOptions.disable_polyfill_integer_div_mod =
+ device->IsToggleEnabled(Toggle::DisablePolyfillsOnIntegerDivisonAndModulo);
const CombinedLimits& limits = device->GetLimits();
req.limits = LimitsForCompilationRequest::Create(limits.v1);
diff --git a/src/dawn/native/opengl/ShaderModuleGL.cpp b/src/dawn/native/opengl/ShaderModuleGL.cpp
index f656832..95ee397 100644
--- a/src/dawn/native/opengl/ShaderModuleGL.cpp
+++ b/src/dawn/native/opengl/ShaderModuleGL.cpp
@@ -265,6 +265,8 @@
req.tintOptions.external_texture_options = BuildExternalTextureTransformBindings(layout);
req.tintOptions.binding_remapper_options.binding_points = std::move(glBindings);
req.tintOptions.texture_builtins_from_uniform = std::move(textureBuiltinsFromUniform);
+ req.tintOptions.disable_polyfill_integer_div_mod =
+ GetDevice()->IsToggleEnabled(Toggle::DisablePolyfillsOnIntegerDivisonAndModulo);
// When textures are accessed without a sampler (e.g., textureLoad()),
// GetSamplerTextureUses() will return this sentinel value.
diff --git a/src/dawn/native/vulkan/ShaderModuleVk.cpp b/src/dawn/native/vulkan/ShaderModuleVk.cpp
index 8be6735..cddaaf3 100644
--- a/src/dawn/native/vulkan/ShaderModuleVk.cpp
+++ b/src/dawn/native/vulkan/ShaderModuleVk.cpp
@@ -335,6 +335,8 @@
req.tintOptions.polyfill_dot_4x8_packed =
GetDevice()->IsToggleEnabled(Toggle::PolyFillPacked4x8DotProduct);
req.use_tint_ir = GetDevice()->IsToggleEnabled(Toggle::UseTintIR);
+ req.tintOptions.disable_polyfill_integer_div_mod =
+ GetDevice()->IsToggleEnabled(Toggle::DisablePolyfillsOnIntegerDivisonAndModulo);
// Set subgroup uniform control flow flag for subgroup experiment, if device has
// Chromium-experimental-subgroup-uniform-control-flow feature. (dawn:464)
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 dde83cd..8d96bc7 100644
--- a/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc
@@ -182,7 +182,7 @@
polyfills.first_leading_bit = true;
polyfills.first_trailing_bit = true;
polyfills.insert_bits = ast::transform::BuiltinPolyfill::Level::kClampParameters;
- polyfills.int_div_mod = true;
+ polyfills.int_div_mod = !options.disable_polyfill_integer_div_mod;
polyfills.saturate = true;
polyfills.texture_sample_base_clamp_to_edge_2d_f32 = true;
polyfills.workgroup_uniform_load = true;
diff --git a/src/tint/lang/glsl/writer/common/options.h b/src/tint/lang/glsl/writer/common/options.h
index 8068595..b795d10 100644
--- a/src/tint/lang/glsl/writer/common/options.h
+++ b/src/tint/lang/glsl/writer/common/options.h
@@ -61,6 +61,9 @@
/// Set to `true` to disable workgroup memory zero initialization
bool disable_workgroup_init = false;
+ /// Set to `true` to disable the polyfills on integer division and modulo.
+ bool disable_polyfill_integer_div_mod = false;
+
/// The GLSL version to emit
Version version;
@@ -85,6 +88,7 @@
/// Reflect the fields of this class so that it can be used by tint::ForeachField()
TINT_REFLECT(disable_robustness,
disable_workgroup_init,
+ disable_polyfill_integer_div_mod,
version,
binding_map,
placeholder_binding_point,
diff --git a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
index 6932c07..452abc5 100644
--- a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
@@ -250,7 +250,7 @@
polyfills.first_leading_bit = true;
polyfills.first_trailing_bit = true;
polyfills.insert_bits = ast::transform::BuiltinPolyfill::Level::kFull;
- polyfills.int_div_mod = true;
+ polyfills.int_div_mod = !options.disable_polyfill_integer_div_mod;
polyfills.precise_float_mod = true;
polyfills.reflect_vec2_f32 = options.polyfill_reflect_vec2_f32;
polyfills.texture_sample_base_clamp_to_edge_2d_f32 = true;
diff --git a/src/tint/lang/hlsl/writer/common/options.h b/src/tint/lang/hlsl/writer/common/options.h
index 44cb403..b1d8535 100644
--- a/src/tint/lang/hlsl/writer/common/options.h
+++ b/src/tint/lang/hlsl/writer/common/options.h
@@ -74,6 +74,9 @@
/// Set to `true` to generate polyfill for `dot4I8Packed` and `dot4U8Packed` builtins
bool polyfill_dot_4x8_packed = false;
+ /// Set to `true` to disable the polyfills on integer division and modulo.
+ bool disable_polyfill_integer_div_mod = false;
+
/// Options used to specify a mapping of binding points to indices into a UBO
/// from which to load buffer sizes.
ArrayLengthFromUniformOptions array_length_from_uniform = {};
@@ -106,6 +109,7 @@
truncate_interstage_variables,
polyfill_reflect_vec2_f32,
polyfill_dot_4x8_packed,
+ disable_polyfill_integer_div_mod,
array_length_from_uniform,
interstage_locations,
root_constant_binding_point,
diff --git a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
index 517885a..b5991d0 100644
--- a/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/msl/writer/ast_printer/ast_printer.cc
@@ -184,7 +184,7 @@
polyfills.first_leading_bit = true;
polyfills.first_trailing_bit = true;
polyfills.insert_bits = ast::transform::BuiltinPolyfill::Level::kClampParameters;
- polyfills.int_div_mod = true;
+ polyfills.int_div_mod = !options.disable_polyfill_integer_div_mod;
polyfills.sign_int = true;
polyfills.texture_sample_base_clamp_to_edge_2d_f32 = true;
polyfills.workgroup_uniform_load = true;
diff --git a/src/tint/lang/msl/writer/common/options.h b/src/tint/lang/msl/writer/common/options.h
index 66623d9..1004293 100644
--- a/src/tint/lang/msl/writer/common/options.h
+++ b/src/tint/lang/msl/writer/common/options.h
@@ -130,6 +130,9 @@
/// for all vertex shaders in the module.
bool emit_vertex_point_size = false;
+ /// Set to `true` to disable the polyfills on integer division and modulo.
+ bool disable_polyfill_integer_div_mod = false;
+
/// The index to use when generating a UBO to receive storage buffer sizes.
/// Defaults to 30, which is the last valid buffer slot.
uint32_t buffer_size_ubo_index = 30;
@@ -152,6 +155,7 @@
TINT_REFLECT(disable_robustness,
disable_workgroup_init,
emit_vertex_point_size,
+ disable_polyfill_integer_div_mod,
buffer_size_ubo_index,
fixed_sample_mask,
pixel_local_options,
diff --git a/src/tint/lang/msl/writer/raise/raise.cc b/src/tint/lang/msl/writer/raise/raise.cc
index 2d970cc..7bbe7c1 100644
--- a/src/tint/lang/msl/writer/raise/raise.cc
+++ b/src/tint/lang/msl/writer/raise/raise.cc
@@ -61,7 +61,7 @@
{
core::ir::transform::BinaryPolyfillConfig binary_polyfills{};
- binary_polyfills.int_div_mod = true;
+ binary_polyfills.int_div_mod = !options.disable_polyfill_integer_div_mod;
binary_polyfills.bitshift_modulo = true; // crbug.com/tint/1543
RUN_TRANSFORM(core::ir::transform::BinaryPolyfill, binary_polyfills);
}
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 31a300e..cdac61d 100644
--- a/src/tint/lang/spirv/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/spirv/writer/ast_printer/ast_printer.cc
@@ -140,7 +140,7 @@
polyfills.first_leading_bit = true;
polyfills.first_trailing_bit = true;
polyfills.insert_bits = ast::transform::BuiltinPolyfill::Level::kClampParameters;
- polyfills.int_div_mod = true;
+ polyfills.int_div_mod = !options.disable_polyfill_integer_div_mod;
polyfills.saturate = true;
polyfills.texture_sample_base_clamp_to_edge_2d_f32 = true;
polyfills.quantize_to_vec_f16 = true; // crbug.com/tint/1741
diff --git a/src/tint/lang/spirv/writer/common/options.h b/src/tint/lang/spirv/writer/common/options.h
index 2c8a117..79ec0e7 100644
--- a/src/tint/lang/spirv/writer/common/options.h
+++ b/src/tint/lang/spirv/writer/common/options.h
@@ -146,6 +146,9 @@
/// Set to `true` to generate polyfill for `dot4I8Packed` and `dot4U8Packed` builtins
bool polyfill_dot_4x8_packed = false;
+ /// Set to `true` to disable the polyfills on integer division and modulo.
+ bool disable_polyfill_integer_div_mod = false;
+
/// The bindings
Bindings bindings;
@@ -159,6 +162,7 @@
clamp_frag_depth,
experimental_require_subgroup_uniform_control_flow,
polyfill_dot_4x8_packed,
+ disable_polyfill_integer_div_mod,
bindings);
};
diff --git a/src/tint/lang/spirv/writer/raise/raise.cc b/src/tint/lang/spirv/writer/raise/raise.cc
index 1c88637..095e47e 100644
--- a/src/tint/lang/spirv/writer/raise/raise.cc
+++ b/src/tint/lang/spirv/writer/raise/raise.cc
@@ -73,7 +73,7 @@
core::ir::transform::BinaryPolyfillConfig binary_polyfills;
binary_polyfills.bitshift_modulo = true;
- binary_polyfills.int_div_mod = true;
+ binary_polyfills.int_div_mod = !options.disable_polyfill_integer_div_mod;
RUN_TRANSFORM(core::ir::transform::BinaryPolyfill, module, binary_polyfills);
core::ir::transform::BuiltinPolyfillConfig core_polyfills;