this sucks, but there is hope

This commit is contained in:
Dynamitos
2024-04-20 21:35:43 +02:00
parent a27e280ab8
commit acc976fe84
30 changed files with 279 additions and 192 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ namespace Metal {
DECLARE_REF(Graphics)
class Buffer {
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();
MTL::Buffer *getHandle() const { return buffers[currentBuffer]; }
uint64 getSize() const { return size; }
@@ -83,4 +83,4 @@ protected:
};
DEFINE_REF(ShaderBuffer)
} // namespace Metal
} // namespace Seele
} // namespace Seele
+12 -9
View File
@@ -3,10 +3,12 @@
#include "Graphics/Buffer.h"
#include "Graphics/Enums.h"
#include "Graphics/Initializer.h"
#include <iostream>
using namespace Seele;
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) {
numBuffers = Gfx::numFramesBuffered;
} else {
@@ -14,10 +16,11 @@ Buffer::Buffer(PGraphics graphics, uint64 size, void* data, bool dynamic) : grap
}
for (size_t i = 0; i < numBuffers; ++i) {
if (data != nullptr) {
buffers[i] = graphics->getDevice()->newBuffer(data, size, MTL::ResourceOptionCPUCacheModeDefault);
buffers[i] = graphics->getDevice()->newBuffer(data, size, MTL::StorageModeShared);
} 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 unmap() {}
void Buffer::unmap() {}
VertexBuffer::VertexBuffer(PGraphics graphics, const VertexBufferCreateInfo& createInfo)
: Gfx::VertexBuffer(graphics->getFamilyMapping(), createInfo.numVertices, createInfo.vertexSize,
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() {}
@@ -61,7 +64,7 @@ void VertexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SeP
IndexBuffer::IndexBuffer(PGraphics graphics, const IndexBufferCreateInfo& createInfo)
: Gfx::IndexBuffer(graphics->getFamilyMapping(), createInfo.sourceData.size, createInfo.indexType,
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() {}
@@ -77,7 +80,7 @@ void IndexBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePi
UniformBuffer::UniformBuffer(PGraphics graphics, const UniformBufferCreateInfo& createInfo)
: 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() {}
@@ -94,7 +97,7 @@ void UniformBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::Se
ShaderBuffer::ShaderBuffer(PGraphics graphics, const ShaderBufferCreateInfo& createInfo)
: 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() {}
@@ -108,4 +111,4 @@ void ShaderBuffer::executeOwnershipBarrier(Gfx::QueueType newOwner) { currentOwn
void ShaderBuffer::executePipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage,
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {}
Gfx::SeAccessFlags dstAccess, Gfx::SePipelineStageFlags dstStage) {}
+78 -41
View File
@@ -11,6 +11,7 @@
#include "Pipeline.h"
#include "Resources.h"
#include "Window.h"
#include <iostream>
using namespace Seele;
using namespace Seele::Metal;
@@ -74,14 +75,46 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) {
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
boundPipeline = pipeline.cast<GraphicsPipeline>();
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) {
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName());
encoder->setVertexBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
encoder->setFragmentBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
encoder->setMeshBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
encoder->setObjectBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
auto metalSet = descriptorSet.cast<DescriptorSet>();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName());
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
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) {
@@ -122,6 +155,10 @@ void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 f
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) {
// 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));
}
@@ -136,46 +173,46 @@ void ComputeCommand::end() {
}
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
boundPipeline = pipeline.cast<ComputePipeline>();
encoder->setComputePipelineState(boundPipeline->getHandle());
argumentBuffer = boundPipeline->graphics->getDevice()->newBuffer(sizeof(uint64) * boundPipeline->getPipelineLayout()->getLayouts().size(), MTL::ResourceOptionCPUCacheModeDefault);
boundPipeline = pipeline.cast<ComputePipeline>();
encoder->setComputePipelineState(boundPipeline->getHandle());
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) {
auto metalSet = set.cast<DescriptorSet>();
metalSet->bind();
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName());
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
auto bindings =metalSet->getLayout()->getBindings();
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);
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName());
uint64* topLevelTable = (uint64*)argumentBuffer->contents();
topLevelTable[parameterIndex] = metalSet->getBuffer()->gpuAddress();
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 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) {
// TODO
encoder->setBuffer(argumentBuffer, 0, 2);
encoder->setBuffer(argumentBuffer, 0, 2);
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
}
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
queue = graphics->getDevice()->newCommandQueue();
MTL::CommandBufferDescriptor* descriptor = MTL::CommandBufferDescriptor::alloc()->init();
descriptor->setErrorOptions(MTL::CommandBufferErrorOptionEncoderExecutionStatus);
activeCommand = new Command(graphics, queue->commandBuffer(descriptor));
descriptor->release();
}
CommandQueue::~CommandQueue() { queue->release(); }
+3 -7
View File
@@ -13,11 +13,8 @@ public:
virtual ~DescriptorLayout();
virtual void create() override;
NS::Array* getArguments() const { return arguments; }
private:
PGraphics graphics;
NS::Array* arguments;
};
DEFINE_REF(DescriptorLayout)
@@ -28,7 +25,6 @@ public:
virtual ~DescriptorPool();
virtual Gfx::PDescriptorSet allocateDescriptorSet() override;
virtual void reset() override;
constexpr NS::Array* getArguments() const { return layout->getArguments(); }
constexpr PDescriptorLayout getLayout() const { return layout; }
private:
@@ -63,7 +59,7 @@ private:
PGraphics graphics;
PDescriptorPool owner;
MTL::Buffer* buffer = nullptr;
MTL::ArgumentEncoder* encoder;
uint64* argumentBuffer = nullptr;
Array<MTL::Resource*> boundResources;
uint32 bindCount;
bool currentlyInUse;
@@ -72,10 +68,10 @@ DEFINE_REF(DescriptorSet)
class PipelineLayout : public Gfx::PipelineLayout {
public:
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout);
PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout);
virtual ~PipelineLayout();
virtual void create() override;
Array<Array<uint32>>
private:
PGraphics graphics;
};
+32 -86
View File
@@ -15,74 +15,11 @@ using namespace Seele;
using namespace Seele::Metal;
DescriptorLayout::DescriptorLayout(PGraphics graphics, const std::string& name)
: Gfx::DescriptorLayout(name), graphics(graphics), arguments(nullptr) {}
: Gfx::DescriptorLayout(name), graphics(graphics) {}
DescriptorLayout::~DescriptorLayout() {}
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);
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(),
CRC::CRC_32());
@@ -116,63 +53,72 @@ void DescriptorPool::reset() {
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: Gfx::DescriptorSet(owner->getLayout()), graphics(graphics), owner(owner), bindCount(0), currentlyInUse(false) {
if (owner->getArguments()->count() > 0) {
boundResources.resize(owner->getArguments()->count());
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
encoder->setArgumentBuffer(buffer, 0);
} else
{
buffer = graphics->getDevice()->newBuffer(8, MTL::ResourceOptionCPUCacheModeDefault);
}
boundResources.resize(owner->getLayout()->getBindings().size());
buffer = graphics->getDevice()->newBuffer(std::max<size_t>(8, sizeof(uint64_t) * 3 * owner->getLayout()->getBindings().size()), MTL::ResourceStorageModeShared);
argumentBuffer = (uint64*)buffer->contents();
buffer->setLabel(NS::String::string(owner->getLayout()->getName().c_str(), NS::ASCIIStringEncoding));
}
DescriptorSet::~DescriptorSet() {}
DescriptorSet::~DescriptorSet() {buffer->release();}
void DescriptorSet::writeChanges() {}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer 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();
}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) {
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();
}
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
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) {
PTextureBase base = texture.cast<TextureBase>();
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{
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();
}
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
for (auto& t : array) {
PTextureBase metalTexture = t.cast<TextureBase>();
encoder->setTexture(metalTexture->getTexture(), binding);
boundResources[binding++] = metalTexture->getTexture();
updateTexture(binding++, t);
}
}
PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(baseLayout), graphics(graphics) {}
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
PipelineLayout::~PipelineLayout() {}
void PipelineLayout::create() {
for (auto& [_, set] : descriptorSetLayouts) {
set->create();
assert(set->getHash() != 0);
uint32 setHash = set->getHash();
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
}
+1 -1
View File
@@ -49,7 +49,7 @@ public:
virtual Gfx::OSampler createSampler(const SamplerCreateInfo& createInfo) 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;
+2 -2
View File
@@ -180,9 +180,9 @@ Gfx::ODescriptorLayout Graphics::createDescriptorLayout(const std::string& 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)
+1 -1
View File
@@ -19,10 +19,10 @@ public:
virtual ~GraphicsPipeline();
constexpr MTL::RenderPipelineState* getHandle() const { return state; }
constexpr MTL::PrimitiveType getPrimitive() const { return primitiveType; }
private:
PGraphics graphics;
MTL::RenderPipelineState* state;
MTL::PrimitiveType primitiveType;
private:
};
DEFINE_REF(GraphicsPipeline)
class ComputePipeline : public Gfx::ComputePipeline {
+7 -7
View File
@@ -25,15 +25,15 @@ Shader::~Shader() {
}
void Shader::create(const ShaderCreateInfo& createInfo) {
std::cout << "Compiling " << createInfo.name << std::endl;
Map<std::string, uint32> test;
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_DXIL, test);
std::cout << "Compiling " << createInfo.name << std::endl;
Map<std::string, uint32> paramMapping;
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_DXIL, paramMapping);
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
IRCompiler* pCompiler = IRCompilerCreate();
IRCompilerSetMinimumGPUFamily(pCompiler, IRGPUFamilyMetal3);
IRCompilerIgnoreRootSignature(pCompiler, true);
IRCompilerSetEntryPointName(pCompiler, "main");
IRCompilerSetValidationFlags(pCompiler, IRCompilerValidationFlagAll);
IRCompilerSetValidationFlags(pCompiler, IRCompilerValidationFlagAll);
IRObject* pDXIL = IRObjectCreateFromDXIL((const uint8*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(),
IRBytecodeOwnershipNone);
@@ -100,8 +100,8 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
descriptor.desc_1_1.pParameters = parameters.data();
IRRootSignature* rootSignature = IRRootSignatureCreateFromDescriptor(&descriptor, &signatureError);
assert(rootSignature);
IRCompilerSetGlobalRootSignature(pCompiler, rootSignature);
// Compile DXIL to Metal IR:
// IRCompilerSetGlobalRootSignature(pCompiler, rootSignature);
// Compile DXIL to Metal IR:
IRError* pError = nullptr;
IRObject* pOutIR = IRCompilerAllocCompileAndLink(pCompiler, NULL, pDXIL, &pError);
@@ -131,7 +131,7 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
IRMetalLibBinary* pMetallib = IRMetalLibBinaryCreate();
IRObjectGetMetalLibBinary(pOutIR, irStage, pMetallib);
dispatch_data_t data = IRMetalLibGetBytecodeData(pMetallib);
IRShaderReflection* reflection = IRShaderReflectionCreate();
IRObjectGetReflection(pOutIR, irStage, reflection);
std::cout << IRShaderReflectionAllocStringAndSerialize(reflection) << std::endl;
+5 -1
View File
@@ -21,7 +21,7 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
ownsImage(existingImage == nullptr) {
if (existingImage == nullptr) {
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;
}
@@ -29,6 +29,10 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
{
mtlUsage |= MTL::TextureUsageShaderRead;
}
if(usage & Gfx::SE_IMAGE_USAGE_STORAGE_BIT)
{
mtlUsage |= MTL::TextureUsageShaderWrite;
}
MTL::TextureDescriptor *descriptor =
MTL::TextureDescriptor::alloc()->init();
descriptor->setPixelFormat(cast(format));