From 387acb7673a152d9348f3c43e4ef6130b29651e1 Mon Sep 17 00:00:00 2001 From: Rui Shi Date: Fri, 12 Jun 2026 11:08:07 -0700 Subject: [PATCH 1/2] D3D11On12: fix clang errors blocking PCH compile and dependent template lookups Fixes the clang-cl errors that surface when building D3D11On12 under USE_CLANG=1. MSVC accepts all of these forms; clang strictly enforces the standard. Behavior on MSVC is byte-identical after the changes. Three patterns are fixed: * Pattern A - `static constexpr` -> `static const` on lookup arrays whose initializers are not core constant expressions (`(EnumType)` casts). - include/VideoTranslate.hpp:86 (`VideoDecodeArgumentType::map`) - src/device.cpp:34 (local `D3D12_FORMAT_SUPPORT1_CAPTURE`) * Pattern B - eliminate the partial-specialization ambiguity in `InitializeDeferredHandle<>` by forcing the 5+-arg specialization to require at least one extra arg (parameter pack must be non-empty), so the 4-arg case is unambiguously handled by the existing 4-arg partial specialization. - include/DeviceChild.hpp:50-57 * Pattern C - insert the `template` keyword on dependent-template-name calls in the `FillContextDDIs` function template, so clang parses the `<` as the start of a template-id rather than as less-than. - src/device.cpp:358-391 (30 sites: SetShader, SetShaderWithIfaces, SetShaderResources, SetConstantBuffers, SetSamplers, six shader stages each) Validated against an OS enlistment by building onecoreuap\windows\DirectX\dxg\d3d11\d3d11on12 (24 files compiled, 0 errors) and the sibling onecoreuap\windows\DirectX\dxg\d3d11\D3D11On12Internal (6 files, 0 errors) under USE_CLANG=1, plus an MSVC build at the same scope (49 files, 0 errors) to confirm no regression. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- include/DeviceChild.hpp | 6 ++-- include/VideoTranslate.hpp | 2 +- src/device.cpp | 70 +++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/include/DeviceChild.hpp b/include/DeviceChild.hpp index 04ea43b..b55670f 100644 --- a/include/DeviceChild.hpp +++ b/include/DeviceChild.hpp @@ -47,10 +47,10 @@ namespace D3D11On12 destroy = InitializeDeferredHandle::Destroy; } - template - struct InitializeDeferredHandle + template + struct InitializeDeferredHandle { - static void Initialize(D3D10DDI_HDEVICE, const UINT*, D3D10DDI_HSHADER handle, D3D10DDI_HRTSHADER rtHandle, TArgs...) + static void Initialize(D3D10DDI_HDEVICE, const UINT*, D3D10DDI_HSHADER handle, D3D10DDI_HRTSHADER rtHandle, TFirst, TArgs...) { reinterpret_cast*>(handle.pDrvPrivate)->m_ImmediateHandle = D3D10DDI_HSHADER{ rtHandle.handle }; } diff --git a/include/VideoTranslate.hpp b/include/VideoTranslate.hpp index 781d28f..532f2c3 100644 --- a/include/VideoTranslate.hpp +++ b/include/VideoTranslate.hpp @@ -83,7 +83,7 @@ namespace D3D11On12 static inline D3D12_VIDEO_DECODE_ARGUMENT_TYPE VideoDecodeArgumentType(D3D11_DDI_VIDEO_DECODER_BUFFER_TYPE Type11) { - static constexpr D3D12_VIDEO_DECODE_ARGUMENT_TYPE map[] = + static const D3D12_VIDEO_DECODE_ARGUMENT_TYPE map[] = { (D3D12_VIDEO_DECODE_ARGUMENT_TYPE)-1, D3D12_VIDEO_DECODE_ARGUMENT_TYPE_PICTURE_PARAMETERS, diff --git a/src/device.cpp b/src/device.cpp index d63d07e..b166d3c 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -31,7 +31,7 @@ namespace D3D11On12 if (APISupport1 & D3D12_FORMAT_SUPPORT1_VIDEO_PROCESSOR_INPUT) *pData |= D3D11_1DDI_FORMAT_SUPPORT_VIDEO_PROCESSOR_INPUT; if (APISupport1 & D3D12_FORMAT_SUPPORT1_IA_VERTEX_BUFFER) *pData |= D3D11_1DDI_FORMAT_SUPPORT_VERTEX_BUFFER; if (APISupport1 & D3D12_FORMAT_SUPPORT1_BUFFER) *pData |= D3D11_1DDI_FORMAT_SUPPORT_BUFFER; - constexpr D3D12_FORMAT_SUPPORT1 D3D12_FORMAT_SUPPORT1_CAPTURE = (D3D12_FORMAT_SUPPORT1)0x80000000; + const D3D12_FORMAT_SUPPORT1 D3D12_FORMAT_SUPPORT1_CAPTURE = (D3D12_FORMAT_SUPPORT1)0x80000000; if (APISupport1 & D3D12_FORMAT_SUPPORT1_CAPTURE) *pData |= D3D11_1DDI_FORMAT_SUPPORT_CAPTURE; if (APISupport1 & D3D12_FORMAT_SUPPORT1_SHADER_GATHER) *pData |= D3D11_1DDI_FORMAT_SUPPORT_SHADER_GATHER; @@ -355,40 +355,40 @@ namespace D3D11On12 template void DeviceBase::FillContextDDIs() { - m_pDDITable->pfnVsSetShader = TDevice::SetShader; - m_pDDITable->pfnPsSetShader = TDevice::SetShader; - m_pDDITable->pfnGsSetShader = TDevice::SetShader; - m_pDDITable->pfnHsSetShader = TDevice::SetShader; - m_pDDITable->pfnDsSetShader = TDevice::SetShader; - m_pDDITable->pfnCsSetShader = TDevice::SetShader; - - m_pDDITable->pfnVsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnPsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnGsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnHsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnDsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnCsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - - m_pDDITable->pfnVsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnPsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnGsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnHsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnDsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnCsSetShaderResources = TDevice::SetShaderResources; - - m_pDDITable->pfnVsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnPsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnGsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnHsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnDsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnCsSetConstantBuffers = TDevice::SetConstantBuffers; - - m_pDDITable->pfnVsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnPsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnGsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnHsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnDsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnCsSetSamplers = TDevice::SetSamplers; + m_pDDITable->pfnVsSetShader = TDevice::template SetShader; + m_pDDITable->pfnPsSetShader = TDevice::template SetShader; + m_pDDITable->pfnGsSetShader = TDevice::template SetShader; + m_pDDITable->pfnHsSetShader = TDevice::template SetShader; + m_pDDITable->pfnDsSetShader = TDevice::template SetShader; + m_pDDITable->pfnCsSetShader = TDevice::template SetShader; + + m_pDDITable->pfnVsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnPsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnGsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnHsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnDsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnCsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + + m_pDDITable->pfnVsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnPsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnGsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnHsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnDsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnCsSetShaderResources = TDevice::template SetShaderResources; + + m_pDDITable->pfnVsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnPsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnGsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnHsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnDsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnCsSetConstantBuffers = TDevice::template SetConstantBuffers; + + m_pDDITable->pfnVsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnPsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnGsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnHsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnDsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnCsSetSamplers = TDevice::template SetSamplers; m_pDDITable->pfnDraw = TDevice::Draw; m_pDDITable->pfnDrawAuto = TDevice::DrawAuto; From b8b91f8da2118fbbff91f61228b1b4fdb975016b Mon Sep 17 00:00:00 2001 From: Rui Shi Date: Fri, 12 Jun 2026 11:08:07 -0700 Subject: [PATCH 2/2] D3D11On12: fix clang errors blocking PCH compile and dependent template lookups Fixes the clang-cl errors that surface when building D3D11On12 under USE_CLANG=1. MSVC accepts all of these forms; clang strictly enforces the standard. Behavior on MSVC is byte-identical after the changes. Three patterns are fixed: * Pattern A - `static constexpr` -> `static const` on lookup arrays whose initializers are not core constant expressions (`(EnumType)` casts). - include/VideoTranslate.hpp:86 (`VideoDecodeArgumentType::map`) - src/device.cpp:34 (local `D3D12_FORMAT_SUPPORT1_CAPTURE`) * Pattern B - eliminate the partial-specialization ambiguity in `InitializeDeferredHandle<>` by forcing the 5+-arg specialization to require the trailing shader IO signatures pointer. The 4-arg form (which only pfnCreateComputeShader hits, since Compute is the only shader stage without an IO signatures argument) is then unambiguously handled by the existing 4-arg partial specialization, whose Initialize body for that instantiation produces the same memory write. - include/DeviceChild.hpp:50-57 * Pattern C - insert the `template` keyword on dependent-template-name calls in the `FillContextDDIs` function template, so clang parses the `<` as the start of a template-id rather than as less-than. - src/device.cpp:358-391 (30 sites: SetShader, SetShaderWithIfaces, SetShaderResources, SetConstantBuffers, SetSamplers, six shader stages each) Validated against an OS enlistment by building onecoreuap\windows\DirectX\dxg\d3d11\d3d11on12 (24 files compiled, 0 errors) and the sibling onecoreuap\windows\DirectX\dxg\d3d11\D3D11On12Internal (6 files, 0 errors) under USE_CLANG=1, plus an MSVC build at the same scope (49 files, 0 errors) to confirm no regression. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- include/DeviceChild.hpp | 6 ++-- include/VideoTranslate.hpp | 2 +- src/device.cpp | 70 +++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/include/DeviceChild.hpp b/include/DeviceChild.hpp index 04ea43b..f5ebefd 100644 --- a/include/DeviceChild.hpp +++ b/include/DeviceChild.hpp @@ -47,10 +47,10 @@ namespace D3D11On12 destroy = InitializeDeferredHandle::Destroy; } - template - struct InitializeDeferredHandle + template + struct InitializeDeferredHandle { - static void Initialize(D3D10DDI_HDEVICE, const UINT*, D3D10DDI_HSHADER handle, D3D10DDI_HRTSHADER rtHandle, TArgs...) + static void Initialize(D3D10DDI_HDEVICE, const UINT*, D3D10DDI_HSHADER handle, D3D10DDI_HRTSHADER rtHandle, TSignature, TArgs...) { reinterpret_cast*>(handle.pDrvPrivate)->m_ImmediateHandle = D3D10DDI_HSHADER{ rtHandle.handle }; } diff --git a/include/VideoTranslate.hpp b/include/VideoTranslate.hpp index 781d28f..532f2c3 100644 --- a/include/VideoTranslate.hpp +++ b/include/VideoTranslate.hpp @@ -83,7 +83,7 @@ namespace D3D11On12 static inline D3D12_VIDEO_DECODE_ARGUMENT_TYPE VideoDecodeArgumentType(D3D11_DDI_VIDEO_DECODER_BUFFER_TYPE Type11) { - static constexpr D3D12_VIDEO_DECODE_ARGUMENT_TYPE map[] = + static const D3D12_VIDEO_DECODE_ARGUMENT_TYPE map[] = { (D3D12_VIDEO_DECODE_ARGUMENT_TYPE)-1, D3D12_VIDEO_DECODE_ARGUMENT_TYPE_PICTURE_PARAMETERS, diff --git a/src/device.cpp b/src/device.cpp index d63d07e..b166d3c 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -31,7 +31,7 @@ namespace D3D11On12 if (APISupport1 & D3D12_FORMAT_SUPPORT1_VIDEO_PROCESSOR_INPUT) *pData |= D3D11_1DDI_FORMAT_SUPPORT_VIDEO_PROCESSOR_INPUT; if (APISupport1 & D3D12_FORMAT_SUPPORT1_IA_VERTEX_BUFFER) *pData |= D3D11_1DDI_FORMAT_SUPPORT_VERTEX_BUFFER; if (APISupport1 & D3D12_FORMAT_SUPPORT1_BUFFER) *pData |= D3D11_1DDI_FORMAT_SUPPORT_BUFFER; - constexpr D3D12_FORMAT_SUPPORT1 D3D12_FORMAT_SUPPORT1_CAPTURE = (D3D12_FORMAT_SUPPORT1)0x80000000; + const D3D12_FORMAT_SUPPORT1 D3D12_FORMAT_SUPPORT1_CAPTURE = (D3D12_FORMAT_SUPPORT1)0x80000000; if (APISupport1 & D3D12_FORMAT_SUPPORT1_CAPTURE) *pData |= D3D11_1DDI_FORMAT_SUPPORT_CAPTURE; if (APISupport1 & D3D12_FORMAT_SUPPORT1_SHADER_GATHER) *pData |= D3D11_1DDI_FORMAT_SUPPORT_SHADER_GATHER; @@ -355,40 +355,40 @@ namespace D3D11On12 template void DeviceBase::FillContextDDIs() { - m_pDDITable->pfnVsSetShader = TDevice::SetShader; - m_pDDITable->pfnPsSetShader = TDevice::SetShader; - m_pDDITable->pfnGsSetShader = TDevice::SetShader; - m_pDDITable->pfnHsSetShader = TDevice::SetShader; - m_pDDITable->pfnDsSetShader = TDevice::SetShader; - m_pDDITable->pfnCsSetShader = TDevice::SetShader; - - m_pDDITable->pfnVsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnPsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnGsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnHsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnDsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - m_pDDITable->pfnCsSetShaderWithIfaces = TDevice::SetShaderWithIfaces; - - m_pDDITable->pfnVsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnPsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnGsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnHsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnDsSetShaderResources = TDevice::SetShaderResources; - m_pDDITable->pfnCsSetShaderResources = TDevice::SetShaderResources; - - m_pDDITable->pfnVsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnPsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnGsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnHsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnDsSetConstantBuffers = TDevice::SetConstantBuffers; - m_pDDITable->pfnCsSetConstantBuffers = TDevice::SetConstantBuffers; - - m_pDDITable->pfnVsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnPsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnGsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnHsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnDsSetSamplers = TDevice::SetSamplers; - m_pDDITable->pfnCsSetSamplers = TDevice::SetSamplers; + m_pDDITable->pfnVsSetShader = TDevice::template SetShader; + m_pDDITable->pfnPsSetShader = TDevice::template SetShader; + m_pDDITable->pfnGsSetShader = TDevice::template SetShader; + m_pDDITable->pfnHsSetShader = TDevice::template SetShader; + m_pDDITable->pfnDsSetShader = TDevice::template SetShader; + m_pDDITable->pfnCsSetShader = TDevice::template SetShader; + + m_pDDITable->pfnVsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnPsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnGsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnHsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnDsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + m_pDDITable->pfnCsSetShaderWithIfaces = TDevice::template SetShaderWithIfaces; + + m_pDDITable->pfnVsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnPsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnGsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnHsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnDsSetShaderResources = TDevice::template SetShaderResources; + m_pDDITable->pfnCsSetShaderResources = TDevice::template SetShaderResources; + + m_pDDITable->pfnVsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnPsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnGsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnHsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnDsSetConstantBuffers = TDevice::template SetConstantBuffers; + m_pDDITable->pfnCsSetConstantBuffers = TDevice::template SetConstantBuffers; + + m_pDDITable->pfnVsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnPsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnGsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnHsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnDsSetSamplers = TDevice::template SetSamplers; + m_pDDITable->pfnCsSetSamplers = TDevice::template SetSamplers; m_pDDITable->pfnDraw = TDevice::Draw; m_pDDITable->pfnDrawAuto = TDevice::DrawAuto;