metal: initial shader texture binding implementation.

rework metal shader compilation/parsing.
This commit is contained in:
Alex Szpakowski
2021-03-31 18:35:57 -03:00
parent 46ca836bd5
commit 52d4a5c679
9 changed files with 399 additions and 253 deletions
+22
View File
@@ -21,6 +21,7 @@
#pragma once
#include "libraries/xxHash/xxhash.h"
#include "common/int.h"
#include "graphics/Shader.h"
#include "graphics/Graphics.h"
#include "graphics/renderstate.h"
@@ -33,6 +34,11 @@
#include <map>
#include <string>
namespace glslang
{
class TProgram;
}
namespace love
{
namespace graphics
@@ -67,6 +73,17 @@ public:
}
};
struct TextureBinding
{
id<MTLTexture> texture;
id<MTLSamplerState> sampler;
bool isMainTexture;
uint8 texturestages[ShaderStage::STAGE_MAX_ENUM];
uint8 samplerstages[ShaderStage::STAGE_MAX_ENUM];
};
Shader(id<MTLDevice> device, love::graphics::ShaderStage *vertex, love::graphics::ShaderStage *pixel);
virtual ~Shader();
@@ -86,6 +103,7 @@ public:
id<MTLRenderPipelineState> getCachedRenderPipeline(const RenderPipelineKey &key);
static int getUniformBufferBinding();
const std::vector<TextureBinding> &getTextureBindings() const { return textureBindings; }
uint8 *getLocalUniformBufferData() { return localUniformBufferData; }
size_t getLocalUniformBufferSize() const { return localUniformBufferSize; }
@@ -101,6 +119,8 @@ private:
}
};
void compileFromGLSLang(id<MTLDevice> device, const glslang::TProgram &program);
id<MTLFunction> functions[ShaderStage::STAGE_MAX_ENUM];
UniformInfo *builtinUniformInfo[BUILTIN_MAX_ENUM];
@@ -112,6 +132,8 @@ private:
std::map<std::string, int> attributes;
std::vector<TextureBinding> textureBindings;
std::unordered_map<RenderPipelineKey, const void *, RenderPipelineHasher> cachedRenderPipelines;
}; // Metal