8#include <Metal/Metal.hpp>
37 std::vector<BindGroupLayoutEntryDesc>
entries;
44 [[nodiscard]] uint32_t
groupIndex()
const {
return _groupIndex; }
46 [[nodiscard]]
const std::vector<BindGroupLayoutEntryDesc>&
entries()
const {
return _entries; }
49 for (
auto& e : _entries) {
50 if (e.binding == binding)
59 std::vector<BindGroupLayoutEntryDesc> _entries;
65 _device(device), _layout(
layout), _encoder(encoder)
67 assert(_device &&
"Device must not be null");
68 assert(_layout &&
"Layout must not be null");
69 assert(_encoder &&
"Argument encoder must not be null");
71 NS::UInteger length = _encoder->encodedLength();
73 _argBuffer= _device->newBuffer(length, MTL::ResourceStorageModeManaged);
74 assert(_argBuffer &&
"Failed to allocate argument buffer");
76 _encoder->setArgumentBuffer(_argBuffer, 0);
83 _argBuffer->release();
93 [[nodiscard]] MTL::Buffer*
argBuffer()
const {
return _argBuffer; }
95 void setBuffer(
const uint32_t binding,
const MTL::Buffer* buffer,
const NS::UInteger offset = 0)
const
97 if (
auto* entry = _layout->findEntry(binding); !entry ||
102 _encoder->setBuffer(buffer, offset, binding);
105 void setSampler(
const uint32_t binding,
const MTL::SamplerState* sampler)
const
111 _encoder->setSamplerState(sampler, binding);
114 void setTexture(
const uint32_t binding,
const MTL::Texture* texture)
const
116 if (
auto* entry = _layout->findEntry(binding); !entry ||
121 _encoder->setTexture(texture, binding);
127 _argBuffer->didModifyRange(NS::Range::Make(0, _argBuffer->length()));
131 MTL::Device* _device = nil;
133 MTL::ArgumentEncoder* _encoder = nil;
134 MTL::Buffer* _argBuffer = nil;
147 if (index >= _bindGroupLayouts.size())
151 return _bindGroupLayouts[index];
156 std::vector<BindGroupLayout*> _bindGroupLayouts;
ShaderStageFlags visibility