Wine-Devel
By thread
wine-devel@list.winehq.org
By month
Messages by month
- ----- 2026 -----
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
June 2022
- 68 participants
- 3274 messages
Re: [PATCH vkd3d 3/3] vkd3d-utils: Allow writing log output via a custom callback.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Il 02/06/22 02:01, Zebediah Figura ha scritto:
> When using PE vkd3d through Wine, debug output may be swallowed by writing to
> Win32 stderr. Avoid this by providing a way to hook up vkd3d log output to Wine
> output.
>
> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
> ---
> include/vkd3d_utils.h | 15 +++++++++++++++
> libs/vkd3d-utils/vkd3d_utils.map | 1 +
> libs/vkd3d-utils/vkd3d_utils_main.c | 6 ++++++
> 3 files changed, 22 insertions(+)
>
> diff --git a/include/vkd3d_utils.h b/include/vkd3d_utils.h
> index 565247820..6e84b176e 100644
> --- a/include/vkd3d_utils.h
> +++ b/include/vkd3d_utils.h
> @@ -75,6 +75,21 @@ VKD3D_UTILS_API HRESULT WINAPI D3DPreprocess(const void *data, SIZE_T size, cons
> const D3D_SHADER_MACRO *defines, ID3DInclude *include,
> ID3DBlob **shader, ID3DBlob **error_messages);
>
> +/**
> + * Set a callback to be called when vkd3d-utils outputs debug logging.
> + *
> + * If NULL, or if this function has not been called, libvkd3d-utils will print
> + * all enabled log output to stderr.
> + *
> + * Calling this function will also set the log callback for libvkd3d and
> + * libvkd3d-shader.
> + *
> + * \param callback Callback function to set.
> + *
> + * \since 1.4
> + */
> +VKD3D_UTILS_API void vkd3d_utils_set_log_callback(PFN_vkd3d_log callback);
> +
> #ifdef __cplusplus
> }
> #endif /* __cplusplus */
> diff --git a/libs/vkd3d-utils/vkd3d_utils.map b/libs/vkd3d-utils/vkd3d_utils.map
> index 1e46cd865..14eb439e0 100644
> --- a/libs/vkd3d-utils/vkd3d_utils.map
> +++ b/libs/vkd3d-utils/vkd3d_utils.map
> @@ -15,6 +15,7 @@ global:
> vkd3d_create_event;
> vkd3d_destroy_event;
> vkd3d_signal_event;
> + vkd3d_utils_set_log_callback;
> vkd3d_wait_event;
>
> local: *;
> diff --git a/libs/vkd3d-utils/vkd3d_utils_main.c b/libs/vkd3d-utils/vkd3d_utils_main.c
> index 22953c461..644188930 100644
> --- a/libs/vkd3d-utils/vkd3d_utils_main.c
> +++ b/libs/vkd3d-utils/vkd3d_utils_main.c
> @@ -536,3 +536,9 @@ HRESULT WINAPI D3DCreateBlob(SIZE_T data_size, ID3DBlob **blob)
> }
> return hr;
> }
> +
> +void vkd3d_utils_set_log_callback(PFN_vkd3d_log callback)
> +{
> + vkd3d_set_log_callback(callback);
> + vkd3d_dbg_set_log_callback(callback);
> +}
June 2, 2022
Re: [PATCH vkd3d 2/3] vkd3d: Allow writing log output via a custom callback.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Il 02/06/22 02:01, Zebediah Figura ha scritto:
> When using PE vkd3d through Wine, debug output may be swallowed by writing to
> Win32 stderr. Avoid this by providing a way to hook up vkd3d log output to Wine
> output.
>
> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
> ---
> include/vkd3d.h | 17 +++++++++++++++++
> libs/vkd3d/vkd3d.map | 1 +
> libs/vkd3d/vkd3d_main.c | 6 ++++++
> 3 files changed, 24 insertions(+)
>
> diff --git a/include/vkd3d.h b/include/vkd3d.h
> index bce3c6e4b..f3c3fdc68 100644
> --- a/include/vkd3d.h
> +++ b/include/vkd3d.h
> @@ -212,6 +212,20 @@ VKD3D_API HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED
> VKD3D_API HRESULT vkd3d_create_versioned_root_signature_deserializer(const void *data, SIZE_T data_size,
> REFIID iid, void **deserializer);
>
> +/**
> + * Set a callback to be called when vkd3d outputs debug logging.
> + *
> + * If NULL, or if this function has not been called, libvkd3d will print all
> + * enabled log output to stderr.
> + *
> + * Calling this function will also set the log callback for libvkd3d-shader.
> + *
> + * \param callback Callback function to set.
> + *
> + * \since 1.4
> + */
> +VKD3D_API void vkd3d_set_log_callback(PFN_vkd3d_log callback);
> +
> #endif /* VKD3D_NO_PROTOTYPES */
>
> /*
> @@ -255,6 +269,9 @@ typedef HRESULT (*PFN_vkd3d_serialize_versioned_root_signature)(const D3D12_VERS
> typedef HRESULT (*PFN_vkd3d_create_versioned_root_signature_deserializer)(const void *data, SIZE_T data_size,
> REFIID iid, void **deserializer);
>
> +/** Type of vkd3d_set_log_callback(). \since 1.4 */
> +typedef void (*PFN_vkd3d_set_log_callback)(PFN_vkd3d_log callback);
> +
> #ifdef __cplusplus
> }
> #endif /* __cplusplus */
> diff --git a/libs/vkd3d/vkd3d.map b/libs/vkd3d/vkd3d.map
> index 6f1f37611..441b2e35b 100644
> --- a/libs/vkd3d/vkd3d.map
> +++ b/libs/vkd3d/vkd3d.map
> @@ -22,6 +22,7 @@ global:
> vkd3d_resource_incref;
> vkd3d_serialize_root_signature;
> vkd3d_serialize_versioned_root_signature;
> + vkd3d_set_log_callback;
>
> local: *;
> };
> diff --git a/libs/vkd3d/vkd3d_main.c b/libs/vkd3d/vkd3d_main.c
> index 21d998bf9..88301fbb3 100644
> --- a/libs/vkd3d/vkd3d_main.c
> +++ b/libs/vkd3d/vkd3d_main.c
> @@ -510,3 +510,9 @@ HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED_ROOT_SIGN
> }
> return hr;
> }
> +
> +void vkd3d_set_log_callback(PFN_vkd3d_log callback)
> +{
> + vkd3d_shader_set_log_callback(callback);
> + vkd3d_dbg_set_log_callback(callback);
> +}
June 2, 2022
Re: [PATCH vkd3d 1/3] vkd3d-shader: Allow writing log output via a custom callback.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Il 02/06/22 02:01, Zebediah Figura ha scritto:
> When using PE vkd3d through Wine, debug output may be swallowed by writing to
> Win32 stderr. Avoid this by providing a way to hook up vkd3d log output to Wine
> output.
>
> Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
> ---
> include/private/vkd3d_debug.h | 1 +
> include/vkd3d_shader.h | 15 ++++++++++++++
> include/vkd3d_types.h | 4 ++++
> libs/vkd3d-common/debug.c | 28 +++++++++++++++++++++++++--
> libs/vkd3d-shader/vkd3d_shader.map | 1 +
> libs/vkd3d-shader/vkd3d_shader_main.c | 5 +++++
> 6 files changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/include/private/vkd3d_debug.h b/include/private/vkd3d_debug.h
> index 8ab653aef..579c33d36 100644
> --- a/include/private/vkd3d_debug.h
> +++ b/include/private/vkd3d_debug.h
> @@ -47,6 +47,7 @@ enum vkd3d_dbg_level
> enum vkd3d_dbg_level vkd3d_dbg_get_level(void);
>
> void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4);
> +void vkd3d_dbg_set_log_callback(PFN_vkd3d_log callback);
>
> const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2);
> const char *vkd3d_dbg_vsprintf(const char *fmt, va_list args);
> diff --git a/include/vkd3d_shader.h b/include/vkd3d_shader.h
> index 05d235f9d..1e5a332ef 100644
> --- a/include/vkd3d_shader.h
> +++ b/include/vkd3d_shader.h
> @@ -1806,6 +1806,18 @@ VKD3D_SHADER_API void vkd3d_shader_free_shader_signature(struct vkd3d_shader_sig
> VKD3D_SHADER_API int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info,
> struct vkd3d_shader_code *out, char **messages);
>
> +/**
> + * Set a callback to be called when vkd3d-shader outputs debug logging.
> + *
> + * If NULL, or if this function has not been called, libvkd3d-shader will print
> + * all enabled log output to stderr.
> + *
> + * \param callback Callback function to set.
> + *
> + * \since 1.4
> + */
> +VKD3D_SHADER_API void vkd3d_shader_set_log_callback(PFN_vkd3d_log callback);
> +
> #endif /* VKD3D_SHADER_NO_PROTOTYPES */
>
> /** Type of vkd3d_shader_get_version(). */
> @@ -1859,6 +1871,9 @@ typedef void (*PFN_vkd3d_shader_free_shader_signature)(struct vkd3d_shader_signa
> typedef void (*PFN_vkd3d_shader_preprocess)(struct vkd3d_shader_compile_info *compile_info,
> struct vkd3d_shader_code *out, char **messages);
>
> +/** Type of vkd3d_shader_set_log_callback(). \since 1.4 */
> +typedef void (*PFN_vkd3d_shader_set_log_callback)(PFN_vkd3d_log callback);
> +
> #ifdef __cplusplus
> }
> #endif /* __cplusplus */
> diff --git a/include/vkd3d_types.h b/include/vkd3d_types.h
> index 7014f4c25..4a7aca236 100644
> --- a/include/vkd3d_types.h
> +++ b/include/vkd3d_types.h
> @@ -19,6 +19,8 @@
> #ifndef __VKD3D_TYPES_H
> #define __VKD3D_TYPES_H
>
> +#include <stdarg.h>
> +
> #ifdef __cplusplus
> extern "C" {
> #endif /* __cplusplus */
> @@ -53,6 +55,8 @@ enum vkd3d_result
> VKD3D_FORCE_32_BIT_ENUM(VKD3D_RESULT),
> };
>
> +typedef void (*PFN_vkd3d_log)(const char *format, va_list args);
> +
> #ifdef _WIN32
> # define VKD3D_IMPORT __declspec(dllimport)
> # define VKD3D_EXPORT __declspec(dllexport)
> diff --git a/libs/vkd3d-common/debug.c b/libs/vkd3d-common/debug.c
> index 4868f3fba..0b9e765ac 100644
> --- a/libs/vkd3d-common/debug.c
> +++ b/libs/vkd3d-common/debug.c
> @@ -68,6 +68,25 @@ enum vkd3d_dbg_level vkd3d_dbg_get_level(void)
> return level;
> }
>
> +static PFN_vkd3d_log log_callback;
> +
> +static void vkd3d_dbg_voutput(const char *fmt, va_list args)
> +{
> + if (log_callback)
> + log_callback(fmt, args);
> + else
> + vfprintf(stderr, fmt, args);
> +}
> +
> +static void vkd3d_dbg_output(const char *fmt, ...)
> +{
> + va_list args;
> +
> + va_start(args, fmt);
> + vkd3d_dbg_voutput(fmt, args);
> + va_end(args);
> +}
> +
> void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...)
> {
> va_list args;
> @@ -77,12 +96,17 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const ch
>
> assert(level < ARRAY_SIZE(debug_level_names));
>
> - fprintf(stderr, "%s:%s: ", debug_level_names[level], function);
> + vkd3d_dbg_output("%s:%s ", debug_level_names[level], function);
> va_start(args, fmt);
> - vfprintf(stderr, fmt, args);
> + vkd3d_dbg_voutput(fmt, args);
> va_end(args);
> }
>
> +void vkd3d_dbg_set_log_callback(PFN_vkd3d_log callback)
> +{
> + log_callback = callback;
> +}
> +
> static char *get_buffer(void)
> {
> static char buffers[VKD3D_DEBUG_BUFFER_COUNT][VKD3D_DEBUG_BUFFER_SIZE];
> diff --git a/libs/vkd3d-shader/vkd3d_shader.map b/libs/vkd3d-shader/vkd3d_shader.map
> index 2e49fe248..cac96972a 100644
> --- a/libs/vkd3d-shader/vkd3d_shader.map
> +++ b/libs/vkd3d-shader/vkd3d_shader.map
> @@ -17,6 +17,7 @@ global:
> vkd3d_shader_preprocess;
> vkd3d_shader_scan;
> vkd3d_shader_serialize_root_signature;
> + vkd3d_shader_set_log_callback;
>
> local: *;
> };
> diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c
> index 6fd32435a..7d0157fca 100644
> --- a/libs/vkd3d-shader/vkd3d_shader_main.c
> +++ b/libs/vkd3d-shader/vkd3d_shader_main.c
> @@ -1550,3 +1550,8 @@ int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_info *compile_info
> vkd3d_shader_message_context_cleanup(&message_context);
> return ret;
> }
> +
> +void vkd3d_shader_set_log_callback(PFN_vkd3d_log callback)
> +{
> + vkd3d_dbg_set_log_callback(callback);
> +}
June 2, 2022
Re: [PATCH vkd3d 3/3] vkd3d-utils: Allow writing log output via a custom callback.
by Zebediah Figura
On 6/2/22 10:04, Giovanni Mascellani wrote:
> Hi,
>
> Il 02/06/22 02:01, Zebediah Figura ha scritto:
>> + * Calling this function will also set the log callback for libvkd3d and
>> + * libvkd3d-shader.
>
> What's the reasoning behind the order in which log callbacks call each
> other? I.e., why, for example, libvkd3d-utils sets libvkd3d and not the
> other way around?
The libraries use one-way dependency chains, and the callbacks reflect
that. libvkd3d-utils depends on libvkd3d and libvkd3d-shader; libvkd3d
depends only on libvkd3d-shader; libvkd3d-shader is standalone.
libvkd3d-utils is not a utility library for libvkd3d, but a wrapper
library to provide direct d3d12 entry points for the libvkd3d and
libvkd3d-shader functions not otherwise exposed as d3d12 APIs. It also
provides a few default callback functions meant to be used with libvkd3d
APIs.
June 2, 2022
Re: [PATCH vkd3d 3/3] vkd3d-utils: Allow writing log output via a custom callback.
by Giovanni Mascellani
Hi,
Il 02/06/22 02:01, Zebediah Figura ha scritto:
> + * Calling this function will also set the log callback for libvkd3d and
> + * libvkd3d-shader.
What's the reasoning behind the order in which log callbacks call each
other? I.e., why, for example, libvkd3d-utils sets libvkd3d and not the
other way around?
Thanks, Giovanni.
June 2, 2022
[PATCH vkd3d v3 7/7] vkd3d-shader/hlsl: Parse the mul() intrinsic.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
---
libs/vkd3d-shader/hlsl.y | 118 ++++++++++++++++++++++++
tests/hlsl-majority-pragma.shader_test | 2 +-
tests/hlsl-majority-typedef.shader_test | 2 +-
tests/hlsl-mul.shader_test | 36 ++++----
4 files changed, 138 insertions(+), 20 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 2aee5153..df5fda47 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -2046,6 +2046,123 @@ static bool intrinsic_min(struct hlsl_ctx *ctx,
return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, params->args[0], params->args[1], loc);
}
+static bool intrinsic_mul(struct hlsl_ctx *ctx,
+ const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
+{
+ struct hlsl_ir_node *arg1 = params->args[0], *arg2 = params->args[1], *cast1, *cast2;
+ enum hlsl_base_type base = expr_common_base_type(arg1->data_type->base_type, arg2->data_type->base_type);
+ struct hlsl_type *cast_type1 = arg1->data_type, *cast_type2 = arg2->data_type, *matrix_type, *ret_type;
+ unsigned int i, j, k, vect_count = 0;
+ struct vkd3d_string_buffer *name;
+ static unsigned int counter = 0;
+ struct hlsl_ir_load *load;
+ struct hlsl_ir_var *var;
+
+ if (arg1->data_type->type == HLSL_CLASS_SCALAR || arg2->data_type->type == HLSL_CLASS_SCALAR)
+ return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, arg1, arg2, loc);
+
+ if (arg1->data_type->type == HLSL_CLASS_VECTOR)
+ {
+ vect_count++;
+ cast_type1 = hlsl_get_matrix_type(ctx, base, arg1->data_type->dimx, 1);
+ }
+ if (arg2->data_type->type == HLSL_CLASS_VECTOR)
+ {
+ vect_count++;
+ cast_type2 = hlsl_get_matrix_type(ctx, base, 1, arg2->data_type->dimx);
+ }
+
+ matrix_type = hlsl_get_matrix_type(ctx, base, cast_type2->dimx, cast_type1->dimy);
+
+ if (vect_count == 0)
+ {
+ ret_type = matrix_type;
+ }
+ else if (vect_count == 1)
+ {
+ assert(matrix_type->dimx == 1 || matrix_type->dimy == 1);
+ ret_type = hlsl_get_vector_type(ctx, base, matrix_type->dimx * matrix_type->dimy);
+ }
+ else
+ {
+ assert(matrix_type->dimx == 1 && matrix_type->dimy == 1);
+ ret_type = hlsl_get_scalar_type(ctx, base);
+ }
+
+ if (!(cast1 = add_implicit_conversion(ctx, params->instrs, arg1, cast_type1, loc)))
+ return false;
+
+ if (!(cast2 = add_implicit_conversion(ctx, params->instrs, arg2, cast_type2, loc)))
+ return false;
+
+ name = vkd3d_string_buffer_get(&ctx->string_buffers);
+ vkd3d_string_buffer_printf(name, "<mul-%u>", counter++);
+ var = hlsl_new_synthetic_var(ctx, name->buffer, matrix_type, *loc);
+ vkd3d_string_buffer_release(&ctx->string_buffers, name);
+ if (!var)
+ return false;
+
+ for (i = 0; i < matrix_type->dimx; ++i)
+ for (j = 0; j < matrix_type->dimy; ++j)
+ {
+ struct hlsl_ir_node *node = NULL;
+ struct hlsl_type *scalar_type;
+ struct hlsl_ir_store *store;
+ struct hlsl_ir_constant *c;
+ unsigned int offset;
+
+ for (k = 0; k < cast_type1->dimx && k < cast_type2->dimy; ++k)
+ {
+ struct hlsl_ir_load *value1, *value2;
+ struct hlsl_ir_node *mul;
+
+ offset = hlsl_compute_component_offset(ctx, cast_type1, j * cast_type1->dimx + k, &scalar_type);
+ if (!(c = hlsl_new_uint_constant(ctx, offset, loc)))
+ return false;
+ list_add_tail(params->instrs, &c->node.entry);
+
+ if (!(value1 = add_load(ctx, params->instrs, cast1, &c->node, scalar_type, *loc)))
+ return false;
+
+ offset = hlsl_compute_component_offset(ctx, cast_type2, k * cast_type2->dimx + i, &scalar_type);
+ if (!(c = hlsl_new_uint_constant(ctx, offset, loc)))
+ return false;
+ list_add_tail(params->instrs, &c->node.entry);
+
+ if (!(value2 = add_load(ctx, params->instrs, cast2, &c->node, scalar_type, *loc)))
+ return false;
+
+ if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, &value1->node, &value2->node, loc)))
+ return false;
+
+ if (node)
+ {
+ if (!(node = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, node, mul, loc)))
+ return false;
+ }
+ else
+ {
+ node = mul;
+ }
+ }
+
+ offset = hlsl_compute_component_offset(ctx, matrix_type, j * matrix_type->dimx + i, &scalar_type);
+ if (!(c = hlsl_new_uint_constant(ctx, offset, loc)))
+ return false;
+ list_add_tail(params->instrs, &c->node.entry);
+
+ if (!(store = hlsl_new_store(ctx, var, &c->node, node, 0, *loc)))
+ return false;
+ list_add_tail(params->instrs, &store->node.entry);
+ }
+
+ if (!(load = hlsl_new_load(ctx, var, NULL, matrix_type, *loc)))
+ return false;
+ list_add_tail(params->instrs, &load->node.entry);
+
+ return !!add_implicit_conversion(ctx, params->instrs, &load->node, ret_type, loc);
+}
+
static bool intrinsic_pow(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
@@ -2106,6 +2223,7 @@ intrinsic_functions[] =
{"floor", 1, true, intrinsic_floor},
{"max", 2, true, intrinsic_max},
{"min", 2, true, intrinsic_min},
+ {"mul", 2, true, intrinsic_mul},
{"pow", 2, true, intrinsic_pow},
{"round", 1, true, intrinsic_round},
{"saturate", 1, true, intrinsic_saturate},
diff --git a/tests/hlsl-majority-pragma.shader_test b/tests/hlsl-majority-pragma.shader_test
index a9f917ff..e7fc75cd 100644
--- a/tests/hlsl-majority-pragma.shader_test
+++ b/tests/hlsl-majority-pragma.shader_test
@@ -17,5 +17,5 @@ uniform 0 float4 0.1 0.2 0.0 0.0
uniform 4 float4 0.3 0.4 0.0 0.0
uniform 8 float4 0.1 0.3 0.0 0.0
uniform 12 float4 0.2 0.4 0.0 0.0
-todo draw quad
+draw quad
probe all rgba (0.17, 0.39, 0.17, 0.39) 1
diff --git a/tests/hlsl-majority-typedef.shader_test b/tests/hlsl-majority-typedef.shader_test
index 192c96db..1460e9a0 100644
--- a/tests/hlsl-majority-typedef.shader_test
+++ b/tests/hlsl-majority-typedef.shader_test
@@ -18,5 +18,5 @@ uniform 0 float4 0.1 0.2 0.0 0.0
uniform 4 float4 0.3 0.4 0.0 0.0
uniform 8 float4 0.1 0.3 0.0 0.0
uniform 12 float4 0.2 0.4 0.0 0.0
-todo draw quad
+draw quad
probe all rgba (0.17, 0.39, 0.17, 0.39) 1
diff --git a/tests/hlsl-mul.shader_test b/tests/hlsl-mul.shader_test
index 1d137e69..7b453187 100644
--- a/tests/hlsl-mul.shader_test
+++ b/tests/hlsl-mul.shader_test
@@ -12,7 +12,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (30.0, 70.0, 110.0, 150.0)
[pixel shader]
@@ -28,7 +28,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (90.0, 100.0, 110.0, 120.0)
[pixel shader]
@@ -44,7 +44,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (14.0, 38.0, 62.0, 86.0)
[pixel shader]
@@ -60,7 +60,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (38.0, 44.0, 50.0, 56.0)
[pixel shader]
@@ -75,7 +75,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (14.0, 32.0, 50.0, 0.0)
[pixel shader]
@@ -90,7 +90,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (30.0, 36.0, 42.0, 0.0)
[pixel shader]
@@ -106,7 +106,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (50.0, 60.0, 70.0, 80.0)
[pixel shader]
@@ -122,7 +122,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (50.0, 60.0, 70.0, 80.0)
[pixel shader]
@@ -138,7 +138,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (10.0, 20.0, 30.0, 40.0)
[pixel shader]
@@ -154,7 +154,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (10.0, 50.0, 90.0, 130.0)
[pixel shader]
@@ -170,7 +170,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (10.0, 20.0, 30.0, 40.0)
[pixel shader]
@@ -186,7 +186,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (10.0, 50.0, 90.0, 130.0)
[pixel shader]
@@ -202,7 +202,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (90.0, 100.0, 110.0, 120.0)
[pixel shader]
@@ -218,7 +218,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (5.0, 10.0, 15.0, 20.0)
[pixel shader]
@@ -234,7 +234,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -250,7 +250,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (30.0, 70.0, 110.0, 150.0)
[pixel shader]
@@ -268,7 +268,7 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (83.0, 98.0, 113.0, 128.0)
[pixel shader]
@@ -286,5 +286,5 @@ float4 main(float4 pos : sv_position) : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (78.0, 96.0, 114.0, 0.0)
--
2.36.1
June 2, 2022
[PATCH vkd3d v3 6/7] vkd3d-shader/hlsl: Split matrix operations.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
---
libs/vkd3d-shader/hlsl.y | 74 ++++++++++++++++++++++++++++++++++++
tests/hlsl-shape.shader_test | 30 +++++++--------
2 files changed, 89 insertions(+), 15 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 687569e8..2aee5153 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -1201,6 +1201,22 @@ static bool expr_common_shape(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct
return true;
}
+static unsigned int minor_size(const struct hlsl_type *type)
+{
+ if (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)
+ return type->dimx;
+ else
+ return type->dimy;
+}
+
+static unsigned int major_size(const struct hlsl_type *type)
+{
+ if (type->modifiers & HLSL_MODIFIER_ROW_MAJOR)
+ return type->dimy;
+ else
+ return type->dimx;
+}
+
static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS],
struct hlsl_type *type, const struct vkd3d_shader_location *loc)
@@ -1208,6 +1224,64 @@ static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
struct hlsl_ir_expr *expr;
unsigned int i;
+ if (type->type == HLSL_CLASS_MATRIX)
+ {
+ struct vkd3d_string_buffer *name;
+ static unsigned int counter = 0;
+ struct hlsl_type *vector_type;
+ struct hlsl_ir_load *load;
+ struct hlsl_ir_var *var;
+
+ vector_type = hlsl_get_vector_type(ctx, type->base_type, minor_size(type));
+
+ name = vkd3d_string_buffer_get(&ctx->string_buffers);
+ vkd3d_string_buffer_printf(name, "<split_op-%u>", counter++);
+ var = hlsl_new_synthetic_var(ctx, name->buffer, type, *loc);
+ vkd3d_string_buffer_release(&ctx->string_buffers, name);
+ if (!var)
+ return NULL;
+
+ for (i = 0; i < major_size(type); i++)
+ {
+ struct hlsl_ir_node *value, *vector_operands[HLSL_MAX_OPERANDS] = { NULL };
+ struct hlsl_ir_store *store;
+ struct hlsl_ir_constant *c;
+ unsigned int j;
+
+ if (!(c = hlsl_new_uint_constant(ctx, 4 * i, loc)))
+ return NULL;
+ list_add_tail(instrs, &c->node.entry);
+
+ for (j = 0; j < HLSL_MAX_OPERANDS; j++)
+ {
+ if (operands[j])
+ {
+ struct hlsl_type *vector_arg_type;
+ struct hlsl_ir_load *load;
+
+ vector_arg_type = hlsl_get_vector_type(ctx, operands[j]->data_type->base_type, minor_size(type));
+
+ if (!(load = add_load(ctx, instrs, operands[j], &c->node, vector_arg_type, *loc)))
+ return NULL;
+ vector_operands[j] = &load->node;
+ }
+ }
+
+ if (!(value = add_expr(ctx, instrs, op, vector_operands, vector_type, loc)))
+ return NULL;
+
+ if (!(store = hlsl_new_store(ctx, var, &c->node, value, 0, *loc)))
+ return NULL;
+ list_add_tail(instrs, &store->node.entry);
+ }
+
+ if (!(load = hlsl_new_load(ctx, var, NULL, type, *loc)))
+ return NULL;
+ list_add_tail(instrs, &load->node.entry);
+
+ return &load->node;
+ }
+
if (!(expr = hlsl_alloc(ctx, sizeof(*expr))))
return NULL;
init_node(&expr->node, HLSL_IR_EXPR, type, *loc);
diff --git a/tests/hlsl-shape.shader_test b/tests/hlsl-shape.shader_test
index 65cc322c..b96f0fd2 100644
--- a/tests/hlsl-shape.shader_test
+++ b/tests/hlsl-shape.shader_test
@@ -93,7 +93,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 7.0, 9.0)
[pixel shader]
@@ -107,7 +107,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 7.0, 9.0)
[pixel shader]
@@ -122,7 +122,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -137,7 +137,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -152,7 +152,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 7.0, 12.0, 17.0)
[pixel shader]
@@ -167,7 +167,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 7.0, 12.0, 17.0)
[pixel shader]
@@ -183,7 +183,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 0.0)
[pixel shader]
@@ -199,7 +199,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (9.0, 11.0, 13.0, 0.0)
[pixel shader]
@@ -223,7 +223,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -247,7 +247,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -273,7 +273,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -285,7 +285,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 3.0, 4.0, 5.0)
[pixel shader]
@@ -297,7 +297,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 3.0, 4.0, 5.0)
[pixel shader]
@@ -336,7 +336,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 3.0, 4.0, 5.0)
[pixel shader]
@@ -351,5 +351,5 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (6.0, 7.0, 8.0, 9.0)
--
2.36.1
June 2, 2022
[PATCH vkd3d v3 5/7] vkd3d-shader/hlsl: Have add_expr() return hlsl_ir_node*.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Zebediah Figura <zfigura(a)codeweavers.com>
---
libs/vkd3d-shader/hlsl.y | 54 +++++++++++++++++-----------------------
1 file changed, 23 insertions(+), 31 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index f85d4252..687569e8 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -674,7 +674,7 @@ static bool add_record_load(struct hlsl_ctx *ctx, struct list *instrs, struct hl
return !!add_load(ctx, instrs, record, &c->node, field->type, loc);
}
-static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
const struct vkd3d_shader_location *loc);
@@ -682,8 +682,7 @@ static struct hlsl_ir_node *add_matrix_scalar_load(struct hlsl_ctx *ctx, struct
struct hlsl_ir_node *matrix, struct hlsl_ir_node *x, struct hlsl_ir_node *y,
const struct vkd3d_shader_location *loc)
{
- struct hlsl_ir_node *major, *minor;
- struct hlsl_ir_expr *mul, *add;
+ struct hlsl_ir_node *major, *minor, *mul, *add;
struct hlsl_ir_constant *four;
struct hlsl_ir_load *load;
struct hlsl_type *type = matrix->data_type, *scalar_type;
@@ -708,10 +707,10 @@ static struct hlsl_ir_node *add_matrix_scalar_load(struct hlsl_ctx *ctx, struct
if (!(mul = add_binary_arithmetic_expr(ctx, instrs, HLSL_OP2_MUL, &four->node, major, loc)))
return NULL;
- if (!(add = add_binary_arithmetic_expr(ctx, instrs, HLSL_OP2_ADD, &mul->node, minor, loc)))
+ if (!(add = add_binary_arithmetic_expr(ctx, instrs, HLSL_OP2_ADD, mul, minor, loc)))
return NULL;
- if (!(load = add_load(ctx, instrs, matrix, &add->node, scalar_type, *loc)))
+ if (!(load = add_load(ctx, instrs, matrix, add, scalar_type, *loc)))
return NULL;
return &load->node;
@@ -1202,7 +1201,7 @@ static bool expr_common_shape(struct hlsl_ctx *ctx, struct hlsl_type *t1, struct
return true;
}
-static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *operands[HLSL_MAX_OPERANDS],
struct hlsl_type *type, const struct vkd3d_shader_location *loc)
{
@@ -1217,7 +1216,7 @@ static struct hlsl_ir_expr *add_expr(struct hlsl_ctx *ctx, struct list *instrs,
hlsl_src_from_node(&expr->operands[i], operands[i]);
list_add_tail(instrs, &expr->node.entry);
- return expr;
+ return &expr->node;
}
static void check_integer_type(struct hlsl_ctx *ctx, const struct hlsl_ir_node *instr)
@@ -1241,7 +1240,7 @@ static void check_integer_type(struct hlsl_ctx *ctx, const struct hlsl_ir_node *
}
}
-static struct hlsl_ir_expr *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {arg};
@@ -1249,7 +1248,7 @@ static struct hlsl_ir_expr *add_unary_arithmetic_expr(struct hlsl_ctx *ctx, stru
return add_expr(ctx, instrs, op, args, arg->data_type, loc);
}
-static struct hlsl_ir_expr *add_unary_bitwise_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_unary_bitwise_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc)
{
check_integer_type(ctx, arg);
@@ -1257,7 +1256,7 @@ static struct hlsl_ir_expr *add_unary_bitwise_expr(struct hlsl_ctx *ctx, struct
return add_unary_arithmetic_expr(ctx, instrs, op, arg, loc);
}
-static struct hlsl_ir_expr *add_unary_logical_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_unary_logical_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg, const struct vkd3d_shader_location *loc)
{
struct hlsl_ir_node *args[HLSL_MAX_OPERANDS] = {0};
@@ -1272,7 +1271,7 @@ static struct hlsl_ir_expr *add_unary_logical_expr(struct hlsl_ctx *ctx, struct
return add_expr(ctx, instrs, op, args, bool_type, loc);
}
-static struct hlsl_ir_expr *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_binary_arithmetic_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
const struct vkd3d_shader_location *loc)
{
@@ -1307,7 +1306,7 @@ static struct list *add_binary_arithmetic_expr_merge(struct hlsl_ctx *ctx, struc
return list1;
}
-static struct hlsl_ir_expr *add_binary_bitwise_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_binary_bitwise_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
const struct vkd3d_shader_location *loc)
{
@@ -1329,7 +1328,7 @@ static struct list *add_binary_bitwise_expr_merge(struct hlsl_ctx *ctx, struct l
return list1;
}
-static struct hlsl_ir_expr *add_binary_comparison_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_binary_comparison_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
struct vkd3d_shader_location *loc)
{
@@ -1365,7 +1364,7 @@ static struct list *add_binary_comparison_expr_merge(struct hlsl_ctx *ctx, struc
return list1;
}
-static struct hlsl_ir_expr *add_binary_logical_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_binary_logical_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
const struct vkd3d_shader_location *loc)
{
@@ -1400,7 +1399,7 @@ static struct list *add_binary_logical_expr_merge(struct hlsl_ctx *ctx, struct l
return list1;
}
-static struct hlsl_ir_expr *add_binary_shift_expr(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_binary_shift_expr(struct hlsl_ctx *ctx, struct list *instrs,
enum hlsl_ir_expr_op op, struct hlsl_ir_node *arg1, struct hlsl_ir_node *arg2,
const struct vkd3d_shader_location *loc)
{
@@ -1509,22 +1508,17 @@ static struct hlsl_ir_node *add_assignment(struct hlsl_ctx *ctx, struct list *in
if (assign_op == ASSIGN_OP_SUB)
{
- struct hlsl_ir_expr *expr;
-
- if (!(expr = add_unary_arithmetic_expr(ctx, instrs, HLSL_OP1_NEG, rhs, &rhs->loc)))
+ if (!(rhs = add_unary_arithmetic_expr(ctx, instrs, HLSL_OP1_NEG, rhs, &rhs->loc)))
return NULL;
- rhs = &expr->node;
assign_op = ASSIGN_OP_ADD;
}
if (assign_op != ASSIGN_OP_ASSIGN)
{
enum hlsl_ir_expr_op op = op_from_assignment(assign_op);
- struct hlsl_ir_expr *expr;
assert(op);
- if (!(expr = add_binary_arithmetic_expr(ctx, instrs, op, lhs, rhs, &rhs->loc)))
+ if (!(rhs = add_binary_arithmetic_expr(ctx, instrs, op, lhs, rhs, &rhs->loc)))
return NULL;
- rhs = &expr->node;
}
if (lhs_type->type <= HLSL_CLASS_LAST_NUMERIC)
@@ -1894,12 +1888,12 @@ static bool intrinsic_abs(struct hlsl_ctx *ctx,
static bool intrinsic_clamp(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
- struct hlsl_ir_expr *max;
+ struct hlsl_ir_node *max;
if (!(max = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MAX, params->args[0], params->args[1], loc)))
return false;
- return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, &max->node, params->args[2], loc);
+ return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MIN, max, params->args[2], loc);
}
static bool intrinsic_cross(struct hlsl_ctx *ctx,
@@ -1907,8 +1901,7 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx,
{
struct hlsl_ir_swizzle *arg1_swzl1, *arg1_swzl2, *arg2_swzl1, *arg2_swzl2;
struct hlsl_ir_node *arg1 = params->args[0], *arg2 = params->args[1];
- struct hlsl_ir_node *arg1_cast, *arg2_cast, *mul1_neg;
- struct hlsl_ir_expr *mul1, *mul2;
+ struct hlsl_ir_node *arg1_cast, *arg2_cast, *mul1_neg, *mul1, *mul2;
struct hlsl_type *cast_type;
enum hlsl_base_type base;
@@ -1937,7 +1930,7 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx,
&arg1_swzl1->node, &arg2_swzl1->node, loc)))
return false;
- if (!(mul1_neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, &mul1->node, *loc)))
+ if (!(mul1_neg = hlsl_new_unary_expr(ctx, HLSL_OP1_NEG, mul1, *loc)))
return false;
list_add_tail(params->instrs, &mul1_neg->entry);
@@ -1953,7 +1946,7 @@ static bool intrinsic_cross(struct hlsl_ctx *ctx,
&arg1_swzl2->node, &arg2_swzl2->node, loc)))
return false;
- return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, &mul2->node, mul1_neg, loc);
+ return !!add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_ADD, mul2, mul1_neg, loc);
}
static bool intrinsic_floor(struct hlsl_ctx *ctx,
@@ -1982,8 +1975,7 @@ static bool intrinsic_min(struct hlsl_ctx *ctx,
static bool intrinsic_pow(struct hlsl_ctx *ctx,
const struct parse_initializer *params, const struct vkd3d_shader_location *loc)
{
- struct hlsl_ir_node *log, *exp, *arg;
- struct hlsl_ir_expr *mul;
+ struct hlsl_ir_node *log, *exp, *arg, *mul;
if (!(arg = intrinsic_float_convert_arg(ctx, params, params->args[0], loc)))
return false;
@@ -1995,7 +1987,7 @@ static bool intrinsic_pow(struct hlsl_ctx *ctx,
if (!(mul = add_binary_arithmetic_expr(ctx, params->instrs, HLSL_OP2_MUL, params->args[1], log, loc)))
return false;
- if (!(exp = hlsl_new_unary_expr(ctx, HLSL_OP1_EXP2, &mul->node, *loc)))
+ if (!(exp = hlsl_new_unary_expr(ctx, HLSL_OP1_EXP2, mul, *loc)))
return false;
list_add_tail(params->instrs, &exp->entry);
return true;
--
2.36.1
June 2, 2022
[PATCH vkd3d v3 4/7] vkd3d-shader/hlsl: Lower matrix casts.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
---
I had to add a forward declaration for add_load(). I don't know if in
cases like that it is preferred to add a forward declaration (which adds
cruft) or move the definition backwards (which break the vague logical
order functions have).
---
libs/vkd3d-shader/hlsl.y | 93 ++++++++++++++++++-
tests/hlsl-duplicate-modifiers.shader_test | 2 +-
tests/hlsl-initializer-matrix.shader_test | 2 +-
...lsl-return-implicit-conversion.shader_test | 10 +-
tests/hlsl-shape.shader_test | 10 +-
tests/matrix-semantics.shader_test | 20 ++--
6 files changed, 111 insertions(+), 26 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index 23c48cdc..f85d4252 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -266,6 +266,9 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ
return false;
}
+static struct hlsl_ir_load *add_load(struct hlsl_ctx *ctx, struct list *instrs, struct hlsl_ir_node *var_node,
+ struct hlsl_ir_node *offset, struct hlsl_type *data_type, const struct vkd3d_shader_location loc);
+
static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
{
@@ -275,10 +278,92 @@ static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
if (hlsl_types_are_equal(src_type, dst_type))
return node;
- if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc)))
- return NULL;
- list_add_tail(instrs, &cast->node.entry);
- return &cast->node;
+ if ((src_type->type == HLSL_CLASS_MATRIX || dst_type->type == HLSL_CLASS_MATRIX)
+ && src_type->type <= HLSL_CLASS_LAST_NUMERIC && dst_type->type <= HLSL_CLASS_LAST_NUMERIC)
+ {
+ struct vkd3d_string_buffer *name;
+ static unsigned int counter = 0;
+ struct hlsl_ir_load *load;
+ struct hlsl_ir_var *var;
+ unsigned int dst_idx;
+ bool broadcast;
+
+ broadcast = src_type->dimx == 1 && src_type->dimy == 1;
+ assert(dst_type->dimx * dst_type->dimy <= src_type->dimx * src_type->dimy || broadcast);
+ if (src_type->type == HLSL_CLASS_MATRIX && dst_type->type == HLSL_CLASS_MATRIX && !broadcast)
+ {
+ assert(dst_type->dimx <= src_type->dimx);
+ assert(dst_type->dimy <= src_type->dimy);
+ }
+
+ name = vkd3d_string_buffer_get(&ctx->string_buffers);
+ vkd3d_string_buffer_printf(name, "<cast-%u>", counter++);
+ var = hlsl_new_synthetic_var(ctx, name->buffer, dst_type, *loc);
+ vkd3d_string_buffer_release(&ctx->string_buffers, name);
+ if (!var)
+ return NULL;
+
+ for (dst_idx = 0; dst_idx < dst_type->dimx * dst_type->dimy; ++dst_idx)
+ {
+ struct hlsl_type *src_scalar_type, *dst_scalar_type;
+ unsigned int src_idx, src_offset, dst_offset;
+ struct hlsl_ir_store *store;
+ struct hlsl_ir_constant *c;
+
+ if (broadcast)
+ {
+ src_idx = 0;
+ }
+ else
+ {
+ if (src_type->type == HLSL_CLASS_MATRIX && dst_type->type == HLSL_CLASS_MATRIX)
+ {
+ unsigned int x = dst_idx % dst_type->dimx, y = dst_idx / dst_type->dimx;
+
+ src_idx = y * src_type->dimx + x;
+ }
+ else
+ {
+ src_idx = dst_idx;
+ }
+ }
+
+ dst_offset = hlsl_compute_component_offset(ctx, dst_type, dst_idx, &dst_scalar_type);
+ src_offset = hlsl_compute_component_offset(ctx, src_type, src_idx, &src_scalar_type);
+
+ if (!(c = hlsl_new_uint_constant(ctx, src_offset, loc)))
+ return NULL;
+ list_add_tail(instrs, &c->node.entry);
+
+ if (!(load = add_load(ctx, instrs, node, &c->node, src_scalar_type, *loc)))
+ return NULL;
+
+ if (!(cast = hlsl_new_cast(ctx, &load->node, dst_scalar_type, loc)))
+ return NULL;
+ list_add_tail(instrs, &cast->node.entry);
+
+ if (!(c = hlsl_new_uint_constant(ctx, dst_offset, loc)))
+ return NULL;
+ list_add_tail(instrs, &c->node.entry);
+
+ if (!(store = hlsl_new_store(ctx, var, &c->node, &cast->node, 0, *loc)))
+ return NULL;
+ list_add_tail(instrs, &store->node.entry);
+ }
+
+ if (!(load = hlsl_new_load(ctx, var, NULL, dst_type, *loc)))
+ return NULL;
+ list_add_tail(instrs, &load->node.entry);
+
+ return &load->node;
+ }
+ else
+ {
+ if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc)))
+ return NULL;
+ list_add_tail(instrs, &cast->node.entry);
+ return &cast->node;
+ }
}
static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs,
diff --git a/tests/hlsl-duplicate-modifiers.shader_test b/tests/hlsl-duplicate-modifiers.shader_test
index fcae12da..6491701a 100644
--- a/tests/hlsl-duplicate-modifiers.shader_test
+++ b/tests/hlsl-duplicate-modifiers.shader_test
@@ -7,5 +7,5 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (0.1, 0.2, 0.3, 0.4)
diff --git a/tests/hlsl-initializer-matrix.shader_test b/tests/hlsl-initializer-matrix.shader_test
index ea9de9c0..7e12b0a0 100644
--- a/tests/hlsl-initializer-matrix.shader_test
+++ b/tests/hlsl-initializer-matrix.shader_test
@@ -55,7 +55,7 @@ float4 main() : SV_TARGET
}
[test]
-todo draw quad
+draw quad
probe all rgba (21, 22, 31, 32)
diff --git a/tests/hlsl-return-implicit-conversion.shader_test b/tests/hlsl-return-implicit-conversion.shader_test
index bf99d9cb..4fe8e7eb 100644
--- a/tests/hlsl-return-implicit-conversion.shader_test
+++ b/tests/hlsl-return-implicit-conversion.shader_test
@@ -5,7 +5,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (0.4, 0.3, 0.2, 0.1)
[pixel shader]
@@ -15,7 +15,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (0.4, 0.3, 0.2, 0.1)
[pixel shader]
@@ -25,7 +25,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (0.4, 0.3, 0.2, 0.1)
[pixel shader]
@@ -35,8 +35,8 @@ float4x1 main() : sv_target
}
[test]
-todo draw quad
-probe all rgba (0.4, 0.3, 0.2, 0.1)
+draw quad
+todo probe all rgba (0.4, 0.3, 0.2, 0.1)
[pixel shader]
float3 func()
diff --git a/tests/hlsl-shape.shader_test b/tests/hlsl-shape.shader_test
index 57d59534..65cc322c 100644
--- a/tests/hlsl-shape.shader_test
+++ b/tests/hlsl-shape.shader_test
@@ -211,7 +211,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -235,7 +235,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -260,7 +260,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 6.0, 8.0)
[pixel shader]
@@ -309,7 +309,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 0.0, 0.0)
[pixel shader]
@@ -321,7 +321,7 @@ float4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (2.0, 4.0, 0.0, 0.0)
[pixel shader]
diff --git a/tests/matrix-semantics.shader_test b/tests/matrix-semantics.shader_test
index 6a089683..d297b0d9 100644
--- a/tests/matrix-semantics.shader_test
+++ b/tests/matrix-semantics.shader_test
@@ -5,8 +5,8 @@ float4x1 main() : sv_target
}
[test]
-todo draw quad
-probe all rgba (1.0, 2.0, 3.0, 4.0)
+draw quad
+todo probe all rgba (1.0, 2.0, 3.0, 4.0)
[pixel shader]
row_major float1x4 main() : sv_target
@@ -15,7 +15,7 @@ row_major float1x4 main() : sv_target
}
[test]
-todo draw quad
+draw quad
probe all rgba (1.0, 2.0, 3.0, 4.0)
[require]
@@ -28,8 +28,8 @@ row_major float4x1 main() : sv_target
}
[test]
-todo draw quad
-probe all r (1.0)
+draw quad
+todo probe all r (1.0)
[pixel shader]
float1x4 main() : sv_target
@@ -38,8 +38,8 @@ float1x4 main() : sv_target
}
[test]
-todo draw quad
-probe all r (1.0)
+draw quad
+todo probe all r (1.0)
[pixel shader]
void main(out row_major float1x4 x : sv_target0, out float1x4 y : sv_target1)
@@ -49,7 +49,7 @@ void main(out row_major float1x4 x : sv_target0, out float1x4 y : sv_target1)
}
[test]
-todo draw quad
+draw quad
probe all rgba (1.0, 2.0, 3.0, 4.0)
[pixel shader fail todo]
@@ -67,5 +67,5 @@ void main(out float1x4 x : sv_target0, out float1x4 y : sv_target4)
}
[test]
-todo draw quad
-probe all r (1.0)
+draw quad
+todo probe all r (1.0)
--
2.36.1
June 2, 2022
[PATCH vkd3d v3 3/7] vkd3d-shader/hlsl: Introduce add_cast() helper.
by Giovanni Mascellani
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
---
There is another call to hlsl_new_cast() in hlsl.y that I didn't redirect
to add_cast(), because it doesn't require the upcoming matrix conversion
patch. I don't know if you want it to be redirected too.
v3:
* add back some mistakenly removed lines
---
libs/vkd3d-shader/hlsl.y | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.y b/libs/vkd3d-shader/hlsl.y
index faac562a..23c48cdc 100644
--- a/libs/vkd3d-shader/hlsl.y
+++ b/libs/vkd3d-shader/hlsl.y
@@ -266,7 +266,7 @@ static bool implicit_compatible_data_types(struct hlsl_type *t1, struct hlsl_typ
return false;
}
-static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs,
+static struct hlsl_ir_node *add_cast(struct hlsl_ctx *ctx, struct list *instrs,
struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
{
struct hlsl_type *src_type = node->data_type;
@@ -275,6 +275,17 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
if (hlsl_types_are_equal(src_type, dst_type))
return node;
+ if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc)))
+ return NULL;
+ list_add_tail(instrs, &cast->node.entry);
+ return &cast->node;
+}
+
+static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct list *instrs,
+ struct hlsl_ir_node *node, struct hlsl_type *dst_type, const struct vkd3d_shader_location *loc)
+{
+ struct hlsl_type *src_type = node->data_type;
+
if (!implicit_compatible_data_types(src_type, dst_type))
{
struct vkd3d_string_buffer *src_string, *dst_string;
@@ -293,10 +304,7 @@ static struct hlsl_ir_node *add_implicit_conversion(struct hlsl_ctx *ctx, struct
hlsl_warning(ctx, loc, VKD3D_SHADER_WARNING_HLSL_IMPLICIT_TRUNCATION, "Implicit truncation of %s type.",
src_type->type == HLSL_CLASS_VECTOR ? "vector" : "matrix");
- if (!(cast = hlsl_new_cast(ctx, node, dst_type, loc)))
- return NULL;
- list_add_tail(instrs, &cast->node.entry);
- return &cast->node;
+ return add_cast(ctx, instrs, node, dst_type, loc);
}
static DWORD add_modifiers(struct hlsl_ctx *ctx, DWORD modifiers, DWORD mod, const struct vkd3d_shader_location loc)
@@ -3718,7 +3726,6 @@ unary_expr:
{
struct hlsl_type *src_type = node_from_list($6)->data_type;
struct hlsl_type *dst_type;
- struct hlsl_ir_expr *cast;
unsigned int i;
if ($2)
@@ -3746,12 +3753,11 @@ unary_expr:
YYABORT;
}
- if (!(cast = hlsl_new_cast(ctx, node_from_list($6), dst_type, &@3)))
+ if (!add_cast(ctx, $6, node_from_list($6), dst_type, &@3))
{
hlsl_free_instr_list($6);
YYABORT;
}
- list_add_tail($6, &cast->node.entry);
$$ = $6;
}
--
2.36.1
June 2, 2022