mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-03 03:35:59 +00:00
Support depth-only/stencil-only COPY_SRC on OpenGL
Bug: dawn:439 Change-Id: I09d33d3115d54c03e3ba5a32f34843065edb8020 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24961 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Stephen White <senorblanco@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
caec4ab04a
commit
b54c82ed39
@ -445,7 +445,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
: CommandBufferBase(encoder, descriptor) {
|
: CommandBufferBase(encoder, descriptor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandBuffer::Execute() {
|
MaybeError CommandBuffer::Execute() {
|
||||||
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
|
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
|
||||||
|
|
||||||
auto TransitionForPass = [](const PassResourceUsage& usages) {
|
auto TransitionForPass = [](const PassResourceUsage& usages) {
|
||||||
@ -518,6 +518,12 @@ namespace dawn_native { namespace opengl {
|
|||||||
GLenum target = texture->GetGLTarget();
|
GLenum target = texture->GetGLTarget();
|
||||||
const GLFormat& format = texture->GetGLFormat();
|
const GLFormat& format = texture->GetGLFormat();
|
||||||
|
|
||||||
|
if (dst.aspect == Aspect::Stencil) {
|
||||||
|
return DAWN_VALIDATION_ERROR(
|
||||||
|
"Copies to stencil textures unsupported on OpenGL");
|
||||||
|
}
|
||||||
|
ASSERT(dst.aspect == Aspect::Color);
|
||||||
|
|
||||||
buffer->EnsureDataInitialized();
|
buffer->EnsureDataInitialized();
|
||||||
|
|
||||||
ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D);
|
ASSERT(texture->GetDimension() == wgpu::TextureDimension::e2D);
|
||||||
@ -601,13 +607,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 Format& format = texture->GetFormat();
|
const Format& formatInfo = texture->GetFormat();
|
||||||
const GLFormat& glFormat = texture->GetGLFormat();
|
const GLFormat& format = 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 (format.isCompressed) {
|
if (formatInfo.isCompressed) {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,22 +631,35 @@ namespace dawn_native { namespace opengl {
|
|||||||
gl.GenFramebuffers(1, &readFBO);
|
gl.GenFramebuffers(1, &readFBO);
|
||||||
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
|
gl.BindFramebuffer(GL_READ_FRAMEBUFFER, readFBO);
|
||||||
|
|
||||||
GLenum glAttachment = 0;
|
const TexelBlockInfo& blockInfo = formatInfo.GetTexelBlockInfo(src.aspect);
|
||||||
if (format.aspects == (Aspect::Depth | Aspect::Stencil)) {
|
|
||||||
glAttachment = GL_DEPTH_STENCIL_ATTACHMENT;
|
|
||||||
} else if (format.aspects == Aspect::Depth) {
|
|
||||||
glAttachment = GL_DEPTH_ATTACHMENT;
|
|
||||||
} else if (format.aspects == Aspect::Stencil) {
|
|
||||||
glAttachment = GL_STENCIL_ATTACHMENT;
|
|
||||||
} else if (format.aspects == Aspect::Color) {
|
|
||||||
glAttachment = GL_COLOR_ATTACHMENT0;
|
|
||||||
} else {
|
|
||||||
UNREACHABLE();
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.BindBuffer(GL_PIXEL_PACK_BUFFER, buffer->GetHandle());
|
gl.BindBuffer(GL_PIXEL_PACK_BUFFER, buffer->GetHandle());
|
||||||
gl.PixelStorei(GL_PACK_ROW_LENGTH, dst.bytesPerRow / format.blockByteSize);
|
|
||||||
gl.PixelStorei(GL_PACK_IMAGE_HEIGHT, dst.rowsPerImage);
|
gl.PixelStorei(GL_PACK_IMAGE_HEIGHT, dst.rowsPerImage);
|
||||||
|
gl.PixelStorei(GL_PACK_ROW_LENGTH, dst.bytesPerRow / blockInfo.blockByteSize);
|
||||||
|
|
||||||
|
GLenum glAttachment;
|
||||||
|
GLenum glFormat;
|
||||||
|
GLenum glType;
|
||||||
|
switch (src.aspect) {
|
||||||
|
case Aspect::Color:
|
||||||
|
glAttachment = GL_COLOR_ATTACHMENT0;
|
||||||
|
glFormat = format.format;
|
||||||
|
glType = format.type;
|
||||||
|
break;
|
||||||
|
case Aspect::Depth:
|
||||||
|
glAttachment = GL_DEPTH_ATTACHMENT;
|
||||||
|
glFormat = GL_DEPTH_COMPONENT;
|
||||||
|
glType = GL_FLOAT;
|
||||||
|
break;
|
||||||
|
case Aspect::Stencil:
|
||||||
|
glAttachment = GL_STENCIL_ATTACHMENT;
|
||||||
|
glFormat = GL_STENCIL_INDEX;
|
||||||
|
glType = GL_UNSIGNED_BYTE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
UNREACHABLE();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t* offset =
|
uint8_t* offset =
|
||||||
reinterpret_cast<uint8_t*>(static_cast<uintptr_t>(dst.offset));
|
reinterpret_cast<uint8_t*>(static_cast<uintptr_t>(dst.offset));
|
||||||
@ -650,8 +669,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, glAttachment, target,
|
gl.FramebufferTexture2D(GL_READ_FRAMEBUFFER, glAttachment, target,
|
||||||
texture->GetHandle(), src.mipLevel);
|
texture->GetHandle(), src.mipLevel);
|
||||||
gl.ReadPixels(src.origin.x, src.origin.y, copySize.width,
|
gl.ReadPixels(src.origin.x, src.origin.y, copySize.width,
|
||||||
copySize.height, glFormat.format, glFormat.type,
|
copySize.height, glFormat, glType, offset);
|
||||||
offset);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,8 +679,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
texture->GetHandle(), src.mipLevel,
|
texture->GetHandle(), src.mipLevel,
|
||||||
src.origin.z + layer);
|
src.origin.z + layer);
|
||||||
gl.ReadPixels(src.origin.x, src.origin.y, copySize.width,
|
gl.ReadPixels(src.origin.x, src.origin.y, copySize.width,
|
||||||
copySize.height, glFormat.format, glFormat.type,
|
copySize.height, glFormat, glType, offset);
|
||||||
offset);
|
|
||||||
|
|
||||||
offset += bytesPerImage;
|
offset += bytesPerImage;
|
||||||
}
|
}
|
||||||
@ -731,6 +748,8 @@ namespace dawn_native { namespace opengl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandBuffer::ExecuteComputePass() {
|
void CommandBuffer::ExecuteComputePass() {
|
||||||
|
@ -29,7 +29,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
public:
|
public:
|
||||||
CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor);
|
CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor);
|
||||||
|
|
||||||
void Execute();
|
MaybeError Execute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ExecuteComputePass();
|
void ExecuteComputePass();
|
||||||
|
@ -30,7 +30,7 @@ namespace dawn_native { namespace opengl {
|
|||||||
|
|
||||||
TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute");
|
TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute");
|
||||||
for (uint32_t i = 0; i < commandCount; ++i) {
|
for (uint32_t i = 0; i < commandCount; ++i) {
|
||||||
ToBackend(commands[i])->Execute();
|
DAWN_TRY(ToBackend(commands[i])->Execute());
|
||||||
}
|
}
|
||||||
TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute");
|
TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, "CommandBufferGL::Execute");
|
||||||
|
|
||||||
|
@ -153,6 +153,9 @@ TEST_P(DepthStencilCopyTests, FromStencilAspect) {
|
|||||||
|
|
||||||
// Test copying to the stencil-aspect of a buffer
|
// Test copying to the stencil-aspect of a buffer
|
||||||
TEST_P(DepthStencilCopyTests, ToStencilAspect) {
|
TEST_P(DepthStencilCopyTests, ToStencilAspect) {
|
||||||
|
// Copies to a single aspect are unsupported on OpenGL.
|
||||||
|
DAWN_SKIP_TEST_IF(IsOpenGL());
|
||||||
|
|
||||||
// TODO(enga): Figure out why this fails on Vulkan Intel
|
// TODO(enga): Figure out why this fails on Vulkan Intel
|
||||||
// Results are shifted by 1 byte on Windows, and crash/hang on Linux.
|
// Results are shifted by 1 byte on Windows, and crash/hang on Linux.
|
||||||
DAWN_SKIP_TEST_IF(IsVulkan() && IsIntel());
|
DAWN_SKIP_TEST_IF(IsVulkan() && IsIntel());
|
||||||
@ -320,4 +323,8 @@ TEST_P(DepthStencilCopyTests, ToStencilAspect) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DAWN_INSTANTIATE_TEST(DepthStencilCopyTests, D3D12Backend(), MetalBackend(), VulkanBackend());
|
DAWN_INSTANTIATE_TEST(DepthStencilCopyTests,
|
||||||
|
D3D12Backend(),
|
||||||
|
MetalBackend(),
|
||||||
|
OpenGLBackend(),
|
||||||
|
VulkanBackend());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user