Skip to content

Commit

Permalink
Fix build of interop tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Feb 19, 2024
1 parent c1eaa5e commit ea9038d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 48 deletions.
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ if (GRANITE_TEST_INTEROP)
glad/src/glad.c
glad/include/glad/glad.h
glad/include/KHR/khrplatform.h)
target_link_libraries(granite-gl-interop PRIVATE glfw granite-vulkan)
target_link_libraries(granite-gl-interop PRIVATE SDL3-static granite-vulkan)
target_include_directories(granite-gl-interop PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/glad/include)

if (WIN32)
add_granite_offline_tool(granite-d3d11-interop d3d11_interop_test.cpp)
target_link_libraries(granite-d3d11-interop PRIVATE glfw granite-vulkan d3d11 dxgi)
target_link_libraries(granite-d3d11-interop PRIVATE SDL3-static granite-vulkan d3d11 dxgi)
add_granite_offline_tool(granite-d3d12-interop d3d12_interop_test.cpp)
target_link_libraries(granite-d3d12-interop PRIVATE glfw granite-vulkan d3d12 dxgi)
target_link_libraries(granite-d3d12-interop PRIVATE SDL3-static granite-vulkan d3d12 dxgi)
endif()
endif()

Expand Down
32 changes: 19 additions & 13 deletions tests/d3d11_interop_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#define GLFW_EXPOSE_NATIVE_WIN32
#include "GLFW/glfw3.h"
#include "GLFW/glfw3native.h"
#include "device.hpp"
#include "context.hpp"
#include "global_managers_init.hpp"
Expand All @@ -9,6 +6,8 @@
#include "dxgi1_6.h"
#include "d3d11_4.h"

#include <SDL3/SDL.h>

using namespace Vulkan;

struct DXGIContext
Expand Down Expand Up @@ -110,9 +109,13 @@ static D3DContext create_d3d11_device()
return ctx;
}

static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)
static bool init_swapchain(SDL_Window *window, D3DContext &ctx)
{
HWND hwnd = glfwGetWin32Window(window);
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_LockProperties(props);
HWND hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
SDL_UnlockProperties(props);

DXGI_SWAP_CHAIN_DESC desc = {};
desc.BufferCount = 1;
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
Expand Down Expand Up @@ -140,7 +143,7 @@ static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)

