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" 12 #include "include/gpu/graphite/vk/VulkanGraphiteTypes.h" 13 #include "include/gpu/vk/VulkanTypes.h" 14 #include "src/gpu/graphite/DescriptorData.h" 15 #include "src/gpu/graphite/Log.h" 16 #include "src/gpu/vk/VulkanInterface.h" 17 18 #include <string> 19 20 class SkStream; 21 class SkWStream; 22 23 // Helper macros to call functions on the VulkanInterface without checking for errors. Note: This 24 // cannot require a VulkanSharedContext because driver calls are needed before the shared context 25 // has been initialized. 26 #define VULKAN_CALL(IFACE, X) (IFACE)->fFunctions.f##X 27 28 // Must be called before checkVkResult, since this does not log if the VulkanSharedContext is 29 // already considering the device to be lost. 30 #define VULKAN_LOG_IF_NOT_SUCCESS(SHARED_CONTEXT, RESULT, X, ...) \ 31 do { \ 32 if (RESULT != VK_SUCCESS && !(SHARED_CONTEXT)->isDeviceLost()) { \ 33 SkDebugf("Failed vulkan call. Error: %d, " X "\n", RESULT, ##__VA_ARGS__); \ 34 } \ 35 } while (false) 36 37 #define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X) \ 38 do { \ 39 (RESULT) = VULKAN_CALL((SHARED_CONTEXT)->interface(), X); \ 40 SkASSERT(VK_SUCCESS == RESULT || VK_ERROR_DEVICE_LOST == RESULT); \ 41 VULKAN_LOG_IF_NOT_SUCCESS(SHARED_CONTEXT, RESULT, #X); \ 42 (SHARED_CONTEXT)->checkVkResult(RESULT); \ 43 } while (false) 44 45 // same as VULKAN_CALL but checks for success 46 #define VULKAN_CALL_ERRCHECK(SHARED_CONTEXT, X) \ 47 VkResult SK_MACRO_APPEND_LINE(ret); \ 48 VULKAN_CALL_RESULT(SHARED_CONTEXT, SK_MACRO_APPEND_LINE(ret), X) 49 50 #define VULKAN_CALL_RESULT_NOCHECK(IFACE, RESULT, X) \ 51 do { \ 52 (RESULT) = VULKAN_CALL(IFACE, X); \ 53 } while (false) 54 namespace skgpu::graphite { 55 56 class VulkanSharedContext; 57 struct RenderPassDesc; 58 enum class TextureFormat : uint8_t; 59 60 VkShaderModule createVulkanShaderModule(const VulkanSharedContext*, 61 const std::string& spirv, 62 VkShaderStageFlagBits); 63 64 VkDescriptorType DsTypeEnumToVkDs(DescriptorType); 65 void DescriptorDataToVkDescSetLayout(const VulkanSharedContext*, 66 const SkSpan<DescriptorData>&, 67 VkDescriptorSetLayout*); 68 69 TextureFormat VkFormatToTextureFormat(VkFormat); 70 71 VkShaderStageFlags PipelineStageFlagsToVkShaderStageFlags(SkEnumBitMask<PipelineStageFlags>); 72 73 bool RenderPassDescWillLoadMSAAFromResolve(const RenderPassDesc& renderPassDesc); 74 75 namespace BackendTextures { 76 VkImage GetVkImage(const BackendTexture&); 77 VkImageLayout GetVkImageLayout(const BackendTexture&); 78 uint32_t GetVkQueueFamilyIndex(const BackendTexture&); 79 VulkanAlloc GetMemoryAlloc(const BackendTexture&); 80 81 void SetMutableState(BackendTexture*, const skgpu::MutableTextureState&); 82 sk_sp<skgpu::MutableTextureState> GetMutableState(const BackendTexture&); 83 } // namespace BackendTextures 84 85 } // namespace skgpu::graphite 86 87 #endif // skgpu_graphite_VulkanGraphiteUtilsPriv_DEFINED 88