</PropertyGroup>
<PropertyGroup Condition=" '$(UseMemoryPools)' == 'true'">
- <DefineConstants>$(DefineConstants);_MEMORY_POOLS</DefineConstants>
+ <DefineConstants>$(DefineConstants);MEMORY_POOLS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(UseStbSharp)' == 'true'">
<DefineConstants>$(DefineConstants);STB_SHARP</DefineConstants>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/jpbruyere/vk.net/blob/master/SpirVTasks/README.md</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
+ <PackageIcon>icon.png</PackageIcon>
<License>MIT</License>
<Authors>Jean-Philippe Bruyère</Authors>
<OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<IncludeInPackage>true</IncludeInPackage>
<PackagePath>build</PackagePath>
</Content>
+
+ <None Include="$(SolutionDir)vke\icon.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>
</Project>
\ No newline at end of file
VkSampleCountFlags.SampleCount1, VkImageTiling.Optimal, Image.ComputeMipLevels (TEXTURE_DIM), ctx.ImageCount);
ctx.BuildTexArray (ref texArray, 0);
-
- texArray.CreateView (VkImageViewType.ImageView2DArray, VkImageAspectFlags.Color, texArray.CreateInfo.arrayLayers);
- texArray.CreateSampler ();
- texArray.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
- texArray.SetName ("model texArray");
+ } else {
+ texArray = new Image (dev, Image.DefaultTextureFormat, VkImageUsageFlags.Sampled | VkImageUsageFlags.TransferDst | VkImageUsageFlags.TransferSrc,
+ VkMemoryPropertyFlags.DeviceLocal, TEXTURE_DIM, TEXTURE_DIM, VkImageType.Image2D,
+ VkSampleCountFlags.SampleCount1, VkImageTiling.Optimal, Image.ComputeMipLevels (TEXTURE_DIM), 1);
+ PrimaryCommandBuffer cmd = cmdPool.AllocateAndStart (VkCommandBufferUsageFlags.OneTimeSubmit);
+ texArray.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.ShaderReadOnlyOptimal);
+ transferQ.EndSubmitAndWait (cmd, true);
}
+ texArray.CreateView (VkImageViewType.ImageView2DArray, VkImageAspectFlags.Color, texArray.CreateInfo.arrayLayers);
+ texArray.CreateSampler ();
+ texArray.Descriptor.imageLayout = VkImageLayout.ShaderReadOnlyOptimal;
+ texArray.SetName ("model texArray");
+
+
loadMaterials (ctx);
materialUBO = new HostBuffer<Material> (dev, VkBufferUsageFlags.UniformBuffer, materials);
}
PrimaryCommandBuffer cmd = cmdPool.AllocateAndStart (VkCommandBufferUsageFlags.OneTimeSubmit);
texArray.SetLayout (cmd, VkImageAspectFlags.Color, VkImageLayout.Undefined, VkImageLayout.TransferDstOptimal,
VkPipelineStageFlags.BottomOfPipe, VkPipelineStageFlags.Transfer);
- cmd.End ();
- transferQ.Submit (cmd);
- transferQ.WaitIdle ();
- cmd.Free ();
-
+ transferQ.EndSubmitAndWait (cmd, true);
+
VkImageBlit imageBlit = new VkImageBlit {
srcSubresource = new VkImageSubresourceLayers (VkImageAspectFlags.Color, 1, 0),
dstOffsets_1 = new VkOffset3D (texDim, texDim, 1)
Vk.vkCmdBlitImage (cmd.Handle, vkimg.Handle, VkImageLayout.TransferSrcOptimal,
texArray.Handle, VkImageLayout.TransferDstOptimal, 1, ref imageBlit, VkFilter.Linear);
-
- cmd.End ();
- transferQ.Submit (cmd);
- transferQ.WaitIdle ();
- cmd.Free ();
+
+ transferQ.EndSubmitAndWait (cmd, true);
vkimg.Dispose ();
}
<PackageId>vke.gltfLoader</PackageId>
<AssemblyVersion>$(VkeReleaseVersion)</AssemblyVersion>
<Description>vke.net glTF addons</Description>
- <PackageTags>vulkan C# gltf</PackageTags>
- <PackageVersion>$(AssemblyVersion)</PackageVersion>
+ <PackageTags>vulkan C# gltf</PackageTags>
+ <PackageVersion>$(VkePackageVersion)</PackageVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/jpbruyere/vke.net/blob/master/README.md</PackageProjectUrl>
<PackageReference Include="SpirVTasks" Version="$(SpirVTasksPackageVersion)" />
</ItemGroup>
- <ItemGroup>
+ <ItemGroup>
+ <Compile Include="$(MSBuildThisFileDirectory)common\Utils.cs"/>
<GLSLShader Include="shaders\**\*.frag;shaders\**\*.vert;shaders\**\*.comp;shaders\**\*.geom">
<LogicalName>shaders.%(Filename)%(Extension).spv</LogicalName>
</GLSLShader>
cmds = cmdPool.AllocateCommandBuffer(swapChain.ImageCount);
- font = new BMFont (Utils.DataDirectory + "font.fnt");
+ font = new BMFont (vke.samples.Utils.GetDataFile ("font.fnt"));
vbo = new GPUBuffer<float> (dev, VkBufferUsageFlags.VertexBuffer | VkBufferUsageFlags.TransferDst, 1024);
ibo = new GPUBuffer<ushort> (dev, VkBufferUsageFlags.IndexBuffer | VkBufferUsageFlags.TransferDst, 2048);
ushort[] indices = { 0, 1, 2, 2, 0, 3 };
int currentImgIndex = 0;
string[] imgPathes = {
- Utils.DataDirectory + "models/Bricks16_col.jpg",
- Utils.DataDirectory + "textures/texturearray_rocks_bc3_unorm.ktx",
- Utils.DataDirectory + "textures/texture.jpg",
- Utils.DataDirectory + "textures/tex256.jpg",
- Utils.DataDirectory + "font.ktx",
+ vke.samples.Utils.GetDataFile ("models/Bricks16_col.jpg"),
+ vke.samples.Utils.GetDataFile ("textures/texturearray_rocks_bc3_unorm.ktx"),
+ vke.samples.Utils.GetDataFile ("textures/texture.jpg"),
+ vke.samples.Utils.GetDataFile ("textures/tex256.jpg"),
+ vke.samples.Utils.GetDataFile ("font.ktx"),
};
protected override void initVulkan () {
pipeline = new GraphicPipeline (cfg);
+ cfg.DisposeShaders ();
+
uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices);
uboMats.Map ();//permanent map
1.0f, 1.0f, 1.0f, 1.0f, 0.0f,
};
int currentImgIndex = 4;
- string[] imgPathes = {
- Utils.DataDirectory + "textures/uffizi_cube.ktx",
- Utils.DataDirectory + "textures/papermill.ktx",
- Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx",
- Utils.DataDirectory + "textures/gcanyon_cube.ktx",
- Utils.DataDirectory + "textures/pisa_cube.ktx",
- };
VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1;
DescriptorSetWrites uboUpdate = new DescriptorSetWrites (descriptorSet, dsLayout.Bindings[0]);
uboUpdate.Write (dev, uboMats.Descriptor);
- loadTexture (imgPathes[currentImgIndex]);
+ loadTexture (vke.samples.Utils.CubeMaps [currentImgIndex]);
if (nextTexture != null)
updateTextureSet ();
}
switch (key) {
case Key.Space:
currentImgIndex++;
- if (currentImgIndex == imgPathes.Length)
+ if (currentImgIndex == vke.samples.Utils.CubeMaps.Length)
currentImgIndex = 0;
- loadTexture (imgPathes[currentImgIndex]);
+ loadTexture (vke.samples.Utils.CubeMaps[currentImgIndex]);
break;
default:
base.onKeyDown (key, scanCode, modifiers);
--- /dev/null
+using System.IO;
+using System.Linq;
+
+namespace vke.samples {
+ public static class Utils {
+ static string dataDir = "../../../datas/".Replace ('/', Path.DirectorySeparatorChar);
+ public static string DataDirectory => dataDir;
+ static string[] gltfExtensions = new[] { ".gltf", ".glb"};
+
+ public static string[] GltfFiles =>
+ Directory
+ .GetFiles (Path.Combine (DataDirectory, "models"), "*", SearchOption.AllDirectories)
+ .Where (file => gltfExtensions.Any (file.ToLower ().EndsWith))
+ .ToArray ();
+
+ public static string[] CubeMaps = {
+ GetDataFile ("textures/papermill.ktx"),
+ GetDataFile ("textures/cubemap_yokohama_bc3_unorm.ktx"),
+ GetDataFile ("textures/gcanyon_cube.ktx"),
+ GetDataFile ("textures/pisa_cube.ktx"),
+ GetDataFile ("textures/uffizi_cube.ktx"),
+ };
+
+ public static string GetDataFile (string relativePath) =>
+ Path.Combine (DataDirectory, relativePath);
+ }
+}
model?.Dispose ();
if (TEXTURE_ARRAY) {
- PbrModelTexArray mod = new PbrModelTexArray (transferQ, path);
- if (mod.texArray != null) {
- DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMain, descLayoutMain.Bindings[5], descLayoutMain.Bindings[7]);
- uboUpdate.Write (dev, mod.materialUBO.Descriptor, mod.texArray.Descriptor);
- }
+ PbrModelTexArray mod = new PbrModelTexArray (transferQ, path);
+ DescriptorSetWrites uboUpdate = new DescriptorSetWrites (dsMain, descLayoutMain.Bindings[5], descLayoutMain.Bindings[7]);
+ uboUpdate.Write (dev, mod.materialUBO.Descriptor, mod.texArray.Descriptor);
+
model = mod;
} else {
model = new PbrModelSeparatedTextures (transferQ, path,
vke.Run ();
}
}
+ Deferred (string name = "VkCrowWindow", uint _width = 800, uint _height = 600, bool vSync = false)
+ : base (name, _width, _height, vSync) { }
- public override string[] EnabledInstanceExtensions => new string[] {
+ public override string[] EnabledInstanceExtensions => new string[] {
Ext.I.VK_EXT_debug_utils,
};
transferQ = new Queue (dev, VkQueueFlags.Transfer);
computeQ = new Queue (dev, VkQueueFlags.Compute);
}
- string[] cubemapPathes = {
- Utils.DataDirectory + "textures/papermill.ktx",
- Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx",
- Utils.DataDirectory + "textures/gcanyon_cube.ktx",
- Utils.DataDirectory + "textures/pisa_cube.ktx",
- Utils.DataDirectory + "textures/uffizi_cube.ktx",
- };
- string[] modelPathes = {
- //"/mnt/devel/vkPinball/data/models/pinball.gltf",
- //"/mnt/devel/pinball.net/data/test.glb",
- //Utils.DataDirectory + "models/Box.gltf",
- //Utils.DataDirectory + "models/cubeOnPlane.glb",
- //Utils.DataDirectory + "models/shadow.glb",
- //Utils.DataDirectory + "models/cube.gltf",
- Utils.DataDirectory + "models/DamagedHelmet/glTF/DamagedHelmet.gltf",
- //Utils.DataDirectory + "models/shadow.glb",
- Utils.DataDirectory + "models/Hubble.glb",
- Utils.DataDirectory + "models/MER_static.glb",
- Utils.DataDirectory + "models/ISS_stationary.glb",
- };
-
- int curModelIndex = 0;
+
+ int curModelIndex = 13;
bool reloadModel;
bool rebuildBuffers;
camera.SetPosition (0, 0, -2);
//renderer = new DeferredPbrRenderer (presentQueue, cubemapPathes[2], swapChain.Width, swapChain.Height, camera.NearPlane, camera.FarPlane);
- renderer = new DeferredPbrRenderer (presentQueue, cubemapPathes[2], swapChain.Width, swapChain.Height, camera.NearPlane, camera.FarPlane);
- renderer.LoadModel (transferQ, modelPathes[curModelIndex]);
+ renderer = new DeferredPbrRenderer (presentQueue, vke.samples.Utils.CubeMaps[2], swapChain.Width, swapChain.Height, camera.NearPlane, camera.FarPlane);
+ renderer.LoadModel (transferQ, vke.samples.Utils.GltfFiles [curModelIndex]);
camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (renderer.modelAABB.Width, renderer.modelAABB.Height), renderer.modelAABB.Depth));
init_final_pl ();
}
void buildCommandBuffers () {
+ dev.WaitIdle ();
for (int i = 0; i < swapChain.ImageCount; ++i) {
cmds[i]?.Free ();
cmds[i] = cmdPool.AllocateAndStart ();
public override void Update () {
if (reloadModel) {
- renderer.LoadModel (transferQ, modelPathes[curModelIndex]);
+ renderer.LoadModel (transferQ, vke.samples.Utils.GltfFiles[curModelIndex]);
reloadModel = false;
camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (renderer.modelAABB.Width, renderer.modelAABB.Height), renderer.modelAABB.Depth));
updateViewRequested = true;
break;
case Key.KeypadAdd:
curModelIndex++;
- if (curModelIndex >= modelPathes.Length)
+ if (curModelIndex >= vke.samples.Utils.GltfFiles.Length)
curModelIndex = 0;
reloadModel = true;
- break;
+ return;
case Key.KeypadSubtract:
curModelIndex--;
if (curModelIndex < 0)
- curModelIndex = modelPathes.Length -1;
+ curModelIndex = vke.samples.Utils.GltfFiles.Length -1;
reloadModel = true;
- break;
+ return;
default:
base.onKeyDown (key, scanCode, modifiers);
return;
roughness
}
- string[] modelPathes = {
- Utils.DataDirectory + "models/DamagedHelmet/glTF/DamagedHelmet.gltf",
- Utils.DataDirectory + "models/Hubble.glb",
- Utils.DataDirectory + "models/ISS_stationary.glb",
- Utils.DataDirectory + "models/MER_static.glb",
- Utils.DataDirectory + "models/Box.gltf",
- };
- string[] cubemapPathes = {
- Utils.DataDirectory + "textures/papermill.ktx",
- Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx",
- Utils.DataDirectory + "textures/gcanyon_cube.ktx",
- Utils.DataDirectory + "textures/pisa_cube.ktx",
- Utils.DataDirectory + "textures/uffizi_cube.ktx",
- };
-
-
DebugView currentDebugView = DebugView.none;
bool queryUpdatePrefilCube, showDebugImg;
camera.SetPosition (0, 0, -2);
pbrPipeline = new PBRPipeline (presentQueue,
- new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples), cubemapPathes[0]);
+ new RenderPass (dev, swapChain.ColorFormat, dev.GetSuitableDepthFormat (), samples), vke.samples.Utils.CubeMaps[0]);
loadCurrentModel ();
}
void loadCurrentModel () {
dev.WaitIdle ();
- pbrPipeline.LoadModel (presentQueue, modelPathes[curModelIndex]);
+ pbrPipeline.LoadModel (presentQueue, vke.samples.Utils.GltfFiles[curModelIndex]);
BoundingBox modelAABB = pbrPipeline.model.DefaultScene.AABB;
camera.Model = Matrix4x4.CreateScale (1f / Math.Max (Math.Max (modelAABB.max.X, modelAABB.max.Y), modelAABB.max.Z));
updateViewRequested = true;
switch (key) {
case Key.Space:
if (modifiers.HasFlag (Modifier.Shift))
- curModelIndex = curModelIndex == 0 ? (uint)modelPathes.Length - 1 : curModelIndex - 1;
+ curModelIndex = curModelIndex == 0 ? (uint)vke.samples.Utils.GltfFiles.Length - 1 : curModelIndex - 1;
else
- curModelIndex = curModelIndex < (uint)modelPathes.Length - 1 ? curModelIndex + 1 : 0;
+ curModelIndex = curModelIndex < (uint)vke.samples.Utils.GltfFiles.Length - 1 ? curModelIndex + 1 : 0;
reloadModel = true;
break;
case Key.P:
using System.Xml.Serialization;
namespace Vulkan {
- public static partial class Utils {
- public static string DataDirectory => "../../../datas/";
+ public static partial class Utils {
/// <summary>Throw an erro if VkResult != Success.</summary>
public static void CheckResult (VkResult result, string errorString = "Call failed") {
if (result != VkResult.Success)
dev.Activate (enabledFeatures, EnabledDeviceExtensions);
swapChain = new SwapChain (presentQueue as PresentQueue, Width, Height, SwapChain.PREFERED_FORMAT,
- VSync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.MailboxKHR);
+ VSync ? VkPresentModeKHR.FifoKHR : VkPresentModeKHR.ImmediateKHR);
swapChain.Activate ();
Width = swapChain.Width;