Граф коммитов

252 Коммитов

Автор SHA1 Сообщение Дата
Hans-Kristian Arntzen acae607703 Register implied expression reads in OpLoad/OpAccessChain.
This is required to avoid relying on complex sub-expression elimination
in compilers, and generates cleaner code.

The problem case is if a complex expression is used in an access chain,
like:

Composite comp = buffer[texture(...)];
vec4 a = comp.a + comp.b + comp.c;

Before, we did not have common subexpression tracking for
OpLoad/OpAccessChain, so we easily ended up with code like:

vec4 a = buffer[texture(...)].a + buffer[texture(...)].b + buffer[texture(...)].c;

A good compiler will optimize this, but we should not rely on it, and
forcing texture(...) to a temporary also looks better.

The solution is to add a vector "implied_expression_reads", which works
similarly to expression_dependencies. We also need an extra mechanism in
to_expression which lets us skip expression read checking and do it
later. E.g. for expr -> access chain -> load, we should only trigger
a read of expr when using the loaded expression.
2019-01-04 14:56:12 +01:00
Hans-Kristian Arntzen 318c17cbb2 Nonfunctional: Update copyright headers for 2019. 2019-01-04 12:38:35 +01:00
Hans-Kristian Arntzen 816c1167ce Handle invariant decoration more robustly.
Avoids certain cases of variance between translation units by forcing
every dependent expression of a store to be temporary.
Should avoid the major failure cases where invariance matters.
2018-11-22 11:55:57 +01:00
Chip Davis ca4744ab72 Support constants of 16-bit integral type in GLSL and MSL.
Constants of 8-bit type aren't supported in GLSL, since there's no
extension letting you use them.
2018-11-02 14:39:55 -05:00
Chip Davis 1fb27b4cda Add support for 8- and 16-bit types to GLSL and MSL.
In GLSL, 8-bit types require GL_EXT_shader_8bit_storage. 16-bit types
can use either GL_AMD_gpu_shader_int16/GL_AMD_gpu_shader_half_float or
GL_EXT_shader_16bit_storage.
2018-11-01 10:20:57 -05:00
Hans-Kristian Arntzen 480acdad18 Deal with OpSpecConstantOp used as array size.
When trying to validate buffer sizes, we usually need to bail out when
using SpecConstantOps, but for some very specific cases where we allow
unsized arrays currently, we can safely allow "unknown" sized arrays as
well.

This is probably the best we can do, when we have even more difficult
cases than this, we throw a more sensible error message.
2018-11-01 14:58:02 +01:00
Hans-Kristian Arntzen 6e99fcf695 Run format_all.sh. 2018-11-01 11:23:48 +01:00
Hans-Kristian Arntzen fd6ff3617a Support macro overrides for spec constants in HLSL. 2018-11-01 11:23:48 +01:00
Grigory Dzhavadyan a5d82d1138 Alter the handling of spec consts in non-Vulkan GLSL
Previously, when generating non-Vulkan GLSL, each use of a spec constant
would be subsituted for its default value and the declaration of the constant
itself would be omitted completely.

This change slightly alters this behavior. The uses of the constant are kept,
as well as the declaration, although the latter is stripped of the layout
qualifier. The declaration is also prepended with the following code:

    #ifndef <constant name>_value
    #define <constant name> <default constant value>
    #endif

and the constant itself now looks like

    const <constant type> <constant name> = <constant name>_value;

The rationale for this change is that it gives the user a way to provide
custom values for specialization constants even when the target does not
support them.
2018-11-01 00:39:09 -07:00
Hans-Kristian Arntzen 5bcf02f7c9 Hoist out parsing module from spirv_cross::Compiler.
This is a large refactor which splits out the SPIR-V parser from
Compiler and moves it into its more appropriately named Parser module.

The Parser is responsible for building a ParsedIR structure which is
then consumed by one or more compilers.

Compiler can take a ParsedIR by value or move reference. This should
allow for optimal case for both multiple compilations and single
compilation scenarios.
2018-10-19 12:01:31 +02:00
Chip Davis 2506046cb4 Merge remote-tracking branch 'origin' into resource-arrays-msl 2018-09-27 10:50:16 -05:00
Hans-Kristian Arntzen c07c303999 Use GL_EXT_samplerless_texture_functions in Vulkan GLSL. 2018-09-27 13:36:38 +02:00
Chip Davis 3a9af9681c MSL: Expand arrays of buffers passed as input.
Even as of Metal 2.1, MSL still doesn't support arrays of buffers
directly. Therefore, we must manually expand them. In the prologue, we
define arrays holding the argument pointers; these arrays are what the
transpiled code ends up referencing. We might be able to do similar
things for textures and samplers prior to MSL 2.0.

