Flutter Engine
The Flutter Engine
VulkanGraphiteUtilsPriv.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 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_VulkanGraphiteUtilsPriv_DEFINED
9#define skgpu_graphite_VulkanGraphiteUtilsPriv_DEFINED
10
11#include "include/core/SkSpan.h"
16
17#include <string>
18
19// Helper macros to call functions on the VulkanInterface without checking for errors. Note: This
20// cannot require a VulkanSharedContext because driver calls are needed before the shared context
21// has been initialized.
22#define VULKAN_CALL(IFACE, X) (IFACE)->fFunctions.f##X
23
24// Must be called before checkVkResult, since this does not log if the VulkanSharedContext is
25// already considering the device to be lost.
26#define VULKAN_LOG_IF_NOT_SUCCESS(SHARED_CONTEXT, RESULT, X, ...) \
27 do { \
28 if (RESULT != VK_SUCCESS && !(SHARED_CONTEXT)->isDeviceLost()) { \
29 SkDebugf("Failed vulkan call. Error: %d, " X "\n", RESULT, ##__VA_ARGS__); \
30 } \
31 } while (false)
32
33#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X) \
34 do { \
35 (RESULT) = VULKAN_CALL((SHARED_CONTEXT)->interface(), X); \
36 SkASSERT(VK_SUCCESS == RESULT || VK_ERROR_DEVICE_LOST == RESULT); \
37 VULKAN_LOG_IF_NOT_SUCCESS(SHARED_CONTEXT, RESULT, #X); \
38 (SHARED_CONTEXT)->checkVkResult(RESULT); \
39 } while (false)
40
41// same as VULKAN_CALL but checks for success
42#define VULKAN_CALL_ERRCHECK(SHARED_CONTEXT, X) \
43 VkResult SK_MACRO_APPEND_LINE(ret); \
44 VULKAN_CALL_RESULT(SHARED_CONTEXT, SK_MACRO_APPEND_LINE(ret), X)
45
46#define VULKAN_CALL_RESULT_NOCHECK(IFACE, RESULT, X) \
47 do { \
48 (RESULT) = VULKAN_CALL(IFACE, X); \
49 } while (false)
50namespace skgpu::graphite {
51
52class VulkanSharedContext;
53
54VkShaderModule createVulkanShaderModule(const VulkanSharedContext*,
55 const std::string& spirv,
57
59void DescriptorDataToVkDescSetLayout(const VulkanSharedContext*,
61 VkDescriptorSetLayout*);
62
63namespace ycbcrPackaging {
64
65// Functions to aid with packaging ycbcr information in a compact way.
66int numInt32sNeeded(const VulkanYcbcrConversionInfo&);
67
68uint32_t nonFormatInfoAsUInt32(const VulkanYcbcrConversionInfo&);
69
70// The number of uint32s required to represent all relevant YCbCr conversion info depends upon
71// whether we are using a known VkFormat or an external format. With a known format, we only
72// require 2 - one for non-format information and another to store the VkFormat.
73static constexpr int kInt32sNeededKnownFormat = 2;
74// External formats are represented by a uint64 and require us to store format feature flags,
75// meaning that we end up with 4 uint32s total - 1 for non-format info, 2 for the format, and 1
76// for format feature flags.
77static constexpr int kInt32sNeededExternalFormat = 3;
78
79static constexpr int kUsesExternalFormatBits = 1;
80static constexpr int kYcbcrModelBits = 3;
81static constexpr int kYcbcrRangeBits = 1;
82static constexpr int kXChromaOffsetBits = 1;
83static constexpr int kYChromaOffsetBits = 1;
84static constexpr int kChromaFilterBits = 1;
85static constexpr int kForceExplicitReconBits = 1;
86static constexpr int kComponentBits = 3;
87
88static constexpr int kUsesExternalFormatShift = 0;
100
101static constexpr uint32_t kUseExternalFormatMask =
103static constexpr uint32_t kYcbcrModelMask =
104 ((1 << kYcbcrModelBits) - 1) << kYcbcrModelShift;
105static constexpr uint32_t kYcbcrRangeMask =
106 ((1 << kYcbcrRangeBits) - 1) << kYcbcrRangeShift;
107static constexpr uint32_t kXChromaOffsetMask =
109static constexpr uint32_t kYChromaOffsetMask =
111static constexpr uint32_t kChromaFilterMask =
113static constexpr uint32_t kForceExplicitReconMask =
115static constexpr uint32_t kComponentRMask = ((1 << kComponentBits) - 1) << kComponentRShift;
116static constexpr uint32_t kComponentBMask = ((1 << kComponentBits) - 1) << kComponentGShift;
117static constexpr uint32_t kComponentGMask = ((1 << kComponentBits) - 1) << kComponentBShift;
118static constexpr uint32_t kComponentAMask = ((1 << kComponentBits) - 1) << kComponentAShift;
119} // namespace ycbcrPackaging
120
122
124
125} // namespace skgpu::graphite
126
127#endif // skgpu_graphite_VulkanGraphiteUtilsPriv_DEFINED
static constexpr int kInt32sNeededKnownFormat
static constexpr uint32_t kYChromaOffsetMask
static constexpr int kInt32sNeededExternalFormat
static constexpr uint32_t kComponentAMask
static constexpr uint32_t kYcbcrRangeMask
static constexpr int kUsesExternalFormatBits
static constexpr uint32_t kComponentGMask
static constexpr uint32_t kXChromaOffsetMask
int numInt32sNeeded(const VulkanYcbcrConversionInfo &conversionInfo)
static constexpr uint32_t kUseExternalFormatMask
static constexpr uint32_t kYcbcrModelMask
static constexpr int kUsesExternalFormatShift
static constexpr int kForceExplicitReconShift
static constexpr int kForceExplicitReconBits
static constexpr uint32_t kChromaFilterMask
uint32_t nonFormatInfoAsUInt32(const VulkanYcbcrConversionInfo &conversionInfo)
static constexpr uint32_t kForceExplicitReconMask
static constexpr uint32_t kComponentRMask
static constexpr uint32_t kComponentBMask
VkShaderModule createVulkanShaderModule(const VulkanSharedContext *context, const std::string &spirv, VkShaderStageFlagBits stage)
VkDescriptorType DsTypeEnumToVkDs(DescriptorType type)
bool vkFormatIsSupported(VkFormat format)
void DescriptorDataToVkDescSetLayout(const VulkanSharedContext *ctxt, const SkSpan< DescriptorData > &requestedDescriptors, VkDescriptorSetLayout *outLayout)
VkShaderStageFlags PipelineStageFlagsToVkShaderStageFlags(SkEnumBitMask< PipelineStageFlags > stageFlags)
VkShaderStageFlagBits
Definition: vulkan_core.h:2664
VkFlags VkShaderStageFlags
Definition: vulkan_core.h:2731
VkDescriptorType
Definition: vulkan_core.h:2124
VkFormat
Definition: vulkan_core.h:1458