From 1638d797eb53ee1a414e04b37b5681a028955df5 Mon Sep 17 00:00:00 2001 From: Marco Weber Date: Thu, 12 Nov 2015 12:20:02 +0000 Subject: [PATCH 1/3] Added invalidation of renderpipeline state cache. In case the program object gets re-used the cache can return invalid instances of the descriptor. --- src/renderer_mtl.mm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index 71a84741..60864141 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -1453,6 +1453,8 @@ namespace bgfx { namespace mtl m_processedUniforms = false; m_numPredefined = 0; + + m_renderPipelineStateCache.invalidate(); } UniformType::Enum convertMtlType(MTLDataType _type) From 21ccf8cb8c8b10f99ba9248ef8c21a15e3312c7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 12 Nov 2015 22:26:50 -0800 Subject: [PATCH 2/3] Integrated Remotery. --- 3rdparty/remotery/lib/Remotery.c | 37 ++++++++++++++++---------------- 3rdparty/remotery/lib/Remotery.h | 2 +- examples/common/entry/entry.cpp | 24 +++++++++++++++++++++ examples/common/entry/entry_p.h | 4 ++++ 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/3rdparty/remotery/lib/Remotery.c b/3rdparty/remotery/lib/Remotery.c index ff9dd088..8413af8b 100644 --- a/3rdparty/remotery/lib/Remotery.c +++ b/3rdparty/remotery/lib/Remotery.c @@ -508,7 +508,7 @@ static void WriteFence() // Get a shared value with acquire semantics, ensuring the read is complete // before the function returns. -static void* LoadAcquire(void* volatile const* addr) +void* LoadAcquire(void* volatile const* addr) { // Hardware fence is implicit on x86 so only need the compiler fence void* v = *addr; @@ -519,7 +519,7 @@ static void* LoadAcquire(void* volatile const* addr) // Set a shared value with release semantics, ensuring any prior writes // are complete before the value is set. -static void StoreRelease(void* volatile* addr, void* v) +void StoreRelease(void* volatile* addr, void* v) { // Hardware fence is implicit on x86 so only need the compiler fence WriteFence(); @@ -613,6 +613,7 @@ typedef struct VirtualMirrorBuffer static rmtError VirtualMirrorBuffer_Constructor(VirtualMirrorBuffer* buffer, rmtU32 size, int nb_attempts) { static const rmtU32 k_64 = 64 * 1024; + RMT_UNREFERENCED_PARAMETER(nb_attempts); #ifdef RMT_PLATFORM_LINUX char path[] = "/dev/shm/ring-buffer-XXXXXX"; @@ -785,7 +786,7 @@ static rmtError VirtualMirrorBuffer_Constructor(VirtualMirrorBuffer* buffer, rmt #endif // Map 2 contiguous pages - buffer->ptr = mmap(NULL, size * 2, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + buffer->ptr = (rmtU8*)mmap(NULL, size * 2, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (buffer->ptr == MAP_FAILED) { buffer->ptr = NULL; @@ -1173,8 +1174,6 @@ strstr_s (char *dest, rsize_t dmax, static errno_t strncat_s (char *dest, rsize_t dmax, const char *src, rsize_t slen) { - rsize_t orig_dmax; - char *orig_dest; const char *overlap_bumper; if (dest == NULL) { @@ -1198,8 +1197,6 @@ strncat_s (char *dest, rsize_t dmax, const char *src, rsize_t slen) } /* hold base of dest in case src was not copied */ - orig_dmax = dmax; - orig_dest = dest; if (dest < src) { overlap_bumper = src; @@ -1341,9 +1338,9 @@ static void itoahex_s( char *dest, rsize_t dmax, rmtS32 value ) // // All objects that require free-list-backed allocation need to inherit from this type. // -typedef struct ObjectLink +typedef struct ObjectLink_s { - struct ObjectLink* volatile next; + struct ObjectLink_s* volatile next; } ObjectLink; @@ -1676,11 +1673,12 @@ static void TCPSocket_Destructor(TCPSocket* tcp_socket) static rmtError TCPSocket_RunServer(TCPSocket* tcp_socket, rmtU16 port) { SOCKET s = INVALID_SOCKET; - struct sockaddr_in sin = { 0 }; + struct sockaddr_in sin; #ifdef RMT_PLATFORM_WINDOWS u_long nonblock = 1; #endif + memset(&sin, 0, sizeof(sin) ); assert(tcp_socket != NULL); // Try to create the socket @@ -3294,7 +3292,7 @@ enum SampleType typedef struct Sample { // Inherit so that samples can be quickly allocated - ObjectLink ObjectLink; + ObjectLink Link; enum SampleType type; @@ -3568,13 +3566,13 @@ static void SampleTree_Pop(SampleTree* tree, Sample* sample) static ObjectLink* FlattenSampleTree(Sample* sample, rmtU32* nb_samples) { Sample* child; - ObjectLink* cur_link = &sample->ObjectLink; + ObjectLink* cur_link = &sample->Link; assert(sample != NULL); assert(nb_samples != NULL); *nb_samples += 1; - sample->ObjectLink.next = (ObjectLink*)sample->first_child; + sample->Link.next = (ObjectLink*)sample->first_child; // Link all children together for (child = sample->first_child; child != NULL; child = child->next_sibling) @@ -3600,7 +3598,7 @@ static void FreeSampleTree(Sample* sample, ObjectAllocator* allocator) ObjectLink* last_link = FlattenSampleTree(sample, &nb_cleared_samples); // Release the complete sample memory range - if (sample->ObjectLink.next != NULL) + if (sample->Link.next != NULL) ObjectAllocator_FreeRange(allocator, sample, last_link, nb_cleared_samples); else ObjectAllocator_Free(allocator, sample); @@ -4272,18 +4270,18 @@ static void Remotery_DestroyThreadSamplers(Remotery* rmt) } -static void* CRTMalloc(void* mm_context, rmtU32 size) +static void* CRTMalloc(void* /*mm_context*/, rmtU32 size) { return malloc((size_t)size); } -static void CRTFree(void* mm_context, void* ptr) +static void CRTFree(void* /*mm_context*/, void* ptr) { free(ptr); } -static void* CRTRealloc(void* mm_context, void* ptr, rmtU32 size) +static void* CRTRealloc(void* /*mm_context*/, void* ptr, rmtU32 size) { return realloc(ptr, size); } @@ -4361,6 +4359,7 @@ RMT_API Remotery* _rmt_GetGlobalInstance(void) static void SetDebuggerThreadName(const char* name) { + RMT_UNREFERENCED_PARAMETER(name); #ifdef RMT_PLATFORM_WINDOWS THREADNAME_INFO info; info.dwType = 0x1000; @@ -4926,7 +4925,7 @@ static void D3D11_Destructor(D3D11* d3d11) typedef struct D3D11Timestamp { // Inherit so that timestamps can be quickly allocated - ObjectLink ObjectLink; + ObjectLink Link; // Pair of timestamp queries that wrap the sample ID3D11Query* query_start; @@ -5481,7 +5480,7 @@ static void OpenGL_Destructor(OpenGL* opengl) typedef struct OpenGLTimestamp { // Inherit so that timestamps can be quickly allocated - ObjectLink ObjectLink; + ObjectLink Link; // Pair of timestamp queries that wrap the sample GLuint queries[2]; diff --git a/3rdparty/remotery/lib/Remotery.h b/3rdparty/remotery/lib/Remotery.h index 45dece57..8582cf58 100644 --- a/3rdparty/remotery/lib/Remotery.h +++ b/3rdparty/remotery/lib/Remotery.h @@ -43,7 +43,7 @@ documented just below this comment. // Disable this to not include any bits of Remotery in your build -#define RMT_ENABLED +//#define RMT_ENABLED // Used by the Celtoys TinyCRT library (not released yet) //#define RMT_USE_TINYCRT diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index e3f7d76b..e7f82d7f 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -17,6 +17,12 @@ #include "cmd.h" #include "input.h" +#if ENTRY_CONFIG_PROFILER +# define RMT_ENABLED +#endif // ENTRY_CONFIG_PROFILER + +#include + extern "C" int _main_(int _argc, char** _argv); namespace entry @@ -24,6 +30,9 @@ namespace entry static uint32_t s_debug = BGFX_DEBUG_NONE; static uint32_t s_reset = BGFX_RESET_NONE; static bool s_exit = false; + + static Remotery* s_rmt = NULL; + static bx::FileReaderI* s_fileReader = NULL; static bx::FileWriterI* s_fileWriter = NULL; @@ -338,6 +347,15 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { //DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME); + if (BX_ENABLED(ENTRY_CONFIG_PROFILER) ) + { +// rmtSettings* settings = rmt_Settings(); + if (RMT_ERROR_NONE != rmt_CreateGlobalInstance(&s_rmt) ) + { + s_rmt = NULL; + } + } + #if BX_CONFIG_CRT_FILE_READER_WRITER s_fileReader = new bx::CrtFileReader; s_fileWriter = new bx::CrtFileWriter; @@ -370,6 +388,12 @@ BX_PRAGMA_DIAGNOSTIC_POP(); s_fileWriter = NULL; #endif // BX_CONFIG_CRT_FILE_READER_WRITER + if (BX_ENABLED(ENTRY_CONFIG_PROFILER) + && NULL != s_rmt) + { + rmt_DestroyGlobalInstance(s_rmt); + } + return result; } diff --git a/examples/common/entry/entry_p.h b/examples/common/entry/entry_p.h index e1a1a514..669bd729 100644 --- a/examples/common/entry/entry_p.h +++ b/examples/common/entry/entry_p.h @@ -48,6 +48,10 @@ # define ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR 1 #endif // ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR +#ifndef ENTRY_CONFIG_PROFILER +# define ENTRY_CONFIG_PROFILER 0 +#endif // ENTRY_CONFIG_PROFILER + #define ENTRY_IMPLEMENT_EVENT(_class, _type) \ _class(WindowHandle _handle) : Event(_type, _handle) {} From ded18236b9863429b6e1bd7ce8bbcbf952a4f31a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Thu, 12 Nov 2015 22:28:07 -0800 Subject: [PATCH 3/3] Updated .editorconfig. --- 3rdparty/.editorconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/3rdparty/.editorconfig b/3rdparty/.editorconfig index 9f05daea..3a32420d 100644 --- a/3rdparty/.editorconfig +++ b/3rdparty/.editorconfig @@ -7,3 +7,7 @@ indent_size = 2 [ocornut-imgui/*] indent_style = space indent_size = 4 + +[remotery/*] +indent_style = space +indent_size = 4