Browse Source

metal: work on storage buffers

Alex Szpakowski 4 years ago
parent
commit
7851124260
2 changed files with 39 additions and 0 deletions
  1. 10 0
      src/modules/graphics/metal/Graphics.mm
  2. 29 0
      src/modules/graphics/metal/Shader.mm

+ 10 - 0
src/modules/graphics/metal/Graphics.mm

@@ -964,6 +964,16 @@ void Graphics::applyShaderUniforms(id<MTLRenderCommandEncoder> renderEncoder, lo
 		if (sampindex != LOVE_UINT8_MAX)
 		if (sampindex != LOVE_UINT8_MAX)
 			setSampler(renderEncoder, bindings, ShaderStage::STAGE_PIXEL, sampindex, sampler);
 			setSampler(renderEncoder, bindings, ShaderStage::STAGE_PIXEL, sampindex, sampler);
 	}
 	}
+
+	for (const Shader::BufferBinding &b : s->getBufferBindings())
+	{
+		uint8 index = b.stages[ShaderStage::STAGE_VERTEX];
+		if (index != LOVE_UINT8_MAX)
+			setBuffer(renderEncoder, bindings, ShaderStage::STAGE_VERTEX, index, b.buffer, 0);
+		index = b.stages[ShaderStage::STAGE_PIXEL];
+		if (index != LOVE_UINT8_MAX)
+			setBuffer(renderEncoder, bindings, ShaderStage::STAGE_PIXEL, index, b.buffer, 0);
+	}
 }
 }
 
 
 static void setVertexBuffers(id<MTLRenderCommandEncoder> encoder, const BufferBindings *buffers, Graphics::RenderEncoderBindings &bindings)
 static void setVertexBuffers(id<MTLRenderCommandEncoder> encoder, const BufferBindings *buffers, Graphics::RenderEncoderBindings &bindings)

+ 29 - 0
src/modules/graphics/metal/Shader.mm

@@ -684,6 +684,35 @@ void Shader::compileFromGLSLang(id<MTLDevice> device, const glslang::TProgram &p
 					b.samplerStages[stageindex] = (uint8) samplerbinding;
 					b.samplerStages[stageindex] = (uint8) samplerbinding;
 				}
 				}
 			}
 			}
+
+			for (const auto &resource : resources.storage_buffers)
+			{
+				auto it = uniforms.find(resource.name);
+				if (it == uniforms.end())
+					continue;
+
+				UniformInfo &u = it->second;
+
+				uint32 bufferbinding = msl.get_automatic_msl_resource_binding(resource.id);
+				if (bufferbinding == (uint32)-1)
+					continue;
+
+				for (int i = 0; i < u.count; i++)
+				{
+					if (u.ints[i] == -1)
+					{
+						u.ints[i] = (int)bufferBindings.size();
+						BufferBinding b = {};
+
+						for (uint8 &stagebinding : b.stages)
+							stagebinding = LOVE_UINT8_MAX;
+
+						bufferBindings.push_back(b);
+					}
+
+					bufferBindings[u.ints[i]].stages[stageindex] = (uint8) bufferbinding;
+				}
+			}
 		}
 		}
 		catch (std::exception &e)
 		catch (std::exception &e)
 		{
 		{