Skip to content

Commit fa702ce

Browse files
committed
Implement geometry shaders using object and mesh stages.
1 parent 5e963d6 commit fa702ce

File tree

4 files changed

+772
-132
lines changed

4 files changed

+772
-132
lines changed

main.cpp

+32-44
Original file line numberDiff line numberDiff line change
@@ -900,21 +900,21 @@ static void print_help_msl()
900900
"\t[--msl-enable-frag-output-mask <mask>]:\n\t\tOnly selectively enable fragment outputs. Useful if pipeline does not enable fragment output for certain locations, as pipeline creation might otherwise fail.\n"
901901
"\t[--msl-no-clip-distance-user-varying]:\n\t\tDo not emit user varyings to emulate gl_ClipDistance in fragment shaders.\n"
902902
"\t[--msl-add-shader-input <index> <format> <size> <rate>]:\n\t\tSpecify the format of the shader input at <index>.\n"
903-
"\t\t<format> can be 'any32', 'any16', 'u16', 'u8', or 'other', to indicate a 32-bit opaque value, 16-bit opaque value, 16-bit unsigned integer, 8-bit unsigned integer, "
903+
"\t\t<format> can be 'i32', 'i16', 'i8', 'u32', 'u16', 'u8', 'float', 'half', or 'other', to indicate a 32/16/8-bit integer (i) or unsigned integer (u), floating point, half-precision floating point, "
904904
"or other-typed variable. <size> is the vector length of the variable, which must be greater than or equal to that declared in the shader. <rate> can be 'vertex', "
905905
"'primitive', or 'patch' to indicate a per-vertex, per-primitive, or per-patch variable.\n"
906906
"\t\tUseful if shader stage interfaces don't match up, as pipeline creation might otherwise fail.\n"
907907
"\t[--msl-add-shader-output <index> <format> <size> <rate>]:\n\t\tSpecify the format of the shader output at <index>.\n"
908-
"\t\t<format> can be 'any32', 'any16', 'u16', 'u8', or 'other', to indicate a 32-bit opaque value, 16-bit opaque value, 16-bit unsigned integer, 8-bit unsigned integer, "
908+
"\t\t<format> can be 'i32', 'i16', 'i8', 'u32', 'u16', 'u8', 'float', 'half', or 'other', to indicate a 32/16/8-bit integer (i) or unsigned integer (u), floating point, half-precision floating point, "
909909
"or other-typed variable. <size> is the vector length of the variable, which must be greater than or equal to that declared in the shader. <rate> can be 'vertex', "
910910
"'primitive', or 'patch' to indicate a per-vertex, per-primitive, or per-patch variable.\n"
911911
"\t\tUseful if shader stage interfaces don't match up, as pipeline creation might otherwise fail.\n"
912912
"\t[--msl-shader-input <index> <format> <size>]:\n\t\tSpecify the format of the shader input at <index>.\n"
913-
"\t\t<format> can be 'any32', 'any16', 'u16', 'u8', or 'other', to indicate a 32-bit opaque value, 16-bit opaque value, 16-bit unsigned integer, 8-bit unsigned integer, "
913+
"\t\t<format> can be 'i32', 'i16', 'i8', 'u32', 'u16', 'u8', 'float', 'half', or 'other', to indicate a 32/16/8-bit integer (i) or unsigned integer (u), floating point, half-precision floating point, "
914914
"or other-typed variable. <size> is the vector length of the variable, which must be greater than or equal to that declared in the shader."
915915
"\t\tEquivalent to --msl-add-shader-input with a rate of 'vertex'.\n"
916916
"\t[--msl-shader-output <index> <format> <size>]:\n\t\tSpecify the format of the shader output at <index>.\n"
917-
"\t\t<format> can be 'any32', 'any16', 'u16', 'u8', or 'other', to indicate a 32-bit opaque value, 16-bit opaque value, 16-bit unsigned integer, 8-bit unsigned integer, "
917+
"\t\t<format> can be 'i32', 'i16', 'i8', 'u32', 'u16', 'u8', 'float', or 'other', to indicate a 32/16/8-bit integer (i) or unsigned integer (u), floating point, half-precision floating point, "
918918
"or other-typed variable. <size> is the vector length of the variable, which must be greater than or equal to that declared in the shader."
919919
"\t\tEquivalent to --msl-add-shader-output with a rate of 'vertex'.\n"
920920
"\t[--msl-raw-buffer-tese-input]:\n\t\tUse raw buffers for tessellation evaluation input.\n"
@@ -1554,6 +1554,30 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
15541554
return ret;
15551555
}
15561556

