Skip to content

Commit 89df6de

Browse files
beaufortfrancoisDawn LUCI CQ
authored andcommitted
[dawn][opengl] Define G, B, A components of depth-stencil textures
CTS: gpuweb/cts#4427 Bug: 444702045 Change-Id: Idc1ccc5b68fdb8035d43815075668471af28af64 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/261054 Reviewed-by: Kai Ninomiya <[email protected]> Commit-Queue: Fr <[email protected]>
1 parent f491888 commit 89df6de

File tree

9 files changed

+41
-50
lines changed

9 files changed

+41
-50
lines changed

src/dawn/native/CommandBufferStateTracker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ Return FindStorageBufferBindingAliasing(const PipelineLayoutBase* pipelineLayout
270270

271271
bool TextureViewsMatch(const TextureViewBase* a, const TextureViewBase* b) {
272272
DAWN_ASSERT(a->GetTexture() == b->GetTexture());
273+
auto swizzleA = a->GetSwizzle();
274+
auto swizzleB = b->GetSwizzle();
273275
// If the texture format is multiplanar, the view formats are permitted to differ (e.g., R8
274276
// and RG8), referring to different planes of the same YUV texture. This cannot happen in
275277
// OpenGL that actually needs the validation of texture views matching so it's safe for
@@ -281,10 +283,8 @@ bool TextureViewsMatch(const TextureViewBase* a, const TextureViewBase* b) {
281283
a->GetDimension() == b->GetDimension() && a->GetBaseMipLevel() == b->GetBaseMipLevel() &&
282284
a->GetLevelCount() == b->GetLevelCount() &&
283285
a->GetBaseArrayLayer() == b->GetBaseArrayLayer() &&
284-
a->GetLayerCount() == b->GetLayerCount() && a->GetSwizzleRed() == b->GetSwizzleRed() &&
285-
a->GetSwizzleGreen() == b->GetSwizzleGreen() &&
286-
a->GetSwizzleBlue() == b->GetSwizzleBlue() &&
287-
a->GetSwizzleAlpha() == b->GetSwizzleAlpha();
286+
a->GetLayerCount() == b->GetLayerCount() && swizzleA.r == swizzleB.r &&
287+
swizzleA.g == swizzleB.g && swizzleA.b == swizzleB.b && swizzleA.a == swizzleB.a;
288288
}
289289

290290
using VectorOfTextureViews = absl::InlinedVector<const TextureViewBase*, 8>;

src/dawn/native/Texture.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,22 +1920,6 @@ wgpu::TextureComponentSwizzle TextureViewBase::GetSwizzle() const {
19201920
};
19211921
}
19221922

1923-
wgpu::ComponentSwizzle TextureViewBase::GetSwizzleRed() const {
1924-
return mSwizzleRed;
1925-
}
1926-
1927-
wgpu::ComponentSwizzle TextureViewBase::GetSwizzleGreen() const {
1928-
return mSwizzleGreen;
1929-
}
1930-
1931-
wgpu::ComponentSwizzle TextureViewBase::GetSwizzleBlue() const {
1932-
return mSwizzleBlue;
1933-
}
1934-
1935-
wgpu::ComponentSwizzle TextureViewBase::GetSwizzleAlpha() const {
1936-
return mSwizzleAlpha;
1937-
}
1938-
19391923
bool TextureViewBase::IsYCbCr() const {
19401924
return false;
19411925
}

src/dawn/native/Texture.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ class TextureViewBase : public ApiObjectBase {
371371
wgpu::TextureUsage GetInternalUsage() const;
372372

373373
wgpu::TextureComponentSwizzle GetSwizzle() const;
374-
wgpu::ComponentSwizzle GetSwizzleRed() const;
375-
wgpu::ComponentSwizzle GetSwizzleGreen() const;
376-
wgpu::ComponentSwizzle GetSwizzleBlue() const;
377-
wgpu::ComponentSwizzle GetSwizzleAlpha() const;
378374

379375
virtual bool IsYCbCr() const;
380376
// Valid to call only if `IsYCbCr()` is true.

src/dawn/native/d3d12/TextureD3D12.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -933,13 +933,7 @@ TextureView::TextureView(TextureBase* texture, const UnpackedPtr<TextureViewDesc
933933
mSrvDesc.Format =
934934
d3d::D3DShaderResourceViewFormat(GetDevice(), textureFormat, GetFormat(), aspects);
935935
if (mSrvDesc.Format != DXGI_FORMAT_UNKNOWN) {
936-
wgpu::TextureComponentSwizzle swizzle = {
937-
.r = GetSwizzleRed(),
938-
.g = GetSwizzleGreen(),
939-
.b = GetSwizzleBlue(),
940-
.a = GetSwizzleAlpha(),
941-
};
942-
936+
auto swizzle = GetSwizzle();
943937
// Stencil is accessed using the .g component in the shader.
944938
DXGI_FORMAT textureDxgiFormat = d3d::DXGITextureFormat(GetDevice(), textureFormat.format);
945939
if (d3d::IsDepthStencil(textureDxgiFormat) && aspects == Aspect::Stencil) {

src/dawn/native/opengl/CommandBufferGL.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "dawn/native/opengl/DeviceGL.h"
4646
#include "dawn/native/opengl/Forward.h"
4747
#include "dawn/native/opengl/PersistentPipelineStateGL.h"
48+
#include "dawn/native/opengl/PhysicalDeviceGL.h"
4849
#include "dawn/native/opengl/PipelineLayoutGL.h"
4950
#include "dawn/native/opengl/QuerySetGL.h"
5051
#include "dawn/native/opengl/RenderPipelineGL.h"
@@ -427,19 +428,21 @@ class BindGroupTracker : public BindGroupTrackerBase<false, uint64_t> {
427428
DAWN_GL_TRY(
428429
gl, TexParameteri(target, GL_TEXTURE_MAX_LEVEL,
429430
view->GetBaseMipLevel() + view->GetLevelCount() - 1));
430-
if (mPipelineLayout->GetDevice()->HasFeature(
431-
Feature::TextureComponentSwizzle)) {
431+
PhysicalDeviceBase* device =
432+
ToBackend(mPipelineLayout->GetDevice())->GetPhysicalDevice();
433+
if (ToBackend(device)->SupportTextureComponentSwizzle()) {
434+
wgpu::TextureComponentSwizzle swizzle = view->GetSwizzle();
435+
if (view->GetTexture()->GetFormat().HasDepthOrStencil()) {
436+
swizzle = ComposeSwizzle(kR001Swizzle, swizzle);
437+
}
432438
DAWN_GL_TRY(gl, TexParameteri(target, GL_TEXTURE_SWIZZLE_R,
433-
ComponentSwizzle(view->GetSwizzleRed())));
434-
DAWN_GL_TRY(gl,
435-
TexParameteri(target, GL_TEXTURE_SWIZZLE_G,
436-
ComponentSwizzle(view->GetSwizzleGreen())));
437-
DAWN_GL_TRY(gl,
438-
TexParameteri(target, GL_TEXTURE_SWIZZLE_B,
439-
ComponentSwizzle(view->GetSwizzleBlue())));
440-
DAWN_GL_TRY(gl,
441-
TexParameteri(target, GL_TEXTURE_SWIZZLE_A,
442-
ComponentSwizzle(view->GetSwizzleAlpha())));
439+
ComponentSwizzle(swizzle.r)));
440+
DAWN_GL_TRY(gl, TexParameteri(target, GL_TEXTURE_SWIZZLE_G,
441+
ComponentSwizzle(swizzle.g)));
442+
DAWN_GL_TRY(gl, TexParameteri(target, GL_TEXTURE_SWIZZLE_B,
443+
ComponentSwizzle(swizzle.b)));
444+
DAWN_GL_TRY(gl, TexParameteri(target, GL_TEXTURE_SWIZZLE_A,
445+
ComponentSwizzle(swizzle.a)));
443446
}
444447
}
445448

src/dawn/native/opengl/PhysicalDeviceGL.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ uint32_t GetDeviceIdFromRender(std::string_view render) {
9191
return deviceId;
9292
}
9393

94+
bool IsANGLED3D11(std::string_view renderer) {
95+
return renderer.find("ANGLE") != std::string::npos &&
96+
renderer.find("Direct3D11") != std::string::npos;
97+
}
98+
9499
bool IsANGLEDesktopGL(std::string_view renderer) {
95100
return renderer.find("ANGLE") != std::string::npos &&
96101
renderer.find("OpenGL") != std::string::npos &&
@@ -302,7 +307,7 @@ void PhysicalDevice::InitializeSupportedFeaturesImpl() {
302307
}
303308

304309
// TextureComponentSwizzle
305-
if (mFunctions.IsAtLeastGLES(3, 0) || mFunctions.IsAtLeastGL(3, 3)) {
310+
if (SupportTextureComponentSwizzle()) {
306311
EnableFeature(Feature::TextureComponentSwizzle);
307312
}
308313
}
@@ -572,4 +577,10 @@ FeatureValidationResult PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
572577

573578
void PhysicalDevice::PopulateBackendProperties(UnpackedPtr<AdapterInfo>& info) const {}
574579

580+
bool PhysicalDevice::SupportTextureComponentSwizzle() const {
581+
// Texture component swizzle requires GLES 3.0 / GL 3.3+ and is known to be incomplete or
582+
// unsupported on the ANGLE D3D11 backend (as D3D11 lacks native support).
583+
return (mFunctions.IsAtLeastGLES(3, 0) || mFunctions.IsAtLeastGL(3, 3)) && !IsANGLED3D11(mName);
584+
}
585+
575586
} // namespace dawn::native::opengl

src/dawn/native/opengl/PhysicalDeviceGL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class PhysicalDevice : public PhysicalDeviceBase {
5757
InstanceBase* instance,
5858
const Surface* surface) const override;
5959

60+
bool SupportTextureComponentSwizzle() const;
61+
6062
private:
6163
PhysicalDevice(wgpu::BackendType backendType, Ref<DisplayEGL> display);
6264

src/dawn/native/opengl/TextureGL.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ bool RequiresCreatingNewTextureView(
125125
return true;
126126
}
127127

128-
// TODO(414312052): Use TextureViewBase::UsesNonDefaultSwizzle() instead of
129-
// textureViewDescriptor.
128+
// TODO(414312052): We're doing a simple check against the default kRGBASwizzle, even though a
129+
// more rigorous check against the implicitly inherited swizzle would be technically better.
130+
// We're deferring that complexity because the simple check is "good enough" for now, and the
131+
// issue is minimal (only affecting Desktop GL).
130132
if (auto* swizzleDesc = textureViewDescriptor.Get<TextureComponentSwizzleDescriptor>()) {
131133
auto swizzle = swizzleDesc->swizzle.WithTrivialFrontendDefaults();
132-
if (swizzle.r != wgpu::ComponentSwizzle::R || swizzle.g != wgpu::ComponentSwizzle::G ||
133-
swizzle.b != wgpu::ComponentSwizzle::B || swizzle.a != wgpu::ComponentSwizzle::A) {
134+
if (!AreSwizzleEquivalent(*ToCppAPI(&swizzle), kRGBASwizzle)) {
134135
return true;
135136
}
136137
}

src/dawn/tests/end2end/ArchTierLimitsExhaustive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,9 @@ AddDevice({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
388388
AddDevice({1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, }, "Metal_Intel_R__UHD_Graphics_630");
389389
AddDevice({0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, }, "OpenGLES_ANGLE__Google__Vulkan_1_3_0__SwiftShader_Device__Subzero___0x0000C0DE____SwiftShader_driver_5_0_0__compat");
390390
AddDevice({0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, }, "OpenGLES_ANGLE__Google__Vulkan_1_3_0__SwiftShader_Device__Subzero___0x0000C0DE____SwiftShader_driver_5_0_0__compat");
391-
AddDevice({0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, }, "OpenGLES_ANGLE__Intel__Intel_R__UHD_Graphics_630__0x00009BC5__Direct3D11_vs_5_0_ps_5_0__D3D11_31_0_101_2127__compat");
391+
AddDevice({0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, "OpenGLES_ANGLE__Intel__Intel_R__UHD_Graphics_630__0x00009BC5__Direct3D11_vs_5_0_ps_5_0__D3D11_31_0_101_2127__compat");
392392
AddDevice({0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, }, "OpenGLES_ANGLE__Intel__Intel_R__UHD_Graphics_770__0x00004680__Direct3D11_vs_5_0_ps_5_0__D3D11_31_0_101_5333__compat");
393-
AddDevice({0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, }, "OpenGLES_ANGLE__NVIDIA__NVIDIA_GeForce_GTX_1660__0x00002184__Direct3D11_vs_5_0_ps_5_0__D3D11_31_0_15_4601__compat");
393+
AddDevice({0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, "OpenGLES_ANGLE__NVIDIA__NVIDIA_GeForce_GTX_1660__0x00002184__Direct3D11_vs_5_0_ps_5_0__D3D11_31_0_15_4601__compat");
394394
AddDevice({1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, }, "Vulkan_GeForce_GTX_1660");
395395
AddDevice({1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, }, "Vulkan_Intel_R__UHD_Graphics_630");
396396
AddDevice({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, }, "Vulkan_Intel_R__UHD_Graphics_630__CML_GT2");

0 commit comments

Comments
 (0)