Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement VMA usage and update APIs to reflect the simplification. #588

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5338005
Master Skywalker, there are too many of them! What are we going to do…
RubyNova Jul 2, 2023
c34b345
Merge branch 'main' into feature/rendering-abstraction-v2
RubyNova Jul 2, 2023
0031769
Why did ECS header revert? lol
RubyNova Jul 2, 2023
3c2ef34
[NOT COMPILING] Circular include hell here I am. :)
RubyNova Jul 5, 2023
578e7fc
fix: inline functions are no bueno
FiniteReality Jul 5, 2023
ee59d5b
Begin new Graphics surface for memory allocator.
RubyNova Jul 13, 2023
a72e936
Update GraphicsMemoryAllocator.hpp to have correct method signatures.
RubyNova Sep 17, 2023
4324d3a
Design basic API surface for new memory allocator code.
RubyNova Sep 17, 2023
38d2fe3
clang-format can't make its mind up.
RubyNova Sep 17, 2023
d41edd8
Design new createinfo-based APIs for graphics resources. Why is clang…
RubyNova Sep 17, 2023
ab3341e
Add missing file.
RubyNova Sep 17, 2023
16e357d
Update VulkanGraphicsMemoryAllocator header.
RubyNova Sep 17, 2023
a1559b1
Add MORE missing file changes.
RubyNova Sep 17, 2023
e00bcd4
Add basic template files for VulkanMemoryAllocator.
RubyNova Sep 17, 2023
3a2cacc
Begin adding buffer allocation code using VMA.
RubyNova Sep 18, 2023
f5703ce
VSCode please l2save.
RubyNova Sep 18, 2023
251a33d
Add placeholder headers. Move logic in memory allocator code to corre…
RubyNova Sep 19, 2023
072d511
Add missing include.
RubyNova Sep 19, 2023
47fb9a9
Add GraphicsResource APIs.
RubyNova Sep 23, 2023
343db91
Update GraphicsBuffer APIs to use new allocator APIs.
RubyNova Oct 1, 2023
72e23d6
Add support for VulkanGraphicsTexture.
RubyNova Oct 8, 2023
7e76246
Add the beginnings of cmdlist APIs. Add new memory region APIs.
RubyNova Dec 11, 2023
89ae289
This is a mess.
RubyNova May 27, 2024
5a545c1
part one of template update for rendering APIs.
RubyNova Jun 5, 2024
829c390
ALL of the templates.
RubyNova Jun 6, 2024
3b7f1aa
Add missing files.
RubyNova Jun 6, 2024
d5a39f7
[NOT COMPILING] Fix headers and some source files. TODO: Fix remainde…
RubyNova Jul 30, 2024
e39c6d8
Template-ification is basically all done now. Back to VMA work probably.
RubyNova Sep 25, 2024
523f592
[NOT WORKING] C++ compilers are the dumbest things I have ever encoun…
RubyNova Jan 15, 2025
e2fefe1
[NOT WORKING] apparently it builds on linux now???
FiniteReality Jan 15, 2025
8432083
[MAYBE WORKING?] compiler magic on linux
FiniteReality Jan 15, 2025
625aa94
delete additional files i forgot to delete
FiniteReality Jan 15, 2025
9961362
looks like the explicit instantiations weren't necessary; leaving the…
FiniteReality Jan 15, 2025
4cc1042
Remove missing CMakeLists files
FiniteReality Jan 16, 2025
fdc8073
Continue implementing new API changes.
RubyNova Jan 16, 2025
9426138
Minor Vulkan graphics fixes.
RubyNova Jan 20, 2025
35e953d
Time to bother Monica about the type traits stuff again.
RubyNova Jan 20, 2025
8081cf2
Checkpoint before GraphicsDescriptorSet redesign.
RubyNova Jan 24, 2025
6acedc9
Part one of CmdList integration. Fix compile error in spdlog on newer…
RubyNova Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add the beginnings of cmdlist APIs. Add new memory region APIs.
  • Loading branch information
