org.lwjgl.vulkan.VkMemoryAllocateInfo Maven / Gradle / Ivy
Show all versions of lwjgl-vulkan Show documentation
/*
* Copyright LWJGL. All rights reserved.
* License terms: https://www.lwjgl.org/license
* MACHINE GENERATED FILE, DO NOT EDIT
*/
package org.lwjgl.vulkan;
import java.nio.*;
import org.lwjgl.*;
import org.lwjgl.system.*;
import static org.lwjgl.system.MemoryUtil.*;
import static org.lwjgl.system.MemoryStack.*;
/**
* Structure containing parameters of a memory allocation.
*
* Description
*
* If the {@code pNext} chain contains an instance of {@link VkImportMemoryWin32HandleInfoKHR} with a non-zero value for {@link VkImportMemoryWin32HandleInfoKHR}{@code ::handleType}, or {@link VkImportMemoryFdInfoKHR} with a non-zero value for {@link VkImportMemoryFdInfoKHR}{@code ::handleType}, the {@link VkMemoryAllocateInfo} instance defines a memory import operation. Importing memory must not modify the content of the memory. Implementations must ensure that importing memory does not enable the importing Vulkan instance to access any memory or resources in other Vulkan instances other than that corresponding to the memory object imported. Implementations must also ensure accessing imported memory which has not been initialized does not allow the importing Vulkan instance to obtain data from the exporting Vulkan instance or vice-versa.
*
* Note
*
* How exported and imported memory is isolated is left to the implementation, but applications should be aware that such isolation may prevent implementations from placing multiple exportable memory objects in the same physical or virtual page. Hence, applications should avoid creating many small external memory objects whenever possible.
*
*
* When performing a memory import operation, it is the responsibility of the application to ensure the external handles meet all valid usage requirements. However, implementations must perform sufficient validation of external handles to ensure that the operation results in a valid memory object which will not cause program termination, device loss, queue stalls, or corruption of other resources when used as allowed according to its allocation parameters. If the external handle provided does not meet these requirements, the implementation must fail the memory import operation with the error code {@link KHRExternalMemory#VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR ERROR_INVALID_EXTERNAL_HANDLE_KHR}.
*
* Valid Usage
*
*
* - {@code allocationSize} must be less than or equal to the amount of memory available to the {@link VkMemoryHeap} specified by {@code memoryTypeIndex} and the calling command’s {@code VkDevice}
* - {@code allocationSize} must be greater than 0
* - If the {@code pNext} chain contains an instance of {@link VkExportMemoryAllocateInfoKHR}, and any of the handle types specified in {@link VkExportMemoryAllocateInfoKHR}{@code ::handleTypes} require a dedicated allocation, as reported by {@link KHRGetPhysicalDeviceProperties2#vkGetPhysicalDeviceImageFormatProperties2KHR GetPhysicalDeviceImageFormatProperties2KHR} in {@link VkExternalImageFormatPropertiesKHR}{@code ::externalMemoryProperties}{@code ::externalMemoryFeatures} or {@link VkExternalBufferPropertiesKHR}{@code ::externalMemoryProperties}{@code ::externalMemoryFeatures}, the {@code pNext} chain must contain an instance of {@link VkMemoryDedicatedAllocateInfoKHR} or {@link VkDedicatedAllocationMemoryAllocateInfoNV} with either its {@code image} or {@code buffer} field set to a value other than {@link VK10#VK_NULL_HANDLE NULL_HANDLE}.
* - If the {@code pNext} chain contains an instance of {@link VkExportMemoryAllocateInfoKHR}, it must not contain an instance of {@link VkExportMemoryAllocateInfoNV} or {@link VkExportMemoryWin32HandleInfoNV}.
* - If the {@code pNext} chain contains an instance of {@link VkImportMemoryWin32HandleInfoKHR}, it must not contain an instance of {@link VkImportMemoryWin32HandleInfoNV}.
* - If the parameters define an import operation and the external handle specified was created by the Vulkan API, the values of {@code allocationSize} and {@code memoryTypeIndex} must match those specified when the memory object being imported was created.
* - If the parameters define an import operation and the external handle specified was created by the Vulkan API, the device mask specified by {@link VkMemoryAllocateFlagsInfoKHX} must match that specified when the memory object being imported was allocated.
* - If the parameters define an import operation and the external handle specified was created by the Vulkan API, the list of physical devices that comprise the logical device passed to {@link VK10#vkAllocateMemory AllocateMemory} must match the list of physical devices that comprise the logical device on which the memory was originally allocated.
* - If the parameters define an import operation and the external handle is an NT handle or a global share handle created outside of the Vulkan API, the value of {@code memoryTypeIndex} must be one of those returned by {@link KHRExternalMemoryWin32#vkGetMemoryWin32HandlePropertiesKHR GetMemoryWin32HandlePropertiesKHR}.
* - If the parameters define an import operation and the external handle type is {@link KHRExternalMemoryCapabilities#VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT_KHR EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT_KHR}, {@link KHRExternalMemoryCapabilities#VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT_KHR EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_KMT_BIT_KHR}, or {@link KHRExternalMemoryCapabilities#VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT_KHR EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT_KHR}, {@code allocationSize} must match the size reported in the memory requirements of the {@code image} or {@code buffer} member of the instance of {@link VkDedicatedAllocationMemoryAllocateInfoNV} included in the {@code pNext} chain.
* - If the parameters define an import operation and the external handle type is {@link KHRExternalMemoryCapabilities#VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT_KHR EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT_KHR}, {@code allocationSize} must match the size specified when creating the Direct3D 12 heap from which the external handle was extracted.
* - If the parameters define an import operation and the external handle is a POSIX file descriptor created outside of the Vulkan API, the value of {@code memoryTypeIndex} must be one of those returned by {@link KHRExternalMemoryFd#vkGetMemoryFdPropertiesKHR GetMemoryFdPropertiesKHR}.
*
*
* Valid Usage (Implicit)
*
*
* - {@code sType} must be {@link VK10#VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}
* - Each {@code pNext} member of any structure (including this one) in the {@code pNext} chain must be either {@code NULL} or a pointer to a valid instance of {@link VkDedicatedAllocationMemoryAllocateInfoNV}, {@link VkExportMemoryAllocateInfoKHR}, {@link VkExportMemoryAllocateInfoNV}, {@link VkExportMemoryWin32HandleInfoKHR}, {@link VkExportMemoryWin32HandleInfoNV}, {@link VkImportMemoryFdInfoKHR}, {@link VkImportMemoryWin32HandleInfoKHR}, {@link VkImportMemoryWin32HandleInfoNV}, {@link VkMemoryAllocateFlagsInfoKHX}, or {@link VkMemoryDedicatedAllocateInfoKHR}
* - Each {@code sType} member in the {@code pNext} chain must be unique
*
*
* See Also
*
* {@link VK10#vkAllocateMemory AllocateMemory}
*
* Member documentation
*
*
* - {@code sType} – the type of this structure.
* - {@code pNext} – {@code NULL} or a pointer to an extension-specific structure.
* - {@code allocationSize} – the size of the allocation in bytes
* - {@code memoryTypeIndex} – the memory type index, which selects the properties of the memory to be allocated, as well as the heap the memory will come from.
*
*
* Layout
*
*
* struct VkMemoryAllocateInfo {
* VkStructureType sType;
* const void * pNext;
* VkDeviceSize allocationSize;
* uint32_t memoryTypeIndex;
* }
*/
public class VkMemoryAllocateInfo extends Struct implements NativeResource {
/** The struct size in bytes. */
public static final int SIZEOF;
public static final int ALIGNOF;
/** The struct member offsets. */
public static final int
STYPE,
PNEXT,
ALLOCATIONSIZE,
MEMORYTYPEINDEX;
static {
Layout layout = __struct(
__member(4),
__member(POINTER_SIZE),
__member(8),
__member(4)
);
SIZEOF = layout.getSize();
ALIGNOF = layout.getAlignment();
STYPE = layout.offsetof(0);
PNEXT = layout.offsetof(1);
ALLOCATIONSIZE = layout.offsetof(2);
MEMORYTYPEINDEX = layout.offsetof(3);
}
VkMemoryAllocateInfo(long address, ByteBuffer container) {
super(address, container);
}
/**
* Creates a {@link VkMemoryAllocateInfo} instance at the current position of the specified {@link ByteBuffer} container. Changes to the buffer's content will be
* visible to the struct instance and vice versa.
*
* The created instance holds a strong reference to the container object.
*/
public VkMemoryAllocateInfo(ByteBuffer container) {
this(memAddress(container), checkContainer(container, SIZEOF));
}
@Override
public int sizeof() { return SIZEOF; }
/** Returns the value of the {@code sType} field. */
@NativeType("VkStructureType")
public int sType() { return nsType(address()); }
/** Returns the value of the {@code pNext} field. */
@NativeType("const void *")
public long pNext() { return npNext(address()); }
/** Returns the value of the {@code allocationSize} field. */
@NativeType("VkDeviceSize")
public long allocationSize() { return nallocationSize(address()); }
/** Returns the value of the {@code memoryTypeIndex} field. */
@NativeType("uint32_t")
public int memoryTypeIndex() { return nmemoryTypeIndex(address()); }
/** Sets the specified value to the {@code sType} field. */
public VkMemoryAllocateInfo sType(@NativeType("VkStructureType") int value) { nsType(address(), value); return this; }
/** Sets the specified value to the {@code pNext} field. */
public VkMemoryAllocateInfo pNext(@NativeType("const void *") long value) { npNext(address(), value); return this; }
/** Sets the specified value to the {@code allocationSize} field. */
public VkMemoryAllocateInfo allocationSize(@NativeType("VkDeviceSize") long value) { nallocationSize(address(), value); return this; }
/** Sets the specified value to the {@code memoryTypeIndex} field. */
public VkMemoryAllocateInfo memoryTypeIndex(@NativeType("uint32_t") int value) { nmemoryTypeIndex(address(), value); return this; }
/** Initializes this struct with the specified values. */
public VkMemoryAllocateInfo set(
int sType,
long pNext,
long allocationSize,
int memoryTypeIndex
) {
sType(sType);
pNext(pNext);
allocationSize(allocationSize);
memoryTypeIndex(memoryTypeIndex);
return this;
}
/**
* Copies the specified struct data to this struct.
*
* @param src the source struct
*
* @return this struct
*/
public VkMemoryAllocateInfo set(VkMemoryAllocateInfo src) {
memCopy(src.address(), address(), SIZEOF);
return this;
}
// -----------------------------------
/** Returns a new {@link VkMemoryAllocateInfo} instance allocated with {@link MemoryUtil#memAlloc memAlloc}. The instance must be explicitly freed. */
public static VkMemoryAllocateInfo malloc() {
return create(nmemAlloc(SIZEOF));
}
/** Returns a new {@link VkMemoryAllocateInfo} instance allocated with {@link MemoryUtil#memCalloc memCalloc}. The instance must be explicitly freed. */
public static VkMemoryAllocateInfo calloc() {
return create(nmemCalloc(1, SIZEOF));
}
/** Returns a new {@link VkMemoryAllocateInfo} instance allocated with {@link BufferUtils}. */
public static VkMemoryAllocateInfo create() {
return new VkMemoryAllocateInfo(BufferUtils.createByteBuffer(SIZEOF));
}
/** Returns a new {@link VkMemoryAllocateInfo} instance for the specified memory address or {@code null} if the address is {@code NULL}. */
public static VkMemoryAllocateInfo create(long address) {
return address == NULL ? null : new VkMemoryAllocateInfo(address, null);
}
/**
* Returns a new {@link VkMemoryAllocateInfo.Buffer} instance allocated with {@link MemoryUtil#memAlloc memAlloc}. The instance must be explicitly freed.
*
* @param capacity the buffer capacity
*/
public static Buffer malloc(int capacity) {
return create(__malloc(capacity, SIZEOF), capacity);
}
/**
* Returns a new {@link VkMemoryAllocateInfo.Buffer} instance allocated with {@link MemoryUtil#memCalloc memCalloc}. The instance must be explicitly freed.
*
* @param capacity the buffer capacity
*/
public static Buffer calloc(int capacity) {
return create(nmemCalloc(capacity, SIZEOF), capacity);
}
/**
* Returns a new {@link VkMemoryAllocateInfo.Buffer} instance allocated with {@link BufferUtils}.
*
* @param capacity the buffer capacity
*/
public static Buffer create(int capacity) {
return new Buffer(__create(capacity, SIZEOF));
}
/**
* Create a {@link VkMemoryAllocateInfo.Buffer} instance at the specified memory.
*
* @param address the memory address
* @param capacity the buffer capacity
*/
public static Buffer create(long address, int capacity) {
return address == NULL ? null : new Buffer(address, null, -1, 0, capacity, capacity);
}
// -----------------------------------
/** Returns a new {@link VkMemoryAllocateInfo} instance allocated on the thread-local {@link MemoryStack}. */
public static VkMemoryAllocateInfo mallocStack() {
return mallocStack(stackGet());
}
/** Returns a new {@link VkMemoryAllocateInfo} instance allocated on the thread-local {@link MemoryStack} and initializes all its bits to zero. */
public static VkMemoryAllocateInfo callocStack() {
return callocStack(stackGet());
}
/**
* Returns a new {@link VkMemoryAllocateInfo} instance allocated on the specified {@link MemoryStack}.
*
* @param stack the stack from which to allocate
*/
public static VkMemoryAllocateInfo mallocStack(MemoryStack stack) {
return create(stack.nmalloc(ALIGNOF, SIZEOF));
}
/**
* Returns a new {@link VkMemoryAllocateInfo} instance allocated on the specified {@link MemoryStack} and initializes all its bits to zero.
*
* @param stack the stack from which to allocate
*/
public static VkMemoryAllocateInfo callocStack(MemoryStack stack) {
return create(stack.ncalloc(ALIGNOF, 1, SIZEOF));
}
/**
* Returns a new {@link VkMemoryAllocateInfo.Buffer} instance allocated on the thread-local {@link MemoryStack}.
*
* @param capacity the buffer capacity
*/
public static Buffer mallocStack(int capacity) {
return mallocStack(capacity, stackGet());
}
/**
* Returns a new {@link VkMemoryAllocateInfo.Buffer} instance allocated on the thread-local {@link MemoryStack} and initializes all its bits to zero.
*
* @param capacity the buffer capacity
*/
public static Buffer callocStack(int capacity) {
return callocStack(capacity, stackGet());
}
/**
* Returns a new {@link VkMemoryAllocateInfo.Buffer} instance allocated on the specified {@link MemoryStack}.
*
* @param stack the stack from which to allocate
* @param capacity the buffer capacity
*/
public static Buffer mallocStack(int capacity, MemoryStack stack) {
return create(stack.nmalloc(ALIGNOF, capacity * SIZEOF), capacity);
}
/**
* Returns a new {@link VkMemoryAllocateInfo.Buffer} instance allocated on the specified {@link MemoryStack} and initializes all its bits to zero.
*
* @param stack the stack from which to allocate
* @param capacity the buffer capacity
*/
public static Buffer callocStack(int capacity, MemoryStack stack) {
return create(stack.ncalloc(ALIGNOF, capacity, SIZEOF), capacity);
}
// -----------------------------------
/** Unsafe version of {@link #sType}. */
public static int nsType(long struct) { return memGetInt(struct + VkMemoryAllocateInfo.STYPE); }
/** Unsafe version of {@link #pNext}. */
public static long npNext(long struct) { return memGetAddress(struct + VkMemoryAllocateInfo.PNEXT); }
/** Unsafe version of {@link #allocationSize}. */
public static long nallocationSize(long struct) { return memGetLong(struct + VkMemoryAllocateInfo.ALLOCATIONSIZE); }
/** Unsafe version of {@link #memoryTypeIndex}. */
public static int nmemoryTypeIndex(long struct) { return memGetInt(struct + VkMemoryAllocateInfo.MEMORYTYPEINDEX); }
/** Unsafe version of {@link #sType(int) sType}. */
public static void nsType(long struct, int value) { memPutInt(struct + VkMemoryAllocateInfo.STYPE, value); }
/** Unsafe version of {@link #pNext(long) pNext}. */
public static void npNext(long struct, long value) { memPutAddress(struct + VkMemoryAllocateInfo.PNEXT, value); }
/** Unsafe version of {@link #allocationSize(long) allocationSize}. */
public static void nallocationSize(long struct, long value) { memPutLong(struct + VkMemoryAllocateInfo.ALLOCATIONSIZE, value); }
/** Unsafe version of {@link #memoryTypeIndex(int) memoryTypeIndex}. */
public static void nmemoryTypeIndex(long struct, int value) { memPutInt(struct + VkMemoryAllocateInfo.MEMORYTYPEINDEX, value); }
// -----------------------------------
/** An array of {@link VkMemoryAllocateInfo} structs. */
public static class Buffer extends StructBuffer implements NativeResource {
/**
* Creates a new {@link VkMemoryAllocateInfo.Buffer} instance backed by the specified container.
*
* Changes to the container's content will be visible to the struct buffer instance and vice versa. The two buffers' position, limit, and mark values
* will be independent. The new buffer's position will be zero, its capacity and its limit will be the number of bytes remaining in this buffer divided
* by {@link VkMemoryAllocateInfo#SIZEOF}, and its mark will be undefined.
*
* The created buffer instance holds a strong reference to the container object.
*/
public Buffer(ByteBuffer container) {
super(container, container.remaining() / SIZEOF);
}
Buffer(long address, ByteBuffer container, int mark, int pos, int lim, int cap) {
super(address, container, mark, pos, lim, cap);
}
@Override
protected Buffer self() {
return this;
}
@Override
protected Buffer newBufferInstance(long address, ByteBuffer container, int mark, int pos, int lim, int cap) {
return new Buffer(address, container, mark, pos, lim, cap);
}
@Override
protected VkMemoryAllocateInfo newInstance(long address) {
return new VkMemoryAllocateInfo(address, container);
}
@Override
public int sizeof() {
return SIZEOF;
}
/** Returns the value of the {@code sType} field. */
@NativeType("VkStructureType")
public int sType() { return VkMemoryAllocateInfo.nsType(address()); }
/** Returns the value of the {@code pNext} field. */
@NativeType("const void *")
public long pNext() { return VkMemoryAllocateInfo.npNext(address()); }
/** Returns the value of the {@code allocationSize} field. */
@NativeType("VkDeviceSize")
public long allocationSize() { return VkMemoryAllocateInfo.nallocationSize(address()); }
/** Returns the value of the {@code memoryTypeIndex} field. */
@NativeType("uint32_t")
public int memoryTypeIndex() { return VkMemoryAllocateInfo.nmemoryTypeIndex(address()); }
/** Sets the specified value to the {@code sType} field. */
public VkMemoryAllocateInfo.Buffer sType(@NativeType("VkStructureType") int value) { VkMemoryAllocateInfo.nsType(address(), value); return this; }
/** Sets the specified value to the {@code pNext} field. */
public VkMemoryAllocateInfo.Buffer pNext(@NativeType("const void *") long value) { VkMemoryAllocateInfo.npNext(address(), value); return this; }
/** Sets the specified value to the {@code allocationSize} field. */
public VkMemoryAllocateInfo.Buffer allocationSize(@NativeType("VkDeviceSize") long value) { VkMemoryAllocateInfo.nallocationSize(address(), value); return this; }
/** Sets the specified value to the {@code memoryTypeIndex} field. */
public VkMemoryAllocateInfo.Buffer memoryTypeIndex(@NativeType("uint32_t") int value) { VkMemoryAllocateInfo.nmemoryTypeIndex(address(), value); return this; }
}
}