Commit eaf2d928 by Courtney Goeltzenleuchter Committed by Commit Bot

Add support for OES_depth_texture

Note: Includes workaround for http://anglebug.com/3452 - some Android devices do not indicate filtering support on VK_FORMAT_D16_UNORM. Bug: angleproject:3103 Test: angle_end2end_tests --gtest_filter=DepthStencilFormatsTest.DepthTexture/* angle_end2end_tests --gtest_filter=DepthStencilFormatsTest.PackedDepthStencil/* angle_end2end_tests --gtest_filter=DepthStencilFormatsTest.DepthTextureRender/ES2_VULKAN Change-Id: Ic325fb94ab0e619a17c2e149e0e0865fa4142f3a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1575426 Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent a253cff3
...@@ -143,6 +143,18 @@ struct FeaturesVk : angle::FeatureSetBase ...@@ -143,6 +143,18 @@ struct FeaturesVk : angle::FeatureSetBase
"On Windows Intel, when the scissor is (0,0,0,0), the driver acts as if the " "On Windows Intel, when the scissor is (0,0,0,0), the driver acts as if the "
"scissor was disabled", "scissor was disabled",
&members, "http://anglebug.com/3153"}; &members, "http://anglebug.com/3153"};
// OES_depth_texture is a commonly expected feature on Android. However it
// requires that D16_UNORM support texture filtering
// (e.g. VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT) and some devices
// do not. Work-around this by setting saying D16_UNORM supports filtering
// anyway.
angle::Feature forceD16TexFilter = {
"force_D16_texture_filter", angle::FeatureCategory::VulkanWorkarounds,
"On some Android devices, VK_FORMAT_D16_UNORM does not support "
"VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT, "
"which prevents OES_depth_texture from being supported.",
&members, "http://anglebug.com/3452"};
}; };
inline FeaturesVk::FeaturesVk() = default; inline FeaturesVk::FeaturesVk() = default;
......
...@@ -188,9 +188,9 @@ ...@@ -188,9 +188,9 @@
"Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py": "Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"c50c9c66b89df7179a688cda42eb85f2", "c50c9c66b89df7179a688cda42eb85f2",
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json": "Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json":
"a6522dc0af17eebfee8b3d6d4723594f", "2590230893bdc30563cdca291a12d92b",
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_table_autogen.cpp": "Vulkan format:src/libANGLE/renderer/vulkan/vk_format_table_autogen.cpp":
"34dcf4f106f94b03f74c9fd08b22f6ed", "ba26e079062affec8cd72d48f5c91d21",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py": "Vulkan internal shader programs:src/libANGLE/renderer/vulkan/gen_vk_internal_shaders.py":
"4cc82aa02df5371fc2e3d7448a241fc1", "4cc82aa02df5371fc2e3d7448a241fc1",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/gen/BufferUtils.comp.00000000.inc": "Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/gen/BufferUtils.comp.00000000.inc":
......
...@@ -175,6 +175,7 @@ Extensions::Extensions() ...@@ -175,6 +175,7 @@ Extensions::Extensions()
compressedTextureETC(false), compressedTextureETC(false),
sRGB(false), sRGB(false),
depthTextureANGLE(false), depthTextureANGLE(false),
depthTextureOES(false),
depth32(false), depth32(false),
textureStorage(false), textureStorage(false),
textureNPOT(false), textureNPOT(false),
...@@ -665,6 +666,17 @@ static bool DetermineDepthTextureANGLESupport(const TextureCapsMap &textureCaps) ...@@ -665,6 +666,17 @@ static bool DetermineDepthTextureANGLESupport(const TextureCapsMap &textureCaps)
return GetFormatSupport(textureCaps, requiredFormats, true, true, true, true); return GetFormatSupport(textureCaps, requiredFormats, true, true, true, true);
} }
// Check for GL_OES_depth_texture
static bool DetermineDepthTextureOESSupport(const TextureCapsMap &textureCaps)
{
constexpr GLenum requiredFormats[] = {
GL_DEPTH_COMPONENT16,
GL_DEPTH_COMPONENT32_OES,
};
return GetFormatSupport(textureCaps, requiredFormats, true, true, true, true);
}
// Check for GL_OES_depth32 // Check for GL_OES_depth32
static bool DetermineDepth32Support(const TextureCapsMap &textureCaps) static bool DetermineDepth32Support(const TextureCapsMap &textureCaps)
{ {
...@@ -785,6 +797,7 @@ void Extensions::setTextureExtensionSupport(const TextureCapsMap &textureCaps) ...@@ -785,6 +797,7 @@ void Extensions::setTextureExtensionSupport(const TextureCapsMap &textureCaps)
compressedEACRG11SignedTexture = DetermineEACRG11SignedTextureSupport(textureCaps); compressedEACRG11SignedTexture = DetermineEACRG11SignedTextureSupport(textureCaps);
sRGB = DetermineSRGBTextureSupport(textureCaps); sRGB = DetermineSRGBTextureSupport(textureCaps);
depthTextureANGLE = DetermineDepthTextureANGLESupport(textureCaps); depthTextureANGLE = DetermineDepthTextureANGLESupport(textureCaps);
depthTextureOES = DetermineDepthTextureOESSupport(textureCaps);
depth32 = DetermineDepth32Support(textureCaps); depth32 = DetermineDepth32Support(textureCaps);
colorBufferFloatRGB = DetermineColorBufferFloatRGBSupport(textureCaps); colorBufferFloatRGB = DetermineColorBufferFloatRGBSupport(textureCaps);
colorBufferFloatRGBA = DetermineColorBufferFloatRGBASupport(textureCaps); colorBufferFloatRGBA = DetermineColorBufferFloatRGBASupport(textureCaps);
...@@ -847,6 +860,7 @@ const ExtensionInfoMap &GetExtensionInfoMap() ...@@ -847,6 +860,7 @@ const ExtensionInfoMap &GetExtensionInfoMap()
map["GL_CHROMIUM_compressed_texture_etc"] = enableableExtension(&Extensions::compressedTextureETC); map["GL_CHROMIUM_compressed_texture_etc"] = enableableExtension(&Extensions::compressedTextureETC);
map["GL_EXT_sRGB"] = enableableExtension(&Extensions::sRGB); map["GL_EXT_sRGB"] = enableableExtension(&Extensions::sRGB);
map["GL_ANGLE_depth_texture"] = esOnlyExtension(&Extensions::depthTextureANGLE); map["GL_ANGLE_depth_texture"] = esOnlyExtension(&Extensions::depthTextureANGLE);
map["GL_OES_depth_texture"] = esOnlyExtension(&Extensions::depthTextureOES);
map["GL_OES_depth32"] = esOnlyExtension(&Extensions::depth32); map["GL_OES_depth32"] = esOnlyExtension(&Extensions::depth32);
map["GL_EXT_texture_storage"] = enableableExtension(&Extensions::textureStorage); map["GL_EXT_texture_storage"] = enableableExtension(&Extensions::textureStorage);
map["GL_OES_texture_npot"] = enableableExtension(&Extensions::textureNPOT); map["GL_OES_texture_npot"] = enableableExtension(&Extensions::textureNPOT);
......
...@@ -117,6 +117,9 @@ struct Extensions ...@@ -117,6 +117,9 @@ struct Extensions
// GL_EXT_texture_compression_bptc // GL_EXT_texture_compression_bptc
void setTextureExtensionSupport(const TextureCapsMap &textureCaps); void setTextureExtensionSupport(const TextureCapsMap &textureCaps);
// indicate if any depth texture extension is available
bool depthTextureAny() const { return (depthTextureANGLE || depthTextureOES); }
// ES2 Extension support // ES2 Extension support
// GL_OES_element_index_uint // GL_OES_element_index_uint
...@@ -240,6 +243,9 @@ struct Extensions ...@@ -240,6 +243,9 @@ struct Extensions
// GL_ANGLE_depth_texture // GL_ANGLE_depth_texture
bool depthTextureANGLE; bool depthTextureANGLE;
// OES_depth_texture
bool depthTextureOES;
// GL_OES_depth32 // GL_OES_depth32
// Allows DEPTH_COMPONENT32_OES as a valid Renderbuffer format. // Allows DEPTH_COMPONENT32_OES as a valid Renderbuffer format.
bool depth32; bool depth32;
......
...@@ -136,6 +136,13 @@ static bool RequireExtOrExt(const Version &, const Extensions &extensions) ...@@ -136,6 +136,13 @@ static bool RequireExtOrExt(const Version &, const Extensions &extensions)
return extensions.*bool1 || extensions.*bool2; return extensions.*bool1 || extensions.*bool2;
} }
// Check support for any of three extensions
template <ExtensionBool bool1, ExtensionBool bool2, ExtensionBool bool3>
static bool RequireExtOrExtOrExt(const Version &, const Extensions &extensions)
{
return extensions.*bool1 || extensions.*bool2 || extensions.*bool3;
}
// R8, RG8 // R8, RG8
static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions) static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions)
{ {
...@@ -785,12 +792,12 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap() ...@@ -785,12 +792,12 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap()
AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloatRGB>, NeverSupported ); AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloatRGB>, NeverSupported );
AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBASupport, RequireExt<&Extensions::textureFloatLinear>, SizedFloatRGBARenderableSupport, SizedFloatRGBARenderableSupport ); AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBASupport, RequireExt<&Extensions::textureFloatLinear>, SizedFloatRGBARenderableSupport, SizedFloatRGBARenderableSupport );
// Depth stencil formats // ANGLE Depth stencil formats
// | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer | // | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, RequireES<1, 0>, RequireES<1, 0> ); AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::depthTextureOES>, RequireES<1, 0>, RequireES<1, 0> );
AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, true, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, RequireES<3, 0>, RequireES<3, 0> ); AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, true, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, RequireES<3, 0>, RequireES<3, 0> );
AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, RequireES<3, 0>, RequireES<3, 0> ); AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, RequireES<3, 0>, RequireES<3, 0> );
AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depth32>, AlwaysSupported, RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depth32> ); AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32>, AlwaysSupported, RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32>, RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32>);
AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, true, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencil>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencil>); AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, true, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencil>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencil>);
AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8, true, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireES<3, 0>, AlwaysSupported, RequireES<3, 0>, RequireES<3, 0> ); AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8, true, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireES<3, 0>, AlwaysSupported, RequireES<3, 0>, RequireES<3, 0> );
// STENCIL_INDEX8 is special-cased, see around the bottom of the list. // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
......
...@@ -1653,6 +1653,10 @@ void GenerateCaps(ID3D11Device *device, ...@@ -1653,6 +1653,10 @@ void GenerateCaps(ID3D11Device *device,
extensions->blendFuncExtended = true; extensions->blendFuncExtended = true;
extensions->maxDualSourceDrawBuffers = 1; extensions->maxDualSourceDrawBuffers = 1;
// D3D11 cannot support reading depth texture as a luminance texture.
// It treats it as a red-channel-only texture.
extensions->depthTextureOES = false;
// D3D11 Feature Level 10_0+ uses SV_IsFrontFace in HLSL to emulate gl_FrontFacing. // D3D11 Feature Level 10_0+ uses SV_IsFrontFace in HLSL to emulate gl_FrontFacing.
// D3D11 Feature Level 9_3 doesn't support SV_IsFrontFace, and has no equivalent, so can't // D3D11 Feature Level 9_3 doesn't support SV_IsFrontFace, and has no equivalent, so can't
// support gl_FrontFacing. // support gl_FrontFacing.
......
...@@ -658,6 +658,10 @@ void GenerateCaps(IDirect3D9 *d3d9, ...@@ -658,6 +658,10 @@ void GenerateCaps(IDirect3D9 *d3d9,
extensions->mapBuffer = false; extensions->mapBuffer = false;
extensions->mapBufferRange = false; extensions->mapBufferRange = false;
// D3D does not allow depth textures to have more than one mipmap level OES_depth_texture
// allows for that so we can't implement full support with the D3D9 back end.
extensions->depthTextureOES = false;
// textureRG is emulated and not performant. // textureRG is emulated and not performant.
extensions->textureRG = false; extensions->textureRG = false;
...@@ -674,6 +678,7 @@ void GenerateCaps(IDirect3D9 *d3d9, ...@@ -674,6 +678,7 @@ void GenerateCaps(IDirect3D9 *d3d9,
if (IsAMD(adapterId.VendorId)) if (IsAMD(adapterId.VendorId))
{ {
extensions->depthTextureANGLE = false; extensions->depthTextureANGLE = false;
extensions->depthTextureOES = false;
} }
} }
else else
......
...@@ -221,9 +221,7 @@ ProgramVk::DefaultUniformBlock::DefaultUniformBlock() ...@@ -221,9 +221,7 @@ ProgramVk::DefaultUniformBlock::DefaultUniformBlock()
ProgramVk::DefaultUniformBlock::~DefaultUniformBlock() = default; ProgramVk::DefaultUniformBlock::~DefaultUniformBlock() = default;
ProgramVk::ProgramVk(const gl::ProgramState &state) : ProgramImpl(state), mUniformBlocksOffsets{} ProgramVk::ProgramVk(const gl::ProgramState &state) : ProgramImpl(state), mUniformBlocksOffsets{} {}
{
}
ProgramVk::~ProgramVk() = default; ProgramVk::~ProgramVk() = default;
...@@ -998,8 +996,10 @@ angle::Result ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk, ...@@ -998,8 +996,10 @@ angle::Result ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk,
vk::CommandBuffer *srcLayoutChange; vk::CommandBuffer *srcLayoutChange;
ANGLE_TRY(image.recordCommands(contextVk, &srcLayoutChange)); ANGLE_TRY(image.recordCommands(contextVk, &srcLayoutChange));
image.changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, VkImageAspectFlags aspectFlags = image.getAspectFlags();
vk::ImageLayout::FragmentShaderReadOnly, srcLayoutChange); ASSERT(aspectFlags != 0);
image.changeLayout(aspectFlags, vk::ImageLayout::FragmentShaderReadOnly,
srcLayoutChange);
} }
image.addReadDependency(framebuffer); image.addReadDependency(framebuffer);
......
...@@ -1320,6 +1320,11 @@ void RendererVk::initFeatures(const ExtensionNameList &deviceExtensionNames) ...@@ -1320,6 +1320,11 @@ void RendererVk::initFeatures(const ExtensionNameList &deviceExtensionNames)
{ {
mFeatures.forceNonZeroScissor.enabled = true; mFeatures.forceNonZeroScissor.enabled = true;
} }
if (IsAndroid() && IsQualcomm(mPhysicalDeviceProperties.vendorID))
{
mFeatures.forceD16TexFilter.enabled = true;
}
} }
void RendererVk::initPipelineCacheVkKey() void RendererVk::initPipelineCacheVkKey()
...@@ -2284,6 +2289,12 @@ VkFormatFeatureFlags RendererVk::getFormatFeatureBits(VkFormat format, ...@@ -2284,6 +2289,12 @@ VkFormatFeatureFlags RendererVk::getFormatFeatureBits(VkFormat format,
// Otherwise query the format features and cache it. // Otherwise query the format features and cache it.
vkGetPhysicalDeviceFormatProperties(mPhysicalDevice, format, &deviceProperties); vkGetPhysicalDeviceFormatProperties(mPhysicalDevice, format, &deviceProperties);
// Workaround for some Android devices that don't indicate filtering
// support on D16_UNORM and they should.
if (mFeatures.forceD16TexFilter.enabled && format == VK_FORMAT_D16_UNORM)
{
deviceProperties.*features |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
}
} }
return deviceProperties.*features & featureBits; return deviceProperties.*features & featureBits;
......
...@@ -1340,7 +1340,7 @@ angle::Result TextureVk::getLayerLevelDrawImageView(vk::Context *context, ...@@ -1340,7 +1340,7 @@ angle::Result TextureVk::getLayerLevelDrawImageView(vk::Context *context,
// Lazily allocate the image view itself. // Lazily allocate the image view itself.
// Note that these views are specifically made to be used as color attachments, and therefore // Note that these views are specifically made to be used as color attachments, and therefore
// don't have swizzle. // don't have swizzle.
return mImage->initLayerImageView(context, mState.getType(), VK_IMAGE_ASPECT_COLOR_BIT, return mImage->initLayerImageView(context, mState.getType(), mImage->getAspectFlags(),
gl::SwizzleState(), *imageViewOut, getNativeImageLevel(level), gl::SwizzleState(), *imageViewOut, getNativeImageLevel(level),
1, getNativeImageLayer(layer), 1); 1, getNativeImageLayer(layer), 1);
} }
...@@ -1357,14 +1357,18 @@ angle::Result TextureVk::initImage(ContextVk *contextVk, ...@@ -1357,14 +1357,18 @@ angle::Result TextureVk::initImage(ContextVk *contextVk,
const uint32_t levelCount, const uint32_t levelCount,
vk::CommandBuffer *commandBuffer) vk::CommandBuffer *commandBuffer)
{ {
const RendererVk *renderer = contextVk->getRenderer(); RendererVk *renderer = contextVk->getRenderer();
const angle::Format &textureFormat = format.imageFormat();
VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT; VK_IMAGE_USAGE_SAMPLED_BIT;
if (renderer->hasImageFormatFeatureBits(format.vkImageFormat,
if (!textureFormat.isBlock) VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
{
imageUsageFlags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
else if (renderer->hasImageFormatFeatureBits(format.vkImageFormat,
VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
{ {
imageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; imageUsageFlags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
} }
...@@ -1410,16 +1414,22 @@ angle::Result TextureVk::initImageViews(ContextVk *contextVk, ...@@ -1410,16 +1414,22 @@ angle::Result TextureVk::initImageViews(ContextVk *contextVk,
uint32_t baseLevel = getNativeImageLevel(0); uint32_t baseLevel = getNativeImageLevel(0);
uint32_t baseLayer = getNativeImageLayer(0); uint32_t baseLayer = getNativeImageLayer(0);
uint32_t layerCount = mState.getType() == gl::TextureType::CubeMap ? gl::kCubeFaceCount : 1; uint32_t layerCount = mState.getType() == gl::TextureType::CubeMap ? gl::kCubeFaceCount : 1;
VkImageAspectFlags aspectFlags = vk::GetFormatAspectFlags(format.angleFormat());
// If we are reading a depth buffer, select only the depth component/aspect
if (aspectFlags & VK_IMAGE_ASPECT_DEPTH_BIT)
{
aspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT;
}
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), VK_IMAGE_ASPECT_COLOR_BIT, ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
mappedSwizzle, &mReadMipmapImageView, baseLevel, &mReadMipmapImageView, baseLevel, levelCount, baseLayer,
levelCount, baseLayer, layerCount)); layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), VK_IMAGE_ASPECT_COLOR_BIT, ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
mappedSwizzle, &mReadBaseLevelImageView, baseLevel, 1, &mReadBaseLevelImageView, baseLevel, 1, baseLayer,
baseLayer, layerCount)); layerCount));
if (!format.imageFormat().isBlock) if (!format.imageFormat().isBlock)
{ {
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), VK_IMAGE_ASPECT_COLOR_BIT, ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags,
gl::SwizzleState(), &mDrawBaseLevelImageView, gl::SwizzleState(), &mDrawBaseLevelImageView,
baseLevel, 1, baseLayer, layerCount)); baseLevel, 1, baseLayer, layerCount));
} }
......
...@@ -224,6 +224,10 @@ ...@@ -224,6 +224,10 @@
"buffer": "NONE", "buffer": "NONE",
"image": "D24_UNORM_S8_UINT" "image": "D24_UNORM_S8_UINT"
}, },
"D32_UNORM": {
"buffer": "NONE",
"image": "D24_UNORM_S8_UINT"
},
"ETC1_R8G8B8_UNORM_BLOCK": { "ETC1_R8G8B8_UNORM_BLOCK": {
"buffer": "NONE", "buffer": "NONE",
"image": "ETC2_R8G8B8_UNORM_BLOCK" "image": "ETC2_R8G8B8_UNORM_BLOCK"
......
...@@ -695,7 +695,19 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat) ...@@ -695,7 +695,19 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat)
break; break;
case angle::FormatID::D32_UNORM: case angle::FormatID::D32_UNORM:
// This format is not implemented in Vulkan. internalFormat = GL_DEPTH_COMPONENT32_OES;
{
static constexpr ImageFormatInitInfo kInfo[] = {
{angle::FormatID::D24_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, nullptr},
{angle::FormatID::D32_FLOAT_S8X24_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, nullptr},
{angle::FormatID::D24_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, nullptr}};
initImageFallback(renderer, kInfo, ArraySize(kInfo));
}
bufferFormatID = angle::FormatID::NONE;
vkBufferFormat = VK_FORMAT_UNDEFINED;
vkBufferFormatIsPacked = false;
vertexLoadFunction = nullptr;
vertexLoadRequiresConversion = true;
break; break;
case angle::FormatID::EAC_R11G11_SNORM_BLOCK: case angle::FormatID::EAC_R11G11_SNORM_BLOCK:
......
...@@ -321,6 +321,18 @@ void MapSwizzleState(const vk::Format &format, ...@@ -321,6 +321,18 @@ void MapSwizzleState(const vk::Format &format,
swizzleStateOut->swizzleAlpha = swizzleState.swizzleRed; swizzleStateOut->swizzleAlpha = swizzleState.swizzleRed;
break; break;
default: default:
if (angleFormat.hasDepthOrStencilBits())
{
swizzleStateOut->swizzleRed =
angleFormat.depthBits > 0 ? swizzleState.swizzleRed : GL_ZERO;
swizzleStateOut->swizzleGreen =
angleFormat.depthBits > 0 ? swizzleState.swizzleRed : GL_ZERO;
swizzleStateOut->swizzleBlue =
angleFormat.depthBits > 0 ? swizzleState.swizzleRed : GL_ZERO;
swizzleStateOut->swizzleAlpha = GL_ONE;
}
else
{
// Set any missing channel to default in case the emulated format has that channel. // Set any missing channel to default in case the emulated format has that channel.
swizzleStateOut->swizzleRed = swizzleStateOut->swizzleRed =
angleFormat.redBits > 0 ? swizzleState.swizzleRed : GL_ZERO; angleFormat.redBits > 0 ? swizzleState.swizzleRed : GL_ZERO;
...@@ -330,6 +342,7 @@ void MapSwizzleState(const vk::Format &format, ...@@ -330,6 +342,7 @@ void MapSwizzleState(const vk::Format &format,
angleFormat.blueBits > 0 ? swizzleState.swizzleBlue : GL_ZERO; angleFormat.blueBits > 0 ? swizzleState.swizzleBlue : GL_ZERO;
swizzleStateOut->swizzleAlpha = swizzleStateOut->swizzleAlpha =
angleFormat.alphaBits > 0 ? swizzleState.swizzleAlpha : GL_ONE; angleFormat.alphaBits > 0 ? swizzleState.swizzleAlpha : GL_ONE;
}
break; break;
} }
} }
......
...@@ -1683,6 +1683,10 @@ void ImageHelper::clearColor(const VkClearColorValue &color, ...@@ -1683,6 +1683,10 @@ void ImageHelper::clearColor(const VkClearColorValue &color,
void ImageHelper::clearDepthStencil(VkImageAspectFlags imageAspectFlags, void ImageHelper::clearDepthStencil(VkImageAspectFlags imageAspectFlags,
VkImageAspectFlags clearAspectFlags, VkImageAspectFlags clearAspectFlags,
const VkClearDepthStencilValue &depthStencil, const VkClearDepthStencilValue &depthStencil,
uint32_t baseMipLevel,
uint32_t levelCount,
uint32_t baseArrayLayer,
uint32_t layerCount,
vk::CommandBuffer *commandBuffer) vk::CommandBuffer *commandBuffer)
{ {
ASSERT(valid()); ASSERT(valid());
...@@ -1691,10 +1695,10 @@ void ImageHelper::clearDepthStencil(VkImageAspectFlags imageAspectFlags, ...@@ -1691,10 +1695,10 @@ void ImageHelper::clearDepthStencil(VkImageAspectFlags imageAspectFlags,
VkImageSubresourceRange clearRange = { VkImageSubresourceRange clearRange = {
/*aspectMask*/ clearAspectFlags, /*aspectMask*/ clearAspectFlags,
/*baseMipLevel*/ 0, /*baseMipLevel*/ baseMipLevel,
/*levelCount*/ 1, /*levelCount*/ levelCount,
/*baseArrayLayer*/ 0, /*baseArrayLayer*/ baseArrayLayer,
/*layerCount*/ 1, /*layerCount*/ layerCount,
}; };
commandBuffer->clearDepthStencilImage(mImage, getCurrentLayout(), depthStencil, 1, &clearRange); commandBuffer->clearDepthStencilImage(mImage, getCurrentLayout(), depthStencil, 1, &clearRange);
...@@ -1711,9 +1715,9 @@ void ImageHelper::clear(const VkClearValue &value, ...@@ -1711,9 +1715,9 @@ void ImageHelper::clear(const VkClearValue &value,
if (isDepthStencil) if (isDepthStencil)
{ {
ASSERT(mipLevel == 0 && baseArrayLayer == 0 && layerCount == 1);
const VkImageAspectFlags aspect = vk::GetDepthStencilAspectFlags(mFormat->imageFormat()); const VkImageAspectFlags aspect = vk::GetDepthStencilAspectFlags(mFormat->imageFormat());
clearDepthStencil(aspect, aspect, value.depthStencil, commandBuffer); clearDepthStencil(aspect, aspect, value.depthStencil, mipLevel, 1, baseArrayLayer,
layerCount, commandBuffer);
} }
else else
{ {
...@@ -1946,11 +1950,11 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk, ...@@ -1946,11 +1950,11 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
inputDepthPitch, stagingPointer, outputRowPitch, outputDepthPitch); inputDepthPitch, stagingPointer, outputRowPitch, outputDepthPitch);
VkBufferImageCopy copy = {}; VkBufferImageCopy copy = {};
VkImageAspectFlags aspectFlags = GetFormatAspectFlags(vkFormat.imageFormat());
copy.bufferOffset = stagingOffset; copy.bufferOffset = stagingOffset;
copy.bufferRowLength = bufferRowLength; copy.bufferRowLength = bufferRowLength;
copy.bufferImageHeight = bufferImageHeight; copy.bufferImageHeight = bufferImageHeight;
copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy.imageSubresource.mipLevel = index.getLevelIndex(); copy.imageSubresource.mipLevel = index.getLevelIndex();
copy.imageSubresource.baseArrayLayer = index.hasLayer() ? index.getLayerIndex() : 0; copy.imageSubresource.baseArrayLayer = index.hasLayer() ? index.getLayerIndex() : 0;
copy.imageSubresource.layerCount = index.getLayerCount(); copy.imageSubresource.layerCount = index.getLayerCount();
...@@ -1958,7 +1962,19 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk, ...@@ -1958,7 +1962,19 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
gl_vk::GetOffset(offset, &copy.imageOffset); gl_vk::GetOffset(offset, &copy.imageOffset);
gl_vk::GetExtent(extents, &copy.imageExtent); gl_vk::GetExtent(extents, &copy.imageExtent);
// TODO: http://anglebug.com/3437 - need to split packed depth_stencil into
// staging buffers for upload.
// Ignore stencil for now.
if (aspectFlags & VK_IMAGE_ASPECT_STENCIL_BIT)
{
aspectFlags &= ~VK_IMAGE_ASPECT_STENCIL_BIT;
}
if (aspectFlags)
{
copy.imageSubresource.aspectMask = aspectFlags;
mSubresourceUpdates.emplace_back(bufferHandle, copy); mSubresourceUpdates.emplace_back(bufferHandle, copy);
}
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1984,6 +2000,9 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk ...@@ -1984,6 +2000,9 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk
copy.imageSubresource.baseArrayLayer = imageIndex.hasLayer() ? imageIndex.getLayerIndex() : 0; copy.imageSubresource.baseArrayLayer = imageIndex.hasLayer() ? imageIndex.getLayerIndex() : 0;
copy.imageSubresource.layerCount = imageIndex.getLayerCount(); copy.imageSubresource.layerCount = imageIndex.getLayerCount();
// Note: Only support color now
ASSERT(getAspectFlags() == VK_IMAGE_ASPECT_COLOR_BIT);
gl_vk::GetOffset(offset, &copy.imageOffset); gl_vk::GetOffset(offset, &copy.imageOffset);
gl_vk::GetExtent(extents, &copy.imageExtent); gl_vk::GetExtent(extents, &copy.imageExtent);
......
...@@ -754,6 +754,10 @@ class ImageHelper final : public CommandGraphResource ...@@ -754,6 +754,10 @@ class ImageHelper final : public CommandGraphResource
void clearDepthStencil(VkImageAspectFlags imageAspectFlags, void clearDepthStencil(VkImageAspectFlags imageAspectFlags,
VkImageAspectFlags clearAspectFlags, VkImageAspectFlags clearAspectFlags,
const VkClearDepthStencilValue &depthStencil, const VkClearDepthStencilValue &depthStencil,
uint32_t baseMipLevel,
uint32_t levelCount,
uint32_t baseArrayLayer,
uint32_t layerCount,
vk::CommandBuffer *commandBuffer); vk::CommandBuffer *commandBuffer);
struct SubresourceUpdate struct SubresourceUpdate
......
...@@ -730,9 +730,21 @@ bool ValidateES2CopyTexImageParameters(Context *context, ...@@ -730,9 +730,21 @@ bool ValidateES2CopyTexImageParameters(Context *context,
case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16: case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT32_OES: case GL_DEPTH_COMPONENT32_OES:
if (context->getExtensions().depthTextureAny())
{
context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
return false;
}
else
{
context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false;
}
break;
case GL_DEPTH_STENCIL_OES: case GL_DEPTH_STENCIL_OES:
case GL_DEPTH24_STENCIL8_OES: case GL_DEPTH24_STENCIL8_OES:
if (context->getExtensions().depthTextureANGLE) if (context->getExtensions().depthTextureAny() ||
context->getExtensions().packedDepthStencil)
{ {
context->validationError(GL_INVALID_OPERATION, kInvalidFormat); context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
return false; return false;
...@@ -742,6 +754,7 @@ bool ValidateES2CopyTexImageParameters(Context *context, ...@@ -742,6 +754,7 @@ bool ValidateES2CopyTexImageParameters(Context *context,
context->validationError(GL_INVALID_ENUM, kEnumNotSupported); context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false; return false;
} }
break;
default: default:
context->validationError(GL_INVALID_ENUM, kEnumNotSupported); context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false; return false;
...@@ -1497,7 +1510,9 @@ bool ValidateES2TexImageParameters(Context *context, ...@@ -1497,7 +1510,9 @@ bool ValidateES2TexImageParameters(Context *context,
break; break;
case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT:
case GL_DEPTH_STENCIL_OES: case GL_DEPTH_STENCIL_OES:
if (!context->getExtensions().depthTextureANGLE) if (!context->getExtensions().depthTextureANGLE &&
!(context->getExtensions().packedDepthStencil &&
context->getExtensions().depthTextureOES))
{ {
context->validationError(GL_INVALID_ENUM, kEnumNotSupported); context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false; return false;
...@@ -1509,6 +1524,8 @@ bool ValidateES2TexImageParameters(Context *context, ...@@ -1509,6 +1524,8 @@ bool ValidateES2TexImageParameters(Context *context,
} }
// OES_depth_texture supports loading depth data and multiple levels, // OES_depth_texture supports loading depth data and multiple levels,
// but ANGLE_depth_texture does not // but ANGLE_depth_texture does not
if (!context->getExtensions().depthTextureOES)
{
if (pixels != nullptr) if (pixels != nullptr)
{ {
context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull); context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
...@@ -1519,6 +1536,7 @@ bool ValidateES2TexImageParameters(Context *context, ...@@ -1519,6 +1536,7 @@ bool ValidateES2TexImageParameters(Context *context,
context->validationError(GL_INVALID_OPERATION, kLevelNotZero); context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
return false; return false;
} }
}
break; break;
default: default:
break; break;
...@@ -1587,8 +1605,16 @@ bool ValidateES2TexImageParameters(Context *context, ...@@ -1587,8 +1605,16 @@ bool ValidateES2TexImageParameters(Context *context,
break; break;
case GL_DEPTH_COMPONENT: case GL_DEPTH_COMPONENT:
if (!(context->getExtensions().depthTextureAny()))
{
context->validationError(GL_INVALID_ENUM, kInvalidFormat);
return false;
}
break;
case GL_DEPTH_STENCIL: case GL_DEPTH_STENCIL:
if (!context->getExtensions().depthTextureANGLE) if (!(context->getExtensions().depthTextureANGLE ||
context->getExtensions().packedDepthStencil))
{ {
context->validationError(GL_INVALID_ENUM, kInvalidFormat); context->validationError(GL_INVALID_ENUM, kInvalidFormat);
return false; return false;
...@@ -1883,8 +1909,30 @@ bool ValidateES2TexStorageParameters(Context *context, ...@@ -1883,8 +1909,30 @@ bool ValidateES2TexStorageParameters(Context *context,
break; break;
case GL_DEPTH_COMPONENT16: case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT32_OES: case GL_DEPTH_COMPONENT32_OES:
if (!(context->getExtensions().depthTextureAny()))
{
context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false;
}
if (target != TextureType::_2D)
{
context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
return false;
}
// ANGLE_depth_texture only supports 1-level textures
if (!context->getExtensions().depthTextureOES)
{
if (levels != 1)
{
context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
return false;
}
}
break;
case GL_DEPTH24_STENCIL8_OES: case GL_DEPTH24_STENCIL8_OES:
if (!context->getExtensions().depthTextureANGLE) if (!(context->getExtensions().depthTextureANGLE ||
(context->getExtensions().packedDepthStencil &&
context->getExtensions().textureStorage)))
{ {
context->validationError(GL_INVALID_ENUM, kEnumNotSupported); context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false; return false;
...@@ -1894,13 +1942,17 @@ bool ValidateES2TexStorageParameters(Context *context, ...@@ -1894,13 +1942,17 @@ bool ValidateES2TexStorageParameters(Context *context,
context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget); context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
return false; return false;
} }
if (!context->getExtensions().packedDepthStencil)
{
// ANGLE_depth_texture only supports 1-level textures // ANGLE_depth_texture only supports 1-level textures
if (levels != 1) if (levels != 1)
{ {
context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels); context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
return false; return false;
} }
}
break; break;
default: default:
break; break;
} }
......
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