From 927410a8c1bd7ab8f52fdb8cbb59c87c2f27e331 Mon Sep 17 00:00:00 2001 From: Shahbaz Youssefi Date: Thu, 13 Jul 2023 15:02:58 -0400 Subject: [PATCH] Prevent accidental misuse of ANGLE_ENABLED ... by removing it altogether. This macro was only available when features.h was included. If that header was not included, the preprocessor would automatically consider it 0, which has the opposite effect from what was desired. Bug: angleproject:8256 Change-Id: Ia141573c0c8b44eef1388f4c3ec73ef770cd2854 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4685226 Auto-Submit: Shahbaz Youssefi Reviewed-by: Geoff Lang Commit-Queue: Geoff Lang --- src/libANGLE/ProgramLinkedResources.cpp | 2 +- src/libANGLE/features.h | 13 +++++-------- src/libANGLE/renderer/d3d/HLSLCompiler.cpp | 8 ++++---- src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp | 4 ++-- src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp | 4 ++-- src/libANGLE/renderer/d3d/d3d9/SwapChain9.cpp | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/libANGLE/ProgramLinkedResources.cpp b/src/libANGLE/ProgramLinkedResources.cpp index be425b9d1..e8f5f0d68 100644 --- a/src/libANGLE/ProgramLinkedResources.cpp +++ b/src/libANGLE/ProgramLinkedResources.cpp @@ -54,7 +54,7 @@ LinkMismatchError LinkValidateUniforms(const sh::ShaderVariable &uniform1, const sh::ShaderVariable &uniform2, std::string *mismatchedStructFieldName) { -#if ANGLE_PROGRAM_LINK_VALIDATE_UNIFORM_PRECISION == ANGLE_ENABLED +#if ANGLE_PROGRAM_LINK_VALIDATE_UNIFORM_PRECISION const bool validatePrecisionFeature = true; #else const bool validatePrecisionFeature = false; diff --git a/src/libANGLE/features.h b/src/libANGLE/features.h index a65ef28b4..a6fe076c7 100644 --- a/src/libANGLE/features.h +++ b/src/libANGLE/features.h @@ -9,9 +9,6 @@ #include "common/platform.h" -#define ANGLE_DISABLED 0 -#define ANGLE_ENABLED 1 - // Feature defaults // Direct3D9EX @@ -19,22 +16,22 @@ // D3D9Ex interfaces. In order to get debug pixel to work on a Vista/Win 7 // machine, define "ANGLE_D3D9EX=0" in your project file. #if !defined(ANGLE_D3D9EX) -# define ANGLE_D3D9EX ANGLE_ENABLED +# define ANGLE_D3D9EX 1 #endif // Vsync // ENABLED allows Vsync to be configured at runtime // DISABLED disallows Vsync #if !defined(ANGLE_VSYNC) -# define ANGLE_VSYNC ANGLE_ENABLED +# define ANGLE_VSYNC 1 #endif // Append HLSL assembly to shader debug info. Defaults to enabled in Debug and off in Release. #if !defined(ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO) # if !defined(NDEBUG) -# define ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO ANGLE_ENABLED +# define ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO 1 # else -# define ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO ANGLE_DISABLED +# define ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO 0 # endif // !defined(NDEBUG) #endif // !defined(ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO) @@ -44,7 +41,7 @@ // ENABLED validate that precision for uniforms match between vertex and fragment shaders // DISABLED allow precision for uniforms to differ between vertex and fragment shaders #if !defined(ANGLE_PROGRAM_LINK_VALIDATE_UNIFORM_PRECISION) -# define ANGLE_PROGRAM_LINK_VALIDATE_UNIFORM_PRECISION ANGLE_ENABLED +# define ANGLE_PROGRAM_LINK_VALIDATE_UNIFORM_PRECISION 1 #endif #endif // LIBANGLE_FEATURES_H_ diff --git a/src/libANGLE/renderer/d3d/HLSLCompiler.cpp b/src/libANGLE/renderer/d3d/HLSLCompiler.cpp index f053dcb5e..2a351ab1f 100644 --- a/src/libANGLE/renderer/d3d/HLSLCompiler.cpp +++ b/src/libANGLE/renderer/d3d/HLSLCompiler.cpp @@ -19,7 +19,7 @@ namespace { -#if ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED +#if ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO # ifdef CREATE_COMPILER_FLAG_INFO # undef CREATE_COMPILER_FLAG_INFO # endif @@ -82,7 +82,7 @@ bool IsCompilerFlagSet(UINT mask, UINT flag) return isFlagSet; } } -#endif // ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED +#endif // ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO enum D3DCompilerLoadLibraryResult { @@ -290,7 +290,7 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context, (*outDebugInfo) += "// COMPILER INPUT HLSL BEGIN\n\n" + hlsl + "\n// COMPILER INPUT HLSL END\n"; -#if ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED +#if ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO (*outDebugInfo) += "\n\n// ASSEMBLY BEGIN\n\n"; (*outDebugInfo) += "// Compiler configuration: " + configs[i].name + "\n// Flags:\n"; for (size_t fIx = 0; fIx < ArraySize(CompilerFlagInfos); ++fIx) @@ -318,7 +318,7 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context, std::string disassembly; ANGLE_TRY(disassembleBinary(context, binary, &disassembly)); (*outDebugInfo) += "\n" + disassembly + "\n// ASSEMBLY END\n"; -#endif // ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO == ANGLE_ENABLED +#endif // ANGLE_APPEND_ASSEMBLY_TO_SHADER_DEBUG_INFO return angle::Result::Continue; } diff --git a/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp b/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp index 8470510ea..c0ed26a7a 100644 --- a/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp +++ b/src/libANGLE/renderer/d3d/d3d11/SwapChain11.cpp @@ -286,7 +286,7 @@ EGLint SwapChain11::resetOffscreenColorBuffer(DisplayD3D *displayD3D, { IDXGIResource *offscreenTextureResource = nullptr; HRESULT hr = mOffscreenTexture.get()->QueryInterface( - __uuidof(IDXGIResource), (void **)&offscreenTextureResource); + __uuidof(IDXGIResource), (void **)&offscreenTextureResource); // Fall back to no share handle on failure if (FAILED(hr)) @@ -907,7 +907,7 @@ EGLint SwapChain11::present(DisplayD3D *displayD3D, EGLint x, EGLint y, EGLint w } UINT swapInterval = mSwapInterval; -#if ANGLE_VSYNC == ANGLE_DISABLED +#if !ANGLE_VSYNC swapInterval = 0; #endif diff --git a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp index 433555463..4ccbe3840 100644 --- a/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp +++ b/src/libANGLE/renderer/d3d/d3d9/Renderer9.cpp @@ -217,7 +217,7 @@ egl::Error Renderer9::initialize() // inclined to report a lost context, for example when the user switches // desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are // available. - if (ANGLE_D3D9EX == ANGLE_ENABLED && Direct3DCreate9ExPtr && + if (static_cast(ANGLE_D3D9EX) && Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9Ex))) { ANGLE_TRACE_EVENT0("gpu.angle", "D3d9Ex_QueryInterface"); @@ -2359,7 +2359,7 @@ bool Renderer9::isRemovedDeviceResettable() const { bool success = false; -#if ANGLE_D3D9EX == ANGLE_ENABLED +#if ANGLE_D3D9EX IDirect3D9Ex *d3d9Ex = nullptr; typedef HRESULT(WINAPI * Direct3DCreate9ExFunc)(UINT, IDirect3D9Ex **); Direct3DCreate9ExFunc Direct3DCreate9ExPtr = diff --git a/src/libANGLE/renderer/d3d/d3d9/SwapChain9.cpp b/src/libANGLE/renderer/d3d/d3d9/SwapChain9.cpp index c8abac7a5..a786e5411 100644 --- a/src/libANGLE/renderer/d3d/d3d9/SwapChain9.cpp +++ b/src/libANGLE/renderer/d3d/d3d9/SwapChain9.cpp @@ -62,7 +62,7 @@ void SwapChain9::release() static DWORD convertInterval(EGLint interval) { -#if ANGLE_VSYNC == ANGLE_DISABLED +#if !ANGLE_VSYNC return D3DPRESENT_INTERVAL_IMMEDIATE; #else switch (interval)