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"
|
2023-10-21 12:35:08 -07:00
|
|
|
|
#include "hlsl.h"
|
2017-06-16 13:38:21 -07:00
|
|
|
|
|
2019-01-31 02:29:27 -08:00
|
|
|
|
#include <stdio.h>
|
2022-03-01 04:21:33 -08:00
|
|
|
|
#include <math.h>
|
2019-01-31 02:29:27 -08:00
|
|
|
|
|
2019-01-31 02:29:29 -08:00
|
|
|
|
VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG");
|
2019-01-31 02:29:28 -08:00
|
|
|
|
|
2022-05-11 07:39:08 -07:00
|
|
|
|
static inline int char_to_int(char c)
|
|
|
|
|
{
|
|
|
|
|
if ('0' <= c && c <= '9')
|
|
|
|
|
return c - '0';
|
|
|
|
|
if ('A' <= c && c <= 'F')
|
|
|
|
|
return c - 'A' + 10;
|
|
|
|
|
if ('a' <= c && c <= 'f')
|
|
|
|
|
return c - 'a' + 10;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t vkd3d_parse_integer(const char *s)
|
|
|
|
|
{
|
|
|
|
|
uint32_t base = 10, ret = 0;
|
|
|
|
|
int digit;
|
|
|
|
|
|
|
|
|
|
if (*s == '0')
|
|
|
|
|
{
|
|
|
|
|
base = 8;
|
|
|
|
|
++s;
|
|
|
|
|
if (*s == 'x' || *s == 'X')
|
|
|
|
|
{
|
|
|
|
|
base = 16;
|
|
|
|
|
++s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((digit = char_to_int(*s++)) >= 0)
|
|
|
|
|
ret = ret * base + (uint32_t)digit;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 23:14:03 -07:00
|
|
|
|
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer)
|
2020-07-23 02:11:25 -07:00
|
|
|
|
{
|
2021-09-30 12:36:17 -07:00
|
|
|
|
buffer->buffer_size = 16;
|
|
|
|
|
buffer->content_size = 0;
|
|
|
|
|
buffer->buffer = vkd3d_malloc(buffer->buffer_size);
|
|
|
|
|
assert(buffer->buffer);
|
|
|
|
|
memset(buffer->buffer, 0, buffer->buffer_size);
|
2020-07-23 02:11:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_free(buffer->buffer);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 16:03:09 -08:00
|
|
|
|
static void vkd3d_string_buffer_clear(struct vkd3d_string_buffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
buffer->buffer[0] = '\0';
|
|
|
|
|
buffer->content_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 02:11:25 -07:00
|
|
|
|
static bool vkd3d_string_buffer_resize(struct vkd3d_string_buffer *buffer, int rc)
|
|
|
|
|
{
|
2021-09-30 12:36:17 -07:00
|
|
|
|
unsigned int new_buffer_size = rc >= 0 ? buffer->content_size + rc + 1 : buffer->buffer_size * 2;
|
2020-07-23 02:11:25 -07:00
|
|
|
|
|
2021-09-30 12:36:16 -07:00
|
|
|
|
if (!vkd3d_array_reserve((void **)&buffer->buffer, &buffer->buffer_size, new_buffer_size, 1))
|
2020-07-23 02:11:25 -07:00
|
|
|
|
{
|
|
|
|
|
ERR("Failed to grow buffer.\n");
|
|
|
|
|
buffer->buffer[buffer->content_size] = '\0';
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 10:56:30 -08:00
|
|
|
|
int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer, const char *format, ...)
|
2020-07-23 02:11:25 -07:00
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
ret = vkd3d_string_buffer_vprintf(buffer, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 04:21:33 -08:00
|
|
|
|
int vkd3d_string_buffer_print_f32(struct vkd3d_string_buffer *buffer, float f)
|
|
|
|
|
{
|
|
|
|
|
unsigned int idx = buffer->content_size + 1;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (!(ret = vkd3d_string_buffer_printf(buffer, "%.8e", f)) && isfinite(f))
|
|
|
|
|
{
|
|
|
|
|
if (signbit(f))
|
|
|
|
|
++idx;
|
|
|
|
|
buffer->buffer[idx] = '.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 04:21:34 -08:00
|
|
|
|
int vkd3d_string_buffer_print_f64(struct vkd3d_string_buffer *buffer, double d)
|
|
|
|
|
{
|
|
|
|
|
unsigned int idx = buffer->content_size + 1;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (!(ret = vkd3d_string_buffer_printf(buffer, "%.16e", d)) && isfinite(d))
|
|
|
|
|
{
|
|
|
|
|
if (signbit(d))
|
|
|
|
|
++idx;
|
|
|
|
|
buffer->buffer[idx] = '.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-07 10:56:30 -08:00
|
|
|
|
void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function)
|
2020-07-28 02:52:34 -07:00
|
|
|
|
{
|
2021-09-16 20:36:35 -07:00
|
|
|
|
vkd3d_shader_trace_text_(buffer->buffer, buffer->content_size, function);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vkd3d_shader_trace_text_(const char *text, size_t size, const char *function)
|
|
|
|
|
{
|
|
|
|
|
const char *p, *q, *end = text + size;
|
2020-07-28 02:52:34 -07:00
|
|
|
|
|
|
|
|
|
if (!TRACE_ON())
|
|
|
|
|
return;
|
|
|
|
|
|
2021-09-16 20:36:35 -07:00
|
|
|
|
for (p = text; p < end; p = q)
|
2020-07-28 02:52:34 -07:00
|
|
|
|
{
|
2020-10-15 08:44:45 -07:00
|
|
|
|
if (!(q = memchr(p, '\n', end - p)))
|
|
|
|
|
q = end;
|
2020-07-28 02:52:34 -07:00
|
|
|
|
else
|
|
|
|
|
++q;
|
|
|
|
|
vkd3d_dbg_printf(VKD3D_DBG_LEVEL_TRACE, function, "%.*s", (int)(q - p), p);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 16:03:09 -08:00
|
|
|
|
void vkd3d_string_buffer_cache_init(struct vkd3d_string_buffer_cache *cache)
|
|
|
|
|
{
|
|
|
|
|
memset(cache, 0, sizeof(*cache));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vkd3d_string_buffer_cache_cleanup(struct vkd3d_string_buffer_cache *cache)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cache->count; ++i)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_string_buffer_cleanup(cache->buffers[i]);
|
|
|
|
|
vkd3d_free(cache->buffers[i]);
|
|
|
|
|
}
|
|
|
|
|
vkd3d_free(cache->buffers);
|
|
|
|
|
vkd3d_string_buffer_cache_init(cache);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct vkd3d_string_buffer *vkd3d_string_buffer_get(struct vkd3d_string_buffer_cache *cache)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_string_buffer *buffer;
|
|
|
|
|
|
|
|
|
|
if (!cache->count)
|
|
|
|
|
{
|
|
|
|
|
if (!vkd3d_array_reserve((void **)&cache->buffers, &cache->capacity,
|
|
|
|
|
cache->max_count + 1, sizeof(*cache->buffers)))
|
|
|
|
|
return NULL;
|
|
|
|
|
++cache->max_count;
|
|
|
|
|
|
|
|
|
|
if (!(buffer = vkd3d_malloc(sizeof(*buffer))))
|
|
|
|
|
return NULL;
|
|
|
|
|
vkd3d_string_buffer_init(buffer);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
buffer = cache->buffers[--cache->count];
|
|
|
|
|
}
|
|
|
|
|
vkd3d_string_buffer_clear(buffer);
|
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vkd3d_string_buffer_release(struct vkd3d_string_buffer_cache *cache, struct vkd3d_string_buffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
if (!buffer)
|
|
|
|
|
return;
|
|
|
|
|
assert(cache->count + 1 <= cache->max_count);
|
|
|
|
|
cache->buffers[cache->count++] = buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 23:14:03 -07:00
|
|
|
|
void vkd3d_shader_message_context_init(struct vkd3d_shader_message_context *context,
|
2020-12-15 09:01:32 -08:00
|
|
|
|
enum vkd3d_shader_log_level log_level)
|
2020-07-23 02:11:25 -07:00
|
|
|
|
{
|
|
|
|
|
context->log_level = log_level;
|
2020-10-08 23:14:03 -07:00
|
|
|
|
vkd3d_string_buffer_init(&context->messages);
|
2020-07-23 02:11:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 20:04:38 -08:00
|
|
|
|
void vkd3d_shader_vnote(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location,
|
|
|
|
|
enum vkd3d_shader_log_level level, const char *format, va_list args)
|
|
|
|
|
{
|
|
|
|
|
if (context->log_level < level)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (location)
|
|
|
|
|
{
|
|
|
|
|
const char *source_name = location->source_name ? location->source_name : "<anonymous>";
|
|
|
|
|
|
|
|
|
|
if (location->line)
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s:%u:%u: ",
|
|
|
|
|
source_name, location->line, location->column);
|
|
|
|
|
else
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s: ", source_name);
|
|
|
|
|
}
|
|
|
|
|
vkd3d_string_buffer_vprintf(&context->messages, format, args);
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 12:37:06 -08:00
|
|
|
|
void vkd3d_shader_vwarning(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location,
|
|
|
|
|
enum vkd3d_shader_error error, const char *format, va_list args)
|
|
|
|
|
{
|
|
|
|
|
if (context->log_level < VKD3D_SHADER_LOG_WARNING)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (location)
|
|
|
|
|
{
|
|
|
|
|
const char *source_name = location->source_name ? location->source_name : "<anonymous>";
|
|
|
|
|
|
|
|
|
|
if (location->line)
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s:%u:%u: W%04u: ",
|
|
|
|
|
source_name, location->line, location->column, error);
|
|
|
|
|
else
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s: W%04u: ", source_name, error);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "W%04u: ", error);
|
|
|
|
|
}
|
|
|
|
|
vkd3d_string_buffer_vprintf(&context->messages, format, args);
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 09:01:32 -08:00
|
|
|
|
void vkd3d_shader_verror(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location,
|
2020-08-04 03:13:29 -07:00
|
|
|
|
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;
|
|
|
|
|
|
2020-12-15 09:01:32 -08:00
|
|
|
|
if (location)
|
|
|
|
|
{
|
|
|
|
|
const char *source_name = location->source_name ? location->source_name : "<anonymous>";
|
|
|
|
|
|
|
|
|
|
if (location->line)
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s:%u:%u: E%04u: ",
|
|
|
|
|
source_name, location->line, location->column, error);
|
|
|
|
|
else
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "%s: E%04u: ", source_name, error);
|
|
|
|
|
}
|
2020-07-23 02:11:25 -07:00
|
|
|
|
else
|
2020-12-15 09:01:32 -08:00
|
|
|
|
{
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "E%04u: ", error);
|
|
|
|
|
}
|
2020-07-23 02:11:25 -07:00
|
|
|
|
vkd3d_string_buffer_vprintf(&context->messages, format, args);
|
|
|
|
|
vkd3d_string_buffer_printf(&context->messages, "\n");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 09:01:32 -08:00
|
|
|
|
void vkd3d_shader_error(struct vkd3d_shader_message_context *context, const struct vkd3d_shader_location *location,
|
2020-08-04 03:13:29 -07:00
|
|
|
|
enum vkd3d_shader_error error, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
2020-12-15 09:01:32 -08:00
|
|
|
|
vkd3d_shader_verror(context, location, error, format, args);
|
2020-08-04 03:13:29 -07:00
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 14:55:50 -07:00
|
|
|
|
size_t bytecode_align(struct vkd3d_bytecode_buffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
size_t aligned_size = align(buffer->size, 4);
|
|
|
|
|
|
|
|
|
|
if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->capacity, aligned_size, 1))
|
|
|
|
|
{
|
|
|
|
|
buffer->status = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
return aligned_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(buffer->data + buffer->size, 0xab, aligned_size - buffer->size);
|
|
|
|
|
buffer->size = aligned_size;
|
|
|
|
|
return aligned_size;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 13:51:29 -07:00
|
|
|
|
size_t bytecode_put_bytes(struct vkd3d_bytecode_buffer *buffer, const void *bytes, size_t size)
|
|
|
|
|
{
|
2023-04-05 14:55:50 -07:00
|
|
|
|
size_t offset = bytecode_align(buffer);
|
2021-07-26 13:51:29 -07:00
|
|
|
|
|
|
|
|
|
if (buffer->status)
|
|
|
|
|
return offset;
|
|
|
|
|
|
2023-04-04 09:27:59 -07:00
|
|
|
|
if (!vkd3d_array_reserve((void **)&buffer->data, &buffer->capacity, offset + size, 1))
|
2021-07-26 13:51:29 -07:00
|
|
|
|
{
|
|
|
|
|
buffer->status = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
memcpy(buffer->data + offset, bytes, size);
|
2023-04-04 09:27:59 -07:00
|
|
|
|
buffer->size = offset + size;
|
2021-07-26 13:51:29 -07:00
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_u32(struct vkd3d_bytecode_buffer *buffer, size_t offset, uint32_t value)
|
|
|
|
|
{
|
|
|
|
|
if (buffer->status)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
assert(vkd3d_bound_range(offset, sizeof(value), buffer->size));
|
|
|
|
|
memcpy(buffer->data + offset, &value, sizeof(value));
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-21 12:35:08 -07:00
|
|
|
|
static void vkd3d_shader_dump_blob(const char *path, const char *profile,
|
2021-09-01 06:45:05 -07:00
|
|
|
|
const char *suffix, const void *data, size_t size)
|
2019-01-31 02:29:27 -08:00
|
|
|
|
{
|
2022-01-31 02:51:58 -08:00
|
|
|
|
static LONG shader_id = 0;
|
2019-01-31 02:29:27 -08:00
|
|
|
|
char filename[1024];
|
|
|
|
|
unsigned int id;
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
|
|
id = InterlockedIncrement(&shader_id) - 1;
|
|
|
|
|
|
2023-10-21 12:35:08 -07:00
|
|
|
|
if (profile)
|
|
|
|
|
snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%u-%s.%s", path, id, profile, suffix);
|
2023-10-21 11:44:07 -07:00
|
|
|
|
else
|
|
|
|
|
snprintf(filename, ARRAY_SIZE(filename), "%s/vkd3d-shader-%u.%s", path, id, suffix);
|
2019-01-31 02:29:27 -08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 06:45:05 -07:00
|
|
|
|
static const char *shader_get_source_type_suffix(enum vkd3d_shader_source_type type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_TPF:
|
|
|
|
|
return "dxbc";
|
|
|
|
|
case VKD3D_SHADER_SOURCE_HLSL:
|
|
|
|
|
return "hlsl";
|
2021-10-06 08:11:48 -07:00
|
|
|
|
case VKD3D_SHADER_SOURCE_D3D_BYTECODE:
|
|
|
|
|
return "d3dbc";
|
2022-11-14 21:16:41 -08:00
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_DXIL:
|
|
|
|
|
return "dxil";
|
2021-09-01 06:45:05 -07:00
|
|
|
|
default:
|
|
|
|
|
FIXME("Unhandled source type %#x.\n", type);
|
|
|
|
|
return "bin";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-21 12:35:08 -07:00
|
|
|
|
void vkd3d_shader_dump_shader(const struct vkd3d_shader_compile_info *compile_info)
|
2019-01-31 02:29:27 -08:00
|
|
|
|
{
|
2023-10-21 12:35:08 -07:00
|
|
|
|
const struct vkd3d_shader_code *shader = &compile_info->source;
|
|
|
|
|
const struct vkd3d_shader_hlsl_source_info *hlsl_source_info;
|
|
|
|
|
const struct hlsl_profile_info *profile;
|
|
|
|
|
const char *profile_name = NULL;
|
2019-01-31 02:29:27 -08:00
|
|
|
|
static bool enabled = true;
|
|
|
|
|
const char *path;
|
|
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!(path = getenv("VKD3D_SHADER_DUMP_PATH")))
|
|
|
|
|
{
|
|
|
|
|
enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-21 12:35:08 -07:00
|
|
|
|
if (compile_info->source_type == VKD3D_SHADER_SOURCE_HLSL)
|
|
|
|
|
{
|
|
|
|
|
if (!(hlsl_source_info = vkd3d_find_struct(compile_info->next, HLSL_SOURCE_INFO)))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!(profile = hlsl_get_target_info(hlsl_source_info->profile)))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
profile_name = profile->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_dump_blob(path, profile_name, shader_get_source_type_suffix(compile_info->source_type),
|
2023-10-21 11:44:07 -07:00
|
|
|
|
shader->code, shader->size);
|
2019-01-31 02:29:27 -08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 14:21:18 -08:00
|
|
|
|
static void init_scan_signature_info(const struct vkd3d_shader_compile_info *info)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_scan_signature_info *signature_info;
|
|
|
|
|
|
|
|
|
|
if ((signature_info = vkd3d_find_struct(info->next, SCAN_SIGNATURE_INFO)))
|
|
|
|
|
{
|
|
|
|
|
memset(&signature_info->input, 0, sizeof(signature_info->input));
|
|
|
|
|
memset(&signature_info->output, 0, sizeof(signature_info->output));
|
|
|
|
|
memset(&signature_info->patch_constant, 0, sizeof(signature_info->patch_constant));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-29 12:20:35 -07:00
|
|
|
|
static const struct vkd3d_debug_option vkd3d_shader_config_options[] =
|
|
|
|
|
{
|
|
|
|
|
{"force_validation", VKD3D_SHADER_CONFIG_FLAG_FORCE_VALIDATION}, /* force validation of internal shader representations */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static uint64_t vkd3d_shader_init_config_flags(void)
|
|
|
|
|
{
|
|
|
|
|
uint64_t config_flags;
|
|
|
|
|
const char *config;
|
|
|
|
|
|
|
|
|
|
config = getenv("VKD3D_SHADER_CONFIG");
|
|
|
|
|
config_flags = vkd3d_parse_debug_options(config, vkd3d_shader_config_options, ARRAY_SIZE(vkd3d_shader_config_options));
|
|
|
|
|
|
|
|
|
|
if (config_flags)
|
|
|
|
|
TRACE("VKD3D_SHADER_CONFIG='%s'.\n", config);
|
|
|
|
|
|
|
|
|
|
return config_flags;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 17:44:21 -08:00
|
|
|
|
bool vkd3d_shader_parser_init(struct vkd3d_shader_parser *parser,
|
2021-10-01 08:51:15 -07:00
|
|
|
|
struct vkd3d_shader_message_context *message_context, const char *source_name,
|
2023-01-19 17:44:21 -08:00
|
|
|
|
const struct vkd3d_shader_version *version, const struct vkd3d_shader_parser_ops *ops,
|
|
|
|
|
unsigned int instruction_reserve)
|
2021-10-01 08:51:14 -07:00
|
|
|
|
{
|
|
|
|
|
parser->message_context = message_context;
|
2021-10-01 08:51:15 -07:00
|
|
|
|
parser->location.source_name = source_name;
|
|
|
|
|
parser->location.line = 1;
|
|
|
|
|
parser->location.column = 0;
|
2021-10-01 08:51:14 -07:00
|
|
|
|
parser->shader_version = *version;
|
2021-10-06 08:11:47 -07:00
|
|
|
|
parser->ops = ops;
|
2023-08-29 12:20:35 -07:00
|
|
|
|
parser->config_flags = vkd3d_shader_init_config_flags();
|
2023-01-19 17:44:21 -08:00
|
|
|
|
return shader_instruction_array_init(&parser->instructions, instruction_reserve);
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
2017-06-19 09:05:53 -07:00
|
|
|
|
|
2021-10-06 08:11:46 -07:00
|
|
|
|
void VKD3D_PRINTF_FUNC(3, 4) vkd3d_shader_parser_error(struct vkd3d_shader_parser *parser,
|
|
|
|
|
enum vkd3d_shader_error error, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vkd3d_shader_verror(parser->message_context, &parser->location, error, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
parser->failed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 08:11:48 -07:00
|
|
|
|
void VKD3D_PRINTF_FUNC(3, 4) vkd3d_shader_parser_warning(struct vkd3d_shader_parser *parser,
|
|
|
|
|
enum vkd3d_shader_error error, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vkd3d_shader_vwarning(parser->message_context, &parser->location, error, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-02 07:29:11 -08:00
|
|
|
|
static int vkd3d_shader_validate_compile_info(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
bool validate_target_type)
|
2020-06-19 04:43:36 -07:00
|
|
|
|
{
|
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-12-02 07:29:11 -08:00
|
|
|
|
if (validate_target_type)
|
2020-06-23 02:20:12 -07:00
|
|
|
|
{
|
2020-12-02 07:29:11 -08:00
|
|
|
|
target_types = vkd3d_shader_get_supported_target_types(compile_info->source_type, &count);
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (target_types[i] == compile_info->target_type)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 14:21:18 -08:00
|
|
|
|
static bool vkd3d_shader_signature_from_shader_signature(struct vkd3d_shader_signature *signature,
|
|
|
|
|
const struct shader_signature *src)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
signature->element_count = src->element_count;
|
|
|
|
|
if (!src->elements)
|
|
|
|
|
{
|
|
|
|
|
assert(!signature->element_count);
|
|
|
|
|
signature->elements = NULL;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!(signature->elements = vkd3d_calloc(signature->element_count, sizeof(*signature->elements))))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < signature->element_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_signature_element *d = &signature->elements[i];
|
|
|
|
|
struct signature_element *e = &src->elements[i];
|
|
|
|
|
|
|
|
|
|
d->semantic_name = e->semantic_name;
|
|
|
|
|
d->semantic_index = e->semantic_index;
|
|
|
|
|
d->stream_index = e->stream_index;
|
|
|
|
|
d->sysval_semantic = e->sysval_semantic;
|
|
|
|
|
d->component_type = e->component_type;
|
|
|
|
|
d->register_index = e->register_index;
|
|
|
|
|
if (e->register_count > 1)
|
|
|
|
|
FIXME("Arrayed elements are not supported yet.\n");
|
|
|
|
|
d->mask = e->mask;
|
|
|
|
|
d->used_mask = e->used_mask;
|
|
|
|
|
d->min_precision = e->min_precision;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 23:18:24 -07:00
|
|
|
|
struct vkd3d_shader_scan_context
|
|
|
|
|
{
|
2023-10-14 16:26:32 -07:00
|
|
|
|
const struct vkd3d_shader_version *version;
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info1 *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-12-15 09:01:32 -08:00
|
|
|
|
struct vkd3d_shader_location location;
|
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;
|
|
|
|
|
|
2022-02-28 03:23:46 -08:00
|
|
|
|
enum vkd3d_shader_api_version api_version;
|
2023-10-14 16:26:32 -07:00
|
|
|
|
|
|
|
|
|
struct vkd3d_shader_scan_combined_resource_sampler_info *combined_sampler_info;
|
|
|
|
|
size_t combined_samplers_size;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
};
|
|
|
|
|
|
2023-11-20 05:51:05 -08:00
|
|
|
|
static VKD3D_PRINTF_FUNC(3, 4) void vkd3d_shader_scan_error(struct vkd3d_shader_scan_context *context,
|
|
|
|
|
enum vkd3d_shader_error error, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vkd3d_shader_verror(context->message_context, &context->location, error, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-20 05:58:40 -08:00
|
|
|
|
static void VKD3D_PRINTF_FUNC(3, 4) vkd3d_shader_scan_warning(struct vkd3d_shader_scan_context *context,
|
|
|
|
|
enum vkd3d_shader_error error, const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vkd3d_shader_vwarning(context->message_context, &context->location, error, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:52:58 -07:00
|
|
|
|
static void vkd3d_shader_scan_context_init(struct vkd3d_shader_scan_context *context,
|
2023-10-14 16:26:32 -07:00
|
|
|
|
const struct vkd3d_shader_version *version,
|
2020-12-15 09:01:32 -08:00
|
|
|
|
const struct vkd3d_shader_compile_info *compile_info,
|
2023-07-31 16:52:21 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info1 *scan_descriptor_info,
|
2023-10-14 16:26:32 -07:00
|
|
|
|
struct vkd3d_shader_scan_combined_resource_sampler_info *combined_sampler_info,
|
2020-09-25 14:52:58 -07:00
|
|
|
|
struct vkd3d_shader_message_context *message_context)
|
2020-07-30 03:29:54 -07:00
|
|
|
|
{
|
2022-02-28 03:23:46 -08:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
2020-07-30 03:29:54 -07:00
|
|
|
|
memset(context, 0, sizeof(*context));
|
2023-10-14 16:26:32 -07:00
|
|
|
|
context->version = version;
|
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-12-15 09:01:32 -08:00
|
|
|
|
context->location.source_name = compile_info->source_name;
|
|
|
|
|
context->location.line = 2; /* Line 1 is the version token. */
|
2022-02-28 03:23:46 -08:00
|
|
|
|
context->api_version = VKD3D_SHADER_API_VERSION_1_2;
|
2023-10-14 16:26:32 -07:00
|
|
|
|
context->combined_sampler_info = combined_sampler_info;
|
2022-02-28 03:23:46 -08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < compile_info->option_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
const struct vkd3d_shader_compile_option *option = &compile_info->options[i];
|
|
|
|
|
|
|
|
|
|
if (option->name == VKD3D_SHADER_COMPILE_OPTION_API_VERSION)
|
|
|
|
|
context->api_version = option->value;
|
|
|
|
|
}
|
2020-07-30 03:29:54 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_scan_context_cleanup(struct vkd3d_shader_scan_context *context)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 15:59:09 -07:00
|
|
|
|
static void vkd3d_shader_scan_add_uav_flag(const struct vkd3d_shader_scan_context *context,
|
|
|
|
|
const struct vkd3d_shader_register *reg, uint32_t flag)
|
2020-06-24 23:18:26 -07:00
|
|
|
|
{
|
2023-07-31 15:59:09 -07:00
|
|
|
|
unsigned int range_id = reg->idx[0].offset;
|
2020-06-24 23:18:26 -07:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
2023-07-31 15:59:09 -07:00
|
|
|
|
if (!context->scan_descriptor_info)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-07-31 17:10:37 -07:00
|
|
|
|
for (i = 0; i < context->scan_descriptor_info->descriptor_count; ++i)
|
2020-06-24 23:18:26 -07:00
|
|
|
|
{
|
2023-08-31 19:44:44 -07:00
|
|
|
|
if (context->scan_descriptor_info->descriptors[i].type == VKD3D_SHADER_DESCRIPTOR_TYPE_UAV
|
|
|
|
|
&& context->scan_descriptor_info->descriptors[i].register_id == range_id)
|
2023-07-31 15:59:09 -07:00
|
|
|
|
{
|
2023-07-31 17:10:37 -07:00
|
|
|
|
context->scan_descriptor_info->descriptors[i].flags |= flag;
|
2023-07-31 15:59:09 -07:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-06-24 23:18:26 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-21 03:41:07 -07:00
|
|
|
|
static bool vkd3d_shader_instruction_is_uav_read(const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
2021-02-16 05:58:23 -08:00
|
|
|
|
enum vkd3d_shader_opcode handler_idx = instruction->handler_idx;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-07-31 15:59:09 -07:00
|
|
|
|
vkd3d_shader_scan_add_uav_flag(context, reg, 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)
|
|
|
|
|
{
|
2021-02-16 05:58:23 -08:00
|
|
|
|
enum vkd3d_shader_opcode handler_idx = instruction->handler_idx;
|
2017-09-01 02:27:58 -07:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-07-31 15:59:09 -07:00
|
|
|
|
vkd3d_shader_scan_add_uav_flag(context, reg, VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_COUNTER);
|
2017-09-01 02:27:58 -07:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 19:44:05 -08:00
|
|
|
|
static bool vkd3d_shader_instruction_is_uav_atomic_op(const struct vkd3d_shader_instruction *instruction)
|
|
|
|
|
{
|
|
|
|
|
enum vkd3d_shader_opcode handler_idx = instruction->handler_idx;
|
|
|
|
|
return (VKD3DSIH_ATOMIC_AND <= handler_idx && handler_idx <= VKD3DSIH_ATOMIC_XOR)
|
|
|
|
|
|| (VKD3DSIH_IMM_ATOMIC_ALLOC <= handler_idx && handler_idx <= VKD3DSIH_IMM_ATOMIC_XOR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_scan_record_uav_atomic_op(struct vkd3d_shader_scan_context *context,
|
|
|
|
|
const struct vkd3d_shader_register *reg)
|
|
|
|
|
{
|
2023-07-31 15:59:09 -07:00
|
|
|
|
vkd3d_shader_scan_add_uav_flag(context, reg, VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_ATOMICS);
|
2022-11-17 19:44:05 -08:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-15 15:52:24 -07:00
|
|
|
|
static struct vkd3d_shader_descriptor_info1 *vkd3d_shader_scan_add_descriptor(struct vkd3d_shader_scan_context *context,
|
2023-07-31 16:59:16 -07:00
|
|
|
|
enum vkd3d_shader_descriptor_type type, const struct vkd3d_shader_register *reg,
|
|
|
|
|
const struct vkd3d_shader_register_range *range, enum vkd3d_shader_resource_type resource_type,
|
2023-08-15 15:52:24 -07:00
|
|
|
|
enum vkd3d_shader_resource_data_type resource_data_type)
|
2020-06-24 23:18:24 -07:00
|
|
|
|
{
|
2023-07-31 16:52:21 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info1 *info = context->scan_descriptor_info;
|
|
|
|
|
struct vkd3d_shader_descriptor_info1 *d;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
|
2023-10-27 09:48:24 -07:00
|
|
|
|
if (!info)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
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");
|
2023-08-15 15:52:24 -07:00
|
|
|
|
return NULL;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 03:29:55 -07:00
|
|
|
|
d = &info->descriptors[info->descriptor_count];
|
2023-08-15 15:52:24 -07:00
|
|
|
|
memset(d, 0, sizeof(*d));
|
2020-06-24 23:18:24 -07:00
|
|
|
|
d->type = type;
|
2023-07-31 16:59:16 -07:00
|
|
|
|
d->register_id = reg->idx[0].offset;
|
2021-06-27 20:03:11 -07:00
|
|
|
|
d->register_space = range->space;
|
|
|
|
|
d->register_index = range->first;
|
2020-06-24 23:18:25 -07:00
|
|
|
|
d->resource_type = resource_type;
|
|
|
|
|
d->resource_data_type = resource_data_type;
|
2021-07-23 06:01:38 -07:00
|
|
|
|
d->count = (range->last == ~0u) ? ~0u : range->last - range->first + 1;
|
2020-07-30 03:29:55 -07:00
|
|
|
|
++info->descriptor_count;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
|
2023-08-15 15:52:24 -07:00
|
|
|
|
return d;
|
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;
|
2023-07-31 17:34:23 -07:00
|
|
|
|
struct vkd3d_shader_descriptor_info1 *d;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
|
2023-07-31 17:34:23 -07:00
|
|
|
|
if (!(d = vkd3d_shader_scan_add_descriptor(context, VKD3D_SHADER_DESCRIPTOR_TYPE_CBV,
|
|
|
|
|
&cb->src.reg, &cb->range, VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT)))
|
|
|
|
|
return;
|
2023-10-18 20:15:46 -07:00
|
|
|
|
d->buffer_size = cb->size;
|
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;
|
2023-08-15 15:52:24 -07:00
|
|
|
|
struct vkd3d_shader_descriptor_info1 *d;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
|
2023-08-15 15:52:24 -07:00
|
|
|
|
if (!(d = vkd3d_shader_scan_add_descriptor(context, VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER,
|
|
|
|
|
&sampler->src.reg, &sampler->range, VKD3D_SHADER_RESOURCE_NONE, VKD3D_SHADER_RESOURCE_DATA_UINT)))
|
|
|
|
|
return;
|
|
|
|
|
|
2018-10-21 16:49:15 -07:00
|
|
|
|
if (instruction->flags & VKD3DSI_SAMPLER_COMPARISON_MODE)
|
2023-08-15 15:52:24 -07:00
|
|
|
|
d->flags |= VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_SAMPLER_COMPARISON_MODE;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 13:26:25 -07:00
|
|
|
|
static void vkd3d_shader_scan_combined_sampler_declaration(
|
|
|
|
|
struct vkd3d_shader_scan_context *context, const struct vkd3d_shader_semantic *semantic)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_shader_scan_add_descriptor(context, VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER, &semantic->resource.reg.reg,
|
|
|
|
|
&semantic->resource.range, VKD3D_SHADER_RESOURCE_NONE, VKD3D_SHADER_RESOURCE_DATA_UINT);
|
|
|
|
|
vkd3d_shader_scan_add_descriptor(context, VKD3D_SHADER_DESCRIPTOR_TYPE_SRV, &semantic->resource.reg.reg,
|
|
|
|
|
&semantic->resource.range, semantic->resource_type, VKD3D_SHADER_RESOURCE_DATA_FLOAT);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-14 16:26:32 -07:00
|
|
|
|
static void vkd3d_shader_scan_combined_sampler_usage(struct vkd3d_shader_scan_context *context,
|
|
|
|
|
const struct vkd3d_shader_register *resource, const struct vkd3d_shader_register *sampler)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_scan_combined_resource_sampler_info *info;
|
|
|
|
|
struct vkd3d_shader_combined_resource_sampler_info *s;
|
|
|
|
|
unsigned resource_space = 0, sampler_space = 0;
|
|
|
|
|
unsigned int resource_idx, sampler_idx, i;
|
|
|
|
|
|
|
|
|
|
if (!(info = context->combined_sampler_info))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (resource->type == VKD3DSPR_RESOURCE)
|
|
|
|
|
resource_idx = resource->idx[1].offset;
|
|
|
|
|
else
|
|
|
|
|
resource_idx = resource->idx[0].offset;
|
|
|
|
|
|
|
|
|
|
if (!sampler)
|
|
|
|
|
sampler_idx = VKD3D_SHADER_DUMMY_SAMPLER_INDEX;
|
|
|
|
|
else if (sampler->type == VKD3DSPR_SAMPLER)
|
|
|
|
|
sampler_idx = sampler->idx[1].offset;
|
|
|
|
|
else
|
|
|
|
|
sampler_idx = sampler->idx[0].offset;
|
|
|
|
|
|
|
|
|
|
if (vkd3d_shader_ver_ge(context->version, 5, 1))
|
|
|
|
|
{
|
|
|
|
|
const struct vkd3d_shader_scan_descriptor_info1 *info = context->scan_descriptor_info;
|
|
|
|
|
const struct vkd3d_shader_descriptor_info1 *d;
|
2023-11-20 05:58:40 -08:00
|
|
|
|
bool dynamic_resource, dynamic_sampler;
|
|
|
|
|
|
|
|
|
|
if ((dynamic_resource = resource->idx[1].rel_addr))
|
|
|
|
|
vkd3d_shader_scan_warning(context, VKD3D_SHADER_WARNING_VSIR_DYNAMIC_DESCRIPTOR_ARRAY,
|
|
|
|
|
"Resource descriptor array %u is being dynamically indexed, "
|
|
|
|
|
"not recording a combined resource-sampler pair.", resource->idx[0].offset);
|
|
|
|
|
if ((dynamic_sampler = sampler && sampler->idx[1].rel_addr))
|
|
|
|
|
vkd3d_shader_scan_warning(context, VKD3D_SHADER_WARNING_VSIR_DYNAMIC_DESCRIPTOR_ARRAY,
|
|
|
|
|
"Sampler descriptor array %u is being dynamically indexed, "
|
|
|
|
|
"not recording a combined resource-sampler pair.", sampler->idx[0].offset);
|
|
|
|
|
if (dynamic_resource || dynamic_sampler)
|
|
|
|
|
return;
|
2023-10-14 16:26:32 -07:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < info->descriptor_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
d = &info->descriptors[i];
|
|
|
|
|
if (d->type != VKD3D_SHADER_DESCRIPTOR_TYPE_SRV)
|
|
|
|
|
continue;
|
|
|
|
|
if (d->register_id != resource->idx[0].offset)
|
|
|
|
|
continue;
|
|
|
|
|
resource_space = d->register_space;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sampler)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < info->descriptor_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
d = &info->descriptors[i];
|
|
|
|
|
if (d->type != VKD3D_SHADER_DESCRIPTOR_TYPE_SAMPLER)
|
|
|
|
|
continue;
|
|
|
|
|
if (d->register_id != sampler->idx[0].offset)
|
|
|
|
|
continue;
|
|
|
|
|
sampler_space = d->register_space;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < info->combined_sampler_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
s = &info->combined_samplers[i];
|
|
|
|
|
if (s->resource_space == resource_space && s->resource_index == resource_idx
|
|
|
|
|
&& s->sampler_space == sampler_space && s->sampler_index == sampler_idx)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!vkd3d_array_reserve((void **)&info->combined_samplers, &context->combined_samplers_size,
|
|
|
|
|
info->combined_sampler_count + 1, sizeof(*info->combined_samplers)))
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to allocate combined sampler info.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s = &info->combined_samplers[info->combined_sampler_count++];
|
|
|
|
|
s->resource_space = resource_space;
|
|
|
|
|
s->resource_index = resource_idx;
|
|
|
|
|
s->sampler_space = sampler_space;
|
|
|
|
|
s->sampler_index = sampler_idx;
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
2023-07-31 17:56:43 -07:00
|
|
|
|
enum vkd3d_shader_resource_data_type resource_data_type,
|
2023-08-09 16:59:51 -07:00
|
|
|
|
unsigned int sample_count, unsigned int structure_stride, bool raw)
|
2020-06-24 23:18:24 -07:00
|
|
|
|
{
|
2023-07-31 17:22:33 -07:00
|
|
|
|
struct vkd3d_shader_descriptor_info1 *d;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
enum vkd3d_shader_descriptor_type type;
|
|
|
|
|
|
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;
|
2023-07-31 17:22:33 -07:00
|
|
|
|
if (!(d = vkd3d_shader_scan_add_descriptor(context, type, &resource->reg.reg,
|
|
|
|
|
&resource->range, resource_type, resource_data_type)))
|
|
|
|
|
return;
|
|
|
|
|
d->sample_count = sample_count;
|
2023-07-31 17:56:43 -07:00
|
|
|
|
d->structure_stride = structure_stride;
|
2023-08-09 16:59:51 -07:00
|
|
|
|
if (raw)
|
|
|
|
|
d->flags |= VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_RAW_BUFFER;
|
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;
|
2022-02-28 03:23:46 -08:00
|
|
|
|
case VKD3D_DATA_MIXED:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_MIXED;
|
|
|
|
|
break;
|
2022-02-28 03:23:47 -08:00
|
|
|
|
case VKD3D_DATA_DOUBLE:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_DOUBLE;
|
|
|
|
|
break;
|
|
|
|
|
case VKD3D_DATA_CONTINUED:
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_CONTINUED;
|
|
|
|
|
break;
|
2020-06-24 23:18:25 -07:00
|
|
|
|
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;
|
|
|
|
|
}
|
2022-02-28 03:23:46 -08:00
|
|
|
|
|
|
|
|
|
if (context->api_version < VKD3D_SHADER_API_VERSION_1_3
|
|
|
|
|
&& resource_data_type >= VKD3D_SHADER_RESOURCE_DATA_MIXED)
|
|
|
|
|
{
|
|
|
|
|
ERR("Invalid resource data type %#x for API version %#x.\n",
|
|
|
|
|
semantic->resource_data_type[0], context->api_version);
|
|
|
|
|
resource_data_type = VKD3D_SHADER_RESOURCE_DATA_FLOAT;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-30 03:32:03 -07:00
|
|
|
|
vkd3d_shader_scan_resource_declaration(context, &semantic->resource,
|
2023-08-09 16:59:51 -07:00
|
|
|
|
semantic->resource_type, resource_data_type, semantic->sample_count, 0, false);
|
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)
|
|
|
|
|
{
|
2023-10-14 16:26:32 -07:00
|
|
|
|
const struct vkd3d_shader_register *sampler_reg;
|
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:
|
2023-08-11 13:26:25 -07:00
|
|
|
|
if (instruction->declaration.semantic.resource.reg.reg.type == VKD3DSPR_COMBINED_SAMPLER)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_declaration(context, &instruction->declaration.semantic);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* fall through */
|
2020-06-24 23:18:24 -07:00
|
|
|
|
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,
|
2023-08-09 16:59:51 -07:00
|
|
|
|
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT, 0, 0, true);
|
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,
|
2023-07-31 17:56:43 -07:00
|
|
|
|
VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT, 0,
|
2023-08-09 16:59:51 -07:00
|
|
|
|
instruction->declaration.structured_resource.byte_stride, false);
|
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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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;
|
2021-11-08 05:50:17 -08:00
|
|
|
|
cf_info->inside_block = true;
|
2020-07-30 03:29:54 -07:00
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_ENDLOOP:
|
|
|
|
|
if (!(cf_info = vkd3d_shader_scan_get_current_cf_info(context)) || cf_info->type != VKD3D_SHADER_BLOCK_LOOP)
|
|
|
|
|
{
|
2020-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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-12-14 20:49:15 -08:00
|
|
|
|
vkd3d_shader_scan_error(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;
|
2023-10-14 16:26:32 -07:00
|
|
|
|
case VKD3DSIH_TEX:
|
|
|
|
|
if (context->version->major == 1)
|
|
|
|
|
sampler_reg = &instruction->dst[0].reg;
|
|
|
|
|
else
|
|
|
|
|
sampler_reg = &instruction->src[1].reg;
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, sampler_reg, sampler_reg);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_TEXBEM:
|
|
|
|
|
case VKD3DSIH_TEXBEML:
|
|
|
|
|
case VKD3DSIH_TEXDP3TEX:
|
|
|
|
|
case VKD3DSIH_TEXM3x2TEX:
|
|
|
|
|
case VKD3DSIH_TEXM3x3SPEC:
|
|
|
|
|
case VKD3DSIH_TEXM3x3TEX:
|
|
|
|
|
case VKD3DSIH_TEXM3x3VSPEC:
|
|
|
|
|
case VKD3DSIH_TEXREG2AR:
|
|
|
|
|
case VKD3DSIH_TEXREG2GB:
|
|
|
|
|
case VKD3DSIH_TEXREG2RGB:
|
|
|
|
|
sampler_reg = &instruction->dst[0].reg;
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, sampler_reg, sampler_reg);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_GATHER4:
|
|
|
|
|
case VKD3DSIH_GATHER4_C:
|
|
|
|
|
case VKD3DSIH_SAMPLE:
|
|
|
|
|
case VKD3DSIH_SAMPLE_B:
|
|
|
|
|
case VKD3DSIH_SAMPLE_C:
|
|
|
|
|
case VKD3DSIH_SAMPLE_C_LZ:
|
|
|
|
|
case VKD3DSIH_SAMPLE_GRAD:
|
|
|
|
|
case VKD3DSIH_SAMPLE_LOD:
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, &instruction->src[1].reg, &instruction->src[2].reg);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_GATHER4_PO:
|
|
|
|
|
case VKD3DSIH_GATHER4_PO_C:
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, &instruction->src[2].reg, &instruction->src[3].reg);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_LD:
|
|
|
|
|
case VKD3DSIH_LD2DMS:
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, &instruction->src[1].reg, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_BUFINFO:
|
|
|
|
|
case VKD3DSIH_SAMPLE_INFO:
|
|
|
|
|
if (instruction->src[0].reg.type == VKD3DSPR_RESOURCE)
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, &instruction->src[0].reg, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_LD_RAW:
|
|
|
|
|
case VKD3DSIH_RESINFO:
|
|
|
|
|
if (instruction->src[1].reg.type == VKD3DSPR_RESOURCE)
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, &instruction->src[1].reg, NULL);
|
|
|
|
|
break;
|
|
|
|
|
case VKD3DSIH_LD_STRUCTURED:
|
|
|
|
|
if (instruction->src[2].reg.type == VKD3DSPR_RESOURCE)
|
|
|
|
|
vkd3d_shader_scan_combined_sampler_usage(context, &instruction->src[2].reg, NULL);
|
|
|
|
|
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
|
|
|
|
|
2022-11-17 19:44:05 -08:00
|
|
|
|
if (vkd3d_shader_instruction_is_uav_atomic_op(instruction))
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < instruction->dst_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (instruction->dst[i].reg.type == VKD3DSPR_UAV)
|
|
|
|
|
vkd3d_shader_scan_record_uav_atomic_op(context, &instruction->dst[i].reg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 09:01:32 -08:00
|
|
|
|
++context->location.line;
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return VKD3D_OK;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
static enum vkd3d_result convert_descriptor_info(struct vkd3d_shader_scan_descriptor_info *info,
|
|
|
|
|
const struct vkd3d_shader_scan_descriptor_info1 *info1)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
if (!(info->descriptors = vkd3d_calloc(info1->descriptor_count, sizeof(*info->descriptors))))
|
|
|
|
|
return VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < info1->descriptor_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
const struct vkd3d_shader_descriptor_info1 *src = &info1->descriptors[i];
|
|
|
|
|
struct vkd3d_shader_descriptor_info *dst = &info->descriptors[i];
|
|
|
|
|
|
|
|
|
|
dst->type = src->type;
|
|
|
|
|
dst->register_space = src->register_space;
|
|
|
|
|
dst->register_index = src->register_index;
|
|
|
|
|
dst->resource_type = src->resource_type;
|
|
|
|
|
dst->resource_data_type = src->resource_data_type;
|
|
|
|
|
dst->flags = src->flags;
|
|
|
|
|
dst->count = src->count;
|
|
|
|
|
}
|
|
|
|
|
info->descriptor_count = info1->descriptor_count;
|
|
|
|
|
|
|
|
|
|
return VKD3D_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void vkd3d_shader_free_scan_descriptor_info1(struct vkd3d_shader_scan_descriptor_info1 *scan_descriptor_info)
|
|
|
|
|
{
|
|
|
|
|
TRACE("scan_descriptor_info %p.\n", scan_descriptor_info);
|
|
|
|
|
|
|
|
|
|
vkd3d_free(scan_descriptor_info->descriptors);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 08:11:49 -07:00
|
|
|
|
static int scan_with_parser(const struct vkd3d_shader_compile_info *compile_info,
|
2023-07-31 16:52:21 -07:00
|
|
|
|
struct vkd3d_shader_message_context *message_context,
|
|
|
|
|
struct vkd3d_shader_scan_descriptor_info1 *descriptor_info1, struct vkd3d_shader_parser *parser)
|
2017-08-21 03:41:07 -07:00
|
|
|
|
{
|
2023-10-14 16:26:32 -07:00
|
|
|
|
struct vkd3d_shader_scan_combined_resource_sampler_info *combined_sampler_info;
|
2023-07-31 16:52:21 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info1 local_descriptor_info1 = {0};
|
|
|
|
|
struct vkd3d_shader_scan_descriptor_info *descriptor_info;
|
2023-02-23 14:21:18 -08:00
|
|
|
|
struct vkd3d_shader_scan_signature_info *signature_info;
|
2023-01-19 18:23:27 -08:00
|
|
|
|
struct vkd3d_shader_instruction *instruction;
|
2020-06-24 23:18:24 -07:00
|
|
|
|
struct vkd3d_shader_scan_context context;
|
2023-01-19 18:23:27 -08:00
|
|
|
|
int ret = VKD3D_OK;
|
|
|
|
|
unsigned int i;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
descriptor_info = vkd3d_find_struct(compile_info->next, SCAN_DESCRIPTOR_INFO);
|
|
|
|
|
if (descriptor_info1)
|
|
|
|
|
{
|
|
|
|
|
descriptor_info1->descriptors = NULL;
|
|
|
|
|
descriptor_info1->descriptor_count = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (descriptor_info)
|
2020-07-30 03:29:55 -07:00
|
|
|
|
{
|
2023-07-31 16:52:21 -07:00
|
|
|
|
descriptor_info1 = &local_descriptor_info1;
|
2020-07-30 03:29:55 -07:00
|
|
|
|
}
|
2023-02-23 14:21:18 -08:00
|
|
|
|
signature_info = vkd3d_find_struct(compile_info->next, SCAN_SIGNATURE_INFO);
|
2020-07-30 03:29:55 -07:00
|
|
|
|
|
2023-10-14 16:26:32 -07:00
|
|
|
|
if ((combined_sampler_info = vkd3d_find_struct(compile_info->next, SCAN_COMBINED_RESOURCE_SAMPLER_INFO)))
|
|
|
|
|
{
|
|
|
|
|
combined_sampler_info->combined_samplers = NULL;
|
|
|
|
|
combined_sampler_info->combined_sampler_count = 0;
|
|
|
|
|
if (!descriptor_info1)
|
|
|
|
|
descriptor_info1 = &local_descriptor_info1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_scan_context_init(&context, &parser->shader_version, compile_info,
|
|
|
|
|
descriptor_info1, combined_sampler_info, message_context);
|
2020-07-30 03:29:54 -07:00
|
|
|
|
|
2020-07-28 02:52:33 -07:00
|
|
|
|
if (TRACE_ON())
|
2021-09-02 05:35:54 -07:00
|
|
|
|
{
|
2023-02-22 19:47:03 -08:00
|
|
|
|
vkd3d_shader_trace(&parser->instructions, &parser->shader_version);
|
2021-09-02 05:35:54 -07:00
|
|
|
|
}
|
2020-07-28 02:52:33 -07:00
|
|
|
|
|
2023-01-19 18:23:27 -08:00
|
|
|
|
for (i = 0; i < parser->instructions.count; ++i)
|
2017-08-21 03:41:07 -07:00
|
|
|
|
{
|
2023-01-19 18:23:27 -08:00
|
|
|
|
instruction = &parser->instructions.elements[i];
|
|
|
|
|
if ((ret = vkd3d_shader_scan_instruction(&context, instruction)) < 0)
|
|
|
|
|
break;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-27 22:07:14 -08:00
|
|
|
|
for (i = 0; i < ARRAY_SIZE(parser->shader_desc.flat_constant_count); ++i)
|
|
|
|
|
{
|
2023-07-31 17:34:23 -07:00
|
|
|
|
unsigned int size = parser->shader_desc.flat_constant_count[i].external;
|
2023-02-27 22:07:14 -08:00
|
|
|
|
struct vkd3d_shader_register_range range = {.space = 0, .first = i, .last = i};
|
2023-07-31 16:59:16 -07:00
|
|
|
|
struct vkd3d_shader_register reg = {.idx[0].offset = i, .idx_count = 1};
|
2023-07-31 17:34:23 -07:00
|
|
|
|
struct vkd3d_shader_descriptor_info1 *d;
|
2023-02-27 22:07:14 -08:00
|
|
|
|
|
|
|
|
|
if (parser->shader_desc.flat_constant_count[i].external)
|
2023-07-31 17:34:23 -07:00
|
|
|
|
{
|
|
|
|
|
if ((d = vkd3d_shader_scan_add_descriptor(&context, VKD3D_SHADER_DESCRIPTOR_TYPE_CBV, ®,
|
|
|
|
|
&range, VKD3D_SHADER_RESOURCE_BUFFER, VKD3D_SHADER_RESOURCE_DATA_UINT)))
|
|
|
|
|
d->buffer_size = size * 16;
|
|
|
|
|
}
|
2023-02-27 22:07:14 -08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 14:21:18 -08:00
|
|
|
|
if (!ret && signature_info)
|
|
|
|
|
{
|
|
|
|
|
if (!vkd3d_shader_signature_from_shader_signature(&signature_info->input, &parser->shader_desc.input_signature)
|
|
|
|
|
|| !vkd3d_shader_signature_from_shader_signature(&signature_info->output,
|
|
|
|
|
&parser->shader_desc.output_signature)
|
|
|
|
|
|| !vkd3d_shader_signature_from_shader_signature(&signature_info->patch_constant,
|
|
|
|
|
&parser->shader_desc.patch_constant_signature))
|
|
|
|
|
{
|
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
if (!ret && descriptor_info)
|
|
|
|
|
ret = convert_descriptor_info(descriptor_info, descriptor_info1);
|
|
|
|
|
|
2023-07-31 16:36:30 -07:00
|
|
|
|
if (ret < 0)
|
|
|
|
|
{
|
2023-10-14 16:26:32 -07:00
|
|
|
|
if (combined_sampler_info)
|
|
|
|
|
vkd3d_shader_free_scan_combined_resource_sampler_info(combined_sampler_info);
|
2023-07-31 16:52:21 -07:00
|
|
|
|
if (descriptor_info)
|
|
|
|
|
vkd3d_shader_free_scan_descriptor_info(descriptor_info);
|
|
|
|
|
if (descriptor_info1)
|
|
|
|
|
vkd3d_shader_free_scan_descriptor_info1(descriptor_info1);
|
2023-07-31 16:36:30 -07:00
|
|
|
|
if (signature_info)
|
|
|
|
|
vkd3d_shader_free_scan_signature_info(signature_info);
|
|
|
|
|
}
|
2023-07-31 16:52:21 -07:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
vkd3d_shader_free_scan_descriptor_info1(&local_descriptor_info1);
|
|
|
|
|
}
|
2020-07-30 03:29:54 -07:00
|
|
|
|
vkd3d_shader_scan_context_cleanup(&context);
|
2021-10-06 08:11:49 -07:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int scan_dxbc(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_message_context *message_context)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_parser *parser;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_sm4_parser_create(compile_info, message_context, &parser)) < 0)
|
|
|
|
|
{
|
|
|
|
|
WARN("Failed to initialise shader parser.\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
ret = scan_with_parser(compile_info, message_context, NULL, parser);
|
2021-10-06 08:11:49 -07:00
|
|
|
|
vkd3d_shader_parser_destroy(parser);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int scan_d3dbc(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_message_context *message_context)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_parser *parser;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_sm1_parser_create(compile_info, message_context, &parser)) < 0)
|
|
|
|
|
{
|
|
|
|
|
WARN("Failed to initialise shader parser.\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
ret = scan_with_parser(compile_info, message_context, NULL, parser);
|
2021-10-01 08:51:11 -07:00
|
|
|
|
vkd3d_shader_parser_destroy(parser);
|
2021-10-06 08:11:49 -07:00
|
|
|
|
|
2020-07-30 03:29:54 -07:00
|
|
|
|
return ret;
|
2017-08-21 03:41:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 21:16:41 -08:00
|
|
|
|
static int scan_dxil(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_message_context *message_context)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_parser *parser;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_sm6_parser_create(compile_info, message_context, &parser)) < 0)
|
|
|
|
|
{
|
|
|
|
|
WARN("Failed to initialise shader parser.\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
ret = scan_with_parser(compile_info, message_context, NULL, parser);
|
2022-11-14 21:16:41 -08:00
|
|
|
|
vkd3d_shader_parser_destroy(parser);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-12-28 14:20:17 -08:00
|
|
|
|
if ((ret = vkd3d_shader_validate_compile_info(compile_info, false)) < 0)
|
2020-09-25 14:52:58 -07:00
|
|
|
|
return ret;
|
|
|
|
|
|
2023-02-23 14:21:18 -08:00
|
|
|
|
init_scan_signature_info(compile_info);
|
|
|
|
|
|
2020-12-15 09:01:32 -08:00
|
|
|
|
vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
|
2020-09-25 14:52:58 -07:00
|
|
|
|
|
2023-10-21 12:35:08 -07:00
|
|
|
|
vkd3d_shader_dump_shader(compile_info);
|
|
|
|
|
|
2021-09-01 06:45:07 -07:00
|
|
|
|
switch (compile_info->source_type)
|
|
|
|
|
{
|
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_TPF:
|
|
|
|
|
ret = scan_dxbc(compile_info, &message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case VKD3D_SHADER_SOURCE_HLSL:
|
|
|
|
|
FIXME("HLSL support not implemented.\n");
|
|
|
|
|
ret = VKD3D_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
break;
|
|
|
|
|
|
2021-10-06 08:11:49 -07:00
|
|
|
|
case VKD3D_SHADER_SOURCE_D3D_BYTECODE:
|
|
|
|
|
ret = scan_d3dbc(compile_info, &message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-14 21:16:41 -08:00
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_DXIL:
|
|
|
|
|
ret = scan_dxil(compile_info, &message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
2021-09-01 06:45:07 -07:00
|
|
|
|
default:
|
|
|
|
|
ERR("Unsupported source type %#x.\n", compile_info->source_type);
|
|
|
|
|
ret = VKD3D_ERROR_INVALID_ARGUMENT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-25 14:52:58 -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:58 -07:00
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
vkd3d_shader_message_context_cleanup(&message_context);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-12 14:53:39 -08:00
|
|
|
|
static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser,
|
|
|
|
|
const struct vkd3d_shader_compile_info *compile_info,
|
2020-09-25 14:53:00 -07:00
|
|
|
|
struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
|
2020-09-25 14:52:59 -07:00
|
|
|
|
{
|
2023-07-31 16:52:21 -07:00
|
|
|
|
struct vkd3d_shader_scan_descriptor_info1 scan_descriptor_info;
|
2022-03-12 14:53:39 -08:00
|
|
|
|
struct vkd3d_glsl_generator *glsl_generator;
|
2020-09-25 14:52:59 -07:00
|
|
|
|
struct vkd3d_shader_compile_info scan_info;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
scan_info = *compile_info;
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
if ((ret = scan_with_parser(&scan_info, message_context, &scan_descriptor_info, parser)) < 0)
|
2022-03-12 14:45:41 -08:00
|
|
|
|
return ret;
|
|
|
|
|
|
2022-03-12 14:53:39 -08:00
|
|
|
|
switch (compile_info->target_type)
|
2020-09-25 14:52:59 -07:00
|
|
|
|
{
|
2022-03-12 14:53:39 -08:00
|
|
|
|
case VKD3D_SHADER_TARGET_D3D_ASM:
|
|
|
|
|
ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out);
|
|
|
|
|
break;
|
2020-09-25 14:52:59 -07:00
|
|
|
|
|
2022-03-12 14:53:39 -08:00
|
|
|
|
case VKD3D_SHADER_TARGET_GLSL:
|
|
|
|
|
if (!(glsl_generator = vkd3d_glsl_generator_create(&parser->shader_version,
|
|
|
|
|
message_context, &parser->location)))
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to create GLSL generator.\n");
|
2023-07-31 16:52:21 -07:00
|
|
|
|
vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info);
|
2022-03-12 14:53:39 -08:00
|
|
|
|
return VKD3D_ERROR;
|
|
|
|
|
}
|
2021-08-19 07:48:13 -07:00
|
|
|
|
|
2022-03-12 14:53:39 -08:00
|
|
|
|
ret = vkd3d_glsl_generator_generate(glsl_generator, parser, out);
|
|
|
|
|
vkd3d_glsl_generator_destroy(glsl_generator);
|
|
|
|
|
break;
|
2021-08-19 07:48:13 -07:00
|
|
|
|
|
2022-03-12 14:53:39 -08:00
|
|
|
|
case VKD3D_SHADER_TARGET_SPIRV_BINARY:
|
|
|
|
|
case VKD3D_SHADER_TARGET_SPIRV_TEXT:
|
|
|
|
|
ret = spirv_compile(parser, &scan_descriptor_info, compile_info, out, message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* Validation should prevent us from reaching this. */
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 16:52:21 -07:00
|
|
|
|
vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info);
|
2022-03-12 14:53:39 -08:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2021-08-19 07:48:13 -07:00
|
|
|
|
|
2022-03-12 14:53:39 -08: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)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_parser *parser;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_sm4_parser_create(compile_info, message_context, &parser)) < 0)
|
|
|
|
|
{
|
|
|
|
|
WARN("Failed to initialise shader parser.\n");
|
2021-08-19 07:48:13 -07:00
|
|
|
|
return ret;
|
2021-08-17 21:19:14 -07:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-12 14:53:39 -08:00
|
|
|
|
ret = vkd3d_shader_parser_compile(parser, compile_info, out, message_context);
|
2020-09-25 14:52:59 -07:00
|
|
|
|
|
2021-10-01 08:51:11 -07:00
|
|
|
|
vkd3d_shader_parser_destroy(parser);
|
2020-09-25 14:53:00 -07:00
|
|
|
|
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)
|
|
|
|
|
{
|
2021-01-27 08:29:44 -08:00
|
|
|
|
struct vkd3d_shader_code preprocessed;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = preproc_lexer_parse(compile_info, &preprocessed, message_context)))
|
|
|
|
|
return ret;
|
|
|
|
|
|
2021-03-04 15:33:28 -08:00
|
|
|
|
ret = hlsl_compile_shader(&preprocessed, compile_info, out, message_context);
|
2021-01-27 08:29:44 -08:00
|
|
|
|
|
|
|
|
|
vkd3d_shader_free_shader_code(&preprocessed);
|
|
|
|
|
return ret;
|
2020-09-25 14:53:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 08:11:48 -07:00
|
|
|
|
static int compile_d3d_bytecode(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_parser *parser;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_sm1_parser_create(compile_info, message_context, &parser)) < 0)
|
|
|
|
|
{
|
|
|
|
|
WARN("Failed to initialise shader parser.\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM)
|
|
|
|
|
{
|
2023-02-22 19:47:03 -08:00
|
|
|
|
ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out);
|
2021-10-06 08:11:48 -07:00
|
|
|
|
vkd3d_shader_parser_destroy(parser);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VKD3D_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 21:16:41 -08:00
|
|
|
|
static int compile_dxbc_dxil(const struct vkd3d_shader_compile_info *compile_info,
|
|
|
|
|
struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_parser *parser;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if ((ret = vkd3d_shader_sm6_parser_create(compile_info, message_context, &parser)) < 0)
|
|
|
|
|
{
|
|
|
|
|
WARN("Failed to initialise shader parser.\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = vkd3d_shader_parser_compile(parser, compile_info, out, message_context);
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_parser_destroy(parser);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
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;
|
|
|
|
|
|
2020-12-02 07:29:11 -08:00
|
|
|
|
if ((ret = vkd3d_shader_validate_compile_info(compile_info, true)) < 0)
|
2020-09-25 14:53:00 -07:00
|
|
|
|
return ret;
|
|
|
|
|
|
2023-02-23 14:21:18 -08:00
|
|
|
|
init_scan_signature_info(compile_info);
|
|
|
|
|
|
2020-12-15 09:01:32 -08:00
|
|
|
|
vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
|
2020-09-25 14:53:00 -07:00
|
|
|
|
|
2023-10-21 12:35:08 -07:00
|
|
|
|
vkd3d_shader_dump_shader(compile_info);
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
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;
|
|
|
|
|
|
2021-10-06 08:11:48 -07:00
|
|
|
|
case VKD3D_SHADER_SOURCE_D3D_BYTECODE:
|
|
|
|
|
ret = compile_d3d_bytecode(compile_info, out, &message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
2022-11-14 21:16:41 -08:00
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_DXIL:
|
|
|
|
|
ret = compile_dxbc_dxil(compile_info, out, &message_context);
|
|
|
|
|
break;
|
|
|
|
|
|
2020-09-25 14:53:00 -07:00
|
|
|
|
default:
|
2022-08-31 04:25:24 -07:00
|
|
|
|
vkd3d_unreachable();
|
2020-09-25 14:53:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2023-10-14 16:26:32 -07:00
|
|
|
|
|
|
|
|
|
void vkd3d_shader_free_scan_combined_resource_sampler_info(
|
|
|
|
|
struct vkd3d_shader_scan_combined_resource_sampler_info *info)
|
|
|
|
|
{
|
|
|
|
|
TRACE("info %p.\n", info);
|
|
|
|
|
|
|
|
|
|
vkd3d_free(info->combined_samplers);
|
|
|
|
|
}
|
2020-09-25 14:52:59 -07:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 14:21:18 -08:00
|
|
|
|
void vkd3d_shader_free_scan_signature_info(struct vkd3d_shader_scan_signature_info *info)
|
|
|
|
|
{
|
|
|
|
|
TRACE("info %p.\n", info);
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_free_shader_signature(&info->input);
|
|
|
|
|
vkd3d_shader_free_shader_signature(&info->output);
|
|
|
|
|
vkd3d_shader_free_shader_signature(&info->patch_constant);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-03 23:22:57 -07:00
|
|
|
|
void shader_signature_cleanup(struct shader_signature *signature)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_free(signature->elements);
|
|
|
|
|
signature->elements = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2023-04-03 23:22:57 -07:00
|
|
|
|
struct shader_signature shader_signature;
|
2020-07-30 03:29:56 -07:00
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
TRACE("dxbc {%p, %zu}, signature %p, messages %p.\n", dxbc->code, dxbc->size, signature, messages);
|
|
|
|
|
|
|
|
|
|
if (messages)
|
|
|
|
|
*messages = NULL;
|
2020-12-15 09:01:32 -08:00
|
|
|
|
vkd3d_shader_message_context_init(&message_context, VKD3D_SHADER_LOG_INFO);
|
2017-09-11 13:35:16 -07:00
|
|
|
|
|
2023-04-03 23:22:57 -07:00
|
|
|
|
ret = shader_parse_input_signature(dxbc, &message_context, &shader_signature);
|
2020-07-30 03:29:56 -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-07-30 03:29:56 -07:00
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_message_context_cleanup(&message_context);
|
|
|
|
|
|
2023-04-03 23:22:57 -07:00
|
|
|
|
if (!vkd3d_shader_signature_from_shader_signature(signature, &shader_signature))
|
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
shader_signature_cleanup(&shader_signature);
|
2020-07-30 03:29:56 -07:00
|
|
|
|
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,
|
2021-10-06 08:11:48 -07:00
|
|
|
|
VKD3D_SHADER_SOURCE_D3D_BYTECODE,
|
2023-09-18 04:54:00 -07:00
|
|
|
|
#ifdef VKD3D_SHADER_UNSUPPORTED_DXIL
|
2022-11-14 21:16:41 -08:00
|
|
|
|
VKD3D_SHADER_SOURCE_DXBC_DXIL,
|
2023-09-18 04:54:00 -07:00
|
|
|
|
#endif
|
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,
|
2022-03-02 10:06:23 -08:00
|
|
|
|
#if 0
|
2021-08-17 21:19:14 -07:00
|
|
|
|
VKD3D_SHADER_TARGET_GLSL,
|
2022-03-02 10:06:23 -08:00
|
|
|
|
#endif
|
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[] =
|
|
|
|
|
{
|
2022-02-28 03:23:43 -08:00
|
|
|
|
VKD3D_SHADER_TARGET_D3D_BYTECODE,
|
2020-09-25 14:53:00 -07:00
|
|
|
|
VKD3D_SHADER_TARGET_DXBC_TPF,
|
|
|
|
|
};
|
|
|
|
|
|
2021-10-06 08:11:48 -07:00
|
|
|
|
static const enum vkd3d_shader_target_type d3dbc_types[] =
|
|
|
|
|
{
|
|
|
|
|
VKD3D_SHADER_TARGET_D3D_ASM,
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-06 01:53:49 -07:00
|
|
|
|
TRACE("source_type %#x, count %p.\n", source_type, count);
|
|
|
|
|
|
|
|
|
|
switch (source_type)
|
|
|
|
|
{
|
2023-09-18 04:54:00 -07:00
|
|
|
|
#ifdef VKD3D_SHADER_UNSUPPORTED_DXIL
|
2022-11-14 21:16:41 -08:00
|
|
|
|
case VKD3D_SHADER_SOURCE_DXBC_DXIL:
|
2023-09-18 04:54:00 -07:00
|
|
|
|
#endif
|
2020-08-06 01:53:49 -07:00
|
|
|
|
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;
|
|
|
|
|
|
2021-10-06 08:11:48 -07:00
|
|
|
|
case VKD3D_SHADER_SOURCE_D3D_BYTECODE:
|
|
|
|
|
*count = ARRAY_SIZE(d3dbc_types);
|
|
|
|
|
return d3dbc_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)
|
|
|
|
|
{
|
2020-12-07 10:56:30 -08:00
|
|
|
|
struct vkd3d_shader_message_context message_context;
|
2020-12-02 07:29:11 -08:00
|
|
|
|
int ret;
|
|
|
|
|
|
2020-09-25 14:53:01 -07:00
|
|
|
|
TRACE("compile_info %p, out %p, messages %p.\n", compile_info, out, messages);
|
|
|
|
|
|
2020-11-21 15:23:44 -08:00
|
|
|
|
if (messages)
|
|
|
|
|
*messages = NULL;
|
|
|
|
|
|
2020-12-02 07:29:11 -08:00
|
|
|
|
if ((ret = vkd3d_shader_validate_compile_info(compile_info, false)) < 0)
|
|
|
|
|
return ret;
|
|
|
|
|
|
2020-12-15 09:01:32 -08:00
|
|
|
|
vkd3d_shader_message_context_init(&message_context, compile_info->log_level);
|
2020-12-07 10:56:30 -08:00
|
|
|
|
|
|
|
|
|
ret = preproc_lexer_parse(compile_info, out, &message_context);
|
|
|
|
|
|
|
|
|
|
vkd3d_shader_message_context_trace_messages(&message_context);
|
|
|
|
|
if (!vkd3d_shader_message_context_copy_messages(&message_context, messages))
|
|
|
|
|
ret = VKD3D_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
vkd3d_shader_message_context_cleanup(&message_context);
|
|
|
|
|
return ret;
|
2020-09-25 14:53:01 -07:00
|
|
|
|
}
|
2022-06-01 17:01:00 -07:00
|
|
|
|
|
|
|
|
|
void vkd3d_shader_set_log_callback(PFN_vkd3d_log callback)
|
|
|
|
|
{
|
|
|
|
|
vkd3d_dbg_set_log_callback(callback);
|
|
|
|
|
}
|
2023-01-19 17:13:01 -08:00
|
|
|
|
|
|
|
|
|
static struct vkd3d_shader_param_node *shader_param_allocator_node_create(
|
|
|
|
|
struct vkd3d_shader_param_allocator *allocator)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_param_node *node;
|
|
|
|
|
|
|
|
|
|
if (!(node = vkd3d_malloc(offsetof(struct vkd3d_shader_param_node, param[allocator->count * allocator->stride]))))
|
|
|
|
|
return NULL;
|
|
|
|
|
node->next = NULL;
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void shader_param_allocator_init(struct vkd3d_shader_param_allocator *allocator,
|
|
|
|
|
unsigned int count, unsigned int stride)
|
|
|
|
|
{
|
2023-08-17 06:38:42 -07:00
|
|
|
|
allocator->count = max(count, MAX_REG_OUTPUT);
|
2023-01-19 17:13:01 -08:00
|
|
|
|
allocator->stride = stride;
|
|
|
|
|
allocator->head = NULL;
|
|
|
|
|
allocator->current = NULL;
|
|
|
|
|
allocator->index = allocator->count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void shader_param_allocator_destroy(struct vkd3d_shader_param_allocator *allocator)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_param_node *current = allocator->head;
|
|
|
|
|
|
|
|
|
|
while (current)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_param_node *next = current->next;
|
|
|
|
|
vkd3d_free(current);
|
|
|
|
|
current = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *shader_param_allocator_get(struct vkd3d_shader_param_allocator *allocator, unsigned int count)
|
|
|
|
|
{
|
|
|
|
|
void *params;
|
|
|
|
|
|
|
|
|
|
if (count > allocator->count - allocator->index)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_param_node *next = shader_param_allocator_node_create(allocator);
|
|
|
|
|
|
|
|
|
|
if (!next)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (allocator->current)
|
|
|
|
|
allocator->current->next = next;
|
2023-02-03 17:35:16 -08:00
|
|
|
|
else
|
|
|
|
|
allocator->head = next;
|
2023-01-19 17:13:01 -08:00
|
|
|
|
allocator->current = next;
|
|
|
|
|
allocator->index = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
params = &allocator->current->param[allocator->index * allocator->stride];
|
|
|
|
|
allocator->index += count;
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool shader_instruction_array_init(struct vkd3d_shader_instruction_array *instructions, unsigned int reserve)
|
|
|
|
|
{
|
|
|
|
|
memset(instructions, 0, sizeof(*instructions));
|
|
|
|
|
/* Size the parameter initial allocations so they are large enough for most shaders. The
|
|
|
|
|
* code path for chained allocations will be tested if a few shaders need to use it. */
|
|
|
|
|
shader_param_allocator_init(&instructions->dst_params, reserve - reserve / 8u,
|
|
|
|
|
sizeof(*instructions->elements->dst));
|
|
|
|
|
shader_param_allocator_init(&instructions->src_params, reserve * 2u, sizeof(*instructions->elements->src));
|
|
|
|
|
return shader_instruction_array_reserve(instructions, reserve);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool shader_instruction_array_reserve(struct vkd3d_shader_instruction_array *instructions, unsigned int reserve)
|
|
|
|
|
{
|
|
|
|
|
if (!vkd3d_array_reserve((void **)&instructions->elements, &instructions->capacity, reserve,
|
|
|
|
|
sizeof(*instructions->elements)))
|
|
|
|
|
{
|
|
|
|
|
ERR("Failed to allocate instructions.\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-28 17:17:51 -07:00
|
|
|
|
unsigned int shader_instruction_array_add_icb(struct vkd3d_shader_instruction_array *instructions,
|
2023-01-19 17:35:38 -08:00
|
|
|
|
struct vkd3d_shader_immediate_constant_buffer *icb)
|
|
|
|
|
{
|
|
|
|
|
if (!vkd3d_array_reserve((void **)&instructions->icbs, &instructions->icb_capacity, instructions->icb_count + 1,
|
|
|
|
|
sizeof(*instructions->icbs)))
|
2023-09-28 17:17:51 -07:00
|
|
|
|
return UINT_MAX;
|
|
|
|
|
instructions->icbs[instructions->icb_count] = icb;
|
|
|
|
|
return instructions->icb_count++;
|
2023-01-19 17:35:38 -08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-28 17:59:28 -08:00
|
|
|
|
static struct vkd3d_shader_src_param *shader_instruction_array_clone_src_params(
|
|
|
|
|
struct vkd3d_shader_instruction_array *instructions, const struct vkd3d_shader_src_param *params,
|
|
|
|
|
unsigned int count);
|
|
|
|
|
|
|
|
|
|
static bool shader_register_clone_relative_addresses(struct vkd3d_shader_register *reg,
|
|
|
|
|
struct vkd3d_shader_instruction_array *instructions)
|
|
|
|
|
{
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
2023-05-26 00:06:16 -07:00
|
|
|
|
for (i = 0; i < reg->idx_count; ++i)
|
2023-02-28 17:59:28 -08:00
|
|
|
|
{
|
|
|
|
|
if (!reg->idx[i].rel_addr)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!(reg->idx[i].rel_addr = shader_instruction_array_clone_src_params(instructions, reg->idx[i].rel_addr, 1)))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct vkd3d_shader_dst_param *shader_instruction_array_clone_dst_params(
|
|
|
|
|
struct vkd3d_shader_instruction_array *instructions, const struct vkd3d_shader_dst_param *params,
|
|
|
|
|
unsigned int count)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_dst_param *dst_params;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
if (!(dst_params = shader_dst_param_allocator_get(&instructions->dst_params, count)))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
memcpy(dst_params, params, count * sizeof(*params));
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (!shader_register_clone_relative_addresses(&dst_params[i].reg, instructions))
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dst_params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct vkd3d_shader_src_param *shader_instruction_array_clone_src_params(
|
|
|
|
|
struct vkd3d_shader_instruction_array *instructions, const struct vkd3d_shader_src_param *params,
|
|
|
|
|
unsigned int count)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_src_param *src_params;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
if (!(src_params = shader_src_param_allocator_get(&instructions->src_params, count)))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
memcpy(src_params, params, count * sizeof(*params));
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (!shader_register_clone_relative_addresses(&src_params[i].reg, instructions))
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return src_params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* NOTE: Immediate constant buffers are not cloned, so the source must not be destroyed while the
|
|
|
|
|
* destination is in use. This seems like a reasonable requirement given how this is currently used. */
|
|
|
|
|
bool shader_instruction_array_clone_instruction(struct vkd3d_shader_instruction_array *instructions,
|
|
|
|
|
unsigned int dst, unsigned int src)
|
|
|
|
|
{
|
|
|
|
|
struct vkd3d_shader_instruction *ins = &instructions->elements[dst];
|
|
|
|
|
|
|
|
|
|
*ins = instructions->elements[src];
|
|
|
|
|
|
|
|
|
|
if (ins->dst_count && ins->dst && !(ins->dst = shader_instruction_array_clone_dst_params(instructions,
|
|
|
|
|
ins->dst, ins->dst_count)))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return !ins->src_count || !!(ins->src = shader_instruction_array_clone_src_params(instructions,
|
|
|
|
|
ins->src, ins->src_count));
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-19 17:13:01 -08:00
|
|
|
|
void shader_instruction_array_destroy(struct vkd3d_shader_instruction_array *instructions)
|
|
|
|
|
{
|
2023-01-19 17:35:38 -08:00
|
|
|
|
unsigned int i;
|
|
|
|
|
|
2023-01-19 17:13:01 -08:00
|
|
|
|
vkd3d_free(instructions->elements);
|
|
|
|
|
shader_param_allocator_destroy(&instructions->dst_params);
|
|
|
|
|
shader_param_allocator_destroy(&instructions->src_params);
|
2023-01-19 17:35:38 -08:00
|
|
|
|
for (i = 0; i < instructions->icb_count; ++i)
|
|
|
|
|
vkd3d_free(instructions->icbs[i]);
|
|
|
|
|
vkd3d_free(instructions->icbs);
|
2023-01-19 17:13:01 -08:00
|
|
|
|
}
|
2023-07-30 22:45:54 -07:00
|
|
|
|
|
|
|
|
|
void vkd3d_shader_build_varying_map(const struct vkd3d_shader_signature *output_signature,
|
|
|
|
|
const struct vkd3d_shader_signature *input_signature,
|
|
|
|
|
unsigned int *ret_count, struct vkd3d_shader_varying_map *varyings)
|
|
|
|
|
{
|
|
|
|
|
unsigned int count = 0;
|
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
|
|
TRACE("output_signature %p, input_signature %p, ret_count %p, varyings %p.\n",
|
|
|
|
|
output_signature, input_signature, ret_count, varyings);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < input_signature->element_count; ++i)
|
|
|
|
|
{
|
|
|
|
|
const struct vkd3d_shader_signature_element *input_element, *output_element;
|
|
|
|
|
|
|
|
|
|
input_element = &input_signature->elements[i];
|
|
|
|
|
|
|
|
|
|
if (input_element->sysval_semantic != VKD3D_SHADER_SV_NONE)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
varyings[count].input_register_index = input_element->register_index;
|
|
|
|
|
varyings[count].input_mask = input_element->mask;
|
|
|
|
|
|
|
|
|
|
if ((output_element = vkd3d_shader_find_signature_element(output_signature,
|
|
|
|
|
input_element->semantic_name, input_element->semantic_index, 0)))
|
|
|
|
|
{
|
|
|
|
|
varyings[count].output_signature_index = output_element - output_signature->elements;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
varyings[count].output_signature_index = output_signature->element_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*ret_count = count;
|
|
|
|
|
}
|