Trying to fix metal shader compilation
This commit is contained in:
Vendored
+1
@@ -164,4 +164,5 @@
|
|||||||
"lldb.showDisassembly": "auto",
|
"lldb.showDisassembly": "auto",
|
||||||
"lldb.dereferencePointers": true,
|
"lldb.dereferencePointers": true,
|
||||||
"lldb.consoleMode": "commands",
|
"lldb.consoleMode": "commands",
|
||||||
|
"cmake.generator": "Xcode",
|
||||||
}
|
}
|
||||||
+1
-1
@@ -127,7 +127,7 @@ target_compile_options(Engine PUBLIC "$<$<CONFIG:DEBUG>:-DENABLE_VALIDATION>")
|
|||||||
target_compile_options(Engine PUBLIC "$<$<CONFIG:DEBUG>:-DSEELE_DEBUG>")
|
target_compile_options(Engine PUBLIC "$<$<CONFIG:DEBUG>:-DSEELE_DEBUG>")
|
||||||
|
|
||||||
add_subdirectory(src/)
|
add_subdirectory(src/)
|
||||||
add_subdirectory(tests/)
|
#add_subdirectory(tests/)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_custom_target(dll_copy ALL
|
add_custom_target(dll_copy ALL
|
||||||
|
|||||||
@@ -42,6 +42,6 @@ struct Scene
|
|||||||
StructuredBuffer<uint32_t> primitiveIndices;
|
StructuredBuffer<uint32_t> primitiveIndices;
|
||||||
StructuredBuffer<uint32_t> vertexIndices;
|
StructuredBuffer<uint32_t> vertexIndices;
|
||||||
};
|
};
|
||||||
|
layout(set=2)
|
||||||
ParameterBlock<Scene> pScene;
|
ParameterBlock<Scene> pScene;
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ void MaterialLoader::import(MaterialImportArgs args, PMaterialAsset asset)
|
|||||||
json j;
|
json j;
|
||||||
jsonstream >> j;
|
jsonstream >> j;
|
||||||
std::string materialName = j["name"].get<std::string>() + "Material";
|
std::string materialName = j["name"].get<std::string>() + "Material";
|
||||||
Gfx::ODescriptorLayout layout = graphics->createDescriptorLayout(materialName + "Layout");
|
Gfx::ODescriptorLayout layout = graphics->createDescriptorLayout("pMaterial");
|
||||||
//Shader file needs to conform to the slang standard, which prohibits _
|
//Shader file needs to conform to the slang standard, which prohibits _
|
||||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end());
|
materialName.erase(std::remove(materialName.begin(), materialName.end(), '_'), materialName.end());
|
||||||
materialName.erase(std::remove(materialName.begin(), materialName.end(), '-'), materialName.end());
|
materialName.erase(std::remove(materialName.begin(), materialName.end(), '-'), materialName.end());
|
||||||
|
|||||||
@@ -160,4 +160,4 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset)
|
|||||||
|
|
||||||
|
|
||||||
////co_return;
|
////co_return;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -271,4 +271,4 @@ int main() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
using namespace Seele::Gfx;
|
using namespace Seele::Gfx;
|
||||||
|
|
||||||
DescriptorLayout::DescriptorLayout(const std::string& name) : setIndex(0), name(name) {}
|
DescriptorLayout::DescriptorLayout(const std::string& name) : name(name) {}
|
||||||
|
|
||||||
DescriptorLayout::DescriptorLayout(const DescriptorLayout& other) {
|
DescriptorLayout::DescriptorLayout(const DescriptorLayout& other) {
|
||||||
descriptorBindings.resize(other.descriptorBindings.size());
|
descriptorBindings.resize(other.descriptorBindings.size());
|
||||||
@@ -62,12 +62,20 @@ PipelineLayout::PipelineLayout(PPipelineLayout baseLayout) {
|
|||||||
|
|
||||||
PipelineLayout::~PipelineLayout() {}
|
PipelineLayout::~PipelineLayout() {}
|
||||||
|
|
||||||
void PipelineLayout::addDescriptorLayout(uint32 setIndex, PDescriptorLayout layout) {
|
void PipelineLayout::addDescriptorLayout(PDescriptorLayout layout) {
|
||||||
if (descriptorSetLayouts.size() <= setIndex) {
|
descriptorSetLayouts[layout->getName()] = layout;
|
||||||
descriptorSetLayouts.resize(setIndex + 1);
|
|
||||||
}
|
|
||||||
descriptorSetLayouts[setIndex] = layout;
|
|
||||||
layout->setIndex = setIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PipelineLayout::addPushConstants(const SePushConstantRange& pushConstant) { pushConstants.add(pushConstant); }
|
void PipelineLayout::addPushConstants(const SePushConstantRange& pushConstant) { pushConstants.add(pushConstant); }
|
||||||
|
|
||||||
|
void PipelineLayout::addMapping(Map<std::string, uint32> mapping)
|
||||||
|
{
|
||||||
|
for(const auto& [name, index] : mapping)
|
||||||
|
{
|
||||||
|
if(parameterMapping.contains(name))
|
||||||
|
{
|
||||||
|
assert(parameterMapping[name] == index);
|
||||||
|
}
|
||||||
|
parameterMapping[name] = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,14 +31,12 @@ public:
|
|||||||
PDescriptorSet allocateDescriptorSet();
|
PDescriptorSet allocateDescriptorSet();
|
||||||
virtual void create() = 0;
|
virtual void create() = 0;
|
||||||
constexpr const Array<DescriptorBinding>& getBindings() const { return descriptorBindings; }
|
constexpr const Array<DescriptorBinding>& getBindings() const { return descriptorBindings; }
|
||||||
constexpr uint32 getSetIndex() const { return setIndex; }
|
|
||||||
constexpr void setSetIndex(uint32 _setIndex) { setIndex = _setIndex; }
|
|
||||||
constexpr uint32 getHash() const { return hash; }
|
constexpr uint32 getHash() const { return hash; }
|
||||||
|
constexpr const std::string& getName() const { return name; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Array<DescriptorBinding> descriptorBindings;
|
Array<DescriptorBinding> descriptorBindings;
|
||||||
ODescriptorPool pool;
|
ODescriptorPool pool;
|
||||||
uint32 setIndex;
|
|
||||||
std::string name;
|
std::string name;
|
||||||
uint32 hash = 0;
|
uint32 hash = 0;
|
||||||
friend class PipelineLayout;
|
friend class PipelineLayout;
|
||||||
@@ -71,7 +69,7 @@ public:
|
|||||||
virtual void updateTextureArray(uint32_t binding, Array<PTexture> texture) = 0;
|
virtual void updateTextureArray(uint32_t binding, Array<PTexture> texture) = 0;
|
||||||
bool operator<(PDescriptorSet other);
|
bool operator<(PDescriptorSet other);
|
||||||
|
|
||||||
constexpr uint32 getSetIndex() const { return layout->getSetIndex(); }
|
constexpr PDescriptorLayout getLayout() const { return layout; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PDescriptorLayout layout;
|
PDescriptorLayout layout;
|
||||||
@@ -84,13 +82,17 @@ public:
|
|||||||
PipelineLayout(PPipelineLayout baseLayout);
|
PipelineLayout(PPipelineLayout baseLayout);
|
||||||
virtual ~PipelineLayout();
|
virtual ~PipelineLayout();
|
||||||
virtual void create() = 0;
|
virtual void create() = 0;
|
||||||
void addDescriptorLayout(uint32 setIndex, PDescriptorLayout layout);
|
void addDescriptorLayout(PDescriptorLayout layout);
|
||||||
void addPushConstants(const SePushConstantRange& pushConstants);
|
void addPushConstants(const SePushConstantRange& pushConstants);
|
||||||
constexpr uint32 getHash() const { return layoutHash; }
|
constexpr uint32 getHash() const { return layoutHash; }
|
||||||
|
constexpr const Map<std::string, PDescriptorLayout>& getLayouts() const { return descriptorSetLayouts; }
|
||||||
|
constexpr uint32 findParameter(const std::string& name) const { return parameterMapping[name]; }
|
||||||
|
void addMapping(Map<std::string, uint32> mapping);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32 layoutHash = 0;
|
uint32 layoutHash = 0;
|
||||||
Array<PDescriptorLayout> descriptorSetLayouts;
|
Map<std::string, PDescriptorLayout> descriptorSetLayouts;
|
||||||
|
Map<std::string, uint32> parameterMapping;
|
||||||
Array<SePushConstantRange> pushConstants;
|
Array<SePushConstantRange> pushConstants;
|
||||||
};
|
};
|
||||||
DEFINE_REF(PipelineLayout)
|
DEFINE_REF(PipelineLayout)
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ struct ShaderBufferCreateInfo
|
|||||||
uint8 dynamic = 0;
|
uint8 dynamic = 0;
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
DECLARE_NAME_REF(Gfx, PipelineLayout)
|
||||||
struct ShaderCreateInfo
|
struct ShaderCreateInfo
|
||||||
{
|
{
|
||||||
std::string mainModule;
|
std::string mainModule;
|
||||||
@@ -123,6 +124,7 @@ struct ShaderCreateInfo
|
|||||||
std::string entryPoint;
|
std::string entryPoint;
|
||||||
Array<Pair<const char*, const char*>> typeParameter;
|
Array<Pair<const char*, const char*>> typeParameter;
|
||||||
Map<const char*, const char*> defines;
|
Map<const char*, const char*> defines;
|
||||||
|
Gfx::PPipelineLayout rootSignature;
|
||||||
};
|
};
|
||||||
struct VertexInputBinding
|
struct VertexInputBinding
|
||||||
{
|
{
|
||||||
@@ -218,7 +220,7 @@ struct LegacyPipelineCreateInfo
|
|||||||
PVertexShader vertexShader;
|
PVertexShader vertexShader;
|
||||||
PFragmentShader fragmentShader;
|
PFragmentShader fragmentShader;
|
||||||
PRenderPass renderPass;
|
PRenderPass renderPass;
|
||||||
OPipelineLayout pipelineLayout;
|
PPipelineLayout pipelineLayout;
|
||||||
MultisampleState multisampleState;
|
MultisampleState multisampleState;
|
||||||
RasterizationState rasterizationState;
|
RasterizationState rasterizationState;
|
||||||
DepthStencilState depthStencilState;
|
DepthStencilState depthStencilState;
|
||||||
@@ -235,7 +237,7 @@ struct MeshPipelineCreateInfo
|
|||||||
PMeshShader meshShader;
|
PMeshShader meshShader;
|
||||||
PFragmentShader fragmentShader;
|
PFragmentShader fragmentShader;
|
||||||
PRenderPass renderPass;
|
PRenderPass renderPass;
|
||||||
OPipelineLayout pipelineLayout;
|
PPipelineLayout pipelineLayout;
|
||||||
MultisampleState multisampleState;
|
MultisampleState multisampleState;
|
||||||
RasterizationState rasterizationState;
|
RasterizationState rasterizationState;
|
||||||
DepthStencilState depthStencilState;
|
DepthStencilState depthStencilState;
|
||||||
@@ -248,11 +250,11 @@ struct MeshPipelineCreateInfo
|
|||||||
struct ComputePipelineCreateInfo
|
struct ComputePipelineCreateInfo
|
||||||
{
|
{
|
||||||
Gfx::PComputeShader computeShader;
|
Gfx::PComputeShader computeShader;
|
||||||
Gfx::OPipelineLayout pipelineLayout;
|
Gfx::PPipelineLayout pipelineLayout;
|
||||||
ComputePipelineCreateInfo();
|
ComputePipelineCreateInfo();
|
||||||
ComputePipelineCreateInfo(ComputePipelineCreateInfo&& rhs) = default;
|
ComputePipelineCreateInfo(ComputePipelineCreateInfo&& rhs) = default;
|
||||||
ComputePipelineCreateInfo& operator=(ComputePipelineCreateInfo&& rhs) = default;
|
ComputePipelineCreateInfo& operator=(ComputePipelineCreateInfo&& rhs) = default;
|
||||||
~ComputePipelineCreateInfo();
|
~ComputePipelineCreateInfo();
|
||||||
};
|
};
|
||||||
} // namespace Gfx
|
} // namespace Gfx
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "Graphics/Command.h"
|
#include "Graphics/Command.h"
|
||||||
#include "Metal/MTLBlitCommandEncoder.hpp"
|
#include "Metal/MTLBlitCommandEncoder.hpp"
|
||||||
|
#include "Metal/MTLCaptureManager.hpp"
|
||||||
#include "Metal/MTLCommandBuffer.hpp"
|
#include "Metal/MTLCommandBuffer.hpp"
|
||||||
#include "Metal/MTLComputeCommandEncoder.hpp"
|
#include "Metal/MTLComputeCommandEncoder.hpp"
|
||||||
#include "Metal/MTLRenderCommandEncoder.hpp"
|
#include "Metal/MTLRenderCommandEncoder.hpp"
|
||||||
@@ -16,6 +17,7 @@ DECLARE_REF(RenderCommand)
|
|||||||
DECLARE_REF(Graphics)
|
DECLARE_REF(Graphics)
|
||||||
DECLARE_REF(IndexBuffer)
|
DECLARE_REF(IndexBuffer)
|
||||||
DECLARE_REF(GraphicsPipeline)
|
DECLARE_REF(GraphicsPipeline)
|
||||||
|
DECLARE_REF(ComputePipeline)
|
||||||
class Command {
|
class Command {
|
||||||
public:
|
public:
|
||||||
Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer);
|
Command(PGraphics graphics, MTL::CommandBuffer* cmdBuffer);
|
||||||
@@ -85,6 +87,7 @@ public:
|
|||||||
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
|
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PComputePipeline boundPipeline;
|
||||||
MTL::CommandBuffer* commandBuffer;
|
MTL::CommandBuffer* commandBuffer;
|
||||||
MTL::ComputeCommandEncoder* encoder;
|
MTL::ComputeCommandEncoder* encoder;
|
||||||
std::string name;
|
std::string name;
|
||||||
@@ -123,4 +126,4 @@ private:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(IOCommandQueue)
|
DEFINE_REF(IOCommandQueue)
|
||||||
} // namespace Metal
|
} // namespace Metal
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "Graphics/Enums.h"
|
#include "Graphics/Enums.h"
|
||||||
#include "Graphics/Graphics.h"
|
#include "Graphics/Graphics.h"
|
||||||
#include "Graphics/Resources.h"
|
#include "Graphics/Resources.h"
|
||||||
|
#include "Metal/MTLCaptureManager.hpp"
|
||||||
#include "Pipeline.h"
|
#include "Pipeline.h"
|
||||||
#include "Resources.h"
|
#include "Resources.h"
|
||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
@@ -77,10 +78,11 @@ void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline pipeline) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
|
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet) {
|
||||||
encoder->setVertexBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, descriptorSet->getSetIndex());
|
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(descriptorSet->getLayout()->getName());
|
||||||
encoder->setFragmentBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, descriptorSet->getSetIndex());
|
encoder->setVertexBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
||||||
encoder->setMeshBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, descriptorSet->getSetIndex());
|
encoder->setFragmentBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
||||||
encoder->setObjectBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, descriptorSet->getSetIndex());
|
encoder->setMeshBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
||||||
|
encoder->setObjectBuffer(descriptorSet.cast<DescriptorSet>()->getBuffer(), 0, parameterIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
|
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets) {
|
||||||
@@ -135,13 +137,44 @@ void ComputeCommand::end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
|
void ComputeCommand::bindPipeline(Gfx::PComputePipeline pipeline) {
|
||||||
encoder->setComputePipelineState(pipeline.cast<ComputePipeline>()->getHandle());
|
boundPipeline = pipeline.cast<ComputePipeline>();
|
||||||
|
encoder->setComputePipelineState(boundPipeline->getHandle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet set) {
|
||||||
auto metalSet = set.cast<DescriptorSet>();
|
auto metalSet = set.cast<DescriptorSet>();
|
||||||
metalSet->bind();
|
metalSet->bind();
|
||||||
encoder->setBuffer(metalSet->getBuffer(), 0, set->getSetIndex());
|
uint32 parameterIndex = boundPipeline->getPipelineLayout()->findParameter(set->getLayout()->getName());
|
||||||
|
encoder->setBuffer(metalSet->getBuffer(), 0, parameterIndex);
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) {
|
||||||
@@ -157,7 +190,7 @@ void ComputeCommand::pushConstants(Gfx::PPipelineLayout, Gfx::SeShaderStageFlags
|
|||||||
|
|
||||||
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
|
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) {
|
||||||
// TODO
|
// TODO
|
||||||
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 32));
|
encoder->dispatchThreadgroups(MTL::Size(threadX, threadY, threadZ), MTL::Size(32, 32, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
|
CommandQueue::CommandQueue(PGraphics graphics) : graphics(graphics) {
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ public:
|
|||||||
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState);
|
virtual void updateSampler(uint32_t binding, Gfx::PSampler samplerState);
|
||||||
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr);
|
virtual void updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler sampler = nullptr);
|
||||||
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture);
|
virtual void updateTextureArray(uint32_t binding, Array<Gfx::PTexture> texture);
|
||||||
virtual bool operator<(Gfx::PDescriptorSet other);
|
|
||||||
|
|
||||||
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
|
constexpr bool isCurrentlyBound() const { return bindCount > 0; }
|
||||||
constexpr bool isCurrentlyInUse() const { return currentlyInUse; }
|
constexpr bool isCurrentlyInUse() const { return currentlyInUse; }
|
||||||
@@ -58,12 +57,14 @@ public:
|
|||||||
constexpr void free() { currentlyInUse = false; }
|
constexpr void free() { currentlyInUse = false; }
|
||||||
|
|
||||||
constexpr MTL::Buffer* getBuffer() const { return buffer; }
|
constexpr MTL::Buffer* getBuffer() const { return buffer; }
|
||||||
|
constexpr const Array<MTL::Resource*>& getBoundResources() const { return boundResources; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PGraphics graphics;
|
PGraphics graphics;
|
||||||
PDescriptorPool owner;
|
PDescriptorPool owner;
|
||||||
MTL::Buffer* buffer;
|
MTL::Buffer* buffer;
|
||||||
MTL::ArgumentEncoder* encoder;
|
MTL::ArgumentEncoder* encoder;
|
||||||
|
Array<MTL::Resource*> boundResources;
|
||||||
uint32 bindCount;
|
uint32 bindCount;
|
||||||
bool currentlyInUse;
|
bool currentlyInUse;
|
||||||
};
|
};
|
||||||
@@ -80,4 +81,4 @@ private:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(PipelineLayout)
|
DEFINE_REF(PipelineLayout)
|
||||||
} // namespace Metal
|
} // namespace Metal
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ DescriptorSet::DescriptorSet(PGraphics graphics, PDescriptorPool owner)
|
|||||||
if (owner->getArguments()->count() == 0) {
|
if (owner->getArguments()->count() == 0) {
|
||||||
buffer = graphics->getDevice()->newBuffer(0, MTL::ResourceOptionCPUCacheModeDefault);
|
buffer = graphics->getDevice()->newBuffer(0, MTL::ResourceOptionCPUCacheModeDefault);
|
||||||
} else {
|
} else {
|
||||||
|
boundResources.resize(owner->getArguments()->count());
|
||||||
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
|
encoder = graphics->getDevice()->newArgumentEncoder(owner->getArguments());
|
||||||
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
|
buffer = graphics->getDevice()->newBuffer(encoder->encodedLength(), MTL::ResourceOptionCPUCacheModeDefault);
|
||||||
encoder->setArgumentBuffer(buffer, 0);
|
encoder->setArgumentBuffer(buffer, 0);
|
||||||
@@ -135,10 +136,12 @@ void DescriptorSet::writeChanges() {}
|
|||||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
|
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PUniformBuffer uniformBuffer) {
|
||||||
PUniformBuffer metalBuffer = uniformBuffer.cast<UniformBuffer>();
|
PUniformBuffer metalBuffer = uniformBuffer.cast<UniformBuffer>();
|
||||||
encoder->setBuffer(metalBuffer->getHandle(), 0, binding);
|
encoder->setBuffer(metalBuffer->getHandle(), 0, binding);
|
||||||
|
boundResources[binding] = metalBuffer->getHandle();
|
||||||
}
|
}
|
||||||
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) {
|
void DescriptorSet::updateBuffer(uint32_t binding, Gfx::PShaderBuffer uniformBuffer) {
|
||||||
PShaderBuffer metalBuffer = uniformBuffer.cast<ShaderBuffer>();
|
PShaderBuffer metalBuffer = uniformBuffer.cast<ShaderBuffer>();
|
||||||
encoder->setBuffer(metalBuffer->getHandle(), 0, binding);
|
encoder->setBuffer(metalBuffer->getHandle(), 0, binding);
|
||||||
|
boundResources[binding] = metalBuffer->getHandle();
|
||||||
}
|
}
|
||||||
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
|
void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState) {
|
||||||
PSampler sampler = samplerState.cast<Sampler>();
|
PSampler sampler = samplerState.cast<Sampler>();
|
||||||
@@ -147,30 +150,26 @@ void DescriptorSet::updateSampler(uint32_t binding, Gfx::PSampler samplerState)
|
|||||||
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
void DescriptorSet::updateTexture(uint32_t binding, Gfx::PTexture texture, Gfx::PSampler samplerState) {
|
||||||
PTextureBase base = texture.cast<TextureBase>();
|
PTextureBase base = texture.cast<TextureBase>();
|
||||||
encoder->setTexture(base->getTexture(), binding);
|
encoder->setTexture(base->getTexture(), binding);
|
||||||
if (samplerState != nullptr) {
|
boundResources[binding] = base->getTexture();
|
||||||
PSampler sampler = samplerState.cast<Sampler>();
|
|
||||||
encoder->setSamplerState(sampler->getHandle(), binding);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
|
void DescriptorSet::updateTextureArray(uint32_t binding, Array<Gfx::PTexture> array) {
|
||||||
for (auto& t : array) {
|
for (auto& t : array) {
|
||||||
PTextureBase metalTexture = t.cast<TextureBase>();
|
PTextureBase metalTexture = t.cast<TextureBase>();
|
||||||
encoder->setTexture(metalTexture->getTexture(), binding++);
|
encoder->setTexture(metalTexture->getTexture(), binding);
|
||||||
|
boundResources[binding++] = metalTexture->getTexture();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DescriptorSet::operator<(Gfx::PDescriptorSet other) { return this < other.getHandle(); }
|
|
||||||
|
|
||||||
PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
|
PipelineLayout::PipelineLayout(PGraphics graphics, Gfx::PPipelineLayout baseLayout)
|
||||||
: Gfx::PipelineLayout(baseLayout), graphics(graphics) {}
|
: Gfx::PipelineLayout(baseLayout), graphics(graphics) {}
|
||||||
|
|
||||||
PipelineLayout::~PipelineLayout() {}
|
PipelineLayout::~PipelineLayout() {}
|
||||||
|
|
||||||
void PipelineLayout::create() {
|
void PipelineLayout::create() {
|
||||||
for (auto& set : descriptorSetLayouts) {
|
for (auto& [_, set] : descriptorSetLayouts) {
|
||||||
set->create();
|
set->create();
|
||||||
uint32 setHash = set->getHash();
|
uint32 setHash = set->getHash();
|
||||||
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
layoutHash = CRC::Calculate(&setHash, sizeof(uint32), CRC::CRC_32(), layoutHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ DECLARE_REF(PipelineLayout)
|
|||||||
DECLARE_REF(Graphics)
|
DECLARE_REF(Graphics)
|
||||||
class GraphicsPipeline : public Gfx::GraphicsPipeline {
|
class GraphicsPipeline : public Gfx::GraphicsPipeline {
|
||||||
public:
|
public:
|
||||||
GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline, Gfx::OPipelineLayout createInfo);
|
GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline, Gfx::PPipelineLayout createInfo);
|
||||||
virtual ~GraphicsPipeline();
|
virtual ~GraphicsPipeline();
|
||||||
constexpr MTL::RenderPipelineState* getHandle() const { return state; }
|
constexpr MTL::RenderPipelineState* getHandle() const { return state; }
|
||||||
constexpr MTL::PrimitiveType getPrimitive() const { return primitiveType; }
|
constexpr MTL::PrimitiveType getPrimitive() const { return primitiveType; }
|
||||||
@@ -27,7 +27,7 @@ private:
|
|||||||
DEFINE_REF(GraphicsPipeline)
|
DEFINE_REF(GraphicsPipeline)
|
||||||
class ComputePipeline : public Gfx::ComputePipeline {
|
class ComputePipeline : public Gfx::ComputePipeline {
|
||||||
public:
|
public:
|
||||||
ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline, Gfx::OPipelineLayout);
|
ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline, Gfx::PPipelineLayout);
|
||||||
virtual ~ComputePipeline();
|
virtual ~ComputePipeline();
|
||||||
constexpr MTL::ComputePipelineState* getHandle() const { return state; }
|
constexpr MTL::ComputePipelineState* getHandle() const { return state; }
|
||||||
|
|
||||||
@@ -37,4 +37,4 @@ private:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(ComputePipeline)
|
DEFINE_REF(ComputePipeline)
|
||||||
} // namespace Metal
|
} // namespace Metal
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ VertexInput::VertexInput(VertexInputStateCreateInfo createInfo) : Gfx::VertexInp
|
|||||||
VertexInput::~VertexInput() {}
|
VertexInput::~VertexInput() {}
|
||||||
|
|
||||||
GraphicsPipeline::GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline,
|
GraphicsPipeline::GraphicsPipeline(PGraphics graphics, MTL::PrimitiveType primitive, MTL::RenderPipelineState* pipeline,
|
||||||
Gfx::OPipelineLayout createInfo)
|
Gfx::PPipelineLayout layout)
|
||||||
: Gfx::GraphicsPipeline(std::move(createInfo)), graphics(graphics), state(pipeline), primitiveType(primitive) {}
|
: Gfx::GraphicsPipeline(layout), graphics(graphics), state(pipeline), primitiveType(primitive) {}
|
||||||
|
|
||||||
GraphicsPipeline::~GraphicsPipeline() {}
|
GraphicsPipeline::~GraphicsPipeline() {}
|
||||||
|
|
||||||
ComputePipeline::ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline,
|
ComputePipeline::ComputePipeline(PGraphics graphics, MTL::ComputePipelineState* pipeline,
|
||||||
Gfx::OPipelineLayout createInfo)
|
Gfx::PPipelineLayout layout)
|
||||||
: Gfx::ComputePipeline(std::move(createInfo)), graphics(graphics), state(pipeline) {}
|
: Gfx::ComputePipeline(layout), graphics(graphics), state(pipeline) {}
|
||||||
|
|
||||||
ComputePipeline::~ComputePipeline() {}
|
ComputePipeline::~ComputePipeline() {}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Graphics/slang-compile.h"
|
#include "Graphics/slang-compile.h"
|
||||||
#include "Metal/MTLDevice.hpp"
|
#include "Metal/MTLDevice.hpp"
|
||||||
#include "Metal/MTLLibrary.hpp"
|
#include "Metal/MTLLibrary.hpp"
|
||||||
|
#include "Descriptor.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <metal_irconverter/metal_irconverter.h>
|
#include <metal_irconverter/metal_irconverter.h>
|
||||||
@@ -24,16 +25,75 @@ Shader::~Shader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Shader::create(const ShaderCreateInfo& createInfo) {
|
void Shader::create(const ShaderCreateInfo& createInfo) {
|
||||||
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_DXIL);
|
Map<std::string, uint32> test;
|
||||||
|
Slang::ComPtr<slang::IBlob> kernelBlob = generateShader(createInfo, SLANG_DXIL, test);
|
||||||
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
|
hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32());
|
||||||
IRCompiler* pCompiler = IRCompilerCreate();
|
IRCompiler* pCompiler = IRCompilerCreate();
|
||||||
|
IRCompilerSetMinimumGPUFamily(pCompiler, IRGPUFamilyMetal3);
|
||||||
|
IRCompilerIgnoreRootSignature(pCompiler, true);
|
||||||
IRCompilerSetEntryPointName(pCompiler, "main");
|
IRCompilerSetEntryPointName(pCompiler, "main");
|
||||||
|
|
||||||
IRObject* pDXIL = IRObjectCreateFromDXIL((const uint8*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(),
|
IRObject* pDXIL = IRObjectCreateFromDXIL((const uint8*)kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(),
|
||||||
IRBytecodeOwnershipNone);
|
IRBytecodeOwnershipNone);
|
||||||
|
IRVersionedRootSignatureDescriptor descriptor;
|
||||||
// Compile DXIL to Metal IR:
|
descriptor.version = IRRootSignatureVersion_1_1;
|
||||||
|
Map<std::string, Gfx::PDescriptorLayout> layouts =createInfo.rootSignature->getLayouts();
|
||||||
|
descriptor.desc_1_1.NumParameters = layouts.size();
|
||||||
|
descriptor.desc_1_1.NumStaticSamplers = 0;
|
||||||
|
descriptor.desc_1_1.pStaticSamplers = nullptr;
|
||||||
|
Array<IRRootParameter1> parameters;
|
||||||
|
// each layout has an array for its bindings
|
||||||
|
Array<Array<IRDescriptorRange1>> ranges;
|
||||||
|
for(const auto& [name, layout] : layouts)
|
||||||
|
{
|
||||||
|
uint32 textureReg = 0; // SRV
|
||||||
|
uint32 samplerReg = 0; // Sampler
|
||||||
|
uint32 uavReg = 0; // UAV
|
||||||
|
uint32 constantReg = 0; // CBV
|
||||||
|
auto& bindingRanges = ranges.add();
|
||||||
|
for(auto binding : layout->getBindings())
|
||||||
|
{
|
||||||
|
IRDescriptorRangeType type;
|
||||||
|
uint32 reg = 0;
|
||||||
|
switch(binding.descriptorType)
|
||||||
|
{
|
||||||
|
case Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
|
||||||
|
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER:
|
||||||
|
type = IRDescriptorRangeTypeSRV;
|
||||||
|
reg = textureReg++;
|
||||||
|
break;
|
||||||
|
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||||
|
case Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
|
||||||
|
type = IRDescriptorRangeTypeCBV;
|
||||||
|
reg = constantReg++;
|
||||||
|
break;
|
||||||
|
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
|
||||||
|
case Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE:
|
||||||
|
type = IRDescriptorRangeTypeUAV;
|
||||||
|
reg = uavReg++;
|
||||||
|
break;
|
||||||
|
default: throw std::logic_error("Not implemented");
|
||||||
|
};
|
||||||
|
bindingRanges.add() = IRDescriptorRange1{
|
||||||
|
.BaseShaderRegister = reg,
|
||||||
|
.NumDescriptors = binding.descriptorCount,
|
||||||
|
.RangeType = type,
|
||||||
|
.RegisterSpace = createInfo.rootSignature->findParameter(name),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
parameters.add() = IRRootParameter1{
|
||||||
|
.ParameterType = IRRootParameterTypeDescriptorTable,
|
||||||
|
.DescriptorTable = IRRootDescriptorTable1{ .NumDescriptorRanges = (uint32)(bindingRanges.size()), bindingRanges.data() },
|
||||||
|
.ShaderVisibility = IRShaderVisibilityAll,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
IRError* signatureError = nullptr;
|
||||||
|
descriptor.desc_1_1.NumParameters = parameters.size();
|
||||||
|
descriptor.desc_1_1.pParameters = parameters.data();
|
||||||
|
IRRootSignature* rootSignature = IRRootSignatureCreateFromDescriptor(&descriptor, &signatureError);
|
||||||
|
assert(rootSignature);
|
||||||
|
IRCompilerSetGlobalRootSignature(pCompiler, rootSignature);
|
||||||
|
// Compile DXIL to Metal IR:
|
||||||
IRError* pError = nullptr;
|
IRError* pError = nullptr;
|
||||||
IRObject* pOutIR = IRCompilerAllocCompileAndLink(pCompiler, NULL, pDXIL, &pError);
|
IRObject* pOutIR = IRCompilerAllocCompileAndLink(pCompiler, NULL, pDXIL, &pError);
|
||||||
|
|
||||||
@@ -63,7 +123,13 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
|
|||||||
IRMetalLibBinary* pMetallib = IRMetalLibBinaryCreate();
|
IRMetalLibBinary* pMetallib = IRMetalLibBinaryCreate();
|
||||||
IRObjectGetMetalLibBinary(pOutIR, irStage, pMetallib);
|
IRObjectGetMetalLibBinary(pOutIR, irStage, pMetallib);
|
||||||
dispatch_data_t data = IRMetalLibGetBytecodeData(pMetallib);
|
dispatch_data_t data = IRMetalLibGetBytecodeData(pMetallib);
|
||||||
|
|
||||||
|
IRShaderReflection* reflection = IRShaderReflectionCreate();
|
||||||
|
IRObjectGetReflection(pOutIR, irStage, reflection);
|
||||||
|
std::cout << " NumRes: " << IRShaderReflectionGetResourceCount(reflection) << std::endl;
|
||||||
|
std::cout << IRShaderReflectionAllocStringAndSerialize(reflection) << std::endl;
|
||||||
|
IRShaderReflectionDestroy(reflection);
|
||||||
|
|
||||||
// Store the metallib to custom format or disk, or use to create a MTLLibrary.
|
// Store the metallib to custom format or disk, or use to create a MTLLibrary.
|
||||||
NS::Error* error;
|
NS::Error* error;
|
||||||
library = graphics->getDevice()->newLibrary(data, &error);
|
library = graphics->getDevice()->newLibrary(data, &error);
|
||||||
@@ -78,4 +144,4 @@ void Shader::create(const ShaderCreateInfo& createInfo) {
|
|||||||
IRCompilerDestroy(pCompiler);
|
IRCompilerDestroy(pCompiler);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 Shader::getShaderHash() const { return hash; }
|
uint32 Shader::getShaderHash() const { return hash; }
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ TextureBase::TextureBase(PGraphics graphics, MTL::TextureType type,
|
|||||||
|
|
||||||
descriptor->release();
|
descriptor->release();
|
||||||
}
|
}
|
||||||
if(createInfo.sourceData.data != nullptr)
|
// if(createInfo.sourceData.data != nullptr)
|
||||||
{
|
// {
|
||||||
MTL::Region region(0, 0, 0, width, height, depth);
|
// MTL::Region region(0, 0, 0, width, height, depth);
|
||||||
texture->replaceRegion(region, 0, createInfo.sourceData.data, createInfo.sourceData.size / (depth / height));
|
// texture->replaceRegion(region, 0, createInfo.sourceData.data, createInfo.sourceData.size / (depth * height));
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureBase::~TextureBase() {
|
TextureBase::~TextureBase() {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ private:
|
|||||||
CAMetalLayer* metalLayer;
|
CAMetalLayer* metalLayer;
|
||||||
CA::MetalDrawable* drawable;
|
CA::MetalDrawable* drawable;
|
||||||
OTexture2D backBuffer;
|
OTexture2D backBuffer;
|
||||||
|
MTL::CaptureDescriptor* capture = nullptr;
|
||||||
|
|
||||||
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
std::function<void(KeyCode, InputAction, KeyModifier)> keyCallback;
|
||||||
std::function<void(double, double)> mouseMoveCallback;
|
std::function<void(double, double)> mouseMoveCallback;
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "Foundation/NSAutoreleasePool.hpp"
|
#include "Foundation/NSAutoreleasePool.hpp"
|
||||||
|
#include "Foundation/NSString.hpp"
|
||||||
|
#include "Graphics/Enums.h"
|
||||||
#include "Graphics/Initializer.h"
|
#include "Graphics/Initializer.h"
|
||||||
#include "Graphics/Metal/Enums.h"
|
#include "Graphics/Metal/Enums.h"
|
||||||
#include "Graphics/Texture.h"
|
#include "Graphics/Texture.h"
|
||||||
|
#include "Metal/MTLCaptureManager.hpp"
|
||||||
#include "Metal/MTLTexture.hpp"
|
#include "Metal/MTLTexture.hpp"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
#include <fmt/core.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace Seele;
|
using namespace Seele;
|
||||||
@@ -13,6 +17,8 @@ using namespace Seele::Metal;
|
|||||||
|
|
||||||
double currentFrameDelta = 0;
|
double currentFrameDelta = 0;
|
||||||
double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
|
double Gfx::getCurrentFrameDelta() { return currentFrameDelta; }
|
||||||
|
uint32 currentFrameIndex = 0;
|
||||||
|
uint32 Gfx::getCurrentFrameIndex() { return currentFrameIndex; }
|
||||||
|
|
||||||
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) {
|
void glfwKeyCallback(GLFWwindow* handle, int key, int, int action, int modifier) {
|
||||||
if (key == -1) {
|
if (key == -1) {
|
||||||
@@ -88,6 +94,17 @@ Window::~Window() { glfwDestroyWindow(static_cast<GLFWwindow*>(windowHandle)); }
|
|||||||
void Window::pollInput() { glfwPollEvents(); }
|
void Window::pollInput() { glfwPollEvents(); }
|
||||||
|
|
||||||
void Window::beginFrame() {
|
void Window::beginFrame() {
|
||||||
|
auto captureManager = MTL::CaptureManager::sharedCaptureManager();
|
||||||
|
capture = MTL::CaptureDescriptor::alloc()->init();
|
||||||
|
capture->setCaptureObject((__bridge id<MTLDevice>)graphics->getDevice());
|
||||||
|
capture->setDestination(MTL::CaptureDestinationDeveloperTools);
|
||||||
|
capture->setOutputURL(NS::URL::fileURLWithPath(NS::String::string(fmt::format("frame{0}.trace", Gfx::getCurrentFrameIndex()).c_str(), NS::ASCIIStringEncoding)));
|
||||||
|
NS::Error* error;
|
||||||
|
captureManager->startCapture(capture, &error);
|
||||||
|
if(error)
|
||||||
|
{
|
||||||
|
std::cout << error->localizedDescription()->cString(NS::ASCIIStringEncoding) << std::endl;
|
||||||
|
}
|
||||||
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
drawable = (__bridge CA::MetalDrawable*)[metalLayer nextDrawable];
|
||||||
createBackBuffer();
|
createBackBuffer();
|
||||||
}
|
}
|
||||||
@@ -95,6 +112,8 @@ void Window::beginFrame() {
|
|||||||
void Window::endFrame() {
|
void Window::endFrame() {
|
||||||
graphics->getQueue()->getCommands()->present(drawable);
|
graphics->getQueue()->getCommands()->present(drawable);
|
||||||
graphics->getQueue()->submitCommands();
|
graphics->getQueue()->submitCommands();
|
||||||
|
MTL::CaptureManager::sharedCaptureManager()->stopCapture();
|
||||||
|
currentFrameIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::onWindowCloseEvent() {}
|
void Window::onWindowCloseEvent() {}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ VertexInput::~VertexInput()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsPipeline::GraphicsPipeline(OPipelineLayout layout)
|
GraphicsPipeline::GraphicsPipeline(PPipelineLayout layout)
|
||||||
: layout(std::move(layout))
|
: layout(layout)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,8 +26,8 @@ PPipelineLayout GraphicsPipeline::getPipelineLayout() const
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComputePipeline::ComputePipeline(OPipelineLayout layout)
|
ComputePipeline::ComputePipeline(PPipelineLayout layout)
|
||||||
: layout(std::move(layout))
|
: layout(layout)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,23 +18,23 @@ private:
|
|||||||
class GraphicsPipeline
|
class GraphicsPipeline
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GraphicsPipeline(OPipelineLayout layout);
|
GraphicsPipeline(PPipelineLayout layout);
|
||||||
virtual ~GraphicsPipeline();
|
virtual ~GraphicsPipeline();
|
||||||
PPipelineLayout getPipelineLayout() const;
|
PPipelineLayout getPipelineLayout() const;
|
||||||
protected:
|
protected:
|
||||||
OPipelineLayout layout;
|
PPipelineLayout layout;
|
||||||
};
|
};
|
||||||
DEFINE_REF(GraphicsPipeline)
|
DEFINE_REF(GraphicsPipeline)
|
||||||
|
|
||||||
class ComputePipeline
|
class ComputePipeline
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ComputePipeline(OPipelineLayout layout);
|
ComputePipeline(PPipelineLayout layout);
|
||||||
virtual ~ComputePipeline();
|
virtual ~ComputePipeline();
|
||||||
PPipelineLayout getPipelineLayout() const;
|
PPipelineLayout getPipelineLayout() const;
|
||||||
protected:
|
protected:
|
||||||
OPipelineLayout layout;
|
PPipelineLayout layout;
|
||||||
};
|
};
|
||||||
DEFINE_REF(ComputePipeline)
|
DEFINE_REF(ComputePipeline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,6 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
|||||||
: RenderPass(graphics, scene)
|
: RenderPass(graphics, scene)
|
||||||
, descriptorSets(6)
|
, descriptorSets(6)
|
||||||
{
|
{
|
||||||
if (graphics->supportMeshShading())
|
|
||||||
{
|
|
||||||
graphics->getShaderCompiler()->registerRenderPass("BasePass", "MeshletBasePass", true, true, "BasePass", true, true, "MeshletBasePass");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
graphics->getShaderCompiler()->registerRenderPass("BasePass", "LegacyBasePass", true, true, "BasePass");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BasePass::~BasePass()
|
BasePass::~BasePass()
|
||||||
@@ -100,11 +92,6 @@ void BasePass::render()
|
|||||||
|
|
||||||
Gfx::ORenderCommand command = graphics->createRenderCommand("BaseRender");
|
Gfx::ORenderCommand command = graphics->createRenderCommand("BaseRender");
|
||||||
command->setViewport(viewport);
|
command->setViewport(viewport);
|
||||||
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(basePassLayout);
|
|
||||||
layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
|
||||||
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
|
|
||||||
layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout());
|
|
||||||
layout->create();
|
|
||||||
|
|
||||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
||||||
assert(collection != nullptr);
|
assert(collection != nullptr);
|
||||||
@@ -114,7 +101,7 @@ void BasePass::render()
|
|||||||
pipelineInfo.taskShader = collection->taskShader;
|
pipelineInfo.taskShader = collection->taskShader;
|
||||||
pipelineInfo.meshShader = collection->meshShader;
|
pipelineInfo.meshShader = collection->meshShader;
|
||||||
pipelineInfo.fragmentShader = collection->fragmentShader;
|
pipelineInfo.fragmentShader = collection->fragmentShader;
|
||||||
pipelineInfo.pipelineLayout = std::move(layout);
|
pipelineInfo.pipelineLayout = collection->pipelineLayout;
|
||||||
pipelineInfo.renderPass = renderPass;
|
pipelineInfo.renderPass = renderPass;
|
||||||
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
||||||
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
||||||
@@ -127,7 +114,7 @@ void BasePass::render()
|
|||||||
Gfx::LegacyPipelineCreateInfo pipelineInfo;
|
Gfx::LegacyPipelineCreateInfo pipelineInfo;
|
||||||
pipelineInfo.vertexShader = collection->vertexShader;
|
pipelineInfo.vertexShader = collection->vertexShader;
|
||||||
pipelineInfo.fragmentShader = collection->fragmentShader;
|
pipelineInfo.fragmentShader = collection->fragmentShader;
|
||||||
pipelineInfo.pipelineLayout = std::move(layout);
|
pipelineInfo.pipelineLayout = collection->pipelineLayout;
|
||||||
pipelineInfo.renderPass = renderPass;
|
pipelineInfo.renderPass = renderPass;
|
||||||
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
||||||
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
||||||
@@ -174,21 +161,30 @@ void BasePass::publishOutputs()
|
|||||||
{
|
{
|
||||||
basePassLayout = graphics->createPipelineLayout();
|
basePassLayout = graphics->createPipelineLayout();
|
||||||
|
|
||||||
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
|
basePassLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, scene->getLightEnvironment()->getDescriptorLayout());
|
basePassLayout->addDescriptorLayout(scene->getLightEnvironment()->getDescriptorLayout());
|
||||||
|
|
||||||
lightCullingLayout = graphics->createDescriptorLayout("BasePassLightCulling");
|
lightCullingLayout = graphics->createDescriptorLayout("pLightCullingData");
|
||||||
// oLightIndexList
|
// oLightIndexList
|
||||||
lightCullingLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
lightCullingLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
// oLightGrid
|
// oLightGrid
|
||||||
lightCullingLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
|
lightCullingLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
|
||||||
lightCullingLayout->create();
|
lightCullingLayout->create();
|
||||||
|
|
||||||
basePassLayout->addDescriptorLayout(INDEX_LIGHT_CULLING, lightCullingLayout);
|
basePassLayout->addDescriptorLayout(lightCullingLayout);
|
||||||
colorAttachment = Gfx::RenderTargetAttachment(viewport,
|
colorAttachment = Gfx::RenderTargetAttachment(viewport,
|
||||||
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||||
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||||
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
|
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
|
||||||
|
|
||||||
|
if (graphics->supportMeshShading())
|
||||||
|
{
|
||||||
|
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "MeshletBasePass", true, true, "BasePass", true, true, "MeshletBasePass");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "LegacyBasePass", true, true, "BasePass");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasePass::createRenderPass()
|
void BasePass::createRenderPass()
|
||||||
|
|||||||
@@ -119,8 +119,8 @@ void DebugPass::createRenderPass()
|
|||||||
};
|
};
|
||||||
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
|
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
|
||||||
|
|
||||||
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
pipelineLayout = graphics->createPipelineLayout();
|
||||||
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
|
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
pipelineLayout->create();
|
pipelineLayout->create();
|
||||||
|
|
||||||
ShaderCreateInfo createInfo = {
|
ShaderCreateInfo createInfo = {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ private:
|
|||||||
Gfx::OVertexShader vertexShader;
|
Gfx::OVertexShader vertexShader;
|
||||||
Gfx::OFragmentShader fragmentShader;
|
Gfx::OFragmentShader fragmentShader;
|
||||||
Gfx::PGraphicsPipeline pipeline;
|
Gfx::PGraphicsPipeline pipeline;
|
||||||
|
Gfx::OPipelineLayout pipelineLayout;
|
||||||
};
|
};
|
||||||
DEFINE_REF(DebugPass)
|
DEFINE_REF(DebugPass)
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
|||||||
, descriptorSets(3)
|
, descriptorSets(3)
|
||||||
{
|
{
|
||||||
depthPrepassLayout = graphics->createPipelineLayout();
|
depthPrepassLayout = graphics->createPipelineLayout();
|
||||||
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
|
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
if (graphics->supportMeshShading())
|
if (graphics->supportMeshShading())
|
||||||
{
|
{
|
||||||
graphics->getShaderCompiler()->registerRenderPass("DepthPass", "MeshletBasePass", false, false, "", true, true, "MeshletBasePass");
|
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletBasePass", false, false, "", true, true, "MeshletBasePass");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
graphics->getShaderCompiler()->registerRenderPass("DepthPass", "LegacyBasePass");
|
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyBasePass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,12 +68,7 @@ void DepthPrepass::render()
|
|||||||
|
|
||||||
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
|
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
|
||||||
command->setViewport(viewport);
|
command->setViewport(viewport);
|
||||||
Gfx::OPipelineLayout layout = graphics->createPipelineLayout(depthPrepassLayout);
|
|
||||||
//layout->addDescriptorLayout(INDEX_MATERIAL, materialData.material->getDescriptorLayout());
|
|
||||||
layout->addDescriptorLayout(INDEX_VERTEX_DATA, vertexData->getVertexDataLayout());
|
|
||||||
layout->addDescriptorLayout(INDEX_SCENE_DATA, vertexData->getInstanceDataLayout());
|
|
||||||
layout->create();
|
|
||||||
|
|
||||||
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
const Gfx::ShaderCollection* collection = graphics->getShaderCompiler()->findShaders(id);
|
||||||
assert(collection != nullptr);
|
assert(collection != nullptr);
|
||||||
if(graphics->supportMeshShading())
|
if(graphics->supportMeshShading())
|
||||||
@@ -82,7 +77,7 @@ void DepthPrepass::render()
|
|||||||
pipelineInfo.taskShader = collection->taskShader;
|
pipelineInfo.taskShader = collection->taskShader;
|
||||||
pipelineInfo.meshShader = collection->meshShader;
|
pipelineInfo.meshShader = collection->meshShader;
|
||||||
pipelineInfo.fragmentShader = collection->fragmentShader;
|
pipelineInfo.fragmentShader = collection->fragmentShader;
|
||||||
pipelineInfo.pipelineLayout = std::move(layout);
|
pipelineInfo.pipelineLayout = collection->pipelineLayout;
|
||||||
pipelineInfo.renderPass = renderPass;
|
pipelineInfo.renderPass = renderPass;
|
||||||
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS;
|
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS;
|
||||||
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
pipelineInfo.multisampleState.samples = viewport->getSamples();
|
||||||
@@ -94,7 +89,7 @@ void DepthPrepass::render()
|
|||||||
Gfx::LegacyPipelineCreateInfo pipelineInfo;
|
Gfx::LegacyPipelineCreateInfo pipelineInfo;
|
||||||
pipelineInfo.vertexShader = collection->vertexShader;
|
pipelineInfo.vertexShader = collection->vertexShader;
|
||||||
pipelineInfo.fragmentShader = collection->fragmentShader;
|
pipelineInfo.fragmentShader = collection->fragmentShader;
|
||||||
pipelineInfo.pipelineLayout = std::move(layout);
|
pipelineInfo.pipelineLayout = collection->pipelineLayout;
|
||||||
pipelineInfo.renderPass = renderPass;
|
pipelineInfo.renderPass = renderPass;
|
||||||
//pipelineInfo.depthStencilState.depthWriteEnable = false;
|
//pipelineInfo.depthStencilState.depthWriteEnable = false;
|
||||||
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ void LightCullingPass::publishOutputs()
|
|||||||
dispatchParamsSet->updateBuffer(1, frustumBuffer);
|
dispatchParamsSet->updateBuffer(1, frustumBuffer);
|
||||||
dispatchParamsSet->writeChanges();
|
dispatchParamsSet->writeChanges();
|
||||||
|
|
||||||
cullingDescriptorLayout = graphics->createDescriptorLayout("CullingLayout");
|
cullingDescriptorLayout = graphics->createDescriptorLayout("pCullingParams");
|
||||||
|
|
||||||
//DepthTexture
|
//DepthTexture
|
||||||
cullingDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
cullingDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
||||||
@@ -116,18 +116,24 @@ void LightCullingPass::publishOutputs()
|
|||||||
|
|
||||||
lightEnv = scene->getLightEnvironment();
|
lightEnv = scene->getLightEnvironment();
|
||||||
|
|
||||||
Gfx::OPipelineLayout cullingLayout = graphics->createPipelineLayout();
|
cullingLayout = graphics->createPipelineLayout();
|
||||||
cullingLayout->addDescriptorLayout(0, viewParamsLayout);
|
cullingLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
cullingLayout->addDescriptorLayout(1, dispatchParamsLayout);
|
cullingLayout->addDescriptorLayout(dispatchParamsLayout);
|
||||||
cullingLayout->addDescriptorLayout(2, cullingDescriptorLayout);
|
cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
|
||||||
cullingLayout->addDescriptorLayout(3, lightEnv->getDescriptorLayout());
|
cullingLayout->addDescriptorLayout(lightEnv->getDescriptorLayout());
|
||||||
|
Map<std::string, uint32> mapping;
|
||||||
|
mapping["pViewParams"] = 0;
|
||||||
|
mapping["pDispatchParams"] = 1;
|
||||||
|
cullingLayout->addMapping(mapping);
|
||||||
cullingLayout->create();
|
cullingLayout->create();
|
||||||
|
|
||||||
ShaderCreateInfo createInfo;
|
ShaderCreateInfo createInfo = {
|
||||||
createInfo.name = "Culling";
|
.name = "Culling",
|
||||||
createInfo.additionalModules.add("LightCulling");
|
.additionalModules = {"LightCulling"},
|
||||||
createInfo.mainModule = "LightCulling";
|
.mainModule = "LightCulling",
|
||||||
createInfo.entryPoint = "cullLights";
|
.entryPoint = "cullLights",
|
||||||
|
.rootSignature = cullingLayout,
|
||||||
|
};
|
||||||
cullingShader = graphics->createComputeShader(createInfo);
|
cullingShader = graphics->createComputeShader(createInfo);
|
||||||
|
|
||||||
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
||||||
@@ -202,18 +208,25 @@ void LightCullingPass::setupFrustums()
|
|||||||
dispatchParams.numThreads = numThreads;
|
dispatchParams.numThreads = numThreads;
|
||||||
dispatchParams.numThreadGroups = numThreadGroups;
|
dispatchParams.numThreadGroups = numThreadGroups;
|
||||||
|
|
||||||
dispatchParamsLayout = graphics->createDescriptorLayout("FrustumLayout");
|
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
|
||||||
dispatchParamsLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
dispatchParamsLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
dispatchParamsLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
dispatchParamsLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
Gfx::OPipelineLayout frustumLayout = graphics->createPipelineLayout();
|
frustumLayout = graphics->createPipelineLayout();
|
||||||
frustumLayout->addDescriptorLayout(0, viewParamsLayout);
|
frustumLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
frustumLayout->addDescriptorLayout(1, dispatchParamsLayout);
|
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
|
||||||
|
Map<std::string, uint32> mapping;
|
||||||
|
mapping["pViewParams"] = 0;
|
||||||
|
mapping["pDispatchParams"] = 1;
|
||||||
|
frustumLayout->addMapping(mapping);
|
||||||
frustumLayout->create();
|
frustumLayout->create();
|
||||||
ShaderCreateInfo createInfo;
|
ShaderCreateInfo createInfo = {
|
||||||
createInfo.name = "Frustum";
|
.name = "Frustum",
|
||||||
createInfo.additionalModules.add("ComputeFrustums");
|
.additionalModules = {"ComputeFrustums"},
|
||||||
createInfo.mainModule = "ComputeFrustums";
|
.mainModule = "ComputeFrustums",
|
||||||
createInfo.entryPoint = "computeFrustums";
|
.entryPoint = "computeFrustums",
|
||||||
|
.rootSignature = frustumLayout,
|
||||||
|
};
|
||||||
|
std::cout << "Compiling frustumShader" << std::endl;
|
||||||
frustumShader = graphics->createComputeShader(createInfo);
|
frustumShader = graphics->createComputeShader(createInfo);
|
||||||
|
|
||||||
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
Gfx::ComputePipelineCreateInfo pipelineInfo;
|
||||||
@@ -256,4 +269,4 @@ void LightCullingPass::setupFrustums()
|
|||||||
graphics->executeCommands(std::move(commands));
|
graphics->executeCommands(std::move(commands));
|
||||||
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
frustumBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||||
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ private:
|
|||||||
Gfx::PDescriptorSet dispatchParamsSet;
|
Gfx::PDescriptorSet dispatchParamsSet;
|
||||||
Gfx::OComputeShader frustumShader;
|
Gfx::OComputeShader frustumShader;
|
||||||
Gfx::PComputePipeline frustumPipeline;
|
Gfx::PComputePipeline frustumPipeline;
|
||||||
|
Gfx::OPipelineLayout frustumLayout;
|
||||||
|
|
||||||
PLightEnvironment lightEnv;
|
PLightEnvironment lightEnv;
|
||||||
Gfx::PTexture2D depthAttachment;
|
Gfx::PTexture2D depthAttachment;
|
||||||
@@ -62,6 +63,7 @@ private:
|
|||||||
Gfx::ODescriptorLayout cullingDescriptorLayout;
|
Gfx::ODescriptorLayout cullingDescriptorLayout;
|
||||||
Gfx::OComputeShader cullingShader;
|
Gfx::OComputeShader cullingShader;
|
||||||
Gfx::PComputePipeline cullingPipeline;
|
Gfx::PComputePipeline cullingPipeline;
|
||||||
|
Gfx::OPipelineLayout cullingLayout;
|
||||||
};
|
};
|
||||||
DEFINE_REF(LightCullingPass)
|
DEFINE_REF(LightCullingPass)
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene)
|
|||||||
, scene(scene)
|
, scene(scene)
|
||||||
{
|
{
|
||||||
|
|
||||||
viewParamsLayout = graphics->createDescriptorLayout("ViewLayout");
|
viewParamsLayout = graphics->createDescriptorLayout("pViewParams");
|
||||||
viewParamsLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
viewParamsLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
UniformBufferCreateInfo uniformInitializer = {
|
UniformBufferCreateInfo uniformInitializer = {
|
||||||
.sourceData = {
|
.sourceData = {
|
||||||
@@ -57,4 +57,4 @@ void RenderPass::setViewport(Gfx::PViewport _viewport)
|
|||||||
{
|
{
|
||||||
viewport = _viewport;
|
viewport = _viewport;
|
||||||
publishOutputs();
|
publishOutputs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,10 +74,10 @@ void SkyboxRenderPass::endFrame()
|
|||||||
|
|
||||||
void SkyboxRenderPass::publishOutputs()
|
void SkyboxRenderPass::publishOutputs()
|
||||||
{
|
{
|
||||||
skyboxDataLayout = graphics->createDescriptorLayout("SkyboxDescLayout");
|
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
|
||||||
skyboxDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
skyboxDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
skyboxDataLayout->create();
|
skyboxDataLayout->create();
|
||||||
textureLayout = graphics->createDescriptorLayout();
|
textureLayout = graphics->createDescriptorLayout("pSkyboxTextures");
|
||||||
textureLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
textureLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
||||||
textureLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
textureLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
|
||||||
textureLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
textureLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
||||||
@@ -122,10 +122,10 @@ void SkyboxRenderPass::createRenderPass()
|
|||||||
createInfo.entryPoint = "fragmentMain";
|
createInfo.entryPoint = "fragmentMain";
|
||||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||||
|
|
||||||
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
pipelineLayout = graphics->createPipelineLayout();
|
||||||
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
|
pipelineLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
pipelineLayout->addDescriptorLayout(1, skyboxDataLayout);
|
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
|
||||||
pipelineLayout->addDescriptorLayout(2, textureLayout);
|
pipelineLayout->addDescriptorLayout(textureLayout);
|
||||||
pipelineLayout->create();
|
pipelineLayout->create();
|
||||||
|
|
||||||
Gfx::LegacyPipelineCreateInfo gfxInfo;
|
Gfx::LegacyPipelineCreateInfo gfxInfo;
|
||||||
@@ -133,7 +133,7 @@ void SkyboxRenderPass::createRenderPass()
|
|||||||
gfxInfo.fragmentShader = fragmentShader;
|
gfxInfo.fragmentShader = fragmentShader;
|
||||||
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
|
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
|
||||||
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||||
gfxInfo.pipelineLayout = std::move(pipelineLayout);
|
gfxInfo.pipelineLayout = pipelineLayout;
|
||||||
gfxInfo.renderPass = renderPass;
|
gfxInfo.renderPass = renderPass;
|
||||||
gfxInfo.multisampleState.samples = viewport->getSamples();
|
gfxInfo.multisampleState.samples = viewport->getSamples();
|
||||||
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ private:
|
|||||||
Gfx::PDescriptorSet textureSet;
|
Gfx::PDescriptorSet textureSet;
|
||||||
Gfx::OVertexShader vertexShader;
|
Gfx::OVertexShader vertexShader;
|
||||||
Gfx::OFragmentShader fragmentShader;
|
Gfx::OFragmentShader fragmentShader;
|
||||||
|
Gfx::OPipelineLayout pipelineLayout;
|
||||||
Gfx::PGraphicsPipeline pipeline;
|
Gfx::PGraphicsPipeline pipeline;
|
||||||
Gfx::OSampler skyboxSampler;
|
Gfx::OSampler skyboxSampler;
|
||||||
struct SkyboxData
|
struct SkyboxData
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ void TextPass::render()
|
|||||||
command->bindDescriptor({generalSet, resource.textureArraySet});
|
command->bindDescriptor({generalSet, resource.textureArraySet});
|
||||||
//command->bindVertexBuffer({resource.vertexBuffer});
|
//command->bindVertexBuffer({resource.vertexBuffer});
|
||||||
|
|
||||||
command->pushConstants(layoutRef, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData);
|
command->pushConstants(pipelineLayout, Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(TextData), &resource.textData);
|
||||||
//command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
|
//command->draw(4, static_cast<uint32>(resource.vertexBuffer->getNumVertices()), 0, 0);
|
||||||
}
|
}
|
||||||
commands.add(std::move(command));
|
commands.add(std::move(command));
|
||||||
@@ -120,12 +120,12 @@ void TextPass::createRenderPass()
|
|||||||
createInfo.name = "TextFragment";
|
createInfo.name = "TextFragment";
|
||||||
createInfo.entryPoint = "fragmentMain";
|
createInfo.entryPoint = "fragmentMain";
|
||||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||||
generalLayout = graphics->createDescriptorLayout("TextGeneral");
|
generalLayout = graphics->createDescriptorLayout("pRender");
|
||||||
generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
||||||
generalLayout->create();
|
generalLayout->create();
|
||||||
|
|
||||||
textureArrayLayout = graphics->createDescriptorLayout("TextTextureArray");
|
textureArrayLayout = graphics->createDescriptorLayout("pGlyphTextures");
|
||||||
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
|
textureArrayLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE, Gfx::SE_IMAGE_VIEW_TYPE_2D_ARRAY, 256, Gfx::SE_DESCRIPTOR_BINDING_VARIABLE_DESCRIPTOR_COUNT_BIT);
|
||||||
textureArrayLayout->create();
|
textureArrayLayout->create();
|
||||||
|
|
||||||
@@ -149,10 +149,9 @@ void TextPass::createRenderPass()
|
|||||||
generalSet->updateSampler(1, glyphSampler);
|
generalSet->updateSampler(1, glyphSampler);
|
||||||
generalSet->writeChanges();
|
generalSet->writeChanges();
|
||||||
|
|
||||||
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
pipelineLayout = graphics->createPipelineLayout();
|
||||||
layoutRef = pipelineLayout;
|
pipelineLayout->addDescriptorLayout(generalLayout);
|
||||||
pipelineLayout->addDescriptorLayout(0, generalLayout);
|
pipelineLayout->addDescriptorLayout(textureArrayLayout);
|
||||||
pipelineLayout->addDescriptorLayout(1, textureArrayLayout);
|
|
||||||
pipelineLayout->addPushConstants({
|
pipelineLayout->addPushConstants({
|
||||||
.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
|
||||||
.offset = 0,
|
.offset = 0,
|
||||||
@@ -169,7 +168,7 @@ void TextPass::createRenderPass()
|
|||||||
pipelineInfo.vertexShader = vertexShader;
|
pipelineInfo.vertexShader = vertexShader;
|
||||||
pipelineInfo.fragmentShader = fragmentShader;
|
pipelineInfo.fragmentShader = fragmentShader;
|
||||||
pipelineInfo.renderPass = renderPass;
|
pipelineInfo.renderPass = renderPass;
|
||||||
pipelineInfo.pipelineLayout = std::move(pipelineLayout);
|
pipelineInfo.pipelineLayout = pipelineLayout;
|
||||||
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
|
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
|
||||||
pipelineInfo.colorBlend.attachmentCount = 1;
|
pipelineInfo.colorBlend.attachmentCount = 1;
|
||||||
pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true;
|
pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true;
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ private:
|
|||||||
|
|
||||||
Gfx::OVertexShader vertexShader;
|
Gfx::OVertexShader vertexShader;
|
||||||
Gfx::OFragmentShader fragmentShader;
|
Gfx::OFragmentShader fragmentShader;
|
||||||
Gfx::PPipelineLayout layoutRef;
|
Gfx::OPipelineLayout pipelineLayout;
|
||||||
Gfx::PGraphicsPipeline pipeline;
|
Gfx::PGraphicsPipeline pipeline;
|
||||||
Array<TextRender> texts;
|
Array<TextRender> texts;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ void UIPass::createRenderPass()
|
|||||||
createInfo.entryPoint = "fragmentMain";
|
createInfo.entryPoint = "fragmentMain";
|
||||||
fragmentShader = graphics->createFragmentShader(createInfo);
|
fragmentShader = graphics->createFragmentShader(createInfo);
|
||||||
|
|
||||||
descriptorLayout = graphics->createDescriptorLayout("UIDescriptorLayout");
|
descriptorLayout = graphics->createDescriptorLayout("pParams");
|
||||||
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
|
||||||
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
@@ -140,7 +140,7 @@ void UIPass::createRenderPass()
|
|||||||
descriptorSet->writeChanges();
|
descriptorSet->writeChanges();
|
||||||
|
|
||||||
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
|
||||||
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
|
pipelineLayout->addDescriptorLayout(descriptorLayout);
|
||||||
pipelineLayout->create();
|
pipelineLayout->create();
|
||||||
|
|
||||||
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
|
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ private:
|
|||||||
Gfx::OVertexShader vertexShader;
|
Gfx::OVertexShader vertexShader;
|
||||||
Gfx::OFragmentShader fragmentShader;
|
Gfx::OFragmentShader fragmentShader;
|
||||||
Gfx::PGraphicsPipeline pipeline;
|
Gfx::PGraphicsPipeline pipeline;
|
||||||
|
Gfx::OPipelineLayout pipelineLayout;
|
||||||
|
|
||||||
Array<UI::RenderElementStyle> renderElements;
|
Array<UI::RenderElementStyle> renderElements;
|
||||||
Array<Gfx::PTexture> usedTextures;
|
Array<Gfx::PTexture> usedTextures;
|
||||||
|
|||||||
@@ -33,9 +33,10 @@ void ShaderCompiler::registerVertexData(VertexData* vd)
|
|||||||
compile();
|
compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderCompiler::registerRenderPass(std::string name, std::string mainFile, bool useMaterials, bool hasFragmentShader, std::string fragmentFile, bool useMeshShading, bool hasTaskShader, std::string taskFile)
|
void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout, std::string name, std::string mainFile, bool useMaterials, bool hasFragmentShader, std::string fragmentFile, bool useMeshShading, bool hasTaskShader, std::string taskFile)
|
||||||
{
|
{
|
||||||
passes[name] = PassConfig{
|
passes[name] = PassConfig{
|
||||||
|
.baseLayout = layout,
|
||||||
.taskFile = taskFile,
|
.taskFile = taskFile,
|
||||||
.mainFile = mainFile,
|
.mainFile = mainFile,
|
||||||
.fragmentFile = fragmentFile,
|
.fragmentFile = fragmentFile,
|
||||||
@@ -52,57 +53,71 @@ void ShaderCompiler::compile()
|
|||||||
{
|
{
|
||||||
for (const auto& [name, pass] : passes)
|
for (const auto& [name, pass] : passes)
|
||||||
{
|
{
|
||||||
ShaderPermutation permutation;
|
ShaderPermutation permutation;
|
||||||
if (pass.useMeshShading)
|
if (pass.useMeshShading)
|
||||||
{
|
{
|
||||||
permutation.setMeshFile(pass.mainFile);
|
permutation.setMeshFile(pass.mainFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
permutation.setVertexFile(pass.mainFile);
|
permutation.setVertexFile(pass.mainFile);
|
||||||
}
|
}
|
||||||
if (pass.hasFragmentShader)
|
if (pass.hasFragmentShader)
|
||||||
{
|
{
|
||||||
permutation.setFragmentFile(pass.fragmentFile);
|
permutation.setFragmentFile(pass.fragmentFile);
|
||||||
}
|
}
|
||||||
if (pass.hasTaskShader)
|
if (pass.hasTaskShader)
|
||||||
{
|
{
|
||||||
permutation.setTaskFile(pass.taskFile);
|
permutation.setTaskFile(pass.taskFile);
|
||||||
}
|
}
|
||||||
for (const auto& [vdName, vd] : vertexData)
|
for (const auto& [vdName, vd] : vertexData)
|
||||||
{
|
{
|
||||||
permutation.setVertexData(vd->getTypeName());
|
permutation.setVertexData(vd->getTypeName());
|
||||||
if (pass.useMaterial)
|
if (pass.useMaterial)
|
||||||
{
|
{
|
||||||
for (const auto& [matName, mat] : materials)
|
for (const auto& [matName, mat] : materials)
|
||||||
{
|
{
|
||||||
|
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout);
|
||||||
|
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||||
|
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||||
|
layout->addDescriptorLayout(mat->getDescriptorLayout());
|
||||||
permutation.setMaterial(mat->getName());
|
permutation.setMaterial(mat->getName());
|
||||||
createShaders(permutation);
|
createShaders(permutation, std::move(layout));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
createShaders(permutation);
|
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout);
|
||||||
|
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||||
|
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||||
|
Map<std::string, uint32> mapping;
|
||||||
|
mapping["pViewParams"] = 1;
|
||||||
|
mapping["pVertexData"] = 2;
|
||||||
|
mapping["pScene"] = 3;
|
||||||
|
layout->addMapping(mapping);
|
||||||
|
createShaders(permutation, std::move(layout));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderCompiler::createShaders(ShaderPermutation permutation)
|
void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout)
|
||||||
{
|
{
|
||||||
std::scoped_lock lock(shadersLock);
|
std::scoped_lock lock(shadersLock);
|
||||||
PermutationId perm = PermutationId(permutation);
|
PermutationId perm = PermutationId(permutation);
|
||||||
if (shaders.contains(perm))
|
if (shaders.contains(perm))
|
||||||
return;
|
return;
|
||||||
ShaderCollection collection;
|
ShaderCollection collection;
|
||||||
|
collection.pipelineLayout = std::move(layout);
|
||||||
|
|
||||||
ShaderCreateInfo createInfo;
|
ShaderCreateInfo createInfo;
|
||||||
createInfo.name = fmt::format("Material {0}", permutation.materialName);
|
createInfo.name = fmt::format("Material {0}", permutation.materialName);
|
||||||
|
createInfo.rootSignature = collection.pipelineLayout;
|
||||||
if (std::strlen(permutation.materialName) > 0)
|
if (std::strlen(permutation.materialName) > 0)
|
||||||
{
|
{
|
||||||
createInfo.additionalModules.add(permutation.materialName);
|
createInfo.additionalModules.add(permutation.materialName);
|
||||||
createInfo.typeParameter.add(Pair<const char*, const char*>("IMaterial", permutation.materialName));
|
createInfo.typeParameter.add(Pair<const char*, const char*>("IMaterial", permutation.materialName));
|
||||||
}
|
}
|
||||||
createInfo.typeParameter.add({ Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) });
|
createInfo.typeParameter.add({ Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) });
|
||||||
createInfo.additionalModules.add(permutation.vertexDataName);
|
createInfo.additionalModules.add(permutation.vertexDataName);
|
||||||
createInfo.additionalModules.add(permutation.vertexMeshFile);
|
createInfo.additionalModules.add(permutation.vertexMeshFile);
|
||||||
@@ -141,4 +156,4 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation)
|
|||||||
collection.fragmentShader = graphics->createFragmentShader(createInfo);
|
collection.fragmentShader = graphics->createFragmentShader(createInfo);
|
||||||
}
|
}
|
||||||
shaders[perm] = std::move(collection);
|
shaders[perm] = std::move(collection);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ struct PermutationId
|
|||||||
};
|
};
|
||||||
struct ShaderCollection
|
struct ShaderCollection
|
||||||
{
|
{
|
||||||
|
OPipelineLayout pipelineLayout;
|
||||||
OVertexShader vertexShader;
|
OVertexShader vertexShader;
|
||||||
OTaskShader taskShader;
|
OTaskShader taskShader;
|
||||||
OMeshShader meshShader;
|
OMeshShader meshShader;
|
||||||
@@ -137,7 +138,8 @@ public:
|
|||||||
const ShaderCollection* findShaders(PermutationId id) const;
|
const ShaderCollection* findShaders(PermutationId id) const;
|
||||||
void registerMaterial(PMaterial material);
|
void registerMaterial(PMaterial material);
|
||||||
void registerVertexData(VertexData* vertexData);
|
void registerVertexData(VertexData* vertexData);
|
||||||
void registerRenderPass(std::string name,
|
void registerRenderPass(Gfx::PPipelineLayout baseLayout,
|
||||||
|
std::string name,
|
||||||
std::string mainFile,
|
std::string mainFile,
|
||||||
bool useMaterials = false,
|
bool useMaterials = false,
|
||||||
bool hasFragmentShader = false,
|
bool hasFragmentShader = false,
|
||||||
@@ -147,13 +149,14 @@ public:
|
|||||||
std::string taskFile = "");
|
std::string taskFile = "");
|
||||||
private:
|
private:
|
||||||
void compile();
|
void compile();
|
||||||
void createShaders(ShaderPermutation permutation);
|
void createShaders(ShaderPermutation permutation, OPipelineLayout layout);
|
||||||
std::mutex shadersLock;
|
std::mutex shadersLock;
|
||||||
Map<PermutationId, ShaderCollection> shaders;
|
Map<PermutationId, ShaderCollection> shaders;
|
||||||
Map<std::string, PMaterial> materials;
|
Map<std::string, PMaterial> materials;
|
||||||
Map<std::string, VertexData*> vertexData;
|
Map<std::string, VertexData*> vertexData;
|
||||||
struct PassConfig
|
struct PassConfig
|
||||||
{
|
{
|
||||||
|
Gfx::PPipelineLayout baseLayout;
|
||||||
std::string taskFile;
|
std::string taskFile;
|
||||||
std::string mainFile;
|
std::string mainFile;
|
||||||
std::string fragmentFile;
|
std::string fragmentFile;
|
||||||
@@ -167,4 +170,4 @@ private:
|
|||||||
};
|
};
|
||||||
DEFINE_REF(ShaderCompiler)
|
DEFINE_REF(ShaderCompiler)
|
||||||
}
|
}
|
||||||
} // namespace Seele
|
} // namespace Seele
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ void StaticMeshVertexData::deserializeMesh(MeshId id, ArchiveBuffer& buffer)
|
|||||||
void StaticMeshVertexData::init(Gfx::PGraphics _graphics)
|
void StaticMeshVertexData::init(Gfx::PGraphics _graphics)
|
||||||
{
|
{
|
||||||
VertexData::init(_graphics);
|
VertexData::init(_graphics);
|
||||||
descriptorLayout = _graphics->createDescriptorLayout("StaticMeshDescriptorLayout");
|
descriptorLayout = _graphics->createDescriptorLayout("pVertexData");
|
||||||
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ void Seele::VertexData::init(Gfx::PGraphics _graphics)
|
|||||||
{
|
{
|
||||||
graphics = _graphics;
|
graphics = _graphics;
|
||||||
verticesAllocated = NUM_DEFAULT_ELEMENTS;
|
verticesAllocated = NUM_DEFAULT_ELEMENTS;
|
||||||
instanceDataLayout = graphics->createDescriptorLayout("VertexDataInstanceLayout");
|
instanceDataLayout = graphics->createDescriptorLayout("pScene");
|
||||||
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
instanceDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
|
|
||||||
// meshData
|
// meshData
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#define CHECK_RESULT(x) {SlangResult r = x; if(r != 0) {throw std::runtime_error(fmt::format("Error: {0}", r));}}
|
#define CHECK_RESULT(x) {SlangResult r = x; if(r != 0) {throw std::runtime_error(fmt::format("Error: {0}", r));}}
|
||||||
#define CHECK_DIAGNOSTICS() {if(diagnostics) {std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; assert(false);}}
|
#define CHECK_DIAGNOSTICS() {if(diagnostics) {std::cout << (const char*)diagnostics->getBufferPointer() << std::endl; assert(false);}}
|
||||||
|
|
||||||
Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& createInfo, SlangCompileTarget target)
|
Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& createInfo, SlangCompileTarget target, Map<std::string, uint32>& paramMapping)
|
||||||
{
|
{
|
||||||
thread_local Slang::ComPtr<slang::IGlobalSession> globalSession;
|
thread_local Slang::ComPtr<slang::IGlobalSession> globalSession;
|
||||||
if(!globalSession)
|
if(!globalSession)
|
||||||
@@ -89,5 +89,14 @@ Slang::ComPtr<slang::IBlob> Seele::generateShader(const ShaderCreateInfo& create
|
|||||||
diagnostics.writeRef()
|
diagnostics.writeRef()
|
||||||
);
|
);
|
||||||
CHECK_DIAGNOSTICS();
|
CHECK_DIAGNOSTICS();
|
||||||
|
slang::ProgramLayout* signature = specializedComponent->getLayout(0, diagnostics.writeRef());
|
||||||
|
CHECK_DIAGNOSTICS();
|
||||||
|
auto entry = signature->findEntryPointByName(createInfo.entryPoint.c_str());
|
||||||
|
for(size_t i = 0; i < signature->getParameterCount(); ++i)
|
||||||
|
{
|
||||||
|
auto param = signature->getParameterByIndex(i);
|
||||||
|
paramMapping[param->getName()] = param->getBindingIndex();
|
||||||
|
std::cout << param->getName() << " " << param->getBindingIndex() << " " << param->getSemanticIndex() << std::endl;
|
||||||
|
}
|
||||||
return kernelBlob;
|
return kernelBlob;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,5 +4,5 @@
|
|||||||
#include <slang.h>
|
#include <slang.h>
|
||||||
|
|
||||||
namespace Seele {
|
namespace Seele {
|
||||||
Slang::ComPtr<slang::IBlob> generateShader(const ShaderCreateInfo& createInfo, SlangCompileTarget target);
|
Slang::ComPtr<slang::IBlob> generateShader(const ShaderCreateInfo& createInfo, SlangCompileTarget target, Map<std::string, uint32>& paramMapping);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void Material::save(ArchiveBuffer& buffer) const
|
|||||||
Serialization::save(buffer, codeExpressions);
|
Serialization::save(buffer, codeExpressions);
|
||||||
Serialization::save(buffer, parameters);
|
Serialization::save(buffer, parameters);
|
||||||
Serialization::save(buffer, brdf);
|
Serialization::save(buffer, brdf);
|
||||||
Serialization::save(buffer, layout->getSetIndex());
|
Serialization::save(buffer, layout->getName());
|
||||||
const auto& bindings = layout->getBindings();
|
const auto& bindings = layout->getBindings();
|
||||||
Serialization::save(buffer, bindings.size());
|
Serialization::save(buffer, bindings.size());
|
||||||
for (const auto& binding : bindings)
|
for (const auto& binding : bindings)
|
||||||
@@ -81,11 +81,11 @@ void Material::load(ArchiveBuffer& buffer)
|
|||||||
Serialization::load(buffer, codeExpressions);
|
Serialization::load(buffer, codeExpressions);
|
||||||
Serialization::load(buffer, parameters);
|
Serialization::load(buffer, parameters);
|
||||||
Serialization::load(buffer, brdf);
|
Serialization::load(buffer, brdf);
|
||||||
uint32 setIndex;
|
std::string descriptorName;
|
||||||
Serialization::load(buffer, setIndex);
|
Serialization::load(buffer, descriptorName);
|
||||||
uint64 numBindings;
|
uint64 numBindings;
|
||||||
Serialization::load(buffer, numBindings);
|
Serialization::load(buffer, numBindings);
|
||||||
layout = graphics->createDescriptorLayout();
|
layout = graphics->createDescriptorLayout(descriptorName);
|
||||||
for (uint64 i = 0; i < numBindings; ++i)
|
for (uint64 i = 0; i < numBindings; ++i)
|
||||||
{
|
{
|
||||||
uint32 binding;
|
uint32 binding;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using namespace Seele;
|
|||||||
LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
|
LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
|
||||||
: graphics(graphics)
|
: graphics(graphics)
|
||||||
{
|
{
|
||||||
layout = graphics->createDescriptorLayout("LightEnvironment");
|
layout = graphics->createDescriptorLayout("pLightEnv");
|
||||||
layout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
layout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
|
||||||
layout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
layout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
layout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
layout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
|
||||||
|
|||||||
Reference in New Issue
Block a user