Browse Source

misc metal fix/optim (#1241)

- setLabel now in 'wrapper' I have tested this and it compiles on older sdks ( gives warning). It works on iOS8 device.
- fixed texture skip
- fixed performance issue related to submitBlit. It caused problem because it closed active rendercommand encoder even when blit was not used, so device had to store/load framebuffer. ( thanks to @jazzbre)
attilaz 8 years ago
parent
commit
4371a31a2f
2 changed files with 20 additions and 5 deletions
  1. 11 0
      src/renderer_mtl.h
  2. 9 5
      src/renderer_mtl.mm

+ 11 - 0
src/renderer_mtl.h

@@ -326,6 +326,12 @@ namespace bgfx { namespace mtl
 
 	MTL_CLASS(Function)
 		NSArray* vertexAttributes() { return m_obj.vertexAttributes; }
+
+		void setLabel(const char* _label)
+		{
+			if ([m_obj respondsToSelector:@selector(setLabel:)])
+				[m_obj setLabel:@(_label)];
+		}
 	MTL_CLASS_END
 
 	MTL_CLASS(Library)
@@ -498,6 +504,11 @@ namespace bgfx { namespace mtl
 		{
 			return m_obj.textureType;
 		}
+
+		void setLabel(const char* _label)
+		{
+			[m_obj setLabel:@(_label)];
+		}
 	MTL_CLASS_END
 
 	typedef id<MTLComputePipelineState> ComputePipelineState;

+ 9 - 5
src/renderer_mtl.mm

@@ -23,7 +23,6 @@
    03-raymarch: OSX10.11.3 nothing is visible ( depth/color swap in fragment output struct fixed this )
    24-nbody: no generated compute shaders for metal
 
-
 Known issues(driver problems??):
   OSX mac mini(late 2014), OSX10.11.3 : nanovg-rendering: color writemask off causes problem...
   03-raymarch: OSX nothing is visible  ( depth/color order should be swapped in fragment output struct)
@@ -33,6 +32,8 @@ Known issues(driver problems??):
   Only on this device ( no problem on iPad Air 2 with iOS9.3.1)
 
   TODOs:
+ - support multiple vertex buffers: 34-mvs
+
  - framebufferMtl and TextureMtl resolve
 
  - FrameBufferMtl::postReset recreate framebuffer???
@@ -988,11 +989,11 @@ namespace bgfx { namespace mtl
 			switch (_handle.type)
 			{
 			case Handle::Shader:
-//				m_shaders[_handle.idx].m_function.m_obj.label = [NSString stringWithUTF8String:_name];
+				m_shaders[_handle.idx].m_function.setLabel(_name);
 				break;
 
 			case Handle::Texture:
-				m_textures[_handle.idx].m_ptr.m_obj.label = [NSString stringWithUTF8String:_name];
+				m_textures[_handle.idx].m_ptr.setLabel(_name);
 				break;
 
 			default:
@@ -2067,7 +2068,7 @@ namespace bgfx { namespace mtl
 			FrameBufferMtl& frameBuffer = s_renderMtl->m_frameBuffers[_fbHandle.idx];
 			murmur.add(frameBuffer.m_pixelFormatHash);
 		}
-		murmur.add(_declHandle.idx);
+		murmur.add(s_renderMtl->m_vertexDecls[_declHandle.idx].m_hash);
 		murmur.add(_numInstanceData);
 		uint32_t hash = murmur.end();
 
@@ -2544,7 +2545,7 @@ namespace bgfx { namespace mtl
 			desc.width  = textureWidth;
 			desc.height = textureHeight;
 			desc.depth  = bx::uint32_max(1,imageContainer.m_depth);
-			desc.mipmapLevelCount = imageContainer.m_numMips;
+			desc.mipmapLevelCount = numMips;
 			desc.sampleCount      = 1;
 			desc.arrayLength = numLayers;
 
@@ -3047,6 +3048,9 @@ namespace bgfx { namespace mtl
 
 	void RendererContextMtl::submitBlit(BlitState& _bs, uint16_t _view)
 	{
+		if (!_bs.hasItem(_view))
+			return;
+
 		if (0 != m_renderCommandEncoder)
 		{
 			m_renderCommandEncoder.endEncoding();