mojoshader.c
author Caleb Cornett <caleb.cornett@outlook.com>
Mon, 04 May 2020 09:55:32 -0400
changeset 1254 422f68756c9f
parent 1225 50b8dd7e0b1a
child 1255 0135d797e287
permissions -rw-r--r--
Store pixel shader input attributes, add type data to vertex attributes
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
14
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   239
#if !SUPPORT_PROFILE_GLSL
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   240
#define PROFILE_EMITTER_GLSL(op)
14
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   241
#else
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   242
#undef AT_LEAST_ONE_PROFILE
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   243
#define AT_LEAST_ONE_PROFILE 1
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   244
#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
   245
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
   246
#endif
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   247
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
   248
#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
   249
#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
   250
#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
   251
#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
   252
#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
   253
#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
   254
PREDECLARE_PROFILE(METAL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   255
#endif
2
c37210f5e87b [svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents: 1
diff changeset
   256
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   257
#if !SUPPORT_PROFILE_ARB1
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   258
#define PROFILE_EMITTER_ARB1(op)
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   259
#else
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   260
#undef AT_LEAST_ONE_PROFILE
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   261
#define AT_LEAST_ONE_PROFILE 1
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   262
#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
   263
PREDECLARE_PROFILE(ARB1)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1193
diff changeset
   264
#endif
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   265
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   266
#if !SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   267
#define PROFILE_EMITTER_SPIRV(op)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   268
#else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   269
#undef AT_LEAST_ONE_PROFILE
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   270
#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
   271
#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
   272
PREDECLARE_PROFILE(SPIRV)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   273
#endif
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   274
14
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   275
#if !AT_LEAST_ONE_PROFILE
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   276
#error No profiles are supported. Fix your build.
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   277
#endif
7075b6e31471 [svn] More proper split into profiles.
icculus
parents: 13
diff changeset
   278
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   279
#define DEFINE_PROFILE(prof) { \
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   280
    MOJOSHADER_PROFILE_##prof, \
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   281
    emit_##prof##_start, \
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   282
    emit_##prof##_end, \
400
05e384a14cd6 Implemented support for phase token.
Ryan C. Gordon <icculus@icculus.org>
parents: 399
diff changeset
   283
    emit_##prof##_phase, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   284
    emit_##prof##_global, \
402
933d71481f5b Better relative addressing support.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
   285
    emit_##prof##_array, \
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   286
    emit_##prof##_const_array, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   287
    emit_##prof##_uniform, \
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 145
diff changeset
   288
    emit_##prof##_sampler, \
104
7019f99f17d0 Attribute parsing is closer to correct now.
Ryan C. Gordon <icculus@icculus.org>
parents: 103
diff changeset
   289
    emit_##prof##_attribute, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   290
    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
   291
    get_##prof##_varname, \
f8d9d0ae6ba8 Bunch more work (ARB1 profile, OpenGL glue, and general fixes).
Ryan C. Gordon <icculus@icculus.org>
parents: 346
diff changeset
   292
    get_##prof##_const_array_varname, \
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   293
},
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   294
34
ca4b727ad2ce [svn] Chopped out a bunch of D3D2GLSL_ crap.
icculus
parents: 33
diff changeset
   295
static const Profile profiles[] =
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   296
{
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   297
#if SUPPORT_PROFILE_D3D
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   298
    DEFINE_PROFILE(D3D)
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   299
#endif
469
b8cfaae6c4af Renamed "passthrough" profile to "bytecode"
Ryan C. Gordon <icculus@icculus.org>
parents: 468
diff changeset
   300
#if SUPPORT_PROFILE_BYTECODE
b8cfaae6c4af Renamed "passthrough" profile to "bytecode"
Ryan C. Gordon <icculus@icculus.org>
parents: 468
diff changeset
   301
    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
   302
#endif
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   303
#if SUPPORT_PROFILE_GLSL
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   304
    DEFINE_PROFILE(GLSL)
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   305
#endif
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   306
#if SUPPORT_PROFILE_ARB1
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   307
    DEFINE_PROFILE(ARB1)
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   308
#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
   309
#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
   310
    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
   311
#endif
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   312
#if SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   313
    DEFINE_PROFILE(SPIRV)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   314
#endif
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   315
};
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   316
95
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   317
#undef DEFINE_PROFILE
56af2093eefe Implemented uniform reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 93
diff changeset
   318
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   319
// 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
   320
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
   321
{
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
   322
    { 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
   323
    { 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
   324
    { MOJOSHADER_PROFILE_GLSL120, MOJOSHADER_PROFILE_GLSL },
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   325
    { 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
   326
    { MOJOSHADER_PROFILE_NV3, MOJOSHADER_PROFILE_ARB1 },
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
   327
    { MOJOSHADER_PROFILE_NV4, MOJOSHADER_PROFILE_ARB1 },
361
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   328
};
9fa6652cacbd First (untested) work on nv2 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 360
diff changeset
   329
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   330
// The PROFILE_EMITTER_* items MUST be in the same order as profiles[]!
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   331
#define PROFILE_EMITTERS(op) { \
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   332
     PROFILE_EMITTER_D3D(op) \
469
b8cfaae6c4af Renamed "passthrough" profile to "bytecode"
Ryan C. Gordon <icculus@icculus.org>
parents: 468
diff changeset
   333
     PROFILE_EMITTER_BYTECODE(op) \
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   334
     PROFILE_EMITTER_GLSL(op) \
323
b60c88ec8182 Initial work on ARB1 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 322
diff changeset
   335
     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
   336
     PROFILE_EMITTER_METAL(op) \
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1223
diff changeset
   337
     PROFILE_EMITTER_SPIRV(op) \
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
   338
}
2
c37210f5e87b [svn] Bunch More Work. Parse out instruction tokens, fail in a bunch of new stubs.
icculus
parents: 1
diff changeset
   339
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   340
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
   341
{
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   342
    // !!! 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
   343
    if (ctx->tokencount == 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   344
    {
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   345
        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
   346
        return 0;
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   347
    } // if
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   348
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   349
    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
   350
    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
   351
    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
   352
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   353
    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
   354
    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
   355
    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
   356
    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
   357
    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
   358
    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
   359
    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
   360
316
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   361
    int writemask;
1054
63dd1a46ce13 Treat dcl_psize registers as scalar.
Ryan C. Gordon <icculus@icculus.org>
parents: 1052
diff changeset
   362
    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
   363
        writemask = 0x1;  // just x.
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   364
    else
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   365
        writemask = info->orig_writemask;
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   366
1077
57e18783574e Cleaned up some cut-and-paste.
Ryan C. Gordon <icculus@icculus.org>
parents: 1076
diff changeset
   367
    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
   368
234
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   369
    // 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
   370
    //  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
   371
    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
   372
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   373
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   374
        info->regnum += 2048;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   375
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   376
    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
   377
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   378
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   379
        info->regnum += 4096;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   380
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   381
    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
   382
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   383
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   384
        info->regnum += 6144;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   385
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   386
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   387
    // 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
   388
    adjust_token_position(ctx, 1);
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   389
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   390
    if (reserved1 != 0x0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   391
        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
   392
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   393
    if (reserved2 != 0x1)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   394
        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
   395
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   396
    if (info->relative)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   397
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   398
        if (!shader_is_vertex(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   399
            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
   400
        if (!shader_version_atleast(ctx, 3, 0))
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   401
            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
   402
        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
   403
        {
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   404
            // 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
   405
            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
   406
        } // if
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   407
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   408
        // !!! 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
   409
        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
   410
        return 2;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   411
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   412
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   413
    const int s = info->result_shift;
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   414
    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
   415
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   416
        if (!shader_is_pixel(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   417
            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
   418
        if (shader_version_atleast(ctx, 2, 0))
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   419
            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
   420
        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
   421
            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
   422
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   423
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   424
    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
   425
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   426
        if (!shader_is_pixel(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   427
            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
   428
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   429
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   430
    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
   431
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   432
        if (!shader_is_pixel(ctx))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   433
            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
   434
        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
   435
            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
   436
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   437
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
   438
    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
   439
        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
   440
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   441
    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
   442
        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
   443
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   444
    return 1;
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   445
} // parse_destination_token
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   446
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   447
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   448
static void determine_constants_arrays(Context *ctx)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   449
{
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   450
    // 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
   451
    //  could have been parsed.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   452
    if (ctx->determined_constants_arrays)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   453
        return;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   454
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   455
    ctx->determined_constants_arrays = 1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   456
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   457
    if (ctx->constant_count <= 1)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   458
        return;  // nothing to sort or group.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   459
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   460
    // 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
   461
    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
   462
    ConstantsList *item = ctx->constants;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   463
    int i;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   464
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   465
    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
   466
    {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   467
        if (item == NULL)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   468
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   469
            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
   470
            return;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   471
        } // if
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
        array[i] = item;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   474
        item = item->next;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   475
    } // for
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   476
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   477
    array[ctx->constant_count] = NULL;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   478
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   479
    // bubble sort ftw.
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   480
    int sorted;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   481
    do
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   482
    {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   483
        sorted = 1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   484
        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
   485
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   486
            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
   487
            {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   488
                ConstantsList *tmp = array[i];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   489
                array[i] = array[i+1];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   490
                array[i+1] = tmp;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   491
                sorted = 0;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   492
            } // if
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   493
        } // for
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   494
    } while (!sorted);
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
    // 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
   497
    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
   498
        array[i]->next = array[i+1];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   499
    ctx->constants = array[0];
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
    // 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
   502
    int start = -1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   503
    int prev = -1;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   504
    int count = 0;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   505
    const int hi = ctx->constant_count;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   506
    for (i = 0; i <= hi; i++)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   507
    {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   508
        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
   509
            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
   510
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   511
        if (start == -1)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   512
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   513
            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
   514
            continue;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   515
        } // if
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   516
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   517
        // 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
   518
        //  contiguous set before this point...
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   519
        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
   520
            count++;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   521
        else
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   522
        {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   523
            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
   524
            {
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   525
                VariableList *var;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   526
                var = (VariableList *) Malloc(ctx, sizeof (VariableList));
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   527
                if (var == NULL)
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   528
                    break;
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
                var->type = MOJOSHADER_UNIFORM_FLOAT;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   531
                var->index = array[start]->constant.index;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   532
                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
   533
                var->constant = array[start];
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   534
                var->used = 0;
760
6dc8d2cafc58 "Must Push" seemed more correct than "Must Load".
Ryan C. Gordon <icculus@icculus.org>
parents: 758
diff changeset
   535
                var->emit_position = -1;
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   536
                var->next = ctx->variables;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   537
                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
   538
            } // if
405
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   539
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   540
            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
   541
        } // if
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
        prev = i;
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   544
    } // for
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   545
} // determine_constants_arrays
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   546
e2cffb40e8b8 Build arrays of constants if necessary.
Ryan C. Gordon <icculus@icculus.org>
parents: 404
diff changeset
   547
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   548
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
   549
                          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
   550
{
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   551
    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
   552
        return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   553
    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
   554
        return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   555
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   556
    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
   557
    if (reg == NULL)
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   558
        return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   559
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
   560
    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
   561
    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
   562
    {
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
   563
        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
   564
        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
   565
        {
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   566
            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
   567
                     (((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
   568
                     (((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
   569
                     (((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
   570
        } // if
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   571
    } // for
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   572
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   573
    return swizzle;
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   574
} // adjust_swizzle
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   575
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   576
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   577
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
   578
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   579
    int retval = 1;
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   580
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   581
    if (ctx->tokencount == 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   582
    {
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   583
        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
   584
        return 0;
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   585
    } // if
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   586
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   587
    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
   588
    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
   589
    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
   590
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   591
    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
   592
    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
   593
    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
   594
    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
   595
    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
   596
    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
   597
234
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   598
    // 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
   599
    //  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
   600
    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
   601
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   602
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   603
        info->regnum += 2048;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   604
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   605
    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
   606
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   607
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   608
        info->regnum += 4096;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   609
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   610
    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
   611
    {
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   612
        info->regtype = REG_TYPE_CONST;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   613
        info->regnum += 6144;
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   614
    } // else if
c05582e582ad Cleaned up the CONST/CONST2/CONST3/CONST4 tapdance.
Ryan C. Gordon <icculus@icculus.org>
parents: 233
diff changeset
   615
450
6a9faf398c1d Allow overriding of swizzle on vertex attributes during bytecode parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 446
diff changeset
   616
    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
   617
    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
   618
    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
   619
    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
   620
    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
   621
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   622
    // 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
   623
    adjust_token_position(ctx, 1);
21
d43449cf3cb2 [svn] Implemented destination argument output in D3D profile. Untested.
icculus
parents: 20
diff changeset
   624
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   625
    if (reserved1 != 0x0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   626
        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
   627
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   628
    if (reserved2 != 0x1)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   629
        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
   630
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   631
    if ((info->relative) && (ctx->tokencount == 0))
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   632
    {
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   633
        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
   634
        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
   635
    } // if
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   636
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   637
    if (info->relative)
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   638
    {
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   639
        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
   640
            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
   641
1139
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   642
        // 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
   643
        //  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
   644
        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
   645
        {
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   646
            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
   647
            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
   648
            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
   649
        } // if
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   650
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   651
        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
   652
        {
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   653
            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
   654
            // 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
   655
            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
   656
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   657
            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
   658
            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
   659
            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
   660
                                        (((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
   661
                                        ((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
   662
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   663
            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
   664
                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
   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
            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
   667
                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
   668
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   669
            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
   670
            {
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   671
                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
   672
                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
   673
                    break;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   674
                default:
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   675
                    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
   676
                    break;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   677
            } // switch
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 (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
   680
                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
   681
1190
51de95edd697 Loop register should not have swizzling
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1188
diff changeset
   682
            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
   683
                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
   684
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   685
            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
   686
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   687
            retval++;
8cda6a463824 Shader Model 1 doesn't use an extra token for relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 1131
diff changeset
   688
        } // else
1061
dbf2735676ae Set relative_component correctly when parsing source registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1060
diff changeset
   689
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   690
        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
   691
        {
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   692
            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
   693
                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
   694
            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
   695
        } // if
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   696
        else if (info->regtype == REG_TYPE_CONST)
402
933d71481f5b Better relative addressing support.
Ryan C. Gordon <icculus@icculus.org>
parents: 401
diff changeset
   697
        {
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   698
            // 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
   699
            if (!ctx->ignores_ctab)
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   700
            {
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   701
                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
   702
                    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
   703
                else
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   704
                {
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   705
                    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
   706
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   707
                    VariableList *var;
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   708
                    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
   709
                    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
   710
                    {
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   711
                        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
   712
                        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
   713
                            break;  // match!
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   714
                    } // for
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   715
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   716
                    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
   717
                        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
   718
                    else
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   719
                    {
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   720
                        var->used = 1;
4cdf5a3ceb03 Fixed a few things clang's static analysis reported.
Ryan C. Gordon <icculus@icculus.org>
parents: 1058
diff changeset
   721
                        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
   722
                        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
   723
                    } // else
1058
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   724
                } // else
dcbe39bffedc Let d3d and bytecode profiles use relative addressing without a CTAB.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   725
            } // if
531
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   726
        } // else if
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   727
        else
a059fa2d137a Initial work on input registers with relative addressing.
Ryan C. Gordon <icculus@icculus.org>
parents: 525
diff changeset
   728
        {
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   729
            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
   730
        } // else
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   731
    } // if
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   732
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   733
    switch (info->src_mod)
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   734
    {
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   735
        case SRCMOD_NONE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   736
        case SRCMOD_ABSNEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   737
        case SRCMOD_ABS:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   738
        case SRCMOD_NEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   739
            break; // okay in any shader model.
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   740
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   741
        // 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
   742
        case SRCMOD_BIASNEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   743
        case SRCMOD_BIAS:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   744
        case SRCMOD_SIGNNEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   745
        case SRCMOD_SIGN:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   746
        case SRCMOD_COMPLEMENT:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   747
        case SRCMOD_X2NEGATE:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   748
        case SRCMOD_X2:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   749
        case SRCMOD_DZ:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   750
        case SRCMOD_DW:
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   751
            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
   752
                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
   753
            break;
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   754
494
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   755
        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
   756
            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
   757
            {
1183
ec44ee868688 Minor fixes from FNA branch
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1182
diff changeset
   758
                if (info->regtype != REG_TYPE_PREDICATE
ec44ee868688 Minor fixes from FNA branch
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1182
diff changeset
   759
                 && info->regtype != REG_TYPE_CONSTBOOL)
ec44ee868688 Minor fixes from FNA branch
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1182
diff changeset
   760
                    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
   761
            } // if
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   762
            break;
309f60d7cf8c SRCMOD_NOT apparently is allowed in SM3 for predicate registers...?!
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   763
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   764
        default:
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   765
            fail(ctx, "Unknown source modifier");
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   766
    } // switch
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   767
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   768
    // !!! 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
   769
    //  "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
   770
    //   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
   771
    //   m4x4 - ps."
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   772
    //  "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
   773
    //   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
   774
    //    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
   775
    //    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
   776
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   777
    if (!isfail(ctx))
1085
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   778
    {
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   779
        RegisterList *reg;
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   780
        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
   781
        // !!! 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
   782
        // !!! 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
   783
        // !!! FIXME:  destination token first.
dac9e6cea0d1 Test for reading of uninitialized temp registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1084
diff changeset
   784
        // !!! 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
   785
        // !!! 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
   786
        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
   787
            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
   788
    } // if
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   789
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   790
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   791
} // parse_source_token
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   792
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   793
139
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   794
static int parse_predicated_token(Context *ctx)
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   795
{
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   796
    SourceArgInfo *arg = &ctx->predicate_arg;
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   797
    parse_source_token(ctx, arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   798
    if (arg->regtype != REG_TYPE_PREDICATE)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   799
        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
   800
    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
   801
        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
   802
    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
   803
        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
   804
    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
   805
        fail(ctx, "relative addressing in predicated token");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   806
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   807
    return 1;
139
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   808
} // parse_predicated_token
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   809
a7695f68cbff First shot at predicated instruction support.
Ryan C. Gordon <icculus@icculus.org>
parents: 138
diff changeset
   810
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   811
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
   812
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   813
    return 1;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   814
} // parse_args_NULL
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   815
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
   816
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   817
static int parse_args_DEF(Context *ctx)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   818
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   819
    parse_destination_token(ctx, &ctx->dest_arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   820
    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
   821
        fail(ctx, "DEF using non-CONST register");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   822
    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
   823
        fail(ctx, "relative addressing in DEF");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   824
56
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   825
    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
   826
    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
   827
    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
   828
    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
   829
49
780cd8790dff [svn] args_function implementations should return total token usage for the opcode,
icculus
parents: 48
diff changeset
   830
    return 6;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   831
} // parse_args_DEF
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   832
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   833
466
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   834
static int parse_args_DEFI(Context *ctx)
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   835
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   836
    parse_destination_token(ctx, &ctx->dest_arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   837
    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
   838
        fail(ctx, "DEFI using non-CONSTING register");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   839
    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
   840
        fail(ctx, "relative addressing in DEFI");
466
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   841
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   842
    ctx->dwords[0] = SWAP32(ctx->tokens[0]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   843
    ctx->dwords[1] = SWAP32(ctx->tokens[1]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   844
    ctx->dwords[2] = SWAP32(ctx->tokens[2]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   845
    ctx->dwords[3] = SWAP32(ctx->tokens[3]);
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   846
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   847
    return 6;
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   848
} // parse_args_DEFI
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   849
c2aa844013f1 Better parse_args for DEFx opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 465
diff changeset
   850
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   851
static int parse_args_DEFB(Context *ctx)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   852
{
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   853
    parse_destination_token(ctx, &ctx->dest_arg);
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   854
    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
   855
        fail(ctx, "DEFB using non-CONSTBOOL register");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   856
    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
   857
        fail(ctx, "relative addressing in DEFB");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   858
56
1e8b180d3eb1 [svn] Bunch of work from the transatlantic airplane flight...since this is a ton of
icculus
parents: 55
diff changeset
   859
    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
   860
49
780cd8790dff [svn] args_function implementations should return total token usage for the opcode,
icculus
parents: 48
diff changeset
   861
    return 3;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   862
} // parse_args_DEFB
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   863
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   864
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   865
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
   866
{
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   867
    switch ((const TextureType) ttype)
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   868
    {
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   869
        case TEXTURE_TYPE_2D:
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   870
        case TEXTURE_TYPE_CUBE:
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   871
        case TEXTURE_TYPE_VOLUME:
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   872
            return 1;  // it's okay.
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   873
    } // switch
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   874
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   875
    return 0;
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   876
} // valid_texture_type
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   877
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   878
154
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   879
// !!! FIXME: this function is kind of a mess.
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   880
static int parse_args_DCL(Context *ctx)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   881
{
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   882
    int unsupported = 0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   883
    const uint32 token = SWAP32(*(ctx->tokens));
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   884
    const int reserved1 = (int) ((token >> 31) & 0x1); // bit 31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   885
    uint32 reserved_mask = 0x00000000;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   886
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   887
    if (reserved1 != 0x1)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   888
        fail(ctx, "Bit #31 in DCL token must be one");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   889
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
   890
    ctx->centroid_allowed = 1;
947
16af6e2b2ada Cleaned up error position reporting.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   891
    adjust_token_position(ctx, 1);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   892
    parse_destination_token(ctx, &ctx->dest_arg);
431
0d0cbe10db02 First shot at nv4 profile.
Ryan C. Gordon <icculus@icculus.org>
parents: 430
diff changeset
   893
    ctx->centroid_allowed = 0;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   894
428
8d410fecd518 More bytecode verification tests against spec.
Ryan C. Gordon <icculus@icculus.org>
parents: 427
diff changeset
   895
    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
   896
        fail(ctx, "shift scale in DCL");
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   897
    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
   898
        fail(ctx, "relative addressing in DCL");
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
   899
161
a0e1920ce909 Removed "dest_args" array...it's only ever one structure.
Ryan C. Gordon <icculus@icculus.org>
parents: 160
diff changeset
   900
    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
   901
    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
   902
    if ( (shader_is_pixel(ctx)) && (shader_version_atleast(ctx, 3, 0)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   903
    {
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   904
        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
   905
        {
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   906
            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
   907
            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
   908
            reserved_mask = 0x7FF0FFE0;
ebd0921fdd39 Fixed DCL parse and D3D profile for ps_3_0.
Ryan C. Gordon <icculus@icculus.org>
parents: 152
diff changeset
   909
            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
   910
            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
   911
        } // if
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   912
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   913
        else if (regtype == REG_TYPE_MISCTYPE)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   914
        {
83
ce46250e553d Add defined/declared registers to the appropriate register list.
Ryan C. Gordon <icculus@icculus.org>
parents: 82
diff changeset
   915
            const MiscTypeType mt = (MiscTypeType) regnum;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   916
            if (mt == MISCTYPE_TYPE_POSITION)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   917
                reserved_mask = 0x7FFFFFFF;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   918
            else if (mt == MISCTYPE_TYPE_FACE)
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   919
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   920
                reserved_mask = 0x7FFFFFFF;
316
93e70dbdba48 Deal with scalar D3D registers more properly.
Ryan C. Gordon <icculus@icculus.org>
parents: 315
diff changeset
   921
                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
   922
                    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
   923
                if (ctx->dest_arg.result_mod != 0)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   924
                    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
   925
                if (ctx->dest_arg.result_shift != 0)
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   926
                    fail(ctx, "DCL face shift scale must be zero");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   927
            } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   928
            else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   929
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   930
                unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   931
            } // else
317
74a9f3ae4534 Support for vFace and vPos registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   932
74a9f3ae4534 Support for vFace and vPos registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   933
            ctx->dwords[0] = (uint32) MOJOSHADER_USAGE_UNKNOWN;
74a9f3ae4534 Support for vFace and vPos registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 316
diff changeset
   934
            ctx->dwords[1] = 0;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   935
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   936
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   937
        else if (regtype == REG_TYPE_TEXTURE)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   938
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   939
            const uint32 usage = (token & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   940
            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
   941
            if (usage == MOJOSHADER_USAGE_TEXCOORD)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   942
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   943
                if (index > 7)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   944
                    fail(ctx, "DCL texcoord usage must have 0-7 index");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   945
            } // if
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 99
diff changeset
   946
            else if (usage == MOJOSHADER_USAGE_COLOR)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   947
            {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   948
                if (index != 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   949
                    fail(ctx, "DCL color usage must have 0 index");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   950
            } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   951
            else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   952
            {
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   953
                fail(ctx, "Invalid DCL texture usage");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   954
            } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   955
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   956
            reserved_mask = 0x7FF0FFE0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   957
            ctx->dwords[0] = usage;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   958
            ctx->dwords[1] = index;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   959
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   960
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   961
        else if (regtype == REG_TYPE_SAMPLER)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   962
        {
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   963
            const uint32 ttype = ((token >> 27) & 0xF);
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   964
            if (!valid_texture_type(ttype))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   965
                fail(ctx, "unknown sampler texture type");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   966
            reserved_mask = 0x7FFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   967
            ctx->dwords[0] = ttype;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   968
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   969
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   970
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   971
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   972
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   973
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   974
    } // if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   975
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
   976
    else if ( (shader_is_pixel(ctx)) && (shader_version_atleast(ctx, 2, 0)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   977
    {
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   978
        if (regtype == REG_TYPE_INPUT)
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   979
        {
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   980
            ctx->dwords[0] = (uint32) MOJOSHADER_USAGE_COLOR;
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   981
            ctx->dwords[1] = regnum;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   982
            reserved_mask = 0x7FFFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   983
        } // if
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   984
        else if (regtype == REG_TYPE_TEXTURE)
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   985
        {
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   986
            ctx->dwords[0] = (uint32) MOJOSHADER_USAGE_TEXCOORD;
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   987
            ctx->dwords[1] = regnum;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   988
            reserved_mask = 0x7FFFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   989
        } // else if
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
   990
        else if (regtype == REG_TYPE_SAMPLER)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   991
        {
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   992
            const uint32 ttype = ((token >> 27) & 0xF);
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   993
            if (!valid_texture_type(ttype))
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
   994
                fail(ctx, "unknown sampler texture type");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   995
            reserved_mask = 0x7FFFFFF;
310
d323e04e62f7 Fixed register declaration in pixel shaders.
Ryan C. Gordon <icculus@icculus.org>
parents: 309
diff changeset
   996
            ctx->dwords[0] = ttype;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   997
        } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   998
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
   999
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1000
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1001
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1002
    } // if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1003
151
1667680fe402 Cleaned up tests for shader type and version.
Ryan C. Gordon <icculus@icculus.org>
parents: 150
diff changeset
  1004
    else if ( (shader_is_vertex(ctx)) && (shader_version_atleast(ctx, 3, 0)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1005
    {
101
0834e95e5e76 First shot at DCL emitter for GLSL profile. Incomplete.
Ryan C. Gordon <icculus@icculus.org>
parents: 99
diff changeset
  1006
        if ((regtype == REG_TYPE_INPUT) || (regtype == REG_TYPE_OUTPUT))
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1007
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1008
            const uint32 usage = (token & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1009
            const uint32 index = ((token >> 16) & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1010
            reserved_mask = 0x7FF0FFE0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1011
            ctx->dwords[0] = usage;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1012
            ctx->dwords[1] = index;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1013
        } // if
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1014
        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
  1015
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1016
            const uint32 usage = (token & 0xF);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1017
            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
  1018
            if (usage == MOJOSHADER_USAGE_TEXCOORD)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1019
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1020
                if (index > 7)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1021
                    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
  1022
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1023
            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
  1024
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1025
                if (index != 0)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1026
                    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
  1027
            } // else if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1028
            else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1029
                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
  1030
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1031
            reserved_mask = 0x7FF0FFE0;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1032
            ctx->dwords[0] = usage;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1033
            ctx->dwords[1] = index;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1034
        } // else if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1035
        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
  1036
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1037
            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
  1038
            if (!valid_texture_type(ttype))
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1039
                fail(ctx, "Unknown sampler texture type");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1040
            reserved_mask = 0x6FFFFFFF;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1041
            ctx->dwords[0] = ttype;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1148
diff changeset
  1042
        } // else if
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1043
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1044
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1045
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1046
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1047
    } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1048
803
cfd14c5f187a vs_1_1 also has decls on D3D9
Aras Pranckevicius <aras@unity3d.com>
parents: 802
diff changeset
  1049
    else if ( (shader_is_vertex(ctx)) && (shader_version_atleast(ctx, 1, 1)) )
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1050
    {
73
c368f50d89d2 Shrank chatty enum name.
Ryan C. Gordon <icculus@icculus.org>
parents: 72
diff changeset
  1051
        if (regtype == REG_TYPE_INPUT)
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1052
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1053
            const uint32 usage = (token & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1054
            const uint32 index = ((token >> 16) & 0xF);
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1055
            reserved_mask = 0x7FF0FFE0;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1056
            ctx->dwords[0] = usage;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1057
            ctx->dwords[1] = index;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1058
        } // if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1059
        else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1060
        {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1061
            unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1062
        } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1063
    } // else if
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1064
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1065
    else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1066
    {
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1067
        unsupported = 1;
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1068
    } // else
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1069
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1070
    if (unsupported)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1071
        fail(ctx, "invalid DCL register type for this shader model");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1072
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1073
    if ((token & reserved_mask) != 0)
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1074
        fail(ctx, "reserved bits in DCL dword aren't zero");
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1075
49
780cd8790dff [svn] args_function implementations should return total token usage for the opcode,
icculus
parents: 48
diff changeset
  1076
    return 3;
31
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1077
} // parse_args_DCL
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1078
ee4ff9d30b67 [svn] DCL support!
icculus
parents: 30
diff changeset
  1079
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1080
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
  1081
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1082
    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
  1083
    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
  1084
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1085
} // parse_args_D
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1086
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1087
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1088
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
  1089
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1090
    int retval = 1;
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1091
    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
  1092
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1093
} // parse_args_S
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1094
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1095
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1096
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
  1097
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1098
    int retval = 1;
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1099
    retval += parse_source_token(ctx, &ctx->source_args[0]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1100
    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
  1101
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1102
} // parse_args_SS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1103
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1104
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1105
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
  1106
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1107
    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
  1108
    retval += parse_destination_token(ctx, &ctx->dest_arg);
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1109
    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
  1110
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1111
} // parse_args_DS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1112
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1113
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1114
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
  1115
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1116
    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
  1117
    retval += parse_destination_token(ctx, &ctx->dest_arg);
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1118
    retval += parse_source_token(ctx, &ctx->source_args[0]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1119
    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
  1120
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1121
} // parse_args_DSS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1122
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1123
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1124
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
  1125
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1126
    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
  1127
    retval += parse_destination_token(ctx, &ctx->dest_arg);
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1128
    retval += parse_source_token(ctx, &ctx->source_args[0]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1129
    retval += parse_source_token(ctx, &ctx->source_args[1]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1130
    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
  1131
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1132
} // parse_args_DSSS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1133
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1134
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1135
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
  1136
{
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1137
    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
  1138
    retval += parse_destination_token(ctx, &ctx->dest_arg);
152
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1139
    retval += parse_source_token(ctx, &ctx->source_args[0]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1140
    retval += parse_source_token(ctx, &ctx->source_args[1]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1141
    retval += parse_source_token(ctx, &ctx->source_args[2]);
cc7c38dfe145 Relative addressing work.
Ryan C. Gordon <icculus@icculus.org>
parents: 151
diff changeset
  1142
    retval += parse_source_token(ctx, &ctx->source_args[3]);
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 541
diff changeset
  1143
    return retval;
20
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1144
} // parse_args_DSSSS
bb2e8f285acc [svn] Bunch More Work...higher level parses dest/src tokens before it goes to the
icculus
parents: 19
diff changeset
  1145
15
97ad0050e75b [svn] Still more profile cleanup.
icculus
parents: 14
diff changeset
  1146
120
5589b5160d12 SINCOS work.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
  1147
static int parse_args_SINCOS(Context *ctx)
5589b5160d12 SINCOS work.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
  1148
{
5589b5160d12 SINCOS work.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
  1149
    // this opcode needs extra registers for sm2 and lower.
5589b5160d12 SINCOS work.
Ryan C. Gordon <icculus@icculus.org>
parents: 119
diff changeset
  1150
    if (!shader_version_atleast(ctx, 3, 0))
5589b5160d12 SINCOS work.
Ryan C. Gordon <icculus@icculus.org>
parents: 119