profiles/mojoshader_profile_spirv.c
author Martin Krošlák <kroslakma@gmail.com>
Sun, 03 May 2020 09:52:42 +0200
changeset 1253 c84325b641cc
parent 1249 349cc8980298
child 1258 077de213154d
permissions -rw-r--r--
Add descriptor set assignment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     1
/**
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     2
 * MojoShader; generate shader programs from bytecode of compiled
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     3
 *  Direct3D shaders.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     4
 *
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     5
 * Please see the file LICENSE.txt in the source's root directory.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     6
 *
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     7
 *  This file written by Ryan C. Gordon.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     8
 */
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
     9
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    10
#define __MOJOSHADER_INTERNAL__ 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    11
#include "mojoshader_profile.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    12
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    13
#pragma GCC visibility push(hidden)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    14
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    15
#if SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    16
#include "spirv/spirv.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    17
#include "spirv/GLSL.std.450.h"
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    18
#include <float.h>
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    19
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    20
static const int SPV_NO_SWIZZLE = 0xE4; // 0xE4 == 11100100 ... 0 1 2 3. No swizzle.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    21
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    22
#define EMIT_SPIRV_OPCODE_UNIMPLEMENTED_FUNC(op) \
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    23
    void emit_SPIRV_##op(Context *ctx) { \
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    24
        fail(ctx, #op " unimplemented in spirv profile"); \
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    25
    }
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    26
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    27
typedef struct SpirvTexm3x3SetupResult
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    28
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    29
    // vec4 load results
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    30
    uint32 id_dst_pad0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    31
    uint32 id_dst_pad1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    32
    uint32 id_dst;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    33
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    34
    // float dot results
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    35
    uint32 id_res_x;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    36
    uint32 id_res_y;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    37
    uint32 id_res_z;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    38
} SpirvTexm3x3SetupResult;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    39
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    40
static const char *spv_get_uniform_array_varname(Context *ctx,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    41
                                                   const RegisterType regtype,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    42
                                                   char *buf, const size_t len)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    43
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    44
    const char *shadertype = ctx->shader_type_str;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    45
    const char *type = "";
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    46
    switch (regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    47
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    48
        case REG_TYPE_CONST: type = "vec4"; break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    49
        case REG_TYPE_CONSTINT: type = "ivec4"; break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    50
        case REG_TYPE_CONSTBOOL: type = "bool"; break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    51
        default: fail(ctx, "BUG: used a uniform we don't know how to define.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    52
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    53
    snprintf(buf, len, "%s_uniforms_%s", shadertype, type);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    54
    return buf;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    55
} // spv_get_uniform_array_varname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    56
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    57
static uint32 spv_bumpid(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    58
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    59
    return (ctx->spirv.idmax += 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    60
} // spv_bumpid
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    61
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    62
static RegisterList *spv_getreg(Context *ctx, const RegisterType regtype, const int regnum)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    63
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    64
    RegisterList *r = reglist_find(&ctx->used_registers, regtype, regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    65
    if (!r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    66
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    67
        failf(ctx, "register not found rt=%d, rn=%d", regtype, regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    68
        return NULL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    69
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    70
    return r;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    71
} // spv_getreg
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    72
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    73
static void spv_componentlist_free(Context *ctx, ComponentList *cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    74
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    75
    ComponentList *next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    76
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    77
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    78
        next = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    79
        Free(ctx, cl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    80
        cl = next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    81
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    82
} // spv_componentlist_free
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    83
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    84
static ComponentList *spv_componentlist_alloc(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    85
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    86
    ComponentList *ret = (ComponentList *) Malloc(ctx, sizeof(ComponentList));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    87
    if (!ret) return NULL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    88
    ret->id = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    89
    ret->v.i = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    90
    ret->next = NULL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    91
    return ret;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    92
} // spv_componentlist_alloc
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    93
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    94
static const char *get_SPIRV_varname_in_buf(Context *ctx, const RegisterType rt,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    95
                                           const int regnum, char *buf,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    96
                                           const size_t buflen)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    97
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    98
    // turns out these are identical at the moment.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
    99
    return get_D3D_varname_in_buf(ctx, rt, regnum, buf, buflen);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   100
} // get_SPIRV_varname_in_buf
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   101
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   102
const char *get_SPIRV_varname(Context *ctx, const RegisterType rt,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   103
                                    const int regnum)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   104
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   105
    // turns out these are identical at the moment.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   106
    return get_D3D_varname(ctx, rt, regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   107
} // get_SPIRV_varname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   108
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   109
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   110
static inline const char *get_SPIRV_const_array_varname_in_buf(Context *ctx,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   111
                                                const int base, const int size,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   112
                                                char *buf, const size_t buflen)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   113
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   114
    snprintf(buf, buflen, "c_array_%d_%d", base, size);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   115
    return buf;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   116
} // get_SPIRV_const_array_varname_in_buf
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   117
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   118
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   119
const char *get_SPIRV_const_array_varname(Context *ctx, int base, int size)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   120
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   121
    char buf[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   122
    get_SPIRV_const_array_varname_in_buf(ctx, base, size, buf, sizeof (buf));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   123
    return StrDup(ctx, buf);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   124
} // get_SPIRV_const_array_varname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   125
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   126
static uint32 spv_get_uniform_array_id(Context *ctx, const RegisterType regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   127
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   128
    uint32 id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   129
    switch (regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   130
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   131
        case REG_TYPE_CONST:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   132
            id = ctx->spirv.uniform_arrays.idvec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   133
            if (id == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   134
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   135
                id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   136
                ctx->spirv.uniform_arrays.idvec4 = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   137
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   138
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   139
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   140
        case REG_TYPE_CONSTINT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   141
            id = ctx->spirv.uniform_arrays.idivec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   142
            if (id == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   143
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   144
                id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   145
                ctx->spirv.uniform_arrays.idivec4 = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   146
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   147
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   148
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   149
        case REG_TYPE_CONSTBOOL:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   150
            id = ctx->spirv.uniform_arrays.idbool;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   151
            if (id == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   152
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   153
                id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   154
                ctx->spirv.uniform_arrays.idbool = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   155
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   156
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   157
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   158
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   159
            fail(ctx, "Unexpected register type used to access uniform array.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   160
            id = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   161
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   162
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   163
    return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   164
} // spv_get_uniform_array_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   165
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   166
static void spv_emit_part_va(Context* ctx, uint32 word_count, uint32 argc, SpvOp op, va_list args)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   167
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   168
    assert(ctx->output != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   169
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   170
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   171
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   172
    uint32 word = op | (word_count << 16);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   173
    buffer_append(ctx->output, &word, sizeof(word));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   174
    while (--argc)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   175
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   176
        word = va_arg(args, uint32);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   177
        buffer_append(ctx->output, &word, sizeof(word));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   178
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   179
} // spv_emit_part_va
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   180
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   181
static void spv_emit_part(Context* ctx, uint32 word_count, uint32 argc, SpvOp op, ...)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   182
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   183
    va_list args;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   184
    va_start(args, op);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   185
    spv_emit_part_va(ctx, word_count, argc, op, args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   186
    va_end(args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   187
} // spv_emit_part
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   188
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   189
static void spv_emit(Context *ctx, uint32 word_count, SpvOp op, ...)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   190
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   191
    va_list args;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   192
    va_start(args, op);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   193
    spv_emit_part_va(ctx, word_count, word_count, op, args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   194
    va_end(args);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   195
} // spv_emit
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   196
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   197
static void spv_emit_word(Context *ctx, uint32 word)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   198
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   199
    assert(ctx->output != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   200
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   201
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   202
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   203
    buffer_append(ctx->output, &word, sizeof(word));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   204
} // spv_emit_word
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   205
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   206
static void spv_emit_str(Context *ctx, const char *str)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   207
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   208
    size_t len;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   209
    uint32 trail;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   210
    assert(ctx->output != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   211
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   212
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   213
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   214
    if (str == NULL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   215
        return spv_emit_word(ctx, 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   216
    len = strlen(str) + 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   217
    buffer_append(ctx->output, str, len);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   218
    len = len % 4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   219
    if (len)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   220
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   221
        trail = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   222
        buffer_append(ctx->output, &trail, 4 - len);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   223
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   224
} // spv_emit_str
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   225
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   226
// get the word count of a string
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   227
static uint32 spv_strlen(const char *str)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   228
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   229
    size_t len = strlen(str);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   230
    return (uint32) ((len / 4) + 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   231
} // spv_strlen
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   232
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   233
// emits an OpName straight into ctx->globals
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   234
static void spv_output_name(Context *ctx, uint32 id, const char *str)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   235
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   236
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   237
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   238
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   239
    push_output(ctx, &ctx->globals);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   240
    spv_emit_part(ctx, 2 + spv_strlen(str), 2, SpvOpName, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   241
    spv_emit_str(ctx, str);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   242
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   243
} // spv_output_name
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   244
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   245
// emit an OpName instruction to identify a register
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   246
static void spv_output_regname(Context *ctx, uint32 id, RegisterType regtype, int regnum)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   247
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   248
    char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   249
    snprintf(varname, sizeof(varname), "%s_", ctx->shader_type_str);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   250
    size_t offset = strlen(varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   251
    get_SPIRV_varname_in_buf(ctx, regtype, regnum, varname + offset, sizeof(varname) - offset);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   252
    spv_output_name(ctx, id, varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   253
} // spv_output_regname
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   254
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   255
// emits an OpDecorate BuiltIn straight into ctx->helpers
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   256
static void spv_output_builtin(Context *ctx, uint32 id, SpvBuiltIn builtin)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   257
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   258
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   259
        return;  // we failed previously, don't go on...
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   260
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   261
    push_output(ctx, &ctx->helpers);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   262
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationBuiltIn, builtin);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   263
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   264
} // spv_output_builtin
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   265
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   266
static uint32 spv_output_location(Context *ctx, uint32 id, uint32 loc)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   267
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   268
    push_output(ctx, &ctx->helpers);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   269
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationLocation, loc);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   270
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   271
    return (buffer_size(ctx->helpers) >> 2) - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   272
} // spv_output_location
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   273
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   274
static void spv_output_sampler_binding(Context *ctx, uint32 id, uint32 binding)
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   275
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   276
    if (isfail(ctx))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   277
        return;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   278
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   279
    uint32 set = 0;
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   280
    if (ctx->spirv.mode == SPIRV_MODE_VK)
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   281
    {
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   282
        set = shader_is_vertex(ctx) ? MOJOSHADER_SPIRV_VS_SAMPLER_SET
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   283
                                    : MOJOSHADER_SPIRV_PS_SAMPLER_SET;
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   284
    } // if
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   285
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   286
    push_output(ctx, &ctx->helpers);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   287
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationDescriptorSet, set);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   288
    spv_emit(ctx, 4, SpvOpDecorate, id, SpvDecorationBinding, binding);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   289
    pop_output(ctx);
1253
c84325b641cc Add descriptor set assignment
Martin Krošlák <kroslakma@gmail.com>
parents: 1249
diff changeset
   290
} // spv_output_sampler_binding
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   291
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   292
static SpirvTypeIdx spv_change_base_type_vec_dim(SpirvTypeIdx sti, uint32 dim)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   293
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   294
    uint32 dimSub1 = dim - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   295
    assert(STI_CORE_START_ <= sti && sti < STI_CORE_END_);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   296
    assert(dimSub1 < 4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   297
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   298
    SpirvTypeIdx sti_base = (SpirvTypeIdx)(sti & ~0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   299
    SpirvTypeIdx sti_new = (SpirvTypeIdx)(sti_base | dimSub1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   300
    return sti_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   301
} // spv_change_base_type_vec_dim
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   302
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   303
static uint32 spv_get_type(Context *ctx, SpirvTypeIdx tidx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   304
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   305
    assert(((uint32)tidx) < ((uint32)STI_LENGTH_));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   306
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   307
    uint32 tid = ctx->spirv.tid[tidx];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   308
    if (tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   309
        return tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   310
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   311
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   312
    if (STI_CORE_START_ <= tidx && tidx < STI_CORE_END_)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   313
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   314
        uint32 dim = tidx & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   315
        SpirvType type = (SpirvType)((tidx >> 2) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   316
        if (dim)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   317
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   318
            uint32 tid_base = spv_get_type(ctx, (SpirvTypeIdx)(tidx - dim));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   319
            tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   320
            spv_emit(ctx, 4, SpvOpTypeVector, tid, tid_base, dim + 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   321
        } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   322
        else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   323
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   324
            tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   325
            switch (type)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   326
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   327
                case ST_FLOAT: spv_emit(ctx, 3, SpvOpTypeFloat, tid, 32); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   328
                case ST_SINT: spv_emit(ctx, 4, SpvOpTypeInt, tid, 32, 1); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   329
                case ST_UINT: spv_emit(ctx, 4, SpvOpTypeInt, tid, 32, 0); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   330
                case ST_BOOL: spv_emit(ctx, 2, SpvOpTypeBool, tid); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   331
                default: assert(!"Unexpected value of SpirvType."); break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   332
            } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   333
        } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   334
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   335
    else if (STI_IMAGE2D <= tidx && tidx <= STI_IMAGECUBE)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   336
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   337
        static const SpvDim dim_table[] = {SpvDim2D, SpvDim3D, SpvDimCube};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   338
        SpvDim dim = dim_table[tidx - STI_IMAGE2D];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   339
        uint32 tid_float = spv_get_type(ctx, STI_FLOAT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   340
        uint32 id_image = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   341
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   342
        spv_emit(ctx, 9, SpvOpTypeImage, id_image, tid_float, dim, 0, 0, 0, 1, SpvImageFormatUnknown);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   343
        spv_emit(ctx, 3, SpvOpTypeSampledImage, tid, id_image);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   344
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   345
    else if (tidx == STI_VOID)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   346
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   347
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   348
        spv_emit(ctx, 2, SpvOpTypeVoid, tid);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   349
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   350
    else if (tidx == STI_FUNC_VOID)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   351
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   352
        uint32 tid_void = spv_get_type(ctx, STI_VOID);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   353
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   354
        spv_emit(ctx, 3, SpvOpTypeFunction, tid, tid_void);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   355
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   356
    else if (tidx == STI_FUNC_LIT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   357
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   358
        uint32 tid_vec4 = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   359
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   360
        spv_emit(ctx, 3 + 1, SpvOpTypeFunction, tid, tid_vec4, tid_vec4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   361
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   362
    else if (STI_PTR_START_ <= tidx && tidx < STI_PTR_END_)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   363
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   364
        uint32 dim = (tidx & (1 << 4)) ? 3 : 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   365
        SpirvType type = (SpirvType)((tidx >> 2) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   366
        uint32 tid_base = spv_get_type(ctx, (SpirvTypeIdx)((1 << 4) | (type << 2) | dim));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   367
        static const SpvStorageClass sc_map[] = {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   368
            SpvStorageClassInput,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   369
            SpvStorageClassInput,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   370
            SpvStorageClassOutput,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   371
            SpvStorageClassOutput,
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   372
            SpvStorageClassPrivate,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   373
            SpvStorageClassPrivate,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   374
            SpvStorageClassUniformConstant,
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   375
            SpvStorageClassUniform,
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   376
        };
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   377
        SpvStorageClass sc = sc_map[((tidx & 0x3) << 1) | (ctx->spirv.mode == SPIRV_MODE_VK)];
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   378
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   379
        spv_emit(ctx, 4, SpvOpTypePointer, tid, sc, tid_base);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   380
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   381
    else if (STI_PTR_IMAGE2D <= tidx && tidx <= STI_PTR_IMAGECUBE)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   382
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   383
        uint32 tid_image = spv_get_type(ctx, (SpirvTypeIdx)(tidx - (STI_PTR_IMAGE2D - STI_IMAGE2D)));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   384
        tid = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   385
        spv_emit(ctx, 4, SpvOpTypePointer, tid, SpvStorageClassUniformConstant, tid_image);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   386
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   387
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   388
        assert(!"Unexpected value of type index.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   389
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   390
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   391
    ctx->spirv.tid[tidx] = tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   392
    return tid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   393
} // spv_get_type
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   394
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   395
static uint32 spv_gettrue(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   396
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   397
    if (ctx->spirv.idtrue)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   398
        return ctx->spirv.idtrue;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   399
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   400
    uint32 tid_bool = spv_get_type(ctx, STI_BOOL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   401
    uint32 id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   402
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   403
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   404
    spv_emit(ctx, 3, SpvOpConstantTrue, tid_bool, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   405
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   406
    return ctx->spirv.idtrue = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   407
} // spv_gettrue
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   408
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   409
static uint32 spv_getfalse(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   410
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   411
    if (ctx->spirv.idfalse)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   412
        return ctx->spirv.idfalse;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   413
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   414
    uint32 tid_bool = spv_get_type(ctx, STI_BOOL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   415
    uint32 id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   416
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   417
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   418
    spv_emit(ctx, 3, SpvOpConstantFalse, tid_bool, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   419
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   420
    return ctx->spirv.idfalse = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   421
} // spv_getfalse
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   422
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   423
static uint32 spv_getext(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   424
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   425
    if (ctx->spirv.idext)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   426
        return ctx->spirv.idext;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   427
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   428
    return ctx->spirv.idext = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   429
} // spv_getext
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   430
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   431
static uint32 spv_output_scalar(Context *ctx, ComponentList *cl,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   432
                             MOJOSHADER_attributeType type)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   433
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   434
    uint32 idret, idtype;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   435
    if (type == MOJOSHADER_ATTRIBUTE_FLOAT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   436
        idtype = spv_get_type(ctx, STI_FLOAT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   437
    else if (type == MOJOSHADER_ATTRIBUTE_INT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   438
        idtype = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   439
    else if (type == MOJOSHADER_ATTRIBUTE_UINT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   440
        idtype = spv_get_type(ctx, STI_UINT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   441
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   442
    {
1234
608cef8fa24d VS2010 buildfixes
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1228
diff changeset
   443
        failf(ctx, "spv_output_scalar: invalid attribute type %d", type);
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   444
        return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   445
    } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   446
    idret = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   447
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   448
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   449
    spv_emit(ctx, 4, SpvOpConstant, idtype, idret, cl->v.u);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   450
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   451
    return idret;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   452
} // spv_output_scalar
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   453
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   454
// The spv_getscalar* functions retrieve the result id of an OpConstant
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   455
// instruction with the corresponding value v, or generate a new one.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   456
static uint32 spv_getscalarf(Context *ctx, float v)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   457
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   458
    ComponentList *prev = &(ctx->spirv.cl.f), *cl = ctx->spirv.cl.f.next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   459
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   460
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   461
        if (v == cl->v.f)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   462
            return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   463
        else if (v < cl->v.f)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   464
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   465
        prev = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   466
        cl = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   467
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   468
    cl = spv_componentlist_alloc(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   469
    cl->next = prev->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   470
    prev->next = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   471
    cl->v.f = v;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   472
    cl->id = spv_output_scalar(ctx, cl, MOJOSHADER_ATTRIBUTE_FLOAT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   473
    return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   474
} // spv_getscalarf
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   475
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   476
static uint32 spv_getscalari(Context *ctx, int v)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   477
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   478
    ComponentList *prev = &(ctx->spirv.cl.i), *cl = ctx->spirv.cl.i.next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   479
    while (cl)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   480
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   481
        if (v == cl->v.i)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   482
            return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   483
        else if (v < cl->v.i)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   484
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   485
        prev = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   486
        cl = cl->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   487
    } // while
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   488
    cl = spv_componentlist_alloc(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   489
    cl->next = prev->next;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   490
    prev->next = cl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   491
    cl->v.i = v;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   492
    cl->id = spv_output_scalar(ctx, cl, MOJOSHADER_ATTRIBUTE_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   493
    return cl->id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   494
} // spv_getscalari
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   495
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   496
static uint32 spv_get_constant_composite(Context *ctx, uint32 tid, uint32* cache, float scalar)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   497
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   498
    uint32 i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   499
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   500
    assert(tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   501
    uint32 dim =
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   502
       (tid == ctx->spirv.tid[STI_VEC4]) ? 4 :
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   503
       (tid == ctx->spirv.tid[STI_VEC3]) ? 3 :
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   504
       (tid == ctx->spirv.tid[STI_VEC2]) ? 2 : 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   505
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   506
    uint32 id = cache[dim - 1];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   507
    if (id)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   508
        return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   509
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   510
    uint32 sid = spv_getscalarf(ctx, scalar);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   511
    if (dim == 1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   512
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   513
        cache[0] = sid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   514
        return sid;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   515
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   516
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   517
    id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   518
    push_output(ctx, &ctx->mainline_intro);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   519
    spv_emit_part(ctx, 3 + dim, 3, SpvOpConstantComposite, tid, id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   520
    for (i = 0; i < dim; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   521
        spv_emit_word(ctx, sid);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   522
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   523
    cache[dim - 1] = id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   524
    return id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   525
} // spv_get_constant_composite
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   526
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   527
static uint32 spv_get_zero(Context *ctx, uint32 tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   528
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   529
    return spv_get_constant_composite(ctx, tid, ctx->spirv.id_0_0, 0.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   530
} // spv_get_zero
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   531
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   532
static uint32 spv_get_one(Context *ctx, uint32 tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   533
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   534
    return spv_get_constant_composite(ctx, tid, ctx->spirv.id_1_0, 1.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   535
} // spv_get_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   536
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   537
static uint32 spv_get_flt_max(Context *ctx, uint32 tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   538
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   539
    return spv_get_constant_composite(ctx, tid, ctx->spirv.id_flt_max, FLT_MAX);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   540
} // spv_get_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   541
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   542
static uint32 spv_getvec4_zero(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   543
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   544
    return spv_get_constant_composite(ctx, spv_get_type(ctx, STI_VEC4), ctx->spirv.id_0_0, 0.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   545
} // spv_getvec4_zero
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   546
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   547
static uint32 spv_getvec4_one(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   548
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   549
    return spv_get_constant_composite(ctx, spv_get_type(ctx, STI_VEC4), ctx->spirv.id_1_0, 1.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   550
} // spv_getvec4_one
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   551
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   552
// Make a 4-channel vector with a value broadcast across all channels. Roughly equivalent to `vec4(value)` in GLSL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   553
static uint32 spv_vectorbroadcast(Context *ctx, uint32 tid, uint32 value)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   554
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   555
    uint32 result = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   556
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   557
    spv_emit(ctx, 3 + 4, SpvOpCompositeConstruct, tid, result, value, value, value, value);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   558
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   559
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   560
} // spv_vectorbroadcast
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   561
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   562
static void spv_branch_push(Context *ctx, uint32 id_merge, uint32 patch_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   563
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   564
    assert(((size_t)ctx->branch_labels_stack_index) < STATICARRAYLEN(ctx->branch_labels_stack));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   565
    int pos = ctx->branch_labels_stack_index++;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   566
    ctx->branch_labels_stack[pos] = id_merge;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   567
    ctx->branch_labels_patch_stack[pos] = patch_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   568
} // spv_branch_push
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   569
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   570
static void spv_branch_get(Context *ctx, uint32* out_id_merge, uint32* out_patch_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   571
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   572
    assert(ctx->branch_labels_stack_index > 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   573
    int pos = ctx->branch_labels_stack_index - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   574
    *out_id_merge = ctx->branch_labels_stack[pos];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   575
    *out_patch_offset = ctx->branch_labels_patch_stack[pos];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   576
} // spv_branch_get
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   577
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   578
static void spv_branch_pop(Context *ctx, uint32* out_id_merge, uint32* out_patch_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   579
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   580
    spv_branch_get(ctx, out_id_merge, out_patch_offset);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   581
    ctx->branch_labels_stack_index--;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   582
} // spv_branch_pop
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   583
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   584
static void spv_loop_push(Context *ctx, const SpirvLoopInfo *loop)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   585
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   586
    assert(((size_t)ctx->spirv.loop_stack_idx) < STATICARRAYLEN(ctx->spirv.loop_stack));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   587
    int pos = ctx->spirv.loop_stack_idx++;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   588
    ctx->spirv.loop_stack[pos] = *loop;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   589
} // spv_loop_push
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   590
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   591
static void spv_loop_get(Context *ctx, SpirvLoopInfo *loop)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   592
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   593
    assert(ctx->spirv.loop_stack_idx > 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   594
    int pos = ctx->spirv.loop_stack_idx - 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   595
    *loop = ctx->spirv.loop_stack[pos];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   596
} // spv_loop_get
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   597
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   598
static void spv_loop_pop(Context *ctx, SpirvLoopInfo *loop)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   599
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   600
    spv_loop_get(ctx, loop);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   601
    ctx->spirv.loop_stack_idx--;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   602
} // spv_loop_pop
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   603
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   604
static uint32 spv_loop_get_aL(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   605
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   606
    int i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   607
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   608
    // Find the first enclosing loop..endloop. There may be rep..endrep nested inside, so it might
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   609
    // not be at the top of the stack.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   610
    for (i = ctx->spirv.loop_stack_idx - 1; i >= 0; i--)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   611
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   612
        uint32 id_aL = ctx->spirv.loop_stack[i].id_aL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   613
        if (id_aL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   614
            return id_aL;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   615
    } // for
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   616
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   617
    assert(!"Referencing loop counter register aL in code not part of loop..endloop region.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   618
    return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   619
} // spv_loop_get_aL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   620
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   621
static SpvOp spv_get_comparison(Context *ctx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   622
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   623
    static const SpvOp spv_cmp_ops[] = {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   624
        SpvOpUndef,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   625
        SpvOpFOrdGreaterThan,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   626
        SpvOpFOrdEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   627
        SpvOpFOrdGreaterThanEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   628
        SpvOpFOrdLessThan,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   629
        SpvOpFOrdNotEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   630
        SpvOpFOrdLessThanEqual,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   631
    };
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   632
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   633
    if (ctx->instruction_controls >= STATICARRAYLEN(spv_cmp_ops))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   634
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   635
        fail(ctx, "unknown comparison control");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   636
        return SpvOpUndef;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   637
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   638
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   639
    return spv_cmp_ops[ctx->instruction_controls];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   640
} // spv_get_comparison
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   641
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   642
static void spv_check_read_reg_id(Context *ctx, RegisterList *r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   643
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   644
    if (r->spirv.iddecl == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   645
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   646
        assert(r->regtype != REG_TYPE_SAMPLER || (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 1, 4)));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   647
        assert(r->regtype != REG_TYPE_TEXTURE || (shader_is_pixel(ctx) && !shader_version_atleast(ctx, 1, 4)));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   648
        switch (r->regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   649
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   650
            case REG_TYPE_SAMPLER: // s# (only ps_1_1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   651
            case REG_TYPE_TEXTURE: // t# (only ps_1_1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   652
            case REG_TYPE_INPUT: // v#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   653
            case REG_TYPE_TEMP: // r#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   654
            case REG_TYPE_CONST: // c#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   655
            case REG_TYPE_CONSTINT: // i#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   656
            case REG_TYPE_CONSTBOOL: // b#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   657
            case REG_TYPE_LABEL: // l#
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   658
            case REG_TYPE_PREDICATE: // p0
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   659
                r->spirv.iddecl = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   660
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   661
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   662
            case REG_TYPE_LOOP: // aL
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   663
                r->spirv.iddecl = spv_loop_get_aL(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   664
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   665
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   666
            default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   667
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   668
                char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   669
                get_SPIRV_varname_in_buf(ctx, r->regtype, r->regnum, varname, sizeof(varname));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   670
                failf(ctx, "register type %s is unimplemented\n", varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   671
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   672
            } // default
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   673
        } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   674
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   675
} // spv_check_read_reg_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   676
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   677
static void spv_check_write_reg_id(Context *ctx, RegisterList *r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   678
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   679
    if (r->spirv.iddecl == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   680
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   681
        switch (r->regtype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   682
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   683
            // These registers require no declarations, so we can just create them as we see them
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   684
            case REG_TYPE_ADDRESS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   685
            case REG_TYPE_TEMP:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   686
            case REG_TYPE_RASTOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   687
            case REG_TYPE_COLOROUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   688
            case REG_TYPE_TEXCRDOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   689
            case REG_TYPE_DEPTHOUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   690
            case REG_TYPE_ATTROUT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   691
            case REG_TYPE_PREDICATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   692
                r->spirv.iddecl = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   693
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   694
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   695
            // Other register types should be explicitly declared, so it is an error for them to have iddecl == 0 by now
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   696
            default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   697
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   698
                char varname[64];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   699
                get_SPIRV_varname_in_buf(ctx, r->regtype, r->regnum, varname, sizeof(varname));
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   700
                failf(ctx, "tried to write to undeclared register %s\n", varname);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   701
                break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   702
            } // default
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   703
        } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   704
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   705
} // spv_check_write_reg_id
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   706
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   707
static uint32 spv_ptrimage_from_texturetype(Context *ctx, TextureType ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   708
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   709
    switch (ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   710
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   711
        case TEXTURE_TYPE_2D:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   712
            return spv_get_type(ctx, STI_PTR_IMAGE2D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   713
        case TEXTURE_TYPE_CUBE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   714
            return spv_get_type(ctx, STI_PTR_IMAGECUBE);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   715
        case TEXTURE_TYPE_VOLUME:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   716
            return spv_get_type(ctx, STI_PTR_IMAGE3D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   717
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   718
            fail(ctx, "BUG: used a sampler we don't know how to define.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   719
            return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   720
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   721
} // spv_ptrimage_from_texturetype
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   722
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   723
static uint32 spv_image_from_texturetype(Context *ctx, TextureType ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   724
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   725
    switch (ttype)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   726
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   727
        case TEXTURE_TYPE_2D:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   728
            return spv_get_type(ctx, STI_IMAGE2D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   729
        case TEXTURE_TYPE_CUBE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   730
            return spv_get_type(ctx, STI_IMAGECUBE);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   731
        case TEXTURE_TYPE_VOLUME:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   732
            return spv_get_type(ctx, STI_IMAGE3D);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   733
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   734
            fail(ctx, "BUG: used a sampler we don't know how to define.");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   735
            return 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   736
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   737
} // spv_ptrimage_from_texturetype
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   738
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   739
static uint32 spv_access_uniform(Context *ctx, SpirvTypeIdx sti_ptr, RegisterType regtype, uint32 id_offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   740
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   741
    uint32 tid_ptr = spv_get_type(ctx, sti_ptr);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   742
    uint32 id_arr = spv_get_uniform_array_id(ctx, regtype);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   743
    uint32 id_access = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   744
    push_output(ctx, &ctx->mainline);
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   745
    if (ctx->spirv.mode == SPIRV_MODE_VK)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   746
    {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   747
        uint32 id_uniform_block = ctx->spirv.id_uniform_block;
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   748
        if (id_uniform_block == 0)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   749
        {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   750
            id_uniform_block = spv_bumpid(ctx);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   751
            ctx->spirv.id_uniform_block = id_uniform_block;
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   752
        } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   753
        spv_emit(ctx, 4+2, SpvOpAccessChain, tid_ptr, id_access, id_uniform_block, id_arr, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   754
    } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   755
    else
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   756
    {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   757
        spv_emit(ctx, 4+1, SpvOpAccessChain, tid_ptr, id_access, id_arr, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
   758
    } // else
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   759
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   760
    return id_access;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   761
} // spv_access_uniform
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   762
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   763
static SpirvResult spv_loadreg(Context *ctx, RegisterList *r)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   764
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   765
    const RegisterType regtype = r->regtype;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   766
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   767
    spv_check_read_reg_id(ctx, r);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   768
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   769
    uint32 id_src = r->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   770
    SpirvResult result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   771
    if (regtype == REG_TYPE_SAMPLER)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   772
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   773
        RegisterList *sreg = reglist_find(&ctx->samplers, REG_TYPE_SAMPLER, r->regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   774
        result.tid = spv_image_from_texturetype(ctx, (TextureType)sreg->index);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   775
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   776
    else if (regtype == REG_TYPE_CONSTBOOL)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   777
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   778
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   779
            id_src = spv_access_uniform(ctx, STI_PTR_INT_U, regtype, r->spirv.iddecl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   780
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   781
        result.tid = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   782
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   783
    else if (regtype == REG_TYPE_CONSTINT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   784
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   785
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   786
            id_src = spv_access_uniform(ctx, STI_PTR_IVEC4_U, regtype, r->spirv.iddecl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   787
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   788
        result.tid = spv_get_type(ctx, STI_IVEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   789
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   790
    else if (regtype == REG_TYPE_CONST)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   791
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   792
        if (!r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   793
            id_src = spv_access_uniform(ctx, STI_PTR_VEC4_U, regtype, r->spirv.iddecl);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   794
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   795
        result.tid = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   796
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   797
    else if (regtype == REG_TYPE_LOOP)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   798
        result.tid = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   799
    else if (regtype == REG_TYPE_PREDICATE)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   800
        result.tid = spv_get_type(ctx, STI_BVEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   801
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   802
        result.tid = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   803
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   804
    // Constants can be used directly, no need to load them.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   805
    assert(r->spirv.is_ssa == 0 || r->spirv.is_ssa == 1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   806
    if (r->spirv.is_ssa)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   807
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   808
        result.id = r->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   809
        return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   810
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   811
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   812
    assert(id_src);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   813
    result.id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   814
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   815
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   816
    spv_emit(ctx, 4, SpvOpLoad, result.tid, result.id, id_src);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   817
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   818
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   819
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   820
} // spv_loadreg
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   821
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   822
static uint32 spv_emit_swizzle(Context *ctx, uint32 arg, uint32 rtid, const int swizzle, const int writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   823
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   824
    uint32 result = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   825
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   826
    const int writemask0 = (writemask >> 0) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   827
    const int writemask1 = (writemask >> 1) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   828
    const int writemask2 = (writemask >> 2) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   829
    const int writemask3 = (writemask >> 3) & 0x1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   830
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   831
    const uint32 swizzle_x = (swizzle >> 0) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   832
    const uint32 swizzle_y = (swizzle >> 2) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   833
    const uint32 swizzle_z = (swizzle >> 4) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   834
    const uint32 swizzle_w = (swizzle >> 6) & 0x3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   835
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   836
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   837
    // OpVectorShuffle takes two vectors to shuffle, but to do a swizzle
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   838
    // operation we can just ignore the second argument (meaning it can be
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   839
    // anything, and I am just making it `arg` for convenience)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   840
    uint32 word_count = 5 + writemask0 + writemask1 + writemask2 + writemask3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   841
    spv_emit_part(ctx, word_count, 5, SpvOpVectorShuffle, rtid, result, arg, arg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   842
    if (writemask0) spv_emit_word(ctx, swizzle_x);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   843
    if (writemask1) spv_emit_word(ctx, swizzle_y);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   844
    if (writemask2) spv_emit_word(ctx, swizzle_z);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   845
    if (writemask3) spv_emit_word(ctx, swizzle_w);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   846
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   847
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   848
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   849
} // spv_emit_swizzle
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   850
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   851
SpirvResult spv_swizzle(Context *ctx, SpirvResult arg, const int swizzle, const int writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   852
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   853
    int i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   854
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   855
    // Nothing to do, so return the same SSA value
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   856
    if (no_swizzle(swizzle) && writemask_xyzw(writemask))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   857
        return arg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   858
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   859
    assert(arg.tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   860
    assert(writemask == 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   861
        || writemask == 3
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   862
        || writemask == 7
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   863
        || writemask == 15
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   864
    );
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   865
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   866
    SpirvTypeIdx sti_arg = STI_VOID;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   867
    for (i = STI_CORE_START_; i < STI_CORE_END_; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   868
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   869
        if (ctx->spirv.tid[i] == arg.tid)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   870
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   871
            sti_arg = (SpirvTypeIdx)i;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   872
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   873
        } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   874
    } // for
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   875
    assert(sti_arg != STI_VOID);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   876
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   877
    // We should not leave any value undefined, as it may end up used (eg. dot
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   878
    // product), which will make everything relying on it's result undefined.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   879
    // Therefore, we specifically determine true dimensionality of the result.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   880
    int resdim = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   881
    switch (writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   882
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   883
        case 1:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   884
            resdim = 1;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   885
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   886
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   887
        case 3:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   888
            resdim = 2;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   889
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   890
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   891
        case 7:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   892
            resdim = 3;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   893
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   894
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   895
        case 15:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   896
            resdim = 4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   897
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   898
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   899
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   900
            failf(ctx, "Unexpected write mask in swizzle: 0x%X");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   901
            assert(0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   902
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   903
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   904
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   905
    SpirvTypeIdx sti_result = spv_change_base_type_vec_dim(sti_arg, resdim);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   906
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   907
    SpirvResult result = {0};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   908
    result.id = (resdim != 1 || sti_arg != sti_result) ? spv_bumpid(ctx) : arg.id;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   909
    result.tid = spv_get_type(ctx, sti_result);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   910
    assert(result.tid != 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   911
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   912
    push_output(ctx, &ctx->mainline);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   913
    if (resdim != 1)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   914
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   915
        // OpVectorShuffle takes two vectors to shuffle, but to do a swizzle
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   916
        // operation we can just ignore the second argument (meaning it can be
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   917
        // anything, and I am just making it `arg` for convenience)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   918
        spv_emit_part(ctx, 5 + resdim, 5, SpvOpVectorShuffle, result.tid, result.id, arg.id, arg.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   919
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   920
        for (i = 0; i < resdim; i++)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   921
            spv_emit_word(ctx, (swizzle >> (2*i)) & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   922
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   923
    else if (sti_arg != sti_result)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   924
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   925
        // OpVectorShuffle may not produce a scalar. Instead we use OpCompositeExtract.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   926
        spv_emit(ctx, 5, SpvOpCompositeExtract, result.tid, result.id, arg.id, swizzle & 0x3);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   927
    } // else if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   928
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   929
    pop_output(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   930
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   931
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   932
} // make_GLSL_swizzle_string
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   933
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   934
static SpirvResult spv_load_srcarg(Context *ctx, const size_t idx, const int writemask)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   935
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   936
    SpirvResult result = {0};
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   937
    if (idx >= STATICARRAYLEN(ctx->source_args))
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   938
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   939
        fail(ctx, "Too many source args");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   940
        return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   941
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   942
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   943
    const SourceArgInfo *arg = &ctx->source_args[idx];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   944
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   945
    RegisterList *reg = spv_getreg(ctx, arg->regtype, arg->regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   946
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   947
    if (arg->relative)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   948
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   949
        if (arg->regtype == REG_TYPE_INPUT)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   950
            fail(ctx, "relative input array access is unimplemented");
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   951
        else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   952
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   953
            assert(arg->regtype == REG_TYPE_CONST);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   954
            const int arrayidx = arg->relative_array->index;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   955
            const int offset = arg->regnum - arrayidx;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   956
            assert(offset >= 0);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   957
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   958
            int is_constant = (arg->relative_array->constant != NULL);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   959
            uint32 id_array = 0;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   960
            if (is_constant)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   961
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   962
                id_array = ctx->spirv.constant_arrays.idvec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   963
                if (id_array == 0)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   964
                {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   965
                    id_array = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   966
                    ctx->spirv.constant_arrays.idvec4 = id_array;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   967
                } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   968
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   969
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   970
            RegisterList *reg_rel = spv_getreg(ctx, arg->relative_regtype, arg->relative_regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   971
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   972
            spv_check_read_reg_id(ctx, reg_rel);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   973
            spv_check_read_reg_id(ctx, reg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   974
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   975
            uint32 id_int = spv_get_type(ctx, STI_INT);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   976
            uint32 id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   977
            if (reg_rel->regtype == REG_TYPE_LOOP)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   978
                id_offset = reg_rel->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   979
            else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   980
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   981
                uint32 id_pint = spv_get_type(ctx, STI_PTR_INT_P);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   982
                uint32 id_compidx = spv_getscalari(ctx, arg->relative_component);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   983
                uint32 id_pcomp = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   984
                spv_emit(ctx, 5, SpvOpAccessChain, id_pint, id_pcomp, reg_rel->spirv.iddecl, id_compidx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   985
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   986
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   987
                spv_emit(ctx, 4, SpvOpLoad, id_int, id_offset, id_pcomp);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   988
            } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   989
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   990
            if (!is_constant)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   991
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   992
                uint32 id_arraybase = reg->spirv.iddecl;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   993
                uint32 id_a = id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   994
                uint32 id_b = id_arraybase;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   995
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   996
                spv_emit(ctx, 5, SpvOpIAdd, id_int, id_offset, id_a, id_b);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   997
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   998
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
   999
            if (offset)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1000
            {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1001
                uint32 id_a = id_offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1002
                uint32 id_b = spv_getscalari(ctx, offset);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1003
                id_offset = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1004
                spv_emit(ctx, 5, SpvOpIAdd, id_int, id_offset, id_a, id_b);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1005
            } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1006
1248
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1007
            uint32 id_pvalue;
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1008
            if (is_constant)
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1009
            {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1010
                uint32 id_pvec4 = spv_get_type(ctx, STI_PTR_VEC4_P);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1011
                id_pvalue = spv_bumpid(ctx);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1012
                spv_emit(ctx, 4+1, SpvOpAccessChain, id_pvec4, id_pvalue, id_array, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1013
            } // if
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1014
            else
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1015
            {
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1016
                id_pvalue = spv_access_uniform(ctx, STI_PTR_VEC4_U, arg->regtype, id_offset);
2f03f0b5ded3 Add uniform block support for vulkan
Martin Krošlák <kroslakma@gmail.com>
parents: 1234
diff changeset
  1017
            } // else
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1018
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1019
            result.tid = spv_get_type(ctx, STI_VEC4);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1020
            result.id = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1021
            spv_emit(ctx, 4, SpvOpLoad, result.tid, result.id, id_pvalue);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1022
        } // else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1023
    } // if
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1024
    else
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1025
        result = spv_loadreg(ctx, reg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1026
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1027
    result = spv_swizzle(ctx, result, arg->swizzle, writemask);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1028
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1029
    switch (arg->src_mod)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1030
    {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1031
        case SRCMOD_NEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1032
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1033
            uint32 id_neg = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1034
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_neg, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1035
            result.id = id_neg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1036
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1037
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1038
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1039
        case SRCMOD_BIASNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1040
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1041
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1042
            uint32 id_tmp  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1043
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1044
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_tmp, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1045
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_new, id_tmp);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1046
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1047
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1048
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1049
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1050
        case SRCMOD_BIAS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1051
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1052
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1053
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1054
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_new, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1055
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1056
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1057
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1058
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1059
        case SRCMOD_SIGNNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1060
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1061
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1062
            uint32 id_two  = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1063
            uint32 id_tmp0 = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1064
            uint32 id_tmp1 = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1065
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1066
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_tmp0, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1067
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_tmp1, id_tmp0, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1068
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_new, id_tmp1);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1069
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1070
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1071
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1072
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1073
        case SRCMOD_SIGN:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1074
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1075
            uint32 id_half = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_0_5, 0.5f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1076
            uint32 id_two  = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1077
            uint32 id_tmp  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1078
            uint32 id_new  = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1079
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_tmp, result.id, id_half);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1080
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_new, id_tmp, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1081
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1082
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1083
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1084
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1085
        case SRCMOD_COMPLEMENT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1086
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1087
            uint32 id_one = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_1_0, 1.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1088
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1089
            spv_emit(ctx, 5, SpvOpFSub, result.tid, id_new, id_one, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1090
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1091
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1092
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1093
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1094
        case SRCMOD_X2NEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1095
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1096
            uint32 id_two = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1097
            uint32 id_tmp = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1098
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1099
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_tmp, result.id, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1100
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_new, id_tmp);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1101
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1102
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1103
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1104
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1105
        case SRCMOD_X2:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1106
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1107
            uint32 id_two = spv_get_constant_composite(ctx, result.tid, ctx->spirv.id_2_0, 2.0f);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1108
            uint32 id_new = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1109
            spv_emit(ctx, 5, SpvOpFMul, result.tid, id_new, result.id, id_two);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1110
            result.id = id_new;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1111
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1112
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1113
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1114
        // case SRCMOD_DZ:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1115
        //     fail(ctx, "SRCMOD_DZ unsupported"); return buf; // !!! FIXME
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1116
        //     postmod_str = "_dz";
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1117
        //     break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1118
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1119
        // case SRCMOD_DW:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1120
        //     fail(ctx, "SRCMOD_DW unsupported"); return buf; // !!! FIXME
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1121
        //     postmod_str = "_dw";
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1122
        //     break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1123
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1124
        case SRCMOD_ABSNEGATE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1125
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1126
            uint32 id_abs = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1127
            uint32 id_neg = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1128
            spv_emit(ctx, 5 + 1, SpvOpExtInst, result.tid, id_abs, spv_getext(ctx), GLSLstd450FAbs, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1129
            spv_emit(ctx, 4, SpvOpFNegate, result.tid, id_neg, id_abs);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1130
            result.id = id_neg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1131
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1132
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1133
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1134
        case SRCMOD_ABS:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1135
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1136
            uint32 id_abs = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1137
            spv_emit(ctx, 5 + 1, SpvOpExtInst, result.tid, id_abs, spv_getext(ctx), GLSLstd450FAbs, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1138
            result.id = id_abs;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1139
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1140
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1141
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1142
        case SRCMOD_NOT:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1143
        {
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1144
            uint32 id_not = spv_bumpid(ctx);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1145
            spv_emit(ctx, 4, SpvOpLogicalNot, result.tid, id_not, result.id);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1146
            result.id = id_not;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1147
            break;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1148
        } // case
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1149
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1150
        case SRCMOD_NONE:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1151
        case SRCMOD_TOTAL:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1152
            break;  // stop compiler whining.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1153
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1154
        default:
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1155
            failf(ctx, "unsupported source modifier %d", arg->src_mod);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1156
            return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1157
    } // switch
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1158
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1159
    return result;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1160
} // spv_load_srcarg
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1161
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1162
static inline SpirvResult spv_load_srcarg_full(Context *ctx, const size_t idx)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1163
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1164
    return spv_load_srcarg(ctx, idx, 0xF);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1165
} // spv_load_srcarg_full
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1166
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1167
static void spv_assign_destarg(Context *ctx, SpirvResult value)
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1168
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1169
    const DestArgInfo *arg = &ctx->dest_arg;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1170
    RegisterList *reg = spv_getreg(ctx, arg->regtype, arg->regnum);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1171
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1172
    spv_check_write_reg_id(ctx, reg);
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents:
diff changeset
  1173
21cd84f1aa0a Add support for emitting SPIR-V shaders. </