5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_PASS_BINDINGS_CACHE_MTL_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_METAL_PASS_BINDINGS_CACHE_MTL_H_
8 #include <Metal/Metal.h>
36 void SetEncoder(id<MTLRenderCommandEncoder> encoder);
56 id<MTLBuffer> buffer);
70 id<MTLSamplerState> sampler);
85 struct BufferOffsetPair {
86 id<MTLBuffer> buffer =
nullptr;
89 using BufferMap = std::map<uint64_t, BufferOffsetPair>;
90 using TextureMap = std::map<uint64_t, id<MTLTexture>>;
91 using SamplerMap = std::map<uint64_t, id<MTLSamplerState>>;
93 id<MTLRenderCommandEncoder> encoder_;
94 id<MTLRenderPipelineState> pipeline_ =
nullptr;
95 id<MTLDepthStencilState> depth_stencil_ =
nullptr;
96 std::map<ShaderStage, BufferMap> buffers_;
97 std::map<ShaderStage, TextureMap> textures_;
98 std::map<ShaderStage, SamplerMap> samplers_;
99 std::optional<Viewport> viewport_;
100 std::optional<IRect> scissor_;
101 std::optional<uint32_t> stencil_ref_;
Ensures that bindings on the pass are not redundantly set or updated. Avoids making the driver do add...
PassBindingsCacheMTL(const PassBindingsCacheMTL &)=delete
void SetScissor(const IRect &scissor)
Set the encoder scissor rect if the value is different from the current encoder state.
~PassBindingsCacheMTL()=default
void SetStencilRef(uint32_t stencil_ref)
Set the encoder's stencil reference if the value is different from the current encoder state.
void SetRenderPipelineState(id< MTLRenderPipelineState > pipeline)
Set the render pipeline state for the current encoder.
bool SetSampler(ShaderStage stage, uint64_t index, id< MTLSamplerState > sampler)
Set the sampler for the given stage and binding.
bool SetBuffer(ShaderStage stage, uint64_t index, uint64_t offset, id< MTLBuffer > buffer)
Set the buffer for the given shader stage, binding, and offset.
void SetViewport(const Viewport &viewport)
Set the viewport if the value is different from the current encoder state.
void SetDepthStencilState(id< MTLDepthStencilState > depth_stencil)
Set the depth and stencil state for the current encoder.
void SetEncoder(id< MTLRenderCommandEncoder > encoder)
Set the command encoder for this pass bindings cache.
bool SetTexture(ShaderStage stage, uint64_t index, id< MTLTexture > texture)
Set the texture for the given stage and binding.
PassBindingsCacheMTL(PassBindingsCacheMTL &&)=delete