Skip to content

Commit 7369bdd

Browse files
Peter McNeeleyDawn LUCI CQ
authored andcommitted
[tint] Polyfill unary negation and abs for amd mesa frontend
Bug: 448294721 Change-Id: Ibca22bac11a7289538cefcd70169640d323b297c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/276774 Reviewed-by: James Price <[email protected]> Commit-Queue: Peter McNeeley <[email protected]>
1 parent c3de402 commit 7369bdd

File tree

13 files changed

+495
-4
lines changed

13 files changed

+495
-4
lines changed

src/dawn/native/Toggles.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ static constexpr ToggleEnumAndInfoList kToggleNameAndInfoList = {{
387387
{"metal_polyfill_unpack_2x16_unorm",
388388
"Polyfill unpack2x16unorm for MSL due to CTS failures on Mac M3+ devices.",
389389
"https://crbug.com/449576833", ToggleStage::Device}},
390+
{Toggle::VulkanPolyfillF32Negation,
391+
{"spirv_polyfill_f32_negation",
392+
"Polyfill f32 negation with bit manipulation in SPIR-V writer.",
393+
"https://crbug.com/448294721", ToggleStage::Device}},
394+
{Toggle::VulkanPolyfillF32Abs,
395+
{"spirv_polyfill_f32_abs", "Polyfill f32 abs with bit manipulation in SPIR-V writer.",
396+
"https://crbug.com/448294721", ToggleStage::Device}},
390397
{Toggle::MetalFillEmptyOcclusionQueriesWithZero,
391398
{"metal_fill_empty_occlusion_queries_with_zero",
392399
"Apple GPUs leave stale results in the visibility result buffer instead of writing zero if "

src/dawn/native/Toggles.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ enum class Toggle {
104104
MetalKeepMultisubresourceDepthStencilTexturesInitialized,
105105
MetalPolyfillUnpack2x16snorm,
106106
MetalPolyfillUnpack2x16unorm,
107+
VulkanPolyfillF32Negation,
108+
VulkanPolyfillF32Abs,
107109
MetalFillEmptyOcclusionQueriesWithZero,
108110
UseBlitForBufferToDepthTextureCopy,
109111
UseBlitForBufferToStencilTextureCopy,

src/dawn/native/vulkan/PhysicalDeviceVk.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,17 @@ void PhysicalDevice::SetupBackendDeviceToggles(dawn::platform::Platform* platfor
998998
deviceToggles->Default(Toggle::VulkanPolyfillSwitchWithIf, true);
999999
}
10001000

1001+
// AMD mesa front end optimizer bug for unary negation and abs.
1002+
// Fixed in 25.3 - See crbug.com/448294721
1003+
if (IsAmdMesa()) {
1004+
const gpu_info::DriverVersion kGoodMesaDriver = {25, 3, 0, 0};
1005+
const bool badDriver = GetDriverVersion() < kGoodMesaDriver;
1006+
if (badDriver) {
1007+
deviceToggles->Default(Toggle::VulkanPolyfillF32Abs, true);
1008+
deviceToggles->Default(Toggle::VulkanPolyfillF32Negation, true);
1009+
}
1010+
}
1011+
10011012
if (IsAndroidARM()) {
10021013
// dawn:1550: Resolving multiple color targets in a single pass fails on ARM GPUs. To
10031014
// work around the issue, passes that resolve to multiple color targets will instead be
@@ -1285,6 +1296,13 @@ bool PhysicalDevice::IsIntelMesa() const {
12851296
return false;
12861297
}
12871298

1299+
bool PhysicalDevice::IsAmdMesa() const {
1300+
if (mDeviceInfo.HasExt(DeviceExt::DriverProperties)) {
1301+
return mDeviceInfo.driverProperties.driverID == VK_DRIVER_ID_MESA_RADV_KHR;
1302+
}
1303+
return false;
1304+
}
1305+
12881306
bool PhysicalDevice::IsSwiftshader() const {
12891307
return gpu_info::IsGoogleSwiftshader(GetVendorId(), GetDeviceId());
12901308
}

src/dawn/native/vulkan/PhysicalDeviceVk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class PhysicalDevice : public PhysicalDeviceBase {
6767
bool IsAndroidImgTec() const;
6868
bool IsPixel10() const;
6969
bool IsIntelMesa() const;
70+
bool IsAmdMesa() const;
7071
bool IsAndroidHuawei() const;
7172
bool IsSwiftshader() const;
7273

src/dawn/native/vulkan/ShaderModuleVk.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ ResultOrError<ShaderModule::ModuleAndSpirv> ShaderModule::GetHandleAndSpirv(
212212
req.tintOptions.bindings = std::move(bindings);
213213
req.tintOptions.resource_binding = std::move(resourceBindingConfig);
214214

215-
req.tintOptions.disable_robustness = !GetDevice()->IsRobustnessEnabled();
216-
req.tintOptions.disable_workgroup_init =
217-
GetDevice()->IsToggleEnabled(Toggle::DisableWorkgroupInit);
215+
req.tintOptions.workarounds.polyfill_unary_f32_negation =
216+
GetDevice()->IsToggleEnabled(Toggle::VulkanPolyfillF32Negation);
217+
req.tintOptions.workarounds.polyfill_f32_abs =
218+
GetDevice()->IsToggleEnabled(Toggle::VulkanPolyfillF32Abs);
218219
req.tintOptions.disable_polyfill_integer_div_mod =
219220
GetDevice()->IsToggleEnabled(Toggle::DisablePolyfillsOnIntegerDivisonAndModulo);
220221

src/tint/lang/spirv/writer/common/options.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,22 @@ struct Options {
9191
/// Set to `true` to always pass matrices to user functions by pointer instead of by value.
9292
bool pass_matrix_by_pointer = false;
9393

94+
/// Set to `true` to generate polyfill for f32 negation.
95+
bool polyfill_unary_f32_negation = false;
96+
97+
/// Set to `true` to generate polyfill for f32 abs.
98+
bool polyfill_f32_abs = false;
99+
94100
TINT_REFLECT(Workarounds,
95101
polyfill_case_switch,
96102
scalarize_max_min_clamp,
97103
dva_transform_handle,
98104
polyfill_pack_unpack_4x8_norm,
99105
subgroup_shuffle_clamped,
100106
polyfill_subgroup_broadcast_f16,
101-
pass_matrix_by_pointer);
107+
pass_matrix_by_pointer,
108+
polyfill_unary_f32_negation,
109+
polyfill_f32_abs);
102110
};
103111

104112
/// Any options which are controlled by the presence/absence of a vulkan extension.

src/tint/lang/spirv/writer/raise/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ cc_library(
5252
"resource_binding.cc",
5353
"resource_table.cc",
5454
"shader_io.cc",
55+
"unary_polyfill.cc",
5556
"var_for_dynamic_index.cc",
5657
],
5758
hdrs = [
@@ -68,6 +69,7 @@ cc_library(
6869
"resource_binding.h",
6970
"resource_table.h",
7071
"shader_io.h",
72+
"unary_polyfill.h",
7173
"var_for_dynamic_index.h",
7274
],
7375
deps = [
@@ -122,6 +124,7 @@ cc_library(
122124
"pass_matrix_by_pointer_test.cc",
123125
"remove_unreachable_in_loop_continuing_test.cc",
124126
"shader_io_test.cc",
127+
"unary_polyfill_test.cc",
125128
"var_for_dynamic_index_test.cc",
126129
],
127130
deps = [

src/tint/lang/spirv/writer/raise/BUILD.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ tint_add_target(tint_lang_spirv_writer_raise lib
6767
lang/spirv/writer/raise/resource_table.h
6868
lang/spirv/writer/raise/shader_io.cc
6969
lang/spirv/writer/raise/shader_io.h
70+
lang/spirv/writer/raise/unary_polyfill.cc
71+
lang/spirv/writer/raise/unary_polyfill.h
7072
lang/spirv/writer/raise/var_for_dynamic_index.cc
7173
lang/spirv/writer/raise/var_for_dynamic_index.h
7274
)
@@ -130,6 +132,7 @@ tint_add_target(tint_lang_spirv_writer_raise_test test
130132
lang/spirv/writer/raise/pass_matrix_by_pointer_test.cc
131133
lang/spirv/writer/raise/remove_unreachable_in_loop_continuing_test.cc
132134
lang/spirv/writer/raise/shader_io_test.cc
135+
lang/spirv/writer/raise/unary_polyfill_test.cc
133136
lang/spirv/writer/raise/var_for_dynamic_index_test.cc
134137
)
135138

src/tint/lang/spirv/writer/raise/BUILD.gn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ if (tint_build_spv_writer) {
7171
"resource_table.h",
7272
"shader_io.cc",
7373
"shader_io.h",
74+
"unary_polyfill.cc",
75+
"unary_polyfill.h",
7476
"var_for_dynamic_index.cc",
7577
"var_for_dynamic_index.h",
7678
]
@@ -123,6 +125,7 @@ if (tint_build_unittests) {
123125
"pass_matrix_by_pointer_test.cc",
124126
"remove_unreachable_in_loop_continuing_test.cc",
125127
"shader_io_test.cc",
128+
"unary_polyfill_test.cc",
126129
"var_for_dynamic_index_test.cc",
127130
]
128131
deps = [

src/tint/lang/spirv/writer/raise/raise.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include "src/tint/lang/spirv/writer/raise/resource_binding.h"
6767
#include "src/tint/lang/spirv/writer/raise/resource_table.h"
6868
#include "src/tint/lang/spirv/writer/raise/shader_io.h"
69+
#include "src/tint/lang/spirv/writer/raise/unary_polyfill.h"
6970
#include "src/tint/lang/spirv/writer/raise/var_for_dynamic_index.h"
7071

7172
namespace tint::spirv::writer {
@@ -230,6 +231,14 @@ Result<SuccessType> Raise(core::ir::Module& module, const Options& options) {
230231
.signed_negation = true, .signed_arithmetic = true, .signed_shiftleft = true};
231232
RUN_TRANSFORM(core::ir::transform::SignedIntegerPolyfill, module, signed_integer_cfg);
232233

234+
// AMD mesa front end optimizer bug for unary negation and abs.
235+
// Fixed in 25.3 - See crbug.com/448294721
236+
raise::UnaryPolyfillConfig unary_polyfill_cfg = {
237+
.polyfill_f32_negation = options.workarounds.polyfill_unary_f32_negation,
238+
.polyfill_f32_abs = options.workarounds.polyfill_f32_abs};
239+
240+
RUN_TRANSFORM(raise::UnaryPolyfill, module, unary_polyfill_cfg);
241+
233242
// kAllowAnyInputAttachmentIndexType required after ExpandImplicitSplats
234243
RUN_TRANSFORM(raise::HandleMatrixArithmetic, module);
235244
RUN_TRANSFORM(raise::MergeReturn, module);

0 commit comments

Comments
 (0)