Descriptors now work in metal hopefully
This commit is contained in:
+9
-11
@@ -11,8 +11,6 @@
|
||||
#include "Graphics/Vulkan/Graphics.h"
|
||||
#endif
|
||||
#include "Graphics/StaticMeshVertexData.h"
|
||||
#include "Graphics/Vulkan/Buffer.h"
|
||||
#include "Graphics/Vulkan/Graphics.h"
|
||||
#include "Window/PlayView.h"
|
||||
#include "Window/WindowManager.h"
|
||||
#include <fmt/core.h>
|
||||
@@ -60,22 +58,22 @@ int main() {
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/cube.fbx",
|
||||
//});
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/culling.fbx",
|
||||
});
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/culling.fbx",
|
||||
//});
|
||||
AssetImporter::importTexture(TextureImportArgs{
|
||||
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
|
||||
.type = TextureImportType::TEXTURE_CUBEMAP,
|
||||
});
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/ship.fbx",
|
||||
// .importPath = "ship",
|
||||
//});
|
||||
AssetImporter::importMesh(MeshImportArgs{
|
||||
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
||||
.importPath = "Whitechapel",
|
||||
.filePath = sourcePath / "import/models/ship.fbx",
|
||||
.importPath = "ship",
|
||||
});
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
||||
// .importPath = "Whitechapel",
|
||||
//});
|
||||
//AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
|
||||
// .importPath = "suburbs",
|
||||
//});
|
||||
|
||||
@@ -13,8 +13,8 @@ class RenderCommand {
|
||||
virtual void setViewport(Gfx::PViewport viewport) = 0;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) = 0;
|
||||
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) = 0;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets = {}) = 0;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets = {}) = 0;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
|
||||
virtual void bindVertexBuffer(const Array<PVertexBuffer>& buffer) = 0;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) = 0;
|
||||
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0;
|
||||
@@ -31,8 +31,8 @@ class ComputeCommand {
|
||||
ComputeCommand();
|
||||
virtual ~ComputeCommand();
|
||||
virtual void bindPipeline(Gfx::PComputePipeline pipeline) = 0;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets = {}) = 0;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets = {}) = 0;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) = 0;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) = 0;
|
||||
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) = 0;
|
||||
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) = 0;
|
||||
std::string name;
|
||||
|
||||
@@ -64,11 +64,8 @@ class DescriptorSet {
|
||||
virtual void updateBuffer(uint32 binding, PUniformBuffer uniformBuffer) = 0;
|
||||
virtual void updateBuffer(uint32 binding, PIndexBuffer indexBuffer) = 0;
|
||||
virtual void updateBuffer(uint32 binding, PShaderBuffer shaderBuffer) = 0;
|
||||
virtual void updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) = 0;
|
||||
virtual void updateSampler(uint32 binding, PSampler sampler) = 0;
|
||||
virtual void updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) = 0;
|
||||
virtual void updateTexture(uint32 binding, PTexture texture, PSampler samplerState = nullptr) = 0;
|
||||
virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, PTexture texture) = 0;
|
||||
virtual void updateTextureArray(uint32_t binding, Array<PTexture2D> texture) = 0;
|
||||
virtual void updateSamplerArray(uint32_t binding, Array<PSampler> samplers) = 0;
|
||||
virtual void updateAccelerationStructure(uint32 binding, PTopLevelAS as) = 0;
|
||||
@@ -96,6 +93,8 @@ class PipelineLayout {
|
||||
constexpr uint32 findParameter(const std::string& param) const { return parameterMapping[param]; }
|
||||
void addMapping(std::string name, uint32 index);
|
||||
constexpr std::string getName() const { return name; };
|
||||
constexpr bool hasPushConstants() const { return !pushConstants.empty(); }
|
||||
constexpr uint64 getPushConstantsSize() const { return pushConstants[0].size; }
|
||||
|
||||
protected:
|
||||
uint32 layoutHash = 0;
|
||||
|
||||
@@ -159,8 +159,8 @@ static constexpr bool useAsyncCompute = false;
|
||||
static constexpr bool useMeshShading = true;
|
||||
static constexpr uint32 numFramesBuffered = 3;
|
||||
|
||||
static constexpr uint32 numVerticesPerMeshlet = 256;
|
||||
static constexpr uint32 numPrimitivesPerMeshlet = 256;
|
||||
static constexpr uint32 numVerticesPerMeshlet = 64;
|
||||
static constexpr uint32 numPrimitivesPerMeshlet = 126;
|
||||
double getCurrentFrameDelta();
|
||||
double getCurrentFrameTime();
|
||||
uint32 getCurrentFrameIndex();
|
||||
|
||||
@@ -68,7 +68,7 @@ struct SamplerCreateInfo {
|
||||
Gfx::SeSamplerAddressMode addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
float mipLodBias = 0.0f;
|
||||
uint32 anisotropyEnable = 0;
|
||||
float maxAnisotropy = 0.0f;
|
||||
float maxAnisotropy = 1.0f;
|
||||
uint32 compareEnable = 0;
|
||||
Gfx::SeCompareOp compareOp = Gfx::SE_COMPARE_OP_NEVER;
|
||||
float minLod = 0.0f;
|
||||
@@ -138,6 +138,7 @@ struct SePushConstantRange {
|
||||
SeShaderStageFlags stageFlags;
|
||||
uint32 offset;
|
||||
uint32 size;
|
||||
std::string name;
|
||||
};
|
||||
struct RasterizationState {
|
||||
uint32 depthClampEnable = 0;
|
||||
|
||||
@@ -42,8 +42,11 @@ void BufferAllocation::unmap() {}
|
||||
Buffer::Buffer(PGraphics graphics, uint64 size, Gfx::SeBufferUsageFlags usage, Gfx::QueueType queueType, bool dynamic, std::string name,
|
||||
bool createCleared, uint32 clearValue)
|
||||
: graphics(graphics), currentBuffer(0), dynamic(dynamic), createCleared(createCleared), name(name), clearValue(clearValue) {
|
||||
buffers.add(nullptr);
|
||||
createBuffer(size, 0);
|
||||
if(size > 0)
|
||||
{
|
||||
buffers.add(nullptr);
|
||||
createBuffer(size, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::~Buffer() {
|
||||
@@ -101,10 +104,16 @@ void Buffer::copyBuffer(uint64 src, uint64 dest) {
|
||||
std::memcpy(buffers[dest]->map(), buffers[src]->map(), buffers[src]->size);
|
||||
}
|
||||
|
||||
void Buffer::transferOwnership(Gfx::QueueType newOwner) { getAlloc()->transferOwnership(newOwner); }
|
||||
void Buffer::transferOwnership(Gfx::QueueType newOwner) {
|
||||
if(buffers.size() == 0)
|
||||
return;
|
||||
getAlloc()->transferOwnership(newOwner);
|
||||
}
|
||||
|
||||
void Buffer::pipelineBarrier(Gfx::SeAccessFlags srcAccess, Gfx::SePipelineStageFlags srcStage, Gfx::SeAccessFlags dstAccess,
|
||||
Gfx::SePipelineStageFlags dstStage) {
|
||||
if(buffers.size() == 0)
|
||||
return;
|
||||
getAlloc()->pipelineBarrier(srcAccess, srcStage, dstAccess, dstStage);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ class RenderCommand : public Gfx::RenderCommand {
|
||||
virtual void setViewport(Gfx::PViewport viewport) override;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
||||
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
|
||||
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
@@ -71,9 +71,8 @@ class RenderCommand : public Gfx::RenderCommand {
|
||||
private:
|
||||
PGraphicsPipeline boundPipeline;
|
||||
PIndexBuffer boundIndexBuffer;
|
||||
MTL::ArgumentEncoder* argumentEncoder;
|
||||
MTL::Buffer* argumentBuffer;
|
||||
MTL::RenderCommandEncoder* encoder;
|
||||
MTL::Buffer* constantsBuffer;
|
||||
std::string name;
|
||||
};
|
||||
DEFINE_REF(RenderCommand)
|
||||
@@ -83,8 +82,8 @@ class ComputeCommand : public Gfx::ComputeCommand {
|
||||
virtual ~ComputeCommand();
|
||||
void end();
|
||||
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
|
||||
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
|
||||
|
||||
@@ -92,7 +91,7 @@ class ComputeCommand : public Gfx::ComputeCommand {
|
||||
PComputePipeline boundPipeline;
|
||||
MTL::CommandBuffer* commandBuffer;
|
||||
MTL::ComputeCommandEncoder* encoder;
|
||||
MTL::Buffer* argumentBuffer;
|
||||
MTL::Buffer* constantsBuffer;
|
||||
std::string name;
|
||||
};
|
||||
DEFINE_REF(ComputeCommand)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Containers/Array.h"
|
||||
#include "Descriptor.h"
|
||||
#include "Enums.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Graphics/Command.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
@@ -74,35 +75,51 @@ void RenderCommand::setViewport(Gfx::PViewport viewport) {
|
||||
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
|
||||
boundPipeline = pipeline.cast<GraphicsPipeline>();
|
||||
encoder->setRenderPipelineState(boundPipeline->getHandle());
|
||||
if(boundPipeline->getPipelineLayout()->hasPushConstants()) {
|
||||
constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCommand::bindPipeline(Gfx::PRayTracingPipeline pipeline) {}
|
||||
|
||||
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> offsets) {
|
||||
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
|
||||
auto metalSet = descriptorSet.cast<DescriptorSet>();
|
||||
metalSet->bind();
|
||||
uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName());
|
||||
encoder->setVertexBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
|
||||
encoder->setFragmentBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
|
||||
encoder->setObjectBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
|
||||
encoder->setMeshBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
|
||||
}
|
||||
|
||||
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> offsets) {
|
||||
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
|
||||
for (auto set : descriptorSets) {
|
||||
bindDescriptor(set, offsets);
|
||||
bindDescriptor(set);
|
||||
}
|
||||
}
|
||||
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) {
|
||||
uint32 i = 0;
|
||||
for (auto buffer : buffers) {
|
||||
encoder->setVertexBuffer(buffer.cast<VertexBuffer>()->getHandle(), 0, METAL_VERTEXBUFFER_OFFSET + i++);
|
||||
encoder->setVertexBuffer(buffer.cast<VertexBuffer>()->getHandle(), 0, buffer.cast<VertexBuffer>()->getVertexSize(), i++);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer gfxIndexBuffer) { boundIndexBuffer = gfxIndexBuffer.cast<IndexBuffer>(); }
|
||||
|
||||
void RenderCommand::pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) {
|
||||
std::memcpy(constantsBuffer->contents(), data, size);
|
||||
uint pushIndex = boundPipeline->getPipelineLayout()->findParameter("pOffsets");
|
||||
if (stage & Gfx::SE_SHADER_STAGE_VERTEX_BIT) {
|
||||
encoder->setVertexBytes((char*)data + offset, size, 0);
|
||||
encoder->setVertexBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
|
||||
}
|
||||
if (stage & Gfx::SE_SHADER_STAGE_FRAGMENT_BIT) {
|
||||
encoder->setFragmentBytes((char*)data + offset, size, 0);
|
||||
encoder->setFragmentBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
|
||||
}
|
||||
if (stage & Gfx::SE_SHADER_STAGE_TASK_BIT_EXT) {
|
||||
encoder->setObjectBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
|
||||
}
|
||||
if (stage & Gfx::SE_SHADER_STAGE_MESH_BIT_EXT) {
|
||||
encoder->setMeshBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,11 +133,6 @@ 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));
|
||||
}
|
||||
|
||||
@@ -143,29 +155,32 @@ 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() + 1), MTL::ResourceStorageModeShared);
|
||||
argumentBuffer->setLabel(NS::String::string(pipeline->getPipelineLayout()->getName().c_str(), NS::ASCIIStringEncoding));
|
||||
if(boundPipeline->getPipelineLayout()->hasPushConstants()) {
|
||||
constantsBuffer = boundPipeline->graphics->getDevice()->newBuffer(boundPipeline->getPipelineLayout()->getPushConstantsSize(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> offsets) {
|
||||
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
||||
auto metalSet = set.cast<DescriptorSet>();
|
||||
metalSet->bind();
|
||||
uint32 descriptorIndex = boundPipeline->getPipelineLayout()->findParameter(metalSet->getLayout()->getName());
|
||||
encoder->setBuffer(metalSet->getArgumentBuffer(), 0, descriptorIndex);
|
||||
}
|
||||
|
||||
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> offsets) {
|
||||
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
||||
for (auto& set : sets) {
|
||||
bindDescriptor(set, offsets);
|
||||
bindDescriptor(set);
|
||||
}
|
||||
}
|
||||
|
||||
void ComputeCommand::pushConstants(Gfx::SeShaderStageFlags, uint32 offset, uint32 size, const void* data) {
|
||||
encoder->setBytes((char*)data + offset, size, 0);
|
||||
std::memcpy(constantsBuffer->contents(), data, size);
|
||||
uint pushIndex = boundPipeline->getPipelineLayout()->findParameter("pMipParam");
|
||||
encoder->setBuffer(constantsBuffer, 0, pushIndex); // TODO: hardcoded
|
||||
}
|
||||
|
||||
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
|
||||
// TODO
|
||||
encoder->setBuffer(argumentBuffer, 0, 2);
|
||||
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -50,21 +50,20 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
|
||||
virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
|
||||
virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override;
|
||||
virtual void updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) override;
|
||||
virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
|
||||
virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) override;
|
||||
virtual void updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) override;
|
||||
virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override;
|
||||
virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override;
|
||||
|
||||
constexpr const Array<Array<MTL::Resource*>>& getBoundResources() const { return boundResources; }
|
||||
constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; }
|
||||
|
||||
MTL::Buffer* getArgumentBuffer() const { return argumentBuffer; }
|
||||
|
||||
private:
|
||||
PGraphics graphics;
|
||||
PDescriptorPool owner;
|
||||
Array<Array<MTL::Resource*>> boundResources;
|
||||
Array<MTL::Resource*> boundResources;
|
||||
MTL::ArgumentEncoder* encoder;
|
||||
MTL::Buffer* argumentBuffer = nullptr;
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Foundation/NSArray.hpp"
|
||||
#include "Foundation/NSObject.hpp"
|
||||
#include "Graphics/Descriptor.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/Initializer.h"
|
||||
#include "Graphics/Metal/Resources.h"
|
||||
#include "Graphics/Metal/Shader.h"
|
||||
@@ -15,8 +16,10 @@
|
||||
#include "Metal/MTLTexture.hpp"
|
||||
#include "Texture.h"
|
||||
#include <CRC.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Metal;
|
||||
@@ -29,19 +32,68 @@ void DescriptorLayout::create() {
|
||||
pool = new DescriptorPool(graphics, this);
|
||||
hash = CRC::Calculate(descriptorBindings.data(), sizeof(Gfx::DescriptorBinding) * descriptorBindings.size(), CRC::CRC_32());
|
||||
MTL::ArgumentDescriptor** objects = new MTL::ArgumentDescriptor*[descriptorBindings.size()];
|
||||
for(uint32 i = 0; i < descriptorBindings.size(); ++i) {
|
||||
for (uint32 i = 0; i < descriptorBindings.size(); ++i) {
|
||||
objects[i] = MTL::ArgumentDescriptor::alloc()->init();
|
||||
objects[i]->setIndex(i);
|
||||
objects[i]->setAccess(cast(descriptorBindings[i].access));
|
||||
objects[i]->setArrayLength(descriptorBindings[i].descriptorCount);
|
||||
objects[i]->setDataType(MTL::DataTypeStruct);
|
||||
MTL::DataType dataType;
|
||||
switch (descriptorBindings[i].descriptorType) {
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
||||
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:
|
||||
dataType = MTL::DataTypePointer;
|
||||
break;
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLER:
|
||||
dataType = MTL::DataTypeSampler;
|
||||
break;
|
||||
case Gfx::SE_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR:
|
||||
dataType = MTL::DataTypeInstanceAccelerationStructure;
|
||||
break;
|
||||
default:
|
||||
throw new std::logic_error("unknown descriptor type");
|
||||
}
|
||||
objects[i]->setDataType(dataType);
|
||||
MTL::TextureType textureType;
|
||||
switch (descriptorBindings[i].textureType) {
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_1D:
|
||||
textureType = MTL::TextureType1D;
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_2D:
|
||||
textureType = MTL::TextureType2D;
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_3D:
|
||||
textureType = MTL::TextureType3D;
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE:
|
||||
textureType = MTL::TextureTypeCube;
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_1D_ARRAY:
|
||||
textureType = MTL::TextureType1DArray;
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY:
|
||||
textureType = MTL::TextureType2DArray;
|
||||
break;
|
||||
case Gfx::SE_IMAGE_VIEW_TYPE_CUBE_ARRAY:
|
||||
textureType = MTL::TextureTypeCubeArray;
|
||||
break;
|
||||
}
|
||||
objects[i]->setTextureType(textureType);
|
||||
}
|
||||
arguments = NS::Array::array((NS::Object**)objects, descriptorBindings.size());
|
||||
}
|
||||
|
||||
MTL::ArgumentEncoder* DescriptorLayout::createEncoder() {
|
||||
return graphics->getDevice()->newArgumentEncoder(arguments);
|
||||
}
|
||||
MTL::ArgumentEncoder* DescriptorLayout::createEncoder() { return graphics->getDevice()->newArgumentEncoder(arguments); }
|
||||
|
||||
DescriptorPool::DescriptorPool(PGraphics graphics, PDescriptorLayout layout) : graphics(graphics), layout(layout) {}
|
||||
|
||||
@@ -65,10 +117,10 @@ void DescriptorPool::reset() {}
|
||||
|
||||
DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
||||
: Gfx::DescriptorSet(owner->getLayout()), CommandBoundResource(graphics), graphics(graphics), owner(owner) {
|
||||
encoder = owner->getLayout()->createEncoder();
|
||||
argumentBuffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), 0);
|
||||
encoder->setArgumentBuffer(argumentBuffer, 0);
|
||||
boundResources.resize(owner->getLayout()->getBindings().size());
|
||||
for (uint32 i = 0; i < boundResources.size(); ++i) {
|
||||
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
|
||||
}
|
||||
}
|
||||
|
||||
DescriptorSet::~DescriptorSet() {}
|
||||
@@ -76,38 +128,40 @@ DescriptorSet::~DescriptorSet() {}
|
||||
void DescriptorSet::writeChanges() {}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) {
|
||||
boundResources[binding][0] = uniformBuffer.cast<UniformBuffer>()->getHandle();
|
||||
PUniformBuffer buffer = uniformBuffer.cast<UniformBuffer>();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, binding);
|
||||
boundResources[binding] = buffer->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) {
|
||||
boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
|
||||
PShaderBuffer buffer = uniformBuffer.cast<ShaderBuffer>();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, binding);
|
||||
boundResources[binding] = buffer->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) {
|
||||
boundResources[binding][0] = uniformBuffer.cast<IndexBuffer>()->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) {
|
||||
boundResources[binding][0] = uniformBuffer.cast<ShaderBuffer>()->getHandle();
|
||||
PIndexBuffer buffer = uniformBuffer.cast<IndexBuffer>();
|
||||
encoder->setBuffer(buffer->getHandle(), 0, binding);
|
||||
boundResources[binding] = buffer->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSampler(uint32 binding, Gfx::PSampler samplerState) {
|
||||
boundResources[binding][0] = nullptr; // Samplers are not resources??????
|
||||
PSampler sampler = samplerState.cast<Sampler>();
|
||||
encoder->setSamplerState(sampler->getHandle(), binding);
|
||||
boundResources[binding] = nullptr; // Samplers are not resources??????
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) {
|
||||
boundResources[binding][dstArrayIndex] = nullptr;
|
||||
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {
|
||||
PTextureBase base = texture.cast<TextureBase>();
|
||||
encoder->setTexture(base->getHandle()->texture, binding);
|
||||
boundResources[binding] = base->getHandle()->texture;
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler) {}
|
||||
void DescriptorSet::updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) { assert(false && "TODO"); }
|
||||
|
||||
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {}
|
||||
void DescriptorSet::updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) { assert(false && "TODO"); }
|
||||
|
||||
void DescriptorSet::updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) {}
|
||||
|
||||
void DescriptorSet::updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) {}
|
||||
|
||||
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) {}
|
||||
void DescriptorSet::updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) { assert(false && "TODO"); }
|
||||
|
||||
PipelineLayout::PipelineLayout(PGraphics graphics, const std::string& name, Gfx::PPipelineLayout baseLayout)
|
||||
: Gfx::PipelineLayout(name, baseLayout), graphics(graphics) {}
|
||||
|
||||
@@ -121,7 +121,7 @@ Gfx::PGraphicsPipeline Graphics::createGraphicsPipeline(Gfx::MeshPipelineCreateI
|
||||
Gfx::PComputePipeline Graphics::createComputePipeline(Gfx::ComputePipelineCreateInfo createInfo) {
|
||||
return cache->createPipeline(std::move(createInfo));
|
||||
}
|
||||
Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo createInfo) { return nullptr; }
|
||||
Gfx::PRayTracingPipeline Graphics::createRayTracingPipeline(Gfx::RayTracingPipelineCreateInfo) { return nullptr; }
|
||||
|
||||
Gfx::OSampler Graphics::createSampler(const SamplerCreateInfo& createInfo) { return new Sampler(this, createInfo); }
|
||||
|
||||
@@ -143,16 +143,16 @@ Gfx::OTimestampQuery Graphics::createTimestampQuery(uint64 numTimestamps, const
|
||||
return new TimestampQuery(this, name, numTimestamps);
|
||||
}
|
||||
|
||||
void Graphics::resolveTexture(Gfx::PTexture source, Gfx::PTexture destination) {}
|
||||
void Graphics::resolveTexture(Gfx::PTexture, Gfx::PTexture) {}
|
||||
|
||||
void Graphics::copyTexture(Gfx::PTexture src, Gfx::PTexture dst) {}
|
||||
void Graphics::copyTexture(Gfx::PTexture, Gfx::PTexture) {}
|
||||
|
||||
// Ray Tracing
|
||||
Gfx::OBottomLevelAS Graphics::createBottomLevelAccelerationStructure(const Gfx::BottomLevelASCreateInfo& createInfo) { return nullptr; }
|
||||
|
||||
Gfx::OTopLevelAS Graphics::createTopLevelAccelerationStructure(const Gfx::TopLevelASCreateInfo& createInfo) { return nullptr; }
|
||||
|
||||
void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS> data) {}
|
||||
void Graphics::buildBottomLevelAccelerationStructures(Array<Gfx::PBottomLevelAS>) {}
|
||||
|
||||
Gfx::ORayGenShader Graphics::createRayGenShader(const ShaderCreateInfo& createInfo) {
|
||||
ORayGenShader shader = new RayGenShader(this);
|
||||
|
||||
@@ -14,205 +14,171 @@
|
||||
#include "Metal/MTLVertexDescriptor.hpp"
|
||||
#include "Shader.h"
|
||||
#include "Texture.h"
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <iostream>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Metal;
|
||||
|
||||
PipelineCache::PipelineCache(PGraphics graphics, const std::string &name)
|
||||
: graphics(graphics), cacheFile(name) {}
|
||||
PipelineCache::PipelineCache(PGraphics graphics, const std::string& name) : graphics(graphics), cacheFile(name) {}
|
||||
|
||||
PipelineCache::~PipelineCache() {}
|
||||
|
||||
PGraphicsPipeline
|
||||
PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
|
||||
PPipelineLayout layout =
|
||||
Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
|
||||
PGraphicsPipeline PipelineCache::createPipeline(Gfx::LegacyPipelineCreateInfo createInfo) {
|
||||
PPipelineLayout layout = Gfx::PPipelineLayout(createInfo.pipelineLayout).cast<PipelineLayout>();
|
||||
|
||||
MTL::RenderPipelineDescriptor *pipelineDescriptor =
|
||||
MTL::RenderPipelineDescriptor::alloc()->init();
|
||||
MTL::RenderPipelineDescriptor* pipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||
|
||||
MTL::VertexDescriptor *vertexDescriptor =
|
||||
pipelineDescriptor->vertexDescriptor()->init();
|
||||
MTL::VertexAttributeDescriptorArray *attributes =
|
||||
vertexDescriptor->attributes()->init();
|
||||
if (createInfo.vertexInput != nullptr) {
|
||||
const auto &vertexInfo = createInfo.vertexInput->getInfo();
|
||||
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
|
||||
MTL::VertexAttributeDescriptor *attribute =
|
||||
attributes->object(attr + METAL_VERTEXATTRIBUTE_OFFSET)->init();
|
||||
attribute->setBufferIndex(vertexInfo.attributes[attr].binding +
|
||||
METAL_VERTEXBUFFER_OFFSET);
|
||||
switch (vertexInfo.attributes[attr].format) {
|
||||
case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
|
||||
attribute->setFormat(MTL::VertexFormatFloat3);
|
||||
MTL::VertexDescriptor* vertexDescriptor = pipelineDescriptor->vertexDescriptor()->init();
|
||||
MTL::VertexAttributeDescriptorArray* attributes = vertexDescriptor->attributes()->init();
|
||||
if (createInfo.vertexInput != nullptr) {
|
||||
const auto& vertexInfo = createInfo.vertexInput->getInfo();
|
||||
for (size_t attr = 0; attr < vertexInfo.attributes.size(); ++attr) {
|
||||
MTL::VertexAttributeDescriptor* attribute = attributes->object(attr)->init();
|
||||
attribute->setBufferIndex(vertexInfo.attributes[attr].binding);
|
||||
switch (vertexInfo.attributes[attr].format) {
|
||||
case Gfx::SE_FORMAT_R32G32B32_SFLOAT:
|
||||
attribute->setFormat(MTL::VertexFormatFloat3);
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("TODO");
|
||||
}
|
||||
attribute->setOffset(vertexInfo.attributes[attr].offset);
|
||||
}
|
||||
|
||||
MTL::VertexBufferLayoutDescriptorArray* bufferLayout = vertexDescriptor->layouts()->init();
|
||||
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
|
||||
MTL::VertexBufferLayoutDescriptor* buffer = bufferLayout->object(binding)->init();
|
||||
buffer->setStride(vertexInfo.bindings[binding].stride);
|
||||
buffer->setStepRate(1);
|
||||
switch (vertexInfo.bindings[binding].inputRate) {
|
||||
case Gfx::SE_VERTEX_INPUT_RATE_VERTEX:
|
||||
buffer->setStepFunction(MTL::VertexStepFunctionPerVertex);
|
||||
break;
|
||||
case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE:
|
||||
buffer->setStepFunction(MTL::VertexStepFunctionPerInstance);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
|
||||
|
||||
pipelineDescriptor->setVertexFunction(createInfo.vertexShader.cast<VertexShader>()->getFunction());
|
||||
if (createInfo.fragmentShader != nullptr) {
|
||||
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
|
||||
}
|
||||
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
|
||||
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
|
||||
pipelineDescriptor->setDepthAttachmentPixelFormat(
|
||||
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
|
||||
}
|
||||
pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
|
||||
pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
|
||||
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
|
||||
pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
|
||||
|
||||
uint32 hash = pipelineDescriptor->hash();
|
||||
|
||||
if (graphicsPipelines.contains(hash)) {
|
||||
return graphicsPipelines[hash];
|
||||
}
|
||||
MTL::PrimitiveType type = MTL::PrimitiveTypeTriangle;
|
||||
switch (createInfo.topology) {
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST:
|
||||
type = MTL::PrimitiveTypePoint;
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("TODO");
|
||||
}
|
||||
attribute->setOffset(vertexInfo.attributes[attr].offset);
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST:
|
||||
type = MTL::PrimitiveTypeLine;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP:
|
||||
type = MTL::PrimitiveTypeLineStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
|
||||
type = MTL::PrimitiveTypeTriangleStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeLine;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeLineStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeTriangleStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
}
|
||||
NS::Error* error;
|
||||
graphicsPipelines[hash] = new GraphicsPipeline(
|
||||
graphics, type, graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error), std::move(createInfo.pipelineLayout));
|
||||
if (error) {
|
||||
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
MTL::VertexBufferLayoutDescriptorArray *bufferLayout =
|
||||
vertexDescriptor->layouts()->init();
|
||||
for (size_t binding = 0; binding < vertexInfo.bindings.size(); ++binding) {
|
||||
MTL::VertexBufferLayoutDescriptor *buffer =
|
||||
bufferLayout->object(binding + METAL_VERTEXBUFFER_OFFSET)->init();
|
||||
buffer->setStride(vertexInfo.bindings[binding].stride);
|
||||
buffer->setStepRate(1);
|
||||
switch (vertexInfo.bindings[binding].inputRate) {
|
||||
case Gfx::SE_VERTEX_INPUT_RATE_VERTEX:
|
||||
buffer->setStepFunction(MTL::VertexStepFunctionPerVertex);
|
||||
break;
|
||||
case Gfx::SE_VERTEX_INPUT_RATE_INSTANCE:
|
||||
buffer->setStepFunction(MTL::VertexStepFunctionPerInstance);
|
||||
break;
|
||||
}
|
||||
pipelineDescriptor->release();
|
||||
return graphicsPipelines[hash];
|
||||
}
|
||||
|
||||
PGraphicsPipeline PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
|
||||
MTL::MeshRenderPipelineDescriptor* pipelineDescriptor = MTL::MeshRenderPipelineDescriptor::alloc()->init();
|
||||
|
||||
pipelineDescriptor->setMeshFunction(createInfo.meshShader.cast<MeshShader>()->getFunction());
|
||||
if (createInfo.taskShader != nullptr) {
|
||||
pipelineDescriptor->setObjectFunction(createInfo.taskShader.cast<TaskShader>()->getFunction());
|
||||
}
|
||||
}
|
||||
pipelineDescriptor->setVertexDescriptor(vertexDescriptor);
|
||||
if (createInfo.fragmentShader != nullptr) {
|
||||
pipelineDescriptor->setFragmentFunction(createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
|
||||
}
|
||||
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() != nullptr) {
|
||||
pipelineDescriptor->setDepthAttachmentPixelFormat(
|
||||
cast(createInfo.renderPass->getLayout().depthAttachment.getTexture().cast<Texture2D>()->getFormat()));
|
||||
}
|
||||
pipelineDescriptor->setAlphaToCoverageEnabled(createInfo.multisampleState.alphaCoverageEnable);
|
||||
pipelineDescriptor->setAlphaToOneEnabled(createInfo.multisampleState.alphaToOneEnable);
|
||||
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
|
||||
pipelineDescriptor->setRasterizationEnabled(!createInfo.rasterizationState.rasterizerDiscardEnable);
|
||||
|
||||
pipelineDescriptor->setVertexFunction(
|
||||
createInfo.vertexShader.cast<VertexShader>()->getFunction());
|
||||
if (createInfo.fragmentShader != nullptr) {
|
||||
pipelineDescriptor->setFragmentFunction(
|
||||
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
|
||||
}
|
||||
pipelineDescriptor->setInputPrimitiveTopology(cast(createInfo.topology));
|
||||
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() !=
|
||||
nullptr) {
|
||||
pipelineDescriptor->setDepthAttachmentPixelFormat(
|
||||
cast(createInfo.renderPass->getLayout()
|
||||
.depthAttachment.getTexture()
|
||||
.cast<Texture2D>()
|
||||
->getFormat()));
|
||||
}
|
||||
pipelineDescriptor->setAlphaToCoverageEnabled(
|
||||
createInfo.multisampleState.alphaCoverageEnable);
|
||||
pipelineDescriptor->setAlphaToOneEnabled(
|
||||
createInfo.multisampleState.alphaToOneEnable);
|
||||
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
|
||||
pipelineDescriptor->setRasterizationEnabled(
|
||||
!createInfo.rasterizationState.rasterizerDiscardEnable);
|
||||
uint32 hash = pipelineDescriptor->hash();
|
||||
|
||||
uint32 hash = pipelineDescriptor->hash();
|
||||
if (graphicsPipelines.contains(hash)) {
|
||||
return graphicsPipelines[hash];
|
||||
}
|
||||
NS::Error* error = nullptr;
|
||||
MTL::AutoreleasedRenderPipelineReflection reflection;
|
||||
graphicsPipelines[hash] = new GraphicsPipeline(
|
||||
graphics, MTL::PrimitiveTypeTriangle,
|
||||
graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
|
||||
std::move(createInfo.pipelineLayout));
|
||||
|
||||
if (graphicsPipelines.contains(hash)) {
|
||||
if (error) {
|
||||
std::cout << error->debugDescription()->utf8String() << std::endl;
|
||||
}
|
||||
|
||||
pipelineDescriptor->release();
|
||||
return graphicsPipelines[hash];
|
||||
}
|
||||
MTL::PrimitiveType type = MTL::PrimitiveTypeTriangle;
|
||||
switch (createInfo.topology) {
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_POINT_LIST:
|
||||
type = MTL::PrimitiveTypePoint;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST:
|
||||
type = MTL::PrimitiveTypeLine;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP:
|
||||
type = MTL::PrimitiveTypeLineStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
|
||||
type = MTL::PrimitiveTypeTriangleStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeLine;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeLineStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY:
|
||||
type = MTL::PrimitiveTypeTriangleStrip;
|
||||
break;
|
||||
case Gfx::SE_PRIMITIVE_TOPOLOGY_PATCH_LIST:
|
||||
type = MTL::PrimitiveTypeTriangle;
|
||||
break;
|
||||
}
|
||||
NS::Error *error;
|
||||
graphicsPipelines[hash] = new GraphicsPipeline(
|
||||
graphics, type,
|
||||
graphics->getDevice()->newRenderPipelineState(pipelineDescriptor, &error),
|
||||
std::move(createInfo.pipelineLayout));
|
||||
if (error) {
|
||||
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding)
|
||||
<< std::endl;
|
||||
assert(false);
|
||||
}
|
||||
|
||||
pipelineDescriptor->release();
|
||||
return graphicsPipelines[hash];
|
||||
}
|
||||
|
||||
PGraphicsPipeline
|
||||
PipelineCache::createPipeline(Gfx::MeshPipelineCreateInfo createInfo) {
|
||||
MTL::MeshRenderPipelineDescriptor *pipelineDescriptor =
|
||||
MTL::MeshRenderPipelineDescriptor::alloc()->init();
|
||||
PComputePipeline PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
|
||||
PComputeShader shader = createInfo.computeShader.cast<ComputeShader>();
|
||||
uint32 hash = shader->getShaderHash();
|
||||
if (computePipelines.contains(hash)) {
|
||||
return computePipelines[hash];
|
||||
}
|
||||
|
||||
pipelineDescriptor->setMeshFunction(
|
||||
createInfo.meshShader.cast<MeshShader>()->getFunction());
|
||||
if (createInfo.taskShader != nullptr) {
|
||||
pipelineDescriptor->setObjectFunction(
|
||||
createInfo.taskShader.cast<TaskShader>()->getFunction());
|
||||
}
|
||||
if (createInfo.fragmentShader != nullptr) {
|
||||
pipelineDescriptor->setFragmentFunction(
|
||||
createInfo.fragmentShader.cast<FragmentShader>()->getFunction());
|
||||
}
|
||||
if (createInfo.renderPass->getLayout().depthAttachment.getTexture() !=
|
||||
nullptr) {
|
||||
pipelineDescriptor->setDepthAttachmentPixelFormat(
|
||||
cast(createInfo.renderPass->getLayout()
|
||||
.depthAttachment.getTexture()
|
||||
.cast<Texture2D>()
|
||||
->getFormat()));
|
||||
}
|
||||
pipelineDescriptor->setAlphaToCoverageEnabled(
|
||||
createInfo.multisampleState.alphaCoverageEnable);
|
||||
pipelineDescriptor->setAlphaToOneEnabled(
|
||||
createInfo.multisampleState.alphaToOneEnable);
|
||||
pipelineDescriptor->setRasterSampleCount(createInfo.multisampleState.samples);
|
||||
pipelineDescriptor->setRasterizationEnabled(
|
||||
!createInfo.rasterizationState.rasterizerDiscardEnable);
|
||||
|
||||
uint32 hash = pipelineDescriptor->hash();
|
||||
|
||||
if (graphicsPipelines.contains(hash)) {
|
||||
return graphicsPipelines[hash];
|
||||
}
|
||||
NS::Error *error = nullptr;
|
||||
MTL::AutoreleasedRenderPipelineReflection reflection;
|
||||
graphicsPipelines[hash] = new GraphicsPipeline(
|
||||
graphics, MTL::PrimitiveTypeTriangle,
|
||||
graphics->getDevice()->newRenderPipelineState(
|
||||
pipelineDescriptor, MTL::PipelineOptionNone, &reflection, &error),
|
||||
std::move(createInfo.pipelineLayout));
|
||||
|
||||
pipelineDescriptor->release();
|
||||
return graphicsPipelines[hash];
|
||||
}
|
||||
|
||||
PComputePipeline
|
||||
PipelineCache::createPipeline(Gfx::ComputePipelineCreateInfo createInfo) {
|
||||
PComputeShader shader = createInfo.computeShader.cast<ComputeShader>();
|
||||
uint32 hash = shader->getShaderHash();
|
||||
if (computePipelines.contains(hash)) {
|
||||
NS::Error* error;
|
||||
computePipelines[hash] = new ComputePipeline(graphics, graphics->getDevice()->newComputePipelineState(shader->getFunction(), &error),
|
||||
std::move(createInfo.pipelineLayout));
|
||||
assert(!error);
|
||||
return computePipelines[hash];
|
||||
}
|
||||
|
||||
NS::Error *error;
|
||||
computePipelines[hash] =
|
||||
new ComputePipeline(graphics,
|
||||
graphics->getDevice()->newComputePipelineState(
|
||||
shader->getFunction(), &error),
|
||||
std::move(createInfo.pipelineLayout));
|
||||
assert(!error);
|
||||
return computePipelines[hash];
|
||||
}
|
||||
|
||||
@@ -40,16 +40,10 @@ class TimestampQuery : public Gfx::TimestampQuery, public QueryPool {
|
||||
public:
|
||||
TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps);
|
||||
virtual ~TimestampQuery();
|
||||
virtual void begin() override;
|
||||
virtual void write(Gfx::SePipelineStageFlagBits stage, const std::string& name = "") override;
|
||||
virtual void end() override;
|
||||
virtual Array<Gfx::Timestamp> getResults() override;
|
||||
virtual Gfx::Timestamp getResult() override;
|
||||
|
||||
private:
|
||||
uint64 wrapping = 0;
|
||||
uint64 lastMeasure = 0;
|
||||
uint32 numTimestamps = 0;
|
||||
uint32 currentTimestamp = 0;
|
||||
Array<std::string> pendingTimestamps;
|
||||
};
|
||||
DEFINE_REF(TimestampQuery)
|
||||
|
||||
@@ -4,28 +4,23 @@
|
||||
#include "Containers/Array.h"
|
||||
#include "Enums.h"
|
||||
#include "Graphics.h"
|
||||
#include "Graphics/Query.h"
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Metal;
|
||||
|
||||
QueryPool::QueryPool(PGraphics graphics, const std::string& name)
|
||||
: graphics(graphics) {
|
||||
}
|
||||
QueryPool::QueryPool(PGraphics graphics, const std::string&) : graphics(graphics) {}
|
||||
|
||||
QueryPool::~QueryPool() { }
|
||||
QueryPool::~QueryPool() {}
|
||||
|
||||
void QueryPool::begin() {
|
||||
}
|
||||
void QueryPool::begin() {}
|
||||
|
||||
void QueryPool::end() {
|
||||
}
|
||||
void QueryPool::end() {}
|
||||
|
||||
void QueryPool::getQueryResults(Array<uint64>& results) {
|
||||
}
|
||||
void QueryPool::getQueryResults(Array<uint64>&) {}
|
||||
|
||||
OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name)
|
||||
: QueryPool(graphics, name) {}
|
||||
OcclusionQuery::OcclusionQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {}
|
||||
|
||||
OcclusionQuery::~OcclusionQuery() {}
|
||||
|
||||
@@ -41,8 +36,7 @@ Gfx::OcclusionResult OcclusionQuery::getResults() {
|
||||
};
|
||||
}
|
||||
|
||||
PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name)
|
||||
: QueryPool(graphics, name) {}
|
||||
PipelineStatisticsQuery::PipelineStatisticsQuery(PGraphics graphics, const std::string& name) : QueryPool(graphics, name) {}
|
||||
|
||||
PipelineStatisticsQuery::~PipelineStatisticsQuery() {}
|
||||
|
||||
@@ -66,21 +60,15 @@ Gfx::PipelineStatisticsResult PipelineStatisticsQuery::getResults() {
|
||||
};
|
||||
}
|
||||
|
||||
TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32 numTimestamps)
|
||||
: QueryPool(graphics, name), numTimestamps(numTimestamps) {
|
||||
}
|
||||
TimestampQuery::TimestampQuery(PGraphics graphics, const std::string& name, uint32) : QueryPool(graphics, name) {}
|
||||
|
||||
TimestampQuery::~TimestampQuery() {}
|
||||
|
||||
void TimestampQuery::begin() {
|
||||
currentTimestamp = 0;
|
||||
}
|
||||
void TimestampQuery::write(Gfx::SePipelineStageFlagBits, const std::string&) {}
|
||||
|
||||
void TimestampQuery::write(Gfx::SePipelineStageFlagBits stage, const std::string& name) {
|
||||
}
|
||||
|
||||
void TimestampQuery::end() {
|
||||
}
|
||||
|
||||
Array<Gfx::Timestamp> TimestampQuery::getResults() {
|
||||
Gfx::Timestamp TimestampQuery::getResult() {
|
||||
return Gfx::Timestamp{
|
||||
.name = "Test",
|
||||
.time = 0,
|
||||
};
|
||||
}
|
||||
@@ -25,10 +25,10 @@ Shader::~Shader() {
|
||||
|
||||
void Shader::create(const ShaderCreateInfo& createInfo) {
|
||||
auto [kernelBlob, entryPoint] = generateShader(createInfo);
|
||||
std::ofstream test("test.metal");
|
||||
test.write((char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize());
|
||||
test.close();
|
||||
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
|
||||
std::ofstream test("test.metal");
|
||||
test.write((const char*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize());
|
||||
test.close();
|
||||
NS::Error* error;
|
||||
MTL::CompileOptions* options = MTL::CompileOptions::alloc()->init();
|
||||
library = graphics->getDevice()->newLibrary(NS::String::string((char*)kernelBlob->getBufferPointer(), NS::ASCIIStringEncoding), options,
|
||||
|
||||
@@ -88,7 +88,10 @@ void TextureBase::generateMipmaps() { handle->generateMipmaps(); }
|
||||
|
||||
Texture2D::Texture2D(PGraphics graphics, const TextureCreateInfo& createInfo, MTL::Texture* existingImage)
|
||||
: Gfx::Texture2D(graphics->getFamilyMapping()),
|
||||
TextureBase(graphics, createInfo.elements > 1 ? MTL::TextureType2DArray : MTL::TextureType2D, createInfo, existingImage) {}
|
||||
TextureBase(graphics,
|
||||
createInfo.elements > 1 ? (createInfo.samples > 1 ? MTL::TextureType2DMultisampleArray : MTL::TextureType2DArray)
|
||||
: (createInfo.samples > 1 ? MTL::TextureType2DMultisample : MTL::TextureType2D),
|
||||
createInfo, existingImage) {}
|
||||
|
||||
Texture2D::~Texture2D() {}
|
||||
|
||||
|
||||
@@ -90,6 +90,10 @@ Window::Window(PGraphics graphics, const WindowCreateInfo& createInfo) : graphic
|
||||
metalLayer.drawableSize = CGSizeMake(createInfo.width, createInfo.height);
|
||||
metalWindow.contentView.layer = metalLayer;
|
||||
metalWindow.contentView.wantsLayer = YES;
|
||||
framebufferFormat = Gfx::SE_FORMAT_R8G8B8A8_UNORM;
|
||||
|
||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||
createBackBuffer();
|
||||
}
|
||||
|
||||
Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
|
||||
|
||||
@@ -533,13 +533,13 @@ void WaterRenderer::updateFFTDescriptor() {
|
||||
|
||||
computeSet = computeLayout->allocateDescriptorSet();
|
||||
computeSet->updateBuffer(0, paramsBuffer);
|
||||
computeSet->updateTexture(1, 0, Gfx::PTexture2D(spectrumTextures));
|
||||
computeSet->updateTexture(2, 0, Gfx::PTexture2D(initialSpectrumTextures));
|
||||
computeSet->updateTexture(3, 0, Gfx::PTexture2D(displacementTextures));
|
||||
computeSet->updateTexture(4, 0, Gfx::PTexture2D(slopeTextures));
|
||||
computeSet->updateTexture(5, 0, Gfx::PTexture2D(boyancyData));
|
||||
computeSet->updateBuffer(6, 0, spectrumBuffer);
|
||||
computeSet->updateSampler(7, 0, linearRepeatSampler);
|
||||
computeSet->updateTexture(1, Gfx::PTexture2D(spectrumTextures));
|
||||
computeSet->updateTexture(2, Gfx::PTexture2D(initialSpectrumTextures));
|
||||
computeSet->updateTexture(3, Gfx::PTexture2D(displacementTextures));
|
||||
computeSet->updateTexture(4, Gfx::PTexture2D(slopeTextures));
|
||||
computeSet->updateTexture(5, Gfx::PTexture2D(boyancyData));
|
||||
computeSet->updateBuffer(6, spectrumBuffer);
|
||||
computeSet->updateSampler(7, linearRepeatSampler);
|
||||
computeSet->writeChanges();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "StaticMeshVertexData.h"
|
||||
#include "Graphics.h"
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Graphics/VertexData.h"
|
||||
#include "Mesh.h"
|
||||
#include <fstream>
|
||||
|
||||
@@ -133,11 +134,13 @@ void StaticMeshVertexData::init(Gfx::PGraphics _graphics) {
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 2, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 3, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{.binding = 4, .descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER});
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 5,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
.descriptorCount = MAX_TEXCOORDS,
|
||||
});
|
||||
for(uint i = 0; i < MAX_TEXCOORDS; ++i)
|
||||
{
|
||||
descriptorLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.binding = 5 + i,
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
}
|
||||
descriptorLayout->create();
|
||||
descriptorSet = descriptorLayout->allocateDescriptorSet();
|
||||
}
|
||||
@@ -223,7 +226,7 @@ void StaticMeshVertexData::updateBuffers() {
|
||||
descriptorSet->updateBuffer(3, biTangents);
|
||||
descriptorSet->updateBuffer(4, colors);
|
||||
for (size_t i = 0; i < MAX_TEXCOORDS; ++i) {
|
||||
descriptorSet->updateBuffer(5, i, texCoords[i]);
|
||||
descriptorSet->updateBuffer(5 + i, texCoords[i]);
|
||||
}
|
||||
descriptorSet->writeChanges();
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ MeshId VertexData::allocateVertexData(uint64 numVertices) {
|
||||
return res;
|
||||
}
|
||||
|
||||
void VertexData::serializeMesh(MeshId id, uint64 numVertices, ArchiveBuffer& buffer) {
|
||||
void VertexData::serializeMesh(MeshId id, uint64, ArchiveBuffer& buffer) {
|
||||
std::unique_lock l(vertexDataLock);
|
||||
Array<Meshlet> out;
|
||||
MeshData data = meshData[id];
|
||||
|
||||
@@ -78,8 +78,8 @@ class RenderCommand : public Gfx::RenderCommand {
|
||||
virtual void setViewport(Gfx::PViewport viewport) override;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
||||
virtual void bindPipeline(Gfx::PRayTracingPipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) override;
|
||||
virtual void bindVertexBuffer(const Array<Gfx::PVertexBuffer>& buffers) override;
|
||||
virtual void bindIndexBuffer(Gfx::PIndexBuffer indexBuffer) override;
|
||||
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
@@ -114,8 +114,8 @@ class ComputeCommand : public Gfx::ComputeCommand {
|
||||
void reset();
|
||||
bool isReady();
|
||||
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets, Array<uint32> dynamicOffsets) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
|
||||
virtual void pushConstants(Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
||||
graphics(graphics), owner(owner) {
|
||||
boundResources.resize(owner->getLayout()->getBindings().size());
|
||||
for (uint32 i = 0; i < boundResources.size(); ++i) {
|
||||
boundResources[i].resize(owner->getLayout()->getBindings()[i].descriptorCount);
|
||||
if(owner->getLayout()->getBindings()[i].descriptorCount > 1) std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ DescriptorSet::~DescriptorSet() {}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
|
||||
PUniformBuffer vulkanBuffer = uniformBuffer.cast<UniformBuffer>();
|
||||
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) {
|
||||
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -192,12 +192,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBu
|
||||
.pBufferInfo = &bufferInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][0] = vulkanBuffer->getAlloc();
|
||||
boundResources[binding] = vulkanBuffer->getAlloc();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuffer) {
|
||||
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
|
||||
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) {
|
||||
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -217,12 +217,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer shaderBuff
|
||||
.pBufferInfo = &bufferInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][0] = vulkanBuffer->getAlloc();
|
||||
boundResources[binding] = vulkanBuffer->getAlloc();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer) {
|
||||
PIndexBuffer vulkanBuffer = indexBuffer.cast<IndexBuffer>();
|
||||
if (boundResources[binding][0] == vulkanBuffer->getAlloc()) {
|
||||
if (boundResources[binding] == vulkanBuffer->getAlloc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -242,38 +242,12 @@ void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PIndexBuffer indexBuffer
|
||||
.pBufferInfo = &bufferInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][0] = vulkanBuffer->getAlloc();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateBuffer(uint32_t binding, uint32 index, Gfx::PShaderBuffer shaderBuffer) {
|
||||
PShaderBuffer vulkanBuffer = shaderBuffer.cast<ShaderBuffer>();
|
||||
if (boundResources[binding][index] == vulkanBuffer->getAlloc()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bufferInfos.add(VkDescriptorBufferInfo{
|
||||
.buffer = vulkanBuffer->getHandle(),
|
||||
.offset = 0,
|
||||
.range = vulkanBuffer->getSize(),
|
||||
});
|
||||
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = nullptr,
|
||||
.dstSet = setHandle,
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = index,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
|
||||
.pBufferInfo = &bufferInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][index] = vulkanBuffer->getAlloc();
|
||||
boundResources[binding] = vulkanBuffer->getAlloc();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
|
||||
PSampler vulkanSampler = samplerState.cast<Sampler>();
|
||||
if (boundResources[binding][0] == vulkanSampler->getHandle()) {
|
||||
if (boundResources[binding] == vulkanSampler->getHandle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -294,38 +268,12 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][0] = vulkanSampler->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateSampler(uint32_t binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) {
|
||||
PSampler vulkanSampler = samplerState.cast<Sampler>();
|
||||
if (boundResources[binding][dstArrayIndex] == vulkanSampler->getHandle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
imageInfos.add(VkDescriptorImageInfo{
|
||||
.sampler = vulkanSampler->getSampler(),
|
||||
.imageView = VK_NULL_HANDLE,
|
||||
.imageLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
});
|
||||
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = nullptr,
|
||||
.dstSet = setHandle,
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = dstArrayIndex,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER,
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][dstArrayIndex] = vulkanSampler->getHandle();
|
||||
boundResources[binding] = vulkanSampler->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
||||
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
|
||||
if (boundResources[binding][0] == vulkanTexture->getHandle()) {
|
||||
if (boundResources[binding] == vulkanTexture->getHandle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -346,33 +294,7 @@ void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][0] = vulkanTexture->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) {
|
||||
TextureBase* vulkanTexture = texture.cast<TextureBase>().getHandle();
|
||||
if (boundResources[binding][dstArrayIndex] == vulkanTexture->getHandle()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// It is assumed that the image is in the correct layout
|
||||
imageInfos.add(VkDescriptorImageInfo{
|
||||
.sampler = VK_NULL_HANDLE,
|
||||
.imageView = vulkanTexture->getView(),
|
||||
.imageLayout = cast(vulkanTexture->getLayout()),
|
||||
});
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = nullptr,
|
||||
.dstSet = setHandle,
|
||||
.dstBinding = binding,
|
||||
.dstArrayElement = dstArrayIndex,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = cast(layout->getBindings()[binding].descriptorType),
|
||||
.pImageInfo = &imageInfos.back(),
|
||||
});
|
||||
|
||||
boundResources[binding][dstArrayIndex] = vulkanTexture->getHandle();
|
||||
boundResources[binding] = vulkanTexture->getHandle();
|
||||
}
|
||||
|
||||
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D> textures) {
|
||||
@@ -380,7 +302,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D>
|
||||
uint32 arrayElement = 0;
|
||||
for (auto& gfxTexture : textures) {
|
||||
TextureBase* vulkanTexture = gfxTexture.cast<TextureBase>().getHandle();
|
||||
if (boundResources[binding][arrayElement] == vulkanTexture->getHandle()) {
|
||||
if (boundResources[binding+arrayElement] == vulkanTexture->getHandle()) {
|
||||
continue;
|
||||
}
|
||||
imageInfos.add(VkDescriptorImageInfo{
|
||||
@@ -389,7 +311,7 @@ void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture2D>
|
||||
.imageLayout = cast(vulkanTexture->getLayout()),
|
||||
});
|
||||
|
||||
boundResources[binding][arrayElement] = vulkanTexture->getHandle();
|
||||
boundResources[binding+arrayElement] = vulkanTexture->getHandle();
|
||||
writeDescriptors.add(VkWriteDescriptorSet{
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.pNext = nullptr,
|
||||
@@ -408,7 +330,7 @@ void DescriptorSet::updateSamplerArray(uint32_t binding, Array<Gfx::PSampler> sa
|
||||
uint32 arrayElement = 0;
|
||||
for (auto& gfxSampler : samplers) {
|
||||
PSampler vulkanSampler = gfxSampler.cast<Sampler>();
|
||||
if (boundResources[binding][arrayElement] == vulkanSampler->getHandle()) {
|
||||
if (boundResources[binding+arrayElement] == vulkanSampler->getHandle()) {
|
||||
continue;
|
||||
}
|
||||
imageInfos.add(VkDescriptorImageInfo{
|
||||
|
||||
@@ -51,11 +51,8 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
|
||||
virtual void updateBuffer(uint32 binding, Gfx::PUniformBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, Gfx::PShaderBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, Gfx::PIndexBuffer uniformBuffer) override;
|
||||
virtual void updateBuffer(uint32 binding, uint32 index, Gfx::PShaderBuffer uniformBuffer) override;
|
||||
virtual void updateSampler(uint32 binding, Gfx::PSampler samplerState) override;
|
||||
virtual void updateSampler(uint32 binding, uint32 dstArrayIndex, Gfx::PSampler samplerState) override;
|
||||
virtual void updateTexture(uint32 binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr) override;
|
||||
virtual void updateTexture(uint32 binding, uint32 dstArrayIndex, Gfx::PTexture texture) override;
|
||||
virtual void updateTextureArray(uint32 binding, Array<Gfx::PTexture2D> texture) override;
|
||||
virtual void updateSamplerArray(uint32 binding, Array<Gfx::PSampler> samplers) override;
|
||||
virtual void updateAccelerationStructure(uint32 binding, Gfx::PTopLevelAS as) override;
|
||||
@@ -71,7 +68,7 @@ class DescriptorSet : public Gfx::DescriptorSet, public CommandBoundResource {
|
||||
// since the layout is fixed, trying to bind a texture to a buffer
|
||||
// would not work anyways, so casts should be safe
|
||||
// Array<void*> cachedData;
|
||||
Array<Array<PCommandBoundResource>> boundResources;
|
||||
Array<PCommandBoundResource> boundResources;
|
||||
VkDescriptorSet setHandle;
|
||||
PGraphics graphics;
|
||||
PDescriptorPool owner;
|
||||
|
||||
@@ -116,15 +116,16 @@ void Seele::beginCompilation(const ShaderCompilationInfo& info, SlangCompileTarg
|
||||
for (size_t i = 0; i < signature->getParameterCount(); ++i) {
|
||||
auto param = signature->getParameterByIndex(i);
|
||||
layout->addMapping(param->getName(), param->getBindingIndex());
|
||||
std::cout << param->getName() << ": " << param->getBindingIndex() << std::endl;
|
||||
}
|
||||
|
||||
// workaround
|
||||
layout->addMapping("pVertexData", 1);
|
||||
layout->addMapping("pMaterial", 4);
|
||||
layout->addMapping("pLightEnv", 3);
|
||||
layout->addMapping("pRayTracingParams", 5);
|
||||
layout->addMapping("pScene", 2);
|
||||
layout->addMapping("pWaterMaterial", 1);
|
||||
//layout->addMapping("pVertexData", 1);
|
||||
//layout->addMapping("pMaterial", 4);
|
||||
//layout->addMapping("pLightEnv", 3);
|
||||
//layout->addMapping("pRayTracingParams", 5);
|
||||
//layout->addMapping("pScene", 2);
|
||||
//layout->addMapping("pWaterMaterial", 1);
|
||||
}
|
||||
|
||||
Pair<Slang::ComPtr<slang::IBlob>, std::string> Seele::generateShader(const ShaderCreateInfo& createInfo) {
|
||||
|
||||
@@ -76,15 +76,16 @@ void Material::updateDescriptor() {
|
||||
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
layout->reset();
|
||||
set = layout->allocateDescriptorSet();
|
||||
set->updateBuffer(0, floatBuffer);
|
||||
uint32 binding = 0;
|
||||
set->updateBuffer(binding++, floatBuffer);
|
||||
for (uint32 i = 0; i < textures.size(); ++i) {
|
||||
if (textures[i] != nullptr) {
|
||||
set->updateTexture(1, i, textures[i]);
|
||||
set->updateTexture(binding++, textures[i]);
|
||||
}
|
||||
}
|
||||
for (uint32 i = 0; i < samplers.size(); ++i) {
|
||||
if (samplers[i] != nullptr) {
|
||||
set->updateSampler(2, i, samplers[i]);
|
||||
set->updateSampler(binding++, samplers[i]);
|
||||
}
|
||||
}
|
||||
set->writeChanges();
|
||||
|
||||
@@ -27,8 +27,8 @@ template <typename... Components> class ComponentSystem : public SystemBase {
|
||||
setupView((getDependencies<Components>() | ...));
|
||||
}
|
||||
virtual void update() override {}
|
||||
virtual void update(Components&... components) {}
|
||||
virtual void update(entt::entity id, Components&... components) {}
|
||||
virtual void update(Components&...) {}
|
||||
virtual void update(entt::entity, Components&...) {}
|
||||
};
|
||||
} // namespace System
|
||||
} // namespace Seele
|
||||
|
||||
@@ -28,7 +28,7 @@ GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreate
|
||||
renderGraph.addPass(new VisibilityPass(graphics, scene));
|
||||
renderGraph.addPass(new LightCullingPass(graphics, scene));
|
||||
renderGraph.addPass(new BasePass(graphics, scene));
|
||||
//renderGraph.addPass(new RayTracingPass(graphics, scene));
|
||||
renderGraph.addPass(new RayTracingPass(graphics, scene));
|
||||
renderGraph.setViewport(viewport);
|
||||
renderGraph.createRenderPass();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user