profiles/mojoshader_profile_common.c
author Martin Krošlák <kroslakma@gmail.com>
Tue, 31 Dec 2019 12:22:44 -0500
changeset 1224 21cd84f1aa0a
parent 1200 eb1e5280a5a9
child 1289 f47a47343dbc
permissions -rw-r--r--
Add support for emitting SPIR-V shaders. Co-authors include: - Angus Holder <aholder97@gmail.com> - Melker Narikka <meklu@meklu.org> - Caleb Cornett <caleb.cornett@outlook.com> - Ethan Lee <flibitijibibo@flibitijibibo.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     1
/**
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     3
 *  Direct3D shaders.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     4
 *
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     6
 *
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     8
 */
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
     9
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    10
#define __MOJOSHADER_INTERNAL__ 1
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    11
#include "mojoshader_profile.h"
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    12
1200
eb1e5280a5a9 Move the visibility pragmas below the includes.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1199
diff changeset
    13
#pragma GCC visibility push(hidden)
eb1e5280a5a9 Move the visibility pragmas below the includes.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1199
diff changeset
    14
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    15
// Common Utilities
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    16
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    17
void out_of_memory(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    18
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    19
    ctx->isfail = ctx->out_of_memory = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    20
} // out_of_memory
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    21
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    22
void *Malloc(Context *ctx, const size_t len)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    23
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    24
    void *retval = ctx->malloc((int) len, ctx->malloc_data);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    25
    if (retval == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    26
        out_of_memory(ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    27
    return retval;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    28
} // Malloc
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    29
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    30
char *StrDup(Context *ctx, const char *str)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    31
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    32
    char *retval = (char *) Malloc(ctx, strlen(str) + 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    33
    if (retval != NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    34
        strcpy(retval, str);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    35
    return retval;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    36
} // StrDup
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    37
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    38
void Free(Context *ctx, void *ptr)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    39
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    40
    ctx->free(ptr, ctx->malloc_data);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    41
} // Free
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    42
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    43
void * MOJOSHADERCALL MallocBridge(int bytes, void *data)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    44
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    45
    return Malloc((Context *) data, (size_t) bytes);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    46
} // MallocBridge
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    47
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    48
void MOJOSHADERCALL FreeBridge(void *ptr, void *data)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    49
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    50
    Free((Context *) data, ptr);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    51
} // FreeBridge
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    52
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    53
// Jump between output sections in the context...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    54
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    55
int set_output(Context *ctx, Buffer **section)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    56
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    57
    // only create output sections on first use.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    58
    if (*section == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    59
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    60
        *section = buffer_create(256, MallocBridge, FreeBridge, ctx);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    61
        if (*section == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    62
            return 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    63
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    64
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    65
    ctx->output = *section;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    66
    return 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    67
} // set_output
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    68
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    69
void push_output(Context *ctx, Buffer **section)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    70
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    71
    assert(ctx->output_stack_len < (int) (STATICARRAYLEN(ctx->output_stack)));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    72
    ctx->output_stack[ctx->output_stack_len] = ctx->output;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    73
    ctx->indent_stack[ctx->output_stack_len] = ctx->indent;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    74
    ctx->output_stack_len++;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    75
    if (!set_output(ctx, section))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    76
        return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    77
    ctx->indent = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    78
} // push_output
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    79
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    80
void pop_output(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    81
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    82
    assert(ctx->output_stack_len > 0);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    83
    ctx->output_stack_len--;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    84
    ctx->output = ctx->output_stack[ctx->output_stack_len];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    85
    ctx->indent = ctx->indent_stack[ctx->output_stack_len];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    86
} // pop_output
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    87
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    88
// Shader model version magic...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    89
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    90
uint32 ver_ui32(const uint8 major, const uint8 minor)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    91
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    92
    return ( (((uint32) major) << 16) | (((minor) == 0xFF) ? 1 : (minor)) );
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    93
} // version_ui32
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    94
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    95
int shader_version_supported(const uint8 maj, const uint8 min)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    96
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    97
    return (ver_ui32(maj,min) <= ver_ui32(MAX_SHADER_MAJOR, MAX_SHADER_MINOR));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    98
} // shader_version_supported
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
    99
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   100
int shader_version_atleast(const Context *ctx, const uint8 maj,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   101
                                         const uint8 min)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   102
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   103
    return (ver_ui32(ctx->major_ver, ctx->minor_ver) >= ver_ui32(maj, min));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   104
} // shader_version_atleast
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   105
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   106
int shader_version_exactly(const Context *ctx, const uint8 maj,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   107
                           const uint8 min)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   108
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   109
    return ((ctx->major_ver == maj) && (ctx->minor_ver == min));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   110
} // shader_version_exactly
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   111
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   112
int shader_is_pixel(const Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   113
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   114
    return (ctx->shader_type == MOJOSHADER_TYPE_PIXEL);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   115
} // shader_is_pixel
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   116
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   117
int shader_is_vertex(const Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   118
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   119
    return (ctx->shader_type == MOJOSHADER_TYPE_VERTEX);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   120
} // shader_is_vertex
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   121
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   122
// Fail...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   123
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   124
int isfail(const Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   125
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   126
    return ctx->isfail;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   127
} // isfail
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   128
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   129
void failf(Context *ctx, const char *fmt, ...) ISPRINTF(2,3);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   130
void failf(Context *ctx, const char *fmt, ...)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   131
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   132
    ctx->isfail = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   133
    if (ctx->out_of_memory)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   134
        return;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   135
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   136
    // no filename at this level (we pass a NULL to errorlist_add_va()...)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   137
    va_list ap;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   138
    va_start(ap, fmt);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   139
    errorlist_add_va(ctx->errors, NULL, ctx->current_position, fmt, ap);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   140
    va_end(ap);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   141
} // failf
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   142
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   143
void fail(Context *ctx, const char *reason)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   144
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   145
    failf(ctx, "%s", reason);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   146
} // fail
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   147
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   148
// Output Lines...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   149
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   150
void output_line(Context *ctx, const char *fmt, ...) ISPRINTF(2,3);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   151
void output_line(Context *ctx, const char *fmt, ...)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   152
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   153
    assert(ctx->output != NULL);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   154
    if (isfail(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   155
        return;  // we failed previously, don't go on...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   156
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   157
    const int indent = ctx->indent;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   158
    if (indent > 0)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   159
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   160
        char *indentbuf = (char *) alloca(indent);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   161
        memset(indentbuf, '\t', indent);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   162
        buffer_append(ctx->output, indentbuf, indent);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   163
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   164
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   165
    va_list ap;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   166
    va_start(ap, fmt);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   167
    buffer_append_va(ctx->output, fmt, ap);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   168
    va_end(ap);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   169
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   170
    buffer_append(ctx->output, ctx->endline, ctx->endline_len);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   171
} // output_line
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   172
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   173
void output_blank_line(Context *ctx)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   174
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   175
    assert(ctx->output != NULL);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   176
    if (!isfail(ctx))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   177
        buffer_append(ctx->output, ctx->endline, ctx->endline_len);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   178
} // output_blank_line
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   179
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   180
// !!! FIXME: this is sort of nasty.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   181
void floatstr(Context *ctx, char *buf, size_t bufsize, float f,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   182
              int leavedecimal)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   183
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   184
    const size_t len = MOJOSHADER_printFloat(buf, bufsize, f);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   185
    if ((len+2) >= bufsize)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   186
        fail(ctx, "BUG: internal buffer is too small");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   187
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   188
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   189
        char *end = buf + len;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   190
        char *ptr = strchr(buf, '.');
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   191
        if (ptr == NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   192
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   193
            if (leavedecimal)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   194
                strcat(buf, ".0");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   195
            return;  // done.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   196
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   197
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   198
        while (--end != ptr)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   199
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   200
            if (*end != '0')
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   201
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   202
                end++;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   203
                break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   204
            } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   205
        } // while
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   206
        if ((leavedecimal) && (end == ptr))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   207
            end += 2;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   208
        *end = '\0';  // chop extra '0' or all decimal places off.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   209
    } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   210
} // floatstr
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   211
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   212
// Deal with register lists...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   213
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   214
static inline uint32 reg_to_ui32(const RegisterType regtype, const int regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   215
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   216
    return ( ((uint32) regnum) | (((uint32) regtype) << 16) );
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   217
} // reg_to_uint32
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   218
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   219
// !!! FIXME: ditch this for a hash table.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   220
RegisterList *reglist_insert(Context *ctx, RegisterList *prev,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   221
                             const RegisterType regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   222
                             const int regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   223
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   224
    const uint32 newval = reg_to_ui32(regtype, regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   225
    RegisterList *item = prev->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   226
    while (item != NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   227
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   228
        const uint32 val = reg_to_ui32(item->regtype, item->regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   229
        if (newval == val)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   230
            return item;  // already set, so we're done.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   231
        else if (newval < val)  // insert it here.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   232
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   233
        else // if (newval > val)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   234
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   235
            // keep going, we're not to the insertion point yet.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   236
            prev = item;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   237
            item = item->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   238
        } // else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   239
    } // while
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   240
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   241
    // we need to insert an entry after (prev).
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   242
    item = (RegisterList *) Malloc(ctx, sizeof (RegisterList));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   243
    if (item != NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   244
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   245
        item->regtype = regtype;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   246
        item->regnum = regnum;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   247
        item->usage = MOJOSHADER_USAGE_UNKNOWN;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   248
        item->index = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   249
        item->writemask = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   250
        item->misc = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   251
        item->written = 0;
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1200
diff changeset
   252
#if SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1200
diff changeset
   253
        item->spirv.iddecl = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1200
diff changeset
   254
        item->spirv.is_ssa = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1200
diff changeset
   255
#endif
1199
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   256
        item->array = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   257
        item->next = prev->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   258
        prev->next = item;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   259
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   260
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   261
    return item;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   262
} // reglist_insert
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   263
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   264
RegisterList *reglist_find(const RegisterList *prev,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   265
                           const RegisterType rtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   266
                           const int regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   267
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   268
    const uint32 newval = reg_to_ui32(rtype, regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   269
    RegisterList *item = prev->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   270
    while (item != NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   271
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   272
        const uint32 val = reg_to_ui32(item->regtype, item->regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   273
        if (newval == val)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   274
            return item;  // here it is.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   275
        else if (newval < val)  // should have been here if it existed.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   276
            return NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   277
        else // if (newval > val)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   278
            item = item->next;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   279
    } // while
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   280
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   281
    return NULL;  // wasn't in the list.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   282
} // reglist_find
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   283
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   284
RegisterList *set_used_register(Context *ctx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   285
                                const RegisterType regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   286
                                const int regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   287
                                const int written)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   288
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   289
    RegisterList *reg = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   290
    if ((regtype == REG_TYPE_COLOROUT) && (regnum > 0))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   291
        ctx->have_multi_color_outputs = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   292
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   293
    reg = reglist_insert(ctx, &ctx->used_registers, regtype, regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   294
    if (reg && written)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   295
        reg->written = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   296
    return reg;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   297
} // set_used_register
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   298
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   299
void set_defined_register(Context *ctx, const RegisterType rtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   300
                          const int regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   301
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   302
    reglist_insert(ctx, &ctx->defined_registers, rtype, regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   303
} // set_defined_register
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   304
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   305
// Writemasks
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   306
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   307
int writemask_xyzw(const int writemask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   308
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   309
    return (writemask == 0xF);  // 0xF == 1111. No explicit mask (full!).
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   310
} // writemask_xyzw
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   311
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   312
int writemask_xyz(const int writemask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   313
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   314
    return (writemask == 0x7);  // 0x7 == 0111. (that is: xyz)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   315
} // writemask_xyz
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   316
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   317
int writemask_xy(const int writemask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   318
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   319
    return (writemask == 0x3);  // 0x3 == 0011. (that is: xy)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   320
} // writemask_xy
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   321
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   322
int writemask_x(const int writemask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   323
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   324
    return (writemask == 0x1);  // 0x1 == 0001. (that is: x)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   325
} // writemask_x
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   326
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   327
int writemask_y(const int writemask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   328
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   329
    return (writemask == 0x2);  // 0x2 == 0010. (that is: y)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   330
} // writemask_y
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   331
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   332
int replicate_swizzle(const int swizzle)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   333
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   334
    return ( (((swizzle >> 0) & 0x3) == ((swizzle >> 2) & 0x3)) &&
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   335
             (((swizzle >> 2) & 0x3) == ((swizzle >> 4) & 0x3)) &&
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   336
             (((swizzle >> 4) & 0x3) == ((swizzle >> 6) & 0x3)) );
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   337
} // replicate_swizzle
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   338
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   339
int no_swizzle(const int swizzle)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   340
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   341
    return (swizzle == 0xE4);  // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   342
} // no_swizzle
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   343
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   344
int vecsize_from_writemask(const int m)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   345
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   346
    return (m & 1) + ((m >> 1) & 1) + ((m >> 2) & 1) + ((m >> 3) & 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   347
} // vecsize_from_writemask
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   348
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   349
void set_dstarg_writemask(DestArgInfo *dst, const int mask)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   350
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   351
    dst->writemask = mask;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   352
    dst->writemask0 = ((mask >> 0) & 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   353
    dst->writemask1 = ((mask >> 1) & 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   354
    dst->writemask2 = ((mask >> 2) & 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   355
    dst->writemask3 = ((mask >> 3) & 1);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   356
} // set_dstarg_writemask
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   357
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   358
// D3D stuff that's used in more than just the d3d profile...
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   359
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   360
int isscalar(Context *ctx, const MOJOSHADER_shaderType shader_type,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   361
             const RegisterType rtype, const int rnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   362
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   363
    const int uses_psize = ctx->uses_pointsize;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   364
    const int uses_fog = ctx->uses_fog;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   365
    if ( (rtype == REG_TYPE_OUTPUT) && ((uses_psize) || (uses_fog)) )
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   366
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   367
        const RegisterList *reg = reglist_find(&ctx->attributes, rtype, rnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   368
        if (reg != NULL)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   369
        {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   370
            const MOJOSHADER_usage usage = reg->usage;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   371
            return ( (uses_psize && (usage == MOJOSHADER_USAGE_POINTSIZE)) ||
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   372
                     (uses_fog && (usage == MOJOSHADER_USAGE_FOG)) );
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   373
        } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   374
    } // if
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   375
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   376
    return scalar_register(shader_type, rtype, rnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   377
} // isscalar
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   378
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   379
const char *get_D3D_register_string(Context *ctx,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   380
                                    RegisterType regtype,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   381
                                    int regnum, char *regnum_str,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   382
                                    size_t regnum_size)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   383
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   384
    const char *retval = NULL;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   385
    int has_number = 1;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   386
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   387
    switch (regtype)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   388
    {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   389
        case REG_TYPE_TEMP:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   390
            retval = "r";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   391
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   392
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   393
        case REG_TYPE_INPUT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   394
            retval = "v";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   395
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   396
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   397
        case REG_TYPE_CONST:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   398
            retval = "c";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   399
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   400
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   401
        case REG_TYPE_ADDRESS:  // (or REG_TYPE_TEXTURE, same value.)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   402
            retval = shader_is_vertex(ctx) ? "a" : "t";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   403
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   404
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   405
        case REG_TYPE_RASTOUT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   406
            switch ((RastOutType) regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   407
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   408
                case RASTOUT_TYPE_POSITION: retval = "oPos"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   409
                case RASTOUT_TYPE_FOG: retval = "oFog"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   410
                case RASTOUT_TYPE_POINT_SIZE: retval = "oPts"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   411
            } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   412
            has_number = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   413
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   414
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   415
        case REG_TYPE_ATTROUT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   416
            retval = "oD";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   417
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   418
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   419
        case REG_TYPE_OUTPUT: // (or REG_TYPE_TEXCRDOUT, same value.)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   420
            if (shader_is_vertex(ctx) && shader_version_atleast(ctx, 3, 0))
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   421
                retval = "o";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   422
            else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   423
                retval = "oT";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   424
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   425
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   426
        case REG_TYPE_CONSTINT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   427
            retval = "i";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   428
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   429
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   430
        case REG_TYPE_COLOROUT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   431
            retval = "oC";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   432
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   433
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   434
        case REG_TYPE_DEPTHOUT:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   435
            retval = "oDepth";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   436
            has_number = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   437
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   438
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   439
        case REG_TYPE_SAMPLER:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   440
            retval = "s";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   441
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   442
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   443
        case REG_TYPE_CONSTBOOL:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   444
            retval = "b";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   445
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   446
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   447
        case REG_TYPE_LOOP:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   448
            retval = "aL";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   449
            has_number = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   450
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   451
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   452
        case REG_TYPE_MISCTYPE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   453
            switch ((const MiscTypeType) regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   454
            {
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   455
                case MISCTYPE_TYPE_POSITION: retval = "vPos"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   456
                case MISCTYPE_TYPE_FACE: retval = "vFace"; break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   457
            } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   458
            has_number = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   459
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   460
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   461
        case REG_TYPE_LABEL:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   462
            retval = "l";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   463
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   464
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   465
        case REG_TYPE_PREDICATE:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   466
            retval = "p";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   467
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   468
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   469
        //case REG_TYPE_TEMPFLOAT16:  // !!! FIXME: don't know this asm string
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   470
        default:
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   471
            fail(ctx, "unknown register type");
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   472
            retval = "???";
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   473
            has_number = 0;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   474
            break;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   475
    } // switch
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   476
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   477
    if (has_number)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   478
        snprintf(regnum_str, regnum_size, "%u", (uint) regnum);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   479
    else
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   480
        regnum_str[0] = '\0';
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   481
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   482
    return retval;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   483
} // get_D3D_register_string
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   484
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   485
// !!! FIXME: These should stay in the mojoshader_profile_d3d file
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   486
// !!! FIXME: but ARB1 relies on them, so we have to move them here.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   487
// !!! FIXME: If/when we kill off ARB1, we can move these back.
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   488
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   489
const char *get_D3D_varname_in_buf(Context *ctx, RegisterType rt,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   490
                                   int regnum, char *buf,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   491
                                   const size_t len)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   492
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   493
    char regnum_str[16];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   494
    const char *regtype_str = get_D3D_register_string(ctx, rt, regnum,
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   495
                                              regnum_str, sizeof (regnum_str));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   496
    snprintf(buf,len,"%s%s", regtype_str, regnum_str);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   497
    return buf;
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   498
} // get_D3D_varname_in_buf
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   499
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   500
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   501
const char *get_D3D_varname(Context *ctx, RegisterType rt, int regnum)
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   502
{
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   503
    char buf[64];
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   504
    get_D3D_varname_in_buf(ctx, rt, regnum, buf, sizeof (buf));
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   505
    return StrDup(ctx, buf);
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   506
} // get_D3D_varname
b8ece252a201 Reorganize profiles into their own files
Caleb Cornett <caleb.cornett@outlook.com>
parents:
diff changeset
   507
1200
eb1e5280a5a9 Move the visibility pragmas below the includes.
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1199
diff changeset
   508
#pragma GCC visibility pop