2016-01-07 08:17:16 -05:00
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
Copying //UE4/Dev-Platform to //UE4/Main (Source: //UE4/Dev-Platform @ 3008177)
==========================
MAJOR FEATURES + CHANGES
==========================
Change 2948322 on 2016/04/19 by Nick.Shin
update libwebsockets to v1.7.4
part 4 of 4 - doing this in stages for tracking purposes
#jira UEPLAT-1246 - Update libWebsockets
#jira UEPLAT-1221 - update websocket library
#jira UEPLAT-1204 - Rebuild libwebsockets with SSL
Change 2970016 on 2016/05/07 by Nick.Shin
undo all of the following upgrades:
- zlib
- openssl
- libcurl
- libwebsockets
and reset webrtc
#jira UE-30298 - Fortnite and Orion crash on login
#lockdown josh.adams
Change 2970373 on 2016/05/09 by Lee.Clark
PS4 - Fix NumInstances not getting reset after DrawIndirect calls
Change 2972873 on 2016/05/10 by Michael.Trepka
Correct initial position for SlateViewer windows on Mac
Change 2974363 on 2016/05/11 by Mark.Satterthwaite
Fix invoking buils using distcc from UFE - the command-line executed to access the number of parallel tasks was incorrect.
Change 2975921 on 2016/05/12 by Michael.Trepka
Removed unused AdjustWindowRegion declaration from LinuxWindow.h
#codereview Dmitry.Rekman
Change 2977002 on 2016/05/13 by Michael.Trepka
Make sure dSYM generation action in UBT on Mac does not start before the source dylib is ready
#codereview Ben.Marsh
Change 2977337 on 2016/05/13 by Brent.Pease
UE-27805 - Adding special characters into the BundleDisplayName or BundleName causes packaging error
+ Prevent illegal characters from being entered in the packaging UI
+ Report an error from iPhonePackager if a illegal bundle id is specified
+ Convert special characters to XML equivalents
- Correctly check for the presence of iTunes 12 when packaging iOS games on Windows
- Improve ios certificate and provision message in package settings UI
#codereview peter.sauerbrei
Change 2977509 on 2016/05/13 by Brent.Pease
+ Fix mac compile error
Change 2978036 on 2016/05/14 by Mark.Satterthwaite
One-line tweak that resolves incorrect rendering of the colour LUT because float imprecision allows -ve values to be passed into a call to pow which then generates NaN.
#jira UE-30777
Change 2978037 on 2016/05/14 by Mark.Satterthwaite
Fix a heap-use-after-free bug spotted by AddressSanitizer - you can't assume that the UObject system will be available in ShutdownModule() - on OS X it may have been killed a long time ago.
Change 2978333 on 2016/05/16 by Lee.Clark
Fix packaging of non-code projects when plugins are enabled
#codereview Peter.Sauerbrei
Change 2978780 on 2016/05/16 by Mark.Satterthwaite
Reduce temporary allocations required to set uniform parameters in Metal.
Change 2979680 on 2016/05/16 by Nick.Shin
editor's HTML5 platform settings was missing due to the emscripten SDK move
should have been included with CL: #2946251
Change 2979681 on 2016/05/16 by Nick.Shin
cleaned up websocket processing for HTML5
#jira UE-13657 - HTML5 plugin OnRawRecieve overflow
Change 2979701 on 2016/05/16 by Brent.Pease
UE-28421 - Message box cannot be closed after accessing the home screen on iOS
+ Implement a timeout when waiting for a reply after sending background/foreground/suspend events from the main thread to the game thread. This solves the immediate problem presented in the jira bug report, however, there are deeper issues with the consequences of blocking the game thread that are not addressed. Perhaps structuring the game thread loop to know about modal dialogs so that it can receive these events even when a modal dialog is up could be a better longer term solution
Change 2980766 on 2016/05/17 by Jeremiah.Waldron
Adding Android build support for HarfBuzz
- using a combination of android-cmake (from https://github.com/taka-no-me/android-cmake) to create the build files and Visual Studio 2015 to compile them
- Adding Debug and RelWithDebInfo compiled binaries to harfbuzz-1.2.4/Android/<arch>/<config>
Tested armv7 with TextShapingTest project on a GalaxyNote3 and text showed up correctly
#jira UE-28586
#codereview chris.babcock
Change 2980953 on 2016/05/17 by Jeremiah.Waldron
Changing HarfBuzz build script and libs to use Release instead of RelWithDebInfo
#jira UE-28586
Change 2981039 on 2016/05/17 by Jeff.Campeau
ICMP support disabled for Xbox One and basic address processing wrappers provided (needed for Oodle support)
Change 2981054 on 2016/05/17 by Jeff.Campeau
Enable Live OSS for Orion on Xbox One
Change 2981553 on 2016/05/18 by Jeff.Campeau
Enable Oodle for Xbox One
Change 2981555 on 2016/05/18 by Jeff.Campeau
Scalability settings for Xbox One
Change 2981774 on 2016/05/18 by Keith.Judge
Xbox One - Duplicating Movie Player fix from 4.12.
Change 2981789 on 2016/05/18 by Keith.Judge
Xbox One - Duplicate fast semantics rendertarget unbind/clear/rebind fix from 4.12.
Change 2981802 on 2016/05/18 by Keith.Judge
Xbox One - Duplicate of distance field AO/Shadow fixes from 4.12.
Change 2981875 on 2016/05/18 by Keith.Judge
Xbox One - Dynamic VB/IB refactor. Duplicated from 4.12.
Change 2981900 on 2016/05/18 by Keith.Judge
Xbox One - D3D11Query refactor. Duplicated from 4.12
Change 2981945 on 2016/05/18 by Nick.Shin
filled out response headers for HTML5 platform
#jira UE-26047 - HTML5 HTTP Response Headers not implemented
Change 2981981 on 2016/05/18 by Lee.Clark
PS4 - Fix COTF not updating files
#codereview Daniel.Lamb
Change 2982246 on 2016/05/18 by Michael.Trepka
Fixed Mono compile errors in UT build scripts
Change 2983869 on 2016/05/19 by Mark.Satterthwaite
Explicitly retain/release all the MTLTexture objects in FMetalSurface without the assumptions about them being the same object - the recent stencil & SRV related changes make those assumptions invalid and could lead to over-releasing some textures.
#jira UE-29557
Change 2983871 on 2016/05/19 by Mark.Satterthwaite
Pool Metal texture update buffers to reduce churn.
Change 2983892 on 2016/05/19 by Mark.Satterthwaite
Duplicate 4.12 CL #2972885: Enable Metal resource lifetime delay on all platforms, not just iOS to try and address intermittent invalid resource errors.
Change 2983898 on 2016/05/19 by Mark.Satterthwaite
Duplicate 4.12 CL #2982825: Correctly wait for the dispatch semaphore when clearing the Metal resource free lists.
Change 2983911 on 2016/05/19 by Mark.Satterthwaite
Change Metal SubmitCommandsHint to use an enum of flags rather than boolean variables to control behaviour so that its clearer to the reader what is going to happen.
Change 2983916 on 2016/05/19 by Mark.Satterthwaite
Duplicate 4.12 CL #2974765: Workaround for UE-30069 - on Nvidia Macs we are breaking the GMux swap the second time we run the engine and it isn't clear why, so instead explicitly select the Metal device ourselves and don't allow the OS to swap the GPU driving the display. This will potentially reduce performance a little if the discrete GPU isn't already driving the display but until we know how we are clobbering the GMux/driver it is all we can do. This only applies to 10.11.5 with the default OS X drivers where there is more than one GPU in the system, earlier versions of OS X and the Nvidia WebDrivers are unaffected.
Change 2984874 on 2016/05/20 by Keith.Judge
Xbox One - Re-enable shader DXBC intermediate bytecode stripping, except for geometry and hull shaders where there's a possibility of runtime recompilation in certain combinations. Saves ~2MB in TM-ShaderModels, will save more in larger maps.
#jira UEPLAT-1295
Change 2985446 on 2016/05/20 by Mark.Satterthwaite
Remove the non-functional -metaldebug option from MetalRHI.
Change 2985827 on 2016/05/20 by Nick.Shin
call EndSession() onbeforeunload()
note: API CHANGE
- HTML5JavaScripteFx.{js,h}
- UE_MakeHTTPDataRequest()
#jira UE-22285 - Session End events are not generated for HTML5
Change 2986013 on 2016/05/20 by Jeremiah.Waldron
PR #2387: In-App Purchases - parameters needed for Receipt Validation (Contributed by gameDNAstudio)
Also touches IOS because of added RawPrice member in FInAppPurchaseProductInfo
Pulled from Release-4.12 CL
#jira UE-30782
#codereview chris.babcock, Peter.Sauerbrei
Change 2986057 on 2016/05/20 by Mark.Satterthwaite
Further changes to ensure that UE-30710 really is fixed while also not live-leaking memory in MetalRHI.
Change 2986059 on 2016/05/20 by Mark.Satterthwaite
Move the Metal uniform buffers into the same resource pool as all the other buffers and add stats for how many buffers are in the pool, how much memory is in use, free and wasted (due to aligned-buffer sizes).
Change 2986060 on 2016/05/20 by Mark.Satterthwaite
Disable tiled-reflections on Nvidia & Intel Metal until they sort out the sample command on cube-arrays ignoring the lod level.
Change 2986063 on 2016/05/20 by Mark.Satterthwaite
Missing change from previous CL.
Change 2986066 on 2016/05/20 by Mark.Satterthwaite
More Metal stats tracking the number & memory size of id<MTLBuffer>'s allocated/released each frame.
Change 2986455 on 2016/05/23 by Keith.Judge
Xbox One - Fix precompile promise in shader compiler to not stop subsequent defines from being parsed by D3DCompiler.
Change 2986886 on 2016/05/23 by Mark.Satterthwaite
Duplicate 4.12 CL #2986880: Fix UE-31124 due to bad array iteration logic - amazing that this hadn't been seen earlier.
Change 2986955 on 2016/05/23 by Brent.Pease
+ Do not error out if "[PROJECT_NAME]" is in the bundle ID
#codereview peter.sauerbrei
Change 2987304 on 2016/05/23 by Chris.Babcock
Remove old Android platforms
#ue4
#android
#codeview Josh.Adams
Change 2987571 on 2016/05/23 by Mark.Satterthwaite
Duplicate CL #2967998: Integrate - MaterialParameterCollections now create default resources (uniform buffers) which are used when no valid FScene is present (eg DrawTile while exporting materials to lightmass)
#jira UE-31111
Change 2987591 on 2016/05/23 by Mark.Satterthwaite
Remove usage of MTLRender/ComputeEncoder setSamplerState/s calls that take Min & Max Lod overrides - they currently don't work as expected on some GPU drivers and as we don't use them anywhere and I can't see that we will removing them costs us nothing and fixes tiled reflections on Nvidia with Metal SM5.
Change 2987679 on 2016/05/23 by Mark.Satterthwaite
Re-enable tiled reflections on Nvidia by default now that they work.
Change 2987799 on 2016/05/24 by Mark.Satterthwaite
Add a shader compile option "r.Shaders.ZeroInitialise" that we can turn on to force explicit zero-initialisation of local & temporary variables in hlslcc - so far only implemented for Metal. The default behaviour remains to omit zero-initialisation but the option is helpful to eliminate or track down uninitialised access in shaders that are causing real bugs (e.g. POM material relying on zero-initialised loop counters causing hangs/bad rendering on Mac).
Change 2989395 on 2016/05/25 by Lee.Clark
PS4 - Fix shader output / render target format mismatch for sparse MRT.
Change 2990003 on 2016/05/25 by Jeremiah.Waldron
When creating our own ConfigCacheIni in GetConfigCacheIni_APL, do not assume that the Engine ini was requested. Instead use the baseIniName passed to the function.
Change 2990393 on 2016/05/25 by Mark.Satterthwaite
Back out changelist 2961310 - causes more problems than it solves. DistanceField rendering will still work on Intel Metal SM5 and may work on AMD but will be broken on Nvidia due to a bad access within the compute shader - there's no bounds checking in Metal...
Change 2990516 on 2016/05/25 by Brent.Pease
+ UEPLAT-1294 - Support for local notifications
+ UEPLAT-1254 - Add BP event for device orientation change
+ Added a new class based on UGameInstance for mobile device callbacks
+ Ensured IOSAppDelegate.cpp follows convention for lambda functions
Change 2991361 on 2016/05/26 by Jeremiah.Waldron
Move InAppPurchase class to StoreHelper.java so GooglePlay and Amazon store helpers can use it
Change 2992450 on 2016/05/27 by Mark.Satterthwaite
Optional r.Shaders.BoundsChecking flag to control whether shader platforms should manually enforce buffer access bounds - HLSL returns zero or ignores invalid reads & writes but Metal leaves the behaviour undefined and some drivers then fail. By default this is off and its whatever the native platform behaviour is, enabling it will cost some amount of performance as the shader translator inserts additional instructions to try and match D3D as accurately as possible. This is required to fix GPU restart errors on some Metal drivers when using SM5 rendering features including DistanceField shaders.
Change 2993027 on 2016/05/27 by Mark.Satterthwaite
Fix typo for new CFLAG_BoundsChecking enumeration value.
Change 2993594 on 2016/05/27 by Mark.Satterthwaite
Build fix - check not assert...
Change 2993595 on 2016/05/27 by Mark.Satterthwaite
Fix typo from Xcode hang...
Change 2993614 on 2016/05/28 by Mark.Satterthwaite
At least for now enable shader zero-initialisation and bounds-checking on Mac to ensure that Metal shaders are compiled with semantics that approximate those HLSL assumes. This may cost some performance but will avoid a few GPU restarts on some vendor drivers.
Change 2993747 on 2016/05/28 by Mark.Satterthwaite
Separate texture & buffer references in the Metal backend as they bind to separate arrays in the runtime to avoid giving the side-table buffer an innaccessible binding index. Also the side-table doesn't need to be emitted if no buffer SRV or UAV is used.
Change 2994256 on 2016/05/31 by Lee.Clark
PS4 - Fix unitialized Head Position from HMD tracker when tracking fails. Fixes a problem with A3D audio not working.
#codereview Chad.Taylor,Aaron.McLeran
Change 2994281 on 2016/05/31 by Rolando.Caloca
DP - Allow hlslcc to process type casts containing the 'const' keyword
- it isn't strictly complete as it will simply omit the type qualifier from the cast in the AST but it is sufficient for FortniteFoliage_MasterMaterial to compile.
#codereview Mark.Satterthwaite, Dmitry.Rekman
#jira UE-31411
Change 2994467 on 2016/05/31 by Josh.Adams
Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)
Change 2994493 on 2016/05/31 by Daniel.Lamb
Fixed issue with DDC commandlet not caching things from the startup packages list.
Change 2994644 on 2016/05/31 by Mark.Satterthwaite
Updated hlslcc Mac binaries with fix for UE-31411 which RCO accepted and submitted + script for building parsers on POSIX OSes hooked up to an Xcode scheme in the project.
Change 2996074 on 2016/06/01 by Lee.Clark
PS4 - Fix GS mode not getting disabled when using parallel contexts.
#codereview Marcus.Wassmer
Change 2996129 on 2016/06/01 by Brent.Pease
Manual merge of Pete's dsym generation fix (CL#2996089) from the 4.12 branch.
Change 2996130 on 2016/06/01 by Jeremiah.Waldron
PR #2387 part 2 (Contributed by gameDNAstudio)
Adding ability to consume purchases during GooglePlay RestorePurchases
This also touches IOS due to changes to base classes and function signatures
#codereview chris.babcock, Peter.Sauerbrei
Change 2996441 on 2016/06/01 by Jeremiah.Waldron
Relates to PR #2387: Adding ability to consume purchases during GooglePlay RestorePurchases (Contributed by gameDNAstudio)
Missing changes from part 2 reworked so that there is still only one RestorePurchases function which takes the product IDs and consumable flags. I reflected this in StoreHelper so no casting is necessary in GameActivity and the soon-to-be-added AmazonStoreHelper in the GameCircle plugin will still work dynamically with GameActivity since it will call StoreHelper functionality rather than a GooglePlayStoreHelper specific function.
#codereview chris.babcock
Change 2996514 on 2016/06/01 by Jeff.Campeau
Fix merge issue from main
#jira UE-31502
Change 2996740 on 2016/06/01 by Jonathan.Fitzpatrick
https://jira.ol.epicgames.net/browse/UE-31446
Two PS4 source files fail during unity builds due to name conflict with handleReserveFailed.
Renamed handleReserveFailed to handleReserveFailedLightweight
Change 2997235 on 2016/06/01 by Jeremiah.Waldron
RestorePurchases fix up in Match3 since the new Restore consumable stuff adds an additional pin to the Restore node.
The IAP product in Match3 is non-consumable so just passing an empty array where necessary
Change 2997241 on 2016/06/01 by Jeremiah.Waldron
OnlineSubsystemGameCircle Plugin
- Leaderboards
- Achievements
- Friends
- IAP
- External UI Interface
- Runtime Settings in Project Settings Plugin section when plugin is enabled
- Disabled by default
#jira UEPLAT-105
#codereview chris.babcock
Change 2997618 on 2016/06/02 by Lee.Clark
#UE4Docs: Removed PS4MapFileUtil info
Change 2997840 on 2016/06/02 by Jeremiah.Waldron
Removing trace logging from OnlineSubsystemGameCircle_APL
Change 2998754 on 2016/06/02 by Brent.Pease
Change BlueprintMobileLibrary to BlueprintPlatformLibrary
Change 3000762 on 2016/06/03 by Jeff.Campeau
Add example rating info to ShooterGame
Change 3001037 on 2016/06/04 by Brent.Pease
+ Add ui screens for delegate test, local notification test, and iap test
+ Implement delegate test
Change 3001250 on 2016/06/05 by Brent.Pease
+ Initial pass at IAP test screen
Change 3001639 on 2016/06/06 by Jeff.Campeau
Fix Xbox One build issue with DX12
#codereview Zabir.Hoque
Change 3002574 on 2016/06/06 by Jeremiah.Waldron
Adding Android Install Location to Android platform runtime settings and manifest generation
Change 3002780 on 2016/06/06 by Brent.Pease
+ Initial implementation of local notification test
Change 3003005 on 2016/06/06 by Jeremiah.Waldron
OnlineSubsystemGameCircle plugin - adding setting for Fire TV support. Using that specification in the APL to Add/Update android.hardware.touchscreen feature required attribute
Change 3004392 on 2016/06/07 by Jeremiah.Waldron
Fixing typo in APL comment :)
Change 3005768 on 2016/06/08 by Josh.Adams
Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)
Change 3005929 on 2016/06/08 by Josh.Adams
Merging //UE4/Dev-Main to Dev-Platform (//UE4/Dev-Platform)
Change 3006151 on 2016/06/08 by Peter.Sauerbrei
fix for LocalNotifications not available on TVOS
#lockdown josh.adams
Change 3006183 on 2016/06/08 by Brent.Pease
Manual merge CL#3000242 from Release-4.12 into Dev-Platform
#lockdown josh.adams
Change 3006296 on 2016/06/08 by Peter.Sauerbrei
submit an updated iPhonePackager and support DLLs
#lockdown josh.adams
Change 3006378 on 2016/06/08 by Peter.Sauerbrei
fix for API update to RestorePurchases
#codereview brent.pease
#lockdown josh.adams
#lockdown nick.penwarden
[CL 3008183 by Josh Adams in Main branch]
2016-06-09 17:45:44 -04:00
// .
2014-09-25 14:27:21 -04:00
// This code is largely based on that in ir_print_glsl_visitor.cpp from
// glsl-optimizer.
// https://github.com/aras-p/glsl-optimizer
// The license for glsl-optimizer is reproduced below:
/*
GLSL Optimizer is licensed according to the terms of the MIT license :
Copyright ( C ) 1999 - 2007 Brian Paul All Rights Reserved .
Copyright ( C ) 2010 - 2011 Unity Technologies All Rights Reserved .
Permission is hereby granted , free of charge , to any person obtaining a
copy of this software and associated documentation files ( the " Software " ) ,
to deal in the Software without restriction , including without limitation
the rights to use , copy , modify , merge , publish , distribute , sublicense ,
and / or sell copies of the Software , and to permit persons to whom the
Software is furnished to do so , subject to the following conditions :
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software .
THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS
OR IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL
BRIAN PAUL BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER LIABILITY , WHETHER IN
AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE .
*/
# include "ShaderFormatOpenGL.h"
# include "Core.h"
# include "hlslcc.h"
# include "hlslcc_private.h"
2014-09-25 18:03:18 -04:00
# include "GlslBackend.h"
2014-09-30 18:44:44 -04:00
# include "compiler.h"
2015-04-13 13:43:25 -04:00
PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS
2014-09-30 18:44:44 -04:00
# include "glsl_parser_extras.h"
2015-05-12 17:41:47 -04:00
PRAGMA_ENABLE_SHADOW_VARIABLE_WARNINGS
2015-04-13 13:43:25 -04:00
2014-09-30 18:44:44 -04:00
# include "hash_table.h"
# include "ir_rvalue_visitor.h"
2014-09-25 14:27:21 -04:00
# include "PackUniformBuffers.h"
# include "IRDump.h"
//@todo-rco: Remove STL!
# include <sstream>
//#define OPTIMIZE_ANON_STRUCTURES_OUT
// We can't optimize them out presently, because apparently Windows Radeon
// OpenGL driver chokes on valid GLSL code then.
# if !PLATFORM_WINDOWS
2014-10-01 18:16:34 -04:00
# define _strdup strdup
2014-09-25 14:27:21 -04:00
# endif
2015-12-10 16:56:55 -05:00
static inline FCustomStdString FixHlslName ( const glsl_type * Type )
2014-09-25 14:27:21 -04:00
{
check ( Type - > is_image ( ) | | Type - > is_vector ( ) | | Type - > is_numeric ( ) | | Type - > is_void ( ) | | Type - > is_sampler ( ) | | Type - > is_scalar ( ) ) ;
2015-12-10 16:56:55 -05:00
FCustomStdString Name = Type - > name ;
2014-09-25 14:27:21 -04:00
if ( Type = = glsl_type : : half_type )
{
return " float " ;
}
else if ( Type = = glsl_type : : half2_type )
{
return " vec2 " ;
}
else if ( Type = = glsl_type : : half3_type )
{
return " vec3 " ;
}
else if ( Type = = glsl_type : : half4_type )
{
return " vec4 " ;
}
return Name ;
}
/**
* This table must match the ir_expression_operation enum .
*/
static const char * const GLSLExpressionTable [ ir_opcode_count ] [ 4 ] =
{
{ " (~ " , " ) " , " " , " " } , // ir_unop_bit_not,
{ " not( " , " ) " , " " , " ! " } , // ir_unop_logic_not,
{ " (- " , " ) " , " " , " " } , // ir_unop_neg,
{ " abs( " , " ) " , " " , " " } , // ir_unop_abs,
{ " sign( " , " ) " , " " , " " } , // ir_unop_sign,
{ " (1.0/( " , " )) " , " " , " " } , // ir_unop_rcp,
{ " inversesqrt( " , " ) " , " " , " " } , // ir_unop_rsq,
{ " sqrt( " , " ) " , " " , " " } , // ir_unop_sqrt,
{ " exp( " , " ) " , " " , " " } , // ir_unop_exp, /**< Log base e on gentype */
{ " log( " , " ) " , " " , " " } , // ir_unop_log, /**< Natural log on gentype */
{ " exp2( " , " ) " , " " , " " } , // ir_unop_exp2,
{ " log2( " , " ) " , " " , " " } , // ir_unop_log2,
{ " int( " , " ) " , " " , " " } , // ir_unop_f2i, /**< Float-to-integer conversion. */
{ " float( " , " ) " , " " , " " } , // ir_unop_i2f, /**< Integer-to-float conversion. */
{ " bool( " , " ) " , " " , " " } , // ir_unop_f2b, /**< Float-to-boolean conversion */
{ " float( " , " ) " , " " , " " } , // ir_unop_b2f, /**< Boolean-to-float conversion */
{ " bool( " , " ) " , " " , " " } , // ir_unop_i2b, /**< int-to-boolean conversion */
{ " int( " , " ) " , " " , " " } , // ir_unop_b2i, /**< Boolean-to-int conversion */
{ " uint( " , " ) " , " " , " " } , // ir_unop_b2u,
{ " bool( " , " ) " , " " , " " } , // ir_unop_u2b,
{ " uint( " , " ) " , " " , " " } , // ir_unop_f2u,
{ " float( " , " ) " , " " , " " } , // ir_unop_u2f, /**< Unsigned-to-float conversion. */
{ " uint( " , " ) " , " " , " " } , // ir_unop_i2u, /**< Integer-to-unsigned conversion. */
{ " int( " , " ) " , " " , " " } , // ir_unop_u2i, /**< Unsigned-to-integer conversion. */
{ " int( " , " ) " , " " , " " } , // ir_unop_h2i,
{ " float( " , " ) " , " " , " " } , // ir_unop_i2h,
{ " ( " , " ) " , " " , " " } , // ir_unop_h2f,
{ " ( " , " ) " , " " , " " } , // ir_unop_f2h,
{ " bool( " , " ) " , " " , " " } , // ir_unop_h2b,
{ " float( " , " ) " , " " , " " } , // ir_unop_b2h,
{ " uint( " , " ) " , " " , " " } , // ir_unop_h2u,
{ " uint( " , " ) " , " " , " " } , // ir_unop_u2h,
{ " transpose( " , " ) " , " " , " " } , // ir_unop_transpose
{ " any( " , " ) " , " " , " " } , // ir_unop_any,
{ " all( " , " ) " , " " , " " } , // ir_unop_all,
/**
* \ name Unary floating - point rounding operations .
*/
/*@{*/
{ " trunc( " , " ) " , " " , " " } , // ir_unop_trunc,
{ " ceil( " , " ) " , " " , " " } , // ir_unop_ceil,
{ " floor( " , " ) " , " " , " " } , // ir_unop_floor,
{ " fract( " , " ) " , " " , " " } , // ir_unop_fract,
{ " round( " , " ) " , " " , " " } , // ir_unop_round,
/*@}*/
/**
* \ name Trigonometric operations .
*/
/*@{*/
{ " sin( " , " ) " , " " , " " } , // ir_unop_sin,
{ " cos( " , " ) " , " " , " " } , // ir_unop_cos,
{ " tan( " , " ) " , " " , " " } , // ir_unop_tan,
{ " asin( " , " ) " , " " , " " } , // ir_unop_asin,
{ " acos( " , " ) " , " " , " " } , // ir_unop_acos,
{ " atan( " , " ) " , " " , " " } , // ir_unop_atan,
{ " sinh( " , " ) " , " " , " " } , // ir_unop_sinh,
{ " cosh( " , " ) " , " " , " " } , // ir_unop_cosh,
{ " tanh( " , " ) " , " " , " " } , // ir_unop_tanh,
/*@}*/
/**
* \ name Normalize .
*/
/*@{*/
{ " normalize( " , " ) " , " " , " " } , // ir_unop_normalize,
/*@}*/
/**
* \ name Partial derivatives .
*/
/*@{*/
{ " dFdx( " , " ) " , " " , " " } , // ir_unop_dFdx,
{ " dFdy( " , " ) " , " " , " " } , // ir_unop_dFdy,
/*@}*/
{ " isnan( " , " ) " , " " , " " } , // ir_unop_isnan,
{ " isinf( " , " ) " , " " , " " } , // ir_unop_isinf,
{ " floatBitsToUint( " , " ) " , " " , " " } , // ir_unop_fasu,
{ " floatBitsToInt( " , " ) " , " " , " " } , // ir_unop_fasi,
{ " intBitsToFloat( " , " ) " , " " , " " } , // ir_unop_iasf,
{ " uintBitsToFloat( " , " ) " , " " , " " } , // ir_unop_uasf,
{ " bitfieldReverse( " , " ) " , " " , " " } , // ir_unop_bitreverse,
{ " bitCount( " , " ) " , " " , " " } , // ir_unop_bitcount,
{ " findMSB( " , " ) " , " " , " " } , // ir_unop_msb,
{ " findLSB( " , " ) " , " " , " " } , // ir_unop_lsb,
{ " ERROR_NO_NOISE_FUNCS( " , " ) " , " " , " " } , // ir_unop_noise,
{ " ( " , " + " , " ) " , " " } , // ir_binop_add,
{ " ( " , " - " , " ) " , " " } , // ir_binop_sub,
{ " ( " , " * " , " ) " , " " } , // ir_binop_mul,
{ " ( " , " / " , " ) " , " " } , // ir_binop_div,
/**
* Takes one of two combinations of arguments :
*
* - mod ( vecN , vecN )
* - mod ( vecN , float )
*
* Does not take integer types .
*/
{ " mod( " , " , " , " ) " , " % " } , // ir_binop_mod,
{ " modf( " , " , " , " ) " , " " } , // ir_binop_modf,
{ " step( " , " , " , " ) " , " " } , // ir_binop_step,
/**
* \ name Binary comparison operators which return a boolean vector .
* The type of both operands must be equal .
*/
/*@{*/
{ " lessThan( " , " , " , " ) " , " < " } , // ir_binop_less,
{ " greaterThan( " , " , " , " ) " , " > " } , // ir_binop_greater,
{ " lessThanEqual( " , " , " , " ) " , " <= " } , // ir_binop_lequal,
{ " greaterThanEqual( " , " , " , " ) " , " >= " } , // ir_binop_gequal,
{ " equal( " , " , " , " ) " , " == " } , // ir_binop_equal,
{ " notEqual( " , " , " , " ) " , " != " } , // ir_binop_nequal,
/**
* Returns single boolean for whether all components of operands [ 0 ]
* equal the components of operands [ 1 ] .
*/
{ " ( " , " == " , " ) " , " " } , // ir_binop_all_equal,
/**
* Returns single boolean for whether any component of operands [ 0 ]
* is not equal to the corresponding component of operands [ 1 ] .
*/
{ " ( " , " != " , " ) " , " " } , // ir_binop_any_nequal,
/*@}*/
/**
* \ name Bit - wise binary operations .
*/
/*@{*/
{ " ( " , " << " , " ) " , " " } , // ir_binop_lshift,
{ " ( " , " >> " , " ) " , " " } , // ir_binop_rshift,
{ " ( " , " & " , " ) " , " " } , // ir_binop_bit_and,
{ " ( " , " ^ " , " ) " , " " } , // ir_binop_bit_xor,
{ " ( " , " | " , " ) " , " " } , // ir_binop_bit_or,
/*@}*/
{ " bvec%d(uvec%d( " , " )*uvec%d( " , " )) " , " && " } , // ir_binop_logic_and,
{ " bvec%d(abs(ivec%d( " , " )+ivec%d( " , " ))) " , " ^^ " } , // ir_binop_logic_xor,
{ " bvec%d(uvec%d( " , " )+uvec%d( " , " )) " , " || " } , // ir_binop_logic_or,
{ " dot( " , " , " , " ) " , " " } , // ir_binop_dot,
{ " cross( " , " , " , " ) " , " " } , // ir_binop_cross,
{ " min( " , " , " , " ) " , " " } , // ir_binop_min,
{ " max( " , " , " , " ) " , " " } , // ir_binop_max,
{ " atan( " , " , " , " ) " , " " } ,
{ " pow( " , " , " , " ) " , " " } , // ir_binop_pow,
{ " mix( " , " , " , " , " , " ) " } , // ir_ternop_lerp,
{ " smoothstep( " , " , " , " , " , " ) " } , // ir_ternop_smoothstep,
{ " clamp( " , " , " , " , " , " ) " } , // ir_ternop_clamp,
{ " ERROR_QUADOP_VECTOR( " , " , " , " ) " } , // ir_quadop_vector,
} ;
static const char * OutputStreamTypeStrings [ 4 ] = {
" !invalid! " ,
" points " ,
" line_strip " ,
" triangle_strip "
} ;
static const char * GeometryInputStrings [ 6 ] = {
" !invalid! " ,
" points " ,
" lines " ,
" line_adjacency " ,
" triangles " ,
" triangles_adjacency "
} ;
static const char * DomainStrings [ 4 ] = {
" !invalid! " ,
" triangles " ,
" quads " ,
" isolines " ,
} ;
static const char * PartitioningStrings [ 5 ] = {
" !invalid! " ,
" equal_spacing " ,
" fractional_even_spacing " ,
" fractional_odd_spacing " ,
" pow2 " ,
} ;
static const char * OutputTopologyStrings [ 5 ] = {
" !invalid! " ,
" point_needs_to_be_fixed " ,
" line_needs_to_be_fixed " ,
" cw " ,
" ccw " ,
} ;
static_assert ( ( sizeof ( GLSLExpressionTable ) / sizeof ( GLSLExpressionTable [ 0 ] ) ) = = ir_opcode_count , " GLSLExpressionTableSizeMismatch " ) ;
struct SDMARange
{
unsigned SourceCB ;
unsigned SourceOffset ;
unsigned Size ;
unsigned DestCBIndex ;
unsigned DestCBPrecision ;
unsigned DestOffset ;
bool operator < ( SDMARange const & Other ) const
{
if ( SourceCB = = Other . SourceCB )
{
return SourceOffset < Other . SourceOffset ;
}
return SourceCB < Other . SourceCB ;
}
} ;
typedef std : : list < SDMARange > TDMARangeList ;
typedef std : : map < unsigned , TDMARangeList > TCBDMARangeMap ;
static void InsertRange ( TCBDMARangeMap & CBAllRanges , unsigned SourceCB , unsigned SourceOffset , unsigned Size , unsigned DestCBIndex , unsigned DestCBPrecision , unsigned DestOffset )
{
check ( SourceCB < ( 1 < < 12 ) ) ;
check ( DestCBIndex < ( 1 < < 12 ) ) ;
check ( DestCBPrecision < ( 1 < < 8 ) ) ;
unsigned SourceDestCBKey = ( SourceCB < < 20 ) | ( DestCBIndex < < 8 ) | DestCBPrecision ;
SDMARange Range = { SourceCB , SourceOffset , Size , DestCBIndex , DestCBPrecision , DestOffset } ;
TDMARangeList & CBRanges = CBAllRanges [ SourceDestCBKey ] ;
2016-04-13 12:14:19 -04:00
//printf("* InsertRange: %08x\t%u:%u - %u:%c:%u:%u\n", SourceDestCBKey, SourceCB, SourceOffset, DestCBIndex, DestCBPrecision, DestOffset, Size);
2014-09-25 14:27:21 -04:00
if ( CBRanges . empty ( ) )
{
CBRanges . push_back ( Range ) ;
}
else
{
TDMARangeList : : iterator Prev = CBRanges . end ( ) ;
bool bAdded = false ;
for ( auto Iter = CBRanges . begin ( ) ; Iter ! = CBRanges . end ( ) ; + + Iter )
{
if ( SourceOffset + Size < = Iter - > SourceOffset )
{
if ( Prev = = CBRanges . end ( ) )
{
CBRanges . push_front ( Range ) ;
}
else
{
CBRanges . insert ( Iter , Range ) ;
}
bAdded = true ;
break ;
}
Prev = Iter ;
}
if ( ! bAdded )
{
CBRanges . push_back ( Range ) ;
}
if ( CBRanges . size ( ) > 1 )
{
// Try to merge ranges
bool bDirty = false ;
do
{
bDirty = false ;
TDMARangeList NewCBRanges ;
for ( auto Iter = CBRanges . begin ( ) ; Iter ! = CBRanges . end ( ) ; + + Iter )
{
if ( Iter = = CBRanges . begin ( ) )
{
Prev = CBRanges . begin ( ) ;
}
else
{
if ( Prev - > SourceOffset + Prev - > Size = = Iter - > SourceOffset & & Prev - > DestOffset + Prev - > Size = = Iter - > DestOffset )
{
SDMARange Merged = * Prev ;
Merged . Size = Prev - > Size + Iter - > Size ;
NewCBRanges . pop_back ( ) ;
NewCBRanges . push_back ( Merged ) ;
+ + Iter ;
NewCBRanges . insert ( NewCBRanges . end ( ) , Iter , CBRanges . end ( ) ) ;
bDirty = true ;
break ;
}
}
NewCBRanges . push_back ( * Iter ) ;
Prev = Iter ;
}
CBRanges . swap ( NewCBRanges ) ;
}
while ( bDirty ) ;
}
}
}
static TDMARangeList SortRanges ( TCBDMARangeMap & CBRanges )
{
TDMARangeList Sorted ;
for ( auto & Pair : CBRanges )
{
Sorted . insert ( Sorted . end ( ) , Pair . second . begin ( ) , Pair . second . end ( ) ) ;
}
Sorted . sort ( ) ;
return Sorted ;
}
static void DumpSortedRanges ( TDMARangeList & SortedRanges )
{
printf ( " ********************************** \n " ) ;
for ( auto & o : SortedRanges )
{
2016-04-13 12:14:19 -04:00
printf ( " \t %u:%u - %u:%c:%u:%u \n " , o . SourceCB , o . SourceOffset , o . DestCBIndex , o . DestCBPrecision , o . DestOffset , o . Size ) ;
2014-09-25 14:27:21 -04:00
}
}
2015-07-15 06:39:44 -04:00
// Returns true if the passed 'intrinsic' is used
static bool UsesUEIntrinsic ( exec_list * Instructions , const char * UEIntrinsic )
2014-09-25 14:27:21 -04:00
{
2015-07-15 06:39:44 -04:00
struct SFindUEIntrinsic : public ir_hierarchical_visitor
2014-09-25 14:27:21 -04:00
{
bool bFound ;
2015-07-15 06:39:44 -04:00
const char * UEIntrinsic ;
SFindUEIntrinsic ( const char * InUEIntrinsic ) : bFound ( false ) , UEIntrinsic ( InUEIntrinsic ) { }
2014-09-25 14:27:21 -04:00
virtual ir_visitor_status visit_enter ( ir_call * IR ) override
{
2015-07-15 06:39:44 -04:00
if ( IR - > use_builtin & & ! strcmp ( IR - > callee_name ( ) , UEIntrinsic ) )
2014-09-25 14:27:21 -04:00
{
bFound = true ;
return visit_stop ;
}
return visit_continue ;
}
} ;
2015-07-15 06:39:44 -04:00
SFindUEIntrinsic Visitor ( UEIntrinsic ) ;
2014-09-25 14:27:21 -04:00
Visitor . run ( Instructions ) ;
return Visitor . bFound ;
}
2015-06-25 02:07:29 -04:00
2014-09-25 14:27:21 -04:00
/**
* IR visitor used to generate GLSL . Based on ir_print_visitor .
*/
class ir_gen_glsl_visitor : public ir_visitor
{
/** Track which multi-dimensional arrays are used. */
struct md_array_entry : public exec_node
{
const glsl_type * type ;
} ;
/** Track external variables. */
struct extern_var : public exec_node
{
ir_variable * var ;
explicit extern_var ( ir_variable * in_var ) : var ( in_var ) { }
} ;
/** External variables. */
exec_list input_variables ;
exec_list output_variables ;
exec_list uniform_variables ;
exec_list sampler_variables ;
exec_list image_variables ;
/** Data tied globally to the shader via attributes */
bool early_depth_stencil ;
int wg_size_x ;
int wg_size_y ;
int wg_size_z ;
glsl_tessellation_info tessellation ;
/** Track global instructions. */
struct global_ir : public exec_node
{
ir_instruction * ir ;
explicit global_ir ( ir_instruction * in_ir ) : ir ( in_ir ) { }
} ;
/** Global instructions. */
exec_list global_instructions ;
/** A mapping from ir_variable * -> unique printable names. */
hash_table * printable_names ;
/** Structures required by the code. */
hash_table * used_structures ;
/** Uniform block variables required by the code. */
hash_table * used_uniform_blocks ;
/** Multi-dimensional arrays required by the code. */
exec_list used_md_arrays ;
// Code generation flags
bool bIsES ;
2015-06-18 14:24:11 -04:00
bool bEmitPrecision ;
2015-06-19 19:28:40 -04:00
bool bIsES31 ;
2014-09-25 14:27:21 -04:00
_mesa_glsl_parser_targets ShaderTarget ;
bool bGenerateLayoutLocations ;
2016-06-13 12:20:22 -04:00
bool bDefaultPrecisionIsHalf ;
2014-09-25 14:27:21 -04:00
/** Memory context within which to make allocations. */
void * mem_ctx ;
/** Buffer to which GLSL source is being generated. */
char * * buffer ;
/** Indentation level. */
int indentation ;
/** Scope depth. */
int scope_depth ;
/** The number of temporary variables declared in the current scope. */
int temp_id ;
/** The number of global variables declared. */
int global_id ;
/** Whether a semicolon must be printed before the next EOL. */
bool needs_semicolon ;
/**
* Whether uint literals should be printed as int literals . This is a hack
* because glCompileShader crashes on Mac OS X with code like this :
* foo = bar [ 0u ] ;
*/
bool should_print_uint_literals_as_ints ;
/** number of loops in the generated code */
int loop_count ;
/** Whether the shader being cross compiled needs EXT_shader_texture_lod. */
bool bUsesES2TextureLODExtension ;
// Found dFdx or dFdy
bool bUsesDXDY ;
2015-12-09 15:04:15 -05:00
// Uses gl_InstanceID
bool bUsesInstanceID ;
2014-09-25 14:27:21 -04:00
/**
* Return true if the type is a multi - dimensional array . Also , track the
* array .
*/
bool is_md_array ( const glsl_type * type )
{
if ( type - > base_type = = GLSL_TYPE_ARRAY & &
type - > fields . array - > base_type = = GLSL_TYPE_ARRAY )
{
foreach_iter ( exec_list_iterator , iter , used_md_arrays )
{
md_array_entry * entry = ( md_array_entry * ) iter . get ( ) ;
if ( entry - > type = = type )
return true ;
}
md_array_entry * entry = new ( mem_ctx ) md_array_entry ( ) ;
entry - > type = type ;
used_md_arrays . push_tail ( entry ) ;
return true ;
}
return false ;
}
/**
* Fetch / generate a unique name for ir_variable .
*
* GLSL IR permits multiple ir_variables to share the same name . This works
* fine until we try to print it , when we really need a unique one .
*/
const char * unique_name ( ir_variable * var )
{
if ( var - > mode = = ir_var_temporary | | var - > mode = = ir_var_auto )
{
/* Do we already have a name for this variable? */
const char * name = ( const char * ) hash_table_find ( this - > printable_names , var ) ;
if ( name = = NULL )
{
2015-03-20 16:18:49 -04:00
bool bIsGlobal = ( scope_depth = = 0 & & var - > mode ! = ir_var_temporary ) ;
const char * prefix = " g " ;
if ( ! bIsGlobal )
{
if ( var - > type - > is_matrix ( ) )
{
prefix = " m " ;
}
else if ( var - > type - > is_vector ( ) )
{
prefix = " v " ;
}
else
{
switch ( var - > type - > base_type )
{
case GLSL_TYPE_BOOL : prefix = " b " ; break ;
case GLSL_TYPE_UINT : prefix = " u " ; break ;
case GLSL_TYPE_INT : prefix = " i " ; break ;
case GLSL_TYPE_HALF : prefix = " h " ; break ;
case GLSL_TYPE_FLOAT : prefix = " f " ; break ;
default : prefix = " t " ; break ;
}
}
}
int var_id = bIsGlobal ? global_id + + : temp_id + + ;
2014-09-25 14:27:21 -04:00
name = ralloc_asprintf ( mem_ctx , " %s%d " , prefix , var_id ) ;
hash_table_insert ( this - > printable_names , ( void * ) name , var ) ;
}
return name ;
}
/* If there's no conflict, just use the original name */
return var - > name ;
}
/**
* Add tabs / spaces for the current indentation level .
*/
void indent ( void )
{
for ( int i = 0 ; i < indentation ; i + + )
{
ralloc_asprintf_append ( buffer , " \t " ) ;
}
}
/**
* Print out the internal name for a multi - dimensional array .
*/
void print_md_array_type ( const glsl_type * t )
{
if ( t - > base_type = = GLSL_TYPE_ARRAY )
{
ralloc_asprintf_append ( buffer , " _mdarr_ " ) ;
do
{
2016-04-13 12:14:19 -04:00
ralloc_asprintf_append ( buffer , " %u_ " , t - > length ) ;
2014-09-25 14:27:21 -04:00
t = t - > fields . array ;
} while ( t - > base_type = = GLSL_TYPE_ARRAY ) ;
print_base_type ( t ) ;
}
}
/**
* Print the base type , e . g . vec3 .
*/
void print_base_type ( const glsl_type * t )
{
if ( t - > base_type = = GLSL_TYPE_ARRAY )
{
print_base_type ( t - > fields . array ) ;
}
else if ( t - > base_type = = GLSL_TYPE_INPUTPATCH )
{
ralloc_asprintf_append ( buffer , " /* %s */ " , t - > name ) ;
print_base_type ( t - > inner_type ) ;
}
else if ( t - > base_type = = GLSL_TYPE_OUTPUTPATCH )
{
ralloc_asprintf_append ( buffer , " /* %s */ " , t - > name ) ;
print_base_type ( t - > inner_type ) ;
}
else if ( ( t - > base_type = = GLSL_TYPE_STRUCT )
& & ( strncmp ( " gl_ " , t - > name , 3 ) ! = 0 ) )
{
ralloc_asprintf_append ( buffer , " %s " , t - > name ) ;
}
else
{
2015-12-10 16:56:55 -05:00
FCustomStdString Name = FixHlslName ( t ) ;
2014-09-25 14:27:21 -04:00
ralloc_asprintf_append ( buffer , " %s " , Name . c_str ( ) ) ;
}
}
/**
* Print the portion of the type that appears before a variable declaration .
*/
void print_type_pre ( const glsl_type * t )
{
if ( is_md_array ( t ) )
{
print_md_array_type ( t ) ;
}
else
{
print_base_type ( t ) ;
}
}
/**
* Print the portion of the type that appears after a variable declaration .
*/
void print_type_post ( const glsl_type * t , bool is_unsized = false )
{
if ( t - > base_type = = GLSL_TYPE_ARRAY & & ! is_md_array ( t ) )
{
if ( is_unsized )
{
ralloc_asprintf_append ( buffer , " [] " ) ;
}
else
{
ralloc_asprintf_append ( buffer , " [%u] " , t - > length ) ;
}
}
else if ( t - > base_type = = GLSL_TYPE_INPUTPATCH | | t - > base_type = = GLSL_TYPE_OUTPUTPATCH )
{
ralloc_asprintf_append ( buffer , " [%u] /* %s */ " , t - > patch_length , t - > name ) ;
}
}
/**
* Print a full variable declaration .
*/
void print_type_full ( const glsl_type * t )
{
print_type_pre ( t ) ;
print_type_post ( t ) ;
}
/**
* Visit a single instruction . Appends a semicolon and EOL if needed .
*/
void do_visit ( ir_instruction * ir )
{
needs_semicolon = true ;
ir - > accept ( this ) ;
if ( needs_semicolon )
{
ralloc_asprintf_append ( buffer , " ; \n " ) ;
}
}
2015-07-08 22:20:29 -04:00
enum EPrecisionModifier
{
GLSL_PRECISION_DEFAULT ,
GLSL_PRECISION_LOWP ,
GLSL_PRECISION_MEDIUMP ,
GLSL_PRECISION_HIGHP ,
} ;
EPrecisionModifier GetPrecisionModifier ( const struct glsl_type * type )
{
if ( type - > is_sampler ( ) | | type - > is_image ( ) )
{
2016-06-13 12:20:22 -04:00
if ( bDefaultPrecisionIsHalf & & type - > inner_type - > base_type = = GLSL_TYPE_FLOAT )
2015-07-08 22:20:29 -04:00
{
return GLSL_PRECISION_HIGHP ;
}
2016-06-13 12:20:22 -04:00
else if ( ! bDefaultPrecisionIsHalf & & type - > inner_type - > base_type = = GLSL_TYPE_HALF )
2015-07-08 22:20:29 -04:00
{
return GLSL_PRECISION_MEDIUMP ;
}
else // shadow samplers, integer textures etc
{
return GLSL_PRECISION_HIGHP ;
}
}
2016-06-13 12:20:22 -04:00
else if ( bDefaultPrecisionIsHalf & & ( type - > base_type = = GLSL_TYPE_FLOAT | | ( type - > is_array ( ) & & type - > element_type ( ) - > base_type = = GLSL_TYPE_FLOAT ) ) )
2015-07-08 22:20:29 -04:00
{
return GLSL_PRECISION_HIGHP ;
}
2016-06-13 12:20:22 -04:00
else if ( ! bDefaultPrecisionIsHalf & & ( type - > base_type = = GLSL_TYPE_HALF | | ( type - > is_array ( ) & & type - > element_type ( ) - > base_type = = GLSL_TYPE_HALF ) ) )
2015-07-08 22:20:29 -04:00
{
return GLSL_PRECISION_MEDIUMP ;
}
else if ( type - > is_integer ( ) )
{
return GLSL_PRECISION_HIGHP ;
}
return GLSL_PRECISION_DEFAULT ;
}
2015-07-09 02:21:05 -04:00
void AppendPrecisionModifier ( char * * inBuffer , EPrecisionModifier PrecisionModifier )
2015-07-08 22:20:29 -04:00
{
switch ( PrecisionModifier )
{
case GLSL_PRECISION_LOWP :
2015-07-09 02:21:05 -04:00
ralloc_asprintf_append ( inBuffer , " lowp " ) ;
2015-07-08 22:20:29 -04:00
break ;
case GLSL_PRECISION_MEDIUMP :
2015-07-09 02:21:05 -04:00
ralloc_asprintf_append ( inBuffer , " mediump " ) ;
2015-07-08 22:20:29 -04:00
break ;
case GLSL_PRECISION_HIGHP :
2015-07-09 02:21:05 -04:00
ralloc_asprintf_append ( inBuffer , " highp " ) ;
2015-07-08 22:20:29 -04:00
break ;
case GLSL_PRECISION_DEFAULT :
break ;
default :
// we missed a type
check ( false ) ;
}
}
2014-09-25 14:27:21 -04:00
/**
* \ name Visit methods
*
* As typical for the visitor pattern , there must be one \ c visit method for
* each concrete subclass of \ c ir_instruction . Virtual base classes within
* the hierarchy should not have \ c visit methods .
*/
virtual void visit ( ir_rvalue * rvalue )
{
check ( 0 & & " ir_rvalue not handled for GLSL export. " ) ;
}
virtual void visit ( ir_variable * var )
{
const char * const centroid_str [ ] = { " " , " centroid " } ;
const char * const invariant_str [ ] = { " " , " invariant " } ;
const char * const patch_constant_str [ ] = { " " , " patch " } ;
const char * const GLSLmode_str [ ] = { " " , " uniform " , " in " , " out " , " inout " , " in " , " " , " shared " , " " , " " , " uniform_ref " } ;
const char * const ESVSmode_str [ ] = { " " , " uniform " , " attribute " , " varying " , " inout " , " in " , " " , " shared " } ;
const char * const ESFSmode_str [ ] = { " " , " uniform " , " varying " , " attribute " , " " , " in " , " " , " shared " } ;
2015-12-09 15:04:15 -05:00
const char * const GLSLinterp_str [ ] = { " " , " smooth " , " flat " , " noperspective " } ;
const char * const ESinterp_str [ ] = { " " , " " , " " , " " } ;
2014-09-25 14:27:21 -04:00
const char * const layout_str [ ] = { " " , " layout(origin_upper_left) " , " layout(pixel_center_integer) " , " layout(origin_upper_left,pixel_center_integer) " } ;
const char * const * mode_str = bIsES ? ( ( ShaderTarget = = vertex_shader ) ? ESVSmode_str : ESFSmode_str ) : GLSLmode_str ;
2015-12-09 15:04:15 -05:00
const char * const * interp_str = bIsES ? ESinterp_str : GLSLinterp_str ;
2014-09-25 14:27:21 -04:00
// Check for an initialized const variable
// If var is read-only and initialized, set it up as an initialized const
bool constInit = false ;
if ( var - > has_initializer & & var - > read_only & & ( var - > constant_initializer | | var - > constant_value ) )
{
ralloc_asprintf_append ( buffer , " const " ) ;
constInit = true ;
}
if ( scope_depth = = 0 )
{
glsl_base_type base_type = var - > type - > base_type ;
if ( base_type = = GLSL_TYPE_ARRAY )
{
base_type = var - > type - > fields . array - > base_type ;
}
if ( var - > mode = = ir_var_in )
{
input_variables . push_tail ( new ( mem_ctx ) extern_var ( var ) ) ;
}
else if ( var - > mode = = ir_var_out )
{
output_variables . push_tail ( new ( mem_ctx ) extern_var ( var ) ) ;
}
else if ( var - > mode = = ir_var_uniform & & var - > type - > is_sampler ( ) )
{
sampler_variables . push_tail ( new ( mem_ctx ) extern_var ( var ) ) ;
}
else if ( var - > mode = = ir_var_uniform & & var - > type - > is_image ( ) )
{
image_variables . push_tail ( new ( mem_ctx ) extern_var ( var ) ) ;
}
else if ( var - > mode = = ir_var_uniform & & base_type = = GLSL_TYPE_SAMPLER_STATE )
{
// ignore sampler state uniforms
}
else if ( var - > mode = = ir_var_uniform & & var - > semantic = = NULL )
{
uniform_variables . push_tail ( new ( mem_ctx ) extern_var ( var ) ) ;
}
}
2015-12-09 15:04:15 -05:00
const bool bBuiltinVariable = ( var - > name & & strncmp ( var - > name , " gl_ " , 3 ) = = 0 ) ;
if ( bBuiltinVariable & & ShaderTarget = = vertex_shader & & strncmp ( var - > name , " gl_InstanceID " , 13 ) = = 0 )
{
bUsesInstanceID = true ;
}
if ( bBuiltinVariable & &
2014-09-25 14:27:21 -04:00
var - > centroid = = 0 & & var - > interpolation = = 0 & &
var - > invariant = = 0 & & var - > origin_upper_left = = 0 & &
var - > pixel_center_integer = = 0 )
{
// Don't emit builtin GL variable declarations.
needs_semicolon = false ;
}
else if ( scope_depth = = 0 & & var - > mode = = ir_var_temporary )
{
global_instructions . push_tail ( new ( mem_ctx ) global_ir ( var ) ) ;
needs_semicolon = false ;
}
else
{
int layout_bits =
( var - > origin_upper_left ? 0x1 : 0 ) |
( var - > pixel_center_integer ? 0x2 : 0 ) ;
2015-02-06 11:35:30 -05:00
2014-09-25 14:27:21 -04:00
if ( scope_depth = = 0 & &
( ( var - > mode = = ir_var_in ) | | ( var - > mode = = ir_var_out ) ) & &
var - > is_interface_block )
{
/**
Hack to display our fake structs as what they are supposed to be - interface blocks
' in ' or ' out ' variable qualifier becomes interface block declaration start ,
structure name becomes block name ,
we add information about block contents , taking type from sole struct member type , and
struct variable name becomes block instance name .
Note : With tessellation , matching interfaces between shaders is tricky , so we need
to assign explicit locations to shader input and output variables .
The reason we use a struct instead of an interface block is that with
GL4 .2 / GL_ARB_separate_shader_objects , you can add a layout ( location = foo ) to a variable
that is not part of an interface block . However , in order to add a location to a variable
inside an interface block , you need GL4 .4 / GL_enhanced_layouts . Since for now , we don ' t want
that dependency , we use structs .
*/
2015-02-06 11:35:30 -05:00
if ( bGenerateLayoutLocations & & var - > explicit_location & & var - > is_patch_constant = = 0 )
2014-09-25 14:27:21 -04:00
{
check ( layout_bits = = 0 ) ;
Copying //UE4/Dev-Mobile to //UE4/Main (Source: //UE4/Dev-Mobile @ 2945914)
==========================
MAJOR FEATURES + CHANGES
==========================
Change 2911743 on 2016/03/16 by Allan.Bentham
Fix broken tonemapper when using 32bpp encoded HDR. Fixes UE-28359
Cleaned up some ronin integration hacks from ronin.
Change 2912053 on 2016/03/16 by Peter.Sauerbrei
disable Vulkan in Win32 builds for now
#codereview rolando.caloca
#jira UE-28465
Change 2914512 on 2016/03/18 by Dmitriy.Dyomin
Fixed crash on Nexus5 with Android 4.4.2 when TonemapperFilm is enabled
Change 2914944 on 2016/03/18 by Allan.Bentham
Fix es2 tonemap flip. Fixes UE-25148
Change 2915248 on 2016/03/18 by Chris.Babcock
Updates to support NDK r11
#jira UE-28529
#ue4
#android
Change 2919192 on 2016/03/22 by Chris.Babcock
NDK level set above 19 forces minSdkVersion to 21 or above to prevent installing on unsupported devices
#jira UE-28408
#ue4
#android
#codereview Jack.Porter
Change 2919591 on 2016/03/23 by Allan.Bentham
Merge ronin's Gaussian DoF to 4.11's dof changes.
Gaussian DoF will use a single recombine pass with ES31 devices or if no separate translucency is used on SM4+.
Added permutation to exclude separate translucency from Gaussian recombine shader when not in use.
#codereview martin.mittring
Change 2920758 on 2016/03/24 by Dmitriy.Dyomin
Fixed: shifting lighting samples octree
https://udn.unrealengine.com/questions/276026/lighting-samples-visualization-not-working-with-le.html
Change 2920793 on 2016/03/24 by Dmitriy.Dyomin
Fixed: When sub-level set to be unloaded but with visbility state set to true, ULevelStreaming::IsStreamingStatePending returns wrong value
#jira UE-26426
Change 2920981 on 2016/03/24 by Dmitriy.Dyomin
GPU particles support for iOS Metal (A8+ only)
#jira UE-11067
#jira UE-28514
#codereview Jack.Porter
Change 2921383 on 2016/03/24 by Allan.Bentham
Fix inverted image on device when framebuffer fetch/bViewRectSource is not used.
#codereview jack.porter
Change 2925694 on 2016/03/29 by Dmitriy.Dyomin
Fixed: GPU particles and bloom on S7 Mali
Change 2927065 on 2016/03/29 by Chris.Babcock
Set the DT_SONAME field in linker (stops warning toast)
#ue4
#android
#codereview Jack.Porter
Change 2927375 on 2016/03/30 by Jack.Porter
Fixed localization for placement mode Cube, Sphere, Cylinder and Cone
Change 2928643 on 2016/03/30 by Jack.Porter
Fixed bug introdued by Ronin merge with DepthOfFieldScale setting being locked for BokehDOF
#code_review: allan.bentham
Change 2932773 on 2016/04/04 by Jack.Porter
Reapply android Vulkan version fixes
Change 2932853 on 2016/04/05 by Jack.Porter
Enable VULKAN_CLEAR_SURFACE_ON_CREATE on Android to prevent assertion
Change 2932998 on 2016/04/05 by Jack.Porter
Native web browser widget on iOS
#jira UEMOB-20
Change 2933420 on 2016/04/05 by Chris.Babcock
Removed hard-coded bUseUnityBuild in UBT for Android (contributed by kosz78)
#jira UE-29066
#pr #2236
#ue4
#android
Change 2934315 on 2016/04/05 by Chris.Babcock
Allow Android to act as server with OnlineSubsystemNull (contributed by psychogony)
#jira UE-23937
#PR #1820
#ue4
#android
#codereview Ryan.Gerleve
Change 2935038 on 2016/04/06 by Chris.Babcock
Fix OpenGLES31 compile error
#ue4
#android
#codereview Jack.Porter
Change 2936288 on 2016/04/07 by Allan.Bentham
Planar reflection captures for mobile. (UE-27426)
Added mobile planar reflection flag to material.
#codereview jack.porter, daniel.wright
Change 2936297 on 2016/04/07 by Allan.Bentham
Missed file. Planar reflection captures for mobile. (UE-27426)
#codereview jack.porter, daniel.wright
Change 2937763 on 2016/04/08 by Dmitriy.Dyomin
Fix InstancedStaticMesh batches for ES2 (contributed by Grimmick)
GitHub #2031
#jira UE-26576
#codereview Jack.Porter
Change 2937863 on 2016/04/08 by Jack.Porter
Merged Ronin CLs 2840392, 2860028
Allow vertex texture fetches on ES2 (requires absolute mip level)
Change 2938461 on 2016/04/08 by Chris.Babcock
Write Android uninstall batch files
#ue4
#android
Change 2939679 on 2016/04/11 by Allan.Bentham
Remove bStationaryLightUsesCSMForMovableShadows from light component's UI.
renamed proxy equivalent and infer its state from Inset Shadows For Movable Objects
#codereview jack.porter, daniel.wright
Change 2939887 on 2016/04/11 by Chris.Babcock
Android ARM64 libraries
#jira UEPLAT-1268
#ue4
#android
Change 2940125 on 2016/04/11 by Chris.Babcock
Added requirements to Arm64 and x86_64 tooltips
Change 2941051 on 2016/04/12 by Allan.Bentham
Fix for inverted RG channels when using filmic tonemapper with ES2.
#codereview jack.porter
Change 2942523 on 2016/04/13 by Chris.Babcock
Add cxa_demangle build.cs instead of hiding dependency in UEBuildAndroid.cs
#ue4
#android
#codereview Josh.Adams
Change 2942578 on 2016/04/13 by Chris.Babcock
Add cxademangle dependency to Core for Android
#ue4
#android
#codereview Josh.Adams
Change 2942997 on 2016/04/13 by Chris.Babcock
Run Ant with -quiet first and run again without if there is an error for the log
#ue4
#android
#codereview Josh.Adams
Change 2943320 on 2016/04/14 by Jack.Porter
Fixed planar reflection merge errors
Change 2943352 on 2016/04/14 by Jack.Porter
Fix NAME_VULKAN_ES3_1_ANDROID shader format name
#codereview: Rolando.Coloca
Change 2943367 on 2016/04/14 by Dmitriy.Dyomin
Added cvars to add or strip specific GL extensions from a driver reported extensions string
#jira UE-29467
Change 2943425 on 2016/04/14 by Dmitriy.Dyomin
Better logging of MobileHDR mode
Change 2943461 on 2016/04/14 by Dmitriy.Dyomin
Fixing HDR rendering and bloom on Galaxy S7
Change 2943493 on 2016/04/14 by Dmitriy.Dyomin
Better HDR fix for devices with ES3 support
Change 2943855 on 2016/04/14 by Allan.Bentham
Mobile planar reflections.
- currently only supports opaque materials
#codereview jack.porter
Change 2944721 on 2016/04/14 by Chris.Babcock
Allow Vulkan-only Android builds
#ue4
#android
#codereview Allan.Bentham,Jack.Porter
Change 2944771 on 2016/04/14 by Dmitriy.Dyomin
Fixed: mesh particles crash in ES2
Change 2944827 on 2016/04/15 by Dmitriy.Dyomin
Fixed: GPU particles not working on S6 with Android 6.0.1
Change 2944836 on 2016/04/15 by Jack.Porter
Disable FX system calls in forward renderer when particles showflag is off
Change 2944840 on 2016/04/15 by Jack.Porter
Re-enabled non-radial TDeferredLightVS on ES2 for planar and put #if FEATURE_LEVEL >= FEATURE_LEVEL_SM4 around the radial shader code which was tripping up ES2.
#codereview: Allan.Bentham, Chris.Babcock, Daniel.Wright
Change 2944914 on 2016/04/15 by Jack.Porter
Device profiles to detect Galaxy S7 Mali and Adreno variants in Vulkan mode
Change 2945020 on 2016/04/15 by Gareth.Martin
Cloning changes across from Dev-Landscape to Dev-Mobile due to feature deadline for 4.12.
Change 2943560 on 2016/04/14 by Gareth.Martin
Added ability to expand landscape bounds
#jira UE-28928
#jira UE-25230
Change 2943538 on 2016/04/14 by Gareth.Martin
Fix a crash with saving a level >2GB in size.
There may still be other crashes with >2GB levels.
Change 2943477 on 2016/04/14 by Gareth.Martin
Fixed LODFalloff setting on landscape getting reset when using the "Change Landscape Component Size" tool
Also moved all the LOD settings together in LandscapeProxy.h because it was messy
Change 2942113 on 2016/04/13 by Gareth.Martin
Updating comment to clarify behaviour of Foliage Align-To-Normal when Random-Yaw is disabled.
Change 2941030 on 2016/04/12 by Gareth.Martin
Cleanup and commenting
Change 2940994 on 2016/04/12 by Gareth.Martin
Implement random scale option for Landscape Grass.
#jira UE-25743
Change 2940993 on 2016/04/12 by Gareth.Martin
Remove unused BuildFlatTree function from HierarchicalInstancedStaticMeshComponent
Change 2940150 on 2016/04/11 by Gareth.Martin
Harden UHierarchicalInstancedStaticMeshComponent::UpdateInstanceTransform
Change 2940101 on 2016/04/11 by Gareth.Martin
Additional checks for bad static mesh when building the HISMC tree
Change 2945560 on 2016/04/15 by Rolando.Caloca
DM - Fix for newer Vulkan sdks
Change 2945638 on 2016/04/15 by Chris.Babcock
Fix permissions on uninstall script on Mac
#jira UE-29236
#ue4
#android
#lockdown Jack.Porter
Change 2945856 on 2016/04/15 by Rolando.Caloca
DM - vk - Fix mapped allocations on mobile
#lockdown nick.penwarden
[CL 2945995 by Chris Babcock in Main branch]
2016-04-15 18:19:26 -04:00
// Some devices (S6 G920L 6.0.1) may complain about second empty parameter in an INTERFACE_BLOCK macro
// Make sure we put something there
const char * interp_qualifier = interp_str [ var - > interpolation ] ;
if ( bIsES31 & & strlen ( interp_qualifier ) = = 0 )
{
interp_qualifier = " smooth " ;
}
2014-09-25 14:27:21 -04:00
ralloc_asprintf_append (
buffer ,
2015-02-06 11:35:30 -05:00
" INTERFACE_BLOCK(%d, %s, %s%s%s%s, " ,
2014-09-25 14:27:21 -04:00
var - > location ,
Copying //UE4/Dev-Mobile to //UE4/Main (Source: //UE4/Dev-Mobile @ 2945914)
==========================
MAJOR FEATURES + CHANGES
==========================
Change 2911743 on 2016/03/16 by Allan.Bentham
Fix broken tonemapper when using 32bpp encoded HDR. Fixes UE-28359
Cleaned up some ronin integration hacks from ronin.
Change 2912053 on 2016/03/16 by Peter.Sauerbrei
disable Vulkan in Win32 builds for now
#codereview rolando.caloca
#jira UE-28465
Change 2914512 on 2016/03/18 by Dmitriy.Dyomin
Fixed crash on Nexus5 with Android 4.4.2 when TonemapperFilm is enabled
Change 2914944 on 2016/03/18 by Allan.Bentham
Fix es2 tonemap flip. Fixes UE-25148
Change 2915248 on 2016/03/18 by Chris.Babcock
Updates to support NDK r11
#jira UE-28529
#ue4
#android
Change 2919192 on 2016/03/22 by Chris.Babcock
NDK level set above 19 forces minSdkVersion to 21 or above to prevent installing on unsupported devices
#jira UE-28408
#ue4
#android
#codereview Jack.Porter
Change 2919591 on 2016/03/23 by Allan.Bentham
Merge ronin's Gaussian DoF to 4.11's dof changes.
Gaussian DoF will use a single recombine pass with ES31 devices or if no separate translucency is used on SM4+.
Added permutation to exclude separate translucency from Gaussian recombine shader when not in use.
#codereview martin.mittring
Change 2920758 on 2016/03/24 by Dmitriy.Dyomin
Fixed: shifting lighting samples octree
https://udn.unrealengine.com/questions/276026/lighting-samples-visualization-not-working-with-le.html
Change 2920793 on 2016/03/24 by Dmitriy.Dyomin
Fixed: When sub-level set to be unloaded but with visbility state set to true, ULevelStreaming::IsStreamingStatePending returns wrong value
#jira UE-26426
Change 2920981 on 2016/03/24 by Dmitriy.Dyomin
GPU particles support for iOS Metal (A8+ only)
#jira UE-11067
#jira UE-28514
#codereview Jack.Porter
Change 2921383 on 2016/03/24 by Allan.Bentham
Fix inverted image on device when framebuffer fetch/bViewRectSource is not used.
#codereview jack.porter
Change 2925694 on 2016/03/29 by Dmitriy.Dyomin
Fixed: GPU particles and bloom on S7 Mali
Change 2927065 on 2016/03/29 by Chris.Babcock
Set the DT_SONAME field in linker (stops warning toast)
#ue4
#android
#codereview Jack.Porter
Change 2927375 on 2016/03/30 by Jack.Porter
Fixed localization for placement mode Cube, Sphere, Cylinder and Cone
Change 2928643 on 2016/03/30 by Jack.Porter
Fixed bug introdued by Ronin merge with DepthOfFieldScale setting being locked for BokehDOF
#code_review: allan.bentham
Change 2932773 on 2016/04/04 by Jack.Porter
Reapply android Vulkan version fixes
Change 2932853 on 2016/04/05 by Jack.Porter
Enable VULKAN_CLEAR_SURFACE_ON_CREATE on Android to prevent assertion
Change 2932998 on 2016/04/05 by Jack.Porter
Native web browser widget on iOS
#jira UEMOB-20
Change 2933420 on 2016/04/05 by Chris.Babcock
Removed hard-coded bUseUnityBuild in UBT for Android (contributed by kosz78)
#jira UE-29066
#pr #2236
#ue4
#android
Change 2934315 on 2016/04/05 by Chris.Babcock
Allow Android to act as server with OnlineSubsystemNull (contributed by psychogony)
#jira UE-23937
#PR #1820
#ue4
#android
#codereview Ryan.Gerleve
Change 2935038 on 2016/04/06 by Chris.Babcock
Fix OpenGLES31 compile error
#ue4
#android
#codereview Jack.Porter
Change 2936288 on 2016/04/07 by Allan.Bentham
Planar reflection captures for mobile. (UE-27426)
Added mobile planar reflection flag to material.
#codereview jack.porter, daniel.wright
Change 2936297 on 2016/04/07 by Allan.Bentham
Missed file. Planar reflection captures for mobile. (UE-27426)
#codereview jack.porter, daniel.wright
Change 2937763 on 2016/04/08 by Dmitriy.Dyomin
Fix InstancedStaticMesh batches for ES2 (contributed by Grimmick)
GitHub #2031
#jira UE-26576
#codereview Jack.Porter
Change 2937863 on 2016/04/08 by Jack.Porter
Merged Ronin CLs 2840392, 2860028
Allow vertex texture fetches on ES2 (requires absolute mip level)
Change 2938461 on 2016/04/08 by Chris.Babcock
Write Android uninstall batch files
#ue4
#android
Change 2939679 on 2016/04/11 by Allan.Bentham
Remove bStationaryLightUsesCSMForMovableShadows from light component's UI.
renamed proxy equivalent and infer its state from Inset Shadows For Movable Objects
#codereview jack.porter, daniel.wright
Change 2939887 on 2016/04/11 by Chris.Babcock
Android ARM64 libraries
#jira UEPLAT-1268
#ue4
#android
Change 2940125 on 2016/04/11 by Chris.Babcock
Added requirements to Arm64 and x86_64 tooltips
Change 2941051 on 2016/04/12 by Allan.Bentham
Fix for inverted RG channels when using filmic tonemapper with ES2.
#codereview jack.porter
Change 2942523 on 2016/04/13 by Chris.Babcock
Add cxa_demangle build.cs instead of hiding dependency in UEBuildAndroid.cs
#ue4
#android
#codereview Josh.Adams
Change 2942578 on 2016/04/13 by Chris.Babcock
Add cxademangle dependency to Core for Android
#ue4
#android
#codereview Josh.Adams
Change 2942997 on 2016/04/13 by Chris.Babcock
Run Ant with -quiet first and run again without if there is an error for the log
#ue4
#android
#codereview Josh.Adams
Change 2943320 on 2016/04/14 by Jack.Porter
Fixed planar reflection merge errors
Change 2943352 on 2016/04/14 by Jack.Porter
Fix NAME_VULKAN_ES3_1_ANDROID shader format name
#codereview: Rolando.Coloca
Change 2943367 on 2016/04/14 by Dmitriy.Dyomin
Added cvars to add or strip specific GL extensions from a driver reported extensions string
#jira UE-29467
Change 2943425 on 2016/04/14 by Dmitriy.Dyomin
Better logging of MobileHDR mode
Change 2943461 on 2016/04/14 by Dmitriy.Dyomin
Fixing HDR rendering and bloom on Galaxy S7
Change 2943493 on 2016/04/14 by Dmitriy.Dyomin
Better HDR fix for devices with ES3 support
Change 2943855 on 2016/04/14 by Allan.Bentham
Mobile planar reflections.
- currently only supports opaque materials
#codereview jack.porter
Change 2944721 on 2016/04/14 by Chris.Babcock
Allow Vulkan-only Android builds
#ue4
#android
#codereview Allan.Bentham,Jack.Porter
Change 2944771 on 2016/04/14 by Dmitriy.Dyomin
Fixed: mesh particles crash in ES2
Change 2944827 on 2016/04/15 by Dmitriy.Dyomin
Fixed: GPU particles not working on S6 with Android 6.0.1
Change 2944836 on 2016/04/15 by Jack.Porter
Disable FX system calls in forward renderer when particles showflag is off
Change 2944840 on 2016/04/15 by Jack.Porter
Re-enabled non-radial TDeferredLightVS on ES2 for planar and put #if FEATURE_LEVEL >= FEATURE_LEVEL_SM4 around the radial shader code which was tripping up ES2.
#codereview: Allan.Bentham, Chris.Babcock, Daniel.Wright
Change 2944914 on 2016/04/15 by Jack.Porter
Device profiles to detect Galaxy S7 Mali and Adreno variants in Vulkan mode
Change 2945020 on 2016/04/15 by Gareth.Martin
Cloning changes across from Dev-Landscape to Dev-Mobile due to feature deadline for 4.12.
Change 2943560 on 2016/04/14 by Gareth.Martin
Added ability to expand landscape bounds
#jira UE-28928
#jira UE-25230
Change 2943538 on 2016/04/14 by Gareth.Martin
Fix a crash with saving a level >2GB in size.
There may still be other crashes with >2GB levels.
Change 2943477 on 2016/04/14 by Gareth.Martin
Fixed LODFalloff setting on landscape getting reset when using the "Change Landscape Component Size" tool
Also moved all the LOD settings together in LandscapeProxy.h because it was messy
Change 2942113 on 2016/04/13 by Gareth.Martin
Updating comment to clarify behaviour of Foliage Align-To-Normal when Random-Yaw is disabled.
Change 2941030 on 2016/04/12 by Gareth.Martin
Cleanup and commenting
Change 2940994 on 2016/04/12 by Gareth.Martin
Implement random scale option for Landscape Grass.
#jira UE-25743
Change 2940993 on 2016/04/12 by Gareth.Martin
Remove unused BuildFlatTree function from HierarchicalInstancedStaticMeshComponent
Change 2940150 on 2016/04/11 by Gareth.Martin
Harden UHierarchicalInstancedStaticMeshComponent::UpdateInstanceTransform
Change 2940101 on 2016/04/11 by Gareth.Martin
Additional checks for bad static mesh when building the HISMC tree
Change 2945560 on 2016/04/15 by Rolando.Caloca
DM - Fix for newer Vulkan sdks
Change 2945638 on 2016/04/15 by Chris.Babcock
Fix permissions on uninstall script on Mac
#jira UE-29236
#ue4
#android
#lockdown Jack.Porter
Change 2945856 on 2016/04/15 by Rolando.Caloca
DM - vk - Fix mapped allocations on mobile
#lockdown nick.penwarden
[CL 2945995 by Chris Babcock in Main branch]
2016-04-15 18:19:26 -04:00
interp_qualifier ,
2015-02-06 11:35:30 -05:00
centroid_str [ var - > centroid ] ,
invariant_str [ var - > invariant ] ,
patch_constant_str [ var - > is_patch_constant ] ,
mode_str [ var - > mode ] ) ;
2014-09-25 14:27:21 -04:00
2015-02-06 11:35:30 -05:00
print_type_pre ( var - > type ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
const glsl_type * inner_type = var - > type ;
if ( inner_type - > is_array ( ) )
{
inner_type = inner_type - > fields . array ;
}
check ( inner_type - > is_record ( ) ) ;
check ( inner_type - > length = = 1 ) ;
const glsl_struct_field * field = & inner_type - > fields . structure [ 0 ] ;
check ( strcmp ( field - > name , " Data " ) = = 0 ) ;
2015-07-08 22:20:29 -04:00
if ( bEmitPrecision )
{
if ( field - > type - > is_integer ( ) )
{
ralloc_asprintf_append ( buffer , " flat " ) ;
}
AppendPrecisionModifier ( buffer , GetPrecisionModifier ( field - > type ) ) ;
}
2015-02-06 11:35:30 -05:00
print_type_pre ( field - > type ) ;
ralloc_asprintf_append ( buffer , " , Data " ) ;
print_type_post ( field - > type ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
2014-09-25 14:27:21 -04:00
}
else
{
2015-02-06 11:35:30 -05:00
ralloc_asprintf_append (
buffer ,
" %s%s%s%s%s " ,
layout_str [ layout_bits ] ,
centroid_str [ var - > centroid ] ,
invariant_str [ var - > invariant ] ,
patch_constant_str [ var - > is_patch_constant ] ,
mode_str [ var - > mode ]
) ;
print_type_pre ( var - > type ) ;
2014-09-25 14:27:21 -04:00
2015-02-06 11:35:30 -05:00
const glsl_type * inner_type = var - > type ;
if ( inner_type - > is_array ( ) )
{
inner_type = inner_type - > fields . array ;
}
check ( inner_type - > is_record ( ) ) ;
check ( inner_type - > length = = 1 ) ;
const glsl_struct_field * field = & inner_type - > fields . structure [ 0 ] ;
check ( strcmp ( field - > name , " Data " ) = = 0 ) ;
ralloc_asprintf_append ( buffer , " { %s " , interp_str [ var - > interpolation ] ) ;
print_type_pre ( field - > type ) ;
ralloc_asprintf_append ( buffer , " Data " ) ;
print_type_post ( field - > type ) ;
ralloc_asprintf_append ( buffer , " ; } " ) ;
}
2014-09-25 14:27:21 -04:00
}
else if ( var - > type - > is_image ( ) )
{
2015-06-19 19:28:40 -04:00
const bool bSingleComp = ( var - > type - > inner_type - > vector_elements = = 1 ) ;
2014-09-25 14:27:21 -04:00
const char * const coherent_str [ ] = { " " , " coherent " } ;
const char * const writeonly_str [ ] = { " " , " writeonly " } ;
2015-06-19 19:28:40 -04:00
const char * const type_str [ ] = { " 32ui " , " 32i " , " 16f " , ( bIsES31 & & ! bSingleComp ) ? " 16f " : " 32f " } ;
const char * const comp_str = bSingleComp ? " r " : " rgba " ;
2014-09-25 14:27:21 -04:00
const int writeonly = var - > image_write & & ! ( var - > image_read ) ;
check ( var - > type - > inner_type - > base_type > = GLSL_TYPE_UINT & &
var - > type - > inner_type - > base_type < = GLSL_TYPE_FLOAT ) ;
ralloc_asprintf_append (
buffer ,
" %s%s%s%s " ,
invariant_str [ var - > invariant ] ,
mode_str [ var - > mode ] ,
coherent_str [ var - > coherent ] ,
writeonly_str [ writeonly ]
) ;
if ( bGenerateLayoutLocations & & var - > explicit_location )
{
//should check here on base type
ralloc_asprintf_append (
buffer ,
2015-06-19 19:28:40 -04:00
" layout(%s%s,binding=%d) " ,
comp_str ,
2014-09-25 14:27:21 -04:00
type_str [ var - > type - > inner_type - > base_type ] ,
var - > location
) ;
}
else
{
//should check here on base type
ralloc_asprintf_append (
buffer ,
2015-06-19 19:28:40 -04:00
" layout(%s%s) " ,
comp_str ,
2014-09-25 14:27:21 -04:00
type_str [ var - > type - > inner_type - > base_type ]
) ;
}
2015-06-18 14:24:11 -04:00
if ( bEmitPrecision )
2014-09-25 14:27:21 -04:00
{
2015-07-08 22:20:29 -04:00
AppendPrecisionModifier ( buffer , GetPrecisionModifier ( var - > type ) ) ;
2014-09-25 14:27:21 -04:00
}
print_type_pre ( var - > type ) ;
}
else
{
char * layout = nullptr ;
if ( bGenerateLayoutLocations & & var - > explicit_location )
{
check ( layout_bits = = 0 ) ;
2015-02-06 11:35:30 -05:00
layout = ralloc_asprintf ( nullptr , " INTERFACE_LOCATION(%d) " , var - > location ) ;
2014-09-25 14:27:21 -04:00
}
ralloc_asprintf_append (
buffer ,
" %s%s%s%s%s%s " ,
layout ? layout : layout_str [ layout_bits ] ,
2015-12-10 16:56:55 -05:00
var - > mode ! = ir_var_temporary & & var - > mode ! = ir_var_auto ? centroid_str [ var - > centroid ] : " " ,
var - > mode ! = ir_var_temporary & & var - > mode ! = ir_var_auto ? invariant_str [ var - > invariant ] : " " ,
2014-09-25 14:27:21 -04:00
patch_constant_str [ var - > is_patch_constant ] ,
mode_str [ var - > mode ] ,
2015-12-10 16:56:55 -05:00
var - > mode ! = ir_var_temporary & & var - > mode ! = ir_var_auto ? interp_str [ var - > interpolation ] : " "
2014-09-25 14:27:21 -04:00
) ;
2015-06-18 14:24:11 -04:00
if ( bEmitPrecision )
2014-09-25 14:27:21 -04:00
{
2015-07-08 22:20:29 -04:00
AppendPrecisionModifier ( buffer , GetPrecisionModifier ( var - > type ) ) ;
2014-09-25 14:27:21 -04:00
}
if ( bGenerateLayoutLocations & & var - > explicit_location )
{
ralloc_free ( layout ) ;
}
print_type_pre ( var - > type ) ;
}
ralloc_asprintf_append ( buffer , " %s " , unique_name ( var ) ) ;
const bool bUnsizedArray = var - > mode = = ir_var_in & & ( ( ShaderTarget = = tessellation_evaluation_shader ) | | ( ShaderTarget = = tessellation_control_shader ) ) ;
print_type_post ( var - > type , bUnsizedArray ) ;
}
// Add the initializer if we need it
if ( constInit )
{
ralloc_asprintf_append ( buffer , " = " ) ;
if ( var - > constant_initializer )
{
var - > constant_initializer - > accept ( this ) ;
}
else
{
var - > constant_value - > accept ( this ) ;
}
}
// add type to used_structures so we can later declare them at the start of the GLSL shader
// this is for the case of a variable that is declared, but not later dereferenced (which can happen
// when debugging HLSLCC and running without optimization
AddTypeToUsedStructs ( var - > type ) ;
}
virtual void visit ( ir_function_signature * sig )
{
// Reset temporary id count.
temp_id = 0 ;
bool bPrintComma = false ;
scope_depth + + ;
print_type_full ( sig - > return_type ) ;
ralloc_asprintf_append ( buffer , " %s( " , sig - > function_name ( ) ) ;
foreach_iter ( exec_list_iterator , iter , sig - > parameters )
{
ir_variable * const inst = ( ir_variable * ) iter . get ( ) ;
if ( bPrintComma )
{
ralloc_asprintf_append ( buffer , " , " ) ;
}
inst - > accept ( this ) ;
bPrintComma = true ;
}
ralloc_asprintf_append ( buffer , " ) \n " ) ;
indent ( ) ;
ralloc_asprintf_append ( buffer , " { \n " ) ;
if ( sig - > is_main & & ! global_instructions . is_empty ( ) )
{
indentation + + ;
foreach_iter ( exec_list_iterator , iter , global_instructions )
{
global_ir * gir = ( global_ir * ) iter . get ( ) ;
indent ( ) ;
do_visit ( gir - > ir ) ;
}
indentation - - ;
}
//grab the global attributes
if ( sig - > is_main )
{
early_depth_stencil = sig - > is_early_depth_stencil ;
wg_size_x = sig - > wg_size_x ;
wg_size_y = sig - > wg_size_y ;
wg_size_z = sig - > wg_size_z ;
tessellation = sig - > tessellation ;
}
indentation + + ;
foreach_iter ( exec_list_iterator , iter , sig - > body )
{
ir_instruction * const inst = ( ir_instruction * ) iter . get ( ) ;
indent ( ) ;
do_visit ( inst ) ;
}
indentation - - ;
indent ( ) ;
ralloc_asprintf_append ( buffer , " } \n " ) ;
needs_semicolon = false ;
scope_depth - - ;
}
virtual void visit ( ir_function * func )
{
foreach_iter ( exec_list_iterator , iter , * func )
{
ir_function_signature * const sig = ( ir_function_signature * ) iter . get ( ) ;
if ( sig - > is_defined & & ! sig - > is_builtin )
{
indent ( ) ;
sig - > accept ( this ) ;
}
}
needs_semicolon = false ;
}
virtual void visit ( ir_expression * expr )
{
check ( scope_depth > 0 ) ;
int numOps = expr - > get_num_operands ( ) ;
ir_expression_operation op = expr - > operation ;
if ( numOps = = 1 & & op > = ir_unop_first_conversion & & op < = ir_unop_last_conversion )
{
if ( op = = ir_unop_f2h | | op = = ir_unop_h2f )
{
// No need to convert from half<->float as that is part of the precision of a variable
expr - > operands [ 0 ] - > accept ( this ) ;
}
else
{
ralloc_asprintf_append ( buffer , " %s( " , FixHlslName ( expr - > type ) . c_str ( ) ) ;
expr - > operands [ 0 ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
}
}
else if ( expr - > type - > is_scalar ( ) & &
( ( numOps = = 1 & & op = = ir_unop_logic_not ) | |
( numOps = = 2 & & op > = ir_binop_first_comparison & & op < = ir_binop_last_comparison ) | |
( numOps = = 2 & & op > = ir_binop_first_logic & & op < = ir_binop_last_logic ) ) )
{
const char * op_str = GLSLExpressionTable [ op ] [ 3 ] ;
ralloc_asprintf_append ( buffer , " %s( " , ( numOps = = 1 ) ? op_str : " " ) ;
expr - > operands [ 0 ] - > accept ( this ) ;
if ( numOps = = 2 )
{
ralloc_asprintf_append ( buffer , " %s " , op_str ) ;
expr - > operands [ 1 ] - > accept ( this ) ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
else if ( expr - > type - > is_vector ( ) & & numOps = = 2 & &
op > = ir_binop_first_logic & & op < = ir_binop_last_logic )
{
ralloc_asprintf_append ( buffer , GLSLExpressionTable [ op ] [ 0 ] , expr - > type - > vector_elements , expr - > type - > vector_elements ) ;
expr - > operands [ 0 ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , GLSLExpressionTable [ op ] [ 1 ] , expr - > type - > vector_elements ) ;
expr - > operands [ 1 ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , GLSLExpressionTable [ op ] [ 2 ] ) ;
}
else if ( op = = ir_binop_mod & & ! expr - > type - > is_float ( ) )
{
ralloc_asprintf_append ( buffer , " (( " ) ;
expr - > operands [ 0 ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " )%%( " ) ;
expr - > operands [ 1 ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " )) " ) ;
}
else if ( op = = ir_binop_mul & & expr - > type - > is_matrix ( )
& & expr - > operands [ 0 ] - > type - > is_matrix ( )
& & expr - > operands [ 1 ] - > type - > is_matrix ( ) )
{
ralloc_asprintf_append ( buffer , " matrixCompMult( " ) ;
expr - > operands [ 0 ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
expr - > operands [ 1 ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
}
else if ( numOps < 4 )
{
if ( op = = ir_unop_dFdx | | op = = ir_unop_dFdy )
{
bUsesDXDY = true ;
}
ralloc_asprintf_append ( buffer , GLSLExpressionTable [ op ] [ 0 ] ) ;
for ( int i = 0 ; i < numOps ; + + i )
{
expr - > operands [ i ] - > accept ( this ) ;
ralloc_asprintf_append ( buffer , GLSLExpressionTable [ op ] [ i + 1 ] ) ;
}
}
}
virtual void visit ( ir_texture * tex )
{
check ( scope_depth > 0 ) ;
const char * const fetch_str [ ] = { " texture " , " texelFetch " } ;
const char * const Dim [ ] = { " " , " 2D " , " 3D " , " Cube " , " " , " " , " " } ;
static const char * const size_str [ ] = { " " , " Size " } ;
static const char * const proj_str [ ] = { " " , " Proj " } ;
static const char * const grad_str [ ] = { " " , " Grad " } ;
static const char * const lod_str [ ] = { " " , " Lod " } ;
static const char * const offset_str [ ] = { " " , " Offset " } ;
static const char * const gather_str [ ] = { " " , " Gather " } ;
static const char * const querymips_str [ ] = { " " , " QueryLevels " } ;
static const char * const EXT_str [ ] = { " " , " EXT " } ;
const bool cube_array = tex - > sampler - > type - > sampler_dimensionality = = GLSL_SAMPLER_DIM_CUBE & &
tex - > sampler - > type - > sampler_array ;
ir_texture_opcode op = tex - > op ;
if ( op = = ir_txl & & tex - > sampler - > type - > sampler_shadow & & tex - > sampler - > type - > sampler_dimensionality = = GLSL_SAMPLER_DIM_CUBE )
{
// This very instruction is missing in OpenGL 3.2, so we need to change the sampling to instruction that exists in order for shader to compile
op = ir_tex ;
}
bool bEmitEXT = false ;
if ( bIsES & & op = = ir_txl )
{
// See http://www.khronos.org/registry/gles/extensions/EXT/EXT_shader_texture_lod.txt
bUsesES2TextureLODExtension = true ;
bEmitEXT = true ;
}
// Emit texture function and sampler.
ralloc_asprintf_append ( buffer , " %s%s%s%s%s%s%s%s%s%s( " ,
fetch_str [ op = = ir_txf ] ,
bIsES ? Dim [ tex - > sampler - > type - > sampler_dimensionality ] : " " ,
gather_str [ op = = ir_txg ] ,
size_str [ op = = ir_txs ] ,
querymips_str [ op = = ir_txm ] ,
proj_str [ tex - > projector ! = 0 ] ,
grad_str [ op = = ir_txd ] ,
lod_str [ op = = ir_txl ] ,
offset_str [ tex - > offset ! = 0 ] ,
EXT_str [ ( int ) bEmitEXT ]
) ;
tex - > sampler - > accept ( this ) ;
// Emit coordinates.
if ( ( op = = ir_txs & & tex - > lod_info . lod ) | | op = = ir_txm )
{
if ( ! tex - > sampler - > type - > sampler_ms & & op ! = ir_txm )
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > lod_info . lod - > accept ( this ) ;
}
}
else if ( tex - > sampler - > type - > sampler_shadow & & ( op ! = ir_txg & & ! cube_array ) )
{
int coord_dims = 0 ;
switch ( tex - > sampler - > type - > sampler_dimensionality )
{
case GLSL_SAMPLER_DIM_1D : coord_dims = 2 ; break ;
case GLSL_SAMPLER_DIM_2D : coord_dims = 3 ; break ;
case GLSL_SAMPLER_DIM_3D : coord_dims = 4 ; break ;
case GLSL_SAMPLER_DIM_CUBE : coord_dims = 4 ; break ;
default : check ( 0 & & " Shadow sampler has unsupported dimensionality. " ) ;
}
ralloc_asprintf_append ( buffer , " ,vec%d( " , coord_dims ) ;
tex - > coordinate - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > shadow_comparitor - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
}
else
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > coordinate - > accept ( this ) ;
}
// Emit gather compare value
if ( tex - > sampler - > type - > sampler_shadow & & ( op = = ir_txg | | cube_array ) )
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > shadow_comparitor - > accept ( this ) ;
}
// Emit sample index.
if ( op = = ir_txf & & tex - > sampler - > type - > sampler_ms )
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > lod_info . sample_index - > accept ( this ) ;
}
// Emit LOD.
if ( op = = ir_txl | |
( op = = ir_txf & & tex - > lod_info . lod & &
! tex - > sampler - > type - > sampler_ms & & ! tex - > sampler - > type - > sampler_buffer ) )
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > lod_info . lod - > accept ( this ) ;
}
// Emit gradients.
if ( op = = ir_txd )
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > lod_info . grad . dPdx - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > lod_info . grad . dPdy - > accept ( this ) ;
}
else if ( op = = ir_txb )
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > lod_info . bias - > accept ( this ) ;
}
// Emit offset.
if ( tex - > offset )
{
ralloc_asprintf_append ( buffer , " , " ) ;
tex - > offset - > accept ( this ) ;
}
// Emit channel selection for gather
if ( op = = ir_txg & & tex - > channel > ir_channel_none )
{
check ( tex - > channel < ir_channel_unknown ) ;
ralloc_asprintf_append ( buffer , " , %d " , int ( tex - > channel ) - 1 ) ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
virtual void visit ( ir_swizzle * swizzle )
{
check ( scope_depth > 0 ) ;
const unsigned mask [ 4 ] =
{
swizzle - > mask . x ,
swizzle - > mask . y ,
swizzle - > mask . z ,
swizzle - > mask . w ,
} ;
if ( swizzle - > val - > type - > is_scalar ( ) )
{
// Scalar -> Vector swizzles must use the constructor syntax.
if ( swizzle - > type - > is_scalar ( ) = = false )
{
print_type_full ( swizzle - > type ) ;
ralloc_asprintf_append ( buffer , " ( " ) ;
swizzle - > val - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
}
}
else
{
const bool is_constant = swizzle - > val - > as_constant ( ) ! = nullptr ;
if ( is_constant )
{
ralloc_asprintf_append ( buffer , " ( " ) ;
}
swizzle - > val - > accept ( this ) ;
if ( is_constant )
{
ralloc_asprintf_append ( buffer , " ) " ) ;
}
ralloc_asprintf_append ( buffer , " . " ) ;
for ( unsigned i = 0 ; i < swizzle - > mask . num_components ; i + + )
{
ralloc_asprintf_append ( buffer , " %c " , " xyzw " [ mask [ i ] ] ) ;
}
}
}
virtual void visit ( ir_dereference_variable * deref )
{
check ( scope_depth > 0 ) ;
ir_variable * var = deref - > variable_referenced ( ) ;
ralloc_asprintf_append ( buffer , unique_name ( var ) ) ;
// add type to used_structures so we can later declare them at the start of the GLSL shader
AddTypeToUsedStructs ( var - > type ) ;
if ( var - > mode = = ir_var_uniform & & var - > semantic ! = NULL )
{
if ( hash_table_find ( used_uniform_blocks , var - > semantic ) = = NULL )
{
hash_table_insert ( used_uniform_blocks , ( void * ) var - > semantic , var - > semantic ) ;
}
}
if ( is_md_array ( deref - > type ) )
{
ralloc_asprintf_append ( buffer , " .Inner " ) ;
}
}
virtual void visit ( ir_dereference_array * deref )
{
check ( scope_depth > 0 ) ;
deref - > array - > accept ( this ) ;
// Make extra sure crappy Mac OS X compiler won't have any reason to crash
bool enforceInt = false ;
if ( deref - > array_index - > type - > base_type = = GLSL_TYPE_UINT )
{
if ( deref - > array_index - > ir_type = = ir_type_constant )
{
should_print_uint_literals_as_ints = true ;
}
else
{
enforceInt = true ;
}
}
if ( enforceInt )
{
ralloc_asprintf_append ( buffer , " [int( " ) ;
}
else
{
ralloc_asprintf_append ( buffer , " [ " ) ;
}
deref - > array_index - > accept ( this ) ;
should_print_uint_literals_as_ints = false ;
if ( enforceInt )
{
ralloc_asprintf_append ( buffer , " )] " ) ;
}
else
{
ralloc_asprintf_append ( buffer , " ] " ) ;
}
if ( is_md_array ( deref - > array - > type ) )
{
ralloc_asprintf_append ( buffer , " .Inner " ) ;
}
}
void print_image_op ( ir_dereference_image * deref , ir_rvalue * src )
{
const char * swizzle [ ] =
{
" x " , " xy " , " xyz " , " xyzw "
} ;
const char * expand [ ] =
{
" xxxx " , " xyxx " , " xyzx " , " xyzw "
} ;
const char * int_cast [ ] =
{
" int " , " ivec2 " , " ivec3 " , " ivec4 "
} ;
const int dst_elements = deref - > type - > vector_elements ;
const int src_elements = ( src ) ? src - > type - > vector_elements : 1 ;
check ( 1 < = dst_elements & & dst_elements < = 4 ) ;
check ( 1 < = src_elements & & src_elements < = 4 ) ;
if ( deref - > op = = ir_image_access )
{
if ( src = = NULL )
{
ralloc_asprintf_append ( buffer , " imageLoad( " ) ;
deref - > image - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
deref - > image_index - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ).%s " , swizzle [ dst_elements - 1 ] ) ;
}
else
{
ralloc_asprintf_append ( buffer , " imageStore( " ) ;
deref - > image - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
deref - > image_index - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
src - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " .%s) " , expand [ src_elements - 1 ] ) ;
}
}
else if ( deref - > op = = ir_image_dimensions )
{
ralloc_asprintf_append ( buffer , " imageSize( " ) ;
deref - > image - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
}
else
{
check ( ! " Unknown image operation " ) ;
}
}
virtual void visit ( ir_dereference_image * deref )
{
check ( scope_depth > 0 ) ;
print_image_op ( deref , NULL ) ;
}
virtual void visit ( ir_dereference_record * deref )
{
check ( scope_depth > 0 ) ;
deref - > record - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " .%s " , deref - > field ) ;
if ( is_md_array ( deref - > type ) )
{
ralloc_asprintf_append ( buffer , " .Inner " ) ;
}
}
virtual void visit ( ir_assignment * assign )
{
if ( scope_depth = = 0 )
{
global_instructions . push_tail ( new ( mem_ctx ) global_ir ( assign ) ) ;
needs_semicolon = false ;
return ;
}
// constant variables with initializers are statically assigned
ir_variable * var = assign - > lhs - > variable_referenced ( ) ;
if ( var - > has_initializer & & var - > read_only & & ( var - > constant_initializer | | var - > constant_value ) )
{
//This will leave a blank line with a semi-colon
return ;
}
if ( assign - > condition )
{
ralloc_asprintf_append ( buffer , " if( " ) ;
assign - > condition - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) { " ) ;
}
if ( assign - > lhs - > as_dereference_image ( ) ! = NULL )
{
/** EHart - should the write mask be checked here? */
print_image_op ( assign - > lhs - > as_dereference_image ( ) , assign - > rhs ) ;
}
else
{
char mask [ 6 ] ;
unsigned j = 1 ;
if ( assign - > lhs - > type - > is_scalar ( ) = = false | |
assign - > write_mask ! = 0x1 )
{
for ( unsigned i = 0 ; i < 4 ; i + + )
{
if ( ( assign - > write_mask & ( 1 < < i ) ) ! = 0 )
{
mask [ j ] = " xyzw " [ i ] ;
j + + ;
}
}
}
mask [ j ] = ' \0 ' ;
mask [ 0 ] = ( j = = 1 ) ? ' \0 ' : ' . ' ;
assign - > lhs - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " %s = " , mask ) ;
assign - > rhs - > accept ( this ) ;
}
if ( assign - > condition )
{
ralloc_asprintf_append ( buffer , " %s } " , needs_semicolon ? " ; " : " " ) ;
}
}
void print_constant ( ir_constant * constant , int index )
{
if ( constant - > type - > is_float ( ) )
{
if ( constant - > is_component_finite ( index ) )
{
float value = constant - > value . f [ index ] ;
// Original formatting code relied on %f style formatting
// %e is more accureate, and has been available since at least ES 2.0
// leaving original code in place, in case some drivers don't properly handle it
#if 0
const char * format = ( fabsf ( fmodf ( value , 1.0f ) ) < 1.e-8 f ) ? " %.1f " : " %.8f " ;
# else
const char * format = " %e " ;
# endif
ralloc_asprintf_append ( buffer , format , value ) ;
}
else
{
switch ( constant - > value . u [ index ] )
{
case 0x7f800000u :
ralloc_asprintf_append ( buffer , " (1.0/0.0) " ) ;
break ;
case 0xffc00000u :
ralloc_asprintf_append ( buffer , " (0.0/0.0) " ) ;
break ;
case 0xff800000u :
ralloc_asprintf_append ( buffer , " (-1.0/0.0) " ) ;
break ;
default :
check ( 0 ) ;
}
}
}
else if ( constant - > type - > base_type = = GLSL_TYPE_INT )
{
ralloc_asprintf_append ( buffer , " %d " , constant - > value . i [ index ] ) ;
}
else if ( constant - > type - > base_type = = GLSL_TYPE_UINT )
{
ralloc_asprintf_append ( buffer , " %u%s " ,
constant - > value . u [ index ] ,
should_print_uint_literals_as_ints ? " " : " u "
) ;
}
else if ( constant - > type - > base_type = = GLSL_TYPE_BOOL )
{
ralloc_asprintf_append ( buffer , " %s " , constant - > value . b [ index ] ? " true " : " false " ) ;
}
}
virtual void visit ( ir_constant * constant )
{
if ( constant - > type = = glsl_type : : float_type
| | constant - > type = = glsl_type : : half_type
| | constant - > type = = glsl_type : : bool_type
| | constant - > type = = glsl_type : : int_type
| | constant - > type = = glsl_type : : uint_type )
{
print_constant ( constant , 0 ) ;
}
else if ( constant - > type - > is_record ( ) )
{
print_type_full ( constant - > type ) ;
ralloc_asprintf_append ( buffer , " ( " ) ;
ir_constant * value = ( ir_constant * ) constant - > components . get_head ( ) ;
if ( value )
{
value - > accept ( this ) ;
}
for ( uint32 i = 1 ; i < constant - > type - > length ; i + + )
{
check ( value ) ;
value = ( ir_constant * ) value - > next ;
if ( value )
{
ralloc_asprintf_append ( buffer , " , " ) ;
value - > accept ( this ) ;
}
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
else if ( constant - > type - > is_array ( ) )
{
print_type_full ( constant - > type ) ;
ralloc_asprintf_append ( buffer , " ( " ) ;
constant - > get_array_element ( 0 ) - > accept ( this ) ;
for ( uint32 i = 1 ; i < constant - > type - > length ; + + i )
{
ralloc_asprintf_append ( buffer , " , " ) ;
constant - > get_array_element ( i ) - > accept ( this ) ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
else
{
print_type_full ( constant - > type ) ;
ralloc_asprintf_append ( buffer , " ( " ) ;
print_constant ( constant , 0 ) ;
int num_components = constant - > type - > components ( ) ;
for ( int i = 1 ; i < num_components ; + + i )
{
ralloc_asprintf_append ( buffer , " , " ) ;
print_constant ( constant , i ) ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
}
virtual void visit ( ir_call * call )
{
if ( scope_depth = = 0 )
{
global_instructions . push_tail ( new ( mem_ctx ) global_ir ( call ) ) ;
needs_semicolon = false ;
return ;
}
if ( call - > return_deref )
{
call - > return_deref - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " = " ) ;
}
ralloc_asprintf_append ( buffer , " %s( " , call - > callee_name ( ) ) ;
bool bPrintComma = false ;
foreach_iter ( exec_list_iterator , iter , * call )
{
ir_instruction * const inst = ( ir_instruction * ) iter . get ( ) ;
if ( bPrintComma )
{
ralloc_asprintf_append ( buffer , " , " ) ;
}
inst - > accept ( this ) ;
bPrintComma = true ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
virtual void visit ( ir_return * ret )
{
check ( scope_depth > 0 ) ;
ralloc_asprintf_append ( buffer , " return " ) ;
ir_rvalue * const value = ret - > get_value ( ) ;
if ( value )
{
value - > accept ( this ) ;
}
}
virtual void visit ( ir_discard * discard )
{
check ( scope_depth > 0 ) ;
if ( discard - > condition )
{
ralloc_asprintf_append ( buffer , " if ( " ) ;
discard - > condition - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
}
ralloc_asprintf_append ( buffer , " discard " ) ;
}
bool try_conditional_move ( ir_if * expr )
{
ir_dereference_variable * dest_deref = NULL ;
ir_rvalue * true_value = NULL ;
ir_rvalue * false_value = NULL ;
unsigned write_mask = 0 ;
const glsl_type * assign_type = NULL ;
int num_inst ;
num_inst = 0 ;
foreach_iter ( exec_list_iterator , iter , expr - > then_instructions )
{
if ( num_inst > 0 )
{
// multiple instructions? not a conditional move
return false ;
}
ir_instruction * const inst = ( ir_instruction * ) iter . get ( ) ;
ir_assignment * assignment = inst - > as_assignment ( ) ;
if ( assignment & & ( assignment - > rhs - > ir_type = = ir_type_dereference_variable | | assignment - > rhs - > ir_type = = ir_type_constant ) )
{
dest_deref = assignment - > lhs - > as_dereference_variable ( ) ;
true_value = assignment - > rhs ;
write_mask = assignment - > write_mask ;
}
num_inst + + ;
}
if ( dest_deref = = NULL | | true_value = = NULL )
return false ;
num_inst = 0 ;
foreach_iter ( exec_list_iterator , iter , expr - > else_instructions )
{
if ( num_inst > 0 )
{
// multiple instructions? not a conditional move
return false ;
}
ir_instruction * const inst = ( ir_instruction * ) iter . get ( ) ;
ir_assignment * assignment = inst - > as_assignment ( ) ;
if ( assignment & & ( assignment - > rhs - > ir_type = = ir_type_dereference_variable | | assignment - > rhs - > ir_type = = ir_type_constant ) )
{
ir_dereference_variable * tmp_deref = assignment - > lhs - > as_dereference_variable ( ) ;
if ( tmp_deref
& & tmp_deref - > var = = dest_deref - > var
& & tmp_deref - > type = = dest_deref - > type
& & assignment - > write_mask = = write_mask )
{
false_value = assignment - > rhs ;
}
}
num_inst + + ;
}
if ( false_value = = NULL )
return false ;
char mask [ 6 ] ;
unsigned j = 1 ;
if ( dest_deref - > type - > is_scalar ( ) = = false | | write_mask ! = 0x1 )
{
for ( unsigned i = 0 ; i < 4 ; i + + )
{
if ( ( write_mask & ( 1 < < i ) ) ! = 0 )
{
mask [ j ] = " xyzw " [ i ] ;
j + + ;
}
}
}
mask [ j ] = ' \0 ' ;
mask [ 0 ] = ( j = = 1 ) ? ' \0 ' : ' . ' ;
dest_deref - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " %s = ( " , mask ) ;
expr - > condition - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " )?( " ) ;
true_value - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ):( " ) ;
false_value - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) " ) ;
return true ;
}
virtual void visit ( ir_if * expr )
{
check ( scope_depth > 0 ) ;
if ( try_conditional_move ( expr ) = = false )
{
ralloc_asprintf_append ( buffer , " if ( " ) ;
expr - > condition - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ) \n " ) ;
indent ( ) ;
ralloc_asprintf_append ( buffer , " { \n " ) ;
indentation + + ;
foreach_iter ( exec_list_iterator , iter , expr - > then_instructions )
{
ir_instruction * const inst = ( ir_instruction * ) iter . get ( ) ;
indent ( ) ;
do_visit ( inst ) ;
}
indentation - - ;
indent ( ) ;
ralloc_asprintf_append ( buffer , " } \n " ) ;
if ( ! expr - > else_instructions . is_empty ( ) )
{
indent ( ) ;
ralloc_asprintf_append ( buffer , " else \n " ) ;
indent ( ) ;
ralloc_asprintf_append ( buffer , " { \n " ) ;
indentation + + ;
foreach_iter ( exec_list_iterator , iter , expr - > else_instructions )
{
ir_instruction * const inst = ( ir_instruction * ) iter . get ( ) ;
indent ( ) ;
do_visit ( inst ) ;
}
indentation - - ;
indent ( ) ;
ralloc_asprintf_append ( buffer , " } \n " ) ;
}
needs_semicolon = false ;
}
}
virtual void visit ( ir_loop * loop )
{
check ( scope_depth > 0 ) ;
if ( loop - > counter & & loop - > to )
{
// IR cmp operator is when to terminate loop; whereas GLSL for loop syntax
// is while to continue the loop. Invert the meaning of operator when outputting.
const char * termOp = NULL ;
switch ( loop - > cmp )
{
case ir_binop_less : termOp = " >= " ; break ;
case ir_binop_greater : termOp = " <= " ; break ;
case ir_binop_lequal : termOp = " > " ; break ;
case ir_binop_gequal : termOp = " < " ; break ;
case ir_binop_equal : termOp = " != " ; break ;
case ir_binop_nequal : termOp = " == " ; break ;
default : check ( false ) ;
}
ralloc_asprintf_append ( buffer , " for (;%s%s " , unique_name ( loop - > counter ) , termOp ) ;
loop - > to - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " ;) \n " ) ;
}
else
{
# if 1
ralloc_asprintf_append ( buffer , " for (;;) \n " ) ;
# else
ralloc_asprintf_append ( buffer , " for ( int loop%d = 0; loop%d < 256; loop%d ++) \n " , loop_count , loop_count , loop_count ) ;
loop_count + + ;
# endif
}
indent ( ) ;
ralloc_asprintf_append ( buffer , " { \n " ) ;
indentation + + ;
foreach_iter ( exec_list_iterator , iter , loop - > body_instructions )
{
ir_instruction * const inst = ( ir_instruction * ) iter . get ( ) ;
indent ( ) ;
do_visit ( inst ) ;
}
indentation - - ;
indent ( ) ;
ralloc_asprintf_append ( buffer , " } \n " ) ;
needs_semicolon = false ;
}
virtual void visit ( ir_loop_jump * jmp )
{
check ( scope_depth > 0 ) ;
ralloc_asprintf_append ( buffer , " %s " ,
jmp - > is_break ( ) ? " break " : " continue " ) ;
}
virtual void visit ( ir_atomic * ir )
{
const char * sharedAtomicFunctions [ ] =
{
" atomicAdd " ,
" atomicAnd " ,
" atomicMin " ,
" atomicMax " ,
" atomicOr " ,
" atomicXor " ,
" atomicExchange " ,
" atomicCompSwap "
} ;
const char * imageAtomicFunctions [ ] =
{
" imageAtomicAdd " ,
" imageAtomicAnd " ,
" imageAtomicMin " ,
" imageAtomicMax " ,
" imageAtomicOr " ,
" imageAtomicXor " ,
" imageAtomicExchange " ,
" imageAtomicCompSwap "
} ;
check ( scope_depth > 0 ) ;
const bool is_image = ir - > memory_ref - > as_dereference_image ( ) ! = NULL ;
ir - > lhs - > accept ( this ) ;
if ( ! is_image )
{
ralloc_asprintf_append ( buffer , " = %s( " ,
sharedAtomicFunctions [ ir - > operation ] ) ;
ir - > memory_ref - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
ir - > operands [ 0 ] - > accept ( this ) ;
if ( ir - > operands [ 1 ] )
{
ralloc_asprintf_append ( buffer , " , " ) ;
ir - > operands [ 1 ] - > accept ( this ) ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
else
{
ir_dereference_image * image = ir - > memory_ref - > as_dereference_image ( ) ;
ralloc_asprintf_append ( buffer , " = %s( " ,
imageAtomicFunctions [ ir - > operation ] ) ;
image - > image - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
image - > image_index - > accept ( this ) ;
ralloc_asprintf_append ( buffer , " , " ) ;
ir - > operands [ 0 ] - > accept ( this ) ;
if ( ir - > operands [ 1 ] )
{
ralloc_asprintf_append ( buffer , " , " ) ;
ir - > operands [ 1 ] - > accept ( this ) ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
}
void AddTypeToUsedStructs ( const glsl_type * type ) ;
/**
* Declare structs used to simulate multi - dimensional arrays .
*/
void declare_md_array_struct ( const glsl_type * type , hash_table * ht )
{
check ( type - > is_array ( ) ) ;
if ( hash_table_find ( ht , ( void * ) type ) = = NULL )
{
const glsl_type * subtype = type - > fields . array ;
if ( subtype - > base_type = = GLSL_TYPE_ARRAY )
{
declare_md_array_struct ( subtype , ht ) ;
ralloc_asprintf_append ( buffer , " struct " ) ;
print_md_array_type ( type ) ;
ralloc_asprintf_append ( buffer , " \n { \n \t " ) ;
print_md_array_type ( subtype ) ;
ralloc_asprintf_append ( buffer , " Inner[%u]; \n }; \n \n " , type - > length ) ;
}
else
{
ralloc_asprintf_append ( buffer , " struct " ) ;
print_md_array_type ( type ) ;
ralloc_asprintf_append ( buffer , " \n { \n \t " ) ;
print_type_pre ( type ) ;
ralloc_asprintf_append ( buffer , " Inner " ) ;
print_type_post ( type ) ;
ralloc_asprintf_append ( buffer , " ; \n }; \n \n " ) ;
}
hash_table_insert ( ht , ( void * ) type , ( void * ) type ) ;
}
}
/**
* Declare structs used by the code that has been generated .
*/
void declare_structs ( _mesa_glsl_parse_state * state )
{
// If any variable in a uniform block is in use, the entire uniform block
// must be present including structs that are not actually accessed.
for ( unsigned i = 0 ; i < state - > num_uniform_blocks ; i + + )
{
const glsl_uniform_block * block = state - > uniform_blocks [ i ] ;
if ( hash_table_find ( used_uniform_blocks , block - > name ) )
{
for ( unsigned var_index = 0 ; var_index < block - > num_vars ; + + var_index )
{
const glsl_type * type = block - > vars [ var_index ] - > type ;
if ( type - > base_type = = GLSL_TYPE_STRUCT & &
hash_table_find ( used_structures , type ) = = NULL )
{
hash_table_insert ( used_structures , ( void * ) type , type ) ;
}
}
}
}
// If otherwise unused structure is a member of another, used structure, the unused structure is also, in fact, used
{
int added_structure_types ;
do
{
added_structure_types = 0 ;
for ( unsigned i = 0 ; i < state - > num_user_structures ; i + + )
{
const glsl_type * const s = state - > user_structures [ i ] ;
if ( hash_table_find ( used_structures , s ) = = NULL )
{
continue ;
}
for ( unsigned j = 0 ; j < s - > length ; j + + )
{
const glsl_type * type = s - > fields . structure [ j ] . type ;
if ( type - > base_type = = GLSL_TYPE_STRUCT )
{
if ( hash_table_find ( used_structures , type ) = = NULL )
{
hash_table_insert ( used_structures , ( void * ) type , type ) ;
+ + added_structure_types ;
}
}
else if ( type - > base_type = = GLSL_TYPE_ARRAY & & type - > fields . array - > base_type = = GLSL_TYPE_STRUCT )
{
if ( hash_table_find ( used_structures , type - > fields . array ) = = NULL )
{
hash_table_insert ( used_structures , ( void * ) type - > fields . array , type - > fields . array ) ;
}
}
else if ( ( type - > base_type = = GLSL_TYPE_INPUTPATCH | | type - > base_type = = GLSL_TYPE_OUTPUTPATCH ) & & type - > inner_type - > base_type = = GLSL_TYPE_STRUCT )
{
if ( hash_table_find ( used_structures , type - > inner_type ) = = NULL )
{
hash_table_insert ( used_structures , ( void * ) type - > inner_type , type - > inner_type ) ;
}
}
}
}
}
while ( added_structure_types > 0 ) ;
}
// Generate structures that allow support for multi-dimensional arrays.
{
hash_table * ht = hash_table_ctor ( 32 , hash_table_pointer_hash , hash_table_pointer_compare ) ;
foreach_iter ( exec_list_iterator , iter , used_md_arrays )
{
md_array_entry * entry = ( md_array_entry * ) iter . get ( ) ;
declare_md_array_struct ( entry - > type , ht ) ;
}
hash_table_dtor ( ht ) ;
}
# ifdef OPTIMIZE_ANON_STRUCTURES_OUT
// If a uniform block consists of a single, anonymous structure, don't declare this structure
// separately. We'll remove it entirely during uniform block code generation, and name the
// uniform block instead.
for ( unsigned i = 0 ; i < state - > num_uniform_blocks ; i + + )
{
const glsl_uniform_block * block = state - > uniform_blocks [ i ] ;
if ( hash_table_find ( used_uniform_blocks , block - > name ) )
{
if ( block - > num_vars = = 1 )
{
ir_variable * var = block - > vars [ 0 ] ;
const glsl_type * type = var - > type ;
if ( type - > base_type = = GLSL_TYPE_STRUCT & &
type - > name & &
! strcmp ( var - > name , block - > name ) & &
! strncmp ( type - > name , " anon_struct_ " , 12 ) )
{
hash_table_remove ( used_structures , type ) ;
}
}
}
}
# endif // OPTIMIZE_ANON_STRUCTURES_OUT
for ( unsigned i = 0 ; i < state - > num_user_structures ; i + + )
{
const glsl_type * const s = state - > user_structures [ i ] ;
if ( hash_table_find ( used_structures , s ) = = NULL )
{
continue ;
}
ralloc_asprintf_append ( buffer , " struct %s \n { \n " , s - > name ) ;
if ( s - > length = = 0 )
{
2015-06-18 14:24:11 -04:00
if ( bEmitPrecision )
2015-06-16 14:56:48 -04:00
{
ralloc_asprintf_append ( buffer , " \t highp float glsl_doesnt_like_empty_structs; \n " ) ;
}
else
{
ralloc_asprintf_append ( buffer , " \t float glsl_doesnt_like_empty_structs; \n " ) ;
}
2014-09-25 14:27:21 -04:00
}
else
{
for ( unsigned j = 0 ; j < s - > length ; j + + )
{
2015-06-18 14:24:11 -04:00
ralloc_asprintf_append ( buffer , " \t %s " , ( state - > language_version = = 310 & & bEmitPrecision ) ? " highp " : " " ) ;
2014-09-25 14:27:21 -04:00
print_type_pre ( s - > fields . structure [ j ] . type ) ;
ralloc_asprintf_append ( buffer , " %s " , s - > fields . structure [ j ] . name ) ;
print_type_post ( s - > fields . structure [ j ] . type ) ;
ralloc_asprintf_append ( buffer , " ; \n " ) ;
}
}
ralloc_asprintf_append ( buffer , " }; \n \n " ) ;
}
unsigned num_used_blocks = 0 ;
for ( unsigned i = 0 ; i < state - > num_uniform_blocks ; i + + )
{
const glsl_uniform_block * block = state - > uniform_blocks [ i ] ;
if ( hash_table_find ( used_uniform_blocks , block - > name ) )
{
const char * block_name = block - > name ;
if ( state - > has_packed_uniforms )
{
block_name = ralloc_asprintf ( mem_ctx , " %sb%u " ,
glsl_variable_tag_from_parser_target ( state - > target ) ,
num_used_blocks
) ;
}
ralloc_asprintf_append ( buffer , " layout(std140) uniform %s \n { \n " , block_name ) ;
bool optimized_structure_out = false ;
# ifdef OPTIMIZE_ANON_STRUCTURES_OUT
if ( block - > num_vars = = 1 )
{
ir_variable * var = block - > vars [ 0 ] ;
const glsl_type * type = var - > type ;
if ( type - > base_type = = GLSL_TYPE_STRUCT & &
type - > name & &
! strcmp ( var - > name , block - > name ) & &
! strncmp ( type - > name , " anon_struct_ " , 12 ) )
{
for ( unsigned j = 0 ; j < type - > length ; j + + )
{
2015-06-18 14:24:11 -04:00
ralloc_asprintf_append ( buffer , " \t %s " , ( state - > language_version = = 310 & & bEmitPrecision ) ? " highp " : " " ) ;
2014-09-25 14:27:21 -04:00
print_type_pre ( type - > fields . structure [ j ] . type ) ;
ralloc_asprintf_append ( buffer , " %s " , type - > fields . structure [ j ] . name ) ;
print_type_post ( type - > fields . structure [ j ] . type ) ;
ralloc_asprintf_append ( buffer , " ; \n " ) ;
}
ralloc_asprintf_append ( buffer , " } %s; \n \n " , block - > name ) ;
optimized_structure_out = true ;
}
}
# endif
if ( ! optimized_structure_out )
{
for ( unsigned var_index = 0 ; var_index < block - > num_vars ; + + var_index )
{
ir_variable * var = block - > vars [ var_index ] ;
//EHart - name-mangle variables to prevent colliding names
ralloc_asprintf_append ( buffer , " #define %s %s%s \n " , var - > name , var - > name , block_name ) ;
2015-06-18 14:24:11 -04:00
ralloc_asprintf_append ( buffer , " \t %s " , ( state - > language_version = = 310 & & bEmitPrecision ) ? " highp " : " " ) ;
2014-09-25 14:27:21 -04:00
print_type_pre ( var - > type ) ;
ralloc_asprintf_append ( buffer , " %s " , var - > name ) ;
print_type_post ( var - > type ) ;
ralloc_asprintf_append ( buffer , " ; \n " ) ;
}
ralloc_asprintf_append ( buffer , " }; \n \n " ) ;
}
num_used_blocks + + ;
}
}
}
void PrintPackedSamplers ( _mesa_glsl_parse_state : : TUniformList & Samplers , TStringToSetMap & TextureToSamplerMap )
{
bool bPrintHeader = true ;
bool bNeedsComma = false ;
for ( _mesa_glsl_parse_state : : TUniformList : : iterator Iter = Samplers . begin ( ) ; Iter ! = Samplers . end ( ) ; + + Iter )
{
glsl_packed_uniform & Sampler = * Iter ;
2015-12-10 16:56:55 -05:00
FCustomStdString SamplerStates ( " " ) ;
2014-09-25 14:27:21 -04:00
TStringToSetMap : : iterator IterFound = TextureToSamplerMap . find ( Sampler . Name ) ;
if ( IterFound ! = TextureToSamplerMap . end ( ) )
{
TStringSet & ListSamplerStates = IterFound - > second ;
check ( ! ListSamplerStates . empty ( ) ) ;
for ( TStringSet : : iterator IterSS = ListSamplerStates . begin ( ) ; IterSS ! = ListSamplerStates . end ( ) ; + + IterSS )
{
if ( IterSS = = ListSamplerStates . begin ( ) )
{
SamplerStates + = " [ " ;
}
else
{
SamplerStates + = " , " ;
}
SamplerStates + = * IterSS ;
}
SamplerStates + = " ] " ;
}
ralloc_asprintf_append (
buffer ,
" %s%s(%u:%u%s) " ,
bNeedsComma ? " , " : " " ,
Sampler . Name . c_str ( ) ,
Sampler . offset ,
Sampler . num_components ,
SamplerStates . c_str ( )
) ;
bNeedsComma = true ;
}
/*
for ( TStringToSetMap : : iterator Iter = state - > TextureToSamplerMap . begin ( ) ; Iter ! = state - > TextureToSamplerMap . end ( ) ; + + Iter )
{
2015-12-10 16:56:55 -05:00
const FCustomStdString & Texture = Iter - > first ;
2014-09-25 14:27:21 -04:00
TStringSet & Samplers = Iter - > second ;
if ( ! Samplers . empty ( ) )
{
if ( bFirstTexture )
{
bFirstTexture = false ;
}
else
{
ralloc_asprintf_append ( buffer , " , " ) ;
}
ralloc_asprintf_append ( buffer , " %s( " , Texture . c_str ( ) ) ;
bool bFirstSampler = true ;
for ( TStringSet : : iterator IterSamplers = Samplers . begin ( ) ; IterSamplers ! = Samplers . end ( ) ; + + IterSamplers )
{
if ( bFirstSampler )
{
bFirstSampler = false ;
}
else
{
ralloc_asprintf_append ( buffer , " , " ) ;
}
ralloc_asprintf_append ( buffer , " %s " , IterSamplers - > c_str ( ) ) ;
}
ralloc_asprintf_append ( buffer , " ) " ) ;
}
}
*/
}
bool PrintPackedUniforms ( bool bPrintArrayType , char ArrayType , _mesa_glsl_parse_state : : TUniformList & Uniforms , bool bFlattenUniformBuffers , bool NeedsComma )
{
bool bPrintHeader = true ;
for ( glsl_packed_uniform & Uniform : Uniforms )
{
if ( ! bFlattenUniformBuffers | | Uniform . CB_PackedSampler . empty ( ) )
{
if ( bPrintArrayType & & bPrintHeader )
{
ralloc_asprintf_append ( buffer , " %s%c[ " ,
NeedsComma ? " , " : " " ,
ArrayType ) ;
bPrintHeader = false ;
NeedsComma = false ;
}
ralloc_asprintf_append (
buffer ,
" %s%s(%u:%u) " ,
NeedsComma ? " , " : " " ,
Uniform . Name . c_str ( ) ,
Uniform . offset ,
Uniform . num_components
) ;
NeedsComma = true ;
}
}
if ( bPrintArrayType & & ! bPrintHeader )
{
ralloc_asprintf_append ( buffer , " ] " ) ;
}
return NeedsComma ;
}
void PrintPackedGlobals ( _mesa_glsl_parse_state * State )
{
// @PackedGlobals: Global0(DestArrayType, DestOffset, SizeInFloats), Global1(DestArrayType, DestOffset, SizeInFloats), ...
bool bNeedsHeader = true ;
bool bNeedsComma = false ;
for ( auto & Pair : State - > GlobalPackedArraysMap )
{
char ArrayType = Pair . first ;
if ( ArrayType ! = EArrayType_Image & & ArrayType ! = EArrayType_Sampler )
{
_mesa_glsl_parse_state : : TUniformList & Uniforms = Pair . second ;
check ( ! Uniforms . empty ( ) ) ;
for ( auto Iter = Uniforms . begin ( ) ; Iter ! = Uniforms . end ( ) ; + + Iter )
{
glsl_packed_uniform & Uniform = * Iter ;
if ( ! State - > bFlattenUniformBuffers | | Uniform . CB_PackedSampler . empty ( ) )
{
if ( bNeedsHeader )
{
ralloc_asprintf_append ( buffer , " // @PackedGlobals: " ) ;
bNeedsHeader = false ;
}
ralloc_asprintf_append (
buffer ,
" %s%s(%c:%u,%u) " ,
bNeedsComma ? " , " : " " ,
Uniform . Name . c_str ( ) ,
ArrayType ,
Uniform . offset ,
Uniform . num_components
) ;
bNeedsComma = true ;
}
}
}
}
if ( ! bNeedsHeader )
{
ralloc_asprintf_append ( buffer , " \n " ) ;
}
}
void PrintPackedUniformBuffers ( _mesa_glsl_parse_state * State , bool bGroupFlattenedUBs )
{
// @PackedUB: UniformBuffer0(SourceIndex0): Member0(SourceOffset,SizeInFloats),Member1(SourceOffset,SizeInFloats), ...
// @PackedUB: UniformBuffer1(SourceIndex1): Member0(SourceOffset,SizeInFloats),Member1(SourceOffset,SizeInFloats), ...
// ...
// First find all used CBs (since we lost that info during flattening)
TStringSet UsedCBs ;
for ( auto IterCB = State - > CBPackedArraysMap . begin ( ) ; IterCB ! = State - > CBPackedArraysMap . end ( ) ; + + IterCB )
{
for ( auto Iter = IterCB - > second . begin ( ) ; Iter ! = IterCB - > second . end ( ) ; + + Iter )
{
_mesa_glsl_parse_state : : TUniformList & Uniforms = Iter - > second ;
for ( auto IterU = Uniforms . begin ( ) ; IterU ! = Uniforms . end ( ) ; + + IterU )
{
if ( ! IterU - > CB_PackedSampler . empty ( ) )
{
check ( IterCB - > first = = IterU - > CB_PackedSampler ) ;
UsedCBs . insert ( IterU - > CB_PackedSampler ) ;
}
}
}
}
check ( UsedCBs . size ( ) = = State - > CBPackedArraysMap . size ( ) ) ;
// Now get the CB index based off source declaration order, and print an info line for each, while creating the mem copy list
unsigned CBIndex = 0 ;
TCBDMARangeMap CBRanges ;
for ( unsigned i = 0 ; i < State - > num_uniform_blocks ; i + + )
{
const glsl_uniform_block * block = State - > uniform_blocks [ i ] ;
if ( UsedCBs . find ( block - > name ) ! = UsedCBs . end ( ) )
{
bool bNeedsHeader = true ;
// Now the members for this CB
bool bNeedsComma = false ;
auto IterPackedArrays = State - > CBPackedArraysMap . find ( block - > name ) ;
check ( IterPackedArrays ! = State - > CBPackedArraysMap . end ( ) ) ;
for ( auto Iter = IterPackedArrays - > second . begin ( ) ; Iter ! = IterPackedArrays - > second . end ( ) ; + + Iter )
{
char ArrayType = Iter - > first ;
check ( ArrayType ! = EArrayType_Image & & ArrayType ! = EArrayType_Sampler ) ;
_mesa_glsl_parse_state : : TUniformList & Uniforms = Iter - > second ;
for ( auto IterU = Uniforms . begin ( ) ; IterU ! = Uniforms . end ( ) ; + + IterU )
{
glsl_packed_uniform & Uniform = * IterU ;
if ( Uniform . CB_PackedSampler = = block - > name )
{
if ( bNeedsHeader )
{
2016-04-13 12:14:19 -04:00
ralloc_asprintf_append ( buffer , " // @PackedUB: %s(%u): " ,
2014-09-25 14:27:21 -04:00
block - > name ,
CBIndex ) ;
bNeedsHeader = false ;
}
ralloc_asprintf_append ( buffer , " %s%s(%u,%u) " ,
bNeedsComma ? " , " : " " ,
Uniform . Name . c_str ( ) ,
Uniform . OffsetIntoCBufferInFloats ,
Uniform . SizeInFloats ) ;
bNeedsComma = true ;
unsigned SourceOffset = Uniform . OffsetIntoCBufferInFloats ;
unsigned DestOffset = Uniform . offset ;
unsigned Size = Uniform . SizeInFloats ;
unsigned DestCBIndex = bGroupFlattenedUBs ? std : : distance ( UsedCBs . begin ( ) , UsedCBs . find ( block - > name ) ) : 0 ;
unsigned DestCBPrecision = ArrayType ;
InsertRange ( CBRanges , CBIndex , SourceOffset , Size , DestCBIndex , DestCBPrecision , DestOffset ) ;
}
}
}
if ( ! bNeedsHeader )
{
ralloc_asprintf_append ( buffer , " \n " ) ;
}
CBIndex + + ;
}
}
//DumpSortedRanges(SortRanges(CBRanges));
// @PackedUBCopies: SourceArray:SourceOffset-DestArray:DestOffset,SizeInFloats;SourceArray:SourceOffset-DestArray:DestOffset,SizeInFloats,...
bool bFirst = true ;
for ( auto & Pair : CBRanges )
{
TDMARangeList & List = Pair . second ;
for ( auto IterList = List . begin ( ) ; IterList ! = List . end ( ) ; + + IterList )
{
if ( bFirst )
{
ralloc_asprintf_append ( buffer , bGroupFlattenedUBs ? " // @PackedUBCopies: " : " // @PackedUBGlobalCopies: " ) ;
bFirst = false ;
}
else
{
ralloc_asprintf_append ( buffer , " , " ) ;
}
if ( bGroupFlattenedUBs )
{
2016-04-13 12:14:19 -04:00
ralloc_asprintf_append ( buffer , " %u:%u-%u:%c:%u:%u " , IterList - > SourceCB , IterList - > SourceOffset , IterList - > DestCBIndex , IterList - > DestCBPrecision , IterList - > DestOffset , IterList - > Size ) ;
2014-09-25 14:27:21 -04:00
}
else
{
check ( IterList - > DestCBIndex = = 0 ) ;
2016-04-13 12:14:19 -04:00
ralloc_asprintf_append ( buffer , " %u:%u-%c:%u:%u " , IterList - > SourceCB , IterList - > SourceOffset , IterList - > DestCBPrecision , IterList - > DestOffset , IterList - > Size ) ;
2014-09-25 14:27:21 -04:00
}
}
}
if ( ! bFirst )
{
ralloc_asprintf_append ( buffer , " \n " ) ;
}
}
void PrintPackedUniforms ( _mesa_glsl_parse_state * State , bool bGroupFlattenedUBs )
{
PrintPackedGlobals ( State ) ;
if ( State - > bFlattenUniformBuffers & & ! State - > CBuffersOriginal . empty ( ) )
{
PrintPackedUniformBuffers ( State , bGroupFlattenedUBs ) ;
}
}
/**
* Print a list of external variables .
*/
void print_extern_vars ( _mesa_glsl_parse_state * State , exec_list * extern_vars )
{
const char * type_str [ GLSL_TYPE_MAX ] = { " u " , " i " , " f " , " f " , " b " , " t " , " ? " , " ? " , " ? " , " ? " , " s " , " os " , " im " , " ip " , " op " } ;
const char * col_str [ ] = { " " , " " , " 2x " , " 3x " , " 4x " } ;
const char * row_str [ ] = { " " , " 1 " , " 2 " , " 3 " , " 4 " } ;
check ( sizeof ( type_str ) / sizeof ( char * ) = = GLSL_TYPE_MAX ) ;
bool need_comma = false ;
foreach_iter ( exec_list_iterator , iter , * extern_vars )
{
ir_variable * var = ( ( extern_var * ) iter . get ( ) ) - > var ;
const glsl_type * type = var - > type ;
if ( ! strcmp ( var - > name , " gl_in " ) )
{
// Ignore it, as we can't properly frame this information in current format, and it's not used anyway for geometry shaders
continue ;
}
if ( ! strncmp ( var - > name , " in_ " , 3 ) | | ! strncmp ( var - > name , " out_ " , 4 ) )
{
if ( type - > is_record ( ) )
{
// This is the specific case for GLSL >= 150, as we generate a struct with a member for each interpolator (which we still want to count)
if ( type - > length ! = 1 )
{
_mesa_glsl_warning ( State , " Found a complex structure as in/out, counting is not implemented yet... \n " ) ;
continue ;
}
type = type - > fields . structure - > type ;
}
}
Copying //UE4/Dev-Core to //UE4/Dev-Main (Source: //UE4/Dev-Core @ 2996057)
==========================
MAJOR FEATURES + CHANGES
==========================
Change 2975196 on 2016/05/12 by Robert.Manuszewski
Garbage Collector will no longer be responsible for generating class token stream, instead the token stream will be generated on startup or when a class has finished loading.
- This way we can avoid very long GC times after new blueprints have been loaded.
- Temporarily enabled CLASS_TokenStreamAssembled check in development builds (for testing purposes)
Change 2993960 on 2016/05/30 by Robert.Manuszewski
Fixing leaked linkers created by blocking load requests during async loading.
Change 2959398 on 2016/04/28 by Steve.Robb
TMap references are strong and cannot be nulled by pending kill. This makes references in values strong too, even though we only really care about keys, which will corrupt the map when nulled.
#jira UE-20828
Change 2960723 on 2016/04/29 by Graeme.Thornton
Fix for texture asset import data being ignored when async loaded
Change 2960938 on 2016/04/29 by Robert.Manuszewski
Nulling out sql db handle after closing it.
Change 2967127 on 2016/05/05 by Steve.Robb
Move constructors explicitly disabled in generated code.
Change 2967143 on 2016/05/05 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2967164 on 2016/05/05 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer
Change 2968650 on 2016/05/06 by Steve.Robb
Fix for HotReload copying module manager.
Change 2968915 on 2016/05/06 by Robert.Manuszewski
Fixing spelling of SetImageIntegrityStatus function name.
Change 2970406 on 2016/05/09 by Steve.Robb
Static analysis fixes:
Function uses '...' bytes of stack: exceeds /analyze:stacksize '81940'. Consider moving some data to heap.
Change 2970419 on 2016/05/09 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
warning C6011: Dereferencing NULL pointer '...'.
warning C6385: Reading invalid data from '...': the readable size is '...' bytes, but '...' bytes may be read.
warning C6386: Buffer overrun while writing to '...': the writable size is '...' bytes, but '...' bytes might be written.
Change 2970431 on 2016/05/09 by Steve.Robb
Static analysis fixes:
warning C6299: Explicitly comparing a bit field to a Boolean type will yield unexpected results.
Change 2972032 on 2016/05/10 by Steven.Hutton
Workflow fixes to bugg / crashgroup filtering. Filters should now correctly persist across queries.
Change 2972085 on 2016/05/10 by Steve.Robb
Const-correctness fix for FLogCategoryBase::IsSuppressed.
Change 2972087 on 2016/05/10 by Steve.Robb
ELogVerbosity moved into its own header.
Change 2972090 on 2016/05/10 by Steve.Robb
Redundant ensure removed.
Change 2972103 on 2016/05/10 by Steve.Robb
Removal of redundant use of USING_CODE_ANALYSIS.
Change 2972139 on 2016/05/10 by Steve.Robb
Fix for ensure macros throwing C6326 warnings during static analysis.
Change 2972147 on 2016/05/10 by Steve.Robb
Fix for UE_LOG_ACTIVE macro throwing C6326 warnings during static analysis.
Change 2972162 on 2016/05/10 by Steve.Robb
SCOPE_CYCLE_COUNTER_GUARD removed.
Change 2972168 on 2016/05/10 by Steve.Robb
Compile error fix for logOrEnsureNanError in static analysis builds.
Change 2973084 on 2016/05/10 by Chris.Wood
Crash Report Server performance tweak
Change 2974030 on 2016/05/11 by Steve.Robb
Fix for IPropertyHandle::SetValue - used to take a non-const reference to a const UObject*, now it takes const references to both non-const and const UObject*.
Change 2974053 on 2016/05/11 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2974191 on 2016/05/11 by Steve.Robb
Fix for template instantiation error in VS2013.
Change 2975298 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.
Change 2975318 on 2016/05/12 by Steve.Robb
Fix for hot reload info being reported as warnings.
#jira UE-30586
Change 2975447 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
warning C6285: (<non-zero constant> || <non-zero constant>) is always a non-zero constant. Did you intend to use the bitwise-and operator?
warning C6286: (<non-zero constant> || <expression>) is always a non-zero constant. <expression> is never evaluated and might have side effects.
warning C6289: Incorrect operator: mutual exclusion over || is always a non-zero constant. Did you intend to use && instead?
warning C6316: Incorrect operator: tested expression is constant and non-zero. Use bitwise-and to determine whether bits are set.
Change 2975478 on 2016/05/12 by Steve.Robb
Static analysis fixes for lots of redundant <zero constant> and <non-zero constant> warnings.
Change 2975538 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'StaticResource'
Change 2976640 on 2016/05/13 by Robert.Manuszewski
Fixing crashes caused by token stream generation changes. Making sure the token stream gets re-generated when a class gets re-linked.
#jira UE-30675
Change 2978320 on 2016/05/16 by Steve.Robb
Fix for static analysis warnings in XNA headers.
Change 2978329 on 2016/05/16 by Steve.Robb
Static analysis fixes:
warning C6334: sizeof operator applied to an expression with an operator might yield unexpected results: Parentheses can be used to disambiguate certain usages.
Change 2980222 on 2016/05/17 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'X'.
warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.
Change 2980458 on 2016/05/17 by Chris.Wood
Attempt to fix crash report submission problems from CRP to CR website
[UE-30257] - Crashreports are sometimes missing file attachments
Passing crash GUID so that website can easily check for duplicates in future
Increased request timeout for AddCrash to be longer than website database timeout
Logging retries for future visibility
CRP v.1.1.6
Change 2980639 on 2016/05/17 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'X'.
warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.
Change 2981750 on 2016/05/18 by Steve.Robb
check()s in ContainerAllocationPolicies.h changed to checkSlow()s, as they only exist to check that the container has been written correctly.
Change 2982106 on 2016/05/18 by John.Mahoney
Fixed a crash caused by loading two stat capture files simultaneously in the profiler.
If the user tries to load a capture file while another load is in progress, the previous load is now cancelled and cleaned up before proceeding with the new load.
Made the delegates in FNewStatsReader explicitly specify which profiler instance they are loading data for, instead of relying on the current value of LoadConnection->InstanceId.
This also fixes a crash that occurs when selecting a different capture file in the "Stats dump browser" pane of the profiler (after using Load Folder) while another file is still loading.
Cleaned up some weak pointer usage in the profiler window.
#jira UE-30741
Change 2983366 on 2016/05/19 by Steven.Hutton
Changes for passing crash type directly from CRP to CRW.
Change 2983394 on 2016/05/19 by Steven.Hutton
Minor changes to add crash with more error reporting
Change 2984685 on 2016/05/20 by Robert.Manuszewski
Merging //UE4/Dev-Main @ 2984626 to Dev-Core (//UE4/Dev-Core)
Change 2985143 on 2016/05/20 by Steve.Robb
Missing semi-colons.
Change 2986463 on 2016/05/23 by Steve.Robb
CopyTemp added to make it clear that you want to make a copy (rather than a move, or an accidental copy) at the call site of a function taking rvalue refs.
Change 2986475 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6313: Incorrect operator: zero-valued flag cannot be tested with bitwise-and.
Change 2986476 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6313: Incorrect operator: zero-valued flag cannot be tested with bitwise-and.
Change 2986480 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant
Change 2986515 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6340: Mismatch on sign: 'X' passed as _Param_(N) when some unsigned type is required in call to 'Func'
Change 2986680 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6386: Buffer overrun while writing to 'Ptr': the writable size is 'X' bytes, but 'Y' bytes might be written.
warning C6387: 'Ptr' could be '0': this does not adhere to the specification for the function 'Func'
warning C6031: Return value ignored: 'snprintf'.
warning C6340: Mismatch on sign: 'const unsigned int' passed as _Param_(4) when some signed type is required in call to 'snprintf'.
Change 2986865 on 2016/05/23 by Robert.Manuszewski
Removing redundand AddReferencedObjects functions
Change 2987968 on 2016/05/24 by Robert.Manuszewski
Removing redundant UPROPERTY macros from intrinsic classes.
Change 2987979 on 2016/05/24 by Steve.Robb
Optimization of some FString and FPaths operations to produce fewer temporaries.
Change 2988297 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6287: Redundant code: the left and right sub-expressions are identical.
Change 2988430 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6385: Reading invalid data from 'var': the readable size is 'X' bytes, but 'Y' bytes may be read.
Change 2988461 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.
Change 2988464 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6262: Function uses 'X' bytes of stack: exceeds /analyze:stacksize 'Y'. Consider moving some data to heap.
Change 2988494 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6237: (<zero> && <expression>) is always zero. <expression> is never evaluated and might have side effects.
Change 2989411 on 2016/05/25 by Robert.Manuszewski
Splitting GC cluster index and intenral object flags to allow more UObjects in editor builds.
Change 2989429 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6387: '_Param_(X)' could be '0': this does not adhere to the specification for the function 'Func'.
Change 2989982 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6001: Using uninitialized memory 'LODPlanesMin'.
Change 2990018 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6386: Buffer overrun while writing to 'X'
Change 2990077 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2990114 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent.
Change 2990125 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
Change 2990162 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6294: Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
Change 2990193 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C28182: Dereferencing NULL pointer. 'type' contains the same NULL value as 'type->base_type' did.
warning C6011: Dereferencing NULL pointer 'Semantic'.
Change 2991006 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C28113: Accessing a local variable dummy via an Interlocked function: This is an unusual usage which could be reconsidered.
Change 2991012 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6031: Return value ignored: 'InitializeCriticalSectionAndSpinCount'.
Change 2991013 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6287: Redundant code: the left and right sub-expressions are identical.
Change 2991016 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.
Change 2991017 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2991019 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6292: Ill-defined for-loop: counts up from maximum.
Change 2991023 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6322: Empty _except block.
warning C28251: Inconsistent annotation for 'WinMain': this instance has no annotations.
Change 2991070 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C28182: Dereferencing NULL pointer. 'Ptr1' contains the same NULL value as 'Ptr2' did.
Change 2991416 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2992738 on 2016/05/27 by Steve.Robb
Revert changes to FString::MatchesWildcard.
Change 2992916 on 2016/05/27 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2992960 on 2016/05/27 by Chris.Wood
Optimized P4 access in Crash Report Process and MinidumpDiagostics.
Change 2992964 on 2016/05/27 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2993956 on 2016/05/30 by Robert.Manuszewski
Fixing a crash after adding a new C++ class in the editor - made sure new classes have the token stream assembled after hot-reload.
#jira UE-31309
Change 2993977 on 2016/05/30 by Robert.Manuszewski
Don't wait for all packages to finish loading before PostLoading those which already have.
Change 2994206 on 2016/05/31 by Robert.Manuszewski
PR #2429: Three bug fixes required for script support to work properly (Contributed by pluranium)
#lockdown Nick.Penwarden
[CL 2996251 by Robert Manuszewski in Main branch]
2016-06-01 12:08:56 -04:00
check ( type ) ;
2014-09-25 14:27:21 -04:00
bool is_array = type - > is_array ( ) ;
int array_size = is_array ? type - > length : 0 ;
if ( is_array )
{
type = type - > fields . array ;
}
ralloc_asprintf_append ( buffer , " %s%s%s%s " ,
need_comma ? " , " : " " ,
2015-07-02 11:52:03 -04:00
type - > base_type = = GLSL_TYPE_STRUCT ? type - > name : type_str [ type - > base_type ] ,
2014-09-25 14:27:21 -04:00
col_str [ type - > matrix_columns ] ,
row_str [ type - > vector_elements ] ) ;
if ( is_array )
{
ralloc_asprintf_append ( buffer , " [%u] " , array_size ) ;
}
2015-02-06 11:35:30 -05:00
ralloc_asprintf_append ( buffer , " ;%d:%s " , var - > location , var - > name ) ;
2014-09-25 14:27:21 -04:00
need_comma = true ;
}
}
/**
* Print the input / output signature for this shader .
*/
void print_signature ( _mesa_glsl_parse_state * state , bool bGroupFlattenedUBs )
{
if ( ! input_variables . is_empty ( ) )
{
ralloc_asprintf_append ( buffer , " // @Inputs: " ) ;
print_extern_vars ( state , & input_variables ) ;
ralloc_asprintf_append ( buffer , " \n " ) ;
}
if ( ! output_variables . is_empty ( ) )
{
ralloc_asprintf_append ( buffer , " // @Outputs: " ) ;
print_extern_vars ( state , & output_variables ) ;
ralloc_asprintf_append ( buffer , " \n " ) ;
}
if ( state - > num_uniform_blocks > 0 & & ! state - > bFlattenUniformBuffers )
{
bool first = true ;
int Index = 0 ;
for ( unsigned i = 0 ; i < state - > num_uniform_blocks ; i + + )
{
const glsl_uniform_block * block = state - > uniform_blocks [ i ] ;
if ( hash_table_find ( used_uniform_blocks , block - > name ) )
{
ralloc_asprintf_append ( buffer , " %s%s(%d) " ,
first ? " // @UniformBlocks: " : " , " ,
block - > name , Index ) ;
first = false ;
+ + Index ;
}
}
if ( ! first )
{
ralloc_asprintf_append ( buffer , " \n " ) ;
}
}
if ( state - > has_packed_uniforms )
{
PrintPackedUniforms ( state , bGroupFlattenedUBs ) ;
if ( ! state - > GlobalPackedArraysMap [ EArrayType_Sampler ] . empty ( ) )
{
ralloc_asprintf_append ( buffer , " // @Samplers: " ) ;
PrintPackedSamplers (
state - > GlobalPackedArraysMap [ EArrayType_Sampler ] ,
state - > TextureToSamplerMap
) ;
ralloc_asprintf_append ( buffer , " \n " ) ;
}
if ( ! state - > GlobalPackedArraysMap [ EArrayType_Image ] . empty ( ) )
{
ralloc_asprintf_append ( buffer , " // @UAVs: " ) ;
PrintPackedUniforms (
false ,
EArrayType_Image ,
state - > GlobalPackedArraysMap [ EArrayType_Image ] ,
false ,
false
) ;
ralloc_asprintf_append ( buffer , " \n " ) ;
}
}
else
{
if ( ! uniform_variables . is_empty ( ) )
{
ralloc_asprintf_append ( buffer , " // @Uniforms: " ) ;
print_extern_vars ( state , & uniform_variables ) ;
ralloc_asprintf_append ( buffer , " \n " ) ;
}
if ( ! sampler_variables . is_empty ( ) )
{
ralloc_asprintf_append ( buffer , " // @Samplers: " ) ;
print_extern_vars ( state , & sampler_variables ) ;
ralloc_asprintf_append ( buffer , " \n " ) ;
}
if ( ! image_variables . is_empty ( ) )
{
ralloc_asprintf_append ( buffer , " // @UAVs: " ) ;
print_extern_vars ( state , & image_variables ) ;
ralloc_asprintf_append ( buffer , " \n " ) ;
}
}
}
/**
* Print the layout directives for this shader .
*/
void print_layout ( _mesa_glsl_parse_state * state )
{
if ( early_depth_stencil )
{
ralloc_asprintf_append ( buffer , " layout(early_fragment_tests) in; \n " ) ;
}
if ( state - > target = = compute_shader )
{
ralloc_asprintf_append ( buffer , " layout( local_size_x = %d, "
" local_size_y = %d, local_size_z = %d ) in; \n " , wg_size_x ,
wg_size_y , wg_size_z ) ;
}
if ( state - > target = = tessellation_control_shader )
{
ralloc_asprintf_append ( buffer , " layout(vertices = %d) out; \n " , tessellation . outputcontrolpoints ) ;
}
if ( state - > target = = tessellation_evaluation_shader )
{
2015-12-10 16:56:55 -05:00
std : : basic_stringstream < char , std : : char_traits < char > , FCustomStdAllocator < char > > str ;
2014-09-25 14:27:21 -04:00
switch ( tessellation . outputtopology )
{
// culling is inverted, see TranslateCullMode in the OpenGL and D3D11 RHI
case GLSL_OUTPUTTOPOLOGY_POINT :
str < < " point_mode " ;
break ;
case GLSL_OUTPUTTOPOLOGY_LINE :
str < < " iso_lines " ;
break ;
default :
case GLSL_OUTPUTTOPOLOGY_NONE :
case GLSL_OUTPUTTOPOLOGY_TRIANGLE_CW :
str < < " triangles, ccw " ;
break ;
case GLSL_OUTPUTTOPOLOGY_TRIANGLE_CCW :
str < < " triangles, cw " ;
break ;
}
switch ( tessellation . partitioning )
{
default :
case GLSL_PARTITIONING_NONE :
case GLSL_PARTITIONING_INTEGER :
str < < " , equal_spacing " ;
break ;
case GLSL_PARTITIONING_FRACTIONAL_EVEN :
str < < " , fractional_even_spacing " ;
break ;
case GLSL_PARTITIONING_FRACTIONAL_ODD :
str < < " , fractional_odd_spacing " ;
break ;
// that assumes that the hull/control shader clamps the tessellation factors to be power of two
case GLSL_PARTITIONING_POW2 :
str < < " , equal_spacing " ;
break ;
}
ralloc_asprintf_append ( buffer , " layout(%s) in; \n " , str . str ( ) . c_str ( ) ) ;
}
#if 0
if ( state - > target = = tessellation_evaluation_shader | | state - > target = = tessellation_control_shader )
{
ralloc_asprintf_append ( buffer , " /* DEBUG DUMP \n " ) ;
ralloc_asprintf_append ( buffer , " tessellation.domain = %s \n " , DomainStrings [ tessellation . domain ] ) ;
ralloc_asprintf_append ( buffer , " tessellation.outputtopology = %s \n " , OutputTopologyStrings [ tessellation . outputtopology ] ) ;
ralloc_asprintf_append ( buffer , " tessellation.partitioning = %s \n " , PartitioningStrings [ tessellation . partitioning ] ) ;
ralloc_asprintf_append ( buffer , " tessellation.maxtessfactor = %f \n " , tessellation . maxtessfactor ) ;
ralloc_asprintf_append ( buffer , " tessellation.outputcontrolpoints = %d \n " , tessellation . outputcontrolpoints ) ;
ralloc_asprintf_append ( buffer , " tessellation.patchconstantfunc = %s \n " , tessellation . patchconstantfunc ) ;
ralloc_asprintf_append ( buffer , " */ \n " ) ;
}
# endif
}
2015-06-25 02:07:29 -04:00
void print_extensions ( _mesa_glsl_parse_state * state , bool bUsesFramebufferFetchES2 , bool bUsesDepthbufferFetchES2 , bool bUsesES31Extensions )
2014-09-25 14:27:21 -04:00
{
if ( bUsesES2TextureLODExtension )
{
ralloc_asprintf_append ( buffer , " #ifndef DONTEMITEXTENSIONSHADERTEXTURELODENABLE \n " ) ;
ralloc_asprintf_append ( buffer , " #extension GL_EXT_shader_texture_lod : enable \n " ) ;
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
}
2015-03-18 16:16:25 -04:00
if ( state - > bSeparateShaderObjects & & ! state - > bGenerateES & &
2015-03-18 18:27:58 -04:00
( ( state - > target = = tessellation_control_shader ) | | ( state - > target = = tessellation_evaluation_shader ) ) )
2015-03-18 16:16:25 -04:00
{
ralloc_asprintf_append ( buffer , " #extension GL_ARB_tessellation_shader : enable \n " ) ;
}
2014-09-25 14:27:21 -04:00
if ( bUsesDXDY & & bIsES )
{
ralloc_asprintf_append ( buffer , " #extension GL_OES_standard_derivatives : enable \n " ) ;
}
2015-12-09 15:04:15 -05:00
if ( bUsesInstanceID & & bIsES )
{
ralloc_asprintf_append ( buffer , " #ifdef GL_EXT_draw_instanced \n " ) ;
ralloc_asprintf_append ( buffer , " #extension GL_EXT_draw_instanced : enable \n " ) ;
ralloc_asprintf_append ( buffer , " #define gl_InstanceID gl_InstanceIDEXT \n " ) ;
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
}
2014-09-25 14:27:21 -04:00
if ( bUsesFramebufferFetchES2 )
{
ralloc_asprintf_append ( buffer , " \n #ifdef GL_EXT_shader_framebuffer_fetch \n " ) ;
ralloc_asprintf_append ( buffer , " #extension GL_EXT_shader_framebuffer_fetch : enable \n " ) ;
2016-02-11 09:44:56 -05:00
ralloc_asprintf_append ( buffer , " #define EXT_shader_framebuffer_fetch_enabled 1 \n " ) ;
2014-09-25 14:27:21 -04:00
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
2015-07-15 06:39:44 -04:00
ralloc_asprintf_append ( buffer , " \n #ifdef GL_ARM_shader_framebuffer_fetch \n " ) ;
ralloc_asprintf_append ( buffer , " #extension GL_ARM_shader_framebuffer_fetch : enable \n " ) ;
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
2014-09-25 14:27:21 -04:00
}
2015-06-25 02:07:29 -04:00
if ( bUsesDepthbufferFetchES2 )
{
ralloc_asprintf_append ( buffer , " #extension GL_ARM_shader_framebuffer_fetch_depth_stencil : enable \n " ) ;
}
2014-09-25 14:27:21 -04:00
if ( bUsesES31Extensions )
{
ralloc_asprintf_append ( buffer , " #extension GL_EXT_gpu_shader5 : enable \n " ) ;
ralloc_asprintf_append ( buffer , " #extension GL_EXT_texture_buffer : enable \n " ) ;
ralloc_asprintf_append ( buffer , " #extension GL_EXT_texture_cube_map_array : enable \n " ) ;
ralloc_asprintf_append ( buffer , " #extension GL_EXT_shader_io_blocks : enable \n " ) ;
if ( ShaderTarget = = geometry_shader )
{
ralloc_asprintf_append ( buffer , " #extension GL_EXT_geometry_shader : enable \n " ) ;
}
if ( ShaderTarget = = tessellation_control_shader | | ShaderTarget = = tessellation_evaluation_shader )
{
ralloc_asprintf_append ( buffer , " #extension GL_EXT_tessellation_shader : enable \n " ) ;
2015-02-06 11:35:30 -05:00
}
2014-09-25 14:27:21 -04:00
}
}
public :
/** Constructor. */
2016-06-13 12:20:22 -04:00
ir_gen_glsl_visitor ( bool bInIsES , bool bInEmitPrecision , bool bInIsES31 , _mesa_glsl_parser_targets InShaderTarget , bool bInGenerateLayoutLocations , bool bInDefaultPrecisionIsHalf )
2014-09-25 14:27:21 -04:00
: early_depth_stencil ( false )
, bIsES ( bInIsES )
2015-06-18 14:24:11 -04:00
, bEmitPrecision ( bInEmitPrecision )
2015-06-19 19:28:40 -04:00
, bIsES31 ( bInIsES31 )
2014-09-25 14:27:21 -04:00
, ShaderTarget ( InShaderTarget )
, bGenerateLayoutLocations ( bInGenerateLayoutLocations )
2016-06-13 12:20:22 -04:00
, bDefaultPrecisionIsHalf ( bInDefaultPrecisionIsHalf )
2014-09-25 14:27:21 -04:00
, buffer ( 0 )
, indentation ( 0 )
, scope_depth ( 0 )
, temp_id ( 0 )
, global_id ( 0 )
, needs_semicolon ( false )
, should_print_uint_literals_as_ints ( false )
, loop_count ( 0 )
, bUsesES2TextureLODExtension ( false )
, bUsesDXDY ( false )
2015-12-09 15:04:15 -05:00
, bUsesInstanceID ( false )
2014-09-25 14:27:21 -04:00
{
printable_names = hash_table_ctor ( 32 , hash_table_pointer_hash , hash_table_pointer_compare ) ;
used_structures = hash_table_ctor ( 32 , hash_table_pointer_hash , hash_table_pointer_compare ) ;
used_uniform_blocks = hash_table_ctor ( 32 , hash_table_string_hash , hash_table_string_compare ) ;
}
/** Destructor. */
virtual ~ ir_gen_glsl_visitor ( )
{
hash_table_dtor ( printable_names ) ;
hash_table_dtor ( used_structures ) ;
hash_table_dtor ( used_uniform_blocks ) ;
}
/**
* Executes the visitor on the provided ir .
* @ returns the GLSL source code generated .
*/
const char * run ( exec_list * ir , _mesa_glsl_parse_state * state , bool bGroupFlattenedUBs )
{
mem_ctx = ralloc_context ( NULL ) ;
char * code_buffer = ralloc_asprintf ( mem_ctx , " " ) ;
buffer = & code_buffer ;
2015-06-18 14:24:11 -04:00
if ( bEmitPrecision & & ! ( ShaderTarget = = vertex_shader ) )
2014-09-25 14:27:21 -04:00
{
// TODO: Improve this...
2016-06-13 12:20:22 -04:00
const char * DefaultPrecision = bDefaultPrecisionIsHalf ? " mediump " : " highp " ;
2014-09-25 14:27:21 -04:00
ralloc_asprintf_append ( buffer , " precision %s float; \n " , DefaultPrecision ) ;
ralloc_asprintf_append ( buffer , " precision %s int; \n " , DefaultPrecision ) ;
ralloc_asprintf_append ( buffer , " \n #ifndef DONTEMITSAMPLERDEFAULTPRECISION \n " ) ;
ralloc_asprintf_append ( buffer , " precision %s sampler2D; \n " , DefaultPrecision ) ;
ralloc_asprintf_append ( buffer , " precision %s samplerCube; \n \n " , DefaultPrecision ) ;
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
2015-05-01 10:48:11 -04:00
// SGX540 compiler can get upset with some operations that mix highp and mediump.
// this results in a shader compile fail with output "compile failed."
// Although the actual cause of the failure hasnt been determined this code appears to prevent
// compile failure for cases so far seen.
ralloc_asprintf_append ( buffer , " \n #ifdef TEXCOORDPRECISIONWORKAROUND \n " ) ;
ralloc_asprintf_append ( buffer , " vec4 texture2DTexCoordPrecisionWorkaround(sampler2D p, vec2 tcoord) \n " ) ;
ralloc_asprintf_append ( buffer , " { \n " ) ;
ralloc_asprintf_append ( buffer , " return texture2D(p, tcoord); \n " ) ;
ralloc_asprintf_append ( buffer , " } \n " ) ;
ralloc_asprintf_append ( buffer , " #define texture2D texture2DTexCoordPrecisionWorkaround \n " ) ;
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
2014-09-25 14:27:21 -04:00
}
2015-06-18 14:24:11 -04:00
if ( ( state - > language_version = = 310 ) & & ( ShaderTarget = = fragment_shader ) & & bEmitPrecision )
2014-09-25 14:27:21 -04:00
{
ralloc_asprintf_append ( buffer , " precision %s float; \n " , " highp " ) ;
ralloc_asprintf_append ( buffer , " precision %s int; \n " , " highp " ) ;
}
// FramebufferFetchES2 'intrinsic'
2015-07-15 06:39:44 -04:00
bool bUsesFramebufferFetchES2 = UsesUEIntrinsic ( ir , FRAMEBUFFER_FETCH_ES2 ) ;
2014-09-25 14:27:21 -04:00
if ( bUsesFramebufferFetchES2 )
{
ralloc_asprintf_append ( buffer , " \n #ifdef GL_EXT_shader_framebuffer_fetch \n " ) ;
2016-02-11 09:44:56 -05:00
ralloc_asprintf_append ( buffer , " #if (__VERSION__ >= 300) \n " ) ;
ralloc_asprintf_append ( buffer , " vec4 FramebufferFetchES2() { return gl_FragColor; } \n " ) ;
ralloc_asprintf_append ( buffer , " #else \n " ) ;
ralloc_asprintf_append ( buffer , " vec4 FramebufferFetchES2() { return gl_LastFragData[0]; } \n " ) ;
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
2014-09-25 14:27:21 -04:00
ralloc_asprintf_append ( buffer , " #else \n " ) ;
2015-07-15 06:39:44 -04:00
ralloc_asprintf_append ( buffer , " #ifdef GL_ARM_shader_framebuffer_fetch \n " ) ;
ralloc_asprintf_append ( buffer , " vec4 FramebufferFetchES2() { return gl_LastFragColorARM; } \n " ) ;
ralloc_asprintf_append ( buffer , " #else \n " ) ;
ralloc_asprintf_append ( buffer , " vec4 FramebufferFetchES2() { return vec4(65000.0, 65000.0, 65000.0, 65000.0); } \n " ) ;
ralloc_asprintf_append ( buffer , " #endif \n " ) ;
2014-09-25 14:27:21 -04:00
ralloc_asprintf_append ( buffer , " #endif \n \n " ) ;
}
2015-07-15 06:39:44 -04:00
bool bUsesDepthbufferFetchES2 = UsesUEIntrinsic ( ir , DEPTHBUFFER_FETCH_ES2 ) ;
2015-06-25 02:07:29 -04:00
if ( bUsesDepthbufferFetchES2 )
{
ralloc_asprintf_append ( buffer , " \n #ifdef GL_ARM_shader_framebuffer_fetch_depth_stencil \n " ) ;
2015-07-28 01:50:06 -04:00
ralloc_asprintf_append ( buffer , " float DepthbufferFetchES2(float OptionalDepth, float C1, float C2) { float w = 1.0f/(gl_LastFragDepthARM*C1-C2); return clamp(w, 0.0f, 65000.0f); } \n " ) ;
2015-06-25 02:07:29 -04:00
ralloc_asprintf_append ( buffer , " #else \n " ) ;
ralloc_asprintf_append ( buffer , " float DepthbufferFetchES2(float OptionalDepth, float C1, float C2) { return OptionalDepth; } \n " ) ;
ralloc_asprintf_append ( buffer , " #endif \n \n " ) ;
}
2015-07-15 06:39:44 -04:00
if ( UsesUEIntrinsic ( ir , GET_HDR_32BPP_HDR_ENCODE_MODE_ES2 ) )
{
ralloc_asprintf_append ( buffer , " \n float %s() { return HDR_32BPP_ENCODE_MODE; } \n " , GET_HDR_32BPP_HDR_ENCODE_MODE_ES2 ) ;
}
2014-09-25 14:27:21 -04:00
foreach_iter ( exec_list_iterator , iter , * ir )
{
ir_instruction * inst = ( ir_instruction * ) iter . get ( ) ;
do_visit ( inst ) ;
}
buffer = 0 ;
char * decl_buffer = ralloc_asprintf ( mem_ctx , " " ) ;
buffer = & decl_buffer ;
declare_structs ( state ) ;
buffer = 0 ;
char * signature = ralloc_asprintf ( mem_ctx , " " ) ;
buffer = & signature ;
print_signature ( state , bGroupFlattenedUBs ) ;
buffer = 0 ;
const char * geometry_layouts = " " ;
if ( state - > maxvertexcount > 0 )
{
check ( state - > geometryinput > 0 ) ;
check ( state - > outputstream_type > 0 ) ;
geometry_layouts = ralloc_asprintf (
mem_ctx ,
2016-04-13 12:14:19 -04:00
" \n layout(%s) in; \n layout(%s, max_vertices = %u) out; \n \n " ,
2014-09-25 14:27:21 -04:00
GeometryInputStrings [ state - > geometryinput ] ,
OutputStreamTypeStrings [ state - > outputstream_type ] ,
state - > maxvertexcount ) ;
}
char * layout = ralloc_asprintf ( mem_ctx , " " ) ;
buffer = & layout ;
print_layout ( state ) ;
buffer = 0 ;
char * Extensions = ralloc_asprintf ( mem_ctx , " " ) ;
buffer = & Extensions ;
2015-06-25 02:07:29 -04:00
print_extensions ( state , bUsesFramebufferFetchES2 , bUsesDepthbufferFetchES2 , state - > language_version = = 310 ) ;
2015-03-18 16:16:25 -04:00
if ( state - > bSeparateShaderObjects & & ! state - > bGenerateES )
2015-02-06 11:35:30 -05:00
{
switch ( state - > target )
{
case geometry_shader :
ralloc_asprintf_append ( buffer , " in gl_PerVertex \n "
" { \n "
" \t vec4 gl_Position; \n "
" \t float gl_ClipDistance[6]; \n "
" } gl_in[]; \n "
) ;
case vertex_shader :
ralloc_asprintf_append ( buffer , " out gl_PerVertex \n "
" { \n "
" \t vec4 gl_Position; \n "
" \t float gl_ClipDistance[6]; \n "
" }; \n "
) ;
break ;
case tessellation_control_shader :
ralloc_asprintf_append ( buffer , " in gl_PerVertex \n "
" { \n "
" \t vec4 gl_Position; \n "
" \t float gl_ClipDistance[6]; \n "
" } gl_in[gl_MaxPatchVertices]; \n "
) ;
ralloc_asprintf_append ( buffer , " out gl_PerVertex \n "
" { \n "
" \t vec4 gl_Position; \n "
" \t float gl_ClipDistance[6]; \n "
" } gl_out[]; \n "
) ;
break ;
case tessellation_evaluation_shader :
ralloc_asprintf_append ( buffer , " in gl_PerVertex \n "
" { \n "
" \t vec4 gl_Position; \n "
" \t float gl_ClipDistance[6]; \n "
" } gl_in[gl_MaxPatchVertices]; \n "
) ;
ralloc_asprintf_append ( buffer , " out gl_PerVertex \n "
" { \n "
" \t vec4 gl_Position; \n "
" \t float gl_ClipDistance[6]; \n "
" }; \n "
) ;
break ;
case fragment_shader :
case compute_shader :
default :
break ;
}
}
2014-09-25 14:27:21 -04:00
buffer = 0 ;
char * full_buffer = ralloc_asprintf (
state ,
" // Compiled by HLSLCC %d.%d \n %s#version %u %s \n %s%s%s%s%s \n " ,
HLSLCC_VersionMajor , HLSLCC_VersionMinor ,
signature ,
state - > language_version ,
state - > language_version = = 310 ? " es " : " " ,
Extensions ,
geometry_layouts ,
layout ,
decl_buffer ,
code_buffer
) ;
ralloc_free ( mem_ctx ) ;
return full_buffer ;
}
} ;
struct FBreakPrecisionChangesVisitor : public ir_rvalue_visitor
{
_mesa_glsl_parse_state * State ;
2016-06-13 12:20:22 -04:00
const bool bDefaultPrecisionIsHalf ;
FBreakPrecisionChangesVisitor ( _mesa_glsl_parse_state * InState , bool bInDefaultPrecisionIsHalf )
: State ( InState )
, bDefaultPrecisionIsHalf ( bInDefaultPrecisionIsHalf )
{ }
2014-09-25 14:27:21 -04:00
virtual void handle_rvalue ( ir_rvalue * * RValuePtr ) override
{
if ( ! RValuePtr | | ! * RValuePtr )
{
return ;
}
bool bGenerateNewVar = false ;
auto * RValue = * RValuePtr ;
auto * Expression = RValue - > as_expression ( ) ;
auto * Constant = RValue - > as_constant ( ) ;
if ( Expression )
{
2016-06-13 12:20:22 -04:00
if ( bDefaultPrecisionIsHalf )
2014-09-25 14:27:21 -04:00
{
switch ( Expression - > operation )
{
case ir_unop_i2f :
case ir_unop_b2f :
case ir_unop_u2f :
2016-06-13 12:20:22 -04:00
bGenerateNewVar = bDefaultPrecisionIsHalf ;
2014-09-25 14:27:21 -04:00
break ;
case ir_unop_i2h :
case ir_unop_b2h :
case ir_unop_u2h :
2016-06-13 12:20:22 -04:00
bGenerateNewVar = ! bDefaultPrecisionIsHalf ;
2014-09-25 14:27:21 -04:00
break ;
case ir_unop_h2f :
case ir_unop_f2h :
if ( ! Expression - > operands [ 0 ] - > as_texture ( ) )
{
bGenerateNewVar = true ;
}
break ;
}
}
}
else if ( Constant )
{
/*
2016-06-13 12:20:22 -04:00
if ( ( bDefaultPrecisionIsHalf & & Constant - > type - > base_type = = GLSL_TYPE_HALF ) | |
( ! bDefaultPrecisionIsHalf & & Constant - > type - > base_type = = GLSL_TYPE_FLOAT ) )
2014-09-25 14:27:21 -04:00
{
bGenerateNewVar = true ;
}
*/
}
if ( bGenerateNewVar )
{
auto * NewVar = new ( State ) ir_variable ( RValue - > type , nullptr , ir_var_temporary ) ;
auto * NewAssignment = new ( State ) ir_assignment ( new ( State ) ir_dereference_variable ( NewVar ) , RValue ) ;
* RValuePtr = new ( State ) ir_dereference_variable ( NewVar ) ;
base_ir - > insert_before ( NewVar ) ;
base_ir - > insert_before ( NewAssignment ) ;
}
}
} ;
void ir_gen_glsl_visitor : : AddTypeToUsedStructs ( const glsl_type * type )
{
if ( type - > base_type = = GLSL_TYPE_STRUCT )
{
if ( hash_table_find ( used_structures , type ) = = NULL )
{
hash_table_insert ( used_structures , ( void * ) type , type ) ;
}
}
if ( type - > base_type = = GLSL_TYPE_ARRAY & & type - > fields . array - > base_type = = GLSL_TYPE_STRUCT )
{
if ( hash_table_find ( used_structures , type - > fields . array ) = = NULL )
{
hash_table_insert ( used_structures , ( void * ) type - > fields . array , type - > fields . array ) ;
}
}
if ( ( type - > base_type = = GLSL_TYPE_INPUTPATCH | | type - > base_type = = GLSL_TYPE_OUTPUTPATCH ) & & type - > inner_type - > base_type = = GLSL_TYPE_STRUCT )
{
if ( hash_table_find ( used_structures , type - > inner_type ) = = NULL )
{
hash_table_insert ( used_structures , ( void * ) type - > inner_type , type - > inner_type ) ;
}
}
}
char * FGlslCodeBackend : : GenerateCode ( exec_list * ir , _mesa_glsl_parse_state * state , EHlslShaderFrequency Frequency )
{
FixRedundantCasts ( ir ) ;
//IRDump(ir);
2016-06-13 12:20:22 -04:00
const bool bDefaultPrecisionIsHalf = ( ( HlslCompileFlags & HLSLCC_UseFullPrecisionInPS ) = = 0 ) ;
FBreakPrecisionChangesVisitor BreakPrecisionChangesVisitor ( state , bDefaultPrecisionIsHalf ) ;
2014-09-25 14:27:21 -04:00
BreakPrecisionChangesVisitor . run ( ir ) ;
const bool bGroupFlattenedUBs = ( ( HlslCompileFlags & HLSLCC_GroupFlattenedUniformBuffers ) = = HLSLCC_GroupFlattenedUniformBuffers ) ;
const bool bGenerateLayoutLocations = state - > bGenerateLayoutLocations ;
2015-06-18 14:24:11 -04:00
const bool bEmitPrecision = ( Target = = HCT_FeatureLevelES2 | | Target = = HCT_FeatureLevelES3_1 | | Target = = HCT_FeatureLevelES3_1Ext ) ;
2016-06-13 12:20:22 -04:00
ir_gen_glsl_visitor visitor ( state - > bGenerateES , bEmitPrecision , ( Target = = HCT_FeatureLevelES3_1Ext ) , state - > target , bGenerateLayoutLocations , bDefaultPrecisionIsHalf ) ;
2014-09-25 14:27:21 -04:00
const char * code = visitor . run ( ir , state , bGroupFlattenedUBs ) ;
return _strdup ( code ) ;
}
// Verify if SampleLevel() is used
struct SPromoteSampleLevelES2 : public ir_hierarchical_visitor
{
_mesa_glsl_parse_state * ParseState ;
const bool bIsVertexShader ;
SPromoteSampleLevelES2 ( _mesa_glsl_parse_state * InParseState , bool bInIsVertexShader ) :
ParseState ( InParseState ) ,
bIsVertexShader ( bInIsVertexShader )
{
}
virtual ir_visitor_status visit_leave ( ir_texture * IR ) override
{
if ( IR - > op = = ir_txl )
{
if ( bIsVertexShader )
{
YYLTYPE loc ;
loc . first_column = IR - > SourceLocation . Column ;
loc . first_line = IR - > SourceLocation . Line ;
2015-03-10 10:40:42 -04:00
loc . source_file = IR - > SourceLocation . SourceFile ;
2014-09-25 14:27:21 -04:00
_mesa_glsl_error ( & loc , ParseState , " Vertex texture fetch currently not supported on GLSL ES \n " ) ;
}
else
{
//@todo-mobile: allowing lod texture functions for now, as they are supported on some devices via glsl extension.
// http://www.khronos.org/registry/gles/extensions/EXT/EXT_shader_texture_lod.txt
// Compat work will be required for devices which do not support it.
/*
2016-04-13 12:14:19 -04:00
_mesa_glsl_warning ( ParseState , " %s(%u, %u) Converting SampleLevel() to Sample() \n " , IR - > SourceLocation . SourceFile . c_str ( ) , IR - > SourceLocation . Line , IR - > SourceLocation . Column ) ;
2014-09-25 14:27:21 -04:00
IR - > op = ir_tex ;
*/
}
}
if ( IR - > offset )
{
YYLTYPE loc ;
loc . first_column = IR - > SourceLocation . Column ;
loc . first_line = IR - > SourceLocation . Line ;
2015-03-10 10:40:42 -04:00
loc . source_file = IR - > SourceLocation . SourceFile ;
2014-09-25 14:27:21 -04:00
_mesa_glsl_error ( & loc , ParseState , " Texture offset not supported on GLSL ES \n " ) ;
}
return visit_continue ;
}
} ;
// Converts an array index expression using an integer input attribute, to a float input attribute using a conversion to int
struct SConvertIntVertexAttributeES2 : public ir_hierarchical_visitor
{
_mesa_glsl_parse_state * ParseState ;
exec_list * FunctionBody ;
int InsideArrayDeref ;
std : : map < ir_variable * , ir_variable * > ConvertedVarMap ;
SConvertIntVertexAttributeES2 ( _mesa_glsl_parse_state * InParseState , exec_list * InFunctionBody ) : ParseState ( InParseState ) , FunctionBody ( InFunctionBody ) , InsideArrayDeref ( 0 )
{
}
virtual ir_visitor_status visit_enter ( ir_dereference_array * DeRefArray ) override
{
// Break the array dereference so we know we want to modify the array index part
auto Result = ir_hierarchical_visitor : : visit_enter ( DeRefArray ) ;
+ + InsideArrayDeref ;
DeRefArray - > array_index - > accept ( this ) ;
- - InsideArrayDeref ;
return visit_continue ;
}
virtual ir_visitor_status visit ( ir_dereference_variable * DeRefVar ) override
{
if ( InsideArrayDeref > 0 )
{
ir_variable * SourceVar = DeRefVar - > var ;
if ( SourceVar - > mode = = ir_var_in )
{
// First time it still is an integer, so add the temporary and a conversion, and switch to float
if ( SourceVar - > type - > is_integer ( ) )
{
check ( SourceVar - > type - > is_integer ( ) & & ! SourceVar - > type - > is_matrix ( ) & & ! SourceVar - > type - > is_array ( ) ) ;
// Double check we haven't processed this
auto IterFound = ConvertedVarMap . find ( SourceVar ) ;
check ( IterFound = = ConvertedVarMap . end ( ) ) ;
// New temp var
ir_variable * NewVar = new ( ParseState ) ir_variable ( SourceVar - > type , NULL , ir_var_temporary ) ;
base_ir - > insert_before ( NewVar ) ;
// Switch original type to float
SourceVar - > type = glsl_type : : get_instance ( GLSL_TYPE_FLOAT , SourceVar - > type - > vector_elements , 1 ) ;
// Convert float to int
ir_dereference_variable * NewSourceDeref = new ( ParseState ) ir_dereference_variable ( SourceVar ) ;
ir_expression * NewCastExpression = new ( ParseState ) ir_expression ( ir_unop_f2i , NewSourceDeref ) ;
ir_assignment * NewAssigment = new ( ParseState ) ir_assignment ( new ( ParseState ) ir_dereference_variable ( NewVar ) , NewCastExpression ) ;
base_ir - > insert_before ( NewAssigment ) ;
// Add the entry and modify the original Var
ConvertedVarMap [ SourceVar ] = NewVar ;
DeRefVar - > var = NewVar ;
}
else
{
auto IterFound = ConvertedVarMap . find ( SourceVar ) ;
if ( IterFound ! = ConvertedVarMap . end ( ) )
{
DeRefVar - > var = IterFound - > second ;
}
}
}
}
return ir_hierarchical_visitor : : visit ( DeRefVar ) ;
}
} ;
bool FGlslCodeBackend : : ApplyAndVerifyPlatformRestrictions ( exec_list * Instructions , _mesa_glsl_parse_state * ParseState , EHlslShaderFrequency Frequency )
{
if ( ParseState - > bGenerateES )
{
bool bIsVertexShader = ( Frequency = = HSF_VertexShader ) ;
// Handle SampleLevel
{
SPromoteSampleLevelES2 Visitor ( ParseState , bIsVertexShader ) ;
Visitor . run ( Instructions ) ;
}
// Handle matrices (flatten to vectors so we can support non-sqaure)
ExpandMatricesIntoArrays ( Instructions , ParseState ) ;
// Handle integer vertex attributes used as array indices
if ( bIsVertexShader )
{
SConvertIntVertexAttributeES2 ConvertIntVertexAttributeVisitor ( ParseState , Instructions ) ;
ConvertIntVertexAttributeVisitor . run ( Instructions ) ;
}
}
return true ;
}
/** Qualifers that apply to semantics. */
union FSemanticQualifier
{
struct
{
unsigned bCentroid : 1 ;
unsigned InterpolationMode : 2 ;
unsigned bIsPatchConstant : 1 ;
} Fields ;
unsigned Packed ;
FSemanticQualifier ( ) : Packed ( 0 ) { }
} ;
/** Information on system values. */
struct FSystemValue
{
const char * Semantic ;
const glsl_type * Type ;
const char * GlslName ;
ir_variable_mode Mode ;
bool bOriginUpperLeft ;
bool bArrayVariable ;
bool bApplyClipSpaceAdjustment ;
bool bESOnly ;
} ;
/** Vertex shader system values. */
static FSystemValue VertexSystemValueTable [ ] =
{
{ " SV_VertexID " , glsl_type : : int_type , " gl_VertexID " , ir_var_in , false , false , false , false } ,
{ " SV_InstanceID " , glsl_type : : int_type , " gl_InstanceID " , ir_var_in , false , false , false , false } ,
{ " SV_Position " , glsl_type : : vec4_type , " gl_Position " , ir_var_out , false , false , true , false } ,
{ NULL , NULL , NULL , ir_var_auto , false , false , false , false }
} ;
/** Pixel shader system values. */
static FSystemValue PixelSystemValueTable [ ] =
{
{ " SV_Depth " , glsl_type : : float_type , " gl_FragDepth " , ir_var_out , false , false , false , false } ,
{ " SV_Position " , glsl_type : : vec4_type , " gl_FragCoord " , ir_var_in , true , false , false , false } ,
{ " SV_IsFrontFace " , glsl_type : : bool_type , " gl_FrontFacing " , ir_var_in , false , false , true , false } ,
{ " SV_PrimitiveID " , glsl_type : : int_type , " gl_PrimitiveID " , ir_var_in , false , false , false , false } ,
{ " SV_RenderTargetArrayIndex " , glsl_type : : int_type , " gl_Layer " , ir_var_in , false , false , false , false } ,
{ " SV_Target0 " , glsl_type : : half4_type , " gl_FragColor " , ir_var_out , false , false , false , true } ,
{ NULL , NULL , NULL , ir_var_auto , false , false , false }
} ;
/** Geometry shader system values. */
static FSystemValue GeometrySystemValueTable [ ] =
{
{ " SV_VertexID " , glsl_type : : int_type , " gl_VertexID " , ir_var_in , false , false , false , false } ,
{ " SV_InstanceID " , glsl_type : : int_type , " gl_InstanceID " , ir_var_in , false , false , false , false } ,
{ " SV_Position " , glsl_type : : vec4_type , " gl_Position " , ir_var_in , false , true , true , false } ,
{ " SV_Position " , glsl_type : : vec4_type , " gl_Position " , ir_var_out , false , false , true , false } ,
{ " SV_RenderTargetArrayIndex " , glsl_type : : int_type , " gl_Layer " , ir_var_out , false , false , false , false } ,
{ " SV_PrimitiveID " , glsl_type : : int_type , " gl_PrimitiveID " , ir_var_out , false , false , false , false } ,
{ " SV_PrimitiveID " , glsl_type : : int_type , " gl_PrimitiveIDIn " , ir_var_in , false , false , false , false } ,
{ NULL , NULL , NULL , ir_var_auto , false , false , false , false }
} ;
/** Hull shader system values. */
static FSystemValue HullSystemValueTable [ ] =
{
{ " SV_OutputControlPointID " , glsl_type : : int_type , " gl_InvocationID " , ir_var_in , false , false , false , false } ,
{ NULL , NULL , NULL , ir_var_auto , false , false , false , false }
} ;
/** Domain shader system values. */
static FSystemValue DomainSystemValueTable [ ] =
{
// TODO : SV_DomainLocation has types float2 or float3 depending on the input topology
{ " SV_Position " , glsl_type : : vec4_type , " gl_Position " , ir_var_in , false , true , true , false } ,
{ " SV_Position " , glsl_type : : vec4_type , " gl_Position " , ir_var_out , false , false , true , false } ,
{ " SV_DomainLocation " , glsl_type : : vec3_type , " gl_TessCoord " , ir_var_in , false , false , false , false } ,
{ NULL , NULL , NULL , ir_var_auto , false , false , false , false }
} ;
/** Compute shader system values. */
static FSystemValue ComputeSystemValueTable [ ] =
{
{ " SV_DispatchThreadID " , glsl_type : : uvec3_type , " gl_GlobalInvocationID " , ir_var_in , false , false , false , false } ,
{ " SV_GroupID " , glsl_type : : uvec3_type , " gl_WorkGroupID " , ir_var_in , false , false , false , false } ,
{ " SV_GroupIndex " , glsl_type : : uint_type , " gl_LocalInvocationIndex " , ir_var_in , false , false , false , false } ,
{ " SV_GroupThreadID " , glsl_type : : uvec3_type , " gl_LocalInvocationID " , ir_var_in , false , false , false , false } ,
{ NULL , NULL , NULL , ir_var_auto , false , false , false , false }
} ;
FSystemValue * SystemValueTable [ HSF_FrequencyCount ] =
{
VertexSystemValueTable ,
PixelSystemValueTable ,
GeometrySystemValueTable ,
HullSystemValueTable ,
DomainSystemValueTable ,
ComputeSystemValueTable
} ;
# define CUSTOM_LAYER_INDEX_SEMANTIC "HLSLCC_LAYER_INDEX"
2015-02-06 11:35:30 -05:00
static void ConfigureInOutVariableLayout ( EHlslShaderFrequency Frequency ,
_mesa_glsl_parse_state * ParseState ,
const char * Semantic ,
ir_variable * Variable ,
ir_variable_mode Mode
)
{
if ( Frequency = = HSF_VertexShader & & Mode = = ir_var_in )
{
const int PrefixLength = 9 ;
if ( ( FCStringAnsi : : Strnicmp ( Semantic , " ATTRIBUTE " , PrefixLength ) = = 0 ) & &
( Semantic [ PrefixLength ] > = ' 0 ' ) & & ( Semantic [ PrefixLength ] < = ' 9 ' )
)
{
int AttributeIndex = atoi ( Semantic + PrefixLength ) ;
Variable - > explicit_location = true ;
Variable - > location = AttributeIndex ;
Variable - > semantic = ralloc_strdup ( Variable , Semantic ) ;
}
else
{
# if DEBUG
# define _mesh_glsl_report _mesa_glsl_warning
# else
# define _mesh_glsl_report _mesa_glsl_error
# endif
_mesh_glsl_report ( ParseState , " Vertex shader input semantic must be ATTRIBUTE and not \' %s \' in order to determine location/semantic index " , Semantic ) ;
# undef _mesh_glsl_report
}
}
else if ( Semantic & & FCStringAnsi : : Strnicmp ( Variable - > name , " gl_ " , 3 ) ! = 0 )
{
Variable - > explicit_location = 1 ;
Variable - > semantic = ralloc_strdup ( Variable , Semantic ) ;
if ( Mode = = ir_var_in )
{
Variable - > location = ParseState - > next_in_location_slot + + ;
}
else
{
Variable - > location = ParseState - > next_out_location_slot + + ;
}
}
}
2014-09-25 14:27:21 -04:00
/**
* Generate an input semantic .
* @ param Frequency - The shader frequency .
* @ param ParseState - Parse state .
* @ param Semantic - The semantic name to generate .
* @ param Type - Value type .
* @ param DeclInstructions - IR to which declarations may be added .
* @ returns reference to IR variable for the semantic .
*/
static ir_rvalue * GenShaderInputSemantic (
EHlslShaderFrequency Frequency ,
_mesa_glsl_parse_state * ParseState ,
const char * Semantic ,
FSemanticQualifier InputQualifier ,
const glsl_type * Type ,
exec_list * DeclInstructions ,
int SemanticArraySize ,
int SemanticArrayIndex ,
bool & ApplyClipSpaceAdjustment
)
{
2014-10-01 18:16:34 -04:00
if ( Semantic & & FCStringAnsi : : Strnicmp ( Semantic , " SV_ " , 3 ) = = 0 )
2014-09-25 14:27:21 -04:00
{
FSystemValue * SystemValues = SystemValueTable [ Frequency ] ;
for ( int i = 0 ; SystemValues [ i ] . Semantic ! = NULL ; + + i )
{
if ( SystemValues [ i ] . Mode = = ir_var_in
& & ( ! SystemValues [ i ] . bESOnly | | ParseState - > bGenerateES )
2014-10-01 18:16:34 -04:00
& & FCStringAnsi : : Stricmp ( SystemValues [ i ] . Semantic , Semantic ) = = 0 )
2014-09-25 14:27:21 -04:00
{
if ( SystemValues [ i ] . bArrayVariable )
{
// Built-in array variable. Like gl_in[x].gl_Position.
// The variable for it has already been created in GenShaderInput().
2015-04-13 12:42:09 -04:00
ir_variable * Variable = ParseState - > symbols - > get_variable ( " gl_in " ) ;
2014-09-25 14:27:21 -04:00
check ( Variable ) ;
ir_dereference_variable * ArrayDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
ir_dereference_array * StructDeref = new ( ParseState ) ir_dereference_array (
ArrayDeref ,
new ( ParseState ) ir_constant ( ( unsigned ) SemanticArrayIndex )
) ;
ir_dereference_record * VariableDeref = new ( ParseState ) ir_dereference_record (
StructDeref ,
SystemValues [ i ] . GlslName
) ;
ApplyClipSpaceAdjustment = SystemValues [ i ] . bApplyClipSpaceAdjustment ;
// TO DO - in case of SV_ClipDistance, we need to defer appropriate index in variable too.
return VariableDeref ;
}
else
{
// Built-in variable that shows up only once, like gl_FragCoord in fragment
// shader, or gl_PrimitiveIDIn in geometry shader. Unlike gl_in[x].gl_Position.
// Even in geometry shader input pass it shows up only once.
// Create it on first pass, ignore the call on others.
if ( SemanticArrayIndex = = 0 )
{
ir_variable * Variable = new ( ParseState ) ir_variable (
SystemValues [ i ] . Type ,
SystemValues [ i ] . GlslName ,
ir_var_in
) ;
Variable - > read_only = true ;
Variable - > origin_upper_left = SystemValues [ i ] . bOriginUpperLeft ;
DeclInstructions - > push_tail ( Variable ) ;
ParseState - > symbols - > add_variable ( Variable ) ;
ir_dereference_variable * VariableDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
2014-12-12 12:30:21 -05:00
if ( FCStringAnsi : : Stricmp ( Semantic , " SV_Position " ) = = 0 & & Frequency = = HSF_PixelShader )
{
// This is for input of gl_FragCoord into pixel shader only.
// Generate a local variable to do the conversion in, keeping source type.
ir_variable * TempVariable = new ( ParseState ) ir_variable ( Variable - > type , NULL , ir_var_temporary ) ;
DeclInstructions - > push_tail ( TempVariable ) ;
// Assign input to this variable
ir_dereference_variable * TempVariableDeref = new ( ParseState ) ir_dereference_variable ( TempVariable ) ;
DeclInstructions - > push_tail (
new ( ParseState ) ir_assignment (
TempVariableDeref ,
VariableDeref
)
) ;
// TempVariable.w = ( 1.0f / TempVariable.w );
DeclInstructions - > push_tail (
new ( ParseState ) ir_assignment (
new ( ParseState ) ir_swizzle ( TempVariableDeref - > clone ( ParseState , NULL ) , 3 , 0 , 0 , 0 , 1 ) ,
new ( ParseState ) ir_expression ( ir_binop_div ,
new ( ParseState ) ir_constant ( 1.0f ) ,
new ( ParseState ) ir_swizzle ( TempVariableDeref - > clone ( ParseState , NULL ) , 3 , 0 , 0 , 0 , 1 )
)
)
) ;
return TempVariableDeref - > clone ( ParseState , NULL ) ;
}
else if ( ParseState - > adjust_clip_space_dx11_to_opengl & & SystemValues [ i ] . bApplyClipSpaceAdjustment )
2014-09-25 14:27:21 -04:00
{
// incoming gl_FrontFacing. Make it (!gl_FrontFacing), due to vertical flip in OpenGL
return new ( ParseState ) ir_expression ( ir_unop_logic_not , glsl_type : : bool_type , VariableDeref , NULL ) ;
}
else
{
return VariableDeref ;
}
}
else
{
return NULL ;
}
}
}
}
}
2015-04-13 12:42:09 -04:00
ir_variable * Variable = NULL ;
2014-09-25 14:27:21 -04:00
if ( Variable = = NULL & & Frequency = = HSF_DomainShader )
{
const int PrefixLength = 13 ;
2014-10-01 18:16:34 -04:00
if ( FCStringAnsi : : Strnicmp ( Semantic , " SV_TessFactor " , PrefixLength ) = = 0
2014-09-25 14:27:21 -04:00
& & Semantic [ PrefixLength ] > = ' 0 '
& & Semantic [ PrefixLength ] < = ' 3 ' )
{
int OutputIndex = Semantic [ PrefixLength ] - ' 0 ' ;
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " gl_TessLevelOuter[%d] " , OutputIndex ) ,
ir_var_out
) ;
}
}
if ( Variable = = NULL & & Frequency = = HSF_DomainShader )
{
const int PrefixLength = 19 ;
2014-10-01 18:16:34 -04:00
if ( FCStringAnsi : : Strnicmp ( Semantic , " SV_InsideTessFactor " , PrefixLength ) = = 0
2014-09-25 14:27:21 -04:00
& & Semantic [ PrefixLength ] > = ' 0 '
& & Semantic [ PrefixLength ] < = ' 1 ' )
{
int OutputIndex = Semantic [ PrefixLength ] - ' 0 ' ;
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " gl_TessLevelInner[%d] " , OutputIndex ) ,
ir_var_out
) ;
}
2014-10-01 18:16:34 -04:00
else if ( FCStringAnsi : : Stricmp ( Semantic , " SV_InsideTessFactor " ) = = 0 )
2014-09-25 14:27:21 -04:00
{
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " gl_TessLevelInner[0] " ) ,
ir_var_out
) ;
}
}
if ( Variable )
{
// Up to this point, variables aren't contained in structs
DeclInstructions - > push_tail ( Variable ) ;
ParseState - > symbols - > add_variable ( Variable ) ;
Variable - > centroid = InputQualifier . Fields . bCentroid ;
Variable - > interpolation = InputQualifier . Fields . InterpolationMode ;
Variable - > is_patch_constant = InputQualifier . Fields . bIsPatchConstant ;
ir_rvalue * VariableDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
return VariableDeref ;
}
// If we're here, no built-in variables matched.
2014-10-01 18:16:34 -04:00
if ( Semantic & & FCStringAnsi : : Strnicmp ( Semantic , " SV_ " , 3 ) = = 0 )
2014-09-25 14:27:21 -04:00
{
_mesa_glsl_warning ( ParseState , " unrecognized system "
" value input '%s' " , Semantic ) ;
}
2015-02-06 11:35:30 -05:00
// Patch constants must be variables, not structs or interface blocks, in GLSL <= 4.10
bool bUseGLSL410Rules = InputQualifier . Fields . bIsPatchConstant & & ParseState - > language_version < = 410 ;
if ( Frequency = = HSF_VertexShader | | ParseState - > bGenerateES | | bUseGLSL410Rules )
2014-09-25 14:27:21 -04:00
{
const char * Prefix = " in " ;
2015-02-06 11:35:30 -05:00
if ( ( ParseState - > bGenerateES & & Frequency = = HSF_PixelShader ) | | bUseGLSL410Rules )
2014-09-25 14:27:21 -04:00
{
Prefix = " var " ;
}
// Vertex shader inputs don't get packed into structs that we'll later morph into interface blocks
if ( ParseState - > bGenerateES & & Type - > is_integer ( ) )
{
// Convert integer attributes to floats
2015-04-13 12:42:09 -04:00
Variable = new ( ParseState ) ir_variable (
2014-09-25 14:27:21 -04:00
Type ,
ralloc_asprintf ( ParseState , " %s_%s_I " , Prefix , Semantic ) ,
ir_var_temporary
) ;
Variable - > centroid = InputQualifier . Fields . bCentroid ;
Variable - > interpolation = InputQualifier . Fields . InterpolationMode ;
check ( Type - > is_vector ( ) | | Type - > is_scalar ( ) ) ;
check ( Type - > base_type = = GLSL_TYPE_INT | | Type - > base_type = = GLSL_TYPE_UINT ) ;
// New float attribute
ir_variable * ReplacedAttributeVar = new ( ParseState ) ir_variable ( glsl_type : : get_instance ( GLSL_TYPE_FLOAT , Variable - > type - > vector_elements , 1 ) , ralloc_asprintf ( ParseState , " %s_%s " , Prefix , Semantic ) , ir_var_in ) ;
ReplacedAttributeVar - > read_only = true ;
ReplacedAttributeVar - > centroid = InputQualifier . Fields . bCentroid ;
ReplacedAttributeVar - > interpolation = InputQualifier . Fields . InterpolationMode ;
// Convert to integer
ir_assignment * ConversionAssignment = new ( ParseState ) ir_assignment (
new ( ParseState ) ir_dereference_variable ( Variable ) ,
new ( ParseState ) ir_expression (
Type - > base_type = = GLSL_TYPE_INT ? ir_unop_f2i : ir_unop_f2u ,
new ( ParseState ) ir_dereference_variable ( ReplacedAttributeVar )
)
) ;
DeclInstructions - > push_tail ( ReplacedAttributeVar ) ;
DeclInstructions - > push_tail ( Variable ) ;
DeclInstructions - > push_tail ( ConversionAssignment ) ;
ParseState - > symbols - > add_variable ( Variable ) ;
ParseState - > symbols - > add_variable ( ReplacedAttributeVar ) ;
ir_dereference_variable * VariableDeref = new ( ParseState ) ir_dereference_variable ( ReplacedAttributeVar ) ;
return VariableDeref ;
}
// Regular attribute
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " %s_%s " , Prefix , Semantic ) ,
ir_var_in
) ;
Variable - > read_only = true ;
Variable - > centroid = InputQualifier . Fields . bCentroid ;
Variable - > interpolation = InputQualifier . Fields . InterpolationMode ;
Variable - > is_patch_constant = InputQualifier . Fields . bIsPatchConstant ;
2015-02-06 11:35:30 -05:00
if ( ParseState - > bGenerateLayoutLocations & & ! InputQualifier . Fields . bIsPatchConstant )
2014-09-25 14:27:21 -04:00
{
2015-02-06 11:35:30 -05:00
ConfigureInOutVariableLayout ( Frequency , ParseState , Semantic , Variable , ir_var_in ) ;
2014-09-25 14:27:21 -04:00
}
DeclInstructions - > push_tail ( Variable ) ;
ParseState - > symbols - > add_variable ( Variable ) ;
ir_dereference_variable * VariableDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
return VariableDeref ;
}
else if ( SemanticArrayIndex = = 0 )
{
// On first pass, create variable
glsl_struct_field * StructField = ralloc_array ( ParseState , glsl_struct_field , 1 ) ;
memset ( StructField , 0 , sizeof ( glsl_struct_field ) ) ;
StructField [ 0 ] . type = Type ;
StructField [ 0 ] . name = ralloc_strdup ( ParseState , " Data " ) ;
const glsl_type * VariableType = glsl_type : : get_record_instance ( StructField , 1 , ralloc_strdup ( ParseState , Semantic ) ) ;
if ( SemanticArraySize )
{
// Pack it into an array too
VariableType = glsl_type : : get_array_instance ( VariableType , SemanticArraySize ) ;
}
2015-04-13 12:42:09 -04:00
Variable = new ( ParseState ) ir_variable ( VariableType , ralloc_asprintf ( ParseState , " in_%s " , Semantic ) , ir_var_in ) ;
2014-09-25 14:27:21 -04:00
Variable - > read_only = true ;
Variable - > is_interface_block = true ;
Variable - > centroid = InputQualifier . Fields . bCentroid ;
Variable - > interpolation = InputQualifier . Fields . InterpolationMode ;
Variable - > is_patch_constant = InputQualifier . Fields . bIsPatchConstant ;
DeclInstructions - > push_tail ( Variable ) ;
ParseState - > symbols - > add_variable ( Variable ) ;
if ( ParseState - > bGenerateLayoutLocations & & ! Variable - > is_patch_constant )
{
2015-02-06 11:35:30 -05:00
ConfigureInOutVariableLayout ( Frequency , ParseState , Semantic , Variable , ir_var_in ) ;
2014-09-25 14:27:21 -04:00
}
ir_rvalue * VariableDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
if ( SemanticArraySize )
{
// Deref inside array first
VariableDeref = new ( ParseState ) ir_dereference_array ( VariableDeref , new ( ParseState ) ir_constant ( ( unsigned ) SemanticArrayIndex )
) ;
}
VariableDeref = new ( ParseState ) ir_dereference_record ( VariableDeref , ralloc_strdup ( ParseState , " Data " ) ) ;
return VariableDeref ;
}
else
{
// Array variable, not first pass. It already exists, get it.
2015-02-19 12:13:52 -05:00
Variable = ParseState - > symbols - > get_variable ( ralloc_asprintf ( ParseState , " in_%s " , Semantic ) ) ;
2014-09-25 14:27:21 -04:00
check ( Variable ) ;
ir_rvalue * VariableDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
VariableDeref = new ( ParseState ) ir_dereference_array ( VariableDeref , new ( ParseState ) ir_constant ( ( unsigned ) SemanticArrayIndex ) ) ;
VariableDeref = new ( ParseState ) ir_dereference_record ( VariableDeref , ralloc_strdup ( ParseState , " Data " ) ) ;
return VariableDeref ;
}
}
/**
* Generate an output semantic .
* @ param Frequency - The shader frequency .
* @ param ParseState - Parse state .
* @ param Semantic - The semantic name to generate .
* @ param Type - Value type .
* @ param DeclInstructions - IR to which declarations may be added .
* @ returns the IR variable for the semantic .
*/
static ir_rvalue * GenShaderOutputSemantic (
EHlslShaderFrequency Frequency ,
_mesa_glsl_parse_state * ParseState ,
const char * Semantic ,
FSemanticQualifier OutputQualifier ,
const glsl_type * Type ,
exec_list * DeclInstructions ,
const glsl_type * * DestVariableType ,
bool & ApplyClipSpaceAdjustment ,
bool & ApplyClampPowerOfTwo
)
{
Copying //UE4/Dev-Core to //UE4/Dev-Main (Source: //UE4/Dev-Core @ 2996057)
==========================
MAJOR FEATURES + CHANGES
==========================
Change 2975196 on 2016/05/12 by Robert.Manuszewski
Garbage Collector will no longer be responsible for generating class token stream, instead the token stream will be generated on startup or when a class has finished loading.
- This way we can avoid very long GC times after new blueprints have been loaded.
- Temporarily enabled CLASS_TokenStreamAssembled check in development builds (for testing purposes)
Change 2993960 on 2016/05/30 by Robert.Manuszewski
Fixing leaked linkers created by blocking load requests during async loading.
Change 2959398 on 2016/04/28 by Steve.Robb
TMap references are strong and cannot be nulled by pending kill. This makes references in values strong too, even though we only really care about keys, which will corrupt the map when nulled.
#jira UE-20828
Change 2960723 on 2016/04/29 by Graeme.Thornton
Fix for texture asset import data being ignored when async loaded
Change 2960938 on 2016/04/29 by Robert.Manuszewski
Nulling out sql db handle after closing it.
Change 2967127 on 2016/05/05 by Steve.Robb
Move constructors explicitly disabled in generated code.
Change 2967143 on 2016/05/05 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2967164 on 2016/05/05 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer
Change 2968650 on 2016/05/06 by Steve.Robb
Fix for HotReload copying module manager.
Change 2968915 on 2016/05/06 by Robert.Manuszewski
Fixing spelling of SetImageIntegrityStatus function name.
Change 2970406 on 2016/05/09 by Steve.Robb
Static analysis fixes:
Function uses '...' bytes of stack: exceeds /analyze:stacksize '81940'. Consider moving some data to heap.
Change 2970419 on 2016/05/09 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
warning C6011: Dereferencing NULL pointer '...'.
warning C6385: Reading invalid data from '...': the readable size is '...' bytes, but '...' bytes may be read.
warning C6386: Buffer overrun while writing to '...': the writable size is '...' bytes, but '...' bytes might be written.
Change 2970431 on 2016/05/09 by Steve.Robb
Static analysis fixes:
warning C6299: Explicitly comparing a bit field to a Boolean type will yield unexpected results.
Change 2972032 on 2016/05/10 by Steven.Hutton
Workflow fixes to bugg / crashgroup filtering. Filters should now correctly persist across queries.
Change 2972085 on 2016/05/10 by Steve.Robb
Const-correctness fix for FLogCategoryBase::IsSuppressed.
Change 2972087 on 2016/05/10 by Steve.Robb
ELogVerbosity moved into its own header.
Change 2972090 on 2016/05/10 by Steve.Robb
Redundant ensure removed.
Change 2972103 on 2016/05/10 by Steve.Robb
Removal of redundant use of USING_CODE_ANALYSIS.
Change 2972139 on 2016/05/10 by Steve.Robb
Fix for ensure macros throwing C6326 warnings during static analysis.
Change 2972147 on 2016/05/10 by Steve.Robb
Fix for UE_LOG_ACTIVE macro throwing C6326 warnings during static analysis.
Change 2972162 on 2016/05/10 by Steve.Robb
SCOPE_CYCLE_COUNTER_GUARD removed.
Change 2972168 on 2016/05/10 by Steve.Robb
Compile error fix for logOrEnsureNanError in static analysis builds.
Change 2973084 on 2016/05/10 by Chris.Wood
Crash Report Server performance tweak
Change 2974030 on 2016/05/11 by Steve.Robb
Fix for IPropertyHandle::SetValue - used to take a non-const reference to a const UObject*, now it takes const references to both non-const and const UObject*.
Change 2974053 on 2016/05/11 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2974191 on 2016/05/11 by Steve.Robb
Fix for template instantiation error in VS2013.
Change 2975298 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.
Change 2975318 on 2016/05/12 by Steve.Robb
Fix for hot reload info being reported as warnings.
#jira UE-30586
Change 2975447 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
warning C6285: (<non-zero constant> || <non-zero constant>) is always a non-zero constant. Did you intend to use the bitwise-and operator?
warning C6286: (<non-zero constant> || <expression>) is always a non-zero constant. <expression> is never evaluated and might have side effects.
warning C6289: Incorrect operator: mutual exclusion over || is always a non-zero constant. Did you intend to use && instead?
warning C6316: Incorrect operator: tested expression is constant and non-zero. Use bitwise-and to determine whether bits are set.
Change 2975478 on 2016/05/12 by Steve.Robb
Static analysis fixes for lots of redundant <zero constant> and <non-zero constant> warnings.
Change 2975538 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'StaticResource'
Change 2976640 on 2016/05/13 by Robert.Manuszewski
Fixing crashes caused by token stream generation changes. Making sure the token stream gets re-generated when a class gets re-linked.
#jira UE-30675
Change 2978320 on 2016/05/16 by Steve.Robb
Fix for static analysis warnings in XNA headers.
Change 2978329 on 2016/05/16 by Steve.Robb
Static analysis fixes:
warning C6334: sizeof operator applied to an expression with an operator might yield unexpected results: Parentheses can be used to disambiguate certain usages.
Change 2980222 on 2016/05/17 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'X'.
warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.
Change 2980458 on 2016/05/17 by Chris.Wood
Attempt to fix crash report submission problems from CRP to CR website
[UE-30257] - Crashreports are sometimes missing file attachments
Passing crash GUID so that website can easily check for duplicates in future
Increased request timeout for AddCrash to be longer than website database timeout
Logging retries for future visibility
CRP v.1.1.6
Change 2980639 on 2016/05/17 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'X'.
warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.
Change 2981750 on 2016/05/18 by Steve.Robb
check()s in ContainerAllocationPolicies.h changed to checkSlow()s, as they only exist to check that the container has been written correctly.
Change 2982106 on 2016/05/18 by John.Mahoney
Fixed a crash caused by loading two stat capture files simultaneously in the profiler.
If the user tries to load a capture file while another load is in progress, the previous load is now cancelled and cleaned up before proceeding with the new load.
Made the delegates in FNewStatsReader explicitly specify which profiler instance they are loading data for, instead of relying on the current value of LoadConnection->InstanceId.
This also fixes a crash that occurs when selecting a different capture file in the "Stats dump browser" pane of the profiler (after using Load Folder) while another file is still loading.
Cleaned up some weak pointer usage in the profiler window.
#jira UE-30741
Change 2983366 on 2016/05/19 by Steven.Hutton
Changes for passing crash type directly from CRP to CRW.
Change 2983394 on 2016/05/19 by Steven.Hutton
Minor changes to add crash with more error reporting
Change 2984685 on 2016/05/20 by Robert.Manuszewski
Merging //UE4/Dev-Main @ 2984626 to Dev-Core (//UE4/Dev-Core)
Change 2985143 on 2016/05/20 by Steve.Robb
Missing semi-colons.
Change 2986463 on 2016/05/23 by Steve.Robb
CopyTemp added to make it clear that you want to make a copy (rather than a move, or an accidental copy) at the call site of a function taking rvalue refs.
Change 2986475 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6313: Incorrect operator: zero-valued flag cannot be tested with bitwise-and.
Change 2986476 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6313: Incorrect operator: zero-valued flag cannot be tested with bitwise-and.
Change 2986480 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant
Change 2986515 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6340: Mismatch on sign: 'X' passed as _Param_(N) when some unsigned type is required in call to 'Func'
Change 2986680 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6386: Buffer overrun while writing to 'Ptr': the writable size is 'X' bytes, but 'Y' bytes might be written.
warning C6387: 'Ptr' could be '0': this does not adhere to the specification for the function 'Func'
warning C6031: Return value ignored: 'snprintf'.
warning C6340: Mismatch on sign: 'const unsigned int' passed as _Param_(4) when some signed type is required in call to 'snprintf'.
Change 2986865 on 2016/05/23 by Robert.Manuszewski
Removing redundand AddReferencedObjects functions
Change 2987968 on 2016/05/24 by Robert.Manuszewski
Removing redundant UPROPERTY macros from intrinsic classes.
Change 2987979 on 2016/05/24 by Steve.Robb
Optimization of some FString and FPaths operations to produce fewer temporaries.
Change 2988297 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6287: Redundant code: the left and right sub-expressions are identical.
Change 2988430 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6385: Reading invalid data from 'var': the readable size is 'X' bytes, but 'Y' bytes may be read.
Change 2988461 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.
Change 2988464 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6262: Function uses 'X' bytes of stack: exceeds /analyze:stacksize 'Y'. Consider moving some data to heap.
Change 2988494 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6237: (<zero> && <expression>) is always zero. <expression> is never evaluated and might have side effects.
Change 2989411 on 2016/05/25 by Robert.Manuszewski
Splitting GC cluster index and intenral object flags to allow more UObjects in editor builds.
Change 2989429 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6387: '_Param_(X)' could be '0': this does not adhere to the specification for the function 'Func'.
Change 2989982 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6001: Using uninitialized memory 'LODPlanesMin'.
Change 2990018 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6386: Buffer overrun while writing to 'X'
Change 2990077 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2990114 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent.
Change 2990125 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
Change 2990162 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6294: Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
Change 2990193 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C28182: Dereferencing NULL pointer. 'type' contains the same NULL value as 'type->base_type' did.
warning C6011: Dereferencing NULL pointer 'Semantic'.
Change 2991006 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C28113: Accessing a local variable dummy via an Interlocked function: This is an unusual usage which could be reconsidered.
Change 2991012 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6031: Return value ignored: 'InitializeCriticalSectionAndSpinCount'.
Change 2991013 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6287: Redundant code: the left and right sub-expressions are identical.
Change 2991016 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.
Change 2991017 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2991019 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6292: Ill-defined for-loop: counts up from maximum.
Change 2991023 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6322: Empty _except block.
warning C28251: Inconsistent annotation for 'WinMain': this instance has no annotations.
Change 2991070 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C28182: Dereferencing NULL pointer. 'Ptr1' contains the same NULL value as 'Ptr2' did.
Change 2991416 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2992738 on 2016/05/27 by Steve.Robb
Revert changes to FString::MatchesWildcard.
Change 2992916 on 2016/05/27 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2992960 on 2016/05/27 by Chris.Wood
Optimized P4 access in Crash Report Process and MinidumpDiagostics.
Change 2992964 on 2016/05/27 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2993956 on 2016/05/30 by Robert.Manuszewski
Fixing a crash after adding a new C++ class in the editor - made sure new classes have the token stream assembled after hot-reload.
#jira UE-31309
Change 2993977 on 2016/05/30 by Robert.Manuszewski
Don't wait for all packages to finish loading before PostLoading those which already have.
Change 2994206 on 2016/05/31 by Robert.Manuszewski
PR #2429: Three bug fixes required for script support to work properly (Contributed by pluranium)
#lockdown Nick.Penwarden
[CL 2996251 by Robert Manuszewski in Main branch]
2016-06-01 12:08:56 -04:00
check ( Semantic ) ;
2014-09-25 14:27:21 -04:00
FSystemValue * SystemValues = SystemValueTable [ Frequency ] ;
ir_variable * Variable = NULL ;
Copying //UE4/Dev-Core to //UE4/Dev-Main (Source: //UE4/Dev-Core @ 2996057)
==========================
MAJOR FEATURES + CHANGES
==========================
Change 2975196 on 2016/05/12 by Robert.Manuszewski
Garbage Collector will no longer be responsible for generating class token stream, instead the token stream will be generated on startup or when a class has finished loading.
- This way we can avoid very long GC times after new blueprints have been loaded.
- Temporarily enabled CLASS_TokenStreamAssembled check in development builds (for testing purposes)
Change 2993960 on 2016/05/30 by Robert.Manuszewski
Fixing leaked linkers created by blocking load requests during async loading.
Change 2959398 on 2016/04/28 by Steve.Robb
TMap references are strong and cannot be nulled by pending kill. This makes references in values strong too, even though we only really care about keys, which will corrupt the map when nulled.
#jira UE-20828
Change 2960723 on 2016/04/29 by Graeme.Thornton
Fix for texture asset import data being ignored when async loaded
Change 2960938 on 2016/04/29 by Robert.Manuszewski
Nulling out sql db handle after closing it.
Change 2967127 on 2016/05/05 by Steve.Robb
Move constructors explicitly disabled in generated code.
Change 2967143 on 2016/05/05 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2967164 on 2016/05/05 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer
Change 2968650 on 2016/05/06 by Steve.Robb
Fix for HotReload copying module manager.
Change 2968915 on 2016/05/06 by Robert.Manuszewski
Fixing spelling of SetImageIntegrityStatus function name.
Change 2970406 on 2016/05/09 by Steve.Robb
Static analysis fixes:
Function uses '...' bytes of stack: exceeds /analyze:stacksize '81940'. Consider moving some data to heap.
Change 2970419 on 2016/05/09 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
warning C6011: Dereferencing NULL pointer '...'.
warning C6385: Reading invalid data from '...': the readable size is '...' bytes, but '...' bytes may be read.
warning C6386: Buffer overrun while writing to '...': the writable size is '...' bytes, but '...' bytes might be written.
Change 2970431 on 2016/05/09 by Steve.Robb
Static analysis fixes:
warning C6299: Explicitly comparing a bit field to a Boolean type will yield unexpected results.
Change 2972032 on 2016/05/10 by Steven.Hutton
Workflow fixes to bugg / crashgroup filtering. Filters should now correctly persist across queries.
Change 2972085 on 2016/05/10 by Steve.Robb
Const-correctness fix for FLogCategoryBase::IsSuppressed.
Change 2972087 on 2016/05/10 by Steve.Robb
ELogVerbosity moved into its own header.
Change 2972090 on 2016/05/10 by Steve.Robb
Redundant ensure removed.
Change 2972103 on 2016/05/10 by Steve.Robb
Removal of redundant use of USING_CODE_ANALYSIS.
Change 2972139 on 2016/05/10 by Steve.Robb
Fix for ensure macros throwing C6326 warnings during static analysis.
Change 2972147 on 2016/05/10 by Steve.Robb
Fix for UE_LOG_ACTIVE macro throwing C6326 warnings during static analysis.
Change 2972162 on 2016/05/10 by Steve.Robb
SCOPE_CYCLE_COUNTER_GUARD removed.
Change 2972168 on 2016/05/10 by Steve.Robb
Compile error fix for logOrEnsureNanError in static analysis builds.
Change 2973084 on 2016/05/10 by Chris.Wood
Crash Report Server performance tweak
Change 2974030 on 2016/05/11 by Steve.Robb
Fix for IPropertyHandle::SetValue - used to take a non-const reference to a const UObject*, now it takes const references to both non-const and const UObject*.
Change 2974053 on 2016/05/11 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2974191 on 2016/05/11 by Steve.Robb
Fix for template instantiation error in VS2013.
Change 2975298 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.
Change 2975318 on 2016/05/12 by Steve.Robb
Fix for hot reload info being reported as warnings.
#jira UE-30586
Change 2975447 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>. Did you intend to use the bitwise-and operator?
warning C6285: (<non-zero constant> || <non-zero constant>) is always a non-zero constant. Did you intend to use the bitwise-and operator?
warning C6286: (<non-zero constant> || <expression>) is always a non-zero constant. <expression> is never evaluated and might have side effects.
warning C6289: Incorrect operator: mutual exclusion over || is always a non-zero constant. Did you intend to use && instead?
warning C6316: Incorrect operator: tested expression is constant and non-zero. Use bitwise-and to determine whether bits are set.
Change 2975478 on 2016/05/12 by Steve.Robb
Static analysis fixes for lots of redundant <zero constant> and <non-zero constant> warnings.
Change 2975538 on 2016/05/12 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'StaticResource'
Change 2976640 on 2016/05/13 by Robert.Manuszewski
Fixing crashes caused by token stream generation changes. Making sure the token stream gets re-generated when a class gets re-linked.
#jira UE-30675
Change 2978320 on 2016/05/16 by Steve.Robb
Fix for static analysis warnings in XNA headers.
Change 2978329 on 2016/05/16 by Steve.Robb
Static analysis fixes:
warning C6334: sizeof operator applied to an expression with an operator might yield unexpected results: Parentheses can be used to disambiguate certain usages.
Change 2980222 on 2016/05/17 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'X'.
warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.
Change 2980458 on 2016/05/17 by Chris.Wood
Attempt to fix crash report submission problems from CRP to CR website
[UE-30257] - Crashreports are sometimes missing file attachments
Passing crash GUID so that website can easily check for duplicates in future
Increased request timeout for AddCrash to be longer than website database timeout
Logging retries for future visibility
CRP v.1.1.6
Change 2980639 on 2016/05/17 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'X'.
warning C28182: Dereferencing NULL pointer. 'X' contains the same NULL value as 'Y' did.
Change 2981750 on 2016/05/18 by Steve.Robb
check()s in ContainerAllocationPolicies.h changed to checkSlow()s, as they only exist to check that the container has been written correctly.
Change 2982106 on 2016/05/18 by John.Mahoney
Fixed a crash caused by loading two stat capture files simultaneously in the profiler.
If the user tries to load a capture file while another load is in progress, the previous load is now cancelled and cleaned up before proceeding with the new load.
Made the delegates in FNewStatsReader explicitly specify which profiler instance they are loading data for, instead of relying on the current value of LoadConnection->InstanceId.
This also fixes a crash that occurs when selecting a different capture file in the "Stats dump browser" pane of the profiler (after using Load Folder) while another file is still loading.
Cleaned up some weak pointer usage in the profiler window.
#jira UE-30741
Change 2983366 on 2016/05/19 by Steven.Hutton
Changes for passing crash type directly from CRP to CRW.
Change 2983394 on 2016/05/19 by Steven.Hutton
Minor changes to add crash with more error reporting
Change 2984685 on 2016/05/20 by Robert.Manuszewski
Merging //UE4/Dev-Main @ 2984626 to Dev-Core (//UE4/Dev-Core)
Change 2985143 on 2016/05/20 by Steve.Robb
Missing semi-colons.
Change 2986463 on 2016/05/23 by Steve.Robb
CopyTemp added to make it clear that you want to make a copy (rather than a move, or an accidental copy) at the call site of a function taking rvalue refs.
Change 2986475 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6313: Incorrect operator: zero-valued flag cannot be tested with bitwise-and.
Change 2986476 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6313: Incorrect operator: zero-valued flag cannot be tested with bitwise-and.
Change 2986480 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant
Change 2986515 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6340: Mismatch on sign: 'X' passed as _Param_(N) when some unsigned type is required in call to 'Func'
Change 2986680 on 2016/05/23 by Steve.Robb
Static analysis fixes:
warning C6386: Buffer overrun while writing to 'Ptr': the writable size is 'X' bytes, but 'Y' bytes might be written.
warning C6387: 'Ptr' could be '0': this does not adhere to the specification for the function 'Func'
warning C6031: Return value ignored: 'snprintf'.
warning C6340: Mismatch on sign: 'const unsigned int' passed as _Param_(4) when some signed type is required in call to 'snprintf'.
Change 2986865 on 2016/05/23 by Robert.Manuszewski
Removing redundand AddReferencedObjects functions
Change 2987968 on 2016/05/24 by Robert.Manuszewski
Removing redundant UPROPERTY macros from intrinsic classes.
Change 2987979 on 2016/05/24 by Steve.Robb
Optimization of some FString and FPaths operations to produce fewer temporaries.
Change 2988297 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6287: Redundant code: the left and right sub-expressions are identical.
Change 2988430 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6385: Reading invalid data from 'var': the readable size is 'X' bytes, but 'Y' bytes may be read.
Change 2988461 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6235: (<non-zero constant> || <expression>) is always a non-zero constant.
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.
Change 2988464 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6262: Function uses 'X' bytes of stack: exceeds /analyze:stacksize 'Y'. Consider moving some data to heap.
Change 2988494 on 2016/05/24 by Steve.Robb
Static analysis fixes:
warning C6237: (<zero> && <expression>) is always zero. <expression> is never evaluated and might have side effects.
Change 2989411 on 2016/05/25 by Robert.Manuszewski
Splitting GC cluster index and intenral object flags to allow more UObjects in editor builds.
Change 2989429 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6387: '_Param_(X)' could be '0': this does not adhere to the specification for the function 'Func'.
Change 2989982 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6001: Using uninitialized memory 'LODPlanesMin'.
Change 2990018 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6386: Buffer overrun while writing to 'X'
Change 2990077 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6240: (<expression> && <non-zero constant>) always evaluates to the result of <expression>.
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2990114 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6336: Arithmetic operator has precedence over question operator, use parentheses to clarify intent.
Change 2990125 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6239: (<non-zero constant> && <expression>) always evaluates to the result of <expression>.
Change 2990162 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C6294: Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
Change 2990193 on 2016/05/25 by Steve.Robb
Static analysis fixes:
warning C28182: Dereferencing NULL pointer. 'type' contains the same NULL value as 'type->base_type' did.
warning C6011: Dereferencing NULL pointer 'Semantic'.
Change 2991006 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C28113: Accessing a local variable dummy via an Interlocked function: This is an unusual usage which could be reconsidered.
Change 2991012 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6031: Return value ignored: 'InitializeCriticalSectionAndSpinCount'.
Change 2991013 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6287: Redundant code: the left and right sub-expressions are identical.
Change 2991016 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6236: (<expression> || <non-zero constant>) is always a non-zero constant.
Change 2991017 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6326: Potential comparison of a constant with another constant.
Change 2991019 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6292: Ill-defined for-loop: counts up from maximum.
Change 2991023 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6322: Empty _except block.
warning C28251: Inconsistent annotation for 'WinMain': this instance has no annotations.
Change 2991070 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C28182: Dereferencing NULL pointer. 'Ptr1' contains the same NULL value as 'Ptr2' did.
Change 2991416 on 2016/05/26 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2992738 on 2016/05/27 by Steve.Robb
Revert changes to FString::MatchesWildcard.
Change 2992916 on 2016/05/27 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2992960 on 2016/05/27 by Chris.Wood
Optimized P4 access in Crash Report Process and MinidumpDiagostics.
Change 2992964 on 2016/05/27 by Steve.Robb
Static analysis fixes:
warning C6011: Dereferencing NULL pointer 'Ptr'.
Change 2993956 on 2016/05/30 by Robert.Manuszewski
Fixing a crash after adding a new C++ class in the editor - made sure new classes have the token stream assembled after hot-reload.
#jira UE-31309
Change 2993977 on 2016/05/30 by Robert.Manuszewski
Don't wait for all packages to finish loading before PostLoading those which already have.
Change 2994206 on 2016/05/31 by Robert.Manuszewski
PR #2429: Three bug fixes required for script support to work properly (Contributed by pluranium)
#lockdown Nick.Penwarden
[CL 2996251 by Robert Manuszewski in Main branch]
2016-06-01 12:08:56 -04:00
if ( FCStringAnsi : : Strnicmp ( Semantic , " SV_ " , 3 ) = = 0 )
2014-09-25 14:27:21 -04:00
{
for ( int i = 0 ; SystemValues [ i ] . Semantic ! = NULL ; + + i )
{
if ( ! SystemValues [ i ] . bESOnly | | ParseState - > bGenerateES )
{
if ( SystemValues [ i ] . Mode = = ir_var_out
2014-10-01 18:16:34 -04:00
& & FCStringAnsi : : Stricmp ( SystemValues [ i ] . Semantic , Semantic ) = = 0 )
2014-09-25 14:27:21 -04:00
{
Variable = new ( ParseState ) ir_variable (
SystemValues [ i ] . Type ,
SystemValues [ i ] . GlslName ,
ir_var_out
) ;
Variable - > origin_upper_left = SystemValues [ i ] . bOriginUpperLeft ;
ApplyClipSpaceAdjustment = SystemValues [ i ] . bApplyClipSpaceAdjustment ;
}
}
}
}
if ( Variable = = NULL & & Frequency = = HSF_VertexShader )
{
const int PrefixLength = 15 ;
2014-10-01 18:16:34 -04:00
if ( FCStringAnsi : : Strnicmp ( Semantic , " SV_ClipDistance " , PrefixLength ) = = 0
2014-09-25 14:27:21 -04:00
& & Semantic [ PrefixLength ] > = ' 0 '
& & Semantic [ PrefixLength ] < = ' 9 ' )
{
int OutputIndex = Semantic [ 15 ] - ' 0 ' ;
Variable = new ( ParseState ) ir_variable (
glsl_type : : float_type ,
ralloc_asprintf ( ParseState , " gl_ClipDistance[%d] " , OutputIndex ) ,
ir_var_out
) ;
}
}
if ( Variable = = NULL & & Frequency = = HSF_PixelShader )
{
const int PrefixLength = 9 ;
2014-10-01 18:16:34 -04:00
if ( FCStringAnsi : : Strnicmp ( Semantic , " SV_Target " , PrefixLength ) = = 0
2014-09-25 14:27:21 -04:00
& & Semantic [ PrefixLength ] > = ' 0 '
& & Semantic [ PrefixLength ] < = ' 7 ' )
{
int OutputIndex = Semantic [ PrefixLength ] - ' 0 ' ;
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " out_Target%d " , OutputIndex ) ,
ir_var_out
) ;
if ( ParseState - > bGenerateLayoutLocations )
{
Variable - > explicit_location = true ;
Variable - > location = OutputIndex ;
}
}
}
if ( Variable = = NULL & & Frequency = = HSF_HullShader )
{
const int PrefixLength = 13 ;
2014-10-01 18:16:34 -04:00
if ( FCStringAnsi : : Strnicmp ( Semantic , " SV_TessFactor " , PrefixLength ) = = 0
2014-09-25 14:27:21 -04:00
& & Semantic [ PrefixLength ] > = ' 0 '
& & Semantic [ PrefixLength ] < = ' 3 ' )
{
int OutputIndex = Semantic [ PrefixLength ] - ' 0 ' ;
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " gl_TessLevelOuter[%d] " , OutputIndex ) ,
ir_var_out
) ;
ApplyClampPowerOfTwo = ParseState - > tessellation . partitioning = = GLSL_PARTITIONING_POW2 ;
}
}
if ( Variable = = NULL & & Frequency = = HSF_HullShader )
{
const int PrefixLength = 19 ;
2014-10-01 18:16:34 -04:00
if ( FCStringAnsi : : Strnicmp ( Semantic , " SV_InsideTessFactor " , PrefixLength ) = = 0
2014-09-25 14:27:21 -04:00
& & Semantic [ PrefixLength ] > = ' 0 '
& & Semantic [ PrefixLength ] < = ' 1 ' )
{
int OutputIndex = Semantic [ PrefixLength ] - ' 0 ' ;
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " gl_TessLevelInner[%d] " , OutputIndex ) ,
ir_var_out
) ;
ApplyClampPowerOfTwo = ParseState - > tessellation . partitioning = = GLSL_PARTITIONING_POW2 ;
}
2014-10-01 18:16:34 -04:00
else if ( FCStringAnsi : : Stricmp ( Semantic , " SV_InsideTessFactor " ) = = 0 )
2014-09-25 14:27:21 -04:00
{
Variable = new ( ParseState ) ir_variable (
Type ,
ralloc_asprintf ( ParseState , " gl_TessLevelInner[0] " ) ,
ir_var_out
) ;
ApplyClampPowerOfTwo = ParseState - > tessellation . partitioning = = GLSL_PARTITIONING_POW2 ;
}
}
2015-02-06 11:35:30 -05:00
bool bUseGLSL410Rules = OutputQualifier . Fields . bIsPatchConstant & & ParseState - > language_version = = 410 ;
if ( Variable = = NULL & & ( ParseState - > bGenerateES | | bUseGLSL410Rules ) )
2014-09-25 14:27:21 -04:00
{
// Create a variable so that a struct will not get added
Variable = new ( ParseState ) ir_variable ( Type , ralloc_asprintf ( ParseState , " var_%s " , Semantic ) , ir_var_out ) ;
}
if ( Variable )
{
// Up to this point, variables aren't contained in structs
* DestVariableType = Variable - > type ;
DeclInstructions - > push_tail ( Variable ) ;
ParseState - > symbols - > add_variable ( Variable ) ;
Variable - > centroid = OutputQualifier . Fields . bCentroid ;
Variable - > interpolation = OutputQualifier . Fields . InterpolationMode ;
Variable - > is_patch_constant = OutputQualifier . Fields . bIsPatchConstant ;
ir_rvalue * VariableDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
return VariableDeref ;
}
2014-10-01 18:16:34 -04:00
if ( Semantic & & FCStringAnsi : : Strnicmp ( Semantic , " SV_ " , 3 ) = = 0 )
2014-09-25 14:27:21 -04:00
{
_mesa_glsl_warning ( ParseState , " unrecognized system value output '%s' " ,
Semantic ) ;
}
* DestVariableType = Type ;
// Create variable
glsl_struct_field * StructField = ralloc_array ( ParseState , glsl_struct_field , 1 ) ;
memset ( StructField , 0 , sizeof ( glsl_struct_field ) ) ;
StructField [ 0 ] . type = Type ;
StructField [ 0 ] . name = ralloc_strdup ( ParseState , " Data " ) ;
const glsl_type * VariableType = glsl_type : : get_record_instance ( StructField , 1 , ralloc_strdup ( ParseState , Semantic ) ) ;
if ( Frequency = = HSF_HullShader & & ! OutputQualifier . Fields . bIsPatchConstant )
{
VariableType = glsl_type : : get_array_instance ( VariableType , ParseState - > tessellation . outputcontrolpoints ) ;
}
Variable = new ( ParseState ) ir_variable ( VariableType , ralloc_asprintf ( ParseState , " out_%s " , Semantic ) , ir_var_out ) ;
Variable - > centroid = OutputQualifier . Fields . bCentroid ;
Variable - > interpolation = OutputQualifier . Fields . InterpolationMode ;
Variable - > is_interface_block = true ;
Variable - > is_patch_constant = OutputQualifier . Fields . bIsPatchConstant ;
if ( ParseState - > bGenerateLayoutLocations & & ! Variable - > is_patch_constant )
{
2015-02-06 11:35:30 -05:00
ConfigureInOutVariableLayout ( Frequency , ParseState , Semantic , Variable , ir_var_out ) ;
2014-09-25 14:27:21 -04:00
}
DeclInstructions - > push_tail ( Variable ) ;
ParseState - > symbols - > add_variable ( Variable ) ;
ir_rvalue * VariableDeref = new ( ParseState ) ir_dereference_variable ( Variable ) ;
if ( Frequency = = HSF_HullShader & & ! OutputQualifier . Fields . bIsPatchConstant )
{
VariableDeref = new ( ParseState ) ir_dereference_array ( VariableDeref , new ( ParseState ) ir_dereference_variable ( ParseState - > symbols - > get_variable ( " gl_InvocationID " ) ) ) ;
}
VariableDeref = new ( ParseState ) ir_dereference_record ( VariableDeref , ralloc_strdup ( ParseState , " Data " ) ) ;
return VariableDeref ;
}
/**
* Generate an input semantic .
* @ param Frequency - The shader frequency .
* @ param ParseState - Parse state .
* @ param InputSemantic - The semantic name to generate .
* @ param InputQualifier - Qualifiers applied to the semantic .
* @ param InputVariableDeref - Deref for the argument variable .
* @ param DeclInstructions - IR to which declarations may be added .
* @ param PreCallInstructions - IR to which instructions may be added before the
* entry point is called .
*/
static void GenShaderInputForVariable (
EHlslShaderFrequency Frequency ,
_mesa_glsl_parse_state * ParseState ,
const char * InputSemantic ,
FSemanticQualifier InputQualifier ,
ir_dereference * InputVariableDeref ,
exec_list * DeclInstructions ,
exec_list * PreCallInstructions ,
int SemanticArraySize ,
int SemanticArrayIndex
)
{
const glsl_type * InputType = InputVariableDeref - > type ;
if ( InputType - > is_record ( ) )
{
for ( uint32 i = 0 ; i < InputType - > length ; + + i )
{
const char * FieldSemantic = InputType - > fields . structure [ i ] . semantic ;
const char * Semantic = 0 ;
if ( InputSemantic & & FieldSemantic )
{
_mesa_glsl_warning ( ParseState , " semantic '%s' of field '%s' will be overridden by enclosing types' semantic '%s' " ,
InputType - > fields . structure [ i ] . semantic ,
InputType - > fields . structure [ i ] . name ,
InputSemantic ) ;
FieldSemantic = 0 ;
}
if ( InputSemantic & & ! FieldSemantic )
{
2016-04-13 12:14:19 -04:00
Semantic = ralloc_asprintf ( ParseState , " %s%u " , InputSemantic , i ) ;
2014-09-25 14:27:21 -04:00
_mesa_glsl_warning ( ParseState , " creating semantic '%s' for struct field '%s' " , Semantic , InputType - > fields . structure [ i ] . name ) ;
}
else if ( ! InputSemantic & & FieldSemantic )
{
Semantic = FieldSemantic ;
}
else
{
Semantic = 0 ;
}
if ( InputType - > fields . structure [ i ] . type - > is_record ( ) | |
Semantic )
{
FSemanticQualifier Qualifier = InputQualifier ;
if ( Qualifier . Packed = = 0 )
{
Qualifier . Fields . bCentroid = InputType - > fields . structure [ i ] . centroid ;
Qualifier . Fields . InterpolationMode = InputType - > fields . structure [ i ] . interpolation ;
Qualifier . Fields . bIsPatchConstant = InputType - > fields . structure [ i ] . patchconstant ;
}
ir_dereference_record * FieldDeref = new ( ParseState ) ir_dereference_record (
InputVariableDeref - > clone ( ParseState , NULL ) ,
InputType - > fields . structure [ i ] . name ) ;
GenShaderInputForVariable (
Frequency ,
ParseState ,
Semantic ,
Qualifier ,
FieldDeref ,
DeclInstructions ,
PreCallInstructions ,
SemanticArraySize ,
SemanticArrayIndex
) ;
}
else
{
_mesa_glsl_error (
ParseState ,
" field '%s' in input structure '%s' does not specify a semantic " ,
InputType - > fields . structure [ i ] . name ,
InputType - > name
) ;
}
}
}
else if ( InputType - > is_array ( ) | | InputType - > is_inputpatch ( ) | | InputType - > is_outputpatch ( ) )
{
int BaseIndex = 0 ;
const char * Semantic = 0 ;
check ( InputSemantic ) ;
ParseSemanticAndIndex ( ParseState , InputSemantic , & Semantic , & BaseIndex ) ;
check ( BaseIndex > = 0 ) ;
check ( InputType - > is_array ( ) | | InputType - > is_inputpatch ( ) | | InputType - > is_outputpatch ( ) ) ;
const unsigned ElementCount = InputType - > is_array ( ) ? InputType - > length : InputType - > patch_length ;
{
//check(!InputQualifier.Fields.bIsPatchConstant);
InputQualifier . Fields . bIsPatchConstant = false ;
}
for ( unsigned i = 0 ; i < ElementCount ; + + i )
{
ir_dereference_array * ArrayDeref = new ( ParseState ) ir_dereference_array (
InputVariableDeref - > clone ( ParseState , NULL ) ,
new ( ParseState ) ir_constant ( ( unsigned ) i )
) ;
GenShaderInputForVariable (
Frequency ,
ParseState ,
2016-04-13 12:14:19 -04:00
ralloc_asprintf ( ParseState , " %s%u " , Semantic , BaseIndex + i ) ,
2014-09-25 14:27:21 -04:00
InputQualifier ,
ArrayDeref ,
DeclInstructions ,
PreCallInstructions ,
SemanticArraySize ,
SemanticArrayIndex
) ;
}
}
else
{
bool ApplyClipSpaceAdjustment = false ;
ir_rvalue * SrcValue = GenShaderInputSemantic ( Frequency , ParseState , InputSemantic ,
InputQualifier , InputType , DeclInstructions , SemanticArraySize ,
SemanticArrayIndex , ApplyClipSpaceAdjustment ) ;
if ( SrcValue )
{
YYLTYPE loc ;
if ( ParseState - > adjust_clip_space_dx11_to_opengl & & ApplyClipSpaceAdjustment )
{
// This is for input of gl_Position into geometry shader only.
// Generate a local variable to do the conversion in, keeping source type.
ir_variable * TempVariable = new ( ParseState ) ir_variable ( SrcValue - > type , NULL , ir_var_temporary ) ;
PreCallInstructions - > push_tail ( TempVariable ) ;
// Assign input to this variable
ir_dereference_variable * TempVariableDeref = new ( ParseState ) ir_dereference_variable ( TempVariable ) ;
PreCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
TempVariableDeref ,
SrcValue
)
) ;
// TempVariable.y = -TempVariable.y;
PreCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
new ( ParseState ) ir_swizzle ( TempVariableDeref - > clone ( ParseState , NULL ) , 1 , 0 , 0 , 0 , 1 ) ,
new ( ParseState ) ir_expression ( ir_unop_neg ,
glsl_type : : float_type ,
new ( ParseState ) ir_swizzle ( TempVariableDeref - > clone ( ParseState , NULL ) , 1 , 0 , 0 , 0 , 1 ) ,
NULL )
)
) ;
// TempVariable.z = ( TempVariable.z + TempVariable.w ) / 2.0;
PreCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
new ( ParseState ) ir_swizzle ( TempVariableDeref - > clone ( ParseState , NULL ) , 2 , 0 , 0 , 0 , 1 ) ,
new ( ParseState ) ir_expression ( ir_binop_div ,
new ( ParseState ) ir_expression ( ir_binop_add ,
new ( ParseState ) ir_swizzle ( TempVariableDeref - > clone ( ParseState , NULL ) , 2 , 0 , 0 , 0 , 1 ) ,
new ( ParseState ) ir_swizzle ( TempVariableDeref - > clone ( ParseState , NULL ) , 3 , 0 , 0 , 0 , 1 )
) ,
new ( ParseState ) ir_constant ( 2.0f )
)
)
) ;
SrcValue = TempVariableDeref - > clone ( ParseState , NULL ) ;
}
apply_type_conversion ( InputType , SrcValue , PreCallInstructions , ParseState , true , & loc ) ;
PreCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
InputVariableDeref - > clone ( ParseState , NULL ) ,
SrcValue
)
) ;
}
}
}
/**
* Generate a shader input .
* @ param Frequency - The shader frequency .
* @ param ParseState - Parse state .
* @ param InputSemantic - The semantic name to generate .
* @ param InputQualifier - Qualifiers applied to the semantic .
* @ param InputType - Value type .
* @ param DeclInstructions - IR to which declarations may be added .
* @ param PreCallInstructions - IR to which instructions may be added before the
* entry point is called .
* @ returns the IR variable deref for the semantic .
*/
static ir_dereference_variable * GenShaderInput (
EHlslShaderFrequency Frequency ,
_mesa_glsl_parse_state * ParseState ,
const char * InputSemantic ,
FSemanticQualifier InputQualifier ,
const glsl_type * InputType ,
exec_list * DeclInstructions ,
exec_list * PreCallInstructions )
{
ir_variable * TempVariable = new ( ParseState ) ir_variable (
InputType ,
NULL ,
ir_var_temporary ) ;
ir_dereference_variable * TempVariableDeref = new ( ParseState ) ir_dereference_variable ( TempVariable ) ;
PreCallInstructions - > push_tail ( TempVariable ) ;
2014-10-01 18:16:34 -04:00
//check ( InputSemantic ? (FCStringAnsi::Strnicmp(InputSemantic, "SV_", 3) ==0) : true);
2014-09-25 14:27:21 -04:00
// everything that's not an Outputpatch is patch constant. System values are treated specially
if ( Frequency = = HSF_DomainShader & & ! InputType - > is_outputpatch ( ) )
{
InputQualifier . Fields . bIsPatchConstant = true ;
}
if ( ( Frequency = = HSF_GeometryShader & & TempVariableDeref - > type - > is_array ( ) ) | |
( Frequency = = HSF_HullShader & & TempVariableDeref - > type - > is_inputpatch ( ) ) | |
( Frequency = = HSF_DomainShader & & TempVariableDeref - > type - > is_outputpatch ( ) )
)
{
check ( InputType - > is_array ( ) | | InputType - > is_inputpatch ( ) | | InputType - > is_outputpatch ( ) ) ;
check ( InputType - > length | | InputType - > patch_length ) ;
const unsigned ElementCount = InputType - > is_array ( ) ? InputType - > length : InputType - > patch_length ;
if ( ! ParseState - > symbols - > get_variable ( " gl_in " ) )
{
// Create a built-in OpenGL variable gl_in[] containing built-in types.
// This variable will be used for OpenGL optimization by IR, so IR must know about it,
// but will not end up in final GLSL code.
// It has to be created here, as it contains multiple built-in variables in one interface block,
// which is not usual, so avoiding special cases in code.
glsl_struct_field * BuiltinFields = ralloc_array ( ParseState , glsl_struct_field , 3 ) ;
memset ( BuiltinFields , 0 , 3 * sizeof ( glsl_struct_field ) ) ;
BuiltinFields [ 0 ] . type = glsl_type : : vec4_type ;
BuiltinFields [ 0 ] . name = ralloc_strdup ( ParseState , " gl_Position " ) ;
BuiltinFields [ 1 ] . type = glsl_type : : float_type ;
BuiltinFields [ 1 ] . name = ralloc_strdup ( ParseState , " gl_PointSize " ) ;
BuiltinFields [ 2 ] . type = glsl_type : : get_array_instance ( glsl_type : : float_type , 6 ) ; // magic number is gl_MaxClipDistances
BuiltinFields [ 2 ] . name = ralloc_strdup ( ParseState , " gl_ClipDistance " ) ;
const glsl_type * BuiltinStruct = glsl_type : : get_record_instance ( BuiltinFields , 3 , " gl_PerVertex " ) ;
const glsl_type * BuiltinArray = glsl_type : : get_array_instance ( BuiltinStruct , ElementCount ) ;
ir_variable * BuiltinVariable = new ( ParseState ) ir_variable ( BuiltinArray , " gl_in " , ir_var_in ) ;
BuiltinVariable - > read_only = true ;
BuiltinVariable - > is_interface_block = true ;
DeclInstructions - > push_tail ( BuiltinVariable ) ;
ParseState - > symbols - > add_variable ( BuiltinVariable ) ;
}
for ( unsigned i = 0 ; i < ElementCount ; + + i )
{
ir_dereference_array * ArrayDeref = new ( ParseState ) ir_dereference_array (
TempVariableDeref - > clone ( ParseState , NULL ) ,
new ( ParseState ) ir_constant ( ( unsigned ) i )
) ;
// Parse input variable
GenShaderInputForVariable (
Frequency ,
ParseState ,
InputSemantic ,
InputQualifier ,
ArrayDeref ,
DeclInstructions ,
PreCallInstructions ,
ElementCount ,
i
) ;
}
}
else
{
GenShaderInputForVariable (
Frequency ,
ParseState ,
InputSemantic ,
InputQualifier ,
TempVariableDeref ,
DeclInstructions ,
PreCallInstructions ,
0 ,
0
) ;
}
return TempVariableDeref ;
}
/**
* Generate an output semantic .
* @ param Frequency - The shader frequency .
* @ param ParseState - Parse state .
* @ param OutputSemantic - The semantic name to generate .
* @ param OutputQualifier - Qualifiers applied to the semantic .
* @ param OutputVariableDeref - Deref for the argument variable .
* @ param DeclInstructions - IR to which declarations may be added .
* @ param PostCallInstructions - IR to which instructions may be added after the
* entry point returns .
*/
void GenShaderOutputForVariable (
EHlslShaderFrequency Frequency ,
_mesa_glsl_parse_state * ParseState ,
const char * OutputSemantic ,
FSemanticQualifier OutputQualifier ,
ir_dereference * OutputVariableDeref ,
exec_list * DeclInstructions ,
exec_list * PostCallInstructions ,
int SemanticArraySize ,
int SemanticArrayIndex
)
{
const glsl_type * OutputType = OutputVariableDeref - > type ;
if ( OutputType - > is_record ( ) )
{
for ( uint32 i = 0 ; i < OutputType - > length ; + + i )
{
const char * FieldSemantic = OutputType - > fields . structure [ i ] . semantic ;
const char * Semantic = 0 ;
if ( OutputSemantic & & FieldSemantic )
{
_mesa_glsl_warning ( ParseState , " semantic '%s' of field '%s' will be overridden by enclosing types' semantic '%s' " ,
OutputType - > fields . structure [ i ] . semantic ,
OutputType - > fields . structure [ i ] . name ,
OutputSemantic ) ;
FieldSemantic = 0 ;
}
if ( OutputSemantic & & ! FieldSemantic )
{
2016-04-13 12:14:19 -04:00
Semantic = ralloc_asprintf ( ParseState , " %s%u " , OutputSemantic , i ) ;
2014-09-25 14:27:21 -04:00
_mesa_glsl_warning ( ParseState , " creating semantic '%s' for struct field '%s' " , Semantic , OutputType - > fields . structure [ i ] . name ) ;
}
else if ( ! OutputSemantic & & FieldSemantic )
{
Semantic = FieldSemantic ;
}
else
{
Semantic = 0 ;
}
if ( OutputType - > fields . structure [ i ] . type - > is_record ( ) | |
Semantic
)
{
FSemanticQualifier Qualifier = OutputQualifier ;
if ( Qualifier . Packed = = 0 )
{
Qualifier . Fields . bCentroid = OutputType - > fields . structure [ i ] . centroid ;
Qualifier . Fields . InterpolationMode = OutputType - > fields . structure [ i ] . interpolation ;
Qualifier . Fields . bIsPatchConstant = OutputType - > fields . structure [ i ] . patchconstant ;
}
// Dereference the field and generate shader outputs for the field.
ir_dereference * FieldDeref = new ( ParseState ) ir_dereference_record (
OutputVariableDeref - > clone ( ParseState , NULL ) ,
OutputType - > fields . structure [ i ] . name ) ;
GenShaderOutputForVariable (
Frequency ,
ParseState ,
Semantic ,
Qualifier ,
FieldDeref ,
DeclInstructions ,
PostCallInstructions ,
SemanticArraySize ,
SemanticArrayIndex
) ;
}
else
{
_mesa_glsl_error (
ParseState ,
" field '%s' in output structure '%s' does not specify a semantic " ,
OutputType - > fields . structure [ i ] . name ,
OutputType - > name
) ;
}
}
}
// TODO clean this up!!
else if ( ( OutputType - > is_array ( ) | | OutputType - > is_outputpatch ( ) ) )
{
if ( OutputSemantic )
{
int BaseIndex = 0 ;
const char * Semantic = 0 ;
ParseSemanticAndIndex ( ParseState , OutputSemantic , & Semantic , & BaseIndex ) ;
const unsigned ElementCount = OutputType - > is_array ( ) ? OutputType - > length : ( OutputType - > patch_length ) ;
for ( unsigned i = 0 ; i < ElementCount ; + + i )
{
ir_dereference_array * ArrayDeref = new ( ParseState ) ir_dereference_array (
OutputVariableDeref - > clone ( ParseState , NULL ) ,
new ( ParseState ) ir_constant ( ( unsigned ) i )
) ;
GenShaderOutputForVariable (
Frequency ,
ParseState ,
2016-04-13 12:14:19 -04:00
ralloc_asprintf ( ParseState , " %s%u " , Semantic , BaseIndex + i ) ,
2014-09-25 14:27:21 -04:00
OutputQualifier ,
ArrayDeref ,
DeclInstructions ,
PostCallInstructions ,
SemanticArraySize ,
SemanticArrayIndex
) ;
}
}
else
{
_mesa_glsl_error ( ParseState , " entry point does not specify a semantic for its return value " ) ;
}
}
else
{
if ( OutputSemantic )
{
YYLTYPE loc ;
ir_rvalue * Src = OutputVariableDeref - > clone ( ParseState , NULL ) ;
const glsl_type * DestVariableType = NULL ;
bool ApplyClipSpaceAdjustment = false ;
bool ApplyClampPowerOfTwo = false ;
ir_rvalue * DestVariableDeref = GenShaderOutputSemantic ( Frequency , ParseState , OutputSemantic ,
OutputQualifier , OutputType , DeclInstructions , & DestVariableType , ApplyClipSpaceAdjustment , ApplyClampPowerOfTwo ) ;
apply_type_conversion ( DestVariableType , Src , PostCallInstructions , ParseState , true , & loc ) ;
if ( ParseState - > adjust_clip_space_dx11_to_opengl & & ApplyClipSpaceAdjustment )
{
// Src.y = -Src.y;
PostCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
new ( ParseState ) ir_swizzle ( Src - > clone ( ParseState , NULL ) , 1 , 0 , 0 , 0 , 1 ) ,
new ( ParseState ) ir_expression ( ir_unop_neg ,
glsl_type : : float_type ,
new ( ParseState ) ir_swizzle ( Src - > clone ( ParseState , NULL ) , 1 , 0 , 0 , 0 , 1 ) ,
NULL )
)
) ;
// Src.z = ( 2.0 * Src.z ) - Src.w;
PostCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
new ( ParseState ) ir_swizzle ( Src - > clone ( ParseState , NULL ) , 2 , 0 , 0 , 0 , 1 ) ,
new ( ParseState ) ir_expression ( ir_binop_sub ,
new ( ParseState ) ir_expression ( ir_binop_mul ,
new ( ParseState ) ir_constant ( 2.0f ) ,
new ( ParseState ) ir_swizzle ( Src - > clone ( ParseState , NULL ) , 2 , 0 , 0 , 0 , 1 )
) ,
new ( ParseState ) ir_swizzle ( Src - > clone ( ParseState , NULL ) , 3 , 0 , 0 , 0 , 1 )
)
)
) ;
}
// GLSL doesn't support pow2 partitioning, so we treate pow2 as integer partitioning and
// manually compute the next power of two via exp2(pow(ceil(log2(Src)));
if ( ApplyClampPowerOfTwo )
{
ir_variable * temp = new ( ParseState ) ir_variable ( glsl_type : : float_type , NULL , ir_var_temporary ) ;
PostCallInstructions - > push_tail ( temp ) ;
PostCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
new ( ParseState ) ir_dereference_variable ( temp ) ,
new ( ParseState ) ir_expression ( ir_unop_exp2 ,
new ( ParseState ) ir_expression ( ir_unop_ceil ,
new ( ParseState ) ir_expression ( ir_unop_log2 ,
glsl_type : : float_type ,
Src - > clone ( ParseState , NULL ) ,
NULL
)
)
)
)
) ;
// assign pow2 clamped variable to output variable
PostCallInstructions - > push_tail (
new ( ParseState ) ir_assignment (
DestVariableDeref - > clone ( ParseState , NULL ) ,
new ( ParseState ) ir_dereference_variable ( temp )
)
) ;
}
else
{
PostCallInstructions - > push_tail ( new ( ParseState ) ir_assignment ( DestVariableDeref , Src ) ) ;
}
}
else
{
_mesa_glsl_error ( ParseState , " entry point does not specify a semantic for its return value " ) ;
}
}
}
/**
* Generate an output semantic .
* @ param Frequency - The shader frequency .
* @ param ParseState - Parse state .
* @ param OutputSemantic - The semantic name to generate .
* @ param OutputQualifier - Qualifiers applied to the semantic .
* @ param OutputType - Value type .
* @ param DeclInstructions - IR to which declarations may be added .
* @ param PreCallInstructions - IR to which isntructions may be added before the
entry point is called .
* @ param PostCallInstructions - IR to which instructions may be added after the
* entry point returns .
* @ returns the IR variable deref for the semantic .
*/
static ir_dereference_variable * GenShaderOutput (
EHlslShaderFrequency Frequency ,
_mesa_glsl_parse_state * ParseState ,
const char * OutputSemantic ,
FSemanticQualifier OutputQualifier ,
const glsl_type * OutputType ,
exec_list * DeclInstructions ,
exec_list * PreCallInstructions ,
exec_list * PostCallInstructions
)
{
// Generate a local variable to hold the output.
ir_variable * TempVariable = new ( ParseState ) ir_variable (
OutputType ,
NULL ,
ir_var_temporary ) ;
ir_dereference_variable * TempVariableDeref = new ( ParseState ) ir_dereference_variable ( TempVariable ) ;
PreCallInstructions - > push_tail ( TempVariable ) ;
GenShaderOutputForVariable (
Frequency ,
ParseState ,
OutputSemantic ,
OutputQualifier ,
TempVariableDeref ,
DeclInstructions ,
PostCallInstructions ,
0 ,
0
) ;
return TempVariableDeref ;
}
static void GenerateAppendFunctionBody (
_mesa_glsl_parse_state * ParseState ,
exec_list * DeclInstructions ,
const glsl_type * geometry_append_type
)
{
ir_function * func = ParseState - > symbols - > get_function ( " OutputStream_Append " ) ;
check ( func ) ;
exec_list comparison_parameter ;
ir_variable * var = new ( ParseState ) ir_variable ( geometry_append_type , ralloc_asprintf ( ParseState , " arg0 " ) , ir_var_in ) ;
comparison_parameter . push_tail ( var ) ;
bool is_exact = false ;
ir_function_signature * sig = func - > matching_signature ( & comparison_parameter , & is_exact ) ;
check ( sig & & is_exact ) ;
var = ( ir_variable * ) sig - > parameters . get_head ( ) ;
// {
// const glsl_type* output_type = var->type;
// _mesa_glsl_warning(ParseState, "GenerateAppendFunctionBody: parsing argument struct '%s'", output_type->name );
// int indexof_RenderTargetArrayIndex = -1;
// for (int i = 0; i < output_type->length; i++)
// {
// _mesa_glsl_warning(ParseState, " name '%s' : semantic '%s'", output_type->fields.structure[i].name, output_type->fields.structure[i].semantic );
// }
// }
// Generate assignment instructions from function argument to out variables
FSemanticQualifier OutputQualifier ;
ir_dereference_variable * TempVariableDeref = new ( ParseState ) ir_dereference_variable ( var ) ;
GenShaderOutputForVariable (
HSF_GeometryShader ,
ParseState ,
NULL ,
OutputQualifier ,
TempVariableDeref ,
DeclInstructions ,
& sig - > body ,
0 ,
0
) ;
// If the output structure type contains a SV_RenderTargetArrayIndex semantic, add a custom user output semantic.
// It's used to pass layer index to pixel shader, as GLSL 1.50 doesn't allow pixel shader to read from gl_Layer.
const glsl_type * output_type = var - > type ;
int indexof_RenderTargetArrayIndex = - 1 ;
for ( uint32 i = 0 ; i < output_type - > length ; i + + )
{
if ( output_type - > fields . structure [ i ] . semantic & & ( strcmp ( output_type - > fields . structure [ i ] . semantic , " SV_RenderTargetArrayIndex " ) = = 0 ) )
{
indexof_RenderTargetArrayIndex = i ;
break ;
}
}
if ( indexof_RenderTargetArrayIndex ! = - 1 )
{
// Add the new member with semantic
glsl_struct_field field ;
field . type = output_type - > fields . structure [ indexof_RenderTargetArrayIndex ] . type ;
field . name = " HLSLCCLayerIndex " ;
field . semantic = CUSTOM_LAYER_INDEX_SEMANTIC ;
field . centroid = 0 ;
field . interpolation = ir_interp_qualifier_flat ;
field . geometryinput = 0 ;
field . patchconstant = 0 ;
glsl_type * non_const_type = ( glsl_type * ) output_type ;
non_const_type - > add_structure_member ( & field ) ;
// Create new out variable for the new member and generate assignment that will copy input's layer index field to it
FSemanticQualifier Qualifier ;
Qualifier . Fields . bCentroid = 0 ;
Qualifier . Fields . InterpolationMode = ir_interp_qualifier_flat ;
const glsl_type * new_output_type = ( ( ir_variable * ) sig - > parameters . get_head ( ) ) - > type ;
GenShaderOutputForVariable (
HSF_GeometryShader ,
ParseState ,
CUSTOM_LAYER_INDEX_SEMANTIC ,
Qualifier ,
new ( ParseState ) ir_dereference_record ( var , new_output_type - > fields . structure [ indexof_RenderTargetArrayIndex ] . name ) ,
DeclInstructions ,
& sig - > body ,
0 ,
0
) ;
}
// Call EmitVertex()
ir_function * emitVertexFunc = ParseState - > symbols - > get_function ( " EmitVertex " ) ;
check ( emitVertexFunc ) ;
check ( emitVertexFunc - > signatures . get_head ( ) = = emitVertexFunc - > signatures . get_tail ( ) ) ;
ir_function_signature * emitVertexSig = ( ir_function_signature * ) emitVertexFunc - > signatures . get_head ( ) ;
exec_list actual_parameter ;
sig - > body . push_tail ( new ( ParseState ) ir_call ( emitVertexSig , NULL , & actual_parameter ) ) ;
}
bool FGlslCodeBackend : : GenerateMain (
EHlslShaderFrequency Frequency ,
const char * EntryPoint ,
exec_list * Instructions ,
_mesa_glsl_parse_state * ParseState )
{
{
// Set up origin_upper_left for gl_FragCoord, depending on HLSLCC_DX11ClipSpace flag presence.
FSystemValue * SystemValues = SystemValueTable [ HSF_PixelShader ] ;
for ( int i = 0 ; SystemValues [ i ] . Semantic ! = NULL ; + + i )
{
2014-10-01 18:16:34 -04:00
if ( FCStringAnsi : : Stricmp ( SystemValues [ i ] . GlslName , " gl_FragCoord " ) = = 0 )
2014-09-25 14:27:21 -04:00
{
SystemValues [ i ] . bOriginUpperLeft = ! ParseState - > adjust_clip_space_dx11_to_opengl ;
break ;
}
}
}
ir_function_signature * EntryPointSig = FindEntryPointFunction ( Instructions , ParseState , EntryPoint ) ;
if ( EntryPointSig )
{
void * TempMemContext = ralloc_context ( NULL ) ;
exec_list DeclInstructions ;
exec_list PreCallInstructions ;
exec_list ArgInstructions ;
exec_list PostCallInstructions ;
const glsl_type * geometry_append_type = NULL ;
ParseState - > maxvertexcount = EntryPointSig - > maxvertexcount ;
ParseState - > tessellation = EntryPointSig - > tessellation ;
ParseState - > symbols - > push_scope ( ) ;
foreach_iter ( exec_list_iterator , Iter , EntryPointSig - > parameters )
{
ir_variable * const Variable = ( ir_variable * ) Iter . get ( ) ;
if ( Variable - > semantic ! = NULL | | Variable - > type - > is_record ( )
| | ( Frequency = = HSF_GeometryShader & & ( Variable - > type - > is_outputstream ( ) | | Variable - > type - > is_array ( ) ) )
| | ( Frequency = = HSF_HullShader & & ( Variable - > type - > is_patch ( ) ) )
| | ( Frequency = = HSF_DomainShader & & ( Variable - > type - > is_outputpatch ( ) ) )
)
{
FSemanticQualifier Qualifier ;
Qualifier . Fields . bCentroid = Variable - > centroid ;
Variable - > centroid = 0 ;
Qualifier . Fields . InterpolationMode = Variable - > interpolation ;
Variable - > interpolation = 0 ;
Qualifier . Fields . bIsPatchConstant = Variable - > is_patch_constant ;
Variable - > is_patch_constant = 0 ;
ir_dereference_variable * ArgVarDeref = NULL ;
switch ( Variable - > mode )
{
case ir_var_in :
if ( Frequency = = HSF_GeometryShader & & Variable - > type - > is_array ( ) )
{
// Remember information about geometry input type globally
ParseState - > geometryinput = Variable - > geometryinput ;
}
if ( Frequency = = HSF_PixelShader )
{
// Replace SV_RenderTargetArrayIndex in
// input structure semantic with custom semantic.
if ( Variable - > semantic & & ( strcmp ( Variable - > semantic , " SV_RenderTargetArrayIndex " ) = = 0 ) )
{
// _mesa_glsl_warning(ParseState, "Replacing semantic of variable '%s' with our custom one", Variable->name);
Variable - > semantic = ralloc_strdup ( Variable , CUSTOM_LAYER_INDEX_SEMANTIC ) ;
Variable - > interpolation = ir_interp_qualifier_flat ;
}
else if ( Variable - > type - > is_record ( ) )
{
const glsl_type * output_type = Variable - > type ;
int indexof_RenderTargetArrayIndex = - 1 ;
for ( uint32 i = 0 ; i < output_type - > length ; i + + )
{
if ( Variable - > type - > fields . structure [ i ] . semantic & & ( strcmp ( Variable - > type - > fields . structure [ i ] . semantic , " SV_RenderTargetArrayIndex " ) = = 0 ) )
{
indexof_RenderTargetArrayIndex = i ;
break ;
}
}
if ( indexof_RenderTargetArrayIndex ! = - 1 )
{
// _mesa_glsl_warning(ParseState, "Replacing semantic of member %d of variable '%s' with our custom one", indexof_RenderTargetArrayIndex, Variable->name);
// Replace the member with one with semantic
glsl_struct_field field ;
field . type = Variable - > type - > fields . structure [ indexof_RenderTargetArrayIndex ] . type ;
field . name = Variable - > type - > fields . structure [ indexof_RenderTargetArrayIndex ] . name ;
field . semantic = CUSTOM_LAYER_INDEX_SEMANTIC ;
field . centroid = 0 ;
field . interpolation = ir_interp_qualifier_flat ;
field . geometryinput = 0 ;
field . patchconstant = 0 ;
glsl_type * non_const_type = ( glsl_type * ) output_type ;
non_const_type - > replace_structure_member ( indexof_RenderTargetArrayIndex , & field ) ;
}
}
}
ArgVarDeref = GenShaderInput (
Frequency ,
ParseState ,
Variable - > semantic ,
Qualifier ,
Variable - > type ,
& DeclInstructions ,
& PreCallInstructions
) ;
break ;
case ir_var_out :
ArgVarDeref = GenShaderOutput (
Frequency ,
ParseState ,
Variable - > semantic ,
Qualifier ,
Variable - > type ,
& DeclInstructions ,
& PreCallInstructions ,
& PostCallInstructions
) ;
break ;
case ir_var_inout :
{
check ( Frequency = = HSF_GeometryShader ) ;
// This is an output stream for geometry shader. It's not referenced as a variable inside the function,
// instead OutputStream.Append(vertex) and OutputStream.RestartStrip() are called, and this variable
// has already been optimized out of them in ast_to_hir translation.
// Generate a local variable to add to arguments. It won't be referenced anywhere, so it should get optimized out.
ir_variable * TempVariable = new ( ParseState ) ir_variable (
Variable - > type ,
NULL ,
ir_var_temporary ) ;
ArgVarDeref = new ( ParseState ) ir_dereference_variable ( TempVariable ) ;
PreCallInstructions . push_tail ( TempVariable ) ;
// We need to move this information somewhere safer, as this pseudo-variable will get optimized out of existence
ParseState - > outputstream_type = Variable - > type - > outputstream_type ;
check ( Variable - > type - > is_outputstream ( ) ) ;
check ( Variable - > type - > inner_type - > is_record ( ) ) ;
geometry_append_type = Variable - > type - > inner_type ;
}
break ;
default :
{
_mesa_glsl_error (
ParseState ,
" entry point parameter '%s' must be an input or output " ,
Variable - > name
) ;
}
}
ArgInstructions . push_tail ( ArgVarDeref ) ;
}
else
{
_mesa_glsl_error ( ParseState , " entry point parameter "
" '%s' does not specify a semantic " , Variable - > name ) ;
}
}
// The function's return value should have an output semantic if it's not void.
ir_dereference_variable * EntryPointReturn = NULL ;
if ( EntryPointSig - > return_type - > is_void ( ) = = false )
{
FSemanticQualifier Qualifier ;
EntryPointReturn = GenShaderOutput (
Frequency ,
ParseState ,
EntryPointSig - > return_semantic ,
Qualifier ,
EntryPointSig - > return_type ,
& DeclInstructions ,
& PreCallInstructions ,
& PostCallInstructions
) ;
}
if ( Frequency = = HSF_GeometryShader )
{
GenerateAppendFunctionBody (
ParseState ,
& DeclInstructions ,
geometry_append_type
) ;
}
/*
we map the HLSL hull shader to this GLSL main function
for the most parts , we treat variables of InputPatch and OutputPatch as arrays of the inner type
build input patch from shader input interface blocks
call hull shader main function with input patch and current control point id ( gl_InvocationID )
copy hull shader main result for the current control point to the proper shader output interface block element
barrier
( so all instances have computed the per control point data )
build patch constant function input ( of type output patch ) from the shader output interface blocks
( need to do this , since this is the only shader variable shared between control points running in parallel )
if control point id ( gl_InvocationID ) is 0
call patch constant function with the output patch as an input
copy the patch constant result to the " patch " shader output interface block
*/
if ( Frequency = = HSF_HullShader )
{
ir_function_signature * PatchConstantSig = FindPatchConstantFunction ( Instructions , ParseState ) ;
if ( ! PatchConstantSig )
{
_mesa_glsl_error ( ParseState , " patch constant function `%s' not found " , ParseState - > tessellation . patchconstantfunc ) ;
}
const glsl_type * OutputPatchType = glsl_type : : get_templated_instance ( EntryPointReturn - > type , " OutputPatch " , 0 , ParseState - > tessellation . outputcontrolpoints ) ;
ir_variable * OutputPatchVar = new ( ParseState ) ir_variable ( OutputPatchType , NULL , ir_var_temporary ) ;
// call barrier() to ensure that all threads have computed the per-patch computation
{
// We can't just use the symbol table b/c it only has the HLSL and not the GLSL barrier functions in it
foreach_iter ( exec_list_iterator , Iter , * Instructions )
{
ir_instruction * ir = ( ir_instruction * ) Iter . get ( ) ;
ir_function * Function = ir - > as_function ( ) ;
if ( Function & & strcmp ( Function - > name , " barrier " ) = = 0 )
{
check ( Function - > signatures . get_head ( ) = = Function - > signatures . get_tail ( ) ) ;
exec_list VoidParameter ;
ir_function_signature * BarrierFunctionSig = Function - > matching_signature ( & VoidParameter ) ;
PostCallInstructions . push_tail ( new ( ParseState ) ir_call ( BarrierFunctionSig , NULL , & VoidParameter ) ) ;
}
}
}
// reassemble output patch variable(for the patch constant function) from the shader outputs
GenShaderPatchConstantFunctionInputs ( ParseState , OutputPatchVar , PostCallInstructions ) ;
// call the entry point
if ( PatchConstantSig )
{
CallPatchConstantFunction ( ParseState , OutputPatchVar , PatchConstantSig , DeclInstructions , PostCallInstructions ) ;
}
}
ParseState - > symbols - > pop_scope ( ) ;
// Build the void main() function for GLSL.
ir_function_signature * MainSig = new ( ParseState ) ir_function_signature ( glsl_type : : void_type ) ;
MainSig - > is_defined = true ;
MainSig - > is_main = true ;
MainSig - > body . append_list ( & PreCallInstructions ) ;
MainSig - > body . push_tail ( new ( ParseState ) ir_call ( EntryPointSig , EntryPointReturn , & ArgInstructions ) ) ;
MainSig - > body . append_list ( & PostCallInstructions ) ;
MainSig - > maxvertexcount = EntryPointSig - > maxvertexcount ;
MainSig - > is_early_depth_stencil = EntryPointSig - > is_early_depth_stencil ;
MainSig - > wg_size_x = EntryPointSig - > wg_size_x ;
MainSig - > wg_size_y = EntryPointSig - > wg_size_y ;
MainSig - > wg_size_z = EntryPointSig - > wg_size_z ;
MainSig - > tessellation = EntryPointSig - > tessellation ;
if ( MainSig - > is_early_depth_stencil & & Frequency ! = HSF_PixelShader )
{
_mesa_glsl_error ( ParseState , " 'earlydepthstencil' attribute only applies to pixel shaders " ) ;
}
if ( MainSig - > maxvertexcount > 0 & & Frequency ! = HSF_GeometryShader )
{
_mesa_glsl_error ( ParseState , " 'maxvertexcount' attribute only applies to geometry shaders " ) ;
}
if ( MainSig - > is_early_depth_stencil & & ParseState - > language_version < 310 )
{
_mesa_glsl_error ( ParseState , " 'earlydepthstencil' attribute only supported on GLSL 4.30 target and later " ) ;
}
if ( MainSig - > wg_size_x > 0 & & Frequency ! = HSF_ComputeShader )
{
_mesa_glsl_error ( ParseState , " 'num_threads' attribute only applies to compute shaders " ) ;
}
// in GLSL, unlike in HLSL fixed-function tessellator properties are specified on the domain shader
// and not the hull shader, so we specify them for both in the .usf shaders and then print a warning,
// similar to what fxc is doing
if ( MainSig - > tessellation . domain ! = GLSL_DOMAIN_NONE & & ( Frequency ! = HSF_HullShader & & Frequency ! = HSF_DomainShader ) )
{
_mesa_glsl_warning ( ParseState , " 'domain' attribute only applies to hull or domain shaders " ) ;
}
if ( MainSig - > tessellation . outputtopology ! = GLSL_OUTPUTTOPOLOGY_NONE & & Frequency ! = HSF_HullShader )
{
_mesa_glsl_warning ( ParseState , " 'outputtopology' attribute only applies to hull shaders " ) ;
}
if ( MainSig - > tessellation . partitioning ! = GLSL_PARTITIONING_NONE & & Frequency ! = HSF_HullShader )
{
_mesa_glsl_warning ( ParseState , " 'partitioning' attribute only applies to hull shaders " ) ;
}
if ( MainSig - > tessellation . outputcontrolpoints > 0 & & Frequency ! = HSF_HullShader )
{
_mesa_glsl_warning ( ParseState , " 'outputcontrolpoints' attribute only applies to hull shaders " ) ;
}
if ( MainSig - > tessellation . maxtessfactor > 0.0f & & Frequency ! = HSF_HullShader )
{
_mesa_glsl_warning ( ParseState , " 'maxtessfactor' attribute only applies to hull shaders " ) ;
}
if ( MainSig - > tessellation . patchconstantfunc ! = 0 & & Frequency ! = HSF_HullShader )
{
_mesa_glsl_warning ( ParseState , " 'patchconstantfunc' attribute only applies to hull shaders " ) ;
}
ir_function * MainFunction = new ( ParseState ) ir_function ( " main " ) ;
MainFunction - > add_signature ( MainSig ) ;
Instructions - > append_list ( & DeclInstructions ) ;
Instructions - > push_tail ( MainFunction ) ;
ralloc_free ( TempMemContext ) ;
// Now that we have a proper main(), move global setup to main().
MoveGlobalInstructionsToMain ( Instructions ) ;
}
else
{
_mesa_glsl_error ( ParseState , " shader entry point '%s' not "
" found " , EntryPoint ) ;
}
return true ;
}
ir_function_signature * FGlslCodeBackend : : FindPatchConstantFunction ( exec_list * Instructions , _mesa_glsl_parse_state * ParseState )
{
ir_function_signature * PatchConstantSig = 0 ;
// TODO refactor this and the fetching of the main siganture
foreach_iter ( exec_list_iterator , Iter , * Instructions )
{
ir_instruction * ir = ( ir_instruction * ) Iter . get ( ) ;
ir_function * Function = ir - > as_function ( ) ;
if ( Function & & strcmp ( Function - > name , ParseState - > tessellation . patchconstantfunc ) = = 0 )
{
int NumSigs = 0 ;
foreach_iter ( exec_list_iterator , SigIter , * Function )
{
if ( + + NumSigs = = 1 )
{
PatchConstantSig = ( ir_function_signature * ) SigIter . get ( ) ;
}
}
if ( NumSigs = = 1 )
{
break ;
}
else
{
_mesa_glsl_error ( ParseState , " patch constant function "
" `%s' has multiple signatures " , ParseState - > tessellation . patchconstantfunc ) ;
}
}
}
return PatchConstantSig ;
}
void FGlslCodeBackend : : CallPatchConstantFunction ( _mesa_glsl_parse_state * ParseState , ir_variable * OutputPatchVar , ir_function_signature * PatchConstantSig , exec_list & DeclInstructions , exec_list & PostCallInstructions )
{
exec_list PatchConstantArgs ;
if ( OutputPatchVar & & ! PatchConstantSig - > parameters . is_empty ( ) )
{
PatchConstantArgs . push_tail ( new ( ParseState ) ir_dereference_variable ( OutputPatchVar ) ) ;
}
ir_if * thread_if = new ( ParseState ) ir_if (
new ( ParseState ) ir_expression (
ir_binop_equal ,
new ( ParseState ) ir_constant (
0
) ,
new ( ParseState ) ir_dereference_variable (
ParseState - > symbols - > get_variable ( " gl_InvocationID " )
)
)
) ;
exec_list PrePatchConstCallInstructions ;
exec_list PostPatchConstCallInstructions ;
FSemanticQualifier Qualifier ;
Qualifier . Fields . bIsPatchConstant = 1 ;
ir_dereference_variable * PatchConstantReturn = GenShaderOutput (
HSF_HullShader ,
ParseState ,
PatchConstantSig - > return_semantic ,
Qualifier ,
PatchConstantSig - > return_type ,
& DeclInstructions ,
& PrePatchConstCallInstructions ,
& PostPatchConstCallInstructions
) ;
thread_if - > then_instructions . append_list ( & PrePatchConstCallInstructions ) ;
thread_if - > then_instructions . push_tail ( new ( ParseState ) ir_call ( PatchConstantSig , PatchConstantReturn , & PatchConstantArgs ) ) ;
thread_if - > then_instructions . append_list ( & PostPatchConstCallInstructions ) ;
PostCallInstructions . push_tail ( thread_if ) ;
}
/*
reassemble output patch variable ( for the patch constant function ) from the shader outputs
turn this : ( from the GenOutputs of calling the entry point main )
out_InnerMember [ gl_InvocationID ] . Data = t2 . Middle . Inner . Value ;
into this :
//output_patch<FPNTessellationHSToDS> FPNTessellationHSToDS t3[3]; //output_patch<FPNTessellationHSToDS> ;
t3 [ 0 ] . Middle . Inner . Value = out_InnerMember [ 0 ] . Data ;
t3 [ 1 ] . Middle . Inner . Value = out_InnerMember [ 1 ] . Data ;
t3 [ 2 ] . Middle . Inner . Value = out_InnerMember [ 2 ] . Data ;
*/
void FGlslCodeBackend : : GenShaderPatchConstantFunctionInputs ( _mesa_glsl_parse_state * ParseState , ir_variable * OutputPatchVar , exec_list & PostCallInstructions )
{
PostCallInstructions . push_tail ( OutputPatchVar ) ;
foreach_iter ( exec_list_iterator , Iter , PostCallInstructions )
{
ir_instruction * ir = ( ir_instruction * ) Iter . get ( ) ;
ir_assignment * assignment = ir - > as_assignment ( ) ;
if ( ! assignment )
{
continue ;
}
ir_dereference_record * lhs = assignment - > lhs - > as_dereference_record ( ) ;
ir_rvalue * rhs = assignment - > rhs ;
if ( ! lhs )
{
continue ;
}
if ( ! rhs )
{
continue ;
}
ir_dereference_array * lhs_array = lhs - > record - > as_dereference_array ( ) ;
if ( ! lhs_array )
{
continue ;
}
ir_dereference_variable * OutputPatchArrayIndex = lhs_array - > array_index - > as_dereference_variable ( ) ;
ir_dereference_variable * OutputPatchArray = lhs_array - > array - > as_dereference_variable ( ) ;
if ( ! OutputPatchArrayIndex )
{
continue ;
}
if ( 0 ! = strcmp ( OutputPatchArrayIndex - > var - > name , " gl_InvocationID " ) )
{
continue ;
}
if ( ! OutputPatchArray )
{
continue ;
}
const char * OutArrayFieldName = lhs - > field ;
for ( int OutputVertex = 0 ; OutputVertex < ParseState - > tessellation . outputcontrolpoints ; + + OutputVertex )
{
struct Helper
{
// the struct inside the output patch can have the actual outputs with semantics nested inside,
static void ReplaceVariableDerefWithArrayDeref ( ir_instruction * Node , ir_dereference_array * ArrayDereference )
{
if ( ir_dereference_record * AsRecord = Node - > as_dereference_record ( ) )
{
if ( AsRecord - > record - > as_dereference_variable ( ) )
{
AsRecord - > record = ArrayDereference ;
}
else
{
ReplaceVariableDerefWithArrayDeref ( AsRecord - > record , ArrayDereference ) ;
}
}
else if ( ir_dereference_array * AsArray = Node - > as_dereference_array ( ) )
{
if ( AsArray - > array - > as_dereference_variable ( ) )
{
AsArray - > array = ArrayDereference ;
}
else
{
ReplaceVariableDerefWithArrayDeref ( AsArray - > array , ArrayDereference ) ;
}
}
else
{
check ( false ) ;
}
}
} ;
ir_dereference_array * OutputPatchElementIndex = new ( ParseState ) ir_dereference_array (
OutputPatchVar ,
new ( ParseState ) ir_constant (
OutputVertex
)
) ;
ir_rvalue * OutputPatchElement = rhs - > clone ( ParseState , 0 ) ;
Helper : : ReplaceVariableDerefWithArrayDeref ( OutputPatchElement , OutputPatchElementIndex ) ;
PostCallInstructions . push_tail (
new ( ParseState ) ir_assignment (
OutputPatchElement ,
new ( ParseState ) ir_dereference_record (
new ( ParseState ) ir_dereference_array (
OutputPatchArray - > clone ( ParseState , 0 ) ,
new ( ParseState ) ir_constant ( OutputVertex )
) ,
OutArrayFieldName
)
)
) ;
}
}
}
void FGlslLanguageSpec : : SetupLanguageIntrinsics ( _mesa_glsl_parse_state * State , exec_list * ir )
{
if ( bIsES2 )
{
make_intrinsic_genType ( ir , State , FRAMEBUFFER_FETCH_ES2 , ir_invalid_opcode , IR_INTRINSIC_FLOAT , 0 , 4 , 4 ) ;
2015-06-25 02:07:29 -04:00
make_intrinsic_genType ( ir , State , DEPTHBUFFER_FETCH_ES2 , ir_invalid_opcode , IR_INTRINSIC_ALL_FLOATING , 3 , 1 , 1 ) ;
2015-07-15 06:39:44 -04:00
make_intrinsic_genType ( ir , State , GET_HDR_32BPP_HDR_ENCODE_MODE_ES2 , ir_invalid_opcode , IR_INTRINSIC_ALL_FLOATING , 0 ) ;
2014-09-25 14:27:21 -04:00
}
2014-11-11 17:28:52 -05:00
if ( State - > language_version > = 310 )
{
/**
* Create GLSL functions that are left out of the symbol table
* Prevent pollution , but make them so thay can be used to
* implement the hlsl barriers
*/
const int glslFuncCount = 7 ;
const char * glslFuncName [ glslFuncCount ] =
{
" barrier " , " memoryBarrier " , " memoryBarrierAtomicCounter " , " memoryBarrierBuffer " ,
" memoryBarrierShared " , " memoryBarrierImage " , " groupMemoryBarrier "
} ;
ir_function * glslFuncs [ glslFuncCount ] ;
for ( int i = 0 ; i < glslFuncCount ; i + + )
{
void * ctx = State ;
ir_function * func = new ( ctx ) ir_function ( glslFuncName [ i ] ) ;
ir_function_signature * sig = new ( ctx ) ir_function_signature ( glsl_type : : void_type ) ;
sig - > is_builtin = true ;
func - > add_signature ( sig ) ;
ir - > push_tail ( func ) ;
glslFuncs [ i ] = func ;
}
/** Implement HLSL barriers in terms of GLSL functions */
const char * functions [ ] =
{
" GroupMemoryBarrier " , " GroupMemoryBarrierWithGroupSync " ,
" DeviceMemoryBarrier " , " DeviceMemoryBarrierWithGroupSync " ,
" AllMemoryBarrier " , " AllMemoryBarrierWithGroupSync "
} ;
const int max_children = 4 ;
ir_function * implFuncs [ ] [ max_children ] =
{
{ glslFuncs [ 4 ] } /**{"memoryBarrierShared"}*/ ,
{ glslFuncs [ 4 ] , glslFuncs [ 0 ] } /**{"memoryBarrierShared","barrier"}*/ ,
{ glslFuncs [ 2 ] , glslFuncs [ 3 ] , glslFuncs [ 5 ] } /**{"memoryBarrierAtomicCounter", "memoryBarrierBuffer", "memoryBarrierImage"}*/ ,
{ glslFuncs [ 2 ] , glslFuncs [ 3 ] , glslFuncs [ 5 ] , glslFuncs [ 0 ] } /**{"memoryBarrierAtomicCounter", "memoryBarrierBuffer", "memoryBarrierImage", "barrier"}*/ ,
{ glslFuncs [ 1 ] } /**{"memoryBarrier"}*/ ,
{ glslFuncs [ 1 ] , glslFuncs [ 0 ] } /**{"groupMemoryBarrier","barrier"}*/
} ;
for ( size_t i = 0 ; i < sizeof ( functions ) / sizeof ( const char * ) ; i + + )
{
void * ctx = State ;
ir_function * func = new ( ctx ) ir_function ( functions [ i ] ) ;
ir_function_signature * sig = new ( ctx ) ir_function_signature ( glsl_type : : void_type ) ;
sig - > is_builtin = true ;
sig - > is_defined = true ;
for ( int j = 0 ; j < max_children ; j + + )
{
if ( implFuncs [ i ] [ j ] = = NULL )
break ;
ir_function * child = implFuncs [ i ] [ j ] ;
check ( child ) ;
check ( child - > signatures . get_head ( ) = = child - > signatures . get_tail ( ) ) ;
ir_function_signature * childSig = ( ir_function_signature * ) child - > signatures . get_head ( ) ;
exec_list actual_parameter ;
sig - > body . push_tail (
new ( ctx ) ir_call ( childSig , NULL , & actual_parameter )
) ;
}
func - > add_signature ( sig ) ;
State - > symbols - > add_global_function ( func ) ;
ir - > push_tail ( func ) ;
}
}
2014-09-25 14:27:21 -04:00
}