diff options
Diffstat (limited to '3rdparty/bgfx/src')
-rw-r--r-- | 3rdparty/bgfx/src/bgfx.cpp | 102 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/bgfx_p.h | 53 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/config.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_eagl.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_eagl.mm | 6 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_egl.cpp | 5 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_egl.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_glx.cpp | 5 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_glx.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_nsgl.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_nsgl.mm | 14 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_ppapi.cpp | 6 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_ppapi.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_wgl.cpp | 5 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/glcontext_wgl.h | 2 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/image.cpp | 58 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_d3d11.cpp | 125 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_d3d9.cpp | 51 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_gl.cpp | 113 | ||||
-rw-r--r-- | 3rdparty/bgfx/src/renderer_gl.h | 2 |
20 files changed, 347 insertions, 212 deletions
diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp index 3a353942cc5..677d7e26a25 100644 --- a/3rdparty/bgfx/src/bgfx.cpp +++ b/3rdparty/bgfx/src/bgfx.cpp @@ -485,12 +485,12 @@ namespace bgfx memcpy(vertex, vert, sizeof(vert) ); vertex += 4; - indices[0] = startVertex+0; - indices[1] = startVertex+1; - indices[2] = startVertex+2; - indices[3] = startVertex+2; - indices[4] = startVertex+3; - indices[5] = startVertex+0; + indices[0] = uint16_t(startVertex+0); + indices[1] = uint16_t(startVertex+1); + indices[2] = uint16_t(startVertex+2); + indices[3] = uint16_t(startVertex+2); + indices[4] = uint16_t(startVertex+3); + indices[5] = uint16_t(startVertex+0); startVertex += 4; indices += 6; @@ -819,6 +819,10 @@ namespace bgfx BGFX_CHECK_RENDER_THREAD(); if (s_ctx->renderFrame() ) { + Context* ctx = s_ctx; + ctx->gameSemWait(); + s_ctx = NULL; + ctx->renderSemPost(); return RenderFrame::Exiting; } @@ -969,7 +973,7 @@ namespace bgfx for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii) { - m_viewRemap[ii] = ii; + m_viewRemap[ii] = uint8_t(ii); } memset(m_fb, 0xff, sizeof(m_fb) ); @@ -1054,15 +1058,18 @@ namespace bgfx m_declRef.shutdown(m_vertexDeclHandle); #if BGFX_CONFIG_MULTITHREADED + // Render thread shutdown sequence. + renderSemWait(); // Wait for previous frame. + gameSemPost(); // OK to set context to NULL. + // s_ctx is NULL here. + renderSemWait(); // In RenderFrame::Exiting state. + if (m_thread.isRunning() ) { m_thread.shutdown(); } #endif // BGFX_CONFIG_MULTITHREADED - s_ctx = NULL; // Can't be used by renderFrame at this point. - renderSemWait(); - m_submit->destroy(); m_render->destroy(); @@ -1204,7 +1211,10 @@ namespace bgfx freeAllHandles(m_submit); m_submit->resetFreeHandles(); - m_submit->m_textVideoMem->resize(m_render->m_textVideoMem->m_small, m_resolution.m_width, m_resolution.m_height); + m_submit->m_textVideoMem->resize(m_render->m_textVideoMem->m_small + , m_resolution.m_width + , m_resolution.m_height + ); } bool Context::renderFrame() @@ -2099,18 +2109,41 @@ again: return mem; } - const Memory* makeRef(const void* _data, uint32_t _size) + struct MemoryRef { - Memory* mem = (Memory*)BX_ALLOC(g_allocator, sizeof(Memory) ); - mem->size = _size; - mem->data = (uint8_t*)_data; - return mem; + Memory mem; + ReleaseFn releaseFn; + void* userData; + }; + + const Memory* makeRef(const void* _data, uint32_t _size, ReleaseFn _releaseFn, void* _userData) + { + MemoryRef* memRef = (MemoryRef*)BX_ALLOC(g_allocator, sizeof(MemoryRef) ); + memRef->mem.size = _size; + memRef->mem.data = (uint8_t*)_data; + memRef->releaseFn = _releaseFn; + memRef->userData = _userData; + return &memRef->mem; + } + + bool isMemoryRef(const Memory* _mem) + { + return _mem->data != (uint8_t*)_mem + sizeof(Memory); } void release(const Memory* _mem) { BX_CHECK(NULL != _mem, "_mem can't be NULL"); - BX_FREE(g_allocator, const_cast<Memory*>(_mem) ); + Memory* mem = const_cast<Memory*>(_mem); + if (isMemoryRef(mem) ) + { + MemoryRef* memRef = reinterpret_cast<MemoryRef*>(mem); + if (NULL != memRef->releaseFn) + { + memRef->releaseFn(mem->data, memRef->userData); + } + } + BX_FREE(g_allocator, mem); } void setDebug(uint32_t _debug) @@ -2350,15 +2383,15 @@ again: { const ImageBlockInfo& blockInfo = getBlockInfo(_format); const uint8_t bpp = blockInfo.bitsPerPixel; - const uint32_t blockWidth = blockInfo.blockWidth; - const uint32_t blockHeight = blockInfo.blockHeight; - const uint32_t minBlockX = blockInfo.minBlockX; - const uint32_t minBlockY = blockInfo.minBlockY; + const uint16_t blockWidth = blockInfo.blockWidth; + const uint16_t blockHeight = blockInfo.blockHeight; + const uint16_t minBlockX = blockInfo.minBlockX; + const uint16_t minBlockY = blockInfo.minBlockY; - _width = bx::uint32_max(blockWidth * minBlockX, ( (_width + blockWidth - 1) / blockWidth)*blockWidth); - _height = bx::uint32_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight); - _depth = bx::uint32_max(1, _depth); - _numMips = bx::uint32_max(1, _numMips); + _width = bx::uint16_max(blockWidth * minBlockX, ( (_width + blockWidth - 1) / blockWidth)*blockWidth); + _height = bx::uint16_max(blockHeight * minBlockY, ( (_height + blockHeight - 1) / blockHeight)*blockHeight); + _depth = bx::uint16_max(1, _depth); + _numMips = uint8_t(bx::uint16_max(1, _numMips) ); uint32_t width = _width; uint32_t height = _height; @@ -2400,7 +2433,7 @@ again: { BGFX_CHECK_MAIN_THREAD(); - _numMips = bx::uint32_max(1, _numMips); + _numMips = uint8_t(bx::uint32_max(1, _numMips) ); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) @@ -2441,7 +2474,7 @@ again: BGFX_CHECK_MAIN_THREAD(); BX_CHECK(0 != (g_caps.supported & BGFX_CAPS_TEXTURE_3D), "Texture3D is not supported! Use bgfx::getCaps to check backend renderer capabilities."); - _numMips = bx::uint32_max(1, _numMips); + _numMips = uint8_t(bx::uint32_max(1, _numMips) ); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) @@ -2481,7 +2514,7 @@ again: { BGFX_CHECK_MAIN_THREAD(); - _numMips = bx::uint32_max(1, _numMips); + _numMips = uint8_t(bx::uint32_max(1, _numMips) ); if (BX_ENABLED(BGFX_CONFIG_DEBUG) && NULL != _mem) @@ -2621,10 +2654,10 @@ again: { BGFX_CHECK_MAIN_THREAD(); - const uint8_t rr = _rgba>>24; - const uint8_t gg = _rgba>>16; - const uint8_t bb = _rgba>> 8; - const uint8_t aa = _rgba>> 0; + const uint8_t rr = uint8_t(_rgba>>24); + const uint8_t gg = uint8_t(_rgba>>16); + const uint8_t bb = uint8_t(_rgba>> 8); + const uint8_t aa = uint8_t(_rgba>> 0); float rgba[4] = { @@ -3073,6 +3106,11 @@ BGFX_C_API const bgfx_memory_t* bgfx_make_ref(const void* _data, uint32_t _size) return (const bgfx_memory_t*)bgfx::makeRef(_data, _size); } +BGFX_C_API const bgfx_memory_t* bgfx_make_ref_release(const void* _data, uint32_t _size, bgfx_release_fn_t _releaseFn, void* _userData) +{ + return (const bgfx_memory_t*)bgfx::makeRef(_data, _size, _releaseFn, _userData); +} + BGFX_C_API void bgfx_set_debug(uint32_t _debug) { bgfx::setDebug(_debug); diff --git a/3rdparty/bgfx/src/bgfx_p.h b/3rdparty/bgfx/src/bgfx_p.h index efc413a62da..63a3032529c 100644 --- a/3rdparty/bgfx/src/bgfx_p.h +++ b/3rdparty/bgfx/src/bgfx_p.h @@ -379,7 +379,7 @@ namespace bgfx BX_FREE(g_allocator, m_mem); } - void resize(bool _small = false, uint16_t _width = BGFX_DEFAULT_WIDTH, uint16_t _height = BGFX_DEFAULT_HEIGHT) + void resize(bool _small = false, uint32_t _width = BGFX_DEFAULT_WIDTH, uint32_t _height = BGFX_DEFAULT_HEIGHT) { uint32_t width = bx::uint32_max(1, _width/8); uint32_t height = bx::uint32_max(1, _height/(_small ? 8 : 16) ); @@ -389,8 +389,8 @@ namespace bgfx || m_height != height || m_small != _small) { - m_small = _small; - m_width = (uint16_t)width; + m_small = _small; + m_width = (uint16_t)width; m_height = (uint16_t)height; uint32_t size = m_size; @@ -701,7 +701,7 @@ namespace bgfx void operator=(const CommandBuffer&); }; -#define SORT_KEY_RENDER_DRAW (UINT64_C(1)<<0x2b) +#define SORT_KEY_RENDER_DRAW (UINT64_C(1)<<0x36) #define SORT_KEY_VIEW_SHIFT UINT8_C(0x37) #define SORT_KEY_VIEW_MASK ( (uint64_t(BGFX_CONFIG_MAX_VIEWS-1) )<<SORT_KEY_VIEW_SHIFT) @@ -714,16 +714,16 @@ namespace bgfx { // | 3 2 1 0| // |fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210| - // | vvvvvvvvsssssssssssdttpppppppppdddddddddddddddddddddddddddddddd| - // | ^ ^^ ^ ^ ^| - // | | || | | || - // | view-+ seq-+| +-trans +-program depth-+| - // | +-draw | + // | vvvvvvvvdsssssssssssttpppppppppdddddddddddddddddddddddddddddddd| + // | ^^ ^ ^ ^ ^| + // | || | | | || + // | view-+| seq-+ +-trans +-program depth-+| + // | +-draw | const uint64_t depth = m_depth; const uint64_t program = uint64_t(m_program)<<0x20; const uint64_t trans = uint64_t(m_trans )<<0x29; - const uint64_t seq = uint64_t(m_seq )<<0x2c; + const uint64_t seq = uint64_t(m_seq )<<0x2b; const uint64_t view = uint64_t(m_view )<<SORT_KEY_VIEW_SHIFT; const uint64_t key = depth|program|trans|SORT_KEY_RENDER_DRAW|seq|view; return key; @@ -733,14 +733,14 @@ namespace bgfx { // | 3 2 1 0| // |fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210| - // | vvvvvvvvsssssssssssdppppppppp | - // | ^ ^^ ^ | - // | | || | | - // | view-+ seq-+| +-program | - // | +-draw | + // | vvvvvvvvdsssssssssssppppppppp | + // | ^^ ^ ^ | + // | || | | | + // | view-+| seq-+ +-program | + // | +-draw | const uint64_t program = uint64_t(m_program)<<0x22; - const uint64_t seq = uint64_t(m_seq )<<0x2c; + const uint64_t seq = uint64_t(m_seq )<<0x2b; const uint64_t view = uint64_t(m_view )<<SORT_KEY_VIEW_SHIFT; const uint64_t key = program|seq|view; return key; @@ -1418,7 +1418,7 @@ namespace bgfx { m_draw.m_instanceDataOffset = _idb->offset; m_draw.m_instanceDataStride = _idb->stride; - m_draw.m_numInstances = bx::uint32_min(_idb->num, _num); + m_draw.m_numInstances = uint16_t(bx::uint32_min(_idb->num, _num) ); m_draw.m_instanceDataBuffer = _idb->handle; BX_FREE(g_allocator, const_cast<InstanceDataBuffer*>(_idb) ); } @@ -1427,7 +1427,7 @@ namespace bgfx { m_draw.m_instanceDataOffset = _startVertex * _stride; m_draw.m_instanceDataStride = _stride; - m_draw.m_numInstances = _num; + m_draw.m_numInstances = uint16_t(_num); m_draw.m_instanceDataBuffer = _handle; } @@ -1768,9 +1768,9 @@ namespace bgfx if (0 < m_free.size() ) { - Free free = m_free.front(); + Free freeBlock = m_free.front(); m_free.pop_front(); - return free.m_ptr; + return freeBlock.m_ptr; } return 0; @@ -1934,11 +1934,10 @@ namespace bgfx { } - static int32_t renderThread(void* _userData) + static int32_t renderThread(void* /*_userData*/) { BX_TRACE("render thread start"); - Context* ctx = (Context*)_userData; - while (!ctx->renderFrame() ) {}; + while (RenderFrame::Exiting != bgfx::renderFrame() ) {}; BX_TRACE("render thread exit"); return EXIT_SUCCESS; } @@ -3069,10 +3068,10 @@ namespace bgfx { Clear& clear = m_clear[_id]; clear.m_flags = _flags; - clear.m_index[0] = _rgba>>24; - clear.m_index[1] = _rgba>>16; - clear.m_index[2] = _rgba>> 8; - clear.m_index[3] = _rgba>> 0; + clear.m_index[0] = uint8_t(_rgba>>24); + clear.m_index[1] = uint8_t(_rgba>>16); + clear.m_index[2] = uint8_t(_rgba>> 8); + clear.m_index[3] = uint8_t(_rgba>> 0); clear.m_depth = _depth; clear.m_stencil = _stencil; } diff --git a/3rdparty/bgfx/src/config.h b/3rdparty/bgfx/src/config.h index 07fde5584d9..791f39a7aad 100644 --- a/3rdparty/bgfx/src/config.h +++ b/3rdparty/bgfx/src/config.h @@ -180,7 +180,7 @@ # define BGFX_CONFIG_MAX_VIEWS 256 #endif // BGFX_CONFIG_MAX_VIEWS -#define BGFX_CONFIG_MAX_VIEW_NAME_RESERVED 5 +#define BGFX_CONFIG_MAX_VIEW_NAME_RESERVED 6 #ifndef BGFX_CONFIG_MAX_VIEW_NAME # define BGFX_CONFIG_MAX_VIEW_NAME 256 diff --git a/3rdparty/bgfx/src/glcontext_eagl.h b/3rdparty/bgfx/src/glcontext_eagl.h index 5c26a71f2a4..45ba0fbf3d0 100644 --- a/3rdparty/bgfx/src/glcontext_eagl.h +++ b/3rdparty/bgfx/src/glcontext_eagl.h @@ -21,7 +21,7 @@ namespace bgfx { namespace gl void create(uint32_t _width, uint32_t _height); void destroy(); - void resize(uint32_t _width, uint32_t _height, bool _vsync); + void resize(uint32_t _width, uint32_t _height, uint32_t _flags); static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); diff --git a/3rdparty/bgfx/src/glcontext_eagl.mm b/3rdparty/bgfx/src/glcontext_eagl.mm index 4348eb65178..73eedd2b587 100644 --- a/3rdparty/bgfx/src/glcontext_eagl.mm +++ b/3rdparty/bgfx/src/glcontext_eagl.mm @@ -54,7 +54,7 @@ namespace bgfx { namespace gl GL_CHECK(glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height) ); // from OES_packed_depth_stencil GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) ); GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) ); - + BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) , "glCheckFramebufferStatus failed 0x%08x" , glCheckFramebufferStatus(GL_FRAMEBUFFER) @@ -85,9 +85,9 @@ namespace bgfx { namespace gl [context release]; } - void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync) + void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags) { - BX_UNUSED(_width, _height, _vsync); + BX_UNUSED(_width, _height, _flags); BX_TRACE("resize context"); } diff --git a/3rdparty/bgfx/src/glcontext_egl.cpp b/3rdparty/bgfx/src/glcontext_egl.cpp index a3fe4e77c80..93990746c5b 100644 --- a/3rdparty/bgfx/src/glcontext_egl.cpp +++ b/3rdparty/bgfx/src/glcontext_egl.cpp @@ -280,7 +280,7 @@ EGL_IMPORT # endif // BX_PLATFORM_RPI } - void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync) + void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags) { BX_UNUSED(_width, _height); # if BX_PLATFORM_ANDROID @@ -289,7 +289,8 @@ EGL_IMPORT ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format); # endif // BX_PLATFORM_ANDROID - eglSwapInterval(m_display, _vsync ? 1 : 0); + bool vsync = !!(_flags&BGFX_RESET_VSYNC); + eglSwapInterval(m_display, vsync ? 1 : 0); } bool GlContext::isSwapChainSupported() diff --git a/3rdparty/bgfx/src/glcontext_egl.h b/3rdparty/bgfx/src/glcontext_egl.h index 122591ca832..35a30c63f71 100644 --- a/3rdparty/bgfx/src/glcontext_egl.h +++ b/3rdparty/bgfx/src/glcontext_egl.h @@ -26,7 +26,7 @@ namespace bgfx { namespace gl void create(uint32_t _width, uint32_t _height); void destroy(); - void resize(uint32_t _width, uint32_t _height, bool _vsync); + void resize(uint32_t _width, uint32_t _height, uint32_t _flags); static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); diff --git a/3rdparty/bgfx/src/glcontext_glx.cpp b/3rdparty/bgfx/src/glcontext_glx.cpp index 13a91de7daf..17ee8e825e7 100644 --- a/3rdparty/bgfx/src/glcontext_glx.cpp +++ b/3rdparty/bgfx/src/glcontext_glx.cpp @@ -225,9 +225,10 @@ namespace bgfx { namespace gl m_visualInfo = NULL; } - void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync) + void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, uint32_t _flags) { - int32_t interval = _vsync ? 1 : 0; + bool vsync = !!(_flags&BGFX_RESET_VSYNC); + int32_t interval = vsync ? 1 : 0; if (NULL != glXSwapIntervalEXT) { diff --git a/3rdparty/bgfx/src/glcontext_glx.h b/3rdparty/bgfx/src/glcontext_glx.h index cff6faa16a6..a931356cbdd 100644 --- a/3rdparty/bgfx/src/glcontext_glx.h +++ b/3rdparty/bgfx/src/glcontext_glx.h @@ -26,7 +26,7 @@ namespace bgfx { namespace gl void create(uint32_t _width, uint32_t _height); void destroy(); - void resize(uint32_t _width, uint32_t _height, bool _vsync); + void resize(uint32_t _width, uint32_t _height, uint32_t _flags); static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); diff --git a/3rdparty/bgfx/src/glcontext_nsgl.h b/3rdparty/bgfx/src/glcontext_nsgl.h index c88673d8fe6..666926db984 100644 --- a/3rdparty/bgfx/src/glcontext_nsgl.h +++ b/3rdparty/bgfx/src/glcontext_nsgl.h @@ -21,7 +21,7 @@ namespace bgfx { namespace gl void create(uint32_t _width, uint32_t _height); void destroy(); - void resize(uint32_t _width, uint32_t _height, bool _vsync); + void resize(uint32_t _width, uint32_t _height, uint32_t _flags); static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); diff --git a/3rdparty/bgfx/src/glcontext_nsgl.mm b/3rdparty/bgfx/src/glcontext_nsgl.mm index f01c7014131..236809223f7 100644 --- a/3rdparty/bgfx/src/glcontext_nsgl.mm +++ b/3rdparty/bgfx/src/glcontext_nsgl.mm @@ -40,17 +40,19 @@ namespace bgfx { namespace gl class AutoreleasePoolHolder { public: - AutoreleasePoolHolder() : pool([[NSAutoreleasePool alloc] init]) + AutoreleasePoolHolder() : m_pool([[NSAutoreleasePool alloc] init]) { } ~AutoreleasePoolHolder() { - [pool release]; + [m_pool release]; } private: - NSAutoreleasePool* pool; + AutoreleasePoolHolder(AutoreleasePoolHolder const&); + + NSAutoreleasePool* const m_pool; }; static void* s_opengl = NULL; @@ -99,6 +101,7 @@ namespace bgfx { namespace gl NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat]; [pixelFormat release]; +// [glView setWantsBestResolutionOpenGLSurface:YES]; [nsWindow setContentView:glView]; NSOpenGLContext* glContext = [glView openGLContext]; @@ -128,11 +131,12 @@ namespace bgfx { namespace gl bx::dlclose(s_opengl); } - void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync) + void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags) { BX_UNUSED(_width, _height); - GLint interval = _vsync ? 1 : 0; + bool vsync = !!(_flags&BGFX_RESET_VSYNC); + GLint interval = vsync ? 1 : 0; NSOpenGLContext* glContext = (NSOpenGLContext*)m_context; [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; [glContext update]; diff --git a/3rdparty/bgfx/src/glcontext_ppapi.cpp b/3rdparty/bgfx/src/glcontext_ppapi.cpp index 3910e7a13ee..f61244dbd38 100644 --- a/3rdparty/bgfx/src/glcontext_ppapi.cpp +++ b/3rdparty/bgfx/src/glcontext_ppapi.cpp @@ -38,7 +38,7 @@ namespace bgfx { namespace gl bool setInterfaces(PP_Instance _instance, const PPB_Instance* _instInterface, const PPB_Graphics3D* _graphicsInterface, PostSwapBuffersFn _postSwapBuffers); - void resize(uint32_t _width, uint32_t _height, bool /*_vsync*/) + void resize(uint32_t _width, uint32_t _height, uint32_t /*_flags*/) { m_graphicsInterface->ResizeBuffers(m_context, _width, _height); } @@ -147,10 +147,10 @@ namespace bgfx { namespace gl { } - void GlContext::resize(uint32_t _width, uint32_t _height, bool _vsync) + void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags) { s_ppapi.m_forceSwap = false; - s_ppapi.resize(_width, _height, _vsync); + s_ppapi.resize(_width, _height, _flags); } bool GlContext::isSwapChainSupported() diff --git a/3rdparty/bgfx/src/glcontext_ppapi.h b/3rdparty/bgfx/src/glcontext_ppapi.h index 3142b6acdf5..f54ea2bb5a8 100644 --- a/3rdparty/bgfx/src/glcontext_ppapi.h +++ b/3rdparty/bgfx/src/glcontext_ppapi.h @@ -25,7 +25,7 @@ namespace bgfx { namespace gl void create(uint32_t _width, uint32_t _height); void destroy(); - void resize(uint32_t _width, uint32_t _height, bool _vsync); + void resize(uint32_t _width, uint32_t _height, uint32_t _flags); static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); diff --git a/3rdparty/bgfx/src/glcontext_wgl.cpp b/3rdparty/bgfx/src/glcontext_wgl.cpp index 84c32a06633..19ca6d99f72 100644 --- a/3rdparty/bgfx/src/glcontext_wgl.cpp +++ b/3rdparty/bgfx/src/glcontext_wgl.cpp @@ -287,11 +287,12 @@ namespace bgfx { namespace gl m_opengl32dll = NULL; } - void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync) + void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, uint32_t _flags) { if (NULL != wglSwapIntervalEXT) { - wglSwapIntervalEXT(_vsync ? 1 : 0); + bool vsync = !!(_flags&BGFX_RESET_VSYNC); + wglSwapIntervalEXT(vsync ? 1 : 0); } } diff --git a/3rdparty/bgfx/src/glcontext_wgl.h b/3rdparty/bgfx/src/glcontext_wgl.h index 98338f09410..1948622b88e 100644 --- a/3rdparty/bgfx/src/glcontext_wgl.h +++ b/3rdparty/bgfx/src/glcontext_wgl.h @@ -70,7 +70,7 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z void create(uint32_t _width, uint32_t _height); void destroy(); - void resize(uint32_t _width, uint32_t _height, bool _vsync); + void resize(uint32_t _width, uint32_t _height, uint32_t _flags); static bool isSwapChainSupported(); SwapChainGL* createSwapChain(void* _nwh); diff --git a/3rdparty/bgfx/src/image.cpp b/3rdparty/bgfx/src/image.cpp index b420b2da364..f7aa4404b71 100644 --- a/3rdparty/bgfx/src/image.cpp +++ b/3rdparty/bgfx/src/image.cpp @@ -436,7 +436,7 @@ namespace bgfx } } - uint32_t bitRangeConvert(uint32_t _in, uint32_t _from, uint32_t _to) + uint8_t bitRangeConvert(uint32_t _in, uint32_t _from, uint32_t _to) { using namespace bx; uint32_t tmp0 = uint32_sll(1, _to); @@ -449,7 +449,7 @@ namespace bgfx uint32_t tmp7 = uint32_add(tmp5, tmp6); uint32_t result = uint32_srl(tmp7, _from); - return result; + return uint8_t(result); } void decodeBlockDxt(uint8_t _dst[16*4], const uint8_t _src[8]) @@ -986,7 +986,7 @@ namespace bgfx { 0, 8, 0, 8 }, }; - uint32_t morton2d(uint16_t _x, uint16_t _y) + uint32_t morton2d(uint32_t _x, uint32_t _y) { using namespace bx; const uint32_t tmpx = uint32_part1by1(_x); @@ -1099,9 +1099,9 @@ namespace bgfx const uint8_t wa = weight[0]; const uint8_t wb = weight[1]; - _dst[(yy*4 + xx)*4+0] = (ab * wa + bb * wb) >> 7; - _dst[(yy*4 + xx)*4+1] = (ag * wa + bg * wb) >> 7; - _dst[(yy*4 + xx)*4+2] = (ar * wa + br * wb) >> 7; + _dst[(yy*4 + xx)*4+0] = uint8_t( (ab * wa + bb * wb) >> 7); + _dst[(yy*4 + xx)*4+1] = uint8_t( (ag * wa + bg * wb) >> 7); + _dst[(yy*4 + xx)*4+2] = uint8_t( (ar * wa + br * wb) >> 7); _dst[(yy*4 + xx)*4+3] = 255; mod >>= 2; @@ -1209,10 +1209,10 @@ namespace bgfx const uint8_t wc = weight[2]; const uint8_t wd = weight[3]; - _dst[(yy*4 + xx)*4+0] = (ab * wa + bb * wb) >> 7; - _dst[(yy*4 + xx)*4+1] = (ag * wa + bg * wb) >> 7; - _dst[(yy*4 + xx)*4+2] = (ar * wa + br * wb) >> 7; - _dst[(yy*4 + xx)*4+3] = (aa * wc + ba * wd) >> 7; + _dst[(yy*4 + xx)*4+0] = uint8_t( (ab * wa + bb * wb) >> 7); + _dst[(yy*4 + xx)*4+1] = uint8_t( (ag * wa + bg * wb) >> 7); + _dst[(yy*4 + xx)*4+2] = uint8_t( (ar * wa + br * wb) >> 7); + _dst[(yy*4 + xx)*4+3] = uint8_t( (aa * wc + ba * wd) >> 7); mod >>= 2; factorTable += 4; @@ -1542,13 +1542,13 @@ namespace bgfx _imageContainer.m_data = NULL; _imageContainer.m_size = 0; _imageContainer.m_offset = (uint32_t)bx::seek(_reader); - _imageContainer.m_width = width; + _imageContainer.m_width = width; _imageContainer.m_height = height; - _imageContainer.m_depth = depth; - _imageContainer.m_format = format; - _imageContainer.m_numMips = (caps[0] & DDSCAPS_MIPMAP) ? mips : 1; + _imageContainer.m_depth = depth; + _imageContainer.m_format = uint8_t(format); + _imageContainer.m_numMips = uint8_t( (caps[0] & DDSCAPS_MIPMAP) ? mips : 1); _imageContainer.m_hasAlpha = hasAlpha; - _imageContainer.m_cubeMap = cubeMap; + _imageContainer.m_cubeMap = cubeMap; _imageContainer.m_ktx = false; return TextureFormat::Unknown != format; @@ -1719,13 +1719,13 @@ namespace bgfx _imageContainer.m_data = NULL; _imageContainer.m_size = 0; _imageContainer.m_offset = (uint32_t)offset; - _imageContainer.m_width = width; + _imageContainer.m_width = width; _imageContainer.m_height = height; - _imageContainer.m_depth = depth; - _imageContainer.m_format = format; - _imageContainer.m_numMips = numMips; + _imageContainer.m_depth = depth; + _imageContainer.m_format = uint8_t(format); + _imageContainer.m_numMips = uint8_t(numMips); _imageContainer.m_hasAlpha = hasAlpha; - _imageContainer.m_cubeMap = numFaces > 1; + _imageContainer.m_cubeMap = numFaces > 1; _imageContainer.m_ktx = true; return TextureFormat::Unknown != format; @@ -1865,13 +1865,13 @@ namespace bgfx _imageContainer.m_data = NULL; _imageContainer.m_size = 0; _imageContainer.m_offset = (uint32_t)offset; - _imageContainer.m_width = width; + _imageContainer.m_width = width; _imageContainer.m_height = height; - _imageContainer.m_depth = depth; - _imageContainer.m_format = format; - _imageContainer.m_numMips = numMips; + _imageContainer.m_depth = depth; + _imageContainer.m_format = uint8_t(format); + _imageContainer.m_numMips = uint8_t(numMips); _imageContainer.m_hasAlpha = hasAlpha; - _imageContainer.m_cubeMap = numFaces > 1; + _imageContainer.m_cubeMap = numFaces > 1; _imageContainer.m_ktx = false; return TextureFormat::Unknown != format; @@ -2175,13 +2175,13 @@ namespace bgfx if (side == _side && lod == _lod) { - _mip.m_width = width; - _mip.m_height = height; + _mip.m_width = width; + _mip.m_height = height; _mip.m_blockSize = blockSize; _mip.m_size = size; _mip.m_data = (const uint8_t*)_data + offset; - _mip.m_bpp = bpp; - _mip.m_format = type; + _mip.m_bpp = bpp; + _mip.m_format = uint8_t(type); _mip.m_hasAlpha = hasAlpha; return true; } diff --git a/3rdparty/bgfx/src/renderer_d3d11.cpp b/3rdparty/bgfx/src/renderer_d3d11.cpp index c69424ca7ab..20ac1323d98 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.cpp +++ b/3rdparty/bgfx/src/renderer_d3d11.cpp @@ -155,7 +155,7 @@ namespace bgfx { namespace d3d11 * 0x01 // MIP_LINEAR */ - static const uint32_t s_textureFilter[3][3] = + static const uint8_t s_textureFilter[3][3] = { { 0x10, // min linear @@ -624,10 +624,25 @@ namespace bgfx { namespace d3d11 { hr = m_device->QueryInterface(s_deviceIIDs[ii], (void**)&device); BX_TRACE("D3D device 11.%d, hr %x", BX_COUNTOF(s_deviceIIDs)-1-ii, hr); - } - BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); - hr = device->GetParent(IID_IDXGIAdapter, (void**)&adapter); + if (SUCCEEDED(hr) ) + { +BX_PRAGMA_DIAGNOSTIC_PUSH(); +BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4530) // warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc + try + { + // QueryInterface above can succeed, but getting adapter call might crash on Win7. + hr = device->GetAdapter(&adapter); + } + catch (...) + { + BX_TRACE("Failed to get adapter foro IID_IDXGIDevice%d.", BX_COUNTOF(s_deviceIIDs)-1-ii); + DX_RELEASE(device, 0); + hr = E_FAIL; + } +BX_PRAGMA_DIAGNOSTIC_POP(); + } + } BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create Direct3D11 device."); // GPA increases device ref count. @@ -752,7 +767,7 @@ namespace bgfx { namespace d3d11 | (m_ovr.isInitialized() ? BGFX_CAPS_HMD : 0) ); g_caps.maxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; - g_caps.maxFBAttachments = bx::uint32_min(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); + g_caps.maxFBAttachments = uint8_t(bx::uint32_min(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { @@ -796,7 +811,7 @@ namespace bgfx { namespace d3d11 for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1]; - bx::snprintf(name, sizeof(name), "%3d ", ii); + bx::snprintf(name, sizeof(name), "%3d ", ii); mbstowcs(s_viewNameW[ii], name, BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); } @@ -1073,10 +1088,13 @@ namespace bgfx { namespace d3d11 void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE { - mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] - , _name - , BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED - ); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , _name + , BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + ); + } } void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE @@ -1387,7 +1405,7 @@ namespace bgfx { namespace d3d11 } } - void setShaderUniform(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { if (_flags&BGFX_UNIFORM_FRAGMENTBIT) { @@ -1401,12 +1419,12 @@ namespace bgfx { namespace d3d11 } } - void setShaderUniform4f(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { setShaderUniform(_flags, _regIndex, _val, _numRegs); } - void setShaderUniform4x4f(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform4x4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { setShaderUniform(_flags, _regIndex, _val, _numRegs); } @@ -1436,7 +1454,14 @@ namespace bgfx { namespace d3d11 void setFrameBuffer(FrameBufferHandle _fbh, bool _msaa = true) { - BX_UNUSED(_msaa); + if (isValid(m_fbh) + && m_fbh.idx != _fbh.idx + && m_rtMsaa) + { + FrameBufferD3D11& frameBuffer = m_frameBuffers[m_fbh.idx]; + frameBuffer.resolve(); + } + if (!isValid(_fbh) ) { m_deviceCtx->OMSetRenderTargets(1, &m_backBufferColor, m_backBufferDepthStencil); @@ -1455,14 +1480,6 @@ namespace bgfx { namespace d3d11 m_currentDepthStencil = frameBuffer.m_dsv; } - if (isValid(m_fbh) - && m_fbh.idx != _fbh.idx - && m_rtMsaa) - { - FrameBufferD3D11& frameBuffer = m_frameBuffers[m_fbh.idx]; - frameBuffer.resolve(); - } - m_fbh = _fbh; m_rtMsaa = _msaa; } @@ -1511,7 +1528,7 @@ namespace bgfx { namespace d3d11 } } - void setInputLayout(const VertexDecl& _vertexDecl, const ProgramD3D11& _program, uint8_t _numInstanceData) + void setInputLayout(const VertexDecl& _vertexDecl, const ProgramD3D11& _program, uint16_t _numInstanceData) { uint64_t layoutHash = (uint64_t(_vertexDecl.m_hash)<<32) | _program.m_vsh->m_hash; layoutHash ^= _numInstanceData; @@ -1641,7 +1658,7 @@ namespace bgfx { namespace d3d11 drt->DestBlendAlpha = s_blendFactor[dstA][1]; drt->BlendOpAlpha = s_blendEquation[equA]; - uint32_t writeMask = (_state&BGFX_STATE_ALPHA_WRITE) ? D3D11_COLOR_WRITE_ENABLE_ALPHA : 0; + uint8_t writeMask = (_state&BGFX_STATE_ALPHA_WRITE) ? D3D11_COLOR_WRITE_ENABLE_ALPHA : 0; writeMask |= (_state&BGFX_STATE_RGB_WRITE) ? D3D11_COLOR_WRITE_ENABLE_RED|D3D11_COLOR_WRITE_ENABLE_GREEN|D3D11_COLOR_WRITE_ENABLE_BLUE : 0; drt->RenderTargetWriteMask = writeMask; @@ -2066,11 +2083,11 @@ namespace bgfx { namespace d3d11 case UniformType::_uniform: \ case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \ { \ - setShaderUniform(type, loc, data, num); \ + setShaderUniform(uint8_t(type), loc, data, num); \ } \ break; - switch ( (int32_t)type) + switch ( (uint32_t)type) { case UniformType::Uniform3x3fv: case UniformType::Uniform3x3fv|BGFX_UNIFORM_FRAGMENTBIT: \ @@ -2091,7 +2108,7 @@ namespace bgfx { namespace d3d11 mtx.un.val[ 9] = value[7]; mtx.un.val[10] = value[8]; mtx.un.val[11] = 0.0f; - setShaderUniform(type, loc, &mtx.un.val[0], 3); + setShaderUniform(uint8_t(type), loc, &mtx.un.val[0], 3); } } break; @@ -2562,7 +2579,7 @@ namespace bgfx { namespace d3d11 kind = "predefined"; m_predefined[m_numPredefined].m_loc = regIndex; m_predefined[m_numPredefined].m_count = regCount; - m_predefined[m_numPredefined].m_type = predefined|fragmentBit; + m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); m_numPredefined++; } else @@ -2647,7 +2664,7 @@ namespace bgfx { namespace d3d11 if (0 < size) { D3D11_BUFFER_DESC desc; - desc.ByteWidth = size; + desc.ByteWidth = (size + 0xf) & ~0xf; desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.CPUAccessFlags = 0; @@ -2666,7 +2683,7 @@ namespace bgfx { namespace d3d11 if (imageParse(imageContainer, _mem->data, _mem->size) ) { uint8_t numMips = imageContainer.m_numMips; - const uint32_t startLod = bx::uint32_min(_skip, numMips-1); + const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); numMips -= startLod; const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); @@ -2726,7 +2743,7 @@ namespace bgfx { namespace d3d11 uint32_t height = textureHeight; uint32_t depth = imageContainer.m_depth; - for (uint32_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = numMips; lod < num; ++lod) { width = bx::uint32_max(1, width); height = bx::uint32_max(1, height); @@ -3217,18 +3234,26 @@ namespace bgfx { namespace d3d11 viewState.m_rect = _render->m_rect[view]; if (viewRestart) { - wchar_t* viewNameW = s_viewNameW[view]; - viewNameW[3] = eye ? L'R' : L'L'; - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + wchar_t* viewNameW = s_viewNameW[view]; + viewNameW[3] = L' '; + viewNameW[4] = eye ? L'R' : L'L'; + PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + } viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2; viewState.m_rect.m_width /= 2; } else { - wchar_t* viewNameW = s_viewNameW[view]; - viewNameW[3] = L' '; - PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + wchar_t* viewNameW = s_viewNameW[view]; + viewNameW[3] = L' '; + viewNameW[4] = L' '; + PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + } } const Rect& scissorRect = _render->m_scissor[view]; @@ -3258,6 +3283,14 @@ namespace bgfx { namespace d3d11 { wasCompute = true; + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + wchar_t* viewNameW = s_viewNameW[view]; + viewNameW[3] = L'C'; + PIX_ENDEVENT(); + PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + } + deviceCtx->IASetVertexBuffers(0, 2, s_zero.m_buffer, s_zero.m_zero, s_zero.m_zero); deviceCtx->IASetIndexBuffer(NULL, DXGI_FORMAT_R16_UINT, 0); @@ -3376,6 +3409,14 @@ namespace bgfx { namespace d3d11 if (wasCompute) { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + wchar_t* viewNameW = s_viewNameW[view]; + viewNameW[3] = L' '; + PIX_ENDEVENT(); + PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + } + wasCompute = false; programIdx = invalidHandle; @@ -3563,7 +3604,7 @@ namespace bgfx { namespace d3d11 { uint32_t changes = 0; - for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) + for (uint8_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) { const Binding& sampler = draw.m_bind[stage]; Binding& current = currentState.m_bind[stage]; @@ -3722,6 +3763,14 @@ namespace bgfx { namespace d3d11 if (wasCompute) { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + wchar_t* viewNameW = s_viewNameW[view]; + viewNameW[3] = L'C'; + PIX_ENDEVENT(); + PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), viewNameW); + } + invalidateCompute(); } diff --git a/3rdparty/bgfx/src/renderer_d3d9.cpp b/3rdparty/bgfx/src/renderer_d3d9.cpp index 055eb5ed144..970485bb5d1 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.cpp +++ b/3rdparty/bgfx/src/renderer_d3d9.cpp @@ -359,13 +359,13 @@ namespace bgfx { namespace d3d9 m_adapter = D3DADAPTER_DEFAULT; m_deviceType = D3DDEVTYPE_HAL; - uint8_t numGPUs = bx::uint32_min(BX_COUNTOF(g_caps.gpu), m_d3d9->GetAdapterCount() ); + uint8_t numGPUs = uint8_t(bx::uint32_min(BX_COUNTOF(g_caps.gpu), m_d3d9->GetAdapterCount() ) ); for (uint32_t ii = 0; ii < numGPUs; ++ii) { D3DADAPTER_IDENTIFIER9 desc; HRESULT hr = m_d3d9->GetAdapterIdentifier(ii, 0, &desc); if (SUCCEEDED(hr) ) - { + { BX_TRACE("Adapter #%d", ii); BX_TRACE("\tDriver: %s", desc.Driver); BX_TRACE("\tDescription: %s", desc.Description); @@ -470,10 +470,10 @@ namespace bgfx { namespace d3d9 | BGFX_CAPS_FRAGMENT_DEPTH | BGFX_CAPS_SWAP_CHAIN ); - g_caps.maxTextureSize = bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight); + g_caps.maxTextureSize = uint16_t(bx::uint32_min(m_caps.MaxTextureWidth, m_caps.MaxTextureHeight) ); - m_caps.NumSimultaneousRTs = bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); - g_caps.maxFBAttachments = (uint8_t)m_caps.NumSimultaneousRTs; + m_caps.NumSimultaneousRTs = uint8_t(bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); + g_caps.maxFBAttachments = uint8_t(m_caps.NumSimultaneousRTs); m_caps.MaxAnisotropy = bx::uint32_min(m_caps.MaxAnisotropy, 1); @@ -598,7 +598,7 @@ namespace bgfx { namespace d3d9 for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1]; - bx::snprintf(name, sizeof(name), "%3d ", ii); + bx::snprintf(name, sizeof(name), "%3d ", ii); mbstowcs(s_viewNameW[ii], name, BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); } @@ -874,10 +874,13 @@ namespace bgfx { namespace d3d9 void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE { - mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] - , _name - , BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED - ); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , _name + , BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + ); + } } void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE @@ -1084,7 +1087,7 @@ namespace bgfx { namespace d3d9 m_rtMsaa = _msaa; } - void setShaderUniform(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { if (_flags&BGFX_UNIFORM_FRAGMENTBIT) { @@ -1096,12 +1099,12 @@ namespace bgfx { namespace d3d9 } } - void setShaderUniform4f(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { setShaderUniform(_flags, _regIndex, _val, _numRegs); } - void setShaderUniform4x4f(uint8_t _flags, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform4x4f(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { setShaderUniform(_flags, _regIndex, _val, _numRegs); } @@ -1882,7 +1885,7 @@ namespace bgfx { namespace d3d9 }; BX_STATIC_ASSERT(Attrib::Count == BX_COUNTOF(s_attrib)-1); - static const D3DDECLTYPE s_attribType[][4][2] = + static const uint8_t s_attribType[][4][2] = { { { D3DDECLTYPE_UBYTE4, D3DDECLTYPE_UBYTE4N }, @@ -1936,17 +1939,17 @@ namespace bgfx { namespace d3d9 return elem; } - static IDirect3DVertexDeclaration9* createVertexDeclaration(const VertexDecl& _decl, uint8_t _numInstanceData) + static IDirect3DVertexDeclaration9* createVertexDeclaration(const VertexDecl& _decl, uint16_t _numInstanceData) { D3DVERTEXELEMENT9 vertexElements[Attrib::Count+1+BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; D3DVERTEXELEMENT9* elem = fillVertexDecl(vertexElements, _decl); const D3DVERTEXELEMENT9 inst = { 1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }; - for (uint32_t ii = 0; ii < _numInstanceData; ++ii) + for (uint8_t ii = 0; ii < _numInstanceData; ++ii) { memcpy(elem, &inst, sizeof(D3DVERTEXELEMENT9) ); - elem->UsageIndex = 8-_numInstanceData+ii; + elem->UsageIndex = uint8_t(8-_numInstanceData+ii); elem->Offset = ii*16; ++elem; } @@ -2026,9 +2029,9 @@ namespace bgfx { namespace d3d9 if (PredefinedUniform::Count != predefined) { kind = "predefined"; - m_predefined[m_numPredefined].m_loc = regIndex; + m_predefined[m_numPredefined].m_loc = regIndex; m_predefined[m_numPredefined].m_count = regCount; - m_predefined[m_numPredefined].m_type = predefined|fragmentBit; + m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); m_numPredefined++; } else @@ -2362,7 +2365,7 @@ namespace bgfx { namespace d3d9 if (imageParse(imageContainer, _mem->data, _mem->size) ) { uint8_t numMips = imageContainer.m_numMips; - const uint32_t startLod = bx::uint32_min(_skip, numMips-1); + const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); numMips -= startLod; const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); @@ -2425,7 +2428,7 @@ namespace bgfx { namespace d3d9 uint32_t mipWidth = imageContainer.m_width; uint32_t mipHeight = imageContainer.m_height; - for (uint32_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = numMips; lod < num; ++lod) { width = bx::uint32_max(1, width); height = bx::uint32_max(1, height); @@ -3012,7 +3015,7 @@ namespace bgfx { namespace d3d9 { uint32_t fstencil = unpackStencil(0, newStencil); uint32_t bstencil = unpackStencil(1, newStencil); - uint32_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != fstencil; + uint8_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != fstencil; DX_CHECK(device->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, 0 != frontAndBack) ); uint32_t fchanged = unpackStencil(0, changedStencil); @@ -3032,7 +3035,7 @@ namespace bgfx { namespace d3d9 // DX_CHECK(device->SetRenderState(D3DRS_STENCILWRITEMASK, wmask) ); // } - for (uint32_t ii = 0, num = frontAndBack+1; ii < num; ++ii) + for (uint8_t ii = 0, num = frontAndBack+1; ii < num; ++ii) { uint32_t stencil = unpackStencil(ii, newStencil); uint32_t changed = unpackStencil(ii, changedStencil); @@ -3218,7 +3221,7 @@ namespace bgfx { namespace d3d9 } { - for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) + for (uint8_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) { const Binding& sampler = draw.m_bind[stage]; Binding& current = currentState.m_bind[stage]; diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp index c35e9c5a30f..86a0c06f287 100644 --- a/3rdparty/bgfx/src/renderer_gl.cpp +++ b/3rdparty/bgfx/src/renderer_gl.cpp @@ -1355,14 +1355,14 @@ namespace bgfx { namespace gl : 0 ; - g_caps.maxTextureSize = glGet(GL_MAX_TEXTURE_SIZE); + g_caps.maxTextureSize = uint16_t(glGet(GL_MAX_TEXTURE_SIZE) ); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) || s_extension[Extension::EXT_draw_buffers ].m_supported || s_extension[Extension::WEBGL_draw_buffers].m_supported) { - g_caps.maxFBAttachments = bx::uint32_min(glGet(GL_MAX_COLOR_ATTACHMENTS), BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); + g_caps.maxFBAttachments = uint8_t(bx::uint32_min(glGet(GL_MAX_COLOR_ATTACHMENTS), BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); } m_vaoSupport = !!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) @@ -1540,7 +1540,7 @@ namespace bgfx { namespace gl // Init reserved part of view name. for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { - bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1, "%3d ", ii); + bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1, "%3d ", ii); } ovrPostReset(); @@ -1795,10 +1795,13 @@ namespace bgfx { namespace gl void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE { - bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] - , _name - , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED - ); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , _name + , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + ); + } } void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE @@ -1899,10 +1902,10 @@ namespace bgfx { namespace gl m_resolution = _resolution; m_resolution.m_flags = flags; - uint32_t msaa = (m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; - msaa = bx::uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa); - bool vsync = !!(m_resolution.m_flags&BGFX_RESET_VSYNC); - setRenderContextSize(_resolution.m_width, _resolution.m_height, msaa, vsync); + setRenderContextSize(m_resolution.m_width + , m_resolution.m_height + , m_resolution.m_flags + ); updateCapture(); ovrPreReset(); @@ -1915,7 +1918,7 @@ namespace bgfx { namespace gl } } - void setShaderUniform4f(uint8_t /*_flags*/, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { GL_CHECK(glUniform4fv(_regIndex , _numRegs @@ -1923,7 +1926,7 @@ namespace bgfx { namespace gl ) ); } - void setShaderUniform4x4f(uint8_t /*_flags*/, uint16_t _regIndex, const void* _val, uint16_t _numRegs) + void setShaderUniform4x4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { GL_CHECK(glUniformMatrix4fv(_regIndex , _numRegs @@ -1932,7 +1935,7 @@ namespace bgfx { namespace gl ) ); } - uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, uint8_t _discard = BGFX_CLEAR_NONE, bool _msaa = true) + uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, uint16_t _discard = BGFX_CLEAR_NONE, bool _msaa = true) { if (isValid(m_fbh) && m_fbh.idx != _fbh.idx @@ -2068,7 +2071,7 @@ namespace bgfx { namespace gl } } - void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _msaa = 0, bool _vsync = false) + void setRenderContextSize(uint32_t _width, uint32_t _height, uint32_t _flags = 0) { if (_width != 0 || _height != 0) @@ -2086,9 +2089,12 @@ namespace bgfx { namespace gl { destroyMsaaFbo(); - m_glctx.resize(_width, _height, _vsync); + m_glctx.resize(_width, _height, _flags); + + uint32_t msaa = (_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + msaa = bx::uint32_min(m_maxMsaa, msaa == 0 ? 0 : 1<<msaa); - createMsaaFbo(_width, _height, _msaa); + createMsaaFbo(_width, _height, msaa); } } @@ -2629,7 +2635,7 @@ namespace bgfx { namespace gl bool m_rtMsaa; FrameBufferHandle m_fbh; - uint32_t m_fbDiscard; + uint16_t m_fbDiscard; Resolution m_resolution; void* m_capture; @@ -3056,9 +3062,9 @@ namespace bgfx { namespace gl PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name); if (PredefinedUniform::Count != predefined) { - m_predefined[m_numPredefined].m_loc = loc; - m_predefined[m_numPredefined].m_type = predefined; - m_predefined[m_numPredefined].m_count = num; + m_predefined[m_numPredefined].m_loc = loc; + m_predefined[m_numPredefined].m_count = uint16_t(num); + m_predefined[m_numPredefined].m_type = uint8_t(predefined); m_numPredefined++; } else @@ -3072,7 +3078,7 @@ namespace bgfx { namespace gl } UniformType::Enum type = convertGlType(gltype); - m_constantBuffer->writeUniformHandle(type, 0, info->m_handle, num); + m_constantBuffer->writeUniformHandle(type, 0, info->m_handle, uint16_t(num) ); m_constantBuffer->write(loc); BX_TRACE("store %s %d", name, info->m_handle); } @@ -3135,7 +3141,7 @@ namespace bgfx { namespace gl memset(m_attributes, 0xff, sizeof(m_attributes) ); uint32_t used = 0; - for (uint32_t ii = 0; ii < Attrib::Count; ++ii) + for (uint8_t ii = 0; ii < Attrib::Count; ++ii) { GLint loc = glGetAttribLocation(m_id, s_attribName[ii]); if (-1 != loc) @@ -3372,8 +3378,8 @@ namespace bgfx { namespace gl if (imageParse(imageContainer, _mem->data, _mem->size) ) { uint8_t numMips = imageContainer.m_numMips; - const uint32_t startLod = bx::uint32_min(_skip, numMips-1); - numMips -= uint8_t(startLod); + const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); + numMips -= startLod; const ImageBlockInfo& blockInfo = getBlockInfo(TextureFormat::Enum(imageContainer.m_format) ); const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod); @@ -3450,7 +3456,7 @@ namespace bgfx { namespace gl uint32_t height = textureHeight; uint32_t depth = imageContainer.m_depth; - for (uint32_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = numMips; lod < num; ++lod) { width = bx::uint32_max(blockWidth, width); height = bx::uint32_max(blockHeight, height); @@ -4278,7 +4284,7 @@ namespace bgfx { namespace gl } } - m_num = colorIdx; + m_num = uint8_t(colorIdx); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) { @@ -4389,7 +4395,7 @@ namespace bgfx { namespace gl } } - void FrameBufferGL::discard(uint8_t _flags) + void FrameBufferGL::discard(uint16_t _flags) { GLenum buffers[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS+2]; uint32_t idx = 0; @@ -4508,10 +4514,11 @@ namespace bgfx { namespace gl uint32_t baseVertex = 0; GLuint currentVao = 0; + bool wasCompute = false; bool viewHasScissor = false; Rect viewScissorRect; viewScissorRect.clear(); - uint8_t discardFlags = BGFX_CLEAR_NONE; + uint16_t discardFlags = BGFX_CLEAR_NONE; const bool blendIndependentSupported = s_extension[Extension::ARB_draw_buffers_blend].m_supported; const bool computeSupported = (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) && s_extension[Extension::ARB_compute_shader].m_supported) @@ -4592,18 +4599,26 @@ namespace bgfx { namespace gl viewState.m_rect = _render->m_rect[view]; if (viewRestart) { - char* viewName = s_viewName[view]; - viewName[3] = eye ? 'R' : 'L'; - GL_CHECK(glInsertEventMarker(0, viewName) ); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + char* viewName = s_viewName[view]; + viewName[3] = ' '; + viewName[4] = eye ? 'R' : 'L'; + GL_CHECK(glInsertEventMarker(0, viewName) ); + } viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2; viewState.m_rect.m_width /= 2; } else { - char* viewName = s_viewName[view]; - viewName[3] = ' '; - GL_CHECK(glInsertEventMarker(0, viewName) ); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + char* viewName = s_viewName[view]; + viewName[3] = ' '; + viewName[4] = ' '; + GL_CHECK(glInsertEventMarker(0, viewName) ); + } } const Rect& scissorRect = _render->m_scissor[view]; @@ -4633,6 +4648,18 @@ namespace bgfx { namespace gl if (isCompute) { + if (!wasCompute) + { + wasCompute = true; + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + char* viewName = s_viewName[view]; + viewName[3] = 'C'; + GL_CHECK(glInsertEventMarker(0, viewName) ); + } + } + if (computeSupported) { const RenderCompute& compute = renderItem.compute; @@ -4703,6 +4730,18 @@ namespace bgfx { namespace gl continue; } + if (wasCompute) + { + wasCompute = false; + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + char* viewName = s_viewName[view]; + viewName[3] = ' '; + GL_CHECK(glInsertEventMarker(0, viewName) ); + } + } + const RenderDraw& draw = renderItem.draw; const uint64_t newFlags = draw.m_flags; @@ -4764,7 +4803,7 @@ namespace bgfx { namespace gl GL_CHECK(glEnable(GL_STENCIL_TEST) ); uint32_t bstencil = unpackStencil(1, newStencil); - uint32_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != unpackStencil(0, newStencil); + uint8_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != unpackStencil(0, newStencil); // uint32_t bchanged = unpackStencil(1, changedStencil); // if (BGFX_STENCIL_FUNC_RMASK_MASK & bchanged) @@ -4773,7 +4812,7 @@ namespace bgfx { namespace gl // GL_CHECK(glStencilMask(wmask) ); // } - for (uint32_t ii = 0, num = frontAndBack+1; ii < num; ++ii) + for (uint8_t ii = 0, num = frontAndBack+1; ii < num; ++ii) { uint32_t stencil = unpackStencil(ii, newStencil); uint32_t changed = unpackStencil(ii, changedStencil); diff --git a/3rdparty/bgfx/src/renderer_gl.h b/3rdparty/bgfx/src/renderer_gl.h index 65dae432203..db4e1f06958 100644 --- a/3rdparty/bgfx/src/renderer_gl.h +++ b/3rdparty/bgfx/src/renderer_gl.h @@ -928,7 +928,7 @@ namespace bgfx { namespace gl void create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _depthFormat); uint16_t destroy(); void resolve(); - void discard(uint8_t _flags); + void discard(uint16_t _flags); SwapChainGL* m_swapChain; GLuint m_fbo[2]; |