diff options
author | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-03-21 15:21:47 +0300 |
---|---|---|
committer | Hans-Kristian Arntzen <post@arntzen-software.no> | 2022-09-14 16:48:23 +0300 |
commit | b4ecc103a45588e34d50c504b2e44f6d669263ff (patch) | |
tree | 61b430a8f4650c155dc49b26311111190642ef1e | |
parent | f0c82ae608ad98183f07c7ae04aa2a40ae119207 (diff) |
cache: Explicitly do not serialize SPIR-V code for cached PSOs.
With upcoming refactor, we might have to compile code on the fly.
To avoid any race conditions on fallback compile storing code[i] <-> StorePipeline reading code[i],
explicitly mark that code[] should be ignored.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
-rw-r--r-- | libs/vkd3d/cache.c | 27 | ||||
-rw-r--r-- | libs/vkd3d/state.c | 4 | ||||
-rw-r--r-- | libs/vkd3d/vkd3d_private.h | 1 |
3 files changed, 21 insertions, 11 deletions
diff --git a/libs/vkd3d/cache.c b/libs/vkd3d/cache.c index eef6ebd8..6bb4e046 100644 --- a/libs/vkd3d/cache.c +++ b/libs/vkd3d/cache.c @@ -903,18 +903,21 @@ static VkResult vkd3d_serialize_pipeline_state_inline(const struct d3d12_pipelin chunk = finish_and_iterate_blob_chunk(chunk); } - if (d3d12_pipeline_state_is_graphics(state)) + if (!state->pso_is_loaded_from_cached_blob) { - for (i = 0; i < state->graphics.stage_count; i++) + if (d3d12_pipeline_state_is_graphics(state)) { - vkd3d_shader_code_serialize_inline(&state->graphics.code[i], state->graphics.stages[i].stage, - varint_size[i], &chunk); + for (i = 0; i < state->graphics.stage_count; i++) + { + vkd3d_shader_code_serialize_inline(&state->graphics.code[i], state->graphics.stages[i].stage, + varint_size[i], &chunk); + } + } + else if (d3d12_pipeline_state_is_compute(state)) + { + vkd3d_shader_code_serialize_inline(&state->compute.code, VK_SHADER_STAGE_COMPUTE_BIT, + varint_size[0], &chunk); } - } - else if (d3d12_pipeline_state_is_compute(state)) - { - vkd3d_shader_code_serialize_inline(&state->compute.code, VK_SHADER_STAGE_COMPUTE_BIT, - varint_size[0], &chunk); } return VK_SUCCESS; @@ -994,7 +997,8 @@ static VkResult vkd3d_serialize_pipeline_state_referenced(struct d3d12_pipeline_ chunk = finish_and_iterate_blob_chunk(chunk); } - if (pipeline_library->flags & VKD3D_PIPELINE_LIBRARY_FLAG_SAVE_FULL_SPIRV) + if ((pipeline_library->flags & VKD3D_PIPELINE_LIBRARY_FLAG_SAVE_FULL_SPIRV) && + !state->pso_is_loaded_from_cached_blob) { if (d3d12_pipeline_state_is_graphics(state)) { @@ -1054,7 +1058,8 @@ VkResult vkd3d_serialize_pipeline_state(struct d3d12_pipeline_library *pipeline_ vk_blob_size += VKD3D_PIPELINE_BLOB_CHUNK_SIZE_RAW(vk_blob_size_pipeline_cache); } - if (!pipeline_library || (pipeline_library->flags & VKD3D_PIPELINE_LIBRARY_FLAG_SAVE_FULL_SPIRV)) + if ((!pipeline_library || (pipeline_library->flags & VKD3D_PIPELINE_LIBRARY_FLAG_SAVE_FULL_SPIRV)) && + !state->pso_is_loaded_from_cached_blob) { if (d3d12_pipeline_state_is_graphics(state)) { diff --git a/libs/vkd3d/state.c b/libs/vkd3d/state.c index eb4e7e9a..354268eb 100644 --- a/libs/vkd3d/state.c +++ b/libs/vkd3d/state.c @@ -4076,6 +4076,10 @@ HRESULT d3d12_pipeline_state_create(struct d3d12_device *device, VkPipelineBindP { VK_CALL(vkDestroyPipelineCache(device->vk_device, object->vk_pso_cache, NULL)); object->vk_pso_cache = VK_NULL_HANDLE; + + /* Set this explicitly so we avoid attempting to touch code[i] when serializing the PSO blob. + * We are at risk of compiling code on the fly in some upcoming situations. */ + object->pso_is_loaded_from_cached_blob = true; } else if (device->disk_cache.library) { diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 94fcaeb0..34476967 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -1690,6 +1690,7 @@ struct d3d12_pipeline_state struct d3d12_root_signature *root_signature; struct d3d12_device *device; bool root_signature_compat_hash_is_dxbc_derived; + bool pso_is_loaded_from_cached_blob; struct vkd3d_private_store private_store; }; |