Skip to content

Commit

Permalink
Some work on binding set
Browse files Browse the repository at this point in the history
  • Loading branch information
Daethalus committed May 3, 2024
1 parent a02f2f0 commit 2140d2e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 70 deletions.
29 changes: 28 additions & 1 deletion Engine/Source/Fyrion/Graphics/Device/Vulkan/VulkanBindingSet.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
#include "VulkanBindingSet.hpp"

#include "Fyrion/Assets/AssetTypes.hpp"
#include "Fyrion/Resource/Repository.hpp"

namespace Fyrion
{
VulkanBindingSet::VulkanBindingSet(VulkanDevice& vulkanDevice, const RID& shader, BindingSetType bindingSetType) : vulkanDevice(vulkanDevice), shader(shader), bindingSetType(bindingSetType)
{
ResourceObject shaderAsset = Repository::Read(shader);
const ShaderInfo& shaderInfo = shaderAsset[ShaderAsset::Info].As<ShaderInfo>();

for(const DescriptorLayout& descriptorLayout: shaderInfo.descriptors)
{
auto setIt = descriptorLayoutLookup.Find(descriptorLayout.set);

if (setIt == descriptorLayoutLookup.end())
{
descriptorLayoutLookup.Insert(descriptorLayout.set, descriptorLayout);
}

for(const DescriptorBinding& binding: descriptorLayout.bindings)
{
if (auto it = valueDescriptorSetLookup.Find(binding.name); it == valueDescriptorSetLookup.end())
{
valueDescriptorSetLookup.Emplace(String{binding.name}, (u32)descriptorLayout.set);
}
}
}
}

void VulkanBindingValue::SetTexture(const Texture& texture)
{
if (texture != m_texture)
Expand Down Expand Up @@ -30,7 +57,7 @@ namespace Fyrion
auto it = bindingValues.Find(name);
if (it == bindingValues.end())
{
it = bindingValues.Emplace(String{name}, MakeUnique<VulkanBindingValue>()).first;
it = bindingValues.Emplace(String{name}, MakeShared<VulkanBindingValue>()).first;
}
return *it->second;
}
Expand Down
23 changes: 13 additions & 10 deletions Engine/Source/Fyrion/Graphics/Device/Vulkan/VulkanBindingSet.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#pragma once
#include "Fyrion/Core/HashMap.hpp"
#include "Fyrion/Core/UniquePtr.hpp"
#include "Fyrion/Core/SharedPtr.hpp"
#include "Fyrion/Graphics/GraphicsTypes.hpp"

namespace Fyrion
{
class VulkanDevice;

struct VulkanBindingValue : BindingValue
{
union
{
Texture m_texture;
Texture m_texture{};
TextureView m_textureView;
Sampler m_sampler;
Buffer m_buffer;
Expand All @@ -23,16 +25,17 @@ namespace Fyrion

struct VulkanBindingSet : BindingSet
{
RID shader;
BindingSetType bindingSetType;
VulkanDevice& vulkanDevice;
RID shader;
BindingSetType bindingSetType;

VulkanBindingSet(const RID& shader, BindingSetType bindingSetType)
: shader(shader),
bindingSetType(bindingSetType)
{
}
HashMap<String, SharedPtr<VulkanBindingValue>> bindingValues;
HashMap<String, u32> valueDescriptorSetLookup{};
HashMap<u32, DescriptorLayout> descriptorLayoutLookup{};


VulkanBindingSet(VulkanDevice& vulkanDevice, const RID& shader, BindingSetType bindingSetType);

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

BindingValue& GetBindingValue(const StringView& name) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ namespace Fyrion

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

void VulkanDevice::DestroySwapchain(const Swapchain& swapchain)
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Fyrion/Graphics/GraphicsTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ namespace Fyrion
TextureUsage usage{};
u32 mipLevels{1};
u32 arrayLayers{1};
ViewType defaultView{ViewType::Undefined};
ViewType defaultView{ViewType::Type2D};
};

struct TextureViewCreation
Expand Down
58 changes: 1 addition & 57 deletions Player/Source/Fyrion/EntryPoint.cpp
Original file line number Diff line number Diff line change
@@ -1,80 +1,24 @@

#include "Fyrion/Engine.hpp"
#include "Fyrion/Core/Sinks.hpp"
#include "Fyrion/Graphics/Graphics.hpp"
#include "Fyrion/Graphics/RenderGraph.hpp"
#include "Fyrion/Resource/Repository.hpp"
#include "Fyrion/Resource/ResourceAssets.hpp"

using namespace Fyrion;

PipelineState graphicsPipeline = {};
Buffer vertexBuffer = {};

void Draw(RenderCommands& renderCommands)
{
renderCommands.BindPipelineState(graphicsPipeline);
renderCommands.BindVertexBuffer(vertexBuffer);
renderCommands.Draw(3, 1, 0, 0);
}

void Shutdown()
{
Graphics::DestroyGraphicsPipelineState(graphicsPipeline);
Graphics::DestroyBuffer(vertexBuffer);
}

int main(i32 argc, char** argv)
{
StdOutSink stdOutSink{};
Logger::RegisterSink(stdOutSink);

Engine::Init(argc, argv);

Event::Bind<OnSwapchainRender, Draw>();
Event::Bind<OnShutdown, Shutdown>();

EngineContextCreation contextCreation{
.title = "Fyrion Engine",
.resolution = {1920, 1080},
.maximize = true,
.headless = false,
};
Engine::CreateContext(contextCreation);

ResourceAssets::LoadAssetsFromDirectory("SandboxTest", "C:\\dev\\FyrionEngine\\Projects\\SandboxTest\\Assets");

Format format = Format::BGRA;

GraphicsPipelineCreation graphicsPipelineCreation{
.shader = Repository::GetByPath("SandboxTest://TestRaster.raster"),
.attachments = &format
};

const Vec3 positions[3] = {
Vec3{0.0f, -0.5f, 0.0f},
Vec3{0.5, 0.5, 0.0},
Vec3{-0.5, 0.5, 0.0}
};

vertexBuffer = Graphics::CreateBuffer(BufferCreation{
.usage = BufferUsage::VertexBuffer,
.size = sizeof(positions),
.allocation = BufferAllocation::GPUOnly,
});

Graphics::UpdateBufferData(BufferDataInfo{
.buffer = vertexBuffer,
.data = &positions,
.size = sizeof(positions),
.offset = 0
});

graphicsPipeline = Graphics::CreateGraphicsPipelineState(graphicsPipelineCreation);

BindingSet& bindingSet = Graphics::CreateBindingSet(graphicsPipelineCreation.shader, BindingSetType::Dynamic);
bindingSet["buffer"] = vertexBuffer;

Engine::CreateContext(contextCreation);

Engine::Run();
Engine::Destroy();
Expand Down

0 comments on commit 2140d2e

Please sign in to comment.