Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
The assembler needs to accept an implicit ".x" swizzle on RCP's sourc…
…e arg.
  • Loading branch information
icculus committed Jul 20, 2020
1 parent 6d924fd commit 42cf2e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mojoshader_assembler.c
Expand Up @@ -56,6 +56,7 @@ typedef struct Context
int tokenbufpos; // bytecode tokens!
DestArgInfo dest_arg;
uint8 default_writemask;
uint8 default_swizzle;
Buffer *output;
Buffer *token_to_source;
Buffer *ctab;
Expand Down Expand Up @@ -641,6 +642,12 @@ static int parse_source_token_maybe_relative(Context *ctx, const int relok)
{
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;

Expand Down Expand Up @@ -759,8 +766,8 @@ static int parse_source_token_maybe_relative(Context *ctx, const int relok)
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");
Expand Down Expand Up @@ -1247,6 +1254,9 @@ 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.
ctx->default_swizzle = 0; // .xxxx replicate swizzle.

const int tokcount = instruction->parse_args(ctx);

// insttoks bits are reserved and should be zero if < SM2.
Expand Down
1 change: 1 addition & 0 deletions mojoshader_internal.h
Expand Up @@ -412,6 +412,7 @@ void buffer_patch(Buffer *buffer, const size_t start,
#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
Expand Down

0 comments on commit 42cf2e1

Please sign in to comment.