Skip to content

Commit d2d4c5e

Browse files
jvanverthSkia Commit-Bot
authored andcommitted
Add GrD3DGpu and GrD3DCaps.
With this, can specify d3d config for dm and it will create a GrContext with GrD3DGpu (stubbed in). Bug: skia:9935 Change-Id: I0b8635bc541c61833b08b60a9f6e1341d1373090 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/271743 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
1 parent dc2b15e commit d2d4c5e

File tree

8 files changed

+641
-10
lines changed

8 files changed

+641
-10
lines changed

gn/gpu.gni

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,10 @@ skia_vk_sources = [
727727
]
728728

729729
skia_direct3d_sources = [
730+
"$_src/gpu/d3d/GrD3DCaps.cpp",
731+
"$_src/gpu/d3d/GrD3DCaps.h",
732+
"$_src/gpu/d3d/GrD3DGpu.cpp",
733+
"$_src/gpu/d3d/GrD3DGpu.h",
730734
]
731735

732736
skia_dawn_sources = [

src/gpu/GrLegacyDirectContext.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#ifdef SK_VULKAN
2424
#include "src/gpu/vk/GrVkGpu.h"
2525
#endif
26+
#ifdef SK_DIRECT3D
27+
#include "src/gpu/d3d/GrD3DGpu.h"
28+
#endif
2629
#ifdef SK_DAWN
2730
#include "src/gpu/dawn/GrDawnGpu.h"
2831
#endif
@@ -230,18 +233,17 @@ sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendConte
230233

231234
sk_sp<GrContext> GrContext::MakeDirect3D(const GrD3DBackendContext& backendContext,
232235
const GrContextOptions& options) {
233-
return nullptr;
234-
//sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kDirect3D, options));
236+
sk_sp<GrContext> context(new GrLegacyDirectContext(GrBackendApi::kDirect3D, options));
235237

236-
//context->fGpu = GrD3DGpu::Make(backendContext, options, context.get());
237-
//if (!context->fGpu) {
238-
// return nullptr;
239-
//}
238+
context->fGpu = GrD3DGpu::Make(backendContext, options, context.get());
239+
if (!context->fGpu) {
240+
return nullptr;
241+
}
240242

241-
//if (!context->init(context->fGpu->refCaps())) {
242-
// return nullptr;
243-
//}
244-
//return context;
243+
if (!context->init(context->fGpu->refCaps())) {
244+
return nullptr;
245+
}
246+
return context;
245247
}
246248
#endif
247249

src/gpu/GrProgramDesc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class GrProgramDesc {
6969

7070
protected:
7171
friend class GrDawnCaps;
72+
friend class GrD3DCaps;
7273
friend class GrGLCaps;
7374
friend class GrMockCaps;
7475
friend class GrMtlCaps;

src/gpu/d3d/GrD3DCaps.cpp

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/*
2+
* Copyright 2020 Google Inc.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include "include/gpu/GrBackendSurface.h"
9+
#include "include/gpu/d3d/GrD3DBackendContext.h"
10+
11+
#include "src/gpu/GrProgramDesc.h"
12+
#include "src/gpu/GrShaderCaps.h"
13+
#include "src/gpu/d3d/GrD3DCaps.h"
14+
#include "src/gpu/d3d/GrD3DGpu.h"
15+
16+
GrD3DCaps::GrD3DCaps(const GrContextOptions& contextOptions, GrProtected isProtected)
17+
: INHERITED(contextOptions) {
18+
/**************************************************************************
19+
* GrCaps fields
20+
**************************************************************************/
21+
fMipMapSupport = true; // always available in Direct3D
22+
fNPOTTextureTileSupport = false; // TODO: figure this out
23+
fReuseScratchTextures = true; //TODO: figure this out
24+
fGpuTracingSupport = false; //TODO: figure this out
25+
fOversizedStencilSupport = false; //TODO: figure this out
26+
fInstanceAttribSupport = true;
27+
28+
// TODO: implement these
29+
fSemaphoreSupport = false;
30+
fFenceSyncSupport = false;
31+
fCrossContextTextureSupport = false;
32+
fHalfFloatVertexAttributeSupport = false;
33+
34+
// We always copy in/out of a transfer buffer so it's trivial to support row bytes.
35+
fReadPixelsRowBytesSupport = true;
36+
fWritePixelsRowBytesSupport = true;
37+
38+
// TODO: figure this out
39+
fTransferFromBufferToTextureSupport = false;
40+
fTransferFromSurfaceToBufferSupport = false;
41+
42+
// TODO: figure this out
43+
fMaxRenderTargetSize = 4096;
44+
fMaxTextureSize = 4096;
45+
46+
fDynamicStateArrayGeometryProcessorTextureSupport = false; // TODO: figure this out
47+
48+
fShaderCaps.reset(new GrShaderCaps(contextOptions));
49+
50+
this->init(contextOptions);
51+
}
52+
53+
bool GrD3DCaps::onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
54+
const SkIRect& srcRect, const SkIPoint& dstPoint) const {
55+
return false;
56+
}
57+
58+
void GrD3DCaps::init(const GrContextOptions& contextOptions) {
59+
// TODO
60+
61+
this->finishInitialization(contextOptions);
62+
}
63+
64+
65+
66+
bool GrD3DCaps::isFormatSRGB(const GrBackendFormat& format) const {
67+
// TODO
68+
return false;
69+
}
70+
71+
SkImage::CompressionType GrD3DCaps::compressionType(const GrBackendFormat& format) const {
72+
// TODO
73+
return SkImage::CompressionType::kNone;
74+
}
75+
76+
bool GrD3DCaps::isFormatTexturableAndUploadable(GrColorType ct,
77+
const GrBackendFormat& format) const {
78+
// TODO
79+
return false;
80+
}
81+
82+
bool GrD3DCaps::isFormatTexturable(const GrBackendFormat& format) const {
83+
// TODO
84+
return false;
85+
}
86+
87+
bool GrD3DCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
88+
int sampleCount) const {
89+
if (!this->isFormatRenderable(format, sampleCount)) {
90+
return false;
91+
}
92+
// TODO
93+
return false;
94+
}
95+
96+
bool GrD3DCaps::isFormatRenderable(const GrBackendFormat& format, int sampleCount) const {
97+
// TODO
98+
return false;
99+
}
100+
101+
int GrD3DCaps::getRenderTargetSampleCount(int requestedCount,
102+
const GrBackendFormat& format) const {
103+
// TODO
104+
return 0;
105+
}
106+
107+
int GrD3DCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
108+
// TODO
109+
return 0;
110+
}
111+
112+
size_t GrD3DCaps::bytesPerPixel(const GrBackendFormat& format) const {
113+
// TODO
114+
return 0;
115+
}
116+
117+
GrCaps::SupportedWrite GrD3DCaps::supportedWritePixelsColorType(GrColorType surfaceColorType,
118+
const GrBackendFormat& surfaceFormat,
119+
GrColorType srcColorType) const {
120+
// TODO
121+
return {GrColorType::kUnknown, 0};
122+
}
123+
124+
GrCaps::SurfaceReadPixelsSupport GrD3DCaps::surfaceSupportsReadPixels(
125+
const GrSurface* surface) const {
126+
if (surface->isProtected()) {
127+
return SurfaceReadPixelsSupport::kUnsupported;
128+
}
129+
// TODO
130+
return SurfaceReadPixelsSupport::kUnsupported;
131+
}
132+
133+
bool GrD3DCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
134+
// TODO
135+
return false;
136+
}
137+
138+
bool GrD3DCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
139+
const GrBackendFormat& format) const {
140+
// TODO
141+
return false;
142+
}
143+
144+
GrColorType GrD3DCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat& format,
145+
bool isAlphaChannel) const {
146+
// TODO
147+
return GrColorType::kUnknown;
148+
}
149+
150+
GrBackendFormat GrD3DCaps::onGetDefaultBackendFormat(GrColorType ct,
151+
GrRenderable renderable) const {
152+
// TODO
153+
return GrBackendFormat();
154+
}
155+
156+
GrBackendFormat GrD3DCaps::getBackendFormatFromCompressionType(
157+
SkImage::CompressionType compressionType) const {
158+
// TODO
159+
return {};
160+
}
161+
162+
GrSwizzle GrD3DCaps::getReadSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
163+
// TODO
164+
return GrSwizzle::RGBA();
165+
}
166+
167+
GrSwizzle GrD3DCaps::getOutputSwizzle(const GrBackendFormat& format, GrColorType colorType) const {
168+
// TODO
169+
return GrSwizzle::RGBA();
170+
}
171+
172+
uint64_t GrD3DCaps::computeFormatKey(const GrBackendFormat& format) const {
173+
// TODO
174+
return (uint64_t)0;
175+
}
176+
177+
GrCaps::SupportedRead GrD3DCaps::onSupportedReadPixelsColorType(
178+
GrColorType srcColorType, const GrBackendFormat& srcBackendFormat,
179+
GrColorType dstColorType) const {
180+
// TODO
181+
return {GrColorType::kUnknown, 0};
182+
}
183+
184+
void GrD3DCaps::addExtraSamplerKey(GrProcessorKeyBuilder* b,
185+
GrSamplerState samplerState,
186+
const GrBackendFormat& format) const {
187+
// TODO
188+
}
189+
190+
/**
191+
* TODO: Determin what goes in the ProgramDesc
192+
*/
193+
GrProgramDesc GrD3DCaps::makeDesc(const GrRenderTarget* rt, const GrProgramInfo& programInfo) const {
194+
GrProgramDesc desc;
195+
if (!GrProgramDesc::Build(&desc, rt, programInfo, *this)) {
196+
SkASSERT(!desc.isValid());
197+
return desc;
198+
}
199+
200+
GrProcessorKeyBuilder b(&desc.key());
201+
202+
// TODO: add D3D-specific information
203+
204+
return desc;
205+
}
206+
207+
#if GR_TEST_UTILS
208+
std::vector<GrCaps::TestFormatColorTypeCombination> GrD3DCaps::getTestingCombinations() const {
209+
std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
210+
// TODO: fill in combos
211+
};
212+
213+
return combos;
214+
}
215+
#endif

