Skip to content

Commit

Permalink
BindingSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Daethalus committed May 2, 2024
1 parent 02d1ec5 commit a02f2f0
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Engine/Source/Fyrion/Graphics/Device/RenderDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Fyrion
virtual Sampler CreateSampler(const SamplerCreation& samplerCreation) = 0;
virtual PipelineState CreateGraphicsPipelineState(const GraphicsPipelineCreation& graphicsPipelineCreation) = 0;
virtual PipelineState CreateComputePipelineState(const ComputePipelineCreation& computePipelineCreation) = 0;
virtual BindingSet& CreateBindingSet(RID shader) = 0;
virtual BindingSet& CreateBindingSet(RID shader, const BindingSetType& bindingSetType) = 0;
virtual void DestroySwapchain(const Swapchain& swapchain) = 0;
virtual void DestroyRenderPass(const RenderPass& renderPass) = 0;
virtual void DestroyBuffer(const Buffer& buffer) = 0;
Expand Down
31 changes: 31 additions & 0 deletions Engine/Source/Fyrion/Graphics/Device/Vulkan/VulkanBindingSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,36 @@

namespace Fyrion
{
void VulkanBindingValue::SetTexture(const Texture& texture)
{
if (texture != m_texture)
{
m_texture = texture;
}
}

void VulkanBindingValue::SetTextureView(const TextureView& textureView)
{
m_textureView = textureView;
}

void VulkanBindingValue::SetSampler(const Sampler& sampler)
{
m_sampler = sampler;
}

void VulkanBindingValue::SetBuffer(const Buffer& buffer)
{
m_buffer = buffer;
}

BindingValue& VulkanBindingSet::GetBindingValue(const StringView& name)
{
auto it = bindingValues.Find(name);
if (it == bindingValues.end())
{
it = bindingValues.Emplace(String{name}, MakeUnique<VulkanBindingValue>()).first;
}
return *it->second;
}
}
29 changes: 29 additions & 0 deletions Engine/Source/Fyrion/Graphics/Device/Vulkan/VulkanBindingSet.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
#pragma once
#include "Fyrion/Core/HashMap.hpp"
#include "Fyrion/Core/UniquePtr.hpp"
#include "Fyrion/Graphics/GraphicsTypes.hpp"

namespace Fyrion
{
struct VulkanBindingValue : BindingValue
{
union
{
Texture m_texture;
TextureView m_textureView;
Sampler m_sampler;
Buffer m_buffer;
};

void SetTexture(const Texture& texture) override;
void SetTextureView(const TextureView& textureView) override;
void SetSampler(const Sampler& sampler) override;
void SetBuffer(const Buffer& buffer) override;
};

struct VulkanBindingSet : BindingSet
{
RID shader;
BindingSetType bindingSetType;

VulkanBindingSet(const RID& shader, BindingSetType bindingSetType)
: shader(shader),
bindingSetType(bindingSetType)
{
}

HashMap<String, UniquePtr<VulkanBindingValue>> bindingValues{};

BindingValue& GetBindingValue(const StringView& name) override;
};
}
4 changes: 2 additions & 2 deletions Engine/Source/Fyrion/Graphics/Device/Vulkan/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,9 @@ namespace Fyrion
return {};
}

BindingSet& VulkanDevice::CreateBindingSet(RID shader)
BindingSet& VulkanDevice::CreateBindingSet(RID shader, const BindingSetType& bindingSetType)
{
return *allocator.Alloc<VulkanBindingSet>();
return *allocator.Alloc<VulkanBindingSet>(shader, bindingSetType);
}

