one more texture to the GPU
This commit is contained in:
parent
5cf68c5219
commit
e7a7133e9f
1034 changed files with 324 additions and 4194331 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ public:
|
|||
void updateDescriptorSet();
|
||||
void createUniformBuffer();
|
||||
void createTextureImages(const VkCommandBuffer& cmdBuf, tinygltf::Model& gltfModel);
|
||||
void createPointsetTexture(const VkCommandBuffer& cmdBuf);
|
||||
void updateUniformBuffer(const VkCommandBuffer& cmdBuf);
|
||||
void onResize(int /*w*/, int /*h*/) override;
|
||||
void destroyResources();
|
||||
|
|
@ -67,9 +68,9 @@ public:
|
|||
// Information pushed at each draw call
|
||||
PushConstantRaster m_pcRaster{
|
||||
{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
|
||||
1000.f, // light intensity
|
||||
1000.f, // light intensity
|
||||
0, // light type
|
||||
0 // material id
|
||||
};
|
||||
|
|
@ -84,6 +85,7 @@ public:
|
|||
|
||||
nvvk::Buffer m_bGlobals; // Device-Host of the camera matrices
|
||||
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::DebugUtil m_debug; // Utility to name objects
|
||||
|
|
|
|||
|
|
@ -42,15 +42,16 @@ using uint = unsigned int;
|
|||
#endif
|
||||
|
||||
START_BINDING(SceneBindings)
|
||||
eGlobals = 0, // Global uniform containing camera matrices
|
||||
eSceneDesc = 1, // Access to the scene buffers
|
||||
eTextures = 2 // Access to textures
|
||||
eGlobals = 0, // Global uniform containing camera matrices
|
||||
eSceneDesc = 1, // Access to the scene buffers
|
||||
eTextures = 2, // Access to textures
|
||||
ePointsetTexture = 3 //Texture containing the pointset for primary raygen
|
||||
END_BINDING();
|
||||
|
||||
START_BINDING(RtxBindings)
|
||||
eTlas = 0, // Top-level acceleration structure
|
||||
eOutImage = 1, // Ray tracer output image
|
||||
ePrimLookup = 2 // Lookup of objects
|
||||
eTlas = 0, // Top-level acceleration structure
|
||||
eOutImage = 1, // Ray tracer output image
|
||||
ePrimLookup = 2 // Lookup of objects
|
||||
END_BINDING();
|
||||
// clang-format on
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ layout(set = 0, binding = 1, rgba32f) uniform image2D image;
|
|||
|
||||
layout(set = 1, binding = 0) uniform _GlobalUniforms { GlobalUniforms uni; };
|
||||
layout(push_constant) uniform _PushConstantRay { PushConstantRay pcRay; };
|
||||
|
||||
layout(set = 1, binding = ePointsetTexture) uniform sampler2D pointset; // bluenoise pointset
|
||||
// clang-format on
|
||||
|
||||
void main()
|
||||
|
|
@ -63,5 +65,7 @@ void main()
|
|||
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));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue