mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-09-12 18:50:22 -07:00
vkd3d-shader: Implement an initial pass-through HLSL preprocessor.
Signed-off-by: Zebediah Figura <zfigura@codeweavers.com> Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
committed by
Alexandre Julliard
parent
5065cb6c1f
commit
f544cb38e5
33
libs/vkd3d-shader/preproc.h
Normal file
33
libs/vkd3d-shader/preproc.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* HLSL preprocessor
|
||||
*
|
||||
* Copyright 2020 Zebediah Figura 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
|
||||
*/
|
||||
|
||||
#ifndef __VKD3D_SHADER_PREPROC_H
|
||||
#define __VKD3D_SHADER_PREPROC_H
|
||||
|
||||
#include "vkd3d_shader_private.h"
|
||||
|
||||
struct preproc_ctx
|
||||
{
|
||||
void *scanner;
|
||||
|
||||
struct vkd3d_string_buffer buffer;
|
||||
};
|
||||
|
||||
#endif
|
99
libs/vkd3d-shader/preproc.l
Normal file
99
libs/vkd3d-shader/preproc.l
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* HLSL preprocessor
|
||||
*
|
||||
* Copyright 2020 Zebediah Figura 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 "preproc.tab.h"
|
||||
|
||||
#define YYSTYPE PREPROC_YYSTYPE
|
||||
#define YYLTYPE PREPROC_YYLTYPE
|
||||
|
||||
#define YY_DECL static int preproc_lexer_lex(YYSTYPE *yylval_param, YYLTYPE *yylloc_param, yyscan_t yyscanner)
|
||||
|
||||
%}
|
||||
|
||||
%option 8bit
|
||||
%option bison-bridge
|
||||
%option bison-locations
|
||||
%option extra-type="struct preproc_ctx *"
|
||||
%option never-interactive
|
||||
%option noinput
|
||||
%option nounput
|
||||
%option noyywrap
|
||||
%option prefix="preproc_yy"
|
||||
%option reentrant
|
||||
|
||||
WS [ \t]
|
||||
|
||||
%%
|
||||
|
||||
{WS}+ {}
|
||||
. {return T_TEXT;}
|
||||
|
||||
%%
|
||||
|
||||
int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner)
|
||||
{
|
||||
struct preproc_ctx *ctx = yyget_extra(scanner);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
const char *text;
|
||||
int token;
|
||||
|
||||
if (!(token = preproc_lexer_lex(lval, lloc, scanner)))
|
||||
return 0;
|
||||
text = yyget_text(scanner);
|
||||
|
||||
TRACE("Parsing token %d, string %s.\n", token, debugstr_a(text));
|
||||
|
||||
vkd3d_string_buffer_printf(&ctx->buffer, "%s ", text);
|
||||
}
|
||||
}
|
||||
|
||||
int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info,
|
||||
struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context)
|
||||
{
|
||||
struct preproc_ctx ctx = {0};
|
||||
YY_BUFFER_STATE top_buffer;
|
||||
void *output_code;
|
||||
|
||||
vkd3d_string_buffer_init(&ctx.buffer);
|
||||
|
||||
yylex_init_extra(&ctx, &ctx.scanner);
|
||||
top_buffer = yy_scan_bytes(compile_info->source.code, compile_info->source.size, ctx.scanner);
|
||||
|
||||
preproc_yyparse(ctx.scanner, &ctx);
|
||||
|
||||
yy_delete_buffer(top_buffer, ctx.scanner);
|
||||
yylex_destroy(ctx.scanner);
|
||||
|
||||
if (!(output_code = vkd3d_malloc(ctx.buffer.content_size)))
|
||||
{
|
||||
vkd3d_string_buffer_cleanup(&ctx.buffer);
|
||||
return VKD3D_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(output_code, ctx.buffer.buffer, ctx.buffer.content_size);
|
||||
out->size = ctx.buffer.content_size;
|
||||
out->code = output_code;
|
||||
vkd3d_string_buffer_trace(&ctx.buffer);
|
||||
vkd3d_string_buffer_cleanup(&ctx.buffer);
|
||||
return VKD3D_OK;
|
||||
}
|
60
libs/vkd3d-shader/preproc.y
Normal file
60
libs/vkd3d-shader/preproc.y
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* HLSL preprocessor
|
||||
*
|
||||
* Copyright 2020 Zebediah Figura 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
|
||||
*/
|
||||
|
||||
%code requires
|
||||
{
|
||||
|
||||
#include "vkd3d_shader_private.h"
|
||||
#include "preproc.h"
|
||||
|
||||
}
|
||||
|
||||
%code provides
|
||||
{
|
||||
|
||||
int preproc_yylex(PREPROC_YYSTYPE *yylval_param, PREPROC_YYLTYPE *yylloc_param, void *scanner);
|
||||
|
||||
}
|
||||
|
||||
%code
|
||||
{
|
||||
|
||||
static void yyerror(const YYLTYPE *loc, void *scanner, struct preproc_ctx *ctx, const char *string)
|
||||
{
|
||||
FIXME("Error reporting is not implemented.\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%define api.prefix {preproc_yy}
|
||||
%define api.pure full
|
||||
%define parse.error verbose
|
||||
%expect 0
|
||||
%locations
|
||||
%lex-param {yyscan_t scanner}
|
||||
%parse-param {void *scanner}
|
||||
%parse-param {struct preproc_ctx *ctx}
|
||||
|
||||
%token T_TEXT
|
||||
|
||||
%%
|
||||
|
||||
shader_text
|
||||
: %empty
|
@@ -78,8 +78,7 @@ int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *
|
||||
}
|
||||
}
|
||||
|
||||
static int VKD3D_PRINTF_FUNC(2, 3) vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer,
|
||||
const char *format, ...)
|
||||
int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret;
|
||||
@@ -91,7 +90,7 @@ static int VKD3D_PRINTF_FUNC(2, 3) vkd3d_string_buffer_printf(struct vkd3d_strin
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function)
|
||||
void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function)
|
||||
{
|
||||
const char *p, *q, *end = buffer->buffer + buffer->content_size;
|
||||
|
||||
@@ -1154,6 +1153,7 @@ const enum vkd3d_shader_target_type *vkd3d_shader_get_supported_target_types(
|
||||
int vkd3d_shader_preprocess(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);
|
||||
@@ -1164,5 +1164,13 @@ int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info
|
||||
if ((ret = vkd3d_shader_validate_compile_info(compile_info, false)) < 0)
|
||||
return ret;
|
||||
|
||||
return VKD3D_ERROR_NOT_IMPLEMENTED;
|
||||
vkd3d_shader_message_context_init(&message_context, compile_info->log_level, compile_info->source_name);
|
||||
|
||||
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;
|
||||
}
|
||||
|
@@ -837,6 +837,11 @@ struct vkd3d_string_buffer
|
||||
enum vkd3d_result vkd3d_dxbc_binary_to_text(void *data, struct vkd3d_shader_code *out) DECLSPEC_HIDDEN;
|
||||
void vkd3d_string_buffer_cleanup(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN;
|
||||
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer) DECLSPEC_HIDDEN;
|
||||
int vkd3d_string_buffer_printf(struct vkd3d_string_buffer *buffer,
|
||||
const char *format, ...) VKD3D_PRINTF_FUNC(2, 3) DECLSPEC_HIDDEN;
|
||||
#define vkd3d_string_buffer_trace(buffer) \
|
||||
vkd3d_string_buffer_trace_(buffer, __FUNCTION__)
|
||||
void vkd3d_string_buffer_trace_(const struct vkd3d_string_buffer *buffer, const char *function) DECLSPEC_HIDDEN;
|
||||
int vkd3d_string_buffer_vprintf(struct vkd3d_string_buffer *buffer, const char *format, va_list args) DECLSPEC_HIDDEN;
|
||||
|
||||
struct vkd3d_shader_message_context
|
||||
@@ -882,6 +887,9 @@ void vkd3d_dxbc_compiler_destroy(struct vkd3d_dxbc_compiler *compiler) DECLSPEC_
|
||||
|
||||
void vkd3d_compute_dxbc_checksum(const void *dxbc, size_t size, uint32_t checksum[4]) DECLSPEC_HIDDEN;
|
||||
|
||||
int preproc_lexer_parse(const struct vkd3d_shader_compile_info *compile_info,
|
||||
struct vkd3d_shader_code *out, struct vkd3d_shader_message_context *message_context) DECLSPEC_HIDDEN;
|
||||
|
||||
static inline enum vkd3d_shader_component_type vkd3d_component_type_from_data_type(
|
||||
enum vkd3d_data_type data_type)
|
||||
{
|
||||
|
Reference in New Issue
Block a user