mojoshader_internal.h
author Ethan Lee <flibitijibibo@flibitijibibo.com>
Sun, 30 Aug 2020 21:35:31 -0400
changeset 1303 7a43f238f28a
parent 1291 db27fb09421a
child 1318 ff4eb6d9c9c2
permissions -rw-r--r--
spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#ifndef _INCLUDE_MOJOSHADER_INTERNAL_H_
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
#define _INCLUDE_MOJOSHADER_INTERNAL_H_
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
#ifndef __MOJOSHADER_INTERNAL__
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
#error Do not include this header from your applications.
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
// Shader bytecode format is described at MSDN:
907
ce28b304dbd0 Corrected MSDN URL.
Ryan C. Gordon <icculus@icculus.org>
parents: 894
diff changeset
     9
//  http://msdn.microsoft.com/en-us/library/ff569705.aspx
589
1cf3fc2c5e37 Updated some URLs in the comments.
Ryan C. Gordon <icculus@icculus.org>
parents: 587
diff changeset
    10
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    11
#ifdef MOJOSHADER_USE_SDL_STDLIB
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    12
#include <SDL_assert.h>
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    13
#include <SDL_stdinc.h>
1242
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    14
#include <math.h> /* Needed for isinf/isnan :( */
1257
deb563aadfa0 Include stdlib.h in SDL path, needed by Emscripten
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1255
diff changeset
    15
deb563aadfa0 Include stdlib.h in SDL path, needed by Emscripten
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1255
diff changeset
    16
/* FIXME: These includes are needed for alloca :( */
deb563aadfa0 Include stdlib.h in SDL path, needed by Emscripten
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1255
diff changeset
    17
#include <stdlib.h>
1242
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    18
#ifndef __APPLE__
1257
deb563aadfa0 Include stdlib.h in SDL path, needed by Emscripten
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1255
diff changeset
    19
#include <malloc.h>
1239
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
    20
#endif
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    21
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    22
/* stdint.h */
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    23
typedef Uint8 uint8;
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    24
typedef Uint16 uint16;
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    25
typedef Uint32 uint32;
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    26
typedef Sint32 int32;
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    27
typedef Sint64 int64;
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    28
typedef Uint64 uint64;
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    29
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    30
/* assert.h */
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    31
#define assert SDL_assert
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    32
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    33
/* stdlib.h */
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    34
#define malloc SDL_malloc
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    35
#define free SDL_free
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    36
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    37
/* stdio.h */
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    38
#define sscanf SDL_sscanf
1238
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    39
#ifdef snprintf
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    40
#undef snprintf
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    41
#endif
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    42
#define snprintf SDL_snprintf
1238
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    43
#ifdef vsnprintf
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    44
#undef vsnprintf
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    45
#endif
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    46
#define vsnprintf SDL_vsnprintf
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    47
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    48
/* math.h */
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    49
#define acos SDL_acos
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    50
#define asin SDL_asin
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    51
#define atan SDL_atan
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    52
#define atan2 SDL_atan2
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    53
#define cos SDL_acos
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    54
#define exp SDL_exp
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    55
#define floor SDL_floor
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    56
#define log SDL_log
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    57
#define sin SDL_sin
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    58
#define sqrt SDL_sqrt
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    59
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    60
/* string.h */
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    61
#ifdef memcmp
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    62
#undef memcmp
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    63
#endif
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    64
#define memcmp SDL_memcmp
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    65
#ifdef memcpy
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    66
#undef memcpy
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    67
#endif
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    68
#define memcpy SDL_memcpy
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    69
#ifdef memset
1238
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    70
#undef memset
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    71
#endif
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
    72
#define memset SDL_memset
1242
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    73
#ifdef strchr
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    74
#undef strchr
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    75
#endif
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    76
#define strchr SDL_strchr
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    77
#ifdef strcmp
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    78
#undef strcmp
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    79
#endif
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    80
#define strcmp SDL_strcmp
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    81
#ifdef strlen
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    82
#undef strlen
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    83
#endif
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    84
#define strlen SDL_strlen
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    85
#ifdef strncmp
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    86
#undef strncmp
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    87
#endif
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    88
#define strncmp SDL_strncmp
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    89
#ifdef strstr
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    90
#undef strstr
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    91
#endif
4929f916a134 Buildfixes for CentOS, MinGW, osxcross
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1239
diff changeset
    92
#define strstr SDL_strstr
1239
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
    93
#ifdef strcat
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
    94
#undef strcat
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
    95
#endif
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
    96
/* TODO: Move MojoShader away from strcat! This len is awful! */
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
    97
#define strcat(dst, src) SDL_strlcat(dst, src, SDL_strlen(src) + 1)
1238
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    98
#ifdef strcpy
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
    99
#undef strcpy
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
   100
#endif
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
   101
/* TODO: Move MojoShader away from strcpy! This len is awful! */
a6b5578b9851 A few more stdlib macros for Apple
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1237
diff changeset
   102
#define strcpy(dst, src) SDL_strlcpy(dst, src, SDL_strlen(src) + 1)
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
   103
#else /* MOJOSHADER_USE_SDL_STDLIB */
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
#include <stdio.h>
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
#include <string.h>
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
#include <stdlib.h>
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
#include <stdarg.h>
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
#include <assert.h>
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
   109
#endif /* MOJOSHADER_USE_SDL_STDLIB */
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
#include "mojoshader.h"
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
630
e6bd53dd1f91 Allow debug output directly from the lexer, before preprocessor eats.
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
   113
#define DEBUG_LEXER 0
587
202354e004fc Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents: 584
diff changeset
   114
#define DEBUG_PREPROCESSOR 0
716
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 703
diff changeset
   115
#define DEBUG_ASSEMBLER_PARSER 0
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 703
diff changeset
   116
#define DEBUG_COMPILER_PARSER 0
630
e6bd53dd1f91 Allow debug output directly from the lexer, before preprocessor eats.
Ryan C. Gordon <icculus@icculus.org>
parents: 625
diff changeset
   117
#define DEBUG_TOKENIZER \
716
94a804b54078 Cleaned up HLSL parser tracing.
Ryan C. Gordon <icculus@icculus.org>
parents: 703
diff changeset
   118
    (DEBUG_PREPROCESSOR || DEBUG_ASSEMBLER_PARSER || DEBUG_LEXER)
587
202354e004fc Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents: 584
diff changeset
   119
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
// This is the highest shader version we currently support.
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
#define MAX_SHADER_MAJOR 3
493
e2c930ab84b5 Allow SM3 shaders that are vs_3_x or vs_3_sw.
Ryan C. Gordon <icculus@icculus.org>
parents: 491
diff changeset
   123
#define MAX_SHADER_MINOR 255  // vs_3_sw
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
// If SUPPORT_PROFILE_* isn't defined, we assume an implicit desire to support.
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
//  You get all the profiles unless you go out of your way to disable them.
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
#ifndef SUPPORT_PROFILE_D3D
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
#define SUPPORT_PROFILE_D3D 1
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
800
cbd232606562 fix passthrough/bytecode define
Aras Pranckevicius <aras@unity3d.com>
parents: 756
diff changeset
   133
#ifndef SUPPORT_PROFILE_BYTECODE
484
dfce8e965115 s/PASSTHROUGH/BYTECODE that I missed.
Ryan C. Gordon <icculus@icculus.org>
parents: 470
diff changeset
   134
