Implement quick shader switch hotkeys
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
extern bool useViewCulling;
|
||||
|
||||
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
||||
: RenderPass(graphics, scene)
|
||||
{
|
||||
@@ -40,11 +42,11 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene)
|
||||
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "MeshletPass", false, true, true, "BasePass", true, true, "ViewCullingTask");
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "MeshletPass", true, true, "BasePass", true, true, "ViewCullingTask");
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "LegacyPass", false, true, true, "BasePass");
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "LegacyPass", true, true, "BasePass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +99,7 @@ void BasePass::render()
|
||||
permutation.setVertexFile("LegacyPass");
|
||||
}
|
||||
permutation.setFragmentFile("BasePass");
|
||||
permutation.setViewCulling(useViewCulling);
|
||||
for (VertexData* vertexData : VertexData::getList())
|
||||
{
|
||||
permutation.setVertexData(vertexData->getTypeName());
|
||||
@@ -168,7 +171,6 @@ void BasePass::render()
|
||||
command->bindDescriptor(scene->getLightEnvironment()->getDescriptorSet());
|
||||
command->bindDescriptor(opaqueCulling);
|
||||
command->bindDescriptor(vertexData->getInstanceDataSet());
|
||||
command->bindDescriptor(vertexData->getInstanceDataSet());
|
||||
for (const auto& drawCall : materialData.instances)
|
||||
{
|
||||
command->bindDescriptor(drawCall.materialInstance->getDescriptorSet());
|
||||
@@ -222,7 +224,7 @@ void BasePass::publishOutputs()
|
||||
void BasePass::createRenderPass()
|
||||
{
|
||||
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
|
||||
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR);
|
||||
depthAttachment.setLoadOp(Gfx::SE_ATTACHMENT_LOAD_OP_LOAD);
|
||||
depthAttachment.setInitialLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL);
|
||||
depthAttachment.setFinalLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
|
||||
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
|
||||
|
||||
@@ -15,10 +15,10 @@ target_sources(Engine
|
||||
RenderPass.cpp
|
||||
SkyboxRenderPass.h
|
||||
SkyboxRenderPass.cpp
|
||||
StaticDepthPrepass.h
|
||||
StaticDepthPrepass.cpp
|
||||
StaticBasePass.h
|
||||
StaticBasePass.cpp
|
||||
#StaticDepthPrepass.h
|
||||
#StaticDepthPrepass.cpp
|
||||
#StaticBasePass.h
|
||||
#StaticBasePass.cpp
|
||||
TextPass.h
|
||||
TextPass.cpp
|
||||
UIPass.h
|
||||
@@ -35,7 +35,7 @@ target_sources(Engine
|
||||
RenderGraphResources.h
|
||||
RenderPass.h
|
||||
SkyboxRenderPass.h
|
||||
StaticDepthPrepass.h
|
||||
StaticBasePass.h
|
||||
#StaticDepthPrepass.h
|
||||
#StaticBasePass.h
|
||||
TextPass.h
|
||||
UIPass.h)
|
||||
@@ -13,6 +13,9 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
extern bool usePositionOnly;
|
||||
extern bool useViewCulling;
|
||||
|
||||
DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
||||
: RenderPass(graphics, scene)
|
||||
{
|
||||
@@ -25,11 +28,11 @@ DepthPrepass::DepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
||||
});
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", true, false, false, "", true, true, "ViewCullingTask");
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true, true, "ViewCullingTask");
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass", true);
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +51,8 @@ void DepthPrepass::render()
|
||||
Array<Gfx::ORenderCommand> commands;
|
||||
|
||||
Gfx::ShaderPermutation permutation;
|
||||
permutation.setPositionOnly();
|
||||
permutation.setPositionOnly(usePositionOnly);
|
||||
permutation.setViewCulling(useViewCulling);
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
permutation.setTaskFile("ViewCullingTask");
|
||||
|
||||
@@ -22,11 +22,11 @@ StaticBasePass::StaticBasePass(Gfx::PGraphics graphics, PScene scene)
|
||||
basePassLayout->addDescriptorLayout(lightCullingLayout);
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "StaticMeshletPass", false, true, true, "BasePass", true);
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "BasePass", "StaticMeshletPass", false, true, "BasePass", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "StaticBasePass", "StaticLegacyPass", false, true, true, "BasePass");
|
||||
graphics->getShaderCompiler()->registerRenderPass(basePassLayout, "StaticBasePass", "StaticLegacyPass", false, true, "BasePass");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ StaticDepthPrepass::StaticDepthPrepass(Gfx::PGraphics graphics, PScene scene)
|
||||
depthPrepassLayout->addDescriptorLayout(meshletCullingLayout);
|
||||
if (graphics->supportMeshShading())
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", true, false, false, "", true);
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "MeshletPass", false, false, "", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass", true);
|
||||
graphics->getShaderCompiler()->registerRenderPass(depthPrepassLayout, "DepthPass", "LegacyPass");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ void ShaderCompiler::registerVertexData(VertexData* vd)
|
||||
|
||||
void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout,
|
||||
std::string name, std::string mainFile,
|
||||
bool positionOnly,
|
||||
bool useMaterials,
|
||||
bool hasFragmentShader,
|
||||
std::string fragmentFile,
|
||||
@@ -53,7 +52,6 @@ void ShaderCompiler::registerRenderPass(Gfx::PPipelineLayout layout,
|
||||
.useMeshShading = useMeshShading,
|
||||
.hasTaskShader = hasTaskShader,
|
||||
.useMaterial = useMaterials,
|
||||
.positionOnly = positionOnly,
|
||||
};
|
||||
compile();
|
||||
}
|
||||
@@ -70,12 +68,53 @@ void ShaderCompiler::compile()
|
||||
{
|
||||
for (const auto& [matName, mat] : materials)
|
||||
{
|
||||
//work.add([=]() {
|
||||
ShaderPermutation permutation;
|
||||
if (pass.positionOnly)
|
||||
for (int x = 0; x < 2; x++)
|
||||
{
|
||||
for (int y = 0; y < 2; y++)
|
||||
{
|
||||
permutation.setPositionOnly();
|
||||
work.add([=]() {
|
||||
ShaderPermutation permutation;
|
||||
permutation.setPositionOnly(x);
|
||||
permutation.setViewCulling(y);
|
||||
if (pass.useMeshShading)
|
||||
{
|
||||
permutation.setMeshFile(pass.mainFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
permutation.setVertexFile(pass.mainFile);
|
||||
}
|
||||
if (pass.hasFragmentShader)
|
||||
{
|
||||
permutation.setFragmentFile(pass.fragmentFile);
|
||||
}
|
||||
if (pass.hasTaskShader)
|
||||
{
|
||||
permutation.setTaskFile(pass.taskFile);
|
||||
}
|
||||
permutation.setVertexData(vd->getTypeName());
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
layout->addDescriptorLayout(mat->getDescriptorLayout());
|
||||
permutation.setMaterial(mat->getName());
|
||||
createShaders(permutation, std::move(layout));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < 2; x++)
|
||||
{
|
||||
for (int y = 0; y < 2; y++)
|
||||
{
|
||||
work.add([=]() {
|
||||
ShaderPermutation permutation;
|
||||
permutation.setPositionOnly(x);
|
||||
permutation.setViewCulling(y);
|
||||
if (pass.useMeshShading)
|
||||
{
|
||||
permutation.setMeshFile(pass.mainFile);
|
||||
@@ -96,46 +135,14 @@ void ShaderCompiler::compile()
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
layout->addDescriptorLayout(mat->getDescriptorLayout());
|
||||
permutation.setMaterial(mat->getName());
|
||||
createShaders(permutation, std::move(layout));
|
||||
//});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//work.add([=]() {
|
||||
ShaderPermutation permutation;
|
||||
if (pass.positionOnly)
|
||||
{
|
||||
permutation.setPositionOnly();
|
||||
}
|
||||
if (pass.useMeshShading)
|
||||
{
|
||||
permutation.setMeshFile(pass.mainFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
permutation.setVertexFile(pass.mainFile);
|
||||
}
|
||||
if (pass.hasFragmentShader)
|
||||
{
|
||||
permutation.setFragmentFile(pass.fragmentFile);
|
||||
}
|
||||
if (pass.hasTaskShader)
|
||||
{
|
||||
permutation.setTaskFile(pass.taskFile);
|
||||
}
|
||||
permutation.setVertexData(vd->getTypeName());
|
||||
OPipelineLayout layout = graphics->createPipelineLayout(pass.baseLayout->getName(), pass.baseLayout);
|
||||
layout->addDescriptorLayout(vd->getVertexDataLayout());
|
||||
layout->addDescriptorLayout(vd->getInstanceDataLayout());
|
||||
createShaders(permutation, std::move(layout));
|
||||
//});
|
||||
}
|
||||
}
|
||||
}
|
||||
//getThreadPool().runAndWait(std::move(work));
|
||||
getThreadPool().runAndWait(std::move(work));
|
||||
}
|
||||
|
||||
void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipelineLayout layout)
|
||||
@@ -161,6 +168,10 @@ void ShaderCompiler::createShaders(ShaderPermutation permutation, Gfx::OPipeline
|
||||
{
|
||||
createInfo.defines["POS_ONLY"] = "1";
|
||||
}
|
||||
if (permutation.viewCulling)
|
||||
{
|
||||
createInfo.defines["VIEW_CULLING"] = "1";
|
||||
}
|
||||
createInfo.typeParameter.add({ Pair<const char*, const char*>("IVertexData", permutation.vertexDataName) });
|
||||
createInfo.additionalModules.add(permutation.vertexDataName);
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ struct ShaderPermutation
|
||||
uint8 hasTaskShader;
|
||||
uint8 useMaterial;
|
||||
uint8 positionOnly;
|
||||
uint8 viewCulling;
|
||||
//TODO: lightmapping etc
|
||||
ShaderPermutation()
|
||||
{
|
||||
@@ -103,9 +104,13 @@ struct ShaderPermutation
|
||||
useMaterial = 1;
|
||||
strncpy(materialName, name.data(), sizeof(materialName));
|
||||
}
|
||||
void setPositionOnly()
|
||||
void setPositionOnly(bool enable)
|
||||
{
|
||||
positionOnly = true;
|
||||
positionOnly = enable;
|
||||
}
|
||||
void setViewCulling(bool enable)
|
||||
{
|
||||
viewCulling = enable;
|
||||
}
|
||||
};
|
||||
//Hashed ShaderPermutation for fast lookup
|
||||
@@ -146,7 +151,6 @@ public:
|
||||
void registerRenderPass(Gfx::PPipelineLayout baseLayout,
|
||||
std::string name,
|
||||
std::string mainFile,
|
||||
bool positionOnly = true,
|
||||
bool useMaterials = false,
|
||||
bool hasFragmentShader = false,
|
||||
std::string fragmentFile = "",
|
||||
@@ -170,7 +174,6 @@ private:
|
||||
bool useMeshShading;
|
||||
bool hasTaskShader;
|
||||
bool useMaterial;
|
||||
bool positionOnly;
|
||||
};
|
||||
Map<std::string, PassConfig> passes;
|
||||
Gfx::PGraphics graphics;
|
||||
|
||||
@@ -388,7 +388,7 @@ void PipelineLayout::create() {
|
||||
|
||||
std::unique_lock l(layoutLock);
|
||||
if (cachedLayouts.contains(layoutHash)) {
|
||||
std::cout << "New Layout" << std::endl;
|
||||
// std::cout << "New Layout" << std::endl;
|
||||
layoutHandle = cachedLayouts[layoutHash];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,8 @@ void Fence::reset()
|
||||
{
|
||||
if (signaled)
|
||||
{
|
||||
vkResetFences(graphics->getDevice(), 1, &fence);
|
||||
VK_CHECK(vkResetFences(graphics->getDevice(), 1, &fence));
|
||||
//std::cout << vkGetFenceStatus(graphics->getDevice(), fence) << std::endl;
|
||||
signaled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ void Window::pollInput()
|
||||
|
||||
void Window::beginFrame()
|
||||
{
|
||||
imageAvailableFences[currentSemaphoreIndex]->wait(100000);
|
||||
imageAvailableFences[currentSemaphoreIndex]->wait(100000000);
|
||||
imageAvailableFences[currentSemaphoreIndex]->reset();
|
||||
vkAcquireNextImageKHR(graphics->getDevice(), swapchain, std::numeric_limits<uint64>::max(), imageAvailableSemaphores[currentSemaphoreIndex]->getHandle(), imageAvailableFences[currentSemaphoreIndex]->getHandle(), ¤tImageIndex);
|
||||
graphics->getGraphicsCommands()->getCommands()->waitForSemaphore(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, imageAvailableSemaphores[currentSemaphoreIndex]);
|
||||
@@ -284,14 +284,14 @@ void Window::chooseSwapSurfaceFormat()
|
||||
|
||||
void Window::chooseSwapPresentMode()
|
||||
{
|
||||
/*for (const auto& supportedPresentMode : supportedPresentModes)
|
||||
for (const auto& supportedPresentMode : supportedPresentModes)
|
||||
{
|
||||
if (supportedPresentMode == VK_PRESENT_MODE_MAILBOX_KHR)
|
||||
{
|
||||
presentMode = supportedPresentMode;
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
presentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user