blob: d7aa8c6145c1751007932d00d8021d382ae09c6a [file] [log] [blame]
// Copyright 2019 The Dawn 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
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
#include <array>
#include "dawn/common/Assert.h"
#include "dawn/common/BitSetIterator.h"
#include "dawn/native/Toggles.h"
namespace dawn::native {
namespace {
struct ToggleEnumAndInfo {
Toggle toggle;
ToggleInfo info;
using ToggleEnumAndInfoList =
std::array<ToggleEnumAndInfo, static_cast<size_t>(Toggle::EnumCount)>;
static constexpr ToggleEnumAndInfoList kToggleNameAndInfoList = {{
"Emulate storing into multisampled color attachments and doing MSAA resolve "
"simultaneously. This workaround is enabled by default on the Metal drivers that do "
"not support MTLStoreActionStoreAndMultisampleResolve. To support StoreOp::Store on "
"those platforms, we should do MSAA resolve in another render pass after ending the "
"previous one.",
"Clears texture to full 1 bits as soon as they are created, but doesn't update "
"the tracking state of the texture. This way we can test the logic of clearing "
"textures that use recycled memory.",
"When the resolve target is a texture view that is created on the non-zero level or "
"layer of a texture, we first resolve into a temporarily 2D texture with only one "
"mipmap level and one array layer, and copy the result of MSAA resolve into the "
"true resolve target. This workaround is enabled by default on the Metal drivers "
"that have bugs when setting non-zero resolveLevel or resolveSlice.",
"Clears resource to zero on first usage. This initializes the resource "
"so that no dirty bits from recycled memory is present in the new resource.",
"Turn off vsync when rendering. In order to do performance test or run perf tests, "
"turn off vsync so that the fps can exeed 60.",
"Split texture-to-texture copy into two copies: copy from source texture into a "
"temporary buffer, and copy from the temporary buffer into the destination texture "
"when copying between compressed textures that don't have block-aligned sizes. This "
"workaround is enabled by default on all Vulkan drivers to solve an issue in the "
"Vulkan SPEC about the texture-to-texture copies with compressed formats. See #1005 "
"( for more details.",
"Enable support for resource heap tier 2. Resource heap tier 2 allows mixing of "
"texture and buffers in the same heap. This allows better heap re-use and reduces "
"Use the D3D12 render pass API introduced in Windows build 1809 by default. On "
"versions of Windows prior to build 1809, or when this toggle is turned off, Dawn "
"will emulate a render pass.",
"Enable residency management. This allows page-in and page-out of resource heaps in "
"GPU memory. This component improves overcommitted performance by keeping the most "
"recently used resources local to the GPU. Turning this component off can cause "
"allocation failures when application memory exceeds physical device memory.",
{"skip_validation", "Skip expensive validation of Dawn commands.",
"Vulkan mandates support of either D32_FLOAT_S8 or D24_UNORM_S8. When available the "
"backend will use D32S8 (toggle to on) but setting the toggle to off will make it "
"use the D24S8 format when possible.",
"Disables the use of sampler compare on Metal. This is unsupported before A9 "
"The query set on Metal need to create MTLCounterSampleBuffer which storage mode "
"must be either MTLStorageModeShared or MTLStorageModePrivate. But the private mode "
"does not work properly on Intel platforms. The workaround is use shared mode "
"Disables the use of non-zero base vertex which is unsupported on some platforms.",
"Disables the use of non-zero base instance which is unsupported on some "
"Disables the use of indexed draw buffer state which is unsupported on some "
"Disables reading from Snorm textures which is unsupported on some platforms.",
"Disables reading from depth/stencil textures which is unsupported on some "
"Disables gl_SampleMask and related functionality which is unsupported on some "
"Enable use of a small D3D12 shader visible heap, instead of using a large one by "
"default. This setting is used to test bindgroup encoding.",
"Use DXC instead of FXC for compiling HLSL when both dxcompiler.dll and dxil.dll "
"is available.",
{"disable_robustness", "Disable robust buffer access", ""}},
"Uses vertex pulling to protect out-of-bounds reads on Metal",
"Produces validation errors on API entry points or parameter combinations that "
"aren't considered secure yet.",
"Call glFlush before glClientWaitSync to work around bugs in the latter",
"Split texture-to-texture copy into two copies: copy from source texture into a "
"temporary buffer, and copy from the temporary buffer into the destination texture "
"under specific situations. This workaround is by default enabled on some Intel "
"GPUs which have a driver bug in the execution of CopyTextureRegion() when we copy "
"with the formats whose texel block sizes are less than 4 bytes from a greater mip "
"level to a smaller mip level on D3D12 backends.",
"Sets the D3DCOMPILE_SKIP_OPTIMIZATION and D3DCOMPILE_DEBUG compilation flags when "
"compiling HLSL code. Enables better shader debugging with external graphics "
"debugging tools.",
"Disallow usage of SPIR-V completely so that only WGSL is used for shader modules."
"This is useful to prevent a Chromium renderer process from successfully sending"
"SPIR-V code to be compiled in the GPU process.",
"Dump shaders for debugging purposes. Dumped shaders will be log via "
"EmitLog, thus printed in Chrome console or consumed by user-defined callback "
{"dump_translated_shaders", "Deprecated. Use dump_shaders",
"When ingesting SPIR-V shaders, force a first conversion to WGSL. This allows "
"testing Tint's SPIRV->WGSL translation on real content to be sure that it will "
"work when the same translation runs in a WASM module in the page.",
"Disables the workgroup memory zero-initialization for compute shaders.",
"Disables the WGSL symbol renaming so that names are preserved.",
"Enables calls to SetLabel to be forwarded to backend-specific APIs that label "
"Disables mipmaps for r8unorm and rg8unorm textures, which are known on some drivers "
"to not clear correctly.",
"Use a dummy empty fragment shader in vertex only render pipeline. This toggle must "
"be enabled for OpenGL ES backend, and serves as a workaround by default enabled on "
"some Metal devices with Intel GPU to ensure the depth result is correct.",
"Enable optimizations when compiling with FXC. Disabled by default because FXC "
"miscompiles in many cases when optimizations are enabled.",
"Record detailed timing information in trace events at certain point. Currently the "
"timing information is recorded right before calling ExecuteCommandLists on a D3D12 "
"command queue, and the information includes system time, CPU timestamp, GPU "
"timestamp, and their frequency.",
"Resolve timestamp queries into ticks instead of nanoseconds.",
"Initialize workgroup memory with OpConstantNull on Vulkan when the Vulkan extension "
"VK_KHR_zero_initialize_workgroup_memory is supported.",
// Dummy comment to separate the }} so it is clearer what to copy-paste to add a toggle.
} // anonymous namespace
void TogglesSet::Set(Toggle toggle, bool enabled) {
if (toggle == Toggle::DEPRECATED_DumpTranslatedShaders) {
Set(Toggle::DumpShaders, enabled);
ASSERT(toggle != Toggle::InvalidEnum);
const size_t toggleIndex = static_cast<size_t>(toggle);
toggleBitset.set(toggleIndex, enabled);
bool TogglesSet::Has(Toggle toggle) const {
if (toggle == Toggle::DEPRECATED_DumpTranslatedShaders) {
return Has(Toggle::DumpShaders);
ASSERT(toggle != Toggle::InvalidEnum);
const size_t toggleIndex = static_cast<size_t>(toggle);
return toggleBitset.test(toggleIndex);
std::vector<const char*> TogglesSet::GetContainedToggleNames() const {
std::vector<const char*> togglesNameInUse(toggleBitset.count());
uint32_t index = 0;
for (uint32_t i : IterateBitSet(toggleBitset)) {
const char* toggleName = ToggleEnumToName(static_cast<Toggle>(i));
togglesNameInUse[index] = toggleName;
return togglesNameInUse;
const char* ToggleEnumToName(Toggle toggle) {
ASSERT(toggle != Toggle::InvalidEnum);
const ToggleEnumAndInfo& toggleNameAndInfo =
ASSERT(toggleNameAndInfo.toggle == toggle);
const ToggleInfo* TogglesInfo::GetToggleInfo(const char* toggleName) {
const auto& iter = mToggleNameToEnumMap.find(toggleName);
if (iter != mToggleNameToEnumMap.cend()) {
return &kToggleNameAndInfoList[static_cast<size_t>(iter->second)].info;
return nullptr;
Toggle TogglesInfo::ToggleNameToEnum(const char* toggleName) {
const auto& iter = mToggleNameToEnumMap.find(toggleName);
if (iter != mToggleNameToEnumMap.cend()) {
return kToggleNameAndInfoList[static_cast<size_t>(iter->second)].toggle;
return Toggle::InvalidEnum;
void TogglesInfo::EnsureToggleNameToEnumMapInitialized() {
if (mToggleNameToEnumMapInitialized) {
for (size_t index = 0; index < kToggleNameAndInfoList.size(); ++index) {
const ToggleEnumAndInfo& toggleNameAndInfo = kToggleNameAndInfoList[index];
ASSERT(index == static_cast<size_t>(toggleNameAndInfo.toggle));
mToggleNameToEnumMap[] = toggleNameAndInfo.toggle;
mToggleNameToEnumMapInitialized = true;
} // namespace dawn::native