14 id<MTLRenderPipelineState> pipeline) {
15 if (pipeline == pipeline_) {
19 [encoder_ setRenderPipelineState:pipeline_];
23 id<MTLDepthStencilState> depth_stencil) {
24 if (depth_stencil_ == depth_stencil) {
27 depth_stencil_ = depth_stencil;
28 [encoder_ setDepthStencilState:depth_stencil_];
34 id<MTLBuffer> buffer) {
35 auto& buffers_map = buffers_[stage];
36 auto found = buffers_map.find(index);
37 if (found != buffers_map.end() && found->second.buffer == buffer) {
39 if (found->second.offset == offset) {
45 found->second.offset = offset;
49 [encoder_ setVertexBufferOffset:offset atIndex:index];
52 [encoder_ setFragmentBufferOffset:offset atIndex:index];
55 VALIDATION_LOG <<
"Cannot update buffer offset of an unknown stage.";
60 buffers_map[index] = {buffer,
static_cast<size_t>(offset)};
63 [encoder_ setVertexBuffer:buffer offset:offset atIndex:index];
66 [encoder_ setFragmentBuffer:buffer offset:offset atIndex:index];
77 id<MTLTexture> texture) {
78 auto& texture_map = textures_[stage];
79 auto found = texture_map.find(index);
80 if (found != texture_map.end() && found->second == texture) {
84 texture_map[index] = texture;
87 [encoder_ setVertexTexture:texture atIndex:index];
90 [encoder_ setFragmentTexture:texture atIndex:index];
101 id<MTLSamplerState> sampler) {
102 auto& sampler_map = samplers_[stage];
103 auto found = sampler_map.find(index);
104 if (found != sampler_map.end() && found->second == sampler) {
108 sampler_map[index] = sampler;
111 [encoder_ setVertexSamplerState:sampler atIndex:index];
114 [encoder_ setFragmentSamplerState:sampler atIndex:index];
124 if (viewport_.has_value() && viewport_.value() == viewport) {
127 [encoder_ setViewport:MTLViewport{
135 viewport_ = viewport;
139 if (scissor_.has_value() && scissor_.value() == scissor) {
143 setScissorRect:MTLScissorRect{
144 .x =
static_cast<NSUInteger
>(scissor.
GetX()),
145 .y =
static_cast<NSUInteger
>(scissor.
GetY()),
146 .width =
static_cast<NSUInteger
>(scissor.
GetWidth()),
147 .height =
static_cast<NSUInteger
>(scissor.
GetHeight()),
153 if (stencil_ref_.has_value() && stencil_ref_.value() == stencil_ref) {
156 [encoder_ setStencilReferenceValue:stencil_ref];
157 stencil_ref_ = stencil_ref;
void SetScissor(const IRect &scissor)
Set the encoder scissor rect if the value is different from the current encoder state.
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.
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.