RubyNova committed Dec 11, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 7e7624675ca9a12dadc8b32ef25eef18b132b75f
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ endif()
#
add_subdirectory(thirdparty)
add_subdirectory(resources)
add_subdirectory(graphics)
add_subdirectory(Graphics)
add_subdirectory(audio)
add_subdirectory(src)

9 changes: 9 additions & 0 deletions graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
add_library(NovelRT-Graphics STATIC
GraphicsBuffer.cpp
GraphicsCmdList.cpp
GraphicsDescriptorSet.cpp
GraphicsMemoryAllocator.cpp
GraphicsPipeline.cpp
GraphicsPipelineInput.cpp
GraphicsPipelineInputElement.cpp
GraphicsPipelineResource.cpp
GraphicsPipelineSignature.cpp
GraphicsResource.cpp
GraphicsResourceMemoryRegion.cpp
GraphicsTexture.cpp
ShaderProgram.cpp
Vulkan/VulkanGraphicsAdapter.cpp
@@ -20,6 +23,7 @@ add_library(NovelRT-Graphics STATIC
Vulkan/VulkanGraphicsPipelineSignature.cpp
Vulkan/VulkanGraphicsPluginProvider.cpp
Vulkan/VulkanGraphicsResource.cpp
Vulkan/VulkanGraphicsResourceMemoryRegion.cpp
Vulkan/VulkanGraphicsProvider.cpp
Vulkan/VulkanGraphicsSurfaceContext.cpp
Vulkan/VulkanGraphicsTexture.cpp
@@ -34,9 +38,12 @@ target_sources(NovelRT-Graphics
FILES
include/NovelRT/Graphics/GraphicsAdapter.hpp
include/NovelRT/Graphics/GraphicsBuffer.hpp
include/NovelRT/Graphics/GraphicsCmdList.hpp
include/NovelRT/Graphics/GraphicsBufferCreateInfo.hpp
include/NovelRT/Graphics/GraphicsBufferKind.hpp
include/NovelRT/Graphics/GraphicsCmdList.hpp
include/NovelRT/Graphics/GraphicsContext.hpp
include/NovelRT/Graphics/GraphicsDescriptorSet.hpp
include/NovelRT/Graphics/GraphicsDevice.hpp
include/NovelRT/Graphics/GraphicsDeviceObject.hpp
include/NovelRT/Graphics/GraphicsFence.hpp
@@ -52,6 +59,7 @@ target_sources(NovelRT-Graphics
include/NovelRT/Graphics/GraphicsPipelineSignature.hpp
include/NovelRT/Graphics/GraphicsProvider.hpp
include/NovelRT/Graphics/GraphicsResource.hpp
include/NovelRT/Graphics/GraphicsResourceMemoryRegion.hpp
include/NovelRT/Graphics/GraphicsResourceAccess.hpp
include/NovelRT/Graphics/GraphicsSurfaceContext.hpp
include/NovelRT/Graphics/GraphicsSurfaceKind.hpp
@@ -82,6 +90,7 @@ target_sources(NovelRT-Graphics
include/NovelRT/Graphics/Vulkan/VulkanGraphicsPluginProvider.hpp
include/NovelRT/Graphics/Vulkan/VulkanGraphicsProvider.hpp
include/NovelRT/Graphics/Vulkan/VulkanGraphicsResource.hpp
include/NovelRT/Graphics/Vulkan/VulkanGraphicsResourceMemoryRegion.hpp
include/NovelRT/Graphics/Vulkan/VulkanGraphicsSurfaceContext.hpp
include/NovelRT/Graphics/Vulkan/VulkanGraphicsTexture.hpp
include/NovelRT/Graphics/Vulkan/VulkanShaderProgram.hpp
17 changes: 17 additions & 0 deletions graphics/GraphicsCmdList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#include <NovelRT/Graphics/GraphicsCmdList.hpp>
#include <NovelRT/Graphics/GraphicsContext.hpp>

namespace NovelRT::Graphics
{
GraphicsCmdList::GraphicsCmdList(std::shared_ptr<GraphicsContext> context) noexcept : _context(context)
{
}

std::shared_ptr<GraphicsContext> GraphicsCmdList::GetContext() const noexcept
{
return _context;
}
}
26 changes: 26 additions & 0 deletions graphics/GraphicsDescriptorSet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#include <NovelRT/Graphics/GraphicsDescriptorSet.hpp>
#include <NovelRT/Graphics/GraphicsPipeline.hpp>
#include <NovelRT/Graphics/GraphicsPipelineSignature.hpp>

namespace NovelRT::Graphics
{
GraphicsDescriptorSet::GraphicsDescriptorSet(std::shared_ptr<GraphicsPipeline> targetPipeline) noexcept
: _pipeline(targetPipeline)
{
}

std::shared_ptr<GraphicsPipeline> GraphicsDescriptorSet::GetPipeline() const noexcept
{
return _pipeline;
}

void GraphicsDescriptorSet::AddBuffers(NovelRT::Utilities::Misc::Span<const std::shared_ptr<GraphicsBuffer>> buffers)
{
auto signature = GetPipeline()->GetSignature();

signature->GetInputs()
}
}
6 changes: 3 additions & 3 deletions graphics/GraphicsPipeline.cpp
Original file line number Diff line number Diff line change
@@ -5,11 +5,11 @@

namespace NovelRT::Graphics
{
GraphicsPipeline::GraphicsPipeline(const std::shared_ptr<GraphicsDevice>& device,
GraphicsPipeline::GraphicsPipeline(std::shared_ptr<GraphicsDevice> device,
std::shared_ptr<GraphicsPipelineSignature> signature,
std::shared_ptr<ShaderProgram> vertexShader,
std::shared_ptr<ShaderProgram> pixelShader) noexcept
: GraphicsDeviceObject(std::weak_ptr<GraphicsDevice>(device)),
: GraphicsDeviceObject(device),
_signature(signature),
_vertexShader(vertexShader),
_pixelShader(pixelShader)
@@ -40,4 +40,4 @@ namespace NovelRT::Graphics
{
return _signature;
}
} // namespace NovelRT::Graphics
}
14 changes: 12 additions & 2 deletions graphics/GraphicsPipelineSignature.cpp
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@

namespace NovelRT::Graphics
{

GraphicsPipelineSignature::GraphicsPipelineSignature(
std::shared_ptr<GraphicsDevice> device,
GraphicsPipelineBlendFactor srcBlendFactor,
@@ -26,10 +25,21 @@ namespace NovelRT::Graphics
{
return NovelRT::Utilities::Misc::Span<const GraphicsPipelineInput>(&(*_inputs.begin()), _inputs.size());
}

NovelRT::Utilities::Misc::Span<const GraphicsPipelineResource> GraphicsPipelineSignature::GetResources()
const noexcept
{
return NovelRT::Utilities::Misc::Span<const GraphicsPipelineResource>(&(*_resources.begin()),
_resources.size());
}
} // namespace NovelRT::Graphics

[[nodiscard]] inline GraphicsPipelineBlendFactor GraphicsPipelineSignature::GetSrcBlendFactor() const noexcept
{
return _srcBlendFactor;
}

[[nodiscard]] inline GraphicsPipelineBlendFactor GraphicsPipelineSignature::GetDstBlendFactor() const noexcept
{
return _dstBlendFactor;
}
}
2 changes: 1 addition & 1 deletion graphics/GraphicsResource.cpp
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

namespace NovelRT::Graphics
{
GraphicsResource::GraphicsResource(std::shared_ptr<GraphicsDevice> graphicsDevice, std::shared_ptr<GraphicsMemoryAllocator> allocator, GraphicsResourceAccess cpuAccess)
GraphicsResource::GraphicsResource(std::shared_ptr<GraphicsDevice> graphicsDevice, std::shared_ptr<GraphicsMemoryAllocator> allocator, GraphicsResourceAccess cpuAccess) noexcept
: GraphicsDeviceObject(graphicsDevice), _allocator(allocator), _cpuAccess(cpuAccess)
{
}
39 changes: 39 additions & 0 deletions graphics/GraphicsResourceMemoryRegion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#include <NovelRT/Graphics/GraphicsResource.hpp>
#include <NovelRT/Graphics/GraphicsResourceMemoryRegion.hpp>

namespace NovelRT::Graphics
{
GraphicsResourceMemoryRegion::GraphicsResourceMemoryRegion(std::shared_ptr<GraphicsDevice> graphicsDevice,
std::shared_ptr<GraphicsResource> owningResource)
: GraphicsDeviceObject(graphicsDevice), _owningResource(owningResource)
{
}

std::shared_ptr<GraphicsResource> GraphicsResourceMemoryRegion::GetOwningResource() const noexcept
{
return _owningResource;
}

Utilities::Misc::Span<uint8_t> GraphicsResourceMemoryRegion::MapBytes()
{
return _owningResource->MapBytes(GetRelativeOffset(), GetSize());
}

Utilities::Misc::Span<const uint8_t> GraphicsResourceMemoryRegion::MapBytesForRead()
{
return _owningResource->MapBytesForRead(GetRelativeOffset(), GetSize());
}

void GraphicsResourceMemoryRegion::UnmapBytes()
{
_owningResource->UnmapBytes();
}

void GraphicsResourceMemoryRegion::UnmapBytesAndWrite()
{
_owningResource->UnmapBytesAndWrite(GetRelativeOffset(), GetSize());
}
}
78 changes: 39 additions & 39 deletions graphics/Vulkan/VulkanGraphicsContext.cpp
Original file line number Diff line number Diff line change
@@ -177,45 +177,45 @@ namespace NovelRT::Graphics::Vulkan
}
}

void VulkanGraphicsContext::BeginCopy(VkImage vulkanImage) noexcept
{
VkImageSubresourceRange subresourceRange{};
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subresourceRange.levelCount = 1;
subresourceRange.layerCount = 1;

VkImageMemoryBarrier vulkanImageMemoryBarrier{};
vulkanImageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
vulkanImageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
vulkanImageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
vulkanImageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
vulkanImageMemoryBarrier.subresourceRange = subresourceRange;
vulkanImageMemoryBarrier.image = vulkanImage;

vkCmdPipelineBarrier(GetVulkanCommandBuffer(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0,
nullptr, 0, nullptr, 1, &vulkanImageMemoryBarrier);
}

void VulkanGraphicsContext::EndCopy(VkImage vulkanImage) noexcept
{
VkImageSubresourceRange subresourceRange{};
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subresourceRange.levelCount = 1;
subresourceRange.layerCount = 1;

VkImageMemoryBarrier vulkanImageMemoryBarrier{};
vulkanImageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
vulkanImageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
vulkanImageMemoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
vulkanImageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
vulkanImageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
vulkanImageMemoryBarrier.subresourceRange = subresourceRange;
vulkanImageMemoryBarrier.image = vulkanImage;

vkCmdPipelineBarrier(GetVulkanCommandBuffer(), VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1,
&vulkanImageMemoryBarrier);
}
//void VulkanGraphicsContext::BeginCopy(VkImage vulkanImage) noexcept
//{
//VkImageSubresourceRange subresourceRange{};
//subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
//subresourceRange.levelCount = 1;
//subresourceRange.layerCount = 1;

//VkImageMemoryBarrier vulkanImageMemoryBarrier{};
//vulkanImageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
//vulkanImageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
//vulkanImageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
//vulkanImageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
//vulkanImageMemoryBarrier.subresourceRange = subresourceRange;
//vulkanImageMemoryBarrier.image = vulkanImage;

//vkCmdPipelineBarrier(GetVulkanCommandBuffer(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0,
//nullptr, 0, nullptr, 1, &vulkanImageMemoryBarrier);
//}

//void VulkanGraphicsContext::EndCopy(VkImage vulkanImage) noexcept
//{
//VkImageSubresourceRange subresourceRange{};
//subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
//subresourceRange.levelCount = 1;
//subresourceRange.layerCount = 1;

//VkImageMemoryBarrier vulkanImageMemoryBarrier{};
//vulkanImageMemoryBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
//vulkanImageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
//vulkanImageMemoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
//vulkanImageMemoryBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
//vulkanImageMemoryBarrier.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
//vulkanImageMemoryBarrier.subresourceRange = subresourceRange;
//vulkanImageMemoryBarrier.image = vulkanImage;

//vkCmdPipelineBarrier(GetVulkanCommandBuffer(), VK_PIPELINE_STAGE_TRANSFER_BIT,
//VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1,
//&vulkanImageMemoryBarrier);
//}

VulkanGraphicsContext::VulkanGraphicsContext(std::shared_ptr<VulkanGraphicsDevice> device, size_t index) noexcept
: GraphicsContext(std::move(device), index),
2 changes: 1 addition & 1 deletion graphics/Vulkan/VulkanGraphicsFence.cpp
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ namespace NovelRT::Graphics::Vulkan
}

VulkanGraphicsFence::VulkanGraphicsFence(std::shared_ptr<VulkanGraphicsDevice> device, bool isSignaled) noexcept
: GraphicsFence(device->weak_from_this()),
: GraphicsFence(device),
_vulkanFence([=]() { return isSignaled ? CreateVulkanFenceSignaled() : CreateVulkanFenceUnsignaled(); }),
_state()
{
26 changes: 22 additions & 4 deletions graphics/Vulkan/VulkanGraphicsResource.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
// Copyright © Matt Jones and Contributors. Licensed under the MIT Licence (MIT). See LICENCE.md in the repository root
// for more information.

#include <NovelRT/Exceptions/InitialisationFailureException.h>
#include <NovelRT/Graphics/Vulkan/VulkanGraphicsDevice.hpp>
#include <NovelRT/Graphics/Vulkan/VulkanGraphicsMemoryAllocator.hpp>
#include <NovelRT/Graphics/Vulkan/VulkanGraphicsResource.hpp>
#include <string>

namespace NovelRT::Graphics::Vulkan
{
VulkanGraphicsResource::VulkanGraphicsResource(std::shared_ptr<VulkanGraphicsDevice> graphicsDevice,
std::shared_ptr<VulkanGraphicsMemoryAllocator> allocator,
GraphicsResourceAccess cpuAccess,
VmaAllocation allocation,
VmaAllocationInfo allocationInfo) noexcept
VmaAllocationInfo allocationInfo)
: GraphicsResource(graphicsDevice, allocator, cpuAccess),
_allocation(allocation),
_allocationInfo(allocationInfo)
_allocationInfo(allocationInfo),
_virtualBlock(VK_NULL_HANDLE)
{
VmaVirtualBlockCreateInfo createInfo{};
createInfo.size = GetSize();

VkResult result = vmaCreateVirtualBlock(&createInfo, &_virtualBlock);

if (result != VK_SUCCESS)
{
throw Exceptions::InitialisationFailureException("Failed to create virtual memory block for VkBuffer",
std::to_string(result));
}
}

std::shared_ptr<VulkanGraphicsMemoryAllocator> VulkanGraphicsResource::GetAllocator() const noexcept
@@ -38,13 +51,18 @@ namespace NovelRT::Graphics::Vulkan
return _allocationInfo.size;
}

const VmaAllocationInfo& VulkanGraphicsResource::GetAllocationInfo() const noexcept
std::shared_ptr<GraphicsResourceMemoryRegion> VulkanGraphicsResource::Allocate(size_t size, size_t alignment)
{
return _allocationInfo;

}

VmaAllocation VulkanGraphicsResource::GetAllocation() const noexcept
{
return _allocation;
}

const VmaAllocationInfo& VulkanGraphicsResource::GetAllocationInfo() const noexcept
{
return _allocationInfo;
}
}
Loading