Speaking of which, also enable texture arrays on iOS MSL 1.2.
2018-09-26 20:48:09 -05:00
Hans-Kristian Arntzen 3b5968bb26 Deal with switch cases which break out of a loop.
Need some pretty hideous ladder variable system, but high level
languages do not support breaking out of a loop. break in switch blocks
and break in loops alias each other.
2018-09-18 10:50:48 +02:00
Hans-Kristian Arntzen 2f65a1583e MSL: Support array-of-arrays composite construction. 2018-09-12 10:25:51 +02: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
Hans-Kristian Arntzen f6ec83e5d4 GLSL: Allow blocks to have their own namespace. 2018-08-21 11:29:08 +02:00
Hans-Kristian Arntzen 3a268796e2 Deal with loop variable initializers for non-for loops. 2018-08-06 12:52:22 +02: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 d29f48ef06 Deduce constant LUTs from read-write variables. 2018-07-05 13:25:57 +02:00
Hans-Kristian Arntzen e044732896 Support OpTypeImage with depth == 2 (unknown) properly.
Track which OpSampledImages are ever used with Dref opcodes.
2018-07-04 14:26:23 +02:00
Hans-Kristian Arntzen 994f789465
Merge pull request #624 from KhronosGroup/fix-619
Support branch/loop hints in HLSL.
2018-06-25 10:53:52 +02:00
Hans-Kristian Arntzen 33c61d2abe Support branch/loop hints in HLSL. 2018-06-25 10:33:13 +02:00
Hans-Kristian Arntzen ffa9133d77 Support ternary expressions in OpSpecConstantOp. 2018-06-25 09:49:13 +02:00
Hans-Kristian Arntzen d94d20f4f3 Deal with some builtins being declared with wrong signedness. 2018-06-22 11:30:56 +02:00
Hans-Kristian Arntzen b29629fd46 Add support to remove SPIRV_Cross_BaseInstance uniform. 2018-06-22 10:01:38 +02:00
Brad Davis 3a825349bc More cleanup 2018-06-20 09:20:45 -07:00
Brad Davis 6c88b0048b PR feedback 2018-06-20 09:20:45 -07:00
Brad Davis 709d3c60f2 Working on reflection output 2018-06-20 09:20:45 -07:00
Hans-Kristian Arntzen b86bd0a265 Unpack expressions when used in functions on MSL.
OSX 10.14 broke (?) how overload resolution works,
so overloading e.g. dot(float3, packed_float3) no longer works.

