// Copyright (c) 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:
GPUShaderProgramVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule)
: _device(device)
, ShaderModule(shaderModule)
, DescriptorInfo(descriptorInfo)
{
BaseType::Init(initializer);
}
~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:
GPUShaderProgramVSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule, GPUVertexLayout* inputLayout, GPUVertexLayout* vertexLayout)
: GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule)
{
InputLayout = inputLayout;
Layout = vertexLayout;
}
};
#if GPU_ALLOW_TESSELLATION_SHADERS
///
/// Hull Shader for Vulkan backend.
///
class GPUShaderProgramHSVulkan : public GPUShaderProgramVulkan
{
public:
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:
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:
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:
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:
GPUShaderProgramCSVulkan(GPUDeviceVulkan* device, const GPUShaderProgramInitializer& initializer, const SpirvShaderDescriptorInfo& descriptorInfo, VkShaderModule shaderModule)
: GPUShaderProgramVulkan(device, initializer, descriptorInfo, shaderModule)
, _pipelineState(nullptr)
{
}
~GPUShaderProgramCSVulkan();
public:
///
/// Gets the state of the pipeline for the compute shader execution or creates a new one if missing.
///
ComputePipelineStateVulkan* GetOrCreateState();
};
#endif