Flutter Engine
The Flutter Engine
GrVkUtil.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
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 GrVkUtil_DEFINED
9#define GrVkUtil_DEFINED
10
11#include "include/gpu/GrTypes.h"
19
20namespace SkSL { struct ProgramSettings; }
21class GrVkGpu;
22
23// makes a Vk call on the interface
24#define GR_VK_CALL(IFACE, X) (IFACE)->fFunctions.f##X
25
26// Note: must be called before checkVkResult, since this does not log if the GPU is already
27// considering the device to be lost.
28#define GR_VK_LOG_IF_NOT_SUCCESS(GPU, RESULT, X, ...) \
29 do { \
30 if (RESULT != VK_SUCCESS && !GPU->isDeviceLost()) { \
31 SkDebugf("Failed vulkan call. Error: %d, " X "\n", RESULT, ##__VA_ARGS__); \
32 } \
33 } while (false)
34
35#define GR_VK_CALL_RESULT(GPU, RESULT, X) \
36 do { \
37 (RESULT) = GR_VK_CALL(GPU->vkInterface(), X); \
38 SkASSERT(VK_SUCCESS == RESULT || VK_ERROR_DEVICE_LOST == RESULT); \
39 GR_VK_LOG_IF_NOT_SUCCESS(GPU, RESULT, #X); \
40 GPU->checkVkResult(RESULT); \
41 } while (false)
42
43#define GR_VK_CALL_RESULT_NOCHECK(GPU, RESULT, X) \
44 do { \
45 (RESULT) = GR_VK_CALL(GPU->vkInterface(), X); \
46 GPU->checkVkResult(RESULT); \
47 } while (false)
48
49// same as GR_VK_CALL but checks for success
50#define GR_VK_CALL_ERRCHECK(GPU, X) \
51 VkResult SK_MACRO_APPEND_LINE(ret); \
52 GR_VK_CALL_RESULT(GPU, SK_MACRO_APPEND_LINE(ret), X) \
53
54
56
57static constexpr GrColorFormatDesc GrVkFormatDesc(VkFormat vkFormat) {
58 switch (vkFormat) {
95
96 // Compressed texture formats are not expected to have a description.
100
101 // This type only describes color channels.
105
106 default: return GrColorFormatDesc::MakeInvalid();
107 }
108}
109
111 const std::string& shaderString,
113 VkShaderModule* shaderModule,
116 std::string* outSPIRV,
117 SkSL::Program::Interface* outInterface);
118
120 const std::string& spirv,
122 VkShaderModule* shaderModule,
124
125#endif
bool GrVkFormatIsSupported(VkFormat)
Definition: GrVkUtil.cpp:21
bool GrCompileVkShaderModule(GrVkGpu *gpu, const std::string &shaderString, VkShaderStageFlagBits stage, VkShaderModule *shaderModule, VkPipelineShaderStageCreateInfo *stageInfo, const SkSL::ProgramSettings &settings, std::string *outSPIRV, SkSL::Program::Interface *outInterface)
Definition: GrVkUtil.cpp:64
bool GrInstallVkShaderModule(GrVkGpu *gpu, const std::string &spirv, VkShaderStageFlagBits stage, VkShaderModule *shaderModule, VkPipelineShaderStageCreateInfo *stageInfo)
Definition: GrVkUtil.cpp:87
static constexpr GrColorFormatDesc GrVkFormatDesc(VkFormat vkFormat)
Definition: GrVkUtil.h:57
static constexpr GrColorFormatDesc MakeInvalid()
Definition: GrTypesPriv.h:756
static constexpr GrColorFormatDesc MakeRGBA(int rgba, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:720
static constexpr GrColorFormatDesc MakeRG(int rg, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:744
static constexpr GrColorFormatDesc MakeRGB(int rgb, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:728
static constexpr GrColorFormatDesc MakeR(int r, GrColorTypeEncoding e)
Definition: GrTypesPriv.h:740
VkShaderStageFlagBits
Definition: vulkan_core.h:2664
VkFormat
Definition: vulkan_core.h:1458
@ VK_FORMAT_R16G16B16A16_UNORM
Definition: vulkan_core.h:1550
@ VK_FORMAT_R8G8B8A8_SRGB
Definition: vulkan_core.h:1502
@ VK_FORMAT_R8G8B8_UNORM
Definition: vulkan_core.h:1482
@ VK_FORMAT_D24_UNORM_S8_UINT
Definition: vulkan_core.h:1588
@ VK_FORMAT_B8G8R8A8_UNORM
Definition: vulkan_core.h:1503
@ VK_FORMAT_R16G16_SFLOAT
Definition: vulkan_core.h:1542
@ VK_FORMAT_B4G4R4A4_UNORM_PACK16
Definition: vulkan_core.h:1462
@ VK_FORMAT_R16_SFLOAT
Definition: vulkan_core.h:1535
@ VK_FORMAT_R8G8_UNORM
Definition: vulkan_core.h:1475
@ VK_FORMAT_S8_UINT
Definition: vulkan_core.h:1586
@ VK_FORMAT_R8_UNORM
Definition: vulkan_core.h:1468
@ VK_FORMAT_R5G6B5_UNORM_PACK16
Definition: vulkan_core.h:1463
@ VK_FORMAT_R4G4B4A4_UNORM_PACK16
Definition: vulkan_core.h:1461
@ VK_FORMAT_A2B10G10R10_UNORM_PACK32
Definition: vulkan_core.h:1523
@ VK_FORMAT_R8G8B8A8_UNORM
Definition: vulkan_core.h:1496
@ VK_FORMAT_BC1_RGB_UNORM_BLOCK
Definition: vulkan_core.h:1590
@ VK_FORMAT_R16_UNORM
Definition: vulkan_core.h:1529
@ VK_FORMAT_R16G16B16A16_SFLOAT
Definition: vulkan_core.h:1556
@ VK_FORMAT_R16G16_UNORM
Definition: vulkan_core.h:1536
@ VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
Definition: vulkan_core.h:1606
@ VK_FORMAT_A2R10G10B10_UNORM_PACK32
Definition: vulkan_core.h:1517
@ VK_FORMAT_BC1_RGBA_UNORM_BLOCK
Definition: vulkan_core.h:1592
@ VK_FORMAT_B5G6R5_UNORM_PACK16
Definition: vulkan_core.h:1464
@ VK_FORMAT_D32_SFLOAT_S8_UINT
Definition: vulkan_core.h:1589