From ce6e946f6f4882aba8a62392ae791c948633e2e3 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Mon, 25 Jul 2022 13:36:43 -0700 Subject: Split render-cuda.cpp into smaller files (#2334) * render-cuda split, compile errors galore due to missing includes etc. * render-cuda split and fully compiles * Ran premake.bat to disable cuda; Added all new files * Removed render-cuda files * CI fixes * Rerun CI --- tools/gfx/cuda/cuda-query.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/gfx/cuda/cuda-query.cpp (limited to 'tools/gfx/cuda/cuda-query.cpp') diff --git a/tools/gfx/cuda/cuda-query.cpp b/tools/gfx/cuda/cuda-query.cpp new file mode 100644 index 000000000..7e97699f8 --- /dev/null +++ b/tools/gfx/cuda/cuda-query.cpp @@ -0,0 +1,48 @@ +// cuda-query.cpp +#include "cuda-query.h" + +namespace gfx +{ +#ifdef GFX_ENABLE_CUDA +using namespace Slang; + +namespace cuda +{ + +Result QueryPoolImpl::init(const IQueryPool::Desc& desc) +{ + cuEventCreate(&m_startEvent, 0); + cuEventRecord(m_startEvent, 0); + m_events.setCount(desc.count); + for (SlangInt i = 0; i < m_events.getCount(); i++) + { + cuEventCreate(&m_events[i], 0); + } + return SLANG_OK; +} + +QueryPoolImpl::~QueryPoolImpl() +{ + for (auto& e : m_events) + { + cuEventDestroy(e); + } + cuEventDestroy(m_startEvent); +} + +SLANG_NO_THROW Result SLANG_MCALL QueryPoolImpl::getResult( + GfxIndex queryIndex, GfxCount count, uint64_t* data) +{ + for (GfxIndex i = 0; i < count; i++) + { + float time = 0.0f; + cuEventSynchronize(m_events[i + queryIndex]); + cuEventElapsedTime(&time, m_startEvent, m_events[i + queryIndex]); + data[i] = (uint64_t)((double)time * 1000.0f); + } + return SLANG_OK; +} + +} // namespace cuda +#endif +} // namespace gfx -- cgit v1.2.3