1// ======================================================================== //
2// Copyright 2009-2019 Intel Corporation //
3// //
4// Licensed under the Apache License, Version 2.0 (the "License"); //
5// you may not use this file except in compliance with the License. //
6// You may obtain a copy of the License at //
7// //
8// http://www.apache.org/licenses/LICENSE-2.0 //
9// //
10// Unless required by applicable law or agreed to in writing, software //
11// distributed under the License is distributed on an "AS IS" BASIS, //
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13// See the License for the specific language governing permissions and //
14// limitations under the License. //
15// ======================================================================== //
16
17#pragma once
18
19#include "common.h"
20
21namespace oidn {
22
23 class Buffer;
24 class Filter;
25
26 class Device : public RefCount, public Verbose
27 {
28 private:
29 // Thread-safety
30 std::mutex mutex;
31
32 // Error handling
33 struct ErrorState
34 {
35 Error code = Error::None;
36 std::string message;
37 };
38
39 static thread_local ErrorState globalError;
40 ThreadLocal<ErrorState> error;
41 ErrorFunction errorFunc = nullptr;
42 void* errorUserPtr = nullptr;
43
44// -- GODOT start --
45// // Tasking
46// std::shared_ptr<tbb::task_arena> arena;
47// std::shared_ptr<PinningObserver> observer;
48// std::shared_ptr<ThreadAffinity> affinity;
49// -- GODOT end --
50
51 // Parameters
52 int numThreads = 0; // autodetect by default
53 bool setAffinity = true;
54
55 bool dirty = true;
56
57 public:
58 Device();
59 ~Device();
60
61 static void setError(Device* device, Error code, const std::string& message);
62 static Error getError(Device* device, const char** outMessage);
63
64 void setErrorFunction(ErrorFunction func, void* userPtr);
65
66 int get1i(const std::string& name);
67 void set1i(const std::string& name, int value);
68
69 void commit();
70
71// -- GODOT start --
72// template<typename F>
73// void executeTask(F& f)
74// {
75// arena->execute(f);
76// }
77
78// template<typename F>
79// void executeTask(const F& f)
80// {
81// arena->execute(f);
82// }
83// -- GODOT end --
84
85 Ref<Buffer> newBuffer(size_t byteSize);
86 Ref<Buffer> newBuffer(void* ptr, size_t byteSize);
87 Ref<Filter> newFilter(const std::string& type);
88
89 __forceinline Device* getDevice() { return this; }
90 __forceinline std::mutex& getMutex() { return mutex; }
91
92 private:
93// -- GODOT start --
94 //bool isCommitted() const { return bool(arena); }
95 bool isCommitted() const { return false; }
96// -- GODOT end --
97 void checkCommitted();
98
99 void print();
100 };
101
102} // namespace oidn
103