Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 ++ tests/cast-to-float.shader_test | 29 +++++++++++++++++++++++++++++ tests/shader_runner_d3d12.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/cast-to-float.shader_test
diff --git a/Makefile.am b/Makefile.am index 05d9f00c6..d707a26b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,6 +54,7 @@ vkd3d_shader_runners = \ tests/shader_runner_d3d12
vkd3d_shader_tests = \ + tests/cast-to-float.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ @@ -266,6 +267,7 @@ tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@ tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \ + tests/cast-to-float.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ diff --git a/tests/cast-to-float.shader_test b/tests/cast-to-float.shader_test new file mode 100644 index 000000000..75822e527 --- /dev/null +++ b/tests/cast-to-float.shader_test @@ -0,0 +1,29 @@ +[pixel shader] + +float4 main(uniform int i, uniform uint u, uniform bool b, uniform half h) : sv_target +{ + return float4(((float)i) + 1.5, ((float)u) - 2.5, ((float)b) / 2, h); +} + +[test] +uniform 0 int -1 +uniform 1 uint 3 +uniform 2 int -2 +uniform 3 float 0.5 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5) + +[pixel shader] + +float4 main() : sv_target +{ + int i = -1; + uint u = 3; + bool b = true; + half h = 0.5; + return float4(((float)i) + 1.5, ((float)u) - 2.5, ((float)b) / 2, h); +} + +[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5) diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 2221c0f87..d5c0380e8 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -242,11 +242,38 @@ static void parse_test_directive(struct shader_context *context, const char *lin } memcpy(context->uniforms + offset, &v, sizeof(v)); } + else if (match_string(line, "float", &line)) + { + float f; + + if (sscanf(line, "%f", &f) < 1) + goto err; + if (offset + 1 > context->uniform_count) + { + context->uniform_count = offset + 1; + context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms)); + } + memcpy(context->uniforms + offset, &f, sizeof(f)); + } + else if (match_string(line, "int", &line)) + { + int i; + + if (sscanf(line, "%i", &i) < 1) + goto err; + if (offset + 1 > context->uniform_count) + { + context->uniform_count = offset + 1; + context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms)); + } + memcpy(context->uniforms + offset, &i, sizeof(i)); + } else if (match_string(line, "uint", &line)) { unsigned int u;
- sscanf(line, "%u", &u); + if (sscanf(line, "%u", &u) < 1) + goto err; if (offset + 1 > context->uniform_count) { context->uniform_count = offset + 1;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 ++ tests/cast-to-half.shader_test | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/cast-to-half.shader_test
diff --git a/Makefile.am b/Makefile.am index d707a26b3..a1b6eb31b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -55,6 +55,7 @@ vkd3d_shader_runners = \
vkd3d_shader_tests = \ tests/cast-to-float.shader_test \ + tests/cast-to-half.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ @@ -268,6 +269,7 @@ tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \ tests/cast-to-float.shader_test \ + tests/cast-to-half.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ diff --git a/tests/cast-to-half.shader_test b/tests/cast-to-half.shader_test new file mode 100644 index 000000000..6db5412de --- /dev/null +++ b/tests/cast-to-half.shader_test @@ -0,0 +1,29 @@ +[pixel shader] + +float4 main(uniform int i, uniform uint u, uniform bool b, uniform float f) : sv_target +{ + return float4(((half)i) + 1.5, ((half)u) - 2.5, ((half)b) / 2, f); +} + +[test] +uniform 0 int -1 +uniform 1 uint 3 +uniform 2 int -2 +uniform 3 float 0.5 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5) + +[pixel shader] + +float4 main() : sv_target +{ + int i = -1; + uint u = 3; + bool b = true; + float f = 0.5; + return float4(((half)i) + 1.5, ((half)u) - 2.5, ((half)b) / 2, f); +} + +[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 10/09/21 04:11, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Makefile.am | 2 ++ tests/cast-to-half.shader_test | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/cast-to-half.shader_test
diff --git a/Makefile.am b/Makefile.am index d707a26b3..a1b6eb31b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -55,6 +55,7 @@ vkd3d_shader_runners = \
vkd3d_shader_tests = \ tests/cast-to-float.shader_test \
- tests/cast-to-half.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
@@ -268,6 +269,7 @@ tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \ tests/cast-to-float.shader_test \
- tests/cast-to-half.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
diff --git a/tests/cast-to-half.shader_test b/tests/cast-to-half.shader_test new file mode 100644 index 000000000..6db5412de --- /dev/null +++ b/tests/cast-to-half.shader_test @@ -0,0 +1,29 @@ +[pixel shader]
+float4 main(uniform int i, uniform uint u, uniform bool b, uniform float f) : sv_target +{
- return float4(((half)i) + 1.5, ((half)u) - 2.5, ((half)b) / 2, f);
+}
+[test] +uniform 0 int -1 +uniform 1 uint 3 +uniform 2 int -2 +uniform 3 float 0.5 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
+[pixel shader]
+float4 main() : sv_target +{
- int i = -1;
- uint u = 3;
- bool b = true;
- float f = 0.5;
- return float4(((half)i) + 1.5, ((half)u) - 2.5, ((half)b) / 2, f);
+}
+[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 ++ tests/cast-to-int.shader_test | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/cast-to-int.shader_test
diff --git a/Makefile.am b/Makefile.am index a1b6eb31b..da57a6893 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ vkd3d_shader_runners = \ vkd3d_shader_tests = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \ + tests/cast-to-int.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ @@ -270,6 +271,7 @@ SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \ + tests/cast-to-int.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ diff --git a/tests/cast-to-int.shader_test b/tests/cast-to-int.shader_test new file mode 100644 index 000000000..c7d1e23c3 --- /dev/null +++ b/tests/cast-to-int.shader_test @@ -0,0 +1,41 @@ +[pixel shader] + +float4 main(uniform float f, uniform uint u, uniform bool b, uniform half h) : sv_target +{ + float4 ret; + + ret.x = ((float)(int)f) - 1.5; + ret.y = ((float)(int)u) + 2.5; + ret.z = ((float)(int)b) / 2; + ret.w = ((float)(int)h) + 3.5; + return ret; +} + +[test] +uniform 0 float 2.6 +uniform 1 int -2 +uniform 2 int -2 +uniform 3 float -3.6 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5) + +[pixel shader] + +float4 main() : sv_target +{ + float f = 2.6; + uint u = 0xfffffffe; + bool b = true; + half h = -3.6; + float4 ret; + + ret.x = ((float)(int)f) - 1.5; + ret.y = ((float)(int)u) + 2.5; + ret.z = ((float)(int)b) / 2; + ret.w = ((float)(int)h) + 3.5; + return ret; +} + +[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 10/09/21 04:11, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Makefile.am | 2 ++ tests/cast-to-int.shader_test | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/cast-to-int.shader_test
diff --git a/Makefile.am b/Makefile.am index a1b6eb31b..da57a6893 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,6 +56,7 @@ vkd3d_shader_runners = \ vkd3d_shader_tests = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \
- tests/cast-to-int.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
@@ -270,6 +271,7 @@ SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \
- tests/cast-to-int.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
diff --git a/tests/cast-to-int.shader_test b/tests/cast-to-int.shader_test new file mode 100644 index 000000000..c7d1e23c3 --- /dev/null +++ b/tests/cast-to-int.shader_test @@ -0,0 +1,41 @@ +[pixel shader]
+float4 main(uniform float f, uniform uint u, uniform bool b, uniform half h) : sv_target +{
- float4 ret;
- ret.x = ((float)(int)f) - 1.5;
- ret.y = ((float)(int)u) + 2.5;
- ret.z = ((float)(int)b) / 2;
- ret.w = ((float)(int)h) + 3.5;
- return ret;
+}
+[test] +uniform 0 float 2.6 +uniform 1 int -2 +uniform 2 int -2 +uniform 3 float -3.6 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
+[pixel shader]
+float4 main() : sv_target +{
- float f = 2.6;
- uint u = 0xfffffffe;
- bool b = true;
- half h = -3.6;
- float4 ret;
- ret.x = ((float)(int)f) - 1.5;
- ret.y = ((float)(int)u) + 2.5;
- ret.z = ((float)(int)b) / 2;
- ret.w = ((float)(int)h) + 3.5;
- return ret;
+}
+[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- Makefile.am | 2 ++ tests/cast-to-uint.shader_test | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/cast-to-uint.shader_test
diff --git a/Makefile.am b/Makefile.am index da57a6893..9f747f478 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,7 @@ vkd3d_shader_tests = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \ tests/cast-to-int.shader_test \ + tests/cast-to-uint.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ @@ -272,6 +273,7 @@ XFAIL_TESTS = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \ tests/cast-to-int.shader_test \ + tests/cast-to-uint.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \ diff --git a/tests/cast-to-uint.shader_test b/tests/cast-to-uint.shader_test new file mode 100644 index 000000000..01b0442cf --- /dev/null +++ b/tests/cast-to-uint.shader_test @@ -0,0 +1,41 @@ +[pixel shader] + +float4 main(uniform float f, uniform int i, uniform bool b, uniform half h) : sv_target +{ + float4 ret; + + ret.x = ((float)(uint)f) - 1.5; + ret.y = ((float)(uint)i) - 1.5; + ret.z = ((float)(uint)b) / 2; + ret.w = ((float)(uint)h) + 0.5; + return ret; +} + +[test] +uniform 0 float 2.6 +uniform 1 int 2 +uniform 2 int -2 +uniform 3 float -3.6 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5) + +[pixel shader] + +float4 main() : sv_target +{ + float f = 2.6; + int i = 2; + bool b = true; + half h = -3.6; + float4 ret; + + ret.x = ((float)(uint)f) - 1.5; + ret.y = ((float)(uint)i) - 1.5; + ret.z = ((float)(uint)b) / 2; + ret.w = ((float)(uint)h) + 0.5; + return ret; +} + +[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 10/09/21 04:11, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Makefile.am | 2 ++ tests/cast-to-uint.shader_test | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/cast-to-uint.shader_test
diff --git a/Makefile.am b/Makefile.am index da57a6893..9f747f478 100644 --- a/Makefile.am +++ b/Makefile.am @@ -57,6 +57,7 @@ vkd3d_shader_tests = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \ tests/cast-to-int.shader_test \
- tests/cast-to-uint.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
@@ -272,6 +273,7 @@ XFAIL_TESTS = \ tests/cast-to-float.shader_test \ tests/cast-to-half.shader_test \ tests/cast-to-int.shader_test \
- tests/cast-to-uint.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
diff --git a/tests/cast-to-uint.shader_test b/tests/cast-to-uint.shader_test new file mode 100644 index 000000000..01b0442cf --- /dev/null +++ b/tests/cast-to-uint.shader_test @@ -0,0 +1,41 @@ +[pixel shader]
+float4 main(uniform float f, uniform int i, uniform bool b, uniform half h) : sv_target +{
- float4 ret;
- ret.x = ((float)(uint)f) - 1.5;
- ret.y = ((float)(uint)i) - 1.5;
- ret.z = ((float)(uint)b) / 2;
- ret.w = ((float)(uint)h) + 0.5;
- return ret;
+}
+[test] +uniform 0 float 2.6 +uniform 1 int 2 +uniform 2 int -2 +uniform 3 float -3.6 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
+[pixel shader]
+float4 main() : sv_target +{
- float f = 2.6;
- int i = 2;
- bool b = true;
- half h = -3.6;
- float4 ret;
- ret.x = ((float)(uint)f) - 1.5;
- ret.y = ((float)(uint)i) - 1.5;
- ret.z = ((float)(uint)b) / 2;
- ret.w = ((float)(uint)h) + 0.5;
- return ret;
+}
+[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 160da47fd..ce749b692 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -981,6 +981,43 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, { switch (expr->op) { + case HLSL_OP1_CAST: + { + const struct hlsl_type *src_type = arg1->data_type; + + /* Narrowing casts need to be lowered. */ + if (src_type->dimx != expr->node.data_type->dimx) + hlsl_fixme(ctx, expr->node.loc, "Narrowing cast.\n"); + + switch (src_type->base_type) + { + case HLSL_TYPE_HALF: + case HLSL_TYPE_FLOAT: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, 0); + break; + + case HLSL_TYPE_INT: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_ITOF, &expr->node, arg1, 0); + break; + + case HLSL_TYPE_UINT: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_UTOF, &expr->node, arg1, 0); + break; + + case HLSL_TYPE_BOOL: + hlsl_fixme(ctx, expr->node.loc, "Casts from bool to float are not implemented.\n"); + break; + + case HLSL_TYPE_DOUBLE: + hlsl_fixme(ctx, expr->node.loc, "Casts from double to float are not implemented.\n"); + break; + + default: + break; + } + break; + } + case HLSL_OP1_NEG: write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, VKD3D_SM4_REGISTER_MODIFIER_NEGATE); break;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 10/09/21 04:11, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_sm4.c | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 160da47fd..ce749b692 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -981,6 +981,43 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, { switch (expr->op) {
case HLSL_OP1_CAST:
{
const struct hlsl_type *src_type = arg1->data_type;
/* Narrowing casts need to be lowered. */
if (src_type->dimx != expr->node.data_type->dimx)
hlsl_fixme(ctx, expr->node.loc, "Narrowing cast.\n");
switch (src_type->base_type)
{
case HLSL_TYPE_HALF:
case HLSL_TYPE_FLOAT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, 0);
break;
case HLSL_TYPE_INT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_ITOF, &expr->node, arg1, 0);
break;
case HLSL_TYPE_UINT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_UTOF, &expr->node, arg1, 0);
break;
case HLSL_TYPE_BOOL:
hlsl_fixme(ctx, expr->node.loc, "Casts from bool to float are not implemented.\n");
break;
case HLSL_TYPE_DOUBLE:
hlsl_fixme(ctx, expr->node.loc, "Casts from double to float are not implemented.\n");
break;
default:
break;
}
break;
}
case HLSL_OP1_NEG: write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, VKD3D_SM4_REGISTER_MODIFIER_NEGATE); break;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index ce749b692..0660dd58b 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1041,6 +1041,51 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, break; }
+ case HLSL_TYPE_INT: + { + switch (expr->op) + { + case HLSL_OP1_CAST: + { + const struct hlsl_type *src_type = arg1->data_type; + + /* Narrowing casts need to be lowered. */ + if (src_type->dimx != expr->node.data_type->dimx) + hlsl_fixme(ctx, expr->node.loc, "Narrowing cast."); + + switch (src_type->base_type) + { + case HLSL_TYPE_HALF: + case HLSL_TYPE_FLOAT: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_FTOI, &expr->node, arg1, 0); + break; + + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, 0); + break; + + case HLSL_TYPE_BOOL: + hlsl_fixme(ctx, expr->node.loc, "SM4 cast from bool to int."); + break; + + case HLSL_TYPE_DOUBLE: + hlsl_fixme(ctx, expr->node.loc, "SM4 cast from double to int."); + break; + + default: + break; + } + break; + } + + default: + hlsl_fixme(ctx, expr->node.loc, "SM4 int "%s" expression.", debug_hlsl_expr_op(expr->op)); + break; + } + break; + } + default: { struct vkd3d_string_buffer *string;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 10/09/21 04:11, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_sm4.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index ce749b692..0660dd58b 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1041,6 +1041,51 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, break; }
case HLSL_TYPE_INT:
{
switch (expr->op)
{
case HLSL_OP1_CAST:
{
const struct hlsl_type *src_type = arg1->data_type;
/* Narrowing casts need to be lowered. */
if (src_type->dimx != expr->node.data_type->dimx)
hlsl_fixme(ctx, expr->node.loc, "Narrowing cast.");
switch (src_type->base_type)
{
case HLSL_TYPE_HALF:
case HLSL_TYPE_FLOAT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_FTOI, &expr->node, arg1, 0);
break;
case HLSL_TYPE_INT:
case HLSL_TYPE_UINT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, 0);
break;
case HLSL_TYPE_BOOL:
hlsl_fixme(ctx, expr->node.loc, "SM4 cast from bool to int.");
break;
case HLSL_TYPE_DOUBLE:
hlsl_fixme(ctx, expr->node.loc, "SM4 cast from double to int.");
break;
default:
break;
}
break;
}
default:
hlsl_fixme(ctx, expr->node.loc, "SM4 int \"%s\" expression.", debug_hlsl_expr_op(expr->op));
break;
}
break;
}
default: { struct vkd3d_string_buffer *string;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- libs/vkd3d-shader/hlsl_sm4.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 0660dd58b..855804e2c 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1086,6 +1086,51 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, break; }
+ case HLSL_TYPE_UINT: + { + switch (expr->op) + { + case HLSL_OP1_CAST: + { + const struct hlsl_type *src_type = arg1->data_type; + + /* Narrowing casts need to be lowered. */ + if (src_type->dimx != expr->node.data_type->dimx) + hlsl_fixme(ctx, expr->node.loc, "SM4 narrowing cast.\n"); + + switch (src_type->base_type) + { + case HLSL_TYPE_HALF: + case HLSL_TYPE_FLOAT: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_FTOU, &expr->node, arg1, 0); + break; + + case HLSL_TYPE_INT: + case HLSL_TYPE_UINT: + write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, 0); + break; + + case HLSL_TYPE_BOOL: + hlsl_fixme(ctx, expr->node.loc, "SM4 cast from bool to uint.\n"); + break; + + case HLSL_TYPE_DOUBLE: + hlsl_fixme(ctx, expr->node.loc, "SM4 cast from double to uint.\n"); + break; + + default: + break; + } + break; + } + + default: + hlsl_fixme(ctx, expr->node.loc, "SM4 uint "%s" expression.\n", debug_hlsl_expr_op(expr->op)); + break; + } + break; + } + default: { struct vkd3d_string_buffer *string;
Signed-off-by: Matteo Bruni mbruni@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 10/09/21 04:11, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
libs/vkd3d-shader/hlsl_sm4.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/libs/vkd3d-shader/hlsl_sm4.c b/libs/vkd3d-shader/hlsl_sm4.c index 0660dd58b..855804e2c 100644 --- a/libs/vkd3d-shader/hlsl_sm4.c +++ b/libs/vkd3d-shader/hlsl_sm4.c @@ -1086,6 +1086,51 @@ static void write_sm4_expr(struct hlsl_ctx *ctx, break; }
case HLSL_TYPE_UINT:
{
switch (expr->op)
{
case HLSL_OP1_CAST:
{
const struct hlsl_type *src_type = arg1->data_type;
/* Narrowing casts need to be lowered. */
if (src_type->dimx != expr->node.data_type->dimx)
hlsl_fixme(ctx, expr->node.loc, "SM4 narrowing cast.\n");
switch (src_type->base_type)
{
case HLSL_TYPE_HALF:
case HLSL_TYPE_FLOAT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_FTOU, &expr->node, arg1, 0);
break;
case HLSL_TYPE_INT:
case HLSL_TYPE_UINT:
write_sm4_unary_op(buffer, VKD3D_SM4_OP_MOV, &expr->node, arg1, 0);
break;
case HLSL_TYPE_BOOL:
hlsl_fixme(ctx, expr->node.loc, "SM4 cast from bool to uint.\n");
break;
case HLSL_TYPE_DOUBLE:
hlsl_fixme(ctx, expr->node.loc, "SM4 cast from double to uint.\n");
break;
default:
break;
}
break;
}
default:
hlsl_fixme(ctx, expr->node.loc, "SM4 uint \"%s\" expression.\n", debug_hlsl_expr_op(expr->op));
break;
}
break;
}
default: { struct vkd3d_string_buffer *string;
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com
Il 10/09/21 04:11, Zebediah Figura ha scritto:
Signed-off-by: Zebediah Figura zfigura@codeweavers.com
Makefile.am | 2 ++ tests/cast-to-float.shader_test | 29 +++++++++++++++++++++++++++++ tests/shader_runner_d3d12.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/cast-to-float.shader_test
diff --git a/Makefile.am b/Makefile.am index 05d9f00c6..d707a26b3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,6 +54,7 @@ vkd3d_shader_runners = \ tests/shader_runner_d3d12
vkd3d_shader_tests = \
- tests/cast-to-float.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
@@ -266,6 +267,7 @@ tests_vkd3d_api_LDADD = libvkd3d.la @VULKAN_LIBS@ tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la SHADER_TEST_LOG_COMPILER = tests/shader_runner_d3d12 XFAIL_TESTS = \
- tests/cast-to-float.shader_test \ tests/conditional.shader_test \ tests/hlsl-array-dimension.shader_test \ tests/hlsl-bool-cast.shader_test \
diff --git a/tests/cast-to-float.shader_test b/tests/cast-to-float.shader_test new file mode 100644 index 000000000..75822e527 --- /dev/null +++ b/tests/cast-to-float.shader_test @@ -0,0 +1,29 @@ +[pixel shader]
+float4 main(uniform int i, uniform uint u, uniform bool b, uniform half h) : sv_target +{
- return float4(((float)i) + 1.5, ((float)u) - 2.5, ((float)b) / 2, h);
+}
+[test] +uniform 0 int -1 +uniform 1 uint 3 +uniform 2 int -2 +uniform 3 float 0.5 +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5)
+[pixel shader]
+float4 main() : sv_target +{
- int i = -1;
- uint u = 3;
- bool b = true;
- half h = 0.5;
- return float4(((float)i) + 1.5, ((float)u) - 2.5, ((float)b) / 2, h);
+}
+[test] +draw quad +probe all rgba (0.5, 0.5, 0.5, 0.5) diff --git a/tests/shader_runner_d3d12.c b/tests/shader_runner_d3d12.c index 2221c0f87..d5c0380e8 100644 --- a/tests/shader_runner_d3d12.c +++ b/tests/shader_runner_d3d12.c @@ -242,11 +242,38 @@ static void parse_test_directive(struct shader_context *context, const char *lin } memcpy(context->uniforms + offset, &v, sizeof(v)); }
else if (match_string(line, "float", &line))
{
float f;
if (sscanf(line, "%f", &f) < 1)
goto err;
if (offset + 1 > context->uniform_count)
{
context->uniform_count = offset + 1;
context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
}
memcpy(context->uniforms + offset, &f, sizeof(f));
}
else if (match_string(line, "int", &line))
{
int i;
if (sscanf(line, "%i", &i) < 1)
goto err;
if (offset + 1 > context->uniform_count)
{
context->uniform_count = offset + 1;
context->uniforms = realloc(context->uniforms, context->uniform_count * sizeof(*context->uniforms));
}
memcpy(context->uniforms + offset, &i, sizeof(i));
} else if (match_string(line, "uint", &line)) { unsigned int u;
sscanf(line, "%u", &u);
if (sscanf(line, "%u", &u) < 1)
goto err; if (offset + 1 > context->uniform_count) { context->uniform_count = offset + 1;