Fix this by unpacking expressions before various func ops.
This fix might need to be applied elsewhere, but do so later if needed.
2018-06-11 10:56:45 +02:00
Hans-Kristian Arntzen f65120c147 Deal with packed expressions in more scenarios.
Make a new "to_extract_component_expression" helper.
2018-05-25 10:57:02 +02:00
Hans-Kristian Arntzen 991b655c72 Declare OpSpecConstantOp up-front on relevant targets.
Required, since spec constants can include results from constant ops.
2018-05-15 14:20:16 +02:00
Hans-Kristian Arntzen 85a8f066f4 Do not use RMW rewrite for matrices.
Does not work on MSL.
2018-05-04 10:35:56 +02:00
Hans-Kristian Arntzen 40bbf6be7a Build combined dummy samplers for Query functions without sampler as well.
Deal with various query functions which require dummy sampler.
In SPIR-V, separate images are used, but GLSL (even Vulkan GLSL)
requires combined sampler images ...
2018-04-30 12:08:33 +02:00
Hans-Kristian Arntzen df58debf7a Add support for constexpr samplers in MSL. 2018-04-17 17:43:32 +02:00
Hans-Kristian Arntzen b06c1af9b3 Distinguish between enhanced_layouts and SSO requirements.
Block locations are 440, but non-block are 410 ...
2018-04-17 14:16:27 +02:00
Hans-Kristian Arntzen f6c0e53f58 Start adding Vulkan 1.1 subgroup support to GLSL. 2018-04-10 16:13:33 +02:00
Hans-Kristian Arntzen 694b314f87 Support empty structs.
Need to fake it by pretending it has one dummy member.
2018-04-05 16:26:54 +02:00
Hans-Kristian Arntzen 31a3fdf4ee Decouple public require_extension and the internal use of the function. 2018-04-05 14:43:31 +02:00
Hans-Kristian Arntzen 382101bd05 Run format_all.sh. 2018-04-04 09:26:53 +02:00
Hans-Kristian Arntzen c1947aa447 Update glslang/SPIRV-Tools on Travis. 2018-03-24 04:16:18 +01:00
Hans-Kristian Arntzen 938c7debed Handle control-dependent temporaries.
Derivatives, subgroup and implicit-lod instructions all need to happen
in the block they were created.
2018-03-12 17:34:54 +01: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 8d557d4103 Handle cases where merge selects as also loop merge or continue blocks. 2018-03-08 14:01:10 +01:00
Hans-Kristian Arntzen d9da2db442 Some compat fixes for MSL and Half. 2018-03-06 17:09:18 +01:00
Hans-Kristian Arntzen 91f85d3412 Begin adding float16_t support to GLSL. 2018-03-06 17:09:18 +01:00
Hans-Kristian Arntzen a04bdcc7f7 Handle overloaded functions which share the same OpName.
Awkward, but legal SPIR-V.
2018-02-23 14:15:51 +01:00
Hans-Kristian Arntzen 047ad7df0f Support special float constants (NaN/Inf). 2018-02-23 13:06:20 +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 00ccd590ee Return arrays in HLSL/MSL by writing to an output variable instead. 2018-02-08 12:22:08 +01:00
msiglreith 369f5f657e Add missing include 2018-02-07 15:56:47 +01:00
msiglreith d096f5cafe hlsl: Support custom root constant layout 2018-02-07 15:21:52 +01:00
Hans-Kristian Arntzen 5d9df6a31c Do not declare constant composites inline in HLSL.
Move arrays and structs out to their own global static constants.

