├── .gitignore ├── LICENSE.md ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main └── java └── com └── justindriggers ├── glfw ├── GLFWInstance.java └── GLFWSurface.java ├── utilities └── StringUtils.java └── vulkan ├── buffer ├── Buffer.java └── models │ ├── BufferUsage.java │ └── MemoryRequirements.java ├── command ├── CommandBuffer.java ├── CommandPool.java ├── commands │ ├── BeginRenderPassCommand.java │ ├── BindDescriptorSetsCommand.java │ ├── BindIndexBufferCommand.java │ ├── BindPipelineCommand.java │ ├── BindVertexBuffersCommand.java │ ├── ClearColorImageCommand.java │ ├── Command.java │ ├── CopyBufferCommand.java │ ├── CopyImageCommand.java │ ├── CopyImageToBufferCommand.java │ ├── DrawCommand.java │ ├── DrawIndexedCommand.java │ ├── EndRenderPassCommand.java │ ├── PipelineBarrierCommand.java │ └── models │ │ ├── BufferImageCopy.java │ │ ├── BufferMemoryBarrier.java │ │ ├── ImageCopy.java │ │ ├── ImageMemoryBarrier.java │ │ ├── ImageSubresourceLayers.java │ │ ├── ImageSubresourceRange.java │ │ └── MemoryBarrier.java └── models │ ├── CommandBufferLevel.java │ ├── CommandBufferUsage.java │ └── CommandPoolCreateFlag.java ├── devices ├── logical │ ├── DeviceMemory.java │ ├── LogicalDevice.java │ └── MappedDeviceMemory.java └── physical │ ├── PhysicalDevice.java │ └── models │ ├── FormatFeature.java │ ├── FormatProperties.java │ ├── MemoryHeap.java │ ├── MemoryHeapFlag.java │ ├── MemoryProperty.java │ ├── MemoryType.java │ ├── PhysicalDeviceProperties.java │ └── PhysicalDeviceType.java ├── image ├── Image.java ├── ImageView.java ├── SwapchainImage.java └── models │ ├── ImageAspect.java │ ├── ImageCreateFlag.java │ ├── ImageLayout.java │ ├── ImageTiling.java │ ├── ImageType.java │ ├── ImageUsage.java │ └── ImageViewType.java ├── instance ├── DebugLogger.java ├── VulkanFunction.java ├── VulkanInstance.java └── models │ ├── ApplicationInfo.java │ ├── MessageSeverity.java │ ├── MessageType.java │ ├── VulkanException.java │ ├── VulkanResult.java │ └── VulkanVersion.java ├── models ├── Access.java ├── ColorSpace.java ├── Dependency.java ├── Extension.java ├── Extent2D.java ├── Extent3D.java ├── Format.java ├── HasValue.java ├── Maskable.java ├── Offset2D.java ├── Offset3D.java ├── Rect2D.java ├── SampleCount.java ├── SharingMode.java ├── clear │ ├── ClearColor.java │ ├── ClearColorFloat.java │ ├── ClearColorInt.java │ ├── ClearDepthStencil.java │ └── ClearValue.java └── pointers │ ├── Container.java │ ├── Disposable.java │ ├── DisposablePointer.java │ ├── DisposableReferencePointer.java │ ├── Pointer.java │ └── ReferencePointer.java ├── pipeline ├── GraphicsPipeline.java ├── PipelineLayout.java ├── descriptor │ ├── DescriptorPool.java │ ├── DescriptorSet.java │ ├── DescriptorSetLayout.java │ ├── DescriptorSetLayoutBinding.java │ └── models │ │ ├── DescriptorPoolFlag.java │ │ └── DescriptorType.java ├── models │ ├── PipelineBindPoint.java │ ├── PipelineCreateFlag.java │ ├── PipelineStage.java │ ├── assembly │ │ ├── InputAssemblyState.java │ │ └── PrimitiveTopology.java │ ├── colorblend │ │ ├── BlendFactor.java │ │ ├── BlendOperation.java │ │ ├── ColorBlendAttachmentState.java │ │ ├── ColorBlendState.java │ │ ├── ColorComponent.java │ │ └── LogicalOperation.java │ ├── depth │ │ ├── CompareOperator.java │ │ ├── DepthStencilState.java │ │ ├── StencilOperation.java │ │ └── StencilOperationState.java │ ├── multisample │ │ └── MultisampleState.java │ ├── rasterization │ │ ├── CullMode.java │ │ ├── FrontFace.java │ │ ├── PolygonMode.java │ │ └── RasterizationState.java │ ├── vertex │ │ ├── VertexInputAttribute.java │ │ ├── VertexInputBinding.java │ │ ├── VertexInputRate.java │ │ ├── VertexInputState.java │ │ └── builder │ │ │ ├── VertexInputBindingBuilder.java │ │ │ └── VertexInputStateBuilder.java │ └── viewport │ │ ├── Viewport.java │ │ └── ViewportState.java └── shader │ ├── ShaderModule.java │ ├── ShaderModuleLoader.java │ ├── ShaderStage.java │ └── ShaderStageType.java ├── queue ├── Queue.java ├── QueueCapability.java └── QueueFamily.java ├── surface ├── Surface.java └── models │ ├── PresentMode.java │ ├── SurfaceFormat.java │ └── capabilities │ ├── CompositeAlpha.java │ ├── SurfaceCapabilities.java │ └── SurfaceTransform.java ├── swapchain ├── Framebuffer.java ├── RenderPass.java ├── Swapchain.java └── models │ ├── Attachment.java │ ├── AttachmentLoadOperation.java │ ├── AttachmentStoreOperation.java │ ├── ColorAttachment.java │ ├── DepthStencilAttachment.java │ ├── Subpass.java │ ├── SubpassContents.java │ └── SubpassDependency.java └── synchronize ├── Fence.java ├── Semaphore.java └── models └── FenceCreationFlag.java /.gitignore: -------------------------------------------------------------------------------- 1 | ### Intellij ### 2 | # User-specific stuff 3 | .idea/**/* 4 | 5 | # IntelliJ 6 | out/ 7 | *.iml 8 | 9 | ### Java ### 10 | # Compiled class file 11 | *.class 12 | 13 | # Log file 14 | *.log 15 | 16 | # BlueJ files 17 | *.ctxt 18 | 19 | # Mobile Tools for Java (J2ME) 20 | .mtj.tmp/ 21 | 22 | # Package Files # 23 | *.jar 24 | *.war 25 | *.nar 26 | *.ear 27 | *.zip 28 | *.tar.gz 29 | *.rar 30 | 31 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 32 | hs_err_pid* 33 | 34 | ### Gradle ### 35 | .gradle 36 | /build/ 37 | 38 | # Ignore Gradle GUI config 39 | gradle-app.setting 40 | 41 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 42 | !gradle-wrapper.jar 43 | 44 | # Cache of project 45 | .gradletasknamecache -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Justin Driggers 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/justindriggers/vulkan-java-api/blob/master/LICENSE.md) 2 | 3 | ## Vulkan Java API 4 | 5 | The Vulkan Java API is an object-oriented Java library, backed by the 6 | [Lightweight Java Game Library](https://www.lwjgl.org/) Vulkan API. The Java API aims to encapsulate the complexities 7 | of struct construction and memory management into classes that are more easily understood by those uncomfortable with 8 | such concepts. 9 | 10 | ### Disclaimer 11 | 12 | This library is a work-in-progress, and the API is incomplete. Contributions and feedback are welcome and appreciated. 13 | 14 | ### But why? 15 | 16 | The original goal behind writing this library was, first and foremost, to familiarize myself with the Vulkan API. 17 | 18 | However, this library does have a lot of potential for the future: 19 | - Apple recently [deprecated OpenGL](https://developer.apple.com/macos/whats-new/#deprecationofopenglandopencl), pushing 20 | developers to use Metal instead. 21 | - KhronosGroup released [MoltenVK](https://github.com/KhronosGroup/MoltenVK), providing a Vulkan-to-Metal compatibility 22 | layer for Apple systems. 23 | - It is unlikely that libGDX (the most prominent Java-based game library at the time of this writing) will 24 | [support Vulkan](https://github.com/libgdx/libgdx/issues/3344#issuecomment-312908022) any time soon. 25 | 26 | ### Concepts 27 | 28 | - Vulkan APIs that begin with `vkCreate` are covered by Java Object instantiation. 29 | - The `vkCreateSemaphore` function (which requires a `VkDevice`) is invoked simply by constructing a 30 | `new Semaphore(device)`. 31 | - Vulkan APIs that begin with `vkDestroy` are invoked by implementing the `AutoCloseable` interface. 32 | - The `vkDestroySemaphore` function is invoked by calling `semaphore.close()`, or using a `try-with-resources` block. 33 | - Vulkan APIs that act on a specific parameter are implemented as methods on the corresponding object. 34 | - The `vkDeviceWaitIdle` function (which requires a `VkDevice`) is invoked by calling `device.waitIdle()`. 35 | 36 | ### Getting Started 37 | 38 | #### build.gradle 39 | 40 | ``` 41 | import org.gradle.internal.os.OperatingSystem 42 | 43 | project.ext.lwjglVersion = "3.2.0" 44 | project.ext.hasVulkanNatives = false 45 | 46 | switch (OperatingSystem.current()) { 47 | case OperatingSystem.WINDOWS: 48 | project.ext.lwjglNatives = "natives-windows" 49 | break 50 | case OperatingSystem.LINUX: 51 | project.ext.lwjglNatives = "natives-linux" 52 | break 53 | case OperatingSystem.MAC_OS: 54 | project.ext.lwjglNatives = "natives-macos" 55 | project.ext.hasVulkanNatives = true 56 | break 57 | } 58 | 59 | repositories { 60 | mavenCentral() 61 | maven { 62 | url = 'https://dl.bintray.com/justindriggers/vulkan-java-api' 63 | } 64 | } 65 | 66 | dependencies { 67 | implementation('com.justindriggers:vulkan-java-api:0.+') 68 | 69 | implementation("org.lwjgl:lwjgl:$lwjglVersion:$lwjglNatives") 70 | implementation("org.lwjgl:lwjgl-glfw:$lwjglVersion:$lwjglNatives") 71 | 72 | if (project.ext.hasVulkanNatives) { 73 | implementation("org.lwjgl:lwjgl-vulkan:$lwjglVersion:$lwjglNatives") 74 | } 75 | } 76 | ``` 77 | 78 | #### Example 79 | 80 | Check out https://github.com/justindriggers/vulkan-java-api-example for a more comprehensive usage example. -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | id 'maven-publish' 4 | id 'com.jfrog.bintray' version '1.8.4' 5 | } 6 | 7 | group = 'com.justindriggers' 8 | version = '0.8.0' 9 | 10 | sourceCompatibility = JavaVersion.VERSION_1_8 11 | targetCompatibility = JavaVersion.VERSION_1_8 12 | 13 | repositories { 14 | mavenCentral() 15 | } 16 | 17 | dependencies { 18 | implementation("org.lwjgl:lwjgl:$lwjglVersion") 19 | implementation("org.lwjgl:lwjgl-glfw:$lwjglVersion") 20 | implementation("org.lwjgl:lwjgl-vulkan:$lwjglVersion") 21 | } 22 | 23 | task sourcesJar(type: Jar, dependsOn: classes) { 24 | classifier = 'sources' 25 | from sourceSets.main.allSource 26 | } 27 | 28 | task javadocJar(type: Jar, dependsOn: javadoc) { 29 | classifier = 'javadoc' 30 | from javadoc.destinationDir 31 | } 32 | 33 | artifacts { 34 | archives sourcesJar, javadocJar 35 | } 36 | 37 | publishing { 38 | publications { 39 | mavenPublication(MavenPublication) { 40 | from components.java 41 | 42 | artifact sourcesJar 43 | artifact javadocJar 44 | } 45 | } 46 | } 47 | 48 | bintray { 49 | user = System.getProperty('bintray.user') 50 | key = System.getProperty('bintray.key') 51 | publications = ['mavenPublication'] 52 | dryRun = false 53 | publish = false 54 | 55 | pkg { 56 | repo = 'vulkan-java-api' 57 | name = 'vulkan-java-api' 58 | websiteUrl = 'https://github.com/justindriggers/vulkan-java-api' 59 | issueTrackerUrl = 'https://github.com/justindriggers/vulkan-java-api/issues' 60 | vcsUrl = 'https://github.com/justindriggers/vulkan-java-api.git' 61 | licenses = ['MIT'] 62 | labels = ['vulkan', 'java', 'api'] 63 | publicDownloadNumbers = true 64 | version.released = new Date() 65 | } 66 | } 67 | 68 | task wrapper(type: Wrapper) { 69 | gradleVersion = '4.10' 70 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | lwjglVersion=3.2.0 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justindriggers/vulkan-java-api/043d93d1860bc02c8cdb8307f3df3b38b40bc073/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'vulkan-java-api' -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/glfw/GLFWInstance.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.glfw; 2 | 3 | import com.justindriggers.vulkan.instance.VulkanInstance; 4 | import com.justindriggers.vulkan.surface.Surface; 5 | import org.lwjgl.PointerBuffer; 6 | import org.lwjgl.system.MemoryUtil; 7 | 8 | import java.util.Collections; 9 | import java.util.Optional; 10 | import java.util.Set; 11 | import java.util.stream.Collectors; 12 | import java.util.stream.IntStream; 13 | 14 | import static org.lwjgl.glfw.GLFW.glfwInit; 15 | import static org.lwjgl.glfw.GLFWVulkan.glfwGetRequiredInstanceExtensions; 16 | 17 | public class GLFWInstance { 18 | 19 | public GLFWInstance() { 20 | if (!glfwInit()) { 21 | throw new IllegalStateException("Failed to initialize GLFW"); 22 | } 23 | } 24 | 25 | public Set getRequiredVulkanInstanceExtensions() { 26 | final PointerBuffer requiredExtensionsBuffer = glfwGetRequiredInstanceExtensions(); 27 | 28 | return Optional.ofNullable(requiredExtensionsBuffer) 29 | .map(buffer -> IntStream.range(0, buffer.capacity()) 30 | .mapToObj(buffer::get) 31 | .map(MemoryUtil::memUTF8) 32 | .collect(Collectors.toSet())) 33 | .orElseGet(Collections::emptySet); 34 | } 35 | 36 | public Surface createWindowSurface(final VulkanInstance vulkanInstance, final long windowHandle) { 37 | return new GLFWSurface(vulkanInstance, windowHandle); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/glfw/GLFWSurface.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.glfw; 2 | 3 | import com.justindriggers.vulkan.instance.VulkanFunction; 4 | import com.justindriggers.vulkan.instance.VulkanInstance; 5 | import com.justindriggers.vulkan.surface.Surface; 6 | 7 | import java.nio.LongBuffer; 8 | 9 | import static org.lwjgl.glfw.GLFWVulkan.glfwCreateWindowSurface; 10 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 11 | import static org.lwjgl.system.MemoryUtil.memFree; 12 | 13 | public class GLFWSurface extends Surface { 14 | 15 | GLFWSurface(final VulkanInstance vulkanInstance, 16 | final long windowHandle) { 17 | super(vulkanInstance, createSurface(vulkanInstance, windowHandle)); 18 | } 19 | 20 | private static long createSurface(final VulkanInstance vulkanInstance, 21 | final long windowHandle) { 22 | final long result; 23 | 24 | final LongBuffer surfaceHandle = memAllocLong(1); 25 | 26 | try { 27 | VulkanFunction.execute(() -> glfwCreateWindowSurface(vulkanInstance.unwrap(), windowHandle, null, 28 | surfaceHandle)); 29 | 30 | result = surfaceHandle.get(0); 31 | } finally { 32 | memFree(surfaceHandle); 33 | } 34 | 35 | return result; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/utilities/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.utilities; 2 | 3 | import org.lwjgl.PointerBuffer; 4 | import org.lwjgl.system.MemoryUtil; 5 | 6 | import java.util.Collections; 7 | import java.util.Optional; 8 | import java.util.Set; 9 | 10 | import static org.lwjgl.system.MemoryUtil.memAllocPointer; 11 | 12 | public class StringUtils { 13 | 14 | /** 15 | * Safely converts the Set of Strings into a PointerBuffer containing an array of pointers to the Strings. 16 | * 17 | * @param strings A nullable Set of Strings 18 | * @return a PointerBuffer containing an array of pointers to all validation layers. The PointerBuffer and the 19 | * Strings that its contents point to must be disposed of manually. 20 | */ 21 | public static PointerBuffer getPointerBufferFromStrings(final Set strings) { 22 | final Set stringsSafe = Optional.ofNullable(strings) 23 | .orElseGet(Collections::emptySet); 24 | 25 | final PointerBuffer result = memAllocPointer(stringsSafe.size()); 26 | 27 | stringsSafe.stream() 28 | .map(MemoryUtil::memUTF8) 29 | .forEach(result::put); 30 | 31 | result.flip(); 32 | 33 | return result; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/buffer/Buffer.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.buffer; 2 | 3 | import com.justindriggers.vulkan.buffer.models.BufferUsage; 4 | import com.justindriggers.vulkan.buffer.models.MemoryRequirements; 5 | import com.justindriggers.vulkan.devices.logical.DeviceMemory; 6 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 7 | import com.justindriggers.vulkan.instance.VulkanFunction; 8 | import com.justindriggers.vulkan.models.Maskable; 9 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 10 | import org.lwjgl.vulkan.VkBufferCreateInfo; 11 | import org.lwjgl.vulkan.VkMemoryRequirements; 12 | 13 | import java.nio.LongBuffer; 14 | import java.util.Set; 15 | 16 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 17 | import static org.lwjgl.system.MemoryUtil.memFree; 18 | import static org.lwjgl.vulkan.VK10.VK_SHARING_MODE_EXCLUSIVE; 19 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; 20 | import static org.lwjgl.vulkan.VK10.vkBindBufferMemory; 21 | import static org.lwjgl.vulkan.VK10.vkCreateBuffer; 22 | import static org.lwjgl.vulkan.VK10.vkDestroyBuffer; 23 | import static org.lwjgl.vulkan.VK10.vkGetBufferMemoryRequirements; 24 | 25 | public class Buffer extends DisposablePointer { 26 | 27 | private final LogicalDevice device; 28 | private final long size; 29 | 30 | public Buffer(final LogicalDevice device, 31 | final long size, 32 | final Set usages) { 33 | super(createBuffer(device, size, usages)); 34 | this.device = device; 35 | this.size = size; 36 | } 37 | 38 | @Override 39 | protected void dispose(final long address) { 40 | vkDestroyBuffer(device.unwrap(), address, null); 41 | } 42 | 43 | public MemoryRequirements getMemoryRequirements() { 44 | final MemoryRequirements result; 45 | 46 | final VkMemoryRequirements memoryRequirements = VkMemoryRequirements.calloc(); 47 | 48 | try { 49 | vkGetBufferMemoryRequirements(device.unwrap(), getAddress(), memoryRequirements); 50 | 51 | result = new MemoryRequirements(memoryRequirements); 52 | } finally { 53 | memoryRequirements.free(); 54 | } 55 | 56 | return result; 57 | } 58 | 59 | public void bindMemory(final DeviceMemory deviceMemory) { 60 | VulkanFunction.execute(() -> vkBindBufferMemory(device.unwrap(), getAddress(), deviceMemory.getAddress(), 0L)); 61 | } 62 | 63 | public long getSize() { 64 | return size; 65 | } 66 | 67 | private static long createBuffer(final LogicalDevice device, 68 | final long size, 69 | final Set usages) { 70 | final long result; 71 | 72 | final LongBuffer buffer = memAllocLong(1); 73 | 74 | final VkBufferCreateInfo bufferCreateInfo = VkBufferCreateInfo.calloc() 75 | .sType(VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO) 76 | .size(size) 77 | .usage(Maskable.toBitMask(usages)) 78 | .sharingMode(VK_SHARING_MODE_EXCLUSIVE); 79 | 80 | try { 81 | VulkanFunction.execute(() -> vkCreateBuffer(device.unwrap(), bufferCreateInfo, null, buffer)); 82 | 83 | result = buffer.get(0); 84 | } finally { 85 | memFree(buffer); 86 | 87 | bufferCreateInfo.free(); 88 | } 89 | 90 | return result; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/buffer/models/BufferUsage.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.buffer.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum BufferUsage implements Maskable { 7 | 8 | TRANSFER_SRC(VK10.VK_BUFFER_USAGE_TRANSFER_SRC_BIT), 9 | TRANSFER_DST(VK10.VK_BUFFER_USAGE_TRANSFER_DST_BIT), 10 | UNIFORM_TEXEL_BUFFER(VK10.VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT), 11 | STORAGE_TEXEL_BUFFER(VK10.VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT), 12 | UNIFORM_BUFFER(VK10.VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT), 13 | STORAGE_BUFFER(VK10.VK_BUFFER_USAGE_STORAGE_BUFFER_BIT), 14 | INDEX_BUFFER(VK10.VK_BUFFER_USAGE_INDEX_BUFFER_BIT), 15 | VERTEX_BUFFER(VK10.VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), 16 | INDIRECT_BUFFER(VK10.VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT); 17 | 18 | private final int bit; 19 | 20 | BufferUsage(final int bit) { 21 | this.bit = bit; 22 | } 23 | 24 | @Override 25 | public int getBitValue() { 26 | return bit; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/buffer/models/MemoryRequirements.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.buffer.models; 2 | 3 | import com.justindriggers.vulkan.devices.physical.models.MemoryType; 4 | import org.lwjgl.vulkan.VkMemoryRequirements; 5 | 6 | import java.util.Objects; 7 | import java.util.function.Predicate; 8 | 9 | public class MemoryRequirements implements Predicate { 10 | 11 | private final long size; 12 | private final long alignment; 13 | private final int memoryTypeBits; 14 | 15 | public MemoryRequirements(final VkMemoryRequirements vkMemoryRequirements) { 16 | size = vkMemoryRequirements.size(); 17 | alignment = vkMemoryRequirements.alignment(); 18 | memoryTypeBits = vkMemoryRequirements.memoryTypeBits(); 19 | } 20 | 21 | @Override 22 | public boolean test(final MemoryType memoryType) { 23 | return (memoryTypeBits & (1 << memoryType.getIndex())) != 0; 24 | } 25 | 26 | public long getSize() { 27 | return size; 28 | } 29 | 30 | public long getAlignment() { 31 | return alignment; 32 | } 33 | 34 | public int getMemoryTypeBits() { 35 | return memoryTypeBits; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object o) { 40 | if (this == o) { 41 | return true; 42 | } 43 | 44 | if (o == null || getClass() != o.getClass()) { 45 | return false; 46 | } 47 | 48 | MemoryRequirements that = (MemoryRequirements) o; 49 | 50 | return size == that.size 51 | && alignment == that.alignment 52 | && memoryTypeBits == that.memoryTypeBits; 53 | } 54 | 55 | @Override 56 | public int hashCode() { 57 | return Objects.hash( 58 | size, 59 | alignment, 60 | memoryTypeBits 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/CommandBuffer.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command; 2 | 3 | import com.justindriggers.vulkan.command.commands.Command; 4 | import com.justindriggers.vulkan.command.models.CommandBufferUsage; 5 | import com.justindriggers.vulkan.instance.VulkanFunction; 6 | import com.justindriggers.vulkan.models.Maskable; 7 | import com.justindriggers.vulkan.models.pointers.DisposableReferencePointer; 8 | import org.lwjgl.system.Pointer; 9 | import org.lwjgl.vulkan.VkCommandBuffer; 10 | import org.lwjgl.vulkan.VkCommandBufferBeginInfo; 11 | 12 | import static org.lwjgl.vulkan.VK10.VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT; 13 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; 14 | import static org.lwjgl.vulkan.VK10.vkBeginCommandBuffer; 15 | import static org.lwjgl.vulkan.VK10.vkEndCommandBuffer; 16 | import static org.lwjgl.vulkan.VK10.vkResetCommandBuffer; 17 | 18 | public class CommandBuffer extends DisposableReferencePointer { 19 | 20 | CommandBuffer(final VkCommandBuffer vkCommandBuffer) { 21 | super(vkCommandBuffer, Pointer::address); 22 | } 23 | 24 | @Override 25 | protected void dispose(final VkCommandBuffer commandBuffer, final long address) { 26 | // Nothing to do, but disposal ensures that nothing can reference the underlying pointer or value 27 | } 28 | 29 | public void reset() { 30 | VulkanFunction.execute(() -> vkResetCommandBuffer(unwrap(), VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT)); 31 | } 32 | 33 | public void begin(final CommandBufferUsage... usages) { 34 | final VkCommandBufferBeginInfo commandBufferBeginInfo = VkCommandBufferBeginInfo.calloc() 35 | .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO) 36 | .flags(Maskable.toBitMask(usages)); 37 | 38 | try { 39 | VulkanFunction.execute(() -> vkBeginCommandBuffer(unwrap(), commandBufferBeginInfo)); 40 | } finally { 41 | commandBufferBeginInfo.free(); 42 | } 43 | } 44 | 45 | public void end() { 46 | VulkanFunction.execute(() -> vkEndCommandBuffer(unwrap())); 47 | } 48 | 49 | public void submit(final Command command) { 50 | command.execute(this); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/CommandPool.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command; 2 | 3 | import com.justindriggers.vulkan.command.models.CommandBufferLevel; 4 | import com.justindriggers.vulkan.command.models.CommandPoolCreateFlag; 5 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 6 | import com.justindriggers.vulkan.instance.VulkanFunction; 7 | import com.justindriggers.vulkan.models.HasValue; 8 | import com.justindriggers.vulkan.models.Maskable; 9 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 10 | import com.justindriggers.vulkan.queue.QueueFamily; 11 | import org.lwjgl.PointerBuffer; 12 | import org.lwjgl.vulkan.VkCommandBuffer; 13 | import org.lwjgl.vulkan.VkCommandBufferAllocateInfo; 14 | import org.lwjgl.vulkan.VkCommandPoolCreateInfo; 15 | 16 | import java.nio.LongBuffer; 17 | import java.util.Collection; 18 | import java.util.List; 19 | import java.util.Objects; 20 | import java.util.stream.Collectors; 21 | import java.util.stream.IntStream; 22 | 23 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 24 | import static org.lwjgl.system.MemoryUtil.memAllocPointer; 25 | import static org.lwjgl.system.MemoryUtil.memFree; 26 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; 27 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; 28 | import static org.lwjgl.vulkan.VK10.vkAllocateCommandBuffers; 29 | import static org.lwjgl.vulkan.VK10.vkCreateCommandPool; 30 | import static org.lwjgl.vulkan.VK10.vkDestroyCommandPool; 31 | import static org.lwjgl.vulkan.VK10.vkFreeCommandBuffers; 32 | 33 | public class CommandPool extends DisposablePointer { 34 | 35 | private final LogicalDevice device; 36 | 37 | public CommandPool(final LogicalDevice device, 38 | final QueueFamily queueFamily, 39 | final CommandPoolCreateFlag... flags) { 40 | super(createCommandPool(device, queueFamily, flags)); 41 | this.device = device; 42 | } 43 | 44 | @Override 45 | protected void dispose(final long address) { 46 | vkDestroyCommandPool(device.unwrap(), address, null); 47 | } 48 | 49 | public List createCommandBuffers(final CommandBufferLevel commandBufferLevel, final int count) { 50 | if (count <= 0) { 51 | throw new IllegalArgumentException("Count must be at least 1 when creating command buffers"); 52 | } 53 | 54 | final List result; 55 | 56 | final PointerBuffer commandBuffers = memAllocPointer(count); 57 | 58 | final VkCommandBufferAllocateInfo commandBufferAllocateInfo = VkCommandBufferAllocateInfo.calloc() 59 | .sType(VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO) 60 | .commandPool(getAddress()) 61 | .level(HasValue.getValue(commandBufferLevel)) 62 | .commandBufferCount(count); 63 | 64 | try { 65 | VulkanFunction.execute(() -> vkAllocateCommandBuffers(device.unwrap(), commandBufferAllocateInfo, 66 | commandBuffers)); 67 | 68 | result = IntStream.range(0, count) 69 | .mapToLong(commandBuffers::get) 70 | .mapToObj(commandBuffer -> new VkCommandBuffer(commandBuffer, device.unwrap())) 71 | .map(CommandBuffer::new) 72 | .collect(Collectors.toList()); 73 | } finally { 74 | commandBufferAllocateInfo.free(); 75 | 76 | memFree(commandBuffers); 77 | } 78 | 79 | return result; 80 | } 81 | 82 | public void destroyCommandBuffers(final Collection commandBuffers) { 83 | Objects.requireNonNull(commandBuffers); 84 | 85 | if (!commandBuffers.isEmpty()) { 86 | final PointerBuffer commandBufferPointers = memAllocPointer(commandBuffers.size()); 87 | commandBuffers.forEach(commandBuffer -> commandBufferPointers.put(commandBuffer.unwrap().address())); 88 | commandBufferPointers.flip(); 89 | 90 | try { 91 | vkFreeCommandBuffers(device.unwrap(), getAddress(), commandBufferPointers); 92 | commandBuffers.forEach(CommandBuffer::close); 93 | } finally { 94 | memFree(commandBufferPointers); 95 | } 96 | } 97 | } 98 | 99 | private static long createCommandPool(final LogicalDevice device, 100 | final QueueFamily queueFamily, 101 | final CommandPoolCreateFlag... flags) { 102 | final long result; 103 | 104 | final LongBuffer commandPool = memAllocLong(1); 105 | 106 | final VkCommandPoolCreateInfo commandPoolCreateInfo = VkCommandPoolCreateInfo.calloc() 107 | .sType(VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO) 108 | .queueFamilyIndex(queueFamily.getIndex()) 109 | .flags(Maskable.toBitMask(flags)); 110 | 111 | try { 112 | VulkanFunction.execute(() -> vkCreateCommandPool(device.unwrap(), commandPoolCreateInfo, null, 113 | commandPool)); 114 | 115 | result = commandPool.get(0); 116 | } finally { 117 | memFree(commandPool); 118 | 119 | commandPoolCreateInfo.free(); 120 | } 121 | 122 | return result; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/BeginRenderPassCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | import com.justindriggers.vulkan.models.HasValue; 5 | import com.justindriggers.vulkan.models.Rect2D; 6 | import com.justindriggers.vulkan.models.clear.ClearValue; 7 | import com.justindriggers.vulkan.swapchain.Framebuffer; 8 | import com.justindriggers.vulkan.swapchain.RenderPass; 9 | import com.justindriggers.vulkan.swapchain.models.SubpassContents; 10 | import org.lwjgl.vulkan.VkClearValue; 11 | import org.lwjgl.vulkan.VkRenderPassBeginInfo; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; 18 | import static org.lwjgl.vulkan.VK10.vkCmdBeginRenderPass; 19 | 20 | public class BeginRenderPassCommand implements Command { 21 | 22 | private final SubpassContents subpassContents; 23 | private final RenderPass renderPass; 24 | private final Framebuffer framebuffer; 25 | private final Rect2D renderArea; 26 | private final List clearValues; 27 | 28 | public BeginRenderPassCommand(final SubpassContents subpassContents, 29 | final RenderPass renderPass, 30 | final Framebuffer framebuffer, 31 | final Rect2D renderArea, 32 | final List clearValues) { 33 | this.subpassContents = subpassContents; 34 | this.renderPass = renderPass; 35 | this.framebuffer = framebuffer; 36 | this.renderArea = renderArea; 37 | this.clearValues = clearValues; 38 | } 39 | 40 | @Override 41 | public void execute(final CommandBuffer commandBuffer) { 42 | final List clearValuesSafe = Optional.ofNullable(clearValues) 43 | .orElseGet(Collections::emptyList); 44 | 45 | final VkClearValue.Buffer clearValuesBuffer = VkClearValue.calloc(clearValuesSafe.size()); 46 | 47 | clearValuesSafe.stream() 48 | .map(ClearValue::toStruct) 49 | .forEachOrdered(clearValuesBuffer::put); 50 | 51 | clearValuesBuffer.flip(); 52 | 53 | final VkRenderPassBeginInfo renderPassBeginInfo = VkRenderPassBeginInfo.calloc() 54 | .sType(VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO) 55 | .renderPass(renderPass.getAddress()) 56 | .framebuffer(framebuffer.getAddress()) 57 | .pClearValues(clearValuesBuffer); 58 | 59 | renderPassBeginInfo.renderArea().offset() 60 | .x(renderArea.getOffset().getX()) 61 | .y(renderArea.getOffset().getY()); 62 | 63 | renderPassBeginInfo.renderArea().extent() 64 | .width(renderArea.getExtent().getWidth()) 65 | .height(renderArea.getExtent().getHeight()); 66 | 67 | try { 68 | vkCmdBeginRenderPass(commandBuffer.unwrap(), renderPassBeginInfo, HasValue.getValue(subpassContents)); 69 | } finally { 70 | clearValuesBuffer.free(); 71 | renderPassBeginInfo.free(); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/BindDescriptorSetsCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | import com.justindriggers.vulkan.models.pointers.Pointer; 5 | import com.justindriggers.vulkan.pipeline.PipelineLayout; 6 | import com.justindriggers.vulkan.pipeline.descriptor.DescriptorSet; 7 | 8 | import java.nio.IntBuffer; 9 | import java.nio.LongBuffer; 10 | import java.util.Collection; 11 | 12 | import static org.lwjgl.system.MemoryUtil.memAllocInt; 13 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 14 | import static org.lwjgl.system.MemoryUtil.memFree; 15 | import static org.lwjgl.vulkan.VK10.VK_PIPELINE_BIND_POINT_GRAPHICS; 16 | import static org.lwjgl.vulkan.VK10.vkCmdBindDescriptorSets; 17 | 18 | public class BindDescriptorSetsCommand implements Command { 19 | 20 | private final PipelineLayout pipelineLayout; 21 | private final Collection descriptorSets; 22 | 23 | public BindDescriptorSetsCommand(final PipelineLayout pipelineLayout, 24 | final Collection descriptorSets) { 25 | this.pipelineLayout = pipelineLayout; 26 | this.descriptorSets = descriptorSets; 27 | } 28 | 29 | @Override 30 | public void execute(final CommandBuffer commandBuffer) { 31 | final LongBuffer descriptorSetHandles = memAllocLong(descriptorSets.size()); 32 | 33 | descriptorSets.stream() 34 | .map(Pointer::getAddress) 35 | .forEach(descriptorSetHandles::put); 36 | 37 | descriptorSetHandles.flip(); 38 | 39 | final IntBuffer dynamicOffsets = memAllocInt(0); 40 | 41 | try { 42 | vkCmdBindDescriptorSets(commandBuffer.unwrap(), VK_PIPELINE_BIND_POINT_GRAPHICS, 43 | pipelineLayout.getAddress(), 0, descriptorSetHandles, dynamicOffsets); 44 | } finally { 45 | memFree(descriptorSetHandles); 46 | memFree(dynamicOffsets); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/BindIndexBufferCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.buffer.Buffer; 4 | import com.justindriggers.vulkan.command.CommandBuffer; 5 | 6 | import static org.lwjgl.vulkan.VK10.VK_INDEX_TYPE_UINT32; 7 | import static org.lwjgl.vulkan.VK10.vkCmdBindIndexBuffer; 8 | 9 | public class BindIndexBufferCommand implements Command { 10 | 11 | private final Buffer indexBuffer; 12 | 13 | public BindIndexBufferCommand(final Buffer indexBuffer) { 14 | this.indexBuffer = indexBuffer; 15 | } 16 | 17 | @Override 18 | public void execute(final CommandBuffer commandBuffer) { 19 | vkCmdBindIndexBuffer(commandBuffer.unwrap(), indexBuffer.getAddress(), 0, VK_INDEX_TYPE_UINT32); // TODO short/int/long 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/BindPipelineCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | import com.justindriggers.vulkan.pipeline.GraphicsPipeline; 5 | 6 | import static org.lwjgl.vulkan.VK10.VK_PIPELINE_BIND_POINT_GRAPHICS; 7 | import static org.lwjgl.vulkan.VK10.vkCmdBindPipeline; 8 | 9 | public class BindPipelineCommand implements Command { 10 | 11 | private final GraphicsPipeline graphicsPipeline; 12 | 13 | public BindPipelineCommand(final GraphicsPipeline graphicsPipeline) { 14 | this.graphicsPipeline = graphicsPipeline; 15 | } 16 | 17 | @Override 18 | public void execute(final CommandBuffer commandBuffer) { 19 | vkCmdBindPipeline(commandBuffer.unwrap(), VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline.getAddress()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/BindVertexBuffersCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.buffer.Buffer; 4 | import com.justindriggers.vulkan.command.CommandBuffer; 5 | 6 | import java.nio.LongBuffer; 7 | import java.util.List; 8 | 9 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 10 | import static org.lwjgl.system.MemoryUtil.memFree; 11 | import static org.lwjgl.vulkan.VK10.vkCmdBindVertexBuffers; 12 | 13 | public class BindVertexBuffersCommand implements Command { 14 | 15 | private final List vertexBuffers; 16 | 17 | public BindVertexBuffersCommand(final List vertexBuffers) { 18 | this.vertexBuffers = vertexBuffers; 19 | } 20 | 21 | @Override 22 | public void execute(final CommandBuffer commandBuffer) { 23 | final LongBuffer vertexBufferHandles = memAllocLong(vertexBuffers.size()); 24 | final LongBuffer offsets = memAllocLong(vertexBuffers.size()); 25 | 26 | int currentOffset = 0; 27 | 28 | for (final Buffer vertexBuffer : vertexBuffers) { 29 | vertexBufferHandles.put(vertexBuffer.getAddress()); 30 | offsets.put(currentOffset); 31 | 32 | currentOffset += vertexBuffer.getSize(); 33 | } 34 | 35 | vertexBufferHandles.flip(); 36 | offsets.flip(); 37 | 38 | try { 39 | vkCmdBindVertexBuffers(commandBuffer.unwrap(), 0, vertexBufferHandles, offsets); 40 | } finally { 41 | memFree(vertexBufferHandles); 42 | memFree(offsets); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/ClearColorImageCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | import com.justindriggers.vulkan.command.commands.models.ImageSubresourceRange; 5 | import com.justindriggers.vulkan.image.Image; 6 | import com.justindriggers.vulkan.image.models.ImageLayout; 7 | import com.justindriggers.vulkan.models.HasValue; 8 | import com.justindriggers.vulkan.models.Maskable; 9 | import com.justindriggers.vulkan.models.clear.ClearColor; 10 | import org.lwjgl.vulkan.VkClearValue; 11 | import org.lwjgl.vulkan.VkImageSubresourceRange; 12 | 13 | import java.util.Collections; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | import static org.lwjgl.vulkan.VK10.vkCmdClearColorImage; 18 | 19 | public class ClearColorImageCommand implements Command { 20 | 21 | private final Image image; 22 | private final ImageLayout imageLayout; 23 | private final ClearColor clearColor; 24 | private final List regions; 25 | 26 | public ClearColorImageCommand(final Image image, 27 | final ImageLayout imageLayout, 28 | final ClearColor clearColor, 29 | final List regions) { 30 | this.image = image; 31 | this.imageLayout = imageLayout; 32 | this.clearColor = clearColor; 33 | this.regions = regions; 34 | } 35 | 36 | @Override 37 | public void execute(final CommandBuffer commandBuffer) { 38 | final VkClearValue clearValue = clearColor.toStruct(); 39 | 40 | final List regionsSafe = Optional.ofNullable(regions) 41 | .orElseGet(Collections::emptyList); 42 | 43 | final VkImageSubresourceRange.Buffer regionBuffer = VkImageSubresourceRange.calloc(regionsSafe.size()); 44 | 45 | regionsSafe.stream() 46 | .map(region -> VkImageSubresourceRange.calloc() 47 | .aspectMask(Maskable.toBitMask(region.getAspects())) 48 | .baseMipLevel(region.getBaseMipLevel()) 49 | .levelCount(region.getLevelCount()) 50 | .baseArrayLayer(region.getBaseArrayLayer()) 51 | .layerCount(region.getLayerCount())) 52 | .forEachOrdered(regionBuffer::put); 53 | 54 | regionBuffer.flip(); 55 | 56 | try { 57 | vkCmdClearColorImage(commandBuffer.unwrap(), image.getAddress(), HasValue.getValue(imageLayout), 58 | clearValue.color(), regionBuffer); 59 | } finally { 60 | clearValue.free(); 61 | regionBuffer.free(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/Command.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | 5 | public interface Command { 6 | 7 | void execute(final CommandBuffer commandBuffer); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/CopyBufferCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.buffer.Buffer; 4 | import com.justindriggers.vulkan.command.CommandBuffer; 5 | import org.lwjgl.vulkan.VkBufferCopy; 6 | 7 | import static org.lwjgl.vulkan.VK10.vkCmdCopyBuffer; 8 | 9 | public class CopyBufferCommand implements Command { 10 | 11 | private final Buffer sourceBuffer; 12 | private final Buffer destinationBuffer; 13 | private final long size; 14 | 15 | public CopyBufferCommand(final Buffer sourceBuffer, 16 | final Buffer destinationBuffer, 17 | final long size) { 18 | this.sourceBuffer = sourceBuffer; 19 | this.destinationBuffer = destinationBuffer; 20 | this.size = size; 21 | } 22 | 23 | @Override 24 | public void execute(final CommandBuffer commandBuffer) { 25 | final VkBufferCopy.Buffer bufferCopy = VkBufferCopy.calloc(1) 26 | .srcOffset(0L) 27 | .dstOffset(0L) 28 | .size(size); 29 | 30 | vkCmdCopyBuffer(commandBuffer.unwrap(), sourceBuffer.getAddress(), destinationBuffer.getAddress(), bufferCopy); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/CopyImageCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | import com.justindriggers.vulkan.command.commands.models.ImageCopy; 5 | import com.justindriggers.vulkan.image.Image; 6 | import com.justindriggers.vulkan.image.models.ImageLayout; 7 | import com.justindriggers.vulkan.models.HasValue; 8 | import com.justindriggers.vulkan.models.Maskable; 9 | import org.lwjgl.vulkan.VkExtent3D; 10 | import org.lwjgl.vulkan.VkImageCopy; 11 | import org.lwjgl.vulkan.VkImageSubresourceLayers; 12 | import org.lwjgl.vulkan.VkOffset3D; 13 | 14 | import java.util.Collections; 15 | import java.util.List; 16 | import java.util.Optional; 17 | 18 | import static org.lwjgl.vulkan.VK10.vkCmdCopyImage; 19 | 20 | public class CopyImageCommand implements Command { 21 | 22 | private final Image sourceImage; 23 | private final ImageLayout sourceImageLayout; 24 | private final Image destinationImage; 25 | private final ImageLayout destinationImageLayout; 26 | private final List regions; 27 | 28 | public CopyImageCommand(final Image sourceImage, 29 | final ImageLayout sourceImageLayout, 30 | final Image destinationImage, 31 | final ImageLayout destinationImageLayout, 32 | final List regions) { 33 | this.sourceImage = sourceImage; 34 | this.sourceImageLayout = sourceImageLayout; 35 | this.destinationImage = destinationImage; 36 | this.destinationImageLayout = destinationImageLayout; 37 | this.regions = regions; 38 | } 39 | 40 | @Override 41 | public void execute(final CommandBuffer commandBuffer) { 42 | final List regionsSafe = Optional.ofNullable(regions) 43 | .orElseGet(Collections::emptyList); 44 | 45 | final VkImageCopy.Buffer imageCopyBuffer = VkImageCopy.calloc(regionsSafe.size()); 46 | 47 | regionsSafe.stream() 48 | .map(region -> { 49 | final VkImageSubresourceLayers srcSubresource = Optional.ofNullable(region.getSourceSubresource()) 50 | .map(subresource -> VkImageSubresourceLayers.calloc() 51 | .aspectMask(Maskable.toBitMask(subresource.getAspects())) 52 | .mipLevel(subresource.getMipLevel()) 53 | .baseArrayLayer(subresource.getBaseArrayLayer()) 54 | .layerCount(subresource.getLayerCount())) 55 | .orElse(null); 56 | 57 | final VkOffset3D srcOffset = Optional.ofNullable(region.getSourceOffset()) 58 | .map(offset -> VkOffset3D.calloc() 59 | .x(offset.getX()) 60 | .y(offset.getY()) 61 | .z(offset.getZ())) 62 | .orElse(null); 63 | 64 | final VkImageSubresourceLayers dstSubresource = Optional.ofNullable(region.getDestinationSubresource()) 65 | .map(subresource -> VkImageSubresourceLayers.calloc() 66 | .aspectMask(Maskable.toBitMask(subresource.getAspects())) 67 | .mipLevel(subresource.getMipLevel()) 68 | .baseArrayLayer(subresource.getBaseArrayLayer()) 69 | .layerCount(subresource.getLayerCount())) 70 | .orElse(null); 71 | 72 | final VkOffset3D dstOffset = Optional.ofNullable(region.getDestinationOffset()) 73 | .map(offset -> VkOffset3D.calloc() 74 | .x(offset.getX()) 75 | .y(offset.getY()) 76 | .z(offset.getZ())) 77 | .orElse(null); 78 | 79 | final VkExtent3D extent = Optional.ofNullable(region.getExtent()) 80 | .map(extent3D -> VkExtent3D.calloc() 81 | .width(extent3D.getWidth()) 82 | .height(extent3D.getHeight()) 83 | .depth(extent3D.getDepth())) 84 | .orElse(null); 85 | 86 | return VkImageCopy.calloc() 87 | .srcSubresource(srcSubresource) 88 | .srcOffset(srcOffset) 89 | .dstSubresource(dstSubresource) 90 | .dstOffset(dstOffset) 91 | .extent(extent); 92 | }).forEachOrdered(imageCopyBuffer::put); 93 | 94 | imageCopyBuffer.flip(); 95 | 96 | try { 97 | vkCmdCopyImage(commandBuffer.unwrap(), sourceImage.getAddress(), HasValue.getValue(sourceImageLayout), 98 | destinationImage.getAddress(), HasValue.getValue(destinationImageLayout), imageCopyBuffer); 99 | } finally { 100 | imageCopyBuffer.free(); 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/CopyImageToBufferCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.buffer.Buffer; 4 | import com.justindriggers.vulkan.command.CommandBuffer; 5 | import com.justindriggers.vulkan.command.commands.models.BufferImageCopy; 6 | import com.justindriggers.vulkan.image.Image; 7 | import com.justindriggers.vulkan.image.models.ImageLayout; 8 | import com.justindriggers.vulkan.models.HasValue; 9 | import com.justindriggers.vulkan.models.Maskable; 10 | import org.lwjgl.vulkan.VkBufferImageCopy; 11 | import org.lwjgl.vulkan.VkExtent3D; 12 | import org.lwjgl.vulkan.VkImageSubresourceLayers; 13 | import org.lwjgl.vulkan.VkOffset3D; 14 | 15 | import java.util.Collections; 16 | import java.util.List; 17 | import java.util.Optional; 18 | 19 | import static org.lwjgl.vulkan.VK10.vkCmdCopyImageToBuffer; 20 | 21 | public class CopyImageToBufferCommand implements Command { 22 | 23 | private final Image sourceImage; 24 | private final ImageLayout sourceImageLayout; 25 | private final Buffer destinationBuffer; 26 | private final List regions; 27 | 28 | public CopyImageToBufferCommand(final Image sourceImage, 29 | final ImageLayout sourceImageLayout, 30 | final Buffer destinationBuffer, 31 | final List regions) { 32 | this.sourceImage = sourceImage; 33 | this.sourceImageLayout = sourceImageLayout; 34 | this.destinationBuffer = destinationBuffer; 35 | this.regions = regions; 36 | } 37 | 38 | @Override 39 | public void execute(final CommandBuffer commandBuffer) { 40 | final List regionsSafe = Optional.ofNullable(regions) 41 | .orElseGet(Collections::emptyList); 42 | 43 | final VkBufferImageCopy.Buffer regionsBuffer = VkBufferImageCopy.calloc(regionsSafe.size()); 44 | 45 | regionsSafe.stream() 46 | .map(region -> { 47 | final VkImageSubresourceLayers imageSubresource = Optional.ofNullable(region.getImageSubresource()) 48 | .map(subresource -> VkImageSubresourceLayers.calloc() 49 | .aspectMask(Maskable.toBitMask(subresource.getAspects())) 50 | .mipLevel(subresource.getMipLevel()) 51 | .baseArrayLayer(subresource.getBaseArrayLayer()) 52 | .layerCount(subresource.getLayerCount())) 53 | .orElse(null); 54 | 55 | final VkOffset3D imageOffset = Optional.ofNullable(region.getImageOffset()) 56 | .map(offset -> VkOffset3D.calloc() 57 | .x(offset.getX()) 58 | .y(offset.getY()) 59 | .z(offset.getZ())) 60 | .orElse(null); 61 | 62 | final VkExtent3D imageExtent = Optional.ofNullable(region.getImageExtent()) 63 | .map(extent3D -> VkExtent3D.calloc() 64 | .width(extent3D.getWidth()) 65 | .height(extent3D.getHeight()) 66 | .depth(extent3D.getDepth())) 67 | .orElse(null); 68 | 69 | return VkBufferImageCopy.calloc() 70 | .bufferOffset(region.getBufferOffset()) 71 | .bufferRowLength(region.getBufferRowLength()) 72 | .bufferImageHeight(region.getBufferImageHeight()) 73 | .imageSubresource(imageSubresource) 74 | .imageOffset(imageOffset) 75 | .imageExtent(imageExtent); 76 | }).forEachOrdered(regionsBuffer::put); 77 | 78 | regionsBuffer.flip(); 79 | 80 | try { 81 | vkCmdCopyImageToBuffer(commandBuffer.unwrap(), sourceImage.getAddress(), 82 | HasValue.getValue(sourceImageLayout), destinationBuffer.getAddress(), regionsBuffer); 83 | } finally { 84 | regionsBuffer.free(); 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/DrawCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | 5 | import static org.lwjgl.vulkan.VK10.vkCmdDraw; 6 | 7 | public class DrawCommand implements Command { 8 | 9 | private final int vertexCount; 10 | private final int instanceCount; 11 | private final int firstVertex; 12 | private final int firstInstance; 13 | 14 | public DrawCommand(final int vertexCount, 15 | final int instanceCount, 16 | final int firstVertex, 17 | final int firstInstance) { 18 | this.vertexCount = vertexCount; 19 | this.instanceCount = instanceCount; 20 | this.firstVertex = firstVertex; 21 | this.firstInstance = firstInstance; 22 | } 23 | 24 | @Override 25 | public void execute(final CommandBuffer commandBuffer) { 26 | vkCmdDraw(commandBuffer.unwrap(), vertexCount, instanceCount, firstVertex, firstInstance); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/DrawIndexedCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | 5 | import static org.lwjgl.vulkan.VK10.vkCmdDrawIndexed; 6 | 7 | public class DrawIndexedCommand implements Command { 8 | 9 | private final int indexCount; 10 | private final int instanceCount; 11 | private final int firstIndex; 12 | private final int vertexOffset; 13 | private final int firstInstance; 14 | 15 | public DrawIndexedCommand(final int indexCount, 16 | final int instanceCount, 17 | final int firstIndex, 18 | final int vertexOffset, 19 | final int firstInstance) { 20 | this.indexCount = indexCount; 21 | this.instanceCount = instanceCount; 22 | this.firstIndex = firstIndex; 23 | this.vertexOffset = vertexOffset; 24 | this.firstInstance = firstInstance; 25 | } 26 | 27 | @Override 28 | public void execute(final CommandBuffer commandBuffer) { 29 | vkCmdDrawIndexed(commandBuffer.unwrap(), indexCount, instanceCount, firstIndex, vertexOffset, firstInstance); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/EndRenderPassCommand.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands; 2 | 3 | import com.justindriggers.vulkan.command.CommandBuffer; 4 | 5 | import static org.lwjgl.vulkan.VK10.vkCmdEndRenderPass; 6 | 7 | public class EndRenderPassCommand implements Command { 8 | 9 | @Override 10 | public void execute(final CommandBuffer commandBuffer) { 11 | vkCmdEndRenderPass(commandBuffer.unwrap()); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/models/BufferImageCopy.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands.models; 2 | 3 | import com.justindriggers.vulkan.models.Extent3D; 4 | import com.justindriggers.vulkan.models.Offset3D; 5 | 6 | public class BufferImageCopy { 7 | 8 | private final long bufferOffset; 9 | private final int bufferRowLength; 10 | private final int bufferImageHeight; 11 | private final ImageSubresourceLayers imageSubresource; 12 | private final Offset3D imageOffset; 13 | private final Extent3D imageExtent; 14 | 15 | public BufferImageCopy(final long bufferOffset, 16 | final int bufferRowLength, 17 | final int bufferImageHeight, 18 | final ImageSubresourceLayers imageSubresource, 19 | final Offset3D imageOffset, 20 | final Extent3D imageExtent) { 21 | this.bufferOffset = bufferOffset; 22 | this.bufferRowLength = bufferRowLength; 23 | this.bufferImageHeight = bufferImageHeight; 24 | this.imageSubresource = imageSubresource; 25 | this.imageOffset = imageOffset; 26 | this.imageExtent = imageExtent; 27 | } 28 | 29 | public long getBufferOffset() { 30 | return bufferOffset; 31 | } 32 | 33 | public int getBufferRowLength() { 34 | return bufferRowLength; 35 | } 36 | 37 | public int getBufferImageHeight() { 38 | return bufferImageHeight; 39 | } 40 | 41 | public ImageSubresourceLayers getImageSubresource() { 42 | return imageSubresource; 43 | } 44 | 45 | public Offset3D getImageOffset() { 46 | return imageOffset; 47 | } 48 | 49 | public Extent3D getImageExtent() { 50 | return imageExtent; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/models/BufferMemoryBarrier.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands.models; 2 | 3 | import com.justindriggers.vulkan.buffer.Buffer; 4 | import com.justindriggers.vulkan.models.Access; 5 | import com.justindriggers.vulkan.queue.QueueFamily; 6 | 7 | import java.util.Set; 8 | 9 | public class BufferMemoryBarrier { 10 | 11 | private final Set sourceAccess; 12 | private final Set destinationAccess; 13 | private final QueueFamily sourceQueueFamily; 14 | private final QueueFamily destinationQueueFamily; 15 | private final Buffer buffer; 16 | private final long offset; 17 | private final long size; 18 | 19 | public BufferMemoryBarrier(final Set sourceAccess, 20 | final Set destinationAccess, 21 | final QueueFamily sourceQueueFamily, 22 | final QueueFamily destinationQueueFamily, 23 | final Buffer buffer, 24 | final long offset, 25 | final long size) { 26 | this.sourceAccess = sourceAccess; 27 | this.destinationAccess = destinationAccess; 28 | this.sourceQueueFamily = sourceQueueFamily; 29 | this.destinationQueueFamily = destinationQueueFamily; 30 | this.buffer = buffer; 31 | this.offset = offset; 32 | this.size = size; 33 | } 34 | 35 | public Set getSourceAccess() { 36 | return sourceAccess; 37 | } 38 | 39 | public Set getDestinationAccess() { 40 | return destinationAccess; 41 | } 42 | 43 | public QueueFamily getSourceQueueFamily() { 44 | return sourceQueueFamily; 45 | } 46 | 47 | public QueueFamily getDestinationQueueFamily() { 48 | return destinationQueueFamily; 49 | } 50 | 51 | public Buffer getBuffer() { 52 | return buffer; 53 | } 54 | 55 | public long getOffset() { 56 | return offset; 57 | } 58 | 59 | public long getSize() { 60 | return size; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/models/ImageCopy.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands.models; 2 | 3 | import com.justindriggers.vulkan.models.Extent3D; 4 | import com.justindriggers.vulkan.models.Offset3D; 5 | 6 | public class ImageCopy { 7 | 8 | private final ImageSubresourceLayers sourceSubresource; 9 | private final Offset3D sourceOffset; 10 | private final ImageSubresourceLayers destinationSubresource; 11 | private final Offset3D destinationOffset; 12 | private final Extent3D extent; 13 | 14 | public ImageCopy(final ImageSubresourceLayers sourceSubresource, 15 | final Offset3D sourceOffset, 16 | final ImageSubresourceLayers destinationSubresource, 17 | final Offset3D destinationOffset, 18 | final Extent3D extent) { 19 | this.sourceSubresource = sourceSubresource; 20 | this.sourceOffset = sourceOffset; 21 | this.destinationSubresource = destinationSubresource; 22 | this.destinationOffset = destinationOffset; 23 | this.extent = extent; 24 | } 25 | 26 | public ImageSubresourceLayers getSourceSubresource() { 27 | return sourceSubresource; 28 | } 29 | 30 | public Offset3D getSourceOffset() { 31 | return sourceOffset; 32 | } 33 | 34 | public ImageSubresourceLayers getDestinationSubresource() { 35 | return destinationSubresource; 36 | } 37 | 38 | public Offset3D getDestinationOffset() { 39 | return destinationOffset; 40 | } 41 | 42 | public Extent3D getExtent() { 43 | return extent; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/models/ImageMemoryBarrier.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands.models; 2 | 3 | import com.justindriggers.vulkan.image.Image; 4 | import com.justindriggers.vulkan.image.models.ImageLayout; 5 | import com.justindriggers.vulkan.models.Access; 6 | import com.justindriggers.vulkan.queue.QueueFamily; 7 | 8 | import java.util.Set; 9 | 10 | public class ImageMemoryBarrier { 11 | 12 | private final Set sourceAccess; 13 | private final Set destinationAccess; 14 | private final ImageLayout oldLayout; 15 | private final ImageLayout newLayout; 16 | private final QueueFamily sourceQueueFamily; 17 | private final QueueFamily destinationQueueFamily; 18 | private final Image image; 19 | private final ImageSubresourceRange subresourceRange; 20 | 21 | public ImageMemoryBarrier(final Set sourceAccess, 22 | final Set destinationAccess, 23 | final ImageLayout oldLayout, 24 | final ImageLayout newLayout, 25 | final QueueFamily sourceQueueFamily, 26 | final QueueFamily destinationQueueFamily, 27 | final Image image, 28 | final ImageSubresourceRange subresourceRange) { 29 | this.sourceAccess = sourceAccess; 30 | this.destinationAccess = destinationAccess; 31 | this.oldLayout = oldLayout; 32 | this.newLayout = newLayout; 33 | this.sourceQueueFamily = sourceQueueFamily; 34 | this.destinationQueueFamily = destinationQueueFamily; 35 | this.image = image; 36 | this.subresourceRange = subresourceRange; 37 | } 38 | 39 | public Set getSourceAccess() { 40 | return sourceAccess; 41 | } 42 | 43 | public Set getDestinationAccess() { 44 | return destinationAccess; 45 | } 46 | 47 | public ImageLayout getOldLayout() { 48 | return oldLayout; 49 | } 50 | 51 | public ImageLayout getNewLayout() { 52 | return newLayout; 53 | } 54 | 55 | public QueueFamily getSourceQueueFamily() { 56 | return sourceQueueFamily; 57 | } 58 | 59 | public QueueFamily getDestinationQueueFamily() { 60 | return destinationQueueFamily; 61 | } 62 | 63 | public Image getImage() { 64 | return image; 65 | } 66 | 67 | public ImageSubresourceRange getSubresourceRange() { 68 | return subresourceRange; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/models/ImageSubresourceLayers.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands.models; 2 | 3 | import com.justindriggers.vulkan.image.models.ImageAspect; 4 | 5 | import java.util.Set; 6 | 7 | public class ImageSubresourceLayers { 8 | 9 | private final Set aspects; 10 | private final int mipLevel; 11 | private final int baseArrayLayer; 12 | private final int layerCount; 13 | 14 | public ImageSubresourceLayers(final Set aspects, 15 | final int mipLevel, 16 | final int baseArrayLayer, 17 | final int layerCount) { 18 | this.aspects = aspects; 19 | this.mipLevel = mipLevel; 20 | this.baseArrayLayer = baseArrayLayer; 21 | this.layerCount = layerCount; 22 | } 23 | 24 | public Set getAspects() { 25 | return aspects; 26 | } 27 | 28 | public int getMipLevel() { 29 | return mipLevel; 30 | } 31 | 32 | public int getBaseArrayLayer() { 33 | return baseArrayLayer; 34 | } 35 | 36 | public int getLayerCount() { 37 | return layerCount; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/models/ImageSubresourceRange.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands.models; 2 | 3 | import com.justindriggers.vulkan.image.models.ImageAspect; 4 | 5 | import java.util.Set; 6 | 7 | public class ImageSubresourceRange { 8 | 9 | private final Set aspects; 10 | private final int baseMipLevel; 11 | private final int levelCount; 12 | private final int baseArrayLayer; 13 | private final int layerCount; 14 | 15 | public ImageSubresourceRange(final Set aspects, 16 | final int baseMipLevel, 17 | final int levelCount, 18 | final int baseArrayLayer, 19 | final int layerCount) { 20 | this.aspects = aspects; 21 | this.baseMipLevel = baseMipLevel; 22 | this.levelCount = levelCount; 23 | this.baseArrayLayer = baseArrayLayer; 24 | this.layerCount = layerCount; 25 | } 26 | 27 | public Set getAspects() { 28 | return aspects; 29 | } 30 | 31 | public int getBaseMipLevel() { 32 | return baseMipLevel; 33 | } 34 | 35 | public int getLevelCount() { 36 | return levelCount; 37 | } 38 | 39 | public int getBaseArrayLayer() { 40 | return baseArrayLayer; 41 | } 42 | 43 | public int getLayerCount() { 44 | return layerCount; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/commands/models/MemoryBarrier.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.commands.models; 2 | 3 | import com.justindriggers.vulkan.models.Access; 4 | 5 | import java.util.Set; 6 | 7 | public class MemoryBarrier { 8 | 9 | private final Set sourceAccess; 10 | private final Set destinationAccess; 11 | 12 | public MemoryBarrier(final Set sourceAccess, 13 | final Set destinationAccess) { 14 | this.sourceAccess = sourceAccess; 15 | this.destinationAccess = destinationAccess; 16 | } 17 | 18 | public Set getSourceAccess() { 19 | return sourceAccess; 20 | } 21 | 22 | public Set getDestinationAccess() { 23 | return destinationAccess; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/models/CommandBufferLevel.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum CommandBufferLevel implements HasValue { 7 | 8 | PRIMARY(VK10.VK_COMMAND_BUFFER_LEVEL_PRIMARY), 9 | SECONDARY(VK10.VK_COMMAND_BUFFER_LEVEL_SECONDARY); 10 | 11 | private final int value; 12 | 13 | CommandBufferLevel(final int value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Integer getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/models/CommandBufferUsage.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum CommandBufferUsage implements Maskable { 7 | 8 | ONE_TIME_SUBMIT(VK10.VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT), 9 | RENDER_PASS_CONTINUE(VK10.VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT), 10 | SIMULTANEOUS_USE(VK10.VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT); 11 | 12 | private final int bit; 13 | 14 | CommandBufferUsage(final int bit) { 15 | this.bit = bit; 16 | } 17 | 18 | @Override 19 | public int getBitValue() { 20 | return bit; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/command/models/CommandPoolCreateFlag.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.command.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | import org.lwjgl.vulkan.VK11; 6 | 7 | public enum CommandPoolCreateFlag implements Maskable { 8 | 9 | TRANSIENT(VK10.VK_COMMAND_POOL_CREATE_TRANSIENT_BIT), 10 | RESET_COMMAND_BUFFER(VK10.VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT), 11 | PROTECTED(VK11.VK_COMMAND_POOL_CREATE_PROTECTED_BIT); 12 | 13 | private final int bit; 14 | 15 | CommandPoolCreateFlag(final int bit) { 16 | this.bit = bit; 17 | } 18 | 19 | @Override 20 | public int getBitValue() { 21 | return bit; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/logical/DeviceMemory.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.logical; 2 | 3 | import com.justindriggers.vulkan.devices.physical.models.MemoryProperty; 4 | import com.justindriggers.vulkan.devices.physical.models.MemoryType; 5 | import com.justindriggers.vulkan.instance.VulkanFunction; 6 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 7 | import org.lwjgl.PointerBuffer; 8 | 9 | import java.util.Collections; 10 | import java.util.Optional; 11 | import java.util.concurrent.atomic.AtomicReference; 12 | 13 | import static org.lwjgl.system.MemoryUtil.memAllocPointer; 14 | import static org.lwjgl.system.MemoryUtil.memFree; 15 | import static org.lwjgl.vulkan.VK10.vkFreeMemory; 16 | import static org.lwjgl.vulkan.VK10.vkMapMemory; 17 | 18 | public class DeviceMemory extends DisposablePointer { 19 | 20 | private final AtomicReference mappedDeviceMemory = new AtomicReference<>(null); 21 | 22 | private final LogicalDevice device; 23 | private final MemoryType memoryType; 24 | private final long size; 25 | 26 | DeviceMemory(final LogicalDevice device, 27 | final MemoryType memoryType, 28 | final long address, 29 | final long size) { 30 | super(address); 31 | this.device = device; 32 | this.memoryType = memoryType; 33 | this.size = size; 34 | } 35 | 36 | @Override 37 | protected void dispose(final long address) { 38 | Optional.ofNullable(mappedDeviceMemory.getAndSet(null)) 39 | .ifPresent(MappedDeviceMemory::close); 40 | 41 | vkFreeMemory(device.unwrap(), address, null); 42 | } 43 | 44 | public MappedDeviceMemory map(final long size, final long offset) { 45 | return mappedDeviceMemory.updateAndGet(currentlyMappedDeviceMemory -> { 46 | if (currentlyMappedDeviceMemory != null) { 47 | throw new IllegalStateException("Device memory is already mapped"); 48 | } 49 | 50 | final MappedDeviceMemory result; 51 | 52 | final PointerBuffer data = memAllocPointer(1); 53 | 54 | try { 55 | VulkanFunction.execute(() -> vkMapMemory(device.unwrap(), getAddress(), offset, size, 0, data)); 56 | 57 | final boolean isCoherent = Optional.ofNullable(memoryType.getProperties()) 58 | .orElseGet(Collections::emptySet) 59 | .stream() 60 | .anyMatch(MemoryProperty.HOST_COHERENT::equals); 61 | 62 | result = new MappedDeviceMemory(device, this, data.get(0), isCoherent); 63 | } finally { 64 | memFree(data); 65 | } 66 | 67 | return result; 68 | }); 69 | } 70 | 71 | long getSize() { 72 | return size; 73 | } 74 | 75 | void unmap() { 76 | mappedDeviceMemory.set(null); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/logical/MappedDeviceMemory.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.logical; 2 | 3 | import com.justindriggers.vulkan.instance.VulkanFunction; 4 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 5 | import org.lwjgl.vulkan.VkMappedMemoryRange; 6 | 7 | import java.nio.ByteBuffer; 8 | 9 | import static org.lwjgl.system.MemoryUtil.memByteBuffer; 10 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; 11 | import static org.lwjgl.vulkan.VK10.VK_WHOLE_SIZE; 12 | import static org.lwjgl.vulkan.VK10.vkFlushMappedMemoryRanges; 13 | import static org.lwjgl.vulkan.VK10.vkUnmapMemory; 14 | 15 | public class MappedDeviceMemory extends DisposablePointer { 16 | 17 | private final LogicalDevice device; 18 | private final DeviceMemory deviceMemory; 19 | private final boolean isCoherent; 20 | 21 | MappedDeviceMemory(final LogicalDevice device, 22 | final DeviceMemory deviceMemory, 23 | final long address, 24 | final boolean isCoherent) { 25 | super(address); 26 | this.device = device; 27 | this.deviceMemory = deviceMemory; 28 | this.isCoherent = isCoherent; 29 | } 30 | 31 | @Override 32 | protected void dispose(final long address) { 33 | vkUnmapMemory(device.unwrap(), deviceMemory.getAddress()); 34 | deviceMemory.unmap(); 35 | } 36 | 37 | public ByteBuffer getBuffer() { 38 | return memByteBuffer(getAddress(), Math.toIntExact(deviceMemory.getSize())); 39 | } 40 | 41 | public void flush() { 42 | if (!isCoherent) { 43 | final VkMappedMemoryRange vkMappedMemoryRange = VkMappedMemoryRange.calloc() 44 | .sType(VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE) 45 | .memory(deviceMemory.getAddress()) 46 | .offset(0L) 47 | .size(VK_WHOLE_SIZE); 48 | 49 | try { 50 | VulkanFunction.execute(() -> vkFlushMappedMemoryRanges(device.unwrap(), vkMappedMemoryRange)); 51 | } finally { 52 | vkMappedMemoryRange.free(); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/FormatFeature.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.EXTSamplerFilterMinmax; 5 | import org.lwjgl.vulkan.IMGFilterCubic; 6 | import org.lwjgl.vulkan.VK10; 7 | import org.lwjgl.vulkan.VK11; 8 | 9 | public enum FormatFeature implements Maskable { 10 | 11 | SAMPLED_IMAGE(VK10.VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT), 12 | STORAGE_IMAGE(VK10.VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT), 13 | STORAGE_IMAGE_ATOMIC(VK10.VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT), 14 | COLOR_ATTACHMENT(VK10.VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT), 15 | COLOR_ATTACHMENT_BLEND(VK10.VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT), 16 | DEPTH_STENCIL_ATTACHMENT(VK10.VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT), 17 | BLIT_SRC(VK10.VK_FORMAT_FEATURE_BLIT_SRC_BIT), 18 | BLIT_DST(VK10.VK_FORMAT_FEATURE_BLIT_DST_BIT), 19 | SAMPLED_IMAGE_FILTER_LINEAR(VK10.VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT), 20 | TRANSFER_SRC(VK11.VK_FORMAT_FEATURE_TRANSFER_SRC_BIT), 21 | TRANSFER_DST(VK11.VK_FORMAT_FEATURE_TRANSFER_DST_BIT), 22 | SAMPLED_IMAGE_FILTER_MINMAX_EXT(EXTSamplerFilterMinmax.VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT), 23 | SAMPLED_IMAGE_FILTER_CUBIC_IMG(IMGFilterCubic.VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG), 24 | MIDPOINT_CHROMA_SAMPLES(VK11.VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT), 25 | COSITED_CHROMA_SAMPLES(VK11.VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT), 26 | SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER(VK11.VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT), 27 | SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER(VK11.VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT), 28 | SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT(VK11.VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT), 29 | SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE(VK11.VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT), 30 | DISJOINT(VK11.VK_FORMAT_FEATURE_DISJOINT_BIT); 31 | 32 | private final int bit; 33 | 34 | FormatFeature(final int bit) { 35 | this.bit = bit; 36 | } 37 | 38 | @Override 39 | public int getBitValue() { 40 | return bit; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/FormatProperties.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import java.util.Set; 4 | 5 | public class FormatProperties { 6 | 7 | private final Set linearTilingFeatures; 8 | private final Set optimalTilingFeatures; 9 | private final Set bufferFeatures; 10 | 11 | public FormatProperties(final Set linearTilingFeatures, 12 | final Set optimalTilingFeatures, 13 | final Set bufferFeatures) { 14 | this.linearTilingFeatures = linearTilingFeatures; 15 | this.optimalTilingFeatures = optimalTilingFeatures; 16 | this.bufferFeatures = bufferFeatures; 17 | } 18 | 19 | public Set getLinearTilingFeatures() { 20 | return linearTilingFeatures; 21 | } 22 | 23 | public Set getOptimalTilingFeatures() { 24 | return optimalTilingFeatures; 25 | } 26 | 27 | public Set getBufferFeatures() { 28 | return bufferFeatures; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/MemoryHeap.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VkMemoryHeap; 5 | 6 | import java.util.Objects; 7 | import java.util.Set; 8 | 9 | public class MemoryHeap { 10 | 11 | private final long size; 12 | private final Set flags; 13 | 14 | public MemoryHeap(final VkMemoryHeap vkMemoryHeap) { 15 | size = vkMemoryHeap.size(); 16 | flags = Maskable.fromBitMask(vkMemoryHeap.flags(), MemoryHeapFlag.class); 17 | } 18 | 19 | public long getSize() { 20 | return size; 21 | } 22 | 23 | public Set getFlags() { 24 | return flags; 25 | } 26 | 27 | @Override 28 | public boolean equals(Object o) { 29 | if (this == o) { 30 | return true; 31 | } 32 | 33 | if (o == null || getClass() != o.getClass()) { 34 | return false; 35 | } 36 | 37 | MemoryHeap that = (MemoryHeap) o; 38 | 39 | return size == that.size 40 | && Objects.equals(flags, that.flags); 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return Objects.hash( 46 | size, 47 | flags 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/MemoryHeapFlag.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | import org.lwjgl.vulkan.VK11; 6 | 7 | public enum MemoryHeapFlag implements Maskable { 8 | 9 | DEVICE_LOCAL(VK10.VK_MEMORY_HEAP_DEVICE_LOCAL_BIT), 10 | MULTI_INSTANCE(VK11.VK_MEMORY_HEAP_MULTI_INSTANCE_BIT); 11 | 12 | private final int bit; 13 | 14 | MemoryHeapFlag(final int bit) { 15 | this.bit = bit; 16 | } 17 | 18 | @Override 19 | public int getBitValue() { 20 | return bit; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/MemoryProperty.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum MemoryProperty implements Maskable { 7 | 8 | DEVICE_LOCAL(VK10.VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT), 9 | HOST_VISIBLE(VK10.VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT), 10 | HOST_COHERENT(VK10.VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), 11 | HOST_CACHED(VK10.VK_MEMORY_PROPERTY_HOST_CACHED_BIT), 12 | LAZILY_ALLOCATED(VK10.VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT); 13 | 14 | private final int bit; 15 | 16 | MemoryProperty(final int bit) { 17 | this.bit = bit; 18 | } 19 | 20 | @Override 21 | public int getBitValue() { 22 | return bit; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/MemoryType.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import java.util.Objects; 4 | import java.util.Set; 5 | 6 | public class MemoryType { 7 | 8 | private final int index; 9 | private final Set properties; 10 | private final MemoryHeap heap; 11 | 12 | public MemoryType(final int index, 13 | final Set properties, 14 | final MemoryHeap heap) { 15 | this.index = index; 16 | this.properties = properties; 17 | this.heap = heap; 18 | } 19 | 20 | public int getIndex() { 21 | return index; 22 | } 23 | 24 | public Set getProperties() { 25 | return properties; 26 | } 27 | 28 | public MemoryHeap getHeap() { 29 | return heap; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object o) { 34 | if (this == o) { 35 | return true; 36 | } 37 | 38 | if (o == null || getClass() != o.getClass()) { 39 | return false; 40 | } 41 | 42 | MemoryType that = (MemoryType) o; 43 | 44 | return index == that.index 45 | && Objects.equals(properties, that.properties) 46 | && Objects.equals(heap, that.heap); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return Objects.hash( 52 | index, 53 | properties, 54 | heap 55 | ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/PhysicalDeviceProperties.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VkPhysicalDeviceProperties; 5 | 6 | import java.util.Objects; 7 | import java.util.UUID; 8 | 9 | // TODO VkPhysicalDeviceLimits and VkPhysicalDeviceSparseProperties 10 | public class PhysicalDeviceProperties { 11 | 12 | private final int apiVersion; 13 | private final int driverVersion; 14 | private final int vendorId; 15 | private final int deviceId; 16 | private final PhysicalDeviceType deviceType; 17 | private final String deviceName; 18 | private final UUID pipelineCacheUuid; 19 | 20 | public PhysicalDeviceProperties(final VkPhysicalDeviceProperties vkPhysicalDeviceProperties) { 21 | this( 22 | vkPhysicalDeviceProperties.apiVersion(), 23 | vkPhysicalDeviceProperties.driverVersion(), 24 | vkPhysicalDeviceProperties.vendorID(), 25 | vkPhysicalDeviceProperties.deviceID(), 26 | HasValue.getByValue(vkPhysicalDeviceProperties.deviceType(), PhysicalDeviceType.class), 27 | vkPhysicalDeviceProperties.deviceNameString(), 28 | new UUID( 29 | vkPhysicalDeviceProperties.pipelineCacheUUID().getLong(), 30 | vkPhysicalDeviceProperties.pipelineCacheUUID().getLong() 31 | ) 32 | ); 33 | } 34 | 35 | public PhysicalDeviceProperties(final int apiVersion, 36 | final int driverVersion, 37 | final int vendorId, 38 | final int deviceId, 39 | final PhysicalDeviceType deviceType, 40 | final String deviceName, 41 | final UUID pipelineCacheUuid) { 42 | this.apiVersion = apiVersion; 43 | this.driverVersion = driverVersion; 44 | this.vendorId = vendorId; 45 | this.deviceId = deviceId; 46 | this.deviceType = deviceType; 47 | this.deviceName = deviceName; 48 | this.pipelineCacheUuid = pipelineCacheUuid; 49 | } 50 | 51 | public int getApiVersion() { 52 | return apiVersion; 53 | } 54 | 55 | public int getDriverVersion() { 56 | return driverVersion; 57 | } 58 | 59 | public int getVendorId() { 60 | return vendorId; 61 | } 62 | 63 | public int getDeviceId() { 64 | return deviceId; 65 | } 66 | 67 | public PhysicalDeviceType getDeviceType() { 68 | return deviceType; 69 | } 70 | 71 | public String getDeviceName() { 72 | return deviceName; 73 | } 74 | 75 | public UUID getPipelineCacheUuid() { 76 | return pipelineCacheUuid; 77 | } 78 | 79 | @Override 80 | public boolean equals(Object o) { 81 | if (this == o) { 82 | return true; 83 | } 84 | 85 | if (o == null || getClass() != o.getClass()) { 86 | return false; 87 | } 88 | 89 | PhysicalDeviceProperties that = (PhysicalDeviceProperties) o; 90 | 91 | return apiVersion == that.apiVersion && 92 | driverVersion == that.driverVersion && 93 | vendorId == that.vendorId && 94 | deviceId == that.deviceId && 95 | deviceType == that.deviceType && 96 | Objects.equals(deviceName, that.deviceName) && 97 | Objects.equals(pipelineCacheUuid, that.pipelineCacheUuid); 98 | } 99 | 100 | @Override 101 | public int hashCode() { 102 | return Objects.hash( 103 | apiVersion, 104 | driverVersion, 105 | vendorId, 106 | deviceId, 107 | deviceType, 108 | deviceName, 109 | pipelineCacheUuid 110 | ); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/devices/physical/models/PhysicalDeviceType.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.devices.physical.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum PhysicalDeviceType implements HasValue { 7 | 8 | OTHER(VK10.VK_PHYSICAL_DEVICE_TYPE_OTHER), 9 | INTEGRATED_GPU(VK10.VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU), 10 | DISCRETE_GPU(VK10.VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU), 11 | VIRTUAL_GPU(VK10.VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU), 12 | CPU(VK10.VK_PHYSICAL_DEVICE_TYPE_CPU); 13 | 14 | private final int value; 15 | 16 | PhysicalDeviceType(int value) { 17 | this.value = value; 18 | } 19 | 20 | @Override 21 | public Integer getValue() { 22 | return value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/ImageView.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | import com.justindriggers.vulkan.image.models.ImageAspect; 5 | import com.justindriggers.vulkan.image.models.ImageViewType; 6 | import com.justindriggers.vulkan.instance.VulkanFunction; 7 | import com.justindriggers.vulkan.models.Format; 8 | import com.justindriggers.vulkan.models.HasValue; 9 | import com.justindriggers.vulkan.models.Maskable; 10 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 11 | import org.lwjgl.vulkan.VkImageViewCreateInfo; 12 | 13 | import java.nio.LongBuffer; 14 | import java.util.Set; 15 | 16 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 17 | import static org.lwjgl.system.MemoryUtil.memFree; 18 | import static org.lwjgl.vulkan.VK10.VK_COMPONENT_SWIZZLE_IDENTITY; 19 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; 20 | import static org.lwjgl.vulkan.VK10.vkCreateImageView; 21 | import static org.lwjgl.vulkan.VK10.vkDestroyImageView; 22 | 23 | public class ImageView extends DisposablePointer { 24 | 25 | private final LogicalDevice device; 26 | 27 | public ImageView(final LogicalDevice device, 28 | final Image image, 29 | final ImageViewType viewType, 30 | final Format format, 31 | final Set aspects, 32 | final int mipLevelCount, 33 | final int layerCount) { 34 | super(createImageView(device, image, viewType, format, aspects, mipLevelCount, layerCount)); 35 | this.device = device; 36 | } 37 | 38 | @Override 39 | protected void dispose(final long address) { 40 | vkDestroyImageView(device.unwrap(), address, null); 41 | } 42 | 43 | private static long createImageView(final LogicalDevice device, 44 | final Image image, 45 | final ImageViewType viewType, 46 | final Format format, 47 | final Set aspects, 48 | final int mipLevelCount, 49 | final int layerCount) { 50 | final long result; 51 | 52 | final LongBuffer imageView = memAllocLong(1); 53 | 54 | final VkImageViewCreateInfo imageViewCreateInfo = VkImageViewCreateInfo.calloc() 55 | .sType(VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO) 56 | .image(image.getAddress()) 57 | .viewType(HasValue.getValue(viewType)) 58 | .format(HasValue.getValue(format)); 59 | 60 | imageViewCreateInfo.components() 61 | .r(VK_COMPONENT_SWIZZLE_IDENTITY) 62 | .g(VK_COMPONENT_SWIZZLE_IDENTITY) 63 | .b(VK_COMPONENT_SWIZZLE_IDENTITY) 64 | .a(VK_COMPONENT_SWIZZLE_IDENTITY); 65 | 66 | imageViewCreateInfo.subresourceRange() 67 | .aspectMask(Maskable.toBitMask(aspects)) 68 | .baseMipLevel(0) 69 | .levelCount(mipLevelCount) 70 | .baseArrayLayer(0) 71 | .layerCount(layerCount); 72 | 73 | try { 74 | VulkanFunction.execute(() -> vkCreateImageView(device.unwrap(), imageViewCreateInfo, null, imageView)); 75 | 76 | result = imageView.get(0); 77 | } finally { 78 | memFree(imageView); 79 | 80 | imageViewCreateInfo.free(); 81 | } 82 | 83 | return result; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/SwapchainImage.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image; 2 | 3 | public class SwapchainImage extends Image { 4 | 5 | public SwapchainImage(final long handle) { 6 | super(handle); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/models/ImageAspect.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum ImageAspect implements Maskable { 7 | 8 | COLOR(VK10.VK_IMAGE_ASPECT_COLOR_BIT), 9 | DEPTH(VK10.VK_IMAGE_ASPECT_DEPTH_BIT), 10 | STENCIL(VK10.VK_IMAGE_ASPECT_STENCIL_BIT), 11 | METADATA(VK10.VK_IMAGE_ASPECT_METADATA_BIT); 12 | 13 | private final int bit; 14 | 15 | ImageAspect(final int bit) { 16 | this.bit = bit; 17 | } 18 | 19 | @Override 20 | public int getBitValue() { 21 | return bit; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/models/ImageCreateFlag.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.EXTSampleLocations; 5 | import org.lwjgl.vulkan.VK10; 6 | import org.lwjgl.vulkan.VK11; 7 | 8 | public enum ImageCreateFlag implements Maskable { 9 | 10 | SPARSE_BINDING(VK10.VK_IMAGE_CREATE_SPARSE_BINDING_BIT), 11 | SPARSE_RESIDENCY(VK10.VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT), 12 | SPARSE_ALIASED(VK10.VK_IMAGE_CREATE_SPARSE_ALIASED_BIT), 13 | MUTABLE_FORMAT(VK10.VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT), 14 | CUBE_COMPATIBLE(VK10.VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT), 15 | TWO_DIMENSIONAL_ARRAY_COMPATIBLE(VK11.VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT), 16 | PROTECTED(VK11.VK_IMAGE_CREATE_PROTECTED_BIT), 17 | SPLIT_INSTANCE_BIND_REGIONS(VK11.VK_IMAGE_CREATE_SPLIT_INSTANCE_BIND_REGIONS_BIT), 18 | BLOCK_TEXEL_VIEW_COMPATIBLE(VK11.VK_IMAGE_CREATE_BLOCK_TEXEL_VIEW_COMPATIBLE_BIT), 19 | EXTENDED_USAGE(VK11.VK_IMAGE_CREATE_EXTENDED_USAGE_BIT), 20 | DISJOINT(VK11.VK_IMAGE_CREATE_DISJOINT_BIT), 21 | ALIAS(VK11.VK_IMAGE_CREATE_ALIAS_BIT), 22 | SAMPLE_LOCATIONS_COMPATIBLE_DEPTH(EXTSampleLocations.VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT); 23 | 24 | private final int bit; 25 | 26 | ImageCreateFlag(final int bit) { 27 | this.bit = bit; 28 | } 29 | 30 | @Override 31 | public int getBitValue() { 32 | return bit; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/models/ImageLayout.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.KHRSharedPresentableImage; 5 | import org.lwjgl.vulkan.KHRSwapchain; 6 | import org.lwjgl.vulkan.VK10; 7 | import org.lwjgl.vulkan.VK11; 8 | 9 | public enum ImageLayout implements HasValue { 10 | 11 | UNDEFINED(VK10.VK_IMAGE_LAYOUT_UNDEFINED), 12 | PREINITIALIZED(VK10.VK_IMAGE_LAYOUT_PREINITIALIZED), 13 | GENERAL(VK10.VK_IMAGE_LAYOUT_GENERAL), 14 | COLOR_ATTACHMENT_OPTIMAL(VK10.VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL), 15 | DEPTH_STENCIL_ATTACHMENT_OPTIMAL(VK10.VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL), 16 | DEPTH_STENCIL_READ_ONLY_OPTIMAL(VK10.VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL), 17 | DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL(VK11.VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL), 18 | DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL(VK11.VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL), 19 | SHADER_READ_ONLY_OPTIMAL(VK10.VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL), 20 | TRANSFER_SRC_OPTIMAL(VK10.VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL), 21 | TRANSFER_DST_OPTIMAL(VK10.VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL), 22 | PRESENT_SRC(KHRSwapchain.VK_IMAGE_LAYOUT_PRESENT_SRC_KHR), 23 | SHARED_PRESENT(KHRSharedPresentableImage.VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR); 24 | 25 | private final int value; 26 | 27 | ImageLayout(final int value) { 28 | this.value = value; 29 | } 30 | 31 | @Override 32 | public Integer getValue() { 33 | return value; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/models/ImageTiling.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum ImageTiling implements HasValue { 7 | 8 | OPTIMAL(VK10.VK_IMAGE_TILING_OPTIMAL), 9 | LINEAR(VK10.VK_IMAGE_TILING_LINEAR); 10 | 11 | private final int value; 12 | 13 | ImageTiling(final int value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Integer getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/models/ImageType.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum ImageType implements HasValue { 7 | 8 | ONE_DIMENSIONAL(VK10.VK_IMAGE_TYPE_1D), 9 | TWO_DIMENSIONAL(VK10.VK_IMAGE_TYPE_2D), 10 | THREE_DIMENSIONAL(VK10.VK_IMAGE_TYPE_3D); 11 | 12 | private final int value; 13 | 14 | ImageType(final int value) { 15 | this.value = value; 16 | } 17 | 18 | @Override 19 | public Integer getValue() { 20 | return value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/models/ImageUsage.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum ImageUsage implements Maskable { 7 | 8 | TRANSFER_SRC(VK10.VK_IMAGE_USAGE_TRANSFER_SRC_BIT), 9 | TRANSFER_DST(VK10.VK_IMAGE_USAGE_TRANSFER_DST_BIT), 10 | SAMPLED(VK10.VK_IMAGE_USAGE_SAMPLED_BIT), 11 | STORAGE(VK10.VK_IMAGE_USAGE_STORAGE_BIT), 12 | COLOR_ATTACHMENT(VK10.VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT), 13 | DEPTH_STENCIL_ATTACHMENT(VK10.VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT), 14 | TRANSIENT_ATTACHMENT(VK10.VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT), 15 | INPUT_ATTACHMENT(VK10.VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT); 16 | 17 | private final int bit; 18 | 19 | ImageUsage(final int bit) { 20 | this.bit = bit; 21 | } 22 | 23 | @Override 24 | public int getBitValue() { 25 | return bit; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/image/models/ImageViewType.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.image.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum ImageViewType implements HasValue { 7 | 8 | ONE_DIMENSIONAL(VK10.VK_IMAGE_VIEW_TYPE_1D), 9 | TWO_DIMENSIONAL(VK10.VK_IMAGE_VIEW_TYPE_2D), 10 | THREE_DIMENSIONAL(VK10.VK_IMAGE_VIEW_TYPE_3D), 11 | CUBE(VK10.VK_IMAGE_VIEW_TYPE_CUBE), 12 | ONE_DIMENSIONAL_ARRAY(VK10.VK_IMAGE_VIEW_TYPE_1D_ARRAY), 13 | TWO_DIMENSIONAL_ARRAY(VK10.VK_IMAGE_VIEW_TYPE_2D_ARRAY), 14 | CUBE_ARRAY(VK10.VK_IMAGE_VIEW_TYPE_CUBE_ARRAY); 15 | 16 | private final int value; 17 | 18 | ImageViewType(final int value) { 19 | this.value = value; 20 | } 21 | 22 | @Override 23 | public Integer getValue() { 24 | return value; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/DebugLogger.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance; 2 | 3 | import com.justindriggers.vulkan.instance.models.MessageSeverity; 4 | import com.justindriggers.vulkan.instance.models.MessageType; 5 | import com.justindriggers.vulkan.models.Maskable; 6 | import org.lwjgl.vulkan.VkDebugUtilsMessengerCallbackDataEXT; 7 | import org.lwjgl.vulkan.VkDebugUtilsMessengerCallbackEXTI; 8 | 9 | import java.util.logging.Level; 10 | import java.util.logging.Logger; 11 | 12 | import static org.lwjgl.vulkan.VK10.VK_FALSE; 13 | 14 | public class DebugLogger implements VkDebugUtilsMessengerCallbackEXTI { 15 | 16 | private static final Logger LOGGER = Logger.getLogger(DebugLogger.class.getName()); 17 | 18 | /** 19 | * Creates an instance of {@link VkDebugUtilsMessengerCallbackDataEXT} by referencing the callback data pointer. 20 | * 21 | * Since the struct was allocated outside of the scope of this method, and simply referenced by address, it should 22 | * not be destroyed here. 23 | */ 24 | @SuppressWarnings("squid:S2095") 25 | @Override 26 | public int invoke(final int messageSeverity, final int messageType, final long callbackDataPointer, 27 | final long userDataPointer) { 28 | final Level level = Maskable.fromBit(messageSeverity, MessageSeverity.class).getLevel(); 29 | final MessageType type = Maskable.fromBit(messageType, MessageType.class); 30 | 31 | final VkDebugUtilsMessengerCallbackDataEXT callbackData = VkDebugUtilsMessengerCallbackDataEXT.create( 32 | callbackDataPointer); 33 | 34 | LOGGER.log(level, () -> String.format("[%s] %s", type, callbackData.pMessageString())); 35 | 36 | return VK_FALSE; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/VulkanFunction.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance; 2 | 3 | import com.justindriggers.vulkan.instance.models.VulkanException; 4 | import com.justindriggers.vulkan.instance.models.VulkanResult; 5 | import com.justindriggers.vulkan.models.HasValue; 6 | 7 | import java.util.Optional; 8 | 9 | @FunctionalInterface 10 | public interface VulkanFunction { 11 | 12 | int getResult(); 13 | 14 | default void execute() { 15 | Optional.of(getResult()) 16 | .map(code -> HasValue.getByValue(code, VulkanResult.class)) 17 | .filter(result -> !VulkanResult.SUCCESS.equals(result)) 18 | .map(VulkanException::new) 19 | .ifPresent(exception -> { 20 | throw exception; 21 | }); 22 | } 23 | 24 | static void execute(final VulkanFunction vulkanFunction) { 25 | vulkanFunction.execute(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/models/ApplicationInfo.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance.models; 2 | 3 | public class ApplicationInfo { 4 | 5 | private final String applicationName; 6 | private final int applicationVersion; 7 | private final String engineName; 8 | private final int engineVersion; 9 | private final VulkanVersion apiVersion; 10 | 11 | public ApplicationInfo(final String applicationName, 12 | final int applicationVersion, 13 | final String engineName, 14 | final int engineVersion, 15 | final VulkanVersion apiVersion) { 16 | this.applicationName = applicationName; 17 | this.applicationVersion = applicationVersion; 18 | this.engineName = engineName; 19 | this.engineVersion = engineVersion; 20 | this.apiVersion = apiVersion; 21 | } 22 | 23 | public String getApplicationName() { 24 | return applicationName; 25 | } 26 | 27 | public int getApplicationVersion() { 28 | return applicationVersion; 29 | } 30 | 31 | public String getEngineName() { 32 | return engineName; 33 | } 34 | 35 | public int getEngineVersion() { 36 | return engineVersion; 37 | } 38 | 39 | public VulkanVersion getApiVersion() { 40 | return apiVersion; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/models/MessageSeverity.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.EXTDebugUtils; 5 | 6 | import java.util.logging.Level; 7 | 8 | public enum MessageSeverity implements Maskable { 9 | 10 | VERBOSE(EXTDebugUtils.VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT, Level.FINE), 11 | INFO(EXTDebugUtils.VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT, Level.INFO), 12 | WARNING(EXTDebugUtils.VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT, Level.WARNING), 13 | ERROR(EXTDebugUtils.VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT, Level.SEVERE); 14 | 15 | private final int bit; 16 | private final Level level; 17 | 18 | MessageSeverity(final int bit, 19 | final Level level) { 20 | this.bit = bit; 21 | this.level = level; 22 | } 23 | 24 | @Override 25 | public int getBitValue() { 26 | return bit; 27 | } 28 | 29 | public Level getLevel() { 30 | return level; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/models/MessageType.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.EXTDebugUtils; 5 | 6 | public enum MessageType implements Maskable { 7 | 8 | GENERAL(EXTDebugUtils.VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT), 9 | VALIDATION(EXTDebugUtils.VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT), 10 | PERFORMANCE(EXTDebugUtils.VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT); 11 | 12 | private final int bit; 13 | 14 | MessageType(final int bit) { 15 | this.bit = bit; 16 | } 17 | 18 | @Override 19 | public int getBitValue() { 20 | return bit; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/models/VulkanException.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance.models; 2 | 3 | public class VulkanException extends RuntimeException { 4 | 5 | private final VulkanResult result; 6 | 7 | public VulkanException(final VulkanResult result) { 8 | super(String.format("%s (%d)", result.toString(), result.getValue())); 9 | 10 | this.result = result; 11 | } 12 | 13 | public VulkanResult getResult() { 14 | return result; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/models/VulkanResult.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.KHRDisplaySwapchain; 5 | import org.lwjgl.vulkan.KHRSurface; 6 | import org.lwjgl.vulkan.KHRSwapchain; 7 | import org.lwjgl.vulkan.VK10; 8 | 9 | public enum VulkanResult implements HasValue { 10 | 11 | SUCCESS(VK10.VK_SUCCESS), 12 | NOT_READY(VK10.VK_NOT_READY), 13 | TIMEOUT(VK10.VK_TIMEOUT), 14 | EVENT_SET(VK10.VK_EVENT_SET), 15 | EVENT_RESET(VK10.VK_EVENT_RESET), 16 | INCOMPLETE(VK10.VK_INCOMPLETE), 17 | SUBOPTIMAL(KHRSwapchain.VK_SUBOPTIMAL_KHR), 18 | 19 | ERROR_OUT_OF_HOST_MEMORY(VK10.VK_ERROR_OUT_OF_HOST_MEMORY), 20 | ERROR_OUT_OF_DEVICE_MEMORY(VK10.VK_ERROR_OUT_OF_DEVICE_MEMORY), 21 | ERROR_INITIALIZATION_FAILED(VK10.VK_ERROR_INITIALIZATION_FAILED), 22 | ERROR_DEVICE_LOST(VK10.VK_ERROR_DEVICE_LOST), 23 | ERROR_MEMORY_MAP_FAILED(VK10.VK_ERROR_MEMORY_MAP_FAILED), 24 | ERROR_LAYER_NOT_PRESENT(VK10.VK_ERROR_LAYER_NOT_PRESENT), 25 | ERROR_EXTENSION_NOT_PRESENT(VK10.VK_ERROR_EXTENSION_NOT_PRESENT), 26 | ERROR_FEATURE_NOT_PRESENT(VK10.VK_ERROR_FEATURE_NOT_PRESENT), 27 | ERROR_INCOMPATIBLE_DRIVER(VK10.VK_ERROR_INCOMPATIBLE_DRIVER), 28 | ERROR_TOO_MANY_OBJECTS(VK10.VK_ERROR_TOO_MANY_OBJECTS), 29 | ERROR_FORMAT_NOT_SUPPORTED(VK10.VK_ERROR_FORMAT_NOT_SUPPORTED), 30 | ERROR_FRAGMENTED_POOL(VK10.VK_ERROR_FRAGMENTED_POOL), 31 | ERROR_SURFACE_LOST(KHRSurface.VK_ERROR_SURFACE_LOST_KHR), 32 | ERROR_NATIVE_WINDOW_IN_USE(KHRSurface.VK_ERROR_NATIVE_WINDOW_IN_USE_KHR), 33 | ERROR_OUT_OF_DATE(KHRSwapchain.VK_ERROR_OUT_OF_DATE_KHR), 34 | ERROR_INCOMPATIBLE_DISPLAY(KHRDisplaySwapchain.VK_ERROR_INCOMPATIBLE_DISPLAY_KHR), 35 | 36 | UNKNOWN(null); 37 | 38 | private final Integer code; 39 | 40 | VulkanResult(final Integer code) { 41 | this.code = code; 42 | } 43 | 44 | @Override 45 | public Integer getValue() { 46 | return code; 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/instance/models/VulkanVersion.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.instance.models; 2 | 3 | public class VulkanVersion { 4 | 5 | private final int major; 6 | private final int minor; 7 | private final int patch; 8 | 9 | public VulkanVersion(final int major, 10 | final int minor, 11 | final int patch) { 12 | this.major = major; 13 | this.minor = minor; 14 | this.patch = patch; 15 | } 16 | 17 | public int getMajor() { 18 | return major; 19 | } 20 | 21 | public int getMinor() { 22 | return minor; 23 | } 24 | 25 | public int getPatch() { 26 | return patch; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Access.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.EXTBlendOperationAdvanced; 4 | import org.lwjgl.vulkan.EXTConditionalRendering; 5 | import org.lwjgl.vulkan.NVXDeviceGeneratedCommands; 6 | import org.lwjgl.vulkan.VK10; 7 | 8 | public enum Access implements Maskable { 9 | 10 | INDIRECT_COMMAND_READ(VK10.VK_ACCESS_INDIRECT_COMMAND_READ_BIT), 11 | INDEX_READ(VK10.VK_ACCESS_INDEX_READ_BIT), 12 | VERTEX_ATTRIBUTE_READ(VK10.VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT), 13 | UNIFORM_READ(VK10.VK_ACCESS_UNIFORM_READ_BIT), 14 | INPUT_ATTACHMENT_READ(VK10.VK_ACCESS_INPUT_ATTACHMENT_READ_BIT), 15 | SHADER_READ(VK10.VK_ACCESS_SHADER_READ_BIT), 16 | SHADER_WRITE(VK10.VK_ACCESS_SHADER_WRITE_BIT), 17 | COLOR_ATTACHMENT_READ(VK10.VK_ACCESS_COLOR_ATTACHMENT_READ_BIT), 18 | COLOR_ATTACHMENT_WRITE(VK10.VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT), 19 | DEPTH_STENCIL_ATTACHMENT_READ(VK10.VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT), 20 | DEPTH_STENCIL_ATTACHMENT_WRITE(VK10.VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT), 21 | TRANSFER_READ(VK10.VK_ACCESS_TRANSFER_READ_BIT), 22 | TRANSFER_WRITE(VK10.VK_ACCESS_TRANSFER_WRITE_BIT), 23 | HOST_READ(VK10.VK_ACCESS_HOST_READ_BIT), 24 | HOST_WRITE(VK10.VK_ACCESS_HOST_WRITE_BIT), 25 | MEMORY_READ(VK10.VK_ACCESS_MEMORY_READ_BIT), 26 | MEMORY_WRITE(VK10.VK_ACCESS_MEMORY_WRITE_BIT), 27 | CONDITIONAL_RENDERING_READ(EXTConditionalRendering.VK_ACCESS_CONDITIONAL_RENDERING_READ_BIT_EXT), 28 | COMMAND_PROCESS_READ(NVXDeviceGeneratedCommands.VK_ACCESS_COMMAND_PROCESS_READ_BIT_NVX), 29 | COMMAND_PROCESS_WRITE(NVXDeviceGeneratedCommands.VK_ACCESS_COMMAND_PROCESS_WRITE_BIT_NVX), 30 | COLOR_ATTACHMENT_READ_NONCOHERENT(EXTBlendOperationAdvanced.VK_ACCESS_COLOR_ATTACHMENT_READ_NONCOHERENT_BIT_EXT); 31 | 32 | private final int bit; 33 | 34 | Access(final int bit) { 35 | this.bit = bit; 36 | } 37 | 38 | @Override 39 | public int getBitValue() { 40 | return bit; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/ColorSpace.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.EXTSwapchainColorspace; 4 | import org.lwjgl.vulkan.KHRSurface; 5 | 6 | public enum ColorSpace implements HasValue { 7 | 8 | SRGB_NONLINEAR(KHRSurface.VK_COLOR_SPACE_SRGB_NONLINEAR_KHR), 9 | DISPLAY_P3_NONLINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT), 10 | EXTENDED_SRGB_LINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT), 11 | DCI_P3_LINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_DCI_P3_LINEAR_EXT), 12 | DCI_P3_NONLINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT), 13 | BT709_LINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_BT709_LINEAR_EXT), 14 | BT709_NONLINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_BT709_NONLINEAR_EXT), 15 | BT2020_LINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_BT2020_LINEAR_EXT), 16 | HDR10_ST2084(EXTSwapchainColorspace.VK_COLOR_SPACE_HDR10_ST2084_EXT), 17 | DOLBYVISION(EXTSwapchainColorspace.VK_COLOR_SPACE_DOLBYVISION_EXT), 18 | HDR10_HLG(EXTSwapchainColorspace.VK_COLOR_SPACE_HDR10_HLG_EXT), 19 | ADOBERGB_LINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT), 20 | ADOBERGB_NONLINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT), 21 | PASS_THROUGH(EXTSwapchainColorspace.VK_COLOR_SPACE_PASS_THROUGH_EXT), 22 | EXTENDED_SRGB_NONLINEAR(EXTSwapchainColorspace.VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT); 23 | 24 | private final int value; 25 | 26 | ColorSpace(final int value) { 27 | this.value = value; 28 | } 29 | 30 | @Override 31 | public Integer getValue() { 32 | return value; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Dependency.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.VK10; 4 | import org.lwjgl.vulkan.VK11; 5 | 6 | public enum Dependency implements Maskable { 7 | 8 | BY_REGION(VK10.VK_DEPENDENCY_BY_REGION_BIT), 9 | VIEW_LOCAL(VK11.VK_DEPENDENCY_VIEW_LOCAL_BIT), 10 | DEVICE_GROUP(VK11.VK_DEPENDENCY_DEVICE_GROUP_BIT); 11 | 12 | private final int bit; 13 | 14 | Dependency(final int bit) { 15 | this.bit = bit; 16 | } 17 | 18 | @Override 19 | public int getBitValue() { 20 | return bit; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Extension.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.VkExtensionProperties; 4 | 5 | import java.util.Objects; 6 | 7 | public class Extension { 8 | 9 | private final String name; 10 | private final int version; 11 | 12 | public Extension(final VkExtensionProperties vkExtensionProperties) { 13 | this( 14 | vkExtensionProperties.extensionNameString(), 15 | vkExtensionProperties.specVersion() 16 | ); 17 | } 18 | 19 | public Extension(final String name, 20 | final int version) { 21 | this.name = name; 22 | this.version = version; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public int getVersion() { 30 | return version; 31 | } 32 | 33 | @Override 34 | public boolean equals(Object o) { 35 | if (this == o) { 36 | return true; 37 | } 38 | 39 | if (o == null || getClass() != o.getClass()) { 40 | return false; 41 | } 42 | 43 | Extension that = (Extension) o; 44 | 45 | return version == that.version && 46 | Objects.equals(name, that.name); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return Objects.hash( 52 | name, 53 | version 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Extent2D.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.VkExtent2D; 4 | 5 | import java.util.Objects; 6 | 7 | public class Extent2D { 8 | 9 | private final int width; 10 | private final int height; 11 | 12 | public Extent2D(final VkExtent2D vkExtent2D) { 13 | this(vkExtent2D.width(), vkExtent2D.height()); 14 | } 15 | 16 | public Extent2D(final int width, final int height) { 17 | this.width = width; 18 | this.height = height; 19 | } 20 | 21 | public int getWidth() { 22 | return width; 23 | } 24 | 25 | public int getHeight() { 26 | return height; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object o) { 31 | if (this == o) { 32 | return true; 33 | } 34 | 35 | if (o == null || getClass() != o.getClass()) { 36 | return false; 37 | } 38 | 39 | Extent2D extent2D = (Extent2D) o; 40 | 41 | return width == extent2D.width && 42 | height == extent2D.height; 43 | } 44 | 45 | @Override 46 | public int hashCode() { 47 | return Objects.hash( 48 | width, 49 | height 50 | ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Extent3D.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.VkExtent3D; 4 | 5 | import java.util.Objects; 6 | 7 | public class Extent3D extends Extent2D { 8 | 9 | private final int depth; 10 | 11 | public Extent3D(final VkExtent3D vkExtent3D) { 12 | this(vkExtent3D.width(), vkExtent3D.height(), vkExtent3D.depth()); 13 | } 14 | 15 | public Extent3D(final int width, final int height, final int depth) { 16 | super(width, height); 17 | 18 | this.depth = depth; 19 | } 20 | 21 | public int getDepth() { 22 | return depth; 23 | } 24 | 25 | @Override 26 | public boolean equals(Object o) { 27 | if (this == o) { 28 | return true; 29 | } 30 | 31 | if (!(o instanceof Extent3D)) { 32 | return false; 33 | } 34 | 35 | if (!super.equals(o)) { 36 | return false; 37 | } 38 | 39 | Extent3D extent3D = (Extent3D) o; 40 | 41 | return depth == extent3D.depth; 42 | } 43 | 44 | @Override 45 | public int hashCode() { 46 | return Objects.hash( 47 | super.hashCode(), 48 | depth 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/HasValue.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import java.util.Arrays; 4 | import java.util.Objects; 5 | 6 | public interface HasValue { 7 | 8 | T getValue(); 9 | 10 | static & HasValue> T getValue(E enumValue) { 11 | Objects.requireNonNull(enumValue); 12 | 13 | return enumValue.getValue(); 14 | } 15 | 16 | static & HasValue> E getByValue(T value, Class enumType) { 17 | Objects.requireNonNull(enumType); 18 | 19 | return Arrays.stream(enumType.getEnumConstants()) 20 | .filter(enumValue -> Objects.nonNull(enumValue.getValue())) 21 | .filter(enumValue -> value.equals(enumValue.getValue())) 22 | .findFirst() 23 | .orElse(null); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Maskable.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.EnumSet; 6 | import java.util.Objects; 7 | import java.util.Optional; 8 | import java.util.Set; 9 | import java.util.stream.Collectors; 10 | import java.util.stream.Stream; 11 | 12 | public interface Maskable { 13 | 14 | int getBitValue(); 15 | 16 | static & Maskable> E fromBit(final int bit, final Class enumType) { 17 | Objects.requireNonNull(enumType); 18 | 19 | return Arrays.stream(enumType.getEnumConstants()) 20 | .filter(enumValue -> enumValue.getBitValue() == bit) 21 | .findFirst() 22 | .orElseThrow(() -> new IllegalArgumentException("Unrecognized bit value: " + bit)); 23 | } 24 | 25 | static & Maskable> int toBit(final E enumValue) { 26 | return Optional.ofNullable(enumValue) 27 | .map(Maskable.class::cast) 28 | .map(Maskable::getBitValue) 29 | .orElse(0); 30 | } 31 | 32 | static & Maskable> Set fromBitMask(final int bitmask, final Class enumType) { 33 | Objects.requireNonNull(enumType); 34 | 35 | return Arrays.stream(enumType.getEnumConstants()) 36 | .filter(enumValue -> (enumValue.getBitValue() & bitmask) != 0) 37 | .collect(Collectors.toCollection(() -> EnumSet.noneOf(enumType))); 38 | } 39 | 40 | @SafeVarargs 41 | static & Maskable> int toBitMask(final E... enumValues) { 42 | final Stream enumStream = Optional.ofNullable(enumValues) 43 | .map(Arrays::stream) 44 | .orElseGet(Stream::empty); 45 | 46 | return toBitMask(enumStream); 47 | } 48 | 49 | static & Maskable> int toBitMask(final Set enumSet) { 50 | final Stream enumStream = Optional.ofNullable(enumSet) 51 | .orElseGet(Collections::emptySet) 52 | .stream(); 53 | 54 | return toBitMask(enumStream); 55 | } 56 | 57 | static & Maskable> int toBitMask(final Stream enumStream) { 58 | return Optional.ofNullable(enumStream) 59 | .orElseGet(Stream::empty) 60 | .map(Maskable.class::cast) 61 | .mapToInt(Maskable::getBitValue) 62 | .reduce((a, b) -> a | b) 63 | .orElse(0); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Offset2D.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | public class Offset2D { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public Offset2D(final int x, 9 | final int y) { 10 | this.x = x; 11 | this.y = y; 12 | } 13 | 14 | public int getX() { 15 | return x; 16 | } 17 | 18 | public int getY() { 19 | return y; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Offset3D.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | public class Offset3D extends Offset2D { 4 | 5 | private final int z; 6 | 7 | public Offset3D(final int x, final int y, final int z) { 8 | super(x, y); 9 | this.z = z; 10 | } 11 | 12 | public int getZ() { 13 | return z; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/Rect2D.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | public class Rect2D { 4 | 5 | private final Offset2D offset; 6 | private final Extent2D extent; 7 | 8 | public Rect2D(final Offset2D offset, 9 | final Extent2D extent) { 10 | this.offset = offset; 11 | this.extent = extent; 12 | } 13 | 14 | public Rect2D(final int x, 15 | final int y, 16 | final int width, 17 | final int height) { 18 | this.offset = new Offset2D(x, y); 19 | this.extent = new Extent2D(width, height); 20 | } 21 | 22 | public Offset2D getOffset() { 23 | return offset; 24 | } 25 | 26 | public Extent2D getExtent() { 27 | return extent; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/SampleCount.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.VK10; 4 | 5 | public enum SampleCount implements Maskable { 6 | 7 | ONE(VK10.VK_SAMPLE_COUNT_1_BIT), 8 | TWO(VK10.VK_SAMPLE_COUNT_2_BIT), 9 | FOUR(VK10.VK_SAMPLE_COUNT_4_BIT), 10 | EIGHT(VK10.VK_SAMPLE_COUNT_8_BIT), 11 | SIXTEEN(VK10.VK_SAMPLE_COUNT_16_BIT), 12 | THIRTY_TWO(VK10.VK_SAMPLE_COUNT_32_BIT), 13 | SIXTY_FOUR(VK10.VK_SAMPLE_COUNT_64_BIT); 14 | 15 | private final int bit; 16 | 17 | SampleCount(final int bit) { 18 | this.bit = bit; 19 | } 20 | 21 | @Override 22 | public int getBitValue() { 23 | return bit; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/SharingMode.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models; 2 | 3 | import org.lwjgl.vulkan.VK10; 4 | 5 | public enum SharingMode implements HasValue { 6 | 7 | EXCLUSIVE(VK10.VK_SHARING_MODE_EXCLUSIVE), 8 | CONCURRENT(VK10.VK_SHARING_MODE_CONCURRENT); 9 | 10 | private final int value; 11 | 12 | SharingMode(final int value) { 13 | this.value = value; 14 | } 15 | 16 | @Override 17 | public Integer getValue() { 18 | return value; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/clear/ClearColor.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.clear; 2 | 3 | public abstract class ClearColor extends ClearValue { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/clear/ClearColorFloat.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.clear; 2 | 3 | import org.lwjgl.vulkan.VkClearValue; 4 | 5 | public class ClearColorFloat extends ClearColor { 6 | 7 | private final float r; 8 | private final float g; 9 | private final float b; 10 | private final float a; 11 | 12 | public ClearColorFloat(final float r, final float g, final float b, final float a) { 13 | this.r = r; 14 | this.g = g; 15 | this.b = b; 16 | this.a = a; 17 | } 18 | 19 | @Override 20 | public VkClearValue toStruct() { 21 | final VkClearValue result = VkClearValue.calloc(); 22 | 23 | result.color() 24 | .float32(0, r) 25 | .float32(1, g) 26 | .float32(2, b) 27 | .float32(3, a); 28 | 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/clear/ClearColorInt.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.clear; 2 | 3 | import org.lwjgl.vulkan.VkClearValue; 4 | 5 | public class ClearColorInt extends ClearColor { 6 | 7 | private final int r; 8 | private final int g; 9 | private final int b; 10 | private final int a; 11 | 12 | public ClearColorInt(final int r, final int g, final int b, final int a) { 13 | this.r = r; 14 | this.g = g; 15 | this.b = b; 16 | this.a = a; 17 | } 18 | 19 | @Override 20 | public VkClearValue toStruct() { 21 | final VkClearValue result = VkClearValue.calloc(); 22 | 23 | result.color() 24 | .int32(0, r) 25 | .int32(1, g) 26 | .int32(2, b) 27 | .int32(3, a); 28 | 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/clear/ClearDepthStencil.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.clear; 2 | 3 | import org.lwjgl.vulkan.VkClearValue; 4 | 5 | public class ClearDepthStencil extends ClearValue { 6 | 7 | private final float depth; 8 | private final int stencil; 9 | 10 | public ClearDepthStencil(final float depth, final int stencil) { 11 | this.depth = depth; 12 | this.stencil = stencil; 13 | } 14 | 15 | @Override 16 | public VkClearValue toStruct() { 17 | final VkClearValue result = VkClearValue.calloc(); 18 | 19 | result.depthStencil() 20 | .depth(depth) 21 | .stencil(stencil); 22 | 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/clear/ClearValue.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.clear; 2 | 3 | import org.lwjgl.vulkan.VkClearValue; 4 | 5 | public abstract class ClearValue { 6 | 7 | public abstract VkClearValue toStruct(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/pointers/Container.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.pointers; 2 | 3 | public interface Container { 4 | 5 | T unwrap(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/pointers/Disposable.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.pointers; 2 | 3 | import java.io.Closeable; 4 | 5 | public interface Disposable extends Closeable { 6 | 7 | @Override 8 | void close(); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/pointers/DisposablePointer.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.pointers; 2 | 3 | import java.util.Optional; 4 | import java.util.concurrent.atomic.AtomicBoolean; 5 | 6 | public abstract class DisposablePointer extends Pointer implements Disposable { 7 | 8 | private final AtomicBoolean isDisposed; 9 | 10 | protected DisposablePointer(final long handle) { 11 | super(handle); 12 | 13 | isDisposed = new AtomicBoolean(false); 14 | } 15 | 16 | @Override 17 | public long getAddress() { 18 | return Optional.of(super.getAddress()) 19 | .filter(address -> !isDisposed.get()) 20 | .orElseThrow(() -> new IllegalStateException("Underlying instance has already been destroyed")); 21 | } 22 | 23 | @Override 24 | public void close() { 25 | if (!isDisposed.getAndSet(true)) { 26 | dispose(super.getAddress()); 27 | } 28 | } 29 | 30 | protected abstract void dispose(final long address); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/pointers/DisposableReferencePointer.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.pointers; 2 | 3 | import java.util.Optional; 4 | import java.util.concurrent.atomic.AtomicBoolean; 5 | import java.util.function.Function; 6 | 7 | public abstract class DisposableReferencePointer extends ReferencePointer implements Disposable { 8 | 9 | private final AtomicBoolean isDisposed; 10 | 11 | protected DisposableReferencePointer(final T reference, final Function pointerFunction) { 12 | super(reference, pointerFunction); 13 | 14 | isDisposed = new AtomicBoolean(false); 15 | } 16 | 17 | @Override 18 | public long getAddress() { 19 | return Optional.of(super.getAddress()) 20 | .filter(address -> !isDisposed.get()) 21 | .orElseThrow(() -> new IllegalStateException("Underlying instance has already been destroyed")); 22 | } 23 | 24 | @Override 25 | public T unwrap() { 26 | return Optional.of(super.unwrap()) 27 | .filter(ref -> !isDisposed.get()) 28 | .orElseThrow(() -> new IllegalStateException("Underlying instance has already been disposed")); 29 | } 30 | 31 | @Override 32 | public void close() { 33 | if (!isDisposed.getAndSet(true)) { 34 | dispose(super.unwrap(), super.getAddress()); 35 | } 36 | } 37 | 38 | protected abstract void dispose(final T reference, final long address); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/pointers/Pointer.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.pointers; 2 | 3 | public abstract class Pointer { 4 | 5 | private final long handle; 6 | 7 | protected Pointer(final long handle) { 8 | this.handle = handle; 9 | } 10 | 11 | public long getAddress() { 12 | return handle; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/models/pointers/ReferencePointer.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.models.pointers; 2 | 3 | import java.util.function.Function; 4 | 5 | public abstract class ReferencePointer extends Pointer implements Container { 6 | 7 | private final T reference; 8 | 9 | protected ReferencePointer(final T reference, Function pointerFunction) { 10 | super(pointerFunction.apply(reference)); 11 | this.reference = reference; 12 | } 13 | 14 | @Override 15 | public T unwrap() { 16 | return reference; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/PipelineLayout.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | import com.justindriggers.vulkan.instance.VulkanFunction; 5 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 6 | import com.justindriggers.vulkan.pipeline.descriptor.DescriptorSetLayout; 7 | import org.lwjgl.vulkan.VkPipelineLayoutCreateInfo; 8 | 9 | import java.nio.LongBuffer; 10 | import java.util.Collections; 11 | import java.util.List; 12 | import java.util.Optional; 13 | 14 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 15 | import static org.lwjgl.system.MemoryUtil.memFree; 16 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; 17 | import static org.lwjgl.vulkan.VK10.vkCreatePipelineLayout; 18 | import static org.lwjgl.vulkan.VK10.vkDestroyPipelineLayout; 19 | 20 | public class PipelineLayout extends DisposablePointer { 21 | 22 | private final LogicalDevice device; 23 | 24 | public PipelineLayout(final LogicalDevice device, 25 | final List descriptorSetLayouts) { 26 | super(createPipelineLayout(device, descriptorSetLayouts)); 27 | this.device = device; 28 | } 29 | 30 | @Override 31 | protected void dispose(final long address) { 32 | vkDestroyPipelineLayout(device.unwrap(), address, null); 33 | } 34 | 35 | private static long createPipelineLayout(final LogicalDevice device, 36 | final List descriptorSetLayouts) { 37 | final long result; 38 | 39 | final LongBuffer pipelineLayout = memAllocLong(1); 40 | 41 | final List descriptorSetLayoutsSafe = Optional.ofNullable(descriptorSetLayouts) 42 | .orElseGet(Collections::emptyList); 43 | 44 | final LongBuffer setLayouts = memAllocLong(descriptorSetLayoutsSafe.size()); 45 | descriptorSetLayoutsSafe.forEach(descriptorSetLayout -> setLayouts.put(descriptorSetLayout.getAddress())); 46 | setLayouts.flip(); 47 | 48 | final VkPipelineLayoutCreateInfo layoutCreateInfo = VkPipelineLayoutCreateInfo.calloc() 49 | .sType(VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO) 50 | .pSetLayouts(setLayouts); 51 | 52 | try { 53 | VulkanFunction.execute(() -> vkCreatePipelineLayout(device.unwrap(), layoutCreateInfo, null, 54 | pipelineLayout)); 55 | 56 | result = pipelineLayout.get(0); 57 | } finally { 58 | memFree(pipelineLayout); 59 | memFree(setLayouts); 60 | 61 | layoutCreateInfo.free(); 62 | } 63 | 64 | return result; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/descriptor/DescriptorSet.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.descriptor; 2 | 3 | import com.justindriggers.vulkan.buffer.Buffer; 4 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 5 | import com.justindriggers.vulkan.models.HasValue; 6 | import com.justindriggers.vulkan.models.pointers.Pointer; 7 | import com.justindriggers.vulkan.pipeline.descriptor.models.DescriptorType; 8 | import org.lwjgl.vulkan.VkDescriptorBufferInfo; 9 | import org.lwjgl.vulkan.VkWriteDescriptorSet; 10 | 11 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; 12 | import static org.lwjgl.vulkan.VK10.VK_WHOLE_SIZE; 13 | import static org.lwjgl.vulkan.VK10.vkUpdateDescriptorSets; 14 | 15 | public class DescriptorSet extends Pointer { 16 | 17 | private final LogicalDevice device; 18 | private final DescriptorType descriptorType; 19 | 20 | DescriptorSet(final LogicalDevice device, 21 | final long handle, 22 | final DescriptorType descriptorType) { 23 | super(handle); 24 | this.device = device; 25 | this.descriptorType = descriptorType; 26 | } 27 | 28 | public void update(final Buffer buffer) { 29 | final VkDescriptorBufferInfo.Buffer descriptorBufferInfo = VkDescriptorBufferInfo.calloc(1) 30 | .buffer(buffer.getAddress()) 31 | .offset(0L) 32 | .range(VK_WHOLE_SIZE); 33 | 34 | final VkWriteDescriptorSet.Buffer writeDescriptorSet = VkWriteDescriptorSet.calloc(1) 35 | .sType(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET) 36 | .dstSet(getAddress()) 37 | .dstBinding(0) 38 | .dstArrayElement(0) 39 | .descriptorType(HasValue.getValue(descriptorType)) 40 | .pBufferInfo(descriptorBufferInfo); 41 | 42 | try { 43 | vkUpdateDescriptorSets(device.unwrap(), writeDescriptorSet, null); 44 | } finally { 45 | descriptorBufferInfo.free(); 46 | writeDescriptorSet.free(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/descriptor/DescriptorSetLayout.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.descriptor; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | import com.justindriggers.vulkan.instance.VulkanFunction; 5 | import com.justindriggers.vulkan.models.HasValue; 6 | import com.justindriggers.vulkan.models.Maskable; 7 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 8 | import org.lwjgl.vulkan.VkDescriptorSetLayoutBinding; 9 | import org.lwjgl.vulkan.VkDescriptorSetLayoutCreateInfo; 10 | 11 | import java.nio.LongBuffer; 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Optional; 15 | 16 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 17 | import static org.lwjgl.system.MemoryUtil.memFree; 18 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO; 19 | import static org.lwjgl.vulkan.VK10.vkCreateDescriptorSetLayout; 20 | import static org.lwjgl.vulkan.VK10.vkDestroyDescriptorSetLayout; 21 | 22 | public class DescriptorSetLayout extends DisposablePointer { 23 | 24 | private final LogicalDevice device; 25 | 26 | public DescriptorSetLayout(final LogicalDevice device, 27 | final List bindings) { 28 | super(createDescriptorSetLayout(device, bindings)); 29 | this.device = device; 30 | } 31 | 32 | @Override 33 | protected void dispose(final long address) { 34 | vkDestroyDescriptorSetLayout(device.unwrap(), address, null); 35 | } 36 | 37 | private static long createDescriptorSetLayout(final LogicalDevice device, 38 | final List bindings) { 39 | final long result; 40 | 41 | final LongBuffer descriptorSetLayout = memAllocLong(1); 42 | 43 | final List bindingsSafe = Optional.ofNullable(bindings) 44 | .orElseGet(Collections::emptyList); 45 | 46 | final VkDescriptorSetLayoutBinding.Buffer descriptorSetLayoutBindings = VkDescriptorSetLayoutBinding.calloc(bindingsSafe.size()); 47 | 48 | bindingsSafe.stream() 49 | .map(binding -> VkDescriptorSetLayoutBinding.calloc() 50 | .binding(binding.getBinding()) 51 | .descriptorType(HasValue.getValue(binding.getDescriptorType())) 52 | .descriptorCount(binding.getDescriptorCount()) 53 | .stageFlags(Maskable.toBitMask(binding.getStageFlags()))) 54 | .forEachOrdered(descriptorSetLayoutBindings::put); 55 | 56 | descriptorSetLayoutBindings.flip(); 57 | 58 | final VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = VkDescriptorSetLayoutCreateInfo.calloc() 59 | .sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO) 60 | .pBindings(descriptorSetLayoutBindings); 61 | 62 | try { 63 | VulkanFunction.execute(() -> vkCreateDescriptorSetLayout(device.unwrap(), descriptorSetLayoutCreateInfo, 64 | null, descriptorSetLayout)); 65 | 66 | result = descriptorSetLayout.get(0); 67 | } finally { 68 | memFree(descriptorSetLayout); 69 | 70 | descriptorSetLayoutBindings.free(); 71 | descriptorSetLayoutCreateInfo.free(); 72 | } 73 | 74 | return result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/descriptor/DescriptorSetLayoutBinding.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.descriptor; 2 | 3 | import com.justindriggers.vulkan.pipeline.descriptor.models.DescriptorType; 4 | import com.justindriggers.vulkan.pipeline.shader.ShaderStageType; 5 | 6 | import java.util.Set; 7 | import java.util.stream.Collectors; 8 | import java.util.stream.Stream; 9 | 10 | public class DescriptorSetLayoutBinding { 11 | 12 | private final int binding; 13 | private final DescriptorType descriptorType; 14 | private final int descriptorCount; 15 | private final Set stageFlags; 16 | 17 | public DescriptorSetLayoutBinding(final int binding, 18 | final DescriptorType descriptorType, 19 | final int descriptorCount, 20 | final ShaderStageType... stageFlags) { 21 | this.binding = binding; 22 | this.descriptorType = descriptorType; 23 | this.descriptorCount = descriptorCount; 24 | 25 | this.stageFlags = Stream.of(stageFlags).collect(Collectors.toSet()); 26 | } 27 | 28 | int getBinding() { 29 | return binding; 30 | } 31 | 32 | DescriptorType getDescriptorType() { 33 | return descriptorType; 34 | } 35 | 36 | int getDescriptorCount() { 37 | return descriptorCount; 38 | } 39 | 40 | Set getStageFlags() { 41 | return stageFlags; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/descriptor/models/DescriptorPoolFlag.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.descriptor.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.EXTDescriptorIndexing; 5 | import org.lwjgl.vulkan.VK10; 6 | 7 | public enum DescriptorPoolFlag implements Maskable { 8 | 9 | FREE_DESCRIPTOR_SET(VK10.VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT), 10 | UPDATE_AFTER_BIND(EXTDescriptorIndexing.VK_DESCRIPTOR_POOL_CREATE_UPDATE_AFTER_BIND_BIT_EXT); 11 | 12 | private final int bit; 13 | 14 | DescriptorPoolFlag(final int bit) { 15 | this.bit = bit; 16 | } 17 | 18 | @Override 19 | public int getBitValue() { 20 | return bit; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/descriptor/models/DescriptorType.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.descriptor.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum DescriptorType implements HasValue { 7 | 8 | SAMPLER(VK10.VK_DESCRIPTOR_TYPE_SAMPLER), 9 | COMBINED_IMAGE_SAMPLER(VK10.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER), 10 | SAMPLED_IMAGE(VK10.VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE), 11 | STORAGE_IMAGE(VK10.VK_DESCRIPTOR_TYPE_STORAGE_IMAGE), 12 | UNIFORM_TEXEL_BUFFER(VK10.VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER), 13 | STORAGE_TEXEL_BUFFER(VK10.VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER), 14 | UNIFORM_BUFFER(VK10.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER), 15 | STORAGE_BUFFER(VK10.VK_DESCRIPTOR_TYPE_STORAGE_BUFFER), 16 | UNIFORM_BUFFER_DYNAMIC(VK10.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC), 17 | STORAGE_BUFFER_DYNAMIC(VK10.VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC), 18 | INPUT_ATTACHMENT(VK10.VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT); 19 | 20 | private final int value; 21 | 22 | DescriptorType(final int value) { 23 | this.value = value; 24 | } 25 | 26 | @Override 27 | public Integer getValue() { 28 | return value; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/PipelineBindPoint.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum PipelineBindPoint implements HasValue { 7 | 8 | GRAPHICS(VK10.VK_PIPELINE_BIND_POINT_GRAPHICS), 9 | COMPUTE(VK10.VK_PIPELINE_BIND_POINT_COMPUTE); 10 | 11 | private final int value; 12 | 13 | PipelineBindPoint(final int value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Integer getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/PipelineCreateFlag.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum PipelineCreateFlag implements Maskable { 7 | 8 | DISABLE_OPTIMIZATION(VK10.VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT), 9 | ALLOW_DERIVATIVES(VK10.VK_PIPELINE_CREATE_ALLOW_DERIVATIVES_BIT), 10 | DERIVATIVE(VK10.VK_PIPELINE_CREATE_DERIVATIVE_BIT); 11 | 12 | private final int bit; 13 | 14 | PipelineCreateFlag(final int bit) { 15 | this.bit = bit; 16 | } 17 | 18 | @Override 19 | public int getBitValue() { 20 | return bit; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/PipelineStage.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum PipelineStage implements Maskable { 7 | 8 | TOP_OF_PIPE(VK10.VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT), 9 | DRAW_INDIRECT(VK10.VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT), 10 | VERTEX_INPUT(VK10.VK_PIPELINE_STAGE_VERTEX_INPUT_BIT), 11 | VERTEX_SHADER(VK10.VK_PIPELINE_STAGE_VERTEX_SHADER_BIT), 12 | TESSELATION_CONTROL_SHADER(VK10.VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT), 13 | TESSELATION_EVALUATION_SHADER(VK10.VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT), 14 | GEOMETRY_SHADER(VK10.VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT), 15 | FRAGMENT_SHADER(VK10.VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT), 16 | EARLY_FRAGMENT_TESTS(VK10.VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT), 17 | LATE_FRAGEMENT_TESTS(VK10.VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT), 18 | COLOR_ATTACHMENT_OUTPUT(VK10.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT), 19 | COMPUTE_SHADER(VK10.VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT), 20 | TRANSFER(VK10.VK_PIPELINE_STAGE_TRANSFER_BIT), 21 | BOTTOM_OF_PIPE(VK10.VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT), 22 | HOST(VK10.VK_PIPELINE_STAGE_HOST_BIT), 23 | ALL_GRAPHICS(VK10.VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT), 24 | ALL_COMMANDS(VK10.VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); 25 | 26 | private final int bit; 27 | 28 | PipelineStage(final int bit) { 29 | this.bit = bit; 30 | } 31 | 32 | @Override 33 | public int getBitValue() { 34 | return bit; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/assembly/InputAssemblyState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.assembly; 2 | 3 | public class InputAssemblyState { 4 | 5 | private final PrimitiveTopology topology; 6 | private final boolean isPrimitiveRestartEnabled; 7 | 8 | public InputAssemblyState(final PrimitiveTopology topology, 9 | final boolean isPrimitiveRestartEnabled) { 10 | this.topology = topology; 11 | this.isPrimitiveRestartEnabled = isPrimitiveRestartEnabled; 12 | } 13 | 14 | public PrimitiveTopology getTopology() { 15 | return topology; 16 | } 17 | 18 | public boolean isPrimitiveRestartEnabled() { 19 | return isPrimitiveRestartEnabled; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/assembly/PrimitiveTopology.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.assembly; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum PrimitiveTopology implements HasValue { 7 | 8 | POINT_LIST(VK10.VK_PRIMITIVE_TOPOLOGY_POINT_LIST), 9 | LINE_LIST(VK10.VK_PRIMITIVE_TOPOLOGY_LINE_LIST), 10 | LINE_STRIP(VK10.VK_PRIMITIVE_TOPOLOGY_LINE_STRIP), 11 | TRIANGLE_LIST(VK10.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST), 12 | TRIANGLE_STRIP(VK10.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP), 13 | TRIANGLE_FAN(VK10.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN), 14 | LINE_LIST_WITH_ADJACENCY(VK10.VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY), 15 | LINE_STRIP_WITH_ADJACENCY(VK10.VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY), 16 | TRIANGLE_LIST_WITH_ADJACENCY(VK10.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY), 17 | TRIANGLE_STRIP_WITH_ADJACENCY(VK10.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY), 18 | PATCH_LIST(VK10.VK_PRIMITIVE_TOPOLOGY_PATCH_LIST); 19 | 20 | private final int value; 21 | 22 | PrimitiveTopology(final int value) { 23 | this.value = value; 24 | } 25 | 26 | @Override 27 | public Integer getValue() { 28 | return value; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/colorblend/BlendFactor.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.colorblend; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum BlendFactor implements HasValue { 7 | 8 | ZERO(VK10.VK_BLEND_FACTOR_ZERO), 9 | ONE(VK10.VK_BLEND_FACTOR_ONE), 10 | SRC_COLOR(VK10.VK_BLEND_FACTOR_SRC_COLOR), 11 | ONE_MINUS_SRC_COLOR(VK10.VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR), 12 | DST_COLOR(VK10.VK_BLEND_FACTOR_DST_COLOR), 13 | ONE_MINUS_DST_COLOR(VK10.VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR), 14 | SRC_ALPHA(VK10.VK_BLEND_FACTOR_SRC_ALPHA), 15 | ONE_MINUS_SRC_ALPHA(VK10.VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA), 16 | DST_ALPHA(VK10.VK_BLEND_FACTOR_DST_ALPHA), 17 | ONE_MINUS_DST_ALPHA(VK10.VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA), 18 | CONSTANT_COLOR(VK10.VK_BLEND_FACTOR_CONSTANT_COLOR), 19 | ONE_MINUS_CONSTANT_COLOR(VK10.VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR), 20 | CONSTANT_ALPHA(VK10.VK_BLEND_FACTOR_CONSTANT_ALPHA), 21 | ONE_MINUS_CONSTANT_ALPHA(VK10.VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA), 22 | SRC_ALPHA_SATURATE(VK10.VK_BLEND_FACTOR_SRC_ALPHA_SATURATE), 23 | SRC1_COLOR(VK10.VK_BLEND_FACTOR_SRC1_COLOR), 24 | ONE_MINUS_SRC1_COLOR(VK10.VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR), 25 | SRC1_ALPHA(VK10.VK_BLEND_FACTOR_SRC1_ALPHA), 26 | ONE_MINUS_SRC1_ALPHA(VK10.VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA); 27 | 28 | private final int value; 29 | 30 | BlendFactor(final int value) { 31 | this.value = value; 32 | } 33 | 34 | @Override 35 | public Integer getValue() { 36 | return value; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/colorblend/BlendOperation.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.colorblend; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum BlendOperation implements HasValue { 7 | 8 | ADD(VK10.VK_BLEND_OP_ADD), 9 | SUBTRACT(VK10.VK_BLEND_OP_SUBTRACT), 10 | REVERSE_SUBTRACT(VK10.VK_BLEND_OP_REVERSE_SUBTRACT), 11 | MIN(VK10.VK_BLEND_OP_MIN), 12 | MAX(VK10.VK_BLEND_OP_MAX); 13 | 14 | private final int value; 15 | 16 | BlendOperation(final int value) { 17 | this.value = value; 18 | } 19 | 20 | @Override 21 | public Integer getValue() { 22 | return value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/colorblend/ColorBlendAttachmentState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.colorblend; 2 | 3 | import java.util.Set; 4 | 5 | public class ColorBlendAttachmentState { 6 | 7 | private final boolean isBlendEnabled; 8 | private final BlendFactor sourceColorBlendFactor; 9 | private final BlendFactor destinationColorBlendFactor; 10 | private final BlendOperation colorBlendOperation; 11 | private final BlendFactor sourceAlphaBlendFactor; 12 | private final BlendFactor destinationAlphaBlendFactor; 13 | private final BlendOperation alphaBlendOperation; 14 | private final Set colorWrites; 15 | 16 | public ColorBlendAttachmentState(final boolean isBlendEnabled, 17 | final BlendFactor sourceColorBlendFactor, 18 | final BlendFactor destinationColorBlendFactor, 19 | final BlendOperation colorBlendOperation, 20 | final BlendFactor sourceAlphaBlendFactor, 21 | final BlendFactor destinationAlphaBlendFactor, 22 | final BlendOperation alphaBlendOperation, 23 | final Set colorWrites) { 24 | this.isBlendEnabled = isBlendEnabled; 25 | this.sourceColorBlendFactor = sourceColorBlendFactor; 26 | this.destinationColorBlendFactor = destinationColorBlendFactor; 27 | this.colorBlendOperation = colorBlendOperation; 28 | this.sourceAlphaBlendFactor = sourceAlphaBlendFactor; 29 | this.destinationAlphaBlendFactor = destinationAlphaBlendFactor; 30 | this.alphaBlendOperation = alphaBlendOperation; 31 | this.colorWrites = colorWrites; 32 | } 33 | 34 | public boolean isBlendEnabled() { 35 | return isBlendEnabled; 36 | } 37 | 38 | public BlendFactor getSourceColorBlendFactor() { 39 | return sourceColorBlendFactor; 40 | } 41 | 42 | public BlendFactor getDestinationColorBlendFactor() { 43 | return destinationColorBlendFactor; 44 | } 45 | 46 | public BlendOperation getColorBlendOperation() { 47 | return colorBlendOperation; 48 | } 49 | 50 | public BlendFactor getSourceAlphaBlendFactor() { 51 | return sourceAlphaBlendFactor; 52 | } 53 | 54 | public BlendFactor getDestinationAlphaBlendFactor() { 55 | return destinationAlphaBlendFactor; 56 | } 57 | 58 | public BlendOperation getAlphaBlendOperation() { 59 | return alphaBlendOperation; 60 | } 61 | 62 | public Set getColorWrites() { 63 | return colorWrites; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/colorblend/ColorBlendState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.colorblend; 2 | 3 | import java.util.List; 4 | 5 | public class ColorBlendState { 6 | 7 | private final boolean isLogicOpEnabled; 8 | private final LogicalOperation logicalOperation; 9 | private final List attachments; 10 | private final float[] blendConstants; 11 | 12 | public ColorBlendState(final boolean isLogicOpEnabled, 13 | final LogicalOperation logicalOperation, 14 | final List attachments, 15 | final float[] blendConstants) { 16 | this.isLogicOpEnabled = isLogicOpEnabled; 17 | this.logicalOperation = logicalOperation; 18 | this.attachments = attachments; 19 | this.blendConstants = blendConstants; 20 | } 21 | 22 | public boolean isLogicOpEnabled() { 23 | return isLogicOpEnabled; 24 | } 25 | 26 | public LogicalOperation getLogicalOperation() { 27 | return logicalOperation; 28 | } 29 | 30 | public List getAttachments() { 31 | return attachments; 32 | } 33 | 34 | public float[] getBlendConstants() { 35 | return blendConstants; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/colorblend/ColorComponent.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.colorblend; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum ColorComponent implements Maskable { 7 | 8 | R(VK10.VK_COLOR_COMPONENT_R_BIT), 9 | G(VK10.VK_COLOR_COMPONENT_G_BIT), 10 | B(VK10.VK_COLOR_COMPONENT_B_BIT), 11 | A(VK10.VK_COLOR_COMPONENT_A_BIT); 12 | 13 | private final int bit; 14 | 15 | ColorComponent(final int bit) { 16 | this.bit = bit; 17 | } 18 | 19 | @Override 20 | public int getBitValue() { 21 | return bit; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/colorblend/LogicalOperation.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.colorblend; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum LogicalOperation implements HasValue { 7 | 8 | CLEAR(VK10.VK_LOGIC_OP_CLEAR), 9 | AND(VK10.VK_LOGIC_OP_AND), 10 | AND_REVERSE(VK10.VK_LOGIC_OP_AND_REVERSE), 11 | COPY(VK10.VK_LOGIC_OP_COPY), 12 | AND_INVERTED(VK10.VK_LOGIC_OP_AND_INVERTED), 13 | NO_OP(VK10.VK_LOGIC_OP_NO_OP), 14 | XOR(VK10.VK_LOGIC_OP_XOR), 15 | OR(VK10.VK_LOGIC_OP_OR), 16 | NOR(VK10.VK_LOGIC_OP_NOR), 17 | EQUIVALENT(VK10.VK_LOGIC_OP_EQUIVALENT), 18 | INVERT(VK10.VK_LOGIC_OP_INVERT), 19 | OR_REVERSE(VK10.VK_LOGIC_OP_OR_REVERSE), 20 | COPY_INVERTED(VK10.VK_LOGIC_OP_COPY_INVERTED), 21 | OR_INVERTED(VK10.VK_LOGIC_OP_OR_INVERTED), 22 | NAND(VK10.VK_LOGIC_OP_NAND), 23 | SET(VK10.VK_LOGIC_OP_SET); 24 | 25 | private final int value; 26 | 27 | LogicalOperation(final int value) { 28 | this.value = value; 29 | } 30 | 31 | @Override 32 | public Integer getValue() { 33 | return value; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/depth/CompareOperator.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.depth; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum CompareOperator implements HasValue { 7 | 8 | NEVER(VK10.VK_COMPARE_OP_NEVER), 9 | LESS(VK10.VK_COMPARE_OP_LESS), 10 | EQUAL(VK10.VK_COMPARE_OP_EQUAL), 11 | LESS_OR_EQUAL(VK10.VK_COMPARE_OP_LESS_OR_EQUAL), 12 | GREATER(VK10.VK_COMPARE_OP_GREATER), 13 | NOT_EQUAL(VK10.VK_COMPARE_OP_NOT_EQUAL), 14 | GREATER_OR_EQUAL(VK10.VK_COMPARE_OP_GREATER_OR_EQUAL), 15 | ALWAYS(VK10.VK_COMPARE_OP_ALWAYS); 16 | 17 | private final int value; 18 | 19 | CompareOperator(final int value) { 20 | this.value = value; 21 | } 22 | 23 | @Override 24 | public Integer getValue() { 25 | return value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/depth/DepthStencilState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.depth; 2 | 3 | public class DepthStencilState { 4 | 5 | private final boolean isDepthTestEnabled; 6 | private final boolean isDepthWriteEnabled; 7 | private final CompareOperator depthCompareOperator; 8 | private final boolean isDepthBoundsTestEnabled; 9 | private final boolean isStencilTestEnabled; 10 | private final StencilOperationState frontOperationState; 11 | private final StencilOperationState backOperationState; 12 | private final float minDepthBounds; 13 | private final float maxDepthBounds; 14 | 15 | public DepthStencilState(final boolean isDepthTestEnabled, 16 | final boolean isDepthWriteEnabled, 17 | final CompareOperator depthCompareOperator, 18 | final boolean isDepthBoundsTestEnabled, 19 | final boolean isStencilTestEnabled, 20 | final StencilOperationState frontOperationState, 21 | final StencilOperationState backOperationState, 22 | final float minDepthBounds, 23 | final float maxDepthBounds) { 24 | this.isDepthTestEnabled = isDepthTestEnabled; 25 | this.isDepthWriteEnabled = isDepthWriteEnabled; 26 | this.depthCompareOperator = depthCompareOperator; 27 | this.isDepthBoundsTestEnabled = isDepthBoundsTestEnabled; 28 | this.isStencilTestEnabled = isStencilTestEnabled; 29 | this.frontOperationState = frontOperationState; 30 | this.backOperationState = backOperationState; 31 | this.minDepthBounds = minDepthBounds; 32 | this.maxDepthBounds = maxDepthBounds; 33 | } 34 | 35 | public boolean isDepthTestEnabled() { 36 | return isDepthTestEnabled; 37 | } 38 | 39 | public boolean isDepthWriteEnabled() { 40 | return isDepthWriteEnabled; 41 | } 42 | 43 | public CompareOperator getDepthCompareOperator() { 44 | return depthCompareOperator; 45 | } 46 | 47 | public boolean isDepthBoundsTestEnabled() { 48 | return isDepthBoundsTestEnabled; 49 | } 50 | 51 | public boolean isStencilTestEnabled() { 52 | return isStencilTestEnabled; 53 | } 54 | 55 | public StencilOperationState getFrontOperationState() { 56 | return frontOperationState; 57 | } 58 | 59 | public StencilOperationState getBackOperationState() { 60 | return backOperationState; 61 | } 62 | 63 | public float getMinDepthBounds() { 64 | return minDepthBounds; 65 | } 66 | 67 | public float getMaxDepthBounds() { 68 | return maxDepthBounds; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/depth/StencilOperation.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.depth; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum StencilOperation implements HasValue { 7 | 8 | KEEP(VK10.VK_STENCIL_OP_KEEP), 9 | ZERO(VK10.VK_STENCIL_OP_ZERO), 10 | REPLACE(VK10.VK_STENCIL_OP_REPLACE), 11 | INCREMENT_AND_CLAMP(VK10.VK_STENCIL_OP_INCREMENT_AND_CLAMP), 12 | DECREMENT_AND_CLAMP(VK10.VK_STENCIL_OP_DECREMENT_AND_CLAMP), 13 | INVERT(VK10.VK_STENCIL_OP_INVERT), 14 | INCREMENT_AND_WRAP(VK10.VK_STENCIL_OP_INCREMENT_AND_WRAP), 15 | DECREMENT_AND_WRAP(VK10.VK_STENCIL_OP_DECREMENT_AND_WRAP); 16 | 17 | private final int value; 18 | 19 | StencilOperation(final int value) { 20 | this.value = value; 21 | } 22 | 23 | @Override 24 | public Integer getValue() { 25 | return value; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/depth/StencilOperationState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.depth; 2 | 3 | public class StencilOperationState { 4 | 5 | private final StencilOperation failOperation; 6 | private final StencilOperation passOperation; 7 | private final StencilOperation depthFailOperation; 8 | private final CompareOperator compareOperator; 9 | private final int compareMask; 10 | private final int writeMask; 11 | private final int reference; 12 | 13 | public StencilOperationState(final StencilOperation failOperation, 14 | final StencilOperation passOperation, 15 | final StencilOperation depthFailOperation, 16 | final CompareOperator compareOperator, 17 | final int compareMask, 18 | final int writeMask, 19 | final int reference) { 20 | this.failOperation = failOperation; 21 | this.passOperation = passOperation; 22 | this.depthFailOperation = depthFailOperation; 23 | this.compareOperator = compareOperator; 24 | this.compareMask = compareMask; 25 | this.writeMask = writeMask; 26 | this.reference = reference; 27 | } 28 | 29 | public StencilOperation getFailOperation() { 30 | return failOperation; 31 | } 32 | 33 | public StencilOperation getPassOperation() { 34 | return passOperation; 35 | } 36 | 37 | public StencilOperation getDepthFailOperation() { 38 | return depthFailOperation; 39 | } 40 | 41 | public CompareOperator getCompareOperator() { 42 | return compareOperator; 43 | } 44 | 45 | public int getCompareMask() { 46 | return compareMask; 47 | } 48 | 49 | public int getWriteMask() { 50 | return writeMask; 51 | } 52 | 53 | public int getReference() { 54 | return reference; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/multisample/MultisampleState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.multisample; 2 | 3 | import com.justindriggers.vulkan.models.SampleCount; 4 | 5 | public class MultisampleState { 6 | 7 | private final SampleCount rasterizationSamples; 8 | private final boolean isSampleShadingEnabled; 9 | private final float minSampleShading; 10 | private final boolean isAlphaToCoverageEnabled; 11 | private final boolean isAlphaToOneEnabled; 12 | 13 | public MultisampleState(final SampleCount rasterizationSamples, 14 | final boolean isSampleShadingEnabled, 15 | final float minSampleShading, 16 | final boolean isAlphaToCoverageEnabled, 17 | final boolean isAlphaToOneEnabled) { 18 | this.rasterizationSamples = rasterizationSamples; 19 | this.isSampleShadingEnabled = isSampleShadingEnabled; 20 | this.minSampleShading = minSampleShading; 21 | this.isAlphaToCoverageEnabled = isAlphaToCoverageEnabled; 22 | this.isAlphaToOneEnabled = isAlphaToOneEnabled; 23 | } 24 | 25 | public SampleCount getRasterizationSamples() { 26 | return rasterizationSamples; 27 | } 28 | 29 | public boolean isSampleShadingEnabled() { 30 | return isSampleShadingEnabled; 31 | } 32 | 33 | public float getMinSampleShading() { 34 | return minSampleShading; 35 | } 36 | 37 | public boolean isAlphaToCoverageEnabled() { 38 | return isAlphaToCoverageEnabled; 39 | } 40 | 41 | public boolean isAlphaToOneEnabled() { 42 | return isAlphaToOneEnabled; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/rasterization/CullMode.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.rasterization; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum CullMode implements Maskable { 7 | 8 | NONE(VK10.VK_CULL_MODE_NONE), 9 | FRONT(VK10.VK_CULL_MODE_FRONT_BIT), 10 | BACK(VK10.VK_CULL_MODE_BACK_BIT), 11 | FRONT_AND_BACK(VK10.VK_CULL_MODE_FRONT_AND_BACK); 12 | 13 | private final int bit; 14 | 15 | CullMode(final int bit) { 16 | this.bit = bit; 17 | } 18 | 19 | @Override 20 | public int getBitValue() { 21 | return bit; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/rasterization/FrontFace.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.rasterization; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum FrontFace implements HasValue { 7 | 8 | COUNTER_CLOCKWISE(VK10.VK_FRONT_FACE_COUNTER_CLOCKWISE), 9 | CLOCKWISE(VK10.VK_FRONT_FACE_CLOCKWISE); 10 | 11 | private final int value; 12 | 13 | FrontFace(final int value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Integer getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/rasterization/PolygonMode.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.rasterization; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum PolygonMode implements HasValue { 7 | 8 | FILL(VK10.VK_POLYGON_MODE_FILL), 9 | LINE(VK10.VK_POLYGON_MODE_LINE), 10 | POINT(VK10.VK_POLYGON_MODE_POINT); 11 | 12 | private final int value; 13 | 14 | PolygonMode(final int value) { 15 | this.value = value; 16 | } 17 | 18 | @Override 19 | public Integer getValue() { 20 | return value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/rasterization/RasterizationState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.rasterization; 2 | 3 | public class RasterizationState { 4 | 5 | private final boolean isDepthClampEnabled; 6 | private final boolean isRasterizerDiscardEnabled; 7 | private final PolygonMode polygonMode; 8 | private final CullMode cullMode; 9 | private final FrontFace frontFace; 10 | private final boolean isDepthBiasEnabled; 11 | private final float depthBiasConstantFactor; 12 | private final float depthBiasClamp; 13 | private final float depthBiasSlopeFactor; 14 | private final float lineWidth; 15 | 16 | public RasterizationState(final boolean isDepthClampEnabled, 17 | final boolean isRasterizerDiscardEnabled, 18 | final PolygonMode polygonMode, 19 | final CullMode cullMode, 20 | final FrontFace frontFace, 21 | final boolean isDepthBiasEnabled, 22 | final float depthBiasConstantFactor, 23 | final float depthBiasClamp, 24 | final float depthBiasSlopeFactor, 25 | final float lineWidth) { 26 | this.isDepthClampEnabled = isDepthClampEnabled; 27 | this.isRasterizerDiscardEnabled = isRasterizerDiscardEnabled; 28 | this.polygonMode = polygonMode; 29 | this.cullMode = cullMode; 30 | this.frontFace = frontFace; 31 | this.isDepthBiasEnabled = isDepthBiasEnabled; 32 | this.depthBiasConstantFactor = depthBiasConstantFactor; 33 | this.depthBiasClamp = depthBiasClamp; 34 | this.depthBiasSlopeFactor = depthBiasSlopeFactor; 35 | this.lineWidth = lineWidth; 36 | } 37 | 38 | public boolean isDepthClampEnabled() { 39 | return isDepthClampEnabled; 40 | } 41 | 42 | public boolean isRasterizerDiscardEnabled() { 43 | return isRasterizerDiscardEnabled; 44 | } 45 | 46 | public PolygonMode getPolygonMode() { 47 | return polygonMode; 48 | } 49 | 50 | public CullMode getCullMode() { 51 | return cullMode; 52 | } 53 | 54 | public FrontFace getFrontFace() { 55 | return frontFace; 56 | } 57 | 58 | public boolean isDepthBiasEnabled() { 59 | return isDepthBiasEnabled; 60 | } 61 | 62 | public float getDepthBiasConstantFactor() { 63 | return depthBiasConstantFactor; 64 | } 65 | 66 | public float getDepthBiasClamp() { 67 | return depthBiasClamp; 68 | } 69 | 70 | public float getDepthBiasSlopeFactor() { 71 | return depthBiasSlopeFactor; 72 | } 73 | 74 | public float getLineWidth() { 75 | return lineWidth; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/vertex/VertexInputAttribute.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.vertex; 2 | 3 | import com.justindriggers.vulkan.models.Format; 4 | 5 | public class VertexInputAttribute { 6 | 7 | private final int binding; 8 | private final int location; 9 | private final Format format; 10 | private final int offset; 11 | 12 | public VertexInputAttribute(final int binding, 13 | final int location, 14 | final Format format, 15 | final int offset) { 16 | this.binding = binding; 17 | this.location = location; 18 | this.format = format; 19 | this.offset = offset; 20 | } 21 | 22 | public int getBinding() { 23 | return binding; 24 | } 25 | 26 | public int getLocation() { 27 | return location; 28 | } 29 | 30 | public Format getFormat() { 31 | return format; 32 | } 33 | 34 | public int getOffset() { 35 | return offset; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/vertex/VertexInputBinding.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.vertex; 2 | 3 | public class VertexInputBinding { 4 | 5 | private final int binding; 6 | private final int stride; 7 | private final VertexInputRate rate; 8 | 9 | public VertexInputBinding(final int binding, 10 | final int stride, 11 | final VertexInputRate rate) { 12 | this.binding = binding; 13 | this.stride = stride; 14 | this.rate = rate; 15 | } 16 | 17 | public int getBinding() { 18 | return binding; 19 | } 20 | 21 | public int getStride() { 22 | return stride; 23 | } 24 | 25 | public VertexInputRate getRate() { 26 | return rate; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/vertex/VertexInputRate.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.vertex; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum VertexInputRate implements HasValue { 7 | 8 | VERTEX(VK10.VK_VERTEX_INPUT_RATE_VERTEX), 9 | INSTANCE(VK10.VK_VERTEX_INPUT_RATE_INSTANCE); 10 | 11 | private final int value; 12 | 13 | VertexInputRate(final int value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Integer getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/vertex/VertexInputState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.vertex; 2 | 3 | import com.justindriggers.vulkan.pipeline.models.vertex.builder.VertexInputStateBuilder; 4 | 5 | import java.util.List; 6 | 7 | public class VertexInputState { 8 | 9 | private final List vertexInputBindings; 10 | private final List vertexInputAttributes; 11 | 12 | public VertexInputState(final List vertexInputBindings, 13 | final List vertexInputAttributes) { 14 | this.vertexInputBindings = vertexInputBindings; 15 | this.vertexInputAttributes = vertexInputAttributes; 16 | } 17 | 18 | public List getVertexInputBindings() { 19 | return vertexInputBindings; 20 | } 21 | 22 | public List getVertexInputAttributes() { 23 | return vertexInputAttributes; 24 | } 25 | 26 | public static VertexInputStateBuilder builder() { 27 | return new VertexInputStateBuilder(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/vertex/builder/VertexInputBindingBuilder.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.vertex.builder; 2 | 3 | import com.justindriggers.vulkan.models.Format; 4 | import com.justindriggers.vulkan.pipeline.models.vertex.VertexInputAttribute; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | public class VertexInputBindingBuilder { 10 | 11 | private final List vertexInputAttributes = new ArrayList<>(); 12 | 13 | private final VertexInputStateBuilder parent; 14 | private final int binding; 15 | 16 | private int offset = 0; 17 | 18 | VertexInputBindingBuilder(final VertexInputStateBuilder parent, final int binding) { 19 | this.parent = parent; 20 | this.binding = binding; 21 | } 22 | 23 | public VertexInputBindingBuilder intLocation(final int location) { 24 | vertexInputAttributes.add(new VertexInputAttribute(binding, location, Format.R32_SINT, offset)); 25 | offset += 4; 26 | return this; 27 | } 28 | 29 | public VertexInputBindingBuilder floatLocation(final int location) { 30 | vertexInputAttributes.add(new VertexInputAttribute(binding, location, Format.R32_SFLOAT, offset)); 31 | offset += 4; 32 | return this; 33 | } 34 | 35 | public VertexInputBindingBuilder vec2Location(final int location) { 36 | vertexInputAttributes.add(new VertexInputAttribute(binding, location, Format.R32G32_SFLOAT, offset)); 37 | offset += 2 * 4; 38 | return this; 39 | } 40 | 41 | public VertexInputBindingBuilder vec3Location(final int location) { 42 | vertexInputAttributes.add(new VertexInputAttribute(binding, location, Format.R32G32B32_SFLOAT, offset)); 43 | offset += 3 * 4; 44 | return this; 45 | } 46 | 47 | public VertexInputBindingBuilder vec4Location(final int location) { 48 | vertexInputAttributes.add(new VertexInputAttribute(binding, location, Format.R32G32B32A32_SFLOAT, offset)); 49 | offset += 4 * 4; 50 | return this; 51 | } 52 | 53 | public VertexInputStateBuilder finalizeBinding() { 54 | return parent.next(binding, offset, vertexInputAttributes); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/vertex/builder/VertexInputStateBuilder.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.vertex.builder; 2 | 3 | import com.justindriggers.vulkan.pipeline.models.vertex.VertexInputAttribute; 4 | import com.justindriggers.vulkan.pipeline.models.vertex.VertexInputBinding; 5 | import com.justindriggers.vulkan.pipeline.models.vertex.VertexInputRate; 6 | import com.justindriggers.vulkan.pipeline.models.vertex.VertexInputState; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class VertexInputStateBuilder { 12 | 13 | private final List vertexInputBindings = new ArrayList<>(); 14 | private final List vertexInputAttributes = new ArrayList<>(); 15 | 16 | public VertexInputBindingBuilder addBinding(final int binding) { 17 | return new VertexInputBindingBuilder(this, binding); 18 | } 19 | 20 | public VertexInputState build() { 21 | return new VertexInputState(vertexInputBindings, vertexInputAttributes); 22 | } 23 | 24 | VertexInputStateBuilder next(final int binding, final int stride, final List attributes) { 25 | vertexInputBindings.add(new VertexInputBinding(binding, stride, VertexInputRate.VERTEX)); 26 | vertexInputAttributes.addAll(attributes); 27 | return this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/viewport/Viewport.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.viewport; 2 | 3 | public class Viewport { 4 | 5 | private final float x; 6 | private final float y; 7 | private final float width; 8 | private final float height; 9 | private final float minDepth; 10 | private final float maxDepth; 11 | 12 | public Viewport(final float x, 13 | final float y, 14 | final float width, 15 | final float height, 16 | final float minDepth, 17 | final float maxDepth) { 18 | this.x = x; 19 | this.y = y; 20 | this.width = width; 21 | this.height = height; 22 | this.minDepth = minDepth; 23 | this.maxDepth = maxDepth; 24 | } 25 | 26 | public float getX() { 27 | return x; 28 | } 29 | 30 | public float getY() { 31 | return y; 32 | } 33 | 34 | public float getWidth() { 35 | return width; 36 | } 37 | 38 | public float getHeight() { 39 | return height; 40 | } 41 | 42 | public float getMinDepth() { 43 | return minDepth; 44 | } 45 | 46 | public float getMaxDepth() { 47 | return maxDepth; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/models/viewport/ViewportState.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.models.viewport; 2 | 3 | import com.justindriggers.vulkan.models.Rect2D; 4 | 5 | import java.util.List; 6 | 7 | public class ViewportState { 8 | 9 | private final List viewports; 10 | private final List scissors; 11 | 12 | public ViewportState(final List viewports, 13 | final List scissors) { 14 | this.viewports = viewports; 15 | this.scissors = scissors; 16 | } 17 | 18 | public List getViewports() { 19 | return viewports; 20 | } 21 | 22 | public List getScissors() { 23 | return scissors; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/shader/ShaderModule.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.shader; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | import com.justindriggers.vulkan.instance.VulkanFunction; 5 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 6 | import org.lwjgl.vulkan.VkShaderModuleCreateInfo; 7 | 8 | import java.nio.ByteBuffer; 9 | import java.nio.LongBuffer; 10 | 11 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 12 | import static org.lwjgl.system.MemoryUtil.memFree; 13 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; 14 | import static org.lwjgl.vulkan.VK10.vkCreateShaderModule; 15 | import static org.lwjgl.vulkan.VK10.vkDestroyShaderModule; 16 | 17 | public class ShaderModule extends DisposablePointer { 18 | 19 | private final LogicalDevice device; 20 | 21 | public ShaderModule(final LogicalDevice device, 22 | final ByteBuffer shaderCode) { 23 | super(createShaderModule(device, shaderCode)); 24 | this.device = device; 25 | } 26 | 27 | @Override 28 | protected void dispose(final long address) { 29 | vkDestroyShaderModule(device.unwrap(), address, null); 30 | } 31 | 32 | private static long createShaderModule(final LogicalDevice device, 33 | final ByteBuffer shaderCode) { 34 | final long result; 35 | 36 | final LongBuffer shaderModule = memAllocLong(1); 37 | 38 | final VkShaderModuleCreateInfo shaderModuleCreateInfo = VkShaderModuleCreateInfo.calloc() 39 | .sType(VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO) 40 | .pCode(shaderCode); 41 | 42 | try { 43 | VulkanFunction.execute(() -> vkCreateShaderModule(device.unwrap(), shaderModuleCreateInfo, null, 44 | shaderModule)); 45 | 46 | result = shaderModule.get(0); 47 | } finally { 48 | memFree(shaderModule); 49 | 50 | shaderModuleCreateInfo.free(); 51 | } 52 | 53 | return result; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/shader/ShaderModuleLoader.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.shader; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | 5 | import java.io.ByteArrayOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.UncheckedIOException; 9 | import java.net.URL; 10 | import java.nio.ByteBuffer; 11 | import java.util.Optional; 12 | 13 | public class ShaderModuleLoader { 14 | 15 | public ShaderModule loadFromFile(final LogicalDevice device, final String resourcePath) { 16 | final ShaderModule result; 17 | 18 | final URL resourceUrl = Optional.of(getClass()) 19 | .map(Class::getClassLoader) 20 | .map(classLoader -> classLoader.getResource(resourcePath)) 21 | .orElseThrow(() -> new IllegalArgumentException("Unable to open file at " + resourcePath)); 22 | 23 | try (final InputStream inputStream = resourceUrl.openStream(); 24 | final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) { 25 | boolean hasMore = true; 26 | 27 | do { 28 | final int b = inputStream.read(); 29 | 30 | if (b == -1) { 31 | hasMore = false; 32 | } else { 33 | byteArrayOutputStream.write(b); 34 | } 35 | } while (hasMore); 36 | 37 | final byte[] code = byteArrayOutputStream.toByteArray(); 38 | 39 | final ByteBuffer shaderCode = ByteBuffer.allocateDirect(code.length); 40 | shaderCode.put(code); 41 | shaderCode.flip(); 42 | 43 | result = new ShaderModule(device, shaderCode); 44 | } catch (final IOException e) { 45 | throw new UncheckedIOException("Failed to load shader module", e); 46 | } 47 | 48 | return result; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/shader/ShaderStage.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.shader; 2 | 3 | public class ShaderStage implements AutoCloseable { 4 | 5 | private final ShaderStageType type; 6 | private final ShaderModule module; 7 | private final String entryPoint; 8 | 9 | public ShaderStage(final ShaderStageType type, 10 | final ShaderModule module, 11 | final String entryPoint) { 12 | this.type = type; 13 | this.module = module; 14 | this.entryPoint = entryPoint; 15 | } 16 | 17 | public ShaderStageType getType() { 18 | return type; 19 | } 20 | 21 | public ShaderModule getModule() { 22 | return module; 23 | } 24 | 25 | public String getEntryPoint() { 26 | return entryPoint; 27 | } 28 | 29 | @Override 30 | public void close() { 31 | module.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/pipeline/shader/ShaderStageType.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.pipeline.shader; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum ShaderStageType implements Maskable { 7 | 8 | VERTEX(VK10.VK_SHADER_STAGE_VERTEX_BIT), 9 | TESSELLATION_CONTROL(VK10.VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT), 10 | TESSELLATION_EVALUATION(VK10.VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT), 11 | GEOMETRY(VK10.VK_SHADER_STAGE_GEOMETRY_BIT), 12 | FRAGMENT(VK10.VK_SHADER_STAGE_FRAGMENT_BIT), 13 | COMPUTE(VK10.VK_SHADER_STAGE_COMPUTE_BIT), 14 | ALL_GRAPHICS(VK10.VK_SHADER_STAGE_ALL_GRAPHICS), 15 | ALL(VK10.VK_SHADER_STAGE_ALL); 16 | 17 | private final int bit; 18 | 19 | ShaderStageType(final int bit) { 20 | this.bit = bit; 21 | } 22 | 23 | @Override 24 | public int getBitValue() { 25 | return bit; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/queue/QueueCapability.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.queue; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | import org.lwjgl.vulkan.VK11; 6 | 7 | public enum QueueCapability implements Maskable { 8 | 9 | GRAPHICS(VK10.VK_QUEUE_GRAPHICS_BIT), 10 | COMPUTE(VK10.VK_QUEUE_COMPUTE_BIT), 11 | TRANSFER(VK10.VK_QUEUE_TRANSFER_BIT), 12 | SPARSE_BINDING(VK10.VK_QUEUE_SPARSE_BINDING_BIT), 13 | PROTECTED(VK11.VK_QUEUE_PROTECTED_BIT); 14 | 15 | private final int bit; 16 | 17 | QueueCapability(final int bit) { 18 | this.bit = bit; 19 | } 20 | 21 | @Override 22 | public int getBitValue() { 23 | return bit; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/queue/QueueFamily.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.queue; 2 | 3 | import com.justindriggers.vulkan.devices.physical.PhysicalDevice; 4 | import com.justindriggers.vulkan.instance.VulkanFunction; 5 | import com.justindriggers.vulkan.surface.Surface; 6 | 7 | import java.nio.IntBuffer; 8 | import java.util.Objects; 9 | import java.util.Set; 10 | 11 | import static org.lwjgl.system.MemoryUtil.memAllocInt; 12 | import static org.lwjgl.system.MemoryUtil.memFree; 13 | import static org.lwjgl.vulkan.KHRSurface.vkGetPhysicalDeviceSurfaceSupportKHR; 14 | import static org.lwjgl.vulkan.VK10.VK_FALSE; 15 | import static org.lwjgl.vulkan.VK10.VK_TRUE; 16 | 17 | public class QueueFamily { 18 | 19 | private final PhysicalDevice physicalDevice; 20 | private final int index; 21 | private final Set capabilities; 22 | private final int queueCount; 23 | 24 | public QueueFamily(final PhysicalDevice physicalDevice, 25 | final int index, 26 | final Set capabilities, 27 | final int queueCount) { 28 | this.physicalDevice = physicalDevice; 29 | this.index = index; 30 | this.capabilities = capabilities; 31 | this.queueCount = queueCount; 32 | } 33 | 34 | public int getIndex() { 35 | return index; 36 | } 37 | 38 | public Set getCapabilities() { 39 | return capabilities; 40 | } 41 | 42 | public int getQueueCount() { 43 | return queueCount; 44 | } 45 | 46 | public boolean supportsSurfacePresentation(final Surface surface) { 47 | final boolean result; 48 | 49 | final IntBuffer supportsPresentation = memAllocInt(1); 50 | 51 | try { 52 | VulkanFunction.execute(() -> vkGetPhysicalDeviceSurfaceSupportKHR(physicalDevice.unwrap(), 53 | index, surface.getAddress(), supportsPresentation)); 54 | 55 | final int supportsPresentationResult = supportsPresentation.get(0); 56 | 57 | if (supportsPresentationResult == VK_TRUE) { 58 | result = true; 59 | } else if (supportsPresentationResult == VK_FALSE) { 60 | result = false; 61 | } else { 62 | throw new IllegalStateException("Unexpected result from vkGetPhysicalDeviceSurfaceSupportKHR: " 63 | + supportsPresentationResult); 64 | } 65 | } finally { 66 | memFree(supportsPresentation); 67 | } 68 | 69 | return result; 70 | } 71 | 72 | @Override 73 | public boolean equals(Object o) { 74 | if (this == o) { 75 | return true; 76 | } 77 | 78 | if (o == null || getClass() != o.getClass()) { 79 | return false; 80 | } 81 | 82 | QueueFamily that = (QueueFamily) o; 83 | 84 | return index == that.index 85 | && Objects.equals(physicalDevice, that.physicalDevice); 86 | } 87 | 88 | @Override 89 | public int hashCode() { 90 | return Objects.hash( 91 | index, 92 | physicalDevice 93 | ); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/surface/models/PresentMode.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.surface.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.KHRSurface; 5 | 6 | public enum PresentMode implements HasValue { 7 | 8 | IMMEDIATE(KHRSurface.VK_PRESENT_MODE_IMMEDIATE_KHR), 9 | MAILBOX(KHRSurface.VK_PRESENT_MODE_MAILBOX_KHR), 10 | FIFO(KHRSurface.VK_PRESENT_MODE_FIFO_KHR), 11 | FIFO_RELAXED(KHRSurface.VK_PRESENT_MODE_FIFO_RELAXED_KHR); 12 | 13 | private final int value; 14 | 15 | PresentMode(final int value) { 16 | this.value = value; 17 | } 18 | 19 | @Override 20 | public Integer getValue() { 21 | return value; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/surface/models/SurfaceFormat.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.surface.models; 2 | 3 | import com.justindriggers.vulkan.models.ColorSpace; 4 | import com.justindriggers.vulkan.models.Format; 5 | import com.justindriggers.vulkan.models.HasValue; 6 | import org.lwjgl.vulkan.VkSurfaceFormatKHR; 7 | 8 | import java.util.Objects; 9 | 10 | public class SurfaceFormat { 11 | 12 | private final Format format; 13 | private final ColorSpace colorSpace; 14 | 15 | public SurfaceFormat(final VkSurfaceFormatKHR vkSurfaceFormatKHR) { 16 | this( 17 | HasValue.getByValue(vkSurfaceFormatKHR.format(), Format.class), 18 | HasValue.getByValue(vkSurfaceFormatKHR.colorSpace(), ColorSpace.class) 19 | ); 20 | } 21 | 22 | public SurfaceFormat(final Format format, 23 | final ColorSpace colorSpace) { 24 | this.format = format; 25 | this.colorSpace = colorSpace; 26 | } 27 | 28 | public Format getFormat() { 29 | return format; 30 | } 31 | 32 | public ColorSpace getColorSpace() { 33 | return colorSpace; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object o) { 38 | if (this == o) { 39 | return true; 40 | } 41 | 42 | if (!(o instanceof SurfaceFormat)) { 43 | return false; 44 | } 45 | 46 | SurfaceFormat that = (SurfaceFormat) o; 47 | 48 | return format == that.format && 49 | colorSpace == that.colorSpace; 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return Objects.hash( 55 | format, 56 | colorSpace 57 | ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/surface/models/capabilities/CompositeAlpha.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.surface.models.capabilities; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.KHRSurface; 5 | 6 | public enum CompositeAlpha implements Maskable { 7 | 8 | OPAQUE(KHRSurface.VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR), 9 | PRE_MULTIPLIED(KHRSurface.VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR), 10 | POST_MULTIPLIED(KHRSurface.VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR), 11 | INHERIT(KHRSurface.VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR); 12 | 13 | private final int bit; 14 | 15 | CompositeAlpha(final int bit) { 16 | this.bit = bit; 17 | } 18 | 19 | @Override 20 | public int getBitValue() { 21 | return bit; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/surface/models/capabilities/SurfaceCapabilities.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.surface.models.capabilities; 2 | 3 | import com.justindriggers.vulkan.image.models.ImageUsage; 4 | import com.justindriggers.vulkan.models.Extent2D; 5 | import com.justindriggers.vulkan.models.Maskable; 6 | import org.lwjgl.vulkan.VkSurfaceCapabilitiesKHR; 7 | 8 | import java.util.Objects; 9 | import java.util.Set; 10 | 11 | public class SurfaceCapabilities { 12 | 13 | private final int minImageCount; 14 | private final int maxImageCount; 15 | private final Extent2D currentExtent; 16 | private final Extent2D minImageExtent; 17 | private final Extent2D maxImageExtent; 18 | private final int maxImageArrayLayers; 19 | private final Set supportedTransforms; 20 | private final SurfaceTransform currentTransform; 21 | private final Set supportedCompositeAlpha; 22 | private final Set supportedUsageFlags; 23 | 24 | public SurfaceCapabilities(final VkSurfaceCapabilitiesKHR vkSurfaceCapabilitiesKHR) { 25 | this( 26 | vkSurfaceCapabilitiesKHR.minImageCount(), 27 | vkSurfaceCapabilitiesKHR.maxImageCount(), 28 | new Extent2D(vkSurfaceCapabilitiesKHR.currentExtent()), 29 | new Extent2D(vkSurfaceCapabilitiesKHR.minImageExtent()), 30 | new Extent2D(vkSurfaceCapabilitiesKHR.maxImageExtent()), 31 | vkSurfaceCapabilitiesKHR.maxImageArrayLayers(), 32 | Maskable.fromBitMask(vkSurfaceCapabilitiesKHR.supportedTransforms(), SurfaceTransform.class), 33 | Maskable.fromBit(vkSurfaceCapabilitiesKHR.currentTransform(), SurfaceTransform.class), 34 | Maskable.fromBitMask(vkSurfaceCapabilitiesKHR.supportedCompositeAlpha(), CompositeAlpha.class), 35 | Maskable.fromBitMask(vkSurfaceCapabilitiesKHR.supportedUsageFlags(), ImageUsage.class) 36 | ); 37 | } 38 | 39 | public SurfaceCapabilities(final int minImageCount, 40 | final int maxImageCount, 41 | final Extent2D currentExtent, 42 | final Extent2D minImageExtent, 43 | final Extent2D maxImageExtent, 44 | final int maxImageArrayLayers, 45 | final Set supportedTransforms, 46 | final SurfaceTransform currentTransform, 47 | final Set supportedCompositeAlpha, 48 | final Set supportedUsageFlags) { 49 | this.minImageCount = minImageCount; 50 | this.maxImageCount = maxImageCount; 51 | this.currentExtent = currentExtent; 52 | this.minImageExtent = minImageExtent; 53 | this.maxImageExtent = maxImageExtent; 54 | this.maxImageArrayLayers = maxImageArrayLayers; 55 | this.supportedTransforms = supportedTransforms; 56 | this.currentTransform = currentTransform; 57 | this.supportedCompositeAlpha = supportedCompositeAlpha; 58 | this.supportedUsageFlags = supportedUsageFlags; 59 | } 60 | 61 | public int getMinImageCount() { 62 | return minImageCount; 63 | } 64 | 65 | public int getMaxImageCount() { 66 | return maxImageCount; 67 | } 68 | 69 | public Extent2D getCurrentExtent() { 70 | return currentExtent; 71 | } 72 | 73 | public Extent2D getMinImageExtent() { 74 | return minImageExtent; 75 | } 76 | 77 | public Extent2D getMaxImageExtent() { 78 | return maxImageExtent; 79 | } 80 | 81 | public int getMaxImageArrayLayers() { 82 | return maxImageArrayLayers; 83 | } 84 | 85 | public Set getSupportedTransforms() { 86 | return supportedTransforms; 87 | } 88 | 89 | public SurfaceTransform getCurrentTransform() { 90 | return currentTransform; 91 | } 92 | 93 | public Set getSupportedCompositeAlpha() { 94 | return supportedCompositeAlpha; 95 | } 96 | 97 | public Set getSupportedUsageFlags() { 98 | return supportedUsageFlags; 99 | } 100 | 101 | @Override 102 | public boolean equals(Object o) { 103 | if (this == o) { 104 | return true; 105 | } 106 | 107 | if (!(o instanceof SurfaceCapabilities)) { 108 | return false; 109 | } 110 | 111 | SurfaceCapabilities that = (SurfaceCapabilities) o; 112 | 113 | return minImageCount == that.minImageCount && 114 | maxImageCount == that.maxImageCount && 115 | maxImageArrayLayers == that.maxImageArrayLayers && 116 | Objects.equals(currentExtent, that.currentExtent) && 117 | Objects.equals(minImageExtent, that.minImageExtent) && 118 | Objects.equals(maxImageExtent, that.maxImageExtent) && 119 | Objects.equals(supportedTransforms, that.supportedTransforms) && 120 | currentTransform == that.currentTransform && 121 | Objects.equals(supportedCompositeAlpha, that.supportedCompositeAlpha) && 122 | Objects.equals(supportedUsageFlags, that.supportedUsageFlags); 123 | } 124 | 125 | @Override 126 | public int hashCode() { 127 | return Objects.hash( 128 | minImageCount, 129 | maxImageCount, 130 | currentExtent, 131 | minImageExtent, 132 | maxImageExtent, 133 | maxImageArrayLayers, 134 | supportedTransforms, 135 | currentTransform, 136 | supportedCompositeAlpha, 137 | supportedUsageFlags 138 | ); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/surface/models/capabilities/SurfaceTransform.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.surface.models.capabilities; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.KHRSurface; 5 | 6 | public enum SurfaceTransform implements Maskable { 7 | 8 | IDENTITY(KHRSurface.VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR), 9 | ROTATE_90(KHRSurface.VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR), 10 | ROTATE_180(KHRSurface.VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR), 11 | ROTATE_270(KHRSurface.VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR), 12 | HORIZONTAL_MIRROR(KHRSurface.VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR), 13 | HORIZONTAL_MIRROR_ROTATE_90(KHRSurface.VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR), 14 | HORIZONTAL_MIRROR_ROTATE_180(KHRSurface.VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR), 15 | HORIZONTAL_MIRROR_ROTATE_270(KHRSurface.VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR), 16 | INHERIT(KHRSurface.VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR); 17 | 18 | private final int bit; 19 | 20 | SurfaceTransform(final int bit) { 21 | this.bit = bit; 22 | } 23 | 24 | @Override 25 | public int getBitValue() { 26 | return bit; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/Framebuffer.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | import com.justindriggers.vulkan.image.ImageView; 5 | import com.justindriggers.vulkan.instance.VulkanFunction; 6 | import com.justindriggers.vulkan.models.Extent2D; 7 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 8 | import org.lwjgl.vulkan.VkFramebufferCreateInfo; 9 | 10 | import java.nio.LongBuffer; 11 | import java.util.Collections; 12 | import java.util.List; 13 | import java.util.Optional; 14 | 15 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 16 | import static org.lwjgl.system.MemoryUtil.memFree; 17 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO; 18 | import static org.lwjgl.vulkan.VK10.vkCreateFramebuffer; 19 | import static org.lwjgl.vulkan.VK10.vkDestroyFramebuffer; 20 | 21 | public class Framebuffer extends DisposablePointer { 22 | 23 | private final LogicalDevice device; 24 | 25 | public Framebuffer(final LogicalDevice device, 26 | final RenderPass renderPass, 27 | final List attachments, 28 | final Extent2D imageExtent) { 29 | super(createFramebuffer(device, renderPass, attachments, imageExtent)); 30 | this.device = device; 31 | } 32 | 33 | @Override 34 | protected void dispose(final long address) { 35 | vkDestroyFramebuffer(device.unwrap(), address, null); 36 | } 37 | 38 | private static long createFramebuffer(final LogicalDevice device, 39 | final RenderPass renderPass, 40 | final List attachments, 41 | final Extent2D imageExtent) { 42 | final long result; 43 | 44 | final List attachmentsSafe = Optional.ofNullable(attachments) 45 | .orElseGet(Collections::emptyList); 46 | 47 | final LongBuffer attachmentBuffer = memAllocLong(attachmentsSafe.size()); 48 | 49 | attachmentsSafe.stream() 50 | .mapToLong(ImageView::getAddress) 51 | .forEachOrdered(attachmentBuffer::put); 52 | 53 | attachmentBuffer.flip(); 54 | 55 | final LongBuffer framebuffer = memAllocLong(1); 56 | 57 | final VkFramebufferCreateInfo framebufferCreateInfo = VkFramebufferCreateInfo.calloc() 58 | .sType(VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO) 59 | .renderPass(renderPass.getAddress()) 60 | .pAttachments(attachmentBuffer) 61 | .width(imageExtent.getWidth()) 62 | .height(imageExtent.getHeight()) 63 | .layers(1); 64 | 65 | try { 66 | VulkanFunction.execute(() -> vkCreateFramebuffer(device.unwrap(), framebufferCreateInfo, null, 67 | framebuffer)); 68 | 69 | result = framebuffer.get(0); 70 | } finally { 71 | memFree(attachmentBuffer); 72 | memFree(framebuffer); 73 | 74 | framebufferCreateInfo.free(); 75 | } 76 | 77 | return result; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/Attachment.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.image.models.ImageLayout; 4 | import com.justindriggers.vulkan.models.Format; 5 | import com.justindriggers.vulkan.models.SampleCount; 6 | 7 | import java.util.Set; 8 | 9 | public abstract class Attachment { 10 | 11 | private final Format format; 12 | private final Set sampleCounts; 13 | private final AttachmentLoadOperation loadOperation; 14 | private final AttachmentStoreOperation storeOperation; 15 | private final AttachmentLoadOperation stencilLoadOperation; 16 | private final AttachmentStoreOperation stencilStoreOperation; 17 | private final ImageLayout initialLayout; 18 | private final ImageLayout finalLayout; 19 | 20 | Attachment(final Format format, 21 | final Set sampleCounts, 22 | final AttachmentLoadOperation loadOperation, 23 | final AttachmentStoreOperation storeOperation, 24 | final AttachmentLoadOperation stencilLoadOperation, 25 | final AttachmentStoreOperation stencilStoreOperation, 26 | final ImageLayout initialLayout, 27 | final ImageLayout finalLayout) { 28 | this.format = format; 29 | this.sampleCounts = sampleCounts; 30 | this.loadOperation = loadOperation; 31 | this.storeOperation = storeOperation; 32 | this.stencilLoadOperation = stencilLoadOperation; 33 | this.stencilStoreOperation = stencilStoreOperation; 34 | this.initialLayout = initialLayout; 35 | this.finalLayout = finalLayout; 36 | } 37 | 38 | public Format getFormat() { 39 | return format; 40 | } 41 | 42 | public Set getSampleCounts() { 43 | return sampleCounts; 44 | } 45 | 46 | public AttachmentLoadOperation getLoadOperation() { 47 | return loadOperation; 48 | } 49 | 50 | public AttachmentStoreOperation getStoreOperation() { 51 | return storeOperation; 52 | } 53 | 54 | public AttachmentLoadOperation getStencilLoadOperation() { 55 | return stencilLoadOperation; 56 | } 57 | 58 | public AttachmentStoreOperation getStencilStoreOperation() { 59 | return stencilStoreOperation; 60 | } 61 | 62 | public ImageLayout getInitialLayout() { 63 | return initialLayout; 64 | } 65 | 66 | public ImageLayout getFinalLayout() { 67 | return finalLayout; 68 | } 69 | 70 | public abstract ImageLayout getAttachmentLayout(); 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/AttachmentLoadOperation.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum AttachmentLoadOperation implements HasValue { 7 | 8 | LOAD(VK10.VK_ATTACHMENT_LOAD_OP_LOAD), 9 | CLEAR(VK10.VK_ATTACHMENT_LOAD_OP_CLEAR), 10 | DONT_CARE(VK10.VK_ATTACHMENT_LOAD_OP_DONT_CARE); 11 | 12 | private final int value; 13 | 14 | AttachmentLoadOperation(final int value) { 15 | this.value = value; 16 | } 17 | 18 | @Override 19 | public Integer getValue() { 20 | return value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/AttachmentStoreOperation.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum AttachmentStoreOperation implements HasValue { 7 | 8 | STORE(VK10.VK_ATTACHMENT_STORE_OP_STORE), 9 | DONT_CARE(VK10.VK_ATTACHMENT_STORE_OP_DONT_CARE); 10 | 11 | private final int value; 12 | 13 | AttachmentStoreOperation(final int value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Integer getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/ColorAttachment.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.image.models.ImageLayout; 4 | import com.justindriggers.vulkan.models.Format; 5 | import com.justindriggers.vulkan.models.SampleCount; 6 | 7 | import java.util.Set; 8 | 9 | public class ColorAttachment extends Attachment { 10 | 11 | public ColorAttachment(final Format format, 12 | final Set sampleCounts, 13 | final AttachmentLoadOperation loadOperation, 14 | final AttachmentStoreOperation storeOperation, 15 | final AttachmentLoadOperation stencilLoadOperation, 16 | final AttachmentStoreOperation stencilStoreOperation, 17 | final ImageLayout initialLayout, 18 | final ImageLayout finalLayout) { 19 | super(format, sampleCounts, loadOperation, storeOperation, stencilLoadOperation, stencilStoreOperation, 20 | initialLayout, finalLayout); 21 | } 22 | 23 | @Override 24 | public ImageLayout getAttachmentLayout() { 25 | return ImageLayout.COLOR_ATTACHMENT_OPTIMAL; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/DepthStencilAttachment.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.image.models.ImageLayout; 4 | import com.justindriggers.vulkan.models.Format; 5 | import com.justindriggers.vulkan.models.SampleCount; 6 | 7 | import java.util.Set; 8 | 9 | public class DepthStencilAttachment extends Attachment { 10 | 11 | public DepthStencilAttachment(final Format format, 12 | final Set sampleCounts, 13 | final AttachmentLoadOperation loadOperation, 14 | final AttachmentStoreOperation storeOperation, 15 | final AttachmentLoadOperation stencilLoadOperation, 16 | final AttachmentStoreOperation stencilStoreOperation, 17 | final ImageLayout initialLayout, 18 | final ImageLayout finalLayout) { 19 | super(format, sampleCounts, loadOperation, storeOperation, stencilLoadOperation, stencilStoreOperation, 20 | initialLayout, finalLayout); 21 | } 22 | 23 | @Override 24 | public ImageLayout getAttachmentLayout() { 25 | return ImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/Subpass.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.pipeline.models.PipelineBindPoint; 4 | 5 | import java.util.List; 6 | 7 | public class Subpass { 8 | 9 | private final PipelineBindPoint pipelineBindPoint; 10 | private final List colorAttachments; 11 | private final DepthStencilAttachment depthStencilAttachment; 12 | 13 | public Subpass(final PipelineBindPoint pipelineBindPoint, 14 | final List colorAttachments, 15 | final DepthStencilAttachment depthStencilAttachment) { 16 | this.pipelineBindPoint = pipelineBindPoint; 17 | this.colorAttachments = colorAttachments; 18 | this.depthStencilAttachment = depthStencilAttachment; 19 | } 20 | 21 | public PipelineBindPoint getPipelineBindPoint() { 22 | return pipelineBindPoint; 23 | } 24 | 25 | public List getColorAttachments() { 26 | return colorAttachments; 27 | } 28 | 29 | public DepthStencilAttachment getDepthStencilAttachment() { 30 | return depthStencilAttachment; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/SubpassContents.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.models.HasValue; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum SubpassContents implements HasValue { 7 | 8 | INLINE(VK10.VK_SUBPASS_CONTENTS_INLINE), 9 | SECONDARY_COMMAND_BUFFERS(VK10.VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS); 10 | 11 | private final int value; 12 | 13 | SubpassContents(final int value) { 14 | this.value = value; 15 | } 16 | 17 | @Override 18 | public Integer getValue() { 19 | return value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/swapchain/models/SubpassDependency.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.swapchain.models; 2 | 3 | import com.justindriggers.vulkan.models.Access; 4 | import com.justindriggers.vulkan.pipeline.models.PipelineStage; 5 | 6 | import java.util.Set; 7 | 8 | public class SubpassDependency { 9 | 10 | private final int sourceSubpass; 11 | private final int destinationSubpass; 12 | private final Set sourceStages; 13 | private final Set destinationStages; 14 | private final Set sourceAccessFlags; 15 | private final Set destinationAccessFlags; 16 | 17 | public SubpassDependency(final int sourceSubpass, 18 | final int destinationSubpass, 19 | final Set sourceStages, 20 | final Set destinationStages, 21 | final Set sourceAccessFlags, 22 | final Set destinationAccessFlags) { 23 | this.sourceSubpass = sourceSubpass; 24 | this.destinationSubpass = destinationSubpass; 25 | this.sourceStages = sourceStages; 26 | this.destinationStages = destinationStages; 27 | this.sourceAccessFlags = sourceAccessFlags; 28 | this.destinationAccessFlags = destinationAccessFlags; 29 | } 30 | 31 | public int getSourceSubpass() { 32 | return sourceSubpass; 33 | } 34 | 35 | public int getDestinationSubpass() { 36 | return destinationSubpass; 37 | } 38 | 39 | public Set getSourceStages() { 40 | return sourceStages; 41 | } 42 | 43 | public Set getDestinationStages() { 44 | return destinationStages; 45 | } 46 | 47 | public Set getSourceAccessFlags() { 48 | return sourceAccessFlags; 49 | } 50 | 51 | public Set getDestinationAccessFlags() { 52 | return destinationAccessFlags; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/synchronize/Fence.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.synchronize; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | import com.justindriggers.vulkan.instance.VulkanFunction; 5 | import com.justindriggers.vulkan.models.Maskable; 6 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 7 | import com.justindriggers.vulkan.synchronize.models.FenceCreationFlag; 8 | import org.lwjgl.vulkan.VkFenceCreateInfo; 9 | 10 | import java.nio.LongBuffer; 11 | import java.util.Optional; 12 | 13 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 14 | import static org.lwjgl.system.MemoryUtil.memFree; 15 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; 16 | import static org.lwjgl.vulkan.VK10.vkCreateFence; 17 | import static org.lwjgl.vulkan.VK10.vkDestroyFence; 18 | import static org.lwjgl.vulkan.VK10.vkResetFences; 19 | import static org.lwjgl.vulkan.VK10.vkWaitForFences; 20 | 21 | public class Fence extends DisposablePointer { 22 | 23 | private final LogicalDevice device; 24 | 25 | public Fence(final LogicalDevice device, 26 | final FenceCreationFlag... fenceCreationFlags) { 27 | super(createFence(device, fenceCreationFlags)); 28 | this.device = device; 29 | } 30 | 31 | @Override 32 | protected void dispose(final long address) { 33 | vkDestroyFence(device.unwrap(), address, null); 34 | } 35 | 36 | public void waitForSignal() { 37 | VulkanFunction.execute(() -> vkWaitForFences(device.unwrap(), getAddress(), true, Long.MAX_VALUE)); 38 | } 39 | 40 | public void reset() { 41 | VulkanFunction.execute(() -> vkResetFences(device.unwrap(), getAddress())); 42 | } 43 | 44 | private static long createFence(final LogicalDevice device, 45 | final FenceCreationFlag... fenceCreationFlags) { 46 | final long result; 47 | 48 | final LongBuffer fence = memAllocLong(1); 49 | 50 | final int flags = Optional.ofNullable(fenceCreationFlags) 51 | .map(Maskable::toBitMask) 52 | .orElse(0); 53 | 54 | final VkFenceCreateInfo fenceCreateInfo = VkFenceCreateInfo.calloc() 55 | .sType(VK_STRUCTURE_TYPE_FENCE_CREATE_INFO) 56 | .flags(flags); 57 | 58 | try { 59 | VulkanFunction.execute(() -> vkCreateFence(device.unwrap(), fenceCreateInfo, null, fence)); 60 | 61 | result = fence.get(0); 62 | } finally { 63 | memFree(fence); 64 | 65 | fenceCreateInfo.free(); 66 | } 67 | 68 | return result; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/synchronize/Semaphore.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.synchronize; 2 | 3 | import com.justindriggers.vulkan.devices.logical.LogicalDevice; 4 | import com.justindriggers.vulkan.instance.VulkanFunction; 5 | import com.justindriggers.vulkan.models.pointers.DisposablePointer; 6 | import org.lwjgl.vulkan.VkSemaphoreCreateInfo; 7 | 8 | import java.nio.LongBuffer; 9 | 10 | import static org.lwjgl.system.MemoryUtil.memAllocLong; 11 | import static org.lwjgl.vulkan.VK10.VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; 12 | import static org.lwjgl.vulkan.VK10.vkCreateSemaphore; 13 | import static org.lwjgl.vulkan.VK10.vkDestroySemaphore; 14 | 15 | public class Semaphore extends DisposablePointer { 16 | 17 | private final LogicalDevice device; 18 | 19 | public Semaphore(final LogicalDevice device) { 20 | super(createSemaphore(device)); 21 | this.device = device; 22 | } 23 | 24 | @Override 25 | protected void dispose(final long address) { 26 | vkDestroySemaphore(device.unwrap(), address, null); 27 | } 28 | 29 | private static long createSemaphore(final LogicalDevice device) { 30 | final LongBuffer semaphore = memAllocLong(1); 31 | 32 | final VkSemaphoreCreateInfo semaphoreCreateInfo = VkSemaphoreCreateInfo.calloc() 33 | .sType(VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO); 34 | 35 | try { 36 | VulkanFunction.execute(() -> vkCreateSemaphore(device.unwrap(), semaphoreCreateInfo, null, semaphore)); 37 | 38 | return semaphore.get(0); 39 | } finally { 40 | semaphoreCreateInfo.free(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/justindriggers/vulkan/synchronize/models/FenceCreationFlag.java: -------------------------------------------------------------------------------- 1 | package com.justindriggers.vulkan.synchronize.models; 2 | 3 | import com.justindriggers.vulkan.models.Maskable; 4 | import org.lwjgl.vulkan.VK10; 5 | 6 | public enum FenceCreationFlag implements Maskable { 7 | 8 | SIGNALED(VK10.VK_FENCE_CREATE_SIGNALED_BIT); 9 | 10 | private final int bit; 11 | 12 | FenceCreationFlag(final int bit) { 13 | this.bit = bit; 14 | } 15 | 16 | @Override 17 | public int getBitValue() { 18 | return bit; 19 | } 20 | } 21 | --------------------------------------------------------------------------------