Skip to content

Commit

Permalink
Add mipmap level selection to Metal render targets (google#1310)
Browse files Browse the repository at this point in the history
  • Loading branch information
bejado authored Jun 18, 2019
1 parent c97ba45 commit 0cb08cd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion filament/backend/src/metal/MetalDriver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
};

construct_handle<MetalRenderTarget>(mHandleMap, rth, mContext, width, height, samples,
getColorTexture(), getDepthTexture(), color.level);
getColorTexture(), getDepthTexture(), color.level, depth.level);

ASSERT_POSTCONDITION(
!stencil.handle && !(targetBufferFlags & TargetBufferFlags::STENCIL),
Expand Down Expand Up @@ -526,6 +526,7 @@
const auto& colorAttachment = descriptor.colorAttachments[0];
colorAttachment.texture = renderTarget->getColor();
colorAttachment.resolveTexture = discardColor ? nil : renderTarget->getColorResolve();
colorAttachment.level = renderTarget->getColorLevel();
mContext->currentSurfacePixelFormat = colorAttachment.texture.pixelFormat;

// Metal clears the entire attachment without respect to viewport or scissor.
Expand All @@ -544,6 +545,7 @@
depthAttachment.loadAction = renderTarget->getLoadAction(params, TargetBufferFlags::DEPTH);
depthAttachment.storeAction = renderTarget->getStoreAction(params, TargetBufferFlags::DEPTH);
depthAttachment.clearDepth = params.clearDepth;
depthAttachment.level = renderTarget->getDepthLevel();
mContext->currentDepthPixelFormat = descriptor.depthAttachment.texture.pixelFormat;

mContext->currentCommandEncoder =
Expand Down
8 changes: 5 additions & 3 deletions filament/backend/src/metal/MetalHandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct MetalSamplerGroup : public HwSamplerGroup {
class MetalRenderTarget : public HwRenderTarget {
public:
MetalRenderTarget(MetalContext* context, uint32_t width, uint32_t height, uint8_t samples,
id<MTLTexture> color, id<MTLTexture> depth, uint8_t level);
id<MTLTexture> color, id<MTLTexture> depth, uint8_t colorLevel, uint8_t depthLevel);
explicit MetalRenderTarget(MetalContext* context)
: HwRenderTarget(0, 0), context(context), defaultRenderTarget(true) {}
~MetalRenderTarget();
Expand All @@ -162,7 +162,8 @@ class MetalRenderTarget : public HwRenderTarget {
id<MTLTexture> getDepthResolve();
id<MTLTexture> getBlitColorSource();
id<MTLTexture> getBlitDepthSource();
uint8_t getColorLevel() { return level; }
uint8_t getColorLevel() { return colorLevel; }
uint8_t getDepthLevel() { return depthLevel; }

private:
static id<MTLTexture> createMultisampledTexture(id<MTLDevice> device, MTLPixelFormat format,
Expand All @@ -171,7 +172,8 @@ class MetalRenderTarget : public HwRenderTarget {
MetalContext* context;
bool defaultRenderTarget = false;
uint8_t samples = 1;
uint8_t level = 0;
uint8_t colorLevel = 0;
uint8_t depthLevel = 0;

id<MTLTexture> color = nil;
id<MTLTexture> depth = nil;
Expand Down
5 changes: 3 additions & 2 deletions filament/backend/src/metal/MetalHandles.mm
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ static MTLPixelFormat decidePixelFormat(id<MTLDevice> device, TextureFormat form
}

MetalRenderTarget::MetalRenderTarget(MetalContext* context, uint32_t width, uint32_t height,
uint8_t samples, id<MTLTexture> color, id<MTLTexture> depth, uint8_t level)
: HwRenderTarget(width, height), context(context), samples(samples), level(level) {
uint8_t samples, id<MTLTexture> color, id<MTLTexture> depth, uint8_t colorLevel,
uint8_t depthLevel) : HwRenderTarget(width, height), context(context), samples(samples),
colorLevel(colorLevel), depthLevel(depthLevel) {
ASSERT_PRECONDITION(color || depth, "Must provide either a color or depth texture.");

[color retain];
Expand Down

0 comments on commit 0cb08cd

Please sign in to comment.