Class: Vulkan::PhysicalDevice

Inherits:
Object
  • Object
show all
Includes:
Checks, Conversions
Defined in:
lib/vulkan/physical_device.rb

Constant Summary

Constants included from Conversions

Conversions::ACCESS_MASK_BITS, Conversions::BORDER_COLORS, Conversions::BUFFER_USAGE_BITS, Conversions::COMPARE_OPS, Conversions::DEPENDENCY_FLAG_BITS, Conversions::DESCRIPTOR_TYPES, Conversions::DYNAMIC_STATES, Conversions::FILTERS, Conversions::FORMAT_FEATURE_BITS, Conversions::IMAGE_ASPECT_BITS, Conversions::IMAGE_CREATE_BITS, Conversions::IMAGE_FORMATS, Conversions::IMAGE_TILING, Conversions::IMAGE_TYPES, Conversions::IMAGE_USAGE_BITS, Conversions::MEMORY_PROPERTIES, Conversions::PIPELINE_STAGE_BITS, Conversions::PRESENT_MODES, Conversions::SAMPLER_ADDRESS_MODES, Conversions::SAMPLER_MIPMAP_MODES, Conversions::SHADER_STAGE_BITS, Conversions::SHARING_MODES, Conversions::SURFACE_TRANSFORMS, Conversions::VERTEX_INPUT_RATES

Instance Method Summary collapse

Methods included from Conversions

#array_of_pointers, #array_of_structures, #array_of_uint32s, #bool_to_vk, #buffer_usage_flags_to_syms, #const_to_symbol, #cstr_to_rbstr, #flags_to_symbols, #flags_to_syms, #num_to_samples, #present_mode_to_sym, #queue_family_to_index, #struct_to_hash, #sym_to_blend_factor, #sym_to_blend_op, #sym_to_border_color, #sym_to_color_component_bit, #sym_to_command_buffer_level, #sym_to_command_buffer_usage, #sym_to_compare_op, #sym_to_cull_mode, #sym_to_descriptor_type, #sym_to_dynamic_state, #sym_to_filter, #sym_to_front_face, #sym_to_image_format, #sym_to_image_layout, #sym_to_image_tiling, #sym_to_image_type, #sym_to_index_type, #sym_to_load_op, #sym_to_pipeline_bind_point, #sym_to_polygon_mode, #sym_to_present_mode, #sym_to_sampler_address_mode, #sym_to_sampler_mipmap_mode, #sym_to_samples, #sym_to_sharing_mode, #sym_to_store_op, #sym_to_subpass_contents, #sym_to_topology, #sym_to_val, #sym_to_vertex_input_rate, #syms_to_access_mask, #syms_to_buffer_usage_flags, #syms_to_dependency_flags, #syms_to_descriptor_set_layout_type_flags, #syms_to_flags, #syms_to_format_feature_flags, #syms_to_image_aspect_flags, #syms_to_image_create_flags, #syms_to_image_usage_flags, #syms_to_memory_properties, #syms_to_pipeline_stage_flags, #syms_to_shader_stage_flags, #syms_to_surface_transforms, #vk_make_version, #vk_parse_version

Methods included from Checks

#check_result

Constructor Details

#initialize(instance, handle) ⇒ PhysicalDevice

Returns a new instance of PhysicalDevice.



6
7
8
9
10
# File 'lib/vulkan/physical_device.rb', line 6

def initialize(instance, handle)
  @handle = handle
  @instance = instance
  @vk = Vulkan[instance, nil]
end

Instance Method Details

#create_logical_device(**args) ⇒ Object Also known as: create



90
91
92
# File 'lib/vulkan/physical_device.rb', line 90

def create_logical_device(**args)
  Vulkan::LogicalDevice.new(@instance, self, **args)
end

#detect_supported_format(*candidates, usage:, tiling: :optimal) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/vulkan/physical_device.rb', line 61

def detect_supported_format(*candidates, usage:, tiling: :optimal)
  usage  = syms_to_format_feature_flags(usage)
  tiling = sym_to_image_tiling(tiling)
  candidates.flatten.each do |candidate|
    props = VkFormatProperties.malloc
    @vk.vkGetPhysicalDeviceFormatProperties(to_ptr, sym_to_format(candidate), props)
    if tiling == VK_IMAGE_TILING_LINEAR && (props.linearTilingFeatures & usage) == usage
      return candidate
    elsif tiling == VK_IMAGE_TILING_OPTIMAL && (props.optimalTilingFeatures & usage) == usage
      return candidate
    end
  end
  nil
end

#extension_namesObject



86
87
88
# File 'lib/vulkan/physical_device.rb', line 86

def extension_names
  extensions.map { |ext| ext[:extension_name] }
end

#extensionsObject



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/vulkan/physical_device.rb', line 148

def extensions
  @extensions ||= begin
    # get properties count
    count_ptr = Vulkan.create_value("uint32_t", 0)
    check_result @vk.vkEnumerateDeviceExtensionProperties(@handle, nil, count_ptr, nil)
    count = count_ptr.value
    # allocate n devices
    container_struct = Vulkan.struct("handles[#{count}]" => VkExtensionProperties)
    container = container_struct.malloc
    check_result @vk.vkEnumerateDeviceExtensionProperties(@handle, nil, count_ptr, container)
    container.handles.map { |handle| struct_to_hash(handle) }
  end
end

#featuresObject



