mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-04 20:25:56 +00:00
Member rename: src/{common/utils/wire}
This commit is contained in:
parent
8d75e5b4ae
commit
ad6470466c
@ -29,65 +29,65 @@ DynamicLib::~DynamicLib() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DynamicLib::DynamicLib(DynamicLib&& other) {
|
DynamicLib::DynamicLib(DynamicLib&& other) {
|
||||||
std::swap(this->handle, other.handle);
|
std::swap(mHandle, other.mHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
DynamicLib& DynamicLib::operator=(DynamicLib&& other) {
|
DynamicLib& DynamicLib::operator=(DynamicLib&& other) {
|
||||||
std::swap(this->handle, other.handle);
|
std::swap(mHandle, other.mHandle);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DynamicLib::Valid() const {
|
bool DynamicLib::Valid() const {
|
||||||
return handle != nullptr;
|
return mHandle != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DynamicLib::Open(const std::string& filename, std::string* error) {
|
bool DynamicLib::Open(const std::string& filename, std::string* error) {
|
||||||
#if NXT_PLATFORM_WINDOWS
|
#if NXT_PLATFORM_WINDOWS
|
||||||
handle = LoadLibraryA(filename.c_str());
|
mHandle = LoadLibraryA(filename.c_str());
|
||||||
|
|
||||||
if (handle == nullptr && error != nullptr) {
|
if (mHandle == nullptr && error != nullptr) {
|
||||||
*error = "Windows Error: " + std::to_string(GetLastError());
|
*error = "Windows Error: " + std::to_string(GetLastError());
|
||||||
}
|
}
|
||||||
#elif NXT_PLATFORM_POSIX
|
#elif NXT_PLATFORM_POSIX
|
||||||
handle = dlopen(filename.c_str(), RTLD_NOW);
|
mHandle = dlopen(filename.c_str(), RTLD_NOW);
|
||||||
|
|
||||||
if (handle == nullptr && error != nullptr) {
|
if (mHandle == nullptr && error != nullptr) {
|
||||||
*error = dlerror();
|
*error = dlerror();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#error "Unsupported platform for DynamicLib"
|
#error "Unsupported platform for DynamicLib"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return handle != nullptr;
|
return mHandle != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DynamicLib::Close() {
|
void DynamicLib::Close() {
|
||||||
if (handle == nullptr) {
|
if (mHandle == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NXT_PLATFORM_WINDOWS
|
#if NXT_PLATFORM_WINDOWS
|
||||||
FreeLibrary(static_cast<HMODULE>(handle));
|
FreeLibrary(static_cast<HMODULE>(mHandle));
|
||||||
#elif NXT_PLATFORM_POSIX
|
#elif NXT_PLATFORM_POSIX
|
||||||
dlclose(handle);
|
dlclose(mHandle);
|
||||||
#else
|
#else
|
||||||
#error "Unsupported platform for DynamicLib"
|
#error "Unsupported platform for DynamicLib"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
handle = nullptr;
|
mHandle = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* DynamicLib::GetProc(const std::string& procName, std::string* error) const {
|
void* DynamicLib::GetProc(const std::string& procName, std::string* error) const {
|
||||||
void* proc = nullptr;
|
void* proc = nullptr;
|
||||||
|
|
||||||
#if NXT_PLATFORM_WINDOWS
|
#if NXT_PLATFORM_WINDOWS
|
||||||
proc = reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), procName.c_str()));
|
proc = reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(mHandle), procName.c_str()));
|
||||||
|
|
||||||
if (proc == nullptr && error != nullptr) {
|
if (proc == nullptr && error != nullptr) {
|
||||||
*error = "Windows Error: " + std::to_string(GetLastError());
|
*error = "Windows Error: " + std::to_string(GetLastError());
|
||||||
}
|
}
|
||||||
#elif NXT_PLATFORM_POSIX
|
#elif NXT_PLATFORM_POSIX
|
||||||
proc = reinterpret_cast<void*>(dlsym(handle, procName.c_str()));
|
proc = reinterpret_cast<void*>(dlsym(mHandle, procName.c_str()));
|
||||||
|
|
||||||
if (proc == nullptr && error != nullptr) {
|
if (proc == nullptr && error != nullptr) {
|
||||||
*error = dlerror();
|
*error = dlerror();
|
||||||
|
@ -48,7 +48,7 @@ class DynamicLib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void* handle = nullptr;
|
void* mHandle = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMMON_DYNAMICLIB_H_
|
#endif // COMMON_DYNAMICLIB_H_
|
||||||
|
@ -40,11 +40,11 @@ class SerialQueue {
|
|||||||
T& operator*() const;
|
T& operator*() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StorageIterator storageIterator;
|
StorageIterator mStorageIterator;
|
||||||
// Special case the serialIterator when it should be equal to storageIterator.begin()
|
// Special case the mSerialIterator when it should be equal to mStorageIterator.begin()
|
||||||
// otherwise we could ask storageIterator.begin() when storageIterator is storage.end()
|
// otherwise we could ask mStorageIterator.begin() when mStorageIterator is mStorage.end()
|
||||||
// which is invalid. storageIterator.begin() is tagged with a nullptr.
|
// which is invalid. mStorageIterator.begin() is tagged with a nullptr.
|
||||||
T* serialIterator;
|
T* mSerialIterator;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConstIterator {
|
class ConstIterator {
|
||||||
@ -57,8 +57,8 @@ class SerialQueue {
|
|||||||
const T& operator*() const;
|
const T& operator*() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConstStorageIterator storageIterator;
|
ConstStorageIterator mStorageIterator;
|
||||||
const T* serialIterator;
|
const T* mSerialIterator;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BeginEnd {
|
class BeginEnd {
|
||||||
@ -69,8 +69,8 @@ class SerialQueue {
|
|||||||
Iterator end() const;
|
Iterator end() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
StorageIterator startIt;
|
StorageIterator mStartIt;
|
||||||
StorageIterator endIt;
|
StorageIterator mEndIt;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConstBeginEnd {
|
class ConstBeginEnd {
|
||||||
@ -81,8 +81,8 @@ class SerialQueue {
|
|||||||
ConstIterator end() const;
|
ConstIterator end() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConstStorageIterator startIt;
|
ConstStorageIterator mStartIt;
|
||||||
ConstStorageIterator endIt;
|
ConstStorageIterator mEndIt;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The serial must be given in (not strictly) increasing order.
|
// The serial must be given in (not strictly) increasing order.
|
||||||
@ -110,90 +110,90 @@ class SerialQueue {
|
|||||||
// Returns the first StorageIterator that a serial bigger than serial.
|
// Returns the first StorageIterator that a serial bigger than serial.
|
||||||
ConstStorageIterator FindUpTo(Serial serial) const;
|
ConstStorageIterator FindUpTo(Serial serial) const;
|
||||||
StorageIterator FindUpTo(Serial serial);
|
StorageIterator FindUpTo(Serial serial);
|
||||||
Storage storage;
|
Storage mStorage;
|
||||||
};
|
};
|
||||||
|
|
||||||
// SerialQueue
|
// SerialQueue
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialQueue<T>::Enqueue(const T& value, Serial serial) {
|
void SerialQueue<T>::Enqueue(const T& value, Serial serial) {
|
||||||
NXT_ASSERT(Empty() || storage.back().first <= serial);
|
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||||
|
|
||||||
if (Empty() || storage.back().first < serial) {
|
if (Empty() || mStorage.back().first < serial) {
|
||||||
storage.emplace_back(SerialPair(serial, {}));
|
mStorage.emplace_back(SerialPair(serial, {}));
|
||||||
}
|
}
|
||||||
storage.back().second.emplace_back(value);
|
mStorage.back().second.emplace_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialQueue<T>::Enqueue(T&& value, Serial serial) {
|
void SerialQueue<T>::Enqueue(T&& value, Serial serial) {
|
||||||
NXT_ASSERT(Empty() || storage.back().first <= serial);
|
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||||
|
|
||||||
if (Empty() || storage.back().first < serial) {
|
if (Empty() || mStorage.back().first < serial) {
|
||||||
storage.emplace_back(SerialPair(serial, {}));
|
mStorage.emplace_back(SerialPair(serial, {}));
|
||||||
}
|
}
|
||||||
storage.back().second.emplace_back(value);
|
mStorage.back().second.emplace_back(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialQueue<T>::Enqueue(const std::vector<T>& values, Serial serial) {
|
void SerialQueue<T>::Enqueue(const std::vector<T>& values, Serial serial) {
|
||||||
NXT_ASSERT(values.size() > 0);
|
NXT_ASSERT(values.size() > 0);
|
||||||
NXT_ASSERT(Empty() || storage.back().first <= serial);
|
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||||
storage.emplace_back(SerialPair(serial, {values}));
|
mStorage.emplace_back(SerialPair(serial, {values}));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialQueue<T>::Enqueue(std::vector<T>&& values, Serial serial) {
|
void SerialQueue<T>::Enqueue(std::vector<T>&& values, Serial serial) {
|
||||||
NXT_ASSERT(values.size() > 0);
|
NXT_ASSERT(values.size() > 0);
|
||||||
NXT_ASSERT(Empty() || storage.back().first <= serial);
|
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
|
||||||
storage.emplace_back(SerialPair(serial, {values}));
|
mStorage.emplace_back(SerialPair(serial, {values}));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool SerialQueue<T>::Empty() const {
|
bool SerialQueue<T>::Empty() const {
|
||||||
return storage.empty();
|
return mStorage.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::ConstBeginEnd SerialQueue<T>::IterateAll() const {
|
typename SerialQueue<T>::ConstBeginEnd SerialQueue<T>::IterateAll() const {
|
||||||
return {storage.begin(), storage.end()};
|
return {mStorage.begin(), mStorage.end()};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::ConstBeginEnd SerialQueue<T>::IterateUpTo(Serial serial) const {
|
typename SerialQueue<T>::ConstBeginEnd SerialQueue<T>::IterateUpTo(Serial serial) const {
|
||||||
return {storage.begin(), FindUpTo(serial)};
|
return {mStorage.begin(), FindUpTo(serial)};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::BeginEnd SerialQueue<T>::IterateAll() {
|
typename SerialQueue<T>::BeginEnd SerialQueue<T>::IterateAll() {
|
||||||
return {storage.begin(), storage.end()};
|
return {mStorage.begin(), mStorage.end()};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::BeginEnd SerialQueue<T>::IterateUpTo(Serial serial) {
|
typename SerialQueue<T>::BeginEnd SerialQueue<T>::IterateUpTo(Serial serial) {
|
||||||
return {storage.begin(), FindUpTo(serial)};
|
return {mStorage.begin(), FindUpTo(serial)};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialQueue<T>::Clear() {
|
void SerialQueue<T>::Clear() {
|
||||||
storage.clear();
|
mStorage.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void SerialQueue<T>::ClearUpTo(Serial serial) {
|
void SerialQueue<T>::ClearUpTo(Serial serial) {
|
||||||
storage.erase(storage.begin(), FindUpTo(serial));
|
mStorage.erase(mStorage.begin(), FindUpTo(serial));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Serial SerialQueue<T>::FirstSerial() const {
|
Serial SerialQueue<T>::FirstSerial() const {
|
||||||
NXT_ASSERT(!Empty());
|
NXT_ASSERT(!Empty());
|
||||||
return storage.front().first;
|
return mStorage.front().first;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::ConstStorageIterator SerialQueue<T>::FindUpTo(Serial serial) const {
|
typename SerialQueue<T>::ConstStorageIterator SerialQueue<T>::FindUpTo(Serial serial) const {
|
||||||
auto it = storage.begin();
|
auto it = mStorage.begin();
|
||||||
while (it != storage.end() && it->first <= serial) {
|
while (it != mStorage.end() && it->first <= serial) {
|
||||||
it ++;
|
it ++;
|
||||||
}
|
}
|
||||||
return it;
|
return it;
|
||||||
@ -201,8 +201,8 @@ typename SerialQueue<T>::ConstStorageIterator SerialQueue<T>::FindUpTo(Serial se
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::StorageIterator SerialQueue<T>::FindUpTo(Serial serial) {
|
typename SerialQueue<T>::StorageIterator SerialQueue<T>::FindUpTo(Serial serial) {
|
||||||
auto it = storage.begin();
|
auto it = mStorage.begin();
|
||||||
while (it != storage.end() && it->first <= serial) {
|
while (it != mStorage.end() && it->first <= serial) {
|
||||||
it ++;
|
it ++;
|
||||||
}
|
}
|
||||||
return it;
|
return it;
|
||||||
@ -212,39 +212,39 @@ typename SerialQueue<T>::StorageIterator SerialQueue<T>::FindUpTo(Serial serial)
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SerialQueue<T>::BeginEnd::BeginEnd(typename SerialQueue<T>::StorageIterator start, typename SerialQueue<T>::StorageIterator end)
|
SerialQueue<T>::BeginEnd::BeginEnd(typename SerialQueue<T>::StorageIterator start, typename SerialQueue<T>::StorageIterator end)
|
||||||
: startIt(start), endIt(end) {
|
: mStartIt(start), mEndIt(end) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::Iterator SerialQueue<T>::BeginEnd::begin() const {
|
typename SerialQueue<T>::Iterator SerialQueue<T>::BeginEnd::begin() const {
|
||||||
return {startIt};
|
return {mStartIt};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::Iterator SerialQueue<T>::BeginEnd::end() const {
|
typename SerialQueue<T>::Iterator SerialQueue<T>::BeginEnd::end() const {
|
||||||
return {endIt};
|
return {mEndIt};
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerialQueue::Iterator
|
// SerialQueue::Iterator
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SerialQueue<T>::Iterator::Iterator(typename SerialQueue<T>::StorageIterator start)
|
SerialQueue<T>::Iterator::Iterator(typename SerialQueue<T>::StorageIterator start)
|
||||||
: storageIterator(start), serialIterator(nullptr) {
|
: mStorageIterator(start), mSerialIterator(nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::Iterator& SerialQueue<T>::Iterator::operator++() {
|
typename SerialQueue<T>::Iterator& SerialQueue<T>::Iterator::operator++() {
|
||||||
T* vectorData = storageIterator->second.data();
|
T* vectorData = mStorageIterator->second.data();
|
||||||
|
|
||||||
if (serialIterator == nullptr) {
|
if (mSerialIterator == nullptr) {
|
||||||
serialIterator = vectorData + 1;
|
mSerialIterator = vectorData + 1;
|
||||||
} else {
|
} else {
|
||||||
serialIterator ++;
|
mSerialIterator ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serialIterator >= vectorData + storageIterator->second.size()) {
|
if (mSerialIterator >= vectorData + mStorageIterator->second.size()) {
|
||||||
serialIterator = nullptr;
|
mSerialIterator = nullptr;
|
||||||
storageIterator ++;
|
mStorageIterator ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -252,7 +252,7 @@ typename SerialQueue<T>::Iterator& SerialQueue<T>::Iterator::operator++() {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool SerialQueue<T>::Iterator::operator==(const typename SerialQueue<T>::Iterator& other) const {
|
bool SerialQueue<T>::Iterator::operator==(const typename SerialQueue<T>::Iterator& other) const {
|
||||||
return other.storageIterator == storageIterator && other.serialIterator == serialIterator;
|
return other.mStorageIterator == mStorageIterator && other.mSerialIterator == mSerialIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -262,49 +262,49 @@ bool SerialQueue<T>::Iterator::operator!=(const typename SerialQueue<T>::Iterato
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T& SerialQueue<T>::Iterator::operator*() const {
|
T& SerialQueue<T>::Iterator::operator*() const {
|
||||||
if (serialIterator == nullptr) {
|
if (mSerialIterator == nullptr) {
|
||||||
return *storageIterator->second.begin();
|
return *mStorageIterator->second.begin();
|
||||||
}
|
}
|
||||||
return *serialIterator;
|
return *mSerialIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerialQueue::ConstBeginEnd
|
// SerialQueue::ConstBeginEnd
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SerialQueue<T>::ConstBeginEnd::ConstBeginEnd(typename SerialQueue<T>::ConstStorageIterator start, typename SerialQueue<T>::ConstStorageIterator end)
|
SerialQueue<T>::ConstBeginEnd::ConstBeginEnd(typename SerialQueue<T>::ConstStorageIterator start, typename SerialQueue<T>::ConstStorageIterator end)
|
||||||
: startIt(start), endIt(end) {
|
: mStartIt(start), mEndIt(end) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::ConstIterator SerialQueue<T>::ConstBeginEnd::begin() const {
|
typename SerialQueue<T>::ConstIterator SerialQueue<T>::ConstBeginEnd::begin() const {
|
||||||
return {startIt};
|
return {mStartIt};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::ConstIterator SerialQueue<T>::ConstBeginEnd::end() const {
|
typename SerialQueue<T>::ConstIterator SerialQueue<T>::ConstBeginEnd::end() const {
|
||||||
return {endIt};
|
return {mEndIt};
|
||||||
}
|
}
|
||||||
|
|
||||||
// SerialQueue::ConstIterator
|
// SerialQueue::ConstIterator
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SerialQueue<T>::ConstIterator::ConstIterator(typename SerialQueue<T>::ConstStorageIterator start)
|
SerialQueue<T>::ConstIterator::ConstIterator(typename SerialQueue<T>::ConstStorageIterator start)
|
||||||
: storageIterator(start), serialIterator(nullptr) {
|
: mStorageIterator(start), mSerialIterator(nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
typename SerialQueue<T>::ConstIterator& SerialQueue<T>::ConstIterator::operator++() {
|
typename SerialQueue<T>::ConstIterator& SerialQueue<T>::ConstIterator::operator++() {
|
||||||
const T* vectorData = storageIterator->second.data();
|
const T* vectorData = mStorageIterator->second.data();
|
||||||
|
|
||||||
if (serialIterator == nullptr) {
|
if (mSerialIterator == nullptr) {
|
||||||
serialIterator = vectorData + 1;
|
mSerialIterator = vectorData + 1;
|
||||||
} else {
|
} else {
|
||||||
serialIterator ++;
|
mSerialIterator ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serialIterator >= vectorData + storageIterator->second.size()) {
|
if (mSerialIterator >= vectorData + mStorageIterator->second.size()) {
|
||||||
serialIterator = nullptr;
|
mSerialIterator = nullptr;
|
||||||
storageIterator ++;
|
mStorageIterator ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -312,7 +312,7 @@ typename SerialQueue<T>::ConstIterator& SerialQueue<T>::ConstIterator::operator+
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool SerialQueue<T>::ConstIterator::operator==(const typename SerialQueue<T>::ConstIterator& other) const {
|
bool SerialQueue<T>::ConstIterator::operator==(const typename SerialQueue<T>::ConstIterator& other) const {
|
||||||
return other.storageIterator == storageIterator && other.serialIterator == serialIterator;
|
return other.mStorageIterator == mStorageIterator && other.mSerialIterator == mSerialIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -322,10 +322,10 @@ bool SerialQueue<T>::ConstIterator::operator!=(const typename SerialQueue<T>::Co
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const T& SerialQueue<T>::ConstIterator::operator*() const {
|
const T& SerialQueue<T>::ConstIterator::operator*() const {
|
||||||
if (serialIterator == nullptr) {
|
if (mSerialIterator == nullptr) {
|
||||||
return *storageIterator->second.begin();
|
return *mStorageIterator->second.begin();
|
||||||
}
|
}
|
||||||
return *serialIterator;
|
return *mSerialIterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // COMMON_SERIALQUEUE_H_
|
#endif // COMMON_SERIALQUEUE_H_
|
||||||
|
@ -35,7 +35,7 @@ namespace utils {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void BackendBinding::SetWindow(GLFWwindow* window) {
|
void BackendBinding::SetWindow(GLFWwindow* window) {
|
||||||
this->window = window;
|
mWindow = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackendBinding* CreateBinding(BackendType type) {
|
BackendBinding* CreateBinding(BackendType type) {
|
||||||
|
@ -43,7 +43,7 @@ namespace utils {
|
|||||||
void SetWindow(GLFWwindow* window);
|
void SetWindow(GLFWwindow* window);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
GLFWwindow* window = nullptr;
|
GLFWwindow* mWindow = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
BackendBinding* CreateBinding(BackendType type);
|
BackendBinding* CreateBinding(BackendType type);
|
||||||
|
@ -123,26 +123,26 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nxtDevice backendDevice = nullptr;
|
nxtDevice mBackendDevice = nullptr;
|
||||||
nxtProcTable procs = {};
|
nxtProcTable mProcs = {};
|
||||||
|
|
||||||
static constexpr unsigned int kFrameCount = 2;
|
static constexpr unsigned int kFrameCount = 2;
|
||||||
|
|
||||||
HWND window = 0;
|
HWND mWindow = 0;
|
||||||
ComPtr<IDXGIFactory4> factory = {};
|
ComPtr<IDXGIFactory4> mFactory = {};
|
||||||
ComPtr<ID3D12CommandQueue> commandQueue = {};
|
ComPtr<ID3D12CommandQueue> mCommandQueue = {};
|
||||||
ComPtr<IDXGISwapChain3> swapChain = {};
|
ComPtr<IDXGISwapChain3> mSwapChain = {};
|
||||||
ComPtr<ID3D12Resource> renderTargetResources[kFrameCount] = {};
|
ComPtr<ID3D12Resource> mRenderTargetResources[kFrameCount] = {};
|
||||||
|
|
||||||
// Frame synchronization. Updated every frame
|
// Frame synchronization. Updated every frame
|
||||||
uint32_t renderTargetIndex = 0;
|
uint32_t mRenderTargetIndex = 0;
|
||||||
uint32_t previousRenderTargetIndex = 0;
|
uint32_t mPreviousRenderTargetIndex = 0;
|
||||||
uint64_t lastSerialRenderTargetWasUsed[kFrameCount] = {};
|
uint64_t mLastSerialRenderTargetWasUsed[kFrameCount] = {};
|
||||||
|
|
||||||
D3D12_RESOURCE_STATES renderTargetResourceState;
|
D3D12_RESOURCE_STATES mRenderTargetResourceState;
|
||||||
|
|
||||||
SwapChainImplD3D12(HWND window, nxtProcTable procs)
|
SwapChainImplD3D12(HWND window, nxtProcTable procs)
|
||||||
: window(window), procs(procs), factory(CreateFactory()) {
|
: mWindow(window), mProcs(procs), mFactory(CreateFactory()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
~SwapChainImplD3D12() {
|
~SwapChainImplD3D12() {
|
||||||
@ -152,8 +152,8 @@ namespace utils {
|
|||||||
friend class SwapChainImpl;
|
friend class SwapChainImpl;
|
||||||
|
|
||||||
void Init(nxtWSIContextD3D12* ctx) {
|
void Init(nxtWSIContextD3D12* ctx) {
|
||||||
backendDevice = ctx->device;
|
mBackendDevice = ctx->device;
|
||||||
commandQueue = backend::d3d12::GetCommandQueue(backendDevice);
|
mCommandQueue = backend::d3d12::GetCommandQueue(mBackendDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit allowedUsage,
|
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit allowedUsage,
|
||||||
@ -175,73 +175,73 @@ namespace utils {
|
|||||||
swapChainDesc.SampleDesc.Quality = 0;
|
swapChainDesc.SampleDesc.Quality = 0;
|
||||||
|
|
||||||
ComPtr<IDXGISwapChain1> swapChain1;
|
ComPtr<IDXGISwapChain1> swapChain1;
|
||||||
ASSERT_SUCCESS(factory->CreateSwapChainForHwnd(
|
ASSERT_SUCCESS(mFactory->CreateSwapChainForHwnd(
|
||||||
commandQueue.Get(),
|
mCommandQueue.Get(),
|
||||||
window,
|
mWindow,
|
||||||
&swapChainDesc,
|
&swapChainDesc,
|
||||||
nullptr,
|
nullptr,
|
||||||
nullptr,
|
nullptr,
|
||||||
&swapChain1
|
&swapChain1
|
||||||
));
|
));
|
||||||
ASSERT_SUCCESS(swapChain1.As(&swapChain));
|
ASSERT_SUCCESS(swapChain1.As(&mSwapChain));
|
||||||
|
|
||||||
for (uint32_t n = 0; n < kFrameCount; ++n) {
|
for (uint32_t n = 0; n < kFrameCount; ++n) {
|
||||||
ASSERT_SUCCESS(swapChain->GetBuffer(n, IID_PPV_ARGS(&renderTargetResources[n])));
|
ASSERT_SUCCESS(mSwapChain->GetBuffer(n, IID_PPV_ARGS(&mRenderTargetResources[n])));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the initial render target and arbitrarily choose a "previous" render target that's different
|
// Get the initial render target and arbitrarily choose a "previous" render target that's different
|
||||||
previousRenderTargetIndex = renderTargetIndex = swapChain->GetCurrentBackBufferIndex();
|
mPreviousRenderTargetIndex = mRenderTargetIndex = mSwapChain->GetCurrentBackBufferIndex();
|
||||||
previousRenderTargetIndex = renderTargetIndex == 0 ? 1 : 0;
|
mPreviousRenderTargetIndex = mRenderTargetIndex == 0 ? 1 : 0;
|
||||||
|
|
||||||
// Initial the serial for all render targets
|
// Initial the serial for all render targets
|
||||||
const uint64_t initialSerial = backend::d3d12::GetSerial(backendDevice);
|
const uint64_t initialSerial = backend::d3d12::GetSerial(mBackendDevice);
|
||||||
for (uint32_t n = 0; n < kFrameCount; ++n) {
|
for (uint32_t n = 0; n < kFrameCount; ++n) {
|
||||||
lastSerialRenderTargetWasUsed[n] = initialSerial;
|
mLastSerialRenderTargetWasUsed[n] = initialSerial;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
|
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
|
||||||
nextTexture->texture = renderTargetResources[renderTargetIndex].Get();
|
nextTexture->texture = mRenderTargetResources[mRenderTargetIndex].Get();
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError Present() {
|
nxtSwapChainError Present() {
|
||||||
// Current frame already transitioned to Present by the application, but
|
// Current frame already transitioned to Present by the application, but
|
||||||
// we need to flush the D3D12 backend's pending transitions.
|
// we need to flush the D3D12 backend's pending transitions.
|
||||||
procs.deviceTick(backendDevice);
|
mProcs.deviceTick(mBackendDevice);
|
||||||
|
|
||||||
ASSERT_SUCCESS(swapChain->Present(1, 0));
|
ASSERT_SUCCESS(mSwapChain->Present(1, 0));
|
||||||
|
|
||||||
// Transition last frame's render target back to being a render target
|
// Transition last frame's render target back to being a render target
|
||||||
if (renderTargetResourceState != D3D12_RESOURCE_STATE_PRESENT) {
|
if (mRenderTargetResourceState != D3D12_RESOURCE_STATE_PRESENT) {
|
||||||
ComPtr<ID3D12GraphicsCommandList> commandList = {};
|
ComPtr<ID3D12GraphicsCommandList> commandList = {};
|
||||||
backend::d3d12::OpenCommandList(backendDevice, &commandList);
|
backend::d3d12::OpenCommandList(mBackendDevice, &commandList);
|
||||||
|
|
||||||
D3D12_RESOURCE_BARRIER resourceBarrier;
|
D3D12_RESOURCE_BARRIER resourceBarrier;
|
||||||
resourceBarrier.Transition.pResource = renderTargetResources[previousRenderTargetIndex].Get();
|
resourceBarrier.Transition.pResource = mRenderTargetResources[mPreviousRenderTargetIndex].Get();
|
||||||
resourceBarrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
resourceBarrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
|
||||||
resourceBarrier.Transition.StateAfter = renderTargetResourceState;
|
resourceBarrier.Transition.StateAfter = mRenderTargetResourceState;
|
||||||
resourceBarrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
resourceBarrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
|
||||||
resourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
resourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
|
||||||
resourceBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
resourceBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
|
||||||
commandList->ResourceBarrier(1, &resourceBarrier);
|
commandList->ResourceBarrier(1, &resourceBarrier);
|
||||||
ASSERT_SUCCESS(commandList->Close());
|
ASSERT_SUCCESS(commandList->Close());
|
||||||
backend::d3d12::ExecuteCommandLists(backendDevice, { commandList.Get() });
|
backend::d3d12::ExecuteCommandLists(mBackendDevice, { commandList.Get() });
|
||||||
}
|
}
|
||||||
|
|
||||||
backend::d3d12::NextSerial(backendDevice);
|
backend::d3d12::NextSerial(mBackendDevice);
|
||||||
|
|
||||||
previousRenderTargetIndex = renderTargetIndex;
|
mPreviousRenderTargetIndex = mRenderTargetIndex;
|
||||||
renderTargetIndex = swapChain->GetCurrentBackBufferIndex();
|
mRenderTargetIndex = mSwapChain->GetCurrentBackBufferIndex();
|
||||||
|
|
||||||
// If the next render target is not ready to be rendered yet, wait until it is ready.
|
// If the next render target is not ready to be rendered yet, wait until it is ready.
|
||||||
// If the last completed serial is less than the last requested serial for this render target,
|
// If the last completed serial is less than the last requested serial for this render target,
|
||||||
// then the commands previously executed on this render target have not yet completed
|
// then the commands previously executed on this render target have not yet completed
|
||||||
backend::d3d12::WaitForSerial(backendDevice, lastSerialRenderTargetWasUsed[renderTargetIndex]);
|
backend::d3d12::WaitForSerial(mBackendDevice, mLastSerialRenderTargetWasUsed[mRenderTargetIndex]);
|
||||||
|
|
||||||
lastSerialRenderTargetWasUsed[renderTargetIndex] = backend::d3d12::GetSerial(backendDevice);
|
mLastSerialRenderTargetWasUsed[mRenderTargetIndex] = backend::d3d12::GetSerial(mBackendDevice);
|
||||||
|
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
}
|
}
|
||||||
@ -254,25 +254,25 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
|
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
|
||||||
factory = CreateFactory();
|
mFactory = CreateFactory();
|
||||||
ASSERT(GetHardwareAdapter(factory.Get(), &hardwareAdapter));
|
ASSERT(GetHardwareAdapter(mFactory.Get(), &mHardwareAdapter));
|
||||||
ASSERT_SUCCESS(D3D12CreateDevice(
|
ASSERT_SUCCESS(D3D12CreateDevice(
|
||||||
hardwareAdapter.Get(),
|
mHardwareAdapter.Get(),
|
||||||
D3D_FEATURE_LEVEL_11_0,
|
D3D_FEATURE_LEVEL_11_0,
|
||||||
IID_PPV_ARGS(&d3d12Device)
|
IID_PPV_ARGS(&mD3d12Device)
|
||||||
));
|
));
|
||||||
|
|
||||||
backend::d3d12::Init(d3d12Device, procs, device);
|
backend::d3d12::Init(mD3d12Device, procs, device);
|
||||||
backendDevice = *device;
|
mBackendDevice = *device;
|
||||||
procTable = *procs;
|
mProcTable = *procs;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GetSwapChainImplementation() override {
|
uint64_t GetSwapChainImplementation() override {
|
||||||
if (swapchainImpl.userData == nullptr) {
|
if (mSwapchainImpl.userData == nullptr) {
|
||||||
HWND win32Window = glfwGetWin32Window(window);
|
HWND win32Window = glfwGetWin32Window(mWindow);
|
||||||
swapchainImpl = SwapChainImplD3D12::Create(win32Window, procTable);
|
mSwapchainImpl = SwapChainImplD3D12::Create(win32Window, mProcTable);
|
||||||
}
|
}
|
||||||
return reinterpret_cast<uint64_t>(&swapchainImpl);
|
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||||
@ -280,14 +280,14 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nxtDevice backendDevice = nullptr;
|
nxtDevice mBackendDevice = nullptr;
|
||||||
nxtSwapChainImplementation swapchainImpl = {};
|
nxtSwapChainImplementation mSwapchainImpl = {};
|
||||||
nxtProcTable procTable = {};
|
nxtProcTable mProcTable = {};
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
ComPtr<IDXGIFactory4> factory;
|
ComPtr<IDXGIFactory4> mFactory;
|
||||||
ComPtr<IDXGIAdapter1> hardwareAdapter;
|
ComPtr<IDXGIAdapter1> mHardwareAdapter;
|
||||||
ComPtr<ID3D12Device> d3d12Device;
|
ComPtr<ID3D12Device> mD3d12Device;
|
||||||
|
|
||||||
static bool GetHardwareAdapter(IDXGIFactory4* factory, IDXGIAdapter1** hardwareAdapter) {
|
static bool GetHardwareAdapter(IDXGIFactory4* factory, IDXGIAdapter1** hardwareAdapter) {
|
||||||
*hardwareAdapter = nullptr;
|
*hardwareAdapter = nullptr;
|
||||||
|
@ -43,29 +43,29 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
id nsWindow = nil;
|
id mNsWindow = nil;
|
||||||
id<MTLDevice> mtlDevice = nil;
|
id<MTLDevice> mMtlDevice = nil;
|
||||||
id<MTLCommandQueue> commandQueue = nil;
|
id<MTLCommandQueue> mCommandQueue = nil;
|
||||||
|
|
||||||
CAMetalLayer* layer = nullptr;
|
CAMetalLayer* mLayer = nullptr;
|
||||||
id<CAMetalDrawable> currentDrawable = nil;
|
id<CAMetalDrawable> mCurrentDrawable = nil;
|
||||||
id<MTLTexture> currentTexture = nil;
|
id<MTLTexture> mCurrentTexture = nil;
|
||||||
|
|
||||||
SwapChainImplMTL(id nsWindow)
|
SwapChainImplMTL(id nsWindow)
|
||||||
: nsWindow(nsWindow) {
|
: mNsWindow(nsWindow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
~SwapChainImplMTL() {
|
~SwapChainImplMTL() {
|
||||||
[currentTexture release];
|
[mCurrentTexture release];
|
||||||
[currentDrawable release];
|
[mCurrentDrawable release];
|
||||||
}
|
}
|
||||||
|
|
||||||
// For GenerateSwapChainImplementation
|
// For GenerateSwapChainImplementation
|
||||||
friend class SwapChainImpl;
|
friend class SwapChainImpl;
|
||||||
|
|
||||||
void Init(nxtWSIContextMetal* ctx) {
|
void Init(nxtWSIContextMetal* ctx) {
|
||||||
mtlDevice = ctx->device;
|
mMtlDevice = ctx->device;
|
||||||
commandQueue = [mtlDevice newCommandQueue];
|
mCommandQueue = [mMtlDevice newCommandQueue];
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit,
|
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit,
|
||||||
@ -76,41 +76,41 @@ namespace utils {
|
|||||||
ASSERT(width > 0);
|
ASSERT(width > 0);
|
||||||
ASSERT(height > 0);
|
ASSERT(height > 0);
|
||||||
|
|
||||||
NSView* contentView = [nsWindow contentView];
|
NSView* contentView = [mNsWindow contentView];
|
||||||
[contentView setWantsLayer: YES];
|
[contentView setWantsLayer: YES];
|
||||||
|
|
||||||
CGSize size = {};
|
CGSize size = {};
|
||||||
size.width = width;
|
size.width = width;
|
||||||
size.height = height;
|
size.height = height;
|
||||||
|
|
||||||
layer = [CAMetalLayer layer];
|
mLayer = [CAMetalLayer layer];
|
||||||
[layer setDevice: mtlDevice];
|
[mLayer setDevice: mMtlDevice];
|
||||||
[layer setPixelFormat: MTLPixelFormatBGRA8Unorm];
|
[mLayer setPixelFormat: MTLPixelFormatBGRA8Unorm];
|
||||||
[layer setFramebufferOnly: YES];
|
[mLayer setFramebufferOnly: YES];
|
||||||
[layer setDrawableSize: size];
|
[mLayer setDrawableSize: size];
|
||||||
|
|
||||||
[contentView setLayer: layer];
|
[contentView setLayer: mLayer];
|
||||||
|
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
|
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
|
||||||
[currentDrawable release];
|
[mCurrentDrawable release];
|
||||||
currentDrawable = [layer nextDrawable];
|
mCurrentDrawable = [mLayer nextDrawable];
|
||||||
[currentDrawable retain];
|
[mCurrentDrawable retain];
|
||||||
|
|
||||||
[currentTexture release];
|
[mCurrentTexture release];
|
||||||
currentTexture = currentDrawable.texture;
|
mCurrentTexture = mCurrentDrawable.texture;
|
||||||
[currentTexture retain];
|
[mCurrentTexture retain];
|
||||||
|
|
||||||
nextTexture->texture = reinterpret_cast<void*>(currentTexture);
|
nextTexture->texture = reinterpret_cast<void*>(mCurrentTexture);
|
||||||
|
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError Present() {
|
nxtSwapChainError Present() {
|
||||||
id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
|
id<MTLCommandBuffer> commandBuffer = [mCommandQueue commandBuffer];
|
||||||
[commandBuffer presentDrawable: currentDrawable];
|
[commandBuffer presentDrawable: mCurrentDrawable];
|
||||||
[commandBuffer commit];
|
[commandBuffer commit];
|
||||||
|
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
@ -123,17 +123,17 @@ namespace utils {
|
|||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
}
|
}
|
||||||
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
|
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
|
||||||
metalDevice = MTLCreateSystemDefaultDevice();
|
mMetalDevice = MTLCreateSystemDefaultDevice();
|
||||||
|
|
||||||
backend::metal::Init(metalDevice, procs, device);
|
backend::metal::Init(mMetalDevice, procs, device);
|
||||||
backendDevice = *device;
|
mBackendDevice = *device;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GetSwapChainImplementation() override {
|
uint64_t GetSwapChainImplementation() override {
|
||||||
if (swapchainImpl.userData == nullptr) {
|
if (mSwapchainImpl.userData == nullptr) {
|
||||||
swapchainImpl = SwapChainImplMTL::Create(glfwGetCocoaWindow(window));
|
mSwapchainImpl = SwapChainImplMTL::Create(glfwGetCocoaWindow(mWindow));
|
||||||
}
|
}
|
||||||
return reinterpret_cast<uint64_t>(&swapchainImpl);
|
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||||
@ -141,9 +141,9 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
id<MTLDevice> metalDevice = nil;
|
id<MTLDevice> mMetalDevice = nil;
|
||||||
nxtDevice backendDevice = nullptr;
|
nxtDevice mBackendDevice = nullptr;
|
||||||
nxtSwapChainImplementation swapchainImpl = {};
|
nxtSwapChainImplementation mSwapchainImpl = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
BackendBinding* CreateMetalBinding() {
|
BackendBinding* CreateMetalBinding() {
|
||||||
|
@ -39,34 +39,34 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* window = nullptr;
|
GLFWwindow* mWindow = nullptr;
|
||||||
uint32_t cfgWidth = 0;
|
uint32_t mWidth = 0;
|
||||||
uint32_t cfgHeight = 0;
|
uint32_t mHeight = 0;
|
||||||
GLuint backFBO = 0;
|
GLuint mBackFBO = 0;
|
||||||
GLuint backTexture = 0;
|
GLuint mBackTexture = 0;
|
||||||
|
|
||||||
SwapChainImplGL(GLFWwindow* window)
|
SwapChainImplGL(GLFWwindow* window)
|
||||||
: window(window) {
|
: mWindow(window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
~SwapChainImplGL() {
|
~SwapChainImplGL() {
|
||||||
glDeleteTextures(1, &backTexture);
|
glDeleteTextures(1, &mBackTexture);
|
||||||
glDeleteFramebuffers(1, &backFBO);
|
glDeleteFramebuffers(1, &mBackFBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For GenerateSwapChainImplementation
|
// For GenerateSwapChainImplementation
|
||||||
friend class SwapChainImpl;
|
friend class SwapChainImpl;
|
||||||
|
|
||||||
void Init(nxtWSIContextGL*) {
|
void Init(nxtWSIContextGL*) {
|
||||||
glGenTextures(1, &backTexture);
|
glGenTextures(1, &mBackTexture);
|
||||||
glBindTexture(GL_TEXTURE_2D, backTexture);
|
glBindTexture(GL_TEXTURE_2D, mBackTexture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
|
|
||||||
glGenFramebuffers(1, &backFBO);
|
glGenFramebuffers(1, &mBackFBO);
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, backFBO);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
|
||||||
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||||
GL_TEXTURE_2D, backTexture, 0);
|
GL_TEXTURE_2D, mBackTexture, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit,
|
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit,
|
||||||
@ -76,10 +76,10 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
ASSERT(width > 0);
|
ASSERT(width > 0);
|
||||||
ASSERT(height > 0);
|
ASSERT(height > 0);
|
||||||
cfgWidth = width;
|
mWidth = width;
|
||||||
cfgHeight = height;
|
mHeight = height;
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, backTexture);
|
glBindTexture(GL_TEXTURE_2D, mBackTexture);
|
||||||
// Reallocate the texture
|
// Reallocate the texture
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||||
@ -88,16 +88,16 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
|
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
|
||||||
nextTexture->texture = reinterpret_cast<void*>(static_cast<size_t>(backTexture));
|
nextTexture->texture = reinterpret_cast<void*>(static_cast<size_t>(mBackTexture));
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtSwapChainError Present() {
|
nxtSwapChainError Present() {
|
||||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, backFBO);
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
|
||||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||||
glBlitFramebuffer(0, 0, cfgWidth, cfgHeight, 0, 0, cfgWidth, cfgHeight,
|
glBlitFramebuffer(0, 0, mWidth, mHeight, 0, 0, mWidth, mHeight,
|
||||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(mWindow);
|
||||||
|
|
||||||
return NXT_SWAP_CHAIN_NO_ERROR;
|
return NXT_SWAP_CHAIN_NO_ERROR;
|
||||||
}
|
}
|
||||||
@ -119,17 +119,17 @@ namespace utils {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
|
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(mWindow);
|
||||||
backend::opengl::Init(reinterpret_cast<void*(*)(const char*)>(glfwGetProcAddress), procs, device);
|
backend::opengl::Init(reinterpret_cast<void*(*)(const char*)>(glfwGetProcAddress), procs, device);
|
||||||
|
|
||||||
backendDevice = *device;
|
mBackendDevice = *device;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GetSwapChainImplementation() override {
|
uint64_t GetSwapChainImplementation() override {
|
||||||
if (swapchainImpl.userData == nullptr) {
|
if (mSwapchainImpl.userData == nullptr) {
|
||||||
swapchainImpl = SwapChainImplGL::Create(window);
|
mSwapchainImpl = SwapChainImplGL::Create(mWindow);
|
||||||
}
|
}
|
||||||
return reinterpret_cast<uint64_t>(&swapchainImpl);
|
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
|
||||||
}
|
}
|
||||||
|
|
||||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||||
@ -137,8 +137,8 @@ namespace utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nxtDevice backendDevice = nullptr;
|
nxtDevice mBackendDevice = nullptr;
|
||||||
nxtSwapChainImplementation swapchainImpl = {};
|
nxtSwapChainImplementation mSwapchainImpl = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
BackendBinding* CreateOpenGLBinding() {
|
BackendBinding* CreateOpenGLBinding() {
|
||||||
|
@ -70,17 +70,17 @@ namespace utils {
|
|||||||
backend::vulkan::Init(procs, device);
|
backend::vulkan::Init(procs, device);
|
||||||
}
|
}
|
||||||
uint64_t GetSwapChainImplementation() override {
|
uint64_t GetSwapChainImplementation() override {
|
||||||
if (swapchainImpl.userData == nullptr) {
|
if (mSwapchainImpl.userData == nullptr) {
|
||||||
swapchainImpl = SwapChainImplVulkan::Create(window);
|
mSwapchainImpl = SwapChainImplVulkan::Create(mWindow);
|
||||||
}
|
}
|
||||||
return reinterpret_cast<uint64_t>(&swapchainImpl);
|
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
|
||||||
}
|
}
|
||||||
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
|
||||||
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
|
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nxtSwapChainImplementation swapchainImpl = {};
|
nxtSwapChainImplementation mSwapchainImpl = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,22 +20,22 @@ namespace wire {
|
|||||||
TerribleCommandBuffer::TerribleCommandBuffer() {
|
TerribleCommandBuffer::TerribleCommandBuffer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TerribleCommandBuffer::TerribleCommandBuffer(CommandHandler* handler) : handler(handler) {
|
TerribleCommandBuffer::TerribleCommandBuffer(CommandHandler* handler) : mHandler(handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void TerribleCommandBuffer::SetHandler(CommandHandler* handler) {
|
void TerribleCommandBuffer::SetHandler(CommandHandler* handler) {
|
||||||
this->handler = handler;
|
mHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* TerribleCommandBuffer::GetCmdSpace(size_t size) {
|
void* TerribleCommandBuffer::GetCmdSpace(size_t size) {
|
||||||
if (size > sizeof(buffer)) {
|
if (size > sizeof(mBuffer)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* result = &buffer[offset];
|
uint8_t* result = &mBuffer[mOffset];
|
||||||
offset += size;
|
mOffset += size;
|
||||||
|
|
||||||
if (offset > sizeof(buffer)) {
|
if (mOffset > sizeof(mBuffer)) {
|
||||||
Flush();
|
Flush();
|
||||||
return GetCmdSpace(size);
|
return GetCmdSpace(size);
|
||||||
}
|
}
|
||||||
@ -44,8 +44,8 @@ namespace wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TerribleCommandBuffer::Flush() {
|
void TerribleCommandBuffer::Flush() {
|
||||||
handler->HandleCommands(buffer, offset);
|
mHandler->HandleCommands(mBuffer, mOffset);
|
||||||
offset = 0;
|
mOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ class TerribleCommandBuffer : public CommandSerializer {
|
|||||||
void Flush() override;
|
void Flush() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CommandHandler* handler = nullptr;
|
CommandHandler* mHandler = nullptr;
|
||||||
size_t offset = 0;
|
size_t mOffset = 0;
|
||||||
uint8_t buffer[10000000];
|
uint8_t mBuffer[10000000];
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user