• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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 "experimental/graphite/src/CommandBuffer.h"
9 
10 #include "experimental/graphite/src/GraphicsPipeline.h"
11 #include "src/core/SkTraceEvent.h"
12 
13 #include "experimental/graphite/src/Buffer.h"
14 #include "experimental/graphite/src/Texture.h"
15 #include "experimental/graphite/src/TextureProxy.h"
16 
17 namespace skgpu {
18 
CommandBuffer()19 CommandBuffer::CommandBuffer() {}
20 
releaseResources()21 void CommandBuffer::releaseResources() {
22     TRACE_EVENT0("skia.gpu", TRACE_FUNC);
23 
24     fTrackedResources.reset();
25 }
26 
beginRenderPass(const RenderPassDesc & renderPassDesc)27 void CommandBuffer::beginRenderPass(const RenderPassDesc& renderPassDesc) {
28     this->onBeginRenderPass(renderPassDesc);
29 
30     auto& colorInfo = renderPassDesc.fColorAttachment;
31     if (colorInfo.fTextureProxy) {
32         this->trackResource(colorInfo.fTextureProxy->refTexture());
33     }
34     if (colorInfo.fStoreOp == StoreOp::kStore) {
35         fHasWork = true;
36     }
37 }
38 
bindGraphicsPipeline(sk_sp<GraphicsPipeline> graphicsPipeline)39 void CommandBuffer::bindGraphicsPipeline(sk_sp<GraphicsPipeline> graphicsPipeline) {
40     this->onBindGraphicsPipeline(graphicsPipeline.get());
41     this->trackResource(std::move(graphicsPipeline));
42     fHasWork = true;
43 }
44 
bindUniformBuffer(sk_sp<Buffer> uniformBuffer,size_t offset)45 void CommandBuffer::bindUniformBuffer(sk_sp<Buffer> uniformBuffer, size_t offset) {
46     this->onBindUniformBuffer(uniformBuffer.get(), offset);
47     this->trackResource(std::move(uniformBuffer));
48     fHasWork = true;
49 }
50 
bindVertexBuffers(sk_sp<Buffer> vertexBuffer,size_t vertexOffset,sk_sp<Buffer> instanceBuffer,size_t instanceOffset)51 void CommandBuffer::bindVertexBuffers(sk_sp<Buffer> vertexBuffer, size_t vertexOffset,
52                                       sk_sp<Buffer> instanceBuffer, size_t instanceOffset) {
53     this->onBindVertexBuffers(vertexBuffer.get(), vertexOffset,
54                               instanceBuffer.get(), instanceOffset);
55     if (vertexBuffer) {
56         this->trackResource(std::move(vertexBuffer));
57     }
58     if (instanceBuffer) {
59         this->trackResource(std::move(instanceBuffer));
60     }
61     fHasWork = true;
62 }
63 
bindIndexBuffer(sk_sp<Buffer> indexBuffer,size_t bufferOffset)64 void CommandBuffer::bindIndexBuffer(sk_sp<Buffer> indexBuffer, size_t bufferOffset) {
65     this->onBindIndexBuffer(indexBuffer.get(), bufferOffset);
66     if (indexBuffer) {
67         this->trackResource(std::move(indexBuffer));
68     }
69     fHasWork = true;
70 }
71 
check_max_blit_width(int widthInPixels)72 static bool check_max_blit_width(int widthInPixels) {
73     if (widthInPixels > 32767) {
74         SkASSERT(false); // surfaces should not be this wide anyway
75         return false;
76     }
77     return true;
78 }
79 
copyTextureToBuffer(sk_sp<skgpu::Texture> texture,SkIRect srcRect,sk_sp<skgpu::Buffer> buffer,size_t bufferOffset,size_t bufferRowBytes)80 void CommandBuffer::copyTextureToBuffer(sk_sp<skgpu::Texture> texture,
81                                         SkIRect srcRect,
82                                         sk_sp<skgpu::Buffer> buffer,
83                                         size_t bufferOffset,
84                                         size_t bufferRowBytes) {
85     if (!check_max_blit_width(srcRect.width())) {
86         return;
87     }
88 
89     this->onCopyTextureToBuffer(texture.get(), srcRect, buffer.get(), bufferOffset, bufferRowBytes);
90 
91     this->trackResource(std::move(texture));
92     this->trackResource(std::move(buffer));
93 
94     fHasWork = true;
95 }
96 
97 } // namespace skgpu
98