Compare commits

...

17 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen 3a1e6de93d vkd3d: Use rwlock instead of spinlock in PSO fallback cache.
If we defer SPIR-V compilation we risk holding the lock for quite a long
time.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 14:35:41 +01:00
Hans-Kristian Arntzen 191214899d 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>
2022-03-21 14:35:41 +01:00
Hans-Kristian Arntzen 221c47d0fd vkd3d: Separate compilation to SPIR-V and creation of VkShaderModule.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 14:35:41 +01:00
Hans-Kristian Arntzen f322491964 vkd3d: Stub out DXBC code duplication for later.
When we have the ability to load PSO from identifiers only, we need to
retain DXBC blobs for later.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 12:46:57 +01:00
Hans-Kristian Arntzen 1f7f924662 vkd3d: Separate out the different stages of graphics PSO creation.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 12:46:57 +01:00
Hans-Kristian Arntzen 43b7cc8278 vkd3d: Refactor stages of obtaining SPIR-V modules.
- Try to load SPIR-V from cache
- Fallback compile to SPIR-V if necessary
- Parse PSO metadata obtained from either compilation or cache lookup

Also moves SPIR-V compilation to end of PSO init.
Prepares for refactor where we completely decouple PSO creation info
setup and SPIR-V compilation.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 12:46:57 +01:00
Hans-Kristian Arntzen 66ab0e52c7 vkd3d: Prepare for system where we can retain DXBC blobs in pipeline.
Simplifies the code somewhat. Only iterate over the shader_stages LUT
once.

Adds concept of duped DXBC blobs as well.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 11:56:31 +01:00
Hans-Kristian Arntzen adf03e7a4b vkd3d: Add FIXME for dubious use of dsv_plane_optimal_mask.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 11:31:51 +01:00
Hans-Kristian Arntzen fdf5ec705c vkd3d: Hoist out pipeline cache creation.
Not super useful to create a local pipeline cache if we're not going to
compile early, but it's super rare, and cleans up the code either way.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-21 11:29:22 +01:00
Hans-Kristian Arntzen d45b3a0dc7 vkd3d: Streamline vkd3d_create_compute_pipeline.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 17:20:10 +01:00
Hans-Kristian Arntzen 742ee58b50 vkd3d: Sink shader interface struct build to where we need it.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 17:05:43 +01:00
Hans-Kristian Arntzen 5798f5827b vkd3d: Refactor out how XFB info is stored.
For deferred compilation, we need to dupe the structs.
XFB is kinda rare, so it's okay to eat allocations here.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 16:54:42 +01:00
Hans-Kristian Arntzen f78b635d54 vkd3d: Ensure shader interface is set up per vkd3d_create_shader_stage.
Prepares for a situation where we can move this code into
vkd3d_create_shader_stage itself.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 16:33:20 +01:00
Hans-Kristian Arntzen 54a6605edf vkd3d: Refactor how we set compiler options.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 16:26:36 +01:00
Hans-Kristian Arntzen 818773d920 vkd3d: Refactor out shader interface struct plumbing.
Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 16:06:02 +01:00
Hans-Kristian Arntzen c1bc442742 vkd3d: Unify how we hold on to root signatures in PSO state.
Make use of private references to hold on to the root signature object.
This is important in situations where we end up compiling pipelines
late.

With private references like this, there is no longer a need to
distinguish a "private_root_signature", so just rename.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 15:50:00 +01:00
Hans-Kristian Arntzen 8deb9050c2 vkd3d: Make private_root_signatures actually private.
Makes sure that we drop private root signature device references when
public pipeline state refcount hits 0.

Signed-off-by: Hans-Kristian Arntzen <post@arntzen-software.no>
2022-03-18 15:33:06 +01:00
3 changed files with 549 additions and 330 deletions

View File

