GrDawnGpu.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #ifndef GrDawnGpu_DEFINED
  8. #define GrDawnGpu_DEFINED
  9. #include "src/gpu/GrGpu.h"
  10. #include "dawn/dawncpp.h"
  11. class GrPipeline;
  12. class GrDawnGpuRTCommandBuffer;
  13. namespace SkSL {
  14. class Compiler;
  15. }
  16. class GrDawnGpu : public GrGpu {
  17. public:
  18. static sk_sp<GrGpu> Make(const dawn::Device& device, const GrContextOptions&, GrContext*);
  19. GrDawnGpu(GrContext* context, const GrContextOptions& options, const dawn::Device& device);
  20. ~GrDawnGpu() override;
  21. void disconnect(DisconnectType) override;
  22. const dawn::Device& device() const { return fDevice; }
  23. const dawn::Queue& queue() const { return fQueue; }
  24. void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
  25. GrBackendTexture createBackendTexture(int w, int h,
  26. const GrBackendFormat &,
  27. GrMipMapped,
  28. GrRenderable,
  29. const void* pixels,
  30. size_t rowBytes,
  31. const SkColor4f* color,
  32. GrProtected isProtected) override;
  33. void deleteBackendTexture(const GrBackendTexture&) override;
  34. #if GR_TEST_UTILS
  35. bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
  36. GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
  37. void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
  38. void testingOnly_flushGpuAndSync() override;
  39. #endif
  40. GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
  41. int width,
  42. int height,
  43. int numStencilSamples) override;
  44. GrGpuRTCommandBuffer* getCommandBuffer(
  45. GrRenderTarget*, GrSurfaceOrigin, const SkRect& bounds,
  46. const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
  47. const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
  48. GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
  49. SkSL::Compiler* shaderCompiler() const {
  50. return fCompiler.get();
  51. }
  52. void submit(GrGpuCommandBuffer* cb) override;
  53. GrFence SK_WARN_UNUSED_RESULT insertFence() override;
  54. bool waitFence(GrFence, uint64_t timeout) override;
  55. void deleteFence(GrFence) const override;
  56. sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true) override;
  57. sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
  58. GrResourceProvider::SemaphoreWrapType wrapType,
  59. GrWrapOwnership ownership) override;
  60. void insertSemaphore(sk_sp<GrSemaphore> semaphore) override;
  61. void waitSemaphore(sk_sp<GrSemaphore> semaphore) override;
  62. void checkFinishProcs() override;
  63. sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override;
  64. private:
  65. void onResetContext(uint32_t resetBits) override {}
  66. virtual void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>*) override {}
  67. sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, GrRenderable, SkBudgeted budgeted,
  68. GrProtected, const GrMipLevel texels[], int mipLevelCount)
  69. override;
  70. sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType,
  71. SkBudgeted, const void* data) override;
  72. sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership,
  73. GrWrapCacheable, GrIOType) override;
  74. sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
  75. GrColorType, GrWrapOwnership,
  76. GrWrapCacheable) override;
  77. sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
  78. sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
  79. int sampleCnt) override;
  80. sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
  81. const void* data) override;
  82. bool onReadPixels(GrSurface* surface,
  83. int left, int top, int width, int height,
  84. GrColorType, void* buffer, size_t rowBytes) override;
  85. bool onWritePixels(GrSurface* surface,
  86. int left, int top, int width, int height,
  87. GrColorType, const GrMipLevel texels[], int mipLevelCount) override;
  88. bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
  89. GrColorType colorType, GrGpuBuffer* transferBuffer,
  90. size_t offset, size_t rowBytes) override;
  91. bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
  92. GrColorType, GrGpuBuffer* transferBuffer, size_t offset) override;
  93. void onResolveRenderTarget(GrRenderTarget* target) override {
  94. }
  95. bool onRegenerateMipMapLevels(GrTexture*) override;
  96. bool onCopySurface(GrSurface* dst, GrSurface* src,
  97. const SkIRect& srcRect, const SkIPoint& dstPoint,
  98. bool canDiscardOutsideDstRect) override;
  99. void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
  100. const GrFlushInfo& info, const GrPrepareForExternalIORequests&) override;
  101. dawn::Device fDevice;
  102. dawn::Queue fQueue; // Must be Graphics queue
  103. // Compiler used for compiling sksl into spirv. We only want to create the compiler once since
  104. // there is significant overhead to the first compile of any compiler.
  105. std::unique_ptr<SkSL::Compiler> fCompiler;
  106. std::unique_ptr<GrDawnGpuRTCommandBuffer> fCachedRTCommandBuffer;
  107. typedef GrGpu INHERITED;
  108. };
  109. #endif