rework the lut system

This commit is contained in:
Samuliak 2024-10-31 09:25:01 +01:00
parent 90420160f2
commit 158be432fc
No known key found for this signature in database
9 changed files with 273 additions and 152 deletions

View file

@ -135,7 +135,10 @@ public:
colorAttachment->setDestinationAlphaBlendFactor(toMTLBlendFactor(alphaDestFunc));
}
desc->setDepthAttachmentPixelFormat(toMTLPixelFormatDepth(hash.depthFmt));
MTL::PixelFormat depthFormat = toMTLPixelFormatDepth(hash.depthFmt);
desc->setDepthAttachmentPixelFormat(depthFormat);
if (hash.depthFmt == DepthFmt::Depth24Stencil8)
desc->setStencilAttachmentPixelFormat(depthFormat);
NS::Error* error = nullptr;
desc->setLabel(toNSString("Draw pipeline"));

View file

@ -0,0 +1,25 @@
#pragma once
#include <Metal/Metal.hpp>
namespace Metal {
class LutTexture {
public:
LutTexture(MTL::Device* device, MTL::TextureType type, MTL::PixelFormat pixelFormat, u32 width, u32 height, const char* name);
~LutTexture();
u32 getNextIndex();
// Getters
MTL::Texture* getTexture() { return texture; }
u32 getCurrentIndex() { return currentIndex; }
private:
MTL::Texture* texture;
u32 currentIndex = 0;
};
} // namespace Metal

View file

@ -1,4 +1,5 @@
#pragma once
#include <array>
#include <string>
#include <Metal/Metal.hpp>

View file

@ -1,3 +1,5 @@
#pragma once
#include <Metal/Metal.hpp>
#include <QuartzCore/QuartzCore.hpp>
@ -8,6 +10,8 @@
#include "mtl_draw_pipeline_cache.hpp"
#include "mtl_depth_stencil_cache.hpp"
#include "mtl_vertex_buffer_cache.hpp"
#include "mtl_lut_texture.hpp"
// HACK: use the OpenGL cache
#include "../renderer_gl/surface_cache.hpp"
@ -54,12 +58,15 @@ class RendererMTL final : public Renderer {
Metal::DepthStencilCache depthStencilCache;
Metal::VertexBufferCache vertexBufferCache;
// Objects
// Resources
MTL::SamplerState* nearestSampler;
MTL::SamplerState* linearSampler;
MTL::Texture* lutTexture;
MTL::Texture* nullTexture;
MTL::DepthStencilState* defaultDepthStencilState;
Metal::LutTexture* lutLightingTexture;
Metal::LutTexture* lutFogTexture;
// Pipelines
MTL::RenderPipelineState* displayPipeline;
MTL::RenderPipelineState* copyToLutTexturePipeline;
@ -91,21 +98,7 @@ class RendererMTL final : public Renderer {
}
}
void beginRenderPassIfNeeded(MTL::RenderPassDescriptor* renderPassDescriptor, bool doesClears, MTL::Texture* colorTexture, MTL::Texture* depthTexture = nullptr) {
createCommandBufferIfNeeded();
if (doesClears || !renderCommandEncoder || colorTexture != lastColorTexture || (depthTexture != lastDepthTexture && !(lastDepthTexture && !depthTexture))) {
endRenderPass();
renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor);
renderCommandEncoder->setLabel(toNSString(nextRenderPassName));
lastColorTexture = colorTexture;
lastDepthTexture = depthTexture;
}
renderPassDescriptor->release();
}
void beginRenderPassIfNeeded(MTL::RenderPassDescriptor* renderPassDescriptor, bool doesClears, MTL::Texture* colorTexture, MTL::Texture* depthTexture = nullptr);
void commitCommandBuffer() {
if (renderCommandEncoder) {
@ -115,6 +108,8 @@ class RendererMTL final : public Renderer {
}
if (commandBuffer) {
commandBuffer->commit();
// HACK
commandBuffer->waitUntilCompleted();
commandBuffer->release();
commandBuffer = nullptr;
}