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

7
.idea/codeStyles/Project.xml generated Normal file
View file

@ -0,0 +1,7 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<clangFormatSettings>
<option name="ENABLED" value="true" />
</clangFormatSettings>
</code_scheme>
</component>

2
.idea/misc.xml generated
View file

@ -3,7 +3,7 @@
<component name="CMakePythonSetting"> <component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" /> <option name="pythonIntegrationState" value="YES" />
</component> </component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$/utk_experiments/utk"> <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$/raytracer">
<contentRoot DIR="$PROJECT_DIR$" /> <contentRoot DIR="$PROJECT_DIR$" />
</component> </component>
<component name="CidrRootsConfiguration"> <component name="CidrRootsConfiguration">

View file

@ -55,6 +55,7 @@
wayland wayland
# dev tools # dev tools
valgrind valgrind
renderdoc
# general deps # general deps
imgui imgui
# calculating fast fourier transforms # calculating fast fourier transforms
@ -65,7 +66,7 @@
cairo cairo
# ffmpeg for plot animation # ffmpeg for plot animation
ffmpeg ffmpeg
#ompß #omp
llvmPackages.openmp llvmPackages.openmp
] ++ [ ] ++ [
## Phython stuff for plotting ## Phython stuff for plotting

View file

@ -19,6 +19,7 @@
#include <sstream> #include <sstream>
#include <iostream>
#define TINYGLTF_IMPLEMENTATION #define TINYGLTF_IMPLEMENTATION
@ -118,6 +119,8 @@ void HelloVulkan::createDescriptorSetLayout()
bind.addBinding(eSceneDesc, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, 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_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT | VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR
| VK_SHADER_STAGE_ANY_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_descSetLayout = m_descSetLayoutBind.createLayout(m_device);
m_descPool = m_descSetLayoutBind.createPool(m_device, 1); m_descPool = m_descSetLayoutBind.createPool(m_device, 1);
@ -143,6 +146,8 @@ void HelloVulkan::updateDescriptorSet()
for(auto& texture : m_textures) for(auto& texture : m_textures)
diit.emplace_back(texture.descriptor); diit.emplace_back(texture.descriptor);
writes.emplace_back(m_descSetLayoutBind.makeWriteArray(m_descSet, SceneBindings::eTextures, diit.data())); 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 // Writing the information
vkUpdateDescriptorSets(m_device, static_cast<uint32_t>(writes.size()), writes.data(), 0, nullptr); 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 // Creates all textures found
createTextureImages(cmdBuf, tmodel); createTextureImages(cmdBuf, tmodel);
//generate and submit pointset
createPointsetTexture(cmdBuf);
cmdBufGet.submitAndWait(cmdBuf); cmdBufGet.submitAndWait(cmdBuf);
m_alloc.finalizeAndReleaseStaging(); 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 // Destroying all allocations
// //
@ -354,6 +400,8 @@ void HelloVulkan::destroyResources()
m_alloc.destroy(t); m_alloc.destroy(t);
} }
m_alloc.destroy(m_pointset);
//#Post //#Post
m_alloc.destroy(m_offscreenColor); m_alloc.destroy(m_offscreenColor);
m_alloc.destroy(m_offscreenDepth); m_alloc.destroy(m_offscreenDepth);

View file

@ -49,6 +49,7 @@ public:
void updateDescriptorSet(); void updateDescriptorSet();
void createUniformBuffer(); void createUniformBuffer();
void createTextureImages(const VkCommandBuffer& cmdBuf, tinygltf::Model& gltfModel); void createTextureImages(const VkCommandBuffer& cmdBuf, tinygltf::Model& gltfModel);
void createPointsetTexture(const VkCommandBuffer& cmdBuf);
void updateUniformBuffer(const VkCommandBuffer& cmdBuf); void updateUniformBuffer(const VkCommandBuffer& cmdBuf);
void onResize(int /*w*/, int /*h*/) override; void onResize(int /*w*/, int /*h*/) override;
void destroyResources(); void destroyResources();
@ -67,9 +68,9 @@ public:
// Information pushed at each draw call // Information pushed at each draw call
PushConstantRaster m_pcRaster{ PushConstantRaster m_pcRaster{
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, // Identity matrix {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, // Identity matrix
{0.f, 100.f, 0.f}, // light position {0.f, 100.f, 0.f}, // light position
0, // instance Id 0, // instance Id
1000.f, // light intensity 1000.f, // light intensity
0, // light type 0, // light type
0 // material id 0 // material id
}; };
@ -84,6 +85,7 @@ public:
nvvk::Buffer m_bGlobals; // Device-Host of the camera matrices nvvk::Buffer m_bGlobals; // Device-Host of the camera matrices
std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene std::vector<nvvk::Texture> m_textures; // vector of all textures of the scene
nvvk::Texture m_pointset; // Texture for starting locations of primary rays
nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures nvvk::ResourceAllocatorDma m_alloc; // Allocator for buffer, images, acceleration structures
nvvk::DebugUtil m_debug; // Utility to name objects nvvk::DebugUtil m_debug; // Utility to name objects

View file

@ -42,15 +42,16 @@ using uint = unsigned int;
#endif #endif
START_BINDING(SceneBindings) START_BINDING(SceneBindings)
eGlobals = 0, // Global uniform containing camera matrices eGlobals = 0, // Global uniform containing camera matrices
eSceneDesc = 1, // Access to the scene buffers eSceneDesc = 1, // Access to the scene buffers
eTextures = 2 // Access to textures eTextures = 2, // Access to textures
ePointsetTexture = 3 //Texture containing the pointset for primary raygen
END_BINDING(); END_BINDING();
START_BINDING(RtxBindings) START_BINDING(RtxBindings)
eTlas = 0, // Top-level acceleration structure eTlas = 0, // Top-level acceleration structure
eOutImage = 1, // Ray tracer output image eOutImage = 1, // Ray tracer output image
ePrimLookup = 2 // Lookup of objects ePrimLookup = 2 // Lookup of objects
END_BINDING(); END_BINDING();
// clang-format on // clang-format on

View file

@ -34,6 +34,8 @@ layout(set = 0, binding = 1, rgba32f) uniform image2D image;
layout(set = 1, binding = 0) uniform _GlobalUniforms { GlobalUniforms uni; }; layout(set = 1, binding = 0) uniform _GlobalUniforms { GlobalUniforms uni; };
layout(push_constant) uniform _PushConstantRay { PushConstantRay pcRay; }; layout(push_constant) uniform _PushConstantRay { PushConstantRay pcRay; };
layout(set = 1, binding = ePointsetTexture) uniform sampler2D pointset; // bluenoise pointset
// clang-format on // clang-format on
void main() void main()
@ -63,5 +65,7 @@ void main()
0 // payload (location = 0) 0 // payload (location = 0)
); );
imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(prd.hitValue, 1.0)); //imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(prd.hitValue, 1.0));
vec2 uv = vec2(float(gl_LaunchIDEXT.x) / float(gl_LaunchSizeEXT.x) - 0.5, float(gl_LaunchIDEXT.y) / float(gl_LaunchSizeEXT.y) - 0.5);
imageStore(image, ivec2(gl_LaunchIDEXT.xy), texture(pointset, uv));
} }

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show more