Skip to content

Commit

Permalink
tocpp: Support wayland (#1870)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-lunarg authored Nov 7, 2024
1 parent ba60bc9 commit 69a7108
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 17 deletions.
65 changes: 65 additions & 0 deletions framework/decode/vulkan_cpp_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ void VulkanCppConsumerBase::WriteMainHeader()
case GfxToCppPlatform::PLATFORM_XCB:
fprintf(main_file_, "%s", sXcbOutputMainStart);
break;
case GfxToCppPlatform::PLATFORM_WAYLAND:
fprintf(main_file_, "%s", sWaylandOutputMainStart);
break;
default:
GFXRECON_LOG_FATAL("Failed to write main header: Invalid platform (%d)", platform_);
break;
}
}

Expand All @@ -110,6 +116,12 @@ void VulkanCppConsumerBase::WriteMainFooter()
case GfxToCppPlatform::PLATFORM_XCB:
fprintf(main_file_, "%s", sXcbOutputMainEnd);
break;
case GfxToCppPlatform::PLATFORM_WAYLAND:
fprintf(main_file_, "%s", sWaylandOutputMainEnd);
break;
default:
GFXRECON_LOG_FATAL("Failed to write main footer: Invalid platform (%d)", platform_);
break;
}
}

Expand Down Expand Up @@ -146,6 +158,17 @@ bool VulkanCppConsumerBase::WriteGlobalHeaderFile()
sXcbOutputHeader,
sCommonOutputHeaderFunctions);
break;
case GfxToCppPlatform::PLATFORM_WAYLAND:
fprintf(header_file,
"%s%s%s%s",
sWaylandOutputHeadersPlatform,
sCommonHeaderOutputHeaders,
sWaylandOutputHeader,
sCommonOutputHeaderFunctions);
break;
default:
GFXRECON_LOG_FATAL("Failed to write global header file: Invalid platform (%d)", platform_);
break;
}

PrintToFile(header_file, "extern %s;\n", GfxToCppVariable::GenerateStringVec(variable_data_));
Expand Down Expand Up @@ -188,6 +211,12 @@ void VulkanCppConsumerBase::PrintOutCMakeFile()
case GfxToCppPlatform::PLATFORM_XCB:
fprintf(cmake_file, "%s", sXcbCMakeFile);
break;
case GfxToCppPlatform::PLATFORM_WAYLAND:
fprintf(cmake_file, "%s", sWaylandCMakeFile);
break;
default:
GFXRECON_LOG_FATAL("Failed to print out CMake file: Unknown platform (%d)", platform_);
break;
}
util::platform::FileClose(cmake_file);
}
Expand Down Expand Up @@ -273,6 +302,22 @@ void VulkanCppConsumerBase::PrintOutGlobalVar()
delete[] formatted_output_override_method;
break;
}
case GfxToCppPlatform::PLATFORM_WAYLAND:
{
int size = snprintf(NULL, 0, sWaylandOutputOverrideMethod, window_width_, window_height_);
char* formatted_output_override_method = new char[size + 2];
snprintf(formatted_output_override_method,
size + 2,
sWaylandOutputOverrideMethod,
window_width_,
window_height_);
fputs(formatted_output_override_method, global_file);
delete[] formatted_output_override_method;
break;
}
default:
GFXRECON_LOG_FATAL("Failed to print out global var: Invalid platform (%d)", platform_);
break;
}

PrintToFile(global_file, "%s;\n", GfxToCppVariable::GenerateStringVec(variable_data_));
Expand Down Expand Up @@ -1703,6 +1748,26 @@ void VulkanCppConsumerBase::GenerateSurfaceCreation(GfxToCppPlatform plat
surface_create_func_call = "vkCreateXcbSurfaceKHR";
break;
}
case GfxToCppPlatform::PLATFORM_WAYLAND:
{
VkWaylandSurfaceCreateInfoKHR wayland_struct_info = {};
Decoded_VkWaylandSurfaceCreateInfoKHR decoded_wayland_info = {};

if (platform_ == platform)
{
wayland_struct_info =
*reinterpret_cast<StructPointerDecoder<Decoded_VkWaylandSurfaceCreateInfoKHR>*>(pSurfaceCreateInfo)
->GetPointer();
}
wayland_struct_info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
create_info_struct_var_name = GenerateStruct_VkWaylandSurfaceCreateInfoKHR(
stream_create_info, &wayland_struct_info, &decoded_wayland_info, *this);
surface_create_func_call = "vkCreateWaylandSurfaceKHR";
break;
}
default:
GFXRECON_LOG_FATAL("Failed to generate surface creation: Invalid platform (%d)", platform_);
break;
}
fprintf(file, "\n%s", stream_create_info.str().c_str());
AddKnownVariables("VkSurfaceKHR", surface_var_name, pSurface);
Expand Down
9 changes: 6 additions & 3 deletions framework/decode/vulkan_cpp_loader_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ void VulkanCppLoaderGenerator::WriteOutLoaderGenerator(const std::string& outDir
case GfxToCppPlatform::PLATFORM_XCB:
fprintf(pfn_src_file, "#define VK_USE_PLATFORM_XCB_KHR\n");
break;
case GfxToCppPlatform::PLATFORM_WAYLAND:
fprintf(pfn_src_file, "#define VK_USE_PLATFORM_WAYLAND_KHR\n");
break;
#if 0
// TODO: implement these platforms
case GfxToCppPlatform::PLATFORM_MACOS:
fprintf(pfn_src_file, "#define VK_USE_PLATFORM_METAL_EXT\n");
break;
case GfxToCppPlatform::PLATFORM_WAYLAND:
fprintf(pfn_src_file, "#define VK_USE_PLATFORM_WAYLAND_KHR\n");
break;
case GfxToCppPlatform::PLATFORM_XLIB:
fprintf(pfn_src_file, "#define VK_USE_PLATFORM_XLIB_KHR\n");
break;
#endif
default:
GFXRECON_LOG_FATAL("Failed to write out loader generator: Invalid platform (%d)", platform);
break;
}

fprintf(pfn_src_file, "#include \"loader.h\"\n\n");
Expand Down
Loading

0 comments on commit 69a7108

Please sign in to comment.