1
0
forked from mirrors/0ad
Files
0ad/source/renderer/backend/vulkan/PipelineState.h
T
2023-10-09 18:34:50 +00:00

97 lines
2.5 KiB
C++
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Copyright (C) 2023 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_RENDERER_BACKEND_VULKAN_PIPELINESTATE
#define INCLUDED_RENDERER_BACKEND_VULKAN_PIPELINESTATE
#include "renderer/backend/PipelineState.h"
#include "renderer/backend/vulkan/Framebuffer.h"
#include "renderer/backend/vulkan/ShaderProgram.h"
#include "renderer/backend/vulkan/DeviceObjectUID.h"
#include <cstdint>
#include <glad/vulkan.h>
#include <memory>
#include <unordered_map>
namespace Renderer
{
namespace Backend
{
namespace Vulkan
{
class CDevice;
class CFramebuffer;
class CGraphicsPipelineState final : public IGraphicsPipelineState
{
public:
~CGraphicsPipelineState() override;
IDevice* GetDevice() override;
IShaderProgram* GetShaderProgram() const override { return m_Desc.shaderProgram; }
const SGraphicsPipelineStateDesc& GetDesc() const { return m_Desc; }
VkPipeline GetOrCreatePipeline(
const CVertexInputLayout* vertexInputLayout, CFramebuffer* framebuffer);
DeviceObjectUID GetUID() const { return m_UID; }
private:
friend class CDevice;
static std::unique_ptr<CGraphicsPipelineState> Create(
CDevice* device, const SGraphicsPipelineStateDesc& desc);
CGraphicsPipelineState() = default;
CDevice* m_Device = nullptr;
DeviceObjectUID m_UID{INVALID_DEVICE_OBJECT_UID};
SGraphicsPipelineStateDesc m_Desc{};
struct CacheKey
{
DeviceObjectUID vertexInputLayoutUID;
// TODO: try to replace the UID by the only required parameters.
DeviceObjectUID framebufferUID;
};
struct CacheKeyHash
{
size_t operator()(const CacheKey& cacheKey) const;
};
struct CacheKeyEqual
{
bool operator()(const CacheKey& lhs, const CacheKey& rhs) const;
};
std::unordered_map<CacheKey, VkPipeline, CacheKeyHash, CacheKeyEqual> m_PipelineMap;
};
} // namespace Vulkan
} // namespace Backend
} // namespace Renderer
#endif // INCLUDED_RENDERER_BACKEND_VULKAN_PIPELINESTATE