Some actually useful metal changes???
This commit is contained in:
@@ -32,9 +32,10 @@ void DescriptorLayout::create() {
|
||||
pool = new DescriptorPool(graphics, this);
|
||||
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32());
|
||||
MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()];
|
||||
flattenedBindingCount = 0;
|
||||
for (uint32 i = 0; i < descriptorBindings.size(); ++i) {
|
||||
objects[i] = MTL::ArgumentDescriptor::alloc()->init();
|
||||
objects[i]->setIndex(i);
|
||||
objects[i]->setIndex(flattenedBindingCount);
|
||||
objects[i]->setAccess(cast(descriptorBindings[i].access));
|
||||
objects[i]->setArrayLength(descriptorBindings[i].descriptorCount);
|
||||
MTL::DataType dataType;
|
||||
@@ -47,13 +48,16 @@ void DescriptorLayout::create() {
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
|
||||
dataType = MTL::DataTypeTexture;
|
||||
break;
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
|
||||
dataType = MTL::DataTypePointer;
|
||||
break;
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
|
||||
dataType = MTL::DataTypeChar;
|
||||
objects[i]->setArrayLength(descriptorBindings[i].uniformLength);
|
||||
break;
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLER:
|
||||
dataType = MTL::DataTypeSampler;
|
||||
break;
|
||||
@@ -89,6 +93,9 @@ void DescriptorLayout::create() {
|
||||
break;
|
||||
}
|
||||
objects[i]->setTextureType(textureType);
|
||||
for(uint32 j = 0; j < descriptorBindings[i].descriptorCount; ++j) {
|
||||
flattenMap[flattenIndex(i, j)] = flattenedBindingCount++;
|
||||
}
|
||||
}
|
||||
arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size());
|
||||
}
|
||||
@@ -119,49 +126,71 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
||||
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) {
|
||||
encoder = owner->getLayout()->createEncoder();
|
||||
argumentBuffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), 0);
|
||||
std::cout << owner->getLayout()->getName() << ": " << encoder->encodedLength() << std::endl;
|
||||
encoder->setArgumentBuffer(argumentBuffer, 0);
|
||||
boundResources.resize(owner->getLayout()->getBindings().size());
|
||||
boundResources.resize(owner->getLayout()->getTotalBindingCount());
|
||||
}
|
||||
|
||||
DescriptorSet::~DescriptorSet() {}
|
||||
|
||||
void DescriptorSet::writeChanges() {}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) {
|
||||
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PUniformBuffer buffer = uniformBuffer.cast<UniformBuffer>();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, binding);
|
||||
boundResources[binding] = buffer->getHandle();
|
||||
std::memcpy(encoder->constantData(flattenedIndex), buffer->getContents(), buffer->getSize());
|
||||
boundResources[flattenedIndex] = nullptr;
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) {
|
||||
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PShaderBuffer buffer = uniformBuffer.cast<ShaderBuffer>();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, binding);
|
||||
boundResources[binding] = buffer->getHandle();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex);
|
||||
boundResources[flattenedIndex] = buffer->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) {
|
||||
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer uniformBuffer) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PVertexBuffer buffer = uniformBuffer.cast<VertexBuffer>();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex);
|
||||
boundResources[flattenedIndex] = buffer->getHandle();
|
||||
}
|
||||
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer uniformBuffer) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PIndexBuffer buffer = uniformBuffer.cast<IndexBuffer>();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, binding);
|
||||
boundResources[binding] = buffer->getHandle();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex);
|
||||
boundResources[flattenedIndex] = buffer->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) {
|
||||
void DescriptorSet::updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PSampler sampler = samplerState.cast<Sampler>();
|
||||
encoder->setSamplerState(sampler->getHandle(), binding);
|
||||
boundResources[binding] = nullptr; // Samplers are not resources??????
|
||||
encoder->setSamplerState(sampler->getHandle(), flattenedIndex);
|
||||
boundResources[flattenedIndex] = nullptr; // Samplers are not resources??????
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {
|
||||
PTextureBase base = texture.cast<TextureBase>();
|
||||
encoder->setTexture(base->getHandle()->texture, binding);
|
||||
boundResources[binding] = base->getHandle()->texture;
|
||||
void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PTextureBase tex = texture.cast<TextureBase>();
|
||||
encoder->setTexture(tex->getImage(), flattenedIndex);
|
||||
boundResources[flattenedIndex] = tex->getImage();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) { assert(false && "TODO"); }
|
||||
void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PTextureBase tex = texture.cast<TextureBase>();
|
||||
encoder->setTexture(tex->getImage(), flattenedIndex);
|
||||
boundResources[flattenedIndex] = tex->getImage();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) { assert(false && "TODO"); }
|
||||
void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) {
|
||||
uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
|
||||
PTextureBase tex = texture.cast<TextureBase>();
|
||||
encoder->setTexture(tex->getImage(), flattenedIndex);
|
||||
boundResources[flattenedIndex] = tex->getImage();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) { assert(false && "TODO"); }
|
||||
void DescriptorSet::updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) { assert(false && "TODO"); }
|
||||
|
||||
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
|
||||
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
|
||||
|
||||
Reference in New Issue
Block a user