mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-19 09:55:26 +00:00
Implement rendering with view format reinterpretation
Includes fixes for the backends to create and use a texture view if reinterpretation is required. Multiple backends used the original texture and its format instead of the view. Bug: dawn:1276 Change-Id: Ic31231b2955314e90e011905c9048db6f7899299 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/84704 Reviewed-by: Loko Kung <lokokung@google.com> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
@@ -87,14 +87,16 @@ namespace dawn::native::opengl {
|
||||
return handle;
|
||||
}
|
||||
|
||||
bool UsageNeedsTextureView(wgpu::TextureUsage usage) {
|
||||
constexpr wgpu::TextureUsage kUsageNeedingTextureView =
|
||||
wgpu::TextureUsage::StorageBinding | wgpu::TextureUsage::TextureBinding;
|
||||
return usage & kUsageNeedingTextureView;
|
||||
}
|
||||
|
||||
bool RequiresCreatingNewTextureView(const TextureBase* texture,
|
||||
const TextureViewDescriptor* textureViewDescriptor) {
|
||||
constexpr wgpu::TextureUsage kShaderUsageNeedsView =
|
||||
wgpu::TextureUsage::StorageBinding | wgpu::TextureUsage::TextureBinding;
|
||||
constexpr wgpu::TextureUsage kUsageNeedsView =
|
||||
kShaderUsageNeedsView | wgpu::TextureUsage::RenderAttachment;
|
||||
if ((texture->GetInternalUsage() & kUsageNeedsView) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (texture->GetFormat().format != textureViewDescriptor->format &&
|
||||
!texture->GetFormat().HasDepthOrStencil()) {
|
||||
// Color format reinterpretation required. Note: Depth/stencil formats don't support
|
||||
@@ -102,6 +104,12 @@ namespace dawn::native::opengl {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reinterpretation not required. Now, we only need a new view if the view dimension or
|
||||
// set of subresources for the shader is different from the base texture.
|
||||
if ((texture->GetInternalUsage() & kShaderUsageNeedsView) == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (texture->GetArrayLayers() != textureViewDescriptor->arrayLayerCount ||
|
||||
(texture->GetArrayLayers() == 1 &&
|
||||
texture->GetDimension() == wgpu::TextureDimension::e2D &&
|
||||
@@ -554,9 +562,7 @@ namespace dawn::native::opengl {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UsageNeedsTextureView(texture->GetUsage())) {
|
||||
mHandle = 0;
|
||||
} else if (!RequiresCreatingNewTextureView(texture, descriptor)) {
|
||||
if (!RequiresCreatingNewTextureView(texture, descriptor)) {
|
||||
mHandle = ToBackend(texture)->GetHandle();
|
||||
} else {
|
||||
// glTextureView() is supported on OpenGL version >= 4.3
|
||||
@@ -601,13 +607,26 @@ namespace dawn::native::opengl {
|
||||
void TextureView::BindToFramebuffer(GLenum target, GLenum attachment) {
|
||||
const OpenGLFunctions& gl = ToBackend(GetDevice())->gl;
|
||||
|
||||
// Use the texture's handle and target, and the view's base mip level and base array layer
|
||||
GLuint handle = ToBackend(GetTexture())->GetHandle();
|
||||
GLuint textarget = ToBackend(GetTexture())->GetGLTarget();
|
||||
GLuint mipLevel = GetBaseMipLevel();
|
||||
GLuint handle, textarget, mipLevel, arrayLayer;
|
||||
if (mOwnsHandle) {
|
||||
// Use our own texture handle and target which points to a subset of the texture's
|
||||
// subresources.
|
||||
handle = GetHandle();
|
||||
textarget = GetGLTarget();
|
||||
mipLevel = 0;
|
||||
arrayLayer = 0;
|
||||
} else {
|
||||
// Use the texture's handle and target, with the view's base mip level and base array
|
||||
// layer.
|
||||
handle = ToBackend(GetTexture())->GetHandle();
|
||||
textarget = ToBackend(GetTexture())->GetGLTarget();
|
||||
mipLevel = GetBaseMipLevel();
|
||||
arrayLayer = GetBaseArrayLayer();
|
||||
}
|
||||
|
||||
ASSERT(handle != 0);
|
||||
if (textarget == GL_TEXTURE_2D_ARRAY || textarget == GL_TEXTURE_3D) {
|
||||
gl.FramebufferTextureLayer(target, attachment, handle, mipLevel, GetBaseArrayLayer());
|
||||
gl.FramebufferTextureLayer(target, attachment, handle, mipLevel, arrayLayer);
|
||||
} else {
|
||||
gl.FramebufferTexture2D(target, attachment, textarget, handle, mipLevel);
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ namespace dawn::native::opengl {
|
||||
~TextureView() override;
|
||||
void DestroyImpl() override;
|
||||
|
||||
// TODO(crbug.com/dawn/1355): Delete this handle on texture destroy.
|
||||
GLuint mHandle;
|
||||
GLenum mTarget;
|
||||
bool mOwnsHandle;
|
||||
|
||||
Reference in New Issue
Block a user