Commit 87748543 by James Dong Committed by Commit Bot

GL/Vulkan: handle depth texture discrepancy

In GLES 3.0, depth textures where changed to behave like RED textures, but in GLES 2.0 with ARB/OES_depth_texture, they were treated as luminance textures. This change produces the expected behavior on GLES 2.0 for the GL backend and on GLES 3.0 for the Vulkan backend. Bug: angleproject:3540 Change-Id: Iad6b4e03cf947b27eb97dbb10419bc8bcdb11024 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1666363Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: James Dong <dongja@google.com>
parent 647f2000
...@@ -1261,22 +1261,22 @@ angle::Result TextureGL::syncState(const gl::Context *context, ...@@ -1261,22 +1261,22 @@ angle::Result TextureGL::syncState(const gl::Context *context,
// Texture state // Texture state
case gl::Texture::DIRTY_BIT_SWIZZLE_RED: case gl::Texture::DIRTY_BIT_SWIZZLE_RED:
syncTextureStateSwizzle(functions, GL_TEXTURE_SWIZZLE_R, syncTextureStateSwizzle(context, functions, GL_TEXTURE_SWIZZLE_R,
mState.getSwizzleState().swizzleRed, mState.getSwizzleState().swizzleRed,
&mAppliedSwizzle.swizzleRed); &mAppliedSwizzle.swizzleRed);
break; break;
case gl::Texture::DIRTY_BIT_SWIZZLE_GREEN: case gl::Texture::DIRTY_BIT_SWIZZLE_GREEN:
syncTextureStateSwizzle(functions, GL_TEXTURE_SWIZZLE_G, syncTextureStateSwizzle(context, functions, GL_TEXTURE_SWIZZLE_G,
mState.getSwizzleState().swizzleGreen, mState.getSwizzleState().swizzleGreen,
&mAppliedSwizzle.swizzleGreen); &mAppliedSwizzle.swizzleGreen);
break; break;
case gl::Texture::DIRTY_BIT_SWIZZLE_BLUE: case gl::Texture::DIRTY_BIT_SWIZZLE_BLUE:
syncTextureStateSwizzle(functions, GL_TEXTURE_SWIZZLE_B, syncTextureStateSwizzle(context, functions, GL_TEXTURE_SWIZZLE_B,
mState.getSwizzleState().swizzleBlue, mState.getSwizzleState().swizzleBlue,
&mAppliedSwizzle.swizzleBlue); &mAppliedSwizzle.swizzleBlue);
break; break;
case gl::Texture::DIRTY_BIT_SWIZZLE_ALPHA: case gl::Texture::DIRTY_BIT_SWIZZLE_ALPHA:
syncTextureStateSwizzle(functions, GL_TEXTURE_SWIZZLE_A, syncTextureStateSwizzle(context, functions, GL_TEXTURE_SWIZZLE_A,
mState.getSwizzleState().swizzleAlpha, mState.getSwizzleState().swizzleAlpha,
&mAppliedSwizzle.swizzleAlpha); &mAppliedSwizzle.swizzleAlpha);
break; break;
...@@ -1404,7 +1404,8 @@ GLenum TextureGL::getNativeInternalFormat(const gl::ImageIndex &index) const ...@@ -1404,7 +1404,8 @@ GLenum TextureGL::getNativeInternalFormat(const gl::ImageIndex &index) const
return getLevelInfo(index.getTarget(), index.getLevelIndex()).nativeInternalFormat; return getLevelInfo(index.getTarget(), index.getLevelIndex()).nativeInternalFormat;
} }
void TextureGL::syncTextureStateSwizzle(const FunctionsGL *functions, void TextureGL::syncTextureStateSwizzle(const gl::Context *context,
const FunctionsGL *functions,
GLenum name, GLenum name,
GLenum value, GLenum value,
GLenum *outValue) GLenum *outValue)
...@@ -1483,8 +1484,18 @@ void TextureGL::syncTextureStateSwizzle(const FunctionsGL *functions, ...@@ -1483,8 +1484,18 @@ void TextureGL::syncTextureStateSwizzle(const FunctionsGL *functions,
case GL_GREEN: case GL_GREEN:
case GL_BLUE: case GL_BLUE:
// Depth textures should sample 0 from the green and blue channels. if (context->getClientMajorVersion() <= 2)
resultSwizzle = GL_ZERO; {
// In OES_depth_texture/ARB_depth_texture, depth
// textures are treated as luminance.
resultSwizzle = GL_RED;
}
else
{
// In GLES 3.0, depth textures are treated as RED
// textures, so green and blue should be 0.
resultSwizzle = GL_ZERO;
}
break; break;
case GL_ALPHA: case GL_ALPHA:
......
...@@ -40,6 +40,8 @@ struct LevelInfoGL ...@@ -40,6 +40,8 @@ struct LevelInfoGL
GLenum nativeInternalFormat; GLenum nativeInternalFormat;
// If this mip level requires sampler-state re-writing so that only a red channel is exposed. // If this mip level requires sampler-state re-writing so that only a red channel is exposed.
// In GLES 2.0, depth textures are treated as luminance, so we check the
// context's major version when applying the depth swizzle.
bool depthStencilWorkaround; bool depthStencilWorkaround;
// Information about luminance alpha texture workarounds in the core profile. // Information about luminance alpha texture workarounds in the core profile.
...@@ -234,7 +236,8 @@ class TextureGL : public TextureImpl ...@@ -234,7 +236,8 @@ class TextureGL : public TextureImpl
const gl::Buffer *unpackBuffer, const gl::Buffer *unpackBuffer,
const uint8_t *pixels); const uint8_t *pixels);
void syncTextureStateSwizzle(const FunctionsGL *functions, void syncTextureStateSwizzle(const gl::Context *context,
const FunctionsGL *functions,
GLenum name, GLenum name,
GLenum value, GLenum value,
GLenum *outValue); GLenum *outValue);
......
...@@ -1153,7 +1153,7 @@ angle::Result TextureVk::initCubeMapRenderTargets(ContextVk *contextVk) ...@@ -1153,7 +1153,7 @@ angle::Result TextureVk::initCubeMapRenderTargets(ContextVk *contextVk)
// Users of the render target expect the views to directly view the desired layer, so we // Users of the render target expect the views to directly view the desired layer, so we
// need create a fetch view for each layer as well. // need create a fetch view for each layer as well.
gl::SwizzleState mappedSwizzle; gl::SwizzleState mappedSwizzle;
MapSwizzleState(mImage->getFormat(), mState.getSwizzleState(), &mappedSwizzle); MapSwizzleState(contextVk, mImage->getFormat(), mState.getSwizzleState(), &mappedSwizzle);
gl::TextureType arrayType = vk::Get2DTextureType(gl::kCubeFaceCount, mImage->getSamples()); gl::TextureType arrayType = vk::Get2DTextureType(gl::kCubeFaceCount, mImage->getSamples());
ANGLE_TRY(mImage->initLayerImageView(contextVk, arrayType, mImage->getAspectFlags(), ANGLE_TRY(mImage->initLayerImageView(contextVk, arrayType, mImage->getAspectFlags(),
mappedSwizzle, &mLayerFetchImageView[cubeMapFaceIndex], mappedSwizzle, &mLayerFetchImageView[cubeMapFaceIndex],
...@@ -1394,7 +1394,7 @@ angle::Result TextureVk::initImageViews(ContextVk *contextVk, ...@@ -1394,7 +1394,7 @@ angle::Result TextureVk::initImageViews(ContextVk *contextVk,
ASSERT(mImage != nullptr); ASSERT(mImage != nullptr);
gl::SwizzleState mappedSwizzle; gl::SwizzleState mappedSwizzle;
MapSwizzleState(format, mState.getSwizzleState(), &mappedSwizzle); MapSwizzleState(contextVk, format, mState.getSwizzleState(), &mappedSwizzle);
// TODO: Support non-zero base level for ES 3.0 by passing it to getNativeImageLevel. // TODO: Support non-zero base level for ES 3.0 by passing it to getNativeImageLevel.
// http://anglebug.com/3148 // http://anglebug.com/3148
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "libANGLE/Texture.h" #include "libANGLE/Texture.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/load_functions_table.h" #include "libANGLE/renderer/load_functions_table.h"
#include "libANGLE/renderer/vulkan/ContextVk.h"
#include "libANGLE/renderer/vulkan/RendererVk.h" #include "libANGLE/renderer/vulkan/RendererVk.h"
#include "libANGLE/renderer/vulkan/vk_caps_utils.h" #include "libANGLE/renderer/vulkan/vk_caps_utils.h"
...@@ -297,7 +298,8 @@ void ComposeSwizzleState(const gl::SwizzleState &first, ...@@ -297,7 +298,8 @@ void ComposeSwizzleState(const gl::SwizzleState &first,
out->swizzleAlpha = GetSwizzleStateComponent(first, second.swizzleAlpha); out->swizzleAlpha = GetSwizzleStateComponent(first, second.swizzleAlpha);
} }
void MapSwizzleState(const vk::Format &format, void MapSwizzleState(const ContextVk *contextVk,
const vk::Format &format,
const gl::SwizzleState &swizzleState, const gl::SwizzleState &swizzleState,
gl::SwizzleState *swizzleStateOut) gl::SwizzleState *swizzleStateOut)
{ {
...@@ -328,9 +330,14 @@ void MapSwizzleState(const vk::Format &format, ...@@ -328,9 +330,14 @@ void MapSwizzleState(const vk::Format &format,
default: default:
if (angleFormat.hasDepthOrStencilBits()) if (angleFormat.hasDepthOrStencilBits())
{ {
internalSwizzle.swizzleRed = angleFormat.depthBits > 0 ? GL_RED : GL_ZERO; bool hasRed = angleFormat.depthBits > 0;
internalSwizzle.swizzleGreen = angleFormat.depthBits > 0 ? GL_RED : GL_ZERO; // In OES_depth_texture/ARB_depth_texture, depth
internalSwizzle.swizzleBlue = angleFormat.depthBits > 0 ? GL_RED : GL_ZERO; // textures are treated as luminance.
bool hasGB = hasRed && contextVk->getClientMajorVersion() <= 2;
internalSwizzle.swizzleRed = hasRed ? GL_RED : GL_ZERO;
internalSwizzle.swizzleGreen = hasGB ? GL_RED : GL_ZERO;
internalSwizzle.swizzleBlue = hasGB ? GL_RED : GL_ZERO;
internalSwizzle.swizzleAlpha = GL_ONE; internalSwizzle.swizzleAlpha = GL_ONE;
} }
else else
......
...@@ -28,6 +28,7 @@ class TextureCapsMap; ...@@ -28,6 +28,7 @@ class TextureCapsMap;
namespace rx namespace rx
{ {
class RendererVk; class RendererVk;
class ContextVk;
namespace vk namespace vk
{ {
...@@ -148,7 +149,8 @@ bool HasFullTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat); ...@@ -148,7 +149,8 @@ bool HasFullTextureFormatSupport(RendererVk *renderer, VkFormat vkFormat);
// calculation is listed in the Vulkan spec at the end of the section 'Vertex Input Description'. // calculation is listed in the Vulkan spec at the end of the section 'Vertex Input Description'.
size_t GetVertexInputAlignment(const vk::Format &format); size_t GetVertexInputAlignment(const vk::Format &format);
void MapSwizzleState(const vk::Format &format, void MapSwizzleState(const ContextVk *contextVk,
const vk::Format &format,
const gl::SwizzleState &swizzleState, const gl::SwizzleState &swizzleState,
gl::SwizzleState *swizzleStateOut); gl::SwizzleState *swizzleStateOut);
} // namespace rx } // namespace rx
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment