From a3f387cdd4100d9532d0a203d984f9ac1da20774 Mon Sep 17 00:00:00 2001 From: AliMehrabani Date: Mon, 11 Nov 2024 11:47:41 +0330 Subject: [PATCH] Remove loading models Loading models is removes from the ComputeAndGraphics and shaders folder is reordered. --- VkTest.pro | 24 +++++--- VulkanTutorial1.0/ComputeAndGraphics.cpp | 57 ++---------------- VulkanTutorial1.0/ComputeAndGraphics.h | 38 +++--------- VulkanTutorial1.0/Types.h | 2 - .../ComputeAndGraphics}/compComp.spv | Bin .../ComputeAndGraphics}/compile.sh | 3 - .../ComputeAndGraphics/fragComp.spv | Bin 0 -> 764 bytes .../ComputeAndGraphics}/shaderCompute.comp | 0 .../ComputeAndGraphics}/shaderCompute.frag | 2 +- .../ComputeAndGraphics}/shaderCompute.vert | 0 .../ComputeAndGraphics}/vertComp.spv | Bin .../HelloTriangle/compile.sh | 2 + .../HelloTriangle}/frag.spv | Bin .../HelloTriangle}/shader.frag | 0 .../HelloTriangle}/shader.vert | 0 .../HelloTriangle}/vert.spv | Bin shaders/comp.spv | Bin 2196 -> 0 bytes shaders/fragComp.spv | Bin 956 -> 0 bytes 18 files changed, 30 insertions(+), 98 deletions(-) rename shaders/{ => VulkanTutorial1.0/ComputeAndGraphics}/compComp.spv (100%) rename shaders/{ => VulkanTutorial1.0/ComputeAndGraphics}/compile.sh (65%) create mode 100644 shaders/VulkanTutorial1.0/ComputeAndGraphics/fragComp.spv rename shaders/{ => VulkanTutorial1.0/ComputeAndGraphics}/shaderCompute.comp (100%) rename shaders/{ => VulkanTutorial1.0/ComputeAndGraphics}/shaderCompute.frag (87%) rename shaders/{ => VulkanTutorial1.0/ComputeAndGraphics}/shaderCompute.vert (100%) rename shaders/{ => VulkanTutorial1.0/ComputeAndGraphics}/vertComp.spv (100%) create mode 100755 shaders/VulkanTutorial1.0/HelloTriangle/compile.sh rename shaders/{ => VulkanTutorial1.0/HelloTriangle}/frag.spv (100%) rename shaders/{ => VulkanTutorial1.0/HelloTriangle}/shader.frag (100%) rename shaders/{ => VulkanTutorial1.0/HelloTriangle}/shader.vert (100%) rename shaders/{ => VulkanTutorial1.0/HelloTriangle}/vert.spv (100%) delete mode 100644 shaders/comp.spv delete mode 100644 shaders/fragComp.spv diff --git a/VkTest.pro b/VkTest.pro index 157ccce..937460b 100644 --- a/VkTest.pro +++ b/VkTest.pro @@ -24,16 +24,20 @@ HEADERS += \ \ VulkanTutorial1.0/Types.h -DISTFILES += \ - shaders/comp.spv \ - shaders/compile.sh \ - shaders/frag.spv \ - shaders/shader.frag \ - shaders/shader.vert \ - shaders/shaderCompute.comp \ - shaders/shaderCompute.frag \ - shaders/shaderCompute.vert \ - shaders/vert.spv +DISTFILES += \ \ + shaders/VulkanTutorial1.0/ComputeAndGraphics/compComp.spv \ + shaders/VulkanTutorial1.0/ComputeAndGraphics/compile.sh \ + shaders/VulkanTutorial1.0/ComputeAndGraphics/fragComp.spv \ + shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.comp \ + shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.frag \ + shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.vert \ + shaders/VulkanTutorial1.0/ComputeAndGraphics/vertComp.spv \ + shaders/VulkanTutorial1.0/HelloTriangle/compile.sh \ + shaders/VulkanTutorial1.0/HelloTriangle/frag.spv \ + shaders/VulkanTutorial1.0/HelloTriangle/shader.frag \ + shaders/VulkanTutorial1.0/HelloTriangle/shader.vert \ + shaders/VulkanTutorial1.0/HelloTriangle/vert.spv + contains(ANDROID_TARGET_ARCH,arm64-v8a) { QT += diff --git a/VulkanTutorial1.0/ComputeAndGraphics.cpp b/VulkanTutorial1.0/ComputeAndGraphics.cpp index dd5271d..f7f6d57 100644 --- a/VulkanTutorial1.0/ComputeAndGraphics.cpp +++ b/VulkanTutorial1.0/ComputeAndGraphics.cpp @@ -2,7 +2,6 @@ #include #include -#include #include VkResult CreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo @@ -95,7 +94,6 @@ void ComputeAndGraphics::initVulkan() createTextureImage(); createTextureImageView(); createTextureSampler(); - loadModel(); createVertexBuffer(); createIndexBuffer(); // createShaderStorageBuffers(); @@ -682,8 +680,8 @@ VkDescriptorSetLayoutBinding ComputeAndGraphics::createLayoutBindingInfo(uint32_ void ComputeAndGraphics::createGraphicsPipeline() { - auto vertShaderCode = readFile("shaders/vert.spv"); - auto fragShaderCode = readFile("shaders/frag.spv"); + auto vertShaderCode = readFile("shaders/vertComp.spv"); + auto fragShaderCode = readFile("shaders/fragComp.spv"); VkShaderModule vertShaderModule = createShaderModule(vertShaderCode); VkShaderModule fragShaderModule = createShaderModule(fragShaderCode); VkPipelineShaderStageCreateInfo vertShaderStageInfo = createPipelineShaderInfo(VK_SHADER_STAGE_VERTEX_BIT, vertShaderModule); @@ -892,7 +890,7 @@ VkPipelineColorBlendStateCreateInfo ComputeAndGraphics::colorPipelineBlendStateI void ComputeAndGraphics::createComputePipeline() { - auto computeShaderCode = readFile("shaders/comp.spv"); + auto computeShaderCode = readFile("shaders/compComp.spv"); VkShaderModule computeShaderModule = createShaderModule(computeShaderCode); VkPipelineShaderStageCreateInfo computeShaderStageInfo = createPipelineShaderInfo(VK_SHADER_STAGE_COMPUTE_BIT, computeShaderModule); @@ -1022,8 +1020,7 @@ bool ComputeAndGraphics::hasStencilComponent(VkFormat format) { void ComputeAndGraphics::createTextureImage() { int texWidth, texHeight, texChannels; -// stbi_uc* pixels = stbi_load("/home/ali-mehrabani/Qt_projects/VkTest/textures/texture.jpg", &texWidth, &texHeight, &texChannels, STBI_rgb_alpha); - stbi_uc* pixels = stbi_load(TEXTURE_PATH.c_str(), &texWidth, &texHeight, &texChannels, STBI_rgb_alpha); + stbi_uc* pixels = stbi_load("/home/ali-mehrabani/Qt_projects/VkTest/textures/texture.jpg", &texWidth, &texHeight, &texChannels, STBI_rgb_alpha); VkDeviceSize imageSize = texWidth * texHeight * 4; if (!pixels) { @@ -1278,52 +1275,6 @@ void ComputeAndGraphics::createTextureSampler() } } -void ComputeAndGraphics::loadModel() { - tinyobj::attrib_t attrib; - std::vector shapes; - std::vector materials; - std::string warn, err; - - if (!tinyobj::LoadObj(&attrib, &shapes, &materials, &warn, &err, MODEL_PATH.c_str())) { - throw std::runtime_error(warn + err); - } - - std::unordered_map uniqueVertices{}; - - for (const auto& shape : shapes) { - for (const auto& index : shape.mesh.indices) { - Vertex vertex = createLoadModelVertex(attrib, index); - - if (uniqueVertices.count(vertex) == 0) { - uniqueVertices[vertex] = static_cast(_vertices.size()); - _vertices.push_back(vertex); - } - - _indices.push_back(uniqueVertices[vertex]); - } - } -} - -Vertex ComputeAndGraphics::createLoadModelVertex(tinyobj::attrib_t attrib, tinyobj::index_t index) -{ - Vertex vertex{}; - - vertex.pos = { - attrib.vertices[3 * index.vertex_index + 0], - attrib.vertices[3 * index.vertex_index + 1], - attrib.vertices[3 * index.vertex_index + 2] - }; - - vertex.texCoord = { - attrib.texcoords[2 * index.texcoord_index + 0], - 1.0f - attrib.texcoords[2 * index.texcoord_index + 1] - }; - - vertex.color = {1.0f, 1.0f, 1.0f}; - - return vertex; -} - void ComputeAndGraphics::createVertexBuffer() { VkDeviceSize bufferSize = sizeof(_vertices[0]) * _vertices.size(); diff --git a/VulkanTutorial1.0/ComputeAndGraphics.h b/VulkanTutorial1.0/ComputeAndGraphics.h index bd6d8f6..338ef3c 100644 --- a/VulkanTutorial1.0/ComputeAndGraphics.h +++ b/VulkanTutorial1.0/ComputeAndGraphics.h @@ -111,16 +111,6 @@ struct Vertex { } }; -namespace std { - template<> struct hash { - size_t operator()(Vertex const& vertex) const { - return ((hash()(vertex.pos) ^ - (hash()(vertex.color) << 1)) >> 1) ^ - (hash()(vertex.texCoord) << 1); - } - }; -} - struct UniformBufferObject { alignas(16) glm::mat4 model; alignas(16) glm::mat4 view; @@ -221,8 +211,6 @@ private: VkFormat findDepthFormat(); bool hasStencilComponent(VkFormat format); - void loadModel(); - void createShaderStorageBuffers(); void createComputePipeline(); void createComputeCommandBuffers(); @@ -277,8 +265,6 @@ private: VkBufferImageCopy createBufferImageCopyInfo(uint32_t width, uint32_t height); - Vertex createLoadModelVertex(tinyobj::attrib_t attrib, tinyobj::index_t index); - void copyVerticesToStagingBuffer(VkBuffer& stagingBuffer, VkDeviceMemory& stagingBufferMemory); void copyIndicesToStagingBuffer(VkBuffer& stagingBuffer, VkDeviceMemory& stagingBufferMemory); @@ -317,33 +303,27 @@ private: const int32_t WIDTH = 800; const int32_t HEIGHT = 600; - const std::string MODEL_PATH = "/home/ali-mehrabani/Qt_projects/VkTest/models/viking_room.obj"; - const std::string TEXTURE_PATH = "/home/ali-mehrabani/Qt_projects/VkTest/textures/viking_room.png"; - const std::vector validationLayers = { "VK_LAYER_KHRONOS_validation" }; const std::vector deviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; -// const std::vector _vertices = { -// {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f}}, -// {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}, -// {{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}}, -// {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}}, + const std::vector _vertices = { + {{-0.5f, -0.5f, 0.0f}, {1.0f, 0.0f, 0.0f}, {1.0f, 0.0f}}, + {{0.5f, -0.5f, 0.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}}, + {{0.5f, 0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}, {0.0f, 1.0f}}, + {{-0.5f, 0.5f, 0.0f}, {1.0f, 1.0f, 1.0f}, {1.0f, 1.0f}}, // {{-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f, 0.0f}, {0.0f, 0.0f}}, // {{0.5f, -0.5f, -0.5f}, {0.0f, 1.0f, 0.0f}, {1.0f, 0.0f}}, // {{0.5f, 0.5f, -0.5f}, {0.0f, 0.0f, 1.0f}, {1.0f, 1.0f}}, // {{-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f, 1.0f}, {0.0f, 1.0f}} -// }; -// const std::vector _indices = { -// 0, 1, 2, 2, 3, 0, + }; + const std::vector _indices = { + 0, 1, 2, 2, 3, 0, // 4, 5, 6, 6, 7, 4 -// }; - - std::vector _vertices; - std::vector _indices; + }; uint32_t currentFrame = 0; bool framebufferResized = false; diff --git a/VulkanTutorial1.0/Types.h b/VulkanTutorial1.0/Types.h index 9edb0d2..5e28240 100644 --- a/VulkanTutorial1.0/Types.h +++ b/VulkanTutorial1.0/Types.h @@ -19,8 +19,6 @@ #define GLM_FORCE_DEPTH_ZERO_TO_ONE #include #include -#define GLM_ENABLE_EXPERIMENTAL -#include #include #include diff --git a/shaders/compComp.spv b/shaders/VulkanTutorial1.0/ComputeAndGraphics/compComp.spv similarity index 100% rename from shaders/compComp.spv rename to shaders/VulkanTutorial1.0/ComputeAndGraphics/compComp.spv diff --git a/shaders/compile.sh b/shaders/VulkanTutorial1.0/ComputeAndGraphics/compile.sh similarity index 65% rename from shaders/compile.sh rename to shaders/VulkanTutorial1.0/ComputeAndGraphics/compile.sh index b8f2cac..cb0f2f5 100755 --- a/shaders/compile.sh +++ b/shaders/VulkanTutorial1.0/ComputeAndGraphics/compile.sh @@ -1,6 +1,3 @@ -/usr/bin/glslc shader.vert -o vert.spv -/usr/bin/glslc shader.frag -o frag.spv - /usr/bin/glslc shaderCompute.vert -o vertComp.spv /usr/bin/glslc shaderCompute.frag -o fragComp.spv /usr/bin/glslc shaderCompute.comp -o compComp.spv diff --git a/shaders/VulkanTutorial1.0/ComputeAndGraphics/fragComp.spv b/shaders/VulkanTutorial1.0/ComputeAndGraphics/fragComp.spv new file mode 100644 index 0000000000000000000000000000000000000000..0a369b5d42979f09ad30461cc5584fe9a7b615f6 GIT binary patch literal 764 zcmYk3O-lk{6oqfZF)%t}W7w`=(2wd@wFx@U zSlF(;`XE#qDkMhle_<7hgw*k27t(|PENbu=42zAQ$sPyVVG zMT<$QrEmB&fvXD4bb>$!Oumkc9i;eFcMh1`=+k#{rtx)cfjxARjaYJT=$;qXmNga6 zzQD}Z*0&(f*5Pm0n4aKT>aHk{o_d=n#m7>X^ni|hyK4~~`M}J?p?*c4eDsOFDo-wW z^k8O$I~PVk-)e#AKPcVg+WETca#J?zV< e|0NapV9n9PvpDv2C?k%ydu3%`aKEa0Bl`m(m^`Tf literal 0 HcmV?d00001 diff --git a/shaders/shaderCompute.comp b/shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.comp similarity index 100% rename from shaders/shaderCompute.comp rename to shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.comp diff --git a/shaders/shaderCompute.frag b/shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.frag similarity index 87% rename from shaders/shaderCompute.frag rename to shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.frag index b63641b..e138f92 100644 --- a/shaders/shaderCompute.frag +++ b/shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.frag @@ -10,6 +10,6 @@ layout(location = 0) out vec4 outColor; void main() { outColor = texture(texSampler, fragTexCoord * 1.0); - vec2 coord = gl_PointCoord - vec2(0.5); +// vec2 coord = gl_PointCoord - vec2(0.5); // outColor = vec4(fragColor, 0.5 - length(coord)); } diff --git a/shaders/shaderCompute.vert b/shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.vert similarity index 100% rename from shaders/shaderCompute.vert rename to shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.vert diff --git a/shaders/vertComp.spv b/shaders/VulkanTutorial1.0/ComputeAndGraphics/vertComp.spv similarity index 100% rename from shaders/vertComp.spv rename to shaders/VulkanTutorial1.0/ComputeAndGraphics/vertComp.spv diff --git a/shaders/VulkanTutorial1.0/HelloTriangle/compile.sh b/shaders/VulkanTutorial1.0/HelloTriangle/compile.sh new file mode 100755 index 0000000..34d491d --- /dev/null +++ b/shaders/VulkanTutorial1.0/HelloTriangle/compile.sh @@ -0,0 +1,2 @@ +/usr/bin/glslc shader.vert -o vert.spv +/usr/bin/glslc shader.frag -o frag.spv diff --git a/shaders/frag.spv b/shaders/VulkanTutorial1.0/HelloTriangle/frag.spv similarity index 100% rename from shaders/frag.spv rename to shaders/VulkanTutorial1.0/HelloTriangle/frag.spv diff --git a/shaders/shader.frag b/shaders/VulkanTutorial1.0/HelloTriangle/shader.frag similarity index 100% rename from shaders/shader.frag rename to shaders/VulkanTutorial1.0/HelloTriangle/shader.frag diff --git a/shaders/shader.vert b/shaders/VulkanTutorial1.0/HelloTriangle/shader.vert similarity index 100% rename from shaders/shader.vert rename to shaders/VulkanTutorial1.0/HelloTriangle/shader.vert diff --git a/shaders/vert.spv b/shaders/VulkanTutorial1.0/HelloTriangle/vert.spv similarity index 100% rename from shaders/vert.spv rename to shaders/VulkanTutorial1.0/HelloTriangle/vert.spv diff --git a/shaders/comp.spv b/shaders/comp.spv deleted file mode 100644 index 7416b6fda9bf96c1da5cd4b3f081a8e2a9cc4e99..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2196 zcmZvcYflqV5Qb0b1q8W?fH$y!cN9?pQ3NSU3Q3b{(9cb2H)fNiOWK9VNB@97%3tLd z6W?cdM;78~CUfRJ?_AEz+2;Ee`kl+UAvf%HU9!eqpAaXk6zgj3ptjVD+Dj{|%P>Y< zJ|@B$6{jd&kQ_Dr4hKV$G2vk203yOg^7{2j|B_K~gRWX@RO|I>ZMV@nK5q1)v%qTv ze#dLH{jS%F{8JC!K!)dcTER&>ODKww&5u2x9Db+meU~oEqNZ;_qZ)*V&0xQC8n&8| zA9nUX#^*&hA^oY@jr>-ij84^;VvPN9*z+N0aqe>J1!2pN&JsL{!QEP65O$@D`b|n7 zr*Zcc0c=XxH_%elb+mka!2u9CYU%;Fv#?9|D}J-}I3M^6Vu&EZx8YhQ9twa@z2 zPa>iHF@C|911ca)YzlUJy0E_(wDs-!Rs7et^Vo&BU&MohKm9w8mydfzE^4#BW&Pz zN+wh_vF4PGeC#LXWA(~Zj|!Twiv@gI_7!RN_;5Zbos)oXq&7Lg7G=Y|Dq+DNmgWq6 zN>P|gSwd|73$UpL`&w%A?au1Xe1mWh&WLwini@HS!`sMmW|V`OgU@Qu?6C2r599)) zc5G&9y|}G?S(1}*7i``j3;$VZxWvYum!=l-8~?ucS^r0}@qzzX8a{WSPTq^v$y>pO z_e>feFzUqSZGdqn-a^vHf?G{-Fu2%jDMqZ<>E8J7Qrl`~E;|y6w)uTXOyw`dbLJhv z0Y}!0sXXW9JbCR-zMecd&1qt=wOD=49=5tT`vLq)lp9k9G!+i0< zhKCRHd?+bP=nFo~`iTS|-T*$>@a#^{wNLJp)U_ViZ4FC^er$IFyM9maX3JvbcZ zy)NMma6dTA{*46ur#QrYE5Q%^M~ZD|Pd?5nnig+mQ^MOL7WG=sz~S3nwzSXQ<-Kg{ am({r~4BTQ@w71y!TW`U)C4V%5b;)1aNSsyx diff --git a/shaders/fragComp.spv b/shaders/fragComp.spv deleted file mode 100644 index 72e9c53dc86abc778e95d42ceb0acccd813babad..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 956 zcmYk4OH0F05QWFKsgG*wyJ~$@T`J;2MG$pSB%4A71(%_;Q3A0kHHz*8_x>nAiFAxie=bEf)4C%_gj3bJn!+TCjo`6IV`lw|&<>dWri-C#T0Ks#Z*dXlgcX zCGFt38w|LZ78ZmxVMmyko_iJ2si^E`KYCoU8FSm7+v&LN8?QGUdN1)u=zC!>@V$O8 z@_TXc=A)a+>4HHoeC_82juiR&jyZ{k=rwLdVKh=XF^)Pki~aYz?(;D8#X9N_pO2&N z)4l)RilR|}tSwnxhh9pcqnD@9yN!Z@l8%Msq(9zggjDK=*Tylir~mcOph$;*R+!lpXlj>T=3|L=^5@oG1?`;?DHD^s!n*#>zPSj zzoA&``cU5hT|FHeYx=5HnYDo+$@jnHP&UzhWHiXz|1U0Z*5T>ANb> zGcolS1$z2U{Vb;(eLaZd?TWxV?ygjYZvdC&Sl5|8ztS9=I>XT$dOX1W$@RJL4-x-K AFaQ7m