vkd3d-shader/d3dbc: Support SM1 if conditionals.

According to the documentation, if_comp is available from 2_x pixel
and vertex shaders and, unlike "if bool" it doesn't expect a constant
boolean register (from the input signature), so:

if_neq cond -cond

seems like a convenient way to write these, for profiles above 2.0.
This commit is contained in:
Francisco Casas 2024-03-26 19:43:54 -03:00 committed by Alexandre Julliard
parent d2427ea1bd
commit 5e3515f191
Notes: Alexandre Julliard 2024-04-25 00:12:42 +02:00
Approved-by: Giovanni Mascellani (@giomasce)
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Zebediah Figura (@zfigura)
Approved-by: Alexandre Julliard (@julliard)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/794
2 changed files with 69 additions and 16 deletions

View File

@ -1813,6 +1813,7 @@ static uint32_t sm1_encode_register_type(D3DSHADER_PARAM_REGISTER_TYPE type)
struct sm1_instruction
{
D3DSHADER_INSTRUCTION_OPCODE_TYPE opcode;
unsigned int flags;
struct sm1_dst_register
{
@ -1852,6 +1853,8 @@ static void write_sm1_instruction(struct hlsl_ctx *ctx, struct vkd3d_bytecode_bu
uint32_t token = instr->opcode;
unsigned int i;
token |= VKD3D_SM1_INSTRUCTION_FLAGS_MASK & (instr->flags << VKD3D_SM1_INSTRUCTION_FLAGS_SHIFT);
if (ctx->profile->major_version > 1)
token |= (instr->has_dst + instr->src_count) << D3DSI_INSTLENGTH_SHIFT;
put_u32(buffer, token);
@ -2414,6 +2417,49 @@ static void write_sm1_expr(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *b
}
}
static void write_sm1_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer,
const struct hlsl_block *block);
static void write_sm1_if(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_node *instr)
{
const struct hlsl_ir_if *iff = hlsl_ir_if(instr);
const struct hlsl_ir_node *condition;
struct sm1_instruction sm1_ifc, sm1_else, sm1_endif;
condition = iff->condition.node;
assert(condition->data_type->dimx == 1 && condition->data_type->dimy == 1);
sm1_ifc = (struct sm1_instruction)
{
.opcode = D3DSIO_IFC,
.flags = VKD3D_SHADER_REL_OP_NE, /* Make it a "if_ne" instruction. */
.srcs[0].type = D3DSPR_TEMP,
.srcs[0].swizzle = hlsl_swizzle_from_writemask(condition->reg.writemask),
.srcs[0].reg = condition->reg.id,
.srcs[0].mod = 0,
.srcs[1].type = D3DSPR_TEMP,
.srcs[1].swizzle = hlsl_swizzle_from_writemask(condition->reg.writemask),
.srcs[1].reg = condition->reg.id,
.srcs[1].mod = D3DSPSM_NEG,
.src_count = 2,
};
write_sm1_instruction(ctx, buffer, &sm1_ifc);
write_sm1_block(ctx, buffer, &iff->then_block);
if (!list_empty(&iff->else_block.instrs))
{
sm1_else = (struct sm1_instruction){.opcode = D3DSIO_ELSE};
write_sm1_instruction(ctx, buffer, &sm1_else);
write_sm1_block(ctx, buffer, &iff->else_block);
}
sm1_endif = (struct sm1_instruction){.opcode = D3DSIO_ENDIF};
write_sm1_instruction(ctx, buffer, &sm1_endif);
}
static void write_sm1_jump(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *buffer, const struct hlsl_ir_node *instr)
{
const struct hlsl_ir_jump *jump = hlsl_ir_jump(instr);
@ -2643,6 +2689,13 @@ static void write_sm1_block(struct hlsl_ctx *ctx, struct vkd3d_bytecode_buffer *
write_sm1_expr(ctx, buffer, instr);
break;
case HLSL_IR_IF:
if (hlsl_version_ge(ctx, 2, 1))
write_sm1_if(ctx, buffer, instr);
else
hlsl_fixme(ctx, &instr->loc, "Flatten \"if\" conditionals branches.");
break;
case HLSL_IR_JUMP:
write_sm1_jump(ctx, buffer, instr);
break;

View File

@ -75,7 +75,7 @@ float main() : sv_target
shader model >= 3.0
[pixel shader todo(sm<4)]
[pixel shader]
uniform float a;
float4 main() : sv_target
@ -87,14 +87,14 @@ float4 main() : sv_target
[test]
uniform 0 float -2
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (1, 2, 3, 4)
uniform 0 float 10
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (10, 20, 30, 40)
[pixel shader todo(sm<4)]
[pixel shader]
uniform float4 u;
float4 main() : sv_target
@ -108,7 +108,7 @@ float4 main() : sv_target
[test]
uniform 0 float4 0.0 0.0 0.0 0.0
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (0.9, 0.8, 0.7, 0.6)
[pixel shader]
@ -129,7 +129,7 @@ todo(glsl) draw quad
probe all rgba (9.0, 10.0, 11.0, 12.0)
[pixel shader todo(sm<4)]
[pixel shader]
int a, b;
float4 main() : sv_target
@ -145,23 +145,23 @@ if(sm<4) uniform 0 float 8
if(sm<4) uniform 4 float 9
if(sm>=4) uniform 0 int 8
if(sm>=4) uniform 1 int 9
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (-1.0, -1.0, -1.0, -1.0)
if(sm<4) uniform 0 float -3
if(sm<4) uniform 4 float -4
if(sm>=4) uniform 0 int -3
if(sm>=4) uniform 1 int -4
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (1.0, 1.0, 1.0, 1.0)
if(sm<4) uniform 0 float 7
if(sm<4) uniform 4 float 7
if(sm>=4) uniform 0 int 7
if(sm>=4) uniform 1 int 7
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (1.0, 1.0, 1.0, 1.0)
[pixel shader todo(sm<4)]
[pixel shader]
int a, b;
float4 main() : sv_target
@ -177,23 +177,23 @@ if(sm<4) uniform 0 float 8
if(sm<4) uniform 4 float 9
if(sm>=4) uniform 0 int 8
if(sm>=4) uniform 1 int 9
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (-1.0, -1.0, -1.0, -1.0)
if(sm<4) uniform 0 float -3
if(sm<4) uniform 4 float -4
if(sm>=4) uniform 0 int -3
if(sm>=4) uniform 1 int -4
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (1.0, 1.0, 1.0, 1.0)
if(sm<4) uniform 0 float 7
if(sm<4) uniform 4 float 7
if(sm>=4) uniform 0 int 7
if(sm>=4) uniform 1 int 7
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (-1.0, -1.0, -1.0, -1.0)
[pixel shader todo(sm<4)]
[pixel shader]
int a, b;
float4 main() : sv_target
@ -209,13 +209,13 @@ if(sm<4) uniform 0 float -3
if(sm<4) uniform 4 float -2
if(sm>=4) uniform 0 int -3
if(sm>=4) uniform 1 int -2
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (-1.0, -1.0, -1.0, -1.0)
if(sm<4) uniform 0 float 4
if(sm<4) uniform 4 float 4
if(sm>=4) uniform 0 int 4
if(sm>=4) uniform 1 int 4
todo(sm<4 | glsl) draw quad
todo(glsl) draw quad
probe all rgba (1.0, 1.0, 1.0, 1.0)