blob: c8bcbe1284261f04cf5c4619c3c8c4fd3c127d03 [file]
/*
* Copyright 2026 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef skgpu_graphite_SparseStripConfig_DEFINED
#define skgpu_graphite_SparseStripConfig_DEFINED
#include "include/core/SkColorType.h"
#include <array>
#include <cstddef>
#include <cstdint>
namespace skgpu::graphite {
// Tunable compile-time paramters that control various aspects of SparseStrips behavior
struct SparseStripConfig {
// These control the size, in pixels, of the tiles generated by polylines.
static constexpr uint16_t kTileWidth = 8;
static constexpr uint16_t kTileHeight = 8;
static_assert(kTileWidth == kTileHeight);
// The tile dimensions MUST match the hard coded constant in the fragment shader. If that value
// changes, this must be updated.
static_assert(kTileWidth == 8);
// These control the AlphaAtlasManager
static constexpr SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType;
static constexpr int32_t kAtlasBytesPerTexel = 4;
static_assert(kColorType == SkColorType::kRGBA_8888_SkColorType);
static constexpr int32_t kAtlasWidth = 8192;
static constexpr int32_t kAtlasWidthBytes = kAtlasWidth * kAtlasBytesPerTexel;
static constexpr int32_t kInitialAtlasRows = 1;
static constexpr int32_t kMaxAtlasRows = 8192;
static constexpr int32_t kMaxAtlasBytes = kAtlasWidth * kMaxAtlasRows *
kAtlasBytesPerTexel;
static constexpr int32_t kMaxTexturePages = 2;
// The AlphaAtlasManager uses a flipflopping allocation system that will break if the page count
// is increased beyond 2.
static_assert(kMaxTexturePages == 2);
// To avoid uploading the texture width, and to avoid a costly divide and mod in the shader, we
// assume that the atlas width is always fixed.
static_assert(kAtlasWidth == 8192);
// The number of MSAA SubSamples in SparseStrips rendering. We currently only support 8.
using SubSampleType = uint8_t;
static constexpr int32_t kNumSubSamples = sizeof(SubSampleType) * 8;
static_assert(!((kNumSubSamples & (kNumSubSamples - 1))));
static_assert(sizeof(SubSampleType) * 8 == kNumSubSamples);
static constexpr int32_t kLUTMaskWidth = 64;
static constexpr int32_t kLUTMaskHeight = 64;
static constexpr int32_t kLUTMaskWidthExcl = kLUTMaskWidth - 1;
static constexpr int32_t kLUTMaskHeightExcl = kLUTMaskHeight - 1;
static constexpr float kLUTMaskWidthF = static_cast<float>(kLUTMaskWidth);
static constexpr float kLUTMaskHeightF = static_cast<float>(kLUTMaskHeight);
static constexpr size_t kLUTSize = kLUTMaskWidth * kLUTMaskHeight;
using LUTArray = std::array<SubSampleType, kLUTSize>;
static constexpr float kStripEpsilon = 1e-5f;
};
} // namespace skgpu::graphite
#endif // skgpu_graphite_SparseStripConfig_DEFINED