def create_device(): global physical_device, render_queue_family, device # Device selection (use the first available) physical_devices = hvk.list_physical_devices(api, instance) physical_device = physical_devices[0] # Queues setup (A single graphic queue) queue_families = hvk.list_queue_families(api, physical_device) render_queue_family = next(qf for qf in queue_families if IntFlag( vk.QUEUE_GRAPHICS_BIT) in IntFlag(qf.properties.queue_flags)) render_queue_create_info = hvk.queue_create_info( queue_family_index=render_queue_family.index, queue_count=1) # Device creation extensions = ("VK_KHR_swapchain", ) device = hvk.create_device(api, physical_device, extensions, (render_queue_create_info, ))
def _setup_device(self): api, instance = self.api, self.instance conf = self.configuration queues_conf = conf.get("QUEUES", DEFAULT_ENGINE_CONFIGURATION["QUEUES"]) # Device selection failure_reasons, all_good = [], False physical_devices = hvk.list_physical_devices(api, instance) for index, physical_device in enumerate(physical_devices): # Features supported_features = hvk.physical_device_features(api, physical_device) if not "texture_compression_BC" in supported_features: failure_reasons.append(f"BC compressed textures are not supported on your machine on device #{index}") continue # Queues queue_families = hvk.list_queue_families(api, physical_device) queue_create_infos = [] mapped_queue_configurations = {} render_queue_data = None bad_queues = False for qconf in queues_conf: queue_family = None # Find a matching queue family for qf in queue_families: if qconf.type in IntFlag(qf.properties.queue_flags): queue_family = qf # Go to the next device if a required queue configuration could not be found if qconf.required and queue_family is None: bad_queues = True failure_reasons.append(f"No queue family matches the required configuration {qconf} on device #{index}") break # Update the queue create info array new_info = {"queue_family_index": queue_family.index, "queue_count": 0} queue_create_info = next((qc for qc in queue_create_infos if qc["queue_family_index"] == queue_family.index), new_info) queue_create_infos.append(queue_create_info) queue_local_index = queue_create_info["queue_count"] queue_create_info["queue_count"] += 1 # Save the index of the required graphics queue that will be used by the renderer if render_queue_data is None and QueueType.Graphics in qconf.type: render_queue_data = (queue_family, queue_local_index) # Associate the queue configuration with the family and the local index for queue handle fetching mapped_queue_configurations[qconf] = (queue_family, queue_local_index) if bad_queues: continue all_good = True break if not all_good: raise RuntimeError(failure_reasons) if render_queue_data is None: raise RuntimeError("No graphics queue was specified in the engine queues configuration. Protip: use \"QueueConf.Default\" ") # Device creation queue_create_infos = [hvk.queue_create_info(**args) for args in queue_create_infos] extensions = ("VK_KHR_swapchain",) features = vk.PhysicalDeviceFeatures(texture_compression_BC = 1) device = hvk.create_device(api, physical_device, extensions, queue_create_infos, features) # Fetching queues # First, fetch the render queue render_queue_family, render_family_local_index = render_queue_data render_queue_handle = hvk.get_queue(api, device, render_queue_family.index, render_family_local_index) render_queue = Queue(render_queue_handle, render_queue_family) # Second, fetch all the queues (yes, the render queue is fetched twice) queues = {} for queue_conf, queue_data in mapped_queue_configurations.items(): queue_family, local_index = queue_data queue_handle = hvk.get_queue(api, device, queue_family.index, local_index) queues[queue_conf.name] = Queue(queue_handle, queue_family) self.physical_device = physical_device self.device = device self.render_queue = render_queue self.queues = queues