it at least does something
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "Graphics/Metal/Resources.h"
|
||||
#include "Metal/MTLAccelerationStructure.hpp"
|
||||
#include "Metal/MTLArgumentEncoder.hpp"
|
||||
#include "Metal/MTLCommandEncoder.hpp"
|
||||
#include "Metal/MTLLibrary.hpp"
|
||||
#include "Metal/MTLResource.hpp"
|
||||
#include "MinimalEngine.h"
|
||||
@@ -15,25 +16,30 @@
|
||||
namespace Seele {
|
||||
namespace Metal {
|
||||
DECLARE_REF(Graphics)
|
||||
struct DescriptorMapping
|
||||
{
|
||||
uint32 index;
|
||||
uint32 constantSize;
|
||||
MTL::ResourceUsage access;
|
||||
};
|
||||
class DescriptorLayout : public Gfx::DescriptorLayout {
|
||||
public:
|
||||
DescriptorLayout(PGraphics graphics, const std::string& name);
|
||||
virtual ~DescriptorLayout();
|
||||
virtual void create() override;
|
||||
MTL::ArgumentEncoder* createEncoder();
|
||||
uint32 getFlattenedIndex(uint32 binding, uint32 arrayIndex) const { return flattenMap.at(flattenIndex(binding, arrayIndex)); }
|
||||
constexpr uint32 getTotalBindingCount() const { return flattenedBindingCount; }
|
||||
constexpr bool isPlainDescriptor() const { return plainDescriptor; }
|
||||
|
||||
private:
|
||||
constexpr uint64 flattenIndex(uint32 binding, uint32 arrayIndex) const { return uint64(arrayIndex) << 32 | binding; }
|
||||
PGraphics graphics;
|
||||
NS::Array* arguments;
|
||||
Map<uint64, uint32> flattenMap;
|
||||
uint32 flattenedBindingCount = 0;
|
||||
Map<std::string, DescriptorMapping> variableMapping;
|
||||
uint32 numResources;
|
||||
// descriptor sets containing only uniform data are not actually argument buffers, so they need to be
|
||||
// handled separately
|
||||
bool plainDescriptor = true;
|
||||
friend class DescriptorSet;
|
||||
};
|
||||
DEFINE_REF(DescriptorLayout)
|
||||
|
||||
@@ -56,25 +62,24 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
|
||||
public:
|
||||
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
|
||||
virtual ~DescriptorSet();
|
||||
virtual void reset();
|
||||
virtual void writeChanges() override;
|
||||
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PUniformBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PVertexBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PIndexBuffer uniformBuffer) override;
|
||||
virtual void updateSampler(uint32 binding, uint32 index, Gfx::PSampler samplerState) override;
|
||||
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture2D texture) override;
|
||||
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTexture3D texture) override;
|
||||
virtual void updateTexture(uint32 binding, uint32 index, Gfx::PTextureCube texture) override;
|
||||
virtual void updateAccelerationStructure(uint32 binding, uint32 index, Gfx::PTopLevelAS as) override;
|
||||
virtual void updateConstants(const std::string& name, uint32 offset, void* data) override;
|
||||
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PVertexBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(const std::string& name, uint32 index, Gfx::PIndexBuffer uniformBuffer) override;
|
||||
virtual void updateSampler(const std::string& name, uint32 index, Gfx::PSampler samplerState) override;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture2D texture) override;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTexture3D texture) override;
|
||||
virtual void updateTexture(const std::string& name, uint32 index, Gfx::PTextureCube texture) override;
|
||||
virtual void updateAccelerationStructure(const std::string& name, uint32 index, Gfx::PTopLevelAS as) override;
|
||||
|
||||
constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; }
|
||||
constexpr bool isPlainDescriptor() const { return owner->getLayout()->isPlainDescriptor(); }
|
||||
constexpr MTL::ArgumentEncoder* createEncoder() const { return owner->getLayout()->createEncoder(); }
|
||||
|
||||
private:
|
||||
PGraphics graphics;
|
||||
PDescriptorPool owner;
|
||||
Array<MTL::Resource*> boundResources;
|
||||
MTL::Buffer* argumentBuffer = nullptr;
|
||||
MTL::ArgumentEncoder* encoder = nullptr;
|
||||
|
||||
@@ -88,13 +93,15 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
|
||||
struct BufferWriteInfo
|
||||
{
|
||||
uint32 index;
|
||||
MTL::ResourceUsage access;
|
||||
MTL::Buffer* buffer;
|
||||
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setBuffer(buffer, 0, 2); }
|
||||
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setBuffer(buffer, 0, index); }
|
||||
};
|
||||
Array<BufferWriteInfo> bufferWrites;
|
||||
struct TextureWriteInfo
|
||||
{
|
||||
uint32 index;
|
||||
MTL::ResourceUsage access;
|
||||
MTL::Texture* texture;
|
||||
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setTexture(texture, index); }
|
||||
};
|
||||
@@ -109,6 +116,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
|
||||
struct AccelerationStructureWriteInfo
|
||||
{
|
||||
uint32 index;
|
||||
MTL::ResourceUsage access;
|
||||
MTL::AccelerationStructure* accelerationStructure;
|
||||
void apply(MTL::ArgumentEncoder* encoder) const { encoder->setAccelerationStructure(accelerationStructure, index); }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user