Class: Vulkan::LogicalDevice
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 Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Finalizer
#finalize_with, included
#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, physical_device, queues:, extensions:, features: physical_device.supported_features) ⇒ LogicalDevice
Returns a new instance of LogicalDevice.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/vulkan/logical_device.rb', line 11
def initialize(instance, physical_device, queues:, extensions:, features: physical_device.supported_features)
raise ArgumentError, "instance can't be nil" unless instance
raise ArgumentError, "physical_device can't be nil" unless physical_device
@instance = instance
@physical_device = physical_device
extensions.concat ENV['DEVICE_EXTENSIONS'].split(/\:\s/) if ENV['DEVICE_EXTENSIONS']
if queues.size == 0
queues = [{ family: physical_device.queue_families.first, priorities: [1.0] }]
end
queues_p = queues.each_with_index.map do |queue_info, index|
family_index = queue_family_to_index(queue_info[:family])
priorities = queue_info[:priorities] || raise(ArgumentError, 'queue :priorities (array of floats) is required')
priorities = [1.0] if priorities.size == 0
queue_priorities_p = Fiddle::Pointer.malloc(Fiddle::SIZEOF_FLOAT * priorities.size)
priorities.each_with_index do |priority, i|
queue_priorities_p[i * Fiddle::SIZEOF_FLOAT, Fiddle::SIZEOF_FLOAT] = [priority].pack(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_FLOAT])
end
device_queue_info = VkDeviceQueueCreateInfo.malloc
device_queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO
device_queue_info.pNext = nil
device_queue_info.flags = 0
device_queue_info.queueFamilyIndex = family_index
device_queue_info.queueCount = priorities.size
device_queue_info.pQueuePriorities = queue_priorities_p
device_queue_info
end
queue_infos_p = array_of_structures(queues_p)
extensions_p = Vulkan.struct("names[#{extensions.size}]" => ['char *name']).malloc
extensions.each_with_index do |ext, i|
extname = ext.kind_of?(String) ? ext : ext[:extension_name]
extensions_p.names[i].name = Fiddle::Pointer[extname.b + "\x00"]
end
enabled_features = VkPhysicalDeviceFeatures.malloc
enabled_features.to_ptr.copy_from physical_device.features.to_ptr
enabled_features.class.members.each do |member|
member_name = member.gsub(/[0-9A-Z]+/) { |x| "_#{x.downcase}" }.to_sym
if features.include?(member_name)
if enabled_features[member] == VK_FALSE
raise Error::UnsupportedFeature.new(member_name, member)
end
else
enabled_features[member] = VK_FALSE
end
end
@enabled_features = struct_to_hash(enabled_features).reject! { |name, enabled| enabled != VK_TRUE }.keys
device_create_info = VkDeviceCreateInfo.malloc
device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO
device_create_info.pNext = nil
device_create_info.flags = 0
device_create_info.queueCreateInfoCount = queues.size
device_create_info.pQueueCreateInfos = queue_infos_p
device_create_info.enabledLayerCount = 0
device_create_info.ppEnabledLayerNames = nil
device_create_info.enabledExtensionCount = extensions.size
device_create_info.ppEnabledExtensionNames = extensions_p
device_create_info.pEnabledFeatures = enabled_features
device_wrapper = Vulkan.create_value("void *", nil)
check_result Vulkan[instance, nil].vkCreateDevice(physical_device.to_ptr, device_create_info, nil, device_wrapper)
@handle = device_wrapper.value
@vk = Vulkan[instance, self]
finalize_with Vulkan[instance, nil], :vkDestroyDevice, @handle, nil
queue_handle_wrapper = Vulkan.create_value("void *", nil)
@queue_families = queues.map do |queue|
queues = queue[:priorities].each_with_index.map do |priority, index|
@vk.vkGetDeviceQueue(@handle, queue_family_to_index(queue[:family]), index, queue_handle_wrapper)
Vulkan::Queue.new(@vk, queue_handle_wrapper.value, index: index, priority: priority)
end
queue[:family].merge queues: queues
end
end
|
Instance Attribute Details
#enabled_features ⇒ Object
Returns the value of attribute enabled_features.
9
10
11
|
# File 'lib/vulkan/logical_device.rb', line 9
def enabled_features
@enabled_features
end
|
#physical_device ⇒ Object
Returns the value of attribute physical_device.
7
8
9
|
# File 'lib/vulkan/logical_device.rb', line 7
def physical_device
@physical_device
end
|
#queue_families ⇒ Object
Returns the value of attribute queue_families.
8
9
10
|
# File 'lib/vulkan/logical_device.rb', line 8
def queue_families
@queue_families
end
|
Instance Method Details
#create_buffer(**args) ⇒ Object
109
110
111
|
# File 'lib/vulkan/logical_device.rb', line 109
def create_buffer(**args)
Vulkan::Buffer.new(@vk, physical_device, **args)
end
|
#create_buffer_memory_barrier(**args) ⇒ Object
157
158
159
|
# File 'lib/vulkan/logical_device.rb', line 157
def create_buffer_memory_barrier(**args)
Vulkan::BufferMemoryBarrier.new(**args)
end
|
#create_command_pool(**args) ⇒ Object
137
138
139
|
# File 'lib/vulkan/logical_device.rb', line 137
def create_command_pool(**args)
Vulkan::CommandPool.new(@vk, **args)
end
|
#create_descriptor_set_pool(**args) ⇒ Object
141
142
143
|
# File 'lib/vulkan/logical_device.rb', line 141
def create_descriptor_set_pool(**args)
Vulkan::DescriptorPool.new(@vk, **args)
end
|
#create_fence(**args) ⇒ Object
117
118
119
|
# File 'lib/vulkan/logical_device.rb', line 117
def create_fence(**args)
Vulkan::Fence.new(@vk, **args)
end
|
#create_framebuffer(**args) ⇒ Object
153
154
155
|
# File 'lib/vulkan/logical_device.rb', line 153
def create_framebuffer(**args)
Vulkan::Framebuffer.new(@vk, **args)
end
|
#create_image(**args) ⇒ Object
145
146
147
|
# File 'lib/vulkan/logical_device.rb', line 145
def create_image(**args)
Vulkan::Image.new(@vk, physical_device, **args)
end
|
#create_memory(**args) ⇒ Object
161
162
163
|
# File 'lib/vulkan/logical_device.rb', line 161
def create_memory(**args)
Vulkan::Memory.new(@vk, physical_device, **args)
end
|
#create_memory_barrier(**args) ⇒ Object
165
166
167
|
# File 'lib/vulkan/logical_device.rb', line 165
def create_memory_barrier(**args)
Vulkan::MemoryBarrier.new(**args)
end
|
#create_pipeline(**args) ⇒ Object
125
126
127
|
# File 'lib/vulkan/logical_device.rb', line 125
def create_pipeline(**args)
Vulkan::Pipeline.new(@vk, **args)
end
|
#create_renderpass ⇒ Object
133
134
135
|
# File 'lib/vulkan/logical_device.rb', line 133
def create_renderpass
Vulkan::RenderPass.new(@vk)
end
|
#create_sampler(**args) ⇒ Object
149
150
151
|
# File 'lib/vulkan/logical_device.rb', line 149
def create_sampler(**args)
Vulkan::Sampler.new(@vk, self, **args)
end
|
#create_semaphore ⇒ Object
121
122
123
|
# File 'lib/vulkan/logical_device.rb', line 121
def create_semaphore
Vulkan::Semaphore.new(@vk)
end
|
#create_shader_stage(**args) ⇒ Object
113
114
115
|
# File 'lib/vulkan/logical_device.rb', line 113
def create_shader_stage(**args)
Vulkan::ShaderStage.new(@vk, **args)
end
|
#create_swapchain(**args) ⇒ Object
129
130
131
|
# File 'lib/vulkan/logical_device.rb', line 129
def create_swapchain(**args)
Vulkan::Swapchain.new(@instance, self, **args)
end
|
#feature_enabled?(feature_name) ⇒ Boolean
105
106
107
|
# File 'lib/vulkan/logical_device.rb', line 105
def feature_enabled?(feature_name)
@enabled_features.include?(feature_name)
end
|
#hexaddr ⇒ Object
169
170
171
|
# File 'lib/vulkan/logical_device.rb', line 169
def hexaddr
to_ptr.to_i.to_s(16)
end
|
#max_color_samples ⇒ Object
97
98
99
|
# File 'lib/vulkan/logical_device.rb', line 97
def max_color_samples
physical_device.max_color_samples
end
|
#max_depth_samples ⇒ Object
101
102
103
|
# File 'lib/vulkan/logical_device.rb', line 101
def max_depth_samples
physical_device.max_depth_samples
end
|
#max_samples ⇒ Object
93
94
95
|
# File 'lib/vulkan/logical_device.rb', line 93
def max_samples
physical_device.max_samples
end
|
#to_ptr ⇒ Object
173
174
175
|
# File 'lib/vulkan/logical_device.rb', line 173
def to_ptr
@handle
end
|