#define SUPPORT_PROFILE_BYTECODE 1
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
1255
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1242
diff changeset
   137
#ifndef SUPPORT_PROFILE_HLSL
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1242
diff changeset
   138
#define SUPPORT_PROFILE_HLSL 1
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1242
diff changeset
   139
#endif
0135d797e287 Implement HLSL emitter, MOJOSHADER_d3d11 API
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1242
diff changeset
   140
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
#ifndef SUPPORT_PROFILE_GLSL
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
#define SUPPORT_PROFILE_GLSL 1
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   145
#ifndef SUPPORT_PROFILE_GLSL120
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   146
#define SUPPORT_PROFILE_GLSL120 1
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   147
#endif
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   148
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   149
#ifndef SUPPORT_PROFILE_GLSLES
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   150
#define SUPPORT_PROFILE_GLSLES 1
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   151
#endif
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   152
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
#ifndef SUPPORT_PROFILE_ARB1
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
#define SUPPORT_PROFILE_ARB1 1
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   157
#ifndef SUPPORT_PROFILE_ARB1_NV
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   158
#define SUPPORT_PROFILE_ARB1_NV 1
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   159
#endif
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   160
1156
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   161
#ifndef SUPPORT_PROFILE_METAL
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   162
#define SUPPORT_PROFILE_METAL 1
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   163
#endif
6e760a19f456 Added support for producing shader language source code for Apple's Metal API.
Ryan C. Gordon <icculus@icculus.org>
parents: 1150
diff changeset
   164
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   165
#ifndef SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   166
#define SUPPORT_PROFILE_SPIRV 1
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   167
#endif
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   168
1225
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   169
#ifndef SUPPORT_PROFILE_GLSPIRV
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   170
#define SUPPORT_PROFILE_GLSPIRV 1
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   171
#endif
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   172
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   173
#if SUPPORT_PROFILE_ARB1_NV && !SUPPORT_PROFILE_ARB1
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   174
#error nv profiles require arb1 profile. Fix your build.
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   175
#endif
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   176
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   177
#if SUPPORT_PROFILE_GLSL120 && !SUPPORT_PROFILE_GLSL
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   178
#error glsl120 profile requires glsl profile. Fix your build.
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   179
#endif
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   180
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   181
#if SUPPORT_PROFILE_GLSLES && !SUPPORT_PROFILE_GLSL
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   182
#error glsles profile requires glsl profile. Fix your build.
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   183
#endif
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   184
1225
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   185
#if SUPPORT_PROFILE_GLSPIRV && !SUPPORT_PROFILE_SPIRV
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   186
#error glspirv profile requires spirv profile. Fix your build.
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   187
#endif
50b8dd7e0b1a Add GLSPIRV profile, to allow for both GL- and VK-friendly SPIR-V output
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1224
diff changeset
   188
1142
7b554e065321 Allow multiline comments before preprocessor directives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1121
diff changeset
   189
// Microsoft's preprocessor has some quirks. In some ways, it doesn't work
7b554e065321 Allow multiline comments before preprocessor directives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1121
diff changeset
   190
//  like you'd expect a C preprocessor to function.
7b554e065321 Allow multiline comments before preprocessor directives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1121
diff changeset
   191
#ifndef MATCH_MICROSOFT_PREPROCESSOR
7b554e065321 Allow multiline comments before preprocessor directives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1121
diff changeset
   192
#define MATCH_MICROSOFT_PREPROCESSOR 1
7b554e065321 Allow multiline comments before preprocessor directives.
Ryan C. Gordon <icculus@icculus.org>
parents: 1121
diff changeset
   193
#endif
808
b7196cc07283 Allow compiler to strip disabled glsl120 and nvX profiles as dead code.
Ryan C. Gordon <icculus@icculus.org>
parents: 800
diff changeset
   194
1038
9b23f9a8aa31 Allow preshader support to be #ifdef'd out, to reduce binary size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   195
// Other stuff you can disable...
9b23f9a8aa31 Allow preshader support to be #ifdef'd out, to reduce binary size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   196
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   197
#ifdef MOJOSHADER_EFFECT_SUPPORT
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   198
void MOJOSHADER_runPreshader(const MOJOSHADER_preshader*, float*);
1038
9b23f9a8aa31 Allow preshader support to be #ifdef'd out, to reduce binary size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   199
#endif
9b23f9a8aa31 Allow preshader support to be #ifdef'd out, to reduce binary size.
Ryan C. Gordon <icculus@icculus.org>
parents: 1030
diff changeset
   200
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
// Get basic wankery out of the way here...
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
#ifdef _WINDOWS
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
#define ENDLINE_STR "\r\n"
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
#else
700
2213a232d2fb Removed a semicolon from a #define
Ryan C. Gordon <icculus@icculus.org>
parents: 690
diff changeset
   207
#define ENDLINE_STR "\n"
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
typedef unsigned int uint;  // this is a printf() helper. don't use for code.
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   212
// Locale-independent float printing replacement for snprintf
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   213
size_t MOJOSHADER_printFloat(char *text, size_t maxlen, float arg);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   214
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
#ifdef _MSC_VER
1198
84ae1b18fdfe VS2010 buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1192
diff changeset
   216
#include <float.h>
84ae1b18fdfe VS2010 buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1192
diff changeset
   217
#define isnan _isnan // !!! FIXME: not a safe replacement!
1201
2ca303e50e27 Fixed macro clashing with crt function name in MSVC 2015 and newer.
Martin Krošlák <kroslakma@gmail.com>
parents: 1198
diff changeset
   218
#if _MSC_VER < 1900 // pre MSVC 2015
1234
608cef8fa24d VS2010 buildfixes
Caleb Cornett <caleb.cornett@outlook.com>
parents: 1225
diff changeset
   219
#define isinf(x) (!_finite(x)) // FIXME: not a safe replacement!
1201
2ca303e50e27 Fixed macro clashing with crt function name in MSVC 2015 and newer.
Martin Krošlák <kroslakma@gmail.com>
parents: 1198
diff changeset
   220
#endif
1239
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   221
#define va_copy(a, b) a = b
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   222
#endif
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   223
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   224
#ifndef MOJOSHADER_USE_SDL_STDLIB
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   225
#ifdef _MSC_VER
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   226
#include <malloc.h>
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   227
#define snprintf _snprintf  // !!! FIXME: not a safe replacement!
98ccda2125b1 VS2010 SDL_stdlib buildfixes
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1238
diff changeset
   228
#define vsnprintf _vsnprintf  // !!! FIXME: not a safe replacement!
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   229
#define strcasecmp stricmp
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   230
#define strncasecmp strnicmp
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
typedef unsigned __int8 uint8;
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
typedef unsigned __int16 uint16;
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
typedef unsigned __int32 uint32;
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   234
typedef unsigned __int64 uint64;
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
typedef __int32 int32;
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   236
typedef __int64 int64;
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   237
#ifdef _WIN64
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   238
typedef __int64 ssize_t;
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   239
#elif defined _WIN32
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   240
typedef __int32 ssize_t;
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   241
#else
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   242
#error Please define your platform.
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   243
#endif
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
// Warning Level 4 considered harmful.  :)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
#pragma warning(disable: 4100)  // "unreferenced formal parameter"
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
#pragma warning(disable: 4389)  // "signed/unsigned mismatch"
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
#else
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
#include <stdint.h>
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
typedef uint8_t uint8;
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
typedef uint16_t uint16;
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
typedef uint32_t uint32;
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
typedef int32_t int32;
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   253
typedef int64_t int64;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents: 808
diff changeset
   254
