Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Error Fixes #886

Merged
merged 13 commits into from
Feb 6, 2025
Merged
4 changes: 2 additions & 2 deletions .github/actions/linux_setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ runs:
shell: bash
run: |
sudo apt-get install -y mesa-vulkan-drivers
wget "https://sdk.lunarg.com/sdk/download/${{ inputs.sdkVersion }}/linux/vulkan-sdk-linux-x86_64-${{ inputs.sdkVersion }}.tar.gz?Human=true" -O vulkan-sdk.tar.gz
tar xf vulkan-sdk.tar.gz
wget "https://sdk.lunarg.com/sdk/download/${{ inputs.sdkVersion }}/linux/vulkansdk-linux-x86_64-${{ inputs.sdkVersion }}.tar.xz" -O vulkan-sdk.tar.xz
tar xf vulkan-sdk.tar.xz
mv ${{ inputs.sdkVersion }} ${{ github.workspace }}/VulkanSDK

echo "VULKAN_SDK=${{ github.workspace }}/VulkanSDK/x86_64" >> $GITHUB_ENV
Expand Down
26 changes: 17 additions & 9 deletions resources/shaders/PPEnd.psh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

Texture2D ColorSinks[];
Texture2D DepthSinks[];
Texture2D PostProcessSinks[];
SamplerState ColorSinks_sampler; // By convention, texture samplers must use the '_sampler' suffix

cbuffer SinkIndices
{
uint colorRT1;
uint colorRT2;
uint colorRT3;
uint colorRT4;
uint depthRT1;
uint depthRT2;
uint depthRT3;
uint depthRT4;
int colorRT1;
int colorRT2;
int colorRT3;
int colorRT4;
int depthRT1;
int depthRT2;
int depthRT3;
uint hasPostProcess;
};

struct PSInput
Expand All @@ -32,5 +33,12 @@ struct PSOutput

void main(in PSInput PSIn, out PSOutput PSOut)
{
PSOut.Color = ColorSinks[colorRT1].Sample(ColorSinks_sampler, PSIn.UV);;
if (hasPostProcess == 1)
{
PSOut.Color = PostProcessSinks[0].Sample(ColorSinks_sampler, PSIn.UV);
}
else
{
PSOut.Color = ColorSinks[colorRT1].Sample(ColorSinks_sampler, PSIn.UV);
}
}
19 changes: 10 additions & 9 deletions resources/shaders/PPFxaa.psh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Texture2D ColorSinks[];
Texture2D DepthSinks[];
Texture2D PostProcessSinks[];
SamplerState ColorSinks_sampler; // By convention, texture samplers must use the '_sampler' suffix

cbuffer EnvironmentProperties
Expand All @@ -16,14 +17,14 @@ cbuffer EnvironmentProperties

cbuffer SinkIndices
{
uint colorRT1;
uint colorRT2;
uint colorRT3;
uint colorRT4;
uint depthRT1;
uint depthRT2;
uint depthRT3;
uint depthRT4;
int colorRT1;
int colorRT2;
int colorRT3;
int colorRT4;
int depthRT1;
int depthRT2;
int depthRT3;
uint hasPostProcess;
};

