this sucks, but there is hope
This commit is contained in:
Executable
BIN
Binary file not shown.
@@ -52,7 +52,7 @@ void taskMain(
|
|||||||
uint index;
|
uint index;
|
||||||
InterlockedAdd(head, 1, index);
|
InterlockedAdd(head, 1, index);
|
||||||
p.meshletId[index] = m;
|
p.meshletId[index] = m;
|
||||||
p.instanceId[index] = groupID;
|
p.instanceId[index] = groupID + pScene.primitiveIndices[m];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,9 +90,9 @@ void meshMain(
|
|||||||
{
|
{
|
||||||
uint p = min(i, m.primitiveCount - 1);
|
uint p = min(i, m.primitiveCount - 1);
|
||||||
{
|
{
|
||||||
uint local_idx0 = unpackPrimitiveIndices(m.primitiveOffset + (p * 3) + 0);
|
uint local_idx0 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 0];
|
||||||
uint local_idx1 = unpackPrimitiveIndices(m.primitiveOffset + (p * 3) + 1);
|
uint local_idx1 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 1];
|
||||||
uint local_idx2 = unpackPrimitiveIndices(m.primitiveOffset + (p * 3) + 2);
|
uint local_idx2 = pScene.primitiveIndices[m.primitiveOffset + (p * 3) + 2];
|
||||||
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
|
indices[p] = uint3(local_idx0, local_idx1, local_idx2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,5 @@ struct Scene
|
|||||||
StructuredBuffer<uint32_t> primitiveIndices;
|
StructuredBuffer<uint32_t> primitiveIndices;
|
||||||
StructuredBuffer<uint32_t> vertexIndices;
|
StructuredBuffer<uint32_t> vertexIndices;
|
||||||
};
|
};
|
||||||
layout(set=2)
|
|
||||||
ParameterBlock<Scene> pScene;
|
ParameterBlock<Scene> pScene;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
{
|
||||||
|
"EntryPoint": "taskMain",
|
||||||
|
"FunctionConstants": [],
|
||||||
|
"NeedsFunctionConstants": false,
|
||||||
|
"Resources": [
|
||||||
|
{
|
||||||
|
"abIndex": 0,
|
||||||
|
"slot": 0,
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"abIndex": 1,
|
||||||
|
"slot": 1,
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"abIndex": 2,
|
||||||
|
"slot": 2,
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"abIndex": 3,
|
||||||
|
"slot": 3,
|
||||||
|
"type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"abIndex": 4,
|
||||||
|
"slot": 0,
|
||||||
|
"type": "CBV"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"ShaderID": "2266638404583382645",
|
||||||
|
"ShaderType": "Amplification",
|
||||||
|
"TopLevelArgumentBuffer": [
|
||||||
|
{
|
||||||
|
"EltOffset": 0,
|
||||||
|
"Size": 24,
|
||||||
|
"Slot": 0,
|
||||||
|
"Space": 2,
|
||||||
|
"Type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"EltOffset": 24,
|
||||||
|
"Size": 24,
|
||||||
|
"Slot": 1,
|
||||||
|
"Space": 2,
|
||||||
|
"Type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"EltOffset": 48,
|
||||||
|
"Size": 24,
|
||||||
|
"Slot": 2,
|
||||||
|
"Space": 2,
|
||||||
|
"Type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"EltOffset": 72,
|
||||||
|
"Size": 24,
|
||||||
|
"Slot": 3,
|
||||||
|
"Space": 2,
|
||||||
|
"Type": "SRV"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"EltOffset": 96,
|
||||||
|
"Size": 24,
|
||||||
|
"Slot": 0,
|
||||||
|
"Space": 1,
|
||||||
|
"Type": "CBV"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"max_payload_size_in_bytes": 4096,
|
||||||
|
"num_threads": [
|
||||||
|
128,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
]
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -43,9 +43,9 @@ DescriptorSet::DescriptorSet(PDescriptorLayout layout) : layout(layout) {}
|
|||||||
|
|
||||||
DescriptorSet::~DescriptorSet() {}
|
DescriptorSet::~DescriptorSet() {}
|
||||||
|
|
||||||
PipelineLayout::PipelineLayout() {}
|
PipelineLayout::PipelineLayout(const std::string& name) : name(name) {}
|
||||||
|
|
||||||
PipelineLayout::PipelineLayout(PPipelineLayout baseLayout) {
|
PipelineLayout::PipelineLayout(const std::string& name, PPipelineLayout baseLayout) : name(name){
|
||||||
if (baseLayout != nullptr) {
|
if (baseLayout != nullptr) {
|
||||||
descriptorSetLayouts = baseLayout->descriptorSetLayouts;
|
descriptorSetLayouts = baseLayout->descriptorSetLayouts;
|
||||||
pushConstants = baseLayout->pushConstants;
|
pushConstants = baseLayout->pushConstants;
|
||||||
|
|||||||
@@ -75,8 +75,8 @@ DEFINE_REF(DescriptorSet)
|
|||||||
|
|
||||||
class PipelineLayout {
|
class PipelineLayout {
|
||||||
public:
|
public:
|
||||||
PipelineLayout();
|
PipelineLayout(const std::string& name);
|
||||||
PipelineLayout(PPipelineLayout baseLayout);
|
PipelineLayout(const std::string& name, PPipelineLayout baseLayout);
|
||||||
virtual ~PipelineLayout();
|
virtual ~PipelineLayout();
|
||||||
virtual void create() = 0;
|
virtual void create() = 0;
|
||||||
void addDescriptorLayout(PDescriptorLayout layout);
|
void addDescriptorLayout(PDescriptorLayout layout);
|
||||||
@@ -85,12 +85,14 @@ public:
|
|||||||
constexpr const Map<std::string, PDescriptorLayout>& getLayouts() const { return descriptorSetLayouts; }
|
constexpr const Map<std::string, PDescriptorLayout>& getLayouts() const { return descriptorSetLayouts; }
|
||||||
constexpr uint32 findParameter(const std::string& name) const { return parameterMapping[name]; }
|
constexpr uint32 findParameter(const std::string& name) const { return parameterMapping[name]; }
|
||||||
void addMapping(Map<std::string, uint32> mapping);
|
void addMapping(Map<std::string, uint32> mapping);
|
||||||
|
constexpr std::string getName() const {return name;};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32 layoutHash = 0;
|
uint32 layoutHash = 0;
|
||||||
Map<std::string, PDescriptorLayout> descriptorSetLayouts;
|
Map<std::string, PDescriptorLayout> descriptorSetLayouts;
|
||||||
Map<std::string, uint32> parameterMapping;
|
Map<std::string, uint32> parameterMapping;
|
||||||
Array<SePushConstantRange> pushConstants;
|
Array<SePushConstantRange> pushConstants;
|
||||||
|
std::string name;
|
||||||
};
|
};
|
||||||
DEFINE_REF(PipelineLayout)
|
DEFINE_REF(PipelineLayout)
|
||||||
} // namespace Gfx
|
} // namespace Gfx
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public:
|
|||||||
virtual OSampler createSampler(const SamplerCreateInfo& createInfo) = 0;
|
virtual OSampler createSampler(const SamplerCreateInfo& createInfo) = 0;
|
||||||
|
|
||||||
virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0;
|
virtual ODescriptorLayout createDescriptorLayout(const std::string& name = "") = 0;
|
||||||
virtual OPipelineLayout createPipelineLayout(PPipelineLayout baseLayout = nullptr) = 0;
|
virtual OPipelineLayout createPipelineLayout(const std::string& name = "", PPipelineLayout baseLayout = nullptr) = 0;
|
||||||
|
|
||||||
virtual OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) = 0;
|
virtual OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) = 0;
|
||||||
|
|
||||||
@@ -96,4 +96,4 @@ protected:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(Graphics)
|
DEFINE_REF(Graphics)
|
||||||
} // namespace Gfx
|
} // namespace Gfx
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -94,26 +94,26 @@ struct VertexBufferCreateInfo
|
|||||||
// bytes per vertex
|
// bytes per vertex
|
||||||
uint32 vertexSize = 0;
|
uint32 vertexSize = 0;
|
||||||
uint32 numVertices = 0;
|
uint32 numVertices = 0;
|
||||||
std::string name;
|
std::string name = "";
|
||||||
};
|
};
|
||||||
struct IndexBufferCreateInfo
|
struct IndexBufferCreateInfo
|
||||||
{
|
{
|
||||||
DataSource sourceData = DataSource();
|
DataSource sourceData = DataSource();
|
||||||
Gfx::SeIndexType indexType = Gfx::SeIndexType::SE_INDEX_TYPE_UINT16;
|
Gfx::SeIndexType indexType = Gfx::SeIndexType::SE_INDEX_TYPE_UINT16;
|
||||||
std::string name;
|
std::string name = "";
|
||||||
};
|
};
|
||||||
struct UniformBufferCreateInfo
|
struct UniformBufferCreateInfo
|
||||||
{
|
{
|
||||||
DataSource sourceData = DataSource();
|
DataSource sourceData = DataSource();
|
||||||
uint8 dynamic = 0;
|
uint8 dynamic = 0;
|
||||||
std::string name;
|
std::string name = "";
|
||||||
};
|
};
|
||||||
struct ShaderBufferCreateInfo
|
struct ShaderBufferCreateInfo
|
||||||
{
|
{
|
||||||
DataSource sourceData = DataSource();
|
DataSource sourceData = DataSource();
|
||||||
uint64 numElements = 1;
|
uint64 numElements = 1;
|
||||||
uint8 dynamic = 0;
|
uint8 dynamic = 0;
|
||||||
std::string name;
|
std::string name = "";
|
||||||
};
|
};
|
||||||
DECLARE_NAME_REF(Gfx, PipelineLayout)
|
DECLARE_NAME_REF(Gfx, PipelineLayout)
|
||||||
struct ShaderCreateInfo
|
struct ShaderCreateInfo
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Metal {
|
|||||||
DECLARE_REF(Graphics)
|
DECLARE_REF(Graphics)
|
||||||
class Buffer {
|
class Buffer {
|
||||||
public:
|
public:
|
||||||
Buffer(PGraphics graphics, uint64 size, void *data, bool dynamic);
|
Buffer(PGraphics graphics, uint64 size, void *data, bool dynamic, const std::string& name);
|
||||||
virtual ~Buffer();
|
virtual ~Buffer();
|
||||||
MTL::Buffer *getHandle() const { return buffers[currentBuffer]; }
|
MTL::Buffer *getHandle() const { return buffers[currentBuffer]; }
|
||||||
uint64 getSize() const { return size; }
|
uint64 getSize() const { return size; }
|
||||||
@@ -83,4 +83,4 @@ protected:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(ShaderBuffer)
|
DEFINE_REF(ShaderBuffer)
|
||||||
} // namespace Metal
|
} // namespace Metal
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -3,10 +3,12 @@
|
|||||||
#include "Graphics/Buffer.h"
|
#include "Graphics/Buffer.h"
|
||||||
#include "Graphics/Enums.h"
|
#include "Graphics/Enums.h"
|
||||||
#include "Graphics/Initializer.h"
|
#include "Graphics/Initializer.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Metal;
|
using namespace Seele::Metal;
|
||||||
|
|
||||||
Buffer::Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic) : graphics(graphics), size(size) {
|
Buffer::Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic, const std::string& name) : graphics(graphics), size(size) {
|
||||||
if (dynamic) {
|
if (dynamic) {
|
||||||
numBuffers = Gfx::numFramesBuffered;
|
numBuffers = Gfx::numFramesBuffered;
|
||||||
} else {
|
} else {
|
||||||
@@ -14,10 +16,11 @@ Buffer::Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic) : grap
|
|||||||
}
|
}
|
||||||
for (size_t i = 0; i < numBuffers; ++i) {
|
for (size_t i = 0; i < numBuffers; ++i) {
|
||||||
if (data != nullptr) {
|
if (data != nullptr) {
|
||||||
buffers[i] = graphics->getDevice()->newBuffer(data, size, MTL::ResourceOptionCPUCacheModeDefault);
|
buffers[i] = graphics->getDevice()->newBuffer(data, size, MTL::StorageModeShared);
|
||||||
} else {
|
} else {
|
||||||
buffers[i] = graphics->getDevice()->newBuffer(size, MTL::ResourceOptionCPUCacheModeDefault);
|
buffers[i] = graphics->getDevice()->newBuffer(size, MTL::StorageModeShared);
|
||||||
}
|
}
|
||||||
|
buffers[i]->setLabel(NS::String::string(name.c_str(), NS::ASCIIStringEncoding));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,12 +34,12 @@ void* Buffer::map(bool) { return getHandle()->contents(); }
|
|||||||
|
|
||||||
void* Buffer::mapRegion(uint64 regionOffset, uint64, bool) { return (char*)getHandle()->contents() + regionOffset; }
|
void* Buffer::mapRegion(uint64 regionOffset, uint64, bool) { return (char*)getHandle()->contents() + regionOffset; }
|
||||||
|
|
||||||
void unmap() {}
|
void Buffer::unmap() {}
|
||||||
|
|
||||||
VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo)
|
VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo)
|
||||||
: Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo.numVertices, createInfo.vertexSize,
|
: Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo.numVertices, createInfo.vertexSize,
|
||||||
createInfo.sourceData.owner),
|
createInfo.sourceData.owner),
|
||||||
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, false) {}
|
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, false, createInfo.name) {}
|
||||||
|
|
||||||
VertexBuffer::~VertexBuffer() {}
|
VertexBuffer::~VertexBuffer() {}
|
||||||
|
|
||||||
@@ -61,7 +64,7 @@ void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SeP
|
|||||||
IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo)
|
IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo)
|
||||||
: Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo.sourceData.size, createInfo.indexType,
|
: Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo.sourceData.size, createInfo.indexType,
|
||||||
createInfo.sourceData.owner),
|
createInfo.sourceData.owner),
|
||||||
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, false) {}
|
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, false, createInfo.name) {}
|
||||||
|
|
||||||
IndexBuffer::~IndexBuffer() {}
|
IndexBuffer::~IndexBuffer() {}
|
||||||
|
|
||||||
@@ -77,7 +80,7 @@ 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.sourceData),
|
: Gfx::UniformBuffer(graphics->getFamilyMapping(), createInfo.sourceData),
|
||||||
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, createInfo.dynamic) {}
|
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, createInfo.dynamic, createInfo.name) {}
|
||||||
|
|
||||||
UniformBuffer::~UniformBuffer() {}
|
UniformBuffer::~UniformBuffer() {}
|
||||||
|
|
||||||
@@ -94,7 +97,7 @@ void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::Se
|
|||||||
|
|
||||||
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo)
|
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo)
|
||||||
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo.numElements, createInfo.sourceData),
|
: Gfx::ShaderBuffer(graphics->getFamilyMapping(), createInfo.numElements, createInfo.sourceData),
|
||||||
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, createInfo.dynamic) {}
|
Seele::Metal::Buffer(graphics, createInfo.sourceData.size, createInfo.sourceData.data, createInfo.dynamic, createInfo.name) {}
|
||||||
|
|
||||||
ShaderBuffer::~ShaderBuffer() {}
|
ShaderBuffer::~ShaderBuffer() {}
|
||||||
|
|
||||||
@@ -108,4 +111,4 @@ void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwn
|
|||||||
|
|
||||||
|
|
||||||
void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
|
void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
|
||||||
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {}
|
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
#include "Resources.h"
|
#include "Resources.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Metal;
|
using namespace Seele::Metal;
|
||||||
@@ -74,14 +75,46 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) {
|
|||||||
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
|
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
|
||||||
boundPipeline = pipeline.cast<GraphicsPipeline>();
|
boundPipeline = pipeline.cast<GraphicsPipeline>();
|
||||||
encoder->setRenderPipelineState(boundPipeline->getHandle());
|
encoder->setRenderPipelineState(boundPipeline->getHandle());
|
||||||
|
uint64 argBufferSize = 0;
|
||||||
|
for (auto [_, layout] : boundPipeline->getPipelineLayout()->getLayouts()) {
|
||||||
|
argBufferSize += 3 * sizeof(uint64) * layout->getBindings().size();
|
||||||
|
}
|
||||||
|
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(argBufferSize, MTL::ResourceStorageModeShared);
|
||||||
|
argumentBuffer->setLabel(
|
||||||
|
NS::String::string(boundPipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
|
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
|
||||||
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName());
|
auto metalSet = descriptorSet.cast<DescriptorSet>();
|
||||||
encoder->setVertexBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName());
|
||||||
encoder->setFragmentBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
|
||||||
encoder->setMeshBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
|
||||||
encoder->setObjectBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
auto bindings = metalSet->getLayout()->getBindings();
|
||||||
|
encoder->useResource(metalSet->getBuffer(), MTL::ResourceUsageRead);
|
||||||
|
for (size_t i = 0; i < bindings.size(); ++i) {
|
||||||
|
auto binding = bindings[i];
|
||||||
|
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLER) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MTL::ResourceUsage usage;
|
||||||
|
switch (binding.access) {
|
||||||
|
case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT:
|
||||||
|
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE) {
|
||||||
|
usage = MTL::ResourceUsageSample;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
usage = MTL::ResourceUsageRead;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT:
|
||||||
|
usage = MTL::ResourceUsageRead | MTL::ResourceUsageWrite;
|
||||||
|
break;
|
||||||
|
case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT:
|
||||||
|
usage = MTL::ResourceUsageWrite;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
encoder->useResource(metalSet->getBoundResources()[i], usage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
|
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
|
||||||
@@ -122,6 +155,10 @@ void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 f
|
|||||||
|
|
||||||
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
|
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
|
||||||
// TODO:
|
// TODO:
|
||||||
|
std::cout << "Draw" << std::endl;
|
||||||
|
encoder->setFragmentBuffer(argumentBuffer, 0, 2);
|
||||||
|
encoder->setMeshBuffer(argumentBuffer, 0, 2);
|
||||||
|
encoder->setObjectBuffer(argumentBuffer, 0, 2);
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,46 +173,46 @@ void ComputeCommand::end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
|
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
|
||||||
boundPipeline = pipeline.cast<ComputePipeline>();
|
boundPipeline = pipeline.cast<ComputePipeline>();
|
||||||
encoder->setComputePipelineState(boundPipeline->getHandle());
|
encoder->setComputePipelineState(boundPipeline->getHandle());
|
||||||
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(sizeof(uint64) * boundPipeline->getPipelineLayout()->getLayouts().size(), MTL::ResourceOptionCPUCacheModeDefault);
|
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(
|
||||||
|
sizeof(uint64) * (boundPipeline->getPipelineLayout()->getLayouts().size() + 1), MTL::ResourceStorageModeShared);
|
||||||
|
argumentBuffer->setLabel(
|
||||||
|
NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
||||||
auto metalSet = set.cast<DescriptorSet>();
|
auto metalSet = set.cast<DescriptorSet>();
|
||||||
metalSet->bind();
|
metalSet->bind();
|
||||||
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName());
|
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName());
|
||||||
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
|
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
|
||||||
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
|
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
|
||||||
auto bindings =metalSet->getLayout()->getBindings();
|
auto bindings = metalSet->getLayout()->getBindings();
|
||||||
for(size_t i = 0; i < bindings.size(); ++i)
|
encoder->useResource(metalSet->getBuffer(), MTL::ResourceUsageRead);
|
||||||
{
|
for (size_t i = 0; i < bindings.size(); ++i) {
|
||||||
auto binding = bindings[i];
|
auto binding = bindings[i];
|
||||||
if(binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLER)
|
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLER) {
|
||||||
{
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
MTL::ResourceUsage usage;
|
|
||||||
switch(binding.access) {
|
|
||||||
case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT:
|
|
||||||
if(binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE)
|
|
||||||
{
|
|
||||||
usage = MTL::ResourceUsageSample;
|
|
||||||
break;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
usage = MTL::ResourceUsageRead;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT:
|
|
||||||
usage = MTL::ResourceUsageRead | MTL::ResourceUsageWrite;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT:
|
|
||||||
usage = MTL::ResourceUsageWrite;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
encoder->useResource(metalSet->getBoundResources()[i], usage);
|
|
||||||
}
|
}
|
||||||
|
MTL::ResourceUsage usage;
|
||||||
|
switch (binding.access) {
|
||||||
|
case Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT:
|
||||||
|
if (binding.descriptorType == Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE) {
|
||||||
|
usage = MTL::ResourceUsageSample;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
usage = MTL::ResourceUsageRead;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT:
|
||||||
|
usage = MTL::ResourceUsageRead | MTL::ResourceUsageWrite;
|
||||||
|
break;
|
||||||
|
case Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT:
|
||||||
|
usage = MTL::ResourceUsageWrite;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
encoder->useResource(metalSet->getBoundResources()[i], usage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
||||||
@@ -191,15 +228,15 @@ void ComputeCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags
|
|||||||
|
|
||||||
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
|
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
|
||||||
// TODO
|
// TODO
|
||||||
encoder->setBuffer(argumentBuffer, 0, 2);
|
encoder->setBuffer(argumentBuffer, 0, 2);
|
||||||
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
|
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), 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();
|
||||||
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
|
|
||||||
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
|
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
|
||||||
|
descriptor->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandQueue::~CommandQueue() { queue->release(); }
|
CommandQueue::~CommandQueue() { queue->release(); }
|
||||||
|
|||||||
@@ -13,11 +13,8 @@ public:
|
|||||||
virtual ~DescriptorLayout();
|
virtual ~DescriptorLayout();
|
||||||
virtual void create() override;
|
virtual void create() override;
|
||||||
|
|
||||||
NS::Array* getArguments() const { return arguments; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
NS::Array* arguments;
|
|
||||||
};
|
};
|
||||||
DEFINE_REF(DescriptorLayout)
|
DEFINE_REF(DescriptorLayout)
|
||||||
|
|
||||||
@@ -28,7 +25,6 @@ public:
|
|||||||
virtual ~DescriptorPool();
|
virtual ~DescriptorPool();
|
||||||
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
|
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
|
||||||
virtual void reset() override;
|
virtual void reset() override;
|
||||||
constexpr NS::Array* getArguments() const { return layout->getArguments(); }
|
|
||||||
constexpr PDescriptorLayout getLayout() const { return layout; }
|
constexpr PDescriptorLayout getLayout() const { return layout; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -63,7 +59,7 @@ private:
|
|||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
PDescriptorPool owner;
|
PDescriptorPool owner;
|
||||||
MTL::Buffer* buffer = nullptr;
|
MTL::Buffer* buffer = nullptr;
|
||||||
MTL::ArgumentEncoder* encoder;
|
uint64* argumentBuffer = nullptr;
|
||||||
Array<MTL::Resource*> boundResources;
|
Array<MTL::Resource*> boundResources;
|
||||||
uint32 bindCount;
|
uint32 bindCount;
|
||||||
bool currentlyInUse;
|
bool currentlyInUse;
|
||||||
@@ -72,10 +68,10 @@ DEFINE_REF(DescriptorSet)
|
|||||||
|
|
||||||
class PipelineLayout : public Gfx::PipelineLayout {
|
class PipelineLayout : public Gfx::PipelineLayout {
|
||||||
public:
|
public:
|
||||||
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout);
|
PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout);
|
||||||
virtual ~PipelineLayout();
|
virtual ~PipelineLayout();
|
||||||
virtual void create() override;
|
virtual void create() override;
|
||||||
|
Array<Array<uint32>>
|
||||||
private:
|
private:
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,74 +15,11 @@ using namespace Seele;
|
|||||||
using namespace Seele::Metal;
|
using namespace Seele::Metal;
|
||||||
|
|
||||||
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name)
|
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name)
|
||||||
: Gfx::DescriptorLayout(name), graphics(graphics), arguments(nullptr) {}
|
: Gfx::DescriptorLayout(name), graphics(graphics) {}
|
||||||
|
|
||||||
DescriptorLayout::~DescriptorLayout() {}
|
DescriptorLayout::~DescriptorLayout() {}
|
||||||
|
|
||||||
void DescriptorLayout::create() {
|
void DescriptorLayout::create() {
|
||||||
if (arguments != nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Array<NS::Object*> descriptors;
|
|
||||||
for (size_t i = 0; i < descriptorBindings.size(); ++i) {
|
|
||||||
const auto& binding = descriptorBindings[i];
|
|
||||||
auto desc = MTL::ArgumentDescriptor::alloc()->init();
|
|
||||||
desc->setAccess(cast(binding.access));
|
|
||||||
desc->setArrayLength(binding.descriptorCount);
|
|
||||||
MTL::DataType dataType;
|
|
||||||
switch (binding.descriptorType) {
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLER:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
|
||||||
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_EXT:
|
|
||||||
dataType = MTL::DataTypePointer;
|
|
||||||
break;
|
|
||||||
case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV:
|
|
||||||
dataType = MTL::DataTypePrimitiveAccelerationStructure;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw std::logic_error("Nooo");
|
|
||||||
}
|
|
||||||
desc->setDataType(dataType);
|
|
||||||
desc->setIndex(i);
|
|
||||||
if (dataType == MTL::DataTypeTexture) {
|
|
||||||
switch (binding.textureType) {
|
|
||||||
case Gfx::SE_IMAGE_VIEW_TYPE_1D:
|
|
||||||
desc->setTextureType(MTL::TextureType1D);
|
|
||||||
break;
|
|
||||||
case Gfx::SE_IMAGE_VIEW_TYPE_2D:
|
|
||||||
desc->setTextureType(MTL::TextureType2D);
|
|
||||||
break;
|
|
||||||
case Gfx::SE_IMAGE_VIEW_TYPE_3D:
|
|
||||||
desc->setTextureType(MTL::TextureType3D);
|
|
||||||
break;
|
|
||||||
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE:
|
|
||||||
desc->setTextureType(MTL::TextureTypeCube);
|
|
||||||
break;
|
|
||||||
case Gfx::SE_IMAGE_VIEW_TYPE_1D_ARRAY:
|
|
||||||
desc->setTextureType(MTL::TextureType1DArray);
|
|
||||||
break;
|
|
||||||
case Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY:
|
|
||||||
desc->setTextureType(MTL::TextureType2DArray);
|
|
||||||
break;
|
|
||||||
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE_ARRAY:
|
|
||||||
desc->setTextureType(MTL::TextureTypeCubeArray);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
descriptors.add(desc);
|
|
||||||
}
|
|
||||||
arguments = NS::Array::array(descriptors.data(), descriptors.size());
|
|
||||||
pool = new DescriptorPool(graphics, this);
|
pool = new DescriptorPool(graphics, this);
|
||||||
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(),
|
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(),
|
||||||
CRC::CRC_32());
|
CRC::CRC_32());
|
||||||
@@ -116,63 +53,72 @@ void DescriptorPool::reset() {
|
|||||||
|
|
||||||
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
||||||
: Gfx::DescriptorSet(owner->getLayout()), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) {
|
: Gfx::DescriptorSet(owner->getLayout()), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) {
|
||||||
if (owner->getArguments()->count() > 0) {
|
boundResources.resize(owner->getLayout()->getBindings().size());
|
||||||
boundResources.resize(owner->getArguments()->count());
|
buffer = graphics->getDevice()->newBuffer(std::max<size_t>(8, sizeof(uint64_t) * 3 * owner->getLayout()->getBindings().size()), MTL::ResourceStorageModeShared);
|
||||||
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
|
argumentBuffer = (uint64*)buffer->contents();
|
||||||
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
|
buffer->setLabel(NS::String::string(owner->getLayout()->getName().c_str(), NS::ASCIIStringEncoding));
|
||||||
encoder->setArgumentBuffer(buffer, 0);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
buffer = graphics->getDevice()->newBuffer(8, MTL::ResourceOptionCPUCacheModeDefault);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptorSet::~DescriptorSet() {}
|
DescriptorSet::~DescriptorSet() {buffer->release();}
|
||||||
|
|
||||||
void DescriptorSet::writeChanges() {}
|
void DescriptorSet::writeChanges() {}
|
||||||
|
|
||||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
|
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
|
||||||
PUniformBuffer metalBuffer = uniformBuffer.cast<UniformBuffer>();
|
PUniformBuffer metalBuffer = uniformBuffer.cast<UniformBuffer>();
|
||||||
encoder->setBuffer(metalBuffer->getHandle(), 0, binding);
|
uint64 offset = binding * 3;
|
||||||
|
argumentBuffer[offset + 0] = metalBuffer->getHandle()->gpuAddress();
|
||||||
|
argumentBuffer[offset + 1] = 0;
|
||||||
|
argumentBuffer[offset + 2] = (uint32)metalBuffer->getSize(); // TODO: buffer texture view, typed??
|
||||||
boundResources[binding] = metalBuffer->getHandle();
|
boundResources[binding] = metalBuffer->getHandle();
|
||||||
}
|
}
|
||||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) {
|
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) {
|
||||||
PShaderBuffer metalBuffer = uniformBuffer.cast<ShaderBuffer>();
|
PShaderBuffer metalBuffer = uniformBuffer.cast<ShaderBuffer>();
|
||||||
encoder->setBuffer(metalBuffer->getHandle(), 0, binding);
|
uint64 offset = binding * 3;
|
||||||
|
argumentBuffer[offset + 0] = metalBuffer->getHandle()->gpuAddress();
|
||||||
|
argumentBuffer[offset + 1] = 0;
|
||||||
|
argumentBuffer[offset + 2] = (uint32)metalBuffer->getSize(); // TODO: buffer texture view, typed??
|
||||||
boundResources[binding] = metalBuffer->getHandle();
|
boundResources[binding] = metalBuffer->getHandle();
|
||||||
}
|
}
|
||||||
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
|
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
|
||||||
PSampler sampler = samplerState.cast<Sampler>();
|
PSampler sampler = samplerState.cast<Sampler>();
|
||||||
encoder->setSamplerState(sampler->getHandle(), binding);
|
MTL::ResourceID resourceId =sampler->getHandle()->gpuResourceID();
|
||||||
|
uint64 offset = binding * 3;
|
||||||
|
argumentBuffer[offset + 0] = 0;
|
||||||
|
argumentBuffer[offset + 1] = *(uint64*)&resourceId;
|
||||||
|
argumentBuffer[offset + 2] = 0; // LOD bias
|
||||||
}
|
}
|
||||||
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
||||||
PTextureBase base = texture.cast<TextureBase>();
|
PTextureBase base = texture.cast<TextureBase>();
|
||||||
if(layout->getBindings()[binding].access == Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT)
|
if(layout->getBindings()[binding].access == Gfx::SE_DESCRIPTOR_ACCESS_READ_ONLY_BIT)
|
||||||
{
|
{
|
||||||
encoder->setTexture(base->getTexture(), binding);
|
MTL::ResourceID resourceId =base->getTexture()->gpuResourceID();
|
||||||
|
uint64 offset = binding * 3;
|
||||||
|
argumentBuffer[offset + 0] = 0;
|
||||||
|
argumentBuffer[offset + 1] = *(uint64*)&resourceId;
|
||||||
|
argumentBuffer[offset + 2] = 0; // min LOD clamp
|
||||||
}else{
|
}else{
|
||||||
encoder->setBuffer(base->getTexture()->buffer(), 0, binding);
|
uint64 offset = binding * 3;
|
||||||
|
argumentBuffer[offset + 0] = base->getTexture()->buffer()->gpuAddress();
|
||||||
|
argumentBuffer[offset + 1] = 0;
|
||||||
|
argumentBuffer[offset + 2] = (uint32)base->getTexture()->buffer()->length(); // TODO: buffer texture view, typed??
|
||||||
}
|
}
|
||||||
boundResources[binding] = base->getTexture();
|
boundResources[binding] = base->getTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
|
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
|
||||||
for (auto& t : array) {
|
for (auto& t : array) {
|
||||||
PTextureBase metalTexture = t.cast<TextureBase>();
|
updateTexture(binding++, t);
|
||||||
encoder->setTexture(metalTexture->getTexture(), binding);
|
|
||||||
boundResources[binding++] = metalTexture->getTexture();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
|
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
|
||||||
: Gfx::PipelineLayout(baseLayout), graphics(graphics) {}
|
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
|
||||||
|
|
||||||
PipelineLayout::~PipelineLayout() {}
|
PipelineLayout::~PipelineLayout() {}
|
||||||
|
|
||||||
void PipelineLayout::create() {
|
void PipelineLayout::create() {
|
||||||
for (auto& [_, set] : descriptorSetLayouts) {
|
for (auto& [_, set] : descriptorSetLayouts) {
|
||||||
set->create();
|
assert(set->getHash() != 0);
|
||||||
uint32 setHash = set->getHash();
|
uint32 setHash = set->getHash();
|
||||||
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
virtual Gfx::OSampler createSampler(const SamplerCreateInfo& createInfo) override;
|
virtual Gfx::OSampler createSampler(const SamplerCreateInfo& createInfo) override;
|
||||||
|
|
||||||
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
|
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
|
||||||
virtual Gfx::OPipelineLayout createPipelineLayout(Gfx::PPipelineLayout baseLayout = nullptr) override;
|
virtual Gfx::OPipelineLayout createPipelineLayout(const std::string& name = "", Gfx::PPipelineLayout baseLayout = nullptr) override;
|
||||||
|
|
||||||
virtual Gfx::OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) override;
|
virtual Gfx::OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) override;
|
||||||
|
|
||||||
|
|||||||
@@ -180,9 +180,9 @@ Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& name)
|
|||||||
return new DescriptorLayout(this, name);
|
return new DescriptorLayout(this, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OPipelineLayout Graphics::createPipelineLayout(Gfx::PPipelineLayout baseLayout)
|
Gfx::OPipelineLayout Graphics::createPipelineLayout(const std::string& name, Gfx::PPipelineLayout baseLayout)
|
||||||
{
|
{
|
||||||
return new PipelineLayout(this, baseLayout);
|
return new PipelineLayout(this, name, baseLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo)
|
Gfx::OVertexInput Graphics::createVertexInput(VertexInputStateCreateInfo createInfo)
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ public:
|
|||||||
virtual ~GraphicsPipeline();
|
virtual ~GraphicsPipeline();
|
||||||
constexpr MTL::RenderPipelineState* getHandle() const { return state; }
|
constexpr MTL::RenderPipelineState* getHandle() const { return state; }
|
||||||
constexpr MTL::PrimitiveType getPrimitive() const { return primitiveType; }
|
constexpr MTL::PrimitiveType getPrimitive() const { return primitiveType; }
|
||||||
private:
|
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
MTL::RenderPipelineState* state;
|
MTL::RenderPipelineState* state;
|
||||||
MTL::PrimitiveType primitiveType;
|
MTL::PrimitiveType primitiveType;
|
||||||
|
private:
|
||||||
};
|
};
|
||||||
DEFINE_REF(GraphicsPipeline)
|
DEFINE_REF(GraphicsPipeline)
|
||||||
class ComputePipeline : public Gfx::ComputePipeline {
|
class ComputePipeline : public Gfx::ComputePipeline {
|
||||||
|
|||||||
@@ -25,15 +25,15 @@ Shader::~Shader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shader::create(const ShaderCreateInfo& createInfo) {
|
void Shader::create(const ShaderCreateInfo& createInfo) {
|
||||||
std::cout << "Compiling " << createInfo.name << std::endl;
|
std::cout << "Compiling " << createInfo.name << std::endl;
|
||||||
Map<std::string, uint32> test;
|
Map<std::string, uint32> paramMapping;
|
||||||
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_DXIL, test);
|
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_DXIL, paramMapping);
|
||||||
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
|
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
|
||||||
IRCompiler* pCompiler = IRCompilerCreate();
|
IRCompiler* pCompiler = IRCompilerCreate();
|
||||||
IRCompilerSetMinimumGPUFamily(pCompiler, IRGPUFamilyMetal3);
|
IRCompilerSetMinimumGPUFamily(pCompiler, IRGPUFamilyMetal3);
|
||||||
IRCompilerIgnoreRootSignature(pCompiler, true);
|
IRCompilerIgnoreRootSignature(pCompiler, true);
|
||||||
IRCompilerSetEntryPointName(pCompiler, "main");
|
IRCompilerSetEntryPointName(pCompiler, "main");
|
||||||
IRCompilerSetValidationFlags(pCompiler, IRCompilerValidationFlagAll);
|
IRCompilerSetValidationFlags(pCompiler, IRCompilerValidationFlagAll);
|
||||||
|
|
||||||
IRObject* pDXIL = IRObjectCreateFromDXIL((const uint8*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(),
|
IRObject* pDXIL = IRObjectCreateFromDXIL((const uint8*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(),
|
||||||
IRBytecodeOwnershipNone);
|
IRBytecodeOwnershipNone);
|
||||||
@@ -100,8 +100,8 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
|
|||||||
descriptor.desc_1_1.pParameters = parameters.data();
|
descriptor.desc_1_1.pParameters = parameters.data();
|
||||||
IRRootSignature* rootSignature = IRRootSignatureCreateFromDescriptor(&descriptor, &signatureError);
|
IRRootSignature* rootSignature = IRRootSignatureCreateFromDescriptor(&descriptor, &signatureError);
|
||||||
assert(rootSignature);
|
assert(rootSignature);
|
||||||
IRCompilerSetGlobalRootSignature(pCompiler, rootSignature);
|
// IRCompilerSetGlobalRootSignature(pCompiler, rootSignature);
|
||||||
// Compile DXIL to Metal IR:
|
// Compile DXIL to Metal IR:
|
||||||
IRError* pError = nullptr;
|
IRError* pError = nullptr;
|
||||||
IRObject* pOutIR = IRCompilerAllocCompileAndLink(pCompiler, NULL, pDXIL, &pError);
|
IRObject* pOutIR = IRCompilerAllocCompileAndLink(pCompiler, NULL, pDXIL, &pError);
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
|
|||||||
IRMetalLibBinary* pMetallib = IRMetalLibBinaryCreate();
|
IRMetalLibBinary* pMetallib = IRMetalLibBinaryCreate();
|
||||||
IRObjectGetMetalLibBinary(pOutIR, irStage, pMetallib);
|
IRObjectGetMetalLibBinary(pOutIR, irStage, pMetallib);
|
||||||
dispatch_data_t data = IRMetalLibGetBytecodeData(pMetallib);
|
dispatch_data_t data = IRMetalLibGetBytecodeData(pMetallib);
|
||||||
|
|
||||||
IRShaderReflection* reflection = IRShaderReflectionCreate();
|
IRShaderReflection* reflection = IRShaderReflectionCreate();
|
||||||
IRObjectGetReflection(pOutIR, irStage, reflection);
|
IRObjectGetReflection(pOutIR, irStage, reflection);
|
||||||
std::cout << IRShaderReflectionAllocStringAndSerialize(reflection) << std::endl;
|
std::cout << IRShaderReflectionAllocStringAndSerialize(reflection) << std::endl;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
|
|||||||
ownsImage(existingImage == nullptr) {
|
ownsImage(existingImage == nullptr) {
|
||||||
if (existingImage == nullptr) {
|
if (existingImage == nullptr) {
|
||||||
MTL::TextureUsage mtlUsage = 0;
|
MTL::TextureUsage mtlUsage = 0;
|
||||||
if(usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
|
if(usage & Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT || usage & Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
||||||
{
|
{
|
||||||
mtlUsage |= MTL::TextureUsageRenderTarget;
|
mtlUsage |= MTL::TextureUsageRenderTarget;
|
||||||
}
|
}
|
||||||
@@ -29,6 +29,10 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
|
|||||||
{
|
{
|
||||||
mtlUsage |= MTL::TextureUsageShaderRead;
|
mtlUsage |= MTL::TextureUsageShaderRead;
|
||||||
}
|
}
|
||||||
|
if(usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT)
|
||||||
|
{
|
||||||
|
mtlUsage |= MTL::TextureUsageShaderWrite;
|
||||||
|
}
|
||||||
MTL::TextureDescriptor *descriptor =
|
MTL::TextureDescriptor *descriptor =
|
||||||
MTL::TextureDescriptor::alloc()->init();
|
MTL::TextureDescriptor::alloc()->init();
|
||||||
descriptor->setPixelFormat(cast(format));
|
descriptor->setPixelFormat(cast(format));
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ void BasePass::endFrame()
|
|||||||
|
|
||||||
void BasePass::publishOutputs()
|
void BasePass::publishOutputs()
|
||||||
{
|
{
|
||||||
basePassLayout = graphics->createPipelineLayout();
|
basePassLayout = graphics->createPipelineLayout("BasePassLayout");
|
||||||
|
|
||||||
basePassLayout->addDescriptorLayout(viewParamsLayout);
|
basePassLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
basePassLayout->addDescriptorLayout(scene->getLightEnvironment()->getDescriptorLayout());
|
basePassLayout->addDescriptorLayout(scene->getLightEnvironment()->getDescriptorLayout());
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ void DebugPass::createRenderPass()
|
|||||||
};
|
};
|
||||||
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
|
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
|
||||||
|
|
||||||
pipelineLayout = graphics->createPipelineLayout();
|
pipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
|
||||||
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
pipelineLayout->create();
|
pipelineLayout->create();
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
|||||||
: RenderPass(graphics, scene)
|
: RenderPass(graphics, scene)
|
||||||
, descriptorSets(3)
|
, descriptorSets(3)
|
||||||
{
|
{
|
||||||
depthPrepassLayout = graphics->createPipelineLayout();
|
depthPrepassLayout = graphics->createPipelineLayout("DepthPrepassLayout");
|
||||||
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
|
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
if (graphics->supportMeshShading())
|
if (graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -114,9 +114,11 @@ void LightCullingPass::publishOutputs()
|
|||||||
//t_lightGrid
|
//t_lightGrid
|
||||||
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
|
cullingDescriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 6, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE, .access = Gfx::SE_DESCRIPTOR_ACCESS_READ_WRITE_BIT});
|
||||||
|
|
||||||
|
cullingDescriptorLayout->create();
|
||||||
|
|
||||||
lightEnv = scene->getLightEnvironment();
|
lightEnv = scene->getLightEnvironment();
|
||||||
|
|
||||||
cullingLayout = graphics->createPipelineLayout();
|
cullingLayout = graphics->createPipelineLayout("CullingLayout");
|
||||||
cullingLayout->addDescriptorLayout(viewParamsLayout);
|
cullingLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
cullingLayout->addDescriptorLayout(dispatchParamsLayout);
|
cullingLayout->addDescriptorLayout(dispatchParamsLayout);
|
||||||
cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
|
cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
|
||||||
@@ -213,7 +215,8 @@ void LightCullingPass::setupFrustums()
|
|||||||
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
|
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
|
||||||
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, });
|
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 0, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER, });
|
||||||
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT });
|
dispatchParamsLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 1, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER, .access = Gfx::SE_DESCRIPTOR_ACCESS_WRITE_ONLY_BIT });
|
||||||
frustumLayout = graphics->createPipelineLayout();
|
dispatchParamsLayout->create();
|
||||||
|
frustumLayout = graphics->createPipelineLayout("FrustumLayout");
|
||||||
frustumLayout->addDescriptorLayout(viewParamsLayout);
|
frustumLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
|
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
|
||||||
Map<std::string, uint32> mapping;
|
Map<std::string, uint32> mapping;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene)
|
|||||||
.data = (uint8*)&viewParams,
|
.data = (uint8*)&viewParams,
|
||||||
},
|
},
|
||||||
.dynamic = true,
|
.dynamic = true,
|
||||||
|
.name = "viewParamsBuffer",
|
||||||
};
|
};
|
||||||
viewParamsBuffer = graphics->createUniformBuffer(uniformInitializer);
|
viewParamsBuffer = graphics->createUniformBuffer(uniformInitializer);
|
||||||
viewParamsLayout->create();
|
viewParamsLayout->create();
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ void SkyboxRenderPass::createRenderPass()
|
|||||||
createInfo.entryPoint = "fragmentMain";
|
createInfo.entryPoint = "fragmentMain";
|
||||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||||
|
|
||||||
pipelineLayout = graphics->createPipelineLayout();
|
pipelineLayout = graphics->createPipelineLayout("SkyboxLayout");
|
||||||
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
|
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
|
||||||
pipelineLayout->addDescriptorLayout(textureLayout);
|
pipelineLayout->addDescriptorLayout(textureLayout);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ void ShaderCompiler::compile()
|
|||||||
{
|
{
|
||||||
for (const auto& [matName, mat] : materials)
|
for (const auto& [matName, mat] : materials)
|
||||||
{
|
{
|
||||||
OPipelineLayout layout = graphics->createPipelineLayout(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());
|
||||||
layout->addDescriptorLayout(mat->getDescriptorLayout());
|
layout->addDescriptorLayout(mat->getDescriptorLayout());
|
||||||
@@ -95,7 +95,7 @@ void ShaderCompiler::compile()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OPipelineLayout layout = graphics->createPipelineLayout(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());
|
||||||
Map<std::string, uint32> mapping;
|
Map<std::string, uint32> mapping;
|
||||||
|
|||||||
@@ -162,13 +162,19 @@ void StaticMeshVertexData::resizeBuffers()
|
|||||||
},
|
},
|
||||||
.numElements = verticesAllocated * 3,
|
.numElements = verticesAllocated * 3,
|
||||||
.dynamic = true,
|
.dynamic = true,
|
||||||
|
.name = "Positions",
|
||||||
};
|
};
|
||||||
positions = graphics->createShaderBuffer(createInfo);
|
positions = graphics->createShaderBuffer(createInfo);
|
||||||
|
createInfo.name = "Normals";
|
||||||
normals = graphics->createShaderBuffer(createInfo);
|
normals = graphics->createShaderBuffer(createInfo);
|
||||||
|
createInfo.name = "Tangents";
|
||||||
tangents = graphics->createShaderBuffer(createInfo);
|
tangents = graphics->createShaderBuffer(createInfo);
|
||||||
|
createInfo.name = "BiTangents";
|
||||||
biTangents = graphics->createShaderBuffer(createInfo);
|
biTangents = graphics->createShaderBuffer(createInfo);
|
||||||
|
createInfo.name = "Colors";
|
||||||
colors = graphics->createShaderBuffer(createInfo);
|
colors = graphics->createShaderBuffer(createInfo);
|
||||||
createInfo.sourceData.size = verticesAllocated * sizeof(Vector2);
|
createInfo.sourceData.size = verticesAllocated * sizeof(Vector2);
|
||||||
|
createInfo.name = "TexCoords";
|
||||||
createInfo.numElements = verticesAllocated * 2;
|
createInfo.numElements = verticesAllocated * 2;
|
||||||
texCoords = graphics->createShaderBuffer(createInfo);
|
texCoords = graphics->createShaderBuffer(createInfo);
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ void VertexData::createDescriptors()
|
|||||||
},
|
},
|
||||||
.numElements = instanceData.size(),
|
.numElements = instanceData.size(),
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "InstanceBuffer"
|
||||||
});
|
});
|
||||||
matInst.instanceBuffer->pipelineBarrier(
|
matInst.instanceBuffer->pipelineBarrier(
|
||||||
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
||||||
@@ -124,6 +125,7 @@ void VertexData::createDescriptors()
|
|||||||
},
|
},
|
||||||
.numElements = meshes.size(),
|
.numElements = meshes.size(),
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "MeshDataBuffer"
|
||||||
});
|
});
|
||||||
matInst.meshDataBuffer->pipelineBarrier(
|
matInst.meshDataBuffer->pipelineBarrier(
|
||||||
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
|
||||||
@@ -162,7 +164,11 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
|||||||
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
|
std::memcpy(vertexIndices.data() + vertexOffset, m.uniqueVertices, m.numVertices * sizeof(uint32));
|
||||||
uint32 primitiveOffset = primitiveIndices.size();
|
uint32 primitiveOffset = primitiveIndices.size();
|
||||||
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
primitiveIndices.resize(primitiveOffset + (m.numPrimitives * 3));
|
||||||
std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
for(size_t x = 0; x < m.numPrimitives*3; ++x)
|
||||||
|
{
|
||||||
|
primitiveIndices[primitiveOffset + x] = m.primitiveLayout[x];
|
||||||
|
}
|
||||||
|
//std::memcpy(primitiveIndices.data() + primitiveOffset, m.primitiveLayout, m.numPrimitives * 3 * sizeof(uint8));
|
||||||
meshlets.add(MeshletDescription{
|
meshlets.add(MeshletDescription{
|
||||||
.bounding = m.boundingBox.toSphere(),
|
.bounding = m.boundingBox.toSphere(),
|
||||||
.vertexCount = m.numVertices,
|
.vertexCount = m.numVertices,
|
||||||
@@ -190,6 +196,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
|||||||
.data = (uint8*)indices.data(),
|
.data = (uint8*)indices.data(),
|
||||||
},
|
},
|
||||||
.indexType = Gfx::SE_INDEX_TYPE_UINT32,
|
.indexType = Gfx::SE_INDEX_TYPE_UINT32,
|
||||||
|
.name = "IndexBuffer",
|
||||||
});
|
});
|
||||||
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
meshletBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData = {
|
.sourceData = {
|
||||||
@@ -198,6 +205,7 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
|||||||
},
|
},
|
||||||
.numElements = meshlets.size(),
|
.numElements = meshlets.size(),
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "MeshletBuffer"
|
||||||
});
|
});
|
||||||
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
vertexIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData = {
|
.sourceData = {
|
||||||
@@ -206,14 +214,16 @@ void VertexData::loadMesh(MeshId id, Array<uint32> loadedIndices, Array<Meshlet>
|
|||||||
},
|
},
|
||||||
.numElements = vertexIndices.size(),
|
.numElements = vertexIndices.size(),
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "VertexIndicesBuffer"
|
||||||
});
|
});
|
||||||
primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
primitiveIndicesBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData = {
|
.sourceData = {
|
||||||
.size = sizeof(uint8) * primitiveIndices.size(),
|
.size = sizeof(uint32) * primitiveIndices.size(),
|
||||||
.data = (uint8*)primitiveIndices.data(),
|
.data = (uint8*)primitiveIndices.data(),
|
||||||
},
|
},
|
||||||
.numElements = primitiveIndices.size(),
|
.numElements = primitiveIndices.size(),
|
||||||
.dynamic = false,
|
.dynamic = false,
|
||||||
|
.name = "PrimitiveIndicesBuffer",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
virtual Gfx::OSampler createSampler(const SamplerCreateInfo& createInfo) override;
|
virtual Gfx::OSampler createSampler(const SamplerCreateInfo& createInfo) override;
|
||||||
|
|
||||||
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
|
virtual Gfx::ODescriptorLayout createDescriptorLayout(const std::string& name = "") override;
|
||||||
virtual Gfx::OPipelineLayout createPipelineLayout(Gfx::PPipelineLayout baseLayout = nullptr) override;
|
virtual Gfx::OPipelineLayout createPipelineLayout(const std::string& name = "", Gfx::PPipelineLayout baseLayout = nullptr) override;
|
||||||
|
|
||||||
virtual Gfx::OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) override;
|
virtual Gfx::OVertexInput createVertexInput(VertexInputStateCreateInfo createInfo) override;
|
||||||
|
|
||||||
@@ -109,4 +109,4 @@ protected:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(Graphics)
|
DEFINE_REF(Graphics)
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
|||||||
}
|
}
|
||||||
sessionDesc.preprocessorMacroCount = macros.size();
|
sessionDesc.preprocessorMacroCount = macros.size();
|
||||||
sessionDesc.preprocessorMacros = macros.data();
|
sessionDesc.preprocessorMacros = macros.data();
|
||||||
slang::TargetDesc vulkan;
|
slang::TargetDesc targetDesc;
|
||||||
vulkan.profile = globalSession->findProfile("sm_6_6");
|
targetDesc.profile = globalSession->findProfile("sm_6_6");
|
||||||
vulkan.format = target;
|
targetDesc.format = target;
|
||||||
sessionDesc.targetCount = 1;
|
sessionDesc.targetCount = 1;
|
||||||
sessionDesc.targets = &vulkan;
|
sessionDesc.targets = &targetDesc;
|
||||||
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
|
StaticArray<const char*, 3> searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"};
|
||||||
sessionDesc.searchPaths = searchPaths.data();
|
sessionDesc.searchPaths = searchPaths.data();
|
||||||
sessionDesc.searchPathCount = searchPaths.size();
|
sessionDesc.searchPathCount = searchPaths.size();
|
||||||
@@ -92,11 +92,14 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
|||||||
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
|
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
|
||||||
CHECK_DIAGNOSTICS();
|
CHECK_DIAGNOSTICS();
|
||||||
auto entry = signature->findEntryPointByName(createInfo.entryPoint.c_str());
|
auto entry = signature->findEntryPointByName(createInfo.entryPoint.c_str());
|
||||||
|
uint32 offset = 0;
|
||||||
|
if(target == SLANG_DXIL)
|
||||||
|
{
|
||||||
|
offset = 1;// idk why
|
||||||
|
}
|
||||||
for(size_t i = 0; i < signature->getParameterCount(); ++i)
|
for(size_t i = 0; i < signature->getParameterCount(); ++i)
|
||||||
{
|
{
|
||||||
auto param = signature->getParameterByIndex(i);
|
paramMapping[param->getName()] = offset++;
|
||||||
paramMapping[param->getName()] = param->getBindingIndex();
|
|
||||||
std::cout << param->getName() << " " << param->getBindingIndex() << " " << param->getSemanticIndex() << std::endl;
|
|
||||||
}
|
}
|
||||||
return kernelBlob;
|
return kernelBlob;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user