Lines Matching refs:instance
31 * Instance extensions add instance-level or physical-device-level
74 vn_instance_init_renderer_versions(struct vn_instance *instance)
78 vn_call_vkEnumerateInstanceVersion(instance, &instance_version);
81 vn_log(instance, "failed to enumerate renderer instance version");
87 vn_log(instance, "unsupported renderer instance version %d.%d",
95 vn_log(instance, "renderer instance version %d.%d.%d",
102 instance->renderer_api_version =
103 MAX2(instance->base.base.app_info.api_version, VN_MIN_RENDERER_VERSION);
105 /* instance version for internal use is capped */
106 instance_version = MIN3(instance_version, instance->renderer_api_version,
107 instance->renderer_info.vk_xml_version);
110 instance->renderer_version = instance_version;
116 vn_instance_init_ring(struct vn_instance *instance)
118 const size_t buf_size = instance->experimental.largeRing
126 instance->ring.shmem =
127 vn_renderer_shmem_create(instance->renderer, layout.shmem_size);
128 if (!instance->ring.shmem) {
130 vn_log(instance, "failed to allocate/map ring shmem");
134 mtx_init(&instance->ring.mutex, mtx_plain);
136 struct vn_ring *ring = &instance->ring.ring;
137 vn_ring_init(ring, instance->renderer, &layout,
138 instance->ring.shmem->mmap_ptr);
140 instance->ring.id = (uintptr_t)ring;
144 .resourceId = instance->ring.shmem->res_id,
159 vn_encode_vkCreateRingMESA(&local_enc, 0, instance->ring.id, &info);
160 vn_renderer_submit_simple(instance->renderer, create_ring_data,
163 vn_cs_encoder_init_indirect(&instance->ring.upload, instance,
166 mtx_init(&instance->ring.roundtrip_mutex, mtx_plain);
167 instance->ring.roundtrip_next = 1;
173 vn_instance_get_reply_shmem_locked(struct vn_instance *instance,
178 vn_instance_init_experimental_features(struct vn_instance *instance)
180 if (instance->renderer_info.vk_mesa_venus_protocol_spec_version !=
183 vn_log(instance, "renderer supports no experimental features");
187 size_t struct_size = sizeof(instance->experimental);
192 &struct_size, &instance->experimental);
195 vn_instance_get_reply_shmem_locked(instance, reply_size, &reply_ptr);
205 &instance->experimental);
208 instance->renderer, local_data, vn_cs_encoder_get_len(&local_enc));
210 vn_renderer_shmem_unref(instance->renderer, reply_shmem);
217 &reply_dec, &struct_size, &instance->experimental);
218 vn_renderer_shmem_unref(instance->renderer, reply_shmem);
221 vn_log(instance,
226 instance->experimental.memoryResourceAllocationSize,
227 instance->experimental.globalFencing,
228 instance->experimental.largeRing);
235 vn_instance_init_renderer(struct vn_instance *instance)
237 const VkAllocationCallbacks *alloc = &instance->base.base.alloc;
239 VkResult result = vn_renderer_create(instance, alloc, &instance->renderer);
243 vn_renderer_get_info(instance->renderer, &instance->renderer_info);
246 if (instance->renderer_info.wire_format_version != version) {
248 vn_log(instance, "wire format version %d != %d",
249 instance->renderer_info.wire_format_version, version);
255 if (instance->renderer_info.vk_xml_version > version)
256 instance->renderer_info.vk_xml_version = version;
257 if (instance->renderer_info.vk_xml_version < VN_MIN_RENDERER_VERSION) {
259 vn_log(instance, "vk xml version %d.%d.%d < %d.%d.%d",
260 VK_VERSION_MAJOR(instance->renderer_info.vk_xml_version),
261 VK_VERSION_MINOR(instance->renderer_info.vk_xml_version),
262 VK_VERSION_PATCH(instance->renderer_info.vk_xml_version),
271 if (instance->renderer_info.vk_ext_command_serialization_spec_version >
273 instance->renderer_info.vk_ext_command_serialization_spec_version =
278 if (instance->renderer_info.vk_mesa_venus_protocol_spec_version >
280 instance->renderer_info.vk_mesa_venus_protocol_spec_version = version;
284 vn_log(instance, "connected to renderer");
285 vn_log(instance, "wire format version %d",
286 instance->renderer_info.wire_format_version);
287 vn_log(instance, "vk xml version %d.%d.%d",
288 VK_VERSION_MAJOR(instance->renderer_info.vk_xml_version),
289 VK_VERSION_MINOR(instance->renderer_info.vk_xml_version),
290 VK_VERSION_PATCH(instance->renderer_info.vk_xml_version));
292 instance, "VK_EXT_command_serialization spec version %d",
293 instance->renderer_info.vk_ext_command_serialization_spec_version);
294 vn_log(instance, "VK_MESA_venus_protocol spec version %d",
295 instance->renderer_info.vk_mesa_venus_protocol_spec_version);
302 vn_instance_submit_roundtrip(struct vn_instance *instance,
310 mtx_lock(&instance->ring.roundtrip_mutex);
311 const uint32_t seqno = instance->ring.roundtrip_next++;
312 vn_encode_vkWriteRingExtraMESA(&local_enc, 0, instance->ring.id, 0, seqno);
314 vn_renderer_submit_simple(instance->renderer, write_ring_extra_data,
316 mtx_unlock(&instance->ring.roundtrip_mutex);
323 vn_instance_wait_roundtrip(struct vn_instance *instance,
326 const struct vn_ring *ring = &instance->ring.ring;
459 vn_instance_submission_can_direct(const struct vn_instance *instance,
462 const size_t threshold = instance->experimental.largeRing
469 vn_instance_ring_cs_upload_locked(struct vn_instance *instance,
477 struct vn_cs_encoder *upload = &instance->ring.upload;
485 vn_instance_wait_roundtrip(instance, upload->current_buffer_roundtrip);
491 vn_instance_ring_submit_locked(struct vn_instance *instance,
496 struct vn_ring *ring = &instance->ring.ring;
498 const bool direct = vn_instance_submission_can_direct(instance, cs);
500 cs = vn_instance_ring_cs_upload_locked(instance, cs);
518 vn_encode_vkNotifyRingMESA(&local_enc, 0, instance->ring.id, seqno, 0);
519 vn_renderer_submit_simple(instance->renderer, notify_ring_data,
532 vn_instance_ring_submit(struct vn_instance *instance,
535 mtx_lock(&instance->ring.mutex);
536 VkResult result = vn_instance_ring_submit_locked(instance, cs, NULL, NULL);
537 mtx_unlock(&instance->ring.mutex);
543 vn_instance_grow_reply_shmem_locked(struct vn_instance *instance, size_t size)
548 instance->reply.size ? instance->reply.size : min_shmem_size;
556 vn_renderer_shmem_create(instance->renderer, shmem_size);
560 if (instance->reply.shmem)
561 vn_renderer_shmem_unref(instance->renderer, instance->reply.shmem);
562 instance->reply.shmem = shmem;
563 instance->reply.size = shmem_size;
564 instance->reply.used = 0;
565 instance->reply.ptr = shmem->mmap_ptr;
571 vn_instance_get_reply_shmem_locked(struct vn_instance *instance,
575 if (unlikely(instance->reply.used + size > instance->reply.size)) {
576 if (!vn_instance_grow_reply_shmem_locked(instance, size))
584 .resourceId = instance->reply.shmem->res_id,
585 .size = instance->reply.size,
590 if (likely(instance->ring.id)) {
591 vn_instance_roundtrip(instance);
592 vn_instance_ring_submit_locked(instance, &local_enc, NULL, NULL);
594 vn_renderer_submit_simple(instance->renderer,
604 const size_t offset = instance->reply.used;
608 if (likely(instance->ring.id)) {
609 vn_instance_ring_submit_locked(instance, &local_enc, NULL, NULL);
611 vn_renderer_submit_simple(instance->renderer,
616 *ptr = instance->reply.ptr + offset;
617 instance->reply.used += size;
619 return vn_renderer_shmem_ref(instance->renderer, instance->reply.shmem);
623 vn_instance_submit_command(struct vn_instance *instance,
629 mtx_lock(&instance->ring.mutex);
637 instance, submit->reply_size, &reply_ptr);
644 instance, &submit->command, submit->reply_shmem, &ring_seqno);
646 mtx_unlock(&instance->ring.mutex);
651 vn_ring_wait(&instance->ring.ring, ring_seqno);
656 instance->ring.command_dropped++;
657 mtx_unlock(&instance->ring.mutex);
660 /* instance commands */
696 struct vn_instance *instance;
702 instance = vk_zalloc(alloc, sizeof(*instance), VN_DEFAULT_ALIGN,
704 if (!instance)
712 result = vn_instance_base_init(&instance->base,
716 vk_free(alloc, instance);
720 mtx_init(&instance->physical_device.mutex, mtx_plain);
723 instance->base.base.app_info.api_version)) {
733 result = vn_instance_init_renderer(instance);
737 result = vn_instance_init_experimental_features(instance);
741 result = vn_instance_init_ring(instance);
745 result = vn_instance_init_renderer_versions(instance);
755 if (instance->base.base.app_info.api_version <
756 instance->renderer_api_version) {
759 local_app_info.apiVersion = instance->renderer_api_version;
763 .apiVersion = instance->renderer_api_version,
769 VkInstance instance_handle = vn_instance_to_handle(instance);
771 vn_call_vkCreateInstance(instance, pCreateInfo, NULL, &instance_handle);
775 driParseOptionInfo(&instance->available_dri_options, vn_dri_options,
777 driParseConfigFiles(&instance->dri_options,
778 &instance->available_dri_options, 0, "venus", NULL, NULL,
779 instance->base.base.app_info.app_name,
780 instance->base.base.app_info.app_version,
781 instance->base.base.app_info.engine_name,
782 instance->base.base.app_info.engine_version);
789 if (instance->reply.shmem)
790 vn_renderer_shmem_unref(instance->renderer, instance->reply.shmem);
792 if (instance->ring.shmem) {
796 vn_encode_vkDestroyRingMESA(&local_enc, 0, instance->ring.id);
797 vn_renderer_submit_simple(instance->renderer, destroy_ring_data,
800 mtx_destroy(&instance->ring.roundtrip_mutex);
801 vn_cs_encoder_fini(&instance->ring.upload);
802 vn_renderer_shmem_unref(instance->renderer, instance->ring.shmem);
803 vn_ring_fini(&instance->ring.ring);
804 mtx_destroy(&instance->ring.mutex);
807 if (instance->renderer)
808 vn_renderer_destroy(instance->renderer, alloc);
810 mtx_destroy(&instance->physical_device.mutex);
812 vn_instance_base_fini(&instance->base);
813 vk_free(alloc, instance);
822 struct vn_instance *instance = vn_instance_from_handle(_instance);
824 pAllocator ? pAllocator : &instance->base.base.alloc;
826 if (!instance)
829 if (instance->physical_device.initialized) {
830 for (uint32_t i = 0; i < instance->physical_device.device_count; i++)
831 vn_physical_device_fini(&instance->physical_device.devices[i]);
832 vk_free(alloc, instance->physical_device.devices);
833 vk_free(alloc, instance->physical_device.groups);
835 mtx_destroy(&instance->physical_device.mutex);
837 vn_call_vkDestroyInstance(instance, _instance, NULL);
839 vn_renderer_shmem_unref(instance->renderer, instance->reply.shmem);
844 vn_encode_vkDestroyRingMESA(&local_enc, 0, instance->ring.id);
845 vn_renderer_submit_simple(instance->renderer, destroy_ring_data,
848 mtx_destroy(&instance->ring.roundtrip_mutex);
849 vn_cs_encoder_fini(&instance->ring.upload);
850 vn_ring_fini(&instance->ring.ring);
851 mtx_destroy(&instance->ring.mutex);
852 vn_renderer_shmem_unref(instance->renderer, instance->ring.shmem);
854 vn_renderer_destroy(instance->renderer, alloc);
856 driDestroyOptionCache(&instance->dri_options);
857 driDestroyOptionInfo(&instance->available_dri_options);
859 vn_instance_base_fini(&instance->base);
860 vk_free(alloc, instance);
866 struct vn_instance *instance = vn_instance_from_handle(_instance);
867 return vk_instance_get_proc_addr(&instance->base.base,