Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
VulkanGraphiteUtils.cpp
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
10
19
21
22std::unique_ptr<Context> MakeVulkan(const VulkanBackendContext& backendContext,
23 const ContextOptions& options) {
24 sk_sp<SharedContext> sharedContext = VulkanSharedContext::Make(backendContext, options);
25 if (!sharedContext) {
26 return nullptr;
27 }
28
29 std::unique_ptr<QueueManager> queueManager(new VulkanQueueManager(backendContext.fQueue,
30 sharedContext.get()));
31 if (!queueManager) {
32 return nullptr;
33 }
34
35 return ContextCtorAccessor::MakeContext(std::move(sharedContext),
36 std::move(queueManager),
37 options);
38}
39
40} // namespace skgpu::graphite::ContextFactory
41
42namespace skgpu::graphite {
43
44VkShaderModule createVulkanShaderModule(const VulkanSharedContext* context,
45 const std::string& spirv,
47 TRACE_EVENT0("skia.shaders", "InstallVkShaderModule");
48 VkShaderModuleCreateInfo moduleCreateInfo;
49 memset(&moduleCreateInfo, 0, sizeof(VkShaderModuleCreateInfo));
51 moduleCreateInfo.pNext = nullptr;
52 moduleCreateInfo.flags = 0;
53 moduleCreateInfo.codeSize = spirv.size();
54 moduleCreateInfo.pCode = (const uint32_t*)spirv.c_str();
55
56 VkShaderModule shaderModule;
58 VULKAN_CALL_RESULT(context,
59 result,
60 CreateShaderModule(context->device(),
61 &moduleCreateInfo,
62 /*const VkAllocationCallbacks*=*/nullptr,
63 &shaderModule));
64 if (result != VK_SUCCESS) {
65 SKGPU_LOG_E("Failed to create VkShaderModule");
66 return VK_NULL_HANDLE;
67 }
68 return shaderModule;
69}
70
72 const SkSpan<DescriptorData>& requestedDescriptors,
73 VkDescriptorSetLayout* outLayout) {
75 for (size_t i = 0; i < requestedDescriptors.size(); i++) {
76 if (requestedDescriptors[i].count != 0) {
77 const DescriptorData& currDescriptor = requestedDescriptors[i];
78 VkDescriptorSetLayoutBinding& layoutBinding = bindingLayouts.push_back();
79 memset(&layoutBinding, 0, sizeof(VkDescriptorSetLayoutBinding));
80 layoutBinding.binding = currDescriptor.bindingIndex;
81 layoutBinding.descriptorType = DsTypeEnumToVkDs(currDescriptor.type);
82 layoutBinding.descriptorCount = currDescriptor.count;
83 layoutBinding.stageFlags =
85 // TODO(b/302126498): Optionally set immutableSamplers here. Needed for YCbCr
86 layoutBinding.pImmutableSamplers = nullptr;
87 }
88 }
89
90 VkDescriptorSetLayoutCreateInfo layoutCreateInfo;
91 memset(&layoutCreateInfo, 0, sizeof(VkDescriptorSetLayoutCreateInfo));
93 layoutCreateInfo.pNext = nullptr;
94 layoutCreateInfo.flags = 0;
95 layoutCreateInfo.bindingCount = bindingLayouts.size();
96 layoutCreateInfo.pBindings = &bindingLayouts.front();
97
100 ctxt,
101 result,
102 CreateDescriptorSetLayout(ctxt->device(), &layoutCreateInfo, nullptr, outLayout));
103 if (result != VK_SUCCESS) {
104 SkDebugf("Failed to create VkDescriptorSetLayout\n");
105 outLayout = VK_NULL_HANDLE;
106 }
107}
108
126
159
162 VkShaderStageFlags vkStageFlags = 0;
163 if (stageFlags & PipelineStageFlags::kVertexShader) {
164 vkStageFlags |= VK_SHADER_STAGE_VERTEX_BIT;
165 }
166 if (stageFlags & PipelineStageFlags::kFragmentShader) {
167 vkStageFlags |= VK_SHADER_STAGE_FRAGMENT_BIT;
168 }
169 if (stageFlags & PipelineStageFlags::kCompute) {
170 vkStageFlags |= VK_SHADER_STAGE_COMPUTE_BIT;
171 }
172 return vkStageFlags;
173}
174
175} // namespace skgpu::graphite
const char * options
int count
#define SKGPU_LOG_E(fmt,...)
Definition Log.h:38
#define SkUNREACHABLE
Definition SkAssert.h:135
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
constexpr size_t size() const
Definition SkSpan_impl.h:95
T * get() const
Definition SkRefCnt.h:303
static std::unique_ptr< Context > MakeContext(sk_sp< SharedContext >, std::unique_ptr< QueueManager >, const ContextOptions &)
Definition Context.cpp:926
static sk_sp< SharedContext > Make(const VulkanBackendContext &, const ContextOptions &)
int size() const
Definition SkTArray.h:416
GAsyncResult * result
uint32_t uint32_t * format
SK_API std::unique_ptr< Context > MakeVulkan(const VulkanBackendContext &, const ContextOptions &)
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)
VkDescriptorType descriptorType
const VkSampler * pImmutableSamplers
VkShaderStageFlags stageFlags
const VkDescriptorSetLayoutBinding * pBindings
VkDescriptorSetLayoutCreateFlags flags
VkShaderModuleCreateFlags flags
const uint32_t * pCode
SkEnumBitMask< PipelineStageFlags > pipelineStageFlags
#define TRACE_EVENT0(category_group, name)
VkShaderStageFlagBits
@ VK_SHADER_STAGE_VERTEX_BIT
@ VK_SHADER_STAGE_COMPUTE_BIT
@ VK_SHADER_STAGE_FRAGMENT_BIT
VkFlags VkShaderStageFlags
VkResult
@ VK_SUCCESS
VkDescriptorType
@ VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE
@ VK_DESCRIPTOR_TYPE_SAMPLER
@ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
@ VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
@ VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT
@ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
VkFormat
@ VK_FORMAT_R16G16B16A16_UNORM
@ VK_FORMAT_R8G8B8A8_SRGB
@ VK_FORMAT_R8G8B8_UNORM
@ VK_FORMAT_D24_UNORM_S8_UINT
@ VK_FORMAT_B8G8R8A8_UNORM
@ VK_FORMAT_R16G16_SFLOAT
@ VK_FORMAT_B4G4R4A4_UNORM_PACK16
@ VK_FORMAT_R16_SFLOAT
@ VK_FORMAT_R8G8_UNORM
@ VK_FORMAT_S8_UINT
@ VK_FORMAT_R8_UNORM
@ VK_FORMAT_R5G6B5_UNORM_PACK16
@ VK_FORMAT_R4G4B4A4_UNORM_PACK16
@ VK_FORMAT_A2B10G10R10_UNORM_PACK32
@ VK_FORMAT_R8G8B8A8_UNORM
@ VK_FORMAT_BC1_RGB_UNORM_BLOCK
@ VK_FORMAT_R16_UNORM
@ VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM
@ VK_FORMAT_R16G16B16A16_SFLOAT
@ VK_FORMAT_R16G16_UNORM
@ VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK
@ VK_FORMAT_A2R10G10B10_UNORM_PACK32
@ VK_FORMAT_BC1_RGBA_UNORM_BLOCK
@ VK_FORMAT_G8_B8R8_2PLANE_420_UNORM
@ VK_FORMAT_D32_SFLOAT_S8_UINT
@ VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO
@ VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO