mojoshader.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 20 Jul 2020 15:14:32 -0400
changeset 1286 d9e3872a055e
parent 1283 c198fe1c469a
child 1287 c5a53296dbd5
permissions -rw-r--r--
Fixed typo in error message.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents: 6
diff changeset
     1
/**
35
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 34
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
5749d174b537 [svn] Might as well keep the tradition alive.
icculus
parents: 34
diff changeset
     3
 *  Direct3D shaders.
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents: 6
diff changeset
     4
 *
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents: 6
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents: 6
diff changeset
     6
 *
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents: 6
diff changeset
     7
 *  This file written by Ryan C. Gordon.
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents: 6
diff changeset
     8
 */
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents: 6
diff changeset
     9
322
92b8f994bdc5 Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 320
diff changeset
    10
// !!! FIXME: this file really needs to be split up.
18
0dbdb2be8bf8 [svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents: 17
diff changeset
    11
// !!! FIXME: I keep changing coding styles for symbols and typedefs.
0dbdb2be8bf8 [svn] Bunch More Work. Cleanups, added app-supplied allocators, flexible output, etc.
icculus
parents: 17
diff changeset
    12
1082
6fbcfbef2a63 Added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1081
diff changeset
    13
// !!! FIXME: rules from MSDN about temp registers we probably don't check.
6fbcfbef2a63 Added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1081
diff changeset
    14
// - There are limited temporaries: vs_1_1 has 12 (ps_1_1 has _2_!).
6fbcfbef2a63 Added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1081
diff changeset
    15
// - SM2 apparently was variable, between 12 and 32. Shader Model 3 has 32.
6fbcfbef2a63 Added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1081
diff changeset
    16
// - A maximum of three temp registers can be used in a single instruction.
6fbcfbef2a63 Added some FIXMEs.
Ryan C. Gordon <icculus@icculus.org>
parents: 1081
diff changeset
    17
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents: 463
diff changeset
    18
#define __MOJOSHADER_INTERNAL__ 1
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    19
#include "profiles/mojoshader_profile.h"
17
78d605d6641d [svn] Starting to fill in D3D profile...
icculus
parents: 16
diff changeset
    20
82
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    21
// Deal with register lists...  !!! FIXME: I sort of hate this.
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    22
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 96
diff changeset
    23
static void free_reglist(MOJOSHADER_free f, void *d, RegisterList *item)
82
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    24
{
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    25
    while (item != NULL)
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    26
    {
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    27
        RegisterList *next = item->next;
97
4a41e3d17297 Allow instance data to be passed to the allocator.
Ryan C. Gordon <icculus@icculus.org>
parents: 96
diff changeset
    28
        f(item, d);
82
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    29
        item = next;
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    30
    } // while
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    31
} // free_reglist
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    32
122
e9da4ede0a27 Hopefully fixed loop register inheriting to subroutines.
Ryan C. Gordon <icculus@icculus.org>
parents: 121
diff changeset
    33
static inline const RegisterList *reglist_exists(RegisterList *prev,
e9da4ede0a27 Hopefully fixed loop register inheriting to subroutines.
Ryan C. Gordon <icculus@icculus.org>
parents: 121
diff changeset
    34
                                                 const RegisterType regtype,
e9da4ede0a27 Hopefully fixed loop register inheriting to subroutines.
Ryan C. Gordon <icculus@icculus.org>
parents: 121
diff changeset
    35
                                                 const int regnum)
e9da4ede0a27 Hopefully fixed loop register inheriting to subroutines.
Ryan C. Gordon <icculus@icculus.org>
parents: 121
diff changeset
    36
{
e9da4ede0a27 Hopefully fixed loop register inheriting to subroutines.
Ryan C. Gordon <icculus@icculus.org>
parents: 121
diff changeset
    37
    return (reglist_find(prev, regtype, regnum));
82
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    38
} // reglist_exists
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    39
1084
414c5019f0c6 Fail if Shader Model 1 pixel shaders don't write to r0.
Ryan C. Gordon <icculus@icculus.org>
parents: 1083
diff changeset
    40
static inline int register_was_written(Context *ctx, const RegisterType rtype,
414c5019f0c6 Fail if Shader Model 1 pixel shaders don't write to r0.
Ryan C. Gordon <icculus@icculus.org>
parents: 1083
diff changeset
    41
                                       const int regnum)
414c5019f0c6 Fail if Shader Model 1 pixel shaders don't write to r0.
Ryan C. Gordon <icculus@icculus.org>
parents: 1083
diff changeset
    42
{
414c5019f0c6 Fail if Shader Model 1 pixel shaders don't write to r0.
Ryan C. Gordon <icculus@icculus.org>
parents: 1083
diff changeset
    43
    RegisterList *reg = reglist_find(&ctx->used_registers, rtype, regnum);
414c5019f0c6 Fail if Shader Model 1 pixel shaders don't write to r0.
Ryan C. Gordon <icculus@icculus.org>
parents: 1083
diff changeset
    44
    return (reg && reg->written);
414c5019f0c6 Fail if Shader Model 1 pixel shaders don't write to r0.
Ryan C. Gordon <icculus@icculus.org>
parents: 1083
diff changeset
    45
} // register_was_written
414c5019f0c6 Fail if Shader Model 1 pixel shaders don't write to r0.
Ryan C. Gordon <icculus@icculus.org>
parents: 1083
diff changeset
    46
82
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    47
static inline int get_defined_register(Context *ctx, const RegisterType rtype,
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    48
                                       const int regnum)
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    49
{
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    50
    return (reglist_exists(&ctx->defined_registers, rtype, regnum) != NULL);
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    51
} // get_defined_register
dc7ad4cea75b Keep a list of used/defined registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 81
diff changeset
    52
104
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    53
static void add_attribute_register(Context *ctx, const RegisterType rtype,
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    54
                                const int regnum, const MOJOSHADER_usage usage,
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
    55
                                const int index, const int writemask, int flags)
104
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    56
{
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    57
    RegisterList *item = reglist_insert(ctx, &ctx->attributes, rtype, regnum);
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    58
    item->usage = usage;
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    59
    item->index = index;
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    60
    item->writemask = writemask;
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
    61
    item->misc = flags;
1054
63dd1a46ce13 Treat dcl_psize registers as scalar.
Ryan C. Gordon <icculus@icculus.org>
parents: 1052
diff changeset
    62
63dd1a46ce13 Treat dcl_psize registers as scalar.
Ryan C. Gordon <icculus@icculus.org>
parents: 1052
diff changeset
    63
    if ((rtype == REG_TYPE_OUTPUT) && (usage == MOJOSHADER_USAGE_POINTSIZE))
63dd1a46ce13 Treat dcl_psize registers as scalar.
Ryan C. Gordon <icculus@icculus.org>
parents: 1052
diff changeset
    64
        ctx->uses_pointsize = 1;  // note that we have to check this later.
1075
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1062
diff changeset
    65
    else if ((rtype == REG_TYPE_OUTPUT) && (usage == MOJOSHADER_USAGE_FOG))
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1062
diff changeset
    66
        ctx->uses_fog = 1;  // note that we have to check this later.
104
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    67
} // add_attribute_register
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
    68
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    69
static inline TextureType cvtMojoToD3DSamplerType(const MOJOSHADER_samplerType type)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    70
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    71
    return (TextureType) (((int) type) + 2);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    72
} // cvtMojoToD3DSamplerType
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    73
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    74
static inline MOJOSHADER_samplerType cvtD3DToMojoSamplerType(const TextureType type)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    75
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    76
    return (MOJOSHADER_samplerType) (((int) type) - 2);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    77
} // cvtD3DToMojoSamplerType
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
    78
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    79
static inline void add_sampler(Context *ctx, const int regnum,
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    80
                               TextureType ttype, const int texbem)
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    81
{
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    82
    const RegisterType rtype = REG_TYPE_SAMPLER;
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    83
297
16ec5a14777d Added a FIXME.
Ryan C. Gordon <icculus@icculus.org>
parents: 296
diff changeset
    84
    // !!! FIXME: make sure it doesn't exist?
1088
d2c20b029834 Implement ps_1_1 TEX opcode for arb1 and glsl profiles.
Ryan C. Gordon <icculus@icculus.org>
parents: 1087
diff changeset
    85
    // !!! FIXME:  (ps_1_1 assume we can add it multiple times...)
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
    86
    RegisterList *item = reglist_insert(ctx, &ctx->samplers, rtype, regnum);
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    87
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    88
    if (ctx->samplermap != NULL)
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    89
    {
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    90
        unsigned int i;
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    91
        for (i = 0; i < ctx->samplermap_count; i++)
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    92
        {
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    93
            if (ctx->samplermap[i].index == regnum)
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    94
            {
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    95
                ttype = cvtMojoToD3DSamplerType(ctx->samplermap[i].type);
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    96
                break;
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    97
            } // if
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    98
        } // for
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
    99
    } // if
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1103
diff changeset
   100
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   101
    item->index = (int) ttype;
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1089
diff changeset
   102
    item->misc |= texbem;
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   103
} // add_sampler
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   104
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   105
static inline void adjust_token_position(Context *ctx, const int incr)
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   106
{
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   107
    ctx->tokens += incr;
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   108
    ctx->tokencount -= incr;
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   109
    ctx->current_position += incr * sizeof (uint32);
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   110
} // adjust_token_position
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   111
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   112
// Generate emitter declarations for each profile with this macro...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   113
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   114
#define PREDECLARE_PROFILE(prof) \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   115
    void emit_##prof##_start(Context *ctx, const char *profilestr); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   116
    void emit_##prof##_end(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   117
    void emit_##prof##_phase(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   118
    void emit_##prof##_finalize(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   119
    void emit_##prof##_global(Context *ctx, RegisterType regtype, int regnum);\
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   120
    void emit_##prof##_array(Context *ctx, VariableList *var); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   121
    void emit_##prof##_const_array(Context *ctx, const ConstantsList *clist, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   122
                                   int base, int size); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   123
    void emit_##prof##_uniform(Context *ctx, RegisterType regtype, int regnum,\
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   124
                               const VariableList *var); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   125
    void emit_##prof##_sampler(Context *ctx, int stage, TextureType ttype, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   126
                               int tb); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   127
    void emit_##prof##_attribute(Context *ctx, RegisterType regtype, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   128
                                 int regnum, MOJOSHADER_usage usage, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   129
                                 int index, int wmask, int flags); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   130
    void emit_##prof##_NOP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   131
    void emit_##prof##_MOV(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   132
    void emit_##prof##_ADD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   133
    void emit_##prof##_SUB(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   134
    void emit_##prof##_MAD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   135
    void emit_##prof##_MUL(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   136
    void emit_##prof##_RCP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   137
    void emit_##prof##_RSQ(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   138
    void emit_##prof##_DP3(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   139
    void emit_##prof##_DP4(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   140
    void emit_##prof##_MIN(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   141
    void emit_##prof##_MAX(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   142
    void emit_##prof##_SLT(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   143
    void emit_##prof##_SGE(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   144
    void emit_##prof##_EXP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   145
    void emit_##prof##_LOG(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   146
    void emit_##prof##_LIT(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   147
    void emit_##prof##_DST(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   148
    void emit_##prof##_LRP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   149
    void emit_##prof##_FRC(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   150
    void emit_##prof##_M4X4(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   151
    void emit_##prof##_M4X3(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   152
    void emit_##prof##_M3X4(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   153
    void emit_##prof##_M3X3(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   154
    void emit_##prof##_M3X2(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   155
    void emit_##prof##_CALL(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   156
    void emit_##prof##_CALLNZ(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   157
    void emit_##prof##_LOOP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   158
    void emit_##prof##_ENDLOOP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   159
    void emit_##prof##_LABEL(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   160
    void emit_##prof##_DCL(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   161
    void emit_##prof##_POW(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   162
    void emit_##prof##_CRS(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   163
    void emit_##prof##_SGN(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   164
    void emit_##prof##_ABS(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   165
    void emit_##prof##_NRM(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   166
    void emit_##prof##_SINCOS(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   167
    void emit_##prof##_REP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   168
    void emit_##prof##_ENDREP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   169
    void emit_##prof##_IF(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   170
    void emit_##prof##_IFC(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   171
    void emit_##prof##_ELSE(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   172
    void emit_##prof##_ENDIF(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   173
    void emit_##prof##_BREAK(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   174
    void emit_##prof##_BREAKC(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   175
    void emit_##prof##_MOVA(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   176
    void emit_##prof##_DEFB(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   177
    void emit_##prof##_DEFI(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   178
    void emit_##prof##_TEXCRD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   179
    void emit_##prof##_TEXKILL(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   180
    void emit_##prof##_TEXLD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   181
    void emit_##prof##_TEXBEM(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   182
    void emit_##prof##_TEXBEML(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   183
    void emit_##prof##_TEXREG2AR(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   184
    void emit_##prof##_TEXREG2GB(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   185
    void emit_##prof##_TEXM3X2PAD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   186
    void emit_##prof##_TEXM3X2TEX(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   187
    void emit_##prof##_TEXM3X3PAD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   188
    void emit_##prof##_TEXM3X3TEX(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   189
    void emit_##prof##_TEXM3X3SPEC(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   190
    void emit_##prof##_TEXM3X3VSPEC(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   191
    void emit_##prof##_EXPP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   192
    void emit_##prof##_LOGP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   193
    void emit_##prof##_CND(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   194
    void emit_##prof##_DEF(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   195
    void emit_##prof##_TEXREG2RGB(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   196
    void emit_##prof##_TEXDP3TEX(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   197
    void emit_##prof##_TEXM3X2DEPTH(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   198
    void emit_##prof##_TEXDP3(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   199
    void emit_##prof##_TEXM3X3(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   200
    void emit_##prof##_TEXDEPTH(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   201
    void emit_##prof##_CMP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   202
    void emit_##prof##_BEM(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   203
    void emit_##prof##_DP2ADD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   204
    void emit_##prof##_DSX(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   205
    void emit_##prof##_DSY(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   206
    void emit_##prof##_TEXLDD(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   207
    void emit_##prof##_SETP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   208
    void emit_##prof##_TEXLDL(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   209
    void emit_##prof##_BREAKP(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   210
    void emit_##prof##_RESERVED(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   211
    void emit_##prof##_RET(Context *ctx); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   212
    const char *get_##prof##_varname(Context *ctx, RegisterType rt, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   213
                                     int regnum); \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   214
    const char *get_##prof##_const_array_varname(Context *ctx, \
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   215
                                                 int base, int size);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   216
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   217
// Check for profile support...
940
bc2a5efade5e Added a bunch of FIXMEs to accurately portray current technical debt.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   218
67
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   219
#define AT_LEAST_ONE_PROFILE 0
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   220
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   221
#if !SUPPORT_PROFILE_BYTECODE
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   222
#define PROFILE_EMITTER_BYTECODE(op)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   223
#else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   224
#undef AT_LEAST_ONE_PROFILE
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   225
#define AT_LEAST_ONE_PROFILE 1
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   226
#define PROFILE_EMITTER_BYTECODE(op) emit_BYTECODE_##op,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   227
PREDECLARE_PROFILE(BYTECODE)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   228
#endif
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   229
67
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   230
#if !SUPPORT_PROFILE_D3D
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   231
#define PROFILE_EMITTER_D3D(op)
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   232
#else
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   233
#undef AT_LEAST_ONE_PROFILE
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   234
#define AT_LEAST_ONE_PROFILE 1
cc42106d11ec Fixed dest arg output.
Ryan C. Gordon <icculus@icculus.org>
parents: 66
diff changeset
   235
