aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-08-23 12:53:37 +0200
committerj-p <jp_bruyere@hotmail.com>2019-08-28 11:32:06 +0200
commit28e25d4c9f0ec82f2c7b4eeb63aba7f0c6d4e91f (patch)
tree23ce5a09799691f8ace90354f716e0358287e64c
parent3ebbf86e007af2ab49f5e50d8b36f63e00c29c81 (diff)
save comit before image modif
-rw-r--r--Directory.Build.props17
-rw-r--r--VK/vulkan.csproj9
-rw-r--r--samples/Model/Model.csproj34
-rw-r--r--samples/Model/data/DamagedHelmet.binbin0 -> 558504 bytes
-rw-r--r--samples/Model/data/DamagedHelmet.gltf204
-rw-r--r--samples/Model/main.cs259
-rw-r--r--samples/Model/shaders/model.frag72
-rw-r--r--samples/Model/shaders/model.vert44
-rw-r--r--samples/Textured/Textured.csproj8
-rw-r--r--samples/Textured/main.cs46
-rw-r--r--samples/TexturedCube/TexturedCube.csproj7
-rw-r--r--samples/TexturedCube/main.cs2
-rw-r--r--samples/Triangle/Triangle.csproj5
-rw-r--r--samples/Triangle/main.cs9
-rw-r--r--samples/compute/compute.csproj7
-rw-r--r--samples/deferred/deferred.csproj7
-rw-r--r--samples/deferred/main.cs4
-rw-r--r--samples/pbr/main.cs8
-rw-r--r--samples/pbr/pbr.csproj7
-rw-r--r--vk.generator/vk.generator.csproj7
-rw-r--r--vk.net.sln11
-rw-r--r--vk.rewrite/vk.rewrite.csproj5
-rw-r--r--vke/CVKL.csproj11
-rw-r--r--vke/src/base/Buffer.cs2
-rw-r--r--vke/src/base/DescriptorSetLayout.cs4
-rw-r--r--vke/src/base/Image.cs2
-rw-r--r--vke/src/ktx.cs50
-rw-r--r--vke/src/model/Model.cs60
-rw-r--r--vke/src/model/PbrModelSeparateTextures.cs8
-rw-r--r--vke/src/model/PbrModelTexArray.cs4
-rw-r--r--vke/src/model/glTFLoader.cs48
31 files changed, 805 insertions, 156 deletions
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..756aa73
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,17 @@
+<Project>
+ <PropertyGroup>
+ <RootDirectory>$(MSBuildThisFileDirectory)</RootDirectory>
+ <Deterministic>true</Deterministic>
+
+ <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+
+ <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
+ <License>MIT</License>
+ <Authors>Jean-Philippe Bruyère</Authors>
+
+ <LangVersion>7.2</LangVersion>
+
+ <!--<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>-->
+ </PropertyGroup>
+ <!--<Import Project="netfx.props" />-->
+</Project>
diff --git a/VK/vulkan.csproj b/VK/vulkan.csproj
index c28391f..9e7c9ee 100644
--- a/VK/vulkan.csproj
+++ b/VK/vulkan.csproj
@@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
-
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<Copyright></Copyright>
<AssemblyVersion>0.1.4</AssemblyVersion>
<AssemblyName>VK</AssemblyName>
@@ -16,10 +14,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageProjectUrl>https://github.com/jpbruyere/vk.net/blob/master/README.md</PackageProjectUrl>
<PackageLicense>https://opensource.org/licenses/MIT</PackageLicense>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
<!--<PackageIconUrl>https://github.com/KhronosGroup/glTF/blob/master/specification/figures/gltf.png</PackageIconUrl>-->
-
- <Authors>Jean-Philippe Bruyère</Authors>
<SynchReleaseVersion>false</SynchReleaseVersion>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
</PropertyGroup>
diff --git a/samples/Model/Model.csproj b/samples/Model/Model.csproj
new file mode 100644
index 0000000..df98d01
--- /dev/null
+++ b/samples/Model/Model.csproj
@@ -0,0 +1,34 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
+ <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
+ <OutputType>Exe</OutputType>
+ <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ </PropertyGroup>
+
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DefineConstants>TRACE;DEBUG;NETSTANDARD;NETSTANDARD2_0</DefineConstants>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ </PropertyGroup>
+
+ <ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
+ <Reference Include="System" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <PackageReference Include="glTF2Loader" Version="1.1.3-alpha" />
+ <PackageReference Include="Vulkan" Version="0.1.3" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\vke\CVKL.csproj" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <GLSLShader Include="shaders\**\*.frag;shaders\**\*.vert" />
+ <None Remove="shaders\**\*.frag;shaders\**\*.vert" />
+ </ItemGroup>
+
+ <Import Project="$(SolutionDir)spirv.targets" />
+</Project>
diff --git a/samples/Model/data/DamagedHelmet.bin b/samples/Model/data/DamagedHelmet.bin
new file mode 100644
index 0000000..662eacc
--- /dev/null
+++ b/samples/Model/data/DamagedHelmet.bin
Binary files differ
diff --git a/samples/Model/data/DamagedHelmet.gltf b/samples/Model/data/DamagedHelmet.gltf
new file mode 100644
index 0000000..c61145a
--- /dev/null
+++ b/samples/Model/data/DamagedHelmet.gltf
@@ -0,0 +1,204 @@
+{
+ "accessors" : [
+ {
+ "bufferView" : 0,
+ "componentType" : 5123,
+ "count" : 46356,
+ "max" : [
+ 14555
+ ],
+ "min" : [
+ 0
+ ],
+ "type" : "SCALAR"
+ },
+ {
+ "bufferView" : 1,
+ "componentType" : 5126,
+ "count" : 14556,
+ "max" : [
+ 0.9424954056739807,
+ 0.8128451108932495,
+ 0.900973916053772
+ ],
+ "min" : [
+ -0.9474585652351379,
+ -1.18715500831604,
+ -0.9009949564933777
+ ],
+ "type" : "VEC3"
+ },
+ {
+ "bufferView" : 2,
+ "componentType" : 5126,
+ "count" : 14556,
+ "max" : [
+ 1.0,
+ 1.0,
+ 1.0
+ ],
+ "min" : [
+ -1.0,
+ -1.0,
+ -1.0
+ ],
+ "type" : "VEC3"
+ },
+ {
+ "bufferView" : 3,
+ "componentType" : 5126,
+ "count" : 14556,
+ "max" : [
+ 0.9999759793281555,
+ 1.998665988445282
+ ],
+ "min" : [
+ 0.002448640065267682,
+ 1.0005531199858524
+ ],
+ "type" : "VEC2"
+ }
+ ],
+ "asset" : {
+ "generator" : "Khronos Blender glTF 2.0 exporter",
+ "version" : "2.0"
+ },
+ "bufferViews" : [
+ {
+ "buffer" : 0,
+ "byteLength" : 92712,
+ "byteOffset" : 0,
+ "target" : 34963
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 174672,
+ "byteOffset" : 92712,
+ "target" : 34962
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 174672,
+ "byteOffset" : 267384,
+ "target" : 34962
+ },
+ {
+ "buffer" : 0,
+ "byteLength" : 116448,
+ "byteOffset" : 442056,
+ "target" : 34962
+ }
+ ],
+ "buffers" : [
+ {
+ "byteLength" : 558504,
+ "uri" : "DamagedHelmet.bin"
+ }
+ ],
+ "images" : [
+ {
+ "uri" : "Default_albedo.jpg"
+ },
+ {
+ "uri" : "Default_metalRoughness.jpg"
+ },
+ {
+ "uri" : "Default_emissive.jpg"
+ },
+ {
+ "uri" : "Default_AO.jpg"
+ },
+ {
+ "uri" : "Default_normal.jpg"
+ }
+ ],
+ "materials" : [
+ {
+ "emissiveFactor" : [
+ 1.0,
+ 1.0,
+ 1.0
+ ],
+ "emissiveTexture" : {
+ "index" : 2
+ },
+ "name" : "Material_MR",
+ "normalTexture" : {
+ "index" : 4
+ },
+ "occlusionTexture" : {
+ "index" : 3
+ },
+ "pbrMetallicRoughness" : {
+ "baseColorTexture" : {
+ "index" : 0
+ },
+ "metallicRoughnessTexture" : {
+ "index" : 1
+ }
+ }
+ }
+ ],
+ "meshes" : [
+ {
+ "name" : "mesh_helmet_LP_13930damagedHelmet",
+ "primitives" : [
+ {
+ "attributes" : {
+ "NORMAL" : 2,
+ "POSITION" : 1,
+ "TEXCOORD_0" : 3
+ },
+ "indices" : 0,
+ "material" : 0
+ }
+ ]
+ }
+ ],
+ "nodes" : [
+ {
+ "mesh" : 0,
+ "name" : "node_damagedHelmet_-6514",
+ "rotation" : [
+ 0.7071068286895752,
+ 0.0,
+ -0.0,
+ 0.7071068286895752
+ ]
+ }
+ ],
+ "samplers" : [
+ {}
+ ],
+ "scene" : 0,
+ "scenes" : [
+ {
+ "name" : "Scene",
+ "nodes" : [
+ 0
+ ]
+ }
+ ],
+ "textures" : [
+ {
+ "sampler" : 0,
+ "source" : 0
+ },
+ {
+ "sampler" : 0,
+ "source" : 1
+ },
+ {
+ "sampler" : 0,
+ "source" : 2
+ },
+ {
+ "sampler" : 0,
+ "source" : 3
+ },
+ {
+ "sampler" : 0,
+ "source" : 4
+ }
+ ]
+}
diff --git a/samples/Model/main.cs b/samples/Model/main.cs
new file mode 100644
index 0000000..95a6e90
--- /dev/null
+++ b/samples/Model/main.cs
@@ -0,0 +1,259 @@
+using System.Collections.Generic;
+using System.Numerics;
+using System.Runtime.InteropServices;
+using CVKL;
+using VK;
+
+namespace ModelSample {
+ class Program : VkWindow {
+ static void Main (string[] args) {
+
+ Instance.VALIDATION = true;
+ //Instance.DEBUG_UTILS = true;
+ //Instance.RENDER_DOC_CAPTURE = true;
+
+ using (Program vke = new Program ()) {
+ vke.Run ();
+ }
+ }
+
+ struct Matrices {
+ public Matrix4x4 projection;
+ public Matrix4x4 view;
+ public Matrix4x4 model;
+ //public Vector4 lightPos;
+ }
+
+ public struct PushConstants {
+ public Matrix4x4 matrix;
+ }
+
+ Matrices matrices;
+
+ HostBuffer uboMats;
+
+ DescriptorPool descriptorPool;
+ DescriptorSet dsMatrices, dsTextures;
+ DescriptorSetLayout descLayoutMatrix;
+ DescriptorSetLayout descLayoutTextures;
+
+ Framebuffer[] frameBuffers;
+
+ GraphicPipeline pipeline;
+
+ VkSampleCountFlags NUM_SAMPLES = VkSampleCountFlags.SampleCount1;
+
+ float rotSpeed = 0.01f, zoomSpeed = 0.01f;
+ float rotX, rotY, rotZ = 0f, zoom = 2f;
+
+ SimpleModel helmet;
+ DebugReport dbgReport;
+
+ Program () : base () {
+ //dbgReport = new DebugReport (instance);
+
+ descriptorPool = new DescriptorPool (dev, 2,
+ new VkDescriptorPoolSize (VkDescriptorType.UniformBuffer),
+ new VkDescriptorPoolSize (VkDescriptorType.CombinedImageSampler, 3));
+
+ descLayoutMatrix = new DescriptorSetLayout (dev,
+ new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Vertex, VkDescriptorType.UniformBuffer));
+
+ descLayoutTextures = new DescriptorSetLayout (dev,
+ new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
+ new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
+ new VkDescriptorSetLayoutBinding (2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler)
+ );
+
+
+ VkPushConstantRange pushConstantRange = new VkPushConstantRange {
+ stageFlags = VkShaderStageFlags.Vertex,
+ size = (uint)Marshal.SizeOf<PushConstants>(),
+ offset = 0
+ };
+
+ GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, NUM_SAMPLES);
+ cfg.rasterizationState.cullMode = VkCullModeFlags.Back;
+ if (NUM_SAMPLES != VkSampleCountFlags.SampleCount1) {
+ cfg.multisampleState.sampleShadingEnable = true;
+ cfg.multisampleState.minSampleShading = 0.5f;
+ }
+
+ cfg.Layout = new PipelineLayout (dev, pushConstantRange, descLayoutMatrix, descLayoutTextures);
+ cfg.RenderPass = new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), cfg.Samples);
+ cfg.AddVertexBinding<Model.Vertex> (0);
+ cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, VkFormat.R32g32b32Sfloat, VkFormat.R32g32Sfloat);
+
+ cfg.AddShader (VkShaderStageFlags.Vertex, "shaders/model.vert.spv");
+ cfg.AddShader (VkShaderStageFlags.Fragment, "shaders/model.frag.spv");
+
+ pipeline = new GraphicPipeline (cfg);
+
+ helmet = new SimpleModel (presentQueue, "data/models/DamagedHelmet/glTF/DamagedHelmet.gltf");
+ //helmet = new SimpleModel (presentQueue, "data/models/Hubble.glb");
+
+ //helmet = new SimpleModel (presentQueue, "/mnt/devel/vulkan/Lugdunum/resources/models/Box.gltf");
+
+ dsMatrices = descriptorPool.Allocate (descLayoutMatrix);
+ dsTextures = descriptorPool.Allocate (descLayoutTextures);
+
+ uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices);
+ //matrices.lightPos = new Vector4 (0.0f, 0.0f, -2.0f, 1.0f);
+
+ DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMatrices, descLayoutMatrix);
+ uboUpdate.Write (dev, uboMats.Descriptor);
+
+ DescriptorSetWrites texturesUpdate = new DescriptorSetWrites (dsTextures, descLayoutTextures);
+ texturesUpdate.Write (dev,
+ helmet.textures[0].Descriptor,
+ helmet.textures[1].Descriptor,
+ helmet.textures[2].Descriptor);
+
+ uboMats.Map ();//permanent map
+ }
+
+ public override void UpdateView () {
+ matrices.projection = Matrix4x4.CreatePerspectiveFieldOfView (Utils.DegreesToRadians (45f),
+ (float)swapChain.Width / (float)swapChain.Height, 0.1f, 256.0f) * Camera.VKProjectionCorrection;
+ matrices.view =
+ Matrix4x4.CreateFromAxisAngle (Vector3.UnitZ, rotZ) *
+ Matrix4x4.CreateFromAxisAngle (Vector3.UnitY, rotY) *
+ Matrix4x4.CreateFromAxisAngle (Vector3.UnitX, rotX) *
+ Matrix4x4.CreateTranslation (0, 0, -3f * zoom);
+ matrices.model = Matrix4x4.Identity;
+ uboMats.Update (matrices, (uint)Marshal.SizeOf<Matrices> ());
+ updateViewRequested = false;
+ }
+
+ protected override void onMouseMove (double xPos, double yPos) {
+ double diffX = lastMouseX - xPos;
+ double diffY = lastMouseY - yPos;
+ if (MouseButton[0]) {
+ rotY -= rotSpeed * (float)diffX;
+ rotX += rotSpeed * (float)diffY;
+ } else if (MouseButton[1]) {
+ zoom += zoomSpeed * (float)diffY;
+ }
+ updateViewRequested = true;
+ }
+ void buildCommandBuffers () {
+ cmdPool.Reset (VkCommandPoolResetFlags.ReleaseResources);
+ cmds = cmdPool.AllocateCommandBuffer (swapChain.ImageCount);
+
+ for (int i = 0; i < swapChain.ImageCount; ++i) {
+ Framebuffer fb = frameBuffers[i];
+ cmds[i].Start ();
+
+ pipeline.RenderPass.Begin (cmds[i], fb);
+
+ cmds[i].SetViewport (swapChain.Width, swapChain.Height);
+ cmds[i].SetScissor (swapChain.Width, swapChain.Height);
+
+ cmds[i].BindDescriptorSet (pipeline.Layout, dsMatrices);
+ cmds[i].BindDescriptorSet (pipeline.Layout, dsTextures, 1);
+
+ PushConstants pc = new PushConstants { matrix = Matrix4x4.Identity };
+ cmds[i].PushConstant (pipeline.Layout, VkShaderStageFlags.Vertex, pc, (uint)Marshal.SizeOf<Matrix4x4> ());
+
+ cmds[i].BindPipeline (pipeline);
+
+ helmet.DrawAll (cmds[i], pipeline.Layout);
+
+ pipeline.RenderPass.End (cmds[i]);
+
+ cmds[i].End ();
+ }
+ }
+
+ protected override void OnResize () {
+
+ if (frameBuffers != null)
+ for (int i = 0; i < swapChain.ImageCount; ++i)
+ frameBuffers[i]?.Dispose ();
+ frameBuffers = new Framebuffer[swapChain.ImageCount];
+
+ for (int i = 0; i < swapChain.ImageCount; ++i)
+ frameBuffers[i] = new Framebuffer (pipeline.RenderPass, swapChain.Width, swapChain.Height,
+ (pipeline.Samples == VkSampleCountFlags.SampleCount1) ? new Image[] {
+ swapChain.images[i],
+ null
+ } : new Image[] {
+ null,
+ null,
+ swapChain.images[i]
+ });
+
+ buildCommandBuffers ();
+ }
+
+ class SimpleModel : Model {
+ public GPUBuffer vbo;
+ public GPUBuffer ibo;
+ public Image[] textures;
+
+ public SimpleModel (Queue transferQ, string path) {
+ dev = transferQ.Dev;
+
+ using (CommandPool cmdPool = new CommandPool (dev, transferQ.index)) {
+ using (CVKL.glTFLoader ctx = new CVKL.glTFLoader (path, transferQ, cmdPool)) {
+ ulong vertexCount, indexCount;
+
+ ctx.GetVertexCount (out vertexCount, out indexCount, out IndexBufferType);
+
+ ulong vertSize = vertexCount * (ulong)Marshal.SizeOf<Vertex> ();
+ ulong idxSize = indexCount * (IndexBufferType == VkIndexType.Uint16 ? 2ul : 4ul);
+ ulong size = vertSize + idxSize;
+
+ vbo = new GPUBuffer (dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, vertSize);
+ ibo = new GPUBuffer (dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, idxSize);
+
+ vbo.SetName ("vbo gltf");
+ ibo.SetName ("ibo gltf");
+
+ Meshes = new List<Mesh> (ctx.LoadMeshes<Vertex> (IndexBufferType, vbo, 0, ibo, 0));
+ Scenes = new List<Scene> (ctx.LoadScenes (out defaultSceneIndex));
+
+ textures = ctx.LoadImages ();
+ }
+ }
+ }
+ /// <summary> bind vertex and index buffers </summary>
+ public virtual void Bind (CommandBuffer cmd) {
+ cmd.BindVertexBuffer (vbo);
+ cmd.BindIndexBuffer (ibo, IndexBufferType);
+ }
+ public void DrawAll (CommandBuffer cmd, PipelineLayout pipelineLayout) {
+ //helmet.Meshes
+ cmd.BindVertexBuffer (vbo);
+ cmd.BindIndexBuffer (ibo, IndexBufferType);
+ cmd.DrawIndexed ((uint)Meshes[0].Primitives[0].indexCount);
+ //foreach (Scene sc in Scenes) {
+ // foreach (Node node in sc.Root.Children)
+ // RenderNode (cmd, pipelineLayout, node, sc.Root.localMatrix, shadowPass);
+ //}
+ }
+ }
+
+ protected override void Dispose (bool disposing) {
+ if (disposing) {
+ if (!isDisposed) {
+ helmet.vbo.Dispose ();
+ helmet.ibo.Dispose ();
+ foreach (var t in helmet.textures)
+ t.Dispose ();
+
+ pipeline.Dispose ();
+ descLayoutMatrix.Dispose ();
+ descLayoutTextures.Dispose ();
+ for (int i = 0; i < swapChain.ImageCount; i++)
+ frameBuffers[i]?.Dispose ();
+ descriptorPool.Dispose ();
+ uboMats.Dispose ();
+ dbgReport?.Dispose ();
+ }
+ }
+
+ base.Dispose (disposing);
+ }
+ }
+}
diff --git a/samples/Model/shaders/model.frag b/samples/Model/shaders/model.frag
new file mode 100644
index 0000000..351f156
--- /dev/null
+++ b/samples/Model/shaders/model.frag
@@ -0,0 +1,72 @@
+#version 450
+
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout (set = 1, binding = 0) uniform sampler2D samplerColor;
+layout (set = 1, binding = 1) uniform sampler2D samplerNormal;
+layout (set = 1, binding = 2) uniform sampler2D samplerOcclusion;
+
+layout (location = 0) in vec2 inUV;
+layout (location = 1) in vec3 inN;
+layout (location = 2) in vec3 inV;//ViewDir
+
+layout (location = 0) out vec4 outFragColor;
+
+vec3 light = vec3(1.0,.0,1.0);
+
+// http://www.thetenthplanet.de/archives/1180
+mat3 cotangent_frame(vec3 N, vec3 p, vec2 uv)
+{
+ // get edge vectors of the pixel triangle
+ vec3 dp1 = dFdx( p );
+ vec3 dp2 = dFdy( p );
+ vec2 duv1 = dFdx( uv );
+ vec2 duv2 = dFdy( uv );
+
+ // solve the linear system
+ vec3 dp2perp = cross( dp2, N );
+ vec3 dp1perp = cross( N, dp1 );
+ vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;
+ vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;
+
+ // construct a scale-invariant frame
+ float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );
+ return mat3( T * invmax, B * invmax, N );
+}
+
+vec3 perturb_normal( vec3 N, vec3 V, vec2 texcoord )
+{
+ // assume N, the interpolated vertex normal and
+ // V, the view vector (vertex to eye)
+ vec3 map = texture(samplerNormal, texcoord).xyz;
+ map = map * 255./127. - 128./127.;
+ mat3 TBN = cotangent_frame(N, -V, texcoord);
+ return normalize(TBN * map);
+}
+
+
+
+void main()
+{
+ vec4 diff = texture(samplerColor, inUV);
+
+ vec3 n = normalize(inN);
+ vec3 l = normalize(light);
+ vec3 pn = perturb_normal(n, inV, inUV);
+
+ float lambert = max(0.0, dot(pn, l));
+
+ //diff.rgb *= lambert * texture(samplerOcclusion, inUV).rgb;
+ vec3 spec = vec3(0);
+ vec3 amb = vec3(0.1);
+ if (lambert >= 0.0) {
+ vec3 rd = reflect(l, pn);
+ float s = dot(rd, normalize(inV));
+ spec = vec3(0.9,0.9,0.9)* //light.specular.xyz * material.specular.xyz *
+ pow(max(0.0, s), 0.5); //0.5 = mat shininess
+ }
+ //outFragColor = vec4(1.0); //
+ //outFragColor = vec4(diff.rgb , 1.0); //
+ outFragColor = vec4(diff.rgb + amb + spec , diff.a); //
+} \ No newline at end of file
diff --git a/samples/Model/shaders/model.vert b/samples/Model/shaders/model.vert
new file mode 100644
index 0000000..d63c794
--- /dev/null
+++ b/samples/Model/shaders/model.vert
@@ -0,0 +1,44 @@
+#version 450
+
+#extension GL_ARB_separate_shader_objects : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+layout (location = 0) in vec3 inPos;
+layout (location = 1) in vec3 inNormal;
+layout (location = 2) in vec2 inUV;
+
+layout (binding = 0) uniform UBO
+{
+ mat4 projectionMatrix;
+ mat4 viewMatrix;
+ mat4 modelMatrix;
+} ubo;
+
+layout (location = 0) out vec2 outUV;
+layout (location = 1) out vec3 outN;
+layout (location = 2) out vec3 outV;//ViewDir
+
+out gl_PerVertex
+{
+ vec4 gl_Position;
+};
+
+layout(push_constant) uniform PushConsts {
+ mat4 model;
+} pc;
+
+void main()
+{
+ outUV = inUV;
+
+ mat4 mod = ubo.modelMatrix;// * pc.model;
+ vec4 pos = mod * vec4(inPos.xyz, 1.0);
+
+ //outN = normalize(transpose(inverse(mat3(mod))) * inNormal);
+ outN = normalize(mat3(mod)* inNormal);
+
+ mat4 viewInv = inverse(ubo.viewMatrix);
+ outV = -(ubo.viewMatrix * pos).xyz;//normalize(vec3(viewInv * vec4(0.0, 0.0, 0.0, 1.0) - pos));
+
+ gl_Position = ubo.projectionMatrix * ubo.viewMatrix * pos;
+}
diff --git a/samples/Textured/Textured.csproj b/samples/Textured/Textured.csproj
index 6d93943..16716c7 100644
--- a/samples/Textured/Textured.csproj
+++ b/samples/Textured/Textured.csproj
@@ -1,11 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
@@ -35,6 +32,7 @@
<Datas Include="..\data\**\*.*">
<Link>data\%(RecursiveDir)%(Filename)%(Extension)</Link>
</Datas>
+ <None Remove="mono_crash.1adb363697.0.json" />
</ItemGroup>
<Import Project="$(SolutionDir)spirv.targets" />
diff --git a/samples/Textured/main.cs b/samples/Textured/main.cs
index a1c792f..c765ea6 100644
--- a/samples/Textured/main.cs
+++ b/samples/Textured/main.cs
@@ -5,17 +5,21 @@ using Glfw;
using CVKL;
using VK;
using Buffer = CVKL.Buffer;
+using System.IO;
namespace TextureSample {
class Program : VkWindow {
static void Main (string[] args) {
+ Instance.VALIDATION = true;
+ Instance.DEBUG_UTILS = true;
using (Program vke = new Program ()) {
vke.Run ();
}
}
protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures features) {
base.configureEnabledFeatures (available_features, ref features);
- features.textureCompressionBC = available_features.textureCompressionBC;
+ //features.textureCompressionBC = available_features.textureCompressionBC;
+ features.textureCompressionASTC_LDR = available_features.textureCompressionASTC_LDR;
}
float rotSpeed = 0.01f, zoomSpeed = 0.01f;
@@ -52,12 +56,24 @@ namespace TextureSample {
ushort[] indices = { 0, 1, 2, 2, 0, 3 };
int currentImgIndex = 0;
string[] imgPathes = {
+ "/mnt/devel/vulkan/vulkanExUpstream/data/textures/trail_astc_8x8_unorm.ktx",
+ //"data/textures/tex.astc",
+ "data/textures/tex256.jpg",
"data/textures/texture.jpg",
"data/textures/rgba-reference.ktx",
"data/textures/texturearray_rocks_bc3_unorm.ktx",
};
-
+
+ DebugReport dbgReport;
+
Program () : base () {
+ dbgReport = new DebugReport (instance,
+ VkDebugReportFlagsEXT.DebugEXT|
+ VkDebugReportFlagsEXT.ErrorEXT |
+ VkDebugReportFlagsEXT.WarningEXT |
+ VkDebugReportFlagsEXT.PerformanceWarningEXT |
+ VkDebugReportFlagsEXT.InformationEXT);
+
vbo = new GPUBuffer<float> (presentQueue, cmdPool, VkBufferUsageFlags.VertexBuffer, vertices);
ibo = new GPUBuffer<ushort> (presentQueue, cmdPool, VkBufferUsageFlags.IndexBuffer, indices);
@@ -88,10 +104,8 @@ namespace TextureSample {
descriptorSet = descriptorPool.Allocate (dsLayout);
- using (DescriptorSetWrites2 uboUpdate = new DescriptorSetWrites2 (dev)) {
- uboUpdate.AddWriteInfo (descriptorSet, dsLayout.Bindings[0], uboMats.Descriptor);
- uboUpdate.Update ();
- }
+ DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descriptorSet, dsLayout.Bindings[0]);
+ uboUpdate.Write (dev, uboMats.Descriptor);
loadTexture (imgPathes[currentImgIndex]);
updateTextureSet ();
@@ -129,11 +143,17 @@ namespace TextureSample {
//in the thread of the keyboard
void loadTexture (string path) {
- if (path.EndsWith("ktx", StringComparison.OrdinalIgnoreCase))
+ if (path.EndsWith ("ktx", StringComparison.OrdinalIgnoreCase))
nextTexture = KTX.KTX.Load (presentQueue, cmdPool, path,
- VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, true);
+ VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, true, VkImageTiling.Optimal);
+ /*else if (path.EndsWith ("astc", StringComparison.OrdinalIgnoreCase)) {
+ using (Stream str = File.OpenRead (path)) {
+ str.Length
+ nextTexture = Image.Load (dev, presentQueue, cmdPool, str, VkFormat.Astc6x6UnormBlock, VkMemoryPropertyFlags.DeviceLocal, VkImageTiling.Optimal, false);
+ }
+ } */
else
- nextTexture = Image.Load (dev, path);
+ nextTexture = Image.Load (dev, presentQueue, cmdPool, path, VkFormat.R8g8b8a8Unorm, VkMemoryPropertyFlags.DeviceLocal, VkImageTiling.Optimal, false);
updateViewRequested = true;
}
@@ -143,10 +163,9 @@ namespace TextureSample {
nextTexture.CreateSampler ();
nextTexture.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
- using (DescriptorSetWrites2 uboUpdate = new DescriptorSetWrites2 (dev)) {
- uboUpdate.AddWriteInfo (descriptorSet, dsLayout.Bindings[1], nextTexture.Descriptor);
- uboUpdate.Update ();
- }
+
+ DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descriptorSet, dsLayout.Bindings[1]);
+ uboUpdate.Write (dev, nextTexture.Descriptor);
texture?.Dispose ();
texture = nextTexture;
@@ -240,6 +259,7 @@ namespace TextureSample {
vbo.Dispose ();
ibo.Dispose ();
uboMats.Dispose ();
+ dbgReport.Dispose ();
}
}
diff --git a/samples/TexturedCube/TexturedCube.csproj b/samples/TexturedCube/TexturedCube.csproj
index 6dfe9a1..170d601 100644
--- a/samples/TexturedCube/TexturedCube.csproj
+++ b/samples/TexturedCube/TexturedCube.csproj
@@ -1,11 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
diff --git a/samples/TexturedCube/main.cs b/samples/TexturedCube/main.cs
index 7a8c7b6..96ef778 100644
--- a/samples/TexturedCube/main.cs
+++ b/samples/TexturedCube/main.cs
@@ -157,7 +157,7 @@ namespace TextureCube {
nextTexture = KTX.KTX.Load (presentQueue, cmdPool, path,
VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, true);
else
- nextTexture = Image.Load (dev, path);
+ nextTexture = Image.StbLoad (dev, path);
updateViewRequested = true;
}
diff --git a/samples/Triangle/Triangle.csproj b/samples/Triangle/Triangle.csproj
index 9d4fbf3..d3956b0 100644
--- a/samples/Triangle/Triangle.csproj
+++ b/samples/Triangle/Triangle.csproj
@@ -1,11 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../../netfx.props" />
+ <Import Project="$(RootDirectory)netfx.props" />
<PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
diff --git a/samples/Triangle/main.cs b/samples/Triangle/main.cs
index 27f9838..9a6b397 100644
--- a/samples/Triangle/main.cs
+++ b/samples/Triangle/main.cs
@@ -1,4 +1,7 @@
-using System.Numerics;
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System.Numerics;
using System.Runtime.InteropServices;
using CVKL;
using VK;
@@ -6,7 +9,7 @@ using VK;
namespace Triangle {
class Program : VkWindow {
static void Main (string[] args) {
- Instance.RENDER_DOC_CAPTURE = true;
+ //Instance.RENDER_DOC_CAPTURE = true;
Instance.VALIDATION = true;
using (Program vke = new Program ()) {
@@ -73,6 +76,8 @@ namespace Triangle {
pipeline = new GraphicPipeline (cfg);
+ //note that descriptor set is allocated after the pipeline creation that use this layout, layout is activated
+ //automaticaly on pipeline creation.
descriptorSet = descriptorPool.Allocate (dsLayout);
DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descriptorSet, dsLayout);
uboUpdate.Write (dev, uboMats.Descriptor);
diff --git a/samples/compute/compute.csproj b/samples/compute/compute.csproj
index 09e76c4..1a8629c 100644
--- a/samples/compute/compute.csproj
+++ b/samples/compute/compute.csproj
@@ -1,11 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
diff --git a/samples/deferred/deferred.csproj b/samples/deferred/deferred.csproj
index ae60085..d98f4cc 100644
--- a/samples/deferred/deferred.csproj
+++ b/samples/deferred/deferred.csproj
@@ -1,11 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs
index e7c843d..13bf08c 100644
--- a/samples/deferred/main.cs
+++ b/samples/deferred/main.cs
@@ -13,9 +13,9 @@ namespace deferred {
//Instance.RENDER_DOC_CAPTURE = true;
DeferredPbrRenderer.TEXTURE_ARRAY = true;
- DeferredPbrRenderer.NUM_SAMPLES = VkSampleCountFlags.SampleCount4;
+ DeferredPbrRenderer.NUM_SAMPLES = VkSampleCountFlags.SampleCount1;
- PbrModelTexArray.TEXTURE_DIM = 1024;
+ PbrModelTexArray.TEXTURE_DIM = 512;
using (Deferred vke = new Deferred ()) {
vke.Run ();
diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs
index 53c6342..692779c 100644
--- a/samples/pbr/main.cs
+++ b/samples/pbr/main.cs
@@ -13,8 +13,10 @@ using VK;
using CVKL;
namespace pbrSample {
- class Program : VkWindow{
+ class Program : VkWindow{
+
static void Main (string[] args) {
+ Instance.VALIDATION = true;
using (Program vke = new Program ()) {
vke.Run ();
}
@@ -24,10 +26,10 @@ namespace pbrSample {
#if PIPELINE_STATS
features.pipelineStatisticsQuery = true;
#endif
- features.samplerAnisotropy = true;
+ features.samplerAnisotropy = available_features.samplerAnisotropy;
}
- VkSampleCountFlags samples = VkSampleCountFlags.SampleCount4;
+ VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1;
Framebuffer[] frameBuffers;
PBRPipeline pbrPipeline;
diff --git a/samples/pbr/pbr.csproj b/samples/pbr/pbr.csproj
index b7830aa..96274aa 100644
--- a/samples/pbr/pbr.csproj
+++ b/samples/pbr/pbr.csproj
@@ -1,11 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultCompileItems>true</EnableDefaultCompileItems>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
diff --git a/vk.generator/vk.generator.csproj b/vk.generator/vk.generator.csproj
index 00a5935..00dbf3c 100644
--- a/vk.generator/vk.generator.csproj
+++ b/vk.generator/vk.generator.csproj
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
diff --git a/vk.net.sln b/vk.net.sln
index 677f959..5da6981 100644
--- a/vk.net.sln
+++ b/vk.net.sln
@@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "compute", "samples\compute\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pbr", "samples\pbr\pbr.csproj", "{790642C5-7AD1-437D-9F9C-3F721133AFEF}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "samples\Model\Model.csproj", "{0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -103,6 +105,14 @@ Global
{790642C5-7AD1-437D-9F9C-3F721133AFEF}.DebugCrow|Any CPU.ActiveCfg = Debug|Any CPU
{790642C5-7AD1-437D-9F9C-3F721133AFEF}.DebugCrow|Any CPU.Build.0 = Debug|Any CPU
{790642C5-7AD1-437D-9F9C-3F721133AFEF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.temp|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.temp|Any CPU.Build.0 = Debug|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.DebugCrow|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385}.DebugCrow|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{96A2E0B8-91AE-4EB9-A435-185D01E24067} = {A2A2849A-0032-4AA8-BC0E-82C69D7DE354}
@@ -112,6 +122,7 @@ Global
{BFF1BEEC-2E93-4963-AD3C-2A8C9BA05C36} = {A2A2849A-0032-4AA8-BC0E-82C69D7DE354}
{05515E15-D3C3-4A8C-A940-9467D9D77823} = {A2A2849A-0032-4AA8-BC0E-82C69D7DE354}
{790642C5-7AD1-437D-9F9C-3F721133AFEF} = {A2A2849A-0032-4AA8-BC0E-82C69D7DE354}
+ {0E4346C3-87C0-4C0A-8CDB-DBF1E29F5385} = {A2A2849A-0032-4AA8-BC0E-82C69D7DE354}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
diff --git a/vk.rewrite/vk.rewrite.csproj b/vk.rewrite/vk.rewrite.csproj
index 804d8ca..d54b4ed 100644
--- a/vk.rewrite/vk.rewrite.csproj
+++ b/vk.rewrite/vk.rewrite.csproj
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../netfx.props" />
+ <Import Project="$(RootDirectory)netfx.props" />
<PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
- <License>https://opensource.org/licenses/MIT</License>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
diff --git a/vke/CVKL.csproj b/vke/CVKL.csproj
index c9fd9a3..ff861c2 100644
--- a/vke/CVKL.csproj
+++ b/vke/CVKL.csproj
@@ -1,8 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="../netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
-
+ <Import Project="$(RootDirectory)netfx.props" />
+ <PropertyGroup>
<Copyright></Copyright>
<AssemblyVersion>0.1.5</AssemblyVersion>
<Description>C# vulkan library with IDispose model and references counting</Description>
@@ -16,13 +14,10 @@
<PackageProjectUrl>https://github.com/jpbruyere/vk.net/blob/master/README.md</PackageProjectUrl>
<PackageLicense>https://opensource.org/licenses/MIT</PackageLicense>
<PackageReleaseNotes></PackageReleaseNotes>
- <RepositoryUrl>https://github.com/jpbruyere/vk.net</RepositoryUrl>
<!--<PackageIconUrl>https://github.com/KhronosGroup/glTF/blob/master/specification/figures/gltf.png</PackageIconUrl>-->
- <Authors>Jean-Philippe Bruyère</Authors>
<SynchReleaseVersion>false</SynchReleaseVersion>
<AssemblyName>CVKL</AssemblyName>
- <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
- <LangVersion>7.2</LangVersion>
+ <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
diff --git a/vke/src/base/Buffer.cs b/vke/src/base/Buffer.cs
index d80ad57..c43eda0 100644
--- a/vke/src/base/Buffer.cs
+++ b/vke/src/base/Buffer.cs
@@ -70,7 +70,7 @@ namespace CVKL {
img.SetLayout (cmd, VkImageAspectFlags.Color,
VkImageLayout.TransferDstOptimal, finalLayout,
- VkPipelineStageFlags.Transfer, VkPipelineStageFlags.AllGraphics);
+ VkPipelineStageFlags.Transfer, VkPipelineStageFlags.Transfer);
}
public void CopyTo (CommandBuffer cmd, Buffer buff, ulong size = 0, ulong srcOffset = 0, ulong dstOffset = 0) {
VkBufferCopy bufferCopy = new VkBufferCopy {
diff --git a/vke/src/base/DescriptorSetLayout.cs b/vke/src/base/DescriptorSetLayout.cs
index 01c6d7e..f63e5e2 100644
--- a/vke/src/base/DescriptorSetLayout.cs
+++ b/vke/src/base/DescriptorSetLayout.cs
@@ -7,6 +7,10 @@ using VK;
using static VK.Vk;
namespace CVKL {
+ /// <summary>
+ /// Descriptor set layout, automatically activated when used in pipeline creation, so don't allocate descriptor sets using
+ /// this layout unless it has been activated.
+ /// </summary>
public sealed class DescriptorSetLayout : Activable {
internal VkDescriptorSetLayout handle;
diff --git a/vke/src/base/Image.cs b/vke/src/base/Image.cs
index 9b0e5e6..06cec8f 100644
--- a/vke/src/base/Image.cs
+++ b/vke/src/base/Image.cs
@@ -542,7 +542,7 @@ namespace CVKL {
VkImageSubresourceRange mipSubRange = new VkImageSubresourceRange (VkImageAspectFlags.Color, 0, 1, 0, info.arrayLayers);
SetLayout (cmd, VkImageLayout.Undefined, VkImageLayout.TransferSrcOptimal, mipSubRange,
- VkPipelineStageFlags.Transfer, VkPipelineStageFlags.Transfer);
+ VkPipelineStageFlags.BottomOfPipe, VkPipelineStageFlags.Transfer);
for (int i = 1; i < info.mipLevels; i++) {
VkImageBlit imageBlit = new VkImageBlit {
diff --git a/vke/src/ktx.cs b/vke/src/ktx.cs
index 227328d..4c71dff 100644
--- a/vke/src/ktx.cs
+++ b/vke/src/ktx.cs
@@ -70,10 +70,10 @@ namespace KTX {
if (vkFormat == VkFormat.Undefined)
throw new KtxException ("Undefined format: " + ktxPath);
}
-
+ VkFormatProperties formatProperties = staggingQ.Dev.phy.GetFormatProperties (vkFormat);
VkFormatFeatureFlags phyFormatSupport = (tiling == VkImageTiling.Linear) ?
- staggingQ.Dev.phy.GetFormatProperties (vkFormat).linearTilingFeatures :
- staggingQ.Dev.phy.GetFormatProperties (vkFormat).optimalTilingFeatures;
+ formatProperties.linearTilingFeatures :
+ formatProperties.optimalTilingFeatures;
uint requestedMipsLevels = numberOfMipmapLevels;
if (numberOfMipmapLevels == 1)
@@ -119,7 +119,6 @@ namespace KTX {
if (memoryProperty.HasFlag (VkMemoryPropertyFlags.DeviceLocal)) {
ulong staggingSize = img.AllocatedDeviceMemorySize;
-
using (HostBuffer stagging = new HostBuffer (staggingQ.Dev, VkBufferUsageFlags.TransferSrc, staggingSize)) {
stagging.Map ();
@@ -144,7 +143,7 @@ namespace KTX {
UInt32 imgSize = br.ReadUInt32 ();
bufferCopyRegion.bufferImageHeight = imgWidth;
- bufferCopyRegion.bufferRowLength = imgHeight;
+ bufferCopyRegion.bufferRowLength = 0; //imgHeight;
bufferCopyRegion.bufferOffset = bufferOffset;
if (createFlags.HasFlag (VkImageCreateFlags.CubeCompatible)) {
@@ -189,28 +188,29 @@ namespace KTX {
}
//for (int mips = 0; mips < numberOfMipmapLevels; mips++) {
- //UInt32 imgSize = br.ReadUInt32 ();
- /*VkImageBlit imageBlit = new VkImageBlit {
- srcSubresource = new VkImageSubresourceLayers(VkImageAspectFlags.Color, numberOfArrayElements, (uint)mips - 1),
- srcOffsets_1 = new VkOffset3D((int)pixelWidth >> (mips - 1), (int)pixelHeight >> (mips - 1),1),
- dstSubresource = new VkImageSubresourceLayers (VkImageAspectFlags.Color, numberOfArrayElements, (uint)mips),
- dstOffsets_1 = new VkOffset3D ((int)pixelWidth >> mips, (int)pixelHeight >> mips, 1),
- };*/
- //for (int layer = 0; layer < numberOfArrayElements; layer++) {
- //for (int face = 0; face < numberOfFaces; face++) {
- //for (int slice = 0; slice < pixelDepth; slice++) {
- /*for (int y = 0; y < pixelHeight; y++) {
- for (int x = 0; x < pixelWidth; x++) {
- //Uncompressed texture data matches a GL_UNPACK_ALIGNMENT of 4.
- }
- }*/
- //}
- //Byte cubePadding[0-3]
- //}
- //}
- //Byte mipPadding[0-3]
+ //UInt32 imgSize = br.ReadUInt32 ();
+ /*VkImageBlit imageBlit = new VkImageBlit {
+ srcSubresource = new VkImageSubresourceLayers(VkImageAspectFlags.Color, numberOfArrayElements, (uint)mips - 1),
+ srcOffsets_1 = new VkOffset3D((int)pixelWidth >> (mips - 1), (int)pixelHeight >> (mips - 1),1),
+ dstSubresource = new VkImageSubresourceLayers (VkImageAspectFlags.Color, numberOfArrayElements, (uint)mips),
+ dstOffsets_1 = new VkOffset3D ((int)pixelWidth >> mips, (int)pixelHeight >> mips, 1),
+ };*/
+ //for (int layer = 0; layer < numberOfArrayElements; layer++) {
+ //for (int face = 0; face < numberOfFaces; face++) {
+ //for (int slice = 0; slice < pixelDepth; slice++) {
+ /*for (int y = 0; y < pixelHeight; y++) {
+ for (int x = 0; x < pixelWidth; x++) {
+ //Uncompressed texture data matches a GL_UNPACK_ALIGNMENT of 4.
+ }
+ }*/
+ //}
+ //Byte cubePadding[0-3]
+ //}
+ //}
+ //Byte mipPadding[0-3]
//}
+ } else {
}
}
}
diff --git a/vke/src/model/Model.cs b/vke/src/model/Model.cs
index fbcea30..0bc56e8 100644
--- a/vke/src/model/Model.cs
+++ b/vke/src/model/Model.cs
@@ -28,8 +28,6 @@ using System.Collections.Generic;
using System.Numerics;
using VK;
-
-
namespace CVKL {
public enum AlphaMode : UInt32 {
@@ -37,8 +35,11 @@ namespace CVKL {
Mask,
Blend
};
- //TODO:stride in buffer views?
+ /// <summary>
+ /// Model base class, does not implement Vulkan objects (vbo, ibo, descSets,...)
+ /// </summary>
public class Model {
+ #region nested structs and classes
public struct Vertex {
[VertexAttribute (VertexAttributeType.Position, VkFormat.R32g32b32Sfloat)]
public Vector3 pos;
@@ -142,61 +143,20 @@ namespace CVKL {
return aabb;
}
}
+ #endregion
- public class Material {
- public enum Workflow { PhysicalyBaseRendering = 1, SpecularGlossinnes };
- public string Name;
- public Workflow workflow;
- public Int32 baseColorTexture;
- public Int32 metallicRoughnessTexture;
- public Int32 normalTexture;
- public Int32 occlusionTexture;
- public Int32 emissiveTexture;
-
- public Vector4 baseColorFactor;
- public Vector4 emissiveFactor;
- public AttachmentType availableAttachments;
- public AttachmentType availableAttachments1;
-
- public AlphaMode alphaMode;
- public float alphaCutoff;
- public float metallicFactor;
- public float roughnessFactor;
-
- public bool metallicRoughness = true;
- public bool specularGlossiness = false;
-
- public Material (Int32 _baseColorTexture = -1, Int32 _metallicRoughnessTexture = -1,
- Int32 _normalTexture = -1, Int32 _occlusionTexture = -1) {
- workflow = Workflow.PhysicalyBaseRendering;
- baseColorTexture = _baseColorTexture;
- metallicRoughnessTexture = _metallicRoughnessTexture;
- normalTexture = _normalTexture;
- occlusionTexture = _occlusionTexture;
- emissiveTexture = -1;
-
- alphaMode = AlphaMode.Opaque;
- alphaCutoff = 1f;
- metallicFactor = 1f;
- roughnessFactor = 1;
- baseColorFactor = new Vector4 (1);
- emissiveFactor = new Vector4 (1);
-
- metallicRoughness = true;
- specularGlossiness = false;
-
- }
- }
protected Device dev;
+ protected int defaultSceneIndex;
public VkIndexType IndexBufferType;
- protected int defaultSceneIndex;
public Scene DefaultScene => Scenes[defaultSceneIndex];
public List<Mesh> Meshes;
public List<Scene> Scenes;
+ public Dimensions dimensions = new Dimensions (new Vector3 (float.MaxValue), new Vector3 (float.MinValue));
- public Node FindNode(string name) {
+
+ public Node FindNode(string name) {
foreach (Scene scene in Scenes)
{
Node n = scene.FindNode(name);
@@ -206,6 +166,6 @@ namespace CVKL {
return null;
}
- public Dimensions dimensions = new Dimensions (new Vector3 (float.MaxValue), new Vector3 (float.MinValue));
+
}
}
diff --git a/vke/src/model/PbrModelSeparateTextures.cs b/vke/src/model/PbrModelSeparateTextures.cs
index ae9482f..240cd79 100644
--- a/vke/src/model/PbrModelSeparateTextures.cs
+++ b/vke/src/model/PbrModelSeparateTextures.cs
@@ -42,7 +42,7 @@ namespace CVKL {
/// Pbr data structure suitable for push constant or ubo, containing
/// availablility of attached textures and the coef of pbr inputs
/// </summary>
- public new struct Material {
+ public struct Material {
public Vector4 baseColorFactor;
public Vector4 emissiveFactor;
public Vector4 diffuseFactor;
@@ -54,7 +54,9 @@ namespace CVKL {
public float roughnessFactor;
public float alphaMask;
public float alphaMaskCutoff;
- int pad0;//see std420
+#pragma warning disable 169
+ readonly int pad0;//see std420
+#pragma warning restore 169
}
Image[] textures;
@@ -95,7 +97,7 @@ namespace CVKL {
}
void loadMaterials (glTFLoader ctx, DescriptorSetLayout layout, params AttachmentType[] attachments) {
- Model.Material[] mats = ctx.LoadMaterial ();
+ glTFLoader.Material[] mats = ctx.LoadMaterial ();
materials = new Material[mats.Length];
descriptorSets = new DescriptorSet[mats.Length];
diff --git a/vke/src/model/PbrModelTexArray.cs b/vke/src/model/PbrModelTexArray.cs
index 99c6f76..162182e 100644
--- a/vke/src/model/PbrModelTexArray.cs
+++ b/vke/src/model/PbrModelTexArray.cs
@@ -43,7 +43,7 @@ namespace CVKL {
/// <summary>
/// Material structure for ubo containing texture indices in tex array
/// </summary>
- public new struct Material {
+ public struct Material {
public Vector4 baseColorFactor;
public Vector4 emissiveFactor;
public Vector4 diffuseFactor;
@@ -110,7 +110,7 @@ namespace CVKL {
}
void loadMaterials (glTFLoader ctx) {
- Model.Material[] mats = ctx.LoadMaterial ();
+ glTFLoader.Material[] mats = ctx.LoadMaterial ();
materials = new Material[mats.Length];
for (int i = 0; i < mats.Length; i++) {
diff --git a/vke/src/model/glTFLoader.cs b/vke/src/model/glTFLoader.cs
index 88d29f5..9c6dae7 100644
--- a/vke/src/model/glTFLoader.cs
+++ b/vke/src/model/glTFLoader.cs
@@ -44,6 +44,54 @@ namespace CVKL {
/// Loading context with I as the vertex index type (uint16,uint32)
/// </summary>
public class glTFLoader : IDisposable {
+ /// <summary>
+ /// Material class used by the gltfLoader to fetch values.
+ /// </summary>
+ public class Material {
+ public enum Workflow { PhysicalyBaseRendering = 1, SpecularGlossinnes };
+ public string Name;
+ public Workflow workflow;
+ public Int32 baseColorTexture;
+ public Int32 metallicRoughnessTexture;
+ public Int32 normalTexture;
+ public Int32 occlusionTexture;
+ public Int32 emissiveTexture;
+
+ public Vector4 baseColorFactor;
+ public Vector4 emissiveFactor;
+ public AttachmentType availableAttachments;
+ public AttachmentType availableAttachments1;
+
+ public AlphaMode alphaMode;
+ public float alphaCutoff;
+ public float metallicFactor;
+ public float roughnessFactor;
+
+ public bool metallicRoughness = true;
+ public bool specularGlossiness = false;
+
+ public Material (Int32 _baseColorTexture = -1, Int32 _metallicRoughnessTexture = -1,
+ Int32 _normalTexture = -1, Int32 _occlusionTexture = -1) {
+ workflow = Workflow.PhysicalyBaseRendering;
+ baseColorTexture = _baseColorTexture;
+ metallicRoughnessTexture = _metallicRoughnessTexture;
+ normalTexture = _normalTexture;
+ occlusionTexture = _occlusionTexture;
+ emissiveTexture = -1;
+
+ alphaMode = AlphaMode.Opaque;
+ alphaCutoff = 1f;
+ metallicFactor = 1f;
+ roughnessFactor = 1;
+ baseColorFactor = new Vector4 (1);
+ emissiveFactor = new Vector4 (1);
+
+ metallicRoughness = true;
+ specularGlossiness = false;
+
+ }
+ }
+
public Queue transferQ;
public CommandPool cmdPool;
Device dev => transferQ.dev;