src/gpu/d3d/GrD3DCaps.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2020 Google Inc.
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#ifndef GrD3DCaps_DEFINED
9+
#define GrD3DCaps_DEFINED
10+
11+
#include "src/gpu/GrCaps.h"
12+
13+
class GrShaderCaps;
14+
15+
/**
16+
* Stores some capabilities of a D3D backend.
17+
*/
18+
class GrD3DCaps : public GrCaps {
19+
public:
20+
/**
21+
* Creates a GrD3DCaps that is set such that nothing is supported. The init function should
22+
* be called to fill out the caps.
23+
*/
24+
GrD3DCaps(const GrContextOptions& contextOptions, GrProtected isProtected = GrProtected::kNo);
25+
26+
bool isFormatSRGB(const GrBackendFormat&) const override;
27+
SkImage::CompressionType compressionType(const GrBackendFormat&) const override;
28+
29+
bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override;
30+
bool isFormatTexturable(const GrBackendFormat&) const override;
31+
32+
bool isFormatCopyable(const GrBackendFormat&) const override { return true; }
33+
34+
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format,
35+
int sampleCount = 1) const override;
36+
bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
37+
38+
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const override;
39+
40+
int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
41+
42+
size_t bytesPerPixel(const GrBackendFormat&) const override;
43+
44+
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
45+
const GrBackendFormat& surfaceFormat,
46+
GrColorType srcColorType) const override;
47+
48+
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override;
49+
50+
GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&,
51+
bool isAlphaChannel) const override;
52+
53+
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
54+
55+
GrSwizzle getReadSwizzle(const GrBackendFormat&, GrColorType) const override;
56+
GrSwizzle getOutputSwizzle(const GrBackendFormat&, GrColorType) const override;
57+
58+
uint64_t computeFormatKey(const GrBackendFormat&) const override;
59+
60+
void addExtraSamplerKey(GrProcessorKeyBuilder*,
61+
GrSamplerState,
62+
const GrBackendFormat&) const override;
63+
64+
GrProgramDesc makeDesc(const GrRenderTarget*, const GrProgramInfo&) const override;
65+
66+
#if GR_TEST_UTILS
67+
std::vector<TestFormatColorTypeCombination> getTestingCombinations() const override;
68+
#endif
69+
70+
private:
71+
void init(const GrContextOptions& contextOptions);
72+
73+
bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
74+
bool onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
75+
const SkIRect& srcRect, const SkIPoint& dstPoint) const override;
76+
GrBackendFormat onGetDefaultBackendFormat(GrColorType, GrRenderable) const override;
77+
78+
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat&) const override;
79+
80+
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat&,
81+
GrColorType) const override;
82+
83+
typedef GrCaps INHERITED;
84+
};
85+
86+
#endif

0 commit comments

Comments
 (0)