// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Graphics/Shaders/GPUShaderProgram.h" #include "IncludeVulkanHeaders.h" #include "Types.h" #if GRAPHICS_API_VULKAN class GPUDeviceVulkan; class ComputePipelineStateVulkan; /// /// Shaders base class for Vulkan backend. /// template class GPUShaderProgramVulkan : public BaseType { protected: GPUDeviceVulkan* _device; public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The program descriptors usage info. /// The shader module object. GPUShaderProgramVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule) : _device(device) , ShaderModule(shaderModule) , DescriptorInfo(descriptorInfo) { BaseType::Init(initializer); } /// /// Finalizes an instance of the class. /// ~GPUShaderProgramVulkan() { if (ShaderModule) { _device->DeferredDeletionQueue.EnqueueResource(DeferredDeletionQueueVulkan::ShaderModule, ShaderModule); } } public: /// /// The Vulkan shader module. /// VkShaderModule ShaderModule; /// /// The descriptor information container. /// SpirvShaderDescriptorInfo DescriptorInfo; public: // [BaseType] uint32 GetBufferSize() const override { return 0; } void* GetBufferHandle() const override { return (void*)ShaderModule; } }; /// /// Vertex Shader for Vulkan backend. /// class GPUShaderProgramVSVulkan : public GPUShaderProgramVulkan { public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The program descriptors usage info. /// The shader module object. GPUShaderProgramVSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule) : GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule) { } public: VkPipelineVertexInputStateCreateInfo VertexInputState; VkVertexInputBindingDescription VertexBindingDescriptions[VERTEX_SHADER_MAX_INPUT_ELEMENTS]; VkVertexInputAttributeDescription VertexAttributeDescriptions[VERTEX_SHADER_MAX_INPUT_ELEMENTS]; public: // [GPUShaderProgramVulkan] void* GetInputLayout() const override { return (void*)&VertexInputState; } byte GetInputLayoutSize() const override { return 0; } }; #if GPU_ALLOW_TESSELLATION_SHADERS /// /// Hull Shader for Vulkan backend. /// class GPUShaderProgramHSVulkan : public GPUShaderProgramVulkan { public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The program descriptors usage info. /// The shader module object. /// The control points used by the hull shader for processing. GPUShaderProgramHSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule, int32 controlPointsCount) : GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule) { _controlPointsCount = controlPointsCount; } }; /// /// Domain Shader for Vulkan backend. /// class GPUShaderProgramDSVulkan : public GPUShaderProgramVulkan { public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The program descriptors usage info. /// The shader module object. GPUShaderProgramDSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule) : GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule) { } }; #endif #if GPU_ALLOW_GEOMETRY_SHADERS /// /// Geometry Shader for Vulkan backend. /// class GPUShaderProgramGSVulkan : public GPUShaderProgramVulkan { public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The program descriptors usage info. /// The shader module object. GPUShaderProgramGSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule) : GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule) { } }; #endif /// /// Pixel Shader for Vulkan backend. /// class GPUShaderProgramPSVulkan : public GPUShaderProgramVulkan { public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The program descriptors usage info. /// The shader module object. GPUShaderProgramPSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule) : GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule) { } }; /// /// Compute Shader for Vulkan backend. /// class GPUShaderProgramCSVulkan : public GPUShaderProgramVulkan { private: ComputePipelineStateVulkan* _pipelineState; public: /// /// Initializes a new instance of the class. /// /// The graphics device. /// The program initialization data. /// The program descriptors usage info. /// The shader module object. GPUShaderProgramCSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule) : GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule) , _pipelineState(nullptr) { } /// /// Finalizes an instance of the class. /// ~GPUShaderProgramCSVulkan(); public: /// /// Gets the state of the pipeline for the compute shader execution or creates a new one if missing. /// /// The compute pipeline state. ComputePipelineStateVulkan* GetOrCreateState(); }; #endif