Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/src/main/cpp/winlator/vk/vk_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,8 @@ VkTexture* vkr_texture_import_ahb(VkRenderer* r, AHardwareBuffer* ahb, bool tran
if (t->ycbcr != VK_NULL_HANDLE) {
vi.components = format_props.samplerYcbcrConversionComponents;
} else {
// fixes devices that supports vulkan bgra8 format, but doesn't support bgra8 ahb images
bool swizzle_rb = format_props.format == VK_FORMAT_R8G8B8A8_UNORM
&& r->caps.upload_format == VK_FORMAT_B8G8R8A8_UNORM;
&& desc.format == HAL_PIXEL_FORMAT_BGRA_8888;
vi.components.r = swizzle_rb ? VK_COMPONENT_SWIZZLE_B : VK_COMPONENT_SWIZZLE_IDENTITY;
vi.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
vi.components.b = swizzle_rb ? VK_COMPONENT_SWIZZLE_R : VK_COMPONENT_SWIZZLE_IDENTITY;
Expand Down
59 changes: 35 additions & 24 deletions app/src/main/cpp/winlator/vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ PFN_vkDestroyInstance destroyInstance;

static void *vulkan_handle = NULL;

static void destroy_probe_instance(void) {
if (instance != VK_NULL_HANDLE) {
PFN_vkDestroyInstance destroy = destroyInstance;
if (destroy == NULL && vulkan_handle != NULL) {
destroy = (PFN_vkDestroyInstance)dlsym(vulkan_handle, "vkDestroyInstance");
}
if (destroy != NULL) destroy(instance, NULL);
}
instance = VK_NULL_HANDLE;
physicalDevice = VK_NULL_HANDLE;
getPhysicalDeviceProperties = NULL;
enumerateDeviceExtensionProperties = NULL;
enumeratePhysicalDevices = NULL;
destroyInstance = NULL;
if (vulkan_handle) {
dlclose(vulkan_handle);
vulkan_handle = NULL;
}
}

static char *get_native_library_dir(JNIEnv *env, jobject context) {
char *native_libdir = NULL;

Expand Down Expand Up @@ -363,11 +383,13 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_getVulkanVersionNative(

if (create_instance(driverName, env, context) != VK_SUCCESS) {
printf("Failed to create instance");
destroy_probe_instance();
return (*env)->NewStringUTF(env, "Unknown");
}

if (enumerate_physical_devices() != VK_SUCCESS) {
printf("Failed to query physical devices");
destroy_probe_instance();
return (*env)->NewStringUTF(env, "Unknown");
}

Expand All @@ -381,12 +403,7 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_getVulkanVersionNative(
jstring result = (*env)->NewStringUTF(env, driverVersion);
free(driverVersion);

destroyInstance(instance, NULL);

if (vulkan_handle) {
dlclose(vulkan_handle);
vulkan_handle = NULL;
}
destroy_probe_instance();

return result;
}
Expand All @@ -399,23 +416,20 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_getVendorIDNative(

if (create_instance(driverName, env, context) != VK_SUCCESS) {
printf("Failed to create instance");
destroy_probe_instance();
return 0;
}

if (enumerate_physical_devices() != VK_SUCCESS) {
printf("Failed to query physical devices");
destroy_probe_instance();
return 0;
}

getPhysicalDeviceProperties(physicalDevice, &props);
vendorID = props.vendorID;

destroyInstance(instance, NULL);

if (vulkan_handle) {
dlclose(vulkan_handle);
vulkan_handle = NULL;
}
destroy_probe_instance();

return vendorID;
}
Expand All @@ -427,23 +441,20 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_getRendererNative(

if (create_instance(driverName, env, context) != VK_SUCCESS) {
printf("Failed to create instance");
destroy_probe_instance();
return (*env)->NewStringUTF(env, "Unknown");
}

if (enumerate_physical_devices() != VK_SUCCESS) {
printf("Failed to query physical devices");
destroy_probe_instance();
return (*env)->NewStringUTF(env, "Unknown");
}

getPhysicalDeviceProperties(physicalDevice, &props);
jstring result = (*env)->NewStringUTF(env, props.deviceName);

destroyInstance(instance, NULL);

if (vulkan_handle) {
dlclose(vulkan_handle);
vulkan_handle = NULL;
}
destroy_probe_instance();

return result;
}
Expand All @@ -458,11 +469,13 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_enumerateExtensionsNative(

if (create_instance(driverName, env, context) != VK_SUCCESS) {
printf("Failed to create instance");
destroy_probe_instance();
return (*env)->NewObjectArray(env, 0, stringClass, NULL);
}

if (enumerate_physical_devices() != VK_SUCCESS) {
printf("Failed to query physical devices");
destroy_probe_instance();
return (*env)->NewObjectArray(env, 0, stringClass, NULL);
}

Expand All @@ -471,13 +484,15 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_enumerateExtensionsNative(

if (result != VK_SUCCESS || extensionCount < 1) {
printf("Failed to query extension count");
destroy_probe_instance();
return (*env)->NewObjectArray(env, 0, stringClass, NULL);
}

VkExtensionProperties *extensionProperties =
malloc(sizeof(VkExtensionProperties) * extensionCount);
if (!extensionProperties) {
printf("Failed to allocate extension properties");
destroy_probe_instance();
return (*env)->NewObjectArray(env, 0, stringClass, NULL);
}

Expand All @@ -487,6 +502,7 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_enumerateExtensionsNative(
if (result != VK_SUCCESS) {
printf("Failed to query extensions (result=%d)", result);
free(extensionProperties);
destroy_probe_instance();
return (*env)->NewObjectArray(env, 0, stringClass, NULL);
}

Expand All @@ -501,12 +517,7 @@ Java_com_winlator_cmod_runtime_system_GPUInformation_enumerateExtensionsNative(

free(extensionProperties);

destroyInstance(instance, NULL);

if (vulkan_handle) {
dlclose(vulkan_handle);
vulkan_handle = NULL;
}
destroy_probe_instance();

return extensions;
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,7 @@ Installed path:
<string name="preloader_launching">Launching</string>
<string name="preloader_closing">Closing %1$s</string>
<string name="preloader_preparing_steam_environment">Preparing Steam environment</string>
<string name="preloader_launch_failed">Launch failed: %1$s</string>
<string name="preloader_starting_wine">Starting Wine</string>
<string name="preloader_starting_steam_launcher">Starting Steam Launcher</string>
<string name="preloader_loading_steam_client">Loading Steam client</string>
Expand Down
Loading
Loading