Move tint options to the HLSL request
This CL moves the options which are passed to Tint for the HLSL backend
into a tintOptions object in the compilation request instead of passing
each option individually.
Change-Id: I2d36df15b4a0ba40215f7af9c73fb1c59b2bf012
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/160920
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/dawn/native/d3d/D3DCompilationRequest.h b/src/dawn/native/d3d/D3DCompilationRequest.h
index af100a4..0fb571e 100644
--- a/src/dawn/native/d3d/D3DCompilationRequest.h
+++ b/src/dawn/native/d3d/D3DCompilationRequest.h
@@ -76,22 +76,11 @@
X(IDxcCompiler3*, dxcCompiler) \
X(uint32_t, firstIndexOffsetShaderRegister) \
X(uint32_t, firstIndexOffsetRegisterSpace) \
- X(bool, usesNumWorkgroups) \
- X(uint32_t, numWorkgroupsShaderRegister) \
- X(uint32_t, numWorkgroupsRegisterSpace) \
- X(tint::ExternalTextureOptions, externalTextureOptions) \
- X(tint::ArrayLengthFromUniformOptions, arrayLengthFromUniform) \
- X(tint::BindingRemapperOptions, bindingRemapper) \
- X(AccessControl, accessControls) \
+ X(tint::hlsl::writer::Options, tintOptions) \
X(std::optional<tint::ast::transform::SubstituteOverride::Config>, substituteOverrideConfig) \
- X(InterStageShaderVariablesMask, interstageLocations) \
X(LimitsForCompilationRequest, limits) \
X(bool, disableSymbolRenaming) \
- X(bool, isRobustnessEnabled) \
- X(bool, disableWorkgroupInit) \
- X(bool, polyfillReflectVec2F32) \
- X(bool, dumpShaders) \
- X(std::vector<tint::BindingPoint>, bindingPointsIgnoredInRobustnessTransform)
+ X(bool, dumpShaders)
#define D3D_BYTECODE_COMPILATION_REQUEST_MEMBERS(X) \
X(bool, hasShaderF16Feature) \
diff --git a/src/dawn/native/d3d/ShaderUtils.cpp b/src/dawn/native/d3d/ShaderUtils.cpp
index 7f005a6..f02eb78 100644
--- a/src/dawn/native/d3d/ShaderUtils.cpp
+++ b/src/dawn/native/d3d/ShaderUtils.cpp
@@ -236,39 +236,8 @@
}
}
- tint::hlsl::writer::Options options;
- options.disable_robustness = !r.isRobustnessEnabled;
- options.disable_workgroup_init = r.disableWorkgroupInit;
- options.binding_remapper_options = r.bindingRemapper;
- options.access_controls = r.accessControls;
- options.external_texture_options = r.externalTextureOptions;
-
- if (r.usesNumWorkgroups) {
- options.root_constant_binding_point =
- tint::BindingPoint{r.numWorkgroupsRegisterSpace, r.numWorkgroupsShaderRegister};
- }
- // TODO(dawn:549): HLSL generation outputs the indices into the
- // array_length_from_uniform buffer that were actually used. When the blob cache can
- // store more than compiled shaders, we should reflect these used indices and store
- // them as well. This would allow us to only upload root constants that are actually
- // read by the shader.
- options.array_length_from_uniform = r.arrayLengthFromUniform;
-
- if (r.stage == SingleShaderStage::Vertex) {
- // Now that only vertex shader can have interstage outputs.
- // Pass in the actually used interstage locations for tint to potentially truncate unused
- // outputs.
- options.interstage_locations = r.interstageLocations;
- options.truncate_interstage_variables = true;
- }
-
- options.polyfill_reflect_vec2_f32 = r.polyfillReflectVec2F32;
-
- options.binding_points_ignored_in_robustness_transform =
- std::move(r.bindingPointsIgnoredInRobustnessTransform);
-
TRACE_EVENT0(tracePlatform.UnsafeGetValue(), General, "tint::hlsl::writer::Generate");
- auto result = tint::hlsl::writer::Generate(transformedProgram, options);
+ auto result = tint::hlsl::writer::Generate(transformedProgram, r.tintOptions);
DAWN_INVALID_IF(!result, "An error occurred while generating HLSL:\n%s",
result.Failure().reason.str());
diff --git a/src/dawn/native/d3d11/ShaderModuleD3D11.cpp b/src/dawn/native/d3d11/ShaderModuleD3D11.cpp
index df927c0..6a1efdf 100644
--- a/src/dawn/native/d3d11/ShaderModuleD3D11.cpp
+++ b/src/dawn/native/d3d11/ShaderModuleD3D11.cpp
@@ -90,14 +90,8 @@
req.tracePlatform = UnsafeUnkeyedValue(device->GetPlatform());
req.hlsl.shaderModel = 50;
req.hlsl.disableSymbolRenaming = device->IsToggleEnabled(Toggle::DisableSymbolRenaming);
- req.hlsl.isRobustnessEnabled = device->IsRobustnessEnabled();
- req.hlsl.disableWorkgroupInit = device->IsToggleEnabled(Toggle::DisableWorkgroupInit);
req.hlsl.dumpShaders = device->IsToggleEnabled(Toggle::DumpShaders);
- if (usedInterstageVariables.has_value()) {
- req.hlsl.interstageLocations = *usedInterstageVariables;
- }
-
req.bytecode.hasShaderF16Feature = false;
req.bytecode.compileFlags = compileFlags;
@@ -181,23 +175,37 @@
bindingRemapper.binding_points.emplace(srcBindingPoint, dstBindingPoint);
}
- req.hlsl.usesNumWorkgroups = entryPoint.usesNumWorkgroups;
- // D3D11 (HLSL SM5.0) doesn't support spaces, so we have to put the numWorkgroups in the default
- // space(0)
- req.hlsl.numWorkgroupsRegisterSpace = 0;
- req.hlsl.numWorkgroupsShaderRegister = PipelineLayout::kNumWorkgroupsConstantBufferSlot;
-
- req.hlsl.bindingRemapper = std::move(bindingRemapper);
-
- req.hlsl.externalTextureOptions = BuildExternalTextureTransformBindings(layout);
req.hlsl.substituteOverrideConfig = std::move(substituteOverrideConfig);
- // TODO(dawn:1705): do we need to support it?
- req.hlsl.polyfillReflectVec2F32 = false;
-
const CombinedLimits& limits = device->GetLimits();
req.hlsl.limits = LimitsForCompilationRequest::Create(limits.v1);
+ req.hlsl.tintOptions.disable_robustness = !device->IsRobustnessEnabled();
+ req.hlsl.tintOptions.disable_workgroup_init =
+ device->IsToggleEnabled(Toggle::DisableWorkgroupInit);
+ req.hlsl.tintOptions.binding_remapper_options = std::move(bindingRemapper);
+ req.hlsl.tintOptions.external_texture_options = BuildExternalTextureTransformBindings(layout);
+
+ if (entryPoint.usesNumWorkgroups) {
+ // D3D11 (HLSL SM5.0) doesn't support spaces, so we have to put the numWorkgroups in the
+ // default space(0)
+ req.hlsl.tintOptions.root_constant_binding_point =
+ tint::BindingPoint{0, PipelineLayout::kNumWorkgroupsConstantBufferSlot};
+ }
+
+ if (stage == SingleShaderStage::Vertex) {
+ // Now that only vertex shader can have interstage outputs.
+ // Pass in the actually used interstage locations for tint to potentially truncate unused
+ // outputs.
+ if (usedInterstageVariables.has_value()) {
+ req.hlsl.tintOptions.interstage_locations = *usedInterstageVariables;
+ }
+ req.hlsl.tintOptions.truncate_interstage_variables = true;
+ }
+
+ // TODO(dawn:1705): do we need to support it?
+ req.hlsl.tintOptions.polyfill_reflect_vec2_f32 = false;
+
CacheResult<d3d::CompiledShader> compiledShader;
MaybeError compileError = [&]() -> MaybeError {
DAWN_TRY_LOAD_OR_RUN(compiledShader, device, std::move(req), d3d::CompiledShader::FromBlob,
diff --git a/src/dawn/native/d3d12/ShaderModuleD3D12.cpp b/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
index 336597c..3381785 100644
--- a/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
+++ b/src/dawn/native/d3d12/ShaderModuleD3D12.cpp
@@ -141,14 +141,8 @@
req.tracePlatform = UnsafeUnkeyedValue(device->GetPlatform());
req.hlsl.shaderModel = device->GetDeviceInfo().shaderModel;
req.hlsl.disableSymbolRenaming = device->IsToggleEnabled(Toggle::DisableSymbolRenaming);
- req.hlsl.isRobustnessEnabled = device->IsRobustnessEnabled();
- req.hlsl.disableWorkgroupInit = device->IsToggleEnabled(Toggle::DisableWorkgroupInit);
req.hlsl.dumpShaders = device->IsToggleEnabled(Toggle::DumpShaders);
- if (usedInterstageVariables.has_value()) {
- req.hlsl.interstageLocations = *usedInterstageVariables;
- }
-
req.bytecode.hasShaderF16Feature = device->HasFeature(Feature::ShaderF16);
req.bytecode.compileFlags = compileFlags;
@@ -250,7 +244,8 @@
if ((bindingInfo.buffer.type == wgpu::BufferBindingType::Storage ||
bindingInfo.buffer.type == wgpu::BufferBindingType::ReadOnlyStorage) &&
!bgl->GetBindingInfo(bindingIndex).buffer.hasDynamicOffset) {
- req.hlsl.bindingPointsIgnoredInRobustnessTransform.emplace_back(srcBindingPoint);
+ req.hlsl.tintOptions.binding_points_ignored_in_robustness_transform.emplace_back(
+ srcBindingPoint);
}
}
@@ -285,16 +280,40 @@
req.hlsl.stage = stage;
req.hlsl.firstIndexOffsetShaderRegister = layout->GetFirstIndexOffsetShaderRegister();
req.hlsl.firstIndexOffsetRegisterSpace = layout->GetFirstIndexOffsetRegisterSpace();
- req.hlsl.usesNumWorkgroups = entryPoint.usesNumWorkgroups;
- req.hlsl.numWorkgroupsShaderRegister = layout->GetNumWorkgroupsShaderRegister();
- req.hlsl.numWorkgroupsRegisterSpace = layout->GetNumWorkgroupsRegisterSpace();
- req.hlsl.bindingRemapper = std::move(bindingRemapper);
- req.hlsl.accessControls = std::move(accessControls);
- req.hlsl.externalTextureOptions = BuildExternalTextureTransformBindings(layout);
- req.hlsl.arrayLengthFromUniform = std::move(arrayLengthFromUniform);
req.hlsl.substituteOverrideConfig = std::move(substituteOverrideConfig);
- req.hlsl.polyfillReflectVec2F32 = device->IsToggleEnabled(Toggle::D3D12PolyfillReflectVec2F32);
+ req.hlsl.tintOptions.disable_robustness = !device->IsRobustnessEnabled();
+ req.hlsl.tintOptions.disable_workgroup_init =
+ device->IsToggleEnabled(Toggle::DisableWorkgroupInit);
+ req.hlsl.tintOptions.binding_remapper_options = std::move(bindingRemapper);
+ req.hlsl.tintOptions.access_controls = std::move(accessControls);
+ req.hlsl.tintOptions.external_texture_options = BuildExternalTextureTransformBindings(layout);
+
+ if (entryPoint.usesNumWorkgroups) {
+ req.hlsl.tintOptions.root_constant_binding_point = tint::BindingPoint{
+ layout->GetNumWorkgroupsRegisterSpace(), layout->GetNumWorkgroupsShaderRegister()};
+ }
+
+ // TODO(dawn:549): HLSL generation outputs the indices into the
+ // array_length_from_uniform buffer that were actually used. When the blob cache can
+ // store more than compiled shaders, we should reflect these used indices and store
+ // them as well. This would allow us to only upload root constants that are actually
+ // read by the shader.
+ req.hlsl.tintOptions.array_length_from_uniform = std::move(arrayLengthFromUniform);
+
+ if (stage == SingleShaderStage::Vertex) {
+ // Now that only vertex shader can have interstage outputs.
+ // Pass in the actually used interstage locations for tint to potentially truncate unused
+ // outputs.
+ if (usedInterstageVariables.has_value()) {
+ req.hlsl.tintOptions.interstage_locations = *usedInterstageVariables;
+ }
+
+ req.hlsl.tintOptions.truncate_interstage_variables = true;
+ }
+
+ req.hlsl.tintOptions.polyfill_reflect_vec2_f32 =
+ device->IsToggleEnabled(Toggle::D3D12PolyfillReflectVec2F32);
const CombinedLimits& limits = device->GetLimits();
req.hlsl.limits = LimitsForCompilationRequest::Create(limits.v1);