aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-08-30 08:55:54 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-08-30 08:55:54 +0200
commitf1c2cb1c45d81cd7a30c6d0aac6e2eb70412e22d (patch)
treeac5bbfa3117b078b1a401c26eb9d09760624e0c9
parent3898aa5bf7bde8f018c8c064574ba726ddb8553f (diff)
debug, update pbr with vkvg add-on, swc image format preference
-rw-r--r--CVKL/src/VkWindow.cs5
-rw-r--r--CVKL/src/base/DescriptorSetWrites.cs2
-rw-r--r--CVKL/src/base/SwapChain.cs7
-rw-r--r--SpirVTasks/README.md6
-rw-r--r--samples/deferred/main.cs1
-rw-r--r--samples/pbr/PbrPipeline.cs8
-rw-r--r--samples/pbr/main.cs125
-rw-r--r--samples/pbr/pbr.csproj8
8 files changed, 57 insertions, 105 deletions
diff --git a/CVKL/src/VkWindow.cs b/CVKL/src/VkWindow.cs
index 3b2b953..6f5d9e4 100644
--- a/CVKL/src/VkWindow.cs
+++ b/CVKL/src/VkWindow.cs
@@ -2,12 +2,11 @@
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
-using System.Linq;
using System.Diagnostics;
+using System.Linq;
using Glfw;
using VK;
using static VK.Vk;
-using System.Collections.Generic;
namespace CVKL {
/// <summary>
@@ -121,7 +120,7 @@ namespace CVKL {
//activate the device to have effective queues created accordingly to what's available
dev.Activate (enabledFeatures, EnabledDeviceExtensions);
- swapChain = new SwapChain (presentQueue as PresentQueue, width, height, VkFormat.B8g8r8a8Unorm,
+ swapChain = new SwapChain (presentQueue as PresentQueue, width, height, SwapChain.PREFERED_FORMAT,
vSync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.MailboxKHR);
swapChain.Create ();
diff --git a/CVKL/src/base/DescriptorSetWrites.cs b/CVKL/src/base/DescriptorSetWrites.cs
index f9f1adf..b47d7d0 100644
--- a/CVKL/src/base/DescriptorSetWrites.cs
+++ b/CVKL/src/base/DescriptorSetWrites.cs
@@ -95,7 +95,7 @@ namespace CVKL {
/// </summary>
public void AddWriteInfo (VkDescriptorSetLayoutBinding[] bindings) {
foreach (VkDescriptorSetLayoutBinding binding in bindings)
- AddWriteInfo (bindings);
+ AddWriteInfo (binding);
}
/// <summary>
/// Adds write info without specifying a destination descriptor set, this imply that on calling Write, you MUST
diff --git a/CVKL/src/base/SwapChain.cs b/CVKL/src/base/SwapChain.cs
index d691ea8..0ebdb0d 100644
--- a/CVKL/src/base/SwapChain.cs
+++ b/CVKL/src/base/SwapChain.cs
@@ -29,6 +29,13 @@ using static VK.Vk;
namespace CVKL {
public class SwapChain : Activable {
+ /// <summary>
+ /// Set the default swapchain image format.
+ /// </summary>
+ public static VkFormat PREFERED_FORMAT = VkFormat.B8g8r8a8Srgb;
+ /// <summary>
+ /// Set additional usage flags for the swapchain images such as TransferDst.
+ /// </summary>
public static VkImageUsageFlags IMAGES_USAGE = VkImageUsageFlags.ColorAttachment;
internal VkSwapchainKHR handle;
diff --git a/SpirVTasks/README.md b/SpirVTasks/README.md
index 3495865..226e438 100644
--- a/SpirVTasks/README.md
+++ b/SpirVTasks/README.md
@@ -14,14 +14,13 @@
**SpirVTasks** package add **SpirV** compilation support to msbuild project. Error and warning
are routed to the **IDE**.
-#### Usage
+#### Usage
```xml
<ItemGroup>
<GLSLShader Include="shaders\*.frag;shaders\*.vert;shaders\*.comp;shaders\*.geom" />
</ItemGroup>
```
-
Resulting `.spv` files are embedded with resource ID = **ProjectName.file.ext.spv**. You can override the default resource id by adding a custom LogicalName.
```xml
<ItemGroup>
@@ -36,6 +35,8 @@ Resulting `.spv` files are embedded with resource ID = **ProjectName.file.ext.sp
<SpirVglslcPath>bin\glslc.exe</SpirVglslcPath>
</PropertyGroup>
```
+
+
#### Include in glsl
```glsl
#include <preamble.inc>
@@ -58,5 +59,4 @@ Included files are searched from the location of the current parsed file, then i
```
#### todo
-
- Error source file and line with included files.
diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs
index 2e24b37..5b74eed 100644
--- a/samples/deferred/main.cs
+++ b/samples/deferred/main.cs
@@ -14,6 +14,7 @@ namespace deferred {
Instance.DEBUG_UTILS = true;
Instance.RENDER_DOC_CAPTURE = false;
#endif
+ SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Srgb;
DeferredPbrRenderer.TEXTURE_ARRAY = true;
DeferredPbrRenderer.NUM_SAMPLES = VkSampleCountFlags.SampleCount1;
DeferredPbrRenderer.HDR_FORMAT = VkFormat.R16g16b16a16Sfloat;
diff --git a/samples/pbr/PbrPipeline.cs b/samples/pbr/PbrPipeline.cs
index 852efd5..37e2d36 100644
--- a/samples/pbr/PbrPipeline.cs
+++ b/samples/pbr/PbrPipeline.cs
@@ -44,7 +44,7 @@ namespace CVKL {
public PbrModel2 model;
public EnvironmentCube envCube;
- public PBRPipeline (Queue staggingQ, RenderPass renderPass, Image uiImage, PipelineCache pipelineCache = null) :
+ public PBRPipeline (Queue staggingQ, RenderPass renderPass, PipelineCache pipelineCache = null) :
base (renderPass, pipelineCache, "pbr pipeline") {
descriptorPool = new DescriptorPool (Dev, 2,
@@ -120,15 +120,13 @@ namespace CVKL {
AttachmentType.Emissive);
//model = new Model (Dev, presentQueue, "../data/models/icosphere.gltf");
//model = new Model (Dev, presentQueue, cmdPool, "../data/models/cube.gltf");
- DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descLayoutMain);
+ DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descLayoutMain.Bindings.GetRange(0,5).ToArray());
uboUpdate.Write (Dev, dsMain,
uboMats.Descriptor,
envCube.irradianceCube.Descriptor,
envCube.prefilterCube.Descriptor,
envCube.lutBrdf.Descriptor,
- model.materialUBO.Descriptor,
- uiImage.Descriptor);
-
+ model.materialUBO.Descriptor);
}
public void RecordDraw (CommandBuffer cmd) {
diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs
index b890489..b664c50 100644
--- a/samples/pbr/main.cs
+++ b/samples/pbr/main.cs
@@ -25,12 +25,12 @@ namespace pbrSample {
vke.Run ();
}
}
- protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures features) {
- base.configureEnabledFeatures (available_features, ref features);
+ protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures enabled_features) {
+ base.configureEnabledFeatures (available_features, ref enabled_features);
#if PIPELINE_STATS
features.pipelineStatisticsQuery = true;
#endif
- features.samplerAnisotropy = available_features.samplerAnisotropy;
+ enabled_features.samplerAnisotropy = available_features.samplerAnisotropy;
}
VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1;
@@ -55,9 +55,9 @@ namespace pbrSample {
TimestampQueryPool timestampQPool;
ulong[] results;
#endif
- bool queryUpdatePrefilCube, showDebugImg, showUI;
+ bool queryUpdatePrefilCube, showDebugImg;
- #region ui
+#if WITH_VKVG
//DescriptorSet dsDebugImg;
//void initDebugImg () {
// dsDebugImg = descriptorPool.Allocate (descLayoutMain);
@@ -65,38 +65,11 @@ namespace pbrSample {
// DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsDebugImg, descLayoutMain);
// uboUpdate.Write (dev, pbrPipeline.envCube.debugImg.Descriptor);
//}
- vkvg.Device vkvgDev;
- vkvg.Surface vkvgSurf;
- Image uiImage;
-
- Pipeline uiPipeline;
-
- void initUIPipeline () {
-
- GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, samples, false);
- cfg.RenderPass = pbrPipeline.RenderPass;
- cfg.Layout = pbrPipeline.Layout;
- cfg.AddShader (VkShaderStageFlags.Vertex, "#pbr.FullScreenQuad.vert.spv");
- cfg.AddShader (VkShaderStageFlags.Fragment, "#pbr.simpletexture.frag.spv");
- cfg.blendAttachments[0] = new VkPipelineColorBlendAttachmentState (true);
-
- uiPipeline = new GraphicPipeline (cfg);
-
- }
- void initUISurface () {
- uiImage?.Dispose ();
- vkvgSurf?.Dispose ();
- vkvgSurf = new vkvg.Surface (vkvgDev, (int)swapChain.Width, (int)swapChain.Height);
- uiImage = new Image (dev, new VkImage ((ulong)vkvgSurf.VkImage.ToInt64 ()), VkFormat.B8g8r8a8Unorm,
- VkImageUsageFlags.ColorAttachment, (uint)vkvgSurf.Width, (uint)vkvgSurf.Height);
- uiImage.CreateView (VkImageViewType.ImageView2D, VkImageAspectFlags.Color);
- uiImage.CreateSampler (VkFilter.Nearest, VkFilter.Nearest, VkSamplerMipmapMode.Nearest, VkSamplerAddressMode.ClampToBorder);
- uiImage.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
- }
+ VkvgPipeline.VkvgPipeline vkvgPipeline;
void vkvgDraw () {
- using (vkvg.Context ctx = new vkvg.Context (vkvgSurf)) {
+ using (vkvg.Context ctx = vkvgPipeline.CreateContext ()) {
ctx.Operator = vkvg.Operator.Clear;
ctx.Paint ();
ctx.Operator = vkvg.Operator.Over;
@@ -161,52 +134,27 @@ namespace pbrSample {
y += dy;
ctx.MoveTo (x, y);
ctx.ShowText (string.Format ($"{"Debug Prefil Mip: (m)",-30} : {pbrPipeline.envCube.debugMip.ToString ()} "));
- }
- }
- void recordDrawOverlay (CommandBuffer cmd) {
- uiPipeline.Bind (cmd);
- uiImage.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.ColorAttachmentOptimal, VkImageLayout.ShaderReadOnlyOptimal,
- VkPipelineStageFlags.ColorAttachmentOutput, VkPipelineStageFlags.FragmentShader);
-
- cmd.Draw (3, 1, 0, 0);
-
- uiImage.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.ShaderReadOnlyOptimal, VkImageLayout.ColorAttachmentOptimal,
- VkPipelineStageFlags.FragmentShader, VkPipelineStageFlags.BottomOfPipe);
-
- //if (!showDebugImg)
- // return;
- //const uint debugImgSize = 256;
- //const uint debugImgMargin = 10;
-
- //cmd.BindDescriptorSet (uiPipeline.Layout, dsDebugImg);
-
- //cmd.SetViewport (debugImgSize, debugImgSize, debugImgMargin, swapChain.Height - debugImgSize - debugImgMargin);
- //cmd.SetScissor (debugImgSize, debugImgSize, (int)debugImgMargin, (int)(swapChain.Height - debugImgSize - debugImgMargin));
-
- //cmd.Draw (3, 1, 0, 0);
+ vkvgPipeline.DrawResources (ctx, (int)Width, (int)Height);
+ }
}
-#endregion
+#endif
Vector4 lightPos = new Vector4 (1, 0, 0, 0);
BoundingBox modelAABB;
- Program () {
+ Program () : base() {
//UpdateFrequency = 20;
camera.SetPosition (0, 0, 5);
- vkvgDev = new vkvg.Device (instance.Handle, phy.Handle, dev.Handle, presentQueue.qFamIndex,
- vkvg.SampleCount.Sample_4, presentQueue.index);
-
- initUISurface ();
pbrPipeline = new PBRPipeline(presentQueue,
- new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples), uiImage);
+ new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples));
+
- initUIPipeline ();
modelAABB = pbrPipeline.model.DefaultScene.AABB;
@@ -222,6 +170,10 @@ namespace pbrSample {
timestampQPool = new TimestampQueryPool (dev);
#endif
+
+#if WITH_VKVG
+ vkvgPipeline = new VkvgPipeline.VkvgPipeline (instance, dev, presentQueue, pbrPipeline);
+#endif
}
bool rebuildBuffers;
@@ -249,9 +201,9 @@ namespace pbrSample {
pbrPipeline.RecordDraw (cmd);
- if (showUI)
- recordDrawOverlay (cmd);
-
+#if WITH_VKVG
+ vkvgPipeline.RecordDraw (cmd);
+#endif
pbrPipeline.RenderPass.End (cmd);
}
@@ -287,18 +239,19 @@ namespace pbrSample {
buildCommandBuffers ();
rebuildBuffers = false;
}
- if (showUI)
- vkvgDraw ();
+#if WITH_VKVG
+ vkvgDraw ();
+#endif
}
#endregion
protected override void OnResize () {
- initUISurface ();
-
- uiImage.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
- DescriptorSetWrites uboUpdate = new DescriptorSetWrites (pbrPipeline.dsMain, pbrPipeline.Layout.DescriptorSetLayouts[0].Bindings[5]);
- uboUpdate.Write (dev, uiImage.Descriptor);
+ dev.WaitIdle ();
+#if WITH_VKVG
+ vkvgPipeline.Resize ((int)swapChain.Width, (int)swapChain.Height,
+ new DescriptorSetWrites (pbrPipeline.dsMain, pbrPipeline.Layout.DescriptorSetLayouts[0].Bindings[5]));
+#endif
UpdateView ();
@@ -321,9 +274,10 @@ namespace pbrSample {
}
buildCommandBuffers ();
+ dev.WaitIdle ();
}
-#region Mouse and keyboard
+ #region Mouse and keyboard
protected override void onMouseMove (double xPos, double yPos) {
double diffX = lastMouseX - xPos;
double diffY = lastMouseY - yPos;
@@ -423,11 +377,7 @@ namespace pbrSample {
lightPos -= Vector4.UnitY;
else
camera.Move (0, -1, 0);
- break;
- case Key.F1:
- showUI = !showUI;
- rebuildBuffers = true;
- break;
+ break;
case Key.F2:
if (modifiers.HasFlag (Modifier.Shift))
pbrPipeline.matrices.exposure -= 0.3f;
@@ -453,9 +403,8 @@ namespace pbrSample {
}
updateViewRequested = true;
}
-#endregion
+ #endregion
-#region dispose
protected override void Dispose (bool disposing) {
if (disposing) {
if (!isDisposed) {
@@ -464,12 +413,9 @@ namespace pbrSample {
frameBuffers[i]?.Dispose ();
pbrPipeline.Dispose ();
-
- uiPipeline.Dispose ();
-
- uiImage?.Dispose ();
- vkvgSurf?.Dispose ();
- vkvgDev.Dispose ();
+#if WITH_VKVG
+ vkvgPipeline.Dispose ();
+#endif
#if PIPELINE_STATS
timestampQPool?.Dispose ();
@@ -480,6 +426,5 @@ namespace pbrSample {
base.Dispose (disposing);
}
-#endregion
}
}
diff --git a/samples/pbr/pbr.csproj b/samples/pbr/pbr.csproj
index 6365e75..c8eff12 100644
--- a/samples/pbr/pbr.csproj
+++ b/samples/pbr/pbr.csproj
@@ -1,16 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(RootDirectory)netfx.props" />
<PropertyGroup>
- <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
- <DefineConstants>_WITH_VKVG</DefineConstants>
+ <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="vkvg.net" Version="0.2.2-beta" />
+ <GLSLShader Update="shaders/simpletexture.frag">
+ <LogicalName>CVKL.simpletexture.frag.spv</LogicalName>
+ </GLSLShader>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\CVKL.Addons\gltfLoader\gltfLoader.csproj" />
+ <ProjectReference Include="..\..\CVKL.Addons\VkvgPipeline\VkvgPipeline.csproj" />
</ItemGroup>
<ItemGroup>