void VulkanDevice::DestroySwapchain(const Swapchain& swapchain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace Fyrion
Sampler CreateSampler(const SamplerCreation& samplerCreation) override;
PipelineState CreateGraphicsPipelineState(const GraphicsPipelineCreation& graphicsPipelineCreation) override;
PipelineState CreateComputePipelineState(const ComputePipelineCreation& computePipelineCreation) override;
BindingSet& CreateBindingSet(RID shader) override;
BindingSet& CreateBindingSet(RID shader, const BindingSetType& bindingSetType) override;
void DestroySwapchain(const Swapchain& swapchain) override;
void DestroyRenderPass(const RenderPass& renderPass) override;
void DestroyBuffer(const Buffer& buffer) override;
Expand Down
4 changes: 2 additions & 2 deletions Engine/Source/Fyrion/Graphics/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ namespace Fyrion
return renderDevice->CreateComputePipelineState(computePipelineCreation);
}

BindingSet& Graphics::CreateBindingSet(RID shader)
BindingSet& Graphics::CreateBindingSet(RID shader, const BindingSetType& bindingSetType)
{
return renderDevice->CreateBindingSet(shader);
return renderDevice->CreateBindingSet(shader, bindingSetType);
}

void Graphics::DestroySwapchain(const Swapchain& swapchain)
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Fyrion/Graphics/Graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Fyrion::Graphics
FY_API Sampler CreateSampler(const SamplerCreation& samplerCreation);
FY_API PipelineState CreateGraphicsPipelineState(const GraphicsPipelineCreation& graphicsPipelineCreation);
FY_API PipelineState CreateComputePipelineState(const ComputePipelineCreation& computePipelineCreation);
FY_API BindingSet& CreateBindingSet(RID shader);
FY_API BindingSet& CreateBindingSet(RID shader, const BindingSetType& bindingSetType);
FY_API void DestroySwapchain(const Swapchain& swapchain);
FY_API void DestroyRenderPass(const RenderPass& renderPass);
FY_API void DestroyBuffer(const Buffer& buffer);
Expand Down
83 changes: 81 additions & 2 deletions Engine/Source/Fyrion/Graphics/GraphicsTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ namespace Fyrion
Linear
};

enum class BindingSetType
{
Dynamic,
Static
};

struct SwapchainCreation
{
Window window{};
Expand Down Expand Up @@ -447,9 +453,82 @@ namespace Fyrion
usize size;
};

struct BindingSet
struct BindingValue;


template<typename T>
struct BindingValueSetter
{
static void SetValue(BindingValue& bindingValue, const T& value)
{
static_assert(Traits::AlwaysFalse<T>, "Type not implemented");
}
};


struct FY_API BindingValue
{
virtual ~BindingValue() = default;

template<typename T>
BindingValue& operator=(const T& val)
{
BindingValueSetter<T>::SetValue(*this, val);
return *this;
}

virtual void SetTexture(const Texture& texture) = 0;
virtual void SetTextureView(const TextureView& textureView) = 0;
virtual void SetSampler(const Sampler& sampler) = 0;
virtual void SetBuffer(const Buffer& buffer) = 0;
};

struct FY_API BindingSet
{
virtual ~BindingSet() = default;

virtual BindingValue& GetBindingValue(const StringView& name) = 0;

BindingValue& operator[](const StringView& name)
{
return GetBindingValue(name);
}
};

template<>
struct BindingValueSetter<Texture>
{
//TODO
static void SetValue(BindingValue& bindingValue, const Texture& value)
{
bindingValue.SetTexture(value);
}
};

template<>
struct BindingValueSetter<TextureView>
{
static void SetValue(BindingValue& bindingValue, const TextureView& value)
{
bindingValue.SetTextureView(value);
}
};

template<>
struct BindingValueSetter<Sampler>
{
static void SetValue(BindingValue& bindingValue, const Sampler& value)
{
bindingValue.SetSampler(value);
}
};

template<>
struct BindingValueSetter<Buffer>
{
static void SetValue(BindingValue& bindingValue, const Buffer& value)
{
bindingValue.SetBuffer(value);
}
};

struct RenderCommands
Expand Down

0 comments on commit a02f2f0

Please sign in to comment.