Hash :
2dd13ebb
Author :
Date :
2022-04-21T11:25:00
Track Surface color & depth/stencil init separately. This clears up some trace testing confusion due when robust resource init is enabled, and the app clears color but not depth on the default surface. Bug: angleproject:7221 Change-Id: Id97871aec32ad831b663aaa9116e04b582ab5a36 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3600375 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// RenderBufferMtl.mm:
// Implements the class methods for RenderBufferMtl.
//
#include "libANGLE/renderer/metal/RenderBufferMtl.h"
#include "libANGLE/renderer/metal/ContextMtl.h"
#include "libANGLE/renderer/metal/ImageMtl.h"
#include "libANGLE/renderer/metal/mtl_format_utils.h"
#include "libANGLE/renderer/metal/mtl_utils.h"
namespace rx
{
RenderbufferMtl::RenderbufferMtl(const gl::RenderbufferState &state) : RenderbufferImpl(state) {}
RenderbufferMtl::~RenderbufferMtl() {}
void RenderbufferMtl::onDestroy(const gl::Context *context)
{
releaseTexture();
}
void RenderbufferMtl::releaseTexture()
{
mTexture = nullptr;
mImplicitMSTexture = nullptr;
}
angle::Result RenderbufferMtl::setStorageImpl(const gl::Context *context,
GLsizei samples,
GLenum internalformat,
GLsizei width,
GLsizei height)
{
ContextMtl *contextMtl = mtl::GetImpl(context);
if (mTexture != nullptr && mTexture->valid())
{
// Check against the state if we need to recreate the storage.
if (internalformat != mState.getFormat().info->internalFormat ||
width != mState.getWidth() || height != mState.getHeight() ||
samples != mState.getSamples())
{
releaseTexture();
}
}
const gl::InternalFormat &internalFormat = gl::GetSizedInternalFormatInfo(internalformat);
angle::FormatID angleFormatId =
angle::Format::InternalFormatToID(internalFormat.sizedInternalFormat);
mFormat = contextMtl->getPixelFormat(angleFormatId);
uint32_t actualSamples;
if (samples == 0)
{
actualSamples = 1;
}
else
{
// We always start at at least 2 samples
actualSamples = static_cast<uint32_t>(std::max<size_t>(2, samples));
const gl::TextureCaps &textureCaps =
contextMtl->getTextureCaps().get(mFormat.intendedFormatId);
actualSamples = textureCaps.getNearestSamples(actualSamples);
ANGLE_MTL_CHECK(contextMtl, actualSamples != 0, GL_INVALID_VALUE);
}
if ((mTexture == nullptr || !mTexture->valid()) && (width != 0 && height != 0))
{
if (actualSamples == 1 || (mFormat.getCaps().resolve))
{
ANGLE_TRY(mtl::Texture::Make2DTexture(
contextMtl, mFormat, static_cast<uint32_t>(width), static_cast<uint32_t>(height), 1,
/* renderTargetOnly */ false,
/* allowFormatView */ mFormat.hasDepthAndStencilBits(), &mTexture));
// Use implicit resolve for depth stencil texture whenever possible. This is because
// for depth stencil texture, if stencil needs to be blitted, a formatted clone has
// to be created. And it is expensive to clone a multisample texture.
if (actualSamples > 1)
{
// This format must supports implicit resolve
ASSERT(mFormat.getCaps().resolve);
ANGLE_TRY(mtl::Texture::Make2DMSTexture(
contextMtl, mFormat, static_cast<uint32_t>(width),
static_cast<uint32_t>(height), actualSamples,
/* renderTargetOnly */ true,
/* allowFormatView */ mFormat.hasDepthAndStencilBits(), &mImplicitMSTexture));
}
}
else
{
ANGLE_TRY(mtl::Texture::Make2DMSTexture(
contextMtl, mFormat, static_cast<uint32_t>(width), static_cast<uint32_t>(height),
actualSamples,
/* renderTargetOnly */ false,
/* allowFormatView */ mFormat.hasDepthAndStencilBits(), &mTexture));
}
mRenderTarget.setWithImplicitMSTexture(mTexture, mImplicitMSTexture,
mtl::kZeroNativeMipLevel, 0, mFormat);
// For emulated channels that GL texture intends to not have,
// we need to initialize their content.
bool emulatedChannels = mtl::IsFormatEmulated(mFormat);
if (emulatedChannels)
{
gl::ImageIndex index;
if (actualSamples > 1)
{
index = gl::ImageIndex::Make2DMultisample();
}
else
{
index = gl::ImageIndex::Make2D(0);
}
ANGLE_TRY(mtl::InitializeTextureContents(context, mTexture, mFormat,
mtl::ImageNativeIndex(index, 0)));
if (mImplicitMSTexture)
{
ANGLE_TRY(mtl::InitializeTextureContents(
context, mImplicitMSTexture, mFormat,
mtl::ImageNativeIndex(gl::ImageIndex::Make2DMultisample(), 0)));
}
} // if (emulatedChannels)
bool isDepthStencil = mFormat.hasDepthOrStencilBits();
if (isDepthStencil)
{
gl::ImageIndex index;
if (actualSamples > 1)
{
index = gl::ImageIndex::Make2DMultisample();
}
else
{
index = gl::ImageIndex::Make2D(0);
}
ANGLE_TRY(mtl::InitializeDepthStencilTextureContentsGPU(
context, mTexture, mFormat, mtl::ImageNativeIndex(index, 0)));
if (mImplicitMSTexture)
{
ANGLE_TRY(mtl::InitializeDepthStencilTextureContentsGPU(
context, mImplicitMSTexture, mFormat,
mtl::ImageNativeIndex(gl::ImageIndex::Make2DMultisample(), 0)));
}
}
}
return angle::Result::Continue;
}
angle::Result RenderbufferMtl::setStorage(const gl::Context *context,
GLenum internalformat,
GLsizei width,
GLsizei height)
{
return setStorageImpl(context, 0, internalformat, width, height);
}
angle::Result RenderbufferMtl::setStorageMultisample(const gl::Context *context,
GLsizei samples,
GLenum internalformat,
GLsizei width,
GLsizei height,
gl::MultisamplingMode mode)
{
return setStorageImpl(context, samples, internalformat, width, height);
}
angle::Result RenderbufferMtl::setStorageEGLImageTarget(const gl::Context *context,
egl::Image *image)
{
releaseTexture();
ContextMtl *contextMtl = mtl::GetImpl(context);
ImageMtl *imageMtl = mtl::GetImpl(image);
mTexture = imageMtl->getTexture();
const angle::FormatID angleFormatId =
angle::Format::InternalFormatToID(image->getFormat().info->sizedInternalFormat);
mFormat = contextMtl->getPixelFormat(angleFormatId);
mRenderTarget.set(mTexture, mtl::kZeroNativeMipLevel, 0, mFormat);
return angle::Result::Continue;
}
angle::Result RenderbufferMtl::getAttachmentRenderTarget(const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex,
GLsizei samples,
FramebufferAttachmentRenderTarget **rtOut)
{
ASSERT(mTexture && mTexture->valid());
*rtOut = &mRenderTarget;
return angle::Result::Continue;
}
angle::Result RenderbufferMtl::initializeContents(const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex)
{
if (imageIndex.valid())
return mtl::InitializeTextureContents(
context, mTexture, mFormat, mtl::ImageNativeIndex::FromBaseZeroGLIndex(imageIndex));
else
return mtl::InitializeTextureContents(
context, mTexture, mFormat,
mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)));
}
}