vkd3d: Remove the global VkPipelineCache.

Just use VK_NULL_HANDLE. We rely on the disk cache to exist anyways
here. We never serialize the global pipeline cache, so it might just
confuse drivers into disable disk cache if anything.

Also reduce memory bloat.

Also gets rid of very old NV driver workaround where we forced global
pipeline cache.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
This commit is contained in:
Hans-Kristian Arntzen 2022-06-16 12:54:15 +02:00
parent 2f6a9e0d55
commit 135aff4685
3 changed files with 5 additions and 54 deletions

View File

@ -2806,48 +2806,6 @@ static ULONG STDMETHODCALLTYPE d3d12_device_AddRef(d3d12_device_iface *iface)
return refcount;
}
static HRESULT d3d12_device_global_pipeline_cache_init(struct d3d12_device *device)
{
/* On certain drivers, VkPipelineCache has a fixed (large) memory overhead.
* This means that using a VkPipelineCache per PSO will explode system memory usage, leading to OOM.
* To counteract this, we use one global pipeline cache instead, but this means we lose the ability to
* serialize and unserialize PSO state. Instead, we can just serialize garbage and ignore unserialization.
* From a correctness PoV, this is perfectly fine, and cached PSOs should be present in disk cache either way.
* The bug was introduced in 470 series, but was fixed as of 470.62.02 driver.
* 470.63.01 mainline one was released before 62.02, so it is also included in workaround list. */
bool use_global = false;
VkResult vr;
if (device->device_info.properties2.properties.vendorID == VKD3D_VENDOR_ID_NVIDIA)
{
uint32_t driver_version = device->device_info.properties2.properties.driverVersion;
use_global = (driver_version >= VKD3D_DRIVER_VERSION_MAKE_NV(470, 0, 0) &&
driver_version < VKD3D_DRIVER_VERSION_MAKE_NV(470, 62, 2)) ||
driver_version == VKD3D_DRIVER_VERSION_MAKE_NV(470, 63, 1);
if (use_global)
WARN("Workaround applied. Creating global pipeline cache.\n");
}
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_GLOBAL_PIPELINE_CACHE)
{
INFO("Using global pipeline cache, PSO caches will not be saved to individual blobs.\n");
use_global = true;
}
if (!use_global)
return S_OK;
vr = vkd3d_create_pipeline_cache(device, 0, NULL, &device->global_pipeline_cache);
return hresult_from_vk_result(vr);
}
static void d3d12_device_global_pipeline_cache_cleanup(struct d3d12_device *device)
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
VK_CALL(vkDestroyPipelineCache(device->vk_device, device->global_pipeline_cache, NULL));
}
static void d3d12_device_destroy(struct d3d12_device *device)
{
const struct vkd3d_vk_device_procs *vk_procs = &device->vk_procs;
@ -2874,7 +2832,6 @@ static void d3d12_device_destroy(struct d3d12_device *device)
vkd3d_breadcrumb_tracer_cleanup(&device->breadcrumb_tracer, device);
#endif
vkd3d_pipeline_library_flush_disk_cache(&device->disk_cache);
d3d12_device_global_pipeline_cache_cleanup(device);
vkd3d_sampler_state_cleanup(&device->sampler_state, device);
vkd3d_view_map_destroy(&device->sampler_map, device);
vkd3d_meta_ops_cleanup(&device->meta_ops, device);
@ -6212,14 +6169,11 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
goto out_cleanup_debug_ring;
#endif
if (FAILED(hr = d3d12_device_global_pipeline_cache_init(device)))
goto out_cleanup_breadcrumb_tracer;
if (vkd3d_descriptor_debug_active_qa_checks())
{
if (FAILED(hr = vkd3d_descriptor_debug_alloc_global_info(&device->descriptor_qa_global_info,
VKD3D_DESCRIPTOR_DEBUG_DEFAULT_NUM_COOKIES, device)))
goto out_cleanup_global_pipeline_cache;
goto out_cleanup_breadcrumb_tracer;
}
if ((device->parent = create_info->parent))
@ -6243,8 +6197,6 @@ static HRESULT d3d12_device_init(struct d3d12_device *device,
out_cleanup_descriptor_qa_global_info:
vkd3d_descriptor_debug_free_global_info(device->descriptor_qa_global_info, device);
out_cleanup_global_pipeline_cache:
d3d12_device_global_pipeline_cache_cleanup(device);
out_cleanup_breadcrumb_tracer:
#ifdef VKD3D_ENABLE_BREADCRUMBS
if (vkd3d_config_flags & VKD3D_CONFIG_FLAG_BREADCRUMBS)

View File

@ -2302,7 +2302,7 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st
shader_interface.descriptor_qa_heap_binding = &root_signature->descriptor_qa_heap_binding;
#endif
if (!device->global_pipeline_cache)
if (!(vkd3d_config_flags & VKD3D_CONFIG_FLAG_GLOBAL_PIPELINE_CACHE))
{
if ((hr = vkd3d_create_pipeline_cache_from_d3d12_desc(device, cached_pso, &state->vk_pso_cache)) < 0)
{
@ -2317,7 +2317,7 @@ static HRESULT d3d12_pipeline_state_init_compute(struct d3d12_pipeline_state *st
hr = vkd3d_create_compute_pipeline(device,
&desc->cs, &shader_interface,
root_signature->compute.vk_pipeline_layout,
state->vk_pso_cache ? state->vk_pso_cache : device->global_pipeline_cache,
state->vk_pso_cache,
&state->compute.vk_pipeline,
&state->compute.code);
@ -3584,7 +3584,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
if (can_compile_pipeline_early)
{
if (!device->global_pipeline_cache)
if (!(vkd3d_config_flags & VKD3D_CONFIG_FLAG_GLOBAL_PIPELINE_CACHE))
{
if ((hr = vkd3d_create_pipeline_cache_from_d3d12_desc(device, cached_pso, &state->vk_pso_cache)) < 0)
{
@ -3594,7 +3594,7 @@ static HRESULT d3d12_pipeline_state_init_graphics(struct d3d12_pipeline_state *s
}
if (!(graphics->pipeline = d3d12_pipeline_state_create_pipeline_variant(state, NULL, graphics->dsv_format,
state->vk_pso_cache ? state->vk_pso_cache : device->global_pipeline_cache, &graphics->dynamic_state_flags)))
state->vk_pso_cache, &graphics->dynamic_state_flags)))
goto fail;
}
else

View File

@ -3237,7 +3237,6 @@ struct d3d12_device
#ifdef VKD3D_ENABLE_DESCRIPTOR_QA
struct vkd3d_descriptor_qa_global_info *descriptor_qa_global_info;
#endif
VkPipelineCache global_pipeline_cache;
uint64_t shader_interface_key;
};