diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f7197b..5e6a3ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required (VERSION 3.15) # Options option (NRI_STATIC_LIBRARY "Build static library" OFF) +option (NRI_ENABLE_NVTX_SUPPORT "Annotations for NVIDIA Nsight Systems" OFF) # Options: backends option (NRI_ENABLE_NONE_SUPPORT "Enable NONE backend" ON) @@ -121,7 +122,10 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU") set (COMPILE_OPTIONS -msse4.1 -Wextra -Wno-missing-field-initializers) elseif (MSVC) - set (COMPILE_OPTIONS /W4 /WX /wd4324) + set (COMPILE_OPTIONS + /W4 /WX + /wd4324 # padding was added at the end of a structure because you specified an alignment specifier + ) else () message (WARNING "Unknown compiler!") endif () @@ -130,6 +134,9 @@ set (COMPILE_DEFINITIONS WIN32_LEAN_AND_MEAN NOMINMAX _CRT_SECURE_NO_WARNINGS) if (NRI_ENABLE_EXTERNAL_LIBRARIES) set (COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NRI_USE_EXT_LIBS=1) endif () +if (NRI_ENABLE_NVTX_SUPPORT) + set (COMPILE_DEFINITIONS ${COMPILE_DEFINITIONS} NRI_USE_NVTX=1) +endif () # External libs if (WIN32 AND NRI_ENABLE_EXTERNAL_LIBRARIES AND (NRI_ENABLE_D3D11_SUPPORT OR NRI_ENABLE_D3D12_SUPPORT)) @@ -150,7 +157,7 @@ if (NRI_ENABLE_NONE_SUPPORT) file (GLOB NONE_SOURCE "Source/NONE/*") source_group ("" FILES ${NONE_SOURCE}) add_library (NRI_NONE STATIC ${NONE_SOURCE}) - target_include_directories (NRI_NONE PRIVATE "Include" "Source/Shared") + target_include_directories (NRI_NONE PRIVATE "Include" "Source/Shared" "External") target_compile_definitions (NRI_NONE PRIVATE ${COMPILE_DEFINITIONS}) target_compile_options (NRI_NONE PRIVATE ${COMPILE_OPTIONS}) set_property (TARGET NRI_NONE PROPERTY FOLDER ${PROJECT_FOLDER}) @@ -271,7 +278,7 @@ endif () file (GLOB SHARED_SOURCE "Source/Shared/*.cpp" "Source/Shared/*.h" "Source/Shared/*.hpp") source_group ("" FILES ${SHARED_SOURCE}) add_library (NRI_Shared STATIC ${SHARED_SOURCE}) -target_include_directories (NRI_Shared PRIVATE "Include" "Source/Shared") +target_include_directories (NRI_Shared PRIVATE "Include" "Source/Shared" "External") target_compile_definitions (NRI_Shared PRIVATE ${COMPILE_DEFINITIONS}) target_compile_options (NRI_Shared PRIVATE ${COMPILE_OPTIONS}) set_property (TARGET NRI_Shared PROPERTY FOLDER ${PROJECT_FOLDER}) @@ -280,7 +287,7 @@ set_property (TARGET NRI_Shared PROPERTY FOLDER ${PROJECT_FOLDER}) file (GLOB NRI_VALIDATION_SOURCE "Source/Validation/*.cpp" "Source/Validation/*.h" "Source/Validation/*.hpp") source_group ("" FILES ${NRI_VALIDATION_SOURCE}) add_library (NRI_Validation STATIC ${NRI_VALIDATION_SOURCE}) -target_include_directories (NRI_Validation PRIVATE "Include" "Source/Shared") +target_include_directories (NRI_Validation PRIVATE "Include" "Source/Shared" "External") target_compile_definitions (NRI_Validation PRIVATE ${COMPILE_DEFINITIONS}) target_compile_options (NRI_Validation PRIVATE ${COMPILE_OPTIONS}) target_link_libraries (NRI_Validation PRIVATE NRI_Shared) @@ -312,7 +319,7 @@ else () endif () endif () -target_include_directories (${PROJECT_NAME} PRIVATE "Include" "Source/Shared" "External/vulkan/include") +target_include_directories (${PROJECT_NAME} PRIVATE "Include" "Source/Shared" "External" "External/vulkan/include") target_compile_definitions (${PROJECT_NAME} PRIVATE ${COMPILE_DEFINITIONS}) target_compile_options (${PROJECT_NAME} PRIVATE ${COMPILE_OPTIONS}) diff --git a/Include/Extensions/NRIHelper.h b/Include/Extensions/NRIHelper.h index 7ae76b3..4df1edc 100644 --- a/Include/Extensions/NRIHelper.h +++ b/Include/Extensions/NRIHelper.h @@ -200,4 +200,5 @@ static inline Nri(TextureBarrierDesc) NriFunc(TextureBarrierFromState)(NriRef(Te return *NriDeref(prevState); } + NriNamespaceEnd diff --git a/Include/NRI.h b/Include/NRI.h index d6e8a0d..c1da3be 100644 --- a/Include/NRI.h +++ b/Include/NRI.h @@ -25,7 +25,7 @@ Non-goals: #define NRI_VERSION_MAJOR 1 #define NRI_VERSION_MINOR 155 -#define NRI_VERSION_DATE "19 December 2024" +#define NRI_VERSION_DATE "20 December 2024" #include "NRIDescs.h" @@ -34,6 +34,13 @@ NriNamespaceBegin // Example: Result result = nriGetInterface(device, NRI_INTERFACE(CoreInterface), &coreInterface) NRI_API Nri(Result) NRI_CALL nriGetInterface(const NriRef(Device) device, const char* interfaceName, size_t interfaceSize, void* interfacePtr); +// Annotations for profiling tools: host (via NVTX) +// BGRA color can be constructed via "NriBgra" macro or "BGRA_UNUSED" constant +NRI_API void NRI_CALL nriBeginAnnotation(const char* name, uint32_t bgra); // start a named range +NRI_API void NRI_CALL nriEndAnnotation(); // end the last opened range +NRI_API void NRI_CALL nriEvent(const char* name, uint32_t bgra); // emit a simulateneous event +NRI_API void NRI_CALL nriSetThreadName(const char* name); // assign a name to the current thread + NriStruct(CoreInterface) { // Get const NriRef(DeviceDesc) (NRI_CALL *GetDeviceDesc) (const NriRef(Device) device); @@ -166,14 +173,17 @@ NriStruct(CoreInterface) { void (NRI_CALL *CmdEndQuery) (NriRef(CommandBuffer) commandBuffer, NriRef(QueryPool) queryPool, uint32_t offset); void (NRI_CALL *CmdCopyQueries) (NriRef(CommandBuffer) commandBuffer, const NriRef(QueryPool) queryPool, uint32_t offset, uint32_t num, NriRef(Buffer) dstBuffer, uint64_t dstOffset); - // Annotation - void (NRI_CALL *CmdBeginAnnotation) (NriRef(CommandBuffer) commandBuffer, const char* name); + // Annotations for profiling tools: device + void (NRI_CALL *CmdBeginAnnotation) (NriRef(CommandBuffer) commandBuffer, const char* name, uint32_t bgra); void (NRI_CALL *CmdEndAnnotation) (NriRef(CommandBuffer) commandBuffer); // } } Nri(Result) (NRI_CALL *EndCommandBuffer) (NriRef(CommandBuffer) commandBuffer); + // Query + void (NRI_CALL *ResetQueries) (NriRef(QueryPool) queryPool, uint32_t offset, uint32_t num); // on host + // Work submission and synchronization - void (NRI_CALL *QueueSubmit) (NriRef(CommandQueue) commandQueue, const NriRef(QueueSubmitDesc) queueSubmitDesc); // on device + void (NRI_CALL *QueueSubmit) (NriRef(CommandQueue) commandQueue, const NriRef(QueueSubmitDesc) queueSubmitDesc); // to device void (NRI_CALL *Wait) (NriRef(Fence) fence, uint64_t value); // on host uint64_t (NRI_CALL *GetFenceValue) (NriRef(Fence) fence); diff --git a/Include/NRIDescs.h b/Include/NRIDescs.h index 14a49be..7f2f53d 100644 --- a/Include/NRIDescs.h +++ b/Include/NRIDescs.h @@ -57,6 +57,7 @@ typedef uint16_t Nri(Dim_t); typedef uint32_t Nri(MemoryType); // Aliases +static const uint32_t NriConstant(BGRA_UNUSED) = 0; // only for "bgra" color for profiling static const uint32_t NriConstant(ALL_SAMPLES) = 0; // only for "sampleMask" static const uint32_t NriConstant(ONE_VIEWPORT) = 0; // only for "viewportNum" static const Nri(Dim_t) NriConstant(WHOLE_SIZE) = 0; // only for "Dim_t" and "size" diff --git a/Include/NRIMacro.h b/Include/NRIMacro.h index 7d319fd..42c343a 100644 --- a/Include/NRIMacro.h +++ b/Include/NRIMacro.h @@ -5,6 +5,7 @@ #undef ERROR #define NriBit(bit) (1 << (bit)) +#define NriBgra(r, g, b) (0xFF000000 | ((r) << 16) | ((g) << 8) | (b)) #define NRI_NAME_C(name) Nri##name #define NRI_FUNC_NAME_C(name) nri##name diff --git a/Source/Creation/Creation.cpp b/Source/Creation/Creation.cpp index 2be7b5c..0622e84 100644 --- a/Source/Creation/Creation.cpp +++ b/Source/Creation/Creation.cpp @@ -103,6 +103,76 @@ NRI_API Result NRI_CALL nriGetInterface(const Device& device, const char* interf return result; } +NRI_API void NRI_CALL nriBeginAnnotation(const char* name, uint32_t bgra) { + MaybeUnused(name, bgra); + +#if NRI_USE_NVTX + nvtxEventAttributes_t eventAttrib = {}; + eventAttrib.version = NVTX_VERSION; + eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; + eventAttrib.colorType = bgra == BGRA_UNUSED ? NVTX_COLOR_UNKNOWN : NVTX_COLOR_ARGB; + eventAttrib.color = bgra; + eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; + eventAttrib.message.ascii = name; + + nvtxRangePushEx(&eventAttrib); +#endif +} + +NRI_API void NRI_CALL nriEndAnnotation() { +#if NRI_USE_NVTX + nvtxRangePop(); +#endif +} + +NRI_API void NRI_CALL nriEvent(const char* name, uint32_t bgra) { + MaybeUnused(name, bgra); + +#if NRI_USE_NVTX + nvtxEventAttributes_t eventAttrib = {}; + eventAttrib.version = NVTX_VERSION; + eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; + eventAttrib.colorType = bgra == BGRA_UNUSED ? NVTX_COLOR_UNKNOWN : NVTX_COLOR_ARGB; + eventAttrib.color = bgra; + eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; + eventAttrib.message.ascii = name; + + nvtxMarkEx(&eventAttrib); +#endif +} + +#if NRI_USE_NVTX + +# if (defined __linux__) +# include +# elif (defined __APPLE__) +# include +# elif (defined __ANDROID__) +# include +# elif (defined _WIN64) +# include +# endif + +NRI_API void NRI_CALL nriSetThreadName(const char* name) { +# if (defined __linux__) + nvtxNameOsThreadA(syscall(SYS_gettid), name); +# elif (defined __APPLE__) + nvtxNameOsThreadA(syscall(SYS_thread_selfid), name); +# elif (defined __ANDROID__) + nvtxNameOsThreadA(gettid(), name); +# elif (defined _WIN64) + nvtxNameOsThreadA(GetCurrentThreadId(), name); +# endif +} + +#else + +NRI_API void NRI_CALL nriSetThreadName(const char* name) { + MaybeUnused(name); +} + +#endif + template Result FinalizeDeviceCreation(const T& deviceCreationDesc, DeviceBase& deviceImpl, Device*& device) { if (deviceCreationDesc.enableNRIValidation && deviceCreationDesc.graphicsAPI != GraphicsAPI::NONE) { @@ -113,9 +183,14 @@ Result FinalizeDeviceCreation(const T& deviceCreationDesc, DeviceBase& deviceImp } device = deviceVal; - } else + } else { device = (Device*)&deviceImpl; +#if NRI_USE_NVTX + nvtxInitialize(nullptr); // needed only to avoid stalls on the first use +#endif + } + return Result::SUCCESS; } diff --git a/Source/D3D11/CommandBufferD3D11.h b/Source/D3D11/CommandBufferD3D11.h index 9c4bc4f..f309634 100644 --- a/Source/D3D11/CommandBufferD3D11.h +++ b/Source/D3D11/CommandBufferD3D11.h @@ -83,7 +83,7 @@ struct CommandBufferD3D11 final : public CommandBufferHelper { void BeginQuery(QueryPool& queryPool, uint32_t offset); void EndQuery(QueryPool& queryPool, uint32_t offset); void CopyQueries(const QueryPool& queryPool, uint32_t offset, uint32_t num, Buffer& dstBuffer, uint64_t dstOffset); - void BeginAnnotation(const char* name); + void BeginAnnotation(const char* name, uint32_t bgra); void EndAnnotation(); private: diff --git a/Source/D3D11/CommandBufferD3D11.hpp b/Source/D3D11/CommandBufferD3D11.hpp index 8020c52..0b32c49 100644 --- a/Source/D3D11/CommandBufferD3D11.hpp +++ b/Source/D3D11/CommandBufferD3D11.hpp @@ -1,5 +1,7 @@ // © 2021 NVIDIA Corporation +#include + static constexpr uint64_t s_nullOffsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT] = {0}; uint8_t QueryLatestDeviceContext(ComPtr& in, ComPtr& out) { @@ -570,14 +572,22 @@ NRI_INLINE void CommandBufferD3D11::CopyQueries(const QueryPool& queryPool, uint ((BufferD3D11&)dstBuffer).AssignQueryPoolRange((QueryPoolD3D11*)&queryPool, offset, num, dstOffset); } -NRI_INLINE void CommandBufferD3D11::BeginAnnotation(const char* name) { - size_t len = strlen(name) + 1; - Scratch s = AllocateScratch(m_Device, wchar_t, len); - ConvertCharToWchar(name, s, len); - - m_Annotation->BeginEvent(s); +NRI_INLINE void CommandBufferD3D11::BeginAnnotation(const char* name, uint32_t bgra) { + /* + // TODO: unfortunately, just a few tools support "BeginEventInt" + if (m_Version >= 2) + PIXBeginEvent(m_DeferredContext, bgra, name); + else + */ + PIXBeginEvent(m_Annotation, bgra, name); } NRI_INLINE void CommandBufferD3D11::EndAnnotation() { - m_Annotation->EndEvent(); + /* + // TODO: unfortunately, just a few tools support "BeginEventInt" + if (m_Version >= 2) + PIXEndEvent(m_DeferredContext); + else + */ + PIXEndEvent(m_Annotation); } diff --git a/Source/D3D11/CommandBufferEmuD3D11.h b/Source/D3D11/CommandBufferEmuD3D11.h index 87b8a0f..2ba5ddd 100644 --- a/Source/D3D11/CommandBufferEmuD3D11.h +++ b/Source/D3D11/CommandBufferEmuD3D11.h @@ -74,7 +74,7 @@ struct CommandBufferEmuD3D11 final : public CommandBufferHelper { void BeginQuery(QueryPool& queryPool, uint32_t offset); void EndQuery(QueryPool& queryPool, uint32_t offset); void CopyQueries(const QueryPool& queryPool, uint32_t offset, uint32_t num, Buffer& dstBuffer, uint64_t dstOffset); - void BeginAnnotation(const char* name); + void BeginAnnotation(const char* name, uint32_t bgra); void EndAnnotation(); private: diff --git a/Source/D3D11/CommandBufferEmuD3D11.hpp b/Source/D3D11/CommandBufferEmuD3D11.hpp index 8fcdd29..d772733 100644 --- a/Source/D3D11/CommandBufferEmuD3D11.hpp +++ b/Source/D3D11/CommandBufferEmuD3D11.hpp @@ -461,7 +461,10 @@ void CommandBufferEmuD3D11::Submit() { const char* name; Read(m_PushBuffer, i, name, len); - commandBuffer.BeginAnnotation(name); + uint32_t bgra; + Read(m_PushBuffer, i, bgra); + + commandBuffer.BeginAnnotation(name, bgra); } break; case END_ANNOTATION: { commandBuffer.EndAnnotation(); @@ -717,11 +720,12 @@ NRI_INLINE void CommandBufferEmuD3D11::CopyQueries(const QueryPool& queryPool, u Push(m_PushBuffer, dstOffset); } -NRI_INLINE void CommandBufferEmuD3D11::BeginAnnotation(const char* name) { +NRI_INLINE void CommandBufferEmuD3D11::BeginAnnotation(const char* name, uint32_t bgra) { uint32_t len = (uint32_t)std::strlen(name) + 1; Push(m_PushBuffer, BEGIN_ANNOTATION); Push(m_PushBuffer, name, len); + Push(m_PushBuffer, name, bgra); } NRI_INLINE void CommandBufferEmuD3D11::EndAnnotation() { diff --git a/Source/D3D11/ImplD3D11.cpp b/Source/D3D11/ImplD3D11.cpp index 660ed19..77a8c84 100644 --- a/Source/D3D11/ImplD3D11.cpp +++ b/Source/D3D11/ImplD3D11.cpp @@ -415,8 +415,8 @@ static void NRI_CALL CmdEndQuery(CommandBuffer& commandBuffer, QueryPool& queryP ((CommandBufferD3D11&)commandBuffer).EndQuery(queryPool, offset); } -static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name) { - ((CommandBufferD3D11&)commandBuffer).BeginAnnotation(name); +static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name, uint32_t bgra) { + ((CommandBufferD3D11&)commandBuffer).BeginAnnotation(name, bgra); } static void NRI_CALL CmdEndAnnotation(CommandBuffer& commandBuffer) { @@ -458,6 +458,9 @@ static void NRI_CALL CmdCopyQueries(CommandBuffer& commandBuffer, const QueryPoo static void NRI_CALL CmdResetQueries(CommandBuffer&, QueryPool&, uint32_t, uint32_t) { } +static void NRI_CALL ResetQueries(QueryPool&, uint32_t, uint32_t) { +} + static void* NRI_CALL GetCommandBufferNativeObject(const CommandBuffer& commandBuffer) { if (!(&commandBuffer)) return nullptr; @@ -589,8 +592,8 @@ static void NRI_CALL EmuCmdEndQuery(CommandBuffer& commandBuffer, QueryPool& que ((CommandBufferEmuD3D11&)commandBuffer).EndQuery(queryPool, offset); } -static void NRI_CALL EmuCmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name) { - ((CommandBufferEmuD3D11&)commandBuffer).BeginAnnotation(name); +static void NRI_CALL EmuCmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name, uint32_t bgra) { + ((CommandBufferEmuD3D11&)commandBuffer).BeginAnnotation(name, bgra); } static void NRI_CALL EmuCmdEndAnnotation(CommandBuffer& commandBuffer) { @@ -756,6 +759,7 @@ Result DeviceD3D11::FillFunctionTable(CoreInterface& table) const { table.BindBufferMemory = ::BindBufferMemory; table.BindTextureMemory = ::BindTextureMemory; table.FreeMemory = ::FreeMemory; + table.ResetQueries = ::ResetQueries; table.QueueSubmit = ::QueueSubmit; table.Wait = ::Wait; table.GetFenceValue = ::GetFenceValue; diff --git a/Source/D3D12/CommandBufferD3D12.h b/Source/D3D12/CommandBufferD3D12.h index 3aaf5ca..1758a4e 100644 --- a/Source/D3D12/CommandBufferD3D12.h +++ b/Source/D3D12/CommandBufferD3D12.h @@ -93,7 +93,7 @@ struct CommandBufferD3D12 { void BeginQuery(QueryPool& queryPool, uint32_t offset); void EndQuery(QueryPool& queryPool, uint32_t offset); void CopyQueries(const QueryPool& queryPool, uint32_t offset, uint32_t num, Buffer& buffer, uint64_t alignedBufferOffset); - void BeginAnnotation(const char* name); + void BeginAnnotation(const char* name, uint32_t bgra); void EndAnnotation(); void BuildTopLevelAccelerationStructure(uint32_t instanceNum, const Buffer& buffer, uint64_t bufferOffset, AccelerationStructureBuildBits flags, AccelerationStructure& dst, Buffer& scratch, uint64_t scratchOffset); void BuildBottomLevelAccelerationStructure(uint32_t geometryObjectNum, const GeometryObject* geometryObjects, AccelerationStructureBuildBits flags, AccelerationStructure& dst, Buffer& scratch, uint64_t scratchOffset); diff --git a/Source/D3D12/CommandBufferD3D12.hpp b/Source/D3D12/CommandBufferD3D12.hpp index 31c6e20..3dd9df6 100644 --- a/Source/D3D12/CommandBufferD3D12.hpp +++ b/Source/D3D12/CommandBufferD3D12.hpp @@ -932,12 +932,8 @@ NRI_INLINE void CommandBufferD3D12::CopyQueries(const QueryPool& queryPool, uint m_GraphicsCommandList->ResolveQueryData(queryPoolD3D12, queryPoolD3D12.GetType(), offset, num, bufferD3D12, alignedBufferOffset); } -NRI_INLINE void CommandBufferD3D12::BeginAnnotation(const char* name) { - size_t len = strlen(name) + 1; - Scratch s = AllocateScratch(m_Device, wchar_t, len); - ConvertCharToWchar(name, s, len); - - PIXBeginEvent(m_GraphicsCommandList, PIX_COLOR_DEFAULT, s); +NRI_INLINE void CommandBufferD3D12::BeginAnnotation(const char* name, uint32_t bgra) { + PIXBeginEvent(m_GraphicsCommandList, bgra, name); } NRI_INLINE void CommandBufferD3D12::EndAnnotation() { diff --git a/Source/D3D12/ImplD3D12.cpp b/Source/D3D12/ImplD3D12.cpp index f1c6503..c35e4dd 100644 --- a/Source/D3D12/ImplD3D12.cpp +++ b/Source/D3D12/ImplD3D12.cpp @@ -251,8 +251,8 @@ static void NRI_CALL CmdEndQuery(CommandBuffer& commandBuffer, QueryPool& queryP ((CommandBufferD3D12&)commandBuffer).EndQuery(queryPool, offset); } -static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name) { - ((CommandBufferD3D12&)commandBuffer).BeginAnnotation(name); +static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name, uint32_t bgra) { + ((CommandBufferD3D12&)commandBuffer).BeginAnnotation(name, bgra); } static void NRI_CALL CmdEndAnnotation(CommandBuffer& commandBuffer) { @@ -294,6 +294,9 @@ static void NRI_CALL CmdCopyQueries(CommandBuffer& commandBuffer, const QueryPoo static void NRI_CALL CmdResetQueries(CommandBuffer&, QueryPool&, uint32_t, uint32_t) { } +static void NRI_CALL ResetQueries(QueryPool&, uint32_t, uint32_t) { +} + static void* NRI_CALL GetCommandBufferNativeObject(const CommandBuffer& commandBuffer) { if (!(&commandBuffer)) return nullptr; @@ -632,6 +635,7 @@ Result DeviceD3D12::FillFunctionTable(CoreInterface& table) const { table.CmdBeginAnnotation = ::CmdBeginAnnotation; table.CmdEndAnnotation = ::CmdEndAnnotation; table.EndCommandBuffer = ::EndCommandBuffer; + table.ResetQueries = ::ResetQueries; table.QueueSubmit = ::QueueSubmit; table.Wait = ::Wait; table.GetFenceValue = ::GetFenceValue; diff --git a/Source/NONE/ImplNONE.cpp b/Source/NONE/ImplNONE.cpp index 1f1e1bb..971ea08 100644 --- a/Source/NONE/ImplNONE.cpp +++ b/Source/NONE/ImplNONE.cpp @@ -512,7 +512,7 @@ static void NRI_CALL CmdEndQuery(CommandBuffer&, QueryPool&, uint32_t) { static void NRI_CALL CmdCopyQueries(CommandBuffer&, const QueryPool&, uint32_t, uint32_t, Buffer&, uint64_t) { } -static void NRI_CALL CmdBeginAnnotation(CommandBuffer&, const char*) { +static void NRI_CALL CmdBeginAnnotation(CommandBuffer&, const char*, uint32_t) { } static void NRI_CALL CmdEndAnnotation(CommandBuffer&) { @@ -522,6 +522,9 @@ static Result NRI_CALL EndCommandBuffer(CommandBuffer&) { return Result::SUCCESS; } +static void NRI_CALL ResetQueries(QueryPool&, uint32_t, uint32_t) { +} + static void NRI_CALL QueueSubmit(CommandQueue&, const QueueSubmitDesc&) { } @@ -699,6 +702,7 @@ Result DeviceNONE::FillFunctionTable(CoreInterface& table) const { table.CmdBeginAnnotation = ::CmdBeginAnnotation; table.CmdEndAnnotation = ::CmdEndAnnotation; table.EndCommandBuffer = ::EndCommandBuffer; + table.ResetQueries = ::ResetQueries; table.QueueSubmit = ::QueueSubmit; table.Wait = ::Wait; table.GetFenceValue = ::GetFenceValue; diff --git a/Source/Shared/SharedExternal.h b/Source/Shared/SharedExternal.h index 6d0bc4d..65df402 100644 --- a/Source/Shared/SharedExternal.h +++ b/Source/Shared/SharedExternal.h @@ -38,6 +38,11 @@ typedef nri::AllocationCallbacks AllocationCallbacks; #include "DeviceBase.h" #include "Lock.h" +// Annotations for NVIDIA Nsight Systems +#if NRI_USE_NVTX + #include "NVTX/c/include/nvtx3/nvToolsExt.h" +#endif + // Consts constexpr uint32_t NRI_NODE_MASK = 0x1; // mGPU is not planned constexpr uint32_t TIMEOUT_PRESENT = 1000; // 1 sec diff --git a/Source/VK/CommandBufferVK.h b/Source/VK/CommandBufferVK.h index cef2151..26a3273 100644 --- a/Source/VK/CommandBufferVK.h +++ b/Source/VK/CommandBufferVK.h @@ -63,7 +63,7 @@ struct CommandBufferVK { void DispatchIndirect(const Buffer& buffer, uint64_t offset); void BeginQuery(QueryPool& queryPool, uint32_t offset); void EndQuery(QueryPool& queryPool, uint32_t offset); - void BeginAnnotation(const char* name); + void BeginAnnotation(const char* name, uint32_t bgra); void EndAnnotation(); void ClearStorageBuffer(const ClearStorageBufferDesc& clearDesc); void ClearStorageTexture(const ClearStorageTextureDesc& clearDesc); diff --git a/Source/VK/CommandBufferVK.hpp b/Source/VK/CommandBufferVK.hpp index f19d75e..6608cc8 100644 --- a/Source/VK/CommandBufferVK.hpp +++ b/Source/VK/CommandBufferVK.hpp @@ -832,9 +832,13 @@ NRI_INLINE void CommandBufferVK::ResetQueries(QueryPool& queryPool, uint32_t off vk.CmdResetQueryPool(m_Handle, queryPoolImpl.GetHandle(), offset, num); } -NRI_INLINE void CommandBufferVK::BeginAnnotation(const char* name) { +NRI_INLINE void CommandBufferVK::BeginAnnotation(const char* name, uint32_t bgra) { VkDebugUtilsLabelEXT info = {VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT}; info.pLabelName = name; + info.color[0] = ((bgra >> 16) & 0xFF) / 255.0f; + info.color[1] = ((bgra >> 8) & 0xFF) / 255.0f; + info.color[2] = ((bgra >> 0) & 0xFF) / 255.0f; + info.color[3] = ((bgra >> 24) & 0xFF) / 255.0f; const auto& vk = m_Device.GetDispatchTable(); if (vk.CmdBeginDebugUtilsLabelEXT) diff --git a/Source/VK/DeviceVK.hpp b/Source/VK/DeviceVK.hpp index 083cc34..416d897 100644 --- a/Source/VK/DeviceVK.hpp +++ b/Source/VK/DeviceVK.hpp @@ -1577,6 +1577,7 @@ Result DeviceVK::ResolveDispatchTable(const Vector& desiredDeviceEx GET_DEVICE_CORE_OR_KHR_PROC(BindImageMemory2); GET_DEVICE_CORE_OR_KHR_PROC(GetDeviceBufferMemoryRequirements); GET_DEVICE_CORE_OR_KHR_PROC(GetDeviceImageMemoryRequirements); + GET_DEVICE_CORE_OR_KHR_PROC(ResetQueryPool); GET_DEVICE_CORE_OR_KHR_PROC(BeginCommandBuffer); GET_DEVICE_CORE_OR_KHR_PROC(CmdSetViewport); GET_DEVICE_CORE_OR_KHR_PROC(CmdSetScissor); diff --git a/Source/VK/DispatchTable.h b/Source/VK/DispatchTable.h index 855b97d..658781c 100644 --- a/Source/VK/DispatchTable.h +++ b/Source/VK/DispatchTable.h @@ -102,6 +102,7 @@ struct DispatchTable { VULKAN_FUNCTION(BindImageMemory2); VULKAN_FUNCTION(GetDeviceBufferMemoryRequirements); VULKAN_FUNCTION(GetDeviceImageMemoryRequirements); + VULKAN_FUNCTION(ResetQueryPool); VULKAN_FUNCTION(GetBufferDeviceAddress); VULKAN_FUNCTION(BeginCommandBuffer); VULKAN_FUNCTION(CmdSetViewport); diff --git a/Source/VK/ImplVK.cpp b/Source/VK/ImplVK.cpp index fccee4a..e40cd35 100644 --- a/Source/VK/ImplVK.cpp +++ b/Source/VK/ImplVK.cpp @@ -118,6 +118,10 @@ static Result NRI_CALL EndCommandBuffer(CommandBuffer& commandBuffer) { return ((CommandBufferVK&)commandBuffer).End(); } +static void NRI_CALL ResetQueries(QueryPool& queryPool, uint32_t offset, uint32_t num) { + ((QueryPoolVK&)queryPool).Reset(offset, num); +} + static void NRI_CALL CmdSetPipelineLayout(CommandBuffer& commandBuffer, const PipelineLayout& pipelineLayout) { ((CommandBufferVK&)commandBuffer).SetPipelineLayout(pipelineLayout); } @@ -230,8 +234,8 @@ static void NRI_CALL CmdEndQuery(CommandBuffer& commandBuffer, QueryPool& queryP ((CommandBufferVK&)commandBuffer).EndQuery(queryPool, offset); } -static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name) { - ((CommandBufferVK&)commandBuffer).BeginAnnotation(name); +static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name, uint32_t bgra) { + ((CommandBufferVK&)commandBuffer).BeginAnnotation(name, bgra); } static void NRI_CALL CmdEndAnnotation(CommandBuffer& commandBuffer) { @@ -619,6 +623,7 @@ Result DeviceVK::FillFunctionTable(CoreInterface& table) const { table.CmdBeginAnnotation = ::CmdBeginAnnotation; table.CmdEndAnnotation = ::CmdEndAnnotation; table.EndCommandBuffer = ::EndCommandBuffer; + table.ResetQueries = ::ResetQueries; table.QueueSubmit = ::QueueSubmit; table.Wait = ::Wait; table.GetFenceValue = ::GetFenceValue; diff --git a/Source/VK/QueryPoolVK.h b/Source/VK/QueryPoolVK.h index 2e969070..872f78a 100644 --- a/Source/VK/QueryPoolVK.h +++ b/Source/VK/QueryPoolVK.h @@ -33,6 +33,7 @@ struct QueryPoolVK { //================================================================================================================ void SetDebugName(const char* name); + void Reset(uint32_t offset, uint32_t num); inline uint32_t GetQuerySize() const { return m_QuerySize; diff --git a/Source/VK/QueryPoolVK.hpp b/Source/VK/QueryPoolVK.hpp index 5575fe7..dbc181f 100644 --- a/Source/VK/QueryPoolVK.hpp +++ b/Source/VK/QueryPoolVK.hpp @@ -50,3 +50,8 @@ Result QueryPoolVK::Create(const QueryPoolVKDesc& queryPoolDesc) { NRI_INLINE void QueryPoolVK::SetDebugName(const char* name) { m_Device.SetDebugNameToTrivialObject(VK_OBJECT_TYPE_QUERY_POOL, (uint64_t)m_Handle, name); } + +NRI_INLINE void QueryPoolVK::Reset(uint32_t offset, uint32_t num) { + const auto& vk = m_Device.GetDispatchTable(); + vk.ResetQueryPool(m_Device, m_Handle, offset, num); +} diff --git a/Source/Validation/CommandBufferVal.h b/Source/Validation/CommandBufferVal.h index dc5017f..320e3ca 100644 --- a/Source/Validation/CommandBufferVal.h +++ b/Source/Validation/CommandBufferVal.h @@ -11,15 +11,10 @@ struct PipelineLayoutVal; struct CommandBufferVal : public DeviceObjectVal { CommandBufferVal(DeviceVal& device, CommandBuffer* commandBuffer, bool isWrapped) : DeviceObjectVal(device, commandBuffer) - , m_ValidationCommands(device.GetStdAllocator()) , m_IsRecordingStarted(isWrapped) , m_IsWrapped(isWrapped) { } - inline const Vector& GetValidationCommands() const { - return m_ValidationCommands; - } - inline void* GetNativeObject() const { return GetCoreInterface().GetCommandBufferNativeObject(*GetImpl()); } @@ -76,7 +71,7 @@ struct CommandBufferVal : public DeviceObjectVal { void EndQuery(QueryPool& queryPool, uint32_t offset); void CopyQueries(const QueryPool& queryPool, uint32_t offset, uint32_t num, Buffer& dstBuffer, uint64_t dstOffset); void ResetQueries(QueryPool& queryPool, uint32_t offset, uint32_t num); - void BeginAnnotation(const char* name); + void BeginAnnotation(const char* name, uint32_t bgra); void EndAnnotation(); void BuildTopLevelAccelerationStructure(uint32_t instanceNum, const Buffer& buffer, uint64_t bufferOffset, AccelerationStructureBuildBits flags, AccelerationStructure& dst, Buffer& scratch, uint64_t scratchOffset); void BuildBottomLevelAccelerationStructure(uint32_t geometryObjectNum, const GeometryObject* geometryObjects, AccelerationStructureBuildBits flags, AccelerationStructure& dst, Buffer& scratch, uint64_t scratchOffset); @@ -90,11 +85,8 @@ struct CommandBufferVal : public DeviceObjectVal { void DrawMeshTasksIndirect(const Buffer& buffer, uint64_t offset, uint32_t drawNum, uint32_t stride, const Buffer* countBuffer, uint64_t countBufferOffset); private: - template - Command& AllocateValidationCommand(); void ValidateReadonlyDepthStencil(); - Vector m_ValidationCommands; std::array m_RenderTargets = {}; DescriptorVal* m_DepthStencil = nullptr; PipelineLayoutVal* m_PipelineLayout = nullptr; @@ -106,25 +98,4 @@ struct CommandBufferVal : public DeviceObjectVal { bool m_IsRenderPass = false; }; -enum class ValidationCommandType : uint32_t { - NONE, - BEGIN_QUERY, - END_QUERY, - RESET_QUERY, - MAX_NUM -}; - -struct ValidationCommandUseQuery { - ValidationCommandType type; - QueryPool* queryPool; - uint32_t queryPoolOffset; -}; - -struct ValidationCommandResetQuery { - ValidationCommandType type; - QueryPool* queryPool; - uint32_t queryPoolOffset; - uint32_t queryNum; -}; - } // namespace nri diff --git a/Source/Validation/CommandBufferVal.hpp b/Source/Validation/CommandBufferVal.hpp index 6398878..a22e926 100644 --- a/Source/Validation/CommandBufferVal.hpp +++ b/Source/Validation/CommandBufferVal.hpp @@ -44,8 +44,6 @@ NRI_INLINE Result CommandBufferVal::Begin(const DescriptorPool* descriptorPool) if (result == Result::SUCCESS) m_IsRecordingStarted = true; - m_ValidationCommands.clear(); - m_Pipeline = nullptr; m_PipelineLayout = nullptr; @@ -462,17 +460,10 @@ NRI_INLINE void CommandBufferVal::BeginQuery(QueryPool& queryPool, uint32_t offs RETURN_ON_FAILURE(&m_Device, m_IsRecordingStarted, ReturnVoid(), "the command buffer must be in the recording state"); RETURN_ON_FAILURE(&m_Device, queryPoolVal.GetQueryType() != QueryType::TIMESTAMP, ReturnVoid(), "'BeginQuery' is not supported for timestamp queries"); - if (!queryPoolVal.IsImported()) { + if (!queryPoolVal.IsImported()) RETURN_ON_FAILURE(&m_Device, offset < queryPoolVal.GetQueryNum(), ReturnVoid(), "'offset = %u' is out of range", offset); - ValidationCommandUseQuery& validationCommand = AllocateValidationCommand(); - validationCommand.type = ValidationCommandType::BEGIN_QUERY; - validationCommand.queryPool = const_cast(&queryPool); - validationCommand.queryPoolOffset = offset; - } - QueryPool* queryPoolImpl = NRI_GET_IMPL(QueryPool, &queryPool); - GetCoreInterface().CmdBeginQuery(*GetImpl(), *queryPoolImpl, offset); } @@ -481,17 +472,10 @@ NRI_INLINE void CommandBufferVal::EndQuery(QueryPool& queryPool, uint32_t offset RETURN_ON_FAILURE(&m_Device, m_IsRecordingStarted, ReturnVoid(), "the command buffer must be in the recording state"); - if (!queryPoolVal.IsImported()) { + if (!queryPoolVal.IsImported()) RETURN_ON_FAILURE(&m_Device, offset < queryPoolVal.GetQueryNum(), ReturnVoid(), "'offset = %u' is out of range", offset); - ValidationCommandUseQuery& validationCommand = AllocateValidationCommand(); - validationCommand.type = ValidationCommandType::END_QUERY; - validationCommand.queryPool = const_cast(&queryPool); - validationCommand.queryPoolOffset = offset; - } - QueryPool* queryPoolImpl = NRI_GET_IMPL(QueryPool, &queryPool); - GetCoreInterface().CmdEndQuery(*GetImpl(), *queryPoolImpl, offset); } @@ -514,26 +498,18 @@ NRI_INLINE void CommandBufferVal::ResetQueries(QueryPool& queryPool, uint32_t of RETURN_ON_FAILURE(&m_Device, !m_IsRenderPass, ReturnVoid(), "must be called outside of 'CmdBeginRendering/CmdEndRendering'"); QueryPoolVal& queryPoolVal = (QueryPoolVal&)queryPool; - if (!queryPoolVal.IsImported()) { + if (!queryPoolVal.IsImported()) RETURN_ON_FAILURE(&m_Device, offset + num <= queryPoolVal.GetQueryNum(), ReturnVoid(), "'offset + num = %u' is out of range", offset + num); - ValidationCommandResetQuery& validationCommand = AllocateValidationCommand(); - validationCommand.type = ValidationCommandType::RESET_QUERY; - validationCommand.queryPool = const_cast(&queryPool); - validationCommand.queryPoolOffset = offset; - validationCommand.queryNum = num; - } - QueryPool* queryPoolImpl = NRI_GET_IMPL(QueryPool, &queryPool); - GetCoreInterface().CmdResetQueries(*GetImpl(), *queryPoolImpl, offset, num); } -NRI_INLINE void CommandBufferVal::BeginAnnotation(const char* name) { +NRI_INLINE void CommandBufferVal::BeginAnnotation(const char* name, uint32_t bgra) { RETURN_ON_FAILURE(&m_Device, m_IsRecordingStarted, ReturnVoid(), "the command buffer must be in the recording state"); m_AnnotationStack++; - GetCoreInterface().CmdBeginAnnotation(*GetImpl(), name); + GetCoreInterface().CmdBeginAnnotation(*GetImpl(), name, bgra); } NRI_INLINE void CommandBufferVal::EndAnnotation() { @@ -709,18 +685,3 @@ NRI_INLINE void CommandBufferVal::ValidateReadonlyDepthStencil() { REPORT_WARNING(&m_Device, "Stencil is read-only, but the pipeline writes to stencil. Writing happens only in VK!"); } } - -template -Command& CommandBufferVal::AllocateValidationCommand() { - const size_t commandSize = sizeof(Command); - const size_t newSize = m_ValidationCommands.size() + commandSize; - const size_t capacity = m_ValidationCommands.capacity(); - - if (newSize > capacity) - m_ValidationCommands.reserve(std::max(capacity + (capacity >> 1), newSize)); - - const size_t offset = m_ValidationCommands.size(); - m_ValidationCommands.resize(newSize); - - return *(Command*)(m_ValidationCommands.data() + offset); -} diff --git a/Source/Validation/CommandQueueVal.h b/Source/Validation/CommandQueueVal.h index cbc9266..6af2a80 100644 --- a/Source/Validation/CommandQueueVal.h +++ b/Source/Validation/CommandQueueVal.h @@ -20,12 +20,6 @@ struct CommandQueueVal : public DeviceObjectVal { Result WaitForIdle(); Result UploadData(const TextureUploadDesc* textureUploadDescs, uint32_t textureUploadDescNum, const BufferUploadDesc* bufferUploadDescs, uint32_t bufferUploadDescNum); - -private: - void ProcessValidationCommands(const CommandBufferVal* const* commandBuffers, uint32_t commandBufferNum); - void ProcessValidationCommandBeginQuery(const uint8_t*& begin, const uint8_t* end); - void ProcessValidationCommandEndQuery(const uint8_t*& begin, const uint8_t* end); - void ProcessValidationCommandResetQuery(const uint8_t*& begin, const uint8_t* end); }; } // namespace nri diff --git a/Source/Validation/CommandQueueVal.hpp b/Source/Validation/CommandQueueVal.hpp index 4489b90..a9deb53 100644 --- a/Source/Validation/CommandQueueVal.hpp +++ b/Source/Validation/CommandQueueVal.hpp @@ -53,8 +53,6 @@ NRI_INLINE void CommandQueueVal::SetDebugName(const char* name) { } NRI_INLINE void CommandQueueVal::Submit(const QueueSubmitDesc& queueSubmitDesc, const SwapChain* swapChain) { - ProcessValidationCommands((const CommandBufferVal* const*)queueSubmitDesc.commandBuffers, queueSubmitDesc.commandBufferNum); - auto queueSubmitDescImpl = queueSubmitDesc; Scratch waitFences = AllocateScratch(m_Device, FenceSubmitDesc, queueSubmitDesc.waitFenceNum); @@ -115,81 +113,3 @@ NRI_INLINE Result CommandQueueVal::UploadData(const TextureUploadDesc* textureUp NRI_INLINE Result CommandQueueVal::WaitForIdle() { return GetHelperInterface().WaitForIdle(*GetImpl()); } - -template -const Command* ReadCommand(const uint8_t*& begin, const uint8_t* end) { - if (begin + sizeof(Command) <= end) { - const Command* command = (const Command*)begin; - begin += sizeof(Command); - return command; - } - return nullptr; -} - -void CommandQueueVal::ProcessValidationCommandBeginQuery(const uint8_t*& begin, const uint8_t* end) { - const ValidationCommandUseQuery* command = ReadCommand(begin, end); - CHECK(command != nullptr, "can't parse command"); - CHECK(command->queryPool != nullptr, "query pool is invalid"); - - QueryPoolVal& queryPool = *(QueryPoolVal*)command->queryPool; - const bool used = queryPool.SetQueryState(command->queryPoolOffset, true); - - if (used) - REPORT_ERROR(&m_Device, "QueryPool='%s' (offset=%u) must be reset before use", queryPool.GetDebugName(), command->queryPoolOffset); -} - -void CommandQueueVal::ProcessValidationCommandEndQuery(const uint8_t*& begin, const uint8_t* end) { - const ValidationCommandUseQuery* command = ReadCommand(begin, end); - CHECK(command != nullptr, "can't parse command"); - CHECK(command->queryPool != nullptr, "query pool is invalid"); - - QueryPoolVal& queryPool = *(QueryPoolVal*)command->queryPool; - const bool used = queryPool.SetQueryState(command->queryPoolOffset, true); - - if (queryPool.GetQueryType() == QueryType::TIMESTAMP) { - if (used) - REPORT_ERROR(&m_Device, "QueryPool='%s' (offset=%u) must be reset before use", queryPool.GetDebugName(), command->queryPoolOffset); - } else { - if (!used) - REPORT_ERROR(&m_Device, "QueryPool='%s' (offset=%u) is not in active state", queryPool.GetDebugName(), command->queryPoolOffset); - } -} - -void CommandQueueVal::ProcessValidationCommandResetQuery(const uint8_t*& begin, const uint8_t* end) { - const ValidationCommandResetQuery* command = ReadCommand(begin, end); - CHECK(command != nullptr, "can't parse command"); - CHECK(command->queryPool != nullptr, "query pool is invalid"); - - QueryPoolVal& queryPool = *(QueryPoolVal*)command->queryPool; - queryPool.ResetQueries(command->queryPoolOffset, command->queryNum); -} - -void CommandQueueVal::ProcessValidationCommands(const CommandBufferVal* const* commandBuffers, uint32_t commandBufferNum) { - ExclusiveScope lockScope(m_Device.GetLock()); - - using ProcessValidationCommandMethod = void (CommandQueueVal::*)(const uint8_t*& begin, const uint8_t* end); - - constexpr ProcessValidationCommandMethod table[] = { - &CommandQueueVal::ProcessValidationCommandBeginQuery, // ValidationCommandType::BEGIN_QUERY - &CommandQueueVal::ProcessValidationCommandEndQuery, // ValidationCommandType::END_QUERY - &CommandQueueVal::ProcessValidationCommandResetQuery // ValidationCommandType::RESET_QUERY - }; - - for (size_t i = 0; i < commandBufferNum; i++) { - const Vector& buffer = commandBuffers[i]->GetValidationCommands(); - const uint8_t* begin = buffer.data(); - const uint8_t* end = buffer.data() + buffer.size(); - - while (begin != end) { - const ValidationCommandType type = *(const ValidationCommandType*)begin; - - if (type == ValidationCommandType::NONE || type >= ValidationCommandType::MAX_NUM) { - REPORT_ERROR(&m_Device, "Invalid validation command: %u", (uint32_t)type); - break; - } - - const ProcessValidationCommandMethod method = table[(size_t)type - 1]; - (this->*method)(begin, end); - } - } -} diff --git a/Source/Validation/ImplVal.cpp b/Source/Validation/ImplVal.cpp index cbfdc3e..6d94745 100644 --- a/Source/Validation/ImplVal.cpp +++ b/Source/Validation/ImplVal.cpp @@ -210,8 +210,8 @@ static void NRI_CALL CmdEndQuery(CommandBuffer& commandBuffer, QueryPool& queryP ((CommandBufferVal&)commandBuffer).EndQuery(queryPool, offset); } -static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name) { - ((CommandBufferVal&)commandBuffer).BeginAnnotation(name); +static void NRI_CALL CmdBeginAnnotation(CommandBuffer& commandBuffer, const char* name, uint32_t bgra) { + ((CommandBufferVal&)commandBuffer).BeginAnnotation(name, bgra); } static void NRI_CALL CmdEndAnnotation(CommandBuffer& commandBuffer) { @@ -265,6 +265,10 @@ static void NRI_CALL SetCommandQueueDebugName(CommandQueue& commandQueue, const ((CommandQueueVal&)commandQueue).SetDebugName(name); } +static void NRI_CALL ResetQueries(QueryPool& queryPool, uint32_t offset, uint32_t num) { + ((QueryPoolVal&)queryPool).ResetQueries(offset, num); +} + static void NRI_CALL QueueSubmit(CommandQueue& commandQueue, const QueueSubmitDesc& queueSubmitDesc) { ((CommandQueueVal&)commandQueue).Submit(queueSubmitDesc, nullptr); } @@ -626,6 +630,7 @@ Result DeviceVal::FillFunctionTable(CoreInterface& table) const { table.CmdBeginAnnotation = ::CmdBeginAnnotation; table.CmdEndAnnotation = ::CmdEndAnnotation; table.EndCommandBuffer = ::EndCommandBuffer; + table.ResetQueries = ::ResetQueries; table.QueueSubmit = ::QueueSubmit; table.Wait = ::Wait; table.GetFenceValue = ::GetFenceValue; diff --git a/Source/Validation/QueryPoolVal.h b/Source/Validation/QueryPoolVal.h index ad5799a..a841e87 100644 --- a/Source/Validation/QueryPoolVal.h +++ b/Source/Validation/QueryPoolVal.h @@ -7,8 +7,7 @@ namespace nri { struct QueryPoolVal : public DeviceObjectVal { QueryPoolVal(DeviceVal& device, QueryPool* queryPool, QueryType queryType, uint32_t queryNum); - bool SetQueryState(uint32_t offset, bool state); - void ResetQueries(uint32_t offset, uint32_t number); + void ResetQueries(uint32_t offset, uint32_t num); inline uint32_t GetQueryNum() const { return m_QueryNum; @@ -30,7 +29,6 @@ struct QueryPoolVal : public DeviceObjectVal { uint32_t GetQuerySize() const; private: - Vector m_DeviceState; uint32_t m_QueryNum; QueryType m_QueryType; }; diff --git a/Source/Validation/QueryPoolVal.hpp b/Source/Validation/QueryPoolVal.hpp index 02f0ba8..f769369 100644 --- a/Source/Validation/QueryPoolVal.hpp +++ b/Source/Validation/QueryPoolVal.hpp @@ -2,31 +2,12 @@ QueryPoolVal::QueryPoolVal(DeviceVal& device, QueryPool* queryPool, QueryType queryType, uint32_t queryNum) : DeviceObjectVal(device, queryPool) - , m_DeviceState(device.GetStdAllocator()) , m_QueryType(queryType) { m_QueryNum = queryNum; - - if (queryNum != 0) { - const size_t batchNum = std::max(queryNum >> 6, 1u); - m_DeviceState.resize(batchNum, 0); - } -} - -bool QueryPoolVal::SetQueryState(uint32_t offset, bool state) { - const size_t batchIndex = offset >> 6; - const uint64_t batchValue = m_DeviceState[batchIndex]; - const size_t bitIndex = 1ull << (offset & 63); - const uint64_t maskBitValue = ~bitIndex; - const uint64_t bitValue = state ? bitIndex : 0; - - m_DeviceState[batchIndex] = (batchValue & maskBitValue) | bitValue; - - return batchValue & bitIndex; } -void QueryPoolVal::ResetQueries(uint32_t offset, uint32_t number) { - for (uint32_t i = 0; i < number; i++) - SetQueryState(offset + i, false); +void QueryPoolVal::ResetQueries(uint32_t offset, uint32_t num) { + GetCoreInterface().ResetQueries(*GetImpl(), offset, num); } NRI_INLINE void QueryPoolVal::SetDebugName(const char* name) {