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 #ifndef skgpu_graphite_ContextUtils_DEFINED 9 #define skgpu_graphite_ContextUtils_DEFINED 10 11 #include "include/core/SkBlendMode.h" 12 #include "src/gpu/graphite/PipelineData.h" 13 14 #include <optional> 15 16 class SkColorInfo; 17 class SkM44; 18 19 namespace skgpu { 20 enum class BackendApi : unsigned int; 21 22 namespace graphite { 23 class ComputeStep; 24 enum class Coverage; 25 enum class DstReadStrategy : uint8_t; 26 class Geometry; 27 class PaintParams; 28 class PipelineDataGatherer; 29 class Recorder; 30 struct RenderPassDesc; 31 class RenderStep; 32 class ShaderCodeDictionary; 33 class UniformManager; 34 class UniquePaintParamsID; 35 36 struct ResourceBindingRequirements; 37 38 UniquePaintParamsID ExtractPaintData(Recorder*, 39 PipelineDataGatherer* gatherer, 40 PaintParamsKeyBuilder* builder, 41 const Layout layout, 42 const SkM44& local2Dev, 43 const PaintParams&, 44 const Geometry& geometry, 45 const SkColorInfo& targetColorInfo); 46 47 // Intrinsic uniforms used by every program created in Graphite. 48 // 49 // `viewport` should hold the actual viewport set as backend state (defining the NDC -> pixel 50 // transform). The viewport's dimensions are used to define the SkDevice->NDC transform applied in 51 // the vertex shader, but this assumes that the (0,0) device coordinate maps to the corner of the 52 // top-left of the NDC cube. The viewport's origin is used in the fragment shader to reconstruct 53 // the logical fragment coordinate from the target's current frag coord (which are not relative to 54 // active viewport). 55 // 56 // It is assumed that `dstReadBounds` is in the same coordinate space as the `viewport` (e.g. 57 // final backing target's pixel coords) and that its width and height match the dimensions of the 58 // texture to be sampled for dst reads. 59 static constexpr Uniform kIntrinsicUniforms[] = { {"viewport", SkSLType::kFloat4}, 60 {"dstReadBounds", SkSLType::kFloat4} }; 61 62 void CollectIntrinsicUniforms(const Caps* caps, 63 SkIRect viewport, 64 SkIRect dstReadBounds, 65 UniformManager*); 66 67 bool IsDstReadRequired(const Caps*, std::optional<SkBlendMode>, Coverage); 68 69 std::string GetPipelineLabel(const ShaderCodeDictionary*, 70 const RenderPassDesc& renderPassDesc, 71 const RenderStep* renderStep, 72 UniquePaintParamsID paintID); 73 74 // TODO(b/396420770): Right now, BuildComputeSkSL must consider the backend in order to make certain 75 // decisions. It would be ideal if we could make this more backend-agnostic, perhaps by having a 76 // compute-specific equivalent to ResourceBindingRequirements. 77 std::string BuildComputeSkSL(const Caps*, const ComputeStep*, BackendApi); 78 79 std::string EmitSamplerLayout(const ResourceBindingRequirements&, int* binding); 80 81 } // namespace graphite 82 } // namespace skgpu 83 84 #endif // skgpu_graphite_ContextUtils_DEFINED 85