1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef VULKAN_GPU_PROGRAM_VK_H 17 #define VULKAN_GPU_PROGRAM_VK_H 18 19 #include <vulkan/vulkan_core.h> 20 21 #include <render/device/gpu_resource_desc.h> 22 #include <render/device/pipeline_layout_desc.h> 23 #include <render/namespace.h> 24 25 #include "device/gpu_program.h" 26 27 RENDER_BEGIN_NAMESPACE() 28 class ShaderModuleVk; 29 class Device; 30 31 struct GpuShaderProgramPlatformDataVk final { 32 // modules are not owned by the GpuShaderProgram 33 VkShaderModule vert { VK_NULL_HANDLE }; 34 VkShaderModule frag { VK_NULL_HANDLE }; 35 }; 36 37 class GpuShaderProgramVk final : public GpuShaderProgram { 38 public: 39 GpuShaderProgramVk(Device& aDevice, const GpuShaderProgramCreateData& aCreateData); 40 ~GpuShaderProgramVk() = default; 41 42 const GpuShaderProgramPlatformDataVk& GetPlatformData() const; 43 const ShaderReflection& GetReflection() const override; 44 45 private: 46 ShaderModuleVk* vertShaderModule_ { nullptr }; 47 ShaderModuleVk* fragShaderModule_ { nullptr }; 48 49 GpuShaderProgramPlatformDataVk plat_; 50 BASE_NS::vector<ShaderSpecialization::Constant> constants_; 51 52 ShaderReflection reflection_; 53 }; 54 55 struct GpuComputeProgramPlatformDataVk final { 56 // module is not owned by the GpuShaderProgram 57 VkShaderModule comp { VK_NULL_HANDLE }; 58 }; 59 60 class GpuComputeProgramVk final : public GpuComputeProgram { 61 public: 62 GpuComputeProgramVk(Device& aDevice, const GpuComputeProgramCreateData& aCreateData); 63 ~GpuComputeProgramVk() = default; 64 65 const GpuComputeProgramPlatformDataVk& GetPlatformData() const; 66 const ComputeShaderReflection& GetReflection() const override; 67 68 private: 69 ShaderModuleVk* shaderModule_ { nullptr }; 70 71 GpuComputeProgramPlatformDataVk plat_; 72 BASE_NS::vector<ShaderSpecialization::Constant> constants_; 73 ComputeShaderReflection reflection_; 74 }; 75 RENDER_END_NAMESPACE() 76 77 #endif // VULKAN_GPU_PROGRAM_VK_H 78