Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions samples/vulkan_test-triangle.adb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
--------------------------------------------------------------------------------
with Ada.Text_IO;
With Glfw;
with Vulkan; use Vulkan;
with Vulkan; use Vulkan;
With Vulkan.Math.Mat4x4;
with Vulkan.Math.Vec4;
with Vulkan.Math.GenFMatrix; use Vulkan.Math.GenFMatrix;
with Vulkan.Core.Instance; use Vulkan.Core.Instance;
with Vulkan.Core; use Vulkan.Core;
with Vulkan.Math.GenFMatrix; use Vulkan.Math.GenFMatrix;
with Vulkan.Core.Instance; use Vulkan.Core.Instance;
with Vulkan.Core.Physical_Device; use Vulkan.Core.Physical_Device;
with Vulkan.Core; use Vulkan.Core;


procedure Vulkan_Test.Triangle is
Expand Down Expand Up @@ -56,6 +57,8 @@ procedure Vulkan_Test.Triangle is

instance : Vk_Instance;

physical_devices : Vk_Physical_Device_Vector;

begin
Ada.Text_IO.Put_Line("Initializing Window System");

Expand Down Expand Up @@ -83,8 +86,6 @@ begin

Glfw.Get_Required_Instance_Extensions(required_extension_names);

required_extension_names.Append(Glfw.To_Bounded_String(To_String(VK_EXT_debug_utils)));

for name of required_extension_names loop

-- Determine whether the name exists in the set of supported extensions
Expand Down Expand Up @@ -152,6 +153,11 @@ begin
-- Create an instance!
instance := Vk_Create_Instance(create_info => instance_info);

-- Enumerating Physical Devices
Ada.Text_IO.Put_Line("Enumerating Physical Devices");
Vk_Enumerate_Physical_Devices(instance, physical_devices);

Ada.Text_IO.Put_Line("Enumerated " & physical_devices.Length'Image & " physical devices!");
-- Main Loop
Ada.Text_IO.Put_Line("Entering Main Loop");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ with crtdefs_h;
with Interfaces.C.Strings;
with Interfaces.C.Extensions;

package Vulkan.Core.vulkan_core_h is
package Vulkan.Core.Binding is
pragma Preelaborate;

-- unsupported macro: VULKAN_CORE_H_ 1
Expand Down Expand Up @@ -14873,4 +14873,4 @@ package Vulkan.Core.vulkan_core_h is
end record;
pragma Convention (C_Pass_By_Copy, VkPhysicalDeviceRayQueryFeaturesKHR); -- vulkan_core.h:12173

end Vulkan.Core.vulkan_core_h;
end Vulkan.Core.Binding;
14,876 changes: 0 additions & 14,876 deletions src/vulkan-binding/vulkan-vulkan_core_h.ads

This file was deleted.

69 changes: 59 additions & 10 deletions src/vulkan-core/vulkan-core-instance.adb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--------------------------------------------------------------------------------
with Vulkan.Core.Vulkan_Core_H; use Vulkan.Core.Vulkan_Core_H;
with stdint_h; use stdint_h;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Ada.Containers; use Ada.Containers;
with System; use System;
with Vulkan.Core.Binding; use Vulkan.Core.Binding;
with stdint_h; use stdint_h;
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
with Ada.Containers; use Ada.Containers;
with System; use System;


--------------------------------------------------------------------------------
Expand All @@ -43,6 +43,7 @@ package body Vulkan.Core.Instance is

type Chars_Ptr_Array is array (Natural range <>) of Interfaces.C.Strings.chars_ptr;

type Vk_Physical_Device_Array is array (Natural range <>) of VkPhysicalDevice;

--< Convert Extension properties to a type that is easier to use.
function To_Vk_Extension_Properties(from : in VkExtensionProperties)
Expand All @@ -69,7 +70,7 @@ package body Vulkan.Core.Instance is
properties : in out Vk_Extension_Properties_Vector) is

extension_count : aliased stdint_h.uint32_t := 0;

result : VkResult;
begin

Expand Down Expand Up @@ -213,7 +214,7 @@ package body Vulkan.Core.Instance is

