Member rename: src/{common/utils/wire}

This commit is contained in:
Corentin Wallez 2017-11-23 10:49:58 -08:00 committed by Corentin Wallez
parent 8d75e5b4ae
commit ad6470466c
11 changed files with 214 additions and 214 deletions

View File

@ -29,65 +29,65 @@ DynamicLib::~DynamicLib() {
}
DynamicLib::DynamicLib(DynamicLib&& other) {
std::swap(this->handle, other.handle);
std::swap(mHandle, other.mHandle);
}
DynamicLib& DynamicLib::operator=(DynamicLib&& other) {
std::swap(this->handle, other.handle);
std::swap(mHandle, other.mHandle);
return *this;
}
bool DynamicLib::Valid() const {
return handle != nullptr;
return mHandle != nullptr;
}
bool DynamicLib::Open(const std::string& filename, std::string* error) {
#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());
}
#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();
}
#else
#error "Unsupported platform for DynamicLib"
#endif
return handle != nullptr;
return mHandle != nullptr;
}
void DynamicLib::Close() {
if (handle == nullptr) {
if (mHandle == nullptr) {
return;
}
#if NXT_PLATFORM_WINDOWS
FreeLibrary(static_cast<HMODULE>(handle));
FreeLibrary(static_cast<HMODULE>(mHandle));
#elif NXT_PLATFORM_POSIX
dlclose(handle);
dlclose(mHandle);
#else
#error "Unsupported platform for DynamicLib"
#endif
handle = nullptr;
mHandle = nullptr;
}
void* DynamicLib::GetProc(const std::string& procName, std::string* error) const {
void* proc = nullptr;
#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) {
*error = "Windows Error: " + std::to_string(GetLastError());
}
#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) {
*error = dlerror();

View File

@ -48,7 +48,7 @@ class DynamicLib {
}
private:
void* handle = nullptr;
void* mHandle = nullptr;
};
#endif // COMMON_DYNAMICLIB_H_

View File

