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 "GrColor.h"
12 #include "GrTypes.h"
13 #include "vk/GrVkDefines.h"
14 #include "vk/GrVkInterface.h"
15 #include "ir/SkSLProgram.h"
16 
17 class GrVkGpu;
18 
19 // makes a Vk call on the interface
20 #define GR_VK_CALL(IFACE, X) (IFACE)->fFunctions.f##X;
21 // same as GR_VK_CALL but checks for success
22 #ifdef SK_DEBUG
23 #define GR_VK_CALL_ERRCHECK(IFACE, X) \
24     VkResult SK_MACRO_APPEND_LINE(ret) = GR_VK_CALL(IFACE, X); \
25     SkASSERT(VK_SUCCESS == SK_MACRO_APPEND_LINE(ret));
26 #else
27 #define GR_VK_CALL_ERRCHECK(IFACE, X)  (void) GR_VK_CALL(IFACE, X);
28 #endif
29 
30 /**
31  * Returns the vulkan texture format for the given GrPixelConfig
32  */
33 bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format);
34 
35 /**
36 * Returns the GrPixelConfig for the given vulkan texture format
37 */
38 GrPixelConfig GrVkFormatToPixelConfig(VkFormat format);
39 
40 bool GrVkFormatIsSupported(VkFormat);
41 
42 /**
43  * Returns true if the passed in VkFormat and GrPixelConfig are compatible with each other.
44  */
45 bool GrVkFormatPixelConfigPairIsValid(VkFormat, GrPixelConfig);
46 
47 /**
48  * Returns true if the given vulkan texture format is sRGB encoded.
49  * Also provides the non-sRGB version, if there is one.
50  */
51 bool GrVkFormatIsSRGB(VkFormat format, VkFormat* linearFormat);
52 
53 bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples);
54 
55 bool GrCompileVkShaderModule(const GrVkGpu* gpu,
56                              const char* shaderString,
57                              VkShaderStageFlagBits stage,
58                              VkShaderModule* shaderModule,
59                              VkPipelineShaderStageCreateInfo* stageInfo,
60                              const SkSL::Program::Settings& settings,
61                              SkSL::Program::Inputs* outInputs);
62 
63 #endif
64