mirror of
https://github.com/mmp/pbrt-v4
synced 2026-09-26 16:20:07 +03:00
120 lines
4.6 KiB
C++
120 lines
4.6 KiB
C++
// pbrt is Copyright(c) 1998-2020 Matt Pharr, Wenzel Jakob, and Greg Humphreys.
|
|
// The pbrt source code is licensed under the Apache License, Version 2.0.
|
|
// SPDX: Apache-2.0
|
|
|
|
#ifndef PBRT_GPU_ACCEL_H
|
|
#define PBRT_GPU_ACCEL_H
|
|
|
|
#include <pbrt/pbrt.h>
|
|
|
|
#include <pbrt/gpu/optix.h>
|
|
#include <pbrt/gpu/workitems.h>
|
|
#include <pbrt/materials.h>
|
|
#include <pbrt/parsedscene.h>
|
|
#include <pbrt/util/containers.h>
|
|
#include <pbrt/util/pstd.h>
|
|
#include <pbrt/util/soa.h>
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include <cuda.h>
|
|
#include <cuda_runtime.h>
|
|
#include <optix.h>
|
|
#include <cuda/std/atomic>
|
|
|
|
namespace pbrt {
|
|
|
|
class GPUAccel {
|
|
public:
|
|
GPUAccel(const ParsedScene &scene, Allocator alloc, CUstream cudaStream,
|
|
const std::map<int, pstd::vector<LightHandle> *> &shapeIndexToAreaLights,
|
|
const std::map<std::string, MediumHandle> &media,
|
|
pstd::array<bool, MaterialHandle::NumTags()> *haveBasicEvalMaterial,
|
|
pstd::array<bool, MaterialHandle::NumTags()> *haveUniversalEvalMaterial,
|
|
bool *haveSubsurface);
|
|
|
|
Bounds3f Bounds() const { return bounds; }
|
|
|
|
std::pair<cudaEvent_t, cudaEvent_t> IntersectClosest(
|
|
int maxRays, EscapedRayQueue *escapedRayQueue,
|
|
HitAreaLightQueue *hitAreaLightQueue, MaterialEvalQueue *basicEvalMaterialQueue,
|
|
MaterialEvalQueue *universalEvalMaterialQueue,
|
|
MediumTransitionQueue *mediumTransitionQueue,
|
|
MediumSampleQueue *mediumSampleQueue, RayQueue *rayQueue) const;
|
|
|
|
std::pair<cudaEvent_t, cudaEvent_t> IntersectShadow(
|
|
int maxRays, ShadowRayQueue *shadowRayQueue) const;
|
|
|
|
std::pair<cudaEvent_t, cudaEvent_t> IntersectShadowTr(int maxRays,
|
|
ShadowRayQueue *shadowRayQueue) const;
|
|
|
|
std::pair<cudaEvent_t, cudaEvent_t> IntersectOneRandom(
|
|
int maxRays, SubsurfaceScatterQueue *subsurfaceScatterQueue) const;
|
|
|
|
private:
|
|
struct HitgroupRecord;
|
|
|
|
OptixTraversableHandle createGASForTriangles(
|
|
const std::vector<ShapeSceneEntity> &shapes, const OptixProgramGroup &intersectPG,
|
|
const OptixProgramGroup &shadowPG, const OptixProgramGroup &randomHitPG,
|
|
const std::map<std::string, FloatTextureHandle> &floatTextures,
|
|
const std::map<std::string, MaterialHandle> &namedMaterials,
|
|
const std::vector<MaterialHandle> &materials,
|
|
const std::map<std::string, MediumHandle> &media,
|
|
const std::map<int, pstd::vector<LightHandle> *> &shapeIndexToAreaLights,
|
|
Bounds3f *gasBounds);
|
|
|
|
OptixTraversableHandle createGASForBLPs(
|
|
const std::vector<ShapeSceneEntity> &shapes, const OptixProgramGroup &intersectPG,
|
|
const OptixProgramGroup &shadowPG, const OptixProgramGroup &randomHitPG,
|
|
const std::map<std::string, FloatTextureHandle> &floatTextures,
|
|
const std::map<std::string, MaterialHandle> &namedMaterials,
|
|
const std::vector<MaterialHandle> &materials,
|
|
const std::map<std::string, MediumHandle> &media,
|
|
const std::map<int, pstd::vector<LightHandle> *> &shapeIndexToAreaLights,
|
|
Bounds3f *gasBounds);
|
|
|
|
OptixTraversableHandle createGASForQuadrics(
|
|
const std::vector<ShapeSceneEntity> &shapes, const OptixProgramGroup &intersectPG,
|
|
const OptixProgramGroup &shadowPG, const OptixProgramGroup &randomHitPG,
|
|
const std::map<std::string, FloatTextureHandle> &floatTextures,
|
|
const std::map<std::string, MaterialHandle> &namedMaterials,
|
|
const std::vector<MaterialHandle> &materials,
|
|
const std::map<std::string, MediumHandle> &media,
|
|
const std::map<int, pstd::vector<LightHandle> *> &shapeIndexToAreaLights,
|
|
Bounds3f *gasBounds);
|
|
|
|
OptixTraversableHandle buildBVH(const std::vector<OptixBuildInput> &buildInputs);
|
|
|
|
Allocator alloc;
|
|
Bounds3f bounds;
|
|
CUstream cudaStream;
|
|
OptixDeviceContext optixContext;
|
|
OptixModule optixModule;
|
|
OptixPipeline optixPipeline;
|
|
|
|
struct ParamBufferState {
|
|
bool used = false;
|
|
cudaEvent_t finishedEvent;
|
|
CUdeviceptr ptr = 0;
|
|
void *hostPtr = nullptr;
|
|
};
|
|
mutable std::vector<ParamBufferState> paramsPool;
|
|
mutable size_t nextParamOffset = 0;
|
|
|
|
ParamBufferState &getParamBuffer(const RayIntersectParameters &) const;
|
|
|
|
pstd::vector<HitgroupRecord> intersectHGRecords;
|
|
pstd::vector<HitgroupRecord> shadowHGRecords;
|
|
pstd::vector<HitgroupRecord> randomHitHGRecords;
|
|
OptixShaderBindingTable intersectSBT = {}, shadowSBT = {}, shadowTrSBT = {};
|
|
OptixShaderBindingTable randomHitSBT = {};
|
|
OptixTraversableHandle rootTraversable = {};
|
|
};
|
|
|
|
} // namespace pbrt
|
|
|
|
#endif // PBRT_GPU_ACCEL_H
|