Module: vkd3d
Branch: master
Commit: f5d1b5d263cda3c4db0195075733bb5eac30eb9d
URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/f5d1b5d263cda3c4db0195075733b…
Author: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Date: Wed Mar 13 13:09:51 2024 +0100
vkd3d-shader/ir: Move `break's out of selection constructs when possible.
---
libs/vkd3d-shader/ir.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/libs/vkd3d-shader/ir.c b/libs/vkd3d-shader/ir.c
index 9d5b7904..450f753c 100644
--- a/libs/vkd3d-shader/ir.c
+++ b/libs/vkd3d-shader/ir.c
@@ -4115,6 +4115,71 @@ static void vsir_cfg_remove_trailing_continue(struct vsir_cfg_structure_list *li
--list->count;
}
+static struct vsir_cfg_structure *vsir_cfg_get_trailing_break(struct vsir_cfg_structure_list *list)
+{
+ struct vsir_cfg_structure *structure;
+ size_t count = list->count;
+
+ if (count == 0)
+ return NULL;
+
+ structure = &list->structures[count - 1];
+
+ if (structure->type != STRUCTURE_TYPE_JUMP || structure->u.jump.type != JUMP_BREAK
+ || structure->u.jump.condition)
+ return NULL;
+
+ return structure;
+}
+
+/* When the last instruction in both branches of a selection construct
+ * is an unconditional break, any of them can be moved after the
+ * selection construct. If they break the same loop both of them can
+ * be moved out, otherwise we can choose which one: we choose the one
+ * that breaks the innermost loop, because we hope to eventually
+ * remove the loop itself.
+ *
+ * In principle a similar movement could be done when the last
+ * instructions are continue and continue, or continue and break. But
+ * in practice I don't think those situations can happen given the
+ * previous passes we do on the program, so we don't care. */
+static enum vkd3d_result vsir_cfg_move_breaks_out_of_selections(struct vsir_cfg_structure_list *list)
+{
+ struct vsir_cfg_structure *selection, *if_break, *else_break, *new_break;
+ unsigned int if_target, else_target, max_target;
+ size_t pos = list->count - 1;
+
+ selection = &list->structures[pos];
+ assert(selection->type == STRUCTURE_TYPE_SELECTION);
+
+ if_break = vsir_cfg_get_trailing_break(&selection->u.selection.if_body);
+ else_break = vsir_cfg_get_trailing_break(&selection->u.selection.else_body);
+
+ if (!if_break || !else_break)
+ return VKD3D_OK;
+
+ if_target = if_break->u.jump.target;
+ else_target = else_break->u.jump.target;
+ max_target = max(if_target, else_target);
+
+ if (!(new_break = vsir_cfg_structure_list_append(list, STRUCTURE_TYPE_JUMP)))
+ return VKD3D_ERROR_OUT_OF_MEMORY;
+ new_break->u.jump.type = JUMP_BREAK;
+ new_break->u.jump.target = max_target;
+
+ /* Pointer `selection' could have been invalidated by the append
+ * operation. */
+ selection = &list->structures[pos];
+ assert(selection->type == STRUCTURE_TYPE_SELECTION);
+
+ if (if_target == max_target)
+ --selection->u.selection.if_body.count;
+ if (else_target == max_target)
+ --selection->u.selection.else_body.count;
+
+ return VKD3D_OK;
+}
+
static enum vkd3d_result vsir_cfg_synthesize_selections(struct vsir_cfg_structure_list *list)
{
enum vkd3d_result ret;
@@ -4155,6 +4220,9 @@ static enum vkd3d_result vsir_cfg_synthesize_selections(struct vsir_cfg_structur
if ((ret = vsir_cfg_synthesize_selections(&structure->u.selection.else_body)) < 0)
return ret;
+ if ((ret = vsir_cfg_move_breaks_out_of_selections(list)) < 0)
+ return ret;
+
break;
}
Module: vkd3d
Branch: master
Commit: 285059ef11e4ce1e05a3ad1386f19706fc99ad74
URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/285059ef11e4ce1e05a3ad1386f19…
Author: Zebediah Figura <zfigura(a)codeweavers.com>
Date: Mon Feb 5 19:38:22 2024 -0600
vkd3d-shader/d3dbc: Consider the class in sm1_base_type().
We want the base type to stop being a property of all types, and to stop using
the same enumeration for objects and numeric types. The backend should do the
work of translation; we want a more sensible and convenient representation for
the compiler itself.
---
libs/vkd3d-shader/d3dbc.c | 132 +++++++++++++++++++++++++++-------------------
1 file changed, 77 insertions(+), 55 deletions(-)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c
index 1ad97add..4685afa0 100644
--- a/libs/vkd3d-shader/d3dbc.c
+++ b/libs/vkd3d-shader/d3dbc.c
@@ -1522,72 +1522,94 @@ D3DXPARAMETER_CLASS hlsl_sm1_class(const struct hlsl_type *type)
D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type)
{
- switch (type->base_type)
+ switch (type->class)
{
- case HLSL_TYPE_BOOL:
- return D3DXPT_BOOL;
- /* Actually double behaves differently depending on DLL version:
- * For <= 36, it maps to D3DXPT_FLOAT.
- * For 37-40, it maps to zero (D3DXPT_VOID).
- * For >= 41, it maps to 39, which is D3D_SVT_DOUBLE (note D3D_SVT_*
- * values are mostly compatible with D3DXPT_*).
- * However, the latter two cases look like bugs, and a reasonable
- * application certainly wouldn't know what to do with them.
- * For fx_2_0 it's always D3DXPT_FLOAT regardless of DLL version. */
- case HLSL_TYPE_DOUBLE:
- case HLSL_TYPE_FLOAT:
- case HLSL_TYPE_HALF:
- return D3DXPT_FLOAT;
- case HLSL_TYPE_INT:
- case HLSL_TYPE_UINT:
- return D3DXPT_INT;
- case HLSL_TYPE_PIXELSHADER:
- return D3DXPT_PIXELSHADER;
- case HLSL_TYPE_SAMPLER:
- switch (type->sampler_dim)
+ case HLSL_CLASS_SCALAR:
+ case HLSL_CLASS_VECTOR:
+ case HLSL_CLASS_MATRIX:
+ switch (type->base_type)
{
- case HLSL_SAMPLER_DIM_1D:
- return D3DXPT_SAMPLER1D;
- case HLSL_SAMPLER_DIM_2D:
- return D3DXPT_SAMPLER2D;
- case HLSL_SAMPLER_DIM_3D:
- return D3DXPT_SAMPLER3D;
- case HLSL_SAMPLER_DIM_CUBE:
- return D3DXPT_SAMPLERCUBE;
- case HLSL_SAMPLER_DIM_GENERIC:
- return D3DXPT_SAMPLER;
+ case HLSL_TYPE_BOOL:
+ return D3DXPT_BOOL;
+ /* Actually double behaves differently depending on DLL version:
+ * For <= 36, it maps to D3DXPT_FLOAT.
+ * For 37-40, it maps to zero (D3DXPT_VOID).
+ * For >= 41, it maps to 39, which is D3D_SVT_DOUBLE (note D3D_SVT_*
+ * values are mostly compatible with D3DXPT_*).
+ * However, the latter two cases look like bugs, and a reasonable
+ * application certainly wouldn't know what to do with them.
+ * For fx_2_0 it's always D3DXPT_FLOAT regardless of DLL version. */
+ case HLSL_TYPE_DOUBLE:
+ case HLSL_TYPE_FLOAT:
+ case HLSL_TYPE_HALF:
+ return D3DXPT_FLOAT;
+ case HLSL_TYPE_INT:
+ case HLSL_TYPE_UINT:
+ return D3DXPT_INT;
default:
- ERR("Invalid dimension %#x.\n", type->sampler_dim);
vkd3d_unreachable();
}
- break;
- case HLSL_TYPE_STRING:
- return D3DXPT_STRING;
- case HLSL_TYPE_TEXTURE:
- switch (type->sampler_dim)
+
+ case HLSL_CLASS_OBJECT:
+ switch (type->base_type)
{
- case HLSL_SAMPLER_DIM_1D:
- return D3DXPT_TEXTURE1D;
- case HLSL_SAMPLER_DIM_2D:
- return D3DXPT_TEXTURE2D;
- case HLSL_SAMPLER_DIM_3D:
- return D3DXPT_TEXTURE3D;
- case HLSL_SAMPLER_DIM_CUBE:
- return D3DXPT_TEXTURECUBE;
- case HLSL_SAMPLER_DIM_GENERIC:
- return D3DXPT_TEXTURE;
+ case HLSL_TYPE_PIXELSHADER:
+ return D3DXPT_PIXELSHADER;
+ case HLSL_TYPE_SAMPLER:
+ switch (type->sampler_dim)
+ {
+ case HLSL_SAMPLER_DIM_1D:
+ return D3DXPT_SAMPLER1D;
+ case HLSL_SAMPLER_DIM_2D:
+ return D3DXPT_SAMPLER2D;
+ case HLSL_SAMPLER_DIM_3D:
+ return D3DXPT_SAMPLER3D;
+ case HLSL_SAMPLER_DIM_CUBE:
+ return D3DXPT_SAMPLERCUBE;
+ case HLSL_SAMPLER_DIM_GENERIC:
+ return D3DXPT_SAMPLER;
+ default:
+ ERR("Invalid dimension %#x.\n", type->sampler_dim);
+ vkd3d_unreachable();
+ }
+ break;
+ case HLSL_TYPE_STRING:
+ return D3DXPT_STRING;
+ case HLSL_TYPE_TEXTURE:
+ switch (type->sampler_dim)
+ {
+ case HLSL_SAMPLER_DIM_1D:
+ return D3DXPT_TEXTURE1D;
+ case HLSL_SAMPLER_DIM_2D:
+ return D3DXPT_TEXTURE2D;
+ case HLSL_SAMPLER_DIM_3D:
+ return D3DXPT_TEXTURE3D;
+ case HLSL_SAMPLER_DIM_CUBE:
+ return D3DXPT_TEXTURECUBE;
+ case HLSL_SAMPLER_DIM_GENERIC:
+ return D3DXPT_TEXTURE;
+ default:
+ ERR("Invalid dimension %#x.\n", type->sampler_dim);
+ vkd3d_unreachable();
+ }
+ break;
+ case HLSL_TYPE_VERTEXSHADER:
+ return D3DXPT_VERTEXSHADER;
+ case HLSL_TYPE_VOID:
+ return D3DXPT_VOID;
default:
- ERR("Invalid dimension %#x.\n", type->sampler_dim);
vkd3d_unreachable();
}
- break;
- case HLSL_TYPE_VERTEXSHADER:
- return D3DXPT_VERTEXSHADER;
- case HLSL_TYPE_VOID:
- return D3DXPT_VOID;
- default:
vkd3d_unreachable();
+
+ case HLSL_CLASS_ARRAY:
+ return hlsl_sm1_base_type(type->e.array.type);
+
+ case HLSL_CLASS_STRUCT:
+ return D3DXPT_VOID;
}
+
+ vkd3d_unreachable();
}
static void write_sm1_type(struct vkd3d_bytecode_buffer *buffer, struct hlsl_type *type, unsigned int ctab_start)
Module: vkd3d
Branch: master
Commit: a882d60534fc6574ac48430b0da4eedbdddc1d20
URL: https://gitlab.winehq.org/wine/vkd3d/-/commit/a882d60534fc6574ac48430b0da4e…
Author: Zebediah Figura <zfigura(a)codeweavers.com>
Date: Tue Apr 9 18:12:48 2024 -0500
vkd3d-shader/hlsl: Map HLSL_TYPE_DOUBLE to D3DXPT_FLOAT.
---
libs/vkd3d-shader/d3dbc.c | 9 +++++++++
libs/vkd3d-shader/fx.c | 1 +
2 files changed, 10 insertions(+)
diff --git a/libs/vkd3d-shader/d3dbc.c b/libs/vkd3d-shader/d3dbc.c
index 97650942..1ad97add 100644
--- a/libs/vkd3d-shader/d3dbc.c
+++ b/libs/vkd3d-shader/d3dbc.c
@@ -1526,6 +1526,15 @@ D3DXPARAMETER_TYPE hlsl_sm1_base_type(const struct hlsl_type *type)
{
case HLSL_TYPE_BOOL:
return D3DXPT_BOOL;
+ /* Actually double behaves differently depending on DLL version:
+ * For <= 36, it maps to D3DXPT_FLOAT.
+ * For 37-40, it maps to zero (D3DXPT_VOID).
+ * For >= 41, it maps to 39, which is D3D_SVT_DOUBLE (note D3D_SVT_*
+ * values are mostly compatible with D3DXPT_*).
+ * However, the latter two cases look like bugs, and a reasonable
+ * application certainly wouldn't know what to do with them.
+ * For fx_2_0 it's always D3DXPT_FLOAT regardless of DLL version. */
+ case HLSL_TYPE_DOUBLE:
case HLSL_TYPE_FLOAT:
case HLSL_TYPE_HALF:
return D3DXPT_FLOAT;
diff --git a/libs/vkd3d-shader/fx.c b/libs/vkd3d-shader/fx.c
index 5bed9c7e..406e938d 100644
--- a/libs/vkd3d-shader/fx.c
+++ b/libs/vkd3d-shader/fx.c
@@ -648,6 +648,7 @@ static uint32_t write_fx_2_parameter(const struct hlsl_type *type, const char *n
switch (type->base_type)
{
+ case HLSL_TYPE_DOUBLE:
case HLSL_TYPE_HALF:
case HLSL_TYPE_FLOAT:
case HLSL_TYPE_BOOL: