From 2ca581c59eaef31db99ff5e52614dd817a195796 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Tue, 16 Nov 2021 23:26:19 +0100 Subject: [PATCH] GetStreamFromPath: allow embedded ressource assembly with one dot --- Directory.Build.props | 2 +- README.md | 1 - samples/ClearScreen/README.md | 7 ++---- samples/Triangle/README.md | 2 +- samples/pbr/PbrPipeline.cs | 2 +- samples/pbr/main.cs | 4 ++-- vke/src/MemoryPool.cs | 4 ++-- vke/src/Utils.cs | 44 ++++++++++++++++++----------------- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 527f40a..8d90c98 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,7 +4,7 @@ $(SolutionDir)build\$(Configuration)\ 0.1.45 $(SpirVTasksReleaseVersion) - 0.2.2 + 0.2.3 $(VkeReleaseVersion)-beta true false diff --git a/README.md b/README.md index 8808a45..0ffcbbc 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,6 @@ vke is in beta development stage. `vke.net` supports `netcoreapp3.0`. - # Tutorials | Title | Screen shots | diff --git a/samples/ClearScreen/README.md b/samples/ClearScreen/README.md index 3eeab4d..4268d1d 100644 --- a/samples/ClearScreen/README.md +++ b/samples/ClearScreen/README.md @@ -13,7 +13,7 @@ Create a new dotnet console project, and add the [vke nuget package](https://www ``` # VkWindow class -**vke** use [GLFW](https://www.glfw.org/) to interface with the windowing system of the OS. Derive your application from the `VkWindow` base class to start with a vulkan enabled window. **Validation** and **RenderDoc** layers loading may be control at startup with public static boolean properties from the `Instance`class. +**vke** use [GLFW](https://www.glfw.org/) to interface with the windowing system of the OS. Derive your application from the `VkWindow` base class to start with a vulkan enabled window. **Validation** and **RenderDoc** layers loading may be control at startup with public static boolean properties from the `Instance` class. ```csharp class Program : VkWindow { @@ -21,11 +21,8 @@ class Program : VkWindow { Instance.Validation = true; - using (Program vke = new Program ()) { + using (Program vke = new Program ()) vke.Run (); - } - } -} ``` ### Vulkan Initialization diff --git a/samples/Triangle/README.md b/samples/Triangle/README.md index d2bc07c..8bdcb08 100644 --- a/samples/Triangle/README.md +++ b/samples/Triangle/README.md @@ -1,4 +1,4 @@ -# shaders +# Shaders For this tutorials we'll need a `vertex` and a `fragment` shaders. Vulkan need them to be compiled into [SPIR-V](https://www.khronos.org/spir/). Install the [Vulkan Sdk](https://www.lunarg.com/vulkan-sdk/) and after building it, ensure the `VULKAN_SDK` environment variable points to its binary subdir. ```bash export VULKAN_SDK=/VulkanSDK/1.2.176.1/x86_64 diff --git a/samples/pbr/PbrPipeline.cs b/samples/pbr/PbrPipeline.cs index 80f02ac..cc2af4c 100644 --- a/samples/pbr/PbrPipeline.cs +++ b/samples/pbr/PbrPipeline.cs @@ -85,7 +85,7 @@ namespace pbrSample new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding (2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), new VkDescriptorSetLayoutBinding (3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), - new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); + new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer)); descLayoutTextures = new DescriptorSetLayout (Dev, new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler), diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs index 4c31ad3..a49b701 100644 --- a/samples/pbr/main.cs +++ b/samples/pbr/main.cs @@ -145,7 +145,7 @@ namespace pbrSample { } else if (GetButton (MouseButton.Right) == InputAction.Press) { camera.SetZoom ((float)diffY); updateViewRequested = true; - } + } } protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) { @@ -156,7 +156,7 @@ namespace pbrSample { else curModelIndex = curModelIndex < (uint)vke.samples.Utils.GltfFiles.Length - 1 ? curModelIndex + 1 : 0; reloadModel = true; - break; + break; case Key.P: showDebugImg = !showDebugImg; queryUpdatePrefilCube = updateViewRequested = true; diff --git a/vke/src/MemoryPool.cs b/vke/src/MemoryPool.cs index 492dd2f..b5196e1 100644 --- a/vke/src/MemoryPool.cs +++ b/vke/src/MemoryPool.cs @@ -33,7 +33,7 @@ namespace vke { /// Return mapped memory pointer or null if not mapped. public IntPtr MappedData => mappedPointer; /// Last added resource, this is the entry element for the double linked list of ressource. - public Resource Last => lastResource; + public Resource Last => lastResource; /// /// Initializes a new instance of the class. @@ -78,7 +78,7 @@ namespace vke { if (previous.next.poolOffset < previous.poolOffset) { limit = Size; - if (offset + resource.AllocatedDeviceMemorySize < Size) + if (offset + resource.AllocatedDeviceMemorySize < Size) break; offset = 0; limit = previous.next.poolOffset; diff --git a/vke/src/Utils.cs b/vke/src/Utils.cs index 7e1303a..c563a86 100644 --- a/vke/src/Utils.cs +++ b/vke/src/Utils.cs @@ -9,7 +9,7 @@ using System.Reflection; using System.Xml.Serialization; namespace Vulkan { - public static partial class Utils { + public static partial class Utils { /// Throw an erro if VkResult != Success. public static void CheckResult (VkResult result, string errorString = "Call failed") { if (result != VkResult.Success) @@ -27,34 +27,36 @@ namespace Vulkan { xmlMakeTypeFieldsAsAttributes (typeof (VkDescriptorPoolSize), ref xmlAttributeOverrides); return xmlAttributeOverrides; } + static bool tryFindResource (Assembly a, string resId, out Stream stream) { + stream = null; + if (a == null) + return false; + stream = a.GetManifestResourceStream (resId); + return stream != null; + } /// /// Return a file or embedded resource stream. /// /// The stream from path. /// The file or stream path. Embedded resource path starts with '#'. public static Stream GetStreamFromPath (string path) { - Stream stream = null; - if (path.StartsWith ("#", StringComparison.Ordinal)) { + Stream stream = null; string resId = path.Substring (1); - //first search entry assembly - stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); - if (stream != null) + if (tryFindResource (Assembly.GetEntryAssembly (), resId, out stream)) return stream; - //if not found, search assembly named with the 1st element of the resId - string assemblyName = resId.Split ('.')[0]; - Assembly a = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyName); - if (a == null) - throw new Exception ($"Assembly '{assemblyName}' not found for ressource '{path}'."); - stream = a.GetManifestResourceStream (resId); - if (stream == null) - throw new Exception ("Resource not found: " + path); - } else { - if (!File.Exists (path)) - throw new FileNotFoundException ("File not found: ", path); - stream = new FileStream (path, FileMode.Open, FileAccess.Read); + string[] assemblyNames = resId.Split ('.'); + Assembly assembly = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyNames[0]); + if (assembly == null && assemblyNames.Length > 3) + assembly = AppDomain.CurrentDomain.GetAssemblies () + .FirstOrDefault (aa => aa.GetName ().Name == $"{assemblyNames[0]}.{assemblyNames[1]}"); + if (assembly != null && tryFindResource (assembly, resId, out stream)) + return stream; + throw new Exception ("Resource not found: " + path); } - return stream; + if (!File.Exists (path)) + throw new FileNotFoundException ("File not found: ", path); + return new FileStream (path, FileMode.Open, FileAccess.Read); } /// Convert angle from degree to radian. public static float DegreesToRadians (float degrees) { @@ -83,7 +85,7 @@ namespace Vulkan { if (floats.Length > 2) v.Z = floats[2]; if (floats.Length > 3) - v.W = floats[3]; + v.W = floats[3]; } /// /// Populate a Quaternion with values from a float array @@ -221,7 +223,7 @@ namespace Vulkan { break; case VkImageLayout.TransferSrcOptimal: - // Image is a transfer source + // Image is a transfer source // Make sure any reads from the image have been finished imageMemoryBarrier.srcAccessMask = VkAccessFlags.TransferRead; break; -- 2.47.3