Skip to content

Commit

Permalink
Rewriting to BackendAccessor pt 3
Browse files Browse the repository at this point in the history
  • Loading branch information
nekoffski committed Apr 25, 2024
1 parent 06faa46 commit 3a42e87
Show file tree
Hide file tree
Showing 28 changed files with 238 additions and 212 deletions.
2 changes: 2 additions & 0 deletions editor/ui/ResourcesPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ResourcesPanel.h"

#include <thread>

#include "starlight/resource/All.h"

template <typename Resource, typename Manager>
Expand Down
4 changes: 4 additions & 0 deletions editor/ui/ResourcesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "Core.h"
#include "Console.h"

#include "kc/async/TaskScheduler.hpp"

class ResourcesPanel {
public:
explicit ResourcesPanel(UIState* state, Logger* logger);
Expand All @@ -15,6 +17,8 @@ class ResourcesPanel {
UIState* m_state;
Logger* m_logger;

kc::async::TaskScheduler ts;

sl::ui::TabMenu m_resourcesTab;
sl::ui::Popup m_loadPopup;
};
6 changes: 4 additions & 2 deletions engine/src/starlight/renderer/gpu/vulkan/VKBackendAccessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#include "VKContext.h"
#include "VKLogicalDevice.h"
#include "VKPhysicalDevice.h"

namespace sl::vk {

struct VKBackendAccessor {
virtual VKContext* getContext() = 0;
virtual VKLogicalDevice* getLogicalDevice() = 0;
virtual VKContext* getContext() = 0;
virtual VKPhysicalDevice* getPhysicalDevice() = 0;
virtual VKLogicalDevice* getLogicalDevice() = 0;
};

} // namespace sl::vk
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class VKCommandBufferPool : public CommandBufferPool {

for (int i = 0; i < m_size; ++i) {
m_commandBuffers.emplace_back(
&m_device, m_device.getGraphicsCommandPool()
m_device, m_device.getGraphicsCommandPool()
);
}
}
Expand Down
14 changes: 14 additions & 0 deletions engine/src/starlight/renderer/gpu/vulkan/VKLogicalDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ VkCommandPool VKLogicalDevice::getGraphicsCommandPool() {
return m_graphicsCommandPool;
}

VKPhysicalDevice::SwapchainSupportInfo VKLogicalDevice::getSwapchainSupport() const {
return m_physicalDevice.getDeviceInfo().swapchainSupport;
}

VKPhysicalDevice::DeviceProperties VKLogicalDevice::getDeviceProperties() const {
return m_physicalDevice.getDeviceProperties();
}

bool VKLogicalDevice::supportsDeviceLocalHostVisibleMemory() const {
return m_physicalDevice.getDeviceInfo().supportsDeviceLocalHostVisibleMemory;
}

VkDevice VKLogicalDevice::getHandle() { return m_handle; }

std::optional<int32_t> VKLogicalDevice::findMemoryIndex(
Expand Down Expand Up @@ -86,6 +98,8 @@ void VKLogicalDevice::createLogicalDeviceInstance() {
queueCreateInfos.reserve(queueCount);

for (const auto index : indices) {
LOG_TRACE("Adding queue family index: {}", index);

queueProrities.push_back(1.0f);
VkDeviceQueueCreateInfo info;
info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
Expand Down
8 changes: 5 additions & 3 deletions engine/src/starlight/renderer/gpu/vulkan/VKLogicalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class VKLogicalDevice {
u8 getDepthChannelCount() const;
VkCommandPool getGraphicsCommandPool();

std::optional<int32_t> VKLogicalDevice::findMemoryIndex(
u32 typeFilter, u32 propertyFlags
) const;
VKPhysicalDevice::SwapchainSupportInfo getSwapchainSupport() const;
VKPhysicalDevice::DeviceProperties getDeviceProperties() const;
bool supportsDeviceLocalHostVisibleMemory() const;

std::optional<int32_t> findMemoryIndex(u32 typeFilter, u32 propertyFlags) const;

const VKPhysicalDevice::QueueIndices& getQueueIndices() const;

Expand Down
1 change: 0 additions & 1 deletion engine/src/starlight/renderer/gpu/vulkan/VKMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "VKPhysicalDevice.h"
#include "VKContext.h"
#include "VKBackendAccessor.h"
#include "VKDevice.h"
#include "VKBuffer.h"
#include "starlight/renderer/gpu/Mesh.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ std::optional<VKPhysicalDevice::DeviceInfo>
return {};
}
logQueueIndices(*queueIndices);
result.queueIndices = *queueIndices;

if (const auto swapchainSupport = queryDeviceSwapchainSupport(device);
swapchainSupport.formats.empty() || swapchainSupport.presentModes.empty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class Queue : uint16_t {
constexpr void enableBitOperations(Queue);

class VKPhysicalDevice {
public:
struct DeviceProperties {
static DeviceProperties fetch(VkPhysicalDevice device);

Expand All @@ -29,7 +30,6 @@ class VKPhysicalDevice {
VkPhysicalDeviceMemoryProperties memory;
};

public:
struct QueueIndices {
int32_t graphics = -1;
int32_t present = -1;
Expand Down
28 changes: 15 additions & 13 deletions engine/src/starlight/renderer/gpu/vulkan/VKPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#include "Vulkan.h"

#include "VKDevice.h"
#include "VKPhysicalDevice.h"
#include "VKContext.h"
#include "VKBackendAccessor.h"
#include "VKContext.h"
#include "VKCommandBuffer.h"
#include "VKRenderPass.h"
Expand Down Expand Up @@ -37,11 +39,10 @@ class VKPipeline {
};

explicit VKPipeline(
const VKContext* context, const VKDevice* device, VKRenderPass& renderPass,
Properties props
VKBackendAccessor& backendAccessor, VKRenderPass& renderPass, Properties props
) :
m_context(context),
m_device(device) {
m_context(*backendAccessor.getContext()),
m_device(*backendAccessor.getLogicalDevice()) {
VkPipelineViewportStateCreateInfo viewportState = {
VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO
};
Expand Down Expand Up @@ -234,8 +235,8 @@ class VKPipeline {
for (int i = 0; i < pipeline_layout_create_info.setLayoutCount; ++i) {
}

auto logicalDevice = device->getLogicalDevice();
auto allocator = context->getAllocator();
auto logicalDevice = m_device.getHandle();
auto allocator = m_context.getAllocator();

// Create the pipeline layout.
VK_ASSERT(vkCreatePipelineLayout(
Expand Down Expand Up @@ -274,12 +275,13 @@ class VKPipeline {
}

~VKPipeline() {
auto logicalDevice = m_device->getLogicalDevice();
auto allocator = m_context->getAllocator();
auto logicalDeviceHandle = m_device.getHandle();
auto allocator = m_context.getAllocator();

if (m_handle) vkDestroyPipeline(logicalDevice, m_handle, allocator);
if (m_handle) vkDestroyPipeline(logicalDeviceHandle, m_handle, allocator);

if (m_layout) vkDestroyPipelineLayout(logicalDevice, m_layout, allocator);
if (m_layout)
vkDestroyPipelineLayout(logicalDeviceHandle, m_layout, allocator);
}

void bind(VKCommandBuffer& commandBuffer, VkPipelineBindPoint bindPoint) {
Expand All @@ -289,8 +291,8 @@ class VKPipeline {
VkPipelineLayout getLayout() const { return m_layout; }

private:
const VKContext* m_context;
const VKDevice* m_device;
VKContext& m_context;
VKLogicalDevice& m_device;

VkPipeline m_handle = VK_NULL_HANDLE;
VkPipelineLayout m_layout;
Expand Down
16 changes: 7 additions & 9 deletions engine/src/starlight/renderer/gpu/vulkan/VKRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,36 +139,34 @@ struct RenderPassCreateInfo {
};

VKRenderPass::VKRenderPass(
u32 id, VKContext* context, VKDevice* device, const VKSwapchain& swapchain,
u32 id, VKBackendAccessor& backendAccessor, const VKSwapchain& swapchain,
const Properties& properties
) :
RenderPass(id, properties),
m_context(context), m_device(device) {
m_context(*backendAccessor.getContext()),
m_device(*backendAccessor.getLogicalDevice()) {
LOG_TRACE("Creating VKRenderPass instance");

RenderPassCreateInfo createInfo(
m_device->getDepthFormat(), swapchain.getSurfaceFormat(), properties
m_device.getDepthFormat(), swapchain.getSurfaceFormat(), properties
);

VK_ASSERT(vkCreateRenderPass(
m_device->getLogicalDevice(), &createInfo.handle, m_context->getAllocator(),
&m_handle
m_device.getHandle(), &createInfo.handle, m_context.getAllocator(), &m_handle
));

if (properties.targets.size() == 0)
LOG_WARN("Render pass with no render targets created");

for (auto& renderTarget : properties.targets) {
m_renderTargets.emplace_back(
id * 1000, *context, *device, this, renderTarget
);
m_renderTargets.emplace_back(id * 1000, backendAccessor, this, renderTarget);
}
}

VKRenderPass::~VKRenderPass() {
if (m_handle)
vkDestroyRenderPass(
m_device->getLogicalDevice(), m_handle, m_context->getAllocator()
m_device.getHandle(), m_handle, m_context.getAllocator()
);
}

Expand Down
9 changes: 6 additions & 3 deletions engine/src/starlight/renderer/gpu/vulkan/VKRenderPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "starlight/renderer/gpu/RenderPass.h"

#include "VKPhysicalDevice.h"
#include "VKContext.h"
#include "VKBackendAccessor.h"
#include "Vulkan.h"
#include "fwd.h"

Expand All @@ -23,7 +26,7 @@ class VKRenderPass : public RenderPass {
};

explicit VKRenderPass(
u32 id, VKContext* context, VKDevice* device, const VKSwapchain& swapchain,
u32 id, VKBackendAccessor& backendAccessor, const VKSwapchain& swapchain,
const Properties& properties
);

Expand All @@ -44,8 +47,8 @@ class VKRenderPass : public RenderPass {
const std::vector<VkClearValue>& clearValues, VkFramebuffer framebuffer
) const;

const VKContext* m_context;
const VKDevice* m_device;
VKContext& m_context;
VKLogicalDevice& m_device;

VkRenderPass m_handle;
float m_depth = 1.0f;
Expand Down
9 changes: 5 additions & 4 deletions engine/src/starlight/renderer/gpu/vulkan/VKRenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
namespace sl::vk {

VKRenderTarget::VKRenderTarget(
u32 id, VKContext& context, VKDevice& device, VKRenderPass* renderPass,
u32 id, VKBackendAccessor& backendAccessor, VKRenderPass* renderPass,
const Properties& props
) :
RenderTarget(id, props),
m_context(context), m_device(device), m_renderPass(renderPass) {
m_backendAccessor(backendAccessor), m_context(*backendAccessor.getContext()),
m_device(*backendAccessor.getLogicalDevice()), m_renderPass(renderPass) {
VKRenderTarget::regenerate(props);
}

Expand All @@ -31,8 +32,8 @@ void VKRenderTarget::regenerate(const Properties& properties) {
}

m_framebuffer.emplace(
&m_context, &m_device, m_renderPass->getHandle(), m_props.width,
m_props.height, attachmentViews
m_backendAccessor, m_renderPass->getHandle(), m_props.width, m_props.height,
attachmentViews
);
}

Expand Down
11 changes: 8 additions & 3 deletions engine/src/starlight/renderer/gpu/vulkan/VKRenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#include "starlight/renderer/gpu/RenderTarget.h"
#include "starlight/core/memory/Memory.hpp"

#include "VKDevice.h"
#include "VKPhysicalDevice.h"
#include "VKContext.h"
#include "VKBackendAccessor.h"

#include "VKContext.h"
#include "VKFramebuffer.h"

Expand All @@ -12,7 +15,7 @@ namespace sl::vk {
class VKRenderTarget : public RenderTarget {
public:
explicit VKRenderTarget(
u32 id, VKContext& context, VKDevice& device, VKRenderPass* renderPass,
u32 id, VKBackendAccessor& backendAccessor, VKRenderPass* renderPass,
const Properties& props
);

Expand All @@ -21,8 +24,10 @@ class VKRenderTarget : public RenderTarget {
void regenerate(const Properties& properties) override;

private:
VKBackendAccessor& m_backendAccessor;
VKContext& m_context;
VKDevice& m_device;
VKLogicalDevice& m_device;

VKRenderPass* m_renderPass;

LocalPtr<VKFramebuffer> m_framebuffer;
Expand Down
Loading

0 comments on commit 3a42e87

Please sign in to comment.