From 455b0c2c6b6fd1b70466ca749c31512af3bf6718 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sat, 15 Feb 2020 16:00:55 -0400 Subject: [PATCH] metal: more work on MSAA textures --- src/modules/graphics/metal/Texture.h | 3 ++- src/modules/graphics/metal/Texture.mm | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/metal/Texture.h b/src/modules/graphics/metal/Texture.h index adf328177..04d71dbfb 100644 --- a/src/modules/graphics/metal/Texture.h +++ b/src/modules/graphics/metal/Texture.h @@ -45,7 +45,7 @@ public: void setSamplerState(const SamplerState &s) override; ptrdiff_t getHandle() const override { return (ptrdiff_t) texture; } - ptrdiff_t getRenderTargetHandle() const override { return (ptrdiff_t) texture; /* TODO */ } + ptrdiff_t getRenderTargetHandle() const override { return msaaTexture != nil ? (ptrdiff_t) msaaTexture : (ptrdiff_t) texture; } int getMSAA() const override { return 1 /* TODO*/; } private: @@ -53,6 +53,7 @@ private: void uploadByteData(PixelFormat pixelformat, const void *data, size_t size, int level, int slice, const Rect &r, love::image::ImageDataBase *imgd = nullptr) override; id texture; + id msaaTexture; id sampler; }; // Texture diff --git a/src/modules/graphics/metal/Texture.mm b/src/modules/graphics/metal/Texture.mm index f1d0cfd8c..01c23d486 100644 --- a/src/modules/graphics/metal/Texture.mm +++ b/src/modules/graphics/metal/Texture.mm @@ -31,6 +31,7 @@ namespace metal Texture::Texture(id device, const Settings &settings, const Slices *data) : love::graphics::Texture(settings, data) , texture(nil) + , msaaTexture(nil) , sampler(nil) { @autoreleasepool { MTLTextureDescriptor *desc = [MTLTextureDescriptor new]; @@ -38,15 +39,12 @@ Texture::Texture(id device, const Settings &settings, const Slices *d int w = pixelWidth; int h = pixelHeight; - // TODO: sampleCount validation - desc.sampleCount = getRequestedMSAA(); - desc.width = w; desc.height = h; desc.depth = depth; desc.arrayLength = layers; desc.mipmapLevelCount = mipmapCount; - desc.textureType = Metal::getTextureType(texType, (int)desc.sampleCount); + desc.textureType = Metal::getTextureType(texType, 1); desc.pixelFormat = Metal::convertPixelFormat(format, sRGB); desc.storageMode = MTLStorageModePrivate; @@ -60,6 +58,22 @@ Texture::Texture(id device, const Settings &settings, const Slices *d if (texture == nil) throw love::Exception("Out of graphics memory."); + if (getRequestedMSAA() > 1) + { + // TODO: sampleCount validation + desc.sampleCount = getRequestedMSAA(); + desc.textureType = Metal::getTextureType(texType, (int)desc.sampleCount); + desc.usage &= ~MTLTextureUsageShaderRead; + + // TODO: This needs to be cleared, etc. + msaaTexture = [device newTextureWithDescriptor:desc]; + if (msaaTexture == nil) + { + texture = nil; + throw love::Exception("Out of graphics memory."); + } + } + int mipcount = getMipmapCount(); int slicecount = 1; @@ -105,6 +119,7 @@ Texture::Texture(id device, const Settings &settings, const Slices *d Texture::~Texture() { @autoreleasepool { texture = nil; + msaaTexture = nil; sampler = nil; }}