Support sampling depth and stencil of combined d/s formats

This CL adds sampling of depth-only and stencil-only texture
views on all backends. However, Metal on macOS <= 10.11 will
need a workaround to use separate depth/stencil textures for
each aspect since it is impossible to sample the stencil
aspect of a combined depth/stencil texture.

Also fixes sampling of depth24plus on D3D12 which had an
incomplete check for determining if a TYPELESS format is
necessary.

Bug: dawn:439, dawn:553
Change-Id: Id4991c565f822add200054296714e2dcd330119a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30725
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Austin Eng
2020-11-04 15:27:11 +00:00
committed by Commit Bot service account
parent 9d6265bc07
commit a0f1725c4f
9 changed files with 633 additions and 153 deletions

View File

@@ -306,6 +306,24 @@ namespace dawn_native { namespace opengl {
for (auto unit : mPipeline->GetTextureUnitsForTextureView(viewIndex)) {
gl.ActiveTexture(GL_TEXTURE0 + unit);
gl.BindTexture(target, handle);
if (ToBackend(view->GetTexture())->GetGLFormat().format ==
GL_DEPTH_STENCIL) {
Aspect aspect = view->GetAspects();
ASSERT(HasOneBit(aspect));
switch (aspect) {
case Aspect::None:
case Aspect::Color:
UNREACHABLE();
case Aspect::Depth:
gl.TexParameteri(target, GL_DEPTH_STENCIL_TEXTURE_MODE,
GL_DEPTH_COMPONENT);
break;
case Aspect::Stencil:
gl.TexParameteri(target, GL_DEPTH_STENCIL_TEXTURE_MODE,
GL_STENCIL_INDEX);
break;
}
}
}
break;
}

View File

@@ -96,6 +96,16 @@ namespace dawn_native { namespace opengl {
return true;
}
if (ToBackend(texture)->GetGLFormat().format == GL_DEPTH_STENCIL &&
(texture->GetUsage() & wgpu::TextureUsage::Sampled) != 0 &&
textureViewDescriptor->aspect == wgpu::TextureAspect::StencilOnly) {
// We need a separate view for one of the depth or stencil planes
// because each glTextureView needs it's own handle to set
// GL_DEPTH_STENCIL_TEXTURE_MODE. Choose the stencil aspect for the
// extra handle since it is likely sampled less often.
return true;
}
switch (textureViewDescriptor->dimension) {
case wgpu::TextureViewDimension::Cube:
case wgpu::TextureViewDimension::CubeArray: