-
Notifications
You must be signed in to change notification settings - Fork 59
/
render_param.cpp
executable file
·105 lines (95 loc) · 3.9 KB
/
render_param.cpp
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
// Copyright 2019 Luma Pictures
//
// 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
//
// 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.
//
// Modifications Copyright 2019 Autodesk, Inc.
//
// 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
//
// 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.
#include "render_param.h"
#include <ai.h>
PXR_NAMESPACE_OPEN_SCOPE
HdArnoldRenderParam::HdArnoldRenderParam() { _needsRestart.store(false, std::memory_order::memory_order_release); }
HdArnoldRenderParam::Status HdArnoldRenderParam::Render()
{
// Checking early if the render was aborted earlier.
if (_aborted) {
return Status::Aborted;
}
const auto status = AiRenderGetStatus();
if (status == AI_RENDER_STATUS_FINISHED) {
// If render restart is true, it means the Render Delegate received an update after rendering has finished
// and AiRenderInterrupt does not change the status anymore.
// For the atomic operations we are using a release-acquire model.
const auto needsRestart = _needsRestart.exchange(false, std::memory_order_acq_rel);
if (needsRestart) {
AiRenderRestart();
return Status::Converging;
}
return Status::Converged;
}
// Resetting the value.
_needsRestart.store(false, std::memory_order_release);
if (status == AI_RENDER_STATUS_PAUSED) {
AiRenderRestart();
return Status::Converging;
}
if (status == AI_RENDER_STATUS_RESTARTING) {
return Status::Converging;
}
if (status == AI_RENDER_STATUS_FAILED) {
_aborted = true;
const auto errorCode = AiRenderEnd();
if (errorCode == AI_ABORT) {
TF_WARN("[arnold-usd] Render was aborted.");
} else if (errorCode == AI_ERROR_NO_CAMERA) {
TF_WARN("[arnold-usd] Camera not defined.");
} else if (errorCode == AI_ERROR_BAD_CAMERA) {
TF_WARN("[arnold-usd] Bad camera data.");
} else if (errorCode == AI_ERROR_VALIDATION) {
TF_WARN("[arnold-usd] Usage not validated.");
} else if (errorCode == AI_ERROR_RENDER_REGION) {
TF_WARN("[arnold-usd] Invalid render region.");
} else if (errorCode == AI_INTERRUPT) {
TF_WARN("[arnold-usd] Render interrupted by user.");
} else if (errorCode == AI_ERROR_NO_OUTPUTS) {
TF_WARN("[arnold-usd] No rendering outpts.");
} else if (errorCode == AI_ERROR_UNAVAILABLE_DEVICE) {
TF_WARN("[arnold-usd] Cannot create gPU context.");
} else if (errorCode == AI_ERROR) {
TF_WARN("[arnold-usd] Generic error.");
}
return Status::Aborted;
}
AiRenderBegin();
return Status::Converging;
}
void HdArnoldRenderParam::Interrupt()
{
const auto status = AiRenderGetStatus();
if (status != AI_RENDER_STATUS_NOT_STARTED) {
AiRenderInterrupt(AI_BLOCKING);
_needsRestart.store(true, std::memory_order_release);
}
}
void HdArnoldRenderParam::ClearStatus() { _aborted = false; }
PXR_NAMESPACE_CLOSE_SCOPE