The assembler needs to accept an implicit ".x" swizzle on RCP's source arg.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 20 Jul 2020 16:14:43 -0400
changeset 1290 2febe5ae83ad
parent 1289 f47a47343dbc
child 1291 db27fb09421a
The assembler needs to accept an implicit ".x" swizzle on RCP's source arg.
mojoshader_assembler.c
mojoshader_internal.h
--- a/mojoshader_assembler.c	Mon Jul 20 15:37:27 2020 -0400
+++ b/mojoshader_assembler.c	Mon Jul 20 16:14:43 2020 -0400
@@ -56,6 +56,7 @@
     int tokenbufpos;        // bytecode tokens!
     DestArgInfo dest_arg;
     uint8 default_writemask;
+    uint8 default_swizzle;
     Buffer *output;
     Buffer *token_to_source;
     Buffer *ctab;
@@ -641,6 +642,12 @@
 {
     int retval = 1;
 
+    // If we've set a weird default swizzle, save it off and then go back to
+    //  the default, so it won't reuse the setting for relative addressing
+    //  processing. We only need a weird default for a handful of instructions.
+    const uint8 default_swizzle = ctx->default_swizzle;
+    ctx->default_swizzle = 0xE4;  // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
+
     if (tokenbuf_overflow(ctx))
         return 0;
 
@@ -759,8 +766,8 @@
     uint32 swizzle = 0;
     if (nexttoken(ctx) != ((Token) '.'))
     {
-        swizzle = 0xE4;  // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
-        pushback(ctx);  // no explicit writemask; do full mask.
+        swizzle = default_swizzle;
+        pushback(ctx);  // no explicit swizzle; use the default.
     } // if
     else if (scalar_register(ctx->shader_type, regtype, regnum))
         fail(ctx, "Swizzle specified for scalar register");
@@ -1247,6 +1254,9 @@
     ctx->tokenbufpos = 0;
     ctx->default_writemask = instruction->default_writemask;
 
+    if (opcode == OPCODE_RCP)  // RCP has an implicit swizzle of .xxxx if not specified.
+        ctx->default_swizzle = 0;  // .xxxx replicate swizzle.
+
     const int tokcount = instruction->parse_args(ctx);
 
     // insttoks bits are reserved and should be zero if < SM2.
--- a/mojoshader_internal.h	Mon Jul 20 15:37:27 2020 -0400
+++ b/mojoshader_internal.h	Mon Jul 20 16:14:43 2020 -0400
@@ -412,6 +412,7 @@
 #define FXLC_ID 0x434C5846  // 0x434C5846 == 'FXLC'
 
 // we need to reference these by explicit value occasionally...
+#define OPCODE_RCP 6
 #define OPCODE_RET 28
 #define OPCODE_IF 40
 #define OPCODE_IFC 41