mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 14:18:31 +09:00
[Feat] (DirectVulkan): depth-stencil GetTexImage
The depth-stencil ReadPixels core (per-aspect copies + CPU repack) is now shared, and glGetTexImage serves GL_DEPTH_COMPONENT / GL_DEPTH_STENCIL / GL_STENCIL_INDEX queries of depth textures with it instead of rejecting every non-color aspect (packed_depth_stencil.verify_get_tex_image.* now passes).
This commit is contained in:
@@ -7024,6 +7024,18 @@ void main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReadDepthStencilImageToClient(image, vkFormat, trackedLayout, imageAspect, mipLevel, baseArrayLayer, x, y,
|
||||||
|
width, height, format, type, pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VulkanRenderer::ReadDepthStencilImageToClient(VkImage image, VkFormat vkFormat, VkImageLayout* trackedLayout,
|
||||||
|
VkImageAspectFlags imageAspect, Uint32 mipLevel,
|
||||||
|
Uint32 baseArrayLayer, GLint x, GLint y, GLsizei width,
|
||||||
|
GLsizei height, GLenum format, GLenum type, void* pixels) {
|
||||||
|
const Bool wantDepth = format != GL_STENCIL_INDEX;
|
||||||
|
const Bool wantStencil = format != GL_DEPTH_COMPONENT;
|
||||||
|
auto& frame = m_frameContext.GetCurrent();
|
||||||
|
|
||||||
if (*trackedLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
|
if (*trackedLayout == VK_IMAGE_LAYOUT_UNDEFINED) {
|
||||||
MGLOG_E("DirectVulkan::ReadDepthStencilPixels skipped: source layout is undefined");
|
MGLOG_E("DirectVulkan::ReadDepthStencilPixels skipped: source layout is undefined");
|
||||||
return;
|
return;
|
||||||
@@ -7272,10 +7284,6 @@ void main() {
|
|||||||
textureObject->GetExternalIndex());
|
textureObject->GetExternalIndex());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((resource->aspect & VK_IMAGE_ASPECT_COLOR_BIT) == 0) {
|
|
||||||
MGLOG_E("DirectVulkan::GetTexImage skipped: only color textures are supported right now");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& frame = m_frameContext.GetCurrent();
|
auto& frame = m_frameContext.GetCurrent();
|
||||||
if (!frame.isCommandRecording) {
|
if (!frame.isCommandRecording) {
|
||||||
@@ -7289,6 +7297,25 @@ void main() {
|
|||||||
"GetTexImage: failed to materialize pending clear for textureId=%d",
|
"GetTexImage: failed to materialize pending clear for textureId=%d",
|
||||||
textureObject->GetExternalIndex());
|
textureObject->GetExternalIndex());
|
||||||
|
|
||||||
|
if ((resource->aspect & VK_IMAGE_ASPECT_COLOR_BIT) == 0) {
|
||||||
|
if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL || format == GL_STENCIL_INDEX) {
|
||||||
|
const auto levelSize =
|
||||||
|
textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, static_cast<Uint>(level));
|
||||||
|
const Bool isCubeFace = textureUploadTarget >= TextureUploadTarget::CubeMapPositiveX &&
|
||||||
|
textureUploadTarget <= TextureUploadTarget::CubeMapNegativeZ;
|
||||||
|
const Uint32 arrayLayer = isCubeFace
|
||||||
|
? static_cast<Uint32>(textureUploadTarget) -
|
||||||
|
static_cast<Uint32>(TextureUploadTarget::CubeMapPositiveX)
|
||||||
|
: 0;
|
||||||
|
ReadDepthStencilImageToClient(resource->image, resource->format, &resource->layout, resource->aspect,
|
||||||
|
static_cast<Uint32>(level), arrayLayer, 0, 0, levelSize.x(),
|
||||||
|
levelSize.y(), format, type, pixels);
|
||||||
|
} else {
|
||||||
|
MGLOG_E("DirectVulkan::GetTexImage skipped: color query of a non-color texture");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const auto texelSize = textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, static_cast<Uint>(level));
|
const auto texelSize = textureMipmapObject->GetMipmapTexelSize(textureUploadTarget, static_cast<Uint>(level));
|
||||||
const GLsizei width = texelSize.x();
|
const GLsizei width = texelSize.x();
|
||||||
const GLsizei height = texelSize.y();
|
const GLsizei height = texelSize.y();
|
||||||
|
|||||||
@@ -205,6 +205,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
// CPU repacking into the requested client layout).
|
// CPU repacking into the requested client layout).
|
||||||
void ReadDepthStencilPixels(MG_State::GLState::FramebufferObject& readFbo, GLint x, GLint y, GLsizei width,
|
void ReadDepthStencilPixels(MG_State::GLState::FramebufferObject& readFbo, GLint x, GLint y, GLsizei width,
|
||||||
GLsizei height, GLenum format, GLenum type, void* pixels);
|
GLsizei height, GLenum format, GLenum type, void* pixels);
|
||||||
|
// Copy-and-repack core shared by depth-stencil ReadPixels and GetTexImage;
|
||||||
|
// expects command recording to be active and any render pass already ended.
|
||||||
|
void ReadDepthStencilImageToClient(VkImage image, VkFormat vkFormat, VkImageLayout* trackedLayout,
|
||||||
|
VkImageAspectFlags imageAspect, Uint32 mipLevel, Uint32 baseArrayLayer,
|
||||||
|
GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
|
||||||
|
void* pixels);
|
||||||
static SizeT GetReadbackTexelSize(VkFormat sourceFormat);
|
static SizeT GetReadbackTexelSize(VkFormat sourceFormat);
|
||||||
static Bool ConvertReadbackPixels(const Uint8* sourcePixels, VkFormat sourceFormat,
|
static Bool ConvertReadbackPixels(const Uint8* sourcePixels, VkFormat sourceFormat,
|
||||||
GLsizei width, GLsizei height, GLenum destinationFormat,
|
GLsizei width, GLsizei height, GLenum destinationFormat,
|
||||||
|
|||||||
Reference in New Issue
Block a user