chromium/third_party/skia/src/gpu/graphite/dawn/DawnGraphiteUtilsPriv.h

/*
 * Copyright 2022 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_DawnGraphiteUtilsPriv_DEFINED
#define skgpu_graphite_DawnGraphiteUtilsPriv_DEFINED

#include "include/core/SkImageInfo.h"
#include "src/gpu/graphite/ResourceTypes.h"
#include "src/gpu/graphite/dawn/DawnGraphiteTypesPriv.h"
#include "src/sksl/SkSLProgramKind.h"
#include "src/sksl/ir/SkSLProgram.h"

#include "webgpu/webgpu_cpp.h"  // NO_G3_REWRITE

namespace SkSL {
class Compiler;
struct ProgramSettings;
}

namespace skgpu {
class ShaderErrorHandler;
}

namespace skgpu::graphite {
class DawnSharedContext;

bool DawnFormatIsDepthOrStencil(wgpu::TextureFormat);
bool DawnFormatIsDepth(wgpu::TextureFormat);
bool DawnFormatIsStencil(wgpu::TextureFormat);

wgpu::TextureFormat DawnDepthStencilFlagsToFormat(SkEnumBitMask<DepthStencilFlags>);

bool DawnCompileWGSLShaderModule(const DawnSharedContext* sharedContext,
                                 const char* label,
                                 const std::string& wgsl,
                                 wgpu::ShaderModule* module,
                                 ShaderErrorHandler*);

#if !defined(__EMSCRIPTEN__)
namespace ycbcrUtils {

bool DawnDescriptorIsValid(const wgpu::YCbCrVkDescriptor&);

bool DawnDescriptorUsesExternalFormat(const wgpu::YCbCrVkDescriptor&);

// The number of uint32s required to represent all relevant YCbCr conversion info depends upon
// whether we are using a known VkFormat or an external format. With a known format, we only
// require 2 - one for non-format information and another to store the VkFormat. External formats
// are represented as a uint64 and thus require an additional uint32.
static constexpr int kIntsNeededKnownFormat =;
static constexpr int kIntsNeededExternalFormat =;

static constexpr int kUsesExternalFormatBits  =;
static constexpr int kYcbcrModelBits          =;
static constexpr int kYcbcrRangeBits          =;
static constexpr int kXChromaOffsetBits       =;
static constexpr int kYChromaOffsetBits       =;
// wgpu::FilterMode contains Undefined/Nearest/Linear entries (Linear is 2).
static constexpr int kChromaFilterBits        =;
static constexpr int kForceExplicitReconBits  =;
static constexpr int kComponentBits           =;

static constexpr int kUsesExternalFormatShift =;
static constexpr int kYcbcrModelShift         =;
static constexpr int kYcbcrRangeShift         =;
static constexpr int kXChromaOffsetShift      =;
static constexpr int kYChromaOffsetShift      =;
static constexpr int kChromaFilterShift       =;
static constexpr int kForceExplicitReconShift =;
static constexpr int kComponentRShift         =;
static constexpr int kComponentGShift         =;
static constexpr int kComponentBShift         =;
static constexpr int kComponentAShift         =;

static constexpr uint32_t kUseExternalFormatMask =;
static constexpr uint32_t kYcbcrModelMask =;
static constexpr uint32_t kYcbcrRangeMask =;
static constexpr uint32_t kXChromaOffsetMask =;
static constexpr uint32_t kYChromaOffsetMask =;
static constexpr uint32_t kChromaFilterMask =;
static constexpr uint32_t kForceExplicitReconMask =;
static constexpr uint32_t kComponentRMask =;
static constexpr uint32_t kComponentBMask =;
static constexpr uint32_t kComponentGMask =;
static constexpr uint32_t kComponentAMask =;
} // namespace ycbcrUtils
#endif // !defined(__EMSCRIPTEN__)

} // namespace skgpu::graphite

#endif // skgpu_graphite_DawnGraphiteUtilsPriv_DEFINED