Also, replace illegal names in HLSL as well.
2018-02-02 10:12:26 +01:00
Bill Hollings 1c94715350 Update copyright dates to 2018 in main files. 2018-01-31 17:08:43 -05:00
Hans-Kristian Arntzen 09f550f718 Handle exponential explosion of code-gen during first phase of compile.
Certain patterns with OpVectorShuffle (and probably others) will cascade
to so large, that they can cause OOM. After we have observed
force_recompile, don't spend unnecessary memory emitting code which will
never be used.
2018-01-24 18:12:41 +01:00
Hans-Kristian Arntzen 56acf9728a
Merge pull request #406 from KhronosGroup/fix-405
Fix HLSL regression with struct declaration.
2018-01-23 16:54:13 +01:00
Hans-Kristian Arntzen 06041985d0 Fix HLSL regression with struct declaration.
It actually worked surprisingly. Fix it properly.
2018-01-23 16:36:20 +01:00
Hans-Kristian Arntzen d0ce948df4 Do not merge swizzles for anything other than vectors. 2018-01-22 09:52:57 +01:00
Hans-Kristian Arntzen 377c6db480
Merge pull request #398 from KhronosGroup/fix-396
Do not use inline for-loop initializers with different types.
2018-01-17 10:10:01 +01:00
Hans-Kristian Arntzen b902d5400c Do not use inline for-loop initializers with different types. 2018-01-16 10:27:58 +01:00
Hans-Kristian Arntzen bfe6f50b8e Remove cfg_analysis option.
Not using this is broken, and won't work anymore.
2018-01-15 13:21:01 +01:00
Hans-Kristian Arntzen 9c3d4e7c60 Rewrite barrier handling in HLSL. 2018-01-09 12:41:13 +01:00
Hans-Kristian Arntzen 9c72aa00c9 Overhaul barrier handling in GLSL. 2018-01-09 12:07:07 +01:00
Hans-Kristian Arntzen 1a5a755ce5 Flatten structs based on instance name rather than block name.
Block name is too brittle, optimizes will merge block types, making
flattening impossible with unique names.
2018-01-09 10:36:04 +01:00
Hans-Kristian Arntzen f708b497a4 Opt in to gl_in/gl_out handling rather than other way around. 2018-01-09 09:16:33 +01:00
Bill Hollings 27d4af75a0 Revert to not forcing gl_in/gl_out block for MSL, and add MSL gl_ClipDistance tests. 2018-01-08 16:18:34 -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 d8d2da9d8d CompilerMSL allow swizzle of packed_float3 vectors by unpacking to float3.
Pass packed indicator back through OpAccessChain and OpLoad.
Unpack packed vector before applying swizzle.
Add packed swizzle test.
2018-01-05 17:46:56 -05:00
Bill Hollings 8890578d2a CompilerMSL support conversion of non-square row-major matrices. 2018-01-04 16:33:45 -05:00
Bill Hollings 1845f31397 Add option to control use of temp vars for OpVectorShuffle. 2017-12-31 18:55:04 -05:00
Hans-Kristian Arntzen 950732512e Fix compatibility with FXC. 2017-12-12 12:35:22 +01:00
Hans-Kristian Arntzen 2e68675ef7 Support mediump in desktop Vulkan GLSL. 2017-12-06 10:25:58 +01:00
Hans-Kristian Arntzen 2c90ea3acc Improve handling of block name declaration in GLSL.
HLSL UAVs are a bit annoying because they can share block types,
so reflection becomes rather awkward. Sometimes we will need to make
some nasty fallbacks, so add a reflection interface which lets you query
post-shader compile which names was actually declared in the shader.
2017-12-01 14:30:10 +01:00
Hans-Kristian Arntzen 0fd028147f Hoist all phi-local variables to entry block.
We don't have a mechanism to move temporaries to their appropriate
scope, and Phi behavior is weird enough that it will be a heroic effort
to not do this rather ugly codegen :(
2017-11-23 09:50:11 +01:00
Hans-Kristian Arntzen bcdff2d2e1 Fixups for PR #338 review. 2017-11-22 20:51:26 +01:00
Lou Kramer 6671f52334 Add support for new extensions. 2017-11-22 19:05:38 +01:00
Hans-Kristian Arntzen b629ca1c33 Fix complicated Phi case.
A continue block might have used a temporary which existed only in the
loop body.
2017-11-21 09:27:49 +01:00
Bill Hollings e83e2b2217 CompilerMSL support and tests for OpUndef. 2017-11-15 22:44:42 -05:00
Bill Hollings ba865733eb Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2017-11-05 22:49:08 -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
Hans-Kristian Arntzen ab3f114120 Use remap_swizzle for image load-store more actively. 2017-10-24 09:55:25 +02:00
Hans-Kristian Arntzen ae236e7056 Add GroupSync() in HLSL. 2017-10-24 09:55:25 +02:00
Hans-Kristian Arntzen f4d23cd779 Also check IO location for blocks. 2017-10-19 14:17:18 +02:00
Hans-Kristian Arntzen 6feff98295 Update HLSL cbuffer tests. 2017-10-10 15:37:53 +02:00
Hans-Kristian Arntzen f0200bb18d Use packoffset in HLSL.
Rewrite how cbuffers are emitted.
2017-10-10 13:15:49 +02:00
Hans-Kristian Arntzen 6a7b95d2d6 Validate that std140 packing can actually be used. 2017-10-10 10:12:27 +02:00
Hans-Kristian Arntzen 7c58f15928 Run format_all.sh. 2017-09-19 16:09:19 +02:00
Hans-Kristian Arntzen 7064c54820 Various fixes to texture/image query in GLSL. 2017-09-19 16:08:25 +02:00
Hans-Kristian Arntzen 6599a41aad Add option to disable use of 420pack extension. 2017-09-08 09:56:06 +02:00
Hans-Kristian Arntzen 713bd7c2b5 Run format_all.sh. 2017-08-28 09:01:03 +02:00
Hans-Kristian Arntzen 3cbdbec712 Begin implementing ByteAddressBuffer flattening for HLSL. 2017-08-15 09:15:23 +02: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 2abdc135c3 Declare undefined values up front.
They might potentially be used as part of OpStore in the SPIRV-Tools
inliner in some cases.

Implement these as declared variables but without any initializer.
2017-08-02 10:33:03 +02:00
Hans-Kristian Arntzen c8d60914c4 Add support for SampleId/SampleMask/SamplePosition builtins. 2017-07-24 10:07:31 +02:00
Hans-Kristian Arntzen 978901f9e4 Avoid ugly workaround for separate shadow samplers in GLSL/HLSL. 2017-06-17 10:54:59 +02:00
Bill Hollings ba245697f1 Merge branch 'master' of https://github.com/KhronosGroup/SPIRV-Cross 2017-06-01 10:20:00 -04:00