blob: 06e052eedf879eb2a7a9fef6e366b8a0a1a5d674 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrTypes.h"
12#include "include/gpu/vk/GrVkTypes.h"
13#include "include/private/GrColor.h"
14#include "include/private/SkMacros.h"
Robert Phillips28a5a432019-06-07 12:46:21 -040015#include "src/gpu/GrDataUtils.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050016#include "src/gpu/vk/GrVkInterface.h"
17#include "src/sksl/ir/SkSLProgram.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050018
egdaniel88987d82016-09-19 10:17:34 -070019class GrVkGpu;
Greg Daniel164a9f02016-02-22 09:56:40 -050020
Greg Daniel164a9f02016-02-22 09:56:40 -050021// makes a Vk call on the interface
Brian Salomon23356442018-11-30 15:33:19 -050022#define GR_VK_CALL(IFACE, X) (IFACE)->fFunctions.f##X
Greg Daniel164a9f02016-02-22 09:56:40 -050023// same as GR_VK_CALL but checks for success
24#ifdef SK_DEBUG
Brian Salomon23356442018-11-30 15:33:19 -050025#define GR_VK_CALL_ERRCHECK(IFACE, X) \
Greg Daniel164a9f02016-02-22 09:56:40 -050026 VkResult SK_MACRO_APPEND_LINE(ret) = GR_VK_CALL(IFACE, X); \
Brian Salomon23356442018-11-30 15:33:19 -050027 SkASSERT(VK_SUCCESS == SK_MACRO_APPEND_LINE(ret))
Greg Daniel164a9f02016-02-22 09:56:40 -050028#else
Brian Salomon23356442018-11-30 15:33:19 -050029#define GR_VK_CALL_ERRCHECK(IFACE, X) (void) GR_VK_CALL(IFACE, X)
Greg Daniel164a9f02016-02-22 09:56:40 -050030#endif
31
32/**
33 * Returns the vulkan texture format for the given GrPixelConfig
34 */
35bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format);
36
Greg Daniel81b80592017-12-13 10:20:04 -050037bool GrVkFormatIsSupported(VkFormat);
38
Greg Daniel7e000222018-12-03 10:08:21 -050039#ifdef SK_DEBUG
Greg Daniel81b80592017-12-13 10:20:04 -050040/**
41 * Returns true if the passed in VkFormat and GrPixelConfig are compatible with each other.
42 */
43bool GrVkFormatPixelConfigPairIsValid(VkFormat, GrPixelConfig);
Greg Daniel7e000222018-12-03 10:08:21 -050044#endif
Greg Daniel81b80592017-12-13 10:20:04 -050045
Greg Daniel164a9f02016-02-22 09:56:40 -050046bool GrSampleCountToVkSampleCount(uint32_t samples, VkSampleCountFlagBits* vkSamples);
47
egdaniel88987d82016-09-19 10:17:34 -070048bool GrCompileVkShaderModule(const GrVkGpu* gpu,
Brian Osmanfd7657c2019-04-25 11:34:07 -040049 const SkSL::String& shaderString,
egdaniel88987d82016-09-19 10:17:34 -070050 VkShaderStageFlagBits stage,
51 VkShaderModule* shaderModule,
Ethan Nicholas941e7e22016-12-12 15:33:30 -050052 VkPipelineShaderStageCreateInfo* stageInfo,
53 const SkSL::Program::Settings& settings,
Ethan Nicholas92e01cf2018-12-19 13:12:10 -050054 SkSL::String* outSPIRV,
Ethan Nicholas941e7e22016-12-12 15:33:30 -050055 SkSL::Program::Inputs* outInputs);
egdaniel88987d82016-09-19 10:17:34 -070056
Ethan Nicholas92e01cf2018-12-19 13:12:10 -050057bool GrInstallVkShaderModule(const GrVkGpu* gpu,
58 const SkSL::String& spirv,
59 VkShaderStageFlagBits stage,
60 VkShaderModule* shaderModule,
61 VkPipelineShaderStageCreateInfo* stageInfo);
62
Robert Phillips1f098982019-05-15 10:27:36 -040063size_t GrVkBytesPerFormat(VkFormat);
64
65/**
66 * Returns true if the format is compressed.
67 */
68bool GrVkFormatIsCompressed(VkFormat);
69
70/**
71 * Returns the data size for the given compressed format
72 */
73size_t GrVkFormatCompressedDataSize(VkFormat, int width, int height);
74
Robert Phillips28a5a432019-06-07 12:46:21 -040075/**
76 * Maps a vk format into the GrCompressed enum.
77 */
78GrCompression GrVkFormat2Compression(VkFormat);
79
Greg Daniel164a9f02016-02-22 09:56:40 -050080#endif