result := vkCreateInstance(
pCreateInfo => local_create_info'Address,
pInstance => instance.instance'Address);
pInstance => instance.handle'Address);

if result /= VK_SUCCESS then
raise VULKAN_ERROR with "Call to vkCreateInstance() failed with result " & result'Image;
Expand All @@ -227,13 +228,61 @@ package body Vulkan.Core.Instance is

procedure Vk_Destroy_Instance(instance : in out Vk_Instance) is begin

vkDestroyInstance(vkInstance(instance.instance));
vkDestroyInstance(vkInstance(instance.handle));

instance.instance := System.Null_Address;
instance.handle := System.Null_Address;

end Vk_Destroy_Instance;


----------------------------------------------------------------------------


procedure Vk_Enumerate_Physical_Devices (
instance : in Vk_Instance;
physical_devices : in out Vk_Physical_Device_Vector) is

physical_device_count : aliased stdint_h.uint32_t := 0;
result : VkResult;

begin

result := vkEnumeratePhysicalDevices(
VkInstance(instance.handle),
physical_device_count'Access,
System.Null_Address);

if result = VK_SUCCESS and physical_device_count > 0 then
declare
physical_device_array : Vk_Physical_Device_Array(1 .. Natural(physical_device_count)) :=
(others => <>);
begin

result := VkEnumeratePhysicalDevices(
VkInstance(instance.handle),
physical_device_count'Access,
physical_device_array'Address);

if result = VK_SUCCESS then
for index in 1 .. Natural(physical_device_count) loop
declare
physical_device : constant Vk_Physical_Device
:= (handle => System.Address(physical_device_array(index)));
begin
physical_devices.Append(physical_device);
end;
end loop;
end if;
end;
end if;

if result /= VK_SUCCESS then
raise VULKAN_ERROR with "Call to vkEnumeratePhysicalDevices() failed with result " & result'Image;
end if;

end Vk_Enumerate_Physical_Devices;


----------------------------------------------------------------------------
-- Local Operations
----------------------------------------------------------------------------
Expand Down
35 changes: 21 additions & 14 deletions src/vulkan-core/vulkan-core-instance.ads
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
-- SOFTWARE.
--------------------------------------------------------------------------------
with Ada.Containers.Vectors;
with System;
with Vulkan.Core.Physical_Device; use Vulkan.Core.Physical_Device;

--------------------------------------------------------------------------------
--< @group Vulkan Core
Expand All @@ -39,7 +39,7 @@ package Vulkan.Core.Instance is
VK_LAYER_KHRONOS_validation : constant Vk_String := To_Vk_String("VK_LAYER_KHRONOS_validation");

--< A reference to the vkInstance type.
type Vk_Instance is private;
type Vk_Instance is new Vk_Object;

--< This record describes extensions that can be supported by an instance of
--< Vulkan on the platform on which it is being run.
Expand Down Expand Up @@ -140,7 +140,7 @@ package Vulkan.Core.Instance is
--< The following exceptions can be raised by this operation:
--< VULKAN_ERROR
----------------------------------------------------------------------------
function Vk_Create_Instance(
function Vk_Create_Instance (
create_info : in Vk_Instance_Create_Info) return Vk_Instance;


Expand All @@ -155,39 +155,46 @@ package Vulkan.Core.Instance is
--< The following exceptions can be raised by this operation:
--< VULKAN_ERROR
----------------------------------------------------------------------------
procedure Vk_Destroy_Instance(
procedure Vk_Destroy_Instance (
instance : in out Vk_Instance);


----------------------------------------------------------------------------
--< @brief
--< This operation enumerates all physical devices that can be used from the instance.
--<
--< @param physical_devices
--< A list of physical devices that were found by the Vulkan Instance.
--<
----------------------------------------------------------------------------
procedure Vk_Enumerate_Physical_Devices (
instance : in Vk_Instance;
physical_devices : in out Vk_Physical_Device_Vector);


----------------------------------------------------------------------------
--< @brief
--< This operation converts the extension properties object to a human readable
--< string.
function Image(property : in Vk_Extension_Properties) return String is
function Image (property : in Vk_Extension_Properties) return String is
("[ name = " & Image(property.name) & ", version = " & Image(property.version) & " ]") with inline;

function Image(property : in Vk_Layer_Properties) return String is
function Image (property : in Vk_Layer_Properties) return String is
("[ name = " & Image(property.name) &
", spec_version = " & Image(property.spec_version) &
", implementation_version = " & Image(property.implementation_version) &
", description = " & Image(property.description) & "]") with inline;

function Image(application_info :in Vk_Application_Create_Info) return String is
function Image (application_info :in Vk_Application_Create_Info) return String is
("[ application_name = " & Image(application_info.application_name) & LF &
", application_version = " & Image(application_info.application_version) & LF &
", engine_name = " & Image(application_info.engine_name) & LF &
", engine_version = " & Image(application_info.engine_version) & LF &
", api_version = " & Image(application_info.api_version) & " ]") with inline;

function Image(instance_create_info : in Vk_Instance_Create_Info) return String is
function Image (instance_create_info : in Vk_Instance_Create_Info) return String is
("[ application_info = " & Image(instance_create_info.application_info) & LF &
", enabled_extension_names.Length = " & instance_create_info.enabled_extension_names.Length'Image & LF &
", enabled_layer_names.Length = " & instance_create_info.enabled_layer_names.Length'Image & "]") with inline;

private

type Vk_Instance is record
instance : System.Address := System.Null_Address;
end record;

end Vulkan.Core.Instance;
39 changes: 39 additions & 0 deletions src/vulkan-core/vulkan-core-physical_device.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--------------------------------------------------------------------------------
-- MIT License
--
-- Copyright (c) 2021 Zane Myers
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--------------------------------------------------------------------------------

package Vulkan.Core.Physical_Device is
pragma Preelaborate;

--< A physical device type.
type Vk_Physical_Device is new Vk_Object;

--< Instantiation of the vector package for Vk_Phsyical_Device
package Vk_Physical_Device_Vectors is new Ada.Containers.Vectors(
Index_Type => Natural,
Element_Type => Vk_Physical_Device);

subtype Vk_Physical_Device_Vector is Vk_Physical_Device_Vectors.Vector;


end Vulkan.Core.Physical_Device;
12 changes: 11 additions & 1 deletion src/vulkan-core/vulkan-core.ads
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ with Ada.Strings.Bounded;
with Ada.Containers.Vectors;
with Ada.Characters.Latin_1;
with Interfaces.C;

with System;
--------------------------------------------------------------------------------
--< @group Vulkan Core
--------------------------------------------------------------------------------
Expand All @@ -43,6 +43,9 @@ package Vulkan.Core is
--< Local definition of line feed.
LF : constant String := "" & Ada.Characters.Latin_1.LF;

--< Type is a Vk_Object.
type Vk_Object is private;

--< Vulkan Specification Major Version Number.
type Vk_Spec_Major is mod (2 ** 10);

Expand Down Expand Up @@ -99,4 +102,11 @@ package Vulkan.Core is
function Image(string_ref : in Vk_String) return String is
(To_String(string_ref));

private


type Vk_Object is record
handle : System.Address := System.Null_Address;
end record;

end Vulkan.Core;