| 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 "src/core/SkSLTypeShared.h" |
| 12 |
#include "src/gpu/graphite/Uniform.h" |
| 13 |
|
| 14 |
#include <cstdint> |
| 15 |
#include <optional> |
| 16 |
#include <string> |
| 17 |
|
| 18 |
class SkColorInfo; |
| 19 |
class SkM44; |
| 20 |
enum class SkBlendMode; |
| 21 |
struct SkIRect; |
| 22 |
|
| 23 |
namespace skgpu { |
| 24 |
enum class BackendApi : unsigned int; |
| 25 |
|
| 26 |
namespace graphite { |
| 27 |
class Caps; |
| 28 |
class ComputeStep; |
| 29 |
enum class Coverage; |
| 30 |
class FloatStorageManager; |
| 31 |
class Geometry; |
| 32 |
class PaintParams; |
| 33 |
class PaintParamsKeyBuilder; |
| 34 |
class PipelineDataGatherer; |
| 35 |
class Recorder; |
| 36 |
struct RenderPassDesc; |
| 37 |
class RenderStep; |
| 38 |
struct ResourceBindingRequirements; |
| 39 |
class ShaderCodeDictionary; |
| 40 |
enum class TextureFormat : uint8_t; |
| 41 |
class UniformManager; |
| 42 |
class UniquePaintParamsID; |
| 43 |
|
| 44 |
|
| 45 |
enum class Layout : uint8_t; |
| 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 |
// Returns whether or not hardware blending can be used. If not, we must perform a dst read within |
| 68 |
// the shader. If an SkBlender is used instead of an SkBlendMode, it can never use hardware blending |
| 69 |
bool CanUseHardwareBlending(const Caps*, TextureFormat, SkBlendMode, Coverage); |
| 70 |
|
| 71 |
std::string GetPipelineLabel(const Caps*, |
| 72 |
const ShaderCodeDictionary*, |
| 73 |
const RenderPassDesc& renderPassDesc, |
| 74 |
const RenderStep* renderStep, |
| 75 |
UniquePaintParamsID paintID); |
| 76 |
|
| 77 |
// TODO(b/396420770): Right now, BuildComputeSkSL must consider the backend in order to make certain |
| 78 |
// decisions. It would be ideal if we could make this more backend-agnostic, perhaps by having a |
| 79 |
// compute-specific equivalent to ResourceBindingRequirements. |
| 80 |
std::string BuildComputeSkSL(const Caps*, const ComputeStep*, BackendApi); |
| 81 |
|
| 82 |
std::string EmitSamplerLayout(const ResourceBindingRequirements&, int* binding); |
| 83 |
|
| 84 |
} // namespace graphite |
| 85 |
} // namespace skgpu |
| 86 |
|
| 87 |
#endif // skgpu_graphite_ContextUtils_DEFINED |