Skip to content

Commit

Permalink
Roll dawn and adjust for new SwapChain API.
Browse files Browse the repository at this point in the history
Split GrDawnImageInfo into GrDawnTextureInfo and GrDawnRenderTargetInfo.
The former holds only a wgpu::Texture, and the latter holds only a
wgpu::TextureView. This split is necessary because Dawn SwapChains now
vend TextureViews, not Textures.

The TextureView held by GrDawnRenderTargetInfo is always 1-mip, since
it's a requirement for rendering to a texture in Dawn.

Change-Id: Id6e99b5e4bf18f97e939170856a665e2038253ea
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/254810
Commit-Queue: Stephen White <[email protected]>
Reviewed-by: Greg Daniel <[email protected]>
Reviewed-by: Brian Salomon <[email protected]>
  • Loading branch information
SenorBlanco authored and Skia Commit-Bot committed Jan 28, 2020
1 parent 6aa6505 commit f03c116
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 85 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deps = {
"buildtools" : "https://chromium.googlesource.com/chromium/buildtools.git@505de88083136eefd056e5ee4ca0f01fe9b33de8",
"common" : "https://skia.googlesource.com/common.git@9737551d7a52c3db3262db5856e6bcd62c462b92",
"third_party/externals/angle2" : "https://chromium.googlesource.com/angle/angle.git@086aded3cb743b2fc405d8a11b12d7fc132ec181",
"third_party/externals/dawn" : "https://dawn.googlesource.com/dawn.git@3c086a0c2e1dc3e2e14aaa3d78c052c7e07274b4",
"third_party/externals/dawn" : "https://dawn.googlesource.com/dawn.git@604072bc2ed01018eb03bcbbf9d94042f679af63",
"third_party/externals/dng_sdk" : "https://android.googlesource.com/platform/external/dng_sdk.git@c8d0c9b1d16bfda56f15165d39e0ffa360a11123",
"third_party/externals/egl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/EGL-Registry@a0bca08de07c7d7651047bedc0b653cfaaa4f2ae",
"third_party/externals/expat" : "https://android.googlesource.com/platform/external/expat.git@e5aa0a2cb0a5f759ef31c0819dc67d9b14246a4a",
Expand Down
18 changes: 9 additions & 9 deletions include/gpu/GrBackendSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class SK_API GrBackendTexture {
#ifdef SK_DAWN
GrBackendTexture(int width,
int height,
const GrDawnImageInfo& dawnInfo);
const GrDawnTextureInfo& dawnInfo);
#endif

GrBackendTexture(int width,
Expand Down Expand Up @@ -234,9 +234,9 @@ class SK_API GrBackendTexture {
void glTextureParametersModified();

#ifdef SK_DAWN
// If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed
// If the backend API is Dawn, copies a snapshot of the GrDawnTextureInfo struct into the passed
// in pointer and returns true. Otherwise returns false if the backend API is not Dawn.
bool getDawnImageInfo(GrDawnImageInfo*) const;
bool getDawnTextureInfo(GrDawnTextureInfo*) const;
#endif

// If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed
Expand Down Expand Up @@ -317,7 +317,7 @@ class SK_API GrBackendTexture {
GrMtlTextureInfo fMtlInfo;
#endif
#ifdef SK_DAWN
GrDawnImageInfo fDawnInfo;
GrDawnTextureInfo fDawnInfo;
#endif
};

Expand All @@ -338,7 +338,7 @@ class SK_API GrBackendRenderTarget {
int height,
int sampleCnt,
int stencilBits,
const GrDawnImageInfo& dawnInfo);
const GrDawnRenderTargetInfo& dawnInfo);
#endif

/** Deprecated, use version that does not take stencil bits. */
Expand Down Expand Up @@ -379,9 +379,9 @@ class SK_API GrBackendRenderTarget {
bool getGLFramebufferInfo(GrGLFramebufferInfo*) const;

#ifdef SK_DAWN
// If the backend API is Dawn, copies a snapshot of the GrDawnImageInfo struct into the passed
// in pointer and returns true. Otherwise returns false if the backend API is not Dawn.
bool getDawnImageInfo(GrDawnImageInfo*) const;
// If the backend API is Dawn, copies a snapshot of the GrDawnRenderTargetInfo struct into the
// passed-in pointer and returns true. Otherwise returns false if the backend API is not Dawn.
bool getDawnRenderTargetInfo(GrDawnRenderTargetInfo*) const;
#endif

// If the backend API is Vulkan, copies a snapshot of the GrVkImageInfo struct into the passed
Expand Down Expand Up @@ -449,7 +449,7 @@ class SK_API GrBackendRenderTarget {
GrMtlTextureInfo fMtlInfo;
#endif
#ifdef SK_DAWN
GrDawnImageInfo fDawnInfo;
GrDawnRenderTargetInfo fDawnInfo;
#endif
};

Expand Down
46 changes: 41 additions & 5 deletions include/gpu/dawn/GrDawnTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,64 @@ static constexpr int None = 0L;
#endif
#include "dawn/webgpu_cpp.h"

struct GrDawnImageInfo {
struct GrDawnTextureInfo {
wgpu::Texture fTexture;
wgpu::TextureFormat fFormat;
uint32_t fLevelCount;
GrDawnImageInfo() : fTexture(nullptr), fFormat(), fLevelCount(0) {
GrDawnTextureInfo() : fTexture(nullptr), fFormat(), fLevelCount(0) {
}
GrDawnImageInfo(const GrDawnImageInfo& other)
GrDawnTextureInfo(const GrDawnTextureInfo& other)
: fTexture(other.fTexture)
, fFormat(other.fFormat)
, fLevelCount(other.fLevelCount) {
}
GrDawnImageInfo& operator=(const GrDawnImageInfo& other) {
GrDawnTextureInfo& operator=(const GrDawnTextureInfo& other) {
fTexture = other.fTexture;
fFormat = other.fFormat;
fLevelCount = other.fLevelCount;
return *this;
}
bool operator==(const GrDawnImageInfo& other) const {
bool operator==(const GrDawnTextureInfo& other) const {
return fTexture.Get() == other.fTexture.Get() &&
fFormat == other.fFormat &&
fLevelCount == other.fLevelCount;
}
};

// GrDawnRenderTargetInfo holds a reference to a (1-mip) TextureView. This means that, for now,
// GrDawnRenderTarget is suitable for rendering, but not readPixels() or writePixels(). Also,
// backdrop filters and certain blend modes requiring copying the destination framebuffer
// will not work.
struct GrDawnRenderTargetInfo {
wgpu::TextureView fTextureView;
wgpu::TextureFormat fFormat;
uint32_t fLevelCount;
GrDawnRenderTargetInfo() : fTextureView(nullptr), fFormat(), fLevelCount(0) {
}
GrDawnRenderTargetInfo(const GrDawnRenderTargetInfo& other)
: fTextureView(other.fTextureView)
, fFormat(other.fFormat)
, fLevelCount(other.fLevelCount) {
}
explicit GrDawnRenderTargetInfo(const GrDawnTextureInfo& texInfo)
: fFormat(texInfo.fFormat)
, fLevelCount(1) {
wgpu::TextureViewDescriptor desc;
desc.format = texInfo.fFormat;
desc.mipLevelCount = 1;
fTextureView = texInfo.fTexture.CreateView(&desc);
}
GrDawnRenderTargetInfo& operator=(const GrDawnRenderTargetInfo& other) {
fTextureView = other.fTextureView;
fFormat = other.fFormat;
fLevelCount = other.fLevelCount;
return *this;
}
bool operator==(const GrDawnRenderTargetInfo& other) const {
return fTextureView.Get() == other.fTextureView.Get() &&
fFormat == other.fFormat &&
fLevelCount == other.fLevelCount;
}
};

#endif
15 changes: 11 additions & 4 deletions src/gpu/GrBackendSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ SkString GrBackendFormat::toStr() const {
#ifdef SK_DAWN
GrBackendTexture::GrBackendTexture(int width,
int height,
const GrDawnImageInfo& dawnInfo)
const GrDawnTextureInfo& dawnInfo)
: fIsValid(true)
, fWidth(width)
, fHeight(height)
Expand Down Expand Up @@ -466,7 +466,7 @@ GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) {
}

#ifdef SK_DAWN
bool GrBackendTexture::getDawnImageInfo(GrDawnImageInfo* outInfo) const {
bool GrBackendTexture::getDawnTextureInfo(GrDawnTextureInfo* outInfo) const {
if (this->isValid() && GrBackendApi::kDawn == fBackend) {
*outInfo = fDawnInfo;
return true;
Expand Down Expand Up @@ -663,7 +663,7 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
int height,
int sampleCnt,
int stencilBits,
const GrDawnImageInfo& dawnInfo)
const GrDawnRenderTargetInfo& dawnInfo)
: fIsValid(true)
, fFramebufferOnly(true)
, fWidth(width)
Expand Down Expand Up @@ -816,7 +816,7 @@ GrBackendRenderTarget& GrBackendRenderTarget::operator=(const GrBackendRenderTar
}

#ifdef SK_DAWN
bool GrBackendRenderTarget::getDawnImageInfo(GrDawnImageInfo* outInfo) const {
bool GrBackendRenderTarget::getDawnRenderTargetInfo(GrDawnRenderTargetInfo* outInfo) const {
if (this->isValid() && GrBackendApi::kDawn == fBackend) {
*outInfo = fDawnInfo;
return true;
Expand Down Expand Up @@ -897,6 +897,13 @@ GrBackendFormat GrBackendRenderTarget::getBackendFormat() const {
SkAssertResult(this->getMtlTextureInfo(&mtlInfo));
return GrBackendFormat::MakeMtl(GrGetMTLPixelFormatFromMtlTextureInfo(mtlInfo));
}
#endif
#ifdef SK_DAWN
case GrBackendApi::kDawn: {
GrDawnRenderTargetInfo dawnInfo;
SkAssertResult(this->getDawnRenderTargetInfo(&dawnInfo));
return GrBackendFormat::MakeDawn(dawnInfo.fFormat);
}
#endif
case GrBackendApi::kMock:
return fMockInfo.getBackendFormat();
Expand Down
42 changes: 21 additions & 21 deletions src/gpu/dawn/GrDawnGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ sk_sp<GrTexture> GrDawnGpu::onWrapBackendTexture(const GrBackendTexture& backend
GrWrapOwnership ownership,
GrWrapCacheable cacheable,
GrIOType) {
GrDawnImageInfo info;
if (!backendTex.getDawnImageInfo(&info)) {
GrDawnTextureInfo info;
if (!backendTex.getDawnTextureInfo(&info)) {
return nullptr;
}

Expand All @@ -205,8 +205,8 @@ sk_sp<GrTexture> GrDawnGpu::onWrapRenderableBackendTexture(const GrBackendTextur
int sampleCnt, GrColorType colorType,
GrWrapOwnership,
GrWrapCacheable cacheable) {
GrDawnImageInfo info;
if (!tex.getDawnImageInfo(&info) || !info.fTexture) {
GrDawnTextureInfo info;
if (!tex.getDawnTextureInfo(&info) || !info.fTexture) {
return nullptr;
}

Expand All @@ -223,8 +223,8 @@ sk_sp<GrTexture> GrDawnGpu::onWrapRenderableBackendTexture(const GrBackendTextur

sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt,
GrColorType colorType) {
GrDawnImageInfo info;
if (!rt.getDawnImageInfo(&info) && !info.fTexture) {
GrDawnRenderTargetInfo info;
if (!rt.getDawnRenderTargetInfo(&info) || !info.fTextureView) {
return nullptr;
}

Expand All @@ -236,8 +236,8 @@ sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendRenderTarget(const GrBackendRender
sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
int sampleCnt,
GrColorType colorType) {
GrDawnImageInfo info;
if (!tex.getDawnImageInfo(&info) || !info.fTexture) {
GrDawnTextureInfo textureInfo;
if (!tex.getDawnTextureInfo(&textureInfo) || !textureInfo.fTexture) {
return nullptr;
}

Expand All @@ -247,6 +247,7 @@ sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendTextureAsRenderTarget(const GrBack
return nullptr;
}

GrDawnRenderTargetInfo info(textureInfo);
return GrDawnRenderTarget::MakeWrapped(this, dimensions, sampleCnt, info);
}

Expand Down Expand Up @@ -349,7 +350,7 @@ GrBackendTexture GrDawnGpu::onCreateBackendTexture(SkISize dimensions,
}
wgpu::CommandBuffer cmdBuf = copyEncoder.Finish();
fQueue.Submit(1, &cmdBuf);
GrDawnImageInfo info;
GrDawnTextureInfo info;
info.fTexture = tex;
info.fFormat = desc.format;
info.fLevelCount = desc.mipLevelCount;
Expand All @@ -365,16 +366,16 @@ GrBackendTexture GrDawnGpu::onCreateCompressedBackendTexture(SkISize dimensions,
}

void GrDawnGpu::deleteBackendTexture(const GrBackendTexture& tex) {
GrDawnImageInfo info;
if (tex.getDawnImageInfo(&info)) {
GrDawnTextureInfo info;
if (tex.getDawnTextureInfo(&info)) {
info.fTexture = nullptr;
}
}

#if GR_TEST_UTILS
bool GrDawnGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
GrDawnImageInfo info;
if (!tex.getDawnImageInfo(&info)) {
GrDawnTextureInfo info;
if (!tex.getDawnTextureInfo(&info)) {
return false;
}

Expand Down Expand Up @@ -405,17 +406,17 @@ GrBackendRenderTarget GrDawnGpu::createTestingOnlyBackendRenderTarget(int width,

wgpu::Texture tex = this->device().CreateTexture(&desc);

GrDawnImageInfo info;
info.fTexture = tex;
GrDawnRenderTargetInfo info;
info.fTextureView = tex.CreateView();
info.fFormat = desc.format;
info.fLevelCount = desc.mipLevelCount;
return GrBackendRenderTarget(width, height, 1, 0, info);
}

void GrDawnGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget& rt) {
GrDawnImageInfo info;
if (rt.getDawnImageInfo(&info)) {
info.fTexture = nullptr;
GrDawnRenderTargetInfo info;
if (rt.getDawnRenderTargetInfo(&info)) {
info.fTextureView = nullptr;
}
}

Expand All @@ -442,9 +443,7 @@ bool GrDawnGpu::onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfac
}

static wgpu::Texture get_dawn_texture_from_surface(GrSurface* src) {
if (auto rt = static_cast<GrDawnRenderTarget*>(src->asRenderTarget())) {
return rt->texture();
} else if (auto t = static_cast<GrDawnTexture*>(src->asTexture())) {
if (auto t = static_cast<GrDawnTexture*>(src->asTexture())) {
return t->texture();
} else {
return nullptr;
Expand Down Expand Up @@ -483,6 +482,7 @@ bool GrDawnGpu::onReadPixels(GrSurface* surface, int left, int top, int width, i
GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
size_t rowBytes) {
wgpu::Texture tex = get_dawn_texture_from_surface(surface);
SkASSERT(tex);

if (0 == rowBytes) {
return false;
Expand Down
6 changes: 1 addition & 5 deletions src/gpu/dawn/GrDawnOpsRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,12 @@ GrDawnOpsRenderPass::GrDawnOpsRenderPass(GrDawnGpu* gpu, GrRenderTarget* rt, GrS

wgpu::RenderPassEncoder GrDawnOpsRenderPass::beginRenderPass(wgpu::LoadOp colorOp,
wgpu::LoadOp stencilOp) {
wgpu::Texture texture = static_cast<GrDawnRenderTarget*>(fRenderTarget)->texture();
auto stencilAttachment = static_cast<GrDawnStencilAttachment*>(
fRenderTarget->renderTargetPriv().getStencilAttachment());
wgpu::TextureViewDescriptor desc;
desc.mipLevelCount = 1;
wgpu::TextureView colorView = texture.CreateView(&desc);
const float *c = fColorInfo.fClearColor.vec();

wgpu::RenderPassColorAttachmentDescriptor colorAttachment;
colorAttachment.attachment = colorView;
colorAttachment.attachment = static_cast<GrDawnRenderTarget*>(fRenderTarget)->textureView();
colorAttachment.resolveTarget = nullptr;
colorAttachment.clearColor = { c[0], c[1], c[2], c[3] };
colorAttachment.loadOp = colorOp;
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/dawn/GrDawnRenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
GrDawnRenderTarget::GrDawnRenderTarget(GrDawnGpu* gpu,
SkISize dimensions,
int sampleCnt,
const GrDawnImageInfo& info)
const GrDawnRenderTargetInfo& info)
: GrSurface(gpu, dimensions, GrProtected::kNo)
, GrRenderTarget(gpu, dimensions, sampleCnt, GrProtected::kNo)
, fInfo(info) {}

sk_sp<GrDawnRenderTarget> GrDawnRenderTarget::MakeWrapped(GrDawnGpu* gpu,
SkISize dimensions,
int sampleCnt,
const GrDawnImageInfo& info) {
const GrDawnRenderTargetInfo& info) {
sk_sp<GrDawnRenderTarget> rt(new GrDawnRenderTarget(gpu, dimensions, sampleCnt, info));
rt->registerWithCacheWrapped(GrWrapCacheable::kNo);
return rt;
Expand Down
10 changes: 5 additions & 5 deletions src/gpu/dawn/GrDawnRenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GrDawnRenderTarget: public GrRenderTarget {
static sk_sp<GrDawnRenderTarget> MakeWrapped(GrDawnGpu*,
SkISize dimensions,
int sampleCnt,
const GrDawnImageInfo&);
const GrDawnRenderTargetInfo&);

~GrDawnRenderTarget() override;

Expand All @@ -28,13 +28,13 @@ class GrDawnRenderTarget: public GrRenderTarget {

GrBackendRenderTarget getBackendRenderTarget() const override;
GrBackendFormat backendFormat() const override;
wgpu::Texture texture() const { return fInfo.fTexture; }
wgpu::TextureView textureView() const { return fInfo.fTextureView; }

protected:
GrDawnRenderTarget(GrDawnGpu* gpu,
SkISize dimensions,
int sampleCnt,
const GrDawnImageInfo& info);
const GrDawnRenderTargetInfo& info);

void onAbandon() override;
void onRelease() override;
Expand All @@ -44,10 +44,10 @@ class GrDawnRenderTarget: public GrRenderTarget {
size_t onGpuMemorySize() const override;

static GrDawnRenderTarget* Create(GrDawnGpu*, const GrSurfaceDesc&, int sampleCnt,
const GrDawnImageInfo&);
const GrDawnRenderTargetInfo&);

bool completeStencilAttachment() override;
GrDawnImageInfo fInfo;
GrDawnRenderTargetInfo fInfo;
typedef GrRenderTarget INHERITED;
};

Expand Down
Loading

0 comments on commit f03c116

Please sign in to comment.