Skip to content

Commit

Permalink
Fewer copies with frame markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Duttenheim committed Nov 11, 2024
1 parent 8ef6928 commit e332df3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
2 changes: 1 addition & 1 deletion code/render/coregraphics/commandbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void CmdFinishQueries(const CmdBufferId id);
/// Returns true if command buffer uses markers
bool CmdRecordsMarkers(const CmdBufferId id);
/// This is not a command buffer command, but is used to get the markers in the buffer
Util::Array<CoreGraphics::FrameProfilingMarker> CmdCopyProfilingMarkers(const CmdBufferId id);
Util::Array<CoreGraphics::FrameProfilingMarker>&& CmdMoveProfilingMarkers(const CmdBufferId id);
/// Get the offset to the first query
uint CmdGetMarkerOffset(const CmdBufferId id);
#endif
Expand Down
24 changes: 12 additions & 12 deletions code/render/coregraphics/vk/vkcommandbuffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Threading::CriticalSection commandBufferCritSect;
//------------------------------------------------------------------------------
/**
*/
const VkCommandPool
const VkCommandPool
CmdBufferPoolGetVk(const CoreGraphics::CmdBufferPoolId id)
{
return commandBufferPools.Get<CommandBufferPool_VkCommandPool>(id.id);
Expand All @@ -42,7 +42,7 @@ CmdBufferPoolGetVk(const CoreGraphics::CmdBufferPoolId id)
//------------------------------------------------------------------------------
/**
*/
const VkDevice
const VkDevice
CmdBufferPoolGetVkDevice(const CoreGraphics::CmdBufferPoolId id)
{
return commandBufferPools.Get<CommandBufferPool_VkDevice>(id.id);
Expand Down Expand Up @@ -100,7 +100,7 @@ _IMPL_ACQUIRE_RELEASE(CmdBufferId, commandBuffers);
//------------------------------------------------------------------------------
/**
*/
const CmdBufferPoolId
const CmdBufferPoolId
CreateCmdBufferPool(const CmdBufferPoolCreateInfo& info)
{
Ids::Id32 id = commandBufferPools.Alloc();
Expand Down Expand Up @@ -130,7 +130,7 @@ CreateCmdBufferPool(const CmdBufferPoolCreateInfo& info)
//------------------------------------------------------------------------------
/**
*/
void
void
DestroyCmdBufferPool(const CmdBufferPoolId pool)
{
vkDestroyCommandPool(commandBufferPools.Get<CommandBufferPool_VkDevice>(pool.id), commandBufferPools.Get<CommandBufferPool_VkCommandPool>(pool.id), nullptr);
Expand Down Expand Up @@ -359,7 +359,7 @@ CmdSetVertexBuffer(const CmdBufferId id, IndexT streamIndex, const CoreGraphics:
VkBuffer buf = Vulkan::BufferGetVk(buffer);
VkDeviceSize offset = bufferOffset;
vkCmdBindVertexBuffers(cmdBuf, streamIndex, 1, &buf, &offset);
}
}

//------------------------------------------------------------------------------
/**
Expand Down Expand Up @@ -1021,7 +1021,7 @@ CmdBeginPass(const CmdBufferId id, const PassId pass)
pipelineBundle.pipelineInfo.subpass = 0;
pipelineBundle.pipelineInfo.renderPass = framebufferInfo.renderPass;
pipelineBundle.pipelineInfo.pViewportState = framebufferInfo.pViewportState;
vkCmdBeginRenderPass(cmdBuf, &info, VK_SUBPASS_CONTENTS_INLINE);
vkCmdBeginRenderPass(cmdBuf, &info, VK_SUBPASS_CONTENTS_INLINE);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -1141,7 +1141,7 @@ CmdResolve(const CmdBufferId id, const CoreGraphics::TextureId source, const Cor
resolve.dstSubresource.baseArrayLayer = 0;
resolve.dstSubresource.layerCount = 1;
resolve.dstSubresource.mipLevel = 0;

vkCmdResolveImage(cmdBuf, vkSrc, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, vkDst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &resolve);
}

Expand Down Expand Up @@ -1696,7 +1696,7 @@ CmdFinishQueries(const CmdBufferId id)
QueryBundle& queryBundle = commandBuffers.Get<CmdBuffer_Query>(id.id);
for (IndexT i = 0; i < CoreGraphics::QueryType::NumQueryTypes; i++)
{
// Grab all chunk offsets and counts
// Grab all chunk offsets and counts
const Util::Array<QueryBundle::QueryChunk>& chunks = queryBundle.chunks[i];
if (!chunks.IsEmpty())
{
Expand Down Expand Up @@ -1728,11 +1728,11 @@ CmdRecordsMarkers(const CmdBufferId id)
//------------------------------------------------------------------------------
/**
*/
Util::Array<CoreGraphics::FrameProfilingMarker>
CmdCopyProfilingMarkers(const CmdBufferId id)
Util::Array<CoreGraphics::FrameProfilingMarker>&&
CmdMoveProfilingMarkers(const CmdBufferId id)
{
CoreGraphics::CmdBufferMarkerBundle markers = commandBuffers.ConstGet<CmdBuffer_ProfilingMarkers>(id.id);
return markers.finishedMarkers;
CoreGraphics::CmdBufferMarkerBundle& markers = commandBuffers.Get<CmdBuffer_ProfilingMarkers>(id.id);
return std::move(markers.finishedMarkers);
}

//------------------------------------------------------------------------------
Expand Down
50 changes: 25 additions & 25 deletions code/render/coregraphics/vk/vkgraphicsdevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ SetupAdapter(CoreGraphics::GraphicsDeviceCreateInfo::Features features)
n_printf("[Graphics Device] Mesh Shaders are disabled\n");
if (!CoreGraphics::VariableRateShadingSupported)
n_printf("[Graphics Device] Variable Rate Shading is disabled\n");

state.numCaps[i] = newNumCaps;

if (validDevice)
Expand Down Expand Up @@ -406,7 +406,7 @@ GetCurrentPhysicalDevice()
//------------------------------------------------------------------------------
/**
*/
VkPhysicalDeviceFeatures
VkPhysicalDeviceFeatures
GetCurrentFeatures()
{
return state.deviceFeatures[state.currentDevice];
Expand All @@ -415,7 +415,7 @@ GetCurrentFeatures()
//------------------------------------------------------------------------------
/**
*/
VkPipelineCache
VkPipelineCache
GetPipelineCache()
{
return state.cache;
Expand All @@ -433,7 +433,7 @@ GetMemoryProperties()
//------------------------------------------------------------------------------
/**
*/
VkSemaphore
VkSemaphore
GetRenderingSemaphore()
{
return SemaphoreGetVk(state.renderingFinishedSemaphores[state.currentBufferedFrameIndex]);
Expand Down Expand Up @@ -472,7 +472,7 @@ GetQueryPool(const CoreGraphics::QueryType query)
//------------------------------------------------------------------------------
/**
*/
void
void
WaitForPresent(VkSemaphore sem)
{
n_assert(state.waitForPresentSemaphore == VK_NULL_HANDLE);
Expand All @@ -482,7 +482,7 @@ WaitForPresent(VkSemaphore sem)
//------------------------------------------------------------------------------
/**
*/
const VkQueue
const VkQueue
GetQueue(const CoreGraphics::QueueType type, const IndexT index)
{
return state.queueHandler.queues[type][index];
Expand All @@ -491,7 +491,7 @@ GetQueue(const CoreGraphics::QueueType type, const IndexT index)
//------------------------------------------------------------------------------
/**
*/
const VkQueue
const VkQueue
GetCurrentQueue(const CoreGraphics::QueueType type)
{
return state.queueHandler.GetQueue(type);
Expand All @@ -518,7 +518,7 @@ GetOrCreatePipeline(
//------------------------------------------------------------------------------
/**
*/
void
void
SparseTextureBind(const VkImage img, const Util::Array<VkSparseMemoryBind>& opaqueBinds, const Util::Array<VkSparseImageMemoryBind>& pageBinds)
{
CoreGraphics::SubmissionWaitEvent sparseWait;
Expand Down Expand Up @@ -1210,7 +1210,7 @@ CreateGraphicsDevice(const GraphicsDeviceCreateInfo& info)
}

BufferCreateInfo cboInfo;

state.globalConstantBufferMaxValue = info.globalConstantBufferMemorySize;

cboInfo.name = "Global Constant Buffer";
Expand Down Expand Up @@ -1239,7 +1239,7 @@ CreateGraphicsDevice(const GraphicsDeviceCreateInfo& info)
state.presentFences[i] = CreateFence({true});
state.renderingFinishedSemaphores[i] = CreateSemaphore({
#if NEBULA_GRAPHICS_DEBUG
.name = "Present",
.name = "Present",
#endif
.type = SemaphoreType::Binary });
}
Expand Down Expand Up @@ -1650,7 +1650,7 @@ PollSubmissionIndex(const CoreGraphics::QueueType queue, uint64 index)
//------------------------------------------------------------------------------
/**
*/
void
void
AddSubmissionEvent(const CoreGraphics::SubmissionWaitEvent& event)
{
state.waitEvents[state.currentBufferedFrameIndex].Append(event);
Expand Down Expand Up @@ -1695,13 +1695,13 @@ SubmitCommandBuffers(
{
if (CoreGraphics::CmdRecordsMarkers(cmdBuf))
{
Util::Array<CoreGraphics::FrameProfilingMarker> markers = CmdCopyProfilingMarkers(cmdBuf);
Util::Array<CoreGraphics::FrameProfilingMarker> markers = CmdMoveProfilingMarkers(cmdBuf);
state.pendingMarkers[type][state.currentBufferedFrameIndex].markers.Append(std::move(markers));
state.pendingMarkers[type][state.currentBufferedFrameIndex].baseOffset.Append(CmdGetMarkerOffset(cmdBuf));
}
}
#endif

return ret;
}

Expand Down Expand Up @@ -1851,7 +1851,7 @@ GetConstantBuffer(IndexT i)
//------------------------------------------------------------------------------
/**
*/
void
void
ReloadShaderProgram(const CoreGraphics::ShaderProgramId& pro)
{
state.database.Reload(pro);
Expand Down Expand Up @@ -1903,7 +1903,7 @@ FinishFrame(IndexT frameIndex)
//------------------------------------------------------------------------------
/**
*/
void
void
WaitForQueue(CoreGraphics::QueueType queue)
{
state.queueHandler.WaitIdle(queue);
Expand All @@ -1912,7 +1912,7 @@ WaitForQueue(CoreGraphics::QueueType queue)
//------------------------------------------------------------------------------
/**
*/
void
void
WaitAndClearPendingCommands()
{
state.queueHandler.WaitIdle(GraphicsQueueType);
Expand Down Expand Up @@ -2396,7 +2396,7 @@ SaveScreenshot(CoreGraphics::ImageFileFormat::Code fmt, const Ptr<IO::Stream>& o
//------------------------------------------------------------------------------
/**
*/
CoreGraphics::ImageFileFormat::Code
CoreGraphics::ImageFileFormat::Code
SaveScreenshot(CoreGraphics::ImageFileFormat::Code fmt, const Ptr<IO::Stream>& outStream, const Math::rectangle<int>& rect, int x, int y)
{
return CoreGraphics::ImageFileFormat::InvalidImageFileFormat;
Expand All @@ -2405,7 +2405,7 @@ SaveScreenshot(CoreGraphics::ImageFileFormat::Code fmt, const Ptr<IO::Stream>& o
//------------------------------------------------------------------------------
/**
*/
bool
bool
GetVisualizeMipMaps()
{
return state.visualizeMipMaps;
Expand All @@ -2414,7 +2414,7 @@ GetVisualizeMipMaps()
//------------------------------------------------------------------------------
/**
*/
void
void
SetVisualizeMipMaps(bool val)
{
state.visualizeMipMaps = val;
Expand All @@ -2432,7 +2432,7 @@ GetRenderWireframe()
//------------------------------------------------------------------------------
/**
*/
void
void
SetRenderWireframe(bool b)
{
state.renderWireframe = b;
Expand All @@ -2451,7 +2451,7 @@ GetProfilingMarkers()
//------------------------------------------------------------------------------
/**
*/
SizeT
SizeT
GetNumDrawCalls()
{
return state.GraphicsDeviceNumDrawCalls->GetSample();
Expand Down Expand Up @@ -2504,7 +2504,7 @@ ObjectSetName(const CoreGraphics::TextureId id, const char* name)
Util::String str = Util::String::Sprintf("%s - View", name);
info.pObjectName = str.AsCharPtr();
res = VkDebugObjectName(dev, &info);
n_assert(res == VK_SUCCESS);
n_assert(res == VK_SUCCESS);
}


Expand Down Expand Up @@ -2671,7 +2671,7 @@ ObjectSetName(const SemaphoreId id, const char* name)
//------------------------------------------------------------------------------
/**
*/
void
void
QueueBeginMarker(const CoreGraphics::QueueType queue, const Math::vec4& color, const char* name)
{
VkQueue vkqueue = state.queueHandler.GetQueue(queue);
Expand All @@ -2690,7 +2690,7 @@ QueueBeginMarker(const CoreGraphics::QueueType queue, const Math::vec4& color, c
//------------------------------------------------------------------------------
/**
*/
void
void
QueueEndMarker(const CoreGraphics::QueueType queue)
{
VkQueue vkqueue = state.queueHandler.GetQueue(queue);
Expand All @@ -2700,7 +2700,7 @@ QueueEndMarker(const CoreGraphics::QueueType queue)
//------------------------------------------------------------------------------
/**
*/
void
void
QueueInsertMarker(const CoreGraphics::QueueType queue, const Math::vec4& color, const char* name)
{
VkQueue vkqueue = state.queueHandler.GetQueue(queue);
Expand Down
3 changes: 3 additions & 0 deletions toolkit/editor/editor/ui/windows/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ Profiler::Run(SaveMode save)
if (ImGui::IsKeyPressed((ImGuiKey)Input::Key::F3))
this->pauseProfiling = !this->pauseProfiling;
if (!this->pauseProfiling)
{
this->ProfilingContexts = Profiling::ProfilingGetContexts();
this->frameProfilingMarkers = CoreGraphics::GetProfilingMarkers();
}

if (!this->frametimeHistory.IsEmpty())
{
Expand Down

0 comments on commit e332df3

Please sign in to comment.