diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index dff8f81dae1..4932e423dd7 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -145,7 +145,8 @@ def __init__(self, is_enabled, name, json_data): value += prefix if value_name == "undefined": - assert value == 0 + if name != "optional bool": + assert value == 0 self.hasUndefined = True if value != lastValue + 1: self.contiguousFromZero = False diff --git a/generator/templates/api.h b/generator/templates/api.h index 3322b6b35a1..6106216eff9 100644 --- a/generator/templates/api.h +++ b/generator/templates/api.h @@ -73,6 +73,7 @@ #endif #define WGPU_BREAKING_CHANGE_DEPTH_CLIP_CONTROL +#define WGPU_BREAKING_CHANGE_DEPTH_WRITE_ENABLED #include #include diff --git a/generator/templates/api_cpp.h b/generator/templates/api_cpp.h index e88d34a5be4..49315cb0cb5 100644 --- a/generator/templates/api_cpp.h +++ b/generator/templates/api_cpp.h @@ -100,7 +100,9 @@ static T& AsNonConstReference(const T& value) { ) {%- endmacro -%} -{% for type in by_category["enum"] %} +//* Although 'optional bool' is defined as an enum value, in C++, we manually implement it to +//* provide conversion utilities. +{% for type in by_category["enum"] if type.name.get() != "optional bool" %} {% set CppType = as_cppType(type.name) %} {% set CType = as_cType(type.name) %} enum class {{CppType}} : uint32_t { @@ -153,6 +155,67 @@ class {{BoolCppType}} { {{BoolCType}} mValue = static_cast<{{BoolCType}}>(false); }; +// Special class for optional booleans in order to allow conversions. +{% set OptionalBool = types["optional bool"] %} +{% set OptionalBoolCppType = as_cppType(OptionalBool.name) %} +{% set OptionalBoolCType = as_cType(OptionalBool.name) %} +{% set OptionalBoolUndefined = as_cEnum(OptionalBool.name, find_by_name(OptionalBool.values, "undefined").name) %} +class {{OptionalBoolCppType}} { + public: + constexpr {{OptionalBoolCppType}}() = default; + // NOLINTNEXTLINE(runtime/explicit) allow implicit construction + constexpr {{OptionalBoolCppType}}(bool value) : mValue(static_cast<{{OptionalBoolCType}}>(value)) {} + // NOLINTNEXTLINE(runtime/explicit) allow implicit construction + constexpr {{OptionalBoolCppType}}(std::optional value) : + mValue(value ? static_cast<{{OptionalBoolCType}}>(*value) : {{OptionalBoolUndefined}}) {} + // NOLINTNEXTLINE(runtime/explicit) allow implicit construction + constexpr {{OptionalBoolCppType}}({{OptionalBoolCType}} value): mValue(value) {} + + // Define the values that are equivalent to the enums. + {% for value in OptionalBool.values %} + static const {{OptionalBoolCppType}} {{as_cppEnum(value.name)}}; + {% endfor %} + + // Assignment operators. + {{OptionalBoolCppType}}& operator=(const bool& value) { + mValue = static_cast<{{OptionalBoolCType}}>(value); + return *this; + } + {{OptionalBoolCppType}}& operator=(const std::optional& value) { + mValue = value ? static_cast<{{OptionalBoolCType}}>(*value) : {{OptionalBoolUndefined}}; + return *this; + } + {{OptionalBoolCppType}}& operator=(const {{OptionalBoolCType}}& value) { + mValue = value; + return *this; + } + + // Conversion functions. + operator {{OptionalBoolCType}}() const { return mValue; } + operator std::optional() const { + if (mValue == {{OptionalBoolUndefined}}) { + return std::nullopt; + } + return static_cast(mValue); + } + + // Comparison functions. + bool operator==({{OptionalBoolCType}} rhs) const { + return mValue == rhs; + } + bool operator!=({{OptionalBoolCType}} rhs) const { + return mValue != rhs; + } + + private: + friend struct std::hash<{{OptionalBoolCppType}}>; + // Default to undefined. + {{OptionalBoolCType}} mValue = {{OptionalBoolUndefined}}; +}; +{% for value in OptionalBool.values %} + inline const {{OptionalBoolCppType}} {{OptionalBoolCppType}}::{{as_cppEnum(value.name)}} = {{OptionalBoolCppType}}({{as_cEnum(OptionalBool.name, value.name)}}); +{% endfor %} + // Helper class to wrap Status which allows implicit conversion to bool. // Used while callers switch to checking the Status enum instead of booleans. // TODO(crbug.com/42241199): Remove when all callers check the enum. @@ -952,6 +1015,13 @@ struct hash<{{metadata.namespace}}::{{BoolCppType}}> { return hash()(v); } }; +template <> +struct hash<{{metadata.namespace}}::{{OptionalBoolCppType}}> { + public: + size_t operator()(const {{metadata.namespace}}::{{OptionalBoolCppType}} &v) const { + return hash<{{OptionalBoolCType}}>()(v.mValue); + } +}; } // namespace std #endif // {{PREFIX}}{{API}}_CPP_H_ diff --git a/generator/templates/api_cpp_print.h b/generator/templates/api_cpp_print.h index 42d03a387c4..4c7c84a2ea0 100644 --- a/generator/templates/api_cpp_print.h +++ b/generator/templates/api_cpp_print.h @@ -39,7 +39,7 @@ namespace {{metadata.namespace}} { - {% for type in by_category["enum"] %} + {% for type in by_category["enum"] if type.name.get() != "optional bool" %} template std::basic_ostream& operator<<(std::basic_ostream& o, {{as_cppType(type.name)}} value) { switch (value) { diff --git a/generator/templates/dawn/native/ValidationUtils.cpp b/generator/templates/dawn/native/ValidationUtils.cpp index 95dcddd19fb..a7cd252ce75 100644 --- a/generator/templates/dawn/native/ValidationUtils.cpp +++ b/generator/templates/dawn/native/ValidationUtils.cpp @@ -36,9 +36,9 @@ namespace {{native_namespace}} { {% set namespace = metadata.namespace %} {% for type in by_category["enum"] %} MaybeError Validate{{type.name.CamelCase()}}({{namespace}}::{{as_cppType(type.name)}} value) { - switch (value) { + switch ({{as_cType(type.name)}}(value)) { {% for value in type.values if value.valid %} - case {{namespace}}::{{as_cppType(type.name)}}::{{as_cppEnum(value.name)}}: + case {{as_cEnum(type.name, value.name)}}: return {}; {% endfor %} default: diff --git a/generator/templates/dawn/native/api_absl_format.cpp b/generator/templates/dawn/native/api_absl_format.cpp index f0fc7893095..bdac4ade997 100644 --- a/generator/templates/dawn/native/api_absl_format.cpp +++ b/generator/templates/dawn/native/api_absl_format.cpp @@ -85,9 +85,9 @@ namespace {{namespace}} { absl::FormatSink* s) { if (spec.conversion_char() == absl::FormatConversionChar::s) { s->Append("{{as_cppType(type.name)}}::"); - switch (value) { + switch ({{as_cType(type.name)}}(value)) { {% for value in type.values %} - case {{as_cppType(type.name)}}::{{as_cppEnum(value.name)}}: + case {{as_cEnum(type.name, value.name)}}: s->Append("{{as_cppEnum(value.name)}}"); return {true}; {% endfor %} @@ -95,7 +95,7 @@ namespace {{namespace}} { break; } } - s->Append(absl::StrFormat("%u", static_cast::type>(value))); + s->Append(absl::StrFormat("%u", static_cast<{{as_cType(type.name)}}>(value))); return {true}; } {% endfor %} diff --git a/src/dawn/common/xlib_with_undefs.h b/src/dawn/common/xlib_with_undefs.h index 6f419e8bbf0..9fc22420674 100644 --- a/src/dawn/common/xlib_with_undefs.h +++ b/src/dawn/common/xlib_with_undefs.h @@ -48,6 +48,8 @@ #undef Always #undef Bool #undef Status +#undef False +#undef True using XErrorHandler = int (*)(Display*, XErrorEvent*); diff --git a/src/dawn/dawn.json b/src/dawn/dawn.json index ad1b051aaf8..9ab4fbbbfe0 100644 --- a/src/dawn/dawn.json +++ b/src/dawn/dawn.json @@ -625,6 +625,14 @@ "category": "native", "wasm type": "i" }, + "optional bool": { + "category": "enum", + "values": [ + {"value": 0, "name": "false"}, + {"value": 1, "name": "true"}, + {"value": 2, "name": "undefined", "jsrepr": "undefined"} + ] + }, "string view": { "category": "structure", "members": [ @@ -3810,7 +3818,7 @@ "extensible": "in", "members": [ {"name": "format", "type": "texture format"}, - {"name": "depth write enabled", "type": "bool", "default": "false"}, + {"name": "depth write enabled", "type": "optional bool", "default": "undefined"}, {"name": "depth compare", "type": "compare function", "default": "undefined"}, {"name": "stencil front", "type": "stencil face state"}, {"name": "stencil back", "type": "stencil face state"}, diff --git a/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp b/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp index 0ff2f3f1691..945be8090e0 100644 --- a/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp +++ b/src/dawn/native/ApplyClearColorValueWithDrawHelper.cpp @@ -168,6 +168,7 @@ ResultOrError GetOrCreateApplyClearValueWithDrawPipeline( renderPipelineDesc.fragment = &fragment; renderPipelineDesc.multisample.count = key.sampleCount; DepthStencilState depthStencilState = {}; + depthStencilState.depthWriteEnabled = false; if (key.depthStencilFormat != wgpu::TextureFormat::Undefined) { depthStencilState.format = key.depthStencilFormat; renderPipelineDesc.depthStencil = &depthStencilState; diff --git a/src/dawn/native/BlitBufferToDepthStencil.cpp b/src/dawn/native/BlitBufferToDepthStencil.cpp index c6bf28a7933..0ecdc89c59e 100644 --- a/src/dawn/native/BlitBufferToDepthStencil.cpp +++ b/src/dawn/native/BlitBufferToDepthStencil.cpp @@ -162,7 +162,7 @@ ResultOrError> GetOrCreateRG8ToDepth16UnormPipeline(Devi DepthStencilState dsState = {}; dsState.format = wgpu::TextureFormat::Depth16Unorm; - dsState.depthWriteEnabled = true; + dsState.depthWriteEnabled = wgpu::OptionalBool::True; dsState.depthCompare = wgpu::CompareFunction::Always; RenderPipelineDescriptor renderPipelineDesc = {}; @@ -226,7 +226,7 @@ ResultOrError GetOrCreateR8ToSt DepthStencilState dsState = {}; dsState.format = format; - dsState.depthWriteEnabled = false; + dsState.depthWriteEnabled = wgpu::OptionalBool::False; dsState.depthCompare = wgpu::CompareFunction::Always; dsState.stencilFront.passOp = wgpu::StencilOperation::Replace; diff --git a/src/dawn/native/BlitColorToColorWithDraw.cpp b/src/dawn/native/BlitColorToColorWithDraw.cpp index 124607b72fc..14566ce6513 100644 --- a/src/dawn/native/BlitColorToColorWithDraw.cpp +++ b/src/dawn/native/BlitColorToColorWithDraw.cpp @@ -171,7 +171,7 @@ ResultOrError> GetOrCreateExpandMultisamplePipeline( DepthStencilState depthStencilState = {}; if (pipelineKey.depthStencilFormat != wgpu::TextureFormat::Undefined) { depthStencilState.format = pipelineKey.depthStencilFormat; - depthStencilState.depthWriteEnabled = false; + depthStencilState.depthWriteEnabled = wgpu::OptionalBool::False; depthStencilState.depthCompare = wgpu::CompareFunction::Always; renderPipelineDesc.depthStencil = &depthStencilState; diff --git a/src/dawn/native/BlitDepthToDepth.cpp b/src/dawn/native/BlitDepthToDepth.cpp index 79d3da83ae6..c2115767300 100644 --- a/src/dawn/native/BlitDepthToDepth.cpp +++ b/src/dawn/native/BlitDepthToDepth.cpp @@ -87,7 +87,7 @@ ResultOrError> GetOrCreateDepthBlitPipeline(DeviceBase* DepthStencilState dsState = {}; dsState.format = format; - dsState.depthWriteEnabled = true; + dsState.depthWriteEnabled = wgpu::OptionalBool::True; dsState.depthCompare = wgpu::CompareFunction::Always; RenderPipelineDescriptor renderPipelineDesc = {}; diff --git a/src/dawn/native/RenderPipeline.cpp b/src/dawn/native/RenderPipeline.cpp index 813de672799..64d8f4123e2 100644 --- a/src/dawn/native/RenderPipeline.cpp +++ b/src/dawn/native/RenderPipeline.cpp @@ -337,23 +337,19 @@ MaybeError ValidateDepthStencilState(const DeviceBase* device, DAWN_INVALID_IF( format->HasDepth() && descriptor->depthCompare == wgpu::CompareFunction::Undefined && - (descriptor->depthWriteEnabled || + (descriptor->depthWriteEnabled == wgpu::OptionalBool::True || descriptor->stencilFront.depthFailOp != wgpu::StencilOperation::Keep || descriptor->stencilBack.depthFailOp != wgpu::StencilOperation::Keep), "Depth stencil format (%s) has a depth aspect and depthCompare is %s while it's actually " - "used by depthWriteEnabled (%u), or stencil front depth fail operation (%s), or " + "used by depthWriteEnabled (%s), or stencil front depth fail operation (%s), or " "stencil back depth fail operation (%s).", descriptor->format, wgpu::CompareFunction::Undefined, descriptor->depthWriteEnabled, descriptor->stencilFront.depthFailOp, descriptor->stencilBack.depthFailOp); - UnpackedPtr unpacked; - DAWN_TRY_ASSIGN(unpacked, ValidateAndUnpack(descriptor)); - if (const auto* depthWriteDefined = unpacked.Get()) { - DAWN_INVALID_IF( - format->HasDepth() && !depthWriteDefined->depthWriteDefined, - "Depth stencil format (%s) has a depth aspect and depthWriteEnabled is undefined.", - descriptor->format); - } + DAWN_INVALID_IF( + format->HasDepth() && descriptor->depthWriteEnabled == wgpu::OptionalBool::Undefined, + "Depth stencil format (%s) has a depth aspect and depthWriteEnabled is undefined.", + descriptor->format); DAWN_INVALID_IF( !format->HasDepth() && descriptor->depthCompare != wgpu::CompareFunction::Always && @@ -364,8 +360,9 @@ MaybeError ValidateDepthStencilState(const DeviceBase* device, wgpu::CompareFunction::Undefined); DAWN_INVALID_IF( - !format->HasDepth() && descriptor->depthWriteEnabled, - "Depth stencil format (%s) doesn't have depth aspect while depthWriteEnabled (%u) is true.", + !format->HasDepth() && descriptor->depthWriteEnabled == wgpu::OptionalBool::True, + "Depth stencil format (%s) doesn't have depth aspect while depthWriteEnabled (%s) " + "is true.", descriptor->format, descriptor->depthWriteEnabled); if (!format->HasStencil()) { @@ -978,16 +975,16 @@ RenderPipelineBase::RenderPipelineBase(DeviceBase* device, // Reify depth option for stencil-only formats const Format& format = device->GetValidInternalFormat(mDepthStencil.format); if (!format.HasDepth()) { - mDepthStencil.depthWriteEnabled = false; + mDepthStencil.depthWriteEnabled = wgpu::OptionalBool::False; mDepthStencil.depthCompare = wgpu::CompareFunction::Always; } if (format.HasDepth() && mDepthStencil.depthCompare == wgpu::CompareFunction::Undefined && - !mDepthStencil.depthWriteEnabled && + mDepthStencil.depthWriteEnabled != wgpu::OptionalBool::True && mDepthStencil.stencilFront.depthFailOp == wgpu::StencilOperation::Keep && mDepthStencil.stencilBack.depthFailOp == wgpu::StencilOperation::Keep) { mDepthStencil.depthCompare = wgpu::CompareFunction::Always; } - mWritesDepth = mDepthStencil.depthWriteEnabled; + mWritesDepth = mDepthStencil.depthWriteEnabled == wgpu::OptionalBool::True; if (mDepthStencil.stencilWriteMask) { if ((mPrimitive.cullMode != wgpu::CullMode::Front && (mDepthStencil.stencilFront.failOp != wgpu::StencilOperation::Keep || diff --git a/src/dawn/native/d3d11/RenderPipelineD3D11.cpp b/src/dawn/native/d3d11/RenderPipelineD3D11.cpp index 91fc8412355..2c86c56edd1 100644 --- a/src/dawn/native/d3d11/RenderPipelineD3D11.cpp +++ b/src/dawn/native/d3d11/RenderPipelineD3D11.cpp @@ -405,11 +405,13 @@ MaybeError RenderPipeline::InitializeDepthStencilState() { const DepthStencilState* state = GetDepthStencilState(); D3D11_DEPTH_STENCIL_DESC depthStencilDesc = {}; - depthStencilDesc.DepthEnable = - (state->depthCompare == wgpu::CompareFunction::Always && !state->depthWriteEnabled) ? FALSE - : TRUE; - depthStencilDesc.DepthWriteMask = - state->depthWriteEnabled ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; + depthStencilDesc.DepthEnable = (state->depthCompare == wgpu::CompareFunction::Always && + state->depthWriteEnabled != wgpu::OptionalBool::True) + ? FALSE + : TRUE; + depthStencilDesc.DepthWriteMask = state->depthWriteEnabled == wgpu::OptionalBool::True + ? D3D11_DEPTH_WRITE_MASK_ALL + : D3D11_DEPTH_WRITE_MASK_ZERO; depthStencilDesc.DepthFunc = ToD3D11ComparisonFunc(state->depthCompare); depthStencilDesc.StencilEnable = UsesStencil() ? TRUE : FALSE; diff --git a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp index 0784d272375..7d727d5cde4 100644 --- a/src/dawn/native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn/native/d3d12/RenderPipelineD3D12.cpp @@ -555,11 +555,12 @@ D3D12_DEPTH_STENCIL_DESC RenderPipeline::ComputeDepthStencilDesc() { D3D12_DEPTH_STENCIL_DESC depthStencilDescriptor = {}; depthStencilDescriptor.DepthEnable = (descriptor->depthCompare == wgpu::CompareFunction::Always && - !descriptor->depthWriteEnabled) + descriptor->depthWriteEnabled != wgpu::OptionalBool::True) ? FALSE : TRUE; depthStencilDescriptor.DepthWriteMask = - descriptor->depthWriteEnabled ? D3D12_DEPTH_WRITE_MASK_ALL : D3D12_DEPTH_WRITE_MASK_ZERO; + descriptor->depthWriteEnabled == wgpu::OptionalBool::True ? D3D12_DEPTH_WRITE_MASK_ALL + : D3D12_DEPTH_WRITE_MASK_ZERO; depthStencilDescriptor.DepthFunc = ToD3D12ComparisonFunc(descriptor->depthCompare); depthStencilDescriptor.StencilEnable = UsesStencil() ? TRUE : FALSE; diff --git a/src/dawn/native/metal/RenderPipelineMTL.mm b/src/dawn/native/metal/RenderPipelineMTL.mm index f0ddef54a16..51356d1f866 100644 --- a/src/dawn/native/metal/RenderPipelineMTL.mm +++ b/src/dawn/native/metal/RenderPipelineMTL.mm @@ -546,7 +546,8 @@ MTLCullMode ToMTLCullMode(wgpu::CullMode mode) { mtlDepthStencilDescriptor.depthCompareFunction = ToMetalCompareFunction(descriptor->depthCompare); - mtlDepthStencilDescriptor.depthWriteEnabled = descriptor->depthWriteEnabled; + mtlDepthStencilDescriptor.depthWriteEnabled = + descriptor->depthWriteEnabled == wgpu::OptionalBool::True; if (UsesStencil()) { NSRef backFaceStencilRef = AcquireNSRef([MTLStencilDescriptor new]); diff --git a/src/dawn/native/opengl/RenderPipelineGL.cpp b/src/dawn/native/opengl/RenderPipelineGL.cpp index 57991a0bc62..cd0387c752a 100644 --- a/src/dawn/native/opengl/RenderPipelineGL.cpp +++ b/src/dawn/native/opengl/RenderPipelineGL.cpp @@ -345,13 +345,13 @@ void RenderPipeline::ApplyDepthStencilState(const OpenGLFunctions& gl, // Depth writes only occur if depth is enabled if (descriptor->depthCompare == wgpu::CompareFunction::Always && - !descriptor->depthWriteEnabled) { + descriptor->depthWriteEnabled != wgpu::OptionalBool::True) { gl.Disable(GL_DEPTH_TEST); } else { gl.Enable(GL_DEPTH_TEST); } - if (descriptor->depthWriteEnabled) { + if (descriptor->depthWriteEnabled == wgpu::OptionalBool::True) { gl.DepthMask(GL_TRUE); } else { gl.DepthMask(GL_FALSE); diff --git a/src/dawn/native/vulkan/RenderPipelineVk.cpp b/src/dawn/native/vulkan/RenderPipelineVk.cpp index b88fbd8c19f..55860c518dc 100644 --- a/src/dawn/native/vulkan/RenderPipelineVk.cpp +++ b/src/dawn/native/vulkan/RenderPipelineVk.cpp @@ -656,10 +656,11 @@ VkPipelineDepthStencilStateCreateInfo RenderPipeline::ComputeDepthStencilDesc() // Depth writes only occur if depth is enabled depthStencilState.depthTestEnable = (descriptor->depthCompare == wgpu::CompareFunction::Always && - !descriptor->depthWriteEnabled) + descriptor->depthWriteEnabled != wgpu::OptionalBool::True) ? VK_FALSE : VK_TRUE; - depthStencilState.depthWriteEnable = descriptor->depthWriteEnabled ? VK_TRUE : VK_FALSE; + depthStencilState.depthWriteEnable = + descriptor->depthWriteEnabled == wgpu::OptionalBool::True ? VK_TRUE : VK_FALSE; depthStencilState.depthCompareOp = ToVulkanCompareOp(descriptor->depthCompare); depthStencilState.depthBoundsTestEnable = false; depthStencilState.minDepthBounds = 0.0f; diff --git a/src/dawn/native/vulkan/ResolveTextureLoadingUtilsVk.cpp b/src/dawn/native/vulkan/ResolveTextureLoadingUtilsVk.cpp index 6f4cf7c3e72..1bc34c7836c 100644 --- a/src/dawn/native/vulkan/ResolveTextureLoadingUtilsVk.cpp +++ b/src/dawn/native/vulkan/ResolveTextureLoadingUtilsVk.cpp @@ -155,6 +155,7 @@ ResultOrError> GetOrCreateColorBlitPipeline( DepthStencilState depthStencilState = {}; if (pipelineKey.depthStencilFormat != wgpu::TextureFormat::Undefined) { depthStencilState.format = pipelineKey.depthStencilFormat; + depthStencilState.depthWriteEnabled = wgpu::OptionalBool::False; renderPipelineDesc.depthStencil = &depthStencilState; } diff --git a/src/dawn/node/binding/Converter.cpp b/src/dawn/node/binding/Converter.cpp index c3c383d2453..181c42ac560 100644 --- a/src/dawn/node/binding/Converter.cpp +++ b/src/dawn/node/binding/Converter.cpp @@ -922,10 +922,6 @@ bool Converter::Convert(wgpu::ColorTargetState& out, const interop::GPUColorTarg bool Converter::Convert(wgpu::DepthStencilState& out, const interop::GPUDepthStencilState& in) { out = {}; - auto depthWriteDefined = Allocate(); - depthWriteDefined->depthWriteDefined = in.depthWriteEnabled.has_value(); - out.nextInChain = depthWriteDefined; - return Convert(out.format, in.format) && Convert(out.depthWriteEnabled, in.depthWriteEnabled) && Convert(out.depthCompare, in.depthCompare) && Convert(out.stencilFront, in.stencilFront) && Convert(out.stencilBack, in.stencilBack) && @@ -1734,6 +1730,11 @@ bool Converter::Convert(wgpu::Bool& out, const bool& in) { return true; } +bool Converter::Convert(wgpu::OptionalBool& out, const std::optional& in) { + out = in; + return true; +} + char* Converter::ConvertStringReplacingNull(std::string_view in) { char* out = Allocate(in.size() + 1); out[in.size()] = '\0'; diff --git a/src/dawn/node/binding/Converter.h b/src/dawn/node/binding/Converter.h index 363d07605a2..7eeb76be02a 100644 --- a/src/dawn/node/binding/Converter.h +++ b/src/dawn/node/binding/Converter.h @@ -268,6 +268,7 @@ class Converter { [[nodiscard]] bool Convert(wgpu::PipelineLayout& out, const interop::GPUAutoLayoutMode& in); [[nodiscard]] bool Convert(wgpu::Bool& out, const bool& in); + [[nodiscard]] bool Convert(wgpu::OptionalBool& out, const std::optional& in); // Below are the various overloads of Convert() used to convert the Dawn types -> interop. [[nodiscard]] bool Convert(interop::GPUTextureDimension& out, wgpu::TextureDimension in); diff --git a/src/dawn/tests/end2end/DepthBiasTests.cpp b/src/dawn/tests/end2end/DepthBiasTests.cpp index 59667311f3d..43f817bd31f 100644 --- a/src/dawn/tests/end2end/DepthBiasTests.cpp +++ b/src/dawn/tests/end2end/DepthBiasTests.cpp @@ -125,7 +125,7 @@ class DepthBiasTests : public DawnTest { renderPipelineDesc.vertex.module = vertexModule; renderPipelineDesc.cFragment.module = fragmentModule; wgpu::DepthStencilState* depthStencil = renderPipelineDesc.EnableDepthStencil(depthFormat); - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; depthStencil->depthBias = bias; depthStencil->depthBiasSlopeScale = biasSlopeScale; depthStencil->depthBiasClamp = biasClamp; diff --git a/src/dawn/tests/end2end/DepthStencilCopyTests.cpp b/src/dawn/tests/end2end/DepthStencilCopyTests.cpp index 0cae10b5395..1eb060eb544 100644 --- a/src/dawn/tests/end2end/DepthStencilCopyTests.cpp +++ b/src/dawn/tests/end2end/DepthStencilCopyTests.cpp @@ -216,7 +216,7 @@ class DepthStencilCopyTests : public DawnTestWithParamsdepthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; renderPipelineDesc.cFragment.module = utils::CreateShaderModule(device, std::string(R"( @fragment fn main() -> @builtin(frag_depth) f32 { return )" + std::to_string(regionDepth) + R"(; @@ -1109,7 +1109,7 @@ class StencilCopyTests : public DepthStencilCopyTests { renderPipelineDesc.EnableDepthStencil(GetParam().mTextureFormat); depthStencil->stencilFront.passOp = wgpu::StencilOperation::DecrementClamp; if (!hasDepth) { - depthStencil->depthWriteEnabled = false; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::False; depthStencil->depthCompare = wgpu::CompareFunction::Always; } diff --git a/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp b/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp index 0f7835ded6d..edbe12f4353 100644 --- a/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp +++ b/src/dawn/tests/end2end/DepthStencilSamplingTests.cpp @@ -690,7 +690,7 @@ TEST_P(DepthStencilSamplingTest, CheckDepthTextureRange) { pDesc1.cTargets[0].format = wgpu::TextureFormat::R32Float; pDesc1.primitive.topology = wgpu::PrimitiveTopology::PointList; pDesc1.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8); - pDesc1.cDepthStencil.depthWriteEnabled = true; + pDesc1.cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::True; wgpu::RenderPipeline pipeline1 = device.CreateRenderPipeline(&pDesc1); // The second pipeline checks the depth texture and outputs 1 to a texel on success. diff --git a/src/dawn/tests/end2end/DepthStencilStateTests.cpp b/src/dawn/tests/end2end/DepthStencilStateTests.cpp index 2071920651e..bca6738810e 100644 --- a/src/dawn/tests/end2end/DepthStencilStateTests.cpp +++ b/src/dawn/tests/end2end/DepthStencilStateTests.cpp @@ -126,7 +126,7 @@ class DepthStencilStateTest : public DawnTest { stencilFace.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = true; + baseState.depthWriteEnabled = wgpu::OptionalBool::True; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = stencilFace; baseState.stencilFront = stencilFace; @@ -134,7 +134,7 @@ class DepthStencilStateTest : public DawnTest { baseState.stencilWriteMask = 0xff; wgpu::DepthStencilState state; - state.depthWriteEnabled = true; + state.depthWriteEnabled = wgpu::OptionalBool::True; state.depthCompare = compareFunction; state.stencilBack = stencilFace; state.stencilFront = stencilFace; @@ -175,7 +175,7 @@ class DepthStencilStateTest : public DawnTest { baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = false; + baseState.depthWriteEnabled = wgpu::OptionalBool::False; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor; @@ -188,7 +188,7 @@ class DepthStencilStateTest : public DawnTest { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -228,7 +228,7 @@ class DepthStencilStateTest : public DawnTest { baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = false; + baseState.depthWriteEnabled = wgpu::OptionalBool::False; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor; @@ -241,7 +241,7 @@ class DepthStencilStateTest : public DawnTest { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; stencilFaceDescriptor.passOp = stencilOperation; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -267,7 +267,7 @@ class DepthStencilStateTest : public DawnTest { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -394,7 +394,7 @@ TEST_P(DepthStencilStateTest, Basic) { stencilFace.passOp = wgpu::StencilOperation::Undefined; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFace; state.stencilFront = stencilFace; @@ -417,7 +417,7 @@ TEST_P(DepthStencilStateTest, DepthStencilDisabled) { stencilFace.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFace; state.stencilFront = stencilFace; @@ -482,7 +482,7 @@ TEST_P(DepthStencilStateTest, DepthWriteDisabled) { stencilFace.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = true; + baseState.depthWriteEnabled = wgpu::OptionalBool::True; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = stencilFace; baseState.stencilFront = stencilFace; @@ -490,7 +490,7 @@ TEST_P(DepthStencilStateTest, DepthWriteDisabled) { baseState.stencilWriteMask = 0xff; wgpu::DepthStencilState noDepthWrite; - noDepthWrite.depthWriteEnabled = false; + noDepthWrite.depthWriteEnabled = wgpu::OptionalBool::False; noDepthWrite.depthCompare = wgpu::CompareFunction::Always; noDepthWrite.stencilBack = stencilFace; noDepthWrite.stencilFront = stencilFace; @@ -498,7 +498,7 @@ TEST_P(DepthStencilStateTest, DepthWriteDisabled) { noDepthWrite.stencilWriteMask = 0xff; wgpu::DepthStencilState checkState; - checkState.depthWriteEnabled = false; + checkState.depthWriteEnabled = wgpu::OptionalBool::False; checkState.depthCompare = wgpu::CompareFunction::Equal; checkState.stencilBack = stencilFace; checkState.stencilFront = stencilFace; @@ -596,7 +596,7 @@ TEST_P(DepthStencilStateTest, StencilReadMask) { baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = false; + baseState.depthWriteEnabled = wgpu::OptionalBool::False; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor; @@ -609,7 +609,7 @@ TEST_P(DepthStencilStateTest, StencilReadMask) { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -635,7 +635,7 @@ TEST_P(DepthStencilStateTest, StencilWriteMask) { baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = false; + baseState.depthWriteEnabled = wgpu::OptionalBool::False; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor; @@ -648,7 +648,7 @@ TEST_P(DepthStencilStateTest, StencilWriteMask) { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -674,7 +674,7 @@ TEST_P(DepthStencilStateTest, StencilFail) { baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = false; + baseState.depthWriteEnabled = wgpu::OptionalBool::False; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor; @@ -687,7 +687,7 @@ TEST_P(DepthStencilStateTest, StencilFail) { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -712,7 +712,7 @@ TEST_P(DepthStencilStateTest, StencilDepthFail) { baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = true; + baseState.depthWriteEnabled = wgpu::OptionalBool::True; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor; @@ -725,7 +725,7 @@ TEST_P(DepthStencilStateTest, StencilDepthFail) { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Replace; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Keep; wgpu::DepthStencilState state; - state.depthWriteEnabled = true; + state.depthWriteEnabled = wgpu::OptionalBool::True; state.depthCompare = wgpu::CompareFunction::Less; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -748,7 +748,7 @@ TEST_P(DepthStencilStateTest, StencilDepthPass) { baseStencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; baseStencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState baseState; - baseState.depthWriteEnabled = true; + baseState.depthWriteEnabled = wgpu::OptionalBool::True; baseState.depthCompare = wgpu::CompareFunction::Always; baseState.stencilBack = baseStencilFaceDescriptor; baseState.stencilFront = baseStencilFaceDescriptor; @@ -761,7 +761,7 @@ TEST_P(DepthStencilStateTest, StencilDepthPass) { stencilFaceDescriptor.depthFailOp = wgpu::StencilOperation::Keep; stencilFaceDescriptor.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState state; - state.depthWriteEnabled = true; + state.depthWriteEnabled = wgpu::OptionalBool::True; state.depthCompare = wgpu::CompareFunction::Less; state.stencilBack = stencilFaceDescriptor; state.stencilFront = stencilFaceDescriptor; @@ -798,7 +798,7 @@ TEST_P(DepthStencilStateTest, CreatePipelineWithAllFormats) { // Test that the front and back stencil states are set correctly (and take frontFace into account) TEST_P(DepthStencilStateTest, StencilFrontAndBackFace) { wgpu::DepthStencilState state; - state.depthWriteEnabled = false; + state.depthWriteEnabled = wgpu::OptionalBool::False; state.depthCompare = wgpu::CompareFunction::Always; state.stencilFront.compare = wgpu::CompareFunction::Always; state.stencilBack.compare = wgpu::CompareFunction::Never; @@ -813,7 +813,7 @@ TEST_P(DepthStencilStateTest, StencilFrontAndBackFace) { // Test that the depth reference of a new render pass is initialized to default value 0 TEST_P(DepthStencilStateTest, StencilReferenceInitialized) { wgpu::DepthStencilState stencilAlwaysReplaceState; - stencilAlwaysReplaceState.depthWriteEnabled = false; + stencilAlwaysReplaceState.depthWriteEnabled = wgpu::OptionalBool::False; stencilAlwaysReplaceState.depthCompare = wgpu::CompareFunction::Always; stencilAlwaysReplaceState.stencilFront.compare = wgpu::CompareFunction::Always; stencilAlwaysReplaceState.stencilFront.passOp = wgpu::StencilOperation::Replace; @@ -821,7 +821,7 @@ TEST_P(DepthStencilStateTest, StencilReferenceInitialized) { stencilAlwaysReplaceState.stencilBack.passOp = wgpu::StencilOperation::Replace; wgpu::DepthStencilState stencilEqualKeepState; - stencilEqualKeepState.depthWriteEnabled = false; + stencilEqualKeepState.depthWriteEnabled = wgpu::OptionalBool::False; stencilEqualKeepState.depthCompare = wgpu::CompareFunction::Always; stencilEqualKeepState.stencilFront.compare = wgpu::CompareFunction::Equal; stencilEqualKeepState.stencilFront.passOp = wgpu::StencilOperation::Keep; diff --git a/src/dawn/tests/end2end/FragDepthTests.cpp b/src/dawn/tests/end2end/FragDepthTests.cpp index 9af05335cf5..fb490b9a4a1 100644 --- a/src/dawn/tests/end2end/FragDepthTests.cpp +++ b/src/dawn/tests/end2end/FragDepthTests.cpp @@ -56,7 +56,7 @@ TEST_P(FragDepthTests, FragDepthIsClampedToViewport) { pDesc.cFragment.targetCount = 0; wgpu::DepthStencilState* pDescDS = pDesc.EnableDepthStencil(kDepthFormat); - pDescDS->depthWriteEnabled = true; + pDescDS->depthWriteEnabled = wgpu::OptionalBool::True; pDescDS->depthCompare = wgpu::CompareFunction::Always; wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&pDesc); @@ -119,7 +119,7 @@ TEST_P(FragDepthTests, ChangingPipelineLayoutDoesntInvalidateViewport) { upDesc.cFragment.targetCount = 0; wgpu::DepthStencilState* upDescDS = upDesc.EnableDepthStencil(kDepthFormat); - upDescDS->depthWriteEnabled = true; + upDescDS->depthWriteEnabled = wgpu::OptionalBool::True; upDescDS->depthCompare = wgpu::CompareFunction::Always; wgpu::RenderPipeline uniformPipeline = device.CreateRenderPipeline(&upDesc); @@ -137,7 +137,7 @@ TEST_P(FragDepthTests, ChangingPipelineLayoutDoesntInvalidateViewport) { spDesc.cFragment.targetCount = 0; wgpu::DepthStencilState* spDescDS = spDesc.EnableDepthStencil(kDepthFormat); - spDescDS->depthWriteEnabled = true; + spDescDS->depthWriteEnabled = wgpu::OptionalBool::True; spDescDS->depthCompare = wgpu::CompareFunction::Always; wgpu::RenderPipeline storagePipeline = device.CreateRenderPipeline(&spDesc); @@ -203,7 +203,7 @@ TEST_P(FragDepthTests, RasterizationClipBeforeFS) { pDesc.cFragment.targetCount = 0; wgpu::DepthStencilState* pDescDS = pDesc.EnableDepthStencil(kDepthFormat); - pDescDS->depthWriteEnabled = true; + pDescDS->depthWriteEnabled = wgpu::OptionalBool::True; pDescDS->depthCompare = wgpu::CompareFunction::Always; wgpu::RenderPipeline uniformPipeline = device.CreateRenderPipeline(&pDesc); diff --git a/src/dawn/tests/end2end/MultisampledRenderingTests.cpp b/src/dawn/tests/end2end/MultisampledRenderingTests.cpp index 97ba10878d5..9cdd67e5b94 100644 --- a/src/dawn/tests/end2end/MultisampledRenderingTests.cpp +++ b/src/dawn/tests/end2end/MultisampledRenderingTests.cpp @@ -334,7 +334,7 @@ class MultisampledRenderingTest : public DawnTest { if (hasDepthStencilAttachment) { wgpu::DepthStencilState* depthStencil = pipelineDescriptor.EnableDepthStencil(kDepthStencilFormat); - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; depthStencil->depthCompare = wgpu::CompareFunction::Less; } diff --git a/src/dawn/tests/end2end/MultisampledSamplingTests.cpp b/src/dawn/tests/end2end/MultisampledSamplingTests.cpp index 39b60b3d527..3c8ca16c547 100644 --- a/src/dawn/tests/end2end/MultisampledSamplingTests.cpp +++ b/src/dawn/tests/end2end/MultisampledSamplingTests.cpp @@ -93,7 +93,7 @@ class MultisampledSamplingTest : public DawnTest { desc.cAttributes[0].format = wgpu::VertexFormat::Float32x2; wgpu::DepthStencilState* depthStencil = desc.EnableDepthStencil(kDepthFormat); - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; desc.multisample.count = kSampleCount; desc.cFragment.targetCount = 1; diff --git a/src/dawn/tests/end2end/PrimitiveStateTests.cpp b/src/dawn/tests/end2end/PrimitiveStateTests.cpp index 154bcf23197..284c9c17d61 100644 --- a/src/dawn/tests/end2end/PrimitiveStateTests.cpp +++ b/src/dawn/tests/end2end/PrimitiveStateTests.cpp @@ -132,7 +132,7 @@ class DepthClippingTest : public DawnTest { descriptor.vertex.module = vsModule; descriptor.cFragment.module = fsModule; wgpu::DepthStencilState* depthStencil = descriptor.EnableDepthStencil(); - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; depthStencil->format = wgpu::TextureFormat::Depth24PlusStencil8; wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); @@ -312,7 +312,7 @@ TEST_P(DepthClippingTest, UnclippedNotClamped) { return vec4f(frag_pos.z / 4.0, 0.0, 0.0, 1.0); })"); wgpu::DepthStencilState* depthStencil = descriptor.EnableDepthStencil(); - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; depthStencil->format = wgpu::TextureFormat::Depth24PlusStencil8; wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&descriptor); diff --git a/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp b/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp index 6b7b5356677..1237c5bf334 100644 --- a/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp +++ b/src/dawn/tests/end2end/ReadOnlyDepthStencilAttachmentTests.cpp @@ -70,7 +70,7 @@ class ReadOnlyDepthStencilAttachmentTests wgpu::CompareFunction depthCompare = wgpu::CompareFunction::Always; wgpu::CompareFunction stencilCompare = wgpu::CompareFunction::Always; - bool depthWriteEnabled = false; + wgpu::OptionalBool depthWriteEnabled = wgpu::OptionalBool::False; bool stencilWriteEnabled = false; float depthClearValue = 0.0; @@ -395,7 +395,7 @@ TEST_P(ReadOnlyDepthAndStencilAttachmentTests, ModifyDepthSampleStencil) { spec1.stencilClearValue = 42; spec1.depthClearValue = 0.2; spec1.depthCompare = wgpu::CompareFunction::LessEqual; - spec1.depthWriteEnabled = true; + spec1.depthWriteEnabled = wgpu::OptionalBool::True; auto render1 = DoRender(spec1); // Stencil was read successfully, but only in the bottom part. diff --git a/src/dawn/tests/end2end/ShaderTests.cpp b/src/dawn/tests/end2end/ShaderTests.cpp index 05974b5ca00..a5309c0c84e 100644 --- a/src/dawn/tests/end2end/ShaderTests.cpp +++ b/src/dawn/tests/end2end/ShaderTests.cpp @@ -2198,7 +2198,7 @@ TEST_P(ShaderTests, FragDepthAndInstanceIndex) { desc.cFragment.module = module; desc.cFragment.targetCount = 0; wgpu::DepthStencilState* dsState = desc.EnableDepthStencil(); - dsState->depthWriteEnabled = true; + dsState->depthWriteEnabled = wgpu::OptionalBool::True; dsState->depthCompare = wgpu::CompareFunction::Always; device.CreateRenderPipeline(&desc); diff --git a/src/dawn/tests/end2end/VertexOnlyRenderPipelineTests.cpp b/src/dawn/tests/end2end/VertexOnlyRenderPipelineTests.cpp index 22ebed90656..3118c4dcb9c 100644 --- a/src/dawn/tests/end2end/VertexOnlyRenderPipelineTests.cpp +++ b/src/dawn/tests/end2end/VertexOnlyRenderPipelineTests.cpp @@ -90,32 +90,32 @@ class VertexOnlyRenderPipelineTest : public DawnTest { // ignore the stencil component depthPipelineNoFragment = CreateRenderPipeline(wgpu::CompareFunction::Always, wgpu::StencilOperation::Keep, - wgpu::CompareFunction::Always, true, false); + wgpu::CompareFunction::Always, wgpu::OptionalBool::True, false); depthPipelineWithFragment = CreateRenderPipeline(wgpu::CompareFunction::Always, wgpu::StencilOperation::Keep, - wgpu::CompareFunction::Always, true, true); + wgpu::CompareFunction::Always, wgpu::OptionalBool::True, true); // Create a vertex-only render pipeline that only modify the stencil in DepthStencilView, // and ignore the depth component stencilPipelineNoFragment = CreateRenderPipeline(wgpu::CompareFunction::Always, wgpu::StencilOperation::Replace, - wgpu::CompareFunction::Always, false, false); + wgpu::CompareFunction::Always, wgpu::OptionalBool::False, false); stencilPipelineWithFragment = CreateRenderPipeline(wgpu::CompareFunction::Always, wgpu::StencilOperation::Replace, - wgpu::CompareFunction::Always, false, true); + wgpu::CompareFunction::Always, wgpu::OptionalBool::False, true); // Create a complete render pipeline that do both depth and stencil tests, and draw to color // attachment - fullPipeline = - CreateRenderPipeline(wgpu::CompareFunction::Equal, wgpu::StencilOperation::Keep, - wgpu::CompareFunction::GreaterEqual, false, true); + fullPipeline = CreateRenderPipeline( + wgpu::CompareFunction::Equal, wgpu::StencilOperation::Keep, + wgpu::CompareFunction::GreaterEqual, wgpu::OptionalBool::False, true); } wgpu::RenderPipeline CreateRenderPipeline( wgpu::CompareFunction stencilCompare = wgpu::CompareFunction::Always, wgpu::StencilOperation stencilPassOp = wgpu::StencilOperation::Keep, wgpu::CompareFunction depthCompare = wgpu::CompareFunction::Always, - bool writeDepth = false, + wgpu::OptionalBool writeDepth = wgpu::OptionalBool::False, bool useFragment = true) { wgpu::ShaderModule vsModule = utils::CreateShaderModule(device, R"( @vertex diff --git a/src/dawn/tests/end2end/ViewportTests.cpp b/src/dawn/tests/end2end/ViewportTests.cpp index 2d6049b3746..11df0696ca6 100644 --- a/src/dawn/tests/end2end/ViewportTests.cpp +++ b/src/dawn/tests/end2end/ViewportTests.cpp @@ -122,7 +122,7 @@ class ViewportTest : public DawnTest { pipelineDesc.primitive.topology = wgpu::PrimitiveTopology::PointList; wgpu::DepthStencilState* depthStencil = pipelineDesc.EnableDepthStencil(wgpu::TextureFormat::Depth32Float); - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; wgpu::RenderPipeline pipeline = device.CreateRenderPipeline(&pipelineDesc); // Create the texture that will store the post-viewport-transform depth. diff --git a/src/dawn/tests/unittests/validation/CompatValidationTests.cpp b/src/dawn/tests/unittests/validation/CompatValidationTests.cpp index 48a1cb2cbc9..9280c2b1fac 100644 --- a/src/dawn/tests/unittests/validation/CompatValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/CompatValidationTests.cpp @@ -202,7 +202,7 @@ TEST_F(CompatValidationTest, CanNotCreatePipelineWithNonZeroDepthBiasClamp) { wgpu::DepthStencilState* depthStencil = testDescriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24Plus); - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; depthStencil->depthBias = 0; depthStencil->depthBiasSlopeScale = 0; diff --git a/src/dawn/tests/unittests/validation/PipelineAndPassCompatibilityTests.cpp b/src/dawn/tests/unittests/validation/PipelineAndPassCompatibilityTests.cpp index 32ba3f7ce02..0e361424b61 100644 --- a/src/dawn/tests/unittests/validation/PipelineAndPassCompatibilityTests.cpp +++ b/src/dawn/tests/unittests/validation/PipelineAndPassCompatibilityTests.cpp @@ -59,7 +59,7 @@ class RenderPipelineAndPassCompatibilityTests : public ValidationTest { // Enable depth/stencil write if needed wgpu::DepthStencilState* depthStencil = pipelineDescriptor.EnableDepthStencil(format); if (enableDepthWrite) { - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; } if (enableStencilWrite) { depthStencil->stencilFront.failOp = wgpu::StencilOperation::Replace; diff --git a/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp b/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp index d14f8aca77e..439c6a9664f 100644 --- a/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/RenderPipelineValidationTests.cpp @@ -292,7 +292,7 @@ TEST_F(RenderPipelineValidationTest, DepthStencilAspectRequirement) { wgpu::DepthStencilState* depthStencil = descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth24PlusStencil8); depthStencil->depthCompare = wgpu::CompareFunction::LessEqual; - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; device.CreateRenderPipeline(&descriptor); } @@ -305,7 +305,7 @@ TEST_F(RenderPipelineValidationTest, DepthStencilAspectRequirement) { wgpu::DepthStencilState* depthStencil = descriptor.EnableDepthStencil(wgpu::TextureFormat::Stencil8); depthStencil->depthCompare = wgpu::CompareFunction::LessEqual; - depthStencil->depthWriteEnabled = false; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::False; ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); } @@ -318,7 +318,7 @@ TEST_F(RenderPipelineValidationTest, DepthStencilAspectRequirement) { wgpu::DepthStencilState* depthStencil = descriptor.EnableDepthStencil(wgpu::TextureFormat::Stencil8); depthStencil->depthCompare = wgpu::CompareFunction::Undefined; - depthStencil->depthWriteEnabled = true; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); } } @@ -1363,7 +1363,7 @@ TEST_F(RenderPipelineValidationTest, DepthCompareRequiredForFormatsWithDepth) { descriptor.vertex.module = vsModule; descriptor.cFragment.module = fsModule; - descriptor.cDepthStencil.depthWriteEnabled = true; + descriptor.cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::True; descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth32Float); // Control case: Always is valid for format with depth. @@ -1375,30 +1375,30 @@ TEST_F(RenderPipelineValidationTest, DepthCompareRequiredForFormatsWithDepth) { ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); // Undefined is valid though if depthCompare is not used by anything. - descriptor.cDepthStencil.depthWriteEnabled = false; + descriptor.cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::False; descriptor.cDepthStencil.stencilFront.depthFailOp = wgpu::StencilOperation::Keep; descriptor.cDepthStencil.stencilBack.depthFailOp = wgpu::StencilOperation::Keep; device.CreateRenderPipeline(&descriptor); // Undefined is invalid if depthCompare is used by depthWriteEnabled. - descriptor.cDepthStencil.depthWriteEnabled = true; + descriptor.cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::True; descriptor.cDepthStencil.stencilFront.depthFailOp = wgpu::StencilOperation::Keep; descriptor.cDepthStencil.stencilBack.depthFailOp = wgpu::StencilOperation::Keep; ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); // Undefined is invalid if depthCompare is used by stencilFront.depthFailOp. - descriptor.cDepthStencil.depthWriteEnabled = false; + descriptor.cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::False; descriptor.cDepthStencil.stencilFront.depthFailOp = wgpu::StencilOperation::Zero; descriptor.cDepthStencil.stencilBack.depthFailOp = wgpu::StencilOperation::Keep; ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); // Undefined is invalid if depthCompare is used by stencilBack.depthFailOp. - descriptor.cDepthStencil.depthWriteEnabled = false; + descriptor.cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::False; descriptor.cDepthStencil.stencilFront.depthFailOp = wgpu::StencilOperation::Keep; descriptor.cDepthStencil.stencilBack.depthFailOp = wgpu::StencilOperation::Zero; ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); - descriptor.cDepthStencil.depthWriteEnabled = false; + descriptor.cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::False; descriptor.cDepthStencil.stencilFront.depthFailOp = wgpu::StencilOperation::Keep; descriptor.cDepthStencil.stencilBack.depthFailOp = wgpu::StencilOperation::Keep; descriptor.EnableDepthStencil(wgpu::TextureFormat::Stencil8); @@ -1423,32 +1423,35 @@ TEST_F(RenderPipelineValidationTest, DepthWriteEnabledRequiredForFormatsWithDept descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth32Float); // Control case: Set depthWriteEnabled to false for format with depth. - depthStencil->depthWriteEnabled = false; + depthStencil->depthWriteEnabled = wgpu::OptionalBool::False; device.CreateRenderPipeline(&descriptor); - // When DepthStencilStateDepthWriteDefinedDawn struct is chained, depthWriteEnabled is now - // considered optional and depthWriteDefined needs to be true for formats with depth only. - wgpu::DepthStencilStateDepthWriteDefinedDawn depthWriteDefined; depthStencil = descriptor.EnableDepthStencil(wgpu::TextureFormat::Stencil8); - depthStencil->nextInChain = &depthWriteDefined; - // depthWriteDefined set to true is valid for format with no depth. - depthWriteDefined.depthWriteDefined = true; + // depthWriteEnabled set to undefined is valid for format with no depth. + depthStencil->depthWriteEnabled = wgpu::OptionalBool::Undefined; device.CreateRenderPipeline(&descriptor); - // depthWriteDefined set to false is valid for format with no depth. - depthWriteDefined.depthWriteDefined = false; + // depthWriteEnabled set to false is valid for format with no depth. + depthStencil->depthWriteEnabled = wgpu::OptionalBool::False; device.CreateRenderPipeline(&descriptor); + // Error case: depthWriteEnabled set to true is invalid for format with no depth. + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; + ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); + depthStencil = descriptor.EnableDepthStencil(wgpu::TextureFormat::Depth32Float); - depthStencil->nextInChain = &depthWriteDefined; - // depthWriteDefined set to true is valid for format with depth. - depthWriteDefined.depthWriteDefined = true; + // depthWriteEnabled set to false is valid for format with depth. + depthStencil->depthWriteEnabled = wgpu::OptionalBool::False; + device.CreateRenderPipeline(&descriptor); + + // depthWriteEnabled set to true is valid for format with depth. + depthStencil->depthWriteEnabled = wgpu::OptionalBool::True; device.CreateRenderPipeline(&descriptor); - // Error case: depthWriteDefined set to false is invalid for format with depth. - depthWriteDefined.depthWriteDefined = false; + // Error case: depthWriteEnabled set to undefined is invalid for format with depth. + depthStencil->depthWriteEnabled = wgpu::OptionalBool::Undefined; ASSERT_DEVICE_ERROR(device.CreateRenderPipeline(&descriptor)); } diff --git a/src/dawn/tests/unittests/wire/WireOptionalTests.cpp b/src/dawn/tests/unittests/wire/WireOptionalTests.cpp index 078e42d1c8d..159d0c21431 100644 --- a/src/dawn/tests/unittests/wire/WireOptionalTests.cpp +++ b/src/dawn/tests/unittests/wire/WireOptionalTests.cpp @@ -108,7 +108,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) { wgpu::DepthStencilState depthStencilState = {}; depthStencilState.format = wgpu::TextureFormat::Depth24PlusStencil8; - depthStencilState.depthWriteEnabled = false; + depthStencilState.depthWriteEnabled = wgpu::OptionalBool::False; depthStencilState.depthCompare = wgpu::CompareFunction::Always; depthStencilState.stencilBack = stencilFace; depthStencilState.stencilFront = stencilFace; @@ -158,7 +158,7 @@ TEST_F(WireOptionalTests, OptionalStructPointer) { apiDevice, MatchesLambda([](const WGPURenderPipelineDescriptor* desc) -> bool { return desc->depthStencil != nullptr && desc->depthStencil->nextInChain == nullptr && - desc->depthStencil->depthWriteEnabled == false && + desc->depthStencil->depthWriteEnabled == WGPUOptionalBool_False && desc->depthStencil->depthCompare == WGPUCompareFunction_Always && desc->depthStencil->stencilBack.compare == WGPUCompareFunction_Always && desc->depthStencil->stencilBack.failOp == WGPUStencilOperation_Keep && diff --git a/src/dawn/utils/ComboRenderPipelineDescriptor.cpp b/src/dawn/utils/ComboRenderPipelineDescriptor.cpp index 3f653d736c4..e181766c402 100644 --- a/src/dawn/utils/ComboRenderPipelineDescriptor.cpp +++ b/src/dawn/utils/ComboRenderPipelineDescriptor.cpp @@ -104,7 +104,7 @@ ComboRenderPipelineDescriptor::ComboRenderPipelineDescriptor() { stencilFace.passOp = wgpu::StencilOperation::Keep; cDepthStencil.format = wgpu::TextureFormat::Depth24PlusStencil8; - cDepthStencil.depthWriteEnabled = false; + cDepthStencil.depthWriteEnabled = wgpu::OptionalBool::False; cDepthStencil.depthCompare = wgpu::CompareFunction::Always; cDepthStencil.stencilBack = stencilFace; cDepthStencil.stencilFront = stencilFace; diff --git a/tools/android/BUILD.gn b/tools/android/BUILD.gn index f98c605200d..f614befa7c2 100644 --- a/tools/android/BUILD.gn +++ b/tools/android/BUILD.gn @@ -126,6 +126,7 @@ dawn_json_generator("kotlin_gen") { "java/android/dawn/MapMode.kt", "java/android/dawn/MipmapFilterMode.kt", "java/android/dawn/MultisampleState.kt", + "java/android/dawn/OptionalBool.kt", "java/android/dawn/Origin3D.kt", "java/android/dawn/PipelineLayout.kt", "java/android/dawn/PipelineLayoutDescriptor.kt", diff --git a/tools/android/webgpu/src/test/java/android/dawn/MappedNamedConstantsTest.kt b/tools/android/webgpu/src/test/java/android/dawn/MappedNamedConstantsTest.kt index 95d6a940472..dd7c38833b7 100644 --- a/tools/android/webgpu/src/test/java/android/dawn/MappedNamedConstantsTest.kt +++ b/tools/android/webgpu/src/test/java/android/dawn/MappedNamedConstantsTest.kt @@ -43,6 +43,7 @@ class MappedNamedConstantsTest { MapAsyncStatus::class, MapMode::class, MipmapFilterMode::class, + OptionalBool::class, PopErrorScopeStatus::class, PowerPreference::class, PresentMode::class,