Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions 62_CAD/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<smart_refctd_ptr<IGPUShader>, 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<IGPUShader> mainPipelineFragmentShaders = {};
smart_refctd_ptr<IGPUShader> mainPipelineVertexShader = {};
std::array<smart_refctd_ptr<IGPUShader>, 2u> geoTexturePipelineShaders = {};
{
smart_refctd_ptr<IShaderCompiler::CCache> shaderReadCache = nullptr;
Expand Down Expand Up @@ -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<IGPUShader>
auto loadCompileShader = [&](const std::string& relPath, IShader::E_SHADER_STAGE stage) -> smart_refctd_ptr<ICPUShader>
{
IAssetLoader::SAssetLoadParams lp = {};
lp.logger = m_logger.get();
Expand All @@ -914,19 +909,23 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu

// lets go straight from ICPUSpecializedShader to IGPUSpecializedShader
auto cpuShader = IAsset::castDown<ICPUShader>(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<system::IFile> shaderWriteCacheFile;
{
Expand Down Expand Up @@ -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)
Expand All @@ -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] = {};
Expand All @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions 62_CAD/shaders/main_pipeline/fragment.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "fragment_shader.hlsl"
#include "fragment_shader_debug.hlsl"
#include "resolve_alphas.hlsl"

9 changes: 3 additions & 6 deletions 62_CAD/shaders/main_pipeline/fragment_shader.hlsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma shader_stage(fragment)

#include "common.hlsl"
#include <nbl/builtin/hlsl/shapes/beziers.hlsl>
#include <nbl/builtin/hlsl/shapes/line.hlsl>
Expand Down Expand Up @@ -359,8 +357,6 @@ template<>
float32_t4 calculateFinalColor<true>(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];
Expand Down Expand Up @@ -405,8 +401,9 @@ float32_t4 calculateFinalColor<true>(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
Expand Down
8 changes: 3 additions & 5 deletions 62_CAD/shaders/main_pipeline/fragment_shader_debug.hlsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@

#pragma shader_stage(fragment)

struct PSInput
struct PSInputDebug
{
float4 position : SV_Position;
[[vk::location(0)]] float4 color : COLOR;
[[vk::location(1)]] nointerpolation float4 start_end : COLOR1;
[[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;
Expand Down
7 changes: 3 additions & 4 deletions 62_CAD/shaders/main_pipeline/resolve_alphas.hlsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma shader_stage(fragment)

#include "common.hlsl"
#include <nbl/builtin/hlsl/spirv_intrinsics/fragment_shader_pixel_interlock.hlsl>
#include <nbl/builtin/hlsl/jit/device_capabilities.hlsl>
Expand All @@ -19,7 +17,6 @@ float32_t4 calculateFinalColor<true>(const uint2 fragCoord)
{
float32_t4 color;

nbl::hlsl::spirv::execution_mode::PixelInterlockOrderedEXT();
nbl::hlsl::spirv::beginInvocationInterlockEXT();

const uint32_t packedData = pseudoStencil[fragCoord];
Expand Down Expand Up @@ -54,7 +51,9 @@ float32_t4 calculateFinalColor<true>(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<nbl::hlsl::jit::device_capabilities::fragmentShaderPixelInterlock>(position.xy);
}