Skip to content

Commit

Permalink
Drop support for < Vulkan 1.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Dec 4, 2024
1 parent e128ee4 commit e88dd13
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 105 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright © 2018 Mark Raynsford <[email protected]> http://io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

package com.io7m.jcoronado.api;

import java.util.Objects;
import java.util.Optional;

/**
* An exception raised by the Vulkan version not being supported.
*/

public final class VulkanMissingRequiredVersionException
extends VulkanException
{
private final VulkanVersion requested;
private final VulkanVersion required;
private final Optional<VulkanVersion> supported;

/**
* An exception raised by the Vulkan version not being supported.
*
* @param inRequested The requested version
* @param inRequired The required version
* @param inSupported The supported version
*/

public VulkanMissingRequiredVersionException(
final VulkanVersion inRequested,
final VulkanVersion inRequired,
final Optional<VulkanVersion> inSupported)
{
super(
"The required Vulkan version (%s) is not supported (%s is supported, %s was requested)."
.formatted(
inRequired.toHumanString(),
inSupported.map(VulkanVersionType::toHumanString)
.orElse("<unavailable>"),
inRequested.toHumanString())
);

this.requested =
Objects.requireNonNull(inRequested, "inRequested");
this.required =
Objects.requireNonNull(inRequired, "inRequired");
this.supported =
Objects.requireNonNull(inSupported, "inSupported");
}

/**
* @return The requested version
*/

public VulkanVersion requested()
{
return this.requested;
}

/**
* @return The required version
*/

public VulkanVersion required()
{
return this.required;
}

/**
* @return The supported version
*/

public Optional<VulkanVersion> supported()
{
return this.supported;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.io7m.jcoronado.api.VulkanInstanceProviderType;
import com.io7m.jcoronado.api.VulkanInstanceType;
import com.io7m.jcoronado.api.VulkanLayerProperties;
import com.io7m.jcoronado.api.VulkanMissingRequiredVersionException;
import com.io7m.jcoronado.api.VulkanVersion;
import com.io7m.jcoronado.api.VulkanVersions;
import com.io7m.jcoronado.lwjgl.internal.VulkanLWJGLExtensionsRegistry;
Expand Down Expand Up @@ -61,6 +62,9 @@ public final class VulkanLWJGLInstanceProvider
private static final Logger LOG =
LoggerFactory.getLogger(VulkanLWJGLInstanceProvider.class);

private static final VulkanVersion VULKAN_13 =
VulkanVersion.of(1, 3, 0);

private final MemoryStack initialStack;
private final VulkanLWJGLExtensionsRegistry extensions;

Expand Down Expand Up @@ -218,10 +222,28 @@ public VulkanInstanceType createInstance(
final var enabledExtensions =
info.enabledExtensions();

final var requestedVersion =
VulkanVersions.decode(info.applicationInfo().vulkanAPIVersion());

if (LOG.isDebugEnabled()) {
LOG.debug("Requested Vulkan version: {}", requestedVersion);
LOG.debug("Required Vulkan version: {}", VULKAN_13);
}

/*
* We require Vulkan 1.3+ as various extensions such as
* VK_KHR_synchronization2 were moved to core.
*/

if (requestedVersion.compareTo(VULKAN_13) < 0) {
throw new VulkanMissingRequiredVersionException(
requestedVersion,
VULKAN_13,
Optional.empty()
);
}

if (LOG.isDebugEnabled()) {
final var apiVersion =
VulkanVersions.decode(info.applicationInfo().vulkanAPIVersion());
LOG.debug("Creating instance for API {}", apiVersion.toHumanString());
enabledLayers
.forEach(layer -> LOG.debug("Enabling layer: {}", layer));
enabledExtensions
Expand Down Expand Up @@ -288,6 +310,19 @@ public VulkanInstanceType createInstance(
final var enabled =
this.extensions.ofNames(info.enabledExtensions());

final var supported =
this.findSupportedInstanceVersion();

if (supported.compareTo(requestedVersion) < 0) {
VK10.vkDestroyInstance(instance, allocatorProxy.callbackBuffer());

throw new VulkanMissingRequiredVersionException(
requestedVersion,
VULKAN_13,
Optional.of(supported)
);
}

return new VulkanLWJGLInstance(
instance,
this.extensions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,50 +762,8 @@ private static VulkanLineWidthRange parseLineWidthRange(

private static VulkanPhysicalDeviceFeatures parseAllFeatures(
final MemoryStack stack,
final VkPhysicalDevice vkDevice,
final VulkanVersion requestedApiVersion)
final VkPhysicalDevice vkDevice)
{
/*
* For Vulkan 1.0, we need to call the plain vkGetPhysicalDeviceFeatures
* function.
*/

if (requestedApiVersion.major() == 1 && requestedApiVersion.minor() == 0) {
LOG.debug(
"Requested API version is {}; physical device features retrieved using vkGetPhysicalDeviceFeatures",
requestedApiVersion.toHumanString()
);

final var vkFeatures =
VkPhysicalDeviceFeatures.calloc(stack);

VK10.vkGetPhysicalDeviceFeatures(vkDevice, vkFeatures);

final var features10 =
parsePhysicalDeviceFeatures10(vkFeatures);
final var features11 =
VulkanPhysicalDeviceFeatures11.builder()
.build();
final var features12 =
VulkanPhysicalDeviceFeatures12.builder()
.build();
final var features13 =
VulkanPhysicalDeviceFeatures13.builder()
.build();

return VulkanPhysicalDeviceFeatures.builder()
.setFeatures10(features10)
.setFeatures11(features11)
.setFeatures12(features12)
.setFeatures13(features13)
.build();
}

/*
* For newer versions of Vulkan, we call vkGetPhysicalDeviceFeatures2
* and fetch all the new embedded structures.
*/

final var vkFeatures13 =
VkPhysicalDeviceVulkan13Features.calloc(stack);
vkFeatures13.sType(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_3_FEATURES);
Expand All @@ -826,11 +784,6 @@ private static VulkanPhysicalDeviceFeatures parseAllFeatures(
vkFeatures11.pNext(vkFeatures12.address());
vkFeatures.pNext(vkFeatures11.address());

LOG.debug(
"Requested API version is {}; physical device features retrieved using vkGetPhysicalDeviceFeatures2",
requestedApiVersion.toHumanString()
);

VK11.vkGetPhysicalDeviceFeatures2(vkDevice, vkFeatures);

final var features10 =
Expand Down Expand Up @@ -1127,8 +1080,7 @@ private VulkanLWJGLPhysicalDevice parsePhysicalDevice(
final var features =
parseAllFeatures(
stack,
vkDevice,
apiVersion
vkDevice
);

VK10.vkGetPhysicalDeviceMemoryProperties(vkDevice, vkMemory);
Expand Down Expand Up @@ -1160,38 +1112,6 @@ private static PropertiesAndExtras parseAllProperties(
final int index,
final VulkanVersion apiVersion)
{
/*
* For Vulkan 1.0, we need to call the plain vkGetPhysicalDeviceProperties
* function.
*/

if (apiVersion.major() == 1 && apiVersion.minor() == 0) {
LOG.debug(
"Requested API version is {}; physical device properties retrieved using vkGetPhysicalDeviceProperties",
apiVersion.toHumanString()
);

final var vkProperties =
VkPhysicalDeviceProperties.malloc(stack);

VK10.vkGetPhysicalDeviceProperties(vkDevice, vkProperties);
return new PropertiesAndExtras(
parsePhysicalDeviceProperties(vkProperties, index),
Optional.empty(),
Optional.empty()
);
}

/*
* For newer versions of Vulkan, we call vkGetPhysicalDeviceProperties2
* and fetch all the new embedded structures.
*/

LOG.debug(
"Requested API version is {}; physical device properties retrieved using vkGetPhysicalDeviceProperties2",
apiVersion.toHumanString()
);

final var vkIdProperties =
VkPhysicalDeviceIDProperties.malloc(stack);
vkIdProperties.sType(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.io7m.jcoronado.api.VulkanException;
import com.io7m.jcoronado.api.VulkanInstanceCreateInfo;
import com.io7m.jcoronado.api.VulkanInstanceProviderType;
import com.io7m.jcoronado.api.VulkanMissingRequiredVersionException;
import com.io7m.jcoronado.api.VulkanVersions;
import com.io7m.jcoronado.extensions.ext_layer_settings.api.VulkanLayerSettingBoolean;
import com.io7m.jcoronado.extensions.ext_layer_settings.api.VulkanLayerSettingIntegerSigned32;
Expand All @@ -36,6 +37,7 @@
import java.util.Optional;

import static java.lang.Boolean.TRUE;
import static org.junit.jupiter.api.Assertions.assertThrows;

public abstract class VulkanInstanceContract extends VulkanOnDeviceContract
{
Expand Down Expand Up @@ -63,11 +65,9 @@ public final void testInstanceVulkan10()
.setEnabledLayers(List.of("VK_LAYER_KHRONOS_validation"))
.build();

try (var instance =
provider.createInstance(info, Optional.empty())) {
instance.enabledExtensions().forEach(
(name, extension) -> logger.debug("extension: {}", extension.name()));
}
assertThrows(VulkanMissingRequiredVersionException.class, () -> {
provider.createInstance(info, Optional.empty());
});
}

@Test
Expand Down Expand Up @@ -116,7 +116,7 @@ public final void testInstancePhysicalDevices10()
VulkanVersions.encode(0, 0, 1),
"com.io7m.jcoronado.tests",
VulkanVersions.encode(0, 0, 1),
VulkanVersions.encode(1, 0, 0)))
VulkanVersions.encode(1, 3, 0)))
.setEnabledExtensions(List.of())
.setEnabledLayers(List.of("VK_LAYER_KHRONOS_validation"))
.build();
Expand Down Expand Up @@ -188,7 +188,7 @@ public final void testInstanceValidationLayerSettings0()
VulkanVersions.encode(0, 0, 1),
"com.io7m.jcoronado.tests",
VulkanVersions.encode(0, 0, 1),
VulkanVersions.encode(1, 0, 0)))
VulkanVersions.encode(1, 3, 0)))
.setEnabledExtensions(List.of())
.setEnabledLayers(List.of("VK_LAYER_KHRONOS_validation"))
.addExtensionInfo(
Expand Down Expand Up @@ -237,7 +237,7 @@ public final void testInstanceValidationLayerSettings1()
VulkanVersions.encode(0, 0, 1),
"com.io7m.jcoronado.tests",
VulkanVersions.encode(0, 0, 1),
VulkanVersions.encode(1, 0, 0)))
VulkanVersions.encode(1, 3, 0)))
.setEnabledExtensions(List.of())
.setEnabledLayers(List.of("VK_LAYER_KHRONOS_validation"))
.addExtensionInfo(
Expand Down Expand Up @@ -286,7 +286,7 @@ public final void testInstanceValidationLayerSettings2()
VulkanVersions.encode(0, 0, 1),
"com.io7m.jcoronado.tests",
VulkanVersions.encode(0, 0, 1),
VulkanVersions.encode(1, 0, 0)))
VulkanVersions.encode(1, 3, 0)))
.setEnabledExtensions(List.of())
.setEnabledLayers(List.of("VK_LAYER_KHRONOS_validation"))
.addExtensionInfo(
Expand Down Expand Up @@ -335,7 +335,7 @@ public final void testInstanceValidationLayerSettings3()
VulkanVersions.encode(0, 0, 1),
"com.io7m.jcoronado.tests",
VulkanVersions.encode(0, 0, 1),
VulkanVersions.encode(1, 0, 0)))
VulkanVersions.encode(1, 3, 0)))
.setEnabledExtensions(List.of())
.setEnabledLayers(List.of("VK_LAYER_KHRONOS_validation"))
.addExtensionInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ private VulkanInstanceInfo()

public static VulkanInstanceCreateInfo info()
{
final var applicationInfo =
VulkanApplicationInfo.builder()
.setVulkanAPIVersion(
VulkanVersions.encode(1, 3, 0))
.setApplicationVersion(
VulkanVersions.encode(0, 0, 1))
.setEngineVersion(
VulkanVersions.encode(0, 0, 1))
.setEngineName("com.io7m.jcoronado")
.setApplicationName("com.io7m.jcoronado.tests.Test")
.build();

return VulkanInstanceCreateInfo.builder()
.setApplicationInfo(
VulkanApplicationInfo.of(
"com.io7m.jcoronado.tests.Test",
VulkanVersions.encode(0, 0, 1),
"com.io7m.jcoronado.tests",
VulkanVersions.encode(0, 0, 1),
VulkanVersions.encode(1, 0, 0)))
.setApplicationInfo(applicationInfo)
.setEnabledExtensions(List.of())
.setEnabledLayers(List.of("VK_LAYER_KHRONOS_validation"))
.build();
Expand Down
Loading

0 comments on commit e88dd13

Please sign in to comment.