typedef uint64_t uint64;
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
756
9e06e970a730 Need alloca.h on Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 755
diff changeset
   257
#ifdef sun
9e06e970a730 Need alloca.h on Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 755
diff changeset
   258
#include <alloca.h>
9e06e970a730 Need alloca.h on Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 755
diff changeset
   259
#endif
1237
da180fe5b4b7 Add MOJOSHADER_USE_SDL_STDLIB, to avoid C runtime dependencies
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1236
diff changeset
   260
#endif /* MOJOSHADER_USE_SDL_STDLIB */
756
9e06e970a730 Need alloca.h on Solaris.
Ryan C. Gordon <icculus@icculus.org>
parents: 755
diff changeset
   261
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
#ifdef __GNUC__
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
#define ISPRINTF(x,y) __attribute__((format (printf, x, y)))
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
#else
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
#define ISPRINTF(x,y)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
#define STATICARRAYLEN(x) ( (sizeof ((x))) / (sizeof ((x)[0])) )
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
// Byteswap magic...
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
#if ((defined __GNUC__) && (defined __POWERPC__))
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
    static inline uint32 SWAP32(uint32 x)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
    {
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
        __asm__ __volatile__("lwbrx %0,0,%1" : "=r" (x) : "r" (&x));
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
        return x;
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
    } // SWAP32
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    static inline uint16 SWAP16(uint16 x)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    {
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
        __asm__ __volatile__("lhbrx %0,0,%1" : "=r" (x) : "r" (&x));
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
        return x;
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
    } // SWAP16
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
#elif defined(__POWERPC__)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
    static inline uint32 SWAP32(uint32 x)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    {
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
        return ( (((x) >> 24) & 0x000000FF) | (((x) >>  8) & 0x0000FF00) |
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
                 (((x) <<  8) & 0x00FF0000) | (((x) << 24) & 0xFF000000) );
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
    } // SWAP32
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
    static inline uint16 SWAP16(uint16 x)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
    {
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
        return ( (((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00) );
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
    } // SWAP16
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
#else
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
#   define SWAP16(x) (x)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
#   define SWAP32(x) (x)
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
#endif
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   299
#define SWAPDBL(x) (x)  // !!! FIXME
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   300
606
63e7a66ac320 Added support for #error directive to the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 603
diff changeset
   301
static inline int Min(const int a, const int b)
63e7a66ac320 Added support for #error directive to the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 603
diff changeset
   302
{
63e7a66ac320 Added support for #error directive to the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 603
diff changeset
   303
    return ((a < b) ? a : b);
63e7a66ac320 Added support for #error directive to the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 603
diff changeset
   304
} // Min
63e7a66ac320 Added support for #error directive to the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 603
diff changeset
   305
732
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   306
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   307
// Hashtables...
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   308
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   309
typedef struct HashTable HashTable;
859
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   310
typedef uint32 (*HashTable_HashFn)(const void *key, void *data);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   311
typedef int (*HashTable_KeyMatchFn)(const void *a, const void *b, void *data);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   312
typedef void (*HashTable_NukeFn)(const void *key, const void *value, void *data);
732
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   313
859
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   314
HashTable *hash_create(void *data, const HashTable_HashFn hashfn,
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   315
                       const HashTable_KeyMatchFn keymatchfn,
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   316
                       const HashTable_NukeFn nukefn,
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   317
                       const int stackable,
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   318
                       MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
733
1b6d68fabe46 Reworked hashtable create/destroy functions.
Ryan C. Gordon <icculus@icculus.org>
parents: 732
diff changeset
   319
void hash_destroy(HashTable *table);
732
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   320
int hash_insert(HashTable *table, const void *key, const void *value);
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   321
int hash_remove(HashTable *table, const void *key);
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   322
int hash_find(const HashTable *table, const void *key, const void **_value);
965
6284deccb61e Added hash_iter() function, for iterating all matching entries in a hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 956
diff changeset
   323
int hash_iter(const HashTable *table, const void *key, const void **_value, void **iter);
1065
bb021d539ec5 Implemented hash_iter_keys().
Ryan C. Gordon <icculus@icculus.org>
parents: 1054
diff changeset
   324
int hash_iter_keys(const HashTable *table, const void **_key, void **iter);
732
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   325
859
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   326
uint32 hash_hash_string(const void *sym, void *unused);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   327
int hash_keymatch_string(const void *a, const void *b, void *unused);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   328
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   329
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   330
// String -> String map ...
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   331
typedef HashTable StringMap;
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   332
StringMap *stringmap_create(const int copy, MOJOSHADER_malloc m,
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   333
                            MOJOSHADER_free f, void *d);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   334
void stringmap_destroy(StringMap *smap);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   335
int stringmap_insert(StringMap *smap, const char *key, const char *value);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   336
int stringmap_remove(StringMap *smap, const char *key);
824d67791db0 Implemented StringMap, for future use.
Ryan C. Gordon <icculus@icculus.org>
parents: 858
diff changeset
   337
int stringmap_find(const StringMap *smap, const char *key, const char **_val);
732
e070fea1f8c7 Added mojoshader_common.c with first shot at generic hashtable.
Ryan C. Gordon <icculus@icculus.org>
parents: 716
diff changeset
   338
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   339
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   340
// String caching...
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   341
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   342
typedef struct StringCache StringCache;
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   343
StringCache *stringcache_create(MOJOSHADER_malloc m,MOJOSHADER_free f,void *d);
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   344
const char *stringcache(StringCache *cache, const char *str);
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   345
const char *stringcache_len(StringCache *cache, const char *str,
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   346
                            const unsigned int len);
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   347
const char *stringcache_fmt(StringCache *cache, const char *fmt, ...);
1116
0ef3d106dab9 Added stringcache_iscached().
Ryan C. Gordon <icculus@icculus.org>
parents: 1099
diff changeset
   348
int stringcache_iscached(StringCache *cache, const char *str);
858
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   349
void stringcache_destroy(StringCache *cache);
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   350
d51537335896 Formalized the compiler's string cache into a real API.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   351
945
f00ea3986db8 Made ErrorList struct opaque to callers.
Ryan C. Gordon <icculus@icculus.org>
parents: 944
diff changeset
   352
// Error lists...
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   353
945
f00ea3986db8 Made ErrorList struct opaque to callers.
Ryan C. Gordon <icculus@icculus.org>
parents: 944
diff changeset
   354
typedef struct ErrorList ErrorList;
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   355
ErrorList *errorlist_create(MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   356
int errorlist_add(ErrorList *list, const char *fname,
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   357
                      const int errpos, const char *str);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   358
int errorlist_add_fmt(ErrorList *list, const char *fname,
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   359
                      const int errpos, const char *fmt, ...) ISPRINTF(4,5);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   360
int errorlist_add_va(ErrorList *list, const char *_fname,
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   361
                     const int errpos, const char *fmt, va_list va);
945
f00ea3986db8 Made ErrorList struct opaque to callers.
Ryan C. Gordon <icculus@icculus.org>
parents: 944
diff changeset
   362
int errorlist_count(ErrorList *list);
939
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   363
MOJOSHADER_error *errorlist_flatten(ErrorList *list); // resets the list!
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   364
void errorlist_destroy(ErrorList *list);
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   365
64cc93ee5a56 Cut-and-paste cleanup: unified the ErrorList functionality.
Ryan C. Gordon <icculus@icculus.org>
parents: 910
diff changeset
   366
944
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   367
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   368
// Dynamic buffers...
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   369
1236
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   370
typedef struct BufferBlock
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   371
{
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   372
    uint8 *data;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   373
    size_t bytes;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   374
    struct BufferBlock *next;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   375
} BufferBlock;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   376
typedef struct Buffer
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   377
{
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   378
    size_t total_bytes;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   379
    BufferBlock *head;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   380
    BufferBlock *tail;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   381
    size_t block_size;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   382
    MOJOSHADER_malloc m;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   383
    MOJOSHADER_free f;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   384
    void *d;
e2b62a9dde46 Move buffer_find to assembler.c, it isn't actually common
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1234
diff changeset
   385
} Buffer;
944
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   386
Buffer *buffer_create(size_t blksz,MOJOSHADER_malloc m,MOJOSHADER_free f,void *d);
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   387
char *buffer_reserve(Buffer *buffer, const size_t len);
946
16fec3a3f687 Technical debt: cleaned up things in the assembler that should've used Buffer.
Ryan C. Gordon <icculus@icculus.org>
parents: 945
diff changeset
   388
int buffer_append(Buffer *buffer, const void *_data, size_t len);
944
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   389
int buffer_append_fmt(Buffer *buffer, const char *fmt, ...) ISPRINTF(2,3);
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   390
int buffer_append_va(Buffer *buffer, const char *fmt, va_list va);
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   391
size_t buffer_size(Buffer *buffer);
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   392
void buffer_empty(Buffer *buffer);
956
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   393
char *buffer_flatten(Buffer *buffer);
7888858a6777 Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents: 947
diff changeset
   394
char *buffer_merge(Buffer **buffers, const size_t n, size_t *_len);
944
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   395
void buffer_destroy(Buffer *buffer);
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   396
void buffer_patch(Buffer *buffer, const size_t start,
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   397
                  const void *data, const size_t len);
944
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   398
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   399
9f9fa9650772 Paying off more technical debt: unified growable buffers into one place.
Ryan C. Gordon <icculus@icculus.org>
parents: 939
diff changeset
   400
524
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   401
// This is the ID for a D3DXSHADER_CONSTANTTABLE in the bytecode comments.
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   402
#define CTAB_ID 0x42415443  // 0x42415443 == 'CTAB'
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   403
#define CTAB_SIZE 28  // sizeof (D3DXSHADER_CONSTANTTABLE).
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   404
#define CINFO_SIZE 20  // sizeof (D3DXSHADER_CONSTANTINFO).
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   405
#define CTYPEINFO_SIZE 16  // sizeof (D3DXSHADER_TYPEINFO).
03eea2f0762c First (incomplete!) shot at more robust CTAB support.
Ryan C. Gordon <icculus@icculus.org>
parents: 523
diff changeset
   406
#define CMEMBERINFO_SIZE 8  // sizeof (D3DXSHADER_STRUCTMEMBERINFO)
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   407
1030
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   408
// Preshader magic values...
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   409
#define PRES_ID 0x53455250  // 0x53455250 == 'PRES'
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   410
#define PRSI_ID 0x49535250  // 0x49535250 == 'PRSI'
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   411
#define CLIT_ID 0x54494C43  // 0x54494C43 == 'CLIT'
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   412
#define FXLC_ID 0x434C5846  // 0x434C5846 == 'FXLC'
a407c516e325 Initial work on preshader support.
Ryan C. Gordon <icculus@icculus.org>
parents: 965
diff changeset
   413
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   414
// we need to reference these by explicit value occasionally...
1290
2febe5ae83ad The assembler needs to accept an implicit ".x" swizzle on RCP's source arg.
Ryan C. Gordon <icculus@icculus.org>
parents: 1287
diff changeset
   415
#define OPCODE_RCP 6
1291
db27fb09421a RSQ opcode requires replicate swizzle.
Ryan C. Gordon <icculus@icculus.org>
parents: 1290
diff changeset
   416
#define OPCODE_RSQ 7
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   417
#define OPCODE_RET 28
562
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 557
diff changeset
   418
#define OPCODE_IF 40
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   419
#define OPCODE_IFC 41
562
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 557
diff changeset
   420
#define OPCODE_BREAK 44
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   421
#define OPCODE_BREAKC 45
562
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 557
diff changeset
   422
#define OPCODE_TEXLD 66
c9a2bc5129c9 First shot at reworking assembly parser to use preprocessor/lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 557
diff changeset
   423
#define OPCODE_SETP 94
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   424
519
c9b27381c971 Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   425
// TEXLD becomes a different instruction with these instruction controls.
c9b27381c971 Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   426
#define CONTROL_TEXLD  0
c9b27381c971 Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   427
#define CONTROL_TEXLDP 1
c9b27381c971 Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   428
#define CONTROL_TEXLDB 2
c9b27381c971 Added TEXLDP/TEXLDP support to the assembler, cleaned up constants.
Ryan C. Gordon <icculus@icculus.org>
parents: 493
diff changeset
   429
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   430
// #define this to force app to supply an allocator, so there's no reference
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   431
//  to the C runtime's malloc() and free()...
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   432
#if MOJOSHADER_FORCE_ALLOCATOR
553
288ed486e5c3 Renamed internal_malloc() and internal_free().
Ryan C. Gordon <icculus@icculus.org>
parents: 551
diff changeset
   433
#define MOJOSHADER_internal_malloc NULL
288ed486e5c3 Renamed internal_malloc() and internal_free().
Ryan C. Gordon <icculus@icculus.org>
parents: 551
diff changeset
   434
#define MOJOSHADER_internal_free NULL
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   435
#else
1150
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   436
void * MOJOSHADERCALL MOJOSHADER_internal_malloc(int bytes, void *d);
02c0f0afb39a - Add ability to build MojoShader as a shared library
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1142
diff changeset
   437
void MOJOSHADERCALL MOJOSHADER_internal_free(void *ptr, void *d);
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   438
#endif
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   439
611
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   440
#if MOJOSHADER_FORCE_INCLUDE_CALLBACKS
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   441
#define MOJOSHADER_internal_include_open NULL
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   442
#define MOJOSHADER_internal_include_close NULL
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   443
#else
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   444
int MOJOSHADER_internal_include_open(MOJOSHADER_includeType inctype,
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   445
                                     const char *fname, const char *parent,
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   446
                                     const char **outdata,
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   447
                                     unsigned int *outbytes,
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   448
                                     MOJOSHADER_malloc m, MOJOSHADER_free f,
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   449
                                     void *d);
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   450
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   451
void MOJOSHADER_internal_include_close(const char *data, MOJOSHADER_malloc m,
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   452
                                       MOJOSHADER_free f, void *d);
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   453
#endif
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   454
8c2ee1a97ee1 Implemented #include in the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 606
diff changeset
   455
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   456
// result modifiers.
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   457
// !!! FIXME: why isn't this an enum?
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   458
#define MOD_SATURATE 0x01
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   459
#define MOD_PP 0x02
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   460
#define MOD_CENTROID 0x04
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   461
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   462
typedef enum
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   463
{
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   464
    REG_TYPE_TEMP = 0,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   465
    REG_TYPE_INPUT = 1,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   466
    REG_TYPE_CONST = 2,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   467
    REG_TYPE_ADDRESS = 3,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   468
    REG_TYPE_TEXTURE = 3,  // ALSO 3!
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   469
    REG_TYPE_RASTOUT = 4,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   470
    REG_TYPE_ATTROUT = 5,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   471
    REG_TYPE_TEXCRDOUT = 6,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   472
    REG_TYPE_OUTPUT = 6,  // ALSO 6!
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   473
    REG_TYPE_CONSTINT = 7,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   474
    REG_TYPE_COLOROUT = 8,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   475
    REG_TYPE_DEPTHOUT = 9,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   476
    REG_TYPE_SAMPLER = 10,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   477
    REG_TYPE_CONST2 = 11,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   478
    REG_TYPE_CONST3 = 12,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   479
    REG_TYPE_CONST4 = 13,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   480
    REG_TYPE_CONSTBOOL = 14,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   481
    REG_TYPE_LOOP = 15,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   482
    REG_TYPE_TEMPFLOAT16 = 16,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   483
    REG_TYPE_MISCTYPE = 17,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   484
    REG_TYPE_LABEL = 18,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   485
    REG_TYPE_PREDICATE = 19,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   486
    REG_TYPE_MAX = 19
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   487
} RegisterType;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   488
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   489
typedef enum
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   490
{
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   491
    TEXTURE_TYPE_2D = 2,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   492
    TEXTURE_TYPE_CUBE = 3,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   493
    TEXTURE_TYPE_VOLUME = 4,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   494
} TextureType;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   495
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   496
typedef enum
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   497
{
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   498
    RASTOUT_TYPE_POSITION = 0,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   499
    RASTOUT_TYPE_FOG = 1,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   500
    RASTOUT_TYPE_POINT_SIZE = 2,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   501
    RASTOUT_TYPE_MAX = 2
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   502
} RastOutType;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   503
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   504
typedef enum
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   505
{
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   506
    MISCTYPE_TYPE_POSITION = 0,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   507
    MISCTYPE_TYPE_FACE = 1,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   508
    MISCTYPE_TYPE_MAX = 1
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   509
} MiscTypeType;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   510
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   511
// source modifiers.
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   512
typedef enum
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   513
{
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   514
    SRCMOD_NONE,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   515
    SRCMOD_NEGATE,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   516
    SRCMOD_BIAS,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   517
    SRCMOD_BIASNEGATE,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   518
    SRCMOD_SIGN,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   519
    SRCMOD_SIGNNEGATE,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   520
    SRCMOD_COMPLEMENT,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   521
    SRCMOD_X2,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   522
    SRCMOD_X2NEGATE,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   523
    SRCMOD_DZ,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   524
    SRCMOD_DW,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   525
    SRCMOD_ABS,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   526
    SRCMOD_ABSNEGATE,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   527
    SRCMOD_NOT,
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   528
    SRCMOD_TOTAL
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   529
} SourceMod;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   530
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   531
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   532
typedef struct
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   533
{
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   534
    const uint32 *token;   // this is the unmolested token in the stream.
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   535
    int regnum;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   536
    int relative;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   537
    int writemask;   // xyzw or rgba (all four, not split out).
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   538
    int writemask0;  // x or red
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   539
    int writemask1;  // y or green
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   540
    int writemask2;  // z or blue
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   541
    int writemask3;  // w or alpha
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   542
    int orig_writemask;   // writemask before mojoshader tweaks it.
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   543
    int result_mod;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   544
    int result_shift;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   545
    RegisterType regtype;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   546
} DestArgInfo;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   547
1075
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   548
// NOTE: This will NOT know a dcl_psize or dcl_fog output register should be
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   549
//        scalar! This function doesn't have access to that information.
491
bcc3c215807a Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents: 484
diff changeset
   550
static inline int scalar_register(const MOJOSHADER_shaderType shader_type,
bcc3c215807a Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents: 484
diff changeset
   551
                                  const RegisterType regtype, const int regnum)
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   552
{
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   553
    switch (regtype)
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   554
    {
1075
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   555
        case REG_TYPE_RASTOUT:
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   556
            if (((const RastOutType) regnum) == RASTOUT_TYPE_FOG)
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   557
                return 1;
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   558
            else if (((const RastOutType) regnum) == RASTOUT_TYPE_POINT_SIZE)
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   559
                return 1;
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   560
            return 0;
61e5b2764ec8 Flag more registers as scalar. Fixes use of dcl_fog, oPts and oFog registers.
Ryan C. Gordon <icculus@icculus.org>
parents: 1065
diff changeset
   561
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   562
        case REG_TYPE_DEPTHOUT:
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   563
        case REG_TYPE_CONSTBOOL:
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   564
        case REG_TYPE_LOOP:
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   565
            return 1;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   566
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   567
        case REG_TYPE_MISCTYPE:
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   568
            if ( ((const MiscTypeType) regnum) == MISCTYPE_TYPE_FACE )
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   569
                return 1;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   570
            return 0;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   571
491
bcc3c215807a Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents: 484
diff changeset
   572
        case REG_TYPE_PREDICATE:
bcc3c215807a Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents: 484
diff changeset
   573
            return (shader_type == MOJOSHADER_TYPE_PIXEL) ? 1 : 0;
bcc3c215807a Fixed wrong data from scalar_register().
Ryan C. Gordon <icculus@icculus.org>
parents: 484
diff changeset
   574
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   575
        default: break;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   576
    } // switch
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   577
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   578
    return 0;
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   579
} // scalar_register
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   580
523
699696afd731 Allow errors to specify post-processing problems.
Ryan C. Gordon <icculus@icculus.org>
parents: 520
diff changeset
   581
551
217200672d64 Make sure internal symbols aren't polluting namespace.
Ryan C. Gordon <icculus@icculus.org>
parents: 542
diff changeset
   582
extern MOJOSHADER_error MOJOSHADER_out_of_mem_error;
217200672d64 Make sure internal symbols aren't polluting namespace.
Ryan C. Gordon <icculus@icculus.org>
parents: 542
diff changeset
   583
extern MOJOSHADER_parseData MOJOSHADER_out_of_mem_data;
542
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   584
a56d3bfd2e36 More work on multiple error messages.
Ryan C. Gordon <icculus@icculus.org>
parents: 524
diff changeset
   585
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   586
// preprocessor stuff.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   587
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   588
typedef enum
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   589
{
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   590
    TOKEN_UNKNOWN = 256,  // start past ASCII character values.
601
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   591
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   592
    // These are all C-like constructs. Tokens < 256 may be single
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   593
    //  chars (like '+' or whatever). These are just multi-char sequences
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   594
    //  (like "+=" or whatever).
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   595
    TOKEN_IDENTIFIER,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   596
    TOKEN_INT_LITERAL,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   597
    TOKEN_FLOAT_LITERAL,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   598
    TOKEN_STRING_LITERAL,
584
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   599
    TOKEN_RSHIFTASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   600
    TOKEN_LSHIFTASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   601
    TOKEN_ADDASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   602
    TOKEN_SUBASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   603
    TOKEN_MULTASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   604
    TOKEN_DIVASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   605
    TOKEN_MODASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   606
    TOKEN_XORASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   607
    TOKEN_ANDASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   608
    TOKEN_ORASSIGN,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   609
    TOKEN_INCREMENT,
9aea8877564d Updated lexer for HLSL.
Ryan C. Gordon <icculus@icculus.org>
parents: 564
diff changeset
   610
    TOKEN_DECREMENT,
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   611
    TOKEN_RSHIFT,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   612
    TOKEN_LSHIFT,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   613
    TOKEN_ANDAND,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   614
    TOKEN_OROR,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   615
    TOKEN_LEQ,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   616
    TOKEN_GEQ,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   617
    TOKEN_EQL,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   618
    TOKEN_NEQ,
865
4eb06464212d Added stringify operator ("#") to preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 862
diff changeset
   619
    TOKEN_HASH,
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   620
    TOKEN_HASHHASH,
601
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   621
1121
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   622
    // This is returned if the preprocessor isn't stripping comments. Note
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   623
    //  that in asm files, the ';' counts as a single-line comment, same as
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   624
    //  "//". Note that both eat newline tokens: all of the ones inside a
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   625
    //  multiline comment, and the ending newline on a single-line comment.
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   626
    TOKEN_MULTI_COMMENT,
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   627
    TOKEN_SINGLE_COMMENT,
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   628
601
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   629
    // This is returned at the end of input...no more to process.
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   630
    TOKEN_EOI,
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   631
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   632
    // This is returned for char sequences we think are bogus. You'll have
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   633
    //  to judge for yourself. In most cases, you'll probably just fail with
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   634
    //  bogus syntax without explicitly checking for this token.
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   635
    TOKEN_BAD_CHARS,
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   636
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   637
    // This is returned if there's an error condition (the error is returned
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   638
    //  as a NULL-terminated string from preprocessor_nexttoken(), instead
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   639
    //  of actual token data). You can continue getting tokens after this
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   640
    //  is reported. It happens for things like missing #includes, etc.
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   641
    TOKEN_PREPROCESSING_ERROR,
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   642
910
3ee487d85ecb Handle #pragma (or at least, don't fail on them).
Ryan C. Gordon <icculus@icculus.org>
parents: 907
diff changeset
   643
    // These are all caught by the preprocessor. Caller won't ever see them,
3ee487d85ecb Handle #pragma (or at least, don't fail on them).
Ryan C. Gordon <icculus@icculus.org>
parents: 907
diff changeset
   644
    //  except TOKEN_PP_PRAGMA.
603
c7a964b1b0eb More minor comment tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 601
diff changeset
   645
    //  They control the preprocessor (#includes new files, etc).
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   646
    TOKEN_PP_INCLUDE,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   647
    TOKEN_PP_LINE,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   648
    TOKEN_PP_DEFINE,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   649
    TOKEN_PP_UNDEF,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   650
    TOKEN_PP_IF,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   651
    TOKEN_PP_IFDEF,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   652
    TOKEN_PP_IFNDEF,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   653
    TOKEN_PP_ELSE,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   654
    TOKEN_PP_ELIF,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   655
    TOKEN_PP_ENDIF,
601
bb1484be4e1b Reworked and documented preprocessor tokens.
Ryan C. Gordon <icculus@icculus.org>
parents: 598
diff changeset
   656
    TOKEN_PP_ERROR,  // caught, becomes TOKEN_PREPROCESSING_ERROR
910
3ee487d85ecb Handle #pragma (or at least, don't fail on them).
Ryan C. Gordon <icculus@icculus.org>
parents: 907
diff changeset
   657
    TOKEN_PP_PRAGMA,
603
c7a964b1b0eb More minor comment tweaks.
Ryan C. Gordon <icculus@icculus.org>
parents: 601
diff changeset
   658
    TOKEN_INCOMPLETE_COMMENT,  // caught, becomes TOKEN_PREPROCESSING_ERROR
682
ad75eb06ddce First work on #if directive.
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   659
    TOKEN_PP_UNARY_MINUS,  // used internally, never returned.
ad75eb06ddce First work on #if directive.
Ryan C. Gordon <icculus@icculus.org>
parents: 678
diff changeset
   660
    TOKEN_PP_UNARY_PLUS,   // used internally, never returned.
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   661
} Token;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   662
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   663
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   664
// This is opaque.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   665
struct Preprocessor;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   666
typedef struct Preprocessor Preprocessor;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   667
620
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   668
typedef struct Conditional
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   669
{
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   670
    Token type;
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   671
    int linenum;
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   672
    int skipping;
625
bfb4016d9404 Fixed #else preprocessor directive so it'll work with #elif.
Ryan C. Gordon <icculus@icculus.org>
parents: 620
diff changeset
   673
    int chosen;
620
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   674
    struct Conditional *next;
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   675
} Conditional;
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   676
678
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   677
typedef struct Define
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   678
{
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   679
    const char *identifier;
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   680
    const char *definition;
894
1847405a16c6 Serious reworking of preprocessor macro replacement code.
Ryan C. Gordon <icculus@icculus.org>
parents: 865
diff changeset
   681
    const char *original;
678
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   682
    const char **parameters;
755
6a7aa96c51c7 Reworked preprocessor macro argument parsing.
Ryan C. Gordon <icculus@icculus.org>
parents: 734
diff changeset
   683
    int paramcount;
678
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   684
    struct Define *next;
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   685
} Define;
9fa2eb7d7871 Preprocessor now supports macros with parameters.
Ryan C. Gordon <icculus@icculus.org>
parents: 658
diff changeset
   686
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   687
typedef struct IncludeState
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   688
{
612
72ccfe69eaf1 Moved filename caching into the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 611
diff changeset
   689
    const char *filename;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   690
    const char *source_base;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   691
    const char *source;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   692
    const char *token;
648
243e35876142 Have lexer calculate token size now.
Ryan C. Gordon <icculus@icculus.org>
parents: 647
diff changeset
   693
    unsigned int tokenlen;
651
05ad72d120a5 Lexer now stores token value to IncludeState.
Ryan C. Gordon <icculus@icculus.org>
parents: 649
diff changeset
   694
    Token tokenval;
652
3333a0774ccc Added basic pushback facility to the preprocessor.
Ryan C. Gordon <icculus@icculus.org>
parents: 651
diff changeset
   695
    int pushedback;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   696
    const unsigned char *lexer_marker;
635
be3b428802a1 Try to make #error lexing match gcc's.
Ryan C. Gordon <icculus@icculus.org>
parents: 630
diff changeset
   697
    int report_whitespace;
1121
4142681f9fda Allow preprocessor to pass through comments, like GNU cpp does.
Ryan C. Gordon <icculus@icculus.org>
parents: 1116
diff changeset
   698
    int report_comments;
690
4710df464f13 Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 682
diff changeset
   699
    int asm_comments;
642
624ab8696f9b Enormous amount of tapdancing to handle EOI better in the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 635
diff changeset
   700
    unsigned int orig_length;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   701
    unsigned int bytes_left;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   702
    unsigned int line;
620
1c4cf996004e Initial work on preprocessor conditionals.
Ryan C. Gordon <icculus@icculus.org>
parents: 612
diff changeset
   703
    Conditional *conditional_stack;
656
ddb1a0b4c443 Let there be different close callbacks per IncludeState.
Ryan C. Gordon <icculus@icculus.org>
parents: 652
diff changeset
   704
    MOJOSHADER_includeClose close_callback;
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   705
    struct IncludeState *next;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   706
} IncludeState;
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   707
649
527cfe6f2d45 Renamed preprocessor_internal_lexer to preprocessor_lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 648
diff changeset
   708
Token preprocessor_lexer(IncludeState *s);
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   709
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   710
// This will only fail if the allocator fails, so it doesn't return any
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   711
//  error code...NULL on failure.
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   712
Preprocessor *preprocessor_start(const char *fname, const char *source,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   713
                            unsigned int sourcelen,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   714
                            MOJOSHADER_includeOpen open_callback,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   715
                            MOJOSHADER_includeClose close_callback,
658
22695d3d6b98 Should be an array of structs, not an array of pointers to structs.
Ryan C. Gordon <icculus@icculus.org>
parents: 656
diff changeset
   716
                            const MOJOSHADER_preprocessorDefine *defines,
690
4710df464f13 Moved asm comment processing into the lexer.
Ryan C. Gordon <icculus@icculus.org>
parents: 682
diff changeset
   717
                            unsigned int define_count, int asm_comments,
555
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   718
                            MOJOSHADER_malloc m, MOJOSHADER_free f, void *d);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   719
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   720
void preprocessor_end(Preprocessor *pp);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   721
int preprocessor_outofmemory(Preprocessor *pp);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   722
const char *preprocessor_nexttoken(Preprocessor *_ctx,
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   723
                                   unsigned int *_len, Token *_token);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   724
const char *preprocessor_sourcepos(Preprocessor *pp, unsigned int *pos);
940821555fda Initial work on preprocessor. Not yet complete!
Ryan C. Gordon <icculus@icculus.org>
parents: 553
diff changeset
   725
470
7d84d3452125 Bunch More Work on the assembler.
Ryan C. Gordon <icculus@icculus.org>
parents: 468
diff changeset
   726
587
202354e004fc Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents: 584
diff changeset
   727
void MOJOSHADER_print_debug_token(const char *subsystem, const char *token,
202354e004fc Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents: 584
diff changeset
   728
                                  const unsigned int tokenlen,
202354e004fc Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents: 584
diff changeset
   729
                                  const Token tokenval);
202354e004fc Unified some cut-and-paste code.
Ryan C. Gordon <icculus@icculus.org>
parents: 584
diff changeset
   730
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   731
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   732
#if SUPPORT_PROFILE_SPIRV
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   733
// Patching SPIR-V binaries before linking is needed to ensure locations do not
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   734
// overlap between shader stages. Unfortunately, OpDecorate takes Literal, so we
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   735
// can't use Result <id> from OpSpecConstant and leave this up to specialization
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   736
// mechanism.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   737
// Patch table must be propagated from parsing to program linking, but since
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   738
// MOJOSHADER_parseData is public and I'd like to avoid changing ABI and exposing
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   739
// this, it is appended to MOJOSHADER_parseData::output using postflight buffer.
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   740
typedef struct SpirvPatchEntry
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   741
{
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   742
    uint32 offset;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   743
    int32 location;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   744
} SpirvPatchEntry;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   745
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   746
typedef struct SpirvPatchTable
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   747
{
1277
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1257
diff changeset
   748
    // Patches for uniforms
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   749
    SpirvPatchEntry vpflip;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   750
    SpirvPatchEntry array_vec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   751
    SpirvPatchEntry array_ivec4;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   752
    SpirvPatchEntry array_bool;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   753
    SpirvPatchEntry samplers[16];
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   754
    int32 location_count;
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   755
1277
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1257
diff changeset
   756
    // Patches for linking vertex output/pixel input
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1257
diff changeset
   757
    uint32 attrib_offsets[MOJOSHADER_USAGE_TOTAL][16];
1303
7a43f238f28a spirv: Separate pixel shader outputs from inputs, fix linker accordingly
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1291
diff changeset
   758
    uint32 output_offsets[16];
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   759
} SpirvPatchTable;
1277
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1257
diff changeset
   760
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1257
diff changeset
   761
void MOJOSHADER_spirv_link_attributes(const MOJOSHADER_parseData *vertex,
da61410edbc9 Add dynamic linking support for SPIR-V modules
Ethan Lee <flibitijibibo@flibitijibibo.com>
parents: 1257
diff changeset
   762
                                      const MOJOSHADER_parseData *pixel);
1224
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   763
#endif
21cd84f1aa0a Add support for emitting SPIR-V shaders.
Martin Krošlák <kroslakma@gmail.com>
parents: 1201
diff changeset
   764
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   765
#endif  // _INCLUDE_MOJOSHADER_INTERNAL_H_
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   766
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   767
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   768
#if MOJOSHADER_DO_INSTRUCTION_TABLE
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   769
// These have to be in the right order! Arrays are indexed by the value
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   770
//  of the instruction token.
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   771
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   772
// INSTRUCTION_STATE means this opcode has to update the state machine
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   773
//  (we're entering an ELSE block, etc). INSTRUCTION means there's no
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   774
//  state, just go straight to the emitters.
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   775
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   776
// !!! FIXME: Some of these MOJOSHADER_TYPE_ANYs need to have their scope
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   777
// !!! FIXME:  reduced to just PIXEL or VERTEX.
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   778
1287
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   779
INSTRUCTION(NOP, "NOP", 1, NULL, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   780
INSTRUCTION(MOV, "MOV", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   781
INSTRUCTION(ADD, "ADD", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   782
INSTRUCTION(SUB, "SUB", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   783
INSTRUCTION(MAD, "MAD", 1, DSSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   784
INSTRUCTION(MUL, "MUL", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   785
INSTRUCTION_STATE(RCP, "RCP", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
1291
db27fb09421a RSQ opcode requires replicate swizzle.
Ryan C. Gordon <icculus@icculus.org>
parents: 1290
diff changeset
   786
INSTRUCTION_STATE(RSQ, "RSQ", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
1287
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   787
INSTRUCTION(DP3, "DP3", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   788
INSTRUCTION_STATE(DP4, "DP4", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   789
INSTRUCTION(MIN, "MIN", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   790
INSTRUCTION(MAX, "MAX", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   791
INSTRUCTION(SLT, "SLT", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   792
INSTRUCTION(SGE, "SGE", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   793
INSTRUCTION(EXP, "EXP", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   794
INSTRUCTION_STATE(LOG, "LOG", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   795
INSTRUCTION(LIT, "LIT", 3, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   796
INSTRUCTION(DST, "DST", 1, DSS, MOJOSHADER_TYPE_VERTEX, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   797
INSTRUCTION(LRP, "LRP", 2, DSSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   798
INSTRUCTION_STATE(FRC, "FRC", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   799
INSTRUCTION_STATE(M4X4, "M4X4", 4, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   800
INSTRUCTION_STATE(M4X3, "M4X3", 3, DSS, MOJOSHADER_TYPE_ANY, 0x7)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   801
INSTRUCTION_STATE(M3X4, "M3X4", 4, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   802
INSTRUCTION_STATE(M3X3, "M3X3", 3, DSS, MOJOSHADER_TYPE_ANY, 0x7)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   803
INSTRUCTION_STATE(M3X2, "M3X2", 2, DSS, MOJOSHADER_TYPE_ANY, 0x3)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   804
INSTRUCTION_STATE(CALL, "CALL", 2, S, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   805
INSTRUCTION_STATE(CALLNZ, "CALLNZ", 3, SS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   806
INSTRUCTION_STATE(LOOP, "LOOP", 3, SS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   807
INSTRUCTION_STATE(RET, "RET", 1, NULL, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   808
INSTRUCTION_STATE(ENDLOOP, "ENDLOOP", 2, NULL, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   809
INSTRUCTION_STATE(LABEL, "LABEL", 0, S, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   810
INSTRUCTION_STATE(DCL, "DCL", 0, DCL, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   811
INSTRUCTION_STATE(POW, "POW", 3, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   812
INSTRUCTION(CRS, "CRS", 2, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   813
INSTRUCTION(SGN, "SGN", 3, DSSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   814
INSTRUCTION(ABS, "ABS", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   815
INSTRUCTION(NRM, "NRM", 3, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   816
INSTRUCTION_STATE(SINCOS, "SINCOS", 8, SINCOS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   817
INSTRUCTION_STATE(REP, "REP", 3, S, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   818
INSTRUCTION_STATE(ENDREP, "ENDREP", 2, NULL, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   819
INSTRUCTION_STATE(IF, "IF", 3, S, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   820
INSTRUCTION_STATE(IFC, "IF", 3, SS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   821
INSTRUCTION(ELSE, "ELSE", 1, NULL, MOJOSHADER_TYPE_ANY, 0xF)  // !!! FIXME: state!
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   822
INSTRUCTION(ENDIF, "ENDIF", 1, NULL, MOJOSHADER_TYPE_ANY, 0xF) // !!! FIXME: state!
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   823
INSTRUCTION_STATE(BREAK, "BREAK", 1, NULL, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   824
INSTRUCTION_STATE(BREAKC, "BREAK", 3, SS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   825
INSTRUCTION_STATE(MOVA, "MOVA", 1, DS, MOJOSHADER_TYPE_VERTEX, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   826
INSTRUCTION_STATE(DEFB, "DEFB", 0, DEFB, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   827
INSTRUCTION_STATE(DEFI, "DEFI", 0, DEFI, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   828
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   829
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   830
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   831
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   832
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   833
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   834
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   835
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   836
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   837
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   838
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   839
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   840
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   841
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   842
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   843
INSTRUCTION_STATE(TEXCRD, "TEXCRD", 1, TEXCRD, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   844
INSTRUCTION_STATE(TEXKILL, "TEXKILL", 2, D, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   845
INSTRUCTION_STATE(TEXLD, "TEXLD", 1, TEXLD, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   846
INSTRUCTION_STATE(TEXBEM, "TEXBEM", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   847
INSTRUCTION_STATE(TEXBEML, "TEXBEML", 2, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   848
INSTRUCTION(TEXREG2AR, "TEXREG2AR", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   849
INSTRUCTION(TEXREG2GB, "TEXREG2GB", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   850
INSTRUCTION_STATE(TEXM3X2PAD, "TEXM3X2PAD", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   851
INSTRUCTION_STATE(TEXM3X2TEX, "TEXM3X2TEX", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   852
INSTRUCTION_STATE(TEXM3X3PAD, "TEXM3X3PAD", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   853
INSTRUCTION_STATE(TEXM3X3TEX, "TEXM3X3TEX", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   854
INSTRUCTION(RESERVED, 0, 0, NULL, MOJOSHADER_TYPE_UNKNOWN, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   855
INSTRUCTION_STATE(TEXM3X3SPEC, "TEXM3X3SPEC", 1, DSS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   856
INSTRUCTION_STATE(TEXM3X3VSPEC, "TEXM3X3VSPEC", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   857
INSTRUCTION(EXPP, "EXPP", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   858
INSTRUCTION_STATE(LOGP, "LOGP", 1, DS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   859
INSTRUCTION_STATE(CND, "CND", 1, DSSS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   860
INSTRUCTION_STATE(DEF, "DEF", 0, DEF, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   861
INSTRUCTION(TEXREG2RGB, "TEXREG2RGB", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   862
INSTRUCTION(TEXDP3TEX, "TEXDP3TEX", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   863
INSTRUCTION(TEXM3X2DEPTH, "TEXM3X2DEPTH", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   864
INSTRUCTION(TEXDP3, "TEXDP3", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   865
INSTRUCTION_STATE(TEXM3X3, "TEXM3X3", 1, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   866
INSTRUCTION(TEXDEPTH, "TEXDEPTH", 1, D, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   867
INSTRUCTION_STATE(CMP, "CMP", 1, DSSS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   868
INSTRUCTION(BEM, "BEM", 2, DSS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   869
INSTRUCTION_STATE(DP2ADD, "DP2ADD", 2, DSSS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   870
INSTRUCTION(DSX, "DSX", 2, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   871
INSTRUCTION(DSY, "DSY", 2, DS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   872
INSTRUCTION(TEXLDD, "TEXLDD", 3, DSSSS, MOJOSHADER_TYPE_PIXEL, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   873
INSTRUCTION_STATE(SETP, "SETP", 1, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   874
INSTRUCTION_STATE(TEXLDL, "TEXLDL", 2, DSS, MOJOSHADER_TYPE_ANY, 0xF)
c5a53296dbd5 List default writemasks for instructions.
Ryan C. Gordon <icculus@icculus.org>
parents: 1283
diff changeset
   875
INSTRUCTION_STATE(BREAKP, "BREAKP", 3, S, MOJOSHADER_TYPE_ANY, 0xF)
1283
c198fe1c469a Don't make the MOJOSHADER_DO_INSTRUCTION_TABLE caller undef everything after.
Ryan C. Gordon <icculus@icculus.org>
parents: 1277
diff changeset
   876
c198fe1c469a Don't make the MOJOSHADER_DO_INSTRUCTION_TABLE caller undef everything after.
Ryan C. Gordon <icculus@icculus.org>
parents: 1277
diff changeset
   877
#undef MOJOSHADER_DO_INSTRUCTION_TABLE
c198fe1c469a Don't make the MOJOSHADER_DO_INSTRUCTION_TABLE caller undef everything after.
Ryan C. Gordon <icculus@icculus.org>
parents: 1277
diff changeset
   878
#undef INSTRUCTION
c198fe1c469a Don't make the MOJOSHADER_DO_INSTRUCTION_TABLE caller undef everything after.
Ryan C. Gordon <icculus@icculus.org>
parents: 1277
diff changeset
   879
#undef INSTRUCTION_STATE
c198fe1c469a Don't make the MOJOSHADER_DO_INSTRUCTION_TABLE caller undef everything after.
Ryan C. Gordon <icculus@icculus.org>
parents: 1277
diff changeset
   880
465
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   881
#endif
0a75f98f785b Initial work on assembler. Not even close to done.
Ryan C. Gordon <icculus@icculus.org>
parents: 464
diff changeset
   882
464
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   883
// end of mojoshader_internal.h ...
eba4cf79437f Moved some common stuff to mojoshader_internal.h ...
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   884