Commit Graph

180 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
49ac538a64 Remove maybe_assign_input_struct.
This is obsolete and wrong since we already unflatten I/O structs.
2018-09-17 13:51:02 +02:00
Chip Davis
39bc101e82 MSL: Handle the SamplePosition builtin.
This is somewhat tricky, because in MSL this value is obtained through a
function, `get_sample_position()`. Since the call expression is an
rvalue, it can't be passed by reference, so functions get a copy
instead.

This was the last piece preventing us from turning on sample-rate
shading support in MoltenVK.
2018-09-13 09:34:28 -05:00
Hans-Kristian Arntzen
1bbb4032c8
Merge pull request #693 from cdavis5e/msl-atomic-inc-dec
MSL: Fix OpAtomicIIncrement and OpAtomicIDecrement.
2018-09-13 16:19:27 +02:00
Hans-Kristian Arntzen
d310060f92 MSL: Support global I/O block and struct Input/Output usage.
Implement this by flattening outputs and unflattening inputs explicitly.
This allows us to pass down a single struct instead of dealing with the
insanity that would be passing down each flattened member separately.

Remove stage_uniforms_var_id.
Seems to be dead code. Naked uniforms do not exist in SPIR-V for Vulkan,
which this seems to have been intended for. It was also unused elsewhere.
2018-09-13 16:04:24 +02:00
Chip Davis
06edf804ac Clarify name of this parameter. 2018-09-13 08:56:23 -05:00
Hans-Kristian Arntzen
38d19821d4 MSL: Support copying array of arrays. 2018-09-12 09:54:55 +02:00
Chip Davis
41eb5c43b5 MSL: Fix OpAtomicIIncrement and OpAtomicIDecrement.
We were passing a constant '1' to `emit_atomic_func_op()`--which caused
us to refer to SPIR-V value `%1`, which is almost certainly not what we
want! What we really want is to add/subtract the literal constant '1'
to/from the memory location.
2018-09-11 17:29:54 -05:00
Hans-Kristian Arntzen
b114889102 Only declare typed initializer list for non-array types.
Also, cleanup now redundant constant_expression virtualization for MSL.
2018-09-10 10:04:17 +02:00
Chip Davis
4b99fdd5d0 MSL: Account for components when assigning locations to varyings.
Two varyings (vertex outputs/fragment inputs) might have the same
location but be in different components--e.g. the compiler may have
packed what were two different varyings into a single varying vector.
Giving both varyings the same `[[user]]` attribute won't work--it may
yield unexpected results, or flat out fail to link. We could eventually
pack such varyings into a single vector, but that would require us to
handle the case where the varyings are different types--e.g. a `float`
and a `uint` packed into the same vector. For now, it seems most
prudent to give them unique `[[user]]` locations and let Apple's
compiler work out the best way to pack them.
2018-09-06 13:52:33 -05:00
Chip Davis
d3233690cb MSL: Support unordered relational operators.
The SPIR-V spec says that these check if the operands either are
unordered or satisfy the given condition. So that's just what we'll do,
using Metal's `isunordered()` stdlib function. Apple's optimizers ought
to be able to collapse that to a single unordered compare.
2018-08-31 13:54:42 -05:00
Bill Hollings
c3d74e1e14 CompilerMSL disable rasterization on buffer writes in vertex shader. 2018-07-27 16:53:36 -04:00
Bill Hollings
0d6202e770 Add CompilerMSL::get_is_rasterization_disabled() to manage rasterization status. 2018-07-26 16:40:32 -04:00
Bill Hollings
ac238b858b CompilerMSL vertex entry point return void when rasterization disabled.
Add CompilerMSL::Options::disable_rasterization input/output API flag.
Disable rasterization via API flag or when writing to textures.
Disable rasterization when shader declares no output.
Add test shaders for vertex no output and write texture forcing void output.
2018-07-26 00:50:33 -04:00
Hans-Kristian Arntzen
cc7679ee45 Workaround NOMINMAX issues on Windows.
::max() can be overridden if you forget NOMINMAX on Windows.
Hardcode literals instead. UINT32_MAX also requires weird macros in C++.
2018-07-17 00:10:12 +02:00
Hans-Kristian Arntzen
2bf57d6dff Deal with composite constants in variable initializer. 2018-07-05 15:29:49 +02:00
Hans-Kristian Arntzen
9ddbd5aff6 Run format_all.sh. 2018-06-28 23:00:26 +02:00
Bill Hollings
9bf226cb05 Fixes for code review of PR 626. 2018-06-27 10:34:15 -04:00
Bill Hollings
4c5142b9d3 CompilerMSL support larger texel buffers by using 2D Metal textures.
Add CompilerMSL::Options::texture_width_max.
Emit and use spvTexelBufferCoord() function to convert 1D
texel buffer coordinates to 2D Metal texture coordinates.
2018-06-26 17:30:21 -04:00
Hans-Kristian Arntzen
d94d20f4f3 Deal with some builtins being declared with wrong signedness. 2018-06-22 11:30:56 +02:00
Bill Hollings
9b4defe202 CompilerMSL support matrices & arrays in stage-in & stage-out.
Support flattening StorageOutput & StorageInput matrices and arrays.
No longer move matrix & array inputs to separate buffer.
Add separate SPIRFunction::fixup_statements_in & SPIRFunction::fixup_statements_out
instead of just  SPIRFunction::fixup_statements.
Emit SPIRFunction::fixup_statements at beginning of functions.
CompilerMSL track vars_needing_early_declaration.
Pass global output variables as variables to functions that access them.
Sort input structs by location, same as output structs.
Emit struct declarations in order output, input, uniforms.
Regenerate reference shaders to new formats defined by above.
2018-06-12 11:41:35 -04:00
Hans-Kristian Arntzen
e30a94225f Complete MSL constexpr samplers.
Deal with defaults and avoid verbose declarations.
2018-04-18 16:19:55 +02:00
Hans-Kristian Arntzen
df58debf7a Add support for constexpr samplers in MSL. 2018-04-17 17:43:32 +02:00
Hans-Kristian Arntzen
382101bd05 Run format_all.sh. 2018-04-04 09:26:53 +02:00
Hans-Kristian Arntzen
5827dd54ea Support array of images and samplers in MSL. 2018-04-04 09:26:53 +02:00
Hans-Kristian Arntzen
e8e58844d4 Rewrite everything to use Bitset rather than uint64_t. 2018-03-12 13:24:14 +01:00
Hans-Kristian Arntzen
a803e5ae38 Deprecate set_options()/get_options() interface, replace it.
Replace with common/hlsl/msl instead. The old interface had some bad
interaction with overloading which meant you had to up-cast to base
class to be able to use set_options, which was awkward.
2018-03-09 15:25:25 +01:00
Hans-Kristian Arntzen
6a12ff7fb7 Fix multiple declaration of spvDet2x2 on MSL. 2018-02-23 16:52:11 +01:00
Bill Hollings
2964e328e6 CompilerMSL support gl_SampleMask and convert it to scalar uint from array. 2018-02-13 14:44:40 -05:00
Bill Hollings
b453348370 Merge branch 'master' of https://github.com/billhollings/SPIRV-Cross 2018-02-11 16:54:25 -05:00
Bill Hollings
607b0d6d42 CompilerMSL support smaller offsets for 3-row row-major matrices.
Support MSL typedefs to declare 3-row row-major matrices as 3-column matrices.
Allow those matrices to be decorated as packed.
Support transposing those matrices when used.
Modify how member alignments are calculated.
2018-02-11 16:52:57 -05:00
Hans-Kristian Arntzen
702e08671b Support passing implicit frag_coord arguments down to functions. 2018-02-10 10:55:09 +01:00
Hans-Kristian Arntzen
0912427046 Begin implementing subpassLoad in MSL. 2018-02-10 10:54:56 +01:00
Hans-Kristian Arntzen
1a9c960058 MSL cannot declare inline arrays except in certain cases. 2018-02-08 13:06:29 +01:00
Hans-Kristian Arntzen
00ccd590ee Return arrays in HLSL/MSL by writing to an output variable instead. 2018-02-08 12:22:08 +01:00
msiglreith
d096f5cafe hlsl: Support custom root constant layout 2018-02-07 15:21:52 +01:00
Bill Hollings
1c94715350 Update copyright dates to 2018 in main files. 2018-01-31 17:08:43 -05:00
Bill Hollings
6371d9e43a CompilerMSL emit no-warning pragma when emitting spvConvertFromRowMajorCxR functions. 2018-01-06 00:51:25 -05:00
Bill Hollings
5ee6b46087 Fixes from review of PR #373.
Code fixes from review.
Refactor MSL tests back to using the SPIRV-Tools
and glslang loaded by checkout_glslang_spirv_tools.sh.
2018-01-05 23:22:36 -05:00
Bill Hollings
8890578d2a CompilerMSL support conversion of non-square row-major matrices. 2018-01-04 16:33:45 -05:00
Bill Hollings
3fcdce08ab CompilerMSL support platform semantics.
Support customizing MSL based on iOS or macOS platform.
Support SPIV-V containing multiple memory semantics.
2017-12-26 13:39:07 -05:00
Bill Hollings
e83e2b2217 CompilerMSL support and tests for OpUndef. 2017-11-15 22:44:42 -05:00
Bill Hollings
1014847f17 Fixes from review #3 of PR 321. 2017-11-10 16:40:33 -05:00
Bill Hollings
696bf0db0f Fixes from review #2 of PR 321. 2017-11-08 13:54:28 -05:00
Bill Hollings
2086274b62 spriv_msl.hpp fix casting warning when setting MSL version option. 2017-11-07 16:27:21 -05:00
Bill Hollings
6ea0dd95ea spriv_msl.hpp add explicit include of <limits>. 2017-11-07 15:53:20 -05:00
Bill Hollings
bac657d873 Fixes from review of PR 321. 2017-11-07 15:38:13 -05:00
Bill Hollings
1c18078811 Enhancements to MSL compute and entry point naming.
Support Workgroup (threadgroup) variables.
Mark if SPIRConstant is used as an array length, since it cannot be specialized.
Resolve specialized array length constants.
Support passing an array to MSL function.
Support emitting GLSL array assignments in MSL via an array copy function.
Support for memory and control barriers.
Struct packing enhancements, including packing nested structs.
Enhancements to replacing illegal MSL variable and function names.
Add Compiler::get_entry_point_name_map() function to retrieve entry point renamings.
Remove CompilerGLSL::clean_func_name() as obsolete.
Fixes to types in bitcast MSL functions.
Add Variant::get_id() member function.
Add CompilerMSL::Options::msl_version option.
Add numerous MSL compute tests.
2017-11-05 21:34:42 -05:00
Bill Hollings
44347caff1 Add *.bc to .gitignore to ignore Xcode 9 intermediate compiled shader files.
spirv_msl.hpp use numeric_limits instead of UINT32_MAX.
2017-10-02 18:13:08 -04:00
Bill Hollings
1e84a379ff Fix issue #245: assignment of flattened input struct.
Emit input struct assignment by assigning member by member from stage_in struct.
Map qualified member name from pointer type, not base type.
Add Comiler::expression_type_id() function, similar to expression_type().
2017-08-12 00:21:13 -04:00
Hans-Kristian Arntzen
6cda7f120b Merge pull request #246 from KhronosGroup/fix-241
Unify vertex clip-coord fixups.
2017-08-11 12:42:10 +02:00
Bill Hollings
730257cf67 Merge upstream 2017-08-10 17:27:01 -04:00
Hans-Kristian Arntzen
bdfa97a1cf Unify vertex clip-coord fixups.
The different options were scattered around in different backends and
didn't really work right with CLI at all.
2017-08-03 13:02:59 +02:00
Hans-Kristian Arntzen
c8d60914c4 Add support for SampleId/SampleMask/SamplePosition builtins. 2017-07-24 10:07:31 +02:00
Bill Hollings
f591bc0d4a CompilerMSL enhancements.
Support BuiltInFragDepth.
Emit interface block for StorageClassUniformConstant.
Throw exception when output or fragment input structs contain matrix or array.
Dynamically created interface structs sorted by location number instead of alphabetically.
Add Compiler::is_array() function.
2017-06-30 19:10:46 -04:00
Bill Hollings
1f83856366 CompilerMSL add support for MSL specialization function constants.
CompilerMSL add emit_custom_functions() function.
CompilerMSL restrict use of as_type<> cast to necessary conditions.
CompilerMSL refactor get_declared_struct_member_size() and
get_declared_struct_member_alignment() functions, and remove
unnecessary get_declared_type_size() functions.
Add test shaders-msl/vulkan/frag/spec-constant.vk.frag.
2017-06-15 15:24:22 -04:00
Bill Hollings
b41e1482c8 Support emitting SPIR-V type declarations tuned for specified SPIR-V objects.
CompilerGLSL type_to_glsl() and image_type_glsl() functions support optional object ID.
Add SPIRType::Image::access member to support SPIR-V OpTypeImage access qualifier.
Remove SPIRType::Image::is_read and ::is_written members.
Use DecorationNonReadable and DecorationNonWritable to mark read/write access for image variables.
CompilerMSL emit access qualifiers per image variable, instead of per image type.
CompilerGLSL and CompilerHLSL behaviour is unchanged.
2017-05-29 20:45:05 -04:00
Bill Hollings
0f97ffd8be Fix merge conflicts with upstream master, plus fixes from review of PR #186. 2017-05-23 10:44:10 -04:00
Hans-Kristian Arntzen
91379fb0d0 Implement more sophisticated check for point_size. 2017-05-23 10:15:22 +02:00
Bill Hollings
a71c547b30 CompilerMSL remove pad_and_pack_uniform_structs option from both API and CLI tool. 2017-05-22 16:38:38 -04:00
Bill Hollings
d677e63860 Merge with upstream 2017-05-19 19:36:24 -04:00
Bill Hollings
8f6df770ce CompilerMSL map many GLSL functions to MSL functions.
Add bool members is_read and is_written to SPIRType::Image.
Output correct texture read/write access by marking whether textures
are read from and written to by the shader.
Override bitcast_glsl_op() to use Metal as_type<type> functions.
Add implementations of SPIR-V functions inverse(), degrees() & radians().
Map inverseSqrt() to rsqrt().
Map roundEven() to rint().
GLSL functions imageSize() and textureSize() map to equivalent
expression using MSL get_width() & get_height() functions.
Map several SPIR-V integer bitfield functions to MSL equivalents.
Map SPIR-V atomic functions to MSL equivalents.
Map texture packing and unpacking functions to MSL equivalents.
Refactor existing, and add new, image query functions.
Reorganize header lines into includes and pragmas.
Simplify type_to_glsl() logic.
Add MSL test case vert/functions.vert for added function implementations.
Add MSL test case comp/atomic.comp for added function implementations.
test_shaders.py use macOS compilation for MSL shader compilation validations.
2017-05-19 18:14:08 -04:00
Hans-Kristian Arntzen
f081fe1125 Fix separate sampler images in MSL. 2017-05-07 12:36:14 +02:00
Bill Hollings
f9f87ca391 CompilerMSL output [[point_size]] attribute for BuiltInPointSize member by default.
CompilerMSL::Options::is_rendering_points defaults to true.
2017-05-05 16:13:55 -04:00
Bill Hollings
561dc036f2 CompilerMSL round floating point tex coords for read() and tex array index. 2017-04-25 16:32:16 -04:00
Bill Hollings
012cb25b7d CompilerMSL remove option to flip fragment coordinates. 2017-04-25 11:25:50 -04:00
Bill Hollings
7703b746f7 CompilerMSL vectorless constructor uses vectorless attribute and resource bindings. 2017-04-04 16:38:17 -04:00
Hans-Kristian Arntzen
9bad477f16 Add vector-less IR construction to subclasses as well. 2017-04-01 16:08:19 +02:00
Robert Konrad
ec39647d92 Check for legal lod id
And avoid passing superfluous has_lod parameter.
2017-03-24 09:26:02 +01:00
Robert Konrad
3f74503aca Prefer plain texture2D in legacy es vertex shaders
WebGL supports lod texture funcs only in fragment
shaders but SPIR-V supports only lod texture funcs
in vertex shaders. This reverts calls which were
forced (infered from using a 0 constant) to use
an lod to plain calls in vertex shaders when
using legacy es.
2017-03-23 10:11:45 +01:00
Bill Hollings
6a42051d6a CompilerMSL mark the legacy version of the compile() function as deprecated. 2017-03-22 11:15:08 -04:00
Hans-Kristian Arntzen
61c31c6054 Make use of explicit locations in HLSL. 2017-03-21 13:48:50 +01:00
Bill Hollings
5ad73f33f5 MSL fixes from review of PR 134.
Remove unnecessary use of std:: prefix in spirv_msl.cpp.
Use typedef instead of #define.
spirv-cross deprecate --metal CLI option and replace with --msl option.
2017-03-19 21:06:21 -04:00
Bill Hollings
5550c87b1f CompilerMSL options access and UBO alignment test case.
CompilerMSL accesses options using same design pattern as CompilerGLSL and CompilerHLSL.
CompilerMSL support setting VA & rez binding specs via either constructor or compile() method overload.
CompilerMSL support single UBO packing and padding in single pass.
spriv_cross app (main.cpp) supports turning off UBO packing and padding via command line option.
Add MSL UBO alignment test shader.
2017-03-12 17:42:51 -04:00
Bill Hollings
dc69427402 Updates to MSL functionality to support PR review feedback. 2017-03-11 12:17:22 -05:00
Bill Hollings
a3546ebb54 spirv_msl only add padding structure members if required by member alignment. 2017-03-06 11:00:23 -05:00
Bill Hollings
5cb3ce96a7 spirv_msl pack MSL uniform struct members only when size warrants. 2017-03-02 17:57:26 -08:00
Bill Hollings
b332bae3c3 spirv_msl unpack packed MSL uniform struct members.
spirv_glsl add member_is_packed_type() and unpack_expression_type() functions.
2017-03-01 13:07:40 -05:00
Bill Hollings
484931d8b2 spirv_msl auto-alignment of members of MSL uniform structs.
spirv_msl optionally add padding and packing to allow MSL
struct members to align with SPIR-V struct alignments.
spirv_cross add convenience methods for testing Decorations.
spirv_glsl replace member_decl() function with new emit_stuct_member().
Allow struct member types to be marked as packed via DecorationCPacked decoration.
2017-02-28 21:44:36 -05:00
Hans-Kristian Arntzen
3c58bbbcbe Flatten varying structs outputs in legacy targets. 2017-02-22 20:17:58 +01:00
Hans-Kristian Arntzen
5dd7c04195 Merge branch 'master' of git://github.com/brenwill/SPIRV-Cross into pr-109 2017-02-05 10:59:44 +01:00
Hans-Kristian Arntzen
4ca769b546 Merge branch 'msl_global-invocation-id' of git://github.com/Kangz/SPIRV-Cross into pr-105 2017-02-05 10:14:38 +01:00
Bill Hollings
e4f0dde68f CompilerMSL uses std::set where order matters for consistent regression testing. 2017-01-31 11:02:44 -05:00
Bill Hollings
81757507be CompilerMSL support separate indexed MTLBuffers for stage_in containing matrices.
Add DecorationBinding to Compiler::get_member_decoration()/set_member_decoration().
2017-01-29 13:28:20 -05:00
Bill Hollings
804d5313fa Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2017-01-27 16:12:37 -08:00
Corentin Wallez
789eb432e5 msl: Handle writable SSBO in function arguments 2017-01-26 19:44:33 -05:00
Robert Konrad
4846e081a7 Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross into metalcat
# Conflicts:
#	spirv_msl.cpp
2017-01-26 10:19:26 +01:00
Bill Hollings
948a24a049 Update spirv_msl copyright dates. 2017-01-25 19:33:32 -08:00
Polona Caserman
945494d211 Pass main function name in MSLConfiguration 2017-01-23 13:02:01 +01:00
Polona Caserman
91ccd21fc9 Manage variable names in an unordered map 2017-01-23 13:01:44 +01:00
Bill Hollings
2d0d328f61 Run style formatter. 2017-01-20 11:33:59 -05:00
Bill Hollings
4c198bbce9 Remove emission of function prototypes in MSL.
Do not emit function prototypes. If secondary functions are used,
suppress compiler -Wmissing-prototypes warnings.
Refactor Compiler::emit_function_prototype() functions to simplify.
Rename Compiler_msl::CustomFunctionHandler to OpCodePreprocessor, and
Compiler_msl::register_custom_functions() to preprocess_op_codes()
to perform more generic preprocessing.
Add space between dynamic header lines and fixed header lines.
2017-01-20 11:24:44 -05:00
Polona Caserman
f47305c74d Move vector into the class member 2017-01-16 17:35:48 +01:00
Robert Konrad
a778c363e1 Format code 2017-01-15 16:39:03 +01:00
Polona Caserman
84c3092aba Merge with KhronosGroup/SPIRV-Cross 2017-01-15 16:21:15 +01:00
Polona Caserman
47808ec6f3 Add function global variables 2017-01-15 16:05:15 +01:00
Polona Caserman
5775dcfcc6 Check if a variable has a valid name 2017-01-15 16:05:14 +01:00
Polona Caserman
16834e5832 Sort fragment input variables and vertex output variables alphabetical 2017-01-15 16:05:14 +01:00
Polona Caserman
a496a40f98 Adjust clip-space for Metal 2017-01-15 16:05:13 +01:00
Polona Caserman
5de757621c Set function name 2017-01-15 16:05:12 +01:00
Polona Caserman
989563ad3f Add uniform structure 2017-01-15 16:05:11 +01:00