From 478b7df10d0a6678a293659d216d5e8bf154aa41 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 20 Jul 2020 18:53:54 -0400 Subject: [PATCH] RSQ opcode requires replicate swizzle. --- mojoshader.c | 6 ++++++ mojoshader_assembler.c | 3 ++- mojoshader_internal.h | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mojoshader.c b/mojoshader.c index 58609e2..a5c4f96 100644 --- a/mojoshader.c +++ b/mojoshader.c @@ -1504,6 +1504,12 @@ static void state_RCP(Context *ctx) fail(ctx, "RCP without replicate swizzle"); } // state_RCP +static void state_RSQ(Context *ctx) +{ + if (!replicate_swizzle(ctx->source_args[0].swizzle)) + fail(ctx, "RSQ without replicate swizzle"); +} // state_RSQ + static void state_LOOP(Context *ctx) { if (ctx->source_args[0].regtype != REG_TYPE_LOOP) diff --git a/mojoshader_assembler.c b/mojoshader_assembler.c index 09f95c7..1ed04d0 100644 --- a/mojoshader_assembler.c +++ b/mojoshader_assembler.c @@ -1254,7 +1254,8 @@ static int parse_instruction_token(Context *ctx, Token token) ctx->tokenbufpos = 0; ctx->default_writemask = instruction->default_writemask; - if (opcode == OPCODE_RCP) // RCP has an implicit swizzle of .xxxx if not specified. + // RCP and RSQ have an implicit swizzle of .xxxx if not specified. + if ((opcode == OPCODE_RCP) || (opcode == OPCODE_RSQ)) ctx->default_swizzle = 0; // .xxxx replicate swizzle. const int tokcount = instruction->parse_args(ctx); diff --git a/mojoshader_internal.h b/mojoshader_internal.h index 256f30c..455688a 100644 --- a/mojoshader_internal.h +++ b/mojoshader_internal.h @@ -413,6 +413,7 @@ void buffer_patch(Buffer *buffer, const size_t start, // we need to reference these by explicit value occasionally... #define OPCODE_RCP 6 +#define OPCODE_RSQ 7 #define OPCODE_RET 28 #define OPCODE_IF 40 #define OPCODE_IFC 41 @@ -781,7 +782,7 @@ INSTRUCTION(SUB, "SUB", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF) INSTRUCTION(MAD, "MAD", 1, DSSS, MOJOSHADER_TYPE_ANY, 0xF) INSTRUCTION(MUL, "MUL", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF) INSTRUCTION_STATE(RCP, "RCP", 1, DS, MOJOSHADER_TYPE_ANY, 0xF) -INSTRUCTION(RSQ, "RSQ", 1, DS, MOJOSHADER_TYPE_ANY, 0xF) +INSTRUCTION_STATE(RSQ, "RSQ", 1, DS, MOJOSHADER_TYPE_ANY, 0xF) INSTRUCTION(DP3, "DP3", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF) INSTRUCTION_STATE(DP4, "DP4", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF) INSTRUCTION(MIN, "MIN", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)