From 886e488a2670ff7585708d9e9df1fc932217e676 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 5 Nov 2018 10:26:54 -0500 Subject: [PATCH] Move third party libraries to 3rdparty folder --- 3rdparty/CMakeLists.txt | 2 + 3rdparty/nlohmann/CMakeLists.txt | 4 + .../nlohmann/include}/json.hpp | 0 3rdparty/stb/CMakeLists.txt | 5 + {include => 3rdparty/stb/include}/stb_image.h | 0 3rdparty/stb/src/stb.c | 2 + CMakeLists.txt | 10 +- src/dofpass.cpp | 192 +++++++++--------- src/main.cpp | 7 +- 9 files changed, 120 insertions(+), 102 deletions(-) create mode 100644 3rdparty/CMakeLists.txt create mode 100644 3rdparty/nlohmann/CMakeLists.txt rename {include => 3rdparty/nlohmann/include}/json.hpp (100%) create mode 100644 3rdparty/stb/CMakeLists.txt rename {include => 3rdparty/stb/include}/stb_image.h (100%) create mode 100644 3rdparty/stb/src/stb.c diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt new file mode 100644 index 0000000..d303052 --- /dev/null +++ b/3rdparty/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(nlohmann) +add_subdirectory(stb) diff --git a/3rdparty/nlohmann/CMakeLists.txt b/3rdparty/nlohmann/CMakeLists.txt new file mode 100644 index 0000000..85334dd --- /dev/null +++ b/3rdparty/nlohmann/CMakeLists.txt @@ -0,0 +1,4 @@ +add_library(nlohmann INTERFACE) +target_include_directories(nlohmann INTERFACE include) + +add_library(nlohmann::json ALIAS nlohmann) diff --git a/include/json.hpp b/3rdparty/nlohmann/include/json.hpp similarity index 100% rename from include/json.hpp rename to 3rdparty/nlohmann/include/json.hpp diff --git a/3rdparty/stb/CMakeLists.txt b/3rdparty/stb/CMakeLists.txt new file mode 100644 index 0000000..c6730ae --- /dev/null +++ b/3rdparty/stb/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(stb + src/stb.c) +target_include_directories(stb PUBLIC include) + +add_library(stb::stb ALIAS stb) diff --git a/include/stb_image.h b/3rdparty/stb/include/stb_image.h similarity index 100% rename from include/stb_image.h rename to 3rdparty/stb/include/stb_image.h diff --git a/3rdparty/stb/src/stb.c b/3rdparty/stb/src/stb.c new file mode 100644 index 0000000..8ddfd1f --- /dev/null +++ b/3rdparty/stb/src/stb.c @@ -0,0 +1,2 @@ +#define STB_IMAGE_IMPLEMENTATION +#include "stb_image.h" diff --git a/CMakeLists.txt b/CMakeLists.txt index b66a611..7b2698d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ project(Graph) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) +add_subdirectory(3rdparty) + include(cmake/BuildShaders.cmake) include(cmake/CopyData.cmake) @@ -22,7 +24,13 @@ add_executable(Graph src/worldpass.cpp src/postpass.cpp src/dofpass.cpp) -target_link_libraries(Graph PUBLIC SDL2::SDL2 SDL2::SDL2main Vulkan::Vulkan assimp::assimp) +target_link_libraries(Graph PUBLIC + SDL2::SDL2 + SDL2::SDL2main + Vulkan::Vulkan + assimp::assimp + nlohmann::json + stb::stb) target_include_directories(Graph PUBLIC include) add_shaders(Graph diff --git a/src/dofpass.cpp b/src/dofpass.cpp index 966af4a..a0413a7 100644 --- a/src/dofpass.cpp +++ b/src/dofpass.cpp @@ -2,9 +2,7 @@ #include #include - -#define STB_IMAGE_IMPLEMENTATION -#include "stb_image.h" +#include #include "renderer.h" @@ -20,12 +18,12 @@ DoFPass::~DoFPass() { vkDestroyImageView(renderer_.getDevice(), bokehImageView_, nullptr); vkFreeMemory(renderer_.getDevice(), bokehMemory_, nullptr); vkDestroyImage(renderer_.getDevice(), bokehImage_, nullptr); - + vkDestroyPipeline(renderer_.getDevice(), pipeline_, nullptr); vkDestroyPipelineLayout(renderer_.getDevice(), pipelineLayout_, nullptr); - + vkDestroyDescriptorSetLayout(renderer_.getDevice(), setLayout_, nullptr); - + vkDestroyRenderPass(renderer_.getDevice(), renderPass_, nullptr); } @@ -34,17 +32,17 @@ void DoFPass::render(VkCommandBuffer commandBuffer, RenderTarget* target) { viewport.width = target->extent.width / 2; viewport.height = target->extent.height / 2; viewport.maxDepth = 1.0f; - + vkCmdSetViewport(commandBuffer, 0, 1, &viewport); - + VkRect2D scissor = {}; scissor.extent.width = target->extent.width / 2; scissor.extent.height = target->extent.height / 2; - + vkCmdSetScissor(commandBuffer, 0, 1, &scissor); - + VkClearValue clearColor = {}; - + VkRenderPassBeginInfo renderPassBeginInfo = {}; renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; renderPassBeginInfo.framebuffer = target->farFieldFramebuffers[target->currentImage]; @@ -53,41 +51,41 @@ void DoFPass::render(VkCommandBuffer commandBuffer, RenderTarget* target) { renderPassBeginInfo.renderArea.extent.height = target->extent.height / 2; renderPassBeginInfo.clearValueCount = 1; renderPassBeginInfo.pClearValues = &clearColor; - + // far field vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); - + glm::vec4 dpack; dpack[0] = 0; dpack[1] = 0.9581; dpack[2] = target->extent.width / 2; dpack[3] = target->extent.height / 2; - + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->dofSets[target->currentImage], 0, nullptr); - + vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(glm::vec4), &dpack); - + vkCmdDraw(commandBuffer, 3, (target->extent.width / 2) * (target->extent.height / 2), 0, 0); - + vkCmdEndRenderPass(commandBuffer); - + //near field renderPassBeginInfo.framebuffer = target->nearFieldFramebuffers[target->currentImage]; - + vkCmdBeginRenderPass(commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); - + vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_); vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout_, 0, 1, &target->dofSets[target->currentImage], 0, nullptr); - + dpack[0] = 1; dpack[1] = 0.9581; vkCmdPushConstants(commandBuffer, pipelineLayout_, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(glm::vec4), &dpack); - + //FIXME: near field is bugged //vkCmdDraw(commandBuffer, 3, (target->extent.width / 2) * (target->extent.height / 2), 0, 0); - + vkCmdEndRenderPass(commandBuffer); } @@ -96,42 +94,42 @@ void DoFPass::createDescriptorSet(RenderTarget* target) { allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; allocInfo.descriptorPool = renderer_.getDescriptorPool(); allocInfo.descriptorSetCount = target->numImages; - + // FIXME: lol what auto layouts = new VkDescriptorSetLayout[target->numImages]; for(uint32_t i = 0; i < target->numImages; i++) layouts[i] = setLayout_; - + allocInfo.pSetLayouts = layouts; - + target->dofSets = new VkDescriptorSet[target->numImages]; vkAllocateDescriptorSets(renderer_.getDevice(), &allocInfo, target->dofSets); - + delete[] layouts; - + for(uint32_t i = 0; i < target->numImages; i++) { VkDescriptorImageInfo bokehImageInfo = {}; bokehImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; bokehImageInfo.imageView = bokehImageView_; bokehImageInfo.sampler = bokehSampler_; - + VkDescriptorImageInfo sceneImageInfo = {}; sceneImageInfo.imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; sceneImageInfo.imageView = target->offscreenColorImageViews[i]; sceneImageInfo.sampler = bokehSampler_; - + VkDescriptorImageInfo depthImageInfo = {}; depthImageInfo.imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;; depthImageInfo.imageView = target->offscreenDepthImageViews[i]; depthImageInfo.sampler = bokehSampler_; - + VkWriteDescriptorSet bokehDescriptorWrite = {}; bokehDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; bokehDescriptorWrite.descriptorCount = 1; bokehDescriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; bokehDescriptorWrite.dstSet = target->dofSets[i]; bokehDescriptorWrite.pImageInfo = &bokehImageInfo; - + VkWriteDescriptorSet sceneDescriptorWrite = {}; sceneDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; sceneDescriptorWrite.descriptorCount = 1; @@ -139,7 +137,7 @@ void DoFPass::createDescriptorSet(RenderTarget* target) { sceneDescriptorWrite.dstBinding = 1; sceneDescriptorWrite.dstSet = target->dofSets[i]; sceneDescriptorWrite.pImageInfo = &sceneImageInfo; - + VkWriteDescriptorSet depthDescriptorWrite = {}; depthDescriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; depthDescriptorWrite.descriptorCount = 1; @@ -147,13 +145,13 @@ void DoFPass::createDescriptorSet(RenderTarget* target) { depthDescriptorWrite.dstBinding = 2; depthDescriptorWrite.dstSet = target->dofSets[i]; depthDescriptorWrite.pImageInfo = &depthImageInfo; - + const std::array descriptorWrites = { bokehDescriptorWrite, sceneDescriptorWrite, depthDescriptorWrite }; - + vkUpdateDescriptorSets(renderer_.getDevice(), descriptorWrites.size(), descriptorWrites.data(), 0, nullptr); } } @@ -168,10 +166,10 @@ void DoFPass::createRenderPass() { colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE; colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; colorAttachment.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - + VkAttachmentReference colorAttachmentRef = {}; colorAttachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; - + VkSubpassDescription subpass = {}; subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass.colorAttachmentCount = 1; @@ -183,7 +181,7 @@ void DoFPass::createRenderPass() { renderPassInfo.pAttachments = &colorAttachment; renderPassInfo.subpassCount = 1; renderPassInfo.pSubpasses = &subpass; - + vkCreateRenderPass(renderer_.getDevice(), &renderPassInfo, nullptr, &renderPass_); } @@ -192,74 +190,74 @@ void DoFPass::createDescriptorSetLayout() { bokehSamplerBinding.descriptorCount = 1; bokehSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; bokehSamplerBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - + VkDescriptorSetLayoutBinding sceneSamplerBinding = {}; sceneSamplerBinding.binding = 1; sceneSamplerBinding.descriptorCount = 1; sceneSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; sceneSamplerBinding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; - + VkDescriptorSetLayoutBinding depthSamplerBinding = {}; depthSamplerBinding.binding = 2; depthSamplerBinding.descriptorCount = 1; depthSamplerBinding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; depthSamplerBinding.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; - + const std::array bindings = { bokehSamplerBinding, sceneSamplerBinding, depthSamplerBinding }; - + VkDescriptorSetLayoutCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; createInfo.bindingCount = bindings.size(); createInfo.pBindings = bindings.data(); - + vkCreateDescriptorSetLayout(renderer_.getDevice(), &createInfo, nullptr, &setLayout_); } void DoFPass::createPipeline() { VkShaderModule vertShaderModule = renderer_.createShader("shaders/gfield.vert.spv"); VkShaderModule fragShaderModule = renderer_.createShader("shaders/gfield.frag.spv"); - + VkPipelineShaderStageCreateInfo vertShaderStageInfo = {}; vertShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; vertShaderStageInfo.stage = VK_SHADER_STAGE_VERTEX_BIT; vertShaderStageInfo.module = vertShaderModule; vertShaderStageInfo.pName = "main"; - + VkPipelineShaderStageCreateInfo fragShaderStageInfo = {}; fragShaderStageInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; fragShaderStageInfo.stage = VK_SHADER_STAGE_FRAGMENT_BIT; fragShaderStageInfo.module = fragShaderModule; fragShaderStageInfo.pName = "main"; - + const std::array shaderStages = {vertShaderStageInfo, fragShaderStageInfo}; - + VkPipelineVertexInputStateCreateInfo vertexInputInfo = {}; vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; - + VkPipelineInputAssemblyStateCreateInfo inputAssembly = {}; inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO; inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST; - + VkPipelineViewportStateCreateInfo viewportState = {}; viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO; viewportState.viewportCount = 1; viewportState.scissorCount = 1; - + VkPipelineRasterizationStateCreateInfo rasterizer = {}; rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; rasterizer.polygonMode = VK_POLYGON_MODE_FILL; rasterizer.lineWidth = 1.0f; rasterizer.cullMode = VK_CULL_MODE_FRONT_BIT; rasterizer.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE; - + VkPipelineMultisampleStateCreateInfo multisampling = {}; multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampling.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT; - + VkPipelineColorBlendAttachmentState colorBlendAttachment = {}; colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; colorBlendAttachment.blendEnable = VK_TRUE; @@ -269,35 +267,35 @@ void DoFPass::createPipeline() { colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - + VkPipelineColorBlendStateCreateInfo colorBlending = {}; colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; colorBlending.attachmentCount = 1; colorBlending.pAttachments = &colorBlendAttachment; - + const std::array dynamicStates = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR }; - + VkPipelineDynamicStateCreateInfo dynamicState = {}; dynamicState.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; dynamicState.dynamicStateCount = dynamicStates.size(); dynamicState.pDynamicStates = dynamicStates.data(); - + VkPushConstantRange pushConstant = {}; pushConstant.size = sizeof(glm::vec4); pushConstant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT; - + VkPipelineLayoutCreateInfo pipelineLayoutInfo = {}; pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; pipelineLayoutInfo.setLayoutCount = 1; pipelineLayoutInfo.pSetLayouts = &setLayout_; pipelineLayoutInfo.pushConstantRangeCount = 1; pipelineLayoutInfo.pPushConstantRanges = &pushConstant; - + vkCreatePipelineLayout(renderer_.getDevice(), &pipelineLayoutInfo, nullptr, &pipelineLayout_); - + VkGraphicsPipelineCreateInfo pipelineInfo = {}; pipelineInfo.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipelineInfo.stageCount = shaderStages.size(); @@ -311,9 +309,9 @@ void DoFPass::createPipeline() { pipelineInfo.pDynamicState = &dynamicState; pipelineInfo.layout = pipelineLayout_; pipelineInfo.renderPass = renderPass_; - + vkCreateGraphicsPipelines(renderer_.getDevice(), nullptr, 1, &pipelineInfo, nullptr, &pipeline_); - + vkDestroyShaderModule(renderer_.getDevice(), fragShaderModule, nullptr); vkDestroyShaderModule(renderer_.getDevice(), vertShaderModule, nullptr); } @@ -323,7 +321,7 @@ void DoFPass::createBokehImage() { stbi_uc* pixels = stbi_load("data/bokeh.png", &width, &height, &channels, STBI_rgb_alpha); if(pixels == nullptr) return; // haha what - + VkImageCreateInfo imageCreateInfo = {}; imageCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageCreateInfo.imageType = VK_IMAGE_TYPE_2D; @@ -338,61 +336,61 @@ void DoFPass::createBokehImage() { imageCreateInfo.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT; imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; imageCreateInfo.samples = VK_SAMPLE_COUNT_1_BIT; - + vkCreateImage(renderer_.getDevice(), &imageCreateInfo, nullptr, &bokehImage_); - + VkMemoryRequirements memRequirements; vkGetImageMemoryRequirements(renderer_.getDevice(), bokehImage_, &memRequirements); - + VkMemoryAllocateInfo allocInfo = {}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; allocInfo.allocationSize = memRequirements.size; allocInfo.memoryTypeIndex = renderer_.findMemoryType(memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); - + vkAllocateMemory(renderer_.getDevice(), &allocInfo, nullptr, &bokehMemory_); vkBindImageMemory(renderer_.getDevice(), bokehImage_, bokehMemory_, 0); - + VkBuffer stagingBuffer; VkDeviceMemory stagingMemory; - + VkBufferCreateInfo bufferInfo = {}; bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; bufferInfo.size = width * height * 4; bufferInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT; bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; - + vkCreateBuffer(renderer_.getDevice(), &bufferInfo, nullptr, &stagingBuffer); - + vkGetBufferMemoryRequirements(renderer_.getDevice(), stagingBuffer, &memRequirements); - + allocInfo = {}; allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; allocInfo.allocationSize = memRequirements.size; allocInfo.memoryTypeIndex = renderer_.findMemoryType(memRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); - + vkAllocateMemory(renderer_.getDevice(), &allocInfo, nullptr, &stagingMemory); vkBindBufferMemory(renderer_.getDevice(), stagingBuffer, stagingMemory, 0); - + void* data; vkMapMemory(renderer_.getDevice(), stagingMemory, 0, width * height * 4, 0, &data); memcpy(data, pixels, width * height * 4); vkUnmapMemory(renderer_.getDevice(), stagingMemory); - + stbi_image_free(pixels); - + VkCommandBufferAllocateInfo bufferAllocateInfo = {}; bufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; bufferAllocateInfo.commandPool = renderer_.getCommandPool(); bufferAllocateInfo.commandBufferCount = 1; - + VkCommandBuffer commandBuffer = nullptr; vkAllocateCommandBuffers(renderer_.getDevice(), &bufferAllocateInfo, &commandBuffer); - + VkCommandBufferBeginInfo beginInfo = {}; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; - + vkBeginCommandBuffer(commandBuffer, &beginInfo); - + // change layout to transfer dst { VkImageMemoryBarrier imageMemoryBarrier = {}; @@ -403,7 +401,7 @@ void DoFPass::createBokehImage() { imageMemoryBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; imageMemoryBarrier.subresourceRange.layerCount = 1; imageMemoryBarrier.subresourceRange.levelCount = 1; - + vkCmdPipelineBarrier( commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, @@ -413,14 +411,14 @@ void DoFPass::createBokehImage() { 0, nullptr, 1, &imageMemoryBarrier); } - - VkBufferImageCopy region = {}; + + VkBufferImageCopy region = {}; region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; region.imageSubresource.layerCount = 1; region.imageExtent.width = width; region.imageExtent.height = height; region.imageExtent.depth = 1; - + vkCmdCopyBufferToImage( commandBuffer, stagingBuffer, @@ -429,7 +427,7 @@ void DoFPass::createBokehImage() { 1, ®ion ); - + // change layout to shader read only { VkImageMemoryBarrier imageMemoryBarrier = {}; @@ -442,7 +440,7 @@ void DoFPass::createBokehImage() { imageMemoryBarrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; imageMemoryBarrier.subresourceRange.layerCount = 1; imageMemoryBarrier.subresourceRange.levelCount = 1; - + vkCmdPipelineBarrier( commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, @@ -452,30 +450,30 @@ void DoFPass::createBokehImage() { 0, nullptr, 1, &imageMemoryBarrier); } - + vkEndCommandBuffer(commandBuffer); - + VkSubmitInfo submitInfo = {}; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.commandBufferCount = 1; submitInfo.pCommandBuffers = &commandBuffer; - + VkFenceCreateInfo fenceCreateInfo = {}; fenceCreateInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; - + VkFence fence = nullptr; vkCreateFence(renderer_.getDevice(), &fenceCreateInfo, nullptr, &fence); - + vkQueueSubmit(renderer_.getGraphicsQueue(), 1, &submitInfo, fence); - + vkWaitForFences(renderer_.getDevice(), 1, &fence, VK_TRUE, -1); vkDestroyFence(renderer_.getDevice(), fence, nullptr); - + vkFreeCommandBuffers(renderer_.getDevice(), renderer_.getCommandPool(), 1, &commandBuffer); - + vkFreeMemory(renderer_.getDevice(), stagingMemory, nullptr); vkDestroyBuffer(renderer_.getDevice(), stagingBuffer, nullptr); - + VkImageViewCreateInfo createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; createInfo.image = bokehImage_; @@ -484,9 +482,9 @@ void DoFPass::createBokehImage() { createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; createInfo.subresourceRange.levelCount = 1; createInfo.subresourceRange.layerCount = 1; - + vkCreateImageView(renderer_.getDevice(), &createInfo, nullptr, &bokehImageView_); - + VkSamplerCreateInfo samplerInfo = {}; samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; samplerInfo.magFilter = VK_FILTER_LINEAR; @@ -496,6 +494,6 @@ void DoFPass::createBokehImage() { samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER; samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK; samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - + vkCreateSampler(renderer_.getDevice(), &samplerInfo, nullptr, &bokehSampler_); } diff --git a/src/main.cpp b/src/main.cpp index d639619..697f1d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ #include #include #include - +#include #include #include #include @@ -15,7 +15,6 @@ #include "light.h" #include "camera.h" #include "cinematic.h" -#include "json.hpp" SDL_Window* window = nullptr; Renderer* renderer = nullptr; @@ -106,7 +105,7 @@ Mesh* loadMesh(const char* path) { unsigned int indexOffset = 0; for(unsigned mi = 0; mi < scene->mNumMeshes; mi++) { aiMesh* m = scene->mMeshes[mi]; - + for(unsigned int i = 0; i < m->mNumVertices; i++) { Vertex vertex; vertex.position = glm::vec3(m->mVertices[i].x, m->mVertices[i].y, m->mVertices[i].z); @@ -120,7 +119,7 @@ Mesh* loadMesh(const char* path) { for(unsigned int j = 0; j < face.mNumIndices; j++) mesh->indices.push_back(indexOffset + face.mIndices[j]); } - + indexOffset += m->mNumVertices; }