Some actually useful metal changes???

This commit is contained in:
Dynamitos
2024-11-01 21:04:06 +01:00
parent 2811757476
commit 32d3bd8ad8
26 changed files with 152 additions and 73 deletions
+1 -1
+2 -1
View File
@@ -399,7 +399,8 @@ void MeshLoader::loadMaterials(const aiScene* scene, const Array<PTextureAsset>&
}; };
uint32 twoSided = false; uint32 twoSided = false;
float opacity = 1.0f; float opacity = 1.0f;
const char* mat = material->GetName().C_Str(); aiString matName = material->GetName();
const char* mat = matName.C_Str();
if (strcmp(mat, "Leaves0119_14_S") == 0) { if (strcmp(mat, "Leaves0119_14_S") == 0) {
opacity = 0.5f; opacity = 0.5f;
+3 -3
View File
@@ -106,9 +106,9 @@ int main() {
//AssetImporter::importTexture(TextureImportArgs{ //AssetImporter::importTexture(TextureImportArgs{
// .filePath = sourcePath / "import/textures/azeroth_height.png", // .filePath = sourcePath / "import/textures/azeroth_height.png",
//}); //});
AssetImporter::importTexture(TextureImportArgs{ //AssetImporter::importTexture(TextureImportArgs{
.filePath = sourcePath / "import/textures/wgen.png", // .filePath = sourcePath / "import/textures/wgen.png",
}); //});
//AssetImporter::importMesh(MeshImportArgs{ //AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb", // .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
// .importPath = "Whitechapel", // .importPath = "Whitechapel",
+2 -2
View File
@@ -216,7 +216,7 @@ template <size_t Power> class CBT {
uint32_t first_bit = tree.depthOffset[currentDepth] + tree.bitCount[currentDepth] * id_in_level; uint32_t first_bit = tree.depthOffset[currentDepth] + tree.bitCount[currentDepth] * id_in_level;
uint32_t local_id = first_bit % 64; uint32_t local_id = first_bit % 64;
uint64_t target_bits = (heapValue >> local_id) & tree.bitMask[currentDepth]; uint64_t target_bits = (heapValue >> local_id) & tree.bitMask[currentDepth];
uint32_t heapValue = c - countbits(target_bits); uint32_t heapValue = c - std::popcount(target_bits);
uint32_t b = handle < heapValue ? 0u : 1u; uint32_t b = handle < heapValue ? 0u : 1u;
@@ -507,4 +507,4 @@ struct MeshUpdater {
Gfx::OComputeShader lebEvaluateCS; Gfx::OComputeShader lebEvaluateCS;
Gfx::PComputePipeline lebEvaluate; Gfx::PComputePipeline lebEvaluate;
}; };
}; // namespace Seele }; // namespace Seele
+2
View File
@@ -13,6 +13,8 @@ struct DescriptorBinding {
SeDescriptorBindingFlags bindingFlags = 0; SeDescriptorBindingFlags bindingFlags = 0;
SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL; SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL;
Gfx::SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT; Gfx::SeDescriptorAccessTypeFlags access = SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT;
// In Metal uniforms are plain bytes, and for that we need to know the struct size
uint32 uniformLength = 0;
}; };
DECLARE_REF(DescriptorPool) DECLARE_REF(DescriptorPool)
-2
View File
@@ -88,8 +88,6 @@ class Graphics {
virtual PComputePipeline createComputePipeline(ComputePipelineCreateInfo createInfo) = 0; virtual PComputePipeline createComputePipeline(ComputePipelineCreateInfo createInfo) = 0;
virtual OSampler createSampler(const SamplerCreateInfo& createInfo) = 0; virtual OSampler createSampler(const SamplerCreateInfo& createInfo) = 0;
virtual OComputeShader createComputeShaderFromBinary(std::string_view binaryName) = 0;
virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0; virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0;
virtual OPipelineLayout createPipelineLayout(const std::string& name = "", PPipelineLayout baseLayout = nullptr) = 0; virtual OPipelineLayout createPipelineLayout(const std::string& name = "", PPipelineLayout baseLayout = nullptr) = 0;
+7 -2
View File
@@ -89,18 +89,23 @@ class IndexBuffer : public Gfx::IndexBuffer, public Buffer {
}; };
DEFINE_REF(IndexBuffer) DEFINE_REF(IndexBuffer)
DEFINE_REF(IndexBuffer) DEFINE_REF(IndexBuffer)
class UniformBuffer : public Gfx::UniformBuffer, public Buffer { // Metal Uniform Buffer is not a buffer, but just plain bytes
class UniformBuffer : public Gfx::UniformBuffer {
public: public:
UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo); UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo);
virtual ~UniformBuffer(); virtual ~UniformBuffer();
virtual void updateContents(uint64 offset, uint64 size, void* data) override; virtual void updateContents(uint64 offset, uint64 size, void* data) override;
virtual void rotateBuffer(uint64 size) override; virtual void rotateBuffer(uint64 size) override;
void* getContents() const { return contents.data(); }
size_t getSize() const { return contents.size(); }
protected: protected:
// Inherited via QueueOwnedResource // Inherited via QueueOwnedResource
virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override; virtual void executeOwnershipBarrier(Gfx::QueueType newOwner) override;
virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, virtual void executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) override; Gfx::SePipelineStageFlags dstStage) override;
private:
Array<uint8> contents;
}; };
DEFINE_REF(UniformBuffer) DEFINE_REF(UniformBuffer)
class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer { class ShaderBuffer : public Gfx::ShaderBuffer, public Buffer {
+12 -10
View File
@@ -164,36 +164,38 @@ void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePi
} }
UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo) UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo)
: Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo), : Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo)
Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_UNIFORM_BUFFER_BIT, createInfo.sourceData.owner, , contents(createInfo.sourceData.size) {
createInfo.dynamic, createInfo.name) {
if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) { if (createInfo.sourceData.size > 0 && createInfo.sourceData.data != nullptr) {
getAlloc()->updateContents(createInfo.sourceData.offset, createInfo.sourceData.size, createInfo.sourceData.data); std::memcpy(contents.data(), createInfo.sourceData.data, createInfo.sourceData.size);
} }
} }
UniformBuffer::~UniformBuffer() {} UniformBuffer::~UniformBuffer() {}
void UniformBuffer::rotateBuffer(uint64 size) { Metal::Buffer::rotateBuffer(size); } void UniformBuffer::rotateBuffer(uint64 size) {
contents.clear();
contents.resize(size);
}
void UniformBuffer::updateContents(uint64 offset, uint64 size, void* data) { void UniformBuffer::updateContents(uint64 offset, uint64 size, void* data) {
if (size > 0 && data != nullptr) { if (size > 0 && data != nullptr) {
Metal::Buffer::rotateBuffer(size); contents.resize(offset+size);
getAlloc()->updateContents(offset, size, data); std::memcpy(contents.data()+offset, data, size);
} }
} }
void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { Metal::Buffer::transferOwnership(newOwner); } void UniformBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { }
void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess, void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
Gfx::SePipelineStageFlags dstStage) { Gfx::SePipelineStageFlags dstStage) {
Metal::Buffer::pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
} }
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo) ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo)
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo), : Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo),
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT, createInfo.sourceData.owner, Seele::Metal::Buffer(graphics, createInfo.sourceData.size, Gfx::SE_BUFFER_USAGE_STORAGE_BUFFER_BIT, createInfo.sourceData.owner,
createInfo.dynamic, createInfo.name, createInfo.createCleared, createInfo.clearValue) {} true, createInfo.name, createInfo.sourceData.data == nullptr, createInfo.clearValue) {}
ShaderBuffer::~ShaderBuffer() {} ShaderBuffer::~ShaderBuffer() {}
+2
View File
@@ -63,6 +63,7 @@ class RenderCommand : public Gfx::RenderCommand {
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override; virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override; virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
virtual void drawIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride);
virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) override; virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) override;
virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override; virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override;
virtual void drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) override; virtual void drawMeshIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) override;
@@ -86,6 +87,7 @@ class ComputeCommand : public Gfx::ComputeCommand {
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override; virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override; virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
virtual void dispatchIndirect(Gfx::PShaderBuffer buffer, uint32 offset) override;
private: private:
PComputePipeline boundPipeline; PComputePipeline boundPipeline;
+8 -1
View File
@@ -127,11 +127,14 @@ void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVe
encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex, vertexCount, instanceCount, firstInstance); encoder->drawPrimitives(boundPipeline->getPrimitive(), firstVertex, vertexCount, instanceCount, firstInstance);
} }
void RenderCommand::drawIndirect(Gfx::PShaderBuffer buffer, uint64 offset, uint32 drawCount, uint32 stride) {
encoder->drawPrimitives(MTL::PrimitiveTypeTriangle, buffer.cast<ShaderBuffer>()->getHandle(), offset);
}
void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) { void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) {
encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount, cast(boundIndexBuffer->getIndexType()), encoder->drawIndexedPrimitives(boundPipeline->getPrimitive(), indexCount, cast(boundIndexBuffer->getIndexType()),
boundIndexBuffer->getHandle(), firstIndex, instanceCount, vertexOffset, firstInstance); boundIndexBuffer->getHandle(), firstIndex, instanceCount, vertexOffset, firstInstance);
} }
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) { void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1)); encoder->drawMeshThreadgroups(MTL::Size(groupX, groupY, groupZ), MTL::Size(128, 1, 1), MTL::Size(32, 1, 1));
} }
@@ -184,6 +187,10 @@ void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1)); encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
} }
void ComputeCommand::dispatchIndirect(Gfx::PShaderBuffer buffer, uint32 offset){
encoder->dispatchThreadgroups(buffer.cast<ShaderBuffer>()->getHandle(), offset, MTL::Size(32, 32, 1));
}
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) { CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
queue = graphics->getDevice()->newCommandQueue(); queue = graphics->getDevice()->newCommandQueue();
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init(); MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
+16 -11
View File
@@ -19,10 +19,15 @@ class DescriptorLayout : public Gfx::DescriptorLayout {
virtual ~DescriptorLayout(); virtual ~DescriptorLayout();
virtual void create() override; virtual void create() override;
MTL::ArgumentEncoder* createEncoder(); MTL::ArgumentEncoder* createEncoder();
uint32 getFlattenedIndex(uint32 binding, uint32 arrayIndex) const { return flattenMap.at(flattenIndex(binding, arrayIndex)); }
constexpr uint32 getTotalBindingCount() const { return flattenedBindingCount; }
private: private:
constexpr uint64 flattenIndex(uint32 binding, uint32 arrayIndex) const { return uint64(arrayIndex) << 32 | binding; }
PGraphics graphics; PGraphics graphics;
NS::Array* arguments; NS::Array* arguments;
Map<uint64, uint32> flattenMap;
uint32 flattenedBindingCount = 0;
}; };
DEFINE_REF(DescriptorLayout) DEFINE_REF(DescriptorLayout)
@@ -41,21 +46,21 @@ class DescriptorPool : public Gfx::DescriptorPool {
Array<ODescriptorSet> allocatedSets; Array<ODescriptorSet> allocatedSets;
}; };
DEFINE_REF(DescriptorPool) DEFINE_REF(DescriptorPool)
class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource { class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
public: public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner); DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet(); virtual ~DescriptorSet();
virtual void writeChanges() override; virtual void writeChanges() override;
virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override; virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer uniformBuffer) override;
virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override; virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer uniformBuffer) override;
virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override; virtual void updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) override;
virtual void updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) override; virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) override;
virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override; virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) override;
virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override; virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) override;
virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) override;
constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; } constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; }
MTL::Buffer* getArgumentBuffer() const { return argumentBuffer; } MTL::Buffer* getArgumentBuffer() const { return argumentBuffer; }
+53 -24
View File
@@ -32,9 +32,10 @@ void DescriptorLayout::create() {
pool = new DescriptorPool(graphics, this); pool = new DescriptorPool(graphics, this);
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32()); hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32());
MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()]; MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()];
flattenedBindingCount = 0;
for (uint32 i = 0; i < descriptorBindings.size(); ++i) { for (uint32 i = 0; i < descriptorBindings.size(); ++i) {
objects[i] = MTL::ArgumentDescriptor::alloc()->init(); objects[i] = MTL::ArgumentDescriptor::alloc()->init();
objects[i]->setIndex(i); objects[i]->setIndex(flattenedBindingCount);
objects[i]->setAccess(cast(descriptorBindings[i].access)); objects[i]->setAccess(cast(descriptorBindings[i].access));
objects[i]->setArrayLength(descriptorBindings[i].descriptorCount); objects[i]->setArrayLength(descriptorBindings[i].descriptorCount);
MTL::DataType dataType; MTL::DataType dataType;
@@ -47,13 +48,16 @@ void DescriptorLayout::create() {
case Gfx::SE_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: case Gfx::SE_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
dataType = MTL::DataTypeTexture; dataType = MTL::DataTypeTexture;
break; break;
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_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_STORAGE_BUFFER_DYNAMIC:
case Gfx::SE_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK:
dataType = MTL::DataTypePointer; dataType = MTL::DataTypePointer;
break; 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: case Gfx::SE_DESCRIPTOR_TYPE_SAMPLER:
dataType = MTL::DataTypeSampler; dataType = MTL::DataTypeSampler;
break; break;
@@ -89,6 +93,9 @@ void DescriptorLayout::create() {
break; break;
} }
objects[i]->setTextureType(textureType); 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()); 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) { : Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) {
encoder = owner->getLayout()->createEncoder(); encoder = owner->getLayout()->createEncoder();
argumentBuffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), 0); argumentBuffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), 0);
std::cout << owner->getLayout()->getName() << ": " << encoder->encodedLength() << std::endl;
encoder->setArgumentBuffer(argumentBuffer, 0); encoder->setArgumentBuffer(argumentBuffer, 0);
boundResources.resize(owner->getLayout()->getBindings().size()); boundResources.resize(owner->getLayout()->getTotalBindingCount());
} }
DescriptorSet::~DescriptorSet() {} DescriptorSet::~DescriptorSet() {}
void DescriptorSet::writeChanges() {} 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>(); PUniformBuffer buffer = uniformBuffer.cast<UniformBuffer>();
encoder->setBuffer(buffer->getHandle(), 0, binding); std::memcpy(encoder->constantData(flattenedIndex), buffer->getContents(), buffer->getSize());
boundResources[binding] = buffer->getHandle(); 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>(); PShaderBuffer buffer = uniformBuffer.cast<ShaderBuffer>();
encoder->setBuffer(buffer->getHandle(), 0, binding); encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex);
boundResources[binding] = buffer->getHandle(); 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>(); PIndexBuffer buffer = uniformBuffer.cast<IndexBuffer>();
encoder->setBuffer(buffer->getHandle(), 0, binding); encoder->setBuffer(buffer->getHandle(), 0, flattenedIndex);
boundResources[binding] = buffer->getHandle(); 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>(); PSampler sampler = samplerState.cast<Sampler>();
encoder->setSamplerState(sampler->getHandle(), binding); encoder->setSamplerState(sampler->getHandle(), flattenedIndex);
boundResources[binding] = nullptr; // Samplers are not resources?????? boundResources[flattenedIndex] = nullptr; // Samplers are not resources??????
} }
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) { void DescriptorSet::updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) {
PTextureBase base = texture.cast<TextureBase>(); uint32 flattenedIndex = owner->getLayout()->getFlattenedIndex(binding, index);
encoder->setTexture(base->getHandle()->texture, binding); PTextureBase tex = texture.cast<TextureBase>();
boundResources[binding] = base->getHandle()->texture; 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) PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {} : Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
+5
View File
@@ -58,8 +58,13 @@ class Graphics : public Gfx::Graphics {
virtual Gfx::OPipelineStatisticsQuery createPipelineStatisticsQuery(const std::string& name = "") override; virtual Gfx::OPipelineStatisticsQuery createPipelineStatisticsQuery(const std::string& name = "") override;
virtual Gfx::OTimestampQuery createTimestampQuery(uint64 numTimestamps, const std::string& name = "") override; virtual Gfx::OTimestampQuery createTimestampQuery(uint64 numTimestamps, const std::string& name = "") override;
virtual void beginDebugRegion(const std::string& name) override;
virtual void endDebugRegion() override;
virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override; virtual void resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) override;
virtual void copyTexture(Gfx::PTexture src, Gfx::PTexture dst) override; virtual void copyTexture(Gfx::PTexture src, Gfx::PTexture dst) override;
virtual void copyBuffer(Gfx::PShaderBuffer src, Gfx::PShaderBuffer dst) override;
// Ray Tracing // Ray Tracing
virtual Gfx::OBottomLevelAS createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) override; virtual Gfx::OBottomLevelAS createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) override;
+13
View File
@@ -143,10 +143,23 @@ Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const
return new TimestampQuery(this, name, numTimestamps); return new TimestampQuery(this, name, numTimestamps);
} }
void Graphics::beginDebugRegion(const std::string& name) {
queue->getCommands()->getHandle()->pushDebugGroup(NS::String::string(name.c_str(), NS::ASCIIStringEncoding));
}
void Graphics::endDebugRegion() {
queue->getCommands()->getHandle()->popDebugGroup();
}
void Graphics::resolveTexture(Gfx::PTexture, Gfx::PTexture) {} void Graphics::resolveTexture(Gfx::PTexture, Gfx::PTexture) {}
void Graphics::copyTexture(Gfx::PTexture, Gfx::PTexture) {} void Graphics::copyTexture(Gfx::PTexture, Gfx::PTexture) {}
void Graphics::copyBuffer(Gfx::PShaderBuffer src, Gfx::PShaderBuffer dst)
{
// TODO blit commands
}
// Ray Tracing // Ray Tracing
Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; } Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; }
+5 -4
View File
@@ -99,7 +99,7 @@ void BasePass::beginFrame(const Component::Camera& cam) {
transparentCulling = lightCullingLayout->allocateDescriptorSet(); transparentCulling = lightCullingLayout->allocateDescriptorSet();
//waterRenderer->beginFrame(); //waterRenderer->beginFrame();
terrainRenderer->beginFrame(viewParamsSet, cam); //terrainRenderer->beginFrame(viewParamsSet, cam);
// Debug vertices // Debug vertices
{ {
@@ -249,7 +249,7 @@ void BasePass::render() {
} }
//commands.add(waterRenderer->render(viewParamsSet)); //commands.add(waterRenderer->render(viewParamsSet));
commands.add(terrainRenderer->render(viewParamsSet)); //commands.add(terrainRenderer->render(viewParamsSet));
// Skybox // Skybox
{ {
@@ -432,7 +432,7 @@ void BasePass::publishOutputs() {
void BasePass::createRenderPass() { void BasePass::createRenderPass() {
RenderPass::beginFrame(Component::Camera()); RenderPass::beginFrame(Component::Camera());
terrainRenderer = new TerrainRenderer(graphics, scene, viewParamsLayout, viewParamsSet); //terrainRenderer = new TerrainRenderer(graphics, scene, viewParamsLayout, viewParamsSet);
cullingBuffer = resources->requestBuffer("CULLINGBUFFER"); cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
timestamps = resources->requestTimestampQuery("TIMESTAMPS"); timestamps = resources->requestTimestampQuery("TIMESTAMPS");
@@ -475,7 +475,7 @@ void BasePass::createRenderPass() {
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID"); tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
//waterRenderer->setViewport(viewport, renderPass); //waterRenderer->setViewport(viewport, renderPass);
terrainRenderer->setViewport(viewport, renderPass); //terrainRenderer->setViewport(viewport, renderPass);
// Debug rendering // Debug rendering
{ {
@@ -552,6 +552,7 @@ void BasePass::createRenderPass() {
skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{ skyboxDataLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(SkyboxData)
}); });
skyboxDataLayout->create(); skyboxDataLayout->create();
textureLayout = graphics->createDescriptorLayout("pSkyboxTextures"); textureLayout = graphics->createDescriptorLayout("pSkyboxTextures");
@@ -105,9 +105,11 @@ void CachedDepthPass::render() {
command->bindPipeline(pipeline); command->bindPipeline(pipeline);
} }
command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet()}); command->bindDescriptor({viewParamsSet, vertexData->getVertexDataSet(), vertexData->getInstanceDataSet()});
uint32 offset = 0; VertexData::DrawCallOffsets offsets = {
.instanceOffset = 0,
};
command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets), command->pushConstants(Gfx::SE_SHADER_STAGE_TASK_BIT_EXT | Gfx::SE_SHADER_STAGE_VERTEX_BIT, 0, sizeof(VertexData::DrawCallOffsets),
&offset); &offsets);
if (graphics->supportMeshShading()) { if (graphics->supportMeshShading()) {
command->drawMesh(vertexData->getNumInstances(), 1, 1); command->drawMesh(vertexData->getNumInstances(), 1, 1);
} else { } else {
@@ -248,6 +248,7 @@ void LightCullingPass::setupFrustums() {
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(DispatchParams),
}); });
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .binding = 1,
@@ -7,6 +7,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene) : graphics(graphic
viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{ viewParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(ViewParameter),
}); });
UniformBufferCreateInfo uniformInitializer = { UniformBufferCreateInfo uniformInitializer = {
.sourceData = .sourceData =
@@ -129,4 +130,4 @@ void RenderPass::extract_planes_from_view_projection_matrix(const Matrix4 viewPr
// Normalize all the planes // Normalize all the planes
for (uint32_t planeIdx = 0; planeIdx < 4; ++planeIdx) for (uint32_t planeIdx = 0; planeIdx < 4; ++planeIdx)
normalize_plane(frustum.planes[planeIdx]); normalize_plane(frustum.planes[planeIdx]);
} }
@@ -105,6 +105,7 @@ void TextPass::createRenderPass() {
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{ generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(Matrix4),
}); });
generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{ generalLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .binding = 1,
@@ -99,6 +99,7 @@ void UIPass::createRenderPass() {
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(Matrix4),
}); });
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .binding = 1,
@@ -107,6 +108,7 @@ void UIPass::createRenderPass() {
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2, .binding = 2,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(uint32)
}); });
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{ descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 3, .binding = 3,
@@ -124,6 +124,7 @@ WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescri
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{ computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(MaterialParams),
}); });
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{ computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .binding = 1,
+4 -4
View File
@@ -67,7 +67,7 @@ void ShaderCompiler::compile() {
layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout()); layout->addDescriptorLayout(vd->getInstanceDataLayout());
permutation.setMaterial(mat->getName()); permutation.setMaterial(mat->getName());
createShaders(permutation, std::move(layout)); createShaders(permutation, std::move(layout), name);
}); });
} }
} }
@@ -82,7 +82,7 @@ void ShaderCompiler::compile() {
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout); OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
layout->addDescriptorLayout(vd->getVertexDataLayout()); layout->addDescriptorLayout(vd->getVertexDataLayout());
layout->addDescriptorLayout(vd->getInstanceDataLayout()); layout->addDescriptorLayout(vd->getInstanceDataLayout());
createShaders(permutation, std::move(layout)); createShaders(permutation, std::move(layout), name);
}); });
} }
} }
@@ -92,7 +92,7 @@ void ShaderCompiler::compile() {
getThreadPool().runAndWait(std::move(work)); getThreadPool().runAndWait(std::move(work));
} }
void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout) { void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout, std::string debugName) {
PermutationId perm = PermutationId(permutation); PermutationId perm = PermutationId(permutation);
{ {
std::scoped_lock lock(shadersLock); std::scoped_lock lock(shadersLock);
@@ -103,7 +103,7 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
collection.pipelineLayout = std::move(layout); collection.pipelineLayout = std::move(layout);
ShaderCompilationInfo createInfo; ShaderCompilationInfo createInfo;
createInfo.name = fmt::format("Material {0}", permutation.materialName); createInfo.name = fmt::format("{0} Material {1}", debugName, permutation.materialName);
createInfo.rootSignature = collection.pipelineLayout; createInfo.rootSignature = collection.pipelineLayout;
if (std::strlen(permutation.materialName) > 0) { if (std::strlen(permutation.materialName) > 0) {
createInfo.modules.add(permutation.materialName); createInfo.modules.add(permutation.materialName);
+1 -1
View File
@@ -184,7 +184,7 @@ class ShaderCompiler {
private: private:
void compile(); void compile();
void createShaders(ShaderPermutation permutation, OPipelineLayout layout); void createShaders(ShaderPermutation permutation, OPipelineLayout layout, std::string debugName);
std::mutex shadersLock; std::mutex shadersLock;
Map<PermutationId, ShaderCollection> shaders; Map<PermutationId, ShaderCollection> shaders;
Map<std::string, PMaterial> materials; Map<std::string, PMaterial> materials;
+2 -2
View File
@@ -138,11 +138,11 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef()); slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
CHECK_DIAGNOSTICS(); CHECK_DIAGNOSTICS();
// std::cout << info.name << std::endl; std::cout << info.name << std::endl;
for (size_t i = 0; i < signature->getParameterCount(); ++i) { for (size_t i = 0; i < signature->getParameterCount(); ++i) {
auto param = signature->getParameterByIndex(i); auto param = signature->getParameterByIndex(i);
layout->addMapping(param->getName(), param->getBindingIndex()); layout->addMapping(param->getName(), param->getBindingIndex());
// std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl; std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl;
} }
// workaround // workaround
+1
View File
@@ -8,6 +8,7 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) : graphics(graphics)
layout->addDescriptorBinding(Gfx::DescriptorBinding{ layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0, .binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.uniformLength = sizeof(LightEnv)
}); });
layout->addDescriptorBinding(Gfx::DescriptorBinding{ layout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1, .binding = 1,
+2 -2
View File
@@ -7,7 +7,7 @@
namespace Seele { namespace Seele {
class ThreadPool { class ThreadPool {
public: public:
ThreadPool(uint32 numWorkers = std::thread::hardware_concurrency() - 2); ThreadPool(uint32 numWorkers = 1);
~ThreadPool(); ~ThreadPool();
void runAndWait(List<std::function<void()>> functions); void runAndWait(List<std::function<void()>> functions);
void runAsync(std::function<void()> func); void runAsync(std::function<void()> func);
@@ -36,4 +36,4 @@ class ThreadPool {
bool running = true; bool running = true;
}; };
ThreadPool& getThreadPool(); ThreadPool& getThreadPool();
} // namespace Seele } // namespace Seele