]> O.S.I.I.S - jp/vke.net.git/commitdiff
debug
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 29 Oct 2019 04:47:49 +0000 (05:47 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 29 Oct 2019 04:47:49 +0000 (05:47 +0100)
addons/gltfLoader/PbrModelTexArray.cs
addons/gltfLoader/glTFLoader.cs
vke/src/base/GraphicPipelineConfig.cs
vke/src/base/Image.cs
vke/src/base/PhysicalDevice.cs
vke/src/base/Queue.cs
vke/vke.csproj

index 8ac9d0f09a15da9913ed2598bb175f6d7b81ae54..abde06a0633895640382f32e6f43fdac90f1b7ed 100644 (file)
@@ -1,6 +1,7 @@
 // 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;
 using System.Diagnostics;
 using System.Numerics;
 using System.Runtime.InteropServices;
@@ -49,6 +50,7 @@ namespace vke.glTF {
                        public float roughnessFactor;
                        public float alphaMask;
                        public float alphaMaskCutoff;
+
                }
 
                public Image texArray;
index 50ad8dc9da1868afd0cdce36f66fa1ee87e7b76d..94fabd3ba2d8fd79d6ab8df7be5eb0cfd7e4897d 100644 (file)
@@ -87,10 +87,10 @@ namespace vke.glTF {
                        this.path = path;
                        transferQ = _transferQ;
                        cmdPool = _cmdPool;
-                       baseDirectory = System.IO.Path.GetDirectoryName (path);
-                       gltf = Interface.LoadModel (path); ;
-                       loadedBuffers = new byte[gltf.Buffers.Length][];
-                       bufferHandles = new GCHandle[gltf.Buffers.Length];
+                       baseDirectory = Path.GetDirectoryName (path);
+                       gltf = Interface.LoadModel (path);
+                       loadedBuffers = new byte [gltf.Buffers.Length] [];
+                       bufferHandles = new GCHandle [gltf.Buffers.Length];
                }
 
                static byte[] loadDataUri (GL.Image img) {
@@ -102,7 +102,7 @@ namespace vke.glTF {
                        return Convert.FromBase64String (buff.Uri.Substring (idxComa + 1));
                }
 
-               void EnsureBufferIsLoaded (int bufferIdx) {
+               void ensureBufferIsLoaded (int bufferIdx) {
                        if (loadedBuffers[bufferIdx] == null) {
                                //load full buffer
                                string uri = gltf.Buffers[bufferIdx].Uri;
@@ -143,6 +143,7 @@ namespace vke.glTF {
                public Mesh[] LoadMeshes<TVertex> (VkIndexType indexType, Buffer vbo, ulong vboOffset, Buffer ibo, ulong iboOffset) {
                        ulong vCount, iCount;
                        VkIndexType idxType;
+
                        GetVertexCount (out vCount, out iCount, out idxType);
 
                        int vertexByteSize = Marshal.SizeOf<TVertex> ();
@@ -179,19 +180,19 @@ namespace vke.glTF {
                                                        int accessorIdx;
                                                        if (p.Attributes.TryGetValue ("POSITION", out accessorIdx)) {
                                                                AccPos = gltf.Accessors[accessorIdx];
-                                                               EnsureBufferIsLoaded (gltf.BufferViews[(int)AccPos.BufferView].Buffer);
+                                                               ensureBufferIsLoaded (gltf.BufferViews[(int)AccPos.BufferView].Buffer);
                                                        }
                                                        if (p.Attributes.TryGetValue ("NORMAL", out accessorIdx)) {
                                                                AccNorm = gltf.Accessors[accessorIdx];
-                                                               EnsureBufferIsLoaded (gltf.BufferViews[(int)AccNorm.BufferView].Buffer);
+                                                               ensureBufferIsLoaded (gltf.BufferViews[(int)AccNorm.BufferView].Buffer);
                                                        }
                                                        if (p.Attributes.TryGetValue ("TEXCOORD_0", out accessorIdx)) {
                                                                AccUv = gltf.Accessors[accessorIdx];
-                                                               EnsureBufferIsLoaded (gltf.BufferViews[(int)AccUv.BufferView].Buffer);
+                                                               ensureBufferIsLoaded (gltf.BufferViews[(int)AccUv.BufferView].Buffer);
                                                        }
                                                        if (p.Attributes.TryGetValue ("TEXCOORD_1", out accessorIdx)) {
                                                                AccUv1 = gltf.Accessors[accessorIdx];
-                                                               EnsureBufferIsLoaded (gltf.BufferViews[(int)AccUv1.BufferView].Buffer);
+                                                               ensureBufferIsLoaded (gltf.BufferViews[(int)AccUv1.BufferView].Buffer);
                                                        }
 
                                                        Primitive prim = new Primitive {
@@ -228,7 +229,7 @@ namespace vke.glTF {
                                                                inUv1Ptr += AccUv1.ByteOffset + bv.ByteOffset;
                                                        }
 
-
+                                                       //TODO: use vertex attributes scan for copying data if they exists
                                                        for (int j = 0; j < prim.vertexCount; j++) {
                                                                System.Buffer.MemoryCopy (inPosPtr, stagVertPtr, 12, 12);
                                                                inPosPtr += 12;
@@ -432,7 +433,7 @@ namespace vke.glTF {
 
                                if (img.BufferView != null) {//load image from gltf buffer view
                                        GL.BufferView bv = gltf.BufferViews[(int)img.BufferView];
-                                       EnsureBufferIsLoaded (bv.Buffer);
+                                       ensureBufferIsLoaded (bv.Buffer);
                                        vkimg = Image.Load (dev, bufferHandles[bv.Buffer].AddrOfPinnedObject () + bv.ByteOffset, (ulong)bv.ByteLength, VkImageUsageFlags.TransferSrc);
                                } else if (img.Uri.StartsWith ("data:", StringComparison.Ordinal)) {//load base64 encoded image
                                        Debug.WriteLine ("loading embedded image {0} : {1}", img.Name, img.MimeType);
@@ -514,7 +515,7 @@ namespace vke.glTF {
 
                                if (img.BufferView != null) {//load image from gltf buffer view
                                        GL.BufferView bv = gltf.BufferViews[(int)img.BufferView];
-                                       EnsureBufferIsLoaded (bv.Buffer);
+                                       ensureBufferIsLoaded (bv.Buffer);
                                        vkimg = Image.Load (dev, transferQ, cmdPool, bufferHandles[bv.Buffer].AddrOfPinnedObject () + bv.ByteOffset, (ulong)bv.ByteLength);
                                } else if (img.Uri.StartsWith ("data:", StringComparison.Ordinal)) {//load base64 encoded image
                                        Debug.WriteLine ("loading embedded image {0} : {1}", img.Name, img.MimeType);
index 2b7c8d6866e049c952c5246e8e3c51f397e81578..bca8ee6b4c72d70119f8d3c65ce3aa86562a2e6f 100644 (file)
@@ -26,7 +26,7 @@ namespace vke {
                public List<VkDynamicState> dynamicStates = new List<VkDynamicState> ();
                public List<VkVertexInputBindingDescription> vertexBindings = new List<VkVertexInputBindingDescription> ();
                public List<VkVertexInputAttributeDescription> vertexAttributes = new List<VkVertexInputAttributeDescription> ();
-               public readonly List<ShaderInfo> shaders = new List<ShaderInfo> ();
+               public List<ShaderInfo> shaders = new List<ShaderInfo> ();
                public VkBool32 ColorBlendLogicOpEnable = false;
                public VkLogicOp ColorBlendLogicOp;
                public Vector4 ColorBlendConstants;
index 05276745c1e23afeebfc0ab71cdc2a7a584be35a..aa5eb440a789cd0735a3d69c7cbc6f079f289c6c 100644 (file)
@@ -33,7 +33,7 @@ namespace vke {
                public uint Height => CreateInfo.extent.height;
                public override bool IsLinar => CreateInfo.tiling == VkImageTiling.Linear;
 
-               VkImageLayout lastKnownLayout;
+               public VkImageLayout lastKnownLayout { get; private set; }
 
                protected override VkDebugMarkerObjectNameInfoEXT DebugMarkerInfo
                        => new VkDebugMarkerObjectNameInfoEXT(VkDebugReportObjectTypeEXT.ImageEXT, handle.Handle);
index c82e20eda22c6ff9088e94949eb38f0b51131f27..d08bc4f6c593b11914176054c1712e7a0b1cb8c8 100644 (file)
@@ -15,15 +15,16 @@ namespace vke {
        /// Collection of physical devices returned by the vulkan instance.
        /// </summary>
        public class PhysicalDeviceCollection : IEnumerable<PhysicalDevice> {
-        readonly VkInstance inst;
-        readonly PhysicalDevice[] phys;
+               readonly VkInstance inst;
+               readonly PhysicalDevice [] phys;
 
                /// <summary>
                /// Retrieve the physical devices available for the provided vulkan instance
                /// </summary>
                /// <param name="instance">The vulkan instance to retrieve the physical devices from.</param>
-        public PhysicalDeviceCollection (VkInstance instance) {
-            inst = instance;
+               public PhysicalDeviceCollection (VkInstance instance)
+               {
+                       inst = instance;
                        CheckResult (vkEnumeratePhysicalDevices (inst, out uint gpuCount, IntPtr.Zero));
                        if (gpuCount <= 0)
                                throw new Exception ("No GPU found");
@@ -31,26 +32,26 @@ namespace vke {
                        IntPtr gpus = Marshal.AllocHGlobal (Marshal.SizeOf<IntPtr> () * (int)gpuCount);
                        CheckResult (vkEnumeratePhysicalDevices (inst, out gpuCount, gpus), "Could not enumerate physical devices.");
 
-                       phys = new PhysicalDevice[gpuCount];
+                       phys = new PhysicalDevice [gpuCount];
 
                        for (int i = 0; i < gpuCount; i++)
-                               phys[i] = new PhysicalDevice (Marshal.ReadIntPtr (gpus + i * Marshal.SizeOf<IntPtr> ()));
+                               phys [i] = new PhysicalDevice (Marshal.ReadIntPtr (gpus + i * Marshal.SizeOf<IntPtr> ()));
 
                        Marshal.FreeHGlobal (gpus);
                }
 
-        public PhysicalDevice this[int i] => phys[i];
-        public IEnumerator<PhysicalDevice> GetEnumerator () => ((IEnumerable<PhysicalDevice>)phys).GetEnumerator ();
-        IEnumerator IEnumerable.GetEnumerator () => ((IEnumerable<PhysicalDevice>)phys).GetEnumerator ();
-    }
+               public PhysicalDevice this [int i] => phys [i];
+               public IEnumerator<PhysicalDevice> GetEnumerator () => ((IEnumerable<PhysicalDevice>)phys).GetEnumerator ();
+               IEnumerator IEnumerable.GetEnumerator () => ((IEnumerable<PhysicalDevice>)phys).GetEnumerator ();
+       }
        /// <summary>
        /// Vke class that encapsulate a physical device.
        /// </summary>
-    public class PhysicalDevice {
-        readonly IntPtr phy;
+       public class PhysicalDevice {
+               readonly IntPtr phy;
 
-        public VkPhysicalDeviceMemoryProperties memoryProperties { get; private set; }
-        public VkQueueFamilyProperties[] QueueFamilies { get; private set; }
+               public VkPhysicalDeviceMemoryProperties memoryProperties { get; private set; }
+               public VkQueueFamilyProperties [] QueueFamilies { get; private set; }
                public VkPhysicalDeviceProperties Properties {
                        get {
                                vkGetPhysicalDeviceProperties (phy, out VkPhysicalDeviceProperties pdp);
@@ -65,21 +66,23 @@ namespace vke {
                }
                public VkPhysicalDeviceLimits Limits => Properties.limits;
 
-        public bool HasSwapChainSupport { get; private set; }
-        public IntPtr Handle => phy;
+               public bool HasSwapChainSupport { get; private set; }
+               public IntPtr Handle => phy;
                public bool GetDeviceExtensionSupported (string extName) => SupportedExtensions (IntPtr.Zero).Contains (extName);
 
                #region CTOR
-               internal PhysicalDevice (IntPtr vkPhy) {
-            phy = vkPhy;
+               internal PhysicalDevice (IntPtr vkPhy)
+               {
+                       phy = vkPhy;
 
                        // Gather physical Device memory properties
                        IntPtr tmp = Marshal.AllocHGlobal (Marshal.SizeOf<VkPhysicalDeviceMemoryProperties> ());
                        vkGetPhysicalDeviceMemoryProperties (phy, tmp);
                        memoryProperties = Marshal.PtrToStructure<VkPhysicalDeviceMemoryProperties> (tmp);
+                       Marshal.FreeHGlobal (tmp);
 
                        vkGetPhysicalDeviceQueueFamilyProperties (phy, out uint queueFamilyCount, IntPtr.Zero);
-                       QueueFamilies = new VkQueueFamilyProperties[queueFamilyCount];
+                       QueueFamilies = new VkQueueFamilyProperties [queueFamilyCount];
 
                        if (queueFamilyCount <= 0)
                                throw new Exception ("No queues found for physical device");
@@ -91,17 +94,18 @@ namespace vke {
                }
                #endregion
 
-               public string[] SupportedExtensions (IntPtr layer) {
+               public string [] SupportedExtensions (IntPtr layer)
+               {
                        CheckResult (vkEnumerateDeviceExtensionProperties (phy, layer, out uint count, IntPtr.Zero));
 
                        int sizeStruct = Marshal.SizeOf<VkExtensionProperties> ();
                        IntPtr ptrSupExts = Marshal.AllocHGlobal (sizeStruct * (int)count);
                        CheckResult (vkEnumerateDeviceExtensionProperties (phy, layer, out count, ptrSupExts));
 
-                       string[] result = new string[count];
+                       string [] result = new string [count];
                        IntPtr tmp = ptrSupExts;
                        for (int i = 0; i < count; i++) {
-                               result[i] = Marshal.PtrToStringAnsi (tmp);
+                               result [i] = Marshal.PtrToStringAnsi (tmp);
                                tmp += sizeStruct;
                        }
 
@@ -109,37 +113,42 @@ namespace vke {
                        return result;
                }
 
-        public bool GetPresentIsSupported (uint qFamilyIndex, VkSurfaceKHR surf) {             
-            vkGetPhysicalDeviceSurfaceSupportKHR (phy, qFamilyIndex, surf, out VkBool32 isSupported);
-            return isSupported;
-        }
-
-        public VkSurfaceCapabilitiesKHR GetSurfaceCapabilities (VkSurfaceKHR surf) {            
-            vkGetPhysicalDeviceSurfaceCapabilitiesKHR (phy, surf, out VkSurfaceCapabilitiesKHR caps);
-            return caps;
-        }
-
-        public VkSurfaceFormatKHR[] GetSurfaceFormats (VkSurfaceKHR surf) {            
-            vkGetPhysicalDeviceSurfaceFormatsKHR (phy, surf, out uint count, IntPtr.Zero);
-            VkSurfaceFormatKHR[] formats = new VkSurfaceFormatKHR[count];
-            
-            vkGetPhysicalDeviceSurfaceFormatsKHR (phy, surf, out count, formats.Pin());
+               public bool GetPresentIsSupported (uint qFamilyIndex, VkSurfaceKHR surf)
+               {
+                       vkGetPhysicalDeviceSurfaceSupportKHR (phy, qFamilyIndex, surf, out VkBool32 isSupported);
+                       return isSupported;
+               }
+
+               public VkSurfaceCapabilitiesKHR GetSurfaceCapabilities (VkSurfaceKHR surf)
+               {
+                       vkGetPhysicalDeviceSurfaceCapabilitiesKHR (phy, surf, out VkSurfaceCapabilitiesKHR caps);
+                       return caps;
+               }
+
+               public VkSurfaceFormatKHR [] GetSurfaceFormats (VkSurfaceKHR surf)
+               {
+                       vkGetPhysicalDeviceSurfaceFormatsKHR (phy, surf, out uint count, IntPtr.Zero);
+                       VkSurfaceFormatKHR [] formats = new VkSurfaceFormatKHR [count];
+
+                       vkGetPhysicalDeviceSurfaceFormatsKHR (phy, surf, out count, formats.Pin ());
                        formats.Unpin ();
-            
-            return formats;
-        }
-        public VkPresentModeKHR[] GetSurfacePresentModes (VkSurfaceKHR surf) {            
-            vkGetPhysicalDeviceSurfacePresentModesKHR (phy, surf, out uint count, IntPtr.Zero);
-            VkPresentModeKHR[] modes = new VkPresentModeKHR[count];
-            
-            vkGetPhysicalDeviceSurfacePresentModesKHR (phy, surf, out count, modes.Pin());
+
+                       return formats;
+               }
+               public VkPresentModeKHR [] GetSurfacePresentModes (VkSurfaceKHR surf)
+               {
+                       vkGetPhysicalDeviceSurfacePresentModesKHR (phy, surf, out uint count, IntPtr.Zero);
+                       VkPresentModeKHR [] modes = new VkPresentModeKHR [count];
+
+                       vkGetPhysicalDeviceSurfacePresentModesKHR (phy, surf, out count, modes.Pin ());
                        modes.Unpin ();
-            
-            return modes;
-        }
-        public VkFormatProperties GetFormatProperties (VkFormat format) {            
-            vkGetPhysicalDeviceFormatProperties (phy, format, out VkFormatProperties properties);
-            return properties;
-        }
-    }
+
+                       return modes;
+               }
+               public VkFormatProperties GetFormatProperties (VkFormat format)
+               {
+                       vkGetPhysicalDeviceFormatProperties (phy, format, out VkFormatProperties properties);
+                       return properties;
+               }
+       }
 }
index 6c3bad82a6c3f125f6957357ce783806dbe77849..b37bd94f32a66dd4ab7175589c381b899ed9ae1a 100644 (file)
@@ -79,10 +79,12 @@ namespace vke {
                /// <summary>
                /// End command recording, submit, and wait queue idle
                /// </summary>
-               public void EndSubmitAndWait (CommandBuffer cmd) {
+               public void EndSubmitAndWait (CommandBuffer cmd, bool freeCommandBuffer = false) {
                        cmd.End ();
                        Submit (cmd);
                        WaitIdle ();
+                       if (freeCommandBuffer)
+                               cmd.Free ();
                }
         public void Submit (CommandBuffer cmd, VkSemaphore wait = default(VkSemaphore), VkSemaphore signal = default (VkSemaphore), VkFence fence = default (VkFence)) {
             cmd.Submit (handle, wait, signal, fence);
index 1430087134a3745ed4c99c55ca1e83c79cd3298a..2d7aab679d1fe4cdf1f0562e9790dceabd5b9aba 100644 (file)
@@ -49,7 +49,7 @@
                
        <ItemGroup>
                <PackageReference Include="SpirVTasks" Version="0.1.15-beta" />
-               <PackageReference Include="Vulkan" Version="0.1.7" />
+               <PackageReference Include="Vulkan" Version="0.1.8-beta" />
        </ItemGroup>
        <ItemGroup>
                <GLSLShader Include="shaders\**\*.frag;shaders\**\*.vert;shaders\**\*.comp;shaders\**\*.geom">