| 1 |
/* |
| 2 |
* Copyright 2022 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 |
#ifndef skgpu_graphite_DawnGraphicsPipeline_DEFINED |
| 9 |
#define skgpu_graphite_DawnGraphicsPipeline_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkSpan.h" |
| 13 |
#include "include/ports/SkCFObject.h" |
| 14 |
#include "include/private/base/SkTArray.h" |
| 15 |
#include "src/gpu/graphite/DrawTypes.h" |
| 16 |
#include "src/gpu/graphite/GraphicsPipeline.h" |
| 17 |
#include "src/gpu/graphite/dawn/DawnAsyncWait.h" |
| 18 |
#include "src/gpu/graphite/dawn/DawnSampler.h" |
| 19 |
|
| 20 |
#include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE |
| 21 |
|
| 22 |
class SkUniform; |
| 23 |
|
| 24 |
namespace SkSL { |
| 25 |
class Compiler; |
| 26 |
} |
| 27 |
namespace skgpu { |
| 28 |
struct BlendInfo; |
| 29 |
} |
| 30 |
|
| 31 |
namespace skgpu::graphite { |
| 32 |
|
| 33 |
class Attribute; |
| 34 |
class Context; |
| 35 |
class GraphicsPipelineDesc; |
| 36 |
class DawnResourceProvider; |
| 37 |
class DawnSharedContext; |
| 38 |
struct DepthStencilSettings; |
| 39 |
struct RenderPassDesc; |
| 40 |
class RuntimeEffectDictionary; |
| 41 |
|
| 42 |
class DawnGraphicsPipeline final : public GraphicsPipeline { |
| 43 |
public: |
| 44 |
inline static constexpr unsigned int kUniformBufferBindGroupIndex = 0; |
| 45 |
inline static constexpr unsigned int kTextureBindGroupIndex = 1; |
| 46 |
inline static constexpr unsigned int kBindGroupCount = 2; |
| 47 |
|
| 48 |
inline static constexpr unsigned int kIntrinsicUniformBufferIndex = 0; |
| 49 |
inline static constexpr unsigned int kCombinedUniformIndex = 1; |
| 50 |
inline static constexpr unsigned int kGradientBufferIndex = 2; |
| 51 |
inline static constexpr unsigned int kNumUniformBuffers = 3; |
| 52 |
|
| 53 |
inline static constexpr unsigned int kIntrinsicUniformSize = 32; |
| 54 |
|
| 55 |
inline static constexpr unsigned int kStaticDataBufferIndex = 0; |
| 56 |
inline static constexpr unsigned int kAppendDataBufferIndex = 1; |
| 57 |
inline static constexpr unsigned int kNumVertexBuffers = 2; |
| 58 |
|
| 59 |
static sk_sp<DawnGraphicsPipeline> Make(const DawnSharedContext* sharedContext, |
| 60 |
const RuntimeEffectDictionary* runtimeDict, |
| 61 |
const UniqueKey& pipelineKey, |
| 62 |
const GraphicsPipelineDesc& pipelineDesc, |
| 63 |
const RenderPassDesc& renderPassDesc, |
| 64 |
SkEnumBitMask<PipelineCreationFlags>, |
| 65 |
uint32_t compilationID); |
| 66 |
|
| 67 |
~DawnGraphicsPipeline() override; |
| 68 |
|
| 69 |
bool didAsyncCompilationFail() const override; |
| 70 |
|
| 71 |
uint32_t stencilReferenceValue() const { return fStencilReferenceValue; } |
| 72 |
PrimitiveType primitiveType() const { return fPrimitiveType; } |
| 73 |
|
| 74 |
const wgpu::RenderPipeline& dawnRenderPipeline() const; |
| 75 |
|
| 76 |
using BindGroupLayouts = std::array<wgpu::BindGroupLayout, kBindGroupCount>; |
| 77 |
const BindGroupLayouts& dawnGroupLayouts() const { return fGroupLayouts; } |
| 78 |
|
| 79 |
// Returns null if the ith sampler is not an immutable sampler. |
| 80 |
const DawnSampler* immutableSampler(int32_t index) const { |
| 81 |
return fImmutableSamplers[index].get(); |
| 82 |
} |
| 83 |
|
| 84 |
private: |
| 85 |
struct AsyncPipelineCreation; |
| 86 |
|
| 87 |
DawnGraphicsPipeline(const skgpu::graphite::SharedContext* sharedContext, |
| 88 |
const PipelineInfo& pipelineInfo, |
| 89 |
std::string_view pipelineLabel, |
| 90 |
std::unique_ptr<AsyncPipelineCreation> pipelineCreationInfo, |
| 91 |
BindGroupLayouts groupLayouts, |
| 92 |
PrimitiveType primitiveType, |
| 93 |
uint32_t refValue, |
| 94 |
skia_private::TArray<sk_sp<DawnSampler>> immutableSamplers); |
| 95 |
|
| 96 |
void freeGpuData() override; |
| 97 |
|
| 98 |
std::unique_ptr<AsyncPipelineCreation> fAsyncPipelineCreation; |
| 99 |
BindGroupLayouts fGroupLayouts; |
| 100 |
const PrimitiveType fPrimitiveType; |
| 101 |
const uint32_t fStencilReferenceValue; |
| 102 |
|
| 103 |
// Hold a ref to immutable samplers used such that their lifetime is properly managed. |
| 104 |
const skia_private::TArray<sk_sp<DawnSampler>> fImmutableSamplers; |
| 105 |
}; |
| 106 |
|
| 107 |
} // namespace skgpu::graphite |
| 108 |
|
| 109 |
#endif // skgpu_graphite_DawnGraphicsPipeline_DEFINED |