mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-06-04 04:47:22 +12:00
don't bind resources unnecessarily
This commit is contained in:
parent
158be432fc
commit
272c24d8e4
8 changed files with 128 additions and 41 deletions
58
include/renderer_mtl/mtl_command_encoder.hpp
Normal file
58
include/renderer_mtl/mtl_command_encoder.hpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
|
||||
#include <Metal/Metal.hpp>
|
||||
|
||||
namespace Metal {
|
||||
|
||||
struct RenderState {
|
||||
MTL::RenderPipelineState* renderPipelineState = nullptr;
|
||||
MTL::DepthStencilState* depthStencilState = nullptr;
|
||||
MTL::Texture* textures[3] = {nullptr};
|
||||
MTL::SamplerState* samplerStates[3] = {nullptr};
|
||||
};
|
||||
|
||||
class CommandEncoder {
|
||||
public:
|
||||
void newRenderCommandEncoder(MTL::RenderCommandEncoder* rce) {
|
||||
renderCommandEncoder = rce;
|
||||
|
||||
// Reset the render state
|
||||
renderState = RenderState{};
|
||||
}
|
||||
|
||||
// Resource binding
|
||||
void setRenderPipelineState(MTL::RenderPipelineState* renderPipelineState) {
|
||||
if (renderPipelineState != renderState.renderPipelineState) {
|
||||
renderCommandEncoder->setRenderPipelineState(renderPipelineState);
|
||||
renderState.renderPipelineState = renderPipelineState;
|
||||
}
|
||||
}
|
||||
|
||||
void setDepthStencilState(MTL::DepthStencilState* depthStencilState) {
|
||||
if (depthStencilState != renderState.depthStencilState) {
|
||||
renderCommandEncoder->setDepthStencilState(depthStencilState);
|
||||
renderState.depthStencilState = depthStencilState;
|
||||
}
|
||||
}
|
||||
|
||||
void setFragmentTexture(MTL::Texture* texture, u32 index) {
|
||||
if (texture != renderState.textures[index]) {
|
||||
renderCommandEncoder->setFragmentTexture(texture, index);
|
||||
renderState.textures[index] = texture;
|
||||
}
|
||||
}
|
||||
|
||||
void setFragmentSamplerState(MTL::SamplerState* samplerState, u32 index) {
|
||||
if (samplerState != renderState.samplerStates[index]) {
|
||||
renderCommandEncoder->setFragmentSamplerState(samplerState, index);
|
||||
renderState.samplerStates[index] = samplerState;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
MTL::RenderCommandEncoder* renderCommandEncoder = nullptr;
|
||||
|
||||
RenderState renderState;
|
||||
};
|
||||
|
||||
} // namespace Metal
|
6
include/renderer_mtl/mtl_common.hpp
Normal file
6
include/renderer_mtl/mtl_common.hpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <Metal/Metal.hpp>
|
||||
|
||||
#define GET_HELPER_TEXTURE_BINDING(binding) (30 - binding)
|
||||
#define GET_HELPER_SAMPLER_STATE_BINDING(binding) (15 - binding)
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <Metal/Metal.hpp>
|
||||
#include "mtl_common.hpp"
|
||||
|
||||
namespace Metal {
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mtl_depth_stencil_cache.hpp"
|
||||
#include "mtl_vertex_buffer_cache.hpp"
|
||||
#include "mtl_lut_texture.hpp"
|
||||
#include "mtl_command_encoder.hpp"
|
||||
|
||||
// HACK: use the OpenGL cache
|
||||
#include "../renderer_gl/surface_cache.hpp"
|
||||
|
@ -46,6 +47,8 @@ class RendererMTL final : public Renderer {
|
|||
MTL::Device* device;
|
||||
MTL::CommandQueue* commandQueue;
|
||||
|
||||
Metal::CommandEncoder commandEncoder;
|
||||
|
||||
// Libraries
|
||||
MTL::Library* library;
|
||||
|
||||
|
@ -69,7 +72,7 @@ class RendererMTL final : public Renderer {
|
|||
|
||||
// Pipelines
|
||||
MTL::RenderPipelineState* displayPipeline;
|
||||
MTL::RenderPipelineState* copyToLutTexturePipeline;
|
||||
//MTL::RenderPipelineState* copyToLutTexturePipeline;
|
||||
|
||||
// Clears
|
||||
std::map<MTL::Texture*, Color4> colorClearOps;
|
||||
|
@ -177,7 +180,7 @@ class RendererMTL final : public Renderer {
|
|||
Metal::DepthStencilRenderTarget& getDepthRenderTarget();
|
||||
Metal::Texture& getTexture(Metal::Texture& tex);
|
||||
void setupTextureEnvState(MTL::RenderCommandEncoder* encoder);
|
||||
void bindTexturesToSlots(MTL::RenderCommandEncoder* encoder);
|
||||
void bindTexturesToSlots();
|
||||
void updateLightingLUT(MTL::RenderCommandEncoder* encoder);
|
||||
void updateFogLUT(MTL::RenderCommandEncoder* encoder);
|
||||
void textureCopyImpl(Metal::ColorRenderTarget& srcFramebuffer, Metal::ColorRenderTarget& destFramebuffer, const Math::Rect<u32>& srcRect, const Math::Rect<u32>& destRect);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue