diff --git a/62_CAD/main.cpp b/62_CAD/main.cpp index 86a7113e8..1286fe29a 100644 --- a/62_CAD/main.cpp +++ b/62_CAD/main.cpp @@ -860,14 +860,9 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu pipelineLayout = m_device->createPipelineLayout({}, core::smart_refctd_ptr(descriptorSetLayout0), core::smart_refctd_ptr(descriptorSetLayout1), nullptr, nullptr); } - - // Main Pipeline Shaders - std::array, 4u> mainPipelineShaders = {}; - constexpr auto vertexShaderPath = "../shaders/main_pipeline/vertex_shader.hlsl"; - constexpr auto fragmentShaderPath = "../shaders/main_pipeline/fragment_shader.hlsl"; - constexpr auto debugfragmentShaderPath = "../shaders/main_pipeline/fragment_shader_debug.hlsl"; - constexpr auto resolveAlphasShaderPath = "../shaders/main_pipeline/resolve_alphas.hlsl"; - // GeoTexture Pipeline Shaders + + smart_refctd_ptr mainPipelineFragmentShaders = {}; + smart_refctd_ptr mainPipelineVertexShader = {}; std::array, 2u> geoTexturePipelineShaders = {}; { smart_refctd_ptr shaderReadCache = nullptr; @@ -902,7 +897,7 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu } // Load Custom Shader - auto loadCompileAndCreateShader = [&](const std::string& relPath, IShader::E_SHADER_STAGE stage) -> smart_refctd_ptr + auto loadCompileShader = [&](const std::string& relPath, IShader::E_SHADER_STAGE stage) -> smart_refctd_ptr { IAssetLoader::SAssetLoadParams lp = {}; lp.logger = m_logger.get(); @@ -914,19 +909,23 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu // lets go straight from ICPUSpecializedShader to IGPUSpecializedShader auto cpuShader = IAsset::castDown(assets[0]); - cpuShader->setShaderStage(stage); if (!cpuShader) return nullptr; - return m_device->createShader({ cpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get()}); + cpuShader->setShaderStage(stage); + return m_device->compileShader({ cpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); }; - mainPipelineShaders[0] = loadCompileAndCreateShader(vertexShaderPath, IShader::E_SHADER_STAGE::ESS_VERTEX); - mainPipelineShaders[1] = loadCompileAndCreateShader(fragmentShaderPath, IShader::E_SHADER_STAGE::ESS_FRAGMENT); - mainPipelineShaders[2] = loadCompileAndCreateShader(debugfragmentShaderPath, IShader::E_SHADER_STAGE::ESS_FRAGMENT); - mainPipelineShaders[3] = loadCompileAndCreateShader(resolveAlphasShaderPath, IShader::E_SHADER_STAGE::ESS_FRAGMENT); - - geoTexturePipelineShaders[0] = loadCompileAndCreateShader(GeoTextureRenderer::VertexShaderRelativePath, IShader::E_SHADER_STAGE::ESS_VERTEX); - geoTexturePipelineShaders[1] = loadCompileAndCreateShader(GeoTextureRenderer::FragmentShaderRelativePath, IShader::E_SHADER_STAGE::ESS_FRAGMENT); + + auto mainPipelineFragmentCpuShader = loadCompileShader("../shaders/main_pipeline/fragment.hlsl", IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY); + auto mainPipelineVertexCpuShader = loadCompileShader("../shaders/main_pipeline/vertex_shader.hlsl", IShader::E_SHADER_STAGE::ESS_VERTEX); + auto geoTexturePipelineVertCpuShader = loadCompileShader(GeoTextureRenderer::VertexShaderRelativePath, IShader::E_SHADER_STAGE::ESS_VERTEX); + auto geoTexturePipelineFragCpuShader = loadCompileShader(GeoTextureRenderer::FragmentShaderRelativePath, IShader::E_SHADER_STAGE::ESS_FRAGMENT); + mainPipelineFragmentCpuShader->setShaderStage(IShader::E_SHADER_STAGE::ESS_FRAGMENT); + + mainPipelineFragmentShaders = m_device->createShader({ mainPipelineFragmentCpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); + mainPipelineVertexShader = m_device->createShader({ mainPipelineVertexCpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); + geoTexturePipelineShaders[0] = m_device->createShader({ geoTexturePipelineVertCpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); + geoTexturePipelineShaders[1] = m_device->createShader({ geoTexturePipelineFragCpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); core::smart_refctd_ptr shaderWriteCacheFile; { @@ -970,10 +969,7 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu // Load FSTri Shader ext::FullScreenTriangle::ProtoPipeline fsTriangleProtoPipe(m_assetMgr.get(),m_device.get(),m_logger.get()); - const IGPUShader::SSpecInfo fragSpec = { - .entryPoint = "main", - .shader = mainPipelineShaders[3u].get() - }; + const IGPUShader::SSpecInfo fragSpec = { .entryPoint = "resolveAlphaMain", .shader = mainPipelineFragmentShaders.get() }; resolveAlphaGraphicsPipeline = fsTriangleProtoPipe.createPipeline(fragSpec, pipelineLayout.get(), compatibleRenderPass.get(), 0u, blendParams); if (!resolveAlphaGraphicsPipeline) @@ -985,8 +981,14 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu { IGPUShader::SSpecInfo specInfo[2] = { - {.shader=mainPipelineShaders[0u].get() }, - {.shader=mainPipelineShaders[1u].get() }, + { + .entryPoint = "main", + .shader = mainPipelineVertexShader.get() + }, + { + .entryPoint = "fragMain", + .shader = mainPipelineFragmentShaders.get() + }, }; IGPUGraphicsPipeline::SCreationParams params[1] = {}; @@ -1011,7 +1013,7 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu if constexpr (DebugModeWireframe) { - specInfo[1u].shader = mainPipelineShaders[2u].get(); // change only fragment shader to fragment_shader_debug.hlsl + specInfo[1u].entryPoint = "fragDebugMain"; // change only fragment shader entrypoint params[0].cached.rasterization.polygonMode = asset::EPM_LINE; if (!m_device->createGraphicsPipelines(nullptr,params,&debugGraphicsPipeline)) diff --git a/62_CAD/shaders/main_pipeline/fragment.hlsl b/62_CAD/shaders/main_pipeline/fragment.hlsl new file mode 100644 index 000000000..cdd0d652d --- /dev/null +++ b/62_CAD/shaders/main_pipeline/fragment.hlsl @@ -0,0 +1,4 @@ +#include "fragment_shader.hlsl" +#include "fragment_shader_debug.hlsl" +#include "resolve_alphas.hlsl" + diff --git a/62_CAD/shaders/main_pipeline/fragment_shader.hlsl b/62_CAD/shaders/main_pipeline/fragment_shader.hlsl index 4ff88e9a2..e850622c3 100644 --- a/62_CAD/shaders/main_pipeline/fragment_shader.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment_shader.hlsl @@ -1,5 +1,3 @@ -#pragma shader_stage(fragment) - #include "common.hlsl" #include #include @@ -359,8 +357,6 @@ template<> float32_t4 calculateFinalColor(const uint2 fragCoord, const float localAlpha, const uint32_t currentMainObjectIdx, float3 localTextureColor, bool colorFromTexture) { float32_t4 color; - - nbl::hlsl::spirv::execution_mode::PixelInterlockOrderedEXT(); nbl::hlsl::spirv::beginInvocationInterlockEXT(); const uint32_t packedData = pseudoStencil[fragCoord]; @@ -405,8 +401,9 @@ float32_t4 calculateFinalColor(const uint2 fragCoord, const float localAlp return color; } - -float4 main(PSInput input) : SV_TARGET +[[vk::spvexecutionmode(spv::ExecutionModePixelInterlockOrderedEXT)]] +[shader("pixel")] +float4 fragMain(PSInput input) : SV_TARGET { float localAlpha = 0.0f; float3 textureColor = float3(0, 0, 0); // color sampled from a texture diff --git a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl index 9b9de0826..7dba46dd0 100644 --- a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl @@ -1,7 +1,4 @@ - -#pragma shader_stage(fragment) - -struct PSInput +struct PSInputDebug { float4 position : SV_Position; [[vk::location(0)]] float4 color : COLOR; @@ -9,7 +6,8 @@ struct PSInput [[vk::location(2)]] nointerpolation uint3 lineWidth_eccentricity_objType : COLOR2; }; -float4 main(PSInput input) : SV_TARGET +[shader("pixel")] +float4 fragDebugMain(PSInputDebug input) : SV_TARGET { return float4(1.0, 1.0, 1.0, 1.0); // return input.color; diff --git a/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl b/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl index d2b5028e0..46c5d28e0 100644 --- a/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl +++ b/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl @@ -1,5 +1,3 @@ -#pragma shader_stage(fragment) - #include "common.hlsl" #include #include @@ -19,7 +17,6 @@ float32_t4 calculateFinalColor(const uint2 fragCoord) { float32_t4 color; - nbl::hlsl::spirv::execution_mode::PixelInterlockOrderedEXT(); nbl::hlsl::spirv::beginInvocationInterlockEXT(); const uint32_t packedData = pseudoStencil[fragCoord]; @@ -54,7 +51,9 @@ float32_t4 calculateFinalColor(const uint2 fragCoord) return color; } -float4 main(float4 position : SV_Position) : SV_TARGET +[[vk::spvexecutionmode(spv::ExecutionModePixelInterlockOrderedEXT)]] +[shader("pixel")] +float4 resolveAlphaMain(float4 position : SV_Position) : SV_TARGET { return calculateFinalColor(position.xy); }