Trying to fix metal shader compilation

This commit is contained in:
Dynamitos
2024-04-19 18:23:36 +02:00
parent 21636f2460
commit 194a0e8b91
43 changed files with 353 additions and 183 deletions
+15 -19
View File
@@ -19,14 +19,6 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
: RenderPass(graphics, scene)
, 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()
@@ -100,11 +92,6 @@ void BasePass::render()
Gfx::ORenderCommand command = graphics->createRenderCommand("BaseRender");
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);
assert(collection != nullptr);
@@ -114,7 +101,7 @@ void BasePass::render()
pipelineInfo.taskShader = collection->taskShader;
pipelineInfo.meshShader = collection->meshShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
@@ -127,7 +114,7 @@ void BasePass::render()
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
pipelineInfo.multisampleState.samples = viewport->getSamples();
@@ -174,21 +161,30 @@ void BasePass::publishOutputs()
{
basePassLayout = graphics->createPipelineLayout();
basePassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
basePassLayout->addDescriptorLayout(INDEX_LIGHT_ENV, scene->getLightEnvironment()->getDescriptorLayout());
basePassLayout->addDescriptorLayout(viewParamsLayout);
basePassLayout->addDescriptorLayout(scene->getLightEnvironment()->getDescriptorLayout());
lightCullingLayout = graphics->createDescriptorLayout("BasePassLightCulling");
lightCullingLayout = graphics->createDescriptorLayout("pLightCullingData");
// oLightIndexList
lightCullingLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
// oLightGrid
lightCullingLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE);
lightCullingLayout->create();
basePassLayout->addDescriptorLayout(INDEX_LIGHT_CULLING, lightCullingLayout);
basePassLayout->addDescriptorLayout(lightCullingLayout);
colorAttachment = Gfx::RenderTargetAttachment(viewport,
Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
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()
+2 -2
View File
@@ -119,8 +119,8 @@ void DebugPass::createRenderPass()
};
renderPass = graphics->createRenderPass(std::move(layout), dependency, viewport);
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(viewParamsLayout);
pipelineLayout->create();
ShaderCreateInfo createInfo = {
@@ -27,6 +27,7 @@ private:
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline;
Gfx::OPipelineLayout pipelineLayout;
};
DEFINE_REF(DebugPass)
} // namespace Seele
@@ -17,14 +17,14 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
, descriptorSets(3)
{
depthPrepassLayout = graphics->createPipelineLayout();
depthPrepassLayout->addDescriptorLayout(INDEX_VIEW_PARAMS, viewParamsLayout);
depthPrepassLayout->addDescriptorLayout(viewParamsLayout);
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
{
graphics->getShaderCompiler()->registerRenderPass("DepthPass", "LegacyBasePass");
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyBasePass");
}
}
@@ -68,12 +68,7 @@ void DepthPrepass::render()
Gfx::ORenderCommand command = graphics->createRenderCommand("DepthRender");
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);
assert(collection != nullptr);
if(graphics->supportMeshShading())
@@ -82,7 +77,7 @@ void DepthPrepass::render()
pipelineInfo.taskShader = collection->taskShader;
pipelineInfo.meshShader = collection->meshShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS;
pipelineInfo.multisampleState.samples = viewport->getSamples();
@@ -94,7 +89,7 @@ void DepthPrepass::render()
Gfx::LegacyPipelineCreateInfo pipelineInfo;
pipelineInfo.vertexShader = collection->vertexShader;
pipelineInfo.fragmentShader = collection->fragmentShader;
pipelineInfo.pipelineLayout = std::move(layout);
pipelineInfo.pipelineLayout = collection->pipelineLayout;
pipelineInfo.renderPass = renderPass;
//pipelineInfo.depthStencilState.depthWriteEnable = false;
pipelineInfo.depthStencilState.depthCompareOp = Gfx::SE_COMPARE_OP_LESS_OR_EQUAL;
@@ -97,7 +97,7 @@ void LightCullingPass::publishOutputs()
dispatchParamsSet->updateBuffer(1, frustumBuffer);
dispatchParamsSet->writeChanges();
cullingDescriptorLayout = graphics->createDescriptorLayout("CullingLayout");
cullingDescriptorLayout = graphics->createDescriptorLayout("pCullingParams");
//DepthTexture
cullingDescriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
@@ -116,18 +116,24 @@ void LightCullingPass::publishOutputs()
lightEnv = scene->getLightEnvironment();
Gfx::OPipelineLayout cullingLayout = graphics->createPipelineLayout();
cullingLayout->addDescriptorLayout(0, viewParamsLayout);
cullingLayout->addDescriptorLayout(1, dispatchParamsLayout);
cullingLayout->addDescriptorLayout(2, cullingDescriptorLayout);
cullingLayout->addDescriptorLayout(3, lightEnv->getDescriptorLayout());
cullingLayout = graphics->createPipelineLayout();
cullingLayout->addDescriptorLayout(viewParamsLayout);
cullingLayout->addDescriptorLayout(dispatchParamsLayout);
cullingLayout->addDescriptorLayout(cullingDescriptorLayout);
cullingLayout->addDescriptorLayout(lightEnv->getDescriptorLayout());
Map<std::string, uint32> mapping;
mapping["pViewParams"] = 0;
mapping["pDispatchParams"] = 1;
cullingLayout->addMapping(mapping);
cullingLayout->create();
ShaderCreateInfo createInfo;
createInfo.name = "Culling";
createInfo.additionalModules.add("LightCulling");
createInfo.mainModule = "LightCulling";
createInfo.entryPoint = "cullLights";
ShaderCreateInfo createInfo = {
.name = "Culling",
.additionalModules = {"LightCulling"},
.mainModule = "LightCulling",
.entryPoint = "cullLights",
.rootSignature = cullingLayout,
};
cullingShader = graphics->createComputeShader(createInfo);
Gfx::ComputePipelineCreateInfo pipelineInfo;
@@ -202,18 +208,25 @@ void LightCullingPass::setupFrustums()
dispatchParams.numThreads = numThreads;
dispatchParams.numThreadGroups = numThreadGroups;
dispatchParamsLayout = graphics->createDescriptorLayout("FrustumLayout");
dispatchParamsLayout = graphics->createDescriptorLayout("pDispatchParams");
dispatchParamsLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
dispatchParamsLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER);
Gfx::OPipelineLayout frustumLayout = graphics->createPipelineLayout();
frustumLayout->addDescriptorLayout(0, viewParamsLayout);
frustumLayout->addDescriptorLayout(1, dispatchParamsLayout);
frustumLayout = graphics->createPipelineLayout();
frustumLayout->addDescriptorLayout(viewParamsLayout);
frustumLayout->addDescriptorLayout(dispatchParamsLayout);
Map<std::string, uint32> mapping;
mapping["pViewParams"] = 0;
mapping["pDispatchParams"] = 1;
frustumLayout->addMapping(mapping);
frustumLayout->create();
ShaderCreateInfo createInfo;
createInfo.name = "Frustum";
createInfo.additionalModules.add("ComputeFrustums");
createInfo.mainModule = "ComputeFrustums";
createInfo.entryPoint = "computeFrustums";
ShaderCreateInfo createInfo = {
.name = "Frustum",
.additionalModules = {"ComputeFrustums"},
.mainModule = "ComputeFrustums",
.entryPoint = "computeFrustums",
.rootSignature = frustumLayout,
};
std::cout << "Compiling frustumShader" << std::endl;
frustumShader = graphics->createComputeShader(createInfo);
Gfx::ComputePipelineCreateInfo pipelineInfo;
@@ -256,4 +269,4 @@ void LightCullingPass::setupFrustums()
graphics->executeCommands(std::move(commands));
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);
}
}
@@ -49,6 +49,7 @@ private:
Gfx::PDescriptorSet dispatchParamsSet;
Gfx::OComputeShader frustumShader;
Gfx::PComputePipeline frustumPipeline;
Gfx::OPipelineLayout frustumLayout;
PLightEnvironment lightEnv;
Gfx::PTexture2D depthAttachment;
@@ -62,6 +63,7 @@ private:
Gfx::ODescriptorLayout cullingDescriptorLayout;
Gfx::OComputeShader cullingShader;
Gfx::PComputePipeline cullingPipeline;
Gfx::OPipelineLayout cullingLayout;
};
DEFINE_REF(LightCullingPass)
} // namespace Seele
@@ -7,7 +7,7 @@ RenderPass::RenderPass(Gfx::PGraphics graphics, PScene scene)
, scene(scene)
{
viewParamsLayout = graphics->createDescriptorLayout("ViewLayout");
viewParamsLayout = graphics->createDescriptorLayout("pViewParams");
viewParamsLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
UniformBufferCreateInfo uniformInitializer = {
.sourceData = {
@@ -57,4 +57,4 @@ void RenderPass::setViewport(Gfx::PViewport _viewport)
{
viewport = _viewport;
publishOutputs();
}
}
@@ -74,10 +74,10 @@ void SkyboxRenderPass::endFrame()
void SkyboxRenderPass::publishOutputs()
{
skyboxDataLayout = graphics->createDescriptorLayout("SkyboxDescLayout");
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
skyboxDataLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
skyboxDataLayout->create();
textureLayout = graphics->createDescriptorLayout();
textureLayout = graphics->createDescriptorLayout("pSkyboxTextures");
textureLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
textureLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
textureLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
@@ -122,10 +122,10 @@ void SkyboxRenderPass::createRenderPass()
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, viewParamsLayout);
pipelineLayout->addDescriptorLayout(1, skyboxDataLayout);
pipelineLayout->addDescriptorLayout(2, textureLayout);
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(viewParamsLayout);
pipelineLayout->addDescriptorLayout(skyboxDataLayout);
pipelineLayout->addDescriptorLayout(textureLayout);
pipelineLayout->create();
Gfx::LegacyPipelineCreateInfo gfxInfo;
@@ -133,7 +133,7 @@ void SkyboxRenderPass::createRenderPass()
gfxInfo.fragmentShader = fragmentShader;
gfxInfo.rasterizationState.polygonMode = Gfx::SE_POLYGON_MODE_FILL;
gfxInfo.topology = Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
gfxInfo.pipelineLayout = std::move(pipelineLayout);
gfxInfo.pipelineLayout = pipelineLayout;
gfxInfo.renderPass = renderPass;
gfxInfo.multisampleState.samples = viewport->getSamples();
pipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
@@ -26,6 +26,7 @@ private:
Gfx::PDescriptorSet textureSet;
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::OPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Gfx::OSampler skyboxSampler;
struct SkyboxData
+7 -8
View File
@@ -85,7 +85,7 @@ void TextPass::render()
command->bindDescriptor({generalSet, resource.textureArraySet});
//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);
}
commands.add(std::move(command));
@@ -120,12 +120,12 @@ void TextPass::createRenderPass()
createInfo.name = "TextFragment";
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
generalLayout = graphics->createDescriptorLayout("TextGeneral");
generalLayout = graphics->createDescriptorLayout("pRender");
generalLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
generalLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
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->create();
@@ -149,10 +149,9 @@ void TextPass::createRenderPass()
generalSet->updateSampler(1, glyphSampler);
generalSet->writeChanges();
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
layoutRef = pipelineLayout;
pipelineLayout->addDescriptorLayout(0, generalLayout);
pipelineLayout->addDescriptorLayout(1, textureArrayLayout);
pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(generalLayout);
pipelineLayout->addDescriptorLayout(textureArrayLayout);
pipelineLayout->addPushConstants({
.stageFlags = Gfx::SE_SHADER_STAGE_VERTEX_BIT | Gfx::SE_SHADER_STAGE_FRAGMENT_BIT,
.offset = 0,
@@ -169,7 +168,7 @@ void TextPass::createRenderPass()
pipelineInfo.vertexShader = vertexShader;
pipelineInfo.fragmentShader = fragmentShader;
pipelineInfo.renderPass = renderPass;
pipelineInfo.pipelineLayout = std::move(pipelineLayout);
pipelineInfo.pipelineLayout = pipelineLayout;
pipelineInfo.rasterizationState.cullMode = Gfx::SE_CULL_MODE_NONE;
pipelineInfo.colorBlend.attachmentCount = 1;
pipelineInfo.colorBlend.blendAttachments[0].blendEnable = true;
+1 -1
View File
@@ -76,7 +76,7 @@ private:
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::PPipelineLayout layoutRef;
Gfx::OPipelineLayout pipelineLayout;
Gfx::PGraphicsPipeline pipeline;
Array<TextRender> texts;
};
+2 -2
View File
@@ -106,7 +106,7 @@ void UIPass::createRenderPass()
createInfo.entryPoint = "fragmentMain";
fragmentShader = graphics->createFragmentShader(createInfo);
descriptorLayout = graphics->createDescriptorLayout("UIDescriptorLayout");
descriptorLayout = graphics->createDescriptorLayout("pParams");
descriptorLayout->addDescriptorBinding(0, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
descriptorLayout->addDescriptorBinding(1, Gfx::SE_DESCRIPTOR_TYPE_SAMPLER);
descriptorLayout->addDescriptorBinding(2, Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
@@ -140,7 +140,7 @@ void UIPass::createRenderPass()
descriptorSet->writeChanges();
Gfx::OPipelineLayout pipelineLayout = graphics->createPipelineLayout();
pipelineLayout->addDescriptorLayout(0, descriptorLayout);
pipelineLayout->addDescriptorLayout(descriptorLayout);
pipelineLayout->create();
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
+1
View File
@@ -34,6 +34,7 @@ private:
Gfx::OVertexShader vertexShader;
Gfx::OFragmentShader fragmentShader;
Gfx::PGraphicsPipeline pipeline;
Gfx::OPipelineLayout pipelineLayout;
Array<UI::RenderElementStyle> renderElements;
Array<Gfx::PTexture> usedTextures;