Skip to content

Commit

Permalink
Add convenience methods. Add debugging names in toString().
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Dec 9, 2024
1 parent dbc6474 commit 329cc11
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ default Optional<VulkanQueueType> queue(
Objects.requireNonNull(queueFamily, "queueFamily");

final Predicate<VulkanQueueType> queueMatches =
(VulkanQueueType queue) -> {
(final VulkanQueueType queue) -> {
final var familyProperties =
queue.queueFamilyProperties();
final var familyMatches =
Expand Down Expand Up @@ -603,6 +603,24 @@ VulkanSemaphoreBinaryType createBinarySemaphore(
VulkanSemaphoreBinaryCreateInfo info)
throws VulkanException;

/**
* Create a binary semaphore.
*
* @return A semaphore
*
* @throws VulkanException On errors
*/

@VulkanAPIFunctionType(vulkanFunction = "vkCreateSemaphore")
default VulkanSemaphoreBinaryType createBinarySemaphore()
throws VulkanException
{
return this.createBinarySemaphore(
VulkanSemaphoreBinaryCreateInfo.builder()
.build()
);
}

/**
* Create a timeline semaphore.
*
Expand All @@ -618,10 +636,32 @@ VulkanSemaphoreTimelineType createTimelineSemaphore(
VulkanSemaphoreTimelineCreateInfo info)
throws VulkanException;

/**
* Create a timeline semaphore.
*
* @param initialValue The semaphore initial value
*
* @return A semaphore
*
* @throws VulkanException On errors
*/

@VulkanAPIFunctionType(vulkanFunction = "vkCreateSemaphore")
default VulkanSemaphoreTimelineType createTimelineSemaphore(
final long initialValue)
throws VulkanException
{
return this.createTimelineSemaphore(
VulkanSemaphoreTimelineCreateInfo.builder()
.setInitialValue(initialValue)
.build()
);
}

/**
* Create a fence.
*
* @param create_info The fence creation info
* @param createInfo The fence creation info
*
* @return A fence
*
Expand All @@ -630,9 +670,27 @@ VulkanSemaphoreTimelineType createTimelineSemaphore(

@VulkanAPIFunctionType(vulkanFunction = "vkCreateFence")
VulkanFenceType createFence(
VulkanFenceCreateInfo create_info)
VulkanFenceCreateInfo createInfo)
throws VulkanException;

/**
* Create a fence.
*
* @return A fence
*
* @throws VulkanException On errors
*/

@VulkanAPIFunctionType(vulkanFunction = "vkCreateFence")
default VulkanFenceType createFence()
throws VulkanException
{
return this.createFence(
VulkanFenceCreateInfo.builder()
.build()
);
}

/**
* Create an event.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,40 @@
public record VulkanQueueFamilyIndex(int value)
implements Comparable<VulkanQueueFamilyIndex>
{
private static final VulkanQueueFamilyIndex IGNORED =
new VulkanQueueFamilyIndex(-1);

private static final VulkanQueueFamilyIndex EXTERNAL =
new VulkanQueueFamilyIndex(-2);

/**
* @return The special queue family index that indicates that a queue family
* parameter or member is ignored.
*
* @see "VK_QUEUE_FAMILY_IGNORED"
*/

public static VulkanQueueFamilyIndex ignored()
{
return IGNORED;
}

/**
* @return The special queue family index that represents any queue external
* to the resource's current Vulkan instance.
*
* @see "VK_QUEUE_FAMILY_EXTERNAL"
*/

public static VulkanQueueFamilyIndex external()
{
return EXTERNAL;
}

@Override
public int compareTo(
final VulkanQueueFamilyIndex other)
{
return Integer.compareUnsigned(this.value, other.value);
return Integer.compare(this.value, other.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public VulkanSemaphoreTimelineType createTimelineSemaphore(

@Override
public VulkanFenceType createFence(
final VulkanFenceCreateInfo create_info)
final VulkanFenceCreateInfo createInfo)
throws VulkanException
{
throw errorNotImplemented("createFence");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ public void setObjectName(
checkInstanceOf(device, VulkanLWJGLLogicalDevice.class);

if (info.objectHandle() instanceof final VulkanLWJGLHandle handle) {
handle.setName(info.objectName());

final var handleTypeOpt =
objectTypeOfHandleInt(handle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.slf4j.Logger;

import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;

sealed abstract class VulkanLWJGLHandle
implements VulkanHandleType
Expand Down Expand Up @@ -59,6 +60,7 @@ sealed abstract class VulkanLWJGLHandle
private final Ownership ownership;
private final VulkanLWJGLHostAllocatorProxy host_allocator_proxy;
private final long handle;
private final AtomicReference<String> name;
private boolean closed;

VulkanLWJGLHandle(
Expand All @@ -75,6 +77,7 @@ sealed abstract class VulkanLWJGLHandle
"in_host_allocator_proxy"
);
this.handle = inHandle;
this.name = new AtomicReference<>("");
}

/**
Expand Down Expand Up @@ -139,9 +142,10 @@ public final int hashCode()
public final String toString()
{
return String.format(
"[%s 0x%s]",
"[%s 0x%s ('%s')]",
this.getClass().getSimpleName(),
Long.toUnsignedString(this.handle, 16)
Long.toUnsignedString(this.handle, 16),
this.name.get()
);
}

Expand All @@ -167,6 +171,18 @@ protected final void checkNotClosed()

protected abstract void closeActual();

/**
* Set the object name for debugging.
*
* @param inName The name
*/

public void setName(
final String inName)
{
this.name.set(Objects.requireNonNullElse(inName, ""));
}

/**
* The ownership status of the object.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,10 +1103,10 @@ public VulkanSemaphoreTimelineType createTimelineSemaphore(

@Override
public VulkanFenceType createFence(
final VulkanFenceCreateInfo create_info)
final VulkanFenceCreateInfo createInfo)
throws VulkanException
{
Objects.requireNonNull(create_info, "create_info");
Objects.requireNonNull(createInfo, "create_info");

this.checkNotClosed();

Expand All @@ -1116,7 +1116,7 @@ public VulkanFenceType createFence(
VulkanChecks.checkReturnCode(
VK10.vkCreateFence(
this.device,
VulkanLWJGLFenceCreateInfos.pack(stack, create_info),
VulkanLWJGLFenceCreateInfos.pack(stack, createInfo),
proxy.callbackBuffer(),
fences),
"vkCreateFence");
Expand Down

0 comments on commit 329cc11

Please sign in to comment.