mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader: Introduce struct vkd3d_shader_source_list.
This commit is contained in:
Notes:
Henri Verbeet
2025-08-07 20:51:41 +02:00
Approved-by: Elizabeth Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1671
@@ -4908,15 +4908,15 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compil
|
|||||||
|
|
||||||
ctx->message_context = message_context;
|
ctx->message_context = message_context;
|
||||||
|
|
||||||
if (!(ctx->source_files = hlsl_alloc(ctx, sizeof(*ctx->source_files))))
|
vkd3d_shader_source_list_init(&ctx->source_files);
|
||||||
return false;
|
if (!vkd3d_shader_source_list_append(&ctx->source_files,
|
||||||
if (!(ctx->source_files[0] = hlsl_strdup(ctx, compile_info->source_name ? compile_info->source_name : "<anonymous>")))
|
compile_info->source_name ? compile_info->source_name : "<anonymous>"))
|
||||||
{
|
{
|
||||||
vkd3d_free(ctx->source_files);
|
vkd3d_shader_source_list_cleanup(&ctx->source_files);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ctx->source_files_count = 1;
|
|
||||||
ctx->location.source_name = ctx->source_files[0];
|
ctx->location.source_name = ctx->source_files.sources[0];
|
||||||
ctx->location.line = ctx->location.column = 1;
|
ctx->location.line = ctx->location.column = 1;
|
||||||
vkd3d_string_buffer_cache_init(&ctx->string_buffers);
|
vkd3d_string_buffer_cache_init(&ctx->string_buffers);
|
||||||
|
|
||||||
@@ -4924,8 +4924,8 @@ static bool hlsl_ctx_init(struct hlsl_ctx *ctx, const struct vkd3d_shader_compil
|
|||||||
|
|
||||||
if (!(ctx->dummy_scope = hlsl_new_scope(ctx, NULL)))
|
if (!(ctx->dummy_scope = hlsl_new_scope(ctx, NULL)))
|
||||||
{
|
{
|
||||||
vkd3d_free((void *)ctx->source_files[0]);
|
vkd3d_string_buffer_cache_cleanup(&ctx->string_buffers);
|
||||||
vkd3d_free(ctx->source_files);
|
vkd3d_shader_source_list_cleanup(&ctx->source_files);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
hlsl_push_scope(ctx);
|
hlsl_push_scope(ctx);
|
||||||
@@ -5010,10 +5010,8 @@ static void hlsl_ctx_cleanup(struct hlsl_ctx *ctx)
|
|||||||
struct hlsl_type *type, *next_type;
|
struct hlsl_type *type, *next_type;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < ctx->source_files_count; ++i)
|
|
||||||
vkd3d_free((void *)ctx->source_files[i]);
|
|
||||||
vkd3d_free(ctx->source_files);
|
|
||||||
vkd3d_string_buffer_cache_cleanup(&ctx->string_buffers);
|
vkd3d_string_buffer_cache_cleanup(&ctx->string_buffers);
|
||||||
|
vkd3d_shader_source_list_cleanup(&ctx->source_files);
|
||||||
|
|
||||||
rb_destroy(&ctx->functions, free_function_rb, NULL);
|
rb_destroy(&ctx->functions, free_function_rb, NULL);
|
||||||
|
|
||||||
|
@@ -1093,8 +1093,7 @@ struct hlsl_ctx
|
|||||||
{
|
{
|
||||||
const struct hlsl_profile_info *profile;
|
const struct hlsl_profile_info *profile;
|
||||||
|
|
||||||
const char **source_files;
|
struct vkd3d_shader_source_list source_files;
|
||||||
unsigned int source_files_count;
|
|
||||||
/* Current location being read in the HLSL source, updated while parsing. */
|
/* Current location being read in the HLSL source, updated while parsing. */
|
||||||
struct vkd3d_shader_location location;
|
struct vkd3d_shader_location location;
|
||||||
/* Stores the logging messages and logging configuration. */
|
/* Stores the logging messages and logging configuration. */
|
||||||
|
@@ -7190,24 +7190,20 @@ declaration_statement_list:
|
|||||||
preproc_directive:
|
preproc_directive:
|
||||||
PRE_LINE STRING
|
PRE_LINE STRING
|
||||||
{
|
{
|
||||||
const char **new_array = NULL;
|
|
||||||
|
|
||||||
ctx->location.line = $1;
|
|
||||||
if (strcmp($2, ctx->location.source_name))
|
if (strcmp($2, ctx->location.source_name))
|
||||||
new_array = hlsl_realloc(ctx, ctx->source_files,
|
|
||||||
sizeof(*ctx->source_files) * (ctx->source_files_count + 1));
|
|
||||||
|
|
||||||
if (new_array)
|
|
||||||
{
|
{
|
||||||
ctx->source_files = new_array;
|
if (!vkd3d_shader_source_list_append(&ctx->source_files, $2))
|
||||||
ctx->source_files[ctx->source_files_count++] = $2;
|
{
|
||||||
ctx->location.source_name = $2;
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
vkd3d_free($2);
|
ctx->location.line = $1;
|
||||||
|
ctx->location.source_name = ctx->source_files.sources[ctx->source_files.count - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vkd3d_free($2);
|
||||||
|
}
|
||||||
|
|
||||||
struct_declaration_without_vars:
|
struct_declaration_without_vars:
|
||||||
var_modifiers struct_spec ';'
|
var_modifiers struct_spec ';'
|
||||||
|
@@ -57,6 +57,39 @@ uint32_t vkd3d_parse_integer(const char *s)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool vkd3d_shader_source_list_append(struct vkd3d_shader_source_list *l, const char *source)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
|
||||||
|
if (!(s = vkd3d_strdup(source)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!vkd3d_array_reserve((void **)&l->sources, &l->capacity, l->count + 1, sizeof(*l->sources)))
|
||||||
|
{
|
||||||
|
vkd3d_free(s);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
l->sources[l->count++] = s;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vkd3d_shader_source_list_cleanup(struct vkd3d_shader_source_list *l)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < l->count; ++i)
|
||||||
|
{
|
||||||
|
vkd3d_free((void *)l->sources[i]);
|
||||||
|
}
|
||||||
|
vkd3d_free(l->sources);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vkd3d_shader_source_list_init(struct vkd3d_shader_source_list *l)
|
||||||
|
{
|
||||||
|
memset(l, 0, sizeof(*l));
|
||||||
|
}
|
||||||
|
|
||||||
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer)
|
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer)
|
||||||
{
|
{
|
||||||
buffer->buffer_size = 16;
|
buffer->buffer_size = 16;
|
||||||
|
@@ -937,6 +937,16 @@ enum vkd3d_shader_type
|
|||||||
|
|
||||||
struct vkd3d_shader_message_context;
|
struct vkd3d_shader_message_context;
|
||||||
|
|
||||||
|
struct vkd3d_shader_source_list
|
||||||
|
{
|
||||||
|
const char **sources;
|
||||||
|
size_t capacity, count;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool vkd3d_shader_source_list_append(struct vkd3d_shader_source_list *l, const char *source);
|
||||||
|
void vkd3d_shader_source_list_cleanup(struct vkd3d_shader_source_list *l);
|
||||||
|
void vkd3d_shader_source_list_init(struct vkd3d_shader_source_list *l);
|
||||||
|
|
||||||
struct vkd3d_shader_version
|
struct vkd3d_shader_version
|
||||||
{
|
{
|
||||||
enum vkd3d_shader_type type;
|
enum vkd3d_shader_type type;
|
||||||
|
Reference in New Issue
Block a user