struct PSInput
Expand All @@ -50,7 +51,7 @@ void main(in PSInput PSIn, out PSOutput PSOut)
{
// Alias the resource names
SamplerState smplr = ColorSinks_sampler;
Texture2D colorTex = ColorSinks[colorRT1];
Texture2D colorTex = PostProcessSinks[0];
float4 sceneColor = colorTex.Sample(smplr, PSIn.UV);

// Get screen dimensions
Expand Down
16 changes: 8 additions & 8 deletions resources/shaders/PPOutline.psh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ cbuffer EnvironmentProperties

cbuffer SinkIndices
{
uint colorRT1;
uint colorRT2;
uint colorRT3;
uint colorRT4;
uint depthRT1;
uint depthRT2;
uint depthRT3;
uint depthRT4;
int colorRT1;
int colorRT2;
int colorRT3;
int colorRT4;
int depthRT1;
int depthRT2;
int depthRT3;
uint hasPostProcess;
};

cbuffer OutlinePassProperties
Expand Down
39 changes: 0 additions & 39 deletions resources/shaders/PPWave.psh

This file was deleted.

8 changes: 4 additions & 4 deletions sample/source/scenes/PhysicsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,10 @@ auto BuildVehicle(ecs::Ecs world) -> Entity
const auto wheelBR = world.Emplace<Entity>({.position = brPosition, .scale = wheelScale, .parent = car, .tag = "BR"});
const auto carMesh = world.Emplace<Entity>({.scale = carScale, .parent = car, .tag = "CarMesh"});

world.Emplace<StaticMesh>(wheelFL, mesh::Wheel, material::Yellow);
world.Emplace<StaticMesh>(wheelFR, mesh::Wheel, material::Yellow);
world.Emplace<StaticMesh>(wheelBL, mesh::Wheel, material::Yellow);
world.Emplace<StaticMesh>(wheelBR, mesh::Wheel, material::Yellow);
world.Emplace<StaticMesh>(wheelFL, mesh::Wheel, material::Orange);
world.Emplace<StaticMesh>(wheelFR, mesh::Wheel, material::Orange);
world.Emplace<StaticMesh>(wheelBL, mesh::Wheel, material::Orange);
world.Emplace<StaticMesh>(wheelBR, mesh::Wheel, material::Orange);
world.Emplace<StaticMesh>(carMesh, mesh::Cube, material::Green);

CharacterEntities.push_back(car);
Expand Down
84 changes: 57 additions & 27 deletions source/ncengine/graphics2/NcGraphicsImpl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,83 +166,94 @@ NcGraphicsImpl2::NcGraphicsImpl2(const config::GraphicsSettings& graphicsSetting
.name = "Depth",
.type = PassType::Material,
.shaderPaths = ShaderPaths{.vertexShaderPath = "Toon.vsh"},
.depthSink = MainDepth,
.isMsaa = false
.depthSink = DepthTarget::Main,
.isMsaa = false,
.useDepthTest = true
},
PassDesc{
.id = MaterialPassFlag::Depth,
.name = "Depth",
.type = PassType::SkinnedMaterial,
.shaderPaths = ShaderPaths{.vertexShaderPath = "ToonSkinned.vsh"},
.depthSink = MainDepth,
.isMsaa = false
.depthSink = DepthTarget::Main,
.isMsaa = false,
.useDepthTest = true
},
PassDesc{
.id = MaterialPassFlag::Toon,
.name = "Toon",
.type = PassType::Material,
.shaderPaths = ShaderPaths{"Toon.psh", "Toon.vsh"},
.colorSink = MainColorMsaa,
.depthSink = MainDepthMsaa
.colorSink = ColorTarget::Main,
.depthSink = DepthTarget::Main,
.useDepthTest = true

},
PassDesc{
.id = MaterialPassFlag::Toon,
.name = "ToonSkinned",
.type = PassType::SkinnedMaterial,
.shaderPaths = ShaderPaths{"Toon.psh", "ToonSkinned.vsh"},
.colorSink = MainColorMsaa,
.depthSink = MainDepthMsaa
.colorSink = ColorTarget::Main,
.depthSink = DepthTarget::Main,
.useDepthTest = true
},
PassDesc{
.id = MaterialPassFlag::Normals,
.name = "Normals",
.type = PassType::Material,
.shaderPaths = ShaderPaths{"Normals.psh", "Toon.vsh"},
.colorSink = NormalsColorMsaa,
.depthSink = MainDepthMsaa
.colorSink = ColorTarget::Normals,
.depthSink = DepthTarget::Main,
.useDepthTest = true
},
PassDesc{
.id = MaterialPassFlag::Normals,
.name = "NormalsSkinned",
.type = PassType::SkinnedMaterial,
.shaderPaths = ShaderPaths{"Normals.psh", "ToonSkinned.vsh"},
.colorSink = NormalsColorMsaa,
.depthSink = MainDepthMsaa
.colorSink = ColorTarget::Normals,
.depthSink = DepthTarget::Main,
.useDepthTest = true
},
PassDesc{
.id = MiscPassFlag::Wireframe,
.name = "Wireframe",
.type = PassType::Wireframe,
.shaderPaths = ShaderPaths{"Wireframe.psh", "Wireframe.vsh"},
.colorSink = MainColorMsaa,
.depthSink = MainDepthMsaa
.colorSink = ColorTarget::Main,
.depthSink = DepthTarget::Main,
.useDepthTest = true
},
PassDesc{
.id = MiscPassFlag::Particle,
.name = "Particle",
.type = PassType::Particle,
.shaderPaths = ShaderPaths{"Particle.psh", "Particle.vsh"},
.colorSink = MainColor,
.depthSink = MainDepth
.colorSink = ColorTarget::Main,
.depthSink = DepthTarget::Main,
.useDepthTest = true
},
PassDesc{
.id = PostProcessPassFlag::Outline,
.name = "Post Process Outline",
.type = PassType::PostProcess,
.shaderPaths = ShaderPaths{"PPOutline.psh", "PostProcess.vsh"},
.colorSources = std::vector{MainColor, NormalsColor},
.depthSources = SingleSource(MainDepth),
.colorSink = PPOutlineColor,
.isMsaa = false
.colorSources = std::vector{ColorTarget::Main, ColorTarget::Normals},
.depthSources = std::vector{DepthTarget::Main},
.postProcessSink = PostProcessTarget::PPOutline,
.isMsaa = false,
.useDepthTest = false
},
PassDesc{
.id = PostProcessPassFlag::Fxaa,
.name = "Post Process FXAA",
.type = PassType::PostProcess,
.shaderPaths = ShaderPaths{"PPFxaa.psh", "PostProcess.vsh"},
.colorSources = std::vector{PPOutlineColor},
.colorSink = PPFxaaColor,
.isMsaa = false
.postProcessSource = PostProcessTarget::PPOutline,
.postProcessSink = PostProcessTarget::PPFxaa,
.isMsaa = false,
.useDepthTest = false
}
},
GetImplementedMaterialPassFlags(),
Expand All @@ -251,6 +262,7 @@ NcGraphicsImpl2::NcGraphicsImpl2(const config::GraphicsSettings& graphicsSetting
},
m_passBackend{
m_engine.GetDevice(),
m_engine.GetContext(),
m_engine.GetSwapChain(),
m_engine.GetShaderFactory(),
m_shaderBindings,
Expand All @@ -277,7 +289,8 @@ NcGraphicsImpl2::NcGraphicsImpl2(const config::GraphicsSettings& graphicsSetting
},
m_onResizeConnection{window.OnResize().Connect(this, &NcGraphicsImpl2::OnResize)},
m_resizeNeeded{false},
m_numSamples{m_engine.GetDeviceCapability().msaaSampleCount}
m_numSamples{m_engine.GetDeviceCapability().msaaSampleCount},
m_isMinimized{false}
{
}

Expand Down Expand Up @@ -385,6 +398,11 @@ void NcGraphicsImpl2::Run()
Resize();
}

