GrDawnGpu.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Copyright 2019 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. #include "GrDawnGpu.h"
  8. #include "include/gpu/GrBackendSemaphore.h"
  9. #include "include/gpu/GrBackendSurface.h"
  10. #include "include/gpu/GrContextOptions.h"
  11. #include "src/gpu/GrGeometryProcessor.h"
  12. #include "src/gpu/GrGpuResourceCacheAccess.h"
  13. #include "src/gpu/GrMesh.h"
  14. #include "src/gpu/dawn/GrDawnCaps.h"
  15. #include "src/gpu/dawn/GrDawnRenderTarget.h"
  16. #include "src/gpu/dawn/GrDawnGpuCommandBuffer.h"
  17. #include "src/gpu/GrPipeline.h"
  18. #include "src/gpu/GrRenderTargetPriv.h"
  19. #include "src/gpu/GrSemaphore.h"
  20. #include "src/gpu/GrTexturePriv.h"
  21. #include "src/sksl/SkSLCompiler.h"
  22. #if !defined(SK_BUILD_FOR_WIN)
  23. #include <unistd.h>
  24. #endif // !defined(SK_BUILD_FOR_WIN)
  25. sk_sp<GrGpu> GrDawnGpu::Make(const dawn::Device& device,
  26. const GrContextOptions& options, GrContext* context) {
  27. if (!device) {
  28. return nullptr;
  29. }
  30. return sk_sp<GrGpu>(new GrDawnGpu(context, options, device));
  31. }
  32. ////////////////////////////////////////////////////////////////////////////////
  33. GrDawnGpu::GrDawnGpu(GrContext* context, const GrContextOptions& options,
  34. const dawn::Device& device)
  35. : INHERITED(context)
  36. , fDevice(device)
  37. , fQueue(device.CreateQueue())
  38. , fCompiler(new SkSL::Compiler()) {
  39. fCaps.reset(new GrDawnCaps(options));
  40. }
  41. GrDawnGpu::~GrDawnGpu() {
  42. }
  43. void GrDawnGpu::disconnect(DisconnectType type) {
  44. INHERITED::disconnect(type);
  45. }
  46. ///////////////////////////////////////////////////////////////////////////////
  47. GrGpuRTCommandBuffer* GrDawnGpu::getCommandBuffer(
  48. GrRenderTarget* rt, GrSurfaceOrigin origin, const SkRect& bounds,
  49. const GrGpuRTCommandBuffer::LoadAndStoreInfo& colorInfo,
  50. const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo& stencilInfo) {
  51. fCachedRTCommandBuffer.reset(
  52. new GrDawnGpuRTCommandBuffer(this, rt, origin, colorInfo, stencilInfo));
  53. return fCachedRTCommandBuffer.get();
  54. }
  55. GrGpuTextureCommandBuffer* GrDawnGpu::getCommandBuffer(GrTexture* texture,
  56. GrSurfaceOrigin origin) {
  57. return nullptr;
  58. }
  59. ///////////////////////////////////////////////////////////////////////////////
  60. sk_sp<GrGpuBuffer> GrDawnGpu::onCreateBuffer(size_t size, GrGpuBufferType type,
  61. GrAccessPattern accessPattern, const void* data) {
  62. return nullptr;
  63. }
  64. ////////////////////////////////////////////////////////////////////////////////
  65. bool GrDawnGpu::onWritePixels(GrSurface* surface,
  66. int left, int top, int width, int height,
  67. GrColorType colorType,
  68. const GrMipLevel texels[], int mipLevelCount) {
  69. return false;
  70. }
  71. bool GrDawnGpu::onTransferPixelsTo(GrTexture* texture,
  72. int left, int top, int width, int height,
  73. GrColorType colorType, GrGpuBuffer* transferBuffer,
  74. size_t bufferOffset, size_t rowBytes) {
  75. return false;
  76. }
  77. bool GrDawnGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
  78. GrColorType, GrGpuBuffer* transferBuffer, size_t offset) {
  79. return false;
  80. }
  81. ////////////////////////////////////////////////////////////////////////////////
  82. sk_sp<GrTexture> GrDawnGpu::onCreateTexture(const GrSurfaceDesc& desc, GrRenderable renderable,
  83. SkBudgeted budgeted, GrProtected,
  84. const GrMipLevel texels[], int mipLevelCount) {
  85. return nullptr;
  86. }
  87. sk_sp<GrTexture> GrDawnGpu::onCreateCompressedTexture(int width, int height,
  88. SkImage::CompressionType, SkBudgeted,
  89. const void* data) {
  90. return nullptr;
  91. }
  92. sk_sp<GrTexture> GrDawnGpu::onWrapBackendTexture(const GrBackendTexture& backendTex,
  93. GrWrapOwnership ownership,
  94. GrWrapCacheable cacheable,
  95. GrIOType) {
  96. return nullptr;
  97. }
  98. sk_sp<GrTexture> GrDawnGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex,
  99. int sampleCnt, GrColorType,
  100. GrWrapOwnership,
  101. GrWrapCacheable cacheable) {
  102. return nullptr;
  103. }
  104. sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget&) {
  105. return nullptr;
  106. }
  107. sk_sp<GrRenderTarget> GrDawnGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
  108. int sampleCnt) {
  109. GrDawnImageInfo info;
  110. if (!tex.getDawnImageInfo(&info)) {
  111. return nullptr;
  112. }
  113. if (!info.fTexture) {
  114. return nullptr;
  115. }
  116. GrSurfaceDesc desc;
  117. desc.fWidth = tex.width();
  118. desc.fHeight = tex.height();
  119. desc.fConfig = tex.config();
  120. sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, tex.config());
  121. if (sampleCnt < 1) {
  122. return nullptr;
  123. }
  124. sk_sp<GrDawnRenderTarget> tgt = GrDawnRenderTarget::MakeWrapped(this, desc, sampleCnt, info);
  125. return tgt;
  126. }
  127. GrStencilAttachment* GrDawnGpu::createStencilAttachmentForRenderTarget(const GrRenderTarget* rt,
  128. int width,
  129. int height,
  130. int numStencilSamples) {
  131. return nullptr;
  132. }
  133. GrBackendTexture GrDawnGpu::createBackendTexture(int width, int height,
  134. const GrBackendFormat& format,
  135. GrMipMapped mipMapped,
  136. GrRenderable renderable,
  137. const void* pixels,
  138. size_t rowBytes,
  139. const SkColor4f* color,
  140. GrProtected isProtected) {
  141. return GrBackendTexture();
  142. }
  143. void GrDawnGpu::deleteBackendTexture(const GrBackendTexture& tex) {
  144. }
  145. #if GR_TEST_UTILS
  146. bool GrDawnGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
  147. return false;
  148. }
  149. GrBackendRenderTarget GrDawnGpu::createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) {
  150. return GrBackendRenderTarget();
  151. }
  152. void GrDawnGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) {
  153. }
  154. void GrDawnGpu::testingOnly_flushGpuAndSync() {
  155. }
  156. #endif
  157. void GrDawnGpu::onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
  158. const GrFlushInfo& info, const GrPrepareForExternalIORequests&) {
  159. }
  160. bool GrDawnGpu::onCopySurface(GrSurface* dst,
  161. GrSurface* src,
  162. const SkIRect& srcRect,
  163. const SkIPoint& dstPoint,
  164. bool canDiscardOutsideDstRect) {
  165. return false;
  166. }
  167. bool GrDawnGpu::onReadPixels(GrSurface* surface,
  168. int left, int top, int width, int height,
  169. GrColorType colorType,
  170. void* buffer,
  171. size_t rowBytes) {
  172. return false;
  173. }
  174. bool GrDawnGpu::onRegenerateMipMapLevels(GrTexture*) {
  175. return false;
  176. }
  177. void GrDawnGpu::submit(GrGpuCommandBuffer* buffer) {
  178. if (auto buf = static_cast<GrDawnGpuRTCommandBuffer*>(buffer->asRTCommandBuffer())) {
  179. buf->submit();
  180. }
  181. }
  182. GrFence SK_WARN_UNUSED_RESULT GrDawnGpu::insertFence() {
  183. return GrFence();
  184. }
  185. bool GrDawnGpu::waitFence(GrFence fence, uint64_t timeout) {
  186. return false;
  187. }
  188. void GrDawnGpu::deleteFence(GrFence fence) const {
  189. }
  190. sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrDawnGpu::makeSemaphore(bool isOwned) {
  191. return nullptr;
  192. }
  193. sk_sp<GrSemaphore> GrDawnGpu::wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
  194. GrResourceProvider::SemaphoreWrapType wrapType,
  195. GrWrapOwnership ownership) {
  196. SkASSERT(!"unimplemented");
  197. return nullptr;
  198. }
  199. void GrDawnGpu::insertSemaphore(sk_sp<GrSemaphore> semaphore) {
  200. SkASSERT(!"unimplemented");
  201. }
  202. void GrDawnGpu::waitSemaphore(sk_sp<GrSemaphore> semaphore) {
  203. SkASSERT(!"unimplemented");
  204. }
  205. void GrDawnGpu::checkFinishProcs() {
  206. SkASSERT(!"unimplemented");
  207. }
  208. sk_sp<GrSemaphore> GrDawnGpu::prepareTextureForCrossContextUsage(GrTexture* texture) {
  209. return nullptr;
  210. }