Rename GrStencilAttachment class to generic GrAttachment

Additional this adds a UsageFlags member to the new GrAttachment
class.

Bug: skia:10727
Change-Id: Ifc0bfffd959f5fbc46bfcdf269e1b2a933929753
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323107
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Greg Daniel 2020-10-08 14:59:00 -04:00 committed by Skia Commit-Bot
parent 69f3cab837
commit 6113d50ec4
64 changed files with 826 additions and 783 deletions

View File

@ -33,6 +33,8 @@ skia_gpu_sources = [
"$_src/gpu/GrAHardwareBufferUtils.cpp",
"$_src/gpu/GrAHardwareBufferUtils.h",
"$_src/gpu/GrAppliedClip.h",
"$_src/gpu/GrAttachment.cpp",
"$_src/gpu/GrAttachment.h",
"$_src/gpu/GrAuditTrail.cpp",
"$_src/gpu/GrAuditTrail.h",
"$_src/gpu/GrAutoLocaleSetter.h",
@ -210,8 +212,6 @@ skia_gpu_sources = [
"$_src/gpu/GrSoftwarePathRenderer.h",
"$_src/gpu/GrStagingBufferManager.cpp",
"$_src/gpu/GrStagingBufferManager.h",
"$_src/gpu/GrStencilAttachment.cpp",
"$_src/gpu/GrStencilAttachment.h",
"$_src/gpu/GrStencilClip.h",
"$_src/gpu/GrStencilMaskHelper.cpp",
"$_src/gpu/GrStencilMaskHelper.h",
@ -521,13 +521,13 @@ skia_gpu_sources = [
"$_src/gpu/glsl/GrGLSLXferProcessor.h",
# Mock
"$_src/gpu/mock/GrMockAttachment.h",
"$_src/gpu/mock/GrMockBuffer.h",
"$_src/gpu/mock/GrMockCaps.cpp",
"$_src/gpu/mock/GrMockCaps.h",
"$_src/gpu/mock/GrMockGpu.cpp",
"$_src/gpu/mock/GrMockGpu.h",
"$_src/gpu/mock/GrMockOpsRenderPass.h",
"$_src/gpu/mock/GrMockStencilAttachment.h",
"$_src/gpu/mock/GrMockTexture.h",
"$_src/gpu/mock/GrMockTypes.cpp",
@ -559,6 +559,8 @@ skia_gl_gpu_sources = [
"$_src/gpu/gl/GrGLAssembleHelpers.cpp",
"$_src/gpu/gl/GrGLAssembleInterface.cpp",
"$_src/gpu/gl/GrGLAssembleWebGLInterfaceAutogen.cpp",
"$_src/gpu/gl/GrGLAttachment.cpp",
"$_src/gpu/gl/GrGLAttachment.h",
"$_src/gpu/gl/GrGLBuffer.cpp",
"$_src/gpu/gl/GrGLBuffer.h",
"$_src/gpu/gl/GrGLCaps.cpp",
@ -583,8 +585,6 @@ skia_gl_gpu_sources = [
"$_src/gpu/gl/GrGLRenderTarget.h",
"$_src/gpu/gl/GrGLSemaphore.cpp",
"$_src/gpu/gl/GrGLSemaphore.h",
"$_src/gpu/gl/GrGLStencilAttachment.cpp",
"$_src/gpu/gl/GrGLStencilAttachment.h",
"$_src/gpu/gl/GrGLTexture.cpp",
"$_src/gpu/gl/GrGLTexture.h",
"$_src/gpu/gl/GrGLTextureRenderTarget.cpp",
@ -687,6 +687,8 @@ skia_vk_sources = [
"$_include/private/GrVkTypesPriv.h",
"$_src/gpu/vk/GrVkAMDMemoryAllocator.cpp",
"$_src/gpu/vk/GrVkAMDMemoryAllocator.h",
"$_src/gpu/vk/GrVkAttachment.cpp",
"$_src/gpu/vk/GrVkAttachment.h",
"$_src/gpu/vk/GrVkBuffer.cpp",
"$_src/gpu/vk/GrVkBuffer.h",
"$_src/gpu/vk/GrVkCaps.cpp",
@ -743,8 +745,6 @@ skia_vk_sources = [
"$_src/gpu/vk/GrVkSecondaryCBDrawContext.h",
"$_src/gpu/vk/GrVkSemaphore.cpp",
"$_src/gpu/vk/GrVkSemaphore.h",
"$_src/gpu/vk/GrVkStencilAttachment.cpp",
"$_src/gpu/vk/GrVkStencilAttachment.h",
"$_src/gpu/vk/GrVkTexture.cpp",
"$_src/gpu/vk/GrVkTexture.h",
"$_src/gpu/vk/GrVkTextureRenderTarget.cpp",
@ -769,6 +769,8 @@ skia_direct3d_sources = [
"$_include/private/GrD3DTypesPriv.h",
"$_src/gpu/d3d/GrD3DAMDMemoryAllocator.cpp",
"$_src/gpu/d3d/GrD3DAMDMemoryAllocator.h",
"$_src/gpu/d3d/GrD3DAttachment.cpp",
"$_src/gpu/d3d/GrD3DAttachment.h",
"$_src/gpu/d3d/GrD3DBuffer.cpp",
"$_src/gpu/d3d/GrD3DBuffer.h",
"$_src/gpu/d3d/GrD3DCaps.cpp",
@ -802,8 +804,6 @@ skia_direct3d_sources = [
"$_src/gpu/d3d/GrD3DRootSignature.h",
"$_src/gpu/d3d/GrD3DSemaphore.cpp",
"$_src/gpu/d3d/GrD3DSemaphore.h",
"$_src/gpu/d3d/GrD3DStencilAttachment.cpp",
"$_src/gpu/d3d/GrD3DStencilAttachment.h",
"$_src/gpu/d3d/GrD3DTexture.cpp",
"$_src/gpu/d3d/GrD3DTexture.h",
"$_src/gpu/d3d/GrD3DTextureRenderTarget.cpp",
@ -817,6 +817,8 @@ skia_direct3d_sources = [
skia_dawn_sources = [
"$_include/gpu/dawn/GrDawnTypes.h",
"$_src/gpu/dawn/GrDawnAttachment.cpp",
"$_src/gpu/dawn/GrDawnAttachment.h",
"$_src/gpu/dawn/GrDawnBuffer.cpp",
"$_src/gpu/dawn/GrDawnBuffer.h",
"$_src/gpu/dawn/GrDawnCaps.cpp",
@ -833,8 +835,6 @@ skia_dawn_sources = [
"$_src/gpu/dawn/GrDawnRenderTarget.h",
"$_src/gpu/dawn/GrDawnRingBuffer.cpp",
"$_src/gpu/dawn/GrDawnRingBuffer.h",
"$_src/gpu/dawn/GrDawnStencilAttachment.cpp",
"$_src/gpu/dawn/GrDawnStencilAttachment.h",
"$_src/gpu/dawn/GrDawnTexture.cpp",
"$_src/gpu/dawn/GrDawnTexture.h",
"$_src/gpu/dawn/GrDawnTextureRenderTarget.cpp",
@ -845,6 +845,8 @@ skia_dawn_sources = [
skia_metal_sources = [
"$_include/gpu/mtl/GrMtlTypes.h",
"$_src/gpu/mtl/GrMtlAttachment.h",
"$_src/gpu/mtl/GrMtlAttachment.mm",
"$_src/gpu/mtl/GrMtlBuffer.h",
"$_src/gpu/mtl/GrMtlBuffer.mm",
"$_src/gpu/mtl/GrMtlCaps.h",
@ -872,8 +874,6 @@ skia_metal_sources = [
"$_src/gpu/mtl/GrMtlSampler.mm",
"$_src/gpu/mtl/GrMtlSemaphore.h",
"$_src/gpu/mtl/GrMtlSemaphore.mm",
"$_src/gpu/mtl/GrMtlStencilAttachment.h",
"$_src/gpu/mtl/GrMtlStencilAttachment.mm",
"$_src/gpu/mtl/GrMtlTexture.h",
"$_src/gpu/mtl/GrMtlTexture.mm",
"$_src/gpu/mtl/GrMtlTextureRenderTarget.h",

23
src/gpu/GrAttachment.cpp Normal file
View File

@ -0,0 +1,23 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/GrAttachment.h"
#include "include/private/GrResourceKey.h"
void GrAttachment::ComputeSharedAttachmentUniqueKey(SkISize dimensions,
UsageFlags requiredUsage,
int sampleCnt,
GrUniqueKey* key) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kDomain, 4);
builder[0] = dimensions.width();
builder[1] = dimensions.height();
builder[2] = (uint32_t)requiredUsage;
builder[2] = sampleCnt;
}

70
src/gpu/GrAttachment.h Normal file
View File

@ -0,0 +1,70 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrAttachment_DEFINED
#define GrAttachment_DEFINED
#include "src/core/SkClipStack.h"
#include "src/gpu/GrSurface.h"
class GrRenderTarget;
class GrResourceKey;
/**
* This is a generic attachment class for out GrSurfaces. It always represents a single gpu
* allocation. It contains usage flags so that we know what the attachment can be used for.
*
* TODO: Once we can pull out GrRenderTarget to be more of a framebuffer and break apart our
* texture render target diamond, we will merge this class with GrSurface. Until then this will
* act as the staging class for the new surface and framebuffer world.
*/
class GrAttachment : public GrSurface {
public:
enum class UsageFlags : uint8_t {
kStencil = 0x1,
};
GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(UsageFlags);
~GrAttachment() override {}
UsageFlags supportedUsages() const { return fSupportedUsages; }
int numSamples() const { return fSampleCnt; }
bool hasPerformedInitialClear() const { return fHasPerformedInitialClear; }
void markHasPerformedInitialClear() { fHasPerformedInitialClear = true; }
// This unique key is used for attachments of the same dimensions, usage, and sample cnt which
// are shared between multiple render targets at the same time. Only one usage flag may be
// passed in.
// TODO: Once attachments start having multiple usages, we'll need to figure out how to search
// the cache for an attachment that simply contains the requested usage instead of equaling it.
static void ComputeSharedAttachmentUniqueKey(SkISize dimensions,
UsageFlags requiredUsage,
int sampleCnt,
GrUniqueKey* key);
protected:
GrAttachment(GrGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt,
GrProtected isProtected)
: INHERITED(gpu, dimensions, isProtected)
, fSupportedUsages(supportedUsages)
, fSampleCnt(sampleCnt) {}
private:
const char* getResourceType() const override { return "Stencil"; }
UsageFlags fSupportedUsages;
int fSampleCnt;
bool fHasPerformedInitialClear = false;
using INHERITED = GrSurface;
};
GR_MAKE_BITFIELD_CLASS_OPS(GrAttachment::UsageFlags);
#endif

View File

@ -13,6 +13,7 @@
#include "src/core/SkTaskGroup.h"
#include "src/core/SkTraceEvent.h"
#include "src/gpu/GrAppliedClip.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrDeferredProxyUploader.h"
#include "src/gpu/GrDrawingManager.h"
@ -21,7 +22,6 @@
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContextPriv.h"
#include "src/gpu/GrSWMaskHelper.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrStyle.h"
#include "src/gpu/GrTextureProxy.h"
#include "src/gpu/effects/GrBlendFragmentProcessor.h"

View File

@ -14,6 +14,7 @@
#include "src/core/SkCompressedDataUtils.h"
#include "src/core/SkMathPriv.h"
#include "src/core/SkMipmap.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrAuditTrail.h"
#include "src/gpu/GrBackendUtils.h"
#include "src/gpu/GrCaps.h"
@ -29,7 +30,6 @@
#include "src/gpu/GrRingBuffer.h"
#include "src/gpu/GrSemaphore.h"
#include "src/gpu/GrStagingBufferManager.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrStencilSettings.h"
#include "src/gpu/GrTextureProxyPriv.h"
#include "src/gpu/GrTracing.h"

View File

@ -36,7 +36,7 @@ class GrRenderTarget;
class GrRingBuffer;
class GrSemaphore;
class GrStagingBufferManager;
class GrStencilAttachment;
class GrAttachment;
class GrStencilSettings;
class GrSurface;
class GrTexture;
@ -352,15 +352,14 @@ public:
// If a 'stencil' is provided it will be the one bound to 'renderTarget'. If one is not
// provided but 'renderTarget' has a stencil buffer then that is a signal that the
// render target's stencil buffer should be ignored.
virtual GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget* renderTarget,
GrStencilAttachment* stencil,
GrSurfaceOrigin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) = 0;
virtual GrOpsRenderPass* getOpsRenderPass(GrRenderTarget* renderTarget,
GrAttachment* stencil,
GrSurfaceOrigin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) = 0;
// Called by GrDrawingManager when flushing.
// Provides a hook for post-flush actions (e.g. Vulkan command buffer submits). This will also
@ -706,9 +705,10 @@ public:
// width and height may be larger than rt (if underlying API allows it).
// Returns nullptr if compatible sb could not be created, otherwise the caller owns the ref on
// the GrStencilAttachment.
virtual GrStencilAttachment* createStencilAttachmentForRenderTarget(
const GrRenderTarget*, SkISize dimensions, int numStencilSamples) = 0;
// the GrAttachment.
virtual sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*,
SkISize dimensions,
int numStencilSamples) = 0;
void handleDirtyContext() {
if (fResetBits) {

View File

@ -11,6 +11,7 @@
#include "src/core/SkRectPriv.h"
#include "src/core/SkScopeExit.h"
#include "src/core/SkTraceEvent.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrAuditTrail.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrGpu.h"
@ -21,7 +22,6 @@
#include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrResourceAllocator.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/geometry/GrRect.h"
#include "src/gpu/ops/GrClearOp.h"
@ -484,12 +484,17 @@ void GrOpsTask::onPrepare(GrOpFlushState* flushState) {
flushState->setSampledProxyArray(nullptr);
}
static GrOpsRenderPass* create_render_pass(
GrGpu* gpu, GrRenderTarget* rt, GrStencilAttachment* stencil, GrSurfaceOrigin origin,
const SkIRect& bounds, GrLoadOp colorLoadOp, const SkPMColor4f& loadClearColor,
GrLoadOp stencilLoadOp, GrStoreOp stencilStoreOp,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) {
static GrOpsRenderPass* create_render_pass(GrGpu* gpu,
GrRenderTarget* rt,
GrAttachment* stencil,
GrSurfaceOrigin origin,
const SkIRect& bounds,
GrLoadOp colorLoadOp,
const SkPMColor4f& loadClearColor,
GrLoadOp stencilLoadOp,
GrStoreOp stencilStoreOp,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) {
const GrOpsRenderPass::LoadAndStoreInfo kColorLoadStoreInfo {
colorLoadOp,
GrStoreOp::kStore,
@ -536,7 +541,7 @@ bool GrOpsTask::onExecute(GrOpFlushState* flushState) {
GrRenderTarget* renderTarget = proxy->peekRenderTarget();
SkASSERT(renderTarget);
GrStencilAttachment* stencil = nullptr;
GrAttachment* stencil = nullptr;
if (int numStencilSamples = proxy->numStencilSamples()) {
if (!flushState->resourceProvider()->attachStencilAttachment(
renderTarget, numStencilSamples)) {

View File

@ -9,18 +9,18 @@
#include "src/gpu/GrRenderTarget.h"
#include "src/core/SkRectPriv.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrBackendUtils.h"
#include "src/gpu/GrGpu.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrSamplePatternDictionary.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrStencilSettings.h"
GrRenderTarget::GrRenderTarget(GrGpu* gpu,
const SkISize& dimensions,
int sampleCount,
GrProtected isProtected,
GrStencilAttachment* stencil)
GrAttachment* stencil)
: INHERITED(gpu, dimensions, isProtected)
, fStencilAttachment(stencil)
, fSampleCnt(sampleCount)
@ -40,7 +40,7 @@ void GrRenderTarget::onAbandon() {
INHERITED::onAbandon();
}
void GrRenderTarget::attachStencilAttachment(sk_sp<GrStencilAttachment> stencil) {
void GrRenderTarget::attachStencilAttachment(sk_sp<GrAttachment> stencil) {
#ifdef SK_DEBUG
if (fSampleCnt == 1) {
// TODO: We don't expect a mixed sampled render target to ever change its stencil buffer

View File

@ -12,7 +12,7 @@
#include "src/gpu/GrSurface.h"
class GrCaps;
class GrStencilAttachment;
class GrAttachment;
class GrBackendRenderTarget;
/**
@ -41,11 +41,11 @@ public:
virtual GrBackendRenderTarget getBackendRenderTarget() const = 0;
GrStencilAttachment* getStencilAttachment() const { return fStencilAttachment.get(); }
GrAttachment* getStencilAttachment() const { return fStencilAttachment.get(); }
// Checked when this object is asked to attach a stencil buffer.
virtual bool canAttemptStencilAttachment() const = 0;
void attachStencilAttachment(sk_sp<GrStencilAttachment> stencil);
void attachStencilAttachment(sk_sp<GrAttachment> stencil);
int numStencilBits() const;
@ -63,8 +63,7 @@ public:
const SkTArray<SkPoint>& getSampleLocations();
protected:
GrRenderTarget(GrGpu*, const SkISize&, int sampleCount, GrProtected,
GrStencilAttachment* = nullptr);
GrRenderTarget(GrGpu*, const SkISize&, int sampleCount, GrProtected, GrAttachment* = nullptr);
~GrRenderTarget() override;
// override of GrResource
@ -73,12 +72,12 @@ protected:
private:
// Allows the backends to perform any additional work that is required for attaching a
// GrStencilAttachment. When this is called, the GrStencilAttachment has already been put onto
// GrAttachment. When this is called, the GrAttachment has already been put onto
// the GrRenderTarget. This function must return false if any failures occur when completing the
// stencil attachment.
virtual bool completeStencilAttachment() = 0;
sk_sp<GrStencilAttachment> fStencilAttachment;
sk_sp<GrAttachment> fStencilAttachment;
int fSampleCnt;
int fSamplePatternKey;

View File

@ -25,6 +25,7 @@
#include "src/core/SkRRectPriv.h"
#include "src/core/SkSurfacePriv.h"
#include "src/gpu/GrAppliedClip.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrAuditTrail.h"
#include "src/gpu/GrBlurUtils.h"
#include "src/gpu/GrCaps.h"
@ -42,7 +43,6 @@
#include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrRenderTargetContextPriv.h"
#include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrStyle.h"
#include "src/gpu/GrTracing.h"
#include "src/gpu/SkGr.h"

View File

@ -7,8 +7,8 @@
#include "src/gpu/GrRenderTask.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrTextureProxyPriv.h"
#include "src/gpu/GrTextureResolveRenderTask.h"

View File

@ -12,6 +12,7 @@
#include "include/private/GrSingleOwner.h"
#include "src/core/SkConvertPixels.h"
#include "src/core/SkMathPriv.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrDataUtils.h"
#include "src/gpu/GrGpu.h"
@ -23,7 +24,6 @@
#include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrResourceCache.h"
#include "src/gpu/GrSemaphore.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/SkGr.h"
@ -491,7 +491,7 @@ sk_sp<GrGpuBuffer> GrResourceProvider::createBuffer(size_t size, GrGpuBufferType
bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt, int numStencilSamples) {
SkASSERT(rt);
GrStencilAttachment* stencil = rt->getStencilAttachment();
GrAttachment* stencil = rt->getStencilAttachment();
if (stencil && stencil->numSamples() == numStencilSamples) {
return true;
}
@ -505,13 +505,13 @@ bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt, int numSten
height = SkNextPow2(height);
}
#endif
GrStencilAttachment::ComputeSharedStencilAttachmentKey(
rt->dimensions(), numStencilSamples, &sbKey);
auto stencil = this->findByUniqueKey<GrStencilAttachment>(sbKey);
GrAttachment::ComputeSharedAttachmentUniqueKey(
rt->dimensions(), GrAttachment::UsageFlags::kStencil, numStencilSamples, &sbKey);
auto stencil = this->findByUniqueKey<GrAttachment>(sbKey);
if (!stencil) {
// Need to try and create a new stencil
stencil.reset(this->gpu()->createStencilAttachmentForRenderTarget(
rt, rt->dimensions(), numStencilSamples));
stencil = this->gpu()->makeStencilAttachmentForRenderTarget(rt, rt->dimensions(),
numStencilSamples);
if (!stencil) {
return false;
}
@ -520,7 +520,7 @@ bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt, int numSten
rt->attachStencilAttachment(std::move(stencil));
}
if (GrStencilAttachment* stencil = rt->getStencilAttachment()) {
if (GrAttachment* stencil = rt->getStencilAttachment()) {
return stencil->numSamples() == numStencilSamples;
}
return false;

View File

@ -23,7 +23,7 @@ class GrRenderTarget;
class GrResourceProviderPriv;
class GrSemaphore;
class GrSingleOwner;
class GrStencilAttachment;
class GrAttachment;
class GrTexture;
struct GrVkDrawableInfo;

View File

@ -1,19 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/private/GrResourceKey.h"
#include "src/gpu/GrStencilAttachment.h"
void GrStencilAttachment::ComputeSharedStencilAttachmentKey(SkISize dimensions,
int sampleCnt,
GrUniqueKey* key) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kDomain, 3);
builder[0] = dimensions.width();
builder[1] = dimensions.height();
builder[2] = sampleCnt;
}

View File

@ -1,49 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrStencilAttachment_DEFINED
#define GrStencilAttachment_DEFINED
#include "src/core/SkClipStack.h"
#include "src/gpu/GrSurface.h"
class GrRenderTarget;
class GrResourceKey;
class GrStencilAttachment : public GrSurface {
public:
~GrStencilAttachment() override {
// TODO: allow SB to be purged and detach itself from rts
}
int numSamples() const { return fSampleCnt; }
bool hasPerformedInitialClear() const { return fHasPerformedInitialClear; }
void markHasPerformedInitialClear() { fHasPerformedInitialClear = true; }
// We create a unique stencil buffer at each width, height and sampleCnt and share it for
// all render targets that require a stencil with those params.
static void ComputeSharedStencilAttachmentKey(SkISize dimensions, int sampleCnt,
GrUniqueKey* key);
protected:
GrStencilAttachment(GrGpu* gpu, SkISize dimensions, int sampleCnt, GrProtected isProtected)
: INHERITED(gpu, dimensions, isProtected)
, fSampleCnt(sampleCnt) {
}
private:
const char* getResourceType() const override { return "Stencil"; }
int fSampleCnt;
bool fHasPerformedInitialClear = false;
using INHERITED = GrSurface;
};
#endif

View File

@ -11,6 +11,7 @@
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkMathPriv.h"
#include "src/core/SkMipmap.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrClip.h"
#include "src/gpu/GrGpuResourcePriv.h"
@ -18,7 +19,6 @@
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrSurface.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureRenderTargetProxy.h"

View File

@ -5,28 +5,29 @@
* found in the LICENSE file.
*/
#include "src/gpu/d3d/GrD3DStencilAttachment.h"
#include "src/gpu/d3d/GrD3DAttachment.h"
#include "src/gpu/d3d/GrD3DGpu.h"
GrD3DStencilAttachment::GrD3DStencilAttachment(GrD3DGpu* gpu,
SkISize dimensions,
DXGI_FORMAT format,
const D3D12_RESOURCE_DESC& desc,
const GrD3DTextureResourceInfo& info,
sk_sp<GrD3DResourceState> state,
const GrD3DDescriptorHeap::CPUHandle& view)
: GrStencilAttachment(gpu, dimensions, desc.SampleDesc.Count, GrProtected::kNo)
GrD3DAttachment::GrD3DAttachment(GrD3DGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
DXGI_FORMAT format,
const D3D12_RESOURCE_DESC& desc,
const GrD3DTextureResourceInfo& info,
sk_sp<GrD3DResourceState> state,
const GrD3DDescriptorHeap::CPUHandle& view)
: GrAttachment(gpu, dimensions, supportedUsages, desc.SampleDesc.Count, GrProtected::kNo)
, GrD3DTextureResource(info, state)
, fView(view)
, fFormat(format) {
this->registerWithCache(SkBudgeted::kYes);
}
GrD3DStencilAttachment* GrD3DStencilAttachment::Make(GrD3DGpu* gpu,
SkISize dimensions,
int sampleCnt,
DXGI_FORMAT format) {
sk_sp<GrD3DAttachment> GrD3DAttachment::MakeStencil(GrD3DGpu* gpu,
SkISize dimensions,
int sampleCnt,
DXGI_FORMAT format) {
D3D12_RESOURCE_DESC resourceDesc = {};
resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
resourceDesc.Alignment = 0; // default alignment
@ -56,13 +57,12 @@ GrD3DStencilAttachment* GrD3DStencilAttachment::Make(GrD3DGpu* gpu,
gpu->resourceProvider().createDepthStencilView(info.fResource.get());
sk_sp<GrD3DResourceState> state(new GrD3DResourceState(info.fResourceState));
GrD3DStencilAttachment* stencil = new GrD3DStencilAttachment(gpu, dimensions, format,
resourceDesc, info,
std::move(state), view);
return stencil;
return sk_sp<GrD3DAttachment>(new GrD3DAttachment(gpu, dimensions, UsageFlags::kStencil,
format, resourceDesc, info,
std::move(state), view));
}
size_t GrD3DStencilAttachment::onGpuMemorySize() const {
size_t GrD3DAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= GrD3DCaps::GetStencilFormatTotalBitCount(this->dxgiFormat());
@ -70,21 +70,21 @@ size_t GrD3DStencilAttachment::onGpuMemorySize() const {
return static_cast<size_t>(size / 8);
}
void GrD3DStencilAttachment::onRelease() {
void GrD3DAttachment::onRelease() {
GrD3DGpu* gpu = this->getD3DGpu();
this->releaseResource(gpu);
GrStencilAttachment::onRelease();
GrAttachment::onRelease();
}
void GrD3DStencilAttachment::onAbandon() {
void GrD3DAttachment::onAbandon() {
GrD3DGpu* gpu = this->getD3DGpu();
this->releaseResource(gpu);
GrStencilAttachment::onAbandon();
GrAttachment::onAbandon();
}
GrD3DGpu* GrD3DStencilAttachment::getD3DGpu() const {
GrD3DGpu* GrD3DAttachment::getD3DGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrD3DGpu*>(this->getGpu());
}

View File

@ -0,0 +1,54 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrD3DAttachment_DEFINED
#define GrD3DAttachment_DEFINED
#include "src/gpu/GrAttachment.h"
#include "include/gpu/d3d/GrD3DTypes.h"
#include "src/gpu/d3d/GrD3DDescriptorHeap.h"
#include "src/gpu/d3d/GrD3DTextureResource.h"
class GrD3DGpu;
class GrD3DAttachment : public GrAttachment, public GrD3DTextureResource {
public:
static sk_sp<GrD3DAttachment> MakeStencil(GrD3DGpu* gpu,
SkISize dimensions,
int sampleCnt,
DXGI_FORMAT format);
~GrD3DAttachment() override {}
GrBackendFormat backendFormat() const override { return GrBackendFormat::MakeDxgi(fFormat); }
D3D12_CPU_DESCRIPTOR_HANDLE view() const { return fView.fHandle; }
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrD3DAttachment(GrD3DGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
DXGI_FORMAT format,
const D3D12_RESOURCE_DESC&,
const GrD3DTextureResourceInfo&,
sk_sp<GrD3DResourceState>,
const GrD3DDescriptorHeap::CPUHandle& view);
GrD3DGpu* getD3DGpu() const;
GrD3DDescriptorHeap::CPUHandle fView;
DXGI_FORMAT fFormat;
};
#endif

View File

@ -11,7 +11,7 @@
#include "src/gpu/GrCaps.h"
#include "include/gpu/d3d/GrD3DTypes.h"
#include "src/gpu/d3d/GrD3DStencilAttachment.h"
#include "src/gpu/d3d/GrD3DAttachment.h"
class GrShaderCaps;

View File

@ -8,12 +8,12 @@
#include "src/gpu/d3d/GrD3DCommandList.h"
#include "src/gpu/GrScissorState.h"
#include "src/gpu/d3d/GrD3DAttachment.h"
#include "src/gpu/d3d/GrD3DBuffer.h"
#include "src/gpu/d3d/GrD3DCommandSignature.h"
#include "src/gpu/d3d/GrD3DGpu.h"
#include "src/gpu/d3d/GrD3DPipelineState.h"
#include "src/gpu/d3d/GrD3DRenderTarget.h"
#include "src/gpu/d3d/GrD3DStencilAttachment.h"
#include "src/gpu/d3d/GrD3DTexture.h"
#include "src/gpu/d3d/GrD3DTextureResource.h"
#include "src/gpu/d3d/GrD3DUtil.h"
@ -404,7 +404,7 @@ void GrD3DDirectCommandList::clearRenderTargetView(const GrD3DRenderTarget* rend
color.vec(), numRects, rect);
}
void GrD3DDirectCommandList::clearDepthStencilView(const GrD3DStencilAttachment* stencil,
void GrD3DDirectCommandList::clearDepthStencilView(const GrD3DAttachment* stencil,
uint8_t stencilClearValue,
const D3D12_RECT* rect) {
this->addingWork();
@ -426,7 +426,7 @@ void GrD3DDirectCommandList::setRenderTarget(const GrD3DRenderTarget* renderTarg
D3D12_CPU_DESCRIPTOR_HANDLE dsDescriptor;
D3D12_CPU_DESCRIPTOR_HANDLE* dsDescriptorPtr = nullptr;
if (auto stencil = renderTarget->getStencilAttachment()) {
GrD3DStencilAttachment* d3dStencil = static_cast<GrD3DStencilAttachment*>(stencil);
GrD3DAttachment* d3dStencil = static_cast<GrD3DAttachment*>(stencil);
this->addResource(d3dStencil->resource());
dsDescriptor = d3dStencil->view();
dsDescriptorPtr = &dsDescriptor;

View File

@ -24,7 +24,7 @@ class GrD3DConstantRingBuffer;
class GrD3DPipelineState;
class GrD3DRenderTarget;
class GrD3DRootSignature;
class GrD3DStencilAttachment;
class GrD3DAttachment;
class GrD3DTexture;
class GrD3DTextureResource;
@ -174,7 +174,8 @@ public:
void clearRenderTargetView(const GrD3DRenderTarget* renderTarget, const SkPMColor4f& color,
const D3D12_RECT* rect);
void clearDepthStencilView(const GrD3DStencilAttachment*, uint8_t stencilClearValue,
void clearDepthStencilView(const GrD3DAttachment*,
uint8_t stencilClearValue,
const D3D12_RECT* rect);
void setRenderTarget(const GrD3DRenderTarget* renderTarget);
void resolveSubresourceRegion(const GrD3DTextureResource* dstTexture,

View File

@ -15,11 +15,11 @@
#include "src/gpu/GrDataUtils.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/d3d/GrD3DAMDMemoryAllocator.h"
#include "src/gpu/d3d/GrD3DAttachment.h"
#include "src/gpu/d3d/GrD3DBuffer.h"
#include "src/gpu/d3d/GrD3DCaps.h"
#include "src/gpu/d3d/GrD3DOpsRenderPass.h"
#include "src/gpu/d3d/GrD3DSemaphore.h"
#include "src/gpu/d3d/GrD3DStencilAttachment.h"
#include "src/gpu/d3d/GrD3DTexture.h"
#include "src/gpu/d3d/GrD3DTextureRenderTarget.h"
#include "src/gpu/d3d/GrD3DUtil.h"
@ -116,8 +116,10 @@ void GrD3DGpu::destroyResources() {
}
GrOpsRenderPass* GrD3DGpu::getOpsRenderPass(
GrRenderTarget* rt, GrStencilAttachment*,
GrSurfaceOrigin origin, const SkIRect& bounds,
GrRenderTarget* rt,
GrAttachment*,
GrSurfaceOrigin origin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
@ -964,20 +966,17 @@ sk_sp<GrGpuBuffer> GrD3DGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType
return std::move(buffer);
}
GrStencilAttachment* GrD3DGpu::createStencilAttachmentForRenderTarget(
const GrRenderTarget* rt, SkISize dimensions, int numStencilSamples) {
sk_sp<GrAttachment> GrD3DGpu::makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) {
SkASSERT(numStencilSamples == rt->numSamples() || this->caps()->mixedSamplesSupport());
SkASSERT(dimensions.width() >= rt->width());
SkASSERT(dimensions.height() >= rt->height());
DXGI_FORMAT sFmt = this->d3dCaps().preferredStencilFormat();
GrD3DStencilAttachment* stencil(GrD3DStencilAttachment::Make(this,
dimensions,
numStencilSamples,
sFmt));
fStats.incStencilAttachmentCreates();
return stencil;
return GrD3DAttachment::MakeStencil(this, dimensions, numStencilSamples, sFmt);
}
bool GrD3DGpu::createTextureResourceForBackendSurface(DXGI_FORMAT dxgiFormat,

View File

@ -80,16 +80,18 @@ public:
}
#endif
GrStencilAttachment* createStencilAttachmentForRenderTarget(
const GrRenderTarget*, SkISize dimensions, int numStencilSamples) override;
sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*,
SkISize dimensions,
int numStencilSamples) override;
GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget*, GrStencilAttachment*,
GrSurfaceOrigin, const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
GrOpsRenderPass* getOpsRenderPass(GrRenderTarget*,
GrAttachment*,
GrSurfaceOrigin,
const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
void addResourceBarriers(sk_sp<GrManagedResource> resource,
int numBarriers,

View File

@ -66,7 +66,7 @@ void GrD3DOpsRenderPass::onBegin() {
}
if (auto stencil = d3dRT->getStencilAttachment()) {
GrD3DStencilAttachment* d3dStencil = static_cast<GrD3DStencilAttachment*>(stencil);
GrD3DAttachment* d3dStencil = static_cast<GrD3DAttachment*>(stencil);
d3dStencil->setResourceState(fGpu, D3D12_RESOURCE_STATE_DEPTH_WRITE);
if (fStencilLoadOp == GrLoadOp::kClear) {
fGpu->currentCommandList()->clearDepthStencilView(d3dStencil, 0, nullptr);
@ -322,7 +322,7 @@ void GrD3DOpsRenderPass::onClear(const GrScissorState& scissor, const SkPMColor4
}
void GrD3DOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool insideStencilMask) {
GrStencilAttachment* sb = fRenderTarget->getStencilAttachment();
GrAttachment* sb = fRenderTarget->getStencilAttachment();
// this should only be called internally when we know we have a
// stencil buffer.
SkASSERT(sb);
@ -338,7 +338,7 @@ void GrD3DOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool
D3D12_RECT clearRect = scissor_to_d3d_clear_rect(scissor, fRenderTarget, fOrigin);
auto d3dStencil = static_cast<GrD3DStencilAttachment*>(sb);
auto d3dStencil = static_cast<GrD3DAttachment*>(sb);
fGpu->currentCommandList()->clearDepthStencilView(d3dStencil, stencilColor, &clearRect);
}

View File

@ -184,7 +184,7 @@ GrD3DGpu* GrD3DRenderTarget::getD3DGpu() const {
DXGI_FORMAT GrD3DRenderTarget::stencilDxgiFormat() const {
if (auto stencil = this->getStencilAttachment()) {
auto d3dStencil = static_cast<GrD3DStencilAttachment*>(stencil);
auto d3dStencil = static_cast<GrD3DAttachment*>(stencil);
return d3dStencil->dxgiFormat();
}
return DXGI_FORMAT_UNKNOWN;
@ -195,7 +195,7 @@ void GrD3DRenderTarget::genKey(GrProcessorKeyBuilder* b) const {
b->add32(this->numSamples());
b->add32(this->stencilDxgiFormat());
#ifdef SK_DEBUG
if (const GrStencilAttachment* stencil = this->getStencilAttachment()) {
if (const GrAttachment* stencil = this->getStencilAttachment()) {
SkASSERT(stencil->numSamples() == this->numSamples());
}
#endif

View File

@ -1,53 +0,0 @@
/*
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrD3DStencilAttachment_DEFINED
#define GrD3DStencilAttachment_DEFINED
#include "src/gpu/GrStencilAttachment.h"
#include "include/gpu/d3d/GrD3DTypes.h"
#include "src/gpu/d3d/GrD3DDescriptorHeap.h"
#include "src/gpu/d3d/GrD3DTextureResource.h"
class GrD3DGpu;
class GrD3DStencilAttachment : public GrStencilAttachment, public GrD3DTextureResource {
public:
static GrD3DStencilAttachment* Make(GrD3DGpu* gpu, SkISize dimensions, int sampleCnt,
DXGI_FORMAT format);
~GrD3DStencilAttachment() override {}
GrBackendFormat backendFormat() const override { return GrBackendFormat::MakeDxgi(fFormat); }
D3D12_CPU_DESCRIPTOR_HANDLE view() const {
return fView.fHandle;
}
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrD3DStencilAttachment(GrD3DGpu* gpu,
SkISize dimensions,
DXGI_FORMAT format,
const D3D12_RESOURCE_DESC&,
const GrD3DTextureResourceInfo&,
sk_sp<GrD3DResourceState>,
const GrD3DDescriptorHeap::CPUHandle& view);
GrD3DGpu* getD3DGpu() const;
GrD3DDescriptorHeap::CPUHandle fView;
DXGI_FORMAT fFormat;
};
#endif

View File

@ -0,0 +1,65 @@
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/dawn/GrDawnAttachment.h"
#include "src/gpu/dawn/GrDawnGpu.h"
#include "src/gpu/dawn/GrDawnUtil.h"
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
GrDawnAttachment::GrDawnAttachment(GrDawnGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
int samples,
wgpu::Texture texture,
wgpu::TextureView view)
: INHERITED(gpu, dimensions, supportedUsages, samples, GrProtected::kNo)
, fTexture(texture)
, fView(view) {
this->registerWithCache(SkBudgeted::kYes);
}
sk_sp<GrDawnAttachment> GrDawnAttachment::MakeStencil(GrDawnGpu* gpu,
SkISize dimensions,
int sampleCnt) {
wgpu::TextureDescriptor desc;
desc.usage = wgpu::TextureUsage::OutputAttachment;
desc.size.width = dimensions.width();
desc.size.height = dimensions.height();
desc.size.depth = 1;
desc.format = wgpu::TextureFormat::Depth24PlusStencil8;
wgpu::Texture texture = gpu->device().CreateTexture(&desc);
if (!texture) {
return nullptr;
}
wgpu::TextureView view = texture.CreateView();
if (!view) {
return nullptr;
}
return sk_sp<GrDawnAttachment>(
new GrDawnAttachment(gpu, dimensions, UsageFlags::kStencil, sampleCnt, texture, view));
}
GrDawnAttachment::~GrDawnAttachment() {}
size_t GrDawnAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= 32;
size *= std::max(1, this->numSamples());
return static_cast<size_t>(size / 8);
}
void GrDawnAttachment::onRelease() { GrAttachment::onRelease(); }
void GrDawnAttachment::onAbandon() { GrAttachment::onAbandon(); }
GrDawnGpu* GrDawnAttachment::getDawnGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrDawnGpu*>(this->getGpu());
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrDawnAttachment_DEFINED
#define GrDawnAttachment_DEFINED
#include "src/gpu/GrAttachment.h"
#include "dawn/webgpu_cpp.h"
class GrDawnGpu;
class GrDawnAttachment : public GrAttachment {
public:
static sk_sp<GrDawnAttachment> MakeStencil(GrDawnGpu* gpu, SkISize dimensions, int sampleCnt);
~GrDawnAttachment() override;
wgpu::TextureView view() const { return fView; }
GrBackendFormat backendFormat() const override {
return GrBackendFormat::MakeDawn(wgpu::TextureFormat::Depth24PlusStencil8);
}
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrDawnAttachment(GrDawnGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
int samples,
wgpu::Texture texture,
wgpu::TextureView view);
GrDawnGpu* getDawnGpu() const;
wgpu::Texture fTexture;
wgpu::TextureView fView;
using INHERITED = GrAttachment;
};
#endif

View File

@ -21,12 +21,12 @@
#include "src/gpu/GrSemaphore.h"
#include "src/gpu/GrStencilSettings.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/dawn/GrDawnAttachment.h"
#include "src/gpu/dawn/GrDawnBuffer.h"
#include "src/gpu/dawn/GrDawnCaps.h"
#include "src/gpu/dawn/GrDawnOpsRenderPass.h"
#include "src/gpu/dawn/GrDawnProgramBuilder.h"
#include "src/gpu/dawn/GrDawnRenderTarget.h"
#include "src/gpu/dawn/GrDawnStencilAttachment.h"
#include "src/gpu/dawn/GrDawnTexture.h"
#include "src/gpu/dawn/GrDawnUtil.h"
@ -151,8 +151,10 @@ void GrDawnGpu::disconnect(DisconnectType type) {
///////////////////////////////////////////////////////////////////////////////
GrOpsRenderPass* GrDawnGpu::getOpsRenderPass(
GrRenderTarget* rt, GrStencilAttachment*,
GrSurfaceOrigin origin, const SkIRect& bounds,
GrRenderTarget* rt,
GrAttachment*,
GrSurfaceOrigin origin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
@ -304,13 +306,11 @@ sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendTextureAsRenderTarget(const GrBack
return GrDawnRenderTarget::MakeWrapped(this, dimensions, sampleCnt, info);
}
GrStencilAttachment* GrDawnGpu::createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) {
GrDawnStencilAttachment* stencil(GrDawnStencilAttachment::Create(this, dimensions,
numStencilSamples));
sk_sp<GrAttachment> GrDawnGpu::makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) {
fStats.incStencilAttachmentCreates();
return stencil;
return GrDawnAttachment::MakeStencil(this, dimensions, numStencilSamples);
}
GrBackendTexture GrDawnGpu::onCreateBackendTexture(SkISize dimensions,

View File

@ -61,17 +61,18 @@ public:
void testingOnly_flushGpuAndSync() override;
#endif
GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
SkISize dimensions,
int numStencilSamples) override;
sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*,
SkISize dimensions,
int numStencilSamples) override;
GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget*, GrStencilAttachment*,
GrSurfaceOrigin, const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
GrOpsRenderPass* getOpsRenderPass(GrRenderTarget*,
GrAttachment*,
GrSurfaceOrigin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
SkSL::Compiler* shaderCompiler() const {
return fCompiler.get();

View File

@ -11,11 +11,11 @@
#include "src/gpu/GrPipeline.h"
#include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/dawn/GrDawnAttachment.h"
#include "src/gpu/dawn/GrDawnBuffer.h"
#include "src/gpu/dawn/GrDawnGpu.h"
#include "src/gpu/dawn/GrDawnProgramBuilder.h"
#include "src/gpu/dawn/GrDawnRenderTarget.h"
#include "src/gpu/dawn/GrDawnStencilAttachment.h"
#include "src/gpu/dawn/GrDawnTexture.h"
#include "src/gpu/dawn/GrDawnUtil.h"
#include "src/sksl/SkSLCompiler.h"
@ -57,8 +57,8 @@ wgpu::RenderPassEncoder GrDawnOpsRenderPass::beginRenderPass(wgpu::LoadOp colorO
if (GrTexture* tex = fRenderTarget->asTexture()) {
tex->markMipmapsDirty();
}
auto stencilAttachment =
static_cast<GrDawnStencilAttachment*>(fRenderTarget->getStencilAttachment());
auto stencilAttachment = static_cast<GrDawnAttachment*>(fRenderTarget->getStencilAttachment());
const float *c = fColorInfo.fClearColor.vec();
wgpu::RenderPassColorAttachmentDescriptor colorAttachment;

View File

@ -1,68 +0,0 @@
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/dawn/GrDawnStencilAttachment.h"
#include "src/gpu/dawn/GrDawnGpu.h"
#include "src/gpu/dawn/GrDawnUtil.h"
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
GrDawnStencilAttachment::GrDawnStencilAttachment(GrDawnGpu* gpu,
SkISize dimensions,
int samples,
wgpu::Texture texture,
wgpu::TextureView view)
: INHERITED(gpu, dimensions, samples, GrProtected::kNo)
, fTexture(texture)
, fView(view) {
this->registerWithCache(SkBudgeted::kYes);
}
GrDawnStencilAttachment* GrDawnStencilAttachment::Create(GrDawnGpu* gpu,
SkISize dimensions,
int sampleCnt) {
wgpu::TextureDescriptor desc;
desc.usage = wgpu::TextureUsage::OutputAttachment;
desc.size.width = dimensions.width();
desc.size.height = dimensions.height();
desc.size.depth = 1;
desc.format = wgpu::TextureFormat::Depth24PlusStencil8;
wgpu::Texture texture = gpu->device().CreateTexture(&desc);
if (!texture) {
return nullptr;
}
wgpu::TextureView view = texture.CreateView();
if (!view) {
return nullptr;
}
return new GrDawnStencilAttachment(gpu, dimensions, sampleCnt, texture, view);
}
GrDawnStencilAttachment::~GrDawnStencilAttachment() {
}
size_t GrDawnStencilAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= 32;
size *= std::max(1,this->numSamples());
return static_cast<size_t>(size / 8);
}
void GrDawnStencilAttachment::onRelease() {
GrStencilAttachment::onRelease();
}
void GrDawnStencilAttachment::onAbandon() {
GrStencilAttachment::onAbandon();
}
GrDawnGpu* GrDawnStencilAttachment::getDawnGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrDawnGpu*>(this->getGpu());
}

View File

@ -1,45 +0,0 @@
/*
* Copyright 2019 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrDawnStencil_DEFINED
#define GrDawnStencil_DEFINED
#include "src/gpu/GrStencilAttachment.h"
#include "dawn/webgpu_cpp.h"
class GrDawnGpu;
class GrDawnStencilAttachment : public GrStencilAttachment {
public:
static GrDawnStencilAttachment* Create(GrDawnGpu* gpu, SkISize dimensions, int sampleCnt);
~GrDawnStencilAttachment() override;
wgpu::TextureView view() const { return fView; }
GrBackendFormat backendFormat() const override {
return GrBackendFormat::MakeDawn(wgpu::TextureFormat::Depth24PlusStencil8);
}
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrDawnStencilAttachment(GrDawnGpu* gpu, SkISize dimensions, int samples,
wgpu::Texture texture, wgpu::TextureView view);
GrDawnGpu* getDawnGpu() const;
wgpu::Texture fTexture;
wgpu::TextureView fView;
using INHERITED = GrStencilAttachment;
};
#endif

View File

@ -5,12 +5,12 @@
* found in the LICENSE file.
*/
#include "src/gpu/gl/GrGLAttachment.h"
#include "include/core/SkTraceMemoryDump.h"
#include "src/gpu/gl/GrGLGpu.h"
#include "src/gpu/gl/GrGLStencilAttachment.h"
size_t GrGLStencilAttachment::onGpuMemorySize() const {
size_t GrGLAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= GrGLFormatBytesPerBlock(fFormat);
@ -18,9 +18,9 @@ size_t GrGLStencilAttachment::onGpuMemorySize() const {
return static_cast<size_t>(size);
}
void GrGLStencilAttachment::onRelease() {
void GrGLAttachment::onRelease() {
if (0 != fRenderbufferID) {
GrGLGpu* gpuGL = (GrGLGpu*) this->getGpu();
GrGLGpu* gpuGL = (GrGLGpu*)this->getGpu();
const GrGLInterface* gl = gpuGL->glInterface();
GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID));
fRenderbufferID = 0;
@ -29,20 +29,19 @@ void GrGLStencilAttachment::onRelease() {
INHERITED::onRelease();
}
void GrGLStencilAttachment::onAbandon() {
void GrGLAttachment::onAbandon() {
fRenderbufferID = 0;
INHERITED::onAbandon();
}
GrBackendFormat GrGLStencilAttachment::backendFormat() const {
GrBackendFormat GrGLAttachment::backendFormat() const {
return GrBackendFormat::MakeGL(GrGLFormatToEnum(fFormat), GR_GL_TEXTURE_NONE);
}
void GrGLStencilAttachment::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
const SkString& dumpName) const {
void GrGLAttachment::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
const SkString& dumpName) const {
SkString renderbuffer_id;
renderbuffer_id.appendU32(this->renderbufferID());
traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer",
renderbuffer_id.c_str());
traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer", renderbuffer_id.c_str());
}

View File

@ -5,36 +5,32 @@
* found in the LICENSE file.
*/
#ifndef GrGLStencilAttachment_DEFINED
#define GrGLStencilAttachment_DEFINED
#ifndef GrGLMtlAttachment_DEFINED
#define GrGLMtlAttachment_DEFINED
#include "include/gpu/gl/GrGLInterface.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrAttachment.h"
class GrGLStencilAttachment : public GrStencilAttachment {
class GrGLAttachment : public GrAttachment {
public:
struct IDDesc {
IDDesc() : fRenderbufferID(0) {}
GrGLuint fRenderbufferID;
};
GrGLStencilAttachment(GrGpu* gpu,
const IDDesc& idDesc,
SkISize dimensions,
int sampleCnt,
GrGLFormat format)
: GrStencilAttachment(gpu, dimensions, sampleCnt, GrProtected::kNo)
, fFormat(format)
, fRenderbufferID(idDesc.fRenderbufferID) {
GrGLAttachment(
GrGpu* gpu, const IDDesc& idDesc, SkISize dimensions, UsageFlags supportedUsages,
int sampleCnt, GrGLFormat format)
: GrAttachment(gpu, dimensions, supportedUsages, sampleCnt, GrProtected::kNo)
, fFormat(format)
, fRenderbufferID(idDesc.fRenderbufferID) {
SkASSERT(supportedUsages == UsageFlags::kStencil);
this->registerWithCache(SkBudgeted::kYes);
}
GrBackendFormat backendFormat() const override;
GrGLuint renderbufferID() const {
return fRenderbufferID;
}
GrGLuint renderbufferID() const { return fRenderbufferID; }
GrGLFormat format() const { return fFormat; }
@ -55,7 +51,7 @@ private:
// us how many bits of stencil there are).
GrGLuint fRenderbufferID;
using INHERITED = GrStencilAttachment;
using INHERITED = GrAttachment;
};
#endif

View File

@ -16,7 +16,7 @@
#include "include/private/SkTHash.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrSwizzle.h"
#include "src/gpu/gl/GrGLStencilAttachment.h"
#include "src/gpu/gl/GrGLAttachment.h"
#include "src/gpu/gl/GrGLUtil.h"
class GrGLContextInfo;

View File

@ -31,10 +31,10 @@
#include "src/gpu/GrShaderCaps.h"
#include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/gl/GrGLAttachment.h"
#include "src/gpu/gl/GrGLBuffer.h"
#include "src/gpu/gl/GrGLOpsRenderPass.h"
#include "src/gpu/gl/GrGLSemaphore.h"
#include "src/gpu/gl/GrGLStencilAttachment.h"
#include "src/gpu/gl/GrGLTextureRenderTarget.h"
#include "src/gpu/gl/builders/GrGLShaderStringBuilder.h"
#include "src/sksl/SkSLCompiler.h"
@ -1693,12 +1693,13 @@ GrGLuint GrGLGpu::createTexture(SkISize dimensions,
return 0;
}
GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(
const GrRenderTarget* rt, SkISize dimensions, int numStencilSamples) {
sk_sp<GrAttachment> GrGLGpu::makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) {
SkASSERT(dimensions.width() >= rt->width());
SkASSERT(dimensions.height() >= rt->height());
GrGLStencilAttachment::IDDesc sbDesc;
GrGLAttachment::IDDesc sbDesc;
int sIdx = this->getCompatibleStencilIndex(rt->backendFormat().asGLFormat());
if (sIdx < 0) {
@ -1733,12 +1734,8 @@ GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget(
}
fStats.incStencilAttachmentCreates();
GrGLStencilAttachment* stencil = new GrGLStencilAttachment(this,
sbDesc,
dimensions,
numStencilSamples,
sFmt);
return stencil;
return sk_sp<GrAttachment>(new GrGLAttachment(
this, sbDesc, dimensions, GrAttachment::UsageFlags::kStencil, numStencilSamples, sFmt));
}
////////////////////////////////////////////////////////////////////////////////
@ -2038,7 +2035,7 @@ void GrGLGpu::clearStencilClip(const GrScissorState& scissor, bool insideStencil
SkASSERT(!scissor.enabled() || !this->caps()->performPartialClearsAsDraws());
this->handleDirtyContext();
GrStencilAttachment* sb = target->getStencilAttachment();
GrAttachment* sb = target->getStencilAttachment();
if (!sb) {
// We should only get here if we marked a proxy as requiring a SB. However,
// the SB creation could later fail. Likely clipping is going to go awry now.
@ -2141,7 +2138,7 @@ bool GrGLGpu::readOrTransferPixelsFrom(GrSurface* surface, int left, int top, in
if (reattachStencil) {
auto* stencilAttachment =
static_cast<GrGLStencilAttachment*>(renderTarget->getStencilAttachment());
static_cast<GrGLAttachment*>(renderTarget->getStencilAttachment());
GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT,
GR_GL_RENDERBUFFER, stencilAttachment->renderbufferID()));
}
@ -2178,8 +2175,10 @@ bool GrGLGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int
}
GrOpsRenderPass* GrGLGpu::getOpsRenderPass(
GrRenderTarget* rt, GrStencilAttachment*,
GrSurfaceOrigin origin, const SkIRect& bounds,
GrRenderTarget* rt,
GrAttachment*,
GrSurfaceOrigin origin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,

View File

@ -17,11 +17,11 @@
#include "src/gpu/GrProgramDesc.h"
#include "src/gpu/GrWindowRectsState.h"
#include "src/gpu/GrXferProcessor.h"
#include "src/gpu/gl/GrGLAttachment.h"
#include "src/gpu/gl/GrGLContext.h"
#include "src/gpu/gl/GrGLPathRendering.h"
#include "src/gpu/gl/GrGLProgram.h"
#include "src/gpu/gl/GrGLRenderTarget.h"
#include "src/gpu/gl/GrGLStencilAttachment.h"
#include "src/gpu/gl/GrGLTexture.h"
#include "src/gpu/gl/GrGLVertexArray.h"
@ -119,20 +119,22 @@ public:
void endCommandBuffer(GrRenderTarget*, const GrOpsRenderPass::LoadAndStoreInfo& colorLoadStore,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilLoadStore);
GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget*, GrStencilAttachment*,
GrSurfaceOrigin, const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
GrOpsRenderPass* getOpsRenderPass(GrRenderTarget*,
GrAttachment*,
GrSurfaceOrigin,
const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
void invalidateBoundRenderTarget() {
fHWBoundRenderTargetUniqueID.makeInvalid();
}
GrStencilAttachment* createStencilAttachmentForRenderTarget(
const GrRenderTarget* rt, SkISize dimensions, int numStencilSamples) override;
sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) override;
void deleteBackendTexture(const GrBackendTexture&) override;
bool compile(const GrProgramDesc&, const GrProgramInfo&) override;

View File

@ -25,7 +25,7 @@ GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu,
GrGLFormat format,
int sampleCount,
const IDs& ids,
GrGLStencilAttachment* stencil)
GrGLAttachment* stencil)
: GrSurface(gpu, dimensions, GrProtected::kNo)
, INHERITED(gpu, dimensions, sampleCount, GrProtected::kNo, stencil) {
this->setFlags(gpu->glCaps(), ids);
@ -81,9 +81,9 @@ sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu,
int sampleCount,
const IDs& idDesc,
int stencilBits) {
GrGLStencilAttachment* sb = nullptr;
GrGLAttachment* sb = nullptr;
if (stencilBits) {
GrGLStencilAttachment::IDDesc sbDesc;
GrGLAttachment::IDDesc sbDesc;
// We pick a "fake" actual format that matches the number of stencil bits. When wrapping
// an FBO with some number of stencil bits all we care about in the future is that we have
// a format with the same number of stencil bits. We don't even directly use the format or
@ -92,7 +92,8 @@ sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu,
GrGLFormat sFmt = stencil_bits_to_format(stencilBits);
// Ownership of sb is passed to the GrRenderTarget so doesn't need to be deleted
sb = new GrGLStencilAttachment(gpu, sbDesc, dimensions, sampleCount, sFmt);
sb = new GrGLAttachment(gpu, sbDesc, dimensions, GrAttachment::UsageFlags::kStencil,
sampleCount, sFmt);
}
return sk_sp<GrGLRenderTarget>(
new GrGLRenderTarget(gpu, dimensions, format, sampleCount, idDesc, sb));
@ -103,7 +104,7 @@ GrBackendRenderTarget GrGLRenderTarget::getBackendRenderTarget() const {
fbi.fFBOID = fRTFBOID;
fbi.fFormat = GrGLFormatToEnum(this->format());
int numStencilBits = 0;
if (GrStencilAttachment* stencil = this->getStencilAttachment()) {
if (GrAttachment* stencil = this->getStencilAttachment()) {
numStencilBits = GrBackendFormatStencilBits(stencil->backendFormat());
}
@ -125,7 +126,7 @@ size_t GrGLRenderTarget::onGpuMemorySize() const {
bool GrGLRenderTarget::completeStencilAttachment() {
GrGLGpu* gpu = this->getGLGpu();
const GrGLInterface* interface = gpu->glInterface();
GrStencilAttachment* stencil = this->getStencilAttachment();
GrAttachment* stencil = this->getStencilAttachment();
if (nullptr == stencil) {
GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_STENCIL_ATTACHMENT,
@ -144,7 +145,7 @@ bool GrGLRenderTarget::completeStencilAttachment() {
#endif
return true;
} else {
const GrGLStencilAttachment* glStencil = static_cast<const GrGLStencilAttachment*>(stencil);
const GrGLAttachment* glStencil = static_cast<const GrGLAttachment*>(stencil);
GrGLuint rb = glStencil->renderbufferID();
gpu->invalidateBoundRenderTarget();

View File

@ -15,7 +15,7 @@
class GrGLCaps;
class GrGLGpu;
class GrGLStencilAttachment;
class GrGLAttachment;
class GrGLRenderTarget : public GrRenderTarget {
public:
@ -75,12 +75,8 @@ protected:
private:
// Constructor for instances wrapping backend objects.
GrGLRenderTarget(GrGLGpu*,
const SkISize&,
GrGLFormat,
int sampleCount,
const IDs&,
GrGLStencilAttachment*);
GrGLRenderTarget(
GrGLGpu*, const SkISize&, GrGLFormat, int sampleCount, const IDs&, GrGLAttachment*);
void setFlags(const GrGLCaps&, const IDs&);

View File

@ -5,17 +5,18 @@
* found in the LICENSE file.
*/
#ifndef GrMockStencilAttachment_DEFINED
#define GrMockStencilAttachment_DEFINED
#ifndef GrMockAttachment_DEFINED
#define GrMockAttachment_DEFINED
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrBackendUtils.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/mock/GrMockGpu.h"
class GrMockStencilAttachment : public GrStencilAttachment {
class GrMockAttachment : public GrAttachment {
public:
GrMockStencilAttachment(GrMockGpu* gpu, SkISize dimensions, int sampleCnt)
: INHERITED(gpu, dimensions, sampleCnt, GrProtected::kNo) {
GrMockAttachment(GrMockGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt)
: INHERITED(gpu, dimensions, supportedUsages, sampleCnt, GrProtected::kNo) {
SkASSERT(supportedUsages == UsageFlags::kStencil);
this->registerWithCache(SkBudgeted::kYes);
}
@ -30,7 +31,7 @@ private:
return std::max(1, (int)(bpp)) * this->width() * this->height();
}
using INHERITED = GrStencilAttachment;
using INHERITED = GrAttachment;
};
#endif

View File

@ -5,12 +5,14 @@
* found in the LICENSE file.
*/
#include "src/gpu/mock/GrMockGpu.h"
#include "src/gpu/mock/GrMockAttachment.h"
#include "src/gpu/mock/GrMockBuffer.h"
#include "src/gpu/mock/GrMockCaps.h"
#include "src/gpu/mock/GrMockGpu.h"
#include "src/gpu/mock/GrMockOpsRenderPass.h"
#include "src/gpu/mock/GrMockStencilAttachment.h"
#include "src/gpu/mock/GrMockTexture.h"
#include <atomic>
int GrMockGpu::NextInternalTextureID() {
@ -52,13 +54,14 @@ sk_sp<GrGpu> GrMockGpu::Make(const GrMockOptions* mockOptions,
return sk_sp<GrGpu>(new GrMockGpu(direct, *mockOptions, contextOptions));
}
GrOpsRenderPass* GrMockGpu::getOpsRenderPass(
GrRenderTarget* rt, GrStencilAttachment*,
GrSurfaceOrigin origin, const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) {
GrOpsRenderPass* GrMockGpu::getOpsRenderPass(GrRenderTarget* rt,
GrAttachment*,
GrSurfaceOrigin origin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) {
return new GrMockOpsRenderPass(this, rt, origin, colorInfo);
}
@ -266,11 +269,14 @@ sk_sp<GrGpuBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType
return sk_sp<GrGpuBuffer>(new GrMockBuffer(this, sizeInBytes, type, accessPattern));
}
GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(
const GrRenderTarget* rt, SkISize dimensions, int numStencilSamples) {
sk_sp<GrAttachment> GrMockGpu::makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) {
SkASSERT(numStencilSamples == rt->numSamples());
fStats.incStencilAttachmentCreates();
return new GrMockStencilAttachment(this, dimensions, rt->numSamples());
return sk_sp<GrAttachment>(
new GrMockAttachment(this, dimensions, GrAttachment::UsageFlags::kStencil,
rt->numSamples()));
}
GrBackendTexture GrMockGpu::onCreateBackendTexture(SkISize dimensions,

View File

@ -24,15 +24,14 @@ public:
~GrMockGpu() override {}
GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget*,
GrStencilAttachment*,
GrSurfaceOrigin,
const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
GrOpsRenderPass* getOpsRenderPass(GrRenderTarget*,
GrAttachment*,
GrSurfaceOrigin,
const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
bool waitFence(GrFence) override { return true; }
@ -145,8 +144,9 @@ private:
return true;
}
GrStencilAttachment* createStencilAttachmentForRenderTarget(
const GrRenderTarget*, SkISize dimensions, int numStencilSamples) override;
sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*,
SkISize dimensions,
int numStencilSamples) override;
GrBackendTexture onCreateBackendTexture(SkISize dimensions,
const GrBackendFormat&,
GrRenderable,

View File

@ -8,8 +8,8 @@
#define GrMockTexture_DEFINED
#include "include/gpu/mock/GrMockTypes.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/GrRenderTarget.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/mock/GrMockGpu.h"
@ -115,7 +115,7 @@ public:
GrBackendRenderTarget getBackendRenderTarget() const override {
int numStencilBits = 0;
if (GrStencilAttachment* stencil = this->getStencilAttachment()) {
if (GrAttachment* stencil = this->getStencilAttachment()) {
numStencilBits = GrBackendFormatStencilBits(stencil->backendFormat());
}
return {this->width(), this->height(), this->numSamples(), numStencilBits, fInfo};

View File

@ -0,0 +1,52 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrMtlAttachment_DEFINED
#define GrMtlAttachment_DEFINED
#include "src/gpu/GrAttachment.h"
#import <Metal/Metal.h>
class GrMtlImageView;
class GrMtlGpu;
class GrMtlAttachment : public GrAttachment {
public:
static sk_sp<GrMtlAttachment> MakeStencil(GrMtlGpu* gpu,
SkISize dimensions,
int sampleCnt,
MTLPixelFormat format);
~GrMtlAttachment() override;
GrBackendFormat backendFormat() const override {
return GrBackendFormat::MakeMtl(fView.pixelFormat);
}
MTLPixelFormat mtlFormat() const { return fView.pixelFormat; }
id<MTLTexture> view() const { return fView; }
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrMtlAttachment(GrMtlGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
const id<MTLTexture> View);
GrMtlGpu* getMtlGpu() const;
id<MTLTexture> fView;
};
#endif

View File

@ -0,0 +1,74 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/mtl/GrMtlAttachment.h"
#include "src/gpu/mtl/GrMtlGpu.h"
#include "src/gpu/mtl/GrMtlUtil.h"
#if !__has_feature(objc_arc)
#error This file must be compiled with Arc. Use -fobjc-arc flag
#endif
GrMtlAttachment::GrMtlAttachment(GrMtlGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
const id<MTLTexture> view)
: GrAttachment(gpu, dimensions, supportedUsages, view.sampleCount, GrProtected::kNo)
, fView(view) {
this->registerWithCache(SkBudgeted::kYes);
}
sk_sp<GrMtlAttachment> GrMtlAttachment::MakeStencil(GrMtlGpu* gpu,
SkISize dimensions,
int sampleCnt,
MTLPixelFormat format) {
MTLTextureDescriptor* desc =
[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:format
width:dimensions.width()
height:dimensions.height()
mipmapped:NO];
if (@available(macOS 10.11, iOS 9.0, *)) {
desc.storageMode = MTLStorageModePrivate;
desc.usage = MTLTextureUsageRenderTarget;
}
desc.sampleCount = sampleCnt;
if (sampleCnt > 1) {
desc.textureType = MTLTextureType2DMultisample;
}
return sk_sp<GrMtlAttachment>(
new GrMtlAttachment(gpu, dimensions, UsageFlags::kStencil,
[gpu->device() newTextureWithDescriptor:desc]));
}
GrMtlAttachment::~GrMtlAttachment() {
// should have been released or abandoned first
SkASSERT(!fView);
}
size_t GrMtlAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= GrMtlFormatBytesPerBlock(this->mtlFormat());
size *= this->numSamples();
return static_cast<size_t>(size);
}
void GrMtlAttachment::onRelease() {
fView = nullptr;
GrAttachment::onRelease();
}
void GrMtlAttachment::onAbandon() {
fView = nullptr;
GrAttachment::onAbandon();
}
GrMtlGpu* GrMtlAttachment::getMtlGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrMtlGpu*>(this->getGpu());
}

View File

@ -10,7 +10,7 @@
#include "include/private/SkTDArray.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/mtl/GrMtlStencilAttachment.h"
#include "src/gpu/mtl/GrMtlAttachment.h"
#import <Metal/Metal.h>

View File

@ -16,10 +16,10 @@
#include "src/gpu/GrStagingBufferManager.h"
#include "src/gpu/GrTexture.h"
#include "src/gpu/mtl/GrMtlAttachment.h"
#include "src/gpu/mtl/GrMtlCaps.h"
#include "src/gpu/mtl/GrMtlCommandBuffer.h"
#include "src/gpu/mtl/GrMtlResourceProvider.h"
#include "src/gpu/mtl/GrMtlStencilAttachment.h"
#include "src/gpu/mtl/GrMtlUtil.h"
#import <Metal/Metal.h>
@ -86,7 +86,7 @@ public:
const SkIPoint& dstPoint) override;
GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget*, GrStencilAttachment*,
GrRenderTarget*, GrAttachment*,
GrSurfaceOrigin, const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
@ -238,7 +238,7 @@ private:
GrColorType dstColorType, id<MTLBuffer> transferBuffer, size_t offset,
size_t imageBytes, size_t rowBytes);
GrStencilAttachment* createStencilAttachmentForRenderTarget(
sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(
const GrRenderTarget*, SkISize dimensions, int numStencilSamples) override;
bool createMtlTextureForBackendSurface(MTLPixelFormat,

View File

@ -183,7 +183,7 @@ void GrMtlGpu::destroyResources() {
}
GrOpsRenderPass* GrMtlGpu::getOpsRenderPass(
GrRenderTarget* renderTarget, GrStencilAttachment*,
GrRenderTarget* renderTarget, GrAttachment*,
GrSurfaceOrigin origin, const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
@ -497,7 +497,7 @@ bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) {
return true;
}
GrStencilAttachment* GrMtlGpu::createStencilAttachmentForRenderTarget(
sk_sp<GrAttachment> GrMtlGpu::makeStencilAttachmentForRenderTarget(
const GrRenderTarget* rt, SkISize dimensions, int numStencilSamples) {
SkASSERT(numStencilSamples == rt->numSamples());
SkASSERT(dimensions.width() >= rt->width());
@ -507,12 +507,8 @@ GrStencilAttachment* GrMtlGpu::createStencilAttachmentForRenderTarget(
MTLPixelFormat sFmt = this->mtlCaps().preferredStencilFormat();
GrMtlStencilAttachment* stencil(GrMtlStencilAttachment::Create(this,
dimensions,
samples,
sFmt));
fStats.incStencilAttachmentCreates();
return stencil;
return GrMtlAttachment::GrMtlAttachment::MakeStencil(this, dimensions, samples, sFmt);
}
sk_sp<GrTexture> GrMtlGpu::onCreateTexture(SkISize dimensions,

View File

@ -142,7 +142,7 @@ void GrMtlOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool
// Partial clears are not supported
SkASSERT(!scissor.enabled());
GrStencilAttachment* sb = fRenderTarget->getStencilAttachment();
GrAttachment* sb = fRenderTarget->getStencilAttachment();
// this should only be called internally when we know we have a
// stencil buffer.
SkASSERT(sb);
@ -220,9 +220,9 @@ void GrMtlOpsRenderPass::setupRenderPass(
renderPassDesc.colorAttachments[0].storeAction =
mtlStoreAction[static_cast<int>(colorInfo.fStoreOp)];
auto* stencil = static_cast<GrMtlStencilAttachment*>(fRenderTarget->getStencilAttachment());
auto* stencil = static_cast<GrMtlAttachment*>(fRenderTarget->getStencilAttachment());
if (stencil) {
renderPassDesc.stencilAttachment.texture = stencil->stencilView();
renderPassDesc.stencilAttachment.texture = stencil->view();
}
renderPassDesc.stencilAttachment.clearStencil = 0;
renderPassDesc.stencilAttachment.loadAction =

View File

@ -1,49 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrMtlStencil_DEFINED
#define GrMtlStencil_DEFINED
#include "src/gpu/GrStencilAttachment.h"
#import <Metal/Metal.h>
class GrMtlImageView;
class GrMtlGpu;
class GrMtlStencilAttachment : public GrStencilAttachment {
public:
static GrMtlStencilAttachment* Create(GrMtlGpu* gpu, SkISize dimensions,
int sampleCnt, MTLPixelFormat format);
~GrMtlStencilAttachment() override;
GrBackendFormat backendFormat() const override {
return GrBackendFormat::MakeMtl(fStencilView.pixelFormat);
}
MTLPixelFormat mtlFormat() const { return fStencilView.pixelFormat; }
id<MTLTexture> stencilView() const { return fStencilView; }
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrMtlStencilAttachment(GrMtlGpu* gpu,
SkISize dimensions,
const id<MTLTexture> stencilView);
GrMtlGpu* getMtlGpu() const;
id<MTLTexture> fStencilView;
};
#endif

View File

@ -1,70 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/mtl/GrMtlGpu.h"
#include "src/gpu/mtl/GrMtlUtil.h"
#if !__has_feature(objc_arc)
#error This file must be compiled with Arc. Use -fobjc-arc flag
#endif
GrMtlStencilAttachment::GrMtlStencilAttachment(GrMtlGpu* gpu,
SkISize dimensions,
const id<MTLTexture> stencilView)
: GrStencilAttachment(gpu, dimensions, stencilView.sampleCount, GrProtected::kNo)
, fStencilView(stencilView) {
this->registerWithCache(SkBudgeted::kYes);
}
GrMtlStencilAttachment* GrMtlStencilAttachment::Create(GrMtlGpu* gpu,
SkISize dimensions,
int sampleCnt,
MTLPixelFormat format) {
MTLTextureDescriptor* desc =
[MTLTextureDescriptor texture2DDescriptorWithPixelFormat:format
width:dimensions.width()
height:dimensions.height()
mipmapped:NO];
if (@available(macOS 10.11, iOS 9.0, *)) {
desc.storageMode = MTLStorageModePrivate;
desc.usage = MTLTextureUsageRenderTarget;
}
desc.sampleCount = sampleCnt;
if (sampleCnt > 1) {
desc.textureType = MTLTextureType2DMultisample;
}
return new GrMtlStencilAttachment(gpu, dimensions,
[gpu->device() newTextureWithDescriptor:desc]);
}
GrMtlStencilAttachment::~GrMtlStencilAttachment() {
// should have been released or abandoned first
SkASSERT(!fStencilView);
}
size_t GrMtlStencilAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= GrMtlFormatBytesPerBlock(this->mtlFormat());
size *= this->numSamples();
return static_cast<size_t>(size);
}
void GrMtlStencilAttachment::onRelease() {
fStencilView = nullptr;
GrStencilAttachment::onRelease();
}
void GrMtlStencilAttachment::onAbandon() {
fStencilView = nullptr;
GrStencilAttachment::onAbandon();
}
GrMtlGpu* GrMtlStencilAttachment::getMtlGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrMtlGpu*>(this->getGpu());
}

View File

@ -0,0 +1,96 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/vk/GrVkAttachment.h"
#include "src/gpu/vk/GrVkGpu.h"
#include "src/gpu/vk/GrVkImage.h"
#include "src/gpu/vk/GrVkImageView.h"
#include "src/gpu/vk/GrVkUtil.h"
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
GrVkAttachment::GrVkAttachment(GrVkGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
VkFormat format,
const GrVkImage::ImageDesc& desc,
const GrVkImageInfo& info,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
sk_sp<const GrVkImageView> stencilView)
: GrAttachment(gpu, dimensions, supportedUsages, desc.fSamples, info.fProtected)
, GrVkImage(gpu, info, std::move(mutableState), GrBackendObjectOwnership::kOwned)
, fStencilView(std::move(stencilView)) {
this->registerWithCache(SkBudgeted::kYes);
}
sk_sp<GrVkAttachment> GrVkAttachment::MakeStencil(GrVkGpu* gpu,
SkISize dimensions,
int sampleCnt,
VkFormat format) {
GrVkImage::ImageDesc imageDesc;
imageDesc.fImageType = VK_IMAGE_TYPE_2D;
imageDesc.fFormat = format;
imageDesc.fWidth = dimensions.width();
imageDesc.fHeight = dimensions.height();
imageDesc.fLevels = 1;
imageDesc.fSamples = sampleCnt;
imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
imageDesc.fUsageFlags =
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
GrVkImageInfo info;
if (!GrVkImage::InitImageInfo(gpu, imageDesc, &info)) {
return nullptr;
}
sk_sp<const GrVkImageView> imageView = GrVkImageView::Make(
gpu, info.fImage, format, GrVkImageView::kStencil_Type, 1, GrVkYcbcrConversionInfo());
if (!imageView) {
GrVkImage::DestroyImageInfo(gpu, &info);
return nullptr;
}
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState(
new GrBackendSurfaceMutableStateImpl(info.fImageLayout, info.fCurrentQueueFamily));
return sk_sp<GrVkAttachment>(
new GrVkAttachment(gpu, dimensions, UsageFlags::kStencil, format, imageDesc,
info, std::move(mutableState), std::move(imageView)));
}
GrVkAttachment::~GrVkAttachment() {
// should have been released or abandoned first
SkASSERT(!fStencilView);
}
size_t GrVkAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= GrVkCaps::GetStencilFormatTotalBitCount(this->imageFormat());
size *= this->numSamples();
return static_cast<size_t>(size / 8);
}
void GrVkAttachment::onRelease() {
this->releaseImage();
fStencilView.reset();
GrAttachment::onRelease();
}
void GrVkAttachment::onAbandon() {
this->releaseImage();
fStencilView.reset();
GrAttachment::onAbandon();
}
GrVkGpu* GrVkAttachment::getVkGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrVkGpu*>(this->getGpu());
}

View File

@ -0,0 +1,53 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrVkAttachment_DEFINED
#define GrVkAttachment_DEFINED
#include "include/gpu/vk/GrVkTypes.h"
#include "src/gpu/GrAttachment.h"
#include "src/gpu/vk/GrVkImage.h"
class GrVkImageView;
class GrVkGpu;
class GrVkAttachment : public GrAttachment, public GrVkImage {
public:
static sk_sp<GrVkAttachment> MakeStencil(GrVkGpu* gpu,
SkISize dimensions,
int sampleCnt,
VkFormat format);
~GrVkAttachment() override;
GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
const GrManagedResource* imageResource() const { return this->resource(); }
const GrVkImageView* stencilView() const { return fStencilView.get(); }
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrVkAttachment(GrVkGpu* gpu,
SkISize dimensions,
UsageFlags supportedUsages,
VkFormat format,
const GrVkImage::ImageDesc&,
const GrVkImageInfo&,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
sk_sp<const GrVkImageView> stencilView);
GrVkGpu* getVkGpu() const;
sk_sp<const GrVkImageView> fStencilView;
};
#endif

View File

@ -10,7 +10,7 @@
#include "include/gpu/vk/GrVkTypes.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/vk/GrVkStencilAttachment.h"
#include "src/gpu/vk/GrVkAttachment.h"
class GrShaderCaps;
class GrVkExtensions;

View File

@ -321,12 +321,14 @@ void GrVkGpu::disconnect(DisconnectType type) {
///////////////////////////////////////////////////////////////////////////////
GrOpsRenderPass* GrVkGpu::getOpsRenderPass(
GrRenderTarget* rt, GrStencilAttachment* stencil,
GrSurfaceOrigin origin, const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) {
GrRenderTarget* rt,
GrAttachment* stencil,
GrSurfaceOrigin origin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) {
if (!fCachedOpsRenderPass) {
fCachedOpsRenderPass = std::make_unique<GrVkOpsRenderPass>(this);
}
@ -1540,20 +1542,17 @@ bool GrVkGpu::onRegenerateMipMapLevels(GrTexture* tex) {
////////////////////////////////////////////////////////////////////////////////
GrStencilAttachment* GrVkGpu::createStencilAttachmentForRenderTarget(
const GrRenderTarget* rt, SkISize dimensions, int numStencilSamples) {
sk_sp<GrAttachment> GrVkGpu::makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
SkISize dimensions,
int numStencilSamples) {
SkASSERT(numStencilSamples == rt->numSamples() || this->caps()->mixedSamplesSupport());
SkASSERT(dimensions.width() >= rt->width());
SkASSERT(dimensions.height() >= rt->height());
VkFormat sFmt = this->vkCaps().preferredStencilFormat();
GrVkStencilAttachment* stencil(GrVkStencilAttachment::Create(this,
dimensions,
numStencilSamples,
sFmt));
fStats.incStencilAttachmentCreates();
return stencil;
return GrVkAttachment::MakeStencil(this, dimensions, numStencilSamples, sFmt);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -106,16 +106,18 @@ public:
}
#endif
GrStencilAttachment* createStencilAttachmentForRenderTarget(
const GrRenderTarget*, SkISize dimensions, int numStencilSamples) override;
sk_sp<GrAttachment> makeStencilAttachmentForRenderTarget(const GrRenderTarget*,
SkISize dimensions,
int numStencilSamples) override;
GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget*, GrStencilAttachment*,
GrSurfaceOrigin, const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
GrOpsRenderPass* getOpsRenderPass(GrRenderTarget*,
GrAttachment*,
GrSurfaceOrigin,
const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
GrXferBarrierFlags renderPassXferBarriers) override;
void addBufferMemoryBarrier(const GrManagedResource*,
VkPipelineStageFlags srcStageMask,

View File

@ -101,8 +101,7 @@ bool GrVkOpsRenderPass::init(const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
// If we are using a stencil attachment we also need to update its layout
if (withStencil) {
auto* vkStencil =
static_cast<GrVkStencilAttachment*>(fRenderTarget->getStencilAttachment());
auto* vkStencil = static_cast<GrVkAttachment*>(fRenderTarget->getStencilAttachment());
SkASSERT(vkStencil);
// We need the write and read access bits since we may load and store the stencil.
@ -218,8 +217,10 @@ void GrVkOpsRenderPass::submit() {
fGpu->endRenderPass(fRenderTarget, fOrigin, fBounds);
}
bool GrVkOpsRenderPass::set(GrRenderTarget* rt, GrStencilAttachment* stencil,
GrSurfaceOrigin origin, const SkIRect& bounds,
bool GrVkOpsRenderPass::set(GrRenderTarget* rt,
GrAttachment* stencil,
GrSurfaceOrigin origin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
@ -303,7 +304,7 @@ void GrVkOpsRenderPass::onClearStencilClip(const GrScissorState& scissor, bool i
return;
}
GrStencilAttachment* sb = fRenderTarget->getStencilAttachment();
GrAttachment* sb = fRenderTarget->getStencilAttachment();
// this should only be called internally when we know we have a
// stencil buffer.
SkASSERT(sb);

View File

@ -33,8 +33,10 @@ public:
using SelfDependencyFlags = GrVkRenderPass::SelfDependencyFlags;
bool set(GrRenderTarget*, GrStencilAttachment*,
GrSurfaceOrigin, const SkIRect& bounds,
bool set(GrRenderTarget*,
GrAttachment*,
GrSurfaceOrigin,
const SkIRect& bounds,
const GrOpsRenderPass::LoadAndStoreInfo&,
const GrOpsRenderPass::StencilLoadAndStoreInfo&,
const SkTArray<GrSurfaceProxy*, true>& sampledProxies,

View File

@ -374,9 +374,9 @@ void GrVkRenderTarget::getAttachmentsDescriptor(GrVkRenderPass::AttachmentsDescr
uint32_t attachmentCount = 1;
if (withStencil) {
const GrStencilAttachment* stencil = this->getStencilAttachment();
const GrAttachment* stencil = this->getStencilAttachment();
SkASSERT(stencil);
const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAttachment*>(stencil);
const GrVkAttachment* vkStencil = static_cast<const GrVkAttachment*>(stencil);
desc->fStencil.fFormat = vkStencil->imageFormat();
desc->fStencil.fSamples = vkStencil->numSamples();
#ifdef SK_DEBUG
@ -554,9 +554,9 @@ GrVkImage* GrVkRenderTarget::msaaImage() {
const GrManagedResource* GrVkRenderTarget::stencilImageResource() const {
SkASSERT(!this->wrapsSecondaryCommandBuffer());
const GrStencilAttachment* stencil = this->getStencilAttachment();
const GrAttachment* stencil = this->getStencilAttachment();
if (stencil) {
const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAttachment*>(stencil);
const GrVkAttachment* vkStencil = static_cast<const GrVkAttachment*>(stencil);
return vkStencil->imageResource();
}
@ -565,9 +565,9 @@ const GrManagedResource* GrVkRenderTarget::stencilImageResource() const {
const GrVkImageView* GrVkRenderTarget::stencilAttachmentView() const {
SkASSERT(!this->wrapsSecondaryCommandBuffer());
const GrStencilAttachment* stencil = this->getStencilAttachment();
const GrAttachment* stencil = this->getStencilAttachment();
if (stencil) {
const GrVkStencilAttachment* vkStencil = static_cast<const GrVkStencilAttachment*>(stencil);
const GrVkAttachment* vkStencil = static_cast<const GrVkAttachment*>(stencil);
return vkStencil->stencilView();
}

View File

@ -20,7 +20,7 @@
class GrVkFramebuffer;
class GrVkGpu;
class GrVkImageView;
class GrVkStencilAttachment;
class GrVkAttachment;
struct GrVkImageInfo;

View File

@ -1,97 +0,0 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/vk/GrVkGpu.h"
#include "src/gpu/vk/GrVkImage.h"
#include "src/gpu/vk/GrVkImageView.h"
#include "src/gpu/vk/GrVkStencilAttachment.h"
#include "src/gpu/vk/GrVkUtil.h"
#define VK_CALL(GPU, X) GR_VK_CALL(GPU->vkInterface(), X)
GrVkStencilAttachment::GrVkStencilAttachment(GrVkGpu* gpu,
SkISize dimensions,
VkFormat format,
const GrVkImage::ImageDesc& desc,
const GrVkImageInfo& info,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
sk_sp<const GrVkImageView> stencilView)
: GrStencilAttachment(gpu, dimensions, desc.fSamples, info.fProtected)
, GrVkImage(gpu, info, std::move(mutableState), GrBackendObjectOwnership::kOwned)
, fStencilView(std::move(stencilView)) {
this->registerWithCache(SkBudgeted::kYes);
}
GrVkStencilAttachment* GrVkStencilAttachment::Create(GrVkGpu* gpu,
SkISize dimensions,
int sampleCnt,
VkFormat format) {
GrVkImage::ImageDesc imageDesc;
imageDesc.fImageType = VK_IMAGE_TYPE_2D;
imageDesc.fFormat = format;
imageDesc.fWidth = dimensions.width();
imageDesc.fHeight = dimensions.height();
imageDesc.fLevels = 1;
imageDesc.fSamples = sampleCnt;
imageDesc.fImageTiling = VK_IMAGE_TILING_OPTIMAL;
imageDesc.fUsageFlags = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT;
imageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
GrVkImageInfo info;
if (!GrVkImage::InitImageInfo(gpu, imageDesc, &info)) {
return nullptr;
}
sk_sp<const GrVkImageView> imageView = GrVkImageView::Make(gpu, info.fImage, format,
GrVkImageView::kStencil_Type, 1,
GrVkYcbcrConversionInfo());
if (!imageView) {
GrVkImage::DestroyImageInfo(gpu, &info);
return nullptr;
}
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState(new GrBackendSurfaceMutableStateImpl(
info.fImageLayout, info.fCurrentQueueFamily));
GrVkStencilAttachment* stencil = new GrVkStencilAttachment(gpu, dimensions, format, imageDesc,
info, std::move(mutableState),
std::move(imageView));
return stencil;
}
GrVkStencilAttachment::~GrVkStencilAttachment() {
// should have been released or abandoned first
SkASSERT(!fStencilView);
}
size_t GrVkStencilAttachment::onGpuMemorySize() const {
uint64_t size = this->width();
size *= this->height();
size *= GrVkCaps::GetStencilFormatTotalBitCount(this->imageFormat());
size *= this->numSamples();
return static_cast<size_t>(size / 8);
}
void GrVkStencilAttachment::onRelease() {
this->releaseImage();
fStencilView.reset();
GrStencilAttachment::onRelease();
}
void GrVkStencilAttachment::onAbandon() {
this->releaseImage();
fStencilView.reset();
GrStencilAttachment::onAbandon();
}
GrVkGpu* GrVkStencilAttachment::getVkGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrVkGpu*>(this->getGpu());
}

View File

@ -1,50 +0,0 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrVkStencil_DEFINED
#define GrVkStencil_DEFINED
#include "include/gpu/vk/GrVkTypes.h"
#include "src/gpu/GrStencilAttachment.h"
#include "src/gpu/vk/GrVkImage.h"
class GrVkImageView;
class GrVkGpu;
class GrVkStencilAttachment : public GrStencilAttachment, public GrVkImage {
public:
static GrVkStencilAttachment* Create(GrVkGpu* gpu, SkISize dimensions, int sampleCnt,
VkFormat format);
~GrVkStencilAttachment() override;
GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
const GrManagedResource* imageResource() const { return this->resource(); }
const GrVkImageView* stencilView() const { return fStencilView.get(); }
protected:
void onRelease() override;
void onAbandon() override;
private:
size_t onGpuMemorySize() const override;
GrVkStencilAttachment(GrVkGpu* gpu,
SkISize dimensions,
VkFormat format,
const GrVkImage::ImageDesc&,
const GrVkImageInfo&,
sk_sp<GrBackendSurfaceMutableStateImpl> mutableState,
sk_sp<const GrVkImageView> stencilView);
GrVkGpu* getVkGpu() const;
sk_sp<const GrVkImageView> fStencilView;
};
#endif

View File

@ -85,7 +85,7 @@ static bool is_rendering_and_not_angle_es3(sk_gpu_test::GrContextFactory::Contex
return sk_gpu_test::GrContextFactory::IsRenderingContext(type);
}
static GrStencilAttachment* get_SB(GrRenderTarget* rt) { return rt->getStencilAttachment(); }
static GrAttachment* get_SB(GrRenderTarget* rt) { return rt->getStencilAttachment(); }
static sk_sp<GrRenderTarget> create_RT_with_SB(GrResourceProvider* provider,
int size, int sampleCount, SkBudgeted budgeted) {