Adding DXC

This commit is contained in:
Dynamitos
2024-04-12 09:27:30 +02:00
parent 4dc2df800a
commit efb2c0e169
17 changed files with 164 additions and 76 deletions
+4 -4
View File
@@ -1,5 +1,6 @@
#pragma once
#include "Graphics/Command.h"
#include "Metal/MTLCommandBuffer.hpp"
#include "RenderPass.h"
#include "Resources.h"
@@ -12,7 +13,7 @@ DECLARE_REF(Graphics)
class Command
{
public:
Command(PGraphics graphics, PCommandQueue owner);
Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer);
~Command();
void beginRenderPass(PRenderPass renderPass);
void endRenderPass();
@@ -32,7 +33,6 @@ public:
}
private:
PGraphics graphics;
PCommandQueue owner;
OEvent completed;
MTL::CommandBuffer* cmdBuffer;
MTL::ParallelRenderCommandEncoder* renderEncoder;
@@ -82,7 +82,7 @@ public:
{
return queue;
}
PCommand getCommands();
PCommand getCommands() {return activeCommand;} //TODO
ORenderCommand getRenderCommand(const std::string& name);
OComputeCommand getComputeCommand(const std::string& name);
void submitCommands(PEvent signal = nullptr);
@@ -100,7 +100,7 @@ public:
{
return queue;
}
PCommand getCommands();
PCommand getCommands() {return activeCommand;} // TODO
void submitCommands(PEvent signal = nullptr);
private:
PGraphics graphics;
+28 -27
View File
@@ -1,6 +1,7 @@
#include "Command.h"
#include "Graphics/Graphics.h"
#include "Graphics/Metal/Resources.h"
#include "Metal/MTLCommandBuffer.hpp"
#include "Metal/MTLIOCommandQueue.hpp"
#include "Metal/MTLRenderCommandEncoder.hpp"
#include "Window.h"
@@ -8,9 +9,9 @@
using namespace Seele;
using namespace Seele::Metal;
Command::Command(PGraphics graphics, PCommandQueue owner)
: graphics(graphics), owner(owner), completed(new Event(graphics)),
cmdBuffer(owner->getHandle()->commandBuffer()), renderEncoder(nullptr) {}
Command::Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer)
: graphics(graphics), completed(new Event(graphics)),
cmdBuffer(cmdBuffer), renderEncoder(nullptr) {}
Command::~Command() { cmdBuffer->release(); }
@@ -77,48 +78,48 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) {
}
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
encoder->setRenderPipelineState(
pipeline.cast<GraphicsPipeline>()->getState());
// encoder->setRenderPipelineState(
// pipeline.cast<GraphicsPipeline>()->getState());
}
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
encoder->set ? ? ? ? ?
}
void RenderCommand::bindDescriptor(
const Array<Gfx::PDescriptorSet> &descriptorSets) {
encoder->set ? ? ? ? ?
// encoder->set ? ? ? ? ?
}
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer> &buffers) {
encoder->setVertexBuffers();
// encoder->setVertexBuffers();
}
void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) {
encoder->setObjectBuffer(??, NS::UInteger offset, NS::UInteger index)
// encoder->setObjectBuffer(??, NS::UInteger offset, NS::UInteger index)
}
void RenderCommand::pushConstants(Gfx::PPipelineLayout layout,
Gfx::SeShaderStageFlags stage, uint32 offset,
uint32 size, const void *data) {
? ? ?
// ? ? ?
}
void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount,
int32 firstVertex, uint32 firstInstance) {
encoder->drawPrimitives(???, firstVertex, vertexCount, instanceCount, firstInstance);
// encoder->drawPrimitives(???, firstVertex, vertexCount, instanceCount, firstInstance);
}
void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount,
int32 firstIndex, uint32 vertexOffset,
uint32 firstInstance) {
encoder->drawIndexedPrimitives(???, indexCount, indexbuffer->getType(), indexBuffer->getBuffer(), firstIndex, instanceCount, vertexOffset, firstInstance);
// encoder->drawIndexedPrimitives(???, indexCount, indexbuffer->getType(), indexBuffer->getBuffer(), firstIndex, instanceCount, vertexOffset, firstInstance);
}
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ){
encoder->drawMeshThreads(MTL::Size threadsPerGrid,
MTL::Size threadsPerObjectThreadgroup,
MTL::Size threadsPerMeshThreadgroup)}
// encoder->drawMeshThreads(MTL::Size threadsPerGrid,
// MTL::Size threadsPerObjectThreadgroup,
// MTL::Size threadsPerMeshThreadgroup)
}
ComputeCommand::ComputeCommand(MTL::ComputeCommandEncoder *encoder)
: encoder(encoder) {}
@@ -128,30 +129,30 @@ ComputeCommand::~ComputeCommand() { encoder->release(); }
void ComputeCommand::end() { encoder->endEncoding(); }
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
encoder->setComputePipelineState(pipeline.cast<ComputePipeline>());
// encoder->setComputePipelineState(pipeline.cast<ComputePipeline>());
}
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
encoder->set ? ? ?
// encoder->set ? ? ?
}
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet> &sets) {
encoder->set ? ? ?
// encoder->set ? ? ?
}
void ComputeCommand::pushConstants(Gfx::PPipelineLayout layout,
Gfx::SeShaderStageFlags stage, uint32 offset,
uint32 size, const void *data) {
? ? ?
// ? ? ?
}
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
encoder->dispatchThreadgroups(???);
// encoder->dispatchThreadgroups(???);
}
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
queue = graphics->getDevice()->newCommandQueue();
activeCommand = new Command(graphics, this);
activeCommand = new Command(graphics, queue->commandBuffer());
}
CommandQueue::~CommandQueue() { queue->release(); }
@@ -166,8 +167,8 @@ OComputeCommand CommandQueue::getComputeCommand(const std::string &name) {
void CommandQueue::submitCommands(PEvent signalSemaphore) {
activeCommand->end(signalSemaphore);
MTL::Event *prevCmdEvent = activeCommand->getCompletedEvent();
activeCommand = new Command(graphics, this);
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
activeCommand = new Command(graphics, queue->commandBuffer());
activeCommand->waitForEvent(prevCmdEvent);
}
@@ -175,8 +176,8 @@ IOCommandQueue::IOCommandQueue(PGraphics graphics) : graphics(graphics) {
MTL::IOCommandQueueDescriptor* desc = MTL::IOCommandQueueDescriptor::alloc()->init();
desc->setType(MTL::IOCommandQueueTypeConcurrent);
desc->setPriority(MTL::IOPriorityNormal);
queue = graphics->getDevice()->newIOCommandQueue(desc);
activeCommand = new Command(graphics, this);
queue = graphics->getDevice()->newIOCommandQueue(desc, nullptr);
//activeCommand = new Command(graphics, queue->commandBuffer());
desc->release();
}
@@ -185,7 +186,7 @@ IOCommandQueue::~IOCommandQueue() { queue->release(); }
void IOCommandQueue::submitCommands(PEvent signalSemaphore) {
//TODO: scratch buffer
activeCommand->end(signalSemaphore);
MTL::Event *prevCmdEvent = activeCommand->getCompletedEvent();
activeCommand = new Command(graphics, this);
PEvent prevCmdEvent = activeCommand->getCompletedEvent();
//activeCommand = new Command(graphics, queue->commandBuffer());
activeCommand->waitForEvent(prevCmdEvent);
}
+37 -19
View File
@@ -1,53 +1,71 @@
#pragma once
#include "Foundation/NSArray.hpp"
#include "Graphics/Descriptor.h"
#include "Graphics/Initializer.h"
#include "Metal/MTLArgumentEncoder.hpp"
#include "MinimalEngine.h"
namespace Seele {
namespace Metal {
DECLARE_REF(Graphics)
DECLARE_REF(DescriptorPool)
class DescriptorLayout : public Gfx::DescriptorLayout
{
class DescriptorLayout : public Gfx::DescriptorLayout {
public:
DescriptorLayout(PGraphics graphics, const std::string& name);
DescriptorLayout(PGraphics graphics, const std::string &name);
virtual ~DescriptorLayout();
virtual void create() override;
NS::Array* getArguments() const
{
return arguments;
}
private:
PGraphics graphics;
NS::Array* arguments;
};
class PipelineLayout : public Gfx::PipelineLayout
{
class PipelineLayout : public Gfx::PipelineLayout {
public:
PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
: Gfx::PipelineLayout(baseLayout)
, graphics(graphics)
{}
: Gfx::PipelineLayout(baseLayout), graphics(graphics) {}
private:
PGraphics graphics;
};
DEFINE_REF(PipelineLayout)
class DescriptorSet : public Gfx::DescriptorSet
{
class DescriptorSet : public Gfx::DescriptorSet {
public:
DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: graphics(graphics)
, owner(owner)
{}
DescriptorSet(PGraphics graphics, PDescriptorPool owner);
virtual ~DescriptorSet();
virtual void writeChanges();
virtual void updateBuffer(uint32_t binding,
Gfx::PUniformBuffer uniformBuffer);
virtual void updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer);
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState);
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture,
Gfx::PSampler sampler = nullptr);
virtual void updateTextureArray(uint32_t binding,
Array<Gfx::PTexture> texture);
virtual bool operator<(Gfx::PDescriptorSet other);
private:
PGraphics graphics;
PDescriptorPool owner;
MTL::Buffer* buffer;
MTL::ArgumentEncoder* encoder;
};
DEFINE_REF(DescriptorSet)
class DescriptorPool : public Gfx::DescriptorPool
{
class DescriptorPool : public Gfx::DescriptorPool {
public:
DescriptorPool(PGraphics graphics);
DescriptorPool(PGraphics graphics, DescriptorLayout& layout);
virtual ~DescriptorPool();
NS::Array* getArguments() const
{
return layout.getArguments();
}
private:
PGraphics graphics;
DescriptorLayout& layout;
};
}
}
} // namespace Metal
} // namespace Seele
+28
View File
@@ -0,0 +1,28 @@
#include "Descriptor.h"
#include "Graphics.h"
using namespace Seele;
using namespace Seele::Metal;
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
: graphics(graphics)
, owner(owner)
{
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
}
DescriptorSet::~DescriptorSet()
{
}
void DescriptorSet::writeChanges()
{
}
void DescriptorSet::updateBuffer(uint32_t binding,
Gfx::PUniformBuffer uniformBuffer){}
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer){}
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState){}
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture,
Gfx::PSampler sampler){}
void DescriptorSet::updateTextureArray(uint32_t binding,
Array<Gfx::PTexture> texture){}
bool DescriptorSet::operator<(Gfx::PDescriptorSet other){return this < other.getHandle();}
-1
View File
@@ -59,7 +59,6 @@ public:
PIOCommandQueue getIOQueue() const { return ioQueue; }
protected:
MTL::Device* device;
MTL::Library* library;
OCommandQueue queue;
OIOCommandQueue ioQueue;
};
+8 -4
View File
@@ -1,4 +1,5 @@
#include "Graphics.h"
#include "Graphics/Metal/Shader.h"
#include "RenderPass.h"
#include "Command.h"
#include "Window.h"
@@ -19,8 +20,6 @@ Graphics::~Graphics()
void Graphics::init(GraphicsInitializer)
{
device = MTL::CreateSystemDefaultDevice();
library = device->newDefaultLibrary();
assert(library);
queue = new CommandQueue(this);
ioQueue = new IOCommandQueue(this);
}
@@ -121,11 +120,16 @@ Gfx::OFragmentShader Graphics::createFragmentShader(const ShaderCreateInfo& crea
}
Gfx::OComputeShader Graphics::createComputeShader(const ShaderCreateInfo& createInfo)
{
OComputeShader result = new ComputeShader(this);
result->create(createInfo);
return result;
}
Gfx::OMeshShader Graphics::createMeshShader(const ShaderCreateInfo& createInfo)
{
OMeshShader result = new MeshShader(this);
result->create(createInfo);
return result;
}
Gfx::OTaskShader Graphics::createTaskShader(const ShaderCreateInfo& createInfo)
{
+13 -2
View File
@@ -2,8 +2,8 @@
#include "Graphics.h"
#include "Graphics/Enums.h"
#include "Graphics/slang-compile.h"
#include "Metal/MTLLibrary.hpp"
#include "metal_irconverter/metal_irconverter.h"
#include <iostream>
#include </usr/local/include/metal_irconverter/metal_irconverter.h>
#include <slang.h>
using namespace Seele;
@@ -55,6 +55,17 @@ void Shader::create(const ShaderCreateInfo &createInfo) {
uint8_t *metallib = new uint8_t[metallibSize];
IRMetalLibGetBytecode(pMetallib, metallib);
IRShaderReflection* reflection = IRShaderReflectionCreate();
IRObjectGetReflection(pOutIR, irStage, reflection);
Array<IRResourceLocation> locations(
IRShaderReflectionGetResourceCount(reflection));
IRShaderReflectionGetResourceLocations(reflection, locations.data());
for(auto l : locations)
{
std::cout << "Resource " << l.resourceName << " Type " << l.resourceType << " size " << l.sizeBytes << " slot " << l.slot << " space " << l.space << " offset " << l.topLevelOffset << std::endl;
}
IRShaderReflectionDestroy(reflection);
// Store the metallib to custom format or disk, or use to create a MTLLibrary.
NS::Error *__autoreleasing error = nil;
dispatch_data_t data = dispatch_data_create(metallib, metallibSize,