Commit b436aac3 by Jamie Madill Committed by Commit Bot

Vulkan: Support inverted blit for depth/stencil.

Depth/stencil formats are packed tightly when reading back Images with vkCmdCopyImageToBuffer. Same for the reverse. Thus we need to take this into account when doing our blitWithReadback implementation. This splits the depth/stencil blit into two separate steps. Fixes all the remaining blit failures in BlitFramebufferANGLETest. Bug: angleproject:2673 Change-Id: Ie9f43f782a82b5a0746d00122b24f81088d57c4c Reviewed-on: https://chromium-review.googlesource.com/1140740 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 3003f048
......@@ -6,7 +6,7 @@
"ANGLE format:src/libANGLE/renderer/angle_format_map.json":
"ea6dfe3ebbc86e04f0d4b9f568ba22ae",
"ANGLE format:src/libANGLE/renderer/gen_angle_format_table.py":
"4b311db89dc5d3ed17c6e0f0e99260aa",
"9de29b6ca59a05747623c0dc32344b14",
"ANGLE load functions table:src/libANGLE/renderer/gen_load_functions_table.py":
"8afc7eecce2a3ba9f0b4beacb1aa7fe2",
"ANGLE load functions table:src/libANGLE/renderer/load_functions_data.json":
......
......@@ -9,6 +9,8 @@
#ifndef COMMON_COLOR_H_
#define COMMON_COLOR_H_
#include <cstdint>
namespace angle
{
......@@ -46,6 +48,14 @@ typedef Color<float> ColorF;
typedef Color<int> ColorI;
typedef Color<unsigned int> ColorUI;
struct DepthStencil
{
DepthStencil() : depth(0), stencil(0) {}
// Double is needed to represent the 32-bit integer range of GL_DEPTH_COMPONENT32.
double depth;
uint32_t stencil;
};
} // namespace angle
// TODO: Move this fully into the angle namespace
......
......@@ -24,8 +24,11 @@ void ReadColor(const uint8_t *source, uint8_t *dest);
template <typename destType, typename colorDataType>
void WriteColor(const uint8_t *source, uint8_t *dest);
template <typename sourceType, typename destType, typename colorDataType>
void CopyPixel(const uint8_t *source, uint8_t *dest);
template <typename SourceType>
void ReadDepthStencil(const uint8_t *source, uint8_t *dest);
template <typename DestType>
void WriteDepthStencil(const uint8_t *source, uint8_t *dest);
void CopyBGRA8ToRGBA8(const uint8_t *source, uint8_t *dest);
......
......@@ -8,27 +8,31 @@
namespace angle
{
template <typename sourceType, typename colorDataType>
inline void ReadColor(const uint8_t *source, uint8_t *dest)
void ReadColor(const uint8_t *source, uint8_t *dest)
{
sourceType::readColor(reinterpret_cast<Color<colorDataType>*>(dest),
reinterpret_cast<const sourceType*>(source));
}
template <typename destType, typename colorDataType>
inline void WriteColor(const uint8_t *source, uint8_t *dest)
void WriteColor(const uint8_t *source, uint8_t *dest)
{
destType::writeColor(reinterpret_cast<destType*>(dest),
reinterpret_cast<const Color<colorDataType>*>(source));
}
template <typename sourceType, typename destType, typename colorDataType>
inline void CopyPixel(const uint8_t *source, uint8_t *dest)
template <typename SourceType>
void ReadDepthStencil(const uint8_t *source, uint8_t *dest)
{
colorDataType temp;
ReadColor<sourceType, colorDataType>(source, &temp);
WriteColor<destType, colorDataType>(&temp, dest);
SourceType::ReadDepthStencil(reinterpret_cast<DepthStencil *>(dest),
reinterpret_cast<const SourceType *>(source));
}
template <typename DestType>
void WriteDepthStencil(const uint8_t *source, uint8_t *dest)
{
DestType::WriteDepthStencil(reinterpret_cast<DestType *>(dest),
reinterpret_cast<const DepthStencil *>(source));
}
} // namespace angle
......@@ -1759,4 +1759,77 @@ void R11G11B10F::average(R11G11B10F *dst, const R11G11B10F *src1, const R11G11B1
dst->B = gl::averageFloat10(src1->B, src2->B);
}
void D24S8::ReadDepthStencil(DepthStencil *dst, const D24S8 *src)
{
dst->depth = gl::normalizedToFloat<24>(src->D);
dst->stencil = gl::getShiftedData<8, 24>(src->S);
}
void D24S8::WriteDepthStencil(D24S8 *dst, const DepthStencil *src)
{
dst->D = gl::floatToNormalized<24, uint32_t>(static_cast<float>(src->depth));
dst->S = src->stencil & 0xFF;
}
void S8::ReadDepthStencil(DepthStencil *dst, const S8 *src)
{
UNIMPLEMENTED();
}
void S8::WriteDepthStencil(S8 *dst, const DepthStencil *src)
{
UNIMPLEMENTED();
}
void D16::ReadDepthStencil(DepthStencil *dst, const D16 *src)
{
UNIMPLEMENTED();
}
void D16::WriteDepthStencil(D16 *dst, const DepthStencil *src)
{
UNIMPLEMENTED();
}
void D24::ReadDepthStencil(DepthStencil *dst, const D24 *src)
{
dst->depth = gl::normalizedToFloat<24>(src->D);
}
void D24::WriteDepthStencil(D24 *dst, const DepthStencil *src)
{
UNIMPLEMENTED();
}
void D32F::ReadDepthStencil(DepthStencil *dst, const D32F *src)
{
dst->depth = src->D;
}
void D32F::WriteDepthStencil(D32F *dst, const DepthStencil *src)
{
UNIMPLEMENTED();
}
void D32::ReadDepthStencil(DepthStencil *dst, const D32 *src)
{
UNIMPLEMENTED();
}
void D32::WriteDepthStencil(D32 *dst, const DepthStencil *src)
{
UNIMPLEMENTED();
}
void D32FS8::ReadDepthStencil(DepthStencil *dst, const D32FS8 *src)
{
dst->depth = src->D;
dst->stencil = gl::getShiftedData<8, 24>(static_cast<uint32_t>(src->S));
}
void D32FS8::WriteDepthStencil(D32FS8 *dst, const DepthStencil *src)
{
dst->D = static_cast<float>(src->depth);
dst->S = src->stencil & 0xFF;
}
} // namespace angle
......@@ -710,6 +710,63 @@ struct R11G11B10F
};
static_assert(sizeof(R11G11B10F) == 4, "R11G11B10F struct not 32-bits.");
struct D24S8
{
uint32_t D : 24;
uint32_t S : 8;
static void ReadDepthStencil(DepthStencil *dst, const D24S8 *src);
static void WriteDepthStencil(D24S8 *dst, const DepthStencil *src);
};
struct S8
{
uint8_t S;
static void ReadDepthStencil(DepthStencil *dst, const S8 *src);
static void WriteDepthStencil(S8 *dst, const DepthStencil *src);
};
struct D16
{
uint16_t D;
static void ReadDepthStencil(DepthStencil *dst, const D16 *src);
static void WriteDepthStencil(D16 *dst, const DepthStencil *src);
};
struct D24
{
uint32_t D;
static void ReadDepthStencil(DepthStencil *dst, const D24 *src);
static void WriteDepthStencil(D24 *dst, const DepthStencil *src);
};
struct D32F
{
float D;
static void ReadDepthStencil(DepthStencil *dst, const D32F *src);
static void WriteDepthStencil(D32F *dst, const DepthStencil *src);
};
struct D32
{
uint32_t D;
static void ReadDepthStencil(DepthStencil *dst, const D32 *src);
static void WriteDepthStencil(D32 *dst, const DepthStencil *src);
};
struct D32FS8
{
float D;
uint32_t S;
static void ReadDepthStencil(DepthStencil *dst, const D32FS8 *src);
static void WriteDepthStencil(D32FS8 *dst, const DepthStencil *src);
};
} // namespace angle
#endif // IMAGEUTIL_IMAGEFORMATS_H_
......@@ -73,12 +73,12 @@ constexpr Format g_formatInfoTable[] = {
{ FormatID::BC2_RGBA_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, true },
{ FormatID::BC3_RGBA_UNORM_BLOCK, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, true },
{ FormatID::BC3_RGBA_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, true },
{ FormatID::D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 16, 0, 2, false },
{ FormatID::D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 24, 8, 4, false },
{ FormatID::D24_UNORM_X8_UINT, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT24, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 24, 0, 4, false },
{ FormatID::D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, nullptr, NoCopyFunctions, nullptr, nullptr, GL_FLOAT, 0, 0, 0, 0, 32, 0, 4, false },
{ FormatID::D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, nullptr, NoCopyFunctions, nullptr, nullptr, GL_FLOAT, 0, 0, 0, 0, 32, 8, 8, false },
{ FormatID::D32_UNORM, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT32_OES, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 32, 0, 4, false },
{ FormatID::D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, nullptr, NoCopyFunctions, ReadDepthStencil<D16>, WriteDepthStencil<D16>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 16, 0, 2, false },
{ FormatID::D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, nullptr, NoCopyFunctions, ReadDepthStencil<D24S8>, WriteDepthStencil<D24S8>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 24, 8, 4, false },
{ FormatID::D24_UNORM_X8_UINT, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT24, nullptr, NoCopyFunctions, ReadDepthStencil<D24>, WriteDepthStencil<D24>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 24, 0, 4, false },
{ FormatID::D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, nullptr, NoCopyFunctions, ReadDepthStencil<D32F>, WriteDepthStencil<D32F>, GL_FLOAT, 0, 0, 0, 0, 32, 0, 4, false },
{ FormatID::D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, nullptr, NoCopyFunctions, ReadDepthStencil<D32FS8>, WriteDepthStencil<D32FS8>, GL_FLOAT, 0, 0, 0, 0, 32, 8, 8, false },
{ FormatID::D32_UNORM, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT32_OES, nullptr, NoCopyFunctions, ReadDepthStencil<D32>, WriteDepthStencil<D32>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 32, 0, 4, false },
{ FormatID::EAC_R11G11_SNORM_BLOCK, GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, nullptr, NoCopyFunctions, nullptr, nullptr, GL_SIGNED_NORMALIZED, 11, 11, 0, 0, 0, 0, 2, true },
{ FormatID::EAC_R11G11_UNORM_BLOCK, GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 11, 11, 0, 0, 0, 0, 2, true },
{ FormatID::EAC_R11_SNORM_BLOCK, GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, nullptr, NoCopyFunctions, nullptr, nullptr, GL_SIGNED_NORMALIZED, 11, 0, 0, 0, 0, 0, 1, true },
......@@ -196,7 +196,7 @@ constexpr Format g_formatInfoTable[] = {
{ FormatID::R8_UNORM, GL_R8, GL_R8, GenerateMip<R8>, NoCopyFunctions, ReadColor<R8, GLfloat>, WriteColor<R8, GLfloat>, GL_UNSIGNED_NORMALIZED, 8, 0, 0, 0, 0, 0, 1, false },
{ FormatID::R8_USCALED, GL_R8_USCALED_ANGLEX, GL_R8_USCALED_ANGLEX, GenerateMip<R8>, NoCopyFunctions, ReadColor<R8, GLuint>, WriteColor<R8, GLuint>, GL_UNSIGNED_INT, 8, 0, 0, 0, 0, 0, 1, false },
{ FormatID::R9G9B9E5_SHAREDEXP, GL_RGB9_E5, GL_RGB9_E5, GenerateMip<R9G9B9E5>, NoCopyFunctions, ReadColor<R9G9B9E5, GLfloat>, WriteColor<R9G9B9E5, GLfloat>, GL_FLOAT, 9, 9, 9, 0, 0, 0, 3, false },
{ FormatID::S8_UINT, GL_STENCIL_INDEX8, GL_STENCIL_INDEX8, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_INT, 0, 0, 0, 0, 0, 8, 1, false },
{ FormatID::S8_UINT, GL_STENCIL_INDEX8, GL_STENCIL_INDEX8, nullptr, NoCopyFunctions, ReadDepthStencil<S8>, WriteDepthStencil<S8>, GL_UNSIGNED_INT, 0, 0, 0, 0, 0, 8, 1, false },
// clang-format on
};
......
......@@ -85,19 +85,31 @@ const Format &Format::Get(FormatID id)
}} // namespace angle
"""
def is_depth_stencil(angle_format):
if not 'channels' in angle_format or not angle_format['channels']:
return False
return 'd' in angle_format['channels'] or 's' in angle_format['channels']
def get_component_suffix(angle_format):
if angle_format['componentType'] == 'float':
return 'F'
if angle_format['componentType'] == 'int' or angle_format['componentType'] == 'snorm':
return 'S'
return ""
def get_channel_struct(angle_format):
if 'bits' not in angle_format or angle_format['bits'] is None:
return None
if 'BLOCK' in angle_format['id']:
return None
bits = angle_format['bits']
if 'D' in bits or 'S' in bits:
return None
if 'channelStruct' in angle_format:
return angle_format['channelStruct']
struct_name = ''
component_suffix = get_component_suffix(angle_format)
for channel in angle_format['channels']:
if channel == 'r':
struct_name += 'R{}'.format(bits['R'])
......@@ -109,15 +121,19 @@ def get_channel_struct(angle_format):
struct_name += 'A{}'.format(bits['A'])
if channel == 'l':
struct_name += 'L{}'.format(bits['L'])
if angle_format['componentType'] == 'float':
struct_name += 'F'
if angle_format['componentType'] == 'int' or angle_format['componentType'] == 'snorm':
struct_name += 'S'
if channel == 'd':
struct_name += 'D{}'.format(bits['D']) + component_suffix
if channel == 's':
struct_name += 'S{}'.format(bits['S'])
if not is_depth_stencil(angle_format):
struct_name += component_suffix
return struct_name
def get_mip_generation_function(angle_format):
channel_struct = get_channel_struct(angle_format)
if channel_struct == None or "BLOCK" in angle_format["id"]:
if is_depth_stencil(angle_format) or channel_struct == None or "BLOCK" in angle_format["id"]:
return 'nullptr'
return 'GenerateMip<' + channel_struct + '>'
......@@ -135,6 +151,10 @@ def get_color_read_function(angle_format):
channel_struct = get_channel_struct(angle_format)
if channel_struct == None:
return 'nullptr'
if is_depth_stencil(angle_format):
return 'ReadDepthStencil<' + channel_struct + '>'
read_component_type = get_color_read_write_component_type(angle_format)
return 'ReadColor<' + channel_struct + ', '+ read_component_type + '>'
......@@ -142,6 +162,10 @@ def get_color_write_function(angle_format):
channel_struct = get_channel_struct(angle_format)
if channel_struct == None:
return 'nullptr'
if is_depth_stencil(angle_format):
return 'WriteDepthStencil<' + channel_struct + '>'
write_component_type = get_color_read_write_component_type(angle_format)
return 'WriteColor<' + channel_struct + ', '+ write_component_type + '>'
......
......@@ -236,8 +236,9 @@ void PackPixels(const PackPixelsParams &params,
// Maximum size of any Color<T> type used.
uint8_t temp[16];
static_assert(sizeof(temp) >= sizeof(gl::ColorF) && sizeof(temp) >= sizeof(gl::ColorUI) &&
sizeof(temp) >= sizeof(gl::ColorI),
"Unexpected size of gl::Color struct.");
sizeof(temp) >= sizeof(gl::ColorI) &&
sizeof(temp) >= sizeof(angle::DepthStencil),
"Unexpected size of pixel struct.");
ColorReadFunction colorReadFunction = sourceFormat.colorReadFunction;
ASSERT(colorReadFunction != nullptr);
......
......@@ -98,7 +98,7 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource
angle::Result readPixelsImpl(ContextVk *contextVk,
const gl::Rectangle &area,
const PackPixelsParams &packPixelsParams,
const VkImageAspectFlags &copyAspectFlags,
VkImageAspectFlagBits copyAspectFlags,
RenderTargetVk *renderTarget,
void *pixels);
......@@ -135,8 +135,7 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource
angle::Result blitWithReadback(ContextVk *contextVk,
const gl::Rectangle &copyArea,
bool blitDepthBuffer,
bool blitStencilBuffer,
VkImageAspectFlagBits aspect,
vk::CommandBuffer *commandBuffer,
RenderTargetVk *readRenderTarget,
RenderTargetVk *drawRenderTarget);
......
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