Bulk update nvpro-samples 05/17/21

Changing license from BSD-3 to Apache2
This commit is contained in:
Mathias Heyer 2021-05-17 13:10:30 -07:00
parent d370c2168b
commit d2ade024c4
279 changed files with 7236 additions and 6905 deletions

View file

@ -1,42 +1,36 @@
/* Copyright (c) 2014-2018, NVIDIA CORPORATION. All rights reserved.
/*
* Copyright (c) 2014-2021, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-FileCopyrightText: Copyright (c) 2014-2021 NVIDIA CORPORATION
* SPDX-License-Identifier: Apache-2.0
*/
#include <sstream>
#include <vulkan/vulkan.hpp>
extern std::vector<std::string> defaultSearchPaths;
#define STB_IMAGE_IMPLEMENTATION
#include "fileformats/stb_image.h"
#include "obj_loader.h"
#include "stb_image.h"
#include "hello_vulkan.h"
#include "nvh//cameramanipulator.hpp"
#include "nvvk/descriptorsets_vk.hpp"
#include "nvvk/images_vk.hpp"
#include "nvvk/pipeline_vk.hpp"
#include "nvh/alignment.hpp"
@ -382,8 +376,7 @@ void HelloVulkan::createTextureImages(const vk::CommandBuffer& cmdBuf,
auto imageCreateInfo = nvvk::makeImage2DCreateInfo(imgSize, format, vkIU::eSampled, true);
{
nvvk::ImageDedicated image =
m_alloc.createImage(cmdBuf, bufferSize, pixels, imageCreateInfo);
nvvk::Image image = m_alloc.createImage(cmdBuf, bufferSize, pixels, imageCreateInfo);
nvvk::cmdGenerateMipmaps(cmdBuf, image.image, format, imgSize, imageCreateInfo.mipLevels);
vk::ImageViewCreateInfo ivInfo =
nvvk::makeImageViewCreateInfo(image.image, imageCreateInfo);
@ -433,12 +426,15 @@ void HelloVulkan::destroyResources()
m_device.destroy(m_offscreenFramebuffer);
// #VKRay
m_sbtWrapper.destroy();
m_rtBuilder.destroy();
m_device.destroy(m_rtDescPool);
m_device.destroy(m_rtDescSetLayout);
m_device.destroy(m_rtPipeline);
m_device.destroy(m_rtPipelineLayout);
m_alloc.destroy(m_rtSBTBuffer);
m_alloc.deinit();
}
//--------------------------------------------------------------------------------------------------
@ -653,12 +649,14 @@ void HelloVulkan::initRayTracing()
vk::PhysicalDeviceRayTracingPipelinePropertiesKHR>();
m_rtProperties = properties.get<vk::PhysicalDeviceRayTracingPipelinePropertiesKHR>();
m_rtBuilder.setup(m_device, &m_alloc, m_graphicsQueueIndex);
m_sbtWrapper.setup(m_device, m_graphicsQueueIndex, &m_alloc, m_rtProperties);
}
//--------------------------------------------------------------------------------------------------
// Converting a OBJ primitive to the ray tracing geometry used for the BLAS
//
nvvk::RaytracingBuilderKHR::BlasInput HelloVulkan::objectToVkGeometryKHR(const ObjModel& model)
auto HelloVulkan::objectToVkGeometryKHR(const ObjModel& model)
{
vk::DeviceAddress vertexAddress = m_device.getBufferAddress({model.vertexBuffer.buffer});
vk::DeviceAddress indexAddress = m_device.getBufferAddress({model.indexBuffer.buffer});
@ -854,6 +852,13 @@ void HelloVulkan::createRtPipeline()
m_rtPipeline = static_cast<const vk::Pipeline&>(
m_device.createRayTracingPipelineKHR({}, {}, rayPipelineInfo));
// Manually defining group indices
m_sbtWrapper.addIndices(rayPipelineInfo);
m_sbtWrapper.addIndex(SBTWrapper::eHit, 4); // hit = 2
m_sbtWrapper.addData(SBTWrapper::eHit, 1, m_hitShaderRecord[0]);
m_sbtWrapper.addData(SBTWrapper::eHit, 2, m_hitShaderRecord[1]);
m_sbtWrapper.create(m_rtPipeline);
m_device.destroy(raygenSM);
m_device.destroy(missSM);
m_device.destroy(shadowmissSM);
@ -963,26 +968,39 @@ void HelloVulkan::raytrace(const vk::CommandBuffer& cmdBuf, const nvmath::vec4f&
0, m_rtPushConstants);
// Size of a program identifier
uint32_t groupSize =
nvh::align_up(m_rtProperties.shaderGroupHandleSize, m_rtProperties.shaderGroupBaseAlignment);
uint32_t groupStride = groupSize;
vk::DeviceSize hitGroupSize =
nvh::align_up(m_rtProperties.shaderGroupHandleSize + sizeof(HitRecordBuffer),
m_rtProperties.shaderGroupBaseAlignment);
vk::DeviceAddress sbtAddress = m_device.getBufferAddress({m_rtSBTBuffer.buffer});
//// Size of a program identifier
//uint32_t groupSize =
// nvh::align_up(m_rtProperties.shaderGroupHandleSize, m_rtProperties.shaderGroupBaseAlignment);
//uint32_t groupStride = groupSize;
//vk::DeviceSize hitGroupSize =
// nvh::align_up(m_rtProperties.shaderGroupHandleSize + sizeof(HitRecordBuffer),
// m_rtProperties.shaderGroupBaseAlignment);
//vk::DeviceAddress sbtAddress = m_device.getBufferAddress({m_rtSBTBuffer.buffer});
using Stride = vk::StridedDeviceAddressRegionKHR;
std::array<Stride, 4> strideAddresses{
Stride{sbtAddress + 0u * groupSize, groupStride, groupSize * 1}, // raygen
Stride{sbtAddress + 1u * groupSize, groupStride, groupSize * 2}, // miss
Stride{sbtAddress + 3u * groupSize, hitGroupSize, hitGroupSize * 3}, // hit
Stride{0u, 0u, 0u}}; // callable
//using Stride = vk::StridedDeviceAddressRegionKHR;
//std::array<Stride, 4> strideAddresses{
// Stride{sbtAddress + 0u * groupSize, groupStride, groupSize * 1}, // raygen
// Stride{sbtAddress + 1u * groupSize, groupStride, groupSize * 2}, // miss
// Stride{sbtAddress + 3u * groupSize, hitGroupSize, hitGroupSize * 3}, // hit
// Stride{0u, 0u, 0u}}; // callable
cmdBuf.traceRaysKHR(&strideAddresses[0], &strideAddresses[1], &strideAddresses[2],
&strideAddresses[3], //
m_size.width, m_size.height, 1); //
//strideAddresses[0] = m_sbtWrapper.getRaygenRegion();
//strideAddresses[1] = m_sbtWrapper.getMissRegion();
//strideAddresses[2] = m_sbtWrapper.getHitRegion();
//cmdBuf.traceRaysKHR(&strideAddresses[0], &strideAddresses[1], &strideAddresses[2],
// &strideAddresses[3], //
// m_size.width, m_size.height, 1); //
//std::array<vk::StridedDeviceAddressRegionKHR, 4> regions;
//regions[0] = m_sbtWrapper.getRegion(SBTWrapper::eRaygen);
//regions[1] = m_sbtWrapper.getRegion(SBTWrapper::eMiss);
//regions[2] = m_sbtWrapper.getRegion(SBTWrapper::eHit);
//regions[3] = m_sbtWrapper.getRegion(SBTWrapper::eCallable);
auto regions = m_sbtWrapper.getRegions();
cmdBuf.traceRaysKHR(regions[0], regions[1], regions[2], regions[3], //
m_size.width, m_size.height, 1); //
m_debug.endLabel(cmdBuf);
}