| 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 |
#ifndef skgpu_graphite_Caps_DEFINED |
| 8 |
#define skgpu_graphite_Caps_DEFINED |
| 9 |
|
| 10 |
#include "include/core/SkColorType.h" |
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkSize.h" |
| 13 |
#include "include/gpu/GpuTypes.h" |
| 14 |
#include "include/private/base/SkAlign.h" |
| 15 |
#include "include/private/base/SkAssert.h" |
| 16 |
#include "src/base/SkEnumBitMask.h" |
| 17 |
#include "src/gpu/ResourceKey.h" |
| 18 |
#include "src/gpu/Swizzle.h" |
| 19 |
#include "src/gpu/graphite/ResourceTypes.h" |
| 20 |
#include "src/text/gpu/SubRunControl.h" |
| 21 |
|
| 22 |
#include <cstddef> |
| 23 |
#include <cstdint> |
| 24 |
#include <memory> |
| 25 |
#include <string> |
| 26 |
#include <string_view> |
| 27 |
#include <utility> |
| 28 |
|
| 29 |
class SkCapabilities; |
| 30 |
enum class SkTextureCompressionType; |
| 31 |
|
| 32 |
namespace SkSL { struct ShaderCaps; } |
| 33 |
|
| 34 |
namespace skgpu { class ShaderErrorHandler; } |
| 35 |
|
| 36 |
namespace skgpu::graphite { |
| 37 |
|
| 38 |
class ComputePipelineDesc; |
| 39 |
class GraphicsPipelineDesc; |
| 40 |
class GraphiteResourceKey; |
| 41 |
class RendererProvider; |
| 42 |
class TextureInfo; |
| 43 |
enum class DepthStencilFlags : int; |
| 44 |
enum class PathRendererStrategy; |
| 45 |
enum class TextureFormat : uint8_t; |
| 46 |
struct AttachmentDesc; |
| 47 |
struct ContextOptions; |
| 48 |
struct RenderPassDesc; |
| 49 |
|
| 50 |
struct ResourceBindingRequirements { |
| 51 |
/* The API of the backend currently in use. */ |
| 52 |
BackendApi fBackendApi = BackendApi::kUnsupported; |
| 53 |
|
| 54 |
/* The required data layout rules for the contents of a uniform buffer. */ |
| 55 |
Layout fUniformBufferLayout = Layout::kInvalid; |
| 56 |
|
| 57 |
/* The required data layout rules for the contents of a storage buffer. */ |
| 58 |
Layout fStorageBufferLayout = Layout::kInvalid; |
| 59 |
|
| 60 |
/** |
| 61 |
* Whether combined texture-sampler types are supported. Backends that do not support combined |
| 62 |
* image samplers (i.e. sampler2D) require a texture and sampler object to be bound separately |
| 63 |
* and their binding indices explicitly specified in the shader text. |
| 64 |
*/ |
| 65 |
bool fSeparateTextureAndSamplerBinding = false; |
| 66 |
|
| 67 |
/** |
| 68 |
* Whether intrinsic constant information is stored as push constants (rather than normal UBO). |
| 69 |
* Currently only relevant or possibly true for Dawn or Vulkan. |
| 70 |
*/ |
| 71 |
bool fUsePushConstantsForIntrinsicConstants = false; |
| 72 |
|
| 73 |
/** |
| 74 |
* Whether compute shader textures use separate index ranges from other resources (i.e. buffers) |
| 75 |
*/ |
| 76 |
bool fComputeUsesDistinctIdxRangesForTextures = false; |
| 77 |
|
| 78 |
/** |
| 79 |
* Define set indices. We assume that even if textures and samplers must be bound separately, |
| 80 |
* they will still be contained within the same set/group. |
| 81 |
*/ |
| 82 |
static constexpr int kUnassigned = -1; |
| 83 |
int fUniformsSetIdx = kUnassigned; |
| 84 |
int fTextureSamplerSetIdx = kUnassigned; |
| 85 |
int fInputAttachmentSetIdx = kUnassigned; |
| 86 |
/* Define uniform buffer bindings */ |
| 87 |
int fIntrinsicBufferBinding = kUnassigned; |
| 88 |
int fCombinedUniformBufferBinding = kUnassigned; |
| 89 |
int fGradientBufferBinding = kUnassigned; |
| 90 |
}; |
| 91 |
|
| 92 |
class Caps { |
| 93 |
public: |
| 94 |
virtual ~Caps(); |
| 95 |
|
| 96 |
const SkSL::ShaderCaps* shaderCaps() const { return fShaderCaps.get(); } |
| 97 |
|
| 98 |
sk_sp<SkCapabilities> capabilities() const; |
| 99 |
|
| 100 |
#if defined(GPU_TEST_UTILS) |
| 101 |
std::string_view deviceName() const { return fDeviceName; } |
| 102 |
|
| 103 |
std::optional<PathRendererStrategy> requestedPathRendererStrategy() const { |
| 104 |
return fRequestedPathRendererStrategy; |
| 105 |
} |
| 106 |
#endif |
| 107 |
|
| 108 |
/** |
| 109 |
* TODO(b/390473370): Once backends initialize a Caps-level format table, these will not need |
| 110 |
* to be virtual anymore: |
| 111 |
*/ |
| 112 |
virtual bool isSampleCountSupported(TextureFormat, SampleCount) const = 0; |
| 113 |
/* Return the TextureFormat that satisfies `dsFlags`. */ |
| 114 |
virtual TextureFormat getDepthStencilFormat(SkEnumBitMask<DepthStencilFlags>) const = 0; |
| 115 |
|
| 116 |
virtual TextureInfo getDefaultAttachmentTextureInfo(AttachmentDesc, |
| 117 |
Protected, |
| 118 |
Discardable) const = 0; |
| 119 |
|
| 120 |
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, |
| 121 |
Mipmapped, |
| 122 |
Protected, |
| 123 |
Renderable) const = 0; |
| 124 |
|
| 125 |
virtual TextureInfo getTextureInfoForSampledCopy(const TextureInfo&, |
| 126 |
Mipmapped) const = 0; |
| 127 |
|
| 128 |
virtual TextureInfo getDefaultCompressedTextureInfo(SkTextureCompressionType, |
| 129 |
Mipmapped, |
| 130 |
Protected) const = 0; |
| 131 |
|
| 132 |
virtual TextureInfo getDefaultStorageTextureInfo(SkColorType) const = 0; |
| 133 |
|
| 134 |
/* Get required depth attachment dimensions for a givin color attachment info and dimensions. */ |
| 135 |
virtual SkISize getDepthAttachmentDimensions(const TextureInfo&, |
| 136 |
const SkISize colorAttachmentDimensions) const; |
| 137 |
|
| 138 |
virtual UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc&, |
| 139 |
const RenderPassDesc&) const = 0; |
| 140 |
virtual UniqueKey makeComputePipelineKey(const ComputePipelineDesc&) const = 0; |
| 141 |
|
| 142 |
|
| 143 |
virtual bool extractGraphicsDescs(const UniqueKey&, |
| 144 |
GraphicsPipelineDesc*, |
| 145 |
RenderPassDesc*, |
| 146 |
const RendererProvider*) const { return false; } |
| 147 |
|
| 148 |
SkColorType getDefaultColorType(const TextureInfo&) const; |
| 149 |
bool areColorTypeAndTextureInfoCompatible(SkColorType, const TextureInfo&) const; |
| 150 |
|
| 151 |
// Tries to return a sample count > 1 if needing MSAA to render into the target specification. |
| 152 |
// If the target is already multisampled, it will be that count; otherwise it will be the |
| 153 |
// highest supported sample count less than the configured max internal sample count. |
| 154 |
// |
| 155 |
// NOTE: If avoidMSAA() is true (either from ContextOptions or driver workarounds), the max |
| 156 |
// internal sample count is 1. In this case getCompatibleMSAASampleCount() returns k1 for single |
| 157 |
// sampled targets to show MSAA isn't supported. |
| 158 |
SampleCount getCompatibleMSAASampleCount(const TextureInfo&) const; |
| 159 |
|
| 160 |
bool isTexturable(const TextureInfo&) const; |
| 161 |
virtual bool isRenderable(const TextureInfo&) const = 0; |
| 162 |
virtual bool isStorage(const TextureInfo&) const = 0; |
| 163 |
|
| 164 |
virtual bool loadOpAffectsMSAAPipelines() const { return false; } |
| 165 |
|
| 166 |
int maxTextureSize() const { return fMaxTextureSize; } |
| 167 |
|
| 168 |
bool avoidMSAA() const { |
| 169 |
// Publicly, treat avoiding MSAA due to device issues or due to client option equivalently. |
| 170 |
return fAvoidMSAA || fMaxInternalSampleCount == SampleCount::k1; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Returns the maximum number of varyings allowed in a render pipeline. Note that this is the |
| 175 |
* number of varying variables, not the total number of varying scalars. |
| 176 |
*/ |
| 177 |
int maxVaryings() const { return fMaxVaryings; } |
| 178 |
|
| 179 |
virtual void buildKeyForTexture(SkISize dimensions, |
| 180 |
const TextureInfo&, |
| 181 |
ResourceType, |
| 182 |
GraphiteResourceKey*) const = 0; |
| 183 |
|
| 184 |
const ResourceBindingRequirements& resourceBindingRequirements() const { |
| 185 |
return fResourceBindingReqs; |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Returns the required alignment in bytes for the offset into a uniform buffer when binding it |
| 190 |
* to a draw. |
| 191 |
*/ |
| 192 |
size_t requiredUniformBufferAlignment() const { return fRequiredUniformBufferAlignment; } |
| 193 |
|
| 194 |
/** |
| 195 |
* Returns the required alignment in bytes for the offset into a storage buffer when binding it |
| 196 |
* to a draw. |
| 197 |
*/ |
| 198 |
size_t requiredStorageBufferAlignment() const { return fRequiredStorageBufferAlignment; } |
| 199 |
|
| 200 |
/** |
| 201 |
* Returns the required alignment in bytes for the offset and size of copies involving a buffer. |
| 202 |
*/ |
| 203 |
size_t requiredTransferBufferAlignment() const { return fRequiredTransferBufferAlignment; } |
| 204 |
|
| 205 |
/* Returns the aligned rowBytes when transferring to or from a Texture */ |
| 206 |
size_t getAlignedTextureDataRowBytes(size_t rowBytes) const { |
| 207 |
return SkAlignTo(rowBytes, fTextureDataRowBytesAlignment); |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* Backends can optionally override this method to return meaningful sampler conversion info. |
| 212 |
* By default, simply return a default ImmutableSamplerInfo (e.g. no immutable sampler). |
| 213 |
*/ |
| 214 |
virtual ImmutableSamplerInfo getImmutableSamplerInfo(const TextureInfo&) const { |
| 215 |
return {}; |
| 216 |
} |
| 217 |
|
| 218 |
/* Returns a compressed label describing the immutable sampler for the Pipeline label */ |
| 219 |
virtual std::string toString(const ImmutableSamplerInfo&) const { return ""; } |
| 220 |
|
| 221 |
/** |
| 222 |
* Backends may have restrictions on what types of textures support Device::writePixels(). |
| 223 |
* If this returns false then the caller should implement a fallback where a temporary texture |
| 224 |
* is created, pixels are written to it, and then that is copied or drawn into the surface. |
| 225 |
*/ |
| 226 |
virtual bool supportsWritePixels(const TextureInfo&) const = 0; |
| 227 |
|
| 228 |
/** |
| 229 |
* Backends may have restrictions on what types of textures support Device::readPixels(). |
| 230 |
* If this returns false then the caller should implement a fallback where a temporary texture |
| 231 |
* is created, the original texture is copied or drawn into it, and then pixels read from |
| 232 |
* the temporary texture. |
| 233 |
*/ |
| 234 |
virtual bool supportsReadPixels(const TextureInfo&) const = 0; |
| 235 |
|
| 236 |
/** |
| 237 |
* Given a texture config and its color type interpretation, returns the color type that matches |
| 238 |
* the texture's layout after a copy (i.e. does not have any of the automatic swizzling that |
| 239 |
* occurs during regular sampling). The returned colortype either represents the color type that |
| 240 |
* source data must be coaxed into for writePixels(), or it represents the color type after a |
| 241 |
* readPixels() operation. |
| 242 |
* |
| 243 |
* We currently don't have an SkColorType for a 3 channel RGB format. Additionally the current |
| 244 |
* implementation of raster pipeline requires power of 2 channels, so it is not easy to add such |
| 245 |
* an SkColorType. Thus we need to check for data that is 3 channels using the isRGBFormat |
| 246 |
* return value and handle it manually. |
| 247 |
*/ |
| 248 |
std::pair<SkColorType, bool /*isRGB888Format*/> supportedTransferColorType( |
| 249 |
SkColorType colorType, |
| 250 |
const TextureInfo& textureInfo) const; |
| 251 |
|
| 252 |
/** |
| 253 |
* Checks whether the passed color type is renderable. If so, the same color type is passed |
| 254 |
* back. If not, provides an alternative (perhaps lower bit depth and/or unorm instead of float) |
| 255 |
* color type that is supported or kUnknown if there no renderable fallback format. |
| 256 |
*/ |
| 257 |
SkColorType getRenderableColorType(SkColorType) const; |
| 258 |
|
| 259 |
/** |
| 260 |
* Determines the orientation of the NDC coordinates emitted by the vertex stage relative to |
| 261 |
* both Skia's presumed top-left Y-down system and the viewport coordinates (which are also |
| 262 |
* always top-left, Y-down for all supported backends).) |
| 263 |
* |
| 264 |
* If true is returned, then (-1,-1) in normalized device coords maps to the top-left of the |
| 265 |
* configured viewport and positive Y points down. This aligns with Skia's conventions. |
| 266 |
* If false is returned, then (-1,-1) in NDC maps to the bottom-left of the viewport and |
| 267 |
* positive Y points up (so NDC is flipped relative to sk_Position and the viewport coords). |
| 268 |
* |
| 269 |
* There is no backend difference in handling the X axis so it's assumed -1 maps to the left |
| 270 |
* edge and +1 maps to the right edge. |
| 271 |
*/ |
| 272 |
bool ndcYAxisPointsDown() const { return fNDCYAxisPointsDown; } |
| 273 |
|
| 274 |
bool clampToBorderSupport() const { return fClampToBorderSupport; } |
| 275 |
|
| 276 |
bool protectedSupport() const { return fProtectedSupport; } |
| 277 |
|
| 278 |
/* Supports BackendSemaphores */ |
| 279 |
bool semaphoreSupport() const { return fSemaphoreSupport; } |
| 280 |
|
| 281 |
/* If false then calling Context::submit with SyncToCpu::kYes is an error. */ |
| 282 |
bool allowCpuSync() const { return fAllowCpuSync; } |
| 283 |
|
| 284 |
/* Returns whether storage buffers are supported and to be preferred over uniform buffers. */ |
| 285 |
bool storageBufferSupport() const { return fStorageBufferSupport; } |
| 286 |
|
| 287 |
/** |
| 288 |
* The gradient buffer is an unsized float array so it is only optimal memory-wise to use it if |
| 289 |
* the storage buffer memory layout is std430 or in metal, which is also the only supported |
| 290 |
* way the data is packed. |
| 291 |
*/ |
| 292 |
bool gradientBufferSupport() const { |
| 293 |
return fStorageBufferSupport && |
| 294 |
(fResourceBindingReqs.fStorageBufferLayout == Layout::kStd430 || |
| 295 |
fResourceBindingReqs.fStorageBufferLayout == Layout::kMetal); |
| 296 |
} |
| 297 |
|
| 298 |
/* Returns whether a draw buffer can be mapped. */ |
| 299 |
bool drawBufferCanBeMapped() const { return fDrawBufferCanBeMapped; } |
| 300 |
|
| 301 |
#if defined(GPU_TEST_UTILS) |
| 302 |
bool drawBufferCanBeMappedForReadback() const { return fDrawBufferCanBeMappedForReadback; } |
| 303 |
#endif |
| 304 |
|
| 305 |
/** |
| 306 |
* Returns whether using Buffer::asyncMap() must be used to map buffers. map() may only be |
| 307 |
* called after asyncMap() is called and will fail if the asynchronous map is not complete. This |
| 308 |
* excludes premapped buffers for which map() can be called freely until the first unmap() call. |
| 309 |
*/ |
| 310 |
bool bufferMapsAreAsync() const { return fBufferMapsAreAsync; } |
| 311 |
|
| 312 |
/* Returns whether multisampled render to single sampled is supported. */ |
| 313 |
bool msaaRenderToSingleSampledSupport() const { return fMSAARenderToSingleSampledSupport; } |
| 314 |
|
| 315 |
/* Returns whether multisampled render to single sampled is supported for a given texture. */ |
| 316 |
virtual bool msaaTextureRenderToSingleSampledSupport(const TextureInfo& info) const { |
| 317 |
return this->msaaRenderToSingleSampledSupport(); |
| 318 |
} |
| 319 |
|
| 320 |
/** |
| 321 |
* Returns whether a render pass can have MSAA/depth/stencil attachments and a resolve |
| 322 |
* attachment with mismatched sizes. Note: the MSAA attachment and the depth/stencil attachment |
| 323 |
* still need to match their sizes. |
| 324 |
* This also implies supporting partial load/resolve. |
| 325 |
*/ |
| 326 |
bool differentResolveAttachmentSizeSupport() const { |
| 327 |
return fDifferentResolveAttachmentSizeSupport; |
| 328 |
} |
| 329 |
|
| 330 |
/* Returns whether compute shaders are supported. */ |
| 331 |
bool computeSupport() const { return fComputeSupport; } |
| 332 |
|
| 333 |
/** |
| 334 |
* Returns true if the given backend supports importing AHardwareBuffers. This will only |
| 335 |
* ever be supported on Android devices with API level >= 26. |
| 336 |
*/ |
| 337 |
bool supportsAHardwareBufferImages() const { return fSupportsAHardwareBufferImages; } |
| 338 |
|
| 339 |
/** |
| 340 |
* Enum representing the capabilities of the fixed function blend unit. |
| 341 |
*/ |
| 342 |
enum BlendEquationSupport : uint8_t { |
| 343 |
kBasic = 0, /* Default bare minimum support. Allows selecting the operator that |
| 344 |
combines src + dst terms.*/ |
| 345 |
kAdvancedNoncoherent, /* Additional fixed function support for specific SVG/PDF blend modes. |
| 346 |
Requires blend barriers.*/ |
| 347 |
kAdvancedCoherent /* Advanced blend equation support that does not require blend |
| 348 |
barriers and permits overlap.*/ |
| 349 |
}; |
| 350 |
/** |
| 351 |
* Return the level of hardware advanced blend mode support. |
| 352 |
*/ |
| 353 |
BlendEquationSupport blendEquationSupport() const { return fBlendEqSupport; } |
| 354 |
/** |
| 355 |
* Simple helper for indicating whether the hardware supports advanced blend modes at all |
| 356 |
* (coherent or noncoherent). |
| 357 |
*/ |
| 358 |
bool supportsHardwareAdvancedBlending() const { |
| 359 |
return fBlendEqSupport > BlendEquationSupport::kBasic; |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* Returns the skgpu::Swizzle to use when sampling or reading back from a texture with the |
| 364 |
* passed in SkColorType and TextureInfo. |
| 365 |
*/ |
| 366 |
skgpu::Swizzle getReadSwizzle(SkColorType, const TextureInfo&) const; |
| 367 |
|
| 368 |
/** |
| 369 |
* Returns the skgpu::Swizzle to use when writing colors to a surface with the passed in |
| 370 |
* SkColorType and TextureInfo. |
| 371 |
*/ |
| 372 |
skgpu::Swizzle getWriteSwizzle(SkColorType, const TextureInfo&) const; |
| 373 |
|
| 374 |
/** |
| 375 |
* Includes the following dynamic state: |
| 376 |
* |
| 377 |
* * Line width, depth bias, depth bounds, stencil compare mask, stencil write mask and stencil |
| 378 |
* reference. |
| 379 |
* This set corresponds to Vulkan 1.0 dynamic state. Blend constants does not depend on this |
| 380 |
* flag as it is always dynamic with all graphite backends. |
| 381 |
* |
| 382 |
* * Depth test enable, depth write enable, depth compare op, depth bounds test enable, depth |
| 383 |
* bias enable, stencil test enable and stencil op. |
| 384 |
* This set corresponds to depth and stencil related state from VK_EXT_extended_dynamic_state |
| 385 |
* and VK_EXT_extended_dynamic_state2. |
| 386 |
* |
| 387 |
* * Primitive topology and primitive restart enable. |
| 388 |
* Note that the primitive topology _class_ is not dynamic. |
| 389 |
* This set corresponds to input assembly state from VK_EXT_extended_dynamic_state and |
| 390 |
* VK_EXT_extended_dynamic_state2. |
| 391 |
* |
| 392 |
* * Cull mode, front face and rasterizer discard. |
| 393 |
* This set corresponds to rasterizer state from VK_EXT_extended_dynamic_state and |
| 394 |
* VK_EXT_extended_dynamic_state2. |
| 395 |
*/ |
| 396 |
bool useBasicDynamicState() const { return fUseBasicDynamicState; } |
| 397 |
/** |
| 398 |
* Whether all vertex input state is dynamic. |
| 399 |
* This set corresponds to state from VK_EXT_vertex_input_dynamic_state. This state is |
| 400 |
* equivalently pulled out of the shaders pipeline via VK_EXT_graphics_pipeline_library |
| 401 |
* (usePipelineLibraries()). |
| 402 |
*/ |
| 403 |
bool useVertexInputDynamicState() const { return fUseVertexInputDynamicState; } |
| 404 |
/** |
| 405 |
* Whether VK_EXT_graphics_pipeline_library should be used. In this case, the "shaders" subset |
| 406 |
* of the pipeline is compiled separately, then fast-linked with the vertex input and fragment |
| 407 |
* output state to create the final library. Currently, this is a detail of the Vulkan backend, |
| 408 |
* which helps VkPipelineCache hits (because the shaders pipeline hits the cache, and blend |
| 409 |
* state is patched in). However, this is most useful once exposed to the front-end, such that |
| 410 |
* it can track the (fewer) shaders pipeline separately, have the complete pipelines point to |
| 411 |
* the shaders pipeline, avoid unnecessary cache look ups, and more. (skbug.com/414645289) |
| 412 |
*/ |
| 413 |
bool usePipelineLibraries() const { return fUsePipelineLibraries; } |
| 414 |
|
| 415 |
bool supportsHostImageCopy() const { return fSupportsHostImageCopy; } |
| 416 |
|
| 417 |
skgpu::ShaderErrorHandler* shaderErrorHandler() const { return fShaderErrorHandler; } |
| 418 |
|
| 419 |
/** |
| 420 |
* Returns what method of dst read a draw should use for obtaining the dst color. Backends can |
| 421 |
* use the default implementation or override this method as needed. |
| 422 |
*/ |
| 423 |
virtual DstReadStrategy getDstReadStrategy() const; |
| 424 |
|
| 425 |
float minPathSizeForMSAA() const { return fMinMSAAPathSize; } |
| 426 |
float minDistanceFieldFontSize() const { return fMinDistanceFieldFontSize; } |
| 427 |
float glyphsAsPathsFontSize() const { return fGlyphsAsPathsFontSize; } |
| 428 |
|
| 429 |
size_t glyphCacheTextureMaximumBytes() const { return fGlyphCacheTextureMaximumBytes; } |
| 430 |
int maxPathAtlasTextureSize() const { return fMaxPathAtlasTextureSize; } |
| 431 |
|
| 432 |
bool allowMultipleAtlasTextures() const { return fAllowMultipleAtlasTextures; } |
| 433 |
bool supportBilerpFromGlyphAtlas() const { return fSupportBilerpFromGlyphAtlas; } |
| 434 |
|
| 435 |
bool requireOrderedRecordings() const { return fRequireOrderedRecordings; } |
| 436 |
|
| 437 |
/** |
| 438 |
* When uploading to a full compressed texture do we need to pad the size out to a multiple of |
| 439 |
* the block width and height. |
| 440 |
*/ |
| 441 |
bool fullCompressedUploadSizeMustAlignToBlockDims() const { |
| 442 |
return fFullCompressedUploadSizeMustAlignToBlockDims; |
| 443 |
} |
| 444 |
|
| 445 |
sktext::gpu::SubRunControl getSubRunControl(bool useSDFTForSmallText) const; |
| 446 |
|
| 447 |
bool setBackendLabels() const { return fSetBackendLabels; } |
| 448 |
|
| 449 |
GpuStatsFlags supportedGpuStats() const { return fSupportedGpuStats; } |
| 450 |
|
| 451 |
protected: |
| 452 |
Caps(); |
| 453 |
|
| 454 |
/** |
| 455 |
* Subclasses must call this at the end of their init method in order to do final processing on |
| 456 |
* the caps. |
| 457 |
*/ |
| 458 |
void finishInitialization(const ContextOptions&); |
| 459 |
|
| 460 |
#if defined(GPU_TEST_UTILS) |
| 461 |
void setDeviceName(std::string n) { |
| 462 |
fDeviceName = std::move(n); |
| 463 |
} |
| 464 |
#endif |
| 465 |
|
| 466 |
/* ColorTypeInfo for a specific format. Used in format tables. */ |
| 467 |
struct ColorTypeInfo { |
| 468 |
ColorTypeInfo() = default; |
| 469 |
ColorTypeInfo(SkColorType ct, SkColorType transferCt, uint32_t flags, |
| 470 |
skgpu::Swizzle readSwizzle, skgpu::Swizzle writeSwizzle) |
| 471 |
: fColorType(ct) |
| 472 |
, fTransferColorType(transferCt) |
| 473 |
, fFlags(flags) |
| 474 |
, fReadSwizzle(readSwizzle) |
| 475 |
, fWriteSwizzle(writeSwizzle) {} |
| 476 |
|
| 477 |
SkColorType fColorType = kUnknown_SkColorType; |
| 478 |
SkColorType fTransferColorType = kUnknown_SkColorType; |
| 479 |
enum { |
| 480 |
kUploadData_Flag = 0x1, |
| 481 |
/** |
| 482 |
* Does Graphite itself support rendering to this colorType & format pair. Renderability |
| 483 |
* still additionally depends on if the format itself is renderable. |
| 484 |
*/ |
| 485 |
kRenderable_Flag = 0x2, |
| 486 |
}; |
| 487 |
uint32_t fFlags = 0; |
| 488 |
|
| 489 |
skgpu::Swizzle fReadSwizzle; |
| 490 |
skgpu::Swizzle fWriteSwizzle; |
| 491 |
}; |
| 492 |
|
| 493 |
int fMaxTextureSize = 0; |
| 494 |
|
| 495 |
size_t fRequiredUniformBufferAlignment = 0; |
| 496 |
size_t fRequiredStorageBufferAlignment = 0; |
| 497 |
size_t fRequiredTransferBufferAlignment = 0; |
| 498 |
size_t fTextureDataRowBytesAlignment = 1; |
| 499 |
|
| 500 |
int fMaxVaryings = 0; |
| 501 |
|
| 502 |
std::unique_ptr<SkSL::ShaderCaps> fShaderCaps; |
| 503 |
|
| 504 |
bool fNDCYAxisPointsDown = false; // Most backends have NDC +Y pointing up |
| 505 |
bool fClampToBorderSupport = true; |
| 506 |
bool fProtectedSupport = false; |
| 507 |
bool fSemaphoreSupport = false; |
| 508 |
bool fAllowCpuSync = true; |
| 509 |
bool fStorageBufferSupport = false; |
| 510 |
bool fDrawBufferCanBeMapped = true; |
| 511 |
bool fBufferMapsAreAsync = false; |
| 512 |
bool fMSAARenderToSingleSampledSupport = false; |
| 513 |
bool fDifferentResolveAttachmentSizeSupport = false; |
| 514 |
bool fAvoidMSAA = false; |
| 515 |
|
| 516 |
bool fComputeSupport = false; |
| 517 |
bool fSupportsAHardwareBufferImages = false; |
| 518 |
bool fFullCompressedUploadSizeMustAlignToBlockDims = false; |
| 519 |
|
| 520 |
// Dynamic state. The granularity is less fine than Vulkan's, but there is still some |
| 521 |
// granularity to allow for some dynamic state to be disabled due to driver bugs without having |
| 522 |
// to disable everything. Eventually, these can be used to create fewer pipelines in the first |
| 523 |
// place (b/414645289). |
| 524 |
bool fUseBasicDynamicState = false; |
| 525 |
bool fUseVertexInputDynamicState = false; |
| 526 |
bool fUsePipelineLibraries = false; |
| 527 |
|
| 528 |
// Whether it's possible to upload data to images using the CPU (host) instead of the device. |
| 529 |
// Under certain circumstances, it's more efficient to upload data in this way instead of |
| 530 |
// through a staging buffer. |
| 531 |
bool fSupportsHostImageCopy = false; |
| 532 |
|
| 533 |
#if defined(GPU_TEST_UTILS) |
| 534 |
bool fDrawBufferCanBeMappedForReadback = true; |
| 535 |
#endif |
| 536 |
|
| 537 |
ResourceBindingRequirements fResourceBindingReqs; |
| 538 |
BlendEquationSupport fBlendEqSupport = BlendEquationSupport::kBasic; |
| 539 |
|
| 540 |
GpuStatsFlags fSupportedGpuStats = GpuStatsFlags::kNone; |
| 541 |
|
| 542 |
////////////////////////////////////////////////////////////////////////////////////////// |
| 543 |
// Client-provided Caps |
| 544 |
|
| 545 |
/** |
| 546 |
* If present, use this object to report shader compilation failures. If not, report failures |
| 547 |
* via SkDebugf and assert. |
| 548 |
*/ |
| 549 |
ShaderErrorHandler* fShaderErrorHandler = nullptr; |
| 550 |
|
| 551 |
#if defined(GPU_TEST_UTILS) |
| 552 |
std::string fDeviceName; |
| 553 |
std::optional<PathRendererStrategy> fRequestedPathRendererStrategy; |
| 554 |
#endif |
| 555 |
|
| 556 |
// NOTE: This is a requested limit, the actual supported sample counts for a particular format |
| 557 |
// could be lower or higher. |
| 558 |
SampleCount fMaxInternalSampleCount = SampleCount::k4; |
| 559 |
|
| 560 |
size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; |
| 561 |
|
| 562 |
float fMinMSAAPathSize = 0; |
| 563 |
float fMinDistanceFieldFontSize = 18; |
| 564 |
float fGlyphsAsPathsFontSize = 324; |
| 565 |
|
| 566 |
int fMaxPathAtlasTextureSize = 8192; |
| 567 |
|
| 568 |
bool fAllowMultipleAtlasTextures = true; |
| 569 |
bool fSupportBilerpFromGlyphAtlas = false; |
| 570 |
|
| 571 |
bool fRequireOrderedRecordings = false; |
| 572 |
|
| 573 |
bool fSetBackendLabels = false; |
| 574 |
|
| 575 |
private: |
| 576 |
virtual bool onIsTexturable(const TextureInfo&) const = 0; |
| 577 |
virtual SkSpan<const ColorTypeInfo> getColorTypeInfos(const TextureInfo&) const = 0; |
| 578 |
|
| 579 |
const ColorTypeInfo* getColorTypeInfo(SkColorType, const TextureInfo&) const; |
| 580 |
|
| 581 |
sk_sp<SkCapabilities> fCapabilities; |
| 582 |
}; |
| 583 |
|
| 584 |
} // namespace skgpu::graphite |
| 585 |
|
| 586 |
#endif // skgpu_graphite_Caps_DEFINED |