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 0000000..0a369b5 Binary files /dev/null and b/shaders/VulkanTutorial1.0/ComputeAndGraphics/fragComp.spv differ 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 7416b6f..0000000 Binary files a/shaders/comp.spv and /dev/null differ diff --git a/shaders/fragComp.spv b/shaders/fragComp.spv deleted file mode 100644 index 72e9c53..0000000 Binary files a/shaders/fragComp.spv and /dev/null differ