Commit Graph

310 Commits

Author SHA1 Message Date
Hans-Kristian Arntzen
016b1d86e9 Emit readonly, writeonly for SSBOs. 2017-01-21 10:08:27 +01:00
Hans-Kristian Arntzen
2c7359d1d3 Merge pull request #103 from brenwill/master
Remove emission of function prototypes in MSL.
2017-01-20 20:39:22 +01:00
Bill Hollings
2d0d328f61 Run style formatter. 2017-01-20 11:33:59 -05:00
Bill Hollings
339881468c Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2017-01-20 11:27:05 -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
Hans-Kristian Arntzen
7b9036f402 Fix small oversight in last PR. 2017-01-20 12:06:05 +01:00
Hans-Kristian Arntzen
0a6e0a7b19 Merge pull request #102 from Kangz/msl_writable-ssbo
spirv_msl: Put writable SSBOs in the 'device' address space
2017-01-20 09:22:45 +01:00
Corentin Wallez
b61235ae9f spirv_msl: Put writable SSBOs in the 'device' address space 2017-01-19 10:37:15 -05:00
Hans-Kristian Arntzen
f2d56a4600 Merge pull request #101 from Kangz/fix-cpp11
Fix compilation on some old C++11 standard libraries.
2017-01-19 08:03:23 +01:00
Corentin Wallez
e88c88c310 Fix compilation on some old C++11 standard libraries. 2017-01-18 17:22:54 -05:00
Hans-Kristian Arntzen
250ae11f74 Merge pull request #82 from zeux/flatten-buffer-block
Implement buffer block flattening
2017-01-18 18:48:13 +01:00
Arseny Kapoulkine
62b27f1d81 Implement access chain flattening support for row major matrices
We currently only support access chains that end in a matrix by propagating
"needs transpose" flag upstream which flips the matrix multiplication order.

It's possible to support indexed extraction as well, however it would have to
generate code like this:

    vec4 row = vec4(UBO[0].y, UBO[1].y, UBO[2].y, UBO[3].y);

for a column equivalent of:

    vec4 row = UBO[1];

It is definitely possible to do so but it requires signaling the vector output
that it needs to switch to per-component extraction which is a bit more trouble
than this is worth for now.
2017-01-17 23:26:23 -08:00
Arseny Kapoulkine
1ec6c1a029 Refactor flattened_access_chain functions
Instead of filling a std::string buffer passed by reference return a new
string. This may be slightly slower in certain cases but they are pretty
rare and this matches the code style better.

Also streamline error handling in different branches and extract function
to generate vector swizzle.
2017-01-17 23:26:22 -08:00
Arseny Kapoulkine
c5a821cdbf Minor emit_buffer_block refactoring
Move buffer block variant dispatch into emit_buffer_block to match
emit_push_constant_block, move SSBO check into emit_buffer_block_legacy.
2017-01-17 23:26:20 -08:00
Arseny Kapoulkine
64c17b59e5 Fix whitespace in generated flattened expressions
Add whitespace after comma and around arithmetic operators.
2017-01-17 23:26:19 -08:00
Arseny Kapoulkine
24c66250c7 Add tests for buffer block flattening 2017-01-17 23:26:18 -08:00
Arseny Kapoulkine
0185f0a6b8 Implement buffer block flattening
Legacy GLSL targets do not support uniform buffers, and as such require
some sort of emulation. There are two alternatives - one is to represent
a uniform buffer as a uniform struct, and another one is to flatten it
into an array of primitive vector types (vec4).

Uniform struct have two disadvantages that make using them prohibitive
in some applications:

- The location assignment for struct members is arbitrary which means
the application has to set each struct member one by one
- Some Android drivers fail to link shader programs if both vertex and
fragment shader use the same uniform struct

Because of this, we need to support flattening uniform buffers into an
array. This is not just important for legacy GLSL but also is sometimes
useful for ESSL 3.0 where some Android drivers do not have stable UBO
support.

The way flattening works is the entire buffer is represented as a vec4
array; each access chain is rewritten into a combination of array
accesses, swizzles and data type constructors. Specifically:

- Extracting a vector or a scalar requires indexing into the array with
an optional swizzle, for example CB0[13].yz for reading vec2
- Extracting a matrix or a struct requires extracting each individual
vector or struct member and then combining them into the resulting
object
- Extracting arrays is not supported, mostly because the resulting
construct is very inefficient and ESSL 1.0 does not support array
constructors.

Additionally, while we try to constant-fold each individual indexing
operation, there are cases where we have to use dynamic index
computation (specifically for indexing arrays with non-constants); so
the general form of the primitive array extraction expression is:

buffer[stride0*index0+...+strideN*indexN+offset]

Where stride/offset are integer literals and index represents variables.
2017-01-17 23:26:08 -08:00
Hans-Kristian Arntzen
6198e37f3f Merge pull request #96 from KhronosGroup/transpose-improvement
Legacy GLSL improvements
2017-01-17 20:06:27 +01:00
Hans-Kristian Arntzen
7fe07f9692 Merge pull request #98 from zeux/fix-get-declared-struct-member-size
Fix get_declared_struct_member_size for struct members
2017-01-17 15:05:13 +01:00
Arseny Kapoulkine
f63e7c5c98 Fix get_declared_struct_member_size for struct members
When a member of a struct is a struct, get_declared_struct_member_size
instead returned the size of the entire outer struct because it added
the offset of the last field to the size of the last field.