@ -40,11 +40,11 @@ class SerialQueue {
T& operator*() const;
private:
StorageIterator storageIterator;
// Special case the serialIterator when it should be equal to storageIterator.begin()
// otherwise we could ask storageIterator.begin() when storageIterator is storage.end()
// which is invalid. storageIterator.begin() is tagged with a nullptr.
T* serialIterator;
StorageIterator mStorageIterator;
// Special case the mSerialIterator when it should be equal to mStorageIterator.begin()
// otherwise we could ask mStorageIterator.begin() when mStorageIterator is mStorage.end()
// which is invalid. mStorageIterator.begin() is tagged with a nullptr.
T* mSerialIterator;
};
class ConstIterator {
@ -57,8 +57,8 @@ class SerialQueue {
const T& operator*() const;
private:
ConstStorageIterator storageIterator;
const T* serialIterator;
ConstStorageIterator mStorageIterator;
const T* mSerialIterator;
};
class BeginEnd {
@ -69,8 +69,8 @@ class SerialQueue {
Iterator end() const;
private:
StorageIterator startIt;
StorageIterator endIt;
StorageIterator mStartIt;
StorageIterator mEndIt;
};
class ConstBeginEnd {
@ -81,8 +81,8 @@ class SerialQueue {
ConstIterator end() const;
private:
ConstStorageIterator startIt;
ConstStorageIterator endIt;
ConstStorageIterator mStartIt;
ConstStorageIterator mEndIt;
};
// 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.
ConstStorageIterator FindUpTo(Serial serial) const;
StorageIterator FindUpTo(Serial serial);
Storage storage;
Storage mStorage;
};
// SerialQueue
template<typename T>
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) {
storage.emplace_back(SerialPair(serial, {}));
if (Empty() || mStorage.back().first < serial) {
mStorage.emplace_back(SerialPair(serial, {}));
}
storage.back().second.emplace_back(value);
mStorage.back().second.emplace_back(value);
}
template<typename T>
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) {
storage.emplace_back(SerialPair(serial, {}));
if (Empty() || mStorage.back().first < serial) {
mStorage.emplace_back(SerialPair(serial, {}));
}
storage.back().second.emplace_back(value);
mStorage.back().second.emplace_back(value);
}
template<typename T>
void SerialQueue<T>::Enqueue(const std::vector<T>& values, Serial serial) {
NXT_ASSERT(values.size() > 0);
NXT_ASSERT(Empty() || storage.back().first <= serial);
storage.emplace_back(SerialPair(serial, {values}));
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
mStorage.emplace_back(SerialPair(serial, {values}));
}
template<typename T>
void SerialQueue<T>::Enqueue(std::vector<T>&& values, Serial serial) {
NXT_ASSERT(values.size() > 0);
NXT_ASSERT(Empty() || storage.back().first <= serial);
storage.emplace_back(SerialPair(serial, {values}));
NXT_ASSERT(Empty() || mStorage.back().first <= serial);
mStorage.emplace_back(SerialPair(serial, {values}));
}
template<typename T>
bool SerialQueue<T>::Empty() const {
return storage.empty();
return mStorage.empty();
}
template<typename T>
typename SerialQueue<T>::ConstBeginEnd SerialQueue<T>::IterateAll() const {
return {storage.begin(), storage.end()};
return {mStorage.begin(), mStorage.end()};
}
template<typename T>
typename SerialQueue<T>::ConstBeginEnd SerialQueue<T>::IterateUpTo(Serial serial) const {
return {storage.begin(), FindUpTo(serial)};
return {mStorage.begin(), FindUpTo(serial)};
}
template<typename T>
typename SerialQueue<T>::BeginEnd SerialQueue<T>::IterateAll() {
return {storage.begin(), storage.end()};
return {mStorage.begin(), mStorage.end()};
}
template<typename T>
typename SerialQueue<T>::BeginEnd SerialQueue<T>::IterateUpTo(Serial serial) {
return {storage.begin(), FindUpTo(serial)};
return {mStorage.begin(), FindUpTo(serial)};
}
template<typename T>
void SerialQueue<T>::Clear() {
storage.clear();
mStorage.clear();
}
template<typename T>
void SerialQueue<T>::ClearUpTo(Serial serial) {
storage.erase(storage.begin(), FindUpTo(serial));
mStorage.erase(mStorage.begin(), FindUpTo(serial));
}
template<typename T>
Serial SerialQueue<T>::FirstSerial() const {
NXT_ASSERT(!Empty());
return storage.front().first;
return mStorage.front().first;
}
template<typename T>
typename SerialQueue<T>::ConstStorageIterator SerialQueue<T>::FindUpTo(Serial serial) const {
auto it = storage.begin();
while (it != storage.end() && it->first <= serial) {
auto it = mStorage.begin();
while (it != mStorage.end() && it->first <= serial) {
it ++;
}
return it;
@ -201,8 +201,8 @@ typename SerialQueue<T>::ConstStorageIterator SerialQueue<T>::FindUpTo(Serial se
template<typename T>
typename SerialQueue<T>::StorageIterator SerialQueue<T>::FindUpTo(Serial serial) {
auto it = storage.begin();
while (it != storage.end() && it->first <= serial) {
auto it = mStorage.begin();
while (it != mStorage.end() && it->first <= serial) {
it ++;
}
return it;
@ -212,39 +212,39 @@ typename SerialQueue<T>::StorageIterator SerialQueue<T>::FindUpTo(Serial serial)
template<typename T>
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>
typename SerialQueue<T>::Iterator SerialQueue<T>::BeginEnd::begin() const {
return {startIt};
return {mStartIt};
}
template<typename T>
typename SerialQueue<T>::Iterator SerialQueue<T>::BeginEnd::end() const {
return {endIt};
return {mEndIt};
}
// SerialQueue::Iterator
template<typename T>
SerialQueue<T>::Iterator::Iterator(typename SerialQueue<T>::StorageIterator start)
: storageIterator(start), serialIterator(nullptr) {
: mStorageIterator(start), mSerialIterator(nullptr) {
}
template<typename T>
typename SerialQueue<T>::Iterator& SerialQueue<T>::Iterator::operator++() {
T* vectorData = storageIterator->second.data();
T* vectorData = mStorageIterator->second.data();
if (serialIterator == nullptr) {
serialIterator = vectorData + 1;
if (mSerialIterator == nullptr) {
mSerialIterator = vectorData + 1;
} else {
serialIterator ++;
mSerialIterator ++;
}
if (serialIterator >= vectorData + storageIterator->second.size()) {
serialIterator = nullptr;
storageIterator ++;
if (mSerialIterator >= vectorData + mStorageIterator->second.size()) {
mSerialIterator = nullptr;
mStorageIterator ++;
}
return *this;
@ -252,7 +252,7 @@ typename SerialQueue<T>::Iterator& SerialQueue<T>::Iterator::operator++() {
template<typename T>
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>
@ -262,49 +262,49 @@ bool SerialQueue<T>::Iterator::operator!=(const typename SerialQueue<T>::Iterato
template<typename T>
T& SerialQueue<T>::Iterator::operator*() const {
if (serialIterator == nullptr) {
return *storageIterator->second.begin();
if (mSerialIterator == nullptr) {
return *mStorageIterator->second.begin();
}
return *serialIterator;
return *mSerialIterator;
}
// SerialQueue::ConstBeginEnd
template<typename T>
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>
typename SerialQueue<T>::ConstIterator SerialQueue<T>::ConstBeginEnd::begin() const {
return {startIt};
return {mStartIt};
}
template<typename T>
typename SerialQueue<T>::ConstIterator SerialQueue<T>::ConstBeginEnd::end() const {
return {endIt};
return {mEndIt};
}
// SerialQueue::ConstIterator
template<typename T>
SerialQueue<T>::ConstIterator::ConstIterator(typename SerialQueue<T>::ConstStorageIterator start)
: storageIterator(start), serialIterator(nullptr) {
: mStorageIterator(start), mSerialIterator(nullptr) {
}
template<typename T>
typename SerialQueue<T>::ConstIterator& SerialQueue<T>::ConstIterator::operator++() {
const T* vectorData = storageIterator->second.data();
const T* vectorData = mStorageIterator->second.data();
if (serialIterator == nullptr) {
serialIterator = vectorData + 1;
if (mSerialIterator == nullptr) {
mSerialIterator = vectorData + 1;
} else {
serialIterator ++;
mSerialIterator ++;
}
if (serialIterator >= vectorData + storageIterator->second.size()) {
serialIterator = nullptr;
storageIterator ++;
if (mSerialIterator >= vectorData + mStorageIterator->second.size()) {
mSerialIterator = nullptr;
mStorageIterator ++;
}
return *this;
@ -312,7 +312,7 @@ typename SerialQueue<T>::ConstIterator& SerialQueue<T>::ConstIterator::operator+
template<typename T>
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>
@ -322,10 +322,10 @@ bool SerialQueue<T>::ConstIterator::operator!=(const typename SerialQueue<T>::Co
template<typename T>
const T& SerialQueue<T>::ConstIterator::operator*() const {
if (serialIterator == nullptr) {
return *storageIterator->second.begin();
if (mSerialIterator == nullptr) {
return *mStorageIterator->second.begin();
}
return *serialIterator;
return *mSerialIterator;
}
#endif // COMMON_SERIALQUEUE_H_

View File

@ -35,7 +35,7 @@ namespace utils {
#endif
void BackendBinding::SetWindow(GLFWwindow* window) {
this->window = window;
mWindow = window;
}
BackendBinding* CreateBinding(BackendType type) {

View File

@ -43,7 +43,7 @@ namespace utils {
void SetWindow(GLFWwindow* window);
protected:
GLFWwindow* window = nullptr;
GLFWwindow* mWindow = nullptr;
};
BackendBinding* CreateBinding(BackendType type);

View File

@ -123,26 +123,26 @@ namespace utils {
}
private:
nxtDevice backendDevice = nullptr;
nxtProcTable procs = {};
nxtDevice mBackendDevice = nullptr;
nxtProcTable mProcs = {};
static constexpr unsigned int kFrameCount = 2;
HWND window = 0;
ComPtr<IDXGIFactory4> factory = {};
ComPtr<ID3D12CommandQueue> commandQueue = {};
ComPtr<IDXGISwapChain3> swapChain = {};
ComPtr<ID3D12Resource> renderTargetResources[kFrameCount] = {};
HWND mWindow = 0;
ComPtr<IDXGIFactory4> mFactory = {};
ComPtr<ID3D12CommandQueue> mCommandQueue = {};
ComPtr<IDXGISwapChain3> mSwapChain = {};
ComPtr<ID3D12Resource> mRenderTargetResources[kFrameCount] = {};
// Frame synchronization. Updated every frame
uint32_t renderTargetIndex = 0;
uint32_t previousRenderTargetIndex = 0;
uint64_t lastSerialRenderTargetWasUsed[kFrameCount] = {};
uint32_t mRenderTargetIndex = 0;
uint32_t mPreviousRenderTargetIndex = 0;
uint64_t mLastSerialRenderTargetWasUsed[kFrameCount] = {};
D3D12_RESOURCE_STATES renderTargetResourceState;
D3D12_RESOURCE_STATES mRenderTargetResourceState;
SwapChainImplD3D12(HWND window, nxtProcTable procs)
: window(window), procs(procs), factory(CreateFactory()) {
: mWindow(window), mProcs(procs), mFactory(CreateFactory()) {
}
~SwapChainImplD3D12() {
@ -152,8 +152,8 @@ namespace utils {
friend class SwapChainImpl;
void Init(nxtWSIContextD3D12* ctx) {
backendDevice = ctx->device;
commandQueue = backend::d3d12::GetCommandQueue(backendDevice);
mBackendDevice = ctx->device;
mCommandQueue = backend::d3d12::GetCommandQueue(mBackendDevice);
}
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit allowedUsage,
@ -175,73 +175,73 @@ namespace utils {
swapChainDesc.SampleDesc.Quality = 0;
ComPtr<IDXGISwapChain1> swapChain1;
ASSERT_SUCCESS(factory->CreateSwapChainForHwnd(
commandQueue.Get(),
window,
ASSERT_SUCCESS(mFactory->CreateSwapChainForHwnd(
mCommandQueue.Get(),
mWindow,
&swapChainDesc,
nullptr,
nullptr,
&swapChain1
));
ASSERT_SUCCESS(swapChain1.As(&swapChain));
ASSERT_SUCCESS(swapChain1.As(&mSwapChain));
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
previousRenderTargetIndex = renderTargetIndex = swapChain->GetCurrentBackBufferIndex();
previousRenderTargetIndex = renderTargetIndex == 0 ? 1 : 0;
mPreviousRenderTargetIndex = mRenderTargetIndex = mSwapChain->GetCurrentBackBufferIndex();
mPreviousRenderTargetIndex = mRenderTargetIndex == 0 ? 1 : 0;
// 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) {
lastSerialRenderTargetWasUsed[n] = initialSerial;
mLastSerialRenderTargetWasUsed[n] = initialSerial;
}
return NXT_SWAP_CHAIN_NO_ERROR;
}
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
nextTexture->texture = renderTargetResources[renderTargetIndex].Get();
nextTexture->texture = mRenderTargetResources[mRenderTargetIndex].Get();
return NXT_SWAP_CHAIN_NO_ERROR;
}
nxtSwapChainError Present() {
// Current frame already transitioned to Present by the application, but
// 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
if (renderTargetResourceState != D3D12_RESOURCE_STATE_PRESENT) {
if (mRenderTargetResourceState != D3D12_RESOURCE_STATE_PRESENT) {
ComPtr<ID3D12GraphicsCommandList> commandList = {};
backend::d3d12::OpenCommandList(backendDevice, &commandList);
backend::d3d12::OpenCommandList(mBackendDevice, &commandList);
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.StateAfter = renderTargetResourceState;
resourceBarrier.Transition.StateAfter = mRenderTargetResourceState;
resourceBarrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
resourceBarrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
resourceBarrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
commandList->ResourceBarrier(1, &resourceBarrier);
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;
renderTargetIndex = swapChain->GetCurrentBackBufferIndex();
mPreviousRenderTargetIndex = mRenderTargetIndex;
mRenderTargetIndex = mSwapChain->GetCurrentBackBufferIndex();
// 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,
// 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;
}
@ -254,25 +254,25 @@ namespace utils {
}
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
factory = CreateFactory();
ASSERT(GetHardwareAdapter(factory.Get(), &hardwareAdapter));
mFactory = CreateFactory();
ASSERT(GetHardwareAdapter(mFactory.Get(), &mHardwareAdapter));
ASSERT_SUCCESS(D3D12CreateDevice(
hardwareAdapter.Get(),
mHardwareAdapter.Get(),
D3D_FEATURE_LEVEL_11_0,
IID_PPV_ARGS(&d3d12Device)
IID_PPV_ARGS(&mD3d12Device)
));
backend::d3d12::Init(d3d12Device, procs, device);
backendDevice = *device;
procTable = *procs;
backend::d3d12::Init(mD3d12Device, procs, device);
mBackendDevice = *device;
mProcTable = *procs;
}
uint64_t GetSwapChainImplementation() override {
if (swapchainImpl.userData == nullptr) {
HWND win32Window = glfwGetWin32Window(window);
swapchainImpl = SwapChainImplD3D12::Create(win32Window, procTable);
if (mSwapchainImpl.userData == nullptr) {
HWND win32Window = glfwGetWin32Window(mWindow);
mSwapchainImpl = SwapChainImplD3D12::Create(win32Window, mProcTable);
}
return reinterpret_cast<uint64_t>(&swapchainImpl);
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
}
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
@ -280,14 +280,14 @@ namespace utils {
}
private:
nxtDevice backendDevice = nullptr;
nxtSwapChainImplementation swapchainImpl = {};
nxtProcTable procTable = {};
nxtDevice mBackendDevice = nullptr;
nxtSwapChainImplementation mSwapchainImpl = {};
nxtProcTable mProcTable = {};
// Initialization
ComPtr<IDXGIFactory4> factory;
ComPtr<IDXGIAdapter1> hardwareAdapter;
ComPtr<ID3D12Device> d3d12Device;
ComPtr<IDXGIFactory4> mFactory;
ComPtr<IDXGIAdapter1> mHardwareAdapter;
ComPtr<ID3D12Device> mD3d12Device;
static bool GetHardwareAdapter(IDXGIFactory4* factory, IDXGIAdapter1** hardwareAdapter) {
*hardwareAdapter = nullptr;

View File

@ -43,29 +43,29 @@ namespace utils {
}
private:
id nsWindow = nil;
id<MTLDevice> mtlDevice = nil;
id<MTLCommandQueue> commandQueue = nil;
id mNsWindow = nil;
id<MTLDevice> mMtlDevice = nil;
id<MTLCommandQueue> mCommandQueue = nil;
CAMetalLayer* layer = nullptr;
id<CAMetalDrawable> currentDrawable = nil;
id<MTLTexture> currentTexture = nil;
CAMetalLayer* mLayer = nullptr;
id<CAMetalDrawable> mCurrentDrawable = nil;
id<MTLTexture> mCurrentTexture = nil;
SwapChainImplMTL(id nsWindow)
: nsWindow(nsWindow) {
: mNsWindow(nsWindow) {
}
~SwapChainImplMTL() {
[currentTexture release];
[currentDrawable release];
[mCurrentTexture release];
[mCurrentDrawable release];
}
// For GenerateSwapChainImplementation
friend class SwapChainImpl;
void Init(nxtWSIContextMetal* ctx) {
mtlDevice = ctx->device;
commandQueue = [mtlDevice newCommandQueue];
mMtlDevice = ctx->device;
mCommandQueue = [mMtlDevice newCommandQueue];
}
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit,
@ -76,41 +76,41 @@ namespace utils {
ASSERT(width > 0);
ASSERT(height > 0);
NSView* contentView = [nsWindow contentView];
NSView* contentView = [mNsWindow contentView];
[contentView setWantsLayer: YES];
CGSize size = {};
size.width = width;
size.height = height;
layer = [CAMetalLayer layer];
[layer setDevice: mtlDevice];
[layer setPixelFormat: MTLPixelFormatBGRA8Unorm];
[layer setFramebufferOnly: YES];
[layer setDrawableSize: size];
mLayer = [CAMetalLayer layer];
[mLayer setDevice: mMtlDevice];
[mLayer setPixelFormat: MTLPixelFormatBGRA8Unorm];
[mLayer setFramebufferOnly: YES];
[mLayer setDrawableSize: size];
[contentView setLayer: layer];
[contentView setLayer: mLayer];
return NXT_SWAP_CHAIN_NO_ERROR;
}
nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture* nextTexture) {
[currentDrawable release];
currentDrawable = [layer nextDrawable];
[currentDrawable retain];
[mCurrentDrawable release];
mCurrentDrawable = [mLayer nextDrawable];
[mCurrentDrawable retain];
[currentTexture release];
currentTexture = currentDrawable.texture;
[currentTexture retain];
[mCurrentTexture release];
mCurrentTexture = mCurrentDrawable.texture;
[mCurrentTexture retain];
nextTexture->texture = reinterpret_cast<void*>(currentTexture);
nextTexture->texture = reinterpret_cast<void*>(mCurrentTexture);
return NXT_SWAP_CHAIN_NO_ERROR;
}
nxtSwapChainError Present() {
id<MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];
[commandBuffer presentDrawable: currentDrawable];
id<MTLCommandBuffer> commandBuffer = [mCommandQueue commandBuffer];
[commandBuffer presentDrawable: mCurrentDrawable];
[commandBuffer commit];
return NXT_SWAP_CHAIN_NO_ERROR;
@ -123,17 +123,17 @@ namespace utils {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
}
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
metalDevice = MTLCreateSystemDefaultDevice();
mMetalDevice = MTLCreateSystemDefaultDevice();
backend::metal::Init(metalDevice, procs, device);
backendDevice = *device;
backend::metal::Init(mMetalDevice, procs, device);
mBackendDevice = *device;
}
uint64_t GetSwapChainImplementation() override {
if (swapchainImpl.userData == nullptr) {
swapchainImpl = SwapChainImplMTL::Create(glfwGetCocoaWindow(window));
if (mSwapchainImpl.userData == nullptr) {
mSwapchainImpl = SwapChainImplMTL::Create(glfwGetCocoaWindow(mWindow));
}
return reinterpret_cast<uint64_t>(&swapchainImpl);
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
}
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
@ -141,9 +141,9 @@ namespace utils {
}
private:
id<MTLDevice> metalDevice = nil;
nxtDevice backendDevice = nullptr;
nxtSwapChainImplementation swapchainImpl = {};
id<MTLDevice> mMetalDevice = nil;
nxtDevice mBackendDevice = nullptr;
nxtSwapChainImplementation mSwapchainImpl = {};
};
BackendBinding* CreateMetalBinding() {

View File

@ -39,34 +39,34 @@ namespace utils {
}
private:
GLFWwindow* window = nullptr;
uint32_t cfgWidth = 0;
uint32_t cfgHeight = 0;
GLuint backFBO = 0;
GLuint backTexture = 0;
GLFWwindow* mWindow = nullptr;
uint32_t mWidth = 0;
uint32_t mHeight = 0;
GLuint mBackFBO = 0;
GLuint mBackTexture = 0;
SwapChainImplGL(GLFWwindow* window)
: window(window) {
: mWindow(window) {
}
~SwapChainImplGL() {
glDeleteTextures(1, &backTexture);
glDeleteFramebuffers(1, &backFBO);
glDeleteTextures(1, &mBackTexture);
glDeleteFramebuffers(1, &mBackFBO);
}
// For GenerateSwapChainImplementation
friend class SwapChainImpl;
void Init(nxtWSIContextGL*) {
glGenTextures(1, &backTexture);
glBindTexture(GL_TEXTURE_2D, backTexture);
glGenTextures(1, &mBackTexture);
glBindTexture(GL_TEXTURE_2D, mBackTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, 0,
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glGenFramebuffers(1, &backFBO);
glBindFramebuffer(GL_READ_FRAMEBUFFER, backFBO);
glGenFramebuffers(1, &mBackFBO);
glBindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, backTexture, 0);
GL_TEXTURE_2D, mBackTexture, 0);
}
nxtSwapChainError Configure(nxtTextureFormat format, nxtTextureUsageBit,
@ -76,10 +76,10 @@ namespace utils {
}
ASSERT(width > 0);
ASSERT(height > 0);
cfgWidth = width;
cfgHeight = height;
mWidth = width;
mHeight = height;
glBindTexture(GL_TEXTURE_2D, backTexture);
glBindTexture(GL_TEXTURE_2D, mBackTexture);
// Reallocate the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
@ -88,16 +88,16 @@ namespace utils {
}
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;
}
nxtSwapChainError Present() {
glBindFramebuffer(GL_READ_FRAMEBUFFER, backFBO);
glBindFramebuffer(GL_READ_FRAMEBUFFER, mBackFBO);
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);
glfwSwapBuffers(window);
glfwSwapBuffers(mWindow);
return NXT_SWAP_CHAIN_NO_ERROR;
}
@ -119,17 +119,17 @@ namespace utils {
#endif
}
void GetProcAndDevice(nxtProcTable* procs, nxtDevice* device) override {
glfwMakeContextCurrent(window);
glfwMakeContextCurrent(mWindow);
backend::opengl::Init(reinterpret_cast<void*(*)(const char*)>(glfwGetProcAddress), procs, device);
backendDevice = *device;
mBackendDevice = *device;
}
uint64_t GetSwapChainImplementation() override {
if (swapchainImpl.userData == nullptr) {
swapchainImpl = SwapChainImplGL::Create(window);
if (mSwapchainImpl.userData == nullptr) {
mSwapchainImpl = SwapChainImplGL::Create(mWindow);
}
return reinterpret_cast<uint64_t>(&swapchainImpl);
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
}
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
@ -137,8 +137,8 @@ namespace utils {
}
private:
nxtDevice backendDevice = nullptr;
nxtSwapChainImplementation swapchainImpl = {};
nxtDevice mBackendDevice = nullptr;
nxtSwapChainImplementation mSwapchainImpl = {};
};
BackendBinding* CreateOpenGLBinding() {

View File

@ -70,17 +70,17 @@ namespace utils {
backend::vulkan::Init(procs, device);
}
uint64_t GetSwapChainImplementation() override {
if (swapchainImpl.userData == nullptr) {
swapchainImpl = SwapChainImplVulkan::Create(window);
if (mSwapchainImpl.userData == nullptr) {
mSwapchainImpl = SwapChainImplVulkan::Create(mWindow);
}
return reinterpret_cast<uint64_t>(&swapchainImpl);
return reinterpret_cast<uint64_t>(&mSwapchainImpl);
}
nxtTextureFormat GetPreferredSwapChainTextureFormat() override {
return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM;
}
private:
nxtSwapChainImplementation swapchainImpl = {};
nxtSwapChainImplementation mSwapchainImpl = {};
};

View File

@ -20,22 +20,22 @@ namespace wire {
TerribleCommandBuffer::TerribleCommandBuffer() {
}
TerribleCommandBuffer::TerribleCommandBuffer(CommandHandler* handler) : handler(handler) {
TerribleCommandBuffer::TerribleCommandBuffer(CommandHandler* handler) : mHandler(handler) {
}
void TerribleCommandBuffer::SetHandler(CommandHandler* handler) {
this->handler = handler;
mHandler = handler;
}
void* TerribleCommandBuffer::GetCmdSpace(size_t size) {
if (size > sizeof(buffer)) {
if (size > sizeof(mBuffer)) {
return nullptr;
}
uint8_t* result = &buffer[offset];
offset += size;
uint8_t* result = &mBuffer[mOffset];
mOffset += size;
if (offset > sizeof(buffer)) {
if (mOffset > sizeof(mBuffer)) {
Flush();
return GetCmdSpace(size);
}
@ -44,8 +44,8 @@ namespace wire {
}
void TerribleCommandBuffer::Flush() {
handler->HandleCommands(buffer, offset);
offset = 0;
mHandler->HandleCommands(mBuffer, mOffset);
mOffset = 0;
}
}

View File

@ -33,9 +33,9 @@ class TerribleCommandBuffer : public CommandSerializer {
void Flush() override;
private:
CommandHandler* handler = nullptr;
size_t offset = 0;
uint8_t buffer[10000000];
CommandHandler* mHandler = nullptr;
size_t mOffset = 0;
uint8_t mBuffer[10000000];
};
}