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
"On Windows Intel, when the scissor is (0,0,0,0), the driver acts as if the "
"scissor was disabled",
&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;
......
......@@ -188,9 +188,9 @@
"Vulkan format:src/libANGLE/renderer/vulkan/gen_vk_format_table.py":
"c50c9c66b89df7179a688cda42eb85f2",
"Vulkan format:src/libANGLE/renderer/vulkan/vk_format_map.json":
"a6522dc0af17eebfee8b3d6d4723594f",
"2590230893bdc30563cdca291a12d92b",
"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":
"4cc82aa02df5371fc2e3d7448a241fc1",
"Vulkan internal shader programs:src/libANGLE/renderer/vulkan/shaders/gen/BufferUtils.comp.00000000.inc":
......
......@@ -175,6 +175,7 @@ Extensions::Extensions()
compressedTextureETC(false),
sRGB(false),
depthTextureANGLE(false),
depthTextureOES(false),
depth32(false),
textureStorage(false),
textureNPOT(false),
......@@ -665,6 +666,17 @@ static bool DetermineDepthTextureANGLESupport(const TextureCapsMap &textureCaps)
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
static bool DetermineDepth32Support(const TextureCapsMap &textureCaps)
{
......@@ -785,6 +797,7 @@ void Extensions::setTextureExtensionSupport(const TextureCapsMap &textureCaps)
compressedEACRG11SignedTexture = DetermineEACRG11SignedTextureSupport(textureCaps);
sRGB = DetermineSRGBTextureSupport(textureCaps);
depthTextureANGLE = DetermineDepthTextureANGLESupport(textureCaps);
depthTextureOES = DetermineDepthTextureOESSupport(textureCaps);
depth32 = DetermineDepth32Support(textureCaps);
colorBufferFloatRGB = DetermineColorBufferFloatRGBSupport(textureCaps);
colorBufferFloatRGBA = DetermineColorBufferFloatRGBASupport(textureCaps);
......@@ -847,6 +860,7 @@ const ExtensionInfoMap &GetExtensionInfoMap()
map["GL_CHROMIUM_compressed_texture_etc"] = enableableExtension(&Extensions::compressedTextureETC);
map["GL_EXT_sRGB"] = enableableExtension(&Extensions::sRGB);
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_EXT_texture_storage"] = enableableExtension(&Extensions::textureStorage);
map["GL_OES_texture_npot"] = enableableExtension(&Extensions::textureNPOT);
......
......@@ -117,6 +117,9 @@ struct Extensions
// GL_EXT_texture_compression_bptc
void setTextureExtensionSupport(const TextureCapsMap &textureCaps);
// indicate if any depth texture extension is available
bool depthTextureAny() const { return (depthTextureANGLE || depthTextureOES); }
// ES2 Extension support
// GL_OES_element_index_uint
......@@ -240,6 +243,9 @@ struct Extensions
// GL_ANGLE_depth_texture
bool depthTextureANGLE;
// OES_depth_texture
bool depthTextureOES;
// GL_OES_depth32
// Allows DEPTH_COMPONENT32_OES as a valid Renderbuffer format.
bool depth32;
......
......@@ -136,6 +136,13 @@ static bool RequireExtOrExt(const Version &, const Extensions &extensions)
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
static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions)
{
......@@ -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_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 |
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_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_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.
......
......@@ -1653,6 +1653,10 @@ void GenerateCaps(ID3D11Device *device,
extensions->blendFuncExtended = true;
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 9_3 doesn't support SV_IsFrontFace, and has no equivalent, so can't
// support gl_FrontFacing.
......
......@@ -658,6 +658,10 @@ void GenerateCaps(IDirect3D9 *d3d9,
extensions->mapBuffer = 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.
extensions->textureRG = false;
......@@ -674,6 +678,7 @@ void GenerateCaps(IDirect3D9 *d3d9,
if (IsAMD(adapterId.VendorId))
{
extensions->depthTextureANGLE = false;
extensions->depthTextureOES = false;
}
}
else
......@@ -710,14 +715,14 @@ void GenerateCaps(IDirect3D9 *d3d9,
extensions->robustBufferAccessBehavior = false;
extensions->blendMinMax = true;
// https://docs.microsoft.com/en-us/windows/desktop/direct3ddxgi/format-support-for-direct3d-feature-level-9-1-hardware
extensions->floatBlend = false;
extensions->framebufferBlit = true;
extensions->framebufferMultisample = true;
extensions->instancedArraysANGLE = deviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0);
extensions->floatBlend = false;
extensions->framebufferBlit = true;
extensions->framebufferMultisample = true;
extensions->instancedArraysANGLE = deviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0);
// D3D9 requires at least one attribute that has a divisor of 0, which isn't required by the EXT
// extension
extensions->instancedArraysEXT = false;
extensions->packReverseRowOrder = true;
extensions->instancedArraysEXT = false;
extensions->packReverseRowOrder = true;
extensions->standardDerivatives =
(deviceCaps.PS20Caps.Caps & D3DPS20CAPS_GRADIENTINSTRUCTIONS) != 0;
extensions->shaderTextureLOD = true;
......
......@@ -221,9 +221,7 @@ ProgramVk::DefaultUniformBlock::DefaultUniformBlock()
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;
......@@ -998,8 +996,10 @@ angle::Result ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk,
vk::CommandBuffer *srcLayoutChange;
ANGLE_TRY(image.recordCommands(contextVk, &srcLayoutChange));
image.changeLayout(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::FragmentShaderReadOnly, srcLayoutChange);
VkImageAspectFlags aspectFlags = image.getAspectFlags();
ASSERT(aspectFlags != 0);
image.changeLayout(aspectFlags, vk::ImageLayout::FragmentShaderReadOnly,
srcLayoutChange);
}
image.addReadDependency(framebuffer);
......@@ -1092,8 +1092,8 @@ angle::Result ProgramVk::updateDescriptorSets(ContextVk *contextVk,
descSet = mEmptyDescriptorSets[descriptorSetIndex];
}
constexpr uint32_t kShaderTypeMin = static_cast<uint32_t>(gl::kGLES2ShaderTypeMin);
constexpr uint32_t kShaderTypeMax = static_cast<uint32_t>(gl::kGLES2ShaderTypeMax);
constexpr uint32_t kShaderTypeMin = static_cast<uint32_t>(gl::kGLES2ShaderTypeMin);
constexpr uint32_t kShaderTypeMax = static_cast<uint32_t>(gl::kGLES2ShaderTypeMax);
constexpr uint32_t kShaderTypeCount = kShaderTypeMax - kShaderTypeMin + 1;
// Default uniforms are encompassed in a block per shader stage, and they are assigned
......
......@@ -1320,6 +1320,11 @@ void RendererVk::initFeatures(const ExtensionNameList &deviceExtensionNames)
{
mFeatures.forceNonZeroScissor.enabled = true;
}
if (IsAndroid() && IsQualcomm(mPhysicalDeviceProperties.vendorID))
{
mFeatures.forceD16TexFilter.enabled = true;
}
}
void RendererVk::initPipelineCacheVkKey()
......@@ -2284,6 +2289,12 @@ VkFormatFeatureFlags RendererVk::getFormatFeatureBits(VkFormat format,
// Otherwise query the format features and cache it.
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;
......
......@@ -1340,7 +1340,7 @@ angle::Result TextureVk::getLayerLevelDrawImageView(vk::Context *context,
// Lazily allocate the image view itself.
// Note that these views are specifically made to be used as color attachments, and therefore
// 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),
1, getNativeImageLayer(layer), 1);
}
......@@ -1357,14 +1357,18 @@ angle::Result TextureVk::initImage(ContextVk *contextVk,
const uint32_t levelCount,
vk::CommandBuffer *commandBuffer)
{
const RendererVk *renderer = contextVk->getRenderer();
const angle::Format &textureFormat = format.imageFormat();
RendererVk *renderer = contextVk->getRenderer();
VkImageUsageFlags imageUsageFlags = VK_IMAGE_USAGE_TRANSFER_DST_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_SAMPLED_BIT;
if (!textureFormat.isBlock)
if (renderer->hasImageFormatFeatureBits(format.vkImageFormat,
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;
}
......@@ -1410,16 +1414,22 @@ angle::Result TextureVk::initImageViews(ContextVk *contextVk,
uint32_t baseLevel = getNativeImageLevel(0);
uint32_t baseLayer = getNativeImageLayer(0);
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,
mappedSwizzle, &mReadMipmapImageView, baseLevel,
levelCount, baseLayer, layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), VK_IMAGE_ASPECT_COLOR_BIT,
mappedSwizzle, &mReadBaseLevelImageView, baseLevel, 1,
baseLayer, layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
&mReadMipmapImageView, baseLevel, levelCount, baseLayer,
layerCount));
ANGLE_TRY(mImage->initLayerImageView(contextVk, mState.getType(), aspectFlags, mappedSwizzle,
&mReadBaseLevelImageView, baseLevel, 1, baseLayer,
layerCount));
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,
baseLevel, 1, baseLayer, layerCount));
}
......
......@@ -224,6 +224,10 @@
"buffer": "NONE",
"image": "D24_UNORM_S8_UINT"
},
"D32_UNORM": {
"buffer": "NONE",
"image": "D24_UNORM_S8_UINT"
},
"ETC1_R8G8B8_UNORM_BLOCK": {
"buffer": "NONE",
"image": "ETC2_R8G8B8_UNORM_BLOCK"
......
......@@ -695,7 +695,19 @@ void Format::initialize(RendererVk *renderer, const angle::Format &angleFormat)
break;
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;
case angle::FormatID::EAC_R11G11_SNORM_BLOCK:
......
......@@ -321,15 +321,28 @@ void MapSwizzleState(const vk::Format &format,
swizzleStateOut->swizzleAlpha = swizzleState.swizzleRed;
break;
default:
// Set any missing channel to default in case the emulated format has that channel.
swizzleStateOut->swizzleRed =
angleFormat.redBits > 0 ? swizzleState.swizzleRed : GL_ZERO;
swizzleStateOut->swizzleGreen =
angleFormat.greenBits > 0 ? swizzleState.swizzleGreen : GL_ZERO;
swizzleStateOut->swizzleBlue =
angleFormat.blueBits > 0 ? swizzleState.swizzleBlue : GL_ZERO;
swizzleStateOut->swizzleAlpha =
angleFormat.alphaBits > 0 ? swizzleState.swizzleAlpha : GL_ONE;
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.
swizzleStateOut->swizzleRed =
angleFormat.redBits > 0 ? swizzleState.swizzleRed : GL_ZERO;
swizzleStateOut->swizzleGreen =
angleFormat.greenBits > 0 ? swizzleState.swizzleGreen : GL_ZERO;
swizzleStateOut->swizzleBlue =
angleFormat.blueBits > 0 ? swizzleState.swizzleBlue : GL_ZERO;
swizzleStateOut->swizzleAlpha =
angleFormat.alphaBits > 0 ? swizzleState.swizzleAlpha : GL_ONE;
}
break;
}
}
......
......@@ -1683,6 +1683,10 @@ void ImageHelper::clearColor(const VkClearColorValue &color,
void ImageHelper::clearDepthStencil(VkImageAspectFlags imageAspectFlags,
VkImageAspectFlags clearAspectFlags,
const VkClearDepthStencilValue &depthStencil,
uint32_t baseMipLevel,
uint32_t levelCount,
uint32_t baseArrayLayer,
uint32_t layerCount,
vk::CommandBuffer *commandBuffer)
{
ASSERT(valid());
......@@ -1691,10 +1695,10 @@ void ImageHelper::clearDepthStencil(VkImageAspectFlags imageAspectFlags,
VkImageSubresourceRange clearRange = {
/*aspectMask*/ clearAspectFlags,
/*baseMipLevel*/ 0,
/*levelCount*/ 1,
/*baseArrayLayer*/ 0,
/*layerCount*/ 1,
/*baseMipLevel*/ baseMipLevel,
/*levelCount*/ levelCount,
/*baseArrayLayer*/ baseArrayLayer,
/*layerCount*/ layerCount,
};
commandBuffer->clearDepthStencilImage(mImage, getCurrentLayout(), depthStencil, 1, &clearRange);
......@@ -1711,9 +1715,9 @@ void ImageHelper::clear(const VkClearValue &value,
if (isDepthStencil)
{
ASSERT(mipLevel == 0 && baseArrayLayer == 0 && layerCount == 1);
const VkImageAspectFlags aspect = vk::GetDepthStencilAspectFlags(mFormat->imageFormat());
clearDepthStencil(aspect, aspect, value.depthStencil, commandBuffer);
clearDepthStencil(aspect, aspect, value.depthStencil, mipLevel, 1, baseArrayLayer,
layerCount, commandBuffer);
}
else
{
......@@ -1945,12 +1949,12 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
loadFunction.loadFunction(extents.width, extents.height, extents.depth, source, inputRowPitch,
inputDepthPitch, stagingPointer, outputRowPitch, outputDepthPitch);
VkBufferImageCopy copy = {};
VkBufferImageCopy copy = {};
VkImageAspectFlags aspectFlags = GetFormatAspectFlags(vkFormat.imageFormat());
copy.bufferOffset = stagingOffset;
copy.bufferRowLength = bufferRowLength;
copy.bufferImageHeight = bufferImageHeight;
copy.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
copy.imageSubresource.mipLevel = index.getLevelIndex();
copy.imageSubresource.baseArrayLayer = index.hasLayer() ? index.getLayerIndex() : 0;
copy.imageSubresource.layerCount = index.getLayerCount();
......@@ -1958,7 +1962,19 @@ angle::Result ImageHelper::stageSubresourceUpdate(ContextVk *contextVk,
gl_vk::GetOffset(offset, &copy.imageOffset);
gl_vk::GetExtent(extents, &copy.imageExtent);
mSubresourceUpdates.emplace_back(bufferHandle, copy);
// 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);
}
return angle::Result::Continue;
}
......@@ -1984,6 +2000,9 @@ angle::Result ImageHelper::stageSubresourceUpdateAndGetData(ContextVk *contextVk
copy.imageSubresource.baseArrayLayer = imageIndex.hasLayer() ? imageIndex.getLayerIndex() : 0;
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::GetExtent(extents, &copy.imageExtent);
......
......@@ -754,6 +754,10 @@ class ImageHelper final : public CommandGraphResource
void clearDepthStencil(VkImageAspectFlags imageAspectFlags,
VkImageAspectFlags clearAspectFlags,
const VkClearDepthStencilValue &depthStencil,
uint32_t baseMipLevel,
uint32_t levelCount,
uint32_t baseArrayLayer,
uint32_t layerCount,
vk::CommandBuffer *commandBuffer);
struct SubresourceUpdate
......
......@@ -730,9 +730,21 @@ bool ValidateES2CopyTexImageParameters(Context *context,
case GL_DEPTH_COMPONENT:
case GL_DEPTH_COMPONENT16:
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_DEPTH24_STENCIL8_OES:
if (context->getExtensions().depthTextureANGLE)
if (context->getExtensions().depthTextureAny() ||
context->getExtensions().packedDepthStencil)
{
context->validationError(GL_INVALID_OPERATION, kInvalidFormat);
return false;
......@@ -742,6 +754,7 @@ bool ValidateES2CopyTexImageParameters(Context *context,
context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false;
}
break;
default:
context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false;
......@@ -1497,7 +1510,9 @@ bool ValidateES2TexImageParameters(Context *context,
break;
case GL_DEPTH_COMPONENT:
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);
return false;
......@@ -1509,15 +1524,18 @@ bool ValidateES2TexImageParameters(Context *context,
}
// OES_depth_texture supports loading depth data and multiple levels,
// but ANGLE_depth_texture does not
if (pixels != nullptr)
if (!context->getExtensions().depthTextureOES)
{
context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
return false;
}
if (level != 0)
{
context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
return false;
if (pixels != nullptr)
{
context->validationError(GL_INVALID_OPERATION, kPixelDataNotNull);
return false;
}
if (level != 0)
{
context->validationError(GL_INVALID_OPERATION, kLevelNotZero);
return false;
}
}
break;
default:
......@@ -1587,8 +1605,16 @@ bool ValidateES2TexImageParameters(Context *context,
break;
case GL_DEPTH_COMPONENT:
if (!(context->getExtensions().depthTextureAny()))
{
context->validationError(GL_INVALID_ENUM, kInvalidFormat);
return false;
}
break;
case GL_DEPTH_STENCIL:
if (!context->getExtensions().depthTextureANGLE)
if (!(context->getExtensions().depthTextureANGLE ||
context->getExtensions().packedDepthStencil))
{
context->validationError(GL_INVALID_ENUM, kInvalidFormat);
return false;
......@@ -1883,8 +1909,7 @@ bool ValidateES2TexStorageParameters(Context *context,
break;
case GL_DEPTH_COMPONENT16:
case GL_DEPTH_COMPONENT32_OES:
case GL_DEPTH24_STENCIL8_OES:
if (!context->getExtensions().depthTextureANGLE)
if (!(context->getExtensions().depthTextureAny()))
{
context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false;
......@@ -1895,12 +1920,39 @@ bool ValidateES2TexStorageParameters(Context *context,
return false;
}
// ANGLE_depth_texture only supports 1-level textures
if (levels != 1)
if (!context->getExtensions().depthTextureOES)
{
if (levels != 1)
{
context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
return false;
}
}
break;
case GL_DEPTH24_STENCIL8_OES:
if (!(context->getExtensions().depthTextureANGLE ||
(context->getExtensions().packedDepthStencil &&
context->getExtensions().textureStorage)))
{
context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
context->validationError(GL_INVALID_ENUM, kEnumNotSupported);
return false;
}
if (target != TextureType::_2D)
{
context->validationError(GL_INVALID_OPERATION, kInvalidTextureTarget);
return false;
}
if (!context->getExtensions().packedDepthStencil)
{
// ANGLE_depth_texture only supports 1-level textures
if (levels != 1)
{
context->validationError(GL_INVALID_OPERATION, kInvalidMipLevels);
return false;
}
}
break;
default:
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