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 ...@@ -341,7 +341,7 @@ class ContextMtl : public ContextImpl, public mtl::Context
// Utilities to quickly create render command encoder to a specific texture: // Utilities to quickly create render command encoder to a specific texture:
// The previous content of texture will be loaded // The previous content of texture will be loaded
mtl::RenderCommandEncoder *getTextureRenderCommandEncoder(const mtl::TextureRef &textureTarget, 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 // The previous content of texture will be loaded if clearColor is not provided
mtl::RenderCommandEncoder *getRenderTargetCommandEncoderWithClear( mtl::RenderCommandEncoder *getRenderTargetCommandEncoderWithClear(
const RenderTargetMtl &renderTarget, const RenderTargetMtl &renderTarget,
......
...@@ -1285,14 +1285,14 @@ mtl::RenderCommandEncoder *ContextMtl::getRenderPassCommandEncoder(const mtl::Re ...@@ -1285,14 +1285,14 @@ mtl::RenderCommandEncoder *ContextMtl::getRenderPassCommandEncoder(const mtl::Re
// The previous content of texture will be loaded // The previous content of texture will be loaded
mtl::RenderCommandEncoder *ContextMtl::getTextureRenderCommandEncoder( mtl::RenderCommandEncoder *ContextMtl::getTextureRenderCommandEncoder(
const mtl::TextureRef &textureTarget, const mtl::TextureRef &textureTarget,
const gl::ImageIndex &index) const mtl::ImageNativeIndex &index)
{ {
ASSERT(textureTarget && textureTarget->valid()); ASSERT(textureTarget && textureTarget->valid());
mtl::RenderPassDesc rpDesc; mtl::RenderPassDesc rpDesc;
rpDesc.colorAttachments[0].texture = textureTarget; 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.colorAttachments[0].sliceOrDepth = index.hasLayer() ? index.getLayerIndex() : 0;
rpDesc.numColorAttachments = 1; rpDesc.numColorAttachments = 1;
rpDesc.sampleCount = textureTarget->samples(); rpDesc.sampleCount = textureTarget->samples();
...@@ -1898,8 +1898,9 @@ angle::Result ContextMtl::handleDirtyRenderPass(const gl::Context *context) ...@@ -1898,8 +1898,9 @@ angle::Result ContextMtl::handleDirtyRenderPass(const gl::Context *context)
getPixelFormat(angle::FormatID::R8G8B8A8_UNORM), getPixelFormat(angle::FormatID::R8G8B8A8_UNORM),
1, 1, 1, true, false, &mDummyXFBRenderTexture)); 1, 1, 1, true, false, &mDummyXFBRenderTexture));
} }
mtl::RenderCommandEncoder *encoder = mtl::RenderCommandEncoder *encoder = getTextureRenderCommandEncoder(
getTextureRenderCommandEncoder(mDummyXFBRenderTexture, gl::ImageIndex::Make2D(0)); mDummyXFBRenderTexture,
mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)));
encoder->setColorLoadAction(MTLLoadActionDontCare, MTLClearColor(), 0); encoder->setColorLoadAction(MTLLoadActionDontCare, MTLClearColor(), 0);
encoder->setColorStoreAction(MTLStoreActionDontCare); encoder->setColorStoreAction(MTLStoreActionDontCare);
......
...@@ -1053,9 +1053,8 @@ gl::Rectangle FramebufferMtl::getCorrectFlippedReadArea(const gl::Context *conte ...@@ -1053,9 +1053,8 @@ gl::Rectangle FramebufferMtl::getCorrectFlippedReadArea(const gl::Context *conte
gl::Rectangle flippedArea = glArea; gl::Rectangle flippedArea = glArea;
if (mFlipY) if (mFlipY)
{ {
flippedArea.y = flippedArea.y = readRT->getTexture()->height(readRT->getLevelIndex()) - flippedArea.y -
readRT->getTexture()->height(static_cast<uint32_t>(readRT->getLevelIndex())) - flippedArea.height;
flippedArea.y - flippedArea.height;
} }
return flippedArea; return flippedArea;
......
...@@ -61,16 +61,14 @@ angle::Result RenderbufferMtl::setStorageImpl(const gl::Context *context, ...@@ -61,16 +61,14 @@ angle::Result RenderbufferMtl::setStorageImpl(const gl::Context *context,
ANGLE_TRY(mtl::Texture::Make2DTexture(contextMtl, mFormat, width, height, 1, false, ANGLE_TRY(mtl::Texture::Make2DTexture(contextMtl, mFormat, width, height, 1, false,
mFormat.hasDepthAndStencilBits(), &mTexture)); 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, // For emulated channels that GL texture intends to not have,
// we need to initialize their content. // we need to initialize their content.
bool emulatedChannels = mtl::IsFormatEmulated(mFormat); bool emulatedChannels = mtl::IsFormatEmulated(mFormat);
if (emulatedChannels) if (emulatedChannels)
{ {
gl::ImageIndex index; auto index = mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0));
index = gl::ImageIndex::Make2D(0);
ANGLE_TRY(mtl::InitializeTextureContents(context, mTexture, mFormat, index)); ANGLE_TRY(mtl::InitializeTextureContents(context, mTexture, mFormat, index));
} }
...@@ -122,6 +120,7 @@ angle::Result RenderbufferMtl::getAttachmentRenderTarget(const gl::Context *cont ...@@ -122,6 +120,7 @@ angle::Result RenderbufferMtl::getAttachmentRenderTarget(const gl::Context *cont
angle::Result RenderbufferMtl::initializeContents(const gl::Context *context, angle::Result RenderbufferMtl::initializeContents(const gl::Context *context,
const gl::ImageIndex &imageIndex) 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 ...@@ -33,21 +33,21 @@ class RenderTargetMtl final : public FramebufferAttachmentRenderTarget
RenderTargetMtl(RenderTargetMtl &&other); RenderTargetMtl(RenderTargetMtl &&other);
void set(const mtl::TextureRef &texture, void set(const mtl::TextureRef &texture,
uint32_t level, const mtl::MipmapNativeLevel &level,
uint32_t layer,
const mtl::Format &format);
void set(const mtl::TextureRef &texture,
const mtl::TextureRef &implicitMSTexture,
uint32_t level,
uint32_t layer, uint32_t layer,
const mtl::Format &format); 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 setTexture(const mtl::TextureRef &texture);
void setImplicitMSTexture(const mtl::TextureRef &implicitMSTexture); void setImplicitMSTexture(const mtl::TextureRef &implicitMSTexture);
void reset(); void reset();
mtl::TextureRef getTexture() const { return mTexture.lock(); } mtl::TextureRef getTexture() const { return mTexture.lock(); }
mtl::TextureRef getImplicitMSTexture() const { return mImplicitMSTexture.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 getLayerIndex() const { return mLayerIndex; }
uint32_t getRenderSamples() const; uint32_t getRenderSamples() const;
const mtl::Format *getFormat() const { return mFormat; } const mtl::Format *getFormat() const { return mFormat; }
...@@ -57,9 +57,9 @@ class RenderTargetMtl final : public FramebufferAttachmentRenderTarget ...@@ -57,9 +57,9 @@ class RenderTargetMtl final : public FramebufferAttachmentRenderTarget
private: private:
mtl::TextureWeakRef mTexture; mtl::TextureWeakRef mTexture;
mtl::TextureWeakRef mImplicitMSTexture; mtl::TextureWeakRef mImplicitMSTexture;
uint32_t mLevelIndex = 0; mtl::MipmapNativeLevel mLevelIndex = mtl::kZeroNativeMipLevel;
uint32_t mLayerIndex = 0; uint32_t mLayerIndex = 0;
const mtl::Format *mFormat = nullptr; const mtl::Format *mFormat = nullptr;
}; };
} // namespace rx } // namespace rx
......
...@@ -26,18 +26,18 @@ RenderTargetMtl::RenderTargetMtl(RenderTargetMtl &&other) ...@@ -26,18 +26,18 @@ RenderTargetMtl::RenderTargetMtl(RenderTargetMtl &&other)
{} {}
void RenderTargetMtl::set(const mtl::TextureRef &texture, void RenderTargetMtl::set(const mtl::TextureRef &texture,
uint32_t level, const mtl::MipmapNativeLevel &level,
uint32_t layer, uint32_t layer,
const mtl::Format &format) const mtl::Format &format)
{ {
set(texture, nullptr, level, layer, format); setWithImplicitMSTexture(texture, nullptr, level, layer, format);
} }
void RenderTargetMtl::set(const mtl::TextureRef &texture, void RenderTargetMtl::setWithImplicitMSTexture(const mtl::TextureRef &texture,
const mtl::TextureRef &implicitMSTexture, const mtl::TextureRef &implicitMSTexture,
uint32_t level, const mtl::MipmapNativeLevel &level,
uint32_t layer, uint32_t layer,
const mtl::Format &format) const mtl::Format &format)
{ {
mTexture = texture; mTexture = texture;
mImplicitMSTexture = implicitMSTexture; mImplicitMSTexture = implicitMSTexture;
...@@ -60,7 +60,7 @@ void RenderTargetMtl::reset() ...@@ -60,7 +60,7 @@ void RenderTargetMtl::reset()
{ {
mTexture.reset(); mTexture.reset();
mImplicitMSTexture.reset(); mImplicitMSTexture.reset();
mLevelIndex = 0; mLevelIndex = mtl::kZeroNativeMipLevel;
mLayerIndex = 0; mLayerIndex = 0;
mFormat = nullptr; mFormat = nullptr;
} }
......
...@@ -397,7 +397,7 @@ EGLint SurfaceMtl::getWidth() const ...@@ -397,7 +397,7 @@ EGLint SurfaceMtl::getWidth() const
{ {
if (mColorTexture) if (mColorTexture)
{ {
return static_cast<EGLint>(mColorTexture->width()); return static_cast<EGLint>(mColorTexture->widthAt0());
} }
return 0; return 0;
} }
...@@ -406,7 +406,7 @@ EGLint SurfaceMtl::getHeight() const ...@@ -406,7 +406,7 @@ EGLint SurfaceMtl::getHeight() const
{ {
if (mColorTexture) if (mColorTexture)
{ {
return static_cast<EGLint>(mColorTexture->height()); return static_cast<EGLint>(mColorTexture->heightAt0());
} }
return 0; return 0;
} }
...@@ -488,7 +488,7 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context * ...@@ -488,7 +488,7 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context *
ASSERT(mColorTexture); ASSERT(mColorTexture);
if (mSamples > 1 && (!mMSColorTexture || mMSColorTexture->size() != size)) if (mSamples > 1 && (!mMSColorTexture || mMSColorTexture->sizeAt0() != size))
{ {
mAutoResolveMSColorTexture = mAutoResolveMSColorTexture =
contextMtl->getDisplay()->getFeatures().allowMultisampleStoreAndResolve.enabled; contextMtl->getDisplay()->getFeatures().allowMultisampleStoreAndResolve.enabled;
...@@ -507,15 +507,15 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context * ...@@ -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, ANGLE_TRY(CreateOrResizeTexture(context, mDepthFormat, size.width, size.height, mSamples,
/** renderTargetOnly */ false, &mDepthTexture)); /** 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) if (mUsePackedDepthStencil)
{ {
...@@ -528,7 +528,7 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context * ...@@ -528,7 +528,7 @@ angle::Result SurfaceMtl::ensureCompanionTexturesSizeCorrect(const gl::Context *
/** renderTargetOnly */ false, &mStencilTexture)); /** renderTargetOnly */ false, &mStencilTexture));
} }
mStencilRenderTarget.set(mStencilTexture, 0, 0, mStencilFormat); mStencilRenderTarget.set(mStencilTexture, mtl::kZeroNativeMipLevel, 0, mStencilFormat);
} }
return angle::Result::Continue; return angle::Result::Continue;
...@@ -542,7 +542,8 @@ angle::Result SurfaceMtl::resolveColorTextureIfNeeded(const gl::Context *context ...@@ -542,7 +542,8 @@ angle::Result SurfaceMtl::resolveColorTextureIfNeeded(const gl::Context *context
// Manually resolve texture // Manually resolve texture
ContextMtl *contextMtl = mtl::GetImpl(context); ContextMtl *contextMtl = mtl::GetImpl(context);
mColorManualResolveRenderTarget.set(mColorTexture, 0, 0, mColorFormat); mColorManualResolveRenderTarget.set(mColorTexture, mtl::kZeroNativeMipLevel, 0,
mColorFormat);
mtl::RenderCommandEncoder *encoder = mtl::RenderCommandEncoder *encoder =
contextMtl->getRenderTargetCommandEncoder(mColorManualResolveRenderTarget); contextMtl->getRenderTargetCommandEncoder(mColorManualResolveRenderTarget);
ANGLE_TRY(contextMtl->getDisplay()->getUtils().blitColorWithDraw(context, encoder, ANGLE_TRY(contextMtl->getDisplay()->getUtils().blitColorWithDraw(context, encoder,
...@@ -798,7 +799,8 @@ angle::Result WindowSurfaceMtl::obtainNextDrawable(const gl::Context *context) ...@@ -798,7 +799,8 @@ angle::Result WindowSurfaceMtl::obtainNextDrawable(const gl::Context *context)
{ {
mColorTexture = mtl::Texture::MakeFromMetal(mCurrentDrawable.get().texture); mColorTexture = mtl::Texture::MakeFromMetal(mCurrentDrawable.get().texture);
ASSERT(!mColorRenderTarget.getTexture()); ASSERT(!mColorRenderTarget.getTexture());
mColorRenderTarget.set(mColorTexture, mMSColorTexture, 0, 0, mColorFormat); mColorRenderTarget.setWithImplicitMSTexture(mColorTexture, mMSColorTexture,
mtl::kZeroNativeMipLevel, 0, mColorFormat);
} }
else else
{ {
...@@ -907,12 +909,12 @@ angle::Result OffscreenSurfaceMtl::getAttachmentRenderTarget( ...@@ -907,12 +909,12 @@ angle::Result OffscreenSurfaceMtl::getAttachmentRenderTarget(
angle::Result OffscreenSurfaceMtl::ensureTexturesSizeCorrect(const gl::Context *context) 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, ANGLE_TRY(CreateOrResizeTexture(context, mColorFormat, mSize.width, mSize.height, 1,
/** renderTargetOnly */ false, &mColorTexture)); /** renderTargetOnly */ false, &mColorTexture));
mColorRenderTarget.set(mColorTexture, 0, 0, mColorFormat); mColorRenderTarget.set(mColorTexture, mtl::kZeroNativeMipLevel, 0, mColorFormat);
} }
return ensureCompanionTexturesSizeCorrect(context, mSize); return ensureCompanionTexturesSizeCorrect(context, mSize);
...@@ -1023,16 +1025,17 @@ angle::Result IOSurfaceSurfaceMtl::ensureColorTextureCreated(const gl::Context * ...@@ -1023,16 +1025,17 @@ angle::Result IOSurfaceSurfaceMtl::ensureColorTextureCreated(const gl::Context *
mColorTexture = mtl::Texture::MakeFromMetal([texture ANGLE_MTL_AUTORELEASE]); 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) if (kIOSurfaceFormats[mIOSurfaceFormatIdx].internalFormat == GL_RGB)
{ {
// This format has emulated alpha channel. Initialize texture's alpha channel to 1.0. // This format has emulated alpha channel. Initialize texture's alpha channel to 1.0.
const mtl::Format &rgbClearFormat = const mtl::Format &rgbClearFormat =
contextMtl->getPixelFormat(angle::FormatID::R8G8B8_UNORM); contextMtl->getPixelFormat(angle::FormatID::R8G8B8_UNORM);
ANGLE_TRY(mtl::InitializeTextureContentsGPU(context, mColorTexture, rgbClearFormat, ANGLE_TRY(mtl::InitializeTextureContentsGPU(
gl::ImageIndex::Make2D(0), context, mColorTexture, rgbClearFormat,
MTLColorWriteMaskAlpha)); mtl::ImageNativeIndex::FromBaseZeroGLIndex(gl::ImageIndex::Make2D(0)),
MTLColorWriteMaskAlpha));
// Disable subsequent rendering to alpha channel. // Disable subsequent rendering to alpha channel.
mColorTexture->setColorWritableMask(MTLColorWriteMaskAll & (~MTLColorWriteMaskAlpha)); mColorTexture->setColorWritableMask(MTLColorWriteMaskAll & (~MTLColorWriteMaskAlpha));
......
...@@ -180,12 +180,13 @@ class TextureMtl : public TextureImpl ...@@ -180,12 +180,13 @@ class TextureMtl : public TextureImpl
angle::Result ensureImageCreated(const gl::Context *context, const gl::ImageIndex &index); angle::Result ensureImageCreated(const gl::Context *context, const gl::ImageIndex &index);
// Ensure all image views at all faces/levels are retained. // Ensure all image views at all faces/levels are retained.
void retainImageDefinitions(); void retainImageDefinitions();
mtl::TextureRef createImageViewFromNativeTexture(GLuint cubeFaceOrZero, GLuint nativeLevel); mtl::TextureRef createImageViewFromNativeTexture(GLuint cubeFaceOrZero,
const mtl::MipmapNativeLevel &nativeLevel);
angle::Result ensureNativeLevelViewsCreated(); angle::Result ensureNativeLevelViewsCreated();
angle::Result checkForEmulatedChannels(const gl::Context *context, angle::Result checkForEmulatedChannels(const gl::Context *context,
const mtl::Format &mtlFormat, const mtl::Format &mtlFormat,
const mtl::TextureRef &texture); 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); mtl::TextureRef &getImage(const gl::ImageIndex &imageIndex);
ImageDefinitionMtl &getImageDefinition(const gl::ImageIndex &imageIndex); ImageDefinitionMtl &getImageDefinition(const gl::ImageIndex &imageIndex);
RenderTargetMtl &getRenderTarget(const gl::ImageIndex &imageIndex); RenderTargetMtl &getRenderTarget(const gl::ImageIndex &imageIndex);
...@@ -255,7 +256,7 @@ class TextureMtl : public TextureImpl ...@@ -255,7 +256,7 @@ class TextureMtl : public TextureImpl
const gl::ImageIndex &index, const gl::ImageIndex &index,
const gl::Offset &destOffset, const gl::Offset &destOffset,
const gl::InternalFormat &internalFormat, const gl::InternalFormat &internalFormat,
uint32_t sourceNativeLevel, const mtl::MipmapNativeLevel &sourceNativeLevel,
const gl::Box &sourceBox, const gl::Box &sourceBox,
const angle::Format &sourceAngleFormat, const angle::Format &sourceAngleFormat,
bool unpackFlipY, bool unpackFlipY,
...@@ -267,7 +268,7 @@ class TextureMtl : public TextureImpl ...@@ -267,7 +268,7 @@ class TextureMtl : public TextureImpl
const gl::ImageIndex &index, const gl::ImageIndex &index,
const gl::Offset &destOffset, const gl::Offset &destOffset,
const gl::InternalFormat &internalFormat, const gl::InternalFormat &internalFormat,
uint32_t sourceNativeLevel, const mtl::MipmapNativeLevel &sourceNativeLevel,
const gl::Box &sourceBox, const gl::Box &sourceBox,
const angle::Format &sourceAngleFormat, const angle::Format &sourceAngleFormat,
bool unpackFlipY, bool unpackFlipY,
...@@ -331,7 +332,7 @@ class TextureMtl : public TextureImpl ...@@ -331,7 +332,7 @@ class TextureMtl : public TextureImpl
std::map<int, gl::TexLevelArray<RenderTargetMtl>> mPerLayerRenderTargets; std::map<int, gl::TexLevelArray<RenderTargetMtl>> mPerLayerRenderTargets;
// Mipmap views are indexed by native level (ignored base level): // Mipmap views are indexed by native level (ignored base level):
gl::TexLevelArray<mtl::TextureRef> mNativeLevelViews; mtl::NativeTexLevelArray mNativeLevelViews;
bool mIsPow2 = false; bool mIsPow2 = false;
}; };
......
...@@ -240,7 +240,7 @@ angle::Result UploadDepthStencilTextureContentsWithStagingBuffer( ...@@ -240,7 +240,7 @@ angle::Result UploadDepthStencilTextureContentsWithStagingBuffer(
ContextMtl *contextMtl, ContextMtl *contextMtl,
const angle::Format &textureAngleFormat, const angle::Format &textureAngleFormat,
MTLRegion region, MTLRegion region,
uint32_t mipmapLevel, const mtl::MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
const uint8_t *data, const uint8_t *data,
size_t bytesPerRow, size_t bytesPerRow,
...@@ -279,7 +279,7 @@ angle::Result UploadPackedDepthStencilTextureContentsWithStagingBuffer( ...@@ -279,7 +279,7 @@ angle::Result UploadPackedDepthStencilTextureContentsWithStagingBuffer(
ContextMtl *contextMtl, ContextMtl *contextMtl,
const angle::Format &textureAngleFormat, const angle::Format &textureAngleFormat,
MTLRegion region, MTLRegion region,
uint32_t mipmapLevel, const mtl::MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
const uint8_t *data, const uint8_t *data,
size_t bytesPerRow, size_t bytesPerRow,
...@@ -351,7 +351,7 @@ angle::Result UploadPackedDepthStencilTextureContentsWithStagingBuffer( ...@@ -351,7 +351,7 @@ angle::Result UploadPackedDepthStencilTextureContentsWithStagingBuffer(
angle::Result UploadTextureContents(const gl::Context *context, angle::Result UploadTextureContents(const gl::Context *context,
const angle::Format &textureAngleFormat, const angle::Format &textureAngleFormat,
const MTLRegion &region, const MTLRegion &region,
uint32_t mipmapLevel, const mtl::MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
const uint8_t *data, const uint8_t *data,
size_t bytesPerRow, size_t bytesPerRow,
...@@ -506,23 +506,24 @@ angle::Result TextureMtl::createNativeTexture(const gl::Context *context, ...@@ -506,23 +506,24 @@ angle::Result TextureMtl::createNativeTexture(const gl::Context *context,
mtl::BlitCommandEncoder *encoder = nullptr; mtl::BlitCommandEncoder *encoder = nullptr;
for (int face = 0; face < numCubeFaces; ++face) for (int face = 0; face < numCubeFaces; ++face)
{ {
for (GLuint mip = 0; mip < mips; ++mip) for (mtl::MipmapNativeLevel actualMip = mtl::kZeroNativeMipLevel; actualMip.get() < mips;
++actualMip)
{ {
GLuint imageMipLevel = mip + mState.getEffectiveBaseLevel(); GLuint imageMipLevel = mtl::GetGLMipLevel(actualMip, mState.getEffectiveBaseLevel());
mtl::TextureRef &imageToTransfer = mTexImageDefs[face][imageMipLevel].image; mtl::TextureRef &imageToTransfer = mTexImageDefs[face][imageMipLevel].image;
// Only transfer if this mip & slice image has been defined and in correct size & // Only transfer if this mip & slice image has been defined and in correct size &
// format. // format.
gl::Extents actualMipSize = mNativeTexture->size(mip); gl::Extents actualMipSize = mNativeTexture->size(actualMip);
if (imageToTransfer && imageToTransfer->size() == actualMipSize && if (imageToTransfer && imageToTransfer->sizeAt0() == actualMipSize &&
imageToTransfer->pixelFormat() == mNativeTexture->pixelFormat()) imageToTransfer->pixelFormat() == mNativeTexture->pixelFormat())
{ {
if (!encoder) if (!encoder)
{ {
encoder = contextMtl->getBlitCommandEncoder(); encoder = contextMtl->getBlitCommandEncoder();
} }
encoder->copyTexture(imageToTransfer, 0, 0, mNativeTexture, face, mip, encoder->copyTexture(imageToTransfer, 0, mtl::kZeroNativeMipLevel, mNativeTexture,
imageToTransfer->arrayLength(), 1); face, actualMip, imageToTransfer->arrayLength(), 1);
} }
imageToTransfer = nullptr; imageToTransfer = nullptr;
...@@ -585,7 +586,8 @@ angle::Result TextureMtl::ensureNativeLevelViewsCreated() ...@@ -585,7 +586,8 @@ angle::Result TextureMtl::ensureNativeLevelViewsCreated()
{ {
ASSERT(mNativeTexture); ASSERT(mNativeTexture);
const GLuint baseLevel = mState.getEffectiveBaseLevel(); const GLuint baseLevel = mState.getEffectiveBaseLevel();
for (uint32_t mip = 0; mip < mNativeTexture->mipmapLevels(); ++mip) for (mtl::MipmapNativeLevel mip = mtl::kZeroNativeMipLevel;
mip.get() < mNativeTexture->mipmapLevels(); ++mip)
{ {
if (mNativeLevelViews[mip]) if (mNativeLevelViews[mip])
{ {
...@@ -593,10 +595,10 @@ angle::Result TextureMtl::ensureNativeLevelViewsCreated() ...@@ -593,10 +595,10 @@ angle::Result TextureMtl::ensureNativeLevelViewsCreated()
} }
if (mNativeTexture->textureType() != MTLTextureTypeCube && if (mNativeTexture->textureType() != MTLTextureTypeCube &&
mTexImageDefs[0][mip + baseLevel].image) mTexImageDefs[0][mtl::GetGLMipLevel(mip, baseLevel)].image)
{ {
// Reuse texture image view. // Reuse texture image view.
mNativeLevelViews[mip] = mTexImageDefs[0][mip + baseLevel].image; mNativeLevelViews[mip] = mTexImageDefs[0][mtl::GetGLMipLevel(mip, baseLevel)].image;
} }
else else
{ {
...@@ -606,8 +608,9 @@ angle::Result TextureMtl::ensureNativeLevelViewsCreated() ...@@ -606,8 +608,9 @@ angle::Result TextureMtl::ensureNativeLevelViewsCreated()
return angle::Result::Continue; return angle::Result::Continue;
} }
mtl::TextureRef TextureMtl::createImageViewFromNativeTexture(GLuint cubeFaceOrZero, mtl::TextureRef TextureMtl::createImageViewFromNativeTexture(
GLuint nativeLevel) GLuint cubeFaceOrZero,
const mtl::MipmapNativeLevel &nativeLevel)
{ {
mtl::TextureRef image; mtl::TextureRef image;
if (mNativeTexture->textureType() == MTLTextureTypeCube) if (mNativeTexture->textureType() == MTLTextureTypeCube)
...@@ -652,9 +655,9 @@ void TextureMtl::retainImageDefinitions() ...@@ -652,9 +655,9 @@ void TextureMtl::retainImageDefinitions()
// Create image view per cube face, per mip level // Create image view per cube face, per mip level
for (int face = 0; face < numCubeFaces; ++face) for (int face = 0; face < numCubeFaces; ++face)
{ {
for (GLuint mip = 0; mip < mips; ++mip) for (mtl::MipmapNativeLevel mip = mtl::kZeroNativeMipLevel; mip.get() < mips; ++mip)
{ {
GLuint imageMipLevel = mip + mState.getEffectiveBaseLevel(); GLuint imageMipLevel = mtl::GetGLMipLevel(mip, mState.getEffectiveBaseLevel());
ImageDefinitionMtl &imageDef = mTexImageDefs[face][imageMipLevel]; ImageDefinitionMtl &imageDef = mTexImageDefs[face][imageMipLevel];
if (imageDef.image) if (imageDef.image)
{ {
...@@ -672,11 +675,10 @@ bool TextureMtl::isIndexWithinMinMaxLevels(const gl::ImageIndex &imageIndex) con ...@@ -672,11 +675,10 @@ bool TextureMtl::isIndexWithinMinMaxLevels(const gl::ImageIndex &imageIndex) con
imageIndex.getLevelIndex() <= static_cast<GLint>(mState.getEffectiveMaxLevel()); imageIndex.getLevelIndex() <= static_cast<GLint>(mState.getEffectiveMaxLevel());
} }
int TextureMtl::getNativeLevel(const gl::ImageIndex &imageIndex) const mtl::MipmapNativeLevel TextureMtl::getNativeLevel(const gl::ImageIndex &imageIndex) const
{ {
int baseLevel = mState.getEffectiveBaseLevel(); int baseLevel = mState.getEffectiveBaseLevel();
int adjustedLevel = imageIndex.getLevelIndex() - baseLevel; return mtl::GetNativeMipLevel(imageIndex.getLevelIndex(), baseLevel);
return adjustedLevel;
} }
mtl::TextureRef &TextureMtl::getImage(const gl::ImageIndex &imageIndex) mtl::TextureRef &TextureMtl::getImage(const gl::ImageIndex &imageIndex)
...@@ -700,8 +702,8 @@ ImageDefinitionMtl &TextureMtl::getImageDefinition(const gl::ImageIndex &imageIn ...@@ -700,8 +702,8 @@ ImageDefinitionMtl &TextureMtl::getImageDefinition(const gl::ImageIndex &imageIn
return imageDef; return imageDef;
} }
uint32_t nativeLevel = getNativeLevel(imageIndex); mtl::MipmapNativeLevel nativeLevel = getNativeLevel(imageIndex);
if (nativeLevel >= mNativeTexture->mipmapLevels()) if (nativeLevel.get() >= mNativeTexture->mipmapLevels())
{ {
// Image outside native texture's mip levels is skipped. // Image outside native texture's mip levels is skipped.
return imageDef; return imageDef;
...@@ -729,11 +731,11 @@ RenderTargetMtl &TextureMtl::getRenderTarget(const gl::ImageIndex &imageIndex) ...@@ -729,11 +731,11 @@ RenderTargetMtl &TextureMtl::getRenderTarget(const gl::ImageIndex &imageIndex)
if (imageIndex.getType() == gl::TextureType::CubeMap) if (imageIndex.getType() == gl::TextureType::CubeMap)
{ {
// Cube map is special, the image is already the view of its layer // Cube map is special, the image is already the view of its layer
rtt.set(image, 0, 0, mFormat); rtt.set(image, mtl::kZeroNativeMipLevel, 0, mFormat);
} }
else else
{ {
rtt.set(image, 0, layer, mFormat); rtt.set(image, mtl::kZeroNativeMipLevel, layer, mFormat);
} }
} }
} }
...@@ -1002,12 +1004,13 @@ angle::Result TextureMtl::generateMipmapCPU(const gl::Context *context) ...@@ -1002,12 +1004,13 @@ angle::Result TextureMtl::generateMipmapCPU(const gl::Context *context)
for (uint32_t slice = 0; slice < mSlices; ++slice) for (uint32_t slice = 0; slice < mSlices; ++slice)
{ {
int maxMipLevel = static_cast<int>(mNativeTexture->mipmapLevels()) - 1; mtl::MipmapNativeLevel maxMipLevel =
int firstLevel = 0; mtl::GetNativeMipLevel(mNativeTexture->mipmapLevels() - 1, 0);
const mtl::MipmapNativeLevel firstLevel = mtl::kZeroNativeMipLevel;
uint32_t prevLevelWidth = mNativeTexture->width(); uint32_t prevLevelWidth = mNativeTexture->widthAt0();
uint32_t prevLevelHeight = mNativeTexture->height(); uint32_t prevLevelHeight = mNativeTexture->heightAt0();
uint32_t prevLevelDepth = mNativeTexture->depth(); uint32_t prevLevelDepth = mNativeTexture->depthAt0();
size_t prevLevelRowPitch = angleFormat.pixelBytes * prevLevelWidth; size_t prevLevelRowPitch = angleFormat.pixelBytes * prevLevelWidth;
size_t prevLevelDepthPitch = prevLevelRowPitch * prevLevelHeight; size_t prevLevelDepthPitch = prevLevelRowPitch * prevLevelHeight;
std::unique_ptr<uint8_t[]> prevLevelData(new (std::nothrow) std::unique_ptr<uint8_t[]> prevLevelData(new (std::nothrow)
...@@ -1021,7 +1024,7 @@ angle::Result TextureMtl::generateMipmapCPU(const gl::Context *context) ...@@ -1021,7 +1024,7 @@ angle::Result TextureMtl::generateMipmapCPU(const gl::Context *context)
MTLRegionMake3D(0, 0, 0, prevLevelWidth, prevLevelHeight, prevLevelDepth), firstLevel, MTLRegionMake3D(0, 0, 0, prevLevelWidth, prevLevelHeight, prevLevelDepth), firstLevel,
slice, prevLevelData.get()); slice, prevLevelData.get());
for (int mip = firstLevel + 1; mip <= maxMipLevel; ++mip) for (mtl::MipmapNativeLevel mip = firstLevel + 1; mip <= maxMipLevel; ++mip)
{ {
uint32_t dstWidth = mNativeTexture->width(mip); uint32_t dstWidth = mNativeTexture->width(mip);
uint32_t dstHeight = mNativeTexture->height(mip); uint32_t dstHeight = mNativeTexture->height(mip);
...@@ -1075,7 +1078,7 @@ angle::Result TextureMtl::bindTexImage(const gl::Context *context, egl::Surface ...@@ -1075,7 +1078,7 @@ angle::Result TextureMtl::bindTexImage(const gl::Context *context, egl::Surface
auto pBuffer = GetImplAs<OffscreenSurfaceMtl>(surface); auto pBuffer = GetImplAs<OffscreenSurfaceMtl>(surface);
mNativeTexture = pBuffer->getColorTexture(); mNativeTexture = pBuffer->getColorTexture();
mFormat = pBuffer->getColorFormat(); mFormat = pBuffer->getColorFormat();
gl::Extents size = mNativeTexture->size(); gl::Extents size = mNativeTexture->sizeAt0();
mIsPow2 = gl::isPow2(size.width) && gl::isPow2(size.height) && gl::isPow2(size.depth); mIsPow2 = gl::isPow2(size.width) && gl::isPow2(size.height) && gl::isPow2(size.depth);
ANGLE_TRY(ensureSamplerStateCreated(context)); ANGLE_TRY(ensureSamplerStateCreated(context));
...@@ -1151,8 +1154,8 @@ angle::Result TextureMtl::redefineImage(const gl::Context *context, ...@@ -1151,8 +1154,8 @@ angle::Result TextureMtl::redefineImage(const gl::Context *context,
if (isIndexWithinMinMaxLevels(index) && mNativeTexture && mNativeTexture->valid()) if (isIndexWithinMinMaxLevels(index) && mNativeTexture && mNativeTexture->valid())
{ {
imageWithinLevelRange = true; imageWithinLevelRange = true;
int nativeLevel = getNativeLevel(index); mtl::MipmapNativeLevel nativeLevel = getNativeLevel(index);
// Calculate the expected size for the index we are defining. If the size is different // Calculate the expected size for the index we are defining. If the size is different
// from the given size, or the format is different, we are redefining the image so we // from the given size, or the format is different, we are redefining the image so we
// must release it. // must release it.
...@@ -1181,7 +1184,7 @@ angle::Result TextureMtl::redefineImage(const gl::Context *context, ...@@ -1181,7 +1184,7 @@ angle::Result TextureMtl::redefineImage(const gl::Context *context,
{ {
ASSERT(imageDef.image->textureType() == ASSERT(imageDef.image->textureType() ==
mtl::GetTextureType(GetTextureImageType(index.getType())) && mtl::GetTextureType(GetTextureImageType(index.getType())) &&
imageDef.formatID == mFormat.intendedFormatId && imageDef.image->size() == size); imageDef.formatID == mFormat.intendedFormatId && imageDef.image->sizeAt0() == size);
} }
else else
{ {
...@@ -1311,7 +1314,7 @@ angle::Result TextureMtl::setSubImageImpl(const gl::Context *context, ...@@ -1311,7 +1314,7 @@ angle::Result TextureMtl::setSubImageImpl(const gl::Context *context,
{ {
// area must be the whole mip level // area must be the whole mip level
sourceRowPitch = 0; sourceRowPitch = 0;
gl::Extents size = image->size(); gl::Extents size = image->sizeAt0();
if (area.x != 0 || area.y != 0 || area.width != size.width || area.height != size.height) if (area.x != 0 || area.y != 0 || area.width != size.width || area.height != size.height)
{ {
ANGLE_MTL_CHECK(contextMtl, false, GL_INVALID_OPERATION); ANGLE_MTL_CHECK(contextMtl, false, GL_INVALID_OPERATION);
...@@ -1374,8 +1377,9 @@ angle::Result TextureMtl::setPerSliceSubImage(const gl::Context *context, ...@@ -1374,8 +1377,9 @@ angle::Result TextureMtl::setPerSliceSubImage(const gl::Context *context,
// to split its depth & stencil data and copy separately. // to split its depth & stencil data and copy separately.
const uint8_t *clientData = unpackBufferMtl->getClientShadowCopyData(contextMtl); const uint8_t *clientData = unpackBufferMtl->getClientShadowCopyData(contextMtl);
clientData += offset; clientData += offset;
ANGLE_TRY(UploadTextureContents(context, mFormat.actualAngleFormat(), mtlArea, 0, slice, ANGLE_TRY(UploadTextureContents(context, mFormat.actualAngleFormat(), mtlArea,
clientData, pixelsRowPitch, pixelsDepthPitch, image)); mtl::kZeroNativeMipLevel, slice, clientData,
pixelsRowPitch, pixelsDepthPitch, image));
} }
else else
{ {
...@@ -1383,15 +1387,16 @@ angle::Result TextureMtl::setPerSliceSubImage(const gl::Context *context, ...@@ -1383,15 +1387,16 @@ angle::Result TextureMtl::setPerSliceSubImage(const gl::Context *context,
mtl::BlitCommandEncoder *blitEncoder = contextMtl->getBlitCommandEncoder(); mtl::BlitCommandEncoder *blitEncoder = contextMtl->getBlitCommandEncoder();
blitEncoder->copyBufferToTexture( blitEncoder->copyBufferToTexture(
unpackBufferMtl->getCurrentBuffer(), offset, pixelsRowPitch, pixelsDepthPitch, unpackBufferMtl->getCurrentBuffer(), offset, pixelsRowPitch, pixelsDepthPitch,
mtlArea.size, image, slice, 0, mtlArea.origin, mtlArea.size, image, slice, mtl::kZeroNativeMipLevel, mtlArea.origin,
mFormat.isPVRTC() ? mtl::kBlitOptionRowLinearPVRTC : MTLBlitOptionNone); mFormat.isPVRTC() ? mtl::kBlitOptionRowLinearPVRTC : MTLBlitOptionNone);
} }
} }
else else
{ {
// Upload texture data directly // Upload texture data directly
ANGLE_TRY(UploadTextureContents(context, mFormat.actualAngleFormat(), mtlArea, 0, slice, ANGLE_TRY(UploadTextureContents(context, mFormat.actualAngleFormat(), mtlArea,
pixels, pixelsRowPitch, pixelsDepthPitch, image)); mtl::kZeroNativeMipLevel, slice, pixels, pixelsRowPitch,
pixelsDepthPitch, image));
} }
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -1481,8 +1486,8 @@ angle::Result TextureMtl::convertAndSetPerSliceSubImage(const gl::Context *conte ...@@ -1481,8 +1486,8 @@ angle::Result TextureMtl::convertAndSetPerSliceSubImage(const gl::Context *conte
pixelsDepthPitch, decompressBuf.data(), dstRowPitch, dstDepthPitch); pixelsDepthPitch, decompressBuf.data(), dstRowPitch, dstDepthPitch);
// Upload to texture // Upload to texture
ANGLE_TRY(UploadTextureContents(context, dstFormat, mtlArea, 0, slice, ANGLE_TRY(UploadTextureContents(context, dstFormat, mtlArea, mtl::kZeroNativeMipLevel,
decompressBuf.data(), dstRowPitch, dstDepthPitch, slice, decompressBuf.data(), dstRowPitch, dstDepthPitch,
image)); image));
} // if (mFormat.intendedAngleFormat().isBlock) } // if (mFormat.intendedAngleFormat().isBlock)
else else
...@@ -1525,7 +1530,8 @@ angle::Result TextureMtl::convertAndSetPerSliceSubImage(const gl::Context *conte ...@@ -1525,7 +1530,8 @@ angle::Result TextureMtl::convertAndSetPerSliceSubImage(const gl::Context *conte
} }
// Upload to texture // Upload to texture
ANGLE_TRY(UploadTextureContents(context, dstFormat, mtlRow, 0, slice, ANGLE_TRY(UploadTextureContents(context, dstFormat, mtlRow,
mtl::kZeroNativeMipLevel, slice,
conversionRow.data(), dstRowPitch, 0, image)); conversionRow.data(), dstRowPitch, 0, image));
} }
} }
...@@ -1552,7 +1558,8 @@ angle::Result TextureMtl::checkForEmulatedChannels(const gl::Context *context, ...@@ -1552,7 +1558,8 @@ angle::Result TextureMtl::checkForEmulatedChannels(const gl::Context *context,
{ {
for (uint32_t mip = 0; mip < mipmaps; ++mip) for (uint32_t mip = 0; mip < mipmaps; ++mip)
{ {
gl::ImageIndex index = GetSliceMipIndex(texture, layer, mip); auto index = mtl::ImageNativeIndex::FromBaseZeroGLIndex(
GetSliceMipIndex(texture, layer, mip));
ANGLE_TRY(mtl::InitializeTextureContents(context, texture, mtlFormat, index)); ANGLE_TRY(mtl::InitializeTextureContents(context, texture, mtlFormat, index));
} }
...@@ -1604,7 +1611,9 @@ angle::Result TextureMtl::initializeContents(const gl::Context *context, ...@@ -1604,7 +1611,9 @@ angle::Result TextureMtl::initializeContents(const gl::Context *context,
ImageDefinitionMtl &imageDef = getImageDefinition(index); ImageDefinitionMtl &imageDef = getImageDefinition(index);
const mtl::TextureRef &image = imageDef.image; const mtl::TextureRef &image = imageDef.image;
const mtl::Format &format = contextMtl->getPixelFormat(imageDef.formatID); const mtl::Format &format = contextMtl->getPixelFormat(imageDef.formatID);
return mtl::InitializeTextureContents(context, image, format, GetZeroLevelIndex(image)); return mtl::InitializeTextureContents(
context, image, format,
mtl::ImageNativeIndex::FromBaseZeroGLIndex(GetZeroLevelIndex(image)));
} }
angle::Result TextureMtl::copySubImageImpl(const gl::Context *context, angle::Result TextureMtl::copySubImageImpl(const gl::Context *context,
...@@ -1741,8 +1750,8 @@ angle::Result TextureMtl::copySubImageCPU(const gl::Context *context, ...@@ -1741,8 +1750,8 @@ angle::Result TextureMtl::copySubImageCPU(const gl::Context *context,
conversionRow.data())); conversionRow.data()));
// Upload to texture // Upload to texture
ANGLE_TRY(UploadTextureContents(context, dstFormat, mtlDstRowArea, 0, dstSlice, ANGLE_TRY(UploadTextureContents(context, dstFormat, mtlDstRowArea, mtl::kZeroNativeMipLevel,
conversionRow.data(), dstRowPitch, 0, image)); dstSlice, conversionRow.data(), dstRowPitch, 0, image));
} }
return angle::Result::Continue; return angle::Result::Continue;
...@@ -1778,20 +1787,21 @@ angle::Result TextureMtl::copySubTextureImpl(const gl::Context *context, ...@@ -1778,20 +1787,21 @@ angle::Result TextureMtl::copySubTextureImpl(const gl::Context *context,
if (!mFormat.getCaps().isRenderable()) if (!mFormat.getCaps().isRenderable())
{ {
return copySubTextureCPU(context, index, destOffset, internalFormat, 0, sourceBox, return copySubTextureCPU(context, index, destOffset, internalFormat,
sourceAngleFormat, unpackFlipY, unpackPremultiplyAlpha, mtl::kZeroNativeMipLevel, sourceBox, sourceAngleFormat,
unpackUnmultiplyAlpha, sourceImage); unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha,
sourceImage);
} }
return copySubTextureWithDraw(context, index, destOffset, internalFormat, 0, sourceBox, return copySubTextureWithDraw(
sourceAngleFormat, unpackFlipY, unpackPremultiplyAlpha, context, index, destOffset, internalFormat, mtl::kZeroNativeMipLevel, sourceBox,
unpackUnmultiplyAlpha, sourceImage); sourceAngleFormat, unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha, sourceImage);
} }
angle::Result TextureMtl::copySubTextureWithDraw(const gl::Context *context, angle::Result TextureMtl::copySubTextureWithDraw(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
const gl::Offset &destOffset, const gl::Offset &destOffset,
const gl::InternalFormat &internalFormat, const gl::InternalFormat &internalFormat,
uint32_t sourceNativeLevel, const mtl::MipmapNativeLevel &sourceNativeLevel,
const gl::Box &sourceBox, const gl::Box &sourceBox,
const angle::Format &sourceAngleFormat, const angle::Format &sourceAngleFormat,
bool unpackFlipY, bool unpackFlipY,
...@@ -1810,11 +1820,11 @@ angle::Result TextureMtl::copySubTextureWithDraw(const gl::Context *context, ...@@ -1810,11 +1820,11 @@ angle::Result TextureMtl::copySubTextureWithDraw(const gl::Context *context,
image = image->getLinearColorView(); image = image->getLinearColorView();
} }
mtl::RenderCommandEncoder *cmdEncoder = mtl::RenderCommandEncoder *cmdEncoder = contextMtl->getTextureRenderCommandEncoder(
contextMtl->getTextureRenderCommandEncoder(image, GetZeroLevelIndex(image)); image, mtl::ImageNativeIndex::FromBaseZeroGLIndex(GetZeroLevelIndex(image)));
mtl::ColorBlitParams blitParams; mtl::ColorBlitParams blitParams;
blitParams.dstTextureSize = image->size(); blitParams.dstTextureSize = image->sizeAt0();
blitParams.dstRect = blitParams.dstRect =
gl::Rectangle(destOffset.x, destOffset.y, sourceBox.width, sourceBox.height); gl::Rectangle(destOffset.x, destOffset.y, sourceBox.width, sourceBox.height);
blitParams.dstScissorRect = blitParams.dstRect; blitParams.dstScissorRect = blitParams.dstRect;
...@@ -1838,7 +1848,7 @@ angle::Result TextureMtl::copySubTextureCPU(const gl::Context *context, ...@@ -1838,7 +1848,7 @@ angle::Result TextureMtl::copySubTextureCPU(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
const gl::Offset &destOffset, const gl::Offset &destOffset,
const gl::InternalFormat &internalFormat, const gl::InternalFormat &internalFormat,
uint32_t sourceNativeLevel, const mtl::MipmapNativeLevel &sourceNativeLevel,
const gl::Box &sourceBox, const gl::Box &sourceBox,
const angle::Format &sourceAngleFormat, const angle::Format &sourceAngleFormat,
bool unpackFlipY, bool unpackFlipY,
...@@ -1878,8 +1888,8 @@ angle::Result TextureMtl::copySubTextureCPU(const gl::Context *context, ...@@ -1878,8 +1888,8 @@ angle::Result TextureMtl::copySubTextureCPU(const gl::Context *context,
unpackUnmultiplyAlpha); unpackUnmultiplyAlpha);
// Upload to texture // Upload to texture
ANGLE_TRY(UploadTextureContents(context, dstAngleFormat, mtlDstArea, 0, 0, conversionDst.data(), ANGLE_TRY(UploadTextureContents(context, dstAngleFormat, mtlDstArea, mtl::kZeroNativeMipLevel,
convRowPitch, 0, image)); 0, conversionDst.data(), convRowPitch, 0, image));
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -519,13 +519,13 @@ class BlitCommandEncoder final : public CommandEncoder ...@@ -519,13 +519,13 @@ class BlitCommandEncoder final : public CommandEncoder
MTLSize srcSize, MTLSize srcSize,
const TextureRef &dst, const TextureRef &dst,
uint32_t dstSlice, uint32_t dstSlice,
uint32_t dstLevel, MipmapNativeLevel dstLevel,
MTLOrigin dstOrigin, MTLOrigin dstOrigin,
MTLBlitOption blitOption); MTLBlitOption blitOption);
BlitCommandEncoder &copyTextureToBuffer(const TextureRef &src, BlitCommandEncoder &copyTextureToBuffer(const TextureRef &src,
uint32_t srcSlice, uint32_t srcSlice,
uint32_t srcLevel, MipmapNativeLevel srcLevel,
MTLOrigin srcOrigin, MTLOrigin srcOrigin,
MTLSize srcSize, MTLSize srcSize,
const BufferRef &dst, const BufferRef &dst,
...@@ -536,10 +536,10 @@ class BlitCommandEncoder final : public CommandEncoder ...@@ -536,10 +536,10 @@ class BlitCommandEncoder final : public CommandEncoder
BlitCommandEncoder &copyTexture(const TextureRef &src, BlitCommandEncoder &copyTexture(const TextureRef &src,
uint32_t srcSlice, uint32_t srcSlice,
uint32_t srcLevel, MipmapNativeLevel srcLevel,
const TextureRef &dst, const TextureRef &dst,
uint32_t dstSlice, uint32_t dstSlice,
uint32_t dstLevel, MipmapNativeLevel dstLevel,
uint32_t sliceCount, uint32_t sliceCount,
uint32_t levelCount); uint32_t levelCount);
......
...@@ -975,7 +975,7 @@ inline void RenderCommandEncoder::initAttachmentWriteDependencyAndScissorRect( ...@@ -975,7 +975,7 @@ inline void RenderCommandEncoder::initAttachmentWriteDependencyAndScissorRect(
{ {
cmdBuffer().setWriteDependency(texture); cmdBuffer().setWriteDependency(texture);
uint32_t mipLevel = attachment.level; const MipmapNativeLevel &mipLevel = attachment.level;
mRenderPassMaxScissorRect.width = mRenderPassMaxScissorRect.width =
std::min<NSUInteger>(mRenderPassMaxScissorRect.width, texture->width(mipLevel)); std::min<NSUInteger>(mRenderPassMaxScissorRect.width, texture->width(mipLevel));
...@@ -1703,7 +1703,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src ...@@ -1703,7 +1703,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src
MTLSize srcSize, MTLSize srcSize,
const TextureRef &dst, const TextureRef &dst,
uint32_t dstSlice, uint32_t dstSlice,
uint32_t dstLevel, MipmapNativeLevel dstLevel,
MTLOrigin dstOrigin, MTLOrigin dstOrigin,
MTLBlitOption blitOption) MTLBlitOption blitOption)
{ {
...@@ -1722,7 +1722,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src ...@@ -1722,7 +1722,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src
sourceSize:srcSize sourceSize:srcSize
toTexture:dst->get() toTexture:dst->get()
destinationSlice:dstSlice destinationSlice:dstSlice
destinationLevel:dstLevel destinationLevel:dstLevel.get()
destinationOrigin:dstOrigin destinationOrigin:dstOrigin
options:blitOption]; options:blitOption];
...@@ -1731,7 +1731,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src ...@@ -1731,7 +1731,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyBufferToTexture(const BufferRef &src
BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &src, BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &src,
uint32_t srcSlice, uint32_t srcSlice,
uint32_t srcLevel, MipmapNativeLevel srcLevel,
MTLOrigin srcOrigin, MTLOrigin srcOrigin,
MTLSize srcSize, MTLSize srcSize,
const BufferRef &dst, const BufferRef &dst,
...@@ -1751,7 +1751,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &sr ...@@ -1751,7 +1751,7 @@ BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &sr
[get() copyFromTexture:src->get() [get() copyFromTexture:src->get()
sourceSlice:srcSlice sourceSlice:srcSlice
sourceLevel:srcLevel sourceLevel:srcLevel.get()
sourceOrigin:srcOrigin sourceOrigin:srcOrigin
sourceSize:srcSize sourceSize:srcSize
toBuffer:dst->get() toBuffer:dst->get()
...@@ -1765,10 +1765,10 @@ BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &sr ...@@ -1765,10 +1765,10 @@ BlitCommandEncoder &BlitCommandEncoder::copyTextureToBuffer(const TextureRef &sr
BlitCommandEncoder &BlitCommandEncoder::copyTexture(const TextureRef &src, BlitCommandEncoder &BlitCommandEncoder::copyTexture(const TextureRef &src,
uint32_t srcStartSlice, uint32_t srcStartSlice,
uint32_t srcStartLevel, MipmapNativeLevel srcStartLevel,
const TextureRef &dst, const TextureRef &dst,
uint32_t dstStartSlice, uint32_t dstStartSlice,
uint32_t dstStartLevel, MipmapNativeLevel dstStartLevel,
uint32_t sliceCount, uint32_t sliceCount,
uint32_t levelCount) uint32_t levelCount)
{ {
...@@ -1787,19 +1787,19 @@ BlitCommandEncoder &BlitCommandEncoder::copyTexture(const TextureRef &src, ...@@ -1787,19 +1787,19 @@ BlitCommandEncoder &BlitCommandEncoder::copyTexture(const TextureRef &src,
uint32_t dstSlice = dstStartSlice + slice; uint32_t dstSlice = dstStartSlice + slice;
for (uint32_t level = 0; level < levelCount; ++level) for (uint32_t level = 0; level < levelCount; ++level)
{ {
uint32_t srcLevel = srcStartLevel + level; MipmapNativeLevel srcLevel = srcStartLevel + level;
uint32_t dstLevel = dstStartLevel + level; MipmapNativeLevel dstLevel = dstStartLevel + level;
MTLSize srcSize = MTLSize srcSize =
MTLSizeMake(src->width(srcLevel), src->height(srcLevel), src->depth(srcLevel)); MTLSizeMake(src->width(srcLevel), src->height(srcLevel), src->depth(srcLevel));
[get() copyFromTexture:src->get() [get() copyFromTexture:src->get()
sourceSlice:srcSlice sourceSlice:srcSlice
sourceLevel:srcLevel sourceLevel:srcLevel.get()
sourceOrigin:origin sourceOrigin:origin
sourceSize:srcSize sourceSize:srcSize
toTexture:dst->get() toTexture:dst->get()
destinationSlice:dstSlice destinationSlice:dstSlice
destinationLevel:dstLevel destinationLevel:dstLevel.get()
destinationOrigin:origin]; destinationOrigin:origin];
} }
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "common/apple_platform_utils.h" #include "common/apple_platform_utils.h"
#include "libANGLE/Constants.h" #include "libANGLE/Constants.h"
#include "libANGLE/ImageIndex.h"
#include "libANGLE/Version.h" #include "libANGLE/Version.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
...@@ -339,6 +340,70 @@ using SharedEventRef = AutoObjCPtr<id<MTLSharedEvent>>; ...@@ -339,6 +340,70 @@ using SharedEventRef = AutoObjCPtr<id<MTLSharedEvent>>;
using SharedEventRef = AutoObjCObj<NSObject>; using SharedEventRef = AutoObjCObj<NSObject>;
#endif #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 struct ClearOptions
{ {
Optional<MTLClearColor> clearColor; Optional<MTLClearColor> clearColor;
......
...@@ -21,6 +21,13 @@ namespace rx ...@@ -21,6 +21,13 @@ namespace rx
namespace mtl namespace mtl
{ {
// ImageNativeIndex implementation
ImageNativeIndexIterator ImageNativeIndex::getLayerIterator(GLint layerCount) const
{
return ImageNativeIndexIterator(mNativeIndex.getLayerIterator(layerCount));
}
// Context implementation
Context::Context(DisplayMtl *display) : mDisplay(display) {} Context::Context(DisplayMtl *display) : mDisplay(display) {}
id<MTLDevice> Context::getMetalDevice() const id<MTLDevice> Context::getMetalDevice() const
......
...@@ -57,8 +57,8 @@ struct BlitParams ...@@ -57,8 +57,8 @@ struct BlitParams
bool dstFlipX = false; bool dstFlipX = false;
TextureRef src; TextureRef src;
uint32_t srcLevel = 0; MipmapNativeLevel srcLevel = kZeroNativeMipLevel;
uint32_t srcLayer = 0; uint32_t srcLayer = 0;
// Source rectangle: // Source rectangle:
// NOTE: if srcYFlipped=true, this rectangle will be converted internally to flipped rect before // NOTE: if srcYFlipped=true, this rectangle will be converted internally to flipped rect before
...@@ -93,9 +93,9 @@ struct StencilBlitViaBufferParams : public DepthStencilBlitParams ...@@ -93,9 +93,9 @@ struct StencilBlitViaBufferParams : public DepthStencilBlitParams
StencilBlitViaBufferParams(const DepthStencilBlitParams &src); StencilBlitViaBufferParams(const DepthStencilBlitParams &src);
TextureRef dstStencil; TextureRef dstStencil;
uint32_t dstStencilLevel = 0; MipmapNativeLevel dstStencilLevel = kZeroNativeMipLevel;
uint32_t dstStencilLayer = 0; uint32_t dstStencilLayer = 0;
bool dstPackedDepthStencilFormat = false; bool dstPackedDepthStencilFormat = false;
}; };
struct TriFanFromArrayParams struct TriFanFromArrayParams
...@@ -150,8 +150,8 @@ struct CopyPixelsFromBufferParams : CopyPixelsCommonParams ...@@ -150,8 +150,8 @@ struct CopyPixelsFromBufferParams : CopyPixelsCommonParams
struct CopyPixelsToBufferParams : CopyPixelsCommonParams struct CopyPixelsToBufferParams : CopyPixelsCommonParams
{ {
gl::Rectangle textureArea; gl::Rectangle textureArea;
uint32_t textureLevel = 0; MipmapNativeLevel textureLevel = kZeroNativeMipLevel;
uint32_t textureSliceOrDeph = 0; uint32_t textureSliceOrDeph = 0;
bool reverseTextureRowOrder; bool reverseTextureRowOrder;
}; };
...@@ -371,7 +371,7 @@ class MipmapUtils final : angle::NonCopyable ...@@ -371,7 +371,7 @@ class MipmapUtils final : angle::NonCopyable
angle::Result generateMipmapCS(ContextMtl *contextMtl, angle::Result generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture, const TextureRef &srcTexture,
bool sRGBMipmap, bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews); NativeTexLevelArray *mipmapOutputViews);
private: private:
void ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl); void ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl);
...@@ -470,7 +470,7 @@ class RenderUtils : public Context, angle::NonCopyable ...@@ -470,7 +470,7 @@ class RenderUtils : public Context, angle::NonCopyable
angle::Result generateMipmapCS(ContextMtl *contextMtl, angle::Result generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture, const TextureRef &srcTexture,
bool sRGBMipmap, bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews); NativeTexLevelArray *mipmapOutputViews);
angle::Result unpackPixelsFromBufferToTexture(ContextMtl *contextMtl, angle::Result unpackPixelsFromBufferToTexture(ContextMtl *contextMtl,
const angle::Format &srcAngleFormat, const angle::Format &srcAngleFormat,
......
...@@ -437,7 +437,7 @@ void SetupBlitWithDrawUniformData(RenderCommandEncoder *cmdEncoder, ...@@ -437,7 +437,7 @@ void SetupBlitWithDrawUniformData(RenderCommandEncoder *cmdEncoder,
BlitParamsUniform uniformParams; BlitParamsUniform uniformParams;
uniformParams.dstFlipX = params.dstFlipX ? 1 : 0; uniformParams.dstFlipX = params.dstFlipX ? 1 : 0;
uniformParams.dstFlipY = params.dstFlipY ? 1 : 0; uniformParams.dstFlipY = params.dstFlipY ? 1 : 0;
uniformParams.srcLevel = params.srcLevel; uniformParams.srcLevel = params.srcLevel.get();
uniformParams.srcLayer = params.srcLayer; uniformParams.srcLayer = params.srcLayer;
if (isColorBlit) if (isColorBlit)
{ {
...@@ -611,10 +611,10 @@ angle::Result RenderUtils::blitColorWithDraw(const gl::Context *context, ...@@ -611,10 +611,10 @@ angle::Result RenderUtils::blitColorWithDraw(const gl::Context *context,
} }
ColorBlitParams params; ColorBlitParams params;
params.enabledBuffers.set(0); params.enabledBuffers.set(0);
params.src = srcTexture; params.src = srcTexture;
params.dstTextureSize = params.dstTextureSize = gl::Extents(static_cast<int>(srcTexture->widthAt0()),
gl::Extents(static_cast<int>(srcTexture->width()), static_cast<int>(srcTexture->height()), static_cast<int>(srcTexture->heightAt0()),
static_cast<int>(srcTexture->depth())); static_cast<int>(srcTexture->depthAt0()));
params.dstRect = params.dstScissorRect = params.srcRect = params.dstRect = params.dstScissorRect = params.srcRect =
gl::Rectangle(0, 0, params.dstTextureSize.width, params.dstTextureSize.height); gl::Rectangle(0, 0, params.dstTextureSize.width, params.dstTextureSize.height);
...@@ -682,7 +682,7 @@ void RenderUtils::combineVisibilityResult( ...@@ -682,7 +682,7 @@ void RenderUtils::combineVisibilityResult(
angle::Result RenderUtils::generateMipmapCS(ContextMtl *contextMtl, angle::Result RenderUtils::generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture, const TextureRef &srcTexture,
bool sRGBMipmap, bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews) NativeTexLevelArray *mipmapOutputViews)
{ {
return mMipmapUtils.generateMipmapCS(contextMtl, srcTexture, sRGBMipmap, mipmapOutputViews); return mMipmapUtils.generateMipmapCS(contextMtl, srcTexture, sRGBMipmap, mipmapOutputViews);
} }
...@@ -1336,7 +1336,7 @@ angle::Result DepthStencilBlitUtils::blitStencilViaCopyBuffer( ...@@ -1336,7 +1336,7 @@ angle::Result DepthStencilBlitUtils::blitStencilViaCopyBuffer(
uniform.srcTexCoordSteps[1] = (v1 - v0) / params.dstRect.height; uniform.srcTexCoordSteps[1] = (v1 - v0) / params.dstRect.height;
uniform.srcStartTexCoords[0] = u0 + uniform.srcTexCoordSteps[0] * 0.5f; uniform.srcStartTexCoords[0] = u0 + uniform.srcTexCoordSteps[0] * 0.5f;
uniform.srcStartTexCoords[1] = v0 + uniform.srcTexCoordSteps[1] * 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.srcLayer = params.srcLayer;
uniform.dstSize[0] = params.dstRect.width; uniform.dstSize[0] = params.dstRect.width;
uniform.dstSize[1] = params.dstRect.height; uniform.dstSize[1] = params.dstRect.height;
...@@ -1801,7 +1801,7 @@ void MipmapUtils::ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl ...@@ -1801,7 +1801,7 @@ void MipmapUtils::ensure3DMipGeneratorPipelineInitialized(ContextMtl *contextMtl
angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl, angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl,
const TextureRef &srcTexture, const TextureRef &srcTexture,
bool sRGBMipmap, bool sRGBMipmap,
gl::TexLevelArray<mtl::TextureRef> *mipmapOutputViews) NativeTexLevelArray *mipmapOutputViews)
{ {
// Only support 3D texture for now. // Only support 3D texture for now.
ASSERT(srcTexture->textureType() == MTLTextureType3D); ASSERT(srcTexture->textureType() == MTLTextureType3D);
...@@ -1848,16 +1848,17 @@ angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl, ...@@ -1848,16 +1848,17 @@ angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl,
GenerateMipmapUniform options; GenerateMipmapUniform options;
uint32_t remainMips = srcTexture->mipmapLevels() - 1; uint32_t remainMips = srcTexture->mipmapLevels() - 1;
options.srcLevel = 0; MipmapNativeLevel batchSrcLevel = kZeroNativeMipLevel;
options.sRGB = sRGBMipmap; options.srcLevel = batchSrcLevel.get();
options.sRGB = sRGBMipmap;
cmdEncoder->setTexture(srcTexture, 0); cmdEncoder->setTexture(srcTexture, 0);
cmdEncoder->markResourceBeingWrittenByGPU(srcTexture); cmdEncoder->markResourceBeingWrittenByGPU(srcTexture);
while (remainMips) while (remainMips)
{ {
const TextureRef &firstMipView = mipmapOutputViews->at(options.srcLevel + 1); const TextureRef &firstMipView = mipmapOutputViews->at(batchSrcLevel + 1);
gl::Extents size = firstMipView->size(); gl::Extents size = firstMipView->sizeAt0();
bool isPow2 = gl::isPow2(size.width) && gl::isPow2(size.height) && gl::isPow2(size.depth); 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. // Currently multiple mipmaps generation is only supported for power of two base level.
...@@ -1874,18 +1875,20 @@ angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl, ...@@ -1874,18 +1875,20 @@ angle::Result MipmapUtils::generateMipmapCS(ContextMtl *contextMtl,
for (uint32_t i = 1; i <= options.numMipmapsToGenerate; ++i) 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, DispatchCompute(
/** allowNonUniform */ false, contextMtl, cmdEncoder,
MTLSizeMake(firstMipView->width(), firstMipView->height(), threadsPerZ), /** allowNonUniform */ false,
threadGroupSize); MTLSizeMake(firstMipView->widthAt0(), firstMipView->heightAt0(), threadsPerZ),
threadGroupSize);
remainMips -= options.numMipmapsToGenerate; remainMips -= options.numMipmapsToGenerate;
options.srcLevel += options.numMipmapsToGenerate; batchSrcLevel = batchSrcLevel + options.numMipmapsToGenerate;
options.srcLevel = batchSrcLevel.get();
} }
return angle::Result::Continue; return angle::Result::Continue;
...@@ -2012,7 +2015,7 @@ angle::Result CopyPixelsUtils::packPixelsFromTextureToBuffer(ContextMtl *context ...@@ -2012,7 +2015,7 @@ angle::Result CopyPixelsUtils::packPixelsFromTextureToBuffer(ContextMtl *context
options.bufferRowPitch = params.bufferRowPitch; options.bufferRowPitch = params.bufferRowPitch;
options.textureOffset[0] = params.textureArea.x; options.textureOffset[0] = params.textureArea.x;
options.textureOffset[1] = params.textureArea.y; options.textureOffset[1] = params.textureArea.y;
options.textureLevel = params.textureLevel; options.textureLevel = params.textureLevel.get();
options.textureLayer = params.textureSliceOrDeph; options.textureLayer = params.textureSliceOrDeph;
options.reverseTextureRowOrder = params.reverseTextureRowOrder; options.reverseTextureRowOrder = params.reverseTextureRowOrder;
cmdEncoder->setData(options, 0); cmdEncoder->setData(options, 0);
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "common/MemoryBuffer.h" #include "common/MemoryBuffer.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/ImageIndex.h"
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/renderer/metal/mtl_common.h" #include "libANGLE/renderer/metal/mtl_common.h"
#include "libANGLE/renderer/metal/mtl_format_utils.h" #include "libANGLE/renderer/metal/mtl_format_utils.h"
...@@ -147,14 +146,14 @@ class Texture final : public Resource, ...@@ -147,14 +146,14 @@ class Texture final : public Resource,
void replace2DRegion(ContextMtl *context, void replace2DRegion(ContextMtl *context,
const MTLRegion &region, const MTLRegion &region,
uint32_t mipmapLevel, const MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
const uint8_t *data, const uint8_t *data,
size_t bytesPerRow); size_t bytesPerRow);
void replaceRegion(ContextMtl *context, void replaceRegion(ContextMtl *context,
const MTLRegion &region, const MTLRegion &region,
uint32_t mipmapLevel, const MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
const uint8_t *data, const uint8_t *data,
size_t bytesPerRow, size_t bytesPerRow,
...@@ -164,16 +163,16 @@ class Texture final : public Resource, ...@@ -164,16 +163,16 @@ class Texture final : public Resource,
size_t bytesPerRow, size_t bytesPerRow,
size_t bytesPer2DInage, size_t bytesPer2DInage,
const MTLRegion &region, const MTLRegion &region,
uint32_t mipmapLevel, const MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
uint8_t *dataOut); uint8_t *dataOut);
// Create 2d view of a cube face which full range of mip levels. // Create 2d view of a cube face which full range of mip levels.
TextureRef createCubeFaceView(uint32_t face); TextureRef createCubeFaceView(uint32_t face);
// Create a view of one slice at a level. // 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. // Create a view of a level.
TextureRef createMipView(uint32_t level); TextureRef createMipView(const MipmapNativeLevel &level);
// Create a view with different format // Create a view with different format
TextureRef createViewWithDifferentFormat(MTLPixelFormat format); TextureRef createViewWithDifferentFormat(MTLPixelFormat format);
// Same as above but the target format must be compatible, for example sRGB to linear. In this // 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, ...@@ -187,12 +186,17 @@ class Texture final : public Resource,
uint32_t arrayLength() const; uint32_t arrayLength() const;
uint32_t cubeFacesOrArrayLength() const; uint32_t cubeFacesOrArrayLength() const;
uint32_t width(uint32_t level = 0) const; uint32_t width(const MipmapNativeLevel &level) const;
uint32_t height(uint32_t level = 0) const; uint32_t height(const MipmapNativeLevel &level) const;
uint32_t depth(uint32_t level = 0) const; uint32_t depth(const MipmapNativeLevel &level) const;
gl::Extents size(uint32_t level = 0) const; gl::Extents size(const MipmapNativeLevel &level) const;
gl::Extents size(const gl::ImageIndex &index) 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; uint32_t samples() const;
...@@ -305,6 +309,27 @@ class Buffer final : public Resource, public WrappedObject<id<MTLBuffer>> ...@@ -305,6 +309,27 @@ class Buffer final : public Resource, public WrappedObject<id<MTLBuffer>>
bool mMapReadOnly = true; 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 mtl
} // namespace rx } // namespace rx
......
...@@ -26,9 +26,9 @@ namespace mtl ...@@ -26,9 +26,9 @@ namespace mtl
{ {
namespace 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, void SetTextureSwizzle(ContextMtl *context,
...@@ -355,7 +355,7 @@ bool Texture::supportFormatView() const ...@@ -355,7 +355,7 @@ bool Texture::supportFormatView() const
void Texture::replace2DRegion(ContextMtl *context, void Texture::replace2DRegion(ContextMtl *context,
const MTLRegion &region, const MTLRegion &region,
uint32_t mipmapLevel, const MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
const uint8_t *data, const uint8_t *data,
size_t bytesPerRow) size_t bytesPerRow)
...@@ -366,13 +366,13 @@ void Texture::replace2DRegion(ContextMtl *context, ...@@ -366,13 +366,13 @@ void Texture::replace2DRegion(ContextMtl *context,
void Texture::replaceRegion(ContextMtl *context, void Texture::replaceRegion(ContextMtl *context,
const MTLRegion &region, const MTLRegion &region,
uint32_t mipmapLevel, const MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
const uint8_t *data, const uint8_t *data,
size_t bytesPerRow, size_t bytesPerRow,
size_t bytesPer2DImage) size_t bytesPer2DImage)
{ {
if (mipmapLevel >= this->mipmapLevels()) if (mipmapLevel.get() >= this->mipmapLevels())
{ {
return; return;
} }
...@@ -397,7 +397,7 @@ void Texture::replaceRegion(ContextMtl *context, ...@@ -397,7 +397,7 @@ void Texture::replaceRegion(ContextMtl *context,
} }
[get() replaceRegion:region [get() replaceRegion:region
mipmapLevel:mipmapLevel mipmapLevel:mipmapLevel.get()
slice:slice slice:slice
withBytes:data withBytes:data
bytesPerRow:bytesPerRow bytesPerRow:bytesPerRow
...@@ -408,7 +408,7 @@ void Texture::getBytes(ContextMtl *context, ...@@ -408,7 +408,7 @@ void Texture::getBytes(ContextMtl *context,
size_t bytesPerRow, size_t bytesPerRow,
size_t bytesPer2DInage, size_t bytesPer2DInage,
const MTLRegion &region, const MTLRegion &region,
uint32_t mipmapLevel, const MipmapNativeLevel &mipmapLevel,
uint32_t slice, uint32_t slice,
uint8_t *dataOut) uint8_t *dataOut)
{ {
...@@ -430,7 +430,7 @@ void Texture::getBytes(ContextMtl *context, ...@@ -430,7 +430,7 @@ void Texture::getBytes(ContextMtl *context,
bytesPerRow:bytesPerRow bytesPerRow:bytesPerRow
bytesPerImage:bytesPer2DInage bytesPerImage:bytesPer2DInage
fromRegion:region fromRegion:region
mipmapLevel:mipmapLevel mipmapLevel:mipmapLevel.get()
slice:slice]; slice:slice];
} }
...@@ -450,7 +450,7 @@ TextureRef Texture::createCubeFaceView(uint32_t face) ...@@ -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 ANGLE_MTL_OBJC_SCOPE
{ {
...@@ -459,7 +459,7 @@ TextureRef Texture::createSliceMipView(uint32_t slice, uint32_t level) ...@@ -459,7 +459,7 @@ TextureRef Texture::createSliceMipView(uint32_t slice, uint32_t level)
case MTLTextureTypeCube: case MTLTextureTypeCube:
case MTLTextureType2D: case MTLTextureType2D:
case MTLTextureType2DArray: case MTLTextureType2DArray:
return TextureRef(new Texture(this, MTLTextureType2D, NSMakeRange(level, 1), return TextureRef(new Texture(this, MTLTextureType2D, NSMakeRange(level.get(), 1),
NSMakeRange(slice, 1))); NSMakeRange(slice, 1)));
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -468,13 +468,13 @@ TextureRef Texture::createSliceMipView(uint32_t slice, uint32_t level) ...@@ -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 ANGLE_MTL_OBJC_SCOPE
{ {
NSUInteger slices = cubeFacesOrArrayLength(); NSUInteger slices = cubeFacesOrArrayLength();
return TextureRef( 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 ...@@ -518,22 +518,22 @@ uint32_t Texture::cubeFacesOrArrayLength() const
return arrayLength(); 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)); 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)); 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)); 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; gl::Extents re;
...@@ -544,9 +544,9 @@ gl::Extents Texture::size(uint32_t level) const ...@@ -544,9 +544,9 @@ gl::Extents Texture::size(uint32_t level) const
return re; 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()) if (index.hasLayer())
{ {
......
...@@ -300,7 +300,7 @@ struct RenderPassAttachmentDesc ...@@ -300,7 +300,7 @@ struct RenderPassAttachmentDesc
// Implicit multisample texture that will be rendered into and discarded at the end of // 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. // a render pass. Its result will be resolved into normal texture above.
TextureRef implicitMSTexture; TextureRef implicitMSTexture;
uint32_t level; MipmapNativeLevel level;
uint32_t sliceOrDepth; uint32_t sliceOrDepth;
MTLLoadAction loadAction; MTLLoadAction loadAction;
......
...@@ -193,7 +193,7 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src, ...@@ -193,7 +193,7 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src,
dst.slice = 0; dst.slice = 0;
dst.depthPlane = 0; dst.depthPlane = 0;
dst.resolveTexture = ToObjC(src.texture); dst.resolveTexture = ToObjC(src.texture);
dst.resolveLevel = src.level; dst.resolveLevel = src.level.get();
if (dst.resolveTexture.textureType == MTLTextureType3D) if (dst.resolveTexture.textureType == MTLTextureType3D)
{ {
dst.resolveDepthPlane = src.sliceOrDepth; dst.resolveDepthPlane = src.sliceOrDepth;
...@@ -208,7 +208,7 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src, ...@@ -208,7 +208,7 @@ void BaseRenderPassAttachmentDescToObjC(const RenderPassAttachmentDesc &src,
else else
{ {
dst.texture = ToObjC(src.texture); dst.texture = ToObjC(src.texture);
dst.level = src.level; dst.level = src.level.get();
if (dst.texture.textureType == MTLTextureType3D) if (dst.texture.textureType == MTLTextureType3D)
{ {
dst.depthPlane = src.sliceOrDepth; dst.depthPlane = src.sliceOrDepth;
...@@ -691,7 +691,7 @@ void RenderPassAttachmentDesc::reset() ...@@ -691,7 +691,7 @@ void RenderPassAttachmentDesc::reset()
{ {
texture.reset(); texture.reset();
implicitMSTexture.reset(); implicitMSTexture.reset();
level = 0; level = mtl::kZeroNativeMipLevel;
sliceOrDepth = 0; sliceOrDepth = 0;
loadAction = MTLLoadActionLoad; loadAction = MTLLoadActionLoad;
storeAction = MTLStoreActionStore; storeAction = MTLStoreActionStore;
......
...@@ -32,27 +32,27 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -32,27 +32,27 @@ NS_ASSUME_NONNULL_BEGIN
angle::Result InitializeTextureContents(const gl::Context *context, angle::Result InitializeTextureContents(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
const Format &textureObjFormat, const Format &textureObjFormat,
const gl::ImageIndex &index); const ImageNativeIndex &index);
// Same as above but using GPU clear operation instead of CPU. // Same as above but using GPU clear operation instead of CPU.
// - channelsToInit parameter controls which channels will get their content initialized. // - channelsToInit parameter controls which channels will get their content initialized.
angle::Result InitializeTextureContentsGPU(const gl::Context *context, angle::Result InitializeTextureContentsGPU(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
const Format &textureObjFormat, const Format &textureObjFormat,
const gl::ImageIndex &index, const ImageNativeIndex &index,
MTLColorWriteMask channelsToInit); MTLColorWriteMask channelsToInit);
// Same as above but for a depth/stencil texture. // Same as above but for a depth/stencil texture.
angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *context, angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
const Format &textureObjFormat, const Format &textureObjFormat,
const gl::ImageIndex &index); const ImageNativeIndex &index);
// Unified texture's per slice/depth texel reading function // Unified texture's per slice/depth texel reading function
angle::Result ReadTexturePerSliceBytes(const gl::Context *context, angle::Result ReadTexturePerSliceBytes(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
size_t bytesPerRow, size_t bytesPerRow,
const gl::Rectangle &fromRegion, const gl::Rectangle &fromRegion,
uint32_t mipLevel, const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth, uint32_t sliceOrDepth,
uint8_t *dataOut); uint8_t *dataOut);
...@@ -60,7 +60,7 @@ angle::Result ReadTexturePerSliceBytesToBuffer(const gl::Context *context, ...@@ -60,7 +60,7 @@ angle::Result ReadTexturePerSliceBytesToBuffer(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
size_t bytesPerRow, size_t bytesPerRow,
const gl::Rectangle &fromRegion, const gl::Rectangle &fromRegion,
uint32_t mipLevel, const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth, uint32_t sliceOrDepth,
uint32_t dstOffset, uint32_t dstOffset,
const BufferRef &dstBuffer); const BufferRef &dstBuffer);
...@@ -143,6 +143,9 @@ MTLClearColor EmulatedAlphaClearColor(MTLClearColor color, MTLColorWriteMask col ...@@ -143,6 +143,9 @@ MTLClearColor EmulatedAlphaClearColor(MTLClearColor color, MTLColorWriteMask col
gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion); gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion);
MipmapNativeLevel GetNativeMipLevel(GLuint level, GLuint base);
GLuint GetGLMipLevel(const MipmapNativeLevel &nativeLevel, GLuint base);
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
} // namespace mtl } // namespace mtl
} // namespace rx } // namespace rx
......
...@@ -64,7 +64,7 @@ uint32_t GetDeviceVendorIdFromIOKit(id<MTLDevice> device) ...@@ -64,7 +64,7 @@ uint32_t GetDeviceVendorIdFromIOKit(id<MTLDevice> device)
} }
#endif #endif
void GetSliceAndDepth(const gl::ImageIndex &index, GLint *layer, GLint *startDepth) void GetSliceAndDepth(const ImageNativeIndex &index, GLint *layer, GLint *startDepth)
{ {
*layer = *startDepth = 0; *layer = *startDepth = 0;
if (!index.hasLayer()) if (!index.hasLayer())
...@@ -87,7 +87,7 @@ void GetSliceAndDepth(const gl::ImageIndex &index, GLint *layer, GLint *startDep ...@@ -87,7 +87,7 @@ void GetSliceAndDepth(const gl::ImageIndex &index, GLint *layer, GLint *startDep
break; break;
} }
} }
GLint GetSliceOrDepth(const gl::ImageIndex &index) GLint GetSliceOrDepth(const ImageNativeIndex &index)
{ {
GLint layer, startDepth; GLint layer, startDepth;
GetSliceAndDepth(index, &layer, &startDepth); GetSliceAndDepth(index, &layer, &startDepth);
...@@ -100,7 +100,7 @@ GLint GetSliceOrDepth(const gl::ImageIndex &index) ...@@ -100,7 +100,7 @@ GLint GetSliceOrDepth(const gl::ImageIndex &index)
angle::Result InitializeTextureContents(const gl::Context *context, angle::Result InitializeTextureContents(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
const Format &textureObjFormat, const Format &textureObjFormat,
const gl::ImageIndex &index) const ImageNativeIndex &index)
{ {
ASSERT(texture && texture->valid()); ASSERT(texture && texture->valid());
// Only one slice can be initialized at a time. // Only one slice can be initialized at a time.
...@@ -161,7 +161,7 @@ angle::Result InitializeTextureContents(const gl::Context *context, ...@@ -161,7 +161,7 @@ angle::Result InitializeTextureContents(const gl::Context *context,
mtlRowRegion.origin.y = r; mtlRowRegion.origin.y = r;
// Upload to texture // Upload to texture
texture->replace2DRegion(contextMtl, mtlRowRegion, index.getLevelIndex(), layer, texture->replace2DRegion(contextMtl, mtlRowRegion, index.getNativeLevel(), layer,
conversionRow.data(), dstRowPitch); conversionRow.data(), dstRowPitch);
} }
} }
...@@ -178,17 +178,18 @@ angle::Result InitializeTextureContents(const gl::Context *context, ...@@ -178,17 +178,18 @@ angle::Result InitializeTextureContents(const gl::Context *context,
angle::Result InitializeTextureContentsGPU(const gl::Context *context, angle::Result InitializeTextureContentsGPU(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
const Format &textureObjFormat, const Format &textureObjFormat,
const gl::ImageIndex &index, const ImageNativeIndex &index,
MTLColorWriteMask channelsToInit) MTLColorWriteMask channelsToInit)
{ {
// Only one slice can be initialized at a time. // Only one slice can be initialized at a time.
ASSERT(!index.isLayered() || index.getType() == gl::TextureType::_3D); ASSERT(!index.isLayered() || index.getType() == gl::TextureType::_3D);
if (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()) while (ite.hasNext())
{ {
gl::ImageIndex depthLayerIndex = ite.next(); ImageNativeIndex depthLayerIndex = ite.next();
ANGLE_TRY(InitializeTextureContentsGPU(context, texture, textureObjFormat, ANGLE_TRY(InitializeTextureContentsGPU(context, texture, textureObjFormat,
depthLayerIndex, MTLColorWriteMaskAll)); depthLayerIndex, MTLColorWriteMaskAll));
} }
...@@ -207,7 +208,7 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context, ...@@ -207,7 +208,7 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context,
// Use clear render command // Use clear render command
RenderTargetMtl tempRtt; RenderTargetMtl tempRtt;
tempRtt.set(texture, index.getLevelIndex(), sliceOrDepth, textureObjFormat); tempRtt.set(texture, index.getNativeLevel(), sliceOrDepth, textureObjFormat);
MTLClearColor blackColor = {}; MTLClearColor blackColor = {};
if (!textureObjFormat.intendedAngleFormat().alphaBits) if (!textureObjFormat.intendedAngleFormat().alphaBits)
...@@ -234,9 +235,9 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context, ...@@ -234,9 +235,9 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context,
ClearRectParams clearParams; ClearRectParams clearParams;
clearParams.clearColor = blackColor; clearParams.clearColor = blackColor;
clearParams.dstTextureSize = texture->size(); clearParams.dstTextureSize = texture->sizeAt0();
clearParams.enabledBuffers.set(0); 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( ANGLE_TRY(
contextMtl->getDisplay()->getUtils().clearWithDraw(context, encoder, clearParams)); contextMtl->getDisplay()->getUtils().clearWithDraw(context, encoder, clearParams));
...@@ -252,8 +253,9 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context, ...@@ -252,8 +253,9 @@ angle::Result InitializeTextureContentsGPU(const gl::Context *context,
angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *context, angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
const Format &textureObjFormat, const Format &textureObjFormat,
const gl::ImageIndex &index) const ImageNativeIndex &index)
{ {
const MipmapNativeLevel &level = index.getNativeLevel();
// Use clear operation // Use clear operation
ContextMtl *contextMtl = mtl::GetImpl(context); ContextMtl *contextMtl = mtl::GetImpl(context);
const angle::Format &angleFormat = textureObjFormat.actualAngleFormat(); const angle::Format &angleFormat = textureObjFormat.actualAngleFormat();
...@@ -266,7 +268,7 @@ angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *contex ...@@ -266,7 +268,7 @@ angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *contex
if (angleFormat.depthBits) if (angleFormat.depthBits)
{ {
rpDesc.depthAttachment.texture = texture; rpDesc.depthAttachment.texture = texture;
rpDesc.depthAttachment.level = index.getLevelIndex(); rpDesc.depthAttachment.level = level;
rpDesc.depthAttachment.sliceOrDepth = layer; rpDesc.depthAttachment.sliceOrDepth = layer;
rpDesc.depthAttachment.loadAction = MTLLoadActionClear; rpDesc.depthAttachment.loadAction = MTLLoadActionClear;
rpDesc.depthAttachment.clearDepth = 1.0; rpDesc.depthAttachment.clearDepth = 1.0;
...@@ -274,7 +276,7 @@ angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *contex ...@@ -274,7 +276,7 @@ angle::Result InitializeDepthStencilTextureContentsGPU(const gl::Context *contex
if (angleFormat.stencilBits) if (angleFormat.stencilBits)
{ {
rpDesc.stencilAttachment.texture = texture; rpDesc.stencilAttachment.texture = texture;
rpDesc.stencilAttachment.level = index.getLevelIndex(); rpDesc.stencilAttachment.level = level;
rpDesc.stencilAttachment.sliceOrDepth = layer; rpDesc.stencilAttachment.sliceOrDepth = layer;
rpDesc.stencilAttachment.loadAction = MTLLoadActionClear; rpDesc.stencilAttachment.loadAction = MTLLoadActionClear;
} }
...@@ -292,7 +294,7 @@ angle::Result ReadTexturePerSliceBytes(const gl::Context *context, ...@@ -292,7 +294,7 @@ angle::Result ReadTexturePerSliceBytes(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
size_t bytesPerRow, size_t bytesPerRow,
const gl::Rectangle &fromRegion, const gl::Rectangle &fromRegion,
uint32_t mipLevel, const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth, uint32_t sliceOrDepth,
uint8_t *dataOut) uint8_t *dataOut)
{ {
...@@ -325,7 +327,7 @@ angle::Result ReadTexturePerSliceBytesToBuffer(const gl::Context *context, ...@@ -325,7 +327,7 @@ angle::Result ReadTexturePerSliceBytesToBuffer(const gl::Context *context,
const TextureRef &texture, const TextureRef &texture,
size_t bytesPerRow, size_t bytesPerRow,
const gl::Rectangle &fromRegion, const gl::Rectangle &fromRegion,
uint32_t mipLevel, const MipmapNativeLevel &mipLevel,
uint32_t sliceOrDepth, uint32_t sliceOrDepth,
uint32_t dstOffset, uint32_t dstOffset,
const BufferRef &dstBuffer) const BufferRef &dstBuffer)
...@@ -826,5 +828,16 @@ gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion) ...@@ -826,5 +828,16 @@ gl::Box MTLRegionToGLBox(const MTLRegion &mtlRegion)
static_cast<int>(mtlRegion.size.height), static_cast<int>(mtlRegion.size.depth)); 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 mtl
} // namespace rx } // 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