-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathrenderParam.h
165 lines (134 loc) · 4 KB
/
renderParam.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "debugCodes.h"
#include "geometry.h"
#include "hdAnariTypes.h"
#include "material.h"
#include <anari/anari_cpp.hpp>
#include <anari/anari_cpp/anari_cpp_impl.hpp>
// pxr
#include <pxr/base/tf/debug.h>
#include <pxr/base/tf/diagnostic.h>
#include <pxr/base/tf/hashmap.h>
#include <pxr/base/tf/token.h>
#include <pxr/imaging/hd/enums.h>
#include <pxr/imaging/hd/renderDelegate.h>
#include <pxr/imaging/hd/renderThread.h>
#include <pxr/imaging/hd/tokens.h>
#include <pxr/pxr.h>
#include <pxr/usd/sdf/pathTable.h>
// std
#include <algorithm>
#include <atomic>
#include <cassert>
#include <mutex>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class HdAnariGeometry;
using GeometryList = std::vector<const HdAnariGeometry *>;
struct HdAnariMesh;
using MeshList = std::vector<const HdAnariMesh *>;
class HdAnariRenderParam final : public HdRenderParam
{
public:
enum class MaterialType
{
Matte,
PhysicallyBased,
};
HdAnariRenderParam(anari::Device device);
~HdAnariRenderParam() override;
anari::Device GetANARIDevice() const;
anari::Material GetDefaultMaterial() const;
const HdAnariMaterial::PrimvarBinding &GetDefaultPrimvarBinding() const;
MaterialType GetMaterialType() const
{
return _materialType;
}
void RegisterGeometry(const HdAnariGeometry *geometry);
void UnregisterGeometry(const HdAnariGeometry *geometry);
const GeometryList &Geometries() const;
int SceneVersion() const;
void MarkNewSceneVersion();
private:
anari::Device _device{nullptr};
anari::Material _material{nullptr};
MaterialType _materialType{MaterialType::Matte};
HdAnariMaterial::PrimvarBinding _primvarBinding;
std::mutex _mutex;
GeometryList _geometries;
std::atomic<int> _sceneVersion{0};
};
// Inlined definitions ////////////////////////////////////////////////////////
inline HdAnariRenderParam::HdAnariRenderParam(anari::Device d) : _device(d)
{
if (!d)
return;
anari::Extensions extensions =
anari::extension::getInstanceExtensionStruct(d, d);
if (extensions.ANARI_KHR_MATERIAL_PHYSICALLY_BASED) {
_materialType = MaterialType::PhysicallyBased;
_material = anari::newObject<anari::Material>(d, "physicallyBased");
anari::setParameter(d, _material, "alphaMode", "opaque");
anari::setParameter(d, _material, "baseColor", "color");
anari::commitParameters(d, _material);
_primvarBinding.emplace(HdTokens->displayColor, "color");
} else {
_materialType = MaterialType::Matte;
_material = anari::newObject<anari::Material>(d, "matte");
anari::setParameter(d, _material, "alphaMode", "opaque");
anari::setParameter(d, _material, "color", "color");
anari::commitParameters(d, _material);
_primvarBinding.emplace(HdTokens->displayColor, "color");
}
}
inline HdAnariRenderParam::~HdAnariRenderParam()
{
if (!_device)
return;
anari::release(_device, _material);
anari::release(_device, _device);
_device = nullptr;
}
inline anari::Device HdAnariRenderParam::GetANARIDevice() const
{
assert(_device != nullptr);
return _device;
}
inline anari::Material HdAnariRenderParam::GetDefaultMaterial() const
{
return _material;
}
inline const HdAnariMaterial::PrimvarBinding &
HdAnariRenderParam::GetDefaultPrimvarBinding() const
{
return _primvarBinding;
}
inline void HdAnariRenderParam::RegisterGeometry(
const HdAnariGeometry *geometry)
{
std::lock_guard<std::mutex> guard(_mutex);
_geometries.push_back(geometry);
}
inline void HdAnariRenderParam::UnregisterGeometry(
const HdAnariGeometry *geometry)
{
std::lock_guard<std::mutex> guard(_mutex);
_geometries.erase(
std::remove(_geometries.begin(), _geometries.end(), geometry),
_geometries.end());
}
inline const GeometryList &HdAnariRenderParam::Geometries() const
{
return _geometries;
}
inline int HdAnariRenderParam::SceneVersion() const
{
return _sceneVersion.load();
}
inline void HdAnariRenderParam::MarkNewSceneVersion()
{
_sceneVersion++;
}
PXR_NAMESPACE_CLOSE_SCOPE