OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 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 GrVkGpu_DEFINED | |
9 #define GrVkGpu_DEFINED | |
10 | |
11 #include "GrGpu.h" | |
12 #include "GrGpuFactory.h" | |
13 #include "GrVkCaps.h" | |
14 #include "GrVkIndexBuffer.h" | |
15 #include "GrVkProgram.h" | |
16 #include "GrVkResourceProvider.h" | |
17 #include "GrVkVertexBuffer.h" | |
18 #include "GrVkUtil.h" | |
19 | |
20 #include "shaderc/shaderc.h" | |
21 #include "vulkan/vulkan.h" | |
22 | |
23 class GrPipeline; | |
24 class GrNonInstancedVertices; | |
25 | |
26 class GrVkBufferImpl; | |
27 class GrVkCommandBuffer; | |
28 class GrVkPipeline; | |
29 class GrVkRenderPass; | |
30 class GrVkTexture; | |
31 struct GrVkInterface; | |
32 | |
33 class GrVkGpu : public GrGpu { | |
34 public: | |
35 // Currently passing in the inst so that we can properly delete it when we a
re done. | |
36 // Normally this would be done by the client. | |
37 GrVkGpu(GrContext* context, const GrContextOptions& options, | |
38 VkPhysicalDevice physDev, VkDevice device, VkQueue queue, VkCommandP
ool cmdPool, | |
39 VkInstance inst); | |
40 ~GrVkGpu() override; | |
41 | |
42 const GrVkInterface* vkInterface() const { return fInterface.get(); } | |
43 const GrVkCaps& vkCaps() const { return *fVkCaps; } | |
44 | |
45 VkDevice device() const { return fDevice; } | |
46 VkQueue queue() const { return fQueue; } | |
47 VkCommandPool cmdPool() const { return fCmdPool; } | |
48 VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties() const { | |
49 return fPhysDevMemProps; | |
50 } | |
51 | |
52 GrVkResourceProvider& resourceProvider() { return fResourceProvider; } | |
53 | |
54 enum SyncQueue { | |
55 kForce_SyncQueue, | |
56 kSkip_SyncQueue | |
57 }; | |
58 | |
59 bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeigh
t, size_t rowBytes, | |
60 GrPixelConfig readConfig, DrawPreference*, | |
61 ReadPixelTempDrawInfo*) override; | |
62 | |
63 bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height, | |
64 GrPixelConfig srcConfig, DrawPreference*, | |
65 WritePixelTempDrawInfo*) override; | |
66 | |
67 void buildProgramDesc(GrProgramDesc*, const GrPrimitiveProcessor&, | |
68 const GrPipeline&) const override; | |
69 | |
70 void discard(GrRenderTarget*) override { | |
71 SkDebugf("discard not yet implemented for Vulkan\n"); | |
72 } | |
73 | |
74 bool onCopySurface(GrSurface* dst, | |
75 GrSurface* src, | |
76 const SkIRect& srcRect, | |
77 const SkIPoint& dstPoint) override; | |
78 | |
79 bool initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) const
override { | |
80 SkDebugf("initCopySurfaceDstDesc not yet implemented for Vulkan\n"); | |
81 return false; | |
82 } | |
83 | |
84 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} | |
85 | |
86 GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h, | |
87 GrPixelConfig config) overri
de; | |
88 bool isTestingOnlyBackendTexture(GrBackendObject id) const override; | |
89 void deleteTestingOnlyBackendTexture(GrBackendObject id, bool abandonTexture
) override; | |
90 | |
91 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTa
rget*, | |
92 int width, | |
93 int height) over
ride; | |
94 | |
95 void clearStencil(GrRenderTarget* target) override { | |
96 SkDebugf("clearStencil not yet implemented for Vulkan\n"); | |
97 } | |
98 | |
99 void drawDebugWireRect(GrRenderTarget*, const SkIRect&, GrColor) override { | |
100 SkDebugf("drawDebugWireRect not yet implemented for Vulkan\n"); | |
101 } | |
102 | |
103 void addMemoryBarrier(VkPipelineStageFlags srcStageMask, | |
104 VkPipelineStageFlags dstStageMask, | |
105 bool byRegion, | |
106 VkMemoryBarrier* barrier) const; | |
107 void addBufferMemoryBarrier(VkPipelineStageFlags srcStageMask, | |
108 VkPipelineStageFlags dstStageMask, | |
109 bool byRegion, | |
110 VkBufferMemoryBarrier* barrier) const; | |
111 void addImageMemoryBarrier(VkPipelineStageFlags srcStageMask, | |
112 VkPipelineStageFlags dstStageMask, | |
113 bool byRegion, | |
114 VkImageMemoryBarrier* barrier) const; | |
115 | |
116 shaderc_compiler_t shadercCompiler() const { | |
117 return fCompiler; | |
118 } | |
119 | |
120 void finishDrawTarget() override; | |
121 | |
122 private: | |
123 void onResetContext(uint32_t resetBits) override { | |
124 SkDebugf("onResetContext not yet implemented for Vulkan\n"); | |
125 } | |
126 | |
127 GrTexture* onCreateTexture(const GrSurfaceDesc& desc, GrGpuResource::LifeCyc
le, | |
128 const void* srcData, size_t rowBytes) override; | |
129 | |
130 GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, GrGpuResourc
e::LifeCycle, | |
131 const void* srcData) override { | |
132 SkDebugf("onCreateCompressedTexture not yet implemented for Vulkan\n"); | |
133 return NULL; | |
134 } | |
135 | |
136 GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership
) override; | |
137 | |
138 GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&, | |
139 GrWrapOwnership) override; | |
140 | |
141 GrVertexBuffer* onCreateVertexBuffer(size_t size, bool dynamic) override; | |
142 GrIndexBuffer* onCreateIndexBuffer(size_t size, bool dynamic) override; | |
143 GrTransferBuffer* onCreateTransferBuffer(size_t size, TransferType type) ove
rride; | |
144 | |
145 void onClear(GrRenderTarget*, const SkIRect& rect, GrColor color) override; | |
146 | |
147 void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideCli
p) override { | |
148 SkDebugf("onClearStencilClip not yet implemented for Vulkan\n"); | |
149 } | |
150 | |
151 void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override; | |
152 | |
153 bool onReadPixels(GrSurface* surface, | |
154 int left, int top, int width, int height, | |
155 GrPixelConfig, | |
156 void* buffer, | |
157 size_t rowBytes) override; | |
158 | |
159 bool onWritePixels(GrSurface* surface, | |
160 int left, int top, int width, int height, | |
161 GrPixelConfig config, const void* buffer, size_t rowBytes
) override; | |
162 | |
163 bool onTransferPixels(GrSurface*, | |
164 int left, int top, int width, int height, | |
165 GrPixelConfig config, GrTransferBuffer* buffer, | |
166 size_t offset, size_t rowBytes) override { | |
167 SkDebugf("onTransferPixels not yet implemented for Vulkan\n"); | |
168 return false; | |
169 } | |
170 | |
171 void onResolveRenderTarget(GrRenderTarget* target) override { | |
172 SkDebugf("onResolveRenderTarget not yet implemented for Vulkan\n"); | |
173 } | |
174 | |
175 // Bind vertex and index buffers | |
176 void bindGeometry(const GrPrimitiveProcessor&, const GrNonInstancedVertices&
); | |
177 | |
178 // Ends and submits the current command buffer to the queue and then creates
a new command | |
179 // buffer and begins it. If sync is set to kForce_SyncQueue, the function wi
ll wait for all | |
180 // work in the queue to finish before returning. | |
181 void submitCommandBuffer(SyncQueue sync); | |
182 | |
183 void copySurfaceAsCopyImage(GrSurface* dst, | |
184 GrSurface* src, | |
185 const SkIRect& srcRect, | |
186 const SkIPoint& dstPoint); | |
187 | |
188 void copySurfaceAsDraw(GrSurface* dst, | |
189 GrSurface* src, | |
190 const SkIRect& srcRect, | |
191 const SkIPoint& dstPoint); | |
192 | |
193 // helper for onCreateTexture and writeTexturePixels | |
194 bool uploadTexData(GrVkTexture* tex, | |
195 int left, int top, int width, int height, | |
196 GrPixelConfig dataConfig, | |
197 const void* data, | |
198 size_t rowBytes); | |
199 | |
200 SkAutoTUnref<const GrVkInterface> fInterface; | |
201 SkAutoTUnref<GrVkCaps> fVkCaps; | |
202 VkPhysicalDeviceMemoryProperties fPhysDevMemProps; | |
203 VkDevice fDevice; | |
204 VkQueue fQueue; // for now, one queue | |
205 VkCommandPool fCmdPool; | |
206 GrVkCommandBuffer* fCurrentCmdBuffer; | |
207 GrVkResourceProvider fResourceProvider; | |
208 | |
209 // Shaderc compiler used for compiling glsl in spirv. We only want to create
the compiler once | |
210 // since there is significant overhead to the first compile of any compiler. | |
211 shaderc_compiler_t fCompiler; | |
212 | |
213 // This is only for our current testing and building. The client should be h
olding on to the | |
214 // VkInstance. | |
215 VkInstance fVkInstance; | |
216 | |
217 typedef GrGpu INHERITED; | |
218 }; | |
219 | |
220 #endif | |
OLD | NEW |