#define PROFILE_EMITTER_D3D(op) emit_D3D_##op,
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   236
PREDECLARE_PROFILE(D3D)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   237
#endif
2
c37210f5e87b [svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents: 1
diff changeset
   238
1255
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   239
#if !SUPPORT_PROFILE_HLSL
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   240
#define PROFILE_EMITTER_HLSL(op)
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   241
#else
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   242
#undef AT_LEAST_ONE_PROFILE
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   243
#define AT_LEAST_ONE_PROFILE 1
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   244
#define PROFILE_EMITTER_HLSL(op) emit_HLSL_##op,
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   245
PREDECLARE_PROFILE(HLSL)
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   246
#endif
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   247
14
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   248
#if !SUPPORT_PROFILE_GLSL
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   249
#define PROFILE_EMITTER_GLSL(op)
14
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   250
#else
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   251
#undef AT_LEAST_ONE_PROFILE
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   252
#define AT_LEAST_ONE_PROFILE 1
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   253
#define PROFILE_EMITTER_GLSL(op) emit_GLSL_##op,
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   254
PREDECLARE_PROFILE(GLSL)
1173
4b2f745c643b GLSL: Use varyings when usage_str is NULL for vertex/pixel shaders
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1169
diff changeset
   255
#endif
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   256
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   257
#if !SUPPORT_PROFILE_METAL
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   258
#define PROFILE_EMITTER_METAL(op)
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   259
#else
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   260
#undef AT_LEAST_ONE_PROFILE
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   261
#define AT_LEAST_ONE_PROFILE 1
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   262
#define PROFILE_EMITTER_METAL(op) emit_METAL_##op,
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   263
PREDECLARE_PROFILE(METAL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   264
#endif
2
c37210f5e87b [svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents: 1
diff changeset
   265
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   266
#if !SUPPORT_PROFILE_ARB1
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   267
#define PROFILE_EMITTER_ARB1(op)
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   268
#else
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   269
#undef AT_LEAST_ONE_PROFILE
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   270
#define AT_LEAST_ONE_PROFILE 1
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   271
#define PROFILE_EMITTER_ARB1(op) emit_ARB1_##op,
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   272
PREDECLARE_PROFILE(ARB1)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   273
#endif
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   274
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   275
#if !SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   276
#define PROFILE_EMITTER_SPIRV(op)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   277
#else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   278
#undef AT_LEAST_ONE_PROFILE
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   279
#define AT_LEAST_ONE_PROFILE 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   280
#define PROFILE_EMITTER_SPIRV(op) emit_SPIRV_##op,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   281
PREDECLARE_PROFILE(SPIRV)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   282
#endif
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   283
14
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   284
#if !AT_LEAST_ONE_PROFILE
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   285
#error No profiles are supported. Fix your build.
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   286
#endif
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   287
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   288
#define DEFINE_PROFILE(prof) { \
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   289
    MOJOSHADER_PROFILE_##prof, \
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   290
    emit_##prof##_start, \
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   291
    emit_##prof##_end, \
400
05e384a14cd6 Implemented support for phase token.
Ryan C. Gordon <icculus@icculus.org>
parents: 399
diff changeset
   292
    emit_##prof##_phase, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   293
    emit_##prof##_global, \
402
933d71481f5b Better relative addressing support.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
   294
    emit_##prof##_array, \
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   295
    emit_##prof##_const_array, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   296
    emit_##prof##_uniform, \
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   297
    emit_##prof##_sampler, \
104
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   298
    emit_##prof##_attribute, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   299
    emit_##prof##_finalize, \
347
f8d9d0ae6ba8 Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents: 346
diff changeset
   300
    get_##prof##_varname, \
f8d9d0ae6ba8 Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents: 346
diff changeset
   301
    get_##prof##_const_array_varname, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   302
},
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   303
34
ca4b727ad2ce [svn] Chopped out a bunch of D3D2GLSL_ crap.
icculus
parents: 33
diff changeset
   304
static const Profile profiles[] =
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   305
{
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   306
#if SUPPORT_PROFILE_D3D
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   307
    DEFINE_PROFILE(D3D)
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   308
#endif
469
b8cfaae6c4af Renamed "passthrough" profile to "bytecode"
Ryan C. Gordon <icculus@icculus.org>
parents: 468
diff changeset
   309
#if SUPPORT_PROFILE_BYTECODE
b8cfaae6c4af Renamed "passthrough" profile to "bytecode"
Ryan C. Gordon <icculus@icculus.org>
parents: 468
diff changeset
   310
    DEFINE_PROFILE(BYTECODE)
109
48e95cf41505 Added "passthrough" profile, which just sends the bytecode through unchanged;
Ryan C. Gordon <icculus@icculus.org>
parents: 108
diff changeset
   311
#endif
1255
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   312
#if SUPPORT_PROFILE_HLSL
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   313
    DEFINE_PROFILE(HLSL)
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   314
#endif
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   315
#if SUPPORT_PROFILE_GLSL
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   316
    DEFINE_PROFILE(GLSL)
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   317
#endif
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   318
#if SUPPORT_PROFILE_ARB1
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   319
    DEFINE_PROFILE(ARB1)
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   320
#endif
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   321
#if SUPPORT_PROFILE_METAL
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   322
    DEFINE_PROFILE(METAL)
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   323
#endif
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   324
#if SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   325
    DEFINE_PROFILE(SPIRV)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   326
#endif
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   327
};
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   328
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   329
#undef DEFINE_PROFILE
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   330
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   331
// This is for profiles that extend other profiles...
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   332
static const struct { const char *from; const char *to; } profileMap[] =
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   333
{
1225
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   334
    { MOJOSHADER_PROFILE_GLSPIRV, MOJOSHADER_PROFILE_SPIRV },
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
   335
    { MOJOSHADER_PROFILE_GLSLES, MOJOSHADER_PROFILE_GLSL },
407
620d48c5d13a Added framework for GLSL 1.20 support.
Ryan C. Gordon <icculus@icculus.org>
parents: 405
diff changeset
   336
    { MOJOSHADER_PROFILE_GLSL120, MOJOSHADER_PROFILE_GLSL },
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   337
    { MOJOSHADER_PROFILE_NV2, MOJOSHADER_PROFILE_ARB1 },
430
2756be459ea1 Forgot to add nv3 to arb1 profile mapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 429
diff changeset
   338
    { MOJOSHADER_PROFILE_NV3, MOJOSHADER_PROFILE_ARB1 },
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
   339
    { MOJOSHADER_PROFILE_NV4, MOJOSHADER_PROFILE_ARB1 },
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   340
};
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   341
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   342
// The PROFILE_EMITTER_* items MUST be in the same order as profiles[]!
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   343
#define PROFILE_EMITTERS(op) { \
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   344
     PROFILE_EMITTER_D3D(op) \
469
b8cfaae6c4af Renamed "passthrough" profile to "bytecode"
Ryan C. Gordon <icculus@icculus.org>
parents: 468
diff changeset
   345
     PROFILE_EMITTER_BYTECODE(op) \
1255
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1254
diff changeset
   346
     PROFILE_EMITTER_HLSL(op) \
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   347
     PROFILE_EMITTER_GLSL(op) \
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   348
     PROFILE_EMITTER_ARB1(op) \
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   349
     PROFILE_EMITTER_METAL(op) \
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   350
     PROFILE_EMITTER_SPIRV(op) \
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   351
}
2
c37210f5e87b [svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents: 1
diff changeset
   352
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   353
static int parse_destination_token(Context *ctx, DestArgInfo *info)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   354
{
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   355
    // !!! FIXME: recheck against the spec for ranges (like RASTOUT values, etc).
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   356
    if (ctx->tokencount == 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   357
    {
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   358
        fail(ctx, "Out of tokens in destination parameter");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   359
        return 0;
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   360
    } // if
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   361
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   362
    const uint32 token = SWAP32(*(ctx->tokens));
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   363
    const int reserved1 = (int) ((token >> 14) & 0x3); // bits 14 through 15
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   364
    const int reserved2 = (int) ((token >> 31) & 0x1); // bit 31
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   365
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   366
    info->token = ctx->tokens;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   367
    info->regnum = (int) (token & 0x7ff);  // bits 0 through 10
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   368
    info->relative = (int) ((token >> 13) & 0x1); // bit 13
316
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   369
    info->orig_writemask = (int) ((token >> 16) & 0xF); // bits 16 through 19
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   370
    info->result_mod = (int) ((token >> 20) & 0xF); // bits 20 through 23
56
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   371
    info->result_shift = (int) ((token >> 24) & 0xF); // bits 24 through 27      abc
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   372
    info->regtype = (RegisterType) (((token >> 28) & 0x7) | ((token >> 8) & 0x18));  // bits 28-30, 11-12
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   373
316
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   374
    int writemask;
1054
63dd1a46ce13 Treat dcl_psize registers as scalar.
Ryan C. Gordon <icculus@icculus.org>
parents: 1052
diff changeset
   375
    if (isscalar(ctx, ctx->shader_type, info->regtype, info->regnum))
316
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   376
        writemask = 0x1;  // just x.
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   377
    else
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   378
        writemask = info->orig_writemask;
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   379
1077
57e18783574e Cleaned up some cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 1076
diff changeset
   380
    set_dstarg_writemask(info, writemask);  // bits 16 through 19.
316
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   381
234
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   382
    // all the REG_TYPE_CONSTx types are the same register type, it's just
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   383
    //  split up so its regnum can be > 2047 in the bytecode. Clean it up.
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   384
    if (info->regtype == REG_TYPE_CONST2)
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   385
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   386
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   387
        info->regnum += 2048;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   388
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   389
    else if (info->regtype == REG_TYPE_CONST3)
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   390
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   391
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   392
        info->regnum += 4096;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   393
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   394
    else if (info->regtype == REG_TYPE_CONST4)
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   395
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   396
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   397
        info->regnum += 6144;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   398
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   399
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   400
    // swallow token for now, for multiple calls in a row.
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   401
    adjust_token_position(ctx, 1);
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   402
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   403
    if (reserved1 != 0x0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   404
        fail(ctx, "Reserved bit #1 in destination token must be zero");
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   405
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   406
    if (reserved2 != 0x1)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   407
        fail(ctx, "Reserved bit #2 in destination token must be one");
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   408
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   409
    if (info->relative)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   410
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   411
        if (!shader_is_vertex(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   412
            fail(ctx, "Relative addressing in non-vertex shader");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   413
        if (!shader_version_atleast(ctx, 3, 0))
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   414
            fail(ctx, "Relative addressing in vertex shader version < 3.0");
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   415
        if ((!ctx->ctab.have_ctab) && (!ctx->ignores_ctab))
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   416
        {
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   417
            // it's hard to do this efficiently without!
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   418
            fail(ctx, "relative addressing unsupported without a CTAB");
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   419
        } // if
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   420
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   421
        // !!! FIXME: I don't have a shader that has a relative dest currently.
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   422
        fail(ctx, "Relative addressing of dest tokens is unsupported");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   423
        return 2;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   424
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   425
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   426
    const int s = info->result_shift;
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   427
    if (s != 0)
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   428
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   429
        if (!shader_is_pixel(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   430
            fail(ctx, "Result shift scale in non-pixel shader");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   431
        if (shader_version_atleast(ctx, 2, 0))
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   432
            fail(ctx, "Result shift scale in pixel shader version >= 2.0");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   433
        if ( ! (((s >= 1) && (s <= 3)) || ((s >= 0xD) && (s <= 0xF))) )
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   434
            fail(ctx, "Result shift scale isn't 1 to 3, or 13 to 15.");
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   435
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   436
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   437
    if (info->result_mod & MOD_PP)  // Partial precision (pixel shaders only)
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   438
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   439
        if (!shader_is_pixel(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   440
            fail(ctx, "Partial precision result mod in non-pixel shader");
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   441
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   442
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   443
    if (info->result_mod & MOD_CENTROID)  // Centroid (pixel shaders only)
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   444
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   445
        if (!shader_is_pixel(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   446
            fail(ctx, "Centroid result mod in non-pixel shader");
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
   447
        else if (!ctx->centroid_allowed)  // only on DCL opcodes!
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   448
            fail(ctx, "Centroid modifier not allowed here");
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   449
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   450
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1155
diff changeset
   451
    if (/*(info->regtype < 0) ||*/ (info->regtype > REG_TYPE_MAX))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   452
        fail(ctx, "Register type is out of range");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   453
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   454
    if (!isfail(ctx))
1083
af2182ddc559 Note whether a given register was written to by the shader.
Ryan C. Gordon <icculus@icculus.org>
parents: 1082
diff changeset
   455
        set_used_register(ctx, info->regtype, info->regnum, 1);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   456
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   457
    return 1;
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   458
} // parse_destination_token
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   459
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   460
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   461
static void determine_constants_arrays(Context *ctx)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   462
{
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   463
    // Only process this stuff once. This is called after all DEF* opcodes
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   464
    //  could have been parsed.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   465
    if (ctx->determined_constants_arrays)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   466
        return;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   467
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   468
    ctx->determined_constants_arrays = 1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   469
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   470
    if (ctx->constant_count <= 1)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   471
        return;  // nothing to sort or group.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   472
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   473
    // Sort the linked list into an array for easier tapdancing...
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   474
    ConstantsList **array = (ConstantsList **) alloca(sizeof (ConstantsList *) * (ctx->constant_count + 1));
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   475
    ConstantsList *item = ctx->constants;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   476
    int i;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   477
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   478
    for (i = 0; i < ctx->constant_count; i++)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   479
    {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   480
        if (item == NULL)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   481
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   482
            fail(ctx, "BUG: mismatched constant list and count");
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   483
            return;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   484
        } // if
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   485
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   486
        array[i] = item;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   487
        item = item->next;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   488
    } // for
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   489
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   490
    array[ctx->constant_count] = NULL;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   491
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   492
    // bubble sort ftw.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   493
    int sorted;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   494
    do
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   495
    {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   496
        sorted = 1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   497
        for (i = 0; i < ctx->constant_count-1; i++)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   498
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   499
            if (array[i]->constant.index > array[i+1]->constant.index)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   500
            {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   501
                ConstantsList *tmp = array[i];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   502
                array[i] = array[i+1];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   503
                array[i+1] = tmp;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   504
                sorted = 0;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   505
            } // if
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   506
        } // for
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   507
    } while (!sorted);
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   508
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   509
    // okay, sorted. While we're here, let's redo the linked list in order...
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   510
    for (i = 0; i < ctx->constant_count; i++)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   511
        array[i]->next = array[i+1];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   512
    ctx->constants = array[0];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   513
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   514
    // now figure out the groupings of constants and add to ctx->variables...
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   515
    int start = -1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   516
    int prev = -1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   517
    int count = 0;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   518
    const int hi = ctx->constant_count;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   519
    for (i = 0; i <= hi; i++)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   520
    {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   521
        if (array[i] && (array[i]->constant.type != MOJOSHADER_UNIFORM_FLOAT))
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   522
            continue;  // we only care about REG_TYPE_CONST for array groups.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   523
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   524
        if (start == -1)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   525
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   526
            prev = start = i;  // first REG_TYPE_CONST we've seen. Mark it!
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   527
            continue;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   528
        } // if
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   529
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   530
        // not a match (or last item in the array)...see if we had a
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   531
        //  contiguous set before this point...
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   532
        if ( (array[i]) && (array[i]->constant.index == (array[prev]->constant.index + 1)) )
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   533
            count++;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   534
        else
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   535
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   536
            if (count > 0)  // multiple constants in the set?
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   537
            {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   538
                VariableList *var;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   539
                var = (VariableList *) Malloc(ctx, sizeof (VariableList));
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   540
                if (var == NULL)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   541
                    break;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   542
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   543
                var->type = MOJOSHADER_UNIFORM_FLOAT;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   544
                var->index = array[start]->constant.index;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   545
                var->count = (array[prev]->constant.index - var->index) + 1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   546
                var->constant = array[start];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   547
                var->used = 0;
760
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 758
diff changeset
   548
                var->emit_position = -1;
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   549
                var->next = ctx->variables;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   550
                ctx->variables = var;
1223
32ab7e4fbdc6 Various style/redundancy fixes found during SPIR-V work
Martin Krošlák <kroslakma@gmail.com>
parents: 1206
diff changeset
   551
            } // if
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   552
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   553
            start = i;   // set this as new start of sequence.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   554
        } // if
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   555
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   556
        prev = i;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   557
    } // for
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   558
} // determine_constants_arrays
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   559
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   560
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   561
static int adjust_swizzle(const Context *ctx, const RegisterType regtype,
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   562
                          const int regnum, const int swizzle)
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   563
{
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   564
    if (regtype != REG_TYPE_INPUT)  // !!! FIXME: maybe lift this later?
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   565
        return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   566
    else if (ctx->swizzles_count == 0)
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   567
        return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   568
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   569
    const RegisterList *reg = reglist_find(&ctx->attributes, regtype, regnum);
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   570
    if (reg == NULL)
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   571
        return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   572
798
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 776
diff changeset
   573
    size_t i;
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 776
diff changeset
   574
    for (i = 0; i < ctx->swizzles_count; i++)
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 776
diff changeset
   575
    {
5dd67cc04cf9 Bunch of small tweaks to make this compile as C++ code without errors/warnings.
Ryan C. Gordon <icculus@icculus.org>
parents: 776
diff changeset
   576
        const MOJOSHADER_swizzle *swiz = &ctx->swizzles[i];
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   577
        if ((swiz->usage == reg->usage) && (swiz->index == reg->index))
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   578
        {
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   579
            return ( (((int)(swiz->swizzles[((swizzle >> 0) & 0x3)])) << 0) |
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   580
                     (((int)(swiz->swizzles[((swizzle >> 2) & 0x3)])) << 2) |
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   581
                     (((int)(swiz->swizzles[((swizzle >> 4) & 0x3)])) << 4) |
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   582
                     (((int)(swiz->swizzles[((swizzle >> 6) & 0x3)])) << 6) );
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   583
        } // if
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   584
    } // for
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   585
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   586
    return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   587
} // adjust_swizzle
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   588
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   589
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   590
static int parse_source_token(Context *ctx, SourceArgInfo *info)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   591
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   592
    int retval = 1;
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   593
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   594
    if (ctx->tokencount == 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   595
    {
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   596
        fail(ctx, "Out of tokens in source parameter");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   597
        return 0;
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   598
    } // if
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   599
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   600
    const uint32 token = SWAP32(*(ctx->tokens));
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   601
    const int reserved1 = (int) ((token >> 14) & 0x3); // bits 14 through 15
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   602
    const int reserved2 = (int) ((token >> 31) & 0x1); // bit 31
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   603
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   604
    info->token = ctx->tokens;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   605
    info->regnum = (int) (token & 0x7ff);  // bits 0 through 10
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   606
    info->relative = (int) ((token >> 13) & 0x1); // bit 13
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   607
    const int swizzle = (int) ((token >> 16) & 0xFF); // bits 16 through 23
139
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   608
    info->src_mod = (SourceMod) ((token >> 24) & 0xF); // bits 24 through 27
56
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   609
    info->regtype = (RegisterType) (((token >> 28) & 0x7) | ((token >> 8) & 0x18));  // bits 28-30, 11-12
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   610
234
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   611
    // all the REG_TYPE_CONSTx types are the same register type, it's just
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   612
    //  split up so its regnum can be > 2047 in the bytecode. Clean it up.
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   613
    if (info->regtype == REG_TYPE_CONST2)
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   614
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   615
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   616
        info->regnum += 2048;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   617
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   618
    else if (info->regtype == REG_TYPE_CONST3)
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   619
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   620
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   621
        info->regnum += 4096;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   622
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   623
    else if (info->regtype == REG_TYPE_CONST4)
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   624
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   625
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   626
        info->regnum += 6144;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   627
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   628
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   629
    info->swizzle = adjust_swizzle(ctx, info->regtype, info->regnum, swizzle);
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   630
    info->swizzle_x = ((info->swizzle >> 0) & 0x3);
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   631
    info->swizzle_y = ((info->swizzle >> 2) & 0x3);
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   632
    info->swizzle_z = ((info->swizzle >> 4) & 0x3);
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   633
    info->swizzle_w = ((info->swizzle >> 6) & 0x3);
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   634
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   635
    // swallow token for now, for multiple calls in a row.
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   636
    adjust_token_position(ctx, 1);
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   637
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   638
    if (reserved1 != 0x0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   639
        fail(ctx, "Reserved bits #1 in source token must be zero");
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   640
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   641
    if (reserved2 != 0x1)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   642
        fail(ctx, "Reserved bit #2 in source token must be one");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   643
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   644
    if ((info->relative) && (ctx->tokencount == 0))
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   645
    {
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   646
        fail(ctx, "Out of tokens in relative source parameter");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   647
        info->relative = 0;  // don't try to process it.
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   648
    } // if
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   649
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   650
    if (info->relative)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   651
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   652
        if ( (shader_is_pixel(ctx)) && (!shader_version_atleast(ctx, 3, 0)) )
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   653
            fail(ctx, "Relative addressing in pixel shader version < 3.0");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   654
1139
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   655
        // Shader Model 1 doesn't have an extra token to specify the
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   656
        //  relative register: it's always a0.x.
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   657
        if (!shader_version_atleast(ctx, 2, 0))
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   658
        {
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   659
            info->relative_regnum = 0;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   660
            info->relative_regtype = REG_TYPE_ADDRESS;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   661
            info->relative_component = 0;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   662
        } // if
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   663
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   664
        else  // Shader Model 2 and later...
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   665
        {
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   666
            const uint32 reltoken = SWAP32(*(ctx->tokens));
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   667
            // swallow token for now, for multiple calls in a row.
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   668
            adjust_token_position(ctx, 1);
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   669
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   670
            const int relswiz = (int) ((reltoken >> 16) & 0xFF);
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   671
            info->relative_regnum = (int) (reltoken & 0x7ff);
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   672
            info->relative_regtype = (RegisterType)
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   673
                                        (((reltoken >> 28) & 0x7) |
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   674
                                        ((reltoken >> 8) & 0x18));
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   675
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   676
            if (((reltoken >> 31) & 0x1) == 0)
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   677
                fail(ctx, "bit #31 in relative address must be set");
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   678
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   679
            if ((reltoken & 0xF00E000) != 0)  // usused bits.
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   680
                fail(ctx, "relative address reserved bit must be zero");
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   681
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   682
            switch (info->relative_regtype)
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   683
            {
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   684
                case REG_TYPE_LOOP:
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   685
                case REG_TYPE_ADDRESS:
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   686
                    break;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   687
                default:
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   688
                    fail(ctx, "invalid register for relative address");
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   689
                    break;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   690
            } // switch
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   691
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   692
            if (info->relative_regnum != 0)  // true for now.
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   693
                fail(ctx, "invalid register for relative address");
1139
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   694
1190
51de95edd697 Loop register should not have swizzling
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1188
diff changeset
   695
            if ( (info->relative_regtype != REG_TYPE_LOOP) && !replicate_swizzle(relswiz) )
1139
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   696
                fail(ctx, "relative address needs replicate swizzle");
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   697
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   698
            info->relative_component = (relswiz & 0x3);
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   699
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   700
            retval++;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   701
        } // else
1061
dbf2735676ae Set relative_component correctly when parsing source registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1060
diff changeset
   702
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   703
        if (info->regtype == REG_TYPE_INPUT)
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   704
        {
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   705
            if ( (shader_is_pixel(ctx)) || (!shader_version_atleast(ctx, 3, 0)) )
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   706
                fail(ctx, "relative addressing of input registers not supported in this shader model");
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   707
            ctx->have_relative_input_registers = 1;
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   708
        } // if
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   709
        else if (info->regtype == REG_TYPE_CONST)
402
933d71481f5b Better relative addressing support.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
   710
        {
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   711
            // figure out what array we're in...
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   712
            if (!ctx->ignores_ctab)
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   713
            {
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   714
                if (!ctx->ctab.have_ctab)  // hard to do efficiently without!
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   715
                    fail(ctx, "relative addressing unsupported without a CTAB");
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   716
                else
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   717
                {
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   718
                    determine_constants_arrays(ctx);
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   719
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   720
                    VariableList *var;
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   721
                    const int reltarget = info->regnum;
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   722
                    for (var = ctx->variables; var != NULL; var = var->next)
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   723
                    {
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   724
                        const int lo = var->index;
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   725
                        if ( (reltarget >= lo) && (reltarget < (lo + var->count)) )
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   726
                            break;  // match!
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   727
                    } // for
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   728
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   729
                    if (var == NULL)
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   730
                        fail(ctx, "relative addressing of indeterminate array");
1060
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   731
                    else
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   732
                    {
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   733
                        var->used = 1;
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   734
                        info->relative_array = var;
1083
af2182ddc559 Note whether a given register was written to by the shader.
Ryan C. Gordon <icculus@icculus.org>
parents: 1082
diff changeset
   735
                        set_used_register(ctx, info->relative_regtype, info->relative_regnum, 0);
1060
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   736
                    } // else
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   737
                } // else
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   738
            } // if
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   739
        } // else if
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   740
        else
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   741
        {
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   742
            fail(ctx, "relative addressing of invalid register");
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   743
        } // else
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   744
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   745
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   746
    switch (info->src_mod)
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   747
    {
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   748
        case SRCMOD_NONE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   749
        case SRCMOD_ABSNEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   750
        case SRCMOD_ABS:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   751
        case SRCMOD_NEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   752
            break; // okay in any shader model.
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   753
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   754
        // apparently these are only legal in Shader Model 1.x ...
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   755
        case SRCMOD_BIASNEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   756
        case SRCMOD_BIAS:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   757
        case SRCMOD_SIGNNEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   758
        case SRCMOD_SIGN:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   759
        case SRCMOD_COMPLEMENT:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   760
        case SRCMOD_X2NEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   761
        case SRCMOD_X2:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   762
        case SRCMOD_DZ:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   763
        case SRCMOD_DW:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   764
            if (shader_version_atleast(ctx, 2, 0))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   765
                fail(ctx, "illegal source mod for this Shader Model.");
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   766
            break;
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   767
494
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   768
        case SRCMOD_NOT:  // !!! FIXME: I _think_ this is right...
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   769
            if (shader_version_atleast(ctx, 2, 0))
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   770
            {
1183
ec44ee868688 Minor fixes from FNA branch
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1182
diff changeset
   771
                if (info->regtype != REG_TYPE_PREDICATE
ec44ee868688 Minor fixes from FNA branch
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1182
diff changeset
   772
                 && info->regtype != REG_TYPE_CONSTBOOL)
ec44ee868688 Minor fixes from FNA branch
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1182
diff changeset
   773
                    fail(ctx, "NOT only allowed on bool registers.");
494
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   774
            } // if
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   775
            break;
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   776
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   777
        default:
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   778
            fail(ctx, "Unknown source modifier");
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   779
    } // switch
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   780
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   781
    // !!! FIXME: docs say this for sm3 ... check these!
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   782
    //  "The negate modifier cannot be used on second source register of these
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   783
    //   instructions: m3x2 - ps, m3x3 - ps, m3x4 - ps, m4x3 - ps, and
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   784
    //   m4x4 - ps."
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   785
    //  "If any version 3 shader reads from one or more constant float
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   786
    //   registers (c#), one of the following must be true.
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   787
    //    All of the constant floating-point registers must use the abs modifier.
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   788
    //    None of the constant floating-point registers can use the abs modifier.
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   789
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   790
    if (!isfail(ctx))
1085
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   791
    {
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   792
        RegisterList *reg;
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   793
        reg = set_used_register(ctx, info->regtype, info->regnum, 0);
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   794
        // !!! FIXME: this test passes if you write to the register
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   795
        // !!! FIXME:  in this same instruction, because we parse the
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   796
        // !!! FIXME:  destination token first.
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   797
        // !!! FIXME: Microsoft's shader validation explicitly checks temp
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   798
        // !!! FIXME:  registers for this...do they check other writable ones?
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   799
        if ((info->regtype == REG_TYPE_TEMP) && (reg) && (!reg->written))
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   800
            failf(ctx, "Temp register r%d used uninitialized", info->regnum);
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   801
    } // if
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   802
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   803
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   804
} // parse_source_token
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   805
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   806
139
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   807
static int parse_predicated_token(Context *ctx)
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   808
{
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   809
    SourceArgInfo *arg = &ctx->predicate_arg;
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   810
    parse_source_token(ctx, arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   811
    if (arg->regtype != REG_TYPE_PREDICATE)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   812
        fail(ctx, "Predicated instruction but not predicate register!");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   813
    if ((arg->src_mod != SRCMOD_NONE) && (arg->src_mod != SRCMOD_NOT))
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   814
        fail(ctx, "Predicated instruction register is not NONE or NOT");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   815
    if ( !no_swizzle(arg->swizzle) && !replicate_swizzle(arg->swizzle) )
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   816
        fail(ctx, "Predicated instruction register has wrong swizzle");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   817
    if (arg->relative)  // I'm pretty sure this is illegal...?
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   818
        fail(ctx, "relative addressing in predicated token");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   819
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   820
    return 1;
139
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   821
} // parse_predicated_token
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   822
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   823
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   824
static int parse_args_NULL(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   825
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   826
    return 1;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   827
} // parse_args_NULL
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   828
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   829
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   830
static int parse_args_DEF(Context *ctx)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   831
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   832
    parse_destination_token(ctx, &ctx->dest_arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   833
    if (ctx->dest_arg.regtype != REG_TYPE_CONST)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   834
        fail(ctx, "DEF using non-CONST register");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   835
    if (ctx->dest_arg.relative)  // I'm pretty sure this is illegal...?
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   836
        fail(ctx, "relative addressing in DEF");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   837
56
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   838
    ctx->dwords[0] = SWAP32(ctx->tokens[0]);
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   839
    ctx->dwords[1] = SWAP32(ctx->tokens[1]);
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   840
    ctx->dwords[2] = SWAP32(ctx->tokens[2]);
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   841
    ctx->dwords[3] = SWAP32(ctx->tokens[3]);
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   842
49
780cd8790dff [svn] args_function implementations should return total token usage for the opcode,
icculus
parents: 48
diff changeset
   843
    return 6;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   844
} // parse_args_DEF
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   845
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   846
466
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   847
static int parse_args_DEFI(Context *ctx)
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   848
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   849
    parse_destination_token(ctx, &ctx->dest_arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   850
    if (ctx->dest_arg.regtype != REG_TYPE_CONSTINT)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   851
        fail(ctx, "DEFI using non-CONSTING register");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   852
    if (ctx->dest_arg.relative)  // I'm pretty sure this is illegal...?
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   853
        fail(ctx, "relative addressing in DEFI");
466
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   854
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   855
    ctx->dwords[0] = SWAP32(ctx->tokens[0]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   856
    ctx->dwords[1] = SWAP32(ctx->tokens[1]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   857
    ctx->dwords[2] = SWAP32(ctx->tokens[2]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   858
    ctx->dwords[3] = SWAP32(ctx->tokens[3]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   859
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   860
    return 6;
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   861
} // parse_args_DEFI
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   862
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   863
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   864
static int parse_args_DEFB(Context *ctx)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   865
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   866
    parse_destination_token(ctx, &ctx->dest_arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   867
    if (ctx->dest_arg.regtype != REG_TYPE_CONSTBOOL)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   868
        fail(ctx, "DEFB using non-CONSTBOOL register");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   869
    if (ctx->dest_arg.relative)  // I'm pretty sure this is illegal...?
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   870
        fail(ctx, "relative addressing in DEFB");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   871
56
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   872
    ctx->dwords[0] = *(ctx->tokens) ? 1 : 0;
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   873
49
780cd8790dff [svn] args_function implementations should return total token usage for the opcode,
icculus
parents: 48
diff changeset
   874
    return 3;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   875
} // parse_args_DEFB
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   876
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   877
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   878
static int valid_texture_type(const uint32 ttype)
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   879
{
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   880
    switch ((const TextureType) ttype)
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   881
    {
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   882
        case TEXTURE_TYPE_2D:
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   883
        case TEXTURE_TYPE_CUBE:
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   884
        case TEXTURE_TYPE_VOLUME:
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   885
            return 1;  // it's okay.
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   886
    } // switch
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   887
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   888
    return 0;
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   889
} // valid_texture_type
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   890
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   891
154
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   892
// !!! FIXME: this function is kind of a mess.
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   893
static int parse_args_DCL(Context *ctx)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   894
{
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   895
    int unsupported = 0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   896
    const uint32 token = SWAP32(*(ctx->tokens));
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   897
    const int reserved1 = (int) ((token >> 31) & 0x1); // bit 31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   898
    uint32 reserved_mask = 0x00000000;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   899
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   900
    if (reserved1 != 0x1)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   901
        fail(ctx, "Bit #31 in DCL token must be one");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   902
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
   903
    ctx->centroid_allowed = 1;
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   904
    adjust_token_position(ctx, 1);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   905
    parse_destination_token(ctx, &ctx->dest_arg);
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
   906
    ctx->centroid_allowed = 0;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   907
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   908
    if (ctx->dest_arg.result_shift != 0)  // I'm pretty sure this is illegal...?
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   909
        fail(ctx, "shift scale in DCL");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   910
    if (ctx->dest_arg.relative)  // I'm pretty sure this is illegal...?
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   911
        fail(ctx, "relative addressing in DCL");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   912
161
a0e1920ce909 Removed "dest_args" array...it's only ever one structure.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
   913
    const RegisterType regtype = ctx->dest_arg.regtype;
a0e1920ce909 Removed "dest_args" array...it's only ever one structure.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
   914
    const int regnum = ctx->dest_arg.regnum;
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   915
    if ( (shader_is_pixel(ctx)) && (shader_version_atleast(ctx, 3, 0)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   916
    {
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   917
        if (regtype == REG_TYPE_INPUT)
154
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   918
        {
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   919
            const uint32 usage = (token & 0xF);
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   920
            const uint32 index = ((token >> 16) & 0xF);
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   921
            reserved_mask = 0x7FF0FFE0;
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   922
            ctx->dwords[0] = usage;
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   923
            ctx->dwords[1] = index;
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   924
        } // if
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   925
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   926
        else if (regtype == REG_TYPE_MISCTYPE)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   927
        {
83
ce46250e553d Add defined/declared registers to the appropriate register list.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
   928
            const MiscTypeType mt = (MiscTypeType) regnum;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   929
            if (mt == MISCTYPE_TYPE_POSITION)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   930
                reserved_mask = 0x7FFFFFFF;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   931
            else if (mt == MISCTYPE_TYPE_FACE)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   932
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   933
                reserved_mask = 0x7FFFFFFF;
316
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   934
                if (!writemask_xyzw(ctx->dest_arg.orig_writemask))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   935
                    fail(ctx, "DCL face writemask must be full");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   936
                if (ctx->dest_arg.result_mod != 0)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   937
                    fail(ctx, "DCL face result modifier must be zero");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   938
                if (ctx->dest_arg.result_shift != 0)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   939
                    fail(ctx, "DCL face shift scale must be zero");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   940
            } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   941
            else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   942
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   943
                unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   944
            } // else
317
74a9f3ae4534 Support for vFace and vPos registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   945
74a9f3ae4534 Support for vFace and vPos registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   946
            ctx->dwords[0] = (uint32) MOJOSHADER_USAGE_UNKNOWN;
74a9f3ae4534 Support for vFace and vPos registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   947
            ctx->dwords[1] = 0;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   948
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   949
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   950
        else if (regtype == REG_TYPE_TEXTURE)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   951
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   952
            const uint32 usage = (token & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   953
            const uint32 index = ((token >> 16) & 0xF);
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 99
diff changeset
   954
            if (usage == MOJOSHADER_USAGE_TEXCOORD)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   955
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   956
                if (index > 7)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   957
                    fail(ctx, "DCL texcoord usage must have 0-7 index");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   958
            } // if
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 99
diff changeset
   959
            else if (usage == MOJOSHADER_USAGE_COLOR)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   960
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   961
                if (index != 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   962
                    fail(ctx, "DCL color usage must have 0 index");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   963
            } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   964
            else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   965
            {
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   966
                fail(ctx, "Invalid DCL texture usage");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   967
            } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   968
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   969
            reserved_mask = 0x7FF0FFE0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   970
            ctx->dwords[0] = usage;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   971
            ctx->dwords[1] = index;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   972
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   973
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   974
        else if (regtype == REG_TYPE_SAMPLER)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   975
        {
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   976
            const uint32 ttype = ((token >> 27) & 0xF);
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   977
            if (!valid_texture_type(ttype))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   978
                fail(ctx, "unknown sampler texture type");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   979
            reserved_mask = 0x7FFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   980
            ctx->dwords[0] = ttype;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   981
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   982
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   983
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   984
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   985
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   986
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   987
    } // if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   988
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   989
    else if ( (shader_is_pixel(ctx)) && (shader_version_atleast(ctx, 2, 0)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   990
    {
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   991
        if (regtype == REG_TYPE_INPUT)
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   992
        {
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   993
            ctx->dwords[0] = (uint32) MOJOSHADER_USAGE_COLOR;
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   994
            ctx->dwords[1] = regnum;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   995
            reserved_mask = 0x7FFFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   996
        } // if
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   997
        else if (regtype == REG_TYPE_TEXTURE)
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   998
        {
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   999
            ctx->dwords[0] = (uint32) MOJOSHADER_USAGE_TEXCOORD;
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
  1000
            ctx->dwords[1] = regnum;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1001
            reserved_mask = 0x7FFFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
  1002
        } // else if
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1003
        else if (regtype == REG_TYPE_SAMPLER)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1004
        {
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
  1005
            const uint32 ttype = ((token >> 27) & 0xF);
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
  1006
            if (!valid_texture_type(ttype))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1007
                fail(ctx, "unknown sampler texture type");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1008
            reserved_mask = 0x7FFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
  1009
            ctx->dwords[0] = ttype;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1010
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1011
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1012
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1013
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1014
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1015
    } // if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1016
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
  1017
    else if ( (shader_is_vertex(ctx)) && (shader_version_atleast(ctx, 3, 0)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1018
    {
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 99
diff changeset
  1019
        if ((regtype == REG_TYPE_INPUT) || (regtype == REG_TYPE_OUTPUT))
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1020
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1021
            const uint32 usage = (token & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1022
            const uint32 index = ((token >> 16) & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1023
            reserved_mask = 0x7FF0FFE0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1024
            ctx->dwords[0] = usage;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1025
            ctx->dwords[1] = index;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1026
        } // if
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1027
        else if (regtype == REG_TYPE_TEXTURE)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1028
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1029
            const uint32 usage = (token & 0xF);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1030
            const uint32 index = ((token >> 16) & 0xF);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1031
            if (usage == MOJOSHADER_USAGE_TEXCOORD)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1032
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1033
                if (index > 7)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1034
                    fail(ctx, "DCL texcoord usage must have 0-7 index");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1035
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1036
            else if (usage == MOJOSHADER_USAGE_COLOR)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1037
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1038
                if (index != 0)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1039
                    fail(ctx, "DCL texcoord usage must have 0 index");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1040
            } // else if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1041
            else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1042
                fail(ctx, "Invalid DCL texture usage");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1043
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1044
            reserved_mask = 0x7FF0FFE0;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1045
            ctx->dwords[0] = usage;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1046
            ctx->dwords[1] = index;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1047
        } // else if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1048
        else if (regtype == REG_TYPE_SAMPLER)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1049
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1050
            const uint32 ttype = ((token >> 27) & 0xF);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1051
            if (!valid_texture_type(ttype))
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1052
                fail(ctx, "Unknown sampler texture type");
1261
3405ca546164 Fix vertex sampler reserved mask for 3D/cube textures
Bart van der Werf <bluelive@gmail.com>
parents: 1255
diff changeset
  1053
            reserved_mask = 0x0FFFFFFF;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1054
            ctx->dwords[0] = ttype;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1055
        } // else if
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1056
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1057
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1058
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1059
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1060
    } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1061
803
cfd14c5f187a vs_1_1 also has decls on D3D9
Aras Pranckevicius <aras@unity3d.com>
parents: 802
diff changeset
  1062
    else if ( (shader_is_vertex(ctx)) && (shader_version_atleast(ctx, 1, 1)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1063
    {
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1064
        if (regtype == REG_TYPE_INPUT)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1065
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1066
            const uint32 usage = (token & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1067
            const uint32 index = ((token >> 16) & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1068
            reserved_mask = 0x7FF0FFE0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1069
            ctx->dwords[0] = usage;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1070
            ctx->dwords[1] = index;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1071
        } // if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1072
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1073
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1074
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1075
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1076
    } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1077
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1078
    else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1079
    {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1080
        unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1081
    } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1082
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1083
    if (unsupported)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1084
        fail(ctx, "invalid DCL register type for this shader model");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1085
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1086
    if ((token & reserved_mask) != 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1087
        fail(ctx, "reserved bits in DCL dword aren't zero");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1088
49
780cd8790dff [svn] args_function implementations should return total token usage for the opcode,
icculus
parents: 48
diff changeset
  1089
    return 3;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1090
} // parse_args_DCL
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1091
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1092
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1093
static int parse_args_D(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1094
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1095
    int retval = 1;
161
a0e1920ce909 Removed "dest_args" array...it's only ever one structure.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
  1096
    retval += parse_destination_token(ctx, &ctx->dest_arg);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1097
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1098
} // parse_args_D
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1099
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1100
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1101
static int parse_args_S(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1102
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1103
    int retval = 1;
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1104
    retval += parse_source_token(ctx, &ctx->source_args[0]);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1105
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1106
} // parse_args_S
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1107
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1108
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1109
static int parse_args_SS(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1110
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1111
    int retval = 1;
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1112
    retval += parse_source_token(ctx, &ctx->source_args[0]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1113
    retval += parse_source_token(ctx, &ctx->source_args[1]);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1114
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1115
} // parse_args_SS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1116
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1117
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1118
static int parse_args_DS(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1119
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1120
    int retval = 1;
161
a0e1920ce909 Removed "dest_args" array...it's only ever one structure.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
  1121
    retval += parse_destination_token(ctx, &ctx->dest_arg);
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1122
    retval += parse_source_token(ctx, &ctx->source_args[0]);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1123
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1124
} // parse_args_DS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1125
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1126
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1127
static int parse_args_DSS(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1128
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1129
    int retval = 1;
161
a0e1920ce909 Removed "dest_args" array...it's only ever one structure.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
  1130
    retval += parse_destination_token(ctx, &ctx->dest_arg);
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1131
    retval += parse_source_token(ctx, &ctx->source_args[0]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1132
    retval += parse_source_token(ctx, &ctx->source_args[1]);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1133
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1134
} // parse_args_DSS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1135
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1136
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1137
static int parse_args_DSSS(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1138
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1139
    int retval = 1;
161
a0e1920ce909 Removed "dest_args" array...it's only ever one structure.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
  1140
    retval += parse_destination_token(ctx, &ctx->dest_arg);
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1141
    retval += parse_source_token(ctx, &ctx->source_args[0]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1142
    retval += parse_source_token(ctx, &ctx->source_args[1]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1143
    retval += parse_source_token(ctx, &ctx->source_args[2]);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1144
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1145
} // parse_args_DSSS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1146
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1147
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1148
static int parse_args_DSSSS(Context *ctx)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1149
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1150
    int retval = 1;