Browse Source

Remove loading models

Loading models is removes from the ComputeAndGraphics and shaders folder is reordered.
master
AliMehrabani 2 weeks ago
parent
commit
a3f387cdd4
  1. 24
      VkTest.pro
  2. 57
      VulkanTutorial1.0/ComputeAndGraphics.cpp
  3. 38
      VulkanTutorial1.0/ComputeAndGraphics.h
  4. 2
      VulkanTutorial1.0/Types.h
  5. 0
      shaders/VulkanTutorial1.0/ComputeAndGraphics/compComp.spv
  6. 3
      shaders/VulkanTutorial1.0/ComputeAndGraphics/compile.sh
  7. BIN
      shaders/VulkanTutorial1.0/ComputeAndGraphics/fragComp.spv
  8. 0
      shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.comp
  9. 2
      shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.frag
  10. 0
      shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.vert
  11. 0
      shaders/VulkanTutorial1.0/ComputeAndGraphics/vertComp.spv
  12. 2
      shaders/VulkanTutorial1.0/HelloTriangle/compile.sh
  13. 0
      shaders/VulkanTutorial1.0/HelloTriangle/frag.spv
  14. 0
      shaders/VulkanTutorial1.0/HelloTriangle/shader.frag
  15. 0
      shaders/VulkanTutorial1.0/HelloTriangle/shader.vert
  16. 0
      shaders/VulkanTutorial1.0/HelloTriangle/vert.spv
  17. BIN
      shaders/comp.spv
  18. BIN
      shaders/fragComp.spv

24
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 +=

57
VulkanTutorial1.0/ComputeAndGraphics.cpp

@ -2,7 +2,6 @@
#include <QDebug>
#include <set>
#include <unordered_map>
#include <random>
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<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> 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<Vertex, uint32_t> 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<uint32_t>(_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();

38
VulkanTutorial1.0/ComputeAndGraphics.h

@ -111,16 +111,6 @@ struct Vertex {
}
};
namespace std {
template<> struct hash<Vertex> {
size_t operator()(Vertex const& vertex) const {
return ((hash<glm::vec3>()(vertex.pos) ^
(hash<glm::vec3>()(vertex.color) << 1)) >> 1) ^
(hash<glm::vec2>()(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<const char*> validationLayers = {
"VK_LAYER_KHRONOS_validation"
};
const std::vector<const char*> deviceExtensions = {
VK_KHR_SWAPCHAIN_EXTENSION_NAME
};
// const std::vector<Vertex> _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<Vertex> _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<uint16_t> _indices = {
// 0, 1, 2, 2, 3, 0,
};
const std::vector<uint32_t> _indices = {
0, 1, 2, 2, 3, 0,
// 4, 5, 6, 6, 7, 4
// };
std::vector<Vertex> _vertices;
std::vector<uint32_t> _indices;
};
uint32_t currentFrame = 0;
bool framebufferResized = false;

2
VulkanTutorial1.0/Types.h

@ -19,8 +19,6 @@
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/hash.hpp>
#include <stb_image/stb_image.h>
#include <tiny_obj_loader/tiny_obj_loader.h>

0
shaders/compComp.spv → shaders/VulkanTutorial1.0/ComputeAndGraphics/compComp.spv

3
shaders/compile.sh → 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

BIN
shaders/VulkanTutorial1.0/ComputeAndGraphics/fragComp.spv

Binary file not shown.

0
shaders/shaderCompute.comp → shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.comp

2
shaders/shaderCompute.frag → 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));
}

0
shaders/shaderCompute.vert → shaders/VulkanTutorial1.0/ComputeAndGraphics/shaderCompute.vert

0
shaders/vertComp.spv → shaders/VulkanTutorial1.0/ComputeAndGraphics/vertComp.spv

2
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

0
shaders/frag.spv → shaders/VulkanTutorial1.0/HelloTriangle/frag.spv

0
shaders/shader.frag → shaders/VulkanTutorial1.0/HelloTriangle/shader.frag

0
shaders/shader.vert → shaders/VulkanTutorial1.0/HelloTriangle/shader.vert

0
shaders/vert.spv → shaders/VulkanTutorial1.0/HelloTriangle/vert.spv

BIN
shaders/comp.spv

Binary file not shown.

BIN
shaders/fragComp.spv

Binary file not shown.
Loading…
Cancel
Save