utils/testparse.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 28 May 2016 15:58:05 -0400
changeset 1164 006194daea99
parent 1156 6e760a19f456
child 1171 9f27482a2f58
permissions -rw-r--r--
MOJOSHADER_parsePreshader() cleanup. Merged Ethan's copied/improved code with the original, and documented the APIs. Changed MOJOSHADER_freePreshader() to not need explicit deallocators specified.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
244
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     1
/**
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     3
 *  Direct3D shaders.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     4
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     6
 *
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     7
 *  This file written by Ryan C. Gordon.
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     8
 */
30ceb789b9a1 More comment headers.
Ryan C. Gordon <icculus@icculus.org>
parents: 192
diff changeset
     9
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    10
#include <stdio.h>
9
aea1b254e6a5 [svn] Patched to compile.
icculus
parents: 7
diff changeset
    11
#include <stdlib.h>
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
    12
#include "mojoshader.h"
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
    13
254
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    14
#ifdef _MSC_VER
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    15
#define snprintf _snprintf
13184ff204b9 More Windows patches.
Ryan C. Gordon <icculus@icculus.org>
parents: 244
diff changeset
    16
#endif
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    17
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    18
#if MOJOSHADER_DEBUG_MALLOC
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    19
static void *Malloc(int len)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    20
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    21
    void *ptr = malloc(len + sizeof (int));
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    22
    int *store = (int *) ptr;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    23
    printf("malloc() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    24
    if (ptr == NULL) return NULL;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    25
    *store = len;
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    26
    return (void *) (store + 1);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    27
} // Malloc
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    28
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    29
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    30
static void Free(void *_ptr)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    31
{
50
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    32
    int *ptr = (((int *) _ptr) - 1);
427f32b5eeff [svn] Fixed test malloc.
icculus
parents: 48
diff changeset
    33
    int len = *ptr;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    34
    printf("free() %d bytes (%p)\n", len, ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    35
    free(ptr);
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    36
} // Free
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    37
#else
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    38
#define Malloc NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    39
#define Free NULL
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    40
#endif
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    41
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    42
static inline void do_indent(const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    43
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    44
    unsigned int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    45
    for (i = 0; i < indent; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    46
        printf("    ");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    47
}
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    48
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    49
#define INDENT() do { if (indent) { do_indent(indent); } } while (0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    50
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
    51
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    52
static const char *shader_type(const MOJOSHADER_shaderType s)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    53
{
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    54
    switch (s)
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    55
    {
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    56
        case MOJOSHADER_TYPE_UNKNOWN: return "unknown";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    57
        case MOJOSHADER_TYPE_PIXEL: return "pixel";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    58
        case MOJOSHADER_TYPE_VERTEX: return "vertex";
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    59
        case MOJOSHADER_TYPE_GEOMETRY: return "geometry";
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    60
        default: return "(bogus value?)";
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    61
    } // switch
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    62
48
86dc2c772d26 [svn] Enabled -Wall, found some bugs.
icculus
parents: 47
diff changeset
    63
    return NULL;  // shouldn't hit this.
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    64
} // shader_type
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    65
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
    66
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    67
static void print_typeinfo(const MOJOSHADER_symbolTypeInfo *info,
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    68
                           unsigned int indent)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    69
{
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    70
    static const char *symclasses[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    71
        "scalar", "vector", "row-major matrix",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    72
        "column-major matrix", "object", "struct"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    73
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    74
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    75
    static const char *symtypes[] = {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    76
        "void", "bool", "int", "float", "string", "texture",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    77
        "texture1d", "texture2d", "texture3d", "texturecube",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    78
        "sampler", "sampler1d", "sampler2d", "sampler3d",
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    79
        "samplercube", "pixelshader", "vertexshader", "unsupported"
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    80
    };
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    81
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    82
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    83
    printf("      symbol class %s\n", symclasses[info->parameter_class]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    84
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    85
    printf("      symbol type %s\n", symtypes[info->parameter_type]);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    86
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    87
    printf("      rows %u\n", info->rows);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    88
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    89
    printf("      columns %u\n", info->columns);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    90
    INDENT();
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    91
    printf("      elements %u\n", info->elements);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    92
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    93
    if (info->member_count > 0)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    94
    {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    95
        int i;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    96
        INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    97
        for (i = 0; i < info->member_count; i++)
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    98
        {
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
    99
            const MOJOSHADER_symbolStructMember *member = &info->members[i];
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   100
            INDENT(); printf("      MEMBERS:\n");
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   101
            indent++;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   102
            INDENT(); printf("      * %d: \"%s\"\n", i, member->name);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   103
            print_typeinfo(&member->info, indent);
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   104
            indent--;
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   105
        } // for
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   106
    } // if
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   107
} // print_typeinfo
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   108
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   109
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   110
static void print_symbols(const MOJOSHADER_symbol *sym,
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   111
                          const unsigned int symbol_count,
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   112
                          const unsigned int indent)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   113
{
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   114
    INDENT(); printf("SYMBOLS:");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   115
    if (symbol_count == 0)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   116
        printf(" (none.)\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   117
    else
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   118
    {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   119
        int i;
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   120
        printf("\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   121
        for (i = 0; i < symbol_count; i++, sym++)
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   122
        {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   123
            static const char *regsets[] = {
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   124
                "bool", "int4", "float4", "sampler"
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   125
            };
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   126
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   127
            INDENT(); printf("    * %d: \"%s\"\n", i, sym->name);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   128
            INDENT(); printf("      register set %s\n", regsets[sym->register_set]);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   129
            INDENT(); printf("      register index %u\n", sym->register_index);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   130
            INDENT(); printf("      register count %u\n", sym->register_count);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   131
            print_typeinfo(&sym->info, indent);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   132
        } // for
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   133
        printf("\n");
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   134
    } // else
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   135
} // print_symbols
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   136
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   137
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   138
static void print_preshader_operand(const MOJOSHADER_preshader *preshader,
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   139
                                    const int instidx, const int opidx)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   140
{
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   141
    static char mask[] = { 'x', 'y', 'z', 'w' };
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   142
    const MOJOSHADER_preshaderInstruction *inst = &preshader->instructions[instidx];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   143
    const MOJOSHADER_preshaderOperand *operand = &inst->operands[opidx];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   144
    const int elems = inst->element_count;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   145
    const int isscalarop = (inst->opcode >= MOJOSHADER_PRESHADEROP_SCALAR_OPS);
1051
96a838f4e680 Fixed off-by-one error in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1046
diff changeset
   146
    const int isscalar = ((isscalarop) && (opidx == 0)); // probably wrong.
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   147
    int i;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   148
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   149
    switch (operand->type)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   150
    {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   151
        case MOJOSHADER_PRESHADEROPERAND_LITERAL:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   152
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   153
            const double *lit = &preshader->literals[operand->index];
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   154
            printf("(");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   155
            if (isscalar)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   156
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   157
                const double val = *lit;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   158
                for (i = 0; i < elems-1; i++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   159
                    printf("%g, ", val);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   160
                printf("%g)", val);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   161
            } // if
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   162
            else
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   163
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   164
                for (i = 0; i < elems-1; i++, lit++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   165
                    printf("%g, ", *lit);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   166
                printf("%g)", *lit);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   167
            } // else
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   168
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   169
        } // case
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   170
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   171
        case MOJOSHADER_PRESHADEROPERAND_INPUT:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   172
        case MOJOSHADER_PRESHADEROPERAND_OUTPUT:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   173
        case MOJOSHADER_PRESHADEROPERAND_TEMP:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   174
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   175
            int idx = operand->index % 4;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   176
            char regch = 'c';
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   177
            if (operand->type == MOJOSHADER_PRESHADEROPERAND_TEMP)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   178
                regch = 'r';
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   179
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   180
            if (operand->array_register_count > 0)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   181
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   182
                for (i = operand->array_register_count - 1; i >= 0; i--)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   183
                    printf("c%d[", operand->array_registers[i]);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   184
                printf("%c%d.%c", regch, operand->index / 4, mask[idx]);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   185
                for (i = 0; i < operand->array_register_count; i++)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   186
                    printf("]");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   187
                break;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   188
            } // if
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   189
            printf("%c%d", regch, operand->index / 4);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   190
            if (isscalar)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   191
                printf(".%c", mask[idx]);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   192
            else if (elems != 4)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   193
            {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   194
                printf(".");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   195
                for (i = 0; i < elems; i++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   196
                    printf("%c", mask[idx++]);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   197
            } // else if
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   198
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   199
        } // case
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   200
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   201
        default:
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   202
            printf("[???{%d, %u}???]", (int) operand->type, operand->index);
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   203
            break;
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   204
    } // switch
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   205
} // print_preshader_operand
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   206
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   207
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   208
static void print_preshader(const MOJOSHADER_preshader *preshader,
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   209
                            const int indent)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   210
{
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   211
    MOJOSHADER_preshaderInstruction *inst = preshader->instructions;
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   212
    int i, j;
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   213
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   214
    static const char *opcodestr[] = {
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   215
        "nop", "mov", "neg", "rcp", "frc", "exp", "log", "rsq", "sin", "cos",
1034
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   216
        "asin", "acos", "atan", "min", "max", "lt", "ge", "add", "mul",
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   217
        "atan2", "div", "cmp", "movc", "dot", "noise", "min", "max", "lt",
549f160533fa Found, I think, the final preshader opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1033
diff changeset
   218
        "ge", "add", "mul", "atan2", "div", "dot", "noise"
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   219
    };
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   220
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   221
    INDENT(); printf("PRESHADER:\n");
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   222
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   223
    print_symbols(preshader->symbols, preshader->symbol_count, indent + 1);
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   224
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   225
    for (i = 0; i < preshader->instruction_count; i++, inst++)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   226
    {
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   227
        INDENT(); printf("    %s ", opcodestr[inst->opcode]);
1032
464f38a2fb70 Added some more preshader opcodes, cleaned up opcode handling elsewhere.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   228
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   229
        // print dest register first...
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   230
        print_preshader_operand(preshader, i, inst->operand_count - 1);
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   231
1046
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   232
        // ...then the source registers.
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   233
        for (j = 0; j < inst->operand_count - 1; j++)
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   234
        {
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   235
            printf(", ");
097aefb03885 Place preshader destination register last in operand list.
Ryan C. Gordon <icculus@icculus.org>
parents: 1044
diff changeset
   236
            print_preshader_operand(preshader, i, j);
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   237
        } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   238
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   239
        printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   240
    } // for
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   241
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   242
    printf("\n");
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   243
} // print_preshader
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   244
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   245
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   246
static void print_attrs(const char *category, const int count,
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   247
                        const MOJOSHADER_attribute *attributes,
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   248
                        const int indent)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   249
{
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   250
    INDENT(); printf("%s:", category);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   251
    if (count == 0)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   252
        printf(" (none.)\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   253
    else
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   254
    {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   255
        int i;
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   256
        printf("\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   257
        for (i = 0; i < count; i++)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   258
        {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   259
            static const char *usagenames[] = {
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   260
                "position", "blendweight", "blendindices", "normal",
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   261
                "psize", "texcoord", "tangent", "binormal", "tessfactor",
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   262
                "positiont", "color", "fog", "depth", "sample"
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   263
            };
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   264
            const MOJOSHADER_attribute *a = &attributes[i];
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   265
            char numstr[16] = { 0 };
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   266
            if (a->index != 0)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   267
                snprintf(numstr, sizeof (numstr), "%d", a->index);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   268
            INDENT();
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   269
            printf("    * %s%s", usagenames[(int) a->usage], numstr);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   270
            if (a->name != NULL)
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   271
                printf(" (\"%s\")", a->name);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   272
            printf("\n");
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   273
        } // for
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   274
    } // else
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   275
} // print_attrs
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   276
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   277
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   278
static void print_shader(const char *fname, const MOJOSHADER_parseData *pd,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   279
                         unsigned int indent)
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   280
{
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   281
    INDENT(); printf("PROFILE: %s\n", pd->profile);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   282
    if (pd->error_count > 0)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   283
    {
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   284
        int i;
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   285
        for (i = 0; i < pd->error_count; i++)
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   286
        {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   287
            const MOJOSHADER_error *err = &pd->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   288
            INDENT();
577
bec531dd448e Report filenames in error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 536
diff changeset
   289
            printf("%s:%d: ERROR: %s\n",
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   290
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   291
                    err->error_position, err->error);
536
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   292
        } // for
5af65fe6e917 Allow multiple errors from parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 475
diff changeset
   293
    } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   294
    else
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   295
    {
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   296
        INDENT(); printf("SHADER TYPE: %s\n", shader_type(pd->shader_type));
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   297
        INDENT(); printf("VERSION: %d.%d\n", pd->major_ver, pd->minor_ver);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   298
        INDENT(); printf("INSTRUCTION COUNT: %d\n", (int) pd->instruction_count);
1055
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   299
        print_attrs("INPUTS", pd->attribute_count, pd->attributes, indent);
3295380ce6fc Report shader outputs in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1051
diff changeset
   300
        print_attrs("OUTPUTS", pd->output_count, pd->outputs, indent);
100
2b88649b6f98 First shot at attributes reporting API.
Ryan C. Gordon <icculus@icculus.org>
parents: 97
diff changeset
   301
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   302
        INDENT(); printf("CONSTANTS:");
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   303
        if (pd->constant_count == 0)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   304
            printf(" (none.)\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   305
        else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   306
        {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   307
            int i;
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   308
            printf("\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   309
            for (i = 0; i < pd->constant_count; i++)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   310
            {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   311
                static const char *typenames[] = { "float", "int", "bool" };
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   312
                const MOJOSHADER_constant *c = &pd->constants[i];
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   313
                INDENT(); 
278
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   314
                printf("    * %d: %s (", c->index, typenames[(int) c->type]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   315
                if (c->type == MOJOSHADER_UNIFORM_FLOAT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   316
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   317
                    printf("%f %f %f %f", c->value.f[0], c->value.f[1],
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   318
                                          c->value.f[2], c->value.f[3]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   319
                } // if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   320
                else if (c->type == MOJOSHADER_UNIFORM_INT)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   321
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   322
                    printf("%d %d %d %d", c->value.i[0], c->value.i[1],
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   323
                                          c->value.i[2], c->value.i[3]);
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   324
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   325
                else if (c->type == MOJOSHADER_UNIFORM_BOOL)
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   326
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   327
                    printf("%s", c->value.b ? "true" : "false");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   328
                } // else if
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   329
                else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   330
                {
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   331
                    printf("???");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   332
                } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   333
                printf(")\n");
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   334
            } // for
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   335
        } // else
5c432d216078 Report hardcoded constants in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 254
diff changeset
   336
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   337
        INDENT(); printf("UNIFORMS:");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   338
        if (pd->uniform_count == 0)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   339
            printf(" (none.)\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   340
        else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   341
        {
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   342
            int i;
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   343
            printf("\n");
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   344
            for (i = 0; i < pd->uniform_count; i++)
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   345
            {
94
57adfb4769a0 Simplifed public uniform information.
Ryan C. Gordon <icculus@icculus.org>
parents: 92
diff changeset
   346
                static const char *typenames[] = { "float", "int", "bool" };
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   347
                const MOJOSHADER_uniform *u = &pd->uniforms[i];
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   348
                const char *arrayof = "";
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   349
                const char *constant = u->constant ? "const " : "";
280
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   350
                char arrayrange[64] = { '\0' };
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   351
                if (u->array_count > 0)
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   352
                {
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   353
                    arrayof = "array[";
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   354
                    snprintf(arrayrange, sizeof (arrayrange), "%d] ",
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   355
                             u->array_count);
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   356
                } // if
61b2abd9c927 Relative addressing fixes.
Ryan C. Gordon <icculus@icculus.org>
parents: 278
diff changeset
   357
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   358
                INDENT();
438
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   359
                printf("    * %d: %s%s%s%s", u->index, constant, arrayof,
73492129c1af Expose true constant arrays in parseData, load them at link time for GLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 280
diff changeset
   360
                        arrayrange, typenames[(int) u->type]);
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   361
                if (u->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   362
                    printf(" (\"%s\")", u->name);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   363
                printf("\n");
92
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   364
            } // for
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   365
        } // else
bc1bb138e855 Implemented foundation for reporting uniforms to calling app.
Ryan C. Gordon <icculus@icculus.org>
parents: 53
diff changeset
   366
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   367
        INDENT(); printf("SAMPLERS:");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   368
        if (pd->sampler_count == 0)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   369
            printf(" (none.)\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   370
        else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   371
        {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   372
            int i;
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   373
            printf("\n");
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   374
            for (i = 0; i < pd->sampler_count; i++)
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   375
            {
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   376
                static const char *typenames[] = { "2d", "cube", "volume" };
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   377
                const MOJOSHADER_sampler *s = &pd->samplers[i];
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   378
                INDENT();
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   379
                printf("    * %d: %s", s->index, typenames[(int) s->type]);
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   380
                if (s->name != NULL)
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   381
                    printf(" (\"%s\")", s->name);
1090
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   382
                if (s->texbem)
636ffcd3f14a First shot at GLSL/ARB1 support for TEXBEM and TEXBEML opcodes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1055
diff changeset
   383
                    printf(" [TEXBEM]");
192
e7c864575d1c Print variable names in testparse.c.
Ryan C. Gordon <icculus@icculus.org>
parents: 148
diff changeset
   384
                printf("\n");
148
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   385
            } // for
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   386
        } // else
645003ec6623 Hopefully sorted out the reported uniform/attribute mess.
Ryan C. Gordon <icculus@icculus.org>
parents: 142
diff changeset
   387
1044
1241d4a56b28 Report preshader symbol table in testparse.
Ryan C. Gordon <icculus@icculus.org>
parents: 1037
diff changeset
   388
        print_symbols(pd->symbols, pd->symbol_count, indent);
1028
74e7ee46ac93 Parse symbols in the CTAB, export them in MOJOSHADER_parseData.
Ryan C. Gordon <icculus@icculus.org>
parents: 1019
diff changeset
   389
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   390
        if (pd->preshader != NULL)
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   391
            print_preshader(pd->preshader, indent);
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   392
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   393
        if (pd->output != NULL)
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   394
        {
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   395
            int i;
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   396
            INDENT();
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   397
            printf("OUTPUT:\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   398
            indent++;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   399
            INDENT();
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   400
            for (i = 0; i < pd->output_len; i++)
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   401
            {
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   402
                putchar((int) pd->output[i]);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   403
                if (pd->output[i] == '\n')
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   404
                    INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   405
            } // for
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   406
            printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   407
            indent--;
113
8ebf445c5305 Print output in testparse.c byte-by-byte instead of as an ASCIZ string.
Ryan C. Gordon <icculus@icculus.org>
parents: 100
diff changeset
   408
        } // if
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   409
    } // else
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 1028
diff changeset
   410
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   411
    printf("\n\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   412
} // print_shader
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   413
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   414
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   415
#ifdef MOJOSHADER_EFFECT_SUPPORT
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   416
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   417
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   418
static void print_value(const MOJOSHADER_effectValue *value,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   419
                        const unsigned int indent)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   420
{
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   421
    int i;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   422
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   423
    INDENT();
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   424
    printf("VALUE: %s -> %s\n", value->name, value->semantic);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   425
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   426
    static const char *classes[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   427
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   428
        "SCALAR",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   429
        "VECTOR",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   430
        "ROW-MAJOR MATRIX",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   431
        "COLUMN-MAJOR MATRIX",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   432
        "OBJECT",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   433
        "STRUCT"
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   434
    };
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   435
    static const char *types[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   436
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   437
        "VOID",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   438
        "BOOL",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   439
        "INT",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   440
        "FLOAT",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   441
        "STRING",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   442
        "TEXTURE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   443
        "TEXTURE1D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   444
        "TEXTURE2D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   445
        "TEXTURE3D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   446
        "TEXTURECUBE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   447
        "SAMPLER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   448
        "SAMPLER1D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   449
        "SAMPLER2D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   450
        "SAMPLER3D",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   451
        "SAMPLERCUBE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   452
        "PIXELSHADER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   453
        "VERTEXSHADER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   454
        "UNSUPPORTED"
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   455
    };
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   456
    do_indent(indent + 1);
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   457
    printf("CLASS: %s\n", classes[value->type.parameter_class]);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   458
    do_indent(indent + 1);
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   459
    printf("TYPE: %s\n", types[value->type.parameter_type]);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   460
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   461
    do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   462
    printf("ROWS/COLUMNS/ELEMENTS: %d, %d, %d\n",
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   463
           value->type.rows, value->type.columns, value->type.elements);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   464
    do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   465
    printf("TOTAL VALUES: %d\n", value->value_count);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   466
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   467
    if (value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   468
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER1D
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   469
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER2D
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   470
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLER3D
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   471
     || value->type.parameter_type == MOJOSHADER_SYMTYPE_SAMPLERCUBE)
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   472
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   473
        do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   474
        printf("SAMPLER VALUES:\n");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   475
        for (i = 0; i < value->value_count; i++)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   476
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   477
            MOJOSHADER_effectSamplerState *state = &value->valuesSS[i];
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   478
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   479
            static const char *samplerstatetypes[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   480
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   481
                "UNKNOWN0",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   482
                "UNKNOWN1",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   483
                "UNKNOWN2",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   484
                "UNKNOWN3",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   485
                "TEXTURE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   486
                "ADDRESSU",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   487
                "ADDRESSV",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   488
                "ADDRESSW",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   489
                "BORDERCOLOR",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   490
                "MAGFILTER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   491
                "MINFILTER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   492
                "MIPFILTER",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   493
                "MIPMAPLODBIAS",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   494
                "MAXMIPLEVEL",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   495
                "MAXANISOTROPY",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   496
                "SRGBTEXTURE",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   497
                "ELEMENTINDEX",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   498
                "DMAPOFFSET",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   499
            };
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   500
            do_indent(indent + 2);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   501
            printf("TYPE: %s -> ", samplerstatetypes[state->type]);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   502
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   503
            /* Assuming only one value per state! */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   504
            if (state->type == MOJOSHADER_SAMP_MIPMAPLODBIAS)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   505
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   506
                /* float types */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   507
                printf("%.2f\n", *state->value.valuesF);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   508
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   509
            else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   510
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   511
                /* int/enum types */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   512
                printf("%d\n", *state->value.valuesI);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   513
            } // else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   514
        } // for
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   515
    } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   516
    else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   517
    {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   518
        do_indent(indent + 1);
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   519
        printf("%s VALUES:\n", types[value->type.parameter_type]);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   520
        for (i = 0; i < value->value_count; i++)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   521
        {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   522
            do_indent(indent + 2);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   523
            static const char *prints[] =
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   524
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   525
                "%X\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   526
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   527
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   528
                "%.2f\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   529
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   530
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   531
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   532
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   533
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   534
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   535
                "SAMPLER?!\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   536
                "SAMPLER?!\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   537
                "SAMPLER?!\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   538
                "SAMPLER?!\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   539
                "SAMPLER?!\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   540
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   541
                "%d\n",
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   542
                "%X\n"
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   543
            };
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   544
            if (value->type.parameter_type == MOJOSHADER_SYMTYPE_FLOAT)
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   545
                printf(prints[value->type.parameter_type], value->valuesF[i]);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   546
            else
1152
8f7653f0dc37 Effect struct parameter support
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1150
diff changeset
   547
                printf(prints[value->type.parameter_type], value->valuesI[i]);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   548
        } // for
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   549
    } // else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   550
} // print_value
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   551
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   552
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   553
static void print_effect(const char *fname, const MOJOSHADER_effect *effect,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   554
                         const unsigned int indent)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   555
{
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   556
    INDENT();
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   557
    printf("PROFILE: %s\n", effect->profile);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   558
    printf("\n");
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   559
    if (effect->error_count > 0)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   560
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   561
        int i;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   562
        for (i = 0; i < effect->error_count; i++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   563
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   564
            const MOJOSHADER_error *err = &effect->errors[i];
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   565
            INDENT();
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   566
            printf("%s:%d: ERROR: %s\n",
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   567
                    err->filename ? err->filename : fname,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   568
                    err->error_position, err->error);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   569
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   570
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   571
    else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   572
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   573
        int i, j, k;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   574
        const MOJOSHADER_effectTechnique *technique = effect->techniques;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   575
        const MOJOSHADER_effectObject *object = effect->objects;
1037
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   576
        const MOJOSHADER_effectParam *param = effect->params;
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   577
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   578
        for (i = 0; i < effect->param_count; i++, param++)
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   579
        {
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   580
            INDENT();
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   581
            printf("PARAM #%d\n", i);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   582
            print_value(&param->value, indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   583
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   584
            if (param->annotation_count > 0)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   585
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   586
                do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   587
                printf("ANNOTATIONS:\n");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   588
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   589
            for (j = 0; j < param->annotation_count; j++)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   590
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   591
                print_value(&param->annotations[j], indent + 2);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   592
            } // for
1037
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   593
        } // for
b102a563d9cb Filled in and fixed some stuff in the Effect parser.
Ryan C. Gordon <icculus@icculus.org>
parents: 1034
diff changeset
   594
        printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   595
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   596
        for (i = 0; i < effect->technique_count; i++, technique++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   597
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   598
            const MOJOSHADER_effectPass *pass = technique->passes;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   599
            INDENT();
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   600
            printf("TECHNIQUE #%d ('%s'):\n", i, technique->name);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   601
            for (j = 0; j < technique->pass_count; j++, pass++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   602
            {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   603
                const MOJOSHADER_effectState *state = pass->states;
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   604
                do_indent(indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   605
                printf("PASS #%d ('%s'):\n", j, pass->name);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   606
                for (k = 0; k < pass->state_count; k++, state++)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   607
                {
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   608
                    do_indent(indent + 2);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   609
                    printf("STATE %d:\n", state->type);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   610
                    print_value(&state->value, indent + 3);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   611
                } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   612
            } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   613
        } // for
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   614
        printf("\n");
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   615
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   616
        /* Start at index 1, 0 is always empty (thanks Microsoft!) */
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   617
        object++;
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   618
        for (i = 1; i < effect->object_count; i++, object++)
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   619
        {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   620
            INDENT();
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   621
            if (object->type == MOJOSHADER_SYMTYPE_PIXELSHADER
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   622
             || object->type == MOJOSHADER_SYMTYPE_VERTEXSHADER)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   623
            {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   624
                if (object->shader.is_preshader)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   625
                {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   626
                    printf("OBJECT #%d: PRESHADER, technique %u, pass %u, param %s\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   627
                           object->shader.technique, object->shader.pass,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   628
                           effect->params[object->shader.params[0]].value.name);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   629
                    print_preshader(object->shader.preshader, indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   630
                } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   631
                else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   632
                {
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   633
                    printf("OBJECT #%d: SHADER, technique %u, pass %u\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   634
                           object->shader.technique, object->shader.pass);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   635
                    print_shader(fname, object->shader.shader, indent + 1);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   636
                } // else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   637
            } // if
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   638
            else if (object->type == MOJOSHADER_SYMTYPE_STRING)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   639
                printf("OBJECT #%d: STRING, '%s'\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   640
                       object->string.string);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   641
            else if (object->type == MOJOSHADER_SYMTYPE_SAMPLER
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   642
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLER1D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   643
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLER2D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   644
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLER3D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   645
                  || object->type == MOJOSHADER_SYMTYPE_SAMPLERCUBE)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   646
                printf("OBJECT #%d: MAPPING, '%s'\n", i,
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   647
                       object->mapping.name);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   648
            else if (object->type == MOJOSHADER_SYMTYPE_TEXTURE
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   649
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURE1D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   650
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURE2D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   651
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURE3D
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   652
                  || object->type == MOJOSHADER_SYMTYPE_TEXTURECUBE)
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   653
                printf("OBJECT #%d: TEXTURE\n", i);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   654
            else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   655
                printf("UNKNOWN OBJECT: #%d\n", i);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   656
        } // for
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   657
    } // else
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   658
} // print_effect
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   659
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   660
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   661
#endif // MOJOSHADER_EFFECT_SUPPORT
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   662
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   663
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   664
static int do_parse(const char *fname, const unsigned char *buf,
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   665
                    const int len, const char *prof)
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   666
{
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   667
    int retval = 0;
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   668
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   669
    // magic for an effects file (!!! FIXME: I _think_).
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   670
    if ( ((buf[0] == 0x01) && (buf[1] == 0x09) &&
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   671
          (buf[2] == 0xFF) && (buf[3] == 0xFE)) ||
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   672
         ((buf[0] == 0xCF) && (buf[1] == 0x0B) &&
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   673
          (buf[2] == 0xF0) && (buf[3] == 0xBC)) )
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   674
    {
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   675
#ifdef MOJOSHADER_EFFECT_SUPPORT
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   676
        const MOJOSHADER_effect *effect;
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   677
        effect = MOJOSHADER_parseEffect(prof, buf, len, NULL, 0,
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   678
                                        NULL, 0, Malloc, Free, 0);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   679
        retval = (effect->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   680
        printf("EFFECT: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   681
        print_effect(fname, effect, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   682
        MOJOSHADER_freeEffect(effect);
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   683
#else
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   684
        printf("Is an effect, but effect support is disabled!\n");
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1104
diff changeset
   685
#endif
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   686
    } // if
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   687
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   688
    else  // do it as a regular compiled shader.
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   689
    {
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   690
        const MOJOSHADER_parseData *pd;
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1152
diff changeset
   691
        pd = MOJOSHADER_parse(prof, NULL, buf, len, NULL, 0,
1104
9147482e1ec7 Allow sampler type remapping.
Ryan C. Gordon <icculus@icculus.org>
parents: 1090
diff changeset
   692
                              NULL, 0, Malloc, Free, NULL);
1019
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   693
        retval = (pd->error_count == 0);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   694
        printf("SHADER: %s\n", fname);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   695
        print_shader(fname, pd, 1);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   696
        MOJOSHADER_freeParseData(pd);
e8988ca01c6d Initial work on parsing binary Effects files.
Ryan C. Gordon <icculus@icculus.org>
parents: 902
diff changeset
   697
    } // else
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   698
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   699
    return retval;
46
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   700
} // do_parse
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   701
ff5a0ec44f00 [svn] Lots and lots of work on the public API.
icculus
parents: 37
diff changeset
   702
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   703
int main(int argc, char **argv)
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   704
{
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   705
    int retval = 0;
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   706
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   707
    printf("MojoShader testparse\n");
901
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   708
    printf("Compiled against changeset %s\n", MOJOSHADER_CHANGESET);
a9f799b93150 Report changeset, not version.
Ryan C. Gordon <icculus@icculus.org>
parents: 588
diff changeset
   709
    printf("Linked against changeset %s\n", MOJOSHADER_changeset());
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   710
    printf("\n");
37
63b5ba0bcda0 [svn] Update testparse for renames.
icculus
parents: 18
diff changeset
   711
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   712
    if (argc <= 2)
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   713
        printf("\n\nUSAGE: %s <profile> [file1] ... [fileN]\n\n", argv[0]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   714
    else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   715
    {
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   716
        const char *profile = argv[1];
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   717
        int i;
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   718
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   719
        for (i = 2; i < argc; i++)
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   720
        {
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   721
            FILE *io = fopen(argv[i], "rb");
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   722
            if (io == NULL)
53
8c856f73908e [svn] More testparse tweakage.
icculus
parents: 50
diff changeset
   723
                printf(" ... fopen('%s') failed.\n", argv[i]);
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   724
            else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   725
            {
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   726
                unsigned char *buf = (unsigned char *) malloc(1000000);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   727
                int rc = fread(buf, 1, 1000000, io);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   728
                fclose(io);
902
cff5841d29e7 Report actual filename in errors.
Ryan C. Gordon <icculus@icculus.org>
parents: 901
diff changeset
   729
                if (!do_parse(argv[i], buf, rc, profile))
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   730
                    retval = 1;
47
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   731
                free(buf);
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   732
            } // else
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   733
        } // for
49953c7cb142 [svn] Some testparse cleanups.
icculus
parents: 46
diff changeset
   734
    } // else
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   735
142
e064b4cefb4e Return a more-meaningful pass/fail error code from testparse main().
Ryan C. Gordon <icculus@icculus.org>
parents: 113
diff changeset
   736
    return retval;
7
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   737
} // main
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   738
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   739
// end of testparse.c ...
18bf77bb8c07 [svn] Cleanups, split things out.
icculus
parents:
diff changeset
   740