130
131
132
133
134
135
136
# File 'lib/vulkan/physical_device.rb', line 130

def features
  @features ||= begin
    features = VkPhysicalDeviceFeatures.malloc
    @vk.vkGetPhysicalDeviceFeatures(@handle, features)
    features
  end
end

#features_hashObject



126
127
128
# File 'lib/vulkan/physical_device.rb', line 126

def features_hash
  struct_to_hash features
end

#inspectObject



12
13
14
15
16
# File 'lib/vulkan/physical_device.rb', line 12

def inspect
  # force lazy instance variables to be initialized
  to_hash
  super
end

#max_color_samplesObject



53
54
55
# File 'lib/vulkan/physical_device.rb', line 53

def max_color_samples
  sample_counts_to_max properties[:limits][:framebuffer_color_sample_counts]
end

#max_depth_samplesObject



57
58
59
# File 'lib/vulkan/physical_device.rb', line 57

def max_depth_samples
  sample_counts_to_max properties[:limits][:framebuffer_depth_sample_counts]
end

#max_samplesObject



39
40
41
# File 'lib/vulkan/physical_device.rb', line 39

def max_samples
  [max_color_samples, max_depth_samples].min
end

#memory_propertiesObject



96
97
98
99
100
101
102
# File 'lib/vulkan/physical_device.rb', line 96

def memory_properties
  @memory_properties ||= begin
    memory_properties = VkPhysicalDeviceMemoryProperties.malloc
    @vk.vkGetPhysicalDeviceMemoryProperties(to_ptr, memory_properties)
    struct_to_hash(memory_properties)
  end
end

#propertiesObject



138
139
140
141
142
143
144
145
146
# File 'lib/vulkan/physical_device.rb', line 138

def properties
  @properties ||= begin
    properties = VkPhysicalDeviceProperties.malloc
    @vk.vkGetPhysicalDeviceProperties(@handle, properties)
    properties = struct_to_hash(properties)
    properties[:device_type] = const_to_symbol(properties[:device_type], /^VK_PHYSICAL_DEVICE_TYPE_(.*?)$/)
    properties
  end
end

#queue_familiesObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/vulkan/physical_device.rb', line 104

def queue_families
  @queue_families ||= begin
    count_ptr = Vulkan.create_value("uint32_t", 0)
    @vk.vkGetPhysicalDeviceQueueFamilyProperties(@handle, count_ptr, nil)

    container_struct = Vulkan.struct("queues[#{count_ptr.value}]" => VkQueueFamilyProperties)
    container = container_struct.malloc
    @vk.vkGetPhysicalDeviceQueueFamilyProperties(@handle, count_ptr, container)
    container.queues.each_with_index.map do |prop, index|
      info = struct_to_hash(prop, Vulkan::QueueFamily.new(@vk.instance, self, index))
      info[:supports] = flags_to_symbols(info[:queue_flags], /^VK_QUEUE_(.*?)_BIT$/)
      info[:index] = index
      info[:queues] = [1.0]
      info
    end
  end
end

#sample_counts_to_max(counts) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/vulkan/physical_device.rb', line 43

def sample_counts_to_max(counts)
  return VK_SAMPLE_COUNT_64_BIT if counts & VK_SAMPLE_COUNT_64_BIT != 0
  return VK_SAMPLE_COUNT_32_BIT if counts & VK_SAMPLE_COUNT_32_BIT != 0
  return VK_SAMPLE_COUNT_16_BIT if counts & VK_SAMPLE_COUNT_16_BIT != 0
  return VK_SAMPLE_COUNT_8_BIT  if counts & VK_SAMPLE_COUNT_8_BIT  != 0
  return VK_SAMPLE_COUNT_4_BIT  if counts & VK_SAMPLE_COUNT_4_BIT  != 0
  return VK_SAMPLE_COUNT_2_BIT  if counts & VK_SAMPLE_COUNT_2_BIT  != 0
  return VK_SAMPLE_COUNT_1_BIT
end

#supported_featuresObject



31
32
33
# File 'lib/vulkan/physical_device.rb', line 31

def supported_features
  struct_to_hash(features).reject! { |k, v| v != VK_TRUE }.keys
end

#supports_feature?(feature_name) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/vulkan/physical_device.rb', line 122

def supports_feature?(feature_name)
  features_hash[feature_name] == VK_TRUE
end

#swapchain_surface_info(surface) ⇒ Object

Returns the swapchain surface info if the ‘“VK_KHR_swapchain”` extension is supported, `nil` otherwise.



78
79
80
81
82
83
84
# File 'lib/vulkan/physical_device.rb', line 78

def swapchain_surface_info(surface)
  if extension_names.include?('VK_KHR_swapchain')
    SwapchainSurfaceInfo.new(@instance, self, surface)
  else
    nil
  end
end

#to_hashObject



22
23
24
25
26
27
28
29
# File 'lib/vulkan/physical_device.rb', line 22

def to_hash
  {
    extensions: extensions,
    properties: properties,
    features: features_hash,
    queue_families: queue_families
  }
end

#to_ptrObject



18
19
20
# File 'lib/vulkan/physical_device.rb', line 18

def to_ptr
  @handle
end

#unsupported_featuresObject



35
36
37
# File 'lib/vulkan/physical_device.rb', line 35

def unsupported_features
  struct_to_hash(features).reject! { |k, v| v == VK_TRUE }.keys
end