| /* |
| * Copyright 2022 Google LLC |
| * |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| |
| #include "include/gpu/graphite/vk/VulkanGraphiteUtils.h" |
| #include "src/gpu/graphite/vk/VulkanGraphiteUtilsPriv.h" |
| |
| #include "include/gpu/ShaderErrorHandler.h" |
| #include "include/gpu/graphite/Context.h" |
| #include "include/gpu/vk/VulkanBackendContext.h" |
| #include "src/core/SkTraceEvent.h" |
| #include "src/gpu/graphite/ContextPriv.h" |
| #include "src/gpu/graphite/vk/VulkanQueueManager.h" |
| #include "src/gpu/graphite/vk/VulkanSharedContext.h" |
| #include "src/sksl/SkSLProgramSettings.h" |
| |
| namespace skgpu::graphite::ContextFactory { |
| |
| std::unique_ptr<Context> MakeVulkan(const VulkanBackendContext& backendContext, |
| const ContextOptions& options) { |
| sk_sp<SharedContext> sharedContext = VulkanSharedContext::Make(backendContext, options); |
| if (!sharedContext) { |
| return nullptr; |
| } |
| |
| std::unique_ptr<QueueManager> queueManager(new VulkanQueueManager(backendContext.fQueue, |
| sharedContext.get())); |
| if (!queueManager) { |
| return nullptr; |
| } |
| |
| return ContextCtorAccessor::MakeContext(std::move(sharedContext), |
| std::move(queueManager), |
| options); |
| } |
| |
| } // namespace skgpu::graphite::ContextFactory |
| |
| namespace skgpu::graphite { |
| |
| VkShaderModule createVulkanShaderModule(const VulkanSharedContext* context, |
| const std::string& spirv, |
| VkShaderStageFlagBits stage) { |
| TRACE_EVENT0("skia.shaders", "InstallVkShaderModule"); |
| VkShaderModuleCreateInfo moduleCreateInfo; |
| memset(&moduleCreateInfo, 0, sizeof(VkShaderModuleCreateInfo)); |
| moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; |
| moduleCreateInfo.pNext = nullptr; |
| moduleCreateInfo.flags = 0; |
| moduleCreateInfo.codeSize = spirv.size(); |
| moduleCreateInfo.pCode = (const uint32_t*)spirv.c_str(); |
| |
| VkShaderModule shaderModule; |
| VkResult result; |
| VULKAN_CALL_RESULT(context->interface(), |
| result, |
| CreateShaderModule(context->device(), |
| &moduleCreateInfo, |
| /*const VkAllocationCallbacks*=*/nullptr, |
| &shaderModule)); |
| if (result != VK_SUCCESS) { |
| SKGPU_LOG_E("Failed to create VkShaderModule"); |
| return VK_NULL_HANDLE; |
| } |
| return shaderModule; |
| } |
| |
| } // namespace skgpu::graphite |