Răsfoiți Sursa

Add PIX support to the tracer

Panagiotis Christopoulos Charitos 6 luni în urmă
părinte
comite
875e9d93bc
4 a modificat fișierele cu 65 adăugiri și 8 ștergeri
  1. 16 0
      AnKi/Util/CMakeLists.txt
  2. 23 0
      AnKi/Util/Tracer.cpp
  3. 18 0
      AnKi/Util/Tracer.h
  4. 8 8
      Docs/CodeStyle.md

+ 16 - 0
AnKi/Util/CMakeLists.txt

@@ -54,4 +54,20 @@ if(ANDROID)
 	set(libs ${libs} AnKiStreamlineAnnotate)
 endif()
 
+# PIX annotations
+if(DIRECTX AND ANKI_TRACE)
+	if(ARM)
+		set(cpu_arch "ARM64")
+	elseif(X86)
+		set(cpu_arch "x64")
+	else()
+		message(FATAL_ERROR "Unhandled case")
+	endif()
+
+	find_library(PIX_LIB WinPixEventRuntime HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../../ThirdParty/Pix/bin/${cpu_arch}")
+	set(libs ${libs} ${PIX_LIB})
+
+	include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../../ThirdParty/Pix/include/WinPixEventRuntime")
+endif()
+
 target_link_libraries(AnKiUtil ${libs})

+ 23 - 0
AnKi/Util/Tracer.cpp

@@ -10,6 +10,14 @@
 #if ANKI_OS_ANDROID
 #	include <ThirdParty/StreamlineAnnotate/streamline_annotate.h>
 #endif
+#if ANKI_GR_BACKEND_DIRECT3D
+#	if !defined(WIN32_LEAN_AND_MEAN)
+#		define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers.
+#	endif
+#	include <windows.h>
+#	define USE_PIX ANKI_TRACING_ENABLED
+#	include <pix3.h>
+#endif
 
 namespace anki {
 
@@ -106,6 +114,14 @@ TracerEventHandle Tracer::beginEvent([[maybe_unused]] const char* eventName)
 			ANNOTATE_COLOR(ANNOTATE_RED, eventName);
 		}
 #	endif
+
+#	if ANKI_GR_BACKEND_DIRECT3D
+		if(m_pixEnabled)
+		{
+			const U32 green = PIX_COLOR(0, 255, 0);
+			PIXBeginEvent(green, "%s", eventName);
+		}
+#	endif
 	}
 	else
 	{
@@ -129,6 +145,13 @@ void Tracer::endEvent(const char* eventName, TracerEventHandle event)
 	}
 #	endif
 
+#	if ANKI_GR_BACKEND_DIRECT3D
+	if(m_pixEnabled)
+	{
+		PIXEndEvent();
+	}
+#	endif
+
 	if(event.m_start == 0.0)
 	{
 		return;

+ 18 - 0
AnKi/Util/Tracer.h

@@ -114,6 +114,19 @@ public:
 	}
 #	endif
 
+#	if ANKI_GR_BACKEND_DIRECT3D
+	Bool getPixEnabled() const
+	{
+		return m_pixEnabled;
+	}
+
+	void setPixEnabled(Bool enabled)
+	{
+		ANKI_UTIL_LOGI("PIX CPU annotations %s", (enabled) ? "enabled" : "disabled");
+		m_pixEnabled = enabled;
+	}
+#	endif
+
 private:
 	static constexpr U32 kEventsPerChunk = 256;
 	static constexpr U32 kCountersPerChunk = 512;
@@ -129,7 +142,12 @@ private:
 	Mutex m_allThreadLocalMtx;
 
 	Bool m_enabled = false;
+#	if ANKI_OS_ANDROID
 	Bool m_streamlineEnabled = false;
+#	endif
+#	if ANKI_GR_BACKEND_DIRECT3D
+	Bool m_pixEnabled = true;
+#	endif
 
 	Tracer();
 

+ 8 - 8
Docs/CodeStyle.md

@@ -60,7 +60,7 @@ All **macros and defines** should be SCREAMING_SNAKE_CASE and they should have a
 
 All **template typedefs** should start with `T`. The rule doesn't apply in constant template arguments.
 
-	template<typename TSomething, typename TOther, U32 kSomeConst>
+	template<typename TSomeType, typename TSomeOtherType, U32 kSomeConst>
 
 All **function and method names** should form a sentence with at least one verb.
 
@@ -74,9 +74,7 @@ All **function and method names** should form a sentence with at least one verb.
 - All member variables have the `m_` prefix. That applies to classes and structs.
 - All global variables have the `g_` prefix.
 
-In HLSL there are more exceptions:
-
-- All groupshared variables use the `s_` prefix.
+Same rules apply to HLSL.
 
 **Variables that act as a measure for quantity** should have the `count` suffix. Not `num` or `numberOf` or similar.
 
@@ -117,13 +115,15 @@ C++ rules
 	using U32 = uint32_t;
 	using Func = void(*)(int, int);
 
-**Never use C-style casting**. Use static_cast, reinterpret_cast or const_cast for most cases and constructor-like cast for fudmental types.
+**Never use C-style casting**. Use static_cast, reinterpret_cast or const_cast. For for type conversions of fudmental types use constructor-like cast.
+
 
-	Derived* d = static_cast<Derived*>(base);
+	Derived* d = (Derived*)base;              // NO
+	Derived* d = static_cast<Derived*>(base); // YES!!
 
-	uint i = uint(1.1f); // uint is fudmental type
+	uint i = uint(1.1f); // uint is fudmental type and the expression does a type conversion, in that case use constructor-like cast
 
-**Always use `constexpr`** when applicable. Never use defines for constants.
+**Always use `constexpr`** as much as possible. Also, avoid using defines for constants.
 
 	constexpr uint kSomeConst = ...; // YES!!
 	#define SOME_CONST ...           // NO