2024-04-12 09:27:30 +02:00
|
|
|
#include "Descriptor.h"
|
2024-04-13 23:51:38 +02:00
|
|
|
#include "Buffer.h"
|
|
|
|
|
#include "Enums.h"
|
2024-08-28 17:54:14 +02:00
|
|
|
#include "Foundation/NSArray.hpp"
|
2024-08-26 21:49:09 +02:00
|
|
|
#include "Foundation/NSObject.hpp"
|
2024-04-15 13:48:34 +02:00
|
|
|
#include "Graphics/Descriptor.h"
|
2024-04-13 23:51:38 +02:00
|
|
|
#include "Graphics/Initializer.h"
|
2024-05-17 18:08:11 +02:00
|
|
|
#include "Graphics/Metal/Resources.h"
|
2024-08-28 17:54:14 +02:00
|
|
|
#include "Graphics/Metal/Shader.h"
|
2024-04-15 13:48:34 +02:00
|
|
|
#include "Metal/MTLArgument.hpp"
|
2024-08-28 17:54:14 +02:00
|
|
|
#include "Metal/MTLArgumentEncoder.hpp"
|
2024-04-15 13:48:34 +02:00
|
|
|
#include "Metal/MTLDevice.hpp"
|
|
|
|
|
#include "Metal/MTLResource.hpp"
|
2024-08-28 17:54:14 +02:00
|
|
|
#include "Metal/MTLStageInputOutputDescriptor.hpp"
|
2024-04-15 13:48:34 +02:00
|
|
|
#include "Metal/MTLTexture.hpp"
|
2024-04-13 23:51:38 +02:00
|
|
|
#include "Texture.h"
|
2024-08-26 21:49:09 +02:00
|
|
|
#include <CRC.h>
|
2024-08-28 17:54:14 +02:00
|
|
|
#include <Foundation/Foundation.h>
|
2024-04-15 13:48:34 +02:00
|
|
|
#include <iostream>
|
2024-04-12 09:27:30 +02:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
using namespace Seele::Metal;
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name) : Gfx::DescriptorLayout(name), graphics(graphics) {}
|
2024-04-13 23:51:38 +02:00
|
|
|
|
|
|
|
|
DescriptorLayout::~DescriptorLayout() {}
|
|
|
|
|
|
|
|
|
|
void DescriptorLayout::create() {
|
2024-08-26 21:49:09 +02:00
|
|
|
pool = new DescriptorPool(graphics, this);
|
2024-08-28 17:54:14 +02:00
|
|
|
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32());
|
|
|
|
|
MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()];
|
|
|
|
|
for(uint32 i = 0; i < descriptorBindings.size(); ++i) {
|
|
|
|
|
objects[i] = MTL::ArgumentDescriptor::alloc()->init();
|
|
|
|
|
objects[i]->setIndex(i);
|
|
|
|
|
objects[i]->setAccess(cast(descriptorBindings[i].access));
|
|
|
|
|
objects[i]->setArrayLength(descriptorBindings[i].descriptorCount);
|
|
|
|
|
objects[i]->setDataType(MTL::DataTypeStruct);
|
|
|
|
|
}
|
|
|
|
|
arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size());
|
2024-04-12 09:27:30 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
MTL::ArgumentEncoder* DescriptorLayout::createEncoder() {
|
|
|
|
|
return graphics->getDevice()->newArgumentEncoder(arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
|
2024-04-13 23:51:38 +02:00
|
|
|
|
|
|
|
|
DescriptorPool::~DescriptorPool() {}
|
|
|
|
|
|
|
|
|
|
Gfx::PDescriptorSet DescriptorPool::allocateDescriptorSet() {
|
2024-08-28 17:54:14 +02:00
|
|
|
for (uint32 setIndex = 0; setIndex < allocatedSets.size(); ++setIndex) {
|
|
|
|
|
if (allocatedSets[setIndex]->isCurrentlyBound()) {
|
|
|
|
|
// Currently in use, skip
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Found set, stop searching
|
|
|
|
|
return PDescriptorSet(allocatedSets[setIndex]);
|
2024-04-13 23:51:38 +02:00
|
|
|
}
|
2024-08-28 17:54:14 +02:00
|
|
|
allocatedSets.add(new DescriptorSet(graphics, this));
|
|
|
|
|
return PDescriptorSet(allocatedSets.back());
|
2024-04-13 23:51:38 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
void DescriptorPool::reset() {}
|
2024-04-13 23:51:38 +02:00
|
|
|
|
|
|
|
|
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
2024-08-28 17:54:14 +02:00
|
|
|
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) {
|
|
|
|
|
boundResources.resize(owner->getLayout()->getBindings().size());
|
|
|
|
|
for (uint32 i = 0; i < boundResources.size(); ++i) {
|
|
|
|
|
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
|
|
|
|
|
}
|
2024-04-13 23:51:38 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
DescriptorSet::~DescriptorSet() {}
|
2024-04-13 23:51:38 +02:00
|
|
|
|
|
|
|
|
void DescriptorSet::writeChanges() {}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) {
|
|
|
|
|
boundResources[binding][0] = uniformBuffer.cast<UniformBuffer>()->getHandle();
|
2024-04-13 23:51:38 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) {
|
|
|
|
|
boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
|
2024-05-17 18:08:11 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) {
|
|
|
|
|
boundResources[binding][0] = uniformBuffer.cast<IndexBuffer>()->getHandle();
|
2024-04-13 23:51:38 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
|
|
|
|
|
boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
|
2024-08-26 21:49:09 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) {
|
|
|
|
|
boundResources[binding][0] = nullptr; // Samplers are not resources??????
|
|
|
|
|
}
|
2024-08-26 21:49:09 +02:00
|
|
|
|
2024-08-28 17:54:14 +02:00
|
|
|
void DescriptorSet::updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) {
|
|
|
|
|
boundResources[binding][dstArrayIndex] = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {}
|
|
|
|
|
|
|
|
|
|
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {}
|
|
|
|
|
|
|
|
|
|
void DescriptorSet::updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) {}
|
|
|
|
|
|
|
|
|
|
void DescriptorSet::updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) {}
|
|
|
|
|
|
|
|
|
|
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) {}
|
|
|
|
|
|
|
|
|
|
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
|
2024-04-20 21:35:43 +02:00
|
|
|
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
|
2024-04-13 23:51:38 +02:00
|
|
|
|
2024-04-15 13:48:34 +02:00
|
|
|
PipelineLayout::~PipelineLayout() {}
|
2024-04-13 23:51:38 +02:00
|
|
|
|
2024-04-15 13:48:34 +02:00
|
|
|
void PipelineLayout::create() {
|
2024-08-28 17:54:14 +02:00
|
|
|
for (auto& [_, set] : descriptorSetLayouts) {
|
|
|
|
|
assert(set->getHash() != 0);
|
|
|
|
|
uint32 setHash = set->getHash();
|
|
|
|
|
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
|
|
|
|
}
|
2024-04-19 18:23:36 +02:00
|
|
|
}
|