From ddb1ffae67f0653f2b735e1af8e944f194e76bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 19 May 2018 09:32:22 -0700 Subject: [PATCH] Metal: Fixed pso collsion. --- src/renderer_mtl.h | 11 ++++++----- src/renderer_mtl.mm | 18 ++++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/renderer_mtl.h b/src/renderer_mtl.h index c3eeb4852..5a27b97ce 100644 --- a/src/renderer_mtl.h +++ b/src/renderer_mtl.h @@ -54,11 +54,11 @@ namespace bgfx { namespace mtl #define MTL_MAX_FRAMES_IN_FLIGHT (3) -#define MTL_CLASS(name) \ - class name \ - { \ - public: \ - name(id _obj = nil) : m_obj(_obj) {} \ +#define MTL_CLASS(name) \ + class name \ + { \ + public: \ + name(id _obj = nil) : m_obj(_obj) {} \ operator id () const { return m_obj; } \ id m_obj; @@ -775,6 +775,7 @@ namespace bgfx { namespace mtl } Function m_function; + uint32_t m_hash; }; struct ProgramMtl diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index b228e9816..856d8d29f 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -1780,7 +1780,8 @@ namespace bgfx { namespace mtl | BGFX_STATE_BLEND_ALPHA_TO_COVERAGE ); - bool independentBlendEnable = !!(BGFX_STATE_BLEND_INDEPENDENT & _state); + const bool independentBlendEnable = !!(BGFX_STATE_BLEND_INDEPENDENT & _state); + ProgramMtl& program = m_program[_programIdx]; bx::HashMurmur2A murmur; murmur.begin(); @@ -1798,6 +1799,12 @@ namespace bgfx { namespace mtl 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); @@ -1916,7 +1923,6 @@ namespace bgfx { namespace mtl } } - ProgramMtl& program = m_program[_programIdx]; pd.vertexFunction = program.m_vsh->m_function; pd.fragmentFunction = program.m_fsh != NULL ? program.m_fsh->m_function : NULL; @@ -2374,6 +2380,14 @@ namespace bgfx { namespace mtl , "Failed to create %s shader." , BGFX_CHUNK_MAGIC_FSH == magic ? "Fragment" : BGFX_CHUNK_MAGIC_VSH == magic ? "Vertex" : "Compute" ); + + bx::HashMurmur2A murmur; + murmur.begin(); + murmur.add(iohash); + murmur.add(code, shaderSize); +// murmur.add(numAttrs); +// murmur.add(m_attrMask, numAttrs); + m_hash = murmur.end(); } void ProgramMtl::create(const ShaderMtl* _vsh, const ShaderMtl* _fsh)