2017-06-16 13:38:21 -07:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2017 Józef Kucia for CodeWeavers
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "vkd3d_shader_private.h"
|
2020-08-06 01:53:45 -07:00
|
|
|
|
#include "vkd3d_version.h"
|
2017-06-16 13:38:21 -07:00
|
|
|
|
|
2019-01-31 02:29:27 -08:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2019-01-31 02:29:29 -08:00
|
|
|
|
VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG");
|
2019-01-31 02:29:28 -08:00
|
|
|
|
|
2020-07-23 02:11:25 -07:00
|
|
|
|
static void vkd3d_string_buffer_clear(struct vkd3d_string_buffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
buffer->buffer[0] = '\0';
|
|
|
|
|
buffer->content_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
buffer->buffer_size = 32;
|
|
|
|
|
if (!(buffer->buffer = vkd3d_malloc(buffer->buffer_size)))
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to allocate shader buffer memory.\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vkd3d_string_buffer_clear(buffer);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_free(buffer->buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool vkd3d_string_buffer_resize(struct vkd3d_string_buffer *buffer, int rc)
|
|
|
|
|
{
|
|
|
|
|
unsigned int new_buffer_size = buffer->buffer_size * 2;
|
|
|
|
|
char *new_buffer;
|
|
|
|
|
|
|
|
|
|
while (rc > 0 && (unsigned int)rc >= new_buffer_size - buffer->content_size)
|
|
|
|
|
new_buffer_size *= 2;
|
|
|
|
|
if (!(new_buffer = vkd3d_realloc(buffer->buffer, new_buffer_size)))
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to grow buffer.\n");
|
|
|
|
|
buffer->buffer[buffer->content_size] = '\0';
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
buffer->buffer = new_buffer;
|
|
|
|
|
buffer->buffer_size = new_buffer_size;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *format, va_list args)
|
|
|
|
|
{
|
|
|
|
|
unsigned int rem;
|
|
|
|
|
va_list a;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
rem = buffer->buffer_size - buffer->content_size;
|
|
|
|
|
va_copy(a, args);
|
|
|
|
|
rc = vsnprintf(&buffer->buffer[buffer->content_size], rem, format, a);
|
|
|
|
|
va_end(a);
|
|
|
|
|
if (rc >= 0 && (unsigned int)rc < rem)
|
|
|
|
|
{
|
|
|
|
|
buffer->content_size += rc;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!vkd3d_string_buffer_resize(buffer, rc))
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int VKD3D_PRINTF_FUNC(2, 3) vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer,
|
|
|
|
|
const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
ret = vkd3d_string_buffer_vprintf(buffer, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 02:52:34 -07:00
|
|
|
|
static void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function)
|
|
|
|
|
{
|
|
|
|
|
const char *p, *q;
|
|
|
|
|
|
|
|
|
|
if (!TRACE_ON())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (p = buffer->buffer; *p; p = q)
|
|
|
|
|
{
|
2020-09-24 18:26:34 -07:00
|
|
|
|
if (!(q = strchr(p, '\n')))
|
2020-07-28 02:52:34 -07:00
|
|
|
|
q = p + strlen(p);
|
|
|
|
|
else
|
|
|
|
|
++q;
|
|
|
|
|
vkd3d_dbg_printf(VKD3D_DBG_LEVEL_TRACE, function, "%.*s", (int)(q - p), p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 02:11:25 -07:00
|
|
|
|
bool vkd3d_shader_message_context_init(struct vkd3d_shader_message_context *context,
|
|
|
|
|
enum vkd3d_shader_log_level log_level, const char *source_name)
|
|
|
|
|
{
|
|
|
|
|
context->log_level = log_level;
|
|
|
|
|
context->source_name = source_name ? source_name : "<anonymous>";
|
|
|
|
|
context->line = 0;
|
|
|
|
|
context->column = 0;
|
|
|
|
|
|
|
|
|
|
return vkd3d_string_buffer_init(&context->messages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vkd3d_shader_message_context_cleanup(struct vkd3d_shader_message_context *context)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_string_buffer_cleanup(&context->messages);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 03:29:57 -07:00
|
|
|
|
void vkd3d_shader_message_context_trace_messages_(const struct vkd3d_shader_message_context *context,
|
2020-07-28 02:52:34 -07:00
|
|
|
|
const char *function)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_string_buffer_trace_(&context->messages, function);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 23:14:01 -07:00
|
|
|
|
bool vkd3d_shader_message_context_copy_messages(struct vkd3d_shader_message_context *context, char **out)
|
2020-07-23 02:11:25 -07:00
|
|
|
|
{
|
|
|
|
|
char *messages;
|
|
|
|
|
|
2020-10-08 23:14:01 -07:00
|
|
|
|
if (!out)
|
|
|
|
|
return true;
|
2020-07-23 02:11:25 -07:00
|
|
|
|
|
2020-10-08 23:14:01 -07:00
|
|
|
|
*out = NULL;
|
|
|
|
|
|
2020-10-08 23:14:02 -07:00
|
|
|
|
if (!context->messages.content_size)
|
|
|
|
|
return true;
|
|
|
|
|
|
2020-10-08 23:14:01 -07:00
|
|
|
|
if (!(messages = vkd3d_malloc(context->messages.content_size + 1)))
|
|
|
|
|
return false;
|
|
|
|
|
memcpy(messages, context->messages.buffer, context->messages.content_size + 1);
|
|
|
|
|
*out = messages;
|
|
|
|
|
return true;
|
2020-07-23 02:11:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 03:13:29 -07:00
|
|
|
|
void vkd3d_shader_verror(struct vkd3d_shader_message_context *context,
|
|
|
|
|
enum vkd3d_shader_error error, const char *format, va_list args)
|
2020-07-23 02:11:25 -07:00
|
|
|
|
{
|
|
|
|
|
if (context->log_level < VKD3D_SHADER_LOG_ERROR)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (context->line)
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s:%u:%u: E%04u: ",
|
|
|
|
|
context->source_name, context->line, context->column, error);
|
|
|
|
|
else
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s: E%04u: ", context->source_name, error);
|
|
|
|
|
vkd3d_string_buffer_vprintf(&context->messages, format, args);
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 03:13:29 -07:00
|
|
|
|
void vkd3d_shader_error(struct vkd3d_shader_message_context *context,
|
|
|
|
|
enum vkd3d_shader_error error, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vkd3d_shader_verror(context, error, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 02:29:27 -08:00
|
|
|
|
static void vkd3d_shader_dump_blob(const char *path, const char *prefix, const void *data, size_t size)
|
|
|
|
|
{
|
|
|
|
|
static int shader_id = 0;
|
|
|
|
|
char filename[1024];
|
|
|
|
|
unsigned int id;
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
|
|
id = InterlockedIncrement(&shader_id) - 1;
|
|
|
|
|
|
|
|
|
|
snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%s-%u.dxbc", path, prefix, id);
|
|
|
|
|
if ((f = fopen(filename, "wb")))
|
|
|
|
|
{
|
|
|
|
|
if (fwrite(data, 1, size, f) != size)
|
|
|
|
|
ERR("Failed to write shader to %s.\n", filename);
|
|
|
|
|
if (fclose(f))
|
|
|
|
|
ERR("Failed to close stream %s.\n", filename);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to open %s for dumping shader.\n", filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_dump_shader(enum vkd3d_shader_type type, const struct vkd3d_shader_code *shader)
|
|
|
|
|
{
|
|
|
|
|
static bool enabled = true;
|
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!(path = getenv("VKD3D_SHADER_DUMP_PATH")))
|
|
|
|
|
{
|
|
|
|
|
enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_dump_blob(path, shader_get_type_prefix(type), shader->code, shader->size);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 03:41:07 -07:00
|
|
|
|
struct vkd3d_shader_parser
|
2017-06-16 13:38:21 -07:00
|
|
|
|
{
|
2017-06-19 09:05:53 -07:00
|
|
|
|
struct vkd3d_shader_desc shader_desc;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
struct vkd3d_shader_version shader_version;
|
|
|
|
|
void *data;
|
2017-06-19 09:05:53 -07:00
|
|
|
|
const DWORD *ptr;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
};
|
2017-06-16 13:38:21 -07:00
|
|
|
|
|
2018-02-15 06:43:52 -08:00
|
|
|
|
static int vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser,
|
2020-07-23 02:11:25 -07:00
|
|
|
|
const struct vkd3d_shader_code *dxbc, struct vkd3d_shader_message_context *message_context)
|
2017-08-21 03:41:07 -07:00
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_desc *shader_desc = &parser->shader_desc;
|
2018-02-15 06:43:52 -08:00
|
|
|
|
int ret;
|
2017-06-19 09:05:53 -07:00
|
|
|
|
|
2020-07-23 02:11:25 -07:00
|
|
|
|
if ((ret = shader_extract_from_dxbc(dxbc->code, dxbc->size, message_context, shader_desc)) < 0)
|
2017-06-19 09:05:53 -07:00
|
|
|
|
{
|
2018-02-15 06:43:52 -08:00
|
|
|
|
WARN("Failed to extract shader, vkd3d result %d.\n", ret);
|
|
|
|
|
return ret;
|
2017-06-19 09:05:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 03:41:07 -07:00
|
|
|
|
if (!(parser->data = shader_sm4_init(shader_desc->byte_code,
|
|
|
|
|
shader_desc->byte_code_size, &shader_desc->output_signature)))
|
2017-06-19 09:05:53 -07:00
|
|
|
|
{
|
2018-01-16 05:02:21 -08:00
|
|
|
|
WARN("Failed to initialize shader parser.\n");
|
2017-08-21 03:41:07 -07:00
|
|
|
|
free_shader_desc(shader_desc);
|
2018-02-15 06:43:52 -08:00
|
|
|
|
return VKD3D_ERROR_INVALID_ARGUMENT;
|
2017-06-19 09:05:53 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 03:41:07 -07:00
|
|
|
|
shader_sm4_read_header(parser->data, &parser->ptr, &parser->shader_version);
|
2018-02-15 06:43:52 -08:00
|
|
|
|
return VKD3D_OK;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_parser_destroy(struct vkd3d_shader_parser *parser)
|
|
|
|
|
{
|
|
|
|
|
shader_sm4_free(parser->data);
|
|
|
|
|
free_shader_desc(&parser->shader_desc);
|
|
|
|
|
}
|
2017-06-19 09:05:53 -07:00
|
|
|
|
|
2020-06-19 04:43:36 -07:00
|
|
|
|
static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_info *compile_info)
|
|
|
|
|
{
|
2020-08-06 01:53:48 -07:00
|
|
|
|
const enum vkd3d_shader_source_type *source_types;
|
2020-08-06 01:53:49 -07:00
|
|
|
|
const enum vkd3d_shader_target_type *target_types;
|
2020-08-06 01:53:48 -07:00
|
|
|
|
unsigned int count, i;
|
|
|
|
|
|
2020-06-19 04:43:36 -07:00
|
|
|
|
if (compile_info->type != VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO)
|
|
|
|
|
{
|
|
|
|
|
WARN("Invalid structure type %#x.\n", compile_info->type);
|
|
|
|
|
return VKD3D_ERROR_INVALID_ARGUMENT;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-06 01:53:48 -07:00
|
|
|
|
source_types = vkd3d_shader_get_supported_source_types(&count);
|
|
|
|
|
for (i = 0; i < count; ++i)
|
2020-06-19 04:43:36 -07:00
|
|
|
|
{
|
2020-08-06 01:53:48 -07:00
|
|
|
|
if (source_types[i] == compile_info->source_type)
|
2020-06-19 04:43:36 -07:00
|
|
|
|
break;
|
2020-08-06 01:53:48 -07:00
|
|
|
|
}
|
|
|
|
|
if (i == count)
|
|
|
|
|
{
|
|
|
|
|
WARN("Invalid shader source type %#x.\n", compile_info->source_type);
|
|
|
|
|
return VKD3D_ERROR_INVALID_ARGUMENT;
|
2020-06-19 04:43:36 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-06 01:53:49 -07:00
|
|
|
|
target_types = vkd3d_shader_get_supported_target_types(compile_info->source_type, &count);
|
|
|
|
|
for (i = 0; i < count; ++i)
|
2020-06-23 02:20:12 -07:00
|
|
|
|
{
|
2020-08-06 01:53:49 -07:00
|
|
|
|
if (target_types[i] == compile_info->target_type)
|
2020-06-23 02:20:12 -07:00
|
|
|
|
break;
|
2020-08-06 01:53:49 -07:00
|
|
|
|
}
|
|
|
|
|
if (i == count)
|
|
|
|
|
{
|
|
|
|
|
WARN("Invalid shader target type %#x.\n", compile_info->target_type);
|
|
|
|
|
return VKD3D_ERROR_INVALID_ARGUMENT;
|
2020-06-23 02:20:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-19 04:43:36 -07:00
|
|
|
|
return VKD3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 02:11:25 -07:00
|
|
|
|
void vkd3d_shader_free_messages(char *messages)
|
|
|
|
|
{
|
2020-09-04 09:01:14 -07:00
|
|
|
|
TRACE("messages %p.\n", messages);
|
|
|
|
|
|
2020-07-23 02:11:25 -07:00
|
|
|
|
vkd3d_free(messages);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:24 -07:00
|
|
|
|
struct vkd3d_shader_scan_context
|
|
|
|
|
{
|
2020-07-30 03:29:55 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
size_t descriptors_size;
|
2020-06-24 23:18:26 -07:00
|
|
|
|
|
2020-09-25 14:52:58 -07:00
|
|
|
|
struct vkd3d_shader_message_context *message_context;
|
2020-07-30 03:29:54 -07:00
|
|
|
|
|
|
|
|
|
struct vkd3d_shader_cf_info
|
|
|
|
|
{
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
VKD3D_SHADER_BLOCK_IF,
|
|
|
|
|
VKD3D_SHADER_BLOCK_LOOP,
|
|
|
|
|
VKD3D_SHADER_BLOCK_SWITCH,
|
|
|
|
|
} type;
|
|
|
|
|
bool inside_block;
|
|
|
|
|
bool has_default;
|
|
|
|
|
} *cf_info;
|
|
|
|
|
size_t cf_info_size;
|
|
|
|
|
size_t cf_info_count;
|
|
|
|
|
|
2020-06-24 23:18:26 -07:00
|
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
unsigned int id;
|
|
|
|
|
unsigned int descriptor_idx;
|
|
|
|
|
} *uav_ranges;
|
|
|
|
|
size_t uav_ranges_size;
|
|
|
|
|
size_t uav_range_count;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
};
|
|
|
|
|
|
2020-09-25 14:52:58 -07:00
|
|
|
|
static void vkd3d_shader_scan_context_init(struct vkd3d_shader_scan_context *context,
|
2020-07-30 03:29:55 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info,
|
2020-09-25 14:52:58 -07:00
|
|
|
|
struct vkd3d_shader_message_context *message_context)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
{
|
|
|
|
|
memset(context, 0, sizeof(*context));
|
2020-07-30 03:29:55 -07:00
|
|
|
|
context->scan_descriptor_info = scan_descriptor_info;
|
2020-09-25 14:52:58 -07:00
|
|
|
|
context->message_context = message_context;
|
2020-07-30 03:29:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_scan_context_cleanup(struct vkd3d_shader_scan_context *context)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_free(context->uav_ranges);
|
|
|
|
|
vkd3d_free(context->cf_info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct vkd3d_shader_cf_info *vkd3d_shader_scan_get_current_cf_info(struct vkd3d_shader_scan_context *context)
|
|
|
|
|
{
|
|
|
|
|
if (!context->cf_info_count)
|
|
|
|
|
return NULL;
|
|
|
|
|
return &context->cf_info[context->cf_info_count - 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct vkd3d_shader_cf_info *vkd3d_shader_scan_push_cf_info(struct vkd3d_shader_scan_context *context)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_cf_info *cf_info;
|
|
|
|
|
|
|
|
|
|
if (!vkd3d_array_reserve((void **)&context->cf_info, &context->cf_info_size,
|
|
|
|
|
context->cf_info_count + 1, sizeof(*context->cf_info)))
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to allocate UAV range.\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cf_info = &context->cf_info[context->cf_info_count++];
|
|
|
|
|
memset(cf_info, 0, sizeof(*cf_info));
|
|
|
|
|
|
|
|
|
|
return cf_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_scan_pop_cf_info(struct vkd3d_shader_scan_context *context)
|
|
|
|
|
{
|
|
|
|
|
assert(context->cf_info_count);
|
|
|
|
|
|
|
|
|
|
--context->cf_info_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct vkd3d_shader_cf_info *vkd3d_shader_scan_find_innermost_breakable_cf_info(
|
|
|
|
|
struct vkd3d_shader_scan_context *context)
|
|
|
|
|
{
|
|
|
|
|
size_t count = context->cf_info_count;
|
|
|
|
|
struct vkd3d_shader_cf_info *cf_info;
|
|
|
|
|
|
|
|
|
|
while (count)
|
|
|
|
|
{
|
|
|
|
|
cf_info = &context->cf_info[--count];
|
|
|
|
|
if (cf_info->type == VKD3D_SHADER_BLOCK_LOOP
|
|
|
|
|
|| cf_info->type == VKD3D_SHADER_BLOCK_SWITCH)
|
|
|
|
|
return cf_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct vkd3d_shader_cf_info *vkd3d_shader_scan_find_innermost_loop_cf_info(
|
|
|
|
|
struct vkd3d_shader_scan_context *context)
|
|
|
|
|
{
|
|
|
|
|
size_t count = context->cf_info_count;
|
|
|
|
|
struct vkd3d_shader_cf_info *cf_info;
|
|
|
|
|
|
|
|
|
|
while (count)
|
|
|
|
|
{
|
|
|
|
|
cf_info = &context->cf_info[--count];
|
|
|
|
|
if (cf_info->type == VKD3D_SHADER_BLOCK_LOOP)
|
|
|
|
|
return cf_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:26 -07:00
|
|
|
|
static struct vkd3d_shader_descriptor_info *vkd3d_shader_scan_get_uav_descriptor_info(
|
|
|
|
|
const struct vkd3d_shader_scan_context *context, unsigned int range_id)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < context->uav_range_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (context->uav_ranges[i].id == range_id)
|
2020-07-30 03:29:55 -07:00
|
|
|
|
return &context->scan_descriptor_info->descriptors[context->uav_ranges[i].descriptor_idx];
|
2020-06-24 23:18:26 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 03:41:07 -07:00
|
|
|
|
static bool vkd3d_shader_instruction_is_uav_read(const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
|
|
|
|
enum VKD3D_SHADER_INSTRUCTION_HANDLER handler_idx = instruction->handler_idx;
|
|
|
|
|
return (VKD3DSIH_ATOMIC_AND <= handler_idx && handler_idx <= VKD3DSIH_ATOMIC_XOR)
|
2017-09-07 08:48:43 -07:00
|
|
|
|
|| (VKD3DSIH_IMM_ATOMIC_ALLOC <= handler_idx && handler_idx <= VKD3DSIH_IMM_ATOMIC_XOR)
|
2017-08-21 03:41:07 -07:00
|
|
|
|
|| handler_idx == VKD3DSIH_LD_UAV_TYPED
|
|
|
|
|
|| (handler_idx == VKD3DSIH_LD_RAW && instruction->src[1].reg.type == VKD3DSPR_UAV)
|
|
|
|
|
|| (handler_idx == VKD3DSIH_LD_STRUCTURED && instruction->src[2].reg.type == VKD3DSPR_UAV);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:27 -07:00
|
|
|
|
static void vkd3d_shader_scan_record_uav_read(struct vkd3d_shader_scan_context *context,
|
2017-08-21 03:41:07 -07:00
|
|
|
|
const struct vkd3d_shader_register *reg)
|
|
|
|
|
{
|
2020-06-24 23:18:27 -07:00
|
|
|
|
struct vkd3d_shader_descriptor_info *d;
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if (!context->scan_descriptor_info)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return;
|
|
|
|
|
|
2020-06-24 23:18:27 -07:00
|
|
|
|
d = vkd3d_shader_scan_get_uav_descriptor_info(context, reg->idx[0].offset);
|
|
|
|
|
d->flags |= VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_READ;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-01 02:27:58 -07:00
|
|
|
|
static bool vkd3d_shader_instruction_is_uav_counter(const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
|
|
|
|
enum VKD3D_SHADER_INSTRUCTION_HANDLER handler_idx = instruction->handler_idx;
|
|
|
|
|
return handler_idx == VKD3DSIH_IMM_ATOMIC_ALLOC
|
|
|
|
|
|| handler_idx == VKD3DSIH_IMM_ATOMIC_CONSUME;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:26 -07:00
|
|
|
|
static void vkd3d_shader_scan_record_uav_counter(struct vkd3d_shader_scan_context *context,
|
2017-09-01 02:27:58 -07:00
|
|
|
|
const struct vkd3d_shader_register *reg)
|
|
|
|
|
{
|
2020-06-24 23:18:26 -07:00
|
|
|
|
struct vkd3d_shader_descriptor_info *d;
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if (!context->scan_descriptor_info)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return;
|
|
|
|
|
|
2020-06-24 23:18:26 -07:00
|
|
|
|
d = vkd3d_shader_scan_get_uav_descriptor_info(context, reg->idx[0].offset);
|
|
|
|
|
d->flags |= VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER;
|
2017-09-01 02:27:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:24 -07:00
|
|
|
|
static bool vkd3d_shader_scan_add_descriptor(struct vkd3d_shader_scan_context *context,
|
2020-06-24 23:18:25 -07:00
|
|
|
|
enum vkd3d_shader_descriptor_type type, unsigned int register_space, unsigned int register_index,
|
2020-06-24 23:18:28 -07:00
|
|
|
|
enum vkd3d_shader_resource_type resource_type, enum vkd3d_shader_resource_data_type resource_data_type,
|
|
|
|
|
unsigned int flags)
|
2020-06-24 23:18:24 -07:00
|
|
|
|
{
|
2020-07-30 03:29:55 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info *info = context->scan_descriptor_info;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
struct vkd3d_shader_descriptor_info *d;
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if (!vkd3d_array_reserve((void **)&info->descriptors, &context->descriptors_size,
|
|
|
|
|
info->descriptor_count + 1, sizeof(*info->descriptors)))
|
2020-06-24 23:18:24 -07:00
|
|
|
|
{
|
|
|
|
|
ERR("Failed to allocate descriptor info.\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
d = &info->descriptors[info->descriptor_count];
|
2020-06-24 23:18:24 -07:00
|
|
|
|
d->type = type;
|
|
|
|
|
d->register_space = register_space;
|
|
|
|
|
d->register_index = register_index;
|
2020-06-24 23:18:25 -07:00
|
|
|
|
d->resource_type = resource_type;
|
|
|
|
|
d->resource_data_type = resource_data_type;
|
2020-06-24 23:18:28 -07:00
|
|
|
|
d->flags = flags;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
d->count = 1;
|
2020-07-30 03:29:55 -07:00
|
|
|
|
++info->descriptor_count;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:26 -07:00
|
|
|
|
static bool vkd3d_shader_scan_add_uav_range(struct vkd3d_shader_scan_context *context,
|
|
|
|
|
unsigned int id, unsigned int descriptor_idx)
|
|
|
|
|
{
|
|
|
|
|
if (!vkd3d_array_reserve((void **)&context->uav_ranges, &context->uav_ranges_size,
|
|
|
|
|
context->uav_range_count + 1, sizeof(*context->uav_ranges)))
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to allocate UAV range.\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context->uav_ranges[context->uav_range_count].id = id;
|
|
|
|
|
context->uav_ranges[context->uav_range_count].descriptor_idx = descriptor_idx;
|
|
|
|
|
++context->uav_range_count;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:24 -07:00
|
|
|
|
static void vkd3d_shader_scan_constant_buffer_declaration(struct vkd3d_shader_scan_context *context,
|
|
|
|
|
const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
|
|
|
|
const struct vkd3d_shader_constant_buffer *cb = &instruction->declaration.cb;
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if (!context->scan_descriptor_info)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return;
|
|
|
|
|
|
2020-06-24 23:18:25 -07:00
|
|
|
|
vkd3d_shader_scan_add_descriptor(context, VKD3D_SHADER_DESCRIPTOR_TYPE_CBV, cb->register_space,
|
2020-06-24 23:18:28 -07:00
|
|
|
|
cb->register_index, VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT, 0);
|
2020-06-24 23:18:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_scan_sampler_declaration(struct vkd3d_shader_scan_context *context,
|
2018-10-21 16:49:15 -07:00
|
|
|
|
const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
2020-06-24 23:18:24 -07:00
|
|
|
|
const struct vkd3d_shader_sampler *sampler = &instruction->declaration.sampler;
|
2020-06-24 23:18:28 -07:00
|
|
|
|
unsigned int flags;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if (!context->scan_descriptor_info)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return;
|
|
|
|
|
|
2018-10-21 16:49:15 -07:00
|
|
|
|
if (instruction->flags & VKD3DSI_SAMPLER_COMPARISON_MODE)
|
2020-06-24 23:18:28 -07:00
|
|
|
|
flags = VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_SAMPLER_COMPARISON_MODE;
|
|
|
|
|
else
|
|
|
|
|
flags = 0;
|
2020-06-24 23:18:25 -07:00
|
|
|
|
vkd3d_shader_scan_add_descriptor(context, VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, sampler->register_space,
|
2020-06-24 23:18:28 -07:00
|
|
|
|
sampler->register_index, VKD3D_SHADER_RESOURCE_NONE, VKD3D_SHADER_RESOURCE_DATA_UINT, flags);
|
2020-06-24 23:18:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_scan_resource_declaration(struct vkd3d_shader_scan_context *context,
|
2020-06-30 03:32:03 -07:00
|
|
|
|
const struct vkd3d_shader_resource *resource, enum vkd3d_shader_resource_type resource_type,
|
|
|
|
|
enum vkd3d_shader_resource_data_type resource_data_type)
|
2020-06-24 23:18:24 -07:00
|
|
|
|
{
|
|
|
|
|
enum vkd3d_shader_descriptor_type type;
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if (!context->scan_descriptor_info)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return;
|
|
|
|
|
|
2020-06-30 03:32:03 -07:00
|
|
|
|
if (resource->reg.reg.type == VKD3DSPR_UAV)
|
2020-06-24 23:18:24 -07:00
|
|
|
|
type = VKD3D_SHADER_DESCRIPTOR_TYPE_UAV;
|
|
|
|
|
else
|
|
|
|
|
type = VKD3D_SHADER_DESCRIPTOR_TYPE_SRV;
|
2020-06-30 03:32:03 -07:00
|
|
|
|
vkd3d_shader_scan_add_descriptor(context, type, resource->register_space,
|
|
|
|
|
resource->register_index, resource_type, resource_data_type, 0);
|
|
|
|
|
if (type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV)
|
|
|
|
|
vkd3d_shader_scan_add_uav_range(context, resource->reg.reg.idx[0].offset,
|
2020-07-30 03:29:55 -07:00
|
|
|
|
context->scan_descriptor_info->descriptor_count - 1);
|
2020-06-30 03:32:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_scan_typed_resource_declaration(struct vkd3d_shader_scan_context *context,
|
|
|
|
|
const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
|
|
|
|
const struct vkd3d_shader_semantic *semantic = &instruction->declaration.semantic;
|
|
|
|
|
enum vkd3d_shader_resource_data_type resource_data_type;
|
|
|
|
|
|
2020-09-25 17:05:37 -07:00
|
|
|
|
if (semantic->resource_data_type[0] != semantic->resource_data_type[1] ||
|
|
|
|
|
semantic->resource_data_type[0] != semantic->resource_data_type[2] ||
|
|
|
|
|
semantic->resource_data_type[0] != semantic->resource_data_type[3])
|
|
|
|
|
FIXME("Resource data types are different (%d, %d, %d, %d).\n",
|
|
|
|
|
semantic->resource_data_type[0],
|
|
|
|
|
semantic->resource_data_type[1],
|
|
|
|
|
semantic->resource_data_type[2],
|
|
|
|
|
semantic->resource_data_type[3]);
|
|
|
|
|
|
|
|
|
|
switch (semantic->resource_data_type[0])
|
2020-06-24 23:18:25 -07:00
|
|
|
|
{
|
|
|
|
|
case VKD3D_DATA_UNORM:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_UNORM;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3D_DATA_SNORM:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_SNORM;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3D_DATA_INT:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_INT;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3D_DATA_UINT:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_UINT;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3D_DATA_FLOAT:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_FLOAT;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-09-25 17:05:37 -07:00
|
|
|
|
ERR("Invalid resource data type %#x.\n", semantic->resource_data_type[0]);
|
2020-06-24 23:18:25 -07:00
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_FLOAT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-06-30 03:32:03 -07:00
|
|
|
|
vkd3d_shader_scan_resource_declaration(context, &semantic->resource,
|
|
|
|
|
semantic->resource_type, resource_data_type);
|
2020-06-24 23:18:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 03:29:54 -07:00
|
|
|
|
static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *context,
|
2017-08-21 03:41:07 -07:00
|
|
|
|
const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
2020-07-30 03:29:54 -07:00
|
|
|
|
struct vkd3d_shader_cf_info *cf_info;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
2019-02-07 00:59:18 -08:00
|
|
|
|
switch (instruction->handler_idx)
|
|
|
|
|
{
|
2020-06-24 23:18:24 -07:00
|
|
|
|
case VKD3DSIH_DCL_CONSTANT_BUFFER:
|
|
|
|
|
vkd3d_shader_scan_constant_buffer_declaration(context, instruction);
|
|
|
|
|
break;
|
2019-02-07 00:59:18 -08:00
|
|
|
|
case VKD3DSIH_DCL_SAMPLER:
|
2020-06-24 23:18:24 -07:00
|
|
|
|
vkd3d_shader_scan_sampler_declaration(context, instruction);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_DCL:
|
|
|
|
|
case VKD3DSIH_DCL_UAV_TYPED:
|
2020-06-30 03:32:03 -07:00
|
|
|
|
vkd3d_shader_scan_typed_resource_declaration(context, instruction);
|
2020-06-24 23:18:24 -07:00
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_DCL_RESOURCE_RAW:
|
|
|
|
|
case VKD3DSIH_DCL_UAV_RAW:
|
2020-06-30 03:32:03 -07:00
|
|
|
|
vkd3d_shader_scan_resource_declaration(context, &instruction->declaration.raw_resource.resource,
|
|
|
|
|
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT);
|
2020-06-24 23:18:24 -07:00
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_DCL_RESOURCE_STRUCTURED:
|
|
|
|
|
case VKD3DSIH_DCL_UAV_STRUCTURED:
|
2020-06-30 03:32:03 -07:00
|
|
|
|
vkd3d_shader_scan_resource_declaration(context, &instruction->declaration.structured_resource.resource,
|
|
|
|
|
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT);
|
2019-02-07 00:59:18 -08:00
|
|
|
|
break;
|
2020-07-30 03:29:54 -07:00
|
|
|
|
case VKD3DSIH_IF:
|
|
|
|
|
cf_info = vkd3d_shader_scan_push_cf_info(context);
|
|
|
|
|
cf_info->type = VKD3D_SHADER_BLOCK_IF;
|
|
|
|
|
cf_info->inside_block = true;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_ELSE:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_IF)
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘else’ instruction without corresponding ‘if’ block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
cf_info->inside_block = true;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_ENDIF:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_IF)
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘endif’ instruction without corresponding ‘if’ block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
vkd3d_shader_scan_pop_cf_info(context);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_LOOP:
|
|
|
|
|
cf_info = vkd3d_shader_scan_push_cf_info(context);
|
|
|
|
|
cf_info->type = VKD3D_SHADER_BLOCK_LOOP;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_ENDLOOP:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_LOOP)
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘endloop’ instruction without corresponding ‘loop’ block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
vkd3d_shader_scan_pop_cf_info(context);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_SWITCH:
|
|
|
|
|
cf_info = vkd3d_shader_scan_push_cf_info(context);
|
|
|
|
|
cf_info->type = VKD3D_SHADER_BLOCK_SWITCH;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_ENDSWITCH:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context))
|
|
|
|
|
|| cf_info->type != VKD3D_SHADER_BLOCK_SWITCH || cf_info->inside_block)
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘endswitch’ instruction without corresponding ‘switch’ block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
vkd3d_shader_scan_pop_cf_info(context);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_CASE:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context))
|
|
|
|
|
|| cf_info->type != VKD3D_SHADER_BLOCK_SWITCH)
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘case’ instruction outside switch block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
cf_info->inside_block = true;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_DEFAULT:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context))
|
|
|
|
|
|| cf_info->type != VKD3D_SHADER_BLOCK_SWITCH)
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘default’ instruction outside switch block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
if (cf_info->has_default)
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered duplicate ‘default’ instruction inside the current switch block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
cf_info->inside_block = true;
|
|
|
|
|
cf_info->has_default = true;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_BREAK:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_find_innermost_breakable_cf_info(context)))
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘break’ instruction outside breakable block.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
cf_info->inside_block = false;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_BREAKP:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_find_innermost_loop_cf_info(context)))
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘breakp’ instruction outside loop.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_CONTINUE:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_find_innermost_loop_cf_info(context)))
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘continue’ instruction outside loop.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
cf_info->inside_block = false;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_CONTINUEP:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_find_innermost_loop_cf_info(context)))
|
|
|
|
|
{
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_error(context->message_context, VKD3D_SHADER_ERROR_TPF_MISMATCHED_CF,
|
2020-07-30 03:29:54 -07:00
|
|
|
|
"Encountered ‘continue’ instruction outside loop.");
|
|
|
|
|
return VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_RET:
|
|
|
|
|
if (context->cf_info_count)
|
|
|
|
|
context->cf_info[context->cf_info_count - 1].inside_block = false;
|
|
|
|
|
break;
|
2019-02-07 00:59:18 -08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-10-21 16:49:15 -07:00
|
|
|
|
|
2017-08-21 03:41:07 -07:00
|
|
|
|
if (vkd3d_shader_instruction_is_uav_read(instruction))
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < instruction->dst_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (instruction->dst[i].reg.type == VKD3DSPR_UAV)
|
2020-06-24 23:18:27 -07:00
|
|
|
|
vkd3d_shader_scan_record_uav_read(context, &instruction->dst[i].reg);
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < instruction->src_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (instruction->src[i].reg.type == VKD3DSPR_UAV)
|
2020-06-24 23:18:27 -07:00
|
|
|
|
vkd3d_shader_scan_record_uav_read(context, &instruction->src[i].reg);
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-01 02:27:58 -07:00
|
|
|
|
|
|
|
|
|
if (vkd3d_shader_instruction_is_uav_counter(instruction))
|
2020-06-24 23:18:26 -07:00
|
|
|
|
vkd3d_shader_scan_record_uav_counter(context, &instruction->src[0].reg);
|
2020-07-30 03:29:54 -07:00
|
|
|
|
|
|
|
|
|
return VKD3D_OK;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:52:58 -07:00
|
|
|
|
static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_message_context *message_context)
|
2017-08-21 03:41:07 -07:00
|
|
|
|
{
|
2020-07-30 03:29:55 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
struct vkd3d_shader_instruction instruction;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
struct vkd3d_shader_scan_context context;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
struct vkd3d_shader_parser parser;
|
2018-02-15 06:43:52 -08:00
|
|
|
|
int ret;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if ((scan_descriptor_info = vkd3d_find_struct(compile_info->next, SCAN_DESCRIPTOR_INFO)))
|
|
|
|
|
{
|
|
|
|
|
scan_descriptor_info->descriptors = NULL;
|
|
|
|
|
scan_descriptor_info->descriptor_count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:52:58 -07:00
|
|
|
|
vkd3d_shader_scan_context_init(&context, scan_descriptor_info, message_context);
|
2020-07-30 03:29:54 -07:00
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
if ((ret = vkd3d_shader_parser_init(&parser, &compile_info->source, message_context)) < 0)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
{
|
|
|
|
|
vkd3d_shader_scan_context_cleanup(&context);
|
2018-02-15 06:43:52 -08:00
|
|
|
|
return ret;
|
2020-07-30 03:29:54 -07:00
|
|
|
|
}
|
2017-08-21 03:41:07 -07:00
|
|
|
|
|
2020-07-28 02:52:33 -07:00
|
|
|
|
if (TRACE_ON())
|
|
|
|
|
vkd3d_shader_trace(parser.data);
|
|
|
|
|
|
2020-07-30 03:29:54 -07:00
|
|
|
|
message_context->line = 2; /* Line 1 is the version token. */
|
|
|
|
|
message_context->column = 1;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
while (!shader_sm4_is_end(parser.data, &parser.ptr))
|
|
|
|
|
{
|
|
|
|
|
shader_sm4_read_instruction(parser.data, &parser.ptr, &instruction);
|
|
|
|
|
|
2019-02-20 04:42:48 -08:00
|
|
|
|
if (instruction.handler_idx == VKD3DSIH_INVALID)
|
2017-08-21 03:41:07 -07:00
|
|
|
|
{
|
|
|
|
|
WARN("Encountered unrecognized or invalid instruction.\n");
|
2020-08-25 08:22:28 -07:00
|
|
|
|
if (scan_descriptor_info)
|
|
|
|
|
vkd3d_shader_free_scan_descriptor_info(scan_descriptor_info);
|
2020-07-30 03:29:54 -07:00
|
|
|
|
ret = VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
goto done;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 03:29:54 -07:00
|
|
|
|
if ((ret = vkd3d_shader_scan_instruction(&context, &instruction)) < 0)
|
|
|
|
|
{
|
2020-08-25 08:22:28 -07:00
|
|
|
|
if (scan_descriptor_info)
|
|
|
|
|
vkd3d_shader_free_scan_descriptor_info(scan_descriptor_info);
|
2020-07-30 03:29:54 -07:00
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
++message_context->line;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 03:29:54 -07:00
|
|
|
|
ret = VKD3D_OK;
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
vkd3d_shader_scan_context_cleanup(&context);
|
2017-08-21 03:41:07 -07:00
|
|
|
|
vkd3d_shader_parser_destroy(&parser);
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return ret;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:52:58 -07:00
|
|
|
|
int vkd3d_shader_scan(const struct vkd3d_shader_compile_info *compile_info, char **messages)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_message_context message_context;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
TRACE("compile_info %p, messages %p.\n", compile_info, messages);
|
|
|
|
|
|
|
|
|
|
if (messages)
|
|
|
|
|
*messages = NULL;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_validate_compile_info(compile_info)) < 0)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
if (!vkd3d_shader_message_context_init(&message_context, compile_info->log_level, compile_info->source_name))
|
|
|
|
|
return VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
ret = scan_dxbc(compile_info, &message_context);
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_message_context_trace_messages(&message_context);
|
2020-10-08 23:14:01 -07:00
|
|
|
|
if (!vkd3d_shader_message_context_copy_messages(&message_context, messages))
|
2020-09-25 14:52:58 -07:00
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
vkd3d_shader_message_context_cleanup(&message_context);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
static int compile_dxbc_tpf(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
|
2020-09-25 14:52:59 -07:00
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_scan_descriptor_info scan_descriptor_info;
|
|
|
|
|
struct vkd3d_shader_instruction instruction;
|
|
|
|
|
struct vkd3d_shader_compile_info scan_info;
|
|
|
|
|
struct vkd3d_dxbc_compiler *spirv_compiler;
|
|
|
|
|
struct vkd3d_shader_parser parser;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
scan_info = *compile_info;
|
|
|
|
|
scan_descriptor_info.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_DESCRIPTOR_INFO;
|
|
|
|
|
scan_descriptor_info.next = scan_info.next;
|
|
|
|
|
scan_info.next = &scan_descriptor_info;
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
if ((ret = scan_dxbc(&scan_info, message_context)) < 0)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_parser_init(&parser, &compile_info->source, message_context)) < 0)
|
2020-09-25 14:52:59 -07:00
|
|
|
|
{
|
2020-09-25 14:53:00 -07:00
|
|
|
|
vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info);
|
2020-09-25 14:52:59 -07:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_dump_shader(parser.shader_version.type, &compile_info->source);
|
|
|
|
|
|
|
|
|
|
if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM)
|
|
|
|
|
{
|
2020-09-25 14:53:00 -07:00
|
|
|
|
vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info);
|
2020-09-25 14:52:59 -07:00
|
|
|
|
ret = vkd3d_dxbc_binary_to_text(parser.data, out);
|
|
|
|
|
vkd3d_shader_parser_destroy(&parser);
|
2020-09-25 14:53:00 -07:00
|
|
|
|
return ret;
|
2020-09-25 14:52:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(spirv_compiler = vkd3d_dxbc_compiler_create(&parser.shader_version,
|
2020-09-25 14:53:00 -07:00
|
|
|
|
&parser.shader_desc, compile_info, &scan_descriptor_info, message_context)))
|
2020-09-25 14:52:59 -07:00
|
|
|
|
{
|
|
|
|
|
ERR("Failed to create DXBC compiler.\n");
|
|
|
|
|
vkd3d_shader_parser_destroy(&parser);
|
2020-09-25 14:53:00 -07:00
|
|
|
|
vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info);
|
|
|
|
|
return VKD3D_ERROR;
|
2020-09-25 14:52:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
message_context->line = 2; /* Line 1 is the version token. */
|
|
|
|
|
message_context->column = 1;
|
2020-09-25 14:52:59 -07:00
|
|
|
|
while (!shader_sm4_is_end(parser.data, &parser.ptr))
|
|
|
|
|
{
|
|
|
|
|
shader_sm4_read_instruction(parser.data, &parser.ptr, &instruction);
|
|
|
|
|
|
|
|
|
|
if (instruction.handler_idx == VKD3DSIH_INVALID)
|
|
|
|
|
{
|
|
|
|
|
WARN("Encountered unrecognized or invalid instruction.\n");
|
|
|
|
|
ret = VKD3D_ERROR_INVALID_SHADER;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_dxbc_compiler_handle_instruction(spirv_compiler, &instruction)) < 0)
|
|
|
|
|
break;
|
2020-09-25 14:53:00 -07:00
|
|
|
|
++message_context->line;
|
2020-09-25 14:52:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret >= 0)
|
|
|
|
|
ret = vkd3d_dxbc_compiler_generate_spirv(spirv_compiler, compile_info, out);
|
|
|
|
|
|
|
|
|
|
vkd3d_dxbc_compiler_destroy(spirv_compiler);
|
|
|
|
|
vkd3d_shader_parser_destroy(&parser);
|
2020-09-25 14:53:00 -07:00
|
|
|
|
vkd3d_shader_free_scan_descriptor_info(&scan_descriptor_info);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int compile_hlsl(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
|
|
|
|
|
{
|
|
|
|
|
return VKD3D_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_code *out, char **messages)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_message_context message_context;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
TRACE("compile_info %p, out %p, messages %p.\n", compile_info, out, messages);
|
|
|
|
|
|
|
|
|
|
if (messages)
|
|
|
|
|
*messages = NULL;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_validate_compile_info(compile_info)) < 0)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
if (!vkd3d_shader_message_context_init(&message_context, compile_info->log_level, compile_info->source_name))
|
|
|
|
|
return VKD3D_ERROR;
|
|
|
|
|
|
|
|
|
|
switch (compile_info->source_type)
|
|
|
|
|
{
|
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_TPF:
|
|
|
|
|
ret = compile_dxbc_tpf(compile_info, out, &message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VKD3D_SHADER_SOURCE_HLSL:
|
|
|
|
|
ret = compile_hlsl(compile_info, out, &message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:52:59 -07:00
|
|
|
|
vkd3d_shader_message_context_trace_messages(&message_context);
|
2020-10-08 23:14:01 -07:00
|
|
|
|
if (!vkd3d_shader_message_context_copy_messages(&message_context, messages))
|
2020-09-25 14:52:59 -07:00
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
vkd3d_shader_message_context_cleanup(&message_context);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
void vkd3d_shader_free_scan_descriptor_info(struct vkd3d_shader_scan_descriptor_info *scan_descriptor_info)
|
2020-06-24 23:18:24 -07:00
|
|
|
|
{
|
2020-09-04 09:01:14 -07:00
|
|
|
|
TRACE("scan_descriptor_info %p.\n", scan_descriptor_info);
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
vkd3d_free(scan_descriptor_info->descriptors);
|
2020-06-24 23:18:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-16 13:38:21 -07:00
|
|
|
|
void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *shader_code)
|
|
|
|
|
{
|
2020-09-04 09:01:14 -07:00
|
|
|
|
TRACE("shader_code %p.\n", shader_code);
|
|
|
|
|
|
2017-06-16 13:38:21 -07:00
|
|
|
|
vkd3d_free((void *)shader_code->code);
|
|
|
|
|
}
|
2017-06-27 04:16:47 -07:00
|
|
|
|
|
2020-07-21 03:50:03 -07:00
|
|
|
|
static void vkd3d_shader_free_root_signature_v_1_0(struct vkd3d_shader_root_signature_desc *root_signature)
|
2017-06-27 04:16:47 -07:00
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
2018-02-15 06:43:51 -08:00
|
|
|
|
for (i = 0; i < root_signature->parameter_count; ++i)
|
2017-06-27 04:16:47 -07:00
|
|
|
|
{
|
2020-07-17 02:44:25 -07:00
|
|
|
|
const struct vkd3d_shader_root_parameter *parameter = &root_signature->parameters[i];
|
2017-06-27 04:16:47 -07:00
|
|
|
|
|
2020-07-14 04:22:55 -07:00
|
|
|
|
if (parameter->parameter_type == VKD3D_SHADER_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE)
|
2018-02-15 06:43:51 -08:00
|
|
|
|
vkd3d_free((void *)parameter->u.descriptor_table.descriptor_ranges);
|
2017-06-27 04:16:47 -07:00
|
|
|
|
}
|
2018-02-15 06:43:51 -08:00
|
|
|
|
vkd3d_free((void *)root_signature->parameters);
|
|
|
|
|
vkd3d_free((void *)root_signature->static_samplers);
|
2017-06-27 04:16:47 -07:00
|
|
|
|
|
|
|
|
|
memset(root_signature, 0, sizeof(*root_signature));
|
|
|
|
|
}
|
2017-09-11 13:35:16 -07:00
|
|
|
|
|
2020-07-22 04:24:11 -07:00
|
|
|
|
static void vkd3d_shader_free_root_signature_v_1_1(struct vkd3d_shader_root_signature_desc1 *root_signature)
|
2019-04-19 02:07:31 -07:00
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < root_signature->parameter_count; ++i)
|
|
|
|
|
{
|
2020-07-21 03:50:01 -07:00
|
|
|
|
const struct vkd3d_shader_root_parameter1 *parameter = &root_signature->parameters[i];
|
2019-04-19 02:07:31 -07:00
|
|
|
|
|
2020-07-14 04:22:55 -07:00
|
|
|
|
if (parameter->parameter_type == VKD3D_SHADER_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE)
|
2019-04-19 02:07:31 -07:00
|
|
|
|
vkd3d_free((void *)parameter->u.descriptor_table.descriptor_ranges);
|
|
|
|
|
}
|
|
|
|
|
vkd3d_free((void *)root_signature->parameters);
|
|
|
|
|
vkd3d_free((void *)root_signature->static_samplers);
|
|
|
|
|
|
|
|
|
|
memset(root_signature, 0, sizeof(*root_signature));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 04:24:12 -07:00
|
|
|
|
void vkd3d_shader_free_root_signature(struct vkd3d_shader_versioned_root_signature_desc *desc)
|
2019-04-24 07:05:48 -07:00
|
|
|
|
{
|
2020-09-04 09:01:14 -07:00
|
|
|
|
TRACE("desc %p.\n", desc);
|
|
|
|
|
|
2020-07-21 03:50:02 -07:00
|
|
|
|
if (desc->version == VKD3D_SHADER_ROOT_SIGNATURE_VERSION_1_0)
|
2019-04-24 07:05:48 -07:00
|
|
|
|
{
|
|
|
|
|
vkd3d_shader_free_root_signature_v_1_0(&desc->u.v_1_0);
|
|
|
|
|
}
|
2020-07-21 03:50:02 -07:00
|
|
|
|
else if (desc->version == VKD3D_SHADER_ROOT_SIGNATURE_VERSION_1_1)
|
2019-04-24 07:05:48 -07:00
|
|
|
|
{
|
|
|
|
|
vkd3d_shader_free_root_signature_v_1_1(&desc->u.v_1_1);
|
|
|
|
|
}
|
|
|
|
|
else if (desc->version)
|
|
|
|
|
{
|
|
|
|
|
FIXME("Unknown version %#x.\n", desc->version);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
desc->version = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 06:43:52 -08:00
|
|
|
|
int vkd3d_shader_parse_input_signature(const struct vkd3d_shader_code *dxbc,
|
2020-07-30 03:29:56 -07:00
|
|
|
|
struct vkd3d_shader_signature *signature, char **messages)
|
2017-09-11 13:35:16 -07:00
|
|
|
|
{
|
2020-07-30 03:29:56 -07:00
|
|
|
|
struct vkd3d_shader_message_context message_context;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
TRACE("dxbc {%p, %zu}, signature %p, messages %p.\n", dxbc->code, dxbc->size, signature, messages);
|
|
|
|
|
|
|
|
|
|
if (messages)
|
|
|
|
|
*messages = NULL;
|
|
|
|
|
if (!vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_INFO, NULL))
|
|
|
|
|
return VKD3D_ERROR;
|
2017-09-11 13:35:16 -07:00
|
|
|
|
|
2020-07-30 03:29:56 -07:00
|
|
|
|
ret = shader_parse_input_signature(dxbc->code, dxbc->size, &message_context, signature);
|
|
|
|
|
vkd3d_shader_message_context_trace_messages(&message_context);
|
2020-10-08 23:14:01 -07:00
|
|
|
|
if (!vkd3d_shader_message_context_copy_messages(&message_context, messages))
|
2020-07-30 03:29:56 -07:00
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_message_context_cleanup(&message_context);
|
|
|
|
|
|
|
|
|
|
return ret;
|
2017-09-11 13:35:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct vkd3d_shader_signature_element *vkd3d_shader_find_signature_element(
|
|
|
|
|
const struct vkd3d_shader_signature *signature, const char *semantic_name,
|
|
|
|
|
unsigned int semantic_index, unsigned int stream_index)
|
|
|
|
|
{
|
2018-04-13 03:37:38 -07:00
|
|
|
|
struct vkd3d_shader_signature_element *e;
|
2017-09-11 13:35:16 -07:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
TRACE("signature %p, semantic_name %s, semantic_index %u, stream_index %u.\n",
|
|
|
|
|
signature, debugstr_a(semantic_name), semantic_index, stream_index);
|
|
|
|
|
|
|
|
|
|
e = signature->elements;
|
|
|
|
|
for (i = 0; i < signature->element_count; ++i)
|
|
|
|
|
{
|
2019-04-30 05:33:48 -07:00
|
|
|
|
if (!ascii_strcasecmp(e[i].semantic_name, semantic_name)
|
2017-09-11 13:35:16 -07:00
|
|
|
|
&& e[i].semantic_index == semantic_index
|
|
|
|
|
&& e[i].stream_index == stream_index)
|
|
|
|
|
return &e[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vkd3d_shader_free_shader_signature(struct vkd3d_shader_signature *signature)
|
|
|
|
|
{
|
|
|
|
|
TRACE("signature %p.\n", signature);
|
|
|
|
|
|
|
|
|
|
vkd3d_free(signature->elements);
|
|
|
|
|
signature->elements = NULL;
|
|
|
|
|
}
|
2020-08-06 01:53:45 -07:00
|
|
|
|
|
|
|
|
|
const char *vkd3d_shader_get_version(unsigned int *major, unsigned int *minor)
|
|
|
|
|
{
|
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
|
|
TRACE("major %p, minor %p.\n", major, minor);
|
|
|
|
|
|
|
|
|
|
if (major || minor)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_parse_version(PACKAGE_VERSION, &x, &y);
|
|
|
|
|
if (major)
|
|
|
|
|
*major = x;
|
|
|
|
|
if (minor)
|
|
|
|
|
*minor = y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "vkd3d-shader " PACKAGE_VERSION VKD3D_VCS_ID;
|
|
|
|
|
}
|
2020-08-06 01:53:48 -07:00
|
|
|
|
|
|
|
|
|
const enum vkd3d_shader_source_type *vkd3d_shader_get_supported_source_types(unsigned int *count)
|
|
|
|
|
{
|
|
|
|
|
static const enum vkd3d_shader_source_type types[] =
|
|
|
|
|
{
|
|
|
|
|
VKD3D_SHADER_SOURCE_DXBC_TPF,
|
2020-09-25 14:53:00 -07:00
|
|
|
|
VKD3D_SHADER_SOURCE_HLSL,
|
2020-08-06 01:53:48 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TRACE("count %p.\n", count);
|
|
|
|
|
|
|
|
|
|
*count = ARRAY_SIZE(types);
|
|
|
|
|
return types;
|
|
|
|
|
}
|
2020-08-06 01:53:49 -07:00
|
|
|
|
|
|
|
|
|
const enum vkd3d_shader_target_type *vkd3d_shader_get_supported_target_types(
|
|
|
|
|
enum vkd3d_shader_source_type source_type, unsigned int *count)
|
|
|
|
|
{
|
|
|
|
|
static const enum vkd3d_shader_target_type dxbc_tpf_types[] =
|
|
|
|
|
{
|
|
|
|
|
VKD3D_SHADER_TARGET_SPIRV_BINARY,
|
2020-09-07 04:35:41 -07:00
|
|
|
|
#ifdef HAVE_SPIRV_TOOLS
|
|
|
|
|
VKD3D_SHADER_TARGET_SPIRV_TEXT,
|
|
|
|
|
#endif
|
2020-09-24 18:26:38 -07:00
|
|
|
|
VKD3D_SHADER_TARGET_D3D_ASM,
|
2020-08-06 01:53:49 -07:00
|
|
|
|
};
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
static const enum vkd3d_shader_target_type hlsl_types[] =
|
|
|
|
|
{
|
|
|
|
|
VKD3D_SHADER_TARGET_DXBC_TPF,
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-06 01:53:49 -07:00
|
|
|
|
TRACE("source_type %#x, count %p.\n", source_type, count);
|
|
|
|
|
|
|
|
|
|
switch (source_type)
|
|
|
|
|
{
|
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_TPF:
|
|
|
|
|
*count = ARRAY_SIZE(dxbc_tpf_types);
|
|
|
|
|
return dxbc_tpf_types;
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
case VKD3D_SHADER_SOURCE_HLSL:
|
|
|
|
|
*count = ARRAY_SIZE(hlsl_types);
|
|
|
|
|
return hlsl_types;
|
|
|
|
|
|
2020-08-06 01:53:49 -07:00
|
|
|
|
default:
|
|
|
|
|
*count = 0;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-25 14:53:01 -07:00
|
|
|
|
|
|
|
|
|
int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_code *out, char **messages)
|
|
|
|
|
{
|
|
|
|
|
TRACE("compile_info %p, out %p, messages %p.\n", compile_info, out, messages);
|
|
|
|
|
|
|
|
|
|
return VKD3D_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
}
|