AccelerationStructure.h#
↰ Parent directory (Vulkan
)
Includes#
PVRAssets/Model.h
PVRCore/glm.h
PVRUtils/Vulkan/HelperVk.h
PVRVk/AccelerationStructureVk.h
PVRVk/BufferVk.h
PVRVk/CommandPoolVk.h
Namespaces#
Classes#
Source Code#
#include "PVRCore/glm.h"
#include "PVRVk/BufferVk.h"
#include "PVRVk/AccelerationStructureVk.h"
#include "PVRVk/CommandPoolVk.h"
#include "PVRUtils/Vulkan/HelperVk.h"
#include <PVRAssets/Model.h>
#pragma once
namespace pvr {
namespace utils {
struct SceneDescription
{
uint32_t modelIndex = 0;
glm::mat4 transform = glm::mat4(1);
glm::mat4 transformIT = glm::mat4(1);
};
struct RTInstance
{
uint32_t modelIndex = 0;
uint32_t instanceId = 0;
uint32_t hitGroupId = 0;
uint32_t mask = 0xFF;
pvrvk::GeometryInstanceFlagsKHR flags = pvrvk::GeometryInstanceFlagsKHR::e_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR;
glm::mat4 transform = glm::mat4(1.0);
};
struct RTModelInfo
{
pvrvk::Buffer vertexBuffer;
pvrvk::Buffer indexBuffer;
uint32_t primitiveCount;
uint32_t vertexCount;
size_t vertexStride;
};
struct ASVertexFormat
{
glm::vec3 pos;
glm::vec3 nrm;
glm::vec2 texCoord;
glm::vec3 tangent;
};
class AccelerationStructureWrapper
{
private:
pvrvk::AccelerationStructure _tlas;
std::vector<pvrvk::AccelerationStructure> _blas;
std::vector<RTModelInfo> _rtModelInfos;
std::vector<RTInstance> _instances;
std::vector<SceneDescription> _sceneDescriptions;
pvrvk::Buffer _instancesBuffer;
public:
explicit AccelerationStructureWrapper() {}
void buildASModelDescription(std::vector<pvrvk::Buffer> vertexBuffers, std::vector<pvrvk::Buffer> indexBuffers, std::vector<int> verticesSize, std::vector<int> indicesSize,
const std::vector<glm::mat4>& vectorInstanceTransform);
void clearASModelDescriptionData();
void buildAS(pvrvk::Device device, pvrvk::Queue queue, pvrvk::CommandBuffer commandBuffer,
pvrvk::BuildAccelerationStructureFlagsKHR buildASFlags = pvrvk::BuildAccelerationStructureFlagsKHR::e_PREFER_FAST_TRACE_BIT_KHR);
void buildBottomLevelASModels(pvrvk::Device device, pvrvk::CommandBuffer commandBuffer, pvrvk::Queue queue);
void buildTopLevelASAndInstances(pvrvk::Device device, pvrvk::CommandBuffer commandBuffer, pvrvk::Queue queue, pvrvk::BuildAccelerationStructureFlagsKHR flags, bool update);
void setupGeometryInstances(pvrvk::Device device, std::vector<VkAccelerationStructureInstanceKHR>& geometryInstances);
inline pvrvk::AccelerationStructure getTopLevelAccelerationStructure() { return _tlas; }
inline std::vector<SceneDescription>& getSceneDescriptions() { return _sceneDescriptions; }
inline std::vector<pvrvk::AccelerationStructure>& getBlas() { return _blas; }
void updateInstanceTransformData(const std::vector<glm::mat4>& vectorTransform);
};
} // namespace utils
} // namespace pvr