diff options
Diffstat (limited to '3rdparty/bgfx/src')
85 files changed, 29438 insertions, 12026 deletions
diff --git a/3rdparty/bgfx/src/amalgamated.cpp b/3rdparty/bgfx/src/amalgamated.cpp index 6e6ebec7c85..deac46d36e7 100644 --- a/3rdparty/bgfx/src/amalgamated.cpp +++ b/3rdparty/bgfx/src/amalgamated.cpp @@ -1,24 +1,28 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx.cpp" #include "debug_renderdoc.cpp" #include "dxgi.cpp" #include "glcontext_egl.cpp" -#include "glcontext_glx.cpp" #include "glcontext_wgl.cpp" +#include "glcontext_html5.cpp" #include "nvapi.cpp" -#include "renderer_d3d9.cpp" +#include "renderer_agc.cpp" #include "renderer_d3d11.cpp" #include "renderer_d3d12.cpp" -#include "renderer_noop.cpp" +#include "renderer_d3d9.cpp" #include "renderer_gl.cpp" -#include "renderer_vk.cpp" #include "renderer_gnm.cpp" -#include "shader_dxbc.cpp" +#include "renderer_noop.cpp" +#include "renderer_nvn.cpp" +#include "renderer_vk.cpp" +#include "renderer_webgpu.cpp" +#include "shader.cpp" #include "shader_dx9bc.cpp" +#include "shader_dxbc.cpp" #include "shader_spirv.cpp" #include "topology.cpp" -#include "vertexdecl.cpp" +#include "vertexlayout.cpp" diff --git a/3rdparty/bgfx/src/amalgamated.mm b/3rdparty/bgfx/src/amalgamated.mm index 8d1ce6416ac..e3746e68dfc 100644 --- a/3rdparty/bgfx/src/amalgamated.mm +++ b/3rdparty/bgfx/src/amalgamated.mm @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "amalgamated.cpp" diff --git a/3rdparty/bgfx/src/bgfx.cpp b/3rdparty/bgfx/src/bgfx.cpp index 5b58c5f55f0..d2aa92ad8ad 100644 --- a/3rdparty/bgfx/src/bgfx.cpp +++ b/3rdparty/bgfx/src/bgfx.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include <bx/platform.h> @@ -12,24 +12,42 @@ #include "topology.h" -BX_ERROR_RESULT(BGFX_ERROR_TEXTURE_VALIDATION, BX_MAKEFOURCC('b', 'g', 0, 1) ); +#if BX_PLATFORM_OSX || BX_PLATFORM_IOS +# include <objc/message.h> +#elif BX_PLATFORM_WINDOWS +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif // WIN32_LEAN_AND_MEAN +# include <windows.h> +#endif // BX_PLATFORM_OSX + +BX_ERROR_RESULT(BGFX_ERROR_TEXTURE_VALIDATION, BX_MAKEFOURCC('b', 'g', 0, 1) ); +BX_ERROR_RESULT(BGFX_ERROR_FRAME_BUFFER_VALIDATION, BX_MAKEFOURCC('b', 'g', 0, 2) ); +BX_ERROR_RESULT(BGFX_ERROR_IDENTIFIER_VALIDATION, BX_MAKEFOURCC('b', 'g', 0, 3) ); namespace bgfx { #define BGFX_API_THREAD_MAGIC UINT32_C(0x78666762) #if BGFX_CONFIG_MULTITHREADED -# define BGFX_CHECK_API_THREAD() \ - BX_CHECK(NULL != s_ctx, "Library is not initialized yet."); \ - BX_CHECK(BGFX_API_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.") -# define BGFX_CHECK_RENDER_THREAD() BX_CHECK(~BGFX_API_THREAD_MAGIC == s_threadIndex, "Must be called from render thread.") + +# define BGFX_CHECK_API_THREAD() \ + BX_ASSERT(NULL != s_ctx, "Library is not initialized yet."); \ + BX_ASSERT(BGFX_API_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.") + +# define BGFX_CHECK_RENDER_THREAD() \ + BX_ASSERT( (NULL != s_ctx && s_ctx->m_singleThreaded) \ + || ~BGFX_API_THREAD_MAGIC == s_threadIndex \ + , "Must be called from render thread." \ + ) + #else # define BGFX_CHECK_API_THREAD() # define BGFX_CHECK_RENDER_THREAD() #endif // BGFX_CONFIG_MULTITHREADED #define BGFX_CHECK_CAPS(_caps, _msg) \ - BX_CHECK(0 != (g_caps.supported & (_caps) ) \ + BX_ASSERT(0 != (g_caps.supported & (_caps) ) \ , _msg " Use bgfx::getCaps to check " #_caps " backend renderer capabilities." \ ); @@ -56,14 +74,14 @@ namespace bgfx virtual void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _str) override { + bgfx::trace(_filePath, _line, "BGFX FATAL 0x%08x: %s\n", _code, _str); + if (Fatal::DebugCheck == _code) { bx::debugBreak(); } else { - bgfx::trace(_filePath, _line, "BGFX 0x%08x: %s\n", _code, _str); - BX_UNUSED(_code, _str); abort(); } } @@ -172,7 +190,7 @@ namespace bgfx #if BGFX_CONFIG_MEMORY_TRACKING { bx::MutexScope scope(m_mutex); - BX_CHECK(m_numBlocks > 0, "Number of blocks is 0. Possible alloc/free mismatch?"); + BX_ASSERT(m_numBlocks > 0, "Number of blocks is 0. Possible alloc/free mismatch?"); --m_numBlocks; } #endif // BGFX_CONFIG_MEMORY_TRACKING @@ -245,8 +263,8 @@ namespace bgfx class ThreadData { BX_CLASS(ThreadData + , NO_DEFAULT_CTOR , NO_COPY - , NO_ASSIGNMENT ); public: @@ -293,13 +311,43 @@ namespace bgfx PlatformData g_platformData; bool g_platformDataChangedSinceReset = false; + static Handle::TypeName s_typeName[] = + { + { "DIB", "DynamicIndexBuffer" }, + { "DVB", "DynamicVertexBuffer" }, + { "FB", "FrameBuffer" }, + { "IB", "IndexBuffer" }, + { "IndB", "IndirectBuffer" }, + { "OQ", "OcclusionQuery" }, + { "P", "Program" }, + { "S", "Shader" }, + { "T", "Texture" }, + { "U", "Uniform" }, + { "VB", "VertexBuffer" }, + { "VL", "VertexLayout" }, + { "?", "?" }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_typeName) == Handle::Count+1, ""); + + const Handle::TypeName& Handle::getTypeName(Handle::Enum _enum) + { + BX_ASSERT(_enum < Handle::Count, "Invalid Handle::Enum %d!", _enum); + return s_typeName[bx::min(_enum, Handle::Count)]; + } + void AllocatorStub::checkLeaks() { #if BGFX_CONFIG_MEMORY_TRACKING // BK - CallbackStub will be deleted after printing this info, so there is always one // leak if CallbackStub is used. BX_WARN(uint32_t(NULL != s_callbackStub ? 1 : 0) == m_numBlocks - , "MEMORY LEAK: %d (max: %d)" + , "\n\n" + "\n########################################################" + "\n" + "\nMEMORY LEAK: Number of leaked blocks %d (Max blocks: %d)" + "\n" + "\n########################################################" + "\n\n" , m_numBlocks , m_maxBlocks ); @@ -323,7 +371,6 @@ namespace bgfx const InternalData* getInternalData() { - BGFX_CHECK_RENDER_THREAD(); return &g_internalData; } @@ -341,7 +388,7 @@ namespace bgfx return rci->getInternal(_handle); } - uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint32_t _flags) + uintptr_t overrideInternal(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, TextureFormat::Enum _format, uint64_t _flags) { BGFX_CHECK_RENDER_THREAD(); RendererContextI* rci = s_ctx->m_renderCtx; @@ -355,7 +402,7 @@ namespace bgfx bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -366,7 +413,7 @@ namespace bgfx tc.m_format = _format; tc.m_cubeMap = false; tc.m_mem = NULL; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); rci->destroyTexture(_handle); rci->createTexture(_handle, mem, _flags, 0); @@ -404,7 +451,7 @@ namespace bgfx if (BX_UNLIKELY(NULL == g_callback) ) { - bx::debugPrintf("%s(%d): BGFX 0x%08x: %s", _filePath, _line, _code, out); + bx::debugPrintf("%s(%d): BGFX FATAL 0x%08x: %s", _filePath, _line, _code, out); abort(); } else @@ -488,34 +535,34 @@ namespace bgfx return handle; } - void dump(const VertexDecl& _decl) + void dump(const VertexLayout& _layout) { if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { - BX_TRACE("vertexdecl %08x (%08x), stride %d" - , _decl.m_hash - , bx::hash<bx::HashMurmur2A>(_decl.m_attributes) - , _decl.m_stride + BX_TRACE("VertexLayout %08x (%08x), stride %d" + , _layout.m_hash + , bx::hash<bx::HashMurmur2A>(_layout.m_attributes) + , _layout.m_stride ); for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - if (UINT16_MAX != _decl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); + _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); - BX_TRACE("\tattr %d - %s, num %d, type %d, norm %d, asint %d, offset %d" + BX_TRACE("\tattr %2d: %-20s num %d, type %d, norm [%c], asint [%c], offset %2d" , attr , getAttribName(Attrib::Enum(attr) ) , num , type - , normalized - , asInt - , _decl.m_offset[attr] + , normalized ? 'x' : ' ' + , asInt ? 'x' : ' ' + , _layout.m_offset[attr] ); } } @@ -625,7 +672,7 @@ namespace bgfx void TextVideoMemBlitter::init() { BGFX_CHECK_API_THREAD(); - m_decl + m_layout .begin() .add(Attrib::Position, 3, AttribType::Float) .add(Attrib::Color0, 4, AttribType::Uint8, true) @@ -645,20 +692,22 @@ namespace bgfx charsetFillTexture(vga8x8, rgba, 8, pitch, bpp); charsetFillTexture(vga8x16, &rgba[8*pitch], 16, pitch, bpp); m_texture = createTexture2D(width, height, false, 1, TextureFormat::R8 - , BGFX_SAMPLER_MIN_POINT - | BGFX_SAMPLER_MAG_POINT - | BGFX_SAMPLER_MIP_POINT - | BGFX_SAMPLER_U_CLAMP - | BGFX_SAMPLER_V_CLAMP - , mem - ); + , BGFX_SAMPLER_MIN_POINT + | BGFX_SAMPLER_MAG_POINT + | BGFX_SAMPLER_MIP_POINT + | BGFX_SAMPLER_U_CLAMP + | BGFX_SAMPLER_V_CLAMP + , mem + ); ShaderHandle vsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, "vs_debugfont"); ShaderHandle fsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, "fs_debugfont"); + BX_ASSERT(isValid(vsh) && isValid(fsh), "Failed to create embedded blit shaders"); + m_program = createProgram(vsh, fsh, true); - m_vb = s_ctx->createTransientVertexBuffer(numBatchVertices*m_decl.m_stride, &m_decl); + m_vb = s_ctx->createTransientVertexBuffer(numBatchVertices*m_layout.m_stride, &m_layout); m_ib = s_ctx->createTransientIndexBuffer(numBatchIndices*2); } @@ -676,6 +725,48 @@ namespace bgfx s_ctx->destroyTransientIndexBuffer(m_ib); } + static const uint32_t s_paletteSrgb[] = + { + 0x0, // Black + 0xffa46534, // Blue + 0xff069a4e, // Green + 0xff9a9806, // Cyan + 0xff0000cc, // Red + 0xff7b5075, // Magenta + 0xff00a0c4, // Brown + 0xffcfd7d3, // Light Gray + 0xff535755, // Dark Gray + 0xffcf9f72, // Light Blue + 0xff34e28a, // Light Green + 0xffe2e234, // Light Cyan + 0xff2929ef, // Light Red + 0xffa87fad, // Light Magenta + 0xff4fe9fc, // Yellow + 0xffeceeee, // White + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_paletteSrgb) == 16); + + static const uint32_t s_paletteLinear[] = + { + 0x0, // Black + 0xff5e2108, // Blue + 0xff005213, // Green + 0xff525000, // Cyan + 0xff000099, // Red + 0xff32142d, // Magenta + 0xff00598c, // Brown + 0xff9fada6, // Light Gray + 0xff161817, // Dark Gray + 0xff9f582a, // Light Blue + 0xff08c140, // Light Green + 0xffc1c108, // Light Cyan + 0xff0505dc, // Light Red + 0xff63366a, // Light Magenta + 0xff13cff8, // Yellow + 0xffd5dada // White + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_paletteLinear) == 16); + void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem) { struct Vertex @@ -689,40 +780,24 @@ namespace bgfx float m_v; }; - static uint32_t palette[] = - { - 0x0, // Black - 0xffa46534, // Blue - 0xff069a4e, // Green - 0xff9a9806, // Cyan - 0xff0000cc, // Red - 0xff7b5075, // Magenta - 0xff00a0c4, // Brown - 0xffcfd7d3, // Light Gray - 0xff535755, // Dark Gray - 0xffcf9f72, // Light Blue - 0xff34e28a, // Light Green - 0xffe2e234, // Light Cyan - 0xff2929ef, // Light Red - 0xffa87fad, // Light Magenta - 0xff4fe9fc, // Yellow - 0xffeceeee, // White - }; - BX_STATIC_ASSERT(BX_COUNTOF(palette) == 16); - uint32_t yy = 0; uint32_t xx = 0; - const float texelWidth = 1.0f/2048.0f; - const float texelWidthHalf = RendererType::Direct3D9 == g_caps.rendererType ? 0.0f : texelWidth*0.5f; - const float texelHeight = 1.0f/24.0f; + const float texelWidth = 1.0f/2048.0f; + const float texelWidthHalf = RendererType::Direct3D9 == g_caps.rendererType ? 0.0f : texelWidth*0.5f; + const float texelHeight = 1.0f/24.0f; const float texelHeightHalf = RendererType::Direct3D9 == g_caps.rendererType ? texelHeight*0.5f : 0.0f; - const float utop = (_mem.m_small ? 0.0f : 8.0f)*texelHeight + texelHeightHalf; - const float ubottom = (_mem.m_small ? 8.0f : 24.0f)*texelHeight + texelHeightHalf; + const float utop = (_mem.m_small ? 0.0f : 8.0f)*texelHeight + texelHeightHalf; + const float ubottom = (_mem.m_small ? 8.0f : 24.0f)*texelHeight + texelHeightHalf; const float fontHeight = (_mem.m_small ? 8.0f : 16.0f); _renderCtx->blitSetup(_blitter); + const uint32_t* palette = 0 != (s_ctx->m_init.resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) + ? s_paletteLinear + : s_paletteSrgb + ; + for (;yy < _mem.m_height;) { Vertex* vertex = (Vertex*)_blitter.m_vb->data; @@ -738,15 +813,18 @@ namespace bgfx for (; xx < _mem.m_width && numIndices < numBatchIndices; ++xx) { uint32_t ch = line->character; - uint8_t attr = line->attribute; + const uint8_t attr = line->attribute; + if (ch > 0xff) - ch = 0; // todo: render unicode code point , ch > 255) + { + ch = 0; + } if (0 != (ch|attr) && (' ' != ch || 0 != (attr&0xf0) ) ) { - uint32_t fg = palette[attr&0xf]; - uint32_t bg = palette[(attr>>4)&0xf]; + const uint32_t fg = palette[attr&0xf]; + const uint32_t bg = palette[(attr>>4)&0xf]; Vertex vert[4] = { @@ -772,7 +850,7 @@ namespace bgfx numIndices += 6; } - line ++; + line++; } if (numIndices >= numBatchIndices) @@ -791,27 +869,52 @@ namespace bgfx if (RendererType::Noop != g_caps.rendererType) { - m_decl + m_layout .begin() - .add(Attrib::Position, 3, AttribType::Float) + .add(Attrib::Position, 2, AttribType::Float) .end(); ShaderHandle vsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, "vs_clear"); + BX_ASSERT(isValid(vsh), "Failed to create clear quad embedded vertex shader \"vs_clear\""); for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii) { char name[32]; bx::snprintf(name, BX_COUNTOF(name), "fs_clear%d", ii); ShaderHandle fsh = createEmbeddedShader(s_embeddedShaders, g_caps.rendererType, name); + BX_ASSERT(isValid(fsh), "Failed to create clear quad embedded fragment shader \"%s\"", name); m_program[ii] = createProgram(vsh, fsh); - BX_CHECK(isValid(m_program[ii]), "Failed to create clear quad program."); + BX_ASSERT(isValid(m_program[ii]), "Failed to create clear quad program."); destroy(fsh); } destroy(vsh); - m_vb = s_ctx->createTransientVertexBuffer(4*m_decl.m_stride, &m_decl); + struct Vertex + { + float m_x; + float m_y; + }; + + const uint16_t stride = m_layout.m_stride; + const bgfx::Memory* mem = bgfx::alloc(4 * stride); + Vertex* vertex = (Vertex*)mem->data; + BX_ASSERT(stride == sizeof(Vertex), "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)", stride, sizeof(Vertex)); + + vertex->m_x = -1.0f; + vertex->m_y = -1.0f; + vertex++; + vertex->m_x = 1.0f; + vertex->m_y = -1.0f; + vertex++; + vertex->m_x = -1.0f; + vertex->m_y = 1.0f; + vertex++; + vertex->m_x = 1.0f; + vertex->m_y = 1.0f; + + m_vb = s_ctx->createVertexBuffer(mem, m_layout, 0); } } @@ -830,13 +933,13 @@ namespace bgfx } } - s_ctx->destroyTransientVertexBuffer(m_vb); + s_ctx->destroyVertexBuffer(m_vb); } } const char* s_uniformTypeName[] = { - "int1", + "sampler1", NULL, "vec4", "mat3", @@ -846,7 +949,7 @@ namespace bgfx const char* getUniformTypeName(UniformType::Enum _enum) { - BX_CHECK(_enum < UniformType::Count, "%d < UniformType::Count %d", _enum, UniformType::Count); + BX_ASSERT(_enum < UniformType::Count, "%d < UniformType::Count %d", _enum, UniformType::Count); return s_uniformTypeName[_enum]; } @@ -885,7 +988,7 @@ namespace bgfx return s_predefinedName[_enum]; } - PredefinedUniform::Enum nameToPredefinedUniformEnum(const char* _name) + PredefinedUniform::Enum nameToPredefinedUniformEnum(const bx::StringView& _name) { for (uint32_t ii = 0; ii < PredefinedUniform::Count; ++ii) { @@ -1117,10 +1220,10 @@ namespace bgfx } } - void EncoderImpl::submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, bool _preserveState) + void EncoderImpl::submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags) { if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) - && !_preserveState) + && (_flags & BGFX_DISCARD_STATE)) { m_uniformSet.clear(); } @@ -1128,7 +1231,7 @@ namespace bgfx if (BX_ENABLED(BGFX_CONFIG_DEBUG_OCCLUSION) && isValid(_occlusionQuery) ) { - BX_CHECK(m_occlusionQuerySet.end() == m_occlusionQuerySet.find(_occlusionQuery.idx) + BX_ASSERT(m_occlusionQuerySet.end() == m_occlusionQuerySet.find(_occlusionQuery.idx) , "OcclusionQuery %d was already used for this frame." , _occlusionQuery.idx ); @@ -1137,22 +1240,22 @@ namespace bgfx if (m_discard) { - discard(); + discard(_flags); return; } if (0 == m_draw.m_numVertices && 0 == m_draw.m_numIndices) { - discard(); + discard(_flags); ++m_numDropped; return; } const uint32_t renderItemIdx = bx::atomicFetchAndAddsat<uint32_t>(&m_frame->m_numRenderItems, 1, BGFX_CONFIG_MAX_DRAW_CALLS); - if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= renderItemIdx) + if (BGFX_CONFIG_MAX_DRAW_CALLS <= renderItemIdx) { - discard(); + discard(_flags); ++m_numDropped; return; } @@ -1162,20 +1265,20 @@ namespace bgfx UniformBuffer* uniformBuffer = m_frame->m_uniformBuffer[m_uniformIdx]; m_uniformEnd = uniformBuffer->getPos(); - m_key.m_program = kInvalidHandle == _program.idx - ? 0 - : _program.idx + m_key.m_program = isValid(_program) + ? _program + : ProgramHandle{0} ; m_key.m_view = _id; - SortKey::Enum type = SortKey::SortProgram; + SortKey::Enum type; switch (s_ctx->m_view[_id].m_mode) { case ViewMode::Sequential: m_key.m_seq = s_ctx->getSeqIncr(_id); type = SortKey::SortSequence; break; case ViewMode::DepthAscending: m_key.m_depth = _depth; type = SortKey::SortDepth; break; case ViewMode::DepthDescending: m_key.m_depth = UINT32_MAX-_depth; type = SortKey::SortDepth; break; - default: break; + default: m_key.m_depth = _depth; type = SortKey::SortProgram; break; } uint64_t key = m_key.encodeDraw(type); @@ -1190,11 +1293,12 @@ namespace bgfx if (UINT8_MAX != m_draw.m_streamMask) { uint32_t numVertices = UINT32_MAX; - for (uint32_t idx = 0, streamMask = m_draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = m_draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ; streamMask >>= 1, idx += 1 ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; numVertices = bx::min(numVertices, m_numVertices[idx]); @@ -1216,10 +1320,10 @@ namespace bgfx m_frame->m_renderItem[renderItemIdx].draw = m_draw; m_frame->m_renderItemBind[renderItemIdx] = m_bind; - if (!_preserveState) + m_draw.clear(_flags); + m_bind.clear(_flags); + if (_flags & BGFX_DISCARD_STATE) { - m_draw.clear(); - m_bind.clear(); m_uniformBegin = m_uniformEnd; } } @@ -1233,14 +1337,14 @@ namespace bgfx if (m_discard) { - discard(); + discard(_flags); return; } const uint32_t renderItemIdx = bx::atomicFetchAndAddsat<uint32_t>(&m_frame->m_numRenderItems, 1, BGFX_CONFIG_MAX_DRAW_CALLS); if (BGFX_CONFIG_MAX_DRAW_CALLS-1 <= renderItemIdx) { - discard(); + discard(_flags); ++m_numDropped; return; } @@ -1255,9 +1359,8 @@ namespace bgfx m_compute.m_numX = bx::max(_numX, 1u); m_compute.m_numY = bx::max(_numY, 1u); m_compute.m_numZ = bx::max(_numZ, 1u); - m_compute.m_submitFlags = _flags; - m_key.m_program = _handle.idx; + m_key.m_program = _handle; m_key.m_depth = 0; m_key.m_view = _id; m_key.m_seq = s_ctx->getSeqIncr(_id); @@ -1272,8 +1375,8 @@ namespace bgfx m_frame->m_renderItem[renderItemIdx].compute = m_compute; m_frame->m_renderItemBind[renderItemIdx] = m_bind; - m_compute.clear(); - m_bind.clear(); + m_compute.clear(_flags); + m_bind.clear(_flags); m_uniformBegin = m_uniformEnd; } @@ -1317,18 +1420,49 @@ namespace bgfx for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { viewRemap[m_viewRemap[ii] ] = ViewId(ii); + + View& view = m_view[ii]; + Rect rect(0, 0, uint16_t(m_resolution.width), uint16_t(m_resolution.height) ); + + if (isValid(view.m_fbh) ) + { + const FrameBufferRef& fbr = s_ctx->m_frameBufferRef[view.m_fbh.idx]; + const BackbufferRatio::Enum bbRatio = fbr.m_window + ? BackbufferRatio::Count + : BackbufferRatio::Enum(s_ctx->m_textureRef[fbr.un.m_th[0].idx].m_bbRatio) + ; + + if (BackbufferRatio::Count != bbRatio) + { + getTextureSizeFromRatio(bbRatio, rect.m_width, rect.m_height); + } + else + { + rect.m_width = fbr.m_width; + rect.m_height = fbr.m_height; + } + } + + view.m_rect.intersect(rect); + + if (!view.m_scissor.isZero() ) + { + view.m_scissor.intersect(rect); + } } for (uint32_t ii = 0, num = m_numRenderItems; ii < num; ++ii) { m_sortKeys[ii] = SortKey::remapView(m_sortKeys[ii], viewRemap); } + bx::radixSort(m_sortKeys, s_ctx->m_tempKeys, m_sortValues, s_ctx->m_tempValues, m_numRenderItems); for (uint32_t ii = 0, num = m_numBlitItems; ii < num; ++ii) { m_blitKeys[ii] = BlitKey::remapView(m_blitKeys[ii], viewRemap); } + bx::radixSort(m_blitKeys, (uint32_t*)&s_ctx->m_tempKeys, m_numBlitItems); } @@ -1364,7 +1498,7 @@ namespace bgfx return result; } - BX_CHECK(false, "This call only makes sense if used with multi-threaded renderer."); + BX_ASSERT(false, "This call only makes sense if used with multi-threaded renderer."); return RenderFrame::NoContext; } @@ -1419,6 +1553,7 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_GRAPHICS_DEBUGGER), CAPS_FLAGS(BGFX_CAPS_HDR10), CAPS_FLAGS(BGFX_CAPS_HIDPI), + CAPS_FLAGS(BGFX_CAPS_IMAGE_RW), CAPS_FLAGS(BGFX_CAPS_INDEX32), CAPS_FLAGS(BGFX_CAPS_INSTANCING), CAPS_FLAGS(BGFX_CAPS_OCCLUSION_QUERY), @@ -1427,6 +1562,7 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_TEXTURE_2D_ARRAY), CAPS_FLAGS(BGFX_CAPS_TEXTURE_3D), CAPS_FLAGS(BGFX_CAPS_TEXTURE_BLIT), + CAPS_FLAGS(BGFX_CAPS_TRANSPARENT_BACKBUFFER), CAPS_FLAGS(BGFX_CAPS_TEXTURE_COMPARE_ALL), CAPS_FLAGS(BGFX_CAPS_TEXTURE_COMPARE_LEQUAL), CAPS_FLAGS(BGFX_CAPS_TEXTURE_CUBE_ARRAY), @@ -1435,6 +1571,7 @@ namespace bgfx CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_HALF), CAPS_FLAGS(BGFX_CAPS_VERTEX_ATTRIB_UINT10), CAPS_FLAGS(BGFX_CAPS_VERTEX_ID), + CAPS_FLAGS(BGFX_CAPS_VIEWPORT_LAYER_ARRAY), #undef CAPS_FLAGS }; @@ -1463,6 +1600,9 @@ namespace bgfx BX_TRACE(""); } + BX_TRACE("GPU device, Device ID: %04x, Vendor ID: %04x", g_caps.deviceId, g_caps.vendorId); + BX_TRACE(""); + RendererType::Enum renderers[RendererType::Count]; uint8_t num = getSupportedRenderers(BX_COUNTOF(renderers), renderers); @@ -1474,48 +1614,49 @@ namespace bgfx BX_TRACE(""); BX_TRACE("Sort key masks:"); - BX_TRACE("\t View %016" PRIx64, SORT_KEY_VIEW_MASK); - BX_TRACE("\t Draw bit %016" PRIx64, SORT_KEY_DRAW_BIT); + BX_TRACE("\t View %016" PRIx64, kSortKeyViewMask); + BX_TRACE("\t Draw bit %016" PRIx64, kSortKeyDrawBit); BX_TRACE(""); - BX_TRACE("\tD Type %016" PRIx64, SORT_KEY_DRAW_TYPE_MASK); + BX_TRACE("\tD Type %016" PRIx64, kSortKeyDrawTypeMask); BX_TRACE(""); - BX_TRACE("\tD0 Trans %016" PRIx64, SORT_KEY_DRAW_0_TRANS_MASK); - BX_TRACE("\tD0 Program %016" PRIx64, SORT_KEY_DRAW_0_PROGRAM_MASK); - BX_TRACE("\tD0 Depth %016" PRIx64, SORT_KEY_DRAW_0_DEPTH_MASK); + BX_TRACE("\tD0 Blend %016" PRIx64, kSortKeyDraw0BlendMask); + BX_TRACE("\tD0 Program %016" PRIx64, kSortKeyDraw0ProgramMask); + BX_TRACE("\tD0 Depth %016" PRIx64, kSortKeyDraw0DepthMask); BX_TRACE(""); - BX_TRACE("\tD1 Depth %016" PRIx64, SORT_KEY_DRAW_1_DEPTH_MASK); - BX_TRACE("\tD1 Trans %016" PRIx64, SORT_KEY_DRAW_1_TRANS_MASK); - BX_TRACE("\tD1 Program %016" PRIx64, SORT_KEY_DRAW_1_PROGRAM_MASK); + BX_TRACE("\tD1 Depth %016" PRIx64, kSortKeyDraw1DepthMask); + BX_TRACE("\tD1 Blend %016" PRIx64, kSortKeyDraw1BlendMask); + BX_TRACE("\tD1 Program %016" PRIx64, kSortKeyDraw1ProgramMask); BX_TRACE(""); - BX_TRACE("\tD2 Seq %016" PRIx64, SORT_KEY_DRAW_2_SEQ_MASK); - BX_TRACE("\tD2 Trans %016" PRIx64, SORT_KEY_DRAW_2_TRANS_MASK); - BX_TRACE("\tD2 Program %016" PRIx64, SORT_KEY_DRAW_2_PROGRAM_MASK); + BX_TRACE("\tD2 Seq %016" PRIx64, kSortKeyDraw2SeqMask); + BX_TRACE("\tD2 Blend %016" PRIx64, kSortKeyDraw2BlendMask); + BX_TRACE("\tD2 Program %016" PRIx64, kSortKeyDraw2ProgramMask); BX_TRACE(""); - BX_TRACE("\t C Seq %016" PRIx64, SORT_KEY_COMPUTE_SEQ_MASK); - BX_TRACE("\t C Program %016" PRIx64, SORT_KEY_COMPUTE_PROGRAM_MASK); + BX_TRACE("\t C Seq %016" PRIx64, kSortKeyComputeSeqMask); + BX_TRACE("\t C Program %016" PRIx64, kSortKeyComputeProgramMask); BX_TRACE(""); - BX_TRACE("Supported capabilities (renderer %s, vendor 0x%04x, device 0x%04x):" + BX_TRACE("Capabilities (renderer %s, vendor 0x%04x, device 0x%04x):" , s_ctx->m_renderCtx->getRendererName() , g_caps.vendorId , g_caps.deviceId ); for (uint32_t ii = 0; ii < BX_COUNTOF(s_capsFlags); ++ii) { - if (0 != (g_caps.supported & s_capsFlags[ii].m_flag) ) - { - BX_TRACE("\t%s", s_capsFlags[ii].m_str); - } + BX_TRACE("\t[%c] %s" + , 0 != (g_caps.supported & s_capsFlags[ii].m_flag) ? 'x' : ' ' + , s_capsFlags[ii].m_str + ); } + BX_UNUSED(s_capsFlags); BX_TRACE(""); BX_TRACE("Limits:"); -#define LIMITS(_x) BX_TRACE("\t%-24s %d", #_x, g_caps.limits._x) +#define LIMITS(_x) BX_TRACE("\t%-24s%10d", #_x, g_caps.limits._x) LIMITS(maxDrawCalls); LIMITS(maxBlits); LIMITS(maxTextureSize); @@ -1528,7 +1669,7 @@ namespace bgfx LIMITS(maxTextures); LIMITS(maxTextureSamplers); LIMITS(maxComputeBindings); - LIMITS(maxVertexDecls); + LIMITS(maxVertexLayouts); LIMITS(maxVertexStreams); LIMITS(maxIndexBuffers); LIMITS(maxVertexBuffers); @@ -1537,6 +1678,7 @@ namespace bgfx LIMITS(maxUniforms); LIMITS(maxOcclusionQueries); LIMITS(maxEncoders); + LIMITS(minResourceCbSize); LIMITS(transientVbSize); LIMITS(transientIbSize); #undef LIMITS @@ -1550,7 +1692,7 @@ namespace bgfx BX_TRACE("\t ||||+------------ Cube: x = supported / * = emulated"); BX_TRACE("\t |||||+----------- Cube: sRGB format"); BX_TRACE("\t ||||||+---------- vertex format"); - BX_TRACE("\t |||||||+--------- image"); + BX_TRACE("\t |||||||+--------- image: i = read-write / r = read / w = write"); BX_TRACE("\t ||||||||+-------- framebuffer"); BX_TRACE("\t |||||||||+------- MSAA framebuffer"); BX_TRACE("\t ||||||||||+------ MSAA texture"); @@ -1561,7 +1703,7 @@ namespace bgfx if (TextureFormat::Unknown != ii && TextureFormat::UnknownDepth != ii) { - uint16_t flags = g_caps.formats[ii]; + uint32_t flags = g_caps.formats[ii]; BX_TRACE("\t[%c%c%c%c%c%c%c%c%c%c%c%c] %s" , flags&BGFX_CAPS_FORMAT_TEXTURE_2D ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_2D_EMULATED ? '*' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ? 'l' : ' ' @@ -1570,7 +1712,8 @@ namespace bgfx , flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE ? 'x' : flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED ? '*' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB ? 'l' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_VERTEX ? 'v' : ' ' - , flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE ? 'i' : ' ' + , (flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ) && + (flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE) ? 'i' : flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ ? 'r' : flags&BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE ? 'w' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER ? 'f' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA ? '+' : ' ' , flags&BGFX_CAPS_FORMAT_TEXTURE_MSAA ? 'm' : ' ' @@ -1590,6 +1733,38 @@ namespace bgfx BX_TRACE(""); } + void dump(const Resolution& _resolution) + { + const uint32_t reset = _resolution.reset; + const uint32_t msaa = (reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + BX_UNUSED(reset, msaa); + + BX_TRACE("Reset back-buffer swap chain:"); + BX_TRACE("\t%dx%d, format: %s, numBackBuffers: %d, maxFrameLatency: %d" + , _resolution.width + , _resolution.height + , TextureFormat::Count == _resolution.format + ? "*default*" + : bimg::getName(bimg::TextureFormat::Enum(_resolution.format) ) + , _resolution.numBackBuffers + , _resolution.maxFrameLatency + ); + + BX_TRACE("\t[%c] MSAAx%d", 0 != msaa ? 'x' : ' ', 1<<msaa); + BX_TRACE("\t[%c] Fullscreen", 0 != (reset & BGFX_RESET_FULLSCREEN) ? 'x' : ' '); + BX_TRACE("\t[%c] V-sync", 0 != (reset & BGFX_RESET_VSYNC) ? 'x' : ' '); + BX_TRACE("\t[%c] Max Anisotropy", 0 != (reset & BGFX_RESET_MAXANISOTROPY) ? 'x' : ' '); + BX_TRACE("\t[%c] Capture", 0 != (reset & BGFX_RESET_CAPTURE) ? 'x' : ' '); + BX_TRACE("\t[%c] Flush After Render", 0 != (reset & BGFX_RESET_FLUSH_AFTER_RENDER) ? 'x' : ' '); + BX_TRACE("\t[%c] Flip After Render", 0 != (reset & BGFX_RESET_FLIP_AFTER_RENDER) ? 'x' : ' '); + BX_TRACE("\t[%c] sRGB Back Buffer", 0 != (reset & BGFX_RESET_SRGB_BACKBUFFER) ? 'x' : ' '); + BX_TRACE("\t[%c] Transparent Back Buffer", 0 != (reset & BGFX_RESET_TRANSPARENT_BACKBUFFER) ? 'x' : ' '); + BX_TRACE("\t[%c] HDR10", 0 != (reset & BGFX_RESET_HDR10) ? 'x' : ' '); + BX_TRACE("\t[%c] Hi-DPI", 0 != (reset & BGFX_RESET_HIDPI) ? 'x' : ' '); + BX_TRACE("\t[%c] Depth Clamp", 0 != (reset & BGFX_RESET_DEPTH_CLAMP) ? 'x' : ' '); + BX_TRACE("\t[%c] Suspend", 0 != (reset & BGFX_RESET_SUSPEND) ? 'x' : ' '); + } + TextureFormat::Enum getViableTextureFormat(const bimg::ImageContainer& _imageContainer) { const uint32_t formatCaps = g_caps.formats[_imageContainer.m_format]; @@ -1632,6 +1807,11 @@ namespace bgfx return s_ctx->m_uniformRef[_handle.idx].m_name.getPtr(); } + const char* getName(ShaderHandle _handle) + { + return s_ctx->m_shaderRef[_handle.idx].m_name.getPtr(); + } + static const char* s_topologyName[] = { "Triangles", @@ -1662,7 +1842,7 @@ namespace bgfx return "Vertex"; } - BX_CHECK(false, "Invalid shader type!"); + BX_ASSERT(false, "Invalid shader type!"); return NULL; } @@ -1688,45 +1868,56 @@ namespace bgfx TextureFormat::ATCE, TextureFormat::ATCI, TextureFormat::ASTC4x4, + TextureFormat::ASTC5x4, TextureFormat::ASTC5x5, + TextureFormat::ASTC6x5, TextureFormat::ASTC6x6, TextureFormat::ASTC8x5, TextureFormat::ASTC8x6, + TextureFormat::ASTC8x8, TextureFormat::ASTC10x5, + TextureFormat::ASTC10x6, + TextureFormat::ASTC10x8, + TextureFormat::ASTC10x10, + TextureFormat::ASTC12x10, + TextureFormat::ASTC12x12, TextureFormat::BGRA8, // GL doesn't support BGRA8 without extensions. TextureFormat::RGBA8, // D3D9 doesn't support RGBA8 }; bool Context::init(const Init& _init) { - BX_CHECK(!m_rendererInitialized, "Already initialized?"); + BX_ASSERT(!m_rendererInitialized, "Already initialized?"); m_init = _init; m_init.resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; + m_init.resolution.numBackBuffers = bx::clamp<uint8_t>(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS); + m_init.resolution.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY); + dump(m_init.resolution); - if (g_platformData.ndt == NULL - && g_platformData.nwh == NULL - && g_platformData.context == NULL - && g_platformData.backBuffer == NULL - && g_platformData.backBufferDS == NULL) - { - bx::memCopy(&g_platformData, &m_init.platformData, sizeof(PlatformData) ); - } - else + if (true + && RendererType::Noop != m_init.type + && NULL == m_init.platformData.ndt + && NULL == m_init.platformData.nwh + && NULL == m_init.platformData.context + && NULL == m_init.platformData.backBuffer + && NULL == m_init.platformData.backBufferDS + ) { - bx::memCopy(&m_init.platformData, &g_platformData, sizeof(PlatformData) ); + BX_TRACE("bgfx platform data like window handle or backbuffer is not set, creating headless device."); } + bx::memCopy(&g_platformData, &m_init.platformData, sizeof(PlatformData) ); + m_exit = false; m_flipped = true; - m_frames = 0; m_debug = BGFX_DEBUG_NONE; m_frameTimeLast = bx::getHPCounter(); - m_submit->create(); + m_submit->create(_init.limits.minResourceCbSize); #if BGFX_CONFIG_MULTITHREADED - m_render->create(); + m_render->create(_init.limits.minResourceCbSize); if (s_renderFrameCalled) { @@ -1770,7 +1961,7 @@ namespace bgfx m_clearColor[ii][3] = 1.0f; } - m_declRef.init(); + m_vertexLayoutRef.init(); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RendererInit); cmdbuf.write(_init); @@ -1778,7 +1969,7 @@ namespace bgfx frameNoRenderWait(); m_encoderHandle = bx::createHandleAlloc(g_allocator, _init.limits.maxEncoders); - m_encoder = (EncoderImpl*)BX_ALLOC(g_allocator, sizeof(EncoderImpl)*_init.limits.maxEncoders); + m_encoder = (EncoderImpl*)BX_ALIGNED_ALLOC(g_allocator, sizeof(EncoderImpl)*_init.limits.maxEncoders, BX_ALIGNOF(EncoderImpl) ); m_encoderStats = (EncoderStats*)BX_ALLOC(g_allocator, sizeof(EncoderStats)*_init.limits.maxEncoders); for (uint32_t ii = 0, num = _init.limits.maxEncoders; ii < num; ++ii) { @@ -1786,9 +1977,12 @@ namespace bgfx } uint16_t idx = m_encoderHandle->alloc(); - BX_CHECK(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx); + BX_ASSERT(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx); m_encoder[0].begin(m_submit, 0); - m_encoder0 = reinterpret_cast<Encoder*>(&m_encoder[0]); + m_encoder0 = BX_ENABLED(BGFX_CONFIG_ENCODER_API_ONLY) + ? NULL + : reinterpret_cast<Encoder*>(&m_encoder[0]) + ; // Make sure renderer init is called from render thread. // g_caps is initialized and available after this point. @@ -1799,7 +1993,7 @@ namespace bgfx getCommandBuffer(CommandBuffer::RendererShutdownEnd); frame(); frame(); - m_declRef.shutdown(m_vertexDeclHandle); + m_vertexLayoutRef.shutdown(m_layoutHandle); m_submit->destroy(); #if BGFX_CONFIG_MULTITHREADED m_render->destroy(); @@ -1826,6 +2020,7 @@ namespace bgfx g_caps.rendererType = m_renderCtx->getRendererType(); initAttribTypeSizeTable(g_caps.rendererType); + g_caps.supported &= _init.capabilities; g_caps.supported |= 0 | (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) && !m_singleThreaded ? BGFX_CAPS_RENDERER_MULTITHREADED : 0) | (isGraphicsDebuggerPresent() ? BGFX_CAPS_GRAPHICS_DEBUGGER : 0) @@ -1870,7 +2065,7 @@ namespace bgfx frame(); } - frame(); // If any VertexDecls needs to be destroyed. + frame(); // If any VertexLayouts needs to be destroyed. getCommandBuffer(CommandBuffer::RendererShutdownEnd); frame(); @@ -1884,19 +2079,21 @@ namespace bgfx { m_encoder[ii].~EncoderImpl(); } - BX_FREE(g_allocator, m_encoder); + + BX_ALIGNED_FREE(g_allocator, m_encoder, BX_ALIGNOF(EncoderImpl) ); BX_FREE(g_allocator, m_encoderStats); m_dynVertexBufferAllocator.compact(); m_dynIndexBufferAllocator.compact(); - BX_CHECK(m_vertexDeclHandle.getNumHandles() == m_declRef.m_vertexDeclMap.getNumElements() - , "VertexDeclRef mismatch, num handles %d, handles in hash map %d." - , m_vertexDeclHandle.getNumHandles() - , m_declRef.m_vertexDeclMap.getNumElements() - ); + BX_ASSERT( + m_layoutHandle.getNumHandles() == m_vertexLayoutRef.m_vertexLayoutMap.getNumElements() + , "VertexLayoutRef mismatch, num handles %d, handles in hash map %d." + , m_layoutHandle.getNumHandles() + , m_vertexLayoutRef.m_vertexLayoutMap.getNumElements() + ); - m_declRef.shutdown(m_vertexDeclHandle); + m_vertexLayoutRef.shutdown(m_layoutHandle); #if BGFX_CONFIG_MULTITHREADED // Render thread shutdown sequence. @@ -1920,11 +2117,12 @@ namespace bgfx if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) { -#define CHECK_HANDLE_LEAK(_handleAlloc) \ +#define CHECK_HANDLE_LEAK(_name, _handleAlloc) \ BX_MACRO_BLOCK_BEGIN \ if (0 != _handleAlloc.getNumHandles() ) \ { \ - BX_TRACE("LEAK: " #_handleAlloc " %d (max: %d)" \ + BX_TRACE("LEAK: %s %d (max: %d)" \ + , _name \ , _handleAlloc.getNumHandles() \ , _handleAlloc.getMaxHandles() \ ); \ @@ -1935,11 +2133,34 @@ namespace bgfx } \ BX_MACRO_BLOCK_END -#define CHECK_HANDLE_LEAK_NAME(_handleAlloc, _type, _ref) \ +#define CHECK_HANDLE_LEAK_NAME(_name, _handleAlloc, _type, _ref) \ BX_MACRO_BLOCK_BEGIN \ if (0 != _handleAlloc.getNumHandles() ) \ { \ - BX_TRACE("LEAK: " #_handleAlloc " %d (max: %d)" \ + BX_TRACE("LEAK: %s %d (max: %d)" \ + , _name \ + , _handleAlloc.getNumHandles() \ + , _handleAlloc.getMaxHandles() \ + ); \ + for (uint16_t ii = 0, num = _handleAlloc.getNumHandles(); ii < num; ++ii) \ + { \ + uint16_t idx = _handleAlloc.getHandleAt(ii); \ + const _type& ref = _ref[idx]; BX_UNUSED(ref); \ + BX_TRACE("\t%3d: %4d %s" \ + , ii \ + , idx \ + , ref.m_name.getPtr() \ + ); \ + } \ + } \ + BX_MACRO_BLOCK_END + +#define CHECK_HANDLE_LEAK_RC_NAME(_name, _handleAlloc, _type, _ref) \ + BX_MACRO_BLOCK_BEGIN \ + if (0 != _handleAlloc.getNumHandles() ) \ + { \ + BX_TRACE("LEAK: %s %d (max: %d)" \ + , _name \ , _handleAlloc.getNumHandles() \ , _handleAlloc.getMaxHandles() \ ); \ @@ -1948,26 +2169,26 @@ namespace bgfx uint16_t idx = _handleAlloc.getHandleAt(ii); \ const _type& ref = _ref[idx]; BX_UNUSED(ref); \ BX_TRACE("\t%3d: %4d %s (count %d)" \ - , ii \ - , idx \ - , ref.m_name.getPtr() \ - , ref.m_refCount \ - ); \ + , ii \ + , idx \ + , ref.m_name.getPtr() \ + , ref.m_refCount \ + ); \ } \ } \ BX_MACRO_BLOCK_END - CHECK_HANDLE_LEAK (m_dynamicIndexBufferHandle ); - CHECK_HANDLE_LEAK (m_dynamicVertexBufferHandle ); - CHECK_HANDLE_LEAK (m_indexBufferHandle ); - CHECK_HANDLE_LEAK (m_vertexDeclHandle ); - CHECK_HANDLE_LEAK (m_vertexBufferHandle ); - CHECK_HANDLE_LEAK_NAME(m_shaderHandle, ShaderRef, m_shaderRef ); - CHECK_HANDLE_LEAK (m_programHandle ); - CHECK_HANDLE_LEAK_NAME(m_textureHandle, TextureRef, m_textureRef); - CHECK_HANDLE_LEAK (m_frameBufferHandle ); - CHECK_HANDLE_LEAK_NAME(m_uniformHandle, UniformRef, m_uniformRef); - CHECK_HANDLE_LEAK (m_occlusionQueryHandle ); + CHECK_HANDLE_LEAK ("DynamicIndexBufferHandle", m_dynamicIndexBufferHandle ); + CHECK_HANDLE_LEAK ("DynamicVertexBufferHandle", m_dynamicVertexBufferHandle ); + CHECK_HANDLE_LEAK_NAME ("IndexBufferHandle", m_indexBufferHandle, IndexBuffer, m_indexBuffers ); + CHECK_HANDLE_LEAK ("VertexLayoutHandle", m_layoutHandle ); + CHECK_HANDLE_LEAK_NAME ("VertexBufferHandle", m_vertexBufferHandle, VertexBuffer, m_vertexBuffers ); + CHECK_HANDLE_LEAK_RC_NAME("ShaderHandle", m_shaderHandle, ShaderRef, m_shaderRef ); + CHECK_HANDLE_LEAK ("ProgramHandle", m_programHandle ); + CHECK_HANDLE_LEAK_RC_NAME("TextureHandle", m_textureHandle, TextureRef, m_textureRef ); + CHECK_HANDLE_LEAK_NAME ("FrameBufferHandle", m_frameBufferHandle, FrameBufferRef, m_frameBufferRef); + CHECK_HANDLE_LEAK_RC_NAME("UniformHandle", m_uniformHandle, UniformRef, m_uniformRef ); + CHECK_HANDLE_LEAK ("OcclusionQueryHandle", m_occlusionQueryHandle ); #undef CHECK_HANDLE_LEAK #undef CHECK_HANDLE_LEAK_NAME } @@ -2006,9 +2227,9 @@ namespace bgfx destroyVertexBufferInternal(_frame->m_freeVertexBuffer.get(ii)); } - for (uint16_t ii = 0, num = _frame->m_freeVertexDecl.getNumQueued(); ii < num; ++ii) + for (uint16_t ii = 0, num = _frame->m_freeVertexLayout.getNumQueued(); ii < num; ++ii) { - m_vertexDeclHandle.free(_frame->m_freeVertexDecl.get(ii).idx); + m_layoutHandle.free(_frame->m_freeVertexLayout.get(ii).idx); } for (uint16_t ii = 0, num = _frame->m_freeShader.getNumQueued(); ii < num; ++ii) @@ -2091,6 +2312,8 @@ namespace bgfx m_submit->m_capture = _capture; + uint32_t frameNum = m_submit->m_frameNum; + BGFX_PROFILER_SCOPE("bgfx/API thread frame", 0xff2040ff); // wait for render thread to finish renderSemWait(); @@ -2098,7 +2321,7 @@ namespace bgfx m_encoder[0].begin(m_submit, 0); - return m_frames; + return frameNum; } void Context::frameNoRenderWait() @@ -2141,8 +2364,8 @@ namespace bgfx renderFrame(); } - m_frames++; - m_submit->start(); + uint32_t nextFrameNum = m_render->m_frameNum + 1; + m_submit->start(nextFrameNum); bx::memSet(m_seq, 0, sizeof(m_seq) ); @@ -2184,10 +2407,34 @@ namespace bgfx } } +#if BX_PLATFORM_OSX || BX_PLATFORM_IOS + struct NSAutoreleasePoolScope + { + NSAutoreleasePoolScope() + { + id obj = class_createInstance(objc_getClass("NSAutoreleasePool"), 0); + typedef id(*objc_msgSend_init)(void*, SEL); + pool = ((objc_msgSend_init)objc_msgSend)(obj, sel_getUid("init") ); + } + + ~NSAutoreleasePoolScope() + { + typedef void(*objc_msgSend_release)(void*, SEL); + ((objc_msgSend_release)objc_msgSend)(pool, sel_getUid("release") ); + } + + id pool; + }; +#endif // BX_PLATFORM_OSX + RenderFrame::Enum Context::renderFrame(int32_t _msecs) { BGFX_PROFILER_SCOPE("bgfx::renderFrame", 0xff2040ff); +#if BX_PLATFORM_OSX || BX_PLATFORM_IOS + NSAutoreleasePoolScope pool; +#endif // BX_PLATFORM_OSX + if (!m_flipAfterRender) { BGFX_PROFILER_SCOPE("bgfx/flip", 0xff2040ff); @@ -2203,9 +2450,20 @@ namespace bgfx if (m_rendererInitialized) { - BGFX_PROFILER_SCOPE("bgfx/Render submit", 0xff2040ff); - m_renderCtx->submit(m_render, m_clearQuad, m_textVideoMemBlitter); - m_flipped = false; + { + BGFX_PROFILER_SCOPE("bgfx/Render submit", 0xff2040ff); + m_renderCtx->submit(m_render, m_clearQuad, m_textVideoMemBlitter); + m_flipped = false; + } + + { + BGFX_PROFILER_SCOPE("bgfx/Screenshot", 0xff2040ff); + for (uint8_t ii = 0, num = m_render->m_numScreenShots; ii < num; ++ii) + { + const ScreenShot& screenShot = m_render->m_screenShot[ii]; + m_renderCtx->requestScreenShot(screenShot.handle, screenShot.filePath.getCPtr() ); + } + } } { @@ -2265,7 +2523,7 @@ namespace bgfx } else { - _renderCtx->setMarker(data, size); + _renderCtx->setMarker(data, uint16_t(size)-1); } } } @@ -2344,13 +2602,16 @@ namespace bgfx } BGFX_RENDERER_CONTEXT(noop); + BGFX_RENDERER_CONTEXT(agc); BGFX_RENDERER_CONTEXT(d3d9); BGFX_RENDERER_CONTEXT(d3d11); BGFX_RENDERER_CONTEXT(d3d12); + BGFX_RENDERER_CONTEXT(gnm); BGFX_RENDERER_CONTEXT(mtl); + BGFX_RENDERER_CONTEXT(nvn); BGFX_RENDERER_CONTEXT(gl); BGFX_RENDERER_CONTEXT(vk); - BGFX_RENDERER_CONTEXT(gnm); + BGFX_RENDERER_CONTEXT(webgpu); #undef BGFX_RENDERER_CONTEXT @@ -2364,19 +2625,22 @@ namespace bgfx static RendererCreator s_rendererCreator[] = { - { noop::rendererCreate, noop::rendererDestroy, BGFX_RENDERER_NOOP_NAME, true }, // Noop - { d3d9::rendererCreate, d3d9::rendererDestroy, BGFX_RENDERER_DIRECT3D9_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9 - { d3d11::rendererCreate, d3d11::rendererDestroy, BGFX_RENDERER_DIRECT3D11_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11 - { d3d12::rendererCreate, d3d12::rendererDestroy, BGFX_RENDERER_DIRECT3D12_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D12 }, // Direct3D12 - { gnm::rendererCreate, gnm::rendererDestroy, BGFX_RENDERER_GNM_NAME, !!BGFX_CONFIG_RENDERER_GNM }, // GNM + { noop::rendererCreate, noop::rendererDestroy, BGFX_RENDERER_NOOP_NAME, true }, // Noop + { agc::rendererCreate, agc::rendererDestroy, BGFX_RENDERER_AGC_NAME, !!BGFX_CONFIG_RENDERER_AGC }, // GNM + { d3d9::rendererCreate, d3d9::rendererDestroy, BGFX_RENDERER_DIRECT3D9_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9 + { d3d11::rendererCreate, d3d11::rendererDestroy, BGFX_RENDERER_DIRECT3D11_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11 + { d3d12::rendererCreate, d3d12::rendererDestroy, BGFX_RENDERER_DIRECT3D12_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D12 }, // Direct3D12 + { gnm::rendererCreate, gnm::rendererDestroy, BGFX_RENDERER_GNM_NAME, !!BGFX_CONFIG_RENDERER_GNM }, // GNM #if BX_PLATFORM_OSX || BX_PLATFORM_IOS - { mtl::rendererCreate, mtl::rendererDestroy, BGFX_RENDERER_METAL_NAME, !!BGFX_CONFIG_RENDERER_METAL }, // Metal + { mtl::rendererCreate, mtl::rendererDestroy, BGFX_RENDERER_METAL_NAME, !!BGFX_CONFIG_RENDERER_METAL }, // Metal #else - { noop::rendererCreate, noop::rendererDestroy, BGFX_RENDERER_NOOP_NAME, false }, // Noop + { noop::rendererCreate, noop::rendererDestroy, BGFX_RENDERER_NOOP_NAME, false }, // Noop #endif // BX_PLATFORM_OSX || BX_PLATFORM_IOS - { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES - { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL - { vk::rendererCreate, vk::rendererDestroy, BGFX_RENDERER_VULKAN_NAME, !!BGFX_CONFIG_RENDERER_VULKAN }, // Vulkan + { nvn::rendererCreate, nvn::rendererDestroy, BGFX_RENDERER_NVN_NAME, !!BGFX_CONFIG_RENDERER_NVN }, // NVN + { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES + { gl::rendererCreate, gl::rendererDestroy, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL + { vk::rendererCreate, vk::rendererDestroy, BGFX_RENDERER_VULKAN_NAME, !!BGFX_CONFIG_RENDERER_VULKAN }, // Vulkan + { webgpu::rendererCreate, webgpu::rendererDestroy, BGFX_RENDERER_WEBGPU_NAME, !!BGFX_CONFIG_RENDERER_WEBGPU }, // WebGPU }; BX_STATIC_ASSERT(BX_COUNTOF(s_rendererCreator) == RendererType::Count); @@ -2408,11 +2672,6 @@ namespace bgfx #endif // BX_PLATFORM_WINDOWS } - static int32_t compareDescending(const void* _lhs, const void* _rhs) - { - return *(const int32_t*)_rhs - *(const int32_t*)_lhs; - } - RendererContextI* rendererCreate(const Init& _init) { int32_t scores[RendererType::Count]; @@ -2451,8 +2710,12 @@ namespace bgfx } else if (BX_ENABLED(BX_PLATFORM_LINUX) ) { - score += RendererType::OpenGL == renderer ? 20 : 0; - score += RendererType::OpenGLES == renderer ? 10 : 0; + score += RendererType::Vulkan == renderer ? 50 : 0; + score += RendererType::OpenGL == renderer ? 40 : 0; + score += RendererType::OpenGLES == renderer ? 30 : 0; + score += RendererType::Direct3D12 == renderer ? 20 : 0; + score += RendererType::Direct3D11 == renderer ? 10 : 0; + score += RendererType::Direct3D9 == renderer ? 5 : 0; } else if (BX_ENABLED(BX_PLATFORM_OSX) ) { @@ -2489,7 +2752,7 @@ namespace bgfx } } - bx::quickSort(scores, numScores, sizeof(int32_t), compareDescending); + bx::quickSort(scores, numScores, bx::compareDescending<int32_t>); RendererContextI* renderCtx = NULL; for (uint32_t ii = 0; ii < numScores; ++ii) @@ -2537,11 +2800,11 @@ namespace bgfx default: { - BX_CHECK(CommandBuffer::RendererInit == command + BX_ASSERT(CommandBuffer::RendererInit == command , "RendererInit must be the first command in command buffer before initialization. Unexpected command %d?" , command ); - BX_CHECK(!m_rendererInitialized, "This shouldn't happen! Bad synchronization?"); + BX_ASSERT(!m_rendererInitialized, "This shouldn't happen! Bad synchronization?"); Init init; _cmdbuf.read(init); @@ -2553,7 +2816,7 @@ namespace bgfx if (!m_rendererInitialized) { _cmdbuf.read(command); - BX_CHECK(CommandBuffer::End == command, "Unexpected command %d?" + BX_ASSERT(CommandBuffer::End == command, "Unexpected command %d?" , command ); return; @@ -2572,14 +2835,14 @@ namespace bgfx { case CommandBuffer::RendererShutdownBegin: { - BX_CHECK(m_rendererInitialized, "This shouldn't happen! Bad synchronization?"); + BX_ASSERT(m_rendererInitialized, "This shouldn't happen! Bad synchronization?"); m_rendererInitialized = false; } break; case CommandBuffer::RendererShutdownEnd: { - BX_CHECK(!m_rendererInitialized && !m_exit, "This shouldn't happen! Bad synchronization?"); + BX_ASSERT(!m_rendererInitialized && !m_exit, "This shouldn't happen! Bad synchronization?"); rendererDestroy(m_renderCtx); m_renderCtx = NULL; @@ -2594,6 +2857,8 @@ namespace bgfx case CommandBuffer::CreateIndexBuffer: { + BGFX_PROFILER_SCOPE("CreateIndexBuffer", 0xff2040ff); + IndexBufferHandle handle; _cmdbuf.read(handle); @@ -2611,6 +2876,8 @@ namespace bgfx case CommandBuffer::DestroyIndexBuffer: { + BGFX_PROFILER_SCOPE("DestroyIndexBuffer", 0xff2040ff); + IndexBufferHandle handle; _cmdbuf.read(handle); @@ -2618,42 +2885,48 @@ namespace bgfx } break; - case CommandBuffer::CreateVertexDecl: + case CommandBuffer::CreateVertexLayout: { - VertexDeclHandle handle; + BGFX_PROFILER_SCOPE("CreateVertexLayout", 0xff2040ff); + + VertexLayoutHandle handle; _cmdbuf.read(handle); - VertexDecl decl; - _cmdbuf.read(decl); + VertexLayout layout; + _cmdbuf.read(layout); - m_renderCtx->createVertexDecl(handle, decl); + m_renderCtx->createVertexLayout(handle, layout); } break; - case CommandBuffer::DestroyVertexDecl: + case CommandBuffer::DestroyVertexLayout: { - VertexDeclHandle handle; + BGFX_PROFILER_SCOPE("DestroyVertexLayout", 0xff2040ff); + + VertexLayoutHandle handle; _cmdbuf.read(handle); - m_renderCtx->destroyVertexDecl(handle); + m_renderCtx->destroyVertexLayout(handle); } break; case CommandBuffer::CreateVertexBuffer: { + BGFX_PROFILER_SCOPE("CreateVertexBuffer", 0xff2040ff); + VertexBufferHandle handle; _cmdbuf.read(handle); const Memory* mem; _cmdbuf.read(mem); - VertexDeclHandle declHandle; - _cmdbuf.read(declHandle); + VertexLayoutHandle layoutHandle; + _cmdbuf.read(layoutHandle); uint16_t flags; _cmdbuf.read(flags); - m_renderCtx->createVertexBuffer(handle, mem, declHandle, flags); + m_renderCtx->createVertexBuffer(handle, mem, layoutHandle, flags); release(mem); } @@ -2661,6 +2934,8 @@ namespace bgfx case CommandBuffer::DestroyVertexBuffer: { + BGFX_PROFILER_SCOPE("DestroyVertexBuffer", 0xff2040ff); + VertexBufferHandle handle; _cmdbuf.read(handle); @@ -2670,6 +2945,8 @@ namespace bgfx case CommandBuffer::CreateDynamicIndexBuffer: { + BGFX_PROFILER_SCOPE("CreateDynamicIndexBuffer", 0xff2040ff); + IndexBufferHandle handle; _cmdbuf.read(handle); @@ -2685,6 +2962,8 @@ namespace bgfx case CommandBuffer::UpdateDynamicIndexBuffer: { + BGFX_PROFILER_SCOPE("UpdateDynamicIndexBuffer", 0xff2040ff); + IndexBufferHandle handle; _cmdbuf.read(handle); @@ -2705,6 +2984,8 @@ namespace bgfx case CommandBuffer::DestroyDynamicIndexBuffer: { + BGFX_PROFILER_SCOPE("DestroyDynamicIndexBuffer", 0xff2040ff); + IndexBufferHandle handle; _cmdbuf.read(handle); @@ -2714,6 +2995,8 @@ namespace bgfx case CommandBuffer::CreateDynamicVertexBuffer: { + BGFX_PROFILER_SCOPE("CreateDynamicVertexBuffer", 0xff2040ff); + VertexBufferHandle handle; _cmdbuf.read(handle); @@ -2729,6 +3012,8 @@ namespace bgfx case CommandBuffer::UpdateDynamicVertexBuffer: { + BGFX_PROFILER_SCOPE("UpdateDynamicVertexBuffer", 0xff2040ff); + VertexBufferHandle handle; _cmdbuf.read(handle); @@ -2749,6 +3034,8 @@ namespace bgfx case CommandBuffer::DestroyDynamicVertexBuffer: { + BGFX_PROFILER_SCOPE("DestroyDynamicVertexBuffer", 0xff2040ff); + VertexBufferHandle handle; _cmdbuf.read(handle); @@ -2758,6 +3045,8 @@ namespace bgfx case CommandBuffer::CreateShader: { + BGFX_PROFILER_SCOPE("CreateShader", 0xff2040ff); + ShaderHandle handle; _cmdbuf.read(handle); @@ -2772,6 +3061,8 @@ namespace bgfx case CommandBuffer::DestroyShader: { + BGFX_PROFILER_SCOPE("DestroyShader", 0xff2040ff); + ShaderHandle handle; _cmdbuf.read(handle); @@ -2781,6 +3072,8 @@ namespace bgfx case CommandBuffer::CreateProgram: { + BGFX_PROFILER_SCOPE("CreateProgram", 0xff2040ff); + ProgramHandle handle; _cmdbuf.read(handle); @@ -2796,6 +3089,8 @@ namespace bgfx case CommandBuffer::DestroyProgram: { + BGFX_PROFILER_SCOPE("DestroyProgram", 0xff2040ff); + ProgramHandle handle; _cmdbuf.read(handle); @@ -2805,6 +3100,8 @@ namespace bgfx case CommandBuffer::CreateTexture: { + BGFX_PROFILER_SCOPE("CreateTexture", 0xff2040ff); + TextureHandle handle; _cmdbuf.read(handle); @@ -2824,14 +3121,15 @@ namespace bgfx } bx::MemoryReader reader(mem->data, mem->size); + bx::Error err; uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, &err); if (BGFX_CHUNK_MAGIC_TEX == magic) { TextureCreate tc; - bx::read(&reader, tc); + bx::read(&reader, tc, &err); if (NULL != tc.m_mem) { @@ -2845,6 +3143,8 @@ namespace bgfx case CommandBuffer::UpdateTexture: { + BGFX_PROFILER_SCOPE("UpdateTexture", 0xff2040ff); + if (m_textureUpdateBatch.isFull() ) { flushTextureUpdateBatch(_cmdbuf); @@ -2878,6 +3178,8 @@ namespace bgfx case CommandBuffer::ReadTexture: { + BGFX_PROFILER_SCOPE("ReadTexture", 0xff2040ff); + TextureHandle handle; _cmdbuf.read(handle); @@ -2893,6 +3195,8 @@ namespace bgfx case CommandBuffer::ResizeTexture: { + BGFX_PROFILER_SCOPE("ResizeTexture", 0xff2040ff); + TextureHandle handle; _cmdbuf.read(handle); @@ -2914,6 +3218,8 @@ namespace bgfx case CommandBuffer::DestroyTexture: { + BGFX_PROFILER_SCOPE("DestroyTexture", 0xff2040ff); + TextureHandle handle; _cmdbuf.read(handle); @@ -2923,6 +3229,8 @@ namespace bgfx case CommandBuffer::CreateFrameBuffer: { + BGFX_PROFILER_SCOPE("CreateFrameBuffer", 0xff2040ff); + FrameBufferHandle handle; _cmdbuf.read(handle); @@ -2963,6 +3271,8 @@ namespace bgfx case CommandBuffer::DestroyFrameBuffer: { + BGFX_PROFILER_SCOPE("DestroyFrameBuffer", 0xff2040ff); + FrameBufferHandle handle; _cmdbuf.read(handle); @@ -2972,6 +3282,8 @@ namespace bgfx case CommandBuffer::CreateUniform: { + BGFX_PROFILER_SCOPE("CreateUniform", 0xff2040ff); + UniformHandle handle; _cmdbuf.read(handle); @@ -2992,6 +3304,8 @@ namespace bgfx case CommandBuffer::DestroyUniform: { + BGFX_PROFILER_SCOPE("DestroyUniform", 0xff2040ff); + UniformHandle handle; _cmdbuf.read(handle); @@ -2999,22 +3313,10 @@ namespace bgfx } break; - case CommandBuffer::RequestScreenShot: - { - FrameBufferHandle handle; - _cmdbuf.read(handle); - - uint16_t len; - _cmdbuf.read(len); - - const char* filePath = (const char*)_cmdbuf.skip(len); - - m_renderCtx->requestScreenShot(handle, filePath); - } - break; - case CommandBuffer::UpdateViewName: { + BGFX_PROFILER_SCOPE("UpdateViewName", 0xff2040ff); + ViewId id; _cmdbuf.read(id); @@ -3029,6 +3331,8 @@ namespace bgfx case CommandBuffer::InvalidateOcclusionQuery: { + BGFX_PROFILER_SCOPE("InvalidateOcclusionQuery", 0xff2040ff); + OcclusionQueryHandle handle; _cmdbuf.read(handle); @@ -3038,6 +3342,8 @@ namespace bgfx case CommandBuffer::SetName: { + BGFX_PROFILER_SCOPE("SetName", 0xff2040ff); + Handle handle; _cmdbuf.read(handle); @@ -3046,12 +3352,12 @@ namespace bgfx const char* name = (const char*)_cmdbuf.skip(len); - m_renderCtx->setName(handle, name); + m_renderCtx->setName(handle, name, len-1); } break; default: - BX_CHECK(false, "Invalid command: %d", command); + BX_ASSERT(false, "Invalid command: %d", command); break; } } while (!end); @@ -3059,6 +3365,11 @@ namespace bgfx flushTextureUpdateBatch(_cmdbuf); } + uint32_t weldVertices(void* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon) + { + return weldVertices(_output, _layout, _data, _num, _index32, _epsilon, g_allocator); + } + uint32_t topologyConvert(TopologyConvert::Enum _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32) { return topologyConvert(_conversion, _dst, _dstSize, _indices, _numIndices, _index32, g_allocator); @@ -3101,7 +3412,7 @@ namespace bgfx const char* getRendererName(RendererType::Enum _type) { - BX_CHECK(_type < RendererType::Count, "Invalid renderer type %d.", _type); + BX_ASSERT(_type < RendererType::Count, "Invalid renderer type %d.", _type); return s_rendererCreator[_type].name; } @@ -3111,6 +3422,7 @@ namespace bgfx , context(NULL) , backBuffer(NULL) , backBufferDS(NULL) + , type(NativeWindowHandleType::Default) { } @@ -3124,30 +3436,37 @@ namespace bgfx { } + Init::Limits::Limits() + : maxEncoders(BGFX_CONFIG_DEFAULT_MAX_ENCODERS) + , minResourceCbSize(BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE) + , transientVbSize(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE) + , transientIbSize(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE) + { + } + Init::Init() : type(RendererType::Count) , vendorId(BGFX_PCI_ID_NONE) , deviceId(0) + , capabilities(UINT64_MAX) , debug(BX_ENABLED(BGFX_CONFIG_DEBUG) ) - , profile(BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + , profile(BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) , callback(NULL) , allocator(NULL) { - limits.maxEncoders = BGFX_CONFIG_DEFAULT_MAX_ENCODERS; - limits.transientVbSize = BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE; - limits.transientIbSize = BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE; } - void Attachment::init(TextureHandle _handle, Access::Enum _access, uint16_t _layer, uint16_t _mip, uint8_t _resolve) + void Attachment::init(TextureHandle _handle, Access::Enum _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve) { - access = _access; - handle = _handle; - mip = _mip; - layer = _layer; - resolve = _resolve; + access = _access; + handle = _handle; + mip = _mip; + layer = _layer; + numLayers = _numLayers; + resolve = _resolve; } - bool init(const Init& _init) + bool init(const Init& _userInit) { if (NULL != s_ctx) { @@ -3155,12 +3474,10 @@ namespace bgfx return false; } - if (1 > _init.limits.maxEncoders - || 128 < _init.limits.maxEncoders) - { - BX_TRACE("init.limits.maxEncoders must be between 1 and 128."); - return false; - } + Init init = _userInit; + + init.limits.maxEncoders = bx::clamp<uint16_t>(init.limits.maxEncoders, 1, (0 != BGFX_CONFIG_MULTITHREADED) ? 128 : 1); + init.limits.minResourceCbSize = bx::min<uint32_t>(init.limits.minResourceCbSize, BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE); struct ErrorState { @@ -3173,9 +3490,9 @@ namespace bgfx ErrorState::Enum errorState = ErrorState::Default; - if (NULL != _init.allocator) + if (NULL != init.allocator) { - g_allocator = _init.allocator; + g_allocator = init.allocator; } else { @@ -3184,9 +3501,9 @@ namespace bgfx s_allocatorStub = BX_NEW(&allocator, AllocatorStub); } - if (NULL != _init.callback) + if (NULL != init.callback) { - g_callback = _init.callback; + g_callback = init.callback; } else { @@ -3194,19 +3511,6 @@ namespace bgfx s_callbackStub = BX_NEW(g_allocator, CallbackStub); } - if (true - && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN || BX_PLATFORM_PS4) - && RendererType::Noop != _init.type - && NULL == _init.platformData.ndt - && NULL == _init.platformData.nwh - && NULL == _init.platformData.context - && NULL == _init.platformData.backBuffer - && NULL == _init.platformData.backBufferDS - ) - { - BX_TRACE("bgfx platform data like window handle or backbuffer is not set, creating headless device."); - } - bx::memSet(&g_caps, 0, sizeof(g_caps) ); g_caps.limits.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS; g_caps.limits.maxBlits = BGFX_CONFIG_MAX_BLIT_ITEMS; @@ -3219,7 +3523,7 @@ namespace bgfx g_caps.limits.maxTextures = BGFX_CONFIG_MAX_TEXTURES; g_caps.limits.maxTextureSamplers = BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; g_caps.limits.maxComputeBindings = 0; - g_caps.limits.maxVertexDecls = BGFX_CONFIG_MAX_VERTEX_DECLS; + g_caps.limits.maxVertexLayouts = BGFX_CONFIG_MAX_VERTEX_LAYOUTS; g_caps.limits.maxVertexStreams = 1; g_caps.limits.maxIndexBuffers = BGFX_CONFIG_MAX_INDEX_BUFFERS; g_caps.limits.maxVertexBuffers = BGFX_CONFIG_MAX_VERTEX_BUFFERS; @@ -3228,31 +3532,38 @@ namespace bgfx g_caps.limits.maxUniforms = BGFX_CONFIG_MAX_UNIFORMS; g_caps.limits.maxOcclusionQueries = BGFX_CONFIG_MAX_OCCLUSION_QUERIES; g_caps.limits.maxFBAttachments = 1; - g_caps.limits.maxEncoders = (0 != BGFX_CONFIG_MULTITHREADED) ? _init.limits.maxEncoders : 1; - g_caps.limits.transientVbSize = _init.limits.transientVbSize; - g_caps.limits.transientIbSize = _init.limits.transientIbSize; + g_caps.limits.maxEncoders = init.limits.maxEncoders; + g_caps.limits.minResourceCbSize = init.limits.minResourceCbSize; + g_caps.limits.transientVbSize = init.limits.transientVbSize; + g_caps.limits.transientIbSize = init.limits.transientIbSize; - g_caps.vendorId = _init.vendorId; - g_caps.deviceId = _init.deviceId; + g_caps.vendorId = init.vendorId; + g_caps.deviceId = init.deviceId; BX_TRACE("Init..."); + // bgfx 1.104.7082 + // ^ ^^^ ^^^^ + // | | +--- Commit number (https://github.com/bkaradzic/bgfx / git rev-list --count HEAD) + // | +------- API version (from https://github.com/bkaradzic/bgfx/blob/master/scripts/bgfx.idl#L4) + // +--------- Major revision (always 1) + BX_TRACE("Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")", BGFX_API_VERSION, BGFX_REV_NUMBER); + errorState = ErrorState::ContextAllocated; - s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 64); - if (s_ctx->init(_init) ) + s_ctx = BX_ALIGNED_NEW(g_allocator, Context, Context::kAlignment); + if (s_ctx->init(init) ) { BX_TRACE("Init complete."); return true; } -//error: BX_TRACE("Init failed."); switch (errorState) { case ErrorState::ContextAllocated: - BX_ALIGNED_DELETE(g_allocator, s_ctx, 64); + BX_ALIGNED_DELETE(g_allocator, s_ctx, Context::kAlignment); s_ctx = NULL; BX_FALLTHROUGH; @@ -3270,7 +3581,6 @@ namespace bgfx s_allocatorStub = NULL; } - s_renderFrameCalled = false; s_threadIndex = 0; g_callback = NULL; g_allocator = NULL; @@ -3287,9 +3597,9 @@ namespace bgfx BGFX_CHECK_API_THREAD(); Context* ctx = s_ctx; // it's going to be NULLd inside shutdown. ctx->shutdown(); - BX_CHECK(NULL == s_ctx, "bgfx is should be uninitialized here."); + BX_ASSERT(NULL == s_ctx, "bgfx is should be uninitialized here."); - BX_ALIGNED_DELETE(g_allocator, ctx, 16); + BX_ALIGNED_DELETE(g_allocator, ctx, Context::kAlignment); BX_TRACE("Shutdown complete."); @@ -3311,7 +3621,6 @@ namespace bgfx s_allocatorStub = NULL; } - s_renderFrameCalled = false; s_threadIndex = 0; g_callback = NULL; g_allocator = NULL; @@ -3320,7 +3629,7 @@ namespace bgfx void reset(uint32_t _width, uint32_t _height, uint32_t _flags, TextureFormat::Enum _format) { BGFX_CHECK_API_THREAD(); - BX_CHECK(0 == (_flags&BGFX_RESET_RESERVED_MASK), "Do not set reset reserved flags!"); + BX_ASSERT(0 == (_flags&BGFX_RESET_RESERVED_MASK), "Do not set reset reserved flags!"); s_ctx->reset(_width, _height, _flags, _format); } @@ -3338,7 +3647,7 @@ namespace bgfx void Encoder::setState(uint64_t _state, uint32_t _rgba) { - BX_CHECK(0 == (_state&BGFX_STATE_RESERVED_MASK), "Do not set state reserved flags!"); + BX_ASSERT(0 == (_state&BGFX_STATE_RESERVED_MASK), "Do not set state reserved flags!"); BGFX_ENCODER(setState(_state, _rgba) ); } @@ -3381,9 +3690,9 @@ namespace bgfx void Encoder::setUniform(UniformHandle _handle, const void* _value, uint16_t _num) { BGFX_CHECK_HANDLE("setUniform", s_ctx->m_uniformHandle, _handle); - const Context::UniformRef& uniform = s_ctx->m_uniformRef[_handle.idx]; - BX_CHECK(isValid(_handle) && 0 < uniform.m_refCount, "Setting invalid uniform (handle %3d)!", _handle.idx); - BX_CHECK(_num == UINT16_MAX || uniform.m_num >= _num, "Truncated uniform update. %d (max: %d)", _num, uniform.m_num); + const UniformRef& uniform = s_ctx->m_uniformRef[_handle.idx]; + BX_ASSERT(isValid(_handle) && 0 < uniform.m_refCount, "Setting invalid uniform (handle %3d)!", _handle.idx); + BX_ASSERT(_num == UINT16_MAX || uniform.m_num >= _num, "Truncated uniform update. %d (max: %d)", _num, uniform.m_num); BGFX_ENCODER(setUniform(uniform.m_type, _handle, _value, UINT16_MAX != _num ? _num : uniform.m_num) ); } @@ -3395,7 +3704,8 @@ namespace bgfx void Encoder::setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) { BGFX_CHECK_HANDLE("setIndexBuffer", s_ctx->m_indexBufferHandle, _handle); - BGFX_ENCODER(setIndexBuffer(_handle, _firstIndex, _numIndices) ); + const IndexBuffer& ib = s_ctx->m_indexBuffers[_handle.idx]; + BGFX_ENCODER(setIndexBuffer(_handle, ib, _firstIndex, _numIndices) ); } void Encoder::setIndexBuffer(DynamicIndexBufferHandle _handle) @@ -3417,15 +3727,22 @@ namespace bgfx void Encoder::setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) { - BX_CHECK(NULL != _tib, "_tib can't be NULL"); + BX_ASSERT(NULL != _tib, "_tib can't be NULL"); BGFX_CHECK_HANDLE("setIndexBuffer", s_ctx->m_indexBufferHandle, _tib->handle); BGFX_ENCODER(setIndexBuffer(_tib, _firstIndex, _numIndices) ); } - void Encoder::setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) + void Encoder::setVertexBuffer( + uint8_t _stream + , VertexBufferHandle _handle + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { BGFX_CHECK_HANDLE("setVertexBuffer", s_ctx->m_vertexBufferHandle, _handle); - BGFX_ENCODER(setVertexBuffer(_stream, _handle, _startVertex, _numVertices) ); + BGFX_CHECK_HANDLE_INVALID_OK("setVertexBuffer", s_ctx->m_layoutHandle, _layoutHandle); + BGFX_ENCODER(setVertexBuffer(_stream, _handle, _startVertex, _numVertices, _layoutHandle) ); } void Encoder::setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle) @@ -3433,11 +3750,18 @@ namespace bgfx setVertexBuffer(_stream, _handle, 0, UINT32_MAX); } - void Encoder::setVertexBuffer(uint8_t _stream, DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) + void Encoder::setVertexBuffer( + uint8_t _stream + , DynamicVertexBufferHandle _handle + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { BGFX_CHECK_HANDLE("setVertexBuffer", s_ctx->m_dynamicVertexBufferHandle, _handle); + BGFX_CHECK_HANDLE_INVALID_OK("setVertexBuffer", s_ctx->m_layoutHandle, _layoutHandle); const DynamicVertexBuffer& dvb = s_ctx->m_dynamicVertexBuffers[_handle.idx]; - BGFX_ENCODER(setVertexBuffer(_stream, dvb, _startVertex, _numVertices) ); + BGFX_ENCODER(setVertexBuffer(_stream, dvb, _startVertex, _numVertices, _layoutHandle) ); } void Encoder::setVertexBuffer(uint8_t _stream, DynamicVertexBufferHandle _handle) @@ -3445,11 +3769,18 @@ namespace bgfx setVertexBuffer(_stream, _handle, 0, UINT32_MAX); } - void Encoder::setVertexBuffer(uint8_t _stream, const TransientVertexBuffer* _tvb, uint32_t _startVertex, uint32_t _numVertices) + void Encoder::setVertexBuffer( + uint8_t _stream + , const TransientVertexBuffer* _tvb + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { - BX_CHECK(NULL != _tvb, "_tvb can't be NULL"); + BX_ASSERT(NULL != _tvb, "_tvb can't be NULL"); BGFX_CHECK_HANDLE("setVertexBuffer", s_ctx->m_vertexBufferHandle, _tvb->handle); - BGFX_ENCODER(setVertexBuffer(_stream, _tvb, _startVertex, _numVertices) ); + BGFX_CHECK_HANDLE_INVALID_OK("setVertexBuffer", s_ctx->m_layoutHandle, _layoutHandle); + BGFX_ENCODER(setVertexBuffer(_stream, _tvb, _startVertex, _numVertices, _layoutHandle) ); } void Encoder::setVertexBuffer(uint8_t _stream, const TransientVertexBuffer* _tvb) @@ -3470,7 +3801,7 @@ namespace bgfx void Encoder::setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _start, uint32_t _num) { - BX_CHECK(NULL != _idb, "_idb can't be NULL"); + BX_ASSERT(NULL != _idb, "_idb can't be NULL"); BGFX_ENCODER(setInstanceDataBuffer(_idb, _start, _num) ); } @@ -3502,59 +3833,79 @@ namespace bgfx { BGFX_CHECK_HANDLE("setTexture/UniformHandle", s_ctx->m_uniformHandle, _sampler); BGFX_CHECK_HANDLE_INVALID_OK("setTexture/TextureHandle", s_ctx->m_textureHandle, _handle); - BX_CHECK(_stage < g_caps.limits.maxTextureSamplers, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxTextureSamplers); + BX_ASSERT(_stage < g_caps.limits.maxTextureSamplers, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxTextureSamplers); + + if (isValid(_handle) ) + { + const TextureRef& ref = s_ctx->m_textureRef[_handle.idx]; + BX_ASSERT(!ref.isReadBack() + , "Can't sample from texture which was created with BGFX_TEXTURE_READ_BACK. This is CPU only texture." + ); + BX_UNUSED(ref); + } + BGFX_ENCODER(setTexture(_stage, _sampler, _handle, _flags) ); } void Encoder::touch(ViewId _id) { - ProgramHandle handle = BGFX_INVALID_HANDLE; - submit(_id, handle); + discard(); + submit(_id, BGFX_INVALID_HANDLE); } - void Encoder::submit(ViewId _id, ProgramHandle _program, uint32_t _depth, bool _preserveState) + void Encoder::submit(ViewId _id, ProgramHandle _program, uint32_t _depth, uint8_t _flags) { OcclusionQueryHandle handle = BGFX_INVALID_HANDLE; - submit(_id, _program, handle, _depth, _preserveState); + submit(_id, _program, handle, _depth, _flags); } - void Encoder::submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, bool _preserveState) + void Encoder::submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags) { - BX_CHECK(false + BX_ASSERT(false || !isValid(_occlusionQuery) || 0 != (g_caps.supported & BGFX_CAPS_OCCLUSION_QUERY) , "Occlusion query is not supported! Use bgfx::getCaps to check BGFX_CAPS_OCCLUSION_QUERY backend renderer capabilities." ); BGFX_CHECK_HANDLE_INVALID_OK("submit", s_ctx->m_programHandle, _program); BGFX_CHECK_HANDLE_INVALID_OK("submit", s_ctx->m_occlusionQueryHandle, _occlusionQuery); - BGFX_ENCODER(submit(_id, _program, _occlusionQuery, _depth, _preserveState) ); + BGFX_ENCODER(submit(_id, _program, _occlusionQuery, _depth, _flags) ); + } + + void Encoder::submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags) + { + BGFX_CHECK_HANDLE_INVALID_OK("submit", s_ctx->m_programHandle, _program); + BGFX_CHECK_HANDLE("submit", s_ctx->m_vertexBufferHandle, _indirectHandle); + BGFX_CHECK_CAPS(BGFX_CAPS_DRAW_INDIRECT, "Draw indirect is not supported!"); + BGFX_ENCODER(submit(_id, _program, _indirectHandle, _start, _num, _depth, _flags) ); } - void Encoder::submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, bool _preserveState) + void Encoder::submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, IndexBufferHandle _numHandle, uint32_t _numIndex, uint16_t _numMax, uint32_t _depth, uint8_t _flags) { BGFX_CHECK_HANDLE_INVALID_OK("submit", s_ctx->m_programHandle, _program); BGFX_CHECK_HANDLE("submit", s_ctx->m_vertexBufferHandle, _indirectHandle); + BGFX_CHECK_HANDLE("submit", s_ctx->m_indexBufferHandle, _numHandle); BGFX_CHECK_CAPS(BGFX_CAPS_DRAW_INDIRECT, "Draw indirect is not supported!"); - BGFX_ENCODER(submit(_id, _program, _indirectHandle, _start, _num, _depth, _preserveState) ); + BGFX_CHECK_CAPS(BGFX_CAPS_DRAW_INDIRECT_COUNT, "Draw indirect count is not supported!"); + BGFX_ENCODER(submit(_id, _program, _indirectHandle, _start, _numHandle, _numIndex, _numMax, _depth, _flags) ); } void Encoder::setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) { - BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); + BX_ASSERT(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_indexBufferHandle, _handle); BGFX_ENCODER(setBuffer(_stage, _handle, _access) ); } void Encoder::setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access) { - BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); + BX_ASSERT(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_vertexBufferHandle, _handle); BGFX_ENCODER(setBuffer(_stage, _handle, _access) ); } void Encoder::setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access) { - BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); + BX_ASSERT(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_dynamicIndexBufferHandle, _handle); const DynamicIndexBuffer& dib = s_ctx->m_dynamicIndexBuffers[_handle.idx]; BGFX_ENCODER(setBuffer(_stage, dib.m_handle, _access) ); @@ -3562,7 +3913,7 @@ namespace bgfx void Encoder::setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access) { - BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); + BX_ASSERT(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_dynamicVertexBufferHandle, _handle); const DynamicVertexBuffer& dvb = s_ctx->m_dynamicVertexBuffers[_handle.idx]; BGFX_ENCODER(setBuffer(_stage, dvb.m_handle, _access) ); @@ -3570,7 +3921,7 @@ namespace bgfx void Encoder::setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access) { - BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); + BX_ASSERT(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE("setBuffer", s_ctx->m_vertexBufferHandle, _handle); VertexBufferHandle handle = { _handle.idx }; BGFX_ENCODER(setBuffer(_stage, handle, _access) ); @@ -3578,15 +3929,27 @@ namespace bgfx void Encoder::setImage(uint8_t _stage, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) { - BX_CHECK(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); + BX_ASSERT(_stage < g_caps.limits.maxComputeBindings, "Invalid stage %d (max %d).", _stage, g_caps.limits.maxComputeBindings); BGFX_CHECK_HANDLE_INVALID_OK("setImage/TextureHandle", s_ctx->m_textureHandle, _handle); _format = TextureFormat::Count == _format ? TextureFormat::Enum(s_ctx->m_textureRef[_handle.idx].m_format) : _format ; - BX_CHECK(_format != TextureFormat::BGRA8 + BX_ASSERT(_format != TextureFormat::BGRA8 , "Can't use TextureFormat::BGRA8 with compute, use TextureFormat::RGBA8 instead." ); + + if (isValid(_handle) ) + { + const TextureRef& ref = s_ctx->m_textureRef[_handle.idx]; + BX_ASSERT(!ref.isReadBack() + , "Can't texture (handle %d, '%S') which was created with BGFX_TEXTURE_READ_BACK with compute. This is CPU only texture." + , _handle.idx + , &ref.m_name + ); + BX_UNUSED(ref); + } + BGFX_ENCODER(setImage(_stage, _handle, _mip, _access, _format) ); } @@ -3606,9 +3969,9 @@ namespace bgfx BGFX_ENCODER(dispatch(_id, _program, _indirectHandle, _start, _num, _flags) ); } - void Encoder::discard() + void Encoder::discard(uint8_t _flags) { - BGFX_ENCODER(discard() ); + BGFX_ENCODER(discard(_flags) ); } void Encoder::blit(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height) @@ -3621,15 +3984,55 @@ namespace bgfx BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_BLIT, "Texture blit is not supported!"); BGFX_CHECK_HANDLE("blit/src TextureHandle", s_ctx->m_textureHandle, _src); BGFX_CHECK_HANDLE("blit/dst TextureHandle", s_ctx->m_textureHandle, _dst); - const Context::TextureRef& src = s_ctx->m_textureRef[_src.idx]; - const Context::TextureRef& dst = s_ctx->m_textureRef[_dst.idx]; - BX_CHECK(src.m_format == dst.m_format + + const TextureRef& src = s_ctx->m_textureRef[_src.idx]; + const TextureRef& dst = s_ctx->m_textureRef[_dst.idx]; + + BX_ASSERT(dst.isBlitDst() + , "Blit destination texture (handle %d, '%S') is not created with `BGFX_TEXTURE_BLIT_DST` flag." + , _dst.idx + , &dst.m_name + ); + + BX_ASSERT(src.m_format == dst.m_format , "Texture format must match (src %s, dst %s)." , bimg::getName(bimg::TextureFormat::Enum(src.m_format) ) , bimg::getName(bimg::TextureFormat::Enum(dst.m_format) ) ); - BX_UNUSED(src, dst); - BGFX_ENCODER(blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth) ); + BX_ASSERT(_srcMip < src.m_numMips, "Invalid blit src mip (%d > %d)", _srcMip, src.m_numMips - 1); + BX_ASSERT(_dstMip < dst.m_numMips, "Invalid blit dst mip (%d > %d)", _dstMip, dst.m_numMips - 1); + + uint32_t srcWidth = bx::max<uint32_t>(1, src.m_width >> _srcMip); + uint32_t srcHeight = bx::max<uint32_t>(1, src.m_height >> _srcMip); + uint32_t dstWidth = bx::max<uint32_t>(1, dst.m_width >> _dstMip); + uint32_t dstHeight = bx::max<uint32_t>(1, dst.m_height >> _dstMip); + + uint32_t srcDepth = src.isCubeMap() ? 6 : bx::max<uint32_t>(1, src.m_depth >> _srcMip); + uint32_t dstDepth = dst.isCubeMap() ? 6 : bx::max<uint32_t>(1, dst.m_depth >> _dstMip); + + BX_ASSERT(_srcX < srcWidth && _srcY < srcHeight && _srcZ < srcDepth + , "Blit src coordinates out of range (%d, %d, %d) >= (%d, %d, %d)" + , _srcX, _srcY, _srcZ + , srcWidth, srcHeight, srcDepth + ); + BX_ASSERT(_dstX < dstWidth && _dstY < dstHeight && _dstZ < dstDepth + , "Blit dst coordinates out of range (%d, %d, %d) >= (%d, %d, %d)" + , _dstX, _dstY, _dstZ + , dstWidth, dstHeight, dstDepth + ); + + srcWidth = bx::min<uint32_t>(srcWidth, _srcX + _width ) - _srcX; + srcHeight = bx::min<uint32_t>(srcHeight, _srcY + _height) - _srcY; + srcDepth = bx::min<uint32_t>(srcDepth, _srcZ + _depth ) - _srcZ; + dstWidth = bx::min<uint32_t>(dstWidth, _dstX + _width ) - _dstX; + dstHeight = bx::min<uint32_t>(dstHeight, _dstY + _height) - _dstY; + dstDepth = bx::min<uint32_t>(dstDepth, _dstZ + _depth ) - _dstZ; + + const uint16_t width = uint16_t(bx::min(srcWidth, dstWidth ) ); + const uint16_t height = uint16_t(bx::min(srcHeight, dstHeight) ); + const uint16_t depth = uint16_t(bx::min(srcDepth, dstDepth ) ); + + BGFX_ENCODER(blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, width, height, depth) ); } #undef BGFX_ENCODER @@ -3662,7 +4065,7 @@ namespace bgfx const Memory* alloc(uint32_t _size) { - BX_CHECK(0 < _size, "Invalid memory operation. _size is 0."); + BX_ASSERT(0 < _size, "Invalid memory operation. _size is 0."); Memory* mem = (Memory*)BX_ALLOC(g_allocator, sizeof(Memory) + _size); mem->size = _size; mem->data = (uint8_t*)mem + sizeof(Memory); @@ -3671,7 +4074,7 @@ namespace bgfx const Memory* copy(const void* _data, uint32_t _size) { - BX_CHECK(0 < _size, "Invalid memory operation. _size is 0."); + BX_ASSERT(0 < _size, "Invalid memory operation. _size is 0."); const Memory* mem = alloc(_size); bx::memCopy(mem->data, _data, _size); return mem; @@ -3701,7 +4104,7 @@ namespace bgfx void release(const Memory* _mem) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); Memory* mem = const_cast<Memory*>(_mem); if (isMemoryRef(mem) ) { @@ -3748,20 +4151,44 @@ namespace bgfx IndexBufferHandle createIndexBuffer(const Memory* _mem, uint16_t _flags) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT( + 0 == (_flags & BGFX_BUFFER_INDEX32) || 0 != (g_caps.supported & BGFX_CAPS_INDEX32) + , "32-bit indices are not supported. Use bgfx::getCaps to check BGFX_CAPS_INDEX32 backend renderer capabilities." + ); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); return s_ctx->createIndexBuffer(_mem, _flags); } + void setName(IndexBufferHandle _handle, const char* _name, int32_t _len) + { + s_ctx->setName(_handle, bx::StringView(_name, _len) ); + } + void destroy(IndexBufferHandle _handle) { s_ctx->destroyIndexBuffer(_handle); } - VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) + VertexLayoutHandle createVertexLayout(const VertexLayout& _layout) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); - BX_CHECK(isValid(_decl), "Invalid VertexDecl."); - return s_ctx->createVertexBuffer(_mem, _decl, _flags); + return s_ctx->createVertexLayout(_layout); + } + + void destroy(VertexLayoutHandle _handle) + { + s_ctx->destroyVertexLayout(_handle); + } + + VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexLayout& _layout, uint16_t _flags) + { + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(isValid(_layout), "Invalid VertexLayout."); + return s_ctx->createVertexBuffer(_mem, _layout, _flags); + } + + void setName(VertexBufferHandle _handle, const char* _name, int32_t _len) + { + s_ctx->setName(_handle, bx::StringView(_name, _len) ); } void destroy(VertexBufferHandle _handle) @@ -3776,13 +4203,17 @@ namespace bgfx DynamicIndexBufferHandle createDynamicIndexBuffer(const Memory* _mem, uint16_t _flags) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT( + 0 == (_flags & BGFX_BUFFER_INDEX32) || 0 != (g_caps.supported & BGFX_CAPS_INDEX32) + , "32-bit indices are not supported. Use bgfx::getCaps to check BGFX_CAPS_INDEX32 backend renderer capabilities." + ); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); return s_ctx->createDynamicIndexBuffer(_mem, _flags); } void update(DynamicIndexBufferHandle _handle, uint32_t _startIndex, const Memory* _mem) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); s_ctx->update(_handle, _startIndex, _mem); } @@ -3791,22 +4222,22 @@ namespace bgfx s_ctx->destroyDynamicIndexBuffer(_handle); } - DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint16_t _flags) + DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexLayout& _layout, uint16_t _flags) { - BX_CHECK(isValid(_decl), "Invalid VertexDecl."); - return s_ctx->createDynamicVertexBuffer(_num, _decl, _flags); + BX_ASSERT(isValid(_layout), "Invalid VertexLayout."); + return s_ctx->createDynamicVertexBuffer(_num, _layout, _flags); } - DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) + DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexLayout& _layout, uint16_t _flags) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); - BX_CHECK(isValid(_decl), "Invalid VertexDecl."); - return s_ctx->createDynamicVertexBuffer(_mem, _decl, _flags); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(isValid(_layout), "Invalid VertexLayout."); + return s_ctx->createDynamicVertexBuffer(_mem, _layout, _flags); } void update(DynamicVertexBufferHandle _handle, uint32_t _startVertex, const Memory* _mem) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); s_ctx->update(_handle, _startVertex, _mem); } @@ -3815,61 +4246,78 @@ namespace bgfx s_ctx->destroyDynamicVertexBuffer(_handle); } - uint32_t getAvailTransientIndexBuffer(uint32_t _num) + uint32_t getAvailTransientIndexBuffer(uint32_t _num, bool _index32) { - BX_CHECK(0 < _num, "Requesting 0 indices."); - return s_ctx->getAvailTransientIndexBuffer(_num); + BX_ASSERT(0 < _num, "Requesting 0 indices."); + return s_ctx->getAvailTransientIndexBuffer(_num, _index32); } - uint32_t getAvailTransientVertexBuffer(uint32_t _num, const VertexDecl& _decl) + uint32_t getAvailTransientVertexBuffer(uint32_t _num, const VertexLayout& _layout) { - BX_CHECK(0 < _num, "Requesting 0 vertices."); - BX_CHECK(isValid(_decl), "Invalid VertexDecl."); - return s_ctx->getAvailTransientVertexBuffer(_num, _decl.m_stride); + BX_ASSERT(0 < _num, "Requesting 0 vertices."); + BX_ASSERT(isValid(_layout), "Invalid VertexLayout."); + return s_ctx->getAvailTransientVertexBuffer(_num, _layout.m_stride); } uint32_t getAvailInstanceDataBuffer(uint32_t _num, uint16_t _stride) { - BX_CHECK(0 < _num, "Requesting 0 instances."); + BX_ASSERT(0 < _num, "Requesting 0 instances."); return s_ctx->getAvailTransientVertexBuffer(_num, _stride); } - void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num) + void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num, bool _index32) { - BX_CHECK(NULL != _tib, "_tib can't be NULL"); - BX_CHECK(0 < _num, "Requesting 0 indices."); - s_ctx->allocTransientIndexBuffer(_tib, _num); - BX_CHECK(_num == _tib->size/2 + BX_ASSERT(NULL != _tib, "_tib can't be NULL"); + BX_ASSERT(0 < _num, "Requesting 0 indices."); + BX_ASSERT( + !_index32 || 0 != (g_caps.supported & BGFX_CAPS_INDEX32) + , "32-bit indices are not supported. Use bgfx::getCaps to check BGFX_CAPS_INDEX32 backend renderer capabilities." + ); + + s_ctx->allocTransientIndexBuffer(_tib, _num, _index32); + + const uint32_t indexSize = _tib->isIndex16 ? 2 : 4; + BX_ASSERT(_num == _tib->size/ indexSize , "Failed to allocate transient index buffer (requested %d, available %d). " "Use bgfx::getAvailTransient* functions to ensure availability." , _num - , _tib->size/2 + , _tib->size/indexSize ); + BX_UNUSED(indexSize); } - void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl) + void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexLayout& _layout) { - BX_CHECK(NULL != _tvb, "_tvb can't be NULL"); - BX_CHECK(0 < _num, "Requesting 0 vertices."); - BX_CHECK(isValid(_decl), "Invalid VertexDecl."); - s_ctx->allocTransientVertexBuffer(_tvb, _num, _decl); - BX_CHECK(_num == _tvb->size / _decl.m_stride + BX_ASSERT(NULL != _tvb, "_tvb can't be NULL"); + BX_ASSERT(0 < _num, "Requesting 0 vertices."); + BX_ASSERT(isValid(_layout), "Invalid VertexLayout."); + + VertexLayoutHandle layoutHandle; + { + BGFX_MUTEX_SCOPE(s_ctx->m_resourceApiLock); + layoutHandle = s_ctx->findOrCreateVertexLayout(_layout, true); + } + BX_ASSERT(isValid(layoutHandle), "Failed to allocate vertex layout handle (BGFX_CONFIG_MAX_VERTEX_LAYOUTS, max: %d).", BGFX_CONFIG_MAX_VERTEX_LAYOUTS); + + s_ctx->allocTransientVertexBuffer(_tvb, _num, layoutHandle, _layout.m_stride); + + BX_ASSERT(_num == _tvb->size / _layout.m_stride , "Failed to allocate transient vertex buffer (requested %d, available %d). " "Use bgfx::getAvailTransient* functions to ensure availability." , _num - , _tvb->size / _decl.m_stride + , _tvb->size / _layout.m_stride ); } - bool allocTransientBuffers(bgfx::TransientVertexBuffer* _tvb, const bgfx::VertexDecl& _decl, uint32_t _numVertices, bgfx::TransientIndexBuffer* _tib, uint32_t _numIndices) + bool allocTransientBuffers(bgfx::TransientVertexBuffer* _tvb, const bgfx::VertexLayout& _layout, uint32_t _numVertices, bgfx::TransientIndexBuffer* _tib, uint32_t _numIndices, bool _index32) { BGFX_MUTEX_SCOPE(s_ctx->m_resourceApiLock); - if (_numVertices == getAvailTransientVertexBuffer(_numVertices, _decl) - && _numIndices == getAvailTransientIndexBuffer(_numIndices) ) + if (_numVertices == getAvailTransientVertexBuffer(_numVertices, _layout) + && _numIndices == getAvailTransientIndexBuffer(_numIndices, _index32) ) { - allocTransientVertexBuffer(_tvb, _numVertices, _decl); - allocTransientIndexBuffer(_tib, _numIndices); + allocTransientVertexBuffer(_tvb, _numVertices, _layout); + allocTransientIndexBuffer(_tib, _numIndices, _index32); return true; } @@ -3879,10 +4327,10 @@ namespace bgfx void allocInstanceDataBuffer(InstanceDataBuffer* _idb, uint32_t _num, uint16_t _stride) { BGFX_CHECK_CAPS(BGFX_CAPS_INSTANCING, "Instancing is not supported!"); - BX_CHECK(_stride == BX_ALIGN_16(_stride), "Stride must be multiple of 16."); - BX_CHECK(0 < _num, "Requesting 0 instanced data vertices."); + BX_ASSERT(bx::isAligned(_stride, 16), "Stride must be multiple of 16."); + BX_ASSERT(0 < _num, "Requesting 0 instanced data vertices."); s_ctx->allocInstanceDataBuffer(_idb, _num, _stride); - BX_CHECK(_num == _idb->size / _stride + BX_ASSERT(_num == _idb->size / _stride , "Failed to allocate instance data buffer (requested %d, available %d). " "Use bgfx::getAvailTransient* functions to ensure availability." , _num @@ -3902,13 +4350,25 @@ namespace bgfx ShaderHandle createShader(const Memory* _mem) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); return s_ctx->createShader(_mem); } uint16_t getShaderUniforms(ShaderHandle _handle, UniformHandle* _uniforms, uint16_t _max) { - return s_ctx->getShaderUniforms(_handle, _uniforms, _max); + BX_WARN(NULL == _uniforms || 0 != _max + , "Passing uniforms array pointer, but array maximum capacity is set to 0." + ); + + uint16_t num = s_ctx->getShaderUniforms(_handle, _uniforms, _max); + + BX_WARN(0 == _max || num <= _max + , "Shader has more uniforms that capacity of output array. Output is truncated (num %d, max %d)." + , num + , _max + ); + + return num; } void setName(ShaderHandle _handle, const char* _name, int32_t _len) @@ -3941,49 +4401,265 @@ namespace bgfx s_ctx->destroyProgram(_handle); } - static void isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, bx::Error* _err) + void isFrameBufferValid(uint8_t _num, const Attachment* _attachment, bx::Error* _err) { - BX_ERROR_SCOPE(_err); + BX_ERROR_SCOPE(_err, "Frame buffer validation"); - const bool is3DTexture = 1 < _depth; + uint8_t color = 0; + uint8_t depth = 0; + + const TextureRef& firstTexture = s_ctx->m_textureRef[_attachment[0].handle.idx]; + + const uint16_t firstAttachmentWidth = bx::max<uint16_t>(firstTexture.m_width >> _attachment[0].mip, 1); + const uint16_t firstAttachmentHeight = bx::max<uint16_t>(firstTexture.m_height >> _attachment[0].mip, 1); - if (_cubeMap && is3DTexture) + for (uint32_t ii = 0; ii < _num; ++ii) { - _err->setError(BGFX_ERROR_TEXTURE_VALIDATION - , "Texture can't be depth and cube map at the same time." + const Attachment& at = _attachment[ii]; + const TextureHandle texHandle = at.handle; + const TextureRef& tr = s_ctx->m_textureRef[texHandle.idx]; + + BGFX_ERROR_CHECK(true + && isValid(texHandle) + && s_ctx->m_textureHandle.isValid(texHandle.idx) + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Invalid texture attachment." + , "Attachment %d, texture handle %d." + , ii + , texHandle.idx ); - return; - } - if (is3DTexture - && 0 == (g_caps.supported & BGFX_CAPS_TEXTURE_3D) ) - { - _err->setError(BGFX_ERROR_TEXTURE_VALIDATION - , "Texture3D is not supported! " - "Use bgfx::getCaps to check BGFX_CAPS_TEXTURE_3D backend renderer capabilities." + BGFX_ERROR_CHECK(true + && at.mip < tr.m_numMips + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Invalid texture mip level." + , "Attachment %d, Mip %d, texture (handle %d) number of mips %d." + , ii + , at.mip + , texHandle.idx + , tr.m_numMips ); - return; - } - if (0 != (_flags & BGFX_TEXTURE_RT_MASK) - && 0 != (_flags & BGFX_TEXTURE_READ_BACK) ) - { - _err->setError(BGFX_ERROR_TEXTURE_VALIDATION - , "Can't create render target with BGFX_TEXTURE_READ_BACK flag." + { + const uint16_t numLayers = tr.is3D() + ? bx::max<uint16_t>(tr.m_depth >> at.mip, 1) + : tr.m_numLayers * (tr.isCubeMap() ? 6 : 1) + ; + + BGFX_ERROR_CHECK(true + && (at.layer + at.numLayers) <= numLayers + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Invalid texture layer range." + , "Attachment %d, Layer: %d, Num: %d, Max number of layers: %d." + , ii + , at.layer + , at.numLayers + , numLayers + ); + } + + BGFX_ERROR_CHECK(true + && _attachment[0].numLayers == at.numLayers + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Mismatch in attachment layer count." + , "Attachment %d, Given: %d, Expected: %d." + , ii + , at.numLayers + , _attachment[0].numLayers ); - return; - } - if (1 < _numLayers - && 0 == (g_caps.supported & BGFX_CAPS_TEXTURE_2D_ARRAY) ) - { - _err->setError(BGFX_ERROR_TEXTURE_VALIDATION - , "Texture array is not supported! " - "Use bgfx::getCaps to check BGFX_CAPS_TEXTURE_2D_ARRAY backend renderer capabilities." + BGFX_ERROR_CHECK(true + && firstTexture.m_bbRatio == tr.m_bbRatio + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Mismatch in texture back-buffer ratio." + , "Attachment %d, Given: %d, Expected: %d." + , ii + , tr.m_bbRatio + , firstTexture.m_bbRatio + ); + + BGFX_ERROR_CHECK(true + && firstTexture.m_numSamples == tr.m_numSamples + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Mismatch in texture sample count." + , "Attachment %d, Given: %d, Expected: %d." + , ii + , tr.m_numSamples + , firstTexture.m_numSamples + ); + + if (BackbufferRatio::Count == firstTexture.m_bbRatio) + { + const uint16_t width = bx::max<uint16_t>(tr.m_width >> at.mip, 1); + const uint16_t height = bx::max<uint16_t>(tr.m_height >> at.mip, 1); + + BGFX_ERROR_CHECK(true + && width == firstAttachmentWidth + && height == firstAttachmentHeight + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Mismatch in texture size." + , "Attachment %d, Given: %dx%d, Expected: %dx%d." + , ii + , width + , height + , firstAttachmentWidth + , firstAttachmentHeight + ); + } + + if (bimg::isDepth(bimg::TextureFormat::Enum(tr.m_format) ) ) + { + ++depth; + + BGFX_ERROR_CHECK( + // if BGFX_TEXTURE_RT_MSAA_X2 or greater than BGFX_TEXTURE_RT_WRITE_ONLY is required + // if BGFX_TEXTURE_RT with no MSSA then WRITE_ONLY is not required. + (1 == ((tr.m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT)) + || (0 != (tr.m_flags & BGFX_TEXTURE_RT_WRITE_ONLY)) + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Frame buffer depth MSAA texture cannot be resolved. It must be created with `BGFX_TEXTURE_RT_WRITE_ONLY` flag." + , "Attachment %d, texture flags 0x%016" PRIx64 "." + , ii + , tr.m_flags + ); + } + else + { + ++color; + } + + BGFX_ERROR_CHECK(true + && 0 == (tr.m_flags & BGFX_TEXTURE_READ_BACK) + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Frame buffer texture cannot be created with `BGFX_TEXTURE_READ_BACK`." + , "Attachment %d, texture flags 0x%016" PRIx64 "." + , ii + , tr.m_flags + ); + + BGFX_ERROR_CHECK(true + && 0 != (tr.m_flags & BGFX_TEXTURE_RT_MASK) + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Frame buffer texture is not created with one of `BGFX_TEXTURE_RT*` flags." + , "Attachment %d, texture flags 0x%016" PRIx64 "." + , ii + , tr.m_flags ); - return; } + BGFX_ERROR_CHECK(true + && color <= g_caps.limits.maxFBAttachments + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "Too many frame buffer color attachments." + , "Num: %d, Max: %d." + , _num + , g_caps.limits.maxFBAttachments + ); + + BGFX_ERROR_CHECK(true + && depth <= 1 + , _err + , BGFX_ERROR_FRAME_BUFFER_VALIDATION + , "There can be only one depth texture attachment." + , "Num depth attachments %d." + , depth + ); + } + + bool isFrameBufferValid(uint8_t _num, const Attachment* _attachment) + { + BGFX_MUTEX_SCOPE(s_ctx->m_resourceApiLock); + bx::Error err; + isFrameBufferValid(_num, _attachment, &err); + return err.isOk(); + } + + static void isTextureValid(uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, bx::Error* _err) + { + BX_ERROR_SCOPE(_err, "Texture validation"); + + const bool is3DTexture = 1 < _depth; + + BGFX_ERROR_CHECK(false + || !_cubeMap + || !is3DTexture + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Texture can't be 3D and cube map at the same time." + , "" + ); + + BGFX_ERROR_CHECK(false + || !is3DTexture + || 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_3D) + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Texture3D is not supported! " + "Use bgfx::getCaps to check `BGFX_CAPS_TEXTURE_3D` backend renderer capabilities." + , "" + ); + + BGFX_ERROR_CHECK(false + || _width <= g_caps.limits.maxTextureSize + || _height <= g_caps.limits.maxTextureSize + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Requested texture width/height is above the `maxTextureSize` limit." + , "Texture width x height requested %d x %d (Max: %d)." + , _width + , _height + , g_caps.limits.maxTextureSize + ); + + BGFX_ERROR_CHECK(false + || 0 == (_flags & BGFX_TEXTURE_RT_MASK) + || 0 == (_flags & BGFX_TEXTURE_READ_BACK) + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Can't create render target with `BGFX_TEXTURE_READ_BACK` flag." + , "" + ); + + BGFX_ERROR_CHECK(false + || 0 == (_flags & BGFX_TEXTURE_COMPUTE_WRITE) + || 0 == (_flags & BGFX_TEXTURE_READ_BACK) + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Can't create compute texture with `BGFX_TEXTURE_READ_BACK` flag." + , "" + ); + + BGFX_ERROR_CHECK(false + || 1 >= _numLayers + || 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_2D_ARRAY) + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Texture array is not supported! " + "Use bgfx::getCaps to check `BGFX_CAPS_TEXTURE_2D_ARRAY` backend renderer capabilities." + , "" + ); + + BGFX_ERROR_CHECK(false + || _numLayers <= g_caps.limits.maxTextureLayers + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Requested number of texture array layers is above the `maxTextureLayers` limit." + , "Number of texture array layers requested %d (Max: %d)." + , _numLayers + , g_caps.limits.maxTextureLayers + ); + bool formatSupported; if (0 != (_flags & (BGFX_TEXTURE_RT | BGFX_TEXTURE_RT_WRITE_ONLY)) ) { @@ -3997,6 +4673,7 @@ namespace bgfx | BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB ) ); } + uint16_t srgbCaps = BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB; if (_cubeMap) @@ -4026,45 +4703,97 @@ namespace bgfx ) ); } - if (!formatSupported) - { - _err->setError(BGFX_ERROR_TEXTURE_VALIDATION - , "Texture format is not supported! " - "Use bgfx::isTextureValid to check support for texture format before creating it." - ); - return; - } + BGFX_ERROR_CHECK( + formatSupported + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "Texture format is not supported! " + "Use bgfx::isTextureValid to check support for texture format before creating it." + , "Texture format: %s." + , getName(_format) + ); - if (0 != (_flags & BGFX_TEXTURE_MSAA_SAMPLE) - && 0 == (g_caps.formats[_format] & BGFX_CAPS_FORMAT_TEXTURE_MSAA) ) - { - _err->setError(BGFX_ERROR_TEXTURE_VALIDATION - , "MSAA sampling for this texture format is not supported." - ); - return; - } + BGFX_ERROR_CHECK(false + || 0 == (_flags & BGFX_TEXTURE_MSAA_SAMPLE) + || 0 != (g_caps.formats[_format] & BGFX_CAPS_FORMAT_TEXTURE_MSAA) + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "MSAA sampling for this texture format is not supported." + , "Texture format: %s." + , getName(_format) + ); - if (0 != (_flags & BGFX_TEXTURE_SRGB) - && 0 == (g_caps.supported & srgbCaps & (0 - | BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB - | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB - | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB - ) ) ) - { - _err->setError(BGFX_ERROR_TEXTURE_VALIDATION - , "sRGB sampling for this texture format is not supported." - ); - return; - } + BGFX_ERROR_CHECK(false + || 0 == (_flags & BGFX_TEXTURE_SRGB) + || 0 != (g_caps.formats[_format] & srgbCaps & (0 + | BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB + ) ) + , _err + , BGFX_ERROR_TEXTURE_VALIDATION + , "sRGB sampling for this texture format is not supported." + , "Texture format: %s." + , getName(_format) + ); } bool isTextureValid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags) { bx::Error err; - isTextureValid(_depth, _cubeMap, _numLayers, _format, _flags, &err); + isTextureValid(0, 0, _depth, _cubeMap, _numLayers, _format, _flags, &err); return err.isOk(); } + void isIdentifierValid(const bx::StringView& _name, bx::Error* _err) + { + BX_ERROR_SCOPE(_err, "Uniform identifier validation"); + + BGFX_ERROR_CHECK(false + || !_name.isEmpty() + , _err + , BGFX_ERROR_IDENTIFIER_VALIDATION + , "Identifier can't be empty." + , "" + ); + + BGFX_ERROR_CHECK(false + || PredefinedUniform::Count == nameToPredefinedUniformEnum(_name) + , _err + , BGFX_ERROR_IDENTIFIER_VALIDATION + , "Identifier can't use predefined uniform name." + , "" + ); + + const char ch = *_name.getPtr(); + BGFX_ERROR_CHECK(false + || bx::isAlpha(ch) + || '_' == ch + , _err + , BGFX_ERROR_IDENTIFIER_VALIDATION + , "The first character of an identifier should be either an alphabet character or an underscore." + , "" + ); + + bool result = true; + + for (const char* ptr = _name.getPtr() + 1, *term = _name.getTerm() + ; ptr != term && result + ; ++ptr + ) + { + result &= bx::isAlphaNum(*ptr) || '_' == *ptr; + } + + BGFX_ERROR_CHECK(false + || result + , _err + , BGFX_ERROR_IDENTIFIER_VALIDATION + , "Identifier contains invalid characters. Identifier must be the alphabet character, number, or underscore." + , "" + ); + } + void calcTextureSize(TextureInfo& _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format) { bimg::imageGetSize( (bimg::TextureInfo*)&_info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bimg::TextureFormat::Enum(_format) ); @@ -4072,7 +4801,7 @@ namespace bgfx TextureHandle createTexture(const Memory* _mem, uint64_t _flags, uint8_t _skip, TextureInfo* _info) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); return s_ctx->createTexture(_mem, _flags, _skip, _info, BackbufferRatio::Count, false); } @@ -4096,14 +4825,6 @@ namespace bgfx static TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { - bx::Error err; - isTextureValid(0, false, _numLayers, _format, _flags, &err); - BX_CHECK(err.isOk(), "%s (layers %d, format %s)" - , err.getMessage().getPtr() - , _numLayers - , getName(_format) - ); - if (BackbufferRatio::Count != _ratio) { _width = uint16_t(s_ctx->m_init.resolution.width); @@ -4111,6 +4832,14 @@ namespace bgfx getTextureSizeFromRatio(_ratio, _width, _height); } + bx::ErrorAssert err; + isTextureValid(_width, _height, 0, false, _numLayers, _format, _flags, &err); + + if (!err.isOk() ) + { + return BGFX_INVALID_HANDLE; + } + const uint8_t numMips = calcNumMips(_hasMips, _width, _height); _numLayers = bx::max<uint16_t>(_numLayers, 1); @@ -4119,7 +4848,7 @@ namespace bgfx { TextureInfo ti; calcTextureSize(ti, _width, _height, 1, false, _hasMips, _numLayers, _format); - BX_CHECK(ti.storageSize == _mem->size + BX_ASSERT(ti.storageSize == _mem->size , "createTexture2D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize , _mem->size @@ -4131,7 +4860,7 @@ namespace bgfx bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -4142,28 +4871,32 @@ namespace bgfx tc.m_format = _format; tc.m_cubeMap = false; tc.m_mem = _mem; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); return s_ctx->createTexture(mem, _flags, 0, NULL, _ratio, NULL != _mem); } TextureHandle createTexture2D(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { - BX_CHECK(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height); + BX_ASSERT(_width > 0 && _height > 0, "Invalid texture size (width %d, height %d).", _width, _height); return createTexture2D(BackbufferRatio::Count, _width, _height, _hasMips, _numLayers, _format, _flags, _mem); } TextureHandle createTexture2D(BackbufferRatio::Enum _ratio, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags) { - BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); + BX_ASSERT(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); return createTexture2D(_ratio, 0, 0, _hasMips, _numLayers, _format, _flags, NULL); } TextureHandle createTexture3D(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { - bx::Error err; - isTextureValid(_depth, false, 1, _format, _flags, &err); - BX_CHECK(err.isOk(), "%s", err.getMessage().getPtr() ); + bx::ErrorAssert err; + isTextureValid(_width, _height, _depth, false, 1, _format, _flags, &err); + + if (!err.isOk() ) + { + return BGFX_INVALID_HANDLE; + } const uint8_t numMips = calcNumMips(_hasMips, _width, _height, _depth); @@ -4172,7 +4905,7 @@ namespace bgfx { TextureInfo ti; calcTextureSize(ti, _width, _height, _depth, false, _hasMips, 1, _format); - BX_CHECK(ti.storageSize == _mem->size + BX_ASSERT(ti.storageSize == _mem->size , "createTexture3D: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize , _mem->size @@ -4184,7 +4917,7 @@ namespace bgfx bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -4195,16 +4928,20 @@ namespace bgfx tc.m_format = _format; tc.m_cubeMap = false; tc.m_mem = _mem; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count, NULL != _mem); } TextureHandle createTextureCube(uint16_t _size, bool _hasMips, uint16_t _numLayers, TextureFormat::Enum _format, uint64_t _flags, const Memory* _mem) { - bx::Error err; - isTextureValid(0, true, _numLayers, _format, _flags, &err); - BX_CHECK(err.isOk(), "%s", err.getMessage().getPtr() ); + bx::ErrorAssert err; + isTextureValid(_size, _size, 0, true, _numLayers, _format, _flags, &err); + + if (!err.isOk() ) + { + return BGFX_INVALID_HANDLE; + } const uint8_t numMips = calcNumMips(_hasMips, _size, _size); _numLayers = bx::max<uint16_t>(_numLayers, 1); @@ -4214,7 +4951,7 @@ namespace bgfx { TextureInfo ti; calcTextureSize(ti, _size, _size, 1, true, _hasMips, _numLayers, _format); - BX_CHECK(ti.storageSize == _mem->size + BX_ASSERT(ti.storageSize == _mem->size , "createTextureCube: Texture storage size doesn't match passed memory size (storage size: %d, memory size: %d)" , ti.storageSize , _mem->size @@ -4226,7 +4963,7 @@ namespace bgfx bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _size; @@ -4237,7 +4974,7 @@ namespace bgfx tc.m_format = _format; tc.m_cubeMap = true; tc.m_mem = _mem; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); return s_ctx->createTexture(mem, _flags, 0, NULL, BackbufferRatio::Count, NULL != _mem); } @@ -4259,7 +4996,7 @@ namespace bgfx void updateTexture2D(TextureHandle _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); if (_width == 0 || _height == 0) { @@ -4273,7 +5010,7 @@ namespace bgfx void updateTexture3D(TextureHandle _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const Memory* _mem) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_3D, "Texture3D is not supported!"); if (0 == _width @@ -4290,8 +5027,8 @@ namespace bgfx void updateTextureCube(TextureHandle _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const Memory* _mem, uint16_t _pitch) { - BX_CHECK(NULL != _mem, "_mem can't be NULL"); - BX_CHECK(_side <= 5, "Invalid side %d.", _side); + BX_ASSERT(NULL != _mem, "_mem can't be NULL"); + BX_ASSERT(_side <= 5, "Invalid side %d.", _side); if (0 == _width || 0 == _height) { @@ -4305,7 +5042,7 @@ namespace bgfx uint32_t readTexture(TextureHandle _handle, void* _data, uint8_t _mip) { - BX_CHECK(NULL != _data, "_data can't be NULL"); + BX_ASSERT(NULL != _data, "_data can't be NULL"); BGFX_CHECK_CAPS(BGFX_CAPS_TEXTURE_READ_BACK, "Texture read-back is not supported!"); return s_ctx->readTexture(_handle, _data, _mip); } @@ -4319,7 +5056,7 @@ namespace bgfx FrameBufferHandle createFrameBuffer(BackbufferRatio::Enum _ratio, TextureFormat::Enum _format, uint64_t _textureFlags) { - BX_CHECK(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); + BX_ASSERT(_ratio < BackbufferRatio::Count, "Invalid back buffer ratio."); _textureFlags |= _textureFlags&BGFX_TEXTURE_RT_MSAA_MASK ? 0 : BGFX_TEXTURE_RT; TextureHandle th = createTexture2D(_ratio, false, 1, _format, _textureFlags); return createFrameBuffer(1, &th, true); @@ -4331,20 +5068,20 @@ namespace bgfx for (uint8_t ii = 0; ii < _num; ++ii) { Attachment& at = attachment[ii]; - at.init(_handles[ii], Access::Write, 0, 0, BGFX_RESOLVE_AUTO_GEN_MIPS); + at.init(_handles[ii], Access::Write, 0, 1, 0, BGFX_RESOLVE_AUTO_GEN_MIPS); } return createFrameBuffer(_num, attachment, _destroyTextures); } FrameBufferHandle createFrameBuffer(uint8_t _num, const Attachment* _attachment, bool _destroyTextures) { - BX_CHECK(_num != 0, "Number of frame buffer attachments can't be 0."); - BX_CHECK(_num <= BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS + BX_ASSERT(_num != 0, "Number of frame buffer attachments can't be 0."); + BX_ASSERT(_num <= BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS , "Number of frame buffer attachments is larger than allowed %d (max: %d)." , _num , BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS ); - BX_CHECK(NULL != _attachment, "_attachment can't be NULL"); + BX_ASSERT(NULL != _attachment, "_attachment can't be NULL"); return s_ctx->createFrameBuffer(_num, _attachment, _destroyTextures); } @@ -4356,11 +5093,11 @@ namespace bgfx , _width , _height ); - BX_CHECK(_format == TextureFormat::Count || bimg::isColor(bimg::TextureFormat::Enum(_format) ) + BX_ASSERT(_format == TextureFormat::Count || bimg::isColor(bimg::TextureFormat::Enum(_format) ) , "Invalid texture format for color (%s)." , bimg::getName(bimg::TextureFormat::Enum(_format) ) ); - BX_CHECK(_depthFormat == TextureFormat::Count || bimg::isDepth(bimg::TextureFormat::Enum(_depthFormat) ) + BX_ASSERT(_depthFormat == TextureFormat::Count || bimg::isDepth(bimg::TextureFormat::Enum(_depthFormat) ) , "Invalid texture format for depth (%s)." , bimg::getName(bimg::TextureFormat::Enum(_depthFormat) ) ); @@ -4373,6 +5110,11 @@ namespace bgfx ); } + void setName(FrameBufferHandle _handle, const char* _name, int32_t _len) + { + s_ctx->setName(_handle, bx::StringView(_name, _len) ); + } + TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment) { return s_ctx->getTexture(_handle, _attachment); @@ -4454,19 +5196,19 @@ namespace bgfx void setViewName(ViewId _id, const char* _name) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewName(_id, _name); } void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewRect(_id, _x, _y, _width, _height); } void setViewRect(ViewId _id, uint16_t _x, uint16_t _y, BackbufferRatio::Enum _ratio) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); uint16_t width = uint16_t(s_ctx->m_init.resolution.width); uint16_t height = uint16_t(s_ctx->m_init.resolution.height); @@ -4476,306 +5218,342 @@ namespace bgfx void setViewScissor(ViewId _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewScissor(_id, _x, _y, _width, _height); } void setViewClear(ViewId _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewClear(_id, _flags, _rgba, _depth, _stencil); } void setViewClear(ViewId _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7); } void setViewMode(ViewId _id, ViewMode::Enum _mode) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewMode(_id, _mode); } void setViewFrameBuffer(ViewId _id, FrameBufferHandle _handle) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewFrameBuffer(_id, _handle); } - void setViewTransform(ViewId _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR) + void setViewTransform(ViewId _id, const void* _view, const void* _proj) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); - s_ctx->setViewTransform(_id, _view, _projL, _flags, _projR); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); + s_ctx->setViewTransform(_id, _view, _proj); } void setViewOrder(ViewId _id, uint16_t _num, const ViewId* _order) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->setViewOrder(_id, _num, _order); } void resetView(ViewId _id) { - BX_CHECK(checkView(_id), "Invalid view id: %d", _id); + BX_ASSERT(checkView(_id), "Invalid view id: %d", _id); s_ctx->resetView(_id); } +#define BGFX_CHECK_ENCODER0() \ + BGFX_CHECK_API_THREAD(); \ + BGFX_FATAL(NULL != s_ctx->m_encoder0, Fatal::DebugCheck \ + , "bgfx is configured to allow only encoder API. See: `BGFX_CONFIG_ENCODER_API_ONLY`.") + void setMarker(const char* _marker) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setMarker(_marker); } void setState(uint64_t _state, uint32_t _rgba) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setState(_state, _rgba); } void setCondition(OcclusionQueryHandle _handle, bool _visible) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setCondition(_handle, _visible); } void setStencil(uint32_t _fstencil, uint32_t _bstencil) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setStencil(_fstencil, _bstencil); } uint16_t setScissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); return s_ctx->m_encoder0->setScissor(_x, _y, _width, _height); } void setScissor(uint16_t _cache) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setScissor(_cache); } uint32_t setTransform(const void* _mtx, uint16_t _num) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); return s_ctx->m_encoder0->setTransform(_mtx, _num); } uint32_t allocTransform(Transform* _transform, uint16_t _num) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); return s_ctx->m_encoder0->allocTransform(_transform, _num); } void setTransform(uint32_t _cache, uint16_t _num) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setTransform(_cache, _num); } void setUniform(UniformHandle _handle, const void* _value, uint16_t _num) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setUniform(_handle, _value, _num); } void setIndexBuffer(IndexBufferHandle _handle) { - setIndexBuffer(_handle, 0, UINT32_MAX); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setIndexBuffer(_handle); } void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setIndexBuffer(_handle, _firstIndex, _numIndices); } void setIndexBuffer(DynamicIndexBufferHandle _handle) { - setIndexBuffer(_handle, 0, UINT32_MAX); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setIndexBuffer(_handle); } void setIndexBuffer(DynamicIndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setIndexBuffer(_handle, _firstIndex, _numIndices); } void setIndexBuffer(const TransientIndexBuffer* _tib) { - setIndexBuffer(_tib, 0, UINT32_MAX); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setIndexBuffer(_tib); } void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setIndexBuffer(_tib, _firstIndex, _numIndices); } - void setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) + void setVertexBuffer( + uint8_t _stream + , VertexBufferHandle _handle + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { - BGFX_CHECK_API_THREAD(); - s_ctx->m_encoder0->setVertexBuffer(_stream, _handle, _startVertex, _numVertices); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setVertexBuffer(_stream, _handle, _startVertex, _numVertices, _layoutHandle); } void setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle) { - setVertexBuffer(_stream, _handle, 0, UINT32_MAX); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setVertexBuffer(_stream, _handle); } - void setVertexBuffer(uint8_t _stream, DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) + void setVertexBuffer( + uint8_t _stream + , DynamicVertexBufferHandle _handle + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { - BGFX_CHECK_API_THREAD(); - s_ctx->m_encoder0->setVertexBuffer(_stream, _handle, _startVertex, _numVertices); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setVertexBuffer(_stream, _handle, _startVertex, _numVertices, _layoutHandle); } void setVertexBuffer(uint8_t _stream, DynamicVertexBufferHandle _handle) { - setVertexBuffer(_stream, _handle, 0, UINT32_MAX); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setVertexBuffer(_stream, _handle); } - void setVertexBuffer(uint8_t _stream, const TransientVertexBuffer* _tvb, uint32_t _startVertex, uint32_t _numVertices) + void setVertexBuffer( + uint8_t _stream + , const TransientVertexBuffer* _tvb + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { - BGFX_CHECK_API_THREAD(); - s_ctx->m_encoder0->setVertexBuffer(_stream, _tvb, _startVertex, _numVertices); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setVertexBuffer(_stream, _tvb, _startVertex, _numVertices, _layoutHandle); } void setVertexBuffer(uint8_t _stream, const TransientVertexBuffer* _tvb) { - setVertexBuffer(_stream, _tvb, 0, UINT32_MAX); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->setVertexBuffer(_stream, _tvb); } void setVertexCount(uint32_t _numVertices) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setVertexCount(_numVertices); } void setInstanceDataBuffer(const InstanceDataBuffer* _idb) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setInstanceDataBuffer(_idb); } void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _start, uint32_t _num) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setInstanceDataBuffer(_idb, _start, _num); } void setInstanceDataBuffer(VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setInstanceDataBuffer(_handle, _startVertex, _num); } void setInstanceDataBuffer(DynamicVertexBufferHandle _handle, uint32_t _startVertex, uint32_t _num) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setInstanceDataBuffer(_handle, _startVertex, _num); } void setInstanceCount(uint32_t _numInstances) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setInstanceCount(_numInstances); } void setTexture(uint8_t _stage, UniformHandle _sampler, TextureHandle _handle, uint32_t _flags) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setTexture(_stage, _sampler, _handle, _flags); } void touch(ViewId _id) { - ProgramHandle handle = BGFX_INVALID_HANDLE; - submit(_id, handle); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->touch(_id); } - void submit(ViewId _id, ProgramHandle _program, uint32_t _depth, bool _preserveState) + void submit(ViewId _id, ProgramHandle _program, uint32_t _depth, uint8_t _flags) { - OcclusionQueryHandle handle = BGFX_INVALID_HANDLE; - submit(_id, _program, handle, _depth, _preserveState); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->submit(_id, _program, _depth, _flags); } - void submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, bool _preserveState) + void submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags) { - BGFX_CHECK_API_THREAD(); - s_ctx->m_encoder0->submit(_id, _program, _occlusionQuery, _depth, _preserveState); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->submit(_id, _program, _occlusionQuery, _depth, _flags); } - void submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, bool _preserveState) + void submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags) { - BGFX_CHECK_API_THREAD(); - s_ctx->m_encoder0->submit(_id, _program, _indirectHandle, _start, _num, _depth, _preserveState); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->submit(_id, _program, _indirectHandle, _start, _num, _depth, _flags); + } + + void submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, IndexBufferHandle _numHandle, uint32_t _numIndex, uint16_t _numMax, uint32_t _depth, uint8_t _flags) + { + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->submit(_id, _program, _indirectHandle, _start, _numHandle, _numIndex, _numMax, _depth, _flags); } void setBuffer(uint8_t _stage, IndexBufferHandle _handle, Access::Enum _access) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, VertexBufferHandle _handle, Access::Enum _access) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, DynamicIndexBufferHandle _handle, Access::Enum _access) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, DynamicVertexBufferHandle _handle, Access::Enum _access) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setBuffer(uint8_t _stage, IndirectBufferHandle _handle, Access::Enum _access) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setBuffer(_stage, _handle, _access); } void setImage(uint8_t _stage, TextureHandle _handle, uint8_t _mip, Access::Enum _access, TextureFormat::Enum _format) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->setImage(_stage, _handle, _mip, _access, _format); } void dispatch(ViewId _id, ProgramHandle _handle, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->dispatch(_id, _handle, _numX, _numY, _numZ, _flags); } void dispatch(ViewId _id, ProgramHandle _handle, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->dispatch(_id, _handle, _indirectHandle, _start, _num, _flags); } - void discard() + void discard(uint8_t _flags) { - BGFX_CHECK_API_THREAD(); - s_ctx->m_encoder0->discard(); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->discard(_flags); } void blit(ViewId _id, TextureHandle _dst, uint16_t _dstX, uint16_t _dstY, TextureHandle _src, uint16_t _srcX, uint16_t _srcY, uint16_t _width, uint16_t _height) { - blit(_id, _dst, 0, _dstX, _dstY, 0, _src, 0, _srcX, _srcY, 0, _width, _height, 0); + BGFX_CHECK_ENCODER0(); + s_ctx->m_encoder0->blit(_id, _dst, _dstX, _dstY, _src, _srcX, _srcY, _width, _height); } void blit(ViewId _id, TextureHandle _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, TextureHandle _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) { - BGFX_CHECK_API_THREAD(); + BGFX_CHECK_ENCODER0(); s_ctx->m_encoder0->blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); } @@ -4784,9 +5562,12 @@ namespace bgfx BGFX_CHECK_API_THREAD(); s_ctx->requestScreenShot(_handle, _filePath); } + +#undef BGFX_CHECK_ENCODER0 + } // namespace bgfx -#if BX_PLATFORM_WINDOWS +#if BGFX_CONFIG_PREFER_DISCRETE_GPU extern "C" { // When laptop setup has integrated and discrete GPU, following driver workarounds will @@ -4802,7 +5583,7 @@ extern "C" // __declspec(dllexport) uint32_t AmdPowerXpressRequestHighPerformance = UINT32_C(1); } -#endif // BX_PLATFORM_WINDOWS +#endif // BGFX_CONFIG_PREFER_DISCRETE_GPU #define BGFX_TEXTURE_FORMAT_BIMG(_fmt) \ BX_STATIC_ASSERT(uint32_t(bgfx::TextureFormat::_fmt) == uint32_t(bimg::TextureFormat::_fmt) ) @@ -4828,11 +5609,19 @@ BGFX_TEXTURE_FORMAT_BIMG(ATC); BGFX_TEXTURE_FORMAT_BIMG(ATCE); BGFX_TEXTURE_FORMAT_BIMG(ATCI); BGFX_TEXTURE_FORMAT_BIMG(ASTC4x4); +BGFX_TEXTURE_FORMAT_BIMG(ASTC5x4); BGFX_TEXTURE_FORMAT_BIMG(ASTC5x5); +BGFX_TEXTURE_FORMAT_BIMG(ASTC6x5); BGFX_TEXTURE_FORMAT_BIMG(ASTC6x6); BGFX_TEXTURE_FORMAT_BIMG(ASTC8x5); BGFX_TEXTURE_FORMAT_BIMG(ASTC8x6); +BGFX_TEXTURE_FORMAT_BIMG(ASTC8x8); BGFX_TEXTURE_FORMAT_BIMG(ASTC10x5); +BGFX_TEXTURE_FORMAT_BIMG(ASTC10x6); +BGFX_TEXTURE_FORMAT_BIMG(ASTC10x8); +BGFX_TEXTURE_FORMAT_BIMG(ASTC10x10); +BGFX_TEXTURE_FORMAT_BIMG(ASTC12x10); +BGFX_TEXTURE_FORMAT_BIMG(ASTC12x12); BGFX_TEXTURE_FORMAT_BIMG(Unknown); BGFX_TEXTURE_FORMAT_BIMG(R1); BGFX_TEXTURE_FORMAT_BIMG(A8); @@ -4878,8 +5667,11 @@ BGFX_TEXTURE_FORMAT_BIMG(RGBA16S); BGFX_TEXTURE_FORMAT_BIMG(RGBA32I); BGFX_TEXTURE_FORMAT_BIMG(RGBA32U); BGFX_TEXTURE_FORMAT_BIMG(RGBA32F); +BGFX_TEXTURE_FORMAT_BIMG(B5G6R5); BGFX_TEXTURE_FORMAT_BIMG(R5G6B5); +BGFX_TEXTURE_FORMAT_BIMG(BGRA4); BGFX_TEXTURE_FORMAT_BIMG(RGBA4); +BGFX_TEXTURE_FORMAT_BIMG(BGR5A1); BGFX_TEXTURE_FORMAT_BIMG(RGB5A1); BGFX_TEXTURE_FORMAT_BIMG(RGB10A2); BGFX_TEXTURE_FORMAT_BIMG(RG11B10F); @@ -4897,7 +5689,6 @@ BGFX_TEXTURE_FORMAT_BIMG(Count); #undef BGFX_TEXTURE_FORMAT_BIMG #include <bgfx/c99/bgfx.h> -#include <bgfx/c99/platform.h> #define FLAGS_MASK_TEST(_flags, _mask) ( (_flags) == ( (_flags) & (_mask) ) ) @@ -4920,39 +5711,41 @@ BX_STATIC_ASSERT(FLAGS_MASK_TEST(0 BX_STATIC_ASSERT(FLAGS_MASK_TEST(0 | BGFX_SUBMIT_INTERNAL_OCCLUSION_VISIBLE - , BGFX_SUBMIT_RESERVED_MASK + , BGFX_SUBMIT_INTERNAL_RESERVED_MASK ) ); BX_STATIC_ASSERT( (0 - | BGFX_STATE_WRITE_MASK - | BGFX_STATE_DEPTH_TEST_MASK - | BGFX_STATE_BLEND_MASK + | BGFX_STATE_ALPHA_REF_MASK + | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE | BGFX_STATE_BLEND_EQUATION_MASK | BGFX_STATE_BLEND_INDEPENDENT - | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE + | BGFX_STATE_BLEND_MASK + | BGFX_STATE_CONSERVATIVE_RASTER | BGFX_STATE_CULL_MASK - | BGFX_STATE_ALPHA_REF_MASK - | BGFX_STATE_PT_MASK - | BGFX_STATE_POINT_SIZE_MASK - | BGFX_STATE_MSAA + | BGFX_STATE_DEPTH_TEST_MASK + | BGFX_STATE_FRONT_CCW | BGFX_STATE_LINEAA - | BGFX_STATE_CONSERVATIVE_RASTER + | BGFX_STATE_MSAA + | BGFX_STATE_POINT_SIZE_MASK + | BGFX_STATE_PT_MASK | BGFX_STATE_RESERVED_MASK + | BGFX_STATE_WRITE_MASK ) == (0 - ^ BGFX_STATE_WRITE_MASK - ^ BGFX_STATE_DEPTH_TEST_MASK - ^ BGFX_STATE_BLEND_MASK + ^ BGFX_STATE_ALPHA_REF_MASK + ^ BGFX_STATE_BLEND_ALPHA_TO_COVERAGE ^ BGFX_STATE_BLEND_EQUATION_MASK ^ BGFX_STATE_BLEND_INDEPENDENT - ^ BGFX_STATE_BLEND_ALPHA_TO_COVERAGE + ^ BGFX_STATE_BLEND_MASK + ^ BGFX_STATE_CONSERVATIVE_RASTER ^ BGFX_STATE_CULL_MASK - ^ BGFX_STATE_ALPHA_REF_MASK - ^ BGFX_STATE_PT_MASK - ^ BGFX_STATE_POINT_SIZE_MASK - ^ BGFX_STATE_MSAA + ^ BGFX_STATE_DEPTH_TEST_MASK + ^ BGFX_STATE_FRONT_CCW ^ BGFX_STATE_LINEAA - ^ BGFX_STATE_CONSERVATIVE_RASTER + ^ BGFX_STATE_MSAA + ^ BGFX_STATE_POINT_SIZE_MASK + ^ BGFX_STATE_PT_MASK ^ BGFX_STATE_RESERVED_MASK + ^ BGFX_STATE_WRITE_MASK ) ); BX_STATIC_ASSERT(FLAGS_MASK_TEST(BGFX_CAPS_TEXTURE_COMPARE_LEQUAL, BGFX_CAPS_TEXTURE_COMPARE_ALL) ); @@ -4982,6 +5775,8 @@ BX_STATIC_ASSERT( (0 | BGFX_CAPS_VERTEX_ATTRIB_HALF | BGFX_CAPS_VERTEX_ATTRIB_UINT10 | BGFX_CAPS_VERTEX_ID + | BGFX_CAPS_VIEWPORT_LAYER_ARRAY + | BGFX_CAPS_DRAW_INDIRECT_COUNT ) == (0 ^ BGFX_CAPS_ALPHA_TO_COVERAGE ^ BGFX_CAPS_BLEND_INDEPENDENT @@ -5007,46 +5802,12 @@ BX_STATIC_ASSERT( (0 ^ BGFX_CAPS_VERTEX_ATTRIB_HALF ^ BGFX_CAPS_VERTEX_ATTRIB_UINT10 ^ BGFX_CAPS_VERTEX_ID + ^ BGFX_CAPS_VIEWPORT_LAYER_ARRAY + ^ BGFX_CAPS_DRAW_INDIRECT_COUNT ) ); #undef FLAGS_MASK_TEST -#define BGFX_C99_ENUM_CHECK(_enum, _c99enumcount) \ - BX_STATIC_ASSERT(_enum::Count == _enum::Enum(_c99enumcount) ) - -BGFX_C99_ENUM_CHECK(bgfx::Fatal, BGFX_FATAL_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::RendererType, BGFX_RENDERER_TYPE_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::Attrib, BGFX_ATTRIB_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::AttribType, BGFX_ATTRIB_TYPE_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::TextureFormat, BGFX_TEXTURE_FORMAT_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::UniformType, BGFX_UNIFORM_TYPE_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::BackbufferRatio, BGFX_BACKBUFFER_RATIO_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::OcclusionQueryResult, BGFX_OCCLUSION_QUERY_RESULT_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::Topology, BGFX_TOPOLOGY_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::TopologyConvert, BGFX_TOPOLOGY_CONVERT_COUNT); -BGFX_C99_ENUM_CHECK(bgfx::RenderFrame, BGFX_RENDER_FRAME_COUNT); -#undef BGFX_C99_ENUM_CHECK - -#define BGFX_C99_STRUCT_SIZE_CHECK(_cppstruct, _c99struct) \ - BX_STATIC_ASSERT(sizeof(_cppstruct) == sizeof(_c99struct) ) - -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Memory, bgfx_memory_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Transform, bgfx_transform_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Stats, bgfx_stats_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::VertexDecl, bgfx_vertex_decl_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TransientIndexBuffer, bgfx_transient_index_buffer_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TransientVertexBuffer, bgfx_transient_vertex_buffer_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::InstanceDataBuffer, bgfx_instance_data_buffer_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TextureInfo, bgfx_texture_info_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::UniformInfo, bgfx_uniform_info_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Attachment, bgfx_attachment_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps::GPU, bgfx_caps_gpu_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps::Limits, bgfx_caps_limits_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps, bgfx_caps_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::PlatformData, bgfx_platform_data_t); -BGFX_C99_STRUCT_SIZE_CHECK(bgfx::InternalData, bgfx_internal_data_t); -#undef BGFX_C99_STRUCT_SIZE_CHECK - namespace bgfx { struct CallbackC99 : public CallbackI @@ -5135,1232 +5896,4 @@ namespace bgfx } // namespace bgfx -BGFX_C_API void bgfx_vertex_decl_begin(bgfx_vertex_decl_t* _decl, bgfx_renderer_type_t _renderer) -{ - bgfx::VertexDecl* decl = (bgfx::VertexDecl*)_decl; - decl->begin(bgfx::RendererType::Enum(_renderer) ); -} - -BGFX_C_API void bgfx_vertex_decl_add(bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt) -{ - bgfx::VertexDecl* decl = (bgfx::VertexDecl*)_decl; - decl->add(bgfx::Attrib::Enum(_attrib) - , _num - , bgfx::AttribType::Enum(_type) - , _normalized - , _asInt - ); -} - -BGFX_C_API void bgfx_vertex_decl_decode(const bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib, uint8_t* _num, bgfx_attrib_type_t* _type, bool* _normalized, bool* _asInt) -{ - bgfx::AttribType::Enum type; - const bgfx::VertexDecl* decl = (const bgfx::VertexDecl*)_decl; - decl->decode( - bgfx::Attrib::Enum(_attrib) - , *_num - , type - , *_normalized - , *_asInt - ); - *_type = (bgfx_attrib_type_t)type; -} - -BGFX_C_API bool bgfx_vertex_decl_has(const bgfx_vertex_decl_t* _decl, bgfx_attrib_t _attrib) -{ - const bgfx::VertexDecl* decl = (const bgfx::VertexDecl*)_decl; - return decl->has(bgfx::Attrib::Enum(_attrib)); -} - -BGFX_C_API void bgfx_vertex_decl_skip(bgfx_vertex_decl_t* _decl, uint8_t _num) -{ - bgfx::VertexDecl* decl = (bgfx::VertexDecl*)_decl; - decl->skip(_num); -} - -BGFX_C_API void bgfx_vertex_decl_end(bgfx_vertex_decl_t* _decl) -{ - bgfx::VertexDecl* decl = (bgfx::VertexDecl*)_decl; - decl->end(); -} - -BGFX_C_API void bgfx_vertex_pack(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, void* _data, uint32_t _index) -{ - bgfx::VertexDecl& decl = *(bgfx::VertexDecl*)_decl; - bgfx::vertexPack(_input, _inputNormalized, bgfx::Attrib::Enum(_attr), decl, _data, _index); -} - -BGFX_C_API void bgfx_vertex_unpack(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_decl_t* _decl, const void* _data, uint32_t _index) -{ - bgfx::VertexDecl& decl = *(bgfx::VertexDecl*)_decl; - bgfx::vertexUnpack(_output, bgfx::Attrib::Enum(_attr), decl, _data, _index); -} - -BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_decl_t* _destDecl, void* _destData, const bgfx_vertex_decl_t* _srcDecl, const void* _srcData, uint32_t _num) -{ - bgfx::VertexDecl& destDecl = *(bgfx::VertexDecl*)_destDecl; - bgfx::VertexDecl& srcDecl = *(bgfx::VertexDecl*)_srcDecl; - bgfx::vertexConvert(destDecl, _destData, srcDecl, _srcData, _num); -} - -BGFX_C_API uint16_t bgfx_weld_vertices(uint16_t* _output, const bgfx_vertex_decl_t* _decl, const void* _data, uint16_t _num, float _epsilon) -{ - bgfx::VertexDecl& decl = *(bgfx::VertexDecl*)_decl; - return bgfx::weldVertices(_output, decl, _data, _num, _epsilon); -} - -uint32_t bgfx_topology_convert(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32) -{ - return bgfx::topologyConvert(bgfx::TopologyConvert::Enum(_conversion), _dst, _dstSize, _indices, _numIndices, _index32); -} - -void bgfx_topology_sort_tri_list(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32) -{ - bgfx::topologySortTriList(bgfx::TopologySort::Enum(_sort), _dst, _dstSize, _dir, _pos, _vertices, _stride, _indices, _numIndices, _index32); -} - -BGFX_C_API uint8_t bgfx_get_supported_renderers(uint8_t _max, bgfx_renderer_type_t* _enum) -{ - return bgfx::getSupportedRenderers(_max, (bgfx::RendererType::Enum*)_enum); -} - -BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type) -{ - return bgfx::getRendererName(bgfx::RendererType::Enum(_type) ); -} - -BGFX_C_API void bgfx_init_ctor(bgfx_init_t* _init) -{ - BX_PLACEMENT_NEW(_init, bgfx::Init); -} - -BGFX_C_API bool bgfx_init(const bgfx_init_t* _init) -{ - bgfx_init_t init = *_init; - - if (init.callback != NULL) - { - static bgfx::CallbackC99 s_callback; - s_callback.m_interface = init.callback; - init.callback = reinterpret_cast<bgfx_callback_interface_t *>(&s_callback); - } - - if (init.allocator != NULL) - { - static bgfx::AllocatorC99 s_allocator; - s_allocator.m_interface = init.allocator; - init.allocator = reinterpret_cast<bgfx_allocator_interface_t *>(&s_allocator); - } - - union { const bgfx_init_t* c; const bgfx::Init* cpp; } in; - in.c = &init; - - return bgfx::init(*in.cpp); -} - -BGFX_C_API void bgfx_shutdown(void) -{ - return bgfx::shutdown(); -} - -BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags, bgfx_texture_format_t _format) -{ - bgfx::reset(_width, _height, _flags, bgfx::TextureFormat::Enum(_format) ); -} - -BGFX_C_API uint32_t bgfx_frame(bool _capture) -{ - return bgfx::frame(_capture); -} - -BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type(void) -{ - return bgfx_renderer_type_t(bgfx::getRendererType() ); -} - -BGFX_C_API const bgfx_caps_t* bgfx_get_caps(void) -{ - return (const bgfx_caps_t*)bgfx::getCaps(); -} - -BGFX_C_API const bgfx_stats_t* bgfx_get_stats(void) -{ - return (const bgfx_stats_t*)bgfx::getStats(); -} - -BGFX_C_API const bgfx_memory_t* bgfx_alloc(uint32_t _size) -{ - return (const bgfx_memory_t*)bgfx::alloc(_size); -} - -BGFX_C_API const bgfx_memory_t* bgfx_copy(const void* _data, uint32_t _size) -{ - return (const bgfx_memory_t*)bgfx::copy(_data, _size); -} - -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); -} - -BGFX_C_API void bgfx_dbg_text_clear(uint8_t _attr, bool _small) -{ - bgfx::dbgTextClear(_attr, _small); -} - -BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ...) -{ - va_list argList; - va_start(argList, _format); - bgfx::dbgTextPrintfVargs(_x, _y, _attr, _format, argList); - va_end(argList); -} - -BGFX_C_API void bgfx_dbg_text_vprintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList) -{ - bgfx::dbgTextPrintfVargs(_x, _y, _attr, _format, _argList); -} - -BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch) -{ - bgfx::dbgTextImage(_x, _y, _width, _height, _data, _pitch); -} - -BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint16_t _flags) -{ - union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createIndexBuffer( (const bgfx::Memory*)_mem, _flags); - return handle.c; -} - -BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle) -{ - union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags) -{ - const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle; - handle.cpp = bgfx::createVertexBuffer( (const bgfx::Memory*)_mem, decl, _flags); - return handle.c; -} - -BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle) -{ - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint16_t _flags) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer(_num, _flags); - return handle.c; -} - -BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicIndexBuffer( (const bgfx::Memory*)_mem, _flags); - return handle.c; -} - -BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; - bgfx::update(handle.cpp, _startIndex, (const bgfx::Memory*)_mem); -} - -BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl, uint16_t _flags) -{ - const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicVertexBuffer(_num, decl, _flags); - return handle.c; -} - -BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_decl_t* _decl, uint16_t _flags) -{ - const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle; - handle.cpp = bgfx::createDynamicVertexBuffer( (const bgfx::Memory*)_mem, decl, _flags); - return handle.c; -} - -BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - bgfx::update(handle.cpp, _startVertex, (const bgfx::Memory*)_mem); -} - -BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API uint32_t bgfx_get_avail_transient_index_buffer(uint32_t _num) -{ - return bgfx::getAvailTransientIndexBuffer(_num); -} - -BGFX_C_API uint32_t bgfx_get_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_decl_t* _decl) -{ - const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - return bgfx::getAvailTransientVertexBuffer(_num, decl); -} - -BGFX_C_API uint32_t bgfx_get_avail_instance_data_buffer(uint32_t _num, uint16_t _stride) -{ - return bgfx::getAvailInstanceDataBuffer(_num, _stride); -} - -BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num) -{ - bgfx::allocTransientIndexBuffer( (bgfx::TransientIndexBuffer*)_tib, _num); -} - -BGFX_C_API void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_decl_t* _decl) -{ - const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - bgfx::allocTransientVertexBuffer( (bgfx::TransientVertexBuffer*)_tvb, _num, decl); -} - -BGFX_C_API bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_decl_t* _decl, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices) -{ - const bgfx::VertexDecl& decl = *(const bgfx::VertexDecl*)_decl; - return bgfx::allocTransientBuffers( (bgfx::TransientVertexBuffer*)_tvb, decl, _numVertices, (bgfx::TransientIndexBuffer*)_tib, _numIndices); -} - -BGFX_C_API void bgfx_alloc_instance_data_buffer(bgfx_instance_data_buffer_t* _idb, uint32_t _num, uint16_t _stride) -{ - bgfx::allocInstanceDataBuffer( (bgfx::InstanceDataBuffer*)_idb, _num, _stride); -} - -BGFX_C_API bgfx_indirect_buffer_handle_t bgfx_create_indirect_buffer(uint32_t _num) -{ - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle; - handle.cpp = bgfx::createIndirectBuffer(_num); - return handle.c; -} - -BGFX_C_API void bgfx_destroy_indirect_buffer(bgfx_indirect_buffer_handle_t _handle) -{ - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem) -{ - union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle; - handle.cpp = bgfx::createShader( (const bgfx::Memory*)_mem); - return handle.c; -} - -BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max) -{ - union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; - return bgfx::getShaderUniforms(handle.cpp, (bgfx::UniformHandle*)_uniforms, _max); -} - -BGFX_C_API void bgfx_set_shader_name(bgfx_shader_handle_t _handle, const char* _name, int32_t _len) -{ - union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; - bgfx::setName(handle.cpp, _name, _len); -} - -BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle) -{ - union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders) -{ - union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } vsh = { _vsh }; - union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } fsh = { _fsh }; - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle; - handle.cpp = bgfx::createProgram(vsh.cpp, fsh.cpp, _destroyShaders); - return handle.c; -} - -BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_t _csh, bool _destroyShaders) -{ - union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } csh = { _csh }; - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle; - handle.cpp = bgfx::createProgram(csh.cpp, _destroyShaders); - return handle.c; -} - -BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bool bgfx_is_texture_valid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags) -{ - return bgfx::isTextureValid(_depth, _cubeMap, _numLayers, bgfx::TextureFormat::Enum(_format), _flags); -} - -BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t* _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format) -{ - bgfx::TextureInfo& info = *(bgfx::TextureInfo*)_info; - bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format) ); -} - -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint64_t _flags, uint8_t _skip, bgfx_texture_info_t* _info) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - bgfx::TextureInfo* info = (bgfx::TextureInfo*)_info; - handle.cpp = bgfx::createTexture( (const bgfx::Memory*)_mem, _flags, _skip, info); - return handle.c; -} - -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTexture2D(_width, _height, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); - return handle.c; -} - -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTexture2D(bgfx::BackbufferRatio::Enum(_ratio), _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags); - return handle.c; -} - -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTexture3D(_width, _height, _depth, _hasMips, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); - return handle.c; -} - -BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle; - handle.cpp = bgfx::createTextureCube(_size, _hasMips, _numLayers, bgfx::TextureFormat::Enum(_format), _flags, (const bgfx::Memory*)_mem); - return handle.c; -} - -BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::updateTexture2D(handle.cpp, _layer, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); -} - -BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::updateTexture3D(handle.cpp, _mip, _x, _y, _z, _width, _height, _depth, (const bgfx::Memory*)_mem); -} - -BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::updateTextureCube(handle.cpp, _layer, _side, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); -} - -BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - return bgfx::readTexture(handle.cpp, _data, _mip); -} - -BGFX_C_API void bgfx_set_texture_name(bgfx_texture_handle_t _handle, const char* _name, int32_t _len) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::setName(handle.cpp, _name, _len); -} - -BGFX_C_API void* bgfx_get_direct_access_ptr(bgfx_texture_handle_t _handle) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - return bgfx::getDirectAccessPtr(handle.cpp); -} - -BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint64_t _textureFlags) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; - handle.cpp = bgfx::createFrameBuffer(_width, _height, bgfx::TextureFormat::Enum(_format), _textureFlags); - return handle.c; -} - -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint64_t _textureFlags) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; - handle.cpp = bgfx::createFrameBuffer(bgfx::BackbufferRatio::Enum(_ratio), bgfx::TextureFormat::Enum(_format), _textureFlags); - return handle.c; -} - -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTextures) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; - handle.cpp = bgfx::createFrameBuffer(_num, (const bgfx::TextureHandle*)_handles, _destroyTextures); - return handle.c; -} - -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_attachment(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTextures) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; - handle.cpp = bgfx::createFrameBuffer(_num, (const bgfx::Attachment*)_attachment, _destroyTextures); - return handle.c; -} - -BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, bgfx_texture_format_t _depthFormat) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle; - handle.cpp = bgfx::createFrameBuffer(_nwh, _width, _height, bgfx::TextureFormat::Enum(_format), bgfx::TextureFormat::Enum(_depthFormat) ); - return handle.c; -} - -BGFX_C_API bgfx_texture_handle_t bgfx_get_texture(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } textureHandle; - textureHandle.cpp = bgfx::getTexture(handle.cpp, _attachment); - return textureHandle.c; -} - -BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uniform_type_t _type, uint16_t _num) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle; - handle.cpp = bgfx::createUniform(_name, bgfx::UniformType::Enum(_type), _num); - return handle.c; -} - -BGFX_C_API void bgfx_get_uniform_info(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t* _info) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; - bgfx::UniformInfo& info = *(bgfx::UniformInfo*)_info; - bgfx::getUniformInfo(handle.cpp, info); -} - -BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API bgfx_occlusion_query_handle_t bgfx_create_occlusion_query(void) -{ - union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle; - handle.cpp = bgfx::createOcclusionQuery(); - return handle.c; -} - -BGFX_C_API bgfx_occlusion_query_result_t bgfx_get_result(bgfx_occlusion_query_handle_t _handle, int32_t* _result) -{ - union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; - return bgfx_occlusion_query_result_t(bgfx::getResult(handle.cpp, _result) ); -} - -BGFX_C_API void bgfx_destroy_occlusion_query(bgfx_occlusion_query_handle_t _handle) -{ - union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; - bgfx::destroy(handle.cpp); -} - -BGFX_C_API void bgfx_set_palette_color(uint8_t _index, const float _rgba[4]) -{ - bgfx::setPaletteColor(_index, _rgba); -} - -BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name) -{ - bgfx::setViewName(_id, _name); -} - -BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) -{ - bgfx::setViewRect(_id, _x, _y, _width, _height); -} - -BGFX_C_API void bgfx_set_view_rect_auto(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio) -{ - bgfx::setViewRect(_id, _x, _y, bgfx::BackbufferRatio::Enum(_ratio)); -} - -BGFX_C_API void bgfx_set_view_scissor(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) -{ - bgfx::setViewScissor(_id, _x, _y, _width, _height); -} - -BGFX_C_API void bgfx_set_view_clear(bgfx_view_id_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) -{ - bgfx::setViewClear(_id, _flags, _rgba, _depth, _stencil); -} - -BGFX_C_API void bgfx_set_view_clear_mrt(bgfx_view_id_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) -{ - bgfx::setViewClear(_id, _flags, _depth, _stencil, _0, _1, _2, _3, _4, _5, _6, _7); -} - -BGFX_C_API void bgfx_set_view_mode(bgfx_view_id_t _id, bgfx_view_mode_t _mode) -{ - bgfx::setViewMode(_id, bgfx::ViewMode::Enum(_mode) ); -} - -BGFX_C_API void bgfx_set_view_frame_buffer(bgfx_view_id_t _id, bgfx_frame_buffer_handle_t _handle) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - bgfx::setViewFrameBuffer(_id, handle.cpp); -} - -BGFX_C_API void bgfx_set_view_transform(bgfx_view_id_t _id, const void* _view, const void* _proj) -{ - bgfx::setViewTransform(_id, _view, _proj); -} - -BGFX_C_API void bgfx_set_view_transform_stereo(bgfx_view_id_t _id, const void* _view, const void* _projL, uint8_t _flags, const void* _projR) -{ - bgfx::setViewTransform(_id, _view, _projL, _flags, _projR); -} - -BGFX_C_API void bgfx_set_view_order(bgfx_view_id_t _id, uint16_t _num, const bgfx_view_id_t* _order) -{ - bgfx::setViewOrder(_id, _num, _order); -} - -BGFX_C_API void bgfx_reset_view(bgfx_view_id_t _id) -{ - bgfx::resetView(_id); -} - -BGFX_C_API void bgfx_set_marker(const char* _marker) -{ - bgfx::setMarker(_marker); -} - -BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba) -{ - bgfx::setState(_state, _rgba); -} - -BGFX_C_API void bgfx_set_condition(bgfx_occlusion_query_handle_t _handle, bool _visible) -{ - union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; - bgfx::setCondition(handle.cpp, _visible); -} - -BGFX_C_API void bgfx_set_stencil(uint32_t _fstencil, uint32_t _bstencil) -{ - bgfx::setStencil(_fstencil, _bstencil); -} - -BGFX_C_API uint16_t bgfx_set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) -{ - return bgfx::setScissor(_x, _y, _width, _height); -} - -BGFX_C_API void bgfx_set_scissor_cached(uint16_t _cache) -{ - bgfx::setScissor(_cache); -} - -BGFX_C_API uint32_t bgfx_set_transform(const void* _mtx, uint16_t _num) -{ - return bgfx::setTransform(_mtx, _num); -} - -BGFX_C_API uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num) -{ - return bgfx::allocTransform( (bgfx::Transform*)_transform, _num); -} - -BGFX_C_API void bgfx_set_transform_cached(uint32_t _cache, uint16_t _num) -{ - bgfx::setTransform(_cache, _num); -} - -BGFX_C_API void bgfx_set_uniform(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; - bgfx::setUniform(handle.cpp, _value, _num); -} - -BGFX_C_API void bgfx_set_index_buffer(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) -{ - union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; - bgfx::setIndexBuffer(handle.cpp, _firstIndex, _numIndices); -} - -BGFX_C_API void bgfx_set_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; - bgfx::setIndexBuffer(handle.cpp, _firstIndex, _numIndices); -} - -BGFX_C_API void bgfx_set_transient_index_buffer(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices) -{ - bgfx::setIndexBuffer( (const bgfx::TransientIndexBuffer*)_tib, _firstIndex, _numIndices); -} - -BGFX_C_API void bgfx_set_vertex_buffer(uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) -{ - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; - bgfx::setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices); -} - -BGFX_C_API void bgfx_set_dynamic_vertex_buffer(uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - bgfx::setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices); -} - -BGFX_C_API void bgfx_set_transient_vertex_buffer(uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices) -{ - bgfx::setVertexBuffer(_stream, (const bgfx::TransientVertexBuffer*)_tvb, _startVertex, _numVertices); -} - -BGFX_C_API void bgfx_set_vertex_count(uint32_t _numVertices) -{ - bgfx::setVertexCount(_numVertices); -} - -BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num) -{ - bgfx::setInstanceDataBuffer( (const bgfx::InstanceDataBuffer*)_idb, _start, _num); -} - -BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) -{ - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; - bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); -} - -BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); -} - -BGFX_C_API void bgfx_set_instance_count(uint32_t _numInstances) -{ - bgfx::setInstanceCount(_numInstances); -} - -BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::setTexture(_stage, sampler.cpp, handle.cpp, _flags); -} - -BGFX_C_API void bgfx_touch(bgfx_view_id_t _id) -{ - return bgfx::touch(_id); -} - -BGFX_C_API void bgfx_submit(bgfx_view_id_t _id, bgfx_program_handle_t _handle, uint32_t _depth, bool _preserveState) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - bgfx::submit(_id, handle.cpp, _depth, _preserveState); -} - -BGFX_C_API void bgfx_submit_occlusion_query(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, bool _preserveState) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; - union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } occlusionQuery = { _occlusionQuery }; - bgfx::submit(_id, program.cpp, occlusionQuery.cpp, _depth, _preserveState); -} - -BGFX_C_API void bgfx_submit_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, bool _preserveState) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; - bgfx::submit(_id, handle.cpp, indirectHandle.cpp, _start, _num, _depth, _preserveState); -} - -BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - bgfx::setImage(_stage, handle.cpp, _mip, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) ); -} - -BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; - bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); -} - -BGFX_C_API void bgfx_set_compute_vertex_buffer(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; - bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); -} - -BGFX_C_API void bgfx_set_compute_dynamic_index_buffer(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; - bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); -} - -BGFX_C_API void bgfx_set_compute_dynamic_vertex_buffer(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); -} - -BGFX_C_API void bgfx_set_compute_indirect_buffer(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; - bgfx::setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ); -} - -BGFX_C_API void bgfx_dispatch(bgfx_view_id_t _id, bgfx_program_handle_t _handle, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - bgfx::dispatch(_id, handle.cpp, _numX, _numY, _numZ, _flags); -} - -BGFX_C_API void bgfx_dispatch_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; - bgfx::dispatch(_id, handle.cpp, indirectHandle.cpp, _start, _num, _flags); -} - -BGFX_C_API void bgfx_discard(void) -{ - bgfx::discard(); -} - -BGFX_C_API void bgfx_blit(bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } dst = { _dst }; - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } src = { _src }; - bgfx::blit(_id, dst.cpp, _dstMip, _dstX, _dstY, _dstZ, src.cpp, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); -} - -#define BGFX_ENCODER(_func) reinterpret_cast<bgfx::Encoder*>(_encoder)->_func - -BGFX_C_API void bgfx_encoder_set_marker(bgfx_encoder_s* _encoder, const char* _marker) -{ - BGFX_ENCODER(setMarker(_marker) ); -} - -BGFX_C_API void bgfx_encoder_set_state(bgfx_encoder_s* _encoder, uint64_t _state, uint32_t _rgba) -{ - BGFX_ENCODER(setState(_state, _rgba) ); -} - -BGFX_C_API void bgfx_encoder_set_condition(bgfx_encoder_s* _encoder, bgfx_occlusion_query_handle_t _handle, bool _visible) -{ - union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setCondition(handle.cpp, _visible) ); -} - -BGFX_C_API void bgfx_encoder_set_stencil(bgfx_encoder_s* _encoder, uint32_t _fstencil, uint32_t _bstencil) -{ - BGFX_ENCODER(setStencil(_fstencil, _bstencil) ); -} - -BGFX_C_API uint16_t bgfx_encoder_set_scissor(bgfx_encoder_s* _encoder, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) -{ - return BGFX_ENCODER(setScissor(_x, _y, _width, _height) ); -} - -BGFX_C_API void bgfx_encoder_set_scissor_cached(bgfx_encoder_s* _encoder, uint16_t _cache) -{ - BGFX_ENCODER(setScissor(_cache) ); -} - -BGFX_C_API uint32_t bgfx_encoder_set_transform(bgfx_encoder_s* _encoder, const void* _mtx, uint16_t _num) -{ - return BGFX_ENCODER(setTransform(_mtx, _num) ); -} - -BGFX_C_API uint32_t bgfx_encoder_alloc_transform(bgfx_encoder_s* _encoder, bgfx_transform_t* _transform, uint16_t _num) -{ - return BGFX_ENCODER(allocTransform( (bgfx::Transform*)_transform, _num) ); -} - -BGFX_C_API void bgfx_encoder_set_transform_cached(bgfx_encoder_s* _encoder, uint32_t _cache, uint16_t _num) -{ - BGFX_ENCODER(setTransform(_cache, _num) ); -} - -BGFX_C_API void bgfx_encoder_set_uniform(bgfx_encoder_s* _encoder, bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setUniform(handle.cpp, _value, _num) ); -} - -BGFX_C_API void bgfx_encoder_set_index_buffer(bgfx_encoder_s* _encoder, bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) -{ - union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setIndexBuffer(handle.cpp, _firstIndex, _numIndices) ); -} - -BGFX_C_API void bgfx_encoder_set_dynamic_index_buffer(bgfx_encoder_s* _encoder, bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setIndexBuffer(handle.cpp, _firstIndex, _numIndices) ); -} - -BGFX_C_API void bgfx_encoder_set_transient_index_buffer(bgfx_encoder_s* _encoder, const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices) -{ - BGFX_ENCODER(setIndexBuffer( (const bgfx::TransientIndexBuffer*)_tib, _firstIndex, _numIndices) ); -} - -BGFX_C_API void bgfx_encoder_set_vertex_buffer(bgfx_encoder_s* _encoder, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) -{ - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices) ); -} - -BGFX_C_API void bgfx_encoder_set_dynamic_vertex_buffer(bgfx_encoder_s* _encoder, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices) ); -} - -BGFX_C_API void bgfx_encoder_set_transient_vertex_buffer(bgfx_encoder_s* _encoder, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices) -{ - BGFX_ENCODER(setVertexBuffer(_stream, (const bgfx::TransientVertexBuffer*)_tvb, _startVertex, _numVertices) ); -} - -BGFX_C_API void bgfx_encoder_set_vertex_count(bgfx_encoder_s* _encoder, uint32_t _numVertices) -{ - BGFX_ENCODER(setVertexCount(_numVertices) ); -} - -BGFX_C_API void bgfx_encoder_set_instance_data_buffer(bgfx_encoder_s* _encoder, const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num) -{ - BGFX_ENCODER(setInstanceDataBuffer( (const bgfx::InstanceDataBuffer*)_idb, _start, _num) ); -} - -BGFX_C_API void bgfx_encoder_set_instance_data_from_vertex_buffer(bgfx_encoder_s* _encoder, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) -{ - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setInstanceDataBuffer(handle.cpp, _startVertex, _num) ); -} - -BGFX_C_API void bgfx_encoder_set_instance_data_from_dynamic_vertex_buffer(bgfx_encoder_s* _encoder, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setInstanceDataBuffer(handle.cpp, _startVertex, _num) ); -} - -BGFX_C_API void bgfx_encoder_set_instance_count(bgfx_encoder_s* _encoder, uint32_t _numInstances) -{ - BGFX_ENCODER(setInstanceCount(_numInstances) ); -} - -BGFX_C_API void bgfx_encoder_set_texture(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags) -{ - union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setTexture(_stage, sampler.cpp, handle.cpp, _flags) ); -} - -BGFX_C_API void bgfx_encoder_touch(bgfx_encoder_s* _encoder, bgfx_view_id_t _id) -{ - return BGFX_ENCODER(touch(_id) ); -} - -BGFX_C_API void bgfx_encoder_submit(bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, uint32_t _depth, bool _preserveState) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - BGFX_ENCODER(submit(_id, handle.cpp, _depth, _preserveState) ); -} - -BGFX_C_API void bgfx_encoder_submit_occlusion_query(bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, bool _preserveState) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; - union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } occlusionQuery = { _occlusionQuery }; - BGFX_ENCODER(submit(_id, program.cpp, occlusionQuery.cpp, _depth, _preserveState) ); -} - -BGFX_C_API void bgfx_encoder_submit_indirect(bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, bool _preserveState) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; - BGFX_ENCODER(submit(_id, handle.cpp, indirectHandle.cpp, _start, _num, _depth, _preserveState) ); -} - -BGFX_C_API void bgfx_encoder_set_image(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setImage(_stage, handle.cpp, _mip, bgfx::Access::Enum(_access), bgfx::TextureFormat::Enum(_format) ) ); -} - -BGFX_C_API void bgfx_encoder_set_compute_index_buffer(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ) ); -} - -BGFX_C_API void bgfx_encoder_set_compute_vertex_buffer(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ) ); -} - -BGFX_C_API void bgfx_encoder_set_compute_dynamic_index_buffer(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ) ); -} - -BGFX_C_API void bgfx_encoder_set_compute_dynamic_vertex_buffer(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ) ); -} - -BGFX_C_API void bgfx_encoder_set_compute_indirect_buffer(bgfx_encoder_s* _encoder, uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access) -{ - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; - BGFX_ENCODER(setBuffer(_stage, handle.cpp, bgfx::Access::Enum(_access) ) ); -} - -BGFX_C_API void bgfx_encoder_dispatch(bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - BGFX_ENCODER(dispatch(_id, handle.cpp, _numX, _numY, _numZ, _flags) ); -} - -BGFX_C_API void bgfx_encoder_dispatch_indirect(bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_program_handle_t _handle, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) -{ - union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; - union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; - BGFX_ENCODER(dispatch(_id, handle.cpp, indirectHandle.cpp, _start, _num, _flags) ); -} - -BGFX_C_API void bgfx_encoder_discard(bgfx_encoder_s* _encoder) -{ - BGFX_ENCODER(discard() ); -} - -BGFX_C_API void bgfx_encoder_blit(bgfx_encoder_s* _encoder, bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } dst = { _dst }; - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } src = { _src }; - BGFX_ENCODER(blit(_id, dst.cpp, _dstMip, _dstX, _dstY, _dstZ, src.cpp, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth) ); -} - -#undef BGFX_ENCODER - -BGFX_C_API void bgfx_request_screen_shot(bgfx_frame_buffer_handle_t _handle, const char* _filePath) -{ - union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; - bgfx::requestScreenShot(handle.cpp, _filePath); -} - -BGFX_C_API bgfx_render_frame_t bgfx_render_frame(int32_t _msecs) -{ - return bgfx_render_frame_t(bgfx::renderFrame(_msecs) ); -} - -BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t* _data) -{ - bgfx::setPlatformData(*(const bgfx::PlatformData*)_data); -} - -BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data() -{ - return (const bgfx_internal_data_t*)bgfx::getInternalData(); -} - -BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - return bgfx::overrideInternal(handle.cpp, _ptr); -} - -BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint32_t _flags) -{ - union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; - return bgfx::overrideInternal(handle.cpp, _width, _height, _numMips, bgfx::TextureFormat::Enum(_format), _flags); -} - -BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) -{ - if (_version == BGFX_API_VERSION) - { -#define BGFX_IMPORT \ - BGFX_IMPORT_FUNC(render_frame) \ - BGFX_IMPORT_FUNC(set_platform_data) \ - BGFX_IMPORT_FUNC(get_internal_data) \ - BGFX_IMPORT_FUNC(override_internal_texture_ptr) \ - BGFX_IMPORT_FUNC(override_internal_texture) \ - BGFX_IMPORT_FUNC(vertex_decl_begin) \ - BGFX_IMPORT_FUNC(vertex_decl_add) \ - BGFX_IMPORT_FUNC(vertex_decl_decode) \ - BGFX_IMPORT_FUNC(vertex_decl_has) \ - BGFX_IMPORT_FUNC(vertex_decl_skip) \ - BGFX_IMPORT_FUNC(vertex_decl_end) \ - BGFX_IMPORT_FUNC(vertex_pack) \ - BGFX_IMPORT_FUNC(vertex_unpack) \ - BGFX_IMPORT_FUNC(vertex_convert) \ - BGFX_IMPORT_FUNC(weld_vertices) \ - BGFX_IMPORT_FUNC(topology_convert) \ - BGFX_IMPORT_FUNC(topology_sort_tri_list) \ - BGFX_IMPORT_FUNC(get_supported_renderers) \ - BGFX_IMPORT_FUNC(get_renderer_name) \ - BGFX_IMPORT_FUNC(init_ctor) \ - BGFX_IMPORT_FUNC(init) \ - BGFX_IMPORT_FUNC(shutdown) \ - BGFX_IMPORT_FUNC(reset) \ - BGFX_IMPORT_FUNC(frame) \ - BGFX_IMPORT_FUNC(get_renderer_type) \ - BGFX_IMPORT_FUNC(get_caps) \ - BGFX_IMPORT_FUNC(get_stats) \ - BGFX_IMPORT_FUNC(alloc) \ - BGFX_IMPORT_FUNC(copy) \ - BGFX_IMPORT_FUNC(make_ref) \ - BGFX_IMPORT_FUNC(make_ref_release) \ - BGFX_IMPORT_FUNC(set_debug) \ - BGFX_IMPORT_FUNC(dbg_text_clear) \ - BGFX_IMPORT_FUNC(dbg_text_printf) \ - BGFX_IMPORT_FUNC(dbg_text_vprintf) \ - BGFX_IMPORT_FUNC(dbg_text_image) \ - BGFX_IMPORT_FUNC(create_index_buffer) \ - BGFX_IMPORT_FUNC(destroy_index_buffer) \ - BGFX_IMPORT_FUNC(create_vertex_buffer) \ - BGFX_IMPORT_FUNC(destroy_vertex_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_index_buffer_mem) \ - BGFX_IMPORT_FUNC(update_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(destroy_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(create_dynamic_vertex_buffer_mem) \ - BGFX_IMPORT_FUNC(update_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(destroy_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(get_avail_transient_index_buffer) \ - BGFX_IMPORT_FUNC(get_avail_transient_vertex_buffer) \ - BGFX_IMPORT_FUNC(get_avail_instance_data_buffer) \ - BGFX_IMPORT_FUNC(alloc_transient_index_buffer) \ - BGFX_IMPORT_FUNC(alloc_transient_vertex_buffer) \ - BGFX_IMPORT_FUNC(alloc_transient_buffers) \ - BGFX_IMPORT_FUNC(alloc_instance_data_buffer) \ - BGFX_IMPORT_FUNC(create_indirect_buffer) \ - BGFX_IMPORT_FUNC(destroy_indirect_buffer) \ - BGFX_IMPORT_FUNC(create_shader) \ - BGFX_IMPORT_FUNC(get_shader_uniforms) \ - BGFX_IMPORT_FUNC(set_shader_name) \ - BGFX_IMPORT_FUNC(destroy_shader) \ - BGFX_IMPORT_FUNC(create_program) \ - BGFX_IMPORT_FUNC(create_compute_program) \ - BGFX_IMPORT_FUNC(destroy_program) \ - BGFX_IMPORT_FUNC(is_texture_valid) \ - BGFX_IMPORT_FUNC(calc_texture_size) \ - BGFX_IMPORT_FUNC(create_texture) \ - BGFX_IMPORT_FUNC(create_texture_2d) \ - BGFX_IMPORT_FUNC(create_texture_2d_scaled) \ - BGFX_IMPORT_FUNC(create_texture_3d) \ - BGFX_IMPORT_FUNC(create_texture_cube) \ - BGFX_IMPORT_FUNC(update_texture_2d) \ - BGFX_IMPORT_FUNC(update_texture_3d) \ - BGFX_IMPORT_FUNC(update_texture_cube) \ - BGFX_IMPORT_FUNC(read_texture) \ - BGFX_IMPORT_FUNC(set_texture_name) \ - BGFX_IMPORT_FUNC(get_direct_access_ptr) \ - BGFX_IMPORT_FUNC(destroy_texture) \ - BGFX_IMPORT_FUNC(create_frame_buffer) \ - BGFX_IMPORT_FUNC(create_frame_buffer_scaled) \ - BGFX_IMPORT_FUNC(create_frame_buffer_from_attachment) \ - BGFX_IMPORT_FUNC(create_frame_buffer_from_nwh) \ - BGFX_IMPORT_FUNC(get_texture) \ - BGFX_IMPORT_FUNC(destroy_frame_buffer) \ - BGFX_IMPORT_FUNC(create_uniform) \ - BGFX_IMPORT_FUNC(get_uniform_info) \ - BGFX_IMPORT_FUNC(destroy_uniform) \ - BGFX_IMPORT_FUNC(create_occlusion_query) \ - BGFX_IMPORT_FUNC(get_result) \ - BGFX_IMPORT_FUNC(destroy_occlusion_query) \ - BGFX_IMPORT_FUNC(set_palette_color) \ - BGFX_IMPORT_FUNC(set_view_name) \ - BGFX_IMPORT_FUNC(set_view_rect) \ - BGFX_IMPORT_FUNC(set_view_scissor) \ - BGFX_IMPORT_FUNC(set_view_clear) \ - BGFX_IMPORT_FUNC(set_view_clear_mrt) \ - BGFX_IMPORT_FUNC(set_view_mode) \ - BGFX_IMPORT_FUNC(set_view_frame_buffer) \ - BGFX_IMPORT_FUNC(set_view_transform) \ - BGFX_IMPORT_FUNC(set_view_transform_stereo) \ - BGFX_IMPORT_FUNC(set_view_order) \ - BGFX_IMPORT_FUNC(encoder_set_marker) \ - BGFX_IMPORT_FUNC(encoder_set_state) \ - BGFX_IMPORT_FUNC(encoder_set_condition) \ - BGFX_IMPORT_FUNC(encoder_set_stencil) \ - BGFX_IMPORT_FUNC(encoder_set_scissor) \ - BGFX_IMPORT_FUNC(encoder_set_scissor_cached) \ - BGFX_IMPORT_FUNC(encoder_set_transform) \ - BGFX_IMPORT_FUNC(encoder_alloc_transform) \ - BGFX_IMPORT_FUNC(encoder_set_transform_cached) \ - BGFX_IMPORT_FUNC(encoder_set_uniform) \ - BGFX_IMPORT_FUNC(encoder_set_index_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_transient_index_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_vertex_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_transient_vertex_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_vertex_count) \ - BGFX_IMPORT_FUNC(encoder_set_instance_data_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_instance_data_from_vertex_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_instance_data_from_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_instance_count) \ - BGFX_IMPORT_FUNC(encoder_set_texture) \ - BGFX_IMPORT_FUNC(encoder_touch) \ - BGFX_IMPORT_FUNC(encoder_submit) \ - BGFX_IMPORT_FUNC(encoder_submit_occlusion_query) \ - BGFX_IMPORT_FUNC(encoder_submit_indirect) \ - BGFX_IMPORT_FUNC(encoder_set_image) \ - BGFX_IMPORT_FUNC(encoder_set_compute_index_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_compute_vertex_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_compute_dynamic_index_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_compute_dynamic_vertex_buffer) \ - BGFX_IMPORT_FUNC(encoder_set_compute_indirect_buffer) \ - BGFX_IMPORT_FUNC(encoder_dispatch) \ - BGFX_IMPORT_FUNC(encoder_dispatch_indirect) \ - BGFX_IMPORT_FUNC(encoder_discard) \ - BGFX_IMPORT_FUNC(encoder_blit) \ - BGFX_IMPORT_FUNC(request_screen_shot) - - static bgfx_interface_vtbl_t s_bgfx_interface = - { -#define BGFX_IMPORT_FUNC(_name) BX_CONCATENATE(bgfx_, _name), - BGFX_IMPORT -#undef BGFX_IMPORT_FUNC - }; - - return &s_bgfx_interface; - } - - return NULL; -} +#include "bgfx.idl.inl" diff --git a/3rdparty/bgfx/src/bgfx.idl.inl b/3rdparty/bgfx/src/bgfx.idl.inl new file mode 100644 index 00000000000..2c3b16fe469 --- /dev/null +++ b/3rdparty/bgfx/src/bgfx.idl.inl @@ -0,0 +1,1476 @@ +/* + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +/* + * + * AUTO GENERATED FROM IDL! DO NOT EDIT! (source : temp.bgfx.idl.inl) + * + * More info about IDL: + * https://gist.github.com/bkaradzic/05a1c86a6dd57bf86e2d828878e88dc2#bgfx-is-switching-to-idl-to-generate-api + * + */ + +#define BGFX_C99_ENUM_CHECK(_enum, _c99enumcount) \ + BX_STATIC_ASSERT(_enum::Count == _enum::Enum(_c99enumcount) ) + +BGFX_C99_ENUM_CHECK(bgfx::Fatal, BGFX_FATAL_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::RendererType, BGFX_RENDERER_TYPE_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::Attrib, BGFX_ATTRIB_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::AttribType, BGFX_ATTRIB_TYPE_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::TextureFormat, BGFX_TEXTURE_FORMAT_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::UniformType, BGFX_UNIFORM_TYPE_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::BackbufferRatio, BGFX_BACKBUFFER_RATIO_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::OcclusionQueryResult, BGFX_OCCLUSION_QUERY_RESULT_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::Topology, BGFX_TOPOLOGY_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::TopologyConvert, BGFX_TOPOLOGY_CONVERT_COUNT); +BGFX_C99_ENUM_CHECK(bgfx::RenderFrame, BGFX_RENDER_FRAME_COUNT); + +#undef BGFX_C99_ENUM_CHECK + +#define BGFX_C99_STRUCT_SIZE_CHECK(_cppstruct, _c99struct) \ + BX_STATIC_ASSERT(sizeof(_cppstruct) == sizeof(_c99struct) ) + +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Memory, bgfx_memory_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Transform, bgfx_transform_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Stats, bgfx_stats_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::VertexLayout, bgfx_vertex_layout_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TransientIndexBuffer, bgfx_transient_index_buffer_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TransientVertexBuffer, bgfx_transient_vertex_buffer_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::InstanceDataBuffer, bgfx_instance_data_buffer_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::TextureInfo, bgfx_texture_info_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::UniformInfo, bgfx_uniform_info_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Attachment, bgfx_attachment_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps::GPU, bgfx_caps_gpu_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps::Limits, bgfx_caps_limits_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::Caps, bgfx_caps_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::PlatformData, bgfx_platform_data_t); +BGFX_C99_STRUCT_SIZE_CHECK(bgfx::InternalData, bgfx_internal_data_t); + +#undef BGFX_C99_STRUCT_SIZE_CHECK + +BGFX_C_API void bgfx_attachment_init(bgfx_attachment_t* _this, bgfx_texture_handle_t _handle, bgfx_access_t _access, uint16_t _layer, uint16_t _numLayers, uint16_t _mip, uint8_t _resolve) +{ + bgfx::Attachment* This = (bgfx::Attachment*)_this; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + This->init(handle.cpp, (bgfx::Access::Enum)_access, _layer, _numLayers, _mip, _resolve); +} + +BGFX_C_API bgfx_vertex_layout_t* bgfx_vertex_layout_begin(bgfx_vertex_layout_t* _this, bgfx_renderer_type_t _rendererType) +{ + bgfx::VertexLayout* This = (bgfx::VertexLayout*)_this; + return (bgfx_vertex_layout_t*)&This->begin((bgfx::RendererType::Enum)_rendererType); +} + +BGFX_C_API bgfx_vertex_layout_t* bgfx_vertex_layout_add(bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t _num, bgfx_attrib_type_t _type, bool _normalized, bool _asInt) +{ + bgfx::VertexLayout* This = (bgfx::VertexLayout*)_this; + return (bgfx_vertex_layout_t*)&This->add((bgfx::Attrib::Enum)_attrib, _num, (bgfx::AttribType::Enum)_type, _normalized, _asInt); +} + +BGFX_C_API void bgfx_vertex_layout_decode(const bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib, uint8_t * _num, bgfx_attrib_type_t * _type, bool * _normalized, bool * _asInt) +{ + const bgfx::VertexLayout* This = (const bgfx::VertexLayout*)_this; + bgfx::AttribType::Enum type; + This->decode((bgfx::Attrib::Enum)_attrib, *_num, type, *_normalized, *_asInt); + *_type = (bgfx_attrib_type_t)type; +} + +BGFX_C_API bool bgfx_vertex_layout_has(const bgfx_vertex_layout_t* _this, bgfx_attrib_t _attrib) +{ + const bgfx::VertexLayout* This = (const bgfx::VertexLayout*)_this; + return This->has((bgfx::Attrib::Enum)_attrib); +} + +BGFX_C_API bgfx_vertex_layout_t* bgfx_vertex_layout_skip(bgfx_vertex_layout_t* _this, uint8_t _num) +{ + bgfx::VertexLayout* This = (bgfx::VertexLayout*)_this; + return (bgfx_vertex_layout_t*)&This->skip(_num); +} + +BGFX_C_API void bgfx_vertex_layout_end(bgfx_vertex_layout_t* _this) +{ + bgfx::VertexLayout* This = (bgfx::VertexLayout*)_this; + This->end(); +} + +BGFX_C_API void bgfx_vertex_pack(const float _input[4], bool _inputNormalized, bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, void* _data, uint32_t _index) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + bgfx::vertexPack(_input, _inputNormalized, (bgfx::Attrib::Enum)_attr, layout, _data, _index); +} + +BGFX_C_API void bgfx_vertex_unpack(float _output[4], bgfx_attrib_t _attr, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _index) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + bgfx::vertexUnpack(_output, (bgfx::Attrib::Enum)_attr, layout, _data, _index); +} + +BGFX_C_API void bgfx_vertex_convert(const bgfx_vertex_layout_t * _dstLayout, void* _dstData, const bgfx_vertex_layout_t * _srcLayout, const void* _srcData, uint32_t _num) +{ + const bgfx::VertexLayout & dstLayout = *(const bgfx::VertexLayout *)_dstLayout; + const bgfx::VertexLayout & srcLayout = *(const bgfx::VertexLayout *)_srcLayout; + bgfx::vertexConvert(dstLayout, _dstData, srcLayout, _srcData, _num); +} + +BGFX_C_API uint32_t bgfx_weld_vertices(void* _output, const bgfx_vertex_layout_t * _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + return bgfx::weldVertices(_output, layout, _data, _num, _index32, _epsilon); +} + +BGFX_C_API uint32_t bgfx_topology_convert(bgfx_topology_convert_t _conversion, void* _dst, uint32_t _dstSize, const void* _indices, uint32_t _numIndices, bool _index32) +{ + return bgfx::topologyConvert((bgfx::TopologyConvert::Enum)_conversion, _dst, _dstSize, _indices, _numIndices, _index32); +} + +BGFX_C_API void bgfx_topology_sort_tri_list(bgfx_topology_sort_t _sort, void* _dst, uint32_t _dstSize, const float _dir[3], const float _pos[3], const void* _vertices, uint32_t _stride, const void* _indices, uint32_t _numIndices, bool _index32) +{ + bgfx::topologySortTriList((bgfx::TopologySort::Enum)_sort, _dst, _dstSize, _dir, _pos, _vertices, _stride, _indices, _numIndices, _index32); +} + +BGFX_C_API uint8_t bgfx_get_supported_renderers(uint8_t _max, bgfx_renderer_type_t* _enum) +{ + return bgfx::getSupportedRenderers(_max, (bgfx::RendererType::Enum*)_enum); +} + +BGFX_C_API const char* bgfx_get_renderer_name(bgfx_renderer_type_t _type) +{ + return bgfx::getRendererName((bgfx::RendererType::Enum)_type); +} + +/* BGFX_C_API void bgfx_init_ctor(bgfx_init_t* _init) */ + +/* BGFX_C_API bool bgfx_init(const bgfx_init_t * _init) */ + +BGFX_C_API void bgfx_shutdown(void) +{ + bgfx::shutdown(); +} + +BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags, bgfx_texture_format_t _format) +{ + bgfx::reset(_width, _height, _flags, (bgfx::TextureFormat::Enum)_format); +} + +BGFX_C_API uint32_t bgfx_frame(bool _capture) +{ + return bgfx::frame(_capture); +} + +BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type(void) +{ + return (bgfx_renderer_type_t)bgfx::getRendererType(); +} + +BGFX_C_API const bgfx_caps_t* bgfx_get_caps(void) +{ + return (const bgfx_caps_t*)bgfx::getCaps(); +} + +BGFX_C_API const bgfx_stats_t* bgfx_get_stats(void) +{ + return (const bgfx_stats_t*)bgfx::getStats(); +} + +BGFX_C_API const bgfx_memory_t* bgfx_alloc(uint32_t _size) +{ + return (const bgfx_memory_t*)bgfx::alloc(_size); +} + +BGFX_C_API const bgfx_memory_t* bgfx_copy(const void* _data, uint32_t _size) +{ + return (const bgfx_memory_t*)bgfx::copy(_data, _size); +} + +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, (bgfx::ReleaseFn)_releaseFn, _userData); +} + +BGFX_C_API void bgfx_set_debug(uint32_t _debug) +{ + bgfx::setDebug(_debug); +} + +BGFX_C_API void bgfx_dbg_text_clear(uint8_t _attr, bool _small) +{ + bgfx::dbgTextClear(_attr, _small); +} + +BGFX_C_API void bgfx_dbg_text_printf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, ... ) +{ + va_list argList; + va_start(argList, _format); + bgfx::dbgTextPrintfVargs(_x, _y, _attr, _format, argList); + va_end(argList); +} + +BGFX_C_API void bgfx_dbg_text_vprintf(uint16_t _x, uint16_t _y, uint8_t _attr, const char* _format, va_list _argList) +{ + bgfx::dbgTextPrintfVargs(_x, _y, _attr, _format, _argList); +} + +BGFX_C_API void bgfx_dbg_text_image(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const void* _data, uint16_t _pitch) +{ + bgfx::dbgTextImage(_x, _y, _width, _height, _data, _pitch); +} + +BGFX_C_API bgfx_index_buffer_handle_t bgfx_create_index_buffer(const bgfx_memory_t* _mem, uint16_t _flags) +{ + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createIndexBuffer((const bgfx::Memory*)_mem, _flags); + return handle_ret.c; +} + +BGFX_C_API void bgfx_set_index_buffer_name(bgfx_index_buffer_handle_t _handle, const char* _name, int32_t _len) +{ + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + bgfx::setName(handle.cpp, _name, _len); +} + +BGFX_C_API void bgfx_destroy_index_buffer(bgfx_index_buffer_handle_t _handle) +{ + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_vertex_layout_handle_t bgfx_create_vertex_layout(const bgfx_vertex_layout_t * _layout) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createVertexLayout(layout); + return handle_ret.c; +} + +BGFX_C_API void bgfx_destroy_vertex_layout(bgfx_vertex_layout_handle_t _layoutHandle) +{ + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } layoutHandle = { _layoutHandle }; + bgfx::destroy(layoutHandle.cpp); +} + +BGFX_C_API bgfx_vertex_buffer_handle_t bgfx_create_vertex_buffer(const bgfx_memory_t* _mem, const bgfx_vertex_layout_t * _layout, uint16_t _flags) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createVertexBuffer((const bgfx::Memory*)_mem, layout, _flags); + return handle_ret.c; +} + +BGFX_C_API void bgfx_set_vertex_buffer_name(bgfx_vertex_buffer_handle_t _handle, const char* _name, int32_t _len) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setName(handle.cpp, _name, _len); +} + +BGFX_C_API void bgfx_destroy_vertex_buffer(bgfx_vertex_buffer_handle_t _handle) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer(uint32_t _num, uint16_t _flags) +{ + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createDynamicIndexBuffer(_num, _flags); + return handle_ret.c; +} + +BGFX_C_API bgfx_dynamic_index_buffer_handle_t bgfx_create_dynamic_index_buffer_mem(const bgfx_memory_t* _mem, uint16_t _flags) +{ + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createDynamicIndexBuffer((const bgfx::Memory*)_mem, _flags); + return handle_ret.c; +} + +BGFX_C_API void bgfx_update_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _startIndex, const bgfx_memory_t* _mem) +{ + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + bgfx::update(handle.cpp, _startIndex, (const bgfx::Memory*)_mem); +} + +BGFX_C_API void bgfx_destroy_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle) +{ + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer(uint32_t _num, const bgfx_vertex_layout_t* _layout, uint16_t _flags) +{ + const bgfx::VertexLayout& layout = *(const bgfx::VertexLayout*)_layout; + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createDynamicVertexBuffer(_num, layout, _flags); + return handle_ret.c; +} + +BGFX_C_API bgfx_dynamic_vertex_buffer_handle_t bgfx_create_dynamic_vertex_buffer_mem(const bgfx_memory_t* _mem, const bgfx_vertex_layout_t* _layout, uint16_t _flags) +{ + const bgfx::VertexLayout& layout = *(const bgfx::VertexLayout*)_layout; + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createDynamicVertexBuffer((const bgfx::Memory*)_mem, layout, _flags); + return handle_ret.c; +} + +BGFX_C_API void bgfx_update_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, const bgfx_memory_t* _mem) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::update(handle.cpp, _startVertex, (const bgfx::Memory*)_mem); +} + +BGFX_C_API void bgfx_destroy_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API uint32_t bgfx_get_avail_transient_index_buffer(uint32_t _num, bool _index32) +{ + return bgfx::getAvailTransientIndexBuffer(_num, _index32); +} + +BGFX_C_API uint32_t bgfx_get_avail_transient_vertex_buffer(uint32_t _num, const bgfx_vertex_layout_t * _layout) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + return bgfx::getAvailTransientVertexBuffer(_num, layout); +} + +BGFX_C_API uint32_t bgfx_get_avail_instance_data_buffer(uint32_t _num, uint16_t _stride) +{ + return bgfx::getAvailInstanceDataBuffer(_num, _stride); +} + +BGFX_C_API void bgfx_alloc_transient_index_buffer(bgfx_transient_index_buffer_t* _tib, uint32_t _num, bool _index32) +{ + bgfx::allocTransientIndexBuffer((bgfx::TransientIndexBuffer*)_tib, _num, _index32); +} + +BGFX_C_API void bgfx_alloc_transient_vertex_buffer(bgfx_transient_vertex_buffer_t* _tvb, uint32_t _num, const bgfx_vertex_layout_t * _layout) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + bgfx::allocTransientVertexBuffer((bgfx::TransientVertexBuffer*)_tvb, _num, layout); +} + +BGFX_C_API bool bgfx_alloc_transient_buffers(bgfx_transient_vertex_buffer_t* _tvb, const bgfx_vertex_layout_t * _layout, uint32_t _numVertices, bgfx_transient_index_buffer_t* _tib, uint32_t _numIndices, bool _index32) +{ + const bgfx::VertexLayout & layout = *(const bgfx::VertexLayout *)_layout; + return bgfx::allocTransientBuffers((bgfx::TransientVertexBuffer*)_tvb, layout, _numVertices, (bgfx::TransientIndexBuffer*)_tib, _numIndices, _index32); +} + +BGFX_C_API void bgfx_alloc_instance_data_buffer(bgfx_instance_data_buffer_t* _idb, uint32_t _num, uint16_t _stride) +{ + bgfx::allocInstanceDataBuffer((bgfx::InstanceDataBuffer*)_idb, _num, _stride); +} + +BGFX_C_API bgfx_indirect_buffer_handle_t bgfx_create_indirect_buffer(uint32_t _num) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createIndirectBuffer(_num); + return handle_ret.c; +} + +BGFX_C_API void bgfx_destroy_indirect_buffer(bgfx_indirect_buffer_handle_t _handle) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_shader_handle_t bgfx_create_shader(const bgfx_memory_t* _mem) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createShader((const bgfx::Memory*)_mem); + return handle_ret.c; +} + +BGFX_C_API uint16_t bgfx_get_shader_uniforms(bgfx_shader_handle_t _handle, bgfx_uniform_handle_t* _uniforms, uint16_t _max) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; + return bgfx::getShaderUniforms(handle.cpp, (bgfx::UniformHandle*)_uniforms, _max); +} + +BGFX_C_API void bgfx_set_shader_name(bgfx_shader_handle_t _handle, const char* _name, int32_t _len) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; + bgfx::setName(handle.cpp, _name, _len); +} + +BGFX_C_API void bgfx_destroy_shader(bgfx_shader_handle_t _handle) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_program_handle_t bgfx_create_program(bgfx_shader_handle_t _vsh, bgfx_shader_handle_t _fsh, bool _destroyShaders) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } vsh = { _vsh }; + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } fsh = { _fsh }; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createProgram(vsh.cpp, fsh.cpp, _destroyShaders); + return handle_ret.c; +} + +BGFX_C_API bgfx_program_handle_t bgfx_create_compute_program(bgfx_shader_handle_t _csh, bool _destroyShaders) +{ + union { bgfx_shader_handle_t c; bgfx::ShaderHandle cpp; } csh = { _csh }; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createProgram(csh.cpp, _destroyShaders); + return handle_ret.c; +} + +BGFX_C_API void bgfx_destroy_program(bgfx_program_handle_t _handle) +{ + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bool bgfx_is_texture_valid(uint16_t _depth, bool _cubeMap, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags) +{ + return bgfx::isTextureValid(_depth, _cubeMap, _numLayers, (bgfx::TextureFormat::Enum)_format, _flags); +} + +BGFX_C_API bool bgfx_is_frame_buffer_valid(uint8_t _num, const bgfx_attachment_t* _attachment) +{ + return bgfx::isFrameBufferValid(_num, (const bgfx::Attachment*)_attachment); +} + +BGFX_C_API void bgfx_calc_texture_size(bgfx_texture_info_t * _info, uint16_t _width, uint16_t _height, uint16_t _depth, bool _cubeMap, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format) +{ + bgfx::TextureInfo & info = *(bgfx::TextureInfo *)_info; + bgfx::calcTextureSize(info, _width, _height, _depth, _cubeMap, _hasMips, _numLayers, (bgfx::TextureFormat::Enum)_format); +} + +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture(const bgfx_memory_t* _mem, uint64_t _flags, uint8_t _skip, bgfx_texture_info_t* _info) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createTexture((const bgfx::Memory*)_mem, _flags, _skip, (bgfx::TextureInfo*)_info); + return handle_ret.c; +} + +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d(uint16_t _width, uint16_t _height, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createTexture2D(_width, _height, _hasMips, _numLayers, (bgfx::TextureFormat::Enum)_format, _flags, (const bgfx::Memory*)_mem); + return handle_ret.c; +} + +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_2d_scaled(bgfx_backbuffer_ratio_t _ratio, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createTexture2D((bgfx::BackbufferRatio::Enum)_ratio, _hasMips, _numLayers, (bgfx::TextureFormat::Enum)_format, _flags); + return handle_ret.c; +} + +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_3d(uint16_t _width, uint16_t _height, uint16_t _depth, bool _hasMips, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createTexture3D(_width, _height, _depth, _hasMips, (bgfx::TextureFormat::Enum)_format, _flags, (const bgfx::Memory*)_mem); + return handle_ret.c; +} + +BGFX_C_API bgfx_texture_handle_t bgfx_create_texture_cube(uint16_t _size, bool _hasMips, uint16_t _numLayers, bgfx_texture_format_t _format, uint64_t _flags, const bgfx_memory_t* _mem) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createTextureCube(_size, _hasMips, _numLayers, (bgfx::TextureFormat::Enum)_format, _flags, (const bgfx::Memory*)_mem); + return handle_ret.c; +} + +BGFX_C_API void bgfx_update_texture_2d(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::updateTexture2D(handle.cpp, _layer, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); +} + +BGFX_C_API void bgfx_update_texture_3d(bgfx_texture_handle_t _handle, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _z, uint16_t _width, uint16_t _height, uint16_t _depth, const bgfx_memory_t* _mem) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::updateTexture3D(handle.cpp, _mip, _x, _y, _z, _width, _height, _depth, (const bgfx::Memory*)_mem); +} + +BGFX_C_API void bgfx_update_texture_cube(bgfx_texture_handle_t _handle, uint16_t _layer, uint8_t _side, uint8_t _mip, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height, const bgfx_memory_t* _mem, uint16_t _pitch) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::updateTextureCube(handle.cpp, _layer, _side, _mip, _x, _y, _width, _height, (const bgfx::Memory*)_mem, _pitch); +} + +BGFX_C_API uint32_t bgfx_read_texture(bgfx_texture_handle_t _handle, void* _data, uint8_t _mip) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + return bgfx::readTexture(handle.cpp, _data, _mip); +} + +BGFX_C_API void bgfx_set_texture_name(bgfx_texture_handle_t _handle, const char* _name, int32_t _len) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::setName(handle.cpp, _name, _len); +} + +BGFX_C_API void* bgfx_get_direct_access_ptr(bgfx_texture_handle_t _handle) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + return bgfx::getDirectAccessPtr(handle.cpp); +} + +BGFX_C_API void bgfx_destroy_texture(bgfx_texture_handle_t _handle) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer(uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, uint64_t _textureFlags) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createFrameBuffer(_width, _height, (bgfx::TextureFormat::Enum)_format, _textureFlags); + return handle_ret.c; +} + +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_scaled(bgfx_backbuffer_ratio_t _ratio, bgfx_texture_format_t _format, uint64_t _textureFlags) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createFrameBuffer((bgfx::BackbufferRatio::Enum)_ratio, (bgfx::TextureFormat::Enum)_format, _textureFlags); + return handle_ret.c; +} + +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_handles(uint8_t _num, const bgfx_texture_handle_t* _handles, bool _destroyTexture) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createFrameBuffer(_num, (const bgfx::TextureHandle*)_handles, _destroyTexture); + return handle_ret.c; +} + +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_attachment(uint8_t _num, const bgfx_attachment_t* _attachment, bool _destroyTexture) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createFrameBuffer(_num, (const bgfx::Attachment*)_attachment, _destroyTexture); + return handle_ret.c; +} + +BGFX_C_API bgfx_frame_buffer_handle_t bgfx_create_frame_buffer_from_nwh(void* _nwh, uint16_t _width, uint16_t _height, bgfx_texture_format_t _format, bgfx_texture_format_t _depthFormat) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createFrameBuffer(_nwh, _width, _height, (bgfx::TextureFormat::Enum)_format, (bgfx::TextureFormat::Enum)_depthFormat); + return handle_ret.c; +} + +BGFX_C_API void bgfx_set_frame_buffer_name(bgfx_frame_buffer_handle_t _handle, const char* _name, int32_t _len) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; + bgfx::setName(handle.cpp, _name, _len); +} + +BGFX_C_API bgfx_texture_handle_t bgfx_get_texture(bgfx_frame_buffer_handle_t _handle, uint8_t _attachment) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::getTexture(handle.cpp, _attachment); + return handle_ret.c; +} + +BGFX_C_API void bgfx_destroy_frame_buffer(bgfx_frame_buffer_handle_t _handle) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_uniform_handle_t bgfx_create_uniform(const char* _name, bgfx_uniform_type_t _type, uint16_t _num) +{ + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createUniform(_name, (bgfx::UniformType::Enum)_type, _num); + return handle_ret.c; +} + +BGFX_C_API void bgfx_get_uniform_info(bgfx_uniform_handle_t _handle, bgfx_uniform_info_t * _info) +{ + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; + bgfx::UniformInfo & info = *(bgfx::UniformInfo *)_info; + bgfx::getUniformInfo(handle.cpp, info); +} + +BGFX_C_API void bgfx_destroy_uniform(bgfx_uniform_handle_t _handle) +{ + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API bgfx_occlusion_query_handle_t bgfx_create_occlusion_query(void) +{ + union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle_ret; + handle_ret.cpp = bgfx::createOcclusionQuery(); + return handle_ret.c; +} + +BGFX_C_API bgfx_occlusion_query_result_t bgfx_get_result(bgfx_occlusion_query_handle_t _handle, int32_t* _result) +{ + union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; + return (bgfx_occlusion_query_result_t)bgfx::getResult(handle.cpp, _result); +} + +BGFX_C_API void bgfx_destroy_occlusion_query(bgfx_occlusion_query_handle_t _handle) +{ + union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; + bgfx::destroy(handle.cpp); +} + +BGFX_C_API void bgfx_set_palette_color(uint8_t _index, const float _rgba[4]) +{ + bgfx::setPaletteColor(_index, _rgba); +} + +BGFX_C_API void bgfx_set_palette_color_rgba8(uint8_t _index, uint32_t _rgba) +{ + bgfx::setPaletteColor(_index, _rgba); +} + +BGFX_C_API void bgfx_set_view_name(bgfx_view_id_t _id, const char* _name) +{ + bgfx::setViewName((bgfx::ViewId)_id, _name); +} + +BGFX_C_API void bgfx_set_view_rect(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) +{ + bgfx::setViewRect((bgfx::ViewId)_id, _x, _y, _width, _height); +} + +BGFX_C_API void bgfx_set_view_rect_ratio(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, bgfx_backbuffer_ratio_t _ratio) +{ + bgfx::setViewRect((bgfx::ViewId)_id, _x, _y, (bgfx::BackbufferRatio::Enum)_ratio); +} + +BGFX_C_API void bgfx_set_view_scissor(bgfx_view_id_t _id, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) +{ + bgfx::setViewScissor((bgfx::ViewId)_id, _x, _y, _width, _height); +} + +BGFX_C_API void bgfx_set_view_clear(bgfx_view_id_t _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) +{ + bgfx::setViewClear((bgfx::ViewId)_id, _flags, _rgba, _depth, _stencil); +} + +BGFX_C_API void bgfx_set_view_clear_mrt(bgfx_view_id_t _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _c0, uint8_t _c1, uint8_t _c2, uint8_t _c3, uint8_t _c4, uint8_t _c5, uint8_t _c6, uint8_t _c7) +{ + bgfx::setViewClear((bgfx::ViewId)_id, _flags, _depth, _stencil, _c0, _c1, _c2, _c3, _c4, _c5, _c6, _c7); +} + +BGFX_C_API void bgfx_set_view_mode(bgfx_view_id_t _id, bgfx_view_mode_t _mode) +{ + bgfx::setViewMode((bgfx::ViewId)_id, (bgfx::ViewMode::Enum)_mode); +} + +BGFX_C_API void bgfx_set_view_frame_buffer(bgfx_view_id_t _id, bgfx_frame_buffer_handle_t _handle) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; + bgfx::setViewFrameBuffer((bgfx::ViewId)_id, handle.cpp); +} + +BGFX_C_API void bgfx_set_view_transform(bgfx_view_id_t _id, const void* _view, const void* _proj) +{ + bgfx::setViewTransform((bgfx::ViewId)_id, _view, _proj); +} + +BGFX_C_API void bgfx_set_view_order(bgfx_view_id_t _id, uint16_t _num, const bgfx_view_id_t* _order) +{ + bgfx::setViewOrder((bgfx::ViewId)_id, _num, (const bgfx::ViewId*)_order); +} + +BGFX_C_API void bgfx_reset_view(bgfx_view_id_t _id) +{ + bgfx::resetView((bgfx::ViewId)_id); +} + +BGFX_C_API bgfx_encoder_t* bgfx_encoder_begin(bool _forThread) +{ + return (bgfx_encoder_t*)bgfx::begin(_forThread); +} + +BGFX_C_API void bgfx_encoder_end(bgfx_encoder_t* _encoder) +{ + bgfx::end((bgfx::Encoder*)_encoder); +} + +BGFX_C_API void bgfx_encoder_set_marker(bgfx_encoder_t* _this, const char* _marker) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setMarker(_marker); +} + +BGFX_C_API void bgfx_encoder_set_state(bgfx_encoder_t* _this, uint64_t _state, uint32_t _rgba) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setState(_state, _rgba); +} + +BGFX_C_API void bgfx_encoder_set_condition(bgfx_encoder_t* _this, bgfx_occlusion_query_handle_t _handle, bool _visible) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; + This->setCondition(handle.cpp, _visible); +} + +BGFX_C_API void bgfx_encoder_set_stencil(bgfx_encoder_t* _this, uint32_t _fstencil, uint32_t _bstencil) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setStencil(_fstencil, _bstencil); +} + +BGFX_C_API uint16_t bgfx_encoder_set_scissor(bgfx_encoder_t* _this, uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + return This->setScissor(_x, _y, _width, _height); +} + +BGFX_C_API void bgfx_encoder_set_scissor_cached(bgfx_encoder_t* _this, uint16_t _cache) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setScissor(_cache); +} + +BGFX_C_API uint32_t bgfx_encoder_set_transform(bgfx_encoder_t* _this, const void* _mtx, uint16_t _num) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + return This->setTransform(_mtx, _num); +} + +BGFX_C_API void bgfx_encoder_set_transform_cached(bgfx_encoder_t* _this, uint32_t _cache, uint16_t _num) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setTransform(_cache, _num); +} + +BGFX_C_API uint32_t bgfx_encoder_alloc_transform(bgfx_encoder_t* _this, bgfx_transform_t* _transform, uint16_t _num) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + return This->allocTransform((bgfx::Transform*)_transform, _num); +} + +BGFX_C_API void bgfx_encoder_set_uniform(bgfx_encoder_t* _this, bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; + This->setUniform(handle.cpp, _value, _num); +} + +BGFX_C_API void bgfx_encoder_set_index_buffer(bgfx_encoder_t* _this, bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + This->setIndexBuffer(handle.cpp, _firstIndex, _numIndices); +} + +BGFX_C_API void bgfx_encoder_set_dynamic_index_buffer(bgfx_encoder_t* _this, bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + This->setIndexBuffer(handle.cpp, _firstIndex, _numIndices); +} + +BGFX_C_API void bgfx_encoder_set_transient_index_buffer(bgfx_encoder_t* _this, const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setIndexBuffer((const bgfx::TransientIndexBuffer*)_tib, _firstIndex, _numIndices); +} + +BGFX_C_API void bgfx_encoder_set_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + This->setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices); +} + +BGFX_C_API void bgfx_encoder_set_vertex_buffer_with_layout(bgfx_encoder_t* _this, uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } layoutHandle = { _layoutHandle }; + This->setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices, layoutHandle.cpp); +} + +BGFX_C_API void bgfx_encoder_set_dynamic_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + This->setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices); +} + +BGFX_C_API void bgfx_encoder_set_dynamic_vertex_buffer_with_layout(bgfx_encoder_t* _this, uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } layoutHandle = { _layoutHandle }; + This->setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices, layoutHandle.cpp); +} + +BGFX_C_API void bgfx_encoder_set_transient_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setVertexBuffer(_stream, (const bgfx::TransientVertexBuffer*)_tvb, _startVertex, _numVertices); +} + +BGFX_C_API void bgfx_encoder_set_transient_vertex_buffer_with_layout(bgfx_encoder_t* _this, uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } layoutHandle = { _layoutHandle }; + This->setVertexBuffer(_stream, (const bgfx::TransientVertexBuffer*)_tvb, _startVertex, _numVertices, layoutHandle.cpp); +} + +BGFX_C_API void bgfx_encoder_set_vertex_count(bgfx_encoder_t* _this, uint32_t _numVertices) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setVertexCount(_numVertices); +} + +BGFX_C_API void bgfx_encoder_set_instance_data_buffer(bgfx_encoder_t* _this, const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setInstanceDataBuffer((const bgfx::InstanceDataBuffer*)_idb, _start, _num); +} + +BGFX_C_API void bgfx_encoder_set_instance_data_from_vertex_buffer(bgfx_encoder_t* _this, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + This->setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + +BGFX_C_API void bgfx_encoder_set_instance_data_from_dynamic_vertex_buffer(bgfx_encoder_t* _this, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + This->setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + +BGFX_C_API void bgfx_encoder_set_instance_count(bgfx_encoder_t* _this, uint32_t _numInstances) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->setInstanceCount(_numInstances); +} + +BGFX_C_API void bgfx_encoder_set_texture(bgfx_encoder_t* _this, uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + This->setTexture(_stage, sampler.cpp, handle.cpp, _flags); +} + +BGFX_C_API void bgfx_encoder_touch(bgfx_encoder_t* _this, bgfx_view_id_t _id) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->touch((bgfx::ViewId)_id); +} + +BGFX_C_API void bgfx_encoder_submit(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + This->submit((bgfx::ViewId)_id, program.cpp, _depth, _flags); +} + +BGFX_C_API void bgfx_encoder_submit_occlusion_query(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } occlusionQuery = { _occlusionQuery }; + This->submit((bgfx::ViewId)_id, program.cpp, occlusionQuery.cpp, _depth, _flags); +} + +BGFX_C_API void bgfx_encoder_submit_indirect(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + This->submit((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, _num, _depth, _flags); +} + +BGFX_C_API void bgfx_encoder_submit_indirect_count(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, bgfx_index_buffer_handle_t _numHandle, uint32_t _numIndex, uint16_t _numMax, uint32_t _depth, uint8_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } numHandle = { _numHandle }; + This->submit((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, numHandle.cpp, _numIndex, _numMax, _depth, _flags); +} + +BGFX_C_API void bgfx_encoder_set_compute_index_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + This->setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_encoder_set_compute_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + This->setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_encoder_set_compute_dynamic_index_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + This->setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_encoder_set_compute_dynamic_vertex_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + This->setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_encoder_set_compute_indirect_buffer(bgfx_encoder_t* _this, uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; + This->setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_encoder_set_image(bgfx_encoder_t* _this, uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + This->setImage(_stage, handle.cpp, _mip, (bgfx::Access::Enum)_access, (bgfx::TextureFormat::Enum)_format); +} + +BGFX_C_API void bgfx_encoder_dispatch(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + This->dispatch((bgfx::ViewId)_id, program.cpp, _numX, _numY, _numZ, _flags); +} + +BGFX_C_API void bgfx_encoder_dispatch_indirect(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + This->dispatch((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, _num, _flags); +} + +BGFX_C_API void bgfx_encoder_discard(bgfx_encoder_t* _this, uint8_t _flags) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + This->discard(_flags); +} + +BGFX_C_API void bgfx_encoder_blit(bgfx_encoder_t* _this, bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) +{ + bgfx::Encoder* This = (bgfx::Encoder*)_this; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } dst = { _dst }; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } src = { _src }; + This->blit((bgfx::ViewId)_id, dst.cpp, _dstMip, _dstX, _dstY, _dstZ, src.cpp, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); +} + +BGFX_C_API void bgfx_request_screen_shot(bgfx_frame_buffer_handle_t _handle, const char* _filePath) +{ + union { bgfx_frame_buffer_handle_t c; bgfx::FrameBufferHandle cpp; } handle = { _handle }; + bgfx::requestScreenShot(handle.cpp, _filePath); +} + +BGFX_C_API bgfx_render_frame_t bgfx_render_frame(int32_t _msecs) +{ + return (bgfx_render_frame_t)bgfx::renderFrame(_msecs); +} + +BGFX_C_API void bgfx_set_platform_data(const bgfx_platform_data_t * _data) +{ + const bgfx::PlatformData & data = *(const bgfx::PlatformData *)_data; + bgfx::setPlatformData(data); +} + +BGFX_C_API const bgfx_internal_data_t* bgfx_get_internal_data(void) +{ + return (const bgfx_internal_data_t*)bgfx::getInternalData(); +} + +BGFX_C_API uintptr_t bgfx_override_internal_texture_ptr(bgfx_texture_handle_t _handle, uintptr_t _ptr) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + return bgfx::overrideInternal(handle.cpp, _ptr); +} + +BGFX_C_API uintptr_t bgfx_override_internal_texture(bgfx_texture_handle_t _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, bgfx_texture_format_t _format, uint64_t _flags) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + return bgfx::overrideInternal(handle.cpp, _width, _height, _numMips, (bgfx::TextureFormat::Enum)_format, _flags); +} + +BGFX_C_API void bgfx_set_marker(const char* _marker) +{ + bgfx::setMarker(_marker); +} + +BGFX_C_API void bgfx_set_state(uint64_t _state, uint32_t _rgba) +{ + bgfx::setState(_state, _rgba); +} + +BGFX_C_API void bgfx_set_condition(bgfx_occlusion_query_handle_t _handle, bool _visible) +{ + union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } handle = { _handle }; + bgfx::setCondition(handle.cpp, _visible); +} + +BGFX_C_API void bgfx_set_stencil(uint32_t _fstencil, uint32_t _bstencil) +{ + bgfx::setStencil(_fstencil, _bstencil); +} + +BGFX_C_API uint16_t bgfx_set_scissor(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) +{ + return bgfx::setScissor(_x, _y, _width, _height); +} + +BGFX_C_API void bgfx_set_scissor_cached(uint16_t _cache) +{ + bgfx::setScissor(_cache); +} + +BGFX_C_API uint32_t bgfx_set_transform(const void* _mtx, uint16_t _num) +{ + return bgfx::setTransform(_mtx, _num); +} + +BGFX_C_API void bgfx_set_transform_cached(uint32_t _cache, uint16_t _num) +{ + bgfx::setTransform(_cache, _num); +} + +BGFX_C_API uint32_t bgfx_alloc_transform(bgfx_transform_t* _transform, uint16_t _num) +{ + return bgfx::allocTransform((bgfx::Transform*)_transform, _num); +} + +BGFX_C_API void bgfx_set_uniform(bgfx_uniform_handle_t _handle, const void* _value, uint16_t _num) +{ + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } handle = { _handle }; + bgfx::setUniform(handle.cpp, _value, _num); +} + +BGFX_C_API void bgfx_set_index_buffer(bgfx_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) +{ + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + bgfx::setIndexBuffer(handle.cpp, _firstIndex, _numIndices); +} + +BGFX_C_API void bgfx_set_dynamic_index_buffer(bgfx_dynamic_index_buffer_handle_t _handle, uint32_t _firstIndex, uint32_t _numIndices) +{ + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + bgfx::setIndexBuffer(handle.cpp, _firstIndex, _numIndices); +} + +BGFX_C_API void bgfx_set_transient_index_buffer(const bgfx_transient_index_buffer_t* _tib, uint32_t _firstIndex, uint32_t _numIndices) +{ + bgfx::setIndexBuffer((const bgfx::TransientIndexBuffer*)_tib, _firstIndex, _numIndices); +} + +BGFX_C_API void bgfx_set_vertex_buffer(uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices); +} + +BGFX_C_API void bgfx_set_vertex_buffer_with_layout(uint8_t _stream, bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } layoutHandle = { _layoutHandle }; + bgfx::setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices, layoutHandle.cpp); +} + +BGFX_C_API void bgfx_set_dynamic_vertex_buffer(uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices); +} + +BGFX_C_API void bgfx_set_dynamic_vertex_buffer_with_layout(uint8_t _stream, bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } layoutHandle = { _layoutHandle }; + bgfx::setVertexBuffer(_stream, handle.cpp, _startVertex, _numVertices, layoutHandle.cpp); +} + +BGFX_C_API void bgfx_set_transient_vertex_buffer(uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices) +{ + bgfx::setVertexBuffer(_stream, (const bgfx::TransientVertexBuffer*)_tvb, _startVertex, _numVertices); +} + +BGFX_C_API void bgfx_set_transient_vertex_buffer_with_layout(uint8_t _stream, const bgfx_transient_vertex_buffer_t* _tvb, uint32_t _startVertex, uint32_t _numVertices, bgfx_vertex_layout_handle_t _layoutHandle) +{ + union { bgfx_vertex_layout_handle_t c; bgfx::VertexLayoutHandle cpp; } layoutHandle = { _layoutHandle }; + bgfx::setVertexBuffer(_stream, (const bgfx::TransientVertexBuffer*)_tvb, _startVertex, _numVertices, layoutHandle.cpp); +} + +BGFX_C_API void bgfx_set_vertex_count(uint32_t _numVertices) +{ + bgfx::setVertexCount(_numVertices); +} + +BGFX_C_API void bgfx_set_instance_data_buffer(const bgfx_instance_data_buffer_t* _idb, uint32_t _start, uint32_t _num) +{ + bgfx::setInstanceDataBuffer((const bgfx::InstanceDataBuffer*)_idb, _start, _num); +} + +BGFX_C_API void bgfx_set_instance_data_from_vertex_buffer(bgfx_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + +BGFX_C_API void bgfx_set_instance_data_from_dynamic_vertex_buffer(bgfx_dynamic_vertex_buffer_handle_t _handle, uint32_t _startVertex, uint32_t _num) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::setInstanceDataBuffer(handle.cpp, _startVertex, _num); +} + +BGFX_C_API void bgfx_set_instance_count(uint32_t _numInstances) +{ + bgfx::setInstanceCount(_numInstances); +} + +BGFX_C_API void bgfx_set_texture(uint8_t _stage, bgfx_uniform_handle_t _sampler, bgfx_texture_handle_t _handle, uint32_t _flags) +{ + union { bgfx_uniform_handle_t c; bgfx::UniformHandle cpp; } sampler = { _sampler }; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::setTexture(_stage, sampler.cpp, handle.cpp, _flags); +} + +BGFX_C_API void bgfx_touch(bgfx_view_id_t _id) +{ + bgfx::touch((bgfx::ViewId)_id); +} + +BGFX_C_API void bgfx_submit(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _depth, uint8_t _flags) +{ + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + bgfx::submit((bgfx::ViewId)_id, program.cpp, _depth, _flags); +} + +BGFX_C_API void bgfx_submit_occlusion_query(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_occlusion_query_handle_t _occlusionQuery, uint32_t _depth, uint8_t _flags) +{ + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_occlusion_query_handle_t c; bgfx::OcclusionQueryHandle cpp; } occlusionQuery = { _occlusionQuery }; + bgfx::submit((bgfx::ViewId)_id, program.cpp, occlusionQuery.cpp, _depth, _flags); +} + +BGFX_C_API void bgfx_submit_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags) +{ + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + bgfx::submit((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, _num, _depth, _flags); +} + +BGFX_C_API void bgfx_submit_indirect_count(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, bgfx_index_buffer_handle_t _numHandle, uint32_t _numIndex, uint16_t _numMax, uint32_t _depth, uint8_t _flags) +{ + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } numHandle = { _numHandle }; + bgfx::submit((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, numHandle.cpp, _numIndex, _numMax, _depth, _flags); +} + +BGFX_C_API void bgfx_set_compute_index_buffer(uint8_t _stage, bgfx_index_buffer_handle_t _handle, bgfx_access_t _access) +{ + union { bgfx_index_buffer_handle_t c; bgfx::IndexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_set_compute_vertex_buffer(uint8_t _stage, bgfx_vertex_buffer_handle_t _handle, bgfx_access_t _access) +{ + union { bgfx_vertex_buffer_handle_t c; bgfx::VertexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_set_compute_dynamic_index_buffer(uint8_t _stage, bgfx_dynamic_index_buffer_handle_t _handle, bgfx_access_t _access) +{ + union { bgfx_dynamic_index_buffer_handle_t c; bgfx::DynamicIndexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_set_compute_dynamic_vertex_buffer(uint8_t _stage, bgfx_dynamic_vertex_buffer_handle_t _handle, bgfx_access_t _access) +{ + union { bgfx_dynamic_vertex_buffer_handle_t c; bgfx::DynamicVertexBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_set_compute_indirect_buffer(uint8_t _stage, bgfx_indirect_buffer_handle_t _handle, bgfx_access_t _access) +{ + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } handle = { _handle }; + bgfx::setBuffer(_stage, handle.cpp, (bgfx::Access::Enum)_access); +} + +BGFX_C_API void bgfx_set_image(uint8_t _stage, bgfx_texture_handle_t _handle, uint8_t _mip, bgfx_access_t _access, bgfx_texture_format_t _format) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } handle = { _handle }; + bgfx::setImage(_stage, handle.cpp, _mip, (bgfx::Access::Enum)_access, (bgfx::TextureFormat::Enum)_format); +} + +BGFX_C_API void bgfx_dispatch(bgfx_view_id_t _id, bgfx_program_handle_t _program, uint32_t _numX, uint32_t _numY, uint32_t _numZ, uint8_t _flags) +{ + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + bgfx::dispatch((bgfx::ViewId)_id, program.cpp, _numX, _numY, _numZ, _flags); +} + +BGFX_C_API void bgfx_dispatch_indirect(bgfx_view_id_t _id, bgfx_program_handle_t _program, bgfx_indirect_buffer_handle_t _indirectHandle, uint16_t _start, uint16_t _num, uint8_t _flags) +{ + union { bgfx_program_handle_t c; bgfx::ProgramHandle cpp; } program = { _program }; + union { bgfx_indirect_buffer_handle_t c; bgfx::IndirectBufferHandle cpp; } indirectHandle = { _indirectHandle }; + bgfx::dispatch((bgfx::ViewId)_id, program.cpp, indirectHandle.cpp, _start, _num, _flags); +} + +BGFX_C_API void bgfx_discard(uint8_t _flags) +{ + bgfx::discard(_flags); +} + +BGFX_C_API void bgfx_blit(bgfx_view_id_t _id, bgfx_texture_handle_t _dst, uint8_t _dstMip, uint16_t _dstX, uint16_t _dstY, uint16_t _dstZ, bgfx_texture_handle_t _src, uint8_t _srcMip, uint16_t _srcX, uint16_t _srcY, uint16_t _srcZ, uint16_t _width, uint16_t _height, uint16_t _depth) +{ + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } dst = { _dst }; + union { bgfx_texture_handle_t c; bgfx::TextureHandle cpp; } src = { _src }; + bgfx::blit((bgfx::ViewId)_id, dst.cpp, _dstMip, _dstX, _dstY, _dstZ, src.cpp, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth); +} + + +/* user define functions */ +BGFX_C_API void bgfx_init_ctor(bgfx_init_t* _init) +{ + BX_PLACEMENT_NEW(_init, bgfx::Init); + +} + +BGFX_C_API bool bgfx_init(const bgfx_init_t * _init) +{ + bgfx_init_t init =*_init; + + if (init.callback != NULL) + { + static bgfx::CallbackC99 s_callback; + s_callback.m_interface = init.callback; + init.callback = reinterpret_cast<bgfx_callback_interface_t*>(&s_callback); + } + + if (init.allocator != NULL) + { + static bgfx::AllocatorC99 s_allocator; + s_allocator.m_interface = init.allocator; + init.allocator = reinterpret_cast<bgfx_allocator_interface_t*>(&s_allocator); + } + + union { const bgfx_init_t* c; const bgfx::Init* cpp; } in; + in.c = &init; + + return bgfx::init(*in.cpp); + +} + +/**/ +BGFX_C_API bgfx_interface_vtbl_t* bgfx_get_interface(uint32_t _version) +{ + if (_version == BGFX_API_VERSION) + { + static bgfx_interface_vtbl_t s_bgfx_interface = + { + bgfx_attachment_init, + bgfx_vertex_layout_begin, + bgfx_vertex_layout_add, + bgfx_vertex_layout_decode, + bgfx_vertex_layout_has, + bgfx_vertex_layout_skip, + bgfx_vertex_layout_end, + bgfx_vertex_pack, + bgfx_vertex_unpack, + bgfx_vertex_convert, + bgfx_weld_vertices, + bgfx_topology_convert, + bgfx_topology_sort_tri_list, + bgfx_get_supported_renderers, + bgfx_get_renderer_name, + bgfx_init_ctor, + bgfx_init, + bgfx_shutdown, + bgfx_reset, + bgfx_frame, + bgfx_get_renderer_type, + bgfx_get_caps, + bgfx_get_stats, + bgfx_alloc, + bgfx_copy, + bgfx_make_ref, + bgfx_make_ref_release, + bgfx_set_debug, + bgfx_dbg_text_clear, + bgfx_dbg_text_printf, + bgfx_dbg_text_vprintf, + bgfx_dbg_text_image, + bgfx_create_index_buffer, + bgfx_set_index_buffer_name, + bgfx_destroy_index_buffer, + bgfx_create_vertex_layout, + bgfx_destroy_vertex_layout, + bgfx_create_vertex_buffer, + bgfx_set_vertex_buffer_name, + bgfx_destroy_vertex_buffer, + bgfx_create_dynamic_index_buffer, + bgfx_create_dynamic_index_buffer_mem, + bgfx_update_dynamic_index_buffer, + bgfx_destroy_dynamic_index_buffer, + bgfx_create_dynamic_vertex_buffer, + bgfx_create_dynamic_vertex_buffer_mem, + bgfx_update_dynamic_vertex_buffer, + bgfx_destroy_dynamic_vertex_buffer, + bgfx_get_avail_transient_index_buffer, + bgfx_get_avail_transient_vertex_buffer, + bgfx_get_avail_instance_data_buffer, + bgfx_alloc_transient_index_buffer, + bgfx_alloc_transient_vertex_buffer, + bgfx_alloc_transient_buffers, + bgfx_alloc_instance_data_buffer, + bgfx_create_indirect_buffer, + bgfx_destroy_indirect_buffer, + bgfx_create_shader, + bgfx_get_shader_uniforms, + bgfx_set_shader_name, + bgfx_destroy_shader, + bgfx_create_program, + bgfx_create_compute_program, + bgfx_destroy_program, + bgfx_is_texture_valid, + bgfx_is_frame_buffer_valid, + bgfx_calc_texture_size, + bgfx_create_texture, + bgfx_create_texture_2d, + bgfx_create_texture_2d_scaled, + bgfx_create_texture_3d, + bgfx_create_texture_cube, + bgfx_update_texture_2d, + bgfx_update_texture_3d, + bgfx_update_texture_cube, + bgfx_read_texture, + bgfx_set_texture_name, + bgfx_get_direct_access_ptr, + bgfx_destroy_texture, + bgfx_create_frame_buffer, + bgfx_create_frame_buffer_scaled, + bgfx_create_frame_buffer_from_handles, + bgfx_create_frame_buffer_from_attachment, + bgfx_create_frame_buffer_from_nwh, + bgfx_set_frame_buffer_name, + bgfx_get_texture, + bgfx_destroy_frame_buffer, + bgfx_create_uniform, + bgfx_get_uniform_info, + bgfx_destroy_uniform, + bgfx_create_occlusion_query, + bgfx_get_result, + bgfx_destroy_occlusion_query, + bgfx_set_palette_color, + bgfx_set_palette_color_rgba8, + bgfx_set_view_name, + bgfx_set_view_rect, + bgfx_set_view_rect_ratio, + bgfx_set_view_scissor, + bgfx_set_view_clear, + bgfx_set_view_clear_mrt, + bgfx_set_view_mode, + bgfx_set_view_frame_buffer, + bgfx_set_view_transform, + bgfx_set_view_order, + bgfx_reset_view, + bgfx_encoder_begin, + bgfx_encoder_end, + bgfx_encoder_set_marker, + bgfx_encoder_set_state, + bgfx_encoder_set_condition, + bgfx_encoder_set_stencil, + bgfx_encoder_set_scissor, + bgfx_encoder_set_scissor_cached, + bgfx_encoder_set_transform, + bgfx_encoder_set_transform_cached, + bgfx_encoder_alloc_transform, + bgfx_encoder_set_uniform, + bgfx_encoder_set_index_buffer, + bgfx_encoder_set_dynamic_index_buffer, + bgfx_encoder_set_transient_index_buffer, + bgfx_encoder_set_vertex_buffer, + bgfx_encoder_set_vertex_buffer_with_layout, + bgfx_encoder_set_dynamic_vertex_buffer, + bgfx_encoder_set_dynamic_vertex_buffer_with_layout, + bgfx_encoder_set_transient_vertex_buffer, + bgfx_encoder_set_transient_vertex_buffer_with_layout, + bgfx_encoder_set_vertex_count, + bgfx_encoder_set_instance_data_buffer, + bgfx_encoder_set_instance_data_from_vertex_buffer, + bgfx_encoder_set_instance_data_from_dynamic_vertex_buffer, + bgfx_encoder_set_instance_count, + bgfx_encoder_set_texture, + bgfx_encoder_touch, + bgfx_encoder_submit, + bgfx_encoder_submit_occlusion_query, + bgfx_encoder_submit_indirect, + bgfx_encoder_submit_indirect_count, + bgfx_encoder_set_compute_index_buffer, + bgfx_encoder_set_compute_vertex_buffer, + bgfx_encoder_set_compute_dynamic_index_buffer, + bgfx_encoder_set_compute_dynamic_vertex_buffer, + bgfx_encoder_set_compute_indirect_buffer, + bgfx_encoder_set_image, + bgfx_encoder_dispatch, + bgfx_encoder_dispatch_indirect, + bgfx_encoder_discard, + bgfx_encoder_blit, + bgfx_request_screen_shot, + bgfx_render_frame, + bgfx_set_platform_data, + bgfx_get_internal_data, + bgfx_override_internal_texture_ptr, + bgfx_override_internal_texture, + bgfx_set_marker, + bgfx_set_state, + bgfx_set_condition, + bgfx_set_stencil, + bgfx_set_scissor, + bgfx_set_scissor_cached, + bgfx_set_transform, + bgfx_set_transform_cached, + bgfx_alloc_transform, + bgfx_set_uniform, + bgfx_set_index_buffer, + bgfx_set_dynamic_index_buffer, + bgfx_set_transient_index_buffer, + bgfx_set_vertex_buffer, + bgfx_set_vertex_buffer_with_layout, + bgfx_set_dynamic_vertex_buffer, + bgfx_set_dynamic_vertex_buffer_with_layout, + bgfx_set_transient_vertex_buffer, + bgfx_set_transient_vertex_buffer_with_layout, + bgfx_set_vertex_count, + bgfx_set_instance_data_buffer, + bgfx_set_instance_data_from_vertex_buffer, + bgfx_set_instance_data_from_dynamic_vertex_buffer, + bgfx_set_instance_count, + bgfx_set_texture, + bgfx_touch, + bgfx_submit, + bgfx_submit_occlusion_query, + bgfx_submit_indirect, + bgfx_submit_indirect_count, + bgfx_set_compute_index_buffer, + bgfx_set_compute_vertex_buffer, + bgfx_set_compute_dynamic_index_buffer, + bgfx_set_compute_dynamic_vertex_buffer, + bgfx_set_compute_indirect_buffer, + bgfx_set_image, + bgfx_dispatch, + bgfx_dispatch_indirect, + bgfx_discard, + bgfx_blit + }; + + return &s_bgfx_interface; + } + + return NULL; +} diff --git a/3rdparty/bgfx/src/bgfx_compute.sh b/3rdparty/bgfx/src/bgfx_compute.sh index 05eefd88713..59dda85e067 100644 --- a/3rdparty/bgfx/src/bgfx_compute.sh +++ b/3rdparty/bgfx/src/bgfx_compute.sh @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_COMPUTE_H_HEADER_GUARD @@ -10,6 +10,18 @@ #ifndef __cplusplus +#if BGFX_SHADER_LANGUAGE_HLSL > 0 && BGFX_SHADER_LANGUAGE_HLSL < 400 +# error "Compute is not supported!" +#endif // BGFX_SHADER_LANGUAGE_HLSL + +#if BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV +# define FORMAT(_format) [[spv::format_ ## _format]] +# define WRITEONLY [[spv::nonreadable]] +#else +# define FORMAT(_format) +# define WRITEONLY +#endif // BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV + #if BGFX_SHADER_LANGUAGE_GLSL #define SHARED shared @@ -64,201 +76,193 @@ #define SHARED groupshared -#define r32ui uint -#define rg32ui uint2 -#define rgba32ui uint4 -#define r32f float -#define rg16f float2 -#define rgba16f float4 +#define COMP_r32ui uint +#define COMP_rg32ui uint2 +#define COMP_rgba32ui uint4 +#define COMP_r32f float +#define COMP_r16f float +#define COMP_rg16f float2 +#define COMP_rgba16f float4 #if BGFX_SHADER_LANGUAGE_HLSL -# define rgba8 unorm float4 +# define COMP_rgba8 unorm float4 +# define COMP_rg8 unorm float2 +# define COMP_r8 unorm float #else -# define rgba8 float4 +# define COMP_rgba8 float4 +# define COMP_rg8 float2 +# define COMP_r8 float #endif // BGFX_SHADER_LANGUAGE_HLSL -#define rgba32f float4 +#define COMP_rgba32f float4 -#define IMAGE2D_RO( _name, _format, _reg) \ - Texture2D<_format> _name ## Texture : REGISTER(t, _reg); \ - static BgfxROImage2D_ ## _format _name = { _name ## Texture } +#define IMAGE2D_RO( _name, _format, _reg) \ + FORMAT(_format) Texture2D<COMP_ ## _format> _name : REGISTER(t, _reg); \ #define UIMAGE2D_RO(_name, _format, _reg) IMAGE2D_RO(_name, _format, _reg) -#define IMAGE2D_RW( _name, _format, _reg) \ - RWTexture2D<_format> _name ## Texture : REGISTER(u, _reg); \ - static BgfxRWImage2D_ ## _format _name = { _name ## Texture } +#define IMAGE2D_WR( _name, _format, _reg) \ + WRITEONLY FORMAT(_format) RWTexture2D<COMP_ ## _format> _name : REGISTER(u, _reg); \ + +#define UIMAGE2D_WR(_name, _format, _reg) IMAGE2D_WR(_name, _format, _reg) + +#define IMAGE2D_RW( _name, _format, _reg) \ + FORMAT(_format) RWTexture2D<COMP_ ## _format> _name : REGISTER(u, _reg); \ -#define IMAGE2D_WR( _name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) -#define UIMAGE2D_WR(_name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) #define UIMAGE2D_RW(_name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) -#define IMAGE2D_ARRAY_RO(_name, _format, _reg) \ - Texture2DArray<_format> _name ## Texture : REGISTER(t, _reg); \ - static BgfxROImage2DArray_ ## _format _name = { _name ## Texture } +#define IMAGE2D_ARRAY_RO(_name, _format, _reg) \ + FORMAT(_format) Texture2DArray<COMP_ ## _format> _name : REGISTER(t, _reg); \ #define UIMAGE2D_ARRAY_RO(_name, _format, _reg) IMAGE2D_ARRAY_RO(_name, _format, _reg) -#define IMAGE2D_ARRAY_RW(_name, _format, _reg) \ - RWTexture2DArray<_format> _name ## Texture : REGISTER(u, _reg); \ - static BgfxRWImage2DArray_ ## _format _name = { _name ## Texture } +#define IMAGE2D_ARRAY_WR( _name, _format, _reg) \ + WRITEONLY FORMAT(_format) RWTexture2DArray<COMP_ ## _format> _name : REGISTER(u, _reg); \ + +#define UIMAGE2D_ARRAY_WR(_name, _format, _reg) IMAGE2D_ARRAY_WR(_name, _format, _reg) + +#define IMAGE2D_ARRAY_RW(_name, _format, _reg) \ + FORMAT(_format) RWTexture2DArray<COMP_ ## _format> _name : REGISTER(u, _reg); \ #define UIMAGE2D_ARRAY_RW(_name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) -#define IMAGE2D_ARRAY_WR( _name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) -#define UIMAGE2D_ARRAY_WR(_name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) -#define IMAGE3D_RO( _name, _format, _reg) \ - Texture3D<_format> _name ## Texture : REGISTER(t, _reg); \ - static BgfxROImage3D_ ## _format _name = { _name ## Texture } +#define IMAGE3D_RO( _name, _format, _reg) \ + FORMAT(_format) Texture3D<COMP_ ## _format> _name : REGISTER(t, _reg); #define UIMAGE3D_RO(_name, _format, _reg) IMAGE3D_RO(_name, _format, _reg) -#define IMAGE3D_RW( _name, _format, _reg) \ - RWTexture3D<_format> _name ## Texture : REGISTER(u, _reg); \ - static BgfxRWImage3D_ ## _format _name = { _name ## Texture } +#define IMAGE3D_WR( _name, _format, _reg) \ + WRITEONLY FORMAT(_format) RWTexture3D<COMP_ ## _format> _name : REGISTER(u, _reg); -#define UIMAGE3D_RW(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) -#define IMAGE3D_WR( _name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) #define UIMAGE3D_WR(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) +#define IMAGE3D_RW( _name, _format, _reg) \ + FORMAT(_format) RWTexture3D<COMP_ ## _format> _name : REGISTER(u, _reg); \ + +#define UIMAGE3D_RW(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) + +#if BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV +#define BUFFER_RO(_name, _struct, _reg) StructuredBuffer<_struct> _name : REGISTER(t, _reg) +#define BUFFER_RW(_name, _struct, _reg) RWStructuredBuffer <_struct> _name : REGISTER(u, _reg) +#define BUFFER_WR(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg) +#else #define BUFFER_RO(_name, _struct, _reg) Buffer<_struct> _name : REGISTER(t, _reg) #define BUFFER_RW(_name, _struct, _reg) RWBuffer<_struct> _name : REGISTER(u, _reg) #define BUFFER_WR(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg) +#endif #define NUM_THREADS(_x, _y, _z) [numthreads(_x, _y, _z)] -#define __IMAGE_IMPL_S(_format, _storeComponents, _type, _loadComponents) \ +#define __IMAGE_IMPL_A(_format, _storeComponents, _type, _loadComponents) \ + _type imageLoad(Texture2D<_format> _image, ivec2 _uv) \ + { \ + return _image[_uv]._loadComponents; \ + } \ \ - struct BgfxROImage2D_ ## _format \ - { \ - Texture2D<_format> m_texture; \ - }; \ + ivec2 imageSize(Texture2D<_format> _image) \ + { \ + uvec2 result; \ + _image.GetDimensions(result.x, result.y); \ + return ivec2(result); \ + } \ \ - struct BgfxRWImage2D_ ## _format \ - { \ - RWTexture2D<_format> m_texture; \ - }; \ + _type imageLoad(RWTexture2D<_format> _image, ivec2 _uv) \ + { \ + return _image[_uv]._loadComponents; \ + } \ \ - struct BgfxROImage2DArray_ ## _format \ - { \ - Texture2DArray<_format> m_texture; \ - }; \ + void imageStore(RWTexture2D<_format> _image, ivec2 _uv, _type _value) \ + { \ + _image[_uv] = _value._storeComponents; \ + } \ \ - struct BgfxRWImage2DArray_ ## _format \ - { \ - RWTexture2DArray<_format> m_texture; \ - }; \ + ivec2 imageSize(RWTexture2D<_format> _image) \ + { \ + uvec2 result; \ + _image.GetDimensions(result.x, result.y); \ + return ivec2(result); \ + } \ \ - struct BgfxROImage3D_ ## _format \ - { \ - Texture3D<_format> m_texture; \ - }; \ + _type imageLoad(Texture2DArray<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - struct BgfxRWImage3D_ ## _format \ - { \ - RWTexture3D<_format> m_texture; \ - }; \ - -#define __IMAGE_IMPL_A(_format, _storeComponents, _type, _loadComponents) \ - __IMAGE_IMPL_S(_format, _storeComponents, _type, _loadComponents) \ + ivec3 imageSize(Texture2DArray<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ + } \ \ - _type imageLoad(BgfxROImage2D_ ## _format _image, ivec2 _uv) \ - { \ - return _image.m_texture[_uv]._loadComponents; \ - } \ + _type imageLoad(RWTexture2DArray<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - ivec2 imageSize(BgfxROImage2D_ ## _format _image) \ - { \ - uvec2 result; \ - _image.m_texture.GetDimensions(result.x, result.y); \ - return ivec2(result); \ - } \ + void imageStore(RWTexture2DArray<_format> _image, ivec3 _uvw, _type _value) \ + { \ + _image[_uvw] = _value._storeComponents; \ + } \ \ - _type imageLoad(BgfxRWImage2D_ ## _format _image, ivec2 _uv) \ - { \ - return _image.m_texture[_uv]._loadComponents; \ - } \ + ivec3 imageSize(RWTexture2DArray<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ + } \ \ - ivec2 imageSize(BgfxRWImage2D_ ## _format _image) \ - { \ - uvec2 result; \ - _image.m_texture.GetDimensions(result.x, result.y); \ - return ivec2(result); \ - } \ + _type imageLoad(Texture3D<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - void imageStore(BgfxRWImage2D_ ## _format _image, ivec2 _uv, _type _value) \ - { \ - _image.m_texture[_uv] = _value._storeComponents; \ - } \ + ivec3 imageSize(Texture3D<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ + } \ \ - _type imageLoad(BgfxROImage2DArray_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ + _type imageLoad(RWTexture3D<_format> _image, ivec3 _uvw) \ + { \ + return _image[_uvw]._loadComponents; \ + } \ \ - ivec3 imageSize(BgfxROImage2DArray_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ - } \ + void imageStore(RWTexture3D<_format> _image, ivec3 _uvw, _type _value) \ + { \ + _image[_uvw] = _value._storeComponents; \ + } \ \ - _type imageLoad(BgfxRWImage2DArray_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ - \ - void imageStore(BgfxRWImage2DArray_ ## _format _image, ivec3 _uvw, _type _value) \ - { \ - _image.m_texture[_uvw] = _value._storeComponents; \ - } \ - \ - ivec3 imageSize(BgfxRWImage2DArray_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ - } \ - \ - _type imageLoad(BgfxROImage3D_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ - \ - ivec3 imageSize(BgfxROImage3D_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ - } \ - \ - _type imageLoad(BgfxRWImage3D_ ## _format _image, ivec3 _uvw) \ - { \ - return _image.m_texture[_uvw]._loadComponents; \ - } \ + ivec3 imageSize(RWTexture3D<_format> _image) \ + { \ + uvec3 result; \ + _image.GetDimensions(result.x, result.y, result.z); \ + return ivec3(result); \ + } + +#define __IMAGE_IMPL_ATOMIC(_format, _storeComponents, _type, _loadComponents) \ \ - ivec3 imageSize(BgfxRWImage3D_ ## _format _image) \ - { \ - uvec3 result; \ - _image.m_texture.GetDimensions(result.x, result.y, result.z); \ - return ivec3(result); \ + void imageAtomicAdd(RWTexture2D<_format> _image, ivec2 _uv, _type _value) \ + { \ + InterlockedAdd(_image[_uv], _value._storeComponents); \ } \ - \ - void imageStore(BgfxRWImage3D_ ## _format _image, ivec3 _uvw, _type _value) \ - { \ - _image.m_texture[_uvw] = _value._storeComponents; \ - } -__IMAGE_IMPL_A(rgba8, xyzw, vec4, xyzw) -__IMAGE_IMPL_A(rg16f, xy, vec4, xyyy) + +__IMAGE_IMPL_A(float, x, vec4, xxxx) +__IMAGE_IMPL_A(float2, xy, vec4, xyyy) +__IMAGE_IMPL_A(float4, xyzw, vec4, xyzw) + +__IMAGE_IMPL_A(uint, x, uvec4, xxxx) +__IMAGE_IMPL_A(uint2, xy, uvec4, xyyy) +__IMAGE_IMPL_A(uint4, xyzw, uvec4, xyzw) + #if BGFX_SHADER_LANGUAGE_HLSL -__IMAGE_IMPL_S(rgba16f, xyzw, vec4, xyzw) -#else -__IMAGE_IMPL_A(rgba16f, xyzw, vec4, xyzw) -#endif // BGFX_SHADER_LANGUAGE_HLSL -__IMAGE_IMPL_A(r32f, x, vec4, xxxx) -__IMAGE_IMPL_A(rgba32f, xyzw, vec4, xyzw) -__IMAGE_IMPL_A(r32ui, x, uvec4, xxxx) -__IMAGE_IMPL_A(rg32ui, xy, uvec4, xyyy) -__IMAGE_IMPL_A(rgba32ui, xyzw, uvec4, xyzw) +__IMAGE_IMPL_A(unorm float, x, vec4, xxxx) +__IMAGE_IMPL_A(unorm float2, xy, vec4, xyyy) +__IMAGE_IMPL_A(unorm float4, xyzw, vec4, xyzw) +#endif + +__IMAGE_IMPL_ATOMIC(uint, x, uvec4, xxxx) + #define atomicAdd(_mem, _data) InterlockedAdd(_mem, _data) #define atomicAnd(_mem, _data) InterlockedAnd(_mem, _data) @@ -294,7 +298,7 @@ __IMAGE_IMPL_A(rgba32ui, xyzw, uvec4, xyzw) , _numY \ , _numZ \ ) \ - _buffer[_offset*2+0] = uvec4(_numX, _numY, _numZ, 0u) + _buffer[(_offset)*2+0] = uvec4(_numX, _numY, _numZ, 0u) #define drawIndirect( \ _buffer \ @@ -304,7 +308,7 @@ __IMAGE_IMPL_A(rgba32ui, xyzw, uvec4, xyzw) , _startVertex \ , _startInstance \ ) \ - _buffer[_offset*2+0] = uvec4(_numVertices, _numInstances, _startVertex, _startInstance) + _buffer[(_offset)*2+0] = uvec4(_numVertices, _numInstances, _startVertex, _startInstance) #define drawIndexedIndirect( \ _buffer \ @@ -315,8 +319,8 @@ __IMAGE_IMPL_A(rgba32ui, xyzw, uvec4, xyzw) , _startVertex \ , _startInstance \ ) \ - _buffer[_offset*2+0] = uvec4(_numIndices, _numInstances, _startIndex, _startVertex); \ - _buffer[_offset*2+1] = uvec4(_startInstance, 0u, 0u, 0u) + _buffer[(_offset)*2+0] = uvec4(_numIndices, _numInstances, _startIndex, _startVertex); \ + _buffer[(_offset)*2+1] = uvec4(_startInstance, 0u, 0u, 0u) #endif // __cplusplus diff --git a/3rdparty/bgfx/src/bgfx_p.h b/3rdparty/bgfx/src/bgfx_p.h index f6dfc434b19..31ede49d044 100644 --- a/3rdparty/bgfx/src/bgfx_p.h +++ b/3rdparty/bgfx/src/bgfx_p.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_P_H_HEADER_GUARD @@ -8,16 +8,17 @@ #include <bx/platform.h> -#ifndef BGFX_CONFIG_DEBUG -# define BGFX_CONFIG_DEBUG 0 -#endif // BGFX_CONFIG_DEBUG +#ifndef BX_CONFIG_DEBUG +# error "BX_CONFIG_DEBUG must be defined in build script!" +#endif // BX_CONFIG_DEBUG -#if BGFX_CONFIG_DEBUG || BX_COMPILER_CLANG_ANALYZER -# define BX_TRACE _BX_TRACE -# define BX_WARN _BX_WARN -# define BX_CHECK _BX_CHECK -# define BX_CONFIG_ALLOCATOR_DEBUG 1 -#endif // BGFX_CONFIG_DEBUG +#define BGFX_CONFIG_DEBUG BX_CONFIG_DEBUG + +#if BX_CONFIG_DEBUG +# define BX_TRACE _BGFX_TRACE +# define BX_WARN _BGFX_WARN +# define BX_ASSERT _BGFX_ASSERT +#endif // BX_CONFIG_DEBUG #include <bgfx/bgfx.h> #include "config.h" @@ -25,24 +26,24 @@ #include <inttypes.h> // Check handle, cannot be bgfx::kInvalidHandle and must be valid. -#define BGFX_CHECK_HANDLE(_desc, _handleAlloc, _handle) \ - BX_CHECK(isValid(_handle) \ - && _handleAlloc.isValid(_handle.idx) \ - , "Invalid handle. %s handle: %d (max %d)" \ - , _desc \ - , _handle.idx \ - , _handleAlloc.getMaxHandles() \ - ) +#define BGFX_CHECK_HANDLE(_desc, _handleAlloc, _handle) \ + BX_ASSERT(isValid(_handle) \ + && _handleAlloc.isValid(_handle.idx) \ + , "Invalid handle. %s handle: %d (max %d)" \ + , _desc \ + , _handle.idx \ + , _handleAlloc.getMaxHandles() \ + ) // Check handle, it's ok to be bgfx::kInvalidHandle or must be valid. #define BGFX_CHECK_HANDLE_INVALID_OK(_desc, _handleAlloc, _handle) \ - BX_CHECK(!isValid(_handle) \ - || _handleAlloc.isValid(_handle.idx) \ - , "Invalid handle. %s handle: %d (max %d)" \ - , _desc \ - , _handle.idx \ - , _handleAlloc.getMaxHandles() \ - ) + BX_ASSERT(!isValid(_handle) \ + || _handleAlloc.isValid(_handle.idx) \ + , "Invalid handle. %s handle: %d (max %d)" \ + , _desc \ + , _handle.idx \ + , _handleAlloc.getMaxHandles() \ + ) #if BGFX_CONFIG_MULTITHREADED # define BGFX_MUTEX_SCOPE(_mutex) bx::MutexScope BX_CONCATENATE(mutexScope, __LINE__)(_mutex) @@ -51,66 +52,82 @@ #endif // BGFX_CONFIG_MULTITHREADED #if BGFX_CONFIG_PROFILER -# define BGFX_PROFILER_SCOPE(_name, _abgr) ProfilerScope BX_CONCATENATE(profilerScope, __LINE__)(_name, _abgr, __FILE__, uint16_t(__LINE__) ) -# define BGFX_PROFILER_BEGIN(_name, _abgr) g_callback->profilerBeginLiteral(_name, _abgr, __FILE__, uint16_t(__LINE__) ) -# define BGFX_PROFILER_END() g_callback->profilerEnd() +# define BGFX_PROFILER_SCOPE(_name, _abgr) ProfilerScope BX_CONCATENATE(profilerScope, __LINE__)(_name, _abgr, __FILE__, uint16_t(__LINE__) ) +# define BGFX_PROFILER_BEGIN(_name, _abgr) g_callback->profilerBegin(_name, _abgr, __FILE__, uint16_t(__LINE__) ) +# define BGFX_PROFILER_BEGIN_LITERAL(_name, _abgr) g_callback->profilerBeginLiteral(_name, _abgr, __FILE__, uint16_t(__LINE__) ) +# define BGFX_PROFILER_END() g_callback->profilerEnd() # define BGFX_PROFILER_SET_CURRENT_THREAD_NAME(_name) BX_NOOP() #else -# define BGFX_PROFILER_SCOPE(_name, _abgr) BX_NOOP() -# define BGFX_PROFILER_BEGIN(_name, _abgr) BX_NOOP() -# define BGFX_PROFILER_END() BX_NOOP() +# define BGFX_PROFILER_SCOPE(_name, _abgr) BX_NOOP() +# define BGFX_PROFILER_BEGIN(_name, _abgr) BX_NOOP() +# define BGFX_PROFILER_BEGIN_LITERAL(_name, _abgr) BX_NOOP() +# define BGFX_PROFILER_END() BX_NOOP() # define BGFX_PROFILER_SET_CURRENT_THREAD_NAME(_name) BX_NOOP() #endif // BGFX_PROFILER_SCOPE namespace bgfx { #if BX_COMPILER_CLANG_ANALYZER - void __attribute__( (analyzer_noreturn) ) fatal(Fatal::Enum _code, const char* _format, ...); + void __attribute__( (analyzer_noreturn) ) fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _format, ...); #else void fatal(const char* _filePath, uint16_t _line, Fatal::Enum _code, const char* _format, ...); #endif // BX_COMPILER_CLANG_ANALYZER void trace(const char* _filePath, uint16_t _line, const char* _format, ...); - inline bool operator==(const VertexDeclHandle& _lhs, const VertexDeclHandle& _rhs) { return _lhs.idx == _rhs.idx; } + inline bool operator==(const VertexLayoutHandle& _lhs, const VertexLayoutHandle& _rhs) { return _lhs.idx == _rhs.idx; } inline bool operator==(const UniformHandle& _lhs, const UniformHandle& _rhs) { return _lhs.idx == _rhs.idx; } } -#define _BX_TRACE(_format, ...) \ - BX_MACRO_BLOCK_BEGIN \ - bgfx::trace(__FILE__, uint16_t(__LINE__), "BGFX " _format "\n", ##__VA_ARGS__); \ - BX_MACRO_BLOCK_END - -#define _BX_WARN(_condition, _format, ...) \ - BX_MACRO_BLOCK_BEGIN \ - if (!BX_IGNORE_C4127(_condition) ) \ - { \ - BX_TRACE("WARN " _format, ##__VA_ARGS__); \ - } \ - BX_MACRO_BLOCK_END - -#define _BX_CHECK(_condition, _format, ...) \ - BX_MACRO_BLOCK_BEGIN \ - if (!BX_IGNORE_C4127(_condition) ) \ - { \ - BX_TRACE("CHECK " _format, ##__VA_ARGS__); \ - bgfx::fatal(__FILE__, uint16_t(__LINE__), bgfx::Fatal::DebugCheck, _format, ##__VA_ARGS__); \ - } \ - BX_MACRO_BLOCK_END - -#define BGFX_FATAL(_condition, _err, _format, ...) \ - BX_MACRO_BLOCK_BEGIN \ - if (!BX_IGNORE_C4127(_condition) ) \ - { \ - fatal(__FILE__, uint16_t(__LINE__), _err, _format, ##__VA_ARGS__); \ - } \ - BX_MACRO_BLOCK_END +#define _BGFX_TRACE(_format, ...) \ + BX_MACRO_BLOCK_BEGIN \ + bgfx::trace(__FILE__, uint16_t(__LINE__), "BGFX " _format "\n", ##__VA_ARGS__); \ + BX_MACRO_BLOCK_END + +#define _BGFX_WARN(_condition, _format, ...) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ + { \ + BX_TRACE("WARN " _format, ##__VA_ARGS__); \ + } \ + BX_MACRO_BLOCK_END + +#define _BGFX_ASSERT(_condition, _format, ...) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ + { \ + BX_TRACE("ASSERT " _format, ##__VA_ARGS__); \ + bgfx::fatal(__FILE__, uint16_t(__LINE__), bgfx::Fatal::DebugCheck, _format, ##__VA_ARGS__); \ + } \ + BX_MACRO_BLOCK_END + +#define BGFX_FATAL(_condition, _err, _format, ...) \ + BX_MACRO_BLOCK_BEGIN \ + if (!BX_IGNORE_C4127(_condition) ) \ + { \ + fatal(__FILE__, uint16_t(__LINE__), _err, _format, ##__VA_ARGS__); \ + } \ + BX_MACRO_BLOCK_END + +#define BGFX_ERROR_CHECK(_condition, _err, _result, _msg, _format, ...) \ + if (!BX_IGNORE_C4127(_condition) ) \ + { \ + BX_ERROR_SET(_err, _result, _msg); \ + BX_TRACE("%S: 0x%08x '%S' - " _format \ + , &bxErrorScope.getName() \ + , _err->get().code \ + , &_err->getMessage() \ + , ##__VA_ARGS__ \ + ); \ + return; \ + } #include <bx/allocator.h> #include <bx/bx.h> #include <bx/cpu.h> #include <bx/debug.h> #include <bx/endian.h> +#include <bx/error.h> #include <bx/float4x4_t.h> #include <bx/handlealloc.h> #include <bx/hash.h> @@ -128,7 +145,8 @@ namespace bgfx #include <bgfx/platform.h> #include <bimg/bimg.h> #include "shader.h" -#include "vertexdecl.h" +#include "vertexlayout.h" +#include "version.h" #define BGFX_CHUNK_MAGIC_TEX BX_MAKEFOURCC('T', 'E', 'X', 0x0) @@ -199,8 +217,6 @@ namespace stl = std; #if BX_PLATFORM_ANDROID # include <android/native_window.h> -#elif BX_PLATFORM_WINDOWS -# include <windows.h> #endif // BX_PLATFORM_* #define BGFX_MAX_COMPUTE_BINDINGS BGFX_CONFIG_MAX_TEXTURE_SAMPLERS @@ -213,15 +229,21 @@ namespace stl = std; #define BGFX_STATE_INTERNAL_SCISSOR UINT64_C(0x2000000000000000) #define BGFX_STATE_INTERNAL_OCCLUSION_QUERY UINT64_C(0x4000000000000000) +#define BGFX_SUBMIT_INTERNAL_NONE UINT8_C(0x00) +#define BGFX_SUBMIT_INTERNAL_INDEX32 UINT8_C(0x40) #define BGFX_SUBMIT_INTERNAL_OCCLUSION_VISIBLE UINT8_C(0x80) +#define BGFX_SUBMIT_INTERNAL_RESERVED_MASK UINT8_C(0xff) +#define BGFX_RENDERER_NOOP_NAME "Noop" +#define BGFX_RENDERER_AGC_NAME "AGC" #define BGFX_RENDERER_DIRECT3D9_NAME "Direct3D 9" #define BGFX_RENDERER_DIRECT3D11_NAME "Direct3D 11" #define BGFX_RENDERER_DIRECT3D12_NAME "Direct3D 12" +#define BGFX_RENDERER_GNM_NAME "GNM" #define BGFX_RENDERER_METAL_NAME "Metal" +#define BGFX_RENDERER_NVN_NAME "NVN" #define BGFX_RENDERER_VULKAN_NAME "Vulkan" -#define BGFX_RENDERER_GNM_NAME "GNM" -#define BGFX_RENDERER_NOOP_NAME "Noop" +#define BGFX_RENDERER_WEBGPU_NAME "WebGPU" #if BGFX_CONFIG_RENDERER_OPENGL # if BGFX_CONFIG_RENDERER_OPENGL >= 31 && BGFX_CONFIG_RENDERER_OPENGL <= 33 @@ -232,7 +254,7 @@ namespace stl = std; # else # define BGFX_RENDERER_OPENGL_NAME "OpenGL 3.3" # endif // 31+ -# elif BGFX_CONFIG_RENDERER_OPENGL >= 40 && BGFX_CONFIG_RENDERER_OPENGL <= 45 +# elif BGFX_CONFIG_RENDERER_OPENGL >= 40 && BGFX_CONFIG_RENDERER_OPENGL <= 46 # if BGFX_CONFIG_RENDERER_OPENGL == 40 # define BGFX_RENDERER_OPENGL_NAME "OpenGL 4.0" # elif BGFX_CONFIG_RENDERER_OPENGL == 41 @@ -243,8 +265,10 @@ namespace stl = std; # define BGFX_RENDERER_OPENGL_NAME "OpenGL 4.3" # elif BGFX_CONFIG_RENDERER_OPENGL == 44 # define BGFX_RENDERER_OPENGL_NAME "OpenGL 4.4" -# else +# elif BGFX_CONFIG_RENDERER_OPENGL == 45 # define BGFX_RENDERER_OPENGL_NAME "OpenGL 4.5" +# else +# define BGFX_RENDERER_OPENGL_NAME "OpenGL 4.6" # endif // 40+ # else # define BGFX_RENDERER_OPENGL_NAME "OpenGL 2.1" @@ -252,8 +276,10 @@ namespace stl = std; #elif BGFX_CONFIG_RENDERER_OPENGLES # if BGFX_CONFIG_RENDERER_OPENGLES == 30 # define BGFX_RENDERER_OPENGL_NAME "OpenGL ES 3.0" -# elif BGFX_CONFIG_RENDERER_OPENGLES >= 31 +# elif BGFX_CONFIG_RENDERER_OPENGLES == 31 # define BGFX_RENDERER_OPENGL_NAME "OpenGL ES 3.1" +# elif BGFX_CONFIG_RENDERER_OPENGLES >= 32 +# define BGFX_RENDERER_OPENGL_NAME "OpenGL ES 3.2" # else # define BGFX_RENDERER_OPENGL_NAME "OpenGL ES 2.0" # endif // BGFX_CONFIG_RENDERER_OPENGLES @@ -266,6 +292,8 @@ namespace bgfx extern InternalData g_internalData; extern PlatformData g_platformData; extern bool g_platformDataChangedSinceReset; + extern void isFrameBufferValid(uint8_t _num, const Attachment* _attachment, bx::Error* _err); + extern void isIdentifierValid(const bx::StringView& _name, bx::Error* _err); #if BGFX_CONFIG_MAX_DRAW_CALLS < (64<<10) typedef uint16_t RenderItemCount; @@ -273,35 +301,123 @@ namespace bgfx typedef uint32_t RenderItemCount; #endif // BGFX_CONFIG_MAX_DRAW_CALLS < (64<<10) + /// struct Handle { + /// + struct TypeName + { + const char* abrvName; + const char* fullName; + }; + + /// enum Enum { + DynamicIndexBuffer, + DynamicVertexBuffer, + FrameBuffer, + IndexBuffer, + IndirectBuffer, + OcclusionQuery, + Program, Shader, Texture, + Uniform, + VertexBuffer, + VertexLayout, Count }; - uint16_t type; - uint16_t idx; - }; + template<typename Ty> + static constexpr Enum toEnum(); - inline Handle convert(ShaderHandle _handle) - { - Handle handle = { Handle::Shader, _handle.idx }; - return handle; - } + constexpr Handle() + : idx(kInvalidHandle) + , type(Count) + { + } - inline Handle convert(TextureHandle _handle) - { - Handle handle = { Handle::Texture, _handle.idx }; - return handle; - } + template<typename Ty> + constexpr Handle(Ty _handle) + : idx(_handle.idx) + , type(uint16_t(toEnum<Ty>() ) ) + { + } + + template<typename Ty> + constexpr Ty to() const + { + if (type == toEnum<Ty>() ) + { + return Ty{ idx }; + } - inline bool isValid(const VertexDecl& _decl) + BX_ASSERT(type == toEnum<Ty>(), "Handle type %s, cannot be converted to %s." + , getTypeName().fullName + , getTypeName(toEnum<Ty>() ).fullName + ); + return { kInvalidHandle }; + } + + Enum getType() const + { + return Enum(type); + } + + static const TypeName& getTypeName(Handle::Enum _enum); + + const TypeName& getTypeName() const + { + return getTypeName(getType() ); + } + + bool isBuffer() const + { + return false + || type == DynamicIndexBuffer + || type == DynamicVertexBuffer + || type == IndexBuffer + || type == IndirectBuffer + || type == VertexBuffer + ; + } + + bool isTexture() const + { + return type == Texture; + } + + uint16_t idx; + uint16_t type; + }; + +#define IMPLEMENT_HANDLE(_name) \ + template<> \ + inline constexpr Handle::Enum Handle::toEnum<_name##Handle>() \ + { \ + return Handle::_name; \ + } \ + + IMPLEMENT_HANDLE(DynamicIndexBuffer); + IMPLEMENT_HANDLE(DynamicVertexBuffer); + IMPLEMENT_HANDLE(FrameBuffer); + IMPLEMENT_HANDLE(IndexBuffer); + IMPLEMENT_HANDLE(IndirectBuffer); + IMPLEMENT_HANDLE(OcclusionQuery); + IMPLEMENT_HANDLE(Program); + IMPLEMENT_HANDLE(Shader); + IMPLEMENT_HANDLE(Texture); + IMPLEMENT_HANDLE(Uniform); + IMPLEMENT_HANDLE(VertexBuffer); + IMPLEMENT_HANDLE(VertexLayout); + +#undef IMPLEMENT_HANDLE + + inline bool isValid(const VertexLayout& _layout) { - return 0 != _decl.m_stride; + return 0 != _layout.m_stride; } struct Condition @@ -386,9 +502,9 @@ namespace bgfx void clear() { - m_x = - m_y = - m_width = + m_x = 0; + m_y = 0; + m_width = 0; m_height = 0; } @@ -443,8 +559,8 @@ namespace bgfx uint16_t m_height; uint16_t m_depth; uint16_t m_numLayers; - uint8_t m_numMips; - bool m_cubeMap; + uint8_t m_numMips; + bool m_cubeMap; const Memory* m_mem; }; @@ -477,6 +593,7 @@ namespace bgfx TextureFormat::Enum getViableTextureFormat(const bimg::ImageContainer& _imageContainer); const char* getName(TextureFormat::Enum _fmt); const char* getName(UniformHandle _handle); + const char* getName(ShaderHandle _handle); const char* getName(Topology::Enum _topology); template<typename Ty> @@ -507,7 +624,7 @@ namespace bgfx return uint32_t( (_stencil >> (32*_0or1) ) ); } - inline bool needBorderColor(uint32_t _flags) + inline bool needBorderColor(uint64_t _flags) { return BGFX_SAMPLER_U_BORDER == (_flags & BGFX_SAMPLER_U_BORDER) || BGFX_SAMPLER_V_BORDER == (_flags & BGFX_SAMPLER_V_BORDER) @@ -520,7 +637,7 @@ namespace bgfx if (_hasMips) { const uint32_t max = bx::max(_width, _height, _depth); - const uint32_t num = 1 + uint32_t(bx::log2(float(max) ) ); + const uint32_t num = 1 + uint32_t(bx::log2<int32_t>(max) ); return uint8_t(num); } @@ -528,8 +645,11 @@ namespace bgfx return 1; } - /// Dump vertex declaration into debug output. - void dump(const VertexDecl& _decl); + /// Dump vertex layout info into debug output. + void dump(const VertexLayout& _layout); + + /// Dump resolution and reset info into debug output. + void dump(const Resolution& _resolution); struct TextVideoMem { @@ -566,11 +686,11 @@ namespace bgfx uint32_t size = m_size; m_size = m_width * m_height; - m_mem = (MemSlot*)BX_REALLOC(g_allocator, m_mem, m_size * sizeof(MemSlot)); + m_mem = (MemSlot*)BX_REALLOC(g_allocator, m_mem, m_size * sizeof(MemSlot) ); if (size < m_size) { - bx::memSet(&m_mem[size], 0, (m_size-size) * sizeof(MemSlot)); + bx::memSet(&m_mem[size], 0, (m_size-size) * sizeof(MemSlot) ); } } } @@ -578,7 +698,7 @@ namespace bgfx void clear(uint8_t _attr = 0) { MemSlot* mem = m_mem; - bx::memSet(mem, 0, m_size * sizeof(MemSlot)); + bx::memSet(mem, 0, m_size * sizeof(MemSlot) ); if (_attr != 0) { for (uint32_t ii = 0, num = m_size; ii < num; ++ii) @@ -643,7 +763,7 @@ namespace bgfx TextureHandle m_texture; TransientVertexBuffer* m_vb; TransientIndexBuffer* m_ib; - VertexDecl m_decl; + VertexLayout m_layout; ProgramHandle m_program; }; @@ -712,8 +832,8 @@ namespace bgfx void init(); void shutdown(); - TransientVertexBuffer* m_vb; - VertexDecl m_decl; + VertexBufferHandle m_vb; + VertexLayout m_layout; ProgramHandle m_program[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; }; @@ -744,28 +864,41 @@ namespace bgfx const char* getUniformTypeName(UniformType::Enum _enum); UniformType::Enum nameToUniformTypeEnum(const char* _name); const char* getPredefinedUniformName(PredefinedUniform::Enum _enum); - PredefinedUniform::Enum nameToPredefinedUniformEnum(const char* _name); + PredefinedUniform::Enum nameToPredefinedUniformEnum(const bx::StringView& _name); class CommandBuffer { BX_CLASS(CommandBuffer , NO_COPY - , NO_ASSIGNMENT ); public: CommandBuffer() - : m_pos(0) - , m_size(BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE) + : m_buffer(NULL) + , m_pos(0) + , m_size(0) + , m_minCapacity(0) { + resize(); finish(); } + ~CommandBuffer() + { + BX_FREE(g_allocator, m_buffer); + } + + void init(uint32_t _minCapacity) + { + m_minCapacity = bx::alignUp(_minCapacity, 1024); + resize(); + } + enum Enum { RendererInit, RendererShutdownBegin, - CreateVertexDecl, + CreateVertexLayout, CreateIndexBuffer, CreateVertexBuffer, CreateDynamicIndexBuffer, @@ -784,7 +917,7 @@ namespace bgfx SetName, End, RendererShutdownEnd, - DestroyVertexDecl, + DestroyVertexLayout, DestroyIndexBuffer, DestroyVertexBuffer, DestroyDynamicIndexBuffer, @@ -795,13 +928,22 @@ namespace bgfx DestroyFrameBuffer, DestroyUniform, ReadTexture, - RequestScreenShot, }; + void resize(uint32_t _capacity = 0) + { + m_capacity = bx::alignUp(bx::max(_capacity, m_minCapacity), 1024); + m_buffer = (uint8_t*)BX_REALLOC(g_allocator, m_buffer, m_capacity); + } + void write(const void* _data, uint32_t _size) { - BX_CHECK(m_size == BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE, "Called write outside start/finish?"); - BX_CHECK(m_pos < m_size, "CommandBuffer::write error (pos: %d, size: %d).", m_pos, m_size); + BX_ASSERT(m_size == 0, "Called write outside start/finish (m_size: %d)?", m_size); + if (m_pos + _size > m_capacity) + { + resize(m_capacity + (16<<10) ); + } + bx::memCopy(&m_buffer[m_pos], _data, _size); m_pos += _size; } @@ -815,7 +957,12 @@ namespace bgfx void read(void* _data, uint32_t _size) { - BX_CHECK(m_pos < m_size, "CommandBuffer::read error (pos: %d, size: %d).", m_pos, m_size); + BX_ASSERT(m_pos + _size <= m_size + , "CommandBuffer::read error (pos: %d-%d, size: %d)." + , m_pos + , m_pos + _size + , m_size + ); bx::memCopy(_data, &m_buffer[m_pos], _size); m_pos += _size; } @@ -829,7 +976,12 @@ namespace bgfx const uint8_t* skip(uint32_t _size) { - BX_CHECK(m_pos < m_size, "CommandBuffer::skip error (pos: %d, size: %d).", m_pos, m_size); + BX_ASSERT(m_pos + _size <= m_size + , "CommandBuffer::skip error (pos: %d-%d, size: %d)." + , m_pos + , m_pos + _size + , m_size + ); const uint8_t* result = &m_buffer[m_pos]; m_pos += _size; return result; @@ -857,7 +1009,7 @@ namespace bgfx void start() { m_pos = 0; - m_size = BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE; + m_size = 0; } void finish() @@ -866,128 +1018,134 @@ namespace bgfx write(cmd); m_size = m_pos; m_pos = 0; + + if (m_size < m_minCapacity + && m_capacity != m_minCapacity) + { + resize(); + } } + uint8_t* m_buffer; uint32_t m_pos; uint32_t m_size; - uint8_t m_buffer[BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE]; + uint32_t m_capacity; + uint32_t m_minCapacity; }; -// -#define SORT_KEY_NUM_BITS_VIEW 10 - -#define SORT_KEY_VIEW_SHIFT (64-SORT_KEY_NUM_BITS_VIEW) -#define SORT_KEY_VIEW_MASK ( (uint64_t(BGFX_CONFIG_MAX_VIEWS-1) )<<SORT_KEY_VIEW_SHIFT) - -#define SORT_KEY_DRAW_BIT_SHIFT (SORT_KEY_VIEW_SHIFT - 1) -#define SORT_KEY_DRAW_BIT (UINT64_C(1)<<SORT_KEY_DRAW_BIT_SHIFT) + // + constexpr uint8_t kSortKeyViewNumBits = uint8_t(31 - bx::uint32_cntlz(BGFX_CONFIG_MAX_VIEWS) ); + constexpr uint8_t kSortKeyViewBitShift = 64-kSortKeyViewNumBits; + constexpr uint64_t kSortKeyViewMask = uint64_t(BGFX_CONFIG_MAX_VIEWS-1)<<kSortKeyViewBitShift; -// -#define SORT_KEY_NUM_BITS_DRAW_TYPE 2 + constexpr uint8_t kSortKeyDrawBitShift = kSortKeyViewBitShift - 1; + constexpr uint64_t kSortKeyDrawBit = uint64_t(1)<<kSortKeyDrawBitShift; -#define SORT_KEY_DRAW_TYPE_BIT_SHIFT (SORT_KEY_DRAW_BIT_SHIFT - SORT_KEY_NUM_BITS_DRAW_TYPE) -#define SORT_KEY_DRAW_TYPE_MASK (UINT64_C(3)<<SORT_KEY_DRAW_TYPE_BIT_SHIFT) + // + constexpr uint8_t kSortKeyDrawTypeNumBits = 2; + constexpr uint8_t kSortKeyDrawTypeBitShift = kSortKeyDrawBitShift - kSortKeyDrawTypeNumBits; + constexpr uint64_t kSortKeyDrawTypeMask = uint64_t(3)<<kSortKeyDrawTypeBitShift; -#define SORT_KEY_DRAW_TYPE_PROGRAM (UINT64_C(0)<<SORT_KEY_DRAW_TYPE_BIT_SHIFT) -#define SORT_KEY_DRAW_TYPE_DEPTH (UINT64_C(1)<<SORT_KEY_DRAW_TYPE_BIT_SHIFT) -#define SORT_KEY_DRAW_TYPE_SEQUENCE (UINT64_C(2)<<SORT_KEY_DRAW_TYPE_BIT_SHIFT) + constexpr uint64_t kSortKeyDrawTypeProgram = uint64_t(0)<<kSortKeyDrawTypeBitShift; + constexpr uint64_t kSortKeyDrawTypeDepth = uint64_t(1)<<kSortKeyDrawTypeBitShift; + constexpr uint64_t kSortKeyDrawTypeSequence = uint64_t(2)<<kSortKeyDrawTypeBitShift; -// -#define SORT_KEY_NUM_BITS_TRANS 2 + // + constexpr uint8_t kSortKeyTransNumBits = 2; -#define SORT_KEY_DRAW_0_TRANS_SHIFT (SORT_KEY_DRAW_TYPE_BIT_SHIFT - SORT_KEY_NUM_BITS_TRANS) -#define SORT_KEY_DRAW_0_TRANS_MASK (UINT64_C(0x3)<<SORT_KEY_DRAW_0_TRANS_SHIFT) + constexpr uint8_t kSortKeyDraw0BlendShift = kSortKeyDrawTypeBitShift - kSortKeyTransNumBits; + constexpr uint64_t kSortKeyDraw0BlendMask = uint64_t(0x3)<<kSortKeyDraw0BlendShift; -#define SORT_KEY_DRAW_0_PROGRAM_SHIFT (SORT_KEY_DRAW_0_TRANS_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM) -#define SORT_KEY_DRAW_0_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_DRAW_0_PROGRAM_SHIFT) + constexpr uint8_t kSortKeyDraw0ProgramShift = kSortKeyDraw0BlendShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM; + constexpr uint64_t kSortKeyDraw0ProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1)<<kSortKeyDraw0ProgramShift; -#define SORT_KEY_DRAW_0_DEPTH_SHIFT (SORT_KEY_DRAW_0_PROGRAM_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH) -#define SORT_KEY_DRAW_0_DEPTH_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)-1)<<SORT_KEY_DRAW_0_DEPTH_SHIFT) + constexpr uint8_t kSortKeyDraw0DepthShift = kSortKeyDraw0ProgramShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH; + constexpr uint64_t kSortKeyDraw0DepthMask = ( (uint64_t(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)-1)<<kSortKeyDraw0DepthShift; -// -#define SORT_KEY_DRAW_1_DEPTH_SHIFT (SORT_KEY_DRAW_TYPE_BIT_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH) -#define SORT_KEY_DRAW_1_DEPTH_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)-1)<<SORT_KEY_DRAW_1_DEPTH_SHIFT) + // + constexpr uint8_t kSortKeyDraw1DepthShift = kSortKeyDrawTypeBitShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH; + constexpr uint64_t kSortKeyDraw1DepthMask = ( (uint64_t(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_DEPTH)-1)<<kSortKeyDraw1DepthShift; -#define SORT_KEY_DRAW_1_TRANS_SHIFT (SORT_KEY_DRAW_1_DEPTH_SHIFT - SORT_KEY_NUM_BITS_TRANS) -#define SORT_KEY_DRAW_1_TRANS_MASK (UINT64_C(0x3)<<SORT_KEY_DRAW_1_TRANS_SHIFT) + constexpr uint8_t kSortKeyDraw1BlendShift = kSortKeyDraw1DepthShift - kSortKeyTransNumBits; + constexpr uint64_t kSortKeyDraw1BlendMask = uint64_t(0x3)<<kSortKeyDraw1BlendShift; -#define SORT_KEY_DRAW_1_PROGRAM_SHIFT (SORT_KEY_DRAW_1_TRANS_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM) -#define SORT_KEY_DRAW_1_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_DRAW_1_PROGRAM_SHIFT) + constexpr uint8_t kSortKeyDraw1ProgramShift = kSortKeyDraw1BlendShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM; + constexpr uint64_t kSortKeyDraw1ProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1)<<kSortKeyDraw1ProgramShift; -// -#define SORT_KEY_DRAW_2_SEQ_SHIFT (SORT_KEY_DRAW_TYPE_BIT_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ) -#define SORT_KEY_DRAW_2_SEQ_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)-1)<<SORT_KEY_DRAW_2_SEQ_SHIFT) + // + constexpr uint8_t kSortKeyDraw2SeqShift = kSortKeyDrawTypeBitShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ; + constexpr uint64_t kSortKeyDraw2SeqMask = ( (uint64_t(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)-1)<<kSortKeyDraw2SeqShift; -#define SORT_KEY_DRAW_2_TRANS_SHIFT (SORT_KEY_DRAW_2_SEQ_SHIFT - SORT_KEY_NUM_BITS_TRANS) -#define SORT_KEY_DRAW_2_TRANS_MASK (UINT64_C(0x3)<<SORT_KEY_DRAW_2_TRANS_SHIFT) + constexpr uint8_t kSortKeyDraw2BlendShift = kSortKeyDraw2SeqShift - kSortKeyTransNumBits; + constexpr uint64_t kSortKeyDraw2BlendMask = uint64_t(0x3)<<kSortKeyDraw2BlendShift; -#define SORT_KEY_DRAW_2_PROGRAM_SHIFT (SORT_KEY_DRAW_2_TRANS_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM) -#define SORT_KEY_DRAW_2_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_DRAW_2_PROGRAM_SHIFT) + constexpr uint8_t kSortKeyDraw2ProgramShift = kSortKeyDraw2BlendShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM; + constexpr uint64_t kSortKeyDraw2ProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1)<<kSortKeyDraw2ProgramShift; -// -#define SORT_KEY_COMPUTE_SEQ_SHIFT (SORT_KEY_DRAW_BIT_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ) -#define SORT_KEY_COMPUTE_SEQ_MASK ( ( (UINT64_C(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)-1)<<SORT_KEY_COMPUTE_SEQ_SHIFT) + // + constexpr uint8_t kSortKeyComputeSeqShift = kSortKeyDrawBitShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ; + constexpr uint64_t kSortKeyComputeSeqMask = ( (uint64_t(1)<<BGFX_CONFIG_SORT_KEY_NUM_BITS_SEQ)-1)<<kSortKeyComputeSeqShift; -#define SORT_KEY_COMPUTE_PROGRAM_SHIFT (SORT_KEY_COMPUTE_SEQ_SHIFT - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM) -#define SORT_KEY_COMPUTE_PROGRAM_MASK ( (uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1) )<<SORT_KEY_COMPUTE_PROGRAM_SHIFT) + constexpr uint8_t kSortKeyComputeProgramShift = kSortKeyComputeSeqShift - BGFX_CONFIG_SORT_KEY_NUM_BITS_PROGRAM; + constexpr uint64_t kSortKeyComputeProgramMask = uint64_t(BGFX_CONFIG_MAX_PROGRAMS-1)<<kSortKeyComputeProgramShift; - BX_STATIC_ASSERT(BGFX_CONFIG_MAX_VIEWS <= (1<<SORT_KEY_NUM_BITS_VIEW) ); + BX_STATIC_ASSERT(BGFX_CONFIG_MAX_VIEWS <= (1<<kSortKeyViewNumBits) ); BX_STATIC_ASSERT( (BGFX_CONFIG_MAX_PROGRAMS & (BGFX_CONFIG_MAX_PROGRAMS-1) ) == 0); // Must be power of 2. BX_STATIC_ASSERT( (0 // Render key mask shouldn't overlap. - | SORT_KEY_VIEW_MASK - | SORT_KEY_DRAW_BIT - | SORT_KEY_DRAW_TYPE_MASK - | SORT_KEY_DRAW_0_TRANS_MASK - | SORT_KEY_DRAW_0_PROGRAM_MASK - | SORT_KEY_DRAW_0_DEPTH_MASK + | kSortKeyViewMask + | kSortKeyDrawBit + | kSortKeyDrawTypeMask + | kSortKeyDraw0BlendMask + | kSortKeyDraw0ProgramMask + | kSortKeyDraw0DepthMask ) == (0 - ^ SORT_KEY_VIEW_MASK - ^ SORT_KEY_DRAW_BIT - ^ SORT_KEY_DRAW_TYPE_MASK - ^ SORT_KEY_DRAW_0_TRANS_MASK - ^ SORT_KEY_DRAW_0_PROGRAM_MASK - ^ SORT_KEY_DRAW_0_DEPTH_MASK + ^ kSortKeyViewMask + ^ kSortKeyDrawBit + ^ kSortKeyDrawTypeMask + ^ kSortKeyDraw0BlendMask + ^ kSortKeyDraw0ProgramMask + ^ kSortKeyDraw0DepthMask ) ); BX_STATIC_ASSERT( (0 // Render key mask shouldn't overlap. - | SORT_KEY_VIEW_MASK - | SORT_KEY_DRAW_BIT - | SORT_KEY_DRAW_TYPE_MASK - | SORT_KEY_DRAW_1_DEPTH_MASK - | SORT_KEY_DRAW_1_TRANS_MASK - | SORT_KEY_DRAW_1_PROGRAM_MASK + | kSortKeyViewMask + | kSortKeyDrawBit + | kSortKeyDrawTypeMask + | kSortKeyDraw1DepthMask + | kSortKeyDraw1BlendMask + | kSortKeyDraw1ProgramMask ) == (0 - ^ SORT_KEY_VIEW_MASK - ^ SORT_KEY_DRAW_BIT - ^ SORT_KEY_DRAW_TYPE_MASK - ^ SORT_KEY_DRAW_1_DEPTH_MASK - ^ SORT_KEY_DRAW_1_TRANS_MASK - ^ SORT_KEY_DRAW_1_PROGRAM_MASK + ^ kSortKeyViewMask + ^ kSortKeyDrawBit + ^ kSortKeyDrawTypeMask + ^ kSortKeyDraw1DepthMask + ^ kSortKeyDraw1BlendMask + ^ kSortKeyDraw1ProgramMask ) ); BX_STATIC_ASSERT( (0 // Render key mask shouldn't overlap. - | SORT_KEY_VIEW_MASK - | SORT_KEY_DRAW_BIT - | SORT_KEY_DRAW_TYPE_MASK - | SORT_KEY_DRAW_2_SEQ_MASK - | SORT_KEY_DRAW_2_TRANS_MASK - | SORT_KEY_DRAW_2_PROGRAM_MASK + | kSortKeyViewMask + | kSortKeyDrawBit + | kSortKeyDrawTypeMask + | kSortKeyDraw2SeqMask + | kSortKeyDraw2BlendMask + | kSortKeyDraw2ProgramMask ) == (0 - ^ SORT_KEY_VIEW_MASK - ^ SORT_KEY_DRAW_BIT - ^ SORT_KEY_DRAW_TYPE_MASK - ^ SORT_KEY_DRAW_2_SEQ_MASK - ^ SORT_KEY_DRAW_2_TRANS_MASK - ^ SORT_KEY_DRAW_2_PROGRAM_MASK + ^ kSortKeyViewMask + ^ kSortKeyDrawBit + ^ kSortKeyDrawTypeMask + ^ kSortKeyDraw2SeqMask + ^ kSortKeyDraw2BlendMask + ^ kSortKeyDraw2ProgramMask ) ); BX_STATIC_ASSERT( (0 // Compute key mask shouldn't overlap. - | SORT_KEY_VIEW_MASK - | SORT_KEY_DRAW_BIT - | SORT_KEY_COMPUTE_SEQ_SHIFT - | SORT_KEY_COMPUTE_PROGRAM_MASK + | kSortKeyViewMask + | kSortKeyDrawBit + | kSortKeyComputeSeqShift + | kSortKeyComputeProgramMask ) == (0 - ^ SORT_KEY_VIEW_MASK - ^ SORT_KEY_DRAW_BIT - ^ SORT_KEY_COMPUTE_SEQ_SHIFT - ^ SORT_KEY_COMPUTE_PROGRAM_MASK + ^ kSortKeyViewMask + ^ kSortKeyDrawBit + ^ kSortKeyComputeSeqShift + ^ kSortKeyComputeProgramMask ) ); // | 3 2 1 0| @@ -999,21 +1157,21 @@ namespace bgfx // | +-draw | // |----------------------------------------------------------------| Draw Key 0 - Sort by program // | |kkttpppppppppdddddddddddddddddddddddddddddddd | - // | | ^ ^ ^ | - // | | | | | | - // | | +-trans +-program depth-+ | - // | | | + // | | ^ ^ ^ ^ | + // | | | | | | | + // | | | +-blend +-program depth-+ | + // | | +-key type | // |----------------------------------------------------------------| Draw Key 1 - Sort by depth // | |kkddddddddddddddddddddddddddddddddttppppppppp | - // | | ^^ ^ ^ | - // | | || +-trans | | - // | | depth-+ program-+ | + // | | ^ ^ ^ ^ | + // | | | | +-blend | | + // | | +-key type depth-+ program-+ | // | | | // |----------------------------------------------------------------| Draw Key 2 - Sequential // | |kkssssssssssssssssssssttppppppppp | - // | | ^ ^ ^ | - // | | | | | | - // | | seq-+ +-trans +-program | + // | | ^ ^ ^ ^ | + // | | | | | | | + // | | +-key type seq-+ +-blend +-program | // | | | // |----------------------------------------------------------------| Compute Key // | |ssssssssssssssssssssppppppppp | @@ -1034,49 +1192,61 @@ namespace bgfx uint64_t encodeDraw(Enum _type) { - if (SortDepth == _type) + switch (_type) { - const uint64_t depth = (uint64_t(m_depth ) << SORT_KEY_DRAW_1_DEPTH_SHIFT ) & SORT_KEY_DRAW_1_DEPTH_MASK; - const uint64_t program = (uint64_t(m_program) << SORT_KEY_DRAW_1_PROGRAM_SHIFT) & SORT_KEY_DRAW_1_PROGRAM_MASK; - const uint64_t trans = (uint64_t(m_trans ) << SORT_KEY_DRAW_1_TRANS_SHIFT ) & SORT_KEY_DRAW_1_TRANS_MASK; - const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK; - const uint64_t key = view|SORT_KEY_DRAW_BIT|SORT_KEY_DRAW_TYPE_DEPTH|depth|trans|program; + case SortProgram: + { + const uint64_t depth = (uint64_t(m_depth ) << kSortKeyDraw0DepthShift ) & kSortKeyDraw0DepthMask; + const uint64_t program = (uint64_t(m_program.idx) << kSortKeyDraw0ProgramShift) & kSortKeyDraw0ProgramMask; + const uint64_t blend = (uint64_t(m_blend ) << kSortKeyDraw0BlendShift ) & kSortKeyDraw0BlendMask; + const uint64_t view = (uint64_t(m_view ) << kSortKeyViewBitShift ) & kSortKeyViewMask; + const uint64_t key = view|kSortKeyDrawBit|kSortKeyDrawTypeProgram|blend|program|depth; - return key; - } - else if (SortSequence == _type) - { - const uint64_t seq = (uint64_t(m_seq ) << SORT_KEY_DRAW_2_SEQ_SHIFT ) & SORT_KEY_DRAW_2_SEQ_MASK; - const uint64_t program = (uint64_t(m_program) << SORT_KEY_DRAW_2_PROGRAM_SHIFT) & SORT_KEY_DRAW_2_PROGRAM_MASK; - const uint64_t trans = (uint64_t(m_trans ) << SORT_KEY_DRAW_2_TRANS_SHIFT ) & SORT_KEY_DRAW_2_TRANS_MASK; - const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK; - const uint64_t key = view|SORT_KEY_DRAW_BIT|SORT_KEY_DRAW_TYPE_SEQUENCE|seq|trans|program; + return key; + } + break; - BX_CHECK(seq == (uint64_t(m_seq) << SORT_KEY_DRAW_2_SEQ_SHIFT) - , "SortKey error, sequence is truncated (m_seq: %d)." - , m_seq - ); + case SortDepth: + { + const uint64_t depth = (uint64_t(m_depth ) << kSortKeyDraw1DepthShift ) & kSortKeyDraw1DepthMask; + const uint64_t program = (uint64_t(m_program.idx) << kSortKeyDraw1ProgramShift) & kSortKeyDraw1ProgramMask; + const uint64_t blend = (uint64_t(m_blend ) << kSortKeyDraw1BlendShift) & kSortKeyDraw1BlendMask; + const uint64_t view = (uint64_t(m_view ) << kSortKeyViewBitShift ) & kSortKeyViewMask; + const uint64_t key = view|kSortKeyDrawBit|kSortKeyDrawTypeDepth|depth|blend|program; + return key; + } + break; - return key; - } + case SortSequence: + { + const uint64_t seq = (uint64_t(m_seq ) << kSortKeyDraw2SeqShift ) & kSortKeyDraw2SeqMask; + const uint64_t program = (uint64_t(m_program.idx) << kSortKeyDraw2ProgramShift) & kSortKeyDraw2ProgramMask; + const uint64_t blend = (uint64_t(m_blend ) << kSortKeyDraw2BlendShift ) & kSortKeyDraw2BlendMask; + const uint64_t view = (uint64_t(m_view ) << kSortKeyViewBitShift ) & kSortKeyViewMask; + const uint64_t key = view|kSortKeyDrawBit|kSortKeyDrawTypeSequence|seq|blend|program; + + BX_ASSERT(seq == (uint64_t(m_seq) << kSortKeyDraw2SeqShift) + , "SortKey error, sequence is truncated (m_seq: %d)." + , m_seq + ); - const uint64_t depth = (uint64_t(m_depth ) << SORT_KEY_DRAW_0_DEPTH_SHIFT ) & SORT_KEY_DRAW_0_DEPTH_MASK; - const uint64_t program = (uint64_t(m_program) << SORT_KEY_DRAW_0_PROGRAM_SHIFT) & SORT_KEY_DRAW_0_PROGRAM_MASK; - const uint64_t trans = (uint64_t(m_trans ) << SORT_KEY_DRAW_0_TRANS_SHIFT ) & SORT_KEY_DRAW_0_TRANS_MASK; - const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK; - const uint64_t key = view|SORT_KEY_DRAW_BIT|SORT_KEY_DRAW_TYPE_PROGRAM|trans|program|depth; + return key; + } + break; + } - return key; + BX_ASSERT(false, "You should not be here."); + return 0; } uint64_t encodeCompute() { - const uint64_t program = (uint64_t(m_program) << SORT_KEY_COMPUTE_PROGRAM_SHIFT) & SORT_KEY_COMPUTE_PROGRAM_MASK; - const uint64_t seq = (uint64_t(m_seq ) << SORT_KEY_COMPUTE_SEQ_SHIFT ) & SORT_KEY_COMPUTE_SEQ_MASK; - const uint64_t view = (uint64_t(m_view ) << SORT_KEY_VIEW_SHIFT ) & SORT_KEY_VIEW_MASK; + const uint64_t program = (uint64_t(m_program.idx) << kSortKeyComputeProgramShift) & kSortKeyComputeProgramMask; + const uint64_t seq = (uint64_t(m_seq ) << kSortKeyComputeSeqShift ) & kSortKeyComputeSeqMask; + const uint64_t view = (uint64_t(m_view ) << kSortKeyViewBitShift ) & kSortKeyViewMask; const uint64_t key = program|seq|view; - BX_CHECK(seq == (uint64_t(m_seq) << SORT_KEY_COMPUTE_SEQ_SHIFT) + BX_ASSERT(seq == (uint64_t(m_seq) << kSortKeyComputeSeqShift) , "SortKey error, sequence is truncated (m_seq: %d)." , m_seq ); @@ -1087,39 +1257,42 @@ namespace bgfx /// Returns true if item is compute command. bool decode(uint64_t _key, ViewId _viewRemap[BGFX_CONFIG_MAX_VIEWS]) { - m_view = _viewRemap[(_key & SORT_KEY_VIEW_MASK) >> SORT_KEY_VIEW_SHIFT]; - if (_key & SORT_KEY_DRAW_BIT) + m_view = _viewRemap[(_key & kSortKeyViewMask) >> kSortKeyViewBitShift]; + + if (_key & kSortKeyDrawBit) { - uint64_t type = _key & SORT_KEY_DRAW_TYPE_MASK; - if (type == SORT_KEY_DRAW_TYPE_DEPTH) + uint64_t type = _key & kSortKeyDrawTypeMask; + + if (type == kSortKeyDrawTypeDepth) { - m_program = uint16_t( (_key & SORT_KEY_DRAW_1_PROGRAM_MASK) >> SORT_KEY_DRAW_1_PROGRAM_SHIFT); + m_program.idx = uint16_t( (_key & kSortKeyDraw1ProgramMask) >> kSortKeyDraw1ProgramShift); return false; } - else if (type == SORT_KEY_DRAW_TYPE_SEQUENCE) + + if (type == kSortKeyDrawTypeSequence) { - m_program = uint16_t( (_key & SORT_KEY_DRAW_2_PROGRAM_MASK) >> SORT_KEY_DRAW_2_PROGRAM_SHIFT); + m_program.idx = uint16_t( (_key & kSortKeyDraw2ProgramMask) >> kSortKeyDraw2ProgramShift); return false; } - m_program = uint16_t( (_key & SORT_KEY_DRAW_0_PROGRAM_MASK) >> SORT_KEY_DRAW_0_PROGRAM_SHIFT); + m_program.idx = uint16_t( (_key & kSortKeyDraw0ProgramMask) >> kSortKeyDraw0ProgramShift); return false; // draw } - m_program = uint16_t( (_key & SORT_KEY_COMPUTE_PROGRAM_MASK) >> SORT_KEY_COMPUTE_PROGRAM_SHIFT); + m_program.idx = uint16_t( (_key & kSortKeyComputeProgramMask) >> kSortKeyComputeProgramShift); return true; // compute } static ViewId decodeView(uint64_t _key) { - return ViewId( (_key & SORT_KEY_VIEW_MASK) >> SORT_KEY_VIEW_SHIFT); + return ViewId( (_key & kSortKeyViewMask) >> kSortKeyViewBitShift); } static uint64_t remapView(uint64_t _key, ViewId _viewRemap[BGFX_CONFIG_MAX_VIEWS]) { const ViewId oldView = decodeView(_key); - const uint64_t view = uint64_t(_viewRemap[oldView]) << SORT_KEY_VIEW_SHIFT; - const uint64_t key = (_key & ~SORT_KEY_VIEW_MASK) | view; + const uint64_t view = uint64_t(_viewRemap[oldView]) << kSortKeyViewBitShift; + const uint64_t key = (_key & ~kSortKeyViewMask) | view; return key; } @@ -1127,40 +1300,46 @@ namespace bgfx { m_depth = 0; m_seq = 0; - m_program = 0; + m_program = {0}; m_view = 0; - m_trans = 0; + m_blend = 0; } - uint32_t m_depth; - uint32_t m_seq; - uint16_t m_program; - ViewId m_view; - uint8_t m_trans; + uint32_t m_depth; + uint32_t m_seq; + ProgramHandle m_program; + ViewId m_view; + uint8_t m_blend; }; #undef SORT_KEY_RENDER_DRAW + constexpr uint8_t kBlitKeyViewShift = 32-kSortKeyViewNumBits; + constexpr uint32_t kBlitKeyViewMask = uint32_t(BGFX_CONFIG_MAX_VIEWS-1)<<kBlitKeyViewShift; + constexpr uint8_t kBlitKeyItemShift = 0; + constexpr uint32_t kBlitKeyItemMask = UINT16_MAX; + struct BlitKey { uint32_t encode() { - return 0 - | (uint32_t(m_view) << 24) - | uint32_t(m_item) - ; + const uint32_t view = (uint32_t(m_view) << kBlitKeyViewShift) & kBlitKeyViewMask; + const uint32_t item = (uint32_t(m_item) << kBlitKeyItemShift) & kBlitKeyItemMask; + const uint32_t key = view|item; + + return key; } void decode(uint32_t _key) { - m_item = uint16_t(_key & UINT16_MAX); - m_view = ViewId(_key >> 24); + m_item = uint16_t( (_key & kBlitKeyItemMask) >> kBlitKeyItemShift); + m_view = ViewId( (_key & kBlitKeyViewMask) >> kBlitKeyViewShift); } static uint32_t remapView(uint32_t _key, ViewId _viewRemap[BGFX_CONFIG_MAX_VIEWS]) { - const ViewId oldView = ViewId(_key >> 24); - const uint32_t view = uint32_t(_viewRemap[oldView]) << 24; - const uint32_t key = (_key & ~UINT32_C(0xff000000) ) | view; + const ViewId oldView = ViewId( (_key & kBlitKeyViewMask) >> kBlitKeyViewShift); + const uint32_t view = uint32_t( (_viewRemap[oldView] << kBlitKeyViewShift) & kBlitKeyViewMask); + const uint32_t key = (_key & ~kBlitKeyViewMask) | view; return key; } @@ -1229,7 +1408,7 @@ namespace bgfx float* toPtr(uint32_t _cacheIdx) { - BX_CHECK(_cacheIdx < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" + BX_ASSERT(_cacheIdx < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" , _cacheIdx , BGFX_CONFIG_MAX_MATRIX_CACHE ); @@ -1260,7 +1439,7 @@ namespace bgfx uint32_t add(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) { const uint32_t first = bx::atomicFetchAndAddsat<uint32_t>(&m_num, 1, BGFX_CONFIG_MAX_RECT_CACHE-1); - BX_CHECK(first+1 < BGFX_CONFIG_MAX_RECT_CACHE, "Rect cache overflow. %d (max: %d)", first, BGFX_CONFIG_MAX_RECT_CACHE); + BX_ASSERT(first+1 < BGFX_CONFIG_MAX_RECT_CACHE, "Rect cache overflow. %d (max: %d)", first, BGFX_CONFIG_MAX_RECT_CACHE); Rect& rect = m_cache[first]; @@ -1272,22 +1451,29 @@ namespace bgfx return first; } - Rect m_cache[BGFX_CONFIG_MAX_RECT_CACHE]; + Rect m_cache[BGFX_CONFIG_MAX_RECT_CACHE]; uint32_t m_num; }; -#define CONSTANT_OPCODE_TYPE_SHIFT 27 -#define CONSTANT_OPCODE_TYPE_MASK UINT32_C(0xf8000000) -#define CONSTANT_OPCODE_LOC_SHIFT 11 -#define CONSTANT_OPCODE_LOC_MASK UINT32_C(0x07fff800) -#define CONSTANT_OPCODE_NUM_SHIFT 1 -#define CONSTANT_OPCODE_NUM_MASK UINT32_C(0x000007fe) -#define CONSTANT_OPCODE_COPY_SHIFT 0 -#define CONSTANT_OPCODE_COPY_MASK UINT32_C(0x00000001) - -#define BGFX_UNIFORM_FRAGMENTBIT UINT8_C(0x10) -#define BGFX_UNIFORM_SAMPLERBIT UINT8_C(0x20) -#define BGFX_UNIFORM_MASK (BGFX_UNIFORM_FRAGMENTBIT|BGFX_UNIFORM_SAMPLERBIT) + constexpr uint8_t kConstantOpcodeTypeShift = 27; + constexpr uint32_t kConstantOpcodeTypeMask = UINT32_C(0xf8000000); + constexpr uint8_t kConstantOpcodeLocShift = 11; + constexpr uint32_t kConstantOpcodeLocMask = UINT32_C(0x07fff800); + constexpr uint8_t kConstantOpcodeNumShift = 1; + constexpr uint32_t kConstantOpcodeNumMask = UINT32_C(0x000007fe); + constexpr uint8_t kConstantOpcodeCopyShift = 0; + constexpr uint32_t kConstantOpcodeCopyMask = UINT32_C(0x00000001); + + constexpr uint8_t kUniformFragmentBit = 0x10; + constexpr uint8_t kUniformSamplerBit = 0x20; + constexpr uint8_t kUniformReadOnlyBit = 0x40; + constexpr uint8_t kUniformCompareBit = 0x80; + constexpr uint8_t kUniformMask = 0 + | kUniformFragmentBit + | kUniformSamplerBit + | kUniformReadOnlyBit + | kUniformCompareBit + ; class UniformBuffer { @@ -1296,7 +1482,7 @@ namespace bgfx { const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer); - uint32_t size = BX_ALIGN_16(_size); + uint32_t size = bx::alignUp(_size, 16); void* data = BX_ALLOC(g_allocator, size+structSize); return BX_PLACEMENT_NEW(data, UniformBuffer)(size); } @@ -1307,13 +1493,13 @@ namespace bgfx BX_FREE(g_allocator, _uniformBuffer); } - static void update(UniformBuffer** _uniformBuffer, uint32_t _treshold = 64<<10, uint32_t _grow = 1<<20) + static void update(UniformBuffer** _uniformBuffer, uint32_t _threshold = 64<<10, uint32_t _grow = 1<<20) { UniformBuffer* uniformBuffer = *_uniformBuffer; - if (_treshold >= uniformBuffer->m_size - uniformBuffer->m_pos) + if (_threshold >= uniformBuffer->m_size - uniformBuffer->m_pos) { const uint32_t structSize = sizeof(UniformBuffer)-sizeof(UniformBuffer::m_buffer); - uint32_t size = BX_ALIGN_16(uniformBuffer->m_size + _grow); + uint32_t size = bx::alignUp(uniformBuffer->m_size + _grow, 16); void* data = BX_REALLOC(g_allocator, uniformBuffer, size+structSize); uniformBuffer = reinterpret_cast<UniformBuffer*>(data); uniformBuffer->m_size = size; @@ -1324,19 +1510,19 @@ namespace bgfx static uint32_t encodeOpcode(UniformType::Enum _type, uint16_t _loc, uint16_t _num, uint16_t _copy) { - const uint32_t type = _type << CONSTANT_OPCODE_TYPE_SHIFT; - const uint32_t loc = _loc << CONSTANT_OPCODE_LOC_SHIFT; - const uint32_t num = _num << CONSTANT_OPCODE_NUM_SHIFT; - const uint32_t copy = _copy << CONSTANT_OPCODE_COPY_SHIFT; + const uint32_t type = _type << kConstantOpcodeTypeShift; + const uint32_t loc = _loc << kConstantOpcodeLocShift; + const uint32_t num = _num << kConstantOpcodeNumShift; + const uint32_t copy = _copy << kConstantOpcodeCopyShift; return type|loc|num|copy; } static void decodeOpcode(uint32_t _opcode, UniformType::Enum& _type, uint16_t& _loc, uint16_t& _num, uint16_t& _copy) { - const uint32_t type = (_opcode&CONSTANT_OPCODE_TYPE_MASK) >> CONSTANT_OPCODE_TYPE_SHIFT; - const uint32_t loc = (_opcode&CONSTANT_OPCODE_LOC_MASK ) >> CONSTANT_OPCODE_LOC_SHIFT; - const uint32_t num = (_opcode&CONSTANT_OPCODE_NUM_MASK ) >> CONSTANT_OPCODE_NUM_SHIFT; - const uint32_t copy = (_opcode&CONSTANT_OPCODE_COPY_MASK); // >> CONSTANT_OPCODE_COPY_SHIFT; + const uint32_t type = (_opcode&kConstantOpcodeTypeMask) >> kConstantOpcodeTypeShift; + const uint32_t loc = (_opcode&kConstantOpcodeLocMask ) >> kConstantOpcodeLocShift; + const uint32_t num = (_opcode&kConstantOpcodeNumMask ) >> kConstantOpcodeNumShift; + const uint32_t copy = (_opcode&kConstantOpcodeCopyMask); // >> kConstantOpcodeCopyShift; _type = (UniformType::Enum)(type); _copy = (uint16_t)copy; @@ -1346,7 +1532,7 @@ namespace bgfx void write(const void* _data, uint32_t _size) { - BX_CHECK(m_pos + _size < m_size, "Write would go out of bounds. pos %d + size %d > max size: %d).", m_pos, _size, m_size); + BX_ASSERT(m_pos + _size < m_size, "Write would go out of bounds. pos %d + size %d > max size: %d).", m_pos, _size, m_size); if (m_pos + _size < m_size) { @@ -1362,7 +1548,7 @@ namespace bgfx const char* read(uint32_t _size) { - BX_CHECK(m_pos < m_size, "Out of bounds %d (size: %d).", m_pos, m_size); + BX_ASSERT(m_pos < m_size, "Out of bounds %d (size: %d).", m_pos, m_size); const char* result = &m_buffer[m_pos]; m_pos += _size; return result; @@ -1414,7 +1600,7 @@ namespace bgfx uint32_t m_size; uint32_t m_pos; - char m_buffer[256<<20]; + char m_buffer[256<<20]; }; struct UniformRegInfo @@ -1446,7 +1632,7 @@ namespace bgfx const UniformRegInfo& add(UniformHandle _handle, const char* _name) { - BX_CHECK(isValid(_handle), "Uniform handle is invalid (name: %s)!", _name); + BX_ASSERT(isValid(_handle), "Uniform handle is invalid (name: %s)!", _name); const uint32_t key = bx::hash<bx::HashMurmur2A>(_name); m_uniforms.removeByKey(key); m_uniforms.insert(key, _handle.idx); @@ -1492,26 +1678,29 @@ namespace bgfx { void clear() { - m_startVertex = 0; - m_handle.idx = kInvalidHandle; - m_decl.idx = kInvalidHandle; + m_startVertex = 0; + m_handle.idx = kInvalidHandle; + m_layoutHandle.idx = kInvalidHandle; } uint32_t m_startVertex; VertexBufferHandle m_handle; - VertexDeclHandle m_decl; + VertexLayoutHandle m_layoutHandle; }; BX_ALIGN_DECL_CACHE_LINE(struct) RenderBind { - void clear() + void clear(uint8_t _flags = BGFX_DISCARD_ALL) { - for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii) + if (0 != (_flags & BGFX_DISCARD_BINDINGS) ) { - Binding& bind = m_bind[ii]; - bind.m_idx = kInvalidHandle; - bind.m_type = 0; - bind.m_samplerFlags = 0; + for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii) + { + Binding& bind = m_bind[ii]; + bind.m_idx = kInvalidHandle; + bind.m_type = 0; + bind.m_samplerFlags = 0; + } } }; @@ -1520,32 +1709,59 @@ namespace bgfx BX_ALIGN_DECL_CACHE_LINE(struct) RenderDraw { - void clear() + void clear(uint8_t _flags = BGFX_DISCARD_ALL) { - m_uniformBegin = 0; - m_uniformEnd = 0; - m_stateFlags = BGFX_STATE_DEFAULT; - m_stencil = packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT); - m_rgba = 0; - m_startMatrix = 0; - m_startIndex = 0; - m_numIndices = UINT32_MAX; - m_numVertices = UINT32_MAX; - m_instanceDataOffset = 0; - m_instanceDataStride = 0; - m_numInstances = 1; + if (0 != (_flags & BGFX_DISCARD_STATE) ) + { + m_uniformBegin = 0; + m_uniformEnd = 0; + m_uniformIdx = UINT8_MAX; + + m_stateFlags = BGFX_STATE_DEFAULT; + m_stencil = packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT); + m_rgba = 0; + m_scissor = UINT16_MAX; + } + + if (0 != (_flags & BGFX_DISCARD_TRANSFORM) ) + { + m_startMatrix = 0; + m_numMatrices = 1; + } + + if (0 != (_flags & BGFX_DISCARD_INSTANCE_DATA) ) + { + m_instanceDataOffset = 0; + m_instanceDataStride = 0; + m_numInstances = 1; + m_instanceDataBuffer.idx = kInvalidHandle; + } + + if (0 != (_flags & BGFX_DISCARD_VERTEX_STREAMS) ) + { + m_numVertices = UINT32_MAX; + m_streamMask = 0; + m_stream[0].clear(); + } + + if (0 != (_flags & BGFX_DISCARD_INDEX_BUFFER) ) + { + m_startIndex = 0; + m_numIndices = UINT32_MAX; + m_indexBuffer.idx = kInvalidHandle; + m_submitFlags = 0; + } + else + { + m_submitFlags = isIndex16() ? 0 : BGFX_SUBMIT_INTERNAL_INDEX32; + } + m_startIndirect = 0; - m_numIndirect = UINT16_MAX; - m_numMatrices = 1; - m_submitFlags = BGFX_SUBMIT_EYE_FIRST; - m_scissor = UINT16_MAX; - m_streamMask = 0; - m_stream[0].clear(); - m_indexBuffer.idx = kInvalidHandle; - m_instanceDataBuffer.idx = kInvalidHandle; - m_indirectBuffer.idx = kInvalidHandle; - m_occlusionQuery.idx = kInvalidHandle; - m_uniformIdx = UINT8_MAX; + m_numIndirect = UINT16_MAX; + m_numIndirectIndex = 0; + m_indirectBuffer.idx = kInvalidHandle; + m_numIndirectBuffer.idx = kInvalidHandle; + m_occlusionQuery.idx = kInvalidHandle; } bool setStreamBit(uint8_t _stream, VertexBufferHandle _handle) @@ -1557,6 +1773,11 @@ namespace bgfx return 0 != tmp; } + bool isIndex16() const + { + return 0 == (m_submitFlags & BGFX_SUBMIT_INTERNAL_INDEX32); + } + Stream m_stream[BGFX_CONFIG_MAX_VERTEX_STREAMS]; uint64_t m_stateFlags; uint64_t m_stencil; @@ -1572,6 +1793,7 @@ namespace bgfx uint16_t m_instanceDataStride; uint16_t m_startIndirect; uint16_t m_numIndirect; + uint32_t m_numIndirectIndex; uint16_t m_numMatrices; uint16_t m_scissor; uint8_t m_submitFlags; @@ -1581,23 +1803,31 @@ namespace bgfx IndexBufferHandle m_indexBuffer; VertexBufferHandle m_instanceDataBuffer; IndirectBufferHandle m_indirectBuffer; + IndexBufferHandle m_numIndirectBuffer; OcclusionQueryHandle m_occlusionQuery; }; BX_ALIGN_DECL_CACHE_LINE(struct) RenderCompute { - void clear() + void clear(uint8_t _flags) { - m_uniformBegin = 0; - m_uniformEnd = 0; - m_startMatrix = 0; - m_numX = 0; - m_numY = 0; - m_numZ = 0; - m_numMatrices = 0; - m_submitFlags = BGFX_SUBMIT_EYE_FIRST; - m_uniformIdx = UINT8_MAX; + if (0 != (_flags & BGFX_DISCARD_STATE) ) + { + m_uniformBegin = 0; + m_uniformEnd = 0; + m_uniformIdx = UINT8_MAX; + } + if (0 != (_flags & BGFX_DISCARD_TRANSFORM) ) + { + m_startMatrix = 0; + m_numMatrices = 0; + } + + m_numX = 0; + m_numY = 0; + m_numZ = 0; + m_submitFlags = 0; m_indirectBuffer.idx = kInvalidHandle; m_startIndirect = 0; m_numIndirect = UINT16_MAX; @@ -1637,23 +1867,35 @@ namespace bgfx uint16_t m_depth; uint8_t m_srcMip; uint8_t m_dstMip; - TextureHandle m_src; - TextureHandle m_dst; + Handle m_src; + Handle m_dst; }; struct IndexBuffer { + String m_name; uint32_t m_size; + uint16_t m_flags; }; struct VertexBuffer { + String m_name; uint32_t m_size; uint16_t m_stride; }; struct DynamicIndexBuffer { + void reset() + { + m_handle = BGFX_INVALID_HANDLE; + m_offset = 0; + m_size = 0; + m_startIndex = 0; + m_flags = 0; + } + IndexBufferHandle m_handle; uint32_t m_offset; uint32_t m_size; @@ -1663,16 +1905,145 @@ namespace bgfx struct DynamicVertexBuffer { + void reset() + { + m_handle = BGFX_INVALID_HANDLE; + m_offset = 0; + m_size = 0; + m_startVertex = 0; + m_numVertices = 0; + m_stride = 0; + m_layoutHandle = BGFX_INVALID_HANDLE; + m_flags = 0; + } + VertexBufferHandle m_handle; uint32_t m_offset; uint32_t m_size; uint32_t m_startVertex; uint32_t m_numVertices; uint16_t m_stride; - VertexDeclHandle m_decl; + VertexLayoutHandle m_layoutHandle; uint16_t m_flags; }; + struct ShaderRef + { + UniformHandle* m_uniforms; + String m_name; + uint32_t m_hashIn; + uint32_t m_hashOut; + uint16_t m_num; + int16_t m_refCount; + }; + + struct ProgramRef + { + ShaderHandle m_vsh; + ShaderHandle m_fsh; + int16_t m_refCount; + }; + + struct UniformRef + { + String m_name; + UniformType::Enum m_type; + uint16_t m_num; + int16_t m_refCount; + }; + + struct TextureRef + { + void init( + BackbufferRatio::Enum _ratio + , uint16_t _width + , uint16_t _height + , uint16_t _depth + , TextureFormat::Enum _format + , uint32_t _storageSize + , uint8_t _numMips + , uint16_t _numLayers + , bool _ptrPending + , bool _immutable + , bool _cubeMap + , uint64_t _flags + ) + { + m_ptr = _ptrPending ? (void*)UINTPTR_MAX : NULL; + m_storageSize = _storageSize; + m_refCount = 1; + m_bbRatio = uint8_t(_ratio); + m_width = _width; + m_height = _height; + m_depth = _depth; + m_format = uint8_t(_format); + m_numSamples = 1 << bx::uint32_satsub((_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT, 1); + m_numMips = _numMips; + m_numLayers = _numLayers; + m_owned = false; + m_immutable = _immutable; + m_cubeMap = _cubeMap; + m_flags = _flags; + } + + bool isRt() const + { + return 0 != (m_flags & BGFX_TEXTURE_RT_MASK); + } + + bool isReadBack() const + { + return 0 != (m_flags & BGFX_TEXTURE_READ_BACK); + } + + bool isBlitDst() const + { + return 0 != (m_flags & BGFX_TEXTURE_BLIT_DST); + } + + bool isCubeMap() const + { + return m_cubeMap; + } + + bool is3D() const + { + return 0 < m_depth; + } + + String m_name; + void* m_ptr; + uint64_t m_flags; + uint32_t m_storageSize; + int16_t m_refCount; + uint8_t m_bbRatio; + uint16_t m_width; + uint16_t m_height; + uint16_t m_depth; + uint8_t m_format; + uint8_t m_numSamples; + uint8_t m_numMips; + uint16_t m_numLayers; + bool m_owned; + bool m_immutable; + bool m_cubeMap; + }; + + struct FrameBufferRef + { + String m_name; + uint16_t m_width; + uint16_t m_height; + + union un + { + TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + void* m_nwh; + } un; + + bool m_window; + }; + BX_ALIGN_DECL_CACHE_LINE(struct) View { void reset() @@ -1682,7 +2053,7 @@ namespace bgfx setClear(BGFX_CLEAR_NONE, 0, 0.0f, 0); setMode(ViewMode::Default); setFrameBuffer(BGFX_INVALID_HANDLE); - setTransform(NULL, NULL, BGFX_VIEW_NONE, NULL); + setTransform(NULL, NULL); } void setRect(uint16_t _x, uint16_t _y, uint16_t _width, uint16_t _height) @@ -1721,10 +2092,8 @@ namespace bgfx m_fbh = _handle; } - void setTransform(const void* _view, const void* _proj, uint8_t _flags, const void* _proj1) + void setTransform(const void* _view, const void* _proj) { - m_flags = _flags; - if (NULL != _view) { bx::memCopy(m_view.un.val, _view, sizeof(Matrix4) ); @@ -1736,20 +2105,11 @@ namespace bgfx if (NULL != _proj) { - bx::memCopy(m_proj[0].un.val, _proj, sizeof(Matrix4) ); - } - else - { - m_proj[0].setIdentity(); - } - - if (NULL != _proj1) - { - bx::memCopy(m_proj[1].un.val, _proj1, sizeof(Matrix4) ); + bx::memCopy(m_proj.un.val, _proj, sizeof(Matrix4) ); } else { - bx::memCopy(m_proj[1].un.val, m_proj[0].un.val, sizeof(Matrix4) ); + m_proj.setIdentity(); } } @@ -1757,10 +2117,9 @@ namespace bgfx Rect m_rect; Rect m_scissor; Matrix4 m_view; - Matrix4 m_proj[2]; + Matrix4 m_proj; FrameBufferHandle m_fbh; uint8_t m_mode; - uint8_t m_flags; }; struct FrameCache @@ -1787,16 +2146,23 @@ namespace bgfx RectCache m_rectCache; }; + struct ScreenShot + { + bx::FilePath filePath; + FrameBufferHandle handle; + }; + BX_ALIGN_DECL_CACHE_LINE(struct) Frame { Frame() : m_waitSubmit(0) , m_waitRender(0) + , m_frameNum(0) , m_capture(false) { SortKey term; term.reset(); - term.m_program = kInvalidHandle; + term.m_program = BGFX_INVALID_HANDLE; m_sortKeys[BGFX_CONFIG_MAX_DRAW_CALLS] = term.encodeDraw(SortKey::SortProgram); m_sortValues[BGFX_CONFIG_MAX_DRAW_CALLS] = BGFX_CONFIG_MAX_DRAW_CALLS; bx::memSet(m_occlusion, 0xff, sizeof(m_occlusion) ); @@ -1808,8 +2174,11 @@ namespace bgfx { } - void create() + void create(uint32_t _minResourceCbSize) { + m_cmdPre.init(_minResourceCbSize); + m_cmdPost.init(_minResourceCbSize); + { const uint32_t num = g_caps.limits.maxEncoders; @@ -1822,7 +2191,7 @@ namespace bgfx } reset(); - start(); + start(0); m_textVideoMem = BX_NEW(g_allocator, TextVideoMem); } @@ -1839,12 +2208,12 @@ namespace bgfx void reset() { - start(); + start(0); finish(); resetFreeHandles(); } - void start() + void start(uint32_t frameNum) { m_perfStats.transientVbUsed = m_vboffset; m_perfStats.transientIbUsed = m_iboffset; @@ -1857,39 +2226,32 @@ namespace bgfx m_cmdPre.start(); m_cmdPost.start(); m_capture = false; + m_numScreenShots = 0; + m_frameNum = frameNum; } void finish() { m_cmdPre.finish(); m_cmdPost.finish(); - -// if (0 < m_numDropped) -// { -// BX_TRACE("Too many draw calls: %d, dropped %d (max: %d)" -// , m_numRenderItems+m_numDropped -// , m_numDropped -// , BGFX_CONFIG_MAX_DRAW_CALLS -// ); -// } } void sort(); - uint32_t getAvailTransientIndexBuffer(uint32_t _num) + uint32_t getAvailTransientIndexBuffer(uint32_t _num, uint16_t _indexSize) { - uint32_t offset = bx::strideAlign(m_iboffset, sizeof(uint16_t) ); - uint32_t iboffset = offset + _num*sizeof(uint16_t); + const uint32_t offset = bx::strideAlign(m_iboffset, _indexSize); + uint32_t iboffset = offset + _num*_indexSize; iboffset = bx::min<uint32_t>(iboffset, g_caps.limits.transientIbSize); - uint32_t num = (iboffset-offset)/sizeof(uint16_t); + const uint32_t num = (iboffset-offset)/_indexSize; return num; } - uint32_t allocTransientIndexBuffer(uint32_t& _num) + uint32_t allocTransientIndexBuffer(uint32_t& _num, uint16_t _indexSize) { - uint32_t offset = bx::strideAlign(m_iboffset, sizeof(uint16_t) ); - uint32_t num = getAvailTransientIndexBuffer(_num); - m_iboffset = offset + num*sizeof(uint16_t); + uint32_t offset = bx::strideAlign(m_iboffset, _indexSize); + uint32_t num = getAvailTransientIndexBuffer(_num, _indexSize); + m_iboffset = offset + num*_indexSize; _num = num; return offset; @@ -1919,9 +2281,9 @@ namespace bgfx return m_freeIndexBuffer.queue(_handle); } - bool free(VertexDeclHandle _handle) + bool free(VertexLayoutHandle _handle) { - return m_freeVertexDecl.queue(_handle); + return m_freeVertexLayout.queue(_handle); } bool free(VertexBufferHandle _handle) @@ -1957,7 +2319,7 @@ namespace bgfx void resetFreeHandles() { m_freeIndexBuffer.reset(); - m_freeVertexDecl.reset(); + m_freeVertexLayout.reset(); m_freeVertexBuffer.reset(); m_freeShader.reset(); m_freeProgram.reset(); @@ -1995,6 +2357,9 @@ namespace bgfx Resolution m_resolution; uint32_t m_debug; + ScreenShot m_screenShot[BGFX_CONFIG_MAX_SCREENSHOTS]; + uint8_t m_numScreenShots; + CommandBuffer m_cmdPre; CommandBuffer m_cmdPost; @@ -2055,7 +2420,7 @@ namespace bgfx }; FreeHandle<IndexBufferHandle, BGFX_CONFIG_MAX_INDEX_BUFFERS> m_freeIndexBuffer; - FreeHandle<VertexDeclHandle, BGFX_CONFIG_MAX_VERTEX_DECLS> m_freeVertexDecl; + FreeHandle<VertexLayoutHandle, BGFX_CONFIG_MAX_VERTEX_LAYOUTS> m_freeVertexLayout; FreeHandle<VertexBufferHandle, BGFX_CONFIG_MAX_VERTEX_BUFFERS> m_freeVertexBuffer; FreeHandle<ShaderHandle, BGFX_CONFIG_MAX_SHADERS> m_freeShader; FreeHandle<ProgramHandle, BGFX_CONFIG_MAX_PROGRAMS> m_freeProgram; @@ -2071,6 +2436,8 @@ namespace bgfx int64_t m_waitSubmit; int64_t m_waitRender; + uint32_t m_frameNum; + bool m_capture; }; @@ -2078,7 +2445,7 @@ namespace bgfx { EncoderImpl() { - discard(); + discard(BGFX_DISCARD_ALL); } void begin(Frame* _frame, uint8_t _idx) @@ -2121,6 +2488,7 @@ namespace bgfx void setMarker(const char* _name) { + UniformBuffer::update(&m_frame->m_uniformBuffer[m_uniformIdx]); UniformBuffer* uniformBuffer = m_frame->m_uniformBuffer[m_uniformIdx]; uniformBuffer->writeMarker(_name); } @@ -2129,7 +2497,7 @@ namespace bgfx { if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) { - BX_CHECK(m_uniformSet.end() == m_uniformSet.find(_handle.idx) + BX_ASSERT(m_uniformSet.end() == m_uniformSet.find(_handle.idx) , "Uniform %d (%s) was already set for this draw call." , _handle.idx , getName(_handle) @@ -2144,12 +2512,30 @@ namespace bgfx void setState(uint64_t _state, uint32_t _rgba) { - uint8_t blend = ( (_state&BGFX_STATE_BLEND_MASK)>>BGFX_STATE_BLEND_SHIFT)&0xff; - uint8_t alphaRef = ( (_state&BGFX_STATE_ALPHA_REF_MASK)>>BGFX_STATE_ALPHA_REF_SHIFT)&0xff; - // transparency sort order table - m_key.m_trans = "\x0\x2\x2\x3\x3\x2\x3\x2\x3\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2"[( (blend)&0xf) + (!!blend)] + !!alphaRef; + const uint8_t blend = ( (_state&BGFX_STATE_BLEND_MASK )>>BGFX_STATE_BLEND_SHIFT )&0xff; + const uint8_t alphaRef = ( (_state&BGFX_STATE_ALPHA_REF_MASK)>>BGFX_STATE_ALPHA_REF_SHIFT)&0xff; + + // Transparency sort order table: + // + // +----------------------------------------- BGFX_STATE_BLEND_ZERO + // | +-------------------------------------- BGFX_STATE_BLEND_ONE + // | | +----------------------------------- BGFX_STATE_BLEND_SRC_COLOR + // | | | +-------------------------------- BGFX_STATE_BLEND_INV_SRC_COLOR + // | | | | +----------------------------- BGFX_STATE_BLEND_SRC_ALPHA + // | | | | | +-------------------------- BGFX_STATE_BLEND_INV_SRC_ALPHA + // | | | | | | +----------------------- BGFX_STATE_BLEND_DST_ALPHA + // | | | | | | | +-------------------- BGFX_STATE_BLEND_INV_DST_ALPHA + // | | | | | | | | +----------------- BGFX_STATE_BLEND_DST_COLOR + // | | | | | | | | | +-------------- BGFX_STATE_BLEND_INV_DST_COLOR + // | | | | | | | | | | +----------- BGFX_STATE_BLEND_SRC_ALPHA_SAT + // | | | | | | | | | | | +-------- BGFX_STATE_BLEND_FACTOR + // | | | | | | | | | | | | +----- BGFX_STATE_BLEND_INV_FACTOR + // | | | | | | | | | | | | | + // x | | | | | | | | | | | | | x x x x x + m_key.m_blend = "\x0\x2\x2\x3\x3\x2\x3\x2\x3\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2"[( (blend)&0xf) + (!!blend)] + !!alphaRef; + m_draw.m_stateFlags = _state; - m_draw.m_rgba = _rgba; + m_draw.m_rgba = _rgba; } void setCondition(OcclusionQueryHandle _handle, bool _visible) @@ -2194,7 +2580,7 @@ namespace bgfx void setTransform(uint32_t _cache, uint16_t _num) { - BX_CHECK(_cache < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" + BX_ASSERT(_cache < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" , _cache , BGFX_CONFIG_MAX_MATRIX_CACHE ); @@ -2202,88 +2588,108 @@ namespace bgfx m_draw.m_numMatrices = uint16_t(bx::min<uint32_t>(_cache+_num, BGFX_CONFIG_MAX_MATRIX_CACHE-1) - _cache); } - void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) + void setIndexBuffer(IndexBufferHandle _handle, const IndexBuffer& _ib, uint32_t _firstIndex, uint32_t _numIndices) { - BX_CHECK(UINT8_MAX != m_draw.m_streamMask, ""); + BX_ASSERT(UINT8_MAX != m_draw.m_streamMask, "bgfx::setVertexCount was already called for this draw call."); m_draw.m_startIndex = _firstIndex; m_draw.m_numIndices = _numIndices; m_draw.m_indexBuffer = _handle; + m_draw.m_submitFlags |= 0 == (_ib.m_flags & BGFX_BUFFER_INDEX32) ? BGFX_SUBMIT_INTERNAL_NONE : BGFX_SUBMIT_INTERNAL_INDEX32; } void setIndexBuffer(const DynamicIndexBuffer& _dib, uint32_t _firstIndex, uint32_t _numIndices) { - BX_CHECK(UINT8_MAX != m_draw.m_streamMask, ""); + BX_ASSERT(UINT8_MAX != m_draw.m_streamMask, "bgfx::setVertexCount was already called for this draw call."); const uint32_t indexSize = 0 == (_dib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; m_draw.m_startIndex = _dib.m_startIndex + _firstIndex; m_draw.m_numIndices = bx::min(_numIndices, _dib.m_size/indexSize); m_draw.m_indexBuffer = _dib.m_handle; + m_draw.m_submitFlags |= 0 == (_dib.m_flags & BGFX_BUFFER_INDEX32) ? BGFX_SUBMIT_INTERNAL_NONE : BGFX_SUBMIT_INTERNAL_INDEX32; } void setIndexBuffer(const TransientIndexBuffer* _tib, uint32_t _firstIndex, uint32_t _numIndices) { - BX_CHECK(UINT8_MAX != m_draw.m_streamMask, ""); - const uint32_t numIndices = bx::min(_numIndices, _tib->size/2); + BX_ASSERT(UINT8_MAX != m_draw.m_streamMask, "bgfx::setVertexCount was already called for this draw call."); + const uint32_t indexSize = _tib->isIndex16 ? 2 : 4; + const uint32_t numIndices = bx::min(_numIndices, _tib->size/indexSize); m_draw.m_indexBuffer = _tib->handle; m_draw.m_startIndex = _tib->startIndex + _firstIndex; m_draw.m_numIndices = numIndices; - m_discard = 0 == numIndices; + m_draw.m_submitFlags |= _tib->isIndex16 ? BGFX_SUBMIT_INTERNAL_NONE : BGFX_SUBMIT_INTERNAL_INDEX32; + m_discard = 0 == numIndices; } - void setVertexBuffer(uint8_t _stream, VertexBufferHandle _handle, uint32_t _startVertex, uint32_t _numVertices) + void setVertexBuffer( + uint8_t _stream + , VertexBufferHandle _handle + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { - BX_CHECK(UINT8_MAX != m_draw.m_streamMask, ""); - BX_CHECK(_stream < BGFX_CONFIG_MAX_VERTEX_STREAMS, "Invalid stream %d (max %d).", _stream, BGFX_CONFIG_MAX_VERTEX_STREAMS); + BX_ASSERT(UINT8_MAX != m_draw.m_streamMask, "bgfx::setVertexCount was already called for this draw call."); + BX_ASSERT(_stream < BGFX_CONFIG_MAX_VERTEX_STREAMS, "Invalid stream %d (max %d).", _stream, BGFX_CONFIG_MAX_VERTEX_STREAMS); if (m_draw.setStreamBit(_stream, _handle) ) { Stream& stream = m_draw.m_stream[_stream]; stream.m_startVertex = _startVertex; stream.m_handle = _handle; - stream.m_decl.idx = kInvalidHandle; + stream.m_layoutHandle = _layoutHandle; m_numVertices[_stream] = _numVertices; } } - void setVertexBuffer(uint8_t _stream, const DynamicVertexBuffer& _dvb, uint32_t _startVertex, uint32_t _numVertices) + void setVertexBuffer( + uint8_t _stream + , const DynamicVertexBuffer& _dvb + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { - BX_CHECK(UINT8_MAX != m_draw.m_streamMask, ""); - BX_CHECK(_stream < BGFX_CONFIG_MAX_VERTEX_STREAMS, "Invalid stream %d (max %d).", _stream, BGFX_CONFIG_MAX_VERTEX_STREAMS); + BX_ASSERT(UINT8_MAX != m_draw.m_streamMask, "bgfx::setVertexCount was already called for this draw call."); + BX_ASSERT(_stream < BGFX_CONFIG_MAX_VERTEX_STREAMS, "Invalid stream %d (max %d).", _stream, BGFX_CONFIG_MAX_VERTEX_STREAMS); if (m_draw.setStreamBit(_stream, _dvb.m_handle) ) { Stream& stream = m_draw.m_stream[_stream]; stream.m_startVertex = _dvb.m_startVertex + _startVertex; stream.m_handle = _dvb.m_handle; - stream.m_decl = _dvb.m_decl; + stream.m_layoutHandle = isValid(_layoutHandle) ? _layoutHandle : _dvb.m_layoutHandle; m_numVertices[_stream] = bx::min(bx::uint32_imax(0, _dvb.m_numVertices - _startVertex), _numVertices) ; } } - void setVertexBuffer(uint8_t _stream, const TransientVertexBuffer* _tvb, uint32_t _startVertex, uint32_t _numVertices) + void setVertexBuffer( + uint8_t _stream + , const TransientVertexBuffer* _tvb + , uint32_t _startVertex + , uint32_t _numVertices + , VertexLayoutHandle _layoutHandle + ) { - BX_CHECK(UINT8_MAX != m_draw.m_streamMask, ""); - BX_CHECK(_stream < BGFX_CONFIG_MAX_VERTEX_STREAMS, "Invalid stream %d (max %d).", _stream, BGFX_CONFIG_MAX_VERTEX_STREAMS); + BX_ASSERT(UINT8_MAX != m_draw.m_streamMask, "bgfx::setVertexCount was already called for this draw call."); + BX_ASSERT(_stream < BGFX_CONFIG_MAX_VERTEX_STREAMS, "Invalid stream %d (max %d).", _stream, BGFX_CONFIG_MAX_VERTEX_STREAMS); if (m_draw.setStreamBit(_stream, _tvb->handle) ) { Stream& stream = m_draw.m_stream[_stream]; stream.m_startVertex = _tvb->startVertex + _startVertex; stream.m_handle = _tvb->handle; - stream.m_decl = _tvb->decl; - m_numVertices[_stream] = - bx::min(bx::uint32_imax(0, _tvb->size/_tvb->stride - _startVertex), _numVertices) - ; + stream.m_layoutHandle = isValid(_layoutHandle) ? _layoutHandle : _tvb->layoutHandle; + m_numVertices[_stream] = bx::min(bx::uint32_imax(0, _tvb->size/_tvb->stride - _startVertex), _numVertices); } } void setVertexCount(uint32_t _numVertices) { - BX_CHECK(0 == m_draw.m_streamMask, "Vertex buffer already set."); + BX_ASSERT(0 == m_draw.m_streamMask, "Vertex buffer already set."); m_draw.m_streamMask = UINT8_MAX; Stream& stream = m_draw.m_stream[0]; - stream.m_startVertex = 0; - stream.m_handle.idx = kInvalidHandle; - stream.m_decl.idx = kInvalidHandle; - m_numVertices[0] = _numVertices; + stream.m_startVertex = 0; + stream.m_handle.idx = kInvalidHandle; + stream.m_layoutHandle.idx = kInvalidHandle; + m_numVertices[0] = _numVertices; } void setInstanceDataBuffer(const InstanceDataBuffer* _idb, uint32_t _start, uint32_t _num) @@ -2306,7 +2712,7 @@ namespace bgfx void setInstanceCount(uint32_t _numInstances) { - BX_CHECK(!isValid(m_draw.m_instanceDataBuffer), "Instance buffer already set."); + BX_ASSERT(!isValid(m_draw.m_instanceDataBuffer), "Instance buffer already set."); m_draw.m_numInstances = _numInstances; } @@ -2323,7 +2729,7 @@ namespace bgfx if (isValid(_sampler) ) { uint32_t stage = _stage; - setUniform(UniformType::Int1, _sampler, &stage, 1); + setUniform(UniformType::Sampler, _sampler, &stage, 1); } } @@ -2357,7 +2763,7 @@ namespace bgfx bind.m_mip = _mip; } - void discard() + void discard(uint8_t _flags) { if (BX_ENABLED(BGFX_CONFIG_DEBUG_UNIFORM) ) { @@ -2365,20 +2771,27 @@ namespace bgfx } m_discard = false; - m_draw.clear(); - m_compute.clear(); - m_bind.clear(); + m_draw.clear(_flags); + m_compute.clear(_flags); + m_bind.clear(_flags); } - void submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, bool _preserveState); + void submit(ViewId _id, ProgramHandle _program, OcclusionQueryHandle _occlusionQuery, uint32_t _depth, uint8_t _flags); - void submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, bool _preserveState) + void submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, uint16_t _num, uint32_t _depth, uint8_t _flags) { m_draw.m_startIndirect = _start; m_draw.m_numIndirect = _num; m_draw.m_indirectBuffer = _indirectHandle; OcclusionQueryHandle handle = BGFX_INVALID_HANDLE; - submit(_id, _program, handle, _depth, _preserveState); + submit(_id, _program, handle, _depth, _flags); + } + + void submit(ViewId _id, ProgramHandle _program, IndirectBufferHandle _indirectHandle, uint16_t _start, IndexBufferHandle _numHandle, uint32_t _numIndex, uint16_t _numMax, uint32_t _depth, uint8_t _flags) + { + m_draw.m_numIndirectIndex = _numIndex; + m_draw.m_numIndirectBuffer = _numHandle; + submit(_id, _program, _indirectHandle, _start, _numMax, _depth, _flags); } void dispatch(ViewId _id, ProgramHandle _handle, uint32_t _ngx, uint32_t _ngy, uint32_t _ngz, uint8_t _flags); @@ -2418,15 +2831,15 @@ namespace bgfx int64_t m_cpuTimeEnd; }; - struct VertexDeclRef + struct VertexLayoutRef { - VertexDeclRef() + VertexLayoutRef() { } void init() { - bx::memSet(m_vertexDeclRef, 0, sizeof(m_vertexDeclRef) ); + bx::memSet(m_refCount, 0, sizeof(m_refCount) ); bx::memSet(m_vertexBufferRef, 0xff, sizeof(m_vertexBufferRef) ); bx::memSet(m_dynamicVertexBufferRef, 0xff, sizeof(m_dynamicVertexBufferRef) ); } @@ -2436,83 +2849,83 @@ namespace bgfx { for (uint16_t ii = 0, num = _handleAlloc.getNumHandles(); ii < num; ++ii) { - VertexDeclHandle handle = { _handleAlloc.getHandleAt(ii) }; - m_vertexDeclRef[handle.idx] = 0; - m_vertexDeclMap.removeByHandle(handle.idx); + VertexLayoutHandle handle = { _handleAlloc.getHandleAt(ii) }; + m_refCount[handle.idx] = 0; + m_vertexLayoutMap.removeByHandle(handle.idx); _handleAlloc.free(handle.idx); } - m_vertexDeclMap.reset(); + m_vertexLayoutMap.reset(); } - VertexDeclHandle find(uint32_t _hash) + VertexLayoutHandle find(uint32_t _hash) { - VertexDeclHandle handle = { m_vertexDeclMap.find(_hash) }; + VertexLayoutHandle handle = { m_vertexLayoutMap.find(_hash) }; return handle; } - void add(VertexDeclHandle _declHandle, uint32_t _hash) + void add(VertexLayoutHandle _layoutHandle, uint32_t _hash) { - m_vertexDeclRef[_declHandle.idx]++; - m_vertexDeclMap.insert(_hash, _declHandle.idx); + m_refCount[_layoutHandle.idx]++; + m_vertexLayoutMap.insert(_hash, _layoutHandle.idx); } - void add(VertexBufferHandle _handle, VertexDeclHandle _declHandle, uint32_t _hash) + void add(VertexBufferHandle _handle, VertexLayoutHandle _layoutHandle, uint32_t _hash) { - BX_CHECK(m_vertexBufferRef[_handle.idx].idx == kInvalidHandle, ""); - m_vertexBufferRef[_handle.idx] = _declHandle; - m_vertexDeclRef[_declHandle.idx]++; - m_vertexDeclMap.insert(_hash, _declHandle.idx); + BX_ASSERT(m_vertexBufferRef[_handle.idx].idx == kInvalidHandle, ""); + m_vertexBufferRef[_handle.idx] = _layoutHandle; + m_refCount[_layoutHandle.idx]++; + m_vertexLayoutMap.insert(_hash, _layoutHandle.idx); } - void add(DynamicVertexBufferHandle _handle, VertexDeclHandle _declHandle, uint32_t _hash) + void add(DynamicVertexBufferHandle _handle, VertexLayoutHandle _layoutHandle, uint32_t _hash) { - BX_CHECK(m_dynamicVertexBufferRef[_handle.idx].idx == kInvalidHandle, ""); - m_dynamicVertexBufferRef[_handle.idx] = _declHandle; - m_vertexDeclRef[_declHandle.idx]++; - m_vertexDeclMap.insert(_hash, _declHandle.idx); + BX_ASSERT(m_dynamicVertexBufferRef[_handle.idx].idx == kInvalidHandle, ""); + m_dynamicVertexBufferRef[_handle.idx] = _layoutHandle; + m_refCount[_layoutHandle.idx]++; + m_vertexLayoutMap.insert(_hash, _layoutHandle.idx); } - VertexDeclHandle release(VertexDeclHandle _declHandle) + VertexLayoutHandle release(VertexLayoutHandle _layoutHandle) { - if (isValid(_declHandle) ) + if (isValid(_layoutHandle) ) { - m_vertexDeclRef[_declHandle.idx]--; + m_refCount[_layoutHandle.idx]--; - if (0 == m_vertexDeclRef[_declHandle.idx]) + if (0 == m_refCount[_layoutHandle.idx]) { - m_vertexDeclMap.removeByHandle(_declHandle.idx); - return _declHandle; + m_vertexLayoutMap.removeByHandle(_layoutHandle.idx); + return _layoutHandle; } } return BGFX_INVALID_HANDLE; } - VertexDeclHandle release(VertexBufferHandle _handle) + VertexLayoutHandle release(VertexBufferHandle _handle) { - VertexDeclHandle declHandle = m_vertexBufferRef[_handle.idx]; - declHandle = release(declHandle); + VertexLayoutHandle layoutHandle = m_vertexBufferRef[_handle.idx]; + layoutHandle = release(layoutHandle); m_vertexBufferRef[_handle.idx].idx = kInvalidHandle; - return declHandle; + return layoutHandle; } - VertexDeclHandle release(DynamicVertexBufferHandle _handle) + VertexLayoutHandle release(DynamicVertexBufferHandle _handle) { - VertexDeclHandle declHandle = m_dynamicVertexBufferRef[_handle.idx]; - declHandle = release(declHandle); + VertexLayoutHandle layoutHandle = m_dynamicVertexBufferRef[_handle.idx]; + layoutHandle = release(layoutHandle); m_dynamicVertexBufferRef[_handle.idx].idx = kInvalidHandle; - return declHandle; + return layoutHandle; } - typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_VERTEX_DECLS*2> VertexDeclMap; - VertexDeclMap m_vertexDeclMap; + typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_VERTEX_LAYOUTS*2> VertexLayoutMap; + VertexLayoutMap m_vertexLayoutMap; - uint16_t m_vertexDeclRef[BGFX_CONFIG_MAX_VERTEX_DECLS]; - VertexDeclHandle m_vertexBufferRef[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; - VertexDeclHandle m_dynamicVertexBufferRef[BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS]; + uint16_t m_refCount[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; + VertexLayoutHandle m_vertexBufferRef[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; + VertexLayoutHandle m_dynamicVertexBufferRef[BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS]; }; // First-fit non-local allocator. @@ -2542,7 +2955,7 @@ namespace bgfx uint64_t remove() { - BX_CHECK(0 == m_used.size(), ""); + BX_ASSERT(0 == m_used.size(), ""); if (0 < m_free.size() ) { @@ -2649,9 +3062,9 @@ namespace bgfx virtual void flip() = 0; virtual void createIndexBuffer(IndexBufferHandle _handle, const Memory* _mem, uint16_t _flags) = 0; virtual void destroyIndexBuffer(IndexBufferHandle _handle) = 0; - virtual void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) = 0; - virtual void destroyVertexDecl(VertexDeclHandle _handle) = 0; - virtual void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) = 0; + virtual void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) = 0; + virtual void destroyVertexLayout(VertexLayoutHandle _handle) = 0; + virtual void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t _flags) = 0; virtual void destroyVertexBuffer(VertexBufferHandle _handle) = 0; virtual void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) = 0; virtual void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) = 0; @@ -2680,9 +3093,9 @@ namespace bgfx virtual void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) = 0; virtual void updateViewName(ViewId _id, const char* _name) = 0; virtual void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) = 0; - virtual void setMarker(const char* _marker, uint32_t _size) = 0; virtual void invalidateOcclusionQuery(OcclusionQueryHandle _handle) = 0; - virtual void setName(Handle _handle, const char* _name) = 0; + virtual void setMarker(const char* _marker, uint16_t _len) = 0; + virtual void setName(Handle _handle, const char* _name, uint16_t _len) = 0; virtual void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) = 0; virtual void blitSetup(TextVideoMemBlitter& _blitter) = 0; virtual void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) = 0; @@ -2702,6 +3115,8 @@ namespace bgfx struct Context { + static constexpr uint32_t kAlignment = 64; + Context() : m_render(&m_frame[0]) , m_submit(&m_frame[BGFX_CONFIG_MULTITHREADED ? 1 : 0]) @@ -2714,8 +3129,6 @@ namespace bgfx , m_rtMemoryUsed(0) , m_textureMemoryUsed(0) , m_renderCtx(NULL) - , m_renderMain(NULL) - , m_renderNoop(NULL) , m_rendererInitialized(false) , m_exit(false) , m_flipAfterRender(false) @@ -2727,6 +3140,7 @@ namespace bgfx { } +#if BX_CONFIG_SUPPORTS_THREADING static int32_t renderThread(bx::Thread* /*_self*/, void* /*_userData*/) { BX_TRACE("render thread start"); @@ -2735,6 +3149,7 @@ namespace bgfx BX_TRACE("render thread exit"); return bx::kExitSuccess; } +#endif // game thread bool init(const Init& _init); @@ -2750,6 +3165,37 @@ namespace bgfx BGFX_API_FUNC(void reset(uint32_t _width, uint32_t _height, uint32_t _flags, TextureFormat::Enum _format) ) { + const TextureFormat::Enum format = TextureFormat::Count != _format ? _format : m_init.resolution.format; + + if (!g_platformDataChangedSinceReset + && m_init.resolution.format == format + && m_init.resolution.width == _width + && m_init.resolution.height == _height + && m_init.resolution.reset == _flags) + { + // Nothing changed, ignore request. + return; + } + + const uint32_t maskFlags = ~(0 + | (0 != (g_caps.supported & BGFX_CAPS_TRANSPARENT_BACKBUFFER) ? 0 : BGFX_RESET_TRANSPARENT_BACKBUFFER) + | (0 != (g_caps.supported & BGFX_CAPS_HDR10) ? 0 : BGFX_RESET_HDR10) + | (0 != (g_caps.supported & BGFX_CAPS_HIDPI) ? 0 : BGFX_RESET_HIDPI) + ); + const uint32_t oldFlags = _flags; + _flags &= maskFlags; + +#define WARN_RESET_CAPS_FLAGS(_name) \ + BX_WARN( (oldFlags&(BGFX_RESET_##_name) ) == (_flags&(BGFX_RESET_##_name) ) \ + , "Reset flag `BGFX_RESET_" #_name "` will be ignored, because `BGFX_CAPS_" #_name "` is not supported." \ + ) + WARN_RESET_CAPS_FLAGS(TRANSPARENT_BACKBUFFER); + WARN_RESET_CAPS_FLAGS(HDR10); + WARN_RESET_CAPS_FLAGS(HIDPI); + +#undef WARN_RESET_CAPS_FLAGS + BX_UNUSED(oldFlags); + BX_WARN(g_caps.limits.maxTextureSize >= _width && g_caps.limits.maxTextureSize >= _height , "Frame buffer resolution width or height can't be larger than limits.maxTextureSize %d (width %d, height %d)." @@ -2757,13 +3203,14 @@ namespace bgfx , _width , _height ); - m_init.resolution.format = TextureFormat::Count != _format ? _format : m_init.resolution.format; + m_init.resolution.format = format; m_init.resolution.width = bx::clamp(_width, 1u, g_caps.limits.maxTextureSize); m_init.resolution.height = bx::clamp(_height, 1u, g_caps.limits.maxTextureSize); m_init.resolution.reset = 0 | _flags | (g_platformDataChangedSinceReset ? BGFX_RESET_INTERNAL_FORCE : 0) ; + dump(m_init.resolution); g_platformDataChangedSinceReset = false; m_flipAfterRender = !!(_flags & BGFX_RESET_FLIP_AFTER_RENDER); @@ -2776,15 +3223,15 @@ namespace bgfx for (uint16_t ii = 0, num = m_textureHandle.getNumHandles(); ii < num; ++ii) { uint16_t textureIdx = m_textureHandle.getHandleAt(ii); - const TextureRef& textureRef = m_textureRef[textureIdx]; - if (BackbufferRatio::Count != textureRef.m_bbRatio) + const TextureRef& ref = m_textureRef[textureIdx]; + if (BackbufferRatio::Count != ref.m_bbRatio) { TextureHandle handle = { textureIdx }; resizeTexture(handle , uint16_t(m_init.resolution.width) , uint16_t(m_init.resolution.height) - , textureRef.m_numMips - , textureRef.m_numLayers + , ref.m_numMips + , ref.m_numLayers ); m_init.resolution.reset |= BGFX_RESET_INTERNAL_FORCE; } @@ -2841,7 +3288,7 @@ namespace bgfx stats.numTextures = m_textureHandle.getNumHandles(); stats.numUniforms = m_uniformHandle.getNumHandles(); stats.numVertexBuffers = m_vertexBufferHandle.getNumHandles(); - stats.numVertexDecls = m_vertexDeclHandle.getNumHandles(); + stats.numVertexLayouts = m_layoutHandle.getNumHandles(); stats.textureMemoryUsed = m_textureMemoryUsed; stats.rtMemoryUsed = m_rtMemoryUsed; @@ -2859,12 +3306,15 @@ namespace bgfx if (isValid(handle) ) { IndexBuffer& ib = m_indexBuffers[handle.idx]; - ib.m_size = _mem->size; + ib.m_size = _mem->size; + ib.m_flags = _flags; CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateIndexBuffer); cmdbuf.write(handle); cmdbuf.write(_mem); cmdbuf.write(_flags); + + setDebugNameForHandle(handle); } else { @@ -2874,39 +3324,86 @@ namespace bgfx return handle; } + BGFX_API_FUNC(void setName(IndexBufferHandle _handle, const bx::StringView& _name) ) + { + BGFX_MUTEX_SCOPE(m_resourceApiLock); + + BGFX_CHECK_HANDLE("setName", m_indexBufferHandle, _handle); + + IndexBuffer& ref = m_indexBuffers[_handle.idx]; + ref.m_name.set(_name); + + setNameForHandle(_handle, _name); + } + BGFX_API_FUNC(void destroyIndexBuffer(IndexBufferHandle _handle) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); BGFX_CHECK_HANDLE("destroyIndexBuffer", m_indexBufferHandle, _handle); bool ok = m_submit->free(_handle); BX_UNUSED(ok); - BX_CHECK(ok, "Index buffer handle %d is already destroyed!", _handle.idx); + BX_ASSERT(ok, "Index buffer handle %d is already destroyed!", _handle.idx); + + IndexBuffer& ref = m_indexBuffers[_handle.idx]; + ref.m_name.clear(); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyIndexBuffer); cmdbuf.write(_handle); } - VertexDeclHandle findVertexDecl(const VertexDecl& _decl) + VertexLayoutHandle findOrCreateVertexLayout(const VertexLayout& _layout, bool _refCountOnCreation = false) { - VertexDeclHandle declHandle = m_declRef.find(_decl.m_hash); + VertexLayoutHandle layoutHandle = m_vertexLayoutRef.find(_layout.m_hash); - if (!isValid(declHandle) ) + if (isValid(layoutHandle) ) { - declHandle.idx = m_vertexDeclHandle.alloc(); - if (!isValid(declHandle) ) - { - return declHandle; - } + return layoutHandle; + } + + layoutHandle = { m_layoutHandle.alloc() }; + if (!isValid(layoutHandle) ) + { + BX_TRACE("WARNING: Failed to allocate vertex layout handle (BGFX_CONFIG_MAX_VERTEX_LAYOUTS, max: %d).", BGFX_CONFIG_MAX_VERTEX_LAYOUTS); + return BGFX_INVALID_HANDLE; + } - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateVertexDecl); - cmdbuf.write(declHandle); - cmdbuf.write(_decl); + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateVertexLayout); + cmdbuf.write(layoutHandle); + cmdbuf.write(_layout); + + if (_refCountOnCreation) + { + m_vertexLayoutRef.add(layoutHandle, _layout.m_hash); } - return declHandle; + return layoutHandle; } - BGFX_API_FUNC(VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) ) + BGFX_API_FUNC(VertexLayoutHandle createVertexLayout(const VertexLayout& _layout) ) + { + BGFX_MUTEX_SCOPE(m_resourceApiLock); + + VertexLayoutHandle handle = findOrCreateVertexLayout(_layout); + if (!isValid(handle) ) + { + return BGFX_INVALID_HANDLE; + } + + m_vertexLayoutRef.add(handle, _layout.m_hash); + + return handle; + } + + BGFX_API_FUNC(void destroyVertexLayout(VertexLayoutHandle _handle) ) + { + BGFX_MUTEX_SCOPE(m_resourceApiLock); + if (isValid(m_vertexLayoutRef.release(_handle) ) ) + { + m_submit->free(_handle); + } + } + + BGFX_API_FUNC(VertexBufferHandle createVertexBuffer(const Memory* _mem, const VertexLayout& _layout, uint16_t _flags) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); @@ -2914,26 +3411,28 @@ namespace bgfx if (isValid(handle) ) { - VertexDeclHandle declHandle = findVertexDecl(_decl); - if (!isValid(declHandle) ) + VertexLayoutHandle layoutHandle = findOrCreateVertexLayout(_layout); + if (!isValid(layoutHandle) ) { - BX_TRACE("WARNING: Failed to allocate vertex decl handle (BGFX_CONFIG_MAX_VERTEX_DECLS, max: %d).", BGFX_CONFIG_MAX_VERTEX_DECLS); + BX_TRACE("WARNING: Failed to allocate vertex layout handle (BGFX_CONFIG_MAX_VERTEX_LAYOUTS, max: %d).", BGFX_CONFIG_MAX_VERTEX_LAYOUTS); m_vertexBufferHandle.free(handle.idx); return BGFX_INVALID_HANDLE; } - m_declRef.add(handle, declHandle, _decl.m_hash); + m_vertexLayoutRef.add(handle, layoutHandle, _layout.m_hash); VertexBuffer& vb = m_vertexBuffers[handle.idx]; vb.m_size = _mem->size; - vb.m_stride = _decl.m_stride; + vb.m_stride = _layout.m_stride; CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateVertexBuffer); cmdbuf.write(handle); cmdbuf.write(_mem); - cmdbuf.write(declHandle); + cmdbuf.write(layoutHandle); cmdbuf.write(_flags); + setDebugNameForHandle(handle); + return handle; } @@ -2943,13 +3442,28 @@ namespace bgfx return BGFX_INVALID_HANDLE; } + BGFX_API_FUNC(void setName(VertexBufferHandle _handle, const bx::StringView& _name) ) + { + BGFX_MUTEX_SCOPE(m_resourceApiLock); + + BGFX_CHECK_HANDLE("setName", m_vertexBufferHandle, _handle); + + VertexBuffer& ref = m_vertexBuffers[_handle.idx]; + ref.m_name.set(_name); + + setNameForHandle(_handle, _name); + } + BGFX_API_FUNC(void destroyVertexBuffer(VertexBufferHandle _handle) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); BGFX_CHECK_HANDLE("destroyVertexBuffer", m_vertexBufferHandle, _handle); bool ok = m_submit->free(_handle); BX_UNUSED(ok); - BX_CHECK(ok, "Vertex buffer handle %d is already destroyed!", _handle.idx); + BX_ASSERT(ok, "Vertex buffer handle %d is already destroyed!", _handle.idx); + + VertexBuffer& ref = m_vertexBuffers[_handle.idx]; + ref.m_name.clear(); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexBuffer); cmdbuf.write(_handle); @@ -2957,12 +3471,12 @@ namespace bgfx void destroyVertexBufferInternal(VertexBufferHandle _handle) { - VertexDeclHandle declHandle = m_declRef.release(_handle); - if (isValid(declHandle) ) + VertexLayoutHandle layoutHandle = m_vertexLayoutRef.release(_handle); + if (isValid(layoutHandle) ) { - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexDecl); - cmdbuf.write(declHandle); - m_render->free(declHandle); + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexLayout); + cmdbuf.write(layoutHandle); + m_render->free(layoutHandle); } m_vertexBufferHandle.free(_handle.idx); @@ -2974,13 +3488,13 @@ namespace bgfx if (ptr == NonLocalAllocator::kInvalidBlock) { IndexBufferHandle indexBufferHandle = { m_indexBufferHandle.alloc() }; - BX_WARN(isValid(indexBufferHandle), "Failed to allocate index buffer handle."); if (!isValid(indexBufferHandle) ) { + BX_TRACE("Failed to allocate index buffer handle."); return NonLocalAllocator::kInvalidBlock; } - const uint32_t allocSize = bx::max<uint32_t>(BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE, _size); + const uint32_t allocSize = bx::max<uint32_t>(BGFX_CONFIG_DYNAMIC_INDEX_BUFFER_SIZE, bx::alignUp(_size, 1<<20) ); IndexBuffer& ib = m_indexBuffers[indexBufferHandle.idx]; ib.m_size = allocSize; @@ -2997,48 +3511,51 @@ namespace bgfx return ptr; } + uint64_t allocIndexBuffer(uint32_t _size, uint16_t _flags) + { + IndexBufferHandle indexBufferHandle = { m_indexBufferHandle.alloc() }; + if (!isValid(indexBufferHandle) ) + { + BX_TRACE("Failed to allocate index buffer handle."); + return NonLocalAllocator::kInvalidBlock; + } + + IndexBuffer& ib = m_indexBuffers[indexBufferHandle.idx]; + ib.m_size = _size; + + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicIndexBuffer); + cmdbuf.write(indexBufferHandle); + cmdbuf.write(_size); + cmdbuf.write(_flags); + + setDebugNameForHandle(indexBufferHandle, "Dynamic Index Buffer"); + + return uint64_t(indexBufferHandle.idx) << 32; + } + BGFX_API_FUNC(DynamicIndexBufferHandle createDynamicIndexBuffer(uint32_t _num, uint16_t _flags) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); DynamicIndexBufferHandle handle = { m_dynamicIndexBufferHandle.alloc() }; - BX_WARN(isValid(handle), "Failed to allocate dynamic index buffer handle."); if (!isValid(handle) ) { + BX_TRACE("Failed to allocate dynamic index buffer handle."); return handle; } const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; - uint32_t size = BX_ALIGN_16(_num*indexSize); + const uint32_t size = bx::alignUp(_num*indexSize, 16); - uint64_t ptr = 0; - if (0 != (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) ) - { - IndexBufferHandle indexBufferHandle = { m_indexBufferHandle.alloc() }; - if (!isValid(indexBufferHandle) ) - { - m_dynamicIndexBufferHandle.free(handle.idx); - return BGFX_INVALID_HANDLE; - } - - IndexBuffer& ib = m_indexBuffers[indexBufferHandle.idx]; - ib.m_size = size; - - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicIndexBuffer); - cmdbuf.write(indexBufferHandle); - cmdbuf.write(size); - cmdbuf.write(_flags); + const uint64_t ptr = (0 != (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) ) + ? allocIndexBuffer(size, _flags) + : allocDynamicIndexBuffer(size, _flags) + ; - ptr = uint64_t(indexBufferHandle.idx) << 32; - } - else + if (ptr == NonLocalAllocator::kInvalidBlock) { - ptr = allocDynamicIndexBuffer(size, _flags); - if (ptr == NonLocalAllocator::kInvalidBlock) - { - m_dynamicIndexBufferHandle.free(handle.idx); - return BGFX_INVALID_HANDLE; - } + m_dynamicIndexBufferHandle.free(handle.idx); + return BGFX_INVALID_HANDLE; } DynamicIndexBuffer& dib = m_dynamicIndexBuffers[handle.idx]; @@ -3055,7 +3572,7 @@ namespace bgfx { BGFX_MUTEX_SCOPE(m_resourceApiLock); - BX_CHECK(0 == (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE), "Cannot initialize compute buffer from CPU."); + BX_ASSERT(0 == (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE), "Cannot initialize compute buffer from CPU."); const uint32_t indexSize = 0 == (_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; DynamicIndexBufferHandle handle = createDynamicIndexBuffer(_mem->size/indexSize, _flags); @@ -3077,16 +3594,19 @@ namespace bgfx BGFX_CHECK_HANDLE("updateDynamicIndexBuffer", m_dynamicIndexBufferHandle, _handle); DynamicIndexBuffer& dib = m_dynamicIndexBuffers[_handle.idx]; - BX_CHECK(0 == (dib.m_flags & BGFX_BUFFER_COMPUTE_WRITE), "Can't update GPU buffer from CPU."); + BX_ASSERT(0 == (dib.m_flags & BGFX_BUFFER_COMPUTE_WRITE), "Can't update GPU buffer from CPU."); const uint32_t indexSize = 0 == (dib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; if (dib.m_size < _mem->size && 0 != (dib.m_flags & BGFX_BUFFER_ALLOW_RESIZE) ) { - m_dynIndexBufferAllocator.free(uint64_t(dib.m_handle.idx)<<32 | dib.m_offset); - m_dynIndexBufferAllocator.compact(); + destroy(dib); + + const uint64_t ptr = (0 != (dib.m_flags & BGFX_BUFFER_COMPUTE_READ) ) + ? allocIndexBuffer(_mem->size, dib.m_flags) + : allocDynamicIndexBuffer(_mem->size, dib.m_flags) + ; - uint64_t ptr = allocDynamicIndexBuffer(_mem->size, dib.m_flags); dib.m_handle.idx = uint16_t(ptr>>32); dib.m_offset = uint32_t(ptr); dib.m_size = _mem->size; @@ -3098,7 +3618,7 @@ namespace bgfx + bx::min(bx::uint32_satsub(dib.m_size, _startIndex*indexSize), _mem->size) , m_indexBuffers[dib.m_handle.idx].m_size) - offset ; - BX_CHECK(_mem->size <= size, "Truncating dynamic index buffer update (size %d, mem size %d)." + BX_ASSERT(_mem->size <= size, "Truncating dynamic index buffer update (size %d, mem size %d)." , size , _mem->size ); @@ -3118,27 +3638,31 @@ namespace bgfx m_freeDynamicIndexBufferHandle[m_numFreeDynamicIndexBufferHandles++] = _handle; } - void destroyDynamicIndexBufferInternal(DynamicIndexBufferHandle _handle) + void destroy(const DynamicIndexBuffer& _dib) { - DynamicIndexBuffer& dib = m_dynamicIndexBuffers[_handle.idx]; - - if (0 != (dib.m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) ) + if (0 != (_dib.m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE)) { - destroyIndexBuffer(dib.m_handle); + destroyIndexBuffer(_dib.m_handle); } else { - m_dynIndexBufferAllocator.free(uint64_t(dib.m_handle.idx)<<32 | dib.m_offset); - if (m_dynIndexBufferAllocator.compact() ) + m_dynIndexBufferAllocator.free(uint64_t(_dib.m_handle.idx) << 32 | _dib.m_offset); + if (m_dynIndexBufferAllocator.compact()) { - for (uint64_t ptr = m_dynIndexBufferAllocator.remove(); 0 != ptr; ptr = m_dynIndexBufferAllocator.remove() ) + for (uint64_t ptr = m_dynIndexBufferAllocator.remove(); 0 != ptr; ptr = m_dynIndexBufferAllocator.remove()) { - IndexBufferHandle handle = { uint16_t(ptr>>32) }; + IndexBufferHandle handle = { uint16_t(ptr >> 32) }; destroyIndexBuffer(handle); } } } + } + void destroyDynamicIndexBufferInternal(DynamicIndexBufferHandle _handle) + { + DynamicIndexBuffer& dib = m_dynamicIndexBuffers[_handle.idx]; + destroy(dib); + dib.reset(); m_dynamicIndexBufferHandle.free(_handle.idx); } @@ -3148,13 +3672,13 @@ namespace bgfx if (ptr == NonLocalAllocator::kInvalidBlock) { VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() }; - BX_WARN(isValid(vertexBufferHandle), "Failed to allocate dynamic vertex buffer handle."); if (!isValid(vertexBufferHandle) ) { + BX_TRACE("Failed to allocate dynamic vertex buffer handle."); return NonLocalAllocator::kInvalidBlock; } - const uint32_t allocSize = bx::max<uint32_t>(BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE, _size); + const uint32_t allocSize = bx::max<uint32_t>(BGFX_CONFIG_DYNAMIC_VERTEX_BUFFER_SIZE, bx::alignUp(_size, 1<<20) ); VertexBuffer& vb = m_vertexBuffers[vertexBufferHandle.idx]; vb.m_size = allocSize; @@ -3172,14 +3696,38 @@ namespace bgfx return ptr; } - BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexDecl& _decl, uint16_t _flags) ) + uint64_t allocVertexBuffer(uint32_t _size, uint16_t _flags) + { + VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() }; + + if (!isValid(vertexBufferHandle) ) + { + BX_TRACE("WARNING: Failed to allocate vertex buffer handle (BGFX_CONFIG_MAX_VERTEX_BUFFERS, max: %d).", BGFX_CONFIG_MAX_VERTEX_BUFFERS); + return NonLocalAllocator::kInvalidBlock; + } + + VertexBuffer& vb = m_vertexBuffers[vertexBufferHandle.idx]; + vb.m_size = _size; + vb.m_stride = 0; + + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicVertexBuffer); + cmdbuf.write(vertexBufferHandle); + cmdbuf.write(_size); + cmdbuf.write(_flags); + + setDebugNameForHandle(vertexBufferHandle, "Dynamic Vertex Buffer"); + + return uint64_t(vertexBufferHandle.idx)<<32; + } + + BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(uint32_t _num, const VertexLayout& _layout, uint16_t _flags) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - VertexDeclHandle declHandle = findVertexDecl(_decl); - if (!isValid(declHandle) ) + VertexLayoutHandle layoutHandle = findOrCreateVertexLayout(_layout); + if (!isValid(layoutHandle) ) { - BX_TRACE("WARNING: Failed to allocate vertex decl handle (BGFX_CONFIG_MAX_VERTEX_DECLS, max: %d).", BGFX_CONFIG_MAX_VERTEX_DECLS); + BX_TRACE("WARNING: Failed to allocate vertex layout handle (BGFX_CONFIG_MAX_VERTEX_LAYOUTS, max: %d).", BGFX_CONFIG_MAX_VERTEX_LAYOUTS); return BGFX_INVALID_HANDLE; } @@ -3190,60 +3738,39 @@ namespace bgfx return BGFX_INVALID_HANDLE; } - uint32_t size = bx::strideAlign16(_num*_decl.m_stride, _decl.m_stride); + const uint32_t size = bx::strideAlign<16>(_num*_layout.m_stride, _layout.m_stride)+_layout.m_stride; - uint64_t ptr = 0; - if (0 != (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) ) - { - VertexBufferHandle vertexBufferHandle = { m_vertexBufferHandle.alloc() }; - if (!isValid(vertexBufferHandle) ) - { - m_dynamicVertexBufferHandle.free(handle.idx); - BX_TRACE("WARNING: Failed to allocate vertex buffer handle (BGFX_CONFIG_MAX_VERTEX_BUFFERS, max: %d).", BGFX_CONFIG_MAX_VERTEX_BUFFERS); - return BGFX_INVALID_HANDLE; - } - - VertexBuffer& vb = m_vertexBuffers[vertexBufferHandle.idx]; - vb.m_size = size; - vb.m_stride = 0; - - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicVertexBuffer); - cmdbuf.write(vertexBufferHandle); - cmdbuf.write(size); - cmdbuf.write(_flags); + const uint64_t ptr = (0 != (_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) ) + ? allocVertexBuffer(size, _flags) + : allocDynamicVertexBuffer(size, _flags) + ; - ptr = uint64_t(vertexBufferHandle.idx)<<32; - } - else + if (ptr == NonLocalAllocator::kInvalidBlock) { - ptr = allocDynamicVertexBuffer(size, _flags); - if (ptr == NonLocalAllocator::kInvalidBlock) - { - m_dynamicVertexBufferHandle.free(handle.idx); - return BGFX_INVALID_HANDLE; - } + m_dynamicVertexBufferHandle.free(handle.idx); + return BGFX_INVALID_HANDLE; } DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[handle.idx]; - dvb.m_handle.idx = uint16_t(ptr>>32); - dvb.m_offset = uint32_t(ptr); - dvb.m_size = _num * _decl.m_stride; - dvb.m_startVertex = bx::strideAlign(dvb.m_offset, _decl.m_stride)/_decl.m_stride; - dvb.m_numVertices = _num; - dvb.m_stride = _decl.m_stride; - dvb.m_decl = declHandle; - dvb.m_flags = _flags; - m_declRef.add(handle, declHandle, _decl.m_hash); + dvb.m_handle.idx = uint16_t(ptr>>32); + dvb.m_offset = uint32_t(ptr); + dvb.m_size = _num * _layout.m_stride; + dvb.m_startVertex = bx::strideAlign(dvb.m_offset, _layout.m_stride)/_layout.m_stride; + dvb.m_numVertices = _num; + dvb.m_stride = _layout.m_stride; + dvb.m_layoutHandle = layoutHandle; + dvb.m_flags = _flags; + m_vertexLayoutRef.add(handle, layoutHandle, _layout.m_hash); return handle; } - BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexDecl& _decl, uint16_t _flags) ) + BGFX_API_FUNC(DynamicVertexBufferHandle createDynamicVertexBuffer(const Memory* _mem, const VertexLayout& _layout, uint16_t _flags) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - uint32_t numVertices = _mem->size/_decl.m_stride; - DynamicVertexBufferHandle handle = createDynamicVertexBuffer(numVertices, _decl, _flags); + uint32_t numVertices = _mem->size/_layout.m_stride; + DynamicVertexBufferHandle handle = createDynamicVertexBuffer(numVertices, _layout, _flags); if (!isValid(handle) ) { @@ -3263,19 +3790,24 @@ namespace bgfx BGFX_CHECK_HANDLE("updateDynamicVertexBuffer", m_dynamicVertexBufferHandle, _handle); DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[_handle.idx]; - BX_CHECK(0 == (dvb.m_flags & BGFX_BUFFER_COMPUTE_WRITE), "Can't update GPU write buffer from CPU."); + BX_ASSERT(0 == (dvb.m_flags & BGFX_BUFFER_COMPUTE_WRITE), "Can't update GPU write buffer from CPU."); if (dvb.m_size < _mem->size && 0 != (dvb.m_flags & BGFX_BUFFER_ALLOW_RESIZE) ) { - m_dynVertexBufferAllocator.free(uint64_t(dvb.m_handle.idx)<<32 | dvb.m_offset); - m_dynVertexBufferAllocator.compact(); + destroy(dvb); + + const uint32_t size = bx::strideAlign<16>(_mem->size, dvb.m_stride)+dvb.m_stride; + + const uint64_t ptr = (0 != (dvb.m_flags & BGFX_BUFFER_COMPUTE_READ) ) + ? allocVertexBuffer(size, dvb.m_flags) + : allocDynamicVertexBuffer(size, dvb.m_flags) + ; - uint64_t ptr = allocDynamicVertexBuffer(_mem->size, dvb.m_flags); dvb.m_handle.idx = uint16_t(ptr>>32); dvb.m_offset = uint32_t(ptr); - dvb.m_size = _mem->size; - dvb.m_numVertices = dvb.m_size / dvb.m_stride; + dvb.m_size = size; + dvb.m_numVertices = _mem->size / dvb.m_stride; dvb.m_startVertex = bx::strideAlign(dvb.m_offset, dvb.m_stride)/dvb.m_stride; } @@ -3284,7 +3816,7 @@ namespace bgfx + bx::min(bx::uint32_satsub(dvb.m_size, _startVertex*dvb.m_stride), _mem->size) , m_vertexBuffers[dvb.m_handle.idx].m_size) - offset ; - BX_CHECK(_mem->size <= size, "Truncating dynamic vertex buffer update (size %d, mem size %d)." + BX_ASSERT(_mem->size <= size, "Truncating dynamic vertex buffer update (size %d, mem size %d)." , size , _mem->size ); @@ -3305,45 +3837,51 @@ namespace bgfx m_freeDynamicVertexBufferHandle[m_numFreeDynamicVertexBufferHandles++] = _handle; } - void destroyDynamicVertexBufferInternal(DynamicVertexBufferHandle _handle) + void destroy(const DynamicVertexBuffer& _dvb) { - VertexDeclHandle declHandle = m_declRef.release(_handle); - BGFX_CHECK_HANDLE_INVALID_OK("destroyDynamicVertexBufferInternal", m_vertexDeclHandle, declHandle); - - if (isValid(declHandle) ) + if (0 != (_dvb.m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE)) { - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexDecl); - cmdbuf.write(declHandle); - m_render->free(declHandle); - } - - DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[_handle.idx]; - - if (0 != (dvb.m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE) ) - { - destroyVertexBuffer(dvb.m_handle); + destroyVertexBuffer(_dvb.m_handle); } else { - m_dynVertexBufferAllocator.free(uint64_t(dvb.m_handle.idx)<<32 | dvb.m_offset); - if (m_dynVertexBufferAllocator.compact() ) + m_dynVertexBufferAllocator.free(uint64_t(_dvb.m_handle.idx) << 32 | _dvb.m_offset); + if (m_dynVertexBufferAllocator.compact()) { - for (uint64_t ptr = m_dynVertexBufferAllocator.remove(); 0 != ptr; ptr = m_dynVertexBufferAllocator.remove() ) + for (uint64_t ptr = m_dynVertexBufferAllocator.remove(); 0 != ptr; ptr = m_dynVertexBufferAllocator.remove()) { - VertexBufferHandle handle = { uint16_t(ptr>>32) }; + VertexBufferHandle handle = { uint16_t(ptr >> 32) }; destroyVertexBuffer(handle); } } } + } + + void destroyDynamicVertexBufferInternal(DynamicVertexBufferHandle _handle) + { + VertexLayoutHandle layoutHandle = m_vertexLayoutRef.release(_handle); + BGFX_CHECK_HANDLE_INVALID_OK("destroyDynamicVertexBufferInternal", m_layoutHandle, layoutHandle); + + if (isValid(layoutHandle) ) + { + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyVertexLayout); + cmdbuf.write(layoutHandle); + m_render->free(layoutHandle); + } + DynamicVertexBuffer& dvb = m_dynamicVertexBuffers[_handle.idx]; + destroy(dvb); + dvb.reset(); m_dynamicVertexBufferHandle.free(_handle.idx); } - BGFX_API_FUNC(uint32_t getAvailTransientIndexBuffer(uint32_t _num) ) + BGFX_API_FUNC(uint32_t getAvailTransientIndexBuffer(uint32_t _num, bool _index32) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - return m_submit->getAvailTransientIndexBuffer(_num); + const bool isIndex16 = !_index32; + const uint16_t indexSize = isIndex16 ? 2 : 4; + return m_submit->getAvailTransientIndexBuffer(_num, indexSize); } BGFX_API_FUNC(uint32_t getAvailTransientVertexBuffer(uint32_t _num, uint16_t _stride) ) @@ -3367,11 +3905,16 @@ namespace bgfx uint16_t flags = BGFX_BUFFER_NONE; cmdbuf.write(flags); - const uint32_t size = BX_ALIGN_16(sizeof(TransientIndexBuffer) ) + BX_ALIGN_16(_size); + const uint32_t size = 0 + + bx::alignUp<uint32_t>(sizeof(TransientIndexBuffer), 16) + + bx::alignUp(_size, 16) + ; tib = (TransientIndexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16); - tib->data = (uint8_t *)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer) ); + tib->data = (uint8_t *)tib + bx::alignUp(sizeof(TransientIndexBuffer), 16); tib->size = _size; tib->handle = handle; + + setDebugNameForHandle(handle, "Transient Index Buffer"); } return tib; @@ -3386,21 +3929,24 @@ namespace bgfx BX_ALIGNED_FREE(g_allocator, _tib, 16); } - BGFX_API_FUNC(void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num) ) + BGFX_API_FUNC(void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num, bool _index32) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - uint32_t offset = m_submit->allocTransientIndexBuffer(_num); + const bool isIndex16 = !_index32; + const uint16_t indexSize = isIndex16 ? 2 : 4; + const uint32_t offset = m_submit->allocTransientIndexBuffer(_num, indexSize); TransientIndexBuffer& tib = *m_submit->m_transientIb; _tib->data = &tib.data[offset]; - _tib->size = _num * 2; + _tib->size = _num * indexSize; _tib->handle = tib.handle; - _tib->startIndex = bx::strideAlign(offset, 2)/2; + _tib->startIndex = bx::strideAlign(offset, indexSize) / indexSize; + _tib->isIndex16 = isIndex16; } - TransientVertexBuffer* createTransientVertexBuffer(uint32_t _size, const VertexDecl* _decl = NULL) + TransientVertexBuffer* createTransientVertexBuffer(uint32_t _size, const VertexLayout* _layout = NULL) { TransientVertexBuffer* tvb = NULL; @@ -3410,14 +3956,14 @@ namespace bgfx if (isValid(handle) ) { uint16_t stride = 0; - VertexDeclHandle declHandle = BGFX_INVALID_HANDLE; + VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE; - if (NULL != _decl) + if (NULL != _layout) { - declHandle = findVertexDecl(*_decl); - m_declRef.add(handle, declHandle, _decl->m_hash); + layoutHandle = findOrCreateVertexLayout(*_layout); + m_vertexLayoutRef.add(handle, layoutHandle, _layout->m_hash); - stride = _decl->m_stride; + stride = _layout->m_stride; } CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateDynamicVertexBuffer); @@ -3426,14 +3972,19 @@ namespace bgfx uint16_t flags = BGFX_BUFFER_NONE; cmdbuf.write(flags); - const uint32_t size = BX_ALIGN_16(sizeof(TransientVertexBuffer) ) + BX_ALIGN_16(_size); + const uint32_t size = 0 + + bx::alignUp<uint32_t>(sizeof(TransientVertexBuffer), 16) + + bx::alignUp(_size, 16) + ; tvb = (TransientVertexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16); - tvb->data = (uint8_t *)tvb + BX_ALIGN_16(sizeof(TransientVertexBuffer) ); + tvb->data = (uint8_t *)tvb + bx::alignUp(sizeof(TransientVertexBuffer), 16); tvb->size = _size; tvb->startVertex = 0; tvb->stride = stride; tvb->handle = handle; - tvb->decl = declHandle; + tvb->layoutHandle = layoutHandle; + + setDebugNameForHandle(handle, "Transient Vertex Buffer"); } return tvb; @@ -3448,40 +3999,27 @@ namespace bgfx BX_ALIGNED_FREE(g_allocator, _tvb, 16); } - BGFX_API_FUNC(void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl) ) + BGFX_API_FUNC(void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, VertexLayoutHandle _layoutHandle, uint16_t _stride) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - VertexDeclHandle declHandle = m_declRef.find(_decl.m_hash); - - TransientVertexBuffer& dvb = *m_submit->m_transientVb; - - if (!isValid(declHandle) ) - { - VertexDeclHandle temp = { m_vertexDeclHandle.alloc() }; - declHandle = temp; - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateVertexDecl); - cmdbuf.write(declHandle); - cmdbuf.write(_decl); - m_declRef.add(declHandle, _decl.m_hash); - } + const uint32_t offset = m_submit->allocTransientVertexBuffer(_num, _stride); + const TransientVertexBuffer& dvb = *m_submit->m_transientVb; - uint32_t offset = m_submit->allocTransientVertexBuffer(_num, _decl.m_stride); - - _tvb->data = &dvb.data[offset]; - _tvb->size = _num * _decl.m_stride; - _tvb->startVertex = bx::strideAlign(offset, _decl.m_stride)/_decl.m_stride; - _tvb->stride = _decl.m_stride; - _tvb->handle = dvb.handle; - _tvb->decl = declHandle; + _tvb->data = &dvb.data[offset]; + _tvb->size = _num * _stride; + _tvb->startVertex = bx::strideAlign(offset, _stride)/_stride; + _tvb->stride = _stride; + _tvb->handle = dvb.handle; + _tvb->layoutHandle = _layoutHandle; } BGFX_API_FUNC(void allocInstanceDataBuffer(InstanceDataBuffer* _idb, uint32_t _num, uint16_t _stride) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - uint16_t stride = BX_ALIGN_16(_stride); - uint32_t offset = m_submit->allocTransientVertexBuffer(_num, stride); + const uint16_t stride = bx::alignUp(_stride, 16); + const uint32_t offset = m_submit->allocTransientVertexBuffer(_num, stride); TransientVertexBuffer& dvb = *m_submit->m_transientVb; _idb->data = &dvb.data[offset]; @@ -3613,7 +4151,7 @@ namespace bgfx } bool ok = m_shaderHashMap.insert(shaderHash, handle.idx); - BX_CHECK(ok, "Shader already exists!"); BX_UNUSED(ok); + BX_ASSERT(ok, "Shader already exists!"); BX_UNUSED(ok); ShaderRef& sr = m_shaderRef[handle.idx]; sr.m_refCount = 1; @@ -3635,7 +4173,7 @@ namespace bgfx uint8_t type = 0; bx::read(&reader, type, &err); - type &= ~BGFX_UNIFORM_MASK; + type &= ~kUniformMask; uint8_t num; bx::read(&reader, num, &err); @@ -3646,10 +4184,22 @@ namespace bgfx uint16_t regCount; bx::read(&reader, regCount, &err); + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo; + bx::read(&reader, texInfo, &err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(&reader, texFormat, &err); + } + PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name); - if (PredefinedUniform::Count == predefined) + if (PredefinedUniform::Count == predefined && UniformType::End != UniformType::Enum(type) ) { - uniforms[sr.m_num] = createUniform(name, UniformType::Enum(type), regCount); + uniforms[sr.m_num] = createUniform(name, UniformType::Enum(type), num); sr.m_num++; } } @@ -3665,6 +4215,8 @@ namespace bgfx cmdbuf.write(handle); cmdbuf.write(_mem); + setDebugNameForHandle(handle); + return handle; } @@ -3687,14 +4239,28 @@ namespace bgfx return sr.m_num; } - void setName(Handle _handle, const bx::StringView& _name) + void setNameForHandle(Handle _handle, const bx::StringView& _name) { + char tmp[1024]; + uint16_t len = 1+(uint16_t)bx::snprintf(tmp, BX_COUNTOF(tmp) + , "%sH %d: %S" + , _handle.getTypeName().abrvName + , _handle.idx + , &_name + ); + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::SetName); cmdbuf.write(_handle); - uint16_t len = uint16_t(_name.getLength()+1); cmdbuf.write(len); - cmdbuf.write(_name.getPtr(), len-1); - cmdbuf.write('\0'); + cmdbuf.write(tmp, len); + } + + void setDebugNameForHandle(Handle _handle, const bx::StringView& _name = "") + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) + { + setNameForHandle(_handle, _name); + } } BGFX_API_FUNC(void setName(ShaderHandle _handle, const bx::StringView& _name) ) @@ -3706,7 +4272,7 @@ namespace bgfx ShaderRef& sr = m_shaderRef[_handle.idx]; sr.m_name.set(_name); - setName(convert(_handle), _name); + setNameForHandle(_handle, _name); } BGFX_API_FUNC(void destroyShader(ShaderHandle _handle) ) @@ -3742,7 +4308,7 @@ namespace bgfx if (0 == refs) { bool ok = m_submit->free(_handle); BX_UNUSED(ok); - BX_CHECK(ok, "Shader handle %d is already destroyed!", _handle.idx); + BX_ASSERT(ok, "Shader handle %d is already destroyed!", _handle.idx); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyShader); cmdbuf.write(_handle); @@ -3806,7 +4372,7 @@ namespace bgfx const uint32_t key = uint32_t(_fsh.idx<<16)|_vsh.idx; bool ok = m_programHashMap.insert(key, handle.idx); - BX_CHECK(ok, "Program already exists (key: %x, handle: %3d)!", key, handle.idx); BX_UNUSED(ok); + BX_ASSERT(ok, "Program already exists (key: %x, handle: %3d)!", key, handle.idx); BX_UNUSED(ok); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateProgram); cmdbuf.write(handle); @@ -3858,7 +4424,7 @@ namespace bgfx const uint32_t key = uint32_t(_vsh.idx); bool ok = m_programHashMap.insert(key, handle.idx); - BX_CHECK(ok, "Program already exists (key: %x, handle: %3d)!", key, handle.idx); BX_UNUSED(ok); + BX_ASSERT(ok, "Program already exists (key: %x, handle: %3d)!", key, handle.idx); BX_UNUSED(ok); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateProgram); cmdbuf.write(handle); @@ -3893,7 +4459,7 @@ namespace bgfx if (0 == refs) { bool ok = m_submit->free(_handle); BX_UNUSED(ok); - BX_CHECK(ok, "Program handle %d is already destroyed!", _handle.idx); + BX_ASSERT(ok, "Program handle %d is already destroyed!", _handle.idx); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyProgram); cmdbuf.write(_handle); @@ -3939,6 +4505,8 @@ namespace bgfx return BGFX_INVALID_HANDLE; } + _flags |= imageContainer.m_srgb ? BGFX_TEXTURE_SRGB : 0; + TextureHandle handle = { m_textureHandle.alloc() }; BX_WARN(isValid(handle), "Failed to allocate texture handle."); @@ -3951,16 +4519,20 @@ namespace bgfx TextureRef& ref = m_textureRef[handle.idx]; ref.init( _ratio + , uint16_t(imageContainer.m_width) + , uint16_t(imageContainer.m_height) + , uint16_t(imageContainer.m_depth) , _info->format , _info->storageSize , imageContainer.m_numMips , imageContainer.m_numLayers , 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_DIRECT_ACCESS) , _immutable - , 0 != (_flags & BGFX_TEXTURE_RT_MASK) + , imageContainer.m_cubeMap + , _flags ); - if (ref.m_rt) + if (ref.isRt() ) { m_rtMemoryUsed += int64_t(ref.m_storageSize); } @@ -3975,6 +4547,8 @@ namespace bgfx cmdbuf.write(_flags); cmdbuf.write(_skip); + setDebugNameForHandle(handle); + return handle; } @@ -3986,7 +4560,7 @@ namespace bgfx TextureRef& ref = m_textureRef[_handle.idx]; ref.m_name.set(_name); - setName(convert(_handle), _name); + setNameForHandle(_handle, _name); } void setDirectAccessPtr(TextureHandle _handle, void* _ptr) @@ -4026,28 +4600,30 @@ namespace bgfx BGFX_CHECK_HANDLE("readTexture", m_textureHandle, _handle); const TextureRef& ref = m_textureRef[_handle.idx]; - BX_CHECK(_mip < ref.m_numMips, "Invalid mip: %d num mips:", _mip, ref.m_numMips); BX_UNUSED(ref); + BX_ASSERT(ref.isReadBack(), "Can't read from texture which was not created with BGFX_TEXTURE_READ_BACK."); + BX_ASSERT(_mip < ref.m_numMips, "Invalid mip: %d num mips:", _mip, ref.m_numMips); + BX_UNUSED(ref); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::ReadTexture); cmdbuf.write(_handle); cmdbuf.write(_data); cmdbuf.write(_mip); - return m_frames + 2; + return m_submit->m_frameNum + 2; } void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, uint16_t _numLayers) { - const TextureRef& textureRef = m_textureRef[_handle.idx]; - BX_CHECK(BackbufferRatio::Count != textureRef.m_bbRatio, ""); + const TextureRef& ref = m_textureRef[_handle.idx]; + BX_ASSERT(BackbufferRatio::Count != ref.m_bbRatio, ""); - getTextureSizeFromRatio(BackbufferRatio::Enum(textureRef.m_bbRatio), _width, _height); + getTextureSizeFromRatio(BackbufferRatio::Enum(ref.m_bbRatio), _width, _height); _numMips = calcNumMips(1 < _numMips, _width, _height); BX_TRACE("Resize %3d: %4dx%d %s" , _handle.idx , _width , _height - , bimg::getName(bimg::TextureFormat::Enum(textureRef.m_format) ) + , bimg::getName(bimg::TextureFormat::Enum(ref.m_format) ) ); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::ResizeTexture); @@ -4082,7 +4658,7 @@ namespace bgfx { ref.m_name.clear(); - if (ref.m_rt) + if (ref.isRt() ) { m_rtMemoryUsed -= int64_t(ref.m_storageSize); } @@ -4092,7 +4668,7 @@ namespace bgfx } bool ok = m_submit->free(_handle); BX_UNUSED(ok); - BX_CHECK(ok, "Texture handle %d is already destroyed!", _handle.idx); + BX_ASSERT(ok, "Texture handle %d is already destroyed!", _handle.idx); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyTexture); cmdbuf.write(_handle); @@ -4115,8 +4691,8 @@ namespace bgfx { BGFX_MUTEX_SCOPE(m_resourceApiLock); - const TextureRef& textureRef = m_textureRef[_handle.idx]; - if (textureRef.m_immutable) + const TextureRef& ref = m_textureRef[_handle.idx]; + if (ref.m_immutable) { BX_WARN(false, "Can't update immutable texture."); release(_mem); @@ -4139,38 +4715,17 @@ namespace bgfx cmdbuf.write(_mem); } - bool checkFrameBuffer(uint8_t _num, const Attachment* _attachment) const - { - uint8_t color = 0; - uint8_t depth = 0; - - for (uint32_t ii = 0; ii < _num; ++ii) - { - TextureHandle texHandle = _attachment[ii].handle; - if (bimg::isDepth(bimg::TextureFormat::Enum(m_textureRef[texHandle.idx].m_format))) - { - ++depth; - } - else - { - ++color; - } - } - - return color <= g_caps.limits.maxFBAttachments - && depth <= 1 - ; - } - BGFX_API_FUNC(FrameBufferHandle createFrameBuffer(uint8_t _num, const Attachment* _attachment, bool _destroyTextures) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - BX_CHECK(checkFrameBuffer(_num, _attachment) - , "Too many frame buffer attachments (num attachments: %d, max color attachments %d)!" - , _num - , g_caps.limits.maxFBAttachments - ); + bx::ErrorAssert err; + isFrameBufferValid(_num, _attachment, &err); + + if (!err.isOk() ) + { + return BGFX_INVALID_HANDLE; + } FrameBufferHandle handle = { m_frameBufferHandle.alloc() }; BX_WARN(isValid(handle), "Failed to allocate frame buffer handle."); @@ -4182,18 +4737,23 @@ namespace bgfx cmdbuf.write(false); cmdbuf.write(_num); - FrameBufferRef& ref = m_frameBufferRef[handle.idx]; - ref.m_window = false; - bx::memSet(ref.un.m_th, 0xff, sizeof(ref.un.m_th) ); - BackbufferRatio::Enum bbRatio = BackbufferRatio::Enum(m_textureRef[_attachment[0].handle.idx].m_bbRatio); + const TextureRef& firstTexture = m_textureRef[_attachment[0].handle.idx]; + const BackbufferRatio::Enum bbRatio = BackbufferRatio::Enum(firstTexture.m_bbRatio); + + FrameBufferRef& fbr = m_frameBufferRef[handle.idx]; + if (BackbufferRatio::Count == bbRatio) + { + fbr.m_width = bx::max<uint16_t>(firstTexture.m_width >> _attachment[0].mip, 1); + fbr.m_height = bx::max<uint16_t>(firstTexture.m_height >> _attachment[0].mip, 1); + } + + fbr.m_window = false; + bx::memSet(fbr.un.m_th, 0xff, sizeof(fbr.un.m_th) ); + for (uint32_t ii = 0; ii < _num; ++ii) { TextureHandle texHandle = _attachment[ii].handle; - BGFX_CHECK_HANDLE("createFrameBuffer texture handle", m_textureHandle, texHandle); - BX_CHECK(bbRatio == m_textureRef[texHandle.idx].m_bbRatio, "Mismatch in texture back-buffer ratio."); - BX_UNUSED(bbRatio); - - ref.un.m_th[ii] = texHandle; + fbr.un.m_th[ii] = texHandle; textureIncRef(texHandle); } @@ -4229,25 +4789,39 @@ namespace bgfx cmdbuf.write(_format); cmdbuf.write(_depthFormat); - FrameBufferRef& ref = m_frameBufferRef[handle.idx]; - ref.m_window = true; - ref.un.m_nwh = _nwh; + FrameBufferRef& fbr = m_frameBufferRef[handle.idx]; + fbr.m_width = _width; + fbr.m_height = _height; + fbr.m_window = true; + fbr.un.m_nwh = _nwh; } return handle; } + BGFX_API_FUNC(void setName(FrameBufferHandle _handle, const bx::StringView& _name) ) + { + BGFX_MUTEX_SCOPE(m_resourceApiLock); + + BGFX_CHECK_HANDLE("setName", m_frameBufferHandle, _handle); + + FrameBufferRef& fbr = m_frameBufferRef[_handle.idx]; + fbr.m_name.set(_name); + +// setNameForHandle(_handle, _name); + } + BGFX_API_FUNC(TextureHandle getTexture(FrameBufferHandle _handle, uint8_t _attachment) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); BGFX_CHECK_HANDLE("getTexture", m_frameBufferHandle, _handle); - const FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; - if (!ref.m_window) + const FrameBufferRef& fbr = m_frameBufferRef[_handle.idx]; + if (!fbr.m_window) { const uint32_t attachment = bx::min<uint32_t>(_attachment, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); - return ref.un.m_th[attachment]; + return fbr.un.m_th[attachment]; } return BGFX_INVALID_HANDLE; @@ -4259,17 +4833,19 @@ namespace bgfx BGFX_CHECK_HANDLE("destroyFrameBuffer", m_frameBufferHandle, _handle); bool ok = m_submit->free(_handle); BX_UNUSED(ok); - BX_CHECK(ok, "Frame buffer handle %d is already destroyed!", _handle.idx); + BX_ASSERT(ok, "Frame buffer handle %d is already destroyed!", _handle.idx); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::DestroyFrameBuffer); cmdbuf.write(_handle); - FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; - if (!ref.m_window) + FrameBufferRef& fbr = m_frameBufferRef[_handle.idx]; + fbr.m_name.clear(); + + if (!fbr.m_window) { - for (uint32_t ii = 0; ii < BX_COUNTOF(ref.un.m_th); ++ii) + for (uint32_t ii = 0; ii < BX_COUNTOF(fbr.un.m_th); ++ii) { - TextureHandle th = ref.un.m_th[ii]; + TextureHandle th = fbr.un.m_th[ii]; if (isValid(th) ) { textureDecRef(th); @@ -4282,20 +4858,24 @@ namespace bgfx { BGFX_MUTEX_SCOPE(m_resourceApiLock); - if (PredefinedUniform::Count != nameToPredefinedUniformEnum(_name) ) { - BX_TRACE("%s is predefined uniform name.", _name); - return BGFX_INVALID_HANDLE; + bx::ErrorAssert err; + isIdentifierValid(_name, &err); + + if (!err.isOk() ) + { + return BGFX_INVALID_HANDLE; + } } - _num = bx::max<uint16_t>(1, _num); + _num = bx::max<uint16_t>(1, _num); uint16_t idx = m_uniformHashMap.find(bx::hash<bx::HashMurmur2A>(_name) ); if (kInvalidHandle != idx) { UniformHandle handle = { idx }; UniformRef& uniform = m_uniformRef[handle.idx]; - BX_CHECK(uniform.m_type == _type + BX_ASSERT(uniform.m_type == _type , "Uniform type mismatch (type: %d, expected %d)." , _type , uniform.m_type @@ -4310,6 +4890,8 @@ namespace bgfx uniform.m_type = oldsize < newsize ? _type : uniform.m_type; uniform.m_num = bx::max<uint16_t>(uniform.m_num, _num); + BX_TRACE(" Resize uniform (handle %3d) `%s`, num %d", handle.idx, _name, _num); + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateUniform); cmdbuf.write(handle); cmdbuf.write(uniform.m_type); @@ -4331,7 +4913,7 @@ namespace bgfx return BGFX_INVALID_HANDLE; } - BX_TRACE("Creating uniform (handle %3d) %s", handle.idx, _name); + BX_TRACE("Creating uniform (handle %3d) `%s`, num %d", handle.idx, _name, _num); UniformRef& uniform = m_uniformRef[handle.idx]; uniform.m_name.set(_name); @@ -4340,7 +4922,7 @@ namespace bgfx uniform.m_num = _num; bool ok = m_uniformHashMap.insert(bx::hash<bx::HashMurmur2A>(_name), handle.idx); - BX_CHECK(ok, "Uniform already exists (name: %s)!", _name); BX_UNUSED(ok); + BX_ASSERT(ok, "Uniform already exists (name: %s)!", _name); BX_UNUSED(ok); CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateUniform); cmdbuf.write(handle); @@ -4372,13 +4954,13 @@ namespace bgfx BGFX_CHECK_HANDLE("destroyUniform", m_uniformHandle, _handle); UniformRef& uniform = m_uniformRef[_handle.idx]; - BX_CHECK(uniform.m_refCount > 0, "Destroying already destroyed uniform %d.", _handle.idx); + BX_ASSERT(uniform.m_refCount > 0, "Destroying already destroyed uniform %d.", _handle.idx); int32_t refs = --uniform.m_refCount; if (0 == refs) { bool ok = m_submit->free(_handle); BX_UNUSED(ok); - BX_CHECK(ok, "Uniform handle %d is already destroyed!", _handle.idx); + BX_ASSERT(ok, "Uniform handle %d is already destroyed!", _handle.idx); uniform.m_name.clear(); m_uniformHashMap.removeByHandle(_handle.idx); @@ -4442,26 +5024,40 @@ namespace bgfx if (isValid(_handle) ) { - FrameBufferRef& ref = m_frameBufferRef[_handle.idx]; - if (!ref.m_window) + const FrameBufferRef& fbr = m_frameBufferRef[_handle.idx]; + if (!fbr.m_window) { BX_TRACE("requestScreenShot can be done only for window frame buffer handles (handle: %d).", _handle.idx); return; } } - CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RequestScreenShot); - uint16_t len = (uint16_t)bx::strLen(_filePath)+1; - cmdbuf.write(_handle); - cmdbuf.write(len); - cmdbuf.write(_filePath, len); + if (m_submit->m_numScreenShots >= BGFX_CONFIG_MAX_SCREENSHOTS) + { + BX_TRACE("Only %d screenshots can be requested.", BGFX_CONFIG_MAX_SCREENSHOTS); + return; + } + + for (uint8_t ii = 0, num = m_submit->m_numScreenShots; ii < num; ++ii) + { + const ScreenShot& screenShot = m_submit->m_screenShot[ii]; + if (screenShot.handle.idx == _handle.idx) + { + BX_TRACE("Already requested screenshot on handle %d.", _handle.idx); + return; + } + } + + ScreenShot& screenShot = m_submit->m_screenShot[m_submit->m_numScreenShots++]; + screenShot.handle = _handle; + screenShot.filePath.set(_filePath); } BGFX_API_FUNC(void setPaletteColor(uint8_t _index, const float _rgba[4]) ) { BGFX_MUTEX_SCOPE(m_resourceApiLock); - BX_CHECK(_index < BGFX_CONFIG_MAX_COLOR_PALETTE, "Color palette index out of bounds %d (max: %d)." + BX_ASSERT(_index < BGFX_CONFIG_MAX_COLOR_PALETTE, "Color palette index out of bounds %d (max: %d)." , _index , BGFX_CONFIG_MAX_COLOR_PALETTE ); @@ -4492,7 +5088,7 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(ViewId _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) { - BX_CHECK(bx::equal(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) + BX_ASSERT(bx::isEqual(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." , _depth ); @@ -4502,7 +5098,7 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(ViewId _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) ) { - BX_CHECK(bx::equal(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) + BX_ASSERT(bx::isEqual(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." , _depth ); @@ -4521,9 +5117,9 @@ namespace bgfx m_view[_id].setFrameBuffer(_handle); } - BGFX_API_FUNC(void setViewTransform(ViewId _id, const void* _view, const void* _proj, uint8_t _flags, const void* _proj1) ) + BGFX_API_FUNC(void setViewTransform(ViewId _id, const void* _view, const void* _proj) ) { - m_view[_id].setTransform(_view, _proj, _flags, _proj1); + m_view[_id].setTransform(_view, _proj); } BGFX_API_FUNC(void resetView(ViewId _id) ) @@ -4615,7 +5211,7 @@ namespace bgfx BGFX_PROFILER_SCOPE("bgfx/Render thread wait", 0xff2040ff); int64_t start = bx::getHPCounter(); bool ok = m_renderSem.wait(); - BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok); + BX_ASSERT(ok, "Semaphore wait failed."); BX_UNUSED(ok); m_submit->m_waitRender = bx::getHPCounter() - start; m_submit->m_perfStats.waitRender = m_submit->m_waitRender; } @@ -4641,7 +5237,7 @@ namespace bgfx m_encoderHandle->reset(); uint16_t idx = m_encoderHandle->alloc(); - BX_CHECK(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx); + BX_ASSERT(0 == idx, "Internal encoder handle is not 0 (idx %d).", idx); BX_UNUSED(idx); } bx::Semaphore m_renderSem; @@ -4709,7 +5305,7 @@ namespace bgfx bx::HandleAllocT<BGFX_CONFIG_MAX_DYNAMIC_VERTEX_BUFFERS> m_dynamicVertexBufferHandle; bx::HandleAllocT<BGFX_CONFIG_MAX_INDEX_BUFFERS> m_indexBufferHandle; - bx::HandleAllocT<BGFX_CONFIG_MAX_VERTEX_DECLS > m_vertexDeclHandle; + bx::HandleAllocT<BGFX_CONFIG_MAX_VERTEX_LAYOUTS > m_layoutHandle; bx::HandleAllocT<BGFX_CONFIG_MAX_VERTEX_BUFFERS> m_vertexBufferHandle; bx::HandleAllocT<BGFX_CONFIG_MAX_SHADERS> m_shaderHandle; @@ -4719,94 +5315,21 @@ namespace bgfx bx::HandleAllocT<BGFX_CONFIG_MAX_UNIFORMS> m_uniformHandle; bx::HandleAllocT<BGFX_CONFIG_MAX_OCCLUSION_QUERIES> m_occlusionQueryHandle; - struct ShaderRef - { - UniformHandle* m_uniforms; - String m_name; - uint32_t m_hashIn; - uint32_t m_hashOut; - int16_t m_refCount; - uint16_t m_num; - }; - - struct ProgramRef - { - ShaderHandle m_vsh; - ShaderHandle m_fsh; - int16_t m_refCount; - }; - - struct UniformRef - { - String m_name; - UniformType::Enum m_type; - uint16_t m_num; - int16_t m_refCount; - }; - - struct TextureRef - { - void init( - BackbufferRatio::Enum _ratio - , TextureFormat::Enum _format - , uint32_t _storageSize - , uint8_t _numMips - , uint16_t _numLayers - , bool _ptrPending - , bool _immutable - , bool _rt - ) - { - m_ptr = _ptrPending ? (void*)UINTPTR_MAX : NULL; - m_storageSize = _storageSize; - m_refCount = 1; - m_bbRatio = uint8_t(_ratio); - m_format = uint8_t(_format); - m_numMips = _numMips; - m_numLayers = _numLayers; - m_owned = false; - m_immutable = _immutable; - m_rt = _rt; - } - - String m_name; - void* m_ptr; - uint32_t m_storageSize; - int16_t m_refCount; - uint8_t m_bbRatio; - uint8_t m_format; - uint8_t m_numMips; - uint16_t m_numLayers; - bool m_owned; - bool m_immutable; - bool m_rt; - }; - - struct FrameBufferRef - { - union un - { - TextureHandle m_th[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; - void* m_nwh; - } un; - bool m_window; - }; - typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_UNIFORMS*2> UniformHashMap; UniformHashMap m_uniformHashMap; - UniformRef m_uniformRef[BGFX_CONFIG_MAX_UNIFORMS]; + UniformRef m_uniformRef[BGFX_CONFIG_MAX_UNIFORMS]; typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_SHADERS*2> ShaderHashMap; ShaderHashMap m_shaderHashMap; - ShaderRef m_shaderRef[BGFX_CONFIG_MAX_SHADERS]; + ShaderRef m_shaderRef[BGFX_CONFIG_MAX_SHADERS]; typedef bx::HandleHashMapT<BGFX_CONFIG_MAX_PROGRAMS*2> ProgramHashMap; ProgramHashMap m_programHashMap; - ProgramRef m_programRef[BGFX_CONFIG_MAX_PROGRAMS]; + ProgramRef m_programRef[BGFX_CONFIG_MAX_PROGRAMS]; - TextureRef m_textureRef[BGFX_CONFIG_MAX_TEXTURES]; - FrameBufferRef m_frameBufferRef[BGFX_CONFIG_MAX_FRAME_BUFFERS]; - VertexDeclRef m_declRef; + TextureRef m_textureRef[BGFX_CONFIG_MAX_TEXTURES]; + FrameBufferRef m_frameBufferRef[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + VertexLayoutRef m_vertexLayoutRef; ViewId m_viewRemap[BGFX_CONFIG_MAX_VIEWS]; uint32_t m_seq[BGFX_CONFIG_MAX_VIEWS]; @@ -4828,8 +5351,6 @@ namespace bgfx ClearQuad m_clearQuad; RendererContextI* m_renderCtx; - RendererContextI* m_renderMain; - RendererContextI* m_renderNoop; bool m_rendererInitialized; bool m_exit; diff --git a/3rdparty/bgfx/src/bgfx_shader.sh b/3rdparty/bgfx/src/bgfx_shader.sh index ce8761ed10a..dde910ab728 100644 --- a/3rdparty/bgfx/src/bgfx_shader.sh +++ b/3rdparty/bgfx/src/bgfx_shader.sh @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_SHADER_H_HEADER_GUARD @@ -12,7 +12,7 @@ #ifndef __cplusplus -#if BGFX_SHADER_LANGUAGE_HLSL > 3 +#if BGFX_SHADER_LANGUAGE_HLSL > 300 # define BRANCH [branch] # define LOOP [loop] # define UNROLL [unroll] @@ -20,26 +20,29 @@ # define BRANCH # define LOOP # define UNROLL -#endif // BGFX_SHADER_LANGUAGE_HLSL > 3 +#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 -#if BGFX_SHADER_LANGUAGE_HLSL > 3 && BGFX_SHADER_TYPE_FRAGMENT +#if (BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_METAL || BGFX_SHADER_LANGUAGE_SPIRV) && BGFX_SHADER_TYPE_FRAGMENT # define EARLY_DEPTH_STENCIL [earlydepthstencil] #else # define EARLY_DEPTH_STENCIL -#endif // BGFX_SHADER_LANGUAGE_HLSL > 3 && BGFX_SHADER_TYPE_FRAGMENT +#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 && BGFX_SHADER_TYPE_FRAGMENT #if BGFX_SHADER_LANGUAGE_GLSL -# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[]( -# define ARRAY_END() ) +# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[]( +# define ARRAY_END() ) #else -# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = { -# define ARRAY_END() } +# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = { +# define ARRAY_END() } #endif // BGFX_SHADER_LANGUAGE_GLSL -#if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV +#if BGFX_SHADER_LANGUAGE_HLSL \ + || BGFX_SHADER_LANGUAGE_PSSL \ + || BGFX_SHADER_LANGUAGE_SPIRV \ + || BGFX_SHADER_LANGUAGE_METAL # define CONST(_x) static const _x # define dFdx(_x) ddx(_x) -# define dFdy(_y) ddy(-_y) +# define dFdy(_y) ddy(-(_y)) # define inversesqrt(_x) rsqrt(_x) # define fract(_x) frac(_x) @@ -47,26 +50,28 @@ # define bvec3 bool3 # define bvec4 bool4 -# if BGFX_SHADER_LANGUAGE_HLSL > 4 -# define REGISTER(_type, _reg) register(_type[_reg]) +// To be able to patch the uav registers on the DXBC SPDB Chunk (D3D11 renderer) the whitespaces around +// '_type[_reg]' are necessary. This only affects shaders with debug info (i.e., those that have the SPDB Chunk). +# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL +# define REGISTER(_type, _reg) register( _type[_reg] ) # else # define REGISTER(_type, _reg) register(_type ## _reg) # endif // BGFX_SHADER_LANGUAGE_HLSL -# if BGFX_SHADER_LANGUAGE_HLSL > 3 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV -# if BGFX_SHADER_LANGUAGE_HLSL > 4 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV +# if BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL +# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL # define dFdxCoarse(_x) ddx_coarse(_x) # define dFdxFine(_x) ddx_fine(_x) -# define dFdyCoarse(_y) ddy_coarse(-_y) -# define dFdyFine(_y) ddy_fine(-_y) -# endif // BGFX_SHADER_LANGUAGE_HLSL > 4 +# define dFdyCoarse(_y) ddy_coarse(-(_y)) +# define dFdyFine(_y) ddy_fine(-(_y)) +# endif // BGFX_SHADER_LANGUAGE_HLSL > 400 -# if BGFX_SHADER_LANGUAGE_HLSL +# if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL float intBitsToFloat(int _x) { return asfloat(_x); } vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); } vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); } vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); } -# endif // BGFX_SHADER_LANGUAGE_HLSL +# endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL float uintBitsToFloat(uint _x) { return asfloat(_x); } vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); } @@ -128,6 +133,12 @@ struct BgfxSampler2DShadow Texture2D m_texture; }; +struct BgfxSampler2DArrayShadow +{ + SamplerComparisonState m_sampler; + Texture2DArray m_texture; +}; + struct BgfxSampler3D { SamplerState m_sampler; @@ -150,6 +161,12 @@ struct BgfxSamplerCube TextureCube m_texture; }; +struct BgfxSamplerCubeShadow +{ + SamplerComparisonState m_sampler; + TextureCube m_texture; +}; + struct BgfxSampler2DMS { Texture2DMS<vec4> m_texture; @@ -160,11 +177,21 @@ vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord) return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); } +vec4 bgfxTexture2DBias(BgfxSampler2D _sampler, vec2 _coord, float _bias) +{ + return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); +} + vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level) { return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); } +vec4 bgfxTexture2DLodOffset(BgfxSampler2D _sampler, vec2 _coord, float _level, ivec2 _offset) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); +} + vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec3 _coord) { vec2 coord = _coord.xy * rcp(_coord.z); @@ -192,6 +219,11 @@ vec4 bgfxTexture2DArrayLod(BgfxSampler2DArray _sampler, vec3 _coord, float _lod) return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _lod); } +vec4 bgfxTexture2DArrayLodOffset(BgfxSampler2DArray _sampler, vec3 _coord, float _level, ivec2 _offset) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); +} + float bgfxShadow2D(BgfxSampler2DShadow _sampler, vec3 _coord) { return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z); @@ -203,6 +235,11 @@ float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord) return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z); } +vec4 bgfxShadow2DArray(BgfxSampler2DArrayShadow _sampler, vec4 _coord) +{ + return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); +} + vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord) { return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); @@ -232,16 +269,31 @@ vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord) return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); } +vec4 bgfxTextureCubeBias(BgfxSamplerCube _sampler, vec3 _coord, float _bias) +{ + return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); +} + vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level) { return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); } +float bgfxShadowCube(BgfxSamplerCubeShadow _sampler, vec4 _coord) +{ + return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); +} + vec4 bgfxTexelFetch(BgfxSampler2D _sampler, ivec2 _coord, int _lod) { return _sampler.m_texture.Load(ivec3(_coord, _lod) ); } +vec4 bgfxTexelFetchOffset(BgfxSampler2D _sampler, ivec2 _coord, int _lod, ivec2 _offset) +{ + return _sampler.m_texture.Load(ivec3(_coord, _lod), _offset ); +} + vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod) { vec2 result; @@ -249,6 +301,71 @@ vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod) return result; } +vec2 bgfxTextureSize(BgfxISampler2D _sampler, int _lod) +{ + vec2 result; + _sampler.m_texture.GetDimensions(result.x, result.y); + return result; +} + +vec2 bgfxTextureSize(BgfxUSampler2D _sampler, int _lod) +{ + vec2 result; + _sampler.m_texture.GetDimensions(result.x, result.y); + return result; +} + +vec4 bgfxTextureGather0(BgfxSampler2D _sampler, vec2 _coord) +{ + return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord); +} +vec4 bgfxTextureGather1(BgfxSampler2D _sampler, vec2 _coord) +{ + return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord); +} +vec4 bgfxTextureGather2(BgfxSampler2D _sampler, vec2 _coord) +{ + return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord); +} +vec4 bgfxTextureGather3(BgfxSampler2D _sampler, vec2 _coord) +{ + return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord); +} + +vec4 bgfxTextureGatherOffset0(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) +{ + return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord, _offset); +} +vec4 bgfxTextureGatherOffset1(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) +{ + return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord, _offset); +} +vec4 bgfxTextureGatherOffset2(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) +{ + return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord, _offset); +} +vec4 bgfxTextureGatherOffset3(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) +{ + return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord, _offset); +} + +vec4 bgfxTextureGather0(BgfxSampler2DArray _sampler, vec3 _coord) +{ + return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord); +} +vec4 bgfxTextureGather1(BgfxSampler2DArray _sampler, vec3 _coord) +{ + return _sampler.m_texture.GatherGreen(_sampler.m_sampler, _coord); +} +vec4 bgfxTextureGather2(BgfxSampler2DArray _sampler, vec3 _coord) +{ + return _sampler.m_texture.GatherBlue(_sampler.m_sampler, _coord); +} +vec4 bgfxTextureGather3(BgfxSampler2DArray _sampler, vec3 _coord) +{ + return _sampler.m_texture.GatherAlpha(_sampler.m_sampler, _coord); +} + ivec4 bgfxTexelFetch(BgfxISampler2D _sampler, ivec2 _coord, int _lod) { return _sampler.m_texture.Load(ivec3(_coord, _lod) ); @@ -264,6 +381,11 @@ vec4 bgfxTexelFetch(BgfxSampler2DMS _sampler, ivec2 _coord, int _sampleIdx) return _sampler.m_texture.Load(_coord, _sampleIdx); } +vec4 bgfxTexelFetch(BgfxSampler2DArray _sampler, ivec3 _coord, int _lod) +{ + return _sampler.m_texture.Load(ivec4(_coord, _lod) ); +} + vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod) { return _sampler.m_texture.Load(ivec4(_coord, _lod) ); @@ -288,7 +410,9 @@ vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) static BgfxUSampler2D _name = { _name ## Texture } # define sampler2D BgfxSampler2D # define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord) +# define texture2DBias(_sampler, _coord, _bias) bgfxTexture2DBias(_sampler, _coord, _bias) # define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level) +# define texture2DLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DLodOffset(_sampler, _coord, _level, _offset) # define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) # define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) bgfxTexture2DGrad(_sampler, _coord, _dPdx, _dPdy) @@ -299,6 +423,7 @@ vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) # define sampler2DArray BgfxSampler2DArray # define texture2DArray(_sampler, _coord) bgfxTexture2DArray(_sampler, _coord) # define texture2DArrayLod(_sampler, _coord, _lod) bgfxTexture2DArrayLod(_sampler, _coord, _lod) +# define texture2DArrayLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DArrayLodOffset(_sampler, _coord, _level, _offset) # define SAMPLER2DMS(_name, _reg) \ uniform Texture2DMS<vec4> _name ## Texture : REGISTER(t, _reg); \ @@ -313,6 +438,13 @@ vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) # define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) # define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) +# define SAMPLER2DARRAYSHADOW(_name, _reg) \ + uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ + uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ + static BgfxSampler2DArrayShadow _name = { _name ## SamplerComparison, _name ## Texture } +# define sampler2DArrayShadow BgfxSampler2DArrayShadow +# define shadow2DArray(_sampler, _coord) bgfxShadow2DArray(_sampler, _coord) + # define SAMPLER3D(_name, _reg) \ uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ @@ -333,10 +465,21 @@ vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture } # define samplerCube BgfxSamplerCube # define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord) +# define textureCubeBias(_sampler, _coord, _bias) bgfxTextureCubeBias(_sampler, _coord, _bias) # define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level) +# define SAMPLERCUBESHADOW(_name, _reg) \ + uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ + uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ + static BgfxSamplerCubeShadow _name = { _name ## SamplerComparison, _name ## Texture } +# define samplerCubeShadow BgfxSamplerCubeShadow +# define shadowCube(_sampler, _coord) bgfxShadowCube(_sampler, _coord) + # define texelFetch(_sampler, _coord, _lod) bgfxTexelFetch(_sampler, _coord, _lod) +# define texelFetchOffset(_sampler, _coord, _lod, _offset) bgfxTexelFetchOffset(_sampler, _coord, _lod, _offset) # define textureSize(_sampler, _lod) bgfxTextureSize(_sampler, _lod) +# define textureGather(_sampler, _coord, _comp) bgfxTextureGather ## _comp(_sampler, _coord) +# define textureGatherOffset(_sampler, _coord, _offset, _comp) bgfxTextureGatherOffset ## _comp(_sampler, _coord, _offset) # else # define sampler2DShadow sampler2D @@ -391,19 +534,12 @@ float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) # define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : REGISTER(s, _reg) # define textureCube(_sampler, _coord) texCUBE(_sampler, _coord) -# if BGFX_SHADER_LANGUAGE_HLSL == 2 -# define texture2DLod(_sampler, _coord, _level) tex2D(_sampler, (_coord).xy) -# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2D(_sampler, _coord) -# define texture3DLod(_sampler, _coord, _level) tex3D(_sampler, (_coord).xyz) -# define textureCubeLod(_sampler, _coord, _level) texCUBE(_sampler, (_coord).xyz) -# else -# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) -# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2Dgrad(_sampler, _coord, _dPdx, _dPdy) -# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) -# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) -# endif // BGFX_SHADER_LANGUAGE_HLSL == 2 +# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) +# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2Dgrad(_sampler, _coord, _dPdx, _dPdy) +# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) +# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) -# endif // BGFX_SHADER_LANGUAGE_HLSL > 3 +# endif // BGFX_SHADER_LANGUAGE_HLSL > 300 vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); } vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); } @@ -469,6 +605,14 @@ vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); } # define texture2D(_sampler, _coord) texture(_sampler, _coord) # define texture2DArray(_sampler, _coord) texture(_sampler, _coord) # define texture3D(_sampler, _coord) texture(_sampler, _coord) +# define textureCube(_sampler, _coord) texture(_sampler, _coord) +# define texture2DLod(_sampler, _coord, _lod) textureLod(_sampler, _coord, _lod) +# define texture2DLodOffset(_sampler, _coord, _lod, _offset) textureLodOffset(_sampler, _coord, _lod, _offset) +# define texture2DBias(_sampler, _coord, _bias) texture(_sampler, _coord, _bias) +# define textureCubeBias(_sampler, _coord, _bias) texture(_sampler, _coord, _bias) +# else +# define texture2DBias(_sampler, _coord, _bias) texture2D(_sampler, _coord, _bias) +# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias) # endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); } @@ -486,30 +630,57 @@ vec2 vec2_splat(float _x) { return vec2(_x, _x); } vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); } vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); } -#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV +#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); } uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); } uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); } -#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV +#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3) { #if BGFX_SHADER_LANGUAGE_GLSL - return transpose(mat4(_0, _1, _2, _3) ); + return transpose(mat4(_0, _1, _2, _3) ); #else - return mat4(_0, _1, _2, _3); + return mat4(_0, _1, _2, _3); #endif // BGFX_SHADER_LANGUAGE_GLSL } - mat4 mtxFromCols(vec4 _0, vec4 _1, vec4 _2, vec4 _3) { #if BGFX_SHADER_LANGUAGE_GLSL - return mat4(_0, _1, _2, _3); + return mat4(_0, _1, _2, _3); +#else + return transpose(mat4(_0, _1, _2, _3) ); +#endif // BGFX_SHADER_LANGUAGE_GLSL +} +mat3 mtxFromRows(vec3 _0, vec3 _1, vec3 _2) +{ +#if BGFX_SHADER_LANGUAGE_GLSL + return transpose(mat3(_0, _1, _2) ); +#else + return mat3(_0, _1, _2); +#endif // BGFX_SHADER_LANGUAGE_GLSL +} +mat3 mtxFromCols(vec3 _0, vec3 _1, vec3 _2) +{ +#if BGFX_SHADER_LANGUAGE_GLSL + return mat3(_0, _1, _2); #else - return transpose(mat4(_0, _1, _2, _3) ); + return transpose(mat3(_0, _1, _2) ); #endif // BGFX_SHADER_LANGUAGE_GLSL } +#if BGFX_SHADER_LANGUAGE_GLSL +#define mtxFromRows3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) +#define mtxFromRows4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) +#define mtxFromCols3(_0, _1, _2) mat3(_0, _1, _2) +#define mtxFromCols4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) +#else +#define mtxFromRows3(_0, _1, _2) mat3(_0, _1, _2) +#define mtxFromRows4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) +#define mtxFromCols3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) +#define mtxFromCols4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) +#endif // BGFX_SHADER_LANGUAGE_GLSL + uniform vec4 u_viewRect; uniform vec4 u_viewTexel; uniform mat4 u_view; diff --git a/3rdparty/bgfx/src/charset.h b/3rdparty/bgfx/src/charset.h index e9233a32e70..b76f23d1582 100644 --- a/3rdparty/bgfx/src/charset.h +++ b/3rdparty/bgfx/src/charset.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ static const uint8_t vga8x8[256*8] = diff --git a/3rdparty/bgfx/src/config.h b/3rdparty/bgfx/src/config.h index d8a1ab97164..a492f0006c0 100644 --- a/3rdparty/bgfx/src/config.h +++ b/3rdparty/bgfx/src/config.h @@ -1,34 +1,52 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_CONFIG_H_HEADER_GUARD #define BGFX_CONFIG_H_HEADER_GUARD -#include <bx/bx.h> +#include <bx/bx.h> // bx::isPowerOf2 -#ifndef BGFX_CONFIG_DEBUG -# define BGFX_CONFIG_DEBUG 0 -#endif // BGFX_CONFIG_DEBUG +// # Configuration options for bgfx. +// +// Any of `BGFX_CONFIG_*` options that's inside `#ifndef` block can be configured externally +// via compiler options. +// +// When selecting rendering backends select all backends you want to include in the build. -#if !defined(BGFX_CONFIG_RENDERER_DIRECT3D9) \ +#ifndef BX_CONFIG_DEBUG +# error "BX_CONFIG_DEBUG must be defined in build script!" +#endif // BX_CONFIG_DEBUG + +#if !defined(BGFX_CONFIG_RENDERER_AGC) \ + && !defined(BGFX_CONFIG_RENDERER_DIRECT3D9) \ && !defined(BGFX_CONFIG_RENDERER_DIRECT3D11) \ && !defined(BGFX_CONFIG_RENDERER_DIRECT3D12) \ + && !defined(BGFX_CONFIG_RENDERER_GNM) \ && !defined(BGFX_CONFIG_RENDERER_METAL) \ + && !defined(BGFX_CONFIG_RENDERER_NVN) \ && !defined(BGFX_CONFIG_RENDERER_OPENGL) \ && !defined(BGFX_CONFIG_RENDERER_OPENGLES) \ && !defined(BGFX_CONFIG_RENDERER_VULKAN) \ - && !defined(BGFX_CONFIG_RENDERER_GNM) + && !defined(BGFX_CONFIG_RENDERER_WEBGPU) + +# ifndef BGFX_CONFIG_RENDERER_AGC +# define BGFX_CONFIG_RENDERER_AGC (0 \ + || BX_PLATFORM_PS5 \ + ? 1 : 0) +# endif // BGFX_CONFIG_RENDERER_AGC # ifndef BGFX_CONFIG_RENDERER_DIRECT3D9 # define BGFX_CONFIG_RENDERER_DIRECT3D9 (0 \ + || BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \ ? 1 : 0) # endif // BGFX_CONFIG_RENDERER_DIRECT3D9 # ifndef BGFX_CONFIG_RENDERER_DIRECT3D11 # define BGFX_CONFIG_RENDERER_DIRECT3D11 (0 \ + || BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ || BX_PLATFORM_XBOXONE \ @@ -37,37 +55,60 @@ # ifndef BGFX_CONFIG_RENDERER_DIRECT3D12 # define BGFX_CONFIG_RENDERER_DIRECT3D12 (0 \ + || BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \ || BX_PLATFORM_WINRT \ || BX_PLATFORM_XBOXONE \ ? 1 : 0) # endif // BGFX_CONFIG_RENDERER_DIRECT3D12 +# ifndef BGFX_CONFIG_RENDERER_GNM +# define BGFX_CONFIG_RENDERER_GNM (0 \ + || BX_PLATFORM_PS4 \ + ? 1 : 0) +# endif // BGFX_CONFIG_RENDERER_GNM + # ifndef BGFX_CONFIG_RENDERER_METAL # define BGFX_CONFIG_RENDERER_METAL (0 \ || (BX_PLATFORM_IOS && BX_CPU_ARM) \ + || (BX_PLATFORM_IOS && BX_CPU_X86) \ || (BX_PLATFORM_OSX >= 101100) \ ? 1 : 0) # endif // BGFX_CONFIG_RENDERER_METAL +# ifndef BGFX_CONFIG_RENDERER_NVN +# define BGFX_CONFIG_RENDERER_NVN (0 \ + || BX_PLATFORM_NX \ + ? 1 : 0) +# endif // BGFX_CONFIG_RENDERER_NVN + +# ifndef BGFX_CONFIG_RENDERER_OPENGL_MIN_VERSION +# define BGFX_CONFIG_RENDERER_OPENGL_MIN_VERSION 1 +# endif // BGFX_CONFIG_RENDERER_OPENGL_MIN_VERSION + # ifndef BGFX_CONFIG_RENDERER_OPENGL # define BGFX_CONFIG_RENDERER_OPENGL (0 \ || BX_PLATFORM_BSD \ || BX_PLATFORM_LINUX \ || BX_PLATFORM_OSX \ || BX_PLATFORM_WINDOWS \ - ? 1 : 0) + ? BGFX_CONFIG_RENDERER_OPENGL_MIN_VERSION : 0) # endif // BGFX_CONFIG_RENDERER_OPENGL +# ifndef BGFX_CONFIG_RENDERER_OPENGLES_MIN_VERSION +# define BGFX_CONFIG_RENDERER_OPENGLES_MIN_VERSION (0 \ + || BX_PLATFORM_ANDROID \ + ? 30 : 1) +# endif // BGFX_CONFIG_RENDERER_OPENGLES_MIN_VERSION + # ifndef BGFX_CONFIG_RENDERER_OPENGLES # define BGFX_CONFIG_RENDERER_OPENGLES (0 \ || BX_PLATFORM_ANDROID \ || BX_PLATFORM_EMSCRIPTEN \ || BX_PLATFORM_IOS \ || BX_PLATFORM_RPI \ - || BX_PLATFORM_STEAMLINK \ || BX_PLATFORM_NX \ - ? 1 : 0) + ? BGFX_CONFIG_RENDERER_OPENGLES_MIN_VERSION : 0) # endif // BGFX_CONFIG_RENDERER_OPENGLES # ifndef BGFX_CONFIG_RENDERER_VULKAN @@ -76,16 +117,19 @@ || BX_PLATFORM_LINUX \ || BX_PLATFORM_WINDOWS \ || BX_PLATFORM_NX \ + || BX_PLATFORM_OSX \ ? 1 : 0) # endif // BGFX_CONFIG_RENDERER_VULKAN -# ifndef BGFX_CONFIG_RENDERER_GNM -# define BGFX_CONFIG_RENDERER_GNM (0 \ - || BX_PLATFORM_PS4 \ - ? 1 : 0) -# endif // BGFX_CONFIG_RENDERER_GNM +# ifndef BGFX_CONFIG_RENDERER_WEBGPU +# define BGFX_CONFIG_RENDERER_WEBGPU 0 +# endif // BGFX_CONFIG_RENDERER_WEBGPU #else +# ifndef BGFX_CONFIG_RENDERER_AGC +# define BGFX_CONFIG_RENDERER_AGC 0 +# endif // BGFX_CONFIG_RENDERER_AGC + # ifndef BGFX_CONFIG_RENDERER_DIRECT3D9 # define BGFX_CONFIG_RENDERER_DIRECT3D9 0 # endif // BGFX_CONFIG_RENDERER_DIRECT3D9 @@ -98,10 +142,18 @@ # define BGFX_CONFIG_RENDERER_DIRECT3D12 0 # endif // BGFX_CONFIG_RENDERER_DIRECT3D12 +# ifndef BGFX_CONFIG_RENDERER_GNM +# define BGFX_CONFIG_RENDERER_GNM 0 +# endif // BGFX_CONFIG_RENDERER_GNM + # ifndef BGFX_CONFIG_RENDERER_METAL # define BGFX_CONFIG_RENDERER_METAL 0 # endif // BGFX_CONFIG_RENDERER_METAL +# ifndef BGFX_CONFIG_RENDERER_NVN +# define BGFX_CONFIG_RENDERER_NVN 0 +# endif // BGFX_CONFIG_RENDERER_NVN + # ifndef BGFX_CONFIG_RENDERER_OPENGL # define BGFX_CONFIG_RENDERER_OPENGL 0 # endif // BGFX_CONFIG_RENDERER_OPENGL @@ -114,9 +166,9 @@ # define BGFX_CONFIG_RENDERER_VULKAN 0 # endif // BGFX_CONFIG_RENDERER_VULKAN -# ifndef BGFX_CONFIG_RENDERER_GNM -# define BGFX_CONFIG_RENDERER_GNM 0 -# endif // BGFX_CONFIG_RENDERER_GNM +# ifndef BGFX_CONFIG_RENDERER_WEBGPU +# define BGFX_CONFIG_RENDERER_WEBGPU 0 +# endif // BGFX_CONFIG_RENDERER_VULKAN #endif // !defined... #if BGFX_CONFIG_RENDERER_OPENGL && BGFX_CONFIG_RENDERER_OPENGL < 21 @@ -148,21 +200,16 @@ # define BGFX_CONFIG_DEBUG_PERFHUD 0 #endif // BGFX_CONFIG_DEBUG_NVPERFHUD -/// Enable PIX markers. -#ifndef BGFX_CONFIG_DEBUG_PIX -# define BGFX_CONFIG_DEBUG_PIX BGFX_CONFIG_DEBUG -#endif // BGFX_CONFIG_DEBUG_PIX +/// Enable annotation for graphics debuggers. +#ifndef BGFX_CONFIG_DEBUG_ANNOTATION +# define BGFX_CONFIG_DEBUG_ANNOTATION BGFX_CONFIG_DEBUG +#endif // BGFX_CONFIG_DEBUG_ANNOTATION /// Enable DX11 object names. #ifndef BGFX_CONFIG_DEBUG_OBJECT_NAME -# define BGFX_CONFIG_DEBUG_OBJECT_NAME BGFX_CONFIG_DEBUG +# define BGFX_CONFIG_DEBUG_OBJECT_NAME BGFX_CONFIG_DEBUG_ANNOTATION #endif // BGFX_CONFIG_DEBUG_OBJECT_NAME -/// Enable Metal markers. -#ifndef BGFX_CONFIG_DEBUG_MTL -# define BGFX_CONFIG_DEBUG_MTL BGFX_CONFIG_DEBUG -#endif // BGFX_CONFIG_DEBUG_MTL - /// Enable uniform debug checks. #ifndef BGFX_CONFIG_DEBUG_UNIFORM # define BGFX_CONFIG_DEBUG_UNIFORM BGFX_CONFIG_DEBUG @@ -220,9 +267,9 @@ BX_STATIC_ASSERT(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS m # define BGFX_CONFIG_MAX_VIEW_NAME 256 #endif // BGFX_CONFIG_MAX_VIEW_NAME -#ifndef BGFX_CONFIG_MAX_VERTEX_DECLS -# define BGFX_CONFIG_MAX_VERTEX_DECLS 64 -#endif // BGFX_CONFIG_MAX_VERTEX_DECLS +#ifndef BGFX_CONFIG_MAX_VERTEX_LAYOUTS +# define BGFX_CONFIG_MAX_VERTEX_LAYOUTS 64 +#endif // BGFX_CONFIG_MAX_VERTEX_LAYOUTS #ifndef BGFX_CONFIG_MAX_INDEX_BUFFERS # define BGFX_CONFIG_MAX_INDEX_BUFFERS (4<<10) @@ -280,9 +327,9 @@ BX_STATIC_ASSERT(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS m # define BGFX_CONFIG_MAX_OCCLUSION_QUERIES 256 #endif // BGFX_CONFIG_MAX_OCCLUSION_QUERIES -#ifndef BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE -# define BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE (64<<10) -#endif // BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE +#ifndef BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE +# define BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE (64<<10) +#endif // BGFX_CONFIG_MIN_RESOURCE_COMMAND_BUFFER_SIZE #ifndef BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE # define BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE (6<<20) @@ -296,9 +343,9 @@ BX_STATIC_ASSERT(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS m # define BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT 5 #endif // BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT -#ifndef BGFX_CONFIG_MAX_CLEAR_COLOR_PALETTE +#ifndef BGFX_CONFIG_MAX_COLOR_PALETTE # define BGFX_CONFIG_MAX_COLOR_PALETTE 16 -#endif // BGFX_CONFIG_MAX_CLEAR_COLOR_PALETTE +#endif // BGFX_CONFIG_MAX_COLOR_PALETTE #define BGFX_CONFIG_DRAW_INDIRECT_STRIDE 32 @@ -330,4 +377,22 @@ BX_STATIC_ASSERT(bx::isPowerOf2(BGFX_CONFIG_MAX_VIEWS), "BGFX_CONFIG_MAX_VIEWS m # define BGFX_CONFIG_MAX_BACK_BUFFERS 4 #endif // BGFX_CONFIG_MAX_BACK_BUFFERS +#ifndef BGFX_CONFIG_MAX_FRAME_LATENCY +# define BGFX_CONFIG_MAX_FRAME_LATENCY 3 +#endif // BGFX_CONFIG_MAX_FRAME_LATENCY + +#ifndef BGFX_CONFIG_PREFER_DISCRETE_GPU +// On laptops with integrated and discrete GPU, prefer selection of discrete GPU. +// nVidia and AMD, on Windows only. +# define BGFX_CONFIG_PREFER_DISCRETE_GPU BX_PLATFORM_WINDOWS +#endif // BGFX_CONFIG_PREFER_DISCRETE_GPU + +#ifndef BGFX_CONFIG_MAX_SCREENSHOTS +# define BGFX_CONFIG_MAX_SCREENSHOTS 4 +#endif // BGFX_CONFIG_MAX_SCREENSHOTS + +#ifndef BGFX_CONFIG_ENCODER_API_ONLY +# define BGFX_CONFIG_ENCODER_API_ONLY 0 +#endif // BGFX_CONFIG_ENCODER_API_ONLY + #endif // BGFX_CONFIG_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/debug_renderdoc.cpp b/3rdparty/bgfx/src/debug_renderdoc.cpp index c802806e485..1671014ff7a 100644 --- a/3rdparty/bgfx/src/debug_renderdoc.cpp +++ b/3rdparty/bgfx/src/debug_renderdoc.cpp @@ -1,21 +1,27 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" #if BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX # if BX_PLATFORM_WINDOWS +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif // WIN32_LEAN_AND_MEAN +# include <windows.h> # include <psapi.h> # endif // BX_PLATFORM_WINDOWS # include <renderdoc/renderdoc_app.h> namespace bgfx { - bool findModule(const char* _name) + void* findModule(const char* _name) { #if BX_PLATFORM_WINDOWS + // NOTE: there was some reason to do it this way instead of simply calling GetModuleHandleA, + // but not sure what it was. HANDLE process = GetCurrentProcess(); DWORD size; BOOL result = EnumProcessModules(process @@ -45,14 +51,16 @@ namespace bgfx if (0 != result && 0 == bx::strCmpI(_name, moduleName) ) { - return true; + return (void*)modules[ii]; } } } } -#endif // BX_PLATFORM_WINDOWS +#else BX_UNUSED(_name); - return false; +#endif // BX_PLATFORM_WINDOWS + + return NULL; } pRENDERDOC_GetAPI RENDERDOC_GetAPI; @@ -72,13 +80,19 @@ namespace bgfx return NULL; } - void* renderDocDll = bx::dlopen( + // If RenderDoc is already injected in the process then use the already present DLL + void* renderDocDll = findModule("renderdoc.dll"); + if (NULL == renderDocDll) + { + // TODO: try common installation paths before looking in current directory + renderDocDll = bx::dlopen( #if BX_PLATFORM_WINDOWS - "renderdoc.dll" + "renderdoc.dll" #else - "./librenderdoc.so" + "./librenderdoc.so" #endif // BX_PLATFORM_WINDOWS - ); + ); + } if (NULL != renderDocDll) { @@ -89,7 +103,7 @@ namespace bgfx { s_renderDoc->SetCaptureFilePathTemplate(BGFX_CONFIG_RENDERDOC_LOG_FILEPATH); - s_renderDoc->SetFocusToggleKeys(NULL, 0); + s_renderDoc->SetFocusToggleKeys(NULL, 0); RENDERDOC_InputButton captureKeys[] = BGFX_CONFIG_RENDERDOC_CAPTURE_KEYS; s_renderDoc->SetCaptureKeys(captureKeys, BX_COUNTOF(captureKeys) ); diff --git a/3rdparty/bgfx/src/debug_renderdoc.h b/3rdparty/bgfx/src/debug_renderdoc.h index 0c62e777532..0ec59309fe9 100644 --- a/3rdparty/bgfx/src/debug_renderdoc.h +++ b/3rdparty/bgfx/src/debug_renderdoc.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERDOC_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/dxgi.cpp b/3rdparty/bgfx/src/dxgi.cpp index 4f2bc7c0984..649de902190 100644 --- a/3rdparty/bgfx/src/dxgi.cpp +++ b/3rdparty/bgfx/src/dxgi.cpp @@ -1,16 +1,16 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" -#if BGFX_CONFIG_RENDERER_DIRECT3D11 || BGFX_CONFIG_RENDERER_DIRECT3D12 +#if BGFX_CONFIG_RENDERER_DIRECT3D11 || (BGFX_CONFIG_RENDERER_DIRECT3D12 && !BX_PLATFORM_LINUX) #include "dxgi.h" #include "renderer_d3d.h" -#if !BX_PLATFORM_WINDOWS +#if !BX_PLATFORM_WINDOWS && !BX_PLATFORM_LINUX # include <inspectable.h> # if BX_PLATFORM_WINRT # include <windows.ui.xaml.media.dxinterop.h> @@ -122,20 +122,32 @@ namespace bgfx , m_factory(NULL) , m_adapter(NULL) , m_output(NULL) + , m_tearingSupported(false) { } bool Dxgi::init(Caps& _caps) { -#if BX_PLATFORM_WINDOWS - m_dxgiDll = bx::dlopen("dxgi.dll"); +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS + + const char* dxgiDllName = +#if BX_PLATFORM_LINUX + "dxgi.so" +#else + "dxgi.dll" +#endif // BX_PLATFORM_LINUX + ; + m_dxgiDll = bx::dlopen(dxgiDllName); + if (NULL == m_dxgiDll) { - BX_TRACE("Init error: Failed to load dxgi.dll."); + BX_TRACE("Init error: Failed to load %s.", dxgiDllName); return false; } +# if BX_PLATFORM_WINDOWS m_dxgiDebugDll = bx::dlopen("dxgidebug.dll"); + if (NULL != m_dxgiDebugDll) { DXGIGetDebugInterface = (PFN_GET_DEBUG_INTERFACE )bx::dlsym(m_dxgiDebugDll, "DXGIGetDebugInterface"); @@ -160,6 +172,7 @@ namespace bgfx BX_TRACE("Init error: Function CreateDXGIFactory not found."); return false; } +# endif // BX_PLATFORM_WINDOWS #endif // BX_PLATFORM_WINDOWS HRESULT hr = S_OK; @@ -205,10 +218,20 @@ namespace bgfx , desc.SubSysId , desc.Revision ); - BX_TRACE("\tMemory: %" PRIi64 " (video), %" PRIi64 " (system), %" PRIi64 " (shared)" - , desc.DedicatedVideoMemory - , desc.DedicatedSystemMemory - , desc.SharedSystemMemory + + char dedicatedVideo[16]; + bx::prettify(dedicatedVideo, BX_COUNTOF(dedicatedVideo), desc.DedicatedVideoMemory); + + char dedicatedSystem[16]; + bx::prettify(dedicatedSystem, BX_COUNTOF(dedicatedSystem), desc.DedicatedSystemMemory); + + char sharedSystem[16]; + bx::prettify(sharedSystem, BX_COUNTOF(sharedSystem), desc.SharedSystemMemory); + + BX_TRACE("\tMemory: %s (video), %s (system), %s (shared)" + , dedicatedVideo + , dedicatedSystem + , sharedSystem ); _caps.gpu[ii].vendorId = (uint16_t)desc.VendorId; @@ -246,12 +269,12 @@ namespace bgfx { DXGI_OUTPUT_DESC outputDesc; hr = output->GetDesc(&outputDesc); - if (SUCCEEDED(hr)) + if (SUCCEEDED(hr) ) { BX_TRACE("\tOutput #%d", jj); char deviceName[BX_COUNTOF(outputDesc.DeviceName)]; - wcstombs(deviceName, outputDesc.DeviceName, BX_COUNTOF(outputDesc.DeviceName)); + wcstombs(deviceName, outputDesc.DeviceName, BX_COUNTOF(outputDesc.DeviceName) ); BX_TRACE("\t\t DeviceName: %s", deviceName); BX_TRACE("\t\t DesktopCoordinates: %d, %d, %d, %d" , outputDesc.DesktopCoordinates.left @@ -262,7 +285,7 @@ namespace bgfx BX_TRACE("\t\t AttachedToDesktop: %d", outputDesc.AttachedToDesktop); BX_TRACE("\t\t Rotation: %d", outputDesc.Rotation); -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS IDXGIOutput6* output6; hr = output->QueryInterface(IID_IDXGIOutput6, (void**)&output6); if (SUCCEEDED(hr) ) @@ -297,6 +320,7 @@ namespace bgfx } _caps.supported |= hdr10 ? BGFX_CAPS_HDR10 : 0; + _caps.supported |= BX_ENABLED(BX_PLATFORM_WINRT) ? BGFX_CAPS_TRANSPARENT_BACKBUFFER : 0; DX_RELEASE(adapter, adapter == m_adapter ? 1 : 0); } @@ -361,21 +385,35 @@ namespace bgfx DX_RELEASE_I(dxgiDevice); } - static const GUID IID_ID3D12CommandQueue = { 0x0ec870a6, 0x5d7e, 0x4c22, { 0x8c, 0xfc, 0x5b, 0xaa, 0xe0, 0x76, 0x16, 0xed } }; - HRESULT Dxgi::createSwapChain(IUnknown* _device, const SwapChainDesc& _scd, SwapChainI** _swapChain) { HRESULT hr = S_OK; - bool allowTearing = false; + uint32_t scdFlags = _scd.flags; -#if BX_PLATFORM_WINDOWS - if (windowsVersionIs(Condition::GreaterEqual, 0x0604) ) +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS + IDXGIFactory5* factory5; + hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5); + + if (SUCCEEDED(hr) ) { + BOOL allowTearing = false; // BK - CheckFeatureSupport with DXGI_FEATURE_PRESENT_ALLOW_TEARING // will crash on pre Windows 8. Issue #1356. - hr = m_factory->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing) ); + hr = factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing) ); BX_TRACE("Allow tearing is %ssupported.", allowTearing ? "" : "not "); + + scdFlags |= allowTearing ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0; + scdFlags |= false + || _scd.swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL + || _scd.swapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD + ? 0 // DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT + : 0 + ; + + m_tearingSupported = allowTearing; + + DX_RELEASE_I(factory5); } DXGI_SWAP_CHAIN_DESC scd; @@ -393,27 +431,13 @@ namespace bgfx scd.OutputWindow = (HWND)_scd.nwh; scd.Windowed = _scd.windowed; scd.SwapEffect = _scd.swapEffect; - scd.Flags = 0 - | _scd.flags - | (allowTearing ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0) - ; + scd.Flags = scdFlags; hr = m_factory->CreateSwapChain( _device , &scd , reinterpret_cast<IDXGISwapChain**>(_swapChain) ); - - if (SUCCEEDED(hr) ) - { - IDXGIDevice1* dxgiDevice1; - _device->QueryInterface(IID_IDXGIDevice1, (void**)&dxgiDevice1); - if (NULL != dxgiDevice1) - { - dxgiDevice1->SetMaximumFrameLatency(_scd.maxFrameLatency); - DX_RELEASE_I(dxgiDevice1); - } - } #else DXGI_SWAP_CHAIN_DESC1 scd; scd.Width = _scd.width; @@ -427,7 +451,7 @@ namespace bgfx scd.Scaling = _scd.scaling; scd.SwapEffect = _scd.swapEffect; scd.AlphaMode = _scd.alphaMode; - scd.Flags = _scd.flags; + scd.Flags = scdFlags; if (NULL == _scd.ndt) { @@ -457,38 +481,87 @@ namespace bgfx } # if BX_PLATFORM_WINRT - IInspectable *nativeWindow = reinterpret_cast<IInspectable *>(_scd.nwh); - ISwapChainBackgroundPanelNative* panel = NULL; + IInspectable *nativeWindow = reinterpret_cast<IInspectable*>(_scd.nwh); + ISwapChainPanelNative* swapChainPanelNative; + hr = nativeWindow->QueryInterface( - __uuidof(ISwapChainBackgroundPanelNative) - , (void **)&panel + __uuidof(ISwapChainPanelNative) + , (void**)&swapChainPanelNative ); - if (FAILED(hr) ) + + if (!FAILED(hr) ) { - return hr; - } + // Swap Chain Panel + if (NULL != swapChainPanelNative) + { + hr = swapChainPanelNative->SetSwapChain(*_swapChain); + + if (FAILED(hr) ) + { + DX_RELEASE(swapChainPanelNative, 0); + BX_TRACE("Failed to SetSwapChain, hr %x."); + return hr; + } - if (NULL != panel) + DX_RELEASE_I(swapChainPanelNative); + } + } + else { - hr = panel->SetSwapChain(*_swapChain); + // Swap Chain Background Panel + ISwapChainBackgroundPanelNative* swapChainBackgroundPanelNative = NULL; + + hr = nativeWindow->QueryInterface( + __uuidof(ISwapChainBackgroundPanelNative) + , (void**)&swapChainBackgroundPanelNative + ); + if (FAILED(hr) ) { return hr; } - panel->Release(); + if (NULL != swapChainBackgroundPanelNative) + { + hr = swapChainBackgroundPanelNative->SetSwapChain(*_swapChain); + + if (FAILED(hr) ) + { + DX_RELEASE(swapChainBackgroundPanelNative, 0); + BX_TRACE("Failed to SetSwapChain, hr %x."); + return hr; + } + + DX_RELEASE_I(swapChainBackgroundPanelNative); + } } # endif // BX_PLATFORM_WINRT } #endif // BX_PLATFORM_WINDOWS + if (SUCCEEDED(hr) ) + { + IDXGIDevice1* dxgiDevice1; + _device->QueryInterface(IID_IDXGIDevice1, (void**)&dxgiDevice1); + if (NULL != dxgiDevice1) + { + hr = dxgiDevice1->SetMaximumFrameLatency(_scd.maxFrameLatency); + if (FAILED(hr) ) + { + BX_TRACE("Failed to set maximum frame latency, hr 0x%08x", hr); + hr = S_OK; + } + DX_RELEASE_I(dxgiDevice1); + } + } + if (FAILED(hr) ) { BX_TRACE("Failed to create swap chain."); return hr; } -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS if (SUCCEEDED(hr) ) { for (uint32_t ii = 0; ii < BX_COUNTOF(s_dxgiSwapChainIIDs); ++ii) @@ -521,13 +594,75 @@ namespace bgfx } } } -#endif // BX_PLATFORM_WINDOWS +#endif // BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS updateHdr10(*_swapChain, _scd); return S_OK; } +#if BX_PLATFORM_WINRT + HRESULT Dxgi::removeSwapChain(const SwapChainDesc& _scd, SwapChainI** _swapChain) + { + IInspectable *nativeWindow = reinterpret_cast<IInspectable*>(_scd.nwh); + ISwapChainPanelNative* swapChainPanelNative; + + HRESULT hr = nativeWindow->QueryInterface( + __uuidof(ISwapChainPanelNative) + , (void**)&swapChainPanelNative + ); + + if (SUCCEEDED(hr)) + { + // Swap Chain Panel + if (NULL != swapChainPanelNative) + { + // Remove swap chain + hr = swapChainPanelNative->SetSwapChain(NULL); + + if (FAILED(hr)) + { + DX_RELEASE(swapChainPanelNative, 0); + BX_TRACE("Failed to SetSwapChain, hr %x."); + return hr; + } + + DX_RELEASE_I(swapChainPanelNative); + } + } + else + { + // Swap Chain Background Panel + ISwapChainBackgroundPanelNative* swapChainBackgroundPanelNative = NULL; + + hr = nativeWindow->QueryInterface( + __uuidof(ISwapChainBackgroundPanelNative) + , (void**)&swapChainBackgroundPanelNative + ); + + if (FAILED(hr)) + { + return hr; + } + + if (NULL != swapChainBackgroundPanelNative) + { + // Remove swap chain + hr = swapChainBackgroundPanelNative->SetSwapChain(NULL); + + if (FAILED(hr)) + { + DX_RELEASE(swapChainBackgroundPanelNative, 0); + BX_TRACE("Failed to SetSwapChain, hr %x."); + return hr; + } + + DX_RELEASE_I(swapChainBackgroundPanelNative); + } + } + } +#endif + void Dxgi::updateHdr10(SwapChainI* _swapChain, const SwapChainDesc& _scd) { #if BX_PLATFORM_WINDOWS @@ -559,7 +694,7 @@ namespace bgfx hr = output6->GetDesc1(&desc); if (SUCCEEDED(hr) ) { - BX_TRACE("Display specs:") + BX_TRACE("Display specs:"); BX_TRACE("\t BitsPerColor: %d", desc.BitsPerColor); BX_TRACE("\t Color space: %s (colorspace, range, gamma, sitting, primaries, transform)" , s_colorSpaceStr[bx::min<uint32_t>(desc.ColorSpace, kDxgiLastColorSpace+1)] @@ -606,7 +741,31 @@ namespace bgfx { HRESULT hr; -#if BX_PLATFORM_WINDOWS + uint32_t scdFlags = _scd.flags; + +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS + IDXGIFactory5* factory5; + hr = m_factory->QueryInterface(IID_IDXGIFactory5, (void**)&factory5); + + if (SUCCEEDED(hr)) + { + BOOL allowTearing = false; + // BK - CheckFeatureSupport with DXGI_FEATURE_PRESENT_ALLOW_TEARING + // will crash on pre Windows 8. Issue #1356. + hr = factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allowTearing, sizeof(allowTearing)); + BX_TRACE("Allow tearing is %ssupported.", allowTearing ? "" : "not "); + + scdFlags |= allowTearing ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0; + scdFlags |= false + || _scd.swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL + || _scd.swapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD + ? 0 // DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT + : 0 + ; + + DX_RELEASE_I(factory5); + } + if (NULL != _nodeMask && NULL != _presentQueue) { @@ -615,7 +774,7 @@ namespace bgfx , _scd.width , _scd.height , _scd.format - , _scd.flags + , scdFlags , _nodeMask , _presentQueue ); @@ -630,7 +789,7 @@ namespace bgfx , _scd.width , _scd.height , _scd.format - , _scd.flags + , scdFlags ); } @@ -655,6 +814,11 @@ namespace bgfx #endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT } + bool Dxgi::tearingSupported() const + { + return m_tearingSupported; + } + } // namespace bgfx #endif // BGFX_CONFIG_RENDERER_DIRECT3D11 || BGFX_CONFIG_RENDERER_DIRECT3D12 diff --git a/3rdparty/bgfx/src/dxgi.h b/3rdparty/bgfx/src/dxgi.h index 604a50eb984..cd01d6bf945 100644 --- a/3rdparty/bgfx/src/dxgi.h +++ b/3rdparty/bgfx/src/dxgi.h @@ -1,12 +1,15 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_DXGI_H_HEADER_GUARD #define BGFX_DXGI_H_HEADER_GUARD -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +#include <sal.h> +#include <unknwn.h> + +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include <d3dcommon.h> # include <dxgi1_6.h> #else @@ -15,7 +18,7 @@ namespace bgfx { -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT typedef ::IUnknown IUnknown; #else typedef ::IGraphicsUnknown IUnknown; @@ -53,7 +56,7 @@ namespace bgfx /// struct Dxgi { -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS typedef ::IDXGIAdapter3 AdapterI; typedef ::IDXGIFactory5 FactoryI; typedef ::IDXGISwapChain3 SwapChainI; @@ -85,6 +88,11 @@ namespace bgfx /// HRESULT createSwapChain(IUnknown* _device, const SwapChainDesc& _scd, SwapChainI** _swapChain); +#if BX_PLATFORM_WINRT + /// + HRESULT removeSwapChain(const SwapChainDesc& _scd, SwapChainI** _swapChain); +#endif + /// void updateHdr10(SwapChainI* _swapChain, const SwapChainDesc& _scd); @@ -95,6 +103,9 @@ namespace bgfx void trim(); /// + bool tearingSupported() const; + + /// void* m_dxgiDll; void* m_dxgiDebugDll; @@ -103,6 +114,7 @@ namespace bgfx FactoryI* m_factory; AdapterI* m_adapter; OutputI* m_output; + bool m_tearingSupported; }; } // namespace bgfx diff --git a/3rdparty/bgfx/src/emscripten.h b/3rdparty/bgfx/src/emscripten.h new file mode 100644 index 00000000000..1e1e0aea03d --- /dev/null +++ b/3rdparty/bgfx/src/emscripten.h @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#ifndef BGFX_EMSCRIPTEN_H_HEADER_GUARD +#define BGFX_EMSCRIPTEN_H_HEADER_GUARD + +#if BX_PLATFORM_EMSCRIPTEN + +# include <emscripten/emscripten.h> +# include <emscripten/html5.h> + +# define _EMSCRIPTEN_CHECK(_check, _call) \ + BX_MACRO_BLOCK_BEGIN \ + EMSCRIPTEN_RESULT __result__ = _call; \ + _check(EMSCRIPTEN_RESULT_SUCCESS == __result__, #_call " FAILED 0x%08x\n", (uint32_t)__result__); \ + BX_UNUSED(__result__); \ + BX_MACRO_BLOCK_END + +# if BGFX_CONFIG_DEBUG +# define EMSCRIPTEN_CHECK(_call) _EMSCRIPTEN_CHECK(BX_ASSERT, _call) +# else +# define EMSCRIPTEN_CHECK(_call) _call +# endif // BGFX_CONFIG_DEBUG + +# ifndef HTML5_TARGET_CANVAS_SELECTOR +# define HTML5_TARGET_CANVAS_SELECTOR "#canvas" +# endif // HTML5_TARGET_CANVAS_SELECTOR + +#endif // BX_PLATFORM_EMSCRIPTEN + +#endif // BGFX_EMSCRIPTEN_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/fs_clear0.bin.h b/3rdparty/bgfx/src/fs_clear0.bin.h index 346466213ff..d0313a27c85 100644 --- a/3rdparty/bgfx/src/fs_clear0.bin.h +++ b/3rdparty/bgfx/src/fs_clear0.bin.h @@ -1,130 +1,142 @@ -static const uint8_t fs_clear0_glsl[128] = +static const uint8_t fs_clear0_glsl[136] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x5a, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .Z...uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, // ().{. gl_FragC - 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, // olor = bgfx_clea - 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r_color[0];.}... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........Z...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x62, // gl_FragColor = b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, // gfx_clear_color[ + 0x30, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // 0];.}... }; -static const uint8_t fs_clear0_spv[641] = +static const uint8_t fs_clear0_essl[136] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x01, 0x00, 0x00, 0x01, // clear_color..... - 0x00, 0x58, 0x02, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .X.....#........ - 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // .F.............. - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x06, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, // .main....-...... - 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, // ................ - 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, // .............mai - 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x24, 0x47, 0x6c, // n........ ...$Gl - 0x6f, 0x62, 0x61, 0x6c, 0x00, 0x06, 0x00, 0x08, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // obal..... ...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // r........"...... - 0x00, 0x05, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....-...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, // agData0..G...... - 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x20, 0x00, 0x00, // .........H... .. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, // .....#.......G.. - 0x00, 0x20, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, // . .......G...".. - 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2d, 0x00, 0x00, // .".......G...-.. - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, // ................ - 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, // .!.............. - 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // ..... .......... - 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, // ................ - 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, // . .......+...... - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, // ................ - 0x00, 0x08, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x20, 0x00, 0x00, // ............. .. - 0x00, 0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ..... ...!...... - 0x00, 0x20, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // . ...;...!...".. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .........#... .. - 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, // .....+...#...$.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ..... ...%...... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ..... ...,...... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, // .....;...,...-.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .....6.......... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, // ................ - 0x00, 0x41, 0x00, 0x06, 0x00, 0x25, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // .A...%...D...".. - 0x00, 0x24, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .$...$...=...... - 0x00, 0x45, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x2d, 0x00, 0x00, // .E...D...>...-.. - 0x00, 0x45, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, // .E.......8...... - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........Z...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x62, // gl_FragColor = b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, // gfx_clear_color[ + 0x30, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // 0];.}... }; -static const uint8_t fs_clear0_dx9[198] = +static const uint8_t fs_clear0_spv[749] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x01, // clear_color..... - 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // ...... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x02, 0x00, 0x00, 0x03, 0x02, 0x23, // ...............# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........N...... + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x07, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x2b, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, // .+...4.......... + 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, // ................ + 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x05, 0x00, 0x06, 0x00, 0x21, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // .....!...Uniform + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x21, 0x00, 0x00, // Block........!.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // .....bgfx_clear_ + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x23, 0x00, 0x00, // color........#.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, // .........+...gl_ + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // FragCoord....... + 0x00, 0x34, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .4...bgfx_FragDa + 0x74, 0x61, 0x30, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // ta0..G... ...... + 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....H...!...... + 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x21, 0x00, 0x00, // .#.......G...!.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // .....G...#...".. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, // .....G...#...!.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, // .....G...+...... + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x34, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...4...... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, // .............!.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, // ................ + 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // . .............. + 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ............. .. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, // .....+.......... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // ......... ...... + 0x00, 0x1f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x21, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .........!... .. + 0x00, 0x20, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, // . ...".......!.. + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .;..."...#...... + 0x00, 0x15, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .....$... ...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .+...$...%...... + 0x00, 0x20, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...&.......... + 0x00, 0x20, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...*.......... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .;...*...+...... + 0x00, 0x20, 0x00, 0x04, 0x00, 0x33, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...3.......... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x33, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...3...4...... + 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .6.............. + 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. + 0x00, 0x26, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, // .&...L...#...%.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, // .%...=.......M.. + 0x00, 0x4c, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x34, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, // .L...>...4...M.. + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, // .....8....... }; -static const uint8_t fs_clear0_dx11[341] = +static const uint8_t fs_clear0_dx9[206] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x2c, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x01, 0xdc, 0xf8, 0x1e, 0x7d, 0x89, 0xaa, // .,...DXBC....}.. - 0x45, 0x4f, 0x0c, 0x79, 0x61, 0x5e, 0xe4, 0x72, 0x8d, 0x01, 0x00, 0x00, 0x00, 0x2c, 0x01, 0x00, // EO.ya^.r.....,.. - 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, // .....0...|...... - 0x00, 0xf8, 0x00, 0x00, 0x00, 0x41, 0x6f, 0x6e, 0x39, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, // .....Aon9D...D.. - 0x00, 0x00, 0x02, 0xff, 0xff, 0x14, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x24, // .........0.....$ - 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x30, // ...0...0...$...0 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, // ................ - 0xff, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ - 0x00, 0x53, 0x48, 0x44, 0x52, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, // .SHDR@...@...... - 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .Y...F. ........ - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .e.... ......6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .....>...ISGN,.. + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .............. +}; +static const uint8_t fs_clear0_dx11[269] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x44, 0x58, 0x42, // .............DXB + 0x43, 0x97, 0x89, 0xd6, 0x18, 0xd7, 0x24, 0x4d, 0xea, 0xd1, 0xcc, 0xac, 0xc3, 0xb2, 0xf1, 0x52, // C.....$M.......R + 0x06, 0x01, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .............,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`.......ISGN,.. 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // N,........... .. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, // .....SV_TARGET.. - 0xab, 0x00, 0x00, 0x80, 0x00, // ..... + 0xab, 0x53, 0x48, 0x44, 0x52, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, // .SHDR@...@...... + 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .Y...F. ........ + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .e.... ......6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, // .....>....... }; -static const uint8_t fs_clear0_mtl[449] = +static const uint8_t fs_clear0_mtl[424] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x9b, 0x01, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // .....using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x7d, // gl_FragColor;.} - 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // ;.struct xlatMtl - 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, 0x0a, // ShaderUniform {. - 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // float4 bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, // ear_color[8];.}; - 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // .fragment xlatMt - 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, // lShaderOutput xl - 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, // atMtlMain (xlatM - 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, // tlShaderInput _m - 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, // tl_i [[stage_in] - 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, // ], constant xlat - 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // MtlShaderUniform - 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, // & _mtl_u [[buffe - 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, // r(0)]]).{. xlat - 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, // MtlShaderOutput - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, // _mtl_o;. _mtl_o - 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, // .gl_FragColor = - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, // _mtl_u.bgfx_clea - 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, // r_color[0];. re - 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, // turn _mtl_o;.}.. - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x01, 0x00, 0x00, 0x23, 0x69, 0x6e, // .........w...#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, // olor(0)]];.};..f + 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ragment xlatMtlM + 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ain_out xlatMtlM + 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, // ain(constant _Gl + 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, // obal& _mtl_u [[b + 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // uffer(0)]]).{. + 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, // xlatMtlMain_ou + 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, // t out = {};. + 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // out.bgfx_FragDat + 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, // a0 = _mtl_u.bgfx + 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, // _clear_color[0]; + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, // . return out; + 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, 0x10, 0x00, // .}...... }; extern const uint8_t* fs_clear0_pssl; extern const uint32_t fs_clear0_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear0.sc b/3rdparty/bgfx/src/fs_clear0.sc index c3e1572ec44..29bb11271f2 100644 --- a/3rdparty/bgfx/src/fs_clear0.sc +++ b/3rdparty/bgfx/src/fs_clear0.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_clear1.bin.h b/3rdparty/bgfx/src/fs_clear1.bin.h index 9d90ec80e99..15c9043c1c9 100644 --- a/3rdparty/bgfx/src/fs_clear1.bin.h +++ b/3rdparty/bgfx/src/fs_clear1.bin.h @@ -1,106 +1,116 @@ -static const uint8_t fs_clear1_glsl[170] = +static const uint8_t fs_clear1_glsl[178] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x84, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .....uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, // gl_FragData[1] = + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[1];.}... + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[1];.}. + 0x0a, 0x00, // .. }; -static const uint8_t fs_clear1_spv[769] = +static const uint8_t fs_clear1_essl[178] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x02, 0x00, 0x00, 0x02, // clear_color..... - 0x00, 0xd8, 0x02, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .......#........ - 0x00, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // .Q.............. - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .main....4...6.. - 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, // ................ - 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, // .main........!.. - 0x00, 0x24, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x00, 0x06, 0x00, 0x08, 0x00, 0x21, 0x00, 0x00, // .$Global.....!.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // .....bgfx_clear_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x23, 0x00, 0x00, // color........#.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x34, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // .........4...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData0..... - 0x00, 0x36, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .6...bgfx_FragDa - 0x74, 0x61, 0x31, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // ta1..G... ...... - 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....H...!...... - 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x21, 0x00, 0x00, // .#.......G...!.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // .....G...#...".. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x34, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...4...... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x36, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...6...... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, // .............!.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, // ................ - 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // . .............. - 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ............. .. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, // .....+.......... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x20, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // ......... ...... - 0x00, 0x1f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x21, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .........!... .. - 0x00, 0x20, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, // . ...".......!.. - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .;..."...#...... - 0x00, 0x15, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .....$... ...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .+...$...%...... - 0x00, 0x20, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...&.......... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .+...$...)...... - 0x00, 0x20, 0x00, 0x04, 0x00, 0x33, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...3.......... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x33, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...3...4...... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x33, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...3...6...... - 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .6.............. - 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. - 0x00, 0x26, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, // .&...M...#...%.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, // .%...=.......N.. - 0x00, 0x4d, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x26, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, // .M...A...&...O.. - 0x00, 0x23, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .#...%...)...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .....P...O...>.. - 0x00, 0x34, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x36, 0x00, 0x00, // .4...N...>...6.. - 0x00, 0x50, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, // .P.......8..... - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[1];.}. + 0x0a, 0x00, // .. +}; +static const uint8_t fs_clear1_spv[877] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x03, 0x00, 0x00, 0x03, 0x02, 0x23, // .........<.....# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........Y...... + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x08, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x2f, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, // ./...;...=...... + 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, // ................ + 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, // .............mai + 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x22, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, // n........"...Uni + 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, // formBlock....... + 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .".......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, // ear_color....... + 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x2f, 0x00, 0x00, // .$.........../.. + 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, // .gl_FragCoord... + 0x00, 0x05, 0x00, 0x06, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....;...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x3d, 0x00, 0x00, // agData0......=.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, // .bgfx_FragData1. + 0x00, 0x47, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, // .G...!.......... + 0x00, 0x48, 0x00, 0x05, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, // .H...".......#.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x22, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....G..."...... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...$..."...... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .G...$...!...... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // .G.../.......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...;.......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .G...=.......... + 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, // .........!...... + 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ............. .. + 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x15, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .+....... ...... + 0x00, 0x1c, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .....!....... .. + 0x00, 0x1e, 0x00, 0x03, 0x00, 0x22, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // ....."...!... .. + 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .#......."...;.. + 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // .#...$.......... + 0x00, 0x25, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .%... .......+.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .%...&....... .. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .'...........+.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .%...*....... .. + 0x00, 0x2e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .............;.. + 0x00, 0x2e, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // ...../....... .. + 0x00, 0x3a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .:...........;.. + 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .:...;.......;.. + 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, // .:...=.......6.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ + 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x27, 0x00, 0x00, // .........A...'.. + 0x00, 0x55, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .U...$...&...&.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, // .=.......V...U.. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x27, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, // .A...'...W...$.. + 0x00, 0x26, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .&...*...=...... + 0x00, 0x58, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x3b, 0x00, 0x00, // .X...W...>...;.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, // .V...>...=...X.. + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, // .....8..... . }; -static const uint8_t fs_clear1_dx9[210] = +static const uint8_t fs_clear1_dx9[218] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x02, // clear_color..... - 0x00, 0xac, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ - 0x00, 0x00, // .. + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, // ................ + 0x80, 0x01, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .......... }; -static const uint8_t fs_clear1_dx11[413] = +static const uint8_t fs_clear1_dx11[329] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x74, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x82, 0xff, 0x8b, 0x5f, 0x53, 0xa0, 0x1f, // .t...DXBC..._S.. - 0x3b, 0x53, 0xc6, 0x2a, 0x12, 0xcf, 0xc8, 0x7f, 0xb8, 0x01, 0x00, 0x00, 0x00, 0x74, 0x01, 0x00, // ;S.*.........t.. - 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, // .....0.......... - 0x00, 0x28, 0x01, 0x00, 0x00, 0x41, 0x6f, 0x6e, 0x39, 0x50, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, // .(...Aon9P...P.. - 0x00, 0x00, 0x02, 0xff, 0xff, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x24, // ..... ...0.....$ - 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x30, // ...0...0...$...0 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, // ................ - 0xff, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x53, 0x48, 0x44, // .............SHD - 0x52, 0x64, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, // Rd...@.......Y.. - 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .F. .........e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . - 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .....>...ISGN,.. + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, // .............DXB + 0x43, 0xe1, 0xf9, 0x8b, 0x7f, 0x06, 0xb6, 0xc7, 0x96, 0x4e, 0x0b, 0xee, 0xe9, 0x51, 0x29, 0xfb, // C........N...Q). + 0x5a, 0x01, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // Z............,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`.......ISGN,.. 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG @@ -108,45 +118,50 @@ static const uint8_t fs_clear1_dx11[413] = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ 0x00, 0x0f, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....8.......... 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, // .............SV_ - 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x00, 0x00, 0x80, 0x00, // TARGET....... + 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x64, 0x00, 0x00, // TARGET...SHDRd.. + 0x00, 0x40, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, // .@.......Y...F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .........e.... . + 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....e.... ..... + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .....F. ........ + 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, // .>....... }; -static const uint8_t fs_clear1_mtl[554] = +static const uint8_t fs_clear1_mtl[517] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x04, 0x02, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // .....using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x5b, // gl_FragData_0 [ - 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, // [color(0)]];. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // loat4 gl_FragDat - 0x61, 0x5f, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, 0x5d, // a_1 [[color(1)]] - 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, // ;.};.struct xlat - 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // MtlShaderUniform - 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, // {. float4 bgfx - 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, // _clear_color[8]; - 0x0a, 0x7d, 0x3b, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, // .};.fragment xla - 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, // tMtlShaderOutput - 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x78, 0x6c, // xlatMtlMain (xl - 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, // atMtlShaderInput - 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, // _mtl_i [[stage_ - 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x78, // in]], constant x - 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, // latMtlShaderUnif - 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, // orm& _mtl_u [[bu - 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, // ffer(0)]]).{. x - 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, // latMtlShaderOutp - 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, // ut _mtl_o;. _mt - 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, // l_o.gl_FragData_ - 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, // 0 = _mtl_u.bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, // clear_color[0];. - 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, // _mtl_o.gl_Frag - 0x44, 0x61, 0x74, 0x61, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, // Data_1 = _mtl_u. - 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // bgfx_clear_color - 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, // [1];. return _m - 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // tl_o;.}... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x01, 0x00, 0x00, 0x23, 0x69, 0x6e, // .............#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(0)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, // ata1 [[color(1)] + 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, // ];.};..fragment + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, // xlatMtlMain_out + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, // xlatMtlMain(cons + 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, // tant _Global& _m + 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, // tl_u [[buffer(0) + 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // ]]).{. xlatMt + 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, // lMain_out out = + 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, // {};. out.bgfx + 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // _FragData0 = _mt + 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, // l_u.bgfx_clear_c + 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, // olor[0];. out + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x20, // .bgfx_FragData1 + 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // = _mtl_u.bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, // return out;.}. + 0x0a, 0x00, 0x00, 0x20, 0x00, // ... . }; extern const uint8_t* fs_clear1_pssl; extern const uint32_t fs_clear1_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear1.sc b/3rdparty/bgfx/src/fs_clear1.sc index 81701cdd247..29b965b3fc0 100644 --- a/3rdparty/bgfx/src/fs_clear1.sc +++ b/3rdparty/bgfx/src/fs_clear1.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_clear2.bin.h b/3rdparty/bgfx/src/fs_clear2.bin.h index 19d9d0a6632..df0ce56572e 100644 --- a/3rdparty/bgfx/src/fs_clear2.bin.h +++ b/3rdparty/bgfx/src/fs_clear2.bin.h @@ -1,120 +1,129 @@ -static const uint8_t fs_clear2_glsl[210] = +static const uint8_t fs_clear2_glsl[218] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xac, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .....uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, // gl_FragData[1] = + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[1];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[2] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[2];.}. - 0x0a, 0x00, // .. + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[2];.}... +}; +static const uint8_t fs_clear2_essl[218] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[2];.}... }; -static const uint8_t fs_clear2_spv[897] = +static const uint8_t fs_clear2_spv[1005] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x03, 0x00, 0x00, 0x03, // clear_color..... - 0x00, 0x58, 0x03, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .X.....#........ - 0x00, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // ................ - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, // .main....;...=.. - 0x00, 0x3f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // .?.............. - 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, // ................ - 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, // .....main....... - 0x00, 0x22, 0x00, 0x00, 0x00, 0x24, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x00, 0x06, 0x00, 0x08, // ."...$Global.... - 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .".......bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, // ear_color....... - 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x3b, 0x00, 0x00, // .$...........;.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, // .bgfx_FragData0. - 0x00, 0x05, 0x00, 0x06, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....=...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x3f, 0x00, 0x00, // agData1......?.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, // .bgfx_FragData2. - 0x00, 0x47, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, // .G...!.......... - 0x00, 0x48, 0x00, 0x05, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, // .H...".......#.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x22, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....G..."...... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...$..."...... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...;.......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .G...=.......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .G...?.......... - 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, // .........!...... - 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ............. .. - 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x15, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .+....... ...... - 0x00, 0x1c, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .....!....... .. - 0x00, 0x1e, 0x00, 0x03, 0x00, 0x22, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // ....."...!... .. - 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .#......."...;.. - 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // .#...$.......... - 0x00, 0x25, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .%... .......+.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .%...&....... .. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .'...........+.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .%...*.......+.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .%...-....... .. - 0x00, 0x3a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .:...........;.. - 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .:...;.......;.. - 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .:...=.......;.. - 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, // .:...?.......6.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ - 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x27, 0x00, 0x00, // .........A...'.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .V...$...&...&.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, // .=.......W...V.. - 0x00, 0x41, 0x00, 0x06, 0x00, 0x27, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, // .A...'...X...$.. - 0x00, 0x26, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .&...*...=...... - 0x00, 0x59, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x27, 0x00, 0x00, // .Y...X...A...'.. - 0x00, 0x5a, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, // .Z...$...&...-.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, // .=.......[...Z.. - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...;...W...>.. - 0x00, 0x3d, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x3f, 0x00, 0x00, // .=...Y...>...?.. - 0x00, 0x5b, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, // .[.......8.....0 - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x03, 0x00, 0x00, 0x03, 0x02, 0x23, // ...............# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........d...... + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x09, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x33, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, // .3...B...D...F.. + 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, // ................ + 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x23, 0x00, 0x00, // .main........#.. + 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, // .UniformBlock... + 0x00, 0x06, 0x00, 0x08, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // .....#.......bgf + 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, // x_clear_color... + 0x00, 0x05, 0x00, 0x03, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // .....%.......... + 0x00, 0x33, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 0x72, // .3...gl_FragCoor + 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x42, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // d........B...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData0..... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .D...bgfx_FragDa + 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x46, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta1......F...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, 0x00, 0x47, 0x00, 0x04, // x_FragData2..G.. + 0x00, 0x22, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, // ."...........H.. + 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .#.......#...... + 0x00, 0x47, 0x00, 0x03, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .G...#.......G.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .%...".......G.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .%...!.......G.. + 0x00, 0x33, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .3...........G.. + 0x00, 0x42, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .B...........G.. + 0x00, 0x44, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .D...........G.. + 0x00, 0x46, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, // .F.............. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....!.......... + 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, // ......... ...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // ................ + 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // . ... .......+.. + 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, // . ...!.......... + 0x00, 0x22, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, // .".......!...... + 0x00, 0x23, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, // .#..."... ...$.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, // .....#...;...$.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .%...........&.. + 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // . .......+...&.. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, // .'....... ...(.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .........+...&.. + 0x00, 0x2b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .+.......+...&.. + 0x00, 0x2e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x32, 0x00, 0x00, // ......... ...2.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x32, 0x00, 0x00, // .........;...2.. + 0x00, 0x33, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .3....... ...A.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .........;...A.. + 0x00, 0x42, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .B.......;...A.. + 0x00, 0x44, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .D.......;...A.. + 0x00, 0x46, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, // .F.......6...... + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, // ................ + 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x28, 0x00, 0x00, 0x00, 0x5e, 0x00, 0x00, // .....A...(...^.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .%...'...'...=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // ....._...^...A.. + 0x00, 0x28, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, // .(...`...%...'.. + 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, // .+...=.......a.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x28, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, // .`...A...(...b.. + 0x00, 0x25, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .%...'.......=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .....c...b...>.. + 0x00, 0x42, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x44, 0x00, 0x00, // .B..._...>...D.. + 0x00, 0x61, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x46, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, // .a...>...F...c.. + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x00, // .....8.....0. }; -static const uint8_t fs_clear2_dx9[222] = +static const uint8_t fs_clear2_dx9[230] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x03, // clear_color..... - 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .............. + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, // ................ + 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, // ................ + 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // ...... }; -static const uint8_t fs_clear2_dx11[485] = +static const uint8_t fs_clear2_dx11[389] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xbc, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x0e, 0x9f, 0x66, 0xdd, 0x1f, 0x67, 0xd6, // .....DXBC..f..g. - 0xd1, 0x64, 0xb9, 0x94, 0x61, 0x3d, 0x93, 0x51, 0x1a, 0x01, 0x00, 0x00, 0x00, 0xbc, 0x01, 0x00, // .d..a=.Q........ - 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, // .....0.......$.. - 0x00, 0x58, 0x01, 0x00, 0x00, 0x41, 0x6f, 0x6e, 0x39, 0x5c, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, // .X...Aon9....... - 0x00, 0x00, 0x02, 0xff, 0xff, 0x2c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x24, // .....,...0.....$ - 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x30, // ...0...0...$...0 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, // ................ - 0xff, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, // ................ - 0x80, 0x02, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x53, 0x48, 0x44, 0x52, 0x88, 0x00, 0x00, // .........SHDR... - 0x00, 0x40, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, // .@..."...Y...F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .........e.... . - 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....e.... ..... - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .e.... ......6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x02, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .....>...ISGN,.. + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, // .........T...DXB + 0x43, 0x28, 0xea, 0x41, 0xd6, 0x8b, 0x20, 0x1f, 0x3c, 0x2c, 0x9b, 0xee, 0x43, 0x6d, 0x8a, 0xc1, // C(.A.. .<,..Cm.. + 0xeb, 0x01, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .....T.......,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`.......ISGN,.. 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG @@ -124,51 +133,58 @@ static const uint8_t fs_clear2_dx11[485] = 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, // .............P.. 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, // .....SV_TARGET.. - 0xab, 0x00, 0x00, 0x80, 0x00, // ..... + 0xab, 0x53, 0x48, 0x44, 0x52, 0x88, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // .SHDR....@...".. + 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .Y...F. ........ + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . + 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, // .F. .........>.. + 0x01, 0x00, 0x00, 0x80, 0x00, // ..... }; -static const uint8_t fs_clear2_mtl[644] = +static const uint8_t fs_clear2_mtl[610] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x5e, 0x02, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // .^...using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x5b, // gl_FragData_0 [ - 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, // [color(0)]];. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // loat4 gl_FragDat - 0x61, 0x5f, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, 0x5d, // a_1 [[color(1)]] - 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. float4 gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // agData_2 [[color - 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // (2)]];.};.struct - 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, // xlatMtlShaderUn - 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // iform {. float4 + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x03, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0x02, 0x00, 0x00, 0x23, 0x69, 0x6e, // .........1...#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, // r[8];.};.fragmen - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, // utput xlatMtlMai - 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // n (xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, // Input _mtl_i [[s - 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, // tage_in]], const - 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, // ant xlatMtlShade - 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, // rUniform& _mtl_u - 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, // [[buffer(0)]]). - 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, // {. xlatMtlShade - 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, // rOutput _mtl_o;. - 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, // _mtl_o.gl_Frag - 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, // Data_0 = _mtl_u. - 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // bgfx_clear_color - 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, // [0];. _mtl_o.gl - 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, // _FragData_1 = _m - 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // tl_u.bgfx_clear_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // color[1];. _mtl - 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, // _o.gl_FragData_2 - 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // = _mtl_u.bgfx_c - 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, // lear_color[2];. - 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, // return _mtl_o;. - 0x7d, 0x0a, 0x0a, 0x00, // }... + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(0)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, // ata1 [[color(1)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData2 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, // olor(2)]];.};..f + 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ragment xlatMtlM + 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ain_out xlatMtlM + 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, // ain(constant _Gl + 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, // obal& _mtl_u [[b + 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // uffer(0)]]).{. + 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, // xlatMtlMain_ou + 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, // t out = {};. + 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // out.bgfx_FragDat + 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, // a0 = _mtl_u.bgfx + 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, // _clear_color[0]; + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // . out.bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, // agData1 = _mtl_u + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo + 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, // r[1];. out.bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x3d, 0x20, 0x5f, // fx_FragData2 = _ + 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, // mtl_u.bgfx_clear + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, // _color[2];. r + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, // eturn out;.}.... + 0x30, 0x00, // 0. }; extern const uint8_t* fs_clear2_pssl; extern const uint32_t fs_clear2_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear2.sc b/3rdparty/bgfx/src/fs_clear2.sc index 90a9e4beccb..cbc9837ee86 100644 --- a/3rdparty/bgfx/src/fs_clear2.sc +++ b/3rdparty/bgfx/src/fs_clear2.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_clear3.bin.h b/3rdparty/bgfx/src/fs_clear3.bin.h index 1bf05f08031..cc1a562b2c5 100644 --- a/3rdparty/bgfx/src/fs_clear3.bin.h +++ b/3rdparty/bgfx/src/fs_clear3.bin.h @@ -1,134 +1,144 @@ -static const uint8_t fs_clear3_glsl[250] = +static const uint8_t fs_clear3_glsl[258] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xd4, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .....uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, // gl_FragData[1] = + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[1];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[2] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[2];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, // gl_FragData[3] = + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[3];.}... + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[3];.}. + 0x0a, 0x00, // .. }; -static const uint8_t fs_clear3_spv[1025] = +static const uint8_t fs_clear3_essl[258] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x04, 0x00, 0x00, 0x04, // clear_color..... - 0x00, 0xd8, 0x03, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .......#........ - 0x00, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // .g.............. - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x09, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, // .main....B...D.. - 0x00, 0x46, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, // .F...H.......... - 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, // ................ - 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... - 0x00, 0x05, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, // .....#...$Global - 0x00, 0x06, 0x00, 0x08, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // .....#.......bgf - 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, // x_clear_color... - 0x00, 0x05, 0x00, 0x03, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // .....%.......... - 0x00, 0x42, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .B...bgfx_FragDa - 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x44, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta0......D...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData1..... - 0x00, 0x46, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .F...bgfx_FragDa - 0x74, 0x61, 0x32, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x48, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta2......H...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, 0x00, 0x47, 0x00, 0x04, // x_FragData3..G.. - 0x00, 0x22, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, // ."...........H.. - 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .#.......#...... - 0x00, 0x47, 0x00, 0x03, 0x00, 0x23, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .G...#.......G.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .%...".......G.. - 0x00, 0x42, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .B...........G.. - 0x00, 0x44, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .D...........G.. - 0x00, 0x46, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .F...........G.. - 0x00, 0x48, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, // .H.............. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....!.......... - 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, // ......... ...... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // ................ - 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // . ... .......+.. - 0x00, 0x20, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, // . ...!.......... - 0x00, 0x22, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, // .".......!...... - 0x00, 0x23, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, // .#..."... ...$.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, // .....#...;...$.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .%...........&.. - 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // . .......+...&.. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, // .'....... ...(.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .........+...&.. - 0x00, 0x2b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .+.......+...&.. - 0x00, 0x2e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .........+...&.. - 0x00, 0x31, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .1....... ...A.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .........;...A.. - 0x00, 0x42, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .B.......;...A.. - 0x00, 0x44, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .D.......;...A.. - 0x00, 0x46, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x41, 0x00, 0x00, // .F.......;...A.. - 0x00, 0x48, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, // .H.......6...... - 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, // ................ - 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x28, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, // .....A...(..._.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .%...'...'...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .....`..._...A.. - 0x00, 0x28, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, // .(...a...%...'.. - 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, // .+...=.......b.. - 0x00, 0x61, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x28, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, // .a...A...(...c.. - 0x00, 0x25, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .%...'.......=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .....d...c...A.. - 0x00, 0x28, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, // .(...e...%...'.. - 0x00, 0x31, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, // .1...=.......f.. - 0x00, 0x65, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x42, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, // .e...>...B...`.. - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x44, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...D...b...>.. - 0x00, 0x46, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x48, 0x00, 0x00, // .F...d...>...H.. - 0x00, 0x66, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, // .f.......8.....@ - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[3];.}. + 0x0a, 0x00, // .. }; -static const uint8_t fs_clear3_dx9[234] = +static const uint8_t fs_clear3_spv[1133] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x04, // clear_color..... - 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x04, 0x00, 0x00, 0x03, 0x02, 0x23, // .........<.....# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........o...... + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0a, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x37, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, // .7...I...K...M.. + 0x00, 0x4f, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // .O.............. + 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // .....main....... + 0x00, 0x24, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, // .$...UniformBloc + 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // k........$...... 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, // ................ - 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .......... + 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // r........&...... + 0x00, 0x05, 0x00, 0x06, 0x00, 0x37, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, // .....7...gl_Frag + 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x49, 0x00, 0x00, // Coord........I.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, // .bgfx_FragData0. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....K...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x4d, 0x00, 0x00, // agData1......M.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, // .bgfx_FragData2. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....O...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, // agData3..G...#.. + 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x24, 0x00, 0x00, // .........H...$.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, // .....#.......G.. + 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .$.......G...&.. + 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .".......G...&.. + 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x37, 0x00, 0x00, // .!.......G...7.. + 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x49, 0x00, 0x00, // .........G...I.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4b, 0x00, 0x00, // .........G...K.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4d, 0x00, 0x00, // .........G...M.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, // .........G...O.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, // ................ + 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, // .!.............. + 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // ..... .......... + 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, // .............!.. + 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, // . .......+...!.. + 0x00, 0x22, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, // ."...........#.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00, // .....".......$.. + 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .#... ...%...... + 0x00, 0x24, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .$...;...%...&.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .........'... .. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .....+...'...(.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ..... ...)...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .....+...'...,.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, // .....+...'.../.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, // .....+...'...2.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x36, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ..... ...6...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x36, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, // .....;...6...7.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ..... ...H...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, // .....;...H...I.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, // .....;...H...K.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, // .....;...H...M.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, // .....;...H...O.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .....6.......... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, // ................ + 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .A...)...g...&.. + 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .(...(...=...... + 0x00, 0x68, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, // .h...g...A...).. + 0x00, 0x69, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .i...&...(...,.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, // .=.......j...i.. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .A...)...k...&.. + 0x00, 0x28, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .(.../...=...... + 0x00, 0x6c, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, // .l...k...A...).. + 0x00, 0x6d, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, // .m...&...(...2.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, // .=.......n...m.. + 0x00, 0x3e, 0x00, 0x03, 0x00, 0x49, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...I...h...>.. + 0x00, 0x4b, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x4d, 0x00, 0x00, // .K...j...>...M.. + 0x00, 0x6c, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, // .l...>...O...n.. + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, // .....8.....@. }; -static const uint8_t fs_clear3_dx11[557] = +static const uint8_t fs_clear3_dx9[242] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x04, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0xd5, 0x4f, 0xed, 0x6d, 0x3f, 0x90, 0xd6, // .....DXBC.O.m?.. - 0xbb, 0x53, 0x7b, 0xdc, 0x55, 0x0b, 0xda, 0x6f, 0x86, 0x01, 0x00, 0x00, 0x00, 0x04, 0x02, 0x00, // .S{.U..o........ - 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x54, 0x01, 0x00, // .....0.......T.. - 0x00, 0x88, 0x01, 0x00, 0x00, 0x41, 0x6f, 0x6e, 0x39, 0x68, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, // .....Aon9h...h.. - 0x00, 0x00, 0x02, 0xff, 0xff, 0x38, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x01, 0x00, 0x24, // .....8...0.....$ - 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x30, // ...0...0...$...0 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, // ................ - 0xff, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, // ................ - 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, 0x80, 0x03, 0x00, 0xe4, // ................ - 0xa0, 0xff, 0xff, 0x00, 0x00, 0x53, 0x48, 0x44, 0x52, 0xac, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, // .....SHDR....@.. - 0x00, 0x2b, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .+...Y...F. .... - 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, // .....e.... ..... - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . - 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x03, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .....>...ISGN,.. + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, // ................ + 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, // ................ + 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ + 0x00, 0x00, // .. +}; +static const uint8_t fs_clear3_dx11[449] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, // .............DXB + 0x43, 0x12, 0x80, 0x92, 0xa3, 0x15, 0xef, 0x86, 0x85, 0x80, 0xb7, 0x87, 0xf9, 0x1f, 0xb5, 0xa2, // C............... + 0x4a, 0x01, 0x00, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // J............,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`.......ISGN,.. 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG @@ -139,56 +149,66 @@ static const uint8_t fs_clear3_dx11[557] = 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ 0x00, 0x0f, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....h.......... 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, // .............SV_ - 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x00, 0x00, 0x80, 0x00, // TARGET....... + 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0xac, 0x00, 0x00, // TARGET...SHDR... + 0x00, 0x40, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, // .@...+...Y...F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .........e.... . + 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....e.... ..... + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .. ......6.... . + 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, // .........>...... + 0x00, // . }; -static const uint8_t fs_clear3_mtl[734] = +static const uint8_t fs_clear3_mtl[703] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xb8, 0x02, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // .....using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x5b, // gl_FragData_0 [ - 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, // [color(0)]];. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // loat4 gl_FragDat - 0x61, 0x5f, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, 0x5d, // a_1 [[color(1)]] - 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. float4 gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // agData_2 [[color - 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // (2)]];. float4 - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x5b, 0x5b, // gl_FragData_3 [[ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, // color(3)]];.};.s - 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, // truct xlatMtlSha - 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, // derUniform {. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, // loat4 bgfx_clear - 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x66, 0x72, // _color[8];.};.fr - 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, // agment xlatMtlSh - 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // aderOutput xlatM - 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, // tlMain (xlatMtlS - 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // haderInput _mtl_ - 0x69, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, // i [[stage_in]], - 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // constant xlatMtl - 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, // ShaderUniform& _ - 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, // mtl_u [[buffer(0 - 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // )]]).{. xlatMtl - 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, // ShaderOutput _mt - 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, // l_o;. _mtl_o.gl - 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, // _FragData_0 = _m - 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // tl_u.bgfx_clear_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // color[0];. _mtl - 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x31, // _o.gl_FragData_1 - 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // = _mtl_u.bgfx_c - 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, // lear_color[1];. - 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // _mtl_o.gl_FragD - 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, // ata_2 = _mtl_u.b - 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, // gfx_clear_color[ - 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, // 2];. _mtl_o.gl_ - 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // FragData_3 = _mt + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x02, 0x00, 0x00, 0x23, 0x69, 0x6e, // .............#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(0)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, // ata1 [[color(1)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData2 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(2)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x33, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, // ata3 [[color(3)] + 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, // ];.};..fragment + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, // xlatMtlMain_out + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, // xlatMtlMain(cons + 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, // tant _Global& _m + 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, // tl_u [[buffer(0) + 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // ]]).{. xlatMt + 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, // lMain_out out = + 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, // {};. out.bgfx + 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // _FragData0 = _mt 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, // l_u.bgfx_clear_c - 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, // olor[3];. retur - 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // n _mtl_o;.}... + 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, // olor[0];. out + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x20, // .bgfx_FragData1 + 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // = _mtl_u.bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // out.bgfx_FragD + 0x61, 0x74, 0x61, 0x32, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // ata2 = _mtl_u.bg + 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, // fx_clear_color[2 + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, // ];. out.bgfx_ + 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // FragData3 = _mtl + 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, // _u.bgfx_clear_co + 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, // lor[3];. retu + 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, 0x40, 0x00, // rn out;.}....@. }; extern const uint8_t* fs_clear3_pssl; extern const uint32_t fs_clear3_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear3.sc b/3rdparty/bgfx/src/fs_clear3.sc index 3dd4accb4c3..8244802266d 100644 --- a/3rdparty/bgfx/src/fs_clear3.sc +++ b/3rdparty/bgfx/src/fs_clear3.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_clear4.bin.h b/3rdparty/bgfx/src/fs_clear4.bin.h index 70e1266808a..3ee58c67be2 100644 --- a/3rdparty/bgfx/src/fs_clear4.bin.h +++ b/3rdparty/bgfx/src/fs_clear4.bin.h @@ -1,208 +1,235 @@ -static const uint8_t fs_clear4_glsl[290] = +static const uint8_t fs_clear4_glsl[298] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xfc, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .....uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, // gl_FragData[1] = + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[1];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[2] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[2];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, // gl_FragData[3] = + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[3];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[4] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[4];.}. - 0x0a, 0x00, // .. + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[4];.}... +}; +static const uint8_t fs_clear4_essl[298] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x69, // .............uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[4];.}... }; -static const uint8_t fs_clear4_spv[1153] = +static const uint8_t fs_clear4_spv[1261] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x05, 0x00, 0x00, 0x05, // clear_color..... - 0x00, 0x58, 0x04, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .X.....#........ - 0x00, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // .r.............. - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, // .main....I...K.. - 0x00, 0x4d, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, // .M...O...Q...... - 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, // ................ - 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, // .............mai - 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x24, 0x47, 0x6c, // n........$...$Gl - 0x6f, 0x62, 0x61, 0x6c, 0x00, 0x06, 0x00, 0x08, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // obal.....$...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // r........&...... - 0x00, 0x05, 0x00, 0x06, 0x00, 0x49, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....I...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x4b, 0x00, 0x00, // agData0......K.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, // .bgfx_FragData1. - 0x00, 0x05, 0x00, 0x06, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....M...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x4f, 0x00, 0x00, // agData2......O.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, // .bgfx_FragData3. - 0x00, 0x05, 0x00, 0x06, 0x00, 0x51, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....Q...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, // agData4..G...#.. - 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x24, 0x00, 0x00, // .........H...$.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, // .....#.......G.. - 0x00, 0x24, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, // .$.......G...&.. - 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x49, 0x00, 0x00, // .".......G...I.. - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4b, 0x00, 0x00, // .........G...K.. - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4d, 0x00, 0x00, // .........G...M.. - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, // .........G...O.. - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x51, 0x00, 0x00, // .........G...Q.. - 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, // ................ - 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, // .!.............. - 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // ..... .......... - 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, // .............!.. - 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x21, 0x00, 0x00, // . .......+...!.. - 0x00, 0x22, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, // ."...........#.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x24, 0x00, 0x00, // .....".......$.. - 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .#... ...%...... - 0x00, 0x24, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .$...;...%...&.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .........'... .. - 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .....+...'...(.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ..... ...)...... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .....+...'...,.. - 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, // .....+...'.../.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, // .....+...'...2.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, // .....+...'...5.. - 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ..... ...H...... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, // .....;...H...I.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, // .....;...H...K.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4d, 0x00, 0x00, // .....;...H...M.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, // .....;...H...O.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x51, 0x00, 0x00, // .....;...H...Q.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .....6.......... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, // ................ - 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .A...)...h...&.. - 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .(...(...=...... - 0x00, 0x69, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, // .i...h...A...).. - 0x00, 0x6a, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .j...&...(...,.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, // .=.......k...j.. - 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .A...)...l...&.. - 0x00, 0x28, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .(.../...=...... - 0x00, 0x6d, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, // .m...l...A...).. - 0x00, 0x6e, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, // .n...&...(...2.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, // .=.......o...n.. - 0x00, 0x41, 0x00, 0x06, 0x00, 0x29, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, // .A...)...p...&.. - 0x00, 0x28, 0x00, 0x00, 0x00, 0x35, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .(...5...=...... - 0x00, 0x71, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x49, 0x00, 0x00, // .q...p...>...I.. - 0x00, 0x69, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, // .i...>...K...k.. - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...M...m...>.. - 0x00, 0x4f, 0x00, 0x00, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x51, 0x00, 0x00, // .O...o...>...Q.. - 0x00, 0x71, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, // .q.......8.....P - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x04, 0x00, 0x00, 0x03, 0x02, 0x23, // ...............# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........z...... + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0b, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x3b, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, // .;...P...R...T.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, // .V...X.......... + 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, // ................ + 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x05, 0x00, 0x06, 0x00, 0x25, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // .....%...Uniform + 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x25, 0x00, 0x00, // Block........%.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // .....bgfx_clear_ + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x27, 0x00, 0x00, // color........'.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, // .........;...gl_ + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // FragCoord....... + 0x00, 0x50, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .P...bgfx_FragDa + 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x52, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta0......R...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData1..... + 0x00, 0x54, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .T...bgfx_FragDa + 0x74, 0x61, 0x32, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x56, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta2......V...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData3..... + 0x00, 0x58, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .X...bgfx_FragDa + 0x74, 0x61, 0x34, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // ta4..G...$...... + 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....H...%...... + 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x25, 0x00, 0x00, // .#.......G...%.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // .....G...'...".. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, // .....G...'...!.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, // .....G...;...... + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x50, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...P...... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x52, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...R...... + 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...T...... + 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x56, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...V...... + 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x58, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...X...... + 0x00, 0x04, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, // .............!.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, // ................ + 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // . .............. + 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ........."... .. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, // .....+..."...#.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .........$...... + 0x00, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x25, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, // .#.......%...$.. + 0x00, 0x20, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, // . ...&.......%.. + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .;...&...'...... + 0x00, 0x15, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .....(... ...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .+...(...)...... + 0x00, 0x20, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...*.......... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .+...(...-...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .+...(...0...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .+...(...3...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .+...(...6...... + 0x00, 0x20, 0x00, 0x04, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...:.......... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .;...:...;...... + 0x00, 0x20, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...O.......... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...P...... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...R...... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...T...... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...V...... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...X...... + 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .6.............. + 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. + 0x00, 0x2a, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, // .*...p...'...).. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, // .)...=.......q.. + 0x00, 0x70, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, // .p...A...*...r.. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .'...)...-...=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .....s...r...A.. + 0x00, 0x2a, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, // .*...t...'...).. + 0x00, 0x30, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, // .0...=.......u.. + 0x00, 0x74, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, // .t...A...*...v.. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .'...)...3...=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .....w...v...A.. + 0x00, 0x2a, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, // .*...x...'...).. + 0x00, 0x36, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, // .6...=.......y.. + 0x00, 0x78, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x50, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, // .x...>...P...q.. + 0x00, 0x3e, 0x00, 0x03, 0x00, 0x52, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...R...s...>.. + 0x00, 0x54, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x56, 0x00, 0x00, // .T...u...>...V.. + 0x00, 0x77, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x58, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, // .w...>...X...y.. + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x00, // .....8.....P. }; -static const uint8_t fs_clear4_dx9[234] = +static const uint8_t fs_clear4_dx9[242] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x04, // clear_color..... - 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, // ................ - 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .......... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, // ................ + 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, // ................ + 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ + 0x00, 0x00, // .. }; -static const uint8_t fs_clear4_dx11[501] = +static const uint8_t fs_clear4_dx11[509] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xcc, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x0e, 0x7a, 0x23, 0x41, 0x2a, 0x54, 0xbd, // .....DXBC.z#A*T. - 0xa3, 0x8b, 0x1e, 0xbd, 0x2e, 0x91, 0x6f, 0x8b, 0x29, 0x01, 0x00, 0x00, 0x00, 0xcc, 0x01, 0x00, // ......o.)....... - 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, // .....,...`...... - 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .ISGN,.......... - 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // . .............. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, // .........SV_POSI - 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0x8c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // TION.OSGN....... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, // ................ - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, // .............SV_ - 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0xd0, 0x00, 0x00, // TARGET...SHDR... - 0x00, 0x40, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, // .@...4...Y...F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .........e.... . - 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....e.... ..... - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . - 0x00, 0x04, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, // .F. .........>.. - 0x01, 0x00, 0x00, 0x80, 0x00, // ..... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, // .............DXB + 0x43, 0x0e, 0x7a, 0x23, 0x41, 0x2a, 0x54, 0xbd, 0xa3, 0x8b, 0x1e, 0xbd, 0x2e, 0x91, 0x6f, 0x8b, // C.z#A*T.......o. + 0x29, 0x01, 0x00, 0x00, 0x00, 0xcc, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // )............,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`.......ISGN,.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... + 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ + 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG + 0x4e, 0x8c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, // N............... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, // ................ + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, // .....SV_TARGET.. + 0xab, 0x53, 0x48, 0x44, 0x52, 0xd0, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, // .SHDR....@...4.. + 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // .Y...F. ........ + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . + 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, // .....e.... ..... + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .e.... ......6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x04, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, // .....>....... }; -static const uint8_t fs_clear4_mtl[824] = +static const uint8_t fs_clear4_mtl[796] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x12, 0x03, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // .....using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x5b, // gl_FragData_0 [ - 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, // [color(0)]];. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // loat4 gl_FragDat - 0x61, 0x5f, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, 0x5d, // a_1 [[color(1)]] - 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. float4 gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // agData_2 [[color - 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // (2)]];. float4 - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x5b, 0x5b, // gl_FragData_3 [[ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, // color(3)]];. fl - 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, // oat4 gl_FragData - 0x5f, 0x34, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, // _4 [[color(4)]]; - 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // .};.struct xlatM - 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, // tlShaderUniform - 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, // {. float4 bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, // clear_color[8];. - 0x7d, 0x3b, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, // };.fragment xlat - 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, // MtlShaderOutput - 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, // xlatMtlMain (xla - 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, // tMtlShaderInput - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, // _mtl_i [[stage_i - 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, // n]], constant xl - 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, // atMtlShaderUnifo - 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, // rm& _mtl_u [[buf - 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, // fer(0)]]).{. xl - 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, // atMtlShaderOutpu - 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // t _mtl_o;. _mtl - 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, // _o.gl_FragData_0 - 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // = _mtl_u.bgfx_c - 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, // lear_color[0];. - 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // _mtl_o.gl_FragD - 0x61, 0x74, 0x61, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, // ata_1 = _mtl_u.b - 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, // gfx_clear_color[ - 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, // 1];. _mtl_o.gl_ - 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // FragData_2 = _mt - 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, // l_u.bgfx_clear_c - 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // olor[2];. _mtl_ - 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, // o.gl_FragData_3 - 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // = _mtl_u.bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // _mtl_o.gl_FragDa - 0x74, 0x61, 0x5f, 0x34, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // ta_4 = _mtl_u.bg - 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, // fx_clear_color[4 - 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // ];. return _mtl - 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _o;.}... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x05, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb, 0x02, 0x00, 0x00, 0x23, 0x69, 0x6e, // .............#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(0)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, // ata1 [[color(1)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData2 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(2)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x33, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, // ata3 [[color(3)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData4 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, // olor(4)]];.};..f + 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ragment xlatMtlM + 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ain_out xlatMtlM + 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, // ain(constant _Gl + 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, // obal& _mtl_u [[b + 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // uffer(0)]]).{. + 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, // xlatMtlMain_ou + 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, // t out = {};. + 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // out.bgfx_FragDat + 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, // a0 = _mtl_u.bgfx + 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, // _clear_color[0]; + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // . out.bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, // agData1 = _mtl_u + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo + 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, // r[1];. out.bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x3d, 0x20, 0x5f, // fx_FragData2 = _ + 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, // mtl_u.bgfx_clear + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, // _color[2];. o + 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, // ut.bgfx_FragData + 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, // 3 = _mtl_u.bgfx_ + 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, // clear_color[3];. + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, // out.bgfx_Fra + 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, // gData4 = _mtl_u. + 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // bgfx_clear_color + 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, // [4];. return + 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, 0x50, 0x00, // out;.}....P. }; extern const uint8_t* fs_clear4_pssl; extern const uint32_t fs_clear4_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear4.sc b/3rdparty/bgfx/src/fs_clear4.sc index 7390a02ca11..f8569702d17 100644 --- a/3rdparty/bgfx/src/fs_clear4.sc +++ b/3rdparty/bgfx/src/fs_clear4.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_clear5.bin.h b/3rdparty/bgfx/src/fs_clear5.bin.h index 26d53fe54b4..6a950fa485c 100644 --- a/3rdparty/bgfx/src/fs_clear5.bin.h +++ b/3rdparty/bgfx/src/fs_clear5.bin.h @@ -1,228 +1,259 @@ -static const uint8_t fs_clear5_glsl[330] = +static const uint8_t fs_clear5_glsl[338] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x24, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .$...uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, // gl_FragData[1] = + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........$...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[1];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[2] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[2];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, // gl_FragData[3] = + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[3];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[4] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[4];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, // gl_FragData[5] = + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[5];.}... + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[4];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[5] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[5];.}. + 0x0a, 0x00, // .. }; -static const uint8_t fs_clear5_spv[1281] = +static const uint8_t fs_clear5_essl[338] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x06, 0x00, 0x00, 0x06, // clear_color..... - 0x00, 0xd8, 0x04, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .......#........ - 0x00, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // .}.............. - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0b, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, // .main....P...R.. - 0x00, 0x54, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, // .T...V...X...Z.. - 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, // ................ - 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, // .main........%.. - 0x00, 0x24, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x00, 0x06, 0x00, 0x08, 0x00, 0x25, 0x00, 0x00, // .$Global.....%.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // .....bgfx_clear_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x27, 0x00, 0x00, // color........'.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x50, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // .........P...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData0..... - 0x00, 0x52, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .R...bgfx_FragDa - 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x54, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta1......T...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData2..... - 0x00, 0x56, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .V...bgfx_FragDa - 0x74, 0x61, 0x33, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x58, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta3......X...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData4..... - 0x00, 0x5a, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .Z...bgfx_FragDa - 0x74, 0x61, 0x35, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // ta5..G...$...... - 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....H...%...... - 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x25, 0x00, 0x00, // .#.......G...%.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // .....G...'...".. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x50, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...P...... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x52, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...R...... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...T...... - 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x56, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...V...... - 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x58, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...X...... - 0x00, 0x04, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...Z...... - 0x00, 0x05, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, // .............!.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, // ................ - 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // . .............. - 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ........."... .. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x22, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, // .....+..."...#.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x24, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .........$...... - 0x00, 0x23, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x25, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, // .#.......%...$.. - 0x00, 0x20, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, // . ...&.......%.. - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .;...&...'...... - 0x00, 0x15, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .....(... ...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .+...(...)...... - 0x00, 0x20, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...*.......... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .+...(...-...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .+...(...0...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .+...(...3...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .+...(...6...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // .+...(...9...... - 0x00, 0x20, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // . ...O.......... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...P...... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x52, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...R...... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...T...... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...V...... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...X...... - 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...O...Z...... - 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .6.............. - 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. - 0x00, 0x2a, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, // .*...q...'...).. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, // .)...=.......r.. - 0x00, 0x71, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, // .q...A...*...s.. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .'...)...-...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .....t...s...A.. - 0x00, 0x2a, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, // .*...u...'...).. - 0x00, 0x30, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, // .0...=.......v.. - 0x00, 0x75, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, // .u...A...*...w.. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .'...)...3...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .....x...w...A.. - 0x00, 0x2a, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, // .*...y...'...).. - 0x00, 0x36, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, // .6...=.......z.. - 0x00, 0x79, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, // .y...A...*...{.. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .'...)...9...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .....|...{...>.. - 0x00, 0x50, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x52, 0x00, 0x00, // .P...r...>...R.. - 0x00, 0x74, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x54, 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, // .t...>...T...v.. - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x56, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...V...x...>.. - 0x00, 0x58, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5a, 0x00, 0x00, // .X...z...>...Z.. - 0x00, 0x7c, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x60, // .|.......8.....` - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........$...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[4];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[5] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[5];.}. + 0x0a, 0x00, // .. }; -static const uint8_t fs_clear5_dx9[234] = +static const uint8_t fs_clear5_spv[1389] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x04, // clear_color..... - 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, // ................ - 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .......... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x05, 0x00, 0x00, 0x03, 0x02, 0x23, // .........<.....# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0c, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x3f, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // .?...W...Y...[.. + 0x00, 0x5d, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, // .]..._...a...... + 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, // ................ + 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, // .............mai + 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x26, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, // n........&...Uni + 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, // formBlock....... + 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .&.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, // ear_color....... + 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x3f, 0x00, 0x00, // .(...........?.. + 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, // .gl_FragCoord... + 0x00, 0x05, 0x00, 0x06, 0x00, 0x57, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....W...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x59, 0x00, 0x00, // agData0......Y.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, // .bgfx_FragData1. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....[...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x5d, 0x00, 0x00, // agData2......].. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, // .bgfx_FragData3. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // ....._...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x61, 0x00, 0x00, // agData4......a.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x35, 0x00, // .bgfx_FragData5. + 0x00, 0x47, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, // .G...%.......... + 0x00, 0x48, 0x00, 0x05, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, // .H...&.......#.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....G...&...... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...(..."...... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .G...(...!...... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // .G...?.......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x57, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...W.......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x59, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .G...Y.......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .G...[.......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .G...].......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .G..._.......... + 0x00, 0x47, 0x00, 0x04, 0x00, 0x61, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // .G...a.......... + 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, // .........!...... + 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ............. .. + 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x15, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....#... ...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .+...#...$...... + 0x00, 0x1c, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, // .....%.......$.. + 0x00, 0x1e, 0x00, 0x03, 0x00, 0x26, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .....&...%... .. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .'.......&...;.. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // .'...(.......... + 0x00, 0x29, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)... .......+.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .)...*....... .. + 0x00, 0x2b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .+...........+.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...........+.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...1.......+.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...4.......+.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...7.......+.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .)...:....... .. + 0x00, 0x3e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .>...........;.. + 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .>...?....... .. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...........;.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...W.......;.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...Y.......;.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...[.......;.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...].......;.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V..._.......;.. + 0x00, 0x56, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, // .V...a.......6.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ + 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, // .........A...+.. + 0x00, 0x79, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, // .y...(...*...*.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, // .=.......z...y.. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .A...+...{...(.. + 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .*.......=...... + 0x00, 0x7c, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, // .|...{...A...+.. + 0x00, 0x7d, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, // .}...(...*...1.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, // .=.......~...}.. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .A...+.......(.. + 0x00, 0x2a, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .*...4...=...... + 0x00, 0x80, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, // .........A...+.. + 0x00, 0x81, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, // .....(...*...7.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, // .=.............. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .A...+.......(.. + 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .*...:...=...... + 0x00, 0x84, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x57, 0x00, 0x00, // .........>...W.. + 0x00, 0x7a, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x59, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, // .z...>...Y...|.. + 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...[...~...>.. + 0x00, 0x5d, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5f, 0x00, 0x00, // .].......>..._.. + 0x00, 0x82, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x61, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, // .....>...a...... + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x60, 0x00, // .....8.....`. }; -static const uint8_t fs_clear5_dx11[561] = +static const uint8_t fs_clear5_dx9[242] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x08, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x60, 0x35, 0x1a, 0x9f, 0xa4, 0xdc, 0x6a, // .....DXBC`5....j - 0x17, 0x97, 0x20, 0xbd, 0x81, 0xee, 0x84, 0xd9, 0xac, 0x01, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, // .. ............. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x00, // .....,...`...... - 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .ISGN,.......... - 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // . .............. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, // .........SV_POSI - 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0xa4, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // TION.OSGN....... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, // ................ - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, // ................ - 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, // .....SV_TARGET.. - 0xab, 0x53, 0x48, 0x44, 0x52, 0xf4, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, // .SHDR....@...=.. - 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // .Y...F. ........ - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . - 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, // .....e.... ..... - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .. ......6.... . - 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....F. ........ - 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . - 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....F. ........ - 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . - 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .....F. ........ - 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, // .........>...... - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, // ................ + 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, // ................ + 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ + 0x00, 0x00, // .. }; -static const uint8_t fs_clear5_mtl[914] = +static const uint8_t fs_clear5_dx11[569] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x6c, 0x03, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // .l...using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x5b, // gl_FragData_0 [ - 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, // [color(0)]];. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // loat4 gl_FragDat - 0x61, 0x5f, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, 0x5d, // a_1 [[color(1)]] - 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. float4 gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // agData_2 [[color - 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // (2)]];. float4 - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x5b, 0x5b, // gl_FragData_3 [[ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, // color(3)]];. fl - 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, // oat4 gl_FragData - 0x5f, 0x34, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, // _4 [[color(4)]]; - 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, // . float4 gl_Fra - 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x35, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, // gData_5 [[color( - 0x35, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, // 5)]];.};.struct - 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, // xlatMtlShaderUni - 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // form {. float4 - 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // bgfx_clear_color - 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, // [8];.};.fragment - 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, // xlatMtlShaderOu - 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, // tput xlatMtlMain - 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, // (xlatMtlShaderI - 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, 0x74, // nput _mtl_i [[st - 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, // age_in]], consta - 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // nt xlatMtlShader - 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, // Uniform& _mtl_u - 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, // [[buffer(0)]]).{ - 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // . xlatMtlShader - 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x20, // Output _mtl_o;. - 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // _mtl_o.gl_FragD - 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, // ata_0 = _mtl_u.b - 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, // gfx_clear_color[ - 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, // 0];. _mtl_o.gl_ - 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // FragData_1 = _mt + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, // .............DXB + 0x43, 0x60, 0x35, 0x1a, 0x9f, 0xa4, 0xdc, 0x6a, 0x17, 0x97, 0x20, 0xbd, 0x81, 0xee, 0x84, 0xd9, // C`5....j.. ..... + 0xac, 0x01, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .............,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x0c, 0x01, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`.......ISGN,.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... + 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ + 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG + 0x4e, 0xa4, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, // N............... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, // ................ + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, // .............SV_ + 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0xf4, 0x00, 0x00, // TARGET...SHDR... + 0x00, 0x40, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, // .@...=...Y...F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .........e.... . + 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....e.... ..... + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . + 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, // .....e.... ..... + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x05, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // .....F. ........ + 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, // .>....... +}; +static const uint8_t fs_clear5_mtl[889] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x06, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x03, 0x00, 0x00, 0x23, 0x69, 0x6e, // .........H...#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(0)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, // ata1 [[color(1)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData2 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(2)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x33, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, // ata3 [[color(3)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData4 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(4)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x35, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x35, 0x29, 0x5d, // ata5 [[color(5)] + 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, // ];.};..fragment + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, // xlatMtlMain_out + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, // xlatMtlMain(cons + 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, // tant _Global& _m + 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, // tl_u [[buffer(0) + 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // ]]).{. xlatMt + 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, // lMain_out out = + 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, // {};. out.bgfx + 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // _FragData0 = _mt 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, // l_u.bgfx_clear_c - 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // olor[1];. _mtl_ - 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, // o.gl_FragData_2 + 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, // olor[0];. out + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x20, // .bgfx_FragData1 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // = _mtl_u.bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[2];. - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // _mtl_o.gl_FragDa - 0x74, 0x61, 0x5f, 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // ta_3 = _mtl_u.bg - 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, // fx_clear_color[3 - 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, // ];. _mtl_o.gl_F - 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x34, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // ragData_4 = _mtl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // out.bgfx_FragD + 0x61, 0x74, 0x61, 0x32, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // ata2 = _mtl_u.bg + 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, // fx_clear_color[2 + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, // ];. out.bgfx_ + 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // FragData3 = _mtl 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, // _u.bgfx_clear_co - 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, // lor[4];. _mtl_o - 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x35, 0x20, 0x3d, // .gl_FragData_5 = + 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, // lor[3];. out. + 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x3d, // bgfx_FragData4 = 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, // _mtl_u.bgfx_cle - 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x72, // ar_color[5];. r - 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, // eturn _mtl_o;.}. - 0x0a, 0x00, // .. + 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, // ar_color[4];. + 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // out.bgfx_FragDa + 0x74, 0x61, 0x35, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, // ta5 = _mtl_u.bgf + 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, // x_clear_color[5] + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, // ;. return out + 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, 0x60, 0x00, // ;.}....`. }; extern const uint8_t* fs_clear5_pssl; extern const uint32_t fs_clear5_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear5.sc b/3rdparty/bgfx/src/fs_clear5.sc index 0deb9ff95e0..84784fbfb46 100644 --- a/3rdparty/bgfx/src/fs_clear5.sc +++ b/3rdparty/bgfx/src/fs_clear5.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_clear6.bin.h b/3rdparty/bgfx/src/fs_clear6.bin.h index bc0561c8b52..1c28ca0b10f 100644 --- a/3rdparty/bgfx/src/fs_clear6.bin.h +++ b/3rdparty/bgfx/src/fs_clear6.bin.h @@ -1,247 +1,281 @@ -static const uint8_t fs_clear6_glsl[370] = +static const uint8_t fs_clear6_glsl[378] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x4c, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .L...uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, // gl_FragData[1] = + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........L...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[1];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[2] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[2];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, // gl_FragData[3] = + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[3];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[4] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[4];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, // gl_FragData[5] = + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[4];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[5] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[5];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x36, 0x5d, 0x20, 0x3d, // gl_FragData[6] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[5];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x36, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[6] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[6];.}. - 0x0a, 0x00, // .. + 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[6];.}... }; -static const uint8_t fs_clear6_spv[1409] = +static const uint8_t fs_clear6_essl[378] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x07, 0x00, 0x00, 0x07, // clear_color..... - 0x00, 0x58, 0x05, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .X.....#........ - 0x00, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // ................ - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0c, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, // .main....W...Y.. - 0x00, 0x5b, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, // .[...]..._...a.. - 0x00, 0x63, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // .c.............. - 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, // ................ - 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, // .....main....... - 0x00, 0x26, 0x00, 0x00, 0x00, 0x24, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x00, 0x06, 0x00, 0x08, // .&...$Global.... - 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .&.......bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, // ear_color....... - 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x57, 0x00, 0x00, // .(...........W.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, // .bgfx_FragData0. - 0x00, 0x05, 0x00, 0x06, 0x00, 0x59, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....Y...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x5b, 0x00, 0x00, // agData1......[.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, // .bgfx_FragData2. - 0x00, 0x05, 0x00, 0x06, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....]...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x5f, 0x00, 0x00, // agData3......_.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x00, // .bgfx_FragData4. - 0x00, 0x05, 0x00, 0x06, 0x00, 0x61, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....a...bgfx_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x35, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x63, 0x00, 0x00, // agData5......c.. - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x36, 0x00, // .bgfx_FragData6. - 0x00, 0x47, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, // .G...%.......... - 0x00, 0x48, 0x00, 0x05, 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, // .H...&.......#.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x26, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....G...&...... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...(..."...... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x57, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .G...W.......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x59, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .G...Y.......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .G...[.......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .G...].......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .G..._.......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x61, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // .G...a.......... - 0x00, 0x47, 0x00, 0x04, 0x00, 0x63, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // .G...c.......... - 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, // .........!...... - 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ............. .. - 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x15, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....#... ...... - 0x00, 0x2b, 0x00, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .+...#...$...... - 0x00, 0x1c, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, // .....%.......$.. - 0x00, 0x1e, 0x00, 0x03, 0x00, 0x26, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .....&...%... .. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .'.......&...;.. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // .'...(.......... - 0x00, 0x29, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)... .......+.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .)...*....... .. - 0x00, 0x2b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .+...........+.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...........+.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...1.......+.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...4.......+.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...7.......+.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .)...:.......+.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // .)...=....... .. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...........;.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...W.......;.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...Y.......;.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...[.......;.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...].......;.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V..._.......;.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, // .V...a.......;.. - 0x00, 0x56, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, // .V...c.......6.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ - 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, // .........A...+.. - 0x00, 0x7a, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, // .z...(...*...*.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, // .=.......{...z.. - 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .A...+...|...(.. - 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .*.......=...... - 0x00, 0x7d, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, // .}...|...A...+.. - 0x00, 0x7e, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, // .~...(...*...1.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, // .=...........~.. - 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .A...+.......(.. - 0x00, 0x2a, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .*...4...=...... - 0x00, 0x81, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, // .........A...+.. - 0x00, 0x82, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x37, 0x00, 0x00, // .....(...*...7.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, // .=.............. - 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, // .A...+.......(.. - 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .*...:...=...... - 0x00, 0x85, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2b, 0x00, 0x00, // .........A...+.. - 0x00, 0x86, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, // .....(...*...=.. - 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, // .=.............. - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x57, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...W...{...>.. - 0x00, 0x59, 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5b, 0x00, 0x00, // .Y...}...>...[.. - 0x00, 0x7f, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5d, 0x00, 0x00, 0x00, 0x81, 0x00, 0x00, // .....>...]...... - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>..._.......>.. - 0x00, 0x61, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x63, 0x00, 0x00, // .a.......>...c.. - 0x00, 0x87, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x70, // .........8.....p - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........L...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[4];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[5] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[5];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x36, 0x5d, 0x20, 0x3d, // gl_FragData[6] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[6];.}... }; -static const uint8_t fs_clear6_dx9[234] = +static const uint8_t fs_clear6_spv[1517] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x04, // clear_color..... - 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... - 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, // ................ - 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .......... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbc, 0x05, 0x00, 0x00, 0x03, 0x02, 0x23, // ...............# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0d, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x43, 0x00, 0x00, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, // .C...^...`...b.. + 0x00, 0x64, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, // .d...f...h...j.. + 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, // ................ + 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x27, 0x00, 0x00, // .main........'.. + 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, // .UniformBlock... + 0x00, 0x06, 0x00, 0x08, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // .....'.......bgf + 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, // x_clear_color... + 0x00, 0x05, 0x00, 0x03, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // .....).......... + 0x00, 0x43, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6f, 0x72, // .C...gl_FragCoor + 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // d........^...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData0..... + 0x00, 0x60, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .`...bgfx_FragDa + 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x62, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta1......b...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData2..... + 0x00, 0x64, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .d...bgfx_FragDa + 0x74, 0x61, 0x33, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x66, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta3......f...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData4..... + 0x00, 0x68, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .h...bgfx_FragDa + 0x74, 0x61, 0x35, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta5......j...bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x36, 0x00, 0x00, 0x47, 0x00, 0x04, // x_FragData6..G.. + 0x00, 0x26, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, // .&...........H.. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .'.......#...... + 0x00, 0x47, 0x00, 0x03, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .G...'.......G.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .)...".......G.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .)...!.......G.. + 0x00, 0x43, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .C...........G.. + 0x00, 0x5e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .^...........G.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .`...........G.. + 0x00, 0x62, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .b...........G.. + 0x00, 0x64, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .d...........G.. + 0x00, 0x66, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .f...........G.. + 0x00, 0x68, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .h...........G.. + 0x00, 0x6a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, // .j.............. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....!.......... + 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, // ......... ...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // ................ + 0x00, 0x24, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .$... .......+.. + 0x00, 0x24, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, // .$...%.......... + 0x00, 0x26, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, // .&.......%...... + 0x00, 0x27, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, // .'...&... ...(.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, // .....'...;...(.. + 0x00, 0x29, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .)...........*.. + 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // . .......+...*.. + 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, // .+....... ...,.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .........+...*.. + 0x00, 0x2f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // ./.......+...*.. + 0x00, 0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .2.......+...*.. + 0x00, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .5.......+...*.. + 0x00, 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .8.......+...*.. + 0x00, 0x3b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .;.......+...*.. + 0x00, 0x3e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x42, 0x00, 0x00, // .>....... ...B.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x42, 0x00, 0x00, // .........;...B.. + 0x00, 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .C....... ...].. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .........;...].. + 0x00, 0x5e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .^.......;...].. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .`.......;...].. + 0x00, 0x62, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .b.......;...].. + 0x00, 0x64, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .d.......;...].. + 0x00, 0x66, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .f.......;...].. + 0x00, 0x68, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .h.......;...].. + 0x00, 0x6a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, // .j.......6...... + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, // ................ + 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, // .....A...,...... + 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...+...=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, // .,.......)...+.. + 0x00, 0x2f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, // ./...=.......... + 0x00, 0x84, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, // .....A...,...... + 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...2...=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, // .,.......)...+.. + 0x00, 0x35, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, // .5...=.......... + 0x00, 0x88, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, // .....A...,...... + 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...8...=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, // .,.......)...+.. + 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x00, // .;...=.......... + 0x00, 0x8c, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, // .....A...,...... + 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...>...=.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .............>.. + 0x00, 0x5e, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x60, 0x00, 0x00, // .^.......>...`.. + 0x00, 0x85, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x62, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, // .....>...b...... + 0x00, 0x3e, 0x00, 0x03, 0x00, 0x64, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...d.......>.. + 0x00, 0x66, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x68, 0x00, 0x00, // .f.......>...h.. + 0x00, 0x8d, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, // .....>...j...... + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x70, 0x00, // .....8.....p. }; -static const uint8_t fs_clear6_dx11[621] = +static const uint8_t fs_clear6_dx9[242] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x44, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x68, 0xe2, 0x88, 0x87, 0x2b, 0x8c, 0x92, // .D...DXBCh...+.. - 0xbc, 0x98, 0x11, 0xb6, 0x94, 0x5c, 0x76, 0x9a, 0x47, 0x01, 0x00, 0x00, 0x00, 0x44, 0x02, 0x00, // ......v.G....D.. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, // .....,...`...$.. - 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .ISGN,.......... - 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // . .............. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, // .........SV_POSI - 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0xbc, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // TION.OSGN....... - 0x00, 0x08, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, // ................ - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, // ................ - 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, // .............SV_ - 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x18, 0x01, 0x00, // TARGET...SHDR... - 0x00, 0x40, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, // .@...F...Y...F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .........e.... . - 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....e.... ..... - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . - 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, // .....e.... ..... - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .e.... ......6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x04, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, // .....6.... ..... - 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. - 0x06, 0xf2, 0x20, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... - 0x00, 0x06, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, // .....>....... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, // ................ + 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, // ................ + 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ + 0x00, 0x00, // .. }; -static const uint8_t fs_clear6_mtl[1004] = +static const uint8_t fs_clear6_dx11[629] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xc6, 0x03, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // .....using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x5b, // gl_FragData_0 [ - 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, // [color(0)]];. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // loat4 gl_FragDat - 0x61, 0x5f, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, 0x5d, // a_1 [[color(1)]] - 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. float4 gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // agData_2 [[color - 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // (2)]];. float4 - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x5b, 0x5b, // gl_FragData_3 [[ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, // color(3)]];. fl - 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, // oat4 gl_FragData - 0x5f, 0x34, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, // _4 [[color(4)]]; - 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, // . float4 gl_Fra - 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x35, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, // gData_5 [[color( - 0x35, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, // 5)]];. float4 g - 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x36, 0x20, 0x5b, 0x5b, 0x63, // l_FragData_6 [[c - 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x36, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, // olor(6)]];.};.st - 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, // ruct xlatMtlShad - 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, // erUniform {. fl - 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // oat4 bgfx_clear_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x66, 0x72, 0x61, // color[8];.};.fra - 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, // gment xlatMtlSha - 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // derOutput xlatMt - 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, // lMain (xlatMtlSh - 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, // aderInput _mtl_i - 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, // [[stage_in]], c - 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, // onstant xlatMtlS - 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, // haderUniform& _m - 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, // tl_u [[buffer(0) - 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, // ]]).{. xlatMtlS - 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // haderOutput _mtl - 0x5f, 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, // _o;. _mtl_o.gl_ - 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // FragData_0 = _mt - 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, // l_u.bgfx_clear_c - 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // olor[0];. _mtl_ - 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x31, 0x20, // o.gl_FragData_1 - 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // = _mtl_u.bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // _mtl_o.gl_FragDa - 0x74, 0x61, 0x5f, 0x32, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // ta_2 = _mtl_u.bg - 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, // fx_clear_color[2 - 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, // ];. _mtl_o.gl_F - 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // ragData_3 = _mtl - 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, // _u.bgfx_clear_co - 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, // lor[3];. _mtl_o - 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x34, 0x20, 0x3d, // .gl_FragData_4 = - 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, // _mtl_u.bgfx_cle - 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, // ar_color[4];. _ - 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // mtl_o.gl_FragDat - 0x61, 0x5f, 0x35, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, // a_5 = _mtl_u.bgf - 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, // x_clear_color[5] - 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. _mtl_o.gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x36, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // agData_6 = _mtl_ - 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // u.bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, // or[6];. return - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _mtl_o;.}... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, // .........D...DXB + 0x43, 0x68, 0xe2, 0x88, 0x87, 0x2b, 0x8c, 0x92, 0xbc, 0x98, 0x11, 0xb6, 0x94, 0x5c, 0x76, 0x9a, // Ch...+........v. + 0x47, 0x01, 0x00, 0x00, 0x00, 0x44, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // G....D.......,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x24, 0x01, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`...$...ISGN,.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... + 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ + 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG + 0x4e, 0xbc, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, // N............... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, // ................ + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, // ................ + 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, // .....SV_TARGET.. + 0xab, 0x53, 0x48, 0x44, 0x52, 0x18, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x46, 0x00, 0x00, // .SHDR....@...F.. + 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // .Y...F. ........ + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . + 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, // .....e.... ..... + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . + 0x00, 0x06, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .F. .........6.. + 0x06, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, // .. ......F. .... + 0x00, 0x05, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x06, 0x00, 0x00, // .....6.... ..... + 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, // .F. .........>.. + 0x01, 0x00, 0x00, 0x80, 0x00, // ..... +}; +static const uint8_t fs_clear6_mtl[982] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x07, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa5, 0x03, 0x00, 0x00, 0x23, 0x69, 0x6e, // .............#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(0)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, // ata1 [[color(1)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData2 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(2)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x33, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, // ata3 [[color(3)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData4 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(4)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x35, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x35, 0x29, 0x5d, // ata5 [[color(5)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x36, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData6 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x36, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, // olor(6)]];.};..f + 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ragment xlatMtlM + 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // ain_out xlatMtlM + 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, // ain(constant _Gl + 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, // obal& _mtl_u [[b + 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // uffer(0)]]).{. + 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, // xlatMtlMain_ou + 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, // t out = {};. + 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // out.bgfx_FragDat + 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, // a0 = _mtl_u.bgfx + 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, // _clear_color[0]; + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // . out.bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, // agData1 = _mtl_u + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo + 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, // r[1];. out.bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x3d, 0x20, 0x5f, // fx_FragData2 = _ + 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, // mtl_u.bgfx_clear + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, // _color[2];. o + 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, // ut.bgfx_FragData + 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, // 3 = _mtl_u.bgfx_ + 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, // clear_color[3];. + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, // out.bgfx_Fra + 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, // gData4 = _mtl_u. + 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // bgfx_clear_color + 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, // [4];. out.bgf + 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x35, 0x20, 0x3d, 0x20, 0x5f, 0x6d, // x_FragData5 = _m + 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // tl_u.bgfx_clear_ + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, // color[5];. ou + 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x36, // t.bgfx_FragData6 + 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // = _mtl_u.bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x20, // lear_color[6];. + 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, // return out;.} + 0x0a, 0x0a, 0x00, 0x00, 0x70, 0x00, // ....p. }; extern const uint8_t* fs_clear6_pssl; extern const uint32_t fs_clear6_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear6.sc b/3rdparty/bgfx/src/fs_clear6.sc index 971f5b4e3d1..953eb2b768f 100644 --- a/3rdparty/bgfx/src/fs_clear6.sc +++ b/3rdparty/bgfx/src/fs_clear6.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_clear7.bin.h b/3rdparty/bgfx/src/fs_clear7.bin.h index 29a984ad7c1..2f4c84a47ea 100644 --- a/3rdparty/bgfx/src/fs_clear7.bin.h +++ b/3rdparty/bgfx/src/fs_clear7.bin.h @@ -1,267 +1,305 @@ -static const uint8_t fs_clear7_glsl[410] = +static const uint8_t fs_clear7_glsl[418] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x74, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, // .t...uniform vec - 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // 4 bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // or[8];.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ().{. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[0] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, // gl_FragData[1] = + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........t...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[1];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[2] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[2];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, // gl_FragData[3] = + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[3];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[4] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[4];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, // gl_FragData[5] = + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[5];. gl_FragD - 0x61, 0x74, 0x61, 0x5b, 0x36, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[6] = bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[6];. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x37, 0x5d, 0x20, 0x3d, // gl_FragData[7] = + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[4];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[5] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[5];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x36, 0x5d, 0x20, 0x3d, // gl_FragData[6] = 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo - 0x72, 0x5b, 0x37, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // r[7];.}... + 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[6];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x37, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[7] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x37, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[7];.}. + 0x0a, 0x00, // .. }; -static const uint8_t fs_clear7_spv[1537] = +static const uint8_t fs_clear7_essl[418] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0xd8, 0x05, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, // .......#........ - 0x00, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, // ................ - 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, // .........GLSL.st - 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, // d.450........... - 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ - 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, // .main....^...`.. - 0x00, 0x62, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, // .b...d...f...h.. - 0x00, 0x6a, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, // .j...l.......... - 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, // ................ - 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... - 0x00, 0x05, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x24, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, // .....'...$Global - 0x00, 0x06, 0x00, 0x08, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // .....'.......bgf - 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x00, 0x00, // x_clear_color... - 0x00, 0x05, 0x00, 0x03, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // .....).......... - 0x00, 0x5e, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .^...bgfx_FragDa - 0x74, 0x61, 0x30, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta0......`...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData1..... - 0x00, 0x62, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .b...bgfx_FragDa - 0x74, 0x61, 0x32, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x64, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta2......d...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData3..... - 0x00, 0x66, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .f...bgfx_FragDa - 0x74, 0x61, 0x34, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x68, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta4......h...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x35, 0x00, 0x00, 0x05, 0x00, 0x06, // x_FragData5..... - 0x00, 0x6a, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // .j...bgfx_FragDa - 0x74, 0x61, 0x36, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, // ta6......l...bgf - 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x37, 0x00, 0x00, 0x47, 0x00, 0x04, // x_FragData7..G.. - 0x00, 0x26, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, // .&...........H.. - 0x00, 0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .'.......#...... - 0x00, 0x47, 0x00, 0x03, 0x00, 0x27, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .G...'.......G.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .)...".......G.. - 0x00, 0x5e, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .^...........G.. - 0x00, 0x60, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .`...........G.. - 0x00, 0x62, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .b...........G.. - 0x00, 0x64, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .d...........G.. - 0x00, 0x66, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .f...........G.. - 0x00, 0x68, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .h...........G.. - 0x00, 0x6a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, // .j...........G.. - 0x00, 0x6c, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, // .l.............. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....!.......... - 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, // ......... ...... - 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, // ................ - 0x00, 0x24, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, // .$... .......+.. - 0x00, 0x24, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, // .$...%.......... - 0x00, 0x26, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, // .&.......%...... - 0x00, 0x27, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, // .'...&... ...(.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, // .....'...;...(.. - 0x00, 0x29, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .)...........*.. - 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // . .......+...*.. - 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, // .+....... ...,.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .........+...*.. - 0x00, 0x2f, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // ./.......+...*.. - 0x00, 0x32, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .2.......+...*.. - 0x00, 0x35, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .5.......+...*.. - 0x00, 0x38, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .8.......+...*.. - 0x00, 0x3b, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .;.......+...*.. - 0x00, 0x3e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .>.......+...*.. - 0x00, 0x41, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .A....... ...].. - 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .........;...].. - 0x00, 0x5e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .^.......;...].. - 0x00, 0x60, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .`.......;...].. - 0x00, 0x62, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .b.......;...].. - 0x00, 0x64, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .d.......;...].. - 0x00, 0x66, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .f.......;...].. - 0x00, 0x68, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .h.......;...].. - 0x00, 0x6a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5d, 0x00, 0x00, // .j.......;...].. - 0x00, 0x6c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, // .l.......6...... - 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, // ................ - 0x00, 0x05, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, // .....A...,...... - 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...+...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. - 0x00, 0x2c, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, // .,.......)...+.. - 0x00, 0x2f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, // ./...=.......... - 0x00, 0x85, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, // .....A...,...... - 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...2...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. - 0x00, 0x2c, 0x00, 0x00, 0x00, 0x89, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, // .,.......)...+.. - 0x00, 0x35, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x00, // .5...=.......... - 0x00, 0x89, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, // .....A...,...... - 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...8...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. - 0x00, 0x2c, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, // .,.......)...+.. - 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, // .;...=.......... - 0x00, 0x8d, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, // .....A...,...... - 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .)...+...>...=.. - 0x00, 0x08, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .............A.. - 0x00, 0x2c, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, // .,.......)...+.. - 0x00, 0x41, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, // .A...=.......... - 0x00, 0x91, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, // .....>...^...... - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x60, 0x00, 0x00, 0x00, 0x86, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...`.......>.. - 0x00, 0x62, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x64, 0x00, 0x00, // .b.......>...d.. - 0x00, 0x8a, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x66, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, // .....>...f...... - 0x00, 0x3e, 0x00, 0x03, 0x00, 0x68, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...h.......>.. - 0x00, 0x6a, 0x00, 0x00, 0x00, 0x90, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x6c, 0x00, 0x00, // .j.......>...l.. - 0x00, 0x92, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, // .........8...... - 0x00, // . + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x01, 0x00, 0x00, 0x75, 0x6e, 0x69, // .........t...uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // form vec4 bgfx_c + 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x76, // lear_color[8];.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x30, 0x5d, 0x20, 0x3d, // gl_FragData[0] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[0];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x31, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[1] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x32, 0x5d, 0x20, 0x3d, // gl_FragData[2] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[2];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x33, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[3] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[3];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x34, 0x5d, 0x20, 0x3d, // gl_FragData[4] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[4];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x35, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[5] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[5];. + 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5b, 0x36, 0x5d, 0x20, 0x3d, // gl_FragData[6] = + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // r[6];. gl_FragD + 0x61, 0x74, 0x61, 0x5b, 0x37, 0x5d, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ata[7] = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x37, 0x5d, 0x3b, 0x0a, 0x7d, 0x0a, // ear_color[7];.}. + 0x0a, 0x00, // .. }; -static const uint8_t fs_clear7_dx9[234] = +static const uint8_t fs_clear7_spv[1645] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x04, // clear_color..... - 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, // ...........".CTA - 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, // B....[.......... - 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .........T...0.. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........D...... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x06, 0x00, 0x00, 0x03, 0x02, 0x23, // .........<.....# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x9b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0e, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x47, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, // .G...e...g...i.. + 0x00, 0x6b, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, // .k...m...o...q.. + 0x00, 0x73, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // .s.............. + 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, // .....main....... + 0x00, 0x28, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, // .(...UniformBloc + 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // k........(...... 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // .bgfx_clear_colo - 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // r............... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, // .....ps_3_0.Micr - 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, // osoft (R) HLSL S - 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, // hader Compiler 1 - 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, // 0.1............. - 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, // ................ - 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, // ................ - 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // .......... + 0x72, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // r........*...... + 0x00, 0x05, 0x00, 0x06, 0x00, 0x47, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, // .....G...gl_Frag + 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x65, 0x00, 0x00, // Coord........e.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, // .bgfx_FragData0. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x67, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....g...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x69, 0x00, 0x00, // agData1......i.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x00, // .bgfx_FragData2. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....k...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x6d, 0x00, 0x00, // agData3......m.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x00, // .bgfx_FragData4. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....o...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x35, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x71, 0x00, 0x00, // agData5......q.. + 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x36, 0x00, // .bgfx_FragData6. + 0x00, 0x05, 0x00, 0x06, 0x00, 0x73, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, // .....s...bgfx_Fr + 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x37, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, // agData7..G...'.. + 0x00, 0x06, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x28, 0x00, 0x00, // .........H...(.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, // .....#.......G.. + 0x00, 0x28, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .(.......G...*.. + 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, // .".......G...*.. + 0x00, 0x21, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x47, 0x00, 0x00, // .!.......G...G.. + 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x65, 0x00, 0x00, // .........G...e.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x67, 0x00, 0x00, // .........G...g.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, // .........G...i.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x6b, 0x00, 0x00, // .........G...k.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x6d, 0x00, 0x00, // .........G...m.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x6f, 0x00, 0x00, // .........G...o.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x71, 0x00, 0x00, // .........G...q.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x73, 0x00, 0x00, // .........G...s.. + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, // ................ + 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, // .!.............. + 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // ..... .......... + 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, // .............%.. + 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x25, 0x00, 0x00, // . .......+...%.. + 0x00, 0x26, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, // .&...........'.. + 0x00, 0x08, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x28, 0x00, 0x00, // .....&.......(.. + 0x00, 0x27, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .'... ...)...... + 0x00, 0x28, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, // .(...;...)...*.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // .........+... .. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .....+...+...,.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ..... ...-...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .....+...+...0.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, // .....+...+...3.. + 0x00, 0x02, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .....+...+...6.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, // .....+...+...9.. + 0x00, 0x04, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, // .....+...+...<.. + 0x00, 0x05, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, // .....+...+...?.. + 0x00, 0x06, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, // .....+...+...B.. + 0x00, 0x07, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x46, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ..... ...F...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x46, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, // .....;...F...G.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ..... ...d...... + 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .....;...d...e.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, // .....;...d...g.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, // .....;...d...i.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, // .....;...d...k.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, // .....;...d...m.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x6f, 0x00, 0x00, // .....;...d...o.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, // .....;...d...q.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x64, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, // .....;...d...s.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .....6.......... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, // ................ + 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, // .A...-.......*.. + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .,...,...=...... + 0x00, 0x8c, 0x00, 0x00, 0x00, 0x8b, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, // .........A...-.. + 0x00, 0x8d, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, // .....*...,...0.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x00, // .=.............. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, // .A...-.......*.. + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .,...3...=...... + 0x00, 0x90, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, // .........A...-.. + 0x00, 0x91, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .....*...,...6.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // .=.............. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, // .A...-.......*.. + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .,...9...=...... + 0x00, 0x94, 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, // .........A...-.. + 0x00, 0x95, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, // .....*...,...<.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, // .=.............. + 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x97, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, // .A...-.......*.. + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, // .,...?...=...... + 0x00, 0x98, 0x00, 0x00, 0x00, 0x97, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, 0x00, 0x2d, 0x00, 0x00, // .........A...-.. + 0x00, 0x99, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, // .....*...,...B.. + 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x9a, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, // .=.............. + 0x00, 0x3e, 0x00, 0x03, 0x00, 0x65, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...e.......>.. + 0x00, 0x67, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x69, 0x00, 0x00, // .g.......>...i.. + 0x00, 0x90, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00, // .....>...k...... + 0x00, 0x3e, 0x00, 0x03, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, // .>...m.......>.. + 0x00, 0x6f, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x71, 0x00, 0x00, // .o.......>...q.. + 0x00, 0x98, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x73, 0x00, 0x00, 0x00, 0x9a, 0x00, 0x00, // .....>...s...... + 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, // .....8....... }; -static const uint8_t fs_clear7_dx11[681] = +static const uint8_t fs_clear7_dx9[242] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x80, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0xe7, 0x1e, 0xec, 0x06, 0x0c, 0xd8, 0x43, // .....DXBC......C - 0x65, 0x9a, 0x6f, 0x6f, 0xc7, 0x6f, 0x21, 0xde, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, // e.oo.o!......... - 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x3c, 0x01, 0x00, // .....,...`...<.. - 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .ISGN,.......... - 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // . .............. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, // .........SV_POSI - 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0xd4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // TION.OSGN....... - 0x00, 0x08, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // ................ - 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // ................ - 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // ................ - 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // ................ - 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, // .....SV_TARGET.. - 0xab, 0x53, 0x48, 0x44, 0x52, 0x3c, 0x01, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, // .SHDR<...@...O.. - 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, // .Y...F. ........ - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . - 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, // .....e.... ..... - 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. - 0x03, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . - 0x00, 0x06, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x07, 0x00, 0x00, // .....e.... ..... - 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . - 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .....F. ........ - 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . - 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .....F. ........ - 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . - 0x00, 0x05, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, // .....F. ........ - 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . - 0x00, 0x07, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // .....F. ........ - 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, 0x00, // .>....... + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_color....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, // .............ps_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x01, 0x00, 0x00, // mpiler 10.1..... + 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x08, 0x0f, // ................ + 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x0f, 0x80, 0x02, 0x00, 0xe4, // ................ + 0xa0, 0x01, 0x00, 0x00, 0x02, 0x03, 0x08, 0x0f, 0x80, 0x03, 0x00, 0xe4, 0xa0, 0xff, 0xff, 0x00, // ................ + 0x00, 0x00, // .. }; -static const uint8_t fs_clear7_mtl[1094] = +static const uint8_t fs_clear7_dx11[689] = { - 0x46, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, 0x67, 0x66, 0x78, 0x5f, // FSH........bgfx_ - 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x02, 0x08, 0x00, 0x00, 0x08, // clear_color..... - 0x00, 0x20, 0x04, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, // . ...using names - 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, // pace metal;.stru - 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // ct xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // Input {.};.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // t xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // utput {. float4 - 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, 0x5b, // gl_FragData_0 [ - 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, // [color(0)]];. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // loat4 gl_FragDat - 0x61, 0x5f, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, 0x5d, // a_1 [[color(1)]] - 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. float4 gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // agData_2 [[color - 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // (2)]];. float4 - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x5b, 0x5b, // gl_FragData_3 [[ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, // color(3)]];. fl - 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, // oat4 gl_FragData - 0x5f, 0x34, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, // _4 [[color(4)]]; - 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, // . float4 gl_Fra - 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x35, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, // gData_5 [[color( - 0x35, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, // 5)]];. float4 g - 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x36, 0x20, 0x5b, 0x5b, 0x63, // l_FragData_6 [[c - 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x36, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, // olor(6)]];. flo - 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, // at4 gl_FragData_ - 0x37, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x37, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, // 7 [[color(7)]];. - 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // };.struct xlatMt - 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, // lShaderUniform { - 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, // . float4 bgfx_c - 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, // lear_color[8];.} - 0x3b, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // ;.fragment xlatM - 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, // tlShaderOutput x - 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, // latMtlMain (xlat - 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, // MtlShaderInput _ - 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, // mtl_i [[stage_in - 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, // ]], constant xla - 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, // tMtlShaderUnifor - 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, // m& _mtl_u [[buff - 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, // er(0)]]).{. xla - 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, // tMtlShaderOutput - 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // _mtl_o;. _mtl_ - 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x30, 0x20, // o.gl_FragData_0 + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, // .............DXB + 0x43, 0xe7, 0x1e, 0xec, 0x06, 0x0c, 0xd8, 0x43, 0x65, 0x9a, 0x6f, 0x6f, 0xc7, 0x6f, 0x21, 0xde, // C......Ce.oo.o!. + 0xa4, 0x01, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .............,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x3c, 0x01, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`...<...ISGN,.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... + 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, // ................ + 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x4f, 0x53, 0x47, // .SV_POSITION.OSG + 0x4e, 0xd4, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // N............... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // ................ + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, // ................ + 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, // .............SV_ + 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x3c, 0x01, 0x00, // TARGET...SHDR<.. + 0x00, 0x40, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, // .@...O...Y...F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .........e.... . + 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, // .....e.... ..... + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, // .. ......e.... . + 0x00, 0x04, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, // .....e.... ..... + 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x06, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, // .e.... ......e.. + 0x03, 0xf2, 0x20, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .. ......6.... . + 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x04, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x05, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, // .........6.... . + 0x00, 0x06, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // .....F. ........ + 0x00, 0x36, 0x00, 0x00, 0x06, 0xf2, 0x20, 0x10, 0x00, 0x07, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, // .6.... ......F. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x80, // .........>...... + 0x00, // . +}; +static const uint8_t fs_clear7_mtl[1075] = +{ + 0x46, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // FSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x12, // gfx_clear_color. + 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x23, 0x69, 0x6e, // .............#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // bgfx_clear_colo + 0x72, 0x5b, 0x38, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // r[8];.};..struct + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(0)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x31, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x31, 0x29, 0x5d, // ata1 [[color(1)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x32, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData2 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(2)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x33, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x33, 0x29, 0x5d, // ata3 [[color(3)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData4 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x34, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(4)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x35, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x35, 0x29, 0x5d, // ata5 [[color(5)] + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // ];. float4 bg + 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x36, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData6 [[c + 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x36, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, // olor(6)]];. f + 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // loat4 bgfx_FragD + 0x61, 0x74, 0x61, 0x37, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x37, 0x29, 0x5d, // ata7 [[color(7)] + 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, // ];.};..fragment + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, // xlatMtlMain_out + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x63, 0x6f, 0x6e, 0x73, // xlatMtlMain(cons + 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, // tant _Global& _m + 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, // tl_u [[buffer(0) + 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, // ]]).{. xlatMt + 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, // lMain_out out = + 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, // {};. out.bgfx + 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, // _FragData0 = _mt + 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, // l_u.bgfx_clear_c + 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, // olor[0];. out + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x31, 0x20, // .bgfx_FragData1 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // = _mtl_u.bgfx_cl - 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x30, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[0];. - 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // _mtl_o.gl_FragDa - 0x74, 0x61, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // ta_1 = _mtl_u.bg - 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, // fx_clear_color[1 - 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, // ];. _mtl_o.gl_F - 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x32, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // ragData_2 = _mtl + 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x31, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ear_color[1];. + 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // out.bgfx_FragD + 0x61, 0x74, 0x61, 0x32, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // ata2 = _mtl_u.bg + 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x32, // fx_clear_color[2 + 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, // ];. out.bgfx_ + 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x33, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // FragData3 = _mtl 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, // _u.bgfx_clear_co - 0x6c, 0x6f, 0x72, 0x5b, 0x32, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, // lor[2];. _mtl_o - 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x33, 0x20, 0x3d, // .gl_FragData_3 = + 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, // lor[3];. out. + 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x34, 0x20, 0x3d, // bgfx_FragData4 = 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, // _mtl_u.bgfx_cle - 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x33, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, // ar_color[3];. _ - 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, // mtl_o.gl_FragDat - 0x61, 0x5f, 0x34, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, // a_4 = _mtl_u.bgf - 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, // x_clear_color[4] - 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. _mtl_o.gl_Fr - 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x35, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // agData_5 = _mtl_ + 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x34, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, // ar_color[4];. + 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, // out.bgfx_FragDa + 0x74, 0x61, 0x35, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, // ta5 = _mtl_u.bgf + 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x35, 0x5d, // x_clear_color[5] + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, // ;. out.bgfx_F + 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x36, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // ragData6 = _mtl_ 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, // u.bgfx_clear_col - 0x6f, 0x72, 0x5b, 0x35, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, // or[5];. _mtl_o. - 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x5f, 0x36, 0x20, 0x3d, 0x20, // gl_FragData_6 = + 0x6f, 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, // or[6];. out.b + 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x37, 0x20, 0x3d, 0x20, // gfx_FragData7 = 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, // _mtl_u.bgfx_clea - 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x36, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, // r_color[6];. _m - 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, // tl_o.gl_FragData - 0x5f, 0x37, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, 0x66, 0x78, // _7 = _mtl_u.bgfx - 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x37, 0x5d, 0x3b, // _clear_color[7]; - 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, // . return _mtl_o - 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // ;.}... + 0x72, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x5b, 0x37, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, // r_color[7];. + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // return out;.}... + 0x00, 0x80, 0x00, // ... }; extern const uint8_t* fs_clear7_pssl; extern const uint32_t fs_clear7_pssl_size; diff --git a/3rdparty/bgfx/src/fs_clear7.sc b/3rdparty/bgfx/src/fs_clear7.sc index 946eb2fe188..3fca086f21e 100644 --- a/3rdparty/bgfx/src/fs_clear7.sc +++ b/3rdparty/bgfx/src/fs_clear7.sc @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/fs_debugfont.bin.h b/3rdparty/bgfx/src/fs_debugfont.bin.h index d491d4d3b66..8d08bca73e4 100644 --- a/3rdparty/bgfx/src/fs_debugfont.bin.h +++ b/3rdparty/bgfx/src/fs_debugfont.bin.h @@ -1,226 +1,250 @@ -static const uint8_t fs_debugfont_glsl[354] = +static const uint8_t fs_debugfont_glsl[339] = { - 0x46, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, // FSH..."f...s_tex - 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x42, 0x01, 0x00, 0x00, 0x76, // Color......B...v - 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, // arying highp vec - 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, // 4 v_color0;.vary - 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, // ing highp vec4 v - 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, // _color1;.varying - 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, // highp vec2 v_te - 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // xcoord0;.uniform - 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, // sampler2D s_tex - 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // Color;.void main - 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, // ().{. lowp vec - 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, // 4 tmpvar_1;. tm - 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x78, 0x20, 0x28, 0x76, 0x5f, // pvar_1 = mix (v_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x2c, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, // color1, v_color0 - 0x2c, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x20, 0x28, 0x73, 0x5f, 0x74, // , texture2D (s_t - 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, // exColor, v_texco - 0x6f, 0x72, 0x64, 0x30, 0x29, 0x2e, 0x78, 0x78, 0x78, 0x78, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x69, // ord0).xxxx);. i - 0x66, 0x20, 0x28, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3c, // f ((tmpvar_1.w < - 0x20, 0x30, 0x2e, 0x30, 0x30, 0x33, 0x39, 0x32, 0x31, 0x35, 0x36, 0x39, 0x29, 0x29, 0x20, 0x7b, // 0.003921569)) { - 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x3b, 0x0a, 0x20, 0x20, // . discard;. - 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, // };. gl_FragColo - 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, // r = tmpvar_1;.}. - 0x0a, 0x00, // .. + 0x46, 0x53, 0x48, 0x0b, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x73, // FSH..."f.......s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, // _texColor....... + 0x00, 0x00, 0x00, 0x2b, 0x01, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, // ...+...varying v + 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, // ec4 v_color0;.va + 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, // rying vec4 v_col + 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, // or1;.varying vec + 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, // 2 v_texcoord0;.u + 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x32, 0x44, // niform sampler2D + 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, 0x6f, 0x69, // s_texColor;.voi + 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x76, 0x65, // d main ().{. ve + 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, // c4 tmpvar_1;. t + 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x6d, 0x69, 0x78, 0x20, 0x28, 0x76, // mpvar_1 = mix (v + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x2c, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // _color1, v_color + 0x30, 0x2c, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x44, 0x20, 0x28, 0x73, 0x5f, // 0, texture2D (s_ + 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // texColor, v_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x2e, 0x78, 0x78, 0x78, 0x78, 0x29, 0x3b, 0x0a, 0x20, 0x20, // oord0).xxxx);. + 0x69, 0x66, 0x20, 0x28, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, // if ((tmpvar_1.w + 0x3c, 0x20, 0x30, 0x2e, 0x30, 0x30, 0x33, 0x39, 0x32, 0x31, 0x35, 0x36, 0x39, 0x29, 0x29, 0x20, // < 0.003921569)) + 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x3b, 0x0a, 0x20, // {. discard;. + 0x20, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, // };. gl_FragCol + 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, // or = tmpvar_1;.} + 0x0a, 0x0a, 0x00, // ... }; -static const uint8_t fs_debugfont_spv[1070] = +static const uint8_t fs_debugfont_essl[362] = { - 0x46, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0x1c, 0x04, 0x00, 0x00, 0x03, 0x02, // FSH..."f........ - 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x00, // #............... - 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, // ................ - 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, // ..GLSL.std.450.. - 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, // ................ - 0x09, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, // ..........main.. - 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x7d, 0x00, // ..i...l...p...}. - 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, // ................ - 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, // ................ - 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x29, 0x00, // ..main........). - 0x00, 0x00, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x53, 0x61, 0x6d, 0x70, // ..s_texColorSamp - 0x6c, 0x65, 0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x73, 0x5f, // ler.......,...s_ - 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x00, // texColorTexture. - 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x69, 0x00, 0x00, 0x00, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // ......i...v_colo - 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x76, 0x5f, // r0........l...v_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x70, 0x00, // color1........p. - 0x00, 0x00, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x00, 0x05, 0x00, // ..v_texcoord0... - 0x06, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, // ..}...bgfx_FragD - 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x22, 0x00, // ata0..G...)...". - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x21, 0x00, // ......G...)...!. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x22, 0x00, // ......G...,...". - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x21, 0x00, // ......G...,...!. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x69, 0x00, 0x00, 0x00, 0x1e, 0x00, // ......G...i..... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x1e, 0x00, // ......G...l..... - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x70, 0x00, 0x00, 0x00, 0x1e, 0x00, // ......G...p..... - 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x1e, 0x00, // ......G...}..... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, // ..............!. - 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x02, 0x00, 0x06, 0x00, // ................ - 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x19, 0x00, // .......... ..... - 0x09, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, // ................ - 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, // ................ - 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, // .. ...(......... - 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, // ..;...(...)..... - 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, // .. ...+......... - 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, // ..;...+...,..... - 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x38, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2b, 0x00, // ......8.......+. - 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x81, 0x80, 0x80, 0x3b, 0x14, 0x00, // ......`......;.. - 0x02, 0x00, 0x61, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x01, 0x00, // ..a... ...h..... - 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x69, 0x00, // ......;...h...i. - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x68, 0x00, 0x00, 0x00, 0x6c, 0x00, // ......;...h...l. - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x01, 0x00, // ...... ...o..... - 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x6f, 0x00, 0x00, 0x00, 0x70, 0x00, // ......;...o...p. - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x03, 0x00, // ...... ...|..... - 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x7d, 0x00, // ......;...|...}. - 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, // ......6......... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, // ................ - 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x29, 0x00, // ..=.......*...). - 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x2c, 0x00, // ..=.......-...,. - 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x69, 0x00, // ..=.......j...i. - 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x6c, 0x00, // ..=.......m...l. - 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x70, 0x00, // ..=.......q...p. - 0x00, 0x00, 0x56, 0x00, 0x05, 0x00, 0x38, 0x00, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x2d, 0x00, // ..V...8.......-. - 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x57, 0x00, 0x05, 0x00, 0x0d, 0x00, 0x00, 0x00, 0xa8, 0x00, // ..*...W......... - 0x00, 0x00, 0xa6, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x09, 0x00, 0x0d, 0x00, // ......q...O..... - 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 0x00, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, // ................ - 0x08, 0x00, 0x0d, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2e, 0x00, // ................ - 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x93, 0x00, 0x00, 0x00, 0x51, 0x00, // ..m...j.......Q. - 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0xb3, 0x00, 0x00, 0x00, 0xad, 0x00, 0x00, 0x00, 0x03, 0x00, // ................ - 0x00, 0x00, 0xb8, 0x00, 0x05, 0x00, 0x61, 0x00, 0x00, 0x00, 0x97, 0x00, 0x00, 0x00, 0xb3, 0x00, // ......a......... - 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0xf7, 0x00, 0x03, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, // ..`............. - 0x00, 0x00, 0xfa, 0x00, 0x04, 0x00, 0x97, 0x00, 0x00, 0x00, 0x99, 0x00, 0x00, 0x00, 0x98, 0x00, // ................ - 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x99, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x01, 0x00, 0xf8, 0x00, // ................ - 0x02, 0x00, 0x98, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x7d, 0x00, 0x00, 0x00, 0xad, 0x00, // ......>...}..... - 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ......8....... + 0x46, 0x53, 0x48, 0x0b, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x73, // FSH..."f.......s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, // _texColor....... + 0x00, 0x00, 0x00, 0x42, 0x01, 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // ...B...varying h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // ighp vec4 v_colo + 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, // r0;.varying high + 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, // p vec4 v_color1; + 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, // .varying highp v + 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, // ec2 v_texcoord0; + 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, // .uniform sampler + 0x32, 0x44, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x3b, 0x0a, 0x76, // 2D s_texColor;.v + 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. + 0x6c, 0x6f, 0x77, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // lowp vec4 tmpvar + 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, // _1;. tmpvar_1 = + 0x20, 0x6d, 0x69, 0x78, 0x20, 0x28, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x2c, 0x20, // mix (v_color1, + 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x2c, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, // v_color0, textur + 0x65, 0x32, 0x44, 0x20, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, // e2D (s_texColor, + 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x2e, 0x78, 0x78, // v_texcoord0).xx + 0x78, 0x78, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x28, 0x74, 0x6d, 0x70, 0x76, // xx);. if ((tmpv + 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3c, 0x20, 0x30, 0x2e, 0x30, 0x30, 0x33, 0x39, 0x32, // ar_1.w < 0.00392 + 0x31, 0x35, 0x36, 0x39, 0x29, 0x29, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x69, 0x73, // 1569)) {. dis + 0x63, 0x61, 0x72, 0x64, 0x3b, 0x0a, 0x20, 0x20, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, // card;. };. gl_ + 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, // FragColor = tmpv + 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // ar_1;.}... }; -static const uint8_t fs_debugfont_dx9[364] = +static const uint8_t fs_debugfont_spv[1155] = { - 0x46, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, // FSH..."f...s_tex - 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x4c, 0x01, 0x00, 0x00, 0x00, // Color0.....L.... - 0x03, 0xff, 0xff, 0xfe, 0xff, 0x20, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x53, // ..... .CTAB....S - 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, // ................ - 0x91, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, // ...L...0........ - 0x00, 0x02, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x5f, 0x74, 0x65, 0x78, // ...<.......s_tex - 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0x04, 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, // Color........... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, // .......ps_3_0.Mi - 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, // crosoft (R) HLSL - 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, // Shader Compiler - 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x81, // 10.1..Q........ - 0x80, 0x80, 0xbb, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x1f, // ................ - 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x0a, // ................ - 0x00, 0x01, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x02, // ................ - 0x00, 0x03, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, 0x42, // ...............B - 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0x90, 0x00, 0x08, 0xe4, 0xa0, 0x01, // ................ - 0x00, 0x00, 0x02, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x02, 0x00, 0x00, 0x03, 0x01, // ................ - 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0x81, 0x00, 0x00, 0xe4, 0x90, 0x04, 0x00, 0x00, 0x04, 0x00, // ................ - 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x02, // ................ - 0x00, 0x00, 0x03, 0x01, 0x00, 0x01, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0xa0, 0x58, // ...............X - 0x00, 0x00, 0x04, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x55, 0xa0, 0x00, // .............U.. - 0x00, 0xaa, 0xa0, 0x41, 0x00, 0x00, 0x01, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, 0x00, 0x02, 0x00, // ...A............ - 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0xff, 0xff, 0x00, 0x00, 0x00, // ............ + 0x46, 0x53, 0x48, 0x0b, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x73, // FSH..."f.......s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, // _texColor0...... + 0x02, 0x1a, 0x00, 0x58, 0x04, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, // ...X.....#...... + 0x00, 0x08, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, // ................ + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, // ...........GLSL. + 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, // std.450......... + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0a, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, // ................ + 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x6d, // ...main....j...m + 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x10, // ...p...t........ + 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, // ................ + 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, // ...............m + 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x73, // ain........*...s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, // _texColorSampler + 0x00, 0x00, 0x00, 0x05, 0x00, 0x07, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x73, 0x5f, 0x74, 0x65, 0x78, // .......-...s_tex + 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x00, 0x00, 0x00, 0x05, // ColorTexture.... + 0x00, 0x06, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, // ...j...gl_FragCo + 0x6f, 0x72, 0x64, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x76, // ord........m...v + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x70, // _color0........p + 0x00, 0x00, 0x00, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x00, 0x00, 0x00, 0x00, 0x05, // ...v_color1..... + 0x00, 0x05, 0x00, 0x74, 0x00, 0x00, 0x00, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, // ...t...v_texcoor + 0x64, 0x30, 0x00, 0x05, 0x00, 0x06, 0x00, 0x83, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, // d0.........bgfx_ + 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2a, // FragData0..G...* + 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2a, // ...".......G...* + 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2d, // ...!.......G...- + 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2d, // ...".......G...- + 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x6a, // ...!.......G...j + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x6d, // ...........G...m + 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x70, // ...........G...p + 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x74, // ...........G...t + 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x83, // ...........G.... + 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, // ................ + 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1a, // ...!............ + 0x00, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x07, 0x00, 0x00, 0x00, 0x20, // ............... + 0x00, 0x00, 0x00, 0x19, 0x00, 0x09, 0x00, 0x08, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, // ................ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // ................ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x07, // ................ + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x07, // ................ + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, // ....... ...).... + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2a, // .......;...)...* + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, // ....... ...,.... + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x2d, // .......;...,...- + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x03, 0x00, 0x39, 0x00, 0x00, 0x00, 0x08, // ...........9.... + 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x81, // ...+.......a.... + 0x80, 0x80, 0x3b, 0x14, 0x00, 0x02, 0x00, 0x62, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x69, // ..;....b... ...i + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x69, // ...........;...i + 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x69, // ...j.......;...i + 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x69, // ...m.......;...i + 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x73, // ...p....... ...s + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x73, // ...........;...s + 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x82, // ...t....... .... + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x82, // ...........;.... + 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, // ...........6.... + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, // ................ + 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x2b, // .......=.......+ + 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x2e, // ...*...=........ + 0x00, 0x00, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x6e, // ...-...=.......n + 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x71, // ...m...=.......q + 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x75, // ...p...=.......u + 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x56, 0x00, 0x05, 0x00, 0x39, 0x00, 0x00, 0x00, 0xbf, // ...t...V...9.... + 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x57, 0x00, 0x05, 0x00, 0x0d, // .......+...W.... + 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00, 0x00, 0xbf, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x4f, // ...........u...O + 0x00, 0x09, 0x00, 0x0d, 0x00, 0x00, 0x00, 0xa9, 0x00, 0x00, 0x00, 0xc1, 0x00, 0x00, 0x00, 0xc1, // ................ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x00, 0x00, 0x0c, 0x00, 0x08, 0x00, 0x0d, 0x00, 0x00, 0x00, 0xc7, 0x00, 0x00, 0x00, 0x01, // ................ + 0x00, 0x00, 0x00, 0x2e, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0xa9, // .......q...n.... + 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0xc7, // ...Q............ + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xb8, 0x00, 0x05, 0x00, 0x62, 0x00, 0x00, 0x00, 0xad, // ...........b.... + 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0xf7, 0x00, 0x03, 0x00, 0xaf, // .......a........ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x04, 0x00, 0xad, 0x00, 0x00, 0x00, 0xae, // ................ + 0x00, 0x00, 0x00, 0xaf, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0xae, 0x00, 0x00, 0x00, 0xfc, // ................ + 0x00, 0x01, 0x00, 0xf8, 0x00, 0x02, 0x00, 0xaf, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x83, // ...........>.... + 0x00, 0x00, 0x00, 0xc7, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, // ...........8.... + 0x00, 0x00, 0x00, // ... }; -static const uint8_t fs_debugfont_dx11[774] = +static const uint8_t fs_debugfont_dx9[372] = { - 0x46, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0xf4, 0x02, 0x00, 0x00, 0x44, 0x58, // FSH..."f......DX - 0x42, 0x43, 0x1d, 0xbb, 0xb2, 0xa8, 0xff, 0x65, 0xcd, 0xa5, 0xf7, 0x85, 0xfd, 0xcb, 0xb6, 0xe1, // BC.....e........ - 0x00, 0xc6, 0x01, 0x00, 0x00, 0x00, 0xf4, 0x02, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, // ..............0. - 0x00, 0x00, 0x28, 0x01, 0x00, 0x00, 0x34, 0x02, 0x00, 0x00, 0xc0, 0x02, 0x00, 0x00, 0x41, 0x6f, // ..(...4.......Ao - 0x6e, 0x39, 0xf0, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xff, 0xc8, 0x00, // n9.............. - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, // ..(.....(...(... - 0x28, 0x00, 0x01, 0x00, 0x24, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, // (...$...(....... - 0xff, 0xff, 0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x81, 0x80, 0x80, 0xbb, 0x00, 0x00, // ..Q............. - 0x00, 0x80, 0x00, 0x00, 0x80, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ - 0x00, 0x80, 0x00, 0x00, 0x0f, 0xb0, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, // ................ - 0x0f, 0xb0, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x03, 0xb0, 0x1f, 0x00, // ................ - 0x00, 0x02, 0x00, 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, // ..........B..... - 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xb0, 0x00, 0x08, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, // ................ - 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xb0, 0x02, 0x00, 0x00, 0x03, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, // ................ - 0xe4, 0x81, 0x00, 0x00, 0xe4, 0xb0, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, // ................ - 0x00, 0x80, 0x01, 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0xb0, 0x02, 0x00, 0x00, 0x03, 0x01, 0x00, // ................ - 0x01, 0x80, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0xa0, 0x58, 0x00, 0x00, 0x04, 0x01, 0x00, // ..........X..... - 0x0f, 0x80, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x55, 0xa0, 0x00, 0x00, 0xaa, 0xa0, 0x41, 0x00, // ........U.....A. - 0x00, 0x01, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, // ................ - 0xe4, 0x80, 0xff, 0xff, 0x00, 0x00, 0x53, 0x48, 0x44, 0x52, 0x04, 0x01, 0x00, 0x00, 0x40, 0x00, // ......SHDR....@. - 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, // ..A...Z....`.... - 0x00, 0x00, 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x55, // ..X....p......UU - 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x62, 0x10, // ..b...........b. - 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0x32, 0x10, // ..........b...2. - 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, // ......e.... .... - 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x09, 0xf2, 0x00, // ..h.......E..... - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x7e, // ......F.......F~ - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .......`........ - 0x00, 0x08, 0xf2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, 0x01, 0x00, // ..........F..... - 0x00, 0x00, 0x46, 0x1e, 0x10, 0x80, 0x41, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32, 0x00, // ..F...A.......2. - 0x00, 0x09, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x00, 0x00, // ................ - 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, 0x02, 0x00, // ..F.......F..... - 0x00, 0x00, 0x31, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3a, 0x00, // ..1...........:. - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x81, 0x80, 0x80, 0x3b, 0x0d, 0x00, // .......@.....;.. - 0x04, 0x03, 0x0a, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0xf2, 0x20, // ..........6.... - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, // ......F.......>. - 0x00, 0x01, 0x49, 0x53, 0x47, 0x4e, 0x84, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, // ..ISGN.......... - 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, // ..h............. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, // ..........t..... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x0f, // ................ - 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, // ..t............. - 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, // ..........z..... - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, // ................ - 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, // ..SV_POSITION.CO - 0x4c, 0x4f, 0x52, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0x4f, 0x53, // LOR.TEXCOORD..OS - 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, // GN,........... . - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, // ......SV_TARGET. - 0xab, 0xab, 0x00, 0x00, 0x00, 0x00, // ...... + 0x46, 0x53, 0x48, 0x0b, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x73, // FSH..."f.......s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, // _texColor0...... + 0x00, 0x00, 0x00, 0x4c, 0x01, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xfe, 0xff, 0x20, 0x00, 0x43, // ...L......... .C + 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x53, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x01, // TAB....S........ + 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x30, // ...........L...0 + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, // ...........<.... + 0x00, 0x00, 0x00, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00, 0xab, 0x04, // ...s_texColor... + 0x00, 0x0c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, // ...............p + 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, // s_3_0.Microsoft + 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, // (R) HLSL Shader + 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x51, // Compiler 10.1..Q + 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x81, 0x80, 0x80, 0xbb, 0x00, 0x00, 0x00, 0x80, 0x00, // ................ + 0x00, 0x80, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, 0x00, // ................ + 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x01, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, // ................ + 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x02, 0x00, 0x03, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, // ................ + 0x00, 0x00, 0x90, 0x00, 0x08, 0x0f, 0xa0, 0x42, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x02, // .......B........ + 0x00, 0xe4, 0x90, 0x00, 0x08, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x0f, 0x80, 0x01, // ................ + 0x00, 0xe4, 0x90, 0x02, 0x00, 0x00, 0x03, 0x01, 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0x81, 0x00, // ................ + 0x00, 0xe4, 0x90, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, // ................ + 0x00, 0xe4, 0x80, 0x01, 0x00, 0xe4, 0x90, 0x02, 0x00, 0x00, 0x03, 0x01, 0x00, 0x01, 0x80, 0x00, // ................ + 0x00, 0xff, 0x80, 0x00, 0x00, 0x00, 0xa0, 0x58, 0x00, 0x00, 0x04, 0x01, 0x00, 0x0f, 0x80, 0x01, // .......X........ + 0x00, 0x00, 0x80, 0x00, 0x00, 0x55, 0xa0, 0x00, 0x00, 0xaa, 0xa0, 0x41, 0x00, 0x00, 0x01, 0x01, // .....U.....A.... + 0x00, 0x0f, 0x80, 0x01, 0x00, 0x00, 0x02, 0x00, 0x08, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0xff, // ................ + 0xff, 0x00, 0x00, 0x00, // .... }; -static const uint8_t fs_debugfont_mtl[745] = +static const uint8_t fs_debugfont_dx11[568] = { - 0x46, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0xda, 0x02, 0x00, 0x00, 0x75, 0x73, // FSH..."f......us - 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, // ing namespace me - 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, // tal;.struct xlat - 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, // MtlShaderInput { - 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // . float4 v_colo - 0x72, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x76, 0x5f, 0x63, // r0;. float4 v_c - 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, // olor1;. float2 - 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, // v_texcoord0;.};. - 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, // struct xlatMtlSh - 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, // aderOutput {. f - 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, // loat4 gl_FragCol - 0x6f, 0x72, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, // or;.};.struct xl - 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, // atMtlShaderUnifo - 0x72, 0x6d, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, // rm {.};.fragment - 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, // xlatMtlShaderOu - 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, // tput xlatMtlMain - 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, // (xlatMtlShaderI - 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, 0x74, // nput _mtl_i [[st - 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, // age_in]], consta - 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // nt xlatMtlShader - 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, // Uniform& _mtl_u - 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x0a, 0x20, 0x20, // [[buffer(0)]]. - 0x2c, 0x20, 0x20, 0x20, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x64, 0x3c, 0x66, 0x6c, // , texture2d<fl - 0x6f, 0x61, 0x74, 0x3e, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, // oat> s_texColor - 0x5b, 0x5b, 0x74, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x2c, 0x20, // [[texture(0)]], - 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x73, 0x6d, 0x70, 0x5f, // sampler _mtlsmp_ - 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x5b, 0x5b, 0x73, 0x61, 0x6d, // s_texColor [[sam - 0x70, 0x6c, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, // pler(0)]]).{. x - 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, // latMtlShaderOutp - 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, // ut _mtl_o;. flo - 0x61, 0x74, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x30, // at4 tmpvar_1 = 0 - 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x6d, // ;. tmpvar_1 = m - 0x69, 0x78, 0x20, 0x28, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, // ix (_mtl_i.v_col - 0x6f, 0x72, 0x31, 0x2c, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x2e, 0x76, 0x5f, 0x63, 0x6f, // or1, _mtl_i.v_co - 0x6c, 0x6f, 0x72, 0x30, 0x2c, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, // lor0, s_texColor - 0x2e, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x28, 0x5f, 0x6d, 0x74, 0x6c, 0x73, 0x6d, 0x70, 0x5f, // .sample(_mtlsmp_ - 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x2c, 0x20, 0x28, 0x66, 0x6c, 0x6f, // s_texColor, (flo - 0x61, 0x74, 0x32, 0x29, 0x28, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x2e, 0x76, 0x5f, 0x74, 0x65, // at2)(_mtl_i.v_te - 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x29, 0x2e, 0x78, 0x78, 0x78, 0x78, 0x29, 0x3b, // xcoord0)).xxxx); - 0x0a, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, // . if ((tmpvar_1 - 0x2e, 0x77, 0x20, 0x3c, 0x20, 0x30, 0x2e, 0x30, 0x30, 0x33, 0x39, 0x32, 0x31, 0x35, 0x36, 0x39, // .w < 0.003921569 - 0x29, 0x29, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, // )) {. discard - 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x28, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x7d, // _fragment();. } - 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x46, 0x72, // ;. _mtl_o.gl_Fr - 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // agColor = tmpvar - 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, // _1;. return _mt - 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // l_o;.}... + 0x46, 0x53, 0x48, 0x0b, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0a, 0x73, // FSH..."f.......s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, // _texColor0...... + 0x00, 0x00, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x01, // ....s_texColor0. + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, // ............DXBC + 0x5a, 0xd5, 0xe8, 0x3a, 0x43, 0x7d, 0xa8, 0x34, 0xa8, 0x0a, 0x2d, 0x0c, 0xa2, 0xce, 0x50, 0x4f, // Z..:C}.4..-...PO + 0x01, 0x00, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ............,... + 0xb8, 0x00, 0x00, 0x00, 0xec, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x84, 0x00, 0x00, 0x00, // ........ISGN.... + 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........h....... + 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ + 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // t............... + 0x01, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // ........t....... + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, // ................ + 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // z............... + 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, // ........SV_POSIT + 0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, // ION.COLOR.TEXCOO + 0x52, 0x44, 0x00, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // RD..OSGN,....... + 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .... ........... + 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, // ............SV_T + 0x41, 0x52, 0x47, 0x45, 0x54, 0x00, 0xab, 0xab, 0x53, 0x48, 0x44, 0x52, 0x04, 0x01, 0x00, 0x00, // ARGET...SHDR.... + 0x40, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x5a, 0x00, 0x00, 0x03, 0x00, 0x60, 0x10, 0x00, // @...A...Z....`.. + 0x00, 0x00, 0x00, 0x00, 0x58, 0x18, 0x00, 0x04, 0x00, 0x70, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....X....p...... + 0x55, 0x55, 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, // UU..b........... + 0x62, 0x10, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x62, 0x10, 0x00, 0x03, // b...........b... + 0x32, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, // 2.......e.... .. + 0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x09, // ....h.......E... + 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, // ........F....... + 0x46, 0x7e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // F~.......`...... + 0x00, 0x00, 0x00, 0x08, 0xf2, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, // ............F... + 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x80, 0x41, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // ....F...A....... + 0x32, 0x00, 0x00, 0x09, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, // 2............... + 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, // ....F.......F... + 0x02, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x07, 0x12, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, // ....1........... + 0x3a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x81, 0x80, 0x80, 0x3b, // :........@.....; + 0x0d, 0x00, 0x04, 0x03, 0x0a, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, // ............6... + 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // . ......F....... + 0x3e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, // >....... +}; +static const uint8_t fs_debugfont_mtl[831] = +{ + 0x46, 0x53, 0x48, 0x0b, 0xb8, 0xbe, 0x22, 0x66, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x11, 0x73, // FSH..."f.......s + 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, // _texColorSampler + 0x11, 0x01, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x73, 0x5f, 0x74, 0x65, 0x78, // ...........s_tex + 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x54, 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x11, 0x01, 0xff, 0xff, // ColorTexture.... + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, // .......s_texColo + 0x72, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x02, 0x00, 0x00, 0x23, // r..............# + 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, // include <metal_s + 0x74, 0x64, 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, // tdlib>.#include + 0x3c, 0x73, 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, // <simd/simd.h>..u + 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, // sing namespace m + 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, // etal;..struct xl + 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x0a, 0x7b, 0x0a, // atMtlMain_out.{. + 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, // float4 bgfx_ + 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, 0x6f, 0x6c, 0x6f, // FragData0 [[colo + 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, // r(0)]];.};..stru + 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, // ct xlatMtlMain_i + 0x6e, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x76, // n.{. float4 v + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, // _color0 [[user(l + 0x6f, 0x63, 0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, // ocn0)]];. flo + 0x61, 0x74, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x5b, 0x5b, 0x75, // at4 v_color1 [[u + 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, 0x31, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ser(locn1)]];. + 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, // float2 v_texco + 0x6f, 0x72, 0x64, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, // ord0 [[user(locn + 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, // 2)]];.};..fragme + 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, // nt xlatMtlMain_o + 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, // ut xlatMtlMain(x + 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, // latMtlMain_in in + 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x74, // [[stage_in]], t + 0x65, 0x78, 0x74, 0x75, 0x72, 0x65, 0x32, 0x64, 0x3c, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x3e, 0x20, // exture2d<float> + 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x5b, 0x5b, 0x74, 0x65, 0x78, // s_texColor [[tex + 0x74, 0x75, 0x72, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x2c, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, // ture(0)]], sampl + 0x65, 0x72, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x53, 0x61, 0x6d, // er s_texColorSam + 0x70, 0x6c, 0x65, 0x72, 0x20, 0x5b, 0x5b, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x28, 0x30, // pler [[sampler(0 + 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // )]]).{. xlatM + 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, // tlMain_out out = + 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // {};. float4 + 0x5f, 0x31, 0x39, 0x30, 0x20, 0x3d, 0x20, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, 0x6c, 0x6f, // _190 = s_texColo + 0x72, 0x2e, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x28, 0x73, 0x5f, 0x74, 0x65, 0x78, 0x43, 0x6f, // r.sample(s_texCo + 0x6c, 0x6f, 0x72, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x2c, 0x20, 0x69, 0x6e, 0x2e, 0x76, // lorSampler, in.v + 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, // _texcoord0);. + 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x5f, 0x31, 0x39, 0x36, 0x20, 0x3d, 0x20, 0x6d, // float4 _196 = m + 0x69, 0x78, 0x28, 0x69, 0x6e, 0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x2c, 0x20, // ix(in.v_color1, + 0x69, 0x6e, 0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x2c, 0x20, 0x5f, 0x31, 0x39, // in.v_color0, _19 + 0x30, 0x2e, 0x78, 0x78, 0x78, 0x78, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, // 0.xxxx);. if + 0x28, 0x5f, 0x31, 0x39, 0x36, 0x2e, 0x77, 0x20, 0x3c, 0x20, 0x30, 0x2e, 0x30, 0x30, 0x33, 0x39, // (_196.w < 0.0039 + 0x32, 0x31, 0x35, 0x36, 0x38, 0x38, 0x35, 0x39, 0x33, 0x36, 0x38, 0x35, 0x36, 0x32, 0x37, 0x29, // 215688593685627) + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, // . {. d + 0x69, 0x73, 0x63, 0x61, 0x72, 0x64, 0x5f, 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x28, // iscard_fragment( + 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, // );. }. out + 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, // .bgfx_FragData0 + 0x3d, 0x20, 0x5f, 0x31, 0x39, 0x36, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, // = _196;. retu + 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, 0x20, 0x00, // rn out;.}.... . }; extern const uint8_t* fs_debugfont_pssl; extern const uint32_t fs_debugfont_pssl_size; diff --git a/3rdparty/bgfx/src/fs_debugfont.sc b/3rdparty/bgfx/src/fs_debugfont.sc index 8d9c04b5a40..d641b90d9b0 100644 --- a/3rdparty/bgfx/src/fs_debugfont.sc +++ b/3rdparty/bgfx/src/fs_debugfont.sc @@ -1,8 +1,8 @@ $input v_color0, v_color1, v_texcoord0 /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" diff --git a/3rdparty/bgfx/src/glcontext_eagl.h b/3rdparty/bgfx/src/glcontext_eagl.h index 5e816b4e675..7449f8532ec 100644 --- a/3rdparty/bgfx/src/glcontext_eagl.h +++ b/3rdparty/bgfx/src/glcontext_eagl.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_GLCONTEXT_EAGL_H_HEADER_GUARD @@ -20,10 +20,11 @@ namespace bgfx { namespace gl , m_fbo(0) , m_colorRbo(0) , m_depthStencilRbo(0) + , m_msaaContext(false) { } - void create(uint32_t _width, uint32_t _height); + void create(uint32_t _width, uint32_t _height, uint32_t _flags); void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); @@ -51,6 +52,8 @@ namespace bgfx { namespace gl GLuint m_fbo; GLuint m_colorRbo; GLuint m_depthStencilRbo; + // true when MSAA is handled by the context instead of using MSAA FBO + bool m_msaaContext; }; } /* namespace gl */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/glcontext_eagl.mm b/3rdparty/bgfx/src/glcontext_eagl.mm index a9e49a3a8ba..86d1df42e72 100644 --- a/3rdparty/bgfx/src/glcontext_eagl.mm +++ b/3rdparty/bgfx/src/glcontext_eagl.mm @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -102,7 +102,7 @@ namespace bgfx { namespace gl GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilRbo) ); GLenum err = glCheckFramebufferStatus(GL_FRAMEBUFFER); - BX_CHECK(GL_FRAMEBUFFER_COMPLETE == err, "glCheckFramebufferStatus failed 0x%08x", err); + BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == err, "glCheckFramebufferStatus failed 0x%08x", err); BX_UNUSED(err); makeCurrent(); @@ -159,13 +159,13 @@ namespace bgfx { namespace gl GLint m_height; }; - void GlContext::create(uint32_t _width, uint32_t _height) + void GlContext::create(uint32_t _width, uint32_t _height, uint32_t /*_flags*/) { s_opengles = bx::dlopen("/System/Library/Frameworks/OpenGLES.framework/OpenGLES"); - BX_CHECK(NULL != s_opengles, "OpenGLES dynamic library is not found!"); + BX_ASSERT(NULL != s_opengles, "OpenGLES dynamic library is not found!"); BX_UNUSED(_width, _height); - CAEAGLLayer* layer = (CAEAGLLayer*)g_platformData.nwh; + CAEAGLLayer* layer = (__bridge CAEAGLLayer*)g_platformData.nwh; layer.opaque = [layer.style valueForKey:@"opaque"] == nil ? true : [[layer.style valueForKey:@"opaque"] boolValue]; layer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys @@ -176,7 +176,7 @@ namespace bgfx { namespace gl , nil ]; - EAGLContext* context = (EAGLContext*)g_platformData.context; + EAGLContext* context = (__bridge EAGLContext*)g_platformData.context; if (NULL == context) { context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]; @@ -185,9 +185,9 @@ namespace bgfx { namespace gl context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; } } - BX_CHECK(NULL != context, "No valid OpenGLES context."); + BX_ASSERT(NULL != context, "No valid OpenGLES context."); - m_context = (void*)context; + m_context = (__bridge void*)context; [EAGLContext setCurrentContext:context]; [CATransaction flush]; @@ -212,7 +212,7 @@ namespace bgfx { namespace gl 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) + BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) , "glCheckFramebufferStatus failed 0x%08x" , glCheckFramebufferStatus(GL_FRAMEBUFFER) ); @@ -249,8 +249,7 @@ namespace bgfx { namespace gl m_depthStencilRbo = 0; } - EAGLContext* context = (EAGLContext*)m_context; - [context release]; + EAGLContext* context = (__bridge EAGLContext*)m_context; bx::dlclose(s_opengles); } @@ -284,7 +283,7 @@ namespace bgfx { namespace gl GL_CHECK(glGenRenderbuffers(1, &m_colorRbo) ); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) ); - [((EAGLContext*)m_context) renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)g_platformData.nwh]; + [((__bridge EAGLContext*)m_context) renderbufferStorage:GL_RENDERBUFFER fromDrawable:(__bridge CAEAGLLayer*)g_platformData.nwh]; GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_colorRbo) ); GLint width; @@ -299,7 +298,7 @@ namespace bgfx { namespace gl 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) + BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) , "glCheckFramebufferStatus failed 0x%08x" , glCheckFramebufferStatus(GL_FRAMEBUFFER) ); @@ -312,7 +311,7 @@ namespace bgfx { namespace gl SwapChainGL* GlContext::createSwapChain(void* _nwh) { - return BX_NEW(g_allocator, SwapChainGL)(/*m_display, m_config,*/ (EAGLContext*)m_context, (CAEAGLLayer*)_nwh); + return BX_NEW(g_allocator, SwapChainGL)(/*m_display, m_config,*/ (__bridge EAGLContext*)m_context, (__bridge CAEAGLLayer*)_nwh); } void GlContext::destroySwapChain(SwapChainGL* _swapChain) @@ -327,7 +326,7 @@ namespace bgfx { namespace gl if (NULL == _swapChain) { GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_colorRbo) ); - EAGLContext* context = (EAGLContext*)m_context; + EAGLContext* context = (__bridge EAGLContext*)m_context; [context presentRenderbuffer:GL_RENDERBUFFER]; } else @@ -344,7 +343,7 @@ namespace bgfx { namespace gl if (NULL == _swapChain) { - [EAGLContext setCurrentContext:(EAGLContext*)m_context]; + [EAGLContext setCurrentContext:(__bridge EAGLContext*)m_context]; GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_fbo) ); } else diff --git a/3rdparty/bgfx/src/glcontext_egl.cpp b/3rdparty/bgfx/src/glcontext_egl.cpp index 67e643262b1..85de92e1df5 100644 --- a/3rdparty/bgfx/src/glcontext_egl.cpp +++ b/3rdparty/bgfx/src/glcontext_egl.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -25,36 +25,44 @@ namespace bgfx { namespace gl typedef void (*EGLPROC)(void); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLCHOOSECONFIGPROC)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config); - typedef EGLContext (EGLAPIENTRY* PFNEGLCREATECONTEXTPROC)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list); - typedef EGLSurface (EGLAPIENTRY* PFNEGLCREATEWINDOWSURFACEPROC)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list); - typedef EGLint (EGLAPIENTRY* PFNEGLGETERRORPROC)(void); - typedef EGLDisplay (EGLAPIENTRY* PFNEGLGETDISPLAYPROC)(EGLNativeDisplayType display_id); - typedef EGLPROC (EGLAPIENTRY* PFNEGLGETPROCADDRESSPROC)(const char *procname); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLINITIALIZEPROC)(EGLDisplay dpy, EGLint *major, EGLint *minor); - typedef EGLBoolean (EGLAPIENTRY* PFNEGLMAKECURRENTPROC)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); + typedef EGLBoolean (EGLAPIENTRY* PGNEGLBINDAPIPROC)(EGLenum api); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLCHOOSECONFIGPROC)(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size, EGLint* num_config); + typedef EGLContext (EGLAPIENTRY* PFNEGLCREATECONTEXTPROC)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint* attrib_list); + typedef EGLSurface (EGLAPIENTRY* PFNEGLCREATEPBUFFERSURFACEPROC)(EGLDisplay display, EGLConfig config, EGLint const* attrib_list); + typedef EGLSurface (EGLAPIENTRY* PFNEGLCREATEWINDOWSURFACEPROC)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* attrib_list); typedef EGLBoolean (EGLAPIENTRY* PFNEGLDESTROYCONTEXTPROC)(EGLDisplay dpy, EGLContext ctx); typedef EGLBoolean (EGLAPIENTRY* PFNEGLDESTROYSURFACEPROC)(EGLDisplay dpy, EGLSurface surface); - typedef const char* (EGLAPIENTRY* PGNEGLQUERYSTRINGPROC)(EGLDisplay dpy, EGLint name); + typedef EGLContext (EGLAPIENTRY* PFNEGLGETCURRENTCONTEXTPROC)(void); + typedef EGLSurface (EGLAPIENTRY* PFNEGLGETCURRENTSURFACEPROC)(EGLint readdraw); + typedef EGLDisplay (EGLAPIENTRY* PFNEGLGETDISPLAYPROC)(EGLNativeDisplayType display_id); + typedef EGLint (EGLAPIENTRY* PFNEGLGETERRORPROC)(void); + typedef EGLPROC (EGLAPIENTRY* PFNEGLGETPROCADDRESSPROC)(const char* procname); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLINITIALIZEPROC)(EGLDisplay dpy, EGLint* major, EGLint* minor); + typedef EGLBoolean (EGLAPIENTRY* PFNEGLMAKECURRENTPROC)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx); typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPBUFFERSPROC)(EGLDisplay dpy, EGLSurface surface); typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPINTERVALPROC)(EGLDisplay dpy, EGLint interval); typedef EGLBoolean (EGLAPIENTRY* PFNEGLTERMINATEPROC)(EGLDisplay dpy); + typedef const char* (EGLAPIENTRY* PGNEGLQUERYSTRINGPROC)(EGLDisplay dpy, EGLint name); -#define EGL_IMPORT \ - EGL_IMPORT_FUNC(PFNEGLCHOOSECONFIGPROC, eglChooseConfig); \ - EGL_IMPORT_FUNC(PFNEGLCREATECONTEXTPROC, eglCreateContext); \ - EGL_IMPORT_FUNC(PFNEGLCREATEWINDOWSURFACEPROC, eglCreateWindowSurface); \ - EGL_IMPORT_FUNC(PFNEGLGETDISPLAYPROC, eglGetDisplay); \ - EGL_IMPORT_FUNC(PFNEGLGETERRORPROC, eglGetError); \ - EGL_IMPORT_FUNC(PFNEGLGETPROCADDRESSPROC, eglGetProcAddress); \ - EGL_IMPORT_FUNC(PFNEGLDESTROYCONTEXTPROC, eglDestroyContext); \ - EGL_IMPORT_FUNC(PFNEGLDESTROYSURFACEPROC, eglDestroySurface); \ - EGL_IMPORT_FUNC(PFNEGLINITIALIZEPROC, eglInitialize); \ - EGL_IMPORT_FUNC(PFNEGLMAKECURRENTPROC, eglMakeCurrent); \ - EGL_IMPORT_FUNC(PGNEGLQUERYSTRINGPROC, eglQueryString); \ - EGL_IMPORT_FUNC(PFNEGLSWAPBUFFERSPROC, eglSwapBuffers); \ - EGL_IMPORT_FUNC(PFNEGLSWAPINTERVALPROC, eglSwapInterval); \ - EGL_IMPORT_FUNC(PFNEGLTERMINATEPROC, eglTerminate); +#define EGL_IMPORT \ + EGL_IMPORT_FUNC(PGNEGLBINDAPIPROC, eglBindAPI); \ + EGL_IMPORT_FUNC(PFNEGLCHOOSECONFIGPROC, eglChooseConfig); \ + EGL_IMPORT_FUNC(PFNEGLCREATECONTEXTPROC, eglCreateContext); \ + EGL_IMPORT_FUNC(PFNEGLCREATEPBUFFERSURFACEPROC, eglCreatePbufferSurface); \ + EGL_IMPORT_FUNC(PFNEGLCREATEWINDOWSURFACEPROC, eglCreateWindowSurface); \ + EGL_IMPORT_FUNC(PFNEGLDESTROYCONTEXTPROC, eglDestroyContext); \ + EGL_IMPORT_FUNC(PFNEGLDESTROYSURFACEPROC, eglDestroySurface); \ + EGL_IMPORT_FUNC(PFNEGLGETCURRENTCONTEXTPROC, eglGetCurrentContext); \ + EGL_IMPORT_FUNC(PFNEGLGETCURRENTSURFACEPROC, eglGetCurrentSurface); \ + EGL_IMPORT_FUNC(PFNEGLGETDISPLAYPROC, eglGetDisplay); \ + EGL_IMPORT_FUNC(PFNEGLGETERRORPROC, eglGetError); \ + EGL_IMPORT_FUNC(PFNEGLGETPROCADDRESSPROC, eglGetProcAddress); \ + EGL_IMPORT_FUNC(PFNEGLINITIALIZEPROC, eglInitialize); \ + EGL_IMPORT_FUNC(PFNEGLMAKECURRENTPROC, eglMakeCurrent); \ + EGL_IMPORT_FUNC(PFNEGLSWAPBUFFERSPROC, eglSwapBuffers); \ + EGL_IMPORT_FUNC(PFNEGLSWAPINTERVALPROC, eglSwapInterval); \ + EGL_IMPORT_FUNC(PFNEGLTERMINATEPROC, eglTerminate); \ + EGL_IMPORT_FUNC(PGNEGLQUERYSTRINGPROC, eglQueryString); \ #define EGL_IMPORT_FUNC(_proto, _func) _proto _func EGL_IMPORT @@ -62,13 +70,20 @@ EGL_IMPORT void* eglOpen() { - void* handle = bx::dlopen("libEGL." BX_DL_EXT); + void* handle = bx::dlopen( +#if BX_PLATFORM_LINUX + "libEGL.so.1" +#else + "libEGL." BX_DL_EXT +#endif // BX_PLATFORM_* + ); + BGFX_FATAL(NULL != handle, Fatal::UnableToInitialize, "Failed to load libEGL dynamic library."); -#define EGL_IMPORT_FUNC(_proto, _func) \ - _func = (_proto)bx::dlsym(handle, #_func); \ - BX_TRACE("%p " #_func, _func); \ - BGFX_FATAL(NULL != _func, Fatal::UnableToInitialize, "Failed get " #_func ".") +#define EGL_IMPORT_FUNC(_proto, _func) \ + _func = (_proto)bx::dlsym(handle, #_func); \ + BX_TRACE("%p " #_func, _func); \ + BGFX_FATAL(NULL != _func, Fatal::UnableToInitialize, "Failed get " #_func ".") EGL_IMPORT #undef EGL_IMPORT_FUNC @@ -96,6 +111,43 @@ EGL_IMPORT } #endif // BGFX_USE_GL_DYNAMIC_LIB + +#if BX_PLATFORM_LINUX +# define WL_EGL_IMPORT \ + WL_EGL_FUNC(struct wl_egl_window *, wl_egl_window_create, (struct wl_surface *, int, int) ) \ + WL_EGL_FUNC(void, wl_egl_window_destroy, (struct wl_egl_window *)) \ + WL_EGL_FUNC(void, wl_egl_window_resize, (struct wl_egl_window *, int, int, int, int)) \ + WL_EGL_FUNC(void, wl_egl_window_get_attached_size, (struct wl_egl_window *, int *, int *) ) \ + +# define WL_EGL_FUNC(rt, fname, params) \ + typedef rt(*PFNWLEGL_##fname) params; \ + PFNWLEGL_##fname BGFX_WAYLAND_##fname; + +WL_EGL_IMPORT +# undef WL_EGL_FUNC + + void* waylandEglOpen() + { + void* handle = bx::dlopen("libwayland-egl.so.1"); + BGFX_FATAL(handle != NULL, Fatal::UnableToInitialize, "Could not dlopen() libwayland-egl.so.1"); + +# define WL_EGL_FUNC(rt, fname, params) BGFX_WAYLAND_##fname = (PFNWLEGL_##fname) bx::dlsym(handle, #fname); + WL_EGL_IMPORT +# undef WL_EGL_FUNC + + return handle; + } + + void waylandEglClose(void* _handle) + { + bx::dlclose(_handle); + +# define WL_EGL_FUNC(rt, fname, params) BGFX_WAYLAND_##fname = NULL; + WL_EGL_IMPORT +# undef WL_EGL_FUNC + } +#endif // BX_PLATFORM_LINUX + # define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL # include "glimports.h" @@ -103,29 +155,66 @@ EGL_IMPORT struct SwapChainGL { - SwapChainGL(EGLDisplay _display, EGLConfig _config, EGLContext _context, EGLNativeWindowType _nwh) + SwapChainGL(EGLDisplay _display, EGLConfig _config, EGLContext _context, EGLNativeWindowType _nwh, int _width, int _height) : m_nwh(_nwh) , m_display(_display) +# if BX_PLATFORM_LINUX + , m_eglWindow(NULL) +# endif { - m_surface = eglCreateWindowSurface(m_display, _config, _nwh, NULL); + EGLSurface defaultSurface = eglGetCurrentSurface(EGL_DRAW); + + BX_UNUSED(_width, _height); + + if (EGLNativeWindowType(0) == _nwh) + { + m_surface = eglCreatePbufferSurface(m_display, _config, NULL); + } + else + { +# if BX_PLATFORM_LINUX + if (g_platformData.type == NativeWindowHandleType::Wayland) + { + // A wl_surface needs to be first wrapped in a wl_egl_window + // before it can be used to create the EGLSurface. + m_eglWindow = BGFX_WAYLAND_wl_egl_window_create( (wl_surface*)_nwh, _width, _height); + _nwh = (EGLNativeWindowType) m_eglWindow; + } +# endif + m_surface = eglCreateWindowSurface(m_display, _config, _nwh, NULL); + } + BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface."); m_context = eglCreateContext(m_display, _config, _context, s_contextAttrs); - BX_CHECK(NULL != m_context, "Create swap chain failed: %x", eglGetError() ); + BX_ASSERT(NULL != m_context, "Create swap chain failed: %x", eglGetError() ); makeCurrent(); GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ); GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); swapBuffers(); + GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); swapBuffers(); + + eglMakeCurrent(m_display, defaultSurface, defaultSurface, _context); } ~SwapChainGL() { + EGLSurface defaultSurface = eglGetCurrentSurface(EGL_DRAW); + EGLContext defaultContext = eglGetCurrentContext(); + eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(m_display, m_context); eglDestroySurface(m_display, m_surface); +# if BX_PLATFORM_LINUX + if (m_eglWindow) + { + BGFX_WAYLAND_wl_egl_window_destroy(m_eglWindow); + } +# endif + eglMakeCurrent(m_display, defaultSurface, defaultSurface, defaultContext); } void makeCurrent() @@ -142,19 +231,24 @@ EGL_IMPORT EGLContext m_context; EGLDisplay m_display; EGLSurface m_surface; +# if BX_PLATFORM_LINUX + wl_egl_window *m_eglWindow; +# endif }; # if BX_PLATFORM_RPI static EGL_DISPMANX_WINDOW_T s_dispmanWindow; # endif // BX_PLATFORM_RPI - void GlContext::create(uint32_t _width, uint32_t _height) + void GlContext::create(uint32_t _width, uint32_t _height, uint32_t _flags) { + BX_UNUSED(_flags); + # if BX_PLATFORM_RPI bcm_host_init(); # endif // BX_PLATFORM_RPI - m_eglLibrary = eglOpen(); + m_eglDll = eglOpen(); if (NULL == g_platformData.context) { @@ -173,7 +267,7 @@ EGL_IMPORT } # endif // BX_PLATFORM_WINDOWS - m_display = eglGetDisplay(ndt); + m_display = eglGetDisplay(NULL == ndt ? EGL_DEFAULT_DISPLAY : ndt); BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display); EGLint major = 0; @@ -195,23 +289,52 @@ EGL_IMPORT BX_TRACE("Supported EGL extensions:"); dumpExtensions(extensions); - // https://www.khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_recordable.txt + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) + { + EGLBoolean ok = eglBindAPI(EGL_OPENGL_API); + BGFX_FATAL(ok, Fatal::UnableToInitialize, "Could not set API! error: %d", eglGetError()); + } + const bool hasEglAndroidRecordable = !bx::findIdentifierMatch(extensions, "EGL_ANDROID_recordable").isEmpty(); + const uint32_t glVersion = !!BGFX_CONFIG_RENDERER_OPENGL + ? BGFX_CONFIG_RENDERER_OPENGL + : BGFX_CONFIG_RENDERER_OPENGLES + ; + +#if BX_PLATFORM_ANDROID + const uint32_t msaa = (_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + const uint32_t msaaSamples = msaa == 0 ? 0 : 1<<msaa; + m_msaaContext = true; +#endif // BX_PLATFORM_ANDROID + + const bool headless = EGLNativeWindowType(0) == nwh; + EGLint attrs[] = { - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_RENDERABLE_TYPE, !!BGFX_CONFIG_RENDERER_OPENGL + ? EGL_OPENGL_BIT + : (glVersion >= 30) ? EGL_OPENGL_ES3_BIT_KHR : EGL_OPENGL_ES2_BIT + , + + EGL_SURFACE_TYPE, headless ? EGL_PBUFFER_BIT : EGL_WINDOW_BIT, + + EGL_BLUE_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, + EGL_ALPHA_SIZE, 8, # if BX_PLATFORM_ANDROID EGL_DEPTH_SIZE, 16, + EGL_SAMPLES, (EGLint)msaaSamples, # else EGL_DEPTH_SIZE, 24, # endif // BX_PLATFORM_ EGL_STENCIL_SIZE, 8, // Android Recordable surface - hasEglAndroidRecordable ? 0x3142 : EGL_NONE, - hasEglAndroidRecordable ? 1 : EGL_NONE, + hasEglAndroidRecordable ? EGL_RECORDABLE_ANDROID : EGL_NONE, + hasEglAndroidRecordable ? 1 : EGL_NONE, EGL_NONE }; @@ -253,14 +376,43 @@ EGL_IMPORT vc_dispmanx_update_submit_sync(dispmanUpdate); # endif // BX_PLATFORM_ANDROID - m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL); +# if BX_PLATFORM_LINUX + if (g_platformData.type == NativeWindowHandleType::Wayland) + { + m_waylandEglDll = waylandEglOpen(); + } +# endif + if (headless) + { + EGLint pbAttribs[] = + { + EGL_WIDTH, EGLint(_width), + EGL_HEIGHT, EGLint(_height), + + EGL_NONE + }; + + m_surface = eglCreatePbufferSurface(m_display, m_config, pbAttribs); + } + else + { +# if BX_PLATFORM_LINUX + if (g_platformData.type == NativeWindowHandleType::Wayland) + { + // A wl_surface needs to be first wrapped in a wl_egl_window + // before it can be used to create the EGLSurface. + m_eglWindow = BGFX_WAYLAND_wl_egl_window_create( (wl_surface*)nwh, _width, _height); + nwh = (EGLNativeWindowType) m_eglWindow; + } +# endif + m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL); + } + BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface."); const bool hasEglKhrCreateContext = !bx::findIdentifierMatch(extensions, "EGL_KHR_create_context").isEmpty(); const bool hasEglKhrNoError = !bx::findIdentifierMatch(extensions, "EGL_KHR_create_context_no_error").isEmpty(); - const uint32_t gles = BGFX_CONFIG_RENDERER_OPENGLES; - for (uint32_t ii = 0; ii < 2; ++ii) { bx::StaticMemoryBlockWriter writer(s_contextAttrs, sizeof(s_contextAttrs) ); @@ -272,11 +424,17 @@ EGL_IMPORT # else if (hasEglKhrCreateContext) { - bx::write(&writer, EGLint(EGL_CONTEXT_MAJOR_VERSION_KHR) ); - bx::write(&writer, EGLint(gles / 10) ); + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) + { + bx::write(&writer, EGLint(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR), bx::ErrorAssert{}); + bx::write(&writer, EGLint(EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR), bx::ErrorAssert{}); + } + + bx::write(&writer, EGLint(EGL_CONTEXT_MAJOR_VERSION_KHR), bx::ErrorAssert{}); + bx::write(&writer, EGLint(glVersion / 10), bx::ErrorAssert{}); - bx::write(&writer, EGLint(EGL_CONTEXT_MINOR_VERSION_KHR) ); - bx::write(&writer, EGLint(gles % 10) ); + bx::write(&writer, EGLint(EGL_CONTEXT_MINOR_VERSION_KHR), bx::ErrorAssert{}); + bx::write(&writer, EGLint(glVersion % 10), bx::ErrorAssert{}); flags |= BGFX_CONFIG_DEBUG && hasEglKhrNoError ? 0 | EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR @@ -291,18 +449,18 @@ EGL_IMPORT : 0 ; - bx::write(&writer, EGLint(EGL_CONTEXT_FLAGS_KHR) ); - bx::write(&writer, flags); + bx::write(&writer, EGLint(EGL_CONTEXT_FLAGS_KHR), bx::ErrorAssert{} ); + bx::write(&writer, flags, bx::ErrorAssert{}); } } else # endif // BX_PLATFORM_RPI { - bx::write(&writer, EGLint(EGL_CONTEXT_CLIENT_VERSION) ); - bx::write(&writer, 2); + bx::write(&writer, EGLint(EGL_CONTEXT_CLIENT_VERSION), bx::ErrorAssert{} ); + bx::write(&writer, EGLint(glVersion / 10), bx::ErrorAssert{} ); } - bx::write(&writer, EGLint(EGL_NONE) ); + bx::write(&writer, EGLint(EGL_NONE), bx::ErrorAssert{} ); m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, s_contextAttrs); if (NULL != m_context) @@ -329,16 +487,26 @@ EGL_IMPORT void GlContext::destroy() { + BX_TRACE("GLContext::destroy()"); if (NULL != m_display) { eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(m_display, m_context); eglDestroySurface(m_display, m_surface); +# if BX_PLATFORM_LINUX + if (m_eglWindow) + { + BGFX_WAYLAND_wl_egl_window_destroy(m_eglWindow); + waylandEglClose(m_waylandEglDll); + m_waylandEglDll = NULL; + } +# endif eglTerminate(m_display); m_context = NULL; } - eglClose(m_eglLibrary); + eglClose(m_eglDll); + m_eglDll = NULL; # if BX_PLATFORM_RPI bcm_host_deinit(); @@ -363,7 +531,12 @@ EGL_IMPORT ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format); } # elif BX_PLATFORM_EMSCRIPTEN - emscripten_set_canvas_size(_width, _height); + EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(HTML5_TARGET_CANVAS_SELECTOR, _width, _height) ); +# elif BX_PLATFORM_LINUX + if (NULL != m_eglWindow) + { + BGFX_WAYLAND_wl_egl_window_resize(m_eglWindow, _width, _height, 0, 0); + } # else BX_UNUSED(_width, _height); # endif // BX_PLATFORM_* @@ -378,18 +551,18 @@ EGL_IMPORT uint64_t GlContext::getCaps() const { return BX_ENABLED(0 - | BX_PLATFORM_LINUX - | BX_PLATFORM_WINDOWS - | BX_PLATFORM_ANDROID - ) + | BX_PLATFORM_LINUX + | BX_PLATFORM_WINDOWS + | BX_PLATFORM_ANDROID + ) ? BGFX_CAPS_SWAP_CHAIN : 0 ; } - SwapChainGL* GlContext::createSwapChain(void* _nwh) + SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height) { - return BX_NEW(g_allocator, SwapChainGL)(m_display, m_config, m_context, (EGLNativeWindowType)_nwh); + return BX_NEW(g_allocator, SwapChainGL)(m_display, m_config, m_context, (EGLNativeWindowType)_nwh, _width, _height); } void GlContext::destroySwapChain(SwapChainGL* _swapChain) @@ -437,29 +610,51 @@ EGL_IMPORT void GlContext::import() { BX_TRACE("Import:"); + # if BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX - void* glesv2 = bx::dlopen("libGLESv2." BX_DL_EXT); -# define GL_EXTENSION(_optional, _proto, _func, _import) \ - { \ - if (NULL == _func) \ - { \ - _func = (_proto)bx::dlsym(glesv2, #_import); \ - BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ - BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_import); \ - } \ - } +# if BX_PLATFORM_WINDOWS +# define LIBRARY_NAME "libGL.dll" +# elif BX_PLATFORM_LINUX +# if BGFX_CONFIG_RENDERER_OPENGL +# define LIBRARY_NAME "libGL.so.1" +# else +# define LIBRARY_NAME "libGLESv2.so.2" +# endif +# endif + + void* lib = bx::dlopen(LIBRARY_NAME); + +# define GL_EXTENSION(_optional, _proto, _func, _import) \ + { \ + if (NULL == _func) \ + { \ + _func = bx::dlsym<_proto>(lib, #_import); \ + BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ + BGFX_FATAL(_optional || NULL != _func \ + , Fatal::UnableToInitialize \ + , "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")" \ + , #_import); \ + } \ + } # else -# define GL_EXTENSION(_optional, _proto, _func, _import) \ - { \ - if (NULL == _func) \ - { \ - _func = (_proto)eglGetProcAddress(#_import); \ - BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ - BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_import); \ - } \ - } +# define GL_EXTENSION(_optional, _proto, _func, _import) \ + { \ + if (NULL == _func) \ + { \ + _func = reinterpret_cast<_proto>(eglGetProcAddress(#_import) ); \ + BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ + BGFX_FATAL(_optional || NULL != _func \ + , Fatal::UnableToInitialize \ + , "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")" \ + , #_import); \ + } \ + } + # endif // BX_PLATFORM_ + # include "glimports.h" + +# undef GL_EXTENSION } } /* namespace gl */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/glcontext_egl.h b/3rdparty/bgfx/src/glcontext_egl.h index ac7275666f4..28e7a5d49fb 100644 --- a/3rdparty/bgfx/src/glcontext_egl.h +++ b/3rdparty/bgfx/src/glcontext_egl.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_GLCONTEXT_EGL_H_HEADER_GUARD @@ -10,11 +10,22 @@ #include <EGL/egl.h> #include <EGL/eglext.h> + +struct wl_egl_window; + +// EGL pulls X11 crap... +#if defined(None) +# undef None +#endif // defined(None) + #if defined(Success) -// X11 defines Success # undef Success #endif // defined(Success) +#if defined(Status) +# undef Status +#endif // defined(Status) + namespace bgfx { namespace gl { struct SwapChainGL; @@ -22,19 +33,25 @@ namespace bgfx { namespace gl struct GlContext { GlContext() - : m_current(NULL) + : m_eglDll(NULL) + , m_current(NULL) , m_context(NULL) , m_display(NULL) , m_surface(NULL) +#if BX_PLATFORM_LINUX + , m_waylandEglDll(NULL) + , m_eglWindow(NULL) +#endif + , m_msaaContext(false) { } - void create(uint32_t _width, uint32_t _height); + void create(uint32_t _width, uint32_t _height, uint32_t _flags); void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); uint64_t getCaps() const; - SwapChainGL* createSwapChain(void* _nwh); + SwapChainGL* createSwapChain(void* _nwh, int _w, int _h); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); void makeCurrent(SwapChainGL* _swapChain = NULL); @@ -46,12 +63,18 @@ namespace bgfx { namespace gl return NULL != m_context; } - void* m_eglLibrary; + void* m_eglDll; SwapChainGL* m_current; EGLConfig m_config; EGLContext m_context; EGLDisplay m_display; EGLSurface m_surface; +#if BX_PLATFORM_LINUX + void* m_waylandEglDll; + struct wl_egl_window *m_eglWindow; +#endif + // true when MSAA is handled by the context instead of using MSAA FBO + bool m_msaaContext; }; } /* namespace gl */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/glcontext_glx.cpp b/3rdparty/bgfx/src/glcontext_glx.cpp deleted file mode 100644 index b968267e9c0..00000000000 --- a/3rdparty/bgfx/src/glcontext_glx.cpp +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause - */ - -#include "bgfx_p.h" - -#if (BX_PLATFORM_BSD || BX_PLATFORM_LINUX) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL) -# include "renderer_gl.h" - -# if BGFX_USE_GLX -# define GLX_GLXEXT_PROTOTYPES -# include <glx/glxext.h> - -// will include X11 which #defines None... -#undef None - -namespace bgfx { namespace gl -{ - typedef int (*PFNGLXSWAPINTERVALMESAPROC)(uint32_t _interval); - - PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB; - PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT; - PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA; - PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI; - -# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func -# include "glimports.h" - - struct SwapChainGL - { - SwapChainGL(::Display* display, ::Window _window, XVisualInfo* _visualInfo, GLXContext _context) - : m_display(display) - , m_window(_window) - { - m_context = glXCreateContext(m_display, _visualInfo, _context, GL_TRUE); - } - - ~SwapChainGL() - { - glXMakeCurrent(m_display, 0, 0); - glXDestroyContext(m_display, m_context); - } - - void makeCurrent() - { - glXMakeCurrent(m_display, m_window, m_context); - } - - void swapBuffers() - { - glXSwapBuffers(m_display, m_window); - } - - ::Display* m_display; - Window m_window; - GLXContext m_context; - }; - - void GlContext::create(uint32_t _width, uint32_t _height) - { - BX_UNUSED(_width, _height); - - m_context = (GLXContext)g_platformData.context; - m_display = (::Display*)g_platformData.ndt; - - // It's possible the user has provided the window handle, but not - // the display handle. If this is the case, try opening the default - // display - if (NULL == m_display) - { - m_display = XOpenDisplay(NULL); - BGFX_FATAL(m_display, Fatal::UnableToInitialize, "XOpenDisplay(NULL) : Failed to open default display"); - } - - if (NULL == g_platformData.context) - { - XLockDisplay(m_display); - - int major, minor; - bool version = glXQueryVersion(m_display, &major, &minor); - BGFX_FATAL(version, Fatal::UnableToInitialize, "Failed to query GLX version"); - BGFX_FATAL( (major == 1 && minor >= 2) || major > 1 - , Fatal::UnableToInitialize - , "GLX version is not >=1.2 (%d.%d)." - , major - , minor - ); - - int32_t screen = DefaultScreen(m_display); - - const char* extensions = glXQueryExtensionsString(m_display, screen); - BX_TRACE("GLX extensions:"); - dumpExtensions(extensions); - - const int attrsGlx[] = - { - GLX_RENDER_TYPE, GLX_RGBA_BIT, - GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, - GLX_DOUBLEBUFFER, true, - GLX_RED_SIZE, 8, - GLX_BLUE_SIZE, 8, - GLX_GREEN_SIZE, 8, - // GLX_ALPHA_SIZE, 8, - GLX_DEPTH_SIZE, 24, - GLX_STENCIL_SIZE, 8, - 0, - }; - - // Find suitable config - GLXFBConfig bestConfig = NULL; - - int numConfigs; - GLXFBConfig* configs = glXChooseFBConfig(m_display, screen, attrsGlx, &numConfigs); - - BX_TRACE("glX num configs %d", numConfigs); - - for (int ii = 0; ii < numConfigs; ++ii) - { - m_visualInfo = glXGetVisualFromFBConfig(m_display, configs[ii]); - if (NULL != m_visualInfo) - { - BX_TRACE("---"); - bool valid = true; - for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != 0; attr += 2) - { - int value; - glXGetFBConfigAttrib(m_display, configs[ii], attrsGlx[attr], &value); - BX_TRACE("glX %d/%d %2d: %4x, %8x (%8x%s)" - , ii - , numConfigs - , attr/2 - , attrsGlx[attr] - , value - , attrsGlx[attr + 1] - , value < attrsGlx[attr + 1] ? " *" : "" - ); - - if (value < attrsGlx[attr + 1]) - { - valid = false; -#if !BGFX_CONFIG_DEBUG - break; -#endif // BGFX_CONFIG_DEBUG - } - } - - if (valid) - { - bestConfig = configs[ii]; - BX_TRACE("Best config %d.", ii); - break; - } - } - - XFree(m_visualInfo); - m_visualInfo = NULL; - } - - XFree(configs); - BGFX_FATAL(m_visualInfo, Fatal::UnableToInitialize, "Failed to find a suitable X11 display configuration."); - - BX_TRACE("Create GL 2.1 context."); - m_context = glXCreateContext(m_display, m_visualInfo, 0, GL_TRUE); - BGFX_FATAL(NULL != m_context, Fatal::UnableToInitialize, "Failed to create GL 2.1 context."); - -#if BGFX_CONFIG_RENDERER_OPENGL >= 31 - glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB"); - - if (NULL != glXCreateContextAttribsARB) - { - BX_TRACE("Create GL 3.1 context."); - int32_t flags = BGFX_CONFIG_DEBUG ? GLX_CONTEXT_DEBUG_BIT_ARB : 0; - const int contextAttrs[] = - { - GLX_CONTEXT_MAJOR_VERSION_ARB, 3, - GLX_CONTEXT_MINOR_VERSION_ARB, 1, - GLX_CONTEXT_FLAGS_ARB, flags, - GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, - 0, - }; - - GLXContext context = glXCreateContextAttribsARB(m_display, bestConfig, 0, true, contextAttrs); - - if (NULL != context) - { - glXDestroyContext(m_display, m_context); - m_context = context; - } - } -#else - BX_UNUSED(bestConfig); -#endif // BGFX_CONFIG_RENDERER_OPENGL >= 31 - - XUnlockDisplay(m_display); - } - - import(); - - glXMakeCurrent(m_display, (::Window)g_platformData.nwh, m_context); - m_current = NULL; - - glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT"); - if (NULL != glXSwapIntervalEXT) - { - BX_TRACE("Using glXSwapIntervalEXT."); - glXSwapIntervalEXT(m_display, (::Window)g_platformData.nwh, 0); - } - else - { - glXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalMESA"); - if (NULL != glXSwapIntervalMESA) - { - BX_TRACE("Using glXSwapIntervalMESA."); - glXSwapIntervalMESA(0); - } - else - { - glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI"); - if (NULL != glXSwapIntervalSGI) - { - BX_TRACE("Using glXSwapIntervalSGI."); - glXSwapIntervalSGI(0); - } - } - } - - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - glXSwapBuffers(m_display, (::Window)g_platformData.nwh); - - g_internalData.context = m_context; - } - - void GlContext::destroy() - { - glXMakeCurrent(m_display, 0, 0); - if (NULL == g_platformData.context) - { - glXDestroyContext(m_display, m_context); - XFree(m_visualInfo); - } - // If we opened the display, have to close it - if (NULL == g_platformData.ndt) - { - XCloseDisplay(m_display); - } - m_context = NULL; - m_visualInfo = NULL; - m_display = NULL; - } - - void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, uint32_t _flags) - { - bool vsync = !!(_flags&BGFX_RESET_VSYNC); - int32_t interval = vsync ? 1 : 0; - - if (NULL != glXSwapIntervalEXT) - { - glXSwapIntervalEXT(m_display, (::Window)g_platformData.nwh, interval); - } - else if (NULL != glXSwapIntervalMESA) - { - glXSwapIntervalMESA(interval); - } - else if (NULL != glXSwapIntervalSGI) - { - glXSwapIntervalSGI(interval); - } - } - - uint64_t GlContext::getCaps() const - { - return BGFX_CAPS_SWAP_CHAIN; - } - - SwapChainGL* GlContext::createSwapChain(void* _nwh) - { - return BX_NEW(g_allocator, SwapChainGL)(m_display, (::Window)_nwh, m_visualInfo, m_context); - } - - void GlContext::destroySwapChain(SwapChainGL* _swapChain) - { - BX_DELETE(g_allocator, _swapChain); - glXMakeCurrent(m_display, (::Window)g_platformData.nwh, m_context); - } - - void GlContext::swap(SwapChainGL* _swapChain) - { - makeCurrent(_swapChain); - - if (NULL == _swapChain) - { - glXSwapBuffers(m_display, (::Window)g_platformData.nwh); - } - else - { - _swapChain->swapBuffers(); - } - } - - void GlContext::makeCurrent(SwapChainGL* _swapChain) - { - if (m_current != _swapChain) - { - m_current = _swapChain; - - if (NULL == _swapChain) - { - glXMakeCurrent(m_display, (::Window)g_platformData.nwh, m_context); - } - else - { - _swapChain->makeCurrent(); - } - } - } - - void GlContext::import() - { -# define GL_EXTENSION(_optional, _proto, _func, _import) \ - { \ - if (NULL == _func) \ - { \ - _func = (_proto)glXGetProcAddress( (const GLubyte*)#_import); \ - BX_TRACE("%p " #_func " (" #_import ")", _func); \ - BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. glXGetProcAddress %s", #_import); \ - } \ - } -# include "glimports.h" - } - -} /* namespace gl */ } // namespace bgfx - -# endif // BGFX_USE_GLX - -#endif // (BX_PLATFORM_BSD || BX_PLATFORM_LINUX) && (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL) diff --git a/3rdparty/bgfx/src/glcontext_glx.h b/3rdparty/bgfx/src/glcontext_glx.h deleted file mode 100644 index 622f6ab98de..00000000000 --- a/3rdparty/bgfx/src/glcontext_glx.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause - */ - -#ifndef BGFX_GLCONTEXT_GLX_H_HEADER_GUARD -#define BGFX_GLCONTEXT_GLX_H_HEADER_GUARD - -#if BGFX_USE_GLX - -# include <X11/Xlib.h> -# include <GL/glx.h> - -namespace bgfx { namespace gl -{ - struct SwapChainGL; - - struct GlContext - { - GlContext() - : m_current(NULL) - , m_context(0) - , m_visualInfo(NULL) - , m_display(NULL) - { - } - - void create(uint32_t _width, uint32_t _height); - void destroy(); - void resize(uint32_t _width, uint32_t _height, uint32_t _flags); - - uint64_t getCaps() const; - SwapChainGL* createSwapChain(void* _nwh); - void destroySwapChain(SwapChainGL* _swapChain); - void swap(SwapChainGL* _swapChain = NULL); - void makeCurrent(SwapChainGL* _swapChain = NULL); - - void import(); - - bool isValid() const - { - return 0 != m_context; - } - - SwapChainGL* m_current; - GLXContext m_context; - XVisualInfo* m_visualInfo; - ::Display* m_display; - }; -} /* namespace gl */ } // namespace bgfx - -#endif // BGFX_USE_GLX - -#endif // BGFX_GLCONTEXT_GLX_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/glcontext_html5.cpp b/3rdparty/bgfx/src/glcontext_html5.cpp new file mode 100644 index 00000000000..cce0f299da8 --- /dev/null +++ b/3rdparty/bgfx/src/glcontext_html5.cpp @@ -0,0 +1,240 @@ +/* + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "bgfx_p.h" + +#if BGFX_CONFIG_RENDERER_OPENGLES +# include "renderer_gl.h" + +# if BGFX_USE_HTML5 + +# include "emscripten.h" + +// from emscripten gl.c, because we're not going to go +// through egl +extern "C" void* emscripten_GetProcAddress(const char *name_); +extern "C" void* emscripten_webgl1_get_proc_address(const char *name_); +extern "C" void* emscripten_webgl2_get_proc_address(const char *name_); + +namespace bgfx { namespace gl +{ + +# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL +# include "glimports.h" + + static EmscriptenWebGLContextAttributes s_attrs; + + struct SwapChainGL + { + SwapChainGL(int _context, const char* _canvas) + : m_context(_context) + { + m_canvas = (char*)BX_ALLOC(g_allocator, strlen(_canvas) + 1); + strcpy(m_canvas, _canvas); + + makeCurrent(); + GL_CHECK(glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ); + GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); + swapBuffers(); + GL_CHECK(glClear(GL_COLOR_BUFFER_BIT) ); + swapBuffers(); + } + + ~SwapChainGL() + { + EMSCRIPTEN_CHECK(emscripten_webgl_destroy_context(m_context) ); + BX_FREE(g_allocator, m_canvas); + } + + void makeCurrent() + { + EMSCRIPTEN_CHECK(emscripten_webgl_make_context_current(m_context) ); + } + + void swapBuffers() + { + // There is no swapBuffers equivalent. A swap happens whenever control is returned back + // to the browser. + } + + int m_context; + char* m_canvas; + }; + + void GlContext::create(uint32_t _width, uint32_t _height, uint32_t /*_flags*/) + { + // assert? + if (m_primary != NULL) + return; + + const char* canvas = (const char*) g_platformData.nwh; + + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE) g_platformData.context; + if (context > 0) + { + if (emscripten_webgl_get_context_attributes(context, &s_attrs) >= 0) + { + import(s_attrs.majorVersion); + m_primary = BX_NEW(g_allocator, SwapChainGL)(context, canvas); + } + else + { + BX_TRACE("Invalid WebGL context. (Canvas handle: '%s', context handle: %d)", canvas, context); + } + } + else + { + m_primary = createSwapChain((void*)canvas, (int)_width, (int)_height); + } + + if (0 != _width + && 0 != _height) + { + EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(canvas, (int)_width, (int)_height) ); + } + + makeCurrent(m_primary); + } + + void GlContext::destroy() + { + if (m_primary) + { + if (m_current == m_primary) + { + m_current = NULL; + } + + BX_DELETE(g_allocator, m_primary); + m_primary = NULL; + } + } + + void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t /* _flags */) + { + if (m_primary == NULL) + { + return; + } + + EMSCRIPTEN_CHECK(emscripten_set_canvas_element_size(m_primary->m_canvas, (int) _width, (int) _height) ); + } + + SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height) + { + emscripten_webgl_init_context_attributes(&s_attrs); + BX_UNUSED(_width, _height); + + // Work around bug https://bugs.chromium.org/p/chromium/issues/detail?id=1045643 in Chrome + // by having alpha always enabled. + s_attrs.alpha = true; + s_attrs.premultipliedAlpha = false; + s_attrs.depth = true; + s_attrs.stencil = true; + s_attrs.enableExtensionsByDefault = true; + s_attrs.antialias = false; + + s_attrs.minorVersion = 0; + const char* canvas = (const char*) _nwh; + int32_t error = 0; + + for (int version = 2; version >= 1; --version) + { + s_attrs.majorVersion = version; + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(canvas, &s_attrs); + + if (context > 0) + { + EMSCRIPTEN_CHECK(emscripten_webgl_make_context_current(context) ); + + SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(context, canvas); + + import(version); + + return swapChain; + } + + error = (int32_t)context; + } + + BX_TRACE("Failed to create WebGL context. (Canvas handle: '%s', last attempt error %d)", canvas, error); + BX_UNUSED(error); + + return NULL; + } + + uint64_t GlContext::getCaps() const + { + return BGFX_CAPS_SWAP_CHAIN; + } + + void GlContext::destroySwapChain(SwapChainGL* _swapChain) + { + BX_DELETE(g_allocator, _swapChain); + } + + void GlContext::swap(SwapChainGL* /* _swapChain */) + { + } + + void GlContext::makeCurrent(SwapChainGL* _swapChain) + { + if (m_current != _swapChain) + { + m_current = _swapChain; + + if (NULL == _swapChain) + { + if (NULL != m_primary) + { + m_primary->makeCurrent(); + } + } + else + { + _swapChain->makeCurrent(); + } + } + } + + template<typename Fn> + static Fn getProcAddress(int _version, const char* _name) + { + Fn func = reinterpret_cast<Fn>(emscripten_webgl1_get_proc_address(_name) ); + if (NULL == func && _version >= 2) + { + func = reinterpret_cast<Fn>(emscripten_webgl2_get_proc_address(_name) ); + } + + return func; + } + + void GlContext::import(int _webGLVersion) + { + BX_TRACE("Import:"); + +# define GL_EXTENSION(_optional, _proto, _func, _import) \ + { \ + if (NULL == _func) \ + { \ + _func = getProcAddress<_proto>(_webGLVersion, #_import); \ + BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ + BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize \ + , "Failed to create WebGL/OpenGLES context. GetProcAddress(\"%s\")" \ + , #_import \ + ); \ + } \ + } + +# include "glimports.h" + +# undef GL_EXTENSION + + } + +} /* namespace gl */ } // namespace bgfx + +# endif // BGFX_USE_EGL +#endif // (BGFX_CONFIG_RENDERER_OPENGLES || BGFX_CONFIG_RENDERER_OPENGL) diff --git a/3rdparty/bgfx/src/glcontext_html5.h b/3rdparty/bgfx/src/glcontext_html5.h new file mode 100644 index 00000000000..e1b93799a75 --- /dev/null +++ b/3rdparty/bgfx/src/glcontext_html5.h @@ -0,0 +1,50 @@ +/* + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#ifndef BGFX_GLCONTEXT_HTML5_H_HEADER_GUARD +#define BGFX_GLCONTEXT_HTML5_H_HEADER_GUARD + +#if BGFX_USE_HTML5 + +namespace bgfx { namespace gl +{ + struct SwapChainGL; + + struct GlContext + { + GlContext() + : m_current(NULL) + , m_primary(NULL) + , m_msaaContext(false) + { + } + + void create(uint32_t _width, uint32_t _height, uint32_t _flags); + void destroy(); + void resize(uint32_t _width, uint32_t _height, uint32_t _flags); + + uint64_t getCaps() const; + SwapChainGL* createSwapChain(void* _nwh, int _width, int _height); + void destroySwapChain(SwapChainGL* _swapChain); + void swap(SwapChainGL* _swapChain = NULL); + void makeCurrent(SwapChainGL* _swapChain = NULL); + + void import(int webGLVersion); + + bool isValid() const + { + return NULL != m_primary; + } + + SwapChainGL* m_current; + SwapChainGL* m_primary; + // true when MSAA is handled by the context instead of using MSAA FBO + bool m_msaaContext; + }; +} /* namespace gl */ } // namespace bgfx + +#endif // BGFX_USE_HTML5 + +#endif // BGFX_GLCONTEXT_HTML5_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/glcontext_nsgl.h b/3rdparty/bgfx/src/glcontext_nsgl.h index e6a6db9a223..ed331871e35 100644 --- a/3rdparty/bgfx/src/glcontext_nsgl.h +++ b/3rdparty/bgfx/src/glcontext_nsgl.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_GLCONTEXT_NSGL_H_HEADER_GUARD @@ -17,15 +17,16 @@ namespace bgfx { namespace gl GlContext() : m_context(NULL) , m_view(NULL) + , m_msaaContext(false) { } - void create(uint32_t _width, uint32_t _height); + void create(uint32_t _width, uint32_t _height, uint32_t _flags); void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); uint64_t getCaps() const; - SwapChainGL* createSwapChain(void* _nwh); + SwapChainGL* createSwapChain(void* _nwh, int _width, int _height); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); void makeCurrent(SwapChainGL* _swapChain = NULL); @@ -39,6 +40,9 @@ namespace bgfx { namespace gl void* m_context; void* m_view; + // true when MSAA is handled by the context instead of using MSAA FBO + bool m_msaaContext; + }; } /* namespace gl */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/glcontext_nsgl.mm b/3rdparty/bgfx/src/glcontext_nsgl.mm index af35e9c5ebf..93dd421205f 100644 --- a/3rdparty/bgfx/src/glcontext_nsgl.mm +++ b/3rdparty/bgfx/src/glcontext_nsgl.mm @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -11,6 +11,8 @@ # include <Cocoa/Cocoa.h> # include <bx/os.h> +BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wdeprecated-declarations") + namespace bgfx { namespace gl { @@ -19,22 +21,119 @@ namespace bgfx { namespace gl struct SwapChainGL { - SwapChainGL(void* _nwh) + SwapChainGL(void* _nwh,NSOpenGLContext *_context) { - BX_UNUSED(_nwh); + NSObject* nwh=(NSObject*)_nwh; + + NSWindow* nsWindow = nil; + NSView* contentView = nil; + if ([nwh isKindOfClass:[NSView class]]) + { + contentView = (NSView*)nwh; + } + else if ([nwh isKindOfClass:[NSWindow class]]) + { + nsWindow = (NSWindow*)nwh; + contentView = [nsWindow contentView]; + } + +#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) + NSOpenGLPixelFormatAttribute profile = +#if BGFX_CONFIG_RENDERER_OPENGL >= 31 + NSOpenGLProfileVersion3_2Core +#else + NSOpenGLProfileVersionLegacy +#endif // BGFX_CONFIG_RENDERER_OPENGL >= 31 + ; +#endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) + + NSOpenGLPixelFormatAttribute pixelFormatAttributes[] = { +#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) + NSOpenGLPFAOpenGLProfile, profile, +#endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) + NSOpenGLPFAColorSize, 24, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFADepthSize, 24, + NSOpenGLPFAStencilSize, 8, + NSOpenGLPFADoubleBuffer, true, + NSOpenGLPFAAccelerated, true, + NSOpenGLPFANoRecovery, true, + 0, 0, + }; + + NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; + BGFX_FATAL(NULL != pixelFormat, Fatal::UnableToInitialize, "Failed to initialize pixel format."); + + NSRect glViewRect = [contentView bounds]; + NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat]; + + + // GLFW creates a helper contentView that handles things like keyboard and drag and + // drop events. We don't want to clobber that view if it exists. Instead we just + // add ourselves as a subview and make the view resize automatically. + if (nil != contentView) + { + [glView setAutoresizingMask:( NSViewHeightSizable | + NSViewWidthSizable | + NSViewMinXMargin | + NSViewMaxXMargin | + NSViewMinYMargin | + NSViewMaxYMargin )]; + [contentView addSubview:glView]; + } + else + { + if (nil != nsWindow) + [nsWindow setContentView:glView]; + } + + NSOpenGLContext* glContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:_context]; + BGFX_FATAL(NULL != glContext, Fatal::UnableToInitialize, "Failed to initialize GL context."); + + void (^attachBlock)(void) = ^(void) { + [glView setOpenGLContext: glContext]; + [glContext setView:glView]; + }; + + if([NSThread isMainThread]) + { + attachBlock(); + } + else + { + dispatch_sync(dispatch_get_main_queue(),attachBlock); + } + + [pixelFormat release]; + + [glContext makeCurrentContext]; + GLint interval = 0; + [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; + + + m_view = glView; + m_context = glContext; } ~SwapChainGL() { + if(m_context!=nil) [m_context release]; + if(m_view!=nil) [m_view release]; } void makeCurrent() { + [m_context makeCurrentContext]; } void swapBuffers() { + [m_context makeCurrentContext]; + [m_context flushBuffer]; } + + NSOpenGLView *m_view; + NSOpenGLContext *m_context; }; class AutoreleasePoolHolder @@ -57,17 +156,29 @@ namespace bgfx { namespace gl static void* s_opengl = NULL; - void GlContext::create(uint32_t _width, uint32_t _height) + void GlContext::create(uint32_t _width, uint32_t _height, uint32_t /*_flags*/) { BX_UNUSED(_width, _height); s_opengl = bx::dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL"); - BX_CHECK(NULL != s_opengl, "OpenGL dynamic library is not found!"); + BX_ASSERT(NULL != s_opengl, "OpenGL dynamic library is not found!"); const AutoreleasePoolHolder pool; - NSWindow* nsWindow = (NSWindow*)g_platformData.nwh; + NSObject* nwh = (NSObject*)g_platformData.nwh; m_context = g_platformData.context; + NSWindow* nsWindow = nil; + NSView* contentView = nil; + if ([nwh isKindOfClass:[NSView class]]) + { + contentView = (NSView*)nwh; + } + else if ([nwh isKindOfClass:[NSWindow class]]) + { + nsWindow = (NSWindow*)nwh; + contentView = [nsWindow contentView]; + } + if (NULL == g_platformData.context) { #if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) @@ -97,14 +208,13 @@ namespace bgfx { namespace gl NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes]; BGFX_FATAL(NULL != pixelFormat, Fatal::UnableToInitialize, "Failed to initialize pixel format."); - NSRect glViewRect = [[nsWindow contentView] bounds]; + NSRect glViewRect = [contentView bounds]; NSOpenGLView* glView = [[NSOpenGLView alloc] initWithFrame:glViewRect pixelFormat:pixelFormat]; [pixelFormat release]; // GLFW creates a helper contentView that handles things like keyboard and drag and // drop events. We don't want to clobber that view if it exists. Instead we just // add ourselves as a subview and make the view resize automatically. - NSView *contentView = [nsWindow contentView]; if (nil != contentView) { [glView setAutoresizingMask:( NSViewHeightSizable | @@ -117,7 +227,8 @@ namespace bgfx { namespace gl } else { - [nsWindow setContentView:glView]; + if (nil != nsWindow) + [nsWindow setContentView:glView]; } NSOpenGLContext* glContext = [glView openGLContext]; @@ -127,15 +238,30 @@ namespace bgfx { namespace gl GLint interval = 0; [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; - // When initializing NSOpenGLView programatically (as we are), this sometimes doesn't + // When initializing NSOpenGLView programmatically (as we are), this sometimes doesn't // get hooked up properly (especially when there are existing window elements). This ensures // we are valid. Otherwise, you'll probably get a GL_INVALID_FRAMEBUFFER_OPERATION when // trying to glClear() for the first time. - [glContext setView:glView]; + void (^set_view)(void) = ^(void) { + [glContext setView:glView]; + }; + + if([NSThread isMainThread]) + { + set_view(); + } + else + { + dispatch_sync(dispatch_get_main_queue(),set_view); + } m_view = glView; m_context = glContext; } + else + { + [(NSOpenGLContext*)g_platformData.context makeCurrentContext]; + } import(); @@ -161,32 +287,48 @@ namespace bgfx { namespace gl #if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) bool hidpi = !!(_flags&BGFX_RESET_HIDPI); - NSOpenGLView* glView = (NSOpenGLView*)m_view; - if ([glView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) - [glView setWantsBestResolutionOpenGLSurface:hidpi]; + if (m_view) + { + NSOpenGLView* glView = (NSOpenGLView*)m_view; + if ([glView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) + [glView setWantsBestResolutionOpenGLSurface:hidpi]; + } #endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) bool vsync = !!(_flags&BGFX_RESET_VSYNC); GLint interval = vsync ? 1 : 0; NSOpenGLContext* glContext = (NSOpenGLContext*)m_context; [glContext setValues:&interval forParameter:NSOpenGLCPSwapInterval]; - [glContext update]; + + void (^update_view)(void) = ^(void) { + [glContext update]; + }; + + if([NSThread isMainThread]) + { + update_view(); + } + else + { + dispatch_sync(dispatch_get_main_queue(),update_view); + } } uint64_t GlContext::getCaps() const { uint64_t caps = 0; #if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) - NSWindow* nsWindow = (NSWindow*)g_platformData.nwh; - if ([nsWindow respondsToSelector:@selector(backingScaleFactor)] && (1.0f < [nsWindow backingScaleFactor])) + NSObject* nwh = (NSObject*)g_platformData.nwh; + if ([nwh respondsToSelector:@selector(backingScaleFactor)] && (1.0f < [(id)nwh backingScaleFactor])) caps |= BGFX_CAPS_HIDPI; #endif // defined(MAC_OS_X_VERSION_MAX_ALLOWED) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) + caps |= BGFX_CAPS_SWAP_CHAIN; return caps; } - SwapChainGL* GlContext::createSwapChain(void* _nwh) + SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height) { - return BX_NEW(g_allocator, SwapChainGL)(_nwh); + return BX_NEW(g_allocator, SwapChainGL)(_nwh,(NSOpenGLContext*)m_context); } void GlContext::destroySwapChain(SwapChainGL* _swapChain) diff --git a/3rdparty/bgfx/src/glcontext_wgl.cpp b/3rdparty/bgfx/src/glcontext_wgl.cpp index 859203dccdd..efa0ec2080d 100644 --- a/3rdparty/bgfx/src/glcontext_wgl.cpp +++ b/3rdparty/bgfx/src/glcontext_wgl.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -23,6 +23,13 @@ namespace bgfx { namespace gl # define GL_IMPORT(_optional, _proto, _func, _import) _proto _func # include "glimports.h" +# undef GL_IMPORT + + template<typename ProtoT> + static ProtoT wglGetProc(const char* _name) + { + return reinterpret_cast<ProtoT>( (void*)wglGetProcAddress(_name) ); + } struct SwapChainGL { @@ -101,30 +108,46 @@ namespace bgfx { namespace gl return context; } - void GlContext::create(uint32_t /*_width*/, uint32_t /*_height*/) + void GlContext::create(uint32_t /*_width*/, uint32_t /*_height*/, uint32_t /*_flags*/) { m_opengl32dll = bx::dlopen("opengl32.dll"); BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load opengl32.dll."); - wglGetProcAddress = (PFNWGLGETPROCADDRESSPROC)bx::dlsym(m_opengl32dll, "wglGetProcAddress"); + wglGetProcAddress = bx::dlsym<PFNWGLGETPROCADDRESSPROC>(m_opengl32dll, "wglGetProcAddress"); BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress."); // If g_platformHooks.nwh is NULL, the assumption is that GL context was created // by user (for example, using SDL, GLFW, etc.) BX_WARN(NULL != g_platformData.nwh , "bgfx::setPlatform with valid window is not called. This might " - "be intentional when GL context is created by the user." + "be intentional when GL context is created by the user." ); - if (NULL != g_platformData.nwh) + if (NULL != g_platformData.nwh && NULL != g_platformData.context ) { + // user has provided a context and a window wglMakeCurrent = (PFNWGLMAKECURRENTPROC)bx::dlsym(m_opengl32dll, "wglMakeCurrent"); BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent."); - wglCreateContext = (PFNWGLCREATECONTEXTPROC)bx::dlsym(m_opengl32dll, "wglCreateContext"); + m_hdc = GetDC( (HWND)g_platformData.nwh); + BGFX_FATAL(NULL != m_hdc, Fatal::UnableToInitialize, "GetDC failed!"); + + HGLRC context = (HGLRC)g_platformData.context; + int result = wglMakeCurrent(m_hdc, context ); + BGFX_FATAL(0 != result, Fatal::UnableToInitialize, "wglMakeCurrent failed!"); + + m_context = context; + } + + if (NULL != g_platformData.nwh && NULL == g_platformData.context ) + { + wglMakeCurrent = bx::dlsym<PFNWGLMAKECURRENTPROC>(m_opengl32dll, "wglMakeCurrent"); + BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent."); + + wglCreateContext = bx::dlsym<PFNWGLCREATECONTEXTPROC>(m_opengl32dll, "wglCreateContext"); BGFX_FATAL(NULL != wglCreateContext, Fatal::UnableToInitialize, "Failed get wglCreateContext."); - wglDeleteContext = (PFNWGLDELETECONTEXTPROC)bx::dlsym(m_opengl32dll, "wglDeleteContext"); + wglDeleteContext = bx::dlsym<PFNWGLDELETECONTEXTPROC>(m_opengl32dll, "wglDeleteContext"); BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext."); m_hdc = GetDC( (HWND)g_platformData.nwh); @@ -134,7 +157,7 @@ namespace bgfx { namespace gl // // An application can only set the pixel format of a window one time. // Once a window's pixel format is set, it cannot be changed. - // MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/dd369049%28v=vs.85%29.aspx + // MSDN: https://web.archive.org/web/20190207230357/https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/nf-wingdi-setpixelformat HWND hwnd = CreateWindowA("STATIC" , "" , WS_POPUP|WS_DISABLED @@ -153,10 +176,10 @@ namespace bgfx { namespace gl HGLRC context = createContext(hdc); - wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); - wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB"); - wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); + wglGetExtensionsStringARB = wglGetProc<PFNWGLGETEXTENSIONSSTRINGARBPROC >("wglGetExtensionsStringARB"); + wglChoosePixelFormatARB = wglGetProc<PFNWGLCHOOSEPIXELFORMATARBPROC >("wglChoosePixelFormatARB"); + wglCreateContextAttribsARB = wglGetProc<PFNWGLCREATECONTEXTATTRIBSARBPROC>("wglCreateContextAttribsARB"); + wglSwapIntervalEXT = wglGetProc<PFNWGLSWAPINTERVALEXTPROC >("wglSwapIntervalEXT"); if (NULL != wglGetExtensionsStringARB) { @@ -170,15 +193,20 @@ namespace bgfx { namespace gl { int32_t attrs[] = { - WGL_SAMPLE_BUFFERS_ARB, 0, - WGL_SAMPLES_ARB, 0, - WGL_SUPPORT_OPENGL_ARB, true, - WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, - WGL_DRAW_TO_WINDOW_ARB, true, - WGL_DOUBLE_BUFFER_ARB, true, - WGL_COLOR_BITS_ARB, 32, - WGL_DEPTH_BITS_ARB, 24, - WGL_STENCIL_BITS_ARB, 8, + WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, + WGL_DOUBLE_BUFFER_ARB, GL_TRUE, + WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, + WGL_SUPPORT_OPENGL_ARB, GL_TRUE, + + WGL_ALPHA_BITS_ARB, 8, + WGL_COLOR_BITS_ARB, 32, + WGL_DEPTH_BITS_ARB, 24, + WGL_STENCIL_BITS_ARB, 8, + + WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB, + WGL_SAMPLES_ARB, 0, + WGL_SAMPLE_BUFFERS_ARB, GL_FALSE, + 0 }; @@ -278,8 +306,12 @@ namespace bgfx { namespace gl { wglMakeCurrent(NULL, NULL); - wglDeleteContext(m_context); - m_context = NULL; + if (NULL == g_platformData.context) + { + wglDeleteContext(m_context); + m_context = NULL; + + } ReleaseDC( (HWND)g_platformData.nwh, m_hdc); m_hdc = NULL; @@ -303,15 +335,16 @@ namespace bgfx { namespace gl return BGFX_CAPS_SWAP_CHAIN; } - SwapChainGL* GlContext::createSwapChain(void* _nwh) + SwapChainGL* GlContext::createSwapChain(void* _nwh, int _width, int _height) { + BX_UNUSED(_width, _height); SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(_nwh); int result = SetPixelFormat(swapChain->m_hdc, m_pixelFormat, &m_pfd); BX_WARN(result, "SetPixelFormat failed (last err: 0x%08x)!", GetLastError() ); BX_UNUSED(result); swapChain->m_context = wglCreateContextAttribsARB(swapChain->m_hdc, m_context, m_contextAttrs); - BX_CHECK(NULL != swapChain->m_context, "Create swap chain failed: %x", glGetError() ); + BX_ASSERT(NULL != swapChain->m_context, "Create swap chain failed: %x", glGetError() ); return swapChain; } @@ -360,24 +393,30 @@ namespace bgfx { namespace gl void GlContext::import() { BX_TRACE("Import:"); -# define GL_EXTENSION(_optional, _proto, _func, _import) \ - { \ - if (NULL == _func) \ - { \ - _func = (_proto)wglGetProcAddress(#_import); \ - if (_func == NULL) \ - { \ - _func = (_proto)bx::dlsym(m_opengl32dll, #_import); \ - BX_TRACE(" %p " #_func " (" #_import ")", _func); \ - } \ - else \ - { \ - BX_TRACE("wgl %p " #_func " (" #_import ")", _func); \ - } \ - BGFX_FATAL(BX_IGNORE_C4127(_optional) || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \ - } \ - } + +# define GL_EXTENSION(_optional, _proto, _func, _import) \ + { \ + if (NULL == _func) \ + { \ + _func = wglGetProc<_proto>(#_import); \ + if (NULL == _func) \ + { \ + _func = bx::dlsym<_proto>(m_opengl32dll, #_import); \ + BX_TRACE(" %p " #_func " (" #_import ")", _func); \ + } \ + else \ + { \ + BX_TRACE("wgl %p " #_func " (" #_import ")", _func); \ + } \ + BGFX_FATAL(BX_IGNORE_C4127(_optional) || NULL != _func \ + , Fatal::UnableToInitialize \ + , "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \ + } \ + } + # include "glimports.h" + +# undef GL_EXTENSION } } } // namespace bgfx diff --git a/3rdparty/bgfx/src/glcontext_wgl.h b/3rdparty/bgfx/src/glcontext_wgl.h index 275a114364d..13b8d2ed880 100644 --- a/3rdparty/bgfx/src/glcontext_wgl.h +++ b/3rdparty/bgfx/src/glcontext_wgl.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_GLCONTEXT_WGL_H_HEADER_GUARD @@ -65,15 +65,16 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z , m_opengl32dll(NULL) , m_context(NULL) , m_hdc(NULL) + , m_msaaContext(false) { } - void create(uint32_t _width, uint32_t _height); + void create(uint32_t _width, uint32_t _height, uint32_t _flags); void destroy(); void resize(uint32_t _width, uint32_t _height, uint32_t _flags); uint64_t getCaps() const; - SwapChainGL* createSwapChain(void* _nwh); + SwapChainGL* createSwapChain(void* _nwh, int _width, int _height); void destroySwapChain(SwapChainGL* _swapChain); void swap(SwapChainGL* _swapChain = NULL); void makeCurrent(SwapChainGL* _swapChain = NULL); @@ -92,6 +93,8 @@ typedef void (APIENTRYP PFNGLSTENCILOPPROC) (GLenum fail, GLenum zfail, GLenum z void* m_opengl32dll; HGLRC m_context; HDC m_hdc; + // true when MSAA is handled by the context instead of using MSAA FBO + bool m_msaaContext; }; } /* namespace gl */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/glimports.h b/3rdparty/bgfx/src/glimports.h index 24e25c055f9..a462ff70861 100644 --- a/3rdparty/bgfx/src/glimports.h +++ b/3rdparty/bgfx/src/glimports.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #if !defined(GL_IMPORT) && !defined(GL_EXTENSION) @@ -29,6 +29,8 @@ #define GL_IMPORT_KHR__(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## KHR) #define GL_IMPORT_NV___(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## NV) #define GL_IMPORT_OES__(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## OES) +#define GL_IMPORT_IMG__(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## IMG) +#define GL_IMPORT_WEBGL(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## WEBGL) #define GL_IMPORT_____x(_optional, _proto, _func) GL_EXTENSION(_optional, _proto, _func, _func ## XXXXX) #if GL_IMPORT_TYPEDEFS @@ -73,6 +75,7 @@ typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXIMAGE3DPROC) (GLenum targ typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const void *data); typedef void (GL_APIENTRYP PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const void *data); typedef void (GL_APIENTRYP PFNGLCOPYIMAGESUBDATAPROC) (GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ, GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ, GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth); +typedef void (GL_APIENTRYP PFNGLCOPYTEXSUBIMAGE2DPROC) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height); typedef GLuint (GL_APIENTRYP PFNGLCREATEPROGRAMPROC) (void); typedef GLuint (GL_APIENTRYP PFNGLCREATESHADERPROC) (GLenum type); typedef void (GL_APIENTRYP PFNGLCULLFACEPROC) (GLenum mode); @@ -111,6 +114,7 @@ typedef void (GL_APIENTRYP PFNGLENDQUERYPROC) (GLenum target); typedef void (GL_APIENTRYP PFNGLFINISHPROC) (); typedef void (GL_APIENTRYP PFNGLFLUSHPROC) (); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTUREPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURELAYERPROC) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); typedef void (GL_APIENTRYP PFNGLFRONTFACE)(GLenum mode); @@ -160,6 +164,8 @@ typedef void (GL_APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program); typedef void (GL_APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers); typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTPROC) (GLenum mode, const void *indirect, GLsizei drawcount, GLsizei stride); typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTPROC) (GLenum mode, GLenum type, const void *indirect, GLsizei drawcount, GLsizei stride); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC) (GLenum mode, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); +typedef void (GL_APIENTRYP PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC) (GLenum mode, GLenum type, const void *indirect, GLintptr drawcount, GLsizei maxdrawcount, GLsizei stride); typedef void (GL_APIENTRYP PFNGLOBJECTLABELPROC) (GLenum identifier, GLuint name, GLsizei length, const GLchar *label); typedef void (GL_APIENTRYP PFNGLOBJECTPTRLABELPROC) (const void *ptr, GLsizei length, const GLchar *label); typedef void (GL_APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param); @@ -168,6 +174,7 @@ typedef void (GL_APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum typedef void (GL_APIENTRYP PFNGLPOPDEBUGGROUPPROC) (void); typedef void (GL_APIENTRYP PFNGLPROGRAMBINARYPROC) (GLuint program, GLenum binaryFormat, const void *binary, GLsizei length); typedef void (GL_APIENTRYP PFNGLPROGRAMPARAMETERIPROC) (GLuint program, GLenum pname, GLint value); +typedef void (GL_APIENTRYP PFNGLPROVOKINGVERTEXPROC) (GLenum mode); typedef void (GL_APIENTRYP PFNGLPUSHDEBUGGROUPPROC) (GLenum source, GLuint id, GLsizei length, const GLchar *message); typedef void (GL_APIENTRYP PFNGLQUERYCOUNTERPROC) (GLuint id, GLenum target); typedef void (GL_APIENTRYP PFNGLREADBUFFERPROC) (GLenum mode); @@ -205,6 +212,7 @@ typedef void (GL_APIENTRYP PFNGLUNIFORM1IVPROC) (GLint location, GLsiz typedef void (GL_APIENTRYP PFNGLUNIFORM2FVPROC) (GLint location, GLsizei count, const GLfloat *value); typedef void (GL_APIENTRYP PFNGLUNIFORM3FVPROC) (GLint location, GLsizei count, const GLfloat *value); typedef void (GL_APIENTRYP PFNGLUNIFORM4FVPROC) (GLint location, GLsizei count, const GLfloat *value); +typedef void (GL_APIENTRYP PFNGLUNIFORM4FPROC) (GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w); typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX3FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); typedef void (GL_APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); typedef void (GL_APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program); @@ -218,12 +226,11 @@ typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBIPOINTERPROC) (GLuint inde typedef void (GL_APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height); typedef void (GL_APIENTRYP PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC)(GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *source); -typedef void (GL_APIENTRYP PFNGLSTRINGMARKERGREMEDYPROC) (GLsizei len, const void *string); -typedef void (GL_APIENTRYP PFNGLFRAMETERMINATORGREMEDYPROC) (void); typedef void (GL_APIENTRYP PFNGLINSERTEVENTMARKEREXTPROC) (GLsizei length, const GLchar *marker); typedef void (GL_APIENTRYP PFNGLPUSHGROUPMARKEREXTPROC) (GLsizei length, const GLchar *marker); typedef void (GL_APIENTRYP PFNGLPOPGROUPMARKEREXTPROC) (void); +typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level, GLsizei samples); #endif // GL_IMPORT_TYPEDEFS #if BGFX_USE_GL_DYNAMIC_LIB @@ -265,6 +272,7 @@ GL_IMPORT______(false, PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC, glCompressedT GL_IMPORT______(true , PFNGLCOMPRESSEDTEXIMAGE3DPROC, glCompressedTexImage3D); GL_IMPORT______(true , PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC, glCompressedTexSubImage3D); GL_IMPORT______(true , PFNGLCOPYIMAGESUBDATAPROC, glCopyImageSubData); +GL_IMPORT______(true , PFNGLCOPYTEXSUBIMAGE2DPROC, glCopyTexSubImage2D); GL_IMPORT______(false, PFNGLCREATEPROGRAMPROC, glCreateProgram); GL_IMPORT______(false, PFNGLCREATESHADERPROC, glCreateShader); GL_IMPORT______(false, PFNGLCULLFACEPROC, glCullFace); @@ -303,6 +311,7 @@ GL_IMPORT______(true, PFNGLENDQUERYPROC, glEndQuery); GL_IMPORT______(false, PFNGLFINISHPROC, glFinish); GL_IMPORT______(false, PFNGLFLUSHPROC, glFlush); GL_IMPORT______(true, PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer); +GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTUREPROC, glFramebufferTexture); GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D); GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTURELAYERPROC, glFramebufferTextureLayer); GL_IMPORT______(false, PFNGLFRONTFACE, glFrontFace); @@ -361,12 +370,15 @@ GL_IMPORT______(false, PFNGLLINKPROGRAMPROC, glLinkProgram GL_IMPORT______(true, PFNGLMEMORYBARRIERPROC, glMemoryBarrier); GL_IMPORT______(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); GL_IMPORT______(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); +GL_IMPORT______(true, PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC, glMultiDrawArraysIndirectCount); +GL_IMPORT______(true, PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC, glMultiDrawElementsIndirectCount); GL_IMPORT______(true, PFNGLOBJECTLABELPROC, glObjectLabel); GL_IMPORT______(true, PFNGLOBJECTPTRLABELPROC, glObjectPtrLabel); GL_IMPORT______(false, PFNGLPIXELSTOREIPROC, glPixelStorei); GL_IMPORT______(true, PFNGLPOPDEBUGGROUPPROC, glPopDebugGroup); GL_IMPORT______(true, PFNGLPROGRAMBINARYPROC, glProgramBinary); GL_IMPORT______(true, PFNGLPROGRAMPARAMETERIPROC, glProgramParameteri); +GL_IMPORT______(true, PFNGLPROVOKINGVERTEXPROC, glProvokingVertex); GL_IMPORT______(true, PFNGLPUSHDEBUGGROUPPROC, glPushDebugGroup); GL_IMPORT______(true, PFNGLQUERYCOUNTERPROC, glQueryCounter); GL_IMPORT______(true, PFNGLREADBUFFERPROC, glReadBuffer); @@ -402,6 +414,7 @@ GL_IMPORT______(false, PFNGLUNIFORM1FVPROC, glUniform1fv) GL_IMPORT______(false, PFNGLUNIFORM2FVPROC, glUniform2fv); GL_IMPORT______(false, PFNGLUNIFORM3FVPROC, glUniform3fv); GL_IMPORT______(false, PFNGLUNIFORM4FVPROC, glUniform4fv); +GL_IMPORT______(false, PFNGLUNIFORM4FPROC, glUniform4f); GL_IMPORT______(false, PFNGLUNIFORMMATRIX3FVPROC, glUniformMatrix3fv); GL_IMPORT______(false, PFNGLUNIFORMMATRIX4FVPROC, glUniformMatrix4fv); GL_IMPORT______(false, PFNGLUSEPROGRAMPROC, glUseProgram); @@ -423,8 +436,6 @@ GL_IMPORT_ARB__(true, PFNGLDEBUGMESSAGECONTROLPROC, glDebugMessag GL_IMPORT_ARB__(true, PFNGLDEBUGMESSAGEINSERTPROC, glDebugMessageInsert); GL_IMPORT_ARB__(true, PFNGLDEBUGMESSAGECALLBACKPROC, glDebugMessageCallback); GL_IMPORT_ARB__(true, PFNGLGETDEBUGMESSAGELOGPROC, glGetDebugMessageLog); -GL_IMPORT_ARB__(true, PFNGLPUSHDEBUGGROUPPROC, glPushDebugGroup); -GL_IMPORT_ARB__(true, PFNGLPOPDEBUGGROUPPROC, glPopDebugGroup); GL_IMPORT_ARB__(true, PFNGLOBJECTLABELPROC, glObjectLabel); GL_IMPORT_ARB__(true, PFNGLGETOBJECTLABELPROC, glGetObjectLabel); GL_IMPORT_ARB__(true, PFNGLOBJECTPTRLABELPROC, glObjectPtrLabel); @@ -440,18 +451,25 @@ GL_IMPORT_ARB__(true, PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttri GL_IMPORT_ARB__(true, PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstanced); GL_IMPORT_ARB__(true, PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElementsInstanced); +GL_IMPORT______(true, PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttribDivisorNV); +GL_IMPORT______(true, PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstancedNV); +GL_IMPORT______(true, PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElementsInstancedNV); + GL_IMPORT_ARB__(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers); GL_IMPORT_ARB__(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); GL_IMPORT_ARB__(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); GL_IMPORT_ARB__(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); +GL_IMPORT_ARB__(true, PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC, glMultiDrawArraysIndirectCount); +GL_IMPORT_ARB__(true, PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC, glMultiDrawElementsIndirectCount); GL_IMPORT_EXT__(true, PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer); GL_IMPORT_EXT__(true, PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers); GL_IMPORT_EXT__(true, PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers); GL_IMPORT_EXT__(true, PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus); GL_IMPORT_EXT__(true, PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer); +GL_IMPORT_EXT__(true, PFNGLFRAMEBUFFERTEXTUREPROC, glFramebufferTexture); GL_IMPORT_EXT__(true, PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D); GL_IMPORT_EXT__(true, PFNGLFRAMEBUFFERTEXTURELAYERPROC, glFramebufferTextureLayer); GL_IMPORT_EXT__(true, PFNGLBINDRENDERBUFFERPROC, glBindRenderbuffer); @@ -465,9 +483,16 @@ GL_IMPORT______(true, PFNGLTEXIMAGE3DMULTISAMPLEPROC, glTexImage3DM # else // GLES GL_IMPORT______(false, PFNGLCLEARDEPTHFPROC, glClearDepthf); +GL_IMPORT_EXT__(true, PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC, glRenderbufferStorageMultisample); +# if (BGFX_CONFIG_RENDERER_OPENGLES < 30) +GL_IMPORT_IMG__(true, PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC, glRenderbufferStorageMultisample); +# endif // BGFX_CONFIG_RENDERER_OPENGLES < 30 # endif // BGFX_CONFIG_RENDERER_OPENGL GL_IMPORT______(true, PFNGLINSERTEVENTMARKEREXTPROC, glInsertEventMarker); +GL_IMPORT_ARB__(true, PFNGLPROVOKINGVERTEXPROC, glProvokingVertex); +GL_IMPORT_ARB__(true, PFNGLPUSHDEBUGGROUPPROC, glPushDebugGroup); +GL_IMPORT_ARB__(true, PFNGLPOPDEBUGGROUPPROC, glPopDebugGroup); GL_IMPORT______(true, PFNGLPUSHGROUPMARKEREXTPROC, glPushGroupMarker); GL_IMPORT______(true, PFNGLPOPGROUPMARKEREXTPROC, glPopGroupMarker); #else @@ -476,9 +501,8 @@ GL_IMPORT______(true, PFNGLGETINTERNALFORMATIVPROC, glGetInternal GL_IMPORT______(true, PFNGLGETINTERNALFORMATI64VPROC, glGetInternalformati64v); #endif // BGFX_USE_GL_DYNAMIC_LIB -GL_IMPORT______(true, PFNGLSTRINGMARKERGREMEDYPROC, glStringMarkerGREMEDY); -GL_IMPORT______(true, PFNGLFRAMETERMINATORGREMEDYPROC, glFrameTerminatorGREMEDY); GL_IMPORT______(true, PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC, glGetTranslatedShaderSourceANGLE); +GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTURE2DMULTISAMPLEIMGPROC, glFramebufferTexture2DMultisampleEXT); #if !BGFX_CONFIG_RENDERER_OPENGL GL_IMPORT______(true, PFNGLPOINTSIZEPROC, glPointSize); @@ -496,6 +520,10 @@ GL_IMPORT_KHR__(true, PFNGLGETDEBUGMESSAGELOGPROC, glGetDebugMes GL_IMPORT_____x(true, PFNGLGETCOMPRESSEDTEXIMAGEPROC, glGetCompressedTexImage); GL_IMPORT_____x(true, PFNGLGETTEXIMAGEPROC, glGetTexImage); +GL_IMPORT______(true, PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttribDivisorNV); +GL_IMPORT______(true, PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstancedNV); +GL_IMPORT______(true, PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElementsInstancedNV); + # if BGFX_CONFIG_RENDERER_OPENGLES && BGFX_CONFIG_RENDERER_OPENGLES < 30 GL_IMPORT______(true, PFNGLGETSTRINGIPROC, glGetStringi); @@ -509,9 +537,13 @@ GL_IMPORT_EXT__(true, PFNGLTEXSTORAGE3DPROC, glTexStorage3 GL_IMPORT______(true, PFNGLTEXIMAGE2DMULTISAMPLEPROC, glTexImage2DMultisample); GL_IMPORT______(true, PFNGLTEXIMAGE3DMULTISAMPLEPROC, glTexImage3DMultisample); +GL_IMPORT_EXT__(true, PFNGLFRAMEBUFFERTEXTUREPROC, glFramebufferTexture); GL_IMPORT_EXT__(true, PFNGLFRAMEBUFFERTEXTURELAYERPROC, glFramebufferTextureLayer); GL_IMPORT_EXT__(true, PFNGLINSERTEVENTMARKEREXTPROC, glInsertEventMarker); +GL_IMPORT_ARB__(true, PFNGLPROVOKINGVERTEXPROC, glProvokingVertex); +GL_IMPORT_ARB__(true, PFNGLPUSHDEBUGGROUPPROC, glPushDebugGroup); +GL_IMPORT_ARB__(true, PFNGLPOPDEBUGGROUPPROC, glPopDebugGroup); GL_IMPORT_EXT__(true, PFNGLPUSHGROUPMARKEREXTPROC, glPushGroupMarker); GL_IMPORT_EXT__(true, PFNGLPOPGROUPMARKEREXTPROC, glPopGroupMarker); GL_IMPORT_EXT__(true, PFNGLOBJECTLABELPROC, glObjectLabel); @@ -520,6 +552,8 @@ GL_IMPORT_EXT__(true, PFNGLDRAWARRAYSINDIRECTPROC, glDrawArraysI GL_IMPORT_EXT__(true, PFNGLDRAWELEMENTSINDIRECTPROC, glDrawElementsIndirect); GL_IMPORT_EXT__(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); GL_IMPORT_EXT__(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); +GL_IMPORT_EXT__(true, PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC, glMultiDrawArraysIndirectCount); +GL_IMPORT_EXT__(true, PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC, glMultiDrawElementsIndirectCount); GL_IMPORT_OES__(true, PFNGLGETPROGRAMBINARYPROC, glGetProgramBinary); GL_IMPORT_OES__(true, PFNGLPROGRAMBINARYPROC, glProgramBinary); @@ -528,6 +562,10 @@ GL_IMPORT_OES__(true, PFNGLPROGRAMBINARYPROC, glProgramBina GL_IMPORT_EXT__(true, PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttribDivisor); GL_IMPORT_EXT__(true, PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstanced); GL_IMPORT_EXT__(true, PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElementsInstanced); +#elif BX_PLATFORM_EMSCRIPTEN +GL_IMPORT_ANGLE(true, PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttribDivisor); +GL_IMPORT_ANGLE(true, PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstanced); +GL_IMPORT_ANGLE(true, PFNGLDRAWELEMENTSINSTANCEDPROC, glDrawElementsInstanced); #else GL_IMPORT_OES__(true, PFNGLVERTEXATTRIBDIVISORPROC, glVertexAttribDivisor); GL_IMPORT_OES__(true, PFNGLDRAWARRAYSINSTANCEDPROC, glDrawArraysInstanced); @@ -546,14 +584,16 @@ GL_IMPORT_____x(true, PFNGLBLENDEQUATIONSEPARATEIPROC, glBlendEquati GL_IMPORT_____x(true, PFNGLBLENDFUNCIPROC, glBlendFunci); GL_IMPORT_____x(true, PFNGLBLENDFUNCSEPARATEIPROC, glBlendFuncSeparatei); -GL_IMPORT_____x(true, PFNGLDRAWBUFFERPROC, glDrawBuffer); -GL_IMPORT_____x(true, PFNGLREADBUFFERPROC, glReadBuffer); -GL_IMPORT_____x(true, PFNGLGENSAMPLERSPROC, glGenSamplers); -GL_IMPORT_____x(true, PFNGLDELETESAMPLERSPROC, glDeleteSamplers); -GL_IMPORT_____x(true, PFNGLBINDSAMPLERPROC, glBindSampler); -GL_IMPORT_____x(true, PFNGLSAMPLERPARAMETERFPROC, glSamplerParameterf); -GL_IMPORT_____x(true, PFNGLSAMPLERPARAMETERIPROC, glSamplerParameteri); -GL_IMPORT_____x(true, PFNGLSAMPLERPARAMETERFVPROC, glSamplerParameterfv); +#if !BGFX_USE_GL_DYNAMIC_LIB +GL_IMPORT______(true, PFNGLDRAWBUFFERPROC, glDrawBuffer); +GL_IMPORT______(true, PFNGLREADBUFFERPROC, glReadBuffer); +GL_IMPORT______(true, PFNGLGENSAMPLERSPROC, glGenSamplers); +GL_IMPORT______(true, PFNGLDELETESAMPLERSPROC, glDeleteSamplers); +GL_IMPORT______(true, PFNGLBINDSAMPLERPROC, glBindSampler); +GL_IMPORT______(true, PFNGLSAMPLERPARAMETERFPROC, glSamplerParameterf); +GL_IMPORT______(true, PFNGLSAMPLERPARAMETERIPROC, glSamplerParameteri); +GL_IMPORT______(true, PFNGLSAMPLERPARAMETERFVPROC, glSamplerParameterfv); +#endif // !BGFX_USE_GL_DYNAMIC_LIB GL_IMPORT_____x(true, PFNGLBINDBUFFERBASEPROC, glBindBufferBase); GL_IMPORT_____x(true, PFNGLBINDBUFFERRANGEPROC, glBindBufferRange); @@ -568,7 +608,11 @@ GL_IMPORT_____x(true, PFNGLMEMORYBARRIERPROC, glMemoryBarri GL_IMPORT_____x(true, PFNGLDISPATCHCOMPUTEPROC, glDispatchCompute); GL_IMPORT_____x(true, PFNGLDISPATCHCOMPUTEINDIRECTPROC, glDispatchComputeIndirect); +#if BX_PLATFORM_EMSCRIPTEN +GL_IMPORT_WEBGL(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers); +#else GL_IMPORT_NV___(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers); +#endif GL_IMPORT_NV___(true, PFNGLGENQUERIESPROC, glGenQueries); GL_IMPORT_NV___(true, PFNGLDELETEQUERIESPROC, glDeleteQueries); GL_IMPORT_NV___(true, PFNGLBEGINQUERYPROC, glBeginQuery); @@ -593,9 +637,13 @@ GL_IMPORT______(true, PFNGLTEXSTORAGE3DPROC, glTexStorage3 GL_IMPORT______(true, PFNGLTEXIMAGE2DMULTISAMPLEPROC, glTexImage2DMultisample); GL_IMPORT______(true, PFNGLTEXIMAGE3DMULTISAMPLEPROC, glTexImage3DMultisample); +GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTUREPROC, glFramebufferTexture); GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTURELAYERPROC, glFramebufferTextureLayer); GL_IMPORT______(true, PFNGLINSERTEVENTMARKEREXTPROC, glInsertEventMarker); +GL_IMPORT_ARB__(true, PFNGLPROVOKINGVERTEXPROC, glProvokingVertex); +GL_IMPORT_ARB__(true, PFNGLPUSHDEBUGGROUPPROC, glPushDebugGroup); +GL_IMPORT_ARB__(true, PFNGLPOPDEBUGGROUPPROC, glPopDebugGroup); GL_IMPORT______(true, PFNGLPUSHGROUPMARKEREXTPROC, glPushGroupMarker); GL_IMPORT______(true, PFNGLPOPGROUPMARKEREXTPROC, glPopGroupMarker); GL_IMPORT______(true, PFNGLOBJECTLABELPROC, glObjectLabel); @@ -640,7 +688,11 @@ GL_IMPORT______(true, PFNGLMEMORYBARRIERPROC, glMemoryBarri GL_IMPORT______(true, PFNGLDISPATCHCOMPUTEPROC, glDispatchCompute); GL_IMPORT______(true, PFNGLDISPATCHCOMPUTEINDIRECTPROC, glDispatchComputeIndirect); +# if BX_PLATFORM_EMSCRIPTEN +GL_IMPORT_WEBGL(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers); +# else GL_IMPORT______(true, PFNGLDRAWBUFFERSPROC, glDrawBuffers); +# endif GL_IMPORT______(true, PFNGLGENQUERIESPROC, glGenQueries); GL_IMPORT______(true, PFNGLDELETEQUERIESPROC, glDeleteQueries); GL_IMPORT______(true, PFNGLBEGINQUERYPROC, glBeginQuery); @@ -653,6 +705,8 @@ GL_IMPORT______(true, PFNGLDRAWARRAYSINDIRECTPROC, glDrawArraysI GL_IMPORT______(true, PFNGLDRAWELEMENTSINDIRECTPROC, glDrawElementsIndirect); GL_IMPORT______(true, PFNGLMULTIDRAWARRAYSINDIRECTPROC, glMultiDrawArraysIndirect); GL_IMPORT______(true, PFNGLMULTIDRAWELEMENTSINDIRECTPROC, glMultiDrawElementsIndirect); +GL_IMPORT______(true, PFNGLMULTIDRAWARRAYSINDIRECTCOUNTPROC, glMultiDrawArraysIndirectCount); +GL_IMPORT______(true, PFNGLMULTIDRAWELEMENTSINDIRECTCOUNTPROC, glMultiDrawElementsIndirectCount); GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateFramebuffer); @@ -668,4 +722,5 @@ GL_IMPORT______(true, PFNGLINVALIDATEFRAMEBUFFERPROC, glInvalidateF #undef GL_IMPORT_KHR__ #undef GL_IMPORT_NV___ #undef GL_IMPORT_OES__ +#undef GL_IMPORT_IMG__ #undef GL_IMPORT_____x diff --git a/3rdparty/bgfx/src/makefile b/3rdparty/bgfx/src/makefile index 8dccda6ab3f..086dfe6379c 100644 --- a/3rdparty/bgfx/src/makefile +++ b/3rdparty/bgfx/src/makefile @@ -1,6 +1,6 @@ # -# Copyright 2011-2018 Branimir Karadzic. All rights reserved. -# License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause +# Copyright 2011-2022 Branimir Karadzic. All rights reserved. +# License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE # THISDIR:=$(dir $(lastword $(MAKEFILE_LIST))) @@ -25,40 +25,42 @@ all: $(BIN) define shader-embedded @echo [$(<)] - $(SILENT) $(SHADERC) --type $(1) --platform linux -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_glsl - @cat $(SHADER_TMP) > $(@) - -$(SILENT) $(SHADERC) --type $(1) --platform linux -p spirv -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_spv - -@cat $(SHADER_TMP) >> $(@) - -$(SILENT) $(SHADERC) --type $(1) --platform windows -p $(2) -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_dx9 - -@cat $(SHADER_TMP) >> $(@) - -$(SILENT) $(SHADERC) --type $(1) --platform windows -p $(3) -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_dx11 - -@cat $(SHADER_TMP) >> $(@) - -$(SILENT) $(SHADERC) --type $(1) --platform ios -p metal -O 3 -f $(<) -o $(SHADER_TMP) --bin2c $(basename $(<))_mtl - -@cat $(SHADER_TMP) >> $(@) - -@echo extern const uint8_t* $(basename $(<))_pssl;>> $(@) - -@echo extern const uint32_t $(basename $(<))_pssl_size;>> $(@) + $(SILENT) $(SHADERC) --type $(1) --platform linux -p 120 -f $(<) -o "$(SHADER_TMP)" --bin2c $(basename $(<))_glsl + @cat "$(SHADER_TMP)" > $(@) + -$(SILENT) $(SHADERC) --type $(1) --platform android -f $(<) -o "$(SHADER_TMP)" --bin2c $(basename $(<))_essl + -@cat "$(SHADER_TMP)" >> $(@) + -$(SILENT) $(SHADERC) --type $(1) --platform linux -p spirv -f $(<) -o "$(SHADER_TMP)" --bin2c $(basename $(<))_spv + -@cat "$(SHADER_TMP)" >> $(@) + -$(SILENT) $(SHADERC) --type $(1) --platform windows -p $(2) -O 3 -f $(<) -o "$(SHADER_TMP)" --bin2c $(basename $(<))_dx9 + -@cat "$(SHADER_TMP)" >> $(@) + -$(SILENT) $(SHADERC) --type $(1) --platform windows -p $(3) -O 3 -f $(<) -o "$(SHADER_TMP)" --bin2c $(basename $(<))_dx11 + -@cat "$(SHADER_TMP)" >> $(@) + -$(SILENT) $(SHADERC) --type $(1) --platform ios -p metal -O 3 -f $(<) -o "$(SHADER_TMP)" --bin2c $(basename $(<))_mtl + -@cat "$(SHADER_TMP)" >> $(@) + -@printf "extern const uint8_t* $(basename $(<))_pssl;\n" | tr -d '\015' >> $(@) + -@printf "extern const uint32_t $(basename $(<))_pssl_size;\n" | tr -d '\015' >> $(@) endef vs_debugfont.bin.h : vs_debugfont.sc - $(call shader-embedded, v, vs_3_0, vs_4_0_level_9_1) + $(call shader-embedded, v, vs_3_0, vs_4_0) fs_debugfont.bin.h : fs_debugfont.sc - $(call shader-embedded, f, ps_3_0, ps_4_0_level_9_1) + $(call shader-embedded, f, ps_3_0, ps_4_0) vs_clear.bin.h : vs_clear.sc - $(call shader-embedded, v, vs_3_0, vs_4_0_level_9_1) + $(call shader-embedded, v, vs_3_0, vs_4_0) fs_clear0.bin.h : fs_clear0.sc - $(call shader-embedded, f, ps_3_0, ps_4_0_level_9_1) + $(call shader-embedded, f, ps_3_0, ps_4_0) fs_clear1.bin.h : fs_clear1.sc - $(call shader-embedded, f, ps_3_0, ps_4_0_level_9_1) + $(call shader-embedded, f, ps_3_0, ps_4_0) fs_clear2.bin.h : fs_clear2.sc - $(call shader-embedded, f, ps_3_0, ps_4_0_level_9_1) + $(call shader-embedded, f, ps_3_0, ps_4_0) fs_clear3.bin.h : fs_clear3.sc - $(call shader-embedded, f, ps_3_0, ps_4_0_level_9_1) + $(call shader-embedded, f, ps_3_0, ps_4_0) fs_clear4.bin.h : fs_clear4.sc $(call shader-embedded, f, ps_3_0, ps_4_0) diff --git a/3rdparty/bgfx/src/nvapi.cpp b/3rdparty/bgfx/src/nvapi.cpp index 3ece9c7fc03..0103b0c0c30 100644 --- a/3rdparty/bgfx/src/nvapi.cpp +++ b/3rdparty/bgfx/src/nvapi.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -358,7 +358,7 @@ namespace bgfx #define NVA_CHECK(_call) \ BX_MACRO_BLOCK_BEGIN \ int32_t __result__ = _call; \ - BX_CHECK(1 == __result__, #_call " FAILED 0x%08x\n", __result__); \ + BX_ASSERT(1 == __result__, #_call " FAILED 0x%08x\n", __result__); \ BX_UNUSED(__result__); \ BX_MACRO_BLOCK_END diff --git a/3rdparty/bgfx/src/nvapi.h b/3rdparty/bgfx/src/nvapi.h index 8fe5b967d8c..0f03f4aa8d7 100644 --- a/3rdparty/bgfx/src/nvapi.h +++ b/3rdparty/bgfx/src/nvapi.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_NVAPI_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/renderer.h b/3rdparty/bgfx/src/renderer.h index ef45002a7a0..b62c485bc20 100644 --- a/3rdparty/bgfx/src/renderer.h +++ b/3rdparty/bgfx/src/renderer.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_H_HEADER_GUARD @@ -10,6 +10,23 @@ namespace bgfx { + inline constexpr uint32_t toAbgr8(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 0xff) + { + return 0 + | (uint32_t(_r)<<24) + | (uint32_t(_g)<<16) + | (uint32_t(_b)<< 8) + | (uint32_t(_a) ) + ; + } + + constexpr uint32_t kColorFrame = toAbgr8(0xff, 0xd7, 0xc9); + constexpr uint32_t kColorView = toAbgr8(0xe4, 0xb4, 0x8e); + constexpr uint32_t kColorDraw = toAbgr8(0xc6, 0xe5, 0xb9); + constexpr uint32_t kColorCompute = toAbgr8(0xa7, 0xdb, 0xd8); + constexpr uint32_t kColorMarker = toAbgr8(0xff, 0x00, 0x00); + constexpr uint32_t kColorResource = toAbgr8(0xff, 0x40, 0x20); + struct BlitState { BlitState(const Frame* _frame) @@ -47,82 +64,44 @@ namespace bgfx { } - ViewState(Frame* _frame, bool _stereo) + ViewState(Frame* _frame) { - reset(_frame, _stereo); + reset(_frame); } - void reset(Frame* _frame, bool _stereo) + void reset(Frame* _frame) { m_alphaRef = 0.0f; m_invViewCached = UINT16_MAX; m_invProjCached = UINT16_MAX; m_invViewProjCached = UINT16_MAX; - m_view[0] = m_viewTmp[0]; - m_view[1] = m_viewTmp[1]; - - if (_stereo) - { - m_view[0] = m_viewTmp[0]; - Matrix4 viewAdjust; - bx::mtxIdentity(viewAdjust.un.val); - - for (uint32_t eye = 0; eye < 2; ++eye) - { -/* - const HMD::Eye& hmdEye = hmd.eye[eye]; - viewAdjust.un.val[12] = hmdEye.viewOffset[0]; - viewAdjust.un.val[13] = hmdEye.viewOffset[1]; - viewAdjust.un.val[14] = hmdEye.viewOffset[2]; + m_view = m_viewTmp; - for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) - { - if (BGFX_VIEW_STEREO == (_frame->m_view[ii].m_flags & BGFX_VIEW_STEREO) ) - { - bx::float4x4_mul(&m_view[eye][ii].un.f4x4 - , &_frame->m_view[ii].m_view.un.f4x4 - , &viewAdjust.un.f4x4 - ); - } - else - { - bx::memCopy(&m_view[0][ii].un.f4x4, &_frame->m_view[ii].m_view.un.f4x4, sizeof(Matrix4) ); - } - } -*/ - } - } - else + for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { - for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) - { - bx::memCopy(&m_view[0][ii].un.f4x4, &_frame->m_view[ii].m_view.un.f4x4, sizeof(Matrix4) ); - } + bx::memCopy(&m_view[ii].un.f4x4, &_frame->m_view[ii].m_view.un.f4x4, sizeof(Matrix4) ); } for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii) { - for (uint32_t eye = 0; eye < uint32_t(_stereo)+1; ++eye) - { - bx::float4x4_mul(&m_viewProj[eye][ii].un.f4x4 - , &m_view[eye][ii].un.f4x4 - , &_frame->m_view[ii].m_proj[eye].un.f4x4 - ); - } + bx::float4x4_mul(&m_viewProj[ii].un.f4x4 + , &m_view[ii].un.f4x4 + , &_frame->m_view[ii].m_proj.un.f4x4 + ); } } template<uint16_t mtxRegs, typename RendererContext, typename Program, typename Draw> - void setPredefined(RendererContext* _renderer, uint16_t _view, uint8_t _eye, const Program& _program, const Frame* _frame, const Draw& _draw) + void setPredefined(RendererContext* _renderer, uint16_t _view, const Program& _program, const Frame* _frame, const Draw& _draw) { const FrameCache& frameCache = _frame->m_frameCache; for (uint32_t ii = 0, num = _program.m_numPredefined; ii < num; ++ii) { const PredefinedUniform& predefined = _program.m_predefined[ii]; - uint8_t flags = predefined.m_type&BGFX_UNIFORM_FRAGMENTBIT; - switch (predefined.m_type&(~BGFX_UNIFORM_FRAGMENTBIT) ) + uint8_t flags = predefined.m_type&kUniformFragmentBit; + switch (predefined.m_type&(~kUniformFragmentBit) ) { case PredefinedUniform::ViewRect: { @@ -158,7 +137,7 @@ namespace bgfx { _renderer->setShaderUniform4x4f(flags , predefined.m_loc - , m_view[_eye][_view].un.val + , m_view[_view].un.val , bx::uint32_min(mtxRegs, predefined.m_count) ); } @@ -166,12 +145,11 @@ namespace bgfx case PredefinedUniform::InvView: { - uint16_t viewEye = (_view << 1) | _eye; - if (viewEye != m_invViewCached) + if (_view != m_invViewCached) { - m_invViewCached = viewEye; + m_invViewCached = _view; bx::float4x4_inverse(&m_invView.un.f4x4 - , &m_view[_eye][_view].un.f4x4 + , &m_view[_view].un.f4x4 ); } @@ -187,7 +165,7 @@ namespace bgfx { _renderer->setShaderUniform4x4f(flags , predefined.m_loc - , _frame->m_view[_view].m_proj[_eye].un.val + , _frame->m_view[_view].m_proj.un.val , bx::uint32_min(mtxRegs, predefined.m_count) ); } @@ -195,12 +173,11 @@ namespace bgfx case PredefinedUniform::InvProj: { - uint16_t viewEye = (_view << 1) | _eye; - if (viewEye != m_invProjCached) + if (_view != m_invProjCached) { - m_invProjCached = viewEye; + m_invProjCached = _view; bx::float4x4_inverse(&m_invProj.un.f4x4 - , &_frame->m_view[_view].m_proj[_eye].un.f4x4 + , &_frame->m_view[_view].m_proj.un.f4x4 ); } @@ -216,7 +193,7 @@ namespace bgfx { _renderer->setShaderUniform4x4f(flags , predefined.m_loc - , m_viewProj[_eye][_view].un.val + , m_viewProj[_view].un.val , bx::uint32_min(mtxRegs, predefined.m_count) ); } @@ -224,12 +201,11 @@ namespace bgfx case PredefinedUniform::InvViewProj: { - uint16_t viewEye = (_view << 1) | _eye; - if (viewEye != m_invViewProjCached) + if (_view != m_invViewProjCached) { - m_invViewProjCached = viewEye; + m_invViewProjCached = _view; bx::float4x4_inverse(&m_invViewProj.un.f4x4 - , &m_viewProj[_eye][_view].un.f4x4 + , &m_viewProj[_view].un.f4x4 ); } @@ -256,9 +232,9 @@ namespace bgfx { Matrix4 modelView; const Matrix4& model = frameCache.m_matrixCache.m_cache[_draw.m_startMatrix]; - bx::float4x4_mul(&modelView.un.f4x4 + bx::model4x4_mul(&modelView.un.f4x4 , &model.un.f4x4 - , &m_view[_eye][_view].un.f4x4 + , &m_view[_view].un.f4x4 ); _renderer->setShaderUniform4x4f(flags , predefined.m_loc @@ -272,9 +248,9 @@ namespace bgfx { Matrix4 modelViewProj; const Matrix4& model = frameCache.m_matrixCache.m_cache[_draw.m_startMatrix]; - bx::float4x4_mul(&modelViewProj.un.f4x4 + bx::model4x4_mul_viewproj4x4(&modelViewProj.un.f4x4 , &model.un.f4x4 - , &m_viewProj[_eye][_view].un.f4x4 + , &m_viewProj[_view].un.f4x4 ); _renderer->setShaderUniform4x4f(flags , predefined.m_loc @@ -295,15 +271,15 @@ namespace bgfx break; default: - BX_CHECK(false, "predefined %d not handled", predefined.m_type); + BX_ASSERT(false, "predefined %d not handled", predefined.m_type); break; } } } - Matrix4 m_viewTmp[2][BGFX_CONFIG_MAX_VIEWS]; - Matrix4 m_viewProj[2][BGFX_CONFIG_MAX_VIEWS]; - Matrix4* m_view[2]; + Matrix4 m_viewTmp[BGFX_CONFIG_MAX_VIEWS]; + Matrix4 m_viewProj[BGFX_CONFIG_MAX_VIEWS]; + Matrix4* m_view; Rect m_rect; Matrix4 m_invView; Matrix4 m_invProj; @@ -328,7 +304,7 @@ namespace bgfx handle = m_alloc.alloc(); } - BX_CHECK(UINT16_MAX != handle, "Failed to find handle."); + BX_ASSERT(UINT16_MAX != handle, "Failed to find handle."); Data& data = m_data[handle]; data.m_hash = _key; @@ -336,7 +312,7 @@ namespace bgfx data.m_parent = _parent; m_hashMap.insert(stl::make_pair(_key, handle) ); - return &m_data[handle].m_value; + return bx::addressOf(m_data[handle].m_value); } Ty* find(uint64_t _key) @@ -346,7 +322,7 @@ namespace bgfx { uint16_t handle = it->second; m_alloc.touch(handle); - return &m_data[handle].m_value; + return bx::addressOf(m_data[handle].m_value); } return NULL; @@ -481,11 +457,12 @@ namespace bgfx return true; } - for (uint32_t idx = 0, streamMask = _new.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = _new.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ; streamMask >>= 1, idx += 1 ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; @@ -522,9 +499,9 @@ namespace bgfx if (m_enabled) { ViewStats& viewStats = m_frame->m_perfStats.viewStats[m_numViews]; - viewStats.cpuTimeElapsed = -bx::getHPCounter(); + viewStats.cpuTimeBegin = bx::getHPCounter(); - m_queryIdx = m_gpuTimer.begin(_view); + m_queryIdx = m_gpuTimer.begin(_view, m_frame->m_frameNum); viewStats.view = ViewId(_view); bx::strCopy(viewStats.name @@ -544,8 +521,10 @@ namespace bgfx ViewStats& viewStats = m_frame->m_perfStats.viewStats[m_numViews]; const typename Ty::Result& result = m_gpuTimer.m_result[viewStats.view]; - viewStats.cpuTimeElapsed += bx::getHPCounter(); - viewStats.gpuTimeElapsed = result.m_end - result.m_begin; + viewStats.cpuTimeEnd = bx::getHPCounter(); + viewStats.gpuTimeBegin = result.m_begin; + viewStats.gpuTimeEnd = result.m_end; + viewStats.gpuFrameNum = result.m_frameNum; ++m_numViews; m_queryIdx = UINT32_MAX; diff --git a/3rdparty/bgfx/src/renderer_agc.cpp b/3rdparty/bgfx/src/renderer_agc.cpp new file mode 100644 index 00000000000..f393b3b4400 --- /dev/null +++ b/3rdparty/bgfx/src/renderer_agc.cpp @@ -0,0 +1,20 @@ +/* + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "bgfx_p.h" + +namespace bgfx { namespace agc +{ + RendererContextI* rendererCreate(const Init& _init) + { + BX_UNUSED(_init); + return NULL; + } + + void rendererDestroy() + { + } + +} /* namespace agc */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/renderer_d3d.h b/3rdparty/bgfx/src/renderer_d3d.h index 25983d6dcd6..d0ec4ebdaf9 100644 --- a/3rdparty/bgfx/src/renderer_d3d.h +++ b/3rdparty/bgfx/src/renderer_d3d.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_D3D_H_HEADER_GUARD @@ -19,6 +19,10 @@ # define DX_CHECK_EXTRA_ARGS #endif // BGFX_CONFIG_DEBUG && BGFX_CONFIG_RENDERER_DIRECT3D9 +#ifndef DXGI_ERROR_NOT_CURRENTLY_AVAILABLE +# define DXGI_ERROR_NOT_CURRENTLY_AVAILABLE HRESULT(0x887A0022) +#endif // DXGI_ERROR_NOT_CURRENTLY_AVAILABLE + #define DXGI_FORMAT_ASTC_4X4_TYPELESS DXGI_FORMAT(133) #define DXGI_FORMAT_ASTC_4X4_UNORM DXGI_FORMAT(134) #define DXGI_FORMAT_ASTC_4X4_UNORM_SRGB DXGI_FORMAT(135) @@ -64,45 +68,35 @@ namespace bgfx { - constexpr uint32_t toRgba8(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a) - { - return 0 - | (uint32_t(_r)<<24) - | (uint32_t(_g)<<16) - | (uint32_t(_b)<< 8) - | (uint32_t(_a) ) - ; - } - -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT typedef ::IUnknown IUnknown; #else typedef ::IGraphicsUnknown IUnknown; #endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT -#define _DX_CHECK(_call) \ - BX_MACRO_BLOCK_BEGIN \ - HRESULT __hr__ = _call; \ - BX_CHECK(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \ - , (uint32_t)__hr__ \ - DX_CHECK_EXTRA_ARGS \ - ); \ +#define _DX_CHECK(_call) \ + BX_MACRO_BLOCK_BEGIN \ + HRESULT __hr__ = _call; \ + BX_ASSERT(SUCCEEDED(__hr__), #_call " FAILED 0x%08x" DX_CHECK_EXTRA_F "\n" \ + , (uint32_t)__hr__ \ + DX_CHECK_EXTRA_ARGS \ + ); \ BX_MACRO_BLOCK_END -#define _DX_RELEASE(_ptr, _expected, _check) \ - BX_MACRO_BLOCK_BEGIN \ - if (NULL != (_ptr) ) \ - { \ - ULONG count = (_ptr)->Release(); \ +#define _DX_RELEASE(_ptr, _expected, _check) \ + BX_MACRO_BLOCK_BEGIN \ + if (NULL != (_ptr) ) \ + { \ + ULONG count = (_ptr)->Release(); \ _check(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); BX_UNUSED(count); \ - _ptr = NULL; \ - } \ + _ptr = NULL; \ + } \ BX_MACRO_BLOCK_END -#define _DX_CHECK_REFCOUNT(_ptr, _expected) \ - BX_MACRO_BLOCK_BEGIN \ - ULONG count = getRefCount(_ptr); \ - BX_CHECK(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); \ +#define _DX_CHECK_REFCOUNT(_ptr, _expected) \ + BX_MACRO_BLOCK_BEGIN \ + ULONG count = getRefCount(_ptr); \ + BX_ASSERT(isGraphicsDebuggerPresent() || _expected == count, "%p RefCount is %d (expected %d).", _ptr, count, _expected); \ BX_MACRO_BLOCK_END #define _DX_NAME(_ptr, _format, ...) setDebugObjectName(_ptr, _format, ##__VA_ARGS__) @@ -121,7 +115,7 @@ namespace bgfx # define DX_NAME(_ptr, _format, ...) #endif // BGFX_CONFIG_DEBUG_OBJECT_NAME -#define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK) +#define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_ASSERT) #define DX_RELEASE_W(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN) #define DX_RELEASE_I(_ptr) _DX_RELEASE(_ptr, 0, BX_NOOP) @@ -133,11 +127,11 @@ namespace bgfx typedef void (WINAPI* PFN_D3DPERF_SET_OPTIONS)(DWORD _options); typedef DWORD (WINAPI* PFN_D3DPERF_GET_STATUS)(); -#define _PIX_SETMARKER(_col, _name) D3DPERF_SetMarker(_col, _name) -#define _PIX_BEGINEVENT(_col, _name) D3DPERF_BeginEvent(_col, _name) -#define _PIX_ENDEVENT() D3DPERF_EndEvent() +#define _PIX_SETMARKER(_color, _name) D3DPERF_SetMarker(_color, _name) +#define _PIX_BEGINEVENT(_color, _name) D3DPERF_BeginEvent(_color, _name) +#define _PIX_ENDEVENT() D3DPERF_EndEvent() -#if BGFX_CONFIG_DEBUG_PIX +#if BGFX_CONFIG_DEBUG_ANNOTATION # define PIX_SETMARKER(_color, _name) _PIX_SETMARKER(_color, _name) # define PIX_BEGINEVENT(_color, _name) _PIX_BEGINEVENT(_color, _name) # define PIX_ENDEVENT() _PIX_ENDEVENT() @@ -145,15 +139,7 @@ namespace bgfx # define PIX_SETMARKER(_color, _name) BX_UNUSED(_name) # define PIX_BEGINEVENT(_color, _name) BX_UNUSED(_name) # define PIX_ENDEVENT() -#endif // BGFX_CONFIG_DEBUG_PIX - -#define D3DCOLOR_FRAME toRgba8(0xff, 0xd7, 0xc9, 0xff) -#define D3DCOLOR_VIEW toRgba8(0xe4, 0xb4, 0x8e, 0xff) -#define D3DCOLOR_VIEW_L toRgba8(0xf9, 0xee, 0xe5, 0xff) -#define D3DCOLOR_VIEW_R toRgba8(0xe8, 0xd3, 0xc0, 0xff) -#define D3DCOLOR_DRAW toRgba8(0xc6, 0xe5, 0xb9, 0xff) -#define D3DCOLOR_COMPUTE toRgba8(0xa7, 0xdb, 0xd8, 0xff) -#define D3DCOLOR_MARKER toRgba8(0xff, 0x00, 0x00, 0xff) +#endif // BGFX_CONFIG_DEBUG_ANNOTATION inline bool isType(IUnknown* _interface, const GUID& _id) { @@ -182,7 +168,7 @@ namespace bgfx { invalidate(_key); m_hashMap.insert(stl::make_pair(_key, _value) ); - BX_CHECK(isGraphicsDebuggerPresent() + BX_ASSERT(isGraphicsDebuggerPresent() || 1 == getRefCount(_value), "Interface ref count %d, hash %" PRIx64 "." , getRefCount(_value) , _key diff --git a/3rdparty/bgfx/src/renderer_d3d11.cpp b/3rdparty/bgfx/src/renderer_d3d11.cpp index 7fc4e8777e4..16095248be9 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.cpp +++ b/3rdparty/bgfx/src/renderer_d3d11.cpp @@ -1,17 +1,33 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" #if BGFX_CONFIG_RENDERER_DIRECT3D11 # include "renderer_d3d11.h" +# include <bx/pixelformat.h> namespace bgfx { namespace d3d11 { static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; - static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + static char s_viewName [BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + + inline void setViewType(ViewId _view, const bx::StringView _str) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION | BGFX_CONFIG_PROFILER) ) + { + const uint32_t len = _str.getLength(); + + bx::memCopy(&s_viewName[_view][3], _str.getPtr(), len); + + wchar_t tmpW[16]; + mbstowcs(tmpW, _str.getPtr(), len); + + bx::memCopy(&s_viewNameW[_view][3], tmpW, len*2); + } + } struct PrimInfo { @@ -208,11 +224,19 @@ namespace bgfx { namespace d3d11 { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATCE { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATCI { DXGI_FORMAT_ASTC_4X4_UNORM, DXGI_FORMAT_ASTC_4X4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_4X4_UNORM_SRGB }, // ASTC4x4 + { DXGI_FORMAT_ASTC_5X4_UNORM, DXGI_FORMAT_ASTC_5X4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_5X4_UNORM_SRGB }, // ASTC5x4 { DXGI_FORMAT_ASTC_5X5_UNORM, DXGI_FORMAT_ASTC_5X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_5X5_UNORM_SRGB }, // ASTC5x5 + { DXGI_FORMAT_ASTC_6X5_UNORM, DXGI_FORMAT_ASTC_6X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_6X5_UNORM_SRGB }, // ASTC6x5 { DXGI_FORMAT_ASTC_6X6_UNORM, DXGI_FORMAT_ASTC_6X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_6X6_UNORM_SRGB }, // ASTC6x6 { DXGI_FORMAT_ASTC_8X5_UNORM, DXGI_FORMAT_ASTC_8X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X5_UNORM_SRGB }, // ASTC8x5 { DXGI_FORMAT_ASTC_8X6_UNORM, DXGI_FORMAT_ASTC_8X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X6_UNORM_SRGB }, // ASTC8x6 + { DXGI_FORMAT_ASTC_8X8_UNORM, DXGI_FORMAT_ASTC_8X8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X8_UNORM_SRGB }, // ASTC8x8 { DXGI_FORMAT_ASTC_10X5_UNORM, DXGI_FORMAT_ASTC_10X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X5_UNORM_SRGB }, // ASTC10x5 + { DXGI_FORMAT_ASTC_10X6_UNORM, DXGI_FORMAT_ASTC_10X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X6_UNORM_SRGB }, // ASTC10x6 + { DXGI_FORMAT_ASTC_10X8_UNORM, DXGI_FORMAT_ASTC_10X8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X8_UNORM_SRGB }, // ASTC10x8 + { DXGI_FORMAT_ASTC_10X10_UNORM, DXGI_FORMAT_ASTC_10X10_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X10_UNORM_SRGB}, // ASTC10x10 + { DXGI_FORMAT_ASTC_12X10_UNORM, DXGI_FORMAT_ASTC_12X10_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_12X10_UNORM_SRGB}, // ASTC12x10 + { DXGI_FORMAT_ASTC_12X12_UNORM, DXGI_FORMAT_ASTC_12X12_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_12X12_UNORM_SRGB}, // ASTC12x12 { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // Unknown { DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R1 { DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // A8 @@ -258,8 +282,11 @@ namespace bgfx { namespace d3d11 { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32I { DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32U { DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32F + { DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // B5G6R5 { DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R5G6B5 + { DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BGRA4 { DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA4 + { DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BGR5A1 { DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB5A1 { DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB10A2 { DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG11B10F @@ -333,19 +360,19 @@ namespace bgfx { namespace d3d11 }; BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) ); - static D3D11_INPUT_ELEMENT_DESC* fillVertexDecl(uint8_t _stream, D3D11_INPUT_ELEMENT_DESC* _out, const VertexDecl& _decl) + static D3D11_INPUT_ELEMENT_DESC* fillVertexLayout(uint8_t _stream, D3D11_INPUT_ELEMENT_DESC* _out, const VertexLayout& _layout) { D3D11_INPUT_ELEMENT_DESC* elem = _out; for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - if (UINT16_MAX != _decl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { bx::memCopy(elem, &s_attrib[attr], sizeof(D3D11_INPUT_ELEMENT_DESC) ); elem->InputSlot = _stream; - if (0 == _decl.m_attributes[attr]) + if (0 == _layout.m_attributes[attr]) { elem->AlignedByteOffset = 0; } @@ -355,9 +382,9 @@ namespace bgfx { namespace d3d11 AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); + _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); elem->Format = s_attribType[type][num-1][normalized]; - elem->AlignedByteOffset = _decl.m_offset[attr]; + elem->AlignedByteOffset = _layout.m_offset[attr]; } ++elem; @@ -376,12 +403,14 @@ namespace bgfx { namespace d3d11 void clear() { - bx::memSet(m_srv, 0, sizeof(m_srv) ); + bx::memSet(m_uav, 0, sizeof(m_uav) ); + bx::memSet(m_srv, 0, sizeof(m_srv) ); bx::memSet(m_sampler, 0, sizeof(m_sampler) ); } - ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; - ID3D11SamplerState* m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + ID3D11UnorderedAccessView* m_uav[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + ID3D11SamplerState* m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; }; BX_PRAGMA_DIAGNOSTIC_PUSH(); @@ -523,11 +552,13 @@ namespace bgfx { namespace d3d11 { uint8_t temp[28]; + bx::ErrorAssert err; + bx::StaticMemoryBlockWriter writer(&temp, sizeof(temp) ); - bx::write(&writer, "INTCEXTNCAPSFUNC", 16); - bx::write(&writer, kIntelExtensionInterfaceVersion); - bx::write(&writer, UINT32_C(0) ); - bx::write(&writer, UINT32_C(0) ); + bx::write(&writer, "INTCEXTNCAPSFUNC", 16, &err); + bx::write(&writer, kIntelExtensionInterfaceVersion, &err); + bx::write(&writer, uint32_t(0), &err); + bx::write(&writer, uint32_t(0), &err); if (SUCCEEDED(setIntelExtension(_device, temp, sizeof(temp) ) ) ) { @@ -535,10 +566,10 @@ namespace bgfx { namespace d3d11 bx::skip(&reader, 16); uint32_t version; - bx::read(&reader, version); + bx::read(&reader, version, &err); uint32_t driverVersion; - bx::read(&reader, driverVersion); + bx::read(&reader, driverVersion, &err); return version <= driverVersion; } @@ -648,6 +679,8 @@ namespace bgfx { namespace d3d11 , m_ags(NULL) , m_featureLevel(D3D_FEATURE_LEVEL(0) ) , m_swapChain(NULL) + , m_msaaRt(NULL) + , m_needPresent(false) , m_lost(false) , m_numWindows(0) , m_device(NULL) @@ -757,7 +790,7 @@ namespace bgfx { namespace d3d11 for (int32_t ii = 0; ii < numGPUs; ++ii) { - long long memSize; + int64_t memSize; result = agsGetGPUMemorySize(m_ags, ii, &memSize); if (AGS_SUCCESS == result) { @@ -786,11 +819,19 @@ namespace bgfx { namespace d3d11 m_nvapi.init(); #if USE_D3D11_DYNAMIC_LIB - m_d3d11Dll = bx::dlopen("d3d11.dll"); + const char* d3d11DllName = +#if BX_PLATFORM_LINUX + "d3d11.so" +#else + "d3d11.dll" +#endif // BX_PLATFORM_LINUX + ; + + m_d3d11Dll = bx::dlopen(d3d11DllName); if (NULL == m_d3d11Dll) { - BX_TRACE("Init error: Failed to load d3d11.dll."); + BX_TRACE("Init error: Failed to load %s.", d3d11DllName); goto error; } @@ -798,21 +839,30 @@ namespace bgfx { namespace d3d11 m_d3d9Dll = NULL; - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) { // D3D11_1.h has ID3DUserDefinedAnnotation - // http://msdn.microsoft.com/en-us/library/windows/desktop/hh446881%28v=vs.85%29.aspx + // https://web.archive.org/web/20190207230424/https://docs.microsoft.com/en-us/windows/desktop/api/d3d11_1/nn-d3d11_1-id3duserdefinedannotation m_d3d9Dll = bx::dlopen("d3d9.dll"); if (NULL != m_d3d9Dll) { D3DPERF_SetMarker = (PFN_D3DPERF_SET_MARKER )bx::dlsym(m_d3d9Dll, "D3DPERF_SetMarker" ); D3DPERF_BeginEvent = (PFN_D3DPERF_BEGIN_EVENT)bx::dlsym(m_d3d9Dll, "D3DPERF_BeginEvent"); D3DPERF_EndEvent = (PFN_D3DPERF_END_EVENT )bx::dlsym(m_d3d9Dll, "D3DPERF_EndEvent" ); - BX_CHECK(NULL != D3DPERF_SetMarker - && NULL != D3DPERF_BeginEvent - && NULL != D3DPERF_EndEvent - , "Failed to initialize PIX events." - ); + + if (NULL == D3DPERF_SetMarker + || NULL == D3DPERF_BeginEvent + || NULL == D3DPERF_EndEvent) + { + BX_TRACE("Failed to initialize PIX events."); + + D3DPERF_SetMarker = NULL; + D3DPERF_BeginEvent = NULL; + D3DPERF_EndEvent = NULL; + + bx::dlclose(m_d3d9Dll); + m_d3d9Dll = NULL; + } } } @@ -833,7 +883,20 @@ namespace bgfx { namespace d3d11 errorState = ErrorState::LoadedDXGI; - if (NULL == m_device) + if (NULL != m_device) + { + m_device->AddRef(); + m_device->GetImmediateContext(&m_deviceCtx); + + if (NULL == m_deviceCtx) + { + BX_TRACE("Init error: Unable to retrieve Direct3D11 ImmediateContext."); + goto error; + } + + m_featureLevel = m_device->GetFeatureLevel(); + } + else { if (NULL != m_renderDocDll) { @@ -914,18 +977,6 @@ namespace bgfx { namespace d3d11 goto error; } } - else - { - m_device->GetImmediateContext(&m_deviceCtx); - - if (NULL == m_deviceCtx) - { - BX_TRACE("Init error: Unable to retrieve Direct3D11 ImmediateContext."); - goto error; - } - - m_featureLevel = m_device->GetFeatureLevel(); - } m_dxgi.update(m_device); @@ -963,16 +1014,18 @@ namespace bgfx { namespace d3d11 m_nvapi.shutdown(); } + m_msaaRt = NULL; + if (NULL == g_platformData.backBuffer) { HRESULT hr = S_OK; m_swapEffect = -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS DXGI_SWAP_EFFECT_FLIP_DISCARD #else DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL -#endif // !BX_PLATFORM_WINDOWS +#endif // BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS ; m_swapBufferCount = bx::clamp<uint8_t>(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS); @@ -980,6 +1033,17 @@ namespace bgfx { namespace d3d11 bx::memSet(&m_scd, 0, sizeof(m_scd) ); m_scd.width = _init.resolution.width; m_scd.height = _init.resolution.height; + + /* + * According to https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/converting-data-color-space , + * it is OK to create the backbuffer with m_fmt (a non- _SRGB format), and then create the render target view into it + * with m_fmtSrgb (the _SRGB format of same), and it will work identically as if you had created the swapchain with + * m_fmtSrgb as the backbuffer format. + * + * Moreover, it is actually not desirable to create the backbuffer with an _SRGB format, because that + * is incompatible with the flip presentation model, which is desirable for various reasons including + * player embedding. + */ m_scd.format = s_textureFormat[_init.resolution.format].m_fmt; updateMsaa(m_scd.format); @@ -992,16 +1056,19 @@ namespace bgfx { namespace d3d11 : DXGI_SCALING_STRETCH ; m_scd.swapEffect = m_swapEffect; - m_scd.alphaMode = DXGI_ALPHA_MODE_IGNORE; - m_scd.flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; - m_scd.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, 3); + m_scd.alphaMode = (_init.resolution.reset & BGFX_RESET_TRANSPARENT_BACKBUFFER) + ? DXGI_ALPHA_MODE_PREMULTIPLIED + : DXGI_ALPHA_MODE_IGNORE + ; + + m_scd.flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + + m_scd.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY); m_scd.nwh = g_platformData.nwh; m_scd.ndt = g_platformData.ndt; m_scd.windowed = true; - m_msaaRt = NULL; - if (NULL != m_scd.nwh) { hr = m_dxgi.createSwapChain(m_device @@ -1011,6 +1078,12 @@ namespace bgfx { namespace d3d11 if (FAILED(hr) ) { + BX_TRACE( + "CreateSwapChain with DXGI_SWAP_EFFECT(%d) failed with HRESULT(%x)" + , m_scd.swapEffect + , hr + ); + // DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL is not available on win7 // Try again with DXGI_SWAP_EFFECT_DISCARD m_swapEffect = DXGI_SWAP_EFFECT_DISCARD; @@ -1043,7 +1116,12 @@ namespace bgfx { namespace d3d11 desc.Height = m_scd.height; desc.MipLevels = 1; desc.ArraySize = 1; - desc.Format = m_scd.format; + /* + * According to https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/converting-data-color-space , + * ONLY the backbuffer from swapchain can be created without *_SRGB format, custom backbuffer should be created the same + * format as well as render target view. + */ + desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? s_textureFormat[m_resolution.format].m_fmtSrgb : s_textureFormat[m_resolution.format].m_fmt; desc.SampleDesc = m_scd.sampleDesc; desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_RENDER_TARGET; @@ -1081,7 +1159,7 @@ namespace bgfx { namespace d3d11 m_numWindows = 1; #if USE_D3D11_DYNAMIC_LIB - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) { HRESULT hr = m_deviceCtx->QueryInterface(IID_ID3DUserDefinedAnnotation, (void**)&m_annotation); @@ -1154,6 +1232,9 @@ namespace bgfx { namespace d3d11 : 0) | BGFX_CAPS_TEXTURE_2D_ARRAY | BGFX_CAPS_TEXTURE_CUBE_ARRAY + | ((m_featureLevel >= D3D_FEATURE_LEVEL_11_1) + ? BGFX_CAPS_IMAGE_RW + : 0) ); m_timerQuerySupport = m_featureLevel >= D3D_FEATURE_LEVEL_10_0; @@ -1220,11 +1301,6 @@ namespace bgfx { namespace d3d11 if (m_featureLevel == D3D_FEATURE_LEVEL_10_0 || m_featureLevel == D3D_FEATURE_LEVEL_10_1) { - struct D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS - { - BOOL ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x; - }; - D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS data; HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &data, sizeof(data) ); if (SUCCEEDED(hr) @@ -1245,13 +1321,8 @@ namespace bgfx { namespace d3d11 } else { - struct D3D11_FEATURE_DATA_D3D9_SIMPLE_INSTANCING_SUPPORT - { - BOOL SimpleInstancingSupported; - }; - D3D11_FEATURE_DATA_D3D9_SIMPLE_INSTANCING_SUPPORT data; - HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE(11) /*D3D11_FEATURE_D3D9_SIMPLE_INSTANCING_SUPPORT*/, &data, sizeof(data) ); + HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE_D3D9_SIMPLE_INSTANCING_SUPPORT, &data, sizeof(data) ); if (SUCCEEDED(hr) && data.SimpleInstancingSupported) { @@ -1262,13 +1333,8 @@ namespace bgfx { namespace d3d11 // shadow compare is optional on 9_1 through 9_3 targets if (m_featureLevel <= D3D_FEATURE_LEVEL_9_3) { - struct D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT - { - BOOL SupportsDepthAsTextureWithLessEqualComparisonFilter; - }; - D3D11_FEATURE_DATA_D3D9_SHADOW_SUPPORT data; - HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE(9) /*D3D11_FEATURE_D3D9_SHADOW_SUPPORT*/, &data, sizeof(data) ); + HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE_D3D9_SHADOW_SUPPORT, &data, sizeof(data) ); if (SUCCEEDED(hr) && data.SupportsDepthAsTextureWithLessEqualComparisonFilter) { @@ -1276,6 +1342,17 @@ namespace bgfx { namespace d3d11 } } + // support for SV_ViewportArrayIndex and SV_RenderTargetArrayIndex in the vertex shader is optional + { + D3D11_FEATURE_DATA_D3D11_OPTIONS3 data; + HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS3, &data, sizeof(data) ); + if (SUCCEEDED(hr) + && data.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer) + { + g_caps.supported |= BGFX_CAPS_VIEWPORT_LAYER_ARRAY; + } + } + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; @@ -1288,15 +1365,9 @@ namespace bgfx { namespace d3d11 if (DXGI_FORMAT_UNKNOWN != fmt) { - if (BX_ENABLED(BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) ) + if (BX_ENABLED(BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) ) { - struct D3D11_FEATURE_DATA_FORMAT_SUPPORT - { - DXGI_FORMAT InFormat; - UINT OutFormatSupport; - }; - - D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 + D3D11_FEATURE_DATA_FORMAT_SUPPORT data; data.InFormat = fmt; HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); if (SUCCEEDED(hr) ) @@ -1336,7 +1407,7 @@ namespace bgfx { namespace d3d11 support |= 0 != (data.OutFormatSupport & (0 | D3D11_FORMAT_SUPPORT_SHADER_LOAD ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ : BGFX_CAPS_FORMAT_TEXTURE_NONE ; @@ -1371,23 +1442,35 @@ namespace bgfx { namespace d3d11 } else { - BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) ); + BX_TRACE( + "CheckFeatureSupport failed with HRESULT(%x) for format %s." + , hr + , getName(TextureFormat::Enum(ii) ) + ); } - if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE) ) + if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ) ) { + D3D11_FEATURE_DATA_FORMAT_SUPPORT2 data2; + // clear image flag for additional testing - support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE; + support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ; - data.InFormat = s_textureFormat[ii].m_fmt; - hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data, sizeof(data) ); + data2.InFormat = s_textureFormat[ii].m_fmt; + hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data2, sizeof(data2) ); if (SUCCEEDED(hr) ) { - support |= 0 != (data.OutFormatSupport & (0 + support |= 0 != (data2.OutFormatSupport2 & (0 | D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data2.OutFormatSupport2 & (0 | D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE : BGFX_CAPS_FORMAT_TEXTURE_NONE ; } @@ -1399,19 +1482,19 @@ namespace bgfx { namespace d3d11 | BGFX_CAPS_FORMAT_TEXTURE_2D | BGFX_CAPS_FORMAT_TEXTURE_3D | BGFX_CAPS_FORMAT_TEXTURE_CUBE - | BGFX_CAPS_FORMAT_TEXTURE_IMAGE | BGFX_CAPS_FORMAT_TEXTURE_VERTEX - | BGFX_CAPS_FORMAT_TEXTURE_IMAGE | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA | BGFX_CAPS_FORMAT_TEXTURE_MSAA + | BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ + | BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE ; } } if (DXGI_FORMAT_UNKNOWN != fmtSrgb) { - if (BX_ENABLED(BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) ) + if (BX_ENABLED(BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) ) { struct D3D11_FEATURE_DATA_FORMAT_SUPPORT { @@ -1419,7 +1502,7 @@ namespace bgfx { namespace d3d11 UINT OutFormatSupport; }; - D3D11_FEATURE_DATA_FORMAT_SUPPORT data; // D3D11_FEATURE_DATA_FORMAT_SUPPORT2 + D3D11_FEATURE_DATA_FORMAT_SUPPORT data; data.InFormat = fmtSrgb; HRESULT hr = m_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); if (SUCCEEDED(hr) ) @@ -1447,7 +1530,11 @@ namespace bgfx { namespace d3d11 } else { - BX_TRACE("CheckFeatureSupport failed with %x for sRGB format %s.", hr, getName(TextureFormat::Enum(ii) ) ); + BX_TRACE( + "CheckFeatureSupport failed with HRESULT(%x) for sRGB format %s." + , hr + , getName(TextureFormat::Enum(ii) ) + ); } } else @@ -1528,6 +1615,10 @@ namespace bgfx { namespace d3d11 DX_RELEASE(m_annotation, 1); DX_RELEASE_W(m_infoQueue, 0); DX_RELEASE(m_msaaRt, 0); +#if BX_PLATFORM_WINRT + // Remove swap chain from SwapChainPanel (nwh) if applicable + m_dxgi.removeSwapChain(m_scd, &m_swapChain); +#endif DX_RELEASE(m_swapChain, 0); DX_RELEASE(m_deviceCtx, 0); DX_RELEASE(m_device, 0); @@ -1615,6 +1706,10 @@ namespace bgfx { namespace d3d11 DX_RELEASE(m_annotation, 1); DX_RELEASE_W(m_infoQueue, 0); DX_RELEASE(m_msaaRt, 0); +#if BX_PLATFORM_WINRT + // Remove swap chain from SwapChainPanel (nwh) if applicable + m_dxgi.removeSwapChain(m_scd, &m_swapChain); +#endif DX_RELEASE(m_swapChain, 0); DX_RELEASE(m_deviceCtx, 0); DX_RELEASE(m_device, 0); @@ -1656,20 +1751,20 @@ namespace bgfx { namespace d3d11 m_indexBuffers[_handle.idx].destroy(); } - void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override + void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) override { - VertexDecl& decl = m_vertexDecls[_handle.idx]; - bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); - dump(decl); + VertexLayout& layout = m_vertexLayouts[_handle.idx]; + bx::memCopy(&layout, &_layout, sizeof(VertexLayout) ); + dump(layout); } - void destroyVertexDecl(VertexDeclHandle /*_handle*/) override + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override { } - void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) override + void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t _flags) override { - m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); + m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _layoutHandle, _flags); } void destroyVertexBuffer(VertexBufferHandle _handle) override @@ -1694,8 +1789,8 @@ namespace bgfx { namespace d3d11 void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) override { - VertexDeclHandle decl = BGFX_INVALID_HANDLE; - m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); + VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE; + m_vertexBuffers[_handle.idx].create(_size, NULL, layoutHandle, _flags); } void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override @@ -1783,7 +1878,7 @@ namespace bgfx { namespace d3d11 bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -1794,7 +1889,7 @@ namespace bgfx { namespace d3d11 tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); tc.m_cubeMap = false; tc.m_mem = NULL; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); texture.destroy(); texture.create(mem, texture.m_flags, 0); @@ -1871,7 +1966,7 @@ namespace bgfx { namespace d3d11 BX_FREE(g_allocator, m_uniforms[_handle.idx]); } - uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num); + const uint32_t size = bx::alignUp(g_uniformTypeSize[_type]*_num, 16); void* data = BX_ALLOC(g_allocator, size); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; @@ -1962,7 +2057,7 @@ namespace bgfx { namespace d3d11 void updateViewName(ViewId _id, const char* _name) override { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) { mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] , _name @@ -1981,36 +2076,45 @@ namespace bgfx { namespace d3d11 bx::memCopy(m_uniforms[_loc], _data, _size); } - void setMarker(const char* _marker, uint32_t _size) override + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - uint32_t size = _size*sizeof(wchar_t); - wchar_t* name = (wchar_t*)alloca(size); - mbstowcs(name, _marker, size-2); - PIX_SETMARKER(D3DCOLOR_MARKER, name); - } + m_occlusionQuery.invalidate(_handle); } - void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + void setMarker(const char* _marker, uint16_t _len) override { - m_occlusionQuery.invalidate(_handle); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + uint32_t size = _len*sizeof(wchar_t); + wchar_t* name = (wchar_t*)alloca(size+2); + name[_len] = L'\0'; + mbstowcs(name, _marker, _len); + PIX_SETMARKER(kColorMarker, name); + } } - virtual void setName(Handle _handle, const char* _name) override + virtual void setName(Handle _handle, const char* _name, uint16_t _len) override { switch (_handle.type) { + case Handle::IndexBuffer: + setDebugObjectName(m_indexBuffers[_handle.idx].m_ptr, "%.*s", _len, _name); + break; + case Handle::Shader: - setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name); + setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%.*s", _len, _name); break; case Handle::Texture: - setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name); + setDebugObjectName(m_textures[_handle.idx].m_ptr, "%.*s", _len, _name); + break; + + case Handle::VertexBuffer: + setDebugObjectName(m_vertexBuffers[_handle.idx].m_ptr, "%.*s", _len, _name); break; default: - BX_CHECK(false, "Invalid handle type?! %d", _handle.type); + BX_ASSERT(false, "Invalid handle type?! %d", _handle.type); break; } } @@ -2054,11 +2158,11 @@ namespace bgfx { namespace d3d11 deviceCtx->PSSetConstantBuffers(0, 1, &program.m_fsh->m_buffer); VertexBufferD3D11& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; - VertexDecl& vertexDecl = m_vertexDecls[_blitter.m_vb->decl.idx]; - uint32_t stride = vertexDecl.m_stride; + VertexLayout& layout = m_vertexLayouts[_blitter.m_vb->layoutHandle.idx]; + uint32_t stride = layout.m_stride; uint32_t offset = 0; deviceCtx->IASetVertexBuffers(0, 1, &vb.m_ptr, &stride, &offset); - setInputLayout(vertexDecl, program, 0); + setInputLayout(layout, program, 0); IndexBufferD3D11& ib = m_indexBuffers[_blitter.m_ib->handle.idx]; deviceCtx->IASetIndexBuffer(ib.m_ptr, DXGI_FORMAT_R16_UINT, 0); @@ -2083,7 +2187,7 @@ namespace bgfx { namespace d3d11 ID3D11DeviceContext* deviceCtx = m_deviceCtx; m_indexBuffers [_blitter.m_ib->handle.idx].update(0, _numIndices*2, _blitter.m_ib->data, true); - m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data, true); + m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_layout.m_stride, _blitter.m_vb->data, true); deviceCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); deviceCtx->DrawIndexed(_numIndices, 0, 0); @@ -2136,10 +2240,12 @@ namespace bgfx { namespace d3d11 : D3D11_RTV_DIMENSION_TEXTURE2D ; desc.Texture2D.MipSlice = 0; - desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) - ? m_scd.format == DXGI_FORMAT_R8G8B8A8_UNORM ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : m_scd.format - : m_scd.format - ; + + /* go find the srgb version of this format to make a render target view + * with the srgb version. this is OK because of this: + * https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/converting-data-color-space + */ + desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? s_textureFormat[m_resolution.format].m_fmtSrgb : s_textureFormat[m_resolution.format].m_fmt; DX_CHECK(m_device->CreateRenderTargetView(NULL == m_msaaRt ? backBufferColor : m_msaaRt, &desc, &m_backBufferColor) ); DX_RELEASE(backBufferColor, 0); @@ -2209,7 +2315,15 @@ namespace bgfx { namespace d3d11 if (NULL != m_swapChain && m_needPresent) { - hr = m_swapChain->Present(syncInterval, 0); + uint32_t presentFlags = 0; + + if (!syncInterval + && m_dxgi.tearingSupported() ) + { + presentFlags |= DXGI_PRESENT_ALLOW_TEARING; + } + + hr = m_swapChain->Present(syncInterval, presentFlags); m_needPresent = false; } @@ -2220,9 +2334,10 @@ namespace bgfx { namespace d3d11 } m_lost = isLost(hr); - BGFX_FATAL(!m_lost + BGFX_FATAL( + !m_lost , bgfx::Fatal::DeviceLost - , "Device is lost. FAILED 0x%08x %s (%s)" + , "Device is lost. FAILED HRESULT(%x) %s (%s)" , hr , getLostReason(hr) , DXGI_ERROR_DEVICE_REMOVED == hr ? getLostReason(m_device->GetDeviceRemovedReason() ) : "no info" @@ -2273,6 +2388,22 @@ namespace bgfx { namespace d3d11 } } + void updateNativeWindow() + { +#if BX_PLATFORM_WINRT + // SwapChainPanels can be dynamically updated + if (m_scd.ndt == reinterpret_cast<void*>(2) + && (m_scd.nwh != g_platformData.nwh || m_scd.ndt != g_platformData.ndt)) + { + // Remove swap chain from SwapChainPanel (nwh) if applicable + m_dxgi.removeSwapChain(m_scd, &m_swapChain); + // Update nwh after removing swap chain + m_scd.nwh = g_platformData.nwh; + m_scd.ndt = g_platformData.ndt; + } +#endif + } + bool updateResolution(const Resolution& _resolution) { const bool suspended = !!( _resolution.reset & BGFX_RESET_SUSPEND); @@ -2336,7 +2467,7 @@ namespace bgfx { namespace d3d11 uint32_t flags = _resolution.reset & (~BGFX_RESET_INTERNAL_FORCE); bool resize = true - && !BX_ENABLED(BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT) // can't use ResizeBuffers on Windows Phone + && !BX_ENABLED(BX_PLATFORM_XBOXONE) && (m_resolution.reset&BGFX_RESET_MSAA_MASK) == (flags&BGFX_RESET_MSAA_MASK) ; @@ -2348,7 +2479,9 @@ namespace bgfx { namespace d3d11 m_scd.width = _resolution.width; m_scd.height = _resolution.height; - m_scd.format = s_textureFormat[_resolution.format].m_fmt; + // see comment in init() about why we don't worry about BGFX_RESET_SRGB_BACKBUFFER here + m_scd.format = s_textureFormat[_resolution.format].m_fmt + ; preReset(); @@ -2376,8 +2509,11 @@ namespace bgfx { namespace d3d11 updateMsaa(m_scd.format); m_scd.sampleDesc = s_msaa[(m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; +#if BX_PLATFORM_WINRT + // Remove swap chain from SwapChainPanel (nwh) if applicable + m_dxgi.removeSwapChain(m_scd, &m_swapChain); +#endif DX_RELEASE(m_swapChain, 0); - HRESULT hr = m_dxgi.createSwapChain(m_device , m_scd , &m_swapChain @@ -2392,7 +2528,7 @@ namespace bgfx { namespace d3d11 desc.Height = m_scd.height; desc.MipLevels = 1; desc.ArraySize = 1; - desc.Format = m_scd.format; + desc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) ? s_textureFormat[m_resolution.format].m_fmtSrgb : s_textureFormat[m_resolution.format].m_fmt; desc.SampleDesc = m_scd.sampleDesc; desc.Usage = D3D11_USAGE_DEFAULT; desc.BindFlags = D3D11_BIND_RENDER_TARGET; @@ -2410,7 +2546,7 @@ namespace bgfx { namespace d3d11 void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { - if (_flags&BGFX_UNIFORM_FRAGMENTBIT) + if (_flags&kUniformFragmentBit) { bx::memCopy(&m_fsScratch[_regIndex], _val, _numRegs*16); m_fsChanges += _numRegs; @@ -2470,7 +2606,15 @@ namespace bgfx { namespace d3d11 m_currentColor = m_backBufferColor; m_currentDepthStencil = m_backBufferDepthStencil; - m_deviceCtx->OMSetRenderTargets(1, &m_currentColor, m_currentDepthStencil); + m_deviceCtx->OMSetRenderTargetsAndUnorderedAccessViews( + 1 + , &m_currentColor + , m_currentDepthStencil + , 1 + , 0 + , NULL + , NULL + ); m_needPresent |= _needPresent; } else @@ -2529,19 +2673,19 @@ namespace bgfx { namespace d3d11 } } - void setInputLayout(uint8_t _numStreams, const VertexDecl** _vertexDecls, const ProgramD3D11& _program, uint16_t _numInstanceData) + void setInputLayout(uint8_t _numStreams, const VertexLayout** _layouts, const ProgramD3D11& _program, uint16_t _numInstanceData) { bx::HashMurmur2A murmur; murmur.begin(); murmur.add(_numInstanceData); for (uint8_t stream = 0; stream < _numStreams; ++stream) { - murmur.add(_vertexDecls[stream]->m_hash); + murmur.add(_layouts[stream]->m_hash); } uint64_t layoutHash = (uint64_t(_program.m_vsh->m_hash)<<32) | murmur.end(); - ID3D11InputLayout* layout = m_inputLayoutCache.find(layoutHash); - if (NULL == layout) + ID3D11InputLayout* inputLayout = m_inputLayoutCache.find(layoutHash); + if (NULL == inputLayout) { D3D11_INPUT_ELEMENT_DESC vertexElements[Attrib::Count+1+BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; D3D11_INPUT_ELEMENT_DESC* elem = vertexElements; @@ -2551,19 +2695,19 @@ namespace bgfx { namespace d3d11 for (uint8_t stream = 0; stream < _numStreams; ++stream) { - VertexDecl decl; - bx::memCopy(&decl, _vertexDecls[stream], sizeof(VertexDecl) ); + VertexLayout layout; + bx::memCopy(&layout, _layouts[stream], sizeof(VertexLayout) ); const bool last = stream == _numStreams-1; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) { uint16_t mask = attrMask[ii]; - uint16_t attr = (decl.m_attributes[ii] & mask); + uint16_t attr = (layout.m_attributes[ii] & mask); if (0 == attr || UINT16_MAX == attr) { - decl.m_attributes[ii] = last ? ~attr : UINT16_MAX; + layout.m_attributes[ii] = last ? ~attr : UINT16_MAX; } else { @@ -2571,7 +2715,7 @@ namespace bgfx { namespace d3d11 } } - elem = fillVertexDecl(stream, elem, decl); + elem = fillVertexLayout(stream, elem, layout); } uint32_t num = uint32_t(elem-vertexElements); @@ -2611,18 +2755,18 @@ namespace bgfx { namespace d3d11 , num , _program.m_vsh->m_code->data , _program.m_vsh->m_code->size - , &layout + , &inputLayout ) ); - m_inputLayoutCache.add(layoutHash, layout); + m_inputLayoutCache.add(layoutHash, inputLayout); } - m_deviceCtx->IASetInputLayout(layout); + m_deviceCtx->IASetInputLayout(inputLayout); } - void setInputLayout(const VertexDecl& _vertexDecl, const ProgramD3D11& _program, uint16_t _numInstanceData) + void setInputLayout(const VertexLayout& _layout, const ProgramD3D11& _program, uint16_t _numInstanceData) { - const VertexDecl* decls[1] = { &_vertexDecl }; - setInputLayout(BX_COUNTOF(decls), decls, _program, _numInstanceData); + const VertexLayout* layouts[1] = { &_layout }; + setInputLayout(BX_COUNTOF(layouts), layouts, _program, _numInstanceData); } void setBlendState(uint64_t _state, uint32_t _rgba = 0) @@ -2794,6 +2938,7 @@ namespace bgfx { namespace d3d11 { _state &= 0 | BGFX_STATE_CULL_MASK + | BGFX_STATE_FRONT_CCW | BGFX_STATE_MSAA | BGFX_STATE_LINEAA | BGFX_STATE_CONSERVATIVE_RASTER @@ -2813,7 +2958,7 @@ namespace bgfx { namespace d3d11 D3D11_RASTERIZER_DESC2 desc; desc.FillMode = _wireframe ? D3D11_FILL_WIREFRAME : D3D11_FILL_SOLID; desc.CullMode = s_cullMode[cull]; - desc.FrontCounterClockwise = false; + desc.FrontCounterClockwise = !!(_state&BGFX_STATE_FRONT_CCW); desc.DepthBias = 0; desc.DepthBiasClamp = 0.0f; desc.SlopeScaledDepthBias = 0.0f; @@ -2859,11 +3004,12 @@ namespace bgfx { namespace d3d11 const uint32_t index = (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT; _flags &= BGFX_SAMPLER_BITS_MASK; - // Force both min+max anisotropic, can't be set individually. - _flags |= 0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) ) - ? BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC - : 0 - ; + // Force min+mag anisotropic (can't be set individually) and remove mip (not supported). + if (0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC))) + { + _flags |= BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC; + _flags &= ~BGFX_SAMPLER_MIP_MASK; + } uint32_t hash; ID3D11SamplerState* sampler; @@ -2924,7 +3070,7 @@ namespace bgfx { namespace d3d11 sd.MinLOD = 0; sd.MaxLOD = D3D11_FLOAT32_MAX; - m_device->CreateSamplerState(&sd, &sampler); + DX_CHECK(m_device->CreateSamplerState(&sd, &sampler)); DX_CHECK_REFCOUNT(sampler, 1); m_samplerStateCache.add(hash, sampler); @@ -2939,19 +3085,69 @@ namespace bgfx { namespace d3d11 return _visible == (0 != _render->m_occlusion[_handle.idx]); } + void quietValidation() + { + const uint32_t maxTextureSamplers = g_caps.limits.maxTextureSamplers; + + ID3D11DeviceContext* deviceCtx = m_deviceCtx; + + // vertex texture fetch not supported on 9_1 through 9_3 + if (m_featureLevel > D3D_FEATURE_LEVEL_9_3) + { + deviceCtx->VSSetShaderResources(0, maxTextureSamplers, s_zero.m_srv); + deviceCtx->VSSetSamplers(0, maxTextureSamplers, s_zero.m_sampler); + } + + if (m_featureLevel > D3D_FEATURE_LEVEL_11_0) + { + deviceCtx->OMSetRenderTargetsAndUnorderedAccessViews( + D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL + , NULL + , NULL + , 16 + , maxTextureSamplers + , s_zero.m_uav + , NULL + ); + } + + deviceCtx->PSSetShaderResources(0, maxTextureSamplers, s_zero.m_srv); + deviceCtx->PSSetSamplers(0, maxTextureSamplers, s_zero.m_sampler); + } + void commitTextureStage() { + if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) + { + quietValidation(); + } + const uint32_t maxTextureSamplers = g_caps.limits.maxTextureSamplers; + ID3D11DeviceContext* deviceCtx = m_deviceCtx; + // vertex texture fetch not supported on 9_1 through 9_3 if (m_featureLevel > D3D_FEATURE_LEVEL_9_3) { - m_deviceCtx->VSSetShaderResources(0, maxTextureSamplers, m_textureStage.m_srv); - m_deviceCtx->VSSetSamplers(0, maxTextureSamplers, m_textureStage.m_sampler); + deviceCtx->VSSetShaderResources(0, maxTextureSamplers, m_textureStage.m_srv); + deviceCtx->VSSetSamplers(0, maxTextureSamplers, m_textureStage.m_sampler); } - m_deviceCtx->PSSetShaderResources(0, maxTextureSamplers, m_textureStage.m_srv); - m_deviceCtx->PSSetSamplers(0, maxTextureSamplers, m_textureStage.m_sampler); + if (m_featureLevel > D3D_FEATURE_LEVEL_11_0) + { + deviceCtx->OMSetRenderTargetsAndUnorderedAccessViews( + D3D11_KEEP_RENDER_TARGETS_AND_DEPTH_STENCIL + , NULL + , NULL + , 16 + , maxTextureSamplers + , m_textureStage.m_uav + , NULL + ); + } + + deviceCtx->PSSetShaderResources(0, maxTextureSamplers, m_textureStage.m_srv); + deviceCtx->PSSetSamplers(0, maxTextureSamplers, m_textureStage.m_sampler); } void invalidateTextureStage() @@ -3036,16 +3232,16 @@ namespace bgfx { namespace d3d11 switch (texture.m_type) { case TextureD3D11::Texture2D: - if (1 < texture.m_depth) + if (1 < texture.m_numLayers) { desc.ViewDimension = msaaSample ? D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY : D3D11_SRV_DIMENSION_TEXTURE2DARRAY ; desc.Texture2DArray.MostDetailedMip = _mip; - desc.Texture2DArray.MipLevels = 1; + desc.Texture2DArray.MipLevels = 1; desc.Texture2DArray.FirstArraySlice = 0; - desc.Texture2DArray.ArraySize = texture.m_depth; + desc.Texture2DArray.ArraySize = texture.m_numLayers; } else { @@ -3054,27 +3250,15 @@ namespace bgfx { namespace d3d11 : D3D11_SRV_DIMENSION_TEXTURE2D ; desc.Texture2D.MostDetailedMip = _mip; - desc.Texture2D.MipLevels = 1; + desc.Texture2D.MipLevels = 1; } break; case TextureD3D11::TextureCube: - if (_compute) - { - desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - desc.Texture2DArray.MostDetailedMip = _mip; - desc.Texture2DArray.MipLevels = 1; - desc.Texture2DArray.FirstArraySlice = 0; - desc.Texture2DArray.ArraySize = 6; - } - else - { - desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - desc.TextureCube.MostDetailedMip = _mip; - desc.TextureCube.MipLevels = 1; - } + desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; + desc.TextureCube.MostDetailedMip = _mip; + desc.TextureCube.MipLevels = 1; break; - case TextureD3D11::Texture3D: desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; desc.Texture3D.MostDetailedMip = _mip; @@ -3208,22 +3392,14 @@ namespace bgfx { namespace d3d11 data = (const char*)m_uniforms[handle.idx]; } -#define CASE_IMPLEMENT_UNIFORM(_uniform, _dxsuffix, _type) \ - case UniformType::_uniform: \ - case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \ - { \ - setShaderUniform(uint8_t(type), loc, data, num); \ - } \ - break; - switch ( (uint32_t)type) { case UniformType::Mat3: - case UniformType::Mat3|BGFX_UNIFORM_FRAGMENTBIT: \ - { + case UniformType::Mat3|kUniformFragmentBit: + { float* value = (float*)data; for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3*16, value += 9) - { + { Matrix4 mtx; mtx.un.val[ 0] = value[0]; mtx.un.val[ 1] = value[1]; @@ -3242,9 +3418,16 @@ namespace bgfx { namespace d3d11 } break; - CASE_IMPLEMENT_UNIFORM(Int1, I, int); - CASE_IMPLEMENT_UNIFORM(Vec4, F, float); - CASE_IMPLEMENT_UNIFORM(Mat4, F, float); + case UniformType::Sampler: + case UniformType::Sampler | kUniformFragmentBit: + case UniformType::Vec4: + case UniformType::Vec4 | kUniformFragmentBit: + case UniformType::Mat4: + case UniformType::Mat4 | kUniformFragmentBit: + { + setShaderUniform(uint8_t(type), loc, data, num); + } + break; case UniformType::End: break; @@ -3253,7 +3436,6 @@ namespace bgfx { namespace d3d11 BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy); break; } -#undef CASE_IMPLEMENT_UNIFORM } } @@ -3314,24 +3496,27 @@ namespace bgfx { namespace d3d11 ProgramD3D11& program = m_program[_clearQuad.m_program[numMrt-1].idx]; m_currentProgram = &program; - deviceCtx->VSSetShader(program.m_vsh->m_vertexShader, NULL, 0); - deviceCtx->VSSetConstantBuffers(0, 1, s_zero.m_buffer); + + const ShaderD3D11* vsh = program.m_vsh; + deviceCtx->VSSetShader(vsh->m_vertexShader, NULL, 0); + deviceCtx->VSSetConstantBuffers(0, 1, &vsh->m_buffer); + float mrtClearDepth[4] = { _clear.m_depth }; + deviceCtx->UpdateSubresource(vsh->m_buffer, 0, 0, mrtClearDepth, 0, 0); + if (NULL != m_currentColor) { const ShaderD3D11* fsh = program.m_fsh; deviceCtx->PSSetShader(fsh->m_pixelShader, NULL, 0); deviceCtx->PSSetConstantBuffers(0, 1, &fsh->m_buffer); + float mrtClearColor[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { - float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - bx::memCopy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClearColor[ii], _palette[index], 16); } - - deviceCtx->UpdateSubresource(fsh->m_buffer, 0, 0, mrtClear, 0, 0); } else { @@ -3343,52 +3528,27 @@ namespace bgfx { namespace d3d11 _clear.m_index[3]*1.0f/255.0f, }; - deviceCtx->UpdateSubresource(fsh->m_buffer, 0, 0, rgba, 0, 0); + for (uint32_t ii = 0; ii < numMrt; ++ii) + { + bx::memCopy(mrtClearColor[ii], rgba, 16); + } } + + deviceCtx->UpdateSubresource(fsh->m_buffer, 0, 0, mrtClearColor, 0, 0); } else { deviceCtx->PSSetShader(NULL, NULL, 0); } - VertexBufferD3D11& vb = m_vertexBuffers[_clearQuad.m_vb->handle.idx]; - const VertexDecl& vertexDecl = m_vertexDecls[_clearQuad.m_vb->decl.idx]; - const uint32_t stride = vertexDecl.m_stride; - const uint32_t offset = 0; - - { - struct Vertex - { - float m_x; - float m_y; - float m_z; - }; + VertexBufferD3D11& vb = m_vertexBuffers[_clearQuad.m_vb.idx]; + const VertexLayout& layout = _clearQuad.m_layout; - Vertex* vertex = (Vertex*)_clearQuad.m_vb->data; - BX_CHECK(stride == sizeof(Vertex), "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)", stride, sizeof(Vertex) ); - - const float depth = _clear.m_depth; - - vertex->m_x = -1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = -1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - } + const uint32_t stride = layout.m_stride; + const uint32_t offset = 0; - m_vertexBuffers[_clearQuad.m_vb->handle.idx].update(0, 4*_clearQuad.m_decl.m_stride, _clearQuad.m_vb->data); deviceCtx->IASetVertexBuffers(0, 1, &vb.m_ptr, &stride, &offset); - setInputLayout(vertexDecl, program, 0); + setInputLayout(layout, program, 0); deviceCtx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); deviceCtx->Draw(4, 0); @@ -3446,7 +3606,7 @@ namespace bgfx { namespace d3d11 ShaderD3D11 m_shaders[BGFX_CONFIG_MAX_SHADERS]; ProgramD3D11 m_program[BGFX_CONFIG_MAX_PROGRAMS]; TextureD3D11 m_textures[BGFX_CONFIG_MAX_TEXTURES]; - VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS]; + VertexLayout m_vertexLayouts[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; FrameBufferD3D11 m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; Matrix4 m_predefinedUniforms[PredefinedUniform::Count]; @@ -3562,15 +3722,15 @@ namespace bgfx { namespace d3d11 static const UavFormat s_uavFormat[] = { // BGFX_BUFFER_COMPUTE_TYPE_INT, BGFX_BUFFER_COMPUTE_TYPE_UINT, BGFX_BUFFER_COMPUTE_TYPE_FLOAT { { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, 0 }, // ignored - { { DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN }, 1 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x1 - { { DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x2 - { { DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x4 - { { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_FLOAT }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x1 - { { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x2 - { { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x4 - { { DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x1 - { { DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x2 - { { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_FLOAT }, 16 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x4 + { { DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN }, 1 }, // BGFX_BUFFER_COMPUTE_FORMAT_8X1 + { { DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_8X2 + { { DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_8X4 + { { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_FLOAT }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_16X1 + { { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_16X2 + { { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_16X4 + { { DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_32X1 + { { DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_32X2 + { { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_FLOAT }, 16 }, // BGFX_BUFFER_COMPUTE_FORMAT_32X4 }; void BufferD3D11::create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride, bool _vertex) @@ -3722,7 +3882,7 @@ namespace bgfx { namespace d3d11 void BufferD3D11::update(uint32_t _offset, uint32_t _size, void* _data, bool _discard) { ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx; - BX_CHECK(m_dynamic, "Must be dynamic!"); + BX_ASSERT(m_dynamic, "Must be dynamic!"); #if USE_D3D11_STAGING_BUFFER BX_UNUSED(_discard); @@ -3800,11 +3960,11 @@ namespace bgfx { namespace d3d11 #endif // 0 } - void VertexBufferD3D11::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags) + void VertexBufferD3D11::create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags) { - m_decl = _declHandle; - uint16_t stride = isValid(_declHandle) - ? s_renderD3D11->m_vertexDecls[_declHandle.idx].m_stride + m_layoutHandle = _layoutHandle; + uint16_t stride = isValid(_layoutHandle) + ? s_renderD3D11->m_vertexLayouts[_layoutHandle.idx].m_stride : 0 ; @@ -3848,17 +4008,101 @@ namespace bgfx { namespace d3d11 return find.m_found; } + static void patchUAVRegisterByteCode(DxbcInstruction& _instruction, void* _userData) + { + BX_UNUSED(_userData); + + switch (_instruction.opcode) + { + case DxbcOpcode::DCL_UNORDERED_ACCESS_VIEW_TYPED: + { + DxbcOperand& operand = _instruction.operand[0]; + operand.regIndex[0] += 16; + + BX_ASSERT(operand.regIndex[1] == 0 && operand.regIndex[2] == 0, "Unexpected values"); + } + break; + + case DxbcOpcode::DCL_UNORDERED_ACCESS_VIEW_RAW: + BX_ASSERT(false, "Unsupported UAV access"); + break; + + case DxbcOpcode::DCL_UNORDERED_ACCESS_VIEW_STRUCTURED: + BX_ASSERT(false, "Unsupported UAV access"); + break; + + case DxbcOpcode::LD_UAV_TYPED: + { + DxbcOperand& operand = _instruction.operand[2]; + operand.regIndex[0] += 16; + + BX_ASSERT(operand.regIndex[1] == 0 && operand.regIndex[2] == 0, "Unexpected values"); + } + break; + + case DxbcOpcode::STORE_UAV_TYPED: + { + DxbcOperand& operand = _instruction.operand[0]; + operand.regIndex[0] += 16; + + BX_ASSERT(operand.regIndex[1] == 0 && operand.regIndex[2] == 0, "Unexpected values"); + } + break; + + default: + break; + } + } + + static void patchUAVRegisterDebugInfo(DxbcSPDB& _spdb) + { + if (!_spdb.debugCode.empty()) + { + // 'register( u[xx] )' + char* ptr = (char*)_spdb.debugCode.data(); + while (ptr < (char*)_spdb.debugCode.data() + _spdb.debugCode.size() - 3) + { + if (*(ptr+1) == ' ' + && *(ptr+2) == 'u' + && *(ptr+3) == '[') + { + char* startPtr = ptr+4; + char* endPtr = ptr+4; + + while (*endPtr != ']') + { + endPtr++; + } + + uint32_t regNum = 0; + uint32_t regLen = uint32_t(endPtr - startPtr); + bx::fromString(®Num, bx::StringView(startPtr, regLen)); + + regNum += 16; + uint32_t len = bx::toString(startPtr, regLen+2, regNum); + *(startPtr + len) = ']'; + + break; + } + + ++ptr; + } + } + } + void ShaderD3D11::create(const Memory* _mem) { bx::MemoryReader reader(_mem->data, _mem->size); + bx::ErrorAssert err; + uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, &err); const bool fragment = isShaderType(magic, 'F'); uint32_t hashIn; - bx::read(&reader, hashIn); + bx::read(&reader, hashIn, &err); uint32_t hashOut; @@ -3868,11 +4112,11 @@ namespace bgfx { namespace d3d11 } else { - bx::read(&reader, hashOut); + bx::read(&reader, hashOut, &err); } uint16_t count; - bx::read(&reader, count); + bx::read(&reader, count, &err); m_numPredefined = 0; m_numUniforms = count; @@ -3882,30 +4126,42 @@ namespace bgfx { namespace d3d11 , count ); - const uint8_t fragmentBit = fragment ? BGFX_UNIFORM_FRAGMENTBIT : 0; + const uint8_t fragmentBit = fragment ? kUniformFragmentBit : 0; if (0 < count) { for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize = 0; - bx::read(&reader, nameSize); + bx::read(&reader, nameSize, &err); char name[256] = { '\0' }; - bx::read(&reader, &name, nameSize); + bx::read(&reader, &name, nameSize, &err); name[nameSize] = '\0'; uint8_t type = 0; - bx::read(&reader, type); + bx::read(&reader, type, &err); uint8_t num = 0; - bx::read(&reader, num); + bx::read(&reader, num, &err); uint16_t regIndex = 0; - bx::read(&reader, regIndex); + bx::read(&reader, regIndex, &err); uint16_t regCount = 0; - bx::read(&reader, regCount); + bx::read(&reader, regCount, &err); + + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo = 0; + bx::read(&reader, texInfo, &err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(&reader, texFormat, &err); + } const char* kind = "invalid"; @@ -3918,7 +4174,7 @@ namespace bgfx { namespace d3d11 m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); m_numPredefined++; } - else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) ) + else if (0 == (kUniformSamplerBit & type) ) { const UniformRegInfo* info = s_renderD3D11->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); @@ -3942,7 +4198,7 @@ namespace bgfx { namespace d3d11 BX_TRACE("\t%s: %s (%s), num %2d, r.index %3d, r.count %2d" , kind , name - , getUniformTypeName(UniformType::Enum(type&~BGFX_UNIFORM_MASK) ) + , getUniformTypeName(UniformType::Enum(type&~kUniformMask) ) , num , regIndex , regCount @@ -3957,11 +4213,37 @@ namespace bgfx { namespace d3d11 } uint32_t shaderSize; - bx::read(&reader, shaderSize); + bx::read(&reader, shaderSize, &err); const void* code = reader.getDataPtr(); bx::skip(&reader, shaderSize+1); + const Memory* temp = NULL; + + if (!isShaderType(magic, 'C')) + { + bx::MemoryReader rd(code, shaderSize); + + DxbcContext dxbc; + read(&rd, dxbc, bx::ErrorAssert{}); + + bool patchShader = !dxbc.shader.aon9; + if (patchShader) + { + union { uint32_t offset; void* ptr; } cast = { 0 }; + filter(dxbc.shader, dxbc.shader, patchUAVRegisterByteCode, cast.ptr); + patchUAVRegisterDebugInfo(dxbc.spdb); + + temp = alloc(shaderSize); + bx::StaticMemoryBlockWriter wr(temp->data, temp->size); + + int32_t size = write(&wr, dxbc, &err); + dxbcHash(temp->data + 20, size - 20, temp->data + 4); + + code = temp->data; + } + } + if (isShaderType(magic, 'F') ) { m_hasDepthOp = hasDepthOp(code, shaderSize); @@ -3983,14 +4265,14 @@ namespace bgfx { namespace d3d11 } uint8_t numAttrs = 0; - bx::read(&reader, numAttrs); + bx::read(&reader, numAttrs, bx::ErrorAssert{}); bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); for (uint32_t ii = 0; ii < numAttrs; ++ii) { uint16_t id; - bx::read(&reader, id); + bx::read(&reader, id, bx::ErrorAssert{}); Attrib::Enum attr = idToAttrib(id); @@ -4001,7 +4283,7 @@ namespace bgfx { namespace d3d11 } uint16_t size; - bx::read(&reader, size); + bx::read(&reader, size, bx::ErrorAssert{}); if (0 < size) { @@ -4016,6 +4298,11 @@ namespace bgfx { namespace d3d11 BX_TRACE("\tCB size: %d", desc.ByteWidth); } + + if (NULL != temp) + { + release(temp); + } } void* DirectAccessResourceD3D11::createTexture2D(const D3D11_TEXTURE2D_DESC* _gpuDesc, const D3D11_SUBRESOURCE_DATA* _srd, ID3D11Texture2D** _gpuTexture2d) @@ -4086,21 +4373,28 @@ namespace bgfx { namespace d3d11 if (bimg::imageParse(imageContainer, _mem->data, _mem->size) ) { - uint8_t numMips = imageContainer.m_numMips; - const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); - numMips -= startLod; const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::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); - const uint16_t numLayers = imageContainer.m_numLayers; - - m_flags = _flags; - m_width = textureWidth; - m_height = textureHeight; - m_depth = 1 < imageContainer.m_depth - ? imageContainer.m_depth - : imageContainer.m_numLayers - ; + const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips-1); + + bimg::TextureInfo ti; + bimg::imageGetSize( + &ti + , uint16_t(imageContainer.m_width >>startLod) + , uint16_t(imageContainer.m_height>>startLod) + , uint16_t(imageContainer.m_depth >>startLod) + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + , imageContainer.m_numLayers + , imageContainer.m_format + ); + ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips-startLod, ti.numMips); + + m_flags = _flags; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numLayers = ti.numLayers; + m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -4119,10 +4413,10 @@ namespace bgfx { namespace d3d11 m_type = Texture2D; } - m_numMips = numMips; + m_numMips = ti.numMips; - const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); - const uint32_t numSrd = numSides * numMips; + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * ti.numMips; D3D11_SUBRESOURCE_DATA* srd = (D3D11_SUBRESOURCE_DATA*)alloca(numSrd*sizeof(D3D11_SUBRESOURCE_DATA) ); uint32_t kk = 0; @@ -4134,17 +4428,18 @@ namespace bgfx { namespace d3d11 , getHandle() , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) - , numLayers - , textureWidth - , textureHeight + , ti.numLayers + , ti.width + , ti.height , imageContainer.m_cubeMap ? "x6" : "" , 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" , swizzle ? " (swizzle BGRA8 -> RGBA8)" : "" ); + uint8_t* temp = NULL; for (uint16_t side = 0; side < numSides; ++side) { - for (uint8_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod) { bimg::ImageMip mip; if (bimg::imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) ) @@ -4154,7 +4449,7 @@ namespace bgfx { namespace d3d11 if (convert) { uint32_t srcpitch = mip.m_width*bpp/8; - uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, mip.m_width*mip.m_height*bpp/8); + temp = (uint8_t*)BX_ALLOC(g_allocator, srcpitch*mip.m_height); bimg::imageDecodeToBgra8(g_allocator, temp, mip.m_data, mip.m_width, mip.m_height, srcpitch, mip.m_format); srd[kk].pSysMem = temp; @@ -4168,6 +4463,25 @@ namespace bgfx { namespace d3d11 else { srd[kk].SysMemPitch = mip.m_width*mip.m_bpp/8; + + switch (m_textureFormat) + { + case TextureFormat::R5G6B5: + temp = (uint8_t*)BX_ALLOC(g_allocator, srd[kk].SysMemPitch*mip.m_height); + bimg::imageConvert(temp, 16, bx::packB5G6R5, mip.m_data, bx::unpackR5G6B5, srd[kk].SysMemPitch*mip.m_height); + srd[kk].pSysMem = temp; + break; + case TextureFormat::RGBA4: + temp = (uint8_t*)BX_ALLOC(g_allocator, srd[kk].SysMemPitch*mip.m_height); + bimg::imageConvert(temp, 16, bx::packBgra4, mip.m_data, bx::unpackRgba4, srd[kk].SysMemPitch*mip.m_height); + srd[kk].pSysMem = temp; + break; + case TextureFormat::RGB5A1: + temp = (uint8_t*)BX_ALLOC(g_allocator, srd[kk].SysMemPitch*mip.m_height); + bimg::imageConvert(temp, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, srd[kk].SysMemPitch*mip.m_height); + srd[kk].pSysMem = temp; + break; + } } srd[kk].SysMemSlicePitch = mip.m_height*srd[kk].SysMemPitch; @@ -4231,9 +4545,9 @@ namespace bgfx { namespace d3d11 case TextureCube: { D3D11_TEXTURE2D_DESC desc = {}; - desc.Width = textureWidth; - desc.Height = textureHeight; - desc.MipLevels = numMips; + desc.Width = ti.width; + desc.Height = ti.height; + desc.MipLevels = ti.numMips; desc.ArraySize = numSides; desc.Format = format; desc.SampleDesc = msaa; @@ -4252,7 +4566,7 @@ namespace bgfx { namespace d3d11 desc.BindFlags |= D3D11_BIND_RENDER_TARGET; desc.Usage = D3D11_USAGE_DEFAULT; desc.MiscFlags |= 0 - | (1 < numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) + | (1 < ti.numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) ; } @@ -4272,26 +4586,26 @@ namespace bgfx { namespace d3d11 if (imageContainer.m_cubeMap) { desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE; - if (1 < numLayers) + if (1 < ti.numLayers) { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBEARRAY; - srvd.TextureCubeArray.MipLevels = numMips; - srvd.TextureCubeArray.NumCubes = numLayers; + srvd.TextureCubeArray.MipLevels = ti.numMips; + srvd.TextureCubeArray.NumCubes = ti.numLayers; } else { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE; - srvd.TextureCube.MipLevels = numMips; + srvd.TextureCube.MipLevels = ti.numMips; } } else { if (msaaSample) { - if (1 < numLayers) + if (1 < ti.numLayers) { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY; - srvd.Texture2DMSArray.ArraySize = numLayers; + srvd.Texture2DMSArray.ArraySize = ti.numLayers; } else { @@ -4300,16 +4614,16 @@ namespace bgfx { namespace d3d11 } else { - if (1 < numLayers) + if (1 < ti.numLayers) { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY; - srvd.Texture2DArray.MipLevels = numMips; - srvd.Texture2DArray.ArraySize = numLayers; + srvd.Texture2DArray.MipLevels = ti.numMips; + srvd.Texture2DArray.ArraySize = ti.numLayers; } else { srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srvd.Texture2D.MipLevels = numMips; + srvd.Texture2D.MipLevels = ti.numMips; } } } @@ -4335,10 +4649,10 @@ namespace bgfx { namespace d3d11 case Texture3D: { D3D11_TEXTURE3D_DESC desc = {}; - desc.Width = textureWidth; - desc.Height = textureHeight; - desc.Depth = imageContainer.m_depth; - desc.MipLevels = imageContainer.m_numMips; + desc.Width = ti.width; + desc.Height = ti.height; + desc.Depth = ti.depth; + desc.MipLevels = ti.numMips; desc.Format = format; desc.Usage = kk == 0 || blit ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE; desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; @@ -4350,7 +4664,7 @@ namespace bgfx { namespace d3d11 desc.BindFlags |= D3D11_BIND_RENDER_TARGET; desc.Usage = D3D11_USAGE_DEFAULT; desc.MiscFlags |= 0 - | (1 < numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) + | (1 < ti.numMips ? D3D11_RESOURCE_MISC_GENERATE_MIPS : 0) ; } @@ -4368,7 +4682,7 @@ namespace bgfx { namespace d3d11 } srvd.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D; - srvd.Texture3D.MipLevels = numMips; + srvd.Texture3D.MipLevels = ti.numMips; if (directAccess) { @@ -4392,13 +4706,12 @@ namespace bgfx { namespace d3d11 DX_CHECK(s_renderD3D11->m_device->CreateUnorderedAccessView(m_ptr, NULL, &m_uav) ); } - if (convert - && 0 != kk) + if (temp != NULL) { kk = 0; for (uint16_t side = 0; side < numSides; ++side) { - for (uint32_t lod = 0, num = numMips; lod < num; ++lod) + for (uint32_t lod = 0, num = ti.numMips; lod < num; ++lod) { BX_FREE(g_allocator, const_cast<void*>(srd[kk].pSysMem) ); ++kk; @@ -4426,11 +4739,22 @@ namespace bgfx { namespace d3d11 void TextureD3D11::overrideInternal(uintptr_t _ptr) { + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc{}; + + const bool readable = (m_srv != NULL); + if (readable) + { + m_srv->GetDesc(&srvDesc); + } + destroy(); m_flags |= BGFX_SAMPLER_INTERNAL_SHARED; m_ptr = (ID3D11Resource*)_ptr; - s_renderD3D11->m_device->CreateShaderResourceView(m_ptr, NULL, &m_srv); + if (readable) + { + s_renderD3D11->m_device->CreateShaderResourceView(m_ptr, &srvDesc, &m_srv); + } } void TextureD3D11::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) @@ -4457,10 +4781,16 @@ namespace bgfx { namespace d3d11 box.back = 1; } + const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) ); + const uint16_t bpp = blockInfo.bitsPerPixel; const uint32_t subres = _mip + ( (layer + _side) * m_numMips); const bool depth = bimg::isDepth(bimg::TextureFormat::Enum(m_textureFormat) ); - const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); - const uint32_t rectpitch = _rect.m_width*bpp/8; + uint32_t rectpitch = _rect.m_width*bpp/8; + if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat) ) ) + { + rectpitch = (_rect.m_width / blockInfo.blockWidth)*blockInfo.blockSize; + } + const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; const uint32_t slicepitch = rectpitch*_rect.m_height; @@ -4474,6 +4804,9 @@ namespace bgfx { namespace d3d11 temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch); bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat) ); data = temp; + + box.right = bx::max(1u, m_width >> _mip); + box.bottom = bx::max(1u, m_height >> _mip); } deviceCtx->UpdateSubresource( @@ -4517,14 +4850,18 @@ namespace bgfx { namespace d3d11 ts.m_sampler[_stage] = s_renderD3D11->getSamplerState(flags, _palette[index]); } - void TextureD3D11::resolve(uint8_t _resolve) const + void TextureD3D11::resolve(uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip) const { ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx; const bool needResolve = NULL != m_rt; if (needResolve) { - deviceCtx->ResolveSubresource(m_texture2d, 0, m_rt, 0, s_textureFormat[m_textureFormat].m_fmt); + for (uint32_t ii = _layer; ii < _numLayers; ++ii) + { + const UINT resource = _mip + (ii * m_numMips); + deviceCtx->ResolveSubresource(m_texture2d, resource, m_rt, resource, s_textureFormat[m_textureFormat].m_fmt); + } } const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK); @@ -4561,6 +4898,12 @@ namespace bgfx { namespace d3d11 { m_rtv[ii] = NULL; } + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_uav); ++ii) + { + m_uav[ii] = NULL; + } + m_dsv = NULL; m_swapChain = NULL; @@ -4576,11 +4919,12 @@ namespace bgfx { namespace d3d11 { SwapChainDesc scd; bx::memCopy(&scd, &s_renderD3D11->m_scd, sizeof(SwapChainDesc) ); - scd.format = TextureFormat::Count == _format ? scd.format : s_textureFormat[_format].m_fmt; - scd.width = _width; - scd.height = _height; - scd.nwh = _nwh; - scd.ndt = NULL; + scd.format = TextureFormat::Count == _format ? scd.format : s_textureFormat[_format].m_fmt; + scd.width = _width; + scd.height = _height; + scd.nwh = _nwh; + scd.ndt = NULL; + scd.sampleDesc = s_msaa[0]; ID3D11Device* device = s_renderD3D11->m_device; @@ -4670,7 +5014,9 @@ namespace bgfx { namespace d3d11 if (0 < m_numTh) { - m_num = 0; + m_num = 0; + m_numUav = 0; + for (uint32_t ii = 0; ii < m_numTh; ++ii) { const Attachment& at = m_attachment[ii]; @@ -4709,21 +5055,45 @@ namespace bgfx { namespace d3d11 if (bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) ) { - BX_CHECK(NULL == m_dsv, "Frame buffer already has depth-stencil attached."); + BX_ASSERT(NULL == m_dsv, "Frame buffer already has depth-stencil attached."); + + D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; + dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv; + dsvDesc.Flags = 0; switch (texture.m_type) { default: case TextureD3D11::Texture2D: { - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv; - dsvDesc.ViewDimension = 1 < msaa.Count - ? D3D11_DSV_DIMENSION_TEXTURE2DMS - : D3D11_DSV_DIMENSION_TEXTURE2D - ; - dsvDesc.Flags = 0; - dsvDesc.Texture2D.MipSlice = at.mip; + if (1 < msaa.Count) + { + if (1 < texture.m_numLayers) + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; + dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; + } + else + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; + } + } + else + { + if (1 < texture.m_numLayers) + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; + dsvDesc.Texture2DArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; + dsvDesc.Texture2DArray.MipSlice = at.mip; + } + else + { + dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; + dsvDesc.Texture2D.MipSlice = at.mip; + } + } DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView( NULL == texture.m_rt ? texture.m_ptr : texture.m_rt , &dsvDesc @@ -4734,22 +5104,19 @@ namespace bgfx { namespace d3d11 case TextureD3D11::TextureCube: { - D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; - dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv; if (1 < msaa.Count) { dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY; - dsvDesc.Texture2DMSArray.ArraySize = 1; dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; } else { dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY; - dsvDesc.Texture2DArray.ArraySize = 1; dsvDesc.Texture2DArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; dsvDesc.Texture2DArray.MipSlice = at.mip; } - dsvDesc.Flags = 0; DX_CHECK(s_renderD3D11->m_device->CreateDepthStencilView(texture.m_ptr, &dsvDesc, &m_dsv) ); } break; @@ -4765,11 +5132,11 @@ namespace bgfx { namespace d3d11 case TextureD3D11::Texture2D: if (1 < msaa.Count) { - if (1 < texture.m_depth) + if (1 < texture.m_numLayers) { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY; desc.Texture2DMSArray.FirstArraySlice = at.layer; - desc.Texture2DMSArray.ArraySize = 1; + desc.Texture2DMSArray.ArraySize = at.numLayers; } else { @@ -4778,12 +5145,12 @@ namespace bgfx { namespace d3d11 } else { - if (1 < texture.m_depth) + if (1 < texture.m_numLayers) { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; desc.Texture2DArray.FirstArraySlice = at.layer; - desc.Texture2DArray.ArraySize = 1; - desc.Texture2DArray.MipSlice = at.mip; + desc.Texture2DArray.ArraySize = at.numLayers; + desc.Texture2DArray.MipSlice = at.mip; } else { @@ -4803,34 +5170,38 @@ namespace bgfx { namespace d3d11 if (1 < msaa.Count) { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY; - desc.Texture2DMSArray.ArraySize = 1; desc.Texture2DMSArray.FirstArraySlice = at.layer; + desc.Texture2DMSArray.ArraySize = at.numLayers; } else { desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY; - desc.Texture2DArray.ArraySize = 1; desc.Texture2DArray.FirstArraySlice = at.layer; + desc.Texture2DArray.ArraySize = at.numLayers; desc.Texture2DArray.MipSlice = at.mip; } + DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) ); break; case TextureD3D11::Texture3D: desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D; desc.Texture3D.MipSlice = at.mip; - desc.Texture3D.WSize = 1; desc.Texture3D.FirstWSlice = at.layer; + desc.Texture3D.WSize = at.numLayers; + DX_CHECK(s_renderD3D11->m_device->CreateRenderTargetView(texture.m_ptr, &desc, &m_rtv[m_num]) ); break; } - DX_CHECK(s_renderD3D11->m_device->CreateShaderResourceView(texture.m_ptr, NULL, &m_srv[m_num]) ); + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc{}; + texture.m_srv->GetDesc(&srvDesc); + DX_CHECK(s_renderD3D11->m_device->CreateShaderResourceView(texture.m_ptr, &srvDesc, &m_srv[m_num])); m_num++; } else { - BX_CHECK(false, ""); + m_uav[m_numUav++] = texture.m_uav; } } } @@ -4848,7 +5219,7 @@ namespace bgfx { namespace d3d11 if (isValid(at.handle) ) { const TextureD3D11& texture = s_renderD3D11->m_textures[at.handle.idx]; - texture.resolve(at.resolve); + texture.resolve(at.resolve, at.layer, at.numLayers, at.mip); } } } @@ -4961,7 +5332,7 @@ namespace bgfx { namespace d3d11 } } - uint32_t TimerQueryD3D11::begin(uint32_t _resultIdx) + uint32_t TimerQueryD3D11::begin(uint32_t _resultIdx, uint32_t _frameNum) { ID3D11DeviceContext* deviceCtx = s_renderD3D11->m_deviceCtx; @@ -4977,6 +5348,7 @@ namespace bgfx { namespace d3d11 Query& query = m_query[idx]; query.m_resultIdx = _resultIdx; query.m_ready = false; + query.m_frameNum = _frameNum; deviceCtx->Begin(query.m_disjoint); deviceCtx->End(query.m_begin); @@ -5033,6 +5405,7 @@ namespace bgfx { namespace d3d11 Result& result = m_result[query.m_resultIdx]; --result.m_pending; + result.m_frameNum = query.m_frameNum; result.m_frequency = disjoint.Frequency; result.m_begin = timeBegin; @@ -5138,25 +5511,15 @@ namespace bgfx { namespace d3d11 const TextureD3D11& src = m_textures[blit.m_src.idx]; const TextureD3D11& dst = m_textures[blit.m_dst.idx]; - uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX; - uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY; - uint32_t srcDepth = bx::uint32_min(src.m_depth, blit.m_srcZ + blit.m_depth) - blit.m_srcZ; - uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX; - uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY; - uint32_t dstDepth = bx::uint32_min(dst.m_depth, blit.m_dstZ + blit.m_depth) - blit.m_dstZ; - uint32_t width = bx::uint32_min(srcWidth, dstWidth); - uint32_t height = bx::uint32_min(srcHeight, dstHeight); - uint32_t depth = bx::uint32_min(srcDepth, dstDepth); - if (TextureD3D11::Texture3D == src.m_type) { D3D11_BOX box; box.left = blit.m_srcX; box.top = blit.m_srcY; box.front = blit.m_srcZ; - box.right = blit.m_srcX + width; - box.bottom = blit.m_srcY + height;; - box.back = blit.m_srcZ + bx::uint32_imax(1, depth); + box.right = blit.m_srcX + blit.m_width; + box.bottom = blit.m_srcY + blit.m_height; + box.back = blit.m_srcZ + bx::uint32_imax(1, blit.m_depth); deviceCtx->CopySubresourceRegion(dst.m_ptr , blit.m_dstMip @@ -5171,8 +5534,8 @@ namespace bgfx { namespace d3d11 else { bool depthStencil = bimg::isDepth(bimg::TextureFormat::Enum(src.m_textureFormat) ); - BX_CHECK(!depthStencil - || (width == src.m_width && height == src.m_height) + BX_ASSERT(!depthStencil + || (blit.m_width == bx::uint32_max(1, src.m_width >> blit.m_srcMip) && blit.m_height == bx::uint32_max(1, src.m_height >> blit.m_srcMip)) , "When blitting depthstencil surface, source resolution must match destination." ); @@ -5180,8 +5543,8 @@ namespace bgfx { namespace d3d11 box.left = blit.m_srcX; box.top = blit.m_srcY; box.front = 0; - box.right = blit.m_srcX + width; - box.bottom = blit.m_srcY + height; + box.right = blit.m_srcX + blit.m_width; + box.bottom = blit.m_srcY + blit.m_height; box.back = 1; const uint32_t srcZ = blit.m_srcZ; @@ -5202,8 +5565,13 @@ namespace bgfx { namespace d3d11 void RendererContextD3D11::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { - if (m_lost - || updateResolution(_render->m_resolution) ) + if (m_lost) + { + return; + } + + updateNativeWindow(); + if (updateResolution(_render->m_resolution) ) { return; } @@ -5213,7 +5581,7 @@ namespace bgfx { namespace d3d11 renderDocTriggerCapture(); } - PIX_BEGINEVENT(D3DCOLOR_FRAME, L"rendererSubmit"); + BGFX_D3D11_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorView); ID3D11DeviceContext* deviceCtx = m_deviceCtx; @@ -5224,17 +5592,19 @@ namespace bgfx { namespace d3d11 if (m_timerQuerySupport) { - frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS); + frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS, _render->m_frameNum); } if (0 < _render->m_iboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource); TransientIndexBuffer* ib = _render->m_transientIb; m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true); } if (0 < _render->m_vboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource); TransientVertexBuffer* vb = _render->m_transientVb; m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true); } @@ -5246,18 +5616,19 @@ namespace bgfx { namespace d3d11 currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); + uint32_t currentNumVertices = 0; + RenderBind currentBind; currentBind.clear(); - const bool hmdEnabled = false; static ViewState viewState; - viewState.reset(_render, hmdEnabled); + viewState.reset(_render); bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); bool scissorEnabled = false; setDebugWireframe(wireframe); - uint16_t programIdx = kInvalidHandle; + ProgramHandle currentProgram = BGFX_INVALID_HANDLE; SortKey key; uint16_t view = UINT16_MAX; FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS }; @@ -5299,13 +5670,10 @@ namespace bgfx { namespace d3d11 // if we don't do this we'll only see one frame of output and then nothing setFrameBuffer(BGFX_INVALID_HANDLE, true, false); - bool viewRestart = false; - uint8_t eye = 0; - uint8_t restartState = 0; viewState.m_rect = _render->m_view[0].m_rect; - int32_t numItems = _render->m_numRenderItems; - for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;) + + for (int32_t item = 0; item < numItems;) { const uint64_t encodedKey = _render->m_sortKeys[item]; const bool isCompute = key.decode(encodedKey, _render->m_viewRemap); @@ -5323,77 +5691,27 @@ namespace bgfx { namespace d3d11 if (viewChanged) { - if (1 == restartState) - { - restartState = 2; - item = restartItem; - restartItem = numItems; - view = UINT16_MAX; - continue; - } - view = key.m_view; - programIdx = kInvalidHandle; + currentProgram = BGFX_INVALID_HANDLE; - if (_render->m_view[view].m_fbh.idx != fbh.idx) + if (item > 1) { - fbh = _render->m_view[view].m_fbh; - setFrameBuffer(fbh); + profiler.end(); } - viewRestart = ( (BGFX_VIEW_STEREO == (_render->m_view[view].m_flags & BGFX_VIEW_STEREO) ) ); - viewRestart &= hmdEnabled; - if (viewRestart) - { - if (0 == restartState) - { - restartState = 1; - restartItem = item - 1; - } + BGFX_D3D11_PROFILER_END(); + setViewType(view, " "); + BGFX_D3D11_PROFILER_BEGIN(view, kColorView); - eye = (restartState - 1) & 1; - restartState &= 1; - } - else - { - eye = 0; - } + profiler.begin(view); - PIX_ENDEVENT(); - if (item > 1) + if (_render->m_view[view].m_fbh.idx != fbh.idx) { - profiler.end(); + fbh = _render->m_view[view].m_fbh; + setFrameBuffer(fbh); } - profiler.begin(view); viewState.m_rect = _render->m_view[view].m_rect; - if (viewRestart) - { - 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(0 == ( (view*2+eye)&1) - ? D3DCOLOR_VIEW_L - : D3DCOLOR_VIEW_R - , viewNameW - ); - } - - viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2; - viewState.m_rect.m_width /= 2; - } - else - { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - wchar_t* viewNameW = s_viewNameW[view]; - viewNameW[3] = L' '; - viewNameW[4] = L' '; - PIX_BEGINEVENT(D3DCOLOR_VIEW, viewNameW); - } - } const Rect& scissorRect = _render->m_view[view].m_scissor; viewHasScissor = !scissorRect.isZero(); @@ -5424,13 +5742,9 @@ 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_COMPUTE, viewNameW); - } + setViewType(view, "C"); + BGFX_D3D11_PROFILER_END(); + BGFX_D3D11_PROFILER_BEGIN(view, kColorCompute); deviceCtx->IASetVertexBuffers(0, 2, s_zero.m_buffer, s_zero.m_zero, s_zero.m_zero); deviceCtx->IASetIndexBuffer(NULL, DXGI_FORMAT_R16_UINT, 0); @@ -5444,21 +5758,15 @@ namespace bgfx { namespace d3d11 const RenderCompute& compute = renderItem.compute; - if (0 != eye - && BGFX_SUBMIT_EYE_LEFT == (compute.m_submitFlags&BGFX_SUBMIT_EYE_MASK) ) - { - continue; - } - bool programChanged = false; bool constantsChanged = compute.m_uniformBegin < compute.m_uniformEnd; rendererUpdateUniforms(this, _render->m_uniformBuffer[compute.m_uniformIdx], compute.m_uniformBegin, compute.m_uniformEnd); - if (key.m_program != programIdx) + if (key.m_program.idx != currentProgram.idx) { - programIdx = key.m_program; + currentProgram = key.m_program; - ProgramD3D11& program = m_program[key.m_program]; + ProgramD3D11& program = m_program[currentProgram.idx]; m_currentProgram = &program; deviceCtx->CSSetShader(program.m_vsh->m_computeShader, NULL, 0); @@ -5468,9 +5776,9 @@ namespace bgfx { namespace d3d11 constantsChanged = true; } - if (kInvalidHandle != programIdx) + if (isValid(currentProgram) ) { - ProgramD3D11& program = m_program[programIdx]; + ProgramD3D11& program = m_program[currentProgram.idx]; if (constantsChanged) { @@ -5481,7 +5789,7 @@ namespace bgfx { namespace d3d11 } } - viewState.setPredefined<4>(this, view, eye, program, _render, compute); + viewState.setPredefined<4>(this, view, program, _render, compute); if (constantsChanged || program.m_numPredefined > 0) @@ -5543,6 +5851,12 @@ namespace bgfx { namespace d3d11 break; } } + else + { + m_textureStage.m_srv[stage] = NULL; + m_textureStage.m_sampler[stage] = NULL; + m_textureStage.m_uav[stage] = NULL; + } } if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) @@ -5584,15 +5898,11 @@ 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_DRAW, viewNameW); - } + setViewType(view, " "); + BGFX_D3D11_PROFILER_END(); + BGFX_D3D11_PROFILER_BEGIN(view, kColorDraw); - programIdx = kInvalidHandle; + currentProgram = BGFX_INVALID_HANDLE; m_currentProgram = NULL; invalidateCompute(); @@ -5706,6 +6016,7 @@ namespace bgfx { namespace d3d11 if ( (0 | BGFX_STATE_CULL_MASK + | BGFX_STATE_FRONT_CCW | BGFX_STATE_ALPHA_REF_MASK | BGFX_STATE_PT_MASK | BGFX_STATE_POINT_SIZE_MASK @@ -5716,6 +6027,7 @@ namespace bgfx { namespace d3d11 { if ( (0 | BGFX_STATE_CULL_MASK + | BGFX_STATE_FRONT_CCW | BGFX_STATE_MSAA | BGFX_STATE_LINEAA | BGFX_STATE_CONSERVATIVE_RASTER @@ -5743,11 +6055,11 @@ namespace bgfx { namespace d3d11 bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd; rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); - if (key.m_program != programIdx) + if (key.m_program.idx != currentProgram.idx) { - programIdx = key.m_program; + currentProgram = key.m_program; - if (kInvalidHandle == programIdx) + if (!isValid(currentProgram) ) { m_currentProgram = NULL; @@ -5756,7 +6068,7 @@ namespace bgfx { namespace d3d11 } else { - ProgramD3D11& program = m_program[programIdx]; + ProgramD3D11& program = m_program[currentProgram.idx]; m_currentProgram = &program; const ShaderD3D11* vsh = program.m_vsh; @@ -5780,9 +6092,9 @@ namespace bgfx { namespace d3d11 constantsChanged = true; } - if (kInvalidHandle != programIdx) + if (isValid(currentProgram) ) { - ProgramD3D11& program = m_program[programIdx]; + ProgramD3D11& program = m_program[currentProgram.idx]; if (constantsChanged) { @@ -5802,7 +6114,7 @@ namespace bgfx { namespace d3d11 } } - viewState.setPredefined<4>(this, view, eye, program, _render, draw); + viewState.setPredefined<4>(this, view, program, _render, draw); if (constantsChanged || program.m_numPredefined > 0) @@ -5826,6 +6138,24 @@ namespace bgfx { namespace d3d11 { switch (bind.m_type) { + case Binding::Image: + { + TextureD3D11& texture = m_textures[bind.m_idx]; + if (Access::Read != bind.m_access) + { + m_textureStage.m_uav[stage] = 0 == bind.m_mip + ? texture.m_uav + : s_renderD3D11->getCachedUav(texture.getHandle(), bind.m_mip) + ; + } + else + { + m_textureStage.m_srv[stage] = s_renderD3D11->getCachedSrv(texture.getHandle(), bind.m_mip, true); + m_textureStage.m_sampler[stage] = s_renderD3D11->getSamplerState(uint32_t(texture.m_flags), NULL); + } + } + break; + case Binding::Texture: { TextureD3D11& texture = m_textures[bind.m_idx]; @@ -5842,6 +6172,7 @@ namespace bgfx { namespace d3d11 ; m_textureStage.m_srv[stage] = buffer.m_srv; m_textureStage.m_sampler[stage] = NULL; + m_textureStage.m_uav[stage] = NULL; } break; } @@ -5850,6 +6181,7 @@ namespace bgfx { namespace d3d11 { m_textureStage.m_srv[stage] = NULL; m_textureStage.m_sampler[stage] = NULL; + m_textureStage.m_uav[stage] = NULL; } ++changes; @@ -5877,35 +6209,38 @@ namespace bgfx { namespace d3d11 ID3D11Buffer* buffers[BGFX_CONFIG_MAX_VERTEX_STREAMS]; uint32_t strides[BGFX_CONFIG_MAX_VERTEX_STREAMS]; uint32_t offsets[BGFX_CONFIG_MAX_VERTEX_STREAMS]; - const VertexDecl* decls[BGFX_CONFIG_MAX_VERTEX_STREAMS]; + const VertexLayout* layouts[BGFX_CONFIG_MAX_VERTEX_STREAMS]; uint32_t numVertices = draw.m_numVertices; uint8_t numStreams = 0; if (UINT8_MAX != draw.m_streamMask) { - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask), ++numStreams + ; streamMask >>= 1, idx += 1, ++numStreams ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; - currentState.m_stream[idx].m_decl = draw.m_stream[idx].m_decl; - currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; - currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + currentState.m_stream[idx].m_layoutHandle = draw.m_stream[idx].m_layoutHandle; + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; const uint16_t handle = draw.m_stream[idx].m_handle.idx; const VertexBufferD3D11& vb = m_vertexBuffers[handle]; - const uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = m_vertexDecls[decl]; - const uint32_t stride = vertexDecl.m_stride; + const uint16_t layoutIdx = isValid(draw.m_stream[idx].m_layoutHandle) + ? draw.m_stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx; + const VertexLayout& layout = m_vertexLayouts[layoutIdx]; + const uint32_t stride = layout.m_stride; buffers[numStreams] = vb.m_ptr; strides[numStreams] = stride; offsets[numStreams] = draw.m_stream[idx].m_startVertex * stride; - decls[numStreams] = &vertexDecl; + layouts[numStreams] = &layout; numVertices = bx::uint32_min(UINT32_MAX == draw.m_numVertices ? vb.m_size/stride @@ -5915,7 +6250,7 @@ namespace bgfx { namespace d3d11 } } - currentState.m_numVertices = numVertices; + currentNumVertices = numVertices; if (0 < numStreams) { @@ -5926,12 +6261,12 @@ namespace bgfx { namespace d3d11 const VertexBufferD3D11& inst = m_vertexBuffers[draw.m_instanceDataBuffer.idx]; const uint32_t instStride = draw.m_instanceDataStride; deviceCtx->IASetVertexBuffers(numStreams, 1, &inst.m_ptr, &instStride, &draw.m_instanceDataOffset); - setInputLayout(numStreams, decls, m_program[programIdx], uint16_t(instStride/16) ); + setInputLayout(numStreams, layouts, m_program[currentProgram.idx], uint16_t(instStride/16) ); } else { deviceCtx->IASetVertexBuffers(numStreams, 1, s_zero.m_buffer, s_zero.m_zero, s_zero.m_zero); - setInputLayout(numStreams, decls, m_program[programIdx], 0); + setInputLayout(numStreams, layouts, m_program[currentProgram.idx], 0); } } else @@ -5943,7 +6278,7 @@ namespace bgfx { namespace d3d11 const VertexBufferD3D11& inst = m_vertexBuffers[draw.m_instanceDataBuffer.idx]; const uint32_t instStride = draw.m_instanceDataStride; deviceCtx->IASetVertexBuffers(0, 1, &inst.m_ptr, &instStride, &draw.m_instanceDataOffset); - setInputLayout(0, NULL, m_program[programIdx], uint16_t(instStride/16) ); + setInputLayout(0, NULL, m_program[currentProgram.idx], uint16_t(instStride/16) ); } else { @@ -5952,16 +6287,18 @@ namespace bgfx { namespace d3d11 } } - if (currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx) + if (currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx + || currentState.isIndex16() != draw.isIndex16() ) { currentState.m_indexBuffer = draw.m_indexBuffer; + currentState.m_submitFlags = draw.m_submitFlags; uint16_t handle = draw.m_indexBuffer.idx; if (kInvalidHandle != handle) { const IndexBufferD3D11& ib = m_indexBuffers[handle]; deviceCtx->IASetIndexBuffer(ib.m_ptr - , 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT + , draw.isIndex16() ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT , 0 ); } @@ -5973,7 +6310,7 @@ namespace bgfx { namespace d3d11 if (0 != currentState.m_streamMask) { - uint32_t numVertices = currentState.m_numVertices; + uint32_t numVertices = currentNumVertices; uint32_t numIndices = 0; uint32_t numPrimsSubmitted = 0; uint32_t numInstances = 0; @@ -6112,13 +6449,9 @@ 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_DRAW, viewNameW); - } + setViewType(view, "C"); + BGFX_D3D11_PROFILER_END(); + BGFX_D3D11_PROFILER_BEGIN(view, kColorCompute); invalidateCompute(); } @@ -6140,7 +6473,7 @@ namespace bgfx { namespace d3d11 } } - PIX_ENDEVENT(); + BGFX_D3D11_PROFILER_END(); int64_t timeEnd = bx::getHPCounter(); int64_t frameTime = timeEnd - timeBegin; @@ -6180,12 +6513,13 @@ namespace bgfx { namespace d3d11 perfStats.numCompute = statsKeyType[1]; perfStats.numBlit = _render->m_numBlitItems; perfStats.maxGpuLatency = maxGpuLatency; + perfStats.gpuFrameNum = result.m_frameNum; bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) ); m_nvapi.getMemoryInfo(perfStats.gpuMemoryUsed, perfStats.gpuMemoryMax); if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) { - PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugstats"); + BGFX_D3D11_PROFILER_BEGIN_LITERAL("debugstats", kColorFrame); m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; @@ -6202,11 +6536,17 @@ namespace bgfx { namespace d3d11 tvm.clear(); uint16_t pos = 0; tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f - , " %s.%d (FL %d.%d) / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " + , " %s.%d (FL %d.%d) / " BX_COMPILER_NAME + " / " BX_CPU_NAME + " / " BX_ARCH_NAME + " / " BX_PLATFORM_NAME + " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")" , getRendererName() , m_deviceInterfaceVersion , (m_featureLevel >> 12) & 0xf , (m_featureLevel >> 8) & 0xf + , BGFX_API_VERSION + , BGFX_REV_NUMBER ); const DXGI_ADAPTER_DESC& desc = m_dxgi.m_adapterDesc; @@ -6313,15 +6653,15 @@ namespace bgfx { namespace d3d11 blit(this, _textVideoMemBlitter, tvm); - PIX_ENDEVENT(); + BGFX_D3D11_PROFILER_END(); } else if (_render->m_debug & BGFX_DEBUG_TEXT) { - PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugtext"); + BGFX_D3D11_PROFILER_BEGIN_LITERAL("debugtext", kColorFrame); blit(this, _textVideoMemBlitter, _render->m_textVideoMem); - PIX_ENDEVENT(); + BGFX_D3D11_PROFILER_END(); } m_deviceCtx->OMSetRenderTargets(1, s_zero.m_rtv, NULL); diff --git a/3rdparty/bgfx/src/renderer_d3d11.h b/3rdparty/bgfx/src/renderer_d3d11.h index 2e021c4aa2f..3fc0849ac87 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.h +++ b/3rdparty/bgfx/src/renderer_d3d11.h @@ -1,26 +1,29 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_D3D11_H_HEADER_GUARD #define BGFX_RENDERER_D3D11_H_HEADER_GUARD -#define USE_D3D11_DYNAMIC_LIB BX_PLATFORM_WINDOWS +#define USE_D3D11_DYNAMIC_LIB (BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS) #define USE_D3D11_STAGING_BUFFER 0 #if !USE_D3D11_DYNAMIC_LIB -# undef BGFX_CONFIG_DEBUG_PIX -# define BGFX_CONFIG_DEBUG_PIX 0 +# undef BGFX_CONFIG_DEBUG_ANNOTATION +# define BGFX_CONFIG_DEBUG_ANNOTATION 0 #endif // !USE_D3D11_DYNAMIC_LIB BX_PRAGMA_DIAGNOSTIC_PUSH(); BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunknown-pragmas" ); BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wpragmas"); BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4005) // warning C4005: '' : macro redefinition + #include <sal.h> +#include <unknwn.h> + #define D3D11_NO_HELPERS -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS # include <d3d11_3.h> #elif BX_PLATFORM_WINRT # define __D3D10_1SHADER_H__ // BK - not used keep quiet! @@ -40,19 +43,37 @@ BX_PRAGMA_DIAGNOSTIC_POP() #include "nvapi.h" #include "dxgi.h" -#define BGFX_D3D11_BLEND_STATE_MASK (0 \ - | BGFX_STATE_BLEND_MASK \ - | BGFX_STATE_BLEND_EQUATION_MASK \ - | BGFX_STATE_BLEND_INDEPENDENT \ - | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE \ - | BGFX_STATE_WRITE_A \ - | BGFX_STATE_WRITE_RGB \ - ) +#define BGFX_D3D11_BLEND_STATE_MASK (0 \ + | BGFX_STATE_BLEND_MASK \ + | BGFX_STATE_BLEND_EQUATION_MASK \ + | BGFX_STATE_BLEND_INDEPENDENT \ + | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE \ + | BGFX_STATE_WRITE_A \ + | BGFX_STATE_WRITE_RGB \ + ) #define BGFX_D3D11_DEPTH_STENCIL_MASK (0 \ - | BGFX_STATE_WRITE_Z \ - | BGFX_STATE_DEPTH_TEST_MASK \ - ) + | BGFX_STATE_WRITE_Z \ + | BGFX_STATE_DEPTH_TEST_MASK \ + ) + +#define BGFX_D3D11_PROFILER_BEGIN(_view, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + PIX_BEGINEVENT(_abgr, s_viewNameW[_view]); \ + BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_D3D11_PROFILER_BEGIN_LITERAL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + PIX_BEGINEVENT(_abgr, L"" _name); \ + BGFX_PROFILER_BEGIN_LITERAL("" _name, _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_D3D11_PROFILER_END() \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_END(); \ + PIX_ENDEVENT(); \ + BX_MACRO_BLOCK_END namespace bgfx { namespace d3d11 { @@ -109,9 +130,9 @@ namespace bgfx { namespace d3d11 { } - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags); + void create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags); - VertexDeclHandle m_decl; + VertexLayoutHandle m_layoutHandle; }; struct ShaderD3D11 @@ -186,14 +207,14 @@ namespace bgfx { namespace d3d11 void create(const ShaderD3D11* _vsh, const ShaderD3D11* _fsh) { - BX_CHECK(NULL != _vsh->m_ptr, "Vertex shader doesn't exist."); + BX_ASSERT(NULL != _vsh->m_ptr, "Vertex shader doesn't exist."); m_vsh = _vsh; bx::memCopy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform) ); m_numPredefined = _vsh->m_numPredefined; if (NULL != _fsh) { - BX_CHECK(NULL != _fsh->m_ptr, "Fragment shader doesn't exist."); + BX_ASSERT(NULL != _fsh->m_ptr, "Fragment shader doesn't exist."); m_fsh = _fsh; bx::memCopy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform) ); m_numPredefined += _fsh->m_numPredefined; @@ -269,7 +290,7 @@ namespace bgfx { namespace d3d11 void overrideInternal(uintptr_t _ptr); void update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem); void commit(uint8_t _stage, uint32_t _flags, const float _palette[][4]); - void resolve(uint8_t _resolve) const; + void resolve(uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip) const; TextureHandle getHandle() const; DXGI_FORMAT getSrvFormat() const; @@ -294,6 +315,7 @@ namespace bgfx { namespace d3d11 uint32_t m_width; uint32_t m_height; uint32_t m_depth; + uint32_t m_numLayers; uint8_t m_type; uint8_t m_requestedFormat; uint8_t m_textureFormat; @@ -311,6 +333,7 @@ namespace bgfx { namespace d3d11 , m_denseIdx(UINT16_MAX) , m_num(0) , m_numTh(0) + , m_numUav(0) , m_needPresent(false) { } @@ -325,9 +348,10 @@ namespace bgfx { namespace d3d11 void set(); HRESULT present(uint32_t _syncInterval); - ID3D11RenderTargetView* m_rtv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; - ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; - ID3D11DepthStencilView* m_dsv; + ID3D11RenderTargetView* m_rtv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; + ID3D11UnorderedAccessView* m_uav[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; + ID3D11ShaderResourceView* m_srv[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; + ID3D11DepthStencilView* m_dsv; Dxgi::SwapChainI* m_swapChain; void* m_nwh; uint32_t m_width; @@ -337,6 +361,7 @@ namespace bgfx { namespace d3d11 uint16_t m_denseIdx; uint8_t m_num; uint8_t m_numTh; + uint8_t m_numUav; bool m_needPresent; }; @@ -349,7 +374,7 @@ namespace bgfx { namespace d3d11 void postReset(); void preReset(); - uint32_t begin(uint32_t _resultIdx); + uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum); void end(uint32_t _idx); bool update(); @@ -359,6 +384,7 @@ namespace bgfx { namespace d3d11 ID3D11Query* m_begin; ID3D11Query* m_end; uint32_t m_resultIdx; + uint32_t m_frameNum; bool m_ready; }; @@ -370,12 +396,14 @@ namespace bgfx { namespace d3d11 m_end = 0; m_frequency = 1; m_pending = 0; + m_frameNum = 0; } uint64_t m_begin; uint64_t m_end; uint64_t m_frequency; uint32_t m_pending; + uint32_t m_frameNum; }; Result m_result[BGFX_CONFIG_MAX_VIEWS+1]; diff --git a/3rdparty/bgfx/src/renderer_d3d12.cpp b/3rdparty/bgfx/src/renderer_d3d12.cpp index d577e63b609..36d23cb5a91 100644 --- a/3rdparty/bgfx/src/renderer_d3d12.cpp +++ b/3rdparty/bgfx/src/renderer_d3d12.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -8,22 +8,30 @@ #if BGFX_CONFIG_RENDERER_DIRECT3D12 # include "renderer_d3d12.h" -#if !BX_PLATFORM_WINDOWS +#if !BX_PLATFORM_WINDOWS && !BX_PLATFORM_LINUX # include <inspectable.h> # if BX_PLATFORM_WINRT # include <windows.ui.xaml.media.dxinterop.h> # endif // BX_PLATFORM_WINRT #endif // !BX_PLATFORM_WINDOWS -#if BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) +#if BGFX_CONFIG_DEBUG_ANNOTATION && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) PFN_PIX_GET_THREAD_INFO bgfx_PIXGetThreadInfo; PFN_PIX_EVENTS_REPLACE_BLOCK bgfx_PIXEventsReplaceBlock; -#endif // BGFX_CONFIG_DEBUG_PIX && BX_PLATFORM_WINDOWS +#endif // BGFX_CONFIG_DEBUG_ANNOTATION && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) namespace bgfx { namespace d3d12 { static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + inline void setViewType(ViewId _view, const bx::StringView _str) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION || BGFX_CONFIG_PROFILER) ) + { + bx::memCopy(&s_viewName[_view][3], _str.getPtr(), _str.getLength() ); + } + } + struct PrimInfo { D3D_PRIMITIVE_TOPOLOGY m_topology; @@ -174,95 +182,119 @@ namespace bgfx { namespace d3d12 DXGI_FORMAT m_fmtSrv; DXGI_FORMAT m_fmtDsv; DXGI_FORMAT m_fmtSrgb; + uint32_t m_mapping; }; static const TextureFormatInfo s_textureFormat[] = { - { DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC1_UNORM_SRGB }, // BC1 - { DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC2_UNORM_SRGB }, // BC2 - { DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC3_UNORM_SRGB }, // BC3 - { DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BC4 - { DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BC5 - { DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // BC6H - { DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC7_UNORM_SRGB }, // BC7 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC1 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2A - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ETC2A1 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC12 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC14 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC12A - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC14A - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC22 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // PTC24 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATC - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATCE - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // ATCI - { DXGI_FORMAT_ASTC_4X4_UNORM, DXGI_FORMAT_ASTC_4X4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_4X4_UNORM_SRGB }, // ASTC4x4 - { DXGI_FORMAT_ASTC_5X5_UNORM, DXGI_FORMAT_ASTC_5X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_5X5_UNORM_SRGB }, // ASTC5x5 - { DXGI_FORMAT_ASTC_6X6_UNORM, DXGI_FORMAT_ASTC_6X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_6X6_UNORM_SRGB }, // ASTC6x6 - { DXGI_FORMAT_ASTC_8X5_UNORM, DXGI_FORMAT_ASTC_8X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X5_UNORM_SRGB }, // ASTC8x5 - { DXGI_FORMAT_ASTC_8X6_UNORM, DXGI_FORMAT_ASTC_8X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X6_UNORM_SRGB }, // ASTC8x6 - { DXGI_FORMAT_ASTC_10X5_UNORM, DXGI_FORMAT_ASTC_10X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X5_UNORM_SRGB }, // ASTC10x5 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // Unknown - { DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R1 - { DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // A8 - { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R8 - { DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R8I - { DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R8U - { DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R8S - { DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R16 - { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R16I - { DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R16U - { DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R16F - { DXGI_FORMAT_R16_SNORM, DXGI_FORMAT_R16_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R16S - { DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R32I - { DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R32U - { DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R32F - { DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG8 - { DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG8I - { DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG8U - { DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG8S - { DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG16 - { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG16I - { DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG16U - { DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG16F - { DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG16S - { DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32I - { DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32U - { DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG32F - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8 - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8I - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8U - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB8S - { DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB9E5F - { DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB }, // BGRA8 - { DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA8 - { DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA8I - { DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB }, // RGBA8U - { DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA8S - { DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA16 - { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA16I - { DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA16U - { DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA16F - { DXGI_FORMAT_R16G16B16A16_SNORM, DXGI_FORMAT_R16G16B16A16_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA16S - { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32I - { DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32U - { DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA32F - { DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // R5G6B5 - { DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGBA4 - { DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB5A1 - { DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RGB10A2 - { DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // RG11B10F - { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, // UnknownDepth - { DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_UNKNOWN }, // D16 - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D24 - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D24S8 - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D32 - { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN }, // D16F - { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN }, // D24F - { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN }, // D32F - { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN }, // D0S8 +#define $0 D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0 +#define $1 D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1 +#define $R D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_0 +#define $G D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1 +#define $B D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_2 +#define $A D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_3 + { DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_BC1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC1_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BC1 + { DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_BC2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC2_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BC2 + { DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_BC3_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC3_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BC3 + { DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_BC4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BC4 + { DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_BC5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BC5 + { DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_BC6H_SF16, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BC6H + { DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_BC7_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_BC7_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BC7 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ETC1 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ETC2 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ETC2A + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ETC2A1 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // PTC12 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // PTC14 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // PTC12A + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // PTC14A + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // PTC22 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // PTC24 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ATC + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ATCE + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ATCI + { DXGI_FORMAT_ASTC_4X4_UNORM, DXGI_FORMAT_ASTC_4X4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_4X4_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC4x4 + { DXGI_FORMAT_ASTC_5X4_UNORM, DXGI_FORMAT_ASTC_5X4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_5X4_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC5x4 + { DXGI_FORMAT_ASTC_5X5_UNORM, DXGI_FORMAT_ASTC_5X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_5X5_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC5x5 + { DXGI_FORMAT_ASTC_6X5_UNORM, DXGI_FORMAT_ASTC_6X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_6X5_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC6x5 + { DXGI_FORMAT_ASTC_6X6_UNORM, DXGI_FORMAT_ASTC_6X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_6X6_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC6x6 + { DXGI_FORMAT_ASTC_8X5_UNORM, DXGI_FORMAT_ASTC_8X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X5_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC8x5 + { DXGI_FORMAT_ASTC_8X6_UNORM, DXGI_FORMAT_ASTC_8X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X6_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC8x6 + { DXGI_FORMAT_ASTC_8X8_UNORM, DXGI_FORMAT_ASTC_8X8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_8X8_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC8x8 + { DXGI_FORMAT_ASTC_10X5_UNORM, DXGI_FORMAT_ASTC_10X5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X5_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC10x5 + { DXGI_FORMAT_ASTC_10X6_UNORM, DXGI_FORMAT_ASTC_10X6_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X6_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC10x6 + { DXGI_FORMAT_ASTC_10X8_UNORM, DXGI_FORMAT_ASTC_10X8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X8_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC10x8 + { DXGI_FORMAT_ASTC_10X10_UNORM, DXGI_FORMAT_ASTC_10X10_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_10X10_UNORM_SRGB,D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC10x10 + { DXGI_FORMAT_ASTC_12X10_UNORM, DXGI_FORMAT_ASTC_12X10_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_12X10_UNORM_SRGB,D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC12x10 + { DXGI_FORMAT_ASTC_12X12_UNORM, DXGI_FORMAT_ASTC_12X12_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_ASTC_12X12_UNORM_SRGB,D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // ASTC12x12 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // Unknown + { DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_R1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R1 + { DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // A8 + { DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R8 + { DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R8I + { DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R8U + { DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_R8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R8S + { DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R16 + { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R16I + { DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R16U + { DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_R16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R16F + { DXGI_FORMAT_R16_SNORM, DXGI_FORMAT_R16_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R16S + { DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R32I + { DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R32U + { DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // R32F + { DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG8 + { DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG8I + { DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG8U + { DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_R8G8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG8S + { DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG16 + { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG16I + { DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG16U + { DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG16F + { DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG16S + { DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG32I + { DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG32U + { DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG32F + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGB8 + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGB8I + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGB8U + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGB8S + { DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGB9E5F + { DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BGRA8 + { DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA8 + { DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA8I + { DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA8U + { DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA8S + { DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_R16G16B16A16_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA16 + { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA16I + { DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA16U + { DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA16F + { DXGI_FORMAT_R16G16B16A16_SNORM, DXGI_FORMAT_R16G16B16A16_SNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA16S + { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA32I + { DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA32U + { DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGBA32F + { DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // B5G6R5 + { DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_B5G6R5_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING($B, $G, $R, $1) }, // R5G6B5 + { DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BGRA4 + { DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_B4G4R4A4_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING($B, $G, $R, $A) }, // RGBA4 + { DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // BGR5A1 + { DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_ENCODE_SHADER_4_COMPONENT_MAPPING($B, $G, $R, $A) }, // RGB5A1 + { DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RGB10A2 + { DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_R11G11B10_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // RG11B10F + { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // UnknownDepth + { DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D16 + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D24 + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D24S8 + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D32 + { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D16F + { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D24F + { DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D32F + { DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_UNKNOWN, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING }, // D0S8 +#undef $0 +#undef $1 +#undef $R +#undef $G +#undef $B +#undef $A }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); @@ -324,19 +356,19 @@ namespace bgfx { namespace d3d12 }; BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) ); - static D3D12_INPUT_ELEMENT_DESC* fillVertexDecl(uint8_t _stream, D3D12_INPUT_ELEMENT_DESC* _out, const VertexDecl& _decl) + static D3D12_INPUT_ELEMENT_DESC* fillVertexLayout(uint8_t _stream, D3D12_INPUT_ELEMENT_DESC* _out, const VertexLayout& _layout) { D3D12_INPUT_ELEMENT_DESC* elem = _out; for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - if (UINT16_MAX != _decl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { bx::memCopy(elem, &s_attrib[attr], sizeof(D3D12_INPUT_ELEMENT_DESC) ); elem->InputSlot = _stream; - if (0 == _decl.m_attributes[attr]) + if (0 == _layout.m_attributes[attr]) { elem->AlignedByteOffset = 0; } @@ -346,9 +378,9 @@ namespace bgfx { namespace d3d12 AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); + _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); elem->Format = s_attribType[type][num-1][normalized]; - elem->AlignedByteOffset = _decl.m_offset[attr]; + elem->AlignedByteOffset = _layout.m_offset[attr]; } ++elem; @@ -386,11 +418,14 @@ namespace bgfx { namespace d3d12 static const GUID IID_ID3D12Device3 = { 0x81dadc15, 0x2bad, 0x4392, { 0x93, 0xc5, 0x10, 0x13, 0x45, 0xc4, 0xaa, 0x98 } }; static const GUID IID_ID3D12Device4 = { 0xe865df17, 0xa9ee, 0x46f9, { 0xa4, 0x63, 0x30, 0x98, 0x31, 0x5a, 0xa2, 0xe5 } }; static const GUID IID_ID3D12Device5 = { 0x8b4f173b, 0x2fea, 0x4b80, { 0x8f, 0x58, 0x43, 0x07, 0x19, 0x1a, 0xb9, 0x5d } }; + static const GUID IID_ID3D12Device6 = { 0xc70b221b, 0x40e4, 0x4a17, { 0x89, 0xaf, 0x02, 0x5a, 0x07, 0x27, 0xa6, 0xdc } }; + static const GUID IID_ID3D12Device7 = { 0x5c014b53, 0x68a1, 0x4b9b, { 0x8b, 0xd1, 0xdd, 0x60, 0x46, 0xb9, 0x35, 0x8b } }; + static const GUID IID_ID3D12Device8 = { 0x9218e6bb, 0xf944, 0x4f7e, { 0xa7, 0x5c, 0xb1, 0xb2, 0xc7, 0xb7, 0x01, 0xf3 } }; static const GUID IID_ID3D12Fence = { 0x0a753dcf, 0xc4d8, 0x4b91, { 0xad, 0xf6, 0xbe, 0x5a, 0x60, 0xd9, 0x5a, 0x76 } }; static const GUID IID_ID3D12GraphicsCommandList = { 0x5b160d0f, 0xac1b, 0x4185, { 0x8b, 0xa8, 0xb3, 0xae, 0x42, 0xa5, 0xa4, 0x55 } }; static const GUID IID_ID3D12GraphicsCommandList1 = { 0x553103fb, 0x1fe7, 0x4557, { 0xbb, 0x38, 0x94, 0x6d, 0x7d, 0x0e, 0x7c, 0xa7 } }; - static const GUID IID_ID3D12GraphicsCommandList2 = { 0x38C3E585, 0xFF17, 0x412C, { 0x91, 0x50, 0x4F, 0xC6, 0xF9, 0xD7, 0x2A, 0x28 } }; - static const GUID IID_ID3D12GraphicsCommandList3 = { 0x6FDA83A7, 0xB84C, 0x4E38, { 0x9A, 0xC8, 0xC7, 0xBD, 0x22, 0x01, 0x6B, 0x3D } }; + static const GUID IID_ID3D12GraphicsCommandList2 = { 0x38c3e585, 0xff17, 0x412c, { 0x91, 0x50, 0x4f, 0xc6, 0xf9, 0xd7, 0x2a, 0x28 } }; + static const GUID IID_ID3D12GraphicsCommandList3 = { 0x6fda83a7, 0xb84c, 0x4e38, { 0x9a, 0xc8, 0xc7, 0xbd, 0x22, 0x01, 0x6b, 0x3d } }; static const GUID IID_ID3D12GraphicsCommandList4 = { 0x8754318e, 0xd3a9, 0x4541, { 0x98, 0xcf, 0x64, 0x5b, 0x50, 0xdc, 0x48, 0x74 } }; static const GUID IID_ID3D12InfoQueue = { 0x0742a90b, 0xc387, 0x483f, { 0xb9, 0x46, 0x30, 0xa7, 0xe4, 0xe6, 0x14, 0x58 } }; static const GUID IID_ID3D12PipelineState = { 0x765a30f3, 0xf624, 0x4c6f, { 0xa8, 0x28, 0xac, 0xe9, 0x48, 0x62, 0x24, 0x45 } }; @@ -402,6 +437,9 @@ namespace bgfx { namespace d3d12 static const GUID s_d3dDeviceIIDs[] = { + IID_ID3D12Device8, + IID_ID3D12Device7, + IID_ID3D12Device6, IID_ID3D12Device5, IID_ID3D12Device4, IID_ID3D12Device3, @@ -434,16 +472,15 @@ namespace bgfx { namespace d3d12 }; BX_STATIC_ASSERT(BX_COUNTOF(s_heapProperties) == HeapProperty::Count); - static inline D3D12_HEAP_PROPERTIES ID3D12DeviceGetCustomHeapProperties(ID3D12Device *device, UINT nodeMask, D3D12_HEAP_TYPE heapType) + static inline D3D12_HEAP_PROPERTIES ID3D12DeviceGetCustomHeapProperties(ID3D12Device *device, uint32_t nodeMask, D3D12_HEAP_TYPE heapType) { - // NOTICE: gcc trick for return struct - union { - D3D12_HEAP_PROPERTIES (STDMETHODCALLTYPE ID3D12Device::*w)(UINT, D3D12_HEAP_TYPE); - void (STDMETHODCALLTYPE ID3D12Device::*f)(D3D12_HEAP_PROPERTIES *, UINT, D3D12_HEAP_TYPE); - } conversion = { &ID3D12Device::GetCustomHeapProperties }; +#if BX_COMPILER_MSVC + return device->GetCustomHeapProperties(nodeMask, heapType); +#else D3D12_HEAP_PROPERTIES ret; - (device->*conversion.f)(&ret, nodeMask, heapType); + device->GetCustomHeapProperties(&ret, nodeMask, heapType); return ret; +#endif // BX_COMPILER_MSVC } static void initHeapProperties(ID3D12Device* _device, D3D12_HEAP_PROPERTIES& _properties) @@ -456,11 +493,13 @@ namespace bgfx { namespace d3d12 static void initHeapProperties(ID3D12Device* _device) { -#if BX_PLATFORM_WINDOWS +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS initHeapProperties(_device, s_heapProperties[HeapProperty::Default ].m_properties); initHeapProperties(_device, s_heapProperties[HeapProperty::Texture ].m_properties); initHeapProperties(_device, s_heapProperties[HeapProperty::Upload ].m_properties); initHeapProperties(_device, s_heapProperties[HeapProperty::ReadBack].m_properties); +#else + BX_UNUSED(_device); #endif // BX_PLATFORM_WINDOWS } @@ -485,7 +524,12 @@ namespace bgfx { namespace d3d12 { void* ptr; DX_CHECK(resource->Map(0, NULL, &ptr) ); - D3D12_RESOURCE_ALLOCATION_INFO rai = _device->GetResourceAllocationInfo(1, 1, _resourceDesc); + D3D12_RESOURCE_ALLOCATION_INFO rai; +#if BX_COMPILER_MSVC + rai = _device->GetResourceAllocationInfo(1, 1, _resourceDesc); +#else + _device->GetResourceAllocationInfo(&rai, 1, 1, _resourceDesc); +#endif // BX_COMPILER_MSVC bx::memSet(ptr, 0, size_t(rai.SizeInBytes) ); resource->Unmap(0, NULL); } @@ -495,7 +539,7 @@ namespace bgfx { namespace d3d12 ID3D12Resource* createCommittedResource(ID3D12Device* _device, HeapProperty::Enum _heapProperty, uint64_t _size, D3D12_RESOURCE_FLAGS _flags = D3D12_RESOURCE_FLAG_NONE) { - D3D12_RESOURCE_DESC resourceDesc; + D3D12_RESOURCE_DESC resourceDesc = {}; resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; resourceDesc.Alignment = 0; resourceDesc.Width = _size; @@ -574,8 +618,10 @@ namespace bgfx { namespace d3d12 static PFN_D3D12_GET_DEBUG_INTERFACE D3D12GetDebugInterface; static PFN_D3D12_SERIALIZE_ROOT_SIGNATURE D3D12SerializeRootSignature; +# if !BX_PLATFORM_LINUX typedef HANDLE (WINAPI* PFN_CREATE_EVENT_EX_A)(LPSECURITY_ATTRIBUTES _attrs, LPCSTR _name, DWORD _flags, DWORD _access); static PFN_CREATE_EVENT_EX_A CreateEventExA; +# endif // !BX_PLATFORM_LINUX #endif // USE_D3D12_DYNAMIC_LIB inline D3D12_CPU_DESCRIPTOR_HANDLE getCPUHandleHeapStart(ID3D12DescriptorHeap* _heap) @@ -584,11 +630,7 @@ namespace bgfx { namespace d3d12 return _heap->GetCPUDescriptorHandleForHeapStart(); #else D3D12_CPU_DESCRIPTOR_HANDLE handle; - union { - D3D12_CPU_DESCRIPTOR_HANDLE (WINAPI ID3D12DescriptorHeap::*w)(); - void (WINAPI ID3D12DescriptorHeap::*f)(D3D12_CPU_DESCRIPTOR_HANDLE *); - } conversion = { &ID3D12DescriptorHeap::GetCPUDescriptorHandleForHeapStart }; - (_heap->*conversion.f)(&handle); + _heap->GetCPUDescriptorHandleForHeapStart(&handle); return handle; #endif // BX_COMPILER_MSVC } @@ -599,11 +641,7 @@ namespace bgfx { namespace d3d12 return _heap->GetGPUDescriptorHandleForHeapStart(); #else D3D12_GPU_DESCRIPTOR_HANDLE handle; - union { - D3D12_GPU_DESCRIPTOR_HANDLE (WINAPI ID3D12DescriptorHeap::*w)(); - void (WINAPI ID3D12DescriptorHeap::*f)(D3D12_GPU_DESCRIPTOR_HANDLE *); - } conversion = { &ID3D12DescriptorHeap::GetGPUDescriptorHandleForHeapStart }; - (_heap->*conversion.f)(&handle); + _heap->GetGPUDescriptorHandleForHeapStart(&handle); return handle; #endif // BX_COMPILER_MSVC } @@ -614,16 +652,12 @@ namespace bgfx { namespace d3d12 return _resource->GetDesc(); #else D3D12_RESOURCE_DESC desc; - union { - D3D12_RESOURCE_DESC (STDMETHODCALLTYPE ID3D12Resource::*w)(); - void (STDMETHODCALLTYPE ID3D12Resource::*f)(D3D12_RESOURCE_DESC *); - } conversion = { &ID3D12Resource::GetDesc }; - (_resource->*conversion.f)(&desc); + _resource->GetDesc(&desc); return desc; #endif // BX_COMPILER_MSVC } -#if BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) +#if BGFX_CONFIG_DEBUG_ANNOTATION && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) static PIXEventsThreadInfo s_pixEventsThreadInfo; PIXEventsThreadInfo* WINAPI stubPIXGetThreadInfo() @@ -636,7 +670,7 @@ namespace bgfx { namespace d3d12 BX_UNUSED(_getEarliestTime); return 0; } -#endif // BGFX_CONFIG_DEBUG_PIX && BX_PLATFORM_WINDOWS +#endif // BGFX_CONFIG_DEBUG_ANNOTATION && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) struct RendererContextD3D12 : public RendererContextI { @@ -650,8 +684,6 @@ namespace bgfx { namespace d3d12 , m_lost(false) , m_maxAnisotropy(1) , m_depthClamp(false) - , m_fsChanges(0) - , m_vsChanges(0) , m_backBufferColorIdx(0) , m_rtMsaa(false) , m_directAccessSupport(false) @@ -680,7 +712,7 @@ namespace bgfx { namespace d3d12 ErrorState::Enum errorState = ErrorState::Default; // LUID luid; -#if BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) +#if BGFX_CONFIG_DEBUG_ANNOTATION && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) m_winPixEvent = bx::dlopen("WinPixEventRuntime.dll"); if (NULL != m_winPixEvent) @@ -695,7 +727,7 @@ namespace bgfx { namespace d3d12 bgfx_PIXGetThreadInfo = stubPIXGetThreadInfo; bgfx_PIXEventsReplaceBlock = stubPIXEventsReplaceBlock; } -#endif // BGFX_CONFIG_DEBUG_PIX && BX_PLATFORM_WINDOWS +#endif // BGFX_CONFIG_DEBUG_ANNOTATION && (BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT) if (_init.debug || _init.profile) @@ -710,6 +742,8 @@ namespace bgfx { namespace d3d12 bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); #if USE_D3D12_DYNAMIC_LIB + +# if !BX_PLATFORM_LINUX m_kernel32Dll = bx::dlopen("kernel32.dll"); if (NULL == m_kernel32Dll) { @@ -725,14 +759,26 @@ namespace bgfx { namespace d3d12 } errorState = ErrorState::LoadedKernel32; +# endif // !BX_PLATFORM_LINUX m_nvapi.init(); - m_d3d12Dll = bx::dlopen("d3d12.dll"); - if (NULL == m_d3d12Dll) { - BX_TRACE("Init error: Failed to load d3d12.dll."); - goto error; + const char* d3d12DllName = +#if BX_PLATFORM_LINUX + "libd3d12.so" +#else + "d3d12.dll" +#endif // BX_PLATFORM_LINUX + ; + + m_d3d12Dll = bx::dlopen(d3d12DllName); + + if (NULL == m_d3d12Dll) + { + BX_TRACE("Init error: Failed to load %s.", d3d12DllName); + goto error; + } } errorState = ErrorState::LoadedD3D12; @@ -758,65 +804,59 @@ namespace bgfx { namespace d3d12 } #endif // USE_D3D12_DYNAMIC_LIB +#if !BX_PLATFORM_LINUX if (!m_dxgi.init(g_caps) ) { goto error; } errorState = ErrorState::LoadedDXGI; +#endif // !BX_PLATFORM_LINUX HRESULT hr; - if (_init.debug - || _init.profile) { - ID3D12Debug* debug0; - hr = D3D12GetDebugInterface(IID_ID3D12Debug, (void**)&debug0); - - if (SUCCEEDED(hr) ) +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT + if (_init.debug + || _init.profile) { - uint32_t debugFlags = 0; + ID3D12Debug* debug0; + hr = D3D12GetDebugInterface(IID_ID3D12Debug, (void**)&debug0); - if (_init.debug) + if (SUCCEEDED(hr) ) { -#if BX_PLATFORM_WINDOWS - debug0->EnableDebugLayer(); - + if (_init.debug) { - ID3D12Debug1* debug1; - hr = debug0->QueryInterface(IID_ID3D12Debug1, (void**)&debug1); +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT + debug0->EnableDebugLayer(); - if (SUCCEEDED(hr) ) { -// debug1->SetEnableGPUBasedValidation(true); -// debug1->SetEnableSynchronizedCommandQueueValidation(true); - } + ID3D12Debug1* debug1; + hr = debug0->QueryInterface(IID_ID3D12Debug1, (void**)&debug1); - DX_RELEASE(debug1, 1); - } -#elif BX_PLATFORM_XBOXONE - debugFlags |= D3D12_PROCESS_DEBUG_FLAG_DEBUG_LAYER_ENABLED; -#endif // BX_PLATFORM_WINDOWS - } + if (SUCCEEDED(hr)) + { +// debug1->SetEnableGPUBasedValidation(true); -#if BX_PLATFORM_XBOXONE - // https://github.com/Microsoft/Xbox-ATG-Samples/blob/76d236e3bd372aceec18b2ad0556a7879dbd9628/XDKSamples/IntroGraphics/SimpleTriangle12/DeviceResources.cpp#L67 - debugFlags |= _init.profile ? D3D12XBOX_PROCESS_DEBUG_FLAG_INSTRUMENTED : 0; + // https://discordapp.com/channels/590611987420020747/593519198995742733/703642988345032804 + // D3D12 Bug Number: 26131261 + // There is a bug in the D3D12 validation that causes example-21 to fail when using UAV + // Setting this function below to false avoids the bug + debug1->SetEnableSynchronizedCommandQueueValidation(false); + } - if (0 != debugFlags) - { - debug0->SetProcessDebugFlags(D3D12XBOX_PROCESS_DEBUG_FLAGS(debugFlags) ); - } -#endif // BX_PLATFORM_XBOXONE - BX_UNUSED(debugFlags); + DX_RELEASE(debug1, 1); + } +#endif // BX_PLATFORM_WINDOWS + } - DX_RELEASE(debug0, 0); + DX_RELEASE(debug0, 0); + } } - } - { D3D_FEATURE_LEVEL featureLevel[] = { + D3D_FEATURE_LEVEL_12_2, D3D_FEATURE_LEVEL_12_1, D3D_FEATURE_LEVEL_12_0, D3D_FEATURE_LEVEL_11_1, @@ -826,7 +866,12 @@ namespace bgfx { namespace d3d12 hr = E_FAIL; for (uint32_t ii = 0; ii < BX_COUNTOF(featureLevel) && FAILED(hr); ++ii) { - hr = D3D12CreateDevice(m_dxgi.m_adapter + hr = D3D12CreateDevice( +#if BX_PLATFORM_LINUX + NULL +#else + m_dxgi.m_adapter +#endif // BX_PLATFORM_LINUX , featureLevel[ii] , IID_ID3D12Device , (void**)&m_device @@ -837,19 +882,46 @@ namespace bgfx { namespace d3d12 ); m_featureLevel = featureLevel[ii]; } +#else + // Reference(s): + // - https://github.com/Microsoft/Xbox-ATG-Samples/blob/1271bfd61b4883c775f395b6f13aeabea70290ca/XDKSamples/Graphics/AdvancedESRAM12/DeviceResources.cpp#L64 + D3D12XBOX_CREATE_DEVICE_PARAMETERS params = {}; + params.Version = D3D12_SDK_VERSION; + params.ProcessDebugFlags = D3D12XBOX_PROCESS_DEBUG_FLAGS(0 + | (_init.debug ? D3D12XBOX_PROCESS_DEBUG_FLAG_DEBUG : 0) + | (_init.profile ? D3D12XBOX_PROCESS_DEBUG_FLAG_INSTRUMENTED : 0) + ); + params.GraphicsCommandQueueRingSizeBytes = UINT32_MAX; + params.GraphicsScratchMemorySizeBytes = UINT32_MAX; + params.ComputeScratchMemorySizeBytes = UINT32_MAX; + params.DisableGeometryShaderAllocations = true; + params.DisableTessellationShaderAllocations = true; + + hr = D3D12XboxCreateDevice( + m_dxgi.m_adapter + , ¶ms + , IID_ID3D12Device + , (void**)&m_device + ); + m_featureLevel = D3D_FEATURE_LEVEL_12_1; + + if (SUCCEEDED(hr) ) + { + m_device->SetDebugErrorFilterX(0x73EC9EAF, D3D12XBOX_DEBUG_FILTER_FLAG_DISABLE_BREAKS); + m_device->SetDebugErrorFilterX(0x8EC9B15C, D3D12XBOX_DEBUG_FILTER_FLAG_DISABLE_OUTPUT); + } +#endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT } if (FAILED(hr) ) { BX_TRACE("Init error: Unable to create Direct3D12 device."); - if (BX_ENABLED(BX_PLATFORM_WINRT) ) - { - BX_TRACE("Hint: Change UWP app to game?"); - } goto error; } +#if !BX_PLATFORM_LINUX m_dxgi.update(m_device); +#endif // !BX_PLATFORM_LINUX { m_deviceInterfaceVersion = 0; @@ -866,15 +938,12 @@ namespace bgfx { namespace d3d12 } } -#if BX_PLATFORM_XBOXONE - m_device->SetDebugErrorFilterX(0x73EC9EAF, D3D12XBOX_DEBUG_FILTER_FLAG_DISABLE_BREAKS); - m_device->SetDebugErrorFilterX(0x8EC9B15C, D3D12XBOX_DEBUG_FILTER_FLAG_DISABLE_OUTPUT); -#endif // BX_PLATFORM_XBOXONE - +#if !BX_PLATFORM_LINUX if (BGFX_PCI_ID_NVIDIA != m_dxgi.m_adapterDesc.VendorId) { m_nvapi.shutdown(); } +#endif // !BX_PLATFORM_LINUX { uint32_t numNodes = m_device->GetNodeCount(); @@ -898,7 +967,7 @@ namespace bgfx { namespace d3d12 } DX_CHECK(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &m_options, sizeof(m_options) ) ); - BX_TRACE("D3D12 options:") + BX_TRACE("D3D12 options:"); BX_TRACE("\tTiledResourcesTier %d", m_options.TiledResourcesTier); BX_TRACE("\tResourceBindingTier %d", m_options.ResourceBindingTier); BX_TRACE("\tROVsSupported %d", m_options.ROVsSupported); @@ -906,9 +975,150 @@ namespace bgfx { namespace d3d12 BX_TRACE("\tCrossNodeSharingTier %d", m_options.CrossNodeSharingTier); BX_TRACE("\tResourceHeapTier %d", m_options.ResourceHeapTier); + for (D3D12_FEATURE_DATA_D3D12_OPTIONS1 options1; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &options1, sizeof(options1)));) + { + BX_TRACE("D3D12 options 1:"); + BX_TRACE("\tWaveOps %d", options1.WaveOps); + BX_TRACE("\tWaveLaneCountMin %d", options1.WaveLaneCountMin); + BX_TRACE("\tWaveLaneCountMax %d", options1.WaveLaneCountMax); + BX_TRACE("\tTotalLaneCount %d", options1.TotalLaneCount); + BX_TRACE("\tExpandedComputeResourceStates %d", options1.ExpandedComputeResourceStates); + BX_TRACE("\tInt64ShaderOps %d", options1.Int64ShaderOps); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS2 options2; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS2, &options2, sizeof(options2)));) + { + BX_TRACE("D3D12 options 2:"); + BX_TRACE("\tCopyQueueTimestampQueriesSupported %d", options2.DepthBoundsTestSupported); + BX_TRACE("\tCastingFullyTypedFormatSupported %d", options2.ProgrammableSamplePositionsTier); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS3 options3; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS3, &options3, sizeof(options3)));) + { + BX_TRACE("D3D12 options 3:"); + BX_TRACE("\tCopyQueueTimestampQueriesSupported %d", options3.CopyQueueTimestampQueriesSupported); + BX_TRACE("\tCastingFullyTypedFormatSupported %d", options3.CastingFullyTypedFormatSupported); + BX_TRACE("\tWriteBufferImmediateSupportFlags %d", options3.WriteBufferImmediateSupportFlags); + BX_TRACE("\tViewInstancingTier %d", options3.ViewInstancingTier); + BX_TRACE("\tBarycentricsSupported %d", options3.BarycentricsSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS4 options4; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS4, &options4, sizeof(options4)));) + { + BX_TRACE("D3D12 options 4:"); + BX_TRACE("\tMSAA64KBAlignedTextureSupported %d", options4.MSAA64KBAlignedTextureSupported); + BX_TRACE("\tSharedResourceCompatibilityTier %d", options4.SharedResourceCompatibilityTier); + BX_TRACE("\tNative16BitShaderOpsSupported %d", options4.Native16BitShaderOpsSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS5 options5; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &options5, sizeof(options5) ) );) + { + BX_TRACE("D3D12 options 5:"); + BX_TRACE("\tSRVOnlyTiledResourceTier3 %d", options5.SRVOnlyTiledResourceTier3); + BX_TRACE("\tRenderPassesTier %d", options5.RenderPassesTier); + BX_TRACE("\tRaytracingTier %d", options5.RaytracingTier); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS6 options6; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS6, &options6, sizeof(options6)));) + { + BX_TRACE("D3D12 options 6:"); + BX_TRACE("\tAdditionalShadingRatesSupported %d", options6.AdditionalShadingRatesSupported); + BX_TRACE("\tPerPrimitiveShadingRateSupportedWithViewportIndexing %d", options6.PerPrimitiveShadingRateSupportedWithViewportIndexing); + BX_TRACE("\tVariableShadingRateTier %d", options6.VariableShadingRateTier); + BX_TRACE("\tShadingRateImageTileSize %d", options6.ShadingRateImageTileSize); + BX_TRACE("\tBackgroundProcessingSupported %d", options6.BackgroundProcessingSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS7 options7; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS7, &options7, sizeof(options7)));) + { + BX_TRACE("D3D12 options 7:"); + BX_TRACE("\tMeshShaderTier %d", options7.MeshShaderTier); + BX_TRACE("\tSamplerFeedbackTier %d", options7.SamplerFeedbackTier); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS8 options8; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS8, &options8, sizeof(options8)));) + { + BX_TRACE("D3D12 options 8:"); + BX_TRACE("\tUnalignedBlockTexturesSupported %d", options8.UnalignedBlockTexturesSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS9 options9; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS9, &options9, sizeof(options9)));) + { + BX_TRACE("D3D12 options 9:"); + BX_TRACE("\tMeshShaderPipelineStatsSupported %d", options9.MeshShaderPipelineStatsSupported); + BX_TRACE("\tMeshShaderSupportsFullRangeRenderTargetArrayIndex %d", options9.MeshShaderSupportsFullRangeRenderTargetArrayIndex); + BX_TRACE("\tAtomicInt64OnTypedResourceSupported %d", options9.AtomicInt64OnTypedResourceSupported); + BX_TRACE("\tAtomicInt64OnGroupSharedSupported %d", options9.AtomicInt64OnGroupSharedSupported); + BX_TRACE("\tDerivativesInMeshAndAmplificationShadersSupported %d", options9.DerivativesInMeshAndAmplificationShadersSupported); + BX_TRACE("\tWaveMMATier %d", options9.WaveMMATier); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS10 options10; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS10, &options10, sizeof(options10)));) + { + BX_TRACE("D3D12 options 10:"); + BX_TRACE("\tVariableRateShadingSumCombinerSupported %d", options10.VariableRateShadingSumCombinerSupported); + BX_TRACE("\tMeshShaderPerPrimitiveShadingRateSupported %d", options10.MeshShaderPerPrimitiveShadingRateSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS11 options11; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS11, &options11, sizeof(options11)));) + { + BX_TRACE("D3D12 options 11:"); + BX_TRACE("\tAtomicInt64OnDescriptorHeapResourceSupported %d", options11.AtomicInt64OnDescriptorHeapResourceSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS12 options12; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options12, sizeof(options12)));) + { + BX_TRACE("D3D12 options 12:"); + BX_TRACE("\tMSPrimitivesPipelineStatisticIncludesCulledPrimitives %d", options12.MSPrimitivesPipelineStatisticIncludesCulledPrimitives); + BX_TRACE("\tEnhancedBarriersSupported %d", options12.EnhancedBarriersSupported); + BX_TRACE("\tRelaxedFormatCastingSupported %d", options12.RelaxedFormatCastingSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS13 options13; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options13, sizeof(options13)));) + { + BX_TRACE("D3D12 options 13:"); + BX_TRACE("\tUnrestrictedBufferTextureCopyPitchSupported %d", options13.UnrestrictedBufferTextureCopyPitchSupported); + BX_TRACE("\tUnrestrictedVertexElementAlignmentSupported %d", options13.UnrestrictedVertexElementAlignmentSupported); + BX_TRACE("\tInvertedViewportHeightFlipsYSupported %d", options13.InvertedViewportHeightFlipsYSupported); + BX_TRACE("\tInvertedViewportDepthFlipsZSupported %d", options13.InvertedViewportDepthFlipsZSupported); + BX_TRACE("\tTextureCopyBetweenDimensionsSupported %d", options13.TextureCopyBetweenDimensionsSupported); + BX_TRACE("\tAlphaBlendFactorSupported %d", options13.AlphaBlendFactorSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS14 options14; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options14, sizeof(options14)));) + { + BX_TRACE("D3D12 options 14:"); + BX_TRACE("\tAdvancedTextureOpsSupported %d", options14.AdvancedTextureOpsSupported); + BX_TRACE("\tWriteableMSAATexturesSupported %d", options14.WriteableMSAATexturesSupported); + BX_TRACE("\tIndependentFrontAndBackStencilRefMaskSupported %d", options14.IndependentFrontAndBackStencilRefMaskSupported); + break; + } + + for (D3D12_FEATURE_DATA_D3D12_OPTIONS15 options15; SUCCEEDED(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options15, sizeof(options15)));) + { + BX_TRACE("D3D12 options 15:"); + BX_TRACE("\tTriangleFanSupported %d", options15.TriangleFanSupported); + BX_TRACE("\tDynamicIndexBufferStripCutSupported %d", options15.DynamicIndexBufferStripCutSupported); + break; + } + initHeapProperties(m_device); m_cmd.init(m_device); + m_device->SetPrivateDataInterface(IID_ID3D12CommandQueue, m_cmd.m_commandQueue); errorState = ErrorState::CreatedCommandQueue; if (NULL == g_platformData.backBuffer) @@ -932,7 +1142,7 @@ namespace bgfx { namespace d3d12 m_scd.alphaMode = DXGI_ALPHA_MODE_IGNORE; m_scd.flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; - m_scd.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, 3); + m_scd.maxFrameLatency = bx::min<uint8_t>(_init.resolution.maxFrameLatency, BGFX_CONFIG_MAX_FRAME_LATENCY); m_scd.nwh = g_platformData.nwh; m_scd.ndt = g_platformData.ndt; m_scd.windowed = true; @@ -943,12 +1153,15 @@ namespace bgfx { namespace d3d12 if (NULL != m_scd.nwh) { +#if BX_PLATFORM_LINUX + hr = E_FAIL; +#else hr = m_dxgi.createSwapChain( getDeviceForSwapChain() , m_scd , &m_swapChain ); - +#endif // BX_PLATFORM_LINUX if (FAILED(hr) ) { @@ -972,7 +1185,9 @@ namespace bgfx { namespace d3d12 resourceDesc.Width = m_scd.width; resourceDesc.Height = m_scd.height; resourceDesc.MipLevels = 1; - resourceDesc.Format = m_scd.format; + resourceDesc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) + ? s_textureFormat[m_resolution.format].m_fmtSrgb + : s_textureFormat[m_resolution.format].m_fmt; resourceDesc.SampleDesc = m_scd.sampleDesc; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; @@ -997,6 +1212,7 @@ namespace bgfx { namespace d3d12 m_resolution.width = _init.resolution.width; m_resolution.height = _init.resolution.height; + m_windows[0] = BGFX_INVALID_HANDLE; m_numWindows = 1; #if BX_PLATFORM_WINDOWS @@ -1120,6 +1336,7 @@ namespace bgfx { namespace d3d12 g_caps.supported |= ( 0 | BGFX_CAPS_TEXTURE_3D | BGFX_CAPS_TEXTURE_COMPARE_ALL + | BGFX_CAPS_INDEX32 | BGFX_CAPS_INSTANCING | BGFX_CAPS_DRAW_INDIRECT | BGFX_CAPS_VERTEX_ATTRIB_HALF @@ -1137,6 +1354,9 @@ namespace bgfx { namespace d3d12 | BGFX_CAPS_ALPHA_TO_COVERAGE | BGFX_CAPS_TEXTURE_2D_ARRAY | BGFX_CAPS_TEXTURE_CUBE_ARRAY + | BGFX_CAPS_IMAGE_RW + | BGFX_CAPS_VIEWPORT_LAYER_ARRAY + | BGFX_CAPS_DRAW_INDIRECT_COUNT ); g_caps.limits.maxTextureSize = D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION; g_caps.limits.maxTextureLayers = D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION; @@ -1194,7 +1414,7 @@ namespace bgfx { namespace d3d12 support |= 0 != (data.Support1 & (0 | D3D12_FORMAT_SUPPORT1_SHADER_LOAD ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ : BGFX_CAPS_FORMAT_TEXTURE_NONE ; @@ -1225,10 +1445,10 @@ namespace bgfx { namespace d3d12 BX_TRACE("CheckFeatureSupport failed with %x for format %s.", hr, getName(TextureFormat::Enum(ii) ) ); } - if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE) ) + if (0 != (support & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ) ) { // clear image flag for additional testing - support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE; + support &= ~BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ; data.Format = s_textureFormat[ii].m_fmt; hr = m_device->CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT, &data, sizeof(data) ); @@ -1236,9 +1456,15 @@ namespace bgfx { namespace d3d12 { support |= 0 != (data.Support2 & (0 | D3D12_FORMAT_SUPPORT2_UAV_TYPED_LOAD + ) ) + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= 0 != (data.Support2 & (0 | D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE ) ) - ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE : BGFX_CAPS_FORMAT_TEXTURE_NONE ; } @@ -1250,7 +1476,7 @@ namespace bgfx { namespace d3d12 struct D3D11_FEATURE_DATA_FORMAT_SUPPORT { DXGI_FORMAT InFormat; - UINT OutFormatSupport; + uint32_t OutFormatSupport; }; D3D12_FEATURE_DATA_FORMAT_SUPPORT data; @@ -1297,7 +1523,9 @@ namespace bgfx { namespace d3d12 postReset(); m_batch.create(4<<10); - m_batch.setIndirectMode(BGFX_PCI_ID_NVIDIA != m_dxgi.m_adapterDesc.VendorId); +#if !BX_PLATFORM_LINUX + m_batch.setIndirectMode(BGFX_PCI_ID_NVIDIA != m_dxgi.m_adapterDesc.VendorId && BGFX_PCI_ID_MICROSOFT != m_dxgi.m_adapterDesc.VendorId); +#endif // !BX_PLATFORM_LINUX m_gpuTimer.init(); m_occlusionQuery.init(); @@ -1342,12 +1570,15 @@ namespace bgfx { namespace d3d12 switch (errorState) { case ErrorState::CreatedCommandQueue: + m_device->SetPrivateDataInterface(IID_ID3D12CommandQueue, NULL); m_cmd.shutdown(); BX_FALLTHROUGH; case ErrorState::CreatedDXGIFactory: DX_RELEASE(m_device, 0); +#if !BX_PLATFORM_LINUX m_dxgi.shutdown(); +#endif // !BX_PLATFORM_LINUX BX_FALLTHROUGH; #if USE_D3D12_DYNAMIC_LIB @@ -1429,12 +1660,15 @@ namespace bgfx { namespace d3d12 DX_RELEASE(m_msaaRt, 0); DX_RELEASE(m_swapChain, 0); + m_device->SetPrivateDataInterface(IID_ID3D12CommandQueue, NULL); m_cmd.shutdown(); DX_RELEASE(m_device, 0); m_nvapi.shutdown(); +#if !BX_PLATFORM_LINUX m_dxgi.shutdown(); +#endif // !BX_PLATFORM_LINUX unloadRenderDoc(m_renderDocDll); @@ -1472,17 +1706,28 @@ namespace bgfx { namespace d3d12 HRESULT hr = S_OK; uint32_t syncInterval = !!(m_resolution.reset & BGFX_RESET_VSYNC); - uint32_t flags = 0 == syncInterval ? DXGI_PRESENT_RESTART : 0; + uint32_t presentFlags = 0; + if (syncInterval) + { + presentFlags |= DXGI_PRESENT_RESTART; + } +#if !BX_PLATFORM_LINUX + else if (m_dxgi.tearingSupported() ) + { + presentFlags |= DXGI_PRESENT_ALLOW_TEARING; + } +#endif // !BX_PLATFORM_LINUX + for (uint32_t ii = 1, num = m_numWindows; ii < num && SUCCEEDED(hr); ++ii) { FrameBufferD3D12& frameBuffer = m_frameBuffers[m_windows[ii].idx]; - hr = frameBuffer.present(syncInterval, flags); + hr = frameBuffer.present(syncInterval, presentFlags); } if (SUCCEEDED(hr) && NULL != m_swapChain) { - hr = m_swapChain->Present(syncInterval, flags); + hr = m_swapChain->Present(syncInterval, presentFlags); } int64_t now = bx::getHPCounter(); @@ -1509,20 +1754,20 @@ namespace bgfx { namespace d3d12 m_indexBuffers[_handle.idx].destroy(); } - void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override + void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) override { - VertexDecl& decl = m_vertexDecls[_handle.idx]; - bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); - dump(decl); + VertexLayout& layout = m_vertexLayouts[_handle.idx]; + bx::memCopy(&layout, &_layout, sizeof(VertexLayout) ); + dump(layout); } - void destroyVertexDecl(VertexDeclHandle /*_handle*/) override + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override { } - void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) override + void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t _flags) override { - m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); + m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _layoutHandle, _flags); } void destroyVertexBuffer(VertexBufferHandle _handle) override @@ -1547,8 +1792,8 @@ namespace bgfx { namespace d3d12 void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) override { - VertexDeclHandle decl = BGFX_INVALID_HANDLE; - m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); + VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE; + m_vertexBuffers[_handle.idx].create(_size, NULL, layoutHandle, _flags); } void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override @@ -1608,46 +1853,47 @@ namespace bgfx { namespace d3d12 D3D12_PLACED_SUBRESOURCE_FOOTPRINT layout; uint32_t numRows; uint64_t total; - uint64_t srcPitch; m_device->GetCopyableFootprints(&desc , _mip , 1 , 0 , &layout , &numRows - , &srcPitch + , NULL , &total ); + uint32_t srcPitch = layout.Footprint.RowPitch; + ID3D12Resource* readback = createCommittedResource(m_device, HeapProperty::ReadBack, total); + uint32_t srcWidth = bx::uint32_max(1, texture.m_width >>_mip); + uint32_t srcHeight = bx::uint32_max(1, texture.m_height>>_mip); + D3D12_BOX box; box.left = 0; box.top = 0; - box.right = texture.m_width; - box.bottom = texture.m_height; + box.right = srcWidth; + box.bottom = srcHeight; box.front = 0; box.back = 1; D3D12_TEXTURE_COPY_LOCATION dstLocation = { readback, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, { layout } }; - D3D12_TEXTURE_COPY_LOCATION srcLocation = { texture.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, {} }; + D3D12_TEXTURE_COPY_LOCATION srcLocation = { texture.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { } }; + srcLocation.SubresourceIndex = _mip; m_commandList->CopyTextureRegion(&dstLocation, 0, 0, 0, &srcLocation, &box); finish(); m_commandList = m_cmd.alloc(); - uint32_t srcWidth = bx::uint32_max(1, texture.m_width >>_mip); - uint32_t srcHeight = bx::uint32_max(1, texture.m_height>>_mip); - uint8_t* src; - const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(texture.m_textureFormat) ); uint8_t* dst = (uint8_t*)_data; uint32_t dstPitch = srcWidth*bpp/8; - uint32_t pitch = bx::uint32_min(uint32_t(srcPitch), dstPitch); + uint32_t pitch = bx::uint32_min(srcPitch, dstPitch); - D3D12_RANGE readRange = { 0, dstPitch*srcHeight }; - readback->Map(0, &readRange, (void**)&src); + uint8_t* src; + readback->Map(0, NULL, (void**)&src); for (uint32_t yy = 0, height = srcHeight; yy < height; ++yy) { @@ -1672,7 +1918,7 @@ namespace bgfx { namespace d3d12 bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -1683,7 +1929,7 @@ namespace bgfx { namespace d3d12 tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); tc.m_cubeMap = false; tc.m_mem = NULL; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); texture.destroy(); texture.create(mem, texture.m_flags, 0); @@ -1693,13 +1939,16 @@ namespace bgfx { namespace d3d12 void overrideInternal(TextureHandle _handle, uintptr_t _ptr) override { - BX_UNUSED(_handle, _ptr); + // Resource ref. counts might be messed up outside of bgfx. + // Disabling ref. count check once texture is overridden. + setGraphicsDebuggerPresent(true); + m_textures[_handle.idx].overrideInternal(_ptr); } uintptr_t getInternal(TextureHandle _handle) override { - BX_UNUSED(_handle); - return 0; + setGraphicsDebuggerPresent(true); + return uintptr_t(m_textures[_handle.idx].m_ptr); } void destroyTexture(TextureHandle _handle) override @@ -1764,7 +2013,7 @@ namespace bgfx { namespace d3d12 BX_FREE(g_allocator, m_uniforms[_handle.idx]); } - uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type] * _num); + const uint32_t size = bx::alignUp(g_uniformTypeSize[_type] * _num, 16); void* data = BX_ALLOC(g_allocator, size); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; @@ -1841,7 +2090,8 @@ namespace bgfx { namespace d3d12 , (uint32_t)total , false ); - readback->Unmap(0, NULL); + D3D12_RANGE writeRange = { 0, 0 }; + readback->Unmap(0, &writeRange); DX_RELEASE(readback, 0); } @@ -1859,33 +2109,43 @@ namespace bgfx { namespace d3d12 bx::memCopy(m_uniforms[_loc], _data, _size); } - void setMarker(const char* _marker, uint32_t /*_size*/) override + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - PIX3_SETMARKER(m_commandList, D3DCOLOR_MARKER, _marker); - } + m_occlusionQuery.invalidate(_handle); } - void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + void setMarker(const char* _marker, uint16_t _len) override { - m_occlusionQuery.invalidate(_handle); + BX_UNUSED(_len); + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + PIX3_SETMARKER(m_commandList, kColorMarker, _marker); + } } - virtual void setName(Handle _handle, const char* _name) override + virtual void setName(Handle _handle, const char* _name, uint16_t _len) override { switch (_handle.type) { + case Handle::IndexBuffer: + setDebugObjectName(m_indexBuffers[_handle.idx].m_ptr, "%.*s", _len, _name); + break; + case Handle::Shader: -// setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%s", _name); +// setDebugObjectName(m_shaders[_handle.idx].m_ptr, "%.*s", _len, _name); break; case Handle::Texture: - setDebugObjectName(m_textures[_handle.idx].m_ptr, "%s", _name); + setDebugObjectName(m_textures[_handle.idx].m_ptr, "%.*s", _len, _name); + break; + + case Handle::VertexBuffer: + setDebugObjectName(m_vertexBuffers[_handle.idx].m_ptr, "%.*s", _len, _name); break; default: - BX_CHECK(false, "Invalid handle type?! %d", _handle.type); + BX_ASSERT(false, "Invalid handle type?! %d", _handle.type); break; } } @@ -1923,12 +2183,12 @@ namespace bgfx { namespace d3d12 | BGFX_STATE_DEPTH_TEST_ALWAYS ; - const VertexDecl* decls[1] = { &m_vertexDecls[_blitter.m_vb->decl.idx] }; + const VertexLayout* layouts[1] = { &m_vertexLayouts[_blitter.m_vb->layoutHandle.idx] }; ID3D12PipelineState* pso = getPipelineState(state , packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT) , 1 - , decls - , _blitter.m_program.idx + , layouts + , _blitter.m_program , 0 ); m_commandList->SetPipelineState(pso); @@ -1942,7 +2202,7 @@ namespace bgfx { namespace d3d12 setShaderUniform(flags, predefined.m_loc, proj, 4); D3D12_GPU_VIRTUAL_ADDRESS gpuAddress; - commitShaderConstants(_blitter.m_program.idx, gpuAddress); + commitShaderConstants(_blitter.m_program, gpuAddress); ScratchBufferD3D12& scratchBuffer = m_scratchBuffer[m_backBufferColorIdx]; ID3D12DescriptorHeap* heaps[] = @@ -1961,11 +2221,11 @@ namespace bgfx { namespace d3d12 scratchBuffer.allocSrv(srvHandle, texture); m_commandList->SetGraphicsRootDescriptorTable(Rdt::SRV, srvHandle); - VertexBufferD3D12& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; - const VertexDecl& vertexDecl = m_vertexDecls[_blitter.m_vb->decl.idx]; + VertexBufferD3D12& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; + const VertexLayout& layout = m_vertexLayouts[_blitter.m_vb->layoutHandle.idx]; D3D12_VERTEX_BUFFER_VIEW viewDesc; viewDesc.BufferLocation = vb.m_gpuVA; - viewDesc.StrideInBytes = vertexDecl.m_stride; + viewDesc.StrideInBytes = layout.m_stride; viewDesc.SizeInBytes = vb.m_size; m_commandList->IASetVertexBuffers(0, 1, &viewDesc); @@ -1985,7 +2245,7 @@ namespace bgfx { namespace d3d12 if (0 < numVertices) { m_indexBuffers [_blitter.m_ib->handle.idx].update(m_commandList, 0, _numIndices*2, _blitter.m_ib->data); - m_vertexBuffers[_blitter.m_vb->handle.idx].update(m_commandList, 0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data, true); + m_vertexBuffers[_blitter.m_vb->handle.idx].update(m_commandList, 0, numVertices*_blitter.m_layout.m_stride, _blitter.m_vb->data, true); m_commandList->DrawIndexedInstanced(_numIndices , 1 @@ -2039,11 +2299,34 @@ namespace bgfx { namespace d3d12 , IID_ID3D12Resource , (void**)&m_backBufferColor[ii] ) ); + + D3D12_RENDER_TARGET_VIEW_DESC rtvDesc; + rtvDesc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) + ? s_textureFormat[m_resolution.format].m_fmtSrgb + : s_textureFormat[m_resolution.format].m_fmt; + + if (1 < getResourceDesc(m_backBufferColor[ii]).DepthOrArraySize) + { + rtvDesc.ViewDimension = (NULL == m_msaaRt) ? + D3D12_RTV_DIMENSION_TEXTURE2DARRAY : D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; + rtvDesc.Texture2DArray.FirstArraySlice = 0; + rtvDesc.Texture2DArray.ArraySize = getResourceDesc(m_backBufferColor[ii]).DepthOrArraySize; + rtvDesc.Texture2DArray.MipSlice = 0; + rtvDesc.Texture2DArray.PlaneSlice = 0; + } + else + { + rtvDesc.ViewDimension = (NULL == m_msaaRt) ? + D3D12_RTV_DIMENSION_TEXTURE2D : D3D12_RTV_DIMENSION_TEXTURE2DMS; + rtvDesc.Texture2D.MipSlice = 0; + rtvDesc.Texture2D.PlaneSlice = 0; + } + m_device->CreateRenderTargetView( NULL == m_msaaRt ? m_backBufferColor[ii] : m_msaaRt - , NULL + , &rtvDesc , handle ); @@ -2051,7 +2334,7 @@ namespace bgfx { namespace d3d12 { ID3D12Resource* resource = m_backBufferColor[ii]; - BX_CHECK(DXGI_FORMAT_R8G8B8A8_UNORM == m_scd.format, ""); + BX_ASSERT(DXGI_FORMAT_R8G8B8A8_UNORM == m_scd.format, ""); const uint32_t size = m_scd.width*m_scd.height*4; void* ptr; @@ -2216,7 +2499,7 @@ namespace bgfx { namespace d3d12 BX_STATIC_ASSERT(BX_COUNTOF(m_backBufferColor) == BX_COUNTOF(presentQueue) ); DX_CHECK(m_dxgi.resizeBuffers(m_swapChain, m_scd, nodeMask, presentQueue) ); #elif BX_PLATFORM_WINRT - DX_CHECK(m_dxgi.resizeBuffers(m_swapChain, m_scd); + DX_CHECK(m_dxgi.resizeBuffers(m_swapChain, m_scd)); m_backBufferColorIdx = m_scd.bufferCount-1; #endif // BX_PLATFORM_WINDOWS } @@ -2228,11 +2511,15 @@ namespace bgfx { namespace d3d12 DX_RELEASE(m_swapChain, 0); HRESULT hr; +#if BX_PLATFORM_LINUX + hr = E_FAIL; +#else hr = m_dxgi.createSwapChain( getDeviceForSwapChain() , m_scd , &m_swapChain ); +#endif // BX_PLATFORM_LINUX BGFX_FATAL(SUCCEEDED(hr), bgfx::Fatal::UnableToInitialize, "Failed to create swap chain."); } @@ -2244,7 +2531,9 @@ namespace bgfx { namespace d3d12 resourceDesc.Width = m_scd.width; resourceDesc.Height = m_scd.height; resourceDesc.MipLevels = 1; - resourceDesc.Format = m_scd.format; + resourceDesc.Format = (m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER) + ? s_textureFormat[m_resolution.format].m_fmtSrgb + : s_textureFormat[m_resolution.format].m_fmt; resourceDesc.SampleDesc = m_scd.sampleDesc; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; resourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; @@ -2270,15 +2559,13 @@ namespace bgfx { namespace d3d12 void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { - if (_flags&BGFX_UNIFORM_FRAGMENTBIT) + if (_flags&kUniformFragmentBit) { bx::memCopy(&m_fsScratch[_regIndex], _val, _numRegs*16); - m_fsChanges += _numRegs; } else { bx::memCopy(&m_vsScratch[_regIndex], _val, _numRegs*16); - m_vsChanges += _numRegs; } } @@ -2292,9 +2579,9 @@ namespace bgfx { namespace d3d12 setShaderUniform(_flags, _regIndex, _val, _numRegs); } - void commitShaderConstants(uint16_t _programIdx, D3D12_GPU_VIRTUAL_ADDRESS& _gpuAddress) + void commitShaderConstants(ProgramHandle _program, D3D12_GPU_VIRTUAL_ADDRESS& _gpuAddress) { - const ProgramD3D12& program = m_program[_programIdx]; + const ProgramD3D12& program = m_program[_program.idx]; uint32_t total = bx::strideAlign(0 + program.m_vsh->m_size + (NULL != program.m_fsh ? program.m_fsh->m_size : 0) @@ -2306,15 +2593,11 @@ namespace bgfx { namespace d3d12 uint32_t size = program.m_vsh->m_size; bx::memCopy(data, m_vsScratch, size); data += size; - - m_vsChanges = 0; } if (NULL != program.m_fsh) { bx::memCopy(data, m_fsScratch, program.m_fsh->m_size); - - m_fsChanges = 0; } } @@ -2358,7 +2641,9 @@ namespace bgfx { namespace d3d12 if (isValid(m_fbh) && m_fbh.idx != _fbh.idx) { - const FrameBufferD3D12& frameBuffer = m_frameBuffers[m_fbh.idx]; + FrameBufferD3D12& frameBuffer = m_frameBuffers[m_fbh.idx]; + + if (m_rtMsaa) frameBuffer.resolve(); if (NULL == frameBuffer.m_swapChain) { @@ -2382,14 +2667,17 @@ namespace bgfx { namespace d3d12 if (!isValid(_fbh) ) { - m_rtvHandle = getCPUHandleHeapStart(m_rtvDescriptorHeap); - uint32_t rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); - m_rtvHandle.ptr += m_backBufferColorIdx * rtvDescriptorSize; - m_dsvHandle = getCPUHandleHeapStart(m_dsvDescriptorHeap); + if (NULL != m_swapChain) + { + m_rtvHandle = getCPUHandleHeapStart(m_rtvDescriptorHeap); + uint32_t rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); + m_rtvHandle.ptr += m_backBufferColorIdx * rtvDescriptorSize; + m_dsvHandle = getCPUHandleHeapStart(m_dsvDescriptorHeap); - m_currentColor = &m_rtvHandle; - m_currentDepthStencil = &m_dsvHandle; - m_commandList->OMSetRenderTargets(1, m_currentColor, true, m_currentDepthStencil); + m_currentColor = &m_rtvHandle; + m_currentDepthStencil = &m_dsvHandle; + m_commandList->OMSetRenderTargets(1, m_currentColor, true, m_currentDepthStencil); + } } else { @@ -2526,8 +2814,8 @@ namespace bgfx { namespace d3d12 ? D3D12_FILL_MODE_WIREFRAME : D3D12_FILL_MODE_SOLID ; - _desc.CullMode = s_cullMode[cull]; - _desc.FrontCounterClockwise = false; + _desc.CullMode = s_cullMode[cull]; + _desc.FrontCounterClockwise = !!(_state&BGFX_STATE_FRONT_CCW);; _desc.DepthBias = 0; _desc.DepthBiasClamp = 0.0f; _desc.SlopeScaledDepthBias = 0.0f; @@ -2573,7 +2861,7 @@ namespace bgfx { namespace d3d12 _desc.BackFace.StencilFunc = s_cmpFunc[(bstencil&BGFX_STENCIL_TEST_MASK) >> BGFX_STENCIL_TEST_SHIFT]; } - uint32_t setInputLayout(D3D12_INPUT_ELEMENT_DESC* _vertexElements, uint8_t _numStreams, const VertexDecl** _vertexDecls, const ProgramD3D12& _program, uint16_t _numInstanceData) + uint32_t setInputLayout(D3D12_INPUT_ELEMENT_DESC* _vertexElements, uint8_t _numStreams, const VertexLayout** _layouts, const ProgramD3D12& _program, uint16_t _numInstanceData) { uint16_t attrMask[Attrib::Count]; bx::memCopy(attrMask, _program.m_vsh->m_attrMask, sizeof(attrMask)); @@ -2582,19 +2870,19 @@ namespace bgfx { namespace d3d12 for (uint8_t stream = 0; stream < _numStreams; ++stream) { - VertexDecl decl; - bx::memCopy(&decl, _vertexDecls[stream], sizeof(VertexDecl)); + VertexLayout layout; + bx::memCopy(&layout, _layouts[stream], sizeof(VertexLayout)); const bool last = stream == _numStreams-1; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) { uint16_t mask = attrMask[ii]; - uint16_t attr = (decl.m_attributes[ii] & mask); + uint16_t attr = (layout.m_attributes[ii] & mask); if (0 == attr || UINT16_MAX == attr) { - decl.m_attributes[ii] = last ? ~attr : UINT16_MAX; + layout.m_attributes[ii] = last ? ~attr : UINT16_MAX; } else { @@ -2602,7 +2890,7 @@ namespace bgfx { namespace d3d12 } } - elem = fillVertexDecl(stream, elem, decl); + elem = fillVertexLayout(stream, elem, layout); } uint32_t num = uint32_t(elem-_vertexElements); @@ -2632,7 +2920,7 @@ namespace bgfx { namespace d3d12 } bx::memCopy(curr, &inst, sizeof(D3D12_INPUT_ELEMENT_DESC) ); - curr->InputSlot = 1; + curr->InputSlot = _numStreams; curr->SemanticIndex = index; curr->AlignedByteOffset = ii*16; } @@ -2640,10 +2928,10 @@ namespace bgfx { namespace d3d12 return uint32_t(elem-_vertexElements); } - uint32_t setInputLayout(D3D12_INPUT_ELEMENT_DESC* _vertexElements, const VertexDecl& _vertexDecl, const ProgramD3D12& _program, uint16_t _numInstanceData) + uint32_t setInputLayout(D3D12_INPUT_ELEMENT_DESC* _vertexElements, const VertexLayout& _layout, const ProgramD3D12& _program, uint16_t _numInstanceData) { - const VertexDecl* decls[1] = { &_vertexDecl }; - return setInputLayout(_vertexElements, BX_COUNTOF(decls), decls, _program, _numInstanceData); + const VertexLayout* layouts[1] = { &_layout }; + return setInputLayout(_vertexElements, BX_COUNTOF(layouts), layouts, _program, _numInstanceData); } static void patchCb0(DxbcInstruction& _instruction, void* _userData) @@ -2677,9 +2965,9 @@ namespace bgfx { namespace d3d12 } } - ID3D12PipelineState* getPipelineState(uint16_t _programIdx) + ID3D12PipelineState* getPipelineState(ProgramHandle _program) { - ProgramD3D12& program = m_program[_programIdx]; + ProgramD3D12& program = m_program[_program.idx]; const uint32_t hash = program.m_vsh->m_hash; @@ -2693,17 +2981,67 @@ namespace bgfx { namespace d3d12 D3D12_COMPUTE_PIPELINE_STATE_DESC desc; bx::memSet(&desc, 0, sizeof(desc) ); - desc.pRootSignature = m_rootSignature; - + desc.pRootSignature = m_rootSignature; desc.CS.pShaderBytecode = program.m_vsh->m_code->data; desc.CS.BytecodeLength = program.m_vsh->m_code->size; + desc.NodeMask = 1; + desc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE; + + uint32_t length = g_callback->cacheReadSize(hash); + const bool cached = length > 0; + + void* cachedData = NULL; + + if (cached) + { + cachedData = BX_ALLOC(g_allocator, length); + if (g_callback->cacheRead(hash, cachedData, length) ) + { + BX_TRACE("Loading cached compute PSO (size %d).", length); + bx::MemoryReader reader(cachedData, length); + + desc.CachedPSO.pCachedBlob = reader.getDataPtr(); + desc.CachedPSO.CachedBlobSizeInBytes = (size_t)reader.remaining(); + + HRESULT hr = m_device->CreateComputePipelineState(&desc + , IID_ID3D12PipelineState + , (void**)&pso + ); + if (FAILED(hr) ) + { + BX_TRACE("Failed to load cached compute PSO (HRESULT 0x%08x).", hr); + bx::memSet(&desc.CachedPSO, 0, sizeof(desc.CachedPSO) ); + } + } + } + + if (NULL == pso) + { + DX_CHECK(m_device->CreateComputePipelineState(&desc + , IID_ID3D12PipelineState + , (void**)&pso + ) ); + } - DX_CHECK(m_device->CreateComputePipelineState(&desc - , IID_ID3D12PipelineState - , (void**)&pso - ) ); m_pipelineStateCache.add(hash, pso); + ID3DBlob* blob; + HRESULT hr = pso->GetCachedBlob(&blob); + if (SUCCEEDED(hr) ) + { + void* data = blob->GetBufferPointer(); + length = (uint32_t)blob->GetBufferSize(); + + g_callback->cacheWrite(hash, data, length); + + DX_RELEASE(blob, 0); + } + + if (NULL != cachedData) + { + BX_FREE(g_allocator, cachedData); + } + return pso; } @@ -2711,12 +3049,12 @@ namespace bgfx { namespace d3d12 uint64_t _state , uint64_t _stencil , uint8_t _numStreams - , const VertexDecl** _vertexDecls - , uint16_t _programIdx + , const VertexLayout** _layouts + , ProgramHandle _program , uint8_t _numInstanceData ) { - ProgramD3D12& program = m_program[_programIdx]; + ProgramD3D12& program = m_program[_program.idx]; _state &= 0 | BGFX_STATE_WRITE_RGB @@ -2728,6 +3066,7 @@ namespace bgfx { namespace d3d12 | BGFX_STATE_BLEND_INDEPENDENT | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE | BGFX_STATE_CULL_MASK + | BGFX_STATE_FRONT_CCW | BGFX_STATE_MSAA | BGFX_STATE_LINEAA | BGFX_STATE_CONSERVATIVE_RASTER @@ -2736,17 +3075,17 @@ namespace bgfx { namespace d3d12 _stencil &= packStencil(~BGFX_STENCIL_FUNC_REF_MASK, ~BGFX_STENCIL_FUNC_REF_MASK); - VertexDecl decl; + VertexLayout layout; if (0 < _numStreams) { - bx::memCopy(&decl, _vertexDecls[0], sizeof(VertexDecl) ); + bx::memCopy(&layout, _layouts[0], sizeof(VertexLayout) ); const uint16_t* attrMask = program.m_vsh->m_attrMask; for (uint32_t ii = 0; ii < Attrib::Count; ++ii) { uint16_t mask = attrMask[ii]; - uint16_t attr = (decl.m_attributes[ii] & mask); - decl.m_attributes[ii] = attr == 0 ? UINT16_MAX : attr == UINT16_MAX ? 0 : attr; + uint16_t attr = (layout.m_attributes[ii] & mask); + layout.m_attributes[ii] = attr == 0 ? UINT16_MAX : attr == UINT16_MAX ? 0 : attr; } } @@ -2764,10 +3103,10 @@ namespace bgfx { namespace d3d12 for (uint32_t ii = 0; ii < _numStreams; ++ii) { - murmur.add(_vertexDecls[ii]->m_hash); + murmur.add(_layouts[ii]->m_hash); } - murmur.add(decl.m_attributes, sizeof(decl.m_attributes) ); + murmur.add(layout.m_attributes, sizeof(layout.m_attributes) ); murmur.add(m_fbh.idx); murmur.add(_numInstanceData); const uint32_t hash = murmur.end(); @@ -2804,14 +3143,14 @@ namespace bgfx { namespace d3d12 union { uint32_t offset; void* ptr; } cast = { 0 }; filter(dxbc.shader, dxbc.shader, patchCb0, cast.ptr); - temp = alloc(uint32_t(dxbc.shader.byteCode.size() )+1024); + temp = alloc(uint32_t(dxbc.header.size)); bx::StaticMemoryBlockWriter wr(temp->data, temp->size); int32_t size = write(&wr, dxbc, &err); dxbcHash(temp->data + 20, size - 20, temp->data + 4); patchShader = 0 == bx::memCmp(program.m_fsh->m_code->data, temp->data, 16); - BX_CHECK(patchShader, "DXBC fragment shader patching error (ShaderHandle: %d).", program.m_fsh - m_shaders); + BX_ASSERT(patchShader, "DXBC fragment shader patching error (ShaderHandle: %d).", program.m_fsh - m_shaders); if (!patchShader) { @@ -2841,7 +3180,7 @@ namespace bgfx { namespace d3d12 }; filter(dxbc.shader, dxbc.shader, patchCb0, cast.ptr); - temp = alloc(uint32_t(dxbc.shader.byteCode.size() )+1024); + temp = alloc(uint32_t(dxbc.header.size)); bx::StaticMemoryBlockWriter wr(temp->data, temp->size); int32_t size = write(&wr, dxbc, &err); @@ -2883,7 +3222,7 @@ namespace bgfx { namespace d3d12 setDepthStencilState(desc.DepthStencilState, _state, _stencil); D3D12_INPUT_ELEMENT_DESC vertexElements[Attrib::Count + 1 + BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; - desc.InputLayout.NumElements = setInputLayout(vertexElements, _numStreams, _vertexDecls, program, _numInstanceData); + desc.InputLayout.NumElements = setInputLayout(vertexElements, _numStreams, _layouts, program, _numInstanceData); desc.InputLayout.pInputElementDescs = 0 == desc.InputLayout.NumElements ? NULL : vertexElements @@ -2930,7 +3269,7 @@ namespace bgfx { namespace d3d12 desc.SampleDesc = m_scd.sampleDesc; uint32_t length = g_callback->cacheReadSize(hash); - bool cached = length > 0; + const bool cached = length > 0; void* cachedData = NULL; @@ -2939,7 +3278,7 @@ namespace bgfx { namespace d3d12 cachedData = BX_ALLOC(g_allocator, length); if (g_callback->cacheRead(hash, cachedData, length) ) { - BX_TRACE("Loading cached PSO (size %d).", length); + BX_TRACE("Loading cached graphics PSO (size %d).", length); bx::MemoryReader reader(cachedData, length); desc.CachedPSO.pCachedBlob = reader.getDataPtr(); @@ -2951,7 +3290,7 @@ namespace bgfx { namespace d3d12 ); if (FAILED(hr) ) { - BX_TRACE("Failed to load cached PSO (HRESULT 0x%08x).", hr); + BX_TRACE("Failed to load cached graphics PSO (HRESULT 0x%08x).", hr); bx::memSet(&desc.CachedPSO, 0, sizeof(desc.CachedPSO) ); } } @@ -3047,18 +3386,10 @@ namespace bgfx { namespace d3d12 data = (const char*)m_uniforms[handle.idx]; } -#define CASE_IMPLEMENT_UNIFORM(_uniform, _dxsuffix, _type) \ - case UniformType::_uniform: \ - case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \ - { \ - setShaderUniform(uint8_t(type), loc, data, num); \ - } \ - break; - switch ( (uint32_t)type) { case UniformType::Mat3: - case UniformType::Mat3|BGFX_UNIFORM_FRAGMENTBIT: + case UniformType::Mat3|kUniformFragmentBit: { float* value = (float*)data; for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3*16, value += 9) @@ -3081,9 +3412,16 @@ namespace bgfx { namespace d3d12 } break; - CASE_IMPLEMENT_UNIFORM(Int1, I, int); - CASE_IMPLEMENT_UNIFORM(Vec4, F, float); - CASE_IMPLEMENT_UNIFORM(Mat4, F, float); + case UniformType::Sampler: + case UniformType::Sampler | kUniformFragmentBit: + case UniformType::Vec4: + case UniformType::Vec4 | kUniformFragmentBit: + case UniformType::Mat4: + case UniformType::Mat4 | kUniformFragmentBit: + { + setShaderUniform(uint8_t(type), loc, data, num); + } + break; case UniformType::End: break; @@ -3092,7 +3430,6 @@ namespace bgfx { namespace d3d12 BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy); break; } -#undef CASE_IMPLEMENT_UNIFORM } } @@ -3211,7 +3548,10 @@ namespace bgfx { namespace d3d12 m_commandList = _alloc ? m_cmd.alloc() : NULL; } +#if !BX_PLATFORM_LINUX Dxgi m_dxgi; +#endif // !BX_PLATFORM_LINUX + NvApi m_nvapi; void* m_kernel32Dll; @@ -3275,7 +3615,7 @@ namespace bgfx { namespace d3d12 ShaderD3D12 m_shaders[BGFX_CONFIG_MAX_SHADERS]; ProgramD3D12 m_program[BGFX_CONFIG_MAX_PROGRAMS]; TextureD3D12 m_textures[BGFX_CONFIG_MAX_TEXTURES]; - VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS]; + VertexLayout m_vertexLayouts[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; FrameBufferD3D12 m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; Matrix4 m_predefinedUniforms[PredefinedUniform::Count]; @@ -3288,8 +3628,6 @@ namespace bgfx { namespace d3d12 uint8_t m_fsScratch[64<<10]; uint8_t m_vsScratch[64<<10]; - uint32_t m_fsChanges; - uint32_t m_vsChanges; FrameBufferHandle m_fbh; uint32_t m_backBufferColorIdx; @@ -3372,7 +3710,7 @@ namespace bgfx { namespace d3d12 _gpuAddress = m_gpuVA + m_pos; void* data = &m_data[m_pos]; - m_pos += BX_ALIGN_256(_size); + m_pos += bx::alignUp(_size, 256); // D3D12_CONSTANT_BUFFER_VIEW_DESC desc; // desc.BufferLocation = _gpuAddress; @@ -3422,7 +3760,7 @@ namespace bgfx { namespace d3d12 } } - device->CreateShaderResourceView(_texture.m_ptr + device->CreateShaderResourceView(NULL != _texture.m_singleMsaa ? _texture.m_singleMsaa : _texture.m_ptr , srvd , m_cpuHandle ); @@ -3696,7 +4034,11 @@ namespace bgfx { namespace d3d12 ID3D12CommandList* commandLists[] = { commandList.m_commandList }; m_commandQueue->ExecuteCommandLists(BX_COUNTOF(commandLists), commandLists); +#if BX_PLATFORM_LINUX + commandList.m_event = NULL; +#else commandList.m_event = CreateEventExA(NULL, NULL, 0, EVENT_ALL_ACCESS); +#endif // BX_PLATFORM_LINUX const uint64_t fence = m_currentFence++; m_commandQueue->Signal(m_fence, fence); m_fence->SetEventOnCompletion(fence, commandList.m_event); @@ -3719,7 +4061,7 @@ namespace bgfx { namespace d3d12 } } - BX_CHECK(0 == m_control.available(), ""); + BX_ASSERT(0 == m_control.available(), ""); } bool CommandQueueD3D12::tryFinish(uint64_t _waitFence) @@ -3744,6 +4086,9 @@ namespace bgfx { namespace d3d12 bool CommandQueueD3D12::consume(uint32_t _ms) { CommandList& commandList = m_commandList[m_control.m_read]; +#if BX_PLATFORM_LINUX + BX_UNUSED(commandList, _ms); +#else if (WAIT_OBJECT_0 == WaitForSingleObject(commandList.m_event, _ms) ) { CloseHandle(commandList.m_event); @@ -3764,6 +4109,7 @@ namespace bgfx { namespace d3d12 return true; } +#endif // !BX_PLATFORM_LINUX return false; } @@ -3861,7 +4207,7 @@ namespace bgfx { namespace d3d12 Ty& BatchD3D12::getCmd(Enum _type) { uint32_t index = m_num[_type]; - BX_CHECK(index < m_maxDrawPerBatch, "Memory corruption..."); + BX_ASSERT(index < m_maxDrawPerBatch, "Memory corruption..."); m_num[_type]++; Ty* cmd = &reinterpret_cast<Ty*>(m_cmds[_type])[index]; return *cmd; @@ -3874,13 +4220,14 @@ namespace bgfx { namespace d3d12 if (UINT8_MAX != _draw.m_streamMask) { - for (uint32_t idx = 0, streamMask = _draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = _draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask), ++numStreams + ; streamMask >>= 1, idx += 1, ++numStreams ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; - idx += ntz; + idx += ntz; const Stream& stream = _draw.m_stream[idx]; @@ -3888,13 +4235,13 @@ namespace bgfx { namespace d3d12 VertexBufferD3D12& vb = s_renderD3D12->m_vertexBuffers[handle]; vb.setState(_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - uint16_t decl = !isValid(vb.m_decl) ? stream.m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = s_renderD3D12->m_vertexDecls[decl]; - uint32_t stride = vertexDecl.m_stride; + const uint16_t layoutIdx = !isValid(vb.m_layoutHandle) ? stream.m_layoutHandle.idx : vb.m_layoutHandle.idx; + const VertexLayout& layout = s_renderD3D12->m_vertexLayouts[layoutIdx]; + uint32_t stride = layout.m_stride; D3D12_VERTEX_BUFFER_VIEW& vbv = _vbv[numStreams]; vbv.BufferLocation = vb.m_gpuVA + stream.m_startVertex * stride; - vbv.StrideInBytes = vertexDecl.m_stride; + vbv.StrideInBytes = layout.m_stride; vbv.SizeInBytes = vb.m_size; _outNumVertices = bx::uint32_min(UINT32_MAX == _draw.m_numVertices @@ -3939,6 +4286,13 @@ namespace bgfx { namespace d3d12 ? indirect.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE : _draw.m_numIndirect ; + ID3D12Resource* numIndirect = NULL; + uint32_t numOffsetIndirect = 0; + if (isValid(_draw.m_numIndirectBuffer) ) + { + numIndirect = s_renderD3D12->m_indexBuffers[_draw.m_numIndirectBuffer.idx].m_ptr; + numOffsetIndirect = _draw.m_numIndirectIndex * sizeof(uint32_t); + } uint32_t numIndices = 0; @@ -3947,8 +4301,12 @@ namespace bgfx { namespace d3d12 BufferD3D12& ib = s_renderD3D12->m_indexBuffers[_draw.m_indexBuffer.idx]; ib.setState(_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32); - const uint32_t indexSize = hasIndex16 ? 2 : 4; + const bool isIndex16 = _draw.isIndex16(); + const uint32_t indexSize = isIndex16 ? 2 : 4; + const DXGI_FORMAT indexFormat = isIndex16 + ? DXGI_FORMAT_R16_UINT + : DXGI_FORMAT_R32_UINT + ; numIndices = UINT32_MAX == _draw.m_numIndices ? ib.m_size / indexSize @@ -3958,10 +4316,7 @@ namespace bgfx { namespace d3d12 D3D12_INDEX_BUFFER_VIEW ibv; ibv.BufferLocation = ib.m_gpuVA; ibv.SizeInBytes = ib.m_size; - ibv.Format = hasIndex16 - ? DXGI_FORMAT_R16_UINT - : DXGI_FORMAT_R32_UINT - ; + ibv.Format = indexFormat; _commandList->IASetIndexBuffer(&ibv); _commandList->ExecuteIndirect( @@ -3969,8 +4324,8 @@ namespace bgfx { namespace d3d12 , numDrawIndirect , indirect.m_ptr , _draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE - , NULL - , 0 + , numIndirect + , numOffsetIndirect ); } else @@ -3980,8 +4335,8 @@ namespace bgfx { namespace d3d12 , numDrawIndirect , indirect.m_ptr , _draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE - , NULL - , 0 + , numIndirect + , numOffsetIndirect ); } @@ -4026,8 +4381,9 @@ namespace bgfx { namespace d3d12 BufferD3D12& ib = s_renderD3D12->m_indexBuffers[_draw.m_indexBuffer.idx]; ib.setState(_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32); - const uint32_t indexSize = hasIndex16 ? 2 : 4; + const bool isIndex16 = _draw.isIndex16(); + const uint32_t indexSize = isIndex16 ? 2 : 4; + const DXGI_FORMAT indexFormat = isIndex16 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; numIndices = UINT32_MAX == _draw.m_numIndices ? ib.m_size / indexSize @@ -4038,10 +4394,7 @@ namespace bgfx { namespace d3d12 cmd.cbv = _cbv; cmd.ibv.BufferLocation = ib.m_gpuVA; cmd.ibv.SizeInBytes = ib.m_size; - cmd.ibv.Format = hasIndex16 - ? DXGI_FORMAT_R16_UINT - : DXGI_FORMAT_R32_UINT - ; + cmd.ibv.Format = indexFormat; uint32_t numVertices; uint8_t numStreams = fill(_commandList, cmd.vbv, _draw, numVertices); @@ -4214,15 +4567,15 @@ namespace bgfx { namespace d3d12 static const UavFormat s_uavFormat[] = { // BGFX_BUFFER_COMPUTE_TYPE_INT, BGFX_BUFFER_COMPUTE_TYPE_UINT, BGFX_BUFFER_COMPUTE_TYPE_FLOAT { { DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN }, 0 }, // ignored - { { DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN }, 1 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x1 - { { DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x2 - { { DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_8x4 - { { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_FLOAT }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x1 - { { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x2 - { { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_16x4 - { { DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x1 - { { DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x2 - { { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_FLOAT }, 16 }, // BGFX_BUFFER_COMPUTE_FORMAT_32x4 + { { DXGI_FORMAT_R8_SINT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_UNKNOWN }, 1 }, // BGFX_BUFFER_COMPUTE_FORMAT_8X1 + { { DXGI_FORMAT_R8G8_SINT, DXGI_FORMAT_R8G8_UINT, DXGI_FORMAT_UNKNOWN }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_8X2 + { { DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_UNKNOWN }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_8X4 + { { DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R16_FLOAT }, 2 }, // BGFX_BUFFER_COMPUTE_FORMAT_16X1 + { { DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_16X2 + { { DXGI_FORMAT_R16G16B16A16_SINT, DXGI_FORMAT_R16G16B16A16_UINT, DXGI_FORMAT_R16G16B16A16_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_16X4 + { { DXGI_FORMAT_R32_SINT, DXGI_FORMAT_R32_UINT, DXGI_FORMAT_R32_FLOAT }, 4 }, // BGFX_BUFFER_COMPUTE_FORMAT_32X1 + { { DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_FLOAT }, 8 }, // BGFX_BUFFER_COMPUTE_FORMAT_32X2 + { { DXGI_FORMAT_R32G32B32A32_SINT, DXGI_FORMAT_R32G32B32A32_UINT, DXGI_FORMAT_R32G32B32A32_FLOAT }, 16 }, // BGFX_BUFFER_COMPUTE_FORMAT_32X4 }; void BufferD3D12::create(uint32_t _size, void* _data, uint16_t _flags, bool _vertex, uint32_t _stride) @@ -4247,8 +4600,8 @@ namespace bgfx { namespace d3d12 #if BX_PLATFORM_XBOXONE flags |= D3D12XBOX_RESOURCE_FLAG_ALLOW_INDIRECT_BUFFER; #endif // BX_PLATFORM_XBOXONE - format = DXGI_FORMAT_R32G32B32A32_UINT; - stride = 16; + format = _vertex ? DXGI_FORMAT_R32G32B32A32_UINT : DXGI_FORMAT_R32_UINT; + stride = _vertex ? 16 : 4; } else { @@ -4360,23 +4713,25 @@ namespace bgfx { namespace d3d12 return _state; } - void VertexBufferD3D12::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags) + void VertexBufferD3D12::create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags) { BufferD3D12::create(_size, _data, _flags, true); - m_decl = _declHandle; + m_layoutHandle = _layoutHandle; } void ShaderD3D12::create(const Memory* _mem) { bx::MemoryReader reader(_mem->data, _mem->size); + bx::ErrorAssert err; + uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, &err); const bool fragment = isShaderType(magic, 'F'); uint32_t hashIn; - bx::read(&reader, hashIn); + bx::read(&reader, hashIn, &err); uint32_t hashOut; @@ -4386,11 +4741,11 @@ namespace bgfx { namespace d3d12 } else { - bx::read(&reader, hashOut); + bx::read(&reader, hashOut, &err); } uint16_t count; - bx::read(&reader, count); + bx::read(&reader, count, &err); m_numPredefined = 0; m_numUniforms = count; @@ -4400,30 +4755,42 @@ namespace bgfx { namespace d3d12 , count ); - uint8_t fragmentBit = fragment ? BGFX_UNIFORM_FRAGMENTBIT : 0; + uint8_t fragmentBit = fragment ? kUniformFragmentBit : 0; if (0 < count) { for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize = 0; - bx::read(&reader, nameSize); + bx::read(&reader, nameSize, &err); char name[256] = {}; - bx::read(&reader, &name, nameSize); + bx::read(&reader, &name, nameSize, &err); name[nameSize] = '\0'; uint8_t type = 0; - bx::read(&reader, type); + bx::read(&reader, type, &err); uint8_t num = 0; - bx::read(&reader, num); + bx::read(&reader, num, &err); uint16_t regIndex = 0; - bx::read(&reader, regIndex); + bx::read(&reader, regIndex, &err); uint16_t regCount = 0; - bx::read(&reader, regCount); + bx::read(&reader, regCount, &err); + + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo = 0; + bx::read(&reader, texInfo, &err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(&reader, texFormat, &err); + } const char* kind = "invalid"; @@ -4436,7 +4803,7 @@ namespace bgfx { namespace d3d12 m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); m_numPredefined++; } - else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) ) + else if (0 == (kUniformSamplerBit & type) ) { const UniformRegInfo* info = s_renderD3D12->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); @@ -4460,7 +4827,7 @@ namespace bgfx { namespace d3d12 BX_TRACE("\t%s: %s (%s), num %2d, r.index %3d, r.count %2d" , kind , name - , getUniformTypeName(UniformType::Enum(type&~BGFX_UNIFORM_MASK) ) + , getUniformTypeName(UniformType::Enum(type&~kUniformMask) ) , num , regIndex , regCount @@ -4475,7 +4842,7 @@ namespace bgfx { namespace d3d12 } uint32_t shaderSize; - bx::read(&reader, shaderSize); + bx::read(&reader, shaderSize, &err); const void* code = reader.getDataPtr(); bx::skip(&reader, shaderSize+1); @@ -4483,14 +4850,14 @@ namespace bgfx { namespace d3d12 m_code = copy(code, shaderSize); uint8_t numAttrs = 0; - bx::read(&reader, numAttrs); + bx::read(&reader, numAttrs, &err); bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); for (uint32_t ii = 0; ii < numAttrs; ++ii) { uint16_t id; - bx::read(&reader, id); + bx::read(&reader, id, &err); Attrib::Enum attr = idToAttrib(id); @@ -4509,7 +4876,145 @@ namespace bgfx { namespace d3d12 murmur.add(m_attrMask, numAttrs); m_hash = murmur.end(); - bx::read(&reader, m_size); + bx::read(&reader, m_size, &err); + } + + static void memcpySubresource( + const D3D12_MEMCPY_DEST* _dst + , const D3D12_SUBRESOURCE_DATA* _src + , uint64_t _rowSizeInBytes + , uint32_t _numRows + , uint32_t _numSlices + ) + { + for (uint32_t zz = 0; zz < _numSlices; ++zz) + { + uint8_t* _dstSlice = ( uint8_t*)(_dst->pData) + _dst->SlicePitch * zz; + const uint8_t* _srcSlice = (const uint8_t*)(_src->pData) + _src->SlicePitch * zz; + for (uint32_t yy = 0; yy < _numRows; ++yy) + { + bx::memCopy( + _dstSlice + _dst->RowPitch * yy + , _srcSlice + _src->RowPitch * yy + , size_t(_rowSizeInBytes) + ); + } + } + } + + static uint64_t updateSubresources( + ID3D12GraphicsCommandList* _commandList + , ID3D12Resource* _dstResource + , ID3D12Resource* _intermediate + , uint32_t _firstSubresource + , uint32_t _numSubresources + , uint64_t _requiredSize + , const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* _layouts + , const uint32_t* _numRows + , const uint64_t* _rowSizesInBytes + , const D3D12_SUBRESOURCE_DATA* _srcData + ) + { + uint8_t* data; + DX_CHECK(_intermediate->Map(0, NULL, (void**)&data) ); + + for (uint32_t ii = 0; ii < _numSubresources; ++ii) + { + D3D12_MEMCPY_DEST dstData = + { + data + _layouts[ii].Offset, + _layouts[ii].Footprint.RowPitch, + _layouts[ii].Footprint.RowPitch * _numRows[ii], + }; + + memcpySubresource( + &dstData + , &_srcData[ii] + , _rowSizesInBytes[ii] + , _numRows[ii] + , _layouts[ii].Footprint.Depth + ); + } + + _intermediate->Unmap(0, NULL); + + D3D12_RESOURCE_DESC dstDesc = getResourceDesc(_dstResource); + if (dstDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) + { + _commandList->CopyBufferRegion( + _dstResource + , 0 + , _intermediate + , _layouts[0].Offset + , _layouts[0].Footprint.Width + ); + } + else + { + for (uint32_t i = 0; i < _numSubresources; ++i) + { + D3D12_TEXTURE_COPY_LOCATION src; + src.pResource = _intermediate; + src.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT; + src.PlacedFootprint = _layouts[i]; + + D3D12_TEXTURE_COPY_LOCATION dst; + dst.pResource = _dstResource; + dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + dst.SubresourceIndex = i + _firstSubresource; + + _commandList->CopyTextureRegion(&dst, 0, 0, 0, &src, NULL); + } + } + + return _requiredSize; + } + + static uint64_t updateSubresources( + ID3D12GraphicsCommandList* _commandList + , ID3D12Resource* _dstResource + , ID3D12Resource* _intermediate + , uint64_t _intermediateOffset + , uint32_t _firstSubresource + , uint32_t _numSubresources + , D3D12_SUBRESOURCE_DATA* _srcData + ) + { + uint64_t requiredSize = 0; + + const size_t sizeInBytes = size_t(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(uint32_t) + sizeof(uint64_t) ) * _numSubresources; + D3D12_PLACED_SUBRESOURCE_FOOTPRINT* layouts = (D3D12_PLACED_SUBRESOURCE_FOOTPRINT*)BX_ALLOC(g_allocator, sizeInBytes); + uint64_t* rowSizesInBytes = (uint64_t*)(layouts + _numSubresources); + uint32_t* numRows = (uint32_t*)(rowSizesInBytes + _numSubresources); + + D3D12_RESOURCE_DESC desc = getResourceDesc(_dstResource); + s_renderD3D12->m_device->GetCopyableFootprints( + &desc + , _firstSubresource + , _numSubresources + , _intermediateOffset + , layouts + , numRows + , rowSizesInBytes + , &requiredSize + ); + + const uint64_t result = updateSubresources( + _commandList + , _dstResource + , _intermediate + , _firstSubresource + , _numSubresources + , requiredSize + , layouts + , numRows + , rowSizesInBytes + , _srcData + ); + + BX_FREE(g_allocator, layouts); + + return result; } void* TextureD3D12::create(const Memory* _mem, uint64_t _flags, uint8_t _skip) @@ -4518,18 +5023,27 @@ namespace bgfx { namespace d3d12 if (bimg::imageParse(imageContainer, _mem->data, _mem->size) ) { - uint8_t numMips = imageContainer.m_numMips; - const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); - numMips -= startLod; const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(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); - const uint16_t numLayers = imageContainer.m_numLayers; - - m_flags = _flags; - m_width = textureWidth; - m_height = textureHeight; - m_depth = imageContainer.m_depth; + const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips-1); + + bimg::TextureInfo ti; + bimg::imageGetSize( + &ti + , uint16_t(imageContainer.m_width >>startLod) + , uint16_t(imageContainer.m_height>>startLod) + , uint16_t(imageContainer.m_depth >>startLod) + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + , imageContainer.m_numLayers + , imageContainer.m_format + ); + ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips-startLod, ti.numMips); + + m_flags = _flags; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numLayers = ti.numLayers; m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -4548,9 +5062,9 @@ namespace bgfx { namespace d3d12 m_type = Texture2D; } - m_numMips = numMips; - const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); - const uint32_t numSrd = numSides * numMips; + m_numMips = ti.numMips; + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * ti.numMips; D3D12_SUBRESOURCE_DATA* srd = (D3D12_SUBRESOURCE_DATA*)alloca(numSrd*sizeof(D3D12_SUBRESOURCE_DATA) ); uint32_t kk = 0; @@ -4563,12 +5077,21 @@ namespace bgfx { namespace d3d12 const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK); const bool blit = 0 != (m_flags&BGFX_TEXTURE_BLIT_DST); + const uint32_t msaaQuality = bx::uint32_satsub((m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT, 1); + const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; + + const bool needResolve = true + && 1 < msaa.Count + && 0 == (m_flags & BGFX_TEXTURE_MSAA_SAMPLE) + && !writeOnly + ; + BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s RT[%c], BO[%c], CW[%c]%s." , this - s_renderD3D12->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) - , textureWidth - , textureHeight + , ti.width + , ti.height , imageContainer.m_cubeMap ? "x6" : "" , renderTarget ? 'x' : ' ' , writeOnly ? 'x' : ' ' @@ -4578,7 +5101,7 @@ namespace bgfx { namespace d3d12 for (uint8_t side = 0; side < numSides; ++side) { - for (uint8_t lod = 0; lod < numMips; ++lod) + for (uint8_t lod = 0; lod < ti.numMips; ++lod) { bimg::ImageMip mip; if (bimg::imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) ) @@ -4647,29 +5170,27 @@ namespace bgfx { namespace d3d12 } } - const uint32_t msaaQuality = bx::uint32_satsub( (m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); - const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; - + const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat]; bx::memSet(&m_srvd, 0, sizeof(m_srvd) ); - m_srvd.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; - m_srvd.Format = s_textureFormat[m_textureFormat].m_fmtSrv; - DXGI_FORMAT format = s_textureFormat[m_textureFormat].m_fmt; + m_srvd.Shader4ComponentMapping = tfi.m_mapping; + m_srvd.Format = (m_flags & BGFX_TEXTURE_SRGB) ? tfi.m_fmtSrgb : tfi.m_fmtSrv; + m_uavd.Format = tfi.m_fmtSrv; + DXGI_FORMAT format = tfi.m_fmt; if (swizzle) { format = DXGI_FORMAT_R8G8B8A8_UNORM; m_srvd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + m_uavd.Format = DXGI_FORMAT_R8G8B8A8_UNORM; } - m_uavd.Format = m_srvd.Format; - ID3D12Device* device = s_renderD3D12->m_device; ID3D12GraphicsCommandList* commandList = s_renderD3D12->m_commandList; D3D12_RESOURCE_DESC resourceDesc; resourceDesc.Alignment = 1 < msaa.Count ? D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT : 0; - resourceDesc.Width = textureWidth; - resourceDesc.Height = textureHeight; - resourceDesc.MipLevels = numMips; + resourceDesc.Width = ti.width; + resourceDesc.Height = ti.height; + resourceDesc.MipLevels = ti.numMips; resourceDesc.Format = format; resourceDesc.SampleDesc = msaa; resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; @@ -4680,13 +5201,13 @@ namespace bgfx { namespace d3d12 D3D12_CLEAR_VALUE* clearValue = NULL; if (bimg::isDepth(bimg::TextureFormat::Enum(m_textureFormat) ) ) { - resourceDesc.Format = s_textureFormat[m_textureFormat].m_fmt; + resourceDesc.Format = tfi.m_fmt; resourceDesc.Flags |= D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; state |= D3D12_RESOURCE_STATE_DEPTH_WRITE; state &= ~D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; clearValue = (D3D12_CLEAR_VALUE*)alloca(sizeof(D3D12_CLEAR_VALUE) ); - clearValue->Format = s_textureFormat[m_textureFormat].m_fmtDsv; + clearValue->Format = tfi.m_fmtDsv; clearValue->DepthStencil.Depth = 1.0f; clearValue->DepthStencil.Stencil = 0; } @@ -4730,56 +5251,50 @@ namespace bgfx { namespace d3d12 switch (m_type) { case Texture2D: - case TextureCube: resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; - if (imageContainer.m_cubeMap) + + if (1 < ti.numLayers) { - if (1 < numLayers) + if (1 < msaa.Count && !needResolve) { - m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY; - m_srvd.TextureCubeArray.MostDetailedMip = 0; - m_srvd.TextureCubeArray.MipLevels = numMips; - m_srvd.TextureCubeArray.ResourceMinLODClamp = 0.0f; - m_srvd.TextureCubeArray.NumCubes = numLayers; + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY; + m_srvd.Texture2DMSArray.FirstArraySlice = 0; + m_srvd.Texture2DMSArray.ArraySize = ti.numLayers; } else { - m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; - m_srvd.TextureCube.MostDetailedMip = 0; - m_srvd.TextureCube.MipLevels = numMips; - m_srvd.TextureCube.ResourceMinLODClamp = 0.0f; + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY; + m_srvd.Texture2DArray.MostDetailedMip = 0; + m_srvd.Texture2DArray.MipLevels = ti.numMips; + m_srvd.Texture2DArray.FirstArraySlice = 0; + m_srvd.Texture2DArray.ArraySize = ti.numLayers; + m_srvd.Texture2DArray.PlaneSlice = 0; + m_srvd.Texture2DArray.ResourceMinLODClamp = 0.0f; } } else { - if (1 < numLayers) + if (1 < msaa.Count && !needResolve) { - m_srvd.ViewDimension = 1 < msaa.Count - ? D3D12_SRV_DIMENSION_TEXTURE2DMSARRAY - : D3D12_SRV_DIMENSION_TEXTURE2DARRAY - ; - m_srvd.Texture2DArray.MostDetailedMip = 0; - m_srvd.Texture2DArray.MipLevels = numMips; - m_srvd.Texture2DArray.ResourceMinLODClamp = 0.0f; - m_srvd.Texture2DArray.ArraySize = numLayers; + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DMS; } else { - m_srvd.ViewDimension = 1 < msaa.Count - ? D3D12_SRV_DIMENSION_TEXTURE2DMS - : D3D12_SRV_DIMENSION_TEXTURE2D - ; + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; m_srvd.Texture2D.MostDetailedMip = 0; - m_srvd.Texture2D.MipLevels = numMips; + m_srvd.Texture2D.MipLevels = ti.numMips; + m_srvd.Texture2D.PlaneSlice = 0; m_srvd.Texture2D.ResourceMinLODClamp = 0.0f; } } - if (1 < numLayers) + if (1 < ti.numLayers) { m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; - m_uavd.Texture2DArray.MipSlice = 0; - m_uavd.Texture2DArray.PlaneSlice = 0; + m_uavd.Texture2DArray.MipSlice = 0; + m_uavd.Texture2DArray.FirstArraySlice = 0; + m_uavd.Texture2DArray.ArraySize = ti.numLayers; + m_uavd.Texture2DArray.PlaneSlice = 0; } else { @@ -4787,14 +5302,6 @@ namespace bgfx { namespace d3d12 m_uavd.Texture2D.MipSlice = 0; m_uavd.Texture2D.PlaneSlice = 0; } - - if (TextureCube == m_type) - { - m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; - m_uavd.Texture2DArray.MipSlice = 0; - m_uavd.Texture2DArray.ArraySize = 6; - } - break; case Texture3D: @@ -4802,13 +5309,39 @@ namespace bgfx { namespace d3d12 resourceDesc.DepthOrArraySize = uint16_t(m_depth); m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; m_srvd.Texture3D.MostDetailedMip = 0; - m_srvd.Texture3D.MipLevels = numMips; + m_srvd.Texture3D.MipLevels = ti.numMips; m_srvd.Texture3D.ResourceMinLODClamp = 0.0f; m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; m_uavd.Texture3D.MipSlice = 0; m_uavd.Texture3D.FirstWSlice = 0; - m_uavd.Texture3D.WSize = 0; + m_uavd.Texture3D.WSize = m_depth; + break; + + case TextureCube: + resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + + if (1 < ti.numLayers) + { + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBEARRAY; + m_srvd.TextureCubeArray.MostDetailedMip = 0; + m_srvd.TextureCubeArray.MipLevels = ti.numMips; + m_srvd.TextureCubeArray.ResourceMinLODClamp = 0.0f; + m_srvd.TextureCubeArray.NumCubes = ti.numLayers; + } + else + { + m_srvd.ViewDimension = D3D12_SRV_DIMENSION_TEXTURECUBE; + m_srvd.TextureCube.MostDetailedMip = 0; + m_srvd.TextureCube.MipLevels = ti.numMips; + m_srvd.TextureCube.ResourceMinLODClamp = 0.0f; + } + + m_uavd.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; + m_uavd.Texture2DArray.MipSlice = 0; + m_uavd.Texture2DArray.FirstArraySlice = 0; + m_uavd.Texture2DArray.ArraySize = 6; + m_uavd.Texture2DArray.PlaneSlice = 0; break; } @@ -4828,7 +5361,7 @@ namespace bgfx { namespace d3d12 setState(commandList, D3D12_RESOURCE_STATE_COPY_DEST); - uint64_t result = UpdateSubresources(commandList + uint64_t result = updateSubresources(commandList , m_ptr , staging , 0 @@ -4836,7 +5369,7 @@ namespace bgfx { namespace d3d12 , numSrd , srd ); - BX_CHECK(0 != result, "Invalid size"); BX_UNUSED(result); + BX_ASSERT(0 != result, "Invalid size"); BX_UNUSED(result); BX_TRACE("Update subresource %" PRId64, result); setState(commandList, state); @@ -4853,13 +5386,30 @@ namespace bgfx { namespace d3d12 kk = 0; for (uint8_t side = 0; side < numSides; ++side) { - for (uint32_t lod = 0, num = numMips; lod < num; ++lod) + for (uint32_t lod = 0, num = ti.numMips; lod < num; ++lod) { BX_FREE(g_allocator, const_cast<void*>(srd[kk].pData) ); ++kk; } } } + + if (needResolve) + { + D3D12_RESOURCE_DESC rd = resourceDesc; + + rd.Alignment = 0; + rd.SampleDesc = s_msaa[0]; + rd.Flags &= ~(D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL); + + m_singleMsaa = createCommittedResource(device, HeapProperty::Texture, &rd, NULL); + + setResourceBarrier(commandList + , m_singleMsaa + , D3D12_RESOURCE_STATE_COMMON + , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE + ); + } } return m_directAccessPtr; @@ -4876,30 +5426,86 @@ namespace bgfx { namespace d3d12 m_directAccessPtr = NULL; } - s_renderD3D12->m_cmd.release(m_ptr); - m_ptr = NULL; - m_state = D3D12_RESOURCE_STATE_COMMON; + if (0 == (m_flags & BGFX_SAMPLER_INTERNAL_SHARED)) + { + s_renderD3D12->m_cmd.release(m_ptr); + m_ptr = NULL; + m_state = D3D12_RESOURCE_STATE_COMMON; + + if (NULL != m_singleMsaa) + { + s_renderD3D12->m_cmd.release(m_singleMsaa); + m_singleMsaa = NULL; + } + } } } + void TextureD3D12::overrideInternal(uintptr_t _ptr) + { + destroy(); + m_flags |= BGFX_SAMPLER_INTERNAL_SHARED; + m_ptr = (ID3D12Resource*)_ptr; + } + void TextureD3D12::update(ID3D12GraphicsCommandList* _commandList, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) { D3D12_RESOURCE_STATES state = setState(_commandList, D3D12_RESOURCE_STATE_COPY_DEST); const uint32_t subres = _mip + (_side * m_numMips); const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); - const uint32_t rectpitch = _rect.m_width*bpp/8; - const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; + uint32_t rectpitch = _rect.m_width*bpp/8; + if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat))) + { + const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat)); + rectpitch = (_rect.m_width / blockInfo.blockWidth) * blockInfo.blockSize; + } + + const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; + const uint32_t slicepitch = rectpitch*_rect.m_height; + + const bool convert = m_textureFormat != m_requestedFormat; + + D3D12_BOX box; + box.left = 0; + box.top = 0; + box.right = box.left + _rect.m_width; + box.bottom = box.top + _rect.m_height; + + if (TextureD3D12::Texture3D == m_type) + { + box.front = _z; + box.back = box.front + _depth; + } + else + { + box.front = 0; + box.back = 1; + } + + uint8_t* srcData = _mem->data; + uint8_t* temp = NULL; + + if (convert) + { + temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch); + bimg::imageDecodeToBgra8(g_allocator, temp, srcData, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat)); + srcData = temp; + + box.right = bx::max(1u, m_width >> _mip); + box.bottom = bx::max(1u, m_height >> _mip); + } D3D12_RESOURCE_DESC desc = getResourceDesc(m_ptr); + desc.Width = _rect.m_width; desc.Height = _rect.m_height; uint32_t numRows; uint64_t totalBytes; D3D12_PLACED_SUBRESOURCE_FOOTPRINT layout; s_renderD3D12->m_device->GetCopyableFootprints(&desc - , subres + , 0 , 1 , 0 , &layout @@ -4911,24 +5517,23 @@ namespace bgfx { namespace d3d12 const uint32_t rowPitch = layout.Footprint.RowPitch; ID3D12Resource* staging = createCommittedResource(s_renderD3D12->m_device, HeapProperty::Upload, totalBytes); - uint8_t* data; + uint8_t* dstData; D3D12_RANGE readRange = { 0, 0 }; - DX_CHECK(staging->Map(0, &readRange, (void**)&data) ); - for (uint32_t ii = 0, height = _rect.m_height; ii < height; ++ii) + DX_CHECK(staging->Map(0, &readRange, (void**)&dstData) ); + + for (uint32_t ii = 0, height = numRows; ii < height; ++ii) { - bx::memCopy(&data[ii*rowPitch], &_mem->data[ii*srcpitch], srcpitch); + bx::memCopy(&dstData[ii*rowPitch], &srcData[ii*srcpitch], srcpitch); } - D3D12_RANGE writeRange = { 0, _rect.m_height*srcpitch }; - staging->Unmap(0, &writeRange); - D3D12_BOX box; - box.left = 0; - box.top = 0; - box.right = box.left + _rect.m_width; - box.bottom = box.top + _rect.m_height; - box.front = _z; - box.back = _z+_depth; + if (NULL != temp) + { + BX_FREE(g_allocator, temp); + } + + D3D12_RANGE writeRange = { 0, numRows*rowPitch }; + staging->Unmap(0, &writeRange); D3D12_TEXTURE_COPY_LOCATION dst = { m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { } }; dst.SubresourceIndex = subres; @@ -4940,9 +5545,41 @@ namespace bgfx { namespace d3d12 s_renderD3D12->m_cmd.release(staging); } - void TextureD3D12::resolve(uint8_t _resolve) const + void TextureD3D12::resolve(ID3D12GraphicsCommandList* _commandList, uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip) { BX_UNUSED(_resolve); + + bool needResolve = NULL != m_singleMsaa; + if (needResolve) + { + D3D12_RESOURCE_STATES state = setState(_commandList, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); + + setResourceBarrier(_commandList + , m_singleMsaa + , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE + , D3D12_RESOURCE_STATE_RESOLVE_DEST + ); + + for (uint32_t ii = _layer; ii < _numLayers; ++ii) + { + const uint32_t resource = _mip + (ii * m_numMips); + + _commandList->ResolveSubresource(m_singleMsaa + , resource + , m_ptr + , resource + , s_textureFormat[m_textureFormat].m_fmt + ); + } + + setResourceBarrier(_commandList + , m_singleMsaa + , D3D12_RESOURCE_STATE_RESOLVE_DEST + , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE + ); + + setState(_commandList, state); + } } D3D12_RESOURCE_STATES TextureD3D12::setState(ID3D12GraphicsCommandList* _commandList, D3D12_RESOURCE_STATES _state) @@ -4972,15 +5609,16 @@ namespace bgfx { namespace d3d12 void FrameBufferD3D12::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { - BX_UNUSED(_nwh, _width, _height, _depthFormat); + BX_UNUSED(_nwh, _width, _height, _format, _depthFormat); #if BX_PLATFORM_WINDOWS SwapChainDesc scd; - bx::memCopy(&scd, &s_renderD3D12->m_scd, sizeof(DXGI_SWAP_CHAIN_DESC) ); - scd.format = TextureFormat::Count == _format ? scd.format : s_textureFormat[_format].m_fmt; - scd.width = _width; - scd.height = _height; - scd.nwh = _nwh; + bx::memCopy(&scd, &s_renderD3D12->m_scd, sizeof(SwapChainDesc) ); + scd.format = TextureFormat::Count == _format ? scd.format : s_textureFormat[_format].m_fmt; + scd.width = _width; + scd.height = _height; + scd.nwh = _nwh; + scd.sampleDesc = s_msaa[0]; HRESULT hr; hr = s_renderD3D12->m_dxgi.createSwapChain( @@ -5083,9 +5721,12 @@ namespace bgfx { namespace d3d12 m_height = uint32_t(desc.Height); } + const uint32_t msaaQuality = bx::uint32_satsub((texture.m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT, 1); + const DXGI_SAMPLE_DESC& msaa = s_msaa[msaaQuality]; + if (bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) ) { - BX_CHECK(!isValid(m_depth), ""); + BX_ASSERT(!isValid(m_depth), ""); m_depth = at.handle; D3D12_CPU_DESCRIPTOR_HANDLE dsvDescriptor = getCPUHandleHeapStart(s_renderD3D12->m_dsvDescriptorHeap); uint32_t dsvDescriptorSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV); @@ -5097,25 +5738,66 @@ namespace bgfx { namespace d3d12 D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc; bx::memSet(&dsvDesc, 0, sizeof(dsvDesc) ); dsvDesc.Format = s_textureFormat[texture.m_textureFormat].m_fmtDsv; - dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; dsvDesc.Flags = D3D12_DSV_FLAG_NONE // | (blockInfo.depthBits > 0 ? D3D12_DSV_FLAG_READ_ONLY_DEPTH : D3D12_DSV_FLAG_NONE) // | (blockInfo.stencilBits > 0 ? D3D12_DSV_FLAG_READ_ONLY_STENCIL : D3D12_DSV_FLAG_NONE) ; + switch (texture.m_type) + { + default: + case TextureD3D12::Texture2D: + if (1 < msaa.Count) + { + if (1 < texture.m_numLayers) + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY; + dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; + } + else + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMS; + } + } + else + { + if (1 < texture.m_numLayers) + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY; + dsvDesc.Texture2DArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; + dsvDesc.Texture2DArray.MipSlice = at.mip; + } + else + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D; + dsvDesc.Texture2D.MipSlice = at.mip; + } + } + break; + + case TextureD3D12::TextureCube: + if (1 < msaa.Count) + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY; + dsvDesc.Texture2DMSArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DMSArray.ArraySize = at.numLayers; + } + else + { + dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DARRAY; + dsvDesc.Texture2DArray.FirstArraySlice = at.layer; + dsvDesc.Texture2DArray.ArraySize = at.numLayers; + dsvDesc.Texture2DArray.MipSlice = at.mip; + } + break; + } + device->CreateDepthStencilView(texture.m_ptr , &dsvDesc , dsvDescriptor ); - - s_renderD3D12->m_commandList->ClearDepthStencilView( - dsvDescriptor - , D3D12_CLEAR_FLAG_DEPTH|D3D12_CLEAR_FLAG_STENCIL - , 0.0f - , 0 - , 0 - , NULL - ); } else if (Access::Write == at.access) { @@ -5129,30 +5811,50 @@ namespace bgfx { namespace d3d12 { default: case TextureD3D12::Texture2D: -// if (1 < msaa.Count) -// { -// desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMS; -// } -// else + if (1 < msaa.Count) { - desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; - desc.Texture2D.MipSlice = at.mip; - desc.Texture2D.PlaneSlice = 0; + if (1 < texture.m_numLayers) + { + desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; + desc.Texture2DMSArray.FirstArraySlice = at.layer; + desc.Texture2DMSArray.ArraySize = at.numLayers; + } + else + { + desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMS; + } + } + else + { + if (1 < texture.m_numLayers) + { + desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; + desc.Texture2DArray.FirstArraySlice = at.layer; + desc.Texture2DArray.ArraySize = at.numLayers; + desc.Texture2DArray.MipSlice = at.mip; + desc.Texture2DArray.PlaneSlice = 0; + } + else + { + desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D; + desc.Texture2D.MipSlice = at.mip; + desc.Texture2D.PlaneSlice = 0; + } } break; case TextureD3D12::TextureCube: -// if (1 < msaa.Count) -// { -// desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; -// desc.Texture2DMSArray.ArraySize = 1; -// desc.Texture2DMSArray.FirstArraySlice = at.layer; -// } -// else + if (1 < msaa.Count) + { + desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY; + desc.Texture2DMSArray.FirstArraySlice = at.layer; + desc.Texture2DMSArray.ArraySize = at.numLayers; + } + else { desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; - desc.Texture2DArray.ArraySize = 1; desc.Texture2DArray.FirstArraySlice = at.layer; + desc.Texture2DArray.ArraySize = at.numLayers; desc.Texture2DArray.MipSlice = at.mip; desc.Texture2DArray.PlaneSlice = 0; } @@ -5160,9 +5862,9 @@ namespace bgfx { namespace d3d12 case TextureD3D12::Texture3D: desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE3D; - desc.Texture3D.MipSlice = at.mip; - desc.Texture3D.WSize = 1; + desc.Texture3D.MipSlice = at.mip; desc.Texture3D.FirstWSlice = at.layer; + desc.Texture3D.WSize = at.numLayers; break; } @@ -5171,19 +5873,11 @@ namespace bgfx { namespace d3d12 , rtv ); - float rgba[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - s_renderD3D12->m_commandList->ClearRenderTargetView( - rtv - , rgba - , 0 - , NULL - ); - m_num++; } else { - BX_CHECK(false, ""); + BX_ASSERT(false, ""); } } } @@ -5200,8 +5894,8 @@ namespace bgfx { namespace d3d12 if (isValid(at.handle) ) { - const TextureD3D12& texture = s_renderD3D12->m_textures[at.handle.idx]; - texture.resolve(at.resolve); + TextureD3D12& texture = s_renderD3D12->m_textures[at.handle.idx]; + texture.resolve(s_renderD3D12->m_commandList, at.resolve, at.layer, at.numLayers, at.mip); } } } @@ -5339,7 +6033,7 @@ namespace bgfx { namespace d3d12 DX_RELEASE(m_readback, 0); } - uint32_t TimerQueryD3D12::begin(uint32_t _resultIdx) + uint32_t TimerQueryD3D12::begin(uint32_t _resultIdx, uint32_t _frameNum) { while (0 == m_control.reserve(1) ) { @@ -5353,6 +6047,7 @@ namespace bgfx { namespace d3d12 Query& query = m_query[idx]; query.m_resultIdx = _resultIdx; query.m_ready = false; + query.m_frameNum = _frameNum; ID3D12GraphicsCommandList* commandList = s_renderD3D12->m_commandList; @@ -5414,6 +6109,7 @@ namespace bgfx { namespace d3d12 Result& result = m_result[query.m_resultIdx]; --result.m_pending; + result.m_frameNum = query.m_frameNum; uint32_t offset = idx * 2; result.m_begin = m_queryResult[offset+0]; @@ -5520,7 +6216,7 @@ namespace bgfx { namespace d3d12 { const BlitItem& blit = _bs.advance(); - TextureD3D12& src = m_textures[blit.m_src.idx]; + TextureD3D12& src = m_textures[blit.m_src.idx]; const TextureD3D12& dst = m_textures[blit.m_dst.idx]; if (currentSrc.idx != blit.m_src.idx) @@ -5530,33 +6226,40 @@ namespace bgfx { namespace d3d12 m_textures[currentSrc.idx].setState(m_commandList, state); } - currentSrc = blit.m_src; + currentSrc = blit.m_src.to<TextureHandle>(); + + if (NULL != src.m_singleMsaa) + { + setResourceBarrier(m_commandList + , src.m_singleMsaa + , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE + , D3D12_RESOURCE_STATE_COPY_SOURCE + ); + } state = src.setState(m_commandList, D3D12_RESOURCE_STATE_COPY_SOURCE); } - uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX; - uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY; - uint32_t srcDepth = bx::uint32_min(src.m_depth, blit.m_srcZ + blit.m_depth) - blit.m_srcZ; - uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX; - uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY; - uint32_t dstDepth = bx::uint32_min(dst.m_depth, blit.m_dstZ + blit.m_depth) - blit.m_dstZ; - uint32_t width = bx::uint32_min(srcWidth, dstWidth); - uint32_t height = bx::uint32_min(srcHeight, dstHeight); - uint32_t depth = bx::uint32_min(srcDepth, dstDepth); - if (TextureD3D12::Texture3D == src.m_type) { D3D12_BOX box; - box.left = blit.m_srcX; - box.top = blit.m_srcY; - box.front = blit.m_srcZ; - box.right = blit.m_srcX + width; - box.bottom = blit.m_srcY + height;; - box.back = blit.m_srcZ + bx::uint32_imax(1, depth); - - D3D12_TEXTURE_COPY_LOCATION dstLocation = { dst.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { { 0, { DXGI_FORMAT_UNKNOWN, 0, 0, 0, 0 } } } }; - D3D12_TEXTURE_COPY_LOCATION srcLocation = { src.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { { 0, { DXGI_FORMAT_UNKNOWN, 0, 0, 0, 0 } } } }; + box.left = blit.m_srcX; + box.top = blit.m_srcY; + box.front = blit.m_srcZ; + box.right = blit.m_srcX + blit.m_width; + box.bottom = blit.m_srcY + blit.m_height; + box.back = blit.m_srcZ + bx::uint32_imax(1, blit.m_depth); + + D3D12_TEXTURE_COPY_LOCATION dstLocation; + dstLocation.pResource = dst.m_ptr; + dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + dstLocation.SubresourceIndex = blit.m_dstMip; + + D3D12_TEXTURE_COPY_LOCATION srcLocation; + srcLocation.pResource = src.m_ptr; + srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; + srcLocation.SubresourceIndex = blit.m_srcMip; + m_commandList->CopyTextureRegion(&dstLocation , blit.m_dstX , blit.m_dstY @@ -5571,8 +6274,8 @@ namespace bgfx { namespace d3d12 box.left = blit.m_srcX; box.top = blit.m_srcY; box.front = 0; - box.right = blit.m_srcX + width; - box.bottom = blit.m_srcY + height;; + box.right = blit.m_srcX + blit.m_width; + box.bottom = blit.m_srcY + blit.m_height; box.back = 1; const uint32_t srcZ = TextureD3D12::TextureCube == src.m_type @@ -5588,13 +6291,16 @@ namespace bgfx { namespace d3d12 dstLocation.pResource = dst.m_ptr; dstLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; dstLocation.SubresourceIndex = dstZ*dst.m_numMips+blit.m_dstMip; + D3D12_TEXTURE_COPY_LOCATION srcLocation; - srcLocation.pResource = src.m_ptr; + srcLocation.pResource = NULL != src.m_singleMsaa ? src.m_singleMsaa : src.m_ptr; srcLocation.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX; srcLocation.SubresourceIndex = srcZ*src.m_numMips+blit.m_srcMip; - bool depthStencil = bimg::isDepth(bimg::TextureFormat::Enum(src.m_textureFormat) ); - m_commandList->CopyTextureRegion(&dstLocation + const bool depthStencil = bimg::isDepth(bimg::TextureFormat::Enum(src.m_textureFormat) ); + + m_commandList->CopyTextureRegion( + &dstLocation , blit.m_dstX , blit.m_dstY , 0 @@ -5602,6 +6308,16 @@ namespace bgfx { namespace d3d12 , depthStencil ? NULL : &box ); } + + if (NULL != src.m_singleMsaa) + { + setResourceBarrier( + m_commandList + , src.m_singleMsaa + , D3D12_RESOURCE_STATE_COPY_SOURCE + , D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE + ); + } } if (isValid(currentSrc) @@ -5613,8 +6329,6 @@ namespace bgfx { namespace d3d12 void RendererContextD3D12::submit(Frame* _render, ClearQuad& /*_clearQuad*/, TextVideoMemBlitter& _textVideoMemBlitter) { - PIX3_BEGINEVENT(m_commandList, D3DCOLOR_FRAME, "rendererSubmit"); - if (m_lost || updateResolution(_render->m_resolution) ) { @@ -5626,19 +6340,23 @@ namespace bgfx { namespace d3d12 renderDocTriggerCapture(); } + BGFX_D3D12_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorFrame); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; - uint32_t frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS); + uint32_t frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS, _render->m_frameNum); if (0 < _render->m_iboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource); TransientIndexBuffer* ib = _render->m_transientIb; m_indexBuffers[ib->handle.idx].update(m_commandList, 0, _render->m_iboffset, ib->data); } if (0 < _render->m_vboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource); TransientVertexBuffer* vb = _render->m_transientVb; m_vertexBuffers[vb->handle.idx].update(m_commandList, 0, _render->m_vboffset, vb->data); } @@ -5653,15 +6371,14 @@ namespace bgfx { namespace d3d12 RenderBind currentBind; currentBind.clear(); - const bool hmdEnabled = false; static ViewState viewState; - viewState.reset(_render, hmdEnabled); + viewState.reset(_render); // bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); // setDebugWireframe(wireframe); uint16_t currentSamplerStateIdx = kInvalidHandle; - uint16_t currentProgramIdx = kInvalidHandle; + ProgramHandle currentProgram = BGFX_INVALID_HANDLE; uint32_t currentBindHash = 0; bool hasPredefined = false; bool commandListChanged = false; @@ -5753,12 +6470,10 @@ namespace bgfx { namespace d3d12 m_batch.begin(); -// uint8_t eye = 0; -// uint8_t restartState = 0; viewState.m_rect = _render->m_view[0].m_rect; - int32_t numItems = _render->m_numRenderItems; - for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;) + + for (int32_t item = 0; item < numItems;) { const uint64_t encodedKey = _render->m_sortKeys[item]; const bool isCompute = key.decode(encodedKey, _render->m_viewRemap); @@ -5784,19 +6499,23 @@ namespace bgfx { namespace d3d12 view = key.m_view; currentPso = NULL; currentSamplerStateIdx = kInvalidHandle; - currentProgramIdx = kInvalidHandle; + currentProgram = BGFX_INVALID_HANDLE; hasPredefined = false; - fbh = _render->m_view[view].m_fbh; - setFrameBuffer(fbh); - if (item > 1) { profiler.end(); } + BGFX_D3D12_PROFILER_END(); + setViewType(view, " "); + BGFX_D3D12_PROFILER_BEGIN(view, kColorView); + profiler.begin(view); + fbh = _render->m_view[view].m_fbh; + setFrameBuffer(fbh); + viewState.m_rect = _render->m_view[view].m_rect; const Rect& rect = _render->m_view[view].m_rect; const Rect& scissorRect = _render->m_view[view].m_scissor; @@ -5839,13 +6558,9 @@ namespace bgfx { namespace d3d12 { wasCompute = true; - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - char* viewName = s_viewName[view]; - viewName[3] = L'C'; - PIX3_ENDEVENT(m_commandList); - PIX3_BEGINEVENT(m_commandList, D3DCOLOR_COMPUTE, viewName); - } + setViewType(view, "C"); + BGFX_D3D12_PROFILER_END(); + BGFX_D3D12_PROFILER_BEGIN(view, kColorCompute); commandListChanged = true; } @@ -5880,92 +6595,94 @@ namespace bgfx { namespace d3d12 Bind* bindCached = bindLru.find(bindHash); if (NULL == bindCached) { + uint32_t numSet = 0; D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_MAX_COMPUTE_BINDINGS] = {}; uint32_t samplerFlags[BGFX_MAX_COMPUTE_BINDINGS] = {}; - - for (uint8_t stage = 0; stage < maxComputeBindings; ++stage) { - const Binding& bind = renderBind.m_bind[stage]; - if (kInvalidHandle != bind.m_idx) + for (uint8_t stage = 0; stage < maxComputeBindings; ++stage) { - switch (bind.m_type) + const Binding& bind = renderBind.m_bind[stage]; + if (kInvalidHandle != bind.m_idx) { - case Binding::Image: + switch (bind.m_type) { - TextureD3D12& texture = m_textures[bind.m_idx]; - - if (Access::Read != bind.m_access) + case Binding::Image: { - texture.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); - scratchBuffer.allocUav(srvHandle[stage], texture, bind.m_mip); + TextureD3D12& texture = m_textures[bind.m_idx]; + + if (Access::Read != bind.m_access) + { + texture.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + scratchBuffer.allocUav(srvHandle[stage], texture, bind.m_mip); + } + else + { + texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); + scratchBuffer.allocSrv(srvHandle[stage], texture, bind.m_mip); + samplerFlags[stage] = uint32_t(texture.m_flags); + } + + ++numSet; } - else + break; + + case Binding::Texture: { + TextureD3D12& texture = m_textures[bind.m_idx]; texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - scratchBuffer.allocSrv(srvHandle[stage], texture, bind.m_mip); - samplerFlags[stage] = uint32_t(texture.m_flags); + scratchBuffer.allocSrv(srvHandle[stage], texture); + samplerFlags[stage] = (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & bind.m_samplerFlags) + ? bind.m_samplerFlags + : texture.m_flags + ) & (BGFX_SAMPLER_BITS_MASK | BGFX_SAMPLER_BORDER_COLOR_MASK | BGFX_SAMPLER_COMPARE_MASK) + ; + + ++numSet; } - } - break; + break; - case Binding::Texture: - { - TextureD3D12& texture = m_textures[bind.m_idx]; - texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - scratchBuffer.allocSrv(srvHandle[stage], texture); - samplerFlags[stage] = (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & bind.m_samplerFlags) - ? bind.m_samplerFlags - : texture.m_flags - ) & (BGFX_SAMPLER_BITS_MASK | BGFX_SAMPLER_BORDER_COLOR_MASK | BGFX_SAMPLER_COMPARE_MASK) - ; - } - break; + case Binding::IndexBuffer: + case Binding::VertexBuffer: + { + BufferD3D12& buffer = Binding::IndexBuffer == bind.m_type + ? m_indexBuffers[bind.m_idx] + : m_vertexBuffers[bind.m_idx] + ; - case Binding::IndexBuffer: - case Binding::VertexBuffer: - { - BufferD3D12& buffer = Binding::IndexBuffer == bind.m_type - ? m_indexBuffers[bind.m_idx] - : m_vertexBuffers[bind.m_idx] - ; + if (Access::Read != bind.m_access) + { + buffer.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + scratchBuffer.allocUav(srvHandle[stage], buffer); + } + else + { + buffer.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); + scratchBuffer.allocSrv(srvHandle[stage], buffer); + } - if (Access::Read != bind.m_access) - { - buffer.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); - scratchBuffer.allocUav(srvHandle[stage], buffer); - } - else - { - buffer.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); - scratchBuffer.allocSrv(srvHandle[stage], buffer); + ++numSet; } + break; } - break; + } + else + { + samplerFlags[stage] = 0; + scratchBuffer.allocEmpty(srvHandle[stage]); } } - else + + if (0 != numSet) { - samplerFlags[stage] = 0; - scratchBuffer.allocEmpty(srvHandle[stage]); + Bind bind; + bind.m_srvHandle = srvHandle[0]; + bind.m_samplerStateIdx = getSamplerState(samplerFlags, maxComputeBindings, _render->m_colorPalette); + bindCached = bindLru.add(bindHash, bind, 0); } } - - uint16_t samplerStateIdx = getSamplerState(samplerFlags, maxComputeBindings, _render->m_colorPalette); - if (samplerStateIdx != currentSamplerStateIdx) - { - currentSamplerStateIdx = samplerStateIdx; - m_commandList->SetComputeRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); - } - - m_commandList->SetComputeRootDescriptorTable(Rdt::SRV, srvHandle[0]); - m_commandList->SetComputeRootDescriptorTable(Rdt::UAV, srvHandle[0]); - - Bind bind; - bind.m_srvHandle = srvHandle[0]; - bind.m_samplerStateIdx = samplerStateIdx; - bindLru.add(bindHash, bind, 0); } - else + + if (NULL != bindCached) { uint16_t samplerStateIdx = bindCached->m_samplerStateIdx; if (samplerStateIdx != currentSamplerStateIdx) @@ -5980,12 +6697,12 @@ namespace bgfx { namespace d3d12 bool constantsChanged = false; if (compute.m_uniformBegin < compute.m_uniformEnd - || currentProgramIdx != key.m_program) + || currentProgram.idx != key.m_program.idx) { rendererUpdateUniforms(this, _render->m_uniformBuffer[compute.m_uniformIdx], compute.m_uniformBegin, compute.m_uniformEnd); - currentProgramIdx = key.m_program; - ProgramD3D12& program = m_program[currentProgramIdx]; + currentProgram = key.m_program; + ProgramD3D12& program = m_program[currentProgram.idx]; UniformBuffer* vcb = program.m_vsh->m_constantBuffer; if (NULL != vcb) @@ -6000,8 +6717,8 @@ namespace bgfx { namespace d3d12 if (constantsChanged || hasPredefined) { - ProgramD3D12& program = m_program[currentProgramIdx]; - viewState.setPredefined<4>(this, view, 0, program, _render, compute); + ProgramD3D12& program = m_program[currentProgram.idx]; + viewState.setPredefined<4>(this, view, program, _render, compute); commitShaderConstants(key.m_program, gpuAddress); m_commandList->SetComputeRootConstantBufferView(Rdt::CBV, gpuAddress); } @@ -6038,14 +6755,9 @@ namespace bgfx { namespace d3d12 { wasCompute = false; - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - BX_UNUSED(s_viewName); - char* viewName = s_viewName[view]; - viewName[3] = ' '; - PIX3_ENDEVENT(m_commandList); - PIX3_BEGINEVENT(m_commandList, D3DCOLOR_DRAW, viewName); - } + setViewType(view, " "); + BGFX_D3D12_PROFILER_END(); + BGFX_D3D12_PROFILER_BEGIN(view, kColorDraw); commandListChanged = true; } @@ -6075,63 +6787,54 @@ namespace bgfx { namespace d3d12 } } - const uint64_t newFlags = draw.m_stateFlags; - uint64_t changedFlags = currentState.m_stateFlags ^ draw.m_stateFlags; - currentState.m_stateFlags = newFlags; - - const uint64_t newStencil = draw.m_stencil; - uint64_t changedStencil = (currentState.m_stencil ^ draw.m_stencil) & BGFX_STENCIL_FUNC_REF_MASK; - currentState.m_stencil = newStencil; - - if (resetState) + if (0 != draw.m_streamMask) { - wasCompute = false; - - currentState.clear(); - currentState.m_scissor = !draw.m_scissor; - changedFlags = BGFX_STATE_MASK; - changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); + const uint64_t newFlags = draw.m_stateFlags; + uint64_t changedFlags = currentState.m_stateFlags ^ draw.m_stateFlags; currentState.m_stateFlags = newFlags; - currentState.m_stencil = newStencil; - currentBind.clear(); + if (0 != (BGFX_STATE_PT_MASK & changedFlags) ) + { + primIndex = uint8_t( (newFlags&BGFX_STATE_PT_MASK)>>BGFX_STATE_PT_SHIFT); + } - commandListChanged = true; - } + const uint64_t newStencil = draw.m_stencil; + uint64_t changedStencil = (currentState.m_stencil ^ draw.m_stencil) & BGFX_STENCIL_FUNC_REF_MASK; + currentState.m_stencil = newStencil; - if (commandListChanged) - { - commandListChanged = false; + if (resetState + || commandListChanged) + { + wasCompute = false; + commandListChanged = false; - m_commandList->SetGraphicsRootSignature(m_rootSignature); - ID3D12DescriptorHeap* heaps[] = { - m_samplerAllocator.getHeap(), - scratchBuffer.getHeap(), - }; - m_commandList->SetDescriptorHeaps(BX_COUNTOF(heaps), heaps); + m_commandList->SetGraphicsRootSignature(m_rootSignature); + ID3D12DescriptorHeap* heaps[] = { + m_samplerAllocator.getHeap(), + scratchBuffer.getHeap(), + }; + m_commandList->SetDescriptorHeaps(BX_COUNTOF(heaps), heaps); - currentPso = NULL; - currentBindHash = 0; - currentSamplerStateIdx = kInvalidHandle; - currentProgramIdx = kInvalidHandle; - currentState.clear(); - currentState.m_scissor = !draw.m_scissor; - changedFlags = BGFX_STATE_MASK; - changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); - currentState.m_stateFlags = newFlags; - currentState.m_stencil = newStencil; + currentPso = NULL; + currentBindHash = 0; + currentSamplerStateIdx = kInvalidHandle; + currentProgram = BGFX_INVALID_HANDLE; + currentState.clear(); + currentState.m_scissor = !draw.m_scissor; + changedFlags = BGFX_STATE_MASK; + changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); + currentState.m_stateFlags = newFlags; + currentState.m_stencil = newStencil; - currentBind.clear(); + currentBind.clear(); - const uint64_t pt = newFlags&BGFX_STATE_PT_MASK; - primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT); - } + const uint64_t pt = newFlags&BGFX_STATE_PT_MASK; + primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT); + } - bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd; - rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); + bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd; + rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); - if (0 != draw.m_streamMask) - { currentState.m_streamMask = draw.m_streamMask; currentState.m_instanceDataBuffer.idx = draw.m_instanceDataBuffer.idx; currentState.m_instanceDataOffset = draw.m_instanceDataOffset; @@ -6145,49 +6848,52 @@ namespace bgfx { namespace d3d12 || f3 == (state & f3) ; - const VertexDecl* decls[BGFX_CONFIG_MAX_VERTEX_STREAMS]; + const VertexLayout* layouts[BGFX_CONFIG_MAX_VERTEX_STREAMS]; uint8_t numStreams = 0; if (UINT8_MAX != draw.m_streamMask) { - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask), ++numStreams + ; streamMask >>= 1, idx += 1, ++numStreams ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; - idx += ntz; + idx += ntz; - currentState.m_stream[idx].m_decl = draw.m_stream[idx].m_decl; - currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; - currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + currentState.m_stream[idx].m_layoutHandle = draw.m_stream[idx].m_layoutHandle; + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; uint16_t handle = draw.m_stream[idx].m_handle.idx; const VertexBufferD3D12& vb = m_vertexBuffers[handle]; - uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = m_vertexDecls[decl]; + const uint16_t layoutIdx = isValid(draw.m_stream[idx].m_layoutHandle) + ? draw.m_stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx; + const VertexLayout& layout = m_vertexLayouts[layoutIdx]; - decls[numStreams] = &vertexDecl; + layouts[numStreams] = &layout; } } - ID3D12PipelineState* pso = - getPipelineState(state - , draw.m_stencil - , numStreams - , decls - , key.m_program - , uint8_t(draw.m_instanceDataStride/16) - ); + ID3D12PipelineState* pso = getPipelineState( + state + , draw.m_stencil + , numStreams + , layouts + , key.m_program + , uint8_t(draw.m_instanceDataStride/16) + ); + + const uint32_t bindHash = bx::hash<bx::HashMurmur2A>(renderBind.m_bind, sizeof(renderBind.m_bind) ); - uint16_t scissor = draw.m_scissor; - uint32_t bindHash = bx::hash<bx::HashMurmur2A>(renderBind.m_bind, sizeof(renderBind.m_bind) ); if (currentBindHash != bindHash || 0 != changedStencil || (hasFactor && blendFactor != draw.m_rgba) || (0 != (BGFX_STATE_PT_MASK & changedFlags) || prim.m_topology != s_primInfo[primIndex].m_topology) - || currentState.m_scissor != scissor + || currentState.m_scissor != draw.m_scissor || pso != currentPso || hasOcclusionQuery) { @@ -6202,8 +6908,8 @@ namespace bgfx { namespace d3d12 if (NULL == bindCached) { uint32_t numSet = 0; - D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; - uint32_t samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {}; + uint32_t samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS] = {}; { for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) { @@ -6212,6 +6918,26 @@ namespace bgfx { namespace d3d12 { switch (bind.m_type) { + case Binding::Image: + { + TextureD3D12& texture = m_textures[bind.m_idx]; + + if (Access::Read != bind.m_access) + { + texture.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); + scratchBuffer.allocUav(srvHandle[stage], texture, bind.m_mip); + } + else + { + texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); + scratchBuffer.allocSrv(srvHandle[stage], texture, bind.m_mip); + samplerFlags[stage] = uint32_t(texture.m_flags); + } + + ++numSet; + } + break; + case Binding::Texture: { TextureD3D12& texture = m_textures[bind.m_idx]; @@ -6263,23 +6989,14 @@ namespace bgfx { namespace d3d12 if (0 != numSet) { - uint16_t samplerStateIdx = getSamplerState(samplerFlags, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, _render->m_colorPalette); - if (samplerStateIdx != currentSamplerStateIdx) - { - currentSamplerStateIdx = samplerStateIdx; - m_commandList->SetGraphicsRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); - } - - m_commandList->SetGraphicsRootDescriptorTable(Rdt::SRV, srvHandle[0]); - m_commandList->SetGraphicsRootDescriptorTable(Rdt::UAV, srvHandle[0]); - Bind bind; - bind.m_srvHandle = srvHandle[0]; - bind.m_samplerStateIdx = samplerStateIdx; - bindLru.add(bindHash, bind, 0); + bind.m_srvHandle = srvHandle[0]; + bind.m_samplerStateIdx = getSamplerState(samplerFlags, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, _render->m_colorPalette); + bindCached = bindLru.add(bindHash, bind, 0); } } - else + + if (NULL != bindCached) { uint16_t samplerStateIdx = bindCached->m_samplerStateIdx; if (samplerStateIdx != currentSamplerStateIdx) @@ -6322,6 +7039,7 @@ namespace bgfx { namespace d3d12 m_commandList->IASetPrimitiveTopology(prim.m_topology); } + const uint16_t scissor = draw.m_scissor; if (currentState.m_scissor != scissor) { currentState.m_scissor = scissor; @@ -6366,11 +7084,11 @@ namespace bgfx { namespace d3d12 } if (constantsChanged - || currentProgramIdx != key.m_program + || currentProgram.idx != key.m_program.idx || BGFX_STATE_ALPHA_REF_MASK & changedFlags) { - currentProgramIdx = key.m_program; - ProgramD3D12& program = m_program[currentProgramIdx]; + currentProgram = key.m_program; + ProgramD3D12& program = m_program[currentProgram.idx]; UniformBuffer* vcb = program.m_vsh->m_constantBuffer; if (NULL != vcb) @@ -6394,10 +7112,10 @@ namespace bgfx { namespace d3d12 if (constantsChanged || hasPredefined) { - ProgramD3D12& program = m_program[currentProgramIdx]; + ProgramD3D12& program = m_program[currentProgram.idx]; uint32_t ref = (newFlags&BGFX_STATE_ALPHA_REF_MASK)>>BGFX_STATE_ALPHA_REF_SHIFT; viewState.m_alphaRef = ref/255.0f; - viewState.setPredefined<4>(this, view, 0, program, _render, draw); + viewState.setPredefined<4>(this, view, program, _render, draw); commitShaderConstants(key.m_program, gpuAddress); } @@ -6424,13 +7142,9 @@ namespace bgfx { namespace d3d12 if (wasCompute) { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - char* viewName = s_viewName[view]; - viewName[3] = L'C'; - PIX3_ENDEVENT(m_commandList); - PIX3_BEGINEVENT(m_commandList, D3DCOLOR_DRAW, viewName); - } + setViewType(view, "C"); + BGFX_D3D12_PROFILER_END(); + BGFX_D3D12_PROFILER_BEGIN(view, kColorCompute); } submitBlit(bs, BGFX_CONFIG_MAX_VIEWS); @@ -6450,7 +7164,7 @@ namespace bgfx { namespace d3d12 } } - PIX3_ENDEVENT(m_commandList); + BGFX_D3D12_PROFILER_END(); int64_t timeEnd = bx::getHPCounter(); int64_t frameTime = timeEnd - timeBegin; @@ -6497,6 +7211,7 @@ namespace bgfx { namespace d3d12 perfStats.numCompute = statsKeyType[1]; perfStats.numBlit = _render->m_numBlitItems; perfStats.maxGpuLatency = maxGpuLatency; + perfStats.gpuFrameNum = result.m_frameNum; bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) ); perfStats.gpuMemoryMax = -INT64_MAX; perfStats.gpuMemoryUsed = -INT64_MAX; @@ -6512,7 +7227,7 @@ namespace bgfx { namespace d3d12 if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) { - PIX3_BEGINEVENT(m_commandList, D3DCOLOR_FRAME, "debugstats"); + BGFX_D3D12_PROFILER_BEGIN_LITERAL("debugstats", kColorFrame); // m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; @@ -6529,14 +7244,24 @@ namespace bgfx { namespace d3d12 tvm.clear(); uint16_t pos = 0; tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f - , " %s.%d (FL %d.%d) / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " + , " %s.%d (FL %d.%d) / " BX_COMPILER_NAME + " / " BX_CPU_NAME + " / " BX_ARCH_NAME + " / " BX_PLATFORM_NAME + " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")" , getRendererName() , m_deviceInterfaceVersion , (m_featureLevel >> 12) & 0xf , (m_featureLevel >> 8) & 0xf + , BGFX_API_VERSION + , BGFX_REV_NUMBER ); +#if BX_PLATFORM_LINUX + const DXGI_ADAPTER_DESC desc = {}; +#else const DXGI_ADAPTER_DESC& desc = m_dxgi.m_adapterDesc; +#endif // BX_PLATFORM_LINUX char description[BX_COUNTOF(desc.Description)]; wcstombs(description, desc.Description, BX_COUNTOF(desc.Description) ); tvm.printf(0, pos++, 0x8f, " Device: %s", description); @@ -6676,15 +7401,15 @@ namespace bgfx { namespace d3d12 blit(this, _textVideoMemBlitter, tvm); - PIX3_ENDEVENT(m_commandList); + BGFX_D3D12_PROFILER_END(); } else if (_render->m_debug & BGFX_DEBUG_TEXT) { - PIX3_BEGINEVENT(m_commandList, D3DCOLOR_FRAME, "debugtext"); + BGFX_D3D12_PROFILER_BEGIN_LITERAL("debugtext", kColorFrame); blit(this, _textVideoMemBlitter, _render->m_textVideoMem); - PIX3_ENDEVENT(m_commandList); + BGFX_D3D12_PROFILER_END(); } m_commandList->OMSetRenderTargets(0, NULL, false, NULL); diff --git a/3rdparty/bgfx/src/renderer_d3d12.h b/3rdparty/bgfx/src/renderer_d3d12.h index 216159f37d4..f578f1a385b 100644 --- a/3rdparty/bgfx/src/renderer_d3d12.h +++ b/3rdparty/bgfx/src/renderer_d3d12.h @@ -1,15 +1,17 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_D3D12_H_HEADER_GUARD #define BGFX_RENDERER_D3D12_H_HEADER_GUARD -#define USE_D3D12_DYNAMIC_LIB BX_PLATFORM_WINDOWS +#define USE_D3D12_DYNAMIC_LIB (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) #include <sal.h> -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +#include <unknwn.h> + +#if BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include <d3d12.h> #else # if !BGFX_CONFIG_DEBUG @@ -20,8 +22,14 @@ #if defined(__MINGW32__) // BK - temp workaround for MinGW until I nuke d3dx12 usage. extern "C++" { +# if defined(__cpp_constexpr) && __cpp_constexpr >= 200704L \ + && defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L + __extension__ template<typename Ty> + constexpr const GUID& __mingw_uuidof(); +# else __extension__ template<typename Ty> const GUID& __mingw_uuidof(); +# endif // __cpp_* template<> const GUID& __mingw_uuidof<ID3D12Device>() @@ -32,19 +40,6 @@ extern "C++" { } #endif // defined(__MINGW32__) -BX_PRAGMA_DIAGNOSTIC_PUSH(); -BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wmissing-field-initializers"); -#if BX_PLATFORM_XBOXONE -# include <d3dx12_x.h> -#else -# include <d3dx12.h> -#endif // BX_PLATFORM_XBOXONE -BX_PRAGMA_DIAGNOSTIC_POP(); - -#ifndef D3D12_TEXTURE_DATA_PITCH_ALIGNMENT -# define D3D12_TEXTURE_DATA_PITCH_ALIGNMENT 1024 -#endif // D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - #include "renderer.h" #include "renderer_d3d.h" #include "shader_dxbc.h" @@ -52,7 +47,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); #include "nvapi.h" #include "dxgi.h" -#if BGFX_CONFIG_DEBUG_PIX +#if BGFX_CONFIG_DEBUG_ANNOTATION && !BX_PLATFORM_LINUX # if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT typedef struct PIXEventsThreadInfo* (WINAPI* PFN_PIX_GET_THREAD_INFO)(); typedef uint64_t (WINAPI* PFN_PIX_EVENTS_REPLACE_BLOCK)(bool _getEarliestTime); @@ -80,7 +75,25 @@ extern "C" uint64_t WINAPI bgfx_PIXEventsReplaceBlock(bool _g # define PIX3_BEGINEVENT(_commandList, _color, _name) BX_UNUSED(_commandList, _color, _name) # define PIX3_SETMARKER(_commandList, _color, _name) BX_UNUSED(_commandList, _color, _name) # define PIX3_ENDEVENT(_commandList) BX_UNUSED(_commandList) -#endif // BGFX_CONFIG_DEBUG_PIX +#endif // BGFX_CONFIG_DEBUG_ANNOTATION + +#define BGFX_D3D12_PROFILER_BEGIN(_view, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + PIX3_BEGINEVENT(m_commandList, _abgr, s_viewName[_view]); \ + BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_D3D12_PROFILER_BEGIN_LITERAL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + PIX3_BEGINEVENT(m_commandList, _abgr, "" _name); \ + BGFX_PROFILER_BEGIN_LITERAL("" _name, _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_D3D12_PROFILER_END() \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_END(); \ + PIX3_ENDEVENT(m_commandList); \ + BX_MACRO_BLOCK_END namespace bgfx { namespace d3d12 { @@ -206,9 +219,9 @@ namespace bgfx { namespace d3d12 struct VertexBufferD3D12 : public BufferD3D12 { - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags); + void create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags); - VertexDeclHandle m_decl; + VertexLayoutHandle m_layoutHandle; }; struct ShaderD3D12 @@ -264,14 +277,14 @@ namespace bgfx { namespace d3d12 void create(const ShaderD3D12* _vsh, const ShaderD3D12* _fsh) { - BX_CHECK(NULL != _vsh->m_code, "Vertex shader doesn't exist."); + BX_ASSERT(NULL != _vsh->m_code, "Vertex shader doesn't exist."); m_vsh = _vsh; bx::memCopy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform)); m_numPredefined = _vsh->m_numPredefined; if (NULL != _fsh) { - BX_CHECK(NULL != _fsh->m_code, "Fragment shader doesn't exist."); + BX_ASSERT(NULL != _fsh->m_code, "Fragment shader doesn't exist."); m_fsh = _fsh; bx::memCopy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform)); m_numPredefined += _fsh->m_numPredefined; @@ -303,6 +316,7 @@ namespace bgfx { namespace d3d12 TextureD3D12() : m_ptr(NULL) + , m_singleMsaa(NULL) , m_directAccessPtr(NULL) , m_state(D3D12_RESOURCE_STATE_COMMON) , m_numMips(0) @@ -313,19 +327,22 @@ namespace bgfx { namespace d3d12 void* create(const Memory* _mem, uint64_t _flags, uint8_t _skip); void destroy(); + void overrideInternal(uintptr_t _ptr); void update(ID3D12GraphicsCommandList* _commandList, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem); - void resolve(uint8_t _resolve) const; + void resolve(ID3D12GraphicsCommandList* _commandList, uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip); D3D12_RESOURCE_STATES setState(ID3D12GraphicsCommandList* _commandList, D3D12_RESOURCE_STATES _state); D3D12_SHADER_RESOURCE_VIEW_DESC m_srvd; D3D12_UNORDERED_ACCESS_VIEW_DESC m_uavd; ID3D12Resource* m_ptr; + ID3D12Resource* m_singleMsaa; void* m_directAccessPtr; D3D12_RESOURCE_STATES m_state; uint64_t m_flags; uint32_t m_width; uint32_t m_height; uint32_t m_depth; + uint32_t m_numLayers; uint16_t m_samplerIdx; uint8_t m_type; uint8_t m_requestedFormat; @@ -390,7 +407,7 @@ namespace bgfx { namespace d3d12 void finish(uint64_t _waitFence = UINT64_MAX, bool _finishAll = false); bool tryFinish(uint64_t _waitFence); void release(ID3D12Resource* _ptr); - bool consume(uint32_t _ms = INFINITE); + bool consume(uint32_t _ms = UINT32_MAX); struct CommandList { @@ -500,29 +517,32 @@ namespace bgfx { namespace d3d12 void init(); void shutdown(); - uint32_t begin(uint32_t _resultIdx); + uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum); void end(uint32_t _idx); bool update(); struct Query { uint32_t m_resultIdx; - bool m_ready; + uint32_t m_frameNum; uint64_t m_fence; + bool m_ready; }; struct Result { void reset() { - m_begin = 0; - m_end = 0; - m_pending = 0; + m_begin = 0; + m_end = 0; + m_pending = 0; + m_frameNum = 0; } uint64_t m_begin; uint64_t m_end; uint32_t m_pending; + uint32_t m_frameNum; }; uint64_t m_frequency; diff --git a/3rdparty/bgfx/src/renderer_d3d9.cpp b/3rdparty/bgfx/src/renderer_d3d9.cpp index 21dbef68ff2..ff1a2cf0aec 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.cpp +++ b/3rdparty/bgfx/src/renderer_d3d9.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -12,7 +12,7 @@ namespace bgfx { namespace d3d9 { static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; - static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + static char s_viewName [BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; struct PrimInfo { @@ -183,12 +183,20 @@ namespace bgfx { namespace d3d9 { D3DFMT_UNKNOWN }, // ATC, { D3DFMT_UNKNOWN }, // ATCE, { D3DFMT_UNKNOWN }, // ATCI, - { D3DFMT_UNKNOWN }, // ASTC4x4, - { D3DFMT_UNKNOWN }, // ASTC5x5, - { D3DFMT_UNKNOWN }, // ASTC6x6, - { D3DFMT_UNKNOWN }, // ASTC8x5, - { D3DFMT_UNKNOWN }, // ASTC8x6, - { D3DFMT_UNKNOWN }, // ASTC10x5, + { D3DFMT_UNKNOWN }, // ASTC4x4 + { D3DFMT_UNKNOWN }, // ASTC5x4 + { D3DFMT_UNKNOWN }, // ASTC5x5 + { D3DFMT_UNKNOWN }, // ASTC6x5 + { D3DFMT_UNKNOWN }, // ASTC6x6 + { D3DFMT_UNKNOWN }, // ASTC8x5 + { D3DFMT_UNKNOWN }, // ASTC8x6 + { D3DFMT_UNKNOWN }, // ASTC8x8 + { D3DFMT_UNKNOWN }, // ASTC10x5 + { D3DFMT_UNKNOWN }, // ASTC10x6 + { D3DFMT_UNKNOWN }, // ASTC10x8 + { D3DFMT_UNKNOWN }, // ASTC10x10 + { D3DFMT_UNKNOWN }, // ASTC12x10 + { D3DFMT_UNKNOWN }, // ASTC12x12 { D3DFMT_UNKNOWN }, // Unknown { D3DFMT_A1 }, // R1 { D3DFMT_A8 }, // A8 @@ -234,8 +242,11 @@ namespace bgfx { namespace d3d9 { D3DFMT_UNKNOWN }, // RGBA32I { D3DFMT_UNKNOWN }, // RGBA32U { D3DFMT_A32B32G32R32F }, // RGBA32F + { D3DFMT_R5G6B5 }, // B5G6R5 { D3DFMT_R5G6B5 }, // R5G6B5 + { D3DFMT_A4R4G4B4 }, // BGRA4 { D3DFMT_A4R4G4B4 }, // RGBA4 + { D3DFMT_A1R5G5B5 }, // BGR5A1 { D3DFMT_A1R5G5B5 }, // RGB5A1 { D3DFMT_A2B10G10R10 }, // RGB10A2 { D3DFMT_UNKNOWN }, // RG11B10F @@ -335,25 +346,25 @@ namespace bgfx { namespace d3d9 }; BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) ); - static D3DVERTEXELEMENT9* fillVertexDecl(uint8_t _stream, D3DVERTEXELEMENT9* _out, const VertexDecl& _decl) + static D3DVERTEXELEMENT9* fillVertexLayout(uint8_t _stream, D3DVERTEXELEMENT9* _out, const VertexLayout& _layout) { D3DVERTEXELEMENT9* elem = _out; for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - if (UINT16_MAX != _decl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); + _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); bx::memCopy(elem, &s_attrib[attr], sizeof(D3DVERTEXELEMENT9) ); elem->Stream = _stream; elem->Type = s_attribType[type][num-1][normalized]; - elem->Offset = _decl.m_offset[attr]; + elem->Offset = _layout.m_offset[attr]; ++elem; } } @@ -373,6 +384,35 @@ namespace bgfx { namespace d3d9 ; } + inline bool useD3D9Pitch(bimg::TextureFormat::Enum _format) + { + // Reference(s): + // - For BC4 and B5 in DX9 LockRect returns wrong number of + // bytes. If actual mip size is used it causes memory corruption. + // https://web.archive.org/web/20190207230133/http://www.aras-p.info/texts/D3D9GPUHacks.html + return true + && _format != bimg::TextureFormat::BC4 + && _format != bimg::TextureFormat::BC5 + ; + } + + static inline uint32_t calcRowPitch(const bimg::ImageBlockInfo& _blockInfo, uint8_t _lod, uint32_t _width) + { + const uint8_t blockWidth = _blockInfo.blockWidth; + const uint8_t blockHeight = _blockInfo.blockHeight; + const uint8_t minBlockX = _blockInfo.minBlockX; + const uint8_t bitsPerPixel = _blockInfo.bitsPerPixel; + + // Calculate the row pitch + const uint32_t minBlkWidth = minBlockX; + const uint32_t lodBlkWidth = (((_width >> _lod) + blockWidth - 1) / blockWidth); + const uint32_t rowBlkWidth = bx::max<uint32_t>(minBlkWidth, lodBlkWidth); + const uint32_t pixBlkWidth = rowBlkWidth * blockWidth * blockHeight; + const uint32_t rowPitch = pixBlkWidth * bitsPerPixel / 8u; + + return rowPitch; + } + struct RendererContextD3D9 : public RendererContextI { RendererContextD3D9() @@ -420,34 +460,40 @@ namespace bgfx { namespace d3d9 D3DFORMAT adapterFormat = D3DFMT_X8R8G8B8; - // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172588%28v=vs.85%29.aspx + // Reference(s): + // - https://web.archive.org/web/20190207230309/https://docs.microsoft.com/en-us/windows/desktop/direct3d9/d3dpresent-parameters bx::memSet(&m_params, 0, sizeof(m_params) ); - m_params.BackBufferWidth = _init.resolution.width; - m_params.BackBufferHeight = _init.resolution.height; - m_params.BackBufferFormat = adapterFormat; - m_params.BackBufferCount = bx::clamp<uint8_t>(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS); - m_params.MultiSampleType = D3DMULTISAMPLE_NONE; - m_params.MultiSampleQuality = 0; + m_params.BackBufferWidth = _init.resolution.width; + m_params.BackBufferHeight = _init.resolution.height; + m_params.BackBufferFormat = adapterFormat; + m_params.BackBufferCount = bx::clamp<uint8_t>(_init.resolution.numBackBuffers, 2, BGFX_CONFIG_MAX_BACK_BUFFERS); + m_params.MultiSampleType = D3DMULTISAMPLE_NONE; + m_params.MultiSampleQuality = 0; m_params.EnableAutoDepthStencil = TRUE; m_params.AutoDepthStencilFormat = D3DFMT_D24S8; - m_params.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; + m_params.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; m_params.FullScreen_RefreshRateInHz = 0; - m_params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; - m_params.SwapEffect = D3DSWAPEFFECT_DISCARD; - m_params.hDeviceWindow = NULL; - m_params.Windowed = true; - - RECT rect; - GetWindowRect( (HWND)g_platformData.nwh, &rect); - m_params.BackBufferWidth = rect.right-rect.left; - m_params.BackBufferHeight = rect.bottom-rect.top; + m_params.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; + m_params.SwapEffect = D3DSWAPEFFECT_DISCARD; + m_params.hDeviceWindow = NULL; + m_params.Windowed = true; + m_params.BackBufferWidth = _init.resolution.width; + m_params.BackBufferHeight = _init.resolution.height; + + const char* d3d9DllName = +#if BX_PLATFORM_LINUX + "d3d9.so" +#else + "d3d9.dll" +#endif // BX_PLATFORM_LINUX + ; - m_d3d9Dll = bx::dlopen("d3d9.dll"); + m_d3d9Dll = bx::dlopen(d3d9DllName); if (NULL == m_d3d9Dll) { - BX_TRACE("Init error: Failed to load d3d9.dll."); + BX_TRACE("Init error: Failed to load %s.", d3d9DllName); goto error; } @@ -455,17 +501,22 @@ namespace bgfx { namespace d3d9 m_nvapi.init(); - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) { D3DPERF_SetMarker = (PFN_D3DPERF_SET_MARKER )bx::dlsym(m_d3d9Dll, "D3DPERF_SetMarker"); D3DPERF_BeginEvent = (PFN_D3DPERF_BEGIN_EVENT)bx::dlsym(m_d3d9Dll, "D3DPERF_BeginEvent"); D3DPERF_EndEvent = (PFN_D3DPERF_END_EVENT )bx::dlsym(m_d3d9Dll, "D3DPERF_EndEvent"); - BX_CHECK(NULL != D3DPERF_SetMarker - && NULL != D3DPERF_BeginEvent - && NULL != D3DPERF_EndEvent - , "Failed to initialize PIX events." - ); + if (NULL == D3DPERF_SetMarker + || NULL == D3DPERF_BeginEvent + || NULL == D3DPERF_EndEvent) + { + BX_TRACE("Failed to initialize PIX events."); + + D3DPERF_SetMarker = NULL; + D3DPERF_BeginEvent = NULL; + D3DPERF_EndEvent = NULL; + } } m_d3d9ex = NULL; @@ -675,10 +726,10 @@ namespace bgfx { namespace d3d9 | BGFX_CAPS_VERTEX_ATTRIB_UINT10 | BGFX_CAPS_FRAGMENT_DEPTH | BGFX_CAPS_SWAP_CHAIN - | ( (UINT16_MAX < m_caps.MaxVertexIndex) ? BGFX_CAPS_INDEX32 : 0) | ( (m_caps.DevCaps2 & D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES) ? BGFX_CAPS_TEXTURE_BLIT : 0) | BGFX_CAPS_TEXTURE_READ_BACK | (m_occlusionQuerySupport ? BGFX_CAPS_OCCLUSION_QUERY : 0) + | ((m_caps.MaxVertexIndex > UINT16_MAX) ? BGFX_CAPS_INDEX32 : 0) ); m_caps.NumSimultaneousRTs = bx::uint32_min(m_caps.NumSimultaneousRTs, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); @@ -963,20 +1014,20 @@ namespace bgfx { namespace d3d9 m_indexBuffers[_handle.idx].destroy(); } - void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override + void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) override { - VertexDecl& decl = m_vertexDecls[_handle.idx]; - bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); - dump(decl); + VertexLayout& layout = m_vertexLayouts[_handle.idx]; + bx::memCopy(&layout, &_layout, sizeof(VertexLayout) ); + dump(layout); } - void destroyVertexDecl(VertexDeclHandle /*_handle*/) override + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override { } - void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t /*_flags*/) override + void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t /*_flags*/) override { - m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle); + m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _layoutHandle); } void destroyVertexBuffer(VertexBufferHandle _handle) override @@ -1001,8 +1052,8 @@ namespace bgfx { namespace d3d9 void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t /*_flags*/) override { - VertexDeclHandle decl = BGFX_INVALID_HANDLE; - m_vertexBuffers[_handle.idx].create(_size, NULL, decl); + VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE; + m_vertexBuffers[_handle.idx].create(_size, NULL, layoutHandle); } void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override @@ -1100,7 +1151,7 @@ namespace bgfx { namespace d3d9 bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -1111,7 +1162,7 @@ namespace bgfx { namespace d3d9 tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); tc.m_cubeMap = false; tc.m_mem = NULL; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); texture.destroy(true); texture.create(mem, texture.m_flags, 0); @@ -1178,7 +1229,7 @@ namespace bgfx { namespace d3d9 BX_FREE(g_allocator, m_uniforms[_handle.idx]); } - uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num); + const uint32_t size = bx::alignUp(g_uniformTypeSize[_type]*_num, 16); void* data = BX_ALLOC(g_allocator, size); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; @@ -1194,6 +1245,7 @@ namespace bgfx { namespace d3d9 void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) override { +#if BX_PLATFORM_WINDOWS IDirect3DSwapChain9* swapChain = isValid(_handle) ? m_frameBuffers[_handle.idx].m_swapChain : m_swapChain @@ -1257,11 +1309,15 @@ namespace bgfx { namespace d3d9 DX_CHECK(surface->UnlockRect() ); DX_RELEASE(surface, 0); +#else + BX_TRACE("Screenshot not supported!"); + BX_UNUSED(_handle, _filePath); +#endif // BX_PLATFORM_WINDOWS } void updateViewName(ViewId _id, const char* _name) override { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) { mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] , _name @@ -1280,25 +1336,26 @@ namespace bgfx { namespace d3d9 bx::memCopy(m_uniforms[_loc], _data, _size); } - void setMarker(const char* _marker, uint32_t _size) override + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override { -#if BGFX_CONFIG_DEBUG_PIX - uint32_t size = _size*sizeof(wchar_t); - wchar_t* name = (wchar_t*)alloca(size); - mbstowcs(name, _marker, size-2); - PIX_SETMARKER(D3DCOLOR_MARKER, name); -#endif // BGFX_CONFIG_DEBUG_PIX - BX_UNUSED(_marker, _size); + m_occlusionQuery.invalidate(_handle); } - void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + void setMarker(const char* _marker, uint16_t _len) override { - m_occlusionQuery.invalidate(_handle); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + uint32_t size = _len*sizeof(wchar_t); + wchar_t* name = (wchar_t*)alloca(size+2); + mbstowcs(name, _marker, size); + name[_len] = L'\0'; + PIX_SETMARKER(kColorMarker, name); + } } - virtual void setName(Handle _handle, const char* _name) override + virtual void setName(Handle _handle, const char* _name, uint16_t _len) override { - BX_UNUSED(_handle, _name) + BX_UNUSED(_handle, _name, _len) } void submitBlit(BlitState& _bs, uint16_t _view); @@ -1337,9 +1394,9 @@ namespace bgfx { namespace d3d9 DX_CHECK(device->SetPixelShader(program.m_fsh->m_pixelShader) ); VertexBufferD3D9& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; - VertexDecl& vertexDecl = m_vertexDecls[_blitter.m_vb->decl.idx]; - DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, vertexDecl.m_stride) ); - setInputLayout(vertexDecl, 0); + VertexLayout& layout = m_vertexLayouts[_blitter.m_vb->layoutHandle.idx]; + DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, layout.m_stride) ); + setInputLayout(layout, 0); IndexBufferD3D9& ib = m_indexBuffers[_blitter.m_ib->handle.idx]; DX_CHECK(device->SetIndices(ib.m_ptr) ); @@ -1360,7 +1417,7 @@ namespace bgfx { namespace d3d9 if (0 < numVertices) { m_indexBuffers[_blitter.m_ib->handle.idx].update(0, _numIndices * 2, _blitter.m_ib->data, true); - m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data, true); + m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_layout.m_stride, _blitter.m_vb->data, true); DX_CHECK(m_device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST , 0 @@ -1481,7 +1538,7 @@ namespace bgfx { namespace d3d9 void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { - if (_flags&BGFX_UNIFORM_FRAGMENTBIT) + if (_flags&kUniformFragmentBit) { DX_CHECK(m_device->SetPixelShaderConstantF(_regIndex, (const float*)_val, _numRegs) ); } @@ -1530,11 +1587,6 @@ namespace bgfx { namespace d3d9 { if (NULL != m_swapChain) { - if (NULL != m_deviceEx) - { - DX_CHECK(m_deviceEx->WaitForVBlank(0) ); - } - for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) { HRESULT hr = S_OK; @@ -1698,10 +1750,10 @@ namespace bgfx { namespace d3d9 } } - void setSamplerState(uint8_t _stage, uint32_t _flags, const float _rgba[4]) + void setSamplerState(uint8_t _stage, uint64_t _flags, const float _rgba[4]) { - const uint32_t flags = _flags&( (~BGFX_SAMPLER_RESERVED_MASK) | BGFX_SAMPLER_BITS_MASK | BGFX_TEXTURE_SRGB); - BX_CHECK(_stage < BX_COUNTOF(m_samplerFlags), ""); + const uint64_t flags = _flags&( (~BGFX_SAMPLER_RESERVED_MASK) | BGFX_SAMPLER_BITS_MASK | BGFX_TEXTURE_SRGB); + BX_ASSERT(_stage < BX_COUNTOF(m_samplerFlags), ""); if (m_samplerFlags[_stage] != flags) { m_samplerFlags[_stage] = flags; @@ -1866,7 +1918,7 @@ namespace bgfx { namespace d3d9 } \ break; \ \ - case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \ + case UniformType::_uniform|kUniformFragmentBit: \ { \ _type* value = (_type*)data; \ DX_CHECK(device->SetPixelShaderConstant##_dxsuffix(loc, value, num) ); \ @@ -1898,7 +1950,7 @@ namespace bgfx { namespace d3d9 } break; - case UniformType::Mat3|BGFX_UNIFORM_FRAGMENTBIT: + case UniformType::Mat3|kUniformFragmentBit: { float* value = (float*)data; for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3, value += 9) @@ -1921,9 +1973,9 @@ namespace bgfx { namespace d3d9 } break; - CASE_IMPLEMENT_UNIFORM(Int1, I, int); - CASE_IMPLEMENT_UNIFORM(Vec4, F, float); - CASE_IMPLEMENT_UNIFORM(Mat4, F, float); + CASE_IMPLEMENT_UNIFORM(Sampler, I, int); + CASE_IMPLEMENT_UNIFORM(Vec4, F, float); + CASE_IMPLEMENT_UNIFORM(Mat4, F, float); case UniformType::End: break; @@ -2051,54 +2103,25 @@ namespace bgfx { namespace d3d9 DX_CHECK(device->SetRenderState(D3DRS_STENCILENABLE, FALSE) ); } - VertexBufferD3D9& vb = m_vertexBuffers[_clearQuad.m_vb->handle.idx]; - VertexDecl& vertexDecl = m_vertexDecls[_clearQuad.m_vb->decl.idx]; - uint32_t stride = _clearQuad.m_decl.m_stride; - - { - struct Vertex - { - float m_x; - float m_y; - float m_z; - }; - - Vertex* vertex = (Vertex*)_clearQuad.m_vb->data; - BX_CHECK(stride == sizeof(Vertex), "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)", stride, sizeof(Vertex) ); - - const float depth = _clear.m_depth; - - vertex->m_x = -1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = -1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - } - - vb.update(0, 4*stride, _clearQuad.m_vb->data); + VertexBufferD3D9& vb = m_vertexBuffers[_clearQuad.m_vb.idx]; + VertexLayout& layout = _clearQuad.m_layout; + uint32_t stride = _clearQuad.m_layout.m_stride; ProgramD3D9& program = m_program[_clearQuad.m_program[numMrt-1].idx]; device->SetVertexShader(program.m_vsh->m_vertexShader); device->SetPixelShader(program.m_fsh->m_pixelShader); - float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; + float mrtClearDepth[4] = { _clear.m_depth }; + DX_CHECK(device->SetVertexShaderConstantF(0, mrtClearDepth, 1)); + + float mrtClearColor[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, _clear.m_index[ii]); - bx::memCopy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClearColor[ii], _palette[index], 16); } } else @@ -2113,16 +2136,16 @@ namespace bgfx { namespace d3d9 for (uint32_t ii = 0; ii < numMrt; ++ii) { - bx::memCopy(mrtClear[ii], rgba, 16); + bx::memCopy(mrtClearColor[ii], rgba, 16); } } - DX_CHECK(device->SetPixelShaderConstantF(0, mrtClear[0], numMrt)); + DX_CHECK(device->SetPixelShaderConstantF(0, mrtClearColor[0], numMrt)); DX_CHECK(device->SetStreamSource(0, vb.m_ptr, 0, stride) ); DX_CHECK(device->SetStreamSourceFreq(0, 1) ); DX_CHECK(device->SetStreamSource(1, NULL, 0, 0) ); - setInputLayout(vertexDecl, 0); + setInputLayout(layout, 0); DX_CHECK(device->SetIndices(NULL) ); DX_CHECK(device->DrawPrimitive(D3DPT_TRIANGLESTRIP , 0 @@ -2131,14 +2154,14 @@ namespace bgfx { namespace d3d9 } } - void setInputLayout(uint8_t _numStreams, const VertexDecl** _vertexDecls, uint16_t _numInstanceData) + void setInputLayout(uint8_t _numStreams, const VertexLayout** _layouts, uint16_t _numInstanceData) { bx::HashMurmur2A murmur; murmur.begin(); murmur.add(_numInstanceData); for (uint8_t stream = 0; stream < _numStreams; ++stream) { - murmur.add(_vertexDecls[stream]->m_hash); + murmur.add(_layouts[stream]->m_hash); } uint64_t layoutHash = murmur.end(); @@ -2150,7 +2173,7 @@ namespace bgfx { namespace d3d9 for (uint8_t stream = 0; stream < _numStreams; ++stream) { - elem = fillVertexDecl(stream, elem, *_vertexDecls[stream]); + elem = fillVertexLayout(stream, elem, *_layouts[stream]); } const D3DVERTEXELEMENT9 inst = { _numStreams, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }; @@ -2173,10 +2196,10 @@ namespace bgfx { namespace d3d9 DX_CHECK(m_device->SetVertexDeclaration(layout) ); } - void setInputLayout(const VertexDecl& _vertexDecl, uint16_t _numInstanceData) + void setInputLayout(const VertexLayout& _layout, uint16_t _numInstanceData) { - const VertexDecl* decls[1] = { &_vertexDecl }; - setInputLayout(BX_COUNTOF(decls), decls, _numInstanceData); + const VertexLayout* layouts[1] = { &_layout }; + setInputLayout(BX_COUNTOF(layouts), layouts, _numInstanceData); } D3DCAPS9 m_caps; @@ -2230,12 +2253,12 @@ namespace bgfx { namespace d3d9 ShaderD3D9 m_shaders[BGFX_CONFIG_MAX_SHADERS]; ProgramD3D9 m_program[BGFX_CONFIG_MAX_PROGRAMS]; TextureD3D9 m_textures[BGFX_CONFIG_MAX_TEXTURES]; - VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS]; + VertexLayout m_vertexLayouts[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; FrameBufferD3D9 m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; UniformRegistry m_uniformReg; void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; - uint32_t m_samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + uint64_t m_samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; TextureD3D9* m_updateTexture; uint8_t* m_updateTextureBits; @@ -2334,10 +2357,10 @@ namespace bgfx { namespace d3d9 } } - void VertexBufferD3D9::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle) + void VertexBufferD3D9::create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle) { m_size = _size; - m_decl = _declHandle; + m_layoutHandle = _layoutHandle; uint32_t usage = D3DUSAGE_WRITEONLY; D3DPOOL pool = s_renderD3D9->m_pool; @@ -2391,13 +2414,15 @@ namespace bgfx { namespace d3d9 { bx::MemoryReader reader(_mem->data, _mem->size); + bx::ErrorAssert err; + uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, &err); const bool fragment = isShaderType(magic, 'F'); uint32_t hashIn; - bx::read(&reader, hashIn); + bx::read(&reader, hashIn, &err); uint32_t hashOut; @@ -2407,40 +2432,52 @@ namespace bgfx { namespace d3d9 } else { - bx::read(&reader, hashOut); + bx::read(&reader, hashOut, &err); } uint16_t count; - bx::read(&reader, count); + bx::read(&reader, count, &err); m_numPredefined = 0; BX_TRACE("Shader consts %d", count); - uint8_t fragmentBit = fragment ? BGFX_UNIFORM_FRAGMENTBIT : 0; + uint8_t fragmentBit = fragment ? kUniformFragmentBit : 0; if (0 < count) { for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize = 0; - bx::read(&reader, nameSize); + bx::read(&reader, nameSize, &err); char name[256] = {}; - bx::read(&reader, &name, nameSize); + bx::read(&reader, &name, nameSize, &err); name[nameSize] = '\0'; uint8_t type = 0; - bx::read(&reader, type); + bx::read(&reader, type, &err); uint8_t num = 0; - bx::read(&reader, num); + bx::read(&reader, num, &err); uint16_t regIndex = 0; - bx::read(&reader, regIndex); + bx::read(&reader, regIndex, &err); uint16_t regCount = 0; - bx::read(&reader, regCount); + bx::read(&reader, regCount, &err); + + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo = 0; + bx::read(&reader, texInfo, &err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(&reader, texFormat, &err); + } const char* kind = "invalid"; @@ -2453,7 +2490,7 @@ namespace bgfx { namespace d3d9 m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); m_numPredefined++; } - else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) ) + else if (0 == (kUniformSamplerBit & type) ) { const UniformRegInfo* info = s_renderD3D9->m_uniformReg.find(name); BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); @@ -2477,7 +2514,7 @@ namespace bgfx { namespace d3d9 BX_TRACE("\t%s: %s (%s), num %2d, r.index %3d, r.count %2d" , kind , name - , getUniformTypeName(UniformType::Enum(type&~BGFX_UNIFORM_MASK) ) + , getUniformTypeName(UniformType::Enum(type&~kUniformMask) ) , num , regIndex , regCount @@ -2492,7 +2529,7 @@ namespace bgfx { namespace d3d9 } uint32_t shaderSize; - bx::read(&reader, shaderSize); + bx::read(&reader, shaderSize, &err); const DWORD* code = (const DWORD*)reader.getDataPtr(); @@ -2796,7 +2833,7 @@ namespace bgfx { namespace d3d9 } } - BX_CHECK(false, "You should not be here."); + BX_ASSERT(false, "You should not be here."); _pitch = 0; _slicePitch = 0; return NULL; @@ -2830,7 +2867,7 @@ namespace bgfx { namespace d3d9 return; } - BX_CHECK(false, "You should not be here."); + BX_ASSERT(false, "You should not be here."); } void TextureD3D9::dirty(uint8_t _side, const Rect& _rect, uint16_t _z, uint16_t _depth) @@ -2873,7 +2910,7 @@ namespace bgfx { namespace d3d9 return; } - BX_CHECK(false, "You should not be here."); + BX_ASSERT(false, "You should not be here."); } IDirect3DSurface9* TextureD3D9::getSurface(uint8_t _side, uint8_t _mip) const @@ -2887,7 +2924,7 @@ namespace bgfx { namespace d3d9 break; case Texture3D: - BX_CHECK(false, ""); + BX_ASSERT(false, ""); break; case TextureCube: @@ -2904,18 +2941,28 @@ namespace bgfx { namespace d3d9 if (bimg::imageParse(imageContainer, _mem->data, _mem->size) ) { - uint8_t numMips = imageContainer.m_numMips; - const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); - numMips -= startLod; const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::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); + + const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips-1); + + bimg::TextureInfo ti; + bimg::imageGetSize( + &ti + , uint16_t(imageContainer.m_width >>startLod) + , uint16_t(imageContainer.m_height>>startLod) + , uint16_t(imageContainer.m_depth >>startLod) + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + , imageContainer.m_numLayers + , imageContainer.m_format + ); + ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips-startLod, ti.numMips); m_flags = _flags; - m_width = textureWidth; - m_height = textureHeight; - m_depth = imageContainer.m_depth; - m_numMips = numMips; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numMips = ti.numMips; m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -2924,23 +2971,23 @@ namespace bgfx { namespace d3d9 if (imageContainer.m_cubeMap) { - createCubeTexture(textureWidth, numMips); + createCubeTexture(ti.width, ti.numMips); } else if (imageContainer.m_depth > 1) { - createVolumeTexture(textureWidth, textureHeight, imageContainer.m_depth, numMips); + createVolumeTexture(ti.width, ti.height, ti.depth, ti.numMips); } else { - createTexture(textureWidth, textureHeight, numMips); + createTexture(ti.width, ti.height, ti.numMips); } BX_TRACE("Texture %3d: %s (requested: %s), %dx%d%s%s." , this - s_renderD3D9->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) - , textureWidth - , textureHeight + , ti.width + , ti.height , imageContainer.m_cubeMap ? "x6" : "" , 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" ); @@ -2950,29 +2997,22 @@ namespace bgfx { namespace d3d9 return; } - // For BC4 and B5 in DX9 LockRect returns wrong number of - // bytes. If actual mip size is used it causes memory corruption. - // http://www.aras-p.info/texts/D3D9GPUHacks.html#3dc - const bool useMipSize = true - && imageContainer.m_format != bimg::TextureFormat::BC4 - && imageContainer.m_format != bimg::TextureFormat::BC5 - ; - + const bool useMipSize = useD3D9Pitch(imageContainer.m_format); for (uint8_t side = 0, numSides = imageContainer.m_cubeMap ? 6 : 1; side < numSides; ++side) { - uint32_t width = textureWidth; - uint32_t height = textureHeight; - uint32_t depth = imageContainer.m_depth; - uint32_t mipWidth = imageContainer.m_width; - uint32_t mipHeight = imageContainer.m_height; + uint32_t width = ti.width; + uint32_t height = ti.height; + uint32_t depth = ti.depth; + uint32_t mipWidth = ti.width; + uint32_t mipHeight = ti.height; - for (uint8_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod) { - width = bx::uint32_max(1, width); - height = bx::uint32_max(1, height); - depth = bx::uint32_max(1, depth); - mipWidth = bx::uint32_max(blockInfo.blockWidth, mipWidth); - mipHeight = bx::uint32_max(blockInfo.blockHeight, mipHeight); + width = bx::max<uint32_t>(1, width); + height = bx::max<uint32_t>(1, height); + depth = bx::max<uint32_t>(1, depth); + mipWidth = bx::max<uint32_t>(blockInfo.blockWidth, mipWidth); + mipHeight = bx::max<uint32_t>(blockInfo.blockHeight, mipHeight); uint32_t mipSize = width*height*depth*bpp/8; bimg::ImageMip mip; @@ -3000,7 +3040,7 @@ namespace bgfx { namespace d3d9 , mip.m_format ); - bx::memCopy(bits, temp, pitch, height, srcpitch, pitch); + bx::memCopy(bits, pitch, temp, srcpitch, pitch, height); BX_FREE(g_allocator, temp); } @@ -3014,14 +3054,18 @@ namespace bgfx { namespace d3d9 uint32_t size = useMipSize ? mip.m_size : mipSize; switch (m_textureFormat) { - case TextureFormat::RGB5A1: - bimg::imageConvert(bits, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, size); + case TextureFormat::R5G6B5: + bimg::imageConvert(bits, 16, bx::packB5G6R5, mip.m_data, bx::unpackR5G6B5, size); break; case TextureFormat::RGBA4: bimg::imageConvert(bits, 16, bx::packBgra4, mip.m_data, bx::unpackRgba4, size); break; + case TextureFormat::RGB5A1: + bimg::imageConvert(bits, 16, bx::packBgr5a1, mip.m_data, bx::unpackRgb5a1, size); + break; + default: bx::memCopy(bits, mip.m_data, size); break; @@ -3051,11 +3095,14 @@ namespace bgfx { namespace d3d9 void TextureD3D9::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) { - const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); - const uint32_t rectpitch = _rect.m_width*bpp/8; - const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; - const uint32_t dstpitch = s_renderD3D9->m_updateTexturePitch; - uint8_t* bits = s_renderD3D9->m_updateTextureBits + _rect.m_y*dstpitch + _rect.m_x*bpp/8; + const bimg::ImageBlockInfo & blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) ); + const uint16_t blockHeight = blockInfo.blockHeight; + const uint16_t bpp = blockInfo.bitsPerPixel; + const bool useLockedPitch = useD3D9Pitch(bimg::TextureFormat::Enum(m_textureFormat) ); + const uint32_t rectpitch = calcRowPitch(blockInfo, 0, _rect.m_width); + const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; + const uint32_t dstpitch = (useLockedPitch) ? s_renderD3D9->m_updateTexturePitch : calcRowPitch(blockInfo, _mip, m_width); + uint8_t* bits = s_renderD3D9->m_updateTextureBits + _rect.m_y*dstpitch/blockHeight + _rect.m_x*blockHeight*bpp/8; const bool convert = m_textureFormat != m_requestedFormat; @@ -3072,18 +3119,22 @@ namespace bgfx { namespace d3d9 { uint8_t* src = data; uint8_t* dst = bits; - for (uint32_t yy = 0, height = _rect.m_height; yy < height; ++yy) + for (uint32_t yy = 0, height = _rect.m_height; yy < height; yy += blockHeight) { switch (m_textureFormat) { - case TextureFormat::RGB5A1: - bimg::imageConvert(dst, 16, bx::packBgr5a1, src, bx::unpackRgb5a1, rectpitch); + case TextureFormat::R5G6B5: + bimg::imageConvert(dst, 16, bx::packB5G6R5, src, bx::unpackR5G6B5, rectpitch); break; case TextureFormat::RGBA4: bimg::imageConvert(dst, 16, bx::packBgra4, src, bx::unpackRgba4, rectpitch); break; + case TextureFormat::RGB5A1: + bimg::imageConvert(dst, 16, bx::packBgr5a1, src, bx::unpackRgb5a1, rectpitch); + break; + default: bx::memCopy(dst, src, rectpitch); break; @@ -3111,9 +3162,8 @@ namespace bgfx { namespace d3d9 void TextureD3D9::commit(uint8_t _stage, uint32_t _flags, const float _palette[][4]) { - const uint32_t flags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) - ? _flags - : uint32_t(m_flags) + const uint64_t flags = (m_flags & BGFX_TEXTURE_SRGB) + | (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ? _flags : uint32_t(m_flags) ) ; uint32_t index = (flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT; s_renderD3D9->setSamplerState(_stage, flags, _palette[index]); @@ -3252,9 +3302,11 @@ namespace bgfx { namespace d3d9 D3DPRESENT_PARAMETERS params; bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); - params.BackBufferFormat = TextureFormat::Count == _format ? params.BackBufferFormat : s_textureFormat[_format].m_fmt; - params.BackBufferWidth = m_width; - params.BackBufferHeight = m_height; + params.BackBufferFormat = TextureFormat::Count == _format ? params.BackBufferFormat : s_textureFormat[_format].m_fmt; + params.BackBufferWidth = m_width; + params.BackBufferHeight = m_height; + params.MultiSampleType = s_msaa[0].m_type; + params.MultiSampleQuality = s_msaa[0].m_quality; DX_CHECK(s_renderD3D9->m_device->CreateAdditionalSwapChain(¶ms, &m_swapChain) ); DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_surface[0]) ); @@ -3404,7 +3456,7 @@ namespace bgfx { namespace d3d9 } else { - BX_CHECK(false, ""); + BX_ASSERT(false, ""); } } } @@ -3499,7 +3551,7 @@ namespace bgfx { namespace d3d9 } } - uint32_t TimerQueryD3D9::begin(uint32_t _resultIdx) + uint32_t TimerQueryD3D9::begin(uint32_t _resultIdx, uint32_t _frameNum) { while (0 == m_control.reserve(1) ) { @@ -3513,6 +3565,7 @@ namespace bgfx { namespace d3d9 Query& query = m_query[idx]; query.m_resultIdx = _resultIdx; query.m_ready = false; + query.m_frameNum = _frameNum; query.m_disjoint->Issue(D3DISSUE_BEGIN); query.m_begin->Issue(D3DISSUE_END); @@ -3563,6 +3616,7 @@ namespace bgfx { namespace d3d9 Result& result = m_result[query.m_resultIdx]; --result.m_pending; + result.m_frameNum = query.m_frameNum; result.m_frequency = freq; result.m_begin = timeBegin; @@ -3659,15 +3713,8 @@ namespace bgfx { namespace d3d9 const TextureD3D9& src = m_textures[blit.m_src.idx]; const TextureD3D9& dst = m_textures[blit.m_dst.idx]; - uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX; - uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY; - uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX; - uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY; - uint32_t width = bx::uint32_min(srcWidth, dstWidth); - uint32_t height = bx::uint32_min(srcHeight, dstHeight); - - RECT srcRect = { LONG(blit.m_srcX), LONG(blit.m_srcY), LONG(blit.m_srcX + width), LONG(blit.m_srcY + height) }; - RECT dstRect = { LONG(blit.m_dstX), LONG(blit.m_dstY), LONG(blit.m_dstX + width), LONG(blit.m_dstY + height) }; + RECT srcRect = { LONG(blit.m_srcX), LONG(blit.m_srcY), LONG(blit.m_srcX + blit.m_width), LONG(blit.m_srcY + blit.m_height) }; + RECT dstRect = { LONG(blit.m_dstX), LONG(blit.m_dstY), LONG(blit.m_dstX + blit.m_width), LONG(blit.m_dstY + blit.m_height) }; IDirect3DSurface9* srcSurface = src.getSurface(uint8_t(blit.m_srcZ), blit.m_srcMip); IDirect3DSurface9* dstSurface = dst.getSurface(uint8_t(blit.m_dstZ), blit.m_dstMip); @@ -3708,10 +3755,10 @@ namespace bgfx { namespace d3d9 { IDirect3DDevice9* device = m_device; - PIX_BEGINEVENT(D3DCOLOR_FRAME, L"rendererSubmit"); - updateResolution(_render->m_resolution); + BGFX_D3D9_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorView); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; @@ -3720,17 +3767,19 @@ namespace bgfx { namespace d3d9 device->BeginScene(); if (m_timerQuerySupport) { - frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS); + frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS, _render->m_frameNum); } if (0 < _render->m_iboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource); TransientIndexBuffer* ib = _render->m_transientIb; m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true); } if (0 < _render->m_vboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource); TransientVertexBuffer* vb = _render->m_transientVb; m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true); } @@ -3745,10 +3794,11 @@ namespace bgfx { namespace d3d9 RenderBind currentBind; currentBind.clear(); - ViewState viewState(_render, false); + static ViewState viewState; + viewState.reset(_render); DX_CHECK(device->SetRenderState(D3DRS_FILLMODE, _render->m_debug&BGFX_DEBUG_WIREFRAME ? D3DFILL_WIREFRAME : D3DFILL_SOLID) ); - uint16_t programIdx = kInvalidHandle; + ProgramHandle currentProgram = BGFX_INVALID_HANDLE; SortKey key; uint16_t view = UINT16_MAX; FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS }; @@ -3797,7 +3847,7 @@ namespace bgfx { namespace d3d9 if (isCompute) { - BX_CHECK(false, "Compute is not supported on DirectX 9."); + BX_ASSERT(false, "Compute is not supported on DirectX 9."); continue; } @@ -3838,22 +3888,23 @@ namespace bgfx { namespace d3d9 currentState.m_stencil = newStencil; view = key.m_view; - programIdx = kInvalidHandle; - - if (_render->m_view[view].m_fbh.idx != fbh.idx) - { - fbh = _render->m_view[view].m_fbh; - setFrameBuffer(fbh); - } + currentProgram = BGFX_INVALID_HANDLE; - PIX_ENDEVENT(); if (item > 0) { profiler.end(); } + BGFX_D3D9_PROFILER_END(); + BGFX_D3D9_PROFILER_BEGIN(view, kColorView); + profiler.begin(view); - PIX_BEGINEVENT(D3DCOLOR_VIEW, s_viewNameW[view]); + + if (_render->m_view[view].m_fbh.idx != fbh.idx) + { + fbh = _render->m_view[view].m_fbh; + setFrameBuffer(fbh); + } viewState.m_rect = _render->m_view[view].m_rect; const Rect& scissorRect = _render->m_view[view].m_scissor; @@ -3976,6 +4027,7 @@ namespace bgfx { namespace d3d9 if ( (0 | BGFX_STATE_CULL_MASK +// | BGFX_STATE_FRONT_CCW | BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_MASK | BGFX_STATE_WRITE_RGB @@ -4114,18 +4166,18 @@ namespace bgfx { namespace d3d9 bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd; rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); - if (key.m_program != programIdx) + if (key.m_program.idx != currentProgram.idx) { - programIdx = key.m_program; + currentProgram = key.m_program; - if (kInvalidHandle == programIdx) + if (!isValid(currentProgram) ) { device->SetVertexShader(NULL); device->SetPixelShader(NULL); } else { - ProgramD3D9& program = m_program[programIdx]; + ProgramD3D9& program = m_program[currentProgram.idx]; device->SetVertexShader(program.m_vsh->m_vertexShader); device->SetPixelShader(NULL == program.m_fsh ? NULL @@ -4137,9 +4189,9 @@ namespace bgfx { namespace d3d9 constantsChanged = true; } - if (kInvalidHandle != programIdx) + if (isValid(currentProgram) ) { - ProgramD3D9& program = m_program[programIdx]; + ProgramD3D9& program = m_program[currentProgram.idx]; if (constantsChanged) { @@ -4159,7 +4211,7 @@ namespace bgfx { namespace d3d9 } } - viewState.setPredefined<4>(this, view, 0, program, _render, draw); + viewState.setPredefined<4>(this, view, program, _render, draw); } { @@ -4196,7 +4248,7 @@ namespace bgfx { namespace d3d9 currentState.m_instanceDataOffset = draw.m_instanceDataOffset; currentState.m_instanceDataStride = draw.m_instanceDataStride; - const VertexDecl* decls[BGFX_CONFIG_MAX_VERTEX_STREAMS]; + const VertexLayout* layouts[BGFX_CONFIG_MAX_VERTEX_STREAMS]; const bool instanced = true && isValid(draw.m_instanceDataBuffer) @@ -4210,25 +4262,28 @@ namespace bgfx { namespace d3d9 uint32_t numVertices = draw.m_numVertices; uint8_t numStreams = 0; - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask), ++numStreams + ; streamMask >>= 1, idx += 1, ++numStreams ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; - currentState.m_stream[idx].m_decl = draw.m_stream[idx].m_decl; - currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; - currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + currentState.m_stream[idx].m_layoutHandle = draw.m_stream[idx].m_layoutHandle; + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; const uint16_t handle = draw.m_stream[idx].m_handle.idx; const VertexBufferD3D9& vb = m_vertexBuffers[handle]; - const uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = m_vertexDecls[decl]; - const uint32_t stride = vertexDecl.m_stride; + const uint16_t layoutIdx = isValid(draw.m_stream[idx].m_layoutHandle) + ? draw.m_stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx; + const VertexLayout& layout = m_vertexLayouts[layoutIdx]; + const uint32_t stride = layout.m_stride; - decls[numStreams] = &vertexDecl; + layouts[numStreams] = &layout; numVertices = bx::uint32_min(UINT32_MAX == draw.m_numVertices ? vb.m_size/stride @@ -4240,8 +4295,6 @@ namespace bgfx { namespace d3d9 DX_CHECK(device->SetStreamSource(numStreams, vb.m_ptr, 0, stride) ); } - currentState.m_numVertices = numVertices; - if (0 < numStreams) { if (instanced) @@ -4249,12 +4302,12 @@ namespace bgfx { namespace d3d9 const VertexBufferD3D9& inst = m_vertexBuffers[draw.m_instanceDataBuffer.idx]; DX_CHECK(device->SetStreamSourceFreq(numStreams, UINT(D3DSTREAMSOURCE_INSTANCEDATA|1) ) ); DX_CHECK(device->SetStreamSource(numStreams, inst.m_ptr, draw.m_instanceDataOffset, draw.m_instanceDataStride) ); - setInputLayout(numStreams, decls, draw.m_instanceDataStride/16); + setInputLayout(numStreams, layouts, draw.m_instanceDataStride/16); } else { DX_CHECK(device->SetStreamSource(numStreams, NULL, 0, 0) ); - setInputLayout(numStreams, decls, 0); + setInputLayout(numStreams, layouts, 0); } } else @@ -4298,7 +4351,8 @@ namespace bgfx { namespace d3d9 if (UINT32_MAX == draw.m_numIndices) { const IndexBufferD3D9& ib = m_indexBuffers[draw.m_indexBuffer.idx]; - const uint32_t indexSize = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; + const bool isIndex16 = draw.isIndex16(); + const uint32_t indexSize = isIndex16 ? 2 : 4; numIndices = ib.m_size/indexSize; numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; numInstances = draw.m_numInstances; @@ -4369,7 +4423,7 @@ namespace bgfx { namespace d3d9 } } - PIX_ENDEVENT(); + BGFX_D3D9_PROFILER_END(); int64_t timeEnd = bx::getHPCounter(); int64_t frameTime = timeEnd - timeBegin; @@ -4409,12 +4463,13 @@ namespace bgfx { namespace d3d9 perfStats.numCompute = statsKeyType[1]; perfStats.numBlit = _render->m_numBlitItems; perfStats.maxGpuLatency = maxGpuLatency; + perfStats.gpuFrameNum = result.m_frameNum; bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) ); m_nvapi.getMemoryInfo(perfStats.gpuMemoryUsed, perfStats.gpuMemoryMax); if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) { - PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugstats"); + BGFX_D3D9_PROFILER_BEGIN_LITERAL("debugstats", kColorFrame); m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; @@ -4431,8 +4486,14 @@ namespace bgfx { namespace d3d9 tvm.clear(); uint16_t pos = 0; tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f - , " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " + , " %s / " BX_COMPILER_NAME + " / " BX_CPU_NAME + " / " BX_ARCH_NAME + " / " BX_PLATFORM_NAME + " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")" , getRendererName() + , BGFX_API_VERSION + , BGFX_REV_NUMBER ); const D3DADAPTER_IDENTIFIER9& identifier = m_identifier; @@ -4512,15 +4573,15 @@ namespace bgfx { namespace d3d9 blit(this, _textVideoMemBlitter, tvm); - PIX_ENDEVENT(); + BGFX_D3D9_PROFILER_END(); } else if (_render->m_debug & BGFX_DEBUG_TEXT) { - PIX_BEGINEVENT(D3DCOLOR_FRAME, L"debugtext"); + BGFX_D3D9_PROFILER_BEGIN_LITERAL("debugtext", kColorFrame); blit(this, _textVideoMemBlitter, _render->m_textVideoMem); - PIX_ENDEVENT(); + BGFX_D3D9_PROFILER_END(); } device->EndScene(); diff --git a/3rdparty/bgfx/src/renderer_d3d9.h b/3rdparty/bgfx/src/renderer_d3d9.h index 06cd320b96f..0080c474eba 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.h +++ b/3rdparty/bgfx/src/renderer_d3d9.h @@ -1,17 +1,16 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_D3D9_H_HEADER_GUARD #define BGFX_RENDERER_D3D9_H_HEADER_GUARD -#define BGFX_CONFIG_RENDERER_DIRECT3D9EX BX_PLATFORM_WINDOWS +#define BGFX_CONFIG_RENDERER_DIRECT3D9EX (BX_PLATFORM_LINUX || BX_PLATFORM_WINDOWS) -#if BX_PLATFORM_WINDOWS -# include <sal.h> -# include <d3d9.h> -#endif // BX_PLATFORM_ +#include <sal.h> +#include <unknwn.h> +#include <d3d9.h> #ifndef D3DSTREAMSOURCE_INDEXEDDATA # define D3DSTREAMSOURCE_INDEXEDDATA (1<<30) @@ -25,6 +24,24 @@ #include "renderer_d3d.h" #include "nvapi.h" +#define BGFX_D3D9_PROFILER_BEGIN(_view, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + PIX_BEGINEVENT(_abgr, s_viewNameW[_view]); \ + BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_D3D9_PROFILER_BEGIN_LITERAL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + PIX_BEGINEVENT(_abgr, L"" _name); \ + BGFX_PROFILER_BEGIN_LITERAL("" _name, _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_D3D9_PROFILER_END() \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_END(); \ + PIX_ENDEVENT(); \ + BX_MACRO_BLOCK_END + namespace bgfx { namespace d3d9 { # if defined(D3D_DISABLE_9EX) @@ -173,7 +190,7 @@ namespace bgfx { namespace d3d9 { } - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle); + void create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle); void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false) { if (NULL != m_dynamic @@ -214,7 +231,7 @@ namespace bgfx { namespace d3d9 IDirect3DVertexBuffer9* m_ptr; uint8_t* m_dynamic; uint32_t m_size; - VertexDeclHandle m_decl; + VertexLayoutHandle m_layoutHandle; }; struct ShaderD3D9 @@ -428,7 +445,7 @@ namespace bgfx { namespace d3d9 void postReset(); void preReset(); - uint32_t begin(uint32_t _resultIdx); + uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum); void end(uint32_t _idx); bool update(); @@ -439,6 +456,7 @@ namespace bgfx { namespace d3d9 IDirect3DQuery9* m_end; IDirect3DQuery9* m_freq; uint32_t m_resultIdx; + uint32_t m_frameNum; bool m_ready; }; @@ -450,12 +468,14 @@ namespace bgfx { namespace d3d9 m_end = 0; m_frequency = 1; m_pending = 0; + m_frameNum = 0; } uint64_t m_begin; uint64_t m_end; uint64_t m_frequency; uint32_t m_pending; + uint32_t m_frameNum; }; Result m_result[BGFX_CONFIG_MAX_VIEWS+1]; diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp index 7f0afda9a04..ff860faec25 100644 --- a/3rdparty/bgfx/src/renderer_gl.cpp +++ b/3rdparty/bgfx/src/renderer_gl.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -9,11 +9,20 @@ # include "renderer_gl.h" # include <bx/timer.h> # include <bx/uint32_t.h> +# include "emscripten.h" namespace bgfx { namespace gl { static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + inline void setViewType(ViewId _view, const bx::StringView _str) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION || BGFX_CONFIG_PROFILER) ) + { + bx::memCopy(&s_viewName[_view][3], _str.getPtr(), _str.getLength() ); + } + } + struct PrimInfo { GLenum m_type; @@ -177,97 +186,139 @@ namespace bgfx { namespace gl GLenum m_internalFmt; GLenum m_internalFmtSrgb; GLenum m_fmt; + GLenum m_fmtSrgb; GLenum m_type; - bool m_supported; + bool m_supported; + GLint m_mapping[4]; }; +// In desktop OpenGL 4+ and OpenGL ES 3.0+, specific GL formats GL_x_INTEGER are used for integer textures. +// For older desktop OpenGL contexts, GL names without _INTEGER suffix were used. +// See http://docs.gl/gl4/glTexImage2D, http://docs.gl/gl3/glTexImage2D, http://docs.gl/es3/glTexImage2D +#if BGFX_CONFIG_RENDERER_OPENGL >= 40 || BGFX_CONFIG_RENDERER_OPENGLES +# define RED_INTEGER GL_RED_INTEGER +# define RG_INTEGER GL_RG_INTEGER +# define RGB_INTEGER GL_RGB_INTEGER +# define RGBA_INTEGER GL_RGBA_INTEGER +#else +# define RED_INTEGER GL_RED +# define RG_INTEGER GL_RG +# define RGB_INTEGER GL_RGB +# define RGBA_INTEGER GL_RGBA +#endif + static TextureFormatInfo s_textureFormat[] = { - { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false }, // BC1 - { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false }, // BC2 - { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false }, // BC3 - { GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false }, // BC4 - { GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false }, // BC5 - { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false }, // BC6H - { GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false }, // BC7 - { GL_ETC1_RGB8_OES, GL_ZERO, GL_ETC1_RGB8_OES, GL_ZERO, false }, // ETC1 - { GL_COMPRESSED_RGB8_ETC2, GL_ZERO, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false }, // ETC2 - { GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false }, // ETC2A - { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false }, // ETC2A1 - { GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12 - { GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14 - { GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false }, // PTC12A - { GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false }, // PTC14A - { GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false }, // PTC22 - { GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false }, // PTC24 - { GL_ATC_RGB_AMD, GL_ZERO, GL_ATC_RGB_AMD, GL_ZERO, false }, // ATC - { GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, false }, // ATCE - { GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, false }, // ATCI - { GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_COMPRESSED_SRGB8_ASTC_4x4_KHR, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_ZERO, false }, // ASTC4x4 - { GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_COMPRESSED_SRGB8_ASTC_5x5_KHR, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_ZERO, false }, // ASTC5x5 - { GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_COMPRESSED_SRGB8_ASTC_6x6_KHR, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_ZERO, false }, // ASTC6x6 - { GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_COMPRESSED_SRGB8_ASTC_8x5_KHR, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_ZERO, false }, // ASTC8x5 - { GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_COMPRESSED_SRGB8_ASTC_8x6_KHR, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_ZERO, false }, // ASTC8x6 - { GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_COMPRESSED_SRGB8_ASTC_10x5_KHR, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_ZERO, false }, // ASTC10x5 - { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // Unknown - { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // R1 - { GL_ALPHA, GL_ZERO, GL_ALPHA, GL_UNSIGNED_BYTE, false }, // A8 - { GL_R8, GL_ZERO, GL_RED, GL_UNSIGNED_BYTE, false }, // R8 - { GL_R8I, GL_ZERO, GL_RED, GL_BYTE, false }, // R8I - { GL_R8UI, GL_ZERO, GL_RED, GL_UNSIGNED_BYTE, false }, // R8U - { GL_R8_SNORM, GL_ZERO, GL_RED, GL_BYTE, false }, // R8S - { GL_R16, GL_ZERO, GL_RED, GL_UNSIGNED_SHORT, false }, // R16 - { GL_R16I, GL_ZERO, GL_RED, GL_SHORT, false }, // R16I - { GL_R16UI, GL_ZERO, GL_RED, GL_UNSIGNED_SHORT, false }, // R16U - { GL_R16F, GL_ZERO, GL_RED, GL_HALF_FLOAT, false }, // R16F - { GL_R16_SNORM, GL_ZERO, GL_RED, GL_SHORT, false }, // R16S - { GL_R32I, GL_ZERO, GL_RED, GL_INT, false }, // R32I - { GL_R32UI, GL_ZERO, GL_RED, GL_UNSIGNED_INT, false }, // R32U - { GL_R32F, GL_ZERO, GL_RED, GL_FLOAT, false }, // R32F - { GL_RG8, GL_ZERO, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8 - { GL_RG8I, GL_ZERO, GL_RG, GL_BYTE, false }, // RG8I - { GL_RG8UI, GL_ZERO, GL_RG, GL_UNSIGNED_BYTE, false }, // RG8U - { GL_RG8_SNORM, GL_ZERO, GL_RG, GL_BYTE, false }, // RG8S - { GL_RG16, GL_ZERO, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16 - { GL_RG16I, GL_ZERO, GL_RG, GL_SHORT, false }, // RG16I - { GL_RG16UI, GL_ZERO, GL_RG, GL_UNSIGNED_SHORT, false }, // RG16U - { GL_RG16F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG16F - { GL_RG16_SNORM, GL_ZERO, GL_RG, GL_SHORT, false }, // RG16S - { GL_RG32I, GL_ZERO, GL_RG, GL_INT, false }, // RG32I - { GL_RG32UI, GL_ZERO, GL_RG, GL_UNSIGNED_INT, false }, // RG32U - { GL_RG32F, GL_ZERO, GL_RG, GL_FLOAT, false }, // RG32F - { GL_RGB8, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, false }, // RGB8 - { GL_RGB8I, GL_ZERO, GL_RGB, GL_BYTE, false }, // RGB8I - { GL_RGB8UI, GL_ZERO, GL_RGB, GL_UNSIGNED_BYTE, false }, // RGB8U - { GL_RGB8_SNORM, GL_ZERO, GL_RGB, GL_BYTE, false }, // RGB8S - { GL_RGB9_E5, GL_ZERO, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, false }, // RGB9E5F - { GL_RGBA8, GL_SRGB8_ALPHA8, GL_BGRA, GL_UNSIGNED_BYTE, false }, // BGRA8 - { GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8 - { GL_RGBA8I, GL_ZERO, GL_RGBA, GL_BYTE, false }, // RGBA8I - { GL_RGBA8UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_BYTE, false }, // RGBA8U - { GL_RGBA8_SNORM, GL_ZERO, GL_RGBA, GL_BYTE, false }, // RGBA8S - { GL_RGBA16, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT, false }, // RGBA16 - { GL_RGBA16I, GL_ZERO, GL_RGBA, GL_SHORT, false }, // RGBA16I - { GL_RGBA16UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT, false }, // RGBA16U - { GL_RGBA16F, GL_ZERO, GL_RGBA, GL_HALF_FLOAT, false }, // RGBA16F - { GL_RGBA16_SNORM, GL_ZERO, GL_RGBA, GL_SHORT, false }, // RGBA16S - { GL_RGBA32I, GL_ZERO, GL_RGBA, GL_INT, false }, // RGBA32I - { GL_RGBA32UI, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT, false }, // RGBA32U - { GL_RGBA32F, GL_ZERO, GL_RGBA, GL_FLOAT, false }, // RGBA32F - { GL_RGB565, GL_ZERO, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false }, // R5G6B5 - { GL_RGBA4, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false }, // RGBA4 - { GL_RGB5_A1, GL_ZERO, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false }, // RGB5A1 - { GL_RGB10_A2, GL_ZERO, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false }, // RGB10A2 - { GL_R11F_G11F_B10F, GL_ZERO, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false }, // RG11B10F - { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false }, // UnknownDepth - { GL_DEPTH_COMPONENT16, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false }, // D16 - { GL_DEPTH_COMPONENT24, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D24 - { GL_DEPTH24_STENCIL8, GL_ZERO, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false }, // D24S8 - { GL_DEPTH_COMPONENT32, GL_ZERO, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false }, // D32 - { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D16F - { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D24F - { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_FLOAT, false }, // D32F - { GL_STENCIL_INDEX8, GL_ZERO, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false }, // D0S8 +#define $_ -1 +#define $0 GL_ZERO +#define $1 GL_ONE +#define $R GL_RED +#define $G GL_GREEN +#define $B GL_BLUE +#define $A GL_ALPHA + { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC1 + { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC2 + { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC3 + { GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_COMPRESSED_LUMINANCE_LATC1_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC4 + { GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC5 + { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC6H + { GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_ZERO, false, { $_, $_, $_, $_ } }, // BC7 + { GL_ETC1_RGB8_OES, GL_ZERO, GL_ETC1_RGB8_OES, GL_ETC1_RGB8_OES, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC1 + { GL_COMPRESSED_RGB8_ETC2, GL_ZERO, GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC2 + { GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC2A + { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_ZERO, false, { $_, $_, $_, $_ } }, // ETC2A1 + { GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC12 + { GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC14 + { GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC12A + { GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC14A + { GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC22 + { GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG, GL_ZERO, false, { $_, $_, $_, $_ } }, // PTC24 + { GL_ATC_RGB_AMD, GL_ZERO, GL_ATC_RGB_AMD, GL_ATC_RGB_AMD, GL_ZERO, false, { $_, $_, $_, $_ } }, // ATC + { GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD, GL_ZERO, false, { $_, $_, $_, $_ } }, // ATCE + { GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD, GL_ZERO, false, { $_, $_, $_, $_ } }, // ATCI + { GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_COMPRESSED_SRGB8_ASTC_4x4_KHR, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC4x4 + { GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_COMPRESSED_SRGB8_ASTC_5x4_KHR, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC5x4 + { GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_COMPRESSED_SRGB8_ASTC_5x5_KHR, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC5x5 + { GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_COMPRESSED_SRGB8_ASTC_6x5_KHR, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC6x5 + { GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_COMPRESSED_SRGB8_ASTC_6x6_KHR, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC6x6 + { GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_COMPRESSED_SRGB8_ASTC_8x5_KHR, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC8x5 + { GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_COMPRESSED_SRGB8_ASTC_8x6_KHR, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC8x6 + { GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_COMPRESSED_SRGB8_ASTC_8x8_KHR, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC8x8 + { GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_COMPRESSED_SRGB8_ASTC_10x5_KHR, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x5 + { GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_COMPRESSED_SRGB8_ASTC_10x6_KHR, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x6 + { GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_COMPRESSED_SRGB8_ASTC_10x8_KHR, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x8 + { GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_COMPRESSED_SRGB8_ASTC_10x10_KHR, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC10x10 + { GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_COMPRESSED_SRGB8_ASTC_12x10_KHR, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC12x10 + { GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_COMPRESSED_SRGB8_ASTC_12x12_KHR, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_ZERO, false, { $_, $_, $_, $_ } }, // ASTC12x12 + { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false, { $_, $_, $_, $_ } }, // Unknown + { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false, { $_, $_, $_, $_ } }, // R1 + { GL_ALPHA, GL_ZERO, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // A8 + { GL_R8, GL_ZERO, GL_RED, GL_RED, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // R8 + { GL_R8I, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // R8I + { GL_R8UI, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // R8U + { GL_R8_SNORM, GL_ZERO, GL_RED, GL_RED, GL_BYTE, false, { $_, $_, $_, $_ } }, // R8S + { GL_R16, GL_ZERO, GL_RED, GL_RED, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // R16 + { GL_R16I, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_SHORT, false, { $_, $_, $_, $_ } }, // R16I + { GL_R16UI, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // R16U + { GL_R16F, GL_ZERO, GL_RED, GL_RED, GL_HALF_FLOAT, false, { $_, $_, $_, $_ } }, // R16F + { GL_R16_SNORM, GL_ZERO, GL_RED, GL_RED, GL_SHORT, false, { $_, $_, $_, $_ } }, // R16S + { GL_R32I, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_INT, false, { $_, $_, $_, $_ } }, // R32I + { GL_R32UI, GL_ZERO, RED_INTEGER, GL_RED_INTEGER, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // R32U + { GL_R32F, GL_ZERO, GL_RED, GL_RED, GL_FLOAT, false, { $_, $_, $_, $_ } }, // R32F + { GL_RG8, GL_ZERO, GL_RG, GL_RG, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RG8 + { GL_RG8I, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // RG8I + { GL_RG8UI, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RG8U + { GL_RG8_SNORM, GL_ZERO, GL_RG, GL_RG, GL_BYTE, false, { $_, $_, $_, $_ } }, // RG8S + { GL_RG16, GL_ZERO, GL_RG, GL_RG, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RG16 + { GL_RG16I, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_SHORT, false, { $_, $_, $_, $_ } }, // RG16I + { GL_RG16UI, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RG16U + { GL_RG16F, GL_ZERO, GL_RG, GL_RG, GL_HALF_FLOAT, false, { $_, $_, $_, $_ } }, // RG16F + { GL_RG16_SNORM, GL_ZERO, GL_RG, GL_RG, GL_SHORT, false, { $_, $_, $_, $_ } }, // RG16S + { GL_RG32I, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_INT, false, { $_, $_, $_, $_ } }, // RG32I + { GL_RG32UI, GL_ZERO, RG_INTEGER, GL_RG_INTEGER, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // RG32U + { GL_RG32F, GL_ZERO, GL_RG, GL_RG, GL_FLOAT, false, { $_, $_, $_, $_ } }, // RG32F + { GL_RGB8, GL_SRGB8, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGB8 + { GL_RGB8I, GL_ZERO, RGB_INTEGER, GL_RGB_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGB8I + { GL_RGB8UI, GL_ZERO, RGB_INTEGER, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGB8U + { GL_RGB8_SNORM, GL_ZERO, GL_RGB, GL_RGB, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGB8S + { GL_RGB9_E5, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, false, { $_, $_, $_, $_ } }, // RGB9E5F + { GL_RGBA8, GL_SRGB8_ALPHA8, GL_BGRA, GL_BGRA, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // BGRA8 + { GL_RGBA8, GL_SRGB8_ALPHA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8 + { GL_RGBA8I, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8I + { GL_RGBA8UI, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8U + { GL_RGBA8_SNORM, GL_ZERO, GL_RGBA, GL_RGBA, GL_BYTE, false, { $_, $_, $_, $_ } }, // RGBA8S + { GL_RGBA16, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16 + { GL_RGBA16I, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16I + { GL_RGBA16UI, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16U + { GL_RGBA16F, GL_ZERO, GL_RGBA, GL_RGBA, GL_HALF_FLOAT, false, { $_, $_, $_, $_ } }, // RGBA16F + { GL_RGBA16_SNORM, GL_ZERO, GL_RGBA, GL_RGBA, GL_SHORT, false, { $_, $_, $_, $_ } }, // RGBA16S + { GL_RGBA32I, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_INT, false, { $_, $_, $_, $_ } }, // RGBA32I + { GL_RGBA32UI, GL_ZERO, RGBA_INTEGER, GL_RGBA_INTEGER, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // RGBA32U + { GL_RGBA32F, GL_ZERO, GL_RGBA, GL_RGBA, GL_FLOAT, false, { $_, $_, $_, $_ } }, // RGBA32F + { GL_RGB565, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false, { $_, $_, $_, $_ } }, // B5G6R5 + { GL_RGB565, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, false, { $_, $_, $_, $_ } }, // R5G6B5 + { GL_RGBA4, GL_ZERO, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false, { $_, $_, $_, $_ } }, // BGRA4 + { GL_RGBA4, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV, false, { $_, $_, $_, $_ } }, // RGBA4 + { GL_RGB5_A1, GL_ZERO, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false, { $_, $_, $_, $_ } }, // BGR5A1 + { GL_RGB5_A1, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV, false, { $_, $_, $_, $_ } }, // RGB5A1 + { GL_RGB10_A2, GL_ZERO, GL_RGBA, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, false, { $_, $_, $_, $_ } }, // RGB10A2 + { GL_R11F_G11F_B10F, GL_ZERO, GL_RGB, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, false, { $_, $_, $_, $_ } }, // RG11B10F + { GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO, false, { $_, $_, $_, $_ } }, // UnknownDepth + { GL_DEPTH_COMPONENT16, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, false, { $_, $_, $_, $_ } }, // D16 + { GL_DEPTH_COMPONENT24, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // D24 + { GL_DEPTH24_STENCIL8, GL_ZERO, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, false, { $_, $_, $_, $_ } }, // D24S8 + { GL_DEPTH_COMPONENT32, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, false, { $_, $_, $_, $_ } }, // D32 + { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false, { $_, $_, $_, $_ } }, // D16F + { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false, { $_, $_, $_, $_ } }, // D24F + { GL_DEPTH_COMPONENT32F, GL_ZERO, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_FLOAT, false, { $_, $_, $_, $_ } }, // D32F + { GL_STENCIL_INDEX8, GL_ZERO, GL_STENCIL_INDEX, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, false, { $_, $_, $_, $_ } }, // D0S8 +#undef $_ +#undef $0 +#undef $1 +#undef $R +#undef $G +#undef $B +#undef $A }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); @@ -296,11 +347,19 @@ namespace bgfx { namespace gl GL_ZERO, // ATCE GL_ZERO, // ATCI GL_ZERO, // ASTC4x4 + GL_ZERO, // ASTC5x4 GL_ZERO, // ASTC5x5 + GL_ZERO, // ASTC6x5 GL_ZERO, // ASTC6x6 GL_ZERO, // ASTC8x5 GL_ZERO, // ASTC8x6 + GL_ZERO, // ASTC8x8 GL_ZERO, // ASTC10x5 + GL_ZERO, // ASTC10x6 + GL_ZERO, // ASTC10x8 + GL_ZERO, // ASTC10x10 + GL_ZERO, // ASTC12x10 + GL_ZERO, // ASTC12x12 GL_ZERO, // Unknown GL_ZERO, // R1 GL_ALPHA, // A8 @@ -346,8 +405,11 @@ namespace bgfx { namespace gl GL_RGBA32I, // RGBA32I GL_RGBA32UI, // RGBA32U GL_RGBA32F, // RGBA32F + GL_RGB565, // B5G6R5 GL_RGB565, // R5G6B5 + GL_RGBA4, // BGRA4 GL_RGBA4, // RGBA4 + GL_RGB5_A1, // BGR5A1 GL_RGB5_A1, // RGB5A1 GL_RGB10_A2, // RGB10A2 GL_R11F_G11F_B10F, // RG11B10F @@ -386,11 +448,19 @@ namespace bgfx { namespace gl GL_ZERO, // ATCE GL_ZERO, // ATCI GL_ZERO, // ASTC4x4 + GL_ZERO, // ASTC5x4 GL_ZERO, // ASTC5x5 + GL_ZERO, // ASTC6x5 GL_ZERO, // ASTC6x6 GL_ZERO, // ASTC8x5 GL_ZERO, // ASTC8x6 + GL_ZERO, // ASTC8x8 GL_ZERO, // ASTC10x5 + GL_ZERO, // ASTC10x6 + GL_ZERO, // ASTC10x8 + GL_ZERO, // ASTC10x10 + GL_ZERO, // ASTC12x10 + GL_ZERO, // ASTC12x12 GL_ZERO, // Unknown GL_ZERO, // R1 GL_ALPHA, // A8 @@ -436,8 +506,11 @@ namespace bgfx { namespace gl GL_RGBA32I, // RGBA32I GL_RGBA32UI, // RGBA32U GL_RGBA32F, // RGBA32F + GL_RGB565, // B5G6R5 GL_RGB565, // R5G6B5 + GL_RGBA4, // BGRA4 GL_RGBA4, // RGBA4 + GL_RGB5_A1, // BGR5A1 GL_RGB5_A1, // RGB5A1 GL_RGB10_A2, // RGB10A2 GL_R11F_G11F_B10F, // RG11B10F @@ -490,6 +563,7 @@ namespace bgfx { namespace gl ARB_get_program_binary, ARB_half_float_pixel, ARB_half_float_vertex, + ARB_indirect_parameters, ARB_instanced_arrays, ARB_internalformat_query, ARB_internalformat_query2, @@ -500,12 +574,14 @@ namespace bgfx { namespace gl ARB_occlusion_query, ARB_occlusion_query2, ARB_program_interface_query, + ARB_provoking_vertex, ARB_sampler_objects, ARB_seamless_cube_map, ARB_shader_bit_encoding, ARB_shader_image_load_store, ARB_shader_storage_buffer_object, ARB_shader_texture_lod, + ARB_shader_viewport_layer_array, ARB_texture_compression_bptc, ARB_texture_compression_rgtc, ARB_texture_cube_map_array, @@ -576,6 +652,8 @@ namespace bgfx { namespace gl EXT_texture_type_2_10_10_10_REV, EXT_timer_query, EXT_unpack_subimage, + EXT_sRGB, + EXT_multisampled_render_to_texture, GOOGLE_depth_texture, @@ -597,6 +675,8 @@ namespace bgfx { namespace gl NV_conservative_raster, NV_copy_image, NV_draw_buffers, + NV_draw_instanced, + NV_instanced_arrays, NV_occlusion_query, NV_texture_border_clamp, NVX_gpu_memory_info, @@ -608,6 +688,7 @@ namespace bgfx { namespace gl OES_depth_texture, OES_element_index_uint, OES_fragment_precision_high, + OES_fbo_render_mipmap, OES_get_program_binary, OES_required_internalformat, OES_packed_depth_stencil, @@ -700,6 +781,7 @@ namespace bgfx { namespace gl { "ARB_get_program_binary", BGFX_CONFIG_RENDERER_OPENGL >= 41, true }, { "ARB_half_float_pixel", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "ARB_half_float_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_indirect_parameters", BGFX_CONFIG_RENDERER_OPENGL >= 46, true }, { "ARB_instanced_arrays", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_internalformat_query", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, { "ARB_internalformat_query2", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, @@ -710,12 +792,14 @@ namespace bgfx { namespace gl { "ARB_occlusion_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_occlusion_query2", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_program_interface_query", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, + { "ARB_provoking_vertex", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, { "ARB_sampler_objects", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_seamless_cube_map", BGFX_CONFIG_RENDERER_OPENGL >= 32, true }, { "ARB_shader_bit_encoding", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "ARB_shader_image_load_store", BGFX_CONFIG_RENDERER_OPENGL >= 42, true }, { "ARB_shader_storage_buffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 43, true }, { "ARB_shader_texture_lod", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, + { "ARB_shader_viewport_layer_array", false, true }, { "ARB_texture_compression_bptc", BGFX_CONFIG_RENDERER_OPENGL >= 44, true }, { "ARB_texture_compression_rgtc", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "ARB_texture_cube_map_array", BGFX_CONFIG_RENDERER_OPENGL >= 40, true }, @@ -760,7 +844,7 @@ namespace bgfx { namespace gl { "EXT_framebuffer_blit", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "EXT_framebuffer_object", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, { "EXT_framebuffer_sRGB", BGFX_CONFIG_RENDERER_OPENGL >= 30, true }, - { "EXT_gpu_shader4", false, true }, + { "EXT_gpu_shader4", BGFX_CONFIG_RENDERER_OPENGL >= 31, true }, { "EXT_multi_draw_indirect", false, true }, // GLES3.1 extension. { "EXT_occlusion_query_boolean", false, true }, // GLES2 extension. { "EXT_packed_float", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, @@ -786,6 +870,8 @@ namespace bgfx { namespace gl { "EXT_texture_type_2_10_10_10_REV", false, true }, { "EXT_timer_query", BGFX_CONFIG_RENDERER_OPENGL >= 33, true }, { "EXT_unpack_subimage", false, true }, + { "EXT_sRGB", false, true }, // GLES2 extension. + { "EXT_multisampled_render_to_texture", false, true }, // GLES2 extension. { "GOOGLE_depth_texture", false, true }, @@ -807,6 +893,8 @@ namespace bgfx { namespace gl { "NV_conservative_raster", false, true }, { "NV_copy_image", false, true }, { "NV_draw_buffers", false, true }, // GLES2 extension. + { "NV_draw_instanced", false, true }, // GLES2 extension. + { "NV_instanced_arrays", false, true }, // GLES2 extension. { "NV_occlusion_query", false, true }, { "NV_texture_border_clamp", false, true }, // GLES2 extension. { "NVX_gpu_memory_info", false, true }, @@ -818,6 +906,7 @@ namespace bgfx { namespace gl { "OES_depth_texture", false, true }, { "OES_element_index_uint", false, true }, { "OES_fragment_precision_high", false, true }, + { "OES_fbo_render_mipmap", false, true }, { "OES_get_program_binary", false, true }, { "OES_required_internalformat", false, true }, { "OES_packed_depth_stencil", false, true }, @@ -882,6 +971,13 @@ namespace bgfx { namespace gl NULL }; + static const char* s_ARB_shader_viewport_layer_array[] = + { + "gl_ViewportIndex", + "gl_Layer", + NULL + }; + static const char* s_EXT_shadow_samplers[] = { "shadow2D", @@ -1005,6 +1101,14 @@ namespace bgfx { namespace gl { } + static void GL_APIENTRY stubPushDebugGroup(GLenum /*_source*/, GLuint /*_id*/, GLsizei /*_length*/, const char* /*_message*/) + { + } + + static void GL_APIENTRY stubPopDebugGroup() + { + } + static void GL_APIENTRY stubObjectLabel(GLenum /*_identifier*/, GLuint /*_name*/, GLsizei /*_length*/, const char* /*_label*/) { } @@ -1013,20 +1117,30 @@ namespace bgfx { namespace gl { } - static void GL_APIENTRY stubMultiDrawArraysIndirect(GLenum _mode, const void* _indirect, GLsizei _drawcount, GLsizei _stride) + static void GL_APIENTRY stubFramebufferTexture(GLenum _target, GLenum _attachment, GLuint _texture, GLint _level) + { + GL_CHECK(glFramebufferTextureLayer(_target + , _attachment + , _texture + , _level + , 0 + ) ); + } + + static void GL_APIENTRY stubMultiDrawArraysIndirect(GLenum _mode, const void* _indirect, GLsizei _drawCount, GLsizei _stride) { const uint8_t* args = (const uint8_t*)_indirect; - for (GLsizei ii = 0; ii < _drawcount; ++ii) + for (GLsizei ii = 0; ii < _drawCount; ++ii) { GL_CHECK(glDrawArraysIndirect(_mode, (void*)args) ); args += _stride; } } - static void GL_APIENTRY stubMultiDrawElementsIndirect(GLenum _mode, GLenum _type, const void* _indirect, GLsizei _drawcount, GLsizei _stride) + static void GL_APIENTRY stubMultiDrawElementsIndirect(GLenum _mode, GLenum _type, const void* _indirect, GLsizei _drawCount, GLsizei _stride) { const uint8_t* args = (const uint8_t*)_indirect; - for (GLsizei ii = 0; ii < _drawcount; ++ii) + for (GLsizei ii = 0; ii < _drawCount; ++ii) { GL_CHECK(glDrawElementsIndirect(_mode, _type, (void*)args) ); args += _stride; @@ -1039,10 +1153,22 @@ namespace bgfx { namespace gl typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height); + void flushGlError() + { + for (GLenum err = glGetError(); err != 0; err = glGetError() ); + } + + GLenum getGlError() + { + GLenum err = glGetError(); + flushGlError(); + return err; + } + static const char* getGLString(GLenum _name) { const char* str = (const char*)glGetString(_name); - glGetError(); // ignore error if glGetString returns NULL. + getGlError(); // ignore error if glGetString returns NULL. if (NULL != str) { return str; @@ -1054,7 +1180,7 @@ namespace bgfx { namespace gl static uint32_t getGLStringHash(GLenum _name) { const char* str = (const char*)glGetString(_name); - glGetError(); // ignore error if glGetString returns NULL. + getGlError(); // ignore error if glGetString returns NULL. if (NULL != str) { return bx::hash<bx::HashMurmur2A>(str, (uint32_t)bx::strLen(str) ); @@ -1139,22 +1265,97 @@ namespace bgfx { namespace gl { GLint result = 0; glGetIntegerv(_pname, &result); - GLenum err = glGetError(); + GLenum err = getGlError(); BX_WARN(0 == err, "glGetIntegerv(0x%04x, ...) failed with GL error: 0x%04x.", _pname, err); return 0 == err ? result : 0; } + static uint64_t s_currentlyEnabledVertexAttribArrays = 0; + static uint64_t s_vertexAttribArraysPendingDisable = 0; + static uint64_t s_vertexAttribArraysPendingEnable = 0; + + void lazyEnableVertexAttribArray(GLuint index) + { + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + if (index >= 64) + { + // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize + // out redundant API calls to glEnable/DisableVertexAttribArray. + GL_CHECK(glEnableVertexAttribArray(index) ); + return; + } + + const uint64_t mask = UINT64_C(1) << index; + s_vertexAttribArraysPendingEnable |= mask & (~s_currentlyEnabledVertexAttribArrays); + s_vertexAttribArraysPendingDisable &= ~mask; + } + else + { + GL_CHECK(glEnableVertexAttribArray(index) ); + } + } + + void lazyDisableVertexAttribArray(GLuint index) + { + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + if (index >= 64) + { + // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize + // out redundant API calls to glEnable/DisableVertexAttribArray. + GL_CHECK(glDisableVertexAttribArray(index) ); + return; + } + + const uint64_t mask = UINT64_C(1) << index; + s_vertexAttribArraysPendingDisable |= mask & s_currentlyEnabledVertexAttribArrays; + s_vertexAttribArraysPendingEnable &= ~mask; + } + else + { + GL_CHECK(glDisableVertexAttribArray(index) ); + } + } + + void applyLazyEnabledVertexAttributes() + { + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + while (s_vertexAttribArraysPendingDisable) + { + uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingDisable); + uint64_t mask = ~(UINT64_C(1) << index); + s_vertexAttribArraysPendingDisable &= mask; + s_currentlyEnabledVertexAttribArrays &= mask; + GL_CHECK(glDisableVertexAttribArray(index) ); + } + + while (s_vertexAttribArraysPendingEnable) + { + uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingEnable); + uint64_t mask = UINT64_C(1) << index; + s_vertexAttribArraysPendingEnable &= ~mask; + s_currentlyEnabledVertexAttribArrays |= mask; + GL_CHECK(glEnableVertexAttribArray(index) ); + } + } + } + void setTextureFormat(TextureFormat::Enum _format, GLenum _internalFmt, GLenum _fmt, GLenum _type = GL_ZERO) { TextureFormatInfo& tfi = s_textureFormat[_format]; tfi.m_internalFmt = _internalFmt; tfi.m_fmt = _fmt; + tfi.m_fmtSrgb = _fmt; tfi.m_type = _type; } - void flushGlError() + void setTextureFormatSrgb(TextureFormat::Enum _format, GLenum _internalFmtSrgb, GLenum _fmtSrgb) { - for (GLenum err = glGetError(); err != 0; err = glGetError() ); + TextureFormatInfo& tfi = s_textureFormat[_format]; + tfi.m_internalFmtSrgb = _internalFmtSrgb; + tfi.m_fmtSrgb = _fmtSrgb; } static void texSubImage( @@ -1409,6 +1610,10 @@ namespace bgfx { namespace gl ? tfi.m_internalFmtSrgb : tfi.m_internalFmt ; + GLenum fmt = _srgb + ? tfi.m_fmtSrgb + : tfi.m_fmt + ; GLsizei bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(_format) ); GLsizei size = (_dim*_dim*bpp)/8; @@ -1441,7 +1646,7 @@ namespace bgfx { namespace gl uint32_t block = bx::uint32_max(4, dim); size = (block*block*bpp)/8; compressedTexImage(target, ii, internalFmt, dim, dim, 0, 0, size, data); - err |= glGetError(); + err |= getGlError(); } } else @@ -1450,14 +1655,164 @@ namespace bgfx { namespace gl { dim = bx::uint32_max(1, dim); size = (dim*dim*bpp)/8; - texImage(target, 0, ii, internalFmt, dim, dim, 0, 0, tfi.m_fmt, tfi.m_type, data); - err |= glGetError(); + texImage(target, 0, ii, internalFmt, dim, dim, 0, 0, fmt, tfi.m_type, data); + err |= getGlError(); } } return err; } +#if BX_PLATFORM_EMSCRIPTEN + static bool isTextureFormatValidPerSpec( + TextureFormat::Enum _format + , bool _srgb + , bool _mipAutogen + ) + { + // Avoid creating test textures for WebGL, that causes error noise in the browser + // console; instead examine the supported texture formats from the spec. + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); + + EmscriptenWebGLContextAttributes attrs; + EMSCRIPTEN_CHECK(emscripten_webgl_get_context_attributes(ctx, &attrs) ); + + const int glesVersion = attrs.majorVersion + 1; + + switch(_format) + { + case TextureFormat::A8: + case TextureFormat::R8: // Luminance + case TextureFormat::B5G6R5: + case TextureFormat::R5G6B5: + case TextureFormat::BGRA4: + case TextureFormat::RGBA4: + case TextureFormat::BGR5A1: + case TextureFormat::RGB5A1: + // GLES2 formats without sRGB. + return !_srgb; + + case TextureFormat::D16: + // GLES2 formats without sRGB, depth textures do not support mipmaps. + return !_srgb + && !_mipAutogen + ; + + case TextureFormat::R16F: + case TextureFormat::R32F: + case TextureFormat::RG8: + case TextureFormat::RG16F: + case TextureFormat::RG32F: + case TextureFormat::RGB10A2: + case TextureFormat::RG11B10F: + // GLES3 formats without sRGB + return !_srgb + && glesVersion >= 3 + ; + + case TextureFormat::R8I: + case TextureFormat::R8U: + case TextureFormat::R16I: + case TextureFormat::R16U: + case TextureFormat::R32I: + case TextureFormat::R32U: + case TextureFormat::RG8I: + case TextureFormat::RG8U: + case TextureFormat::RG16I: + case TextureFormat::RG16U: + case TextureFormat::RG32I: + case TextureFormat::RG32U: + case TextureFormat::RGB8I: + case TextureFormat::RGB8U: + case TextureFormat::RGBA8I: + case TextureFormat::RGBA8U: + case TextureFormat::RGBA16I: + case TextureFormat::RGBA16U: + case TextureFormat::RGBA32I: + case TextureFormat::RGBA32U: + case TextureFormat::D32F: + case TextureFormat::R8S: + case TextureFormat::RG8S: + case TextureFormat::RGB8S: + case TextureFormat::RGBA8S: + case TextureFormat::RGB9E5F: + // GLES3 formats without sRGB that are not texture filterable or color renderable. + return !_srgb && glesVersion >= 3 + && !_mipAutogen + ; + + case TextureFormat::D24: + case TextureFormat::D24S8: + case TextureFormat::D32: + // GLES3 formats without sRGB, depth textures do not support mipmaps. + return !_srgb && !_mipAutogen + && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "WEBGL_depth_texture") ) + ; + + case TextureFormat::D16F: + case TextureFormat::D24F: + // GLES3 depth formats without sRGB, depth textures do not support mipmaps. + return !_srgb + && !_mipAutogen + && glesVersion >= 3 + ; + + case TextureFormat::RGBA16F: + case TextureFormat::RGBA32F: + // GLES3 formats without sRGB + return !_srgb + && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "OES_texture_half_float") ) + ; + + case TextureFormat::RGB8: + case TextureFormat::RGBA8: + // sRGB formats + return !_srgb + || glesVersion >= 3 + || emscripten_webgl_enable_extension(ctx, "EXT_sRGB") + ; + + case TextureFormat::BC1: + case TextureFormat::BC2: + case TextureFormat::BC3: + return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_s3tc") + && (!_srgb || emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_s3tc_srgb") ) + ; + + case TextureFormat::PTC12: + case TextureFormat::PTC14: + case TextureFormat::PTC12A: + case TextureFormat::PTC14A: + return !_srgb + && emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_pvrtc") + ; + + case TextureFormat::ETC1: + return !_srgb + && emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc1") + ; + + case TextureFormat::ETC2: + case TextureFormat::ETC2A: + case TextureFormat::ETC2A1: + return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc"); + + case TextureFormat::ASTC4x4: + case TextureFormat::ASTC5x5: + case TextureFormat::ASTC6x6: + case TextureFormat::ASTC8x5: + case TextureFormat::ASTC8x6: + case TextureFormat::ASTC10x5: + return emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_astc"); + + default: + break; + } + + return false; + } +#endif // BX_PLATFORM_EMSCRIPTEN + static bool isTextureFormatValid( TextureFormat::Enum _format , bool _srgb = false @@ -1466,6 +1821,13 @@ namespace bgfx { namespace gl , GLsizei _dim = 16 ) { +#if BX_PLATFORM_EMSCRIPTEN + // On web platform read the validity of textures based on the available GL context and extensions + // to avoid developer unfriendly console error noise that would come from probing. + BX_UNUSED(_array, _dim); + return isTextureFormatValidPerSpec(_format, _srgb, _mipAutogen); +#else + // On other platforms probe the supported textures. const TextureFormatInfo& tfi = s_textureFormat[_format]; GLenum internalFmt = _srgb ? tfi.m_internalFmtSrgb @@ -1476,8 +1838,6 @@ namespace bgfx { namespace gl return false; } -BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); - const GLenum target = _array ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D @@ -1491,13 +1851,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (_array) { glTexStorage3D(target - , 1 + GLsizei(bx::log2(float(_dim) ) ) + , 1 + GLsizei(bx::log2( (int32_t)_dim) ) , internalFmt , _dim , _dim , _dim ); - err = glGetError(); + err = getGlError(); } if (0 == err) @@ -1516,13 +1876,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); && _mipAutogen) { glGenerateMipmap(target); - err = glGetError(); + err = getGlError(); } } GL_CHECK(glDeleteTextures(1, &id) ); return 0 == err; +#endif } static bool isImageFormatValid(TextureFormat::Enum _format, GLsizei _dim = 16) @@ -1540,7 +1901,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GLenum err = 0; glTexStorage2D(GL_TEXTURE_2D, 1, s_imageFormat[_format], _dim, _dim); - err |= glGetError(); + err |= getGlError(); if (0 == err) { glBindImageTexture(0 @@ -1551,7 +1912,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , GL_READ_WRITE , s_imageFormat[_format] ); - err |= glGetError(); + err |= getGlError(); } GL_CHECK(glDeleteTextures(1, &id) ); @@ -1559,6 +1920,135 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); return 0 == err; } +#if BX_PLATFORM_EMSCRIPTEN + static bool isFramebufferFormatValidPerSpec( + TextureFormat::Enum _format + , bool _srgb + , bool _writeOnly + ) + { + // Avoid creating test textures for WebGL, that causes error noise in the browser console; instead examine the supported texture formats from the spec. + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); + + EmscriptenWebGLContextAttributes attrs; + EMSCRIPTEN_CHECK(emscripten_webgl_get_context_attributes(ctx, &attrs) ); + + const int glesVersion = attrs.majorVersion + 1; + + switch(_format) + { + // GLES2 textures + case TextureFormat::B5G6R5: + case TextureFormat::R5G6B5: + case TextureFormat::BGRA4: + case TextureFormat::RGBA4: + case TextureFormat::BGR5A1: + case TextureFormat::RGB5A1: + case TextureFormat::D16: + return !_srgb; + + // GLES2 renderbuffers not a texture in GLES3 + case TextureFormat::D0S8: + return !_srgb + && _writeOnly + ; + + // GLES2 textures that are not renderbuffers + case TextureFormat::RGB8: + case TextureFormat::RGBA8: + return !_srgb + && (!_writeOnly || glesVersion >= 3) + ; + + // GLES3 EXT_color_buffer_float renderbuffer formats + case TextureFormat::R16F: + case TextureFormat::RG16F: + case TextureFormat::R32F: + case TextureFormat::RG32F: + case TextureFormat::RG11B10F: + if (_writeOnly) + { + return emscripten_webgl_enable_extension(ctx, "EXT_color_buffer_float"); + } + + return !_srgb && glesVersion >= 3; + + // GLES2 float extension: + case TextureFormat::RGBA16F: + if (_writeOnly && emscripten_webgl_enable_extension(ctx, "EXT_color_buffer_half_float") ) + { + return true; + } + BX_FALLTHROUGH; + + case TextureFormat::RGBA32F: + if (_writeOnly) + { + return emscripten_webgl_enable_extension(ctx, "EXT_color_buffer_float") || emscripten_webgl_enable_extension(ctx, "WEBGL_color_buffer_float"); + } + + // GLES3 formats without sRGB + return !_srgb + && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "OES_texture_half_float") ) + ; + + case TextureFormat::D24: + case TextureFormat::D24S8: + // GLES3 formats without sRGB, depth textures do not support mipmaps. + return !_srgb + && (glesVersion >= 3 || (!_writeOnly && emscripten_webgl_enable_extension(ctx, "WEBGL_depth_texture") ) ) + ; + + case TextureFormat::D32: + // GLES3 formats without sRGB, depth textures do not support mipmaps. + return !_srgb + && !_writeOnly + && (glesVersion >= 3 || emscripten_webgl_enable_extension(ctx, "WEBGL_depth_texture") ) + ; + + // GLES3 textures + case TextureFormat::R8: + case TextureFormat::RG8: + case TextureFormat::R8I: + case TextureFormat::R8U: + case TextureFormat::R16I: + case TextureFormat::R16U: + case TextureFormat::R32I: + case TextureFormat::R32U: + case TextureFormat::RG8I: + case TextureFormat::RG8U: + case TextureFormat::RGBA8I: + case TextureFormat::RGBA8U: + case TextureFormat::RG16I: + case TextureFormat::RG16U: + case TextureFormat::RG32I: + case TextureFormat::RG32U: + case TextureFormat::RGBA16I: + case TextureFormat::RGBA16U: + case TextureFormat::RGBA32I: + case TextureFormat::RGBA32U: + case TextureFormat::RGB10A2: + case TextureFormat::D16F: + case TextureFormat::D24F: + case TextureFormat::D32F: + return !_srgb + && glesVersion >= 3 + ; + + case TextureFormat::BGRA8: + return !_srgb + && _writeOnly + && glesVersion >= 3 + ; + + default: + break; + } + + return false; + } +#endif + static bool isFramebufferFormatValid( TextureFormat::Enum _format , bool _srgb = false @@ -1566,6 +2056,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , GLsizei _dim = 16 ) { +#if BX_PLATFORM_EMSCRIPTEN + // On web platform read the validity of framebuffers based on the available GL context and extensions + // to avoid developer unfriendly console error noise that would come from probing. + BX_UNUSED(_dim); + return isFramebufferFormatValidPerSpec(_format, _srgb, _writeOnly); +#else + // On other platforms probe the supported textures. const TextureFormatInfo& tfi = s_textureFormat[_format]; GLenum internalFmt = _srgb ? tfi.m_internalFmtSrgb @@ -1590,7 +2087,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); glBindRenderbuffer(GL_RENDERBUFFER, 0); glDeleteRenderbuffers(1, &rbo); - GLenum err = glGetError(); + GLenum err = getGlError(); return 0 == err; } @@ -1632,7 +2129,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , id , 0 ); - err = glGetError(); + err = getGlError(); if (0 == err) { @@ -1645,6 +2142,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glDeleteTextures(1, &id) ); return GL_FRAMEBUFFER_COMPLETE == err; +#endif } static void getFilters(uint32_t _flags, bool _hasMips, GLenum& _magFilter, GLenum& _minFilter) @@ -1656,8 +2154,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); _minFilter = s_textureFilterMin[min][_hasMips ? mip+1 : 0]; } - void updateExtension(const char* _name) + void updateExtension(const bx::StringView& _name) { + bx::StringView ext(_name); + if (0 == bx::strCmp(ext, "GL_", 3) ) // skip GL_ + { + ext.set(ext.getPtr()+3, ext.getTerm() ); + } + bool supported = false; for (uint32_t ii = 0; ii < Extension::Count; ++ii) { @@ -1665,22 +2169,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (!extension.m_supported && extension.m_initialize) { - const char* ext = _name; - if (0 == bx::strCmp(ext, "GL_", 3) ) // skip GL_ - { - ext += 3; - } - if (0 == bx::strCmp(ext, extension.m_name) ) { - extension.m_supported = true; +#if BX_PLATFORM_EMSCRIPTEN + EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context(); + supported = emscripten_webgl_enable_extension(ctx, extension.m_name); +#else supported = true; +#endif + extension.m_supported = supported; break; } } } - BX_TRACE("GL_EXTENSION %s: %s", supported ? " (supported)" : "", _name); + BX_TRACE("GL_EXTENSION %s: %.*s", supported ? " (supported)" : "", _name.getLength(), _name.getPtr() ); BX_UNUSED(supported); } @@ -1696,6 +2199,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { "Advanced Micro Devices, Inc.", BGFX_PCI_ID_AMD }, { "Intel", BGFX_PCI_ID_INTEL }, { "ATI Technologies Inc.", BGFX_PCI_ID_AMD }, + { "ARM", BGFX_PCI_ID_ARM }, }; struct Workaround @@ -1738,6 +2242,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , m_hash( (BX_PLATFORM_WINDOWS<<1) | BX_ARCH_64BIT) , m_backBufferFbo(0) , m_msaaBackBufferFbo(0) + , m_msaaBlitProgram(0) + , m_clearQuadColor(BGFX_INVALID_HANDLE) + , m_clearQuadDepth(BGFX_INVALID_HANDLE) { bx::memSet(m_msaaBackBufferRbos, 0, sizeof(m_msaaBackBufferRbos) ); } @@ -1768,13 +2275,39 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); - setRenderContextSize(_init.resolution.width, _init.resolution.height); + setRenderContextSize(_init.resolution.width, _init.resolution.height, _init.resolution.reset); m_vendor = getGLString(GL_VENDOR); m_renderer = getGLString(GL_RENDERER); m_version = getGLString(GL_VERSION); m_glslVersion = getGLString(GL_SHADING_LANGUAGE_VERSION); + { + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + int32_t majorGlVersion = 0; + int32_t minorGlVersion = 0; + const char* version = m_version; + + while (*version && !bx::isNumeric(*version) ) + { + ++version; + } + + bx::fromString(&majorGlVersion, version); + bx::fromString(&minorGlVersion, version + 2); + int32_t glVersion = majorGlVersion*10 + minorGlVersion; + + BX_TRACE("WebGL context version %d (%d.%d).", glVersion, majorGlVersion, minorGlVersion); + + m_gles3 = glVersion >= 30; + } + else + { + m_gles3 = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30); + } + } + for (uint32_t ii = 0; ii < BX_COUNTOF(s_vendorIds); ++ii) { const VendorId& vendorId = s_vendorIds[ii]; @@ -1838,6 +2371,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_GET(GL_MAX_RENDERBUFFER_SIZE, 1); GL_GET(GL_MAX_COLOR_ATTACHMENTS, 1); GL_GET(GL_MAX_DRAW_BUFFERS, 1); + #undef GL_GET BX_TRACE(" Vendor: %s", m_vendor); @@ -1872,40 +2406,25 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (BX_ENABLED(BGFX_CONFIG_RENDERER_USE_EXTENSIONS) ) { const char* extensions = (const char*)glGetString(GL_EXTENSIONS); - glGetError(); // ignore error if glGetString returns NULL. + getGlError(); // ignore error if glGetString returns NULL. if (NULL != extensions) { - char name[1024]; - const char* pos = extensions; - const char* end = extensions + bx::strLen(extensions); - uint32_t index = 0; - while (pos < end) - { - uint32_t len; - const bx::StringView space = bx::strFind(pos, ' '); - if (!space.isEmpty() ) - { - len = bx::uint32_min(sizeof(name), (uint32_t)(space.getPtr() - pos) ); - } - else - { - len = bx::uint32_min(sizeof(name), (uint32_t)bx::strLen(pos) ); - } - - bx::strCopy(name, BX_COUNTOF(name), pos, len); - name[len] = '\0'; + bx::StringView ext(extensions); - updateExtension(name); + while (!ext.isEmpty() ) + { + const bx::StringView space = bx::strFind(ext, ' '); + const bx::StringView token = bx::StringView(ext.getPtr(), space.getPtr() ); + updateExtension(token); - pos += len+1; - ++index; + ext.set(space.getPtr() + (space.isEmpty() ? 0 : 1), ext.getTerm() ); } } else if (NULL != glGetStringi) { GLint numExtensions = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); - glGetError(); // ignore error if glGetIntegerv returns NULL. + getGlError(); // ignore error if glGetIntegerv returns NULL. for (GLint index = 0; index < numExtensions; ++index) { @@ -2021,19 +2540,38 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) ) { - setTextureFormat(TextureFormat::D32, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); - - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) ) + if (m_gles3) { - setTextureFormat(TextureFormat::RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT); + setTextureFormat(TextureFormat::R16F, GL_R16F, GL_RED, 0x140B /* == GL_HALF_FLOAT, but bgfx overwrites it globally with GL_HALF_FLOAT_OES */); + setTextureFormat(TextureFormat::RG16F, GL_RG16F, GL_RG, 0x140B /* == GL_HALF_FLOAT, but bgfx overwrites it globally with GL_HALF_FLOAT_OES */); + setTextureFormat(TextureFormat::RGBA16F, GL_RGBA16F, GL_RGBA, 0x140B /* == GL_HALF_FLOAT, but bgfx overwrites it globally with GL_HALF_FLOAT_OES */); + } + else + { + setTextureFormat(TextureFormat::RGBA16F, GL_RGBA, GL_RGBA, GL_HALF_FLOAT); // Note: this is actually GL_HALF_FLOAT_OES and not GL_HALF_FLOAT if compiling for GLES target. setTextureFormat(TextureFormat::RGBA32F, GL_RGBA, GL_RGBA, GL_FLOAT); // internalFormat and format must match: // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml setTextureFormat(TextureFormat::RGBA8, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE); + setTextureFormat(TextureFormat::B5G6R5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV); setTextureFormat(TextureFormat::R5G6B5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV); + setTextureFormat(TextureFormat::BGRA4, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV); setTextureFormat(TextureFormat::RGBA4, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4_REV); + setTextureFormat(TextureFormat::BGR5A1, GL_BGRA, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV); setTextureFormat(TextureFormat::RGB5A1, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_1_5_5_5_REV); + if (s_extension[Extension::EXT_sRGB].m_supported) + { + setTextureFormatSrgb(TextureFormat::RGBA8, GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT); + setTextureFormatSrgb(TextureFormat::RGB8, GL_SRGB_EXT, GL_SRGB_EXT); + } + + if (s_extension[Extension::EXT_texture_swizzle].m_supported) + { + s_textureFormat[TextureFormat::R5G6B5].m_mapping[0] = GL_BLUE; + s_textureFormat[TextureFormat::R5G6B5].m_mapping[2] = GL_RED; + } + if (s_extension[Extension::OES_texture_half_float].m_supported || s_extension[Extension::OES_texture_float ].m_supported) { @@ -2050,17 +2588,40 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); s_textureFilter[TextureFormat::RG32F] = linear32F; s_textureFilter[TextureFormat::RGBA32F] = linear32F; } + } - if (BX_ENABLED(BX_PLATFORM_IOS) || BX_ENABLED(BX_PLATFORM_EMSCRIPTEN)) - { - setTextureFormat(TextureFormat::D16, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT); - setTextureFormat(TextureFormat::D24S8, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); - } + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) + && (s_extension[Extension::WEBGL_depth_texture].m_supported + || s_extension[Extension::MOZ_WEBGL_depth_texture].m_supported + || s_extension[Extension::WEBKIT_WEBGL_depth_texture].m_supported) ) + { + setTextureFormat(TextureFormat::D16, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT); + setTextureFormat(TextureFormat::D24, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); // N.b. OpenGL ES does not guarantee that there are 24 bits available here, could be 16. See https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/ + setTextureFormat(TextureFormat::D32, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); // N.b. same as above. + setTextureFormat(TextureFormat::D24S8, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + } + + // OpenGL ES 3.0 depth formats. + if (m_gles3) + { + setTextureFormat(TextureFormat::D16, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT); + setTextureFormat(TextureFormat::D24, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); + setTextureFormat(TextureFormat::D32, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT); + setTextureFormat(TextureFormat::D24S8, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8); + setTextureFormat(TextureFormat::D16F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT); // GLES 3.0 does not have D16F, overshoot to D32F + setTextureFormat(TextureFormat::D24F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT); // GLES 3.0 does not have D24F, overshoot to D32F + setTextureFormat(TextureFormat::D32F, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT); + setTextureFormat(TextureFormat::D0S8, GL_STENCIL_INDEX8, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE); // Only works as renderbuffer, not as texture } } + else + { + setTextureFormat(TextureFormat::R5G6B5, GL_BGR, GL_BGR, GL_UNSIGNED_SHORT_5_6_5); + setTextureFormatSrgb(TextureFormat::R5G6B5, GL_ZERO, GL_BGR); + } if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) - || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) + || m_gles3) { setTextureFormat(TextureFormat::R8I, GL_R8I, GL_RED_INTEGER, GL_BYTE); setTextureFormat(TextureFormat::R8U, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE); @@ -2109,14 +2670,26 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) { - setTextureFormat(TextureFormat::RGBA4, GL_ZERO, GL_ZERO, GL_ZERO); - setTextureFormat(TextureFormat::RGB5A1, GL_ZERO, GL_ZERO, GL_ZERO); - - if (!isTextureFormatValid(TextureFormat::R8) ) + // OpenGL ES does not have reversed BGRA4 and BGR5A1 support. + setTextureFormat(TextureFormat::BGRA4, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); + setTextureFormat(TextureFormat::RGBA4, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4); + setTextureFormat(TextureFormat::BGR5A1, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); + setTextureFormat(TextureFormat::RGB5A1, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1); + setTextureFormat(TextureFormat::B5G6R5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); + setTextureFormat(TextureFormat::R5G6B5, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5); + + if (!m_gles3) { - // GL core has to use GL_R8 Issue#208, GLES2 has to use GL_LUMINANCE issue#226 - s_textureFormat[TextureFormat::R8].m_internalFmt = GL_LUMINANCE; - s_textureFormat[TextureFormat::R8].m_fmt = GL_LUMINANCE; + // OpenGL ES 2.0 uses unsized internal formats. + s_textureFormat[TextureFormat::RGB8].m_internalFmt = GL_RGB; + + // OpenGL ES 2.0 does not have R8 texture format, only L8. Open GL ES 2.0 extension https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_rg.txt + // adds support for R8 to GLES 2.0 core contexts. For those use L8 instead. + if (!s_extension[Extension::EXT_texture_rg].m_supported) + { + s_textureFormat[TextureFormat::R8].m_internalFmt = GL_LUMINANCE; + s_textureFormat[TextureFormat::R8].m_fmt = GL_LUMINANCE; + } } } @@ -2148,6 +2721,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { + const TextureFormat::Enum fmt = TextureFormat::Enum(ii); + uint16_t supported = BGFX_CAPS_FORMAT_TEXTURE_NONE; supported |= s_textureFormat[ii].m_supported ? BGFX_CAPS_FORMAT_TEXTURE_2D @@ -2156,30 +2731,33 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); : BGFX_CAPS_FORMAT_TEXTURE_NONE ; - supported |= isTextureFormatValid(TextureFormat::Enum(ii), true) + supported |= isTextureFormatValid(fmt, true) ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB : BGFX_CAPS_FORMAT_TEXTURE_NONE ; - supported |= isTextureFormatValid(TextureFormat::Enum(ii), false, true) - ? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN - : BGFX_CAPS_FORMAT_TEXTURE_NONE - ; + if (!bimg::isCompressed(bimg::TextureFormat::Enum(fmt) ) ) + { + supported |= isTextureFormatValid(fmt, false, true) + ? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + } supported |= computeSupport - && isImageFormatValid(TextureFormat::Enum(ii) ) - ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE + && isImageFormatValid(fmt) + ? (BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ | BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE) : BGFX_CAPS_FORMAT_TEXTURE_NONE ; - supported |= isFramebufferFormatValid(TextureFormat::Enum(ii) ) + supported |= isFramebufferFormatValid(fmt) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER : BGFX_CAPS_FORMAT_TEXTURE_NONE ; - supported |= isFramebufferFormatValid(TextureFormat::Enum(ii), false, true) + supported |= isFramebufferFormatValid(fmt, false, true) ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER : BGFX_CAPS_FORMAT_TEXTURE_NONE ; @@ -2193,7 +2771,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , 1 , &maxSamples ); - GLenum err = glGetError(); + GLenum err = getGlError(); supported |= 0 == err && maxSamples > 0 ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA : BGFX_CAPS_FORMAT_TEXTURE_NONE @@ -2205,7 +2783,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , 1 , &maxSamples ); - err = glGetError(); + err = getGlError(); supported |= 0 == err && maxSamples > 0 ? BGFX_CAPS_FORMAT_TEXTURE_MSAA : BGFX_CAPS_FORMAT_TEXTURE_NONE @@ -2215,17 +2793,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); g_caps.formats[ii] = supported; } - g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::OES_texture_3D].m_supported ? BGFX_CAPS_TEXTURE_3D : 0 ; - g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::EXT_shadow_samplers].m_supported ? BGFX_CAPS_TEXTURE_COMPARE_ALL : 0 ; - g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::OES_vertex_half_float].m_supported ? BGFX_CAPS_VERTEX_ATTRIB_HALF : 0 @@ -2236,7 +2814,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ? BGFX_CAPS_VERTEX_ATTRIB_UINT10 : 0 ; - g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::EXT_frag_depth].m_supported ? BGFX_CAPS_FRAGMENT_DEPTH : 0 @@ -2249,7 +2827,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ? BGFX_CAPS_FRAGMENT_ORDERING : 0 ; - g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + g_caps.supported |= !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::OES_element_index_uint].m_supported ? BGFX_CAPS_INDEX32 : 0 @@ -2277,6 +2855,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); : 0 ; + g_caps.supported |= s_extension[Extension::ARB_indirect_parameters].m_supported + ? BGFX_CAPS_DRAW_INDIRECT_COUNT + : 0 + ; + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) || NULL == glPolygonMode) { @@ -2288,14 +2871,15 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); || s_extension[Extension:: NV_copy_image].m_supported || s_extension[Extension::OES_copy_image].m_supported) { - m_blitSupported = NULL != glCopyImageSubData; - g_caps.supported |= m_blitSupported - ? BGFX_CAPS_TEXTURE_BLIT - : 0 - ; + m_blitSupported = NULL != glCopyImageSubData; } - g_caps.supported |= m_readBackSupported + g_caps.supported |= m_blitSupported || BX_ENABLED(BGFX_GL_CONFIG_BLIT_EMULATION) + ? BGFX_CAPS_TEXTURE_BLIT + : 0 + ; + + g_caps.supported |= (m_readBackSupported || BX_ENABLED(BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION) ) ? BGFX_CAPS_TEXTURE_READ_BACK : 0 ; @@ -2303,14 +2887,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); g_caps.supported |= false || s_extension[Extension::EXT_texture_array].m_supported || s_extension[Extension::EXT_gpu_shader4].m_supported - || (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + || (m_gles3 && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) ? BGFX_CAPS_TEXTURE_2D_ARRAY : 0 ; g_caps.supported |= false || s_extension[Extension::EXT_gpu_shader4].m_supported - || (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + || (m_gles3 && !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) ? BGFX_CAPS_VERTEX_ID : 0 ; @@ -2323,20 +2907,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ; g_caps.limits.maxTextureSize = uint16_t(glGet(GL_MAX_TEXTURE_SIZE) ); - g_caps.limits.maxTextureLayers = uint16_t(bx::max(glGet(GL_MAX_ARRAY_TEXTURE_LAYERS), 1) ); + g_caps.limits.maxTextureLayers = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) || s_extension[Extension::EXT_texture_array].m_supported ? uint16_t(bx::max(glGet(GL_MAX_ARRAY_TEXTURE_LAYERS), 1) ) : 1; g_caps.limits.maxComputeBindings = computeSupport ? BGFX_MAX_COMPUTE_BINDINGS : 0; g_caps.limits.maxVertexStreams = BGFX_CONFIG_MAX_VERTEX_STREAMS; if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) - || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) + || m_gles3 || s_extension[Extension::EXT_draw_buffers ].m_supported || s_extension[Extension::WEBGL_draw_buffers].m_supported) { g_caps.limits.maxFBAttachments = uint8_t(bx::uint32_clamp( - glGet(GL_MAX_DRAW_BUFFERS) - , 1 - , BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) - ); + glGet(GL_MAX_DRAW_BUFFERS) + , 1 + , BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) + ); } // if (s_extension[Extension::ARB_clip_control].m_supported) @@ -2351,7 +2935,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } m_vaoSupport = !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) - && (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) + && (m_gles3 || s_extension[Extension::ARB_vertex_array_object].m_supported || s_extension[Extension::OES_vertex_array_object].m_supported ); @@ -2361,17 +2945,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glGenVertexArrays(1, &m_vao) ); } - m_samplerObjectSupport = !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) - && (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) - || s_extension[Extension::ARB_sampler_objects].m_supported - ); + m_samplerObjectSupport = false + || m_gles3 + || s_extension[Extension::ARB_sampler_objects].m_supported + ; - m_shadowSamplersSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + m_shadowSamplersSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::EXT_shadow_samplers].m_supported ; m_programBinarySupport = !BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) - && (!!(BGFX_CONFIG_RENDERER_OPENGLES >= 30) + && (m_gles3 || s_extension[Extension::ARB_get_program_binary].m_supported || s_extension[Extension::OES_get_program_binary].m_supported || s_extension[Extension::IMG_shader_binary ].m_supported @@ -2382,7 +2966,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); || s_extension[Extension::EXT_texture_swizzle].m_supported ; - m_depthTextureSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + m_depthTextureSupport = !!(BGFX_CONFIG_RENDERER_OPENGL || m_gles3) || s_extension[Extension::ANGLE_depth_texture ].m_supported || s_extension[Extension::CHROMIUM_depth_texture ].m_supported || s_extension[Extension::GOOGLE_depth_texture ].m_supported @@ -2422,12 +3006,18 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_atocSupport = s_extension[Extension::ARB_multisample].m_supported; m_conservativeRasterSupport = s_extension[Extension::NV_conservative_raster].m_supported; + m_imageLoadStoreSupport = false + || s_extension[Extension::ARB_shader_image_load_store].m_supported + || s_extension[Extension::EXT_shader_image_load_store].m_supported + ; + g_caps.supported |= 0 | (m_atocSupport ? BGFX_CAPS_ALPHA_TO_COVERAGE : 0) | (m_conservativeRasterSupport ? BGFX_CAPS_CONSERVATIVE_RASTER : 0) | (m_occlusionQuerySupport ? BGFX_CAPS_OCCLUSION_QUERY : 0) | (m_depthTextureSupport ? BGFX_CAPS_TEXTURE_COMPARE_LEQUAL : 0) | (computeSupport ? BGFX_CAPS_COMPUTE : 0) + | (m_imageLoadStoreSupport ? BGFX_CAPS_IMAGE_RW : 0) ; g_caps.supported |= m_glctx.getCaps(); @@ -2449,11 +3039,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } if (s_extension[Extension::ARB_texture_multisample].m_supported - || s_extension[Extension::ANGLE_framebuffer_multisample].m_supported) + || s_extension[Extension::ANGLE_framebuffer_multisample].m_supported + || s_extension[Extension::EXT_multisampled_render_to_texture].m_supported) { GL_CHECK(glGetIntegerv(GL_MAX_SAMPLES, &m_maxMsaa) ); } +#if BGFX_CONFIG_RENDERER_OPENGLES && (BGFX_CONFIG_RENDERER_OPENGLES < 30) + if (!m_maxMsaa && s_extension[Extension::IMG_multisampled_render_to_texture].m_supported) + { + GL_CHECK(glGetIntegerv(GL_MAX_SAMPLES_IMG, &m_maxMsaa) ); + } +#endif // BGFX_CONFIG_RENDERER_OPENGLES < 30 + if (s_extension[Extension::OES_read_format].m_supported && (s_extension[Extension::IMG_read_format].m_supported || s_extension[Extension::EXT_read_format_bgra].m_supported) ) { @@ -2464,15 +3062,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_readPixelsFmt = GL_RGBA; } - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) + if (m_gles3) { g_caps.supported |= BGFX_CAPS_INSTANCING; } else { if (s_extension[Extension::ANGLE_instanced_arrays].m_supported - || s_extension[Extension::ARB_instanced_arrays].m_supported - || s_extension[Extension::EXT_instanced_arrays].m_supported) + || s_extension[Extension:: ARB_instanced_arrays].m_supported + || s_extension[Extension:: EXT_instanced_arrays].m_supported + || (s_extension[Extension:: NV_instanced_arrays].m_supported && s_extension[Extension::NV_draw_instanced].m_supported) + ) { if (NULL != glVertexAttribDivisor && NULL != glDrawArraysInstanced @@ -2480,6 +3080,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { g_caps.supported |= BGFX_CAPS_INSTANCING; } + else if (NULL != glVertexAttribDivisorNV + && NULL != glDrawArraysInstancedNV + && NULL != glDrawElementsInstancedNV) + { + glVertexAttribDivisor = glVertexAttribDivisorNV; + glDrawArraysInstanced = glDrawArraysInstancedNV; + glDrawElementsInstanced = glDrawElementsInstancedNV; + + g_caps.supported |= BGFX_CAPS_INSTANCING; + } } if (0 == (g_caps.supported & BGFX_CAPS_INSTANCING) ) @@ -2490,6 +3100,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } + g_caps.supported |= s_extension[Extension::ARB_shader_viewport_layer_array].m_supported + ? BGFX_CAPS_VIEWPORT_LAYER_ARRAY + : 0 + ; + + g_caps.supported |= BX_ENABLED(BX_PLATFORM_WINRT) ? BGFX_CAPS_TRANSPARENT_BACKBUFFER : 0; + if (s_extension[Extension::ARB_debug_output].m_supported || s_extension[Extension::KHR_debug].m_supported) { @@ -2509,17 +3126,32 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } + if (NULL == glPushDebugGroup + || NULL == glPopDebugGroup) + { + glPushDebugGroup = stubPushDebugGroup; + glPopDebugGroup = stubPopDebugGroup; + } + if (s_extension[Extension::ARB_seamless_cube_map].m_supported) { GL_CHECK(glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS) ); } + if (NULL != glProvokingVertex + && s_extension[Extension::ARB_provoking_vertex].m_supported) + { + GL_CHECK(glProvokingVertex(GL_FIRST_VERTEX_CONVENTION) ); + } + if (NULL == glInsertEventMarker || !s_extension[Extension::EXT_debug_marker].m_supported) { glInsertEventMarker = stubInsertEventMarker; } + m_maxLabelLen = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 32) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 43) || s_extension[Extension::KHR_debug].m_supported ? uint16_t(glGet(GL_MAX_LABEL_LENGTH) ) : 0; + setGraphicsDebuggerPresent(s_extension[Extension::EXT_debug_tool].m_supported); if (NULL == glObjectLabel) @@ -2532,6 +3164,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); glInvalidateFramebuffer = stubInvalidateFramebuffer; } + if (NULL == glFramebufferTexture) + { + glFramebufferTexture = stubFramebufferTexture; + } + if (m_timerQuerySupport) { m_gpuTimer.create(); @@ -2634,7 +3271,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (m_needPresent) { // Ensure the back buffer is bound as the source of the flip - GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo)); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) ); m_glctx.swap(); m_needPresent = false; @@ -2652,20 +3289,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_indexBuffers[_handle.idx].destroy(); } - void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override + void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) override { - VertexDecl& decl = m_vertexDecls[_handle.idx]; - bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); - dump(decl); + VertexLayout& layout = m_vertexLayouts[_handle.idx]; + bx::memCopy(&layout, &_layout, sizeof(VertexLayout) ); + dump(layout); } - void destroyVertexDecl(VertexDeclHandle /*_handle*/) override + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override { } - void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) override + void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t _flags) override { - m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); + m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _layoutHandle, _flags); } void destroyVertexBuffer(VertexBufferHandle _handle) override @@ -2690,8 +3327,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) override { - VertexDeclHandle decl = BGFX_INVALID_HANDLE; - m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); + VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE; + m_vertexBuffers[_handle.idx].create(_size, NULL, layoutHandle, _flags); } void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override @@ -2772,31 +3409,28 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glBindTexture(texture.m_target, 0) ); } - else + else if (BX_ENABLED(BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION) ) { const TextureGL& texture = m_textures[_handle.idx]; const bool compressed = bimg::isCompressed(bimg::TextureFormat::Enum(texture.m_textureFormat) ); - if(!compressed) + if (!compressed) { - Attachment attachment[1]; - attachment[0].handle = _handle; - attachment[0].mip = 0; - attachment[0].layer = 0; + Attachment at[1]; + at[0].init(_handle); FrameBufferGL frameBuffer; - frameBuffer.create(1, attachment); + frameBuffer.create(BX_COUNTOF(at), at); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer.m_fbo[0]) ); GL_CHECK(glFramebufferTexture2D( GL_FRAMEBUFFER , GL_COLOR_ATTACHMENT0 , GL_TEXTURE_2D , texture.m_id - , attachment[0].mip + , at[0].mip ) ); - if (!BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) - && !BX_ENABLED(BX_PLATFORM_IOS)) + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || m_gles3) { GL_CHECK(glReadBuffer(GL_COLOR_ATTACHMENT0) ); } @@ -2828,7 +3462,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -2839,7 +3473,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); tc.m_cubeMap = false; tc.m_mem = NULL; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); texture.destroy(); texture.create(mem, texture.m_flags, 0); @@ -2927,6 +3561,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); width = frameBuffer.m_width; height = frameBuffer.m_height; } + m_glctx.makeCurrent(swapChain); uint32_t length = width*height*4; @@ -2970,30 +3605,50 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bx::memCopy(m_uniforms[_loc], _data, _size); } - void setMarker(const char* _marker, uint32_t _size) override + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override { - GL_CHECK(glInsertEventMarker(_size, _marker) ); + m_occlusionQuery.invalidate(_handle); } - void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + void setMarker(const char* _marker, uint16_t _len) override { - m_occlusionQuery.invalidate(_handle); + GL_CHECK(glInsertEventMarker(_len, _marker) ); } - virtual void setName(Handle _handle, const char* _name) override + virtual void setName(Handle _handle, const char* _name, uint16_t _len) override { + uint16_t len = bx::min(_len, m_maxLabelLen); + switch (_handle.type) { + case Handle::IndexBuffer: + GL_CHECK(glObjectLabel(GL_BUFFER, m_indexBuffers[_handle.idx].m_id, len, _name) ); + break; + case Handle::Shader: - GL_CHECK(glObjectLabel(GL_SHADER, m_shaders[_handle.idx].m_id, -1, _name) ); + GL_CHECK(glObjectLabel(GL_SHADER, m_shaders[_handle.idx].m_id, len, _name) ); break; case Handle::Texture: - GL_CHECK(glObjectLabel(GL_TEXTURE, m_textures[_handle.idx].m_id, -1, _name) ); + { + GLint id = m_textures[_handle.idx].m_id; + if (0 != id) + { + GL_CHECK(glObjectLabel(GL_TEXTURE, id, len, _name) ); + } + else + { + GL_CHECK(glObjectLabel(GL_RENDERBUFFER, m_textures[_handle.idx].m_rbo, len, _name) ); + } + } + break; + + case Handle::VertexBuffer: + GL_CHECK(glObjectLabel(GL_BUFFER, m_vertexBuffers[_handle.idx].m_id, len, _name) ); break; default: - BX_CHECK(false, "Invalid handle type?! %d", _handle.type); + BX_ASSERT(false, "Invalid handle type?! %d", _handle.type); break; } } @@ -3001,7 +3656,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void submitBlit(BlitState& _bs, uint16_t _view); void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override; - void blitSetup(TextVideoMemBlitter& _blitter) override { if (0 != m_vao) @@ -3024,30 +3678,26 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) ); ProgramGL& program = m_program[_blitter.m_program.idx]; - GL_CHECK(glUseProgram(program.m_id) ); - GL_CHECK(glUniform1i(program.m_sampler[0], 0) ); + setProgram(program.m_id); + setUniform1i(program.m_sampler[0], 0); float proj[16]; - bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, true); + bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, g_caps.homogeneousDepth); - GL_CHECK(glUniformMatrix4fv(program.m_predefined[0].m_loc + setUniformMatrix4fv(program.m_predefined[0].m_loc , 1 , GL_FALSE , proj - ) ); + ); GL_CHECK(glActiveTexture(GL_TEXTURE0) ); GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_textures[_blitter.m_texture.idx].m_id) ); if (!BX_ENABLED(BX_PLATFORM_OSX) ) { - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) - || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) + if (m_samplerObjectSupport) { - if (m_samplerObjectSupport) - { - GL_CHECK(glBindSampler(0, 0) ); - } + GL_CHECK(glBindSampler(0, 0) ); } } } @@ -3058,7 +3708,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 < numVertices) { m_indexBuffers[_blitter.m_ib->handle.idx].update(0, _numIndices*2, _blitter.m_ib->data); - m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data); + m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_layout.m_stride, _blitter.m_vb->data); VertexBufferGL& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); @@ -3068,7 +3718,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ProgramGL& program = m_program[_blitter.m_program.idx]; program.bindAttributesBegin(); - program.bindAttributes(_blitter.m_decl, 0); + program.bindAttributes(_blitter.m_layout, 0); program.bindAttributesEnd(); GL_CHECK(glDrawElements(GL_TRIANGLES @@ -3135,19 +3785,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void setShaderUniform4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { - GL_CHECK(glUniform4fv(_regIndex + setUniform4fv(_regIndex , _numRegs , (const GLfloat*)_val - ) ); + ); } void setShaderUniform4x4f(uint8_t /*_flags*/, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { - GL_CHECK(glUniformMatrix4fv(_regIndex + setUniformMatrix4fv(_regIndex , _numRegs , GL_FALSE , (const GLfloat*)_val - ) ); + ); } uint32_t setFrameBuffer(FrameBufferHandle _fbh, uint32_t _height, uint16_t _discard = BGFX_CLEAR_NONE, bool _msaa = true) @@ -3192,6 +3842,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (UINT16_MAX != frameBuffer.m_denseIdx) { m_glctx.makeCurrent(frameBuffer.m_swapChain); + GL_CHECK(glFrontFace(GL_CW) ); + frameBuffer.m_needPresent = true; m_currentFbo = 0; } @@ -3225,29 +3877,177 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void createMsaaFbo(uint32_t _width, uint32_t _height, uint32_t _msaa) { if (0 == m_msaaBackBufferFbo // iOS - && 1 < _msaa) + && 1 < _msaa + && !m_glctx.m_msaaContext) { - GL_CHECK(glGenFramebuffers(1, &m_msaaBackBufferFbo) ); - GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) ); - GL_CHECK(glGenRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) ); - GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[0]) ); - GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_RGBA8, _width, _height) ); - GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[1]) ); - GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER, _msaa, GL_DEPTH24_STENCIL8, _width, _height) ); - GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_msaaBackBufferRbos[0]) ); - - GLenum attachment = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) + GLenum storageFormat = m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER + ? GL_SRGB8_ALPHA8 + : GL_RGBA8 + ; + + GLenum attachment = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || m_gles3 ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT ; - GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, m_msaaBackBufferRbos[1]) ); - - BX_CHECK(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) - , "glCheckFramebufferStatus failed 0x%08x" - , glCheckFramebufferStatus(GL_FRAMEBUFFER) - ); + GL_CHECK(glGenFramebuffers(1, &m_msaaBackBufferFbo) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) ); + + if (m_gles3) + { + GL_CHECK(glGenTextures(BX_COUNTOF(m_msaaBackBufferTextures), m_msaaBackBufferTextures) ); + GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_msaaBackBufferTextures[0]) ); + GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, 1, storageFormat, _width, _height) ); + GL_CHECK(glFramebufferTexture2DMultisampleEXT( + GL_FRAMEBUFFER + , GL_COLOR_ATTACHMENT0 + , GL_TEXTURE_2D + , m_msaaBackBufferTextures[0] + , 0 + , _msaa + ) ); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) ); + + GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_msaaBackBufferTextures[1]) ); + GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH24_STENCIL8, _width, _height) ); + GL_CHECK(glFramebufferTexture2DMultisampleEXT( + GL_FRAMEBUFFER + , attachment + , GL_TEXTURE_2D + , m_msaaBackBufferTextures[1] + , 0 + , _msaa + ) ); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) ); + + BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) + , "glCheckFramebufferStatus failed 0x%08x" + , glCheckFramebufferStatus(GL_FRAMEBUFFER) + ); + + if (0 == m_msaaBlitProgram) + { + static const char* msaa_blit_vs = + R"(#version 300 es + precision highp float; + out vec2 UV; + void main() + { + float x = -1.0 + float( (gl_VertexID & 1) << 2); + float y = -1.0 + float( (gl_VertexID & 2) << 1); + gl_Position = vec4(x, y, 0, 1); + UV = vec2(gl_Position.x + 1.0, gl_Position.y + 1.0) * 0.5; + } + )"; + + static const char* msaa_blit_fs = + R"(#version 300 es + precision mediump float; + in vec2 UV; + uniform sampler2D msaaTexture; + out vec4 oFragColor; + void main() + { + oFragColor = texture(msaaTexture, UV); + } + )"; + + const GLchar *const vs = msaa_blit_vs; + const GLchar *const fs = msaa_blit_fs; + + GLuint shader_vs = glCreateShader(GL_VERTEX_SHADER); + { + BX_WARN(0 != shader_vs, "Failed to create msaa Blit Vertex shader."); + GL_CHECK(glShaderSource(shader_vs, 1, &vs, NULL) ); + GL_CHECK(glCompileShader(shader_vs) ); + + GLint compiled = 0; + GL_CHECK(glGetShaderiv(shader_vs, GL_COMPILE_STATUS, &compiled) ); + BX_WARN(0 == shader_vs, "Unable to compile msaa Blit Vertex shader."); + } + + GLuint shader_fs = glCreateShader(GL_FRAGMENT_SHADER); + { + BX_WARN(0 != shader_fs, "Failed to create msaa Blit Fragment shader."); + GL_CHECK(glShaderSource(shader_fs, 1, &fs, NULL) ); + GL_CHECK(glCompileShader(shader_fs) ); + + GLint compiled = 0; + GL_CHECK(glGetShaderiv(shader_fs, GL_COMPILE_STATUS, &compiled) ); + BX_WARN(0 == shader_vs, "Unable to compile msaa Blit Fragment shader."); + } + + m_msaaBlitProgram = glCreateProgram(); + + if (m_msaaBlitProgram) + { + GL_CHECK(glAttachShader(m_msaaBlitProgram, shader_vs) ); + GL_CHECK(glAttachShader(m_msaaBlitProgram, shader_fs) ); + GL_CHECK(glLinkProgram(m_msaaBlitProgram) ); + + GLint linked = 0; + GL_CHECK(glGetProgramiv(m_msaaBlitProgram, GL_LINK_STATUS, &linked) ); + + if (0 == linked) + { + char log[1024]; + GL_CHECK(glGetProgramInfoLog( + m_msaaBlitProgram + , sizeof(log) + , NULL + , log + ) ); + BX_TRACE("%d: %s", linked, log); + } + + GL_CHECK(glDetachShader(m_msaaBlitProgram, shader_vs) ); + GL_CHECK(glDeleteShader(shader_vs) ); + + GL_CHECK(glDetachShader(m_msaaBlitProgram, shader_fs) ); + GL_CHECK(glDeleteShader(shader_fs) ); + } + } + } + else + { + GL_CHECK(glGenRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) ); + + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[0]) ); + GL_CHECK(glRenderbufferStorageMultisample( + GL_RENDERBUFFER + , _msaa + , storageFormat + , _width + , _height + ) ); + + GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_msaaBackBufferRbos[1]) ); + GL_CHECK(glRenderbufferStorageMultisample( + GL_RENDERBUFFER + , _msaa + , GL_DEPTH24_STENCIL8 + , _width + , _height + ) ); + + GL_CHECK(glFramebufferRenderbuffer( + GL_FRAMEBUFFER + , GL_COLOR_ATTACHMENT0 + , GL_RENDERBUFFER + , m_msaaBackBufferRbos[0] + ) ); + GL_CHECK(glFramebufferRenderbuffer( + GL_FRAMEBUFFER + , attachment + , GL_RENDERBUFFER + , m_msaaBackBufferRbos[1] + ) ); + + BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER) + , "glCheckFramebufferStatus failed 0x%08x" + , glCheckFramebufferStatus(GL_FRAMEBUFFER) + ); + } } } @@ -3259,11 +4059,28 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glDeleteFramebuffers(1, &m_msaaBackBufferFbo) ); m_msaaBackBufferFbo = 0; - if (0 != m_msaaBackBufferRbos[0]) + if (m_gles3) { - GL_CHECK(glDeleteRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) ); - m_msaaBackBufferRbos[0] = 0; - m_msaaBackBufferRbos[1] = 0; + if (0 != m_msaaBackBufferTextures[0]) + { + GL_CHECK(glDeleteTextures(BX_COUNTOF(m_msaaBackBufferTextures), m_msaaBackBufferTextures) ); + m_msaaBackBufferTextures[0] = 0; + m_msaaBackBufferTextures[1] = 0; + } + if (0 != m_msaaBlitProgram) + { + GL_CHECK(glDeleteProgram(m_msaaBlitProgram) ); + m_msaaBlitProgram = 0; + } + } + else + { + if (0 != m_msaaBackBufferRbos[0]) + { + GL_CHECK(glDeleteRenderbuffers(BX_COUNTOF(m_msaaBackBufferRbos), m_msaaBackBufferRbos) ); + m_msaaBackBufferRbos[0] = 0; + m_msaaBackBufferRbos[1] = 0; + } } } } @@ -3277,23 +4094,37 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) ); GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_msaaBackBufferFbo) ); GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) ); - uint32_t width = m_resolution.width; - uint32_t height = m_resolution.height; - GLenum filter = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) + + const uint32_t width = m_resolution.width; + const uint32_t height = m_resolution.height; + const GLenum filter = BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || !m_gles3 ? GL_NEAREST : GL_LINEAR ; - GL_CHECK(glBlitFramebuffer(0 - , 0 - , width - , height - , 0 - , 0 - , width - , height - , GL_COLOR_BUFFER_BIT - , filter - ) ); + + if (m_gles3) + { + GL_CHECK(glUseProgram(m_msaaBlitProgram) ); + GL_CHECK(glActiveTexture(GL_TEXTURE0) ); + GL_CHECK(glBindTexture(GL_TEXTURE_2D, m_msaaBackBufferTextures[0]) ); + GL_CHECK(glDrawArrays(GL_TRIANGLES, 0, 3) ); + } + else + { + GL_CHECK(glBlitFramebuffer( + 0 + , 0 + , width + , height + , 0 + , 0 + , width + , height + , GL_COLOR_BUFFER_BIT + , filter + ) ); + } + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_backBufferFbo) ); } } @@ -3305,7 +4136,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { if (!m_glctx.isValid() ) { - m_glctx.create(_width, _height); + m_glctx.create(_width, _height, _flags); #if BX_PLATFORM_IOS // iOS: need to figure out how to deal with FBO created by context. @@ -3330,8 +4161,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void invalidateCache() { - if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) - && m_samplerObjectSupport) + if (m_samplerObjectSupport) { m_samplerStateCache.invalidate(); } @@ -3339,110 +4169,108 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void setSamplerState(uint32_t _stage, uint32_t _numMips, uint32_t _flags, const float _rgba[4]) { - if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) - && m_samplerObjectSupport) + BX_ASSERT(m_samplerObjectSupport, "Cannot use Sampler Objects"); + + if (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ) { - if (0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ) - { - const uint32_t index = (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT; + const uint32_t index = (_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT; - _flags &= ~BGFX_SAMPLER_RESERVED_MASK; - _flags &= BGFX_SAMPLER_BITS_MASK; - _flags |= _numMips<<BGFX_SAMPLER_RESERVED_SHIFT; + _flags &= ~BGFX_SAMPLER_RESERVED_MASK; + _flags &= BGFX_SAMPLER_BITS_MASK; + _flags |= _numMips<<BGFX_SAMPLER_RESERVED_SHIFT; - GLuint sampler; + GLuint sampler; - bool hasBorderColor = false; - bx::HashMurmur2A murmur; - uint32_t hash; + bool hasBorderColor = false; + bx::HashMurmur2A murmur; + uint32_t hash; - murmur.begin(); - murmur.add(_flags); - if (!needBorderColor(_flags) ) - { - murmur.add(-1); - hash = murmur.end(); + murmur.begin(); + murmur.add(_flags); + if (!needBorderColor(_flags) ) + { + murmur.add(-1); + hash = murmur.end(); - sampler = m_samplerStateCache.find(hash); + sampler = m_samplerStateCache.find(hash); + } + else + { + murmur.add(index); + hash = murmur.end(); + + if (NULL != _rgba) + { + hasBorderColor = true; + sampler = UINT32_MAX; } else { - murmur.add(index); - hash = murmur.end(); - - if (NULL != _rgba) - { - hasBorderColor = true; - sampler = UINT32_MAX; - } - else - { - sampler = m_samplerStateCache.find(hash); - } + sampler = m_samplerStateCache.find(hash); } + } - if (UINT32_MAX == sampler) - { - sampler = m_samplerStateCache.add(hash); + if (UINT32_MAX == sampler) + { + sampler = m_samplerStateCache.add(hash); - GL_CHECK(glSamplerParameteri(sampler - , GL_TEXTURE_WRAP_S - , s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT] - ) ); - GL_CHECK(glSamplerParameteri(sampler - , GL_TEXTURE_WRAP_T - , s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT] - ) ); - GL_CHECK(glSamplerParameteri(sampler - , GL_TEXTURE_WRAP_R - , s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT] - ) ); + GL_CHECK(glSamplerParameteri(sampler + , GL_TEXTURE_WRAP_S + , s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT] + ) ); + GL_CHECK(glSamplerParameteri(sampler + , GL_TEXTURE_WRAP_T + , s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT] + ) ); + GL_CHECK(glSamplerParameteri(sampler + , GL_TEXTURE_WRAP_R + , s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT] + ) ); - GLenum minFilter; - GLenum magFilter; - getFilters(_flags, 1 < _numMips, magFilter, minFilter); - GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, magFilter) ); - GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, minFilter) ); + GLenum minFilter; + GLenum magFilter; + getFilters(_flags, 1 < _numMips, magFilter, minFilter); + GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, magFilter) ); + GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, minFilter) ); - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) - { - GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_LOD_BIAS, float(BGFX_CONFIG_MIP_LOD_BIAS) ) ); - } + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) + { + GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_LOD_BIAS, float(BGFX_CONFIG_MIP_LOD_BIAS) ) ); + } - if (m_borderColorSupport - && hasBorderColor) - { - GL_CHECK(glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, _rgba) ); - } + if (m_borderColorSupport + && hasBorderColor) + { + GL_CHECK(glSamplerParameterfv(sampler, GL_TEXTURE_BORDER_COLOR, _rgba) ); + } - if (0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) ) - && 0.0f < m_maxAnisotropy) + if (0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) ) + && 0.0f < m_maxAnisotropy) + { + GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_maxAnisotropy) ); + } + + if (m_gles3 + || m_shadowSamplersSupport) + { + const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT; + if (0 == cmpFunc) { - GL_CHECK(glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, m_maxAnisotropy) ); + GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE) ); } - - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) - || m_shadowSamplersSupport) + else { - const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT; - if (0 == cmpFunc) - { - GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_NONE) ); - } - else - { - GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE) ); - GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC, s_cmpFunc[cmpFunc]) ); - } + GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE) ); + GL_CHECK(glSamplerParameteri(sampler, GL_TEXTURE_COMPARE_FUNC, s_cmpFunc[cmpFunc]) ); } } - - GL_CHECK(glBindSampler(_stage, sampler) ); - } - else - { - GL_CHECK(glBindSampler(_stage, 0) ); } + + GL_CHECK(glBindSampler(_stage, sampler) ); + } + else + { + GL_CHECK(glBindSampler(_stage, 0) ); } } @@ -3522,10 +4350,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void* data = BX_ALLOC(g_allocator, length); if (g_callback->cacheRead(_id, data, length) ) { + bx::Error err; bx::MemoryReader reader(data, length); GLenum format; - bx::read(&reader, format); + bx::read(&reader, format, &err); GL_CHECK(glProgramBinary(programId, format, reader.getDataPtr(), (GLsizei)reader.remaining() ) ); } @@ -3598,36 +4427,51 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); uint32_t loc = _uniformBuffer.read(); -#define CASE_IMPLEMENT_UNIFORM(_uniform, _glsuffix, _dxsuffix, _type) \ - case UniformType::_uniform: \ - { \ - _type* value = (_type*)data; \ - GL_CHECK(glUniform##_glsuffix(loc, num, value) ); \ - } \ - break; - -#define CASE_IMPLEMENT_UNIFORM_T(_uniform, _glsuffix, _dxsuffix, _type) \ - case UniformType::_uniform: \ - { \ - _type* value = (_type*)data; \ - GL_CHECK(glUniform##_glsuffix(loc, num, GL_FALSE, value) ); \ - } \ - break; - switch (type) { -// case ConstantType::Int1: -// { -// int* value = (int*)data; -// BX_TRACE("Int1 sampler %d, loc %d (num %d, copy %d)", *value, loc, num, copy); -// GL_CHECK(glUniform1iv(loc, num, value) ); -// } -// break; +#if BX_PLATFORM_EMSCRIPTEN + // For WebAssembly the array forms glUniform1iv/glUniform4fv are much slower compared to glUniform1i/glUniform4f + // since they need to marshal an array over from Wasm to JS, so optimize the case when there is exactly one + // uniform to upload. + case UniformType::Sampler: + if (num > 1) + { + setUniform1iv(loc, num, (int32_t*)data); + } + else + { + setUniform1i(loc, *(int32_t*)data); + } + break; + + case UniformType::Vec4: + if (num > 1) + { + setUniform4fv(loc, num, (float*)data); + } + else + { + float* vec4 = (float*)data; + setUniform4f(loc, vec4[0], vec4[1], vec4[2], vec4[3]); + } + break; +#else + case UniformType::Sampler: + setUniform1iv(loc, num, (int32_t*)data); + break; + + case UniformType::Vec4: + setUniform4fv(loc, num, (float*)data); + break; +#endif // BX_PLATFORM_EMSCRIPTEN - CASE_IMPLEMENT_UNIFORM(Int1, 1iv, I, int); - CASE_IMPLEMENT_UNIFORM(Vec4, 4fv, F, float); - CASE_IMPLEMENT_UNIFORM_T(Mat3, Matrix3fv, F, float); - CASE_IMPLEMENT_UNIFORM_T(Mat4, Matrix4fv, F, float); + case UniformType::Mat3: + setUniformMatrix3fv(loc, num, GL_FALSE, (float*)data); + break; + + case UniformType::Mat4: + setUniformMatrix4fv(loc, num, GL_FALSE, (float*)data); + break; case UniformType::End: break; @@ -3636,10 +4480,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy); break; } - -#undef CASE_IMPLEMENT_UNIFORM -#undef CASE_IMPLEMENT_UNIFORM_T - } } @@ -3739,57 +4579,46 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glDisable(GL_STENCIL_TEST) ); } - VertexBufferGL& vb = m_vertexBuffers[_clearQuad.m_vb->handle.idx]; - VertexDecl& vertexDecl = m_vertexDecls[_clearQuad.m_vb->decl.idx]; - - { - struct Vertex - { - float m_x; - float m_y; - float m_z; - }; - - Vertex* vertex = (Vertex*)_clearQuad.m_vb->data; - BX_CHECK(vertexDecl.m_stride == sizeof(Vertex), "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)", vertexDecl.m_stride, sizeof(Vertex) ); - - const float depth = _clear.m_depth * 2.0f - 1.0f; - - vertex->m_x = -1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = -1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - } - - vb.update(0, 4*_clearQuad.m_decl.m_stride, _clearQuad.m_vb->data); + VertexBufferGL& vb = m_vertexBuffers[_clearQuad.m_vb.idx]; + VertexLayout& layout = _clearQuad.m_layout; GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); ProgramGL& program = m_program[_clearQuad.m_program[numMrt-1].idx]; - GL_CHECK(glUseProgram(program.m_id) ); + setProgram(program.m_id); program.bindAttributesBegin(); - program.bindAttributes(vertexDecl, 0); + program.bindAttributes(layout, 0); program.bindAttributesEnd(); - float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; + if (m_clearQuadColor.idx == kInvalidHandle) + { + const UniformRegInfo* infoClearColor = m_uniformReg.find("bgfx_clear_color"); + if (NULL != infoClearColor) + { + m_clearQuadColor = infoClearColor->m_handle; + } + } + + if (m_clearQuadDepth.idx == kInvalidHandle) + { + const UniformRegInfo* infoClearDepth = m_uniformReg.find("bgfx_clear_depth"); + if (NULL != infoClearDepth) + { + m_clearQuadDepth = infoClearDepth->m_handle; + } + } + + float mrtClearDepth[4] = { g_caps.homogeneousDepth ? (_clear.m_depth * 2.0f - 1.0f) : _clear.m_depth }; + updateUniform(m_clearQuadDepth.idx, mrtClearDepth, sizeof(float)*4); + + float mrtClearColor[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - bx::memCopy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClearColor[ii], _palette[index], 16); } } else @@ -3804,11 +4633,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); for (uint32_t ii = 0; ii < numMrt; ++ii) { - bx::memCopy(mrtClear[ii], rgba, 16); + bx::memCopy(mrtClearColor[ii], rgba, 16); } } - GL_CHECK(glUniform4fv(0, numMrt, mrtClear[0]) ); + updateUniform(m_clearQuadColor.idx, mrtClearColor[0], numMrt * sizeof(float) * 4); + + commit(*program.m_constantBuffer); GL_CHECK(glDrawArrays(GL_TRIANGLE_STRIP , 0 @@ -3817,6 +4648,95 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } + void setProgram(GLuint program) + { + m_uniformStateCache.saveCurrentProgram(program); + GL_CHECK(glUseProgram(program) ); + } + + // Cache uniform uploads to avoid redundant uploading of state that is + // already set to a shader program + void setUniform1i(uint32_t loc, int value) + { + if (m_uniformStateCache.updateUniformCache(loc, value) ) + { + GL_CHECK(glUniform1i(loc, value) ); + } + } + + void setUniform1iv(uint32_t loc, int num, const int *data) + { + bool changed = false; + for(int i = 0; i < num; ++i) + { + if (m_uniformStateCache.updateUniformCache(loc+i, data[i]) ) + { + changed = true; + } + } + if (changed) + { + GL_CHECK(glUniform1iv(loc, num, data) ); + } + } + + void setUniform4f(uint32_t loc, float x, float y, float z, float w) + { + UniformStateCache::f4 f; f.val[0] = x; f.val[1] = y; f.val[2] = z; f.val[3] = w; + if (m_uniformStateCache.updateUniformCache(loc, f) ) + { + GL_CHECK(glUniform4f(loc, x, y, z, w) ); + } + } + + void setUniform4fv(uint32_t loc, int num, const float *data) + { + bool changed = false; + for(int i = 0; i < num; ++i) + { + if (m_uniformStateCache.updateUniformCache(loc+i, *(const UniformStateCache::f4*)&data[4*i]) ) + { + changed = true; + } + } + if (changed) + { + GL_CHECK(glUniform4fv(loc, num, data) ); + } + } + + void setUniformMatrix3fv(uint32_t loc, int num, GLboolean transpose, const float *data) + { + bool changed = false; + for(int i = 0; i < num; ++i) + { + if (m_uniformStateCache.updateUniformCache(loc+i, *(const UniformStateCache::f3x3*)&data[9*i]) ) + { + changed = true; + } + } + if (changed) + { + GL_CHECK(glUniformMatrix3fv(loc, num, transpose, data) ); + } + } + + void setUniformMatrix4fv(uint32_t loc, int num, GLboolean transpose, const float *data) + { + bool changed = false; + for(int i = 0; i < num; ++i) + { + if (m_uniformStateCache.updateUniformCache(loc+i, *(const UniformStateCache::f4x4*)&data[16*i]) ) + { + changed = true; + } + } + if (changed) + { + GL_CHECK(glUniformMatrix4fv(loc, num, transpose, data) ); + } + } + void* m_renderdocdll; uint16_t m_numWindows; @@ -3827,7 +4747,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ShaderGL m_shaders[BGFX_CONFIG_MAX_SHADERS]; ProgramGL m_program[BGFX_CONFIG_MAX_PROGRAMS]; TextureGL m_textures[BGFX_CONFIG_MAX_TEXTURES]; - VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS]; + VertexLayout m_vertexLayouts[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; FrameBufferGL m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; UniformRegistry m_uniformReg; void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; @@ -3836,6 +4756,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); OcclusionQueryGL m_occlusionQuery; SamplerStateCache m_samplerStateCache; + UniformStateCache m_uniformStateCache; TextVideoMem m_textVideoMem; bool m_rtMsaa; @@ -3850,6 +4771,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); float m_maxAnisotropyDefault; int32_t m_maxMsaa; GLuint m_vao; + uint16_t m_maxLabelLen; bool m_blitSupported; bool m_readBackSupported; bool m_vaoSupport; @@ -3864,6 +4786,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bool m_occlusionQuerySupport; bool m_atocSupport; bool m_conservativeRasterSupport; + bool m_imageLoadStoreSupport; bool m_flip; uint64_t m_hash; @@ -3871,14 +4794,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GLenum m_readPixelsFmt; GLuint m_backBufferFbo; GLuint m_msaaBackBufferFbo; - GLuint m_msaaBackBufferRbos[2]; + union { + GLuint m_msaaBackBufferRbos[2]; + GLuint m_msaaBackBufferTextures[2]; + }; + GLuint m_msaaBlitProgram; GlContext m_glctx; bool m_needPresent; + UniformHandle m_clearQuadColor; + UniformHandle m_clearQuadDepth; + const char* m_vendor; const char* m_renderer; const char* m_version; const char* m_glslVersion; + bool m_gles3; Workaround m_workaround; @@ -3908,7 +4839,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); static void frameBufferValidate() { GLenum complete = glCheckFramebufferStatus(GL_FRAMEBUFFER); - BX_CHECK(GL_FRAMEBUFFER_COMPLETE == complete + BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == complete , "glCheckFramebufferStatus failed 0x%08x: %s" , complete , glEnumName(complete) @@ -3982,7 +4913,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); #undef GLSL_TYPE - BX_CHECK(false, "Unknown GLSL type? %x", _type); + BX_ASSERT(false, "Unknown GLSL type? %x", _type); return "UNKNOWN GLSL TYPE!"; } @@ -4020,7 +4951,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { case GL_INT: case GL_UNSIGNED_INT: - return UniformType::Int1; + return UniformType::Sampler; case GL_FLOAT: case GL_FLOAT_VEC2: @@ -4076,10 +5007,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); case GL_IMAGE_CUBE: case GL_INT_IMAGE_CUBE: case GL_UNSIGNED_INT_IMAGE_CUBE: - return UniformType::Int1; + return UniformType::Sampler; }; - BX_CHECK(false, "Unrecognized GL type 0x%04x.", _type); + BX_ASSERT(false, "Unrecognized GL type 0x%04x.", _type); return UniformType::End; } @@ -4153,7 +5084,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 != m_id) { - GL_CHECK(glUseProgram(0) ); + s_renderGL->setProgram(0); GL_CHECK(glDeleteProgram(m_id) ); m_id = 0; } @@ -4442,27 +5373,36 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_used[used++] = ii; } } - BX_CHECK(used < BX_COUNTOF(m_used), "Out of bounds %d > array size %d.", used, Attrib::Count); + BX_ASSERT(used < BX_COUNTOF(m_used), "Out of bounds %d > array size %d.", used, Attrib::Count); m_usedCount = (uint8_t)used; used = 0; - for (uint32_t ii = 0; ii < BX_COUNTOF(s_instanceDataName); ++ii) + for (uint32_t ii = 0, baseVertex = 0; ii < BX_COUNTOF(s_instanceDataName); ++ii, baseVertex += 16) { - GLuint loc = glGetAttribLocation(m_id, s_instanceDataName[ii]); - if (GLuint(-1) != loc ) + GLint loc = glGetAttribLocation(m_id, s_instanceDataName[ii]); + if (-1 != loc) { BX_TRACE("instance data %s: %d", s_instanceDataName[ii], loc); - m_instanceData[used++] = loc; + m_instanceData[used] = loc; + m_instanceOffset[used] = uint16_t(baseVertex); + + used++; } } - BX_CHECK(used < BX_COUNTOF(m_instanceData), "Out of bounds %d > array size %d." - , used - , BX_COUNTOF(m_instanceData) - ); - m_instanceData[used] = 0xffff; + BX_ASSERT(used < BX_COUNTOF(m_instanceData) + , "Out of bounds %d > array size %d." + , used + , BX_COUNTOF(m_instanceData) + ); + m_instanceData[used] = -1; + } + + void ProgramGL::bindAttributesBegin() + { + bx::memCopy(m_unboundUsedAttrib, m_used, sizeof(m_unboundUsedAttrib) ); } - void ProgramGL::bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex) + void ProgramGL::bindAttributes(const VertexLayout& _layout, uint32_t _baseVertex) { for (uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii) { @@ -4473,24 +5413,24 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); AttribType::Enum type; bool normalized; bool asInt; - _vertexDecl.decode(attr, num, type, normalized, asInt); + _layout.decode(attr, num, type, normalized, asInt); if (-1 != loc) { - if (UINT16_MAX != _vertexDecl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { - GL_CHECK(glEnableVertexAttribArray(loc) ); + lazyEnableVertexAttribArray(loc); GL_CHECK(glVertexAttribDivisor(loc, 0) ); - uint32_t baseVertex = _baseVertex*_vertexDecl.m_stride + _vertexDecl.m_offset[attr]; - if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 31) ) - && (AttribType::Uint8 == type || AttribType::Int16 == type) + uint32_t baseVertex = _baseVertex*_layout.m_stride + _layout.m_offset[attr]; + if ( (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || s_renderGL->m_gles3) + && !isFloat(type) && !normalized) { GL_CHECK(glVertexAttribIPointer(loc , num , s_attribType[type] - , _vertexDecl.m_stride + , _layout.m_stride , (void*)(uintptr_t)baseVertex) ); } @@ -4500,7 +5440,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , num , s_attribType[type] , normalized - , _vertexDecl.m_stride + , _layout.m_stride , (void*)(uintptr_t)baseVertex) ); } @@ -4511,38 +5451,53 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } - void ProgramGL::unbindAttributes() + void ProgramGL::bindInstanceData(uint32_t _stride, uint32_t _baseVertex) const { - for(uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii) + for (uint32_t ii = 0; -1 != m_instanceData[ii]; ++ii) + { + GLint loc = m_instanceData[ii]; + lazyEnableVertexAttribArray(loc); + + const uint32_t baseVertex = _baseVertex + m_instanceOffset[ii]; + GL_CHECK(glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, _stride, (void*)(uintptr_t)baseVertex) ); + GL_CHECK(glVertexAttribDivisor(loc, 1) ); + } + } + + void ProgramGL::bindAttributesEnd() + { + for (uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii) { - if(Attrib::Count == m_unboundUsedAttrib[ii]) + if (Attrib::Count != m_unboundUsedAttrib[ii]) { - Attrib::Enum attr = Attrib::Enum(m_used[ii]); + Attrib::Enum attr = Attrib::Enum(m_unboundUsedAttrib[ii]); GLint loc = m_attributes[attr]; - GL_CHECK(glDisableVertexAttribArray(loc)); + lazyDisableVertexAttribArray(loc); } } + + applyLazyEnabledVertexAttributes(); } - void ProgramGL::bindInstanceData(uint32_t _stride, uint32_t _baseVertex) const + void ProgramGL::unbindAttributes() { - uint32_t baseVertex = _baseVertex; - for (uint32_t ii = 0; 0xffff != m_instanceData[ii]; ++ii) + for(uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii) { - GLint loc = m_instanceData[ii]; - GL_CHECK(glEnableVertexAttribArray(loc) ); - GL_CHECK(glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, _stride, (void*)(uintptr_t)baseVertex) ); - GL_CHECK(glVertexAttribDivisor(loc, 1) ); - baseVertex += 16; + if (Attrib::Count == m_unboundUsedAttrib[ii]) + { + Attrib::Enum attr = Attrib::Enum(m_used[ii]); + GLint loc = m_attributes[attr]; + lazyDisableVertexAttribArray(loc); + } } } void ProgramGL::unbindInstanceData() const { - for(uint32_t ii = 0; 0xffff != m_instanceData[ii]; ++ii) + for(uint32_t ii = 0; -1 != m_instanceData[ii]; ++ii) { GLint loc = m_instanceData[ii]; - GL_CHECK(glDisableVertexAttribArray(loc)); + lazyDisableVertexAttribArray(loc); } } @@ -4554,7 +5509,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void VertexBufferGL::destroy() { - GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, 0) ); + GL_CHECK(glBindBuffer(m_target, 0) ); GL_CHECK(glDeleteBuffers(1, &m_id) ); } @@ -4571,20 +5526,28 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); const bool writeOnly = 0 != (m_flags&BGFX_TEXTURE_RT_WRITE_ONLY); const bool computeWrite = 0 != (m_flags&BGFX_TEXTURE_COMPUTE_WRITE ); const bool srgb = 0 != (m_flags&BGFX_TEXTURE_SRGB); + const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK); const bool textureArray = false || _target == GL_TEXTURE_2D_ARRAY || _target == GL_TEXTURE_CUBE_MAP_ARRAY ; - if (!writeOnly) + if (!writeOnly + || (renderTarget && textureArray) ) { GL_CHECK(glGenTextures(1, &m_id) ); - BX_CHECK(0 != m_id, "Failed to generate texture id."); + BX_ASSERT(0 != m_id, "Failed to generate texture id."); GL_CHECK(glBindTexture(_target, m_id) ); GL_CHECK(glPixelStorei(GL_UNPACK_ALIGNMENT, 1) ); const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat]; - m_fmt = tfi.m_fmt; + + const GLenum fmt = srgb + ? s_textureFormat[m_textureFormat].m_fmtSrgb + : s_textureFormat[m_textureFormat].m_fmt + ; + + m_fmt = fmt; m_type = tfi.m_type; const bool swizzle = true @@ -4655,8 +5618,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } - const bool renderTarget = 0 != (m_flags&BGFX_TEXTURE_RT_MASK); - if (renderTarget) { uint32_t msaaQuality = ( (m_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT); @@ -4665,10 +5626,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); const bool msaaSample = 0 != (m_flags&BGFX_TEXTURE_MSAA_SAMPLE); if (!msaaSample - && (0 != msaaQuality || writeOnly) ) + && (0 != msaaQuality || writeOnly) + && !textureArray) { GL_CHECK(glGenRenderbuffers(1, &m_rbo) ); - BX_CHECK(0 != m_rbo, "Failed to generate renderbuffer id."); + BX_ASSERT(0 != m_rbo, "Failed to generate renderbuffer id."); GL_CHECK(glBindRenderbuffer(GL_RENDERBUFFER, m_rbo) ); if (0 == msaaQuality) @@ -4679,7 +5641,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , _height ) ); } - else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) + else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3) { GL_CHECK(glRenderbufferStorageMultisample(GL_RENDERBUFFER , msaaQuality @@ -4709,22 +5671,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (bimg::imageParse(imageContainer, _mem->data, _mem->size) ) { - uint8_t numMips = imageContainer.m_numMips; - const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); - numMips -= startLod; - const uint16_t numLayers = imageContainer.m_numLayers; - uint32_t textureWidth; - uint32_t textureHeight; - uint32_t textureDepth; - { - const bimg::ImageBlockInfo& ibi = bimg::getBlockInfo(bimg::TextureFormat::Enum(imageContainer.m_format) ); - textureWidth = bx::uint32_max(ibi.blockWidth, imageContainer.m_width >>startLod); - textureHeight = bx::uint32_max(ibi.blockHeight, imageContainer.m_height>>startLod); - textureDepth = 1 < imageContainer.m_depth - ? imageContainer.m_depth - : imageContainer.m_numLayers - ; - } + const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips-1); + + bimg::TextureInfo ti; + bimg::imageGetSize( + &ti + , uint16_t(imageContainer.m_width >>startLod) + , uint16_t(imageContainer.m_height>>startLod) + , uint16_t(imageContainer.m_depth >>startLod) + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + , imageContainer.m_numLayers + , imageContainer.m_format + ); + ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips-startLod, ti.numMips); m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); @@ -4746,7 +5706,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); target = GL_TEXTURE_3D; } - const bool textureArray = 1 < numLayers; + const bool textureArray = 1 < ti.numLayers; if (textureArray) { switch (target) @@ -4758,16 +5718,18 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } if (!init(target - , textureWidth - , textureHeight - , textureDepth - , numMips - , _flags - ) ) + , ti.width + , ti.height + , textureArray ? ti.numLayers : ti.depth + , ti.numMips + , _flags + ) ) { return; } + m_numLayers = ti.numLayers; + target = isCubeMap() ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : m_target @@ -4777,6 +5739,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ? s_textureFormat[m_textureFormat].m_internalFmtSrgb : s_textureFormat[m_textureFormat].m_internalFmt ; + const GLenum fmt = srgb + ? s_textureFormat[m_textureFormat].m_fmtSrgb + : s_textureFormat[m_textureFormat].m_fmt + ; const bool swizzle = true && TextureFormat::BGRA8 == m_requestedFormat @@ -4795,9 +5761,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , getName( (TextureFormat::Enum)m_textureFormat) , srgb ? "+sRGB " : "" , getName( (TextureFormat::Enum)m_requestedFormat) - , numLayers - , textureWidth - , textureHeight + , ti.numLayers + , ti.width + , ti.height , imageContainer.m_cubeMap ? 6 : (1 < imageContainer.m_depth ? imageContainer.m_depth : 0) , 0 != (m_flags&BGFX_TEXTURE_RT_MASK) ? " (render target)" : "" ); @@ -4813,22 +5779,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); uint8_t* temp = NULL; if (convert) { - temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4); + temp = (uint8_t*)BX_ALLOC(g_allocator, ti.width*ti.height*4); } - const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); for (uint16_t side = 0; side < numSides; ++side) { - uint32_t width = textureWidth; - uint32_t height = textureHeight; - uint32_t depth = imageContainer.m_depth; + uint32_t width = ti.width; + uint32_t height = ti.height; + uint32_t depth = ti.depth; GLenum imageTarget = imageContainer.m_cubeMap && !textureArray ? target+side : target ; - for (uint8_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod) { width = bx::uint32_max(1, width); height = bx::uint32_max(1, height); @@ -4880,7 +5846,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , height , depth , 0 - , m_fmt + , fmt , m_type , data ) ); @@ -4888,10 +5854,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } else if (!computeWrite) { - if (compressed) + if (compressed + && !convert) { - uint32_t size = bx::uint32_max(1, (width + 3)>>2) - * bx::uint32_max(1, (height + 3)>>2) + uint32_t size = bx::max<uint32_t>(1, (width + 3)>>2) + * bx::max<uint32_t>(1, (height + 3)>>2) * 4*4* bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) )/8 ; @@ -4916,7 +5883,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , height , depth , 0 - , m_fmt + , fmt , m_type , NULL ) ); @@ -4929,6 +5896,23 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } + GLint mapping[4] = { + s_textureFormat[m_textureFormat].m_mapping[0], + s_textureFormat[m_textureFormat].m_mapping[1], + s_textureFormat[m_textureFormat].m_mapping[2], + s_textureFormat[m_textureFormat].m_mapping[3], + }; + if (s_renderGL->m_textureSwizzleSupport + && (-1 != mapping[0] || -1 != mapping[1] || -1 != mapping[2] || -1 != mapping[3]) ) + { + mapping[0] = -1 == mapping[0] ? GL_RED : mapping[0]; + mapping[1] = -1 == mapping[1] ? GL_GREEN : mapping[1]; + mapping[2] = -1 == mapping[2] ? GL_BLUE : mapping[2]; + mapping[3] = -1 == mapping[3] ? GL_ALPHA : mapping[3]; + + GL_CHECK(glTexParameteriv(m_target, GL_TEXTURE_SWIZZLE_RGBA, mapping)); + } + if (NULL != temp) { BX_FREE(g_allocator, temp); @@ -4988,8 +5972,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); || swizzle ; - const uint32_t width = _rect.m_width; - const uint32_t height = _rect.m_height; + Rect rect; + rect.setIntersect(_rect + , { + 0, 0, + uint16_t(bx::max(1u, m_width >> _mip) ), + uint16_t(bx::max(1u, m_height >> _mip) ), + }); + + uint32_t width = rect.m_width; + uint32_t height = rect.m_height; uint8_t* temp = NULL; if (convert @@ -5002,7 +5994,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glPixelStorei(GL_UNPACK_ROW_LENGTH, srcpitch*8/bpp) ); } - if (compressed) + if (compressed + && !convert) { const uint8_t* data = _mem->data; @@ -5011,16 +6004,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bimg::imageCopy(temp, width, height, 1, bpp, srcpitch, data); data = temp; } - + const GLenum internalFmt = (0 != (m_flags & BGFX_TEXTURE_SRGB) ) + ? s_textureFormat[m_textureFormat].m_internalFmtSrgb + : s_textureFormat[m_textureFormat].m_internalFmt + ; GL_CHECK(compressedTexSubImage(target+_side , _mip - , _rect.m_x - , _rect.m_y + , rect.m_x + , rect.m_y , _z - , _rect.m_width - , _rect.m_height + , rect.m_width + , rect.m_height , _depth - , m_fmt + , internalFmt , _mem->size , data ) ); @@ -5046,11 +6042,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(texSubImage(target+_side , _mip - , _rect.m_x - , _rect.m_y + , rect.m_x + , rect.m_y , _z - , _rect.m_width - , _rect.m_height + , rect.m_width + , rect.m_height , _depth , m_fmt , m_type @@ -5072,7 +6068,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void TextureGL::setSamplerState(uint32_t _flags, const float _rgba[4]) { - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) + if (!s_renderGL->m_gles3 && !s_textureFilter[m_textureFormat]) { // Force point sampling when texture format doesn't support linear sampling. @@ -5115,7 +6111,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glTexParameteri(target, GL_TEXTURE_WRAP_S, s_textureAddress[(flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT]) ); GL_CHECK(glTexParameteri(target, GL_TEXTURE_WRAP_T, s_textureAddress[(flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT]) ); - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 30) + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3 || s_extension[Extension::APPLE_texture_max_level].m_supported) { GL_CHECK(glTexParameteri(targetMsaa, GL_TEXTURE_MAX_LEVEL, numMips-1) ); @@ -5149,7 +6145,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glTexParameterf(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, s_renderGL->m_maxAnisotropy) ); } - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) + if (s_renderGL->m_gles3 || s_renderGL->m_shadowSamplersSupport) { const uint32_t cmpFunc = (flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT; @@ -5179,29 +6175,13 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glActiveTexture(GL_TEXTURE0+_stage) ); GL_CHECK(glBindTexture(m_target, m_id) ); - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) - && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) ) + if (s_renderGL->m_samplerObjectSupport) { - // GLES2 doesn't have support for sampler object. - setSamplerState(flags, _palette[index]); - } - else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) - && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL < 31) ) - { - // In case that GL 2.1 sampler object is supported via extension. - if (s_renderGL->m_samplerObjectSupport) - { - s_renderGL->setSamplerState(_stage, m_numMips, flags, _palette[index]); - } - else - { - setSamplerState(flags, _palette[index]); - } + s_renderGL->setSamplerState(_stage, m_numMips, flags, _palette[index]); } else { - // Everything else has sampler object. - s_renderGL->setSamplerState(_stage, m_numMips, flags, _palette[index]); + setSamplerState(flags, _palette[index]); } } @@ -5230,8 +6210,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bx::MemoryReader reader(_mem->data, _mem->size); m_hash = bx::hash<bx::HashMurmur2A>(_mem->data, _mem->size); + bx::ErrorAssert err; + uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, &err); if (isShaderType(magic, 'C') ) { @@ -5247,7 +6229,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } uint32_t hashIn; - bx::read(&reader, hashIn); + bx::read(&reader, hashIn, &err); uint32_t hashOut; @@ -5257,11 +6239,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } else { - bx::read(&reader, hashOut); + bx::read(&reader, hashOut, &err); } uint16_t count; - bx::read(&reader, count); + bx::read(&reader, count, &err); BX_TRACE("%s Shader consts %d" , getShaderTypeName(magic) @@ -5271,27 +6253,39 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize = 0; - bx::read(&reader, nameSize); + bx::read(&reader, nameSize, &err); char name[256]; - bx::read(&reader, &name, nameSize); + bx::read(&reader, &name, nameSize, &err); name[nameSize] = '\0'; uint8_t type; - bx::read(&reader, type); + bx::read(&reader, type, &err); uint8_t num; - bx::read(&reader, num); + bx::read(&reader, num, &err); uint16_t regIndex; - bx::read(&reader, regIndex); + bx::read(&reader, regIndex, &err); uint16_t regCount; - bx::read(&reader, regCount); + bx::read(&reader, regCount, &err); + + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo = 0; + bx::read(&reader, texInfo, &err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(&reader, texFormat, &err); + } } uint32_t shaderSize; - bx::read(&reader, shaderSize); + bx::read(&reader, shaderSize, &err); m_id = glCreateShader(m_type); BX_WARN(0 != m_id, "Failed to create shader."); @@ -5301,22 +6295,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 != m_id) { if (GL_COMPUTE_SHADER != m_type - && 0 != bx::strCmp(code, "#version 430", 12) ) + && 0 != bx::strCmp(code, "#version", 8) ) // #2000 { int32_t tempLen = code.getLength() + (4<<10); char* temp = (char*)alloca(tempLen); bx::StaticMemoryBlockWriter writer(temp, tempLen); - bx::Error err; - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES) - && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES < 30) ) + && !s_renderGL->m_gles3) { bx::write(&writer , "#define centroid\n" "#define flat\n" "#define noperspective\n" "#define smooth\n" + , &err ); bool usesDerivatives = s_extension[Extension::OES_standard_derivatives].m_supported @@ -5336,7 +6329,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (usesDerivatives) { - bx::write(&writer, "#extension GL_OES_standard_derivatives : enable\n"); + bx::write(&writer, "#extension GL_OES_standard_derivatives : enable\n", &err); } if (usesFragData) @@ -5345,7 +6338,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); || s_extension[Extension::WEBGL_draw_buffers].m_supported , "EXT_draw_buffers is used but not supported by GLES2 driver." ); - bx::write(&writer, "#extension GL_EXT_draw_buffers : enable\n"); + bx::write(&writer, "#extension GL_EXT_draw_buffers : enable\n", &err); } bool insertFragDepth = false; @@ -5357,13 +6350,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bx::write(&writer , "#extension GL_EXT_frag_depth : enable\n" "#define bgfx_FragDepth gl_FragDepthEXT\n" + , &err ); char str[128]; bx::snprintf(str, BX_COUNTOF(str), "%s float gl_FragDepthEXT;\n" , s_extension[Extension::OES_fragment_precision_high].m_supported ? "highp" : "mediump" ); - bx::write(&writer, str); + bx::write(&writer, str, &err); } else { @@ -5379,6 +6373,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , "#extension GL_EXT_shadow_samplers : enable\n" "#define shadow2D shadow2DEXT\n" "#define shadow2DProj shadow2DProjEXT\n" + , &err ); } else @@ -5387,13 +6382,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , "#define sampler2DShadow sampler2D\n" "#define shadow2D(_sampler, _coord) step(_coord.z, texture2D(_sampler, _coord.xy).x)\n" "#define shadow2DProj(_sampler, _coord) step(_coord.z/_coord.w, texture2DProj(_sampler, _coord).x)\n" + , &err ); } } if (usesTexture3D) { - bx::write(&writer, "#extension GL_OES_texture_3D : enable\n"); + bx::write(&writer, "#extension GL_OES_texture_3D : enable\n", &err); } if (usesTextureLod) @@ -5413,17 +6409,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); "#define texture2DGrad texture2DGradARB\n" "#define texture2DProjGrad texture2DProjGradARB\n" "#define textureCubeGrad textureCubeGradARB\n" + , &err ); } else { - if(s_extension[Extension::EXT_shader_texture_lod].m_supported) + if (s_extension[Extension::EXT_shader_texture_lod].m_supported) { bx::write(&writer , "#extension GL_EXT_shader_texture_lod : enable\n" "#define texture2DLod texture2DLodEXT\n" "#define texture2DProjLod texture2DProjLodEXT\n" "#define textureCubeLod textureCubeLodEXT\n" + , &err ); } else @@ -5432,6 +6430,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , "#define texture2DLod(_sampler, _coord, _level) texture2D(_sampler, _coord)\n" "#define texture2DProjLod(_sampler, _coord, _level) texture2DProj(_sampler, _coord)\n" "#define textureCubeLod(_sampler, _coord, _level) textureCube(_sampler, _coord)\n" + , &err ); } } @@ -5441,11 +6440,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { if (s_extension[Extension::INTEL_fragment_shader_ordering].m_supported) { - bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n"); + bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n", &err); } else { - bx::write(&writer, "#define beginFragmentShaderOrdering()\n"); + bx::write(&writer, "#define beginFragmentShaderOrdering()\n", &err); } } @@ -5453,8 +6452,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , m_type == GL_FRAGMENT_SHADER ? "mediump" : "highp" ); - bx::write(&writer, code); - bx::write(&writer, '\0'); + bx::write(&writer, code, &err); + bx::write(&writer, '\0', &err); if (insertFragDepth) { @@ -5478,7 +6477,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); // Replace all instances of gl_FragDepth with bgfx_FragDepth. for (bx::StringView fragDepth = bx::findIdentifierMatch(temp, "gl_FragDepth") ; !fragDepth.isEmpty() - ; fragDepth = bx::findIdentifierMatch(fragDepth, "gl_FragDepth") + ; fragDepth = bx::findIdentifierMatch(fragDepth.getPtr(), "gl_FragDepth") ) { char* insert = const_cast<char*>(fragDepth.getPtr() ); @@ -5493,8 +6492,33 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); && s_extension[Extension::ARB_shader_texture_lod].m_supported && !bx::findIdentifierMatch(code, s_ARB_shader_texture_lod).isEmpty() ; - const bool usesGpuShader4 = !bx::findIdentifierMatch(code, s_EXT_gpu_shader4).isEmpty(); - const bool usesGpuShader5 = !bx::findIdentifierMatch(code, s_ARB_gpu_shader5).isEmpty(); + + const bool usesVertexID = true + && !s_extension[Extension::EXT_gpu_shader4].m_supported + && !bx::findIdentifierMatch(code, "gl_VertexID").isEmpty() + ; + + const bool usesInstanceID = true + && !s_extension[Extension::EXT_gpu_shader4].m_supported + && !bx::findIdentifierMatch(code, "gl_InstanceID").isEmpty() + ; + + const bool usesGpuShader4 = true + && s_extension[Extension::EXT_gpu_shader4].m_supported + && !bx::findIdentifierMatch(code, s_EXT_gpu_shader4).isEmpty() + ; + + // GpuShader5 extension is not supported on the fragment shader! + const bool usesGpuShader5 = true + && m_type != GL_FRAGMENT_SHADER + && !bx::findIdentifierMatch(code, s_ARB_gpu_shader5).isEmpty() + ; + + const bool usesViewportLayerArray = true + && s_extension[Extension::ARB_shader_viewport_layer_array].m_supported + && !bx::findIdentifierMatch(code, s_ARB_shader_viewport_layer_array).isEmpty() + ; + const bool usesIUsamplers = !bx::findIdentifierMatch(code, s_uisamplers).isEmpty(); const bool usesUint = !bx::findIdentifierMatch(code, s_uint).isEmpty(); const bool usesTexelFetch = !bx::findIdentifierMatch(code, s_texelFetch).isEmpty(); @@ -5508,6 +6532,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); : usesTextureArray || usesTexture3D || usesIUsamplers + || usesVertexID || usesUint || usesTexelFetch || usesGpuShader5 @@ -5516,12 +6541,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); : 120 ; - if (0 != version) - { - bx::write(&writer, &err, "#version %d\n", version); - } + version = 0 == bx::strCmp(code, "#version 430", 12) ? 430 : version; - if (usesTextureLod) + bx::write(&writer, &err, "#version %d\n", version); + + if (430 > version && usesTextureLod) { if (m_type == GL_FRAGMENT_SHADER) { @@ -5530,68 +6554,83 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); "#define texture2DGrad texture2DGradARB\n" "#define texture2DProjGrad texture2DProjGradARB\n" "#define textureCubeGrad textureCubeGradARB\n" + , &err ); } } + if (usesInstanceID) + { + bx::write(&writer, "#extension GL_ARB_draw_instanced : enable\n", &err); + } + if (usesGpuShader4) { - bx::write(&writer, "#extension GL_EXT_gpu_shader4 : enable\n"); + bx::write(&writer, "#extension GL_EXT_gpu_shader4 : enable\n", &err); } if (usesGpuShader5) { - bx::write(&writer, "#extension GL_ARB_gpu_shader5 : enable\n"); + bx::write(&writer, "#extension GL_ARB_gpu_shader5 : enable\n", &err); + } + + if (usesViewportLayerArray) + { + bx::write(&writer, "#extension GL_ARB_shader_viewport_layer_array : enable\n", &err); } if (usesPacking) { - bx::write(&writer, "#extension GL_ARB_shading_language_packing : enable\n"); + bx::write(&writer, "#extension GL_ARB_shading_language_packing : enable\n", &err); } if (usesTextureMS) { - bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n"); + bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n", &err); } if (usesTextureArray) { - bx::write(&writer, "#extension GL_EXT_texture_array : enable\n"); + bx::write(&writer, "#extension GL_EXT_texture_array : enable\n", &err); if (BX_ENABLED(BX_PLATFORM_OSX) ) { - bx::write(&writer, "#define texture2DArrayLodEXT texture2DArray\n"); + bx::write(&writer, "#define texture2DArrayLod texture2DArray\n", &err); } else { - bx::write(&writer, "#define texture2DArrayLodEXT texture2DArrayLod\n"); + bx::write(&writer, "#define texture2DArrayLodEXT texture2DArrayLod\n", &err); + bx::write(&writer, "#define textureArray texture\n", &err); } } if (usesTexture3D) { - bx::write(&writer, "#define texture3DEXT texture3D\n"); + bx::write(&writer, "#define texture3DEXT texture3D\n", &err); if (BX_ENABLED(BX_PLATFORM_OSX) ) { - bx::write(&writer, "#define texture3DLodEXT texture3D\n"); + bx::write(&writer, "#define texture3DLodEXT texture3D\n", &err); } else { - bx::write(&writer, "#define texture3DLodEXT texture3DLod\n"); + bx::write(&writer, "#define texture3DLodEXT texture3DLod\n", &err); } } if (130 <= version) { - if (m_type == GL_FRAGMENT_SHADER) + if (430 > version) { - bx::write(&writer, "#define varying in\n"); - } - else - { - bx::write(&writer, "#define attribute in\n"); - bx::write(&writer, "#define varying out\n"); + if (m_type == GL_FRAGMENT_SHADER) + { + bx::write(&writer, "#define varying in\n", &err); + } + else + { + bx::write(&writer, "#define attribute in\n", &err); + bx::write(&writer, "#define varying out\n", &err); + } } uint32_t fragData = 0; @@ -5611,52 +6650,68 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 != fragData) { bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData); - bx::write(&writer, "#define gl_FragData bgfx_FragData\n"); + bx::write(&writer, "#define gl_FragData bgfx_FragData\n", &err); } - else + else if (!bx::findIdentifierMatch(code, "gl_FragColor").isEmpty() ) { - bx::write(&writer, "out vec4 bgfx_FragColor;\n"); - bx::write(&writer, "#define gl_FragColor bgfx_FragColor\n"); + bx::write(&writer + , "out vec4 bgfx_FragColor;\n" + "#define gl_FragColor bgfx_FragColor\n" + , &err + ); } } else { if (m_type == GL_FRAGMENT_SHADER) { - bx::write(&writer, "#define in varying\n"); + bx::write(&writer, "#define in varying\n", &err); } else { bx::write(&writer , "#define in attribute\n" "#define out varying\n" + , &err ); } } - bx::write(&writer, - "#define lowp\n" - "#define mediump\n" - "#define highp\n" + bx::write(&writer + , "#define lowp\n" + "#define mediump\n" + "#define highp\n" + , &err ); if (!usesInterpQ) { - bx::write(&writer, - "#define centroid\n" - "#define flat\n" - "#define noperspective\n" - "#define smooth\n" + bx::write(&writer + , + "#define centroid\n" + "#define flat\n" + "#define noperspective\n" + "#define smooth\n" + , &err ); } - bx::write(&writer, code); - bx::write(&writer, '\0'); + if (version == 430) + { + int32_t verLen = bx::strLen("#version 430\n"); + bx::write(&writer, code.getPtr()+verLen, code.getLength()-verLen, &err); + } + else + { + bx::write(&writer, code, &err); + } + + bx::write(&writer, '\0', &err); } else if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 31) - || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) + || s_renderGL->m_gles3) { - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) + if (s_renderGL->m_gles3) { bx::write(&writer, &err , "#version 300 es\n" @@ -5666,7 +6721,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } else { - bx::write(&writer, "#version 140\n"); + bx::write(&writer, "#version 140\n", &err); } bx::write(&writer @@ -5676,33 +6731,47 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); "#define texture2DGrad textureGrad\n" "#define texture3DGrad textureGrad\n" "#define textureCubeGrad textureGrad\n" + , &err ); if (m_type == GL_FRAGMENT_SHADER) { bx::write(&writer - , "#define varying in\n" - "#define texture2D texture\n" - "#define texture2DProj textureProj\n" + , "#define varying in\n" + "#define texture2D texture\n" + "#define texture2DArray texture\n" + "#define texture2DProj textureProj\n" + , &err ); if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) { - bx::write(&writer, "#define shadow2D(_sampler, _coord) vec2(textureProj(_sampler, vec4(_coord, 1.0) ) )\n"); - bx::write(&writer, "#define shadow2DProj(_sampler, _coord) vec2(textureProj(_sampler, _coord) ) )\n"); + bx::write(&writer + , "#define shadow2D(_sampler, _coord) vec2(textureProj(_sampler, vec4(_coord, 1.0) ) )\n" + "#define shadow2DProj(_sampler, _coord) vec2(textureProj(_sampler, _coord) )\n" + , &err + ); } else { - bx::write(&writer, "#define shadow2D(_sampler, _coord) (textureProj(_sampler, vec4(_coord, 1.0) ) )\n"); - bx::write(&writer, "#define shadow2DProj(_sampler, _coord) (textureProj(_sampler, _coord) ) )\n"); + bx::write(&writer + , "#define shadow2D(_sampler, _coord) (textureProj(_sampler, vec4(_coord, 1.0) ) )\n" + "#define shadow2DProj(_sampler, _coord) (textureProj(_sampler, _coord) )\n" + , &err + ); } - bx::write(&writer, "#define texture3D texture\n"); - bx::write(&writer, "#define textureCube texture\n"); + bx::write(&writer + , "#define texture3D texture\n" + "#define textureCube texture\n" + , &err + ); uint32_t fragData = 0; - if (!bx::findIdentifierMatch(code, "gl_FragData").isEmpty() ) + bool patchedFragData = s_renderGL->m_gles3 && !bx::findIdentifierMatch(code, "bgfx_FragData").isEmpty(); + + if (!patchedFragData && !bx::findIdentifierMatch(code, "gl_FragData").isEmpty() ) { for (uint32_t ii = 0, num = g_caps.limits.maxFBAttachments; ii < num; ++ii) { @@ -5718,30 +6787,37 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { if (s_extension[Extension::INTEL_fragment_shader_ordering].m_supported) { - bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n"); + bx::write(&writer, "#extension GL_INTEL_fragment_shader_ordering : enable\n", &err); } else { - bx::write(&writer, "#define beginFragmentShaderOrdering()\n"); + bx::write(&writer, "#define beginFragmentShaderOrdering()\n", &err); } } if (!bx::findIdentifierMatch(code, s_ARB_texture_multisample).isEmpty() ) { - bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n"); + bx::write(&writer, "#extension GL_ARB_texture_multisample : enable\n", &err); } if (0 != fragData) { - bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData); - bx::write(&writer, "#define gl_FragData bgfx_FragData\n"); + if (!patchedFragData) + { + bx::write(&writer, &err, "out vec4 bgfx_FragData[%d];\n", fragData); + bx::write(&writer, "#define gl_FragData bgfx_FragData\n", &err); + } } - else + else if (!patchedFragData) { - bx::write(&writer - , "out vec4 bgfx_FragColor;\n" - "#define gl_FragColor bgfx_FragColor\n" - ); + if (bx::findIdentifierMatch(code, "bgfx_FragColor").isEmpty() ) + { + bx::write(&writer + , "out vec4 bgfx_FragColor;\n" + "#define gl_FragColor bgfx_FragColor\n" + , &err + ); + } } } else @@ -5749,20 +6825,22 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bx::write(&writer , "#define attribute in\n" "#define varying out\n" + , &err ); } - if (!BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) + if (!s_renderGL->m_gles3) { bx::write(&writer , "#define lowp\n" "#define mediump\n" "#define highp\n" + , &err ); } - bx::write(&writer, code.getPtr(), code.getLength() ); - bx::write(&writer, '\0'); + bx::write(&writer, code.getPtr(), code.getLength(), &err); + bx::write(&writer, '\0', &err); } code.set(temp); @@ -5776,21 +6854,31 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bx::write(&writer , "#version 430\n" - "#define texture2DLod textureLod\n" - "#define texture3DLod textureLod\n" - "#define textureCubeLod textureLod\n" - "#define texture2DGrad textureGrad\n" - "#define texture3DGrad textureGrad\n" - "#define textureCubeGrad textureGrad\n" + "#define texture2DLod textureLod\n" + "#define texture2DLodOffset textureLodOffset\n" + "#define texture2DArrayLod textureLod\n" + "#define texture2DArrayLodOffset textureLodOffset\n" + "#define texture3DLod textureLod\n" + "#define textureCubeLod textureLod\n" + "#define texture2DGrad textureGrad\n" + "#define texture3DGrad textureGrad\n" + "#define textureCubeGrad textureGrad\n" + , &err ); - bx::write(&writer, code.getPtr()+bx::strLen("#version 430"), codeLen); - bx::write(&writer, '\0'); + int32_t verLen = bx::strLen("#version 430\n"); + bx::write(&writer, code.getPtr()+verLen, codeLen-verLen, &err); + bx::write(&writer, '\0', &err); code = temp; } - GL_CHECK(glShaderSource(m_id, 1, (const GLchar**)&code, NULL) ); + { + const GLchar* str = (const GLchar*)code.getPtr(); + int32_t len = code.getLength(); + GL_CHECK(glShaderSource(m_id, 1, &str, &len) ); + } + GL_CHECK(glCompileShader(m_id) ); GLint compiled = 0; @@ -5798,33 +6886,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 == compiled) { - LineReader lineReader(code); - bx::Error err; - for (int32_t line = 1; err.isOk(); ++line) + bx::LineReader lineReader(code); + for (int32_t line = 1; !lineReader.isDone(); ++line) { - char str[4096]; - int32_t len = bx::read(&lineReader, str, BX_COUNTOF(str)-1, &err); - - if (err.isOk() ) - { - str[len] = '\0'; - bx::StringView eol = bx::strFindEol(str); - if (eol.getPtr() != str) - { - *const_cast<char*>(eol.getPtr() ) = '\0'; - } - BX_TRACE("%3d %s", line, str); - } + bx::StringView str = lineReader.next(); + BX_TRACE("%3d %.*s", line, str.getLength(), str.getPtr() ); + BX_UNUSED(str, line); } GLsizei len; char log[1024]; GL_CHECK(glGetShaderInfoLog(m_id, sizeof(log), &len, log) ); - BX_TRACE("Failed to compile shader. %d: %s", compiled, log); GL_CHECK(glDeleteShader(m_id) ); m_id = 0; - BGFX_FATAL(false, bgfx::Fatal::InvalidShader, "Failed to compile shader."); + BGFX_FATAL(false, bgfx::Fatal::InvalidShader, "Failed to compile shader. %d: %s", compiled, log); } else if (BX_ENABLED(BGFX_CONFIG_DEBUG) && s_extension[Extension::ANGLE_translated_shader_source].m_supported @@ -5906,7 +6982,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); attachment = GL_DEPTH_ATTACHMENT; } } - else + else if (Access::Write == at.access) { buffers[colorIdx] = attachment; ++colorIdx; @@ -5914,8 +6990,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 != texture.m_rbo) { -#if !(BGFX_CONFIG_RENDERER_OPENGL >= 30 || BGFX_CONFIG_RENDERER_OPENGLES >= 30) - if (GL_DEPTH_STENCIL_ATTACHMENT == attachment) + if (!(BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL >= 30) || s_renderGL->m_gles3) + && GL_DEPTH_STENCIL_ATTACHMENT == attachment) { GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER , GL_DEPTH_ATTACHMENT @@ -5929,7 +7005,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ) ); } else -#endif { GL_CHECK(glFramebufferRenderbuffer(GL_FRAMEBUFFER , attachment @@ -5938,17 +7013,30 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ) ); } } - else if (Access::Write == at.access) + else { - if (1 < texture.m_depth - && !texture.isCubeMap()) + if (1 < texture.m_numLayers + && !texture.isCubeMap() ) { - GL_CHECK(glFramebufferTextureLayer(GL_FRAMEBUFFER - , attachment - , texture.m_id - , at.mip - , at.layer - ) ); + if (1 < at.numLayers) + { + BX_ASSERT(0 == at.layer, "Can't use start layer > 0 when binding multiple layers to a framebuffer."); + + GL_CHECK(glFramebufferTexture(GL_FRAMEBUFFER + , attachment + , texture.m_id + , at.mip + ) ); + } + else + { + GL_CHECK(glFramebufferTextureLayer(GL_FRAMEBUFFER + , attachment + , texture.m_id + , at.mip + , at.layer + ) ); + } } else { @@ -5965,10 +7053,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ) ); } } - else - { - BX_CHECK(false, ""); - } needResolve |= (0 != texture.m_rbo) && (0 != texture.m_id); } @@ -5976,22 +7060,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_num = uint8_t(colorIdx); - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES >= 31) ) + if (0 == colorIdx && BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) { - if (0 == colorIdx) - { - if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) ) - { - // When only depth is attached disable draw buffer to avoid - // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER. - GL_CHECK(glDrawBuffer(GL_NONE) ); - } - } - else - { - GL_CHECK(glDrawBuffers(colorIdx, buffers) ); - } + // When only depth is attached disable draw buffer to avoid + // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER. + GL_CHECK(glDrawBuffer(GL_NONE) ); + } + else if (g_caps.limits.maxFBAttachments > 0) + { + GL_CHECK(glDrawBuffers(colorIdx, buffers) ); + } + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3) + { // Disable read buffer to avoid GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER. GL_CHECK(glReadBuffer(GL_NONE) ); } @@ -6014,23 +7095,42 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (0 != texture.m_id) { - GLenum attachment = GL_COLOR_ATTACHMENT0 + colorIdx; - if (!bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) ) + + GLenum attachment = GL_INVALID_ENUM; + bimg::TextureFormat::Enum format = bimg::TextureFormat::Enum(texture.m_textureFormat); + if (bimg::isDepth(format) ) + { + const bimg::ImageBlockInfo& info = bimg::getBlockInfo(format); + if (0 < info.stencilBits) + { + attachment = GL_DEPTH_STENCIL_ATTACHMENT; + } + else if (0 == info.depthBits) + { + attachment = GL_STENCIL_ATTACHMENT; + } + else + { + attachment = GL_DEPTH_ATTACHMENT; + } + } + else { + attachment = GL_COLOR_ATTACHMENT0 + colorIdx; ++colorIdx; + } - GLenum target = texture.isCubeMap() - ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + at.layer - : texture.m_target - ; + GLenum target = texture.isCubeMap() + ? GL_TEXTURE_CUBE_MAP_POSITIVE_X + at.layer + : texture.m_target + ; - GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER - , attachment - , target - , texture.m_id - , at.mip - ) ); - } + GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER + , attachment + , target + , texture.m_id + , at.mip + ) ); } } } @@ -6045,7 +7145,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); void FrameBufferGL::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) { BX_UNUSED(_format, _depthFormat); - m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh); + m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh, _width, _height); m_width = _width; m_height = _height; m_numTh = 0; @@ -6055,7 +7155,7 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); uint16_t FrameBufferGL::destroy() { - if (0 != m_num) + if (0 != m_fbo[0]) { GL_CHECK(glDeleteFramebuffers(0 == m_fbo[1] ? 1 : 2, m_fbo) ); m_num = 0; @@ -6089,14 +7189,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { const TextureGL& texture = s_renderGL->m_textures[at.handle.idx]; + const bool writeOnly = 0 != (texture.m_flags&BGFX_TEXTURE_RT_WRITE_ONLY); bimg::TextureFormat::Enum format = bimg::TextureFormat::Enum(texture.m_textureFormat); + if (!bimg::isDepth(format) ) { + GL_CHECK(glDisable(GL_SCISSOR_TEST) ); + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) ); GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo[1]) ); + GL_CHECK(glReadBuffer(GL_COLOR_ATTACHMENT0 + colorIdx) ); GL_CHECK(glDrawBuffer(GL_COLOR_ATTACHMENT0 + colorIdx) ); + colorIdx++; + GL_CHECK(glBlitFramebuffer(0 , 0 , m_width @@ -6109,11 +7216,35 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , GL_LINEAR ) ); } + else if (!writeOnly) + { + GL_CHECK(glDisable(GL_SCISSOR_TEST) ); + + GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) ); + GL_CHECK(glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo[1]) ); + + GL_CHECK(glBlitFramebuffer(0 + , 0 + , m_width + , m_height + , 0 + , 0 + , m_width + , m_height + , GL_DEPTH_BUFFER_BIT + , GL_NEAREST + ) ); + } } } GL_CHECK(glBindFramebuffer(GL_READ_FRAMEBUFFER, m_fbo[0]) ); - GL_CHECK(glReadBuffer(GL_NONE) ); + + if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || s_renderGL->m_gles3) + { + GL_CHECK(glReadBuffer(GL_NONE) ); + } + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderGL->m_msaaBackBufferFbo) ); } @@ -6255,16 +7386,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); const TextureGL& src = m_textures[bi.m_src.idx]; const TextureGL& dst = m_textures[bi.m_dst.idx]; - uint32_t srcWidth = bx::uint32_min(src.m_width, bi.m_srcX + bi.m_width) - bi.m_srcX; - uint32_t srcHeight = bx::uint32_min(src.m_height, bi.m_srcY + bi.m_height) - bi.m_srcY; - uint32_t srcDepth = bx::uint32_min(src.m_depth, bi.m_srcZ + bi.m_depth) - bi.m_srcZ; - uint32_t dstWidth = bx::uint32_min(dst.m_width, bi.m_dstX + bi.m_width) - bi.m_dstX; - uint32_t dstHeight = bx::uint32_min(dst.m_height, bi.m_dstY + bi.m_height) - bi.m_dstY; - uint32_t dstDepth = bx::uint32_min(dst.m_depth, bi.m_dstZ + bi.m_depth) - bi.m_dstZ; - uint32_t width = bx::uint32_min(srcWidth, dstWidth); - uint32_t height = bx::uint32_min(srcHeight, dstHeight); - uint32_t depth = bx::uint32_min(srcDepth, dstDepth); - GL_CHECK(glCopyImageSubData(src.m_id , src.m_target , bi.m_srcMip @@ -6277,10 +7398,56 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); , bi.m_dstX , bi.m_dstY , bi.m_dstZ - , width - , height - , bx::uint32_imax(depth, 1) + , bi.m_width + , bi.m_height + , bx::uint32_imax(bi.m_depth, 1) + ) ); + } + } + else if (BX_ENABLED(BGFX_GL_CONFIG_BLIT_EMULATION) ) + { + while (_bs.hasItem(_view) ) + { + const BlitItem& bi = _bs.advance(); + + const TextureGL& src = m_textures[bi.m_src.idx]; + const TextureGL& dst = m_textures[bi.m_dst.idx]; + + BX_ASSERT(0 == bi.m_srcZ && 0 == bi.m_dstZ && 1 >= bi.m_depth + , "Blitting 3D regions is not supported" + ); + + GLuint fbo; + GL_CHECK(glGenFramebuffers(1, &fbo) ); + + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, fbo) ); + + GL_CHECK(glFramebufferTexture2D(GL_FRAMEBUFFER + , GL_COLOR_ATTACHMENT0 + , GL_TEXTURE_2D + , src.m_id + , bi.m_srcMip ) ); + + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + BX_ASSERT(GL_FRAMEBUFFER_COMPLETE == status, "glCheckFramebufferStatus failed 0x%08x", status); + BX_UNUSED(status); + + GL_CHECK(glActiveTexture(GL_TEXTURE0) ); + GL_CHECK(glBindTexture(GL_TEXTURE_2D, dst.m_id) ); + + GL_CHECK(glCopyTexSubImage2D(GL_TEXTURE_2D + , bi.m_dstMip + , bi.m_dstX + , bi.m_dstY + , bi.m_srcX + , bi.m_srcY + , bi.m_width + , bi.m_height + ) ); + + GL_CHECK(glDeleteFramebuffers(1, &fbo) ); + GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_currentFbo) ); } } } @@ -6292,6 +7459,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); renderDocTriggerCapture(); } + m_glctx.makeCurrent(NULL); + + BGFX_GL_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorView); + if (1 < m_numWindows && m_vaoSupport) { @@ -6301,8 +7472,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_vao = 0; } - m_glctx.makeCurrent(NULL); - const GLuint defaultVao = m_vao; if (0 != defaultVao) { @@ -6322,17 +7491,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (m_timerQuerySupport && !BX_ENABLED(BX_PLATFORM_OSX) ) { - frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS); + frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS, _render->m_frameNum); } if (0 < _render->m_iboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource); TransientIndexBuffer* ib = _render->m_transientIb; m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true); } if (0 < _render->m_vboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource); TransientVertexBuffer* vb = _render->m_transientVb; m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true); } @@ -6347,12 +7518,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); RenderBind currentBind; currentBind.clear(); - const bool hmdEnabled = false; static ViewState viewState; - viewState.reset(_render, hmdEnabled); + viewState.reset(_render); - uint16_t programIdx = kInvalidHandle; - uint16_t boundProgramIdx = kInvalidHandle; + ProgramHandle currentProgram = BGFX_INVALID_HANDLE; + ProgramHandle boundProgram = BGFX_INVALID_HANDLE; SortKey key; uint16_t view = UINT16_MAX; FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS }; @@ -6406,18 +7576,14 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_occlusionQuery.resolve(_render); } - uint8_t eye = 0; - if (0 == (_render->m_debug&BGFX_DEBUG_IFH) ) { GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_msaaBackBufferFbo) ); - bool viewRestart = false; - uint8_t restartState = 0; viewState.m_rect = _render->m_view[0].m_rect; - int32_t numItems = _render->m_numRenderItems; - for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;) + + for (int32_t item = 0; item < numItems;) { const uint64_t encodedKey = _render->m_sortKeys[item]; const bool isCompute = key.decode(encodedKey, _render->m_viewRemap); @@ -6435,17 +7601,15 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); if (viewChanged) { - if (1 == restartState) + view = key.m_view; + currentProgram = BGFX_INVALID_HANDLE; + + if (item > 1) { - restartState = 2; - item = restartItem; - restartItem = numItems; - view = UINT16_MAX; - continue; + profiler.end(); } - view = key.m_view; - programIdx = kInvalidHandle; + BGFX_GL_PROFILER_END(); if (_render->m_view[view].m_fbh.idx != fbh.idx) { @@ -6454,55 +7618,12 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); resolutionHeight = setFrameBuffer(fbh, resolutionHeight, discardFlags); } - viewRestart = ( (BGFX_VIEW_STEREO == (_render->m_view[view].m_flags & BGFX_VIEW_STEREO) ) ); - viewRestart &= hmdEnabled; - if (viewRestart) - { - if (0 == restartState) - { - restartState = 1; - restartItem = item - 1; - } - - eye = (restartState - 1) & 1; - restartState &= 1; - } - else - { - eye = 0; - } - - if (item > 1) - { - profiler.end(); - } + setViewType(view, " "); + BGFX_GL_PROFILER_BEGIN(view, kColorView); profiler.begin(view); viewState.m_rect = _render->m_view[view].m_rect; - if (viewRestart) - { - 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 - { - 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_view[view].m_scissor; viewHasScissor = !scissorRect.isZero(); @@ -6537,20 +7658,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { wasCompute = true; - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - char* viewName = s_viewName[view]; - viewName[3] = 'C'; - GL_CHECK(glInsertEventMarker(0, viewName) ); - } + setViewType(view, "C"); + BGFX_GL_PROFILER_END(); + BGFX_GL_PROFILER_BEGIN(view, kColorCompute); } if (computeSupported) { const RenderCompute& compute = renderItem.compute; - ProgramGL& program = m_program[key.m_program]; - GL_CHECK(glUseProgram(program.m_id) ); + ProgramGL& program = m_program[key.m_program.idx]; + setProgram(program.m_id); GLbitfield barrier = 0; for (uint32_t ii = 0; ii < maxComputeBindings; ++ii) @@ -6569,24 +7687,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); case Binding::Image: { - if (Access::Read == bind.m_access) - { - TextureGL& texture = m_textures[bind.m_idx]; - texture.commit(ii, uint32_t(texture.m_flags), _render->m_colorPalette); - } - else - { - const TextureGL& texture = m_textures[bind.m_idx]; - GL_CHECK(glBindImageTexture(ii - , texture.m_id - , bind.m_mip - , texture.isCubeMap() ? GL_TRUE : GL_FALSE - , 0 - , s_access[bind.m_access] - , s_imageFormat[bind.m_format]) - ); - barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT; - } + const TextureGL& texture = m_textures[bind.m_idx]; + GL_CHECK(glBindImageTexture(ii + , texture.m_id + , bind.m_mip + , texture.isCubeMap() || texture.m_target == GL_TEXTURE_2D_ARRAY ? GL_TRUE : GL_FALSE + , 0 + , s_access[bind.m_access] + , s_imageFormat[bind.m_format]) + ); + barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT; } break; @@ -6620,10 +7730,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); commit(*program.m_constantBuffer); } - viewState.setPredefined<1>(this, view, eye, program, _render, compute); + viewState.setPredefined<1>(this, view, program, _render, compute); if (isValid(compute.m_indirectBuffer) ) { + barrier |= GL_COMMAND_BARRIER_BIT; const VertexBufferGL& vb = m_vertexBuffers[compute.m_indirectBuffer.idx]; if (currentState.m_indirectBuffer.idx != compute.m_indirectBuffer.idx) { @@ -6667,12 +7778,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { wasCompute = false; - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - char* viewName = s_viewName[view]; - viewName[3] = ' '; - GL_CHECK(glInsertEventMarker(0, viewName) ); - } + setViewType(view, " "); + BGFX_GL_PROFILER_END(); + BGFX_GL_PROFILER_BEGIN(view, kColorDraw); } const RenderDraw& draw = renderItem.draw; @@ -6799,22 +7907,31 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } - if ( (0 + if ( ( (0 + | BGFX_STATE_ALPHA_REF_MASK + | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE + | BGFX_STATE_BLEND_EQUATION_MASK + | BGFX_STATE_BLEND_INDEPENDENT + | BGFX_STATE_BLEND_MASK + | BGFX_STATE_CONSERVATIVE_RASTER | BGFX_STATE_CULL_MASK - | BGFX_STATE_WRITE_Z + | BGFX_STATE_FRONT_CCW | BGFX_STATE_DEPTH_TEST_MASK - | BGFX_STATE_WRITE_RGB - | BGFX_STATE_WRITE_A - | BGFX_STATE_BLEND_MASK - | BGFX_STATE_BLEND_EQUATION_MASK - | BGFX_STATE_ALPHA_REF_MASK - | BGFX_STATE_PT_MASK - | BGFX_STATE_POINT_SIZE_MASK - | BGFX_STATE_MSAA | BGFX_STATE_LINEAA - | BGFX_STATE_CONSERVATIVE_RASTER + | BGFX_STATE_MSAA + | BGFX_STATE_POINT_SIZE_MASK + | BGFX_STATE_PT_MASK + | BGFX_STATE_WRITE_A + | BGFX_STATE_WRITE_RGB + | BGFX_STATE_WRITE_Z ) & changedFlags) + || blendFactor != draw.m_rgba) { + if (BGFX_STATE_FRONT_CCW & changedFlags) + { + GL_CHECK(glFrontFace( (BGFX_STATE_FRONT_CCW & newFlags) ? GL_CCW : GL_CW) ); + } + if (BGFX_STATE_CULL_MASK & changedFlags) { if (BGFX_STATE_CULL_CCW & newFlags) @@ -6911,10 +8028,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } if ( ( (0 - | BGFX_STATE_BLEND_MASK + | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE | BGFX_STATE_BLEND_EQUATION_MASK | BGFX_STATE_BLEND_INDEPENDENT - | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE + | BGFX_STATE_BLEND_MASK ) & changedFlags) || blendFactor != draw.m_rgba) { @@ -6931,9 +8048,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } if ( ( (0 - | BGFX_STATE_BLEND_MASK | BGFX_STATE_BLEND_EQUATION_MASK - | BGFX_STATE_BLEND_INDEPENDENT) & newFlags) + | BGFX_STATE_BLEND_INDEPENDENT + | BGFX_STATE_BLEND_MASK + ) & newFlags) || blendFactor != draw.m_rgba) { const bool enabled = !!(BGFX_STATE_BLEND_MASK & newFlags); @@ -7041,23 +8159,23 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); bool bindAttribs = false; rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); - if (key.m_program != programIdx) + if (key.m_program.idx != currentProgram.idx) { - programIdx = key.m_program; - GLuint id = kInvalidHandle == programIdx ? 0 : m_program[programIdx].m_id; + currentProgram = key.m_program; + GLuint id = isValid(currentProgram) ? m_program[currentProgram.idx].m_id : 0; // Skip rendering if program index is valid, but program is invalid. - programIdx = 0 == id ? kInvalidHandle : programIdx; + currentProgram = 0 == id ? ProgramHandle{kInvalidHandle} : currentProgram; - GL_CHECK(glUseProgram(id) ); + setProgram(id); programChanged = constantsChanged = bindAttribs = true; } - if (kInvalidHandle != programIdx) + if (isValid(currentProgram) ) { - ProgramGL& program = m_program[programIdx]; + ProgramGL& program = m_program[currentProgram.idx]; if (constantsChanged && NULL != program.m_constantBuffer) @@ -7065,9 +8183,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); commit(*program.m_constantBuffer); } - viewState.setPredefined<1>(this, view, eye, program, _render, draw); + viewState.setPredefined<1>(this, view, program, _render, draw); { + GLbitfield barrier = 0; for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) { const Binding& bind = renderBind.m_bind[stage]; @@ -7081,6 +8200,21 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { switch (bind.m_type) { + case Binding::Image: + { + const TextureGL& texture = m_textures[bind.m_idx]; + GL_CHECK(glBindImageTexture(stage + , texture.m_id + , bind.m_mip + , texture.isCubeMap() || texture.m_target == GL_TEXTURE_2D_ARRAY ? GL_TRUE : GL_FALSE + , 0 + , s_access[bind.m_access] + , s_imageFormat[bind.m_format]) + ); + barrier |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT; + } + break; + case Binding::Texture: { TextureGL& texture = m_textures[bind.m_idx]; @@ -7107,22 +8241,33 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); current = bind; } + + if (0 != barrier) + { + GL_CHECK(glMemoryBarrier(barrier) ); + } } { - bool diffStreamHandles = false; - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ; streamMask >>= 1, idx += 1 ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; if (currentState.m_stream[idx].m_handle.idx != draw.m_stream[idx].m_handle.idx) { - diffStreamHandles = true; - break; + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; + bindAttribs = true; + } + + if (currentState.m_stream[idx].m_startVertex != draw.m_stream[idx].m_startVertex) + { + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + bindAttribs = true; } } @@ -7130,24 +8275,12 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); || currentState.m_streamMask != draw.m_streamMask || currentState.m_instanceDataBuffer.idx != draw.m_instanceDataBuffer.idx || currentState.m_instanceDataOffset != draw.m_instanceDataOffset - || currentState.m_instanceDataStride != draw.m_instanceDataStride - || diffStreamHandles) + || currentState.m_instanceDataStride != draw.m_instanceDataStride) { - currentState.m_streamMask = draw.m_streamMask; - currentState.m_instanceDataBuffer.idx = draw.m_instanceDataBuffer.idx; - currentState.m_instanceDataOffset = draw.m_instanceDataOffset; - currentState.m_instanceDataStride = draw.m_instanceDataStride; - - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) - ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) - ) - { - streamMask >>= ntz; - idx += ntz; - - currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; - } + currentState.m_streamMask = draw.m_streamMask; + currentState.m_instanceDataBuffer = draw.m_instanceDataBuffer; + currentState.m_instanceDataOffset = draw.m_instanceDataOffset; + currentState.m_instanceDataStride = draw.m_instanceDataStride; bindAttribs = true; } @@ -7156,10 +8289,9 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { currentState.m_indexBuffer = draw.m_indexBuffer; - uint16_t handle = draw.m_indexBuffer.idx; - if (kInvalidHandle != handle) + if (isValid(draw.m_indexBuffer) ) { - IndexBufferGL& ib = m_indexBuffers[handle]; + IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx]; GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib.m_id) ); } else @@ -7168,62 +8300,52 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } - if (0 != currentState.m_streamMask) + if (currentState.m_startIndex != draw.m_startIndex) { - bool diffStartVertex = false; - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) - ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) - ) - { - streamMask >>= ntz; - idx += ntz; - - if (currentState.m_stream[idx].m_startVertex != draw.m_stream[idx].m_startVertex) - { - diffStartVertex = true; - break; - } - } + currentState.m_startIndex = draw.m_startIndex; + } - if (bindAttribs || diffStartVertex) + if (0 != currentState.m_streamMask) + { + if (bindAttribs) { - if(kInvalidHandle != boundProgramIdx) + if (isValid(boundProgram) ) { - ProgramGL& boundProgram = m_program[boundProgramIdx]; - boundProgram.unbindAttributes(); + m_program[boundProgram.idx].unbindAttributes(); + m_program[boundProgram.idx].unbindInstanceData(); } - boundProgramIdx = programIdx; + boundProgram = currentProgram; program.bindAttributesBegin(); if (UINT8_MAX != draw.m_streamMask) { - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ; streamMask >>= 1, idx += 1 ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; - currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; - const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx]; - uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; + const uint16_t decl = isValid(draw.m_stream[idx].m_layoutHandle) + ? draw.m_stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx; GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, vb.m_id) ); - program.bindAttributes(m_vertexDecls[decl], draw.m_stream[idx].m_startVertex); + program.bindAttributes(m_vertexLayouts[decl], draw.m_stream[idx].m_startVertex); } } - program.bindAttributesEnd(); - if (isValid(draw.m_instanceDataBuffer) ) { GL_CHECK(glBindBuffer(GL_ARRAY_BUFFER, m_vertexBuffers[draw.m_instanceDataBuffer.idx].m_id) ); program.bindInstanceData(draw.m_instanceDataStride, draw.m_instanceDataOffset); } + + program.bindAttributesEnd(); } } } @@ -7233,19 +8355,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); uint32_t numVertices = draw.m_numVertices; if (UINT32_MAX == numVertices) { - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask) + ; streamMask >>= 1, idx += 1 ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; const VertexBufferGL& vb = m_vertexBuffers[draw.m_stream[idx].m_handle.idx]; - uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = m_vertexDecls[decl]; + uint16_t decl = !isValid(vb.m_layoutHandle) ? draw.m_stream[idx].m_layoutHandle.idx : vb.m_layoutHandle.idx; + const VertexLayout& layout = m_vertexLayouts[decl]; - numVertices = bx::uint32_min(numVertices, vb.m_size/vertexDecl.m_stride); + numVertices = bx::uint32_min(numVertices, vb.m_size/layout.m_stride); } } @@ -7269,6 +8392,19 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); GL_CHECK(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, vb.m_id) ); } + uint32_t numOffsetIndirect = 0; + if (isValid(draw.m_numIndirectBuffer) ) + { + if (currentState.m_numIndirectBuffer.idx != draw.m_numIndirectBuffer.idx) + { + const IndexBufferGL& nb = m_indexBuffers[draw.m_numIndirectBuffer.idx]; + currentState.m_numIndirectBuffer = draw.m_numIndirectBuffer; + GL_CHECK(glBindBuffer(GL_PARAMETER_BUFFER_ARB, nb.m_id) ); + } + + numOffsetIndirect = draw.m_numIndirectIndex * sizeof(uint32_t); + } + if (isValid(draw.m_indexBuffer) ) { const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx]; @@ -7284,11 +8420,24 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ; uintptr_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; - GL_CHECK(glMultiDrawElementsIndirect(prim.m_type, indexFormat - , (void*)args - , numDrawIndirect - , BGFX_CONFIG_DRAW_INDIRECT_STRIDE - ) ); + + if (isValid(draw.m_numIndirectBuffer) ) + { + GL_CHECK(glMultiDrawElementsIndirectCount(prim.m_type, indexFormat + , (void*)args + , numOffsetIndirect + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ) ); + } + else + { + GL_CHECK(glMultiDrawElementsIndirect(prim.m_type, indexFormat + , (void*)args + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ) ); + } } else { @@ -7298,11 +8447,24 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ; uintptr_t args = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; - GL_CHECK(glMultiDrawArraysIndirect(prim.m_type - , (void*)args - , numDrawIndirect - , BGFX_CONFIG_DRAW_INDIRECT_STRIDE - ) ); + + if (isValid(draw.m_numIndirectBuffer) ) + { + GL_CHECK(glMultiDrawArraysIndirectCount(prim.m_type + , (void*)args + , numOffsetIndirect + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ) ); + } + else + { + GL_CHECK(glMultiDrawArraysIndirect(prim.m_type + , (void*)args + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ) ); + } } } else @@ -7311,14 +8473,20 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); { currentState.m_indirectBuffer.idx = kInvalidHandle; GL_CHECK(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0) ); + + if (isValid(currentState.m_numIndirectBuffer) ) + { + currentState.m_numIndirectBuffer.idx = kInvalidHandle; + GL_CHECK(glBindBuffer(GL_PARAMETER_BUFFER_ARB, 0) ); + } } if (isValid(draw.m_indexBuffer) ) { - const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx]; - const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32); - const uint32_t indexSize = hasIndex16 ? 2 : 4; - const GLenum indexFormat = hasIndex16 + const IndexBufferGL& ib = m_indexBuffers[draw.m_indexBuffer.idx]; + const bool isIndex16 = draw.isIndex16(); + const uint32_t indexSize = isIndex16 ? 2 : 4; + const GLenum indexFormat = isIndex16 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT ; @@ -7339,10 +8507,10 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } else if (prim.m_min <= draw.m_numIndices) { - numIndices = draw.m_numIndices; + numIndices = draw.m_numIndices; numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; GL_CHECK(glDrawElementsInstanced(prim.m_type , numIndices @@ -7355,8 +8523,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); else { numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub; - numInstances = draw.m_numInstances; - numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; GL_CHECK(glDrawArraysInstanced(prim.m_type , 0 @@ -7371,11 +8539,6 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); m_occlusionQuery.end(); } - if(isValid(draw.m_instanceDataBuffer)) - { - program.unbindInstanceData(); - } - statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted; statsNumPrimsRendered[primIndex] += numPrimsRendered; statsNumInstances[primIndex] += numInstances; @@ -7384,10 +8547,17 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } - if(kInvalidHandle != boundProgramIdx) + if (isValid(boundProgram) ) + { + m_program[boundProgram.idx].unbindAttributes(); + boundProgram = BGFX_INVALID_HANDLE; + } + + if (wasCompute) { - ProgramGL& boundProgram = m_program[boundProgramIdx]; - boundProgram.unbindAttributes(); + setViewType(view, "C"); + BGFX_GL_PROFILER_END(); + BGFX_GL_PROFILER_BEGIN(view, kColorCompute); } submitBlit(bs, BGFX_CONFIG_MAX_VIEWS); @@ -7414,6 +8584,8 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } } + BGFX_GL_PROFILER_END(); + m_glctx.makeCurrent(NULL); int64_t timeEnd = bx::getHPCounter(); int64_t frameTime = timeEnd - timeBegin; @@ -7453,12 +8625,15 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); perfStats.numCompute = statsKeyType[1]; perfStats.numBlit = _render->m_numBlitItems; perfStats.maxGpuLatency = maxGpuLatency; + perfStats.gpuFrameNum = result.m_frameNum; bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) ); perfStats.gpuMemoryMax = -INT64_MAX; perfStats.gpuMemoryUsed = -INT64_MAX; if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) { + BGFX_GL_PROFILER_BEGIN_LITERAL("debugstats", kColorFrame); + m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; @@ -7473,9 +8648,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); tvm.clear(); uint16_t pos = 0; tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f - , " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " + , " %s / " BX_COMPILER_NAME + " / " BX_CPU_NAME + " / " BX_ARCH_NAME + " / " BX_PLATFORM_NAME + " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")" , getRendererName() + , BGFX_API_VERSION + , BGFX_REV_NUMBER ); + tvm.printf(0, pos++, 0x8f, " Vendor: %s ", m_vendor); tvm.printf(0, pos++, 0x8f, " Renderer: %s ", m_renderer); tvm.printf(0, pos++, 0x8f, " Version: %s ", m_version); @@ -7627,10 +8809,16 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); } blit(this, _textVideoMemBlitter, tvm); + + BGFX_GL_PROFILER_END(); } else if (_render->m_debug & BGFX_DEBUG_TEXT) { + BGFX_GL_PROFILER_BEGIN_LITERAL("debugtext", kColorFrame); + blit(this, _textVideoMemBlitter, _render->m_textVideoMem); + + BGFX_GL_PROFILER_END(); } } } } // namespace bgfx diff --git a/3rdparty/bgfx/src/renderer_gl.h b/3rdparty/bgfx/src/renderer_gl.h index bccee98fe48..6d0346f3f8b 100644 --- a/3rdparty/bgfx/src/renderer_gl.h +++ b/3rdparty/bgfx/src/renderer_gl.h @@ -1,34 +1,63 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_GL_H_HEADER_GUARD #define BGFX_RENDERER_GL_H_HEADER_GUARD -#define BGFX_USE_EGL (BGFX_CONFIG_RENDERER_OPENGLES && (0 \ - || BX_PLATFORM_ANDROID \ - || BX_PLATFORM_BSD \ - || BX_PLATFORM_EMSCRIPTEN \ - || BX_PLATFORM_LINUX \ - || BX_PLATFORM_NX \ - || BX_PLATFORM_RPI \ - || BX_PLATFORM_STEAMLINK \ - || BX_PLATFORM_WINDOWS \ - ) ) - -#define BGFX_USE_WGL (BGFX_CONFIG_RENDERER_OPENGL && BX_PLATFORM_WINDOWS) -#define BGFX_USE_GLX (BGFX_CONFIG_RENDERER_OPENGL && (0 \ - || BX_PLATFORM_BSD \ - || BX_PLATFORM_LINUX \ - ) ) +#define BGFX_USE_EGL ( (BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES) && (0 \ + || BX_PLATFORM_ANDROID \ + || BX_PLATFORM_BSD \ + || BX_PLATFORM_LINUX \ + || BX_PLATFORM_NX \ + || BX_PLATFORM_RPI \ + ) ) + +#define BGFX_USE_HTML5 (BGFX_CONFIG_RENDERER_OPENGLES && (0 \ + || BX_PLATFORM_EMSCRIPTEN \ + ) ) + +#define BGFX_USE_WGL (BGFX_CONFIG_RENDERER_OPENGL && (0 \ + || BX_PLATFORM_WINDOWS \ + ) ) #define BGFX_USE_GL_DYNAMIC_LIB (0 \ - || BX_PLATFORM_BSD \ - || BX_PLATFORM_LINUX \ - || BX_PLATFORM_OSX \ - || BX_PLATFORM_WINDOWS \ - ) + || BX_PLATFORM_BSD \ + || BX_PLATFORM_LINUX \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_WINDOWS \ + ) + +// Keep a state cache of GL uniform values to avoid redundant uploads +// on the following platforms. +#define BGFX_GL_CONFIG_UNIFORM_CACHE BX_PLATFORM_EMSCRIPTEN + +#ifndef BGFX_GL_CONFIG_BLIT_EMULATION +# define BGFX_GL_CONFIG_BLIT_EMULATION 0 +#endif // BGFX_GL_CONFIG_BLIT_EMULATION + +#ifndef BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION +# define BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION 0 +#endif // BGFX_GL_CONFIG_TEXTURE_READ_BACK_EMULATION + +#define BGFX_GL_PROFILER_BEGIN(_view, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + GL_CHECK(glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, s_viewName[view]) ); \ + BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_GL_PROFILER_BEGIN_LITERAL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + GL_CHECK(glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, -1, "" _name) ); \ + BGFX_PROFILER_BEGIN_LITERAL("" _name, _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_GL_PROFILER_END() \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_END(); \ + GL_CHECK(glPopDebugGroup() ); \ + BX_MACRO_BLOCK_END #if BGFX_CONFIG_RENDERER_OPENGL # if BGFX_CONFIG_RENDERER_OPENGL >= 31 @@ -52,6 +81,12 @@ # undef GL_VERSION_1_4 # undef GL_VERSION_1_5 # undef GL_VERSION_2_0 +# elif BX_PLATFORM_WINDOWS +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif // WIN32_LEAN_AND_MEAN +# include <windows.h> +# include <GL/gl.h> # else # include <GL/gl.h> # endif // BX_PLATFORM_ @@ -103,22 +138,20 @@ typedef uint64_t GLuint64; # include <GLES3/gl3ext.h> # endif // BGFX_CONFIG_RENDERER_ -# if BGFX_USE_EGL -# include "glcontext_egl.h" -# endif // BGFX_USE_EGL - -# if BX_PLATFORM_EMSCRIPTEN -# include <emscripten/emscripten.h> -# endif // BX_PLATFORM_EMSCRIPTEN #endif // BGFX_CONFIG_RENDERER_OPENGL #include "renderer.h" #include "debug_renderdoc.h" +#include "emscripten.h" #ifndef GL_LUMINANCE # define GL_LUMINANCE 0x1909 #endif // GL_LUMINANCE +#ifndef GL_BGR +# define GL_BGR 0x80E0 +#endif // GL_BGR + #ifndef GL_BGRA # define GL_BGRA 0x80E1 #endif // GL_BGRA @@ -315,6 +348,10 @@ typedef uint64_t GLuint64; # define GL_BLUE 0x1905 #endif // GL_BLUE +#ifndef GL_RGB_INTEGER +# define GL_RGB_INTEGER 0x8D98 +#endif // GL_RGB_INTEGER + #ifndef GL_RGBA_INTEGER # define GL_RGBA_INTEGER 0x8D99 #endif // GL_RGBA_INTEGER @@ -457,63 +494,127 @@ typedef uint64_t GLuint64; #ifndef ATC_RGB_AMD #define GL_ATC_RGB_AMD 0x8C92 -#endif +#endif // ATC_RGB_AMD #ifndef GL_ATC_RGBA_EXPLICIT_ALPHA_AMD # define GL_ATC_RGBA_EXPLICIT_ALPHA_AMD 0x8C93 -#endif +#endif // GL_ATC_RGBA_EXPLICIT_ALPHA_AMD #ifndef ATC_RGBA_INTERPOLATED_ALPHA_AMD # define GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD 0x87EE -#endif +#endif // ATC_RGBA_INTERPOLATED_ALPHA_AMD #ifndef GL_COMPRESSED_RGBA_ASTC_4x4_KHR # define GL_COMPRESSED_RGBA_ASTC_4x4_KHR 0x93B0 -#endif +#endif // GL_COMPRESSED_RGBA_ASTC_4x4_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_5x4_KHR +# define GL_COMPRESSED_RGBA_ASTC_5x4_KHR 0x93B1 +#endif // GL_COMPRESSED_RGBA_ASTC_5x4_KHR #ifndef GL_COMPRESSED_RGBA_ASTC_5x5_KHR # define GL_COMPRESSED_RGBA_ASTC_5x5_KHR 0x93B2 -#endif +#endif // GL_COMPRESSED_RGBA_ASTC_5x5_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_6x5_KHR +# define GL_COMPRESSED_RGBA_ASTC_6x5_KHR 0x93B3 +#endif // GL_COMPRESSED_RGBA_ASTC_6x5_KHR #ifndef GL_COMPRESSED_RGBA_ASTC_6x6_KHR # define GL_COMPRESSED_RGBA_ASTC_6x6_KHR 0x93B4 -#endif +#endif // GL_COMPRESSED_RGBA_ASTC_6x6_KHR #ifndef GL_COMPRESSED_RGBA_ASTC_8x5_KHR # define GL_COMPRESSED_RGBA_ASTC_8x5_KHR 0x93B5 -#endif +#endif // GL_COMPRESSED_RGBA_ASTC_8x5_KHR #ifndef GL_COMPRESSED_RGBA_ASTC_8x6_KHR # define GL_COMPRESSED_RGBA_ASTC_8x6_KHR 0x93B6 -#endif +#endif // GL_COMPRESSED_RGBA_ASTC_8x6_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_8x8_KHR +# define GL_COMPRESSED_RGBA_ASTC_8x8_KHR 0x93B7 +#endif // GL_COMPRESSED_RGBA_ASTC_8x8_KHR #ifndef GL_COMPRESSED_RGBA_ASTC_10x5_KHR # define GL_COMPRESSED_RGBA_ASTC_10x5_KHR 0x93B8 -#endif +#endif // GL_COMPRESSED_RGBA_ASTC_10x5_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_10x6_KHR +# define GL_COMPRESSED_RGBA_ASTC_10x6_KHR 0x93B9 +#endif // GL_COMPRESSED_RGBA_ASTC_10x6_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_10x8_KHR +# define GL_COMPRESSED_RGBA_ASTC_10x8_KHR 0x93BA +#endif // GL_COMPRESSED_RGBA_ASTC_10x8_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_10x10_KHR +# define GL_COMPRESSED_RGBA_ASTC_10x10_KHR 0x93BB +#endif // GL_COMPRESSED_RGBA_ASTC_10x10_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_12x10_KHR +# define GL_COMPRESSED_RGBA_ASTC_12x10_KHR 0x93BC +#endif // GL_COMPRESSED_RGBA_ASTC_12x10_KHR + +#ifndef GL_COMPRESSED_RGBA_ASTC_12x12_KHR +# define GL_COMPRESSED_RGBA_ASTC_12x12_KHR 0x93BD +#endif // GL_COMPRESSED_RGBA_ASTC_12x12_KHR #ifndef GL_COMPRESSED_SRGB8_ASTC_4x4_KHR # define GL_COMPRESSED_SRGB8_ASTC_4x4_KHR 0x93D0 -#endif +#endif // GL_COMPRESSED_SRGB8_ASTC_4x4_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_5x4_KHR +# define GL_COMPRESSED_SRGB8_ASTC_5x4_KHR 0x93D1 +#endif // GL_COMPRESSED_SRGB8_ASTC_5x4_KHR #ifndef GL_COMPRESSED_SRGB8_ASTC_5x5_KHR # define GL_COMPRESSED_SRGB8_ASTC_5x5_KHR 0x93D2 -#endif +#endif // GL_COMPRESSED_SRGB8_ASTC_5x5_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_6x5_KHR +# define GL_COMPRESSED_SRGB8_ASTC_6x5_KHR 0x93D3 +#endif // GL_COMPRESSED_SRGB8_ASTC_6x5_KHR #ifndef GL_COMPRESSED_SRGB8_ASTC_6x6_KHR # define GL_COMPRESSED_SRGB8_ASTC_6x6_KHR 0x93D4 -#endif +#endif // GL_COMPRESSED_SRGB8_ASTC_6x6_KHR #ifndef GL_COMPRESSED_SRGB8_ASTC_8x5_KHR # define GL_COMPRESSED_SRGB8_ASTC_8x5_KHR 0x93D5 -#endif +#endif // GL_COMPRESSED_SRGB8_ASTC_8x5_KHR #ifndef GL_COMPRESSED_SRGB8_ASTC_8x6_KHR # define GL_COMPRESSED_SRGB8_ASTC_8x6_KHR 0x93D6 -#endif +#endif // GL_COMPRESSED_SRGB8_ASTC_8x6_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_8x8_KHR +# define GL_COMPRESSED_SRGB8_ASTC_8x8_KHR 0x93D7 +#endif // GL_COMPRESSED_SRGB8_ASTC_8x8_KHR #ifndef GL_COMPRESSED_SRGB8_ASTC_10x5_KHR # define GL_COMPRESSED_SRGB8_ASTC_10x5_KHR 0x93D8 -#endif +#endif // GL_COMPRESSED_SRGB8_ASTC_10x5_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_10x6_KHR +# define GL_COMPRESSED_SRGB8_ASTC_10x6_KHR 0x93D9 +#endif // GL_COMPRESSED_SRGB8_ASTC_10x6_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_10x8_KHR +# define GL_COMPRESSED_SRGB8_ASTC_10x8_KHR 0x93DA +#endif // GL_COMPRESSED_SRGB8_ASTC_10x8_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_10x10_KHR +# define GL_COMPRESSED_SRGB8_ASTC_10x10_KHR 0x93DB +#endif // GL_COMPRESSED_SRGB8_ASTC_10x10_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_12x10_KHR +# define GL_COMPRESSED_SRGB8_ASTC_12x10_KHR 0x93DC +#endif // GL_COMPRESSED_SRGB8_ASTC_12x10_KHR + +#ifndef GL_COMPRESSED_SRGB8_ASTC_12x12_KHR +# define GL_COMPRESSED_SRGB8_ASTC_12x12_KHR 0x93DD +#endif // GL_COMPRESSED_SRGB8_ASTC_12x12_KHR #ifndef GL_COMPRESSED_RGBA_BPTC_UNORM_ARB # define GL_COMPRESSED_RGBA_BPTC_UNORM_ARB 0x8E8C @@ -531,6 +632,14 @@ typedef uint64_t GLuint64; # define GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB 0x8E8F #endif // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB +#ifndef GL_SRGB_EXT +# define GL_SRGB_EXT 0x8C40 +#endif // GL_SRGB_EXT + +#ifndef GL_SRGB_ALPHA_EXT +# define GL_SRGB_ALPHA_EXT 0x8C42 +#endif // GL_SRGB_ALPHA_EXT + #ifndef GL_SRGB8_ALPHA8 # define GL_SRGB8_ALPHA8 0x8C43 #endif // GL_SRGB8_ALPHA8 @@ -575,6 +684,10 @@ typedef uint64_t GLuint64; # define GL_MAX_SAMPLES 0x8D57 #endif // GL_MAX_SAMPLES +#ifndef GL_MAX_SAMPLES_IMG +# define GL_MAX_SAMPLES_IMG 0x9135 +#endif // GL_MAX_SAMPLES_IMG + #ifndef GL_MAX_COLOR_ATTACHMENTS # define GL_MAX_COLOR_ATTACHMENTS 0x8CDF #endif // GL_MAX_COLOR_ATTACHMENTS @@ -587,6 +700,10 @@ typedef uint64_t GLuint64; # define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF #endif // GL_MAX_ARRAY_TEXTURE_LAYERS +#ifndef GL_MAX_LABEL_LENGTH +# define GL_MAX_LABEL_LENGTH 0x82E8 +#endif // GL_MAX_LABEL_LENGTH + #ifndef GL_QUERY_RESULT # define GL_QUERY_RESULT 0x8866 #endif // GL_QUERY_RESULT @@ -631,7 +748,7 @@ typedef uint64_t GLuint64; # define GL_RENDERBUFFER_FREE_MEMORY_ATI 0x87FD #endif // GL_RENDERBUFFER_FREE_MEMORY_ATI -// http://developer.download.nvidia.com/opengl/specs/GL_NVX_gpu_memory_info.txt +// https://web.archive.org/web/20190207230448/http://developer.download.nvidia.com/opengl/specs/GL_NVX_gpu_memory_info.txt #ifndef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX # define GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047 #endif // GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX @@ -916,6 +1033,22 @@ typedef uint64_t GLuint64; # define GL_TEXTURE 0x1702 #endif // GL_TEXTURE +#ifndef GL_BUFFER +# define GL_BUFFER 0x82E0 +#endif // GL_BUFFER + +#ifndef GL_COMMAND_BARRIER_BIT +# define GL_COMMAND_BARRIER_BIT 0x00000040 +#endif // GL_COMMAND_BARRIER_BIT + +#ifndef GL_FIRST_VERTEX_CONVENTION +# define GL_FIRST_VERTEX_CONVENTION 0x8E4D +#endif // GL_FIRST_VERTEX_CONVENTION + +#ifndef GL_PARAMETER_BUFFER_ARB +# define GL_PARAMETER_BUFFER_ARB 0x80EE +#endif // GL_PARAMETER_BUFFER_ARB + // _KHR or _ARB... #define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 #define GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH 0x8243 @@ -1015,20 +1148,18 @@ typedef uint64_t GLuint64; # define GL_TEXTURE_LOD_BIAS 0x8501 #endif // GL_TEXTURE_LOD_BIAS -#if BX_PLATFORM_WINDOWS -# include <windows.h> -#elif BX_PLATFORM_LINUX || BX_PLATFORM_BSD -# include "glcontext_glx.h" +#if BGFX_USE_EGL +# include "glcontext_egl.h" +#elif BGFX_USE_HTML5 +# include "glcontext_html5.h" +#elif BGFX_USE_WGL +# include "glcontext_wgl.h" #elif BX_PLATFORM_OSX # include "glcontext_nsgl.h" #elif BX_PLATFORM_IOS # include "glcontext_eagl.h" #endif // BX_PLATFORM_ -#if BGFX_USE_WGL -# include "glcontext_wgl.h" -#endif // BGFX_USE_WGL - #ifndef GL_APIENTRY # define GL_APIENTRY APIENTRY #endif // GL_APIENTRY @@ -1050,6 +1181,9 @@ namespace bgfx { namespace gl { void dumpExtensions(const char* _extensions); + void lazyEnableVertexAttribArray(GLuint index); + void lazyDisableVertexAttribArray(GLuint index); + const char* glEnumName(GLenum _enum); #define _GL_CHECK(_check, _call) \ @@ -1064,7 +1198,7 @@ namespace bgfx { namespace gl #define IGNORE_GL_ERROR_CHECK(...) BX_NOOP() #if BGFX_CONFIG_DEBUG -# define GL_CHECK(_call) _GL_CHECK(BX_CHECK, _call) +# define GL_CHECK(_call) _GL_CHECK(BX_ASSERT, _call) # define GL_CHECK_I(_call) _GL_CHECK(IGNORE_GL_ERROR_CHECK, _call) #else # define GL_CHECK(_call) _call @@ -1075,6 +1209,88 @@ namespace bgfx { namespace gl #define GL_IMPORT(_optional, _proto, _func, _import) extern _proto _func #include "glimports.h" + class UniformStateCache + { + public: + struct f4 { float val[ 4]; bool operator ==(const f4 &rhs) { const uint64_t *a = (const uint64_t *)this; const uint64_t *b = (const uint64_t *)&rhs; return a[0] == b[0] && a[1] == b[1]; }}; + struct f3x3 { float val[ 9]; bool operator ==(const f3x3 &rhs) { const uint64_t *a = (const uint64_t *)this; const uint64_t *b = (const uint64_t *)&rhs; return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && ((const uint32_t*)a)[8] == ((const uint32_t*)b)[8]; }}; + struct f4x4 { float val[16]; bool operator ==(const f4x4 &rhs) { const uint64_t *a = (const uint64_t *)this; const uint64_t *b = (const uint64_t *)&rhs; return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && a[4] == b[4] && a[5] == b[5] && a[6] == b[6] && a[7] == b[7]; }}; + + typedef stl::unordered_map<uint64_t, int> IMap; + typedef stl::unordered_map<uint64_t, f4> F4Map; + typedef stl::unordered_map<uint64_t, f3x3> F3x3Map; + typedef stl::unordered_map<uint64_t, f4x4> F4x4Map; + + UniformStateCache() + : m_currentProgram(0) + { + } + + // Inserts the new value into the uniform cache, and returns true + // if the old value was different than the new one. + template<typename T> + bool updateUniformCache(uint32_t loc, const T &value) + { + if (BX_ENABLED(BGFX_GL_CONFIG_UNIFORM_CACHE) ) + { + // Uniform state cache for various types. + stl::unordered_map<uint64_t, T>& uniformCacheMap = getUniformCache<T>(); + + uint64_t key = (uint64_t(m_currentProgram) << 32) | loc; + + auto iter = uniformCacheMap.find(key); + + // Not found in the cache? Add it. + if (iter == uniformCacheMap.end()) + { + uniformCacheMap[key] = value; + return true; + } + + // Value in the cache was the same as new state? Skip reuploading this state. + if (iter->second == value) + { + return false; + } + + iter->second = value; + } + + return true; + } + + void saveCurrentProgram(GLuint program) + { + if (BX_ENABLED(BGFX_GL_CONFIG_UNIFORM_CACHE) ) + { + m_currentProgram = program; + } + } + + private: + GLuint m_currentProgram; + + IMap m_uniformiCacheMap; + F4Map m_uniformf4CacheMap; + F3x3Map m_uniformf3x3CacheMap; + F4x4Map m_uniformf4x4CacheMap; + + template<typename T> + stl::unordered_map<uint64_t, T>& getUniformCache(); + }; + + template<> + inline UniformStateCache::IMap& UniformStateCache::getUniformCache() { return m_uniformiCacheMap; } + + template<> + inline UniformStateCache::F4Map& UniformStateCache::getUniformCache() { return m_uniformf4CacheMap; } + + template<> + inline UniformStateCache::F3x3Map& UniformStateCache::getUniformCache() { return m_uniformf3x3CacheMap; } + + template<> + inline UniformStateCache::F4x4Map& UniformStateCache::getUniformCache() { return m_uniformf4x4CacheMap; } + class SamplerStateCache { public: @@ -1138,7 +1354,7 @@ namespace bgfx { namespace gl m_flags = _flags; GL_CHECK(glGenBuffers(1, &m_id) ); - BX_CHECK(0 != m_id, "Failed to generate buffer id."); + BX_ASSERT(0 != m_id, "Failed to generate buffer id."); GL_CHECK(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id) ); GL_CHECK(glBufferData(GL_ELEMENT_ARRAY_BUFFER , _size @@ -1150,7 +1366,7 @@ namespace bgfx { namespace gl void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false) { - BX_CHECK(0 != m_id, "Updating invalid index buffer."); + BX_ASSERT(0 != m_id, "Updating invalid index buffer."); if (_discard) { @@ -1177,16 +1393,16 @@ namespace bgfx { namespace gl struct VertexBufferGL { - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags) + void create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags) { m_size = _size; - m_decl = _declHandle; + m_layoutHandle = _layoutHandle; const bool drawIndirect = 0 != (_flags & BGFX_BUFFER_DRAW_INDIRECT); m_target = drawIndirect ? GL_DRAW_INDIRECT_BUFFER : GL_ARRAY_BUFFER; GL_CHECK(glGenBuffers(1, &m_id) ); - BX_CHECK(0 != m_id, "Failed to generate buffer id."); + BX_ASSERT(0 != m_id, "Failed to generate buffer id."); GL_CHECK(glBindBuffer(m_target, m_id) ); GL_CHECK(glBufferData(m_target , _size @@ -1198,13 +1414,13 @@ namespace bgfx { namespace gl void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false) { - BX_CHECK(0 != m_id, "Updating invalid vertex buffer."); + BX_ASSERT(0 != m_id, "Updating invalid vertex buffer."); if (_discard) { // orphan buffer... destroy(); - create(m_size, NULL, m_decl, 0); + create(m_size, NULL, m_layoutHandle, 0); } GL_CHECK(glBindBuffer(m_target, m_id) ); @@ -1221,7 +1437,7 @@ namespace bgfx { namespace gl GLuint m_id; GLenum m_target; uint32_t m_size; - VertexDeclHandle m_decl; + VertexLayoutHandle m_layoutHandle; }; struct TextureGL @@ -1265,6 +1481,7 @@ namespace bgfx { namespace gl uint32_t m_width; uint32_t m_height; uint32_t m_depth; + uint32_t m_numLayers; uint8_t m_numMips; uint8_t m_requestedFormat; uint8_t m_textureFormat; @@ -1323,34 +1540,18 @@ namespace bgfx { namespace gl , m_constantBuffer(NULL) , m_numPredefined(0) { + m_instanceData[0] = -1; } void create(const ShaderGL& _vsh, const ShaderGL& _fsh); void destroy(); void init(); + + void bindAttributesBegin(); + void bindAttributes(const VertexLayout& _layout, uint32_t _baseVertex = 0); void bindInstanceData(uint32_t _stride, uint32_t _baseVertex = 0) const; + void bindAttributesEnd(); void unbindInstanceData() const; - - void bindAttributesBegin() - { - bx::memCopy(m_unboundUsedAttrib, m_used, sizeof(m_unboundUsedAttrib) ); - } - - void bindAttributes(const VertexDecl& _vertexDecl, uint32_t _baseVertex = 0); - - void bindAttributesEnd() - { - for (uint32_t ii = 0, iiEnd = m_usedCount; ii < iiEnd; ++ii) - { - if (Attrib::Count != m_unboundUsedAttrib[ii]) - { - Attrib::Enum attr = Attrib::Enum(m_unboundUsedAttrib[ii]); - GLint loc = m_attributes[attr]; - GL_CHECK(glDisableVertexAttribArray(loc) ); - } - } - } - void unbindAttributes(); GLuint m_id; @@ -1358,8 +1559,10 @@ namespace bgfx { namespace gl uint8_t m_unboundUsedAttrib[Attrib::Count]; // For tracking unbound used attributes between begin()/end(). uint8_t m_usedCount; uint8_t m_used[Attrib::Count]; // Dense. - GLint m_attributes[Attrib::Count]; // Sparse. - GLint m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT+1]; + GLint m_attributes[Attrib::Count]; // Sparse. + + GLint m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT+1]; + uint16_t m_instanceOffset[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; GLint m_sampler[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; uint8_t m_numSamplers; @@ -1382,6 +1585,7 @@ namespace bgfx { namespace gl { Query& query = m_query[ii]; query.m_ready = false; + query.m_frameNum = 0; GL_CHECK(glGenQueries(1, &query.m_begin) ); GL_CHECK(glGenQueries(1, &query.m_end) ); } @@ -1403,7 +1607,7 @@ namespace bgfx { namespace gl } } - uint32_t begin(uint32_t _resultIdx) + uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum) { while (0 == m_control.reserve(1) ) { @@ -1416,6 +1620,7 @@ namespace bgfx { namespace gl const uint32_t idx = m_control.m_current; Query& query = m_query[idx]; query.m_resultIdx = _resultIdx; + query.m_frameNum = _frameNum; query.m_ready = false; GL_CHECK(glQueryCounter(query.m_begin @@ -1464,6 +1669,7 @@ namespace bgfx { namespace gl Result& result = m_result[query.m_resultIdx]; --result.m_pending; + result.m_frameNum = query.m_frameNum; GL_CHECK(glGetQueryObjectui64v(query.m_begin , GL_QUERY_RESULT @@ -1486,14 +1692,16 @@ namespace bgfx { namespace gl { void reset() { - m_begin = 0; - m_end = 0; - m_pending = 0; + m_begin = 0; + m_end = 0; + m_pending = 0; + m_frameNum = 0; } uint64_t m_begin; uint64_t m_end; uint32_t m_pending; + uint32_t m_frameNum; }; struct Query @@ -1501,6 +1709,7 @@ namespace bgfx { namespace gl GLuint m_begin; GLuint m_end; uint32_t m_resultIdx; + uint32_t m_frameNum; bool m_ready; }; @@ -1534,52 +1743,6 @@ namespace bgfx { namespace gl bx::RingBufferControl m_control; }; - class LineReader : public bx::ReaderI - { - public: - LineReader(const void* _str) - : m_str( (const char*)_str) - , m_pos(0) - , m_size(bx::strLen( (const char*)_str) ) - { - } - - LineReader(const bx::StringView& _str) - : m_str(_str.getPtr() ) - , m_pos(0) - , m_size(_str.getLength() ) - { - } - - virtual int32_t read(void* _data, int32_t _size, bx::Error* _err) override - { - if (m_str[m_pos] == '\0' - || m_pos == m_size) - { - BX_ERROR_SET(_err, BX_ERROR_READERWRITER_EOF, "LineReader: EOF."); - return 0; - } - - uint32_t pos = m_pos; - const char* str = &m_str[pos]; - const char* nl = bx::strFindNl(str).getPtr(); - pos += (uint32_t)(nl - str); - - const char* eol = &m_str[pos]; - - uint32_t size = bx::uint32_min(uint32_t(eol - str), _size); - - bx::memCopy(_data, str, size); - m_pos += size; - - return size; - } - - const char* m_str; - uint32_t m_pos; - uint32_t m_size; - }; - } /* namespace gl */ } // namespace bgfx #endif // BGFX_RENDERER_GL_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/renderer_gnm.cpp b/3rdparty/bgfx/src/renderer_gnm.cpp index cb34386bc56..82f76593b11 100644 --- a/3rdparty/bgfx/src/renderer_gnm.cpp +++ b/3rdparty/bgfx/src/renderer_gnm.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -8,12 +8,12 @@ namespace bgfx { -#define BGFX_DECLARE_EMBEDDED_SHADER(_name) \ - extern const uint8_t* BX_CONCATENATE(_name, _pssl); \ - extern const uint32_t BX_CONCATENATE(_name, _pssl_size); \ - static const uint8_t BX_CONCATENATE(_name, _int_pssl)[] = { 0 }; \ - const uint8_t* BX_CONCATENATE(_name, _pssl) = &BX_CONCATENATE(_name, _int_pssl)[0]; \ - const uint32_t BX_CONCATENATE(_name, _pssl_size) = 1 +#define BGFX_DECLARE_EMBEDDED_SHADER(_name) \ + extern const uint8_t* BX_CONCATENATE(_name, _pssl); \ + extern const uint32_t BX_CONCATENATE(_name, _pssl_size); \ + static const uint8_t BX_CONCATENATE(_name, _int_pssl)[] = { 0 }; \ + const uint8_t* BX_CONCATENATE(_name, _pssl) = &BX_CONCATENATE(_name, _int_pssl)[0]; \ + const uint32_t BX_CONCATENATE(_name, _pssl_size) = 1 BGFX_DECLARE_EMBEDDED_SHADER(vs_debugfont); BGFX_DECLARE_EMBEDDED_SHADER(fs_debugfont); @@ -42,4 +42,5 @@ namespace bgfx { namespace gnm void rendererDestroy() { } + } /* namespace gnm */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/renderer_mtl.h b/3rdparty/bgfx/src/renderer_mtl.h index 95e038405dc..1ceba862ca3 100644 --- a/3rdparty/bgfx/src/renderer_mtl.h +++ b/3rdparty/bgfx/src/renderer_mtl.h @@ -1,6 +1,6 @@ /* * Copyright 2011-2015 Attila Kocsis, Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_METAL_H_HEADER_GUARD @@ -18,6 +18,21 @@ # import <UIKit/UIKit.h> #endif // BX_PLATFORM_* +#define BGFX_MTL_PROFILER_BEGIN(_view, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_MTL_PROFILER_BEGIN_LITERAL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_BEGIN_LITERAL("" _name, _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_MTL_PROFILER_END() \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_END(); \ + BX_MACRO_BLOCK_END + namespace bgfx { namespace mtl { //runtime os check @@ -52,8 +67,6 @@ namespace bgfx { namespace mtl // objects with creation functions starting with 'new' has a refcount 1 after creation, object must be destroyed with release. // commandBuffer, commandEncoders are autoreleased objects. Needs AutoreleasePool! -#define MTL_MAX_FRAMES_IN_FLIGHT (3) - #define MTL_CLASS(name) \ class name \ { \ @@ -64,7 +77,7 @@ namespace bgfx { namespace mtl #define MTL_CLASS_END }; - typedef void (*mtlCallback)(void* userData); + typedef void (*mtlCallback)(void* userData); MTL_CLASS(BlitCommandEncoder) void copyFromTexture( @@ -112,6 +125,11 @@ namespace bgfx { namespace mtl destinationSlice:_destinationSlice destinationLevel:_destinationLevel destinationOrigin:_destinationOrigin]; } + void generateMipmapsForTexture(id<MTLTexture> _texture) + { + [m_obj generateMipmapsForTexture:_texture]; + } + #if BX_PLATFORM_OSX void synchronizeTexture(id<MTLTexture> _texture, NSUInteger _slice, NSUInteger _level) { @@ -140,6 +158,11 @@ namespace bgfx { namespace mtl { return (uint32_t)m_obj.length; } + + void setLabel(const char* _label) + { + [m_obj setLabel:@(_label)]; + } MTL_CLASS_END MTL_CLASS(CommandBuffer) @@ -223,10 +246,31 @@ namespace bgfx { namespace mtl [m_obj setSamplerState:_sampler atIndex:_index]; } + void dispatchThreadgroups(MTLSize _threadgroupsPerGrid, MTLSize _threadsPerThreadgroup) + { + [m_obj dispatchThreadgroups:_threadgroupsPerGrid threadsPerThreadgroup:_threadsPerThreadgroup]; + } + + void dispatchThreadgroupsWithIndirectBuffer(id <MTLBuffer> _indirectBuffer, + NSUInteger _indirectBufferOffset, MTLSize _threadsPerThreadgroup) + { + [m_obj dispatchThreadgroupsWithIndirectBuffer:_indirectBuffer indirectBufferOffset:_indirectBufferOffset threadsPerThreadgroup:_threadsPerThreadgroup]; + } + void endEncoding() { [m_obj endEncoding]; } + + void pushDebugGroup(const char* _string) + { + [m_obj pushDebugGroup:@(_string)]; + } + + void popDebugGroup() + { + [m_obj popDebugGroup]; + } MTL_CLASS_END MTL_CLASS(Device) @@ -322,10 +366,14 @@ namespace bgfx { namespace mtl } // Creating Command Objects Needed to Perform Computational Tasks - id <MTLComputePipelineState> newComputePipelineStateWithFunction(id <MTLFunction> _computeFunction) + id <MTLComputePipelineState> newComputePipelineStateWithFunction( + id <MTLFunction> _computeFunction + , MTLPipelineOption _options + , MTLComputePipelineReflection** _reflection + ) { NSError* error; - id <MTLComputePipelineState> state = [m_obj newComputePipelineStateWithFunction:_computeFunction error:&error]; + id <MTLComputePipelineState> state = [m_obj newComputePipelineStateWithFunction:_computeFunction options:_options reflection:_reflection error:&error]; BX_WARN(NULL == error , "newComputePipelineStateWithFunction failed: %s" @@ -487,6 +535,25 @@ namespace bgfx { namespace mtl [m_obj drawPrimitives:_primitiveType vertexStart:_vertexStart vertexCount:_vertexCount instanceCount:_instanceCount]; } + void drawPrimitives( + MTLPrimitiveType _primitiveType + , id <MTLBuffer> _indirectBuffer + , NSUInteger _indirectBufferOffset) + { + [m_obj drawPrimitives:_primitiveType indirectBuffer:_indirectBuffer indirectBufferOffset:_indirectBufferOffset]; + } + + void drawIndexedPrimitives( + MTLPrimitiveType _primitiveType + , MTLIndexType _indexType + , id <MTLBuffer> _indexBuffer + , NSUInteger _indexBufferOffset + , id <MTLBuffer> _indirectBuffer + , NSUInteger _indirectBufferOffset) + { + [m_obj drawIndexedPrimitives:_primitiveType indexType:_indexType indexBuffer:_indexBuffer indexBufferOffset:_indexBufferOffset indirectBuffer:_indirectBuffer indirectBufferOffset:_indirectBufferOffset]; + } + void insertDebugSignpost(const char* _string) { [m_obj insertDebugSignpost:@(_string)]; @@ -527,6 +594,11 @@ namespace bgfx { namespace mtl return [m_obj newTextureViewWithPixelFormat:_pixelFormat]; } + id<MTLTexture> newTextureViewWithPixelFormat(MTLPixelFormat _pixelFormat, MTLTextureType _textureType, NSRange _levelRange, NSRange _sliceRange) + { + return [m_obj newTextureViewWithPixelFormat:_pixelFormat textureType:_textureType levels:_levelRange slices:_sliceRange]; + } + //properties uint32_t width() const { @@ -538,6 +610,11 @@ namespace bgfx { namespace mtl return (uint32_t)m_obj.height; } + uint32_t arrayLength() const + { + return (uint32_t)m_obj.arrayLength; + } + MTLPixelFormat pixelFormat() const { return m_obj.pixelFormat; @@ -567,6 +644,7 @@ namespace bgfx { namespace mtl //descriptors //NOTE: [class new] is same as [[class alloc] init] typedef MTLRenderPipelineDescriptor* RenderPipelineDescriptor; + typedef MTLComputePipelineReflection* ComputePipelineReflection; inline RenderPipelineDescriptor newRenderPipelineDescriptor() { @@ -683,7 +761,7 @@ namespace bgfx { namespace mtl typename HashMap::iterator it = m_hashMap.find(_id); if (it != m_hashMap.end() ) { - MTL_RELEASE(it->second); + release(it->second); m_hashMap.erase(it); } } @@ -712,13 +790,8 @@ namespace bgfx { namespace mtl { BufferMtl() : m_flags(BGFX_BUFFER_NONE) - , m_dynamic(false) - , m_bufferIndex(0) + , m_dynamic(NULL) { - for (uint32_t ii = 0; ii < MTL_MAX_FRAMES_IN_FLIGHT; ++ii) - { - m_buffers[ii] = NULL; - } } void create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride = 0, bool _vertex = false); @@ -726,23 +799,21 @@ namespace bgfx { namespace mtl void destroy() { - for (uint32_t ii = 0; ii < MTL_MAX_FRAMES_IN_FLIGHT; ++ii) + MTL_RELEASE(m_ptr); + + if (NULL != m_dynamic) { - MTL_RELEASE(m_buffers[ii]); + BX_DELETE(g_allocator, m_dynamic); + m_dynamic = NULL; } - - m_dynamic = false; } - Buffer getBuffer() const { return m_buffers[m_bufferIndex]; } - uint32_t m_size; uint16_t m_flags; + bool m_vertex; - bool m_dynamic; - private: - uint8_t m_bufferIndex; - Buffer m_buffers[MTL_MAX_FRAMES_IN_FLIGHT]; + Buffer m_ptr; + uint8_t* m_dynamic; }; typedef BufferMtl IndexBufferMtl; @@ -754,9 +825,9 @@ namespace bgfx { namespace mtl { } - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags); + void create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags); - VertexDeclHandle m_decl; + VertexLayoutHandle m_layoutHandle; }; @@ -776,22 +847,17 @@ namespace bgfx { namespace mtl Function m_function; uint32_t m_hash; + uint16_t m_numThreads[3]; }; + struct PipelineStateMtl; + struct ProgramMtl { ProgramMtl() : m_vsh(NULL) , m_fsh(NULL) - , m_vshConstantBuffer(NULL) - , m_fshConstantBuffer(NULL) - , m_vshConstantBufferSize(0) - , m_vshConstantBufferAlignmentMask(0) - , m_fshConstantBufferSize(0) - , m_fshConstantBufferAlignmentMask(0) - , m_samplerCount(0) - , m_numPredefined(0) - , m_processedUniforms(false) + , m_computePS(NULL) { } @@ -804,29 +870,77 @@ namespace bgfx { namespace mtl const ShaderMtl* m_vsh; const ShaderMtl* m_fsh; + + PipelineStateMtl* m_computePS; + }; + + struct PipelineStateMtl + { + PipelineStateMtl() + : m_vshConstantBuffer(NULL) + , m_fshConstantBuffer(NULL) + , m_vshConstantBufferSize(0) + , m_vshConstantBufferAlignment(0) + , m_fshConstantBufferSize(0) + , m_fshConstantBufferAlignment(0) + , m_numPredefined(0) + , m_rps(NULL) + , m_cps(NULL) + { + m_numThreads[0] = 1; + m_numThreads[1] = 1; + m_numThreads[2] = 1; + for(uint32_t i=0; i<BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++i) + m_bindingTypes[i] = 0; + } + + ~PipelineStateMtl() + { + if (NULL != m_vshConstantBuffer) + { + UniformBuffer::destroy(m_vshConstantBuffer); + m_vshConstantBuffer = NULL; + } + + if (NULL != m_fshConstantBuffer) + { + UniformBuffer::destroy(m_fshConstantBuffer); + m_fshConstantBuffer = NULL; + } + + release(m_rps); + release(m_cps); + } + UniformBuffer* m_vshConstantBuffer; UniformBuffer* m_fshConstantBuffer; uint32_t m_vshConstantBufferSize; - uint32_t m_vshConstantBufferAlignmentMask; + uint32_t m_vshConstantBufferAlignment; uint32_t m_fshConstantBufferSize; - uint32_t m_fshConstantBufferAlignmentMask; + uint32_t m_fshConstantBufferAlignment; - struct SamplerInfo + enum { - uint32_t m_index; - bgfx::UniformHandle m_uniform; - bool m_fragment; + BindToVertexShader = 1 << 0, + BindToFragmentShader = 1 << 1, }; + uint8_t m_bindingTypes[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; - SamplerInfo m_samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; - uint32_t m_samplerCount; + uint16_t m_numThreads[3]; PredefinedUniform m_predefined[PredefinedUniform::Count*2]; uint8_t m_numPredefined; - bool m_processedUniforms; + + RenderPipelineState m_rps; + ComputePipelineState m_cps; }; + void release(PipelineStateMtl* _ptr) + { + BX_DELETE(g_allocator, _ptr); + } + struct TextureMtl { enum Enum @@ -847,14 +961,32 @@ namespace bgfx { namespace mtl , m_depth(0) , m_numMips(0) { + for(uint32_t ii = 0; ii < BX_COUNTOF(m_ptrMips); ++ii) + { + m_ptrMips[ii] = NULL; + } } void create(const Memory* _mem, uint64_t _flags, uint8_t _skip); void destroy() { - MTL_RELEASE(m_ptr); + if (0 == (m_flags & BGFX_SAMPLER_INTERNAL_SHARED)) + { + MTL_RELEASE(m_ptr); + } MTL_RELEASE(m_ptrStencil); + for (uint32_t ii = 0; ii < m_numMips; ++ii) + { + MTL_RELEASE(m_ptrMips[ii]); + } + } + + void overrideInternal(uintptr_t _ptr) + { + destroy(); + m_flags |= BGFX_SAMPLER_INTERNAL_SHARED; + m_ptr = id<MTLTexture>(_ptr); } void update( @@ -872,11 +1004,15 @@ namespace bgfx { namespace mtl , bool _vertex , bool _fragment , uint32_t _flags = BGFX_SAMPLER_INTERNAL_DEFAULT + , uint8_t _mip = UINT8_MAX ); + Texture getTextureMipLevel(int _mip); + Texture m_ptr; Texture m_ptrMsaa; Texture m_ptrStencil; // for emulating packed depth/stencil formats - only for iOS8... + Texture m_ptrMips[14]; SamplerState m_sampler; uint64_t m_flags; uint32_t m_width; @@ -895,6 +1031,7 @@ namespace bgfx { namespace mtl SwapChainMtl() : m_metalLayer(nil) , m_drawable(nil) + , m_drawableTexture(nil) , m_backBufferColorMsaa() , m_backBufferDepth() , m_backBufferStencil() @@ -905,22 +1042,26 @@ namespace bgfx { namespace mtl ~SwapChainMtl(); void init(void* _nwh); - void resize(FrameBufferMtl &_frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags); + void resize(FrameBufferMtl &_frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags, uint32_t _maximumDrawableCount); - id<CAMetalDrawable> currentDrawable(); + id <MTLTexture> currentDrawableTexture(); CAMetalLayer* m_metalLayer; id <CAMetalDrawable> m_drawable; + id <MTLTexture> m_drawableTexture; Texture m_backBufferColorMsaa; Texture m_backBufferDepth; Texture m_backBufferStencil; uint32_t m_maxAnisotropy; + void* m_nwh; }; struct FrameBufferMtl { FrameBufferMtl() - : m_denseIdx(UINT16_MAX) + : m_swapChain(NULL) + , m_nwh(NULL) + , m_denseIdx(UINT16_MAX) , m_pixelFormatHash(0) , m_num(0) { @@ -939,7 +1080,10 @@ namespace bgfx { namespace mtl void postReset(); uint16_t destroy(); + void resolve(); + SwapChainMtl* m_swapChain; + void* m_nwh; uint32_t m_width; uint32_t m_height; uint16_t m_denseIdx; @@ -948,6 +1092,8 @@ namespace bgfx { namespace mtl TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; TextureHandle m_depthHandle; + Attachment m_colorAttachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1]; + Attachment m_depthAttachment; uint8_t m_num; // number of color handles }; @@ -975,7 +1121,7 @@ namespace bgfx { namespace mtl int m_releaseWriteIndex; int m_releaseReadIndex; typedef stl::vector<NSObject*> ResourceArray; - ResourceArray m_release[MTL_MAX_FRAMES_IN_FLIGHT]; + ResourceArray m_release[BGFX_CONFIG_MAX_FRAME_LATENCY]; }; struct TimerQueryMtl @@ -987,15 +1133,33 @@ namespace bgfx { namespace mtl void init(); void shutdown(); + uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum); + void end(uint32_t _idx); void addHandlers(CommandBuffer& _commandBuffer); bool get(); + struct Result + { + void reset() + { + m_begin = 0; + m_end = 0; + m_pending = 0; + m_frameNum = 0; + } + + uint64_t m_begin; + uint64_t m_end; + uint32_t m_pending; + uint32_t m_frameNum; // TODO: implement (currently stays 0) + }; + uint64_t m_begin; uint64_t m_end; uint64_t m_elapsed; uint64_t m_frequency; - uint64_t m_result[4*2]; + Result m_result[4*2]; bx::RingBufferControl m_control; }; diff --git a/3rdparty/bgfx/src/renderer_mtl.mm b/3rdparty/bgfx/src/renderer_mtl.mm index d104f7130d6..2317c16d6b5 100644 --- a/3rdparty/bgfx/src/renderer_mtl.mm +++ b/3rdparty/bgfx/src/renderer_mtl.mm @@ -1,6 +1,6 @@ /* * Copyright 2011-2016 Attila Kocsis. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -22,6 +22,14 @@ namespace bgfx { namespace mtl { static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + inline void setViewType(ViewId _view, const bx::StringView _str) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION || BGFX_CONFIG_PROFILER) ) + { + bx::memCopy(&s_viewName[_view][3], _str.getPtr(), _str.getLength() ); + } + } + struct PrimInfo { MTLPrimitiveType m_type; @@ -201,110 +209,144 @@ namespace bgfx { namespace mtl struct TextureFormatInfo { - MTLPixelFormat m_fmt; - MTLPixelFormat m_fmtSrgb; + MTLPixelFormat m_fmt; + MTLPixelFormat m_fmtSrgb; + MTLReadWriteTextureTier m_rwTier; + MTLTextureSwizzleChannels m_mapping; + bool m_autoGetMipmap; }; static TextureFormatInfo s_textureFormat[] = { - { MTLPixelFormat(130/*BC1_RGBA*/), MTLPixelFormat(131/*BC1_RGBA_sRGB*/) }, // BC1 - { MTLPixelFormat(132/*BC2_RGBA*/), MTLPixelFormat(133/*BC2_RGBA_sRGB*/) }, // BC2 - { MTLPixelFormat(134/*BC3_RGBA*/), MTLPixelFormat(135/*BC3_RGBA_sRGB*/) }, // BC3 - { MTLPixelFormat(140/*BC4_RUnorm*/), MTLPixelFormatInvalid }, // BC4 - { MTLPixelFormat(142/*BC5_RGUnorm*/), MTLPixelFormatInvalid }, // BC5 - { MTLPixelFormat(150/*BC6H_RGBFloat*/), MTLPixelFormatInvalid }, // BC6H - { MTLPixelFormat(152/*BC7_RGBAUnorm*/), MTLPixelFormat(153/*BC7_RGBAUnorm_sRGB*/) }, // BC7 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ETC1 - { MTLPixelFormat(180/*ETC2_RGB8*/), MTLPixelFormat(181/*ETC2_RGB8_sRGB*/) }, // ETC2 - { MTLPixelFormat(178/*EAC_RGBA8*/), MTLPixelFormat(179/*EAC_RGBA8_sRGB*/) }, // ETC2A - { MTLPixelFormat(182/*ETC2_RGB8A1*/), MTLPixelFormat(183/*ETC2_RGB8A1_sRGB*/) }, // ETC2A1 - { MTLPixelFormat(160/*PVRTC_RGB_2BPP*/), MTLPixelFormat(161/*PVRTC_RGB_2BPP_sRGB*/) }, // PTC12 - { MTLPixelFormat(162/*PVRTC_RGB_4BPP*/), MTLPixelFormat(163/*PVRTC_RGB_4BPP_sRGB*/) }, // PTC14 - { MTLPixelFormat(164/*PVRTC_RGBA_2BPP*/), MTLPixelFormat(165/*PVRTC_RGBA_2BPP_sRGB*/) }, // PTC12A - { MTLPixelFormat(166/*PVRTC_RGBA_4BPP*/), MTLPixelFormat(167/*PVRTC_RGBA_4BPP_sRGB*/) }, // PTC14A - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // PTC22 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // PTC24 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ATC - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ATCE - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ATCI -#if BX_PLATFORM_IOS - { MTLPixelFormatASTC_4x4_LDR, MTLPixelFormatASTC_4x4_sRGB }, // ASTC4x4 - { MTLPixelFormatASTC_5x5_LDR, MTLPixelFormatASTC_5x5_sRGB }, // ASTC5x5 - { MTLPixelFormatASTC_6x6_LDR, MTLPixelFormatASTC_6x6_sRGB }, // ASTC6x6 - { MTLPixelFormatASTC_8x5_LDR, MTLPixelFormatASTC_8x5_sRGB }, // ASTC8x5 - { MTLPixelFormatASTC_8x6_LDR, MTLPixelFormatASTC_8x6_sRGB }, // ASTC8x6 - { MTLPixelFormatASTC_10x5_LDR, MTLPixelFormatASTC_10x5_sRGB }, // ASTC10x5 +#define $0 MTLTextureSwizzleZero +#define $1 MTLTextureSwizzleOne +#define $R MTLTextureSwizzleRed +#define $G MTLTextureSwizzleGreen +#define $B MTLTextureSwizzleBlue +#define $A MTLTextureSwizzleAlpha + { MTLPixelFormat(130/*BC1_RGBA*/), MTLPixelFormat(131/*BC1_RGBA_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC1 + { MTLPixelFormat(132/*BC2_RGBA*/), MTLPixelFormat(133/*BC2_RGBA_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC2 + { MTLPixelFormat(134/*BC3_RGBA*/), MTLPixelFormat(135/*BC3_RGBA_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC3 + { MTLPixelFormat(140/*BC4_RUnorm*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC4 + { MTLPixelFormat(142/*BC5_RGUnorm*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC5 + { MTLPixelFormat(150/*BC6H_RGBFloat*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC6H + { MTLPixelFormat(152/*BC7_RGBAUnorm*/), MTLPixelFormat(153/*BC7_RGBAUnorm_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BC7 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ETC1 + { MTLPixelFormat(180/*ETC2_RGB8*/), MTLPixelFormat(181/*ETC2_RGB8_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ETC2 + { MTLPixelFormat(178/*EAC_RGBA8*/), MTLPixelFormat(179/*EAC_RGBA8_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ETC2A + { MTLPixelFormat(182/*ETC2_RGB8A1*/), MTLPixelFormat(183/*ETC2_RGB8A1_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ETC2A1 + { MTLPixelFormat(160/*PVRTC_RGB_2BPP*/), MTLPixelFormat(161/*PVRTC_RGB_2BPP_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // PTC12 + { MTLPixelFormat(162/*PVRTC_RGB_4BPP*/), MTLPixelFormat(163/*PVRTC_RGB_4BPP_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // PTC14 + { MTLPixelFormat(164/*PVRTC_RGBA_2BPP*/), MTLPixelFormat(165/*PVRTC_RGBA_2BPP_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // PTC12A + { MTLPixelFormat(166/*PVRTC_RGBA_4BPP*/), MTLPixelFormat(167/*PVRTC_RGBA_4BPP_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // PTC14A + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // PTC22 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // PTC24 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ATC + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ATCE + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ATCI +#if BX_PLATFORM_IOS && !TARGET_OS_MACCATALYST + { MTLPixelFormatASTC_4x4_LDR, MTLPixelFormatASTC_4x4_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC4x4 + { MTLPixelFormatASTC_5x4_LDR, MTLPixelFormatASTC_5x4_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x4 + { MTLPixelFormatASTC_5x5_LDR, MTLPixelFormatASTC_5x5_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x5 + { MTLPixelFormatASTC_6x5_LDR, MTLPixelFormatASTC_6x5_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC6x5 + { MTLPixelFormatASTC_6x6_LDR, MTLPixelFormatASTC_6x6_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC6x6 + { MTLPixelFormatASTC_8x5_LDR, MTLPixelFormatASTC_8x5_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x5 + { MTLPixelFormatASTC_8x6_LDR, MTLPixelFormatASTC_8x6_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x6 + { MTLPixelFormatASTC_8x8_LDR, MTLPixelFormatASTC_8x8_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x8 + { MTLPixelFormatASTC_10x5_LDR, MTLPixelFormatASTC_10x5_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x5 + { MTLPixelFormatASTC_10x6_LDR, MTLPixelFormatASTC_10x6_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x6 + { MTLPixelFormatASTC_10x8_LDR, MTLPixelFormatASTC_10x8_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x8 + { MTLPixelFormatASTC_10x10_LDR, MTLPixelFormatASTC_10x10_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x10 + { MTLPixelFormatASTC_12x10_LDR, MTLPixelFormatASTC_12x10_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x10 + { MTLPixelFormatASTC_12x12_LDR, MTLPixelFormatASTC_12x12_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x12 #else - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC4x4 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC5x5 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC6x6 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC8x5 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC8x6 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // ASTC10x5 -#endif - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // Unknown - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // R1 - { MTLPixelFormatA8Unorm, MTLPixelFormatInvalid }, // A8 - { MTLPixelFormatR8Unorm, MTLPixelFormat(11/*R8Unorm_sRGB*/) }, // R8 - { MTLPixelFormatR8Sint, MTLPixelFormatInvalid }, // R8I - { MTLPixelFormatR8Uint, MTLPixelFormatInvalid }, // R8U - { MTLPixelFormatR8Snorm, MTLPixelFormatInvalid }, // R8S - { MTLPixelFormatR16Unorm, MTLPixelFormatInvalid }, // R16 - { MTLPixelFormatR16Sint, MTLPixelFormatInvalid }, // R16I - { MTLPixelFormatR16Uint, MTLPixelFormatInvalid }, // R16U - { MTLPixelFormatR16Float, MTLPixelFormatInvalid }, // R16F - { MTLPixelFormatR16Snorm, MTLPixelFormatInvalid }, // R16S - { MTLPixelFormatR32Sint, MTLPixelFormatInvalid }, // R32I - { MTLPixelFormatR32Uint, MTLPixelFormatInvalid }, // R32U - { MTLPixelFormatR32Float, MTLPixelFormatInvalid }, // R32F - { MTLPixelFormatRG8Unorm, MTLPixelFormat(31/*RG8Unorm_sRGB*/) }, // RG8 - { MTLPixelFormatRG8Sint, MTLPixelFormatInvalid }, // RG8I - { MTLPixelFormatRG8Uint, MTLPixelFormatInvalid }, // RG8U - { MTLPixelFormatRG8Snorm, MTLPixelFormatInvalid }, // RG8S - { MTLPixelFormatRG16Unorm, MTLPixelFormatInvalid }, // RG16 - { MTLPixelFormatRG16Sint, MTLPixelFormatInvalid }, // RG16I - { MTLPixelFormatRG16Uint, MTLPixelFormatInvalid }, // RG16U - { MTLPixelFormatRG16Float, MTLPixelFormatInvalid }, // RG16F - { MTLPixelFormatRG16Snorm, MTLPixelFormatInvalid }, // RG16S - { MTLPixelFormatRG32Sint, MTLPixelFormatInvalid }, // RG32I - { MTLPixelFormatRG32Uint, MTLPixelFormatInvalid }, // RG32U - { MTLPixelFormatRG32Float, MTLPixelFormatInvalid }, // RG32F - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8 - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8I - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8U - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // RGB8S - { MTLPixelFormatRGB9E5Float, MTLPixelFormatInvalid }, // RGB9E5F - { MTLPixelFormatBGRA8Unorm, MTLPixelFormatBGRA8Unorm_sRGB }, // BGRA8 - { MTLPixelFormatRGBA8Unorm, MTLPixelFormatRGBA8Unorm_sRGB }, // RGBA8 - { MTLPixelFormatRGBA8Sint, MTLPixelFormatInvalid }, // RGBA8I - { MTLPixelFormatRGBA8Uint, MTLPixelFormatInvalid }, // RGBA8U - { MTLPixelFormatRGBA8Snorm, MTLPixelFormatInvalid }, // RGBA8S - { MTLPixelFormatRGBA16Unorm, MTLPixelFormatInvalid }, // RGBA16 - { MTLPixelFormatRGBA16Sint, MTLPixelFormatInvalid }, // RGBA16I - { MTLPixelFormatRGBA16Uint, MTLPixelFormatInvalid }, // RGBA16U - { MTLPixelFormatRGBA16Float, MTLPixelFormatInvalid }, // RGBA16F - { MTLPixelFormatRGBA16Snorm, MTLPixelFormatInvalid }, // RGBA16S - { MTLPixelFormatRGBA32Sint, MTLPixelFormatInvalid }, // RGBA32I - { MTLPixelFormatRGBA32Uint, MTLPixelFormatInvalid }, // RGBA32U - { MTLPixelFormatRGBA32Float, MTLPixelFormatInvalid }, // RGBA32F - { MTLPixelFormat(40/*B5G6R5Unorm*/), MTLPixelFormatInvalid }, // R5G6B5 - { MTLPixelFormat(42/*ABGR4Unorm*/), MTLPixelFormatInvalid }, // RGBA4 - { MTLPixelFormat(41/*A1BGR5Unorm*/), MTLPixelFormatInvalid }, // RGB5A1 - { MTLPixelFormatRGB10A2Unorm, MTLPixelFormatInvalid }, // RGB10A2 - { MTLPixelFormatRG11B10Float, MTLPixelFormatInvalid }, // RG11B10F - { MTLPixelFormatInvalid, MTLPixelFormatInvalid }, // UnknownDepth - { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid }, // D16 - { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid }, // D24 - { MTLPixelFormat(255/*Depth24Unorm_Stencil8*/), MTLPixelFormatInvalid }, // D24S8 - { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid }, // D32 - { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid }, // D16F - { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid }, // D24F - { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid }, // D32F - { MTLPixelFormatStencil8, MTLPixelFormatInvalid }, // D0S8 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC4x4 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x4 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC5x5 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC6x5 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC6x6 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x5 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x6 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC8x8 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x5 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x6 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x8 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC10x10 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x10 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // ASTC12x12 +#endif // BX_PLATFORM_IOS && !TARGET_OS_MACCATALYST + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // Unknown + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // R1 + { MTLPixelFormatA8Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // A8 + { MTLPixelFormatR8Unorm, MTLPixelFormat(11/*R8Unorm_sRGB*/), MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // R8 + { MTLPixelFormatR8Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, false }, // R8I + { MTLPixelFormatR8Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // R8U + { MTLPixelFormatR8Snorm, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // R8S + { MTLPixelFormatR16Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // R16 + { MTLPixelFormatR16Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, false }, // R16I + { MTLPixelFormatR16Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, false }, // R16U + { MTLPixelFormatR16Float, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // R16F + { MTLPixelFormatR16Snorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // R16S + { MTLPixelFormatR32Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTier1, { $R, $G, $B, $A }, false }, // R32I + { MTLPixelFormatR32Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTier1, { $R, $G, $B, $A }, false }, // R32U + { MTLPixelFormatR32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTier1, { $R, $G, $B, $A }, false }, // R32F + { MTLPixelFormatRG8Unorm, MTLPixelFormat(31/*RG8Unorm_sRGB*/), MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG8 + { MTLPixelFormatRG8Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RG8I + { MTLPixelFormatRG8Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RG8U + { MTLPixelFormatRG8Snorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG8S + { MTLPixelFormatRG16Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG16 + { MTLPixelFormatRG16Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RG16I + { MTLPixelFormatRG16Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RG16U + { MTLPixelFormatRG16Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG16F + { MTLPixelFormatRG16Snorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG16S + { MTLPixelFormatRG32Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RG32I + { MTLPixelFormatRG32Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RG32U + { MTLPixelFormatRG32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RG32F + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RGB8 + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RGB8I + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RGB8U + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RGB8S + { MTLPixelFormatRGB9E5Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // RGB9E5F + { MTLPixelFormatBGRA8Unorm, MTLPixelFormatBGRA8Unorm_sRGB, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // BGRA8 + { MTLPixelFormatRGBA8Unorm, MTLPixelFormatRGBA8Unorm_sRGB, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA8 + { MTLPixelFormatRGBA8Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, false }, // RGBA8I + { MTLPixelFormatRGBA8Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, false }, // RGBA8U + { MTLPixelFormatRGBA8Snorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGBA8S + { MTLPixelFormatRGBA16Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGBA16 + { MTLPixelFormatRGBA16Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, false }, // RGBA16I + { MTLPixelFormatRGBA16Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, false }, // RGBA16U + { MTLPixelFormatRGBA16Float, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA16F + { MTLPixelFormatRGBA16Snorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGBA16S + { MTLPixelFormatRGBA32Sint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32I + { MTLPixelFormatRGBA32Uint, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32U + { MTLPixelFormatRGBA32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTier2, { $R, $G, $B, $A }, true }, // RGBA32F + { MTLPixelFormatB5G6R5Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // B5G6R5 + { MTLPixelFormatB5G6R5Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // R5G6B5 + { MTLPixelFormatABGR4Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $G, $B, $A, $R }, true }, // BGRA4 + { MTLPixelFormatABGR4Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $A, $B, $G, $R }, true }, // RGBA4 + { MTLPixelFormatBGR5A1Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // BGR5A1 + { MTLPixelFormatBGR5A1Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $B, $G, $R, $A }, true }, // RGB5A1 + { MTLPixelFormatRGB10A2Unorm, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RGB10A2 + { MTLPixelFormatRG11B10Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, true }, // RG11B10F + { MTLPixelFormatInvalid, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // UnknownDepth + { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D16 + { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D24 + { MTLPixelFormat(255/*Depth24Unorm_Stencil8*/), MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D24S8 + { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D32 + { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D16F + { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D24F + { MTLPixelFormatDepth32Float, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D32F + { MTLPixelFormatStencil8, MTLPixelFormatInvalid, MTLReadWriteTextureTierNone, { $R, $G, $B, $A }, false }, // D0S8 +#undef $0 +#undef $1 +#undef $R +#undef $G +#undef $B +#undef $A }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); - int s_msaa[] = + int32_t s_msaa[] = { 1, 2, @@ -319,7 +361,7 @@ namespace bgfx { namespace mtl { case MTLDataTypeUInt: case MTLDataTypeInt: - return UniformType::Int1; + return UniformType::Sampler; case MTLDataTypeFloat: case MTLDataTypeFloat2: @@ -337,17 +379,58 @@ namespace bgfx { namespace mtl break; }; - BX_CHECK(false, "Unrecognized Mtl Data type 0x%04x.", _type); + BX_ASSERT(false, "Unrecognized Mtl Data type 0x%04x.", _type); return UniformType::End; } + static uint64_t getRegistryId(id<MTLDevice> _device) + { + return [_device respondsToSelector: @selector(registryID)] ? _device.registryID : 0; + } + +#if BX_PLATFORM_OSX + static uint32_t getEntryProperty(io_registry_entry_t _entry, CFStringRef _propertyName) + { + uint32_t result = 0; + + CFTypeRef typeRef = IORegistryEntrySearchCFProperty( + _entry + , kIOServicePlane + , _propertyName + , kCFAllocatorDefault + , kIORegistryIterateRecursively | kIORegistryIterateParents + ); + + if (NULL != typeRef) + { + const uint32_t* value = (const uint32_t*)(CFDataGetBytePtr( (CFDataRef)typeRef) ); + if (NULL != value) + { + result = *value; + } + + CFRelease(typeRef); + } + + return result; + } +#endif // BX_PLATFORM_OSX + + +static const char* s_accessNames[] = { + "Access::Read", + "Access::Write", + "Access::ReadWrite", +}; + +BX_STATIC_ASSERT(BX_COUNTOF(s_accessNames) == Access::Count, "Invalid s_accessNames count"); + #define SHADER_FUNCTION_NAME ("xlatMtlMain") -#define SHADER_UNIFORM_NAME ("_mtl_u") +#define SHADER_UNIFORM_NAME ("_mtl_u") struct RendererContextMtl; static RendererContextMtl* s_renderMtl; - struct RendererContextMtl : public RendererContextI { RendererContextMtl() @@ -356,8 +439,8 @@ namespace bgfx { namespace mtl , m_rtMsaa(false) , m_capture(NULL) , m_captureSize(0) - , m_saveScreenshot(false) { + bx::memSet(&m_windows, 0xff, sizeof(m_windows) ); } ~RendererContextMtl() @@ -387,7 +470,22 @@ namespace bgfx { namespace mtl } retain(m_device); - createFrameBuffer(m_fbh, g_platformData.nwh, 0, 0, TextureFormat::Unknown, TextureFormat::UnknownDepth); + + m_mainFrameBuffer.create( + 0 + , g_platformData.nwh + , _init.resolution.width + , _init.resolution.height + , TextureFormat::Unknown + , TextureFormat::UnknownDepth + ); + m_numWindows = 1; + + if (NULL == m_mainFrameBuffer.m_swapChain->m_metalLayer) + { + release(m_device); + return false; + } m_cmd.init(m_device); BGFX_FATAL(NULL != m_cmd.m_commandQueue, Fatal::UnableToInitialize, "Unable to create Metal device."); @@ -400,7 +498,7 @@ namespace bgfx { namespace mtl m_textureDescriptor = newTextureDescriptor(); m_samplerDescriptor = newSamplerDescriptor(); - for (uint8_t ii = 0; ii < MTL_MAX_FRAMES_IN_FLIGHT; ++ii) + for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_FRAME_LATENCY; ++ii) { m_uniformBuffers[ii] = m_device.newBufferWithLength(UNIFORM_BUFFER_SIZE, 0); } @@ -434,26 +532,88 @@ namespace bgfx { namespace mtl if (NULL != lib) { m_screenshotBlitProgramVsh.m_function = lib.newFunctionWithName(SHADER_FUNCTION_NAME); + release(lib); } lib = m_device.newLibraryWithSource(fshSource); if (NULL != lib) { m_screenshotBlitProgramFsh.m_function = lib.newFunctionWithName(SHADER_FUNCTION_NAME); + release(lib); } m_screenshotBlitProgram.create(&m_screenshotBlitProgramVsh, &m_screenshotBlitProgramFsh); - release(lib); reset(m_renderPipelineDescriptor); m_renderPipelineDescriptor.colorAttachments[0].pixelFormat = m_mainFrameBuffer.m_swapChain->m_metalLayer.pixelFormat; m_renderPipelineDescriptor.vertexFunction = m_screenshotBlitProgram.m_vsh->m_function; m_renderPipelineDescriptor.fragmentFunction = m_screenshotBlitProgram.m_fsh->m_function; - m_screenshotBlitRenderPipelineState = m_device.newRenderPipelineStateWithDescriptor(m_renderPipelineDescriptor); + m_screenshotBlitRenderPipelineState = m_device.newRenderPipelineStateWithDescriptor(m_renderPipelineDescriptor); + + { + if ([m_device respondsToSelector: @selector(supportsFamily:)]) + { + if ([m_device supportsFamily: MTLGPUFamily(1004) /*MTLGPUFamilyApple4*/]) + { + g_caps.vendorId = BGFX_PCI_ID_APPLE; + + if ([m_device supportsFamily: MTLGPUFamily(1007) /*MTLGPUFamilyApple7*/]) + { + g_caps.deviceId = 1007; + } + else if ([m_device supportsFamily: MTLGPUFamily(1006) /*MTLGPUFamilyApple6*/]) + { + g_caps.deviceId = 1006; + } + else if ([m_device supportsFamily: MTLGPUFamily(1005) /*MTLGPUFamilyApple5*/]) + { + g_caps.deviceId = 1005; + } + else + { + g_caps.deviceId = 1004; + } + } + } + +#if BX_PLATFORM_OSX + if (0 == g_caps.vendorId) + { + io_registry_entry_t entry; + + uint64_t registryId = getRegistryId(m_device); + + if (0 != registryId) + { + entry = IOServiceGetMatchingService(mach_port_t(NULL), IORegistryEntryIDMatching(registryId) ); + + if (0 != entry) + { + io_registry_entry_t parent; + + if (kIOReturnSuccess == IORegistryEntryGetParentEntry(entry, kIOServicePlane, &parent) ) + { + g_caps.vendorId = getEntryProperty(parent, CFSTR("vendor-id") ); + g_caps.deviceId = getEntryProperty(parent, CFSTR("device-id") ); + + IOObjectRelease(parent); + } + + IOObjectRelease(entry); + } + } + } +#endif // BX_PLATFORM_OSX + } + + g_caps.numGPUs = 1; + g_caps.gpu[0].vendorId = g_caps.vendorId; + g_caps.gpu[0].deviceId = g_caps.deviceId; g_caps.supported |= (0 | BGFX_CAPS_ALPHA_TO_COVERAGE | BGFX_CAPS_BLEND_INDEPENDENT + | BGFX_CAPS_COMPUTE | BGFX_CAPS_FRAGMENT_DEPTH | BGFX_CAPS_INDEX32 | BGFX_CAPS_INSTANCING @@ -467,6 +627,7 @@ namespace bgfx { namespace mtl | BGFX_CAPS_TEXTURE_READ_BACK | BGFX_CAPS_VERTEX_ATTRIB_HALF | BGFX_CAPS_VERTEX_ATTRIB_UINT10 + | BGFX_CAPS_VERTEX_ID ); if (BX_ENABLED(BX_PLATFORM_IOS) ) @@ -481,25 +642,50 @@ namespace bgfx { namespace mtl } g_caps.limits.maxFBAttachments = uint8_t(bx::uint32_min(m_device.supportsFeatureSet( (MTLFeatureSet)1 /* MTLFeatureSet_iOS_GPUFamily2_v1 */) ? 8 : 4, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); + + g_caps.supported |= m_device.supportsFeatureSet( (MTLFeatureSet)4 /* MTLFeatureSet_iOS_GPUFamily3_v1 */) + ? BGFX_CAPS_DRAW_INDIRECT + : 0 + ; + + g_caps.supported |= m_device.supportsFeatureSet( (MTLFeatureSet)11 /* MTLFeatureSet_iOS_GPUFamily4_v1 */) + ? BGFX_CAPS_TEXTURE_CUBE_ARRAY + : 0 + ; } else if (BX_ENABLED(BX_PLATFORM_OSX) ) { g_caps.limits.maxTextureSize = 16384; g_caps.limits.maxFBAttachments = 8; g_caps.supported |= BGFX_CAPS_TEXTURE_CUBE_ARRAY; + + g_caps.supported |= m_device.supportsFeatureSet( (MTLFeatureSet)10001 /* MTLFeatureSet_macOS_GPUFamily1_v2 */) + ? BGFX_CAPS_DRAW_INDIRECT + : 0 + ; } g_caps.limits.maxTextureLayers = 2048; g_caps.limits.maxVertexStreams = BGFX_CONFIG_MAX_VERTEX_STREAMS; + // Maximum number of entries in the buffer argument table, per graphics or compute function are 31. + // It is decremented by 1 because 1 entry is used for uniforms. + g_caps.limits.maxComputeBindings = bx::uint32_min(30, BGFX_MAX_COMPUTE_BINDINGS); m_hasPixelFormatDepth32Float_Stencil8 = false || BX_ENABLED(BX_PLATFORM_OSX) || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ) ; + + m_hasStoreActionStoreAndMultisampleResolve = false + || (BX_ENABLED(BX_PLATFORM_OSX) && macOSVersionEqualOrGreater(10, 12, 0) ) + || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("10.0.0") ) + ; + m_macOS11Runtime = true && BX_ENABLED(BX_PLATFORM_OSX) - && macOSVersionEqualOrGreater(10,11,0) + && macOSVersionEqualOrGreater(10, 11, 0) ; + m_iOS9Runtime = true && BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") @@ -511,6 +697,12 @@ namespace bgfx { namespace mtl s_textureFormat[TextureFormat::RG8].m_fmtSrgb = MTLPixelFormatInvalid; } + const MTLReadWriteTextureTier rwTier = [m_device readWriteTextureSupport]; + g_caps.supported |= rwTier != MTLReadWriteTextureTierNone + ? BGFX_CAPS_IMAGE_RW + : 0 + ; + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { uint16_t support = 0; @@ -539,6 +731,19 @@ namespace bgfx { namespace mtl ; } + support |= true + && s_textureFormat[ii].m_rwTier != MTLReadWriteTextureTierNone + && s_textureFormat[ii].m_rwTier <= rwTier + ? BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ + | BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= s_textureFormat[ii].m_autoGetMipmap + ? BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN + : 0 + ; + g_caps.formats[ii] = support; } @@ -577,10 +782,7 @@ namespace bgfx { namespace mtl g_caps.formats[TextureFormat::PTC12 ] = g_caps.formats[TextureFormat::PTC14 ] = g_caps.formats[TextureFormat::PTC12A] = - g_caps.formats[TextureFormat::PTC14A] = - g_caps.formats[TextureFormat::R5G6B5] = - g_caps.formats[TextureFormat::RGBA4 ] = - g_caps.formats[TextureFormat::RGB5A1] = BGFX_CAPS_FORMAT_TEXTURE_NONE; + g_caps.formats[TextureFormat::PTC14A] = BGFX_CAPS_FORMAT_TEXTURE_NONE; g_caps.formats[TextureFormat::RGB9E5F] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); } @@ -594,11 +796,17 @@ namespace bgfx { namespace mtl } } - for (uint32_t ii = 1; ii < 5; ++ii) + for (uint32_t ii = 1, last = 0; ii < BX_COUNTOF(s_msaa); ++ii) { - if (!m_device.supportsTextureSampleCount(s_msaa[ii]) ) + const int32_t sampleCount = 1<<ii; + if (m_device.supportsTextureSampleCount(sampleCount) ) + { + s_msaa[ii] = sampleCount; + last = ii; + } + else { - s_msaa[ii] = s_msaa[ii-1]; + s_msaa[ii] = s_msaa[last]; } } @@ -612,6 +820,7 @@ namespace bgfx { namespace mtl m_gpuTimer.init(); g_internalData.context = m_device; + return true; } @@ -621,6 +830,10 @@ namespace bgfx { namespace mtl m_gpuTimer.shutdown(); m_pipelineStateCache.invalidate(); + m_pipelineProgram.clear(); + + m_depthStencilStateCache.invalidate(); + m_samplerStateCache.invalidate(); for (uint32_t ii = 0; ii < BX_COUNTOF(m_shaders); ++ii) { @@ -647,13 +860,9 @@ namespace bgfx { namespace mtl MTL_RELEASE(m_textureDescriptor); MTL_RELEASE(m_samplerDescriptor); - MTL_RELEASE(m_mainFrameBuffer.m_swapChain->m_backBufferDepth); - if (BX_ENABLED(BX_PLATFORM_IOS) ) - { - MTL_RELEASE(m_mainFrameBuffer.m_swapChain->m_backBufferStencil); - } + m_mainFrameBuffer.destroy(); - for (uint8_t i=0; i < MTL_MAX_FRAMES_IN_FLIGHT; ++i) + for (uint8_t i=0; i < BGFX_CONFIG_MAX_FRAME_LATENCY; ++i) { MTL_RELEASE(m_uniformBuffers[i]); } @@ -681,20 +890,20 @@ namespace bgfx { namespace mtl m_indexBuffers[_handle.idx].destroy(); } - void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override + void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) override { - VertexDecl& decl = m_vertexDecls[_handle.idx]; - bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); - dump(decl); + VertexLayout& layout = m_vertexLayouts[_handle.idx]; + bx::memCopy(&layout, &_layout, sizeof(VertexLayout) ); + dump(layout); } - void destroyVertexDecl(VertexDeclHandle /*_handle*/) override + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override { } - void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) override + void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t _flags) override { - m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); + m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _layoutHandle, _flags); } void destroyVertexBuffer(VertexBufferHandle _handle) override @@ -719,8 +928,8 @@ namespace bgfx { namespace mtl void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) override { - VertexDeclHandle decl = BGFX_INVALID_HANDLE; - m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); + VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE; + m_vertexBuffers[_handle.idx].create(_size, NULL, layoutHandle, _flags); } void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override @@ -745,11 +954,24 @@ namespace bgfx { namespace mtl void createProgram(ProgramHandle _handle, ShaderHandle _vsh, ShaderHandle _fsh) override { - m_program[_handle.idx].create(&m_shaders[_vsh.idx], &m_shaders[_fsh.idx]); + m_program[_handle.idx].create(&m_shaders[_vsh.idx], isValid(_fsh) ? &m_shaders[_fsh.idx] : NULL); } void destroyProgram(ProgramHandle _handle) override { + for (PipelineProgramArray::iterator it = m_pipelineProgram.begin(); it != m_pipelineProgram.end();) + { + if (it->program.idx == _handle.idx) + { + m_pipelineStateCache.invalidate(it->key); + it = m_pipelineProgram.erase(it); + } + else + { + ++it; + } + } + m_program[_handle.idx].destroy(); } @@ -774,12 +996,18 @@ namespace bgfx { namespace mtl void readTexture(TextureHandle _handle, void* _data, uint8_t _mip) override { + const TextureMtl& texture = m_textures[_handle.idx]; + +#if BX_PLATFORM_OSX + BlitCommandEncoder bce = s_renderMtl->getBlitCommandEncoder(); + bce.synchronizeTexture(texture.m_ptr, 0, _mip); + endEncoding(); +#endif // BX_PLATFORM_OSX + m_cmd.kick(false, true); m_commandBuffer = m_cmd.alloc(); - const TextureMtl& texture = m_textures[_handle.idx]; - - BX_CHECK(_mip<texture.m_numMips,"Invalid mip: %d num mips:",_mip,texture.m_numMips); + BX_ASSERT(_mip<texture.m_numMips,"Invalid mip: %d num mips:",_mip,texture.m_numMips); uint32_t srcWidth = bx::uint32_max(1, texture.m_ptr.width() >> _mip); uint32_t srcHeight = bx::uint32_max(1, texture.m_ptr.height() >> _mip); @@ -803,7 +1031,7 @@ namespace bgfx { namespace mtl bx::StaticMemoryBlockWriter writer(mem->data, mem->size); uint32_t magic = BGFX_CHUNK_MAGIC_TEX; - bx::write(&writer, magic); + bx::write(&writer, magic, bx::ErrorAssert{}); TextureCreate tc; tc.m_width = _width; @@ -814,7 +1042,7 @@ namespace bgfx { namespace mtl tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); tc.m_cubeMap = false; tc.m_mem = NULL; - bx::write(&writer, tc); + bx::write(&writer, tc, bx::ErrorAssert{}); texture.destroy(); texture.create(mem, texture.m_flags, 0); @@ -824,13 +1052,12 @@ namespace bgfx { namespace mtl void overrideInternal(TextureHandle _handle, uintptr_t _ptr) override { - BX_UNUSED(_handle, _ptr); + m_textures[_handle.idx].overrideInternal(_ptr); } uintptr_t getInternal(TextureHandle _handle) override { - BX_UNUSED(_handle); - return 0; + return uintptr_t(id<MTLTexture>(m_textures[_handle.idx].m_ptr) ); } void destroyTexture(TextureHandle _handle) override @@ -845,29 +1072,37 @@ namespace bgfx { namespace mtl void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override { - uint16_t denseIdx = m_numWindows++; - m_windows[denseIdx] = _handle; - if (!isValid(_handle)) - { - m_mainFrameBuffer.create(denseIdx, _nwh, _width, _height, _format, _depthFormat); - } - else + for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) { - m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat); - m_frameBuffers[_handle.idx].m_swapChain->resize(m_frameBuffers[_handle.idx], _width, _height, 0);//_resolution.reset); + FrameBufferHandle handle = m_windows[ii]; + if (isValid(handle) + && m_frameBuffers[handle.idx].m_nwh == _nwh) + { + destroyFrameBuffer(handle); + } } + + uint16_t denseIdx = m_numWindows++; + m_windows[denseIdx] = _handle; + + FrameBufferMtl& fb = m_frameBuffers[_handle.idx]; + fb.create(denseIdx, _nwh, _width, _height, _format, _depthFormat); + fb.m_swapChain->resize(m_frameBuffers[_handle.idx], _width, _height, m_resolution.reset, m_resolution.maxFrameLatency); } void destroyFrameBuffer(FrameBufferHandle _handle) override { uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy(); + if (UINT16_MAX != denseIdx) { --m_numWindows; + if (m_numWindows > 1) { FrameBufferHandle handle = m_windows[m_numWindows]; m_windows[m_numWindows] = {kInvalidHandle}; + if (m_numWindows != denseIdx) { m_windows[denseIdx] = handle; @@ -884,7 +1119,7 @@ namespace bgfx { namespace mtl BX_FREE(g_allocator, m_uniforms[_handle.idx]); } - uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num); + const uint32_t size = bx::alignUp(g_uniformTypeSize[_type]*_num, 16); void* data = BX_ALLOC(g_allocator, size); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; @@ -898,12 +1133,6 @@ namespace bgfx { namespace mtl m_uniformReg.remove(_handle); } - void requestScreenShotPre(const char* _filePath) - { - BX_UNUSED(_filePath); - m_saveScreenshot = true; - } - void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) override { BX_UNUSED(_handle); @@ -913,6 +1142,13 @@ namespace bgfx { namespace mtl return; } +#if BX_PLATFORM_OSX + m_blitCommandEncoder = getBlitCommandEncoder(); + m_blitCommandEncoder.synchronizeResource(m_screenshotTarget); + m_blitCommandEncoder.endEncoding(); + m_blitCommandEncoder = 0; +#endif // BX_PLATFORM_OSX + m_cmd.kick(false, true); m_commandBuffer = 0; @@ -942,14 +1178,11 @@ namespace bgfx { namespace mtl void updateViewName(ViewId _id, const char* _name) override { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - bx::strCopy( - &s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] - , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED - , _name - ); - } + bx::strCopy( + &s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + , _name + ); } void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) override @@ -957,23 +1190,31 @@ namespace bgfx { namespace mtl bx::memCopy(m_uniforms[_loc], _data, _size); } - void setMarker(const char* _marker, uint32_t /*_size*/) override + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + { + m_occlusionQuery.invalidate(_handle); + } + + void setMarker(const char* _marker, uint16_t _len) override { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_MTL) ) + BX_UNUSED(_len); + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) { m_renderCommandEncoder.insertDebugSignpost(_marker); } } - void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + virtual void setName(Handle _handle, const char* _name, uint16_t _len) override { - m_occlusionQuery.invalidate(_handle); - } + BX_UNUSED(_len); - virtual void setName(Handle _handle, const char* _name) override - { switch (_handle.type) { + case Handle::IndexBuffer: + m_indexBuffers[_handle.idx].m_ptr.setLabel(_name); + break; + case Handle::Shader: m_shaders[_handle.idx].m_function.setLabel(_name); break; @@ -982,8 +1223,12 @@ namespace bgfx { namespace mtl m_textures[_handle.idx].m_ptr.setLabel(_name); break; + case Handle::VertexBuffer: + m_vertexBuffers[_handle.idx].m_ptr.setLabel(_name); + break; + default: - BX_CHECK(false, "Invalid handle type?! %d", _handle.type); + BX_ASSERT(false, "Invalid handle type?! %d", _handle.type); break; } } @@ -994,20 +1239,33 @@ namespace bgfx { namespace mtl void blitSetup(TextVideoMemBlitter& _blitter) override { - RenderCommandEncoder rce = m_renderCommandEncoder; + BX_UNUSED(_blitter); + } + + void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) override + { + const uint32_t numVertices = _numIndices*4/6; + if (0 < numVertices) + { + m_indexBuffers [_blitter.m_ib->handle.idx].update( + 0 + , bx::strideAlign(_numIndices*2, 4) + , _blitter.m_ib->data + , true + ); + m_vertexBuffers[_blitter.m_vb->handle.idx].update( + 0 + , numVertices*_blitter.m_layout.m_stride + , _blitter.m_vb->data + , true + ); - uint32_t width = m_resolution.width; - uint32_t height = m_resolution.height; + endEncoding(); - FrameBufferHandle fbh = BGFX_INVALID_HANDLE; + uint32_t width = m_resolution.width; + uint32_t height = m_resolution.height; - if (NULL == rce - || m_renderCommandEncoderFrameBufferHandle.idx != kInvalidHandle) - { - if (m_renderCommandEncoder) - { - m_renderCommandEncoder.endEncoding(); - } + FrameBufferHandle fbh = BGFX_INVALID_HANDLE; RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor(); @@ -1015,80 +1273,83 @@ namespace bgfx { namespace mtl renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionLoad; renderPassDescriptor.colorAttachments[0].storeAction = - NULL != renderPassDescriptor.colorAttachments[0].resolveTexture - ? MTLStoreActionMultisampleResolve - : MTLStoreActionStore - ; + NULL != renderPassDescriptor.colorAttachments[0].resolveTexture + ? MTLStoreActionMultisampleResolve + : MTLStoreActionStore + ; - rce = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor); + RenderCommandEncoder rce = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor); m_renderCommandEncoder = rce; m_renderCommandEncoderFrameBufferHandle = fbh; MTL_RELEASE(renderPassDescriptor); - } - MTLViewport viewport = { 0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f}; - rce.setViewport(viewport); - MTLScissorRect rc = { 0,0,width,height }; - rce.setScissorRect(rc); - rce.setCullMode(MTLCullModeNone); + MTLViewport viewport = { 0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f}; + rce.setViewport(viewport); + MTLScissorRect rc = { 0,0,width,height }; + rce.setScissorRect(rc); + rce.setCullMode(MTLCullModeNone); - uint64_t state = 0 + uint64_t state = 0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A | BGFX_STATE_DEPTH_TEST_ALWAYS ; - setDepthStencilState(state); + setDepthStencilState(state); - RenderPipelineState pso = getPipelineState( - state - , 0 - , fbh - , _blitter.m_vb->decl - , _blitter.m_program.idx - , 0 - ); - rce.setRenderPipelineState(pso); + PipelineStateMtl* pso = getPipelineState( + state + , 0 + , fbh + , _blitter.m_vb->layoutHandle + , _blitter.m_program + , 0 + ); + rce.setRenderPipelineState(pso->m_rps); - ProgramMtl& program = m_program[_blitter.m_program.idx]; - uint32_t vertexUniformBufferSize = program.m_vshConstantBufferSize; - uint32_t fragmentUniformBufferSize = program.m_fshConstantBufferSize; + const uint32_t vertexUniformBufferSize = pso->m_vshConstantBufferSize; + const uint32_t fragmentUniformBufferSize = pso->m_fshConstantBufferSize; - if (vertexUniformBufferSize ) - { - m_uniformBufferVertexOffset = BX_ALIGN_MASK(m_uniformBufferVertexOffset, program.m_vshConstantBufferAlignmentMask); - rce.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0); - } + if (vertexUniformBufferSize) + { + m_uniformBufferVertexOffset = bx::alignUp( + m_uniformBufferVertexOffset + , pso->m_vshConstantBufferAlignment + ); + rce.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0); + } - m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize; - if (fragmentUniformBufferSize ) - { - m_uniformBufferFragmentOffset = BX_ALIGN_MASK(m_uniformBufferFragmentOffset, program.m_fshConstantBufferAlignmentMask); - rce.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0); - } + m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize; - float proj[16]; - bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, false); + if (0 != fragmentUniformBufferSize) + { + m_uniformBufferFragmentOffset = bx::alignUp( + m_uniformBufferFragmentOffset + , pso->m_fshConstantBufferAlignment + ); + rce.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0); + } - PredefinedUniform& predefined = program.m_predefined[0]; - uint8_t flags = predefined.m_type; - setShaderUniform(flags, predefined.m_loc, proj, 4); + float proj[16]; + bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, false); - m_textures[_blitter.m_texture.idx].commit(0, false, true); - } + PredefinedUniform& predefined = pso->m_predefined[0]; + uint8_t flags = predefined.m_type; + setShaderUniform(flags, predefined.m_loc, proj, 4); - void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) override - { - const uint32_t numVertices = _numIndices*4/6; - if (0 < numVertices) - { - m_indexBuffers [_blitter.m_ib->handle.idx].update(0, _numIndices*2, _blitter.m_ib->data, true); - m_vertexBuffers[_blitter.m_vb->handle.idx].update(0, numVertices*_blitter.m_decl.m_stride, _blitter.m_vb->data, true); + m_textures[_blitter.m_texture.idx].commit(0, false, true); VertexBufferMtl& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; - m_renderCommandEncoder.setVertexBuffer(vb.getBuffer(), 0, 1); + m_renderCommandEncoder.setVertexBuffer(vb.m_ptr, 0, 1); - m_renderCommandEncoder.drawIndexedPrimitives(MTLPrimitiveTypeTriangle, _numIndices, MTLIndexTypeUInt16, m_indexBuffers[_blitter.m_ib->handle.idx].getBuffer(), 0, 1); + m_renderCommandEncoder.drawIndexedPrimitives( + MTLPrimitiveTypeTriangle + , _numIndices + , MTLIndexTypeUInt16 + , m_indexBuffers[_blitter.m_ib->handle.idx].m_ptr + , 0 + , 1 + ); } } @@ -1107,11 +1368,16 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) { FrameBufferMtl& frameBuffer = ii == 0 ? m_mainFrameBuffer : m_frameBuffers[m_windows[ii].idx]; - if (NULL != frameBuffer.m_swapChain && - frameBuffer.m_swapChain->m_drawable) + if (NULL != frameBuffer.m_swapChain + && frameBuffer.m_swapChain->m_drawableTexture) { - m_commandBuffer.presentDrawable(frameBuffer.m_swapChain->m_drawable); - MTL_RELEASE(frameBuffer.m_swapChain->m_drawable); + MTL_RELEASE(frameBuffer.m_swapChain->m_drawableTexture); + + if (NULL != frameBuffer.m_swapChain->m_drawable) + { + m_commandBuffer.presentDrawable(frameBuffer.m_swapChain->m_drawable); + MTL_RELEASE(frameBuffer.m_swapChain->m_drawable); + } } } @@ -1139,9 +1405,15 @@ namespace bgfx { namespace mtl MTLPixelFormat prevMetalLayerPixelFormat = m_mainFrameBuffer.m_swapChain->m_metalLayer.pixelFormat; m_resolution = _resolution; + + if (m_resolution.reset & BGFX_RESET_INTERNAL_FORCE + && m_mainFrameBuffer.m_swapChain->m_nwh != g_platformData.nwh) + { + m_mainFrameBuffer.m_swapChain->init(g_platformData.nwh); + } m_resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; - m_mainFrameBuffer.m_swapChain->resize(m_mainFrameBuffer, _resolution.width, _resolution.height, _resolution.reset); + m_mainFrameBuffer.m_swapChain->resize(m_mainFrameBuffer, _resolution.width, _resolution.height, _resolution.reset, m_resolution.maxFrameLatency); for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii) { @@ -1157,6 +1429,7 @@ namespace bgfx { namespace mtl { MTL_RELEASE(m_screenshotBlitRenderPipelineState) reset(m_renderPipelineDescriptor); + m_renderPipelineDescriptor.colorAttachments[0].pixelFormat = m_mainFrameBuffer.m_swapChain->m_metalLayer.pixelFormat; m_renderPipelineDescriptor.vertexFunction = m_screenshotBlitProgram.m_vsh->m_function; m_renderPipelineDescriptor.fragmentFunction = m_screenshotBlitProgram.m_fsh->m_function; @@ -1165,6 +1438,14 @@ namespace bgfx { namespace mtl } } + void invalidateCompute() + { + if (m_computeCommandEncoder) + { + m_computeCommandEncoder.endEncoding(); + m_computeCommandEncoder = NULL; + } + } void updateCapture() { @@ -1220,24 +1501,37 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < g_caps.limits.maxFBAttachments; ++ii) { MTLRenderPassColorAttachmentDescriptor* desc = renderPassDescriptor.colorAttachments[ii]; + if (NULL != desc.texture) { - desc.loadAction = MTLLoadActionLoad; + desc.loadAction = MTLLoadActionLoad; + desc.storeAction = desc.resolveTexture == nil + ? MTLStoreActionStore + : MTLStoreActionMultisampleResolve + ; } } RenderPassDepthAttachmentDescriptor depthAttachment = renderPassDescriptor.depthAttachment; + if (NULL != depthAttachment.texture) { - depthAttachment.loadAction = MTLLoadActionLoad; - depthAttachment.storeAction = MTLStoreActionStore; + depthAttachment.loadAction = MTLLoadActionLoad; + depthAttachment.storeAction = depthAttachment.resolveTexture == nil + ? MTLStoreActionStore + : MTLStoreActionMultisampleResolve + ; } RenderPassStencilAttachmentDescriptor stencilAttachment = renderPassDescriptor.stencilAttachment; + if (NULL != stencilAttachment.texture) { - stencilAttachment.loadAction = MTLLoadActionLoad; - stencilAttachment.storeAction = MTLStoreActionStore; + stencilAttachment.loadAction = MTLLoadActionLoad; + stencilAttachment.storeAction = stencilAttachment.resolveTexture == nil + ? MTLStoreActionStore + : MTLStoreActionMultisampleResolve + ; } m_renderCommandEncoder = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor); @@ -1251,7 +1545,7 @@ namespace bgfx { namespace mtl { g_callback->captureEnd(); BX_FREE(g_allocator, m_capture); - m_capture = NULL; + m_capture = NULL; m_captureSize = 0; } } @@ -1259,7 +1553,7 @@ namespace bgfx { namespace mtl void setShaderUniform(uint8_t _flags, uint32_t _loc, const void* _val, uint32_t _numRegs) { - uint32_t offset = 0 != (_flags&BGFX_UNIFORM_FRAGMENTBIT) + uint32_t offset = 0 != (_flags&kUniformFragmentBit) ? m_uniformBufferFragmentOffset : m_uniformBufferVertexOffset ; @@ -1308,18 +1602,10 @@ namespace bgfx { namespace mtl data = (const char*)m_uniforms[handle.idx]; } -#define CASE_IMPLEMENT_UNIFORM(_uniform, _dxsuffix, _type) \ - case UniformType::_uniform: \ - case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \ - { \ - setShaderUniform(uint8_t(type), loc, data, num); \ - } \ - break; - switch ( (uint32_t)type) { case UniformType::Mat3: - case UniformType::Mat3|BGFX_UNIFORM_FRAGMENTBIT: + case UniformType::Mat3|kUniformFragmentBit: { float* value = (float*)data; for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3*16, value += 9) @@ -1342,9 +1628,16 @@ namespace bgfx { namespace mtl } break; - CASE_IMPLEMENT_UNIFORM(Int1, I, int); - CASE_IMPLEMENT_UNIFORM(Vec4, F, float); - CASE_IMPLEMENT_UNIFORM(Mat4, F, float); + case UniformType::Sampler: + case UniformType::Sampler | kUniformFragmentBit: + case UniformType::Vec4: + case UniformType::Vec4 | kUniformFragmentBit: + case UniformType::Mat4: + case UniformType::Mat4 | kUniformFragmentBit: + { + setShaderUniform(uint8_t(type), loc, data, num); + } + break; case UniformType::End: break; @@ -1353,29 +1646,11 @@ namespace bgfx { namespace mtl BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy); break; } - -#undef CASE_IMPLEMENT_UNIFORM - } } void clearQuad(ClearQuad& _clearQuad, const Rect& /*_rect*/, const Clear& _clear, const float _palette[][4]) { - uint32_t width; - uint32_t height; - - if (isValid(m_fbh) ) - { - const FrameBufferMtl& fb = m_frameBuffers[m_fbh.idx]; - width = fb.m_width; - height = fb.m_height; - } - else - { - width = m_resolution.width; - height = m_resolution.height; - } - uint64_t state = 0; state |= _clear.m_flags & BGFX_CLEAR_COLOR ? BGFX_STATE_WRITE_RGB|BGFX_STATE_WRITE_A : 0; state |= _clear.m_flags & BGFX_CLEAR_DEPTH ? BGFX_STATE_DEPTH_TEST_ALWAYS|BGFX_STATE_WRITE_Z : 0; @@ -1395,45 +1670,56 @@ namespace bgfx { namespace mtl uint32_t numMrt = 1; FrameBufferHandle fbh = m_fbh; - if (isValid(fbh) ) + if (isValid(fbh) && m_frameBuffers[fbh.idx].m_swapChain == NULL) { const FrameBufferMtl& fb = m_frameBuffers[fbh.idx]; numMrt = bx::uint32_max(1, fb.m_num); } - const ProgramMtl& program = m_program[_clearQuad.m_program[numMrt-1].idx]; - RenderPipelineState pso = getPipelineState( + const VertexLayout* layout = &_clearQuad.m_layout; + const PipelineStateMtl* pso = getPipelineState( state , 0 , fbh - , _clearQuad.m_vb->decl - , _clearQuad.m_program[numMrt-1].idx + , 1 + , &layout + , _clearQuad.m_program[numMrt-1] , 0 ); - m_renderCommandEncoder.setRenderPipelineState(pso); + m_renderCommandEncoder.setRenderPipelineState(pso->m_rps); - uint32_t fragmentUniformBufferSize = program.m_fshConstantBufferSize; + const uint32_t vertexUniformBufferSize = pso->m_vshConstantBufferSize; + const uint32_t fragmentUniformBufferSize = pso->m_fshConstantBufferSize; - m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset; + if (0 != vertexUniformBufferSize) + { + m_uniformBufferVertexOffset = bx::alignUp( + m_uniformBufferVertexOffset + , pso->m_vshConstantBufferAlignment + ); + m_renderCommandEncoder.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0); + } + + m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize; if (fragmentUniformBufferSize) { - m_uniformBufferFragmentOffset = BX_ALIGN_MASK(m_uniformBufferFragmentOffset, program.m_fshConstantBufferAlignmentMask); + m_uniformBufferFragmentOffset = bx::alignUp( + m_uniformBufferFragmentOffset + , pso->m_fshConstantBufferAlignment + ); m_renderCommandEncoder.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0); } + float mrtClearColor[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; + float mrtClearDepth[4] = { _clear.m_depth }; + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { - float mrtClear[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - bx::memCopy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClearColor[ii], _palette[index], 16); } - - bx::memCopy( (uint8_t*)m_uniformBuffer.contents() + m_uniformBufferFragmentOffset - , mrtClear - , bx::uint32_min(fragmentUniformBufferSize, sizeof(mrtClear) ) - ); } else { @@ -1445,87 +1731,96 @@ namespace bgfx { namespace mtl _clear.m_index[3]*1.0f/255.0f, }; - bx::memCopy( (uint8_t*)m_uniformBuffer.contents() + m_uniformBufferFragmentOffset - , rgba - , bx::uint32_min(fragmentUniformBufferSize, sizeof(rgba) ) - ); + for (uint32_t ii = 0; ii < numMrt; ++ii) + { + bx::memCopy(mrtClearColor[ii], rgba, 16); + } } - m_uniformBufferFragmentOffset += fragmentUniformBufferSize; - m_uniformBufferVertexOffset = m_uniformBufferFragmentOffset; + bx::memCopy( + (uint8_t*)m_uniformBuffer.contents() + m_uniformBufferVertexOffset + , mrtClearDepth + , bx::uint32_min(vertexUniformBufferSize, sizeof(mrtClearDepth) ) + ); - const VertexBufferMtl& vb = m_vertexBuffers[_clearQuad.m_vb->handle.idx]; - const VertexDecl& vertexDecl = m_vertexDecls[_clearQuad.m_vb->decl.idx]; - const uint32_t stride = vertexDecl.m_stride; - const uint32_t offset = 0; + bx::memCopy( + (uint8_t*)m_uniformBuffer.contents() + m_uniformBufferFragmentOffset + , mrtClearColor + , bx::uint32_min(fragmentUniformBufferSize, sizeof(mrtClearColor) ) + ); - { - struct Vertex - { - float m_x; - float m_y; - float m_z; - }; + m_uniformBufferFragmentOffset += fragmentUniformBufferSize; + m_uniformBufferVertexOffset = m_uniformBufferFragmentOffset; - Vertex* vertex = (Vertex*)_clearQuad.m_vb->data; - BX_CHECK(stride == sizeof(Vertex) - , "Stride/Vertex mismatch (stride %d, sizeof(Vertex) %d)" - , stride - , sizeof(Vertex) - ); - BX_UNUSED(stride); - - const float depth = _clear.m_depth; - - vertex->m_x = -1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = -1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = -1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - vertex++; - vertex->m_x = 1.0f; - vertex->m_y = 1.0f; - vertex->m_z = depth; - } + const VertexBufferMtl& vb = m_vertexBuffers[_clearQuad.m_vb.idx]; - m_vertexBuffers[_clearQuad.m_vb->handle.idx].update(0, 4*_clearQuad.m_decl.m_stride, _clearQuad.m_vb->data); m_renderCommandEncoder.setCullMode(MTLCullModeNone); - m_renderCommandEncoder.setVertexBuffer(vb.getBuffer(), offset, 1); + m_renderCommandEncoder.setVertexBuffer(vb.m_ptr, 0, 1); m_renderCommandEncoder.drawPrimitives(MTLPrimitiveTypeTriangleStrip, 0, 4, 1); } - void setFrameBuffer(RenderPassDescriptor renderPassDescriptor, FrameBufferHandle _fbh, bool _msaa = true) + void setAttachment(MTLRenderPassAttachmentDescriptor* _attachmentDescriptor, const Attachment& _at, uint8_t _textureType, bool _resolve) { - if (!isValid(_fbh) || m_frameBuffers[_fbh.idx].m_swapChain) + _attachmentDescriptor.level = _at.mip; + + if (TextureMtl::Texture3D == _textureType) + { + _attachmentDescriptor.depthPlane = _at.layer; + } + else { - SwapChainMtl* swapChain = - !isValid(_fbh) ? - m_mainFrameBuffer.m_swapChain : - m_frameBuffers[_fbh.idx].m_swapChain; - if (NULL != m_backBufferColorMsaa) + _attachmentDescriptor.slice = _at.layer; + } + + if (_resolve) + { + _attachmentDescriptor.resolveLevel = _at.mip; + + if (TextureMtl::Texture3D == _textureType) + { + _attachmentDescriptor.resolveDepthPlane = _at.layer; + } + else + { + _attachmentDescriptor.resolveSlice = _at.layer; + } + } + } + + void setFrameBuffer(RenderPassDescriptor _renderPassDescriptor, FrameBufferHandle _fbh, bool _msaa = true) + { + // resolve framebuffer + if (isValid(m_fbh) && m_fbh.idx != _fbh.idx) + { + FrameBufferMtl& frameBuffer = m_frameBuffers[m_fbh.idx]; + frameBuffer.resolve(); + } + if (!isValid(_fbh) + || m_frameBuffers[_fbh.idx].m_swapChain) + { + SwapChainMtl* swapChain = !isValid(_fbh) + ? m_mainFrameBuffer.m_swapChain + : m_frameBuffers[_fbh.idx].m_swapChain + ; + + if (NULL != swapChain->m_backBufferColorMsaa) { - renderPassDescriptor.colorAttachments[0].texture = swapChain->m_backBufferColorMsaa; - renderPassDescriptor.colorAttachments[0].resolveTexture = NULL != m_screenshotTarget + _renderPassDescriptor.colorAttachments[0].texture = swapChain->m_backBufferColorMsaa; + _renderPassDescriptor.colorAttachments[0].resolveTexture = NULL != m_screenshotTarget ? m_screenshotTarget.m_obj - : swapChain->currentDrawable().texture + : swapChain->currentDrawableTexture() ; } else { - renderPassDescriptor.colorAttachments[0].texture = NULL != m_screenshotTarget + _renderPassDescriptor.colorAttachments[0].texture = NULL != m_screenshotTarget ? m_screenshotTarget.m_obj - : swapChain->currentDrawable().texture + : swapChain->currentDrawableTexture() ; } - renderPassDescriptor.depthAttachment.texture = swapChain->m_backBufferDepth; - renderPassDescriptor.stencilAttachment.texture = swapChain->m_backBufferStencil; + _renderPassDescriptor.depthAttachment.texture = swapChain->m_backBufferDepth; + _renderPassDescriptor.stencilAttachment.texture = swapChain->m_backBufferStencil; } else { @@ -1534,35 +1829,40 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < frameBuffer.m_num; ++ii) { const TextureMtl& texture = m_textures[frameBuffer.m_colorHandle[ii].idx]; - renderPassDescriptor.colorAttachments[ii].texture = texture.m_ptrMsaa + _renderPassDescriptor.colorAttachments[ii].texture = texture.m_ptrMsaa ? texture.m_ptrMsaa : texture.m_ptr ; - renderPassDescriptor.colorAttachments[ii].resolveTexture = texture.m_ptrMsaa + _renderPassDescriptor.colorAttachments[ii].resolveTexture = texture.m_ptrMsaa ? texture.m_ptr.m_obj : NULL ; + + setAttachment(_renderPassDescriptor.colorAttachments[ii], frameBuffer.m_colorAttachment[ii], texture.m_type, texture.m_ptrMsaa != NULL); } if (isValid(frameBuffer.m_depthHandle) ) { const TextureMtl& texture = m_textures[frameBuffer.m_depthHandle.idx]; - renderPassDescriptor.depthAttachment.texture = texture.m_ptrMsaa + _renderPassDescriptor.depthAttachment.texture = texture.m_ptrMsaa ? texture.m_ptrMsaa : texture.m_ptr ; - renderPassDescriptor.stencilAttachment.texture = texture.m_ptrStencil; + _renderPassDescriptor.stencilAttachment.texture = texture.m_ptrStencil; + + setAttachment(_renderPassDescriptor.depthAttachment, frameBuffer.m_depthAttachment, texture.m_type, NULL != texture.m_ptrMsaa); + setAttachment(_renderPassDescriptor.stencilAttachment, frameBuffer.m_depthAttachment, texture.m_type, NULL != texture.m_ptrMsaa); if (texture.m_textureFormat == TextureFormat::D24S8) { if (texture.m_ptr.pixelFormat() == 255 /* Depth24Unorm_Stencil8 */ || texture.m_ptr.pixelFormat() == 260 /* Depth32Float_Stencil8 */) { - renderPassDescriptor.stencilAttachment.texture = renderPassDescriptor.depthAttachment.texture; + _renderPassDescriptor.stencilAttachment.texture = _renderPassDescriptor.depthAttachment.texture; } else { - renderPassDescriptor.stencilAttachment.texture = texture.m_ptrMsaa + _renderPassDescriptor.stencilAttachment.texture = texture.m_ptrMsaa ? texture.m_ptrMsaa : texture.m_ptrStencil ; @@ -1617,10 +1917,10 @@ namespace bgfx { namespace mtl frontFaceDesc.readMask = readMask; frontFaceDesc.writeMask = writeMask; - backfaceDesc.stencilFailureOperation = s_stencilOp[(bstencil&BGFX_STENCIL_OP_FAIL_S_MASK)>>BGFX_STENCIL_OP_FAIL_S_SHIFT]; - backfaceDesc.depthFailureOperation = s_stencilOp[(bstencil&BGFX_STENCIL_OP_FAIL_Z_MASK)>>BGFX_STENCIL_OP_FAIL_Z_SHIFT]; - backfaceDesc.depthStencilPassOperation = s_stencilOp[(bstencil&BGFX_STENCIL_OP_PASS_Z_MASK)>>BGFX_STENCIL_OP_PASS_Z_SHIFT]; - backfaceDesc.stencilCompareFunction = s_cmpFunc[(bstencil&BGFX_STENCIL_TEST_MASK)>>BGFX_STENCIL_TEST_SHIFT]; + backfaceDesc.stencilFailureOperation = s_stencilOp[(bstencil&BGFX_STENCIL_OP_FAIL_S_MASK)>>BGFX_STENCIL_OP_FAIL_S_SHIFT]; + backfaceDesc.depthFailureOperation = s_stencilOp[(bstencil&BGFX_STENCIL_OP_FAIL_Z_MASK)>>BGFX_STENCIL_OP_FAIL_Z_SHIFT]; + backfaceDesc.depthStencilPassOperation = s_stencilOp[(bstencil&BGFX_STENCIL_OP_PASS_Z_MASK)>>BGFX_STENCIL_OP_PASS_Z_SHIFT]; + backfaceDesc.stencilCompareFunction = s_cmpFunc[(bstencil&BGFX_STENCIL_TEST_MASK)>>BGFX_STENCIL_TEST_SHIFT]; backfaceDesc.readMask = readMask; backfaceDesc.writeMask = writeMask; @@ -1642,13 +1942,169 @@ namespace bgfx { namespace mtl m_renderCommandEncoder.setStencilReferenceValue(ref); } - RenderPipelineState getPipelineState( + void processArguments( + PipelineStateMtl* ps + , NSArray <MTLArgument *>* _vertexArgs + , NSArray <MTLArgument *>* _fragmentArgs + ) + { + ps->m_numPredefined = 0; + + for (uint32_t shaderType = 0; shaderType < 2; ++shaderType) + { + UniformBuffer*& constantBuffer = shaderType == 0 + ? ps->m_vshConstantBuffer + : ps->m_fshConstantBuffer + ; + const int8_t fragmentBit = (1 == shaderType ? kUniformFragmentBit : 0); + + for (MTLArgument* arg in (shaderType == 0 ? _vertexArgs : _fragmentArgs) ) + { + BX_TRACE("arg: %s type:%d", utf8String(arg.name), arg.type); + + if (arg.active) + { + if (arg.type == MTLArgumentTypeBuffer + && 0 == bx::strCmp(utf8String(arg.name), SHADER_UNIFORM_NAME) ) + { + BX_ASSERT(arg.index == 0, "Uniform buffer must be in the buffer slot 0."); + BX_ASSERT(MTLDataTypeStruct == arg.bufferDataType, "%s's type must be a struct",SHADER_UNIFORM_NAME ); + + if (MTLDataTypeStruct == arg.bufferDataType) + { + if (shaderType == 0) + { + ps->m_vshConstantBufferSize = uint32_t(arg.bufferDataSize); + ps->m_vshConstantBufferAlignment = uint32_t(arg.bufferAlignment); + } + else + { + ps->m_fshConstantBufferSize = uint32_t(arg.bufferDataSize); + ps->m_fshConstantBufferAlignment = uint32_t(arg.bufferAlignment); + } + + for (MTLStructMember* uniform in arg.bufferStructType.members ) + { + const char* name = utf8String(uniform.name); + BX_TRACE("uniform: %s type:%d", name, uniform.dataType); + + MTLDataType dataType = uniform.dataType; + uint32_t num = 1; + + if (dataType == MTLDataTypeArray) + { + dataType = uniform.arrayType.elementType; + num = (uint32_t)uniform.arrayType.arrayLength; + } + + switch (dataType) + { + case MTLDataTypeFloat4: num *= 1; break; + case MTLDataTypeFloat4x4: num *= 4; break; + case MTLDataTypeFloat3x3: num *= 3; break; + + default: + BX_WARN(0, "Unsupported uniform MTLDataType: %d", uniform.dataType); + break; + } + + const PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name); + + if (PredefinedUniform::Count != predefined) + { + ps->m_predefined[ps->m_numPredefined].m_loc = uint32_t(uniform.offset); + ps->m_predefined[ps->m_numPredefined].m_count = uint16_t(num); + ps->m_predefined[ps->m_numPredefined].m_type = uint8_t(predefined|fragmentBit); + ++ps->m_numPredefined; + } + else + { + const UniformRegInfo* info = s_renderMtl->m_uniformReg.find(name); + BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); + + if (NULL != info) + { + if (NULL == constantBuffer) + { + constantBuffer = UniformBuffer::create(1024); + } + + UniformType::Enum type = convertMtlType(dataType); + constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), uint32_t(uniform.offset), info->m_handle, uint16_t(num) ); + BX_TRACE("store %s %d offset:%d", name, info->m_handle, uint32_t(uniform.offset) ); + } + } + } + } + } + else if (arg.type == MTLArgumentTypeBuffer + && arg.index > 0 + && NULL != arg.bufferStructType) + { + const char* name = utf8String(arg.name); + BX_UNUSED(name); + + if (arg.index >= BGFX_CONFIG_MAX_TEXTURE_SAMPLERS) + { + BX_TRACE( + "Binding index is too large %d max is %d. " + "User defined uniform '%s' won't be set." + , int32_t(arg.index - 1) + , BGFX_CONFIG_MAX_TEXTURE_SAMPLERS - 1 + , name + ); + } + else + { + ps->m_bindingTypes[arg.index-1] = fragmentBit + ? PipelineStateMtl::BindToFragmentShader + : PipelineStateMtl::BindToVertexShader + ; + BX_TRACE("Buffer %s index: %d", name, int32_t(arg.index-1) ); + } + } + else if (arg.type == MTLArgumentTypeTexture) + { + const char* name = utf8String(arg.name); + if (arg.index >= BGFX_CONFIG_MAX_TEXTURE_SAMPLERS) + { + BX_WARN(false, "Binding index is too large %d max is %d. User defined uniform '%s' won't be set.", int(arg.index), BGFX_CONFIG_MAX_TEXTURE_SAMPLERS - 1, name); + } + else + { + ps->m_bindingTypes[arg.index] = fragmentBit ? PipelineStateMtl::BindToFragmentShader : PipelineStateMtl::BindToVertexShader; + const UniformRegInfo* info = s_renderMtl->m_uniformReg.find(name); + if (info) + { + BX_TRACE("texture %s %d index:%d", name, info->m_handle, uint32_t(arg.index) ); + } + else + { + BX_TRACE("image %s index:%d", name, uint32_t(arg.index) ); + } + } + } + else if (arg.type == MTLArgumentTypeSampler) + { + BX_TRACE("sampler: %s index:%d", utf8String(arg.name), arg.index); + } + } + } + + if (NULL != constantBuffer) + { + constantBuffer->finish(); + } + } + } + + PipelineStateMtl* getPipelineState( uint64_t _state , uint32_t _rgba , FrameBufferHandle _fbh , uint8_t _numStreams - , const VertexDecl** _vertexDecls - , uint16_t _programIdx + , const VertexLayout** _layouts + , ProgramHandle _program , uint8_t _numInstanceData ) { @@ -1663,7 +2119,7 @@ namespace bgfx { namespace mtl ); const bool independentBlendEnable = !!(BGFX_STATE_BLEND_INDEPENDENT & _state); - ProgramMtl& program = m_program[_programIdx]; + const ProgramMtl& program = m_program[_program.idx]; bx::HashMurmur2A murmur; murmur.begin(); @@ -1673,7 +2129,7 @@ namespace bgfx { namespace mtl if (!isValid(_fbh) ) { - murmur.add(m_backBufferPixelFormatHash); + murmur.add(m_mainFrameBuffer.m_pixelFormatHash); } else { @@ -1689,14 +2145,17 @@ namespace bgfx { namespace mtl for (uint8_t ii = 0; ii < _numStreams; ++ii) { - murmur.add(_vertexDecls[ii]->m_hash); + murmur.add(_layouts[ii]->m_hash); } uint32_t hash = murmur.end(); - RenderPipelineState pso = m_pipelineStateCache.find(hash); + PipelineStateMtl* pso = m_pipelineStateCache.find(hash); + if (NULL == pso) { + pso = BX_NEW(g_allocator, PipelineStateMtl); + RenderPipelineDescriptor pd = m_renderPipelineDescriptor; reset(pd); @@ -1704,14 +2163,18 @@ namespace bgfx { namespace mtl uint32_t frameBufferAttachment = 1; - if (!isValid(_fbh) || s_renderMtl->m_frameBuffers[_fbh.idx].m_swapChain) + if (!isValid(_fbh) + || s_renderMtl->m_frameBuffers[_fbh.idx].m_swapChain) { - SwapChainMtl* swapChain = - !isValid(_fbh) ? - s_renderMtl->m_mainFrameBuffer.m_swapChain : - s_renderMtl->m_frameBuffers[_fbh.idx].m_swapChain; - pd.sampleCount = NULL != swapChain->m_backBufferColorMsaa ? swapChain->m_backBufferColorMsaa.sampleCount() : 1; - pd.colorAttachments[0].pixelFormat = swapChain->currentDrawable().texture.pixelFormat; + SwapChainMtl* swapChain = !isValid(_fbh) + ? s_renderMtl->m_mainFrameBuffer.m_swapChain + : s_renderMtl->m_frameBuffers[_fbh.idx].m_swapChain + ; + pd.sampleCount = NULL != swapChain->m_backBufferColorMsaa + ? swapChain->m_backBufferColorMsaa.sampleCount() + : 1 + ; + pd.colorAttachments[0].pixelFormat = swapChain->currentDrawableTexture().pixelFormat; pd.depthAttachmentPixelFormat = swapChain->m_backBufferDepth.m_obj.pixelFormat; pd.stencilAttachmentPixelFormat = swapChain->m_backBufferStencil.m_obj.pixelFormat; } @@ -1734,6 +2197,10 @@ namespace bgfx { namespace mtl { const TextureMtl& texture = m_textures[frameBuffer.m_depthHandle.idx]; pd.depthAttachmentPixelFormat = texture.m_ptr.m_obj.pixelFormat; + pd.sampleCount = NULL != texture.m_ptrMsaa + ? texture.m_ptrMsaa.sampleCount() + : 1 + ; if (NULL != texture.m_ptrStencil) { pd.stencilAttachmentPixelFormat = texture.m_ptrStencil.m_obj.pixelFormat; @@ -1817,33 +2284,38 @@ namespace bgfx { namespace mtl uint8_t stream = 0; for (; stream < _numStreams; ++stream) { - const VertexDecl& vertexDecl = *_vertexDecls[stream]; + const VertexLayout& layout = *_layouts[stream]; + bool streamUsed = false; for (uint32_t ii = 0; Attrib::Count != program.m_used[ii]; ++ii) { Attrib::Enum attr = Attrib::Enum(program.m_used[ii]); + if (attrSet[attr]) + continue; const uint32_t loc = program.m_attributes[attr]; uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - vertexDecl.decode(attr, num, type, normalized, asInt); - BX_CHECK(num <= 4, "num must be <= 4"); + layout.decode(attr, num, type, normalized, asInt); + BX_ASSERT(num <= 4, "num must be <= 4"); - if (UINT16_MAX != vertexDecl.m_attributes[attr]) + if (UINT16_MAX != layout.m_attributes[attr]) { vertexDesc.attributes[loc].format = s_attribType[type][num-1][normalized?1:0]; vertexDesc.attributes[loc].bufferIndex = stream+1; - vertexDesc.attributes[loc].offset = vertexDecl.m_offset[attr]; + vertexDesc.attributes[loc].offset = layout.m_offset[attr]; BX_TRACE("attrib: %s format: %d offset: %d", s_attribName[attr], (int)vertexDesc.attributes[loc].format, (int)vertexDesc.attributes[loc].offset); attrSet[attr] = true; + streamUsed = true; } } - - vertexDesc.layouts[stream+1].stride = vertexDecl.getStride(); - vertexDesc.layouts[stream+1].stepFunction = MTLVertexStepFunctionPerVertex; + if (streamUsed) { + vertexDesc.layouts[stream+1].stride = layout.getStride(); + vertexDesc.layouts[stream+1].stepFunction = MTLVertexStepFunctionPerVertex; + } } for (uint32_t ii = 0; Attrib::Count != program.m_used[ii]; ++ii) @@ -1875,169 +2347,66 @@ namespace bgfx { namespace mtl pd.vertexDescriptor = vertexDesc; - if (program.m_processedUniforms) - { - pso = m_device.newRenderPipelineStateWithDescriptor(pd); - } - else { - program.m_numPredefined = 0; RenderPipelineReflection reflection = NULL; - pso = m_device.newRenderPipelineStateWithDescriptor(pd, MTLPipelineOptionBufferTypeInfo, &reflection); + pso->m_rps = m_device.newRenderPipelineStateWithDescriptor(pd, MTLPipelineOptionBufferTypeInfo, &reflection); if (NULL != reflection) { - for (uint32_t shaderType = 0; shaderType < 2; ++shaderType) - { - UniformBuffer*& constantBuffer = shaderType == 0 - ? program.m_vshConstantBuffer - : program.m_fshConstantBuffer - ; - uint8_t fragmentBit = (1 == shaderType ? BGFX_UNIFORM_FRAGMENTBIT : 0); - - for (MTLArgument* arg in (shaderType == 0 ? reflection.vertexArguments : reflection.fragmentArguments) ) - { - BX_TRACE("arg: %s type:%d", utf8String(arg.name), arg.type); - if (arg.active) - { - if (arg.type == MTLArgumentTypeBuffer - && 0 == bx::strCmp(utf8String(arg.name), SHADER_UNIFORM_NAME) ) - { - BX_CHECK( arg.index == 0, "Uniform buffer must be in the buffer slot 0."); - BX_CHECK( MTLDataTypeStruct == arg.bufferDataType, "%s's type must be a struct",SHADER_UNIFORM_NAME ); - - if (MTLDataTypeStruct == arg.bufferDataType) - { - if (shaderType == 0) - { - program.m_vshConstantBufferSize = (uint32_t)arg.bufferDataSize; - program.m_vshConstantBufferAlignmentMask = (uint32_t)arg.bufferAlignment - 1; - } - else - { - program.m_fshConstantBufferSize = (uint32_t)arg.bufferDataSize; - program.m_fshConstantBufferAlignmentMask = (uint32_t)arg.bufferAlignment - 1; - } - - for (MTLStructMember* uniform in arg.bufferStructType.members ) - { - const char* name = utf8String(uniform.name); - BX_TRACE("uniform: %s type:%d", name, uniform.dataType); - - MTLDataType dataType = uniform.dataType; - uint32_t num = 1; - - if (dataType == MTLDataTypeArray) - { - dataType = uniform.arrayType.elementType; - num = (uint32_t)uniform.arrayType.arrayLength; - } - - switch (dataType) - { - case MTLDataTypeFloat4: num *= 1; break; - case MTLDataTypeFloat4x4: num *= 4; break; - case MTLDataTypeFloat3x3: num *= 3; break; - - default: - BX_WARN(0, "Unsupported uniform MTLDataType: %d", uniform.dataType); - break; - } - - PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name); - if (PredefinedUniform::Count != predefined) - { - program.m_predefined[program.m_numPredefined].m_loc = uint32_t(uniform.offset); - program.m_predefined[program.m_numPredefined].m_count = uint16_t(num); - program.m_predefined[program.m_numPredefined].m_type = uint8_t(predefined|fragmentBit); - ++program.m_numPredefined; - } - else - { - const UniformRegInfo* info = m_uniformReg.find(name); - BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); - - if (NULL != info) - { - if (NULL == constantBuffer) - { - constantBuffer = UniformBuffer::create(1024); - } - - UniformType::Enum type = convertMtlType(dataType); - constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), uint32_t(uniform.offset), info->m_handle, uint16_t(num) ); - BX_TRACE("store %s %d offset:%d", name, info->m_handle, uint32_t(uniform.offset) ); - } - } - } - } - } - else if (arg.type == MTLArgumentTypeTexture) - { - const char* name = utf8String(arg.name); - const UniformRegInfo* info = m_uniformReg.find(name); - BX_WARN(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); - - if (NULL != info) - { - if (program.m_samplerCount >= BGFX_CONFIG_MAX_TEXTURE_SAMPLERS) - { - BX_WARN(NULL != info, "Too many samplers in shader(only %d is supported). User defined uniform '%s' won't be set.", BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, name); - } - else - { - program.m_samplers[program.m_samplerCount].m_index = uint32_t(arg.index); - program.m_samplers[program.m_samplerCount].m_uniform = info->m_handle; - program.m_samplers[program.m_samplerCount].m_fragment = fragmentBit ? 1 : 0; - ++program.m_samplerCount; - BX_TRACE("texture %s %d index:%d", name, info->m_handle, uint32_t(arg.index) ); - } - } - } - else if (arg.type == MTLArgumentTypeSampler) - { - BX_TRACE("sampler: %s index:%d", utf8String(arg.name), arg.index); - } - } - } - - if (NULL != constantBuffer) - { - constantBuffer->finish(); - } - } + processArguments(pso, reflection.vertexArguments, reflection.fragmentArguments); } - - program.m_processedUniforms = true; } m_pipelineStateCache.add(hash, pso); + m_pipelineProgram.push_back({hash, _program}); } return pso; } - RenderPipelineState getPipelineState( + PipelineStateMtl* getPipelineState( uint64_t _state , uint32_t _rgba , FrameBufferHandle _fbh - , VertexDeclHandle _declHandle - , uint16_t _programIdx + , VertexLayoutHandle _layoutHandle + , ProgramHandle _program , uint16_t _numInstanceData ) { - const VertexDecl* decl = &m_vertexDecls[_declHandle.idx]; + const VertexLayout* layout = &m_vertexLayouts[_layoutHandle.idx]; return getPipelineState( _state , _rgba , _fbh , 1 - , &decl - , _programIdx + , &layout + , _program , _numInstanceData ); } + PipelineStateMtl* getComputePipelineState(ProgramHandle _program) + { + ProgramMtl& program = m_program[_program.idx]; + + if (NULL == program.m_computePS) + { + PipelineStateMtl* pso = BX_NEW(g_allocator, PipelineStateMtl); + program.m_computePS = pso; + + ComputePipelineReflection reflection = NULL; + pso->m_cps = m_device.newComputePipelineStateWithFunction(program.m_vsh->m_function, MTLPipelineOptionBufferTypeInfo, &reflection); + processArguments(pso, reflection.arguments, NULL); + + for (uint32_t ii = 0; ii < 3; ++ii) + { + pso->m_numThreads[ii] = program.m_vsh->m_numThreads[ii]; + } + } + + return program.m_computePS; + } + SamplerState getSamplerState(uint32_t _flags) { _flags &= BGFX_SAMPLER_BITS_MASK; @@ -2045,20 +2414,19 @@ namespace bgfx { namespace mtl if (NULL == sampler) { - m_samplerDescriptor.sAddressMode = s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT]; m_samplerDescriptor.tAddressMode = s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT]; m_samplerDescriptor.rAddressMode = s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT]; - m_samplerDescriptor.minFilter = s_textureFilterMinMag[(_flags&BGFX_SAMPLER_MIN_MASK)>>BGFX_SAMPLER_MIN_SHIFT]; - m_samplerDescriptor.magFilter = s_textureFilterMinMag[(_flags&BGFX_SAMPLER_MAG_MASK)>>BGFX_SAMPLER_MAG_SHIFT]; - m_samplerDescriptor.mipFilter = s_textureFilterMip[(_flags&BGFX_SAMPLER_MIP_MASK)>>BGFX_SAMPLER_MIP_SHIFT]; - m_samplerDescriptor.lodMinClamp = 0; - m_samplerDescriptor.lodMaxClamp = FLT_MAX; + m_samplerDescriptor.minFilter = s_textureFilterMinMag[(_flags&BGFX_SAMPLER_MIN_MASK)>>BGFX_SAMPLER_MIN_SHIFT]; + m_samplerDescriptor.magFilter = s_textureFilterMinMag[(_flags&BGFX_SAMPLER_MAG_MASK)>>BGFX_SAMPLER_MAG_SHIFT]; + m_samplerDescriptor.mipFilter = s_textureFilterMip[(_flags&BGFX_SAMPLER_MIP_MASK)>>BGFX_SAMPLER_MIP_SHIFT]; + m_samplerDescriptor.lodMinClamp = 0; + m_samplerDescriptor.lodMaxClamp = FLT_MAX; m_samplerDescriptor.normalizedCoordinates = TRUE; m_samplerDescriptor.maxAnisotropy = (0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) ) ) ? m_mainFrameBuffer.m_swapChain->m_maxAnisotropy : 1; if (m_macOS11Runtime - || [m_device supportsFeatureSet:(MTLFeatureSet)4 /*MTLFeatureSet_iOS_GPUFamily3_v1*/]) + || [m_device supportsFeatureSet:(MTLFeatureSet)4 /*MTLFeatureSet_iOS_GPUFamily3_v1*/]) { const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT; m_samplerDescriptor.compareFunction = 0 == cmpFunc @@ -2082,9 +2450,11 @@ namespace bgfx { namespace mtl BlitCommandEncoder getBlitCommandEncoder() { - if (m_blitCommandEncoder == NULL) + if (NULL == m_blitCommandEncoder) { - if (m_commandBuffer == NULL) + endEncoding(); + + if (NULL == m_commandBuffer) { m_commandBuffer = m_cmd.alloc(); } @@ -2095,15 +2465,25 @@ namespace bgfx { namespace mtl return m_blitCommandEncoder; } - id<CAMetalDrawable> currentDrawable() + void endEncoding() { - if (m_drawable == nil) + if (0 != m_renderCommandEncoder) { - m_drawable = m_metalLayer.nextDrawable; - retain(m_drawable); // keep alive to be useable at 'flip' + m_renderCommandEncoder.endEncoding(); + m_renderCommandEncoder = 0; + } + + if (0 != m_computeCommandEncoder) + { + m_computeCommandEncoder.endEncoding(); + m_computeCommandEncoder = 0; } - return m_drawable; + if (0 != m_blitCommandEncoder) + { + m_blitCommandEncoder.endEncoding(); + m_blitCommandEncoder = 0; + } } Device m_device; @@ -2111,19 +2491,13 @@ namespace bgfx { namespace mtl TimerQueryMtl m_gpuTimer; CommandQueueMtl m_cmd; - CAMetalLayer* m_metalLayer; - Texture m_backBufferColorMsaa; - Texture m_backBufferDepth; - Texture m_backBufferStencil; - uint32_t m_backBufferPixelFormatHash; - uint32_t m_maxAnisotropy; - bool m_iOS9Runtime; bool m_macOS11Runtime; bool m_hasPixelFormatDepth32Float_Stencil8; + bool m_hasStoreActionStoreAndMultisampleResolve; Buffer m_uniformBuffer; - Buffer m_uniformBuffers[MTL_MAX_FRAMES_IN_FLIGHT]; + Buffer m_uniformBuffers[BGFX_CONFIG_MAX_FRAME_LATENCY]; uint32_t m_uniformBufferVertexOffset; uint32_t m_uniformBufferFragmentOffset; @@ -2139,13 +2513,23 @@ namespace bgfx { namespace mtl TextureMtl m_textures[BGFX_CONFIG_MAX_TEXTURES]; FrameBufferMtl m_mainFrameBuffer; FrameBufferMtl m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; - VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS]; + VertexLayout m_vertexLayouts[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; UniformRegistry m_uniformReg; void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; - StateCacheT<RenderPipelineState> m_pipelineStateCache; - StateCacheT<DepthStencilState> m_depthStencilStateCache; - StateCacheT<SamplerState> m_samplerStateCache; + struct PipelineProgram + { + uint64_t key; + ProgramHandle program; + }; + + typedef stl::vector<PipelineProgram> PipelineProgramArray; + + PipelineProgramArray m_pipelineProgram; + + StateCacheT<PipelineStateMtl*> m_pipelineStateCache; + StateCacheT<DepthStencilState> m_depthStencilStateCache; + StateCacheT<SamplerState> m_samplerStateCache; TextVideoMem m_textVideoMem; @@ -2166,19 +2550,17 @@ namespace bgfx { namespace mtl SamplerDescriptor m_samplerDescriptor; // currently active objects data - id <CAMetalDrawable> m_drawable; - bool m_saveScreenshot; Texture m_screenshotTarget; ShaderMtl m_screenshotBlitProgramVsh; ShaderMtl m_screenshotBlitProgramFsh; ProgramMtl m_screenshotBlitProgram; RenderPipelineState m_screenshotBlitRenderPipelineState; - CommandBuffer m_commandBuffer; - CommandBuffer m_prevCommandBuffer; - BlitCommandEncoder m_blitCommandEncoder; - RenderCommandEncoder m_renderCommandEncoder; - FrameBufferHandle m_renderCommandEncoderFrameBufferHandle; + CommandBuffer m_commandBuffer; + BlitCommandEncoder m_blitCommandEncoder; + RenderCommandEncoder m_renderCommandEncoder; + ComputeCommandEncoder m_computeCommandEncoder; + FrameBufferHandle m_renderCommandEncoderFrameBufferHandle; }; RendererContextI* rendererCreate(const Init& _init) @@ -2201,18 +2583,20 @@ namespace bgfx { namespace mtl void writeString(bx::WriterI* _writer, const char* _str) { - bx::write(_writer, _str, (int32_t)bx::strLen(_str) ); + bx::write(_writer, _str, (int32_t)bx::strLen(_str), bx::ErrorAssert{}); } void ShaderMtl::create(const Memory* _mem) { bx::MemoryReader reader(_mem->data, _mem->size); + bx::ErrorAssert err; + uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, &err); uint32_t hashIn; - bx::read(&reader, hashIn); + bx::read(&reader, hashIn, &err); uint32_t hashOut; @@ -2222,11 +2606,11 @@ namespace bgfx { namespace mtl } else { - bx::read(&reader, hashOut); + bx::read(&reader, hashOut, &err); } uint16_t count; - bx::read(&reader, count); + bx::read(&reader, count, &err); BX_TRACE("%s Shader consts %d" , getShaderTypeName(magic) @@ -2236,27 +2620,47 @@ namespace bgfx { namespace mtl for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize; - bx::read(&reader, nameSize); + bx::read(&reader, nameSize, &err); char name[256]; - bx::read(&reader, &name, nameSize); + bx::read(&reader, &name, nameSize, &err); name[nameSize] = '\0'; uint8_t type; - bx::read(&reader, type); + bx::read(&reader, type, &err); uint8_t num; - bx::read(&reader, num); + bx::read(&reader, num, &err); uint16_t regIndex; - bx::read(&reader, regIndex); + bx::read(&reader, regIndex, &err); uint16_t regCount; - bx::read(&reader, regCount); + bx::read(&reader, regCount, &err); + + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo = 0; + bx::read(&reader, texInfo, &err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(&reader, texFormat, &err); + } + } + + if (isShaderType(magic, 'C') ) + { + for (uint32_t ii = 0; ii < 3; ++ii) + { + bx::read(&reader, m_numThreads[ii], &err); + } } uint32_t shaderSize; - bx::read(&reader, shaderSize); + bx::read(&reader, shaderSize, &err); const char* code = (const char*)reader.getDataPtr(); bx::skip(&reader, shaderSize+1); @@ -2287,7 +2691,7 @@ namespace bgfx { namespace mtl void ProgramMtl::create(const ShaderMtl* _vsh, const ShaderMtl* _fsh) { - BX_CHECK(NULL != _vsh->m_function.m_obj, "Vertex shader doesn't exist."); + BX_ASSERT(NULL != _vsh->m_function.m_obj, "Vertex shader doesn't exist."); m_vsh = _vsh; m_fsh = _fsh; @@ -2335,91 +2739,64 @@ namespace bgfx { namespace mtl { m_vsh = NULL; m_fsh = NULL; - - if (NULL != m_vshConstantBuffer) - { - UniformBuffer::destroy(m_vshConstantBuffer); - m_vshConstantBuffer = NULL; - } - - if (NULL != m_fshConstantBuffer) + if (NULL != m_computePS) { - UniformBuffer::destroy(m_fshConstantBuffer); - m_fshConstantBuffer = NULL; + BX_DELETE(g_allocator, m_computePS); + m_computePS = NULL; } - - m_vshConstantBufferSize = 0; - m_vshConstantBufferAlignmentMask = 0; - m_fshConstantBufferSize = 0; - m_fshConstantBufferAlignmentMask = 0; - - m_samplerCount = 0; - m_processedUniforms = false; - m_numPredefined = 0; } void BufferMtl::create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride, bool _vertex) { - BX_UNUSED(_stride, _vertex); + BX_UNUSED(_stride); - m_size = _size; - m_flags = _flags; - m_dynamic = (NULL == _data); + m_size = _size; + m_flags = _flags; + m_vertex = _vertex; if (NULL == _data) { - for (uint32_t ii = 0; ii < MTL_MAX_FRAMES_IN_FLIGHT; ++ii) - { - m_buffers[ii] = s_renderMtl->m_device.newBufferWithLength(_size, 0); - } + m_ptr = s_renderMtl->m_device.newBufferWithLength(_size, 0); } else { - m_buffers[0] = s_renderMtl->m_device.newBufferWithBytes(_data, _size, 0); + m_ptr = s_renderMtl->m_device.newBufferWithBytes(_data, _size, 0); } } void BufferMtl::update(uint32_t _offset, uint32_t _size, void* _data, bool _discard) { - BX_UNUSED(_discard); + BlitCommandEncoder bce = s_renderMtl->getBlitCommandEncoder(); - if (m_dynamic - && _discard) + if (!m_vertex + && !_discard) { - m_bufferIndex = (m_bufferIndex + 1) % MTL_MAX_FRAMES_IN_FLIGHT; - bx::memCopy( (uint8_t*)getBuffer().contents() + _offset, _data, _size); - } - else if (NULL != s_renderMtl->m_renderCommandEncoder) - { - s_renderMtl->m_cmd.release(m_buffers[m_bufferIndex]); - - if (_offset == 0 - && _size == m_size) - { - m_buffers[m_bufferIndex] = s_renderMtl->m_device.newBufferWithBytes(_data, _size, 0); - } - else + if (NULL == m_dynamic) { - const void* oldContent = m_buffers[m_bufferIndex].contents(); - m_buffers[m_bufferIndex] = s_renderMtl->m_device.newBufferWithBytes(oldContent, m_size, 0); - bx::memCopy( (uint8_t*)m_buffers[m_bufferIndex].contents() + _offset, _data, _size); + m_dynamic = (uint8_t*)BX_ALLOC(g_allocator, m_size); } + + bx::memCopy(m_dynamic + _offset, _data, _size); + uint32_t start = _offset & 4; + uint32_t end = bx::strideAlign(_offset + _size, 4); + + Buffer temp = s_renderMtl->m_device.newBufferWithBytes(m_dynamic, end - start, 0); + bce.copyFromBuffer(temp, 0, m_ptr, start, end - start); + s_renderMtl->m_cmd.release(temp); } else { - BlitCommandEncoder bce = s_renderMtl->getBlitCommandEncoder(); - Buffer temp = s_renderMtl->m_device.newBufferWithBytes(_data, _size, 0); - bce.copyFromBuffer(temp, 0, getBuffer(), _offset, _size); - release(temp); + bce.copyFromBuffer(temp, 0, m_ptr, _offset, _size); + s_renderMtl->m_cmd.release(temp); } } - void VertexBufferMtl::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags) + void VertexBufferMtl::create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags) { - m_decl = _declHandle; - uint16_t stride = isValid(_declHandle) - ? s_renderMtl->m_vertexDecls[_declHandle.idx].m_stride + m_layoutHandle = _layoutHandle; + uint16_t stride = isValid(_layoutHandle) + ? s_renderMtl->m_vertexLayouts[_layoutHandle.idx].m_stride : 0 ; @@ -2434,18 +2811,26 @@ namespace bgfx { namespace mtl if (bimg::imageParse(imageContainer, _mem->data, _mem->size) ) { - uint8_t numMips = imageContainer.m_numMips; - const uint8_t startLod = uint8_t(bx::uint32_min(_skip, numMips-1) ); - numMips -= startLod; const bimg::ImageBlockInfo& blockInfo = getBlockInfo(bimg::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); - const uint16_t numLayers = imageContainer.m_numLayers; + const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips-1); + + bimg::TextureInfo ti; + bimg::imageGetSize( + &ti + , uint16_t(imageContainer.m_width >>startLod) + , uint16_t(imageContainer.m_height>>startLod) + , uint16_t(imageContainer.m_depth >>startLod) + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + , imageContainer.m_numLayers + , imageContainer.m_format + ); + ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips-startLod, ti.numMips); m_flags = _flags; - m_width = textureWidth; - m_height = textureHeight; - m_depth = imageContainer.m_depth; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; m_requestedFormat = uint8_t(imageContainer.m_format); m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); const bool convert = m_textureFormat != m_requestedFormat; @@ -2453,7 +2838,7 @@ namespace bgfx { namespace mtl TextureDescriptor desc = s_renderMtl->m_textureDescriptor; - if (1 < numLayers) + if (1 < ti.numLayers) { if (imageContainer.m_cubeMap) { @@ -2471,7 +2856,7 @@ namespace bgfx { namespace mtl desc.textureType = MTLTextureTypeCube; m_type = TextureCube; } - else if (imageContainer.m_depth > 1) + else if (1 < imageContainer.m_depth) { desc.textureType = MTLTextureType3D; m_type = Texture3D; @@ -2482,8 +2867,8 @@ namespace bgfx { namespace mtl m_type = Texture2D; } - m_numMips = numMips; - const uint16_t numSides = numLayers * (imageContainer.m_cubeMap ? 6 : 1); + m_numMips = ti.numMips; + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); const bool compressed = bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat) ); const bool writeOnly = 0 != (_flags&BGFX_TEXTURE_RT_WRITE_ONLY); const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); @@ -2494,23 +2879,25 @@ namespace bgfx { namespace mtl , this - s_renderMtl->m_textures , getName( (TextureFormat::Enum)m_textureFormat) , getName( (TextureFormat::Enum)m_requestedFormat) - , numLayers - , textureWidth - , textureHeight + , ti.numLayers + , ti.width + , ti.height , imageContainer.m_cubeMap ? "x6" : "" - , renderTarget ? 'x' : '.' - , writeOnly ? 'x' : '.' - , computeWrite ? 'x' : '.' - , srgb ? 'x' : '.' + , renderTarget ? 'x' : ' ' + , writeOnly ? 'x' : ' ' + , computeWrite ? 'x' : ' ' + , srgb ? 'x' : ' ' ); const uint32_t msaaQuality = bx::uint32_satsub( (_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); - int sampleCount = s_msaa[msaaQuality]; + const int32_t sampleCount = s_msaa[msaaQuality]; + + const TextureFormatInfo& tfi = s_textureFormat[m_textureFormat]; MTLPixelFormat format = MTLPixelFormatInvalid; if (srgb) { - format = s_textureFormat[m_textureFormat].m_fmtSrgb; + format = tfi.m_fmtSrgb; BX_WARN(format != MTLPixelFormatInvalid , "sRGB not supported for texture format %d" , m_textureFormat @@ -2520,18 +2907,20 @@ namespace bgfx { namespace mtl if (format == MTLPixelFormatInvalid) { // not swizzled and not sRGB, or sRGB unsupported - format = s_textureFormat[m_textureFormat].m_fmt; + format = tfi.m_fmt; } desc.pixelFormat = format; - desc.width = textureWidth; - desc.height = textureHeight; + desc.width = ti.width; + desc.height = ti.height; desc.depth = bx::uint32_max(1,imageContainer.m_depth); - desc.mipmapLevelCount = numMips; + desc.mipmapLevelCount = ti.numMips; desc.sampleCount = 1; - desc.arrayLength = numLayers; + desc.arrayLength = ti.numLayers; + desc.swizzle = tfi.m_mapping; - if (s_renderMtl->m_iOS9Runtime || s_renderMtl->m_macOS11Runtime) + if (s_renderMtl->m_iOS9Runtime + || s_renderMtl->m_macOS11Runtime) { desc.cpuCacheMode = MTLCPUCacheModeDefaultCache; @@ -2582,20 +2971,20 @@ namespace bgfx { namespace mtl uint8_t* temp = NULL; if (convert) { - temp = (uint8_t*)BX_ALLOC(g_allocator, textureWidth*textureHeight*4); + temp = (uint8_t*)BX_ALLOC(g_allocator, ti.width*ti.height*4); } - for (uint8_t side = 0; side < numSides; ++side) + for (uint16_t side = 0; side < numSides; ++side) { - uint32_t width = textureWidth; - uint32_t height = textureHeight; - uint32_t depth = imageContainer.m_depth; + uint32_t width = ti.width; + uint32_t height = ti.height; + uint32_t depth = ti.depth; - for (uint8_t lod = 0, num = numMips; lod < num; ++lod) + for (uint8_t lod = 0, num = ti.numMips; lod < num; ++lod) { - width = bx::uint32_max(1, width); - height = bx::uint32_max(1, height); - depth = bx::uint32_max(1, depth); + width = bx::max(1u, width); + height = bx::max(1u, height); + depth = bx::max(1u, depth); bimg::ImageMip mip; if (bimg::imageGetRawData(imageContainer, side, lod+startLod, _mem->data, _mem->size, mip) ) @@ -2666,10 +3055,23 @@ namespace bgfx { namespace mtl void TextureMtl::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) { const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); - const uint32_t rectpitch = _rect.m_width*bpp/8; + uint32_t rectpitch = _rect.m_width*bpp/8; + if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat) ) ) + { + if (m_ptr.pixelFormat() >= 160 /*PVRTC_RGB_2BPP*/ + && m_ptr.pixelFormat() <= 167 /*PVRTC_RGBA_4BPP_sRGB*/) + { + rectpitch = 0; + } + else + { + const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) ); + rectpitch = (_rect.m_width / blockInfo.blockWidth)*blockInfo.blockSize; + } + } const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; - const uint32_t slice = ( (m_type == Texture3D) ? 0 : _side + _z * (m_type == TextureCube ? 6 : 1) ); - const uint16_t z = (m_type == Texture3D) ? _z : 0 ; + const uint32_t slice = ( (m_type == Texture3D) ? 0 : _side + _z * (m_type == TextureCube ? 6 : 1) ); + const uint16_t zz = (m_type == Texture3D) ? _z : 0 ; const bool convert = m_textureFormat != m_requestedFormat; @@ -2697,7 +3099,7 @@ namespace bgfx { namespace mtl MTLRegion region = { - { _rect.m_x, _rect.m_y, z }, + { _rect.m_x, _rect.m_y, zz }, { _rect.m_width, _rect.m_height, _depth }, }; @@ -2707,30 +3109,37 @@ namespace bgfx { namespace mtl { BlitCommandEncoder bce = s_renderMtl->getBlitCommandEncoder(); - const uint32_t dstpitch = bx::strideAlign(rectpitch, 64); - - Buffer tempBuffer = s_renderMtl->m_device.newBufferWithLength(dstpitch*_rect.m_height, 0); - - const uint8_t* src = (uint8_t*)data; - uint8_t* dst = (uint8_t*)tempBuffer.contents(); - - for (uint32_t yy = 0; yy < _rect.m_height; ++yy, src += srcpitch, dst += dstpitch) + TextureDescriptor desc = s_renderMtl->m_textureDescriptor; + desc.textureType = _depth > 1 ? MTLTextureType3D : MTLTextureType2D; + desc.pixelFormat = m_ptr.pixelFormat(); + desc.width = _rect.m_width; + desc.height = _rect.m_height; + desc.depth = _depth; + desc.mipmapLevelCount = 1; + desc.sampleCount = 1; + desc.arrayLength = 1; + + if (s_renderMtl->m_iOS9Runtime + || s_renderMtl->m_macOS11Runtime) { - bx::memCopy(dst, src, rectpitch); + desc.cpuCacheMode = MTLCPUCacheModeDefaultCache; + desc.storageMode = BX_ENABLED(BX_PLATFORM_IOS) + ? (MTLStorageMode)0 // MTLStorageModeShared + : (MTLStorageMode)1 // MTLStorageModeManaged + ; + desc.usage = 0; } - bce.copyFromBuffer( - tempBuffer - , 0 - , dstpitch - , dstpitch * _rect.m_height - , MTLSizeMake(_rect.m_width, _rect.m_height, _depth) - , m_ptr - , slice - , _mip - , MTLOriginMake(_rect.m_x, _rect.m_y, z) - ); - release(tempBuffer); + Texture tempTexture = s_renderMtl->m_device.newTextureWithDescriptor(desc); + MTLRegion region = + { + { 0, 0, 0 }, + { _rect.m_width, _rect.m_height, _depth }, + }; + tempTexture.replaceRegion(region, 0, 0, data, srcpitch, srcpitch * _rect.m_height); + bce.copyFromTexture(tempTexture, 0, 0, MTLOriginMake(0,0,0), MTLSizeMake(_rect.m_width, _rect.m_height, _depth), + m_ptr, slice, _mip, MTLOriginMake(_rect.m_x, _rect.m_y, zz) ); + release(tempTexture); } if (NULL != temp) @@ -2739,11 +3148,12 @@ namespace bgfx { namespace mtl } } - void TextureMtl::commit(uint8_t _stage, bool _vertex, bool _fragment, uint32_t _flags) + void TextureMtl::commit(uint8_t _stage, bool _vertex, bool _fragment, uint32_t _flags, uint8_t _mip) { if (_vertex) { - s_renderMtl->m_renderCommandEncoder.setVertexTexture(m_ptr, _stage); + Texture p = _mip != UINT8_MAX ? getTextureMipLevel(_mip) : m_ptr; + s_renderMtl->m_renderCommandEncoder.setVertexTexture(p, _stage); s_renderMtl->m_renderCommandEncoder.setVertexSamplerState( 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ? s_renderMtl->getSamplerState(_flags) @@ -2754,7 +3164,8 @@ namespace bgfx { namespace mtl if (_fragment) { - s_renderMtl->m_renderCommandEncoder.setFragmentTexture(m_ptr, _stage); + Texture p = _mip != UINT8_MAX ? getTextureMipLevel(_mip) : m_ptr; + s_renderMtl->m_renderCommandEncoder.setFragmentTexture(p, _stage); s_renderMtl->m_renderCommandEncoder.setFragmentSamplerState( 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & _flags) ? s_renderMtl->getSamplerState(_flags) @@ -2764,17 +3175,62 @@ namespace bgfx { namespace mtl } } + Texture TextureMtl::getTextureMipLevel(int _mip) + { + if (_mip >= 0 + && _mip < m_numMips + && NULL != m_ptr) + { + if (NULL == m_ptrMips[_mip]) + { + if (TextureCube == m_type) + { + m_ptrMips[_mip] = m_ptr.newTextureViewWithPixelFormat( + m_ptr.pixelFormat() + , MTLTextureType2DArray + , NSMakeRange(_mip,1) + , NSMakeRange(0,m_ptr.arrayLength() * 6) + ); + } + else + { + m_ptrMips[_mip] = m_ptr.newTextureViewWithPixelFormat( + m_ptr.pixelFormat() + , m_ptr.textureType() + , NSMakeRange(_mip,1) + , NSMakeRange(0,m_ptr.arrayLength() ) + ); + } + } + + return m_ptrMips[_mip]; + } + + return 0; + } + SwapChainMtl::~SwapChainMtl() { + MTL_RELEASE(m_metalLayer); + MTL_RELEASE(m_drawable); + MTL_RELEASE(m_drawableTexture); + MTL_RELEASE(m_backBufferDepth); - if (BX_ENABLED(BX_PLATFORM_IOS) ) + MTL_RELEASE(m_backBufferStencil); + + if (NULL != m_backBufferColorMsaa) { - MTL_RELEASE(m_backBufferStencil); + MTL_RELEASE(m_backBufferColorMsaa); } + } void SwapChainMtl::init(void* _nwh) { + if (m_metalLayer) + { + release(m_metalLayer); + } if (NULL != NSClassFromString(@"MTKView") ) { MTKView *view = (MTKView *)_nwh; @@ -2793,7 +3249,7 @@ namespace bgfx { namespace mtl if (NULL == metalLayer || ![metalLayer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) { - BX_WARN(NULL != metalLayer, "Unable to create Metal device. Please set platform data window to a CAMetalLayer"); + BX_WARN(false, "Unable to create Metal device. Please set platform data window to a CAMetalLayer"); return; } @@ -2809,10 +3265,54 @@ namespace bgfx { namespace mtl } else { - NSWindow* nsWindow = (NSWindow*)_nwh; - [nsWindow.contentView setWantsLayer:YES]; - m_metalLayer = [CAMetalLayer layer]; - [nsWindow.contentView setLayer:m_metalLayer]; + NSView *contentView; + + if ([nvh isKindOfClass:[NSView class]]) + { + contentView = (NSView*)nvh; + } + else if ([nvh isKindOfClass:[NSWindow class]]) + { + NSWindow* nsWindow = (NSWindow*)nvh; + contentView = [nsWindow contentView]; + } + else + { + BX_WARN(0, "Unable to create Metal device. Please set platform data window to an NSWindow, NSView, or CAMetalLayer"); + return; + } + + void (^setLayer)(void) = ^{ + CALayer* layer = contentView.layer; + if(NULL != layer && [layer isKindOfClass:NSClassFromString(@"CAMetalLayer")]) + { + m_metalLayer = (CAMetalLayer*)layer; + } + else + { + [contentView setWantsLayer:YES]; + m_metalLayer = [CAMetalLayer layer]; + [contentView setLayer:m_metalLayer]; + } + }; + + if ([NSThread isMainThread]) + { + setLayer(); + } + else + { + bx::Semaphore semaphore; + bx::Semaphore* psemaphore = &semaphore; + + CFRunLoopPerformBlock([[NSRunLoop mainRunLoop] getCFRunLoop], + kCFRunLoopCommonModes, + ^{ + setLayer(); + psemaphore->post(); + }); + semaphore.wait(); + } } } #endif // BX_PLATFORM_* @@ -2827,15 +3327,26 @@ namespace bgfx { namespace mtl m_metalLayer.device = s_renderMtl->m_device; m_metalLayer.pixelFormat = MTLPixelFormatBGRA8Unorm; m_metalLayer.magnificationFilter = kCAFilterNearest; + m_nwh = _nwh; + retain(m_metalLayer); } - void SwapChainMtl::resize(FrameBufferMtl &_frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags) + void SwapChainMtl::resize(FrameBufferMtl &_frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags, uint32_t _maximumDrawableCount) { - int sampleCount = s_msaa[(_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; + const int32_t sampleCount = s_msaa[(_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; -#if BX_PLATFORM_OSX > 101300 - m_metalLayer.displaySyncEnabled = 0 != (_flags&BGFX_RESET_VSYNC); -#endif // BX_PLATFORM_OSX > 101300 +#if BX_PLATFORM_OSX +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 + if (@available(macOS 10.13, *) ) + { + m_metalLayer.displaySyncEnabled = 0 != (_flags&BGFX_RESET_VSYNC); + } + if (@available(macOS 10.13.2, *) ) + { + m_metalLayer.maximumDrawableCount = bx::clamp<uint32_t>(_maximumDrawableCount != 0 ? _maximumDrawableCount : BGFX_CONFIG_MAX_FRAME_LATENCY, 2, 3); + } +#endif // __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 +#endif // BX_PLATFORM_OSX m_metalLayer.drawableSize = CGSizeMake(_width, _height); m_metalLayer.pixelFormat = (_flags & BGFX_RESET_SRGB_BACKBUFFER) @@ -2894,7 +3405,7 @@ namespace bgfx { namespace mtl m_backBufferStencil = s_renderMtl->m_device.newTextureWithDescriptor(desc); } - if ( sampleCount > 1 ) + if (sampleCount > 1) { if (NULL != m_backBufferColorMsaa) { @@ -2908,35 +3419,67 @@ namespace bgfx { namespace mtl bx::HashMurmur2A murmur; murmur.begin(); murmur.add(1); - murmur.add((uint32_t)m_metalLayer.pixelFormat); - murmur.add((uint32_t)m_backBufferDepth.pixelFormat()); - murmur.add((uint32_t)m_backBufferStencil.pixelFormat()); - murmur.add((uint32_t)sampleCount); + murmur.add( (uint32_t)m_metalLayer.pixelFormat); + murmur.add( (uint32_t)m_backBufferDepth.pixelFormat() ); + murmur.add( (uint32_t)m_backBufferStencil.pixelFormat() ); + murmur.add( (uint32_t)sampleCount); _frameBuffer.m_pixelFormatHash = murmur.end(); } - id<CAMetalDrawable> SwapChainMtl::currentDrawable() + id <MTLTexture> SwapChainMtl::currentDrawableTexture() { - if (m_drawable == nil) + if (NULL == m_drawableTexture) { m_drawable = m_metalLayer.nextDrawable; - retain(m_drawable); // keep alive to be useable at 'flip' + if (m_drawable != NULL) + { + m_drawableTexture = m_drawable.texture; + retain(m_drawableTexture); + retain(m_drawable); // keep alive to be useable at 'flip' + } + else + { + TextureDescriptor desc = s_renderMtl->m_textureDescriptor; + desc.textureType = MTLTextureType2D; + desc.pixelFormat = m_metalLayer.pixelFormat; + desc.width = m_metalLayer.drawableSize.width; + desc.height = m_metalLayer.drawableSize.height; + desc.depth = 1; + desc.mipmapLevelCount = 1; + desc.sampleCount = 1; + desc.arrayLength = 1; + + if (s_renderMtl->m_iOS9Runtime + || s_renderMtl->m_macOS11Runtime) + { + desc.cpuCacheMode = MTLCPUCacheModeDefaultCache; + desc.storageMode = BX_ENABLED(BX_PLATFORM_IOS) + ? (MTLStorageMode)0 // MTLStorageModeShared + : (MTLStorageMode)1 // MTLStorageModeManaged + ; + + desc.usage = MTLTextureUsageRenderTarget; + } + + m_drawableTexture = s_renderMtl->m_device.newTextureWithDescriptor(desc); + } } - return m_drawable; + return m_drawableTexture; } void FrameBufferMtl::create(uint8_t _num, const Attachment* _attachment) { m_swapChain = NULL; - m_denseIdx = UINT16_MAX; - m_num = 0; - m_width = 0; - m_height = 0; + m_denseIdx = UINT16_MAX; + m_num = 0; + m_width = 0; + m_height = 0; for (uint32_t ii = 0; ii < _num; ++ii) { - TextureHandle handle = _attachment[ii].handle; + const Attachment& at = _attachment[ii]; + TextureHandle handle = at.handle; if (isValid(handle) ) { @@ -2951,10 +3494,12 @@ namespace bgfx { namespace mtl if (bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) ) { m_depthHandle = handle; + m_depthAttachment = at; } else { m_colorHandle[m_num] = handle; + m_colorAttachment[m_num] = at; m_num++; } } @@ -2994,8 +3539,10 @@ namespace bgfx { namespace mtl { BX_UNUSED(_format, _depthFormat); m_swapChain = BX_NEW(g_allocator, SwapChainMtl); + m_num = 0; m_width = _width; m_height = _height; + m_nwh = _nwh; m_denseIdx = _denseIdx; m_swapChain->init(_nwh); @@ -3014,6 +3561,7 @@ namespace bgfx { namespace mtl } m_num = 0; + m_nwh = NULL; m_depthHandle.idx = kInvalidHandle; uint16_t denseIdx = m_denseIdx; @@ -3022,10 +3570,32 @@ namespace bgfx { namespace mtl return denseIdx; } + void FrameBufferMtl::resolve() + { + BlitCommandEncoder bce = s_renderMtl->getBlitCommandEncoder(); + for (uint32_t ii = 0; ii < m_num; ++ii) + { + if (0 != (m_colorAttachment[ii].resolve & BGFX_RESOLVE_AUTO_GEN_MIPS)) + { + const TextureMtl& texture = s_renderMtl->m_textures[m_colorHandle[ii].idx]; + const bool isRenderTarget = (texture.m_flags & BGFX_TEXTURE_RT_MASK); + const bool fmtSupport = 0 != (g_caps.formats[texture.m_textureFormat] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN); + if (isRenderTarget + && fmtSupport + && texture.m_numMips > 1) + { + bce.generateMipmapsForTexture(texture.m_ptr); + } + } + } + + s_renderMtl->endEncoding(); + } + void CommandQueueMtl::init(Device _device) { m_commandQueue = _device.newCommandQueue(); - m_framesSemaphore.post(MTL_MAX_FRAMES_IN_FLIGHT); + m_framesSemaphore.post(BGFX_CONFIG_MAX_FRAME_LATENCY); } void CommandQueueMtl::shutdown() @@ -3041,7 +3611,7 @@ namespace bgfx { namespace mtl return m_activeCommandBuffer; } - static void commandBufferFinishedCallback(void* _data) + inline void commandBufferFinishedCallback(void* _data) { CommandQueueMtl* queue = (CommandQueueMtl*)_data; @@ -3057,7 +3627,7 @@ namespace bgfx { namespace mtl { if (_endFrame) { - m_releaseWriteIndex = (m_releaseWriteIndex + 1) % MTL_MAX_FRAMES_IN_FLIGHT; + m_releaseWriteIndex = (m_releaseWriteIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY; m_activeCommandBuffer.addCompletedHandler(commandBufferFinishedCallback, this); } @@ -3102,7 +3672,7 @@ namespace bgfx { namespace mtl void CommandQueueMtl::consume() { m_framesSemaphore.wait(); - m_releaseReadIndex = (m_releaseReadIndex + 1) % MTL_MAX_FRAMES_IN_FLIGHT; + m_releaseReadIndex = (m_releaseReadIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY; ResourceArray& ra = m_release[m_releaseReadIndex]; @@ -3123,6 +3693,18 @@ namespace bgfx { namespace mtl { } + uint32_t TimerQueryMtl::begin(uint32_t _resultIdx, uint32_t _frameNum) + { + BX_UNUSED(_resultIdx); + BX_UNUSED(_frameNum); + return 0; + } + + void TimerQueryMtl::end(uint32_t _idx) + { + BX_UNUSED(_idx); + } + static void setTimestamp(void* _data) { *( (int64_t*)_data) = bx::getHPCounter(); @@ -3135,10 +3717,10 @@ namespace bgfx { namespace mtl m_control.consume(1); } - uint32_t offset = m_control.m_current * 2 + 0; + uint32_t offset = m_control.m_current; - _commandBuffer.addScheduledHandler(setTimestamp, &m_result[offset]); - _commandBuffer.addCompletedHandler(setTimestamp, &m_result[offset+1]); + _commandBuffer.addScheduledHandler(setTimestamp, &m_result[offset].m_begin); + _commandBuffer.addCompletedHandler(setTimestamp, &m_result[offset].m_end); m_control.commit(1); } @@ -3146,9 +3728,9 @@ namespace bgfx { namespace mtl { if (0 != m_control.available() ) { - uint32_t offset = m_control.m_read * 2; - m_begin = m_result[offset+0]; - m_end = m_result[offset+1]; + uint32_t offset = m_control.m_read; + m_begin = m_result[offset].m_begin; + m_end = m_result[offset].m_end; m_elapsed = m_end - m_begin; m_control.consume(1); @@ -3224,15 +3806,13 @@ namespace bgfx { namespace mtl void RendererContextMtl::submitBlit(BlitState& _bs, uint16_t _view) { - if (!_bs.hasItem(_view)) - return; - - if (0 != m_renderCommandEncoder) + if (!_bs.hasItem(_view) ) { - m_renderCommandEncoder.endEncoding(); - m_renderCommandEncoder = 0; + return; } + endEncoding(); + m_blitCommandEncoder = getBlitCommandEncoder(); while (_bs.hasItem(_view) ) @@ -3242,15 +3822,6 @@ namespace bgfx { namespace mtl const TextureMtl& src = m_textures[blit.m_src.idx]; const TextureMtl& dst = m_textures[blit.m_dst.idx]; - uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX; - uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY; - uint32_t srcDepth = bx::uint32_min(src.m_depth, blit.m_srcZ + blit.m_depth) - blit.m_srcZ; - uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX; - uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY; - uint32_t dstDepth = bx::uint32_min(dst.m_depth, blit.m_dstZ + blit.m_depth) - blit.m_dstZ; - uint32_t width = bx::uint32_min(srcWidth, dstWidth); - uint32_t height = bx::uint32_min(srcHeight, dstHeight); - uint32_t depth = bx::uint32_min(srcDepth, dstDepth); #if BX_PLATFORM_OSX bool readBack = !!(dst.m_flags & BGFX_TEXTURE_READ_BACK); #endif // BX_PLATFORM_OSX @@ -3262,7 +3833,7 @@ namespace bgfx { namespace mtl , 0 , 0 , MTLOriginMake(blit.m_srcX, blit.m_srcY, blit.m_srcZ) - , MTLSizeMake(width, height, bx::uint32_imax(depth, 1) ) + , MTLSizeMake(blit.m_width, blit.m_height, bx::uint32_imax(blit.m_depth, 1) ) , dst.m_ptr , 0 , 0 @@ -3283,7 +3854,7 @@ namespace bgfx { namespace mtl , blit.m_srcZ , blit.m_srcMip , MTLOriginMake(blit.m_srcX, blit.m_srcY, 0) - , MTLSizeMake(width, height, 1) + , MTLSizeMake(blit.m_width, blit.m_height, 1) , dst.m_ptr , blit.m_dstZ , blit.m_dstMip @@ -3310,11 +3881,13 @@ namespace bgfx { namespace mtl { m_cmd.finish(false); - if (m_commandBuffer == NULL) + if (NULL == m_commandBuffer) { m_commandBuffer = m_cmd.alloc(); } + BGFX_MTL_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorFrame); + int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; @@ -3328,7 +3901,7 @@ namespace bgfx { namespace mtl updateResolution(_render->m_resolution); - if (m_saveScreenshot + if (0 != _render->m_numScreenShots || NULL != m_capture) { if (m_screenshotTarget) @@ -3368,8 +3941,6 @@ namespace bgfx { namespace mtl m_screenshotTarget = m_device.newTextureWithDescriptor(m_textureDescriptor); } - - m_saveScreenshot = false; } else { @@ -3377,20 +3948,22 @@ namespace bgfx { namespace mtl } m_uniformBuffer = m_uniformBuffers[m_bufferIndex]; - m_bufferIndex = (m_bufferIndex + 1) % MTL_MAX_FRAMES_IN_FLIGHT; + m_bufferIndex = (m_bufferIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY; m_uniformBufferVertexOffset = 0; m_uniformBufferFragmentOffset = 0; if (0 < _render->m_iboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource); TransientIndexBuffer* ib = _render->m_transientIb; - m_indexBuffers[ib->handle.idx].update(0, _render->m_iboffset, ib->data, true); + m_indexBuffers[ib->handle.idx].update(0, bx::strideAlign(_render->m_iboffset,4), ib->data, true); } if (0 < _render->m_vboffset) { + BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource); TransientVertexBuffer* vb = _render->m_transientVb; - m_vertexBuffers[vb->handle.idx].update(0, _render->m_vboffset, vb->data, true); + m_vertexBuffers[vb->handle.idx].update(0, bx::strideAlign(_render->m_vboffset,4), vb->data, true); } _render->sort(); @@ -3403,14 +3976,13 @@ namespace bgfx { namespace mtl RenderBind currentBind; currentBind.clear(); - const bool hmdEnabled = false; static ViewState viewState; - viewState.reset(_render, hmdEnabled); + viewState.reset(_render); uint32_t blendFactor = 0; bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); - uint16_t programIdx = kInvalidHandle; + ProgramHandle currentProgram = BGFX_INVALID_HANDLE; SortKey key; uint16_t view = UINT16_MAX; FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS }; @@ -3420,33 +3992,38 @@ namespace bgfx { namespace mtl const uint64_t primType = 0; uint8_t primIndex = uint8_t(primType>>BGFX_STATE_PT_SHIFT); PrimInfo prim = s_primInfo[primIndex]; + const uint32_t maxComputeBindings = g_caps.limits.maxComputeBindings; + const uint32_t maxTextureSamplers = g_caps.limits.maxTextureSamplers; - ProgramMtl* currentProgram = NULL; RenderCommandEncoder rce; + PipelineStateMtl* currentPso = NULL; - bool wasCompute = false; + bool wasCompute = false; bool viewHasScissor = false; Rect viewScissorRect; viewScissorRect.clear(); uint32_t statsNumPrimsSubmitted[BX_COUNTOF(s_primInfo)] = {}; - uint32_t statsNumPrimsRendered[BX_COUNTOF(s_primInfo)] = {}; - uint32_t statsNumInstances[BX_COUNTOF(s_primInfo)] = {}; - uint32_t statsNumDrawIndirect[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumPrimsRendered[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumInstances[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumDrawIndirect[BX_COUNTOF(s_primInfo)] = {}; uint32_t statsNumIndices = 0; uint32_t statsKeyType[2] = {}; + Profiler<TimerQueryMtl> profiler( + _render + , m_gpuTimer + , s_viewName + ); + m_occlusionQuery.resolve(_render); if (0 == (_render->m_debug&BGFX_DEBUG_IFH) ) { - bool viewRestart = false; - uint8_t eye = 0; - uint8_t restartState = 0; viewState.m_rect = _render->m_view[0].m_rect; - int32_t numItems = _render->m_numRenderItems; - for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;) + + for (int32_t item = 0; item < numItems;) { const uint64_t encodedKey = _render->m_sortKeys[item]; const bool isCompute = key.decode(encodedKey, _render->m_viewRemap); @@ -3462,226 +4039,393 @@ namespace bgfx { namespace mtl const RenderBind& renderBind = _render->m_renderItemBind[itemIdx]; ++item; - if (viewChanged) + if (viewChanged + || (!isCompute && wasCompute) ) { - if (1 == restartState) - { - restartState = 2; - item = restartItem; - restartItem = numItems; - view = UINT16_MAX; - continue; - } - view = key.m_view; - programIdx = kInvalidHandle; + currentProgram = BGFX_INVALID_HANDLE; - viewRestart = BGFX_VIEW_STEREO == (_render->m_view[view].m_flags & BGFX_VIEW_STEREO); - viewRestart &= hmdEnabled; - - if (viewRestart) - { - if (0 == restartState) - { - restartState = 1; - restartItem = item - 1; - } - - eye = (restartState - 1) & 1; - restartState &= 1; - } - else + if (item > 1) { - eye = 0; + profiler.end(); } - viewState.m_rect = _render->m_view[view].m_rect; + BGFX_MTL_PROFILER_END(); + setViewType(view, " "); + BGFX_MTL_PROFILER_BEGIN(view, kColorView); - if (viewRestart) - { - viewState.m_rect.m_x = eye * (viewState.m_rect.m_width+1)/2; - viewState.m_rect.m_width /= 2; - } + profiler.begin(view); + + viewState.m_rect = _render->m_view[view].m_rect; submitBlit(bs, view); - const Rect& scissorRect = _render->m_view[view].m_scissor; - viewHasScissor = !scissorRect.isZero(); - viewScissorRect = viewHasScissor ? scissorRect : viewState.m_rect; - Clear& clr = _render->m_view[view].m_clear; + if (!isCompute) + { + const Rect& scissorRect = _render->m_view[view].m_scissor; + viewHasScissor = !scissorRect.isZero(); + viewScissorRect = viewHasScissor ? scissorRect : viewState.m_rect; + Clear& clr = _render->m_view[view].m_clear; - Rect viewRect = viewState.m_rect; - bool clearWithRenderPass = false; + Rect viewRect = viewState.m_rect; + bool clearWithRenderPass = false; - if (NULL == m_renderCommandEncoder - || fbh.idx != _render->m_view[view].m_fbh.idx) - { - if (0 != m_renderCommandEncoder) + if (NULL == m_renderCommandEncoder + || fbh.idx != _render->m_view[view].m_fbh.idx) { - m_renderCommandEncoder.endEncoding(); - } + endEncoding(); - RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor(); - renderPassDescriptor.visibilityResultBuffer = m_occlusionQuery.m_buffer; + RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor(); + renderPassDescriptor.visibilityResultBuffer = m_occlusionQuery.m_buffer; - fbh = _render->m_view[view].m_fbh; + fbh = _render->m_view[view].m_fbh; - uint32_t width = m_resolution.width; - uint32_t height = m_resolution.height; + uint32_t width = m_resolution.width; + uint32_t height = m_resolution.height; - if (isValid(fbh) ) - { - FrameBufferMtl& frameBuffer = m_frameBuffers[fbh.idx]; - width = frameBuffer.m_width; - height = frameBuffer.m_height; - } + if (isValid(fbh) ) + { + FrameBufferMtl& frameBuffer = m_frameBuffers[fbh.idx]; + width = frameBuffer.m_width; + height = frameBuffer.m_height; + } - clearWithRenderPass = true - && 0 == viewRect.m_x - && 0 == viewRect.m_y - && width == viewRect.m_width - && height == viewRect.m_height - ; + clearWithRenderPass = true + && 0 == viewRect.m_x + && 0 == viewRect.m_y + && width == viewRect.m_width + && height == viewRect.m_height + ; - setFrameBuffer(renderPassDescriptor, fbh); + setFrameBuffer(renderPassDescriptor, fbh); - if (clearWithRenderPass) - { - for (uint32_t ii = 0; ii < g_caps.limits.maxFBAttachments; ++ii) + if (clearWithRenderPass) { - MTLRenderPassColorAttachmentDescriptor* desc = renderPassDescriptor.colorAttachments[ii]; - - if (desc.texture != NULL) + for (uint32_t ii = 0; ii < g_caps.limits.maxFBAttachments; ++ii) { - if (0 != (BGFX_CLEAR_COLOR & clr.m_flags) ) + MTLRenderPassColorAttachmentDescriptor* desc = renderPassDescriptor.colorAttachments[ii]; + + if (desc.texture != NULL) { - if (0 != (BGFX_CLEAR_COLOR_USE_PALETTE & clr.m_flags) ) + if (0 != (BGFX_CLEAR_COLOR & clr.m_flags) ) { - uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, clr.m_index[ii]); - const float* rgba = _render->m_colorPalette[index]; - const float rr = rgba[0]; - const float gg = rgba[1]; - const float bb = rgba[2]; - const float aa = rgba[3]; - desc.clearColor = MTLClearColorMake(rr, gg, bb, aa); + if (0 != (BGFX_CLEAR_COLOR_USE_PALETTE & clr.m_flags) ) + { + uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, clr.m_index[ii]); + const float* rgba = _render->m_colorPalette[index]; + const float rr = rgba[0]; + const float gg = rgba[1]; + const float bb = rgba[2]; + const float aa = rgba[3]; + desc.clearColor = MTLClearColorMake(rr, gg, bb, aa); + } + else + { + float rr = clr.m_index[0]*1.0f/255.0f; + float gg = clr.m_index[1]*1.0f/255.0f; + float bb = clr.m_index[2]*1.0f/255.0f; + float aa = clr.m_index[3]*1.0f/255.0f; + desc.clearColor = MTLClearColorMake(rr, gg, bb, aa); + } + + desc.loadAction = MTLLoadActionClear; } else { - float rr = clr.m_index[0]*1.0f/255.0f; - float gg = clr.m_index[1]*1.0f/255.0f; - float bb = clr.m_index[2]*1.0f/255.0f; - float aa = clr.m_index[3]*1.0f/255.0f; - desc.clearColor = MTLClearColorMake(rr, gg, bb, aa); + desc.loadAction = MTLLoadActionLoad; } - desc.loadAction = MTLLoadActionClear; + if (NULL != m_capture + && !isValid(fbh) + && m_hasStoreActionStoreAndMultisampleResolve) + { + desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionStoreAndMultisampleResolve : MTLStoreActionStore; + + } + else + { + desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionMultisampleResolve : MTLStoreActionStore; + } } - else + } + + RenderPassDepthAttachmentDescriptor depthAttachment = renderPassDescriptor.depthAttachment; + + if (NULL != depthAttachment.texture) + { + depthAttachment.clearDepth = clr.m_depth; + depthAttachment.loadAction = 0 != (BGFX_CLEAR_DEPTH & clr.m_flags) + ? MTLLoadActionClear + : MTLLoadActionLoad + ; + depthAttachment.storeAction = NULL != m_mainFrameBuffer.m_swapChain->m_backBufferColorMsaa + ? MTLStoreActionDontCare + : MTLStoreActionStore + ; + } + + RenderPassStencilAttachmentDescriptor stencilAttachment = renderPassDescriptor.stencilAttachment; + + if (NULL != stencilAttachment.texture) + { + stencilAttachment.clearStencil = clr.m_stencil; + stencilAttachment.loadAction = 0 != (BGFX_CLEAR_STENCIL & clr.m_flags) + ? MTLLoadActionClear + : MTLLoadActionLoad + ; + stencilAttachment.storeAction = NULL != m_mainFrameBuffer.m_swapChain->m_backBufferColorMsaa + ? MTLStoreActionDontCare + : MTLStoreActionStore + ; + } + } + else + { + for (uint32_t ii = 0; ii < g_caps.limits.maxFBAttachments; ++ii) + { + MTLRenderPassColorAttachmentDescriptor* desc = renderPassDescriptor.colorAttachments[ii]; + if (desc.texture != NULL) { desc.loadAction = MTLLoadActionLoad; + + if (NULL != m_capture + && !isValid(fbh) + && m_hasStoreActionStoreAndMultisampleResolve) + { + desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionStoreAndMultisampleResolve : MTLStoreActionStore; + + } + else + { + desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionMultisampleResolve : MTLStoreActionStore; + } } - desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionMultisampleResolve : MTLStoreActionStore; } - } - RenderPassDepthAttachmentDescriptor depthAttachment = renderPassDescriptor.depthAttachment; - if (NULL != depthAttachment.texture) - { - depthAttachment.clearDepth = clr.m_depth; - depthAttachment.loadAction = 0 != (BGFX_CLEAR_DEPTH & clr.m_flags) - ? MTLLoadActionClear - : MTLLoadActionLoad - ; - depthAttachment.storeAction = NULL != m_mainFrameBuffer.m_swapChain->m_backBufferColorMsaa - ? MTLStoreActionDontCare - : MTLStoreActionStore - ; - } + RenderPassDepthAttachmentDescriptor depthAttachment = renderPassDescriptor.depthAttachment; - RenderPassStencilAttachmentDescriptor stencilAttachment = renderPassDescriptor.stencilAttachment; - if (NULL != stencilAttachment.texture) - { - stencilAttachment.clearStencil = clr.m_stencil; - stencilAttachment.loadAction = 0 != (BGFX_CLEAR_STENCIL & clr.m_flags) - ? MTLLoadActionClear - : MTLLoadActionLoad - ; - stencilAttachment.storeAction = NULL != m_mainFrameBuffer.m_swapChain->m_backBufferColorMsaa - ? MTLStoreActionDontCare - : MTLStoreActionStore - ; + if (NULL != depthAttachment.texture) + { + depthAttachment.loadAction = MTLLoadActionLoad; + depthAttachment.storeAction = MTLStoreActionStore; + } + + RenderPassStencilAttachmentDescriptor stencilAttachment = renderPassDescriptor.stencilAttachment; + + if (NULL != stencilAttachment.texture) + { + stencilAttachment.loadAction = MTLLoadActionLoad; + stencilAttachment.storeAction = MTLStoreActionStore; + } } + + rce = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor); + m_renderCommandEncoder = rce; + m_renderCommandEncoderFrameBufferHandle = fbh; + MTL_RELEASE(renderPassDescriptor); } - else + else if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + rce.popDebugGroup(); + } + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + rce.pushDebugGroup(s_viewName[view]); + } + + rce.setTriangleFillMode(wireframe ? MTLTriangleFillModeLines : MTLTriangleFillModeFill); + + MTLViewport vp; + vp.originX = viewState.m_rect.m_x; + vp.originY = viewState.m_rect.m_y; + vp.width = viewState.m_rect.m_width; + vp.height = viewState.m_rect.m_height; + vp.znear = 0.0f; + vp.zfar = 1.0f; + rce.setViewport(vp); + + MTLScissorRect sciRect = { + viewState.m_rect.m_x, + viewState.m_rect.m_y, + viewState.m_rect.m_width, + viewState.m_rect.m_height + }; + rce.setScissorRect(sciRect); + + if (BGFX_CLEAR_NONE != (clr.m_flags & BGFX_CLEAR_MASK) + && !clearWithRenderPass) + { + clearQuad(_clearQuad, viewState.m_rect, clr, _render->m_colorPalette); + } + } + } + + if (isCompute) + { + if (!wasCompute) + { + wasCompute = true; + + endEncoding(); + rce = NULL; + + setViewType(view, "C"); + BGFX_MTL_PROFILER_END(); + BGFX_MTL_PROFILER_BEGIN(view, kColorCompute); + + m_computeCommandEncoder = m_commandBuffer.computeCommandEncoder(); + } + else if (viewChanged && BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + m_computeCommandEncoder.popDebugGroup(); + } + + if (viewChanged + && BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + s_viewName[view][3] = L'C'; + m_computeCommandEncoder.pushDebugGroup(s_viewName[view]); + s_viewName[view][3] = L' '; + } + + const RenderCompute& compute = renderItem.compute; + + bool programChanged = false; + rendererUpdateUniforms(this, _render->m_uniformBuffer[compute.m_uniformIdx], compute.m_uniformBegin, compute.m_uniformEnd); + + if (key.m_program.idx != currentProgram.idx) + { + currentProgram = key.m_program; + + currentPso = getComputePipelineState(currentProgram); + + if (NULL == currentPso) + { + currentProgram = BGFX_INVALID_HANDLE; + continue; + } + + m_computeCommandEncoder.setComputePipelineState(currentPso->m_cps); + programChanged = true; + } + + if (isValid(currentProgram) + && NULL != currentPso) + { + uint32_t vertexUniformBufferSize = currentPso->m_vshConstantBufferSize; + + if (0 != vertexUniformBufferSize) + { + m_uniformBufferVertexOffset = bx::alignUp( + m_uniformBufferVertexOffset + , currentPso->m_vshConstantBufferAlignment + ); + m_computeCommandEncoder.setBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0); + } + + UniformBuffer* vcb = currentPso->m_vshConstantBuffer; + if (NULL != vcb) { - for (uint32_t ii = 0; ii < g_caps.limits.maxFBAttachments; ++ii) + commit(*vcb); + } + + viewState.setPredefined<4>(this, view, *currentPso, _render, compute); + + m_uniformBufferVertexOffset += vertexUniformBufferSize; + } + BX_UNUSED(programChanged); + + for (uint8_t stage = 0; stage < maxComputeBindings; ++stage) + { + const Binding& bind = renderBind.m_bind[stage]; + if (kInvalidHandle != bind.m_idx) + { + switch (bind.m_type) { - MTLRenderPassColorAttachmentDescriptor* desc = renderPassDescriptor.colorAttachments[ii]; - if (desc.texture != NULL) + case Binding::Image: { - desc.loadAction = MTLLoadActionLoad; + TextureMtl& texture = m_textures[bind.m_idx]; + m_computeCommandEncoder.setTexture(texture.getTextureMipLevel(bind.m_mip), stage); } - } + break; - RenderPassDepthAttachmentDescriptor depthAttachment = renderPassDescriptor.depthAttachment; - if (NULL != depthAttachment.texture) - { - depthAttachment.loadAction = MTLLoadActionLoad; - depthAttachment.storeAction = MTLStoreActionStore; - } + case Binding::Texture: + { + TextureMtl& texture = m_textures[bind.m_idx]; + uint32_t flags = bind.m_samplerFlags; + + m_computeCommandEncoder.setTexture(texture.m_ptr, stage); + m_computeCommandEncoder.setSamplerState( + 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & flags) + ? getSamplerState(flags) + : texture.m_sampler + , stage + ); + } + break; - RenderPassStencilAttachmentDescriptor stencilAttachment = renderPassDescriptor.stencilAttachment; - if (NULL != stencilAttachment.texture) - { - stencilAttachment.loadAction = MTLLoadActionLoad; - stencilAttachment.storeAction = MTLStoreActionStore; + case Binding::IndexBuffer: + case Binding::VertexBuffer: + { + const BufferMtl& buffer = Binding::IndexBuffer == bind.m_type + ? m_indexBuffers[bind.m_idx] + : m_vertexBuffers[bind.m_idx] + ; + m_computeCommandEncoder.setBuffer(buffer.m_ptr, 0, stage + 1); + } + break; } } - - rce = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor); - m_renderCommandEncoder = rce; - m_renderCommandEncoderFrameBufferHandle = fbh; - MTL_RELEASE(renderPassDescriptor); } - rce.setTriangleFillMode(wireframe ? MTLTriangleFillModeLines : MTLTriangleFillModeFill); + MTLSize threadsPerGroup = MTLSizeMake( + currentPso->m_numThreads[0] + , currentPso->m_numThreads[1] + , currentPso->m_numThreads[2] + ); - if (BX_ENABLED(BGFX_CONFIG_DEBUG_MTL) ) + if (isValid(compute.m_indirectBuffer) ) { - if (item != 1) + const VertexBufferMtl& vb = m_vertexBuffers[compute.m_indirectBuffer.idx]; + + uint32_t numDrawIndirect = UINT16_MAX == compute.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : compute.m_numIndirect + ; + + uint32_t args = compute.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) { - rce.popDebugGroup(); + m_computeCommandEncoder.dispatchThreadgroupsWithIndirectBuffer( + vb.m_ptr + , args + , threadsPerGroup + ); + args += BGFX_CONFIG_DRAW_INDIRECT_STRIDE; } - - rce.pushDebugGroup(s_viewName[view]); } - - MTLViewport vp; - vp.originX = viewState.m_rect.m_x; - vp.originY = viewState.m_rect.m_y; - vp.width = viewState.m_rect.m_width; - vp.height = viewState.m_rect.m_height; - vp.znear = 0.0f; - vp.zfar = 1.0f; - rce.setViewport(vp); - - if (BGFX_CLEAR_NONE != (clr.m_flags & BGFX_CLEAR_MASK) - && !clearWithRenderPass) + else { - clearQuad(_clearQuad, viewState.m_rect, clr, _render->m_colorPalette); + m_computeCommandEncoder.dispatchThreadgroups( + MTLSizeMake(compute.m_numX, compute.m_numY, compute.m_numZ) + , threadsPerGroup + ); } + continue; } + bool resetState = viewChanged || wasCompute; if (wasCompute) { wasCompute = false; + currentProgram = BGFX_INVALID_HANDLE; - programIdx = kInvalidHandle; - currentProgram = NULL; - - //invalidateCompute(); + setViewType(view, " "); + BGFX_MTL_PROFILER_END(); + BGFX_MTL_PROFILER_BEGIN(view, kColorDraw); } const RenderDraw& draw = renderItem.draw; @@ -3727,7 +4471,7 @@ namespace bgfx { namespace mtl currentBind.clear(); - programIdx = kInvalidHandle; + currentProgram = BGFX_INVALID_HANDLE; setDepthStencilState(newFlags, packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT) ); const uint64_t pt = newFlags&BGFX_STATE_PT_MASK; @@ -3787,10 +4531,19 @@ namespace bgfx { namespace mtl if ( (0 | BGFX_STATE_CULL_MASK + | BGFX_STATE_FRONT_CCW | BGFX_STATE_ALPHA_REF_MASK | BGFX_STATE_PT_MASK ) & changedFlags) { + if (BGFX_STATE_FRONT_CCW & changedFlags) + { + rce.setFrontFacingWinding( (newFlags&BGFX_STATE_FRONT_CCW) + ? MTLWindingCounterClockwise + : MTLWindingClockwise + ); + } + if (BGFX_STATE_CULL_MASK & changedFlags) { const uint64_t pt = newFlags&BGFX_STATE_CULL_MASK; @@ -3826,12 +4579,11 @@ namespace bgfx { namespace mtl } bool programChanged = false; - bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd; rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); bool vertexStreamChanged = hasVertexStreamChanged(currentState, draw); - if (key.m_program != programIdx + if (key.m_program.idx != currentProgram.idx || vertexStreamChanged || (0 | BGFX_STATE_BLEND_MASK @@ -3844,36 +4596,39 @@ namespace bgfx { namespace mtl ) & changedFlags || ( (blendFactor != draw.m_rgba) && !!(newFlags & BGFX_STATE_BLEND_INDEPENDENT) ) ) { - programIdx = key.m_program; + currentProgram = key.m_program; currentState.m_streamMask = draw.m_streamMask; currentState.m_instanceDataBuffer.idx = draw.m_instanceDataBuffer.idx; currentState.m_instanceDataOffset = draw.m_instanceDataOffset; currentState.m_instanceDataStride = draw.m_instanceDataStride; - const VertexDecl* decls[BGFX_CONFIG_MAX_VERTEX_STREAMS]; + const VertexLayout* layouts[BGFX_CONFIG_MAX_VERTEX_STREAMS]; uint32_t numVertices = draw.m_numVertices; uint8_t numStreams = 0; - for (uint32_t idx = 0, streamMask = draw.m_streamMask, ntz = bx::uint32_cnttz(streamMask) + for (uint32_t idx = 0, streamMask = draw.m_streamMask ; 0 != streamMask - ; streamMask >>= 1, idx += 1, ntz = bx::uint32_cnttz(streamMask), ++numStreams + ; streamMask >>= 1, idx += 1, ++numStreams ) { + const uint32_t ntz = bx::uint32_cnttz(streamMask); streamMask >>= ntz; idx += ntz; - currentState.m_stream[idx].m_decl = draw.m_stream[idx].m_decl; - currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; - currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + currentState.m_stream[idx].m_layoutHandle = draw.m_stream[idx].m_layoutHandle; + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; const uint16_t handle = draw.m_stream[idx].m_handle.idx; const VertexBufferMtl& vb = m_vertexBuffers[handle]; - const uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[idx].m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = m_vertexDecls[decl]; - const uint32_t stride = vertexDecl.m_stride; + const uint16_t decl = isValid(draw.m_stream[idx].m_layoutHandle) + ? draw.m_stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx; + const VertexLayout& layout = m_vertexLayouts[decl]; + const uint32_t stride = layout.m_stride; - decls[numStreams] = &vertexDecl; + layouts[numStreams] = &layout; numVertices = bx::uint32_min(UINT32_MAX == draw.m_numVertices ? vb.m_size/stride @@ -3882,123 +4637,165 @@ namespace bgfx { namespace mtl ); const uint32_t offset = draw.m_stream[idx].m_startVertex * stride; - rce.setVertexBuffer(vb.getBuffer(), offset, idx+1); + rce.setVertexBuffer(vb.m_ptr, offset, idx+1); } - currentState.m_numVertices = numVertices; - - if (kInvalidHandle == programIdx) + if (!isValid(currentProgram) ) { - currentProgram = NULL; continue; } else { - ProgramMtl& program = m_program[programIdx]; - currentProgram = &program; - - RenderPipelineState pso = NULL; + currentPso = NULL; if (0 < numStreams) { - pso = getPipelineState( + currentPso = getPipelineState( newFlags , draw.m_rgba , fbh , numStreams - , decls - , programIdx + , layouts + , currentProgram , draw.m_instanceDataStride/16 ); } - if (NULL == pso) + if (NULL == currentPso) { - currentProgram = NULL; - programIdx = kInvalidHandle; + currentProgram = BGFX_INVALID_HANDLE; continue; } - rce.setRenderPipelineState(pso); + rce.setRenderPipelineState(currentPso->m_rps); } if (isValid(draw.m_instanceDataBuffer) ) { const VertexBufferMtl& inst = m_vertexBuffers[draw.m_instanceDataBuffer.idx]; - rce.setVertexBuffer(inst.getBuffer(), draw.m_instanceDataOffset, numStreams+1); + rce.setVertexBuffer(inst.m_ptr, draw.m_instanceDataOffset, numStreams+1); } - programChanged = - constantsChanged = true; + programChanged = true; } - if (kInvalidHandle != programIdx) + if (isValid(currentProgram) ) { - ProgramMtl& program = m_program[programIdx]; - - uint32_t vertexUniformBufferSize = program.m_vshConstantBufferSize; - uint32_t fragmentUniformBufferSize = program.m_fshConstantBufferSize; + const uint32_t vertexUniformBufferSize = currentPso->m_vshConstantBufferSize; + const uint32_t fragmentUniformBufferSize = currentPso->m_fshConstantBufferSize; if (0 != vertexUniformBufferSize) { - m_uniformBufferVertexOffset = BX_ALIGN_MASK(m_uniformBufferVertexOffset, program.m_vshConstantBufferAlignmentMask); + m_uniformBufferVertexOffset = bx::alignUp( + m_uniformBufferVertexOffset + , currentPso->m_vshConstantBufferAlignment + ); rce.setVertexBuffer(m_uniformBuffer, m_uniformBufferVertexOffset, 0); } m_uniformBufferFragmentOffset = m_uniformBufferVertexOffset + vertexUniformBufferSize; if (0 != fragmentUniformBufferSize) { - m_uniformBufferFragmentOffset = BX_ALIGN_MASK(m_uniformBufferFragmentOffset, program.m_fshConstantBufferAlignmentMask); + m_uniformBufferFragmentOffset = bx::alignUp( + m_uniformBufferFragmentOffset + , currentPso->m_fshConstantBufferAlignment + ); rce.setFragmentBuffer(m_uniformBuffer, m_uniformBufferFragmentOffset, 0); } - if (constantsChanged) + UniformBuffer* vcb = currentPso->m_vshConstantBuffer; + if (NULL != vcb) { - UniformBuffer* vcb = program.m_vshConstantBuffer; - if (NULL != vcb) - { - commit(*vcb); - } + commit(*vcb); + } - UniformBuffer* fcb = program.m_fshConstantBuffer; - if (NULL != fcb) - { - commit(*fcb); - } + UniformBuffer* fcb = currentPso->m_fshConstantBuffer; + if (NULL != fcb) + { + commit(*fcb); } - viewState.setPredefined<4>(this, view, eye, program, _render, draw); + viewState.setPredefined<4>(this, view, *currentPso, _render, draw); m_uniformBufferFragmentOffset += fragmentUniformBufferSize; - m_uniformBufferVertexOffset = m_uniformBufferFragmentOffset; + m_uniformBufferVertexOffset = m_uniformBufferFragmentOffset; } - if (kInvalidHandle != programIdx) + if (isValid(currentProgram) ) { - ProgramMtl& program = m_program[programIdx]; - - for (uint32_t sampler = 0; sampler < program.m_samplerCount; ++sampler) + uint8_t* bindingTypes = currentPso->m_bindingTypes; + for (uint8_t stage = 0; stage < maxTextureSamplers; ++stage) { - ProgramMtl::SamplerInfo& samplerInfo = program.m_samplers[sampler]; - - UniformHandle handle = samplerInfo.m_uniform; - int stage = *((int*)m_uniforms[handle.idx]); - const Binding& bind = renderBind.m_bind[stage]; Binding& current = currentBind.m_bind[stage]; - if (current.m_idx != bind.m_idx + || current.m_type != bind.m_type || current.m_samplerFlags != bind.m_samplerFlags || programChanged) { if (kInvalidHandle != bind.m_idx) { - TextureMtl& texture = m_textures[bind.m_idx]; - texture.commit(samplerInfo.m_index - , !samplerInfo.m_fragment - , samplerInfo.m_fragment - , bind.m_samplerFlags - ); + switch (bind.m_type) + { + case Binding::Image: + { + if (bind.m_access == Access::ReadWrite && 0 == (g_caps.supported & BGFX_CAPS_IMAGE_RW)) + { + BGFX_FATAL(false, Fatal::DebugCheck, + "Failed to set image with access: Access::ReadWrite, device is not support image read&write"); + } + + if ( + (bind.m_access == Access::Read && (0 == (g_caps.formats[bind.m_format] & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ))) + || (bind.m_access == Access::Write && (0 == (g_caps.formats[bind.m_format] & BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE))) + || (bind.m_access == Access::ReadWrite && (0 == (g_caps.formats[bind.m_format] & (BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ|BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE)))) + ) + { + BGFX_FATAL(false, Fatal::DebugCheck, + "Failed to set image with access: %s, format:%s is not supoort", s_accessNames[bind.m_access], bimg::getName(bimg::TextureFormat::Enum(bind.m_format))); + } + TextureMtl& texture = m_textures[bind.m_idx]; + texture.commit( + stage + , 0 != (bindingTypes[stage] & PipelineStateMtl::BindToVertexShader) + , 0 != (bindingTypes[stage] & PipelineStateMtl::BindToFragmentShader) + , bind.m_samplerFlags + , bind.m_mip + ); + } + break; + case Binding::Texture: + { + TextureMtl& texture = m_textures[bind.m_idx]; + texture.commit( + stage + , 0 != (bindingTypes[stage] & PipelineStateMtl::BindToVertexShader) + , 0 != (bindingTypes[stage] & PipelineStateMtl::BindToFragmentShader) + , bind.m_samplerFlags + ); + } + break; + + case Binding::IndexBuffer: + case Binding::VertexBuffer: + { + const BufferMtl& buffer = Binding::IndexBuffer == bind.m_type + ? m_indexBuffers[bind.m_idx] + : m_vertexBuffers[bind.m_idx] + ; + + if (0 != (bindingTypes[stage] & PipelineStateMtl::BindToVertexShader) ) + { + rce.setVertexBuffer(buffer.m_ptr, 0, stage + 1); + } + + if (0 != (bindingTypes[stage] & PipelineStateMtl::BindToFragmentShader) ) + { + rce.setFragmentBuffer(buffer.m_ptr, 0, stage + 1); + } + } + break; + } } } @@ -4009,12 +4806,13 @@ namespace bgfx { namespace mtl if (0 != currentState.m_streamMask) { uint32_t numVertices = draw.m_numVertices; + if (UINT32_MAX == numVertices) { const VertexBufferMtl& vb = m_vertexBuffers[currentState.m_stream[0].m_handle.idx]; - uint16_t decl = !isValid(vb.m_decl) ? draw.m_stream[0].m_decl.idx : vb.m_decl.idx; - const VertexDecl& vertexDecl = m_vertexDecls[decl]; - numVertices = vb.m_size/vertexDecl.m_stride; + uint16_t decl = !isValid(vb.m_layoutHandle) ? draw.m_stream[0].m_layoutHandle.idx : vb.m_layoutHandle.idx; + const VertexLayout& layout = m_vertexLayouts[decl]; + numVertices = vb.m_size/layout.m_stride; } uint32_t numIndices = 0; @@ -4030,33 +4828,63 @@ namespace bgfx { namespace mtl if (isValid(draw.m_indirectBuffer) ) { + const VertexBufferMtl& vb = m_vertexBuffers[draw.m_indirectBuffer.idx]; + + if (isValid(draw.m_indexBuffer) ) + { + const bool isIndex16 = draw.isIndex16(); + const MTLIndexType indexFormat = isIndex16 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32; + const IndexBufferMtl& ib = m_indexBuffers[draw.m_indexBuffer.idx]; + + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; + + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + rce.drawIndexedPrimitives(prim.m_type, indexFormat, ib.m_ptr, 0, vb.m_ptr, (draw.m_startIndirect + ii )* BGFX_CONFIG_DRAW_INDIRECT_STRIDE); + } + } + else + { + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; + + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + rce.drawPrimitives(prim.m_type, vb.m_ptr, (draw.m_startIndirect + ii) * BGFX_CONFIG_DRAW_INDIRECT_STRIDE); + } + } } else { if (isValid(draw.m_indexBuffer) ) { - const IndexBufferMtl& ib = m_indexBuffers[draw.m_indexBuffer.idx]; - MTLIndexType indexType = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32; + const bool isIndex16 = draw.isIndex16(); + const uint32_t indexSize = isIndex16 ? 2 : 4; + const MTLIndexType indexFormat = isIndex16 ? MTLIndexTypeUInt16 : MTLIndexTypeUInt32; + const IndexBufferMtl& ib = m_indexBuffers[draw.m_indexBuffer.idx]; if (UINT32_MAX == draw.m_numIndices) { - const uint32_t indexSize = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; numIndices = ib.m_size/indexSize; numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; numInstances = draw.m_numInstances; numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; - rce.drawIndexedPrimitives(prim.m_type, numIndices, indexType, ib.getBuffer(), 0, draw.m_numInstances); + rce.drawIndexedPrimitives(prim.m_type, numIndices, indexFormat, ib.m_ptr, 0, draw.m_numInstances); } else if (prim.m_min <= draw.m_numIndices) { - const uint32_t indexSize = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32) ? 2 : 4; numIndices = draw.m_numIndices; numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; numInstances = draw.m_numInstances; numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; - rce.drawIndexedPrimitives(prim.m_type, numIndices, indexType, ib.getBuffer(), draw.m_startIndex * indexSize,numInstances); + rce.drawIndexedPrimitives(prim.m_type, numIndices, indexFormat, ib.m_ptr, draw.m_startIndex * indexSize,numInstances); } } else @@ -4065,7 +4893,7 @@ namespace bgfx { namespace mtl numInstances = draw.m_numInstances; numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; - rce.drawPrimitives(prim.m_type, 0, draw.m_numVertices, draw.m_numInstances); + rce.drawPrimitives(prim.m_type, 0, numVertices, draw.m_numInstances); } } @@ -4084,7 +4912,11 @@ namespace bgfx { namespace mtl if (wasCompute) { - //invalidateCompute(); + invalidateCompute(); + + setViewType(view, "C"); + BGFX_MTL_PROFILER_END(); + BGFX_MTL_PROFILER_BEGIN(view, kColorCompute); } submitBlit(bs, BGFX_CONFIG_MAX_VIEWS); @@ -4095,10 +4927,12 @@ namespace bgfx { namespace mtl capture(); rce = m_renderCommandEncoder; captureElapsed += bx::getHPCounter(); + + profiler.end(); } } - if (BX_ENABLED(BGFX_CONFIG_DEBUG_MTL) ) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) { if (0 < _render->m_numRenderItems) { @@ -4106,6 +4940,8 @@ namespace bgfx { namespace mtl } } + BGFX_MTL_PROFILER_END(); + int64_t timeEnd = bx::getHPCounter(); int64_t frameTime = timeEnd - timeBegin; @@ -4141,6 +4977,7 @@ namespace bgfx { namespace mtl perfStats.numCompute = statsKeyType[1]; perfStats.numBlit = _render->m_numBlitItems; perfStats.maxGpuLatency = maxGpuLatency; + perfStats.gpuFrameNum = 0; // TODO: take from TimerQueryMtl::Result bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) ); perfStats.gpuMemoryMax = -INT64_MAX; perfStats.gpuMemoryUsed = -INT64_MAX; @@ -4164,8 +5001,14 @@ namespace bgfx { namespace mtl tvm.clear(); uint16_t pos = 0; tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f - , " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " + , " %s / " BX_COMPILER_NAME + " / " BX_CPU_NAME + " / " BX_ARCH_NAME + " / " BX_PLATFORM_NAME + " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")" , getRendererName() + , BGFX_API_VERSION + , BGFX_REV_NUMBER ); pos = 10; @@ -4241,23 +5084,32 @@ namespace bgfx { namespace mtl rce.popDebugGroup(); } - rce.endEncoding(); - m_renderCommandEncoder = 0; + endEncoding(); m_renderCommandEncoderFrameBufferHandle.idx = kInvalidHandle; if (m_screenshotTarget) { RenderPassDescriptor renderPassDescriptor = newRenderPassDescriptor(); - renderPassDescriptor.colorAttachments[0].texture = m_mainFrameBuffer.m_swapChain->currentDrawable().texture; + renderPassDescriptor.colorAttachments[0].texture = m_mainFrameBuffer.m_swapChain->currentDrawableTexture(); renderPassDescriptor.colorAttachments[0].storeAction = MTLStoreActionStore; rce = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor); + MTL_RELEASE(renderPassDescriptor); + rce.setCullMode(MTLCullModeNone); rce.setRenderPipelineState(m_screenshotBlitRenderPipelineState); - rce.setFragmentSamplerState(getSamplerState(BGFX_SAMPLER_U_CLAMP|BGFX_SAMPLER_V_CLAMP|BGFX_SAMPLER_MIN_POINT|BGFX_SAMPLER_MAG_POINT|BGFX_SAMPLER_MIP_POINT), 0); + const SamplerState samplerState = getSamplerState(0 + | BGFX_SAMPLER_U_CLAMP + | BGFX_SAMPLER_V_CLAMP + | BGFX_SAMPLER_MIN_POINT + | BGFX_SAMPLER_MAG_POINT + | BGFX_SAMPLER_MIP_POINT + ); + + rce.setFragmentSamplerState(samplerState, 0); rce.setFragmentTexture(m_screenshotTarget, 0); rce.drawPrimitives(MTLPrimitiveTypeTriangle, 0, 3, 1); diff --git a/3rdparty/bgfx/src/renderer_noop.cpp b/3rdparty/bgfx/src/renderer_noop.cpp index c4977464ff8..ee051ee90ce 100644 --- a/3rdparty/bgfx/src/renderer_noop.cpp +++ b/3rdparty/bgfx/src/renderer_noop.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -53,7 +53,8 @@ namespace bgfx { namespace noop | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB | BGFX_CAPS_FORMAT_TEXTURE_CUBE_EMULATED | BGFX_CAPS_FORMAT_TEXTURE_VERTEX - | BGFX_CAPS_FORMAT_TEXTURE_IMAGE + | BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ + | BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA | BGFX_CAPS_FORMAT_TEXTURE_MSAA @@ -100,15 +101,15 @@ namespace bgfx { namespace noop { } - void createVertexDecl(VertexDeclHandle /*_handle*/, const VertexDecl& /*_decl*/) override + void createVertexLayout(VertexLayoutHandle /*_handle*/, const VertexLayout& /*_layout*/) override { } - void destroyVertexDecl(VertexDeclHandle /*_handle*/) override + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override { } - void createVertexBuffer(VertexBufferHandle /*_handle*/, const Memory* /*_mem*/, VertexDeclHandle /*_declHandle*/, uint16_t /*_flags*/) override + void createVertexBuffer(VertexBufferHandle /*_handle*/, const Memory* /*_mem*/, VertexLayoutHandle /*_layoutHandle*/, uint16_t /*_flags*/) override { } @@ -226,15 +227,15 @@ namespace bgfx { namespace noop { } - void setMarker(const char* /*_marker*/, uint32_t /*_size*/) override + void invalidateOcclusionQuery(OcclusionQueryHandle /*_handle*/) override { } - void invalidateOcclusionQuery(OcclusionQueryHandle /*_handle*/) override + void setMarker(const char* /*_marker*/, uint16_t /*_len*/) override { } - virtual void setName(Handle /*_handle*/, const char* /*_name*/) override + virtual void setName(Handle /*_handle*/, const char* /*_name*/, uint16_t /*_len*/) override { } @@ -251,6 +252,7 @@ namespace bgfx { namespace noop perfStats.gpuTimeBegin = 0; perfStats.gpuTimeEnd = 0; perfStats.gpuTimerFreq = 1000000000; + perfStats.gpuFrameNum = 0; bx::memSet(perfStats.numPrims, 0, sizeof(perfStats.numPrims) ); diff --git a/3rdparty/bgfx/src/renderer_nvn.cpp b/3rdparty/bgfx/src/renderer_nvn.cpp new file mode 100644 index 00000000000..fedfc6c4e95 --- /dev/null +++ b/3rdparty/bgfx/src/renderer_nvn.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "bgfx_p.h" + +namespace bgfx +{ + +#define BGFX_DECLARE_EMBEDDED_SHADER(_name) \ + extern const uint8_t* BX_CONCATENATE(_name, _nvn); \ + extern const uint32_t BX_CONCATENATE(_name, _nvn_size); \ + static const uint8_t BX_CONCATENATE(_name, _int_nvn)[] = { 0 }; \ + const uint8_t* BX_CONCATENATE(_name, _nvn) = &BX_CONCATENATE(_name, _int_nvn)[0]; \ + const uint32_t BX_CONCATENATE(_name, _nvn_size) = 1 + +BGFX_DECLARE_EMBEDDED_SHADER(vs_debugfont); +BGFX_DECLARE_EMBEDDED_SHADER(fs_debugfont); +BGFX_DECLARE_EMBEDDED_SHADER(vs_clear); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear0); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear1); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear2); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear3); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear4); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear5); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear6); +BGFX_DECLARE_EMBEDDED_SHADER(fs_clear7); + +#undef BGFX_DECLARE_EMBEDDED_SHADER + +} // namespace bgfx + +namespace bgfx { namespace nvn +{ + RendererContextI* rendererCreate(const Init& _init) + { + BX_UNUSED(_init); + return NULL; + } + + void rendererDestroy() + { + } + +} /* namespace nvn */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/renderer_vk.cpp b/3rdparty/bgfx/src/renderer_vk.cpp index b3843e03047..8b2c6cd001e 100644 --- a/3rdparty/bgfx/src/renderer_vk.cpp +++ b/3rdparty/bgfx/src/renderer_vk.cpp @@ -1,16 +1,33 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" #if BGFX_CONFIG_RENDERER_VULKAN +# include <bx/pixelformat.h> # include "renderer_vk.h" +# include "shader_spirv.h" + +#if BX_PLATFORM_OSX +# import <Cocoa/Cocoa.h> +# import <Foundation/Foundation.h> +# import <QuartzCore/QuartzCore.h> +# import <Metal/Metal.h> +#endif // BX_PLATFORM_OSX namespace bgfx { namespace vk { - static char s_viewName[BGFX_CONFIG_MAX_VIEWS][256]; + static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + + inline void setViewType(ViewId _view, const bx::StringView _str) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION || BGFX_CONFIG_PROFILER) ) + { + bx::memCopy(&s_viewName[_view][3], _str.getPtr(), _str.getLength() ); + } + } struct PrimInfo { @@ -31,24 +48,15 @@ namespace bgfx { namespace vk }; BX_STATIC_ASSERT(Topology::Count == BX_COUNTOF(s_primInfo)-1); - static const uint32_t s_checkMsaa[] = + static MsaaSamplerVK s_msaa[] = { - 0, - 2, - 4, - 8, - 16, + { 1, VK_SAMPLE_COUNT_1_BIT }, + { 2, VK_SAMPLE_COUNT_2_BIT }, + { 4, VK_SAMPLE_COUNT_4_BIT }, + { 8, VK_SAMPLE_COUNT_8_BIT }, + { 16, VK_SAMPLE_COUNT_16_BIT }, }; -// static DXGI_SAMPLE_DESC s_msaa[] = -// { -// { 1, 0 }, -// { 2, 0 }, -// { 4, 0 }, -// { 8, 0 }, -// { 16, 0 }, -// }; - static const VkBlendFactor s_blendFactor[][2] = { { VkBlendFactor(0), VkBlendFactor(0) }, // ignored @@ -116,6 +124,21 @@ namespace bgfx { namespace vk VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, }; + struct PresentMode + { + VkPresentModeKHR mode; + bool vsync; + const char* name; + }; + + static const PresentMode s_presentMode[] = + { + { VK_PRESENT_MODE_FIFO_KHR, true, "VK_PRESENT_MODE_FIFO_KHR" }, + { VK_PRESENT_MODE_FIFO_RELAXED_KHR, true, "VK_PRESENT_MODE_FIFO_RELAXED_KHR" }, + { VK_PRESENT_MODE_MAILBOX_KHR, true, "VK_PRESENT_MODE_MAILBOX_KHR" }, + { VK_PRESENT_MODE_IMMEDIATE_KHR, false, "VK_PRESENT_MODE_IMMEDIATE_KHR" }, + }; + #define VK_IMPORT_FUNC(_optional, _func) PFN_##_func _func #define VK_IMPORT_INSTANCE_FUNC VK_IMPORT_FUNC #define VK_IMPORT_DEVICE_FUNC VK_IMPORT_FUNC @@ -132,98 +155,277 @@ VK_IMPORT_DEVICE VkFormat m_fmtSrv; VkFormat m_fmtDsv; VkFormat m_fmtSrgb; + VkComponentMapping m_mapping; }; static const TextureFormatInfo s_textureFormat[] = { - { VK_FORMAT_BC1_RGB_UNORM_BLOCK, VK_FORMAT_BC1_RGB_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC1_RGB_SRGB_BLOCK }, // BC1 - { VK_FORMAT_BC2_UNORM_BLOCK, VK_FORMAT_BC2_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC2_SRGB_BLOCK }, // BC2 - { VK_FORMAT_BC3_UNORM_BLOCK, VK_FORMAT_BC3_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC3_SRGB_BLOCK }, // BC3 - { VK_FORMAT_BC4_UNORM_BLOCK, VK_FORMAT_BC4_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // BC4 - { VK_FORMAT_BC5_UNORM_BLOCK, VK_FORMAT_BC5_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // BC5 - { VK_FORMAT_BC6H_SFLOAT_BLOCK, VK_FORMAT_BC6H_SFLOAT_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // BC6H - { VK_FORMAT_BC7_UNORM_BLOCK, VK_FORMAT_BC7_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC7_SRGB_BLOCK }, // BC7 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ETC1 - { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK }, // ETC2 - { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK }, // ETC2A - { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK }, // ETC2A1 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // PTC12 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // PTC14 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // PTC12A - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // PTC14A - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // PTC22 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // PTC24 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ATC - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ATCE - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ATCI - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ASTC4x4 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ASTC5x5 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ASTC6x6 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ASTC8x5 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ASTC8x6 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // ASTC10x5 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // Unknown - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R1 - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // A8 - { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8_SRGB }, // R8 - { VK_FORMAT_R8_SINT, VK_FORMAT_R8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R8I - { VK_FORMAT_R8_UINT, VK_FORMAT_R8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R8U - { VK_FORMAT_R8_SNORM, VK_FORMAT_R8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R8S - { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R16 - { VK_FORMAT_R16_SINT, VK_FORMAT_R16_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R16I - { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R16U - { VK_FORMAT_R16_SFLOAT, VK_FORMAT_R16_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R16F - { VK_FORMAT_R16_SNORM, VK_FORMAT_R16_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R16S - { VK_FORMAT_R32_SINT, VK_FORMAT_R32_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R32I - { VK_FORMAT_R32_UINT, VK_FORMAT_R32_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R32U - { VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R32F - { VK_FORMAT_R8G8_UNORM, VK_FORMAT_R8G8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8_SRGB }, // RG8 - { VK_FORMAT_R8G8_SINT, VK_FORMAT_R8G8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG8I - { VK_FORMAT_R8G8_UINT, VK_FORMAT_R8G8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG8U - { VK_FORMAT_R8G8_SNORM, VK_FORMAT_R8G8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG8S - { VK_FORMAT_R16G16_UNORM, VK_FORMAT_R16G16_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG16 - { VK_FORMAT_R16G16_SINT, VK_FORMAT_R16G16_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG16I - { VK_FORMAT_R16G16_UINT, VK_FORMAT_R16G16_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG16U - { VK_FORMAT_R16G16_SFLOAT, VK_FORMAT_R16G16_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG16F - { VK_FORMAT_R16G16_SNORM, VK_FORMAT_R16G16_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG16S - { VK_FORMAT_R32G32_SINT, VK_FORMAT_R32G32_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG32I - { VK_FORMAT_R32G32_UINT, VK_FORMAT_R32G32_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG32U - { VK_FORMAT_R32G32_SFLOAT, VK_FORMAT_R32G32_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG32F - { VK_FORMAT_R8G8B8_UNORM, VK_FORMAT_R8G8B8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8_SRGB }, // RGB8 - { VK_FORMAT_R8G8B8_SINT, VK_FORMAT_R8G8B8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8_SRGB }, // RGB8I - { VK_FORMAT_R8G8B8_UINT, VK_FORMAT_R8G8B8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8_SRGB }, // RGB8U - { VK_FORMAT_R8G8B8_SNORM, VK_FORMAT_R8G8B8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGB8S - { VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGB9E5F - { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_B8G8R8A8_SRGB }, // BGRA8 - { VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_SRGB }, // RGBA8 - { VK_FORMAT_R8G8B8A8_SINT, VK_FORMAT_R8G8B8A8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_SRGB }, // RGBA8I - { VK_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_SRGB }, // RGBA8U - { VK_FORMAT_R8G8B8A8_SNORM, VK_FORMAT_R8G8B8A8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA8S - { VK_FORMAT_R16G16B16A16_UNORM, VK_FORMAT_R16G16B16A16_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA16 - { VK_FORMAT_R16G16B16A16_SINT, VK_FORMAT_R16G16B16A16_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA16I - { VK_FORMAT_R16G16B16A16_UINT, VK_FORMAT_R16G16B16A16_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA16U - { VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA16F - { VK_FORMAT_R16G16B16A16_SNORM, VK_FORMAT_R16G16B16A16_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA16S - { VK_FORMAT_R32G32B32A32_SINT, VK_FORMAT_R32G32B32A32_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA32I - { VK_FORMAT_R32G32B32A32_UINT, VK_FORMAT_R32G32B32A32_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA32U - { VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA32F - { VK_FORMAT_B5G6R5_UNORM_PACK16, VK_FORMAT_B5G6R5_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // R5G6B5 - { VK_FORMAT_B4G4R4A4_UNORM_PACK16, VK_FORMAT_B4G4R4A4_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGBA4 - { VK_FORMAT_B5G5R5A1_UNORM_PACK16, VK_FORMAT_B5G5R5A1_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGB5A1 - { VK_FORMAT_A2R10G10B10_UNORM_PACK32, VK_FORMAT_A2R10G10B10_UNORM_PACK32, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RGB10A2 - { VK_FORMAT_B10G11R11_UFLOAT_PACK32, VK_FORMAT_B10G11R11_UFLOAT_PACK32, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // RG11B10F - { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED }, // UnknownDepth - { VK_FORMAT_UNDEFINED, VK_FORMAT_R16_UNORM, VK_FORMAT_D16_UNORM, VK_FORMAT_UNDEFINED }, // D16 - { VK_FORMAT_UNDEFINED, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_UNDEFINED }, // D24 - { VK_FORMAT_UNDEFINED, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_UNDEFINED }, // D24S8 - { VK_FORMAT_UNDEFINED, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_UNDEFINED }, // D32 - { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_UNDEFINED }, // D16F - { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_UNDEFINED }, // D24F - { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_UNDEFINED }, // D32F - { VK_FORMAT_UNDEFINED, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_UNDEFINED }, // D0S8 +#define $_ VK_COMPONENT_SWIZZLE_IDENTITY +#define $0 VK_COMPONENT_SWIZZLE_ZERO +#define $1 VK_COMPONENT_SWIZZLE_ONE +#define $R VK_COMPONENT_SWIZZLE_R +#define $G VK_COMPONENT_SWIZZLE_G +#define $B VK_COMPONENT_SWIZZLE_B +#define $A VK_COMPONENT_SWIZZLE_A + { VK_FORMAT_BC1_RGB_UNORM_BLOCK, VK_FORMAT_BC1_RGB_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC1_RGB_SRGB_BLOCK, { $_, $_, $_, $_ } }, // BC1 + { VK_FORMAT_BC2_UNORM_BLOCK, VK_FORMAT_BC2_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC2_SRGB_BLOCK, { $_, $_, $_, $_ } }, // BC2 + { VK_FORMAT_BC3_UNORM_BLOCK, VK_FORMAT_BC3_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC3_SRGB_BLOCK, { $_, $_, $_, $_ } }, // BC3 + { VK_FORMAT_BC4_UNORM_BLOCK, VK_FORMAT_BC4_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // BC4 + { VK_FORMAT_BC5_UNORM_BLOCK, VK_FORMAT_BC5_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // BC5 + { VK_FORMAT_BC6H_SFLOAT_BLOCK, VK_FORMAT_BC6H_SFLOAT_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // BC6H + { VK_FORMAT_BC7_UNORM_BLOCK, VK_FORMAT_BC7_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_BC7_SRGB_BLOCK, { $_, $_, $_, $_ } }, // BC7 + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // ETC1 + { VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ETC2 + { VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ETC2A + { VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ETC2A1 + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // PTC12 + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // PTC14 + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // PTC12A + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // PTC14A + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // PTC22 + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // PTC24 + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // ATC + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // ATCE + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // ATCI + { VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_4x4_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC4x4 + { VK_FORMAT_ASTC_5x4_UNORM_BLOCK, VK_FORMAT_ASTC_5x4_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_5x4_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC5x4 + { VK_FORMAT_ASTC_5x5_UNORM_BLOCK, VK_FORMAT_ASTC_5x5_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_5x5_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC5x5 + { VK_FORMAT_ASTC_6x5_UNORM_BLOCK, VK_FORMAT_ASTC_6x5_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_6x5_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC6x5 + { VK_FORMAT_ASTC_6x6_UNORM_BLOCK, VK_FORMAT_ASTC_6x6_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_6x6_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC6x6 + { VK_FORMAT_ASTC_8x5_UNORM_BLOCK, VK_FORMAT_ASTC_8x5_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_8x5_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC8x5 + { VK_FORMAT_ASTC_8x6_UNORM_BLOCK, VK_FORMAT_ASTC_8x6_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_8x6_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC8x6 + { VK_FORMAT_ASTC_8x8_UNORM_BLOCK, VK_FORMAT_ASTC_8x8_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_8x8_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC8x8 + { VK_FORMAT_ASTC_10x5_UNORM_BLOCK, VK_FORMAT_ASTC_10x5_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_10x5_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC10x5 + { VK_FORMAT_ASTC_10x6_UNORM_BLOCK, VK_FORMAT_ASTC_10x6_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_10x6_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC10x6 + { VK_FORMAT_ASTC_10x8_UNORM_BLOCK, VK_FORMAT_ASTC_10x8_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_10x8_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC10x8 + { VK_FORMAT_ASTC_10x10_UNORM_BLOCK, VK_FORMAT_ASTC_10x10_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_10x10_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC10x10 + { VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_12x10_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC12x10 + { VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_UNDEFINED, VK_FORMAT_ASTC_12x12_SRGB_BLOCK, { $_, $_, $_, $_ } }, // ASTC12x12 + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // Unknown + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R1 + { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $0, $0, $0, $R } }, // A8 + { VK_FORMAT_R8_UNORM, VK_FORMAT_R8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8_SRGB, { $_, $_, $_, $_ } }, // R8 + { VK_FORMAT_R8_SINT, VK_FORMAT_R8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R8I + { VK_FORMAT_R8_UINT, VK_FORMAT_R8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R8U + { VK_FORMAT_R8_SNORM, VK_FORMAT_R8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R8S + { VK_FORMAT_R16_UNORM, VK_FORMAT_R16_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R16 + { VK_FORMAT_R16_SINT, VK_FORMAT_R16_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R16I + { VK_FORMAT_R16_UINT, VK_FORMAT_R16_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R16U + { VK_FORMAT_R16_SFLOAT, VK_FORMAT_R16_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R16F + { VK_FORMAT_R16_SNORM, VK_FORMAT_R16_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R16S + { VK_FORMAT_R32_SINT, VK_FORMAT_R32_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R32I + { VK_FORMAT_R32_UINT, VK_FORMAT_R32_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R32U + { VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R32F + { VK_FORMAT_R8G8_UNORM, VK_FORMAT_R8G8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8_SRGB, { $_, $_, $_, $_ } }, // RG8 + { VK_FORMAT_R8G8_SINT, VK_FORMAT_R8G8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG8I + { VK_FORMAT_R8G8_UINT, VK_FORMAT_R8G8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG8U + { VK_FORMAT_R8G8_SNORM, VK_FORMAT_R8G8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG8S + { VK_FORMAT_R16G16_UNORM, VK_FORMAT_R16G16_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG16 + { VK_FORMAT_R16G16_SINT, VK_FORMAT_R16G16_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG16I + { VK_FORMAT_R16G16_UINT, VK_FORMAT_R16G16_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG16U + { VK_FORMAT_R16G16_SFLOAT, VK_FORMAT_R16G16_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG16F + { VK_FORMAT_R16G16_SNORM, VK_FORMAT_R16G16_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG16S + { VK_FORMAT_R32G32_SINT, VK_FORMAT_R32G32_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG32I + { VK_FORMAT_R32G32_UINT, VK_FORMAT_R32G32_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG32U + { VK_FORMAT_R32G32_SFLOAT, VK_FORMAT_R32G32_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG32F + { VK_FORMAT_R8G8B8_UNORM, VK_FORMAT_R8G8B8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8_SRGB, { $_, $_, $_, $_ } }, // RGB8 + { VK_FORMAT_R8G8B8_SINT, VK_FORMAT_R8G8B8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8_SRGB, { $_, $_, $_, $_ } }, // RGB8I + { VK_FORMAT_R8G8B8_UINT, VK_FORMAT_R8G8B8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8_SRGB, { $_, $_, $_, $_ } }, // RGB8U + { VK_FORMAT_R8G8B8_SNORM, VK_FORMAT_R8G8B8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGB8S + { VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGB9E5F + { VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_B8G8R8A8_SRGB, { $_, $_, $_, $_ } }, // BGRA8 + { VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_SRGB, { $_, $_, $_, $_ } }, // RGBA8 + { VK_FORMAT_R8G8B8A8_SINT, VK_FORMAT_R8G8B8A8_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_SRGB, { $_, $_, $_, $_ } }, // RGBA8I + { VK_FORMAT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_SRGB, { $_, $_, $_, $_ } }, // RGBA8U + { VK_FORMAT_R8G8B8A8_SNORM, VK_FORMAT_R8G8B8A8_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA8S + { VK_FORMAT_R16G16B16A16_UNORM, VK_FORMAT_R16G16B16A16_UNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA16 + { VK_FORMAT_R16G16B16A16_SINT, VK_FORMAT_R16G16B16A16_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA16I + { VK_FORMAT_R16G16B16A16_UINT, VK_FORMAT_R16G16B16A16_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA16U + { VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA16F + { VK_FORMAT_R16G16B16A16_SNORM, VK_FORMAT_R16G16B16A16_SNORM, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA16S + { VK_FORMAT_R32G32B32A32_SINT, VK_FORMAT_R32G32B32A32_SINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA32I + { VK_FORMAT_R32G32B32A32_UINT, VK_FORMAT_R32G32B32A32_UINT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA32U + { VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RGBA32F + { VK_FORMAT_R5G6B5_UNORM_PACK16, VK_FORMAT_R5G6B5_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // B5G6R5 + { VK_FORMAT_B5G6R5_UNORM_PACK16, VK_FORMAT_B5G6R5_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // R5G6B5 + { VK_FORMAT_B4G4R4A4_UNORM_PACK16, VK_FORMAT_B4G4R4A4_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $G, $R, $A, $B } }, // BGRA4 + { VK_FORMAT_R4G4B4A4_UNORM_PACK16, VK_FORMAT_R4G4B4A4_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $A, $B, $G, $R } }, // RGBA4 + { VK_FORMAT_A1R5G5B5_UNORM_PACK16, VK_FORMAT_A1R5G5B5_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // BGR5A1 + { VK_FORMAT_A1R5G5B5_UNORM_PACK16, VK_FORMAT_A1R5G5B5_UNORM_PACK16, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $B, $G, $R, $A } }, // RGB5A1 + { VK_FORMAT_A2R10G10B10_UNORM_PACK32, VK_FORMAT_A2R10G10B10_UNORM_PACK32, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $B, $G, $R, $A } }, // RGB10A2 + { VK_FORMAT_B10G11R11_UFLOAT_PACK32, VK_FORMAT_B10G11R11_UFLOAT_PACK32, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // RG11B10F + { VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // UnknownDepth + { VK_FORMAT_UNDEFINED, VK_FORMAT_R16_UNORM, VK_FORMAT_D16_UNORM, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D16 + { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D24 + { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D24S8 + { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D32 + { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D16F + { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D24F + { VK_FORMAT_UNDEFINED, VK_FORMAT_R32_SFLOAT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D32F + { VK_FORMAT_UNDEFINED, VK_FORMAT_R8_UINT, VK_FORMAT_S8_UINT, VK_FORMAT_UNDEFINED, { $_, $_, $_, $_ } }, // D0S8 +#undef $_ +#undef $0 +#undef $1 +#undef $R +#undef $G +#undef $B +#undef $A }; BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat) ); + struct LayerInfo + { + bool m_supported; + bool m_initialize; + }; + + struct Layer + { + enum Enum + { + VK_LAYER_LUNARG_standard_validation, + VK_LAYER_KHRONOS_validation, + + Count + }; + + const char* m_name; + uint32_t m_minVersion; + LayerInfo m_instance; + LayerInfo m_device; + }; + + // Layer registry + // + static Layer s_layer[] = + { + { "VK_LAYER_LUNARG_standard_validation", 1, { false, false }, { false, false } }, + { "VK_LAYER_KHRONOS_validation", 1, { false, false }, { false, false } }, + { "", 0, { false, false }, { false, false } }, + }; + BX_STATIC_ASSERT(Layer::Count == BX_COUNTOF(s_layer)-1); + + void updateLayer(const char* _name, uint32_t _version, bool _instanceLayer) + { + bx::StringView layerName(_name); + + for (uint32_t ii = 0; ii < Layer::Count; ++ii) + { + Layer& layer = s_layer[ii]; + LayerInfo& layerInfo = _instanceLayer + ? layer.m_instance + : layer.m_device + ; + + if (!layerInfo.m_supported && layerInfo.m_initialize) + { + if ( 0 == bx::strCmp(layerName, layer.m_name) + && _version >= layer.m_minVersion) + { + layerInfo.m_supported = true; + break; + } + } + } + } + + struct Extension + { + enum Enum + { + EXT_debug_utils, + EXT_debug_report, + EXT_memory_budget, + KHR_get_physical_device_properties2, + EXT_conservative_rasterization, + EXT_line_rasterization, + EXT_shader_viewport_index_layer, + EXT_custom_border_color, + KHR_draw_indirect_count, + +# if BX_PLATFORM_ANDROID + KHR_android_surface, +# elif BX_PLATFORM_LINUX + KHR_wayland_surface, + KHR_xlib_surface, + KHR_xcb_surface, +# elif BX_PLATFORM_WINDOWS + KHR_win32_surface, +# elif BX_PLATFORM_OSX + MVK_macos_surface, +# endif + + Count + }; + + const char* m_name; + uint32_t m_minVersion; + bool m_instanceExt; + bool m_supported; + bool m_initialize; + Layer::Enum m_layer; + }; + + // Extension registry + // + static Extension s_extension[] = + { + { "VK_EXT_debug_utils", 1, false, false, BGFX_CONFIG_DEBUG_OBJECT_NAME || BGFX_CONFIG_DEBUG_ANNOTATION, Layer::Count }, + { "VK_EXT_debug_report", 1, false, false, false , Layer::Count }, + { "VK_EXT_memory_budget", 1, false, false, true , Layer::Count }, + { "VK_KHR_get_physical_device_properties2", 1, false, false, true , Layer::Count }, + { "VK_EXT_conservative_rasterization", 1, false, false, true , Layer::Count }, + { "VK_EXT_line_rasterization", 1, false, false, true , Layer::Count }, + { "VK_EXT_shader_viewport_index_layer", 1, false, false, true , Layer::Count }, + { "VK_EXT_custom_border_color", 1, false, false, true , Layer::Count }, + { "VK_KHR_draw_indirect_count", 1, false, false, true , Layer::Count }, +# if BX_PLATFORM_ANDROID + { VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count }, +# elif BX_PLATFORM_LINUX + { VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count }, + { VK_KHR_XLIB_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count }, + { VK_KHR_XCB_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count }, +# elif BX_PLATFORM_WINDOWS + { VK_KHR_WIN32_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count }, +# elif BX_PLATFORM_OSX + { VK_MVK_MACOS_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count }, +# endif + }; + BX_STATIC_ASSERT(Extension::Count == BX_COUNTOF(s_extension) ); + + bool updateExtension(const char* _name, uint32_t _version, bool _instanceExt, Extension _extensions[Extension::Count]) + { + bool supported = false; + if (BX_ENABLED(BGFX_CONFIG_RENDERER_USE_EXTENSIONS) ) + { + const bx::StringView ext(_name); + for (uint32_t ii = 0; ii < Extension::Count; ++ii) + { + Extension& extension = _extensions[ii]; + const LayerInfo& layerInfo = _instanceExt + ? s_layer[extension.m_layer].m_instance + : s_layer[extension.m_layer].m_device + ; + + if (!extension.m_supported + && extension.m_initialize + && (extension.m_layer == Layer::Count || layerInfo.m_supported) ) + { + if ( 0 == bx::strCmp(ext, extension.m_name) + && _version >= extension.m_minVersion) + { + extension.m_supported = true; + extension.m_instanceExt = _instanceExt; + supported = true; + break; + } + } + } + } + + return supported; + } + static const VkFormat s_attribType[][4][2] = { { // Uint8 @@ -259,48 +461,83 @@ VK_IMPORT_DEVICE }; BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) ); - uint32_t fillVertexDecl(const ShaderVK* _vsh, VkPipelineVertexInputStateCreateInfo& _vertexInputState, const VertexDecl& _decl) + void fillVertexLayout(const ShaderVK* _vsh, VkPipelineVertexInputStateCreateInfo& _vertexInputState, const VertexLayout& _layout) { - VkVertexInputBindingDescription* inputBinding = const_cast<VkVertexInputBindingDescription*>(_vertexInputState.pVertexBindingDescriptions); - VkVertexInputAttributeDescription* inputAttrib = const_cast<VkVertexInputAttributeDescription*>(_vertexInputState.pVertexAttributeDescriptions); + uint32_t numBindings = _vertexInputState.vertexBindingDescriptionCount; + uint32_t numAttribs = _vertexInputState.vertexAttributeDescriptionCount; + VkVertexInputBindingDescription* inputBinding = const_cast<VkVertexInputBindingDescription*>(_vertexInputState.pVertexBindingDescriptions + numBindings); + VkVertexInputAttributeDescription* inputAttrib = const_cast<VkVertexInputAttributeDescription*>(_vertexInputState.pVertexAttributeDescriptions + numAttribs); - inputBinding->binding = 0; - inputBinding->stride = _decl.m_stride; + inputBinding->binding = numBindings; + inputBinding->stride = _layout.m_stride; inputBinding->inputRate = VK_VERTEX_INPUT_RATE_VERTEX; - _vertexInputState.vertexBindingDescriptionCount = 1; - uint32_t numAttribs = 0; for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - if (UINT16_MAX != _decl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { inputAttrib->location = _vsh->m_attrRemap[attr]; - inputAttrib->binding = 0; + inputAttrib->binding = numBindings; - if (0 == _decl.m_attributes[attr]) - { - inputAttrib->format = VK_FORMAT_R32G32B32_SFLOAT; - inputAttrib->offset = 0; - } - else - { - uint8_t num; - AttribType::Enum type; - bool normalized; - bool asInt; - _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); - inputAttrib->format = s_attribType[type][num-1][normalized]; - inputAttrib->offset = _decl.m_offset[attr]; - } + uint8_t num; + AttribType::Enum type; + bool normalized; + bool asInt; + _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); + inputAttrib->format = s_attribType[type][num-1][normalized]; + inputAttrib->offset = _layout.m_offset[attr]; ++inputAttrib; ++numAttribs; } } + _vertexInputState.vertexBindingDescriptionCount = numBindings + 1; + _vertexInputState.vertexAttributeDescriptionCount = numAttribs; + } + + void fillInstanceBinding(const ShaderVK* _vsh, VkPipelineVertexInputStateCreateInfo& _vertexInputState, uint32_t _numInstanceData) + { + BX_UNUSED(_vsh); + + uint32_t numBindings = _vertexInputState.vertexBindingDescriptionCount; + uint32_t numAttribs = _vertexInputState.vertexAttributeDescriptionCount; + VkVertexInputBindingDescription* inputBinding = const_cast<VkVertexInputBindingDescription*>(_vertexInputState.pVertexBindingDescriptions + numBindings); + VkVertexInputAttributeDescription* inputAttrib = const_cast<VkVertexInputAttributeDescription*>(_vertexInputState.pVertexAttributeDescriptions + numAttribs); + + inputBinding->binding = numBindings; + inputBinding->stride = _numInstanceData * 16; + inputBinding->inputRate = VK_VERTEX_INPUT_RATE_INSTANCE; + + for (uint32_t inst = 0; inst < _numInstanceData; ++inst) + { + inputAttrib->location = numAttribs; + inputAttrib->binding = numBindings; + inputAttrib->format = VK_FORMAT_R32G32B32A32_SFLOAT; + inputAttrib->offset = inst * 16; + + ++numAttribs; + ++inputAttrib; + } + + _vertexInputState.vertexBindingDescriptionCount = numBindings + 1; _vertexInputState.vertexAttributeDescriptionCount = numAttribs; + } + + static const char* s_deviceTypeName[] = + { + "Other", + "Integrated GPU", + "Discrete GPU", + "Virtual GPU", + "CPU", + + "Unknown?!" + }; - return numAttribs; + const char* getName(VkPhysicalDeviceType _type) + { + return s_deviceTypeName[bx::min<int32_t>(_type, BX_COUNTOF(s_deviceTypeName)-1 )]; } static const char* s_allocScopeName[] = @@ -311,7 +548,7 @@ VK_IMPORT_DEVICE "vkDevice", "vkInstance", }; - BX_STATIC_ASSERT(VK_SYSTEM_ALLOCATION_SCOPE_RANGE_SIZE == BX_COUNTOF(s_allocScopeName) ); + BX_STATIC_ASSERT(VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE == BX_COUNTOF(s_allocScopeName)-1); static void* VKAPI_PTR allocationFunction(void* _userData, size_t _size, size_t _alignment, VkSystemAllocationScope _allocationScope) { @@ -357,6 +594,27 @@ VK_IMPORT_DEVICE internalFreeNotification, }; + VkResult VKAPI_PTR stubSetDebugUtilsObjectNameEXT(VkDevice _device, const VkDebugUtilsObjectNameInfoEXT* _nameInfo) + { + BX_UNUSED(_device, _nameInfo); + return VK_SUCCESS; + } + + void VKAPI_PTR stubCmdInsertDebugUtilsLabelEXT(VkCommandBuffer _commandBuffer, const VkDebugUtilsLabelEXT* _labelInfo) + { + BX_UNUSED(_commandBuffer, _labelInfo); + } + + void VKAPI_PTR stubCmdBeginDebugUtilsLabelEXT(VkCommandBuffer _commandBuffer, const VkDebugUtilsLabelEXT* _labelInfo) + { + BX_UNUSED(_commandBuffer, _labelInfo); + } + + void VKAPI_PTR stubCmdEndDebugUtilsLabelEXT(VkCommandBuffer _commandBuffer) + { + BX_UNUSED(_commandBuffer); + } + static const char* s_debugReportObjectType[] = { "Unknown", @@ -411,6 +669,16 @@ VK_IMPORT_DEVICE , _userData , s_debugReportObjectType ); + + // For more info about 'VUID-VkSwapchainCreateInfoKHR-imageExtent-01274' + // check https://github.com/KhronosGroup/Vulkan-Docs/issues/1144 + if (!bx::strFind(_message, "PointSizeMissing").isEmpty() + || !bx::strFind(_message, "SwapchainTooManyImages").isEmpty() + || !bx::strFind(_message, "SwapchainImageNotAcquired").isEmpty() + || !bx::strFind(_message, "VUID-VkSwapchainCreateInfoKHR-imageExtent-01274").isEmpty() ) + { + return VK_FALSE; + } BX_TRACE("%c%c%c%c%c %19s, %s, %d: %s" , 0 != (_flags & VK_DEBUG_REPORT_INFORMATION_BIT_EXT ) ? 'I' : '-' , 0 != (_flags & VK_DEBUG_REPORT_WARNING_BIT_EXT ) ? 'W' : '-' @@ -422,7 +690,7 @@ VK_IMPORT_DEVICE , _messageCode , _message ); - return VK_TRUE; + return VK_FALSE; } VkResult enumerateLayerProperties(VkPhysicalDevice _physicalDevice, uint32_t* _propertyCount, VkLayerProperties* _properties) @@ -441,7 +709,7 @@ VK_IMPORT_DEVICE ; } - void dumpExtensions(VkPhysicalDevice _physicalDevice = VK_NULL_HANDLE) + void dumpExtensions(VkPhysicalDevice _physicalDevice, Extension _extensions[Extension::Count]) { { // Global extensions. uint32_t numExtensionProperties; @@ -454,25 +722,36 @@ VK_IMPORT_DEVICE if (VK_SUCCESS == result && 0 < numExtensionProperties) { - VkExtensionProperties extensionProperties[64]; - numExtensionProperties = bx::uint32_min(numExtensionProperties, BX_COUNTOF(extensionProperties) ); + VkExtensionProperties* extensionProperties = (VkExtensionProperties*)BX_ALLOC(g_allocator, numExtensionProperties * sizeof(VkExtensionProperties) ); result = enumerateExtensionProperties(_physicalDevice , NULL , &numExtensionProperties , extensionProperties ); - BX_TRACE("\tGlobal extensions (%d):" + BX_TRACE("Global extensions (%d):" , numExtensionProperties ); for (uint32_t extension = 0; extension < numExtensionProperties; ++extension) { - BX_TRACE("\t\t%s (s: 0x%08x)" - , extensionProperties[extension].extensionName + bool supported = updateExtension( + extensionProperties[extension].extensionName + , extensionProperties[extension].specVersion + , VK_NULL_HANDLE == _physicalDevice + , _extensions + ); + + BX_TRACE("\tv%-3d %s%s" , extensionProperties[extension].specVersion + , extensionProperties[extension].extensionName + , supported ? " (supported)" : "", extensionProperties[extension].extensionName ); + + BX_UNUSED(supported); } + + BX_FREE(g_allocator, extensionProperties); } } @@ -483,11 +762,10 @@ VK_IMPORT_DEVICE if (VK_SUCCESS == result && 0 < numLayerProperties) { - VkLayerProperties layerProperties[64]; - numLayerProperties = bx::uint32_min(numLayerProperties, BX_COUNTOF(layerProperties) ); + VkLayerProperties* layerProperties = (VkLayerProperties*)BX_ALLOC(g_allocator, numLayerProperties * sizeof(VkLayerProperties) ); result = enumerateLayerProperties(_physicalDevice, &numLayerProperties, layerProperties); - char indent = VK_NULL_HANDLE == _physicalDevice ? ' ' : '\t'; + char indent = VK_NULL_HANDLE == _physicalDevice ? '\0' : '\t'; BX_UNUSED(indent); BX_TRACE("%cLayer extensions (%d):" @@ -496,6 +774,12 @@ VK_IMPORT_DEVICE ); for (uint32_t layer = 0; layer < numLayerProperties; ++layer) { + updateLayer( + layerProperties[layer].layerName + , layerProperties[layer].implementationVersion + , VK_NULL_HANDLE == _physicalDevice + ); + BX_TRACE("%c\t%s (s: 0x%08x, i: 0x%08x), %s" , indent , layerProperties[layer].layerName @@ -513,8 +797,7 @@ VK_IMPORT_DEVICE if (VK_SUCCESS == result && 0 < numExtensionProperties) { - VkExtensionProperties extensionProperties[64]; - numExtensionProperties = bx::uint32_min(numExtensionProperties, BX_COUNTOF(extensionProperties) ); + VkExtensionProperties* extensionProperties = (VkExtensionProperties*)BX_ALLOC(g_allocator, numExtensionProperties * sizeof(VkExtensionProperties) ); result = enumerateExtensionProperties(_physicalDevice , layerProperties[layer].layerName , &numExtensionProperties @@ -523,14 +806,28 @@ VK_IMPORT_DEVICE for (uint32_t extension = 0; extension < numExtensionProperties; ++extension) { + bool supported = updateExtension( + extensionProperties[extension].extensionName + , extensionProperties[extension].specVersion + , VK_NULL_HANDLE == _physicalDevice + , _extensions + ); + BX_TRACE("%c\t\t%s (s: 0x%08x)" , indent , extensionProperties[extension].extensionName , extensionProperties[extension].specVersion + , supported ? " (supported)" : "", extensionProperties[extension].extensionName ); + + BX_UNUSED(supported); } + + BX_FREE(g_allocator, extensionProperties); } } + + BX_FREE(g_allocator, layerProperties); } } @@ -547,6 +844,8 @@ VK_IMPORT_DEVICE VKENUM(VK_INCOMPLETE); VKENUM(VK_ERROR_OUT_OF_HOST_MEMORY); VKENUM(VK_ERROR_OUT_OF_DEVICE_MEMORY); + VKENUM(VK_ERROR_OUT_OF_POOL_MEMORY); + VKENUM(VK_ERROR_FRAGMENTED_POOL); VKENUM(VK_ERROR_INITIALIZATION_FAILED); VKENUM(VK_ERROR_DEVICE_LOST); VKENUM(VK_ERROR_MEMORY_MAP_FAILED); @@ -570,101 +869,209 @@ VK_IMPORT_DEVICE return "<VkResult?>"; } - void setImageMemoryBarrier(VkCommandBuffer _commandBuffer, VkImage _image, VkImageLayout _oldLayout, VkImageLayout _newLayout) + template<typename Ty> + constexpr VkObjectType getType(); + + template<> VkObjectType getType<VkBuffer >() { return VK_OBJECT_TYPE_BUFFER; } + template<> VkObjectType getType<VkCommandPool >() { return VK_OBJECT_TYPE_COMMAND_POOL; } + template<> VkObjectType getType<VkDescriptorPool >() { return VK_OBJECT_TYPE_DESCRIPTOR_POOL; } + template<> VkObjectType getType<VkDescriptorSet >() { return VK_OBJECT_TYPE_DESCRIPTOR_SET; } + template<> VkObjectType getType<VkDescriptorSetLayout>() { return VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT; } + template<> VkObjectType getType<VkDeviceMemory >() { return VK_OBJECT_TYPE_DEVICE_MEMORY; } + template<> VkObjectType getType<VkFence >() { return VK_OBJECT_TYPE_FENCE; } + template<> VkObjectType getType<VkFramebuffer >() { return VK_OBJECT_TYPE_FRAMEBUFFER; } + template<> VkObjectType getType<VkImage >() { return VK_OBJECT_TYPE_IMAGE; } + template<> VkObjectType getType<VkImageView >() { return VK_OBJECT_TYPE_IMAGE_VIEW; } + template<> VkObjectType getType<VkPipeline >() { return VK_OBJECT_TYPE_PIPELINE; } + template<> VkObjectType getType<VkPipelineCache >() { return VK_OBJECT_TYPE_PIPELINE_CACHE; } + template<> VkObjectType getType<VkPipelineLayout >() { return VK_OBJECT_TYPE_PIPELINE_LAYOUT; } + template<> VkObjectType getType<VkQueryPool >() { return VK_OBJECT_TYPE_QUERY_POOL; } + template<> VkObjectType getType<VkRenderPass >() { return VK_OBJECT_TYPE_RENDER_PASS; } + template<> VkObjectType getType<VkSampler >() { return VK_OBJECT_TYPE_SAMPLER; } + template<> VkObjectType getType<VkSemaphore >() { return VK_OBJECT_TYPE_SEMAPHORE; } + template<> VkObjectType getType<VkShaderModule >() { return VK_OBJECT_TYPE_SHADER_MODULE; } + template<> VkObjectType getType<VkSurfaceKHR >() { return VK_OBJECT_TYPE_SURFACE_KHR; } + template<> VkObjectType getType<VkSwapchainKHR >() { return VK_OBJECT_TYPE_SWAPCHAIN_KHR; } + + + template<typename Ty> + static BX_NO_INLINE void setDebugObjectName(VkDevice _device, Ty _object, const char* _format, ...) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_OBJECT_NAME) + && s_extension[Extension::EXT_debug_utils].m_supported) + { + char temp[2048]; + va_list argList; + va_start(argList, _format); + int32_t size = bx::min<int32_t>(sizeof(temp)-1, bx::vsnprintf(temp, sizeof(temp), _format, argList) ); + va_end(argList); + temp[size] = '\0'; + + VkDebugUtilsObjectNameInfoEXT ni; + ni.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; + ni.pNext = NULL; + ni.objectType = getType<Ty>(); + ni.objectHandle = uint64_t(_object.vk); + ni.pObjectName = temp; + + VK_CHECK(vkSetDebugUtilsObjectNameEXT(_device, &ni) ); + } + } + + void setMemoryBarrier( + VkCommandBuffer _commandBuffer + , VkPipelineStageFlags _srcStages + , VkPipelineStageFlags _dstStages + ) + { + VkMemoryBarrier mb; + mb.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; + mb.pNext = NULL; + mb.srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; + mb.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; + + vkCmdPipelineBarrier( + _commandBuffer + , _srcStages + , _dstStages + , 0 + , 1 + , &mb + , 0 + , NULL + , 0 + , NULL + ); + } + + void setImageMemoryBarrier( + VkCommandBuffer _commandBuffer + , VkImage _image + , VkImageAspectFlags _aspectMask + , VkImageLayout _oldLayout + , VkImageLayout _newLayout + , uint32_t _baseMipLevel = 0 + , uint32_t _levelCount = VK_REMAINING_MIP_LEVELS + , uint32_t _baseArrayLayer = 0 + , uint32_t _layerCount = VK_REMAINING_ARRAY_LAYERS + ) { - BX_CHECK(true + BX_ASSERT(true && _newLayout != VK_IMAGE_LAYOUT_UNDEFINED && _newLayout != VK_IMAGE_LAYOUT_PREINITIALIZED , "_newLayout cannot use VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED." ); + constexpr VkPipelineStageFlags depthStageMask = 0 + | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT + | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT + ; + + constexpr VkPipelineStageFlags sampledStageMask = 0 + | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT + | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT + | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT + ; + + VkPipelineStageFlags srcStageMask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; + VkPipelineStageFlags dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT; + VkAccessFlags srcAccessMask = 0; VkAccessFlags dstAccessMask = 0; - VkImageAspectFlags aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; switch (_oldLayout) { case VK_IMAGE_LAYOUT_UNDEFINED: -// srcAccessMask |= VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; break; case VK_IMAGE_LAYOUT_GENERAL: + srcStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; + srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; break; case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: - srcAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; + srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: - srcAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + srcStageMask = depthStageMask; + srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + srcStageMask = depthStageMask | sampledStageMask; break; case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: - srcAccessMask |= VK_ACCESS_SHADER_READ_BIT; + srcStageMask = sampledStageMask; break; case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - srcAccessMask |= VK_ACCESS_TRANSFER_READ_BIT; + srcStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; break; case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: + srcStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; + srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; break; case VK_IMAGE_LAYOUT_PREINITIALIZED: - srcAccessMask |= VK_ACCESS_HOST_WRITE_BIT | VK_ACCESS_TRANSFER_WRITE_BIT; + srcStageMask = VK_PIPELINE_STAGE_HOST_BIT; + srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; break; case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: - srcAccessMask |= VK_ACCESS_MEMORY_READ_BIT; break; default: + BX_ASSERT(false, "Unknown image layout."); break; } switch (_newLayout) { - case VK_IMAGE_LAYOUT_UNDEFINED: - break; - case VK_IMAGE_LAYOUT_GENERAL: + dstStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; + dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; break; case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: - dstAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; + dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; + dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: - dstAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; - aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + dstStageMask = depthStageMask; + dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: + dstStageMask = depthStageMask | sampledStageMask; + dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT; break; case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: - dstAccessMask |= VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT; + dstStageMask = sampledStageMask; + dstAccessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT; break; case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: - dstAccessMask |= VK_ACCESS_SHADER_READ_BIT; + dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; + dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; break; case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: - dstAccessMask |= VK_ACCESS_TRANSFER_READ_BIT; - break; - - case VK_IMAGE_LAYOUT_PREINITIALIZED: + dstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; + dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; break; case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: - dstAccessMask |= VK_ACCESS_MEMORY_READ_BIT; + // vkQueuePresentKHR performs automatic visibility operations break; default: + BX_ASSERT(false, "Unknown image layout."); break; } @@ -678,14 +1085,14 @@ VK_IMPORT_DEVICE imb.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; imb.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; imb.image = _image; - imb.subresourceRange.aspectMask = aspectMask; - imb.subresourceRange.baseMipLevel = 0; - imb.subresourceRange.levelCount = 1; - imb.subresourceRange.baseArrayLayer = 0; - imb.subresourceRange.layerCount = 1; + imb.subresourceRange.aspectMask = _aspectMask; + imb.subresourceRange.baseMipLevel = _baseMipLevel; + imb.subresourceRange.levelCount = _levelCount; + imb.subresourceRange.baseArrayLayer = _baseArrayLayer; + imb.subresourceRange.layerCount = _layerCount; vkCmdPipelineBarrier(_commandBuffer - , VK_PIPELINE_STAGE_ALL_COMMANDS_BIT - , VK_PIPELINE_STAGE_ALL_COMMANDS_BIT + , srcStageMask + , dstStageMask , 0 , 0 , NULL @@ -696,15 +1103,20 @@ VK_IMPORT_DEVICE ); } +#define MAX_DESCRIPTOR_SETS (1024 * BGFX_CONFIG_MAX_FRAME_LATENCY) + struct RendererContextVK : public RendererContextI { RendererContextVK() : m_allocatorCb(NULL) , m_renderDocDll(NULL) , m_vulkan1Dll(NULL) - , m_maxAnisotropy(1) + , m_maxAnisotropy(1.0f) , m_depthClamp(false) , m_wireframe(false) + , m_captureBuffer(VK_NULL_HANDLE) + , m_captureMemory(VK_NULL_HANDLE) + , m_captureSize(0) { } @@ -714,8 +1126,6 @@ VK_IMPORT_DEVICE bool init(const Init& _init) { - BX_UNUSED(s_checkMsaa, s_textureAddress); - struct ErrorState { enum Enum @@ -724,24 +1134,31 @@ VK_IMPORT_DEVICE LoadedVulkan1, InstanceCreated, DeviceCreated, - RenderPassCreated, - SurfaceCreated, - SwapchainCreated, - CommandBuffersCreated, + CommandQueueCreated, + SwapChainCreated, DescriptorCreated, + TimerQueryCreated, }; }; ErrorState::Enum errorState = ErrorState::Default; + const bool headless = NULL == g_platformData.nwh; + + const void* nextFeatures = NULL; + VkPhysicalDeviceLineRasterizationFeaturesEXT lineRasterizationFeatures; + VkPhysicalDeviceCustomBorderColorFeaturesEXT customBorderColorFeatures; + + bx::memSet(&lineRasterizationFeatures, 0, sizeof(lineRasterizationFeatures) ); + bx::memSet(&customBorderColorFeatures, 0, sizeof(customBorderColorFeatures) ); + m_fbh.idx = kInvalidHandle; bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); bool imported = true; VkResult result; - m_qfiGraphics = UINT32_MAX; - m_qfiCompute = UINT32_MAX; + m_globalQueueFamily = UINT32_MAX; if (_init.debug || _init.profile) @@ -749,15 +1166,19 @@ VK_IMPORT_DEVICE m_renderDocDll = loadRenderDoc(); } + setGraphicsDebuggerPresent(NULL != m_renderDocDll); + m_vulkan1Dll = bx::dlopen( #if BX_PLATFORM_WINDOWS - "vulkan-1.dll" + "vulkan-1.dll" #elif BX_PLATFORM_ANDROID - "libvulkan.so" + "libvulkan.so" +#elif BX_PLATFORM_OSX + "libvulkan.dylib" #else - "libvulkan.so.1" + "libvulkan.so.1" #endif // BX_PLATFORM_* - ); + ); if (NULL == m_vulkan1Dll) { @@ -768,11 +1189,14 @@ VK_IMPORT_DEVICE errorState = ErrorState::LoadedVulkan1; BX_TRACE("Shared library functions:"); + #define VK_IMPORT_FUNC(_optional, _func) \ _func = (PFN_##_func)bx::dlsym(m_vulkan1Dll, #_func); \ BX_TRACE("\t%p " #_func, _func); \ imported &= _optional || NULL != _func + VK_IMPORT + #undef VK_IMPORT_FUNC if (!imported) @@ -782,53 +1206,127 @@ VK_IMPORT } { - dumpExtensions(); + s_layer[Layer::VK_LAYER_LUNARG_standard_validation].m_device.m_initialize = _init.debug; + s_layer[Layer::VK_LAYER_LUNARG_standard_validation].m_instance.m_initialize = _init.debug; + s_layer[Layer::VK_LAYER_KHRONOS_validation ].m_device.m_initialize = _init.debug; + s_layer[Layer::VK_LAYER_KHRONOS_validation ].m_instance.m_initialize = _init.debug; - VkApplicationInfo appInfo; - appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; - appInfo.pNext = NULL; - appInfo.pApplicationName = "bgfx"; - appInfo.applicationVersion = BGFX_API_VERSION; - appInfo.pEngineName = "bgfx"; - appInfo.engineVersion = BGFX_API_VERSION; - appInfo.apiVersion = VK_MAKE_VERSION(1, 0, 0); //VK_HEADER_VERSION); + s_extension[Extension::EXT_debug_report].m_initialize = _init.debug; - const char* enabledLayerNames[] = + s_extension[Extension::EXT_shader_viewport_index_layer].m_initialize = !!(_init.capabilities & BGFX_CAPS_VIEWPORT_LAYER_ARRAY); + s_extension[Extension::EXT_conservative_rasterization ].m_initialize = !!(_init.capabilities & BGFX_CAPS_CONSERVATIVE_RASTER ); + s_extension[Extension::KHR_draw_indirect_count ].m_initialize = !!(_init.capabilities & BGFX_CAPS_DRAW_INDIRECT_COUNT ); + + dumpExtensions(VK_NULL_HANDLE, s_extension); + + if (s_layer[Layer::VK_LAYER_KHRONOS_validation].m_device.m_supported + || s_layer[Layer::VK_LAYER_KHRONOS_validation].m_instance.m_supported) { -#if BGFX_CONFIG_DEBUG -// "VK_LAYER_GOOGLE_threading", -// "VK_LAYER_GOOGLE_unique_objects", -// "VK_LAYER_LUNARG_device_limits", -// "VK_LAYER_LUNARG_standard_validation", -// "VK_LAYER_LUNARG_image", -// "VK_LAYER_LUNARG_mem_tracker", -// "VK_LAYER_LUNARG_object_tracker", -// "VK_LAYER_LUNARG_parameter_validation", -// "VK_LAYER_LUNARG_swapchain", -// "VK_LAYER_LUNARG_vktrace", -// "VK_LAYER_RENDERDOC_Capture", -#endif // BGFX_CONFIG_DEBUG - /*not used*/ "" - }; + s_layer[Layer::VK_LAYER_LUNARG_standard_validation].m_device.m_supported = false; + s_layer[Layer::VK_LAYER_LUNARG_standard_validation].m_instance.m_supported = false; + } + + uint32_t numEnabledLayers = 0; + + const char* enabledLayer[Layer::Count]; + + BX_TRACE("Enabled instance layers:"); + + for (uint32_t ii = 0; ii < Layer::Count; ++ii) + { + const Layer& layer = s_layer[ii]; + + if (layer.m_instance.m_supported + && layer.m_instance.m_initialize) + { + enabledLayer[numEnabledLayers++] = layer.m_name; + BX_TRACE("\t%s", layer.m_name); + } + } +#if BX_PLATFORM_OSX || defined(WL_EGL_PLATFORM) + uint32_t numEnabledExtensions = headless ? 0 : 3; - const char* enabledExtension[] = + const char* enabledExtension[Extension::Count + 3] = +#else + uint32_t numEnabledExtensions = headless ? 0 : 1; + + const char* enabledExtension[Extension::Count + 1] = +#endif { VK_KHR_SURFACE_EXTENSION_NAME, - KHR_SURFACE_EXTENSION_NAME, -#if BGFX_CONFIG_DEBUG - VK_EXT_DEBUG_REPORT_EXTENSION_NAME, -#endif // BGFX_CONFIG_DEBUG - /*not used*/ "" +#if BX_PLATFORM_OSX + VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, +#endif }; + for (uint32_t ii = 0; ii < Extension::Count; ++ii) + { + const Extension& extension = s_extension[ii]; + const LayerInfo& layerInfo = s_layer[extension.m_layer].m_instance; + + const bool layerEnabled = false + || extension.m_layer == Layer::Count + || (layerInfo.m_supported && layerInfo.m_initialize) + ; + + if (extension.m_supported + && extension.m_initialize + && extension.m_instanceExt + && layerEnabled) + { + enabledExtension[numEnabledExtensions++] = extension.m_name; + } + } + + BX_TRACE("Enabled instance extensions:"); + + for (uint32_t ii = 0; ii < numEnabledExtensions; ++ii) + { + BX_TRACE("\t%s", enabledExtension[ii]); + } + + uint32_t vulkanApiVersionSelector; + + if (NULL != vkEnumerateInstanceVersion) + { + result = vkEnumerateInstanceVersion(&vulkanApiVersionSelector); + + if (VK_SUCCESS != result) + { + BX_TRACE( + "Init error: vkEnumerateInstanceVersion failed %d: %s." + , result + , getName(result) + ); + goto error; + } + } + else + { + vulkanApiVersionSelector = VK_API_VERSION_1_0; + } + + VkApplicationInfo appInfo; + appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; + appInfo.pNext = NULL; + appInfo.pApplicationName = "bgfx"; + appInfo.applicationVersion = BGFX_API_VERSION; + appInfo.pEngineName = "bgfx"; + appInfo.engineVersion = BGFX_API_VERSION; + appInfo.apiVersion = vulkanApiVersionSelector; + VkInstanceCreateInfo ici; ici.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; ici.pNext = NULL; +#if BX_PLATFORM_OSX + ici.flags = 0 | VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; +#else ici.flags = 0; - ici.pApplicationInfo = &appInfo; - ici.enabledLayerCount = BX_COUNTOF(enabledLayerNames) - 1; - ici.ppEnabledLayerNames = enabledLayerNames; - ici.enabledExtensionCount = BX_COUNTOF(enabledExtension) - 1; +#endif + ici.pApplicationInfo = &appInfo; + ici.enabledLayerCount = numEnabledLayers; + ici.ppEnabledLayerNames = enabledLayer; + ici.enabledExtensionCount = numEnabledExtensions; ici.ppEnabledExtensionNames = enabledExtension; if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) @@ -837,16 +1335,26 @@ VK_IMPORT BX_UNUSED(s_allocationCb); } - result = vkCreateInstance(&ici - , m_allocatorCb - , &m_instance - ); - } + result = vkCreateInstance( + &ici + , m_allocatorCb + , &m_instance + ); - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateInstance failed %d: %s.", result, getName(result) ); - goto error; + if (VK_SUCCESS != result) + { + BX_TRACE("Init error: vkCreateInstance failed %d: %s.", result, getName(result) ); + goto error; + } + + m_instanceApiVersion = vulkanApiVersionSelector; + + BX_TRACE("Instance API version: %d.%d.%d" + , VK_API_VERSION_MAJOR(m_instanceApiVersion) + , VK_API_VERSION_MINOR(m_instanceApiVersion) + , VK_API_VERSION_PATCH(m_instanceApiVersion) + ); + BX_TRACE("Instance variant: %d", VK_API_VERSION_VARIANT(m_instanceApiVersion) ); } errorState = ErrorState::InstanceCreated; @@ -868,7 +1376,7 @@ VK_IMPORT_INSTANCE m_debugReportCallback = VK_NULL_HANDLE; - if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) + if (s_extension[Extension::EXT_debug_report].m_supported) { VkDebugReportCallbackCreateInfoEXT drcb; drcb.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT; @@ -903,7 +1411,7 @@ VK_IMPORT_INSTANCE } VkPhysicalDevice physicalDevices[4]; - numPhysicalDevices = bx::uint32_min(numPhysicalDevices, BX_COUNTOF(physicalDevices) ); + numPhysicalDevices = bx::min<uint32_t>(numPhysicalDevices, BX_COUNTOF(physicalDevices) ); result = vkEnumeratePhysicalDevices(m_instance , &numPhysicalDevices , physicalDevices @@ -915,7 +1423,10 @@ VK_IMPORT_INSTANCE goto error; } - m_physicalDevice = VK_NULL_HANDLE; + Extension physicalDeviceExtensions[4][Extension::Count]; + + uint32_t physicalDeviceIdx = UINT32_MAX; + uint32_t fallbackPhysicalDeviceIdx = UINT32_MAX; for (uint32_t ii = 0; ii < numPhysicalDevices; ++ii) { @@ -923,7 +1434,12 @@ VK_IMPORT_INSTANCE vkGetPhysicalDeviceProperties(physicalDevices[ii], &pdp); BX_TRACE("Physical device %d:", ii); BX_TRACE("\t Name: %s", pdp.deviceName); - BX_TRACE("\t API version: %x", pdp.apiVersion); + BX_TRACE("\t API version: %d.%d.%d" + , VK_API_VERSION_MAJOR(pdp.apiVersion) + , VK_API_VERSION_MINOR(pdp.apiVersion) + , VK_API_VERSION_PATCH(pdp.apiVersion) + ); + BX_TRACE("\t API variant: %d", VK_API_VERSION_VARIANT(pdp.apiVersion) ); BX_TRACE("\tDriver version: %x", pdp.driverVersion); BX_TRACE("\t VendorId: %x", pdp.vendorID); BX_TRACE("\t DeviceId: %x", pdp.deviceID); @@ -937,7 +1453,24 @@ VK_IMPORT_INSTANCE && (BGFX_PCI_ID_NONE == g_caps.vendorId || pdp.vendorID == g_caps.vendorId) && (0 == g_caps.deviceId || pdp.deviceID == g_caps.deviceId) ) { - m_physicalDevice = physicalDevices[ii]; + if (pdp.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU + || pdp.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) + { + fallbackPhysicalDeviceIdx = ii; + } + + physicalDeviceIdx = ii; + } + else + { + if (pdp.deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU) + { + fallbackPhysicalDeviceIdx = ii; + } + else if (pdp.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) + { + physicalDeviceIdx = ii; + } } VkPhysicalDeviceMemoryProperties pdmp; @@ -947,10 +1480,10 @@ VK_IMPORT_INSTANCE for (uint32_t jj = 0; jj < pdmp.memoryTypeCount; ++jj) { BX_TRACE("\t%3d: flags 0x%08x, index %d" - , jj - , pdmp.memoryTypes[jj].propertyFlags - , pdmp.memoryTypes[jj].heapIndex - ); + , jj + , pdmp.memoryTypes[jj].propertyFlags + , pdmp.memoryTypes[jj].heapIndex + ); } BX_TRACE("\tMemory heap count: %d", pdmp.memoryHeapCount); @@ -959,51 +1492,189 @@ VK_IMPORT_INSTANCE char size[16]; bx::prettify(size, BX_COUNTOF(size), pdmp.memoryHeaps[jj].size); BX_TRACE("\t%3d: flags 0x%08x, size %10s" - , jj - , pdmp.memoryHeaps[jj].flags - , size - ); + , jj + , pdmp.memoryHeaps[jj].flags + , size + ); } - dumpExtensions(physicalDevices[ii]); + bx::memCopy(&physicalDeviceExtensions[ii][0], &s_extension[0], sizeof(s_extension) ); + dumpExtensions(physicalDevices[ii], physicalDeviceExtensions[ii]); } - if (VK_NULL_HANDLE == m_physicalDevice) + if (UINT32_MAX == physicalDeviceIdx) { - m_physicalDevice = physicalDevices[0]; + physicalDeviceIdx = UINT32_MAX == fallbackPhysicalDeviceIdx + ? 0 + : fallbackPhysicalDeviceIdx + ; } + m_physicalDevice = physicalDevices[physicalDeviceIdx]; + + bx::memCopy(&s_extension[0], &physicalDeviceExtensions[physicalDeviceIdx][0], sizeof(s_extension) ); + vkGetPhysicalDeviceProperties(m_physicalDevice, &m_deviceProperties); g_caps.vendorId = uint16_t(m_deviceProperties.vendorID); g_caps.deviceId = uint16_t(m_deviceProperties.deviceID); + BX_TRACE("Using physical device %d: %s", physicalDeviceIdx, m_deviceProperties.deviceName); + + VkPhysicalDeviceFeatures supportedFeatures; + + if (s_extension[Extension::KHR_get_physical_device_properties2].m_supported) + { + VkPhysicalDeviceFeatures2KHR deviceFeatures2; + deviceFeatures2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR; + deviceFeatures2.pNext = NULL; + + VkBaseOutStructure* next = (VkBaseOutStructure*)&deviceFeatures2; + + if (s_extension[Extension::EXT_line_rasterization].m_supported) + { + next->pNext = (VkBaseOutStructure*)&lineRasterizationFeatures; + next = (VkBaseOutStructure*)&lineRasterizationFeatures; + lineRasterizationFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT; + lineRasterizationFeatures.pNext = NULL; + } + + if (s_extension[Extension::EXT_custom_border_color].m_supported) + { + next->pNext = (VkBaseOutStructure*)&customBorderColorFeatures; + next = (VkBaseOutStructure*)&customBorderColorFeatures; + customBorderColorFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT; + customBorderColorFeatures.pNext = NULL; + } + + nextFeatures = deviceFeatures2.pNext; + + vkGetPhysicalDeviceFeatures2KHR(m_physicalDevice, &deviceFeatures2); + supportedFeatures = deviceFeatures2.features; + } + else + { + vkGetPhysicalDeviceFeatures(m_physicalDevice, &supportedFeatures); + } + + bx::memSet(&m_deviceFeatures, 0, sizeof(m_deviceFeatures) ); + + m_deviceFeatures.fullDrawIndexUint32 = supportedFeatures.fullDrawIndexUint32; + m_deviceFeatures.imageCubeArray = supportedFeatures.imageCubeArray && (_init.capabilities & BGFX_CAPS_TEXTURE_CUBE_ARRAY); + m_deviceFeatures.independentBlend = supportedFeatures.independentBlend && (_init.capabilities & BGFX_CAPS_BLEND_INDEPENDENT); + m_deviceFeatures.multiDrawIndirect = supportedFeatures.multiDrawIndirect && (_init.capabilities & BGFX_CAPS_DRAW_INDIRECT); + m_deviceFeatures.drawIndirectFirstInstance = supportedFeatures.drawIndirectFirstInstance && (_init.capabilities & BGFX_CAPS_DRAW_INDIRECT); + m_deviceFeatures.depthClamp = supportedFeatures.depthClamp; + m_deviceFeatures.fillModeNonSolid = supportedFeatures.fillModeNonSolid; + m_deviceFeatures.largePoints = supportedFeatures.largePoints; + m_deviceFeatures.samplerAnisotropy = supportedFeatures.samplerAnisotropy; + m_deviceFeatures.textureCompressionETC2 = supportedFeatures.textureCompressionETC2; + m_deviceFeatures.textureCompressionBC = supportedFeatures.textureCompressionBC; + m_deviceFeatures.vertexPipelineStoresAndAtomics = supportedFeatures.vertexPipelineStoresAndAtomics; + m_deviceFeatures.fragmentStoresAndAtomics = supportedFeatures.fragmentStoresAndAtomics; + m_deviceFeatures.shaderImageGatherExtended = supportedFeatures.shaderImageGatherExtended; + m_deviceFeatures.shaderStorageImageExtendedFormats = supportedFeatures.shaderStorageImageExtendedFormats; + m_deviceFeatures.shaderClipDistance = supportedFeatures.shaderClipDistance; + m_deviceFeatures.shaderCullDistance = supportedFeatures.shaderCullDistance; + m_deviceFeatures.shaderResourceMinLod = supportedFeatures.shaderResourceMinLod; + + m_lineAASupport = true + && s_extension[Extension::EXT_line_rasterization].m_supported + && lineRasterizationFeatures.smoothLines + ; + + m_borderColorSupport = true + && s_extension[Extension::EXT_custom_border_color].m_supported + && customBorderColorFeatures.customBorderColors + ; + + m_timerQuerySupport = m_deviceProperties.limits.timestampComputeAndGraphics; + + const bool indirectDrawSupport = true + && m_deviceFeatures.multiDrawIndirect + && m_deviceFeatures.drawIndirectFirstInstance + ; + + g_caps.supported |= ( 0 + | BGFX_CAPS_ALPHA_TO_COVERAGE + | (m_deviceFeatures.independentBlend ? BGFX_CAPS_BLEND_INDEPENDENT : 0) + | BGFX_CAPS_COMPUTE + | (indirectDrawSupport ? BGFX_CAPS_DRAW_INDIRECT : 0) + | BGFX_CAPS_FRAGMENT_DEPTH + | BGFX_CAPS_IMAGE_RW + | (m_deviceFeatures.fullDrawIndexUint32 ? BGFX_CAPS_INDEX32 : 0) + | BGFX_CAPS_INSTANCING + | BGFX_CAPS_OCCLUSION_QUERY + | (!headless ? BGFX_CAPS_SWAP_CHAIN : 0) + | BGFX_CAPS_TEXTURE_2D_ARRAY + | BGFX_CAPS_TEXTURE_3D + | BGFX_CAPS_TEXTURE_BLIT + | BGFX_CAPS_TEXTURE_COMPARE_ALL + | (m_deviceFeatures.imageCubeArray ? BGFX_CAPS_TEXTURE_CUBE_ARRAY : 0) + | BGFX_CAPS_TEXTURE_READ_BACK + | BGFX_CAPS_VERTEX_ATTRIB_HALF + | BGFX_CAPS_VERTEX_ATTRIB_UINT10 + | BGFX_CAPS_VERTEX_ID + ); + + g_caps.supported |= 0 + | (s_extension[Extension::EXT_conservative_rasterization ].m_supported ? BGFX_CAPS_CONSERVATIVE_RASTER : 0) + | (s_extension[Extension::EXT_shader_viewport_index_layer].m_supported ? BGFX_CAPS_VIEWPORT_LAYER_ARRAY : 0) + | (s_extension[Extension::KHR_draw_indirect_count ].m_supported && indirectDrawSupport ? BGFX_CAPS_DRAW_INDIRECT_COUNT : 0) + ; + + const uint32_t maxAttachments = bx::min<uint32_t>(m_deviceProperties.limits.maxFragmentOutputAttachments, m_deviceProperties.limits.maxColorAttachments); + g_caps.limits.maxTextureSize = m_deviceProperties.limits.maxImageDimension2D; - g_caps.limits.maxFBAttachments = uint8_t(bx::uint32_min(m_deviceProperties.limits.maxFragmentOutputAttachments, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) ); - g_caps.limits.maxComputeBindings = BGFX_MAX_COMPUTE_BINDINGS; + g_caps.limits.maxTextureLayers = m_deviceProperties.limits.maxImageArrayLayers; + g_caps.limits.maxFBAttachments = bx::min<uint32_t>(maxAttachments, BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS); + g_caps.limits.maxTextureSamplers = bx::min<uint32_t>(m_deviceProperties.limits.maxPerStageResources, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS); + g_caps.limits.maxComputeBindings = bx::min<uint32_t>(m_deviceProperties.limits.maxPerStageResources, BGFX_MAX_COMPUTE_BINDINGS); + g_caps.limits.maxVertexStreams = bx::min<uint32_t>(m_deviceProperties.limits.maxVertexInputBindings, BGFX_CONFIG_MAX_VERTEX_STREAMS); { -// VkFormatProperties fp; -// vkGetPhysicalDeviceFormatProperties(m_physicalDevice, fmt, &fp); + const VkSampleCountFlags sampleMask = ~0 + & m_deviceProperties.limits.framebufferColorSampleCounts + & m_deviceProperties.limits.framebufferDepthSampleCounts + ; + + for (uint16_t ii = 0, last = 0; ii < BX_COUNTOF(s_msaa); ii++) + { + const VkSampleCountFlags sampleBit = s_msaa[ii].Sample; + + if (sampleBit & sampleMask) + { + last = ii; + } + else + { + s_msaa[ii] = s_msaa[last]; + } + } + } + { struct ImageTest { - VkImageType type; - VkImageUsageFlags usage; + VkImageType type; + VkImageUsageFlags usage; VkImageCreateFlags flags; - uint32_t formatCaps[2]; + uint32_t formatCaps[2]; }; const ImageTest imageTest[] = { - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_2D, BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB } }, - { VK_IMAGE_TYPE_3D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_3D, BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB } }, - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, { BGFX_CAPS_FORMAT_TEXTURE_CUBE, BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB } }, - { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER, BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_2D, BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB } }, + { VK_IMAGE_TYPE_3D, VK_IMAGE_USAGE_SAMPLED_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_3D, BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, { BGFX_CAPS_FORMAT_TEXTURE_CUBE, BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER, 0 } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER, 0 } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_STORAGE_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_IMAGE_READ, 0 } }, + { VK_IMAGE_TYPE_2D, VK_IMAGE_USAGE_STORAGE_BIT, 0, { BGFX_CAPS_FORMAT_TEXTURE_IMAGE_WRITE, 0 } }, }; for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) { - uint8_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; + uint16_t support = BGFX_CAPS_FORMAT_TEXTURE_NONE; const bool depth = bimg::isDepth(bimg::TextureFormat::Enum(ii) ); VkFormat fmt = depth @@ -1032,9 +1703,22 @@ VK_IMPORT_INSTANCE if (VK_SUCCESS == result) { support |= it.formatCaps[jj]; - if (VK_SAMPLE_COUNT_1_BIT < ifp.sampleCounts) + + const bool multisample = VK_SAMPLE_COUNT_1_BIT < ifp.sampleCounts; + if (it.usage & VK_IMAGE_USAGE_SAMPLED_BIT) + { + support |= 0 + | BGFX_CAPS_FORMAT_TEXTURE_VERTEX + | (multisample ? BGFX_CAPS_FORMAT_TEXTURE_MSAA : 0) + ; + } + + if (it.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ) { - support |= BGFX_CAPS_FORMAT_TEXTURE_MSAA; + support |= 0 + | BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN + | (multisample ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA : 0) + ; } } } @@ -1054,14 +1738,15 @@ VK_IMPORT_INSTANCE BX_TRACE("---"); uint32_t queueFamilyPropertyCount = 0; - vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice + vkGetPhysicalDeviceQueueFamilyProperties( + m_physicalDevice , &queueFamilyPropertyCount , NULL ); - VkQueueFamilyProperties queueFamilyPropertices[10] = {}; - queueFamilyPropertyCount = bx::uint32_min(queueFamilyPropertyCount, BX_COUNTOF(queueFamilyPropertices) ); - vkGetPhysicalDeviceQueueFamilyProperties(m_physicalDevice + VkQueueFamilyProperties* queueFamilyPropertices = (VkQueueFamilyProperties*)BX_ALLOC(g_allocator, queueFamilyPropertyCount * sizeof(VkQueueFamilyProperties) ); + vkGetPhysicalDeviceQueueFamilyProperties( + m_physicalDevice , &queueFamilyPropertyCount , queueFamilyPropertices ); @@ -1069,98 +1754,121 @@ VK_IMPORT_INSTANCE for (uint32_t ii = 0; ii < queueFamilyPropertyCount; ++ii) { const VkQueueFamilyProperties& qfp = queueFamilyPropertices[ii]; - BX_UNUSED(qfp); + BX_TRACE("Queue family property %d:", ii); BX_TRACE("\t Queue flags: 0x%08x", qfp.queueFlags); BX_TRACE("\t Queue count: %d", qfp.queueCount); BX_TRACE("\tTS valid bits: 0x%08x", qfp.timestampValidBits); BX_TRACE("\t Min image: %d x %d x %d" - , qfp.minImageTransferGranularity.width - , qfp.minImageTransferGranularity.height - , qfp.minImageTransferGranularity.depth - ); - } - - for (uint32_t ii = 0; ii < queueFamilyPropertyCount; ++ii) - { - const VkQueueFamilyProperties& qfp = queueFamilyPropertices[ii]; - if (UINT32_MAX == m_qfiGraphics - && VK_QUEUE_GRAPHICS_BIT & qfp.queueFlags) - { - m_qfiGraphics = ii; - } + , qfp.minImageTransferGranularity.width + , qfp.minImageTransferGranularity.height + , qfp.minImageTransferGranularity.depth + ); - if (UINT32_MAX == m_qfiCompute - && VK_QUEUE_COMPUTE_BIT & qfp.queueFlags) - { - m_qfiCompute = ii; - } + constexpr VkQueueFlags requiredFlags = VK_QUEUE_GRAPHICS_BIT | VK_QUEUE_COMPUTE_BIT; - if (UINT32_MAX != m_qfiGraphics - && UINT32_MAX != m_qfiCompute) + if (UINT32_MAX == m_globalQueueFamily + && requiredFlags == (requiredFlags & qfp.queueFlags) ) { - break; + m_globalQueueFamily = ii; } } - if (UINT32_MAX == m_qfiGraphics) + BX_FREE(g_allocator, queueFamilyPropertices); + + if (UINT32_MAX == m_globalQueueFamily) { - BX_TRACE("Init error: Unable to find graphics queue."); + BX_TRACE("Init error: Unable to find combined graphics and compute queue."); goto error; } } { - const char* enabledLayerNames[] = + uint32_t numEnabledLayers = 0; + + const char* enabledLayer[Layer::Count]; + + BX_TRACE("Enabled device layers:"); + + for (uint32_t ii = 0; ii < Layer::Count; ++ii) { -#if BGFX_CONFIG_DEBUG - "VK_LAYER_GOOGLE_threading", -// "VK_LAYER_GOOGLE_unique_objects", - "VK_LAYER_LUNARG_device_limits", -// "VK_LAYER_LUNARG_standard_validation", - "VK_LAYER_LUNARG_image", - "VK_LAYER_LUNARG_object_tracker", - "VK_LAYER_LUNARG_parameter_validation", - "VK_LAYER_LUNARG_swapchain", -// "VK_LAYER_LUNARG_vktrace", -// "VK_LAYER_RENDERDOC_Capture", -#endif // BGFX_CONFIG_DEBUG - /*not used*/ "" - }; + const Layer& layer = s_layer[ii]; + + if (layer.m_device.m_supported + && layer.m_device.m_initialize) + { + enabledLayer[numEnabledLayers++] = layer.m_name; + BX_TRACE("\t%s", layer.m_name); + } + } +#if BX_PLATFORM_OSX + uint32_t numEnabledExtensions = headless ? 1 : 3; - const char* enabledExtension[] = + const char* enabledExtension[Extension::Count + 3] = +#else + uint32_t numEnabledExtensions = headless ? 1 : 2; + + const char* enabledExtension[Extension::Count + 2] = +#endif { + VK_KHR_MAINTENANCE1_EXTENSION_NAME, VK_KHR_SWAPCHAIN_EXTENSION_NAME, -// "VK_LUNARG_DEBUG_MARKER", - /*not used*/ "" +#if BX_PLATFORM_OSX + "VK_KHR_portability_subset", +#endif }; + for (uint32_t ii = 0; ii < Extension::Count; ++ii) + { + const Extension& extension = s_extension[ii]; + + bool layerEnabled = extension.m_layer == Layer::Count || + (s_layer[extension.m_layer].m_device.m_supported && + s_layer[extension.m_layer].m_device.m_initialize); + + if (extension.m_supported + && extension.m_initialize + && !extension.m_instanceExt + && layerEnabled) + { + enabledExtension[numEnabledExtensions++] = extension.m_name; + } + } + + BX_TRACE("Enabled device extensions:"); + + for (uint32_t ii = 0; ii < numEnabledExtensions; ++ii) + { + BX_TRACE("\t%s", enabledExtension[ii]); + } + float queuePriorities[1] = { 0.0f }; VkDeviceQueueCreateInfo dcqi; dcqi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; dcqi.pNext = NULL; dcqi.flags = 0; - dcqi.queueFamilyIndex = m_qfiGraphics; + dcqi.queueFamilyIndex = m_globalQueueFamily; dcqi.queueCount = 1; dcqi.pQueuePriorities = queuePriorities; VkDeviceCreateInfo dci; dci.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; - dci.pNext = NULL; + dci.pNext = nextFeatures; dci.flags = 0; dci.queueCreateInfoCount = 1; dci.pQueueCreateInfos = &dcqi; - dci.enabledLayerCount = BX_COUNTOF(enabledLayerNames) - 1; - dci.ppEnabledLayerNames = enabledLayerNames; - dci.enabledExtensionCount = BX_COUNTOF(enabledExtension) - 1; + dci.enabledLayerCount = numEnabledLayers; + dci.ppEnabledLayerNames = enabledLayer; + dci.enabledExtensionCount = numEnabledExtensions; dci.ppEnabledExtensionNames = enabledExtension; - dci.pEnabledFeatures = NULL; + dci.pEnabledFeatures = &m_deviceFeatures; - result = vkCreateDevice(m_physicalDevice - , &dci - , m_allocatorCb - , &m_device - ); + result = vkCreateDevice( + m_physicalDevice + , &dci + , m_allocatorCb + , &m_device + ); if (VK_SUCCESS != result) { @@ -1172,9 +1880,9 @@ VK_IMPORT_INSTANCE errorState = ErrorState::DeviceCreated; BX_TRACE("Device functions:"); -#define VK_IMPORT_DEVICE_FUNC(_optional, _func) \ +#define VK_IMPORT_DEVICE_FUNC(_optional, _func) \ _func = (PFN_##_func)vkGetDeviceProcAddr(m_device, #_func); \ - BX_TRACE("\t%p " #_func, _func); \ + BX_TRACE("\t%p " #_func, _func); \ imported &= _optional || NULL != _func VK_IMPORT_DEVICE #undef VK_IMPORT_DEVICE_FUNC @@ -1185,537 +1893,83 @@ VK_IMPORT_DEVICE goto error; } - vkGetDeviceQueue(m_device, m_qfiGraphics, 0, &m_queueGraphics); - vkGetDeviceQueue(m_device, m_qfiCompute, 0, &m_queueCompute); - - m_backBufferDepthStencilFormat = - VK_FORMAT_D32_SFLOAT_S8_UINT -// VK_FORMAT_D24_UNORM_S8_UINT - ; - - { - m_sci.imageFormat = VK_FORMAT_B8G8R8A8_UNORM; - - VkAttachmentDescription ad[2]; - ad[0].flags = 0; - ad[0].format = m_sci.imageFormat; - ad[0].samples = VK_SAMPLE_COUNT_1_BIT; - ad[0].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - ad[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE; - ad[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - ad[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - ad[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - ad[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - ad[1].flags = 0; - ad[1].format = m_backBufferDepthStencilFormat; - ad[1].samples = VK_SAMPLE_COUNT_1_BIT; - ad[1].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - ad[1].storeOp = VK_ATTACHMENT_STORE_OP_STORE; - ad[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; - ad[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; - ad[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - ad[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - - VkAttachmentReference colorAr[1]; - colorAr[0].attachment = 0; - colorAr[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - - VkAttachmentReference resolveAr[1]; - resolveAr[0].attachment = VK_ATTACHMENT_UNUSED; - resolveAr[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - - VkAttachmentReference depthAr[1]; - depthAr[0].attachment = 1; - depthAr[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; - - VkSubpassDescription sd[1]; - sd[0].flags = 0; - sd[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; - sd[0].inputAttachmentCount = 0; - sd[0].pInputAttachments = NULL; - sd[0].colorAttachmentCount = BX_COUNTOF(colorAr); - sd[0].pColorAttachments = colorAr; - sd[0].pResolveAttachments = resolveAr; - sd[0].pDepthStencilAttachment = depthAr; - sd[0].preserveAttachmentCount = 0; - sd[0].pPreserveAttachments = NULL; - - VkRenderPassCreateInfo rpi; - rpi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; - rpi.pNext = NULL; - rpi.flags = 0; - rpi.attachmentCount = BX_COUNTOF(ad); - rpi.pAttachments = ad; - rpi.subpassCount = BX_COUNTOF(sd); - rpi.pSubpasses = sd; - rpi.dependencyCount = 0; - rpi.pDependencies = NULL; - - result = vkCreateRenderPass(m_device, &rpi, m_allocatorCb, &m_renderPass); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateRenderPass failed %d: %s.", result, getName(result) ); - goto error; - } - } - - errorState = ErrorState::RenderPassCreated; - -#if BX_PLATFORM_WINDOWS - { - VkWin32SurfaceCreateInfoKHR sci; - sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; - sci.pNext = NULL; - sci.flags = 0; - sci.hinstance = (HINSTANCE)GetModuleHandle(NULL); - sci.hwnd = (HWND)g_platformData.nwh; - result = vkCreateWin32SurfaceKHR(m_instance, &sci, m_allocatorCb, &m_surface); - } -#elif BX_PLATFORM_ANDROID - { - VkAndroidSurfaceCreateInfoKHR sci; - sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; - sci.pNext = NULL; - sci.flags = 0; - result = vkCreateAndroidSurfaceKHR(m_instance, &sci, m_allocatorCb, &m_surface); - } -#elif BX_PLATFORM_LINUX - { - if (NULL != vkCreateXlibSurfaceKHR) - { - VkXlibSurfaceCreateInfoKHR sci; - sci.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; - sci.pNext = NULL; - sci.flags = 0; - sci.dpy = (Display*)g_platformData.ndt; - sci.window = (Window)g_platformData.nwh; - result = vkCreateXlibSurfaceKHR(m_instance, &sci, m_allocatorCb, &m_surface); - } - else - { - result = VK_RESULT_MAX_ENUM; - } - - if (VK_SUCCESS != result) - { - void* xcbdll = bx::dlopen("libX11-xcb.so.1"); - if (NULL != xcbdll) - { - typedef xcb_connection_t* (*PFN_XGETXCBCONNECTION)(Display*); - PFN_XGETXCBCONNECTION XGetXCBConnection = (PFN_XGETXCBCONNECTION)bx::dlsym(xcbdll, "XGetXCBConnection"); - - VkXcbSurfaceCreateInfoKHR sci; - sci.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; - sci.pNext = NULL; - sci.flags = 0; - sci.connection = XGetXCBConnection( (Display*)g_platformData.ndt); - union { void* ptr; xcb_window_t window; } cast = { g_platformData.nwh }; - sci.window = cast.window; - result = vkCreateXcbSurfaceKHR(m_instance, &sci, m_allocatorCb, &m_surface); - - bx::dlclose(xcbdll); - } - } - } -#else -# error "Figure out KHR surface..." -#endif // BX_PLATFORM_ - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateSurfaceKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - errorState = ErrorState::SurfaceCreated; + vkGetDeviceQueue(m_device, m_globalQueueFamily, 0, &m_globalQueue); { - VkBool32 surfaceSupported; - result = vkGetPhysicalDeviceSurfaceSupportKHR(m_physicalDevice, m_qfiGraphics, m_surface, &surfaceSupported); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkGetPhysicalDeviceSurfaceSupportKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - VkSurfaceCapabilitiesKHR surfaceCapabilities; - result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(m_physicalDevice, m_surface, &surfaceCapabilities); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkGetPhysicalDeviceSurfaceCapabilitiesKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - uint32_t numSurfaceFormats; - result = vkGetPhysicalDeviceSurfaceFormatsKHR(m_physicalDevice, m_surface, &numSurfaceFormats, NULL); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkGetPhysicalDeviceSurfaceFormatsKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - VkSurfaceFormatKHR surfaceFormats[10]; - numSurfaceFormats = bx::uint32_min(numSurfaceFormats, BX_COUNTOF(surfaceFormats) ); - vkGetPhysicalDeviceSurfaceFormatsKHR(m_physicalDevice, m_surface, &numSurfaceFormats, surfaceFormats); - - // find the best match... - uint32_t surfaceFormatIdx = 0; - - uint32_t numPresentModes; - result = vkGetPhysicalDeviceSurfacePresentModesKHR(m_physicalDevice, m_surface, &numPresentModes, NULL); - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkGetPhysicalDeviceSurfacePresentModesKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - VkPresentModeKHR presentModes[10]; - numPresentModes = bx::uint32_min(numPresentModes, BX_COUNTOF(presentModes) ); - vkGetPhysicalDeviceSurfacePresentModesKHR(m_physicalDevice, m_surface, &numPresentModes, presentModes); - - // find the best match... - uint32_t presentModeIdx = 0; - - m_sci.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; - m_sci.pNext = NULL; - m_sci.flags = 0; - m_sci.surface = m_surface; - m_sci.minImageCount = BX_COUNTOF(m_backBufferColorImage); - m_sci.imageFormat = surfaceFormats[surfaceFormatIdx].format; - m_sci.imageColorSpace = surfaceFormats[surfaceFormatIdx].colorSpace; - m_sci.imageExtent.width = _init.resolution.width; - m_sci.imageExtent.height = _init.resolution.height; - m_sci.imageArrayLayers = 1; - m_sci.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - m_sci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; - m_sci.queueFamilyIndexCount = 0; - m_sci.pQueueFamilyIndices = NULL; - m_sci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; - m_sci.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - m_sci.presentMode = presentModes[presentModeIdx]; - m_sci.clipped = VK_TRUE; - m_sci.oldSwapchain = VK_NULL_HANDLE; - result = vkCreateSwapchainKHR(m_device, &m_sci, m_allocatorCb, &m_swapchain); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateSwapchainKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - uint32_t numSwapchainImages; - result = vkGetSwapchainImagesKHR(m_device, m_swapchain, &numSwapchainImages, NULL); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkGetSwapchainImagesKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - if (numSwapchainImages < m_sci.minImageCount) - { - BX_TRACE("Init error: vkGetSwapchainImagesKHR: numSwapchainImages %d, minImageCount %d." - , numSwapchainImages - , m_sci.minImageCount - ); - goto error; - } - - numSwapchainImages = m_sci.minImageCount; - result = vkGetSwapchainImagesKHR(m_device, m_swapchain, &numSwapchainImages, &m_backBufferColorImage[0]); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkGetSwapchainImagesKHR failed %d: %s.", result, getName(result) ); - goto error; - } - - for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImageView); ++ii) - { - m_backBufferColorImageView[ii] = VK_NULL_HANDLE; - m_backBufferColor[ii] = VK_NULL_HANDLE; - } - - VkImageCreateInfo ici; - ici.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - ici.pNext = NULL; - ici.flags = 0; - ici.imageType = VK_IMAGE_TYPE_2D; - ici.format = m_backBufferDepthStencilFormat; - ici.extent.width = m_sci.imageExtent.width; - ici.extent.height = m_sci.imageExtent.height; - ici.extent.depth = 1; - ici.mipLevels = 1; - ici.arrayLayers = 1; - ici.samples = VK_SAMPLE_COUNT_1_BIT; - ici.tiling = VK_IMAGE_TILING_OPTIMAL; - ici.usage = 0 - | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT - | VK_IMAGE_USAGE_TRANSFER_SRC_BIT + m_numFramesInFlight = _init.resolution.maxFrameLatency == 0 + ? BGFX_CONFIG_MAX_FRAME_LATENCY + : _init.resolution.maxFrameLatency ; - ici.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - ici.queueFamilyIndexCount = 0; //m_sci.queueFamilyIndexCount; - ici.pQueueFamilyIndices = NULL; //m_sci.pQueueFamilyIndices; - ici.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - result = vkCreateImage(m_device, &ici, m_allocatorCb, &m_backBufferDepthStencilImage); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateImage failed %d: %s.", result, getName(result) ); - goto error; - } - - VkMemoryRequirements mr; - vkGetImageMemoryRequirements(m_device, m_backBufferDepthStencilImage, &mr); - VkMemoryAllocateInfo ma; - ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - ma.pNext = NULL; - ma.allocationSize = mr.size; - ma.memoryTypeIndex = selectMemoryType(mr.memoryTypeBits - , VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT - ); - result = vkAllocateMemory(m_device - , &ma - , m_allocatorCb - , &m_backBufferDepthStencilMemory - ); + result = m_cmd.init(m_globalQueueFamily, m_globalQueue, m_numFramesInFlight); if (VK_SUCCESS != result) { - BX_TRACE("Init error: vkAllocateMemory failed %d: %s.", result, getName(result) ); + BX_TRACE("Init error: creating command queue failed %d: %s.", result, getName(result) ); goto error; } - result = vkBindImageMemory(m_device, m_backBufferDepthStencilImage, m_backBufferDepthStencilMemory, 0); + result = m_cmd.alloc(&m_commandBuffer); if (VK_SUCCESS != result) { - BX_TRACE("Init error: vkBindImageMemory failed %d: %s.", result, getName(result) ); + BX_TRACE("Init error: allocating command buffer failed %d: %s.", result, getName(result) ); goto error; } + } - VkImageViewCreateInfo ivci; - ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - ivci.pNext = NULL; - ivci.flags = 0; - ivci.image = m_backBufferDepthStencilImage; - ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; - ivci.format = m_backBufferDepthStencilFormat; - ivci.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.subresourceRange.aspectMask = 0 - | VK_IMAGE_ASPECT_DEPTH_BIT - | VK_IMAGE_ASPECT_STENCIL_BIT - ; - ivci.subresourceRange.baseMipLevel = 0; - ivci.subresourceRange.levelCount = 1; - ivci.subresourceRange.baseArrayLayer = 0; - ivci.subresourceRange.layerCount = 1; - result = vkCreateImageView(m_device, &ivci, m_allocatorCb, &m_backBufferDepthStencilImageView); + errorState = ErrorState::CommandQueueCreated; - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateImageView failed %d: %s.", result, getName(result) ); - goto error; - } + m_presentElapsed = 0; - ::VkImageView attachments[] = - { - VK_NULL_HANDLE, - m_backBufferDepthStencilImageView, - }; + { + m_resolution = _init.resolution; + m_resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; - VkFramebufferCreateInfo fci; - fci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; - fci.pNext = NULL; - fci.flags = 0; - fci.renderPass = m_renderPass; - fci.attachmentCount = BX_COUNTOF(attachments); - fci.pAttachments = attachments; - fci.width = m_sci.imageExtent.width; - fci.height = m_sci.imageExtent.height; - fci.layers = 1; - - VkSemaphoreCreateInfo sci; - sci.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; - sci.pNext = NULL; - sci.flags = 0; + m_numWindows = 0; - for (uint32_t ii = 0; ii < numSwapchainImages; ++ii) + if (!headless) { - ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - ivci.pNext = NULL; - ivci.flags = 0; - ivci.image = m_backBufferColorImage[ii]; - ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; - ivci.format = m_sci.imageFormat; - ivci.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - ivci.subresourceRange.baseMipLevel = 0; - ivci.subresourceRange.levelCount = 1; - ivci.subresourceRange.baseArrayLayer = 0; - ivci.subresourceRange.layerCount = 1; - - result = vkCreateImageView(m_device, &ivci, m_allocatorCb, &m_backBufferColorImageView[ii]); + m_textVideoMem.resize(false, _init.resolution.width, _init.resolution.height); + m_textVideoMem.clear(); - if (VK_SUCCESS != result) + for (uint8_t ii = 0; ii < BX_COUNTOF(m_swapchainFormats); ++ii) { - BX_TRACE("Init error: vkCreateImageView failed %d: %s.", result, getName(result) ); - goto error; + m_swapchainFormats[ii] = TextureFormat::Enum(ii); } - attachments[0] = m_backBufferColorImageView[ii]; - result = vkCreateFramebuffer(m_device, &fci, m_allocatorCb, &m_backBufferColor[ii]); + result = m_backBuffer.create(UINT16_MAX, g_platformData.nwh, m_resolution.width, m_resolution.height, m_resolution.format); if (VK_SUCCESS != result) { - BX_TRACE("Init error: vkCreateFramebuffer failed %d: %s.", result, getName(result) ); + BX_TRACE("Init error: creating swap chain failed %d: %s.", result, getName(result) ); goto error; } - result = vkCreateSemaphore(m_device, &sci, m_allocatorCb, &m_presentDone[ii]); + m_windows[0] = BGFX_INVALID_HANDLE; + m_numWindows++; - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateSemaphore failed %d: %s.", result, getName(result) ); - goto error; - } - - sci.flags = 0; + postReset(); } } - errorState = ErrorState::SwapchainCreated; - - { - VkFenceCreateInfo fci; - fci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; - fci.pNext = NULL; - fci.flags = 0; - result = vkCreateFence(m_device, &fci, m_allocatorCb, &m_fence); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateFence failed %d: %s.", result, getName(result) ); - goto error; - } - - VkCommandPoolCreateInfo cpci; - cpci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; - cpci.pNext = NULL; - cpci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; - cpci.queueFamilyIndex = m_qfiGraphics; - result = vkCreateCommandPool(m_device, &cpci, m_allocatorCb, &m_commandPool); - - if (VK_SUCCESS != result) - { - vkDestroy(m_fence); - BX_TRACE("Init error: vkCreateCommandPool failed %d: %s.", result, getName(result) ); - goto error; - } - - VkCommandBufferAllocateInfo cbai; - cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; - cbai.pNext = NULL; - cbai.commandPool = m_commandPool; - cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; - cbai.commandBufferCount = BX_COUNTOF(m_commandBuffers); - - result = vkAllocateCommandBuffers(m_device, &cbai, m_commandBuffers); - - if (VK_SUCCESS != result) - { - vkDestroy(m_commandPool); - vkDestroy(m_fence); - BX_TRACE("Init error: vkAllocateCommandBuffers failed %d: %s.", result, getName(result) ); - goto error; - } - - VkCommandBufferBeginInfo cbbi; - cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cbbi.pNext = NULL; - cbbi.flags = 0; - cbbi.pInheritanceInfo = NULL; - - VkCommandBuffer commandBuffer = m_commandBuffers[0]; - VK_CHECK(vkBeginCommandBuffer(commandBuffer, &cbbi) ); - - VkRenderPassBeginInfo rpbi; - rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; - rpbi.pNext = NULL; - rpbi.renderPass = m_renderPass; - rpbi.renderArea.offset.x = 0; - rpbi.renderArea.offset.y = 0; - rpbi.renderArea.extent = m_sci.imageExtent; - rpbi.clearValueCount = 0; - rpbi.pClearValues = NULL; - - setImageMemoryBarrier(commandBuffer - , m_backBufferDepthStencilImage - , VK_IMAGE_LAYOUT_UNDEFINED - , VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL - ); - - for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImage); ++ii) - { - setImageMemoryBarrier(commandBuffer - , m_backBufferColorImage[ii] - , VK_IMAGE_LAYOUT_UNDEFINED - , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL - ); - - rpbi.framebuffer = m_backBufferColor[ii]; - vkCmdBeginRenderPass(commandBuffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE); - vkCmdEndRenderPass(commandBuffer); - - setImageMemoryBarrier(commandBuffer - , m_backBufferColorImage[ii] - , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL - , VK_IMAGE_LAYOUT_PRESENT_SRC_KHR - ); - } - - VK_CHECK(vkEndCommandBuffer(commandBuffer) ); - m_backBufferColorIdx = 0; - - kick(); - finishAll(); - - VK_CHECK(vkResetCommandPool(m_device, m_commandPool, 0) ); - } - - errorState = ErrorState::CommandBuffersCreated; + errorState = ErrorState::SwapChainCreated; { VkDescriptorPoolSize dps[] = { -// { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS }, - { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 10<<10 }, -// { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS }, - }; - - VkDescriptorSetLayoutBinding dslb[] = - { -// { DslBinding::CombinedImageSampler, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, VK_SHADER_STAGE_ALL, NULL }, - { DslBinding::UniformBuffer, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1, VK_SHADER_STAGE_ALL, NULL }, -// { DslBinding::StorageBuffer, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, VK_SHADER_STAGE_ALL, NULL }, + { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MAX_DESCRIPTOR_SETS * BGFX_CONFIG_MAX_TEXTURE_SAMPLERS }, + { VK_DESCRIPTOR_TYPE_SAMPLER, MAX_DESCRIPTOR_SETS * BGFX_CONFIG_MAX_TEXTURE_SAMPLERS }, + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, MAX_DESCRIPTOR_SETS * 2 }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_DESCRIPTOR_SETS * BGFX_CONFIG_MAX_TEXTURE_SAMPLERS }, + { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MAX_DESCRIPTOR_SETS * BGFX_CONFIG_MAX_TEXTURE_SAMPLERS }, }; VkDescriptorPoolCreateInfo dpci; dpci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; dpci.pNext = NULL; dpci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; - dpci.maxSets = 10<<10; + dpci.maxSets = MAX_DESCRIPTOR_SETS; dpci.poolSizeCount = BX_COUNTOF(dps); dpci.pPoolSizes = dps; @@ -1727,36 +1981,6 @@ VK_IMPORT_DEVICE goto error; } - VkDescriptorSetLayoutCreateInfo dsl; - dsl.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; - dsl.pNext = NULL; - dsl.flags = 0; - dsl.bindingCount = BX_COUNTOF(dslb); - dsl.pBindings = dslb; - result = vkCreateDescriptorSetLayout(m_device, &dsl, m_allocatorCb, &m_descriptorSetLayout); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreateDescriptorSetLayout failed %d: %s.", result, getName(result) ); - goto error; - } - - VkPipelineLayoutCreateInfo pl; - pl.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; - pl.pNext = NULL; - pl.flags = 0; - pl.setLayoutCount = 1; - pl.pSetLayouts = &m_descriptorSetLayout; - pl.pushConstantRangeCount = 0; - pl.pPushConstantRanges = NULL; - result = vkCreatePipelineLayout(m_device, &pl, m_allocatorCb, &m_pipelineLayout); - - if (VK_SUCCESS != result) - { - BX_TRACE("Init error: vkCreatePipelineLayout failed %d: %s.", result, getName(result) ); - goto error; - } - VkPipelineCacheCreateInfo pcci; pcci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; pcci.pNext = NULL; @@ -1772,61 +1996,91 @@ VK_IMPORT_DEVICE } } - for (uint32_t ii = 0; ii < BX_COUNTOF(m_scratchBuffer); ++ii) { - m_scratchBuffer[ii].create(BGFX_CONFIG_MAX_DRAW_CALLS*1024 - , 1024 //BGFX_CONFIG_MAX_TEXTURES + BGFX_CONFIG_MAX_SHADERS + BGFX_CONFIG_MAX_DRAW_CALLS - ); + const uint32_t size = 128; + const uint32_t count = BGFX_CONFIG_MAX_DRAW_CALLS; + for (uint32_t ii = 0; ii < m_numFramesInFlight; ++ii) + { + BX_TRACE("Create scratch buffer %d", ii); + m_scratchBuffer[ii].create(size, count); + } } errorState = ErrorState::DescriptorCreated; + if (NULL == vkSetDebugUtilsObjectNameEXT) + { + vkSetDebugUtilsObjectNameEXT = stubSetDebugUtilsObjectNameEXT; + } + + if (NULL == vkCmdBeginDebugUtilsLabelEXT + || NULL == vkCmdEndDebugUtilsLabelEXT) + { + vkCmdBeginDebugUtilsLabelEXT = stubCmdBeginDebugUtilsLabelEXT; + vkCmdEndDebugUtilsLabelEXT = stubCmdEndDebugUtilsLabelEXT; + } + + if (NULL == vkCmdInsertDebugUtilsLabelEXT) + { + vkCmdInsertDebugUtilsLabelEXT = stubCmdInsertDebugUtilsLabelEXT; + } + + // 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); + } + + if (m_timerQuerySupport) + { + result = m_gpuTimer.init(); + + if (VK_SUCCESS != result) + { + BX_TRACE("Init error: creating GPU timer failed %d: %s.", result, getName(result) ); + goto error; + } + } + + errorState = ErrorState::TimerQueryCreated; + + result = m_occlusionQuery.init(); + + if (VK_SUCCESS != result) + { + BX_TRACE("Init error: creating occlusion query failed %d: %s.", result, getName(result) ); + goto error; + } + + g_internalData.context = m_device; return true; error: BX_TRACE("errorState %d", errorState); switch (errorState) { - case ErrorState::DescriptorCreated: - vkDestroy(m_pipelineCache); - vkDestroy(m_pipelineLayout); - vkDestroy(m_descriptorSetLayout); - vkDestroy(m_descriptorPool); - BX_FALLTHROUGH; - - case ErrorState::CommandBuffersCreated: - vkFreeCommandBuffers(m_device, m_commandPool, BX_COUNTOF(m_commandBuffers), m_commandBuffers); - vkDestroy(m_commandPool); - vkDestroy(m_fence); + case ErrorState::TimerQueryCreated: + if (m_timerQuerySupport) + { + m_gpuTimer.shutdown(); + } BX_FALLTHROUGH; - case ErrorState::SwapchainCreated: - for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImageView); ++ii) + case ErrorState::DescriptorCreated: + for (uint32_t ii = 0; ii < m_numFramesInFlight; ++ii) { - if (VK_NULL_HANDLE != m_backBufferColorImageView[ii]) - { - vkDestroy(m_backBufferColorImageView[ii]); - } - - if (VK_NULL_HANDLE != m_backBufferColor[ii]) - { - vkDestroy(m_backBufferColor[ii]); - } - - if (VK_NULL_HANDLE != m_presentDone[ii]) - { - vkDestroy(m_presentDone[ii]); - } + m_scratchBuffer[ii].destroy(); } - vkDestroy(m_swapchain); + vkDestroy(m_pipelineCache); + vkDestroy(m_descriptorPool); BX_FALLTHROUGH; - case ErrorState::SurfaceCreated: - vkDestroySurfaceKHR(m_instance, m_surface, m_allocatorCb); + case ErrorState::SwapChainCreated: + m_backBuffer.destroy(); BX_FALLTHROUGH; - case ErrorState::RenderPassCreated: - vkDestroy(m_renderPass); + case ErrorState::CommandQueueCreated: + m_cmd.shutdown(); BX_FALLTHROUGH; case ErrorState::DeviceCreated: @@ -1853,18 +2107,29 @@ VK_IMPORT_DEVICE break; }; - BX_CHECK(false, "Failed to initialize Vulkan."); return false; } void shutdown() { - VK_CHECK(vkQueueWaitIdle(m_queueGraphics) ); VK_CHECK(vkDeviceWaitIdle(m_device) ); + if (m_timerQuerySupport) + { + m_gpuTimer.shutdown(); + } + m_occlusionQuery.shutdown(); + + preReset(); + m_pipelineStateCache.invalidate(); + m_descriptorSetLayoutCache.invalidate(); + m_renderPassCache.invalidate(); + m_samplerCache.invalidate(); + m_samplerBorderColorCache.invalidate(); + m_imageViewCache.invalidate(); - for (uint32_t ii = 0; ii < BX_COUNTOF(m_scratchBuffer); ++ii) + for (uint32_t ii = 0; ii < m_numFramesInFlight; ++ii) { m_scratchBuffer[ii].destroy(); } @@ -1894,41 +2159,12 @@ VK_IMPORT_DEVICE m_textures[ii].destroy(); } - vkDestroy(m_pipelineCache); - vkDestroy(m_pipelineLayout); - vkDestroy(m_descriptorSetLayout); - vkDestroy(m_descriptorPool); - - vkFreeCommandBuffers(m_device, m_commandPool, BX_COUNTOF(m_commandBuffers), m_commandBuffers); - vkDestroy(m_commandPool); - vkDestroy(m_fence); - - for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImageView); ++ii) - { - if (VK_NULL_HANDLE != m_backBufferColorImageView[ii]) - { - vkDestroy(m_backBufferColorImageView[ii]); - } - - if (VK_NULL_HANDLE != m_backBufferColor[ii]) - { - vkDestroy(m_backBufferColor[ii]); - } - - if (VK_NULL_HANDLE != m_presentDone[ii]) - { - vkDestroy(m_presentDone[ii]); - } - } - vkDestroy(m_swapchain); + m_backBuffer.destroy(); - vkDestroy(m_backBufferDepthStencilImageView); - vkFreeMemory(m_device, m_backBufferDepthStencilMemory, m_allocatorCb); - vkDestroy(m_backBufferDepthStencilImage); + m_cmd.shutdown(); - vkDestroySurfaceKHR(m_instance, m_surface, m_allocatorCb); - - vkDestroy(m_renderPass); + vkDestroy(m_pipelineCache); + vkDestroy(m_descriptorPool); vkDestroyDevice(m_device, m_allocatorCb); @@ -1962,24 +2198,26 @@ VK_IMPORT_DEVICE void flip() override { - if (VK_NULL_HANDLE != m_swapchain) + int64_t start = bx::getHPCounter(); + + for (uint16_t ii = 0; ii < m_numWindows; ++ii) { - VkPresentInfoKHR pi; - pi.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; - pi.pNext = NULL; - pi.waitSemaphoreCount = 0; - pi.pWaitSemaphores = NULL; //&m_presentDone[0]; - pi.swapchainCount = 1; - pi.pSwapchains = &m_swapchain; - pi.pImageIndices = &m_backBufferColorIdx; - pi.pResults = NULL; - VK_CHECK(vkQueuePresentKHR(m_queueGraphics, &pi) ); + FrameBufferVK& fb = isValid(m_windows[ii]) + ? m_frameBuffers[m_windows[ii].idx] + : m_backBuffer + ; + + fb.present(); } + + int64_t now = bx::getHPCounter(); + + m_presentElapsed += now - start; } void createIndexBuffer(IndexBufferHandle _handle, const Memory* _mem, uint16_t _flags) override { - m_indexBuffers[_handle.idx].create(_mem->size, _mem->data, _flags, false); + m_indexBuffers[_handle.idx].create(m_commandBuffer, _mem->size, _mem->data, _flags, false); } void destroyIndexBuffer(IndexBufferHandle _handle) override @@ -1987,20 +2225,20 @@ VK_IMPORT_DEVICE m_indexBuffers[_handle.idx].destroy(); } - void createVertexDecl(VertexDeclHandle _handle, const VertexDecl& _decl) override + void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _layout) override { - VertexDecl& decl = m_vertexDecls[_handle.idx]; - bx::memCopy(&decl, &_decl, sizeof(VertexDecl) ); - dump(decl); + VertexLayout& layout = m_vertexLayouts[_handle.idx]; + bx::memCopy(&layout, &_layout, sizeof(VertexLayout) ); + dump(layout); } - void destroyVertexDecl(VertexDeclHandle /*_handle*/) override + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override { } - void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexDeclHandle _declHandle, uint16_t _flags) override + void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _layoutHandle, uint16_t _flags) override { - m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); + m_vertexBuffers[_handle.idx].create(m_commandBuffer, _mem->size, _mem->data, _layoutHandle, _flags); } void destroyVertexBuffer(VertexBufferHandle _handle) override @@ -2010,13 +2248,12 @@ VK_IMPORT_DEVICE void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) override { - m_indexBuffers[_handle.idx].create(_size, NULL, _flags, false); + m_indexBuffers[_handle.idx].create(m_commandBuffer, _size, NULL, _flags, false); } void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override { - BX_UNUSED(_handle, _offset, _size, _mem); -// m_indexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::uint32_min(_size, _mem->size), _mem->data); + m_indexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::min<uint32_t>(_size, _mem->size), _mem->data); } void destroyDynamicIndexBuffer(IndexBufferHandle _handle) override @@ -2026,14 +2263,13 @@ VK_IMPORT_DEVICE void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) override { - VertexDeclHandle decl = BGFX_INVALID_HANDLE; - m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); + VertexLayoutHandle layoutHandle = BGFX_INVALID_HANDLE; + m_vertexBuffers[_handle.idx].create(m_commandBuffer, _size, NULL, layoutHandle, _flags); } void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override { - BX_UNUSED(_handle, _offset, _size, _mem); -// m_vertexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::uint32_min(_size, _mem->size), _mem->data); + m_vertexBuffers[_handle.idx].update(m_commandBuffer, _offset, bx::min<uint32_t>(_size, _mem->size), _mem->data); } void destroyDynamicVertexBuffer(VertexBufferHandle _handle) override @@ -2061,29 +2297,81 @@ VK_IMPORT_DEVICE m_program[_handle.idx].destroy(); } - void* createTexture(TextureHandle /*_handle*/, const Memory* /*_mem*/, uint64_t /*_flags*/, uint8_t /*_skip*/) override + void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) override { - return NULL; + return m_textures[_handle.idx].create(m_commandBuffer, _mem, _flags, _skip); } void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override { } - void updateTexture(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/, const Rect& /*_rect*/, uint16_t /*_z*/, uint16_t /*_depth*/, uint16_t /*_pitch*/, const Memory* /*_mem*/) override + void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) override { + m_textures[_handle.idx].update(m_commandBuffer, _side, _mip, _rect, _z, _depth, _pitch, _mem); } void updateTextureEnd() override { } - void readTexture(TextureHandle /*_handle*/, void* /*_data*/, uint8_t /*_mip*/) override + void readTexture(TextureHandle _handle, void* _data, uint8_t _mip) override { + TextureVK& texture = m_textures[_handle.idx]; + + uint32_t height = bx::uint32_max(1, texture.m_height >> _mip); + uint32_t pitch = texture.m_readback.pitch(_mip); + uint32_t size = height * pitch; + + VkDeviceMemory stagingMemory; + VkBuffer stagingBuffer; + VK_CHECK(createReadbackBuffer(size, &stagingBuffer, &stagingMemory) ); + + texture.m_readback.copyImageToBuffer( + m_commandBuffer + , stagingBuffer + , texture.m_currentImageLayout + , texture.m_aspectMask + , _mip + ); + + kick(true); + + texture.m_readback.readback(stagingMemory, 0, _data, _mip); + + vkDestroy(stagingBuffer); + vkDestroy(stagingMemory); } - void resizeTexture(TextureHandle /*_handle*/, uint16_t /*_width*/, uint16_t /*_height*/, uint8_t /*_numMips*/, uint16_t /*_numLayers*/) override + void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, uint16_t _numLayers) override { + const TextureVK& texture = m_textures[_handle.idx]; + + const TextureFormat::Enum format = TextureFormat::Enum(texture.m_requestedFormat); + const uint64_t flags = texture.m_flags; + + const uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate); + const Memory* mem = alloc(size); + + bx::StaticMemoryBlockWriter writer(mem->data, mem->size); + uint32_t magic = BGFX_CHUNK_MAGIC_TEX; + bx::write(&writer, magic, bx::ErrorAssert{}); + + TextureCreate tc; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = _numLayers; + tc.m_numMips = _numMips; + tc.m_format = format; + tc.m_cubeMap = false; + tc.m_mem = NULL; + bx::write(&writer, tc, bx::ErrorAssert{}); + + destroyTexture(_handle); + createTexture(_handle, mem, flags, 0); + + bgfx::release(mem); } void overrideInternal(TextureHandle /*_handle*/, uintptr_t /*_ptr*/) override @@ -2095,20 +2383,58 @@ VK_IMPORT_DEVICE return 0; } - void destroyTexture(TextureHandle /*_handle*/) override + void destroyTexture(TextureHandle _handle) override { + m_imageViewCache.invalidateWithParent(_handle.idx); + m_textures[_handle.idx].destroy(); } - void createFrameBuffer(FrameBufferHandle /*_handle*/, uint8_t /*_num*/, const Attachment* /*_attachment*/) override + void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const Attachment* _attachment) override { + m_frameBuffers[_handle.idx].create(_num, _attachment); } - void createFrameBuffer(FrameBufferHandle /*_handle*/, void* /*_nwh*/, uint32_t /*_width*/, uint32_t /*_height*/, TextureFormat::Enum /*_format*/, TextureFormat::Enum /*_depthFormat*/) override + void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override { + for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) + { + FrameBufferHandle handle = m_windows[ii]; + if (isValid(handle) + && m_frameBuffers[handle.idx].m_nwh == _nwh) + { + destroyFrameBuffer(handle); + } + } + + uint16_t denseIdx = m_numWindows++; + m_windows[denseIdx] = _handle; + VK_CHECK(m_frameBuffers[_handle.idx].create(denseIdx, _nwh, _width, _height, _format, _depthFormat) ); } - void destroyFrameBuffer(FrameBufferHandle /*_handle*/) override + void destroyFrameBuffer(FrameBufferHandle _handle) override { + FrameBufferVK& frameBuffer = m_frameBuffers[_handle.idx]; + + if (_handle.idx == m_fbh.idx) + { + setFrameBuffer(BGFX_INVALID_HANDLE, false); + } + + uint16_t denseIdx = frameBuffer.destroy(); + if (UINT16_MAX != denseIdx) + { + --m_numWindows; + if (m_numWindows > 1) + { + FrameBufferHandle handle = m_windows[m_numWindows]; + m_windows[m_numWindows] = {kInvalidHandle}; + if (m_numWindows != denseIdx) + { + m_windows[denseIdx] = handle; + m_frameBuffers[handle.idx].m_denseIdx = denseIdx; + } + } + } } void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) override @@ -2118,7 +2444,7 @@ VK_IMPORT_DEVICE BX_FREE(g_allocator, m_uniforms[_handle.idx]); } - uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type] * _num); + const uint32_t size = bx::alignUp(g_uniformTypeSize[_type] * _num, 16); void* data = BX_ALLOC(g_allocator, size); bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; @@ -2131,8 +2457,45 @@ VK_IMPORT_DEVICE m_uniforms[_handle.idx] = NULL; } - void requestScreenShot(FrameBufferHandle /*_handle*/, const char* /*_filePath*/) override + void requestScreenShot(FrameBufferHandle _fbh, const char* _filePath) override { + const FrameBufferVK& frameBuffer = isValid(_fbh) + ? m_frameBuffers[_fbh.idx] + : m_backBuffer + ; + const SwapChainVK& swapChain = frameBuffer.m_swapChain; + + if (!isSwapChainReadable(swapChain) ) + { + BX_TRACE("Unable to capture screenshot %s.", _filePath); + return; + } + + auto callback = [](void* _src, uint32_t _width, uint32_t _height, uint32_t _pitch, const void* _userData) + { + const char* filePath = (const char*)_userData; + g_callback->screenShot( + filePath + , _width + , _height + , _pitch + , _src + , _height * _pitch + , false + ); + }; + + const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(swapChain.m_colorFormat) ); + const uint32_t size = frameBuffer.m_width * frameBuffer.m_height * bpp / 8; + + VkDeviceMemory stagingMemory; + VkBuffer stagingBuffer; + VK_CHECK(createReadbackBuffer(size, &stagingBuffer, &stagingMemory) ); + + readSwapChain(swapChain, stagingBuffer, stagingMemory, callback, _filePath); + + vkDestroy(stagingBuffer); + vkDestroy(stagingMemory); } void updateViewName(ViewId _id, const char* _name) override @@ -2148,44 +2511,260 @@ VK_IMPORT_DEVICE bx::memCopy(m_uniforms[_loc], _data, _size); } - void setMarker(const char* /*_marker*/, uint32_t /*_size*/) override + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override { + m_occlusionQuery.invalidate(_handle); } - void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + void setMarker(const char* _marker, uint16_t _len) override { - BX_UNUSED(_handle); + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + BX_UNUSED(_len); + + const uint32_t abgr = kColorMarker; + + VkDebugUtilsLabelEXT dul; + dul.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; + dul.pNext = NULL; + dul.pLabelName = _marker; + dul.color[0] = ((abgr >> 24) & 0xff) / 255.0f; + dul.color[1] = ((abgr >> 16) & 0xff) / 255.0f; + dul.color[2] = ((abgr >> 8) & 0xff) / 255.0f; + dul.color[3] = ((abgr >> 0) & 0xff) / 255.0f; + + vkCmdInsertDebugUtilsLabelEXT(m_commandBuffer, &dul); + } } - virtual void setName(Handle _handle, const char* _name) override + virtual void setName(Handle _handle, const char* _name, uint16_t _len) override { - BX_UNUSED(_handle, _name) + switch (_handle.type) + { + case Handle::IndexBuffer: + setDebugObjectName(m_device, m_indexBuffers[_handle.idx].m_buffer, "%.*s", _len, _name); + break; + + case Handle::Shader: + setDebugObjectName(m_device, m_shaders[_handle.idx].m_module, "%.*s", _len, _name); + break; + + case Handle::Texture: + setDebugObjectName(m_device, m_textures[_handle.idx].m_textureImage, "%.*s", _len, _name); + + if (VK_NULL_HANDLE != m_textures[_handle.idx].m_singleMsaaImage) + { + setDebugObjectName(m_device, m_textures[_handle.idx].m_singleMsaaImage, "%.*s", _len, _name); + } + break; + + case Handle::VertexBuffer: + setDebugObjectName(m_device, m_vertexBuffers[_handle.idx].m_buffer, "%.*s", _len, _name); + break; + + default: + BX_ASSERT(false, "Invalid handle type?! %d", _handle.type); + break; + } + } + + template<typename Ty> + void release(Ty& _object) + { + if (VK_NULL_HANDLE != _object) + { + m_cmd.release(uint64_t(_object.vk), getType<Ty>() ); + _object = VK_NULL_HANDLE; + } } void submitBlit(BlitState& _bs, uint16_t _view); void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override; - void blitSetup(TextVideoMemBlitter& /*_blitter*/) override + void blitSetup(TextVideoMemBlitter& _blitter) override { + const uint32_t width = m_backBuffer.m_width; + const uint32_t height = m_backBuffer.m_height; + + setFrameBuffer(BGFX_INVALID_HANDLE); + + VkViewport vp; + vp.x = 0.0f; + vp.y = float(height); + vp.width = float(width); + vp.height = -float(height); + vp.minDepth = 0.0f; + vp.maxDepth = 1.0f; + vkCmdSetViewport(m_commandBuffer, 0, 1, &vp); + + VkRect2D rc; + rc.offset.x = 0; + rc.offset.y = 0; + rc.extent.width = width; + rc.extent.height = height; + vkCmdSetScissor(m_commandBuffer, 0, 1, &rc); + + const uint64_t state = 0 + | BGFX_STATE_WRITE_RGB + | BGFX_STATE_WRITE_A + | BGFX_STATE_DEPTH_TEST_ALWAYS + | BGFX_STATE_MSAA + ; + + const VertexLayout* layout = &m_vertexLayouts[_blitter.m_vb->layoutHandle.idx]; + VkPipeline pso = getPipeline(state + , packStencil(BGFX_STENCIL_DEFAULT, BGFX_STENCIL_DEFAULT) + , 1 + , &layout + , _blitter.m_program + , 0 + ); + vkCmdBindPipeline(m_commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pso); + + ProgramVK& program = m_program[_blitter.m_program.idx]; + float proj[16]; + bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, false); + + PredefinedUniform& predefined = m_program[_blitter.m_program.idx].m_predefined[0]; + uint8_t flags = predefined.m_type; + setShaderUniform(flags, predefined.m_loc, proj, 4); + + UniformBuffer* vcb = program.m_vsh->m_constantBuffer; + + if (NULL != vcb) + { + commit(*vcb); + } + + ScratchBufferVK& scratchBuffer = m_scratchBuffer[m_cmd.m_currentFrameInFlight]; + const uint32_t bufferOffset = scratchBuffer.write(m_vsScratch, program.m_vsh->m_size); + + const TextureVK& texture = m_textures[_blitter.m_texture.idx]; + + RenderBind bind; + bind.clear(); + bind.m_bind[0].m_type = Binding::Texture; + bind.m_bind[0].m_idx = _blitter.m_texture.idx; + bind.m_bind[0].m_samplerFlags = (uint32_t)(texture.m_flags & BGFX_SAMPLER_BITS_MASK); + + const VkDescriptorSet descriptorSet = getDescriptorSet(program, bind, scratchBuffer, NULL); + + vkCmdBindDescriptorSets( + m_commandBuffer + , VK_PIPELINE_BIND_POINT_GRAPHICS + , program.m_pipelineLayout + , 0 + , 1 + , &descriptorSet + , 1 + , &bufferOffset + ); + + const VertexBufferVK& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; + const VkDeviceSize offset = 0; + vkCmdBindVertexBuffers(m_commandBuffer, 0, 1, &vb.m_buffer, &offset); + + const BufferVK& ib = m_indexBuffers[_blitter.m_ib->handle.idx]; + vkCmdBindIndexBuffer( + m_commandBuffer + , ib.m_buffer + , 0 + , VK_INDEX_TYPE_UINT16 + ); + } + + void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) override + { + const uint32_t numVertices = _numIndices*4/6; + if (0 < numVertices && m_backBuffer.isRenderable() ) + { + m_indexBuffers[_blitter.m_ib->handle.idx].update(m_commandBuffer, 0, _numIndices*2, _blitter.m_ib->data); + m_vertexBuffers[_blitter.m_vb->handle.idx].update(m_commandBuffer, 0, numVertices*_blitter.m_layout.m_stride, _blitter.m_vb->data, true); + + + VkRenderPassBeginInfo rpbi; + rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; + rpbi.pNext = NULL; + rpbi.renderPass = m_backBuffer.m_renderPass; + rpbi.framebuffer = m_backBuffer.m_currentFramebuffer; + rpbi.renderArea.offset.x = 0; + rpbi.renderArea.offset.y = 0; + rpbi.renderArea.extent.width = m_backBuffer.m_width; + rpbi.renderArea.extent.height = m_backBuffer.m_height; + rpbi.clearValueCount = 0; + rpbi.pClearValues = NULL; + + vkCmdBeginRenderPass(m_commandBuffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE); + vkCmdDrawIndexed(m_commandBuffer, _numIndices, 1, 0, 0, 0); + + vkCmdEndRenderPass(m_commandBuffer); + } } - void blitRender(TextVideoMemBlitter& /*_blitter*/, uint32_t /*_numIndices*/) override + void preReset() { + for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii) + { + m_frameBuffers[ii].preReset(); + } + + if (m_captureSize > 0) + { + g_callback->captureEnd(); + + release(m_captureBuffer); + release(m_captureMemory); + m_captureSize = 0; + } } - void updateResolution(const Resolution& _resolution) + void postReset() { + for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii) + { + m_frameBuffers[ii].postReset(); + } + + if (m_resolution.reset & BGFX_RESET_CAPTURE) + { + const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_backBuffer.m_swapChain.m_colorFormat) ); + const uint32_t captureSize = m_backBuffer.m_width * m_backBuffer.m_height * bpp / 8; + + const uint8_t dstBpp = bimg::getBitsPerPixel(bimg::TextureFormat::BGRA8); + const uint32_t dstPitch = m_backBuffer.m_width * dstBpp / 8; + + if (captureSize > m_captureSize) + { + release(m_captureBuffer); + release(m_captureMemory); + + m_captureSize = captureSize; + VK_CHECK(createReadbackBuffer(m_captureSize, &m_captureBuffer, &m_captureMemory) ); + } + + g_callback->captureBegin(m_resolution.width, m_resolution.height, dstPitch, TextureFormat::BGRA8, false); + } + } + + bool updateResolution(const Resolution& _resolution) + { + const bool suspended = !!(_resolution.reset & BGFX_RESET_SUSPEND); + + float maxAnisotropy = 1.0f; if (!!(_resolution.reset & BGFX_RESET_MAXANISOTROPY) ) { - m_maxAnisotropy = UINT32_MAX; + maxAnisotropy = m_deviceProperties.limits.maxSamplerAnisotropy; } - else + + if (m_maxAnisotropy != maxAnisotropy) { - m_maxAnisotropy = 1; + m_maxAnisotropy = maxAnisotropy; + m_samplerCache.invalidate(); + m_samplerBorderColorCache.invalidate(); } - bool depthClamp = !!(_resolution.reset & BGFX_RESET_DEPTH_CLAMP); + bool depthClamp = m_deviceFeatures.depthClamp && !!(_resolution.reset & BGFX_RESET_DEPTH_CLAMP); if (m_depthClamp != depthClamp) { @@ -2193,15 +2772,38 @@ VK_IMPORT_DEVICE m_pipelineStateCache.invalidate(); } - uint32_t flags = _resolution.reset & ~(BGFX_RESET_MAXANISOTROPY | BGFX_RESET_DEPTH_CLAMP); + if (NULL == m_backBuffer.m_nwh) + { + return suspended; + } + + //BX_TRACE("updateResolution(%d, %d) m_resolution=(%d, %d)" + // , _resolution.width + // , _resolution.height + // , m_resolution.width + // , m_resolution.height + // ); + + uint32_t flags = _resolution.reset & ~(0 + | BGFX_RESET_SUSPEND + | BGFX_RESET_MAXANISOTROPY + | BGFX_RESET_DEPTH_CLAMP + ); - if (m_resolution.width != _resolution.width + if (false + || m_resolution.format != _resolution.format + || m_resolution.width != _resolution.width || m_resolution.height != _resolution.height - || m_resolution.reset != flags) + || m_resolution.reset != flags + || m_backBuffer.m_swapChain.m_needToRecreateSurface + || m_backBuffer.m_swapChain.m_needToRecreateSwapchain) { flags &= ~BGFX_RESET_INTERNAL_FORCE; - bool resize = (m_resolution.reset&BGFX_RESET_MSAA_MASK) == (_resolution.reset&BGFX_RESET_MSAA_MASK); + if (m_backBuffer.m_nwh != g_platformData.nwh) + { + m_backBuffer.m_nwh = g_platformData.nwh; + } m_resolution = _resolution; m_resolution.reset = flags; @@ -2209,62 +2811,29 @@ VK_IMPORT_DEVICE m_textVideoMem.resize(false, _resolution.width, _resolution.height); m_textVideoMem.clear(); -#if 1 - BX_UNUSED(resize); -#else - m_scd.BufferDesc.Width = _resolution.m_width; - m_scd.BufferDesc.Height = _resolution.m_height; - preReset(); - if (resize) - { - uint32_t nodeMask[] = { 1, 1, 1, 1 }; - BX_STATIC_ASSERT(BX_COUNTOF(m_backBufferColor) == BX_COUNTOF(nodeMask) ); - IUnknown* presentQueue[] ={ m_cmd.m_commandQueue, m_cmd.m_commandQueue, m_cmd.m_commandQueue, m_cmd.m_commandQueue }; - BX_STATIC_ASSERT(BX_COUNTOF(m_backBufferColor) == BX_COUNTOF(presentQueue) ); - - DX_CHECK(m_swapChain->ResizeBuffers1(m_scd.BufferCount - , m_scd.BufferDesc.Width - , m_scd.BufferDesc.Height - , m_scd.BufferDesc.Format - , m_scd.Flags - , nodeMask - , presentQueue - ) ); - } - else - { - updateMsaa(); - m_scd.SampleDesc = s_msaa[(m_resolution.m_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; - - DX_RELEASE(m_swapChain, 0); - - HRESULT hr; - hr = m_factory->CreateSwapChain(m_cmd.m_commandQueue - , &m_scd - , reinterpret_cast<IDXGISwapChain**>(&m_swapChain) - ); - BGFX_FATAL(SUCCEEDED(hr), bgfx::Fatal::UnableToInitialize, "Failed to create swap chain."); - } + m_backBuffer.update(m_commandBuffer, m_resolution); + // Update the resolution again here, as the actual width and height + // is now final (as it was potentially clamped by the Vulkan driver). + m_resolution.width = m_backBuffer.m_width; + m_resolution.height = m_backBuffer.m_height; postReset(); -#endif // 0 } + + return suspended; } void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) { - BX_UNUSED(_flags, _regIndex, _val, _numRegs); - if (_flags&BGFX_UNIFORM_FRAGMENTBIT) + if (_flags & kUniformFragmentBit) { bx::memCopy(&m_fsScratch[_regIndex], _val, _numRegs*16); - m_fsChanges += _numRegs; } else { bx::memCopy(&m_vsScratch[_regIndex], _val, _numRegs*16); - m_vsChanges += _numRegs; } } @@ -2278,133 +2847,99 @@ VK_IMPORT_DEVICE setShaderUniform(_flags, _regIndex, _val, _numRegs); } - void commitShaderUniforms(VkCommandBuffer _commandBuffer, uint16_t _programIdx) + void setFrameBuffer(FrameBufferHandle _fbh, bool _acquire = true) { - const ProgramVK& program = m_program[_programIdx]; - VkDescriptorBufferInfo descriptorBufferInfo; - uint32_t total = 0 - + program.m_vsh->m_size - + (NULL != program.m_fsh ? program.m_fsh->m_size : 0) - ; - if (0 < total) - { - uint8_t* data = (uint8_t*)m_scratchBuffer[m_backBufferColorIdx].allocUbv(descriptorBufferInfo, total); - - uint32_t size = program.m_vsh->m_size; - bx::memCopy(data, m_vsScratch, size); - data += size; - - if (NULL != program.m_fsh) - { - bx::memCopy(data, m_fsScratch, program.m_fsh->m_size); - } - - vkCmdBindDescriptorSets(_commandBuffer - , VK_PIPELINE_BIND_POINT_GRAPHICS - , m_pipelineLayout - , 0 - , 1 - , &m_scratchBuffer[m_backBufferColorIdx].m_descriptorSet - [m_scratchBuffer[m_backBufferColorIdx].m_currentDs - 1] - , 0 - , NULL - ); - } + BX_ASSERT(false + || isValid(_fbh) + || NULL != m_backBuffer.m_nwh + , "Rendering to backbuffer in headless mode." + ); - m_vsChanges = 0; - m_fsChanges = 0; - } + FrameBufferVK& newFrameBuffer = isValid(_fbh) + ? m_frameBuffers[_fbh.idx] + : m_backBuffer + ; - void setFrameBuffer(FrameBufferHandle _fbh, bool _msaa = true) - { - BX_UNUSED(_msaa); + FrameBufferVK& oldFrameBuffer = isValid(m_fbh) + ? m_frameBuffers[m_fbh.idx] + : m_backBuffer + ; - if (isValid(m_fbh) + if (NULL == oldFrameBuffer.m_nwh && m_fbh.idx != _fbh.idx) { - const FrameBufferVK& frameBuffer = m_frameBuffers[m_fbh.idx]; - BX_UNUSED(frameBuffer); - -// for (uint8_t ii = 0, num = frameBuffer.m_num; ii < num; ++ii) -// { -// TextureVK& texture = m_textures[frameBuffer.m_texture[ii].idx]; -// texture.setState(m_commandList, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); -// } -// -// if (isValid(frameBuffer.m_depth) ) -// { -// TextureVK& texture = m_textures[frameBuffer.m_depth.idx]; -// const bool writeOnly = 0 != (texture.m_flags&BGFX_TEXTURE_RT_WRITE_ONLY); -// if (!writeOnly) -// { -// texture.setState(m_commandList, D3D12_RESOURCE_STATE_DEPTH_READ); -// } -// } - } - - if (!isValid(_fbh) ) - { -// m_rtvHandle = m_rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); -// uint32_t rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); -// m_rtvHandle.ptr += m_backBufferColorIdx * rtvDescriptorSize; -// m_dsvHandle = m_dsvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); -// -// m_currentColor = &m_rtvHandle; -// m_currentDepthStencil = &m_dsvHandle; -// m_commandList->OMSetRenderTargets(1, m_currentColor, true, m_currentDepthStencil); - } - else - { - const FrameBufferVK& frameBuffer = m_frameBuffers[_fbh.idx]; - BX_UNUSED(frameBuffer); + oldFrameBuffer.resolve(); - if (0 < frameBuffer.m_num) - { -// D3D12_CPU_DESCRIPTOR_HANDLE rtvDescriptor = m_rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); -// uint32_t rtvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV); -// m_rtvHandle.ptr = rtvDescriptor.ptr + (BX_COUNTOF(m_backBufferColor) + _fbh.idx * BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS) * rtvDescriptorSize; -// m_currentColor = &m_rtvHandle; - } - else + for (uint8_t ii = 0, num = oldFrameBuffer.m_num; ii < num; ++ii) { -// m_currentColor = NULL; + TextureVK& texture = m_textures[oldFrameBuffer.m_texture[ii].idx]; + texture.setImageMemoryBarrier(m_commandBuffer, texture.m_sampledLayout); + if (VK_NULL_HANDLE != texture.m_singleMsaaImage) + { + texture.setImageMemoryBarrier(m_commandBuffer, texture.m_sampledLayout, true); + } } - if (isValid(frameBuffer.m_depth) ) + if (isValid(oldFrameBuffer.m_depth) ) { -// D3D12_CPU_DESCRIPTOR_HANDLE dsvDescriptor = m_dsvDescriptorHeap->GetCPUDescriptorHandleForHeapStart(); -// uint32_t dsvDescriptorSize = m_device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV); -// m_dsvHandle.ptr = dsvDescriptor.ptr + (1 + _fbh.idx) * dsvDescriptorSize; -// m_currentDepthStencil = &m_dsvHandle; + TextureVK& texture = m_textures[oldFrameBuffer.m_depth.idx]; + const bool writeOnly = 0 != (texture.m_flags&BGFX_TEXTURE_RT_WRITE_ONLY); + + if (!writeOnly) + { + texture.setImageMemoryBarrier(m_commandBuffer, texture.m_sampledLayout); + } } - else + } + + if (NULL == newFrameBuffer.m_nwh) + { + for (uint8_t ii = 0, num = newFrameBuffer.m_num; ii < num; ++ii) { -// m_currentDepthStencil = NULL; + TextureVK& texture = m_textures[newFrameBuffer.m_texture[ii].idx]; + texture.setImageMemoryBarrier( + m_commandBuffer + , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL + ); } - for (uint8_t ii = 0, num = frameBuffer.m_num; ii < num; ++ii) + if (isValid(newFrameBuffer.m_depth) ) { - TextureVK& texture = m_textures[frameBuffer.m_texture[ii].idx]; - BX_UNUSED(texture); -// texture.setState(m_commandList, D3D12_RESOURCE_STATE_RENDER_TARGET); + TextureVK& texture = m_textures[newFrameBuffer.m_depth.idx]; + texture.setImageMemoryBarrier( + m_commandBuffer + , VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL + ); } - if (isValid(frameBuffer.m_depth) ) + newFrameBuffer.acquire(m_commandBuffer); + } + + if (_acquire) + { + int64_t start = bx::getHPCounter(); + + newFrameBuffer.acquire(m_commandBuffer); + + int64_t now = bx::getHPCounter(); + + if (NULL != newFrameBuffer.m_nwh) { - TextureVK& texture = m_textures[frameBuffer.m_depth.idx]; - BX_UNUSED(texture); -// texture.setState(m_commandList, D3D12_RESOURCE_STATE_DEPTH_WRITE); + m_presentElapsed += now - start; } - -// m_commandList->OMSetRenderTargets(frameBuffer.m_num -// , m_currentColor -// , true -// , m_currentDepthStencil -// ); } m_fbh = _fbh; -// m_rtMsaa = _msaa; + } + + void setDebugWireframe(bool _wireframe) + { + const bool wireframe = m_deviceFeatures.fillModeNonSolid && _wireframe; + if (m_wireframe != wireframe) + { + m_wireframe = wireframe; + m_pipelineStateCache.invalidate(); + } } void setBlendState(VkPipelineColorBlendStateCreateInfo& _desc, uint64_t _state, uint32_t _rgba = 0) @@ -2442,14 +2977,18 @@ VK_IMPORT_DEVICE bas->colorWriteMask = writeMask; } - uint32_t numAttachments = 1; - if (isValid(m_fbh) ) - { - const FrameBufferVK& frameBuffer = m_frameBuffers[m_fbh.idx]; - numAttachments = frameBuffer.m_num; - } + const FrameBufferVK& frameBuffer = isValid(m_fbh) + ? m_frameBuffers[m_fbh.idx] + : m_backBuffer + ; - if (!!(BGFX_STATE_BLEND_INDEPENDENT & _state) ) + const uint32_t numAttachments = NULL == frameBuffer.m_nwh + ? frameBuffer.m_num + : 1 + ; + + if (!!(BGFX_STATE_BLEND_INDEPENDENT & _state) + && m_deviceFeatures.independentBlend ) { for (uint32_t ii = 1, rgba = _rgba; ii < numAttachments; ++ii, rgba >>= 11) { @@ -2498,14 +3037,14 @@ VK_IMPORT_DEVICE _desc.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; _desc.pNext = NULL; _desc.flags = 0; - _desc.depthClampEnable = m_depthClamp; + _desc.depthClampEnable = m_deviceFeatures.depthClamp && m_depthClamp; _desc.rasterizerDiscardEnable = VK_FALSE; - _desc.polygonMode = _wireframe + _desc.polygonMode = m_deviceFeatures.fillModeNonSolid && _wireframe ? VK_POLYGON_MODE_LINE : VK_POLYGON_MODE_FILL ; _desc.cullMode = s_cullMode[cull]; - _desc.frontFace = VK_FRONT_FACE_CLOCKWISE; + _desc.frontFace = (_state&BGFX_STATE_FRONT_CCW) ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE; _desc.depthBiasEnable = VK_FALSE; _desc.depthBiasConstantFactor = 0.0f; _desc.depthBiasClamp = 0.0f; @@ -2513,6 +3052,31 @@ VK_IMPORT_DEVICE _desc.lineWidth = 1.0f; } + void setConservativeRasterizerState(VkPipelineRasterizationConservativeStateCreateInfoEXT& _desc, uint64_t _state) + { + _desc.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_CONSERVATIVE_STATE_CREATE_INFO_EXT; + _desc.pNext = NULL; + _desc.flags = 0; + _desc.conservativeRasterizationMode = (_state&BGFX_STATE_CONSERVATIVE_RASTER) + ? VK_CONSERVATIVE_RASTERIZATION_MODE_OVERESTIMATE_EXT + : VK_CONSERVATIVE_RASTERIZATION_MODE_DISABLED_EXT + ; + _desc.extraPrimitiveOverestimationSize = 0.0f; + } + + void setLineRasterizerState(VkPipelineRasterizationLineStateCreateInfoEXT& _desc, uint64_t _state) + { + _desc.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT; + _desc.pNext = NULL; + _desc.lineRasterizationMode = (_state & BGFX_STATE_LINEAA) + ? VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT + : VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT + ; + _desc.stippledLineEnable = VK_FALSE; + _desc.lineStippleFactor = 0; + _desc.lineStipplePattern = 0; + } + void setDepthStencilState(VkPipelineDepthStencilStateCreateInfo& _desc, uint64_t _state, uint64_t _stencil = 0) { const uint32_t fstencil = unpackStencil(0, _stencil); @@ -2552,95 +3116,503 @@ VK_IMPORT_DEVICE _desc.maxDepthBounds = 1.0f; } - uint32_t setInputLayout(VkPipelineVertexInputStateCreateInfo& _vertexInputState, const VertexDecl& _vertexDecl, const ProgramVK& _program, uint8_t _numInstanceData) + void setInputLayout(VkPipelineVertexInputStateCreateInfo& _vertexInputState, uint8_t _numStream, const VertexLayout** _layout, const ProgramVK& _program, uint8_t _numInstanceData) { _vertexInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; _vertexInputState.pNext = NULL; _vertexInputState.flags = 0; - VertexDecl decl; - bx::memCopy(&decl, &_vertexDecl, sizeof(VertexDecl) ); - const uint16_t* attrMask = _program.m_vsh->m_attrMask; + _vertexInputState.vertexBindingDescriptionCount = 0; + _vertexInputState.vertexAttributeDescriptionCount = 0; + + uint16_t unsettedAttr[Attrib::Count]; + bx::memCopy(unsettedAttr, _program.m_vsh->m_attrMask, sizeof(uint16_t) * Attrib::Count); + + for (uint8_t stream = 0; stream < _numStream; ++stream) + { + VertexLayout layout; + bx::memCopy(&layout, _layout[stream], sizeof(VertexLayout) ); + const uint16_t* attrMask = _program.m_vsh->m_attrMask; + + for (uint32_t ii = 0; ii < Attrib::Count; ++ii) + { + uint16_t mask = attrMask[ii]; + uint16_t attr = (layout.m_attributes[ii] & mask); + layout.m_attributes[ii] = attr == 0 || attr == UINT16_MAX ? UINT16_MAX : attr; + + if (unsettedAttr[ii] && attr != UINT16_MAX) + { + unsettedAttr[ii] = 0; + } + } + + fillVertexLayout(_program.m_vsh, _vertexInputState, layout); + } for (uint32_t ii = 0; ii < Attrib::Count; ++ii) { - uint16_t mask = attrMask[ii]; - uint16_t attr = (decl.m_attributes[ii] & mask); - decl.m_attributes[ii] = attr == 0 ? UINT16_MAX : attr == UINT16_MAX ? 0 : attr; + if (0 < unsettedAttr[ii]) + { + uint32_t numAttribs = _vertexInputState.vertexAttributeDescriptionCount; + VkVertexInputAttributeDescription* inputAttrib = const_cast<VkVertexInputAttributeDescription*>(_vertexInputState.pVertexAttributeDescriptions + numAttribs); + inputAttrib->location = _program.m_vsh->m_attrRemap[ii]; + inputAttrib->binding = 0; + inputAttrib->format = VK_FORMAT_R32G32B32_SFLOAT; + inputAttrib->offset = 0; + _vertexInputState.vertexAttributeDescriptionCount++; + } } - uint32_t num = fillVertexDecl(_program.m_vsh, _vertexInputState, decl); + if (0 < _numInstanceData) + { + fillInstanceBinding(_program.m_vsh, _vertexInputState, _numInstanceData); + } + } + + VkResult getRenderPass(uint8_t _num, const VkFormat* _formats, const VkImageAspectFlags* _aspects, const bool* _resolve, VkSampleCountFlagBits _samples, ::VkRenderPass* _renderPass) + { + VkResult result = VK_SUCCESS; + + if (VK_SAMPLE_COUNT_1_BIT == _samples) + { + _resolve = NULL; + } + + bx::HashMurmur2A hash; + hash.begin(); + hash.add(_samples); + hash.add(_formats, sizeof(VkFormat) * _num); + if (NULL != _resolve) + { + hash.add(_resolve, sizeof(bool) * _num); + } + uint32_t hashKey = hash.end(); + + VkRenderPass renderPass = m_renderPassCache.find(hashKey); + + if (VK_NULL_HANDLE != renderPass) + { + *_renderPass = renderPass; + return result; + } + + VkAttachmentDescription ad[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS * 2]; + + for (uint8_t ii = 0; ii < (_num * 2); ++ii) + { + ad[ii].flags = 0; + ad[ii].format = VK_FORMAT_UNDEFINED; + ad[ii].samples = _samples; + ad[ii].loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + ad[ii].storeOp = VK_ATTACHMENT_STORE_OP_STORE; + ad[ii].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + ad[ii].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; + ad[ii].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + ad[ii].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + } + + VkAttachmentReference colorAr[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + VkAttachmentReference resolveAr[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + VkAttachmentReference depthAr; + uint32_t numColorAr = 0; + uint32_t numResolveAr = 0; + + colorAr[0].attachment = VK_ATTACHMENT_UNUSED; + colorAr[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + resolveAr[0].attachment = VK_ATTACHMENT_UNUSED; + resolveAr[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + depthAr.attachment = VK_ATTACHMENT_UNUSED; + depthAr.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + for (uint8_t ii = 0; ii < _num; ++ii) + { + ad[ii].format = _formats[ii]; + + if (_aspects[ii] & VK_IMAGE_ASPECT_COLOR_BIT) + { + colorAr[numColorAr].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + colorAr[numColorAr].attachment = ii; + + resolveAr[numColorAr].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; + resolveAr[numColorAr].attachment = VK_ATTACHMENT_UNUSED; + if (NULL != _resolve + && _resolve[ii]) + { + const uint32_t resolve = _num + numResolveAr; + + ad[resolve].format = _formats[ii]; + ad[resolve].samples = VK_SAMPLE_COUNT_1_BIT; + ad[resolve].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; + + resolveAr[numColorAr].attachment = resolve; + numResolveAr++; + } + + numColorAr++; + } + else if (_aspects[ii] & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) ) + { + ad[ii].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_LOAD; + ad[ii].stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE; + ad[ii].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + ad[ii].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + + depthAr.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + depthAr.attachment = ii; + } + } + + VkSubpassDescription sd[1]; + sd[0].flags = 0; + sd[0].pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; + sd[0].inputAttachmentCount = 0; + sd[0].pInputAttachments = NULL; + sd[0].colorAttachmentCount = bx::max<uint32_t>(numColorAr, 1); + sd[0].pColorAttachments = colorAr; + sd[0].pResolveAttachments = resolveAr; + sd[0].pDepthStencilAttachment = &depthAr; + sd[0].preserveAttachmentCount = 0; + sd[0].pPreserveAttachments = NULL; + + const VkPipelineStageFlags graphicsStages = 0 + | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT + | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT + | VK_PIPELINE_STAGE_VERTEX_SHADER_BIT + | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT + | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT + | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT + | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT + ; + const VkPipelineStageFlags outsideStages = 0 + | graphicsStages + | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT + | VK_PIPELINE_STAGE_TRANSFER_BIT + ; + + VkSubpassDependency dep[2]; + + dep[0].srcSubpass = VK_SUBPASS_EXTERNAL; + dep[0].dstSubpass = 0; + dep[0].srcStageMask = outsideStages; + dep[0].dstStageMask = graphicsStages; + dep[0].srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; + dep[0].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; + dep[0].dependencyFlags = 0; + + dep[1].srcSubpass = BX_COUNTOF(sd)-1; + dep[1].dstSubpass = VK_SUBPASS_EXTERNAL; + dep[1].srcStageMask = graphicsStages; + dep[1].dstStageMask = outsideStages; + dep[1].srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT; + dep[1].dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT; + dep[1].dependencyFlags = 0; + + VkRenderPassCreateInfo rpi; + rpi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO; + rpi.pNext = NULL; + rpi.flags = 0; + rpi.attachmentCount = _num + numResolveAr; + rpi.pAttachments = ad; + rpi.subpassCount = BX_COUNTOF(sd); + rpi.pSubpasses = sd; + rpi.dependencyCount = BX_COUNTOF(dep); + rpi.pDependencies = dep; + + result = vkCreateRenderPass(m_device, &rpi, m_allocatorCb, &renderPass); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create render pass error: vkCreateRenderPass failed %d: %s.", result, getName(result) ); + return result; + } + + m_renderPassCache.add(hashKey, renderPass); + + *_renderPass = renderPass; + + return result; + } + + VkResult getRenderPass(uint8_t _num, const Attachment* _attachments, ::VkRenderPass* _renderPass) + { + VkFormat formats[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + VkImageAspectFlags aspects[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT; + + for (uint8_t ii = 0; ii < _num; ++ii) + { + const TextureVK& texture = m_textures[_attachments[ii].handle.idx]; + formats[ii] = texture.m_format; + aspects[ii] = texture.m_aspectMask; + samples = texture.m_sampler.Sample; + } + + return getRenderPass(_num, formats, aspects, NULL, samples, _renderPass); + } + + VkResult getRenderPass(const SwapChainVK& swapChain, ::VkRenderPass* _renderPass) + { + const VkFormat formats[2] = + { + swapChain.m_sci.imageFormat, + swapChain.m_backBufferDepthStencil.m_format + }; + const VkImageAspectFlags aspects[2] = + { + VK_IMAGE_ASPECT_COLOR_BIT, + swapChain.m_backBufferDepthStencil.m_aspectMask + }; + const bool resolve[2] = + { + swapChain.m_supportsManualResolve ? false : true, + false + }; + const VkSampleCountFlagBits samples = swapChain.m_sampler.Sample; + + return getRenderPass(BX_COUNTOF(formats), formats, aspects, resolve, samples, _renderPass); + } + + VkSampler getSampler(uint32_t _flags, VkFormat _format, const float _palette[][4]) + { + uint32_t index = ((_flags & BGFX_SAMPLER_BORDER_COLOR_MASK) >> BGFX_SAMPLER_BORDER_COLOR_SHIFT); + index = bx::min<uint32_t>(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, index); + + _flags &= BGFX_SAMPLER_BITS_MASK; + _flags &= ~(m_deviceFeatures.samplerAnisotropy ? 0 : (BGFX_SAMPLER_MIN_ANISOTROPIC | BGFX_SAMPLER_MAG_ANISOTROPIC) ); -// const D3D12_INPUT_ELEMENT_DESC inst = { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D12_APPEND_ALIGNED_ELEMENT, D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA, 1 }; + // Force both min+max anisotropic, can't be set individually. + _flags |= 0 != (_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC) ) + ? BGFX_SAMPLER_MIN_ANISOTROPIC|BGFX_SAMPLER_MAG_ANISOTROPIC + : 0 + ; + + const float* rgba = NULL == _palette + ? NULL + : _palette[index] + ; - // VK_VERTEX_INPUT_RATE_INSTANCE + const bool needColor = true + && needBorderColor(_flags) + && NULL != rgba + && m_borderColorSupport + ; - for (uint32_t ii = 0; ii < _numInstanceData; ++ii) + uint32_t hashKey; + VkSampler sampler = VK_NULL_HANDLE; + if (!needColor) + { + bx::HashMurmur2A hash; + hash.begin(); + hash.add(_flags); + hash.add(-1); + hash.add(VK_FORMAT_UNDEFINED); + hashKey = hash.end(); + + sampler = m_samplerCache.find(hashKey); + } + else { - uint32_t index = 7 - ii; // TEXCOORD7 = i_data0, TEXCOORD6 = i_data1, etc. + bx::HashMurmur2A hash; + hash.begin(); + hash.add(_flags); + hash.add(index); + hash.add(_format); + hashKey = hash.end(); + + const uint32_t colorHashKey = m_samplerBorderColorCache.find(hashKey); + const uint32_t newColorHashKey = bx::hash<bx::HashMurmur2A>(rgba, sizeof(float) * 4); + if (newColorHashKey == colorHashKey) + { + sampler = m_samplerCache.find(hashKey); + } + else + { + m_samplerBorderColorCache.add(hashKey, newColorHashKey); + } + } - BX_UNUSED(index); -// bx::memCopy(curr, &inst, sizeof(D3D12_INPUT_ELEMENT_DESC) ); -// curr->InputSlot = 1; -// curr->SemanticIndex = index; -// curr->AlignedByteOffset = ii*16; + if (VK_NULL_HANDLE != sampler) + { + return sampler; } - _vertexInputState.vertexAttributeDescriptionCount = num; - return num; + const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT; + + const float maxLodBias = m_deviceProperties.limits.maxSamplerLodBias; + const float lodBias = bx::clamp(float(BGFX_CONFIG_MIP_LOD_BIAS), -maxLodBias, maxLodBias); + + VkSamplerCreateInfo sci; + sci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; + sci.pNext = NULL; + sci.flags = 0; + sci.magFilter = _flags & BGFX_SAMPLER_MAG_POINT ? VK_FILTER_NEAREST : VK_FILTER_LINEAR; + sci.minFilter = _flags & BGFX_SAMPLER_MIN_POINT ? VK_FILTER_NEAREST : VK_FILTER_LINEAR; + sci.mipmapMode = _flags & BGFX_SAMPLER_MIP_POINT ? VK_SAMPLER_MIPMAP_MODE_NEAREST : VK_SAMPLER_MIPMAP_MODE_LINEAR; + sci.addressModeU = s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT]; + sci.addressModeV = s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT]; + sci.addressModeW = s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT]; + sci.mipLodBias = lodBias; + sci.anisotropyEnable = !!(_flags & (BGFX_SAMPLER_MIN_ANISOTROPIC | BGFX_SAMPLER_MAG_ANISOTROPIC) ); + sci.maxAnisotropy = m_maxAnisotropy; + sci.compareEnable = 0 != cmpFunc; + sci.compareOp = s_cmpFunc[cmpFunc]; + sci.minLod = 0.0f; + sci.maxLod = VK_LOD_CLAMP_NONE; + sci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK; + sci.unnormalizedCoordinates = VK_FALSE; + + VkSamplerCustomBorderColorCreateInfoEXT cbcci; + if (needColor) + { + cbcci.sType = VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT; + cbcci.pNext = NULL; + cbcci.format = _format; + bx::memCopy(cbcci.customBorderColor.float32, rgba, sizeof(cbcci.customBorderColor.float32) ); + + sci.pNext = &cbcci; + sci.borderColor = VK_BORDER_COLOR_FLOAT_CUSTOM_EXT; + } + + VK_CHECK(vkCreateSampler(m_device, &sci, m_allocatorCb, &sampler) ); + + m_samplerCache.add(hashKey, sampler); + return sampler; } - VkPipeline getPipeline(uint16_t _programIdx) + VkImageView getCachedImageView(TextureHandle _handle, uint32_t _mip, uint32_t _numMips, VkImageViewType _type, bool _stencil = false) { - BX_UNUSED(_programIdx); - // vkCreateComputePipelines - return VK_NULL_HANDLE; + const TextureVK& texture = m_textures[_handle.idx]; + + _stencil = _stencil && !!(texture.m_aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT); + + bx::HashMurmur2A hash; + hash.begin(); + hash.add(_handle.idx); + hash.add(_mip); + hash.add(_numMips); + hash.add(_type); + hash.add(_stencil); + uint32_t hashKey = hash.end(); + + VkImageView* viewCached = m_imageViewCache.find(hashKey); + + if (NULL != viewCached) + { + return *viewCached; + } + + const VkImageAspectFlags aspectMask = 0 + | VK_IMAGE_ASPECT_COLOR_BIT + | ( _stencil ? VK_IMAGE_ASPECT_STENCIL_BIT : VK_IMAGE_ASPECT_DEPTH_BIT) + ; + + VkImageView view; + VK_CHECK(texture.createView(0, texture.m_numSides, _mip, _numMips, _type, aspectMask, false, &view) ); + m_imageViewCache.add(hashKey, view, _handle.idx); + + return view; } - VkPipeline getPipeline(uint64_t _state, uint64_t _stencil, uint16_t _declIdx, uint16_t _programIdx, uint8_t _numInstanceData) + VkPipeline getPipeline(ProgramHandle _program) { - ProgramVK& program = m_program[_programIdx]; + ProgramVK& program = m_program[_program.idx]; + + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(program.m_vsh->m_hash); + const uint32_t hash = murmur.end(); + + VkPipeline pipeline = m_pipelineStateCache.find(hash); + + if (VK_NULL_HANDLE != pipeline) + { + return pipeline; + } + + VkComputePipelineCreateInfo cpci; + cpci.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO; + cpci.pNext = NULL; + cpci.flags = 0; + + cpci.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + cpci.stage.pNext = NULL; + cpci.stage.flags = 0; + cpci.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; + cpci.stage.module = program.m_vsh->m_module; + cpci.stage.pName = "main"; + cpci.stage.pSpecializationInfo = NULL; + + cpci.layout = program.m_pipelineLayout; + cpci.basePipelineHandle = VK_NULL_HANDLE; + cpci.basePipelineIndex = 0; + + VK_CHECK(vkCreateComputePipelines(m_device, m_pipelineCache, 1, &cpci, m_allocatorCb, &pipeline) ); + + m_pipelineStateCache.add(hash, pipeline); + + return pipeline; + } + + VkPipeline getPipeline(uint64_t _state, uint64_t _stencil, uint8_t _numStreams, const VertexLayout** _layouts, ProgramHandle _program, uint8_t _numInstanceData) + { + ProgramVK& program = m_program[_program.idx]; _state &= 0 - | BGFX_STATE_WRITE_RGB - | BGFX_STATE_WRITE_A - | BGFX_STATE_WRITE_Z + | BGFX_STATE_WRITE_MASK | BGFX_STATE_DEPTH_TEST_MASK | BGFX_STATE_BLEND_MASK | BGFX_STATE_BLEND_EQUATION_MASK - | BGFX_STATE_BLEND_INDEPENDENT + | (g_caps.supported & BGFX_CAPS_BLEND_INDEPENDENT ? BGFX_STATE_BLEND_INDEPENDENT : 0) | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE | BGFX_STATE_CULL_MASK + | BGFX_STATE_FRONT_CCW | BGFX_STATE_MSAA - | BGFX_STATE_LINEAA - | BGFX_STATE_CONSERVATIVE_RASTER + | (m_lineAASupport ? BGFX_STATE_LINEAA : 0) + | (g_caps.supported & BGFX_CAPS_CONSERVATIVE_RASTER ? BGFX_STATE_CONSERVATIVE_RASTER : 0) | BGFX_STATE_PT_MASK ; _stencil &= packStencil(~BGFX_STENCIL_FUNC_REF_MASK, ~BGFX_STENCIL_FUNC_REF_MASK); - VertexDecl decl; - bx::memCopy(&decl, &m_vertexDecls[_declIdx], sizeof(VertexDecl) ); - const uint16_t* attrMask = program.m_vsh->m_attrMask; - - for (uint32_t ii = 0; ii < Attrib::Count; ++ii) + VertexLayout layout; + if (0 < _numStreams) { - uint16_t mask = attrMask[ii]; - uint16_t attr = (decl.m_attributes[ii] & mask); - decl.m_attributes[ii] = attr == 0 ? UINT16_MAX : attr == UINT16_MAX ? 0 : attr; + bx::memCopy(&layout, _layouts[0], sizeof(VertexLayout) ); + const uint16_t* attrMask = program.m_vsh->m_attrMask; + + for (uint32_t ii = 0; ii < Attrib::Count; ++ii) + { + uint16_t mask = attrMask[ii]; + uint16_t attr = (layout.m_attributes[ii] & mask); + layout.m_attributes[ii] = attr == 0 ? UINT16_MAX : attr == UINT16_MAX ? 0 : attr; + } } + const FrameBufferVK& frameBuffer = isValid(m_fbh) + ? m_frameBuffers[m_fbh.idx] + : m_backBuffer + ; + bx::HashMurmur2A murmur; murmur.begin(); murmur.add(_state); murmur.add(_stencil); murmur.add(program.m_vsh->m_hash); murmur.add(program.m_vsh->m_attrMask, sizeof(program.m_vsh->m_attrMask) ); - murmur.add(program.m_fsh->m_hash); - murmur.add(m_vertexDecls[_declIdx].m_hash); - murmur.add(decl.m_attributes, sizeof(decl.m_attributes) ); - murmur.add(m_fbh.idx); + + if (NULL != program.m_fsh) + { + murmur.add(program.m_fsh->m_hash); + } + + for (uint8_t ii = 0; ii < _numStreams; ++ii) + { + murmur.add(_layouts[ii]->m_hash); + } + + murmur.add(layout.m_attributes, sizeof(layout.m_attributes) ); murmur.add(_numInstanceData); + murmur.add(frameBuffer.m_renderPass); const uint32_t hash = murmur.end(); VkPipeline pipeline = m_pipelineStateCache.find(hash); @@ -2663,18 +3635,36 @@ VK_IMPORT_DEVICE inputAssemblyState.primitiveRestartEnable = VK_FALSE; VkPipelineRasterizationStateCreateInfo rasterizationState; - setRasterizerState(rasterizationState, _state); + setRasterizerState(rasterizationState, _state, m_wireframe); + + VkBaseInStructure* nextRasterizationState = (VkBaseInStructure*)&rasterizationState; + + VkPipelineRasterizationConservativeStateCreateInfoEXT conservativeRasterizationState; + if (s_extension[Extension::EXT_conservative_rasterization].m_supported) + { + nextRasterizationState->pNext = (VkBaseInStructure*)&conservativeRasterizationState; + nextRasterizationState = (VkBaseInStructure*)&conservativeRasterizationState; + setConservativeRasterizerState(conservativeRasterizationState, _state); + } + + VkPipelineRasterizationLineStateCreateInfoEXT lineRasterizationState; + if (m_lineAASupport) + { + nextRasterizationState->pNext = (VkBaseInStructure*)&lineRasterizationState; + nextRasterizationState = (VkBaseInStructure*)&lineRasterizationState; + setLineRasterizerState(lineRasterizationState, _state); + } VkPipelineDepthStencilStateCreateInfo depthStencilState; setDepthStencilState(depthStencilState, _state, _stencil); - VkVertexInputBindingDescription inputBinding[Attrib::Count + 1 + BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; - VkVertexInputAttributeDescription inputAttrib[Attrib::Count + 1 + BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; + VkVertexInputBindingDescription inputBinding[BGFX_CONFIG_MAX_VERTEX_STREAMS + 1]; + VkVertexInputAttributeDescription inputAttrib[Attrib::Count + BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT]; VkPipelineVertexInputStateCreateInfo vertexInputState; vertexInputState.pVertexBindingDescriptions = inputBinding; vertexInputState.pVertexAttributeDescriptions = inputAttrib; - setInputLayout(vertexInputState, m_vertexDecls[_declIdx], program, _numInstanceData); + setInputLayout(vertexInputState, _numStreams, _layouts, program, _numInstanceData); const VkDynamicState dynamicStates[] = { @@ -2683,6 +3673,7 @@ VK_IMPORT_DEVICE VK_DYNAMIC_STATE_BLEND_CONSTANTS, VK_DYNAMIC_STATE_STENCIL_REFERENCE, }; + VkPipelineDynamicStateCreateInfo dynamicState; dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; dynamicState.pNext = NULL; @@ -2698,13 +3689,17 @@ VK_IMPORT_DEVICE shaderStages[0].module = program.m_vsh->m_module; shaderStages[0].pName = "main"; shaderStages[0].pSpecializationInfo = NULL; - shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; - shaderStages[1].pNext = NULL; - shaderStages[1].flags = 0; - shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; - shaderStages[1].module = program.m_fsh->m_module; - shaderStages[1].pName = "main"; - shaderStages[1].pSpecializationInfo = NULL; + + if (NULL != program.m_fsh) + { + shaderStages[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; + shaderStages[1].pNext = NULL; + shaderStages[1].flags = 0; + shaderStages[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT; + shaderStages[1].module = program.m_fsh->m_module; + shaderStages[1].pName = "main"; + shaderStages[1].pSpecializationInfo = NULL; + } VkPipelineViewportStateCreateInfo viewportState; viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; @@ -2719,9 +3714,9 @@ VK_IMPORT_DEVICE multisampleState.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampleState.pNext = NULL; multisampleState.flags = 0; - multisampleState.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; + multisampleState.rasterizationSamples = frameBuffer.m_sampler.Sample; multisampleState.sampleShadingEnable = VK_FALSE; - multisampleState.minSampleShading = !!(BGFX_STATE_CONSERVATIVE_RASTER & _state) ? 1.0f : 0.0f; + multisampleState.minSampleShading = 0.0f; multisampleState.pSampleMask = NULL; multisampleState.alphaToCoverageEnable = !!(BGFX_STATE_BLEND_ALPHA_TO_COVERAGE & _state); multisampleState.alphaToOneEnable = VK_FALSE; @@ -2730,7 +3725,7 @@ VK_IMPORT_DEVICE graphicsPipeline.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; graphicsPipeline.pNext = NULL; graphicsPipeline.flags = 0; - graphicsPipeline.stageCount = BX_COUNTOF(shaderStages); + graphicsPipeline.stageCount = NULL == program.m_fsh ? 1 : 2; graphicsPipeline.pStages = shaderStages; graphicsPipeline.pVertexInputState = &vertexInputState; graphicsPipeline.pInputAssemblyState = &inputAssemblyState; @@ -2741,8 +3736,8 @@ VK_IMPORT_DEVICE graphicsPipeline.pDepthStencilState = &depthStencilState; graphicsPipeline.pColorBlendState = &colorBlendState; graphicsPipeline.pDynamicState = &dynamicState; - graphicsPipeline.layout = m_pipelineLayout; - graphicsPipeline.renderPass = m_renderPass; + graphicsPipeline.layout = program.m_pipelineLayout; + graphicsPipeline.renderPass = frameBuffer.m_renderPass; graphicsPipeline.subpass = 0; graphicsPipeline.basePipelineHandle = VK_NULL_HANDLE; graphicsPipeline.basePipelineIndex = 0; @@ -2775,7 +3770,8 @@ VK_IMPORT_DEVICE VkPipelineCache cache; VK_CHECK(vkCreatePipelineCache(m_device, &pcci, m_allocatorCb, &cache) ); - VK_CHECK(vkCreateGraphicsPipelines(m_device + VK_CHECK(vkCreateGraphicsPipelines( + m_device , cache , 1 , &graphicsPipeline @@ -2793,6 +3789,7 @@ VK_IMPORT_DEVICE { cachedData = BX_REALLOC(g_allocator, cachedData, dataSize); } + VK_CHECK(vkGetPipelineCacheData(m_device, cache, &dataSize, cachedData) ); g_callback->cacheWrite(hash, cachedData, (uint32_t)dataSize); } @@ -2808,6 +3805,321 @@ VK_IMPORT_DEVICE return pipeline; } + VkDescriptorSet getDescriptorSet(const ProgramVK& program, const RenderBind& renderBind, const ScratchBufferVK& scratchBuffer, const float _palette[][4]) + { + VkDescriptorSet descriptorSet; + + VkDescriptorSetAllocateInfo dsai; + dsai.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + dsai.pNext = NULL; + dsai.descriptorPool = m_descriptorPool; + dsai.descriptorSetCount = 1; + dsai.pSetLayouts = &program.m_descriptorSetLayout; + + VK_CHECK(vkAllocateDescriptorSets(m_device, &dsai, &descriptorSet) ); + + VkDescriptorImageInfo imageInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + VkDescriptorBufferInfo bufferInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + + constexpr uint32_t kMaxDescriptorSets = 2 * BGFX_CONFIG_MAX_TEXTURE_SAMPLERS + 2; + VkWriteDescriptorSet wds[kMaxDescriptorSets] = {}; + + uint32_t wdsCount = 0; + uint32_t bufferCount = 0; + uint32_t imageCount = 0; + + for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) + { + const Binding& bind = renderBind.m_bind[stage]; + const BindInfo& bindInfo = program.m_bindInfo[stage]; + + if (kInvalidHandle != bind.m_idx + && isValid(bindInfo.uniformHandle) ) + { + switch (bind.m_type) + { + case Binding::Image: + { + const bool isImageDescriptor = BindType::Image == bindInfo.type; + + wds[wdsCount].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + wds[wdsCount].pNext = NULL; + wds[wdsCount].dstSet = descriptorSet; + wds[wdsCount].dstBinding = bindInfo.binding; + wds[wdsCount].dstArrayElement = 0; + wds[wdsCount].descriptorCount = 1; + wds[wdsCount].descriptorType = isImageDescriptor + ? VK_DESCRIPTOR_TYPE_STORAGE_IMAGE + : VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE + ; + wds[wdsCount].pImageInfo = NULL; + wds[wdsCount].pBufferInfo = NULL; + wds[wdsCount].pTexelBufferView = NULL; + + const TextureVK& texture = m_textures[bind.m_idx]; + + VkImageViewType type = texture.m_type; + if (UINT32_MAX != bindInfo.index) + { + type = program.m_textures[bindInfo.index].type; + } + else if (type == VK_IMAGE_VIEW_TYPE_CUBE + || type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) + { + type = VK_IMAGE_VIEW_TYPE_2D_ARRAY; + } + + BX_ASSERT( + texture.m_currentImageLayout == texture.m_sampledLayout + , "Mismatching image layout. Texture currently used as a framebuffer attachment?" + ); + + imageInfo[imageCount].imageLayout = texture.m_sampledLayout; + imageInfo[imageCount].sampler = VK_NULL_HANDLE; + imageInfo[imageCount].imageView = getCachedImageView( + { bind.m_idx } + , bind.m_mip + , 1 + , type + ); + wds[wdsCount].pImageInfo = &imageInfo[imageCount]; + ++imageCount; + + ++wdsCount; + } + break; + + case Binding::VertexBuffer: + case Binding::IndexBuffer: + { + wds[wdsCount].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + wds[wdsCount].pNext = NULL; + wds[wdsCount].dstSet = descriptorSet; + wds[wdsCount].dstBinding = bindInfo.binding; + wds[wdsCount].dstArrayElement = 0; + wds[wdsCount].descriptorCount = 1; + wds[wdsCount].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; + wds[wdsCount].pImageInfo = NULL; + wds[wdsCount].pBufferInfo = NULL; + wds[wdsCount].pTexelBufferView = NULL; + + const BufferVK& sb = bind.m_type == Binding::VertexBuffer + ? m_vertexBuffers[bind.m_idx] + : m_indexBuffers[bind.m_idx] + ; + + bufferInfo[bufferCount].buffer = sb.m_buffer; + bufferInfo[bufferCount].offset = 0; + bufferInfo[bufferCount].range = sb.m_size; + wds[wdsCount].pBufferInfo = &bufferInfo[bufferCount]; + ++bufferCount; + + ++wdsCount; + } + break; + + case Binding::Texture: + { + TextureVK& texture = m_textures[bind.m_idx]; + const uint32_t samplerFlags = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & bind.m_samplerFlags) + ? bind.m_samplerFlags + : (uint32_t)texture.m_flags + ; + const bool sampleStencil = !!(samplerFlags & BGFX_SAMPLER_SAMPLE_STENCIL); + VkSampler sampler = getSampler(samplerFlags, texture.m_format, _palette); + + const VkImageViewType type = UINT32_MAX == bindInfo.index + ? texture.m_type + : program.m_textures[bindInfo.index].type + ; + + BX_ASSERT( + texture.m_currentImageLayout == texture.m_sampledLayout + , "Mismatching image layout. Texture currently used as a framebuffer attachment?" + ); + + imageInfo[imageCount].imageLayout = texture.m_sampledLayout; + imageInfo[imageCount].sampler = sampler; + imageInfo[imageCount].imageView = getCachedImageView( + { bind.m_idx } + , 0 + , texture.m_numMips + , type + , sampleStencil + ); + + wds[wdsCount].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + wds[wdsCount].pNext = NULL; + wds[wdsCount].dstSet = descriptorSet; + wds[wdsCount].dstBinding = bindInfo.binding; + wds[wdsCount].dstArrayElement = 0; + wds[wdsCount].descriptorCount = 1; + wds[wdsCount].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + wds[wdsCount].pImageInfo = &imageInfo[imageCount]; + wds[wdsCount].pBufferInfo = NULL; + wds[wdsCount].pTexelBufferView = NULL; + ++wdsCount; + + wds[wdsCount].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + wds[wdsCount].pNext = NULL; + wds[wdsCount].dstSet = descriptorSet; + wds[wdsCount].dstBinding = bindInfo.samplerBinding; + wds[wdsCount].dstArrayElement = 0; + wds[wdsCount].descriptorCount = 1; + wds[wdsCount].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; + wds[wdsCount].pImageInfo = &imageInfo[imageCount]; + wds[wdsCount].pBufferInfo = NULL; + wds[wdsCount].pTexelBufferView = NULL; + ++wdsCount; + + ++imageCount; + } + break; + } + } + } + + const uint32_t vsize = program.m_vsh->m_size; + const uint32_t fsize = NULL != program.m_fsh ? program.m_fsh->m_size : 0; + + if (vsize > 0) + { + bufferInfo[bufferCount].buffer = scratchBuffer.m_buffer; + bufferInfo[bufferCount].offset = 0; + bufferInfo[bufferCount].range = vsize; + + wds[wdsCount].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + wds[wdsCount].pNext = NULL; + wds[wdsCount].dstSet = descriptorSet; + wds[wdsCount].dstBinding = program.m_vsh->m_uniformBinding; + wds[wdsCount].dstArrayElement = 0; + wds[wdsCount].descriptorCount = 1; + wds[wdsCount].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; + wds[wdsCount].pImageInfo = NULL; + wds[wdsCount].pBufferInfo = &bufferInfo[bufferCount]; + wds[wdsCount].pTexelBufferView = NULL; + ++wdsCount; + ++bufferCount; + } + + if (fsize > 0) + { + bufferInfo[bufferCount].buffer = scratchBuffer.m_buffer; + bufferInfo[bufferCount].offset = 0; + bufferInfo[bufferCount].range = fsize; + + wds[wdsCount].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; + wds[wdsCount].pNext = NULL; + wds[wdsCount].dstSet = descriptorSet; + wds[wdsCount].dstBinding = program.m_fsh->m_uniformBinding; + wds[wdsCount].dstArrayElement = 0; + wds[wdsCount].descriptorCount = 1; + wds[wdsCount].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; + wds[wdsCount].pImageInfo = NULL; + wds[wdsCount].pBufferInfo = &bufferInfo[bufferCount]; + wds[wdsCount].pTexelBufferView = NULL; + ++wdsCount; + ++bufferCount; + } + + vkUpdateDescriptorSets(m_device, wdsCount, wds, 0, NULL); + + VkDescriptorSet temp = descriptorSet; + release(temp); + + return descriptorSet; + } + + bool isSwapChainReadable(const SwapChainVK& _swapChain) + { + return true + && NULL != _swapChain.m_nwh + && _swapChain.m_needPresent + && _swapChain.m_supportsReadback + && bimg::imageConvert(bimg::TextureFormat::BGRA8, bimg::TextureFormat::Enum(_swapChain.m_colorFormat) ) + ; + } + + typedef void (*SwapChainReadFunc)(void* /*src*/, uint32_t /*width*/, uint32_t /*height*/, uint32_t /*pitch*/, const void* /*userData*/); + + bool readSwapChain(const SwapChainVK& _swapChain, VkBuffer _buffer, VkDeviceMemory _memory, SwapChainReadFunc _func, const void* _userData = NULL) + { + if (isSwapChainReadable(_swapChain) ) + { + // source for the copy is the last rendered swapchain image + const VkImage image = _swapChain.m_backBufferColorImage[_swapChain.m_backBufferColorIdx]; + const VkImageLayout layout = _swapChain.m_backBufferColorImageLayout[_swapChain.m_backBufferColorIdx]; + + const uint32_t width = _swapChain.m_sci.imageExtent.width; + const uint32_t height = _swapChain.m_sci.imageExtent.height; + + ReadbackVK readback; + readback.create(image, width, height, _swapChain.m_colorFormat); + const uint32_t pitch = readback.pitch(); + + readback.copyImageToBuffer(m_commandBuffer, _buffer, layout, VK_IMAGE_ASPECT_COLOR_BIT); + + // stall for commandbuffer to finish + kick(true); + + uint8_t* src; + VK_CHECK(vkMapMemory(m_device, _memory, 0, VK_WHOLE_SIZE, 0, (void**)&src) ); + + if (_swapChain.m_colorFormat == TextureFormat::RGBA8) + { + bimg::imageSwizzleBgra8(src, pitch, width, height, src, pitch); + _func(src, width, height, pitch, _userData); + } + else if (_swapChain.m_colorFormat == TextureFormat::BGRA8) + { + _func(src, width, height, pitch, _userData); + } + else + { + const uint8_t dstBpp = bimg::getBitsPerPixel(bimg::TextureFormat::BGRA8); + const uint32_t dstPitch = width * dstBpp / 8; + const uint32_t dstSize = height * dstPitch; + + void* dst = BX_ALLOC(g_allocator, dstSize); + + bimg::imageConvert(g_allocator, dst, bimg::TextureFormat::BGRA8, src, bimg::TextureFormat::Enum(_swapChain.m_colorFormat), width, height, 1); + + _func(dst, width, height, dstPitch, _userData); + + BX_FREE(g_allocator, dst); + } + + vkUnmapMemory(m_device, _memory); + + readback.destroy(); + + return true; + } + + return false; + } + + void capture() + { + if (m_captureSize > 0) + { + m_backBuffer.resolve(); + + auto callback = [](void* _src, uint32_t /*_width*/, uint32_t _height, uint32_t _pitch, const void* /*_userData*/) + { + const uint32_t size = _height * _pitch; + g_callback->captureFrame(_src, size); + }; + + readSwapChain(m_backBuffer.m_swapChain, m_captureBuffer, m_captureMemory, callback); + } + } + + bool isVisible(Frame* _render, OcclusionQueryHandle _handle, bool _visible) + { + return _visible == (0 != _render->m_occlusion[_handle.idx]); + } + void commit(UniformBuffer& _uniformBuffer) { _uniformBuffer.reset(); @@ -2839,22 +4151,14 @@ VK_IMPORT_DEVICE data = (const char*)m_uniforms[handle.idx]; } -#define CASE_IMPLEMENT_UNIFORM(_uniform, _dxsuffix, _type) \ - case UniformType::_uniform: \ - case UniformType::_uniform|BGFX_UNIFORM_FRAGMENTBIT: \ - { \ - setShaderUniform(uint8_t(type), loc, data, num); \ - } \ - break; - switch ( (uint32_t)type) { case UniformType::Mat3: - case UniformType::Mat3|BGFX_UNIFORM_FRAGMENTBIT: - { + case UniformType::Mat3|kUniformFragmentBit: + { float* value = (float*)data; for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3*16, value += 9) - { + { Matrix4 mtx; mtx.un.val[ 0] = value[0]; mtx.un.val[ 1] = value[1]; @@ -2873,9 +4177,19 @@ VK_IMPORT_DEVICE } break; - CASE_IMPLEMENT_UNIFORM(Int1, I, int); - CASE_IMPLEMENT_UNIFORM(Vec4, F, float); - CASE_IMPLEMENT_UNIFORM(Mat4, F, float); + case UniformType::Sampler: + case UniformType::Sampler|kUniformFragmentBit: + // do nothing, but VkDescriptorSetImageInfo would be set before drawing + break; + + case UniformType::Vec4: + case UniformType::Vec4 | kUniformFragmentBit: + case UniformType::Mat4: + case UniformType::Mat4 | kUniformFragmentBit: + { + setShaderUniform(uint8_t(type), loc, data, num); + } + break; case UniformType::End: break; @@ -2884,7 +4198,6 @@ VK_IMPORT_DEVICE BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy); break; } -#undef CASE_IMPLEMENT_UNIFORM } } @@ -2898,189 +4211,307 @@ VK_IMPORT_DEVICE rect[0].baseArrayLayer = 0; rect[0].layerCount = 1; - uint32_t numMrt = 1; -// FrameBufferHandle fbh = m_fbh; -// if (isValid(fbh) ) -// { -// const FrameBufferVK& fb = m_frameBuffers[fbh.idx]; -// numMrt = bx::uint32_max(1, fb.m_num); -// } + uint32_t numMrt; + bgfx::TextureFormat::Enum mrtFormat[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + VkImageAspectFlags depthAspectMask; - VkClearAttachment attachments[BGFX_CONFIG_MAX_FRAME_BUFFERS]; - uint32_t mrt = 0; + const FrameBufferVK& fb = isValid(m_fbh) + ? m_frameBuffers[m_fbh.idx] + : m_backBuffer + ; - if (true //NULL != m_currentColor - && BGFX_CLEAR_COLOR & _clear.m_flags) + if (NULL == fb.m_nwh) { - if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) + numMrt = fb.m_num; + for (uint8_t ii = 0; ii < fb.m_num; ++ii) { - for (uint32_t ii = 0; ii < numMrt; ++ii) - { - attachments[mrt].colorAttachment = mrt; - attachments[mrt].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - bx::memCopy(&attachments[mrt].clearValue.color.float32, _palette[index], 16); - ++mrt; - } + mrtFormat[ii] = bgfx::TextureFormat::Enum(m_textures[fb.m_texture[ii].idx].m_requestedFormat); } - else + depthAspectMask = isValid(fb.m_depth) ? m_textures[fb.m_depth.idx].m_aspectMask : 0; + rect[0].layerCount = fb.m_attachment[0].numLayers; + } + else + { + numMrt = 1; + mrtFormat[0] = fb.m_swapChain.m_colorFormat; + depthAspectMask = fb.m_swapChain.m_backBufferDepthStencil.m_aspectMask; + } + + VkClearAttachment attachments[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS + 1]; + uint32_t mrt = 0; + + if (BGFX_CLEAR_COLOR & _clear.m_flags) + { + for (uint32_t ii = 0; ii < numMrt; ++ii) { - float frgba[4] = + attachments[mrt].colorAttachment = mrt; + attachments[mrt].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + + VkClearColorValue& clearValue = attachments[mrt].clearValue.color; + + const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(mrtFormat[ii]) ); + const bx::EncodingType::Enum type = bx::EncodingType::Enum(blockInfo.encoding); + + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) { - _clear.m_index[0] * 1.0f / 255.0f, - _clear.m_index[1] * 1.0f / 255.0f, - _clear.m_index[2] * 1.0f / 255.0f, - _clear.m_index[3] * 1.0f / 255.0f, - }; + const uint8_t index = bx::min<uint8_t>(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); - for (uint32_t ii = 0; ii < numMrt; ++ii) + switch (type) + { + case bx::EncodingType::Int: + case bx::EncodingType::Uint: + clearValue.int32[0] = int32_t(_palette[index][0]); + clearValue.int32[1] = int32_t(_palette[index][1]); + clearValue.int32[2] = int32_t(_palette[index][2]); + clearValue.int32[3] = int32_t(_palette[index][3]); + break; + default: + bx::memCopy(&clearValue.float32, _palette[index], sizeof(clearValue.float32) ); + break; + } + } + else { - attachments[mrt].colorAttachment = mrt; - attachments[mrt].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; - bx::memCopy(&attachments[mrt].clearValue.color.float32, frgba, 16); - ++mrt; + switch (type) + { + case bx::EncodingType::Int: + case bx::EncodingType::Uint: + clearValue.uint32[0] = _clear.m_index[0]; + clearValue.uint32[1] = _clear.m_index[1]; + clearValue.uint32[2] = _clear.m_index[2]; + clearValue.uint32[3] = _clear.m_index[3]; + break; + default: + bx::unpackRgba8(clearValue.float32, _clear.m_index); + break; + } } + + ++mrt; } } - if (true //NULL != m_currentDepthStencil - && (BGFX_CLEAR_DEPTH | BGFX_CLEAR_STENCIL) & _clear.m_flags) - { - attachments[mrt].colorAttachment = mrt; - attachments[mrt].aspectMask = 0; - attachments[mrt].aspectMask |= (_clear.m_flags & BGFX_CLEAR_DEPTH ) ? VK_IMAGE_ASPECT_DEPTH_BIT : 0; - attachments[mrt].aspectMask |= (_clear.m_flags & BGFX_CLEAR_STENCIL) ? VK_IMAGE_ASPECT_STENCIL_BIT : 0; + depthAspectMask &= 0 + | (_clear.m_flags & BGFX_CLEAR_DEPTH ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) + | (_clear.m_flags & BGFX_CLEAR_STENCIL ? VK_IMAGE_ASPECT_STENCIL_BIT : 0) + ; + if (0 != depthAspectMask) + { + attachments[mrt].aspectMask = depthAspectMask; attachments[mrt].clearValue.depthStencil.stencil = _clear.m_stencil; attachments[mrt].clearValue.depthStencil.depth = _clear.m_depth; ++mrt; } - vkCmdClearAttachments(m_commandBuffer - , mrt - , attachments - , BX_COUNTOF(rect) - , rect - ); + if (mrt > 0) + { + vkCmdClearAttachments(m_commandBuffer, mrt, attachments, BX_COUNTOF(rect), rect); + } } - uint64_t kick(VkSemaphore _wait = VK_NULL_HANDLE, VkSemaphore _signal = VK_NULL_HANDLE) + void kick(bool _finishAll = false) { - VkPipelineStageFlags stageFlags = 0 - | VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT - ; - - VkSubmitInfo si; - si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - si.pNext = NULL; - si.waitSemaphoreCount = VK_NULL_HANDLE != _wait; - si.pWaitSemaphores = &_wait; - si.pWaitDstStageMask = &stageFlags; - si.commandBufferCount = 1; - si.pCommandBuffers = &m_commandBuffers[m_backBufferColorIdx]; - si.signalSemaphoreCount = VK_NULL_HANDLE != _signal; - si.pSignalSemaphores = &_signal; - -// VK_CHECK(vkResetFences(m_device, 1, &m_fence) ); - VK_CHECK(vkQueueSubmit(m_queueGraphics, 1, &si, VK_NULL_HANDLE) ); - return 0; + m_cmd.kick(_finishAll); + VK_CHECK(m_cmd.alloc(&m_commandBuffer) ); + m_cmd.finish(_finishAll); } - void finish() + int32_t selectMemoryType(uint32_t _memoryTypeBits, uint32_t _propertyFlags, int32_t _startIndex = 0) const { - finishAll(); + for (int32_t ii = _startIndex, num = m_memoryProperties.memoryTypeCount; ii < num; ++ii) + { + const VkMemoryType& memType = m_memoryProperties.memoryTypes[ii]; + if ( (0 != ( (1<<ii) & _memoryTypeBits) ) + && ( (memType.propertyFlags & _propertyFlags) == _propertyFlags) ) + { + return ii; + } + } + + BX_TRACE("Failed to find memory that supports flags 0x%08x.", _propertyFlags); + return -1; } - void finishAll() + VkResult allocateMemory(const VkMemoryRequirements* requirements, VkMemoryPropertyFlags propertyFlags, ::VkDeviceMemory* memory) const { - VK_CHECK(vkQueueWaitIdle(m_queueGraphics) ); -// VK_CHECK(vkWaitForFences(m_device, 1, &m_fence, true, INT64_MAX) ); + VkMemoryAllocateInfo ma; + ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; + ma.pNext = NULL; + ma.allocationSize = requirements->size; + + VkResult result = VK_ERROR_UNKNOWN; + int32_t searchIndex = -1; + do + { + searchIndex++; + searchIndex = selectMemoryType(requirements->memoryTypeBits, propertyFlags, searchIndex); + + if (searchIndex >= 0) + { + ma.memoryTypeIndex = searchIndex; + result = vkAllocateMemory(m_device, &ma, m_allocatorCb, memory); + } + } + while (result != VK_SUCCESS + && searchIndex >= 0); + + return result; } - uint32_t selectMemoryType(uint32_t _memoryTypeBits, uint32_t _propertyFlags) const + VkResult createHostBuffer(uint32_t _size, VkMemoryPropertyFlags _flags, ::VkBuffer* _buffer, ::VkDeviceMemory* _memory, const void* _data = NULL) { - for (uint32_t ii = 0, num = m_memoryProperties.memoryTypeCount; ii < num; ++ii) + VkResult result = VK_SUCCESS; + + VkBufferCreateInfo bci; + bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; + bci.pNext = NULL; + bci.flags = 0; + bci.size = _size; + bci.queueFamilyIndexCount = 0; + bci.pQueueFamilyIndices = NULL; + bci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + bci.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT; + + result = vkCreateBuffer(m_device, &bci, m_allocatorCb, _buffer); + if (VK_SUCCESS != result) { - const VkMemoryType& memType = m_memoryProperties.memoryTypes[ii]; - if ( (0 != ( (1<<ii) & _memoryTypeBits) ) - && ( (memType.propertyFlags & _propertyFlags) == _propertyFlags) ) + BX_TRACE("Create host buffer error: vkCreateBuffer failed %d: %s.", result, getName(result) ); + return result; + } + + VkMemoryRequirements mr; + vkGetBufferMemoryRequirements(m_device, *_buffer, &mr); + + result = allocateMemory(&mr, _flags, _memory); + + if (VK_SUCCESS != result + && (_flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) ) + { + result = allocateMemory(&mr, _flags & ~VK_MEMORY_PROPERTY_HOST_CACHED_BIT, _memory); + } + + if (VK_SUCCESS != result) + { + BX_TRACE("Create host buffer error: vkAllocateMemory failed %d: %s.", result, getName(result) ); + return result; + } + + result = vkBindBufferMemory(m_device, *_buffer, *_memory, 0); + if (VK_SUCCESS != result) + { + BX_TRACE("Create host buffer error: vkBindBufferMemory failed %d: %s.", result, getName(result) ); + return result; + } + + if (_data != NULL) + { + void* dst; + result = vkMapMemory(m_device, *_memory, 0, _size, 0, &dst); + if (VK_SUCCESS != result) { - return ii; + BX_TRACE("Create host buffer error: vkMapMemory failed %d: %s.", result, getName(result) ); + return result; } + + bx::memCopy(dst, _data, _size); + vkUnmapMemory(m_device, *_memory); } - BX_TRACE("Failed to find memory that supports flags 0x%08x.", _propertyFlags); - return 0; + return result; + } + + VkResult createStagingBuffer(uint32_t _size, ::VkBuffer* _buffer, ::VkDeviceMemory* _memory, const void* _data = NULL) + { + const VkMemoryPropertyFlags flags = 0 + | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT + ; + return createHostBuffer(_size, flags, _buffer, _memory, _data); + } + + VkResult createReadbackBuffer(uint32_t _size, ::VkBuffer* _buffer, ::VkDeviceMemory* _memory) + { + const VkMemoryPropertyFlags flags = 0 + | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT + | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT + | VK_MEMORY_PROPERTY_HOST_CACHED_BIT + ; + return createHostBuffer(_size, flags, _buffer, _memory, NULL); } VkAllocationCallbacks* m_allocatorCb; VkDebugReportCallbackEXT m_debugReportCallback; VkInstance m_instance; VkPhysicalDevice m_physicalDevice; + uint32_t m_instanceApiVersion; VkPhysicalDeviceProperties m_deviceProperties; VkPhysicalDeviceMemoryProperties m_memoryProperties; + VkPhysicalDeviceFeatures m_deviceFeatures; - VkSwapchainCreateInfoKHR m_sci; - VkSurfaceKHR m_surface; - VkSwapchainKHR m_swapchain; - VkImage m_backBufferColorImage[4]; - VkImageView m_backBufferColorImageView[4]; - VkFramebuffer m_backBufferColor[4]; - VkCommandBuffer m_commandBuffers[4]; - VkCommandBuffer m_commandBuffer; + bool m_lineAASupport; + bool m_borderColorSupport; + bool m_timerQuerySupport; - VkFormat m_backBufferDepthStencilFormat; - VkDeviceMemory m_backBufferDepthStencilMemory; - VkImage m_backBufferDepthStencilImage; - VkImageView m_backBufferDepthStencilImageView; + FrameBufferVK m_backBuffer; + TextureFormat::Enum m_swapchainFormats[TextureFormat::Count]; - ScratchBufferVK m_scratchBuffer[4]; - VkSemaphore m_presentDone[4]; + uint16_t m_numWindows; + FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + int64_t m_presentElapsed; - uint32_t m_qfiGraphics; - uint32_t m_qfiCompute; + ScratchBufferVK m_scratchBuffer[BGFX_CONFIG_MAX_FRAME_LATENCY]; + + uint32_t m_numFramesInFlight; + CommandQueueVK m_cmd; + VkCommandBuffer m_commandBuffer; VkDevice m_device; - VkQueue m_queueGraphics; - VkQueue m_queueCompute; - VkFence m_fence; - VkRenderPass m_renderPass; + uint32_t m_globalQueueFamily; + VkQueue m_globalQueue; VkDescriptorPool m_descriptorPool; - VkDescriptorSetLayout m_descriptorSetLayout; - VkPipelineLayout m_pipelineLayout; - VkPipelineCache m_pipelineCache; - VkCommandPool m_commandPool; + VkPipelineCache m_pipelineCache; + + TimerQueryVK m_gpuTimer; + OcclusionQueryVK m_occlusionQuery; void* m_renderDocDll; void* m_vulkan1Dll; - IndexBufferVK m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; + IndexBufferVK m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; VertexBufferVK m_vertexBuffers[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; - ShaderVK m_shaders[BGFX_CONFIG_MAX_SHADERS]; - ProgramVK m_program[BGFX_CONFIG_MAX_PROGRAMS]; - TextureVK m_textures[BGFX_CONFIG_MAX_TEXTURES]; - VertexDecl m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_DECLS]; - FrameBufferVK m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + ShaderVK m_shaders[BGFX_CONFIG_MAX_SHADERS]; + ProgramVK m_program[BGFX_CONFIG_MAX_PROGRAMS]; + TextureVK m_textures[BGFX_CONFIG_MAX_TEXTURES]; + VertexLayout m_vertexLayouts[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; + FrameBufferVK m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; Matrix4 m_predefinedUniforms[PredefinedUniform::Count]; UniformRegistry m_uniformReg; StateCacheT<VkPipeline> m_pipelineStateCache; + StateCacheT<VkDescriptorSetLayout> m_descriptorSetLayoutCache; + StateCacheT<VkRenderPass> m_renderPassCache; + StateCacheT<VkSampler> m_samplerCache; + StateCacheT<uint32_t> m_samplerBorderColorCache; + StateCacheLru<VkImageView, 1024> m_imageViewCache; Resolution m_resolution; - uint32_t m_maxAnisotropy; + float m_maxAnisotropy; bool m_depthClamp; bool m_wireframe; + VkBuffer m_captureBuffer; + VkDeviceMemory m_captureMemory; + uint32_t m_captureSize; + TextVideoMem m_textVideoMem; uint8_t m_fsScratch[64<<10]; uint8_t m_vsScratch[64<<10]; - uint32_t m_fsChanges; - uint32_t m_vsChanges; - uint32_t m_backBufferColorIdx; FrameBufferHandle m_fbh; }; @@ -3104,245 +4535,168 @@ VK_IMPORT_DEVICE s_renderVK = NULL; } -#define VK_DESTROY_FUNC(_name) \ - void vkDestroy(Vk##_name& _obj) \ - { \ - if (VK_NULL_HANDLE != _obj) \ - { \ - vkDestroy##_name(s_renderVK->m_device, _obj, s_renderVK->m_allocatorCb); \ - _obj = VK_NULL_HANDLE; \ - } \ - } +#define VK_DESTROY_FUNC(_name) \ + void vkDestroy(Vk##_name& _obj) \ + { \ + if (VK_NULL_HANDLE != _obj) \ + { \ + vkDestroy##_name(s_renderVK->m_device, _obj.vk, s_renderVK->m_allocatorCb); \ + _obj = VK_NULL_HANDLE; \ + } \ + } \ + void release(Vk##_name& _obj) \ + { \ + s_renderVK->release(_obj); \ + } VK_DESTROY #undef VK_DESTROY_FUNC - void ScratchBufferVK::create(uint32_t _size, uint32_t _maxDescriptors) + void vkDestroy(VkDeviceMemory& _obj) { - m_maxDescriptors = _maxDescriptors; - m_descriptorSet = (VkDescriptorSet*)BX_ALLOC(g_allocator, _maxDescriptors * sizeof(VkDescriptorSet) ); + if (VK_NULL_HANDLE != _obj) + { + vkFreeMemory(s_renderVK->m_device, _obj.vk, s_renderVK->m_allocatorCb); + _obj = VK_NULL_HANDLE; + } + } - VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; - VkDevice device = s_renderVK->m_device; + void vkDestroy(VkSurfaceKHR& _obj) + { + if (VK_NULL_HANDLE != _obj) + { + vkDestroySurfaceKHR(s_renderVK->m_instance, _obj.vk, s_renderVK->m_allocatorCb); + _obj = VK_NULL_HANDLE; + } + } - VkDescriptorSetAllocateInfo dsai; - dsai.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; - dsai.pNext = NULL; - dsai.descriptorPool = s_renderVK->m_descriptorPool; - dsai.descriptorSetCount = 1; - dsai.pSetLayouts = &s_renderVK->m_descriptorSetLayout; - for (uint32_t ii = 0, num = m_maxDescriptors; ii < num; ++ii) + void vkDestroy(VkDescriptorSet& _obj) + { + if (VK_NULL_HANDLE != _obj) { - VK_CHECK(vkAllocateDescriptorSets(device, &dsai, &m_descriptorSet[ii]) ); + vkFreeDescriptorSets(s_renderVK->m_device, s_renderVK->m_descriptorPool, 1, &_obj); + _obj = VK_NULL_HANDLE; } + } + + void release(VkDeviceMemory& _obj) + { + s_renderVK->release(_obj); + } + + void release(VkSurfaceKHR& _obj) + { + s_renderVK->release(_obj); + } + + void release(VkDescriptorSet& _obj) + { + s_renderVK->release(_obj); + } + + void ScratchBufferVK::create(uint32_t _size, uint32_t _count) + { + const VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; + const VkDevice device = s_renderVK->m_device; + const VkPhysicalDeviceLimits& deviceLimits = s_renderVK->m_deviceProperties.limits; + + const uint32_t align = uint32_t(deviceLimits.minUniformBufferOffsetAlignment); + const uint32_t entrySize = bx::strideAlign(_size, align); + const uint32_t totalSize = entrySize * _count; VkBufferCreateInfo bci; bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bci.pNext = NULL; bci.flags = 0; - bci.size = _size; - bci.usage = 0 - | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT -// | VK_BUFFER_USAGE_TRANSFER_DST_BIT - ; - bci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + bci.size = totalSize; + bci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT; + bci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; bci.queueFamilyIndexCount = 0; bci.pQueueFamilyIndices = NULL; - VK_CHECK(vkCreateBuffer(device + VK_CHECK(vkCreateBuffer( + device , &bci , allocatorCb , &m_buffer ) ); VkMemoryRequirements mr; - vkGetBufferMemoryRequirements(device + vkGetBufferMemoryRequirements( + device , m_buffer , &mr ); - VkMemoryAllocateInfo ma; - ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - ma.pNext = NULL; - ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits - , VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT - ); - VK_CHECK(vkAllocateMemory(device - , &ma - , allocatorCb - , &m_deviceMem - ) ); + VkMemoryPropertyFlags flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + VkResult result = s_renderVK->allocateMemory(&mr, flags, &m_deviceMem); + + if (VK_SUCCESS != result) + { + flags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; + VK_CHECK(s_renderVK->allocateMemory(&mr, flags, &m_deviceMem) ); + } m_size = (uint32_t)mr.size; m_pos = 0; VK_CHECK(vkBindBufferMemory(device, m_buffer, m_deviceMem, 0) ); - VK_CHECK(vkMapMemory(device, m_deviceMem, 0, ma.allocationSize, 0, (void**)&m_data) ); + VK_CHECK(vkMapMemory(device, m_deviceMem, 0, m_size, 0, (void**)&m_data) ); } void ScratchBufferVK::destroy() { - VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; - VkDevice device = s_renderVK->m_device; - - vkFreeDescriptorSets(device, s_renderVK->m_descriptorPool, m_maxDescriptors, m_descriptorSet); - BX_FREE(g_allocator, m_descriptorSet); - - vkUnmapMemory(device, m_deviceMem); + reset(); - vkDestroy(m_buffer); + vkUnmapMemory(s_renderVK->m_device, m_deviceMem); - vkFreeMemory(device - , m_deviceMem - , allocatorCb - ); + s_renderVK->release(m_buffer); + s_renderVK->release(m_deviceMem); } - void ScratchBufferVK::reset(VkDescriptorBufferInfo& /*_descriptorBufferInfo*/) + void ScratchBufferVK::reset() { m_pos = 0; - m_currentDs = 0; } - void* ScratchBufferVK::allocUbv(VkDescriptorBufferInfo& _descriptorBufferInfo, uint32_t _size) + uint32_t ScratchBufferVK::write(const void* _data, uint32_t _size) { - uint32_t total = bx::strideAlign(_size - , uint32_t(s_renderVK->m_deviceProperties.limits.minUniformBufferOffsetAlignment) - ); - _descriptorBufferInfo.buffer = m_buffer; - _descriptorBufferInfo.offset = m_pos; - _descriptorBufferInfo.range = total; - - VkWriteDescriptorSet wds[1]; - wds[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; - wds[0].pNext = NULL; - wds[0].dstSet = m_descriptorSet[m_currentDs]; - wds[0].dstBinding = DslBinding::UniformBuffer; - wds[0].dstArrayElement = 0; - wds[0].descriptorCount = 1; - wds[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; - wds[0].pImageInfo = NULL; - wds[0].pBufferInfo = &_descriptorBufferInfo; - wds[0].pTexelBufferView = NULL; - vkUpdateDescriptorSets(s_renderVK->m_device, BX_COUNTOF(wds), wds, 0, NULL); - - void* data = &m_data[m_pos]; - m_pos += total; - ++m_currentDs; - - return data; - } - - VkResult ImageVK::create(VkFormat _format, const VkExtent3D& _extent) - { - VkResult result; - - VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; - VkDevice device = s_renderVK->m_device; - - VkImageCreateInfo ici; - ici.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; - ici.pNext = NULL; - ici.flags = 0; - ici.imageType = VK_IMAGE_TYPE_2D; - ici.format = _format; - ici.extent = _extent; - ici.mipLevels = 1; - ici.arrayLayers = 1; - ici.samples = VK_SAMPLE_COUNT_1_BIT; - ici.tiling = VK_IMAGE_TILING_OPTIMAL; - ici.usage = 0 - | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT - | VK_IMAGE_USAGE_TRANSFER_SRC_BIT - ; - ici.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - ici.queueFamilyIndexCount = 0; - ici.pQueueFamilyIndices = 0; - ici.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; - result = vkCreateImage(device, &ici, allocatorCb, &m_image); - - if (VK_SUCCESS != result) - { - BX_TRACE("vkCreateImage failed %d: %s.", result, getName(result) ); - return result; - } + BX_ASSERT(m_pos < m_size, "Out of scratch buffer memory"); - VkMemoryRequirements mr; - vkGetImageMemoryRequirements(device, m_image, &mr); - - VkMemoryAllocateInfo ma; - ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - ma.pNext = NULL; - ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits - , VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT - ); - result = vkAllocateMemory(device - , &ma - , allocatorCb - , &m_memory - ); + const uint32_t offset = m_pos; - if (VK_SUCCESS != result) + if (_size > 0) { - BX_TRACE("vkAllocateMemory failed %d: %s.", result, getName(result) ); - destroy(); - return result; - } + bx::memCopy(&m_data[m_pos], _data, _size); - result = vkBindImageMemory(device, m_image, m_memory, 0); + const VkPhysicalDeviceLimits& deviceLimits = s_renderVK->m_deviceProperties.limits; + const uint32_t align = uint32_t(deviceLimits.minUniformBufferOffsetAlignment); + const uint32_t alignedSize = bx::strideAlign(_size, align); - if (VK_SUCCESS != result) - { - BX_TRACE("vkBindImageMemory failed %d: %s.", result, getName(result) ); - destroy(); - return result; + m_pos += alignedSize; } - VkImageViewCreateInfo ivci; - ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; - ivci.pNext = NULL; - ivci.flags = 0; - ivci.image = m_image; - ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; - ivci.format = _format; - ivci.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; - ivci.subresourceRange.aspectMask = 0 - | VK_IMAGE_ASPECT_DEPTH_BIT - | VK_IMAGE_ASPECT_STENCIL_BIT - ; - ivci.subresourceRange.baseMipLevel = 0; - ivci.subresourceRange.levelCount = 1; - ivci.subresourceRange.baseArrayLayer = 0; - ivci.subresourceRange.layerCount = 1; - result = vkCreateImageView(device, &ivci, allocatorCb, &m_imageView); - - if (VK_SUCCESS != result) - { - BX_TRACE("vkCreateImageView failed %d: %s.", result, getName(result) ); - destroy(); - return result; - } - - return VK_SUCCESS; + return offset; } - void ImageVK::destroy() + void ScratchBufferVK::flush() { - vkDestroy(m_imageView); - vkDestroy(m_image); - if (VK_NULL_HANDLE != m_memory) - { - vkFreeMemory(s_renderVK->m_device, m_memory, s_renderVK->m_allocatorCb); - m_memory = VK_NULL_HANDLE; - } + const VkPhysicalDeviceLimits& deviceLimits = s_renderVK->m_deviceProperties.limits; + VkDevice device = s_renderVK->m_device; + + const uint32_t align = uint32_t(deviceLimits.nonCoherentAtomSize); + const uint32_t size = bx::min(bx::strideAlign(m_pos, align), m_size); + + VkMappedMemoryRange range; + range.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; + range.pNext = NULL; + range.memory = m_deviceMem; + range.offset = 0; + range.size = size; + VK_CHECK(vkFlushMappedMemoryRanges(device, 1, &range) ); } - void BufferVK::create(uint32_t _size, void* _data, uint16_t _flags, bool _vertex, uint32_t _stride) + void BufferVK::create(VkCommandBuffer _commandBuffer, uint32_t _size, void* _data, uint16_t _flags, bool _vertex, uint32_t _stride) { BX_UNUSED(_stride); @@ -3350,93 +4704,92 @@ VK_DESTROY m_flags = _flags; m_dynamic = NULL == _data; + const bool storage = m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE; + const bool indirect = m_flags & BGFX_BUFFER_DRAW_INDIRECT; + VkBufferCreateInfo bci; bci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bci.pNext = NULL; bci.flags = 0; bci.size = _size; bci.usage = 0 - | (m_dynamic ? VK_BUFFER_USAGE_TRANSFER_DST_BIT : 0) - | (_vertex ? VK_BUFFER_USAGE_VERTEX_BUFFER_BIT : VK_BUFFER_USAGE_INDEX_BUFFER_BIT) + | (_vertex ? VK_BUFFER_USAGE_VERTEX_BUFFER_BIT : VK_BUFFER_USAGE_INDEX_BUFFER_BIT) + | (storage || indirect ? VK_BUFFER_USAGE_STORAGE_BUFFER_BIT : 0) + | (indirect ? VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT : 0) + | VK_BUFFER_USAGE_TRANSFER_DST_BIT ; bci.sharingMode = VK_SHARING_MODE_EXCLUSIVE; bci.queueFamilyIndexCount = 0; bci.pQueueFamilyIndices = NULL; - VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; - VkDevice device = s_renderVK->m_device; - VK_CHECK(vkCreateBuffer(device - , &bci - , allocatorCb - , &m_buffer - ) ); + const VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; + const VkDevice device = s_renderVK->m_device; + VK_CHECK(vkCreateBuffer(device, &bci, allocatorCb, &m_buffer) ); VkMemoryRequirements mr; - vkGetBufferMemoryRequirements(device - , m_buffer - , &mr - ); + vkGetBufferMemoryRequirements(device, m_buffer, &mr); - VkMemoryAllocateInfo ma; - ma.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; - ma.pNext = NULL; - ma.allocationSize = mr.size; - ma.memoryTypeIndex = s_renderVK->selectMemoryType(mr.memoryTypeBits - , VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT - ); - VK_CHECK(vkAllocateMemory(device - , &ma - , allocatorCb - , &m_deviceMem - ) ); + VK_CHECK(s_renderVK->allocateMemory(&mr, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &m_deviceMem) ); + + VK_CHECK(vkBindBufferMemory(device, m_buffer, m_deviceMem, 0) ); if (!m_dynamic) { - void* dst; - VK_CHECK(vkMapMemory(device, m_deviceMem, 0, ma.allocationSize, 0, &dst) ); - bx::memCopy(dst, _data, _size); - vkUnmapMemory(device, m_deviceMem); + update(_commandBuffer, 0, _size, _data); } - - VK_CHECK(vkBindBufferMemory(device, m_buffer, m_deviceMem, 0) ); } void BufferVK::update(VkCommandBuffer _commandBuffer, uint32_t _offset, uint32_t _size, void* _data, bool _discard) { - BX_UNUSED(_commandBuffer, _offset, _size, _data, _discard); + BX_UNUSED(_discard); + + VkBuffer stagingBuffer; + VkDeviceMemory stagingMem; + VK_CHECK(s_renderVK->createStagingBuffer(_size, &stagingBuffer, &stagingMem, _data) ); + + VkBufferCopy region; + region.srcOffset = 0; + region.dstOffset = _offset; + region.size = _size; + vkCmdCopyBuffer(_commandBuffer, stagingBuffer, m_buffer, 1, ®ion); + + setMemoryBarrier( + _commandBuffer + , VK_PIPELINE_STAGE_TRANSFER_BIT + , VK_PIPELINE_STAGE_TRANSFER_BIT + ); + + s_renderVK->release(stagingBuffer); + s_renderVK->release(stagingMem); } void BufferVK::destroy() { if (VK_NULL_HANDLE != m_buffer) { - VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; - VkDevice device = s_renderVK->m_device; + s_renderVK->release(m_buffer); + s_renderVK->release(m_deviceMem); - vkDestroy(m_buffer); - vkFreeMemory(device - , m_deviceMem - , allocatorCb - ); m_dynamic = false; } } - void VertexBufferVK::create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags) + void VertexBufferVK::create(VkCommandBuffer _commandBuffer, uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags) { - BufferVK::create(_size, _data, _flags, true); - m_decl = _declHandle; + BufferVK::create(_commandBuffer, _size, _data, _flags, true); + m_layoutHandle = _layoutHandle; } void ShaderVK::create(const Memory* _mem) { bx::MemoryReader reader(_mem->data, _mem->size); + bx::ErrorAssert err; + uint32_t magic; - bx::read(&reader, magic); + bx::read(&reader, magic, &err); - VkShaderStageFlagBits shaderStage; - BX_UNUSED(shaderStage); + VkShaderStageFlagBits shaderStage = VK_SHADER_STAGE_ALL; if (isShaderType(magic, 'C') ) { @@ -3454,7 +4807,7 @@ VK_DESTROY const bool fragment = isShaderType(magic, 'F'); uint32_t hashIn; - bx::read(&reader, hashIn); + bx::read(&reader, hashIn, &err); uint32_t hashOut; @@ -3464,84 +4817,195 @@ VK_DESTROY } else { - bx::read(&reader, hashOut); + bx::read(&reader, hashOut, &err); } uint16_t count; - bx::read(&reader, count); + bx::read(&reader, count, &err); m_numPredefined = 0; - m_numUniforms = count; + m_numUniforms = count; + m_numTextures = 0; + + m_oldBindingModel = isShaderVerLess(magic, 11); BX_TRACE("%s Shader consts %d" , getShaderTypeName(magic) , count ); - uint8_t fragmentBit = fragment ? BGFX_UNIFORM_FRAGMENTBIT : 0; + uint8_t fragmentBit = fragment ? kUniformFragmentBit : 0; + + for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++ii) + { + m_bindInfo[ii].uniformHandle = BGFX_INVALID_HANDLE; + m_bindInfo[ii].type = BindType::Count; + m_bindInfo[ii].binding = 0; + m_bindInfo[ii].samplerBinding = 0; + m_bindInfo[ii].index = UINT32_MAX; + } if (0 < count) { for (uint32_t ii = 0; ii < count; ++ii) { uint8_t nameSize = 0; - bx::read(&reader, nameSize); + bx::read(&reader, nameSize, &err); char name[256]; - bx::read(&reader, &name, nameSize); + bx::read(&reader, &name, nameSize, &err); name[nameSize] = '\0'; uint8_t type = 0; - bx::read(&reader, type); + bx::read(&reader, type, &err); uint8_t num; - bx::read(&reader, num); + bx::read(&reader, num, &err); uint16_t regIndex; - bx::read(&reader, regIndex); + bx::read(&reader, regIndex, &err); uint16_t regCount; - bx::read(&reader, regCount); + bx::read(&reader, regCount, &err); - const char* kind = "invalid"; + const bool hasTexData = !isShaderVerLess(magic, 8); + const bool hasTexFormat = !isShaderVerLess(magic, 10); + uint8_t texComponent = 0; + uint8_t texDimension = 0; + uint16_t texFormat = 0; - PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name); - if (PredefinedUniform::Count != predefined) + if (hasTexData) { - kind = "predefined"; - m_predefined[m_numPredefined].m_loc = regIndex; - m_predefined[m_numPredefined].m_count = regCount; - m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); - m_numPredefined++; + bx::read(&reader, texComponent, &err); + bx::read(&reader, texDimension, &err); } - else if (0 == (BGFX_UNIFORM_SAMPLERBIT & type) ) + + if (hasTexFormat) { - const UniformRegInfo* info = s_renderVK->m_uniformReg.find(name); - BX_CHECK(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); + bx::read(&reader, texFormat, &err); + } + + const char* kind = "invalid"; + + BX_UNUSED(num, texComponent, texFormat); - if (NULL != info) + auto textureDimensionToViewType = [](TextureDimension::Enum dimension) + { + switch (dimension) + { + case TextureDimension::Dimension1D: return VK_IMAGE_VIEW_TYPE_1D; + case TextureDimension::Dimension2D: return VK_IMAGE_VIEW_TYPE_2D; + case TextureDimension::Dimension2DArray: return VK_IMAGE_VIEW_TYPE_2D_ARRAY; + case TextureDimension::DimensionCube: return VK_IMAGE_VIEW_TYPE_CUBE; + case TextureDimension::DimensionCubeArray: return VK_IMAGE_VIEW_TYPE_CUBE_ARRAY; + case TextureDimension::Dimension3D: return VK_IMAGE_VIEW_TYPE_3D; + default: return VK_IMAGE_VIEW_TYPE_MAX_ENUM; + } + }; + + if (UINT16_MAX != regIndex) + { + PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name); + if (PredefinedUniform::Count != predefined) { - if (NULL == m_constantBuffer) + kind = "predefined"; + m_predefined[m_numPredefined].m_loc = regIndex; + m_predefined[m_numPredefined].m_count = regCount; + m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); + m_numPredefined++; + } + else if (UniformType::End == (~kUniformMask & type) ) + { + // regCount is used for descriptor type + const bool isBuffer = idToDescriptorType(regCount) == DescriptorType::StorageBuffer; + if (0 == regIndex) + { + continue; + } + + const uint8_t reverseShift = m_oldBindingModel + ? (fragment ? kSpirvOldFragmentShift : 0) + (isBuffer ? kSpirvOldBufferShift : kSpirvOldImageShift) + : kSpirvBindShift; + + const uint16_t stage = regIndex - reverseShift; // regIndex is used for buffer binding index + + m_bindInfo[stage].type = isBuffer ? BindType::Buffer : BindType::Image; + m_bindInfo[stage].uniformHandle = { 0 }; + m_bindInfo[stage].binding = regIndex; + + if (!isBuffer) { - m_constantBuffer = UniformBuffer::create(1024); + const VkImageViewType viewType = hasTexData + ? textureDimensionToViewType(idToTextureDimension(texDimension) ) + : VK_IMAGE_VIEW_TYPE_MAX_ENUM + ; + + if (VK_IMAGE_VIEW_TYPE_MAX_ENUM != viewType) + { + m_bindInfo[stage].index = m_numTextures; + m_textures[m_numTextures].type = viewType; + m_numTextures++; + } } - kind = "user"; - m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount); + kind = "storage"; + } + else if (UniformType::Sampler == (~kUniformMask & type) ) + { + const uint8_t reverseShift = m_oldBindingModel + ? (fragment ? kSpirvOldFragmentShift : 0) + kSpirvOldTextureShift + : kSpirvBindShift; + + const uint16_t stage = regIndex - reverseShift; // regIndex is used for image/sampler binding index + + const UniformRegInfo* info = s_renderVK->m_uniformReg.find(name); + BX_ASSERT(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); + + m_bindInfo[stage].uniformHandle = info->m_handle; + m_bindInfo[stage].type = BindType::Sampler; + m_bindInfo[stage].binding = regIndex; + m_bindInfo[stage].samplerBinding = regIndex + kSpirvSamplerShift; + + const VkImageViewType viewType = hasTexData + ? textureDimensionToViewType(idToTextureDimension(texDimension) ) + : VK_IMAGE_VIEW_TYPE_MAX_ENUM + ; + + if (VK_IMAGE_VIEW_TYPE_MAX_ENUM != viewType) + { + m_bindInfo[stage].index = m_numTextures; + m_textures[m_numTextures].type = viewType; + m_numTextures++; + } + + kind = "sampler"; + } + else + { + const UniformRegInfo* info = s_renderVK->m_uniformReg.find(name); + BX_ASSERT(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); + + if (NULL != info) + { + if (NULL == m_constantBuffer) + { + m_constantBuffer = UniformBuffer::create(1024); + } + + kind = "user"; + m_constantBuffer->writeUniformHandle( (UniformType::Enum)(type|fragmentBit), regIndex, info->m_handle, regCount); + } } - } - else - { - kind = "sampler"; } - BX_TRACE("\t%s: %s (%s), num %2d, r.index %3d, r.count %2d" + BX_TRACE("\t%s: %s (%s), r.index %3d, r.count %2d, r.texComponent %1d, r.texDimension %1d" , kind , name - , getUniformTypeName(UniformType::Enum(type&~BGFX_UNIFORM_MASK) ) - , num + , getUniformTypeName(UniformType::Enum(type&~kUniformMask) ) , regIndex , regCount + , texComponent + , texDimension ); BX_UNUSED(kind); } @@ -3553,23 +5017,23 @@ VK_DESTROY } uint32_t shaderSize; - bx::read(&reader, shaderSize); + bx::read(&reader, shaderSize, &err); const void* code = reader.getDataPtr(); bx::skip(&reader, shaderSize+1); m_code = alloc(shaderSize); - bx::memCopy(m_code->data - , code - , shaderSize - ); + bx::memCopy(m_code->data, code, shaderSize); VkShaderModuleCreateInfo smci; - smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; - smci.pNext = NULL; - smci.flags = 0; + smci.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; + smci.pNext = NULL; + smci.flags = 0; smci.codeSize = m_code->size; smci.pCode = (const uint32_t*)m_code->data; + +// disassemble(bx::getDebugOut(), m_code->data, m_code->size); + VK_CHECK(vkCreateShaderModule( s_renderVK->m_device , &smci @@ -3580,12 +5044,12 @@ VK_DESTROY bx::memSet(m_attrMask, 0, sizeof(m_attrMask) ); bx::memSet(m_attrRemap, 0, sizeof(m_attrRemap) ); - bx::read(&reader, m_numAttrs); + bx::read(&reader, m_numAttrs, &err); for (uint8_t ii = 0; ii < m_numAttrs; ++ii) { uint16_t id; - bx::read(&reader, id); + bx::read(&reader, id, &err); Attrib::Enum attr = idToAttrib(id); @@ -3606,7 +5070,69 @@ VK_DESTROY murmur.add(m_attrRemap, m_numAttrs); m_hash = murmur.end(); - bx::read(&reader, m_size); + bx::read(&reader, m_size, &err); + + // fill binding description with uniform information + uint16_t bidx = 0; + if (m_size > 0) + { + m_uniformBinding = fragment ? (m_oldBindingModel ? kSpirvOldFragmentBinding : kSpirvFragmentBinding) : 0; + + VkDescriptorSetLayoutBinding& binding = m_bindings[bidx]; + binding.stageFlags = shaderStage; + binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; + binding.binding = m_uniformBinding; + binding.pImmutableSamplers = NULL; + binding.descriptorCount = 1; + bidx++; + } + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_bindInfo); ++ii) + { + switch (m_bindInfo[ii].type) + { + case BindType::Buffer: + case BindType::Image: + { + VkDescriptorSetLayoutBinding& binding = m_bindings[bidx]; + binding.stageFlags = shaderStage; + binding.descriptorType = BindType::Buffer == m_bindInfo[ii].type + ? VK_DESCRIPTOR_TYPE_STORAGE_BUFFER + : VK_DESCRIPTOR_TYPE_STORAGE_IMAGE + ; + binding.binding = m_bindInfo[ii].binding; + binding.pImmutableSamplers = NULL; + binding.descriptorCount = 1; + bidx++; + } + break; + + case BindType::Sampler: + { + VkDescriptorSetLayoutBinding& textureBinding = m_bindings[bidx]; + textureBinding.stageFlags = shaderStage; + textureBinding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; + textureBinding.binding = m_bindInfo[ii].binding; + textureBinding.pImmutableSamplers = NULL; + textureBinding.descriptorCount = 1; + bidx++; + + VkDescriptorSetLayoutBinding& samplerBinding = m_bindings[bidx]; + samplerBinding.stageFlags = shaderStage; + samplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER; + samplerBinding.binding = m_bindInfo[ii].samplerBinding; + samplerBinding.pImmutableSamplers = NULL; + samplerBinding.descriptorCount = 1; + bidx++; + } + break; + + default: + break; + } + } + + m_numBindings = bidx; } void ShaderVK::destroy() @@ -3632,44 +5158,3043 @@ VK_DESTROY } } + void ProgramVK::create(const ShaderVK* _vsh, const ShaderVK* _fsh) + { + BX_ASSERT(NULL != _vsh->m_code, "Vertex shader doesn't exist."); + m_vsh = _vsh; + bx::memCopy( + &m_predefined[0] + , _vsh->m_predefined + , _vsh->m_numPredefined * sizeof(PredefinedUniform) + ); + m_numPredefined = _vsh->m_numPredefined; + + if (NULL != _fsh) + { + BX_ASSERT(NULL != _fsh->m_code, "Fragment shader doesn't exist."); + m_fsh = _fsh; + bx::memCopy( + &m_predefined[m_numPredefined] + , _fsh->m_predefined + , _fsh->m_numPredefined * sizeof(PredefinedUniform) + ); + m_numPredefined += _fsh->m_numPredefined; + } + + m_numTextures = 0; + + for (uint8_t stage = 0; stage < BX_COUNTOF(m_bindInfo); ++stage) + { + const ShaderVK* shader = NULL; + if (isValid(m_vsh->m_bindInfo[stage].uniformHandle) ) + { + shader = _vsh; + + BX_ASSERT(false + || NULL == m_fsh + || !isValid(m_fsh->m_bindInfo[stage].uniformHandle) + || !(m_vsh->m_oldBindingModel || m_fsh->m_oldBindingModel) + , "Shared vertex/fragment bindings require shader binary version >= 11." + ); + } + else if (NULL != m_fsh + && isValid(m_fsh->m_bindInfo[stage].uniformHandle) ) + { + shader = _fsh; + } + + if (NULL != shader) + { + m_bindInfo[stage] = shader->m_bindInfo[stage]; + uint32_t& index = m_bindInfo[stage].index; + if (UINT32_MAX != index) + { + m_textures[m_numTextures] = shader->m_textures[index]; + index = m_numTextures; + m_numTextures++; + } + } + } + + // create exact pipeline layout + m_descriptorSetLayout = VK_NULL_HANDLE; + + uint32_t numBindings = m_vsh->m_numBindings + (m_fsh ? m_fsh->m_numBindings : 0); + if (0 < numBindings) + { + // generate descriptor set layout hash + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(m_vsh->m_bindings, sizeof(VkDescriptorSetLayoutBinding) * m_vsh->m_numBindings); + + if (NULL != m_fsh) + { + murmur.add(m_fsh->m_bindings, sizeof(VkDescriptorSetLayoutBinding) * m_fsh->m_numBindings); + } + + uint32_t descriptorSetLayoutHash = murmur.end(); + + m_descriptorSetLayout = s_renderVK->m_descriptorSetLayoutCache.find(descriptorSetLayoutHash); + + if (VK_NULL_HANDLE == m_descriptorSetLayout) + { + VkDescriptorSetLayoutBinding bindings[2 * BX_COUNTOF(ShaderVK::m_bindings)]; + + bx::memCopy( + bindings + , m_vsh->m_bindings + , sizeof(VkDescriptorSetLayoutBinding) * m_vsh->m_numBindings + ); + + numBindings = m_vsh->m_numBindings; + + if (NULL != m_fsh) + { + for (uint16_t ii = 0; ii < m_fsh->m_numBindings; ii++) + { + const VkDescriptorSetLayoutBinding& fsBinding = m_fsh->m_bindings[ii]; + uint16_t vsBindingIdx = UINT16_MAX; + for (uint16_t jj = 0; jj < m_vsh->m_numBindings; jj++) + { + if (fsBinding.binding == bindings[jj].binding) + { + vsBindingIdx = jj; + break; + } + } + if (UINT16_MAX != vsBindingIdx) + { + BX_ASSERT( + bindings[vsBindingIdx].descriptorType == fsBinding.descriptorType + , "Mismatching descriptor types. Shaders compiled with different versions of shaderc?" + ); + bindings[vsBindingIdx].stageFlags |= fsBinding.stageFlags; + } + else + { + bindings[numBindings] = fsBinding; + numBindings++; + } + } + } + + VkDescriptorSetLayoutCreateInfo dslci; + dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; + dslci.pNext = NULL; + dslci.flags = 0; + dslci.bindingCount = numBindings; + dslci.pBindings = bindings; + + VK_CHECK(vkCreateDescriptorSetLayout( + s_renderVK->m_device + , &dslci + , s_renderVK->m_allocatorCb + , &m_descriptorSetLayout + ) ); + + s_renderVK->m_descriptorSetLayoutCache.add(descriptorSetLayoutHash, m_descriptorSetLayout); + } + } + + VkPipelineLayoutCreateInfo plci; + plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; + plci.pNext = NULL; + plci.flags = 0; + plci.pushConstantRangeCount = 0; + plci.pPushConstantRanges = NULL; + plci.setLayoutCount = (m_descriptorSetLayout == VK_NULL_HANDLE ? 0 : 1); + plci.pSetLayouts = &m_descriptorSetLayout; + + VK_CHECK(vkCreatePipelineLayout( + s_renderVK->m_device + , &plci + , s_renderVK->m_allocatorCb + , &m_pipelineLayout + ) ); + } + + void ProgramVK::destroy() + { + s_renderVK->release(m_pipelineLayout); + m_numPredefined = 0; + m_vsh = NULL; + m_fsh = NULL; + } + + VkResult TimerQueryVK::init() + { + VkResult result = VK_SUCCESS; + + const VkDevice device = s_renderVK->m_device; + const VkCommandBuffer commandBuffer = s_renderVK->m_commandBuffer; + + const uint32_t count = m_control.m_size * 2; + + VkQueryPoolCreateInfo qpci; + qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; + qpci.pNext = NULL; + qpci.flags = 0; + qpci.queryType = VK_QUERY_TYPE_TIMESTAMP; + qpci.queryCount = count; + qpci.pipelineStatistics = 0; + + result = vkCreateQueryPool(device, &qpci, s_renderVK->m_allocatorCb, &m_queryPool); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create timer query error: vkCreateQueryPool failed %d: %s.", result, getName(result) ); + return result; + } + + vkCmdResetQueryPool(commandBuffer, m_queryPool, 0, count); + + const uint32_t size = count * sizeof(uint64_t); + result = s_renderVK->createReadbackBuffer(size, &m_readback, &m_readbackMemory); + + if (VK_SUCCESS != result) + { + return result; + } + + result = vkMapMemory(device, m_readbackMemory, 0, VK_WHOLE_SIZE, 0, (void**)&m_queryResult); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create timer query error: vkMapMemory failed %d: %s.", result, getName(result) ); + return result; + } + + m_frequency = uint64_t(1000000000.0 / double(s_renderVK->m_deviceProperties.limits.timestampPeriod) ); + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_result); ++ii) + { + m_result[ii].reset(); + } + + m_control.reset(); + + return result; + } + + void TimerQueryVK::shutdown() + { + vkDestroy(m_queryPool); + vkDestroy(m_readback); + vkUnmapMemory(s_renderVK->m_device, m_readbackMemory); + vkDestroy(m_readbackMemory); + } + + uint32_t TimerQueryVK::begin(uint32_t _resultIdx, uint32_t _frameNum) + { + while (0 == m_control.reserve(1) ) + { + m_control.consume(1); + } + + Result& result = m_result[_resultIdx]; + ++result.m_pending; + + const uint32_t idx = m_control.m_current; + Query& query = m_query[idx]; + query.m_resultIdx = _resultIdx; + query.m_ready = false; + query.m_frameNum = _frameNum; + + const VkCommandBuffer commandBuffer = s_renderVK->m_commandBuffer; + const uint32_t offset = idx * 2 + 0; + + vkCmdResetQueryPool(commandBuffer, m_queryPool, offset, 2); + vkCmdWriteTimestamp(commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, m_queryPool, offset + 0); + + m_control.commit(1); + + return idx; + } + + void TimerQueryVK::end(uint32_t _idx) + { + Query& query = m_query[_idx]; + query.m_ready = true; + query.m_completed = s_renderVK->m_cmd.m_submitted + s_renderVK->m_cmd.m_numFramesInFlight; + + const VkCommandBuffer commandBuffer = s_renderVK->m_commandBuffer; + const uint32_t offset = _idx * 2 + 0; + + vkCmdWriteTimestamp(commandBuffer, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, m_queryPool, offset + 1); + + vkCmdCopyQueryPoolResults( + commandBuffer + , m_queryPool + , offset + , 2 + , m_readback + , offset * sizeof(uint64_t) + , sizeof(uint64_t) + , VK_QUERY_RESULT_WAIT_BIT | VK_QUERY_RESULT_64_BIT + ); + + setMemoryBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT); + + while (update() ) + { + } + } + + bool TimerQueryVK::update() + { + if (0 != m_control.available() ) + { + uint32_t idx = m_control.m_read; + Query& query = m_query[idx]; + + if (!query.m_ready) + { + return false; + } + + if (query.m_completed > s_renderVK->m_cmd.m_submitted) + { + return false; + } + + m_control.consume(1); + + Result& result = m_result[query.m_resultIdx]; + --result.m_pending; + result.m_frameNum = query.m_frameNum; + + uint32_t offset = idx * 2; + result.m_begin = m_queryResult[offset+0]; + result.m_end = m_queryResult[offset+1]; + + return true; + } + + return false; + } + + VkResult OcclusionQueryVK::init() + { + VkResult result = VK_SUCCESS; + + const VkDevice device = s_renderVK->m_device; + const VkCommandBuffer commandBuffer = s_renderVK->m_commandBuffer; + + const uint32_t count = BX_COUNTOF(m_handle); + + VkQueryPoolCreateInfo qpci; + qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO; + qpci.pNext = NULL; + qpci.flags = 0; + qpci.queryType = VK_QUERY_TYPE_OCCLUSION; + qpci.queryCount = count; + qpci.pipelineStatistics = 0; + + result = vkCreateQueryPool(device, &qpci, s_renderVK->m_allocatorCb, &m_queryPool); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create occlusion query error: vkCreateQueryPool failed %d: %s.", result, getName(result) ); + return result; + } + + vkCmdResetQueryPool(commandBuffer, m_queryPool, 0, count); + + const uint32_t size = count * sizeof(uint32_t); + result = s_renderVK->createReadbackBuffer(size, &m_readback, &m_readbackMemory); + + if (VK_SUCCESS != result) + { + return result; + } + + result = vkMapMemory(device, m_readbackMemory, 0, VK_WHOLE_SIZE, 0, (void**)&m_queryResult); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create occlusion query error: vkMapMemory failed %d: %s.", result, getName(result) ); + return result; + } + + m_control.reset(); + + return result; + } + + void OcclusionQueryVK::shutdown() + { + vkDestroy(m_queryPool); + vkDestroy(m_readback); + vkUnmapMemory(s_renderVK->m_device, m_readbackMemory); + vkDestroy(m_readbackMemory); + } + + void OcclusionQueryVK::begin(OcclusionQueryHandle _handle) + { + m_control.reserve(1); + + const VkCommandBuffer commandBuffer = s_renderVK->m_commandBuffer; + + m_handle[m_control.m_current] = _handle; + vkCmdBeginQuery(commandBuffer, m_queryPool, _handle.idx, 0); + } + + void OcclusionQueryVK::end() + { + const VkCommandBuffer commandBuffer = s_renderVK->m_commandBuffer; + + const OcclusionQueryHandle handle = m_handle[m_control.m_current]; + vkCmdEndQuery(commandBuffer, m_queryPool, handle.idx); + + m_control.commit(1); + } + + void OcclusionQueryVK::flush(Frame* _render) + { + if (0 < m_control.available() ) + { + VkCommandBuffer commandBuffer = s_renderVK->m_commandBuffer; + + const uint32_t size = m_control.m_size; + + // need to copy each result individually because VK_QUERY_RESULT_WAIT_BIT causes + // vkWaitForFences to hang indefinitely if we copy all results (including unavailable ones) + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + const OcclusionQueryHandle& handle = m_handle[(m_control.m_read + ii) % size]; + if (isValid(handle) ) + { + vkCmdCopyQueryPoolResults( + commandBuffer + , m_queryPool + , handle.idx + , 1 + , m_readback + , handle.idx * sizeof(uint32_t) + , sizeof(uint32_t) + , VK_QUERY_RESULT_WAIT_BIT + ); + } + } + + setMemoryBarrier(commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT); + s_renderVK->kick(true); + + commandBuffer = s_renderVK->m_commandBuffer; + + // resetting in the new command buffer prevents a false positive validation layer error + const uint32_t count = BX_COUNTOF(m_handle); + vkCmdResetQueryPool(commandBuffer, m_queryPool, 0, count); + + resolve(_render); + } + } + + void OcclusionQueryVK::resolve(Frame* _render) + { + while (0 != m_control.available() ) + { + OcclusionQueryHandle handle = m_handle[m_control.m_read]; + if (isValid(handle) ) + { + _render->m_occlusion[handle.idx] = m_queryResult[handle.idx]; + } + m_control.consume(1); + } + } + + void OcclusionQueryVK::invalidate(OcclusionQueryHandle _handle) + { + const uint32_t size = m_control.m_size; + + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + OcclusionQueryHandle& handle = m_handle[(m_control.m_read + ii) % size]; + if (handle.idx == _handle.idx) + { + handle.idx = bgfx::kInvalidHandle; + } + } + } + + void ReadbackVK::create(VkImage _image, uint32_t _width, uint32_t _height, TextureFormat::Enum _format) + { + m_image = _image; + m_width = _width; + m_height = _height; + m_format = _format; + } + + void ReadbackVK::destroy() + { + m_image = VK_NULL_HANDLE; + } + + uint32_t ReadbackVK::pitch(uint8_t _mip) const + { + uint32_t mipWidth = bx::uint32_max(1, m_width >> _mip); + uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_format) ); + return mipWidth * bpp / 8; + } + + void ReadbackVK::copyImageToBuffer(VkCommandBuffer _commandBuffer, VkBuffer _buffer, VkImageLayout _layout, VkImageAspectFlags _aspect, uint8_t _mip) const + { + uint32_t mipWidth = bx::uint32_max(1, m_width >> _mip); + uint32_t mipHeight = bx::uint32_max(1, m_height >> _mip); + + setImageMemoryBarrier( + _commandBuffer + , m_image + , _aspect + , _layout + , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , _mip + , 1 + , 0 + , 1 + ); + + VkBufferImageCopy bic; + bic.bufferOffset = 0; + bic.bufferRowLength = mipWidth; + bic.bufferImageHeight = mipHeight; + bic.imageSubresource.aspectMask = _aspect; + bic.imageSubresource.mipLevel = _mip; + bic.imageSubresource.baseArrayLayer = 0; + bic.imageSubresource.layerCount = 1; + bic.imageOffset = { 0, 0, 0 }; + bic.imageExtent = { mipWidth, mipHeight, 1 }; + + vkCmdCopyImageToBuffer( + _commandBuffer + , m_image + , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , _buffer + , 1 + , &bic + ); + + // Make changes to the buffer visible to the host + setMemoryBarrier( + _commandBuffer + , VK_PIPELINE_STAGE_TRANSFER_BIT + , VK_PIPELINE_STAGE_HOST_BIT + ); + + setImageMemoryBarrier( + _commandBuffer + , m_image + , _aspect + , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , _layout + , _mip + , 1 + , 0 + , 1 + ); + } + + void ReadbackVK::readback(VkDeviceMemory _memory, VkDeviceSize _offset, void* _data, uint8_t _mip) const + { + if (m_image == VK_NULL_HANDLE) + { + return; + } + + uint32_t mipHeight = bx::uint32_max(1, m_height >> _mip); + uint32_t rowPitch = pitch(_mip); + + uint8_t* src; + VK_CHECK(vkMapMemory(s_renderVK->m_device, _memory, 0, VK_WHOLE_SIZE, 0, (void**)&src) ); + src += _offset; + uint8_t* dst = (uint8_t*)_data; + + for (uint32_t yy = 0; yy < mipHeight; ++yy) + { + bx::memCopy(dst, src, rowPitch); + src += rowPitch; + dst += rowPitch; + } + + vkUnmapMemory(s_renderVK->m_device, _memory); + } + + VkResult TextureVK::create(VkCommandBuffer _commandBuffer, uint32_t _width, uint32_t _height, uint64_t _flags, VkFormat _format) + { + BX_ASSERT(0 != (_flags & BGFX_TEXTURE_RT_MASK), ""); + _flags |= BGFX_TEXTURE_RT_WRITE_ONLY; + + m_flags = _flags; + m_width = _width; + m_height = _height; + m_depth = 1; + m_numLayers = 1; + m_requestedFormat = uint8_t(bimg::TextureFormat::Count); + m_textureFormat = uint8_t(bimg::TextureFormat::Count); + m_format = _format; + m_components = { VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY }; + m_aspectMask = getAspectMask(m_format); + m_sampler = s_msaa[bx::uint32_satsub( (m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT, 1)]; + m_type = VK_IMAGE_VIEW_TYPE_2D; + m_numMips = 1; + m_numSides = 1; + + VkResult result = createImages(_commandBuffer); + + if (VK_SUCCESS == result) + { + const VkImageLayout layout = 0 != (m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) ) + ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL + : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL + ; + setImageMemoryBarrier(_commandBuffer, layout); + } + + return result; + } + + VkResult TextureVK::createImages(VkCommandBuffer _commandBuffer) + { + VkResult result = VK_SUCCESS; + + const VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; + const VkDevice device = s_renderVK->m_device; + + if (m_sampler.Count > 1) + { + BX_ASSERT(VK_IMAGE_VIEW_TYPE_3D != m_type, "Can't create multisample 3D image."); + BX_ASSERT(m_numMips <= 1, "Can't create multisample image with mip chain."); + } + + // create texture and allocate its device memory + VkImageCreateInfo ici; + ici.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; + ici.pNext = NULL; + ici.flags = 0 + | (VK_IMAGE_VIEW_TYPE_CUBE == m_type + ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT + : 0 + ) + | (VK_IMAGE_VIEW_TYPE_3D == m_type + ? VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT_KHR + : 0 + ) + ; + ici.pQueueFamilyIndices = NULL; + ici.queueFamilyIndexCount = 0; + ici.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; + ici.sharingMode = VK_SHARING_MODE_EXCLUSIVE; + ici.usage = 0 + | VK_IMAGE_USAGE_TRANSFER_SRC_BIT + | VK_IMAGE_USAGE_TRANSFER_DST_BIT + | VK_IMAGE_USAGE_SAMPLED_BIT + | (m_flags & BGFX_TEXTURE_RT_MASK + ? (m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) + ? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT + : VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) + : 0 + ) + | (m_flags & BGFX_TEXTURE_COMPUTE_WRITE ? VK_IMAGE_USAGE_STORAGE_BIT : 0) + ; + ici.format = m_format; + ici.samples = m_sampler.Sample; + ici.mipLevels = m_numMips; + ici.arrayLayers = m_numSides; + ici.extent.width = m_width; + ici.extent.height = m_height; + ici.extent.depth = m_depth; + ici.imageType = VK_IMAGE_VIEW_TYPE_3D == m_type + ? VK_IMAGE_TYPE_3D + : VK_IMAGE_TYPE_2D + ; + ici.tiling = VK_IMAGE_TILING_OPTIMAL; + + result = vkCreateImage(device, &ici, allocatorCb, &m_textureImage); + if (VK_SUCCESS != result) + { + BX_TRACE("Create texture image error: vkCreateImage failed %d: %s.", result, getName(result) ); + return result; + } + + VkMemoryRequirements imageMemReq; + vkGetImageMemoryRequirements(device, m_textureImage, &imageMemReq); + + result = s_renderVK->allocateMemory(&imageMemReq, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &m_textureDeviceMem); + if (VK_SUCCESS != result) + { + BX_TRACE("Create texture image error: allocateMemory failed %d: %s.", result, getName(result) ); + return result; + } + + result = vkBindImageMemory(device, m_textureImage, m_textureDeviceMem, 0); + if (VK_SUCCESS != result) + { + BX_TRACE("Create texture image error: vkBindImageMemory failed %d: %s.", result, getName(result) ); + return result; + } + + m_sampledLayout = m_flags & BGFX_TEXTURE_COMPUTE_WRITE + ? VK_IMAGE_LAYOUT_GENERAL + : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + ; + + const bool needResolve = true + && 1 < m_sampler.Count + && 0 != (ici.usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) + && 0 == (m_flags & BGFX_TEXTURE_MSAA_SAMPLE) + && 0 == (m_flags & BGFX_TEXTURE_RT_WRITE_ONLY) + ; + + if (needResolve) + { + VkImageCreateInfo ici_resolve = ici; + ici_resolve.samples = s_msaa[0].Sample; + ici_resolve.usage &= ~VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + ici_resolve.flags &= ~VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; + + result = vkCreateImage(device, &ici_resolve, allocatorCb, &m_singleMsaaImage); + if (VK_SUCCESS != result) + { + BX_TRACE("Create texture image error: vkCreateImage failed %d: %s.", result, getName(result) ); + return result; + } + + VkMemoryRequirements imageMemReq_resolve; + vkGetImageMemoryRequirements(device, m_singleMsaaImage, &imageMemReq_resolve); + + result = s_renderVK->allocateMemory(&imageMemReq_resolve, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, &m_singleMsaaDeviceMem); + if (VK_SUCCESS != result) + { + BX_TRACE("Create texture image error: allocateMemory failed %d: %s.", result, getName(result) ); + return result; + } + + result = vkBindImageMemory(device, m_singleMsaaImage, m_singleMsaaDeviceMem, 0); + if (VK_SUCCESS != result) + { + BX_TRACE("Create texture image error: vkBindImageMemory failed %d: %s.", result, getName(result) ); + return result; + } + + setImageMemoryBarrier(_commandBuffer, m_sampledLayout, true); + } + + return result; + } + + void* TextureVK::create(VkCommandBuffer _commandBuffer, const Memory* _mem, uint64_t _flags, uint8_t _skip) + { + bimg::ImageContainer imageContainer; + + if (bimg::imageParse(imageContainer, _mem->data, _mem->size) ) + { + const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(imageContainer.m_format); + const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips - 1); + + bimg::TextureInfo ti; + bimg::imageGetSize( + &ti + , uint16_t(imageContainer.m_width >> startLod) + , uint16_t(imageContainer.m_height >> startLod) + , uint16_t(imageContainer.m_depth >> startLod) + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + , imageContainer.m_numLayers + , imageContainer.m_format + ); + + ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips - startLod, ti.numMips); + + m_flags = _flags; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numLayers = ti.numLayers; + m_requestedFormat = uint8_t(imageContainer.m_format); + m_textureFormat = uint8_t(getViableTextureFormat(imageContainer) ); + m_format = bimg::isDepth(bimg::TextureFormat::Enum(m_textureFormat) ) + ? s_textureFormat[m_textureFormat].m_fmtDsv + : (m_flags & BGFX_TEXTURE_SRGB) ? s_textureFormat[m_textureFormat].m_fmtSrgb : s_textureFormat[m_textureFormat].m_fmt + ; + m_components = s_textureFormat[m_textureFormat].m_mapping; + + const bool convert = m_textureFormat != m_requestedFormat; + const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); + + m_aspectMask = getAspectMask(m_format); + m_sampler = s_msaa[bx::uint32_satsub( (m_flags & BGFX_TEXTURE_RT_MSAA_MASK) >> BGFX_TEXTURE_RT_MSAA_SHIFT, 1)]; + + if (imageContainer.m_cubeMap) + { + m_type = imageContainer.m_numLayers > 1 + ? VK_IMAGE_VIEW_TYPE_CUBE_ARRAY + : VK_IMAGE_VIEW_TYPE_CUBE + ; + } + else if (imageContainer.m_depth > 1) + { + m_type = VK_IMAGE_VIEW_TYPE_3D; + } + else if (imageContainer.m_numLayers > 1) + { + m_type = VK_IMAGE_VIEW_TYPE_2D_ARRAY; + } + else + { + m_type = VK_IMAGE_VIEW_TYPE_2D; + } + + m_numMips = ti.numMips; + m_numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * ti.numMips; + + uint32_t kk = 0; + + const bool compressed = bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat) ); + const bool swizzle = TextureFormat::BGRA8 == m_textureFormat && 0 != (m_flags & BGFX_TEXTURE_COMPUTE_WRITE); + + const bool writeOnly = 0 != (m_flags & BGFX_TEXTURE_RT_WRITE_ONLY); + const bool computeWrite = 0 != (m_flags & BGFX_TEXTURE_COMPUTE_WRITE); + const bool renderTarget = 0 != (m_flags & BGFX_TEXTURE_RT_MASK); + const bool blit = 0 != (m_flags & BGFX_TEXTURE_BLIT_DST); + + BX_UNUSED(swizzle, writeOnly, computeWrite, renderTarget, blit); + + BX_TRACE( + "Texture %3d: %s (requested: %s), %dx%dx%d%s RT[%c], BO[%c], CW[%c]%s." + , (int)(this - s_renderVK->m_textures) + , getName( (TextureFormat::Enum)m_textureFormat) + , getName( (TextureFormat::Enum)m_requestedFormat) + , ti.width + , ti.height + , ti.depth + , imageContainer.m_cubeMap ? "x6" : "" + , renderTarget ? 'x' : ' ' + , writeOnly ? 'x' : ' ' + , computeWrite ? 'x' : ' ' + , swizzle ? " (swizzle BGRA8 -> RGBA8)" : "" + ); + + VK_CHECK(createImages(_commandBuffer) ); + + // decode images + struct ImageInfo + { + uint8_t* data; + uint32_t width; + uint32_t height; + uint32_t depth; + uint32_t pitch; + uint32_t slice; + uint32_t size; + uint8_t mipLevel; + uint8_t layer; + }; + + ImageInfo* imageInfos = (ImageInfo*)BX_ALLOC(g_allocator, sizeof(ImageInfo) * numSrd); + bx::memSet(imageInfos, 0, sizeof(ImageInfo) * numSrd); + uint32_t alignment = 1; // tightly aligned buffer + + for (uint8_t side = 0; side < numSides; ++side) + { + for (uint8_t lod = 0; lod < ti.numMips; ++lod) + { + bimg::ImageMip mip; + + if (bimg::imageGetRawData(imageContainer, side, lod + startLod, _mem->data, _mem->size, mip) ) + { + if (convert) + { + const uint32_t pitch = bx::strideAlign(bx::max<uint32_t>(mip.m_width, 4) * bpp / 8, alignment); + const uint32_t slice = bx::strideAlign(bx::max<uint32_t>(mip.m_height, 4) * pitch, alignment); + const uint32_t size = slice * mip.m_depth; + + uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, size); + bimg::imageDecodeToBgra8( + g_allocator + , temp + , mip.m_data + , mip.m_width + , mip.m_height + , pitch + , mip.m_format + ); + + imageInfos[kk].data = temp; + imageInfos[kk].width = mip.m_width; + imageInfos[kk].height = mip.m_height; + imageInfos[kk].depth = mip.m_depth; + imageInfos[kk].pitch = pitch; + imageInfos[kk].slice = slice; + imageInfos[kk].size = size; + imageInfos[kk].mipLevel = lod; + imageInfos[kk].layer = side; + } + else if (compressed) + { + const uint32_t pitch = bx::strideAlign( (mip.m_width / blockInfo.blockWidth) * mip.m_blockSize, alignment); + const uint32_t slice = bx::strideAlign( (mip.m_height / blockInfo.blockHeight) * pitch, alignment); + const uint32_t size = slice * mip.m_depth; + + uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, size); + bimg::imageCopy( + temp + , mip.m_height / blockInfo.blockHeight + , (mip.m_width / blockInfo.blockWidth) * mip.m_blockSize + , mip.m_depth + , mip.m_data + , pitch + ); + + imageInfos[kk].data = temp; + imageInfos[kk].width = mip.m_width; + imageInfos[kk].height = mip.m_height; + imageInfos[kk].depth = mip.m_depth; + imageInfos[kk].pitch = pitch; + imageInfos[kk].slice = slice; + imageInfos[kk].size = size; + imageInfos[kk].mipLevel = lod; + imageInfos[kk].layer = side; + } + else + { + const uint32_t pitch = bx::strideAlign(mip.m_width * mip.m_bpp / 8, alignment); + const uint32_t slice = bx::strideAlign(mip.m_height * pitch, alignment); + const uint32_t size = slice * mip.m_depth; + + uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, size); + bimg::imageCopy( + temp + , mip.m_height + , mip.m_width * mip.m_bpp / 8 + , mip.m_depth + , mip.m_data + , pitch + ); + + imageInfos[kk].data = temp; + imageInfos[kk].width = mip.m_width; + imageInfos[kk].height = mip.m_height; + imageInfos[kk].depth = mip.m_depth; + imageInfos[kk].pitch = pitch; + imageInfos[kk].slice = slice; + imageInfos[kk].size = size; + imageInfos[kk].mipLevel = lod; + imageInfos[kk].layer = side; + } + } + ++kk; + } + } + + uint32_t totalMemSize = 0; + VkBufferImageCopy* bufferCopyInfo = (VkBufferImageCopy*)BX_ALLOC(g_allocator, sizeof(VkBufferImageCopy) * numSrd); + + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + const uint32_t idealWidth = bx::max<uint32_t>(1, m_width >> imageInfos[ii].mipLevel); + const uint32_t idealHeight = bx::max<uint32_t>(1, m_height >> imageInfos[ii].mipLevel); + bufferCopyInfo[ii].bufferOffset = totalMemSize; + bufferCopyInfo[ii].bufferRowLength = 0; // assume that image data are tightly aligned + bufferCopyInfo[ii].bufferImageHeight = 0; // assume that image data are tightly aligned + bufferCopyInfo[ii].imageSubresource.aspectMask = m_aspectMask; + bufferCopyInfo[ii].imageSubresource.mipLevel = imageInfos[ii].mipLevel; + bufferCopyInfo[ii].imageSubresource.baseArrayLayer = imageInfos[ii].layer; + bufferCopyInfo[ii].imageSubresource.layerCount = 1; + bufferCopyInfo[ii].imageOffset = { 0, 0, 0 }; + bufferCopyInfo[ii].imageExtent = { idealWidth, idealHeight, imageInfos[ii].depth }; + totalMemSize += imageInfos[ii].size; + } + + if (totalMemSize > 0) + { + const VkDevice device = s_renderVK->m_device; + + VkBuffer stagingBuffer; + VkDeviceMemory stagingDeviceMem; + VK_CHECK(s_renderVK->createStagingBuffer(totalMemSize, &stagingBuffer, &stagingDeviceMem) ); + + uint8_t* mappedMemory; + VK_CHECK(vkMapMemory( + device + , stagingDeviceMem + , 0 + , totalMemSize + , 0 + , (void**)&mappedMemory + ) ); + + // copy image to staging buffer + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + bx::memCopy(mappedMemory, imageInfos[ii].data, imageInfos[ii].size); + mappedMemory += imageInfos[ii].size; + } + + vkUnmapMemory(device, stagingDeviceMem); + + copyBufferToTexture(_commandBuffer, stagingBuffer, numSrd, bufferCopyInfo); + + s_renderVK->release(stagingBuffer); + s_renderVK->release(stagingDeviceMem); + } + else + { + setImageMemoryBarrier(_commandBuffer, m_sampledLayout); + } + + BX_FREE(g_allocator, bufferCopyInfo); + + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + BX_FREE(g_allocator, imageInfos[ii].data); + } + + BX_FREE(g_allocator, imageInfos); + + m_readback.create(m_textureImage, m_width, m_height, TextureFormat::Enum(m_textureFormat) ); + } + + return m_directAccessPtr; + } + void TextureVK::destroy() { + m_readback.destroy(); + + if (VK_NULL_HANDLE != m_textureImage) + { + s_renderVK->release(m_textureImage); + s_renderVK->release(m_textureDeviceMem); + } + + if (VK_NULL_HANDLE != m_singleMsaaImage) + { + s_renderVK->release(m_singleMsaaImage); + s_renderVK->release(m_singleMsaaDeviceMem); + } + + m_currentImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; + m_currentSingleMsaaImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; + } + + void TextureVK::update(VkCommandBuffer _commandBuffer, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) + { + const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); + uint32_t rectpitch = _rect.m_width * bpp / 8; + uint32_t slicepitch = rectpitch * _rect.m_height; + if (bimg::isCompressed(bimg::TextureFormat::Enum(m_textureFormat) ) ) + { + const bimg::ImageBlockInfo& blockInfo = bimg::getBlockInfo(bimg::TextureFormat::Enum(m_textureFormat) ); + rectpitch = (_rect.m_width / blockInfo.blockWidth ) * blockInfo.blockSize; + slicepitch = (_rect.m_height / blockInfo.blockHeight) * rectpitch; + } + const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; + const uint32_t size = UINT16_MAX == _pitch ? slicepitch * _depth: _rect.m_height * _pitch * _depth; + const bool convert = m_textureFormat != m_requestedFormat; + + VkBufferImageCopy region; + region.bufferOffset = 0; + region.bufferRowLength = (_pitch == UINT16_MAX ? 0 : _pitch * 8 / bpp); + region.bufferImageHeight = 0; + region.imageSubresource.aspectMask = m_aspectMask; + region.imageSubresource.mipLevel = _mip; + region.imageSubresource.baseArrayLayer = 0; + region.imageSubresource.layerCount = 1; + region.imageOffset = { _rect.m_x, _rect.m_y, 0 }; + region.imageExtent = { _rect.m_width, _rect.m_height, _depth }; + + uint8_t* data = _mem->data; + uint8_t* temp = NULL; + + if (convert) + { + temp = (uint8_t*)BX_ALLOC(g_allocator, slicepitch); + bimg::imageDecodeToBgra8(g_allocator, temp, data, _rect.m_width, _rect.m_height, srcpitch, bimg::TextureFormat::Enum(m_requestedFormat)); + data = temp; + + region.imageExtent = + { + bx::max(1u, m_width >> _mip), + bx::max(1u, m_height >> _mip), + _depth, + }; + } + + VkBuffer stagingBuffer = VK_NULL_HANDLE; + VkDeviceMemory stagingDeviceMem = VK_NULL_HANDLE; + VK_CHECK(s_renderVK->createStagingBuffer(size, &stagingBuffer, &stagingDeviceMem, data) ); + + if (VK_IMAGE_VIEW_TYPE_3D == m_type) + { + region.imageOffset.z = _z; + } + else if (VK_IMAGE_VIEW_TYPE_CUBE == m_type + || VK_IMAGE_VIEW_TYPE_CUBE_ARRAY == m_type) + { + region.imageSubresource.baseArrayLayer = _z * 6 + _side; + } + else + { + region.imageSubresource.baseArrayLayer = _z; + } + + copyBufferToTexture(_commandBuffer, stagingBuffer, 1, ®ion); + + s_renderVK->release(stagingBuffer); + s_renderVK->release(stagingDeviceMem); + + if (NULL != temp) + { + BX_FREE(g_allocator, temp); + } + } + + void TextureVK::resolve(VkCommandBuffer _commandBuffer, uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip) + { + const bool needResolve = VK_NULL_HANDLE != m_singleMsaaImage; + + const bool needMipGen = true + && !needResolve + && 0 != (m_flags & BGFX_TEXTURE_RT_MASK) + && 0 == (m_flags & BGFX_TEXTURE_RT_WRITE_ONLY) + && (_mip + 1) < m_numMips + && 0 != (_resolve & BGFX_RESOLVE_AUTO_GEN_MIPS); + + const VkImageLayout oldLayout = m_currentImageLayout; + const VkImageLayout oldSingleMsaaLayout = m_currentSingleMsaaImageLayout; + + if (needResolve) + { + setImageMemoryBarrier(_commandBuffer, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + setImageMemoryBarrier(_commandBuffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, true); + + VkImageResolve resolve; + resolve.srcOffset.x = 0; + resolve.srcOffset.y = 0; + resolve.srcOffset.z = 0; + resolve.dstOffset.x = 0; + resolve.dstOffset.y = 0; + resolve.dstOffset.z = 0; + resolve.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + resolve.srcSubresource.mipLevel = _mip; + resolve.srcSubresource.baseArrayLayer = _layer; + resolve.srcSubresource.layerCount = _numLayers; + resolve.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + resolve.dstSubresource.mipLevel = _mip; + resolve.dstSubresource.baseArrayLayer = _layer; + resolve.dstSubresource.layerCount = _numLayers; + resolve.extent.width = m_width; + resolve.extent.height = m_height; + resolve.extent.depth = 1; + + vkCmdResolveImage( + _commandBuffer + , m_textureImage + , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , m_singleMsaaImage + , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , 1 + , &resolve + ); + } + + if (needMipGen) + { + setImageMemoryBarrier(_commandBuffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + + int32_t mipWidth = bx::max<int32_t>(int32_t(m_width) >> _mip, 1); + int32_t mipHeight = bx::max<int32_t>(int32_t(m_height) >> _mip, 1); + + const VkFilter filter = bimg::isDepth(bimg::TextureFormat::Enum(m_textureFormat) ) + ? VK_FILTER_NEAREST + : VK_FILTER_LINEAR + ; + + VkImageBlit blit; + blit.srcOffsets[0] = { 0, 0, 0 }; + blit.srcOffsets[1] = { mipWidth, mipHeight, 1 }; + blit.srcSubresource.aspectMask = m_aspectMask; + blit.srcSubresource.mipLevel = 0; + blit.srcSubresource.baseArrayLayer = _layer; + blit.srcSubresource.layerCount = _numLayers; + blit.dstOffsets[0] = { 0, 0, 0 }; + blit.dstOffsets[1] = { mipWidth, mipHeight, 1 }; + blit.dstSubresource.aspectMask = m_aspectMask; + blit.dstSubresource.mipLevel = 0; + blit.dstSubresource.baseArrayLayer = _layer; + blit.dstSubresource.layerCount = _numLayers; + + for (uint32_t i = _mip + 1; i < m_numMips; i++) + { + blit.srcOffsets[1] = { mipWidth, mipHeight, 1 }; + blit.srcSubresource.mipLevel = i - 1; + + mipWidth = bx::uint32_max(mipWidth >> 1, 1); + mipHeight = bx::uint32_max(mipHeight >> 1, 1); + + blit.dstOffsets[1] = { mipWidth, mipHeight, 1 }; + blit.dstSubresource.mipLevel = i; + + vk::setImageMemoryBarrier( + _commandBuffer + , m_textureImage + , m_aspectMask + , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , blit.srcSubresource.mipLevel + , 1 + , _layer + , _numLayers + ); + + vkCmdBlitImage( + _commandBuffer + , m_textureImage + , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , m_textureImage + , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , 1 + , &blit + , filter + ); + } + + vk::setImageMemoryBarrier( + _commandBuffer + , m_textureImage + , m_aspectMask + , VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , _mip + , m_numMips - _mip - 1 + , _layer + , _numLayers + ); + } + + setImageMemoryBarrier(_commandBuffer, oldLayout); + setImageMemoryBarrier(_commandBuffer, oldSingleMsaaLayout, true); + } + + void TextureVK::copyBufferToTexture(VkCommandBuffer _commandBuffer, VkBuffer _stagingBuffer, uint32_t _bufferImageCopyCount, VkBufferImageCopy* _bufferImageCopy) + { + const VkImageLayout oldLayout = m_currentImageLayout == VK_IMAGE_LAYOUT_UNDEFINED + ? m_sampledLayout + : m_currentImageLayout + ; + + setImageMemoryBarrier(_commandBuffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + + vkCmdCopyBufferToImage( + _commandBuffer + , _stagingBuffer + , m_textureImage + , VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL + , _bufferImageCopyCount + , _bufferImageCopy + ); + + setImageMemoryBarrier(_commandBuffer, oldLayout); + } + + VkImageLayout TextureVK::setImageMemoryBarrier(VkCommandBuffer _commandBuffer, VkImageLayout _newImageLayout, bool _singleMsaaImage) + { + if (_singleMsaaImage && VK_NULL_HANDLE == m_singleMsaaImage) + { + return VK_IMAGE_LAYOUT_UNDEFINED; + } + + VkImageLayout& currentLayout = _singleMsaaImage + ? m_currentSingleMsaaImageLayout + : m_currentImageLayout + ; + + const VkImageLayout oldLayout = currentLayout; + + if (currentLayout == _newImageLayout) + { + return oldLayout; + } + + const VkImage image = _singleMsaaImage + ? m_singleMsaaImage + : m_textureImage + ; + + vk::setImageMemoryBarrier( + _commandBuffer + , image + , m_aspectMask + , currentLayout + , _newImageLayout + ); + + currentLayout = _newImageLayout; + return oldLayout; + } + + VkResult TextureVK::createView(uint32_t _layer, uint32_t _numLayers, uint32_t _mip, uint32_t _numMips, VkImageViewType _type, VkImageAspectFlags _aspectMask, bool _renderTarget, ::VkImageView* _view) const + { + VkResult result = VK_SUCCESS; + + if (VK_IMAGE_VIEW_TYPE_3D == m_type) + { + BX_ASSERT(false + || !_renderTarget + || !(m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) ) + , "3D image can't be a depth attachment" + ); + } + + if (VK_IMAGE_VIEW_TYPE_CUBE == _type + || VK_IMAGE_VIEW_TYPE_CUBE_ARRAY == _type) + { + BX_ASSERT(_numLayers % 6 == 0, ""); + BX_ASSERT( + VK_IMAGE_VIEW_TYPE_3D != m_type + , "3D image can't be aliased as a cube texture" + ); + } + + VkImageViewCreateInfo viewInfo; + viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + viewInfo.pNext = NULL; + viewInfo.flags = 0; + viewInfo.image = ((VK_NULL_HANDLE != m_singleMsaaImage) && !_renderTarget) + ? m_singleMsaaImage + : m_textureImage + ; + viewInfo.viewType = _type; + viewInfo.format = m_format; + viewInfo.components = m_components; + viewInfo.subresourceRange.aspectMask = m_aspectMask & _aspectMask; + viewInfo.subresourceRange.baseMipLevel = _mip; + viewInfo.subresourceRange.levelCount = _numMips; + viewInfo.subresourceRange.baseArrayLayer = _layer; + viewInfo.subresourceRange.layerCount = 1; + + if (VK_IMAGE_VIEW_TYPE_2D != _type + && VK_IMAGE_VIEW_TYPE_3D != _type) + { + viewInfo.subresourceRange.layerCount = VK_IMAGE_VIEW_TYPE_CUBE == _type + ? 6 + : _numLayers + ; + } + + VkImageView view = VK_NULL_HANDLE; + + result = vkCreateImageView( + s_renderVK->m_device + , &viewInfo + , s_renderVK->m_allocatorCb + , &view + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create texture view error: vkCreateImageView failed %d: %s.", result, getName(result) ); + return result; + } + + *_view = view; + + return result; + } + + VkImageAspectFlags TextureVK::getAspectMask(VkFormat _format) + { + switch (_format) + { + case VK_FORMAT_S8_UINT: + return VK_IMAGE_ASPECT_STENCIL_BIT; + break; + case VK_FORMAT_D16_UNORM: + case VK_FORMAT_X8_D24_UNORM_PACK32: + case VK_FORMAT_D32_SFLOAT: + return VK_IMAGE_ASPECT_DEPTH_BIT; + case VK_FORMAT_D16_UNORM_S8_UINT: + case VK_FORMAT_D24_UNORM_S8_UINT: + case VK_FORMAT_D32_SFLOAT_S8_UINT: + return VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT; + default: + return VK_IMAGE_ASPECT_COLOR_BIT; + } + } + + VkResult SwapChainVK::create(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution, TextureFormat::Enum _depthFormat) + { + struct ErrorState + { + enum Enum + { + Default, + SurfaceCreated, + SwapChainCreated, + AttachmentsCreated + }; + }; + + ErrorState::Enum errorState = ErrorState::Default; + + VkResult result = VK_SUCCESS; + + if (NULL == _nwh) + { + return result; + } + + m_nwh = _nwh; + m_resolution = _resolution; + m_depthFormat = TextureFormat::Count == _depthFormat ? TextureFormat::D24S8 : _depthFormat; + + m_queue = s_renderVK->m_globalQueue; + + result = createSurface(); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swap chain error: creating surface failed %d: %s.", result, getName(result) ); + goto error; + } + + errorState = ErrorState::SurfaceCreated; + + { + m_sci.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; + m_sci.pNext = NULL; + m_sci.flags = 0; + m_sci.imageArrayLayers = 1; + m_sci.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; + m_sci.queueFamilyIndexCount = 0; + m_sci.pQueueFamilyIndices = NULL; + m_sci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + m_sci.oldSwapchain = VK_NULL_HANDLE; + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImageView); ++ii) + { + m_backBufferColorImage[ii] = VK_NULL_HANDLE; + m_backBufferColorImageView[ii] = VK_NULL_HANDLE; + m_backBufferFrameBuffer[ii] = VK_NULL_HANDLE; + m_backBufferFence[ii] = VK_NULL_HANDLE; + m_presentDoneSemaphore[ii] = VK_NULL_HANDLE; + m_renderDoneSemaphore[ii] = VK_NULL_HANDLE; + } + + m_lastImageRenderedSemaphore = VK_NULL_HANDLE; + m_lastImageAcquiredSemaphore = VK_NULL_HANDLE; + + result = createSwapChain(); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swap chain error: creating swapchain and image views failed %d: %s", result, getName(result) ); + goto error; + } + } + + errorState = ErrorState::SwapChainCreated; + + { + result = createAttachments(_commandBuffer); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swap chain error: creating MSAA/depth attachments failed %d: %s.", result, getName(result) ); + goto error; + } + } + + errorState = ErrorState::AttachmentsCreated; + + { + result = createFrameBuffer(); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swap chain error: creating frame buffers failed %d: %s.", result, getName(result) ); + goto error; + } + } + + return VK_SUCCESS; + + error: + BX_TRACE("errorState %d", errorState); + switch (errorState) + { + case ErrorState::AttachmentsCreated: + releaseAttachments(); + BX_FALLTHROUGH; + + case ErrorState::SwapChainCreated: + releaseSwapChain(); + BX_FALLTHROUGH; + + case ErrorState::SurfaceCreated: + releaseSurface(); + BX_FALLTHROUGH; + + case ErrorState::Default: + break; + }; + + return VK_SUCCESS != result + ? result + : VK_ERROR_INITIALIZATION_FAILED + ; + } + + void SwapChainVK::destroy() + { + if (VK_NULL_HANDLE != m_swapchain) + { + releaseFrameBuffer(); + releaseAttachments(); + releaseSwapChain(); + releaseSurface(); + + // can't delay-delete the surface, since there can only be one swapchain per surface + // new framebuffer with the same window would get an error at swapchain creation + s_renderVK->kick(true); + } + + m_nwh = NULL; + } + + void SwapChainVK::update(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution) + { + const VkPhysicalDevice physicalDevice = s_renderVK->m_physicalDevice; + + m_lastImageRenderedSemaphore = VK_NULL_HANDLE; + m_lastImageAcquiredSemaphore = VK_NULL_HANDLE; + + const uint64_t recreateSurfaceMask = BGFX_RESET_HIDPI; + const uint64_t recreateSwapchainMask = BGFX_RESET_VSYNC | BGFX_RESET_SRGB_BACKBUFFER; + const uint64_t recreateAttachmentsMask = BGFX_RESET_MSAA_MASK; + + const bool recreateSurface = false + || m_needToRecreateSurface + || m_nwh != _nwh + || (m_resolution.reset & recreateSurfaceMask) != (_resolution.reset & recreateSurfaceMask) + ; + + const bool recreateSwapchain = false + || m_needToRecreateSwapchain + || m_resolution.format != _resolution.format + || m_resolution.width != _resolution.width + || m_resolution.height != _resolution.height + || (m_resolution.reset & recreateSwapchainMask) != (_resolution.reset & recreateSwapchainMask) + || recreateSurface + ; + + const bool recreateAttachments = false + || (m_resolution.reset & recreateAttachmentsMask) != (_resolution.reset & recreateAttachmentsMask) + || recreateSwapchain + ; + + m_nwh = _nwh; + m_resolution = _resolution; + + if (recreateAttachments) + { + releaseFrameBuffer(); + releaseAttachments(); + + if (recreateSwapchain) + { + releaseSwapChain(); + + if (recreateSurface) + { + m_sci.oldSwapchain = VK_NULL_HANDLE; + releaseSurface(); + s_renderVK->kick(true); + _commandBuffer = s_renderVK->m_commandBuffer; + + VkResult result = createSurface(); + if (VK_SUCCESS != result) + { + BX_TRACE("Surface lost."); + return; + } + } + + VkSurfaceCapabilitiesKHR surfaceCapabilities; + VK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, &surfaceCapabilities) ); + + const uint32_t width = bx::clamp<uint32_t>( + m_resolution.width + , surfaceCapabilities.minImageExtent.width + , surfaceCapabilities.maxImageExtent.width + ); + const uint32_t height = bx::clamp<uint32_t>( + m_resolution.height + , surfaceCapabilities.minImageExtent.height + , surfaceCapabilities.maxImageExtent.height + ); + + // swapchain can't have size 0 + // on some platforms this happens when minimized + if (width == 0 + || height == 0) + { + m_sci.oldSwapchain = VK_NULL_HANDLE; + s_renderVK->kick(true); + return; + } + + VK_CHECK(createSwapChain() ); + } + + VK_CHECK(createAttachments(_commandBuffer) ); + VK_CHECK(createFrameBuffer() ); + } + } + + VkResult SwapChainVK::createSurface() + { + VkResult result = VK_ERROR_INITIALIZATION_FAILED; + + const VkInstance instance = s_renderVK->m_instance; + const VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; + +#if BX_PLATFORM_WINDOWS + { + if (NULL != vkCreateWin32SurfaceKHR) + { + VkWin32SurfaceCreateInfoKHR sci; + sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; + sci.pNext = NULL; + sci.flags = 0; + sci.hinstance = (HINSTANCE)GetModuleHandle(NULL); + sci.hwnd = (HWND)m_nwh; + result = vkCreateWin32SurfaceKHR(instance, &sci, allocatorCb, &m_surface); + } + } +#elif BX_PLATFORM_ANDROID + { + if (NULL != vkCreateAndroidSurfaceKHR) + { + VkAndroidSurfaceCreateInfoKHR sci; + sci.sType = VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR; + sci.pNext = NULL; + sci.flags = 0; + sci.window = (ANativeWindow*)m_nwh; + result = vkCreateAndroidSurfaceKHR(instance, &sci, allocatorCb, &m_surface); + } + } +#elif BX_PLATFORM_LINUX + { + if (g_platformData.type == bgfx::NativeWindowHandleType::Wayland) + { + BGFX_FATAL(s_extension[Extension::KHR_wayland_surface].m_supported, Fatal::UnableToInitialize, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME " not supported"); + BGFX_FATAL(NULL != vkCreateWaylandSurfaceKHR, Fatal::UnableToInitialize, "vkCreateWaylandSurfaceKHR == 0"); + BX_TRACE("Attempting Wayland surface creation."); + VkWaylandSurfaceCreateInfoKHR sci; + sci.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; + sci.pNext = NULL; + sci.flags = 0; + sci.display = (wl_display*)g_platformData.ndt; + sci.surface = (wl_surface*)m_nwh; + result = vkCreateWaylandSurfaceKHR(instance, &sci, allocatorCb, &m_surface); + } + else + { + if (s_extension[Extension::KHR_xlib_surface].m_supported) + { + BGFX_FATAL(NULL != vkCreateXlibSurfaceKHR, Fatal::UnableToInitialize, "vkCreateXlibSurfaceKHR == 0") + BX_TRACE("Attempting Xlib surface creation."); + VkXlibSurfaceCreateInfoKHR sci; + sci.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; + sci.pNext = NULL; + sci.flags = 0; + sci.dpy = (Display*)g_platformData.ndt; + sci.window = (Window)m_nwh; + result = vkCreateXlibSurfaceKHR(instance, &sci, allocatorCb, &m_surface); + } + + if (VK_SUCCESS != result && s_extension[Extension::KHR_xcb_surface].m_supported) + { + void* xcbdll = bx::dlopen("libX11-xcb.so.1"); + + if (NULL != xcbdll + && NULL != vkCreateXcbSurfaceKHR) + { + typedef xcb_connection_t* (*PFN_XGETXCBCONNECTION)(Display*); + PFN_XGETXCBCONNECTION XGetXCBConnection = (PFN_XGETXCBCONNECTION)bx::dlsym(xcbdll, "XGetXCBConnection"); + + union { void* ptr; xcb_window_t window; } cast = { m_nwh }; + + BGFX_FATAL(NULL != vkCreateXcbSurfaceKHR, Fatal::UnableToInitialize, "vkCreateXcbSurfaceKHR == 0") + + VkXcbSurfaceCreateInfoKHR sci; + sci.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + sci.pNext = NULL; + sci.flags = 0; + sci.connection = XGetXCBConnection( (Display*)g_platformData.ndt); + sci.window = cast.window; + result = vkCreateXcbSurfaceKHR(instance, &sci, allocatorCb, &m_surface); + + bx::dlclose(xcbdll); + } + } + } + } + +#elif BX_PLATFORM_OSX + { + if (NULL != vkCreateMacOSSurfaceMVK) + { + NSWindow* window = (NSWindow*)(m_nwh); + NSView* contentView = (NSView*)window.contentView; + CAMetalLayer* layer = [CAMetalLayer layer]; + + if (m_resolution.reset & BGFX_RESET_HIDPI) + { + layer.contentsScale = [window backingScaleFactor]; + } + + [contentView setWantsLayer : YES]; + [contentView setLayer : layer]; + + VkMacOSSurfaceCreateInfoMVK sci; + sci.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; + sci.pNext = NULL; + sci.flags = 0; + sci.pView = (__bridge void*)layer; + result = vkCreateMacOSSurfaceMVK(instance, &sci, allocatorCb, &m_surface); + } + } +#else +# error "Figure out KHR surface..." +#endif // BX_PLATFORM_ + + m_needToRecreateSurface = false; + + if (VK_SUCCESS != result) + { + BX_TRACE("Create surface error: vkCreate[Platform]SurfaceKHR failed %d: %s.", result, getName(result) ); + return result; + } + + const VkPhysicalDevice physicalDevice = s_renderVK->m_physicalDevice; + const uint32_t queueFamily = s_renderVK->m_globalQueueFamily; + + VkBool32 surfaceSupported; + result = vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamily, m_surface, &surfaceSupported); + + if (VK_SUCCESS != result + || !surfaceSupported) + { + BX_TRACE("Create surface error: Presentation to the given surface not supported."); + return VK_ERROR_INITIALIZATION_FAILED; + } + + return result; + } + + void SwapChainVK::releaseSurface() + { + release(m_surface); + } + + VkResult SwapChainVK::createSwapChain() + { + VkResult result = VK_SUCCESS; + + const VkPhysicalDevice physicalDevice = s_renderVK->m_physicalDevice; + const VkDevice device = s_renderVK->m_device; + const VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; + + VkSurfaceCapabilitiesKHR surfaceCapabilities; + result = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, m_surface, &surfaceCapabilities); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: vkGetPhysicalDeviceSurfaceCapabilitiesKHR failed %d: %s.", result, getName(result) ); + return result; + } + + const uint32_t minSwapBufferCount = bx::max<uint32_t>(surfaceCapabilities.minImageCount, 2); + const uint32_t maxSwapBufferCount = surfaceCapabilities.maxImageCount == 0 + ? kMaxBackBuffers + : bx::min<uint32_t>(surfaceCapabilities.maxImageCount, kMaxBackBuffers) + ; + + if (minSwapBufferCount > maxSwapBufferCount) + { + BX_TRACE("Create swapchain error: Incompatible swapchain image count (min: %d, max: %d, MaxBackBuffers: %d)." + , minSwapBufferCount + , maxSwapBufferCount + , kMaxBackBuffers + ); + return VK_ERROR_INITIALIZATION_FAILED; + } + + const uint32_t swapBufferCount = bx::clamp<uint32_t>(m_resolution.numBackBuffers, minSwapBufferCount, maxSwapBufferCount); + + const VkColorSpaceKHR surfaceColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + + const bool srgb = !!(m_resolution.reset & BGFX_RESET_SRGB_BACKBUFFER); + m_colorFormat = findSurfaceFormat(m_resolution.format, surfaceColorSpace, srgb); + + if (TextureFormat::Count == m_colorFormat) + { + BX_TRACE("Create swapchain error: Unable to find surface format (srgb: %d).", srgb); + return VK_ERROR_INITIALIZATION_FAILED; + } + + const VkFormat surfaceFormat = srgb + ? s_textureFormat[m_colorFormat].m_fmtSrgb + : s_textureFormat[m_colorFormat].m_fmt + ; + + const uint32_t width = bx::clamp<uint32_t>( + m_resolution.width + , surfaceCapabilities.minImageExtent.width + , surfaceCapabilities.maxImageExtent.width + ); + const uint32_t height = bx::clamp<uint32_t>( + m_resolution.height + , surfaceCapabilities.minImageExtent.height + , surfaceCapabilities.maxImageExtent.height + ); + if (width != m_resolution.width || height != m_resolution.height) + { + BX_TRACE("Clamped swapchain resolution from %dx%d to %dx%d" + , m_resolution.width + , m_resolution.height + , width + , height + ); + } + + VkCompositeAlphaFlagBitsKHR compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + + if (surfaceCapabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) + { + compositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR; + } + else if (surfaceCapabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) + { + compositeAlpha = VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR; + } + else if (surfaceCapabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR) + { + compositeAlpha = VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR; + } + + const VkImageUsageFlags imageUsageMask = 0 + | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT + | VK_IMAGE_USAGE_TRANSFER_SRC_BIT + | VK_IMAGE_USAGE_TRANSFER_DST_BIT + ; + const VkImageUsageFlags imageUsage = surfaceCapabilities.supportedUsageFlags & imageUsageMask; + + m_supportsReadback = 0 != (imageUsage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT); + m_supportsManualResolve = 0 != (imageUsage & VK_IMAGE_USAGE_TRANSFER_DST_BIT); + + const bool vsync = !!(m_resolution.reset & BGFX_RESET_VSYNC); + uint32_t presentModeIdx = findPresentMode(vsync); + if (UINT32_MAX == presentModeIdx) + { + BX_TRACE("Create swapchain error: Unable to find present mode (vsync: %d).", vsync); + return VK_ERROR_INITIALIZATION_FAILED; + } + + m_sci.surface = m_surface; + m_sci.minImageCount = swapBufferCount; + m_sci.imageFormat = surfaceFormat; + m_sci.imageColorSpace = surfaceColorSpace; + m_sci.imageExtent.width = width; + m_sci.imageExtent.height = height; + m_sci.imageUsage = imageUsage; + m_sci.compositeAlpha = compositeAlpha; + m_sci.presentMode = s_presentMode[presentModeIdx].mode; + m_sci.clipped = VK_FALSE; + + result = vkCreateSwapchainKHR(device, &m_sci, allocatorCb, &m_swapchain); + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: vkCreateSwapchainKHR failed %d: %s.", result, getName(result) ); + return result; + } + + m_sci.oldSwapchain = m_swapchain; + + result = vkGetSwapchainImagesKHR(device, m_swapchain, &m_numSwapchainImages, NULL); + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: vkGetSwapchainImagesKHR failed %d: %s.", result, getName(result) ); + return result; + } + + if (m_numSwapchainImages < m_sci.minImageCount) + { + BX_TRACE("Create swapchain error: vkGetSwapchainImagesKHR: numSwapchainImages %d < minImageCount %d." + , m_numSwapchainImages + , m_sci.minImageCount + ); + return VK_ERROR_INITIALIZATION_FAILED; + } + + if (m_numSwapchainImages > BX_COUNTOF(m_backBufferColorImage) ) + { + BX_TRACE("Create swapchain error: vkGetSwapchainImagesKHR: numSwapchainImages %d > countof(m_backBufferColorImage) %d." + , m_numSwapchainImages + , BX_COUNTOF(m_backBufferColorImage) + ); + return VK_ERROR_INITIALIZATION_FAILED; + } + + result = vkGetSwapchainImagesKHR(device, m_swapchain, &m_numSwapchainImages, &m_backBufferColorImage[0]); + if (VK_SUCCESS != result && VK_INCOMPLETE != result) + { + BX_TRACE("Create swapchain error: vkGetSwapchainImagesKHR failed %d: %s." + , result + , getName(result) + ); + return result; + } + + VkImageViewCreateInfo ivci; + ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; + ivci.pNext = NULL; + ivci.flags = 0; + ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; + ivci.format = m_sci.imageFormat; + ivci.components.r = VK_COMPONENT_SWIZZLE_IDENTITY; + ivci.components.g = VK_COMPONENT_SWIZZLE_IDENTITY; + ivci.components.b = VK_COMPONENT_SWIZZLE_IDENTITY; + ivci.components.a = VK_COMPONENT_SWIZZLE_IDENTITY; + ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; + ivci.subresourceRange.baseMipLevel = 0; + ivci.subresourceRange.levelCount = 1; + ivci.subresourceRange.baseArrayLayer = 0; + ivci.subresourceRange.layerCount = 1; + + for (uint32_t ii = 0; ii < m_numSwapchainImages; ++ii) + { + ivci.image = m_backBufferColorImage[ii]; + + result = vkCreateImageView(device, &ivci, allocatorCb, &m_backBufferColorImageView[ii]); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: vkCreateImageView failed %d: %s.", result, getName(result) ); + return result; + } + + m_backBufferColorImageLayout[ii] = VK_IMAGE_LAYOUT_UNDEFINED; + } + + BX_TRACE("Succesfully created swapchain (%dx%d) with %d images.", width, height, m_numSwapChainImages); + + VkSemaphoreCreateInfo sci; + sci.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; + sci.pNext = NULL; + sci.flags = 0; + + for (uint32_t ii = 0; ii < m_numSwapchainImages; ++ii) + { + if (VK_SUCCESS != vkCreateSemaphore(device, &sci, allocatorCb, &m_presentDoneSemaphore[ii]) + || VK_SUCCESS != vkCreateSemaphore(device, &sci, allocatorCb, &m_renderDoneSemaphore[ii]) ) + { + BX_TRACE("Create swapchain error: vkCreateSemaphore failed %d: %s.", result, getName(result) ); + return result; + } + } + + m_backBufferColorIdx = 0; + m_currentSemaphore = 0; + + m_needPresent = false; + m_needToRecreateSwapchain = false; + + return result; + } + + void SwapChainVK::releaseSwapChain() + { + for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImageView); ++ii) + { + release(m_backBufferColorImageView[ii]); + + m_backBufferFence[ii] = VK_NULL_HANDLE; + + release(m_presentDoneSemaphore[ii]); + release(m_renderDoneSemaphore[ii]); + } + + release(m_swapchain); + } + + VkResult SwapChainVK::createAttachments(VkCommandBuffer _commandBuffer) + { + VkResult result = VK_SUCCESS; + + const uint32_t samplerIndex = (m_resolution.reset & BGFX_RESET_MSAA_MASK) >> BGFX_RESET_MSAA_SHIFT; + const uint64_t textureFlags = (uint64_t(samplerIndex + 1) << BGFX_TEXTURE_RT_MSAA_SHIFT) | BGFX_TEXTURE_RT | BGFX_TEXTURE_RT_WRITE_ONLY; + m_sampler = s_msaa[samplerIndex]; + + const uint16_t requiredCaps = m_sampler.Count > 1 + ? BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA + : BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER + ; + + // the spec guarantees that at least one of D24S8 and D32FS8 is supported + VkFormat depthFormat = VK_FORMAT_D32_SFLOAT_S8_UINT; + + if (g_caps.formats[m_depthFormat] & requiredCaps) + { + depthFormat = s_textureFormat[m_depthFormat].m_fmtDsv; + } + else if (g_caps.formats[TextureFormat::D24S8] & requiredCaps) + { + depthFormat = s_textureFormat[TextureFormat::D24S8].m_fmtDsv; + } + + result = m_backBufferDepthStencil.create( + _commandBuffer + , m_sci.imageExtent.width + , m_sci.imageExtent.height + , textureFlags + , depthFormat + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: creating depth stencil image failed %d: %s.", result, getName(result) ); + return result; + } + + result = m_backBufferDepthStencil.createView(0, 1, 0, 1, VK_IMAGE_VIEW_TYPE_2D, m_backBufferDepthStencil.m_aspectMask, true, &m_backBufferDepthStencilImageView); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: creating depth stencil image view failed %d: %s.", result, getName(result) ); + return result; + } + + if (m_sampler.Count > 1) + { + result = m_backBufferColorMsaa.create( + _commandBuffer + , m_sci.imageExtent.width + , m_sci.imageExtent.height + , textureFlags + , m_sci.imageFormat + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: creating MSAA color image failed %d: %s.", result, getName(result) ); + return result; + } + + result = m_backBufferColorMsaa.createView(0, 1, 0, 1, VK_IMAGE_VIEW_TYPE_2D, m_backBufferColorMsaa.m_aspectMask, true, &m_backBufferColorMsaaImageView); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create swapchain error: creating MSAA color image view failed %d: %s.", result, getName(result) ); + return result; + } + } + + return result; + } + + void SwapChainVK::releaseAttachments() + { + release(m_backBufferDepthStencilImageView); + release(m_backBufferColorMsaaImageView); + + m_backBufferDepthStencil.destroy(); + m_backBufferColorMsaa.destroy(); + } + + VkResult SwapChainVK::createFrameBuffer() + { + VkResult result = VK_SUCCESS; + + const VkDevice device = s_renderVK->m_device; + const VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; + + VkRenderPass renderPass; + result = s_renderVK->getRenderPass(*this, &renderPass); + + if (VK_SUCCESS != result) + { + return result; + } + + for (uint32_t ii = 0; ii < m_numSwapchainImages; ++ii) + { + uint32_t numAttachments = 2; + ::VkImageView attachments[3] = + { + m_sampler.Count > 1 + ? m_backBufferColorMsaaImageView + : m_backBufferColorImageView[ii], + m_backBufferDepthStencilImageView, + }; + + if (m_sampler.Count > 1 && !m_supportsManualResolve) + { + attachments[numAttachments++] = m_backBufferColorImageView[ii]; + } + + VkFramebufferCreateInfo fci; + fci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + fci.pNext = NULL; + fci.flags = 0; + fci.renderPass = renderPass; + fci.attachmentCount = numAttachments; + fci.pAttachments = attachments; + fci.width = m_sci.imageExtent.width; + fci.height = m_sci.imageExtent.height; + fci.layers = 1; + + result = vkCreateFramebuffer(device, &fci, allocatorCb, &m_backBufferFrameBuffer[ii]); + + if (VK_SUCCESS != result) + { + return result; + } + } + + return result; + } + + void SwapChainVK::releaseFrameBuffer() + { + for (uint32_t ii = 0; ii < BX_COUNTOF(m_backBufferColorImageView); ++ii) + { + release(m_backBufferFrameBuffer[ii]); + } + } + + uint32_t SwapChainVK::findPresentMode(bool _vsync) + { + VkResult result = VK_SUCCESS; + + const VkPhysicalDevice physicalDevice = s_renderVK->m_physicalDevice; + + uint32_t numPresentModes; + result = vkGetPhysicalDeviceSurfacePresentModesKHR( + physicalDevice + , m_surface + , &numPresentModes + , NULL + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("findPresentMode error: vkGetPhysicalDeviceSurfacePresentModesKHR failed %d: %s.", result, getName(result) ); + return UINT32_MAX; + } + + VkPresentModeKHR presentModes[16]; + numPresentModes = bx::min<uint32_t>(numPresentModes, BX_COUNTOF(presentModes) ); + result = vkGetPhysicalDeviceSurfacePresentModesKHR( + physicalDevice + , m_surface + , &numPresentModes + , presentModes + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("findPresentMode error: vkGetPhysicalDeviceSurfacePresentModesKHR failed %d: %s.", result, getName(result) ); + return UINT32_MAX; + } + + uint32_t idx = UINT32_MAX; + + for (uint32_t ii = 0; ii < BX_COUNTOF(s_presentMode) && UINT32_MAX == idx; ++ii) + { + for (uint32_t jj = 0; jj < numPresentModes; ++jj) + { + const PresentMode& pm = s_presentMode[ii]; + + if (pm.mode == presentModes[jj] + && pm.vsync == _vsync) + { + idx = ii; + break; + } + } + } + + if (UINT32_MAX == idx) + { + idx = 0; + BX_TRACE("Present mode not found! Defaulting to %s.", s_presentMode[idx].name); + } + + return idx; + } + + TextureFormat::Enum SwapChainVK::findSurfaceFormat(TextureFormat::Enum _format, VkColorSpaceKHR _colorSpace, bool _srgb) + { + VkResult result = VK_SUCCESS; + + TextureFormat::Enum selectedFormat = TextureFormat::Count; + + const VkPhysicalDevice physicalDevice = s_renderVK->m_physicalDevice; + + uint32_t numSurfaceFormats; + result = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &numSurfaceFormats, NULL); + + if (VK_SUCCESS != result) + { + BX_TRACE("findSurfaceFormat error: vkGetPhysicalDeviceSurfaceFormatsKHR failed %d: %s.", result, getName(result) ); + return selectedFormat; + } + + VkSurfaceFormatKHR* surfaceFormats = (VkSurfaceFormatKHR*)BX_ALLOC(g_allocator, numSurfaceFormats * sizeof(VkSurfaceFormatKHR) ); + result = vkGetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, m_surface, &numSurfaceFormats, surfaceFormats); + + if (VK_SUCCESS != result) + { + BX_TRACE("findSurfaceFormat error: vkGetPhysicalDeviceSurfaceFormatsKHR failed %d: %s.", result, getName(result) ); + BX_FREE(g_allocator, surfaceFormats); + return selectedFormat; + } + + const TextureFormat::Enum requestedFormats[] = + { + _format, + TextureFormat::BGRA8, + TextureFormat::RGBA8, + }; + + for (uint32_t ii = 0; ii < BX_COUNTOF(requestedFormats) && TextureFormat::Count == selectedFormat; ii++) + { + const TextureFormat::Enum requested = requestedFormats[ii]; + const VkFormat requestedVkFormat = _srgb + ? s_textureFormat[requested].m_fmtSrgb + : s_textureFormat[requested].m_fmt + ; + + for (uint32_t jj = 0; jj < numSurfaceFormats; jj++) + { + if (_colorSpace == surfaceFormats[jj].colorSpace + && requestedVkFormat == surfaceFormats[jj].format) + { + selectedFormat = requested; + if (0 != ii + && s_renderVK->m_swapchainFormats[_format] != selectedFormat) + { + s_renderVK->m_swapchainFormats[_format] = selectedFormat; + BX_TRACE( + "findSurfaceFormat: Surface format %s not found! Defaulting to %s." + , bimg::getName(bimg::TextureFormat::Enum(_format) ) + , bimg::getName(bimg::TextureFormat::Enum(selectedFormat) ) + ); + } + break; + } + } + } + + BX_FREE(g_allocator, surfaceFormats); + + if (TextureFormat::Count == selectedFormat) + { + BX_TRACE("findSurfaceFormat error: No supported surface format found."); + } + + return selectedFormat; + } + + bool SwapChainVK::acquire(VkCommandBuffer _commandBuffer) + { + if (VK_NULL_HANDLE == m_swapchain + || m_needToRecreateSwapchain) + { + return false; + } + + if (!m_needPresent) + { + const VkDevice device = s_renderVK->m_device; + + m_lastImageAcquiredSemaphore = m_presentDoneSemaphore[m_currentSemaphore]; + m_lastImageRenderedSemaphore = m_renderDoneSemaphore[m_currentSemaphore]; + m_currentSemaphore = (m_currentSemaphore + 1) % m_numSwapchainImages; + + VkResult result = vkAcquireNextImageKHR( + device + , m_swapchain + , UINT64_MAX + , m_lastImageAcquiredSemaphore + , VK_NULL_HANDLE + , &m_backBufferColorIdx + ); + + if (result != VK_SUCCESS) + { + BX_TRACE("vkAcquireNextImageKHR(...): result = %s", getName(result)); + } + + switch (result) + { + case VK_SUCCESS: + break; + + case VK_ERROR_SURFACE_LOST_KHR: + m_needToRecreateSurface = true; + m_needToRecreateSwapchain = true; + return false; + + case VK_ERROR_OUT_OF_DATE_KHR: + case VK_SUBOPTIMAL_KHR: + m_needToRecreateSwapchain = true; + return false; + + default: + BX_ASSERT(VK_SUCCESS == result, "vkAcquireNextImageKHR(...); VK error 0x%x: %s", result, getName(result) ); + return false; + } + + if (VK_NULL_HANDLE != m_backBufferFence[m_backBufferColorIdx]) + { + VK_CHECK(vkWaitForFences( + device + , 1 + , &m_backBufferFence[m_backBufferColorIdx] + , VK_TRUE + , UINT64_MAX + ) ); + } + + transitionImage(_commandBuffer); + + m_needPresent = true; + } + + return true; + } + + void SwapChainVK::present() + { + if (VK_NULL_HANDLE != m_swapchain + && m_needPresent) + { + VkPresentInfoKHR pi; + pi.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; + pi.pNext = NULL; + pi.waitSemaphoreCount = 1; + pi.pWaitSemaphores = &m_lastImageRenderedSemaphore; + pi.swapchainCount = 1; + pi.pSwapchains = &m_swapchain; + pi.pImageIndices = &m_backBufferColorIdx; + pi.pResults = NULL; + VkResult result = vkQueuePresentKHR(m_queue, &pi); + + if (result != VK_SUCCESS) + { + BX_TRACE("vkQueuePresentKHR(...): result = %s", getName(result)); + } + + switch (result) + { + case VK_ERROR_SURFACE_LOST_KHR: + m_needToRecreateSurface = true; + m_needToRecreateSwapchain = true; + break; + + case VK_ERROR_OUT_OF_DATE_KHR: + case VK_SUBOPTIMAL_KHR: + m_needToRecreateSwapchain = true; + break; + + default: + BX_ASSERT(VK_SUCCESS == result, "vkQueuePresentKHR(...); VK error 0x%x: %s", result, getName(result) ); + break; + } + + m_needPresent = false; + m_lastImageRenderedSemaphore = VK_NULL_HANDLE; + } + } + + void SwapChainVK::transitionImage(VkCommandBuffer _commandBuffer) + { + VkImageLayout& layout = m_backBufferColorImageLayout[m_backBufferColorIdx]; + + const bool toPresent = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL == layout; + + const VkImageLayout newLayout = toPresent + ? VK_IMAGE_LAYOUT_PRESENT_SRC_KHR + : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL + ; + + layout = toPresent ? layout : VK_IMAGE_LAYOUT_UNDEFINED; + + setImageMemoryBarrier( + _commandBuffer + , m_backBufferColorImage[m_backBufferColorIdx] + , VK_IMAGE_ASPECT_COLOR_BIT + , layout + , newLayout + ); + + layout = newLayout; + } + + void FrameBufferVK::create(uint8_t _num, const Attachment* _attachment) + { + m_numTh = _num; + bx::memCopy(m_attachment, _attachment, sizeof(Attachment) * _num); + + postReset(); + } + + VkResult FrameBufferVK::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) + { + VkResult result = VK_SUCCESS; + + Resolution resolution = s_renderVK->m_resolution; + resolution.format = TextureFormat::Count == _format ? resolution.format : _format; + resolution.width = _width; + resolution.height = _height; + if (_denseIdx != UINT16_MAX) + { + resolution.reset &= ~BGFX_RESET_MSAA_MASK; + } + + result = m_swapChain.create(s_renderVK->m_commandBuffer, _nwh, resolution, _depthFormat); + + if (VK_SUCCESS != result) + { + return result; + } + + result = s_renderVK->getRenderPass(m_swapChain, &m_renderPass); + + if (VK_SUCCESS != result) + { + return result; + } + + m_denseIdx = _denseIdx; + m_nwh = _nwh; + m_width = _width; + m_height = _height; + m_sampler = m_swapChain.m_sampler; + + return result; + } + + void FrameBufferVK::preReset() + { + if (VK_NULL_HANDLE != m_framebuffer) + { + s_renderVK->release(m_framebuffer); + + for (uint8_t ii = 0; ii < m_numTh; ++ii) + { + s_renderVK->release(m_textureImageViews[ii]); + } + } + } + + void FrameBufferVK::postReset() + { + if (m_numTh > 0) + { + const VkDevice device = s_renderVK->m_device; + const VkAllocationCallbacks* allocatorCb = s_renderVK->m_allocatorCb; + + VK_CHECK(s_renderVK->getRenderPass(m_numTh, m_attachment, &m_renderPass) ); + + m_depth = BGFX_INVALID_HANDLE; + m_num = 0; + + for (uint8_t ii = 0; ii < m_numTh; ++ii) + { + const Attachment& at = m_attachment[ii]; + const TextureVK& texture = s_renderVK->m_textures[at.handle.idx]; + VK_CHECK(texture.createView( + at.layer + , at.numLayers + , at.mip + , 1 + , at.numLayers > 1 ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D + , texture.m_aspectMask + , true + , &m_textureImageViews[ii] + ) ); + + if (texture.m_aspectMask & VK_IMAGE_ASPECT_COLOR_BIT) + { + m_texture[m_num] = at.handle; + m_num++; + } + else if (texture.m_aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) ) + { + m_depth = at.handle; + } + } + + const TextureVK& firstTexture = s_renderVK->m_textures[m_attachment[0].handle.idx]; + m_width = bx::uint32_max(firstTexture.m_width >> m_attachment[0].mip, 1); + m_height = bx::uint32_max(firstTexture.m_height >> m_attachment[0].mip, 1); + m_sampler = firstTexture.m_sampler; + + VkFramebufferCreateInfo fci; + fci.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; + fci.pNext = NULL; + fci.flags = 0; + fci.renderPass = m_renderPass; + fci.attachmentCount = m_numTh; + fci.pAttachments = &m_textureImageViews[0]; + fci.width = m_width; + fci.height = m_height; + fci.layers = m_attachment[0].numLayers; + + VK_CHECK(vkCreateFramebuffer(device, &fci, allocatorCb, &m_framebuffer) ); + + m_currentFramebuffer = m_framebuffer; + } + } + + void FrameBufferVK::update(VkCommandBuffer _commandBuffer, const Resolution& _resolution) + { + m_swapChain.update(_commandBuffer, m_nwh, _resolution); + VK_CHECK(s_renderVK->getRenderPass(m_swapChain, &m_renderPass) ); + // Don't believe the passed Resolution, as the Vulkan driver might have + // specified another resolution, which we had to obey. + m_width = m_swapChain.m_sci.imageExtent.width; + m_height = m_swapChain.m_sci.imageExtent.height; + m_sampler = m_swapChain.m_sampler; } - void FrameBufferVK::destroy() + void FrameBufferVK::resolve() { + if (!m_needResolve) + { + return; + } + + if (NULL == m_nwh) + { + for (uint32_t ii = 0; ii < m_numTh; ++ii) + { + const Attachment& at = m_attachment[ii]; + + if (isValid(at.handle) ) + { + TextureVK& texture = s_renderVK->m_textures[at.handle.idx]; + texture.resolve(s_renderVK->m_commandBuffer, at.resolve, at.layer, at.numLayers, at.mip); + } + } + } + else if (isRenderable() + && m_sampler.Count > 1 + && m_swapChain.m_supportsManualResolve) + { + m_swapChain.m_backBufferColorMsaa.m_singleMsaaImage = m_swapChain.m_backBufferColorImage[m_swapChain.m_backBufferColorIdx]; + m_swapChain.m_backBufferColorMsaa.m_currentSingleMsaaImageLayout = m_swapChain.m_backBufferColorImageLayout[m_swapChain.m_backBufferColorIdx]; + + m_swapChain.m_backBufferColorMsaa.resolve(s_renderVK->m_commandBuffer, 0, 0, 1, 0); + + m_swapChain.m_backBufferColorMsaa.m_singleMsaaImage = VK_NULL_HANDLE; + m_swapChain.m_backBufferColorMsaa.m_currentSingleMsaaImageLayout = VK_IMAGE_LAYOUT_UNDEFINED; + } + + m_needResolve = false; + } + + uint16_t FrameBufferVK::destroy() + { + preReset(); + + if (NULL != m_nwh) + { + m_swapChain.destroy(); + m_nwh = NULL; + m_needPresent = false; + } + + m_numTh = 0; + m_num = 0; + m_depth = BGFX_INVALID_HANDLE; + + m_needResolve = false; + + uint16_t denseIdx = m_denseIdx; + m_denseIdx = UINT16_MAX; + return denseIdx; + } + + bool FrameBufferVK::acquire(VkCommandBuffer _commandBuffer) + { + bool acquired = true; + + if (NULL != m_nwh) + { + acquired = m_swapChain.acquire(_commandBuffer); + m_needPresent = m_swapChain.m_needPresent; + m_currentFramebuffer = m_swapChain.m_backBufferFrameBuffer[m_swapChain.m_backBufferColorIdx]; + } + + m_needResolve = true; + + return acquired; + } + + void FrameBufferVK::present() + { + m_swapChain.present(); + m_needPresent = false; + } + + bool FrameBufferVK::isRenderable() const + { + return false + || (NULL == m_nwh) + || m_swapChain.m_needPresent + ; + } + + VkResult CommandQueueVK::init(uint32_t _queueFamily, VkQueue _queue, uint32_t _numFramesInFlight) + { + m_queueFamily = _queueFamily; + m_queue = _queue; + m_numFramesInFlight = bx::clamp<uint32_t>(_numFramesInFlight, 1, BGFX_CONFIG_MAX_FRAME_LATENCY); + m_activeCommandBuffer = VK_NULL_HANDLE; + + return reset(); + } + + VkResult CommandQueueVK::reset() + { + shutdown(); + + m_currentFrameInFlight = 0; + m_consumeIndex = 0; + + m_numSignalSemaphores = 0; + m_numWaitSemaphores = 0; + + m_activeCommandBuffer = VK_NULL_HANDLE; + m_currentFence = VK_NULL_HANDLE; + m_completedFence = VK_NULL_HANDLE; + + m_submitted = 0; + + VkCommandPoolCreateInfo cpci; + cpci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; + cpci.pNext = NULL; + cpci.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT; + cpci.queueFamilyIndex = m_queueFamily; + + VkCommandBufferAllocateInfo cbai; + cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; + cbai.pNext = NULL; + cbai.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; + cbai.commandBufferCount = 1; + + VkFenceCreateInfo fci; + fci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; + fci.pNext = NULL; + fci.flags = VK_FENCE_CREATE_SIGNALED_BIT; + + VkResult result = VK_SUCCESS; + + for (uint32_t ii = 0; ii < m_numFramesInFlight; ++ii) + { + result = vkCreateCommandPool( + s_renderVK->m_device + , &cpci + , s_renderVK->m_allocatorCb + , &m_commandList[ii].m_commandPool + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create command queue error: vkCreateCommandPool failed %d: %s.", result, getName(result) ); + return result; + } + + cbai.commandPool = m_commandList[ii].m_commandPool; + + result = vkAllocateCommandBuffers( + s_renderVK->m_device + , &cbai + , &m_commandList[ii].m_commandBuffer + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create command queue error: vkAllocateCommandBuffers failed %d: %s.", result, getName(result) ); + return result; + } + + result = vkCreateFence( + s_renderVK->m_device + , &fci + , s_renderVK->m_allocatorCb + , &m_commandList[ii].m_fence + ); + + if (VK_SUCCESS != result) + { + BX_TRACE("Create command queue error: vkCreateFence failed %d: %s.", result, getName(result) ); + return result; + } + } + + return result; + } + + void CommandQueueVK::shutdown() + { + kick(true); + finish(true); + + for (uint32_t ii = 0; ii < m_numFramesInFlight; ++ii) + { + vkDestroy(m_commandList[ii].m_fence); + m_commandList[ii].m_commandBuffer = VK_NULL_HANDLE; + vkDestroy(m_commandList[ii].m_commandPool); + } + } + + VkResult CommandQueueVK::alloc(VkCommandBuffer* _commandBuffer) + { + VkResult result = VK_SUCCESS; + + if (m_activeCommandBuffer == VK_NULL_HANDLE) + { + const VkDevice device = s_renderVK->m_device; + CommandList& commandList = m_commandList[m_currentFrameInFlight]; + + result = vkWaitForFences(device, 1, &commandList.m_fence, VK_TRUE, UINT64_MAX); + + if (VK_SUCCESS != result) + { + BX_TRACE("Allocate command buffer error: vkWaitForFences failed %d: %s.", result, getName(result) ); + return result; + } + + result = vkResetCommandPool(device, commandList.m_commandPool, 0); + + if (VK_SUCCESS != result) + { + BX_TRACE("Allocate command buffer error: vkResetCommandPool failed %d: %s.", result, getName(result) ); + return result; + } + + VkCommandBufferBeginInfo cbi; + cbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; + cbi.pNext = NULL; + cbi.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; + cbi.pInheritanceInfo = NULL; + + result = vkBeginCommandBuffer(commandList.m_commandBuffer, &cbi); + + if (VK_SUCCESS != result) + { + BX_TRACE("Allocate command buffer error: vkBeginCommandBuffer failed %d: %s.", result, getName(result) ); + return result; + } + + m_activeCommandBuffer = commandList.m_commandBuffer; + m_currentFence = commandList.m_fence; + } + + if (NULL != _commandBuffer) + { + *_commandBuffer = m_activeCommandBuffer; + } + + return result; + } + + void CommandQueueVK::addWaitSemaphore(VkSemaphore _semaphore, VkPipelineStageFlags _waitFlags) + { + BX_ASSERT(m_numWaitSemaphores < BX_COUNTOF(m_waitSemaphores), "Too many wait semaphores."); + + m_waitSemaphores[m_numWaitSemaphores] = _semaphore; + m_waitSemaphoreStages[m_numWaitSemaphores] = _waitFlags; + m_numWaitSemaphores++; + } + + void CommandQueueVK::addSignalSemaphore(VkSemaphore _semaphore) + { + BX_ASSERT(m_numSignalSemaphores < BX_COUNTOF(m_signalSemaphores), "Too many signal semaphores."); + + m_signalSemaphores[m_numSignalSemaphores] = _semaphore; + m_numSignalSemaphores++; + } + + void CommandQueueVK::kick(bool _wait) + { + if (VK_NULL_HANDLE != m_activeCommandBuffer) + { + const VkDevice device = s_renderVK->m_device; + + setMemoryBarrier( + m_activeCommandBuffer + , VK_PIPELINE_STAGE_ALL_COMMANDS_BIT + , VK_PIPELINE_STAGE_ALL_COMMANDS_BIT + ); + + VK_CHECK(vkEndCommandBuffer(m_activeCommandBuffer) ); + + m_completedFence = m_currentFence; + m_currentFence = VK_NULL_HANDLE; + + VK_CHECK(vkResetFences(device, 1, &m_completedFence) ); + + VkSubmitInfo si; + si.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + si.pNext = NULL; + si.waitSemaphoreCount = m_numWaitSemaphores; + si.pWaitSemaphores = &m_waitSemaphores[0]; + si.pWaitDstStageMask = m_waitSemaphoreStages; + si.commandBufferCount = 1; + si.pCommandBuffers = &m_activeCommandBuffer; + si.signalSemaphoreCount = m_numSignalSemaphores; + si.pSignalSemaphores = &m_signalSemaphores[0]; + + m_numWaitSemaphores = 0; + m_numSignalSemaphores = 0; + + VK_CHECK(vkQueueSubmit(m_queue, 1, &si, m_completedFence) ); + + if (_wait) + { + VK_CHECK(vkWaitForFences(device, 1, &m_completedFence, VK_TRUE, UINT64_MAX) ); + } + + m_activeCommandBuffer = VK_NULL_HANDLE; + + m_currentFrameInFlight = (m_currentFrameInFlight + 1) % m_numFramesInFlight; + m_submitted++; + } + } + + void CommandQueueVK::finish(bool _finishAll) + { + if (_finishAll) + { + for (uint32_t ii = 0; ii < m_numFramesInFlight; ++ii) + { + consume(); + } + + m_consumeIndex = m_currentFrameInFlight; + } + else + { + consume(); + } + } + + void CommandQueueVK::release(uint64_t _handle, VkObjectType _type) + { + Resource resource; + resource.m_type = _type; + resource.m_handle = _handle; + m_release[m_currentFrameInFlight].push_back(resource); + } + + void CommandQueueVK::consume() + { + m_consumeIndex = (m_consumeIndex + 1) % m_numFramesInFlight; + + for (const Resource& resource : m_release[m_consumeIndex]) + { + switch (resource.m_type) + { + case VK_OBJECT_TYPE_BUFFER: destroy<VkBuffer >(resource.m_handle); break; + case VK_OBJECT_TYPE_IMAGE_VIEW: destroy<VkImageView >(resource.m_handle); break; + case VK_OBJECT_TYPE_IMAGE: destroy<VkImage >(resource.m_handle); break; + case VK_OBJECT_TYPE_FRAMEBUFFER: destroy<VkFramebuffer >(resource.m_handle); break; + case VK_OBJECT_TYPE_PIPELINE_LAYOUT: destroy<VkPipelineLayout >(resource.m_handle); break; + case VK_OBJECT_TYPE_PIPELINE: destroy<VkPipeline >(resource.m_handle); break; + case VK_OBJECT_TYPE_DESCRIPTOR_SET: destroy<VkDescriptorSet >(resource.m_handle); break; + case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT: destroy<VkDescriptorSetLayout>(resource.m_handle); break; + case VK_OBJECT_TYPE_RENDER_PASS: destroy<VkRenderPass >(resource.m_handle); break; + case VK_OBJECT_TYPE_SAMPLER: destroy<VkSampler >(resource.m_handle); break; + case VK_OBJECT_TYPE_SEMAPHORE: destroy<VkSemaphore >(resource.m_handle); break; + case VK_OBJECT_TYPE_SURFACE_KHR: destroy<VkSurfaceKHR >(resource.m_handle); break; + case VK_OBJECT_TYPE_SWAPCHAIN_KHR: destroy<VkSwapchainKHR >(resource.m_handle); break; + case VK_OBJECT_TYPE_DEVICE_MEMORY: destroy<VkDeviceMemory >(resource.m_handle); break; + default: + BX_ASSERT(false, "Invalid resource type: %d", resource.m_type); + break; + } + } + + m_release[m_consumeIndex].clear(); } void RendererContextVK::submitBlit(BlitState& _bs, uint16_t _view) { + VkImageLayout srcLayouts[BGFX_CONFIG_MAX_BLIT_ITEMS]; + VkImageLayout dstLayouts[BGFX_CONFIG_MAX_BLIT_ITEMS]; + + BlitState bs0 = _bs; + + while (bs0.hasItem(_view) ) + { + uint16_t item = bs0.m_item; + + const BlitItem& blit = bs0.advance(); + + TextureVK& src = m_textures[blit.m_src.idx]; + TextureVK& dst = m_textures[blit.m_dst.idx]; + + srcLayouts[item] = VK_NULL_HANDLE != src.m_singleMsaaImage ? src.m_currentSingleMsaaImageLayout : src.m_currentImageLayout; + dstLayouts[item] = dst.m_currentImageLayout; + } + + bs0 = _bs; + + while (bs0.hasItem(_view) ) + { + const BlitItem& blit = bs0.advance(); + + TextureVK& src = m_textures[blit.m_src.idx]; + TextureVK& dst = m_textures[blit.m_dst.idx]; + + src.setImageMemoryBarrier( + m_commandBuffer + , blit.m_src.idx == blit.m_dst.idx ? VK_IMAGE_LAYOUT_GENERAL : VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL + , VK_NULL_HANDLE != src.m_singleMsaaImage + ); + + if (blit.m_src.idx != blit.m_dst.idx) + { + dst.setImageMemoryBarrier(m_commandBuffer, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + } + + const uint16_t srcSamples = VK_NULL_HANDLE != src.m_singleMsaaImage ? 1 : src.m_sampler.Count; + const uint16_t dstSamples = dst.m_sampler.Count; + BX_UNUSED(srcSamples, dstSamples); + + BX_ASSERT( + srcSamples == dstSamples + , "Mismatching texture sample count (%d != %d)." + , srcSamples + , dstSamples + ); + + VkImageCopy copyInfo; + copyInfo.srcSubresource.aspectMask = src.m_aspectMask; + copyInfo.srcSubresource.mipLevel = blit.m_srcMip; + copyInfo.srcSubresource.baseArrayLayer = 0; + copyInfo.srcSubresource.layerCount = 1; + copyInfo.srcOffset.x = blit.m_srcX; + copyInfo.srcOffset.y = blit.m_srcY; + copyInfo.srcOffset.z = 0; + copyInfo.dstSubresource.aspectMask = dst.m_aspectMask; + copyInfo.dstSubresource.mipLevel = blit.m_dstMip; + copyInfo.dstSubresource.baseArrayLayer = 0; + copyInfo.dstSubresource.layerCount = 1; + copyInfo.dstOffset.x = blit.m_dstX; + copyInfo.dstOffset.y = blit.m_dstY; + copyInfo.dstOffset.z = 0; + copyInfo.extent.width = blit.m_width; + copyInfo.extent.height = blit.m_height; + copyInfo.extent.depth = 1; + + const uint32_t depth = bx::max<uint32_t>(1, blit.m_depth); + + if (VK_IMAGE_VIEW_TYPE_3D == src.m_type) + { + BX_ASSERT(VK_IMAGE_VIEW_TYPE_3D == dst.m_type, "Can't blit between 2D and 3D image."); + + copyInfo.srcOffset.z = blit.m_srcZ; + copyInfo.dstOffset.z = blit.m_dstZ; + copyInfo.extent.depth = depth; + } + else + { + copyInfo.srcSubresource.baseArrayLayer = blit.m_srcZ; + copyInfo.dstSubresource.baseArrayLayer = blit.m_dstZ; + copyInfo.srcSubresource.layerCount = depth; + copyInfo.dstSubresource.layerCount = depth; + } + + vkCmdCopyImage( + m_commandBuffer + , VK_NULL_HANDLE != src.m_singleMsaaImage ? src.m_singleMsaaImage : src.m_textureImage + , VK_NULL_HANDLE != src.m_singleMsaaImage ? src.m_currentSingleMsaaImageLayout : src.m_currentImageLayout + , dst.m_textureImage + , dst.m_currentImageLayout + , 1 + , ©Info + ); + + setMemoryBarrier( + m_commandBuffer + , VK_PIPELINE_STAGE_TRANSFER_BIT + , VK_PIPELINE_STAGE_TRANSFER_BIT + ); + } + while (_bs.hasItem(_view) ) { + uint16_t item = _bs.m_item; + const BlitItem& blit = _bs.advance(); - BX_UNUSED(blit); + + TextureVK& src = m_textures[blit.m_src.idx]; + TextureVK& dst = m_textures[blit.m_dst.idx]; + + src.setImageMemoryBarrier(m_commandBuffer, srcLayouts[item], VK_NULL_HANDLE != src.m_singleMsaaImage); + dst.setImageMemoryBarrier(m_commandBuffer, dstLayouts[item]); } } void RendererContextVK::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { - BX_UNUSED(_render, _clearQuad, _textVideoMemBlitter); + BX_UNUSED(_clearQuad); - updateResolution(_render->m_resolution); + if (updateResolution(_render->m_resolution) ) + { + return; + } + + if (_render->m_capture) + { + renderDocTriggerCapture(); + } + + BGFX_VK_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorView); int64_t timeBegin = bx::getHPCounter(); int64_t captureElapsed = 0; -// m_gpuTimer.begin(m_commandList); + uint32_t frameQueryIdx = UINT32_MAX; + + if (m_timerQuerySupport) + { + frameQueryIdx = m_gpuTimer.begin(BGFX_CONFIG_MAX_VIEWS, _render->m_frameNum); + } if (0 < _render->m_iboffset) { -// TransientIndexBuffer* ib = _render->m_transientIb; -// m_indexBuffers[ib->handle.idx].update(m_commandList, 0, _render->m_iboffset, ib->data); + BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource); + TransientIndexBuffer* ib = _render->m_transientIb; + m_indexBuffers[ib->handle.idx].update(m_commandBuffer, 0, _render->m_iboffset, ib->data); } if (0 < _render->m_vboffset) { -// TransientVertexBuffer* vb = _render->m_transientVb; -// m_vertexBuffers[vb->handle.idx].update(m_commandList, 0, _render->m_vboffset, vb->data); + BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource); + TransientVertexBuffer* vb = _render->m_transientVb; + m_vertexBuffers[vb->handle.idx].update(m_commandBuffer, 0, _render->m_vboffset, vb->data); } _render->sort(); @@ -3679,39 +8204,34 @@ VK_DESTROY currentState.m_stateFlags = BGFX_STATE_NONE; currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); - const bool hmdEnabled = false; - ViewState viewState(_render, hmdEnabled); - viewState.reset(_render, hmdEnabled); + static ViewState viewState; + viewState.reset(_render); -// bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); -// setDebugWireframe(wireframe); + bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); + setDebugWireframe(wireframe); - uint16_t currentSamplerStateIdx = kInvalidHandle; - uint16_t currentProgramIdx = kInvalidHandle; - uint32_t currentBindHash = 0; - bool hasPredefined = false; - bool commandListChanged = false; + ProgramHandle currentProgram = BGFX_INVALID_HANDLE; + bool hasPredefined = false; VkPipeline currentPipeline = VK_NULL_HANDLE; + VkDescriptorSet currentDescriptorSet = VK_NULL_HANDLE; + uint32_t currentBindHash = 0; + uint32_t descriptorSetCount = 0; + VkIndexType currentIndexFormat = VK_INDEX_TYPE_MAX_ENUM; SortKey key; uint16_t view = UINT16_MAX; FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS }; BlitState bs(_render); - uint32_t blendFactor = 0; - - const uint64_t primType = _render->m_debug&BGFX_DEBUG_WIREFRAME ? BGFX_STATE_PT_LINES : 0; - uint8_t primIndex = uint8_t(primType >> BGFX_STATE_PT_SHIFT); - PrimInfo prim = s_primInfo[primIndex]; + uint64_t blendFactor = UINT64_MAX; - bool wasCompute = false; + bool wasCompute = false; bool viewHasScissor = false; bool restoreScissor = false; Rect viewScissorRect; viewScissorRect.clear(); - const uint32_t maxComputeBindings = g_caps.limits.maxComputeBindings; - BX_UNUSED(maxComputeBindings); + bool isFrameBufferValid = false; uint32_t statsNumPrimsSubmitted[BX_COUNTOF(s_primInfo)] = {}; uint32_t statsNumPrimsRendered[BX_COUNTOF(s_primInfo)] = {}; @@ -3719,64 +8239,43 @@ VK_DESTROY uint32_t statsNumIndices = 0; uint32_t statsKeyType[2] = {}; - VkSemaphore renderWait = m_presentDone[m_backBufferColorIdx]; - VK_CHECK(vkAcquireNextImageKHR(m_device - , m_swapchain - , UINT64_MAX - , renderWait - , VK_NULL_HANDLE - , &m_backBufferColorIdx - ) ); - - const uint64_t f0 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_FACTOR, BGFX_STATE_BLEND_FACTOR); - const uint64_t f1 = BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_INV_FACTOR, BGFX_STATE_BLEND_INV_FACTOR); - + const uint64_t f0 = BGFX_STATE_BLEND_FACTOR; + const uint64_t f1 = BGFX_STATE_BLEND_INV_FACTOR; + const uint64_t f2 = BGFX_STATE_BLEND_FACTOR<<4; + const uint64_t f3 = BGFX_STATE_BLEND_INV_FACTOR<<4; - ScratchBufferVK& scratchBuffer = m_scratchBuffer[m_backBufferColorIdx]; - VkDescriptorBufferInfo descriptorBufferInfo; - scratchBuffer.reset(descriptorBufferInfo); - - VkCommandBufferBeginInfo cbbi; - cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - cbbi.pNext = NULL; - cbbi.flags = 0 - | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT -// | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT - ; - cbbi.pInheritanceInfo = NULL; + ScratchBufferVK& scratchBuffer = m_scratchBuffer[m_cmd.m_currentFrameInFlight]; + scratchBuffer.reset(); - m_commandBuffer = m_commandBuffers[m_backBufferColorIdx]; - VK_CHECK(vkBeginCommandBuffer(m_commandBuffer, &cbbi) ); - - setImageMemoryBarrier(m_commandBuffer - , m_backBufferColorImage[m_backBufferColorIdx] - , VK_IMAGE_LAYOUT_PRESENT_SRC_KHR - , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL + setMemoryBarrier( + m_commandBuffer + , VK_PIPELINE_STAGE_TRANSFER_BIT + , VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT ); VkRenderPassBeginInfo rpbi; rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; rpbi.pNext = NULL; - rpbi.renderPass = m_renderPass; - rpbi.framebuffer = m_backBufferColor[m_backBufferColorIdx]; - rpbi.renderArea.offset.x = 0; - rpbi.renderArea.offset.y = 0; - rpbi.renderArea.extent = m_sci.imageExtent; rpbi.clearValueCount = 0; rpbi.pClearValues = NULL; bool beginRenderPass = false; + Profiler<TimerQueryVK> profiler( + _render + , m_gpuTimer + , s_viewName + , m_timerQuerySupport + ); + + m_occlusionQuery.flush(_render); + if (0 == (_render->m_debug&BGFX_DEBUG_IFH) ) { -// m_batch.begin(); - -// uint8_t eye = 0; -// uint8_t restartState = 0; viewState.m_rect = _render->m_view[0].m_rect; int32_t numItems = _render->m_numRenderItems; - for (int32_t item = 0, restartItem = numItems; item < numItems || restartItem < numItems;) + for (int32_t item = 0; item < numItems;) { const uint64_t encodedKey = _render->m_sortKeys[item]; const bool isCompute = key.decode(encodedKey, _render->m_viewRemap); @@ -3800,66 +8299,94 @@ VK_DESTROY beginRenderPass = false; } - VK_CHECK(vkEndCommandBuffer(m_commandBuffer) ); + view = key.m_view; + currentProgram = BGFX_INVALID_HANDLE; + hasPredefined = false; -// m_batch.flush(m_commandList, true); - kick(renderWait); - renderWait = VK_NULL_HANDLE; -finishAll(); + if (item > 1) + { + profiler.end(); + } - view = key.m_view; - currentPipeline = VK_NULL_HANDLE; - currentSamplerStateIdx = kInvalidHandle; -BX_UNUSED(currentSamplerStateIdx); - currentProgramIdx = kInvalidHandle; - hasPredefined = false; - - fbh = _render->m_view[view].m_fbh; - setFrameBuffer(fbh); - - viewState.m_rect = _render->m_view[view].m_rect; - const Rect& rect = _render->m_view[view].m_rect; - const Rect& scissorRect = _render->m_view[view].m_scissor; - viewHasScissor = !scissorRect.isZero(); - viewScissorRect = viewHasScissor ? scissorRect : rect; - - rpbi.renderArea.offset.x = rect.m_x; - rpbi.renderArea.offset.y = rect.m_y; - rpbi.renderArea.extent.width = rect.m_width; - rpbi.renderArea.extent.height = rect.m_height; - VK_CHECK(vkBeginCommandBuffer(m_commandBuffer, &cbbi) ); - vkCmdBeginRenderPass(m_commandBuffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE); - beginRenderPass = true; + BGFX_VK_PROFILER_END(); + setViewType(view, " "); + BGFX_VK_PROFILER_BEGIN(view, kColorView); + + profiler.begin(view); - VkViewport vp; - vp.x = rect.m_x; - vp.y = rect.m_y; - vp.width = rect.m_width; - vp.height = rect.m_height; - vp.minDepth = 0.0f; - vp.maxDepth = 1.0f; - vkCmdSetViewport(m_commandBuffer, 0, 1, &vp); - - VkRect2D rc; - rc.offset.x = viewScissorRect.m_x; - rc.offset.y = viewScissorRect.m_y; - rc.extent.width = viewScissorRect.m_x + viewScissorRect.m_width; - rc.extent.height = viewScissorRect.m_y + viewScissorRect.m_height; - vkCmdSetScissor(m_commandBuffer, 0, 1, &rc); - - restoreScissor = false; - - Clear& clr = _render->m_view[view].m_clear; - if (BGFX_CLEAR_NONE != clr.m_flags) + if (_render->m_view[view].m_fbh.idx != fbh.idx) { - Rect clearRect = rect; - clearRect.setIntersect(rect, viewScissorRect); - clearQuad(clearRect, clr, _render->m_colorPalette); + fbh = _render->m_view[view].m_fbh; + setFrameBuffer(fbh); } - prim = s_primInfo[Topology::Count]; // Force primitive type update. + const FrameBufferVK& fb = isValid(m_fbh) + ? m_frameBuffers[m_fbh.idx] + : m_backBuffer + ; + + isFrameBufferValid = fb.isRenderable(); + + if (isFrameBufferValid) + { + viewState.m_rect = _render->m_view[view].m_rect; + Rect rect = _render->m_view[view].m_rect; + Rect scissorRect = _render->m_view[view].m_scissor; + viewHasScissor = !scissorRect.isZero(); + viewScissorRect = viewHasScissor ? scissorRect : rect; + restoreScissor = false; + + // Clamp the rect to what's valid according to Vulkan. + rect.m_width = bx::min(rect.m_width, fb.m_width - rect.m_x); + rect.m_height = bx::min(rect.m_height, fb.m_height - rect.m_y); + if (_render->m_view[view].m_rect.m_width != rect.m_width + || _render->m_view[view].m_rect.m_height != rect.m_height) + { + BX_TRACE("Clamp render pass from %dx%d to %dx%d" + , _render->m_view[view].m_rect.m_width + , _render->m_view[view].m_rect.m_height + , rect.m_width + , rect.m_height + ); + } + + rpbi.framebuffer = fb.m_currentFramebuffer; + rpbi.renderPass = fb.m_renderPass; + rpbi.renderArea.offset.x = rect.m_x; + rpbi.renderArea.offset.y = rect.m_y; + rpbi.renderArea.extent.width = rect.m_width; + rpbi.renderArea.extent.height = rect.m_height; + + VkViewport vp; + vp.x = float(rect.m_x); + vp.y = float(rect.m_y + rect.m_height); + vp.width = float(rect.m_width); + vp.height = -float(rect.m_height); + vp.minDepth = 0.0f; + vp.maxDepth = 1.0f; + vkCmdSetViewport(m_commandBuffer, 0, 1, &vp); + + VkRect2D rc; + rc.offset.x = viewScissorRect.m_x; + rc.offset.y = viewScissorRect.m_y; + rc.extent.width = viewScissorRect.m_width; + rc.extent.height = viewScissorRect.m_height; + vkCmdSetScissor(m_commandBuffer, 0, 1, &rc); + + const Clear& clr = _render->m_view[view].m_clear; + if (BGFX_CLEAR_NONE != clr.m_flags) + { + vkCmdBeginRenderPass(m_commandBuffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE); + + Rect clearRect = rect; + clearRect.setIntersect(rect, viewScissorRect); + clearQuad(clearRect, clr, _render->m_colorPalette); + + vkCmdEndRenderPass(m_commandBuffer); + } - submitBlit(bs, view); + submitBlit(bs, view); + } } if (isCompute) @@ -3867,123 +8394,43 @@ BX_UNUSED(currentSamplerStateIdx); if (!wasCompute) { wasCompute = true; + currentBindHash = 0; -// m_commandList->SetComputeRootSignature(m_rootSignature); -// ID3D12DescriptorHeap* heaps[] = { -// m_samplerAllocator.getHeap(), -// scratchBuffer.getHeap(), -// }; -// m_commandList->SetDescriptorHeaps(BX_COUNTOF(heaps), heaps); + BGFX_VK_PROFILER_END(); + setViewType(view, "C"); + BGFX_VK_PROFILER_BEGIN(view, kColorCompute); } + // renderpass external subpass dependencies handle graphics -> compute and compute -> graphics + // but not compute -> compute (possibly also across views if they contain no draw calls) + setMemoryBarrier( + m_commandBuffer + , VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT + , VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT + ); + const RenderCompute& compute = renderItem.compute; - VkPipeline pipeline = getPipeline(key.m_program); - if (pipeline != currentPipeline) + const VkPipeline pipeline = getPipeline(key.m_program); + + if (currentPipeline != pipeline) { currentPipeline = pipeline; vkCmdBindPipeline(m_commandBuffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); - currentBindHash = 0; } -// uint32_t bindHash = bx::hash<bx::HashMurmur2A>(renderBind.m_bind, sizeof(renderBind.m_bind) ); -// if (currentBindHash != bindHash) -// { -// currentBindHash = bindHash; -// -// Bind* bindCached = bindLru.find(bindHash); -// if (NULL == bindCached) -// { -// D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_MAX_COMPUTE_BINDINGS] = {}; -// uint32_t samplerFlags[BGFX_MAX_COMPUTE_BINDINGS] = {}; -// -// for (uint32_t ii = 0; ii < maxComputeBindings; ++ii) -// { -// const Binding& bind = renderBind.m_bind[ii]; -// if (kInvalidHandle != bind.m_idx) -// { -// switch (bind.m_type) -// { -// case Binding::Image: -// { -// TextureD3D12& texture = m_textures[bind.m_idx]; -// -// if (Access::Read != bind.m_access) -// { -// texture.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); -// scratchBuffer.allocUav(srvHandle[ii], texture, bind.m_mip); -// } -// else -// { -// texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); -// scratchBuffer.allocSrv(srvHandle[ii], texture, bind.m_mip); -// samplerFlags[ii] = texture.m_flags; -// } -// } -// break; -// -// case Binding::IndexBuffer: -// case Binding::VertexBuffer: -// { -// BufferD3D12& buffer = Binding::IndexBuffer == bind.m_type -// ? m_indexBuffers[bind.m_idx] -// : m_vertexBuffers[bind.m_idx] -// ; -// -// if (Access::Read != bind.m_access) -// { -// buffer.setState(m_commandList, D3D12_RESOURCE_STATE_UNORDERED_ACCESS); -// scratchBuffer.allocUav(srvHandle[ii], buffer); -// } -// else -// { -// buffer.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); -// scratchBuffer.allocSrv(srvHandle[ii], buffer); -// } -// } -// break; -// } -// } -// } -// -// uint16_t samplerStateIdx = getSamplerState(samplerFlags, maxComputeBindings, _render->m_colorPalette); -// if (samplerStateIdx != currentSamplerStateIdx) -// { -// currentSamplerStateIdx = samplerStateIdx; -// m_commandList->SetComputeRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); -// } -// -// m_commandList->SetComputeRootDescriptorTable(Rdt::SRV, srvHandle[0]); -// m_commandList->SetComputeRootDescriptorTable(Rdt::UAV, srvHandle[0]); -// -// Bind bind; -// bind.m_srvHandle = srvHandle[0]; -// bind.m_samplerStateIdx = samplerStateIdx; -// bindLru.add(bindHash, bind, 0); -// } -// else -// { -// uint16_t samplerStateIdx = bindCached->m_samplerStateIdx; -// if (samplerStateIdx != currentSamplerStateIdx) -// { -// currentSamplerStateIdx = samplerStateIdx; -// m_commandList->SetComputeRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); -// } -// m_commandList->SetComputeRootDescriptorTable(Rdt::SRV, bindCached->m_srvHandle); -// m_commandList->SetComputeRootDescriptorTable(Rdt::UAV, bindCached->m_srvHandle); -// } -// } - bool constantsChanged = false; + if (compute.m_uniformBegin < compute.m_uniformEnd - || currentProgramIdx != key.m_program) + || currentProgram.idx != key.m_program.idx) { rendererUpdateUniforms(this, _render->m_uniformBuffer[compute.m_uniformIdx], compute.m_uniformBegin, compute.m_uniformEnd); - currentProgramIdx = key.m_program; - ProgramVK& program = m_program[currentProgramIdx]; + currentProgram = key.m_program; + ProgramVK& program = m_program[currentProgram.idx]; UniformBuffer* vcb = program.m_vsh->m_constantBuffer; + if (NULL != vcb) { commit(*vcb); @@ -3993,13 +8440,62 @@ BX_UNUSED(currentSamplerStateIdx); constantsChanged = true; } + const ProgramVK& program = m_program[currentProgram.idx]; + if (constantsChanged || hasPredefined) { - ProgramVK& program = m_program[currentProgramIdx]; - viewState.setPredefined<4>(this, view, 0, program, _render, compute); -// commitShaderConstants(key.m_program, gpuAddress); -// m_commandList->SetComputeRootConstantBufferView(Rdt::CBV, gpuAddress); + viewState.setPredefined<4>(this, view, program, _render, compute); + } + + if (VK_NULL_HANDLE != program.m_descriptorSetLayout) + { + const uint32_t vsize = program.m_vsh->m_size; + uint32_t numOffset = 0; + uint32_t offset = 0; + + if (constantsChanged + || hasPredefined) + { + if (vsize > 0) + { + offset = scratchBuffer.write(m_vsScratch, vsize); + ++numOffset; + } + } + + bx::HashMurmur2A hash; + hash.begin(); + hash.add(program.m_descriptorSetLayout); + hash.add(renderBind.m_bind, sizeof(renderBind.m_bind) ); + hash.add(vsize); + hash.add(0); + const uint32_t bindHash = hash.end(); + + if (currentBindHash != bindHash) + { + currentBindHash = bindHash; + + currentDescriptorSet = getDescriptorSet( + program + , renderBind + , scratchBuffer + , _render->m_colorPalette + ); + + descriptorSetCount++; + } + + vkCmdBindDescriptorSets( + m_commandBuffer + , VK_PIPELINE_BIND_POINT_COMPUTE + , program.m_pipelineLayout + , 0 + , 1 + , ¤tDescriptorSet + , numOffset + , &offset + ); } if (isValid(compute.m_indirectBuffer) ) @@ -4014,13 +8510,13 @@ BX_UNUSED(currentSamplerStateIdx); uint32_t args = compute.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) { -// m_commandList->ExecuteIndirect(ptr, args); + vkCmdDispatchIndirect(m_commandBuffer, vb.m_buffer, args); args += BGFX_CONFIG_DRAW_INDIRECT_STRIDE; } } else { -// m_commandList->Dispatch(compute.m_numX, compute.m_numY, compute.m_numZ); + vkCmdDispatch(m_commandBuffer, compute.m_numX, compute.m_numY, compute.m_numZ); } continue; @@ -4028,189 +8524,154 @@ BX_UNUSED(currentSamplerStateIdx); const RenderDraw& draw = renderItem.draw; - const bool hasOcclusionQuery = false; //0 != (draw.m_stateFlags & BGFX_STATE_INTERNAL_OCCLUSION_QUERY); + rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); + + const bool hasOcclusionQuery = 0 != (draw.m_stateFlags & BGFX_STATE_INTERNAL_OCCLUSION_QUERY); { - const bool occluded = false //true -// && isValid(draw.m_occlusionQuery) -// && !hasOcclusionQuery -// && !isVisible(_render, draw.m_occlusionQuery, 0 != (draw.m_submitFlags&BGFX_SUBMIT_INTERNAL_OCCLUSION_VISIBLE) ) + const bool occluded = true + && isValid(draw.m_occlusionQuery) + && !hasOcclusionQuery + && !isVisible(_render, draw.m_occlusionQuery, 0 != (draw.m_submitFlags & BGFX_SUBMIT_INTERNAL_OCCLUSION_VISIBLE) ) ; if (occluded + || !isFrameBufferValid + || 0 == draw.m_streamMask || _render->m_frameCache.isZeroArea(viewScissorRect, draw.m_scissor) ) { -// if (resetState) -// { -// currentState.clear(); -// currentState.m_scissor = !draw.m_scissor; -// currentBind.clear(); -// } - continue; } } - const uint64_t newFlags = draw.m_stateFlags; - uint64_t changedFlags = currentState.m_stateFlags ^ draw.m_stateFlags; - currentState.m_stateFlags = newFlags; + const uint64_t changedFlags = currentState.m_stateFlags ^ draw.m_stateFlags; + currentState.m_stateFlags = draw.m_stateFlags; - const uint64_t newStencil = draw.m_stencil; - uint64_t changedStencil = (currentState.m_stencil ^ draw.m_stencil) & BGFX_STENCIL_FUNC_REF_MASK; - currentState.m_stencil = newStencil; - - if (viewChanged - || wasCompute) + if (!beginRenderPass) { if (wasCompute) { wasCompute = false; + currentBindHash = 0; } - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) - { - BX_UNUSED(s_viewName); -// wchar_t* viewNameW = s_viewNameW[view]; -// viewNameW[3] = L' '; -// PIX_ENDEVENT(); -// PIX_BEGINEVENT(toRgba8(0xff, 0x00, 0x00, 0xff), viewNameW); - } + BGFX_VK_PROFILER_END(); + setViewType(view, " "); + BGFX_VK_PROFILER_BEGIN(view, kColorDraw); - commandListChanged = true; - } + vkCmdBeginRenderPass(m_commandBuffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE); + beginRenderPass = true; - if (commandListChanged) - { - commandListChanged = false; - -// m_commandList->SetGraphicsRootSignature(m_rootSignature); -// ID3D12DescriptorHeap* heaps[] = { -// m_samplerAllocator.getHeap(), -// scratchBuffer.getHeap(), -// }; -// m_commandList->SetDescriptorHeaps(BX_COUNTOF(heaps), heaps); - - currentPipeline = VK_NULL_HANDLE; - currentBindHash = 0; - currentSamplerStateIdx = kInvalidHandle; - currentProgramIdx = kInvalidHandle; - currentState.clear(); + currentProgram = BGFX_INVALID_HANDLE; currentState.m_scissor = !draw.m_scissor; - changedFlags = BGFX_STATE_MASK; - changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); - currentState.m_stateFlags = newFlags; - currentState.m_stencil = newStencil; - - const uint64_t pt = newFlags&BGFX_STATE_PT_MASK; - primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT); } - rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); - - if (isValid(draw.m_stream[0].m_handle) ) + if (0 != draw.m_streamMask) { - const uint64_t state = draw.m_stateFlags; - bool hasFactor = 0 - || f0 == (state & f0) - || f1 == (state & f1) - ; + const bool bindAttribs = hasVertexStreamChanged(currentState, draw); + + currentState.m_streamMask = draw.m_streamMask; + currentState.m_instanceDataBuffer = draw.m_instanceDataBuffer; + currentState.m_instanceDataOffset = draw.m_instanceDataOffset; + currentState.m_instanceDataStride = draw.m_instanceDataStride; + + const VertexLayout* layouts[BGFX_CONFIG_MAX_VERTEX_STREAMS]; + VkBuffer streamBuffers[BGFX_CONFIG_MAX_VERTEX_STREAMS + 1]; + VkDeviceSize streamOffsets[BGFX_CONFIG_MAX_VERTEX_STREAMS + 1]; + uint8_t numStreams = 0; + uint32_t numVertices = draw.m_numVertices; + if (UINT8_MAX != draw.m_streamMask) + { + for (uint32_t idx = 0, streamMask = draw.m_streamMask + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ++numStreams + ) + { + const uint32_t ntz = bx::uint32_cnttz(streamMask); + streamMask >>= ntz; + idx += ntz; + + currentState.m_stream[idx] = draw.m_stream[idx]; + + const VertexBufferHandle handle = draw.m_stream[idx].m_handle; + const VertexBufferVK& vb = m_vertexBuffers[handle.idx]; + const uint16_t decl = isValid(draw.m_stream[idx].m_layoutHandle) + ? draw.m_stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx + ; + const VertexLayout& layout = m_vertexLayouts[decl]; + const uint32_t stride = layout.m_stride; + + streamBuffers[numStreams] = m_vertexBuffers[handle.idx].m_buffer; + streamOffsets[numStreams] = draw.m_stream[idx].m_startVertex * stride; + layouts[numStreams] = &layout; + + numVertices = bx::uint32_min(UINT32_MAX == draw.m_numVertices + ? vb.m_size/stride + : draw.m_numVertices + , numVertices + ); + } + } + + if (bindAttribs) + { + uint32_t numVertexBuffers = numStreams; + + if (isValid(draw.m_instanceDataBuffer) ) + { + streamOffsets[numVertexBuffers] = draw.m_instanceDataOffset; + streamBuffers[numVertexBuffers] = m_vertexBuffers[draw.m_instanceDataBuffer.idx].m_buffer; + numVertexBuffers++; + } - const VertexBufferVK& vb = m_vertexBuffers[draw.m_stream[0].m_handle.idx]; - uint16_t declIdx = !isValid(vb.m_decl) ? draw.m_stream[0].m_decl.idx : vb.m_decl.idx; + if (0 < numVertexBuffers) + { + vkCmdBindVertexBuffers( + m_commandBuffer + , 0 + , numVertexBuffers + , &streamBuffers[0] + , streamOffsets + ); + } + } - VkPipeline pipeline = - getPipeline(state + const VkPipeline pipeline = + getPipeline(draw.m_stateFlags , draw.m_stencil - , declIdx + , numStreams + , layouts , key.m_program , uint8_t(draw.m_instanceDataStride/16) ); - uint16_t scissor = draw.m_scissor; - uint32_t bindHash = bx::hash<bx::HashMurmur2A>(renderBind.m_bind, sizeof(renderBind.m_bind) ); - if (currentBindHash != bindHash - || 0 != changedStencil - || (hasFactor && blendFactor != draw.m_rgba) - || (0 != (BGFX_STATE_PT_MASK & changedFlags) - || prim.m_topology != s_primInfo[primIndex].m_topology) - || currentState.m_scissor != scissor - || pipeline != currentPipeline - || hasOcclusionQuery) + if (currentPipeline != pipeline) { -// m_batch.flush(m_commandList); + currentPipeline = pipeline; + vkCmdBindPipeline(m_commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); } -// if (currentBindHash != bindHash) -// { -// currentBindHash = bindHash; -// -// Bind* bindCached = bindLru.find(bindHash); -// if (NULL == bindCached) -// { -// D3D12_GPU_DESCRIPTOR_HANDLE srvHandle[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; -// uint32_t samplerFlags[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; -// { -// srvHandle[0].ptr = 0; -// for (uint32_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) -// { -// const Binding& bind = renderBind.m_bind[stage]; -// if (kInvalidHandle != bind.m_idx) -// { -// TextureD3D12& texture = m_textures[bind.m_idx]; -// texture.setState(m_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); -// scratchBuffer.allocSrv(srvHandle[stage], texture); -// samplerFlags[stage] = (0 == (BGFX_TEXTURE_INTERNAL_DEFAULT_SAMPLER & bind.m_textureFlags) -// ? bind.m_textureFlags -// : texture.m_flags -// ) & (BGFX_TEXTURE_SAMPLER_BITS_MASK|BGFX_TEXTURE_BORDER_COLOR_MASK) -// ; -// } -// else -// { -// bx::memCopy(&srvHandle[stage], &srvHandle[0], sizeof(D3D12_GPU_DESCRIPTOR_HANDLE) ); -// samplerFlags[stage] = 0; -// } -// } -// } -// -// if (srvHandle[0].ptr != 0) -// { -// uint16_t samplerStateIdx = getSamplerState(samplerFlags, BGFX_CONFIG_MAX_TEXTURE_SAMPLERS, _render->m_colorPalette); -// if (samplerStateIdx != currentSamplerStateIdx) -// { -// currentSamplerStateIdx = samplerStateIdx; -// m_commandList->SetGraphicsRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); -// } -// -// m_commandList->SetGraphicsRootDescriptorTable(Rdt::SRV, srvHandle[0]); -// -// Bind bind; -// bind.m_srvHandle = srvHandle[0]; -// bind.m_samplerStateIdx = samplerStateIdx; -// bindLru.add(bindHash, bind, 0); -// } -// } -// else -// { -// uint16_t samplerStateIdx = bindCached->m_samplerStateIdx; -// if (samplerStateIdx != currentSamplerStateIdx) -// { -// currentSamplerStateIdx = samplerStateIdx; -// m_commandList->SetGraphicsRootDescriptorTable(Rdt::Sampler, m_samplerAllocator.get(samplerStateIdx) ); -// } -// m_commandList->SetGraphicsRootDescriptorTable(Rdt::SRV, bindCached->m_srvHandle); -// } -// } - - if (pipeline != currentPipeline - || 0 != changedStencil) + const bool hasStencil = 0 != draw.m_stencil; + + if (hasStencil + && currentState.m_stencil != draw.m_stencil) { + currentState.m_stencil = draw.m_stencil; + const uint32_t fstencil = unpackStencil(0, draw.m_stencil); const uint32_t ref = (fstencil&BGFX_STENCIL_FUNC_REF_MASK)>>BGFX_STENCIL_FUNC_REF_SHIFT; vkCmdSetStencilReference(m_commandBuffer, VK_STENCIL_FRONT_AND_BACK, ref); } - if (pipeline != currentPipeline - || (hasFactor && blendFactor != draw.m_rgba) ) + const bool hasFactor = 0 + || f0 == (draw.m_stateFlags & f0) + || f1 == (draw.m_stateFlags & f1) + || f2 == (draw.m_stateFlags & f2) + || f3 == (draw.m_stateFlags & f3) + ; + + if (hasFactor + && blendFactor != draw.m_rgba) { blendFactor = draw.m_rgba; @@ -4222,14 +8683,7 @@ BX_UNUSED(currentSamplerStateIdx); vkCmdSetBlendConstants(m_commandBuffer, bf); } - if (0 != (BGFX_STATE_PT_MASK & changedFlags) - || prim.m_topology != s_primInfo[primIndex].m_topology) - { - const uint64_t pt = newFlags&BGFX_STATE_PT_MASK; - primIndex = uint8_t(pt>>BGFX_STATE_PT_SHIFT); - prim = s_primInfo[primIndex]; -// m_commandList->IASetPrimitiveTopology(prim.m_topology); - } + const uint16_t scissor = draw.m_scissor; if (currentState.m_scissor != scissor) { @@ -4244,8 +8698,8 @@ BX_UNUSED(currentSamplerStateIdx); VkRect2D rc; rc.offset.x = viewScissorRect.m_x; rc.offset.y = viewScissorRect.m_y; - rc.extent.width = viewScissorRect.m_x + viewScissorRect.m_width; - rc.extent.height = viewScissorRect.m_y + viewScissorRect.m_height; + rc.extent.width = viewScissorRect.m_width; + rc.extent.height = viewScissorRect.m_height; vkCmdSetScissor(m_commandBuffer, 0, 1, &rc); } } @@ -4258,25 +8712,19 @@ BX_UNUSED(currentSamplerStateIdx); VkRect2D rc; rc.offset.x = scissorRect.m_x; rc.offset.y = scissorRect.m_y; - rc.extent.width = scissorRect.m_x + scissorRect.m_width; - rc.extent.height = scissorRect.m_y + scissorRect.m_height; + rc.extent.width = scissorRect.m_width; + rc.extent.height = scissorRect.m_height; vkCmdSetScissor(m_commandBuffer, 0, 1, &rc); } } - if (pipeline != currentPipeline) - { - currentPipeline = pipeline; - vkCmdBindPipeline(m_commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); - } - bool constantsChanged = false; if (draw.m_uniformBegin < draw.m_uniformEnd - || currentProgramIdx != key.m_program + || currentProgram.idx != key.m_program.idx || BGFX_STATE_ALPHA_REF_MASK & changedFlags) { - currentProgramIdx = key.m_program; - ProgramVK& program = m_program[currentProgramIdx]; + currentProgram = key.m_program; + ProgramVK& program = m_program[currentProgram.idx]; UniformBuffer* vcb = program.m_vsh->m_constantBuffer; if (NULL != vcb) @@ -4284,83 +8732,222 @@ BX_UNUSED(currentSamplerStateIdx); commit(*vcb); } - UniformBuffer* fcb = program.m_fsh->m_constantBuffer; - if (NULL != fcb) + if (NULL != program.m_fsh) { - commit(*fcb); + UniformBuffer* fcb = program.m_fsh->m_constantBuffer; + if (NULL != fcb) + { + commit(*fcb); + } } hasPredefined = 0 < program.m_numPredefined; constantsChanged = true; } - if (constantsChanged - || hasPredefined) + const ProgramVK& program = m_program[currentProgram.idx]; + + if (hasPredefined) { - ProgramVK& program = m_program[currentProgramIdx]; - uint32_t ref = (newFlags&BGFX_STATE_ALPHA_REF_MASK)>>BGFX_STATE_ALPHA_REF_SHIFT; - viewState.m_alphaRef = ref/255.0f; - viewState.setPredefined<4>(this, view, 0, program, _render, draw); - commitShaderUniforms(m_commandBuffer, key.m_program); //, gpuAddress); + uint32_t ref = (draw.m_stateFlags & BGFX_STATE_ALPHA_REF_MASK) >> BGFX_STATE_ALPHA_REF_SHIFT; + viewState.m_alphaRef = ref / 255.0f; + viewState.setPredefined<4>(this, view, program, _render, draw); } + if (VK_NULL_HANDLE != program.m_descriptorSetLayout) + { + const uint32_t vsize = program.m_vsh->m_size; + const uint32_t fsize = NULL != program.m_fsh ? program.m_fsh->m_size : 0; + uint32_t numOffset = 0; + uint32_t offsets[2] = { 0, 0 }; -// vb.setState(_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); + if (constantsChanged + || hasPredefined) + { + if (vsize > 0) + { + offsets[numOffset++] = scratchBuffer.write(m_vsScratch, vsize); + } - const VertexDecl& vertexDecl = m_vertexDecls[declIdx]; - uint32_t numIndices = 0; + if (fsize > 0) + { + offsets[numOffset++] = scratchBuffer.write(m_fsScratch, fsize); + } + } - VkDeviceSize offset = 0; - vkCmdBindVertexBuffers(m_commandBuffer - , 0 - , 1 - , &vb.m_buffer - , &offset - ); + bx::HashMurmur2A hash; + hash.begin(); + hash.add(program.m_descriptorSetLayout); + hash.add(renderBind.m_bind, sizeof(renderBind.m_bind) ); + hash.add(vsize); + hash.add(fsize); + const uint32_t bindHash = hash.end(); - if (!isValid(draw.m_indexBuffer) ) - { - const uint32_t numVertices = UINT32_MAX == draw.m_numVertices - ? vb.m_size / vertexDecl.m_stride - : draw.m_numVertices - ; - vkCmdDraw(m_commandBuffer - , numVertices - , draw.m_numInstances - , draw.m_stream[0].m_startVertex + if (currentBindHash != bindHash) + { + currentBindHash = bindHash; + + currentDescriptorSet = getDescriptorSet( + program + , renderBind + , scratchBuffer + , _render->m_colorPalette + ); + + descriptorSetCount++; + } + + vkCmdBindDescriptorSets( + m_commandBuffer + , VK_PIPELINE_BIND_POINT_GRAPHICS + , program.m_pipelineLayout , 0 + , 1 + , ¤tDescriptorSet + , numOffset + , offsets ); } - else + + VkBuffer bufferIndirect = VK_NULL_HANDLE; + VkBuffer bufferNumIndirect = VK_NULL_HANDLE; + uint32_t numDrawIndirect = 0; + uint32_t bufferOffsetIndirect = 0; + uint32_t bufferNumOffsetIndirect = 0; + if (isValid(draw.m_indirectBuffer) ) + { + const VertexBufferVK& vb = m_vertexBuffers[draw.m_indirectBuffer.idx]; + bufferIndirect = vb.m_buffer; + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size / BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; + bufferOffsetIndirect = draw.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + + if (isValid(draw.m_numIndirectBuffer) ) + { + bufferNumIndirect = m_indexBuffers[draw.m_numIndirectBuffer.idx].m_buffer; + bufferNumOffsetIndirect = draw.m_numIndirectIndex * sizeof(uint32_t); + } + } + + if (hasOcclusionQuery) { - BufferVK& ib = m_indexBuffers[draw.m_indexBuffer.idx]; -// ib.setState(_commandList, D3D12_RESOURCE_STATE_GENERIC_READ); + m_occlusionQuery.begin(draw.m_occlusionQuery); + } - const bool hasIndex16 = 0 == (ib.m_flags & BGFX_BUFFER_INDEX32); - const uint32_t indexSize = hasIndex16 ? 2 : 4; + const uint8_t primIndex = uint8_t((draw.m_stateFlags & BGFX_STATE_PT_MASK) >> BGFX_STATE_PT_SHIFT); + const PrimInfo& prim = s_primInfo[primIndex]; + + uint32_t numPrimsSubmitted = 0; + uint32_t numIndices = 0; + + if (!isValid(draw.m_indexBuffer) ) + { + numPrimsSubmitted = numVertices / prim.m_div - prim.m_sub; + + if (isValid(draw.m_indirectBuffer) ) + { + if (isValid(draw.m_numIndirectBuffer) ) + { + vkCmdDrawIndirectCountKHR( + m_commandBuffer + , bufferIndirect + , bufferOffsetIndirect + , bufferNumIndirect + , bufferNumOffsetIndirect + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ); + } + else + { + vkCmdDrawIndirect( + m_commandBuffer + , bufferIndirect + , bufferOffsetIndirect + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ); + } + } + else + { + vkCmdDraw( + m_commandBuffer + , numVertices + , draw.m_numInstances + , 0 + , 0 + ); + } + } + else + { + const bool isIndex16 = draw.isIndex16(); + const uint32_t indexSize = isIndex16 ? 2 : 4; + const VkIndexType indexFormat = isIndex16 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32; + const BufferVK& ib = m_indexBuffers[draw.m_indexBuffer.idx]; numIndices = UINT32_MAX == draw.m_numIndices ? ib.m_size / indexSize : draw.m_numIndices ; - vkCmdBindIndexBuffer(m_commandBuffer - , ib.m_buffer - , 0 - , hasIndex16 - ? VK_INDEX_TYPE_UINT16 - : VK_INDEX_TYPE_UINT32 - ); - vkCmdDrawIndexed(m_commandBuffer - , numIndices - , draw.m_numInstances - , draw.m_startIndex - , draw.m_stream[0].m_startVertex - , 0 - ); + numPrimsSubmitted = numIndices / prim.m_div - prim.m_sub; + + if (currentState.m_indexBuffer.idx != draw.m_indexBuffer.idx + || currentIndexFormat != indexFormat) + { + currentState.m_indexBuffer = draw.m_indexBuffer; + currentIndexFormat = indexFormat; + + vkCmdBindIndexBuffer( + m_commandBuffer + , m_indexBuffers[draw.m_indexBuffer.idx].m_buffer + , 0 + , indexFormat + ); + } + + if (isValid(draw.m_indirectBuffer) ) + { + if (isValid(draw.m_numIndirectBuffer) ) + { + vkCmdDrawIndexedIndirectCountKHR( + m_commandBuffer + , bufferIndirect + , bufferOffsetIndirect + , bufferNumIndirect + , bufferNumOffsetIndirect + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ); + } + else + { + vkCmdDrawIndexedIndirect( + m_commandBuffer + , bufferIndirect + , bufferOffsetIndirect + , numDrawIndirect + , BGFX_CONFIG_DRAW_INDIRECT_STRIDE + ); + } + } + else + { + vkCmdDrawIndexed( + m_commandBuffer + , numIndices + , draw.m_numInstances + , draw.m_startIndex + , 0 + , 0 + ); + } } - uint32_t numPrimsSubmitted = numIndices / prim.m_div - prim.m_sub; uint32_t numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted; @@ -4370,18 +8957,38 @@ BX_UNUSED(currentSamplerStateIdx); if (hasOcclusionQuery) { -// m_occlusionQuery.begin(m_commandList, _render, draw.m_occlusionQuery); -// m_batch.flush(m_commandList); -// m_occlusionQuery.end(m_commandList); + m_occlusionQuery.end(); } } } + if (beginRenderPass) + { + vkCmdEndRenderPass(m_commandBuffer); + beginRenderPass = false; + } + + if (wasCompute) + { + setViewType(view, "C"); + BGFX_VK_PROFILER_END(); + BGFX_VK_PROFILER_BEGIN(view, kColorCompute); + } + submitBlit(bs, BGFX_CONFIG_MAX_VIEWS); -// m_batch.end(m_commandList); + if (0 < _render->m_numRenderItems) + { + captureElapsed = -bx::getHPCounter(); + capture(); + captureElapsed += bx::getHPCounter(); + + profiler.end(); + } } + BGFX_VK_PROFILER_END(); + int64_t timeEnd = bx::getHPCounter(); int64_t frameTime = timeEnd - timeBegin; @@ -4393,46 +9000,77 @@ BX_UNUSED(currentSamplerStateIdx); static uint32_t maxGpuLatency = 0; static double maxGpuElapsed = 0.0f; double elapsedGpuMs = 0.0; -BX_UNUSED(maxGpuLatency, maxGpuElapsed, elapsedGpuMs); - static int64_t presentMin = 0; //m_presentElapsed; - static int64_t presentMax = 0; //m_presentElapsed; -BX_UNUSED(presentMin, presentMax); -// presentMin = bx::min<int64_t>(presentMin, m_presentElapsed); -// presentMax = bx::max<int64_t>(presentMax, m_presentElapsed); + static int64_t presentMin = m_presentElapsed; + static int64_t presentMax = m_presentElapsed; + presentMin = bx::min<int64_t>(presentMin, m_presentElapsed); + presentMax = bx::max<int64_t>(presentMax, m_presentElapsed); + + if (UINT32_MAX != frameQueryIdx) + { + m_gpuTimer.end(frameQueryIdx); + + const TimerQueryVK::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS]; + double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); + elapsedGpuMs = (result.m_end - result.m_begin) * toGpuMs; + maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; -// m_gpuTimer.end(m_commandList); + maxGpuLatency = bx::uint32_imax(maxGpuLatency, result.m_pending-1); + } -// while (m_gpuTimer.get() ) -// { -// double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); -// elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; -// maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; -// } -// maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); const int64_t timerFreq = bx::getHPFrequency(); + VkPhysicalDeviceMemoryBudgetPropertiesEXT dmbp; + dmbp.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT; + dmbp.pNext = NULL; + + int64_t gpuMemoryAvailable = -INT64_MAX; + int64_t gpuMemoryUsed = -INT64_MAX; + + if (s_extension[Extension::EXT_memory_budget].m_supported) + { + VkPhysicalDeviceMemoryProperties2 pdmp2; + pdmp2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2; + pdmp2.pNext = &dmbp; + + vkGetPhysicalDeviceMemoryProperties2KHR(m_physicalDevice, &pdmp2); + + gpuMemoryAvailable = 0; + gpuMemoryUsed = 0; + + for (uint32_t ii = 0; ii < m_memoryProperties.memoryHeapCount; ++ii) + { + if (!!(m_memoryProperties.memoryHeaps[ii].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) ) + { + gpuMemoryAvailable += dmbp.heapBudget[ii]; + gpuMemoryUsed += dmbp.heapUsage[ii]; + } + } + } + Stats& perfStats = _render->m_perfStats; perfStats.cpuTimeBegin = timeBegin; perfStats.cpuTimeEnd = timeEnd; perfStats.cpuTimerFreq = timerFreq; -// perfStats.gpuTimeBegin = m_gpuTimer.m_begin; -// perfStats.gpuTimeEnd = m_gpuTimer.m_end; -// perfStats.gpuTimerFreq = m_gpuTimer.m_frequency; -// perfStats.numDraw = statsKeyType[0]; -// perfStats.numCompute = statsKeyType[1]; + const TimerQueryVK::Result& result = m_gpuTimer.m_result[BGFX_CONFIG_MAX_VIEWS]; + perfStats.gpuTimeBegin = result.m_begin; + perfStats.gpuTimeEnd = result.m_end; + perfStats.gpuTimerFreq = m_gpuTimer.m_frequency; + perfStats.numDraw = statsKeyType[0]; + perfStats.numCompute = statsKeyType[1]; perfStats.numBlit = _render->m_numBlitItems; -// perfStats.maxGpuLatency = maxGpuLatency; + perfStats.maxGpuLatency = maxGpuLatency; + perfStats.gpuFrameNum = result.m_frameNum; bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) ); - perfStats.gpuMemoryMax = -INT64_MAX; - perfStats.gpuMemoryUsed = -INT64_MAX; + perfStats.gpuMemoryMax = gpuMemoryAvailable; + perfStats.gpuMemoryUsed = gpuMemoryUsed; if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) { -// PIX_BEGINEVENT(toRgba8(0x40, 0x40, 0x40, 0xff), L"debugstats"); + BGFX_VK_PROFILER_BEGIN_LITERAL("debugstats", kColorFrame); -// m_needPresent = true; TextVideoMem& tvm = m_textVideoMem; static int64_t next = timeEnd; @@ -4447,55 +9085,42 @@ BX_UNUSED(presentMin, presentMax); tvm.clear(); uint16_t pos = 0; tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f - , " %s / " BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME " " + , " %s / " BX_COMPILER_NAME + " / " BX_CPU_NAME + " / " BX_ARCH_NAME + " / " BX_PLATFORM_NAME + " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")" , getRendererName() + , BGFX_API_VERSION + , BGFX_REV_NUMBER ); -// const DXGI_ADAPTER_DESC& desc = m_adapterDesc; -// char description[BX_COUNTOF(desc.Description)]; -// wcstombs(description, desc.Description, BX_COUNTOF(desc.Description) ); -// tvm.printf(0, pos++, 0x8f, " Device: %s", description); -// -// char dedicatedVideo[16]; -// bx::prettify(dedicatedVideo, BX_COUNTOF(dedicatedVideo), desc.DedicatedVideoMemory); -// -// char dedicatedSystem[16]; -// bx::prettify(dedicatedSystem, BX_COUNTOF(dedicatedSystem), desc.DedicatedSystemMemory); -// -// char sharedSystem[16]; -// bx::prettify(sharedSystem, BX_COUNTOF(sharedSystem), desc.SharedSystemMemory); -// -// char processMemoryUsed[16]; -// bx::prettify(processMemoryUsed, BX_COUNTOF(processMemoryUsed), bx::getProcessMemoryUsed() ); -// -// tvm.printf(0, pos++, 0x8f, " Memory: %s (video), %s (system), %s (shared), %s (process) " -// , dedicatedVideo -// , dedicatedSystem -// , sharedSystem -// , processMemoryUsed -// ); - -// DXGI_QUERY_VIDEO_MEMORY_INFO memInfo; -// DX_CHECK(m_adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &memInfo) ); -// -// char budget[16]; -// bx::prettify(budget, BX_COUNTOF(budget), memInfo.Budget); -// -// char currentUsage[16]; -// bx::prettify(currentUsage, BX_COUNTOF(currentUsage), memInfo.CurrentUsage); -// -// char availableForReservation[16]; -// bx::prettify(availableForReservation, BX_COUNTOF(currentUsage), memInfo.AvailableForReservation); -// -// char currentReservation[16]; -// bx::prettify(currentReservation, BX_COUNTOF(currentReservation), memInfo.CurrentReservation); -// -// tvm.printf(0, pos++, 0x8f, " Budget: %s, Usage: %s, AvailRes: %s, CurrRes: %s " -// , budget -// , currentUsage -// , availableForReservation -// , currentReservation -// ); + const VkPhysicalDeviceProperties& pdp = m_deviceProperties; + tvm.printf(0, pos++, 0x8f, " Device: %s (%s)" + , pdp.deviceName + , getName(pdp.deviceType) + ); + + if (0 <= gpuMemoryAvailable && 0 <= gpuMemoryUsed) + { + for (uint32_t ii = 0; ii < m_memoryProperties.memoryHeapCount; ++ii) + { + char budget[16]; + bx::prettify(budget, BX_COUNTOF(budget), dmbp.heapBudget[ii]); + + char usage[16]; + bx::prettify(usage, BX_COUNTOF(usage), dmbp.heapUsage[ii]); + + const bool local = (!!(m_memoryProperties.memoryHeaps[ii].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) ); + + tvm.printf(0, pos++, 0x8f, " Memory %d %s - Budget: %12s, Usage: %12s" + , ii + , local ? "(local) " : "(non-local)" + , budget + , usage + ); + } + } pos = 10; tvm.printf(10, pos++, 0x8b, " Frame: % 7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS " @@ -4504,11 +9129,11 @@ BX_UNUSED(presentMin, presentMax); , double(max)*toMs , freq/frameTime ); -// tvm.printf(10, pos++, 0x8b, " Present: % 7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] " -// , double(m_presentElapsed)*toMs -// , double(presentMin)*toMs -// , double(presentMax)*toMs -// ); + tvm.printf(10, pos++, 0x8b, " Present: % 7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] " + , double(m_presentElapsed)*toMs + , double(presentMin)*toMs + , double(presentMax)*toMs + ); const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d, [%c] MaxAnisotropy " @@ -4536,22 +9161,10 @@ BX_UNUSED(presentMin, presentMax); ); } -// tvm.printf(10, pos++, 0x8b, " Batch: %7dx%d indirect, %7d immediate " -// , m_batch.m_stats.m_numIndirect[BatchD3D12::Draw] -// , m_batch.m_maxDrawPerBatch -// , m_batch.m_stats.m_numImmediate[BatchD3D12::Draw] -// ); - -// tvm.printf(10, pos++, 0x8b, " %7dx%d indirect, %7d immediate " -// , m_batch.m_stats.m_numIndirect[BatchD3D12::DrawIndexed] -// , m_batch.m_maxDrawPerBatch -// , m_batch.m_stats.m_numImmediate[BatchD3D12::DrawIndexed] -// ); - - if (NULL != m_renderDocDll) - { - tvm.printf(tvm.m_width-27, 0, 0x4f, " [F11 - RenderDoc capture] "); - } + if (NULL != m_renderDocDll) + { + tvm.printf(tvm.m_width-27, 0, 0x4f, " [F11 - RenderDoc capture] "); + } tvm.printf(10, pos++, 0x8b, " Indices: %7d ", statsNumIndices); // tvm.printf(10, pos++, 0x8b, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax); @@ -4559,13 +9172,15 @@ BX_UNUSED(presentMin, presentMax); tvm.printf(10, pos++, 0x8b, " DIB size: %7d ", _render->m_iboffset); pos++; - tvm.printf(10, pos++, 0x8b, " State cache: "); - tvm.printf(10, pos++, 0x8b, " PSO | Sampler | Bind | Queued "); - tvm.printf(10, pos++, 0x8b, " %6d " //| %6d | %6d | %6d " + tvm.printf(10, pos++, 0x8b, " Occlusion queries: %3d ", m_occlusionQuery.m_control.available() ); + + pos++; + tvm.printf(10, pos++, 0x8b, " State cache: "); + tvm.printf(10, pos++, 0x8b, " PSO | DSL | DS "); + tvm.printf(10, pos++, 0x8b, " %6d | %6d | %6d " , m_pipelineStateCache.getCount() -// , m_samplerStateCache.getCount() -// , bindLru.getCount() -// , m_cmd.m_control.available() + , m_descriptorSetLayoutCache.getCount() + , descriptorSetCount ); pos++; @@ -4580,41 +9195,49 @@ BX_UNUSED(presentMin, presentMax); min = frameTime; max = frameTime; -// presentMin = m_presentElapsed; -// presentMax = m_presentElapsed; + presentMin = m_presentElapsed; + presentMax = m_presentElapsed; } blit(this, _textVideoMemBlitter, tvm); -// PIX_ENDEVENT(); + BGFX_VK_PROFILER_END(); } else if (_render->m_debug & BGFX_DEBUG_TEXT) { -// PIX_BEGINEVENT(toRgba8(0x40, 0x40, 0x40, 0xff), L"debugtext"); + BGFX_VK_PROFILER_BEGIN_LITERAL("debugtext", kColorFrame); blit(this, _textVideoMemBlitter, _render->m_textVideoMem); -// PIX_ENDEVENT(); + BGFX_VK_PROFILER_END(); } - if (beginRenderPass) + m_presentElapsed = 0; + + scratchBuffer.flush(); + + for (uint16_t ii = 0; ii < m_numWindows; ++ii) { - vkCmdEndRenderPass(m_commandBuffer); - beginRenderPass = false; - } + FrameBufferVK& fb = isValid(m_windows[ii]) + ? m_frameBuffers[m_windows[ii].idx] + : m_backBuffer + ; - setImageMemoryBarrier(m_commandBuffer - , m_backBufferColorImage[m_backBufferColorIdx] - , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL - , VK_IMAGE_LAYOUT_PRESENT_SRC_KHR - ); + if (fb.m_needPresent) + { + fb.resolve(); + + fb.m_swapChain.transitionImage(m_commandBuffer); - VK_CHECK(vkEndCommandBuffer(m_commandBuffer) ); + m_cmd.addWaitSemaphore(fb.m_swapChain.m_lastImageAcquiredSemaphore, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); + m_cmd.addSignalSemaphore(fb.m_swapChain.m_lastImageRenderedSemaphore); + fb.m_swapChain.m_lastImageAcquiredSemaphore = VK_NULL_HANDLE; - kick(renderWait); //, m_presentDone[m_backBufferColorIdx]); - finishAll(); + fb.m_swapChain.m_backBufferFence[fb.m_swapChain.m_backBufferColorIdx] = m_cmd.m_currentFence; + } + } - VK_CHECK(vkResetCommandPool(m_device, m_commandPool, 0) ); + kick(); } } /* namespace vk */ } // namespace bgfx diff --git a/3rdparty/bgfx/src/renderer_vk.h b/3rdparty/bgfx/src/renderer_vk.h index bd7ea608916..1852ed83123 100644 --- a/3rdparty/bgfx/src/renderer_vk.h +++ b/3rdparty/bgfx/src/renderer_vk.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_RENDERER_VK_H_HEADER_GUARD @@ -8,27 +8,39 @@ #if BX_PLATFORM_ANDROID # define VK_USE_PLATFORM_ANDROID_KHR -# define KHR_SURFACE_EXTENSION_NAME VK_KHR_ANDROID_SURFACE_EXTENSION_NAME # define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_ANDROID #elif BX_PLATFORM_LINUX -//# define VK_USE_PLATFORM_MIR_KHR +# define VK_USE_PLATFORM_WAYLAND_KHR # define VK_USE_PLATFORM_XLIB_KHR # define VK_USE_PLATFORM_XCB_KHR -//# define VK_USE_PLATFORM_WAYLAND_KHR -# define KHR_SURFACE_EXTENSION_NAME VK_KHR_XCB_SURFACE_EXTENSION_NAME # define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_LINUX #elif BX_PLATFORM_WINDOWS # define VK_USE_PLATFORM_WIN32_KHR -# define KHR_SURFACE_EXTENSION_NAME VK_KHR_WIN32_SURFACE_EXTENSION_NAME # define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_WINDOWS +#elif BX_PLATFORM_OSX +# define VK_USE_PLATFORM_MACOS_MVK +# define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_MACOS #else -# define KHR_SURFACE_EXTENSION_NAME "" # define VK_IMPORT_INSTANCE_PLATFORM #endif // BX_PLATFORM_* #define VK_NO_STDINT_H #define VK_NO_PROTOTYPES -#include <vulkan/vulkan.h> +#include <vulkan-local/vulkan.h> + +// vulkan.h pulls X11 crap... +#if defined(None) +# undef None +#endif // defined(None) + +#if defined(Success) +# undef Success +#endif // defined(Success) + +#if defined(Status) +# undef Status +#endif // defined(Status) + #include "renderer.h" #include "debug_renderdoc.h" @@ -38,24 +50,32 @@ VK_IMPORT_FUNC(false, vkGetDeviceProcAddr); \ VK_IMPORT_FUNC(false, vkEnumerateInstanceExtensionProperties); \ VK_IMPORT_FUNC(false, vkEnumerateInstanceLayerProperties); \ - -#define VK_IMPORT_INSTANCE_ANDROID \ - VK_IMPORT_INSTANCE_FUNC(true, vkCreateAndroidSurfaceKHR); - -#define VK_IMPORT_INSTANCE_LINUX \ - VK_IMPORT_INSTANCE_FUNC(true, vkCreateXlibSurfaceKHR); \ - VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceXlibPresentationSupportKHR); \ - VK_IMPORT_INSTANCE_FUNC(true, vkCreateXcbSurfaceKHR); \ - VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceXcbPresentationSupportKHR); \ - -// VK_IMPORT_INSTANCE_FUNC(true, vkCreateWaylandSurfaceKHR); -// VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceWaylandPresentationSupportKHR); -// VK_IMPORT_INSTANCE_FUNC(true, vkCreateMirSurfaceKHR); -// VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceMirPresentationSupportKHR); - -#define VK_IMPORT_INSTANCE_WINDOWS \ - VK_IMPORT_INSTANCE_FUNC(true, vkCreateWin32SurfaceKHR); \ - VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceWin32PresentationSupportKHR); + /* 1.1 */ \ + VK_IMPORT_FUNC(true, vkEnumerateInstanceVersion); \ + +#define VK_IMPORT_INSTANCE_ANDROID \ + /* VK_KHR_android_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkCreateAndroidSurfaceKHR); \ + +#define VK_IMPORT_INSTANCE_LINUX \ + /* VK_KHR_wayland_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkCreateWaylandSurfaceKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceWaylandPresentationSupportKHR); \ + /* VK_KHR_xlib_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkCreateXlibSurfaceKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceXlibPresentationSupportKHR); \ + /* VK_KHR_xcb_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkCreateXcbSurfaceKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceXcbPresentationSupportKHR); \ + +#define VK_IMPORT_INSTANCE_WINDOWS \ + /* VK_KHR_win32_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkCreateWin32SurfaceKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceWin32PresentationSupportKHR); \ + +#define VK_IMPORT_INSTANCE_MACOS \ + /* VK_MVK_macos_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkCreateMacOSSurfaceMVK); \ #define VK_IMPORT_INSTANCE \ VK_IMPORT_INSTANCE_FUNC(false, vkDestroyInstance); \ @@ -64,115 +84,133 @@ VK_IMPORT_INSTANCE_FUNC(false, vkEnumerateDeviceLayerProperties); \ VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceProperties); \ VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceFormatProperties); \ + VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceFeatures); \ VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceImageFormatProperties); \ VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceMemoryProperties); \ VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceQueueFamilyProperties); \ - VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfaceCapabilitiesKHR); \ - VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfaceFormatsKHR); \ - VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfacePresentModesKHR); \ - VK_IMPORT_INSTANCE_FUNC(false, vkGetPhysicalDeviceSurfaceSupportKHR); \ VK_IMPORT_INSTANCE_FUNC(false, vkCreateDevice); \ VK_IMPORT_INSTANCE_FUNC(false, vkDestroyDevice); \ - VK_IMPORT_INSTANCE_FUNC(false, vkDestroySurfaceKHR); \ + /* VK_KHR_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfaceCapabilitiesKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfaceFormatsKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfacePresentModesKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceSurfaceSupportKHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkDestroySurfaceKHR); \ + /* VK_KHR_get_physical_device_properties2 */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceFeatures2KHR); \ + VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceMemoryProperties2KHR); \ /* VK_EXT_debug_report */ \ VK_IMPORT_INSTANCE_FUNC(true, vkCreateDebugReportCallbackEXT); \ VK_IMPORT_INSTANCE_FUNC(true, vkDestroyDebugReportCallbackEXT); \ - VK_IMPORT_INSTANCE_FUNC(true, vkDebugReportMessageEXT); \ VK_IMPORT_INSTANCE_PLATFORM -#define VK_IMPORT_DEVICE \ - VK_IMPORT_DEVICE_FUNC(false, vkGetDeviceQueue); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateSwapchainKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroySwapchainKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetSwapchainImagesKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkAcquireNextImageKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkQueuePresentKHR); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateFence); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyFence); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateSemaphore); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroySemaphore); \ - VK_IMPORT_DEVICE_FUNC(false, vkResetFences); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateCommandPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyCommandPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkResetCommandPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkAllocateCommandBuffers); \ - VK_IMPORT_DEVICE_FUNC(false, vkFreeCommandBuffers); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetBufferMemoryRequirements); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetImageMemoryRequirements); \ - VK_IMPORT_DEVICE_FUNC(false, vkAllocateMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkFreeMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateImageView); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyImageView); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateFramebuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyFramebuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateShaderModule); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyShaderModule); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineCache); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineCache); \ - VK_IMPORT_DEVICE_FUNC(false, vkGetPipelineCacheData); \ - VK_IMPORT_DEVICE_FUNC(false, vkMergePipelineCaches); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateGraphicsPipelines); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateComputePipelines); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipeline); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateSampler); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroySampler); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorSetLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorSetLayout); \ - VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkResetDescriptorPool); \ - VK_IMPORT_DEVICE_FUNC(false, vkAllocateDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkFreeDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkUpdateDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkQueueSubmit); \ - VK_IMPORT_DEVICE_FUNC(false, vkQueueWaitIdle); \ - VK_IMPORT_DEVICE_FUNC(false, vkDeviceWaitIdle); \ - VK_IMPORT_DEVICE_FUNC(false, vkWaitForFences); \ - VK_IMPORT_DEVICE_FUNC(false, vkBeginCommandBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkEndCommandBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdPipelineBarrier); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBeginRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdEndRenderPass); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetViewport); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDraw); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexed); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndirect); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexedIndirect); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatch); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatchIndirect); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindPipeline); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetStencilReference); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetBlendConstants); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdSetScissor); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindDescriptorSets); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindIndexBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdBindVertexBuffers); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdUpdateBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdClearColorImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdClearDepthStencilImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdClearAttachments); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdResolveImage); \ - VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyBuffer); \ - VK_IMPORT_DEVICE_FUNC(false, vkMapMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkUnmapMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkFlushMappedMemoryRanges); \ - VK_IMPORT_DEVICE_FUNC(false, vkInvalidateMappedMemoryRanges); \ - VK_IMPORT_DEVICE_FUNC(false, vkBindBufferMemory); \ - VK_IMPORT_DEVICE_FUNC(false, vkBindImageMemory); \ - /* VK_EXT_debug_marker */ \ - VK_IMPORT_DEVICE_FUNC(true, vkDebugMarkerSetObjectTagEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkDebugMarkerSetObjectNameEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerBeginEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerEndEXT); \ - VK_IMPORT_DEVICE_FUNC(true, vkCmdDebugMarkerInsertEXT); \ +#define VK_IMPORT_DEVICE \ + VK_IMPORT_DEVICE_FUNC(false, vkGetDeviceQueue); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateFence); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyFence); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateSemaphore); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroySemaphore); \ + VK_IMPORT_DEVICE_FUNC(false, vkResetFences); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateCommandPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyCommandPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkResetCommandPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkAllocateCommandBuffers); \ + VK_IMPORT_DEVICE_FUNC(false, vkFreeCommandBuffers); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetBufferMemoryRequirements); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetImageMemoryRequirements); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetImageSubresourceLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkAllocateMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkFreeMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateImageView); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyImageView); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateFramebuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyFramebuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateShaderModule); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyShaderModule); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineCache); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineCache); \ + VK_IMPORT_DEVICE_FUNC(false, vkGetPipelineCacheData); \ + VK_IMPORT_DEVICE_FUNC(false, vkMergePipelineCaches); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateGraphicsPipelines); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateComputePipelines); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipeline); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreatePipelineLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyPipelineLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateSampler); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroySampler); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorSetLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorSetLayout); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateDescriptorPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyDescriptorPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkResetDescriptorPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkAllocateDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkFreeDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkUpdateDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkCreateQueryPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkDestroyQueryPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkQueueSubmit); \ + VK_IMPORT_DEVICE_FUNC(false, vkQueueWaitIdle); \ + VK_IMPORT_DEVICE_FUNC(false, vkDeviceWaitIdle); \ + VK_IMPORT_DEVICE_FUNC(false, vkWaitForFences); \ + VK_IMPORT_DEVICE_FUNC(false, vkBeginCommandBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkEndCommandBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdPipelineBarrier); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBeginRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdEndRenderPass); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetViewport); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDraw); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexed); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndirect); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDrawIndexedIndirect); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatch); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdDispatchIndirect); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindPipeline); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetStencilReference); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetBlendConstants); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdSetScissor); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindDescriptorSets); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindIndexBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBindVertexBuffers); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdClearColorImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdClearDepthStencilImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdClearAttachments); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdResolveImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyBufferToImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyImageToBuffer); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBlitImage); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdResetQueryPool); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdWriteTimestamp); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdBeginQuery); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdEndQuery); \ + VK_IMPORT_DEVICE_FUNC(false, vkCmdCopyQueryPoolResults); \ + VK_IMPORT_DEVICE_FUNC(false, vkMapMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkUnmapMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkFlushMappedMemoryRanges); \ + VK_IMPORT_DEVICE_FUNC(false, vkInvalidateMappedMemoryRanges); \ + VK_IMPORT_DEVICE_FUNC(false, vkBindBufferMemory); \ + VK_IMPORT_DEVICE_FUNC(false, vkBindImageMemory); \ + /* VK_KHR_swapchain */ \ + VK_IMPORT_DEVICE_FUNC(true, vkCreateSwapchainKHR); \ + VK_IMPORT_DEVICE_FUNC(true, vkDestroySwapchainKHR); \ + VK_IMPORT_DEVICE_FUNC(true, vkGetSwapchainImagesKHR); \ + VK_IMPORT_DEVICE_FUNC(true, vkAcquireNextImageKHR); \ + VK_IMPORT_DEVICE_FUNC(true, vkQueuePresentKHR); \ + /* VK_EXT_debug_utils */ \ + VK_IMPORT_DEVICE_FUNC(true, vkSetDebugUtilsObjectNameEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdBeginDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdEndDebugUtilsLabelEXT); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdInsertDebugUtilsLabelEXT); \ + /* VK_KHR_draw_indirect_count */ \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdDrawIndirectCountKHR); \ + VK_IMPORT_DEVICE_FUNC(true, vkCmdDrawIndexedIndirectCountKHR); \ #define VK_DESTROY \ VK_DESTROY_FUNC(Buffer); \ @@ -186,7 +224,9 @@ VK_DESTROY_FUNC(Pipeline); \ VK_DESTROY_FUNC(PipelineCache); \ VK_DESTROY_FUNC(PipelineLayout); \ + VK_DESTROY_FUNC(QueryPool); \ VK_DESTROY_FUNC(RenderPass); \ + VK_DESTROY_FUNC(Sampler); \ VK_DESTROY_FUNC(Semaphore); \ VK_DESTROY_FUNC(ShaderModule); \ VK_DESTROY_FUNC(SwapchainKHR); \ @@ -199,41 +239,79 @@ BX_MACRO_BLOCK_END #if BGFX_CONFIG_DEBUG -# define VK_CHECK(_call) _VK_CHECK(BX_CHECK, _call) +# define VK_CHECK(_call) _VK_CHECK(BX_ASSERT, _call) #else # define VK_CHECK(_call) _call #endif // BGFX_CONFIG_DEBUG +#if BGFX_CONFIG_DEBUG_ANNOTATION +# define BGFX_VK_BEGIN_DEBUG_UTILS_LABEL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + VkDebugUtilsLabelEXT dul; \ + dul.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; \ + dul.pNext = NULL; \ + dul.pLabelName = _name; \ + dul.color[0] = ((_abgr >> 24) & 0xff) / 255.0f; \ + dul.color[1] = ((_abgr >> 16) & 0xff) / 255.0f; \ + dul.color[2] = ((_abgr >> 8) & 0xff) / 255.0f; \ + dul.color[3] = ((_abgr >> 0) & 0xff) / 255.0f; \ + vkCmdBeginDebugUtilsLabelEXT(m_commandBuffer, &dul); \ + BX_MACRO_BLOCK_END + +# define BGFX_VK_END_DEBUG_UTILS_LABEL() \ + BX_MACRO_BLOCK_BEGIN \ + vkCmdEndDebugUtilsLabelEXT(m_commandBuffer); \ + BX_MACRO_BLOCK_END +#else +# define BGFX_VK_BEGIN_DEBUG_UTILS_LABEL(_view, _abgr) BX_UNUSED(_view, _abgr) +# define BGFX_VK_END_DEBUG_UTILS_LABEL() BX_NOOP() +#endif // BGFX_CONFIG_DEBUG_ANNOTATION + +#define BGFX_VK_PROFILER_BEGIN(_view, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_VK_BEGIN_DEBUG_UTILS_LABEL(s_viewName[view], _abgr); \ + BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_VK_PROFILER_BEGIN_LITERAL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_VK_BEGIN_DEBUG_UTILS_LABEL(_name, _abgr); \ + BGFX_PROFILER_BEGIN_LITERAL("" _name, _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_VK_PROFILER_END() \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_END(); \ + BGFX_VK_END_DEBUG_UTILS_LABEL(); \ + BX_MACRO_BLOCK_END + namespace bgfx { namespace vk { -#define VK_DESTROY_FUNC(_name) \ - struct Vk##_name \ - { \ - ::Vk##_name vk; \ - Vk##_name() {} \ - Vk##_name(::Vk##_name _vk) : vk(_vk) {} \ - operator ::Vk##_name() { return vk; } \ - operator ::Vk##_name() const { return vk; } \ - ::Vk##_name* operator &() { return &vk; } \ - const ::Vk##_name* operator &() const { return &vk; } \ - }; \ - BX_STATIC_ASSERT(sizeof(::Vk##_name) == sizeof(Vk##_name) ); \ - void vkDestroy(Vk##_name&) +#define VK_DESTROY_FUNC(_name) \ + struct Vk##_name \ + { \ + ::Vk##_name vk; \ + Vk##_name() {} \ + Vk##_name(::Vk##_name _vk) : vk(_vk) {} \ + operator ::Vk##_name() { return vk; } \ + operator ::Vk##_name() const { return vk; } \ + ::Vk##_name* operator &() { return &vk; } \ + const ::Vk##_name* operator &() const { return &vk; } \ + }; \ + BX_STATIC_ASSERT(sizeof(::Vk##_name) == sizeof(Vk##_name) ); \ + void vkDestroy(Vk##_name&); \ + void release(Vk##_name&) VK_DESTROY +VK_DESTROY_FUNC(DeviceMemory); +VK_DESTROY_FUNC(SurfaceKHR); +VK_DESTROY_FUNC(DescriptorSet); #undef VK_DESTROY_FUNC - struct DslBinding + template<typename Ty> + void release(Ty) { - enum Enum - { -// CombinedImageSampler, - UniformBuffer, -// StorageBuffer, - - Count - }; - }; + } template<typename Ty> class StateCacheT @@ -261,7 +339,7 @@ VK_DESTROY typename HashMap::iterator it = m_hashMap.find(_key); if (it != m_hashMap.end() ) { - vkDestroy(it->second); + release(it->second); m_hashMap.erase(it); } } @@ -270,7 +348,7 @@ VK_DESTROY { for (typename HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it) { - vkDestroy(it->second); + release(it->second); } m_hashMap.clear(); @@ -297,36 +375,17 @@ VK_DESTROY { } - void create(uint32_t _size, uint32_t _maxDescriptors); + void create(uint32_t _size, uint32_t _count); void destroy(); - void reset(VkDescriptorBufferInfo& _gpuAddress); - void* allocUbv(VkDescriptorBufferInfo& _gpuAddress, uint32_t _size); + void reset(); + uint32_t write(const void* _data, uint32_t _size); + void flush(); - VkDescriptorSet* m_descriptorSet; VkBuffer m_buffer; VkDeviceMemory m_deviceMem; uint8_t* m_data; uint32_t m_size; uint32_t m_pos; - uint32_t m_currentDs; - uint32_t m_maxDescriptors; - }; - - struct ImageVK - { - ImageVK() - : m_memory(VK_NULL_HANDLE) - , m_image(VK_NULL_HANDLE) - , m_imageView(VK_NULL_HANDLE) - { - } - - VkResult create(VkFormat _format, const VkExtent3D& _extent); - void destroy(); - - VkDeviceMemory m_memory; - VkImage m_image; - VkImageView m_imageView; }; struct BufferVK @@ -340,7 +399,7 @@ VK_DESTROY { } - void create(uint32_t _size, void* _data, uint16_t _flags, bool _vertex, uint32_t _stride = 0); + void create(VkCommandBuffer _commandBuffer, uint32_t _size, void* _data, uint16_t _flags, bool _vertex, uint32_t _stride = 0); void update(VkCommandBuffer _commandBuffer, uint32_t _offset, uint32_t _size, void* _data, bool _discard = false); void destroy(); @@ -353,11 +412,43 @@ VK_DESTROY typedef BufferVK IndexBufferVK; + struct MsaaSamplerVK + { + uint16_t Count; + VkSampleCountFlagBits Sample; + }; + struct VertexBufferVK : public BufferVK { - void create(uint32_t _size, void* _data, VertexDeclHandle _declHandle, uint16_t _flags); + void create(VkCommandBuffer _commandBuffer, uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags); + + VertexLayoutHandle m_layoutHandle; + }; + + struct BindType + { + enum Enum + { + Buffer, + Image, + Sampler, + + Count + }; + }; - VertexDeclHandle m_decl; + struct BindInfo + { + UniformHandle uniformHandle = BGFX_INVALID_HANDLE; + BindType::Enum type; + uint32_t binding; + uint32_t samplerBinding; + uint32_t index; + }; + + struct TextureBindInfo + { + VkImageViewType type; }; struct ShaderVK @@ -369,6 +460,9 @@ VK_DESTROY , m_hash(0) , m_numUniforms(0) , m_numPredefined(0) + , m_uniformBinding(0) + , m_numBindings(0) + , m_oldBindingModel(false) { } @@ -388,6 +482,17 @@ VK_DESTROY uint16_t m_size; uint8_t m_numPredefined; uint8_t m_numAttrs; + + BindInfo m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + + TextureBindInfo m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + uint8_t m_numTextures; + + uint32_t m_uniformBinding; + uint16_t m_numBindings; + VkDescriptorSetLayoutBinding m_bindings[2 * BGFX_CONFIG_MAX_TEXTURE_SAMPLERS + 1]; + + bool m_oldBindingModel; }; struct ProgramVK @@ -395,57 +500,373 @@ VK_DESTROY ProgramVK() : m_vsh(NULL) , m_fsh(NULL) + , m_descriptorSetLayout(VK_NULL_HANDLE) + , m_pipelineLayout(VK_NULL_HANDLE) { } - void create(const ShaderVK* _vsh, const ShaderVK* _fsh) + void create(const ShaderVK* _vsh, const ShaderVK* _fsh); + void destroy(); + + const ShaderVK* m_vsh; + const ShaderVK* m_fsh; + + BindInfo m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + + TextureBindInfo m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + uint8_t m_numTextures; + + PredefinedUniform m_predefined[PredefinedUniform::Count * 2]; + uint8_t m_numPredefined; + + VkDescriptorSetLayout m_descriptorSetLayout; + VkPipelineLayout m_pipelineLayout; + }; + + struct TimerQueryVK + { + TimerQueryVK() + : m_control(BX_COUNTOF(m_query) ) { - BX_CHECK(NULL != _vsh->m_code, "Vertex shader doesn't exist."); - m_vsh = _vsh; - bx::memCopy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined*sizeof(PredefinedUniform)); - m_numPredefined = _vsh->m_numPredefined; + } + + VkResult init(); + void shutdown(); + uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum); + void end(uint32_t _idx); + bool update(); - if (NULL != _fsh) + struct Result + { + void reset() { - BX_CHECK(NULL != _fsh->m_code, "Fragment shader doesn't exist."); - m_fsh = _fsh; - bx::memCopy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined*sizeof(PredefinedUniform)); - m_numPredefined += _fsh->m_numPredefined; + m_begin = 0; + m_end = 0; + m_pending = 0; + m_frameNum = 0; } - } - void destroy() + uint64_t m_begin; + uint64_t m_end; + uint32_t m_pending; + uint32_t m_frameNum; + }; + + struct Query + { + uint32_t m_resultIdx; + uint32_t m_frameNum; + uint64_t m_completed; + bool m_ready; + }; + + uint64_t m_frequency; + + Result m_result[BGFX_CONFIG_MAX_VIEWS+1]; + Query m_query[BGFX_CONFIG_MAX_VIEWS*4]; + + VkBuffer m_readback; + VkDeviceMemory m_readbackMemory; + VkQueryPool m_queryPool; + const uint64_t* m_queryResult; + bx::RingBufferControl m_control; + }; + + struct OcclusionQueryVK + { + OcclusionQueryVK() + : m_control(BX_COUNTOF(m_handle) ) { - m_numPredefined = 0; - m_vsh = NULL; - m_fsh = NULL; } - const ShaderVK* m_vsh; - const ShaderVK* m_fsh; + VkResult init(); + void shutdown(); + void begin(OcclusionQueryHandle _handle); + void end(); + void flush(Frame* _render); + void resolve(Frame* _render); + void invalidate(OcclusionQueryHandle _handle); + + OcclusionQueryHandle m_handle[BGFX_CONFIG_MAX_OCCLUSION_QUERIES]; + + VkBuffer m_readback; + VkDeviceMemory m_readbackMemory; + VkQueryPool m_queryPool; + const uint32_t* m_queryResult; + bx::RingBufferControl m_control; + }; - PredefinedUniform m_predefined[PredefinedUniform::Count * 2]; - uint8_t m_numPredefined; + struct ReadbackVK + { + void create(VkImage _image, uint32_t _width, uint32_t _height, TextureFormat::Enum _format); + void destroy(); + uint32_t pitch(uint8_t _mip = 0) const; + void copyImageToBuffer(VkCommandBuffer _commandBuffer, VkBuffer _buffer, VkImageLayout _layout, VkImageAspectFlags _aspect, uint8_t _mip = 0) const; + void readback(VkDeviceMemory _memory, VkDeviceSize _offset, void* _data, uint8_t _mip = 0) const; + + VkImage m_image; + uint32_t m_width; + uint32_t m_height; + TextureFormat::Enum m_format; }; struct TextureVK { + TextureVK() + : m_directAccessPtr(NULL) + , m_sampler({ 1, VK_SAMPLE_COUNT_1_BIT }) + , m_format(VK_FORMAT_UNDEFINED) + , m_textureImage(VK_NULL_HANDLE) + , m_textureDeviceMem(VK_NULL_HANDLE) + , m_currentImageLayout(VK_IMAGE_LAYOUT_UNDEFINED) + , m_singleMsaaImage(VK_NULL_HANDLE) + , m_singleMsaaDeviceMem(VK_NULL_HANDLE) + , m_currentSingleMsaaImageLayout(VK_IMAGE_LAYOUT_UNDEFINED) + { + } + + void* create(VkCommandBuffer _commandBuffer, const Memory* _mem, uint64_t _flags, uint8_t _skip); + // internal render target + VkResult create(VkCommandBuffer _commandBuffer, uint32_t _width, uint32_t _height, uint64_t _flags, VkFormat _format); + void destroy(); + + void update(VkCommandBuffer _commandBuffer, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem); + void resolve(VkCommandBuffer _commandBuffer, uint8_t _resolve, uint32_t _layer, uint32_t _numLayers, uint32_t _mip); + + void copyBufferToTexture(VkCommandBuffer _commandBuffer, VkBuffer _stagingBuffer, uint32_t _bufferImageCopyCount, VkBufferImageCopy* _bufferImageCopy); + VkImageLayout setImageMemoryBarrier(VkCommandBuffer _commandBuffer, VkImageLayout _newImageLayout, bool _singleMsaaImage = false); + + VkResult createView(uint32_t _layer, uint32_t _numLayers, uint32_t _mip, uint32_t _numMips, VkImageViewType _type, VkImageAspectFlags _aspectMask, bool _renderTarget, ::VkImageView* _view) const; + + void* m_directAccessPtr; + uint64_t m_flags; + uint32_t m_width; + uint32_t m_height; + uint32_t m_depth; + uint32_t m_numLayers; + uint32_t m_numSides; + uint8_t m_requestedFormat; + uint8_t m_textureFormat; + uint8_t m_numMips; + + MsaaSamplerVK m_sampler; + + VkImageViewType m_type; + VkFormat m_format; + VkComponentMapping m_components; + VkImageAspectFlags m_aspectMask; + + VkImage m_textureImage; + VkDeviceMemory m_textureDeviceMem; + VkImageLayout m_currentImageLayout; + + VkImage m_singleMsaaImage; + VkDeviceMemory m_singleMsaaDeviceMem; + VkImageLayout m_currentSingleMsaaImageLayout; + + VkImageLayout m_sampledLayout; + + ReadbackVK m_readback; + + private: + VkResult createImages(VkCommandBuffer _commandBuffer); + static VkImageAspectFlags getAspectMask(VkFormat _format); }; - struct FrameBufferVK + constexpr uint32_t kMaxBackBuffers = bx::max(BGFX_CONFIG_MAX_BACK_BUFFERS, 10); + + struct SwapChainVK { + SwapChainVK() + : m_nwh(NULL) + , m_swapchain(VK_NULL_HANDLE) + , m_lastImageRenderedSemaphore(VK_NULL_HANDLE) + , m_lastImageAcquiredSemaphore(VK_NULL_HANDLE) + , m_backBufferColorMsaaImageView(VK_NULL_HANDLE) + { + } + + VkResult create(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution, TextureFormat::Enum _depthFormat = TextureFormat::Count); + void destroy(); + void update(VkCommandBuffer _commandBuffer, void* _nwh, const Resolution& _resolution); + + VkResult createSurface(); + VkResult createSwapChain(); + VkResult createAttachments(VkCommandBuffer _commandBuffer); + VkResult createFrameBuffer(); + + void releaseSurface(); + void releaseSwapChain(); + void releaseAttachments(); + void releaseFrameBuffer(); + + uint32_t findPresentMode(bool _vsync); + TextureFormat::Enum findSurfaceFormat(TextureFormat::Enum _format, VkColorSpaceKHR _colorSpace, bool _srgb); + + bool acquire(VkCommandBuffer _commandBuffer); + void present(); + + void transitionImage(VkCommandBuffer _commandBuffer); + + VkQueue m_queue; + VkSwapchainCreateInfoKHR m_sci; + + void* m_nwh; + Resolution m_resolution; + + TextureFormat::Enum m_colorFormat; + TextureFormat::Enum m_depthFormat; + + VkSurfaceKHR m_surface; + VkSwapchainKHR m_swapchain; + uint32_t m_numSwapchainImages; + VkImageLayout m_backBufferColorImageLayout[kMaxBackBuffers]; + VkImage m_backBufferColorImage[kMaxBackBuffers]; + VkImageView m_backBufferColorImageView[kMaxBackBuffers]; + VkFramebuffer m_backBufferFrameBuffer[kMaxBackBuffers]; + VkFence m_backBufferFence[kMaxBackBuffers]; + uint32_t m_backBufferColorIdx; + + VkSemaphore m_presentDoneSemaphore[kMaxBackBuffers]; + VkSemaphore m_renderDoneSemaphore[kMaxBackBuffers]; + uint32_t m_currentSemaphore; + + VkSemaphore m_lastImageRenderedSemaphore; + VkSemaphore m_lastImageAcquiredSemaphore; + + bool m_needPresent; + bool m_needToRecreateSwapchain; + bool m_needToRecreateSurface; + + TextureVK m_backBufferDepthStencil; + VkImageView m_backBufferDepthStencilImageView; + + TextureVK m_backBufferColorMsaa; + VkImageView m_backBufferColorMsaaImageView; + MsaaSamplerVK m_sampler; + + bool m_supportsReadback; + bool m_supportsManualResolve; + }; + + struct FrameBufferVK + { + FrameBufferVK() + : m_depth({ kInvalidHandle }) + , m_width(0) + , m_height(0) + , m_denseIdx(kInvalidHandle) + , m_num(0) + , m_numTh(0) + , m_nwh(NULL) + , m_needPresent(false) + , m_framebuffer(VK_NULL_HANDLE) + { + } + + void create(uint8_t _num, const Attachment* _attachment); + VkResult create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format = TextureFormat::Count, TextureFormat::Enum _depthFormat = TextureFormat::Count); + uint16_t destroy(); + + void update(VkCommandBuffer _commandBuffer, const Resolution& _resolution); + + void preReset(); + void postReset(); + + void resolve(); + + bool acquire(VkCommandBuffer _commandBuffer); + void present(); + + bool isRenderable() const; + TextureHandle m_texture[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; TextureHandle m_depth; -// IDXGISwapChain* m_swapChain; uint32_t m_width; uint32_t m_height; uint16_t m_denseIdx; uint8_t m_num; uint8_t m_numTh; Attachment m_attachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + + SwapChainVK m_swapChain; + void* m_nwh; + bool m_needPresent; + bool m_needResolve; + + VkImageView m_textureImageViews[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS]; + VkFramebuffer m_framebuffer; + VkRenderPass m_renderPass; + MsaaSamplerVK m_sampler; + + VkFramebuffer m_currentFramebuffer; + }; + + struct CommandQueueVK + { + VkResult init(uint32_t _queueFamily, VkQueue _queue, uint32_t _numFramesInFlight); + VkResult reset(); + void shutdown(); + + VkResult alloc(VkCommandBuffer* _commandBuffer); + void addWaitSemaphore(VkSemaphore _semaphore, VkPipelineStageFlags _waitFlags = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); + void addSignalSemaphore(VkSemaphore _semaphore); + void kick(bool _wait = false); + void finish(bool _finishAll = false); + + void release(uint64_t _handle, VkObjectType _type); + void consume(); + + uint32_t m_queueFamily; + VkQueue m_queue; + + uint32_t m_numFramesInFlight; + + uint32_t m_currentFrameInFlight; + uint32_t m_consumeIndex; + + VkCommandBuffer m_activeCommandBuffer; + + VkFence m_currentFence; + VkFence m_completedFence; + + uint64_t m_submitted; + + struct CommandList + { + VkCommandPool m_commandPool = VK_NULL_HANDLE; + VkCommandBuffer m_commandBuffer = VK_NULL_HANDLE; + VkFence m_fence = VK_NULL_HANDLE; + }; + + CommandList m_commandList[BGFX_CONFIG_MAX_FRAME_LATENCY]; + + uint32_t m_numWaitSemaphores; + VkSemaphore m_waitSemaphores[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + VkPipelineStageFlags m_waitSemaphoreStages[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + uint32_t m_numSignalSemaphores; + VkSemaphore m_signalSemaphores[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + + struct Resource + { + VkObjectType m_type; + uint64_t m_handle; + }; + + typedef stl::vector<Resource> ResourceArray; + ResourceArray m_release[BGFX_CONFIG_MAX_FRAME_LATENCY]; + + private: + template<typename Ty> + void destroy(uint64_t _handle) + { + typedef decltype(Ty::vk) vk_t; + Ty obj = vk_t(_handle); + vkDestroy(obj); + } }; } /* namespace bgfx */ } // namespace vk diff --git a/3rdparty/bgfx/src/renderer_webgpu.cpp b/3rdparty/bgfx/src/renderer_webgpu.cpp new file mode 100644 index 00000000000..8f747167eee --- /dev/null +++ b/3rdparty/bgfx/src/renderer_webgpu.cpp @@ -0,0 +1,5019 @@ +/* + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#include "bgfx_p.h" + +//#define DAWN_ENABLE_BACKEND_D3D12 +#define DAWN_ENABLE_BACKEND_VULKAN + +#if BGFX_CONFIG_RENDERER_WEBGPU +# include "renderer_webgpu.h" +# include "renderer.h" +# include "debug_renderdoc.h" +# include "emscripten.h" +# include "shader_spirv.h" + +# if BX_PLATFORM_ANDROID +# define VK_USE_PLATFORM_ANDROID_KHR +# elif BX_PLATFORM_LINUX +# define VK_USE_PLATFORM_XLIB_KHR +# define VK_USE_PLATFORM_XCB_KHR +# elif BX_PLATFORM_WINDOWS +# define VK_USE_PLATFORM_WIN32_KHR +# elif BX_PLATFORM_OSX +# define VK_USE_PLATFORM_MACOS_MVK +# endif // BX_PLATFORM_* + +# define VK_NO_STDINT_H +# define VK_NO_PROTOTYPES +# include <vulkan-local/vulkan.h> + +# if BX_PLATFORM_EMSCRIPTEN +# include "emscripten.h" +# include "emscripten/html5_webgpu.h" +# else +# ifdef DAWN_ENABLE_BACKEND_D3D12 +# include <dawn_native/D3D12Backend.h> +# endif // !BX_PLATFORM_EMSCRIPTEN + +# ifdef DAWN_ENABLE_BACKEND_VULKAN +# include <dawn_native/VulkanBackend.h> +# endif // DAWN_ENABLE_BACKEND_VULKAN + +# include <dawn_native/DawnNative.h> +# include <dawn/dawn_wsi.h> +# include <dawn/dawn_proc.h> +# endif // !BX_PLATFORM_EMSCRIPTEN + +namespace bgfx { namespace webgpu +{ + // TODO (hugoam) cleanup + template <class T> + T defaultDescriptor() { return T(); } + + template <> wgpu::BlendComponent defaultDescriptor() { return { wgpu::BlendOperation::Add, wgpu::BlendFactor::One, wgpu::BlendFactor::Zero }; } + template <> wgpu::ColorTargetState defaultDescriptor() { return { NULL, wgpu::TextureFormat::RGBA8Unorm, NULL, wgpu::ColorWriteMask::All }; } + template <> wgpu::StencilFaceState defaultDescriptor() { return { wgpu::CompareFunction::Always, wgpu::StencilOperation::Keep, wgpu::StencilOperation::Keep, wgpu::StencilOperation::Keep }; } + template <> wgpu::VertexState defaultDescriptor() { return { NULL, {}, "main", 0, NULL }; } + template <> wgpu::FragmentState defaultDescriptor() { return { NULL, {}, "main", 0, NULL }; } + template <> wgpu::VertexBufferLayout defaultDescriptor() { return { 0, wgpu::InputStepMode::Vertex, 0, NULL }; } + template <> wgpu::VertexAttribute defaultDescriptor() { return { wgpu::VertexFormat::Float, 0, 0 }; } + template <> wgpu::PrimitiveState defaultDescriptor() { return { NULL, wgpu::PrimitiveTopology::TriangleList, wgpu::IndexFormat::Undefined, wgpu::FrontFace::CCW, wgpu::CullMode::None }; } + template <> wgpu::DepthStencilState defaultDescriptor() { return { NULL, wgpu::TextureFormat::Depth24PlusStencil8, false, wgpu::CompareFunction::Always, defaultDescriptor<wgpu::StencilFaceState>(), defaultDescriptor<wgpu::StencilFaceState>(), 0xff, 0xff }; } + template <> wgpu::PipelineLayoutDescriptor defaultDescriptor() { return { NULL, "", 0, NULL }; } + template <> wgpu::TextureViewDescriptor defaultDescriptor() { return {}; } + + template <> wgpu::RenderPassColorAttachment defaultDescriptor() { return { {}, {}, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, { 0.0f, 0.0f, 0.0f, 0.0f } }; } + template <> wgpu::RenderPassDepthStencilAttachment defaultDescriptor() { return { {}, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, 1.0f, false, wgpu::LoadOp::Clear, wgpu::StoreOp::Store, 0, false }; } + + RenderPassDescriptor::RenderPassDescriptor() + { + depthStencilAttachment = defaultDescriptor<wgpu::RenderPassDepthStencilAttachment>(); + + for(uint32_t i = 0; i < kMaxColorAttachments; ++i) + { + colorAttachments[i] = defaultDescriptor<wgpu::RenderPassColorAttachment>(); + } + + desc = defaultDescriptor<wgpu::RenderPassDescriptor>(); + //desc.colorAttachmentCount = colorAttachmentCount; + desc.colorAttachments = colorAttachments; + desc.colorAttachmentCount = 1; // TODO (hugoam) set it properly everywhere + } + + VertexStateDescriptor::VertexStateDescriptor() + { + for(uint32_t i = 0; i < kMaxVertexInputs; ++i) + { + buffers[i] = defaultDescriptor<wgpu::VertexBufferLayout>(); + } + + for (uint32_t i = 0; i < kMaxVertexAttributes; ++i) + { + attributes[i] = defaultDescriptor<wgpu::VertexAttribute>(); + } + + buffers[0].attributes = &attributes[0]; + //buffers[0].attributeCount = numAttributes; + + desc = defaultDescriptor<wgpu::VertexState>(); + + desc.buffers = buffers; + //desc.vertexBufferCount = numVertexBuffers; + } + + RenderPipelineDescriptor::RenderPipelineDescriptor() + { + //vertex = defaultDescriptor<wgpu::VertexState>(); + fragment = defaultDescriptor<wgpu::FragmentState>(); + depthStencil = defaultDescriptor<wgpu::DepthStencilState>(); + + for(uint32_t i = 0; i < kMaxColorAttachments; ++i) + { + targets[i] = defaultDescriptor<wgpu::ColorTargetState>(); + } + + desc = defaultDescriptor<wgpu::RenderPipelineDescriptor2>(); + + desc.primitive.topology = wgpu::PrimitiveTopology::TriangleList; + desc.multisample.count = 1; + + fragment.targetCount = 1; + fragment.targets = targets; + + //wgpu::VertexStateDescriptor inputState = inputState.descriptor(); + + desc.vertex = defaultDescriptor<wgpu::VertexState>(); + desc.fragment = NULL; + //desc.vertexState = &inputState; + desc.primitive = defaultDescriptor<wgpu::PrimitiveState>(); + desc.depthStencil = NULL; + } + // TODO (hugoam) cleanup (end) + + static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME]; + + inline void setViewType(ViewId _view, const bx::StringView _str) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION || BGFX_CONFIG_PROFILER) ) + { + bx::memCopy(&s_viewName[_view][3], _str.getPtr(), _str.getLength() ); + } + } + + struct PrimInfo + { + wgpu::PrimitiveTopology m_type; + uint32_t m_min; + uint32_t m_div; + uint32_t m_sub; + }; + + static const PrimInfo s_primInfo[] = + { + { wgpu::PrimitiveTopology::TriangleList, 3, 3, 0 }, + { wgpu::PrimitiveTopology::TriangleStrip, 3, 1, 2 }, + { wgpu::PrimitiveTopology::LineList, 2, 2, 0 }, + { wgpu::PrimitiveTopology::LineStrip, 2, 1, 1 }, + { wgpu::PrimitiveTopology::PointList, 1, 1, 0 }, + }; + BX_STATIC_ASSERT(Topology::Count == BX_COUNTOF(s_primInfo) ); + + static const wgpu::VertexFormat s_attribType[][4][2] = + { + { // Uint8 + { wgpu::VertexFormat::Uint8x2, wgpu::VertexFormat::Unorm8x2 }, + { wgpu::VertexFormat::Uint8x2, wgpu::VertexFormat::Unorm8x2 }, + { wgpu::VertexFormat::Uint8x4, wgpu::VertexFormat::Unorm8x4 }, + { wgpu::VertexFormat::Uint8x4, wgpu::VertexFormat::Unorm8x4 }, + }, + { // Uint10 + { wgpu::VertexFormat::Uint16x2, wgpu::VertexFormat::Unorm16x2 }, + { wgpu::VertexFormat::Uint16x2, wgpu::VertexFormat::Unorm16x2 }, + { wgpu::VertexFormat::Uint16x4, wgpu::VertexFormat::Unorm16x4 }, + { wgpu::VertexFormat::Uint16x4, wgpu::VertexFormat::Unorm16x4 }, + }, + { // Int16 + { wgpu::VertexFormat::Sint16x2, wgpu::VertexFormat::Snorm16x2 }, + { wgpu::VertexFormat::Sint16x2, wgpu::VertexFormat::Snorm16x2 }, + { wgpu::VertexFormat::Sint16x4, wgpu::VertexFormat::Snorm16x4 }, + { wgpu::VertexFormat::Sint16x4, wgpu::VertexFormat::Snorm16x4 }, + }, + { // Half + { wgpu::VertexFormat::Float16x2, wgpu::VertexFormat::Float16x2 }, + { wgpu::VertexFormat::Float16x2, wgpu::VertexFormat::Float16x2 }, + { wgpu::VertexFormat::Float16x4, wgpu::VertexFormat::Float16x4 }, + { wgpu::VertexFormat::Float16x4, wgpu::VertexFormat::Float16x4 }, + }, + { // Float + { wgpu::VertexFormat::Float32, wgpu::VertexFormat::Float32 }, + { wgpu::VertexFormat::Float32x2, wgpu::VertexFormat::Float32x2 }, + { wgpu::VertexFormat::Float32x3, wgpu::VertexFormat::Float32x3 }, + { wgpu::VertexFormat::Float32x4, wgpu::VertexFormat::Float32x4 }, + }, + }; + BX_STATIC_ASSERT(AttribType::Count == BX_COUNTOF(s_attribType) ); + + static const wgpu::CullMode s_cullMode[] = + { + wgpu::CullMode::None, + wgpu::CullMode::Front, + wgpu::CullMode::Back, + wgpu::CullMode::None, + }; + + static const wgpu::BlendFactor s_blendFactor[][2] = + { + { wgpu::BlendFactor(0), wgpu::BlendFactor(0) }, // ignored + { wgpu::BlendFactor::Zero, wgpu::BlendFactor::Zero }, // ZERO + { wgpu::BlendFactor::One, wgpu::BlendFactor::One }, // ONE + { wgpu::BlendFactor::SrcColor, wgpu::BlendFactor::SrcAlpha }, // SRC_COLOR + { wgpu::BlendFactor::OneMinusSrcColor, wgpu::BlendFactor::OneMinusSrcAlpha }, // INV_SRC_COLOR + { wgpu::BlendFactor::SrcAlpha, wgpu::BlendFactor::SrcAlpha }, // SRC_ALPHA + { wgpu::BlendFactor::OneMinusSrcAlpha, wgpu::BlendFactor::OneMinusSrcAlpha }, // INV_SRC_ALPHA + { wgpu::BlendFactor::DstAlpha, wgpu::BlendFactor::DstAlpha }, // DST_ALPHA + { wgpu::BlendFactor::OneMinusDstAlpha, wgpu::BlendFactor::OneMinusDstAlpha }, // INV_DST_ALPHA + { wgpu::BlendFactor::DstColor, wgpu::BlendFactor::DstAlpha }, // DST_COLOR + { wgpu::BlendFactor::OneMinusDstColor, wgpu::BlendFactor::OneMinusDstAlpha }, // INV_DST_COLOR + { wgpu::BlendFactor::SrcAlphaSaturated, wgpu::BlendFactor::One }, // SRC_ALPHA_SAT + { wgpu::BlendFactor::BlendColor, wgpu::BlendFactor::BlendColor }, // FACTOR + { wgpu::BlendFactor::OneMinusBlendColor, wgpu::BlendFactor::OneMinusBlendColor }, // INV_FACTOR + }; + + static const wgpu::BlendOperation s_blendEquation[] = + { + wgpu::BlendOperation::Add, + wgpu::BlendOperation::Subtract, + wgpu::BlendOperation::ReverseSubtract, + wgpu::BlendOperation::Min, + wgpu::BlendOperation::Max, + }; + + static const wgpu::CompareFunction s_cmpFunc[] = + { + wgpu::CompareFunction::Always, // ignored + wgpu::CompareFunction::Less, + wgpu::CompareFunction::LessEqual, + wgpu::CompareFunction::Equal, + wgpu::CompareFunction::GreaterEqual, + wgpu::CompareFunction::Greater, + wgpu::CompareFunction::NotEqual, + wgpu::CompareFunction::Never, + wgpu::CompareFunction::Always, + }; + + static const wgpu::StencilOperation s_stencilOp[] = + { + wgpu::StencilOperation::Zero, + wgpu::StencilOperation::Keep, + wgpu::StencilOperation::Replace, + wgpu::StencilOperation::IncrementWrap, + wgpu::StencilOperation::IncrementClamp, + wgpu::StencilOperation::DecrementWrap, + wgpu::StencilOperation::DecrementClamp, + wgpu::StencilOperation::Invert, + }; + + static const wgpu::AddressMode s_textureAddress[] = + { + wgpu::AddressMode::Repeat, + wgpu::AddressMode::MirrorRepeat, + wgpu::AddressMode::ClampToEdge, + wgpu::AddressMode(0), // Border ? ClampToZero ? + }; + + static const wgpu::FilterMode s_textureFilterMinMag[] = + { + wgpu::FilterMode::Linear, + wgpu::FilterMode::Nearest, + wgpu::FilterMode::Linear, + }; + + static const wgpu::FilterMode s_textureFilterMip[] = + { + wgpu::FilterMode::Linear, + wgpu::FilterMode::Nearest, + }; + + struct TextureFormatInfo + { + wgpu::TextureFormat m_fmt; + wgpu::TextureFormat m_fmtSrgb; + }; + + static TextureFormatInfo s_textureFormat[] = + { + { wgpu::TextureFormat::BC1RGBAUnorm, wgpu::TextureFormat::BC1RGBAUnormSrgb }, // BC1 + { wgpu::TextureFormat::BC2RGBAUnorm, wgpu::TextureFormat::BC2RGBAUnormSrgb }, // BC2 + { wgpu::TextureFormat::BC3RGBAUnorm, wgpu::TextureFormat::BC3RGBAUnormSrgb }, // BC3 + { wgpu::TextureFormat::BC4RUnorm, wgpu::TextureFormat::Undefined }, // BC4 // BC4RSnorm ?? + { wgpu::TextureFormat::BC5RGUnorm, wgpu::TextureFormat::Undefined }, // BC5 // BC5RGSnorm ?? + { wgpu::TextureFormat::BC6HRGBUfloat, wgpu::TextureFormat::Undefined }, // BC6H // BC6HRGBSfloat ?? + { wgpu::TextureFormat::BC7RGBAUnorm, wgpu::TextureFormat::BC7RGBAUnormSrgb }, // BC7 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ETC1 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ETC2 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ETC2A + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ETC2A1 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // PTC12 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // PTC14 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // PTC12A + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // PTC14A + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // PTC22 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // PTC24 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ATC + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ATCE + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ATCI + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC4x4 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC5x4 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC5x5 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC6x5 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC6x6 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC8x5 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC8x6 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC8x8 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC10x5 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC10x6 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC10x8 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC10x10 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC12x10 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // ASTC12x12 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // Unknown + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // R1 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // A8 + { wgpu::TextureFormat::R8Unorm, wgpu::TextureFormat::Undefined }, // R8 + { wgpu::TextureFormat::R8Sint, wgpu::TextureFormat::Undefined }, // R8I + { wgpu::TextureFormat::R8Uint, wgpu::TextureFormat::Undefined }, // R8U + { wgpu::TextureFormat::R8Snorm, wgpu::TextureFormat::Undefined }, // R8S + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // R16 + { wgpu::TextureFormat::R16Sint, wgpu::TextureFormat::Undefined }, // R16I + { wgpu::TextureFormat::R16Uint, wgpu::TextureFormat::Undefined }, // R16U + { wgpu::TextureFormat::R16Float, wgpu::TextureFormat::Undefined }, // R16F + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // R16S + { wgpu::TextureFormat::R32Sint, wgpu::TextureFormat::Undefined }, // R32I + { wgpu::TextureFormat::R32Uint, wgpu::TextureFormat::Undefined }, // R32U + { wgpu::TextureFormat::R32Float, wgpu::TextureFormat::Undefined }, // R32F + { wgpu::TextureFormat::RG8Unorm, wgpu::TextureFormat::Undefined }, // RG8 + { wgpu::TextureFormat::RG8Sint, wgpu::TextureFormat::Undefined }, // RG8I + { wgpu::TextureFormat::RG8Uint, wgpu::TextureFormat::Undefined }, // RG8U + { wgpu::TextureFormat::RG8Snorm, wgpu::TextureFormat::Undefined }, // RG8S + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RG16 + { wgpu::TextureFormat::RG16Sint, wgpu::TextureFormat::Undefined }, // RG16I + { wgpu::TextureFormat::RG16Uint, wgpu::TextureFormat::Undefined }, // RG16U + { wgpu::TextureFormat::RG16Float, wgpu::TextureFormat::Undefined }, // RG16F + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RG16S + { wgpu::TextureFormat::RG32Sint, wgpu::TextureFormat::Undefined }, // RG32I + { wgpu::TextureFormat::RG32Uint, wgpu::TextureFormat::Undefined }, // RG32U + { wgpu::TextureFormat::RG32Float, wgpu::TextureFormat::Undefined }, // RG32F + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGB8 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGB8I + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGB8U + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGB8S + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGB9E5F + { wgpu::TextureFormat::BGRA8Unorm, wgpu::TextureFormat::BGRA8UnormSrgb }, // BGRA8 + { wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureFormat::RGBA8UnormSrgb }, // RGBA8 + { wgpu::TextureFormat::RGBA8Sint, wgpu::TextureFormat::Undefined }, // RGBA8I + { wgpu::TextureFormat::RGBA8Uint, wgpu::TextureFormat::Undefined }, // RGBA8U + { wgpu::TextureFormat::RGBA8Snorm, wgpu::TextureFormat::Undefined }, // RGBA8S + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGBA16 + { wgpu::TextureFormat::RGBA16Sint, wgpu::TextureFormat::Undefined }, // RGBA16I + { wgpu::TextureFormat::RGBA16Uint, wgpu::TextureFormat::Undefined }, // RGBA16U + { wgpu::TextureFormat::RGBA16Float, wgpu::TextureFormat::Undefined }, // RGBA16F + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGBA16S + { wgpu::TextureFormat::RGBA32Sint, wgpu::TextureFormat::Undefined }, // RGBA32I + { wgpu::TextureFormat::RGBA32Uint, wgpu::TextureFormat::Undefined }, // RGBA32U + { wgpu::TextureFormat::RGBA32Float, wgpu::TextureFormat::Undefined }, // RGBA32F + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // B5G6R5 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // R5G6B5 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // BGRA4 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGBA4 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // BGR5A1 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // RGB5A1 + { wgpu::TextureFormat::RGB10A2Unorm, wgpu::TextureFormat::Undefined }, // RGB10A2 + { wgpu::TextureFormat::RG11B10Ufloat, wgpu::TextureFormat::Undefined }, // RG11B10F + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // UnknownDepth + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // D16 + { wgpu::TextureFormat::Depth24Plus, wgpu::TextureFormat::Undefined }, // D24 + { wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureFormat::Undefined }, // D24S8 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // D32 + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // D16F + { wgpu::TextureFormat::Undefined, wgpu::TextureFormat::Undefined }, // D24F + { wgpu::TextureFormat::Depth32Float, wgpu::TextureFormat::Undefined }, // D32F + { wgpu::TextureFormat::Stencil8, wgpu::TextureFormat::Undefined }, // D0S8 + }; + BX_STATIC_ASSERT(TextureFormat::Count == BX_COUNTOF(s_textureFormat)); + + int32_t s_msaa[] = + { + 1, + 2, + 4, + 8, + 16, + }; + + struct RendererContextWgpu; + static RendererContextWgpu* s_renderWgpu; + + static bool s_ignoreError = false; + +#if !BX_PLATFORM_EMSCRIPTEN + DawnSwapChainImplementation(*createSwapChain)(wgpu::Device device, void* nwh); + +# if defined(DAWN_ENABLE_BACKEND_D3D12) + DawnSwapChainImplementation CreateSwapChainD3D12(wgpu::Device device, void* nwh) + { + HWND win32Window = (HWND)nwh; + return dawn_native::d3d12::CreateNativeSwapChainImpl(device.Get(), win32Window); + } +# endif // defined(DAWN_ENABLE_BACKEND_D3D12) + +# if defined(DAWN_ENABLE_BACKEND_VULKAN) + DawnSwapChainImplementation CreateSwapChainVulkan(wgpu::Device device, void* nwh) + { + VkInstance instance = dawn_native::vulkan::GetInstance(device.Get()); + + PFN_vkCreateWin32SurfaceKHR vkCreateWin32SurfaceKHR = (PFN_vkCreateWin32SurfaceKHR)dawn_native::vulkan::GetInstanceProcAddr(device.Get(), "vkCreateWin32SurfaceKHR"); + + VkSurfaceKHR surface; +# if BX_PLATFORM_WINDOWS + // Copied from renderer_vk.cpp -> needs refactor + { + VkWin32SurfaceCreateInfoKHR sci; + sci.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; + sci.pNext = NULL; + sci.flags = 0; + sci.hinstance = (HINSTANCE)GetModuleHandle(NULL); + sci.hwnd = (HWND)nwh; + VkResult result = vkCreateWin32SurfaceKHR(instance, &sci, NULL, &surface); + } +# endif // BX_PLATFORM_WINDOWS + return dawn_native::vulkan::CreateNativeSwapChainImpl(device.Get(), surface); + } +# endif // defined(DAWN_ENABLE_BACKEND_VULKAN) + +#endif // !BX_PLATFORM_EMSCRIPTEN + + struct RendererContextWgpu : public RendererContextI + { + RendererContextWgpu() + : m_frameIndex(0) + , m_numWindows(0) + , m_rtMsaa(false) + , m_capture(NULL) + , m_captureSize(0) + { + bx::memSet(&m_windows, 0xff, sizeof(m_windows) ); + } + + ~RendererContextWgpu() + { + } + + bool init(const Init& _init) + { + BX_UNUSED(_init); + BX_TRACE("Init."); + + if (_init.debug + || _init.profile) + { + m_renderDocDll = loadRenderDoc(); + } + + setGraphicsDebuggerPresent(NULL != m_renderDocDll); + + m_fbh.idx = kInvalidHandle; + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); + +#if !BX_PLATFORM_EMSCRIPTEN + // Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on + // their respective platforms, and Vulkan is preferred to OpenGL +# if defined(DAWN_ENABLE_BACKEND_D3D12) + static wgpu::BackendType backendType = wgpu::BackendType::D3D12; +# elif defined(DAWN_ENABLE_BACKEND_METAL) + static wgpu::BackendType backendType = wgpu::BackendType::Metal; +# elif defined(DAWN_ENABLE_BACKEND_OPENGL) + static wgpu::BackendType backendType = wgpu::BackendType::OpenGL; +# elif defined(DAWN_ENABLE_BACKEND_VULKAN) + static wgpu::BackendType backendType = wgpu::BackendType::Vulkan; +# else +# error "Unknown platform." +# endif // defined(DAWN_ENABLE_BACKEND_*) + + if (BX_ENABLED(BGFX_CONFIG_DEBUG)) + { + m_instance.EnableBackendValidation(true); + } + + m_instance.DiscoverDefaultAdapters(); + + dawn_native::Adapter backendAdapter; + std::vector<dawn_native::Adapter> adapters = m_instance.GetAdapters(); + for (dawn_native::Adapter& adapter : adapters) + { + wgpu::AdapterProperties properties; + adapter.GetProperties(&properties); + if (properties.backendType == backendType) + { + backendAdapter = adapter; + break; + } + } + + //BX_ASSERT(adapterIt != adapters.end()); + + dawn_native::DeviceDescriptor desc; +# if defined(DAWN_ENABLE_BACKEND_D3D12) + desc.forceEnabledToggles.push_back("use_dxc"); +# endif + + desc.forceDisabledToggles.push_back("disallow_unsafe_apis"); + + WGPUDevice backendDevice = backendAdapter.CreateDevice(&desc); + DawnProcTable backendProcs = dawn_native::GetProcs(); + + using CreateSwapChain = DawnSwapChainImplementation (*)(wgpu::Device device, void* nwh); + +# if defined(DAWN_ENABLE_BACKEND_D3D12) + createSwapChain = CreateSwapChainD3D12; +# elif defined(DAWN_ENABLE_BACKEND_METAL) + createSwapChain = CreateSwapChainMetal; +# elif defined(DAWN_ENABLE_BACKEND_NULL) + createSwapChain = CreateSwapChainNull; +# elif defined(DAWN_ENABLE_BACKEND_OPENGL) + createSwapChain = CreateSwapChainOpenGL; +# elif defined(DAWN_ENABLE_BACKEND_VULKAN) + createSwapChain = CreateSwapChainVulkan; +# endif // defined(DAWN_ENABLE_BACKEND_*) + + // Choose whether to use the backend procs and devices directly, or set up the wire. + WGPUDevice cDevice = backendDevice; + DawnProcTable procs = backendProcs; + dawnProcSetProcs(&procs); + + m_device = wgpu::Device::Acquire(cDevice); +#else + m_device = wgpu::Device(emscripten_webgpu_get_device()); +#endif // !BX_PLATFORM_EMSCRIPTEN + + auto PrintDeviceError = [](WGPUErrorType errorType, const char* message, void*) { + BX_UNUSED(errorType); + + if (s_ignoreError) + { + BX_TRACE("Device error: %s", message); + } + else + { + BX_ASSERT(false, "Device error: %s", message); + } + + s_ignoreError = false; + }; + + if (!m_device) + { + BX_WARN(!m_device, "Unable to create WebGPU device."); + return false; + } + + m_device.SetUncapturedErrorCallback(PrintDeviceError, NULL); + + bool success = m_mainFrameBuffer.create( + 0 + , g_platformData.nwh + , _init.resolution.width + , _init.resolution.height + , TextureFormat::Unknown + , TextureFormat::UnknownDepth + ); + m_numWindows = 1; + + if (!success) + { + return false; + } + + m_queue = m_device.GetQueue(); + + m_cmd.init(m_queue); + //BGFX_FATAL(NULL != m_cmd.m_commandQueue, Fatal::UnableToInitialize, "Unable to create Metal device."); + + for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_FRAME_LATENCY; ++ii) + { + BX_TRACE("Create scratch buffer %d", ii); + m_scratchBuffers[ii].create(BGFX_CONFIG_MAX_DRAW_CALLS * 128); + m_bindStateCache[ii].create(); // (1024); + } + + for (uint8_t ii = 0; ii < WEBGPU_NUM_UNIFORM_BUFFERS; ++ii) + { + bool mapped = true; // ii == WEBGPU_NUM_UNIFORM_BUFFERS - 1; + m_uniformBuffers[ii].create(BGFX_CONFIG_MAX_DRAW_CALLS * 128, mapped); + } + + g_caps.supported |= (0 + | BGFX_CAPS_ALPHA_TO_COVERAGE + | BGFX_CAPS_BLEND_INDEPENDENT + | BGFX_CAPS_FRAGMENT_DEPTH + | BGFX_CAPS_INDEX32 + | BGFX_CAPS_INSTANCING + // | BGFX_CAPS_OCCLUSION_QUERY + | BGFX_CAPS_SWAP_CHAIN + | BGFX_CAPS_TEXTURE_2D_ARRAY + | BGFX_CAPS_TEXTURE_3D + | BGFX_CAPS_TEXTURE_BLIT + | BGFX_CAPS_TEXTURE_COMPARE_ALL + | BGFX_CAPS_TEXTURE_COMPARE_LEQUAL + | BGFX_CAPS_TEXTURE_READ_BACK + | BGFX_CAPS_VERTEX_ATTRIB_HALF + | BGFX_CAPS_VERTEX_ATTRIB_UINT10 + | BGFX_CAPS_COMPUTE + ); + + g_caps.limits.maxTextureSize = 8192; + g_caps.limits.maxFBAttachments = 4; + g_caps.supported |= BGFX_CAPS_TEXTURE_CUBE_ARRAY; + g_caps.supported |= BGFX_CAPS_DRAW_INDIRECT; + + g_caps.limits.maxTextureLayers = 2048; + g_caps.limits.maxVertexStreams = BGFX_CONFIG_MAX_VERTEX_STREAMS; + // Maximum number of entries in the buffer argument table, per graphics or compute function are 31. + // It is decremented by 1 because 1 entry is used for uniforms. + g_caps.limits.maxComputeBindings = bx::uint32_min(30, BGFX_MAX_COMPUTE_BINDINGS); + + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) + { + uint16_t support = 0; + + support |= wgpu::TextureFormat::Undefined != s_textureFormat[ii].m_fmt + ? BGFX_CAPS_FORMAT_TEXTURE_2D + | BGFX_CAPS_FORMAT_TEXTURE_3D + | BGFX_CAPS_FORMAT_TEXTURE_CUBE + | BGFX_CAPS_FORMAT_TEXTURE_VERTEX + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + support |= wgpu::TextureFormat::Undefined != s_textureFormat[ii].m_fmtSrgb + ? BGFX_CAPS_FORMAT_TEXTURE_2D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_3D_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_CUBE_SRGB + | BGFX_CAPS_FORMAT_TEXTURE_VERTEX + : BGFX_CAPS_FORMAT_TEXTURE_NONE + ; + + if (!bimg::isCompressed(bimg::TextureFormat::Enum(ii) ) ) + { + support |= 0 + | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER + // | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA + ; + } + + g_caps.formats[ii] = support; + } + + g_caps.formats[TextureFormat::A8 ] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); + g_caps.formats[TextureFormat::RG32I ] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); + g_caps.formats[TextureFormat::RG32U ] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); + g_caps.formats[TextureFormat::RGBA32I] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); + g_caps.formats[TextureFormat::RGBA32U] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); + + g_caps.formats[TextureFormat::ETC2 ] = + g_caps.formats[TextureFormat::ETC2A ] = + g_caps.formats[TextureFormat::ETC2A1] = + g_caps.formats[TextureFormat::PTC12 ] = + g_caps.formats[TextureFormat::PTC14 ] = + g_caps.formats[TextureFormat::PTC12A] = + g_caps.formats[TextureFormat::PTC14A] = + g_caps.formats[TextureFormat::B5G6R5] = + g_caps.formats[TextureFormat::R5G6B5] = + g_caps.formats[TextureFormat::BGRA4 ] = + g_caps.formats[TextureFormat::RGBA4 ] = + g_caps.formats[TextureFormat::BGR5A1] = + g_caps.formats[TextureFormat::RGB5A1] = BGFX_CAPS_FORMAT_TEXTURE_NONE; + + g_caps.formats[TextureFormat::RGB9E5F] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); + g_caps.formats[TextureFormat::RG11B10F] &= ~(BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER | BGFX_CAPS_FORMAT_TEXTURE_FRAMEBUFFER_MSAA); + + // disable compressed formats + for (uint32_t ii = 0; ii < TextureFormat::Unknown; ++ii) + { + s_textureFormat[ii].m_fmt = wgpu::TextureFormat::Undefined; + } + + for (uint32_t ii = 0; ii < TextureFormat::Count; ++ii) + { + if (BGFX_CAPS_FORMAT_TEXTURE_NONE == g_caps.formats[ii]) + { + s_textureFormat[ii].m_fmt = wgpu::TextureFormat::Undefined; + s_textureFormat[ii].m_fmtSrgb = wgpu::TextureFormat::Undefined; + } + } + + for (uint32_t ii = 1, last = 0; ii < BX_COUNTOF(s_msaa); ++ii) + { + // TODO (hugoam) + //const int32_t sampleCount = 1; //1<<ii; + //if (m_device.supportsTextureSampleCount(sampleCount) ) + //{ + // s_msaa[ii] = sampleCount; + // last = ii; + //} + //else + { + s_msaa[ii] = s_msaa[last]; + } + } + + // 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); + } + + m_gpuTimer.init(); + + g_internalData.context = &m_device; + + return true; + } + + void shutdown() + { + m_gpuTimer.shutdown(); + + m_pipelineStateCache.invalidate(); + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_shaders); ++ii) + { + m_shaders[ii].destroy(); + } + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii) + { + m_textures[ii].destroy(); + } + + captureFinish(); + + m_mainFrameBuffer.destroy(); + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_scratchBuffers); ++ii) + { + m_scratchBuffers[ii].destroy(); + } + + m_cmd.shutdown(); + } + + RendererType::Enum getRendererType() const override + { + return RendererType::WebGPU; + } + + const char* getRendererName() const override + { + return BGFX_RENDERER_WEBGPU_NAME; + } + + void createIndexBuffer(IndexBufferHandle _handle, const Memory* _mem, uint16_t _flags) override + { + m_indexBuffers[_handle.idx].create(_mem->size, _mem->data, _flags); + } + + void destroyIndexBuffer(IndexBufferHandle _handle) override + { + m_indexBuffers[_handle.idx].destroy(); + } + + void createVertexLayout(VertexLayoutHandle _handle, const VertexLayout& _decl) override + { + VertexLayout& decl = m_vertexDecls[_handle.idx]; + bx::memCopy(&decl, &_decl, sizeof(VertexLayout) ); + dump(decl); + } + + void destroyVertexLayout(VertexLayoutHandle /*_handle*/) override + { + } + + void createVertexBuffer(VertexBufferHandle _handle, const Memory* _mem, VertexLayoutHandle _declHandle, uint16_t _flags) override + { + m_vertexBuffers[_handle.idx].create(_mem->size, _mem->data, _declHandle, _flags); + } + + void destroyVertexBuffer(VertexBufferHandle _handle) override + { + m_vertexBuffers[_handle.idx].destroy(); + } + + void createDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _size, uint16_t _flags) override + { + m_indexBuffers[_handle.idx].create(_size, NULL, _flags); + } + + void updateDynamicIndexBuffer(IndexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override + { + m_indexBuffers[_handle.idx].update(_offset, bx::uint32_min(_size, _mem->size), _mem->data); + } + + void destroyDynamicIndexBuffer(IndexBufferHandle _handle) override + { + m_indexBuffers[_handle.idx].destroy(); + } + + void createDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _size, uint16_t _flags) override + { + VertexLayoutHandle decl = BGFX_INVALID_HANDLE; + m_vertexBuffers[_handle.idx].create(_size, NULL, decl, _flags); + } + + void updateDynamicVertexBuffer(VertexBufferHandle _handle, uint32_t _offset, uint32_t _size, const Memory* _mem) override + { + m_vertexBuffers[_handle.idx].update(_offset, bx::uint32_min(_size, _mem->size), _mem->data); + } + + void destroyDynamicVertexBuffer(VertexBufferHandle _handle) override + { + m_vertexBuffers[_handle.idx].destroy(); + } + + void createShader(ShaderHandle _handle, const Memory* _mem) override + { + m_shaders[_handle.idx].create(_handle, _mem); + } + + void destroyShader(ShaderHandle _handle) override + { + m_shaders[_handle.idx].destroy(); + } + + void createProgram(ProgramHandle _handle, ShaderHandle _vsh, ShaderHandle _fsh) override + { + m_program[_handle.idx].create(&m_shaders[_vsh.idx], isValid(_fsh) ? &m_shaders[_fsh.idx] : NULL); + } + + void destroyProgram(ProgramHandle _handle) override + { + m_program[_handle.idx].destroy(); + } + + void* createTexture(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) override + { + m_textures[_handle.idx].create(_handle, _mem, _flags, _skip); + return NULL; + } + + void updateTextureBegin(TextureHandle /*_handle*/, uint8_t /*_side*/, uint8_t /*_mip*/) override + { + } + + void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) override + { + m_textures[_handle.idx].update(_side, _mip, _rect, _z, _depth, _pitch, _mem); + } + + void updateTextureEnd() override + { + } + + void readback(ReadbackWgpu& readback, const TextureWgpu& texture, void* _data) + { + m_cmd.kick(false, true); + m_cmd.beginRender(); + + if (readback.m_mapped) + return; + + BX_ASSERT(readback.m_mip<texture.m_numMips,"Invalid mip: %d num mips:", readback.m_mip,texture.m_numMips); + + uint32_t srcWidth = bx::uint32_max(1, texture.m_width >> readback.m_mip); + uint32_t srcHeight = bx::uint32_max(1, texture.m_height >> readback.m_mip); + + const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(texture.m_textureFormat)); + const uint32_t pitch = srcWidth * bpp / 8; + + const uint32_t dstpitch = bx::strideAlign(pitch, kMinBufferOffsetAlignment); + const uint32_t size = dstpitch * srcHeight; + + // TODO move inside ReadbackWgpu::create + if (!readback.m_buffer) + { + wgpu::BufferDescriptor desc; + desc.size = size; + desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::MapRead; + + readback.m_buffer = m_device.CreateBuffer(&desc); + } + + wgpu::ImageCopyTexture imageCopyTexture; + imageCopyTexture.texture = texture.m_ptr; + imageCopyTexture.origin = { 0, 0, 0 }; + + wgpu::ImageCopyBuffer imageCopyBuffer; + imageCopyBuffer.buffer = readback.m_buffer; + imageCopyBuffer.layout.bytesPerRow = dstpitch; + imageCopyBuffer.layout.rowsPerImage = srcHeight; + + wgpu::Extent3D extent3D = { srcWidth, srcHeight, 1 }; + getBlitCommandEncoder().CopyTextureToBuffer(&imageCopyTexture, &imageCopyBuffer, &extent3D); + + auto finish = [](WGPUBufferMapAsyncStatus status, void* userdata) + { + ReadbackWgpu* readback = static_cast<ReadbackWgpu*>(userdata); + void const* data = readback->m_buffer.GetConstMappedRange(); + if(status == WGPUBufferMapAsyncStatus_Success) + readback->readback(data); + }; + + m_cmd.finish(); + + m_cmd.kick(true); + + readback.m_mapped = true; + readback.m_data = _data; + readback.m_size = pitch * srcHeight; + + readback.m_buffer.MapAsync(wgpu::MapMode::Read, 0, size, finish, &readback); + } + + void readTexture(TextureHandle _handle, void* _data, uint8_t _mip) override + { + TextureWgpu& texture = m_textures[_handle.idx]; + + readback(texture.m_readback, texture, _data); + } + + void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips, uint16_t _numLayers) override + { + TextureWgpu& texture = m_textures[_handle.idx]; + + uint32_t size = sizeof(uint32_t) + sizeof(TextureCreate); + const Memory* mem = alloc(size); + + bx::StaticMemoryBlockWriter writer(mem->data, mem->size); + uint32_t magic = BGFX_CHUNK_MAGIC_TEX; + bx::write(&writer, magic); + + TextureCreate tc; + tc.m_width = _width; + tc.m_height = _height; + tc.m_depth = 0; + tc.m_numLayers = _numLayers; + tc.m_numMips = _numMips; + tc.m_format = TextureFormat::Enum(texture.m_requestedFormat); + tc.m_cubeMap = false; + tc.m_mem = NULL; + bx::write(&writer, tc); + + texture.destroy(); + texture.create(_handle, mem, texture.m_flags, 0); + + release(mem); + } + + void overrideInternal(TextureHandle _handle, uintptr_t _ptr) override + { + BX_UNUSED(_handle, _ptr); + } + + uintptr_t getInternal(TextureHandle _handle) override + { + BX_UNUSED(_handle); + return 0; + } + + void destroyTexture(TextureHandle _handle) override + { + m_textures[_handle.idx].destroy(); + } + + void createFrameBuffer(FrameBufferHandle _handle, uint8_t _num, const Attachment* _attachment) override + { + m_frameBuffers[_handle.idx].create(_num, _attachment); + } + + void createFrameBuffer(FrameBufferHandle _handle, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) override + { + for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) + { + FrameBufferHandle handle = m_windows[ii]; + if (isValid(handle) + && m_frameBuffers[handle.idx].m_nwh == _nwh) + { + destroyFrameBuffer(handle); + } + } + + uint16_t denseIdx = m_numWindows++; + m_windows[denseIdx] = _handle; + + FrameBufferWgpu& fb = m_frameBuffers[_handle.idx]; + fb.create(denseIdx, _nwh, _width, _height, _format, _depthFormat); + fb.m_swapChain->resize(m_frameBuffers[_handle.idx], _width, _height, 0); + } + + void destroyFrameBuffer(FrameBufferHandle _handle) override + { + uint16_t denseIdx = m_frameBuffers[_handle.idx].destroy(); + + if (UINT16_MAX != denseIdx) + { + --m_numWindows; + + if (m_numWindows > 1) + { + FrameBufferHandle handle = m_windows[m_numWindows]; + m_windows[m_numWindows] = {kInvalidHandle}; + + if (m_numWindows != denseIdx) + { + m_windows[denseIdx] = handle; + m_frameBuffers[handle.idx].m_denseIdx = denseIdx; + } + } + } + } + + void createUniform(UniformHandle _handle, UniformType::Enum _type, uint16_t _num, const char* _name) override + { + if (NULL != m_uniforms[_handle.idx]) + { + BX_FREE(g_allocator, m_uniforms[_handle.idx]); + } + + uint32_t size = bx::alignUp(g_uniformTypeSize[_type]*_num, 16); + void* data = BX_ALLOC(g_allocator, size); + bx::memSet(data, 0, size); + m_uniforms[_handle.idx] = data; + m_uniformReg.add(_handle, _name); + } + + void destroyUniform(UniformHandle _handle) override + { + BX_FREE(g_allocator, m_uniforms[_handle.idx]); + m_uniforms[_handle.idx] = NULL; + m_uniformReg.remove(_handle); + } + + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) override + { + BX_UNUSED(_handle); BX_UNUSED(_filePath); + } + + void updateViewName(ViewId _id, const char* _name) override + { + bx::strCopy( + &s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED] + , BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED + , _name + ); + } + + void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) override + { + bx::memCopy(m_uniforms[_loc], _data, _size); + } + + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) override + { + BX_UNUSED(_handle); + } + + void setMarker(const char* _marker, uint16_t _len) override + { + BX_UNUSED(_len); + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + m_renderEncoder.InsertDebugMarker(_marker); + } + } + + virtual void setName(Handle _handle, const char* _name, uint16_t _len) override + { + BX_UNUSED(_handle); BX_UNUSED(_name); BX_UNUSED(_len); + BX_UNUSED(_len); + + switch (_handle.type) + { + case Handle::IndexBuffer: + m_indexBuffers[_handle.idx].m_label.clear(); + m_indexBuffers[_handle.idx].m_label.append(_name); + break; + + case Handle::Shader: + m_shaders[_handle.idx].m_label.clear(); + m_shaders[_handle.idx].m_label.append(_name); + break; + + case Handle::Texture: + m_textures[_handle.idx].m_label.clear(); + m_textures[_handle.idx].m_label.append(_name); + break; + + case Handle::VertexBuffer: + m_vertexBuffers[_handle.idx].m_label.clear(); + m_vertexBuffers[_handle.idx].m_label.append(_name); + break; + + default: + BX_ASSERT(false, "Invalid handle type?! %d", _handle.type); + break; + } + } + + void submitBlit(BlitState& _bs, uint16_t _view); + + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) override; + + void blitSetup(TextVideoMemBlitter& _blitter) override + { + BX_UNUSED(_blitter); + } + + void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) override + { + const uint32_t numVertices = _numIndices*4/6; + if (0 < numVertices) + { + m_indexBuffers [_blitter.m_ib->handle.idx].update( + 0 + , bx::strideAlign(_numIndices*2, 4) + , _blitter.m_ib->data + , true + ); + m_vertexBuffers[_blitter.m_vb->handle.idx].update( + 0 + , numVertices*_blitter.m_layout.m_stride + , _blitter.m_vb->data + , true + ); + + endEncoding(); + + uint32_t width = m_resolution.width; + uint32_t height = m_resolution.height; + + FrameBufferHandle fbh = BGFX_INVALID_HANDLE; + + uint64_t state = 0 + | BGFX_STATE_WRITE_RGB + | BGFX_STATE_WRITE_A + | BGFX_STATE_DEPTH_TEST_ALWAYS + ; + + PipelineStateWgpu* pso = getPipelineState( + state + , 0 + , 0 + , fbh + , _blitter.m_vb->layoutHandle + , false + , _blitter.m_program + , 0 + ); + + RenderPassDescriptor renderPassDescriptor; + wgpu::RenderPassColorAttachment& color = renderPassDescriptor.colorAttachments[0]; + + setFrameBuffer(renderPassDescriptor, fbh); + + color.loadOp = wgpu::LoadOp::Load; + color.storeOp = wgpu::StoreOp::Store; + // NULL != renderPassDescriptor.colorAttachments[0].resolveTexture + // ? wgpu::StoreOp::MultisampleResolve + // : wgpu::StoreOp::Store + //; + + wgpu::RenderPassEncoder rce = m_cmd.m_renderEncoder.BeginRenderPass(&renderPassDescriptor.desc); + m_renderEncoder = rce; + + rce.SetViewport(0.0f, 0.0f, (float)width, (float)height, 0.0f, 1.0f); + rce.SetScissorRect(0.0f, 0.0f, (float)width, (float)height); + + rce.SetPipeline(pso->m_rps); + + ProgramWgpu& program = m_program[_blitter.m_program.idx]; + + ScratchBufferWgpu& scratchBuffer = m_scratchBuffers[0]; + BindStateCacheWgpu& bindStates = m_bindStateCache[0]; + + float proj[16]; + bx::mtxOrtho(proj, 0.0f, (float)width, (float)height, 0.0f, 0.0f, 1000.0f, 0.0f, false); + + PredefinedUniform& predefined = program.m_predefined[0]; + uint8_t flags = predefined.m_type; + setShaderUniform(flags, predefined.m_loc, proj, 4); + + BX_ASSERT(program.m_vsh->m_size > 0, "Not supposed to happen"); + const uint32_t voffset = scratchBuffer.write(m_vsScratch, program.m_vsh->m_gpuSize); + + const uint32_t fsize = (NULL != program.m_fsh ? program.m_fsh->m_gpuSize : 0); + BX_ASSERT(fsize == 0, "Not supposed to happen"); + + TextureWgpu& texture = m_textures[_blitter.m_texture.idx]; + + BindingsWgpu b; + + BindStateWgpu& bindState = allocBindState(program, bindStates, b, scratchBuffer); + + wgpu::BindGroupEntry& textureEntry = b.m_entries[b.numEntries++]; + textureEntry.binding = program.m_textures[0].binding; + textureEntry.textureView = texture.m_ptr.CreateView(); + + wgpu::BindGroupEntry& samplerEntry = b.m_entries[b.numEntries++]; + samplerEntry.binding = program.m_samplers[0].binding; + samplerEntry.sampler = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & state) + ? getSamplerState(state) + : texture.m_sampler; + + bindGroups(program, bindState, b); + + uint32_t numOffset = 1; + uint32_t offsets[1] = { voffset }; + + bindProgram(rce, program, bindState, numOffset, offsets); + + VertexBufferWgpu& vb = m_vertexBuffers[_blitter.m_vb->handle.idx]; + rce.SetVertexBuffer(0, vb.m_ptr); + + IndexBufferWgpu& ib = m_indexBuffers[_blitter.m_ib->handle.idx]; + rce.SetIndexBuffer(ib.m_ptr, ib.m_format); + rce.DrawIndexed(_numIndices, 1, 0, 0, 0); + } + } + + bool isDeviceRemoved() override + { + return false; + } + + void flip() override + { + for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) + { + FrameBufferWgpu& frameBuffer = ii == 0 ? m_mainFrameBuffer : m_frameBuffers[m_windows[ii].idx]; + if (NULL != frameBuffer.m_swapChain) + //&& frameBuffer.m_swapChain->m_drawable) + { + SwapChainWgpu& swapChain = *frameBuffer.m_swapChain; + swapChain.flip(); + } + } + + m_cmd.m_stagingEncoder = NULL; + m_cmd.m_renderEncoder = NULL; + } + + void updateResolution(const Resolution& _resolution) + { + m_resolution = _resolution; + return; // TODO (hugoam) + + m_mainFrameBuffer.m_swapChain->m_maxAnisotropy = !!(_resolution.reset & BGFX_RESET_MAXANISOTROPY) + ? 16 + : 1 + ; + + const uint32_t maskFlags = ~(0 + | BGFX_RESET_MAXANISOTROPY + | BGFX_RESET_DEPTH_CLAMP + | BGFX_RESET_SUSPEND + ); + + if (m_resolution.width != _resolution.width + || m_resolution.height != _resolution.height + || (m_resolution.reset&maskFlags) != (_resolution.reset&maskFlags) ) + { + wgpu::TextureFormat prevMetalLayerPixelFormat; // = m_mainFrameBuffer.m_swapChain->m_metalLayer.pixelFormat; + BX_UNUSED(prevMetalLayerPixelFormat); + + m_resolution = _resolution; + m_resolution.reset &= ~BGFX_RESET_INTERNAL_FORCE; + + m_mainFrameBuffer.m_swapChain->resize(m_mainFrameBuffer, _resolution.width, _resolution.height, _resolution.reset); + + for (uint32_t ii = 0; ii < BX_COUNTOF(m_frameBuffers); ++ii) + { + m_frameBuffers[ii].postReset(); + } + + updateCapture(); + + m_textVideoMem.resize(false, _resolution.width, _resolution.height); + m_textVideoMem.clear(); + + //if (prevMetalLayerPixelFormat != m_mainFrameBuffer.m_swapChain->m_metalLayer.pixelFormat) + { + //MTL_RELEASE(m_screenshotBlitRenderPipelineState) + //reset(m_renderPipelineDescriptor); + + //m_renderPipelineDescriptor.colorAttachments[0].pixelFormat = m_mainFrameBuffer.m_swapChain->m_metalLayer.pixelFormat; + //m_renderPipelineDescriptor.vertexFunction = m_screenshotBlitProgram.m_vsh->m_function; + //m_renderPipelineDescriptor.fragmentFunction = m_screenshotBlitProgram.m_fsh->m_function; + //m_screenshotBlitRenderPipelineState = m_device.newRenderPipelineStateWithDescriptor(m_renderPipelineDescriptor); + } + } + } + + void invalidateCompute() + { + if (m_computeEncoder) + { + m_computeEncoder.EndPass(); + m_computeEncoder = NULL; + } + } + + void updateCapture() + { + } + + void capture() + { + } + + void captureFinish() + { + } + + BindStateWgpu& allocBindState(const ProgramWgpu& program, BindStateCacheWgpu& bindStates, BindingsWgpu& bindings, ScratchBufferWgpu& scratchBuffer) + { + BindStateWgpu& bindState = bindStates.m_bindStates[bindStates.m_currentBindState]; + bindStates.m_currentBindState++; + + bindState.numOffset = program.m_numUniforms; + + // first two bindings are always uniform buffer (vertex/fragment) + if (0 < program.m_vsh->m_gpuSize) + { + bindings.m_entries[0].binding = kSpirvVertexBinding; + bindings.m_entries[0].offset = 0; + bindings.m_entries[0].size = program.m_vsh->m_gpuSize; + bindings.m_entries[0].buffer = scratchBuffer.m_buffer; + bindings.numEntries++; + } + + if (NULL != program.m_fsh + && 0 < program.m_fsh->m_gpuSize) + { + bindings.m_entries[1].binding = kSpirvFragmentBinding; + bindings.m_entries[1].offset = 0; + bindings.m_entries[1].size = program.m_fsh->m_gpuSize; + bindings.m_entries[1].buffer = scratchBuffer.m_buffer; + bindings.numEntries++; + } + + return bindState; + } + + void bindGroups(const ProgramWgpu& program, BindStateWgpu& bindState, BindingsWgpu& bindings) + { + wgpu::BindGroupDescriptor bindGroupDesc; + bindGroupDesc.layout = program.m_bindGroupLayout; + bindGroupDesc.entryCount = bindings.numEntries; + bindGroupDesc.entries = bindings.m_entries; + + bindState.m_bindGroup = m_device.CreateBindGroup(&bindGroupDesc); + } + + template <class Encoder> + void bindProgram(Encoder& encoder, const ProgramWgpu& program, BindStateWgpu& bindState, uint32_t numOffset, uint32_t* offsets) + { + BX_ASSERT(bindState.numOffset == numOffset, "We're obviously doing something wrong"); + encoder.SetBindGroup(0, bindState.m_bindGroup, numOffset, offsets); + } + + BindStateWgpu& allocAndFillBindState(const ProgramWgpu& program, BindStateCacheWgpu& bindStates, ScratchBufferWgpu& scratchBuffer, const RenderBind& renderBind) + { + BindingsWgpu b; + + BindStateWgpu& bindState = allocBindState(program, bindStates, b, scratchBuffer); + + for (uint8_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) + { + const Binding& bind = renderBind.m_bind[stage]; + const BindInfo& bindInfo = program.m_bindInfo[stage]; + + bool isUsed = isValid(program.m_bindInfo[stage].m_uniform); + + BX_ASSERT(!isUsed || kInvalidHandle != bind.m_idx, "All expected bindings must be bound with WebGPU"); + + if (kInvalidHandle != bind.m_idx) + { + switch (bind.m_type) + { + case Binding::Image: + { + TextureWgpu& texture = m_textures[bind.m_idx]; + wgpu::BindGroupEntry& entry = b.m_entries[b.numEntries++]; + entry.binding = bindInfo.m_binding; + entry.textureView = texture.getTextureMipLevel(bind.m_mip); + + if (Access::Read == bind.m_access) + { + wgpu::BindGroupEntry& samplerEntry = b.m_entries[b.numEntries++]; + samplerEntry.binding = bindInfo.m_binding + 16; + samplerEntry.sampler = texture.m_sampler; + } + } + break; + + case Binding::Texture: + { + // apparently bgfx allows to set a texture to a stage that a program does not even use + if (isUsed) + { + TextureWgpu& texture = m_textures[bind.m_idx]; + uint32_t flags = bind.m_samplerFlags; + + wgpu::TextureViewDescriptor viewDesc = defaultDescriptor<wgpu::TextureViewDescriptor>(); + viewDesc.dimension = program.m_textures[bindInfo.m_index].texture.viewDimension; + + wgpu::BindGroupEntry& textureEntry = b.m_entries[b.numEntries++]; + textureEntry.binding = bindInfo.m_binding; + //textureEntry.textureView = texture.m_ptr.CreateView(); + textureEntry.textureView = texture.m_ptr.CreateView(&viewDesc); + + wgpu::BindGroupEntry& samplerEntry = b.m_entries[b.numEntries++]; + samplerEntry.binding = bindInfo.m_binding + kSpirvSamplerShift; + samplerEntry.sampler = 0 == (BGFX_SAMPLER_INTERNAL_DEFAULT & flags) + ? getSamplerState(flags) + : texture.m_sampler; + } + } + break; + + case Binding::IndexBuffer: + case Binding::VertexBuffer: + { + const BufferWgpu& buffer = Binding::IndexBuffer == bind.m_type + ? (const BufferWgpu&) m_indexBuffers[bind.m_idx] + : (const BufferWgpu&) m_vertexBuffers[bind.m_idx] + ; + + wgpu::BindGroupEntry& entry = b.m_entries[b.numEntries++]; + entry.binding = bindInfo.m_binding; + entry.offset = 0; + entry.size = buffer.m_size; + entry.buffer = buffer.m_ptr; + } + break; + } + } + } + + bindGroups(program, bindState, b); + + return bindState; + }; + + void setShaderUniform(uint8_t _flags, uint32_t _regIndex, const void* _val, uint32_t _numRegs) + { + if(_flags&kUniformFragmentBit) + { + bx::memCopy(&m_fsScratch[_regIndex], _val, _numRegs * 16); + } + else + { + bx::memCopy(&m_vsScratch[_regIndex], _val, _numRegs * 16); + } + } + + void setShaderUniform4f(uint8_t _flags, uint32_t _loc, const void* _val, uint32_t _numRegs) + { + setShaderUniform(_flags, _loc, _val, _numRegs); + } + + void setShaderUniform4x4f(uint8_t _flags, uint32_t _loc, const void* _val, uint32_t _numRegs) + { + setShaderUniform(_flags, _loc, _val, _numRegs); + } + + void commit(UniformBuffer& _uniformBuffer) + { + _uniformBuffer.reset(); + + for (;;) + { + uint32_t opcode = _uniformBuffer.read(); + + if (UniformType::End == opcode) + { + break; + } + + UniformType::Enum type; + uint16_t loc; + uint16_t num; + uint16_t copy; + UniformBuffer::decodeOpcode(opcode, type, loc, num, copy); + + const char* data; + if (copy) + { + data = _uniformBuffer.read(g_uniformTypeSize[type]*num); + } + else + { + UniformHandle handle; + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + data = (const char*)m_uniforms[handle.idx]; + } + + switch ( (uint32_t)type) + { + case UniformType::Mat3: + case UniformType::Mat3|kUniformFragmentBit: + { + float* value = (float*)data; + for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3*16, value += 9) + { + Matrix4 mtx; + mtx.un.val[ 0] = value[0]; + mtx.un.val[ 1] = value[1]; + mtx.un.val[ 2] = value[2]; + mtx.un.val[ 3] = 0.0f; + mtx.un.val[ 4] = value[3]; + mtx.un.val[ 5] = value[4]; + mtx.un.val[ 6] = value[5]; + mtx.un.val[ 7] = 0.0f; + mtx.un.val[ 8] = value[6]; + mtx.un.val[ 9] = value[7]; + mtx.un.val[10] = value[8]; + mtx.un.val[11] = 0.0f; + setShaderUniform(uint8_t(type), loc, &mtx.un.val[0], 3); + } + } + break; + + case UniformType::Sampler: + case UniformType::Sampler | kUniformFragmentBit: + case UniformType::Vec4: + case UniformType::Vec4 | kUniformFragmentBit: + case UniformType::Mat4: + case UniformType::Mat4 | kUniformFragmentBit: + { + setShaderUniform(uint8_t(type), loc, data, num); + } + break; + case UniformType::End: + break; + + default: + BX_TRACE("%4d: INVALID 0x%08x, t %d, l %d, n %d, c %d", _uniformBuffer.getPos(), opcode, type, loc, num, copy); + break; + } + } + } + + void clearQuad(ClearQuad& _clearQuad, const Rect& _rect, const Clear& _clear, const float _palette[][4]) + { + uint32_t width; + uint32_t height; + + if (isValid(m_fbh) ) + { + const FrameBufferWgpu& fb = m_frameBuffers[m_fbh.idx]; + width = fb.m_width; + height = fb.m_height; + } + else + { + width = m_resolution.width; + height = m_resolution.height; + } + + uint64_t state = 0; + state |= _clear.m_flags & BGFX_CLEAR_COLOR ? BGFX_STATE_WRITE_RGB|BGFX_STATE_WRITE_A : 0; + state |= _clear.m_flags & BGFX_CLEAR_DEPTH ? BGFX_STATE_DEPTH_TEST_ALWAYS|BGFX_STATE_WRITE_Z : 0; + state |= BGFX_STATE_PT_TRISTRIP; + + uint64_t stencil = 0; + stencil |= _clear.m_flags & BGFX_CLEAR_STENCIL ? 0 + | BGFX_STENCIL_TEST_ALWAYS + | BGFX_STENCIL_FUNC_REF(_clear.m_stencil) + | BGFX_STENCIL_FUNC_RMASK(0xff) + | BGFX_STENCIL_OP_FAIL_S_REPLACE + | BGFX_STENCIL_OP_FAIL_Z_REPLACE + | BGFX_STENCIL_OP_PASS_Z_REPLACE + : 0 + ; + + uint32_t numMrt = 1; + FrameBufferHandle fbh = m_fbh; + if (isValid(fbh) && m_frameBuffers[fbh.idx].m_swapChain == NULL) + { + const FrameBufferWgpu& fb = m_frameBuffers[fbh.idx]; + numMrt = bx::uint32_max(1, fb.m_num); + } + + wgpu::RenderPassEncoder rce = m_renderEncoder; + ProgramHandle programHandle = _clearQuad.m_program[numMrt-1]; + + const VertexLayout* decl = &_clearQuad.m_layout; + const PipelineStateWgpu* pso = getPipelineState( + state + , stencil + , 0 + , fbh + , 1 + , &decl + , false + , programHandle + , 0 + ); + rce.SetPipeline(pso->m_rps); + + float mrtClearColor[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS][4]; + float mrtClearDepth[4] = { _clear.m_depth }; + + if (BGFX_CLEAR_COLOR_USE_PALETTE & _clear.m_flags) + { + for (uint32_t ii = 0; ii < numMrt; ++ii) + { + uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE-1, _clear.m_index[ii]); + bx::memCopy(mrtClearColor[ii], _palette[index], 16); + } + } + else + { + float rgba[4] = + { + _clear.m_index[0]*1.0f/255.0f, + _clear.m_index[1]*1.0f/255.0f, + _clear.m_index[2]*1.0f/255.0f, + _clear.m_index[3]*1.0f/255.0f, + }; + + for (uint32_t ii = 0; ii < numMrt; ++ii) + { + bx::memCopy( mrtClearColor[ii] + , rgba + , 16 + ); + } + } + + ProgramWgpu& program = m_program[programHandle.idx]; + + ScratchBufferWgpu& scratchBuffer = m_scratchBuffers[0]; + BindStateCacheWgpu& bindStates = m_bindStateCache[0]; + + BindingsWgpu b; + BindStateWgpu& bindState = allocBindState(program, bindStates, b, scratchBuffer); + + const uint32_t voffset = scratchBuffer.write(mrtClearDepth, sizeof(mrtClearDepth), program.m_vsh->m_gpuSize); + const uint32_t foffset = scratchBuffer.write(mrtClearColor, sizeof(mrtClearColor), program.m_fsh->m_gpuSize); + + uint32_t numOffset = 2; + uint32_t offsets[2] = { voffset, foffset }; + + bindGroups(program, bindState, b); + + const VertexBufferWgpu& vb = m_vertexBuffers[_clearQuad.m_vb.idx]; + + bindProgram(rce, program, bindState, numOffset, offsets); + + rce.SetViewport(_rect.m_x, _rect.m_y, _rect.m_width, _rect.m_height, 0.0f, 1.0f); + rce.SetScissorRect(_rect.m_x, _rect.m_y, _rect.m_width, _rect.m_height); + + rce.SetVertexBuffer(0, vb.m_ptr); + rce.Draw(4, 1, 0, 0); + } + + wgpu::TextureViewDescriptor attachmentView(const Attachment& _at, const TextureWgpu& _texture) + { + bool _resolve = bool(_texture.m_ptrMsaa); + BX_UNUSED(_resolve); + + wgpu::TextureViewDescriptor desc; + if (1 < _texture.m_numSides) + { + desc.baseArrayLayer = _at.layer; + } + desc.baseMipLevel = _at.mip; + desc.arrayLayerCount = 1; + desc.mipLevelCount = 1; + + if (_texture.m_type == TextureWgpu::Texture3D) + { + desc.dimension = wgpu::TextureViewDimension::e3D; + } + + return desc; + } + + void setFrameBuffer(RenderPassDescriptor& _renderPassDescriptor, FrameBufferHandle _fbh, bool _msaa = true) + { + if (!isValid(_fbh) + || m_frameBuffers[_fbh.idx].m_swapChain) + { + SwapChainWgpu* swapChain = !isValid(_fbh) + ? m_mainFrameBuffer.m_swapChain + : m_frameBuffers[_fbh.idx].m_swapChain + ; + + _renderPassDescriptor.colorAttachments[0] = defaultDescriptor<wgpu::RenderPassColorAttachment>(); + _renderPassDescriptor.desc.colorAttachmentCount = 1; + + // Force 1 array layers for attachments + wgpu::TextureViewDescriptor desc; + desc.arrayLayerCount = 1; + + if (swapChain->m_backBufferColorMsaa) + { + _renderPassDescriptor.colorAttachments[0].view = swapChain->m_backBufferColorMsaa.CreateView(&desc); + _renderPassDescriptor.colorAttachments[0].resolveTarget = swapChain->current(); + } + else + { + _renderPassDescriptor.colorAttachments[0].view = swapChain->current(); + } + + _renderPassDescriptor.depthStencilAttachment = defaultDescriptor<wgpu::RenderPassDepthStencilAttachment>(); + _renderPassDescriptor.depthStencilAttachment.view = swapChain->m_backBufferDepth.CreateView(); + _renderPassDescriptor.desc.depthStencilAttachment = &_renderPassDescriptor.depthStencilAttachment; + } + else + { + FrameBufferWgpu& frameBuffer = m_frameBuffers[_fbh.idx]; + + _renderPassDescriptor.desc.colorAttachmentCount = frameBuffer.m_num; + + for (uint32_t ii = 0; ii < frameBuffer.m_num; ++ii) + { + const TextureWgpu& texture = m_textures[frameBuffer.m_colorHandle[ii].idx]; + + const wgpu::TextureViewDescriptor desc = attachmentView(frameBuffer.m_colorAttachment[ii], texture); + + _renderPassDescriptor.colorAttachments[ii] = defaultDescriptor<wgpu::RenderPassColorAttachment>(); + _renderPassDescriptor.colorAttachments[ii].view = texture.m_ptrMsaa + ? texture.m_ptrMsaa.CreateView(&desc) + : texture.m_ptr.CreateView(&desc) + ; + _renderPassDescriptor.colorAttachments[ii].resolveTarget = texture.m_ptrMsaa + ? texture.m_ptr.CreateView(&desc) + : wgpu::TextureView() + ; + } + + if (isValid(frameBuffer.m_depthHandle) ) + { + const TextureWgpu& texture = m_textures[frameBuffer.m_depthHandle.idx]; + const wgpu::TextureViewDescriptor desc = attachmentView(frameBuffer.m_depthAttachment, texture); + + _renderPassDescriptor.depthStencilAttachment = defaultDescriptor<wgpu::RenderPassDepthStencilAttachment>(); + _renderPassDescriptor.depthStencilAttachment.view = texture.m_ptrMsaa + ? texture.m_ptrMsaa.CreateView(&desc) + : texture.m_ptr.CreateView(&desc) + ; + + _renderPassDescriptor.desc.depthStencilAttachment = &_renderPassDescriptor.depthStencilAttachment; + } + } + + m_fbh = _fbh; + m_rtMsaa = _msaa; + } + + void setDepthStencilState(wgpu::DepthStencilState& desc, uint64_t _state, uint64_t _stencil = 0) + { + const uint32_t fstencil = unpackStencil(0, _stencil); + const uint32_t func = (_state&BGFX_STATE_DEPTH_TEST_MASK) >> BGFX_STATE_DEPTH_TEST_SHIFT; + + desc.depthWriteEnabled = !!(BGFX_STATE_WRITE_Z & _state); + desc.depthCompare = s_cmpFunc[func]; + + uint32_t bstencil = unpackStencil(1, _stencil); + const uint32_t frontAndBack = bstencil != BGFX_STENCIL_NONE && bstencil != fstencil; + bstencil = frontAndBack ? bstencil : fstencil; + + desc.stencilFront = defaultDescriptor<wgpu::StencilFaceState>(); + desc.stencilBack = defaultDescriptor<wgpu::StencilFaceState>(); + + if (0 != _stencil) + { + // TODO (hugoam) + const uint32_t readMask = (fstencil&BGFX_STENCIL_FUNC_RMASK_MASK)>>BGFX_STENCIL_FUNC_RMASK_SHIFT; + const uint32_t writeMask = 0xff; + + desc.stencilReadMask = readMask; + desc.stencilWriteMask = writeMask; + + desc.stencilFront.failOp = s_stencilOp[(fstencil&BGFX_STENCIL_OP_FAIL_S_MASK)>>BGFX_STENCIL_OP_FAIL_S_SHIFT]; + desc.stencilFront.depthFailOp = s_stencilOp[(fstencil&BGFX_STENCIL_OP_FAIL_Z_MASK)>>BGFX_STENCIL_OP_FAIL_Z_SHIFT]; + desc.stencilFront.passOp = s_stencilOp[(fstencil&BGFX_STENCIL_OP_PASS_Z_MASK)>>BGFX_STENCIL_OP_PASS_Z_SHIFT]; + desc.stencilFront.compare = s_cmpFunc[(fstencil&BGFX_STENCIL_TEST_MASK)>>BGFX_STENCIL_TEST_SHIFT]; + + desc.stencilBack.failOp = s_stencilOp[(bstencil&BGFX_STENCIL_OP_FAIL_S_MASK)>>BGFX_STENCIL_OP_FAIL_S_SHIFT]; + desc.stencilBack.depthFailOp = s_stencilOp[(bstencil&BGFX_STENCIL_OP_FAIL_Z_MASK)>>BGFX_STENCIL_OP_FAIL_Z_SHIFT]; + desc.stencilBack.passOp = s_stencilOp[(bstencil&BGFX_STENCIL_OP_PASS_Z_MASK)>>BGFX_STENCIL_OP_PASS_Z_SHIFT]; + desc.stencilBack.compare = s_cmpFunc[(bstencil&BGFX_STENCIL_TEST_MASK)>>BGFX_STENCIL_TEST_SHIFT]; + } + } + + RenderPassStateWgpu* getRenderPassState(bgfx::FrameBufferHandle fbh, bool clear, Clear clr) + { + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(fbh.idx); + murmur.add(clear); + murmur.add(&clr, sizeof(clr)); + uint32_t hash = murmur.end(); + + RenderPassStateWgpu* rps = m_renderPassStateCache.find(hash); + + if (NULL == rps) + { + rps = BX_NEW(g_allocator, RenderPassStateWgpu); + m_renderPassStateCache.add(hash, rps); + } + + return rps; + } + + PipelineStateWgpu* getPipelineState( + uint64_t _state + , uint64_t _stencil + , uint32_t _rgba + , FrameBufferHandle _fbh + , uint8_t _numStreams + , const VertexLayout** _vertexDecls + , bool _isIndex16 + , ProgramHandle _program + , uint8_t _numInstanceData + ) + { + _state &= 0 + | BGFX_STATE_WRITE_RGB + | BGFX_STATE_WRITE_A + | BGFX_STATE_WRITE_Z + | BGFX_STATE_DEPTH_TEST_MASK + | BGFX_STATE_BLEND_MASK + | BGFX_STATE_BLEND_EQUATION_MASK + | BGFX_STATE_BLEND_INDEPENDENT + | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE + | BGFX_STATE_CULL_MASK + | BGFX_STATE_MSAA + | BGFX_STATE_LINEAA + | BGFX_STATE_CONSERVATIVE_RASTER + | BGFX_STATE_PT_MASK + ; + + const bool independentBlendEnable = !!(BGFX_STATE_BLEND_INDEPENDENT & _state); + const ProgramWgpu& program = m_program[_program.idx]; + + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(_state); + murmur.add(_stencil); + murmur.add(independentBlendEnable ? _rgba : 0); + murmur.add(_numInstanceData); + + FrameBufferWgpu& frameBuffer = !isValid(_fbh) ? m_mainFrameBuffer : m_frameBuffers[_fbh.idx]; + murmur.add(frameBuffer.m_pixelFormatHash); + + murmur.add(program.m_vsh->m_hash); + if (NULL != program.m_fsh) + { + murmur.add(program.m_fsh->m_hash); + } + + for (uint8_t ii = 0; ii < _numStreams; ++ii) + { + murmur.add(_vertexDecls[ii]->m_hash); + } + + uint32_t hash = murmur.end(); + + PipelineStateWgpu* pso = m_pipelineStateCache.find(hash); + + if (NULL == pso) + { + pso = BX_NEW(g_allocator, PipelineStateWgpu); + + //pd.alphaToCoverageEnabled = !!(BGFX_STATE_BLEND_ALPHA_TO_COVERAGE & _state); + + RenderPipelineDescriptor& pd = pso->m_rpd; + + uint32_t frameBufferAttachment = 1; + uint32_t sampleCount = 1; + + if (!isValid(_fbh) + || s_renderWgpu->m_frameBuffers[_fbh.idx].m_swapChain) + { + SwapChainWgpu& swapChain = !isValid(_fbh) + ? *s_renderWgpu->m_mainFrameBuffer.m_swapChain + : *s_renderWgpu->m_frameBuffers[_fbh.idx].m_swapChain + ; + sampleCount = swapChain.m_backBufferColorMsaa + ? swapChain.m_sampleCount + : 1 + ; + pd.targets[0].format = swapChain.m_colorFormat; + pd.depthStencil.format = swapChain.m_depthFormat; + pd.desc.depthStencil = &pd.depthStencil; + } + else + { + frameBufferAttachment = frameBuffer.m_num; + + for (uint32_t ii = 0; ii < frameBuffer.m_num; ++ii) + { + const TextureWgpu& texture = m_textures[frameBuffer.m_colorHandle[ii].idx]; + sampleCount = texture.m_ptrMsaa + ? texture.m_sampleCount + : 1 + ; + pd.targets[ii].format = s_textureFormat[texture.m_textureFormat].m_fmt; + } + + pd.fragment.targetCount = frameBuffer.m_num; + + if (isValid(frameBuffer.m_depthHandle) ) + { + const TextureWgpu& texture = m_textures[frameBuffer.m_depthHandle.idx]; + pd.depthStencil.format = s_textureFormat[texture.m_textureFormat].m_fmt; + pd.desc.depthStencil = &pd.depthStencil; + } + } + + const uint32_t blend = uint32_t( (_state&BGFX_STATE_BLEND_MASK )>>BGFX_STATE_BLEND_SHIFT); + const uint32_t equation = uint32_t( (_state&BGFX_STATE_BLEND_EQUATION_MASK)>>BGFX_STATE_BLEND_EQUATION_SHIFT); + + const uint32_t srcRGB = (blend )&0xf; + const uint32_t dstRGB = (blend>> 4)&0xf; + const uint32_t srcA = (blend>> 8)&0xf; + const uint32_t dstA = (blend>>12)&0xf; + + const uint32_t equRGB = (equation )&0x7; + const uint32_t equA = (equation>>3)&0x7; + + wgpu::ColorWriteMask writeMask = wgpu::ColorWriteMask::None; + writeMask |= (_state&BGFX_STATE_WRITE_R) ? wgpu::ColorWriteMask::Red : wgpu::ColorWriteMask::None; + writeMask |= (_state&BGFX_STATE_WRITE_G) ? wgpu::ColorWriteMask::Green : wgpu::ColorWriteMask::None; + writeMask |= (_state&BGFX_STATE_WRITE_B) ? wgpu::ColorWriteMask::Blue : wgpu::ColorWriteMask::None; + writeMask |= (_state&BGFX_STATE_WRITE_A) ? wgpu::ColorWriteMask::Alpha : wgpu::ColorWriteMask::None; + + for (uint32_t ii = 0; ii < (independentBlendEnable ? 1 : frameBufferAttachment); ++ii) + { + wgpu::ColorTargetState& drt = pd.targets[ii]; + wgpu::BlendState& blend = pd.blends[ii]; + + if(!(BGFX_STATE_BLEND_MASK & _state)) + { + // useless + blend.color = defaultDescriptor<wgpu::BlendComponent>(); + blend.alpha = defaultDescriptor<wgpu::BlendComponent>(); + + drt.blend = NULL; + } + else + { + blend.color.srcFactor = s_blendFactor[srcRGB][0]; + blend.color.dstFactor = s_blendFactor[dstRGB][0]; + blend.color.operation = s_blendEquation[equRGB]; + + blend.alpha.srcFactor = s_blendFactor[srcA][1]; + blend.alpha.dstFactor = s_blendFactor[dstA][1]; + blend.alpha.operation = s_blendEquation[equA]; + + drt.blend = &blend; + } + + drt.writeMask = writeMask; + } + + if (independentBlendEnable) + { + for (uint32_t ii = 1, rgba = _rgba; ii < frameBufferAttachment; ++ii, rgba >>= 11) + { + wgpu::ColorTargetState& drt = pd.targets[ii]; + wgpu::BlendState& blend = pd.blends[ii]; + + //drt.blendingEnabled = 0 != (rgba&0x7ff); + + const uint32_t src = (rgba )&0xf; + const uint32_t dst = (rgba>>4)&0xf; + const uint32_t equationIndex = (rgba>>8)&0x7; + + blend.color.srcFactor = s_blendFactor[src][0]; + blend.color.dstFactor = s_blendFactor[dst][0]; + blend.color.operation = s_blendEquation[equationIndex]; + + blend.alpha.srcFactor = s_blendFactor[src][1]; + blend.alpha.dstFactor = s_blendFactor[dst][1]; + blend.alpha.operation = s_blendEquation[equationIndex]; + + drt.writeMask = writeMask; + } + } + + pd.desc.vertex.module = program.m_vsh->m_module; + + if (NULL != program.m_fsh) + { + pd.fragment.module = program.m_fsh->m_module; + pd.desc.fragment = &pd.fragment; + } + + setDepthStencilState(pd.depthStencil, _state, _stencil); + + const uint64_t cull = _state & BGFX_STATE_CULL_MASK; + const uint8_t cullIndex = uint8_t(cull >> BGFX_STATE_CULL_SHIFT); + pd.desc.primitive.cullMode = s_cullMode[cullIndex]; + + pd.desc.primitive.frontFace = (_state & BGFX_STATE_FRONT_CCW) ? wgpu::FrontFace::CCW : wgpu::FrontFace::CW; + + // pd.desc = m_renderPipelineDescriptor; + pd.desc.multisample.count = sampleCount; + + wgpu::PipelineLayoutDescriptor layout = defaultDescriptor<wgpu::PipelineLayoutDescriptor>(); + layout.bindGroupLayouts = &program.m_bindGroupLayout; + layout.bindGroupLayoutCount = 1; + + BX_TRACE("Creating WebGPU render pipeline layout for program %s", program.m_vsh->name()); + pd.desc.layout = m_device.CreatePipelineLayout(&layout); + // TODO (hugoam) this should be cached too ? + + //uint32_t ref = (_state&BGFX_STATE_ALPHA_REF_MASK) >> BGFX_STATE_ALPHA_REF_SHIFT; + //viewState.m_alphaRef = ref / 255.0f; + + const uint64_t primType = _state & BGFX_STATE_PT_MASK; + uint8_t primIndex = uint8_t(primType >> BGFX_STATE_PT_SHIFT); + + PrimInfo prim = s_primInfo[primIndex]; + pd.desc.primitive.topology = prim.m_type; + + VertexStateDescriptor vertex; + vertex.desc.module = program.m_vsh->m_module; + vertex.desc.bufferCount = 0; + + wgpu::VertexBufferLayout* inputBinding = vertex.buffers; + wgpu::VertexAttribute* inputAttrib = vertex.attributes; + + auto fillVertexDecl = [&](const ShaderWgpu* _vsh, const VertexLayout& _decl) + { + vertex.desc.bufferCount += 1; + + inputBinding->arrayStride = _decl.m_stride; + inputBinding->stepMode = wgpu::InputStepMode::Vertex; + inputBinding->attributes = inputAttrib; + + uint32_t numAttribs = 0; + + for(uint32_t attr = 0; attr < Attrib::Count; ++attr) + { + if(UINT16_MAX != _decl.m_attributes[attr]) + { + if(UINT8_MAX == _vsh->m_attrRemap[attr]) + continue; + + inputAttrib->shaderLocation = _vsh->m_attrRemap[attr]; + + if(0 == _decl.m_attributes[attr]) + { + inputAttrib->format = wgpu::VertexFormat::Float3; + inputAttrib->offset = 0; + } + else + { + uint8_t num; + AttribType::Enum type; + bool normalized; + bool asInt; + _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); + inputAttrib->format = s_attribType[type][num-1][normalized]; + inputAttrib->offset = _decl.m_offset[attr]; + } + + ++inputAttrib; + ++numAttribs; + } + } + + inputBinding->attributeCount = numAttribs; + inputBinding++; + + return numAttribs; + }; + + //bool attrSet[Attrib::Count] = {}; + + uint16_t unsettedAttr[Attrib::Count]; + bx::memCopy(unsettedAttr, program.m_vsh->m_attrMask, sizeof(uint16_t) * Attrib::Count); + + uint8_t stream = 0; + for (; stream < _numStreams; ++stream) + { + VertexLayout layout; + bx::memCopy(&layout, _vertexDecls[stream], sizeof(VertexLayout)); + const uint16_t* attrMask = program.m_vsh->m_attrMask; + + for (uint32_t ii = 0; ii < Attrib::Count; ++ii) + { + Attrib::Enum iiattr = Attrib::Enum(ii); + uint16_t mask = attrMask[ii]; + uint16_t attr = (layout.m_attributes[ii] & mask); + if (attr == 0) + { + layout.m_attributes[ii] = UINT16_MAX; + } + if (unsettedAttr[ii] && attr != UINT16_MAX) + { + unsettedAttr[ii] = 0; + } + } + + fillVertexDecl(program.m_vsh, layout); + } + + for (uint32_t ii = 0; ii < Attrib::Count; ++ii) + { + Attrib::Enum iiattr = Attrib::Enum(ii); + if (0 < unsettedAttr[ii]) + { + //uint32_t numAttribs = vertexs.buffers[stream].attributeCount; + //uint32_t numAttribs = inputBinding->attributeCount; + //wgpu::VertexBufferLayout* inputAttrib = const_cast<VkVertexInputAttributeDescription*>(_vertexInputState.pVertexAttributeDescriptions + numAttribs); + inputAttrib->shaderLocation = program.m_vsh->m_attrRemap[ii]; + //inputAttrib->binding = 0; + inputAttrib->format = wgpu::VertexFormat::Float3; // VK_FORMAT_R32G32B32_SFLOAT; + inputAttrib->offset = 0; + vertex.buffers[stream-1].attributeCount++; + ++inputAttrib; + } + } + + // TODO (hugoam) WebGPU will crash whenever we are not supplying the correct number of attributes (which depends on the stride passed to bgfx::allocInstanceDataBuffer) + // so we need to know the number of live instance attributes in the shader and if they aren't all supplied: + // - fail the pipeline state creation + // - bind dummy attributes + if (0 < _numInstanceData) + { + uint32_t numBindings = vertex.desc.bufferCount; // == stream+1 // .vertexBindingDescriptionCount; + uint32_t firstAttrib = vertex.buffers[stream-1].attributeCount; + uint32_t numAttribs = firstAttrib; + + inputBinding->arrayStride = _numInstanceData * 16; + inputBinding->stepMode = wgpu::InputStepMode::Instance; + + for (uint32_t inst = 0; inst < _numInstanceData; ++inst) + { + inputAttrib->shaderLocation = numAttribs; + inputAttrib->format = wgpu::VertexFormat::Float32x4; + inputAttrib->offset = inst * 16; + + ++numAttribs; + ++inputAttrib; + } + + vertex.desc.bufferCount = numBindings + 1; + vertex.buffers[stream].attributeCount = numAttribs - firstAttrib; + vertex.buffers[stream].attributes = &vertex.attributes[firstAttrib]; + } + + bool isStrip = prim.m_type == wgpu::PrimitiveTopology::LineStrip + || prim.m_type == wgpu::PrimitiveTopology::TriangleStrip; + if (isStrip) + pd.desc.primitive.stripIndexFormat = _isIndex16 ? wgpu::IndexFormat::Uint16 : wgpu::IndexFormat::Uint32; + else + pd.desc.primitive.stripIndexFormat = wgpu::IndexFormat::Undefined; + + pd.desc.vertex = vertex.desc; + + BX_TRACE("Creating WebGPU render pipeline state for program %s", program.m_vsh->name()); + pso->m_rps = m_device.CreateRenderPipeline2(&pd.desc); + + m_pipelineStateCache.add(hash, pso); + } + + return pso; + } + + PipelineStateWgpu* getPipelineState( + uint64_t _state + , uint64_t _stencil + , uint32_t _rgba + , FrameBufferHandle _fbh + , VertexLayoutHandle _declHandle + , bool _isIndex16 + , ProgramHandle _program + , uint8_t _numInstanceData + ) + { + const VertexLayout* decl = &m_vertexDecls[_declHandle.idx]; + return getPipelineState( + _state + , _stencil + , _rgba + , _fbh + , 1 + , &decl + , _isIndex16 + , _program + , _numInstanceData + ); + } + + PipelineStateWgpu* getComputePipelineState(ProgramHandle _program) + { + ProgramWgpu& program = m_program[_program.idx]; + + if (NULL == program.m_computePS) + { + PipelineStateWgpu* pso = BX_NEW(g_allocator, PipelineStateWgpu); + program.m_computePS = pso; + + wgpu::PipelineLayoutDescriptor layout = defaultDescriptor<wgpu::PipelineLayoutDescriptor>(); + layout.bindGroupLayouts = &program.m_bindGroupLayout; + layout.bindGroupLayoutCount = 1; + + BX_TRACE("Creating WebGPU render pipeline layout for program %s", program.m_vsh->name()); + pso->m_layout = m_device.CreatePipelineLayout(&layout); + + wgpu::ComputePipelineDescriptor desc; + desc.layout = pso->m_layout; + desc.computeStage = { NULL, program.m_vsh->m_module, "main" }; + + BX_TRACE("Creating WebGPU render pipeline state for program %s", program.m_vsh->name()); + pso->m_cps = m_device.CreateComputePipeline(&desc); + } + + return program.m_computePS; + } + + + wgpu::Sampler getSamplerState(uint32_t _flags) + { + _flags &= BGFX_SAMPLER_BITS_MASK; + SamplerStateWgpu* sampler = m_samplerStateCache.find(_flags); + + if (NULL == sampler) + { + sampler = BX_NEW(g_allocator, SamplerStateWgpu); + + wgpu::SamplerDescriptor desc; + desc.addressModeU = s_textureAddress[(_flags&BGFX_SAMPLER_U_MASK)>>BGFX_SAMPLER_U_SHIFT]; + desc.addressModeV = s_textureAddress[(_flags&BGFX_SAMPLER_V_MASK)>>BGFX_SAMPLER_V_SHIFT]; + desc.addressModeW = s_textureAddress[(_flags&BGFX_SAMPLER_W_MASK)>>BGFX_SAMPLER_W_SHIFT]; + desc.minFilter = s_textureFilterMinMag[(_flags&BGFX_SAMPLER_MIN_MASK)>>BGFX_SAMPLER_MIN_SHIFT]; + desc.magFilter = s_textureFilterMinMag[(_flags&BGFX_SAMPLER_MAG_MASK)>>BGFX_SAMPLER_MAG_SHIFT]; + desc.mipmapFilter = s_textureFilterMip[(_flags&BGFX_SAMPLER_MIP_MASK)>>BGFX_SAMPLER_MIP_SHIFT]; + desc.lodMinClamp = 0; + desc.lodMaxClamp = bx::kFloatMax; + + const uint32_t cmpFunc = (_flags&BGFX_SAMPLER_COMPARE_MASK)>>BGFX_SAMPLER_COMPARE_SHIFT; + desc.compare = 0 == cmpFunc + ? wgpu::CompareFunction::Undefined + : s_cmpFunc[cmpFunc] + ; + + sampler->m_sampler = s_renderWgpu->m_device.CreateSampler(&desc); + m_samplerStateCache.add(_flags, sampler); + } + + return sampler->m_sampler; + } + + wgpu::CommandEncoder& getRenderEncoder() + { + if (!m_cmd.m_renderEncoder) + m_cmd.beginRender(); + + return m_cmd.m_renderEncoder; + } + + wgpu::CommandEncoder& getStagingEncoder() + { + if (!m_cmd.m_stagingEncoder) + m_cmd.beginStaging(); + + return m_cmd.m_stagingEncoder; + } + + wgpu::CommandEncoder& getBlitCommandEncoder() + { + if (m_renderEncoder || m_computeEncoder) + endEncoding(); + + return getRenderEncoder(); + } + + wgpu::RenderPassEncoder renderPass(bgfx::Frame* _render, bgfx::FrameBufferHandle fbh, bool clear, Clear clr, const char* name = NULL) + { + RenderPassStateWgpu* rps = s_renderWgpu->getRenderPassState(fbh, clear, clr); + + RenderPassDescriptor& renderPassDescriptor = rps->m_rpd; + renderPassDescriptor.desc.label = name; + + setFrameBuffer(renderPassDescriptor, fbh); + + if(clear) + { + for(uint32_t ii = 0; ii < g_caps.limits.maxFBAttachments; ++ii) + { + wgpu::RenderPassColorAttachment& color = renderPassDescriptor.colorAttachments[ii]; + + if(0 != (BGFX_CLEAR_COLOR & clr.m_flags)) + { + if(0 != (BGFX_CLEAR_COLOR_USE_PALETTE & clr.m_flags)) + { + uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, clr.m_index[ii]); + const float* rgba = _render->m_colorPalette[index]; + const float rr = rgba[0]; + const float gg = rgba[1]; + const float bb = rgba[2]; + const float aa = rgba[3]; + color.clearColor = { rr, gg, bb, aa }; + } + else + { + float rr = clr.m_index[0] * 1.0f / 255.0f; + float gg = clr.m_index[1] * 1.0f / 255.0f; + float bb = clr.m_index[2] * 1.0f / 255.0f; + float aa = clr.m_index[3] * 1.0f / 255.0f; + color.clearColor = { rr, gg, bb, aa }; + } + + color.loadOp = wgpu::LoadOp::Clear; + } + else + { + color.loadOp = wgpu::LoadOp::Load; + } + + //desc.storeOp = desc.view.sampleCount > 1 ? wgpu::StoreOp::MultisampleResolve : wgpu::StoreOp::Store; + color.storeOp = wgpu::StoreOp::Store; + } + + wgpu::RenderPassDepthStencilAttachment& depthStencil = renderPassDescriptor.depthStencilAttachment; + + if(depthStencil.view) + { + depthStencil.clearDepth = clr.m_depth; + depthStencil.depthLoadOp = 0 != (BGFX_CLEAR_DEPTH & clr.m_flags) + ? wgpu::LoadOp::Clear + : wgpu::LoadOp::Load + ; + depthStencil.depthStoreOp = m_mainFrameBuffer.m_swapChain->m_backBufferColorMsaa + ? wgpu::StoreOp(0) //wgpu::StoreOp::DontCare + : wgpu::StoreOp::Store + ; + + depthStencil.clearStencil = clr.m_stencil; + depthStencil.stencilLoadOp = 0 != (BGFX_CLEAR_STENCIL & clr.m_flags) + ? wgpu::LoadOp::Clear + : wgpu::LoadOp::Load + ; + depthStencil.stencilStoreOp = m_mainFrameBuffer.m_swapChain->m_backBufferColorMsaa + ? wgpu::StoreOp(0) //wgpu::StoreOp::DontCare + : wgpu::StoreOp::Store + ; + } + } + else + { + for(uint32_t ii = 0; ii < g_caps.limits.maxFBAttachments; ++ii) + { + wgpu::RenderPassColorAttachment& color = renderPassDescriptor.colorAttachments[ii]; + if(color.view) + { + color.loadOp = wgpu::LoadOp::Load; + } + } + + wgpu::RenderPassDepthStencilAttachment& depthStencil = renderPassDescriptor.depthStencilAttachment; + + if(depthStencil.view) + { + depthStencil.depthLoadOp = wgpu::LoadOp::Load; + depthStencil.depthStoreOp = wgpu::StoreOp::Store; + + depthStencil.stencilLoadOp = wgpu::LoadOp::Load; + depthStencil.stencilStoreOp = wgpu::StoreOp::Store; + } + } + + wgpu::RenderPassEncoder rce = m_cmd.m_renderEncoder.BeginRenderPass(&renderPassDescriptor.desc); + m_renderEncoder = rce; + return rce; + } + + void endEncoding() + { + if (m_renderEncoder) + { + m_renderEncoder.EndPass(); + m_renderEncoder = NULL; + } + + if (m_computeEncoder) + { + m_computeEncoder.EndPass(); + m_computeEncoder = NULL; + } + } + + void* m_renderDocDll; + +#if !BX_PLATFORM_EMSCRIPTEN + dawn_native::Instance m_instance; +#endif + wgpu::Device m_device; + wgpu::Queue m_queue; + TimerQueryWgpu m_gpuTimer; + CommandQueueWgpu m_cmd; + + StagingBufferWgpu m_uniformBuffers[WEBGPU_NUM_UNIFORM_BUFFERS]; + ScratchBufferWgpu m_scratchBuffers[BGFX_CONFIG_MAX_FRAME_LATENCY]; + + BindStateCacheWgpu m_bindStateCache[BGFX_CONFIG_MAX_FRAME_LATENCY]; + + uint8_t m_frameIndex; + + uint16_t m_numWindows; + FrameBufferHandle m_windows[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + + IndexBufferWgpu m_indexBuffers[BGFX_CONFIG_MAX_INDEX_BUFFERS]; + VertexBufferWgpu m_vertexBuffers[BGFX_CONFIG_MAX_VERTEX_BUFFERS]; + ShaderWgpu m_shaders[BGFX_CONFIG_MAX_SHADERS]; + ProgramWgpu m_program[BGFX_CONFIG_MAX_PROGRAMS]; + TextureWgpu m_textures[BGFX_CONFIG_MAX_TEXTURES]; + ReadbackWgpu m_readbacks[BGFX_CONFIG_MAX_TEXTURES]; + FrameBufferWgpu m_mainFrameBuffer; + FrameBufferWgpu m_frameBuffers[BGFX_CONFIG_MAX_FRAME_BUFFERS]; + VertexLayout m_vertexDecls[BGFX_CONFIG_MAX_VERTEX_LAYOUTS]; + UniformRegistry m_uniformReg; + void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; + + //StateCacheT<BindStateWgpu*> m_bindStateCache; + StateCacheT<RenderPassStateWgpu*> m_renderPassStateCache; + StateCacheT<PipelineStateWgpu*> m_pipelineStateCache; + StateCacheT<SamplerStateWgpu*> m_samplerStateCache; + + TextVideoMem m_textVideoMem; + + uint8_t m_fsScratch[64 << 10]; + uint8_t m_vsScratch[64 << 10]; + + FrameBufferHandle m_fbh; + bool m_rtMsaa; + + Resolution m_resolution; + void* m_capture; + uint32_t m_captureSize; + + wgpu::RenderPassEncoder m_renderEncoder; + wgpu::ComputePassEncoder m_computeEncoder; + }; + + RendererContextI* rendererCreate(const Init& _init) + { + s_renderWgpu = BX_NEW(g_allocator, RendererContextWgpu); + if (!s_renderWgpu->init(_init) ) + { + BX_DELETE(g_allocator, s_renderWgpu); + s_renderWgpu = NULL; + } + return s_renderWgpu; + } + + void rendererDestroy() + { + s_renderWgpu->shutdown(); + BX_DELETE(g_allocator, s_renderWgpu); + s_renderWgpu = NULL; + } + + void writeString(bx::WriterI* _writer, const char* _str) + { + bx::write(_writer, _str, (int32_t)bx::strLen(_str) ); + } + + void ShaderWgpu::create(ShaderHandle _handle, const Memory* _mem) + { + m_handle = _handle; + + BX_TRACE("Creating shader %s", getName(_handle)); + + bx::MemoryReader reader(_mem->data, _mem->size); + + bx::ErrorAssert err; + + uint32_t magic; + bx::read(&reader, magic, &err); + + wgpu::ShaderStage shaderStage; + + if (isShaderType(magic, 'C')) + { + shaderStage = wgpu::ShaderStage::Compute; + } + else if (isShaderType(magic, 'F')) + { + shaderStage = wgpu::ShaderStage::Fragment; + } + else if (isShaderType(magic, 'G')) + { + //shaderStage = wgpu::ShaderStage::Geometry; + } + else if (isShaderType(magic, 'V')) + { + shaderStage = wgpu::ShaderStage::Vertex; + } + + m_stage = shaderStage; + + uint32_t hashIn; + bx::read(&reader, hashIn, &err); + + uint32_t hashOut; + + if (isShaderVerLess(magic, 6) ) + { + hashOut = hashIn; + } + else + { + bx::read(&reader, hashOut, &err); + } + + uint16_t count; + bx::read(&reader, count, &err); + + m_numPredefined = 0; + m_numUniforms = count; + + BX_TRACE("%s Shader consts %d" + , getShaderTypeName(magic) + , count + ); + + const bool fragment = isShaderType(magic, 'F'); + uint8_t fragmentBit = fragment ? kUniformFragmentBit : 0; + + BX_ASSERT(!isShaderVerLess(magic, 11), "WebGPU backend supports only shader binary version >= 11"); + + if (0 < count) + { + for (uint32_t ii = 0; ii < count; ++ii) + { + uint8_t nameSize = 0; + bx::read(&reader, nameSize, &err); + + char name[256]; + bx::read(&reader, &name, nameSize, &err); + name[nameSize] = '\0'; + + uint8_t type = 0; + bx::read(&reader, type, &err); + + uint8_t num; + bx::read(&reader, num, &err); + + uint16_t regIndex; + bx::read(&reader, regIndex, &err); + + uint16_t regCount; + bx::read(&reader, regCount, &err); + + uint8_t texComponent; + bx::read(&reader, texComponent, &err); + + uint8_t texDimension; + bx::read(&reader, texDimension, &err); + + uint16_t texFormat = 0; + bx::read(&reader, texFormat, &err); + + const char* kind = "invalid"; + + PredefinedUniform::Enum predefined = nameToPredefinedUniformEnum(name); + if (PredefinedUniform::Count != predefined) + { + kind = "predefined"; + m_predefined[m_numPredefined].m_loc = regIndex; + m_predefined[m_numPredefined].m_count = regCount; + m_predefined[m_numPredefined].m_type = uint8_t(predefined|fragmentBit); + m_numPredefined++; + } + else if (UniformType::End == (~kUniformMask & type)) + { + // regCount is used for descriptor type + const bool buffer = idToDescriptorType(regCount) == DescriptorType::StorageBuffer; + const bool readonly = (type & kUniformReadOnlyBit) != 0; + + const uint8_t reverseShift = kSpirvBindShift; + const uint8_t stage = regIndex - reverseShift; + + m_bindInfo[stage].m_index = m_numBuffers; + m_bindInfo[stage].m_binding = regIndex; + m_bindInfo[stage].m_uniform = { 0 }; + + m_buffers[m_numBuffers] = wgpu::BindGroupLayoutEntry(); + m_buffers[m_numBuffers].binding = regIndex; + m_buffers[m_numBuffers].visibility = shaderStage; + + if (buffer) + { + m_buffers[m_numBuffers].buffer.type = readonly + ? wgpu::BufferBindingType::ReadOnlyStorage + : wgpu::BufferBindingType::Storage; + } + else + { + m_buffers[m_numBuffers].storageTexture.access = readonly + ? wgpu::StorageTextureAccess::ReadOnly + : wgpu::StorageTextureAccess::WriteOnly; + + m_buffers[m_numBuffers].storageTexture.format = s_textureFormat[texFormat].m_fmt; + } + + m_numBuffers++; + + kind = "storage"; + } + else if (UniformType::Sampler == (~kUniformMask & type)) + { + const UniformRegInfo* info = s_renderWgpu->m_uniformReg.find(name); + BX_ASSERT(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); + + const uint8_t reverseShift = kSpirvBindShift; + const uint8_t stage = regIndex - reverseShift; + + m_bindInfo[stage].m_index = m_numSamplers; + m_bindInfo[stage].m_binding = regIndex; + m_bindInfo[stage].m_uniform = info->m_handle; + + auto textureDimensionToWgpu = [](TextureDimension::Enum dimension) + { + switch (dimension) + { + case TextureDimension::Dimension1D: return wgpu::TextureViewDimension::e1D; + case TextureDimension::Dimension2D: return wgpu::TextureViewDimension::e2D; + case TextureDimension::Dimension2DArray: return wgpu::TextureViewDimension::e2DArray; + case TextureDimension::DimensionCube: return wgpu::TextureViewDimension::Cube; + case TextureDimension::DimensionCubeArray: return wgpu::TextureViewDimension::CubeArray; + case TextureDimension::Dimension3D: return wgpu::TextureViewDimension::e3D; + default: return wgpu::TextureViewDimension::Undefined; + } + }; + + auto textureComponentToWgpuSampleType = [](TextureComponentType::Enum componentType) + { + switch (componentType) + { + case TextureComponentType::Float: return wgpu::TextureSampleType::Float; + case TextureComponentType::Int: return wgpu::TextureSampleType::Sint; + case TextureComponentType::Uint: return wgpu::TextureSampleType::Uint; + default: return wgpu::TextureSampleType::Float; + } + }; + + m_textures[m_numSamplers] = wgpu::BindGroupLayoutEntry(); + m_textures[m_numSamplers].binding = regIndex; + m_textures[m_numSamplers].visibility = shaderStage; + m_textures[m_numSamplers].texture.viewDimension = textureDimensionToWgpu(idToTextureDimension(texDimension)); + m_textures[m_numSamplers].texture.sampleType = textureComponentToWgpuSampleType(idToTextureComponentType(texComponent)); + + const bool comparisonSampler = (type & kUniformCompareBit) != 0; + + m_samplers[m_numSamplers] = wgpu::BindGroupLayoutEntry(); + m_samplers[m_numSamplers].binding = regIndex + kSpirvSamplerShift; + m_samplers[m_numSamplers].visibility = shaderStage; + m_samplers[m_numSamplers].sampler.type = comparisonSampler + ? wgpu::SamplerBindingType::Comparison + : wgpu::SamplerBindingType::Filtering + ; + + m_numSamplers++; + + kind = "sampler"; + } + else + { + const UniformRegInfo* info = s_renderWgpu->m_uniformReg.find(name); + BX_ASSERT(NULL != info, "User defined uniform '%s' is not found, it won't be set.", name); + + if(NULL == m_constantBuffer) + { + m_constantBuffer = UniformBuffer::create(1024); + } + + kind = "user"; + m_constantBuffer->writeUniformHandle((UniformType::Enum)(type | fragmentBit), regIndex, info->m_handle, regCount); + } + + BX_TRACE("\t%s: %s (%s), r.index %3d, r.count %2d, r.texComponent %1d, r.texDimension %1d" + , kind + , name + , getUniformTypeName(UniformType::Enum(type&~kUniformMask) ) + , regIndex + , regCount + , texComponent + , texDimension + ); + BX_UNUSED(kind); + } + + if (NULL != m_constantBuffer) + { + m_constantBuffer->finish(); + } + } + + uint32_t shaderSize; + bx::read(&reader, shaderSize, &err); + + BX_TRACE("Shader body is at %lld size %u remaining %lld", reader.getPos(), shaderSize, reader.remaining()); + + const uint32_t* code = (const uint32_t*)reader.getDataPtr(); + bx::skip(&reader, shaderSize+1); + + m_code = (uint32_t*)BX_ALLOC(g_allocator, shaderSize); + m_codeSize = shaderSize; + + bx::memCopy(m_code, code, shaderSize); + // TODO (hugoam) delete this + + BX_TRACE("First word %08" PRIx32, code[0]); + + uint8_t numAttrs = 0; + bx::read(&reader, numAttrs, &err); + + m_numAttrs = numAttrs; + + bx::memSet(m_attrMask, 0, sizeof(m_attrMask)); + bx::memSet(m_attrRemap, UINT8_MAX, sizeof(m_attrRemap)); + + for(uint8_t ii = 0; ii < numAttrs; ++ii) + { + uint16_t id; + bx::read(&reader, id, &err); + + auto toString = [](Attrib::Enum attr) + { + if (attr == Attrib::Position) return "Position"; + else if (attr == Attrib::Normal) return "Normal"; + else if (attr == Attrib::Tangent) return "Tangent"; + else if (attr == Attrib::Bitangent) return "Bitangent"; + else if (attr == Attrib::Color0) return "Color0"; + else if (attr == Attrib::Color1) return "Color1"; + else if (attr == Attrib::Color2) return "Color2"; + else if (attr == Attrib::Color3) return "Color3"; + else if (attr == Attrib::Indices) return "Indices"; + else if (attr == Attrib::Weight) return "Weight"; + else if (attr == Attrib::TexCoord0) return "TexCoord0"; + else if (attr == Attrib::TexCoord1) return "TexCoord1"; + else if (attr == Attrib::TexCoord2) return "TexCoord2"; + else if (attr == Attrib::TexCoord3) return "TexCoord3"; + else if (attr == Attrib::TexCoord4) return "TexCoord4"; + else if (attr == Attrib::TexCoord5) return "TexCoord5"; + else if (attr == Attrib::TexCoord6) return "TexCoord6"; + else if (attr == Attrib::TexCoord7) return "TexCoord7"; + return "Invalid"; + }; + + Attrib::Enum attr = idToAttrib(id); + + if(Attrib::Count != attr) + { + m_attrMask[attr] = UINT16_MAX; + m_attrRemap[attr] = ii; + BX_TRACE("\tattrib: %s (%i) at index %i", toString(attr), attr, ii); + } + } + + wgpu::ShaderModuleSPIRVDescriptor spirv; + spirv.code = m_code; + spirv.codeSize = shaderSize / 4; + + wgpu::ShaderModuleDescriptor desc; + desc.label = getName(_handle); + desc.nextInChain = &spirv; + + m_module = s_renderWgpu->m_device.CreateShaderModule(&desc); + + BGFX_FATAL(m_module + , bgfx::Fatal::InvalidShader + , "Failed to create %s shader." + , getShaderTypeName(magic) + ); + + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(hashIn); + murmur.add(hashOut); + murmur.add(code, shaderSize); + murmur.add(numAttrs); + murmur.add(m_attrMask, numAttrs); + m_hash = murmur.end(); + + auto roundUp = [](auto value, auto multiple) + { + return ((value + multiple - 1) / multiple) * multiple; + }; + + bx::read(&reader, m_size, &err); + + const uint32_t align = kMinBufferOffsetAlignment; + m_gpuSize = uint16_t(bx::strideAlign(m_size, align) ); + + BX_TRACE("shader size %d (used=%d) (prev=%d)", (int)m_size, (int)m_gpuSize, (int)bx::strideAlign(roundUp(m_size, 4), align)); + } + + void ProgramWgpu::create(const ShaderWgpu* _vsh, const ShaderWgpu* _fsh) + { + BX_ASSERT(_vsh->m_module, "Vertex shader doesn't exist."); + m_vsh = _vsh; + m_fsh = _fsh; + m_gpuSize = _vsh->m_gpuSize + (_fsh ? _fsh->m_gpuSize : 0); + + //BX_ASSERT(NULL != _vsh->m_code, "Vertex shader doesn't exist."); + m_vsh = _vsh; + bx::memCopy(&m_predefined[0], _vsh->m_predefined, _vsh->m_numPredefined * sizeof(PredefinedUniform)); + m_numPredefined = _vsh->m_numPredefined; + + if(NULL != _fsh) + { + //BX_ASSERT(NULL != _fsh->m_code, "Fragment shader doesn't exist."); + m_fsh = _fsh; + bx::memCopy(&m_predefined[m_numPredefined], _fsh->m_predefined, _fsh->m_numPredefined * sizeof(PredefinedUniform)); + m_numPredefined += _fsh->m_numPredefined; + } + + wgpu::BindGroupLayoutEntry bindings[2 + BGFX_CONFIG_MAX_TEXTURE_SAMPLERS * 3]; + + m_numUniforms = 0 + (_vsh->m_size > 0 ? 1 : 0) + (NULL != _fsh && _fsh->m_size > 0 ? 1 : 0); + + uint8_t numBindings = 0; + + if (_vsh->m_size > 0) + { + bindings[numBindings].binding = kSpirvVertexBinding; + bindings[numBindings].visibility = _vsh->m_stage; + bindings[numBindings].buffer.type = wgpu::BufferBindingType::Uniform; + bindings[numBindings].buffer.hasDynamicOffset = true; + numBindings++; + } + + if (NULL != _fsh && _fsh->m_size > 0) + { + bindings[numBindings].binding = kSpirvFragmentBinding; + bindings[numBindings].visibility = wgpu::ShaderStage::Fragment; + bindings[numBindings].buffer.type = wgpu::BufferBindingType::Uniform; + bindings[numBindings].buffer.hasDynamicOffset = true; + numBindings++; + } + + uint8_t numSamplers = 0; + + for (uint32_t ii = 0; ii < _vsh->m_numSamplers; ++ii) + { + m_textures[ii] = _vsh->m_textures[ii]; + m_samplers[ii] = _vsh->m_samplers[ii]; + bindings[numBindings++] = _vsh->m_textures[ii]; + bindings[numBindings++] = _vsh->m_samplers[ii]; + } + + numSamplers += _vsh->m_numSamplers; + + if (NULL != _fsh) + { + for (uint32_t ii = 0; ii < _fsh->m_numSamplers; ++ii) + { + m_textures[numSamplers + ii] = _fsh->m_textures[ii]; + m_samplers[numSamplers + ii] = _fsh->m_samplers[ii]; + bindings[numBindings++] = _fsh->m_textures[ii]; + bindings[numBindings++] = _fsh->m_samplers[ii]; + } + + numSamplers += _fsh->m_numSamplers; + } + + for (uint8_t stage = 0; stage < BGFX_CONFIG_MAX_TEXTURE_SAMPLERS; ++stage) + { + if (isValid(m_vsh->m_bindInfo[stage].m_uniform)) + { + m_bindInfo[stage] = m_vsh->m_bindInfo[stage]; + } + else if (NULL != m_fsh && isValid(m_fsh->m_bindInfo[stage].m_uniform)) + { + m_bindInfo[stage] = m_fsh->m_bindInfo[stage]; + m_bindInfo[stage].m_index += _vsh->m_numSamplers; + } + } + + m_numSamplers = numSamplers; + + uint8_t numBuffers = 0; + + for (uint32_t ii = 0; ii < _vsh->m_numBuffers; ++ii) + { + m_buffers[ii] = _vsh->m_buffers[ii]; + bindings[numBindings++] = _vsh->m_buffers[ii]; + } + + numBuffers += _vsh->m_numBuffers; + + if (NULL != _fsh) + { + for (uint32_t ii = 0; ii < _fsh->m_numBuffers; ++ii) + { + m_buffers[numBuffers + ii] = _fsh->m_buffers[ii]; + bindings[numBindings++] = _fsh->m_buffers[ii]; + } + + numBuffers += _fsh->m_numBuffers; + } + + m_numBuffers = numBuffers; + + BX_ASSERT(m_numUniforms + m_numSamplers * 2 + m_numBuffers == numBindings, ""); + + wgpu::BindGroupLayoutDescriptor bindGroupDesc; + bindGroupDesc.entryCount = numBindings; + bindGroupDesc.entries = bindings; + m_bindGroupLayout = s_renderWgpu->m_device.CreateBindGroupLayout(&bindGroupDesc); + + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(m_numUniforms); + murmur.add(m_textures, sizeof(wgpu::BindGroupLayoutEntry) * numSamplers); + murmur.add(m_samplers, sizeof(wgpu::BindGroupLayoutEntry) * numSamplers); + murmur.add(m_buffers, sizeof(wgpu::BindGroupLayoutEntry) * m_numBuffers); + m_bindGroupLayoutHash = murmur.end(); + } + + void ProgramWgpu::destroy() + { + m_vsh = NULL; + m_fsh = NULL; + if ( NULL != m_computePS ) + { + BX_DELETE(g_allocator, m_computePS); + m_computePS = NULL; + } + } + + void BufferWgpu::create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride, bool _vertex) + { + BX_UNUSED(_stride); + + m_size = _size; + m_flags = _flags; + m_vertex = _vertex; + + const uint32_t paddedSize = bx::strideAlign(_size, 4); + + bool storage = m_flags & BGFX_BUFFER_COMPUTE_READ_WRITE; + bool indirect = m_flags & BGFX_BUFFER_DRAW_INDIRECT; + + wgpu::BufferDescriptor desc; + desc.size = paddedSize; + desc.usage = _vertex ? wgpu::BufferUsage::Vertex : wgpu::BufferUsage::Index; + desc.usage |= (storage || indirect) ? wgpu::BufferUsage::Storage : wgpu::BufferUsage::None; + desc.usage |= indirect ? wgpu::BufferUsage::Indirect : wgpu::BufferUsage::None; + desc.usage |= NULL == _data ? wgpu::BufferUsage::CopyDst : wgpu::BufferUsage::None; + desc.mappedAtCreation = NULL != _data; + + m_ptr = s_renderWgpu->m_device.CreateBuffer(&desc); + + if(NULL != _data) + { + bx::memCopy(m_ptr.GetMappedRange(), _data, _size); + m_ptr.Unmap(); + } + } + + void BufferWgpu::update(uint32_t _offset, uint32_t _size, void* _data, bool _discard) + { + wgpu::CommandEncoder& bce = s_renderWgpu->getBlitCommandEncoder(); + + if (!m_vertex && !_discard) + { + if ( m_dynamic == NULL ) + { + m_dynamic = (uint8_t*)BX_ALLOC(g_allocator, m_size); + } + + bx::memCopy(m_dynamic + _offset, _data, _size); + uint32_t start = _offset & 4; + uint32_t end = bx::strideAlign(_offset + _size, 4); + + wgpu::BufferDescriptor desc; + desc.size = end - start; + desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc; + desc.mappedAtCreation = true; + + wgpu::Buffer staging = s_renderWgpu->m_device.CreateBuffer(&desc); + bx::memCopy(staging.GetMappedRange(), m_dynamic, end - start); + staging.Unmap(); + + // TODO pad to 4 bytes + bce.CopyBufferToBuffer(staging, 0, m_ptr, start, end - start); + s_renderWgpu->m_cmd.release(staging); + } + else + { + wgpu::BufferDescriptor desc; + desc.size = _size; + desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc; + desc.mappedAtCreation = true; + + wgpu::Buffer staging = s_renderWgpu->m_device.CreateBuffer(&desc); + bx::memCopy(staging.GetMappedRange(), _data, _size); + staging.Unmap(); + + bce.CopyBufferToBuffer(staging, 0, m_ptr, _offset, _size); + s_renderWgpu->m_cmd.release(staging); + } + } + + void IndexBufferWgpu::create(uint32_t _size, void* _data, uint16_t _flags) + { + m_format = (_flags & BGFX_BUFFER_INDEX32) != 0 + ? wgpu::IndexFormat::Uint32 + : wgpu::IndexFormat::Uint16; + + BufferWgpu::create(_size, _data, _flags); + } + + void VertexBufferWgpu::create(uint32_t _size, void* _data, VertexLayoutHandle _layoutHandle, uint16_t _flags) + { + m_layoutHandle = _layoutHandle; + uint16_t stride = isValid(_layoutHandle) + ? s_renderWgpu->m_vertexDecls[_layoutHandle.idx].m_stride + : 0 + ; + + BufferWgpu::create(_size, _data, _flags, stride, true); + } + + void TextureWgpu::create(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip) + { + m_handle = _handle; + + m_sampler = s_renderWgpu->getSamplerState(uint32_t(_flags) ); + + bimg::ImageContainer imageContainer; + + if (bimg::imageParse(imageContainer, _mem->data, _mem->size) ) + { + const bimg::ImageBlockInfo& blockInfo = getBlockInfo(bimg::TextureFormat::Enum(imageContainer.m_format) ); + const uint8_t startLod = bx::min<uint8_t>(_skip, imageContainer.m_numMips-1); + + bimg::TextureInfo ti; + bimg::imageGetSize( + &ti + , uint16_t(imageContainer.m_width >>startLod) + , uint16_t(imageContainer.m_height>>startLod) + , uint16_t(imageContainer.m_depth >>startLod) + , imageContainer.m_cubeMap + , 1 < imageContainer.m_numMips + , imageContainer.m_numLayers + , imageContainer.m_format + ); + ti.numMips = bx::min<uint8_t>(imageContainer.m_numMips-startLod, ti.numMips); + + m_flags = _flags; + m_width = ti.width; + m_height = ti.height; + m_depth = ti.depth; + m_numLayers = ti.numLayers; + m_numMips = ti.numMips; + m_numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + m_requestedFormat = TextureFormat::Enum(imageContainer.m_format); + m_textureFormat = getViableTextureFormat(imageContainer); + + if (m_requestedFormat == bgfx::TextureFormat::D16) + m_textureFormat = bgfx::TextureFormat::D32F; + + const bool compressed = bimg::isCompressed(bimg::TextureFormat::Enum(imageContainer.m_format)); + + if (compressed) + m_textureFormat = bgfx::TextureFormat::BGRA8; + + const bool convert = m_textureFormat != m_requestedFormat; + const uint8_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); + + wgpu::TextureDescriptor desc = defaultDescriptor<wgpu::TextureDescriptor>(); + //desc.label = getName(_handle); + + if (1 < ti.numLayers) + { + if (imageContainer.m_cubeMap) + { + m_type = TextureCube; + desc.dimension = wgpu::TextureDimension::e2D; + } + else + { + m_type = Texture2D; + desc.dimension = wgpu::TextureDimension::e2D; + } + } + else if (imageContainer.m_cubeMap) + { + m_type = TextureCube; + desc.dimension = wgpu::TextureDimension::e2D; + } + else if (1 < imageContainer.m_depth) + { + m_type = Texture3D; + desc.dimension = wgpu::TextureDimension::e3D; + } + else + { + m_type = Texture2D; + desc.dimension = wgpu::TextureDimension::e2D; + } + + const uint16_t numSides = ti.numLayers * (imageContainer.m_cubeMap ? 6 : 1); + const uint32_t numSrd = numSides * ti.numMips; + + const bool writeOnly = 0 != (_flags&BGFX_TEXTURE_RT_WRITE_ONLY); + const bool computeWrite = 0 != (_flags&BGFX_TEXTURE_COMPUTE_WRITE); + const bool renderTarget = 0 != (_flags&BGFX_TEXTURE_RT_MASK); + const bool srgb = 0 != (_flags&BGFX_TEXTURE_SRGB); + + BX_TRACE("Texture %3d: %s (requested: %s), layers %d, %dx%d%s RT[%c], WO[%c], CW[%c], sRGB[%c]" + , this - s_renderWgpu->m_textures + , getName( (TextureFormat::Enum)m_textureFormat) + , getName( (TextureFormat::Enum)m_requestedFormat) + , ti.numLayers + , ti.width + , ti.height + , imageContainer.m_cubeMap ? "x6" : "" + , renderTarget ? 'x' : ' ' + , writeOnly ? 'x' : ' ' + , computeWrite ? 'x' : ' ' + , srgb ? 'x' : ' ' + ); + + const uint32_t msaaQuality = bx::uint32_satsub( (_flags&BGFX_TEXTURE_RT_MSAA_MASK)>>BGFX_TEXTURE_RT_MSAA_SHIFT, 1); + const int32_t sampleCount = s_msaa[msaaQuality]; + + + wgpu::TextureFormat format = wgpu::TextureFormat::Undefined; + if (srgb) + { + format = s_textureFormat[m_textureFormat].m_fmtSrgb; + BX_WARN(format != wgpu::TextureFormat::Undefined + , "sRGB not supported for texture format %d" + , m_textureFormat + ); + } + + if (format == wgpu::TextureFormat::Undefined) + { + // not swizzled and not sRGB, or sRGB unsupported + format = s_textureFormat[m_textureFormat].m_fmt; + } + + desc.format = format; + desc.size.width = m_width; + desc.size.height = m_height; + desc.size.depthOrArrayLayers = m_numSides * bx::uint32_max(1,imageContainer.m_depth); + desc.mipLevelCount = m_numMips; + desc.sampleCount = 1; + + desc.usage = wgpu::TextureUsage::Sampled; + desc.usage |= wgpu::TextureUsage::CopyDst; + desc.usage |= wgpu::TextureUsage::CopySrc; + + if (computeWrite) + { + desc.usage |= wgpu::TextureUsage::Storage; + } + + if (renderTarget) + { + desc.usage |= wgpu::TextureUsage::OutputAttachment; + } + + m_ptr = s_renderWgpu->m_device.CreateTexture(&desc); + + if (sampleCount > 1) + { + desc.sampleCount = sampleCount; + + m_ptrMsaa = s_renderWgpu->m_device.CreateTexture(&desc); + } + + // decode images + struct ImageInfo + { + uint8_t* data; + uint32_t width; + uint32_t height; + uint32_t depth; + uint32_t pitch; + uint32_t slice; + uint32_t size; + uint8_t mipLevel; + uint8_t layer; + }; + + ImageInfo* imageInfos = (ImageInfo*)BX_ALLOC(g_allocator, sizeof(ImageInfo) * numSrd); + bx::memSet(imageInfos, 0, sizeof(ImageInfo) * numSrd); + uint32_t alignment = 1; // tightly aligned buffer + + uint32_t kk = 0; + + for (uint8_t side = 0; side < numSides; ++side) + { + for (uint8_t lod = 0; lod < ti.numMips; ++lod) + { + bimg::ImageMip mip; + if (bimg::imageGetRawData(imageContainer, side, lod + startLod, _mem->data, _mem->size, mip)) + { + if (convert) + { + const uint32_t pitch = bx::strideAlign(bx::max<uint32_t>(mip.m_width, 4) * bpp / 8, alignment); + const uint32_t slice = bx::strideAlign(bx::max<uint32_t>(mip.m_height, 4) * pitch, alignment); + const uint32_t size = slice * mip.m_depth; + + uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, size); + bimg::imageDecodeToBgra8( + g_allocator + , temp + , mip.m_data + , mip.m_width + , mip.m_height + , pitch + , mip.m_format + ); + + imageInfos[kk].data = temp; + imageInfos[kk].width = mip.m_width; + imageInfos[kk].height = mip.m_height; + imageInfos[kk].depth = mip.m_depth; + imageInfos[kk].pitch = pitch; + imageInfos[kk].slice = slice; + imageInfos[kk].size = size; + imageInfos[kk].mipLevel = lod; + imageInfos[kk].layer = side; + } + else if (compressed) + { + const uint32_t pitch = bx::strideAlign((mip.m_width / blockInfo.blockWidth) * mip.m_blockSize, alignment); + const uint32_t slice = bx::strideAlign((mip.m_height / blockInfo.blockHeight) * pitch, alignment); + const uint32_t size = slice * mip.m_depth; + + uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, size); + bimg::imageCopy( + temp + , mip.m_height / blockInfo.blockHeight + , (mip.m_width / blockInfo.blockWidth) * mip.m_blockSize + , mip.m_depth + , mip.m_data + , pitch + ); + + imageInfos[kk].data = temp; + imageInfos[kk].width = mip.m_width; + imageInfos[kk].height = mip.m_height; + imageInfos[kk].depth = mip.m_depth; + imageInfos[kk].pitch = pitch; + imageInfos[kk].slice = slice; + imageInfos[kk].size = size; + imageInfos[kk].mipLevel = lod; + imageInfos[kk].layer = side; + } + else + { + const uint32_t pitch = bx::strideAlign(mip.m_width * mip.m_bpp / 8, alignment); + const uint32_t slice = bx::strideAlign(mip.m_height * pitch, alignment); + const uint32_t size = slice * mip.m_depth; + + uint8_t* temp = (uint8_t*)BX_ALLOC(g_allocator, size); + bimg::imageCopy(temp + , mip.m_height + , mip.m_width * mip.m_bpp / 8 + , mip.m_depth + , mip.m_data + , pitch + ); + + imageInfos[kk].data = temp; + imageInfos[kk].width = mip.m_width; + imageInfos[kk].height = mip.m_height; + imageInfos[kk].depth = mip.m_depth; + imageInfos[kk].pitch = pitch; + imageInfos[kk].slice = slice; + imageInfos[kk].size = size; + imageInfos[kk].mipLevel = lod; + imageInfos[kk].layer = side; + } + } + ++kk; + } + } + + uint32_t totalMemSize = 0; + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + const uint32_t dstpitch = bx::strideAlign(imageInfos[ii].pitch, kMinBufferOffsetAlignment); + totalMemSize += dstpitch * imageInfos[ii].height; + //totalMemSize += imageInfos[ii].size; + } + + wgpu::Buffer stagingBuffer; + if (totalMemSize > 0) + { + wgpu::BufferDescriptor staginBufferDesc; + staginBufferDesc.size = totalMemSize; + staginBufferDesc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc; + staginBufferDesc.mappedAtCreation = true; + + stagingBuffer = s_renderWgpu->m_device.CreateBuffer(&staginBufferDesc); + void* stagingData = stagingBuffer.GetMappedRange(); + + uint64_t offset = 0; + + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + const uint32_t dstpitch = bx::strideAlign(imageInfos[ii].pitch, kMinBufferOffsetAlignment); + + const uint8_t* src = (uint8_t*)imageInfos[ii].data; + uint8_t* dst = (uint8_t*)stagingData; + + for (uint32_t yy = 0; yy < imageInfos[ii].height; ++yy, src += imageInfos[ii].pitch, offset += dstpitch) + { + bx::memCopy(dst + offset, src, imageInfos[ii].pitch); + } + + //bx::memCopy(dst + offset, imageInfos[ii].data, imageInfos[ii].size); + //offset += imageInfos[ii].size; + } + + stagingBuffer.Unmap(); + } + + wgpu::ImageCopyBuffer* imageCopyBuffer = (wgpu::ImageCopyBuffer*)BX_ALLOC(g_allocator, sizeof(wgpu::ImageCopyBuffer) * numSrd); + wgpu::ImageCopyTexture* imageCopyTexture = (wgpu::ImageCopyTexture*)BX_ALLOC(g_allocator, sizeof(wgpu::ImageCopyTexture) * numSrd); + wgpu::Extent3D* textureCopySize = (wgpu::Extent3D*)BX_ALLOC(g_allocator, sizeof(wgpu::Extent3D) * numSrd); + + uint64_t offset = 0; + + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + const uint32_t dstpitch = bx::strideAlign(imageInfos[ii].pitch, kMinBufferOffsetAlignment); + + uint32_t idealWidth = bx::max<uint32_t>(1, m_width >> imageInfos[ii].mipLevel); + uint32_t idealHeight = bx::max<uint32_t>(1, m_height >> imageInfos[ii].mipLevel); + BX_PLACEMENT_NEW(&imageCopyBuffer[ii], wgpu::ImageCopyBuffer)(); + BX_PLACEMENT_NEW(&imageCopyTexture[ii], wgpu::ImageCopyTexture)(); + BX_PLACEMENT_NEW(&textureCopySize[ii], wgpu::Extent3D)(); + imageCopyBuffer[ii].buffer = stagingBuffer; + imageCopyBuffer[ii].layout.offset = offset; + imageCopyBuffer[ii].layout.bytesPerRow = dstpitch; // assume that image data are tightly aligned + imageCopyBuffer[ii].layout.rowsPerImage = 0; // assume that image data are tightly aligned + imageCopyTexture[ii].texture = m_ptr; + imageCopyTexture[ii].mipLevel = imageInfos[ii].mipLevel; + imageCopyTexture[ii].origin = { 0, 0, imageInfos[ii].layer }; + textureCopySize[ii] = { idealWidth, idealHeight, imageInfos[ii].depth }; + + offset += dstpitch * imageInfos[ii].height; + //offset += imageInfos[ii].size; + } + + + if (stagingBuffer) + { + wgpu::CommandEncoder encoder = s_renderWgpu->getBlitCommandEncoder(); + //wgpu::CommandEncoder encoder = s_renderWgpu->m_cmd.m_encoder; + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + encoder.CopyBufferToTexture(&imageCopyBuffer[ii], &imageCopyTexture[ii], &textureCopySize[ii]); + } + } + else + { + //VkCommandBuffer commandBuffer = s_renderVK->beginNewCommand(); + //setImageMemoryBarrier( + // commandBuffer + // , (m_flags & BGFX_TEXTURE_COMPUTE_WRITE + // ? VK_IMAGE_LAYOUT_GENERAL + // : VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL + // ) + //); + //s_renderVK->submitCommandAndWait(commandBuffer); + } + + //vkFreeMemory(device, stagingDeviceMem, allocatorCb); + //vkDestroy(stagingBuffer); + + BX_FREE(g_allocator, imageCopyBuffer); + BX_FREE(g_allocator, imageCopyTexture); + BX_FREE(g_allocator, textureCopySize); + for (uint32_t ii = 0; ii < numSrd; ++ii) + { + BX_FREE(g_allocator, imageInfos[ii].data); + } + BX_FREE(g_allocator, imageInfos); + } + } + + void TextureWgpu::update(uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) + { + const uint32_t bpp = bimg::getBitsPerPixel(bimg::TextureFormat::Enum(m_textureFormat) ); + const uint32_t rectpitch = _rect.m_width*bpp/8; + const uint32_t srcpitch = UINT16_MAX == _pitch ? rectpitch : _pitch; + const uint16_t zz = (m_type == Texture3D) ? _z : _side; + // TODO (hugoam) This won't work for 3D texture arrays, but do we even support that + + const bool convert = m_textureFormat != m_requestedFormat; + + uint8_t* data = _mem->data; + uint8_t* temp = NULL; + + if (convert) + { + temp = (uint8_t*)BX_ALLOC(g_allocator, rectpitch*_rect.m_height); + bimg::imageDecodeToBgra8( + g_allocator + , temp + , data + , _rect.m_width + , _rect.m_height + , srcpitch + , bimg::TextureFormat::Enum(m_requestedFormat) + ); + data = temp; + } + + const uint32_t dstpitch = bx::strideAlign(rectpitch, kMinBufferOffsetAlignment); + + wgpu::BufferDescriptor desc; + desc.size = dstpitch * _rect.m_height; + desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::CopySrc; + desc.mappedAtCreation = true; + + wgpu::Buffer staging = s_renderWgpu->m_device.CreateBuffer(&desc); + + const uint8_t* src = (uint8_t*)data; + uint8_t* dst = (uint8_t*)staging.GetMappedRange(); + uint64_t offset = 0; + + for (uint32_t yy = 0; yy < _rect.m_height; ++yy, src += srcpitch, offset += dstpitch) + { + const uint32_t size = bx::strideAlign(rectpitch, 4); + bx::memCopy(dst + offset, src, size); + } + + staging.Unmap(); + + wgpu::ImageCopyBuffer srcView; + srcView.buffer = staging; + srcView.layout.bytesPerRow = dstpitch; + srcView.layout.rowsPerImage = 0; + + wgpu::ImageCopyTexture destView; + destView.texture = m_ptr; + destView.mipLevel = _mip; + destView.origin = { _rect.m_x, _rect.m_y, zz }; + + wgpu::Extent3D destExtent = { _rect.m_width, _rect.m_height, _depth }; + + //region.imageSubresource.aspectMask = m_vkTextureAspect; + + wgpu::CommandEncoder encoder = s_renderWgpu->getBlitCommandEncoder(); + //wgpu::CommandEncoder encoder = s_renderWgpu->m_cmd.m_encoder; + encoder.CopyBufferToTexture(&srcView, &destView, &destExtent); + + //wgpu::CommandBuffer copy = encoder.Finish(); + //wgpu::Queue queue = s_renderWgpu->m_queue; + //queue.Submit(1, ©); + + //staging.Destroy(); + + if (NULL != temp) + { + BX_FREE(g_allocator, temp); + } + } + + void BindStateWgpu::clear() + { + m_bindGroup = NULL; + } + + void StagingBufferWgpu::create(uint32_t _size, bool mapped) + { + m_size = _size; + + wgpu::BufferDescriptor desc; + desc.size = _size; + desc.usage = wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc; + desc.mappedAtCreation = mapped; + + m_buffer = s_renderWgpu->m_device.CreateBuffer(&desc); + + if (mapped) + { + m_data = m_buffer.GetMappedRange(); + } + else + { + map(); + } + } + + void StagingBufferWgpu::map() + { + auto ready = [](WGPUBufferMapAsyncStatus status, void* userdata) + { + StagingBufferWgpu* staging = static_cast<StagingBufferWgpu*>(userdata); + BX_WARN(status == WGPUBufferMapAsyncStatus_Success, "Failed mapping staging buffer (size %d) for writing with error %d", staging->m_size, status); + if (status == WGPUBufferMapAsyncStatus_Success) + { + void* data = staging->m_buffer.GetMappedRange(); + staging->mapped(data); + } + }; + + m_buffer.MapAsync(wgpu::MapMode::Write, 0, m_size, ready, this); + } + + void StagingBufferWgpu::unmap() + { + m_data = NULL; + m_buffer.Unmap(); + } + + void StagingBufferWgpu::destroy() + { + m_buffer = NULL; + } + + void StagingBufferWgpu::mapped(void* _data) + { + m_data = _data; + } + + void ScratchBufferWgpu::create(uint32_t _size) + { + m_offset = 0; + m_size = _size; + + wgpu::BufferDescriptor desc; + desc.size = BGFX_CONFIG_MAX_DRAW_CALLS * 128; + desc.usage = wgpu::BufferUsage::CopyDst | wgpu::BufferUsage::Uniform; + + m_buffer = s_renderWgpu->m_device.CreateBuffer(&desc); + } + + void ScratchBufferWgpu::destroy() + { + } + + void ScratchBufferWgpu::begin() + { + for (uint8_t ii = 0; ii < WEBGPU_NUM_UNIFORM_BUFFERS; ++ii) + { + if (NULL != s_renderWgpu->m_uniformBuffers[ii].m_data) + { + m_staging = &s_renderWgpu->m_uniformBuffers[ii]; + break; + } + } + + BX_ASSERT(NULL != m_staging, "No available mapped uniform buffer"); + } + + uint32_t ScratchBufferWgpu::write(void* data, uint64_t _size, uint64_t _offset) + { + BX_ASSERT(nullptr != m_staging, "Cannot write uniforms outside of begin()/submit() calls"); + BX_ASSERT(m_size > m_offset + _offset, "Out-of-bounds scratch buffer write"); + uint32_t offset = m_offset; + bx::memCopy((void*)((uint8_t*)m_staging->m_data + offset), data, _size); + m_offset += _offset; + return offset; + } + + uint32_t ScratchBufferWgpu::write(void* data, uint64_t _size) + { + BX_ASSERT(nullptr != m_staging, "Cannot write uniforms outside of begin()/submit() calls"); + BX_ASSERT(m_size > m_offset + _size, "Out-of-bounds scratch buffer write"); + uint32_t offset = m_offset; + bx::memCopy((void*)((uint8_t*)m_staging->m_data + offset), data, _size); + m_offset += _size; + return offset; + } + + void ScratchBufferWgpu::submit() + { + m_staging->unmap(); + + if (m_offset != 0) + { + wgpu::CommandEncoder& bce = s_renderWgpu->getStagingEncoder(); + bce.CopyBufferToBuffer(m_staging->m_buffer, 0, m_buffer, 0, m_offset); + } + } + + void ScratchBufferWgpu::release() + { + m_staging->map(); + m_staging = NULL; + m_offset = 0; + } + + void BindStateCacheWgpu::create() //(uint32_t _maxBindGroups) + { + //m_maxBindStates = 1024; // _maxBindStates; + m_currentBindState = 0; + } + + void BindStateCacheWgpu::destroy() + { + reset(); + } + + void BindStateCacheWgpu::reset() + { + for (size_t i = 0; i < m_currentBindState; ++i) + { + m_bindStates[i] = {}; + } + + m_currentBindState = 0; + } + + wgpu::TextureView TextureWgpu::getTextureMipLevel(int _mip) + { + if (_mip >= 0 + && _mip < m_numMips + && m_ptr) + { + if (!m_ptrMips[_mip]) + { + wgpu::TextureViewDescriptor desc; + desc.baseMipLevel = _mip; + desc.mipLevelCount = 1; + + desc.format = s_textureFormat[m_textureFormat].m_fmt; + + if (TextureCube == m_type) + { + //desc.dimension = MTLTextureType2DArray; + desc.baseArrayLayer = 0; + desc.arrayLayerCount = m_numLayers * 6; + } + else + { + desc.baseArrayLayer = 0; + desc.arrayLayerCount = m_numLayers; + } + + m_ptrMips[_mip] = m_ptr.CreateView(&desc); + } + + return m_ptrMips[_mip]; + } + + return wgpu::TextureView(); + } + + void SwapChainWgpu::init(wgpu::Device _device, void* _nwh, uint32_t _width, uint32_t _height) + { + BX_UNUSED(_nwh); + + wgpu::SwapChainDescriptor desc; + desc.usage = wgpu::TextureUsage::OutputAttachment; + desc.width = _width; + desc.height = _height; + +#if !BX_PLATFORM_EMSCRIPTEN + m_impl = createSwapChain(_device, _nwh); + + desc.presentMode = wgpu::PresentMode::Immediate; + desc.format = wgpu::TextureFormat::RGBA8Unorm; + desc.implementation = reinterpret_cast<uint64_t>(&m_impl); + m_swapChain = _device.CreateSwapChain(nullptr, &desc); +#else + wgpu::SurfaceDescriptorFromCanvasHTMLSelector canvasDesc{}; + canvasDesc.selector = "#canvas"; + + wgpu::SurfaceDescriptor surfDesc{}; + surfDesc.nextInChain = &canvasDesc; + wgpu::Surface surface = wgpu::Instance().CreateSurface(&surfDesc); + + desc.presentMode = wgpu::PresentMode::Fifo; + desc.format = wgpu::TextureFormat::BGRA8Unorm; + m_swapChain = _device.CreateSwapChain(surface, &desc); +#endif + + m_colorFormat = desc.format; + m_depthFormat = wgpu::TextureFormat::Depth24PlusStencil8; + } + + void SwapChainWgpu::resize(FrameBufferWgpu& _frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags) + { + BX_TRACE("SwapChainWgpu::resize"); + + const int32_t sampleCount = s_msaa[(_flags&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT]; + + wgpu::TextureFormat format = (_flags & BGFX_RESET_SRGB_BACKBUFFER) +#ifdef DAWN_ENABLE_BACKEND_VULKAN + ? wgpu::TextureFormat::BGRA8UnormSrgb + : wgpu::TextureFormat::BGRA8Unorm +#else + ? wgpu::TextureFormat::RGBA8UnormSrgb + : wgpu::TextureFormat::RGBA8Unorm +#endif + ; + +#if !BX_PLATFORM_EMSCRIPTEN + m_swapChain.Configure(format, wgpu::TextureUsage::OutputAttachment, _width, _height); +#endif + + m_colorFormat = format; + m_depthFormat = wgpu::TextureFormat::Depth24PlusStencil8; + + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(1); + murmur.add((uint32_t)m_colorFormat); + murmur.add((uint32_t)m_depthFormat); + murmur.add((uint32_t)sampleCount); + _frameBuffer.m_pixelFormatHash = murmur.end(); + + wgpu::TextureDescriptor desc; + + desc.dimension = wgpu::TextureDimension::e2D; + + desc.size.width = _width; + desc.size.height = _height; + desc.size.depthOrArrayLayers = 1; + desc.mipLevelCount = 1; + desc.sampleCount = sampleCount; + desc.usage = wgpu::TextureUsage::OutputAttachment; + + if (m_backBufferDepth) + { + m_backBufferDepth.Destroy(); + } + + desc.format = wgpu::TextureFormat::Depth24PlusStencil8; + + m_backBufferDepth = s_renderWgpu->m_device.CreateTexture(&desc); + + if (sampleCount > 1) + { + if (m_backBufferColorMsaa) + { + m_backBufferColorMsaa.Destroy(); + } + + desc.format = m_colorFormat; + desc.sampleCount = sampleCount; + + m_backBufferColorMsaa = s_renderWgpu->m_device.CreateTexture(&desc); + } + } + + void SwapChainWgpu::flip() + { + m_drawable = m_swapChain.GetCurrentTextureView(); + } + + wgpu::TextureView SwapChainWgpu::current() + { + if (!m_drawable) + m_drawable = m_swapChain.GetCurrentTextureView(); + return m_drawable; + } + + void FrameBufferWgpu::create(uint8_t _num, const Attachment* _attachment) + { + m_swapChain = NULL; + m_denseIdx = UINT16_MAX; + m_num = 0; + m_width = 0; + m_height = 0; + + for (uint32_t ii = 0; ii < _num; ++ii) + { + const Attachment& at = _attachment[ii]; + TextureHandle handle = at.handle; + + if (isValid(handle) ) + { + const TextureWgpu& texture = s_renderWgpu->m_textures[handle.idx]; + + if (0 == m_width) + { + m_width = texture.m_width; + m_height = texture.m_height; + } + + if (bimg::isDepth(bimg::TextureFormat::Enum(texture.m_textureFormat) ) ) + { + m_depthHandle = handle; + m_depthAttachment = at; + } + else + { + m_colorHandle[m_num] = handle; + m_colorAttachment[m_num] = at; + m_num++; + } + } + } + + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(m_num); + + for (uint32_t ii = 0; ii < m_num; ++ii) + { + const TextureWgpu& texture = s_renderWgpu->m_textures[m_colorHandle[ii].idx]; + murmur.add(uint32_t(s_textureFormat[texture.m_textureFormat].m_fmt) ); + } + + if (!isValid(m_depthHandle) ) + { + murmur.add(uint32_t(wgpu::TextureFormat::Undefined) ); + } + else + { + const TextureWgpu& depthTexture = s_renderWgpu->m_textures[m_depthHandle.idx]; + murmur.add(uint32_t(s_textureFormat[depthTexture.m_textureFormat].m_fmt) ); + } + + murmur.add(1); // SampleCount + + m_pixelFormatHash = murmur.end(); + } + + bool FrameBufferWgpu::create(uint16_t _denseIdx, void* _nwh, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, TextureFormat::Enum _depthFormat) + { + BX_UNUSED(_format, _depthFormat); + m_swapChain = BX_NEW(g_allocator, SwapChainWgpu); + m_num = 0; + m_width = _width; + m_height = _height; + m_nwh = _nwh; + m_denseIdx = _denseIdx; + + m_swapChain->init(s_renderWgpu->m_device, _nwh, _width, _height); + m_swapChain->resize(*this, _width, _height, 0); + + return m_swapChain->m_swapChain != NULL; + } + + void FrameBufferWgpu::postReset() + { + } + + uint16_t FrameBufferWgpu::destroy() + { + if (NULL != m_swapChain) + { + BX_DELETE(g_allocator, m_swapChain); + m_swapChain = NULL; + } + + m_num = 0; + m_nwh = NULL; + m_depthHandle.idx = kInvalidHandle; + + uint16_t denseIdx = m_denseIdx; + m_denseIdx = UINT16_MAX; + + return denseIdx; + } + + void CommandQueueWgpu::init(wgpu::Queue _queue) + { + m_queue = _queue; +#if BGFX_CONFIG_MULTITHREADED + //m_framesSemaphore.post(BGFX_CONFIG_MAX_FRAME_LATENCY); +#endif + } + + void CommandQueueWgpu::shutdown() + { + finish(true); + } + + void CommandQueueWgpu::beginRender() + { + m_renderEncoder = s_renderWgpu->m_device.CreateCommandEncoder(); + } + + void CommandQueueWgpu::beginStaging() + { + m_stagingEncoder = s_renderWgpu->m_device.CreateCommandEncoder(); + } + + inline void commandBufferFinishedCallback(void* _data) + { +#if BGFX_CONFIG_MULTITHREADED + CommandQueueWgpu* queue = (CommandQueueWgpu*)_data; + if (queue) + { + //queue->m_framesSemaphore.post(); + } +#else + BX_UNUSED(_data); +#endif + } + + void CommandQueueWgpu::kick(bool _endFrame, bool _waitForFinish) + { + if (m_renderEncoder) + { + if (_endFrame) + { + m_releaseWriteIndex = (m_releaseWriteIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY; + //m_encoder.addCompletedHandler(commandBufferFinishedCallback, this); + } + + if (m_stagingEncoder) + { + wgpu::CommandBuffer commands = m_stagingEncoder.Finish(); + m_queue.Submit(1, &commands); + } + + wgpu::CommandBuffer commands = m_renderEncoder.Finish(); + m_queue.Submit(1, &commands); + + if (_waitForFinish) + { +#if BGFX_CONFIG_MULTITHREADED + //m_framesSemaphore.post(); +#endif + } + + m_stagingEncoder = NULL; + m_renderEncoder = NULL; + } + } + + void CommandQueueWgpu::finish(bool _finishAll) + { + if (_finishAll) + { + uint32_t count = m_renderEncoder + ? 2 + : 3 + ; + + for (uint32_t ii = 0; ii < count; ++ii) + { + consume(); + } + +#if BGFX_CONFIG_MULTITHREADED + //m_framesSemaphore.post(count); +#endif + } + else + { + consume(); + } + } + + void CommandQueueWgpu::release(wgpu::Buffer _buffer) + { + m_release[m_releaseWriteIndex].push_back(_buffer); + } + + void CommandQueueWgpu::consume() + { +#if BGFX_CONFIG_MULTITHREADED + //m_framesSemaphore.wait(); +#endif + + m_releaseReadIndex = (m_releaseReadIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY; + + for (wgpu::Buffer& buffer : m_release[m_releaseReadIndex]) + { + buffer.Destroy(); + } + + m_release[m_releaseReadIndex].clear(); + } + + void TimerQueryWgpu::init() + { + m_frequency = bx::getHPFrequency(); + } + + void TimerQueryWgpu::shutdown() + { + } + + uint32_t TimerQueryWgpu::begin(uint32_t _resultIdx, uint32_t _frameNum) + { + BX_UNUSED(_resultIdx); + BX_UNUSED(_frameNum); + return 0; + } + + void TimerQueryWgpu::end(uint32_t _idx) + { + BX_UNUSED(_idx); + } + +#if 0 + static void setTimestamp(void* _data) + { + *( (int64_t*)_data) = bx::getHPCounter(); + } +#endif + + void TimerQueryWgpu::addHandlers(wgpu::CommandBuffer& _commandBuffer) + { + BX_UNUSED(_commandBuffer); + + while (0 == m_control.reserve(1) ) + { + m_control.consume(1); + } + + //uint32_t offset = m_control.m_current; + //_commandBuffer.addScheduledHandler(setTimestamp, &m_result[offset].m_begin); + //_commandBuffer.addCompletedHandler(setTimestamp, &m_result[offset].m_end); + m_control.commit(1); + } + + bool TimerQueryWgpu::get() + { + if (0 != m_control.available() ) + { + uint32_t offset = m_control.m_read; + m_begin = m_result[offset].m_begin; + m_end = m_result[offset].m_end; + m_elapsed = m_end - m_begin; + + m_control.consume(1); + + return true; + } + + return false; + } + + void RendererContextWgpu::submitBlit(BlitState& _bs, uint16_t _view) + { + if (!_bs.hasItem(_view) ) + { + return; + } + + endEncoding(); + + wgpu::CommandEncoder& bce = getBlitCommandEncoder(); + + while (_bs.hasItem(_view) ) + { + const BlitItem& blit = _bs.advance(); + + const TextureWgpu& src = m_textures[blit.m_src.idx]; + const TextureWgpu& dst = m_textures[blit.m_dst.idx]; + + bool readBack = !!(dst.m_flags & BGFX_TEXTURE_READ_BACK); + + wgpu::ImageCopyTexture srcView; + srcView.texture = src.m_ptr; + srcView.origin = { blit.m_srcX, blit.m_srcY, blit.m_srcZ }; + srcView.mipLevel = blit.m_srcMip; + + wgpu::ImageCopyTexture dstView; + dstView.texture = dst.m_ptr; + dstView.origin = { blit.m_dstX, blit.m_dstY, blit.m_dstZ }; + dstView.mipLevel = blit.m_dstMip; + + if (blit.m_depth == 0) + { + wgpu::Extent3D copyExtent = { blit.m_width, blit.m_height, 1 }; + bce.CopyTextureToTexture(&srcView, &dstView, ©Extent); + } + else + { + wgpu::Extent3D copyExtent = { blit.m_width, blit.m_height, blit.m_depth }; + bce.CopyTextureToTexture(&srcView, &dstView, ©Extent); + } + + if (readBack) + { + //bce..synchronizeTexture(dst.m_ptr, 0, blit.m_dstMip); + } + } + + //if (bce) + //{ + // bce.endEncoding(); + // bce = 0; + //} + } + + void RendererContextWgpu::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) + { + if(_render->m_capture) + { + renderDocTriggerCapture(); + } + + m_cmd.finish(false); + + if (!m_cmd.m_renderEncoder) + { + m_cmd.beginRender(); + } + + BGFX_WEBGPU_PROFILER_BEGIN_LITERAL("rendererSubmit", kColorFrame); + + int64_t timeBegin = bx::getHPCounter(); + int64_t captureElapsed = 0; + + //m_gpuTimer.addHandlers(m_encoder); + + updateResolution(_render->m_resolution); + + m_frameIndex = 0; // (m_frameIndex + 1) % BGFX_CONFIG_MAX_FRAME_LATENCY; + + ScratchBufferWgpu& scratchBuffer = m_scratchBuffers[m_frameIndex]; + scratchBuffer.begin(); + + BindStateCacheWgpu& bindStates = m_bindStateCache[m_frameIndex]; + bindStates.reset(); + + if (0 < _render->m_iboffset) + { + BGFX_PROFILER_SCOPE("bgfx/Update transient index buffer", kColorResource); + TransientIndexBuffer* ib = _render->m_transientIb; + m_indexBuffers[ib->handle.idx].update(0, bx::strideAlign(_render->m_iboffset,4), ib->data, true); + } + + if (0 < _render->m_vboffset) + { + BGFX_PROFILER_SCOPE("bgfx/Update transient vertex buffer", kColorResource); + TransientVertexBuffer* vb = _render->m_transientVb; + m_vertexBuffers[vb->handle.idx].update(0, bx::strideAlign(_render->m_vboffset,4), vb->data, true); + } + + _render->sort(); + + RenderDraw currentState; + currentState.clear(); + currentState.m_stateFlags = BGFX_STATE_NONE; + currentState.m_stencil = packStencil(BGFX_STENCIL_NONE, BGFX_STENCIL_NONE); + + RenderBind currentBind; + currentBind.clear(); + + static ViewState viewState; + viewState.reset(_render); + uint32_t blendFactor = 0; + + //bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); + + ProgramHandle currentProgram = BGFX_INVALID_HANDLE; + uint32_t currentBindHash = 0; + uint32_t currentBindLayoutHash = 0; + BindStateWgpu* previousBindState = NULL; + SortKey key; + uint16_t view = UINT16_MAX; + FrameBufferHandle fbh = { BGFX_CONFIG_MAX_FRAME_BUFFERS }; + + BlitState bs(_render); + + const uint64_t primType = 0; + uint8_t primIndex = uint8_t(primType >> BGFX_STATE_PT_SHIFT); + PrimInfo prim = s_primInfo[primIndex]; + const uint32_t maxComputeBindings = g_caps.limits.maxComputeBindings; + + // TODO store this + static wgpu::RenderPassEncoder rce; + + PipelineStateWgpu* currentPso = NULL; + + bool wasCompute = false; + bool viewHasScissor = false; + Rect viewScissorRect; + viewScissorRect.clear(); + + uint32_t statsNumPrimsSubmitted[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumPrimsRendered[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumInstances[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumDrawIndirect[BX_COUNTOF(s_primInfo)] = {}; + uint32_t statsNumIndices = 0; + uint32_t statsKeyType[2] = {}; + + Profiler<TimerQueryWgpu> profiler( + _render + , m_gpuTimer + , s_viewName + ); + + if (0 == (_render->m_debug & BGFX_DEBUG_IFH)) + { + viewState.m_rect = _render->m_view[0].m_rect; + int32_t numItems = _render->m_numRenderItems; + + for (int32_t item = 0; item < numItems;) + { + const uint64_t encodedKey = _render->m_sortKeys[item]; + const bool isCompute = key.decode(encodedKey, _render->m_viewRemap); + statsKeyType[isCompute]++; + + const bool viewChanged = 0 + || key.m_view != view + || item == numItems + ; + + const uint32_t itemIdx = _render->m_sortValues[item]; + const RenderItem& renderItem = _render->m_renderItem[itemIdx]; + const RenderBind& renderBind = _render->m_renderItemBind[itemIdx]; + ++item; + + if (viewChanged + || (!isCompute && wasCompute)) + { + view = key.m_view; + currentProgram = BGFX_INVALID_HANDLE; + + if (item > 1) + { + profiler.end(); + } + + BGFX_WEBGPU_PROFILER_END(); + setViewType(view, " "); + BGFX_WEBGPU_PROFILER_BEGIN(view, kColorView); + + profiler.begin(view); + + viewState.m_rect = _render->m_view[view].m_rect; + + submitBlit(bs, view); + + if (!isCompute) + { + const Rect& scissorRect = _render->m_view[view].m_scissor; + viewHasScissor = !scissorRect.isZero(); + viewScissorRect = viewHasScissor ? scissorRect : viewState.m_rect; + Clear& clr = _render->m_view[view].m_clear; + + Rect viewRect = viewState.m_rect; + bool clearWithRenderPass = false; + + if (!m_renderEncoder + || fbh.idx != _render->m_view[view].m_fbh.idx) + { + endEncoding(); + + fbh = _render->m_view[view].m_fbh; + + uint32_t width = m_resolution.width; + uint32_t height = m_resolution.height; + + if (isValid(fbh)) + { + FrameBufferWgpu& frameBuffer = m_frameBuffers[fbh.idx]; + width = frameBuffer.m_width; + height = frameBuffer.m_height; + } + + clearWithRenderPass = true + && 0 == viewRect.m_x + && 0 == viewRect.m_y + && width == viewRect.m_width + && height == viewRect.m_height + ; + + rce = renderPass(_render, fbh, clearWithRenderPass, clr, s_viewName[view]); + } + else if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + rce.PopDebugGroup(); + } + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + rce.PushDebugGroup(s_viewName[view]); + } + + //rce.setTriangleFillMode(wireframe ? MTLTriangleFillModeLines : MTLTriangleFillModeFill); + + const Rect& rect = viewState.m_rect; + rce.SetViewport(rect.m_x, rect.m_y, rect.m_width, rect.m_height, 0.0f, 1.0f); + rce.SetScissorRect(rect.m_x, rect.m_y, rect.m_width, rect.m_height); + + + if (BGFX_CLEAR_NONE != (clr.m_flags & BGFX_CLEAR_MASK) + && !clearWithRenderPass) + { + clearQuad(_clearQuad, viewState.m_rect, clr, _render->m_colorPalette); + } + } + } + + if (isCompute) + { + if (!wasCompute) + { + wasCompute = true; + + endEncoding(); + rce = NULL; + + setViewType(view, "C"); + BGFX_WEBGPU_PROFILER_END(); + BGFX_WEBGPU_PROFILER_BEGIN(view, kColorCompute); + + m_computeEncoder = m_cmd.m_renderEncoder.BeginComputePass(); + } + else if (viewChanged) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + m_computeEncoder.PopDebugGroup(); + } + + endEncoding(); + m_computeEncoder = m_cmd.m_renderEncoder.BeginComputePass(); + } + + if (viewChanged) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + s_viewName[view][3] = L'C'; + m_computeEncoder.PushDebugGroup(s_viewName[view]); + s_viewName[view][3] = L' '; + } + } + + const RenderCompute& compute = renderItem.compute; + + bool programChanged = false; + bool constantsChanged = compute.m_uniformBegin < compute.m_uniformEnd; + rendererUpdateUniforms(this, _render->m_uniformBuffer[compute.m_uniformIdx], compute.m_uniformBegin, compute.m_uniformEnd); + + if (key.m_program.idx != currentProgram.idx) + { + currentProgram = key.m_program; + + currentPso = getComputePipelineState(currentProgram); + + if (NULL == currentPso) + { + currentProgram = BGFX_INVALID_HANDLE; + continue; + } + + m_computeEncoder.SetPipeline(currentPso->m_cps); + programChanged = + constantsChanged = true; + } + + if (!isValid(currentProgram) + || NULL == currentPso) + BX_WARN(false, "Invalid program / No PSO"); + + const ProgramWgpu& program = m_program[currentProgram.idx]; + + if (constantsChanged) + { + UniformBuffer* vcb = program.m_vsh->m_constantBuffer; + if (NULL != vcb) + { + commit(*vcb); + } + } + + viewState.setPredefined<4>(this, view, program, _render, compute); + + uint32_t numOffset = 0; + uint32_t offsets[2] = { 0, 0 }; + if (program.m_vsh->m_size > 0) + { + offsets[numOffset++] = scratchBuffer.write(m_vsScratch, program.m_vsh->m_gpuSize); + } + + BindStateWgpu& bindState = allocAndFillBindState(program, bindStates, scratchBuffer, renderBind); + + bindProgram(m_computeEncoder, program, bindState, numOffset, offsets); + + if (isValid(compute.m_indirectBuffer)) + { + const VertexBufferWgpu& vb = m_vertexBuffers[compute.m_indirectBuffer.idx]; + + uint32_t numDrawIndirect = UINT16_MAX == compute.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : compute.m_numIndirect + ; + + uint32_t args = compute.m_startIndirect * BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + m_computeEncoder.DispatchIndirect( + vb.m_ptr + , args + ); + args += BGFX_CONFIG_DRAW_INDIRECT_STRIDE; + } + } + else + { + m_computeEncoder.Dispatch(compute.m_numX, compute.m_numY, compute.m_numZ); + } + + continue; + } + + + bool resetState = viewChanged || wasCompute; + + if (wasCompute) + { + wasCompute = false; + currentProgram = BGFX_INVALID_HANDLE; + + setViewType(view, " "); + BGFX_WEBGPU_PROFILER_END(); + BGFX_WEBGPU_PROFILER_BEGIN(view, kColorDraw); + } + + const RenderDraw& draw = renderItem.draw; + + // TODO (hugoam) + //const bool depthWrite = !!(BGFX_STATE_WRITE_Z & draw.m_stateFlags); + const uint64_t newFlags = draw.m_stateFlags; + uint64_t changedFlags = currentState.m_stateFlags ^ draw.m_stateFlags; + currentState.m_stateFlags = newFlags; + + const uint64_t newStencil = draw.m_stencil; + uint64_t changedStencil = (currentState.m_stencil ^ draw.m_stencil) & BGFX_STENCIL_FUNC_REF_MASK; + currentState.m_stencil = newStencil; + + if (resetState) + { + wasCompute = false; + + currentState.clear(); + currentState.m_scissor = !draw.m_scissor; + changedFlags = BGFX_STATE_MASK; + changedStencil = packStencil(BGFX_STENCIL_MASK, BGFX_STENCIL_MASK); + currentState.m_stateFlags = newFlags; + currentState.m_stencil = newStencil; + + currentBind.clear(); + + currentProgram = BGFX_INVALID_HANDLE; + const uint64_t pt = newFlags & BGFX_STATE_PT_MASK; + primIndex = uint8_t(pt >> BGFX_STATE_PT_SHIFT); + } + + if (prim.m_type != s_primInfo[primIndex].m_type) + { + prim = s_primInfo[primIndex]; + } + + uint16_t scissor = draw.m_scissor; + if (currentState.m_scissor != scissor) + { + currentState.m_scissor = scissor; + + if (UINT16_MAX == scissor) + { + if (viewHasScissor) + { + const auto& r = viewScissorRect; + rce.SetScissorRect(r.m_x, r.m_y, r.m_width, r.m_height); + } + else + { // can't disable: set to view rect + const auto& r = viewState.m_rect; + rce.SetScissorRect(r.m_x, r.m_y, r.m_width, r.m_height); + } + } + else + { + Rect scissorRect; + scissorRect.setIntersect(viewScissorRect, _render->m_frameCache.m_rectCache.m_cache[scissor]); + + const auto& r = scissorRect; + if (r.m_width == 0 || r.m_height == 0) + { + continue; + } + rce.SetScissorRect(r.m_x, r.m_y, r.m_width, r.m_height); + } + + } + + if (0 != changedStencil) + { + const uint32_t fstencil = unpackStencil(0, draw.m_stencil); + const uint32_t ref = (fstencil & BGFX_STENCIL_FUNC_REF_MASK) >> BGFX_STENCIL_FUNC_REF_SHIFT; + rce.SetStencilReference(ref); + } + + if ((0 | BGFX_STATE_PT_MASK) & changedFlags) + { + const uint64_t pt = newFlags & BGFX_STATE_PT_MASK; + primIndex = uint8_t(pt >> BGFX_STATE_PT_SHIFT); + if (prim.m_type != s_primInfo[primIndex].m_type) + { + prim = s_primInfo[primIndex]; + } + } + + if (blendFactor != draw.m_rgba + && !(newFlags & BGFX_STATE_BLEND_INDEPENDENT)) + { + const uint32_t rgba = draw.m_rgba; + float rr = ((rgba >> 24)) / 255.0f; + float gg = ((rgba >> 16) & 0xff) / 255.0f; + float bb = ((rgba >> 8) & 0xff) / 255.0f; + float aa = ((rgba) & 0xff) / 255.0f; + wgpu::Color color = { rr, gg, bb, aa }; + rce.SetBlendColor(&color); + + blendFactor = draw.m_rgba; + } + + bool programChanged = false; + bool constantsChanged = draw.m_uniformBegin < draw.m_uniformEnd; + rendererUpdateUniforms(this, _render->m_uniformBuffer[draw.m_uniformIdx], draw.m_uniformBegin, draw.m_uniformEnd); + + bool vertexStreamChanged = hasVertexStreamChanged(currentState, draw); + + if (key.m_program.idx != currentProgram.idx + || vertexStreamChanged + || (0 + | BGFX_STATE_BLEND_MASK + | BGFX_STATE_BLEND_EQUATION_MASK + | BGFX_STATE_WRITE_RGB + | BGFX_STATE_WRITE_A + | BGFX_STATE_BLEND_INDEPENDENT + | BGFX_STATE_MSAA + | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE + ) & changedFlags + || ((blendFactor != draw.m_rgba) && !!(newFlags & BGFX_STATE_BLEND_INDEPENDENT))) + { + currentProgram = key.m_program; + + currentState.m_streamMask = draw.m_streamMask; + currentState.m_instanceDataBuffer.idx = draw.m_instanceDataBuffer.idx; + currentState.m_instanceDataOffset = draw.m_instanceDataOffset; + currentState.m_instanceDataStride = draw.m_instanceDataStride; + + const VertexLayout* decls[BGFX_CONFIG_MAX_VERTEX_STREAMS]; + + uint32_t numVertices = draw.m_numVertices; + uint8_t numStreams = 0; + for (uint32_t idx = 0, streamMask = draw.m_streamMask + ; 0 != streamMask + ; streamMask >>= 1, idx += 1, ++numStreams + ) + { + const uint32_t ntz = bx::uint32_cnttz(streamMask); + streamMask >>= ntz; + idx += ntz; + + currentState.m_stream[idx].m_layoutHandle = draw.m_stream[idx].m_layoutHandle; + currentState.m_stream[idx].m_handle = draw.m_stream[idx].m_handle; + currentState.m_stream[idx].m_startVertex = draw.m_stream[idx].m_startVertex; + + const uint16_t handle = draw.m_stream[idx].m_handle.idx; + const VertexBufferWgpu& vb = m_vertexBuffers[handle]; + const uint16_t decl = isValid(draw.m_stream[idx].m_layoutHandle) + ? draw.m_stream[idx].m_layoutHandle.idx + : vb.m_layoutHandle.idx; + const VertexLayout& vertexDecl = m_vertexDecls[decl]; + const uint32_t stride = vertexDecl.m_stride; + + decls[numStreams] = &vertexDecl; + + numVertices = bx::uint32_min(UINT32_MAX == draw.m_numVertices + ? vb.m_size / stride + : draw.m_numVertices + , numVertices + ); + const uint32_t offset = draw.m_stream[idx].m_startVertex * stride; + + rce.SetVertexBuffer(idx, vb.m_ptr, offset); + } + + if (!isValid(currentProgram)) + { + continue; + } + else + { + currentPso = NULL; + + if (0 < numStreams) + { + currentPso = getPipelineState( + newFlags + , newStencil + , draw.m_rgba + , fbh + , numStreams + , decls + , draw.isIndex16() + , currentProgram + , uint8_t(draw.m_instanceDataStride / 16) + ); + } + + if (NULL == currentPso) + { + currentProgram = BGFX_INVALID_HANDLE; + continue; + } + + rce.SetPipeline(currentPso->m_rps); + } + + if (isValid(draw.m_instanceDataBuffer)) + { + const VertexBufferWgpu& inst = m_vertexBuffers[draw.m_instanceDataBuffer.idx]; + rce.SetVertexBuffer(numStreams/*+1*/, inst.m_ptr, draw.m_instanceDataOffset); + } + + programChanged = + constantsChanged = true; + } + + if (isValid(currentProgram)) + { + const ProgramWgpu& program = m_program[currentProgram.idx]; + + if (constantsChanged) + { + UniformBuffer* vcb = program.m_vsh->m_constantBuffer; + if (NULL != vcb) + { + commit(*vcb); + } + } + + if (constantsChanged) + { + UniformBuffer* fcb = program.m_fsh->m_constantBuffer; + if (NULL != fcb) + { + commit(*fcb); + } + } + + viewState.setPredefined<4>(this, view, program, _render, draw); + + bool hasPredefined = 0 < program.m_numPredefined; + + uint32_t numOffset = 0; + uint32_t offsets[2] = { 0, 0 }; + if (constantsChanged + || hasPredefined) + { + //viewState.setPredefined<4>(this, view, program, _render, draw, programChanged || viewChanged); + + const uint32_t vsize = program.m_vsh->m_gpuSize; + const uint32_t fsize = (NULL != program.m_fsh ? program.m_fsh->m_gpuSize : 0); + + if (program.m_vsh->m_size > 0) + { + offsets[numOffset++] = scratchBuffer.write(m_vsScratch, vsize); + } + if (fsize > 0) + { + offsets[numOffset++] = scratchBuffer.write(m_fsScratch, fsize); + } + } + + uint32_t bindHash = bx::hash<bx::HashMurmur2A>(renderBind.m_bind, sizeof(renderBind.m_bind)); + if (currentBindHash != bindHash + || currentBindLayoutHash != program.m_bindGroupLayoutHash) + { + currentBindHash = bindHash; + currentBindLayoutHash = program.m_bindGroupLayoutHash; + previousBindState = &bindStates.m_bindStates[bindStates.m_currentBindState]; + + allocAndFillBindState(program, bindStates, scratchBuffer, renderBind); + } + + BindStateWgpu& bindState = bindStates.m_bindStates[bindStates.m_currentBindState-1]; + + bindProgram(rce, program, bindState, numOffset, offsets); + } + + if (0 != currentState.m_streamMask) + { + uint32_t numVertices = draw.m_numVertices; + if (UINT32_MAX == numVertices) + { + const VertexBufferWgpu& vb = m_vertexBuffers[currentState.m_stream[0].m_handle.idx]; + uint16_t decl = !isValid(vb.m_layoutHandle) ? draw.m_stream[0].m_layoutHandle.idx : vb.m_layoutHandle.idx; + const VertexLayout& vertexDecl = m_vertexDecls[decl]; + numVertices = vb.m_size/vertexDecl.m_stride; + } + + uint32_t numIndices = 0; + uint32_t numPrimsSubmitted = 0; + uint32_t numInstances = 0; + uint32_t numPrimsRendered = 0; + uint32_t numDrawIndirect = 0; + + if (isValid(draw.m_indirectBuffer) ) + { + const VertexBufferWgpu& vb = m_vertexBuffers[draw.m_indirectBuffer.idx]; + + if (isValid(draw.m_indexBuffer) ) + { + const IndexBufferWgpu& ib = m_indexBuffers[draw.m_indexBuffer.idx]; + + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; + + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + rce.SetIndexBuffer(ib.m_ptr, ib.m_format, 0); + rce.DrawIndexedIndirect(vb.m_ptr, (draw.m_startIndirect + ii)* BGFX_CONFIG_DRAW_INDIRECT_STRIDE); + } + } + else + { + numDrawIndirect = UINT16_MAX == draw.m_numIndirect + ? vb.m_size/BGFX_CONFIG_DRAW_INDIRECT_STRIDE + : draw.m_numIndirect + ; + for (uint32_t ii = 0; ii < numDrawIndirect; ++ii) + { + rce.DrawIndirect(vb.m_ptr, (draw.m_startIndirect + ii)* BGFX_CONFIG_DRAW_INDIRECT_STRIDE); + } + } + } + else + { + if (isValid(draw.m_indexBuffer) ) + { + const IndexBufferWgpu& ib = m_indexBuffers[draw.m_indexBuffer.idx]; + const uint32_t indexSize = draw.isIndex16() ? 2 : 4; + + if (UINT32_MAX == draw.m_numIndices) + { + numIndices = ib.m_size/indexSize; + numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + rce.SetIndexBuffer(ib.m_ptr, ib.m_format, 0); + rce.DrawIndexed(numIndices, draw.m_numInstances, 0, 0, 0); + } + else if (prim.m_min <= draw.m_numIndices) + { + numIndices = draw.m_numIndices; + numPrimsSubmitted = numIndices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + rce.SetIndexBuffer(ib.m_ptr, ib.m_format, 0); + rce.DrawIndexed(numIndices, numInstances, draw.m_startIndex, 0, 0); + } + } + else + { + numPrimsSubmitted = numVertices/prim.m_div - prim.m_sub; + numInstances = draw.m_numInstances; + numPrimsRendered = numPrimsSubmitted*draw.m_numInstances; + + rce.Draw(numVertices, draw.m_numInstances, 0, 0); + } + } + + statsNumPrimsSubmitted[primIndex] += numPrimsSubmitted; + statsNumPrimsRendered[primIndex] += numPrimsRendered; + statsNumInstances[primIndex] += numInstances; + statsNumDrawIndirect[primIndex] += numDrawIndirect; + statsNumIndices += numIndices; + } + } + + if (wasCompute) + { + invalidateCompute(); + + setViewType(view, "C"); + BGFX_WEBGPU_PROFILER_END(); + BGFX_WEBGPU_PROFILER_BEGIN(view, kColorCompute); + } + + submitBlit(bs, BGFX_CONFIG_MAX_VIEWS); + + if (0 < _render->m_numRenderItems) + { + captureElapsed = -bx::getHPCounter(); + capture(); + rce = m_renderEncoder; + captureElapsed += bx::getHPCounter(); + + profiler.end(); + } + } + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION) ) + { + if (0 < _render->m_numRenderItems) + { + rce.PopDebugGroup(); + } + } + + BGFX_WEBGPU_PROFILER_END(); + + int64_t timeEnd = bx::getHPCounter(); + int64_t frameTime = timeEnd - timeBegin; + + static int64_t min = frameTime; + static int64_t max = frameTime; + min = bx::min<int64_t>(min, frameTime); + max = bx::max<int64_t>(max, frameTime); + + static uint32_t maxGpuLatency = 0; + static double maxGpuElapsed = 0.0f; + double elapsedGpuMs = 0.0; + + do + { + double toGpuMs = 1000.0 / double(m_gpuTimer.m_frequency); + elapsedGpuMs = m_gpuTimer.m_elapsed * toGpuMs; + maxGpuElapsed = elapsedGpuMs > maxGpuElapsed ? elapsedGpuMs : maxGpuElapsed; + } + while (m_gpuTimer.get() ); + + maxGpuLatency = bx::uint32_imax(maxGpuLatency, m_gpuTimer.m_control.available()-1); + + const int64_t timerFreq = bx::getHPFrequency(); + + Stats& perfStats = _render->m_perfStats; + perfStats.cpuTimeBegin = timeBegin; + perfStats.cpuTimeEnd = timeEnd; + perfStats.cpuTimerFreq = timerFreq; + perfStats.gpuTimeBegin = m_gpuTimer.m_begin; + perfStats.gpuTimeEnd = m_gpuTimer.m_end; + perfStats.gpuTimerFreq = m_gpuTimer.m_frequency; + perfStats.numDraw = statsKeyType[0]; + perfStats.numCompute = statsKeyType[1]; + perfStats.numBlit = _render->m_numBlitItems; + perfStats.maxGpuLatency = maxGpuLatency; + perfStats.gpuFrameNum = result.m_frameNum; + bx::memCopy(perfStats.numPrims, statsNumPrimsRendered, sizeof(perfStats.numPrims) ); + perfStats.gpuMemoryMax = -INT64_MAX; + perfStats.gpuMemoryUsed = -INT64_MAX; + + //rce.setTriangleFillMode(MTLTriangleFillModeFill); + if (_render->m_debug & (BGFX_DEBUG_IFH|BGFX_DEBUG_STATS) ) + { + rce = renderPass(_render, BGFX_INVALID_HANDLE, false, Clear()); + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + rce.PushDebugGroup("debugstats"); + } + + TextVideoMem& tvm = m_textVideoMem; + + static int64_t next = timeEnd; + + if (timeEnd >= next) + { + next = timeEnd + timerFreq; + + double freq = double(timerFreq); + double toMs = 1000.0/freq; + + tvm.clear(); + uint16_t pos = 0; + tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x8c : 0x8f + , " %s / " BX_COMPILER_NAME + " / " BX_CPU_NAME + " / " BX_ARCH_NAME + " / " BX_PLATFORM_NAME + " / Version 1.%d.%d (commit: " BGFX_REV_SHA1 ")" + , getRendererName() + , BGFX_API_VERSION + , BGFX_REV_NUMBER + ); + + pos = 10; + tvm.printf(10, pos++, 0x8b, " Frame: %7.3f, % 7.3f \x1f, % 7.3f \x1e [ms] / % 6.2f FPS " + , double(frameTime)*toMs + , double(min)*toMs + , double(max)*toMs + , freq/frameTime + ); + + const uint32_t msaa = (m_resolution.reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; + tvm.printf(10, pos++, 0x8b, " Reset flags: [%c] vsync, [%c] MSAAx%d, [%c] MaxAnisotropy " + , !!(m_resolution.reset&BGFX_RESET_VSYNC) ? '\xfe' : ' ' + , 0 != msaa ? '\xfe' : ' ' + , 1<<msaa + , !!(m_resolution.reset&BGFX_RESET_MAXANISOTROPY) ? '\xfe' : ' ' + ); + + double elapsedCpuMs = double(frameTime)*toMs; + tvm.printf(10, pos++, 0x8b, " Submitted: %4d (draw %4d, compute %4d) / CPU %3.4f [ms] %c GPU %3.4f [ms] (latency %d)" + , _render->m_numRenderItems + , statsKeyType[0] + , statsKeyType[1] + , elapsedCpuMs + , elapsedCpuMs > maxGpuElapsed ? '>' : '<' + , maxGpuElapsed + , maxGpuLatency + ); + maxGpuLatency = 0; + maxGpuElapsed = 0.0; + + for (uint32_t ii = 0; ii < Topology::Count; ++ii) + { + tvm.printf(10, pos++, 0x8b, " %10s: %7d (#inst: %5d), submitted: %7d" + , getName(Topology::Enum(ii) ) + , statsNumPrimsRendered[ii] + , statsNumInstances[ii] + , statsNumPrimsSubmitted[ii] + ); + } + + tvm.printf(10, pos++, 0x8b, " Indices: %7d ", statsNumIndices); +// tvm.printf(10, pos++, 0x8b, " Uniform size: %7d, Max: %7d ", _render->m_uniformEnd, _render->m_uniformMax); + tvm.printf(10, pos++, 0x8b, " DVB size: %7d ", _render->m_vboffset); + tvm.printf(10, pos++, 0x8b, " DIB size: %7d ", _render->m_iboffset); + + pos++; + double captureMs = double(captureElapsed)*toMs; + tvm.printf(10, pos++, 0x8b, " Capture: %3.4f [ms]", captureMs); + + uint8_t attr[2] = { 0x8c, 0x8a }; + uint8_t attrIndex = _render->m_waitSubmit < _render->m_waitRender; + + tvm.printf(10, pos++, attr[attrIndex &1], " Submit wait: %3.4f [ms]", _render->m_waitSubmit*toMs); + tvm.printf(10, pos++, attr[(attrIndex+1)&1], " Render wait: %3.4f [ms]", _render->m_waitRender*toMs); + + min = frameTime; + max = frameTime; + } + + blit(this, _textVideoMemBlitter, tvm); + rce = m_renderEncoder; + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + rce.PopDebugGroup(); + } + } + else if (_render->m_debug & BGFX_DEBUG_TEXT) + { + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + rce.PushDebugGroup("debugtext"); + } + + blit(this, _textVideoMemBlitter, _render->m_textVideoMem); + rce = m_renderEncoder; + + if (BX_ENABLED(BGFX_CONFIG_DEBUG_ANNOTATION)) + { + rce.PopDebugGroup(); + } + } + + endEncoding(); + + scratchBuffer.submit(); + + m_cmd.kick(true); + + scratchBuffer.release(); + +#if !BX_PLATFORM_EMSCRIPTEN + for (uint32_t ii = 0, num = m_numWindows; ii < num; ++ii) + { + FrameBufferWgpu& frameBuffer = ii == 0 ? m_mainFrameBuffer : m_frameBuffers[m_windows[ii].idx]; + if (NULL != frameBuffer.m_swapChain + && frameBuffer.m_swapChain->m_drawable) + { + SwapChainWgpu& swapChain = *frameBuffer.m_swapChain; + swapChain.m_swapChain.Present(); + } + } +#endif + } + +} /* namespace webgpu */ } // namespace bgfx + +#else + +namespace bgfx { namespace webgpu + { + RendererContextI* rendererCreate(const Init& _init) + { + BX_UNUSED(_init); + return NULL; + } + + void rendererDestroy() + { + } + } /* namespace webgpu */ } // namespace bgfx + +#endif // BGFX_CONFIG_RENDERER_WEBGPU diff --git a/3rdparty/bgfx/src/renderer_webgpu.h b/3rdparty/bgfx/src/renderer_webgpu.h new file mode 100644 index 00000000000..54c8aff237e --- /dev/null +++ b/3rdparty/bgfx/src/renderer_webgpu.h @@ -0,0 +1,570 @@ +/* + * Copyright 2011-2019 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +#ifndef BGFX_RENDERER_WEBGPU_H_HEADER_GUARD +#define BGFX_RENDERER_WEBGPU_H_HEADER_GUARD + +#include "bgfx_p.h" + +#if BGFX_CONFIG_RENDERER_WEBGPU + +#if !BX_PLATFORM_EMSCRIPTEN +# include <dawn/webgpu_cpp.h> +# include <dawn/dawn_wsi.h> +#else +# include <webgpu/webgpu_cpp.h> +#endif // !BX_PLATFORM_EMSCRIPTEN + +#define BGFX_WEBGPU_PROFILER_BEGIN(_view, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_BEGIN(s_viewName[view], _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_WEBGPU_PROFILER_BEGIN_LITERAL(_name, _abgr) \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_BEGIN_LITERAL("" # _name, _abgr); \ + BX_MACRO_BLOCK_END + +#define BGFX_WEBGPU_PROFILER_END() \ + BX_MACRO_BLOCK_BEGIN \ + BGFX_PROFILER_END(); \ + BX_MACRO_BLOCK_END + +#define WEBGPU_NUM_UNIFORM_BUFFERS 8 + +namespace bgfx { namespace webgpu +{ + template <typename Ty> + class StateCacheT + { + public: + void add(uint64_t _id, Ty _item) + { + invalidate(_id); + m_hashMap.insert(stl::make_pair(_id, _item)); + } + + Ty find(uint64_t _id) + { + typename HashMap::iterator it = m_hashMap.find(_id); + if(it != m_hashMap.end()) + { + return it->second; + } + + return NULL; + } + + void invalidate(uint64_t _id) + { + typename HashMap::iterator it = m_hashMap.find(_id); + if(it != m_hashMap.end()) + { + release(it->second); + m_hashMap.erase(it); + } + } + + void invalidate() + { + for(typename HashMap::iterator it = m_hashMap.begin(), itEnd = m_hashMap.end(); it != itEnd; ++it) + { + release(it->second); + } + + m_hashMap.clear(); + } + + uint32_t getCount() const + { + return uint32_t(m_hashMap.size()); + } + + private: + typedef stl::unordered_map<uint64_t, Ty> HashMap; + HashMap m_hashMap; + }; + + struct BufferWgpu + { + void create(uint32_t _size, void* _data, uint16_t _flags, uint16_t _stride = 0, bool _vertex = false); + void update(uint32_t _offset, uint32_t _size, void* _data, bool _discard = false); + + void destroy() + { + m_ptr.Destroy(); + + if(NULL != m_dynamic) + { + BX_DELETE(g_allocator, m_dynamic); + m_dynamic = NULL; + } + } + + uint32_t m_size; + uint16_t m_flags = BGFX_BUFFER_NONE; + bool m_vertex; + + String m_label; + wgpu::Buffer m_ptr; + uint8_t* m_dynamic = NULL; + }; + + struct IndexBufferWgpu : public BufferWgpu + { + void create(uint32_t _size, void* _data, uint16_t _flags); + + wgpu::IndexFormat m_format; + }; + + struct VertexBufferWgpu : public BufferWgpu + { + void create(uint32_t _size, void* _data, VertexLayoutHandle _declHandle, uint16_t _flags); + + VertexLayoutHandle m_layoutHandle; + }; + + struct BindInfo + { + uint32_t m_index = UINT32_MAX; + uint32_t m_binding = UINT32_MAX; + UniformHandle m_uniform = BGFX_INVALID_HANDLE; + }; + + struct ShaderWgpu + { + void create(ShaderHandle _handle, const Memory* _mem); + void destroy() + { + if (NULL != m_constantBuffer) + { + UniformBuffer::destroy(m_constantBuffer); + m_constantBuffer = NULL; + } + + m_module = NULL; + } + + const char* name() const { return getName(m_handle); } + + ShaderHandle m_handle; + String m_label; + + wgpu::ShaderStage m_stage; + wgpu::ShaderModule m_module; + + uint32_t* m_code = NULL; + size_t m_codeSize = 0; + + UniformBuffer* m_constantBuffer = NULL; + + PredefinedUniform m_predefined[PredefinedUniform::Count]; + uint16_t m_attrMask[Attrib::Count]; + uint8_t m_attrRemap[Attrib::Count]; + + uint32_t m_hash = 0; + uint16_t m_numUniforms = 0; + uint16_t m_size = 0; + uint16_t m_gpuSize = 0; + uint8_t m_numPredefined = 0; + uint8_t m_numAttrs = 0; + + BindInfo m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + wgpu::BindGroupLayoutEntry m_samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + wgpu::BindGroupLayoutEntry m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + uint8_t m_numSamplers = 0; + wgpu::BindGroupLayoutEntry m_buffers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + uint32_t m_numBuffers = 0; + }; + + struct PipelineStateWgpu; + + struct ProgramWgpu + { + void create(const ShaderWgpu* _vsh, const ShaderWgpu* _fsh); + void destroy(); + + const ShaderWgpu* m_vsh = NULL; + const ShaderWgpu* m_fsh = NULL; + + PredefinedUniform m_predefined[PredefinedUniform::Count * 2]; + uint8_t m_numPredefined; + + PipelineStateWgpu* m_computePS = NULL; + + wgpu::BindGroupLayout m_bindGroupLayout; + uint16_t m_gpuSize = 0; + uint32_t m_numUniforms; + uint32_t m_bindGroupLayoutHash; + + BindInfo m_bindInfo[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + wgpu::BindGroupLayoutEntry m_samplers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + wgpu::BindGroupLayoutEntry m_textures[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + uint32_t m_numSamplers = 0; + wgpu::BindGroupLayoutEntry m_buffers[BGFX_CONFIG_MAX_TEXTURE_SAMPLERS]; + uint32_t m_numBuffers = 0; + }; + + constexpr size_t kMaxVertexInputs = 16; + constexpr size_t kMaxVertexAttributes = 16; + constexpr size_t kMaxColorAttachments = BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS; + + constexpr uint32_t kMinBufferOffsetAlignment = 256; + + struct RenderPassDescriptor + { + RenderPassDescriptor(); + + wgpu::RenderPassDescriptor desc; + + wgpu::RenderPassColorAttachment colorAttachments[kMaxColorAttachments]; + wgpu::RenderPassDepthStencilAttachment depthStencilAttachment; + }; + + struct VertexStateDescriptor + { + VertexStateDescriptor(); + + wgpu::VertexState desc; + + wgpu::VertexBufferLayoutDescriptor buffers[kMaxVertexInputs]; + wgpu::VertexAttributeDescriptor attributes[kMaxVertexAttributes]; + }; + + struct RenderPipelineDescriptor + { + RenderPipelineDescriptor(); + + wgpu::RenderPipelineDescriptor2 desc; + + wgpu::FragmentState fragment; + wgpu::DepthStencilState depthStencil; + + wgpu::ColorTargetState targets[kMaxColorAttachments]; + wgpu::BlendState blends[kMaxColorAttachments]; + }; + + struct BindingsWgpu + { + uint32_t numEntries = 0; + wgpu::BindGroupEntry m_entries[2 + BGFX_CONFIG_MAX_TEXTURE_SAMPLERS*3]; + }; + + struct BindStateWgpu + { + void clear(); + + uint32_t numOffset; + + wgpu::BindGroup m_bindGroup; + }; + + struct RenderPassStateWgpu + { + RenderPassDescriptor m_rpd; + }; + + struct PipelineStateWgpu + { + RenderPipelineDescriptor m_rpd; + + wgpu::PipelineLayout m_layout; + + wgpu::RenderPipeline m_rps; + wgpu::ComputePipeline m_cps; + }; + + void release(RenderPassStateWgpu* _ptr) + { + BX_DELETE(g_allocator, _ptr); + } + + void release(PipelineStateWgpu* _ptr) + { + BX_DELETE(g_allocator, _ptr); + } + + class StagingBufferWgpu + { + public: + void create(uint32_t _size, bool mapped); + void map(); + void unmap(); + void destroy(); + + void mapped(void* _data); + + wgpu::Buffer m_buffer; + void* m_data = NULL; + uint64_t m_size = 0; + }; + + class ScratchBufferWgpu + { + public: + void create(uint32_t _size); // , uint32_t _maxBindGroups); + void destroy(); + void begin(); + uint32_t write(void* data, uint64_t _size, uint64_t _offset); + uint32_t write(void* data, uint64_t _size); + void submit(); + void release(); + + StagingBufferWgpu* m_staging = NULL; + wgpu::Buffer m_buffer; + uint32_t m_offset; + uint32_t m_size; + uint8_t m_stagingIndex = 0; + }; + + class BindStateCacheWgpu + { + public: + void create(); // , uint32_t _maxBindGroups); + void destroy(); + void reset(); + + BindStateWgpu m_bindStates[1024] = {}; + uint32_t m_currentBindState; + //uint32_t m_maxBindStates; + }; + + struct ReadbackWgpu + { + void create(TextureHandle _texture) { m_texture = _texture; } + + void destroy() + { + m_buffer.Destroy(); + } + + void readback(void const* data) + { + bx::memCopy(m_data, data, m_size); + m_buffer.Unmap(); + m_mapped = false; + } + + TextureHandle m_texture; + wgpu::Buffer m_buffer; + uint32_t m_mip = 0; + bool m_mapped = false; + void* m_data = NULL; + size_t m_size = 0; + }; + + struct TextureWgpu + { + enum Enum + { + Texture2D, + Texture3D, + TextureCube, + }; + + void create(TextureHandle _handle, const Memory* _mem, uint64_t _flags, uint8_t _skip); + + void destroy() + { + m_ptr.Destroy(); + } + + void update( + uint8_t _side + , uint8_t _mip + , const Rect& _rect + , uint16_t _z + , uint16_t _depth + , uint16_t _pitch + , const Memory* _mem + ); + + TextureHandle m_handle; + String m_label; + + wgpu::TextureView m_view; + wgpu::TextureView getTextureMipLevel(int _mip); + + wgpu::Texture m_ptr; + wgpu::Texture m_ptrMsaa; + wgpu::TextureView m_ptrMips[14] = {}; + wgpu::Sampler m_sampler; + uint64_t m_flags = 0; + uint32_t m_width = 0; + uint32_t m_height = 0; + uint32_t m_depth = 0; + uint8_t m_type; + TextureFormat::Enum m_requestedFormat; + TextureFormat::Enum m_textureFormat; + uint8_t m_numMips = 0; + uint8_t m_numLayers; + uint32_t m_numSides; + uint8_t m_sampleCount; + + ReadbackWgpu m_readback; + }; + + struct SamplerStateWgpu + { + wgpu::Sampler m_sampler; + }; + + void release(SamplerStateWgpu* _ptr) + { + BX_DELETE(g_allocator, _ptr); + } + + struct FrameBufferWgpu; + + struct SwapChainWgpu + { + void init(wgpu::Device _device, void* _nwh, uint32_t _width, uint32_t _height); + void resize(FrameBufferWgpu& _frameBuffer, uint32_t _width, uint32_t _height, uint32_t _flags); + + void flip(); + + wgpu::TextureView current(); + +#if !BX_PLATFORM_EMSCRIPTEN + DawnSwapChainImplementation m_impl; +#endif + + wgpu::SwapChain m_swapChain; + + wgpu::TextureView m_drawable; + + wgpu::Texture m_backBufferColorMsaa; + wgpu::Texture m_backBufferDepth; + + wgpu::TextureFormat m_colorFormat; + wgpu::TextureFormat m_depthFormat; + + uint32_t m_maxAnisotropy = 0; + uint8_t m_sampleCount; + }; + + struct FrameBufferWgpu + { + void create(uint8_t _num, const Attachment* _attachment); + bool create( + uint16_t _denseIdx + , void* _nwh + , uint32_t _width + , uint32_t _height + , TextureFormat::Enum _format + , TextureFormat::Enum _depthFormat + ); + void postReset(); + uint16_t destroy(); + + SwapChainWgpu* m_swapChain = NULL; + void* m_nwh = NULL; + uint32_t m_width; + uint32_t m_height; + uint16_t m_denseIdx = UINT16_MAX; + + uint32_t m_pixelFormatHash = 0; + + TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS - 1]; + TextureHandle m_depthHandle = { kInvalidHandle }; + Attachment m_colorAttachment[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS - 1]; + Attachment m_depthAttachment; + uint8_t m_num = 0; // number of color handles + }; + + struct CommandQueueWgpu + { + void init(wgpu::Queue _queue); + void shutdown(); + void beginRender(); + void beginStaging(); + void kick(bool _endFrame, bool _waitForFinish = false); + void finish(bool _finishAll = false); + void release(wgpu::Buffer _buffer); + void consume(); + +#if BGFX_CONFIG_MULTITHREADED + //bx::Semaphore m_framesSemaphore; +#endif + + wgpu::Queue m_queue; + wgpu::CommandEncoder m_stagingEncoder; + wgpu::CommandEncoder m_renderEncoder; + + int m_releaseWriteIndex = 0; + int m_releaseReadIndex = 0; + + typedef stl::vector<wgpu::Buffer> ResourceArray; + ResourceArray m_release[BGFX_CONFIG_MAX_FRAME_LATENCY]; + }; + + struct TimerQueryWgpu + { + TimerQueryWgpu() + : m_control(4) + { + } + + void init(); + void shutdown(); + uint32_t begin(uint32_t _resultIdx, uint32_t _frameNum); + void end(uint32_t _idx); + void addHandlers(wgpu::CommandBuffer& _commandBuffer); + bool get(); + + struct Result + { + void reset() + { + m_begin = 0; + m_end = 0; + m_pending = 0; + m_frameNum = 0; + } + + uint64_t m_begin; + uint64_t m_end; + uint32_t m_pending; + uint32_t m_frameNum; // TODO: implement (currently stays 0) + }; + + uint64_t m_begin; + uint64_t m_end; + uint64_t m_elapsed; + uint64_t m_frequency; + + Result m_result[4 * 2]; + bx::RingBufferControl m_control; + }; + + struct OcclusionQueryWgpu + { + OcclusionQueryWgpu() + : m_control(BX_COUNTOF(m_query)) + { + } + + void postReset(); + void preReset(); + void begin(wgpu::RenderPassEncoder& _rce, Frame* _render, OcclusionQueryHandle _handle); + void end(wgpu::RenderPassEncoder& _rce); + void resolve(Frame* _render, bool _wait = false); + void invalidate(OcclusionQueryHandle _handle); + + struct Query + { + OcclusionQueryHandle m_handle; + }; + + wgpu::Buffer m_buffer; + Query m_query[BGFX_CONFIG_MAX_OCCLUSION_QUERIES]; + bx::RingBufferControl m_control; + }; + +} /* namespace webgpu */ } // namespace bgfx + +#endif // BGFX_CONFIG_RENDERER_WEBGPU + +#endif // BGFX_RENDERER_WEBGPU_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/shader.cpp b/3rdparty/bgfx/src/shader.cpp index f6dfb3e350d..2629569e3e5 100644 --- a/3rdparty/bgfx/src/shader.cpp +++ b/3rdparty/bgfx/src/shader.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -10,14 +10,121 @@ namespace bgfx { + struct DescriptorTypeToId + { + DescriptorType::Enum type; + uint16_t id; + }; + + static DescriptorTypeToId s_descriptorTypeToId[] = + { + // NOTICE: + // DescriptorType must be in order how it appears in DescriptorType::Enum! id is + // unique and should not be changed if new DescriptorTypes are added. + { DescriptorType::StorageBuffer, 0x0007 }, + { DescriptorType::StorageImage, 0x0003 }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_descriptorTypeToId) == DescriptorType::Count); + + DescriptorType::Enum idToDescriptorType(uint16_t _id) + { + for (uint32_t ii = 0; ii < BX_COUNTOF(s_descriptorTypeToId); ++ii) + { + if (s_descriptorTypeToId[ii].id == _id) + { + return s_descriptorTypeToId[ii].type; + } + } + + return DescriptorType::Count; + } + + uint16_t descriptorTypeToId(DescriptorType::Enum _type) + { + return s_descriptorTypeToId[_type].id; + } + + struct TextureComponentTypeToId + { + TextureComponentType::Enum type; + uint8_t id; + }; + + static TextureComponentTypeToId s_textureComponentTypeToId[] = + { + // see comment in s_descriptorTypeToId + { TextureComponentType::Float, 0x00 }, + { TextureComponentType::Int, 0x01 }, + { TextureComponentType::Uint, 0x02 }, + { TextureComponentType::Depth, 0x03 }, + { TextureComponentType::UnfilterableFloat, 0x04 }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_textureComponentTypeToId) == TextureComponentType::Count); + + TextureComponentType::Enum idToTextureComponentType(uint8_t _id) + { + for (uint32_t ii = 0; ii < BX_COUNTOF(s_textureComponentTypeToId); ++ii) + { + if (s_textureComponentTypeToId[ii].id == _id) + { + return s_textureComponentTypeToId[ii].type; + } + } + + return TextureComponentType::Count; + } + + uint8_t textureComponentTypeToId(TextureComponentType::Enum _type) + { + return s_textureComponentTypeToId[_type].id; + } + + struct TextureDimensionToId + { + TextureDimension::Enum dimension; + uint8_t id; + }; + + static TextureDimensionToId s_textureDimensionToId[] = + { + // see comment in s_descriptorTypeToId + { TextureDimension::Dimension1D, 0x01 }, + { TextureDimension::Dimension2D, 0x02 }, + { TextureDimension::Dimension2DArray, 0x03 }, + { TextureDimension::DimensionCube, 0x04 }, + { TextureDimension::DimensionCubeArray, 0x05 }, + { TextureDimension::Dimension3D, 0x06 }, + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_textureDimensionToId) == TextureDimension::Count); + + TextureDimension::Enum idToTextureDimension(uint8_t _id) + { + for (uint32_t ii = 0; ii < BX_COUNTOF(s_textureDimensionToId); ++ii) + { + if (s_textureDimensionToId[ii].id == _id) + { + return s_textureDimensionToId[ii].dimension; + } + } + + return TextureDimension::Count; + } + + uint8_t textureDimensionToId(TextureDimension::Enum _dim) + { + return s_textureDimensionToId[_dim].id; + } + static bool printAsm(uint32_t _offset, const DxbcInstruction& _instruction, void* _userData) { BX_UNUSED(_offset); bx::WriterI* writer = reinterpret_cast<bx::WriterI*>(_userData); char temp[512]; toString(temp, sizeof(temp), _instruction); - bx::write(writer, temp, (int32_t)bx::strLen(temp) ); - bx::write(writer, '\n'); + + bx::Error err; + bx::write(writer, temp, (int32_t)bx::strLen(temp), &err); + bx::write(writer, '\n', &err); return true; } @@ -27,8 +134,10 @@ namespace bgfx bx::WriterI* writer = reinterpret_cast<bx::WriterI*>(_userData); char temp[512]; toString(temp, sizeof(temp), _instruction); - bx::write(writer, temp, (int32_t)bx::strLen(temp) ); - bx::write(writer, '\n'); + + bx::Error err; + bx::write(writer, temp, (int32_t)bx::strLen(temp), &err); + bx::write(writer, '\n', &err); return true; } @@ -38,15 +147,17 @@ namespace bgfx bx::WriterI* writer = reinterpret_cast<bx::WriterI*>(_userData); char temp[512]; toString(temp, sizeof(temp), _instruction); - bx::write(writer, temp, (int32_t)bx::strLen(temp) ); - bx::write(writer, '\n'); + + bx::Error err; + bx::write(writer, temp, (int32_t)bx::strLen(temp), &err); + bx::write(writer, '\n', &err); return true; } void disassembleByteCode(bx::WriterI* _writer, bx::ReaderSeekerI* _reader, bx::Error* _err) { uint32_t magic; - bx::peek(_reader, magic); + bx::peek(_reader, magic, _err); if (magic == SPV_CHUNK_HEADER) { @@ -73,14 +184,14 @@ namespace bgfx BX_ERROR_SCOPE(_err); uint32_t magic; - bx::peek(_reader, magic); + bx::peek(_reader, magic, _err); if (isShaderBin(magic) ) { - bx::read(_reader, magic); + bx::read(_reader, magic, _err); uint32_t hashIn; - bx::read(_reader, hashIn); + bx::read(_reader, hashIn, _err); uint32_t hashOut; @@ -90,7 +201,7 @@ namespace bgfx } else { - bx::read(_reader, hashOut); + bx::read(_reader, hashOut, _err); } uint16_t count; @@ -120,6 +231,18 @@ namespace bgfx uint16_t regCount; bx::read(_reader, regCount, _err); + + if (!isShaderVerLess(magic, 8) ) + { + uint16_t texInfo; + bx::read(_reader, texInfo, _err); + } + + if (!isShaderVerLess(magic, 10) ) + { + uint16_t texFormat = 0; + bx::read(_reader, texFormat, _err); + } } uint32_t shaderSize; diff --git a/3rdparty/bgfx/src/shader.h b/3rdparty/bgfx/src/shader.h index bd55dc91f90..5ddc1cdbef4 100644 --- a/3rdparty/bgfx/src/shader.h +++ b/3rdparty/bgfx/src/shader.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_SHADER_H @@ -10,6 +10,55 @@ namespace bgfx { + struct DescriptorType + { + enum Enum + { + StorageBuffer, + StorageImage, + + Count + }; + }; + + DescriptorType::Enum idToDescriptorType(uint16_t _id); + uint16_t descriptorTypeToId(DescriptorType::Enum _type); + + struct TextureComponentType + { + enum Enum + { + Float, + Int, + Uint, + Depth, + UnfilterableFloat, + + Count + }; + }; + + TextureComponentType::Enum idToTextureComponentType(uint8_t _id); + uint8_t textureComponentTypeToId(TextureComponentType::Enum _type); + + struct TextureDimension + { + enum Enum + { + Dimension1D, + Dimension2D, + Dimension2DArray, + DimensionCube, + DimensionCubeArray, + Dimension3D, + + Count + }; + }; + + TextureDimension::Enum idToTextureDimension(uint8_t _id); + uint8_t textureDimensionToId(TextureDimension::Enum _dim); + /// void disassemble(bx::WriterI* _writer, bx::ReaderSeekerI* _reader, bx::Error* _err = NULL); diff --git a/3rdparty/bgfx/src/shader_dx9bc.cpp b/3rdparty/bgfx/src/shader_dx9bc.cpp index 988bec096f0..adf83328345 100644 --- a/3rdparty/bgfx/src/shader_dx9bc.cpp +++ b/3rdparty/bgfx/src/shader_dx9bc.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -225,7 +225,7 @@ namespace bgfx const char* getName(Dx9bcOpcode::Enum _opcode) { - BX_CHECK(_opcode < Dx9bcOpcode::Count, "Unknown opcode id %d (%x).", _opcode, _opcode); + BX_ASSERT(_opcode < Dx9bcOpcode::Count, "Unknown opcode id %d (%x).", _opcode, _opcode); return s_dx9bcOpcode[_opcode]; } @@ -458,7 +458,7 @@ namespace bgfx break; default: - BX_CHECK(false, "Instruction %s with invalid number of operands %d (numValues %d)." + BX_ASSERT(false, "Instruction %s with invalid number of operands %d (numValues %d)." , getName(_instruction.opcode) , _instruction.numOperands , info.numValues @@ -492,7 +492,7 @@ namespace bgfx break; } - return 0; + return size; } int32_t toString(char* _out, int32_t _size, const Dx9bcInstruction& _instruction) @@ -642,7 +642,7 @@ namespace bgfx char temp[512]; toString(temp, 512, instruction); - BX_CHECK(length/4 == instruction.length + BX_ASSERT(length/4 == instruction.length , "%s\nread %d, expected %d" , temp , length/4 @@ -712,7 +712,7 @@ namespace bgfx { Dx9bcInstruction instruction; uint32_t size = read(&reader, instruction, _err); - BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); + BX_ASSERT(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); bool cont = _fn(token * sizeof(uint32_t), instruction, _userData); if (!cont) @@ -737,7 +737,7 @@ namespace bgfx { Dx9bcInstruction instruction; uint32_t size = read(&reader, instruction, _err); - BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); + BX_ASSERT(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); _fn(instruction, _userData); diff --git a/3rdparty/bgfx/src/shader_dx9bc.h b/3rdparty/bgfx/src/shader_dx9bc.h index 618955f9921..dec16858ac8 100644 --- a/3rdparty/bgfx/src/shader_dx9bc.h +++ b/3rdparty/bgfx/src/shader_dx9bc.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_SHADER_DX9BC_H diff --git a/3rdparty/bgfx/src/shader_dxbc.cpp b/3rdparty/bgfx/src/shader_dxbc.cpp index 49da315b3e9..6f27ff7d2a3 100644 --- a/3rdparty/bgfx/src/shader_dxbc.cpp +++ b/3rdparty/bgfx/src/shader_dxbc.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -108,17 +108,17 @@ namespace bgfx { 1, 0 }, // DCL_CONSTANT_BUFFER { 1, 0 }, // DCL_SAMPLER { 1, 1 }, // DCL_INDEX_RANGE - { 1, 0 }, // DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY - { 1, 0 }, // DCL_GS_INPUT_PRIMITIVE + { 0, 0 }, // DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY + { 0, 0 }, // DCL_GS_INPUT_PRIMITIVE { 0, 1 }, // DCL_MAX_OUTPUT_VERTEX_COUNT { 1, 0 }, // DCL_INPUT { 1, 1 }, // DCL_INPUT_SGV - { 1, 0 }, // DCL_INPUT_SIV + { 1, 1 }, // DCL_INPUT_SIV { 1, 0 }, // DCL_INPUT_PS { 1, 1 }, // DCL_INPUT_PS_SGV { 1, 1 }, // DCL_INPUT_PS_SIV { 1, 0 }, // DCL_OUTPUT - { 1, 0 }, // DCL_OUTPUT_SGV + { 1, 1 }, // DCL_OUTPUT_SGV { 1, 1 }, // DCL_OUTPUT_SIV { 0, 1 }, // DCL_TEMPS { 0, 3 }, // DCL_INDEXABLE_TEMP @@ -135,8 +135,8 @@ namespace bgfx { 0, 0 }, // HS_CONTROL_POINT_PHASE { 0, 0 }, // HS_FORK_PHASE { 0, 0 }, // HS_JOIN_PHASE - { 0, 0 }, // EMIT_STREAM - { 0, 0 }, // CUT_STREAM + { 1, 0 }, // EMIT_STREAM + { 1, 0 }, // CUT_STREAM { 1, 0 }, // EMITTHENCUT_STREAM { 1, 0 }, // INTERFACE_CALL { 0, 0 }, // BUFINFO @@ -161,7 +161,7 @@ namespace bgfx { 5, 0 }, // BFI { 0, 0 }, // BFREV { 5, 0 }, // SWAPC - { 0, 0 }, // DCL_STREAM + { 1, 0 }, // DCL_STREAM { 1, 0 }, // DCL_FUNCTION_BODY { 0, 0 }, // DCL_FUNCTION_TABLE { 0, 0 }, // DCL_INTERFACE @@ -468,7 +468,7 @@ namespace bgfx const char* getName(DxbcOpcode::Enum _opcode) { - BX_CHECK(_opcode < DxbcOpcode::Count, "Unknown opcode id %d.", _opcode); + BX_ASSERT(_opcode < DxbcOpcode::Count, "Unknown opcode id %d.", _opcode); return s_dxbcOpcode[_opcode]; } @@ -503,6 +503,69 @@ namespace bgfx }; BX_STATIC_ASSERT(BX_COUNTOF(s_dxbcInterpolationName) == DxbcInterpolation::Count); + const char *s_dxbcPrimitiveTopologyName[] = + { + "", + "PointList", + "LineList", + "LineStrip", + "TriangleList", + "TriangleStrip", + "", + "", + "", + "", + "LineListAdj", + "LineStripAdj", + "TriangleListAdj", + "TriangleStripAdj", + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_dxbcPrimitiveTopologyName) == DxbcPrimitiveTopology::Count); + + const char *s_dxbcPrimitiveName[] = { + "", + "Point", + "Line", + "Triangle", + "", + "", + "LineAdj", + "TriangleAdj", + "_1ControlPointPatch", + "_2ControlPointPatch", + "_3ControlPointPatch", + "_4ControlPointPatch", + "_5ControlPointPatch", + "_6ControlPointPatch", + "_7ControlPointPatch", + "_8ControlPointPatch", + "_9ControlPointPatch", + "_10ControlPointPatch", + "_11ControlPointPatch", + "_12ControlPointPatch", + "_13ControlPointPatch", + "_14ControlPointPatch", + "_15ControlPointPatch", + "_16ControlPointPatch", + "_17ControlPointPatch", + "_18ControlPointPatch", + "_19ControlPointPatch", + "_20ControlPointPatch", + "_21ControlPointPatch", + "_22ControlPointPatch", + "_23ControlPointPatch", + "_24ControlPointPatch", + "_25ControlPointPatch", + "_26ControlPointPatch", + "_27ControlPointPatch", + "_28ControlPointPatch", + "_29ControlPointPatch", + "_30ControlPointPatch", + "_31ControlPointPatch", + "_32ControlPointPatch", + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_dxbcPrimitiveName) == DxbcPrimitive::Count); + // mesa/src/gallium/state_trackers/d3d1x/d3d1xshader/defs/shortfiles.txt static const char* s_dxbcOperandType[] = { @@ -717,8 +780,8 @@ namespace bgfx } // dxbc hash function is slightly modified version of MD5 hash. - // https://tools.ietf.org/html/rfc1321 - // http://www.efgh.com/software/md5.txt + // https://web.archive.org/web/20190207230524/https://tools.ietf.org/html/rfc1321 + // https://web.archive.org/web/20190207230538/http://www.efgh.com/software/md5.txt // // Assumption is that data pointer, size are both 4-byte aligned, // and little endian. @@ -825,7 +888,7 @@ namespace bgfx break; default: - BX_CHECK(false, "sub operand addressing mode %d", _subOperand.addrMode); + BX_ASSERT(false, "sub operand addressing mode %d", _subOperand.addrMode); break; } @@ -878,7 +941,7 @@ namespace bgfx break; default: - BX_CHECK(false, "sub operand addressing mode %d", _subOperand.addrMode); + BX_ASSERT(false, "sub operand addressing mode %d", _subOperand.addrMode); break; } @@ -967,7 +1030,7 @@ namespace bgfx break; default: - BX_CHECK(false, "operand %d addressing mode %d", ii, _operand.addrMode[ii]); + BX_ASSERT(false, "operand %d addressing mode %d", ii, _operand.addrMode[ii]); break; } } @@ -1042,7 +1105,7 @@ namespace bgfx break; default: - BX_CHECK(false, "operand %d addressing mode %d", ii, _operand.addrMode[ii]); + BX_ASSERT(false, "operand %d addressing mode %d", ii, _operand.addrMode[ii]); break; } } @@ -1065,6 +1128,8 @@ namespace bgfx // +-------------------------------- extended _instruction.opcode = DxbcOpcode::Enum( (token & UINT32_C(0x000007ff) ) ); + BX_ASSERT(_instruction.opcode < DxbcOpcode::Enum::Count, "unknown opcode"); + _instruction.length = uint8_t( (token & UINT32_C(0x7f000000) ) >> 24); bool extended = 0 != (token & UINT32_C(0x80000000) ); @@ -1147,11 +1212,30 @@ namespace bgfx _instruction.enableShaderExtensions = 0 != (token & UINT32_C(0x00040000) ); break; - case DxbcOpcode::DCL_INPUT_PS: + case DxbcOpcode::DCL_GS_INPUT_PRIMITIVE: + // 0 1 2 3 + // 76543210765432107654321076543210 + // ........ pppppp........... + // ^----------------- Primitive + + _instruction.primitive = DxbcPrimitive::Enum( (token & UINT32_C(0x0001f800) ) >> 11); + break; + + case DxbcOpcode::DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY: + // 0 1 2 3 + // 76543210765432107654321076543210 + // ........ pppppp........... + // ^----------------- Primitive Topology + + _instruction.primitiveTopology = DxbcPrimitiveTopology::Enum( (token & UINT32_C(0x0001f800) ) >> 11); + break; + + case DxbcOpcode::DCL_INPUT_PS: BX_FALLTHROUGH; + case DxbcOpcode::DCL_INPUT_PS_SIV: // 0 1 2 3 // 76543210765432107654321076543210 // ........ iiiii........... - // ^---------------- Interploation + // ^---------------- Interpolation _instruction.interpolation = DxbcInterpolation::Enum( (token & UINT32_C(0x0000f800) ) >> 11); break; @@ -1279,7 +1363,7 @@ namespace bgfx size += read(_reader, tableId, _err); uint32_t num; - size += read(_reader, num); + size += read(_reader, num, _err); for (uint32_t ii = 0; ii < num; ++ii) { @@ -1297,7 +1381,7 @@ namespace bgfx uint32_t num; size += read(_reader, num, _err); - BX_CHECK(false, "not implemented."); + BX_ASSERT(false, "not implemented."); } break; @@ -1325,7 +1409,7 @@ namespace bgfx break; default: - BX_CHECK(false, "Instruction %s with invalid number of operands %d (numValues %d)." + BX_ASSERT(false, "Instruction %s with invalid number of operands %d (numValues %d)." , getName(_instruction.opcode) , info.numOperands , info.numValues @@ -1356,7 +1440,7 @@ namespace bgfx token &= UINT32_C(0x000007ff); token |= _instruction.customDataClass << 11; - size += bx::write(_writer, token); + size += bx::write(_writer, token, _err); uint32_t len = uint32_t(_instruction.customData.size()*sizeof(uint32_t) ); size += bx::write(_writer, len/4+2, _err); @@ -1379,7 +1463,16 @@ namespace bgfx token |= _instruction.enableShaderExtensions ? UINT32_C(0x00040000) : 0; break; - case DxbcOpcode::DCL_INPUT_PS: + case DxbcOpcode::DCL_GS_INPUT_PRIMITIVE: + token |= (_instruction.primitive << 11) & UINT32_C(0x0001f800); + break; + + case DxbcOpcode::DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY: + token |= (_instruction.primitiveTopology << 11) & UINT32_C(0x0001f800); + break; + + case DxbcOpcode::DCL_INPUT_PS: BX_FALLTHROUGH; + case DxbcOpcode::DCL_INPUT_PS_SIV: token |= (_instruction.interpolation << 11) & UINT32_C(0x0000f800); break; @@ -1408,7 +1501,7 @@ namespace bgfx break; } - size += bx::write(_writer, token); + size += bx::write(_writer, token, _err); for (uint32_t ii = 0; _instruction.extended[ii] != DxbcInstruction::ExtendedType::Count; ++ii) { @@ -1547,6 +1640,22 @@ namespace bgfx ); break; + case DxbcOpcode::DCL_GS_OUTPUT_PRIMITIVE_TOPOLOGY: + size += bx::snprintf(&_out[size], bx::uint32_imax(0, _size-size) + , "%s %s" + , getName(_instruction.opcode) + , s_dxbcPrimitiveTopologyName[_instruction.primitiveTopology] + ); + break; + + case DxbcOpcode::DCL_GS_INPUT_PRIMITIVE: + size += bx::snprintf(&_out[size], bx::uint32_imax(0, _size-size) + , "%s %s" + , getName(_instruction.opcode) + , s_dxbcPrimitiveName[_instruction.primitive] + ); + break; + case DxbcOpcode::IF: size += bx::snprintf(&_out[size], bx::uint32_imax(0, _size-size) , "%s%s" @@ -1732,7 +1841,7 @@ namespace bgfx DxbcSignature::Element element; uint32_t nameOffset; - size += bx::read(_reader, nameOffset); + size += bx::read(_reader, nameOffset, _err); char name[DXBC_MAX_NAME_STRING]; readString(_reader, offset + nameOffset, name, DXBC_MAX_NAME_STRING, _err); @@ -1782,7 +1891,7 @@ namespace bgfx } else { - size += bx::write(_writer, it->second); + size += bx::write(_writer, it->second, _err); } size += bx::write(_writer, element.semanticIndex, _err); @@ -1849,6 +1958,12 @@ namespace bgfx #define DXBC_CHUNK_INPUT_SIGNATURE BX_MAKEFOURCC('I', 'S', 'G', 'N') #define DXBC_CHUNK_OUTPUT_SIGNATURE BX_MAKEFOURCC('O', 'S', 'G', 'N') +#define DXBC_CHUNK_SFI0 BX_MAKEFOURCC('S', 'F', 'I', '0') +#define DXBC_CHUNK_SPDB BX_MAKEFOURCC('S', 'P', 'D', 'B') + +#define DXBC_CHUNK_RDEF BX_MAKEFOURCC('R', 'D', 'E', 'F') +#define DXBC_CHUNK_STAT BX_MAKEFOURCC('S', 'T', 'A', 'T') + int32_t read(bx::ReaderSeekerI* _reader, DxbcContext& _dxbc, bx::Error* _err) { int32_t size = 0; @@ -1867,6 +1982,7 @@ namespace bgfx uint32_t fourcc; size += bx::read(_reader, fourcc, _err); + _dxbc.chunksFourcc[ii] = fourcc; uint32_t chunkSize; size += bx::read(_reader, chunkSize, _err); @@ -1896,12 +2012,27 @@ namespace bgfx _dxbc.shader.aon9 = true; break; + case DXBC_CHUNK_SFI0: // ? + BX_ASSERT(chunkSize == sizeof(_dxbc.sfi0.data), + "Unexpected size of SFI0 chunk"); + + size += bx::read(_reader, _dxbc.sfi0.data, _err); + break; + + case DXBC_CHUNK_SPDB: // Shader debugging info (new). + _dxbc.spdb.debugCode.resize(chunkSize); + size += bx::read(_reader, _dxbc.spdb.debugCode.data(), chunkSize, _err); + break; + case DXBC_CHUNK_RDEF: // Resource definition. + _dxbc.rdef.rdefCode.resize(chunkSize); + size += bx::read(_reader, _dxbc.rdef.rdefCode.data(), chunkSize, _err); + break; + case DXBC_CHUNK_STAT: // Statistics. + _dxbc.stat.statCode.resize(chunkSize); + size += bx::read(_reader, _dxbc.stat.statCode.data(), chunkSize, _err); + break; case BX_MAKEFOURCC('I', 'F', 'C', 'E'): // Interface. - case BX_MAKEFOURCC('R', 'D', 'E', 'F'): // Resource definition. case BX_MAKEFOURCC('S', 'D', 'G', 'B'): // Shader debugging info (old). - case BX_MAKEFOURCC('S', 'P', 'D', 'B'): // Shader debugging info (new). - case BX_MAKEFOURCC('S', 'F', 'I', '0'): // ? - case BX_MAKEFOURCC('S', 'T', 'A', 'T'): // Statistics. case BX_MAKEFOURCC('P', 'C', 'S', 'G'): // Patch constant signature. case BX_MAKEFOURCC('P', 'S', 'O', '1'): // Pipeline State Object 1 case BX_MAKEFOURCC('P', 'S', 'O', '2'): // Pipeline State Object 2 @@ -1912,7 +2043,7 @@ namespace bgfx default: size += chunkSize; - BX_CHECK(false, "UNKNOWN FOURCC %c%c%c%c %d" + BX_ASSERT(false, "UNKNOWN FOURCC %c%c%c%c %d" , ( (char*)&fourcc)[0] , ( (char*)&fourcc)[1] , ( (char*)&fourcc)[2] @@ -1930,8 +2061,32 @@ namespace bgfx { int32_t size = 0; + uint32_t numSupportedChunks = 0; + for (uint32_t ii = 0; ii < _dxbc.header.numChunks; ++ii) + { + switch(_dxbc.chunksFourcc[ii]) + { + case DXBC_CHUNK_SHADER_EX: + case DXBC_CHUNK_SHADER: + case BX_MAKEFOURCC('I', 'S', 'G', '1'): + case DXBC_CHUNK_INPUT_SIGNATURE: + case BX_MAKEFOURCC('O', 'S', 'G', '1'): + case BX_MAKEFOURCC('O', 'S', 'G', '5'): + case DXBC_CHUNK_OUTPUT_SIGNATURE: + case DXBC_CHUNK_SFI0: + case DXBC_CHUNK_SPDB: + case DXBC_CHUNK_RDEF: + case DXBC_CHUNK_STAT: + ++numSupportedChunks; + break; + + default: + break; + } + } + int64_t dxbcOffset = bx::seek(_writer); - size += bx::write(_writer, DXBC_CHUNK_HEADER); + size += bx::write(_writer, DXBC_CHUNK_HEADER, _err); size += bx::writeRep(_writer, 0, 16, _err); @@ -1940,35 +2095,96 @@ namespace bgfx int64_t sizeOffset = bx::seek(_writer); size += bx::writeRep(_writer, 0, 4, _err); - uint32_t numChunks = 3; - size += bx::write(_writer, numChunks, _err); + size += bx::write(_writer, numSupportedChunks, _err); int64_t chunksOffsets = bx::seek(_writer); - size += bx::writeRep(_writer, 0, numChunks*sizeof(uint32_t), _err); - - uint32_t chunkOffset[3]; - uint32_t chunkSize[3]; - - chunkOffset[0] = uint32_t(bx::seek(_writer) - dxbcOffset); - size += write(_writer, DXBC_CHUNK_INPUT_SIGNATURE, _err); - size += write(_writer, UINT32_C(0), _err); - chunkSize[0] = write(_writer, _dxbc.inputSignature, _err); - - chunkOffset[1] = uint32_t(bx::seek(_writer) - dxbcOffset); - size += write(_writer, DXBC_CHUNK_OUTPUT_SIGNATURE, _err); - size += write(_writer, UINT32_C(0), _err); - chunkSize[1] = write(_writer, _dxbc.outputSignature, _err); - - chunkOffset[2] = uint32_t(bx::seek(_writer) - dxbcOffset); - size += write(_writer, _dxbc.shader.shex ? DXBC_CHUNK_SHADER_EX : DXBC_CHUNK_SHADER, _err); - size += write(_writer, UINT32_C(0), _err); - chunkSize[2] = write(_writer, _dxbc.shader, _err); - - size += 0 - + chunkSize[0] - + chunkSize[1] - + chunkSize[2] - ; + size += bx::writeRep(_writer, 0, numSupportedChunks*sizeof(uint32_t), _err); + + uint32_t chunkOffset[DXBC_MAX_CHUNKS] = {}; + uint32_t chunkSize[DXBC_MAX_CHUNKS] = {}; + + for (uint32_t ii = 0, idx = 0; ii < _dxbc.header.numChunks; ++ii) + { + switch (_dxbc.chunksFourcc[ii]) + { + case DXBC_CHUNK_SHADER_EX: + case DXBC_CHUNK_SHADER: + chunkOffset[idx] = uint32_t(bx::seek(_writer) - dxbcOffset); + size += bx::write(_writer, _dxbc.shader.shex ? DXBC_CHUNK_SHADER_EX : DXBC_CHUNK_SHADER, _err); + size += bx::write(_writer, UINT32_C(0), _err); + chunkSize[idx] = write(_writer, _dxbc.shader, _err); + size += chunkSize[idx++]; + break; + + case BX_MAKEFOURCC('I', 'S', 'G', '1'): + case DXBC_CHUNK_INPUT_SIGNATURE: + chunkOffset[idx] = uint32_t(bx::seek(_writer) - dxbcOffset); + size += bx::write(_writer, DXBC_CHUNK_INPUT_SIGNATURE, _err); + size += bx::write(_writer, UINT32_C(0), _err); + chunkSize[idx] = write(_writer, _dxbc.inputSignature, _err); + size += chunkSize[idx++]; + break; + + case BX_MAKEFOURCC('O', 'S', 'G', '1'): + case BX_MAKEFOURCC('O', 'S', 'G', '5'): + case DXBC_CHUNK_OUTPUT_SIGNATURE: + chunkOffset[idx] = uint32_t(bx::seek(_writer) - dxbcOffset); + size += bx::write(_writer, DXBC_CHUNK_OUTPUT_SIGNATURE, _err); + size += bx::write(_writer, UINT32_C(0), _err); + chunkSize[idx] = write(_writer, _dxbc.outputSignature, _err); + size += chunkSize[idx++]; + break; + + case DXBC_CHUNK_SFI0: + chunkOffset[idx] = uint32_t(bx::seek(_writer) - dxbcOffset); + size += bx::write(_writer, DXBC_CHUNK_SFI0, _err); + size += bx::write(_writer, UINT32_C(0), _err); + chunkSize[idx] = bx::write(_writer, _dxbc.sfi0.data, _err); + size += chunkSize[idx++]; + break; + + case DXBC_CHUNK_SPDB: // Shader debugging info (new). + chunkOffset[idx] = uint32_t(bx::seek(_writer) - dxbcOffset); + size += bx::write(_writer, DXBC_CHUNK_SPDB, _err); + size += bx::write(_writer, UINT32_C(0), _err); + chunkSize[idx] = bx::write(_writer, _dxbc.spdb.debugCode.data(), int32_t(_dxbc.spdb.debugCode.size() ), _err); + size += chunkSize[idx++]; + break; + + case DXBC_CHUNK_RDEF: // Resource definition. + chunkOffset[idx] = uint32_t(bx::seek(_writer) - dxbcOffset); + size += bx::write(_writer, DXBC_CHUNK_RDEF, _err); + size += bx::write(_writer, uint32_t(_dxbc.rdef.rdefCode.size()), _err); + chunkSize[idx] = bx::write(_writer, _dxbc.rdef.rdefCode.data(), int32_t(_dxbc.rdef.rdefCode.size() ), _err); + size += chunkSize[idx++]; + break; + + case DXBC_CHUNK_STAT: // Statistics. + chunkOffset[idx] = uint32_t(bx::seek(_writer) - dxbcOffset); + size += bx::write(_writer, DXBC_CHUNK_STAT, _err); + size += bx::write(_writer, uint32_t(_dxbc.stat.statCode.size()), _err); + chunkSize[idx] = bx::write(_writer, _dxbc.stat.statCode.data(), int32_t(_dxbc.stat.statCode.size() ), _err); + size += chunkSize[idx++]; + break; + + case BX_MAKEFOURCC('A', 'o', 'n', '9'): // Contains DX9BC for feature level 9.x (*s_4_0_level_9_*) shaders. + case BX_MAKEFOURCC('I', 'F', 'C', 'E'): // Interface. + case BX_MAKEFOURCC('S', 'D', 'G', 'B'): // Shader debugging info (old). + case BX_MAKEFOURCC('P', 'C', 'S', 'G'): // Patch constant signature. + case BX_MAKEFOURCC('P', 'S', 'O', '1'): // Pipeline State Object 1 + case BX_MAKEFOURCC('P', 'S', 'O', '2'): // Pipeline State Object 2 + case BX_MAKEFOURCC('X', 'N', 'A', 'P'): // ? + case BX_MAKEFOURCC('X', 'N', 'A', 'S'): // ? + default: + BX_ASSERT(false, "Writing of DXBC %c%c%c%c chunk unsupported" + , ( (char*)&_dxbc.chunksFourcc[ii])[0] + , ( (char*)&_dxbc.chunksFourcc[ii])[1] + , ( (char*)&_dxbc.chunksFourcc[ii])[2] + , ( (char*)&_dxbc.chunksFourcc[ii])[3] + ); + break; + } + } int64_t eof = bx::seek(_writer); @@ -1976,9 +2192,9 @@ namespace bgfx bx::write(_writer, size, _err); bx::seek(_writer, chunksOffsets, bx::Whence::Begin); - bx::write(_writer, chunkOffset, sizeof(chunkOffset), _err); + bx::write(_writer, chunkOffset, numSupportedChunks*sizeof(chunkOffset[0]), _err); - for (uint32_t ii = 0; ii < BX_COUNTOF(chunkOffset); ++ii) + for (uint32_t ii = 0; ii < numSupportedChunks; ++ii) { bx::seek(_writer, chunkOffset[ii]+4, bx::Whence::Begin); bx::write(_writer, chunkSize[ii], _err); @@ -1999,7 +2215,7 @@ namespace bgfx { DxbcInstruction instruction; uint32_t size = read(&reader, instruction, _err); - BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); + BX_ASSERT(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); bool cont = _fn(token * sizeof(uint32_t), instruction, _userData); if (!cont) @@ -2026,7 +2242,7 @@ namespace bgfx { DxbcInstruction instruction; uint32_t size = read(&reader, instruction, _err); - BX_CHECK(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); + BX_ASSERT(size/4 == instruction.length, "read %d, expected %d", size/4, instruction.length); BX_UNUSED(size); _fn(instruction, _userData); diff --git a/3rdparty/bgfx/src/shader_dxbc.h b/3rdparty/bgfx/src/shader_dxbc.h index df87d7443a7..ba0e2862a39 100644 --- a/3rdparty/bgfx/src/shader_dxbc.h +++ b/3rdparty/bgfx/src/shader_dxbc.h @@ -1,5 +1,5 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -326,6 +326,72 @@ namespace bgfx }; }; + struct DxbcPrimitiveTopology + { + enum Enum + { + Unknown, + PointList, + LineList, + LineStrip, + TriangleList, + TriangleStrip, + LineListAdj = 10, + LineStripAdj, + TriangleListAdj, + TriangleStripAdj, + + Count + }; + }; + + struct DxbcPrimitive + { + enum Enum + { + Unknown, + Point, + Line, + Triangle, + LineAdj = 6, + TriangleAdj, + _1ControlPointPatch, + _2ControlPointPatch, + _3ControlPointPatch, + _4ControlPointPatch, + _5ControlPointPatch, + _6ControlPointPatch, + _7ControlPointPatch, + _8ControlPointPatch, + _9ControlPointPatch, + _10ControlPointPatch, + _11ControlPointPatch, + _12ControlPointPatch, + _13ControlPointPatch, + _14ControlPointPatch, + _15ControlPointPatch, + _16ControlPointPatch, + _17ControlPointPatch, + _18ControlPointPatch, + _19ControlPointPatch, + _20ControlPointPatch, + _21ControlPointPatch, + _22ControlPointPatch, + _23ControlPointPatch, + _24ControlPointPatch, + _25ControlPointPatch, + _26ControlPointPatch, + _27ControlPointPatch, + _28ControlPointPatch, + _29ControlPointPatch, + _30ControlPointPatch, + _31ControlPointPatch, + _32ControlPointPatch, + + Count + }; + }; + struct DxbcResourceReturnType { enum Enum @@ -562,6 +628,12 @@ namespace bgfx DxbcInterpolation::Enum interpolation; // + DxbcPrimitiveTopology::Enum primitiveTopology; + + // + DxbcPrimitive::Enum primitive; + + // bool shadow; bool mono; @@ -633,6 +705,26 @@ namespace bgfx bool aon9; }; + struct DxbcSFI0 + { + uint64_t data; + }; + + struct DxbcSPDB + { + stl::vector<uint8_t> debugCode; + }; + + struct DxbcRDEF + { + stl::vector<uint8_t> rdefCode; + }; + + struct DxbcSTAT + { + stl::vector<uint8_t> statCode; + }; + int32_t read(bx::ReaderSeekerI* _reader, DxbcShader& _shader, bx::Error* _err); int32_t write(bx::WriterI* _writer, const DxbcShader& _shader, bx::Error* _err); @@ -642,6 +734,8 @@ namespace bgfx typedef void (*DxbcFilterFn)(DxbcInstruction& _instruction, void* _userData); void filter(DxbcShader& _dst, const DxbcShader& _src, DxbcFilterFn _fn, void* _userData, bx::Error* _err = NULL); +#define DXBC_MAX_CHUNKS 32 + struct DxbcContext { struct Header @@ -657,6 +751,11 @@ namespace bgfx DxbcSignature inputSignature; DxbcSignature outputSignature; DxbcShader shader; + DxbcSFI0 sfi0; + DxbcSPDB spdb; + DxbcRDEF rdef; + DxbcSTAT stat; + uint32_t chunksFourcc[DXBC_MAX_CHUNKS]; }; int32_t read(bx::ReaderSeekerI* _reader, DxbcContext& _dxbc, bx::Error* _err); diff --git a/3rdparty/bgfx/src/shader_spirv.cpp b/3rdparty/bgfx/src/shader_spirv.cpp index 83b13c53b93..2143641a0c4 100644 --- a/3rdparty/bgfx/src/shader_spirv.cpp +++ b/3rdparty/bgfx/src/shader_spirv.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_p.h" @@ -17,7 +17,7 @@ namespace bgfx #define SPV_OPERAND_7(_a0, _a1, _a2, _a3, _a4, _a5, _a6) SPV_OPERAND_1(_a0), SPV_OPERAND_6(_a1, _a2, _a3, _a4, _a5, _a6) #define SPV_OPERAND_8(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7) SPV_OPERAND_1(_a0), SPV_OPERAND_7(_a1, _a2, _a3, _a4, _a5, _a6, _a7) #define SPV_OPERAND_9(_a0, _a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8) SPV_OPERAND_1(_a0), SPV_OPERAND_8(_a1, _a2, _a3, _a4, _a5, _a6, _a7, _a8) -#if BX_COMPILER_MSVC +#if BX_COMPILER_MSVC && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL) // Workaround MSVS bug... # define SPV_OPERAND(...) { BX_MACRO_DISPATCHER(SPV_OPERAND_, __VA_ARGS__) BX_VA_ARGS_PASS(__VA_ARGS__) } #else @@ -809,7 +809,7 @@ namespace bgfx const char* getName(SpvDecoration::Enum _enum) { BX_UNUSED(s_spvDecorationInfo); - BX_CHECK(_enum <= SpvDecoration::Count, "Unknown decoration id %d.", _enum); + BX_ASSERT(_enum <= SpvDecoration::Count, "Unknown decoration id %d.", _enum); return _enum <= SpvDecoration::Count ? s_spvDecoration[_enum] : "?SpvDecoration?" @@ -839,7 +839,7 @@ namespace bgfx const char* getName(SpvStorageClass::Enum _enum) { - BX_CHECK(_enum <= SpvStorageClass::Count, "Unknown storage class id %d.", _enum); + BX_ASSERT(_enum <= SpvStorageClass::Count, "Unknown storage class id %d.", _enum); return _enum <= SpvStorageClass::Count ? s_spvStorageClass[_enum] : "?SpvStorageClass?" @@ -895,7 +895,7 @@ namespace bgfx const char* getName(SpvBuiltin::Enum _enum) { - BX_CHECK(_enum <= SpvBuiltin::Count, "Unknown builtin id %d.", _enum); + BX_ASSERT(_enum <= SpvBuiltin::Count, "Unknown builtin id %d.", _enum); return _enum <= SpvBuiltin::Count ? s_spvBuiltin[_enum] : "?SpvBuiltin?" diff --git a/3rdparty/bgfx/src/shader_spirv.h b/3rdparty/bgfx/src/shader_spirv.h index 1fe1c934090..0ab2c4ff33c 100644 --- a/3rdparty/bgfx/src/shader_spirv.h +++ b/3rdparty/bgfx/src/shader_spirv.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_SHADER_SPIRV_H @@ -15,6 +15,18 @@ BX_ERROR_RESULT(BGFX_SHADER_SPIRV_INVALID_INSTRUCTION, BX_MAKEFOURCC('S', 'H', 0 namespace bgfx { + constexpr uint8_t kSpirvVertexBinding = 0; + constexpr uint8_t kSpirvFragmentBinding = 1; + constexpr uint8_t kSpirvBindShift = 2; + constexpr uint8_t kSpirvSamplerShift = 16; + + constexpr uint8_t kSpirvOldVertexBinding = 0; + constexpr uint8_t kSpirvOldFragmentBinding = 48; + constexpr uint8_t kSpirvOldFragmentShift = 48; + constexpr uint8_t kSpirvOldBufferShift = 16; + constexpr uint8_t kSpirvOldImageShift = 32; + constexpr uint8_t kSpirvOldTextureShift = 16; + // Reference(s): // - https://web.archive.org/web/20181126035927/https://www.khronos.org/registry/spir-v/specs/1.0/SPIRV.html // diff --git a/3rdparty/bgfx/src/topology.cpp b/3rdparty/bgfx/src/topology.cpp index 1a3e8b6f6ab..0457ab62403 100644 --- a/3rdparty/bgfx/src/topology.cpp +++ b/3rdparty/bgfx/src/topology.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include <bx/allocator.h> @@ -81,7 +81,7 @@ namespace bgfx if (i0 > i1) { bx::swap(i0, i1); } if (i1 > i2) { bx::swap(i1, i2); } if (i0 > i1) { bx::swap(i0, i1); } - BX_CHECK(i0 < i1 && i1 < i2, ""); + BX_ASSERT(i0 < i1 && i1 < i2, ""); dst[1] = i0; dst[0] = i1; dst[3] = i1; dst[2] = i2; @@ -277,22 +277,21 @@ namespace bgfx return (_a + _b + _c) * 1.0f/3.0f; } - const float* vertexPos(const void* _vertices, uint32_t _stride, uint32_t _index) + const bx::Vec3 vertexPos(const void* _vertices, uint32_t _stride, uint32_t _index) { const uint8_t* vertices = (const uint8_t*)_vertices; - return (const float*)&vertices[_index*_stride]; + return bx::load<bx::Vec3>(&vertices[_index*_stride]); } - inline float distanceDir(const float* __restrict _dir, const void* __restrict _vertices, uint32_t _stride, uint32_t _index) + inline float distanceDir(const float* _dir, const void* _vertices, uint32_t _stride, uint32_t _index) { - return bx::vec3Dot(vertexPos(_vertices, _stride, _index), _dir); + return bx::dot(vertexPos(_vertices, _stride, _index), bx::load<bx::Vec3>(_dir) ); } - inline float distancePos(const float* __restrict _pos, const void* __restrict _vertices, uint32_t _stride, uint32_t _index) + inline float distancePos(const float* _pos, const void* _vertices, uint32_t _stride, uint32_t _index) { - float tmp[3]; - bx::vec3Sub(tmp, _pos, vertexPos(_vertices, _stride, _index) ); - return bx::sqrt(bx::vec3Dot(tmp, tmp) ); + const bx::Vec3 tmp = bx::sub(bx::load<bx::Vec3>(_pos), vertexPos(_vertices, _stride, _index) ); + return bx::sqrt(bx::dot(tmp, tmp) ); } typedef float (*KeyFn)(float, float, float); @@ -300,10 +299,10 @@ namespace bgfx template<typename IndexT, DistanceFn dfn, KeyFn kfn, uint32_t xorBits> inline void calcSortKeys( - uint32_t* __restrict _keys - , uint32_t* __restrict _values + uint32_t* _keys + , uint32_t* _values , const float _dirOrPos[3] - , const void* __restrict _vertices + , const void* _vertices , uint32_t _stride , const IndexT* _indices , uint32_t _num diff --git a/3rdparty/bgfx/src/topology.h b/3rdparty/bgfx/src/topology.h index 896e6e572f8..e26f3bb1e9d 100644 --- a/3rdparty/bgfx/src/topology.h +++ b/3rdparty/bgfx/src/topology.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_TOPOLOGY_H_HEADER_GUARD diff --git a/3rdparty/bgfx/src/version.h b/3rdparty/bgfx/src/version.h new file mode 100644 index 00000000000..84767bc8eaf --- /dev/null +++ b/3rdparty/bgfx/src/version.h @@ -0,0 +1,13 @@ +/* + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE + */ + +/* + * + * AUTO GENERATED! DO NOT EDIT! + * + */ + +#define BGFX_REV_NUMBER 8381 +#define BGFX_REV_SHA1 "988565aa983beb0b329ded834cd09f6a198b41e0" diff --git a/3rdparty/bgfx/src/vertexdecl.cpp b/3rdparty/bgfx/src/vertexlayout.cpp index 6c6358626d1..4cebdb4a2b6 100644 --- a/3rdparty/bgfx/src/vertexdecl.cpp +++ b/3rdparty/bgfx/src/vertexlayout.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include <bx/debug.h> @@ -10,7 +10,7 @@ #include <bx/string.h> #include <bx/uint32_t.h> -#include "vertexdecl.h" +#include "vertexlayout.h" namespace bgfx { @@ -44,14 +44,17 @@ namespace bgfx static const uint8_t (*s_attribTypeSize[])[AttribType::Count][4] = { &s_attribTypeSizeD3D9, // Noop + &s_attribTypeSizeD3D1x, // Agc &s_attribTypeSizeD3D9, // Direct3D9 &s_attribTypeSizeD3D1x, // Direct3D11 &s_attribTypeSizeD3D1x, // Direct3D12 &s_attribTypeSizeD3D1x, // Gnm &s_attribTypeSizeGl, // Metal + &s_attribTypeSizeGl, // Nvn &s_attribTypeSizeGl, // OpenGLES &s_attribTypeSizeGl, // OpenGL &s_attribTypeSizeD3D1x, // Vulkan + &s_attribTypeSizeD3D1x, // WebGPU &s_attribTypeSizeD3D9, // Count }; BX_STATIC_ASSERT(BX_COUNTOF(s_attribTypeSize) == RendererType::Count+1); @@ -62,16 +65,16 @@ namespace bgfx s_attribTypeSize[RendererType::Count] = s_attribTypeSize[_type]; } - VertexDecl::VertexDecl() + VertexLayout::VertexLayout() : m_stride(0) { // BK - struct need to have ctor to qualify as non-POD data. // Need this to catch programming errors when serializing struct. } - VertexDecl& VertexDecl::begin(RendererType::Enum _renderer) + VertexLayout& VertexLayout::begin(RendererType::Enum _renderer) { - m_hash = _renderer; // use hash to store renderer type while building VertexDecl. + m_hash = _renderer; // use hash to store renderer type while building VertexLayout. m_stride = 0; bx::memSet(m_attributes, 0xff, sizeof(m_attributes) ); bx::memSet(m_offset, 0, sizeof(m_offset) ); @@ -79,7 +82,7 @@ namespace bgfx return *this; } - void VertexDecl::end() + void VertexLayout::end() { bx::HashMurmur2A murmur; murmur.begin(); @@ -89,7 +92,7 @@ namespace bgfx m_hash = murmur.end(); } - VertexDecl& VertexDecl::add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized, bool _asInt) + VertexLayout& VertexLayout::add(Attrib::Enum _attrib, uint8_t _num, AttribType::Enum _type, bool _normalized, bool _asInt) { const uint16_t encodedNorm = (_normalized&1)<<7; const uint16_t encodedType = (_type&7)<<3; @@ -103,14 +106,14 @@ namespace bgfx return *this; } - VertexDecl& VertexDecl::skip(uint8_t _num) + VertexLayout& VertexLayout::skip(uint8_t _num) { m_stride += _num; return *this; } - void VertexDecl::decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const + void VertexLayout::decode(Attrib::Enum _attrib, uint8_t& _num, AttribType::Enum& _type, bool& _normalized, bool& _asInt) const { uint16_t val = m_attributes[_attrib]; _num = (val&3)+1; @@ -119,6 +122,21 @@ namespace bgfx _asInt = !!(val&(1<<8) ); } + static const bool s_attribTypeIsFloat[] = + { + false, // Uint8 + false, // Uint10 + false, // Int16 + true, // Half + true, // Float + }; + BX_STATIC_ASSERT(BX_COUNTOF(s_attribTypeIsFloat) == AttribType::Count); + + bool isFloat(AttribType::Enum _type) + { + return s_attribTypeIsFloat[_type]; + } + static const char* s_attrName[] = { "P", "Attrib::Position", @@ -240,7 +258,7 @@ namespace bgfx return s_attribTypeToId[_attr].id; } - int32_t write(bx::WriterI* _writer, const VertexDecl& _decl, bx::Error* _err) + int32_t write(bx::WriterI* _writer, const VertexLayout& _layout, bx::Error* _err) { BX_ERROR_SCOPE(_err); @@ -249,22 +267,22 @@ namespace bgfx for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - numAttrs += UINT16_MAX == _decl.m_attributes[attr] ? 0 : 1; + numAttrs += UINT16_MAX == _layout.m_attributes[attr] ? 0 : 1; } total += bx::write(_writer, numAttrs, _err); - total += bx::write(_writer, _decl.m_stride, _err); + total += bx::write(_writer, _layout.m_stride, _err); for (uint32_t attr = 0; attr < Attrib::Count; ++attr) { - if (UINT16_MAX != _decl.m_attributes[attr]) + if (UINT16_MAX != _layout.m_attributes[attr]) { uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); - total += bx::write(_writer, _decl.m_offset[attr], _err); + _layout.decode(Attrib::Enum(attr), num, type, normalized, asInt); + total += bx::write(_writer, _layout.m_offset[attr], _err); total += bx::write(_writer, s_attribToId[attr].id, _err); total += bx::write(_writer, num, _err); total += bx::write(_writer, s_attribTypeToId[type].id, _err); @@ -276,7 +294,7 @@ namespace bgfx return total; } - int32_t read(bx::ReaderI* _reader, VertexDecl& _decl, bx::Error* _err) + int32_t read(bx::ReaderI* _reader, VertexLayout& _layout, bx::Error* _err) { BX_ERROR_SCOPE(_err); @@ -293,7 +311,7 @@ namespace bgfx return total; } - _decl.begin(); + _layout.begin(); for (uint32_t ii = 0; ii < numAttrs; ++ii) { @@ -325,32 +343,32 @@ namespace bgfx if (Attrib::Count != attr && AttribType::Count != type) { - _decl.add(attr, num, type, normalized, asInt); - _decl.m_offset[attr] = offset; + _layout.add(attr, num, type, normalized, asInt); + _layout.m_offset[attr] = offset; } } - _decl.end(); - _decl.m_stride = stride; + _layout.end(); + _layout.m_stride = stride; return total; } - void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexDecl& _decl, void* _data, uint32_t _index) + void vertexPack(const float _input[4], bool _inputNormalized, Attrib::Enum _attr, const VertexLayout& _layout, void* _data, uint32_t _index) { - if (!_decl.has(_attr) ) + if (!_layout.has(_attr) ) { return; } - uint32_t stride = _decl.getStride(); - uint8_t* data = (uint8_t*)_data + _index*stride + _decl.getOffset(_attr); + uint32_t stride = _layout.getStride(); + uint8_t* data = (uint8_t*)_data + _index*stride + _layout.getOffset(_attr); uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(_attr, num, type, normalized, asInt); + _layout.decode(_attr, num, type, normalized, asInt); switch (type) { @@ -492,22 +510,22 @@ namespace bgfx } } - void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexDecl& _decl, const void* _data, uint32_t _index) + void vertexUnpack(float _output[4], Attrib::Enum _attr, const VertexLayout& _layout, const void* _data, uint32_t _index) { - if (!_decl.has(_attr) ) + if (!_layout.has(_attr) ) { bx::memSet(_output, 0, 4*sizeof(float) ); return; } - uint32_t stride = _decl.getStride(); - uint8_t* data = (uint8_t*)_data + _index*stride + _decl.getOffset(_attr); + uint32_t stride = _layout.getStride(); + uint8_t* data = (uint8_t*)_data + _index*stride + _layout.getOffset(_attr); uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _decl.decode(_attr, num, type, normalized, asInt); + _layout.decode(_attr, num, type, normalized, asInt); switch (type) { @@ -618,25 +636,17 @@ namespace bgfx } } - void vertexConvert(const VertexDecl& _destDecl, void* _destData, const VertexDecl& _srcDecl, const void* _srcData, uint32_t _num) + void vertexConvert(const VertexLayout& _destLayout, void* _destData, const VertexLayout& _srcLayout, const void* _srcData, uint32_t _num) { - if (_destDecl.m_hash == _srcDecl.m_hash) + if (_destLayout.m_hash == _srcLayout.m_hash) { - bx::memCopy(_destData, _srcData, _srcDecl.getSize(_num) ); + bx::memCopy(_destData, _srcData, _srcLayout.getSize(_num) ); return; } struct ConvertOp { - enum Enum - { - Set, - Copy, - Convert, - }; - Attrib::Enum attr; - Enum op; uint32_t src; uint32_t dest; uint32_t size; @@ -645,45 +655,51 @@ namespace bgfx ConvertOp convertOp[Attrib::Count]; uint32_t numOps = 0; + const uint8_t* src = (const uint8_t*)_srcData; + uint32_t srcStride = _srcLayout.getStride(); + + uint8_t* dest = (uint8_t*)_destData; + uint32_t destStride = _destLayout.getStride(); + for (uint32_t ii = 0; ii < Attrib::Count; ++ii) { Attrib::Enum attr = (Attrib::Enum)ii; - if (_destDecl.has(attr) ) + if (_destLayout.has(attr) ) { ConvertOp& cop = convertOp[numOps]; cop.attr = attr; - cop.dest = _destDecl.getOffset(attr); + cop.dest = _destLayout.getOffset(attr); uint8_t num; AttribType::Enum type; bool normalized; bool asInt; - _destDecl.decode(attr, num, type, normalized, asInt); + _destLayout.decode(attr, num, type, normalized, asInt); cop.size = (*s_attribTypeSize[0])[type][num-1]; - if (_srcDecl.has(attr) ) + if (_srcLayout.has(attr) ) { - cop.src = _srcDecl.getOffset(attr); - cop.op = _destDecl.m_attributes[attr] == _srcDecl.m_attributes[attr] ? ConvertOp::Copy : ConvertOp::Convert; + cop.src = _srcLayout.getOffset(attr); + + if (_destLayout.m_attributes[attr] == _srcLayout.m_attributes[attr]) + { + bx::memCopy(dest + cop.dest, destStride, src + cop.src, srcStride, cop.size, _num); + } + else + { + ++numOps; + } } else { - cop.op = ConvertOp::Set; + bx::memSet(dest + cop.dest, destStride, 0, cop.size, _num); } - - ++numOps; } } if (0 < numOps) { - const uint8_t* src = (const uint8_t*)_srcData; - uint32_t srcStride = _srcDecl.getStride(); - - uint8_t* dest = (uint8_t*)_destData; - uint32_t destStride = _destDecl.getStride(); - float unpacked[4]; for (uint32_t ii = 0; ii < _num; ++ii) @@ -691,25 +707,11 @@ namespace bgfx for (uint32_t jj = 0; jj < numOps; ++jj) { const ConvertOp& cop = convertOp[jj]; - - switch (cop.op) - { - case ConvertOp::Set: - bx::memSet(dest + cop.dest, 0, cop.size); - break; - - case ConvertOp::Copy: - bx::memCopy(dest + cop.dest, src + cop.src, cop.size); - break; - - case ConvertOp::Convert: - vertexUnpack(unpacked, cop.attr, _srcDecl, src); - vertexPack(unpacked, true, cop.attr, _destDecl, dest); - break; - } + vertexUnpack(unpacked, cop.attr, _srcLayout, src); + vertexPack(unpacked, true, cop.attr, _destLayout, dest); } - src += srcStride; + src += srcStride; dest += destStride; } } @@ -723,48 +725,50 @@ namespace bgfx return xx*xx + yy*yy + zz*zz; } - uint16_t weldVerticesRef(uint16_t* _output, const VertexDecl& _decl, const void* _data, uint16_t _num, float _epsilon) + template<typename IndexT> + static IndexT weldVerticesRef(IndexT* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, float _epsilon) { // Brute force slow vertex welding... const float epsilonSq = _epsilon*_epsilon; uint32_t numVertices = 0; - bx::memSet(_output, 0xff, _num*sizeof(uint16_t) ); + bx::memSet(_output, 0xff, _num*sizeof(IndexT) ); for (uint32_t ii = 0; ii < _num; ++ii) { - if (UINT16_MAX != _output[ii]) + if (IndexT(-1) != _output[ii]) { continue; } - _output[ii] = (uint16_t)ii; + _output[ii] = (IndexT)ii; ++numVertices; float pos[4]; - vertexUnpack(pos, Attrib::Position, _decl, _data, ii); + vertexUnpack(pos, Attrib::Position, _layout, _data, ii); for (uint32_t jj = 0; jj < _num; ++jj) { - if (UINT16_MAX != _output[jj]) + if (IndexT(-1) != _output[jj]) { continue; } float test[4]; - vertexUnpack(test, Attrib::Position, _decl, _data, jj); + vertexUnpack(test, Attrib::Position, _layout, _data, jj); if (sqLength(test, pos) < epsilonSq) { - _output[jj] = (uint16_t)ii; + _output[jj] = IndexT(ii); } } } - return (uint16_t)numVertices; + return IndexT(numVertices); } - uint16_t weldVertices(uint16_t* _output, const VertexDecl& _decl, const void* _data, uint16_t _num, float _epsilon) + template<typename IndexT> + static IndexT weldVertices(IndexT* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, float _epsilon, bx::AllocatorI* _allocator) { const uint32_t hashSize = bx::uint32_nextpow2(_num); const uint32_t hashMask = hashSize-1; @@ -772,23 +776,23 @@ namespace bgfx uint32_t numVertices = 0; - const uint32_t size = sizeof(uint16_t)*(hashSize + _num); - uint16_t* hashTable = (uint16_t*)alloca(size); + const uint32_t size = sizeof(IndexT)*(hashSize + _num); + IndexT* hashTable = (IndexT*)BX_ALLOC(_allocator, size); bx::memSet(hashTable, 0xff, size); - uint16_t* next = hashTable + hashSize; + IndexT* next = hashTable + hashSize; for (uint32_t ii = 0; ii < _num; ++ii) { float pos[4]; - vertexUnpack(pos, Attrib::Position, _decl, _data, ii); + vertexUnpack(pos, Attrib::Position, _layout, _data, ii); uint32_t hashValue = bx::hash<bx::HashMurmur2A>(pos, 3*sizeof(float) ) & hashMask; - uint16_t offset = hashTable[hashValue]; - for (; UINT16_MAX != offset; offset = next[offset]) + IndexT offset = hashTable[hashValue]; + for (; IndexT(-1) != offset; offset = next[offset]) { float test[4]; - vertexUnpack(test, Attrib::Position, _decl, _data, _output[offset]); + vertexUnpack(test, Attrib::Position, _layout, _data, _output[offset]); if (sqLength(test, pos) < epsilonSq) { @@ -797,16 +801,28 @@ namespace bgfx } } - if (UINT16_MAX == offset) + if (IndexT(-1) == offset) { - _output[ii] = (uint16_t)ii; + _output[ii] = IndexT(ii); next[ii] = hashTable[hashValue]; - hashTable[hashValue] = (uint16_t)ii; + hashTable[hashValue] = IndexT(ii); numVertices++; } } - return (uint16_t)numVertices; + BX_FREE(_allocator, hashTable); + + return IndexT(numVertices); + } + + uint32_t weldVertices(void* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon, bx::AllocatorI* _allocator) + { + if (_index32) + { + return weldVertices( (uint32_t*)_output, _layout, _data, _num, _epsilon, _allocator); + } + + return weldVertices( (uint16_t*)_output, _layout, _data, _num, _epsilon, _allocator); } } // namespace bgfx diff --git a/3rdparty/bgfx/src/vertexdecl.h b/3rdparty/bgfx/src/vertexlayout.h index 2b80b1f50c3..afb649a0bfd 100644 --- a/3rdparty/bgfx/src/vertexdecl.h +++ b/3rdparty/bgfx/src/vertexlayout.h @@ -1,6 +1,6 @@ /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #ifndef BGFX_VERTEXDECL_H_HEADER_GUARD @@ -14,6 +14,9 @@ namespace bgfx /// void initAttribTypeSizeTable(RendererType::Enum _type); + /// + bool isFloat(AttribType::Enum _type); + /// Returns attribute name. const char* getAttribName(Attrib::Enum _attr); @@ -30,10 +33,13 @@ namespace bgfx AttribType::Enum idToAttribType(uint16_t id); /// - int32_t write(bx::WriterI* _writer, const bgfx::VertexDecl& _decl, bx::Error* _err = NULL); + int32_t write(bx::WriterI* _writer, const bgfx::VertexLayout& _layout, bx::Error* _err = NULL); + + /// + int32_t read(bx::ReaderI* _reader, bgfx::VertexLayout& _layout, bx::Error* _err = NULL); /// - int32_t read(bx::ReaderI* _reader, bgfx::VertexDecl& _decl, bx::Error* _err = NULL); + uint32_t weldVertices(void* _output, const VertexLayout& _layout, const void* _data, uint32_t _num, bool _index32, float _epsilon, bx::AllocatorI* _allocator); } // namespace bgfx diff --git a/3rdparty/bgfx/src/vs_clear.bin.h b/3rdparty/bgfx/src/vs_clear.bin.h index f884364e3fb..7c0d725462d 100644 --- a/3rdparty/bgfx/src/vs_clear.bin.h +++ b/3rdparty/bgfx/src/vs_clear.bin.h @@ -1,132 +1,180 @@ -static const uint8_t vs_clear_glsl[164] = +static const uint8_t vs_clear_glsl[251] = { - 0x56, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x61, 0x74, // VSH...........at - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, // tribute highp ve - 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x76, // c3 a_position;.v - 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. - 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // highp vec4 tmpva - 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, // r_1;. tmpvar_1. - 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // w = 1.0;. tmpva - 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, // r_1.xyz = a_posi - 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, // tion;. gl_Posit - 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, // ion = tmpvar_1;. - 0x7d, 0x0a, 0x0a, 0x00, // }... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // VSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x02, // gfx_clear_depth. + 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcd, 0x00, 0x00, 0x00, 0x61, 0x74, 0x74, // .............att + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, // ribute vec3 a_po + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, // sition;.uniform + 0x76, 0x65, 0x63, 0x34, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, // vec4 bgfx_clear_ + 0x64, 0x65, 0x70, 0x74, 0x68, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, // depth;.void main + 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, // ().{. vec4 tmp + 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // var_1;. tmpvar_ + 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, // 1.w = 1.0;. tmp + 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, // var_1.xy = a_pos + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x78, 0x79, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, // ition.xy;. tmpv + 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // ar_1.z = bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x2e, 0x78, 0x3b, 0x0a, 0x20, 0x20, 0x67, // ear_depth.x;. g + 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, // l_Position = tmp + 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // var_1;.}... }; -static const uint8_t vs_clear_spv[568] = +static const uint8_t vs_clear_essl[269] = { - 0x56, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x02, 0x00, 0x00, 0x03, 0x02, // VSH.......$..... - 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x00, 0x00, // #.........O..... - 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, // ................ - 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, // ..GLSL.std.450.. - 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, // ................ - 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, // ..........main.. - 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, // ..'...*......... - 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, // ..............ma - 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x27, 0x00, 0x00, 0x00, 0x61, 0x5f, // in........'...a_ - 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x2a, 0x00, // position......*. - 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, // ..@entryPointOut - 0x70, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, // put.gl_Position. - 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x27, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, // ..G...'......... - 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, // ..G...*......... - 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, // ..........!..... - 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, // .............. . - 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, // ................ - 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, // ................ - 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, // ..+............. - 0x80, 0x3f, 0x20, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, // .? ...&......... - 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x26, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x01, 0x00, // ..;...&...'..... - 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 0x00, // .. ...)......... - 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x03, 0x00, // ..;...)...*..... - 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, // ..6............. - 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, // ..............=. - 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x51, 0x00, // ......(...'...Q. - 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, // ......8...(..... - 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x28, 0x00, // ..Q.......9...(. - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x3a, 0x00, // ......Q.......:. - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x09, 0x00, // ..(.......P..... - 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x3a, 0x00, // ..;...8...9...:. - 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x3f, 0x00, // ..............?. - 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x52, 0x00, 0x06, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4e, 0x00, // ..9...R.......N. - 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, // ..?...;.......>. - 0x03, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, // ..*...N.......8. - 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, // ........ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // VSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x02, // gfx_clear_depth. + 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdf, 0x00, 0x00, 0x00, 0x61, 0x74, 0x74, // .............att + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, // ribute highp vec + 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x75, 0x6e, // 3 a_position;.un + 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, // iform highp vec4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, // bgfx_clear_dept + 0x68, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, // h;.void main (). + 0x7b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, // {. highp vec4 t + 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // mpvar_1;. tmpva + 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, // r_1.w = 1.0;. t + 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, // mpvar_1.xy = a_p + 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x78, 0x79, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, // osition.xy;. tm + 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x7a, 0x20, 0x3d, 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, // pvar_1.z = bgfx_ + 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x2e, 0x78, 0x3b, 0x0a, 0x20, // clear_depth.x;. + 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x74, // gl_Position = t + 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // mpvar_1;.}... }; -static const uint8_t vs_clear_dx9[175] = +static const uint8_t vs_clear_spv[835] = { - 0x56, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x03, // VSH............. - 0xfe, 0xff, 0xfe, 0xff, 0x14, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x23, 0x00, // ......CTAB....#. - 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, // ................ - 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x76, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, // ......vs_3_0.Mic - 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, // rosoft (R) HLSL - 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, // Shader Compiler - 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x51, 0x00, 0x00, 0x05, 0x00, 0x00, 0x0f, 0xa0, 0x00, 0x00, // 10.1..Q......... - 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, // .?.............. - 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, // ................ - 0x00, 0x80, 0x00, 0x00, 0x0f, 0xe0, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, // ................ - 0x24, 0x90, 0x00, 0x00, 0x40, 0xa0, 0x00, 0x00, 0x15, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x00, // $...@.......... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // VSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x02, // gfx_clear_depth. + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00, 0x03, 0x02, 0x23, // ...............# + 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x4d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .........M...... + 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, // ................ + 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, // .GLSL.std.450... + 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x07, // ................ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, // .........main... + 0x00, 0x29, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, // .)...,.......... + 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, // .............mai + 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x16, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, // n............Uni + 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, // formBlock....... + 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .........bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, // ear_depth....... + 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x29, 0x00, 0x00, // .............).. + 0x00, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x0a, // .a_position..... + 0x00, 0x2c, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, // .,...@entryPoint + 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, // Output.gl_Positi + 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // on...H.......... + 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x16, 0x00, 0x00, // .#.......G...... + 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, // .....G.......".. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, // .....G.......!.. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x29, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, // .....G...)...... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, // .....G...,...... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, // .............!.. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, // ................ + 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // . .............. + 0x00, 0x03, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // ................ + 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // ............. .. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x11, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, // .....+.......... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x03, 0x00, 0x16, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, // ................ + 0x00, 0x20, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, // . .............. + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, // .;.............. + 0x00, 0x15, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .+.............. + 0x00, 0x20, 0x00, 0x04, 0x00, 0x1b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, // . .............. + 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, // .+.............. + 0x3f, 0x20, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, // ? ...(.......... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x28, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .;...(...)...... + 0x00, 0x20, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, // . ...+.......... + 0x00, 0x3b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, // .;...+...,...... + 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // .6.............. + 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, // .............=.. + 0x00, 0x07, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x41, 0x00, 0x06, // .....*...)...A.. + 0x00, 0x1b, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, // .....H.......... + 0x00, 0x1a, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, // .....=.......I.. + 0x00, 0x48, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, // .H...Q.......J.. + 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, // .*.......Q...... + 0x00, 0x4b, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, // .K...*.......P.. + 0x00, 0x09, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, // .....L...J...K.. + 0x00, 0x49, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x2c, 0x00, 0x00, // .I.......>...,.. + 0x00, 0x4c, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, // .L.......8...... + 0x00, 0x10, 0x00, // ... }; -static const uint8_t vs_clear_dx11[388] = +static const uint8_t vs_clear_dx9[274] = { - 0x56, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x01, 0x00, 0x00, 0x44, 0x58, // VSH.......p...DX - 0x42, 0x43, 0x35, 0x37, 0xf0, 0x90, 0x23, 0xc6, 0x3b, 0x7a, 0xd4, 0x66, 0x38, 0xf5, 0x51, 0x69, // BC57..#.;z.f8.Qi - 0x19, 0xa8, 0x01, 0x00, 0x00, 0x00, 0x70, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, // ......p.......0. - 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x3c, 0x01, 0x00, 0x00, 0x41, 0x6f, // ..........<...Ao - 0x6e, 0x39, 0x78, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x02, 0xfe, 0xff, 0x50, 0x00, // n9x...x.......P. - 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, // ..(.....$...$... - 0x24, 0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, // $...$...$....... - 0xfe, 0xff, 0x51, 0x00, 0x00, 0x05, 0x01, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, // ..Q..........?.. - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, // ................ - 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, // ................ - 0xe4, 0x90, 0x00, 0x00, 0xe4, 0xa0, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0c, 0xc0, 0x00, 0x00, // ................ - 0xaa, 0x90, 0x01, 0x00, 0x44, 0xa0, 0x01, 0x00, 0x14, 0xa0, 0xff, 0xff, 0x00, 0x00, 0x53, 0x48, // ....D.........SH - 0x44, 0x52, 0x50, 0x00, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0x5f, 0x00, // DRP...@......._. - 0x00, 0x03, 0x72, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, 0xf2, 0x20, // ..r.......g.... - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x72, 0x20, // ..........6...r - 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, // ......F.......6. - 0x00, 0x05, 0x82, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, // ... .......@.... - 0x80, 0x3f, 0x3e, 0x00, 0x00, 0x01, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, // .?>...ISGN,..... - 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ...... ......... - 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x50, 0x4f, // ..............PO - 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0xab, 0xab, 0xab, 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, // SITION....OSGN,. - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // .......... ..... - 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, // ................ - 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x00, 0x01, // ..SV_POSITION... - 0x01, 0x00, 0x00, 0x00, // .... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // VSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x02, // gfx_clear_depth. + 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe4, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, // ................ + 0xff, 0xfe, 0xff, 0x22, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, // ...".CTAB....[.. + 0x00, 0x00, 0x03, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, // ................ + 0x00, 0x54, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .T...0.......... + 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, // .D.......bgfx_cl + 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x00, 0xab, 0xab, 0xab, 0x01, 0x00, 0x03, // ear_depth....... + 0x00, 0x01, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x73, 0x5f, // .............vs_ + 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, // 3_0.Microsoft (R + 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, // ) HLSL Shader Co + 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x51, 0x00, 0x00, // mpiler 10.1..Q.. + 0x05, 0x01, 0x00, 0x0f, 0xa0, 0x00, 0x00, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........?....... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, // ................ + 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0xe0, 0x04, 0x00, 0x00, // ................ + 0x04, 0x00, 0x00, 0x0b, 0xe0, 0x00, 0x00, 0x24, 0x90, 0x01, 0x00, 0x60, 0xa0, 0x01, 0x00, 0x25, // .......$...`...% + 0xa0, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x04, 0xe0, 0x00, 0x00, 0x00, 0xa0, 0xff, 0xff, 0x00, // ................ + 0x00, 0x00, // .. }; -static const uint8_t vs_clear_mtl[504] = +static const uint8_t vs_clear_dx11[327] = { - 0x56, 0x53, 0x48, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe9, 0x01, 0x00, 0x00, 0x75, 0x73, // VSH...........us - 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, // ing namespace me - 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, // tal;.struct xlat - 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, // MtlShaderInput { - 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, // . float3 a_posi - 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, // tion [[attribute - 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // (0)]];.};.struct - 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, // xlatMtlShaderOu - 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // tput {. float4 - 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x70, 0x6f, // gl_Position [[po - 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, 0x72, // sition]];.};.str - 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, // uct xlatMtlShade - 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, 0x0a, 0x7d, 0x3b, 0x0a, 0x76, 0x65, // rUniform {.};.ve - 0x72, 0x74, 0x65, 0x78, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, // rtex xlatMtlShad - 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // erOutput xlatMtl - 0x4d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, // Main (xlatMtlSha - 0x64, 0x65, 0x72, 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, // derInput _mtl_i - 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, // [[stage_in]], co - 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, // nstant xlatMtlSh - 0x61, 0x64, 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, // aderUniform& _mt - 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, // l_u [[buffer(0)] - 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, // ]).{. xlatMtlSh - 0x61, 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // aderOutput _mtl_ - 0x6f, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, // o;. float4 tmpv - 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, // ar_1 = 0;. tmpv - 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, // ar_1.w = 1.0;. - 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x5f, // tmpvar_1.xyz = _ - 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x2e, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, // mtl_i.a_position - 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, // ;. _mtl_o.gl_Po - 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // sition = tmpvar_ - 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // 1;. return _mtl - 0x5f, 0x6f, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _o;.}... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // VSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x02, // gfx_clear_depth. + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 0x00, 0x44, 0x58, 0x42, // .............DXB + 0x43, 0xba, 0x7f, 0x2f, 0x23, 0xea, 0x16, 0x4f, 0xd0, 0x8f, 0x33, 0xa6, 0xfb, 0xc5, 0xc0, 0x63, // C../#..O..3....c + 0x01, 0x01, 0x00, 0x00, 0x00, 0x14, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, // .............,.. + 0x00, 0x60, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, // .`.......ISGN,.. + 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ......... ...... + 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x03, 0x00, // ................ + 0x00, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0xab, 0xab, 0xab, 0x4f, 0x53, 0x47, // .POSITION....OSG + 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, // N,........... .. + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, // .....SV_POSITION + 0x00, 0x53, 0x48, 0x44, 0x52, 0x78, 0x00, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x00, // .SHDRx...@...... + 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, // .Y...F. ........ + 0x00, 0x5f, 0x00, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, // ._...2.......g.. + 0x04, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, // .. ..........6.. + 0x05, 0x32, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, // .2 ......F...... + 0x00, 0x36, 0x00, 0x00, 0x06, 0x42, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x80, 0x20, // .6...B ........ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x82, 0x20, 0x10, // .........6.... . + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x3e, 0x00, 0x00, // ......@.....?>.. + 0x01, 0x00, 0x01, 0x01, 0x00, 0x10, 0x00, // ....... +}; +static const uint8_t vs_clear_mtl[545] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x62, // VSH............b + 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x02, // gfx_clear_depth. + 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0x01, 0x00, 0x00, 0x23, 0x69, 0x6e, // .............#in + 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, // clude <metal_std + 0x6c, 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, // lib>.#include <s + 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, // imd/simd.h>..usi + 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, // ng namespace met + 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, // al;..struct _Glo + 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, // bal.{. float4 + 0x20, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, // bgfx_clear_dept + 0x68, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, // h;.};..struct xl + 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x0a, 0x7b, 0x0a, // atMtlMain_out.{. + 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, // float4 gl_Po + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // sition [[positio + 0x6e, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, // n]];.};..struct + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x0a, 0x7b, // xlatMtlMain_in.{ + 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, // . float3 a_po + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, // sition [[attribu + 0x74, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x76, 0x65, 0x72, // te(0)]];.};..ver + 0x74, 0x65, 0x78, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, // tex xlatMtlMain_ + 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, // out xlatMtlMain( + 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x20, 0x69, // xlatMtlMain_in i + 0x6e, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, // n [[stage_in]], + 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, // constant _Global + 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, // & _mtl_u [[buffe + 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, // r(0)]]).{. xl + 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, // atMtlMain_out ou + 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, // t = {};. out. + 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x66, 0x6c, // gl_Position = fl + 0x6f, 0x61, 0x74, 0x34, 0x28, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, // oat4(in.a_positi + 0x6f, 0x6e, 0x2e, 0x78, 0x79, 0x2c, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x62, 0x67, // on.xy, _mtl_u.bg + 0x66, 0x78, 0x5f, 0x63, 0x6c, 0x65, 0x61, 0x72, 0x5f, 0x64, 0x65, 0x70, 0x74, 0x68, 0x2e, 0x78, // fx_clear_depth.x + 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, // , 1.0);. retu + 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x01, 0x01, 0x00, 0x10, // rn out;.}....... + 0x00, // . }; extern const uint8_t* vs_clear_pssl; extern const uint32_t vs_clear_pssl_size; diff --git a/3rdparty/bgfx/src/vs_clear.sc b/3rdparty/bgfx/src/vs_clear.sc index 39abd06d212..809f32be0ef 100644 --- a/3rdparty/bgfx/src/vs_clear.sc +++ b/3rdparty/bgfx/src/vs_clear.sc @@ -1,13 +1,15 @@ $input a_position /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" +uniform vec4 bgfx_clear_depth; + void main() { - gl_Position = vec4(a_position, 1.0); + gl_Position = vec4(a_position.xy, bgfx_clear_depth.x, 1.0); } diff --git a/3rdparty/bgfx/src/vs_debugfont.bin.h b/3rdparty/bgfx/src/vs_debugfont.bin.h index a1bac2f0fe8..461f0360cc4 100644 --- a/3rdparty/bgfx/src/vs_debugfont.bin.h +++ b/3rdparty/bgfx/src/vs_debugfont.bin.h @@ -1,82 +1,116 @@ -static const uint8_t vs_debugfont_glsl[503] = +static const uint8_t vs_debugfont_glsl[457] = { - 0x56, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH..."f...u_mod - 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, // elViewProj...... - 0xd2, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, // ....attribute hi - 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // ghp vec4 a_color - 0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, // 0;.attribute hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, // hp vec4 a_color1 - 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, // ;.attribute high - 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // p vec3 a_positio - 0x6e, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, // n;.attribute hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, // hp vec2 a_texcoo - 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, // rd0;.varying hig - 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, // hp vec4 v_color0 - 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, // ;.varying highp - 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x76, // vec4 v_color1;.v - 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, // arying highp vec - 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, // 2 v_texcoord0;.u - 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x6d, 0x61, 0x74, // niform highp mat - 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, // 4 u_modelViewPro - 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, // j;.void main (). - 0x7b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, // {. highp vec4 t - 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, // mpvar_1;. tmpva - 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, // r_1.w = 1.0;. t - 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, // mpvar_1.xyz = a_ - 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, // position;. gl_P - 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // osition = (u_mod - 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, // elViewProj * tmp - 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // var_1);. v_texc - 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, // oord0 = a_texcoo - 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, // rd0;. v_color0 - 0x3d, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, // = a_color0;. v_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // color1 = a_color - 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // 1;.}... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, // VSH......."f...u + 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj.. + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, // ............attr + 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, // ibute vec4 a_col + 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, // or0;.attribute v + 0x65, 0x63, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x61, 0x74, // ec4 a_color1;.at + 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, // tribute vec3 a_p + 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, // osition;.attribu + 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, // te vec2 a_texcoo + 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, // rd0;.varying vec + 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, // 4 v_color0;.vary + 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // ing vec4 v_color + 0x31, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, // 1;.varying vec2 + 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, // v_texcoord0;.uni + 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, // form mat4 u_mode + 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, // lViewProj;.void + 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x76, 0x65, 0x63, 0x34, // main ().{. vec4 + 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, // tmpvar_1;. tmp + 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, // var_1.w = 1.0;. + 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, // tmpvar_1.xyz = + 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, // a_position;. gl + 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x6d, // _Position = (u_m + 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, // odelViewProj * t + 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x74, 0x65, // mpvar_1);. v_te + 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, // xcoord0 = a_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, // oord0;. v_color + 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x20, 0x20, // 0 = a_color0;. + 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, // v_color1 = a_col + 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // or1;.}... +}; +static const uint8_t vs_debugfont_essl[511] = +{ + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, // VSH......."f...u + 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj.. + 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd2, 0x01, 0x00, 0x00, 0x61, 0x74, 0x74, 0x72, // ............attr + 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, // ibute highp vec4 + 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, // a_color0;.attri + 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, // bute highp vec4 + 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, // a_color1;.attrib + 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, // ute highp vec3 a + 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, // _position;.attri + 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, // bute highp vec2 + 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, // a_texcoord0;.var + 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, // ying highp vec4 + 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, // v_color0;.varyin + 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x76, 0x5f, 0x63, // g highp vec4 v_c + 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, // olor1;.varying h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x32, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, // ighp vec2 v_texc + 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, // oord0;.uniform h + 0x69, 0x67, 0x68, 0x70, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, // ighp mat4 u_mode + 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, // lViewProj;.void + 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x68, 0x69, 0x67, 0x68, // main ().{. high + 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, // p vec4 tmpvar_1; + 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, // . tmpvar_1.w = + 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, // 1.0;. tmpvar_1. + 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, // xyz = a_position + 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, // ;. gl_Position + 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, // = (u_modelViewPr + 0x6f, 0x6a, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, // oj * tmpvar_1);. + 0x20, 0x20, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x3d, 0x20, // v_texcoord0 = + 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x76, // a_texcoord0;. v + 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // _color0 = a_colo + 0x72, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x3d, // r0;. v_color1 = + 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // a_color1;.}... }; -static const uint8_t vs_debugfont_spv[1456] = +static const uint8_t vs_debugfont_spv[1428] = { - 0x56, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH..."f...u_mod - 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x04, 0x00, // elViewProj...... - 0x80, 0x05, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x06, 0x00, 0x08, 0x00, // ......#......... - 0xb6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, // ................ - 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, // ........GLSL.std - 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, // .450............ - 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, // ................ - 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, // main....D...G... - 0x4b, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, // K...O......._... - 0x62, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, // b...f........... - 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, // ............main - 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x24, 0x47, 0x6c, 0x6f, // ........*...$Glo - 0x62, 0x61, 0x6c, 0x00, 0x06, 0x00, 0x07, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // bal.....*....... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, // VSH......."f...u + 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x00, // _modelViewProj.. + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x05, 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, // ..............#. + 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ + 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, // ................ + 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, // GLSL.std.450.... + 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0d, 0x00, // ................ + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, // ........main.... + 0x3d, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, // =...@...D...H... + 0x55, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, // U...X...[..._... + 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, // ................ + 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, // ....main........ + 0x2a, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, 0x6f, 0x63, 0x6b, // *...UniformBlock + 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x07, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........*....... 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x00, // u_modelViewProj. 0x05, 0x00, 0x03, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, // ....,........... - 0x44, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, // D...a_color0.... - 0x05, 0x00, 0x05, 0x00, 0x47, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, // ....G...a_color1 - 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x70, 0x6f, // ........K...a_po - 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x4f, 0x00, 0x00, 0x00, // sition......O... + 0x3d, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x00, 0x00, // =...a_color0.... + 0x05, 0x00, 0x05, 0x00, 0x40, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, // ....@...a_color1 + 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x44, 0x00, 0x00, 0x00, 0x61, 0x5f, 0x70, 0x6f, // ........D...a_po + 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x48, 0x00, 0x00, 0x00, // sition......H... 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x00, 0x05, 0x00, 0x0a, 0x00, // a_texcoord0..... - 0x5c, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, // ....@entryPointO + 0x55, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, // U...@entryPointO 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // utput.gl_Positio - 0x6e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, // n......._...@ent + 0x6e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x58, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, // n.......X...@ent 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x76, 0x5f, // ryPointOutput.v_ - 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x62, 0x00, 0x00, 0x00, // color0......b... + 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x5b, 0x00, 0x00, 0x00, // color0......[... 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, // @entryPointOutpu 0x74, 0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, // t.v_color1...... - 0x66, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, // f...@entryPointO + 0x5f, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, // _...@entryPointO 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, // utput.v_texcoord 0x30, 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0...H...*....... 0x04, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ....H...*....... 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x2a, 0x00, 0x00, 0x00, // #.......H...*... 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, // ............G... 0x2a, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, // *.......G...,... - 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x44, 0x00, 0x00, 0x00, // ".......G...D... - 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x47, 0x00, 0x00, 0x00, // ........G...G... - 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4b, 0x00, 0x00, 0x00, // ........G...K... - 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4f, 0x00, 0x00, 0x00, // ........G...O... - 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x5c, 0x00, 0x00, 0x00, // ........G....... - 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x5f, 0x00, 0x00, 0x00, // ........G..._... - 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x62, 0x00, 0x00, 0x00, // ........G...b... - 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x66, 0x00, 0x00, 0x00, // ........G...f... + 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x2c, 0x00, 0x00, 0x00, // ".......G...,... + 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x3d, 0x00, 0x00, 0x00, // !.......G...=... + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x40, 0x00, 0x00, 0x00, // ........G...@... + 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x44, 0x00, 0x00, 0x00, // ........G...D... + 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, // ........G...H... + 0x1e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x55, 0x00, 0x00, 0x00, // ........G...U... + 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x58, 0x00, 0x00, 0x00, // ........G...X... + 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x5b, 0x00, 0x00, 0x00, // ........G...[... + 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x5f, 0x00, 0x00, 0x00, // ........G..._... 0x1e, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, // ................ 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, // !............... 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, // .... ........... @@ -90,192 +124,181 @@ static const uint8_t vs_debugfont_spv[1456] = 0x29, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // )... ...+....... 0x2a, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // *...;...+...,... 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x2d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // .... ...-....... - 0x29, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // )... ...C....... - 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x43, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, // ....;...C...D... - 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x43, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, // ....;...C...G... - 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // .... ...J....... - 0x09, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, // ....;...J...K... - 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // .... ...N....... - 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, // ....;...N...O... - 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // .... ...[....... - 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, // ....;...[....... - 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, // ....;...[..._... - 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, // ....;...[...b... - 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x65, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // .... ...e....... - 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x65, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, // ....;...e...f... + 0x29, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // )... ...<....... + 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, // ....;...<...=... + 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, // ....;...<...@... + 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x43, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // .... ...C....... + 0x09, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x43, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, // ....;...C...D... + 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x47, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // .... ...G....... + 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x47, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, // ....;...G...H... + 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // .... ...T....... + 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, // ....;...T...U... + 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, // ....;...T...X... + 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x54, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, // ....;...T...[... + 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // .... ...^....... + 0x0b, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x5e, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, // ....;...^..._... 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, // ....6........... 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, 0x00, 0x00, // ................ - 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, // =.......E...D... - 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, // =.......H...G... - 0x3d, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x4b, 0x00, 0x00, 0x00, // =.......L...K... - 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, // =.......P...O... - 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, // Q...........L... - 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, // ....Q........... - 0x4c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, // L.......Q....... - 0x81, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, // ....L.......P... - 0x07, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, // ................ - 0x81, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x2d, 0x00, 0x00, 0x00, // ........A...-... - 0x83, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, // ....,...#...=... - 0x29, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, 0x83, 0x00, 0x00, 0x00, 0x90, 0x00, 0x05, 0x00, // )............... - 0x07, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x84, 0x00, 0x00, 0x00, // ................ - 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0xb3, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, // Q............... - 0x01, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, 0x00, // ................ - 0xb3, 0x00, 0x00, 0x00, 0x52, 0x00, 0x06, 0x00, 0x07, 0x00, 0x00, 0x00, 0xb5, 0x00, 0x00, 0x00, // ....R........... - 0x8f, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, // ............>... - 0x5c, 0x00, 0x00, 0x00, 0xb5, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5f, 0x00, 0x00, 0x00, // ........>..._... - 0x45, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x62, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, // E...>...b...H... - 0x3e, 0x00, 0x03, 0x00, 0x66, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, // >...f...P....... - 0x38, 0x00, 0x01, 0x00, 0x00, 0x04, 0x05, 0x00, 0x06, 0x00, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, // 8.............@. + 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, // =.......>...=... + 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, // =.......A...@... + 0x3d, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, // =.......E...D... + 0x3d, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, // =.......I...H... + 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, // Q.......z...E... + 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, // ....Q.......{... + 0x45, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, // E.......Q....... + 0x7c, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, // |...E.......P... + 0x07, 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x7b, 0x00, 0x00, 0x00, // ....}...z...{... + 0x7c, 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x2d, 0x00, 0x00, 0x00, // |.......A...-... + 0x7e, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, // ~...,...#...=... + 0x29, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x90, 0x00, 0x05, 0x00, // ).......~....... + 0x07, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, // ........}....... + 0x3e, 0x00, 0x03, 0x00, 0x55, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, // >...U.......>... + 0x58, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5b, 0x00, 0x00, 0x00, // X...>...>...[... + 0x41, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, // A...>..._...I... + 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x04, 0x05, 0x00, 0x06, 0x00, 0x01, 0x00, // ....8........... + 0x10, 0x00, 0x40, 0x00, // ..@. }; -static const uint8_t vs_debugfont_dx9[385] = +static const uint8_t vs_debugfont_dx9[393] = { - 0x56, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH..."f...u_mod - 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x04, 0x00, // elViewProj...... - 0x5c, 0x01, 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, 0xfe, 0xff, 0x21, 0x00, 0x43, 0x54, 0x41, 0x42, // ..........!.CTAB - 0x1c, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00, // ....W........... - 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, // ........P...0... - 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........@....... - 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x00, // u_modelViewProj. - 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x76, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, // vs_3_0.Microsoft - 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // (R) HLSL Shader - 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, // Compiler 10.1.. - 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, // ................ - 0x0a, 0x00, 0x01, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, // ................ - 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0f, 0x90, // ................ - 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0x02, // ................ - 0x0a, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x01, 0x80, // ................ - 0x02, 0x00, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x03, 0x00, 0x03, 0xe0, // ................ - 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, // ..............U. - 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, // ................ - 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, // ................ - 0x02, 0x00, 0xaa, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0xe0, // ................ - 0x00, 0x00, 0xe4, 0x80, 0x03, 0x00, 0xe4, 0xa0, 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x0f, 0xe0, // ................ - 0x00, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x0f, 0xe0, 0x01, 0x00, 0xe4, 0x90, // ................ - 0x01, 0x00, 0x00, 0x02, 0x03, 0x00, 0x03, 0xe0, 0x03, 0x00, 0xe4, 0x90, 0xff, 0xff, 0x00, 0x00, // ................ - 0x00, // . + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, // VSH......."f...u + 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj.. + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x01, 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, // ................ + 0xfe, 0xff, 0x21, 0x00, 0x43, 0x54, 0x41, 0x42, 0x1c, 0x00, 0x00, 0x00, 0x57, 0x00, 0x00, 0x00, // ..!.CTAB....W... + 0x00, 0x03, 0xfe, 0xff, 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x91, 0x00, 0x00, // ................ + 0x50, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, // P...0........... + 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, // @.......u_modelV + 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x00, 0x03, 0x00, 0x03, 0x00, 0x04, 0x00, 0x04, 0x00, // iewProj......... + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x73, 0x5f, 0x33, 0x5f, 0x30, 0x00, 0x4d, // ........vs_3_0.M + 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28, 0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, // icrosoft (R) HLS + 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, // L Shader Compile + 0x72, 0x20, 0x31, 0x30, 0x2e, 0x31, 0x00, 0xab, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, // r 10.1.......... + 0x00, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x01, 0x80, 0x01, 0x00, 0x0f, 0x90, // ................ + 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, // ................ + 0x05, 0x00, 0x00, 0x80, 0x03, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x80, // ................ + 0x00, 0x00, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x00, 0x80, 0x01, 0x00, 0x0f, 0xe0, // ................ + 0x1f, 0x00, 0x00, 0x02, 0x0a, 0x00, 0x01, 0x80, 0x02, 0x00, 0x0f, 0xe0, 0x1f, 0x00, 0x00, 0x02, // ................ + 0x05, 0x00, 0x00, 0x80, 0x03, 0x00, 0x03, 0xe0, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, // ................ + 0x01, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0x55, 0x90, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, // ......U......... + 0x00, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0x00, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x04, // ................ + 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x00, 0x00, 0xe4, 0x80, // ................ + 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0xe4, 0x80, 0x03, 0x00, 0xe4, 0xa0, // ................ + 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x02, // ................ + 0x02, 0x00, 0x0f, 0xe0, 0x01, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x02, 0x03, 0x00, 0x03, 0xe0, // ................ + 0x03, 0x00, 0xe4, 0x90, 0xff, 0xff, 0x00, 0x00, 0x00, // ......... }; -static const uint8_t vs_debugfont_dx11[976] = +static const uint8_t vs_debugfont_dx11[724] = { - 0x56, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH..."f...u_mod - 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, // elViewProj...... - 0xa0, 0x03, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, 0x92, 0x16, 0xf8, 0xaa, 0xc4, 0x4c, 0xee, 0x93, // ....DXBC.....L.. - 0x22, 0xee, 0x2e, 0xcd, 0x17, 0x4a, 0xe5, 0x55, 0x01, 0x00, 0x00, 0x00, 0xa0, 0x03, 0x00, 0x00, // "....J.U........ - 0x04, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x01, 0x00, 0x00, 0x8c, 0x02, 0x00, 0x00, // ....0...0....... - 0x14, 0x03, 0x00, 0x00, 0x41, 0x6f, 0x6e, 0x39, 0xf8, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, // ....Aon9........ - 0x00, 0x02, 0xfe, 0xff, 0xc4, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x01, 0x00, 0x24, 0x00, // ........4.....$. - 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x24, 0x00, 0x01, 0x00, 0x30, 0x00, // ..0...0...$...0. - 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ................ - 0x00, 0x02, 0xfe, 0xff, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x80, 0x00, 0x00, 0x0f, 0x90, // ................ - 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x01, 0x80, 0x01, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, // ................ - 0x05, 0x00, 0x02, 0x80, 0x02, 0x00, 0x0f, 0x90, 0x1f, 0x00, 0x00, 0x02, 0x05, 0x00, 0x03, 0x80, // ................ - 0x03, 0x00, 0x0f, 0x90, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x0f, 0x80, 0x02, 0x00, 0x55, 0x90, // ..............U. - 0x02, 0x00, 0xe4, 0xa0, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, 0x01, 0x00, 0xe4, 0xa0, // ................ - 0x02, 0x00, 0x00, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x80, // ................ - 0x03, 0x00, 0xe4, 0xa0, 0x02, 0x00, 0xaa, 0x90, 0x00, 0x00, 0xe4, 0x80, 0x02, 0x00, 0x00, 0x03, // ................ - 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe4, 0x80, 0x04, 0x00, 0xe4, 0xa0, 0x04, 0x00, 0x00, 0x04, // ................ - 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0xff, 0x80, 0x00, 0x00, 0xe4, 0xa0, 0x00, 0x00, 0xe4, 0x80, // ................ - 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0c, 0xc0, 0x00, 0x00, 0xe4, 0x80, 0x01, 0x00, 0x00, 0x02, // ................ - 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x02, 0x01, 0x00, 0x0f, 0xe0, // ................ - 0x01, 0x00, 0xe4, 0x90, 0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x03, 0xe0, 0x03, 0x00, 0xe4, 0x90, // ................ - 0xff, 0xff, 0x00, 0x00, 0x53, 0x48, 0x44, 0x52, 0x54, 0x01, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, // ....SHDRT...@... - 0x55, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, // U...Y...F. ..... - 0x04, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ...._........... - 0x5f, 0x00, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, // _..........._... - 0x72, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, // r......._...2... - 0x03, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ....g.... ...... - 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, // ....e.... ...... - 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, // e.... ......e... - 0x32, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, // 2 ......h....... - 0x38, 0x00, 0x00, 0x08, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x15, 0x10, 0x00, // 8...........V... - 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // ....F. ......... - 0x32, 0x00, 0x00, 0x0a, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, // 2...........F. . - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, // ................ - 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0xf2, 0x00, 0x10, 0x00, // F.......2....... - 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, // ....F. ......... - 0xa6, 0x1a, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........F....... - 0x00, 0x00, 0x00, 0x08, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, // ..... ......F... - 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // ....F. ......... - 0x36, 0x00, 0x00, 0x05, 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, // 6.... ......F... - 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, // ....6.... ...... - 0x46, 0x1e, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0x32, 0x20, 0x10, 0x00, // F.......6...2 .. - 0x03, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, // ....F.......>... - 0x49, 0x53, 0x47, 0x4e, 0x80, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // ISGN............ - 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // h............... - 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // ........h....... - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, // ................ - 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // n............... - 0x02, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........w....... - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, // ................ - 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x54, // COLOR.POSITION.T - 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0x84, 0x00, 0x00, 0x00, // EXCOORD.OSGN.... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, // VSH......."f...u + 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x00, // _modelViewProj.. + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x02, 0x00, 0x00, 0x44, 0x58, 0x42, 0x43, // ............DXBC + 0xcf, 0x16, 0xf5, 0x3b, 0x91, 0xcc, 0xae, 0x24, 0x91, 0x6c, 0x08, 0xa4, 0x91, 0x55, 0x2a, 0x0e, // ...;...$.l...U*. + 0x01, 0x00, 0x00, 0x00, 0x9c, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, // ............,... + 0xb4, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 0x80, 0x00, 0x00, 0x00, // ....@...ISGN.... 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........h....... - 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ - 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // t............... - 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, // ........t....... - 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ - 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // z............... - 0x03, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, // ........SV_POSIT - 0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, // ION.COLOR.TEXCOO - 0x52, 0x44, 0x00, 0xab, 0x00, 0x04, 0x05, 0x00, 0x06, 0x00, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, // RD............@. + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, // ................ + 0x68, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // h............... + 0x01, 0x00, 0x00, 0x00, 0x0f, 0x0f, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........n....... + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, // ................ + 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // w............... + 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x43, 0x4f, 0x4c, 0x4f, 0x52, 0x00, 0x50, 0x4f, // ........COLOR.PO + 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, // SITION.TEXCOORD. + 0x4f, 0x53, 0x47, 0x4e, 0x84, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // OSGN............ + 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // h............... + 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........t....... + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, // ................ + 0x74, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, // t............... + 0x02, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ........z....... + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x0c, 0x00, 0x00, // ................ + 0x53, 0x56, 0x5f, 0x50, 0x4f, 0x53, 0x49, 0x54, 0x49, 0x4f, 0x4e, 0x00, 0x43, 0x4f, 0x4c, 0x4f, // SV_POSITION.COLO + 0x52, 0x00, 0x54, 0x45, 0x58, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x00, 0xab, 0x53, 0x48, 0x44, 0x52, // R.TEXCOORD..SHDR + 0x54, 0x01, 0x00, 0x00, 0x40, 0x00, 0x01, 0x00, 0x55, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x04, // T...@...U...Y... + 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, // F. ........._... + 0xf2, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0xf2, 0x10, 0x10, 0x00, // ........_....... + 0x01, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0x72, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, // ...._...r....... + 0x5f, 0x00, 0x00, 0x03, 0x32, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, // _...2.......g... + 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, // . ..........e... + 0xf2, 0x20, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0xf2, 0x20, 0x10, 0x00, // . ......e.... .. + 0x02, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x03, 0x32, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, // ....e...2 ...... + 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x08, 0xf2, 0x00, 0x10, 0x00, // h.......8....... + 0x00, 0x00, 0x00, 0x00, 0x56, 0x15, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, // ....V.......F. . + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0xf2, 0x00, 0x10, 0x00, // ........2....... + 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // ....F. ......... + 0x06, 0x10, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, // ........F....... + 0x32, 0x00, 0x00, 0x0a, 0xf2, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, // 2...........F. . + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xa6, 0x1a, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, // ................ + 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf2, 0x20, 0x10, 0x00, // F............ .. + 0x00, 0x00, 0x00, 0x00, 0x46, 0x0e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x00, // ....F.......F. . + 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, 0xf2, 0x20, 0x10, 0x00, // ........6.... .. + 0x01, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x05, // ....F.......6... + 0xf2, 0x20, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, // . ......F....... + 0x36, 0x00, 0x00, 0x05, 0x32, 0x20, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, // 6...2 ......F... + 0x03, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0x00, 0x04, 0x05, 0x00, 0x06, 0x00, 0x01, 0x00, // ....>........... + 0x10, 0x00, 0x40, 0x00, // ..@. }; -static const uint8_t vs_debugfont_mtl[869] = +static const uint8_t vs_debugfont_mtl[987] = { - 0x56, 0x53, 0x48, 0x05, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, 0x5f, 0x6d, 0x6f, 0x64, // VSH..."f...u_mod - 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, // elViewProj...... - 0x40, 0x03, 0x00, 0x00, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, // @...using namesp - 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, // ace metal;.struc - 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x49, // t xlatMtlShaderI - 0x6e, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, // nput {. float4 - 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, // a_color0 [[attri - 0x62, 0x75, 0x74, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, // bute(0)]];. flo - 0x61, 0x74, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x5b, 0x5b, 0x61, // at4 a_color1 [[a - 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x31, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, // ttribute(1)]];. - 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, // float3 a_positi - 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x32, // on [[attribute(2 - 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, 0x61, 0x5f, // )]];. float2 a_ - 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, // texcoord0 [[attr - 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x33, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, // ibute(3)]];.};.s - 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, // truct xlatMtlSha - 0x64, 0x65, 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, // derOutput {. fl - 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, // oat4 gl_Position - 0x20, 0x5b, 0x5b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, // [[position]];. - 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, // float4 v_color0 - 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x76, 0x5f, 0x63, 0x6f, 0x6c, // ;. float4 v_col - 0x6f, 0x72, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, 0x76, 0x5f, // or1;. float2 v_ - 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x73, 0x74, // texcoord0;.};.st - 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, // ruct xlatMtlShad - 0x65, 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, // erUniform {. fl - 0x6f, 0x61, 0x74, 0x34, 0x78, 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, // oat4x4 u_modelVi - 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x76, 0x65, 0x72, 0x74, 0x65, // ewProj;.};.verte - 0x78, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, 0x4f, // x xlatMtlShaderO - 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, // utput xlatMtlMai - 0x6e, 0x20, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, 0x72, // n (xlatMtlShader - 0x49, 0x6e, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x20, 0x5b, 0x5b, 0x73, // Input _mtl_i [[s - 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, // tage_in]], const - 0x61, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, // ant xlatMtlShade - 0x72, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, // rUniform& _mtl_u - 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, // [[buffer(0)]]). - 0x7b, 0x0a, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x53, 0x68, 0x61, 0x64, 0x65, // {. xlatMtlShade - 0x72, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, 0x0a, // rOutput _mtl_o;. - 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // float4 tmpvar_ - 0x31, 0x20, 0x3d, 0x20, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // 1 = 0;. tmpvar_ - 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, // 1.w = 1.0;. tmp - 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, // var_1.xyz = _mtl - 0x5f, 0x69, 0x2e, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, // _i.a_position;. - 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, // _mtl_o.gl_Posit - 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x75, 0x5f, // ion = (_mtl_u.u_ - 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x20, 0x2a, 0x20, // modelViewProj * - 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, // tmpvar_1);. _mt - 0x6c, 0x5f, 0x6f, 0x2e, 0x76, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, // l_o.v_texcoord0 - 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x2e, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, // = _mtl_i.a_texco - 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x2e, 0x76, // ord0;. _mtl_o.v - 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x69, // _color0 = _mtl_i - 0x2e, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x5f, 0x6d, 0x74, // .a_color0;. _mt - 0x6c, 0x5f, 0x6f, 0x2e, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x3d, 0x20, 0x5f, // l_o.v_color1 = _ - 0x6d, 0x74, 0x6c, 0x5f, 0x69, 0x2e, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x3b, 0x0a, // mtl_i.a_color1;. - 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x6f, 0x3b, // return _mtl_o; - 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // .}... + 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xb8, 0xbe, 0x22, 0x66, 0x01, 0x00, 0x0f, 0x75, // VSH......."f...u + 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x04, 0x01, // _modelViewProj.. + 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa3, 0x03, 0x00, 0x00, 0x23, 0x69, 0x6e, 0x63, // ............#inc + 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, 0x74, 0x64, 0x6c, // lude <metal_stdl + 0x69, 0x62, 0x3e, 0x0a, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x73, 0x69, // ib>.#include <si + 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, 0x73, 0x69, 0x6e, // md/simd.h>..usin + 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, // g namespace meta + 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, // l;..struct _Glob + 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x78, // al.{. float4x + 0x34, 0x20, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, // 4 u_modelViewPro + 0x6a, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, // j;.};..struct xl + 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x0a, 0x7b, 0x0a, // atMtlMain_out.{. + 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x5f, 0x65, 0x6e, 0x74, 0x72, // float4 _entr + 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, // yPointOutput_v_c + 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, // olor0 [[user(loc + 0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, // n0)]];. float + 0x34, 0x20, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, // 4 _entryPointOut + 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x5b, 0x5b, 0x75, // put_v_color1 [[u + 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, 0x31, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, // ser(locn1)]];. + 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, // float2 _entryP + 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x74, 0x65, 0x78, // ointOutput_v_tex + 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, // coord0 [[user(lo + 0x63, 0x6e, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, // cn2)]];. floa + 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, // t4 gl_Position [ + 0x5b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, // [position]];.};. + 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // .struct xlatMtlM + 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, // ain_in.{. flo + 0x61, 0x74, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, 0x20, 0x5b, 0x5b, 0x61, // at4 a_color0 [[a + 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, // ttribute(0)]];. + 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // float4 a_colo + 0x72, 0x31, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x31, // r1 [[attribute(1 + 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x20, // )]];. float3 + 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, // a_position [[att + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x32, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, // ribute(2)]];. + 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x32, 0x20, 0x61, 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, // float2 a_texcoo + 0x72, 0x64, 0x30, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, // rd0 [[attribute( + 0x33, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, // 3)]];.};..vertex + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out + 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, 0x6c, 0x61, // xlatMtlMain(xla + 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x5b, // tMtlMain_in in [ + 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, // [stage_in]], con + 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, // stant _Global& _ + 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, // mtl_u [[buffer(0 + 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // )]]).{. xlatM + 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, // tlMain_out out = + 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, // {};. out.gl_ + 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, // Position = _mtl_ + 0x75, 0x2e, 0x75, 0x5f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x56, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, // u.u_modelViewPro + 0x6a, 0x20, 0x2a, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x28, 0x69, 0x6e, 0x2e, 0x61, 0x5f, // j * float4(in.a_ + 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, // position, 1.0);. + 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, // out._entryPo + 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // intOutput_v_colo + 0x72, 0x30, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, 0x72, 0x30, // r0 = in.a_color0 + 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, // ;. out._entry + 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x63, 0x6f, // PointOutput_v_co + 0x6c, 0x6f, 0x72, 0x31, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x63, 0x6f, 0x6c, 0x6f, // lor1 = in.a_colo + 0x72, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x5f, 0x65, 0x6e, 0x74, // r1;. out._ent + 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, // ryPointOutput_v_ + 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x20, 0x3d, 0x20, 0x69, 0x6e, 0x2e, 0x61, // texcoord0 = in.a + 0x5f, 0x74, 0x65, 0x78, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, // _texcoord0;. + 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // return out;.}... + 0x04, 0x05, 0x00, 0x06, 0x00, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, // .........@. }; extern const uint8_t* vs_debugfont_pssl; extern const uint32_t vs_debugfont_pssl_size; diff --git a/3rdparty/bgfx/src/vs_debugfont.sc b/3rdparty/bgfx/src/vs_debugfont.sc index 8c09d62a6a7..c344b716111 100644 --- a/3rdparty/bgfx/src/vs_debugfont.sc +++ b/3rdparty/bgfx/src/vs_debugfont.sc @@ -2,8 +2,8 @@ $input a_position, a_color0, a_color1, a_texcoord0 $output v_color0, v_color1, v_texcoord0 /* - * Copyright 2011-2018 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ #include "bgfx_shader.sh" |