@ -764,18 +764,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;
@ -843,21 +846,24 @@ static VkResult vkd3d_serialize_pipeline_state_referenced(struct d3d12_pipeline_
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))
{
for (i = 0; i < state->graphics.stage_count; i++)
{
vkd3d_shader_code_serialize_referenced(pipeline_library,
&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_referenced(pipeline_library,
&state->graphics.code[i], state->graphics.stages[i].stage,
varint_size[i], &chunk);
&state->compute.code, VK_SHADER_STAGE_COMPUTE_BIT,
varint_size[0], &chunk);
}
}
else if (d3d12_pipeline_state_is_compute(state))
{
vkd3d_shader_code_serialize_referenced(pipeline_library,
&state->compute.code, VK_SHADER_STAGE_COMPUTE_BIT,
varint_size[0], &chunk);
}
return VK_SUCCESS;
}
@ -900,18 +906,21 @@ 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 (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))
{
vk_blob_size += vkd3d_shader_code_compute_serialized_size(&state->graphics.code[i],
need_blob_sizes ? &varint_size[i] : NULL, !pipeline_library);
for (i = 0; i < state->graphics.stage_count; i++)
{
vk_blob_size += vkd3d_shader_code_compute_serialized_size(&state->graphics.code[i],
need_blob_sizes ? &varint_size[i] : NULL, !pipeline_library);
}
}
else if (d3d12_pipeline_state_is_compute(state))
{
vk_blob_size += vkd3d_shader_code_compute_serialized_size(&state->compute.code,
need_blob_sizes ? &varint_size[0] : NULL, !pipeline_library);
}
}
else if (d3d12_pipeline_state_is_compute(state))
{
vk_blob_size += vkd3d_shader_code_compute_serialized_size(&state->compute.code,
need_blob_sizes ? &varint_size[0] : NULL, !pipeline_library);
}
total_size += vk_blob_size;
@ -1386,10 +1395,11 @@ static HRESULT d3d12_pipeline_library_load_pipeline(struct d3d12_pipeline_librar
if (root_signature)
pipeline_cache_compat.root_signature_compat_hash = root_signature->compatibility_hash;
}
else if (!cached_state->private_root_signature)
else if (cached_state->root_signature_compat_hash_is_dxbc_derived)
{
/* If we have no explicit root signature and the existing PSO didn't either,
* just inherit the compat hash from PSO to avoid comparing them. */
* just inherit the compat hash from PSO to avoid comparing them.
* The hash depends entirely on the DXBC blob either way. */
pipeline_cache_compat.root_signature_compat_hash = cached_state->pipeline_cache_compat.root_signature_compat_hash;
}

File diff suppressed because it is too large Load Diff

View File

@ -1327,6 +1327,7 @@ struct d3d12_root_signature
{
ID3D12RootSignature ID3D12RootSignature_iface;
LONG refcount;
LONG internal_refcount;
vkd3d_shader_hash_t compatibility_hash;
@ -1386,6 +1387,9 @@ struct d3d12_root_signature
HRESULT d3d12_root_signature_create(struct d3d12_device *device, const void *bytecode,
size_t bytecode_length, struct d3d12_root_signature **root_signature);
/* Private ref counts, for pipeline library. */
void d3d12_root_signature_inc_ref(struct d3d12_root_signature *state);
void d3d12_root_signature_dec_ref(struct d3d12_root_signature *state);
static inline struct d3d12_root_signature *impl_from_ID3D12RootSignature(ID3D12RootSignature *iface)
{
@ -1452,6 +1456,20 @@ enum vkd3d_plane_optimal_flag
VKD3D_DEPTH_STENCIL_PLANE_GENERAL = (1 << 2),
};
struct d3d12_graphics_pipeline_state_cached_desc
{
/* Information needed to compile to SPIR-V. */
unsigned int ps_output_swizzle[D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT];
struct vkd3d_shader_parameter ps_shader_parameters[1];
bool is_dual_source_blending;
VkShaderStageFlagBits xfb_stage;
struct vkd3d_shader_transform_feedback_info *xfb_info;
D3D12_SHADER_BYTECODE bytecode[VKD3D_MAX_SHADER_STAGES];
VkShaderStageFlagBits bytecode_stages[VKD3D_MAX_SHADER_STAGES];
uint32_t bytecode_duped_mask;
};
struct d3d12_graphics_pipeline_state
{
struct vkd3d_shader_debug_ring_spec_info spec_info[VKD3D_MAX_SHADER_STAGES];
@ -1459,6 +1477,8 @@ struct d3d12_graphics_pipeline_state
struct vkd3d_shader_code code[VKD3D_MAX_SHADER_STAGES];
size_t stage_count;
struct d3d12_graphics_pipeline_state_cached_desc cached_desc;
VkVertexInputAttributeDescription attributes[D3D12_VS_INPUT_REGISTER_COUNT];
VkVertexInputRate input_rates[D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
VkVertexInputBindingDivisorDescriptionEXT instance_divisors[D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
@ -1534,11 +1554,13 @@ struct d3d12_pipeline_state
};
VkPipelineBindPoint vk_bind_point;
VkPipelineCache vk_pso_cache;
spinlock_t lock;
rwlock_t lock;
struct vkd3d_pipeline_cache_compatibility pipeline_cache_compat;
ID3D12RootSignature *private_root_signature;
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;
};