66import com .jme3 .math .Quaternion ;
77import com .jme3 .math .Transform ;
88import com .jme3 .math .Vector3f ;
9- import com .jme3 .renderer .vulkan .VulkanUtils ;
109import com .jme3 .shaderc .ShaderType ;
1110import com .jme3 .shaderc .ShadercLoader ;
1211import com .jme3 .system .AppSettings ;
1716import com .jme3 .vulkan .Queue ;
1817import com .jme3 .vulkan .buffers .*;
1918import com .jme3 .vulkan .descriptors .*;
19+ import com .jme3 .vulkan .devices .*;
2020import com .jme3 .vulkan .flags .ImageUsageFlags ;
2121import com .jme3 .vulkan .flags .MemoryFlags ;
2222import com .jme3 .vulkan .flags .BufferUsageFlags ;
2323import com .jme3 .vulkan .images .*;
24- import org .lwjgl .PointerBuffer ;
2524import org .lwjgl .glfw .GLFW ;
2625import org .lwjgl .system .MemoryStack ;
2726import org .lwjgl .vulkan .*;
@@ -39,7 +38,7 @@ public class VulkanHelperTest extends SimpleApplication implements SwapchainUpda
3938
4039 private VulkanInstance instance ;
4140 private Surface surface ;
42- private LogicalDevice device ;
41+ private LogicalDevice < SimplePhysicalDevice > device ;
4342 private SimpleQueueFamilies queues ;
4443 private Swapchain swapchain ;
4544 private ShaderModule vertModule , fragModule ;
@@ -54,8 +53,6 @@ public class VulkanHelperTest extends SimpleApplication implements SwapchainUpda
5453 private boolean swapchainResizeFlag = false ;
5554 private boolean applicationStopped = false ;
5655
57- private final Collection <String > deviceExtensions = new ArrayList <>();
58-
5956 private VulkanLogger logger ;
6057
6158 // mesh
@@ -106,49 +103,41 @@ public void simpleInitApp() {
106103 flyCam .setMoveSpeed (5f );
107104 flyCam .setDragToRotate (true );
108105
109- deviceExtensions .add (KHRSwapchain .VK_KHR_SWAPCHAIN_EXTENSION_NAME );
110106 long window = ((LwjglVulkanContext )context ).getWindowHandle ();
111107
112- try (InstanceBuilder inst = new InstanceBuilder (VK13 .VK_API_VERSION_1_3 )) {
113-
114- // build instance
115- inst .addGlfwExtensions ();
116- inst .addDebugExtension ();
117- inst .addLunarGLayer ();
118- inst .setApplicationName (VulkanHelperTest .class .getSimpleName ());
119- inst .setApplicationVersion (1 , 0 , 0 );
120- instance = inst .build ();
121-
122- // debug callbacks
123- logger = new VulkanLogger (instance , Level .SEVERE );
124-
125- // surface
126- surface = new Surface (instance , window );
127-
128- // physical device
129- PhysicalDevice <SimpleQueueFamilies > physDevice = PhysicalDevice .getSuitableDevice (
130- instance , Arrays .asList (
131- surface ,
132- DeviceEvaluator .extensions (deviceExtensions ),
133- DeviceEvaluator .swapchain (surface ),
134- DeviceEvaluator .anisotropy ()
135- ),
136- () -> new SimpleQueueFamilies (surface ));
137-
138- // queue families
139- queues = physDevice .getQueueFamilies ();
140-
141- // logical device
142- PointerBuffer deviceExts = VulkanUtils .toPointers (inst .getStack (), deviceExtensions , inst .getStack ()::UTF8 );
143- device = new LogicalDevice (physDevice , deviceExts , inst .getLayers ());
144-
145- // create queues
146- physDevice .getQueueFamilies ().createQueues (device );
147-
148- // swapchain
149- try (SimpleSwapchainSupport support = new SimpleSwapchainSupport (physDevice , surface , window )) {
150- swapchain = new Swapchain (device , surface , support );
151- }
108+ instance = new VulkanInstance (VK_API_VERSION_1_3 );
109+ try (VulkanInstance .Builder i = instance .build ()) {
110+ i .addGlfwExtensions ();
111+ i .addDebugExtension ();
112+ i .addLunarGLayer ();
113+ i .setApplicationName (VulkanHelperTest .class .getSimpleName ());
114+ i .setApplicationVersion (1 , 0 , 0 );
115+ }
116+
117+ // debug callbacks
118+ logger = new VulkanLogger (instance , Level .SEVERE );
119+
120+ // surface
121+ surface = new Surface (instance , window );
122+
123+ // logical device
124+ device = new LogicalDevice <>(instance );
125+ try (LogicalDevice .Builder d = device .build (id -> new SimplePhysicalDevice (instance , surface , id ))) {
126+ d .addFilter (surface );
127+ d .addFilter (DeviceFilter .swapchain (surface ));
128+ d .addCriticalExtension (KHRSwapchain .VK_KHR_SWAPCHAIN_EXTENSION_NAME );
129+ d .addFeature (DeviceFeature .anisotropy (1f , true ));
130+ }
131+
132+ // swapchain
133+ swapchain = new Swapchain (device , surface );
134+ try (Swapchain .Builder s = swapchain .build ()) {
135+ s .addQueue (device .getPhysicalDevice ().getGraphics ());
136+ s .addQueue (device .getPhysicalDevice ().getPresent ());
137+ s .selectFormat (Image .Format .B8G8R8A8_SRGB .getVkEnum (), KHRSurface .VK_COLOR_SPACE_SRGB_NONLINEAR_KHR );
138+ s .selectMode (Swapchain .PresentMode .Mailbox );
139+ s .selectExtentByWindow ();
140+ s .selectImageCount (2 );
152141 }
153142
154143 descriptorLayout = new DescriptorSetLayout (device ,
@@ -415,7 +404,7 @@ public boolean populate(PhysicalDevice device, VkQueueFamilyProperties.Buffer pr
415404 graphicsIndex = i ;
416405 } else if (presentIndex == null ) {
417406 KHRSurface .vkGetPhysicalDeviceSurfaceSupportKHR (
418- device .getDevice (), i , surface .getNativeObject (), ibuf );
407+ device .getPhysicalDevice (), i , surface .getNativeObject (), ibuf );
419408 if (ibuf .get (0 ) == VK13 .VK_TRUE ) {
420409 presentIndex = i ;
421410 }
@@ -484,13 +473,13 @@ private static class SimpleSwapchainSupport implements SwapchainSupport, AutoClo
484473 public SimpleSwapchainSupport (PhysicalDevice device , Surface surface , long window ) {
485474 stack = MemoryStack .stackPush ();
486475 caps = VkSurfaceCapabilitiesKHR .malloc (stack );
487- KHRSurface .vkGetPhysicalDeviceSurfaceCapabilitiesKHR (device .getDevice (), surface .getNativeObject (), caps );
476+ KHRSurface .vkGetPhysicalDeviceSurfaceCapabilitiesKHR (device .getPhysicalDevice (), surface .getNativeObject (), caps );
488477 formats = enumerateBuffer (stack , n -> VkSurfaceFormatKHR .malloc (n , stack ),
489478 (count , buffer ) -> KHRSurface .vkGetPhysicalDeviceSurfaceFormatsKHR (
490- device .getDevice (), surface .getNativeObject (), count , buffer ));
479+ device .getPhysicalDevice (), surface .getNativeObject (), count , buffer ));
491480 modes = enumerateBuffer (stack , stack ::mallocInt ,
492481 (count , buffer ) -> KHRSurface .vkGetPhysicalDeviceSurfacePresentModesKHR (
493- device .getDevice (), surface .getNativeObject (), count , buffer ));
482+ device .getPhysicalDevice (), surface .getNativeObject (), count , buffer ));
494483 this .window = window ;
495484 }
496485
0 commit comments