if (m_isMinimized)
{
return;
}

auto& context = m_engine.GetContext();
auto& device = m_engine.GetDevice();
auto& swapChain = m_engine.GetSwapChain();
Expand Down Expand Up @@ -429,6 +447,12 @@ void NcGraphicsImpl2::Run()
m_shaderBindings.GetPerFrameSignature()
);

m_passBackend.RenderOutputToSwapchain(
context,
swapChain,
m_shaderBindings.GetPerPassSignature()
);

m_ui.Render(context);

swapChain.Present();
Expand All @@ -438,7 +462,13 @@ void NcGraphicsImpl2::Run()

void NcGraphicsImpl2::OnResize(const Vector2& dimensions, bool isMinimized)
{
if (isMinimized) return;
if (isMinimized)
{
m_isMinimized = true;
return;
}

m_isMinimized = false;
m_engine.GetSwapChain().Resize(static_cast<uint32_t>(dimensions.x), static_cast<uint32_t>(dimensions.y));
m_resizeNeeded = true;
m_dimensions = dimensions;
Expand All @@ -449,8 +479,8 @@ void NcGraphicsImpl2::Resize()
const auto width = static_cast<uint32_t>(m_dimensions.x);
const auto height = static_cast<uint32_t>(m_dimensions.y);
m_engine.GetSwapChain().Resize(width, height);
m_shaderBindings.GetPerPassSignature().GetColorSinkBufferResource().Resize(m_engine.GetDevice(), width, height, m_numSamples);
m_shaderBindings.GetPerPassSignature().GetDepthSinkBufferResource().Resize(m_engine.GetDevice(), width, height, m_numSamples);
m_shaderBindings.GetPerPassSignature().GetColorSinksResource().Resize(m_engine.GetDevice(), m_engine.GetContext(), width, height, m_numSamples);
m_shaderBindings.GetPerPassSignature().GetDepthSinksResource().Resize(m_engine.GetDevice(), m_engine.GetContext(), width, height, m_numSamples);
m_resizeNeeded = false;
}
} // namespace graphics
Expand Down
1 change: 1 addition & 0 deletions source/ncengine/graphics2/NcGraphicsImpl2.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class NcGraphicsImpl2 : public NcGraphics
Vector2 m_dimensions;
bool m_resizeNeeded;
uint32_t m_numSamples;
bool m_isMinimized;
};
} // namespace graphics
} // namespace nc
16 changes: 8 additions & 8 deletions source/ncengine/graphics2/ShaderTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ struct OutlinePassData
// Object model for specifying the index into the color and depth offscreen render target arrays. Limited to four of each type of index
struct PostProcessSinkIndexData
{
uint32_t colorRenderTargetIndex1;
uint32_t colorRenderTargetIndex2;
uint32_t colorRenderTargetIndex3;
uint32_t colorRenderTargetIndex4;
uint32_t depthRenderTargetIndex1;
uint32_t depthRenderTargetIndex2;
uint32_t depthRenderTargetIndex3;
uint32_t depthRenderTargetIndex4;
int32_t colorRenderTargetIndex1;
int32_t colorRenderTargetIndex2;
int32_t colorRenderTargetIndex3;
int32_t colorRenderTargetIndex4;
int32_t depthRenderTargetIndex1;
int32_t depthRenderTargetIndex2;
int32_t depthRenderTargetIndex3;
uint32_t hasPostProcessTarget;
};

// Object model for StaticMeshes (type: StructuredBuffer element type).
Expand Down
1 change: 1 addition & 0 deletions source/ncengine/graphics2/diligent/pass/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ target_sources(${NC_ENGINE_LIB}
PRIVATE
MaterialPass.cpp
ParticlePass.cpp
Pass.cpp
PassBackend.cpp
PassManifest.cpp
PassUtilities.cpp
Expand Down
Loading