int main()
{
if (!glfwInit())
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return EXIT_FAILURE;

Granite::Global::init(Granite::Global::MANAGER_FEATURE_DEFAULT_BITS, 1);
Expand All @@ -149,8 +152,7 @@ int main()
if (!ctx.dev)
return EXIT_FAILURE;

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *window = glfwCreateWindow(1280, 720, "D3D11 interop", nullptr, nullptr);
SDL_Window *window = SDL_CreateWindow("D3D11 interop", 1280, 720, 0);
if (!window)
{
LOGE("Failed to create window.\n");
Expand Down Expand Up @@ -182,7 +184,7 @@ int main()
return EXIT_FAILURE;
}

if (memcmp(device.get_device_features().id_properties.deviceLUID,
if (memcmp(device.get_device_features().vk11_props.deviceLUID,
&ctx.luid, VK_LUID_SIZE) != 0)
{
LOGE("LUID mismatch.\n");
Expand Down Expand Up @@ -261,9 +263,13 @@ int main()
uint64_t timeline_value = 0;
unsigned frame_count = 0;

while (!glfwWindowShouldClose(window))
bool alive = true;
SDL_Event e;
while (alive)
{
glfwPollEvents();
while (SDL_PollEvent(&e))
if (e.type == SDL_EVENT_QUIT)
alive = false;

// Render frame in Vulkan
{
Expand Down Expand Up @@ -352,6 +358,6 @@ int main()
if (ref != 0)
LOGE("Missed a release on device.\n");

glfwDestroyWindow(window);
glfwTerminate();
SDL_DestroyWindow(window);
SDL_Quit();
}
32 changes: 19 additions & 13 deletions tests/d3d12_interop_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#define GLFW_EXPOSE_NATIVE_WIN32
#include "GLFW/glfw3.h"
#include "GLFW/glfw3native.h"
#include "device.hpp"
#include "context.hpp"
#include "global_managers_init.hpp"
Expand All @@ -9,6 +6,8 @@
#include "dxgi1_6.h"
#include "d3d12.h"

#include <SDL3/SDL.h>

using namespace Vulkan;

struct DXGIContext
Expand Down Expand Up @@ -117,9 +116,13 @@ static D3DContext create_d3d12_device()
return ctx;
}

static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)
static bool init_swapchain(SDL_Window *window, D3DContext &ctx)
{
HWND hwnd = glfwGetWin32Window(window);
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_LockProperties(props);
HWND hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
SDL_UnlockProperties(props);

DXGI_SWAP_CHAIN_DESC desc = {};
desc.BufferCount = 2;
desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
Expand Down Expand Up @@ -156,7 +159,7 @@ static bool init_swapchain(GLFWwindow *window, D3DContext &ctx)

int main()
{
if (!glfwInit())
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return EXIT_FAILURE;

Granite::Global::init(Granite::Global::MANAGER_FEATURE_DEFAULT_BITS, 1);
Expand All @@ -165,8 +168,7 @@ int main()
if (!ctx.dev)
return EXIT_FAILURE;

glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow *window = glfwCreateWindow(1280, 720, "D3D12 interop", nullptr, nullptr);
SDL_Window *window = SDL_CreateWindow("D3D12 interop", 1280, 720, 0);
if (!window)
{
LOGE("Failed to create window.\n");
Expand Down Expand Up @@ -198,7 +200,7 @@ int main()
return EXIT_FAILURE;
}

if (memcmp(device.get_device_features().id_properties.deviceLUID,
if (memcmp(device.get_device_features().vk11_props.deviceLUID,
&ctx.luid, VK_LUID_SIZE) != 0)
{
LOGE("LUID mismatch.\n");
Expand Down Expand Up @@ -279,9 +281,13 @@ int main()
unsigned frame_count = 0;
unsigned wait_context;

while (!glfwWindowShouldClose(window))
bool alive = true;
SDL_Event e;
while (alive)
{
glfwPollEvents();
while (SDL_PollEvent(&e))
if (e.type == SDL_EVENT_QUIT)
alive = false;

wait_context = frame_count % 2;

Expand Down Expand Up @@ -400,6 +406,6 @@ int main()
if (ref != 0)
LOGE("Missed a release on device.\n");

glfwDestroyWindow(window);
glfwTerminate();
SDL_DestroyWindow(window);
SDL_Quit();
}
40 changes: 21 additions & 19 deletions tests/gl_interop_test.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "glad/glad.h"
#include "GLFW/glfw3.h"
#include "device.hpp"
#include "context.hpp"
#include "global_managers_init.hpp"
#include <stdlib.h>
#include <cmath>

#include <SDL3/SDL.h>

#ifndef _WIN32
#include <unistd.h>
#endif
Expand Down Expand Up @@ -38,24 +39,20 @@ static void import_semaphore(GLuint &glsem, const ExternalHandle &handle)
int main()
{
Granite::Global::init(Granite::Global::MANAGER_FEATURE_DEFAULT_BITS, 1);
if (!glfwInit())
if (SDL_Init(SDL_INIT_VIDEO) < 0)
return EXIT_FAILURE;

glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);

GLFWwindow *window = glfwCreateWindow(1280, 720, "GL interop", nullptr, nullptr);
SDL_Window *window = SDL_CreateWindow("GL interop", 1280, 720, SDL_WINDOW_OPENGL);
if (!window)
{
LOGE("Failed to create window.\n");
return EXIT_FAILURE;
}

glfwMakeContextCurrent(window);
SDL_GLContext glctx = SDL_GL_CreateContext(window);
SDL_GL_MakeCurrent(window, glctx);

if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
if (!gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
{
LOGE("Failed to load GL context functions.\n");
return EXIT_FAILURE;
Expand All @@ -81,7 +78,7 @@ int main()
}
#endif

glfwSwapInterval(1);
SDL_GL_SetSwapInterval(1);
unsigned frame_count = 0;

Context ctx;
Expand Down Expand Up @@ -134,12 +131,12 @@ int main()
LOGI("GL vendor: %s\n", vendor);

auto &features = device.get_device_features();
if (features.id_properties.deviceLUIDValid)
if (features.vk11_props.deviceLUIDValid)
{
GLubyte luid[GL_LUID_SIZE_EXT] = {};
glGetUnsignedBytevEXT(GL_DEVICE_LUID_EXT, luid);

if (memcmp(features.id_properties.deviceLUID, luid, GL_LUID_SIZE_EXT) != 0)
if (memcmp(features.vk11_props.deviceLUID, luid, GL_LUID_SIZE_EXT) != 0)
{
LOGE("LUID mismatch.\n");
return EXIT_FAILURE;
Expand Down Expand Up @@ -178,9 +175,13 @@ int main()
return EXIT_FAILURE;
}

while (!glfwWindowShouldClose(window))
bool alive = true;
SDL_Event e;
while (alive)
{
glfwPollEvents();
while (SDL_PollEvent(&e))
if (e.type == SDL_EVENT_QUIT)
alive = false;

// Render frame in Vulkan
{
Expand Down Expand Up @@ -243,7 +244,7 @@ int main()
}

int fb_width, fb_height;
glfwGetFramebufferSize(window, &fb_width, &fb_height);
SDL_GetWindowSize(window, &fb_width, &fb_height);

glBlitNamedFramebuffer(glfbo, 0,
0, 0, GLint(image->get_width()), GLint(image->get_height()),
Expand Down Expand Up @@ -273,7 +274,7 @@ int main()
glDeleteSemaphoresEXT(1, &glsem);
}

glfwSwapBuffers(window);
SDL_GL_SwapWindow(window);
device.next_frame_context();
frame_count++;
}
Expand All @@ -284,6 +285,7 @@ int main()

check_gl_error();

glfwDestroyWindow(window);
glfwTerminate();
SDL_GL_DeleteContext(glctx);
SDL_DestroyWindow(window);
SDL_Quit();
}

0 comments on commit ea9038d

Please sign in to comment.