1557+
static MSLShaderVariableFormat parse_format(const char *text)
1558+
{
1559+
MSLShaderVariableFormat format;
1560+
if (strcmp(text, "i8") == 0)
1561+
format = MSL_SHADER_VARIABLE_FORMAT_INT8;
1562+
else if (strcmp(text, "i16") == 0)
1563+
format = MSL_SHADER_VARIABLE_FORMAT_INT16;
1564+
else if (strcmp(text, "i32") == 0)
1565+
format = MSL_SHADER_VARIABLE_FORMAT_INT32;
1566+
else if (strcmp(text, "u8") == 0)
1567+
format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
1568+
else if (strcmp(text, "u16") == 0)
1569+
format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
1570+
else if (strcmp(text, "u32") == 0)
1571+
format = MSL_SHADER_VARIABLE_FORMAT_UINT32;
1572+
else if (strcmp(text, "float") == 0)
1573+
format = MSL_SHADER_VARIABLE_FORMAT_FLOAT;
1574+
else if (strcmp(text, "half") == 0)
1575+
format = MSL_SHADER_VARIABLE_FORMAT_HALF;
1576+
else
1577+
format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
1578+
return format;
1579+
}
1580+
15571581
static int main_inner(int argc, char *argv[])
15581582
{
15591583
CLIArguments args;
@@ -1685,16 +1709,7 @@ static int main_inner(int argc, char *argv[])
16851709
// Make sure next_uint() is called in-order.
16861710
input.location = parser.next_uint();
16871711
const char *format = parser.next_value_string("other");
1688-
if (strcmp(format, "any32") == 0)
1689-
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
1690-
else if (strcmp(format, "any16") == 0)
1691-
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
1692-
else if (strcmp(format, "u16") == 0)
1693-
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
1694-
else if (strcmp(format, "u8") == 0)
1695-
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
1696-
else
1697-
input.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
1712+
input.format = parse_format(format);
16981713
input.vecsize = parser.next_uint();
16991714
const char *rate = parser.next_value_string("vertex");
17001715
if (strcmp(rate, "primitive") == 0)
@@ -1710,16 +1725,7 @@ static int main_inner(int argc, char *argv[])
17101725
// Make sure next_uint() is called in-order.
17111726
output.location = parser.next_uint();
17121727
const char *format = parser.next_value_string("other");
1713-
if (strcmp(format, "any32") == 0)
1714-
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
1715-
else if (strcmp(format, "any16") == 0)
1716-
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
1717-
else if (strcmp(format, "u16") == 0)
1718-
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
1719-
else if (strcmp(format, "u8") == 0)
1720-
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
1721-
else
1722-
output.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
1728+
output.format = parse_format(format);
17231729
output.vecsize = parser.next_uint();
17241730
const char *rate = parser.next_value_string("vertex");
17251731
if (strcmp(rate, "primitive") == 0)
@@ -1735,16 +1741,7 @@ static int main_inner(int argc, char *argv[])
17351741
// Make sure next_uint() is called in-order.
17361742
input.location = parser.next_uint();
17371743
const char *format = parser.next_value_string("other");
1738-
if (strcmp(format, "any32") == 0)
1739-
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
1740-
else if (strcmp(format, "any16") == 0)
1741-
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
1742-
else if (strcmp(format, "u16") == 0)
1743-
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
1744-
else if (strcmp(format, "u8") == 0)
1745-
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
1746-
else
1747-
input.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
1744+
input.format = parse_format(format);
17481745
input.vecsize = parser.next_uint();
17491746
args.msl_shader_inputs.push_back(input);
17501747
});
@@ -1753,16 +1750,7 @@ static int main_inner(int argc, char *argv[])
17531750
// Make sure next_uint() is called in-order.
17541751
output.location = parser.next_uint();
17551752
const char *format = parser.next_value_string("other");
1756-
if (strcmp(format, "any32") == 0)
1757-
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
1758-
else if (strcmp(format, "any16") == 0)
1759-
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
1760-
else if (strcmp(format, "u16") == 0)
1761-
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
1762-
else if (strcmp(format, "u8") == 0)
1763-
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
1764-
else
1765-
output.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
1753+
output.format = parse_format(format);
17661754
output.vecsize = parser.next_uint();
17671755
args.msl_shader_outputs.push_back(output);
17681756
});

spirv_cross_c.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,24 @@ typedef enum spvc_msl_index_type
293293
/* Maps to C++ API. */
294294
typedef enum spvc_msl_shader_variable_format
295295
{
296+
296297
SPVC_MSL_SHADER_VARIABLE_FORMAT_OTHER = 0,
297298
SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT8 = 1,
298299
SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT16 = 2,
299-
SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY16 = 3,
300-
SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY32 = 4,
301-
302-
/* Deprecated names. */
300+
SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT32 = 3,
301+
SPVC_MSL_SHADER_VARIABLE_FORMAT_FLOAT = 4,
302+
SPVC_MSL_SHADER_VARIABLE_FORMAT_INT8 = 5,
303+
SPVC_MSL_SHADER_VARIABLE_FORMAT_INT16 = 6,
304+
SPVC_MSL_SHADER_VARIABLE_FORMAT_INT32 = 7,
305+
SPVC_MSL_SHADER_VARIABLE_FORMAT_HALF = 8,
306+
307+
// Deprecated aliases.
303308
SPVC_MSL_VERTEX_FORMAT_OTHER = SPVC_MSL_SHADER_VARIABLE_FORMAT_OTHER,
304309
SPVC_MSL_VERTEX_FORMAT_UINT8 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT8,
305310
SPVC_MSL_VERTEX_FORMAT_UINT16 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT16,
306311
SPVC_MSL_SHADER_INPUT_FORMAT_OTHER = SPVC_MSL_SHADER_VARIABLE_FORMAT_OTHER,
307312
SPVC_MSL_SHADER_INPUT_FORMAT_UINT8 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT8,
308313
SPVC_MSL_SHADER_INPUT_FORMAT_UINT16 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT16,
309-
SPVC_MSL_SHADER_INPUT_FORMAT_ANY16 = SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY16,
310-
SPVC_MSL_SHADER_INPUT_FORMAT_ANY32 = SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY32,
311-
312314

313315
SPVC_MSL_SHADER_INPUT_FORMAT_INT_MAX = 0x7fffffff
314316
} spvc_msl_shader_variable_format, spvc_msl_shader_input_format, spvc_msl_vertex_format;

0 commit comments

Comments
 (0)