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