Added Batcher classes and fixed errors
This commit is contained in:
parent
c1a3a6acf1
commit
1c8a434b26
|
@ -37,7 +37,9 @@ namespace Sandbox
|
||||||
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
|
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
|
||||||
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
SHADE::SHSystemManager::CreateSystem<SHADE::SHGraphicsSystem>();
|
||||||
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
|
||||||
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::SHGraphicsSystemRoutine>(1);
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::BeginRoutine>(1);
|
||||||
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::RenderRoutine>(1);
|
||||||
|
SHADE::SHSystemManager::RegisterRoutine<SHADE::SHGraphicsSystem, SHADE::SHGraphicsSystem::EndRoutine>(1);
|
||||||
|
|
||||||
|
|
||||||
graphicsSystem->SetWindow(&window);
|
graphicsSystem->SetWindow(&window);
|
||||||
|
|
|
@ -11,13 +11,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../SHECSMacros.h"
|
#include "../SHECSMacros.h"
|
||||||
|
#include "SH_API.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
|
||||||
class SHSystemManager;
|
class SHSystemManager;
|
||||||
|
|
||||||
class SHSystem
|
class SH_API SHSystem
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SystemID systemID;
|
SystemID systemID;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "SHRoutineStats.h"
|
#include "SHRoutineStats.h"
|
||||||
#include "SHSystem.h"
|
#include "SHSystem.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "SH_API.h"
|
||||||
|
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -15,7 +16,7 @@ namespace SHADE
|
||||||
class SHSystemManager;
|
class SHSystemManager;
|
||||||
|
|
||||||
|
|
||||||
class SHSystemRoutine
|
class SH_API SHSystemRoutine
|
||||||
{
|
{
|
||||||
friend class SHSystemManager;
|
friend class SHSystemManager;
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -43,8 +43,8 @@ namespace SHADE
|
||||||
imguiCommandPool = gfxSystem->GetDevice()->CreateCommandPool(SH_QUEUE_FAMILY_ARRAY_INDEX::GRAPHICS, SH_CMD_POOL_RESET::POOL_BASED, true);
|
imguiCommandPool = gfxSystem->GetDevice()->CreateCommandPool(SH_QUEUE_FAMILY_ARRAY_INDEX::GRAPHICS, SH_CMD_POOL_RESET::POOL_BASED, true);
|
||||||
imguiCommandBuffer = imguiCommandPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
imguiCommandBuffer = imguiCommandPool->RequestCommandBuffer(SH_CMD_BUFFER_TYPE::PRIMARY);
|
||||||
|
|
||||||
auto renderPass = gfxSystem->GetRenderGraph().GetNode("ImGui Node")->GetRenderpass();
|
/*auto renderPass = gfxSystem->GetRenderGraph().GetNode("ImGui Node")->GetRenderpass();
|
||||||
ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass());
|
ImGui_ImplVulkan_Init(&initInfo, renderPass->GetVkRenderpass());*/
|
||||||
|
|
||||||
imguiCommandBuffer->BeginRecording();
|
imguiCommandBuffer->BeginRecording();
|
||||||
ImGui_ImplVulkan_CreateFontsTexture(imguiCommandBuffer->GetVkCommandBuffer());
|
ImGui_ImplVulkan_CreateFontsTexture(imguiCommandBuffer->GetVkCommandBuffer());
|
||||||
|
@ -53,9 +53,9 @@ namespace SHADE
|
||||||
|
|
||||||
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
||||||
|
|
||||||
gfxSystem->GetRenderGraph().GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle<SHVkCommandBuffer>& cmd) {
|
/*gfxSystem->GetRenderGraph().GetNode("ImGui Node")->GetSubpass("ImGui Draw")->AddExteriorDrawCalls([](Handle<SHVkCommandBuffer>& cmd) {
|
||||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer());
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->GetVkCommandBuffer());
|
||||||
});
|
});*/
|
||||||
|
|
||||||
//ImGuiIO& io = ImGui::GetIO();
|
//ImGuiIO& io = ImGui::GetIO();
|
||||||
//int w, h;
|
//int w, h;
|
||||||
|
|
|
@ -33,8 +33,20 @@ namespace SHADE
|
||||||
};
|
};
|
||||||
cmdBufferHdl->GetVkCommandBuffer().copyBuffer(stagingBuffer, vkBuffer, 1, ©Region);
|
cmdBufferHdl->GetVkCommandBuffer().copyBuffer(stagingBuffer, vkBuffer, 1, ©Region);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Need to destroy staging buffer. Obviously not here but after the command has finished executing.
|
void SHVkBuffer::ResizeNoCopy(uint32_t newSize)
|
||||||
|
{
|
||||||
|
Destroy();
|
||||||
|
vk::Buffer tempBuffer;
|
||||||
|
std::tie(tempBuffer, std::ignore) = createBuffer(newSize);
|
||||||
|
vkBuffer = tempBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHVkBuffer::ResizeReplace(uint32_t newSize, void* data, uint32_t srcSize)
|
||||||
|
{
|
||||||
|
Destroy();
|
||||||
|
Init(newSize, data, srcSize, bufferUsageFlags, allocCreateInfo.usage, allocCreateInfo.flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::Buffer SHVkBuffer::GetVkBuffer(void) const noexcept
|
vk::Buffer SHVkBuffer::GetVkBuffer(void) const noexcept
|
||||||
|
@ -195,12 +207,12 @@ namespace SHADE
|
||||||
// results of allocation
|
// results of allocation
|
||||||
VmaAllocation stagingAlloc;
|
VmaAllocation stagingAlloc;
|
||||||
|
|
||||||
// To get around VMA's usage for C version of vulkan, create a temp first...,
|
// To get around VMA's usage for C version of Vulkan, create a temp first...,
|
||||||
VkBuffer tempBuffer{};
|
VkBuffer tempBuffer{};
|
||||||
|
|
||||||
// Create the buffer...
|
// Create the buffer...
|
||||||
vmaCreateBuffer(vmaAllocator,
|
vmaCreateBuffer(vmaAllocator,
|
||||||
&bufferInfo.operator VkBufferCreateInfo & (), // TODO: Verify if this works (can use renderdoc to check buffer variables?)
|
&bufferInfo.operator VkBufferCreateInfo & (), // TODO: Verify if this works (can use RenderDoc to check buffer variables?)
|
||||||
&allocCreateInfo,
|
&allocCreateInfo,
|
||||||
&tempBuffer, &stagingAlloc, &allocInfo);
|
&tempBuffer, &stagingAlloc, &allocInfo);
|
||||||
|
|
||||||
|
@ -221,6 +233,32 @@ namespace SHADE
|
||||||
vmaUnmapMemory(vmaAllocator, stagingAlloc);
|
vmaUnmapMemory(vmaAllocator, stagingAlloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<vk::Buffer, VmaAllocationInfo> SHVkBuffer::createBuffer(uint32_t size)
|
||||||
|
{
|
||||||
|
// Modify the size based on the parameter
|
||||||
|
sizeStored = size;
|
||||||
|
bufferCreateInfo.size = sizeStored;
|
||||||
|
|
||||||
|
// parameters of a vmaAllocation retrieved via vmaGetAllocationInfo
|
||||||
|
VmaAllocationInfo allocInfo;
|
||||||
|
|
||||||
|
// To get around VMA's usage for C version of vulkan, create a temp first...,
|
||||||
|
VkBuffer tempBuffer{};
|
||||||
|
|
||||||
|
// Create the buffer...
|
||||||
|
auto result = vmaCreateBuffer(vmaAllocator,
|
||||||
|
&bufferCreateInfo.operator VkBufferCreateInfo & (),
|
||||||
|
&allocCreateInfo,
|
||||||
|
&tempBuffer, &alloc, &allocInfo);
|
||||||
|
|
||||||
|
if (result != VK_SUCCESS)
|
||||||
|
SHVulkanDebugUtil::ReportVkError(vk::Result(result), "Failed to create vulkan buffer. ");
|
||||||
|
else
|
||||||
|
SHVulkanDebugUtil::ReportVkSuccess("Successfully created buffer. ");
|
||||||
|
|
||||||
|
return { tempBuffer, allocInfo };
|
||||||
|
}
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
|
@ -230,17 +268,15 @@ namespace SHADE
|
||||||
*/
|
*/
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
SHVkBuffer::SHVkBuffer(std::reference_wrapper<VmaAllocator const> allocator) noexcept
|
SHVkBuffer::SHVkBuffer(std::reference_wrapper<VmaAllocator const> allocator) noexcept
|
||||||
: vkBuffer{}
|
: vkBuffer{}
|
||||||
, stagingBuffer{}
|
, stagingBuffer{}
|
||||||
, sizeStored{ 0 }
|
, sizeStored{ 0 }
|
||||||
, mappedPtr{ nullptr }
|
, mappedPtr{ nullptr }
|
||||||
, alloc {nullptr}
|
, alloc {nullptr}
|
||||||
, randomAccessOptimized{false}
|
, randomAccessOptimized{false}
|
||||||
, boundToCoherent {false}
|
, boundToCoherent {false}
|
||||||
, vmaAllocator{allocator}
|
, vmaAllocator{allocator}
|
||||||
{
|
{}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
SHVkBuffer::SHVkBuffer(
|
SHVkBuffer::SHVkBuffer(
|
||||||
uint32_t inSize,
|
uint32_t inSize,
|
||||||
|
@ -266,6 +302,8 @@ namespace SHADE
|
||||||
, boundToCoherent{ rhs.boundToCoherent}
|
, boundToCoherent{ rhs.boundToCoherent}
|
||||||
, vmaAllocator{ rhs.vmaAllocator }
|
, vmaAllocator{ rhs.vmaAllocator }
|
||||||
, bufferUsageFlags {rhs.bufferUsageFlags}
|
, bufferUsageFlags {rhs.bufferUsageFlags}
|
||||||
|
, bufferCreateInfo { rhs.bufferCreateInfo }
|
||||||
|
, allocCreateInfo { rhs.allocCreateInfo }
|
||||||
|
|
||||||
{
|
{
|
||||||
rhs.vkBuffer = VK_NULL_HANDLE;
|
rhs.vkBuffer = VK_NULL_HANDLE;
|
||||||
|
@ -285,6 +323,8 @@ namespace SHADE
|
||||||
boundToCoherent = rhs.boundToCoherent;
|
boundToCoherent = rhs.boundToCoherent;
|
||||||
vmaAllocator = std::move (rhs.vmaAllocator);
|
vmaAllocator = std::move (rhs.vmaAllocator);
|
||||||
rhs.vkBuffer = VK_NULL_HANDLE;
|
rhs.vkBuffer = VK_NULL_HANDLE;
|
||||||
|
bufferCreateInfo = rhs.bufferCreateInfo;
|
||||||
|
allocCreateInfo = rhs.allocCreateInfo;
|
||||||
bufferUsageFlags = rhs.bufferUsageFlags;
|
bufferUsageFlags = rhs.bufferUsageFlags;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -344,47 +384,26 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
sizeStored = inSize;
|
sizeStored = inSize;
|
||||||
|
|
||||||
// For creation of buffer
|
// Set the buffer flags
|
||||||
vk::BufferCreateInfo bufferInfo{};
|
bufferUsageFlags = bufferUsage;
|
||||||
|
|
||||||
// initialize size and usage (vertex, index, uniform, etc)
|
// initialize size and usage (vertex, index, uniform, etc)
|
||||||
bufferInfo.size = sizeStored;
|
bufferCreateInfo = vk::BufferCreateInfo{};
|
||||||
bufferInfo.usage = bufferUsage;
|
bufferCreateInfo.usage = bufferUsageFlags;
|
||||||
bufferInfo.sharingMode = vk::SharingMode::eExclusive;
|
bufferCreateInfo.sharingMode = vk::SharingMode::eExclusive;
|
||||||
|
|
||||||
// Prepare allocation parameters for call to create buffers later
|
// Prepare allocation parameters for call to create buffers later
|
||||||
VmaAllocationCreateInfo allocCreateInfo{};
|
allocCreateInfo = VmaAllocationCreateInfo{};
|
||||||
allocCreateInfo.usage = memUsage;
|
allocCreateInfo.usage = memUsage;
|
||||||
|
|
||||||
// If vma allocation flags include dedicated bit, immediately activate dst bit
|
// If vma allocation flags include dedicated bit, immediately activate dst bit
|
||||||
if (allocCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT)
|
if (allocCreateInfo.flags & VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT)
|
||||||
bufferInfo.usage |= vk::BufferUsageFlagBits::eTransferDst;
|
bufferCreateInfo.usage |= vk::BufferUsageFlagBits::eTransferDst;
|
||||||
|
|
||||||
allocCreateInfo.flags = allocFlags;
|
allocCreateInfo.flags = allocFlags;
|
||||||
|
|
||||||
// parameters of a vmaAllocation retrieved via vmaGetAllocationInfo
|
auto [tempBuffer, allocInfo] = createBuffer(sizeStored);
|
||||||
VmaAllocationInfo allocInfo;
|
|
||||||
|
|
||||||
// To get around VMA's usage for C version of vulkan, create a temp first...,
|
|
||||||
VkBuffer tempBuffer{};
|
|
||||||
|
|
||||||
// Create the buffer...
|
|
||||||
auto result = vmaCreateBuffer(vmaAllocator,
|
|
||||||
&bufferInfo.operator VkBufferCreateInfo &(),
|
|
||||||
&allocCreateInfo,
|
|
||||||
&tempBuffer, &alloc, &allocInfo);
|
|
||||||
|
|
||||||
if (result != VK_SUCCESS)
|
|
||||||
SHVulkanDebugUtil::ReportVkError(vk::Result (result), "Failed to create vulkan buffer. ");
|
|
||||||
else
|
|
||||||
SHVulkanDebugUtil::ReportVkSuccess("Successfully created buffer. ");
|
|
||||||
|
|
||||||
// ...then assign it to the hpp version
|
|
||||||
vkBuffer = tempBuffer;
|
vkBuffer = tempBuffer;
|
||||||
|
|
||||||
// Set the buffer flags
|
|
||||||
bufferUsageFlags = bufferInfo.usage;
|
|
||||||
|
|
||||||
// This probably means that a HOST_CACHED memory type is used on allocation
|
// This probably means that a HOST_CACHED memory type is used on allocation
|
||||||
if (allocFlags & VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)
|
if (allocFlags & VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)
|
||||||
randomAccessOptimized = true;
|
randomAccessOptimized = true;
|
||||||
|
@ -456,7 +475,7 @@ namespace SHADE
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
void SHVkBuffer::Destroy(void) noexcept
|
void SHVkBuffer::Destroy(void) noexcept
|
||||||
{
|
{
|
||||||
vmaDestroyBuffer(vmaAllocator, vkBuffer, alloc);
|
if (vkBuffer)
|
||||||
|
vmaDestroyBuffer(vmaAllocator, vkBuffer, alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,13 +47,18 @@ namespace SHADE
|
||||||
//! buffer usage info flags
|
//! buffer usage info flags
|
||||||
vk::BufferUsageFlags bufferUsageFlags;
|
vk::BufferUsageFlags bufferUsageFlags;
|
||||||
|
|
||||||
|
vk::BufferCreateInfo bufferCreateInfo;
|
||||||
|
VmaAllocationCreateInfo allocCreateInfo;
|
||||||
|
|
||||||
//! Reference to the allocator
|
//! Reference to the allocator
|
||||||
|
//VmaAllocator const& vmaAllocator;
|
||||||
std::reference_wrapper<VmaAllocator const> vmaAllocator;
|
std::reference_wrapper<VmaAllocator const> vmaAllocator;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* PRIVATE MEMBER FUNCTIONS */
|
/* PRIVATE MEMBER FUNCTIONS */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
void PrepStagingBuffer (void* data, uint32_t srcSize) noexcept;
|
void PrepStagingBuffer (void* data, uint32_t srcSize) noexcept;
|
||||||
|
std::pair<vk::Buffer, VmaAllocationInfo> createBuffer(uint32_t size);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
@ -62,13 +67,13 @@ namespace SHADE
|
||||||
SHVkBuffer (void) noexcept = delete;
|
SHVkBuffer (void) noexcept = delete;
|
||||||
SHVkBuffer (std::reference_wrapper<VmaAllocator const> allocator) noexcept;
|
SHVkBuffer (std::reference_wrapper<VmaAllocator const> allocator) noexcept;
|
||||||
SHVkBuffer (
|
SHVkBuffer (
|
||||||
uint32_t inSize,
|
uint32_t inSize,
|
||||||
void* data,
|
void* data,
|
||||||
uint32_t srcSize,
|
uint32_t srcSize,
|
||||||
std::reference_wrapper<VmaAllocator const> allocator,
|
std::reference_wrapper<VmaAllocator const> allocator,
|
||||||
vk::BufferUsageFlags bufferUsage,
|
vk::BufferUsageFlags bufferUsage,
|
||||||
VmaMemoryUsage memUsage,
|
VmaMemoryUsage memUsage = VMA_MEMORY_USAGE_AUTO,
|
||||||
VmaAllocationCreateFlags allocFlags
|
VmaAllocationCreateFlags allocFlags = {}
|
||||||
) noexcept;
|
) noexcept;
|
||||||
SHVkBuffer(SHVkBuffer&& rhs) noexcept;
|
SHVkBuffer(SHVkBuffer&& rhs) noexcept;
|
||||||
SHVkBuffer& operator=(SHVkBuffer&& rhs) noexcept;
|
SHVkBuffer& operator=(SHVkBuffer&& rhs) noexcept;
|
||||||
|
@ -78,21 +83,23 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* PUBLIC MEMBER VARIABLES */
|
/* PUBLIC MEMBER VARIABLES */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
void Init (
|
void Init (
|
||||||
uint32_t inSize,
|
uint32_t inSize,
|
||||||
void* data,
|
void* data,
|
||||||
uint32_t srcSize,
|
uint32_t srcSize,
|
||||||
vk::BufferUsageFlags bufferUsage,
|
vk::BufferUsageFlags bufferUsage,
|
||||||
VmaMemoryUsage memUsage,
|
VmaMemoryUsage memUsage,
|
||||||
VmaAllocationCreateFlags allocFlags
|
VmaAllocationCreateFlags allocFlags
|
||||||
) noexcept;
|
) noexcept;
|
||||||
void Destroy (void) noexcept;
|
void Destroy (void) noexcept;
|
||||||
|
|
||||||
void Map (void) noexcept;
|
void Map (void) noexcept;
|
||||||
void Unmap (void) noexcept;
|
void Unmap (void) noexcept;
|
||||||
void WriteToMemory (void* data, uint32_t sizeToWrite, uint32_t srcOffset, uint32_t dstOffset) noexcept;
|
void WriteToMemory (void* data, uint32_t sizeToWrite, uint32_t srcOffset, uint32_t dstOffset) noexcept;
|
||||||
void MapWriteUnmap (void* data, uint32_t sizeToWrite, uint32_t srcOffset, uint32_t dstOffset) noexcept;
|
void MapWriteUnmap (void* data, uint32_t sizeToWrite, uint32_t srcOffset, uint32_t dstOffset) noexcept;
|
||||||
void TransferToDeviceResource(Handle<SHVkCommandBuffer> const& cmdBufferHdl) noexcept;
|
void TransferToDeviceResource(Handle<SHVkCommandBuffer> const& cmdBufferHdl) noexcept;
|
||||||
|
void ResizeNoCopy (uint32_t newSize);
|
||||||
|
void ResizeReplace (uint32_t newSize, void* data, uint32_t srcSize);
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* SETTERS AND GETTERS */
|
/* SETTERS AND GETTERS */
|
||||||
|
|
|
@ -451,6 +451,33 @@ namespace SHADE
|
||||||
// //vkCommandBuffer.pipelineBarrier()
|
// //vkCommandBuffer.pipelineBarrier()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
/*!
|
||||||
|
|
||||||
|
\brief
|
||||||
|
Issues a multi indirect draw call.
|
||||||
|
|
||||||
|
\param indirectDrawData
|
||||||
|
SHVkBuffer containing the data for the multi indirect draw call.
|
||||||
|
\param drawCount
|
||||||
|
Number of multi indirect draw sub-calls stored in indirectDrawData.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
|
void SHVkCommandBuffer::DrawMultiIndirect(Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount)
|
||||||
|
{
|
||||||
|
if (cmdBufferState != SH_CMD_BUFFER_STATE::RECORDING)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Command buffer must have started recording before a pipeline can be bound.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vkCommandBuffer.drawIndexedIndirect(indirectDrawData->GetVkBuffer(), 0, drawCount, sizeof(vk::DrawIndexedIndirectCommand));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************/
|
/***************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
void Reset(void);
|
void Reset(void);
|
||||||
|
|
||||||
// Begins, Ends and Nexts
|
// Begins and Ends
|
||||||
void BeginRecording (void) noexcept;
|
void BeginRecording (void) noexcept;
|
||||||
void EndRecording (void) noexcept;
|
void EndRecording (void) noexcept;
|
||||||
void BeginRenderpass (Handle<SHVkRenderpass> const& renderpassHdl, Handle<SHVkFramebuffer> const& framebufferHdl, vk::Offset2D offset = {0, 0}, vk::Extent2D extent = {0, 0}) noexcept;
|
void BeginRenderpass (Handle<SHVkRenderpass> const& renderpassHdl, Handle<SHVkFramebuffer> const& framebufferHdl, vk::Offset2D offset = {0, 0}, vk::Extent2D extent = {0, 0}) noexcept;
|
||||||
|
@ -127,6 +127,7 @@ namespace SHADE
|
||||||
|
|
||||||
bool IsReadyToSubmit (void) const noexcept;
|
bool IsReadyToSubmit (void) const noexcept;
|
||||||
void HandlePostSubmit (void) noexcept;
|
void HandlePostSubmit (void) noexcept;
|
||||||
|
void DrawMultiIndirect (Handle<SHVkBuffer> indirectDrawData, uint32_t drawCount);
|
||||||
|
|
||||||
// Push Constant variable setting
|
// Push Constant variable setting
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -0,0 +1,181 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHBatch.cpp
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Aug 30, 2022
|
||||||
|
\brief Contains the definition of SHBatch's functions.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHBatch.h"
|
||||||
|
|
||||||
|
#include "Graphics/Commands/SHVkCommandBuffer.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
|
||||||
|
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
||||||
|
#include "Graphics/SHVkUtil.h"
|
||||||
|
#include "Graphics/Pipeline/SHVkPipeline.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* SHBatch - Usage Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
SHBatch::SHBatch(Handle<SHVkPipeline> pipeline)
|
||||||
|
: pipeline { pipeline }
|
||||||
|
{
|
||||||
|
if (!pipeline)
|
||||||
|
throw std::invalid_argument("Attempted to create a SHBatch with an invalid SHPipeline!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatch::Add(Handle<SHRenderable> renderable)
|
||||||
|
{
|
||||||
|
// Check if we have a SubBatch with the same mesh yet
|
||||||
|
auto subBatch = std::find_if(subBatches.begin(), subBatches.end(), [&](const SHSubBatch& batch)
|
||||||
|
{
|
||||||
|
return batch.Mesh == renderable->Mesh;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create one if not found
|
||||||
|
if (subBatch == subBatches.end())
|
||||||
|
{
|
||||||
|
subBatches.emplace_back(renderable->Mesh);
|
||||||
|
subBatch = subBatches.end() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add renderable in
|
||||||
|
subBatch->Renderables.insert(renderable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatch::Remove(Handle<SHRenderable> renderable)
|
||||||
|
{
|
||||||
|
// Check if we have a SubBatch with the same mesh yet
|
||||||
|
auto subBatch = std::find_if(subBatches.begin(), subBatches.end(), [&](const SHSubBatch& batch)
|
||||||
|
{
|
||||||
|
return batch.Mesh == renderable->Mesh;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Attempt to remove if it exists
|
||||||
|
if (subBatch == subBatches.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
subBatch->Renderables.erase(renderable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatch::Clear()
|
||||||
|
{
|
||||||
|
subBatches.clear();
|
||||||
|
|
||||||
|
// Clear CPU buffers
|
||||||
|
drawData.clear();
|
||||||
|
transformData.clear();
|
||||||
|
matPropsData.reset();
|
||||||
|
matPropsDataSize = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Clear GPU buffers
|
||||||
|
drawDataBuffer.Free();
|
||||||
|
transformDataBuffer.Free();
|
||||||
|
matPropsBuffer.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatch::Build(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer)
|
||||||
|
{
|
||||||
|
// No need to build as there are no changes
|
||||||
|
if (!isDirty)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Count number of elements
|
||||||
|
size_t numTotalElements = 0;
|
||||||
|
for (const auto& subBatch : subBatches)
|
||||||
|
{
|
||||||
|
numTotalElements += subBatch.Renderables.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate CPU buffers
|
||||||
|
// - Draw data
|
||||||
|
drawData.reserve(subBatches.size());
|
||||||
|
drawData.clear();
|
||||||
|
// - Transform data
|
||||||
|
transformData.reserve(numTotalElements);
|
||||||
|
transformData.clear();
|
||||||
|
// - Material Properties Data
|
||||||
|
const Byte SINGLE_MAT_PROPS_SIZE = pipeline->GetPipelineLayout()->GetShaderBlockInterface
|
||||||
|
(
|
||||||
|
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
||||||
|
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||||
|
vk::ShaderStageFlagBits::eFragment
|
||||||
|
)->GetBytesRequired();
|
||||||
|
const Byte MATPROPS_TOTAL_BYTES = drawData.size() * SINGLE_MAT_PROPS_SIZE;
|
||||||
|
if (matPropsDataSize < MATPROPS_TOTAL_BYTES)
|
||||||
|
{
|
||||||
|
matPropsData.reset(new char[MATPROPS_TOTAL_BYTES]);
|
||||||
|
matPropsDataSize = MATPROPS_TOTAL_BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build Sub Batches
|
||||||
|
uint32_t nextInstanceIndex = 0;
|
||||||
|
char* propsCurrPtr = matPropsData.get();
|
||||||
|
for (auto& subBatch : subBatches)
|
||||||
|
{
|
||||||
|
// Create command
|
||||||
|
drawData.emplace_back(vk::DrawIndexedIndirectCommand
|
||||||
|
{
|
||||||
|
.indexCount = subBatch.Mesh->IndexCount,
|
||||||
|
.instanceCount = static_cast<uint32_t>(subBatch.Renderables.size()),
|
||||||
|
.firstIndex = subBatch.Mesh->FirstIndex,
|
||||||
|
.vertexOffset = subBatch.Mesh->FirstVertex,
|
||||||
|
.firstInstance = nextInstanceIndex
|
||||||
|
});
|
||||||
|
|
||||||
|
// Fill in buffers (CPU)
|
||||||
|
for (Handle<SHRenderable> renderable : subBatch.Renderables)
|
||||||
|
{
|
||||||
|
// Transform
|
||||||
|
transformData.emplace_back(renderable->TransformMatrix);
|
||||||
|
// Material Properties
|
||||||
|
renderable->GetMaterial()->ExportProperties(propsCurrPtr);
|
||||||
|
propsCurrPtr += SINGLE_MAT_PROPS_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send all buffered data to the GPU buffers
|
||||||
|
using BuffUsage = vk::BufferUsageFlagBits;
|
||||||
|
// - Draw Data
|
||||||
|
const uint32_t DRAW_DATA_BYTES = static_cast<uint32_t>(drawData.size() * sizeof(vk::DrawIndexedIndirectCommand));
|
||||||
|
SHVkUtil::EnsureBufferAndCopyData
|
||||||
|
(
|
||||||
|
device, cmdBuffer, drawDataBuffer, drawData.data(), DRAW_DATA_BYTES,
|
||||||
|
BuffUsage::eIndirectBuffer
|
||||||
|
);
|
||||||
|
// - Transform Buffer
|
||||||
|
const uint32_t TF_DATA_BYTES = static_cast<uint32_t>(transformData.size() * sizeof(SHMatrix));
|
||||||
|
SHVkUtil::EnsureBufferAndCopyData
|
||||||
|
(
|
||||||
|
device, cmdBuffer, transformDataBuffer, transformData.data(), TF_DATA_BYTES,
|
||||||
|
BuffUsage::eVertexBuffer
|
||||||
|
);
|
||||||
|
// - Material Properties Buffer
|
||||||
|
SHVkUtil::EnsureBufferAndCopyData
|
||||||
|
(
|
||||||
|
device, cmdBuffer, matPropsBuffer, matPropsData.get(), static_cast<uint32_t>(MATPROPS_TOTAL_BYTES),
|
||||||
|
BuffUsage::eStorageBuffer
|
||||||
|
);
|
||||||
|
|
||||||
|
isDirty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* SHBatch - Usage Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void SHBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer)
|
||||||
|
{
|
||||||
|
cmdBuffer->DrawMultiIndirect(drawDataBuffer, static_cast<uint32_t>(drawData.size()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHBatch.h
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Aug 30, 2022
|
||||||
|
\brief Contains the definition of SHSubBatch and SHBatch.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// STL Includes
|
||||||
|
#include <unordered_set>
|
||||||
|
// External Dependencies
|
||||||
|
#include "Graphics/SHVulkanIncludes.h"
|
||||||
|
// Project Includes
|
||||||
|
#include "Resource/Handle.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHMaterial.h"
|
||||||
|
#include "Math/SHMatrix.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Forward Declarations */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
class SHVkBuffer;
|
||||||
|
class SHVkCommandBuffer;
|
||||||
|
class SHVkPipeline;
|
||||||
|
class SHMesh;
|
||||||
|
class SHRenderable;
|
||||||
|
class SHVkLogicalDevice;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
Describes a segment of the sub batch operation.
|
||||||
|
*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
struct SHSubBatch
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Handle<SHMesh> Mesh;
|
||||||
|
std::unordered_set<Handle<SHRenderable>> Renderables;
|
||||||
|
};
|
||||||
|
/***********************************************************************************/
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
Describes a segment of the sub batch operation.
|
||||||
|
*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
class SHBatch
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructor/Destructors */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
SHBatch(Handle<SHVkPipeline> pipeline);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
void Add(Handle<SHRenderable> renderable);
|
||||||
|
void Remove(Handle<SHRenderable> renderable);
|
||||||
|
void Clear();
|
||||||
|
void Build(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer);
|
||||||
|
void Draw(Handle<SHVkCommandBuffer> cmdBuffer);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Getter Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Handle<SHVkPipeline> GetPipeline() const noexcept { return pipeline; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
// Batch Properties
|
||||||
|
Handle<SHVkPipeline> pipeline;
|
||||||
|
// Batch Tree
|
||||||
|
std::vector<SHSubBatch> subBatches;
|
||||||
|
bool isDirty = true;
|
||||||
|
// CPU Buffers
|
||||||
|
std::vector<vk::DrawIndexedIndirectCommand> drawData;
|
||||||
|
std::vector<SHMatrix> transformData;
|
||||||
|
std::unique_ptr<char> matPropsData;
|
||||||
|
Byte matPropsDataSize = 0;
|
||||||
|
// GPU Buffers
|
||||||
|
Handle<SHVkBuffer> drawDataBuffer;
|
||||||
|
Handle<SHVkBuffer> transformDataBuffer;
|
||||||
|
Handle<SHVkBuffer> matPropsBuffer;
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,107 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHBatcher.cpp
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Aug 30, 2022
|
||||||
|
\brief
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHBatcher.h"
|
||||||
|
// STL Includes
|
||||||
|
#include <vector>
|
||||||
|
// Project Includes
|
||||||
|
#include "SHSuperBatch.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
|
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
||||||
|
#include "Graphics/Commands/SHVkCommandBuffer.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||||
|
#include "Graphics/Pipeline/SHVkPipeline.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Lifecycle Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void SHBatcher::Init(const std::vector<SHRenderable>& _renderables, Handle<SHRenderGraph> _renderGraph)
|
||||||
|
{
|
||||||
|
renderables = &_renderables;
|
||||||
|
renderGraph = _renderGraph;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void SHBatcher::PrepareBatches()
|
||||||
|
{
|
||||||
|
// Iterate through all renderables and send it into the batching
|
||||||
|
for (auto iter = renderables->cbegin(); iter != renderables->cend(); ++iter)
|
||||||
|
{
|
||||||
|
AddToBatch(iter->GetHandle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatcher::AddToBatch(Handle<SHRenderable> renderable)
|
||||||
|
{
|
||||||
|
// Get Subpass Index for this renderables pipeline
|
||||||
|
const SHSubPassIndex SUB_PASS_IDX = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpassIndex();
|
||||||
|
|
||||||
|
|
||||||
|
// Check if there is a SuperBatch for the specific RenderPass
|
||||||
|
auto superBatch = std::find_if(superBatches.begin(), superBatches.end(), [&](const SHSuperBatch& superBatch)
|
||||||
|
{
|
||||||
|
return superBatch.GetSubpassId() == SUB_PASS_IDX;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create if it doesn't exist
|
||||||
|
if (superBatch == superBatches.end())
|
||||||
|
{
|
||||||
|
superBatches.emplace_back(SUB_PASS_IDX);
|
||||||
|
superBatch = superBatches.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the Renderable
|
||||||
|
superBatch->Add(renderable->GetHandle());
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatcher::RemoveFromBatch(Handle<SHRenderable> renderable)
|
||||||
|
{
|
||||||
|
// Get Subpass Index for this renderables pipeline
|
||||||
|
const SHSubPassIndex SUB_PASS_IDX = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpassIndex();
|
||||||
|
|
||||||
|
// Check if there is a SuperBatch for the specific RenderPass
|
||||||
|
auto superBatch = std::find_if(superBatches.begin(), superBatches.end(), [&](const SHSuperBatch& superBatch)
|
||||||
|
{
|
||||||
|
return superBatch.GetSubpassId() == SUB_PASS_IDX;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Remove if it exists
|
||||||
|
if (superBatch == superBatches.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
superBatch->Remove(renderable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatcher::FinaliseBatches(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer)
|
||||||
|
{
|
||||||
|
// Build SuperBatches
|
||||||
|
for (auto& batch : superBatches)
|
||||||
|
{
|
||||||
|
batch.Build(device, cmdBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHBatcher::ClearBatches()
|
||||||
|
{
|
||||||
|
for (auto& batch : superBatches)
|
||||||
|
{
|
||||||
|
batch.Clear();
|
||||||
|
}
|
||||||
|
superBatches.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHBatcher.h
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Aug 30, 2022
|
||||||
|
\brief
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// STL Includes
|
||||||
|
#include <vector>
|
||||||
|
// Project Includes
|
||||||
|
#include "Resource/Handle.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Forward Declarations */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
class SHRenderable;
|
||||||
|
class SHRenderGraph;
|
||||||
|
class SHSuperBatch;
|
||||||
|
class SHVkLogicalDevice;
|
||||||
|
class SHVkCommandBuffer;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
Handles batching of all Renderables assigned to a specific Renderer.
|
||||||
|
*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
class SHBatcher
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Lifecycle Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
void Init(const std::vector<SHRenderable>& _renderables, Handle<SHRenderGraph> _renderGraph);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
void PrepareBatches();
|
||||||
|
void AddToBatch(Handle<SHRenderable> renderable);
|
||||||
|
void RemoveFromBatch(Handle<SHRenderable> renderable);
|
||||||
|
void FinaliseBatches(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer);
|
||||||
|
void ClearBatches();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::vector<SHRenderable>* renderables = nullptr;
|
||||||
|
Handle<SHRenderGraph> renderGraph;
|
||||||
|
// Children
|
||||||
|
std::vector<SHSuperBatch> superBatches;
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHSuperBatch.cpp
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Sep 8, 2022
|
||||||
|
\brief Contains the definition of SHSuperBatch's functions.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#include "SHpch.h"
|
||||||
|
#include "SHSuperBatch.h"
|
||||||
|
|
||||||
|
#include "SHBatch.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
|
||||||
|
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Constructor/Destructors */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
SHSuperBatch::SHSuperBatch(SHSubPassIndex subPass)
|
||||||
|
: subpassIndex { subPass }
|
||||||
|
{}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
void SHSuperBatch::Add(Handle<SHRenderable> renderable) noexcept
|
||||||
|
{
|
||||||
|
const Handle<SHVkPipeline> PIPELINE = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline();
|
||||||
|
|
||||||
|
// Check if we have a batch with the same pipeline first
|
||||||
|
auto batch = std::find_if(batches.begin(), batches.end(), [&](const SHBatch& batch)
|
||||||
|
{
|
||||||
|
return batch.GetPipeline() == PIPELINE;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Create one if not found
|
||||||
|
if (batch == batches.end())
|
||||||
|
{
|
||||||
|
batches.emplace_back(PIPELINE);
|
||||||
|
batch = batches.end() - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add renderable in
|
||||||
|
batch->Add(renderable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHSuperBatch::Remove(Handle<SHRenderable> renderable) noexcept
|
||||||
|
{
|
||||||
|
const Handle<SHVkPipeline> PIPELINE = renderable->GetMaterial()->GetBaseMaterial()->GetPipeline();
|
||||||
|
|
||||||
|
// Check if we have a Batch with the same pipeline yet
|
||||||
|
auto batch = std::find_if(batches.begin(), batches.end(), [&](const SHBatch& batch)
|
||||||
|
{
|
||||||
|
return batch.GetPipeline() == PIPELINE;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Attempt to remove if it exists
|
||||||
|
if (batch == batches.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
batch->Remove(renderable);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHSuperBatch::Clear() noexcept
|
||||||
|
{
|
||||||
|
for (auto& batch : batches)
|
||||||
|
{
|
||||||
|
batch.Clear();
|
||||||
|
}
|
||||||
|
batches.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHSuperBatch::Build(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer) noexcept
|
||||||
|
{
|
||||||
|
// Build all batches
|
||||||
|
for (auto& batch : batches)
|
||||||
|
{
|
||||||
|
batch.Build(device, cmdBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHSuperBatch::Draw(Handle<SHVkCommandBuffer> cmdBuffer) noexcept
|
||||||
|
{
|
||||||
|
// Build all batches
|
||||||
|
for (auto& batch : batches)
|
||||||
|
{
|
||||||
|
batch.Draw(cmdBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
/************************************************************************************//*!
|
||||||
|
\file SHSuperBatch.h
|
||||||
|
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||||
|
\par email: kahwei.tng\@digipen.edu
|
||||||
|
\date Sep 8, 2022
|
||||||
|
\brief Contains the definition of SHSuperBatch.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||||
|
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||||
|
of DigiPen Institute of Technology is prohibited.
|
||||||
|
*//*************************************************************************************/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// External Dependencies
|
||||||
|
#include "Graphics/SHVulkanIncludes.h"
|
||||||
|
// Project Includes
|
||||||
|
#include "Resource/Handle.h"
|
||||||
|
#include "SHBatch.h"
|
||||||
|
#include "Graphics/Pipeline/SHVkPipeline.h"
|
||||||
|
|
||||||
|
namespace SHADE
|
||||||
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Forward Declarations */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
class SHVkBuffer;
|
||||||
|
class SHVkCommandBuffer;
|
||||||
|
class SHMesh;
|
||||||
|
class SHRenderable;
|
||||||
|
class SHVkLogicalDevice;
|
||||||
|
class SHSubpass;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
/*!
|
||||||
|
\brief
|
||||||
|
Stores and manages data for all of the batches associated with a specific SubPass
|
||||||
|
within a RenderGraph.
|
||||||
|
*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
class SHSuperBatch
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Constructor/Destructors */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
SHSuperBatch(SHSubPassIndex subPass);
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Usage Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
void Add(Handle<SHRenderable> renderable) noexcept;
|
||||||
|
void Remove(Handle<SHRenderable> renderable) noexcept;
|
||||||
|
void Clear() noexcept;
|
||||||
|
void Build(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer) noexcept;
|
||||||
|
void Draw(Handle<SHVkCommandBuffer> cmdBuffer) noexcept;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Getter Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
SHSubPassIndex GetSubpassId() const noexcept { return subpassIndex; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Data Members */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
// Batch Properties
|
||||||
|
SHSubPassIndex subpassIndex;
|
||||||
|
// Children
|
||||||
|
std::vector<SHBatch> batches;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -21,23 +21,23 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
void SHCamera::SetLookAt(const SHVec3& pos, const SHVec3& target, const SHVec3& up)
|
void SHCamera::SetLookAt(const SHVec3& pos, const SHVec3& target, const SHVec3& up)
|
||||||
{
|
{
|
||||||
const SHVec3 VIEW = (target - pos).Normalized();
|
SHVec3 view = target - pos; view = SHVec3::Normalise(view);
|
||||||
const SHVec3 RIGHT = SHVec3::Cross(VIEW, up).Normalized();
|
SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right);
|
||||||
const SHVec3 UP = SHVec3::Cross(RIGHT, VIEW);
|
const SHVec3 UP = SHVec3::Cross(right, view);
|
||||||
|
|
||||||
viewMatrix = SHMatrix::Identity;
|
viewMatrix = SHMatrix::Identity;
|
||||||
viewMatrix(0, 0) = RIGHT[0];
|
viewMatrix(0, 0) = right[0];
|
||||||
viewMatrix(1, 0) = RIGHT[1];
|
viewMatrix(1, 0) = right[1];
|
||||||
viewMatrix(2, 0) = RIGHT[2];
|
viewMatrix(2, 0) = right[2];
|
||||||
viewMatrix(0, 1) = UP[0];
|
viewMatrix(0, 1) = UP[0];
|
||||||
viewMatrix(1, 1) = UP[1];
|
viewMatrix(1, 1) = UP[1];
|
||||||
viewMatrix(2, 1) = UP[2];
|
viewMatrix(2, 1) = UP[2];
|
||||||
viewMatrix(0, 2) = -VIEW[0];
|
viewMatrix(0, 2) = -view[0];
|
||||||
viewMatrix(1, 2) = -VIEW[1];
|
viewMatrix(1, 2) = -view[1];
|
||||||
viewMatrix(2, 2) = -VIEW[2];
|
viewMatrix(2, 2) = -view[2];
|
||||||
viewMatrix(3, 0) = -RIGHT.Dot(pos);
|
viewMatrix(3, 0) = -right.Dot(pos);
|
||||||
viewMatrix(3, 1) = -UP.Dot(pos);
|
viewMatrix(3, 1) = -UP.Dot(pos);
|
||||||
viewMatrix(3, 2) = VIEW.Dot(pos);
|
viewMatrix(3, 2) = view.Dot(pos);
|
||||||
|
|
||||||
isDirty = true;
|
isDirty = true;
|
||||||
}
|
}
|
||||||
|
@ -79,32 +79,32 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Getter Functions */
|
/* Getter Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
SHMathMat4f SHCamera::GetViewMatrix() const
|
SHMatrix SHCamera::GetViewMatrix() const
|
||||||
{
|
{
|
||||||
return viewMatrix;
|
return viewMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHMathMat4f SHCamera::GetProjectionMatrix() const
|
SHMatrix SHCamera::GetProjectionMatrix() const
|
||||||
{
|
{
|
||||||
return projMatrix;
|
return projMatrix;
|
||||||
}
|
}
|
||||||
SHMathMat4f SHCamera::GetViewProjectionMatrix()
|
SHMatrix SHCamera::GetViewProjectionMatrix()
|
||||||
{
|
{
|
||||||
updateMatrices();
|
updateMatrices();
|
||||||
return vpMatrix;
|
return vpMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHMathMat4f SHCamera::GetInverseViewMatrix() const
|
SHMatrix SHCamera::GetInverseViewMatrix() const
|
||||||
{
|
{
|
||||||
return inverseVpMatrix;
|
return inverseVpMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHMathMat4f SHCamera::GetInverseProjectionMatrix() const
|
SHMatrix SHCamera::GetInverseProjectionMatrix() const
|
||||||
{
|
{
|
||||||
return inverseProjMatrix;
|
return inverseProjMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHMathMat4f SHCamera::GetInverseViewProjectionMatrix()
|
SHMatrix SHCamera::GetInverseViewProjectionMatrix()
|
||||||
{
|
{
|
||||||
updateMatrices();
|
updateMatrices();
|
||||||
return inverseViewMatrix;
|
return inverseViewMatrix;
|
||||||
|
@ -138,11 +138,11 @@ namespace SHADE
|
||||||
if (isDirty)
|
if (isDirty)
|
||||||
{
|
{
|
||||||
vpMatrix = viewMatrix * projMatrix;
|
vpMatrix = viewMatrix * projMatrix;
|
||||||
inverseVpMatrix = vpMatrix;
|
inverseVpMatrix = SHMatrix::Inverse(vpMatrix);
|
||||||
inverseVpMatrix.Inverse();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SHVec3 SHCamera::multiplyHomogenous(const SHMathMat4f& mat, const SHVec3& vec)
|
|
||||||
|
SHVec3 SHCamera::multiplyHomogenous(const SHMatrix& mat, const SHVec3& vec)
|
||||||
{
|
{
|
||||||
const SHVec4 HOMO_VEC = { vec[0], vec[1], vec[2], 1.0f };
|
const SHVec4 HOMO_VEC = { vec[0], vec[1], vec[2], 1.0f };
|
||||||
const SHVec4 RESULT = mat * HOMO_VEC;
|
const SHVec4 RESULT = mat * HOMO_VEC;
|
||||||
|
|
|
@ -75,6 +75,6 @@ namespace SHADE
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void updateMatrices();
|
void updateMatrices();
|
||||||
static SHVec3 multiplyHomogenous(const SHMatrix& mat, const SHMatrix& vec);
|
static SHVec3 multiplyHomogenous(const SHMatrix& mat, const SHVec3& vec);
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -46,6 +46,8 @@ namespace SHADE
|
||||||
class SHViewport;
|
class SHViewport;
|
||||||
class SHCamera;
|
class SHCamera;
|
||||||
class SHVkShaderModule;
|
class SHVkShaderModule;
|
||||||
|
class SHMaterial;
|
||||||
|
class SHMaterialInstance;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
|
|
|
@ -11,6 +11,10 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
*//*************************************************************************************/
|
*//*************************************************************************************/
|
||||||
#include "SHpch.h"
|
#include "SHpch.h"
|
||||||
#include "SHMaterialInstance.h"
|
#include "SHMaterialInstance.h"
|
||||||
|
|
||||||
|
#include "SHGraphicsConstants.h"
|
||||||
|
#include "SHMaterial.h"
|
||||||
|
#include "Graphics/Pipeline/SHVkPipeline.h"
|
||||||
#include "Tools/SHLogger.h"
|
#include "Tools/SHLogger.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -39,7 +43,7 @@ namespace SHADE
|
||||||
assert(dataStore != nullptr);
|
assert(dataStore != nullptr);
|
||||||
|
|
||||||
if (!baseMaterial)
|
if (!baseMaterial)
|
||||||
throw std::runtime_error("[SHMaterialInstance] Attempted to set export a Material Instance with no base Material!");
|
throw std::runtime_error("[SHMaterialInstance] Attempted to set export a Material Instance with no base Material!");
|
||||||
|
|
||||||
// Copy default data from Material
|
// Copy default data from Material
|
||||||
baseMaterial->ExportProperties(dest);
|
baseMaterial->ExportProperties(dest);
|
||||||
|
@ -49,14 +53,27 @@ namespace SHADE
|
||||||
for (const auto& data : overrideData)
|
for (const auto& data : overrideData)
|
||||||
{
|
{
|
||||||
// Get memory offset to the data
|
// Get memory offset to the data
|
||||||
SHShaderBlockInterface::Variable variable = SHADER_INFO->GetVariable(data.Index);
|
const SHShaderBlockInterface::Variable* variable = SHADER_INFO->GetVariable(data.Index);
|
||||||
if (variable == nullptr)
|
if (variable == nullptr)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("[SHMaterialInstance] Invalid override data indices provided. Skipping.");
|
SHLOG_WARNING("[SHMaterialInstance] Invalid override data indices provided. Skipping.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto DATA_OFFSET = variable->offset;
|
const auto DATA_OFFSET = variable->offset;
|
||||||
memcpy_s(dest + DATA_OFFSET, dataStore.get() + data.StoredDataOffset, data.DataSize);
|
memcpy(static_cast<char*>(dest) + DATA_OFFSET, dataStore.get() + data.StoredDataOffset, data.DataSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
Handle<SHShaderBlockInterface> SHMaterialInstance::getShaderBlockInterface() const noexcept
|
||||||
|
{
|
||||||
|
return baseMaterial->GetPipeline()->GetPipelineLayout()->GetShaderBlockInterface
|
||||||
|
(
|
||||||
|
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
||||||
|
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
|
||||||
|
vk::ShaderStageFlagBits::eFragment
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -14,6 +14,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include <memory>
|
#include <memory>
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Resource/Handle.h"
|
#include "Resource/Handle.h"
|
||||||
|
#include "Graphics/Shaders/BlockInterface/SHShaderBlockInterface.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -76,6 +77,11 @@ namespace SHADE
|
||||||
std::vector<OverrideData> overrideData;
|
std::vector<OverrideData> overrideData;
|
||||||
std::unique_ptr<char> dataStore;
|
std::unique_ptr<char> dataStore;
|
||||||
size_t dataStoreSize = 0;
|
size_t dataStoreSize = 0;
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
/* Helper Functions */
|
||||||
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
Handle<SHShaderBlockInterface> getShaderBlockInterface() const noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@ namespace SHADE
|
||||||
// Allocate data store if it was empty
|
// Allocate data store if it was empty
|
||||||
if (dataStore == nullptr)
|
if (dataStore == nullptr)
|
||||||
{
|
{
|
||||||
dataStoreSize = SHADER_INFO->GetBytesRequired();dataStoreSize
|
dataStoreSize = SHADER_INFO->GetBytesRequired();
|
||||||
dataStore.reset(new char[dataStoreSize]);
|
dataStore.reset(new char[dataStoreSize]);
|
||||||
}
|
}
|
||||||
|
|
||||||
OverrideData od;
|
OverrideData od;
|
||||||
od.Index = SHADER_INFO.GetVariableIndex(key);
|
od.Index = SHADER_INFO->GetVariableIndex(key);
|
||||||
od.DataSize = sizeof(T);
|
od.DataSize = sizeof(T);
|
||||||
if (overrideData.empty())
|
if (overrideData.empty())
|
||||||
{
|
{
|
||||||
|
@ -65,7 +65,7 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search Override Data for the property
|
// Search Override Data for the property
|
||||||
uint32_t PROP_IDX = SHADER_INFO.GetVariableIndex(key);
|
uint32_t PROP_IDX = SHADER_INFO->GetVariableIndex(key);
|
||||||
auto prop = std::find(overrideData.begin(), overrideData.end(), [&](const OverrideData& data)
|
auto prop = std::find(overrideData.begin(), overrideData.end(), [&](const OverrideData& data)
|
||||||
{
|
{
|
||||||
return PROP_IDX == data.Index;
|
return PROP_IDX == data.Index;
|
||||||
|
|
|
@ -17,7 +17,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "Resource/Handle.h"
|
#include "Resource/Handle.h"
|
||||||
#include "Resource/ResourceLibrary.h"
|
#include "Resource/ResourceLibrary.h"
|
||||||
#include "SHVertex.h"
|
#include "Math/SHMath.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -44,10 +44,10 @@ namespace SHADE
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
using Index = uint32_t;
|
using Index = uint32_t;
|
||||||
using VertexPosition = SHMathVec3f;
|
using VertexPosition = SHVec3;
|
||||||
using VertexTexCoord = SHMathVec2f;
|
using VertexTexCoord = SHVec2;
|
||||||
using VertexTangent = SHMathVec3f;
|
using VertexTangent = SHVec3;
|
||||||
using VertexNormal = SHMathVec3f;
|
using VertexNormal = SHVec3;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
|
|
|
@ -13,6 +13,8 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
|
|
||||||
#include "SHRenderable.h"
|
#include "SHRenderable.h"
|
||||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
#include "SHGraphicsSystem.h"
|
||||||
|
#include "SHMaterialInstance.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -46,4 +48,4 @@ namespace SHADE
|
||||||
|
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
// Project Includes
|
// Project Includes
|
||||||
#include "SHCamera.h"
|
#include "SHCamera.h"
|
||||||
#include "Resource/Handle.h"
|
#include "Resource/Handle.h"
|
||||||
#include "SHGraphicsConstants.h"
|
|
||||||
#include "Graphics/RenderGraph/SHRenderGraph.h"
|
#include "Graphics/RenderGraph/SHRenderGraph.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -76,6 +75,6 @@ namespace SHADE
|
||||||
/* Data Members */
|
/* Data Members */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
Handle<SHCamera> camera;
|
Handle<SHCamera> camera;
|
||||||
Handle<SHRenderGraph> renderGraph;
|
Handle<SHRenderGraph> renderGraph;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited.
|
||||||
#include "Graphics/Instance/SHVkInstance.h"
|
#include "Graphics/Instance/SHVkInstance.h"
|
||||||
#include "Tools/SHLogger.h"
|
#include "Tools/SHLogger.h"
|
||||||
#include "SHRenderer.h"
|
#include "SHRenderer.h"
|
||||||
|
#include "Resource/ResourceLibrary.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace SHADE
|
||||||
class SHVkCommandBuffer;
|
class SHVkCommandBuffer;
|
||||||
class SHVkLogicalDevice;
|
class SHVkLogicalDevice;
|
||||||
class SHVkImageView;
|
class SHVkImageView;
|
||||||
|
class ResourceManager;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
|
|
|
@ -107,7 +107,7 @@ namespace SHADE
|
||||||
return renderpassHdl;
|
return renderpassHdl;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SHVkPipelineState::GetSubpassIndex(void) const noexcept
|
SHSubPassIndex SHVkPipelineState::GetSubpassIndex(void) const noexcept
|
||||||
{
|
{
|
||||||
return subpassIndex;
|
return subpassIndex;
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,7 +208,7 @@ namespace SHADE
|
||||||
SHDepthStencilState const& GetDepthStencilState (void) const noexcept;
|
SHDepthStencilState const& GetDepthStencilState (void) const noexcept;
|
||||||
SHColorBlendState const& GetColorBlenState (void) const noexcept;
|
SHColorBlendState const& GetColorBlenState (void) const noexcept;
|
||||||
Handle<SHVkRenderpass> const& GetRenderpass (void) const noexcept;
|
Handle<SHVkRenderpass> const& GetRenderpass (void) const noexcept;
|
||||||
uint32_t GetSubpassIndex (void) const noexcept;
|
SHSubPassIndex GetSubpassIndex (void) const noexcept;
|
||||||
|
|
||||||
void SetDirty(bool isDirty) noexcept;
|
void SetDirty(bool isDirty) noexcept;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,10 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
class SHVkLogicalDevice;
|
class SHVkLogicalDevice;
|
||||||
class SHVkFramebuffer;
|
class SHVkFramebuffer;
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* TYPE DEFINTIIONS */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
using SHSubPassIndex = uint32_t;
|
||||||
|
|
||||||
class SHVkRenderpass
|
class SHVkRenderpass
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#include "SHPch.h"
|
#include "SHPch.h"
|
||||||
#include "SHVkUtil.h"
|
#include "SHVkUtil.h"
|
||||||
|
|
||||||
|
#include "Graphics/Buffers/SHVkBuffer.h"
|
||||||
|
#include "Graphics/Commands/SHVkCommandBuffer.h"
|
||||||
|
#include "Graphics/Devices/SHVkLogicalDevice.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -19,4 +23,29 @@ namespace SHADE
|
||||||
IsDepthOnlyFormat(format);
|
IsDepthOnlyFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHVkUtil::EnsureBufferAndCopyData(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHVkBuffer>& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage)
|
||||||
|
{
|
||||||
|
if (bufferHandle)
|
||||||
|
{
|
||||||
|
// Resize
|
||||||
|
bufferHandle->ResizeReplace(size, src, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create new
|
||||||
|
using BuffUsage = vk::BufferUsageFlagBits;
|
||||||
|
bufferHandle = device->CreateBuffer
|
||||||
|
(
|
||||||
|
size,
|
||||||
|
src,
|
||||||
|
size,
|
||||||
|
usage | BuffUsage::eTransferDst,
|
||||||
|
VmaMemoryUsage::VMA_MEMORY_USAGE_AUTO,
|
||||||
|
VmaAllocationCreateFlagBits::VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order transfers
|
||||||
|
bufferHandle->TransferToDeviceResource(cmdBuffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,53 @@
|
||||||
|
|
||||||
#include "SHVulkanIncludes.h"
|
#include "SHVulkanIncludes.h"
|
||||||
|
|
||||||
|
#include "Resource/Handle.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Forward Declarations */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
class SHVkLogicalDevice;
|
||||||
|
class SHVkCommandBuffer;
|
||||||
|
class SHVkBuffer;
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
/* Type Definitions */
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
class SHVkUtil
|
class SHVkUtil
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool IsDepthOnlyFormat (vk::Format format) noexcept;
|
static bool IsDepthOnlyFormat (vk::Format format) noexcept;
|
||||||
static bool IsDepthStencilAttachment(vk::Format format) noexcept;
|
static bool IsDepthStencilAttachment(vk::Format format) noexcept;
|
||||||
|
/***********************************************************************************/
|
||||||
|
/*!
|
||||||
|
|
||||||
|
\brief
|
||||||
|
Ensures that the specified bufferHandle contains a buffer that fits the specified
|
||||||
|
size and creates it if it does not exist. This follows by issuing a transfer
|
||||||
|
command into the created buffer.
|
||||||
|
|
||||||
|
All created buffers will use VMA_MEMORY_USAGE_AUTO and
|
||||||
|
VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT.
|
||||||
|
|
||||||
|
\param device
|
||||||
|
Device used to create the SHVkBuffer.
|
||||||
|
\param cmdBuffer
|
||||||
|
CommandBuffer which commands for issuing transferring the data to the GPU.
|
||||||
|
\param bufferHandle
|
||||||
|
Reference to the handle that holds any existing buffer or will be used to hold the
|
||||||
|
created buffer.
|
||||||
|
\param src
|
||||||
|
Data to copy from.
|
||||||
|
\param size
|
||||||
|
Size of data to copy.
|
||||||
|
\param usage
|
||||||
|
Usage flags for the buffer.
|
||||||
|
|
||||||
|
*/
|
||||||
|
/***********************************************************************************/
|
||||||
|
static void EnsureBufferAndCopyData(Handle<SHVkLogicalDevice> device, Handle<SHVkCommandBuffer> cmdBuffer, Handle<SHVkBuffer>& bufferHandle, void* src, uint32_t size, vk::BufferUsageFlagBits usage);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "SHPch.h"
|
#include "SHPch.h"
|
||||||
#include "SHShaderBlockInterface.h"
|
#include "SHShaderBlockInterface.h"
|
||||||
|
#include "Tools/SHLogger.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
|
@ -12,14 +13,14 @@ namespace SHADE
|
||||||
SHLOG_WARNING("[SHShaderBlockInterface] Attempted to specify a variable with a duplicate name. This will be ignored.");
|
SHLOG_WARNING("[SHShaderBlockInterface] Attempted to specify a variable with a duplicate name. This will be ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
variableIndexing.emplace_back(std::move(newVariable));
|
variables.emplace_back(std::move(newVariable));
|
||||||
variables.try_emplace (std::move(name), static_cast<uint32_t>(variableIndexing.size() - 1));
|
variableIndexing.try_emplace(std::move(name), static_cast<uint32_t>(variables.size() - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
SHShaderBlockInterface::Variable const* const SHShaderBlockInterface::GetVariable(std::string const& variableName) const noexcept
|
SHShaderBlockInterface::Variable const* const SHShaderBlockInterface::GetVariable(std::string const& variableName) const noexcept
|
||||||
{
|
{
|
||||||
if (variableIndexing.contains(variableName))
|
if (variableIndexing.contains(variableName))
|
||||||
return &variables.at(variableIndexing.at(variableName).second);
|
return &variables.at(variableIndexing.at(variableName));
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -32,12 +33,12 @@ namespace SHADE
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SHShaderBlockInterface::GetVariableIndex(std::string const& variableName) const noexcept
|
uint32_t SHShaderBlockInterface::GetVariableIndex(std::string const& variableName) const
|
||||||
{
|
{
|
||||||
if (!variableIndexing.contains(variableName))
|
if (!variableIndexing.contains(variableName))
|
||||||
throw std::invalid_argument("Attempted to retrieve index to variable that does not exist!");
|
throw std::invalid_argument("Attempted to retrieve index to variable that does not exist!");
|
||||||
|
|
||||||
return variableIndexing.at(variableName).second;
|
return variableIndexing.at(variableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHShaderBlockInterface::SHShaderBlockInterface(void) noexcept
|
SHShaderBlockInterface::SHShaderBlockInterface(void) noexcept
|
||||||
|
@ -47,7 +48,7 @@ namespace SHADE
|
||||||
SHShaderBlockInterface::SHShaderBlockInterface(SHShaderBlockInterface&& rhs) noexcept
|
SHShaderBlockInterface::SHShaderBlockInterface(SHShaderBlockInterface&& rhs) noexcept
|
||||||
: variables { std::move(rhs.variables) }
|
: variables { std::move(rhs.variables) }
|
||||||
, variableIndexing { std::move(rhs.variableIndexing) }
|
, variableIndexing { std::move(rhs.variableIndexing) }
|
||||||
, bytesRequired { std::move (rhs.bytesRequired) }
|
, bytesRequired { rhs.bytesRequired }
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void SHShaderBlockInterface::SetBytesRequired(uint32_t bytes) noexcept
|
void SHShaderBlockInterface::SetBytesRequired(uint32_t bytes) noexcept
|
||||||
|
@ -68,7 +69,7 @@ namespace SHADE
|
||||||
|
|
||||||
variables = std::move(rhs.variables);
|
variables = std::move(rhs.variables);
|
||||||
variableIndexing = std::move(rhs.variableIndexing);
|
variableIndexing = std::move(rhs.variableIndexing);
|
||||||
bytesRequired = std::move(rhs.bytesRequired);
|
bytesRequired = rhs.bytesRequired;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace SHADE
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class ResourceLibrary;
|
class ResourceLibrary;
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
|
@ -89,7 +89,7 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
Handle() = default;
|
Handle() = default;
|
||||||
~Handle() = default;
|
~Handle() = default;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Usage Functions */
|
/* Usage Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -14,16 +14,16 @@ namespace SHADE
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* HandleBase - Overloaded Operators */
|
/* HandleBase - Overloaded Operators */
|
||||||
/*---------------------------------------------------------------------------------*/
|
|
||||||
inline HandleBase::operator bool() const
|
inline HandleBase::operator bool() const
|
||||||
|
/*---------------------------------------------------------------------------------*/
|
||||||
{
|
{
|
||||||
return id.Raw != INVALID_ID.Raw;
|
return id.Raw != INVALID_ID.Raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
/* Handle<T> - Usage Functions */
|
/* Handle<T> - Usage Functions */
|
||||||
/*---------------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------------*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void Handle<T>::Free()
|
inline void Handle<T>::Free()
|
||||||
{
|
{
|
||||||
library->Free(*this);
|
library->Free(*this);
|
||||||
|
|
|
@ -62,14 +62,14 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
SparseSet<T> objects;
|
SparseSet<T> objects;
|
||||||
SparseSet<uint32_t> versionCounts;
|
SparseSet<uint32_t> versionCounts;
|
||||||
std::queue<uint32_t> freeList;
|
std::queue<uint32_t> freeList;
|
||||||
uint32_t lastIdx = 0;
|
uint32_t lastIdx = 0;
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
/* Helper Functions */
|
/* Helper Functions */
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void assertHandleValid(Handle<T> handle) const;
|
void assertHandleValid(Handle<T> handle) const;
|
||||||
uint32_t getAvailableFreeIndex();
|
uint32_t getAvailableFreeIndex();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue