OpenGL: Fix rendering to a layer of a depth/stencil texture
Bug: dawn:430 Change-Id: Ifb6c72374707a05054cfef021840bc8305b4f9d7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22320 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
parent
09987b88f1
commit
f874525de3
|
@ -556,12 +556,13 @@ namespace dawn_native { namespace opengl {
|
||||||
auto& copySize = copy->copySize;
|
auto& copySize = copy->copySize;
|
||||||
Texture* texture = ToBackend(src.texture.Get());
|
Texture* texture = ToBackend(src.texture.Get());
|
||||||
Buffer* buffer = ToBackend(dst.buffer.Get());
|
Buffer* buffer = ToBackend(dst.buffer.Get());
|
||||||
const GLFormat& format = texture->GetGLFormat();
|
const Format& format = texture->GetFormat();
|
||||||
|
const GLFormat& glFormat = texture->GetGLFormat();
|
||||||
GLenum target = texture->GetGLTarget();
|
GLenum target = texture->GetGLTarget();
|
||||||
|
|
||||||
// TODO(jiawei.shao@intel.com): support texture-to-buffer copy with compressed
|
// TODO(jiawei.shao@intel.com): support texture-to-buffer copy with compressed
|
||||||
// texture formats.
|
// texture formats.
|
||||||
if (texture->GetFormat().isCompressed) {
|
if (format.isCompressed) {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,16 +575,35 @@ namespace dawn_native { namespace opengl {
|
||||||
GLuint readFBO = 0;
|
GLuint readFBO = 0;
|
||||||
gl.GenFramebuffers(1, &readFBO);
|
gl.GenFramebuffers(1, &readFBO);
|
||||||
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
|
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
|
||||||
|
|
||||||
|
GLenum glAttachment = 0;
|
||||||
|
switch (format.aspect) {
|
||||||
|
case Format::Aspect::Color:
|
||||||
|
glAttachment = GL_COLOR_ATTACHMENT0;
|
||||||
|
break;
|
||||||
|
case Format::Aspect::Depth:
|
||||||
|
glAttachment = GL_DEPTH_ATTACHMENT;
|
||||||
|
break;
|
||||||
|
case Format::Aspect::Stencil:
|
||||||
|
glAttachment = GL_STENCIL_ATTACHMENT;
|
||||||
|
break;
|
||||||
|
case Format::Aspect::DepthStencil:
|
||||||
|
glAttachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
switch (texture->GetDimension()) {
|
switch (texture->GetDimension()) {
|
||||||
case wgpu::TextureDimension::e2D:
|
case wgpu::TextureDimension::e2D:
|
||||||
if (texture->GetArrayLayers() > 1) {
|
if (texture->GetArrayLayers() > 1) {
|
||||||
gl.FramebufferTextureLayer(
|
gl.FramebufferTextureLayer(GL_READ_FRAMEBUFFER, glAttachment,
|
||||||
GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture->GetHandle(),
|
texture->GetHandle(), src.mipLevel,
|
||||||
src.mipLevel, src.arrayLayer);
|
src.arrayLayer);
|
||||||
} else {
|
} else {
|
||||||
gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, glAttachment, target,
|
||||||
GL_TEXTURE_2D, texture->GetHandle(),
|
texture->GetHandle(), src.mipLevel);
|
||||||
src.mipLevel);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -592,13 +612,12 @@ namespace dawn_native { namespace opengl {
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.BindBuffer(GL_PIXEL_PACK_BUFFER, buffer->GetHandle());
|
gl.BindBuffer(GL_PIXEL_PACK_BUFFER, buffer->GetHandle());
|
||||||
gl.PixelStorei(GL_PACK_ROW_LENGTH,
|
gl.PixelStorei(GL_PACK_ROW_LENGTH, dst.bytesPerRow / format.blockByteSize);
|
||||||
dst.bytesPerRow / texture->GetFormat().blockByteSize);
|
|
||||||
gl.PixelStorei(GL_PACK_IMAGE_HEIGHT, dst.rowsPerImage);
|
gl.PixelStorei(GL_PACK_IMAGE_HEIGHT, dst.rowsPerImage);
|
||||||
ASSERT(copySize.depth == 1 && src.origin.z == 0);
|
ASSERT(copySize.depth == 1 && src.origin.z == 0);
|
||||||
void* offset = reinterpret_cast<void*>(static_cast<uintptr_t>(dst.offset));
|
void* offset = reinterpret_cast<void*>(static_cast<uintptr_t>(dst.offset));
|
||||||
gl.ReadPixels(src.origin.x, src.origin.y, copySize.width, copySize.height,
|
gl.ReadPixels(src.origin.x, src.origin.y, copySize.width, copySize.height,
|
||||||
format.format, format.type, offset);
|
glFormat.format, glFormat.type, offset);
|
||||||
gl.PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
gl.PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||||
gl.PixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
|
gl.PixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
|
||||||
|
|
||||||
|
@ -790,8 +809,15 @@ namespace dawn_native { namespace opengl {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (textureView->GetTexture()->GetArrayLayers() == 1) {
|
||||||
GLenum target = ToBackend(textureView->GetTexture())->GetGLTarget();
|
GLenum target = ToBackend(textureView->GetTexture())->GetGLTarget();
|
||||||
gl.FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, glAttachment, target, texture, 0);
|
gl.FramebufferTexture2D(GL_DRAW_FRAMEBUFFER, glAttachment, target, texture,
|
||||||
|
textureView->GetBaseMipLevel());
|
||||||
|
} else {
|
||||||
|
gl.FramebufferTextureLayer(GL_DRAW_FRAMEBUFFER, glAttachment, texture,
|
||||||
|
textureView->GetBaseMipLevel(),
|
||||||
|
textureView->GetBaseArrayLayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,9 +155,9 @@ TEST_P(SubresourceOutputAttachmentTest, DISABLED_StencilTexture) {
|
||||||
DoTest(Type::Stencil);
|
DoTest(Type::Stencil);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(crbug.com/dawn/430): Not implemented on OpenGL
|
|
||||||
DAWN_INSTANTIATE_TEST(SubresourceOutputAttachmentTest,
|
DAWN_INSTANTIATE_TEST(SubresourceOutputAttachmentTest,
|
||||||
D3D12Backend(),
|
D3D12Backend(),
|
||||||
D3D12Backend({}, {"use_d3d12_render_pass"}),
|
D3D12Backend({}, {"use_d3d12_render_pass"}),
|
||||||
MetalBackend(),
|
MetalBackend(),
|
||||||
|
OpenGLBackend(),
|
||||||
VulkanBackend());
|
VulkanBackend());
|
||||||
|
|
Loading…
Reference in New Issue