Restructure the function so that it handles all arrays in the same way
(by using array stride) and for the rest reuses get_declared_struct_size
if possible - this simplifies the function and fixes the issue.
2017-01-17 01:52:12 -08:00
Hans-Kristian Arntzen
41f7e5b6a1 Add ability to have legacy-specific tests. 2017-01-16 09:08:06 +01:00
Hans-Kristian Arntzen
27f4f75513 Run format_all.sh. 2017-01-13 16:32:54 +01:00
Hans-Kristian Arntzen
fadaec205b Improvements to legacy GLSL output.
- By default, emit uniform structs for UBOs, like push constant.
- Forward transpose information,
  and optimize transpose(matrix) * vector to vector * matrix.
2017-01-13 16:31:13 +01:00
Hans-Kristian Arntzen
a3bac9e4ce Merge pull request #95 from KhronosGroup/msvc-maintenance
MSVC maintenance.
2017-01-12 12:23:05 +01:00
Hans-Kristian Arntzen
ce3fe29557 MSVC maintenance. 2017-01-12 10:57:44 +01:00
Hans-Kristian Arntzen
b50513c03a Merge pull request #94 from eoma/fix-locale-independent-float-conversions
Use the classic locale when converting floats to string
2017-01-11 19:17:36 +01:00
Endre Oma
6ad8b307a1 Use the classic locale when converting floats to string 2017-01-11 17:06:06 +01:00
Hans-Kristian Arntzen
4c05b8c3e3 Merge pull request #93 from eoma/fix-glm-swizzle
Switch to GLM_FORCE_SWIZZLE from deprecated GLM_SWIZZLE
2017-01-09 20:53:32 +01:00
Endre Oma
42ca3d9956 Switch to GLM_FORCE_SWIZZLE from deprecated GLM_SWIZZLE 2017-01-09 18:03:54 +01:00
Hans-Kristian Arntzen
81238656ea Merge pull request #91 from brenwill/master
Refactor emit_texture_op() function.
2017-01-08 15:14:56 +01:00
Bill Hollings
4e915e8c48 Run style formatter. 2017-01-08 08:52:57 -05:00
Bill Hollings
4a6358bb9f Add clean_func_name() to support overrides to function names. 2017-01-07 22:15:58 -05:00
Bill Hollings
e6dab816b0 Removed names of unused function parameters. 2017-01-07 15:55:04 -05:00
Bill Hollings
91367799b0 Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2017-01-06 14:13:56 -05:00
Hans-Kristian Arntzen
c7659507e8 Merge pull request #90 from gwihlidal/master
Improve useability of get_decoration and friends.
2017-01-05 23:07:40 +01:00
Graham Wihlidal
2edc350aa1 Remove whitespace 2017-01-05 21:04:42 +01:00
Graham Wihlidal
bcfe2be332 Coding style fix 2017-01-05 21:02:57 +01:00
Graham Wihlidal
9b1ee8f10a Improve fix for boolean decorations queried in get_decoration, added support to get_member_decoration, and updated comments to reflect the change in behavior. 2017-01-05 21:01:49 +01:00
Graham Wihlidal
acd98ac0d5 Fix typo in comment 2017-01-05 21:00:05 +01:00
Graham Wihlidal
a4818f4391 Explicitly truncate (to keep the fprintf easily portable) 2017-01-05 20:51:14 +01:00
Hans-Kristian Arntzen
0338a5c755 Merge pull request #89 from KhronosGroup/nowrite-noread-fix
Fix handling of NoWrite/NoRead decoration for images.
2017-01-05 20:37:59 +01:00
Graham Wihlidal
862a71b4d3 Fix Compiler::get_decoration to correctly return > 0 if DecorationNonWritable or DecorationNonReadable are specified. 2017-01-05 20:19:59 +01:00
Graham Wihlidal
fadc1f9e10 Fix for "error C4146: unary minus operator applied to unsigned type, result still unsigned" 2017-01-05 20:14:53 +01:00
Graham Wihlidal
33bee8a12e Fix for "warning C4267: '=': conversion from 'size_t' to 'uint32_t', possible loss of data" 2017-01-05 20:14:34 +01:00
Hans-Kristian Arntzen
97f7ab865a Fix handling of NoWrite/NoRead decoration for images.
The old workaround for glslang is no longer needed, so only apply workaround
carefully.
2017-01-05 18:16:33 +01:00
Hans-Kristian Arntzen
3576cfb158 Fix warning in MSL. 2017-01-05 18:16:22 +01:00
Bill Hollings
e27a5f7df6 CompilerMSL refactored to simplify handling of vertex attributes.
Combine all vertex attributes into a single stage_in structure.
Remove unneeded structure members from MSLConfiguration, MSLVertexAttr and Meta::Decoration.
Remove unneeded CompilerMSL functions that supported struct offsets and padding.
2017-01-01 14:43:20 -05:00
Bill Hollings
a2b8a0e5c9 Refactor emit_texture_op() function.
CompilerGLSL add to_function_name() and to_function_args() functions to organize
structure of emit_texture_op() function.
CompilerMSL add support for MSL gather(), gather_compare() and sample_compare() functions.
2016-12-28 18:36:42 -05:00
Hans-Kristian Arntzen
c8e2269a78 Merge pull request #87 from brenwill/master
MSL enhancements
2016-12-22 11:22:16 +01:00
Bill Hollings
7d38f1822a CompilerMSL fixes to support pull-request feedback.
Make Compiler::OpcodeHandler and Compiler::traverse_all_reachable_opcodes protected
instead of private, for use by subclasses.
Add CompilerMSL::CustomFunctionHandler and traverse_all_reachable_opcodes() to detect
active opcodes that require the output of a custom function.
CompilerMSL::custom_function_ops use std::set to retain ordering to improve testability.
2016-12-21 16:31:13 -05:00