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::graphite { 20 21 class ComputeStep; 22 enum class Coverage; 23 enum class DstReadRequirement; 24 class Geometry; 25 class PaintParams; 26 class PipelineDataGatherer; 27 class Recorder; 28 struct RenderPassDesc; 29 class RenderStep; 30 class ShaderCodeDictionary; 31 class UniformManager; 32 class UniquePaintParamsID; 33 34 struct ResourceBindingRequirements; 35 36 UniquePaintParamsID ExtractPaintData(Recorder*, 37 PipelineDataGatherer* gatherer, 38 PaintParamsKeyBuilder* builder, 39 const Layout layout, 40 const SkM44& local2Dev, 41 const PaintParams&, 42 const Geometry& geometry, 43 const SkColorInfo& targetColorInfo); 44 45 // Intrinsic uniforms used by every program created in Graphite. 46 // 47 // `viewport` should hold the actual viewport set as backend state (defining the NDC -> pixel 48 // transform). The viewport's dimensions are used to define the SkDevice->NDC transform applied in 49 // the vertex shader, but this assumes that the (0,0) device coordinate maps to the corner of the 50 // top-left of the NDC cube. The viewport's origin is used in the fragment shader to reconstruct 51 // the logical fragment coordinate from the target's current frag coord (which are not relative to 52 // active viewport). 53 // 54 // It is assumed that `dstCopyBounds` is in the same coordinate space as the `viewport` (e.g. 55 // final backing target's pixel coords) and that its width and height match the dimensions of the 56 // texture to be sampled for dst reads. 57 static constexpr Uniform kIntrinsicUniforms[] = { {"viewport", SkSLType::kFloat4}, 58 {"dstCopyBounds", SkSLType::kFloat4} }; 59 60 void CollectIntrinsicUniforms( 61 const Caps* caps, 62 SkIRect viewport, 63 SkIRect dstCopyBounds, 64 UniformManager*); 65 66 DstReadRequirement GetDstReadRequirement(const Caps*, std::optional<SkBlendMode>, Coverage); 67 68 std::string GetPipelineLabel(const ShaderCodeDictionary*, 69 const RenderPassDesc& renderPassDesc, 70 const RenderStep* renderStep, 71 UniquePaintParamsID paintID); 72 73 std::string BuildComputeSkSL(const Caps*, const ComputeStep*); 74 75 std::string EmitSamplerLayout(const ResourceBindingRequirements&, int* binding); 76 77 } // namespace skgpu::graphite 78 79 #endif // skgpu_graphite_ContextUtils_DEFINED 80