From c7f3180e28fc56f0b1edd6be4bd40a6223ae5f79 Mon Sep 17 00:00:00 2001 From: Ali Cheraghi Date: Tue, 28 Jan 2025 03:10:10 +0330 Subject: [PATCH 1/6] CAD: multi entrypoint shader Signed-off-by: Ali Cheraghi --- 62_CAD/main.cpp | 45 +++++++++---------- 62_CAD/shaders/main_pipeline/all.hlsl | 4 ++ .../main_pipeline/fragment_shader.hlsl | 4 +- .../main_pipeline/fragment_shader_debug.hlsl | 5 ++- .../shaders/main_pipeline/resolve_alphas.hlsl | 3 +- .../shaders/main_pipeline/vertex_shader.hlsl | 3 +- 6 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 62_CAD/shaders/main_pipeline/all.hlsl diff --git a/62_CAD/main.cpp b/62_CAD/main.cpp index 65c3987b2..8a7c33e03 100644 --- a/62_CAD/main.cpp +++ b/62_CAD/main.cpp @@ -36,8 +36,8 @@ using namespace video; static constexpr bool DebugModeWireframe = false; static constexpr bool DebugRotatingViewProj = false; -static constexpr bool FragmentShaderPixelInterlock = true; -static constexpr bool LargeGeoTextureStreaming = true; +static constexpr bool FragmentShaderPixelInterlock = false; +static constexpr bool LargeGeoTextureStreaming = false; enum class ExampleMode { @@ -393,9 +393,9 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu } IGPUSampler::SParams samplerParams = {}; - samplerParams.TextureWrapU = IGPUSampler::ETC_CLAMP_TO_BORDER; - samplerParams.TextureWrapV = IGPUSampler::ETC_CLAMP_TO_BORDER; - samplerParams.TextureWrapW = IGPUSampler::ETC_CLAMP_TO_BORDER; + samplerParams.TextureWrapU = IGPUSampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER; + samplerParams.TextureWrapV = IGPUSampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER; + samplerParams.TextureWrapW = IGPUSampler::E_TEXTURE_CLAMP::ETC_CLAMP_TO_BORDER; samplerParams.BorderColor = IGPUSampler::ETBC_FLOAT_OPAQUE_WHITE; // positive means outside shape samplerParams.MinFilter = IGPUSampler::ETF_LINEAR; samplerParams.MaxFilter = IGPUSampler::ETF_LINEAR; @@ -860,14 +860,8 @@ 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 mainPipelineShader = {}; std::array, 2u> geoTexturePipelineShaders = {}; { smart_refctd_ptr shaderReadCache = nullptr; @@ -918,13 +912,10 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu if (!cpuShader) return nullptr; - return m_device->createShader({ cpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get()}); + return m_device->createShader({ 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); - + + mainPipelineShader = loadCompileAndCreateShader("../shaders/main_pipeline/all.hlsl", IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY); geoTexturePipelineShaders[0] = loadCompileAndCreateShader(GeoTextureRenderer::VertexShaderRelativePath, IShader::E_SHADER_STAGE::ESS_VERTEX); geoTexturePipelineShaders[1] = loadCompileAndCreateShader(GeoTextureRenderer::FragmentShaderRelativePath, IShader::E_SHADER_STAGE::ESS_FRAGMENT); @@ -971,8 +962,8 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu ext::FullScreenTriangle::ProtoPipeline fsTriangleProtoPipe(m_assetMgr.get(),m_device.get(),m_logger.get()); const IGPUShader::SSpecInfo fragSpec = { - .entryPoint = "main", - .shader = mainPipelineShaders[3u].get() + .entryPoint = "resolveAlphasMain", + .shader = mainPipelineShader.get() }; resolveAlphaGraphicsPipeline = fsTriangleProtoPipe.createPipeline(fragSpec, pipelineLayout.get(), compatibleRenderPass.get(), 0u, blendParams); @@ -985,8 +976,14 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu { IGPUShader::SSpecInfo specInfo[2] = { - {.shader=mainPipelineShaders[0u].get() }, - {.shader=mainPipelineShaders[1u].get() }, + { + .entryPoint = "vertMain", + .shader = mainPipelineShader.get() + }, + { + .entryPoint = "fragMain", + .shader = mainPipelineShader.get() + }, }; IGPUGraphicsPipeline::SCreationParams params[1] = {}; @@ -1011,7 +1008,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/all.hlsl b/62_CAD/shaders/main_pipeline/all.hlsl new file mode 100644 index 000000000..59660713d --- /dev/null +++ b/62_CAD/shaders/main_pipeline/all.hlsl @@ -0,0 +1,4 @@ +#include "vertex_shader.hlsl" +#include "fragment_shader.hlsl" +#include "fragment_shader_debug.hlsl" +#include "resolve_alphas.hlsl" \ No newline at end of file diff --git a/62_CAD/shaders/main_pipeline/fragment_shader.hlsl b/62_CAD/shaders/main_pipeline/fragment_shader.hlsl index 644102747..d05847690 100644 --- a/62_CAD/shaders/main_pipeline/fragment_shader.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment_shader.hlsl @@ -399,8 +399,8 @@ float32_t4 calculateFinalColor(const uint2 fragCoord, const float localAlp return color; } - -float4 main(PSInput input) : SV_TARGET +[shader("pixel")] +float4 fragmentMain(PSInput input) : SV_TARGET { float localAlpha = 0.0f; ObjectType objType = input.getObjType(); diff --git a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl index 9b9de0826..3fea2def6 100644 --- a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl @@ -1,7 +1,7 @@ #pragma shader_stage(fragment) -struct PSInput +struct PSInputDebug { float4 position : SV_Position; [[vk::location(0)]] float4 color : COLOR; @@ -9,7 +9,8 @@ struct PSInput [[vk::location(2)]] nointerpolation uint3 lineWidth_eccentricity_objType : COLOR2; }; -float4 main(PSInput input) : SV_TARGET +[shader("pixel")] +float4 fragmentDebugMain(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 087f49235..96b8c8059 100644 --- a/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl +++ b/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl @@ -41,7 +41,8 @@ float32_t4 calculateFinalColor(const uint2 fragCoord) return color; } -float4 main(float4 position : SV_Position) : SV_TARGET +[shader("pixel")] +float4 resolveAlphasMain(float4 position : SV_Position) : SV_TARGET { return calculateFinalColor(position.xy); } diff --git a/62_CAD/shaders/main_pipeline/vertex_shader.hlsl b/62_CAD/shaders/main_pipeline/vertex_shader.hlsl index 50d056eae..2cf0d95ed 100644 --- a/62_CAD/shaders/main_pipeline/vertex_shader.hlsl +++ b/62_CAD/shaders/main_pipeline/vertex_shader.hlsl @@ -85,7 +85,8 @@ void dilateHatch(out float2 outOffsetVec, out float2 outUV, const float2 // Or optionally we could dilate and stuff when we know this hatch is opaque (alpha = 1.0) } -PSInput main(uint vertexID : SV_VertexID) +[shader("vertex")] +PSInput vertMain(uint vertexID : SV_VertexID) { const uint vertexIdx = vertexID & 0x3u; const uint objectID = vertexID >> 2; From 846efc24f674d8f2fc113b18cd2efe1dd4d5912e Mon Sep 17 00:00:00 2001 From: Ali Cheraghi Date: Tue, 28 Jan 2025 03:12:03 +0330 Subject: [PATCH 2/6] CAD: do not disable FSPI & LGTS Signed-off-by: Ali Cheraghi --- 62_CAD/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/62_CAD/main.cpp b/62_CAD/main.cpp index 8a7c33e03..453d13948 100644 --- a/62_CAD/main.cpp +++ b/62_CAD/main.cpp @@ -36,8 +36,8 @@ using namespace video; static constexpr bool DebugModeWireframe = false; static constexpr bool DebugRotatingViewProj = false; -static constexpr bool FragmentShaderPixelInterlock = false; -static constexpr bool LargeGeoTextureStreaming = false; +static constexpr bool FragmentShaderPixelInterlock = true; +static constexpr bool LargeGeoTextureStreaming = true; enum class ExampleMode { From 7a4ee39455978c7d7d815c7a6253dd358420cdc5 Mon Sep 17 00:00:00 2001 From: Ali Cheraghi Date: Tue, 28 Jan 2025 16:14:32 +0330 Subject: [PATCH 3/6] 62_CAD: can not combine with resolve_alphas shader :( Signed-off-by: Ali Cheraghi --- 62_CAD/main.cpp | 9 ++++----- 62_CAD/shaders/main_pipeline/resolve_alphas.hlsl | 3 +-- 62_CAD/shaders/main_pipeline/{all.hlsl => vs_fs.hlsl} | 1 - 3 files changed, 5 insertions(+), 8 deletions(-) rename 62_CAD/shaders/main_pipeline/{all.hlsl => vs_fs.hlsl} (75%) diff --git a/62_CAD/main.cpp b/62_CAD/main.cpp index 453d13948..9fd8190ac 100644 --- a/62_CAD/main.cpp +++ b/62_CAD/main.cpp @@ -862,6 +862,7 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu } smart_refctd_ptr mainPipelineShader = {}; + smart_refctd_ptr mainPipelineResolveAlphasShader = {}; std::array, 2u> geoTexturePipelineShaders = {}; { smart_refctd_ptr shaderReadCache = nullptr; @@ -915,7 +916,8 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu return m_device->createShader({ cpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); }; - mainPipelineShader = loadCompileAndCreateShader("../shaders/main_pipeline/all.hlsl", IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY); + mainPipelineShader = loadCompileAndCreateShader("../shaders/main_pipeline/vs_fs.hlsl", IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY); + mainPipelineResolveAlphasShader = loadCompileAndCreateShader("../shaders/main_pipeline/resolve_alphas.hlsl", 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); @@ -961,10 +963,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 = "resolveAlphasMain", - .shader = mainPipelineShader.get() - }; + const IGPUShader::SSpecInfo fragSpec = { .shader = mainPipelineResolveAlphasShader.get() }; resolveAlphaGraphicsPipeline = fsTriangleProtoPipe.createPipeline(fragSpec, pipelineLayout.get(), compatibleRenderPass.get(), 0u, blendParams); if (!resolveAlphaGraphicsPipeline) diff --git a/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl b/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl index 96b8c8059..087f49235 100644 --- a/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl +++ b/62_CAD/shaders/main_pipeline/resolve_alphas.hlsl @@ -41,8 +41,7 @@ float32_t4 calculateFinalColor(const uint2 fragCoord) return color; } -[shader("pixel")] -float4 resolveAlphasMain(float4 position : SV_Position) : SV_TARGET +float4 main(float4 position : SV_Position) : SV_TARGET { return calculateFinalColor(position.xy); } diff --git a/62_CAD/shaders/main_pipeline/all.hlsl b/62_CAD/shaders/main_pipeline/vs_fs.hlsl similarity index 75% rename from 62_CAD/shaders/main_pipeline/all.hlsl rename to 62_CAD/shaders/main_pipeline/vs_fs.hlsl index 59660713d..78a588e83 100644 --- a/62_CAD/shaders/main_pipeline/all.hlsl +++ b/62_CAD/shaders/main_pipeline/vs_fs.hlsl @@ -1,4 +1,3 @@ #include "vertex_shader.hlsl" #include "fragment_shader.hlsl" #include "fragment_shader_debug.hlsl" -#include "resolve_alphas.hlsl" \ No newline at end of file From 663daa967e0055d09c09d62b870fff8c8362a569 Mon Sep 17 00:00:00 2001 From: Ali Cheraghi Date: Wed, 29 Jan 2025 05:34:38 +0330 Subject: [PATCH 4/6] 62_CAD: try `spvexecutionmode` Signed-off-by: Ali Cheraghi --- 62_CAD/shaders/main_pipeline/fragment_shader.hlsl | 4 +--- 62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/62_CAD/shaders/main_pipeline/fragment_shader.hlsl b/62_CAD/shaders/main_pipeline/fragment_shader.hlsl index d05847690..365079658 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 @@ -361,7 +359,6 @@ float32_t4 calculateFinalColor(const uint2 fragCoord, const float localAlp { float32_t4 color; - nbl::hlsl::spirv::execution_mode::PixelInterlockOrderedEXT(); nbl::hlsl::spirv::beginInvocationInterlockEXT(); const uint32_t packedData = pseudoStencil[fragCoord]; @@ -399,6 +396,7 @@ float32_t4 calculateFinalColor(const uint2 fragCoord, const float localAlp return color; } +[[vk::spvexecutionmode(spv::ExecutionModePixelInterlockOrderedEXT)]] [shader("pixel")] float4 fragmentMain(PSInput input) : SV_TARGET { diff --git a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl index 3fea2def6..570c1fbd2 100644 --- a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl @@ -1,6 +1,3 @@ - -#pragma shader_stage(fragment) - struct PSInputDebug { float4 position : SV_Position; From 20e120ca9aa60a32cd10d793dd6d3a5dd0c16321 Mon Sep 17 00:00:00 2001 From: Ali Cheraghi Date: Wed, 29 Jan 2025 13:00:10 +0100 Subject: [PATCH 5/6] 62_CAD: now it works --- 62_CAD/main.cpp | 18 ++++++++++-------- .../{vs_fs.hlsl => fragment.hlsl} | 7 ++++--- .../shaders/main_pipeline/fragment_shader.hlsl | 2 +- .../main_pipeline/fragment_shader_debug.hlsl | 2 +- .../shaders/main_pipeline/resolve_alphas.hlsl | 7 +++---- .../shaders/main_pipeline/vertex_shader.hlsl | 3 +-- 6 files changed, 20 insertions(+), 19 deletions(-) rename 62_CAD/shaders/main_pipeline/{vs_fs.hlsl => fragment.hlsl} (67%) diff --git a/62_CAD/main.cpp b/62_CAD/main.cpp index 9fd8190ac..e9cff5c50 100644 --- a/62_CAD/main.cpp +++ b/62_CAD/main.cpp @@ -861,8 +861,8 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu pipelineLayout = m_device->createPipelineLayout({}, core::smart_refctd_ptr(descriptorSetLayout0), core::smart_refctd_ptr(descriptorSetLayout1), nullptr, nullptr); } - smart_refctd_ptr mainPipelineShader = {}; - smart_refctd_ptr mainPipelineResolveAlphasShader = {}; + smart_refctd_ptr mainPipelineFragmentShaders = {}; + smart_refctd_ptr mainPipelineVertexShader = {}; std::array, 2u> geoTexturePipelineShaders = {}; { smart_refctd_ptr shaderReadCache = nullptr; @@ -916,10 +916,12 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu return m_device->createShader({ cpuShader.get(), nullptr, shaderReadCache.get(), shaderWriteCache.get() }); }; - mainPipelineShader = loadCompileAndCreateShader("../shaders/main_pipeline/vs_fs.hlsl", IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY); - mainPipelineResolveAlphasShader = loadCompileAndCreateShader("../shaders/main_pipeline/resolve_alphas.hlsl", IShader::E_SHADER_STAGE::ESS_FRAGMENT); + mainPipelineFragmentShaders = loadCompileAndCreateShader("../shaders/main_pipeline/fragment.hlsl", IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY); + mainPipelineVertexShader = loadCompileAndCreateShader("../shaders/main_pipeline/vertex_shader.hlsl", IShader::E_SHADER_STAGE::ESS_VERTEX); geoTexturePipelineShaders[0] = loadCompileAndCreateShader(GeoTextureRenderer::VertexShaderRelativePath, IShader::E_SHADER_STAGE::ESS_VERTEX); geoTexturePipelineShaders[1] = loadCompileAndCreateShader(GeoTextureRenderer::FragmentShaderRelativePath, IShader::E_SHADER_STAGE::ESS_FRAGMENT); + + mainPipelineFragmentShaders->setShaderStage(IShader::E_SHADER_STAGE::ESS_FRAGMENT); core::smart_refctd_ptr shaderWriteCacheFile; { @@ -963,7 +965,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 = { .shader = mainPipelineResolveAlphasShader.get() }; + const IGPUShader::SSpecInfo fragSpec = { .entryPoint = "resolveAlphaMain", .shader = mainPipelineFragmentShaders.get() }; resolveAlphaGraphicsPipeline = fsTriangleProtoPipe.createPipeline(fragSpec, pipelineLayout.get(), compatibleRenderPass.get(), 0u, blendParams); if (!resolveAlphaGraphicsPipeline) @@ -976,12 +978,12 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu IGPUShader::SSpecInfo specInfo[2] = { { - .entryPoint = "vertMain", - .shader = mainPipelineShader.get() + .entryPoint = "main", + .shader = mainPipelineVertexShader.get() }, { .entryPoint = "fragMain", - .shader = mainPipelineShader.get() + .shader = mainPipelineFragmentShaders.get() }, }; diff --git a/62_CAD/shaders/main_pipeline/vs_fs.hlsl b/62_CAD/shaders/main_pipeline/fragment.hlsl similarity index 67% rename from 62_CAD/shaders/main_pipeline/vs_fs.hlsl rename to 62_CAD/shaders/main_pipeline/fragment.hlsl index 78a588e83..cdd0d652d 100644 --- a/62_CAD/shaders/main_pipeline/vs_fs.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment.hlsl @@ -1,3 +1,4 @@ -#include "vertex_shader.hlsl" -#include "fragment_shader.hlsl" -#include "fragment_shader_debug.hlsl" +#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 365079658..215482e5e 100644 --- a/62_CAD/shaders/main_pipeline/fragment_shader.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment_shader.hlsl @@ -398,7 +398,7 @@ float32_t4 calculateFinalColor(const uint2 fragCoord, const float localAlp [[vk::spvexecutionmode(spv::ExecutionModePixelInterlockOrderedEXT)]] [shader("pixel")] -float4 fragmentMain(PSInput input) : SV_TARGET +float4 fragMain(PSInput input) : SV_TARGET { float localAlpha = 0.0f; ObjectType objType = input.getObjType(); diff --git a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl index 570c1fbd2..7dba46dd0 100644 --- a/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl +++ b/62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl @@ -7,7 +7,7 @@ struct PSInputDebug }; [shader("pixel")] -float4 fragmentDebugMain(PSInputDebug input) : SV_TARGET +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 087f49235..b4d8fe2ec 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]; @@ -41,7 +38,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); } diff --git a/62_CAD/shaders/main_pipeline/vertex_shader.hlsl b/62_CAD/shaders/main_pipeline/vertex_shader.hlsl index 2cf0d95ed..50d056eae 100644 --- a/62_CAD/shaders/main_pipeline/vertex_shader.hlsl +++ b/62_CAD/shaders/main_pipeline/vertex_shader.hlsl @@ -85,8 +85,7 @@ void dilateHatch(out float2 outOffsetVec, out float2 outUV, const float2 // Or optionally we could dilate and stuff when we know this hatch is opaque (alpha = 1.0) } -[shader("vertex")] -PSInput vertMain(uint vertexID : SV_VertexID) +PSInput main(uint vertexID : SV_VertexID) { const uint vertexIdx = vertexID & 0x3u; const uint objectID = vertexID >> 2; From 1abda13ceee3a3a8c238e47caff6d744cd561fbf Mon Sep 17 00:00:00 2001 From: Ali Cheraghi Date: Thu, 20 Feb 2025 02:06:18 +0330 Subject: [PATCH 6/6] CAD: use `device->compileShader` Signed-off-by: Ali Cheraghi --- 62_CAD/main.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/62_CAD/main.cpp b/62_CAD/main.cpp index e9cff5c50..fc3cfb3cd 100644 --- a/62_CAD/main.cpp +++ b/62_CAD/main.cpp @@ -897,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(); @@ -909,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() }); }; - mainPipelineFragmentShaders = loadCompileAndCreateShader("../shaders/main_pipeline/fragment.hlsl", IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY); - mainPipelineVertexShader = loadCompileAndCreateShader("../shaders/main_pipeline/vertex_shader.hlsl", IShader::E_SHADER_STAGE::ESS_VERTEX); - 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->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; {