libs/vkd3d-shader: Make sure that inserted chunks are sorted.

The list is expected to be empty or very small so insertion sort should
be fine.
This commit is contained in:
Józef Kucia 2017-08-01 13:55:49 +02:00
parent 3effb4b18c
commit fbeaf0ba95

View File

@ -141,7 +141,7 @@ static size_t vkd3d_spirv_stream_current_location(struct vkd3d_spirv_stream *str
static void vkd3d_spirv_stream_insert(struct vkd3d_spirv_stream *stream, static void vkd3d_spirv_stream_insert(struct vkd3d_spirv_stream *stream,
size_t location, const uint32_t *words, unsigned int word_count) size_t location, const uint32_t *words, unsigned int word_count)
{ {
struct vkd3d_spirv_chunk *chunk; struct vkd3d_spirv_chunk *chunk, *current;
if (!(chunk = vkd3d_malloc(offsetof(struct vkd3d_spirv_chunk, words[word_count])))) if (!(chunk = vkd3d_malloc(offsetof(struct vkd3d_spirv_chunk, words[word_count]))))
return; return;
@ -150,6 +150,15 @@ static void vkd3d_spirv_stream_insert(struct vkd3d_spirv_stream *stream,
chunk->word_count = word_count; chunk->word_count = word_count;
memcpy(chunk->words, words, word_count * sizeof(*words)); memcpy(chunk->words, words, word_count * sizeof(*words));
LIST_FOR_EACH_ENTRY(current, &stream->inserted_chunks, struct vkd3d_spirv_chunk, entry)
{
if (current->location > location)
{
list_add_before(&current->entry, &chunk->entry);
return;
}
}
list_add_tail(&stream->inserted_chunks, &chunk->entry); list_add_tail(&stream->inserted_chunks, &chunk->entry);
} }