one more texture to the GPU

This commit is contained in:
CDaut 2024-06-25 18:43:33 +02:00
parent 5cf68c5219
commit e7a7133e9f
Signed by: clara
GPG key ID: 223391B52FAD4463
1034 changed files with 324 additions and 4194331 deletions

View file

@ -19,6 +19,7 @@
#include <sstream>
#include <iostream>
#define TINYGLTF_IMPLEMENTATION
@ -118,6 +119,8 @@ void HelloVulkan::createDescriptorSetLayout()
bind.addBinding(eSceneDesc, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR
| VK_SHADER_STAGE_ANY_HIT_BIT_KHR);
//Primary Raygen texture
bind.addBinding(SceneBindings::ePointsetTexture, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
m_descSetLayout = m_descSetLayoutBind.createLayout(m_device);
m_descPool = m_descSetLayoutBind.createPool(m_device, 1);
@ -143,6 +146,8 @@ void HelloVulkan::updateDescriptorSet()
for(auto& texture : m_textures)
diit.emplace_back(texture.descriptor);
writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, SceneBindings::eTextures, diit.data()));
//add the pointset texture
writes.emplace_back(m_descSetLayoutBind.makeWrite(m_descSet, SceneBindings::ePointsetTexture, &m_pointset.descriptor));
// Writing the information
vkUpdateDescriptorSets(m_device, static_cast<uint32_t>(writes.size()), writes.data(), 0, nullptr);
@ -250,6 +255,8 @@ void HelloVulkan::loadScene(const std::string& filename)
// Creates all textures found
createTextureImages(cmdBuf, tmodel);
//generate and submit pointset
createPointsetTexture(cmdBuf);
cmdBufGet.submitAndWait(cmdBuf);
m_alloc.finalizeAndReleaseStaging();
@ -329,6 +336,45 @@ void HelloVulkan::createTextureImages(const VkCommandBuffer& cmdBuf, tinygltf::M
}
}
void HelloVulkan::createPointsetTexture(const VkCommandBuffer& cmdBuf)
{
VkSamplerCreateInfo samplerCreateInfo{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO};
samplerCreateInfo.minFilter = VK_FILTER_NEAREST;
samplerCreateInfo.magFilter = VK_FILTER_NEAREST;
samplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
samplerCreateInfo.maxLod = FLT_MAX;
samplerCreateInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerCreateInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerCreateInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
auto swapchainExtent = this->m_swapChain.getExtent();
// TODO: generate and parse pointset here
std::vector<float_t> points{};
points.reserve(swapchainExtent.height * swapchainExtent.width * 2);
for(int y = 0; y < swapchainExtent.height; ++y)
{
for(int x = 0; x < swapchainExtent.width; ++x)
{
float rand_x = static_cast<float>(rand()) / static_cast<float_t>(RAND_MAX);
float rand_y = static_cast<float>(rand()) / static_cast<float_t>(RAND_MAX);
std::cout << "x: " << rand_x << "|y: " << rand_y << std::endl;
points.emplace_back(rand_x);
points.emplace_back(rand_y);
}
}
VkImageCreateInfo imageCreateInfo = nvvk::makeImage2DCreateInfo(swapchainExtent, VK_FORMAT_R32G32_SFLOAT, VK_IMAGE_USAGE_SAMPLED_BIT, false);
nvvk::Image image = m_alloc.createImage(cmdBuf, points.size(), points.data(), imageCreateInfo);
VkImageViewCreateInfo ivInfo = nvvk::makeImageViewCreateInfo(image.image, imageCreateInfo);
m_pointset = m_alloc.createTexture(image, ivInfo, samplerCreateInfo);
m_debug.setObjectName(m_pointset.image, "pointset");
}
//--------------------------------------------------------------------------------------------------
// Destroying all allocations
//
@ -354,6 +400,8 @@ void HelloVulkan::destroyResources()
m_alloc.destroy(t);
}
m_alloc.destroy(m_pointset);
//#Post
m_alloc.destroy(m_offscreenColor);
m_alloc.destroy(m_offscreenDepth);