Commit 0e5e6078 by Le Hoang Quyen Committed by Commit Bot

Metal: Use MipmapNativeLevel class to store native mip lvl

This is to avoid wrong native level in Metal, for example, not taking into account the OpenGL base level. Bug: angleproject:2634 Change-Id: I3a7a3ac41bdbd91a47755bb4ca11bd579c182e04 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2433326 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent c9206a08
......@@ -341,7 +341,7 @@ class ContextMtl : public ContextImpl, public mtl::Context
// Utilities to quickly create render command encoder to a specific texture:
// The previous content of texture will be loaded
mtl::RenderCommandEncoder *getTextureRenderCommandEncoder(const mtl::TextureRef &textureTarget,
const gl::ImageIndex &index);
const mtl::ImageNativeIndex &index);
// The previous content of texture will be loaded if clearColor is not provided
mtl::RenderCommandEncoder *getRenderTargetCommandEncoderWithClear(
const RenderTargetMtl &renderTarget,
......
......@@ -1285,14 +1285,14 @@ mtl::RenderCommandEncoder *ContextMtl::getRenderPassCommandEncoder(const mtl::Re
// The previous content of texture will be loaded
mtl::RenderCommandEncoder *ContextMtl::getTextureRenderCommandEncoder(
const mtl::TextureRef &textureTarget,
const gl::ImageIndex &index)
const mtl::ImageNativeIndex &index)
{
ASSERT(textureTarget && textureTarget->valid());
mtl::RenderPassDesc rpDesc;
rpDesc.colorAttachments[0].texture = textureTarget;
rpDesc.colorAttachments[0].level = index.getLevelIndex();
rpDesc.colorAttachments[0].level = index.getNativeLevel();
rpDesc.colorAttachments[0].sliceOrDepth = index.hasLayer() ? index.getLayerIndex() : 0;
rpDesc.numColorAttachments = 1;
rpDesc.sampleCount = textureTarget->samples();
......@@ -1898,8 +1898,9 @@ angle::Result ContextMtl::handleDirtyRenderPass(const gl::Context *context)
getPixelFormat(angle::FormatID::R8G8B8A8_UNORM),
1, 1, 1, true, false, &mDummyXFBRenderTexture));
}
mtl::RenderCommandEncoder *encoder =
getTextureRenderCommandEncoder(mDummyXFBRenderTexture, gl::ImageIndex::Make2D(0));
mtl::RenderCommandEncoder *encoder = getTextureRenderCommandEncoder(
mDummyXFBRenderTexture,
mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)));
encoder->setColorLoadAction(MTLLoadActionDontCare, MTLClearColor(), 0);
encoder->setColorStoreAction(MTLStoreActionDontCare);
......
......@@ -1053,9 +1053,8 @@ gl::Rectangle FramebufferMtl::getCorrectFlippedReadArea(const gl::Context *conte
gl::Rectangle flippedArea = glArea;
if (mFlipY)
{
flippedArea.y =
readRT->getTexture()->height(static_cast<uint32_t>(readRT->getLevelIndex())) -
flippedArea.y - flippedArea.height;
flippedArea.y = readRT->getTexture()->height(readRT->getLevelIndex()) - flippedArea.y -
flippedArea.height;
}
return flippedArea;
......
......@@ -61,16 +61,14 @@ angle::Result RenderbufferMtl::setStorageImpl(const gl::Context *context,
ANGLE_TRY(mtl::Texture::Make2DTexture(contextMtl, mFormat, width, height, 1, false,
mFormat.hasDepthAndStencilBits(), &mTexture));
mRenderTarget.set(mTexture, 0, 0, mFormat);
mRenderTarget.set(mTexture, 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;
index = gl::ImageIndex::Make2D(0);
auto index = mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0));
ANGLE_TRY(mtl::InitializeTextureContents(context, mTexture, mFormat, index));
}
......@@ -122,6 +120,7 @@ angle::Result RenderbufferMtl::getAttachmentRenderTarget(const gl::Context *cont
angle::Result RenderbufferMtl::initializeContents(const gl::Context *context,
const gl::ImageIndex &imageIndex)
{
return mtl::InitializeTextureContents(context, mTexture, mFormat, imageIndex);
return mtl::InitializeTextureContents(context, mTexture, mFormat,
mtl::ImageNativeIndex::FromBaseZeroGLIndex(imageIndex));
}
}
......@@ -33,21 +33,21 @@ class RenderTargetMtl final : public FramebufferAttachmentRenderTarget
RenderTargetMtl(RenderTargetMtl &&other);
void set(const mtl::TextureRef &texture,
uint32_t level,
uint32_t layer,
const mtl::Format &format);
void set(const mtl::TextureRef &texture,
const mtl::TextureRef &implicitMSTexture,
uint32_t level,
const mtl::MipmapNativeLevel &level,
uint32_t layer,
const mtl::Format &format);
void setWithImplicitMSTexture(const mtl::TextureRef &texture,
const mtl::TextureRef &implicitMSTexture,
const mtl::MipmapNativeLevel &level,
uint32_t layer,
const mtl::Format &format);
void setTexture(const mtl::TextureRef &texture);
void setImplicitMSTexture(const mtl::TextureRef &implicitMSTexture);
void reset();
mtl::TextureRef getTexture() const { return mTexture.lock(); }
mtl::TextureRef getImplicitMSTexture() const { return mImplicitMSTexture.lock(); }
uint32_t getLevelIndex() const { return mLevelIndex; }
const mtl::MipmapNativeLevel &getLevelIndex() const { return mLevelIndex; }
uint32_t getLayerIndex() const { return mLayerIndex; }
uint32_t getRenderSamples() const;
const mtl::Format *getFormat() const { return mFormat; }
......@@ -57,9 +57,9 @@ class RenderTargetMtl final : public FramebufferAttachmentRenderTarget
private:
mtl::TextureWeakRef mTexture;
mtl::TextureWeakRef mImplicitMSTexture;
uint32_t mLevelIndex = 0;
uint32_t mLayerIndex = 0;
const mtl::Format *mFormat = nullptr;
mtl::MipmapNativeLevel mLevelIndex = mtl::kZeroNativeMipLevel;
uint32_t mLayerIndex = 0;
const mtl::Format *mFormat = nullptr;
};
} // namespace rx
......
......@@ -26,18 +26,18 @@ RenderTargetMtl::RenderTargetMtl(RenderTargetMtl &&other)
{}
void RenderTargetMtl::set(const mtl::TextureRef &texture,
uint32_t level,
const mtl::MipmapNativeLevel &level,
uint32_t layer,
const mtl::Format &format)
{
set(texture, nullptr, level, layer, format);
setWithImplicitMSTexture(texture, nullptr, level, layer, format);
}
void RenderTargetMtl::set(const mtl::TextureRef &texture,
const mtl::TextureRef &implicitMSTexture,
uint32_t level,
uint32_t layer,
const mtl::Format &format)
void RenderTargetMtl::setWithImplicitMSTexture(const mtl::TextureRef &texture,
const mtl::TextureRef &implicitMSTexture,
const mtl::MipmapNativeLevel &level,
uint32_t layer,
const mtl::Format &format)
{
mTexture = texture;
mImplicitMSTexture = implicitMSTexture;
......@@ -60,7 +60,7 @@ void RenderTargetMtl::reset()
{
mTexture.reset();
mImplicitMSTexture.reset();
mLevelIndex = 0;
mLevelIndex = mtl::kZeroNativeMipLevel;
mLayerIndex = 0;
mFormat = nullptr;
}
......
......@@ -397,7 +397,7 @@ EGLint SurfaceMtl::getWidth() const
{
if (mColorTexture)
{
return static_cast<EGLint>(mColorTexture->width());
return static_cast<EGLint>(mColorTexture->widthAt0());
}
return 0;
}
......@@ -406,7 +406,7 @@ EGLint SurfaceMtl::getHeight() const
{
if (mColorTexture)
{
return static_cast<EGLint>(mColorTexture->height());
return static_cast<EGLint>(mColorTexture->heightAt0());
}
return 0;
}
......@@ -488,7 +488,7 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context *
ASSERT(mColorTexture);
if (mSamples > 1 && (!mMSColorTexture || mMSColorTexture->size() != size))
if (mSamples > 1 && (!mMSColorTexture || mMSColorTexture->sizeAt0() != size))
{
mAutoResolveMSColorTexture =
contextMtl->getDisplay()->getFeatures().allowMultisampleStoreAndResolve.enabled;
......@@ -507,15 +507,15 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context *
}
}
if (mDepthFormat.valid() && (!mDepthTexture || mDepthTexture->size() != size))
if (mDepthFormat.valid() && (!mDepthTexture || mDepthTexture->sizeAt0() != size))
{
ANGLE_TRY(CreateOrResizeTexture(context, mDepthFormat, size.width, size.height, mSamples,
/** renderTargetOnly */ false, &mDepthTexture));
mDepthRenderTarget.set(mDepthTexture, 0, 0, mDepthFormat);
mDepthRenderTarget.set(mDepthTexture, mtl::kZeroNativeMipLevel, 0, mDepthFormat);
}
if (mStencilFormat.valid() && (!mStencilTexture || mStencilTexture->size() != size))
if (mStencilFormat.valid() && (!mStencilTexture || mStencilTexture->sizeAt0() != size))
{
if (mUsePackedDepthStencil)
{
......@@ -528,7 +528,7 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context *
/** renderTargetOnly */ false, &mStencilTexture));
}
mStencilRenderTarget.set(mStencilTexture, 0, 0, mStencilFormat);
mStencilRenderTarget.set(mStencilTexture, mtl::kZeroNativeMipLevel, 0, mStencilFormat);
}
return angle::Result::Continue;
......@@ -542,7 +542,8 @@ angle::Result SurfaceMtl::resolveColorTextureIfNeeded(const gl::Context *context
// Manually resolve texture
ContextMtl *contextMtl = mtl::GetImpl(context);
mColorManualResolveRenderTarget.set(mColorTexture, 0, 0, mColorFormat);
mColorManualResolveRenderTarget.set(mColorTexture, mtl::kZeroNativeMipLevel, 0,
mColorFormat);
mtl::RenderCommandEncoder *encoder =
contextMtl->getRenderTargetCommandEncoder(mColorManualResolveRenderTarget);
ANGLE_TRY(contextMtl->getDisplay()->getUtils().blitColorWithDraw(context, encoder,
......@@ -798,7 +799,8 @@ angle::Result WindowSurfaceMtl::obtainNextDrawable(const gl::Context *context)
{
mColorTexture = mtl::Texture::MakeFromMetal(mCurrentDrawable.get().texture);
ASSERT(!mColorRenderTarget.getTexture());
mColorRenderTarget.set(mColorTexture, mMSColorTexture, 0, 0, mColorFormat);
mColorRenderTarget.setWithImplicitMSTexture(mColorTexture, mMSColorTexture,
mtl::kZeroNativeMipLevel, 0, mColorFormat);
}
else
{
......@@ -907,12 +909,12 @@ angle::Result OffscreenSurfaceMtl::getAttachmentRenderTarget(
angle::Result OffscreenSurfaceMtl::ensureTexturesSizeCorrect(const gl::Context *context)
{
if (!mColorTexture || mColorTexture->size() != mSize)
if (!mColorTexture || mColorTexture->sizeAt0() != mSize)
{
ANGLE_TRY(CreateOrResizeTexture(context, mColorFormat, mSize.width, mSize.height, 1,
/** renderTargetOnly */ false, &mColorTexture));
mColorRenderTarget.set(mColorTexture, 0, 0, mColorFormat);
mColorRenderTarget.set(mColorTexture, mtl::kZeroNativeMipLevel, 0, mColorFormat);
}
return ensureCompanionTexturesSizeCorrect(context, mSize);
......@@ -1023,16 +1025,17 @@ angle::Result IOSurfaceSurfaceMtl::ensureColorTextureCreated(const gl::Context *
mColorTexture = mtl::Texture::MakeFromMetal([texture ANGLE_MTL_AUTORELEASE]);
}
mColorRenderTarget.set(mColorTexture, 0, 0, mColorFormat);
mColorRenderTarget.set(mColorTexture, mtl::kZeroNativeMipLevel, 0, mColorFormat);
if (kIOSurfaceFormats[mIOSurfaceFormatIdx].internalFormat == GL_RGB)
{
// This format has emulated alpha channel. Initialize texture's alpha channel to 1.0.
const mtl::Format &rgbClearFormat =
contextMtl->getPixelFormat(angle::FormatID::R8G8B8_UNORM);
ANGLE_TRY(mtl::InitializeTextureContentsGPU(context, mColorTexture, rgbClearFormat,
gl::ImageIndex::Make2D(0),
MTLColorWriteMaskAlpha));
ANGLE_TRY(mtl::InitializeTextureContentsGPU(
context, mColorTexture, rgbClearFormat,
mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)),
MTLColorWriteMaskAlpha));
// Disable subsequent rendering to alpha channel.
mColorTexture->setColorWritableMask(MTLColorWriteMaskAll & (~MTLColorWriteMaskAlpha));
......
......@@ -180,12 +180,13 @@ class TextureMtl : public TextureImpl
angle::Result ensureImageCreated(const gl::Context *context, const gl::ImageIndex &index);
// Ensure all image views at all faces/levels are retained.
void retainImageDefinitions();
mtl::TextureRef createImageViewFromNativeTexture(GLuint cubeFaceOrZero, GLuint nativeLevel);
mtl::TextureRef createImageViewFromNativeTexture(GLuint cubeFaceOrZero,
const mtl::MipmapNativeLevel &nativeLevel);
angle::Result ensureNativeLevelViewsCreated();
angle::Result checkForEmulatedChannels(const gl::Context *context,
const mtl::Format &mtlFormat,
const mtl::TextureRef &texture);
int getNativeLevel(const gl::ImageIndex &imageIndex) const;
mtl::MipmapNativeLevel getNativeLevel(const gl::ImageIndex &imageIndex) const;
mtl::TextureRef &getImage(const gl::ImageIndex &imageIndex);
ImageDefinitionMtl &getImageDefinition(const gl::ImageIndex &imageIndex);
RenderTargetMtl &getRenderTarget(const gl::ImageIndex &imageIndex);
......@@ -255,7 +256,7 @@ class TextureMtl : public TextureImpl
const gl::ImageIndex &index,
const gl::Offset &destOffset,
const gl::InternalFormat &internalFormat,
uint32_t sourceNativeLevel,
const mtl::MipmapNativeLevel &sourceNativeLevel,
const gl::Box &sourceBox,
const angle::Format &sourceAngleFormat,
bool unpackFlipY,
......@@ -267,7 +268,7 @@ class TextureMtl : public TextureImpl
const gl::ImageIndex &index,
const gl::Offset &destOffset,
const gl::InternalFormat &internalFormat,
uint32_t sourceNativeLevel,
const mtl::MipmapNativeLevel &sourceNativeLevel,
const gl::Box &sourceBox,
const angle::Format &sourceAngleFormat,
bool unpackFlipY,
......@@ -331,7 +332,7 @@ class TextureMtl : public TextureImpl
std::map<int, gl::TexLevelArray<RenderTargetMtl>> mPerLayerRenderTargets;
// Mipmap views are indexed by native level (ignored base level):
gl::TexLevelArray<mtl::TextureRef> mNativeLevelViews;
mtl::NativeTexLevelArray mNativeLevelViews;
bool mIsPow2 = false;
};
......
......@@ -519,13 +519,13 @@ class BlitCommandEncoder final : public CommandEncoder
MTLSize srcSize,
const TextureRef &dst,
uint32_t dstSlice,
uint32_t dstLevel,
MipmapNativeLevel dstLevel,
MTLOrigin dstOrigin,
MTLBlitOption blitOption);
BlitCommandEncoder &copyTextureToBuffer(const TextureRef &src,
uint32_t srcSlice,
uint32_t srcLevel,
MipmapNativeLevel srcLevel,
MTLOrigin srcOrigin,
MTLSize srcSize,
const BufferRef &dst,
......@@ -536,10 +536,10 @@ class BlitCommandEncoder final : public CommandEncoder
BlitCommandEncoder &copyTexture(const TextureRef &src,
uint32_t srcSlice,
uint32_t srcLevel,
MipmapNativeLevel srcLevel,
const TextureRef &dst,
uint32_t dstSlice,
uint32_t dstLevel,
MipmapNativeLevel dstLevel,
uint32_t sliceCount,
uint32_t levelCount);
......
......@@ -975,7 +975,7 @@ inline void RenderCommandEncoder::initAttachmentWriteDependencyAndScissorRect(
{
cmdBuffer().setWriteDependency(texture);
uint32_t mipLevel = attachment.level;
const MipmapNativeLevel &mipLevel = attachment.level;
mRenderPassMaxScissorRect.width =
std::min<NSUInteger>(mRenderPassMaxScissorRect.width, texture->width(mipLevel));
......@@ -1703,7 +1703,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src
MTLSize srcSize,
const TextureRef &dst,
uint32_t dstSlice,
uint32_t dstLevel,
MipmapNativeLevel dstLevel,
MTLOrigin dstOrigin,
MTLBlitOption blitOption)
{
......@@ -1722,7 +1722,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src
sourceSize:srcSize
toTexture:dst->get()
destinationSlice:dstSlice
destinationLevel:dstLevel
destinationLevel:dstLevel.get()
destinationOrigin:dstOrigin
options:blitOption];
......@@ -1731,7 +1731,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src
BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &src,
uint32_t srcSlice,
uint32_t srcLevel,
MipmapNativeLevel srcLevel,
MTLOrigin srcOrigin,
MTLSize srcSize,
const BufferRef &dst,
......@@ -1751,7 +1751,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &sr
[get() copyFromTexture:src->get()
sourceSlice:srcSlice
sourceLevel:srcLevel
sourceLevel:srcLevel.get()
sourceOrigin:srcOrigin
sourceSize:srcSize
toBuffer:dst->get()
......@@ -1765,10 +1765,10 @@ BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &sr
BlitCommandEncoder &BlitCommandEncoder::copyTexture(const TextureRef &src,
uint32_t srcStartSlice,
uint32_t srcStartLevel,
MipmapNativeLevel srcStartLevel,
const TextureRef &dst,
uint32_t dstStartSlice,
uint32_t dstStartLevel,
MipmapNativeLevel dstStartLevel,
uint32_t sliceCount,
uint32_t levelCount)
{
......@@ -1787,19 +1787,19 @@ BlitCommandEncoder &BlitCommandEncoder::copyTexture(const TextureRef &src,
uint32_t dstSlice = dstStartSlice + slice;
for (uint32_t level = 0; level < levelCount; ++level)
{
uint32_t srcLevel = srcStartLevel + level;
uint32_t dstLevel = dstStartLevel + level;
MipmapNativeLevel srcLevel = srcStartLevel + level;
MipmapNativeLevel dstLevel = dstStartLevel + level;
MTLSize srcSize =
MTLSizeMake(src->width(srcLevel), src->height(srcLevel), src->depth(srcLevel));
[get() copyFromTexture:src->get()
sourceSlice:srcSlice
sourceLevel:srcLevel
sourceLevel:srcLevel.get()
sourceOrigin:origin
sourceSize:srcSize
toTexture:dst->get()
destinationSlice:dstSlice
destinationLevel:dstLevel
destinationLevel:dstLevel.get()
destinationOrigin:origin];
}
}
......
......@@ -22,6 +22,7 @@
#include "common/angleutils.h"
#include "common/apple_platform_utils.h"
#include "libANGLE/Constants.h"
#include "libANGLE/ImageIndex.h"
#include "libANGLE/Version.h"
#include "libANGLE/angletypes.h"
......@@ -339,6 +340,70 @@ using SharedEventRef = AutoObjCPtr<id<MTLSharedEvent>>;
using SharedEventRef = AutoObjCObj<NSObject>;
#endif
// The native image index used by Metal back-end, the image index uses native mipmap level instead
// of "virtual" level modified by OpenGL's base level.
using MipmapNativeLevel = gl::LevelIndexWrapper<uint32_t>;
constexpr MipmapNativeLevel kZeroNativeMipLevel(0);
class ImageNativeIndexIterator;
class ImageNativeIndex final
{
public:
ImageNativeIndex() = delete;
ImageNativeIndex(const gl::ImageIndex &src, GLint baseLevel)
{
mNativeIndex = gl::ImageIndex::MakeFromType(src.getType(), src.getLevelIndex() - baseLevel,
src.getLayerIndex(), src.getLayerCount());
}
static ImageNativeIndex FromBaseZeroGLIndex(const gl::ImageIndex &src)
{
return ImageNativeIndex(src, 0);
}
MipmapNativeLevel getNativeLevel() const
{
return MipmapNativeLevel(mNativeIndex.getLevelIndex());
}
gl::TextureType getType() const { return mNativeIndex.getType(); }
GLint getLayerIndex() const { return mNativeIndex.getLayerIndex(); }
GLint getLayerCount() const { return mNativeIndex.getLayerCount(); }
GLint cubeMapFaceIndex() const { return mNativeIndex.cubeMapFaceIndex(); }
bool isLayered() const { return mNativeIndex.isLayered(); }
bool hasLayer() const { return mNativeIndex.hasLayer(); }
bool has3DLayer() const { return mNativeIndex.has3DLayer(); }
bool usesTex3D() const { return mNativeIndex.usesTex3D(); }
bool valid() const { return mNativeIndex.valid(); }
ImageNativeIndexIterator getLayerIterator(GLint layerCount) const;
private:
gl::ImageIndex mNativeIndex;
};
class ImageNativeIndexIterator final
{
public:
ImageNativeIndex next() { return ImageNativeIndex(mNativeIndexIte.next(), 0); }
ImageNativeIndex current() const { return ImageNativeIndex(mNativeIndexIte.current(), 0); }
bool hasNext() const { return mNativeIndexIte.hasNext(); }
private:
// This class is only constructable from ImageNativeIndex
friend class ImageNativeIndex;
explicit ImageNativeIndexIterator(const gl::ImageIndexIterator &baseZeroSrc)
: mNativeIndexIte(baseZeroSrc)
{}
gl::ImageIndexIterator mNativeIndexIte;
};
struct ClearOptions
{
Optional<MTLClearColor> clearColor;
......
......@@ -21,6 +21,13 @@ namespace rx
namespace mtl
{
// ImageNativeIndex implementation
ImageNativeIndexIterator ImageNativeIndex::getLayerIterator(GLint layerCount) const
{
return ImageNativeIndexIterator(mNativeIndex.getLayerIterator(layerCount));
}
// Context implementation
Context::Context(DisplayMtl *display) : mDisplay(display) {}
id<MTLDevice> Context::getMetalDevice() const
......
......@@ -57,8 +57,8 @@ struct BlitParams
bool dstFlipX = false;
TextureRef src;
uint32_t srcLevel = 0;
uint32_t srcLayer = 0;
MipmapNativeLevel srcLevel = kZeroNativeMipLevel;
uint32_t srcLayer = 0;
// Source rectangle:
// NOTE: if srcYFlipped=true, this rectangle will be converted internally to flipped rect before
......@@ -93,9 +93,9 @@ struct StencilBlitViaBufferParams : public DepthStencilBlitParams
StencilBlitViaBufferParams(const DepthStencilBlitParams &src);
TextureRef dstStencil;
uint32_t dstStencilLevel = 0;
uint32_t dstStencilLayer = 0;
bool dstPackedDepthStencilFormat = false;
MipmapNativeLevel dstStencilLevel = kZeroNativeMipLevel;
uint32_t dstStencilLayer = 0;
bool dstPackedDepthStencilFormat = false;
};
struct TriFanFromArrayParams
......@@ -150,8 +150,8 @@ struct CopyPixelsFromBufferParams : CopyPixelsCommonParams
struct CopyPixelsToBufferParams : CopyPixelsCommonParams
{
gl::Rectangle textureArea;
uint32_t textureLevel = 0;
uint32_t textureSliceOrDeph = 0;
MipmapNativeLevel textureLevel = kZeroNativeMipLevel;
uint32_t textureSliceOrDeph = 0;
bool reverseTextureRowOrder;
};
......@@ -371,7 +371,7 @@ class MipmapUtils final : angle::NonCopyable
angle::Result generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture,
bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews);
NativeTexLevelArray *mipmapOutputViews);
private:
void ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl);
......@@ -470,7 +470,7 @@ class RenderUtils : public Context, angle::NonCopyable
angle::Result generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture,
bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews);
NativeTexLevelArray *mipmapOutputViews);
angle::Result unpackPixelsFromBufferToTexture(ContextMtl *contextMtl,
const angle::Format &srcAngleFormat,
......
......@@ -437,7 +437,7 @@ void SetupBlitWithDrawUniformData(RenderCommandEncoder *cmdEncoder,
BlitParamsUniform uniformParams;
uniformParams.dstFlipX = params.dstFlipX ? 1 : 0;
uniformParams.dstFlipY = params.dstFlipY ? 1 : 0;
uniformParams.srcLevel = params.srcLevel;
uniformParams.srcLevel = params.srcLevel.get();
uniformParams.srcLayer = params.srcLayer;
if (isColorBlit)
{
......@@ -611,10 +611,10 @@ angle::Result RenderUtils::blitColorWithDraw(const gl::Context *context,
}
ColorBlitParams params;
params.enabledBuffers.set(0);
params.src = srcTexture;
params.dstTextureSize =
gl::Extents(static_cast<int>(srcTexture->width()), static_cast<int>(srcTexture->height()),
static_cast<int>(srcTexture->depth()));
params.src = srcTexture;
params.dstTextureSize = gl::Extents(static_cast<int>(srcTexture->widthAt0()),
static_cast<int>(srcTexture->heightAt0()),
static_cast<int>(srcTexture->depthAt0()));
params.dstRect = params.dstScissorRect = params.srcRect =
gl::Rectangle(0, 0, params.dstTextureSize.width, params.dstTextureSize.height);
......@@ -682,7 +682,7 @@ void RenderUtils::combineVisibilityResult(
angle::Result RenderUtils::generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture,
bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews)
NativeTexLevelArray *mipmapOutputViews)
{
return mMipmapUtils.generateMipmapCS(contextMtl, srcTexture, sRGBMipmap, mipmapOutputViews);
}
......@@ -1336,7 +1336,7 @@ angle::Result DepthStencilBlitUtils::blitStencilViaCopyBuffer(
uniform.srcTexCoordSteps[1] = (v1 - v0) / params.dstRect.height;
uniform.srcStartTexCoords[0] = u0 + uniform.srcTexCoordSteps[0] * 0.5f;
uniform.srcStartTexCoords[1] = v0 + uniform.srcTexCoordSteps[1] * 0.5f;
uniform.srcLevel = params.srcLevel;
uniform.srcLevel = params.srcLevel.get();
uniform.srcLayer = params.srcLayer;
uniform.dstSize[0] = params.dstRect.width;
uniform.dstSize[1] = params.dstRect.height;
......@@ -1801,7 +1801,7 @@ void MipmapUtils::ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl
angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture,
bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews)
NativeTexLevelArray *mipmapOutputViews)
{
// Only support 3D texture for now.
ASSERT(srcTexture->textureType() == MTLTextureType3D);
......@@ -1848,16 +1848,17 @@ angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl,
GenerateMipmapUniform options;
uint32_t remainMips = srcTexture->mipmapLevels() - 1;
options.srcLevel = 0;
options.sRGB = sRGBMipmap;
uint32_t remainMips = srcTexture->mipmapLevels() - 1;
MipmapNativeLevel batchSrcLevel = kZeroNativeMipLevel;
options.srcLevel = batchSrcLevel.get();
options.sRGB = sRGBMipmap;
cmdEncoder->setTexture(srcTexture, 0);
cmdEncoder->markResourceBeingWrittenByGPU(srcTexture);
while (remainMips)
{
const TextureRef &firstMipView = mipmapOutputViews->at(options.srcLevel + 1);
gl::Extents size = firstMipView->size();
const TextureRef &firstMipView = mipmapOutputViews->at(batchSrcLevel + 1);
gl::Extents size = firstMipView->sizeAt0();
bool isPow2 = gl::isPow2(size.width) && gl::isPow2(size.height) && gl::isPow2(size.depth);
// Currently multiple mipmaps generation is only supported for power of two base level.
......@@ -1874,18 +1875,20 @@ angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl,
for (uint32_t i = 1; i <= options.numMipmapsToGenerate; ++i)
{
cmdEncoder->setTexture(mipmapOutputViews->at(options.srcLevel + i), i);
cmdEncoder->setTexture(mipmapOutputViews->at(batchSrcLevel + i), i);
}
uint32_t threadsPerZ = std::max(slices, firstMipView->depth());
uint32_t threadsPerZ = std::max(slices, firstMipView->depthAt0());
DispatchCompute(contextMtl, cmdEncoder,
/** allowNonUniform */ false,
MTLSizeMake(firstMipView->width(), firstMipView->height(), threadsPerZ),
threadGroupSize);
DispatchCompute(
contextMtl, cmdEncoder,
/** allowNonUniform */ false,
MTLSizeMake(firstMipView->widthAt0(), firstMipView->heightAt0(), threadsPerZ),
threadGroupSize);
remainMips -= options.numMipmapsToGenerate;
options.srcLevel += options.numMipmapsToGenerate;
batchSrcLevel = batchSrcLevel + options.numMipmapsToGenerate;
options.srcLevel = batchSrcLevel.get();
}
return angle::Result::Continue;
......@@ -2012,7 +2015,7 @@ angle::Result CopyPixelsUtils::packPixelsFromTextureToBuffer(ContextMtl *context
options.bufferRowPitch = params.bufferRowPitch;
options.textureOffset[0] = params.textureArea.x;
options.textureOffset[1] = params.textureArea.y;
options.textureLevel = params.textureLevel;
options.textureLevel = params.textureLevel.get();
options.textureLayer = params.textureSliceOrDeph;
options.reverseTextureRowOrder = params.reverseTextureRowOrder;
cmdEncoder->setData(options, 0);
......
......@@ -19,7 +19,6 @@
#include "common/MemoryBuffer.h"
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include "libANGLE/ImageIndex.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/metal/mtl_common.h"
#include "libANGLE/renderer/metal/mtl_format_utils.h"
......@@ -147,14 +146,14 @@ class Texture final : public Resource,
void replace2DRegion(ContextMtl *context,
const MTLRegion &region,
uint32_t mipmapLevel,
const MipmapNativeLevel &mipmapLevel,
uint32_t slice,
const uint8_t *data,
size_t bytesPerRow);
void replaceRegion(ContextMtl *context,
const MTLRegion &region,
uint32_t mipmapLevel,
const MipmapNativeLevel &mipmapLevel,
uint32_t slice,
const uint8_t *data,
size_t bytesPerRow,
......@@ -164,16 +163,16 @@ class Texture final : public Resource,
size_t bytesPerRow,
size_t bytesPer2DInage,
const MTLRegion &region,
uint32_t mipmapLevel,
const MipmapNativeLevel &mipmapLevel,
uint32_t slice,
uint8_t *dataOut);
// Create 2d view of a cube face which full range of mip levels.
TextureRef createCubeFaceView(uint32_t face);
// Create a view of one slice at a level.
TextureRef createSliceMipView(uint32_t slice, uint32_t level);
TextureRef createSliceMipView(uint32_t slice, const MipmapNativeLevel &level);
// Create a view of a level.
TextureRef createMipView(uint32_t level);
TextureRef createMipView(const MipmapNativeLevel &level);
// Create a view with different format
TextureRef createViewWithDifferentFormat(MTLPixelFormat format);
// Same as above but the target format must be compatible, for example sRGB to linear. In this
......@@ -187,12 +186,17 @@ class Texture final : public Resource,
uint32_t arrayLength() const;
uint32_t cubeFacesOrArrayLength() const;
uint32_t width(uint32_t level = 0) const;
uint32_t height(uint32_t level = 0) const;
uint32_t depth(uint32_t level = 0) const;
uint32_t width(const MipmapNativeLevel &level) const;
uint32_t height(const MipmapNativeLevel &level) const;
uint32_t depth(const MipmapNativeLevel &level) const;
gl::Extents size(uint32_t level = 0) const;
gl::Extents size(const gl::ImageIndex &index) const;
gl::Extents size(const MipmapNativeLevel &level) const;
gl::Extents size(const ImageNativeIndex &index) const;
uint32_t widthAt0() const { return width(kZeroNativeMipLevel); }
uint32_t heightAt0() const { return height(kZeroNativeMipLevel); }
uint32_t depthAt0() const { return depth(kZeroNativeMipLevel); }
gl::Extents sizeAt0() const { return size(kZeroNativeMipLevel); }
uint32_t samples() const;
......@@ -305,6 +309,27 @@ class Buffer final : public Resource, public WrappedObject<id<MTLBuffer>>
bool mMapReadOnly = true;
};
class NativeTexLevelArray
{
public:
TextureRef &at(const MipmapNativeLevel &level) { return mTexLevels.at(level.get()); }
const TextureRef &at(const MipmapNativeLevel &level) const
{
return mTexLevels.at(level.get());
}
TextureRef &operator[](const MipmapNativeLevel &level) { return at(level); }
const TextureRef &operator[](const MipmapNativeLevel &level) const { return at(level); }
gl::TexLevelArray<TextureRef>::iterator begin() { return mTexLevels.begin(); }
gl::TexLevelArray<TextureRef>::const_iterator begin() const { return mTexLevels.begin(); }
gl::TexLevelArray<TextureRef>::iterator end() { return mTexLevels.end(); }
gl::TexLevelArray<TextureRef>::const_iterator end() const { return mTexLevels.end(); }
private:
gl::TexLevelArray<TextureRef> mTexLevels;
};
} // namespace mtl
} // namespace rx
......
......@@ -26,9 +26,9 @@ namespace mtl
{
namespace
{
inline NSUInteger GetMipSize(NSUInteger baseSize, NSUInteger level)
inline NSUInteger GetMipSize(NSUInteger baseSize, const MipmapNativeLevel level)
{
return std::max<NSUInteger>(1, baseSize >> level);
return std::max<NSUInteger>(1, baseSize >> level.get());
}
void SetTextureSwizzle(ContextMtl *context,
......@@ -355,7 +355,7 @@ bool Texture::supportFormatView() const
void Texture::replace2DRegion(ContextMtl *context,
const MTLRegion &region,
uint32_t mipmapLevel,
const MipmapNativeLevel &mipmapLevel,
uint32_t slice,
const uint8_t *data,
size_t bytesPerRow)
......@@ -366,13 +366,13 @@ void Texture::replace2DRegion(ContextMtl *context,
void Texture::replaceRegion(ContextMtl *context,
const MTLRegion &region,
uint32_t mipmapLevel,
const MipmapNativeLevel &mipmapLevel,
uint32_t slice,
const uint8_t *data,
size_t bytesPerRow,
size_t bytesPer2DImage)
{
if (mipmapLevel >= this->mipmapLevels())
if (mipmapLevel.get() >= this->mipmapLevels())
{
return;
}
......@@ -397,7 +397,7 @@ void Texture::replaceRegion(ContextMtl *context,
}
[get() replaceRegion:region
mipmapLevel:mipmapLevel
mipmapLevel:mipmapLevel.get()
slice:slice
withBytes:data
bytesPerRow:bytesPerRow
......@@ -408,7 +408,7 @@ void Texture::getBytes(ContextMtl *context,
size_t bytesPerRow,
size_t bytesPer2DInage,
const MTLRegion &region,
uint32_t mipmapLevel,
const MipmapNativeLevel &mipmapLevel,
uint32_t slice,
uint8_t *dataOut)
{
......@@ -430,7 +430,7 @@ void Texture::getBytes(ContextMtl *context,
bytesPerRow:bytesPerRow
bytesPerImage:bytesPer2DInage
fromRegion:region
mipmapLevel:mipmapLevel
mipmapLevel:mipmapLevel.get()
slice:slice];
}
......@@ -450,7 +450,7 @@ TextureRef Texture::createCubeFaceView(uint32_t face)
}
}
TextureRef Texture::createSliceMipView(uint32_t slice, uint32_t level)
TextureRef Texture::createSliceMipView(uint32_t slice, const MipmapNativeLevel &level)
{
ANGLE_MTL_OBJC_SCOPE
{
......@@ -459,7 +459,7 @@ TextureRef Texture::createSliceMipView(uint32_t slice, uint32_t level)
case MTLTextureTypeCube:
case MTLTextureType2D:
case MTLTextureType2DArray:
return TextureRef(new Texture(this, MTLTextureType2D, NSMakeRange(level, 1),
return TextureRef(new Texture(this, MTLTextureType2D, NSMakeRange(level.get(), 1),
NSMakeRange(slice, 1)));
default:
UNREACHABLE();
......@@ -468,13 +468,13 @@ TextureRef Texture::createSliceMipView(uint32_t slice, uint32_t level)
}
}
TextureRef Texture::createMipView(uint32_t level)
TextureRef Texture::createMipView(const MipmapNativeLevel &level)
{
ANGLE_MTL_OBJC_SCOPE
{
NSUInteger slices = cubeFacesOrArrayLength();
return TextureRef(
new Texture(this, textureType(), NSMakeRange(level, 1), NSMakeRange(0, slices)));
new Texture(this, textureType(), NSMakeRange(level.get(), 1), NSMakeRange(0, slices)));
}
}
......@@ -518,22 +518,22 @@ uint32_t Texture::cubeFacesOrArrayLength() const
return arrayLength();
}
uint32_t Texture::width(uint32_t level) const
uint32_t Texture::width(const MipmapNativeLevel &level) const
{
return static_cast<uint32_t>(GetMipSize(get().width, level));
}
uint32_t Texture::height(uint32_t level) const
uint32_t Texture::height(const MipmapNativeLevel &level) const
{
return static_cast<uint32_t>(GetMipSize(get().height, level));
}
uint32_t Texture::depth(uint32_t level) const
uint32_t Texture::depth(const MipmapNativeLevel &level) const
{
return static_cast<uint32_t>(GetMipSize(get().depth, level));
}
gl::Extents Texture::size(uint32_t level) const
gl::Extents Texture::size(const MipmapNativeLevel &level) const
{
gl::Extents re;
......@@ -544,9 +544,9 @@ gl::Extents Texture::size(uint32_t level) const
return re;
}
gl::Extents Texture::size(const gl::ImageIndex &index) const
gl::Extents Texture::size(const ImageNativeIndex &index) const
{
gl::Extents extents = size(index.getLevelIndex());
gl::Extents extents = size(index.getNativeLevel());
if (index.hasLayer())
{
......
......@@ -300,7 +300,7 @@ struct RenderPassAttachmentDesc
// Implicit multisample texture that will be rendered into and discarded at the end of
// a render pass. Its result will be resolved into normal texture above.
TextureRef implicitMSTexture;
uint32_t level;
MipmapNativeLevel level;
uint32_t sliceOrDepth;
MTLLoadAction loadAction;
......
......@@ -193,7 +193,7 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src,
dst.slice = 0;
dst.depthPlane = 0;
dst.resolveTexture = ToObjC(src.texture);
dst.resolveLevel = src.level;
dst.resolveLevel = src.level.get();
if (dst.resolveTexture.textureType == MTLTextureType3D)
{
dst.resolveDepthPlane = src.sliceOrDepth;
......@@ -208,7 +208,7 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src,
else
{
dst.texture = ToObjC(src.texture);
dst.level = src.level;
dst.level = src.level.get();
if (dst.texture.textureType == MTLTextureType3D)
{
dst.depthPlane = src.sliceOrDepth;
......@@ -691,7 +691,7 @@ void RenderPassAttachmentDesc::reset()
{
texture.reset();
implicitMSTexture.reset();
level = 0;
level = mtl::kZeroNativeMipLevel;
sliceOrDepth = 0;
loadAction = MTLLoadActionLoad;
storeAction = MTLStoreActionStore;
......
......@@ -32,27 +32,27 @@ NS_ASSUME_NONNULL_BEGIN
angle::Result InitializeTextureContents(const gl::Context *context,
const TextureRef &texture,
const Format &textureObjFormat,
const gl::ImageIndex &index);
const ImageNativeIndex &index);
// Same as above but using GPU clear operation instead of CPU.
// - channelsToInit parameter controls which channels will get their content initialized.
angle::Result InitializeTextureContentsGPU(const gl::Context *context,
const TextureRef &texture,
const Format &textureObjFormat,
const gl::ImageIndex &index,
const ImageNativeIndex &index,
MTLColorWriteMask channelsToInit);
// Same as above but for a depth/stencil texture.
angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *context,
const TextureRef &texture,
const Format &textureObjFormat,
const gl::ImageIndex &index);
const ImageNativeIndex &index);
// Unified texture's per slice/depth texel reading function
angle::Result ReadTexturePerSliceBytes(const gl::Context *context,
const TextureRef &texture,
size_t bytesPerRow,
const gl::Rectangle &fromRegion,
uint32_t mipLevel,
const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth,
uint8_t *dataOut);
......@@ -60,7 +60,7 @@ angle::Result ReadTexturePerSliceBytesToBuffer(const gl::Context *context,
const TextureRef &texture,
size_t bytesPerRow,
const gl::Rectangle &fromRegion,
uint32_t mipLevel,
const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth,
uint32_t dstOffset,
const BufferRef &dstBuffer);
......@@ -143,6 +143,9 @@ MTLClearColor EmulatedAlphaClearColor(MTLClearColor color, MTLColorWriteMask col
gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion);
MipmapNativeLevel GetNativeMipLevel(GLuint level, GLuint base);
GLuint GetGLMipLevel(const MipmapNativeLevel &nativeLevel, GLuint base);
NS_ASSUME_NONNULL_END
} // namespace mtl
} // namespace rx
......
......@@ -64,7 +64,7 @@ uint32_t GetDeviceVendorIdFromIOKit(id<MTLDevice> device)
}
#endif
void GetSliceAndDepth(const gl::ImageIndex &index, GLint *layer, GLint *startDepth)
void GetSliceAndDepth(const ImageNativeIndex &index, GLint *layer, GLint *startDepth)
{
*layer = *startDepth = 0;
if (!index.hasLayer())
......@@ -87,7 +87,7 @@ void GetSliceAndDepth(const gl::ImageIndex &index, GLint *layer, GLint *startDep
break;
}
}
GLint GetSliceOrDepth(const gl::ImageIndex &index)
GLint GetSliceOrDepth(const ImageNativeIndex &index)
{
GLint layer, startDepth;
GetSliceAndDepth(index, &layer, &startDepth);
......@@ -100,7 +100,7 @@ GLint GetSliceOrDepth(const gl::ImageIndex &index)
angle::Result InitializeTextureContents(const gl::Context *context,
const TextureRef &texture,
const Format &textureObjFormat,
const gl::ImageIndex &index)
const ImageNativeIndex &index)
{
ASSERT(texture && texture->valid());
// Only one slice can be initialized at a time.
......@@ -161,7 +161,7 @@ angle::Result InitializeTextureContents(const gl::Context *context,
mtlRowRegion.origin.y = r;
// Upload to texture
texture->replace2DRegion(contextMtl, mtlRowRegion, index.getLevelIndex(), layer,
texture->replace2DRegion(contextMtl, mtlRowRegion, index.getNativeLevel(), layer,
conversionRow.data(), dstRowPitch);
}
}
......@@ -178,17 +178,18 @@ angle::Result InitializeTextureContents(const gl::Context *context,
angle::Result InitializeTextureContentsGPU(const gl::Context *context,
const TextureRef &texture,
const Format &textureObjFormat,
const gl::ImageIndex &index,
const ImageNativeIndex &index,
MTLColorWriteMask channelsToInit)
{
// Only one slice can be initialized at a time.
ASSERT(!index.isLayered() || index.getType() == gl::TextureType::_3D);
if (index.isLayered() && index.getType() == gl::TextureType::_3D)
{
gl::ImageIndexIterator ite = index.getLayerIterator(texture->depth(index.getLevelIndex()));
ImageNativeIndexIterator ite =
index.getLayerIterator(texture->depth(index.getNativeLevel()));
while (ite.hasNext())
{
gl::ImageIndex depthLayerIndex = ite.next();
ImageNativeIndex depthLayerIndex = ite.next();
ANGLE_TRY(InitializeTextureContentsGPU(context, texture, textureObjFormat,
depthLayerIndex, MTLColorWriteMaskAll));
}
......@@ -207,7 +208,7 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context,
// Use clear render command
RenderTargetMtl tempRtt;
tempRtt.set(texture, index.getLevelIndex(), sliceOrDepth, textureObjFormat);
tempRtt.set(texture, index.getNativeLevel(), sliceOrDepth, textureObjFormat);
MTLClearColor blackColor = {};
if (!textureObjFormat.intendedAngleFormat().alphaBits)
......@@ -234,9 +235,9 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context,
ClearRectParams clearParams;
clearParams.clearColor = blackColor;
clearParams.dstTextureSize = texture->size();
clearParams.dstTextureSize = texture->sizeAt0();
clearParams.enabledBuffers.set(0);
clearParams.clearArea = gl::Rectangle(0, 0, texture->width(), texture->height());
clearParams.clearArea = gl::Rectangle(0, 0, texture->widthAt0(), texture->heightAt0());
ANGLE_TRY(
contextMtl->getDisplay()->getUtils().clearWithDraw(context, encoder, clearParams));
......@@ -252,8 +253,9 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context,
angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *context,
const TextureRef &texture,
const Format &textureObjFormat,
const gl::ImageIndex &index)
const ImageNativeIndex &index)
{
const MipmapNativeLevel &level = index.getNativeLevel();
// Use clear operation
ContextMtl *contextMtl = mtl::GetImpl(context);
const angle::Format &angleFormat = textureObjFormat.actualAngleFormat();
......@@ -266,7 +268,7 @@ angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *contex
if (angleFormat.depthBits)
{
rpDesc.depthAttachment.texture = texture;
rpDesc.depthAttachment.level = index.getLevelIndex();
rpDesc.depthAttachment.level = level;
rpDesc.depthAttachment.sliceOrDepth = layer;
rpDesc.depthAttachment.loadAction = MTLLoadActionClear;
rpDesc.depthAttachment.clearDepth = 1.0;
......@@ -274,7 +276,7 @@ angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *contex
if (angleFormat.stencilBits)
{
rpDesc.stencilAttachment.texture = texture;
rpDesc.stencilAttachment.level = index.getLevelIndex();
rpDesc.stencilAttachment.level = level;
rpDesc.stencilAttachment.sliceOrDepth = layer;
rpDesc.stencilAttachment.loadAction = MTLLoadActionClear;
}
......@@ -292,7 +294,7 @@ angle::Result ReadTexturePerSliceBytes(const gl::Context *context,
const TextureRef &texture,
size_t bytesPerRow,
const gl::Rectangle &fromRegion,
uint32_t mipLevel,
const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth,
uint8_t *dataOut)
{
......@@ -325,7 +327,7 @@ angle::Result ReadTexturePerSliceBytesToBuffer(const gl::Context *context,
const TextureRef &texture,
size_t bytesPerRow,
const gl::Rectangle &fromRegion,
uint32_t mipLevel,
const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth,
uint32_t dstOffset,
const BufferRef &dstBuffer)
......@@ -826,5 +828,16 @@ gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion)
static_cast<int>(mtlRegion.size.height), static_cast<int>(mtlRegion.size.depth));
}
MipmapNativeLevel GetNativeMipLevel(GLuint level, GLuint base)
{
ASSERT(level >= base);
return MipmapNativeLevel(level - base);
}
GLuint GetGLMipLevel(const MipmapNativeLevel &nativeLevel, GLuint base)
{
return nativeLevel.get() + base;
}
} // namespace mtl
} // namespace rx
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment