Skip to content

Commit

Permalink
Implement geometry shaders using object and mesh stages.
Browse files Browse the repository at this point in the history
  • Loading branch information
js6i committed Sep 21, 2023
1 parent 5e963d6 commit 3dbf356
Show file tree
Hide file tree
Showing 4 changed files with 768 additions and 128 deletions.
68 changes: 28 additions & 40 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,30 @@ static string compile_iteration(const CLIArguments &args, std::vector<uint32_t>
return ret;
}

static MSLShaderVariableFormat parse_format(const char *text)
{
MSLShaderVariableFormat format;
if (strcmp(text, "i8") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_INT8;
else if (strcmp(text, "i16") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_INT16;
else if (strcmp(text, "i32") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_INT32;
else if (strcmp(text, "u8") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
else if (strcmp(text, "u16") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
else if (strcmp(text, "u32") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_UINT32;
else if (strcmp(text, "float") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_FLOAT;
else if (strcmp(text, "half") == 0)
format = MSL_SHADER_VARIABLE_FORMAT_HALF;
else
format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
return format;
}

static int main_inner(int argc, char *argv[])
{
CLIArguments args;
Expand Down Expand Up @@ -1685,16 +1709,7 @@ static int main_inner(int argc, char *argv[])
// Make sure next_uint() is called in-order.
input.location = parser.next_uint();
const char *format = parser.next_value_string("other");
if (strcmp(format, "any32") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
else if (strcmp(format, "any16") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
else if (strcmp(format, "u16") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
else if (strcmp(format, "u8") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
else
input.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
input.format = parse_format(format);
input.vecsize = parser.next_uint();
const char *rate = parser.next_value_string("vertex");
if (strcmp(rate, "primitive") == 0)
Expand All @@ -1710,16 +1725,7 @@ static int main_inner(int argc, char *argv[])
// Make sure next_uint() is called in-order.
output.location = parser.next_uint();
const char *format = parser.next_value_string("other");
if (strcmp(format, "any32") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
else if (strcmp(format, "any16") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
else if (strcmp(format, "u16") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
else if (strcmp(format, "u8") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
else
output.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
output.format = parse_format(format);
output.vecsize = parser.next_uint();
const char *rate = parser.next_value_string("vertex");
if (strcmp(rate, "primitive") == 0)
Expand All @@ -1735,16 +1741,7 @@ static int main_inner(int argc, char *argv[])
// Make sure next_uint() is called in-order.
input.location = parser.next_uint();
const char *format = parser.next_value_string("other");
if (strcmp(format, "any32") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
else if (strcmp(format, "any16") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
else if (strcmp(format, "u16") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
else if (strcmp(format, "u8") == 0)
input.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
else
input.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
input.format = parse_format(format);
input.vecsize = parser.next_uint();
args.msl_shader_inputs.push_back(input);
});
Expand All @@ -1753,16 +1750,7 @@ static int main_inner(int argc, char *argv[])
// Make sure next_uint() is called in-order.
output.location = parser.next_uint();
const char *format = parser.next_value_string("other");
if (strcmp(format, "any32") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY32;
else if (strcmp(format, "any16") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_ANY16;
else if (strcmp(format, "u16") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT16;
else if (strcmp(format, "u8") == 0)
output.format = MSL_SHADER_VARIABLE_FORMAT_UINT8;
else
output.format = MSL_SHADER_VARIABLE_FORMAT_OTHER;
output.format = parse_format(format);
output.vecsize = parser.next_uint();
args.msl_shader_outputs.push_back(output);
});
Expand Down
16 changes: 9 additions & 7 deletions spirv_cross_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,24 @@ typedef enum spvc_msl_index_type
/* Maps to C++ API. */
typedef enum spvc_msl_shader_variable_format
{

SPVC_MSL_SHADER_VARIABLE_FORMAT_OTHER = 0,
SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT8 = 1,
SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT16 = 2,
SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY16 = 3,
SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY32 = 4,

/* Deprecated names. */
SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT32 = 3,
SPVC_MSL_SHADER_VARIABLE_FORMAT_FLOAT = 4,
SPVC_MSL_SHADER_VARIABLE_FORMAT_INT8 = 5,
SPVC_MSL_SHADER_VARIABLE_FORMAT_INT16 = 6,
SPVC_MSL_SHADER_VARIABLE_FORMAT_INT32 = 7,
SPVC_MSL_SHADER_VARIABLE_FORMAT_HALF = 8,

// Deprecated aliases.
SPVC_MSL_VERTEX_FORMAT_OTHER = SPVC_MSL_SHADER_VARIABLE_FORMAT_OTHER,
SPVC_MSL_VERTEX_FORMAT_UINT8 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT8,
SPVC_MSL_VERTEX_FORMAT_UINT16 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT16,
SPVC_MSL_SHADER_INPUT_FORMAT_OTHER = SPVC_MSL_SHADER_VARIABLE_FORMAT_OTHER,
SPVC_MSL_SHADER_INPUT_FORMAT_UINT8 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT8,
SPVC_MSL_SHADER_INPUT_FORMAT_UINT16 = SPVC_MSL_SHADER_VARIABLE_FORMAT_UINT16,
SPVC_MSL_SHADER_INPUT_FORMAT_ANY16 = SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY16,
SPVC_MSL_SHADER_INPUT_FORMAT_ANY32 = SPVC_MSL_SHADER_VARIABLE_FORMAT_ANY32,


SPVC_MSL_SHADER_INPUT_FORMAT_INT_MAX = 0x7fffffff
} spvc_msl_shader_variable_format, spvc_msl_shader_input_format, spvc_msl_vertex_format;
Expand Down
Loading

0 comments on commit 3dbf356

Please sign in to comment.