xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/metal/RenderTargetMtl.mm (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker//
2*8975f5c5SAndroid Build Coastguard Worker// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker// Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker// found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker//
6*8975f5c5SAndroid Build Coastguard Worker// RenderTargetMtl.mm:
7*8975f5c5SAndroid Build Coastguard Worker//    Implements the class methods for RenderTargetMtl.
8*8975f5c5SAndroid Build Coastguard Worker//
9*8975f5c5SAndroid Build Coastguard Worker
10*8975f5c5SAndroid Build Coastguard Worker#include "libANGLE/renderer/metal/RenderTargetMtl.h"
11*8975f5c5SAndroid Build Coastguard Worker
12*8975f5c5SAndroid Build Coastguard Workernamespace rx
13*8975f5c5SAndroid Build Coastguard Worker{
14*8975f5c5SAndroid Build Coastguard WorkerRenderTargetMtl::RenderTargetMtl() {}
15*8975f5c5SAndroid Build Coastguard Worker
16*8975f5c5SAndroid Build Coastguard WorkerRenderTargetMtl::~RenderTargetMtl()
17*8975f5c5SAndroid Build Coastguard Worker{
18*8975f5c5SAndroid Build Coastguard Worker    reset();
19*8975f5c5SAndroid Build Coastguard Worker}
20*8975f5c5SAndroid Build Coastguard Worker
21*8975f5c5SAndroid Build Coastguard Workervoid RenderTargetMtl::set(const mtl::TextureRef &texture,
22*8975f5c5SAndroid Build Coastguard Worker                          const mtl::MipmapNativeLevel &level,
23*8975f5c5SAndroid Build Coastguard Worker                          uint32_t layer,
24*8975f5c5SAndroid Build Coastguard Worker                          const mtl::Format &format)
25*8975f5c5SAndroid Build Coastguard Worker{
26*8975f5c5SAndroid Build Coastguard Worker    setWithImplicitMSTexture(texture, nullptr, level, layer, format);
27*8975f5c5SAndroid Build Coastguard Worker}
28*8975f5c5SAndroid Build Coastguard Worker
29*8975f5c5SAndroid Build Coastguard Workervoid RenderTargetMtl::setWithImplicitMSTexture(const mtl::TextureRef &texture,
30*8975f5c5SAndroid Build Coastguard Worker                                               const mtl::TextureRef &implicitMSTexture,
31*8975f5c5SAndroid Build Coastguard Worker                                               const mtl::MipmapNativeLevel &level,
32*8975f5c5SAndroid Build Coastguard Worker                                               uint32_t layer,
33*8975f5c5SAndroid Build Coastguard Worker                                               const mtl::Format &format)
34*8975f5c5SAndroid Build Coastguard Worker{
35*8975f5c5SAndroid Build Coastguard Worker    mTexture           = texture;
36*8975f5c5SAndroid Build Coastguard Worker    mImplicitMSTexture = implicitMSTexture;
37*8975f5c5SAndroid Build Coastguard Worker    mLevelIndex        = level;
38*8975f5c5SAndroid Build Coastguard Worker    mLayerIndex        = layer;
39*8975f5c5SAndroid Build Coastguard Worker    mFormat            = format;
40*8975f5c5SAndroid Build Coastguard Worker}
41*8975f5c5SAndroid Build Coastguard Worker
42*8975f5c5SAndroid Build Coastguard Workervoid RenderTargetMtl::setTexture(const mtl::TextureRef &texture)
43*8975f5c5SAndroid Build Coastguard Worker{
44*8975f5c5SAndroid Build Coastguard Worker    mTexture = texture;
45*8975f5c5SAndroid Build Coastguard Worker}
46*8975f5c5SAndroid Build Coastguard Worker
47*8975f5c5SAndroid Build Coastguard Workervoid RenderTargetMtl::setImplicitMSTexture(const mtl::TextureRef &implicitMSTexture)
48*8975f5c5SAndroid Build Coastguard Worker{
49*8975f5c5SAndroid Build Coastguard Worker    mImplicitMSTexture = implicitMSTexture;
50*8975f5c5SAndroid Build Coastguard Worker}
51*8975f5c5SAndroid Build Coastguard Worker
52*8975f5c5SAndroid Build Coastguard Workervoid RenderTargetMtl::duplicateFrom(const RenderTargetMtl &src)
53*8975f5c5SAndroid Build Coastguard Worker{
54*8975f5c5SAndroid Build Coastguard Worker    setWithImplicitMSTexture(src.getTexture(), src.getImplicitMSTexture(), src.getLevelIndex(),
55*8975f5c5SAndroid Build Coastguard Worker                             src.getLayerIndex(), src.getFormat());
56*8975f5c5SAndroid Build Coastguard Worker}
57*8975f5c5SAndroid Build Coastguard Worker
58*8975f5c5SAndroid Build Coastguard Workervoid RenderTargetMtl::reset()
59*8975f5c5SAndroid Build Coastguard Worker{
60*8975f5c5SAndroid Build Coastguard Worker    mTexture.reset();
61*8975f5c5SAndroid Build Coastguard Worker    mImplicitMSTexture.reset();
62*8975f5c5SAndroid Build Coastguard Worker    mLevelIndex = mtl::kZeroNativeMipLevel;
63*8975f5c5SAndroid Build Coastguard Worker    mLayerIndex = 0;
64*8975f5c5SAndroid Build Coastguard Worker    mFormat     = mtl::Format();
65*8975f5c5SAndroid Build Coastguard Worker}
66*8975f5c5SAndroid Build Coastguard Worker
67*8975f5c5SAndroid Build Coastguard Workeruint32_t RenderTargetMtl::getRenderSamples() const
68*8975f5c5SAndroid Build Coastguard Worker{
69*8975f5c5SAndroid Build Coastguard Worker    mtl::TextureRef implicitMSTex = getImplicitMSTexture();
70*8975f5c5SAndroid Build Coastguard Worker    mtl::TextureRef tex           = getTexture();
71*8975f5c5SAndroid Build Coastguard Worker    return implicitMSTex ? implicitMSTex->samples() : (tex ? tex->samples() : 1);
72*8975f5c5SAndroid Build Coastguard Worker}
73*8975f5c5SAndroid Build Coastguard Worker
74*8975f5c5SAndroid Build Coastguard Workervoid RenderTargetMtl::toRenderPassAttachmentDesc(mtl::RenderPassAttachmentDesc *rpaDescOut) const
75*8975f5c5SAndroid Build Coastguard Worker{
76*8975f5c5SAndroid Build Coastguard Worker    rpaDescOut->texture           = mTexture.lock();
77*8975f5c5SAndroid Build Coastguard Worker    rpaDescOut->implicitMSTexture = mImplicitMSTexture.lock();
78*8975f5c5SAndroid Build Coastguard Worker    rpaDescOut->level             = mLevelIndex;
79*8975f5c5SAndroid Build Coastguard Worker    rpaDescOut->sliceOrDepth      = mLayerIndex;
80*8975f5c5SAndroid Build Coastguard Worker    rpaDescOut->blendable         = mFormat.getCaps().blendable;
81*8975f5c5SAndroid Build Coastguard Worker}
82*8975f5c5SAndroid Build Coastguard Worker}  // namespace rx
83