Catered to light comp deletion and solved minimize bugs
Editor can also now shift the viewport around without Vulkan vomiting validation layers
This commit is contained in:
parent
fa6e3cf1df
commit
25db4db99a
|
@ -73,15 +73,7 @@ namespace SHADE
|
|||
if (width == 0 || height == 0)
|
||||
return;
|
||||
|
||||
#ifdef SHEDITOR
|
||||
|
||||
//PrepareResize(1, 1, SHVec2(0, 0));
|
||||
|
||||
#else
|
||||
|
||||
PrepareResize(resizeWidth, resizeHeight, SHVec2(0, 0));
|
||||
|
||||
#endif
|
||||
PrepareResize(resizeWidth, resizeHeight);
|
||||
});
|
||||
|
||||
window->RegisterWindowCloseCallback([&](void)
|
||||
|
@ -352,6 +344,12 @@ namespace SHADE
|
|||
void SHGraphicsSystem::Run(double) noexcept
|
||||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
{
|
||||
restoredFromMinimize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (restoredFromMinimize)
|
||||
return;
|
||||
|
||||
// Frame data for the current frame
|
||||
|
@ -487,17 +485,12 @@ namespace SHADE
|
|||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
{
|
||||
// #BackEndTest: For for the fence initialized by queue submit
|
||||
renderContext.WaitForFence();
|
||||
|
||||
// #BackEndTest: Get the current frame from frame manager
|
||||
auto& currFrameData = renderContext.GetCurrentFrameData();
|
||||
|
||||
// #BackEndTest: Reset command pool
|
||||
if (currFrameData.cmdPoolHdls.empty())
|
||||
throw std::runtime_error("No command pools available!");
|
||||
currFrameData.cmdPoolHdls[0]->Reset();
|
||||
restoredFromMinimize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (restoredFromMinimize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -548,7 +541,17 @@ namespace SHADE
|
|||
void SHGraphicsSystem::EndRender()
|
||||
{
|
||||
if (window->IsMinimized() || renderContext.GetWindowIsDead())
|
||||
{
|
||||
restoredFromMinimize = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (restoredFromMinimize)
|
||||
{
|
||||
restoredFromMinimize = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const uint32_t CURR_FRAME_IDX = renderContext.GetCurrentFrame();
|
||||
auto& currFrameData = renderContext.GetCurrentFrameData();
|
||||
|
|
|
@ -356,5 +356,7 @@ namespace SHADE
|
|||
|
||||
uint32_t resizeWidth;
|
||||
uint32_t resizeHeight;
|
||||
bool restoredFromMinimize = false;
|
||||
|
||||
};
|
||||
}
|
|
@ -67,6 +67,7 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -88,6 +89,7 @@ namespace SHADE
|
|||
|
||||
// Get data required for struct
|
||||
lightDataSize = GetLightTypeSize(type);
|
||||
lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize);
|
||||
|
||||
// So create some data!
|
||||
Expand(logicalDevice);
|
||||
|
@ -123,10 +125,10 @@ namespace SHADE
|
|||
// Initialize the data for lights
|
||||
intermediateData = std::make_unique<uint8_t[]>(lightDataSize * maxLights);
|
||||
|
||||
lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize * maxLights);
|
||||
lightDataTotalAlignedSize = logicalDevice->PadSSBOSize(lightDataAlignedSize * maxLights);
|
||||
|
||||
// We want to initialize 3 times the amount of data required.
|
||||
dataBuffer = logicalDevice->CreateBuffer(lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT);
|
||||
dataBuffer = logicalDevice->CreateBuffer(lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, nullptr, lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, vk::BufferUsageFlagBits::eStorageBuffer, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -145,7 +147,7 @@ namespace SHADE
|
|||
maxLights *= 2;
|
||||
|
||||
// calculate total + padding
|
||||
lightDataAlignedSize = logicalDevice->PadSSBOSize(lightDataSize * maxLights);
|
||||
lightDataTotalAlignedSize = logicalDevice->PadSSBOSize(lightDataAlignedSize * maxLights);
|
||||
|
||||
// destroy old data and initialize container for double the amount of data.
|
||||
intermediateData = std::make_unique<uint8_t[]>(lightDataSize * maxLights);
|
||||
|
@ -154,7 +156,7 @@ namespace SHADE
|
|||
std::memcpy(intermediateData.get(), oldData.get(), lightDataSize * OLD_MAX_LIGHTS);
|
||||
|
||||
// Resize the GPU buffer. TODO: Replace with Resize no copy here
|
||||
dataBuffer->ResizeReplace(maxLights * lightDataAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataAlignedSize * OLD_MAX_LIGHTS);
|
||||
dataBuffer->ResizeReplace(maxLights * lightDataTotalAlignedSize * SHGraphicsConstants::NUM_FRAME_BUFFERS, oldData.get(), lightDataTotalAlignedSize * OLD_MAX_LIGHTS);
|
||||
}
|
||||
|
||||
|
||||
|
@ -205,7 +207,7 @@ namespace SHADE
|
|||
|
||||
uint32_t SHLightingSubSystem::PerTypeData::GetAlignmentSize(void) const noexcept
|
||||
{
|
||||
return lightDataAlignedSize;
|
||||
return lightDataTotalAlignedSize;
|
||||
}
|
||||
|
||||
uint32_t SHLightingSubSystem::PerTypeData::GetDataSize(void) const noexcept
|
||||
|
@ -254,7 +256,7 @@ namespace SHADE
|
|||
// Now that the container is big enough, bind the new light
|
||||
|
||||
// Get address of write location
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataSize * numLights);
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataAlignedSize * numLights);
|
||||
|
||||
// Write the light data to address
|
||||
WriteLightToAddress(writeLocation, unboundLight);
|
||||
|
@ -280,7 +282,7 @@ namespace SHADE
|
|||
/***************************************************************************/
|
||||
void SHLightingSubSystem::PerTypeData::ModifyLight(SHLightComponent* lightComp) noexcept
|
||||
{
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataSize * lightComp->GetIndexInBuffer());
|
||||
void* writeLocation = reinterpret_cast<uint8_t*>(intermediateData.get()) + (lightDataAlignedSize * lightComp->GetIndexInBuffer());
|
||||
WriteLightToAddress(writeLocation, lightComp);
|
||||
}
|
||||
|
||||
|
@ -289,10 +291,15 @@ namespace SHADE
|
|||
if (intermediateData)
|
||||
{
|
||||
// we want to write to the offset of the current frame
|
||||
dataBuffer->WriteToMemory(intermediateData.get(), lightDataSize * numLights, 0, lightDataSize * maxLights * frameIndex);
|
||||
dataBuffer->WriteToMemory(intermediateData.get(), lightDataAlignedSize * numLights, 0, lightDataAlignedSize * maxLights * frameIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void SHLightingSubSystem::PerTypeData::ResetNumLights(void) noexcept
|
||||
{
|
||||
numLights = 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -343,6 +350,14 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHLightingSubSystem::ResetNumLights(void) noexcept
|
||||
{
|
||||
for (auto& data : perTypeData)
|
||||
{
|
||||
data.ResetNumLights();
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
/*!
|
||||
|
||||
|
@ -391,6 +406,7 @@ namespace SHADE
|
|||
dynamicOffsets[i].resize(NUM_LIGHT_TYPES + 1); // +1 for the count
|
||||
}
|
||||
|
||||
numLightComponents = 0;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
@ -409,13 +425,23 @@ namespace SHADE
|
|||
|
||||
auto& lightComps = SHComponentManager::GetDense<SHLightComponent>();
|
||||
bool expanded = false;
|
||||
bool rewrite = false;
|
||||
|
||||
if (numLightComponents > lightComps.size())
|
||||
{
|
||||
rewrite = true;
|
||||
ResetNumLights();
|
||||
}
|
||||
|
||||
numLightComponents = lightComps.size();
|
||||
|
||||
for (auto& light : lightComps)
|
||||
{
|
||||
auto enumValue = SHUtilities::ToUnderlying(light.GetLightData().type);
|
||||
|
||||
// First we want to make sure the light is already bound to the system. if it
|
||||
// isn't, we write it to the correct buffer.
|
||||
if (!light.GetBound())
|
||||
if (!light.GetBound() || rewrite)
|
||||
{
|
||||
perTypeData[enumValue].AddLight(logicalDevice, &light, expanded);
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* STATIC MEMBER VARIABLES */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static constexpr uint32_t STARTING_NUM_LIGHTS = 20;
|
||||
static constexpr uint32_t STARTING_NUM_LIGHTS = 50;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PRIVATE MEMBER VARIABLES */
|
||||
|
@ -74,11 +74,13 @@ namespace SHADE
|
|||
uint32_t maxLights;
|
||||
|
||||
//! SSBOs need to be aligned. This is to pad descriptor offset
|
||||
uint32_t lightDataAlignedSize;
|
||||
uint32_t lightDataTotalAlignedSize;
|
||||
|
||||
//! size needed to store 1 struct object
|
||||
uint32_t lightDataSize;
|
||||
|
||||
uint32_t lightDataAlignedSize;
|
||||
|
||||
//! type of the light. Will be used later when we want to expand
|
||||
SH_LIGHT_TYPE lightType;
|
||||
|
||||
|
@ -103,6 +105,7 @@ namespace SHADE
|
|||
void AddLight (Handle<SHVkLogicalDevice> logicalDevice, SHLightComponent* unboundLight, bool expanded) noexcept;
|
||||
void ModifyLight (SHLightComponent* lightComp) noexcept;
|
||||
void WriteToGPU (uint32_t frameIndex) noexcept;
|
||||
void ResetNumLights (void) noexcept;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* GETTERS */
|
||||
|
@ -138,11 +141,17 @@ namespace SHADE
|
|||
//! For padding in the buffer
|
||||
uint32_t lightCountsAlignedSize;
|
||||
|
||||
//! Number of SHLightComponents recorded. If at the beginning of the run function the size returned by the dense
|
||||
//! set is less than the size recorded, rewrite all light components into the its respective buffers. If its more,
|
||||
//! don't do anything.
|
||||
uint32_t numLightComponents;
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* PRIVATE MEMBER FUNCTIONS */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
void UpdateDescSet (uint32_t binding) noexcept;
|
||||
void ComputeDynamicOffsets (void) noexcept;
|
||||
void ResetNumLights (void) noexcept;
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ namespace SHADE
|
|||
{
|
||||
SHLOG_ERROR("Frame index retrieved from vkAcquireNextImageKHR is not the same as currentFrame.");
|
||||
}
|
||||
|
||||
currentFrame = frameIndex;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue