Skip to content

Commit

Permalink
Reland "Create D3D device and queue"
Browse files Browse the repository at this point in the history
This is a reland of 29dc430

Original change's description:
> Create D3D device and queue
> 
> Bug: skia:9935
> Change-Id: Ib6548f413ca3a8befb553d2d47354b400c9162b9
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272520
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>

Bug: skia:9935
Change-Id: I1c8797e09cdeb3694ea7f47b2236ab7d91d9519f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272996
Reviewed-by: Ben Wagner aka dogben <benjaminwagner@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
  • Loading branch information
jvanverth authored and Skia Commit-Bot committed Feb 24, 2020
1 parent 6dd3b73 commit 03b8ab2
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 53 deletions.
4 changes: 4 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ optional("gpu") {
public_defines += [ "SK_DIRECT3D" ]
deps += [ "//third_party/spirv-cross:spirv_cross" ]
sources += skia_direct3d_sources
if (skia_enable_direct3d_debug_layer) {
public_defines += [ "SK_ENABLE_D3D_DEBUG_LAYER" ]
}
libs += [
"d3d12.lib",
"dxgi.lib",
Expand Down Expand Up @@ -1385,6 +1388,7 @@ if (skia_enable_tools) {
}
if (skia_use_direct3d) {
sources += [ "tools/gpu/d3d/D3DTestContext.cpp" ]
sources += [ "tools/gpu/d3d/D3DTestUtils.cpp" ]
}
if (skia_use_dawn) {
public_deps += [ "//third_party/dawn:dawn_headers" ]
Expand Down
2 changes: 1 addition & 1 deletion gm/rectangletexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RectangleTexture : public GpuGM {
return nullptr;
}

const GrGLInterface* gl = glCtx->interface();
const GrGLInterface* gl = glCtx->glInterface();
// Useful for debugging whether errors result from use of RECTANGLE
// static constexpr GrGLenum kTarget = GR_GL_TEXTURE_2D;
static constexpr GrGLenum kTarget = GR_GL_TEXTURE_RECTANGLE;
Expand Down
2 changes: 2 additions & 0 deletions gn/gpu.gni
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ skia_vk_sources = [
]

skia_direct3d_sources = [
"$_include/gpu/d3d/GrD3DBackendContext.h",
"$_include/gpu/d3d/GrD3D12.h",
"$_src/gpu/d3d/GrD3DCaps.cpp",
"$_src/gpu/d3d/GrD3DCaps.h",
"$_src/gpu/d3d/GrD3DGpu.cpp",
Expand Down
4 changes: 3 additions & 1 deletion gn/skia.gni
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare_args() {
is_skia_dev_build && ((target_cpu == "x64" && (is_linux || is_mac)) ||
(target_cpu == "arm64" && is_android))
skia_enable_tools = is_skia_dev_build
skia_enable_vulkan_debug_layers = is_skia_dev_build && is_debug
skia_enable_gpu_debug_layers = is_skia_dev_build && is_debug
skia_generate_workarounds = false
skia_include_multiframe_procs = false
skia_lex = false
Expand Down Expand Up @@ -96,6 +96,8 @@ declare_args() {
skia_use_dng_sdk = !is_fuchsia && skia_use_libjpeg_turbo && skia_use_zlib
skia_use_libgifcodec = !skia_use_wuffs
skia_use_sfntly = skia_use_icu
skia_enable_vulkan_debug_layers = skia_enable_gpu_debug_layers
skia_enable_direct3d_debug_layer = skia_enable_gpu_debug_layers
}

# Our tools require static linking (they use non-exported symbols), and the GPU backend.
Expand Down
18 changes: 18 additions & 0 deletions include/gpu/d3d/GrD3D12.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 GrD3D12_DEFINED
#define GrD3D12_DEFINED

#include <d3d12.h>
#include <wrl/client.h> // for ComPtr

// Abbreviate and alias ComPtr
template<typename T>
using gr_cp = Microsoft::WRL::ComPtr<T>;

#endif
9 changes: 7 additions & 2 deletions include/gpu/d3d/GrD3DBackendContext.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google Inc.
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
Expand All @@ -8,11 +8,16 @@
#ifndef GrD3DBackendContext_DEFINED
#define GrD3DBackendContext_DEFINED

#include "include/core/SkRefCnt.h"
#include "include/gpu/d3d/GrD3D12.h"

#include "include/gpu/GrTypes.h"

// The BackendContext contains all of the base D3D objects needed by the GrD3DGpu. The assumption
// is that the client will set these up and pass them to the GrD3DGpu constructor.
struct SK_API GrD3DBackendContext {
gr_cp<ID3D12Device> fDevice;
gr_cp<ID3D12CommandQueue> fQueue;
GrProtected fProtectedContext = GrProtected::kNo;
};

#endif
4 changes: 4 additions & 0 deletions public.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ BASE_SRCS_ALL = struct(
# Currently exclude all vulkan specific files
"src/gpu/vk/*",

# Currently exclude all Direct3D specific files
"src/gpu/d3d/*",

# Currently exclude all Dawn-specific files
"src/gpu/dawn/*",

Expand Down Expand Up @@ -534,6 +537,7 @@ DM_SRCS_ALL = struct(
"tests/SkParagraphTest.cpp", # Skipping tests for now.
"tests/skia_test.cpp", # Old main.
"tools/gpu/atlastext/*",
"tools/gpu/d3d/*",
"tools/gpu/dawn/*",
"tools/gpu/gl/angle/*",
"tools/gpu/gl/egl/*",
Expand Down
8 changes: 4 additions & 4 deletions src/gpu/GrLegacyDirectContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class GrLegacyDirectContext : public GrContext {
};

#ifdef SK_GL
sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface) {
sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface) {
GrContextOptions defaultOptions;
return MakeGL(std::move(interface), defaultOptions);
return MakeGL(std::move(glInterface), defaultOptions);
}

sk_sp<GrContext> GrContext::MakeGL(const GrContextOptions& options) {
Expand All @@ -139,11 +139,11 @@ sk_sp<GrContext> GrContext::MakeGL() {
return MakeGL(nullptr, defaultOptions);
}

sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface,
sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> glInterface,
const GrContextOptions& options) {
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kOpenGL, options));

context->fGpu = GrGLGpu::Make(std::move(interface), options, context.get());
context->fGpu = GrGLGpu::Make(std::move(glInterface), options, context.get());
if (!context->fGpu) {
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/d3d/GrD3DCaps.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google Inc.
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/d3d/GrD3DCaps.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google Inc.
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
Expand Down
7 changes: 5 additions & 2 deletions src/gpu/d3d/GrD3DGpu.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google Inc.
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
Expand All @@ -15,7 +15,10 @@ sk_sp<GrGpu> GrD3DGpu::Make(const GrD3DBackendContext& backendContext,

GrD3DGpu::GrD3DGpu(GrContext* context, const GrContextOptions& contextOptions,
const GrD3DBackendContext& backendContext)
: INHERITED(context) {
: INHERITED(context)
, fDevice(backendContext.fDevice)
, fQueue(backendContext.fQueue)
, fProtectedContext(backendContext.fProtectedContext) {
fCaps.reset(new GrD3DCaps(contextOptions));
}

Expand Down
41 changes: 24 additions & 17 deletions src/gpu/d3d/GrD3DGpu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google Inc.
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
Expand All @@ -25,6 +25,26 @@ class GrD3DGpu : public GrGpu {

~GrD3DGpu() override {}

void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override;

void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}

void deleteBackendTexture(const GrBackendTexture&) override;

bool compile(const GrProgramDesc&, const GrProgramInfo&) override;

#if GR_TEST_UTILS
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;

GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;

void testingOnly_flushGpuAndSync() override {}
#endif

GrStencilAttachment* createStencilAttachmentForRenderTarget(
const GrRenderTarget*, int width, int height, int numStencilSamples) override;

GrOpsRenderPass* getOpsRenderPass(
GrRenderTarget*, GrSurfaceOrigin, const SkIRect&,
const GrOpsRenderPass::LoadAndStoreInfo&,
Expand Down Expand Up @@ -59,10 +79,6 @@ class GrD3DGpu : public GrGpu {

void onResetContext(uint32_t resetBits) override {}

void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override;

void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}

sk_sp<GrTexture> onCreateTexture(SkISize,
const GrBackendFormat&,
GrRenderable,
Expand Down Expand Up @@ -139,8 +155,6 @@ class GrD3DGpu : public GrGpu {
return true;
}

GrStencilAttachment* createStencilAttachmentForRenderTarget(
const GrRenderTarget*, int width, int height, int numStencilSamples) override;
GrBackendTexture onCreateBackendTexture(SkISize dimensions,
const GrBackendFormat&,
GrRenderable,
Expand All @@ -152,18 +166,11 @@ class GrD3DGpu : public GrGpu {
GrMipMapped,
GrProtected,
const BackendTextureData*) override;
void deleteBackendTexture(const GrBackendTexture&) override;

bool compile(const GrProgramDesc&, const GrProgramInfo&) override;
gr_cp<ID3D12Device> fDevice;
gr_cp<ID3D12CommandQueue> fQueue;

#if GR_TEST_UTILS
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;

GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;

void testingOnly_flushGpuAndSync() override {}
#endif
GrProtected fProtectedContext;

typedef GrGpu INHERITED;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/gl/GrGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class GrGLContext : public GrGLContextInfo {
*/
static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&);

const GrGLInterface* interface() const { return fInterface.get(); }
const GrGLInterface* glInterface() const { return fInterface.get(); }

SkSL::Compiler* compiler() const;

Expand Down
34 changes: 17 additions & 17 deletions src/gpu/gl/GrGLGpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,36 +1167,36 @@ static bool renderbuffer_storage_msaa(const GrGLContext& ctx,
int sampleCount,
GrGLenum format,
int width, int height) {
CLEAR_ERROR_BEFORE_ALLOC(ctx.interface());
CLEAR_ERROR_BEFORE_ALLOC(ctx.glInterface());
SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType());
switch (ctx.caps()->msFBOType()) {
case GrGLCaps::kStandard_MSFBOType:
GL_ALLOC_CALL(ctx.interface(),
RenderbufferStorageMultisample(GR_GL_RENDERBUFFER,
sampleCount,
format,
width, height));
GL_ALLOC_CALL(ctx.glInterface(),
RenderbufferStorageMultisample(GR_GL_RENDERBUFFER,
sampleCount,
format,
width, height));
break;
case GrGLCaps::kES_Apple_MSFBOType:
GL_ALLOC_CALL(ctx.interface(),
RenderbufferStorageMultisampleES2APPLE(GR_GL_RENDERBUFFER,
sampleCount,
format,
width, height));
GL_ALLOC_CALL(ctx.glInterface(),
RenderbufferStorageMultisampleES2APPLE(GR_GL_RENDERBUFFER,
sampleCount,
format,
width, height));
break;
case GrGLCaps::kES_EXT_MsToTexture_MSFBOType:
case GrGLCaps::kES_IMG_MsToTexture_MSFBOType:
GL_ALLOC_CALL(ctx.interface(),
RenderbufferStorageMultisampleES2EXT(GR_GL_RENDERBUFFER,
sampleCount,
format,
width, height));
GL_ALLOC_CALL(ctx.glInterface(),
RenderbufferStorageMultisampleES2EXT(GR_GL_RENDERBUFFER,
sampleCount,
format,
width, height));
break;
case GrGLCaps::kNone_MSFBOType:
SK_ABORT("Shouldn't be here if we don't support multisampled renderbuffers.");
break;
}
return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));
return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.glInterface()));
}

bool GrGLGpu::createRenderTargetObjects(const GrGLTexture::Desc& desc,
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/gl/GrGLGpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl {

const GrGLContext& glContext() const { return *fGLContext; }

const GrGLInterface* glInterface() const { return fGLContext->interface(); }
const GrGLInterface* glInterface() const { return fGLContext->glInterface(); }
const GrGLContextInfo& ctxInfo() const { return *fGLContext; }
GrGLStandard glStandard() const { return fGLContext->standard(); }
GrGLVersion glVersion() const { return fGLContext->version(); }
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/gl/builders/GrGLShaderStringBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
const SkSL::String& glsl,
GrGpu::Stats* stats,
GrContextOptions::ShaderErrorHandler* errorHandler) {
const GrGLInterface* gli = glCtx.interface();
const GrGLInterface* gli = glCtx.glInterface();

// Specify GLSL source to the driver.
GrGLuint shaderId;
Expand Down
11 changes: 7 additions & 4 deletions tools/gpu/d3d/D3DTestContext.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Google Inc.
* Copyright 2020 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
Expand All @@ -10,11 +10,10 @@
#ifdef SK_DIRECT3D

#include "include/gpu/GrContext.h"
#include "tools/gpu/d3d/D3DTestUtils.h"

namespace {

// TODO: Implement D3DFenceSync

class D3DTestContextImpl : public sk_gpu_test::D3DTestContext {
public:
static D3DTestContext* Create(D3DTestContext* sharedContext) {
Expand All @@ -23,8 +22,13 @@ class D3DTestContextImpl : public sk_gpu_test::D3DTestContext {
if (sharedContext) {
// take from the given context
ownsContext = false;
backendContext = sharedContext->getD3DBackendContext();
} else {
// create our own
if (!sk_gpu_test::CreateD3DBackendContext(&backendContext)) {
return nullptr;
}

ownsContext = true;
}
return new D3DTestContextImpl(backendContext, ownsContext);
Expand Down Expand Up @@ -54,7 +58,6 @@ class D3DTestContextImpl : public sk_gpu_test::D3DTestContext {
private:
D3DTestContextImpl(const GrD3DBackendContext& backendContext, bool ownsContext)
: D3DTestContext(backendContext, ownsContext) {
// TODO fFenceSync.reset(new D3DFenceSync(backendContext));
}

void onPlatformMakeNotCurrent() const override {}
Expand Down
4 changes: 4 additions & 0 deletions tools/gpu/d3d/D3DTestContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class D3DTestContext : public TestContext {
public:
virtual GrBackendApi backend() override { return GrBackendApi::kDirect3D; }

const GrD3DBackendContext& getD3DBackendContext() const {
return fD3D;
}

protected:
D3DTestContext(const GrD3DBackendContext& d3d, bool ownsContext)
: fD3D(d3d)
Expand Down
Loading

0 comments on commit 03b8ab2

Please sign in to comment.