Avoid name conflicts between Util and Windows function

GetWindow and SwapBuffers are function of Windows.h and using the same
name causes a compile error.

This commit also changes Util's GetProcTableAndDevice to CreateNXTDevice
because we might need to call NXT procs when creating the C++ device.
This commit is contained in:
Corentin Wallez 2017-05-29 11:30:29 -07:00 committed by Corentin Wallez
parent 26275d0a16
commit 583e9a8f3c
13 changed files with 71 additions and 87 deletions

View File

@ -16,7 +16,6 @@
#include <cstdlib>
#include <cstdio>
#include <unistd.h>
#include <vector>
nxt::Device device;
@ -42,9 +41,7 @@ struct ShaderData {
static std::vector<ShaderData> shaderData;
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -150,7 +147,7 @@ void frame() {
}
queue.Submit(50, commands.data());
SwapBuffers();
DoSwapBuffers();
fprintf(stderr, "frame %i\n", f);
}
@ -162,7 +159,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -17,7 +17,6 @@
#include <array>
#include <cstring>
#include <random>
#include <unistd.h>
#include <glm/glm.hpp>
@ -296,9 +295,7 @@ void initCommandBuffers() {
}
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -310,7 +307,7 @@ void init() {
void frame() {
queue.Submit(1, &commandBuffers[pingpong]);
SwapBuffers();
DoSwapBuffers();
pingpong = (pingpong + 1) % 2;
}
@ -323,7 +320,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -15,7 +15,6 @@
#include "Utils.h"
#include <string.h>
#include <unistd.h>
nxt::Device device;
nxt::Queue queue;
@ -28,9 +27,7 @@ nxt::Pipeline computePipeline;
nxt::BindGroup computeBindGroup;
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -142,7 +139,7 @@ void frame() {
.GetResult();
queue.Submit(1, &commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -153,7 +150,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -14,7 +14,6 @@
#include "Utils.h"
#include <unistd.h>
#include <vector>
nxt::Device device;
@ -55,9 +54,7 @@ void initBuffers() {
}
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -105,7 +102,7 @@ void frame() {
.GetResult();
queue.Submit(1, &commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -116,7 +113,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -14,7 +14,6 @@
#include "Utils.h"
#include <unistd.h>
#include <vector>
nxt::Device device;
@ -59,9 +58,7 @@ void initBuffers() {
}
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -112,7 +109,7 @@ void frame() {
.GetResult();
queue.Submit(1, &commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -123,7 +120,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -14,8 +14,6 @@
#include "Utils.h"
#include <unistd.h>
nxtDevice device;
nxtQueue queue;
nxtPipeline pipeline;
@ -23,9 +21,7 @@ nxtRenderPass renderpass;
nxtFramebuffer framebuffer;
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateNXTDevice();
{
nxtQueueBuilder builder = nxtDeviceCreateQueueBuilder(device);
@ -93,7 +89,7 @@ void frame() {
nxtQueueSubmit(queue, 1, &commands);
nxtCommandBufferRelease(commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -104,7 +100,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -14,7 +14,6 @@
#include "Utils.h"
#include <unistd.h>
#include <vector>
nxt::Device device;
@ -95,9 +94,7 @@ void initTextures() {
}
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -173,7 +170,7 @@ void frame() {
.GetResult();
queue.Submit(1, &commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -184,7 +181,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -14,8 +14,6 @@
#include "Utils.h"
#include <unistd.h>
nxt::Device device;
nxt::Queue queue;
nxt::Pipeline pipeline;
@ -27,9 +25,7 @@ nxt::BindGroup bindGroup;
struct {uint32_t a; float b;} s;
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -104,7 +100,7 @@ void frame() {
.GetResult();
queue.Submit(1, &commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -115,7 +111,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -14,7 +14,6 @@
#include "Utils.h"
#include <unistd.h>
#include <vector>
nxt::Device device;
@ -43,9 +42,7 @@ void initBuffers() {
}
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -92,7 +89,7 @@ void frame() {
.GetResult();
queue.Submit(1, &commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -103,7 +100,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -14,7 +14,6 @@
#include "Utils.h"
#include <unistd.h>
#include <vector>
nxt::Device device;
@ -183,9 +182,7 @@ void initPipelinePost() {
}
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -217,7 +214,7 @@ void frame() {
.GetResult();
queue.Submit(1, &commands);
SwapBuffers();
DoSwapBuffers();
}
int main(int argc, const char* argv[]) {
@ -228,7 +225,7 @@ int main(int argc, const char* argv[]) {
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff

View File

@ -25,6 +25,12 @@
#include <sstream>
#include <iomanip>
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
BackendBinding* CreateMetalBinding();
namespace backend {
@ -104,7 +110,7 @@ static nxt::wire::CommandHandler* wireClient = nullptr;
static nxt::wire::TerribleCommandBuffer* c2sBuf = nullptr;
static nxt::wire::TerribleCommandBuffer* s2cBuf = nullptr;
void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
nxt::Device CreateCppNXTDevice() {
switch (backendType) {
case BackendType::OpenGL:
binding = new OpenGLBinding;
@ -122,13 +128,13 @@ void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
}
if (!glfwInit()) {
return;
return nxt::Device();
}
binding->SetupGLFWWindowHints();
window = glfwCreateWindow(640, 480, "NXT window", nullptr, nullptr);
if (!window) {
return;
return nxt::Device();
}
binding->SetWindow(window);
@ -137,10 +143,12 @@ void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
nxtProcTable backendProcs;
binding->GetProcAndDevice(&backendProcs, &backendDevice);
nxtDevice cDevice = nullptr;
nxtProcTable procs;
switch (cmdBufType) {
case CmdBufType::None:
*procs = backendProcs;
*device = nxt::Device::Acquire(backendDevice);
procs = backendProcs;
cDevice = backendDevice;
break;
case CmdBufType::Terrible:
@ -156,13 +164,15 @@ void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
wireClient = nxt::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
s2cBuf->SetHandler(wireClient);
*procs = clientProcs;
*device = nxt::Device::Acquire(clientDevice);
procs = clientProcs;
cDevice = clientDevice;
}
break;
}
procs->deviceSetErrorCallback(device->Get(), PrintDeviceError, 0);
nxtSetProcs(&procs);
procs.deviceSetErrorCallback(cDevice, PrintDeviceError, 0);
return nxt::Device::Acquire(cDevice);
}
nxt::ShaderModule CreateShaderModule(const nxt::Device& device, nxt::ShaderStage stage, const char* source) {
@ -278,17 +288,15 @@ extern "C" {
return true;
}
void GetProcTableAndDevice(nxtProcTable* procs, nxtDevice* device) {
nxt::Device cppDevice;
GetProcTableAndDevice(procs, &cppDevice);
*device = cppDevice.Release();
nxtDevice CreateNXTDevice() {
return CreateCppNXTDevice().Release();
}
nxtShaderModule CreateShaderModule(nxtDevice device, nxtShaderStage stage, const char* source) {
return CreateShaderModule(device, static_cast<nxt::ShaderStage>(stage), source).Release();
}
void SwapBuffers() {
void DoSwapBuffers() {
if (cmdBufType == CmdBufType::Terrible) {
c2sBuf->Flush();
s2cBuf->Flush();
@ -297,11 +305,21 @@ extern "C" {
binding->SwapBuffers();
}
#ifdef _WIN32
void USleep(uint64_t usecs) {
Sleep(usecs / 1000);
}
#else
void USleep(uint64_t usecs) {
usleep(usecs);
}
#endif
bool ShouldQuit() {
return glfwWindowShouldClose(window);
}
GLFWwindow* GetWindow() {
GLFWwindow* GetGLFWWindow() {
return window;
}
}

View File

@ -18,11 +18,12 @@
extern "C" {
#endif
bool InitUtils(int argc, const char** argv);
void SwapBuffers();
void DoSwapBuffers();
bool ShouldQuit();
void USleep(uint64_t usecs);
struct GLFWwindow;
struct GLFWwindow* GetWindow();
struct GLFWwindow* GetGLFWWindow();
#if defined(__cplusplus)
}
#endif
@ -30,10 +31,10 @@ extern "C" {
// Yuck
#if defined(__cplusplus)
#include <nxt/nxtcpp.h>
void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device);
nxt::Device CreateCppNXTDevice();
nxt::ShaderModule CreateShaderModule(const nxt::Device& device, nxt::ShaderStage stage, const char* source);
void CreateDefaultRenderPass(const nxt::Device& device, nxt::RenderPass* renderPass, nxt::Framebuffer* framebuffer);
#else
void GetProcTableAndDevice(nxtProcTable* procs, nxtDevice* device);
nxtDevice CreateNXTDevice();
nxtShaderModule CreateShaderModule(nxtDevice device, nxtShaderStage stage, const char* source);
#endif

View File

@ -15,7 +15,6 @@
#include "Utils.h"
#include <bitset>
#include <unistd.h>
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/mat4x4.hpp>
#include <glm/gtc/matrix_inverse.hpp>
@ -450,9 +449,7 @@ namespace {
}
void init() {
nxtProcTable procs;
GetProcTableAndDevice(&procs, &device);
nxtSetProcs(&procs);
device = CreateCppNXTDevice();
queue = device.CreateQueueBuilder().GetResult();
@ -575,7 +572,7 @@ namespace {
const auto& node = scene.nodes.at(n);
drawNode(node);
}
SwapBuffers();
DoSwapBuffers();
}
}
@ -640,14 +637,14 @@ int main(int argc, const char* argv[]) {
init();
GLFWwindow* window = GetWindow();
GLFWwindow* window = GetGLFWWindow();
glfwSetMouseButtonCallback(window, mouseButtonCallback);
glfwSetCursorPosCallback(window, cursorPosCallback);
glfwSetScrollCallback(window, scrollCallback);
while (!ShouldQuit()) {
frame();
usleep(16000);
USleep(16000);
}
// TODO release stuff