You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#lockdown Nick.Penwarden #rb None ========================== MAJOR FEATURES + CHANGES ========================== Change 3358140 on 2017/03/22 by Rolando.Caloca DR - Fix copy to cube face - Compile fix when using dump layer - Add new error enum Change 3358301 on 2017/03/22 by Mitchell.Wilson Initial check in of LODs in InfiltratorForward. First pass on optimization in level. Adding a visibility track for SceneCapture2D in tunnel section. Change 3358477 on 2017/03/22 by Mitchell.Wilson Updating Skeletal Mesh DPW_Robot_Export to resolve screen size being too low for LOD1. Cleaned up LOD1 which was showing some visible popping when transitioning. Change 3358529 on 2017/03/22 by Mark.Satterthwaite Globally disable clang's "constant-logical-operand" warning when running under Distcc - it is much easier and less invasive than constantly fixing the code. Change 3358745 on 2017/03/22 by Mark.Satterthwaite Disable another warning (parentheses-equality) under Distcc because again the separation of preprocessing from compilation means it turns up where it isn't expected. Change 3358837 on 2017/03/22 by Joe.Graf Merge of pull request #3214 for the RenderDocPlugin #CodeReview: matt.kuhlenschmidt, marcus.wassmer #rb: marcus.wassmer Change 3359112 on 2017/03/22 by Ben.Salem Update perf monitor to include frame time by default. Also, use only game/PIE world timers when in editor, instead of all worlds combined. #tests Ran several Showdown test runs with plugin! Change 3359363 on 2017/03/22 by Joe.Graf First pass at non-unity & no pch compilation Change 3359449 on 2017/03/22 by Joe.Graf Added missing null check when exporting a EXR on Linux (UE-40268) #CodeReview: dmitry.rekman #rb: n/a Change 3360349 on 2017/03/23 by Guillaume.Abadie Fixes TAA's AA_FORCE_ALPHA_CLAMP causing DOF layouts. #jira UE-42920 Change 3360405 on 2017/03/23 by Marcus.Wassmer Better method for detecting Kepler Change 3360718 on 2017/03/23 by Daniel.Wright Planar reflections handle views smaller than the render target in a general way * Fixes planar reflections with adaptive pixel density (ViewFamily size larger than actual views combined) * Planar reflections are now supported in splitscreen Change 3360758 on 2017/03/23 by Daniel.Wright [Copy] Added new light property bCastVolumetricShadow, which defaults to true for directional and sky lights, but false for point / spot lights as supporting volumetric fog shadowing has significant GPU overhead Change 3360762 on 2017/03/23 by Daniel.Wright [Copy] Texture flags are now properly routed to RHICreateTexture3D from the render target pool Change 3360768 on 2017/03/23 by Daniel.Wright [Copy] Disabled GPUProfiler histogram by default, controlled by r.ProfileGPU.ShowEventHistogram Change 3360770 on 2017/03/23 by Daniel.Wright [Copy] Disabled fast clears on CustomDepth, saves .2ms on xbox Change 3360771 on 2017/03/23 by Daniel.Wright [Copy] Particle lights no longer force tiled deferred lighting. Tiled deferred lighting is only used if enough unshadowed lights + particle lights are on screen. Saves 1.5ms Xbox with one particle light. Change 3360774 on 2017/03/23 by Daniel.Wright [Copy] Distance field cvar comments Change 3360782 on 2017/03/23 by Daniel.Wright [Copy] Disabled selection color on Volume materials Change 3360795 on 2017/03/23 by Daniel.Wright [Copy] Volume materials now specify Albedo and Extinction, which is more intuitive than Scattering and Absorption. Albedo is [0-1] reflectance, while Extinction is a world space density. Change 3360799 on 2017/03/23 by Daniel.Wright [Copy] Cinematic scalability levels get 2x volumetric fog resolution in x and y Change 3360806 on 2017/03/23 by Daniel.Wright [Copy] Fixed volumetric fog being offset when viewport min is not 0 Change 3360809 on 2017/03/23 by Daniel.Wright [Copy] Volumetric fog now adds a bias to the inverse squared light falloff denominator, prevents extreme aliasing from the hotspot. Can be controlled with r.VolumetricFog.InverseSquaredLightDistanceBiasScale. Change 3361651 on 2017/03/23 by Brian.Karis Higher quality sharp SSR at quality 4 Change 3361678 on 2017/03/23 by Brian.Karis Fresnel darkens diffuse for clearcoat. Change 3361683 on 2017/03/23 by Brian.Karis Fixed SSR artifact Change 3361691 on 2017/03/23 by Brian.Karis Chagned min roughness limit Change 3361707 on 2017/03/23 by Brian.Karis Added inverse film tone map Change 3361726 on 2017/03/23 by Brian.Karis Better precision inverse Change 3361758 on 2017/03/23 by Brian.Karis Material flag normal curvature to roughness is no longer forward only. Change 3361765 on 2017/03/23 by Brian.Karis Update ACES Change 3361774 on 2017/03/23 by Brian.Karis Cleaned up alpha support and disabled screen edge clipping. Change 3362478 on 2017/03/24 by Guillaume.Abadie Cherry pick 3316084's PostProcessing.cpp: Fixes a bug in Circle DOF where the apply pass was no longer using the downres DOF's TAA output. #author Brian.Karis #jira UE-42920 Change 3362738 on 2017/03/24 by Rolando.Caloca DR - Hide scene capture on IF Change 3362890 on 2017/03/24 by Guillaume.Abadie Renames r.SceneAlpha to r.PostProcessing.PropagateAlpha Change 3363665 on 2017/03/24 by Mark.Satterthwaite PR #3414: Add command line option "-noheartbeatthread" to disable heart beat thread (Contributed by JeffRous) Change 3363866 on 2017/03/24 by Arne.Schober DR - Updated NVAPI #RB Marcus.Wassmer Change 3364300 on 2017/03/24 by Brian.Karis SSR use dynamic velocity Change 3364372 on 2017/03/24 by Brian.Karis Fix changing off axis projection velocities. Change 3364373 on 2017/03/24 by Brian.Karis Enabled velocity drawing in scene captures Change 3365531 on 2017/03/27 by Guillaume.Abadie Computes the material's screen position material expression directly from the pixel shader SvPosition Change 3365764 on 2017/03/27 by Chris.Bunner Lowering severity of crash for missing values in scalability.ini. #jira UE-41331 Change 3365916 on 2017/03/27 by Guillaume.Abadie Exposes the viewport offset within the view property material expression Change 3365979 on 2017/03/27 by Brian.Karis Fixed skylight intensity from double applying Change 3365987 on 2017/03/27 by Brian.Karis Stopped post process indirect lighting intensity from scaling skylight reflections Change 3365991 on 2017/03/27 by Brian.Karis Fix for static analysis Change 3366028 on 2017/03/27 by Daniel.Wright Volumetric fog supports static shadowing from Stationary lights * Using bilinear on static shadowmap depths + 1 PCF to smooth out results Change 3366029 on 2017/03/27 by Daniel.Wright Static shadow depth maps for Stationary point and spot lights are 2x higher res by default (4x more texels), which is more appropriate for volumetric fog Change 3366055 on 2017/03/27 by Guillaume.Abadie Cherry picks 3251469: Implements scene capture component's CaptureSortPriority to control GPU execution order in order to manage inter dependencies. Change 3366447 on 2017/03/27 by Simon.Tourangeau Fix IES light profile importer. - Bug in the LM-63-1986 format importer. Change3366836on 2017/03/27 by Brian.Karis ClearUAV now supports int types Change 3367435 on 2017/03/28 by Benjamin.Hyder Submitting Decal Automation map for initial approval Change 3367572 on 2017/03/28 by Chris.Bunner Changed ClampedPow {max(abs(x),0.00001)} to PositiveClampedPow {max(x,0)} to give more expected results to Power node in material graphs. #jira UE-42989 Change 3367756 on 2017/03/28 by Olaf.Piesche Niagara material usage flags Change 3367835 on 2017/03/28 by Marcus.Wassmer Fix crash when TileRenderer runs before anything else. Make explicit behavior when rendering at a time when there is no valid scene. Change 3367837 on 2017/03/28 by Marcus.Wassmer Missed a file. Change 3367838 on 2017/03/28 by Richard.Wallis Updated items from original shelved version by Mark Satt: - Added MetalBackend.cpp to change main function string to have an initial crc + code length zero's **Description below taken from Mark Satt's original verison of this in CL3343280** Updated for Dev-Rendering's PSOs & integrates Richard's work on RHI shader libraries. Replace the FShaderCache's cook-time binary shader cache with Dmitriy Dyomin's standalone FShaderCodeLibrary that saves all shader byte-code arrays to files named by the FSHAHash. This de-duplicates shaders so we only ever store the byte code once. Includes optional support for generating a platform specific library file - which Metal implements to provide a single Metal library. The platform-native implementation can perform more de-duplication and in the case of Metal has lower file overheads and will compress more efficiently. - All of the support code for the FShaderCache's cook caching is gone, which affects all platforms. The FShaderCodeLibrary is currently supported by Cook-By-The-Book but can be used with iterate or child cookers - only DLC cooking requires further work. - With further modifications it should be possible to support Cook-on-the-Fly as well (output directories would be needed in FShaderCodeLibrary::InitForCooking) and the file-access pattern should be changed to use async. IO so that Material loading is not considered complete until all required byte-code arrays are loaded into the FShaderCodeLibrary. - For Metal archiving shaders this way will compile with debug information and the FShaderCodeLibrary, with some help from extensions to IShaderFormat, will save the debug information out into separate files during cooking - these can then be used to debug the game without having to locally recompile, recook & repackage but the shipped byte-code is stripped. Global shader caches are also subject to de-duplication in the library in order to support Metal's shader stripping. - File Move operations need to respect the 'Replace' flag - for FShaderCodeLibrary to work we need Move to be atomic. - This bumps the object version and will cause all content to recook. - Native library support is optional - only Metal currently implements one, but so could Vulkan and D3D12. For Metal the big advantages are further de-duplication where different materials generate the same MetalSL text but a different FSHAHash, that the single Metal library has lower overhead and that as a single file it all compresses far better (esp. with LZMA - 5x smaller). Change 3367854 on 2017/03/28 by Mark.Satterthwaite Don't track or record draw call resources for non-OpenGL shader platforms in the shader-cache as it is unnecessary and makes it slower on the CPU than it needs to be. Change 3367877 on 2017/03/28 by Brian.Karis Fixed linux build hopefully Change 3368001 on 2017/03/28 by Mark.Satterthwaite Compile fixes from Richard's checkin caused by not having visibility to all platforms from my original shelves. Change 3368019 on 2017/03/28 by Mark.Satterthwaite And another fix for Windows compilation of MetalShaderFormat. Change 3368042 on 2017/03/28 by Mark.Satterthwaite And a couple of simpler MSVC errors. Change 3368271 on 2017/03/28 by Mark.Satterthwaite Make SceneRenderTargets compile again. Change 3368691 on 2017/03/28 by Daniel.Wright [Copy from BenW] Renamed r.Shadow.MaxCSMShadowResolution to r.Shadow.MaxCSMResolution to match scalability inis Change 3369689 on 2017/03/29 by Marcus.Wassmer Fix non editor compile for now Change 3369862 on 2017/03/29 by Marcus.Wassmer Get the rest of the things compiling again. Change 3369896 on 2017/03/29 by Chris.Bunner Enabling AMD HDR support by default. #jira UE-42113 Change 3370535 on 2017/03/29 by Marcus.Wassmer DR - Fix template explicit instantiation for ClearUAV permutations #RB Brian.Karis, Arne.Schober Change 3370704 on 2017/03/29 by Rolando.Caloca DR - Rewrote GPU Skin Cache - Per section buffers - Limited memory per non-editor worlds (control with r.SkinCache.SceneMemoryLimitInMB) Copied from 3370529 Change 3371389 on 2017/03/30 by Richard.Wallis Remove temp working directories after archive packages built. Change 3371641 on 2017/03/30 by Rolando.Caloca DR - Copy 3371640 (fix mem leak) Change 3372436 on 2017/03/30 by Uriel.Doyon Added flags in UPrimitiveComponent to keep track of its state in the streaming manager. This allows to avoid unnecessary callback and processing in begin destroy reattach and being destroy logic. Removed the limitation of only processing UMeshComponent when handling spawed primitive. This releases the level manager from having to manage dynamic primitives. This improves performance by not having to manage dynamic references in the level manager. Primitives managed as dynamic now have a callback when ever their proxy is udpated, handling many cases automatically where previously a manual callback to notify would have been required. Fixed an issue where primitives with no reference to streaming textures would loose they dynamic state because of lack of references in the streamer. Change 3372740 on 2017/03/30 by Chris.Bunner [Experimental] Partial compute post process pipeline (r.PostProcess.PreferCompute). StencilSceneTexture added to deferred list. A few known issues to be fixed in a follow-up CL. Change 3372765 on 2017/03/30 by Uriel.Doyon Disabled concurrent call to NotifyPrimitiveUpdated while we don't have a safe concurrent update Change 3372979 on 2017/03/30 by Richard.Hinckley #jira UE-43501 The stencil buffer can now use single-channel bitmasks that ignore depth. This makes it possible to detect overlaps between stencil objects. Change 3373053 on 2017/03/30 by Simon.Tourangeau LPV Fade support - mostly integrated from CL 2959511 Change3373272on 2017/03/30 by Uriel.Doyon Added support for the concurrent update of dynamic primitives by the streaming manager. Change 3373450 on 2017/03/30 by Rolando.Caloca DR - FNT - Fix bad data for odd texcoord channels used on skin cache passthrough factory Copy 3373364 #jira UE-43492 Change 3373470 on 2017/03/30 by Marcus.Wassmer Nvidia Aftermath support Change 3374187 on 2017/03/31 by Chris.Bunner Volume texture support for CombineLUTs/Tonemap compute pass. Refactored common param code to shared sub-class in CombineLUTs and Tonemap PS/CS. Skip compute post process out-of-bounds writes. Unsigned type conversion fixes. Trimmed compute post process shader inputs. Change 3374233 on 2017/03/31 by Chris.Bunner Removed several redundant post process compute fences and resource transitions. Added testing CVar to force compute post processes to async (r.PostProcess.ForceAsyncDispatch). Change 3374412 on 2017/03/31 by Rolando.Caloca DR - Fix static analysis Change 3374544 on 2017/03/31 by Richard.Wallis FShaderCache Parallel-Context-Aware Merged with FShaderCache Single Library. Future Work - This was done before Engine PSO were in so this now needs a refector in the recording and playback on pipeline states instead an emulate PSO in OpenGL Driver. - Remove FShaderCacheState and replace the logic with FGraphicsPipelineStateInitializer which should be able to record from the RHI current pipeline state - This would reduce the Locking required as it's naturally per thread/context and only the final record would need a lock Change 3374588 on 2017/03/31 by Richard.Wallis Windows Compile Fixes Change 3374810 on 2017/03/31 by Benjamin.Hyder updating recommended GPU drivers Change 3375207 on 2017/03/31 by Rolando.Caloca DR - vk - Fixed swapchain format selection for some Linux platforms Change 3375248 on 2017/03/31 by Rolando.Caloca DR - vk - Prefer D32S8 Change 3375495 on 2017/03/31 by Rolando.Caloca DR - vk - Update to sdk 1.0.42.2 Change 3375496 on 2017/03/31 by Rolando.Caloca DR - Force compiling with updated Vulkan SDK Change 3375636 on 2017/03/31 by Mark.Satterthwaite Copying Metal improvements from task stream, with some modifications: - Off-by-default implementations for MTLFence & MTLHeap, including some small changes to the RHI interface for parallel contexts. - Support for Apple's Instruments "Points of Interest" tool. - Consolidation of some Mac & iOS compiler, memory and thread handling code. - Fixes for Metal not having implicit buffer SRV typecasting for DistanceField effects. - Improvements to the internal FMetalDebug layer, still off by default. - Limited support for Xcode automatic code-signing for iOS/tvOS. - Minimisation of render-target changes in some rendering code, esp. SceneOcclusion, DBufferDecals. - Added RHISetResourceAliasability_RenderThread to FDynamicRHI for RHIs to implement simple render-target aliasing. - Added FApplePlatformObject, a custom block allocator for Objective-C types (with NSZombie support) which is now used in MetalRHI to decrease allocation costs of Objective-C types. - Smattering of lesser fixes. Change 3375654 on 2017/03/31 by Mark.Satterthwaite Incremental Windows build fix. Change 3375656 on 2017/04/01 by Mark.Satterthwaite Correct extern declaration, including the module export macro which Mac unhelpfully doesn't enforce (for now...). Change 3375797 on 2017/04/01 by Mark.Satterthwaite Nullability qualifiers to fix Mac build-farm compilation: perversely this is not a problem for local builds... Change 3375798 on 2017/04/01 by Mark.Satterthwaite Fix the first mis-merge in ParticleGpuSimulation - these changes clearly weren't properly resolved in the task-stream. Change 3375835 on 2017/04/01 by Mark.Satterthwaite Try again with nullability and fix the occlusion changes as the PSO work wasn't merged correctly. Change 3376143 on 2017/04/02 by Mark.Satterthwaite Switch back to flat dSYMs for Dev-Rendering - they don't work with Instruments etc. but they are required by our build system. Change 3376324 on 2017/04/03 by Chris.Bunner Fixed cvar re-registration log spam and flagged a testing-only cvar as such. Change 3376726 on 2017/04/03 by Benjamin.Hyder Submitting initial HDR test map (WIP) Change 3376756 on 2017/04/03 by Guillaume.Abadie Fixes scene captures ordering's backward compatibility. Before, 2d scene captures were rendered before cube scene captures. The CaptureSortPriority broke backward compatibility by settings this new member to 0 in the USceneCaptureComponent's constructor. Since it is a higher come first policy, this CL set the default of this value to 1 in USceneCaptureComponent2D's constructor. Change 3377378 on 2017/04/03 by Arne.Schober DR - Fix ShaderRecompiling over and over again #RB Chris.Bunner Change 3377512 on 2017/04/03 by Daniel.Wright [Copy] Fixed profilegpu in d3d12 - initialize FLongGPUTaskPS when it is safe to do so, and fixed FSlateRHIRenderer's incorrect usage of draw events Change 3377518 on 2017/04/03 by Daniel.Wright [Copy] Distance field atlas coalesces updates to reduce RHIUpdateTexture3D memory overhead on d3d12 Change 3377526 on 2017/04/03 by Daniel.Wright [Copy] "Ran out of GPU queries!" log only happens once Change 3377535 on 2017/04/03 by Daniel.Wright [Copy] Fixed unreferenced local variable Change 3377539 on 2017/04/03 by Daniel.Wright [Copy] Xbox One RHIGetResourceInfo takes ESRAM into account - fixes render target pool 'VRamInKB request failed' messages Change 3377546 on 2017/04/03 by Daniel.Wright [Copy] Added r.LightMaxDrawDistanceScale for local light scalability Change 3377553 on 2017/04/03 by Daniel.Wright [Copy] Removed NEW_ESRAM_ALLOCATOR define and old unused path Change 3377560 on 2017/04/03 by Daniel.Wright [Copy] Fixed two d3d12 refcounting bugs causing -norhithread crashes Change 3377565 on 2017/04/03 by Daniel.Wright [Copy] Fixed Xbox One deleting GPU resources before the GPU is done reading from them (GRHINeedsExtraDeletionLatency was false) Change 3377572 on 2017/04/03 by Daniel.Wright [Copy] Disabled point / spot lights with MaxDrawDistance on LowPC Change 3377586 on 2017/04/03 by Daniel.Wright Fixed compile error Change 3377699 on 2017/04/03 by David.Hill FFT Code. Moved over from raven and refactored #review-3374589 @guillaume.abadie Change 3377910 on 2017/04/03 by David.Hill GPU FFT: Fix Linux Build adding a missing template<> to an IMPLEMENT_SHADER_TYPE Change 3378751 on 2017/04/04 by Marcus.Wassmer HQ particle lights now spawn attached to the same socket as their parent module. Change 3378819 on 2017/04/04 by Richard.Wallis Should be no need to protect shader cache against RHI thread now. Change 3378823 on 2017/04/04 by Richard.Wallis FRHIShaderLibrary Opaque Type - Base FRHIShaderLibrary has no Create*Shader functions and is passed to Overloaded RHICreate*Shader functions instead of creation directly through the library. - Assumed that only Native libraries will end up in the RHICreate*Shader functions. - ShaderCache and ShaderCode Libraries now inherit from a common factory interface. Change 3378883 on 2017/04/04 by Arne.Schober DR - Fix DCC build Change 3378885 on 2017/04/04 by Richard.Wallis Metal resource cast compile fix post merge. Change 3378946 on 2017/04/04 by Chris.Bunner SM4 assert fix. Change 3378953 on 2017/04/04 by Chris.Bunner Fixed type-correctness on legacy BreakMA material nodes and set more flexible formats to global attributes which should result in much more forgiving graphs for users. Allowed material nodes to opt out of mask-based pin coloration. #tests Compiled most Paragon materials + QAGame test maps. #jira UE-39885 Change 3379189 on 2017/04/04 by Arne.Schober DR - Fix aftermath staging Change 3379229 on 2017/04/04 by Arne.Schober DR - Fix missing include Change 3379374 on 2017/04/04 by Mark.Satterthwaite Revert an accidentally merged change in MacPlatformProcess that relies on further changes from the Metal task stream. Change 3379505 on 2017/04/04 by Rolando.Caloca DR - Fix mismatched interpolators Change 3379539 on 2017/04/04 by Mark.Satterthwaite No FFT for any hlslcc platform - the IR for one or more RWTexture2D isn't quite right... #jira UE-43626 Change 3379561 on 2017/04/04 by Rolando.Caloca DR - Fix root signature issues on D3D12 PC Change 3379590 on 2017/04/04 by Mark.Satterthwaite Back out changelist 3379539 & change the shader slightly instead, the HLSLCC library generates bogus IR when you have an inout RWTexture. #jira UE-43626 Change 3379917 on 2017/04/04 by Uriel.Doyon Fix to input mismatch Change 3380578 on 2017/04/05 by Chris.Bunner Shader type fixes. #jira UE-43652 Change 3380639 on 2017/04/05 by Rolando.Caloca DR - Expose GetOrCreate PSO and document Change 3380821 on 2017/04/05 by Guillaume.Abadie Fixes a crash in USceneCaptureComponent::UpdateDeferredCaptures() #jira UE-43642 Change 3381092 on 2017/04/05 by Guillaume.Abadie Cherry pick 3362517: Implements TAA's scene color unpremultiplication from alpha channel to reduce DOF alpha channel temporal ghosting. This CL take the oportunity to transform AA_ALPHA to an compile time enumeration, and add a basic TAA compile time configuration validation to improve readability of the different TAA passes' configurations. Change 3381300 on 2017/04/05 by Mark.Satterthwaite Quick fix for changes to MetalRHI's render-thread safe texture creation not correctly handling AVFoundation video player handing us an IOSurface. #jira UE-43597 Change3381359on 2017/04/05 by Guillaume.Abadie Back out changelist 3381092 Change 3381421 on 2017/04/05 by Mark.Satterthwaite Amended CL #3380995 from Richard Wallis to address crash in the Material Editor under the validation layer - when there are no textures bound the default pass descriptor assigns store actions, which means we can't override them with our deferred store actions. #jira UE-43689 Change 3381422 on 2017/04/05 by Mark.Satterthwaite Absolute time queries can't be batched in Metal but I also can't rely on them being started with a call to BeginQuery - only EndQuery. #jira UE-43691 Change3381503on 2017/04/05 by Daniel.Wright More intuitive controls for Volumetric Fog * Removed ScatteringScale / AbsorptionScale on Exponential Height Fog and added Albedo / Extinction * InscatteringColorCubemap is now supported by Volumetric Fog * Particle lights have a default VolumetricScatteringIntensity of 0 to avoid trailing * Tweaked GVolumetricFogDepthDistributionScale better for nearby details * Volume Materials have twice the interpolators available Change 3381527 on 2017/04/05 by Mark.Satterthwaite Disable Private GPU storage for PVRTC texture formats on iOS Metal - these require more changes to the blit-encoder usage as PVRTC has strange requirements. Change 3381671 on 2017/04/05 by Mark.Satterthwaite Better error message for failure to compile shaders remotely from PC for Metal. Change 3381769 on 2017/04/05 by Rolando.Caloca DR - Added lock texture array 2d on Vulkan Change 3382003 on 2017/04/05 by Mark.Satterthwaite Remove the automatic Metal aliasing/re-use when releasing some resource types as it doesn't work as intended. Change 3382030 on 2017/04/05 by Zachary.Wilson Fix compiling Metal text shaders from PC broken in merge from task stream. #submitter mark.satterthwaite #jira UE-43652 Change 3382880 on 2017/04/06 by Mark.Satterthwaite Michael Trepka's CL #3379927: VolumetricFogVoxelization implementation for Mac Change 3383315 on 2017/04/06 by Mark.Satterthwaite Partially revert CL #3382003 - the emulated Metal heaps require invoking makeAliasable in order to reclaim memory. #jira UE-43739 Change 3384639 on 2017/04/07 by Marcus.Wassmer Move ShaderResource version bump to RenderingObjectVersion Change 3384704 on 2017/04/07 by Mark.Satterthwaite Compile fix for merge. Change 3384933 on 2017/04/07 by Rolando.Caloca DR - Fix skin cache crash with BP (copy 3384714) Change 3385104 on 2017/04/07 by Mark.Satterthwaite Fix MetalRHI's abs(int2) handling - it can't be translated to fabs(int2) as that won't compile. Also rebuild hlslcc for my sanity. #jira UE-43783 Change 3385105 on 2017/04/07 by Mark.Satterthwaite Force a shader rebuild to ensure that everybody picks up the fix for #jira UE-43783 #jira UE-43783 Change 3385118 on 2017/04/07 by Arne.Schober DR - [OR-37359] - Fix disapearing Decals when StencilLod Fade is enabled #RB none Change 3385149 on 2017/04/07 by Marcus.Wassmer Fix skincache motion blur Change 3385189 on 2017/04/07 by Rolando.Caloca DR - Fix swapchain format for editor on Vulkan Change 3385287 on 2017/04/07 by Mark.Satterthwaite Enable SM5 on Intel as of 10.12.4 and later. Change 3385347 on 2017/04/07 by Rolando.Caloca DR - Temp fix for GL4 corruption on editor #jira UE-43785 Change 3385363 on 2017/04/07 by Rolando.Caloca DR - Actually fix all win platforms for GL bug #jira UE-43785 Change 3385557 on 2017/04/07 by Arne.Schober DR - [UE-43205] - Fix mesh paint #RB none Change3385608on 2017/04/07 by Daniel.Wright Fixed SampleCmp being used on a non-depth texture, causing a d3d error Change 3385980 on 2017/04/10 by Rolando.Caloca DR - Remove transition functions RHIClearColor* RHIClearDepthStencilTexture Change 3386042 on 2017/04/10 by Rolando.Caloca DR - Fix metal merge issue Change 3386157 on 2017/04/10 by Rolando.Caloca DR - Remove VS2013 libs generation off hlslcc & glslang (to match main) Change 3386356 on 2017/04/10 by Chris.Bunner Resolving merge errors. Change 3386414 on 2017/04/10 by Chris.Bunner Resolved merge issue in RendererScene.cpp. Change 3386700 on 2017/04/10 by Mark.Satterthwaite Silence documentation warnings. Change 3387178 on 2017/04/10 by Chris.Bunner Removed invalid mask correction on MakeMA material nodes. Change 3388177 on 2017/04/11 by Marcus.Wassmer Disable ensure that is no longer relevant now that we bind clear colors on texture creation Change 3388261 on 2017/04/11 by Chris.Bunner Static analysis fix. [CL3388266by Chris Bunner in Main branch]
2937 lines
98 KiB
C++
2937 lines
98 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "MetalUtils.h"
|
|
#include "MetalShaderFormat.h"
|
|
#include "MetalBackend.h"
|
|
|
|
#include "hlslcc.h"
|
|
#include "hlslcc_private.h"
|
|
#include "compiler.h"
|
|
#include "MetalUtils.h"
|
|
|
|
PRAGMA_DISABLE_SHADOW_VARIABLE_WARNINGS
|
|
#include "glsl_parser_extras.h"
|
|
PRAGMA_ENABLE_SHADOW_VARIABLE_WARNINGS
|
|
|
|
#include "hash_table.h"
|
|
#include "ir_rvalue_visitor.h"
|
|
#include "ast.h"
|
|
#include "PackUniformBuffers.h"
|
|
#include "IRDump.h"
|
|
#include "OptValueNumbering.h"
|
|
#include "ir_optimization.h"
|
|
|
|
const bool bExpandVSInputsToFloat4 = false;
|
|
const bool bGenerateVSInputDummies = false;
|
|
|
|
static int GetIndexSuffix(const char* Prefix, int PrefixLength, const char* Semantic)
|
|
{
|
|
check(Semantic);
|
|
|
|
if (!strncmp(Semantic, Prefix, PrefixLength))
|
|
{
|
|
Semantic += PrefixLength;
|
|
int Index = 0;
|
|
if (isdigit((unsigned char)*Semantic))
|
|
{
|
|
Index = (*Semantic) - '0';
|
|
|
|
++Semantic;
|
|
if (*Semantic == 0)
|
|
{
|
|
return Index;
|
|
}
|
|
else if (isdigit((unsigned char)*Semantic))
|
|
{
|
|
Index = Index * 10 + (*Semantic) - '0';
|
|
++Semantic;
|
|
if (*Semantic == 0)
|
|
{
|
|
return Index;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
static int GetAttributeIndex(const char* Semantic)
|
|
{
|
|
return GetIndexSuffix("ATTRIBUTE", 9, Semantic);
|
|
}
|
|
|
|
static int GetInAttributeIndex(const char* Semantic)
|
|
{
|
|
return GetIndexSuffix("IN_ATTRIBUTE", 12, Semantic);
|
|
}
|
|
|
|
const glsl_type* PromoteHalfToFloatType(_mesa_glsl_parse_state* state, const glsl_type* type)
|
|
{
|
|
if (type->base_type == GLSL_TYPE_HALF)
|
|
{
|
|
return glsl_type::get_instance(GLSL_TYPE_FLOAT, type->vector_elements, type->matrix_columns);
|
|
}
|
|
else if (type->is_array())
|
|
{
|
|
auto* ElementType = type->element_type();
|
|
auto* NewElementType = PromoteHalfToFloatType(state, ElementType);
|
|
if (NewElementType != ElementType)
|
|
{
|
|
return glsl_type::get_array_instance(NewElementType, type->length);
|
|
}
|
|
}
|
|
else if (type->is_record())
|
|
{
|
|
auto* Fields = ralloc_array(state, glsl_struct_field, type->length);
|
|
bool bNeedNewType = false;
|
|
for (unsigned i = 0; i < type->length; ++i)
|
|
{
|
|
auto* NewMemberType = PromoteHalfToFloatType(state, type->fields.structure[i].type);
|
|
Fields[i] = type->fields.structure[i];
|
|
if (NewMemberType != type->fields.structure[i].type)
|
|
{
|
|
bNeedNewType = true;
|
|
Fields[i].type = NewMemberType;
|
|
}
|
|
}
|
|
|
|
if (bNeedNewType)
|
|
{
|
|
auto* NewType = glsl_type::get_record_instance(Fields, type->length, ralloc_asprintf(state, "%s_F", type->name));
|
|
// Hack: This way we tell this is a uniform buffer and we need to emit 'packed_'
|
|
((glsl_type*)NewType)->HlslName = "__PACKED__";
|
|
state->AddUserStruct(NewType);
|
|
return NewType;
|
|
}
|
|
}
|
|
|
|
return type;
|
|
}
|
|
|
|
void CreateNewAssignmentsFloat2Half(_mesa_glsl_parse_state* State, exec_list& NewAssignments, ir_variable* NewVar, ir_rvalue* RValue)
|
|
{
|
|
if (NewVar->type->is_matrix())
|
|
{
|
|
for (uint32 i = 0; i < NewVar->type->matrix_columns; ++i)
|
|
{
|
|
auto* NewF2H = new(State)ir_expression(ir_unop_f2h, new(State)ir_dereference_array(RValue, new(State)ir_constant(i)));
|
|
auto* NewAssignment = new(State)ir_assignment(new(State)ir_dereference_array(NewVar, new(State)ir_constant(i)), NewF2H);
|
|
NewAssignments.push_tail(NewAssignment);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
auto* NewF2H = new(State)ir_expression(ir_unop_f2h, RValue);
|
|
auto* NewAssignment = new(State)ir_assignment(new(State)ir_dereference_variable(NewVar), NewF2H);
|
|
|
|
NewAssignments.push_tail(NewAssignment);
|
|
}
|
|
}
|
|
|
|
static void CreateNewAssignmentsHalf2Float(_mesa_glsl_parse_state* State, exec_list& NewAssignments, ir_variable* NewVar, ir_rvalue* RValue)
|
|
{
|
|
if (NewVar->type->is_matrix())
|
|
{
|
|
for (uint32 i = 0; i < NewVar->type->matrix_columns; ++i)
|
|
{
|
|
auto* NewF2H = new(State)ir_expression(ir_unop_h2f, new(State)ir_dereference_array(RValue, new(State)ir_constant(i)));
|
|
auto* NewAssignment = new(State)ir_assignment(new(State)ir_dereference_array(NewVar, new(State)ir_constant(i)), NewF2H);
|
|
NewAssignments.push_tail(NewAssignment);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
auto* NewF2H = new(State)ir_expression(ir_unop_h2f, RValue);
|
|
auto* NewAssignment = new(State)ir_assignment(new(State)ir_dereference_variable(NewVar), NewF2H);
|
|
|
|
NewAssignments.push_tail(NewAssignment);
|
|
}
|
|
}
|
|
|
|
const glsl_type* GetFragColorTypeFromMetalOutputStruct(const glsl_type* OutputType)
|
|
{
|
|
const glsl_type* FragColorType = glsl_type::error_type;
|
|
if (OutputType && OutputType->base_type == GLSL_TYPE_STRUCT)
|
|
{
|
|
for (unsigned j = 0; j < OutputType->length; j++)
|
|
{
|
|
if (OutputType->fields.structure[j].semantic)
|
|
{
|
|
//@todo-rco: MRTs?
|
|
if (!strncmp(OutputType->fields.structure[j].semantic, "[[ color(", 9))
|
|
{
|
|
FragColorType = OutputType->fields.structure[j].type;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return FragColorType;
|
|
}
|
|
|
|
namespace MetalUtils
|
|
{
|
|
/** Information on system values. */
|
|
struct FSystemValue
|
|
{
|
|
const char* HlslSemantic;
|
|
const glsl_type* Type;
|
|
const char* MetalName;
|
|
ir_variable_mode Mode;
|
|
const char* MetalSemantic;
|
|
};
|
|
|
|
/** Vertex shader system values. */
|
|
static FSystemValue VertexSystemValueTable[] =
|
|
{
|
|
{"SV_VertexID", glsl_type::uint_type, "IN_VertexID", ir_var_in, "[[ vertex_id ]]"},
|
|
{"SV_InstanceID", glsl_type::uint_type, "IN_InstanceID", ir_var_in, "[[ instance_id ]]"},
|
|
{"SV_Position", glsl_type::vec4_type, "Position", ir_var_out, "[[ position ]]"},
|
|
{"SV_RenderTargetArrayIndex", glsl_type::uint_type, "OUT_Layer", ir_var_out, "[[ render_target_array_index ]]"},
|
|
{"SV_ClipDistance", glsl_type::float_type, "ClipDistance0", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance0", glsl_type::float_type, "ClipDistance0", ir_var_out, "[[ clip_distance ]]"},
|
|
//#todo-rco: Values 1..7 are not really defined well in the Metal Language Doc...
|
|
//#todo-marksatt: Perhaps not, but this is a semantic marker not a 'slot' so I think we can just use 0-8.
|
|
{"SV_ClipDistance1", glsl_type::float_type, "ClipDistance1", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance2", glsl_type::float_type, "ClipDistance2", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance3", glsl_type::float_type, "ClipDistance3", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance4", glsl_type::float_type, "ClipDistance4", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance5", glsl_type::float_type, "ClipDistance5", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance6", glsl_type::float_type, "ClipDistance6", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance7", glsl_type::float_type, "ClipDistance7", ir_var_out, "[[ clip_distance ]]"},
|
|
{NULL, NULL, NULL, ir_var_auto, nullptr}
|
|
};
|
|
|
|
/** Pixel shader system values. */
|
|
static FSystemValue MobilePixelSystemValueTable[] =
|
|
{
|
|
{"SV_Depth", glsl_type::float_type, "FragDepth", ir_var_out, "[[ depth(any) ]]"},
|
|
{"SV_Position", glsl_type::vec4_type, "IN_FragCoord", ir_var_in, "[[ position ]]"},
|
|
{"SV_IsFrontFace", glsl_type::bool_type, "IN_FrontFacing", ir_var_in, "[[ front_facing ]]"},
|
|
//{"SV_PrimitiveID", glsl_type::int_type, "IN_PrimitiveID", ir_var_in, "[[ ]]"},
|
|
//{"SV_RenderTargetArrayIndex", glsl_type::uint_type, "IN_Layer", ir_var_in, "[[ render_target_array_index ]]"},
|
|
{"SV_Target0", glsl_type::half4_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::half4_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::half4_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::half4_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::half4_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::half4_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::half4_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::half4_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::half3_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::half3_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::half3_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::half3_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::half3_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::half3_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::half3_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::half3_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::half2_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::half2_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::half2_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::half2_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::half2_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::half2_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::half2_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::half2_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::float_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::float_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::float_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::float_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::float_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::float_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::float_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::float_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{NULL, NULL, NULL, ir_var_auto, nullptr}
|
|
};
|
|
|
|
/** Pixel shader system values. */
|
|
static FSystemValue DesktopPixelSystemValueTable[] =
|
|
{
|
|
{"SV_Depth", glsl_type::float_type, "FragDepth", ir_var_out, "[[ depth(any) ]]"},
|
|
{"SV_Position", glsl_type::vec4_type, "IN_FragCoord", ir_var_in, "[[ position ]]"},
|
|
{"SV_IsFrontFace", glsl_type::bool_type, "IN_FrontFacing", ir_var_in, "[[ front_facing ]]"},
|
|
{"SV_Coverage", glsl_type::uint_type, "IN_Coverage", ir_var_in, "[[ sample_mask ]]"},
|
|
{"SV_Coverage", glsl_type::uint_type, "OUT_Coverage", ir_var_out, "[[ sample_mask ]]"},
|
|
//{"SV_PrimitiveID", glsl_type::int_type, "IN_PrimitiveID", ir_var_in, "[[ ]]"},
|
|
//{"SV_RenderTargetArrayIndex", glsl_type::uint_type, "IN_Layer", ir_var_in, "[[ render_target_array_index ]]"},
|
|
{"SV_Target0", glsl_type::vec4_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::vec4_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::vec4_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::vec4_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::vec4_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::vec4_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::vec4_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::vec4_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::vec3_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::vec3_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::vec3_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::vec3_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::vec3_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::vec3_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::vec3_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::vec3_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::vec2_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::vec2_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::vec2_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::vec2_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::vec2_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::vec2_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::vec2_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::vec2_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::float_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::float_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::float_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::float_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::float_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::float_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::float_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::float_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::uvec4_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::uvec4_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::uvec4_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::uvec4_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::uvec4_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::uvec4_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::uvec4_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::uvec4_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::uvec3_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::uvec3_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::uvec3_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::uvec3_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::uvec3_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::uvec3_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::uvec3_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::uvec3_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::uvec2_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::uvec2_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::uvec2_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::uvec2_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::uvec2_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::uvec2_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::uvec2_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::uvec2_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{"SV_Target0", glsl_type::uint_type, "FragColor0", ir_var_out, "[[ color(0) ]]"},
|
|
{"SV_Target1", glsl_type::uint_type, "FragColor1", ir_var_out, "[[ color(1) ]]"},
|
|
{"SV_Target2", glsl_type::uint_type, "FragColor2", ir_var_out, "[[ color(2) ]]"},
|
|
{"SV_Target3", glsl_type::uint_type, "FragColor3", ir_var_out, "[[ color(3) ]]"},
|
|
{"SV_Target4", glsl_type::uint_type, "FragColor4", ir_var_out, "[[ color(4) ]]"},
|
|
{"SV_Target5", glsl_type::uint_type, "FragColor5", ir_var_out, "[[ color(5) ]]"},
|
|
{"SV_Target6", glsl_type::uint_type, "FragColor6", ir_var_out, "[[ color(6) ]]"},
|
|
{"SV_Target7", glsl_type::uint_type, "FragColor7", ir_var_out, "[[ color(7) ]]"},
|
|
{NULL, NULL, NULL, ir_var_auto, nullptr}
|
|
};
|
|
|
|
/** Geometry shader system values. */
|
|
static FSystemValue GeometrySystemValueTable[] =
|
|
{
|
|
/*
|
|
{"SV_VertexID", glsl_type::int_type, "IN_VertexID", ir_var_in, false, false, false, false},
|
|
{"SV_InstanceID", glsl_type::int_type, "IN_InstanceID", ir_var_in, false, false, false, false},
|
|
{"SV_Position", glsl_type::vec4_type, "IN_Position", ir_var_in, false, true, true, false},
|
|
{"SV_Position", glsl_type::vec4_type, "OUT_Position", ir_var_out, false, false, true, false},
|
|
{"SV_RenderTargetArrayIndex", glsl_type::uint_type, "OUT_Layer", ir_var_out, false, false, false, false},
|
|
{"SV_PrimitiveID", glsl_type::int_type, "OUT_PrimitiveID", ir_var_out, false, false, false, false},
|
|
{"SV_PrimitiveID", glsl_type::int_type, "IN_PrimitiveIDIn", ir_var_in, false, false, false, false},
|
|
*/
|
|
{NULL, NULL, NULL, ir_var_auto, nullptr}
|
|
};
|
|
|
|
|
|
/** Hull shader system values. */
|
|
static FSystemValue HullSystemValueTable[] =
|
|
{
|
|
{"SV_VertexID", glsl_type::uint_type, "IN_VertexID", ir_var_in, "[[ vertex_id ]]"},
|
|
{"SV_InstanceID", glsl_type::uint_type, "IN_InstanceID", ir_var_in, "[[ instance_id ]]"},
|
|
/*
|
|
{"SV_OutputControlPointID", glsl_type::int_type, "gl_InvocationID", ir_var_in, false, false, false, false},
|
|
*/
|
|
// {"SV_OutputControlPointID", glsl_type::uint_type, "LocalInvocationID", ir_var_in, "[[ thread_position_in_threadgroup ]]"},
|
|
{NULL, NULL, NULL, ir_var_auto, nullptr}
|
|
};
|
|
|
|
/** Domain shader system values. */
|
|
static FSystemValue DomainSystemValueTable[] =
|
|
{
|
|
{"SV_Position", glsl_type::vec4_type, "IN_Position", ir_var_in, "[[ TODO ]]"},
|
|
{"SV_Position", glsl_type::vec4_type, "Position", ir_var_out, "[[ position ]]"},
|
|
{"SV_DomainLocation", glsl_type::vec2_type, "PositionInPatch", ir_var_in, "[[ position_in_patch ]]"}, // @todo maybe add a NULL/void_type/error_type and set it using the passed in type for GenerateInputFromSemantic -- use it to simplify SV_Target as well
|
|
{"SV_DomainLocation", glsl_type::vec3_type, "PositionInPatch", ir_var_in, "[[ position_in_patch ]]"},
|
|
{"SV_RenderTargetArrayIndex", glsl_type::uint_type, "OUT_Layer", ir_var_out, "[[ render_target_array_index ]]"},
|
|
{"SV_ClipDistance", glsl_type::float_type, "ClipDistance0", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance0", glsl_type::float_type, "ClipDistance0", ir_var_out, "[[ clip_distance ]]"},
|
|
//#todo-rco: Values 1..7 are not really defined well in the Metal Language Doc...
|
|
//#todo-marksatt: Perhaps not, but this is a semantic marker not a 'slot' so I think we can just use 0-8.
|
|
{"SV_ClipDistance1", glsl_type::float_type, "ClipDistance1", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance2", glsl_type::float_type, "ClipDistance2", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance3", glsl_type::float_type, "ClipDistance3", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance4", glsl_type::float_type, "ClipDistance4", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance5", glsl_type::float_type, "ClipDistance5", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance6", glsl_type::float_type, "ClipDistance6", ir_var_out, "[[ clip_distance ]]"},
|
|
{"SV_ClipDistance7", glsl_type::float_type, "ClipDistance7", ir_var_out, "[[ clip_distance ]]"},
|
|
{NULL, NULL, NULL, ir_var_auto, nullptr}
|
|
};
|
|
|
|
/** Compute shader system values. */
|
|
static FSystemValue ComputeSystemValueTable[] =
|
|
{
|
|
// D3D, type, GL, param, Metal
|
|
{"SV_DispatchThreadID", glsl_type::uvec3_type, "thread_position_in_grid", ir_var_in, "[[ thread_position_in_grid ]]"},
|
|
{"SV_GroupID", glsl_type::uvec3_type, "threadgroup_position_in_grid", ir_var_in, "[[ threadgroup_position_in_grid ]]"},
|
|
{"SV_GroupIndex", glsl_type::uint_type, "thread_index_in_threadgroup", ir_var_in, "[[ thread_index_in_threadgroup ]]"},
|
|
{"SV_GroupThreadID", glsl_type::uvec3_type, "thread_position_in_threadgroup", ir_var_in, "[[ thread_position_in_threadgroup ]]"},
|
|
{NULL, NULL, NULL, ir_var_auto, nullptr}
|
|
};
|
|
|
|
FSystemValue* MobileSystemValueTable[HSF_FrequencyCount] =
|
|
{
|
|
VertexSystemValueTable,
|
|
MobilePixelSystemValueTable,
|
|
GeometrySystemValueTable,
|
|
HullSystemValueTable,
|
|
DomainSystemValueTable,
|
|
ComputeSystemValueTable
|
|
};
|
|
|
|
FSystemValue* DesktopSystemValueTable[HSF_FrequencyCount] =
|
|
{
|
|
VertexSystemValueTable,
|
|
DesktopPixelSystemValueTable,
|
|
GeometrySystemValueTable,
|
|
HullSystemValueTable,
|
|
DomainSystemValueTable,
|
|
ComputeSystemValueTable
|
|
};
|
|
|
|
static ir_rvalue* GenerateInputFromSemantic(EHlslShaderFrequency Frequency, EMetalGPUSemantics bIsDesktop, _mesa_glsl_parse_state* ParseState,
|
|
const char* Semantic, const glsl_type* Type, exec_list* DeclInstructions, exec_list* PreCallInstructions)
|
|
{
|
|
if (!Semantic)
|
|
{
|
|
//todo-rco: More info!
|
|
_mesa_glsl_error(ParseState, "Missing input semantic!", Semantic);
|
|
return nullptr;
|
|
}
|
|
|
|
if (!FCStringAnsi::Stricmp(Semantic, "SV_OutputControlPointID"))
|
|
{
|
|
//check(bIsTessellationVSHS);
|
|
auto Variable = ParseState->symbols->get_variable("SV_OutputControlPointID");
|
|
check(Variable);
|
|
return new (ParseState)ir_dereference_variable(Variable);
|
|
}
|
|
else
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_", 3) == 0)
|
|
{
|
|
FSystemValue* SystemValues = (bIsDesktop == EMetalGPUSemanticsMobile) ? MobileSystemValueTable[Frequency] : DesktopSystemValueTable[Frequency];
|
|
for (int i = 0; SystemValues[i].HlslSemantic != NULL; ++i)
|
|
{
|
|
if (SystemValues[i].Mode == ir_var_in && FCStringAnsi::Stricmp(SystemValues[i].HlslSemantic, Semantic) == 0)
|
|
{
|
|
if (!FCStringAnsi::Stricmp(Semantic, "SV_DomainLocation") && Frequency == HSF_DomainShader)
|
|
{
|
|
// SV_DomainLocation is either float2 or float3 -- find the proper type
|
|
if (SystemValues[i].Type != Type)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
ir_variable* Variable = new(ParseState) ir_variable(SystemValues[i].Type, SystemValues[i].MetalName, ir_var_in);
|
|
Variable->semantic = SystemValues[i].MetalSemantic;
|
|
Variable->read_only = true;
|
|
Variable->origin_upper_left = false;
|
|
DeclInstructions->push_tail(Variable);
|
|
ParseState->symbols->add_variable(Variable);
|
|
ir_dereference_variable* VariableDeref = new(ParseState) ir_dereference_variable(Variable);
|
|
if (!FCStringAnsi::Stricmp(Semantic, "SV_Position") && Frequency == HSF_PixelShader)
|
|
{
|
|
// UE4 requires w instead of 1/w in SVPosition
|
|
auto* TempVariable = new(ParseState) ir_variable(Variable->type, nullptr, ir_var_temporary);
|
|
DeclInstructions->push_tail(TempVariable);
|
|
|
|
// Assign input to this variable
|
|
auto* 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, nullptr), 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, nullptr), 3, 0, 0, 0, 1)
|
|
)
|
|
)
|
|
);
|
|
|
|
VariableDeref = TempVariableDeref->clone(ParseState, nullptr);
|
|
}
|
|
return VariableDeref;
|
|
}
|
|
}
|
|
}
|
|
|
|
// If we're here, no built-in variables matched.
|
|
bool bUseSlice = false;
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_", 3) == 0)
|
|
{
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_RenderTargetArrayIndex", 25) == 0)
|
|
{
|
|
bUseSlice = true;
|
|
}
|
|
else
|
|
{
|
|
_mesa_glsl_warning(ParseState, "unrecognized system value input '%s'", Semantic);
|
|
}
|
|
}
|
|
|
|
ir_variable* Variable = new(ParseState)ir_variable(
|
|
Type,
|
|
ralloc_asprintf(ParseState, "IN_%s", Semantic),
|
|
ir_var_in);
|
|
if (Frequency == HSF_VertexShader)
|
|
{
|
|
if (!FCStringAnsi::Strnicmp(Semantic, "ATTRIBUTE", 9))
|
|
{
|
|
Variable->semantic = ralloc_asprintf(ParseState, "[[ attribute(%s) ]]", Semantic);
|
|
}
|
|
else if (FCStringAnsi::Strnicmp(Semantic, "[[", 2))
|
|
{
|
|
_mesa_glsl_warning(ParseState, "Unrecognized input attribute '%s'", Semantic);
|
|
}
|
|
}
|
|
else if (bUseSlice)
|
|
{
|
|
check(Frequency == HSF_PixelShader);
|
|
Variable->semantic = ralloc_asprintf(ParseState, "[[ render_target_array_index ]]");
|
|
}
|
|
|
|
if (Variable->type->is_patch())
|
|
{
|
|
// do not add any semantics for patch-types
|
|
}
|
|
else
|
|
if (!Variable->semantic)
|
|
{
|
|
Variable->semantic = ralloc_asprintf(ParseState, "[[ user(%s) ]]", Semantic);
|
|
}
|
|
Variable->read_only = true;
|
|
DeclInstructions->push_tail(Variable);
|
|
ParseState->symbols->add_variable(Variable);
|
|
ir_dereference_variable* VariableDeref = new(ParseState)ir_dereference_variable(Variable);
|
|
return VariableDeref;
|
|
}
|
|
|
|
static void GenerateInputForVariable(EHlslShaderFrequency Frequency, EMetalGPUSemantics bIsDesktop, _mesa_glsl_parse_state* ParseState,
|
|
const char* InputSemantic, ir_dereference* InputVariableDeref, exec_list* DeclInstructions, exec_list* PreCallInstructions)
|
|
{
|
|
const glsl_type* InputType = InputVariableDeref->type;
|
|
if (InputType->is_record())
|
|
{
|
|
for (uint32 i = 0; i < InputType->length; ++i)
|
|
{
|
|
const char* Semantic = nullptr;
|
|
const char* FieldSemantic = InputType->fields.structure[i].semantic;
|
|
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 = nullptr;
|
|
}
|
|
else if (InputSemantic && !FieldSemantic)
|
|
{
|
|
Semantic = ralloc_asprintf(ParseState, "%s%d", InputSemantic, i);
|
|
_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 = nullptr;
|
|
}
|
|
|
|
if (InputType->fields.structure[i].type->is_record() || Semantic)
|
|
{
|
|
ir_dereference_record* FieldDeref = new(ParseState)ir_dereference_record(
|
|
InputVariableDeref->clone(ParseState, NULL),
|
|
InputType->fields.structure[i].name);
|
|
GenerateInputForVariable(Frequency, bIsDesktop, ParseState, Semantic, FieldDeref, DeclInstructions, PreCallInstructions);
|
|
}
|
|
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())
|
|
{
|
|
int BaseIndex = 0;
|
|
const char* Semantic = 0;
|
|
check(InputSemantic);
|
|
ParseSemanticAndIndex(ParseState, InputSemantic, &Semantic, &BaseIndex);
|
|
check(BaseIndex >= 0);
|
|
for (unsigned i = 0; i < InputType->length; ++i)
|
|
{
|
|
ir_dereference_array* ArrayDeref = new(ParseState)ir_dereference_array(
|
|
InputVariableDeref->clone(ParseState, NULL),
|
|
new(ParseState)ir_constant((unsigned)i)
|
|
);
|
|
GenerateInputForVariable(
|
|
Frequency,
|
|
bIsDesktop,
|
|
ParseState,
|
|
ralloc_asprintf(ParseState, "%s%d", Semantic, BaseIndex + i),
|
|
ArrayDeref,
|
|
DeclInstructions,
|
|
PreCallInstructions);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ir_rvalue* SrcValue = GenerateInputFromSemantic(Frequency, bIsDesktop, ParseState, InputSemantic, InputType, DeclInstructions, PreCallInstructions);
|
|
if (SrcValue)
|
|
{
|
|
YYLTYPE loc;
|
|
apply_type_conversion(InputType, SrcValue, PreCallInstructions, ParseState, true, &loc);
|
|
PreCallInstructions->push_tail(
|
|
new(ParseState) ir_assignment(InputVariableDeref->clone(ParseState, NULL),SrcValue));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
ir_dereference_variable* GenerateInput(EHlslShaderFrequency Frequency, uint32 bIsDesktop, _mesa_glsl_parse_state* ParseState, const char* InputSemantic, const glsl_type* InputType, exec_list* DeclInstructions, exec_list* PreCallInstructions)
|
|
{
|
|
if((InputType->is_inputpatch()))
|
|
{
|
|
return GenerateInputFromSemantic(Frequency, (EMetalGPUSemantics)bIsDesktop, ParseState, InputSemantic, InputType, DeclInstructions, PreCallInstructions)->as_dereference_variable();
|
|
}
|
|
ir_variable* TempVariable = new(ParseState)ir_variable(InputType, nullptr, ir_var_temporary);
|
|
ir_dereference_variable* TempVariableDeref = new(ParseState)ir_dereference_variable(TempVariable);
|
|
PreCallInstructions->push_tail(TempVariable);
|
|
GenerateInputForVariable(Frequency, (EMetalGPUSemantics)bIsDesktop, ParseState, InputSemantic, TempVariableDeref, DeclInstructions, PreCallInstructions);
|
|
return TempVariableDeref;
|
|
}
|
|
|
|
static ir_rvalue* GenerateOutputFromSemantic(EHlslShaderFrequency Frequency, uint32 bIsDesktop, _mesa_glsl_parse_state* ParseState,
|
|
const char* Semantic, FSemanticQualifier Qualifier, const glsl_type* Type, exec_list* DeclInstructions, const glsl_type** DestVariableType)
|
|
{
|
|
ir_variable* Variable = NULL;
|
|
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_", 3) == 0)
|
|
{
|
|
FSystemValue* SystemValues = (bIsDesktop == EMetalGPUSemanticsMobile) ? MobileSystemValueTable[Frequency] : DesktopSystemValueTable[Frequency];
|
|
|
|
for (int i = 0; SystemValues[i].HlslSemantic != nullptr; ++i)
|
|
{
|
|
if (SystemValues[i].Mode == ir_var_out && FCStringAnsi::Stricmp(SystemValues[i].HlslSemantic, Semantic) == 0 && SystemValues[i].Type == Type)
|
|
{
|
|
Variable = new(ParseState) ir_variable(SystemValues[i].Type, SystemValues[i].MetalName, ir_var_out);
|
|
Variable->semantic = SystemValues[i].MetalSemantic;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!Variable)
|
|
{
|
|
for (int i = 0; SystemValues[i].HlslSemantic != nullptr; ++i)
|
|
{
|
|
if (SystemValues[i].Mode == ir_var_out && FCStringAnsi::Stricmp(SystemValues[i].HlslSemantic, Semantic) == 0 && SystemValues[i].Type->vector_elements == Type->vector_elements)
|
|
{
|
|
Variable = new(ParseState) ir_variable(SystemValues[i].Type, SystemValues[i].MetalName, ir_var_out);
|
|
Variable->semantic = SystemValues[i].MetalSemantic;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Semantic && FCStringAnsi::Strnicmp(Semantic, "SV_", 3) == 0 && !Variable)
|
|
{
|
|
_mesa_glsl_warning(ParseState, "unrecognized system value output '%s'", Semantic);
|
|
}
|
|
|
|
if (!Variable)
|
|
{
|
|
Variable = new(ParseState)ir_variable(Type, ralloc_asprintf(ParseState, "OUT_%s", Semantic), ir_var_out);
|
|
Variable->semantic = ralloc_asprintf(ParseState, "[[ user(%s) ]]", Semantic);
|
|
if (Qualifier.Fields.bIsPatchConstant)
|
|
{
|
|
// Propagate the semantic straight through for things like SV_TessFactor and SV_InsideTessFactor as they aren't treated as
|
|
// system variables yet.
|
|
Variable->semantic = Semantic;
|
|
}
|
|
}
|
|
|
|
*DestVariableType = Variable->type;
|
|
DeclInstructions->push_tail(Variable);
|
|
ParseState->symbols->add_variable(Variable);
|
|
ir_rvalue* VariableDeref = new(ParseState)ir_dereference_variable(Variable);
|
|
return VariableDeref;
|
|
}
|
|
|
|
static void GenerateOutputForVariable(EHlslShaderFrequency Frequency, EMetalGPUSemantics bIsDesktop, _mesa_glsl_parse_state* ParseState,
|
|
const char* OutputSemantic, FSemanticQualifier Qualifier, 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 = nullptr;
|
|
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 = nullptr;
|
|
}
|
|
else if (OutputSemantic && !FieldSemantic)
|
|
{
|
|
Semantic = ralloc_asprintf(ParseState, "%s%d", OutputSemantic, i);
|
|
_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 = nullptr;
|
|
}
|
|
|
|
if (OutputType->fields.structure[i].type->is_record() || Semantic)
|
|
{
|
|
// 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);
|
|
GenerateOutputForVariable(Frequency, bIsDesktop, ParseState, Semantic, Qualifier, FieldDeref, DeclInstructions, PostCallInstructions);
|
|
}
|
|
else
|
|
{
|
|
_mesa_glsl_error(
|
|
ParseState,
|
|
"field '%s' in output structure '%s' does not specify a semantic",
|
|
OutputType->fields.structure[i].name,
|
|
OutputType->name
|
|
);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!OutputSemantic)
|
|
{
|
|
_mesa_glsl_error(ParseState, "Entry point does not specify a semantic for its return value");
|
|
}
|
|
else
|
|
{
|
|
if (OutputType->is_array())
|
|
{
|
|
int BaseIndex = 0;
|
|
const char* Semantic = 0;
|
|
|
|
ParseSemanticAndIndex(ParseState, OutputSemantic, &Semantic, &BaseIndex);
|
|
|
|
for (unsigned i = 0; i < OutputType->length; ++i)
|
|
{
|
|
ir_dereference_array* ArrayDeref = new(ParseState)ir_dereference_array(
|
|
OutputVariableDeref->clone(ParseState, NULL),
|
|
new(ParseState) ir_constant((unsigned)i)
|
|
);
|
|
GenerateOutputForVariable(Frequency, bIsDesktop, ParseState,
|
|
ralloc_asprintf(ParseState, "%s%d", Semantic, BaseIndex + i),
|
|
Qualifier,
|
|
ArrayDeref, DeclInstructions, PostCallInstructions);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
YYLTYPE loc;
|
|
ir_rvalue* Src = OutputVariableDeref->clone(ParseState, NULL);
|
|
const glsl_type* DestVariableType = NULL;
|
|
ir_rvalue* DestVariableDeref = GenerateOutputFromSemantic(Frequency, bIsDesktop, ParseState, OutputSemantic,
|
|
Qualifier,
|
|
OutputType, DeclInstructions, &DestVariableType);
|
|
|
|
apply_type_conversion(DestVariableType, Src, PostCallInstructions, ParseState, true, &loc);
|
|
PostCallInstructions->push_tail(new(ParseState)ir_assignment(DestVariableDeref, Src));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
ir_dereference_variable* GenerateOutput(EHlslShaderFrequency Frequency, uint32 bIsDesktop, _mesa_glsl_parse_state* ParseState,
|
|
const char* OutputSemantic, FSemanticQualifier Qualifier, 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, nullptr, ir_var_temporary);
|
|
ir_dereference_variable* TempVariableDeref = new(ParseState) ir_dereference_variable(TempVariable);
|
|
PreCallInstructions->push_tail(TempVariable);
|
|
|
|
GenerateOutputForVariable(Frequency, (EMetalGPUSemantics)bIsDesktop, ParseState, OutputSemantic, Qualifier, TempVariableDeref, DeclInstructions, PostCallInstructions);
|
|
|
|
return TempVariableDeref;
|
|
}
|
|
}
|
|
|
|
struct FFixIntrinsicsVisitor : public ir_rvalue_visitor
|
|
{
|
|
_mesa_glsl_parse_state* State;
|
|
bool bUsesFramebufferFetchES2;
|
|
int MRTFetchMask;
|
|
ir_variable* DestColorVar;
|
|
const glsl_type* DestColorType;
|
|
ir_variable* DestMRTColorVar[MAX_SIMULTANEOUS_RENDER_TARGETS];
|
|
|
|
FFixIntrinsicsVisitor(_mesa_glsl_parse_state* InState, ir_function_signature* InMainSig) :
|
|
State(InState),
|
|
bUsesFramebufferFetchES2(false),
|
|
MRTFetchMask(0),
|
|
DestColorVar(nullptr),
|
|
DestColorType(glsl_type::error_type)
|
|
{
|
|
DestColorType = GetFragColorTypeFromMetalOutputStruct(InMainSig->return_type);
|
|
memset(DestMRTColorVar, 0, sizeof(DestMRTColorVar));
|
|
}
|
|
|
|
//ir_visitor_status visit_leave(ir_expression* expr) override
|
|
virtual void handle_rvalue(ir_rvalue** RValue)
|
|
{
|
|
if (!RValue || !*RValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
// Fix .x swizzle of scalars...
|
|
auto* Swizzle = (*RValue)->as_swizzle();
|
|
if (Swizzle)
|
|
{
|
|
auto* Texture = Swizzle->val->as_texture();
|
|
if (Texture && Texture->op == ir_txf &&
|
|
Texture->sampler && Texture->sampler->type->sampler_buffer &&
|
|
Texture->sampler->type->inner_type && Texture->sampler->type->inner_type->is_scalar() &&
|
|
Swizzle->mask.x == 0 &&
|
|
Swizzle->mask.y == 0 &&
|
|
Swizzle->mask.z == 0 &&
|
|
Swizzle->mask.w == 0 &&
|
|
Swizzle->mask.num_components == 1 &&
|
|
Swizzle->mask.has_duplicates == 0)
|
|
{
|
|
*RValue = Texture;
|
|
}
|
|
}
|
|
|
|
auto* expr = (*RValue)->as_expression();
|
|
if (!expr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ir_expression_operation op = expr->operation;
|
|
|
|
if (op == ir_binop_mul && expr->type->is_matrix()
|
|
&& expr->operands[0]->type->is_matrix()
|
|
&& expr->operands[1]->type->is_matrix())
|
|
{
|
|
// Convert matrixCompMult to memberwise multiply
|
|
check(expr->operands[0]->type == expr->operands[1]->type);
|
|
auto* NewTemp = new(State)ir_variable(expr->operands[0]->type, nullptr, ir_var_temporary);
|
|
base_ir->insert_before(NewTemp);
|
|
for (uint32 Index = 0; Index < expr->operands[0]->type->matrix_columns; ++Index)
|
|
{
|
|
auto* NewMul = new(State)ir_expression(ir_binop_mul,
|
|
new(State)ir_dereference_array(expr->operands[0], new(State)ir_constant(Index)),
|
|
new(State)ir_dereference_array(expr->operands[1], new(State)ir_constant(Index)));
|
|
auto* NewAssign = new(State)ir_assignment(
|
|
new(State)ir_dereference_array(NewTemp, new(State)ir_constant(Index)),
|
|
NewMul);
|
|
base_ir->insert_before(NewAssign);
|
|
}
|
|
|
|
*RValue = new(State)ir_dereference_variable(NewTemp);
|
|
}
|
|
}
|
|
|
|
virtual ir_visitor_status visit_leave(ir_call* IR) override
|
|
{
|
|
if (IR->use_builtin)
|
|
{
|
|
const char* CalleeName = IR->callee_name();
|
|
static auto ES2Len = strlen(FRAMEBUFFER_FETCH_ES2);
|
|
static auto MRTLen = strlen(FRAMEBUFFER_FETCH_MRT);
|
|
if (!strncmp(CalleeName, FRAMEBUFFER_FETCH_ES2, ES2Len))
|
|
{
|
|
// 'Upgrade' framebuffer fetch
|
|
check(IR->actual_parameters.is_empty());
|
|
bUsesFramebufferFetchES2 = true;
|
|
if (!DestColorVar)
|
|
{
|
|
// Generate new input variable for Metal semantics
|
|
DestColorVar = new(State)ir_variable(glsl_type::get_instance(DestColorType->base_type, 4, 1), "gl_LastFragData", ir_var_in);
|
|
DestColorVar->semantic = "[[ color(0) ]]";
|
|
}
|
|
|
|
ir_rvalue* DestColor = new(State)ir_dereference_variable(DestColorVar);
|
|
if (IR->return_deref->type->base_type != DestColor->type->base_type)
|
|
{
|
|
DestColor = convert_component(DestColor, IR->return_deref->type);
|
|
}
|
|
auto* Assignment = new (State)ir_assignment(IR->return_deref, DestColor);
|
|
IR->insert_before(Assignment);
|
|
IR->remove();
|
|
}
|
|
else if (!strncmp(CalleeName, FRAMEBUFFER_FETCH_MRT, MRTLen))
|
|
{
|
|
int Index = atoi(CalleeName + MRTLen);
|
|
if (!DestMRTColorVar[Index])
|
|
{
|
|
DestMRTColorVar[Index] = new(State)ir_variable(glsl_type::get_instance(DestColorType->base_type, 4, 1), CalleeName, ir_var_in);
|
|
DestMRTColorVar[Index]->semantic = ralloc_asprintf(State, "[[ color(%d) ]]", Index);
|
|
}
|
|
|
|
ir_rvalue* DestColor = new(State) ir_dereference_variable(DestMRTColorVar[Index]);
|
|
if (IR->return_deref->type->base_type != DestColor->type->base_type)
|
|
{
|
|
DestColor = convert_component(DestColor, IR->return_deref->type);
|
|
}
|
|
auto* Assignment = new (State) ir_assignment(IR->return_deref, DestColor);
|
|
IR->insert_before(Assignment);
|
|
IR->remove();
|
|
}
|
|
}
|
|
|
|
return visit_continue;
|
|
}
|
|
};
|
|
|
|
void FMetalCodeBackend::FixIntrinsics(exec_list* ir, _mesa_glsl_parse_state* state)
|
|
{
|
|
ir_function_signature* MainSig = GetMainFunction(ir);
|
|
check(MainSig);
|
|
|
|
FFixIntrinsicsVisitor Visitor(state,MainSig);
|
|
Visitor.run(&MainSig->body);
|
|
|
|
if (Visitor.bUsesFramebufferFetchES2)
|
|
{
|
|
check(Visitor.DestColorVar);
|
|
MainSig->parameters.push_tail(Visitor.DestColorVar);
|
|
}
|
|
|
|
for (int i = 0; i < MAX_SIMULTANEOUS_RENDER_TARGETS; ++i)
|
|
{
|
|
if (Visitor.DestMRTColorVar[i])
|
|
{
|
|
MainSig->parameters.push_tail(Visitor.DestMRTColorVar[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
struct FConvertUBVisitor : public ir_rvalue_visitor
|
|
{
|
|
_mesa_glsl_parse_state* State;
|
|
TStringIRVarMap& Map;
|
|
FConvertUBVisitor(_mesa_glsl_parse_state* InState, TStringIRVarMap& InMap) :
|
|
State(InState),
|
|
Map(InMap)
|
|
{
|
|
}
|
|
|
|
virtual void handle_rvalue(ir_rvalue** RValuePtr) override
|
|
{
|
|
if (!RValuePtr || !*RValuePtr)
|
|
{
|
|
return;
|
|
}
|
|
auto* ReferencedVar = (*RValuePtr)->variable_referenced();
|
|
if (ReferencedVar && ReferencedVar->mode == ir_var_uniform && ReferencedVar->semantic)
|
|
{
|
|
auto FoundIter = Map.find(ReferencedVar->semantic);
|
|
if (FoundIter != Map.end())
|
|
{
|
|
auto* StructVar = FoundIter->second;
|
|
StructVar->used = 1;
|
|
|
|
// Actually replace the variable
|
|
auto* DeRefVar = (*RValuePtr)->as_dereference_variable();
|
|
if (DeRefVar)
|
|
{
|
|
*RValuePtr = new(State)ir_dereference_record(StructVar, ReferencedVar->name);
|
|
}
|
|
else
|
|
{
|
|
check(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
void FMetalCodeBackend::MovePackedUniformsToMain(exec_list* ir, _mesa_glsl_parse_state* state, FBuffers& OutBuffers)
|
|
{
|
|
//IRDump(ir);
|
|
TStringIRVarMap CBVarMap;
|
|
|
|
// Now make a new struct type and global variable per uniform buffer
|
|
for (uint32 i = 0; i < state->num_uniform_blocks; ++i)
|
|
// for (auto& CB : state->CBuffersOriginal)
|
|
{
|
|
auto* CBP = state->FindCBufferByName(false, state->uniform_blocks[i]->name);
|
|
check(CBP);
|
|
auto& CB = *CBP;
|
|
if (!CB.Members.empty())
|
|
{
|
|
glsl_struct_field* Fields = ralloc_array(state, glsl_struct_field, (unsigned)CB.Members.size());
|
|
uint32 Index = 0;
|
|
for (auto& Member : CB.Members)
|
|
{
|
|
check(Member.Var);
|
|
Fields[Index++] = glsl_struct_field(Member.Var->type, ralloc_strdup(state, Member.Var->name));
|
|
}
|
|
|
|
auto* Type = glsl_type::get_record_instance(Fields, (unsigned)CB.Members.size(), ralloc_asprintf(state, "CB_%s", CB.Name.c_str()));
|
|
// Hack: This way we tell this is a uniform buffer and we need to emit 'packed_'
|
|
((glsl_type*)Type)->HlslName = "__PACKED__";
|
|
state->AddUserStruct(Type);
|
|
|
|
auto* Var = new(state)ir_variable(Type, ralloc_asprintf(state, "%s", CB.Name.c_str()), ir_var_uniform);
|
|
CBVarMap[CB.Name] = Var;
|
|
}
|
|
}
|
|
|
|
FConvertUBVisitor ConvertVisitor(state, CBVarMap);
|
|
ConvertVisitor.run(ir);
|
|
|
|
std::set<const glsl_type*> PendingTypes;
|
|
std::set<const glsl_type*> ProcessedTypes;
|
|
|
|
// Actually only save the used variables
|
|
for (auto& Pair : CBVarMap)
|
|
{
|
|
auto* Var = Pair.second;
|
|
if (Var->used)
|
|
{
|
|
// Go through each struct type and mark it as packed
|
|
ir->push_head(Var);
|
|
if (Var->type->is_record())
|
|
{
|
|
PendingTypes.insert(Var->type);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Mark all structures as packed
|
|
while (!PendingTypes.empty())
|
|
{
|
|
auto* Type = *PendingTypes.begin();
|
|
PendingTypes.erase(PendingTypes.begin());
|
|
if (ProcessedTypes.find(Type) == ProcessedTypes.end())
|
|
{
|
|
ProcessedTypes.insert(Type);
|
|
((glsl_type*)Type)->HlslName = "__PACKED__";
|
|
|
|
for (uint32 i = 0; i < Type->length; ++i)
|
|
{
|
|
if (Type->fields.structure[i].type->is_record())
|
|
{
|
|
PendingTypes.insert(Type->fields.structure[i].type);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
ir_function_signature* MainSig = GetMainFunction(ir);
|
|
check(MainSig);
|
|
|
|
// Gather all globals still lying outside Main
|
|
foreach_iter(exec_list_iterator, iter, *ir)
|
|
{
|
|
auto* Instruction = ((ir_instruction*)iter.get());
|
|
auto* Var = Instruction->as_variable();
|
|
if (Var)
|
|
{
|
|
check(Var->mode == ir_var_uniform || Var->mode == ir_var_out || Var->mode == ir_var_in || Var->mode == ir_var_shared);
|
|
if ((!Var->type->is_sampler() && !Var->type->is_image()) || Var->type->sampler_buffer)
|
|
{
|
|
OutBuffers.Buffers.Add(Var);
|
|
}
|
|
else
|
|
{
|
|
OutBuffers.Textures.Add(Var);
|
|
}
|
|
}
|
|
}
|
|
|
|
OutBuffers.SortBuffers(state);
|
|
|
|
// And move them to main
|
|
for (auto Iter : OutBuffers.Buffers)
|
|
{
|
|
auto* Var = (ir_variable*)Iter;
|
|
if (Var)
|
|
{
|
|
Var->remove();
|
|
MainSig->parameters.push_tail(Var);
|
|
}
|
|
}
|
|
|
|
// And move them to main
|
|
for (auto Iter : OutBuffers.Textures)
|
|
{
|
|
auto* Var = (ir_variable*)Iter;
|
|
if (Var)
|
|
{
|
|
Var->remove();
|
|
MainSig->parameters.push_tail(Var);
|
|
}
|
|
}
|
|
//IRDump(ir, state);
|
|
}
|
|
|
|
|
|
void FMetalCodeBackend::PromoteInputsAndOutputsGlobalHalfToFloat(exec_list* Instructions, _mesa_glsl_parse_state* State, EHlslShaderFrequency Frequency)
|
|
{
|
|
//IRDump(Instructions);
|
|
ir_function_signature* EntryPointSig = GetMainFunction(Instructions);
|
|
check(EntryPointSig);
|
|
foreach_iter(exec_list_iterator, Iter, *Instructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* Variable = IR->as_variable();
|
|
if (Variable)
|
|
{
|
|
auto* NewType = PromoteHalfToFloatType(State, Variable->type);
|
|
if (Variable->type == NewType)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
switch (Variable->mode)
|
|
{
|
|
case ir_var_in:
|
|
{
|
|
auto* NewVar = new(State)ir_variable(NewType, Variable->name, ir_var_in);
|
|
NewVar->semantic = Variable->semantic;
|
|
Variable->insert_before(NewVar);
|
|
Variable->name = nullptr;
|
|
Variable->semantic = nullptr;
|
|
Variable->mode = ir_var_temporary;
|
|
Variable->remove();
|
|
exec_list Assignments;
|
|
Assignments.push_head(Variable);
|
|
CreateNewAssignmentsFloat2Half(State, Assignments, Variable, new(State)ir_dereference_variable(NewVar));
|
|
EntryPointSig->body.get_head()->insert_before(&Assignments);
|
|
}
|
|
break;
|
|
|
|
case ir_var_out:
|
|
{
|
|
if(bIsTessellationVSHS)
|
|
{
|
|
// do nothing
|
|
}
|
|
else
|
|
if (Frequency != HSF_PixelShader)
|
|
{
|
|
auto* NewVar = new(State)ir_variable(NewType, Variable->name, ir_var_out);
|
|
NewVar->semantic = Variable->semantic;
|
|
Variable->insert_before(NewVar);
|
|
Variable->name = nullptr;
|
|
Variable->semantic = nullptr;
|
|
Variable->mode = ir_var_temporary;
|
|
Variable->remove();
|
|
exec_list Assignments;
|
|
CreateNewAssignmentsHalf2Float(State, Assignments, NewVar, new(State)ir_dereference_variable(Variable));
|
|
EntryPointSig->body.push_head(Variable);
|
|
EntryPointSig->body.append_list(&Assignments);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
static bool ProcessStageInVariables(_mesa_glsl_parse_state* ParseState, EMetalGPUSemantics bIsDesktop, EHlslShaderFrequency Frequency, ir_variable* Variable, TArray<glsl_struct_field>& OutStageInMembers, std::set<ir_variable*>& OutStageInVariables, unsigned int* OutVertexAttributesMask, TIRVarList& OutFunctionArguments)
|
|
{
|
|
// Don't move variables that are system values into the input structures
|
|
const auto* SystemValues = (bIsDesktop == EMetalGPUSemanticsMobile) ? MetalUtils::MobileSystemValueTable[Frequency] : MetalUtils::DesktopSystemValueTable[Frequency];
|
|
for(int i = 0; SystemValues[i].MetalSemantic != nullptr; ++i)
|
|
{
|
|
if (Variable->semantic && !FCStringAnsi::Stricmp(Variable->semantic, "SV_DomainLocation"))
|
|
{
|
|
check(Frequency == HSF_DomainShader);
|
|
}
|
|
else if (Variable->semantic && SystemValues[i].Mode == ir_var_in && FCStringAnsi::Stricmp(SystemValues[i].MetalSemantic, Variable->semantic) == 0)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
if (Frequency == HSF_VertexShader)
|
|
{
|
|
// Generate an uber struct
|
|
if (Variable->type->is_record())
|
|
{
|
|
check(0);
|
|
}
|
|
else
|
|
{
|
|
int AttributeIndex = GetInAttributeIndex(Variable->name);
|
|
if (AttributeIndex >= 0)
|
|
{
|
|
if (Variable->type->is_array())
|
|
{
|
|
check(Variable->type->element_type()->is_vector());
|
|
for (uint32 i = 0; i < Variable->type->length; ++i, ++AttributeIndex)
|
|
{
|
|
glsl_struct_field OutMember;
|
|
OutMember.type = Variable->type->element_type();
|
|
OutMember.semantic = ralloc_asprintf(ParseState, "ATTRIBUTE%d", AttributeIndex);
|
|
OutMember.name = ralloc_asprintf(ParseState, "ATTRIBUTE%d", AttributeIndex);
|
|
|
|
if (OutVertexAttributesMask)
|
|
{
|
|
*OutVertexAttributesMask |= (1 << AttributeIndex);
|
|
}
|
|
|
|
OutStageInMembers.Add(OutMember);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
glsl_struct_field OutMember;
|
|
OutMember.type = Variable->type;
|
|
OutMember.semantic = ralloc_asprintf(ParseState, "ATTRIBUTE%d", AttributeIndex);
|
|
OutMember.name = ralloc_asprintf(ParseState, "IN_ATTRIBUTE%d", AttributeIndex);
|
|
|
|
if (OutVertexAttributesMask)
|
|
{
|
|
*OutVertexAttributesMask |= (1 << AttributeIndex);
|
|
}
|
|
|
|
OutStageInMembers.Add(OutMember);
|
|
}
|
|
}
|
|
else if (!strcmp(Variable->name, "gl_VertexID") || !strcmp(Variable->name, "gl_InstanceID"))
|
|
{
|
|
OutFunctionArguments.push_back(Variable);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
_mesa_glsl_error(ParseState, "Unknown semantic for input attribute %s!\n", Variable->semantic ? Variable->semantic : "", Variable->name);
|
|
check(0);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
OutStageInVariables.insert(Variable);
|
|
return true;
|
|
}
|
|
else if(Frequency != HSF_HullShader && Frequency != HSF_DomainShader)
|
|
{
|
|
check(Frequency == HSF_PixelShader);
|
|
if (!strcmp(Variable->name, "gl_FrontFacing"))
|
|
{
|
|
// Make sure we add a semantic
|
|
Variable->semantic = "gl_FrontFacing";
|
|
return true;
|
|
}
|
|
}
|
|
|
|
glsl_struct_field Member;
|
|
Member.type = Variable->type;
|
|
Member.name = ralloc_strdup(ParseState, Variable->name);
|
|
Member.semantic = ralloc_strdup(ParseState, Variable->semantic ? Variable->semantic : Variable->name);
|
|
OutStageInMembers.Add(Member);
|
|
OutStageInVariables.insert(Variable);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
/** Information on system values. */
|
|
struct FSystemValue
|
|
{
|
|
const char* Semantic;
|
|
const glsl_type* Type;
|
|
const char* GlslName;
|
|
ir_variable_mode Mode;
|
|
bool bOriginUpperLeft;
|
|
bool bArrayVariable;
|
|
};
|
|
|
|
/** Vertex shader system values. */
|
|
static FSystemValue VertexSystemValueTable[] =
|
|
{
|
|
{"SV_VertexID", glsl_type::uint_type, "gl_VertexID", ir_var_in, false, false},
|
|
{"SV_InstanceID", glsl_type::uint_type, "gl_InstanceID", ir_var_in, false, false},
|
|
{"SV_RenderTargetArrayIndex", glsl_type::uint_type, "OUT_Layer", ir_var_out, false, false},
|
|
//{ "SV_Position", glsl_type::vec4_type, "gl_Position", ir_var_out, false, true },
|
|
{NULL, NULL, NULL, ir_var_auto, false, false}
|
|
};
|
|
|
|
/** Pixel shader system values. */
|
|
static FSystemValue PixelSystemValueTable[] =
|
|
{
|
|
{"SV_Depth", glsl_type::float_type, "gl_FragDepth", ir_var_out, false, false},
|
|
{"SV_Position", glsl_type::vec4_type, "gl_FragCoord", ir_var_in, true, false},
|
|
{"SV_Coverage", glsl_type::uint_type, "IN_Coverage", ir_var_in, false, false},
|
|
{"SV_Coverage", glsl_type::uint_type, "OUT_Coverage", ir_var_out, false, false},
|
|
// { "SV_IsFrontFace", glsl_type::bool_type, "gl_FrontFacing", ir_var_in, false, true },
|
|
{"SV_PrimitiveID", glsl_type::int_type, "gl_PrimitiveID", ir_var_in, false, false},
|
|
{"SV_RenderTargetArrayIndex", glsl_type::uint_type, "IN_Layer", ir_var_in, false, false},
|
|
// { "SV_RenderTargetArrayIndex", glsl_type::uint_type, "gl_Layer", ir_var_in, false, false },
|
|
// { "SV_Target0", glsl_type::vec4_type, "gl_FragColor", ir_var_out, false, true },
|
|
{NULL, NULL, NULL, ir_var_auto, false, false}
|
|
};
|
|
|
|
static FSystemValue* SystemValueTable[] =
|
|
{
|
|
VertexSystemValueTable,
|
|
PixelSystemValueTable,
|
|
nullptr,
|
|
nullptr,
|
|
nullptr,
|
|
nullptr
|
|
};
|
|
|
|
/**
|
|
* 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* GenerateShaderInput(
|
|
EHlslShaderFrequency Frequency, EMetalGPUSemantics bIsDesktop,
|
|
_mesa_glsl_parse_state* ParseState,
|
|
const char* InputSemantic,
|
|
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);
|
|
|
|
check(!InputType->is_inputpatch() && !InputType->is_outputpatch());
|
|
ir_rvalue* SrcValue = MetalUtils::GenerateInputFromSemantic(Frequency, bIsDesktop, ParseState, InputSemantic, InputType, DeclInstructions, PreCallInstructions);
|
|
if(SrcValue)
|
|
{
|
|
YYLTYPE loc ={0};
|
|
apply_type_conversion(InputType,SrcValue,PreCallInstructions,ParseState,true,&loc);
|
|
PreCallInstructions->push_tail(
|
|
new(ParseState)ir_assignment(
|
|
TempVariableDeref->clone(ParseState,NULL),
|
|
SrcValue
|
|
)
|
|
);
|
|
}
|
|
|
|
return TempVariableDeref;
|
|
}
|
|
|
|
|
|
/**
|
|
* 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,
|
|
const glsl_type* Type,
|
|
exec_list* DeclInstructions,
|
|
const glsl_type** DestVariableType)
|
|
{
|
|
check(Semantic);
|
|
|
|
FSystemValue* SystemValues = SystemValueTable[Frequency];
|
|
ir_variable* Variable = NULL;
|
|
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_", 3) == 0)
|
|
{
|
|
for (int i = 0; SystemValues[i].Semantic != NULL; ++i)
|
|
{
|
|
if (SystemValues[i].Mode == ir_var_out
|
|
&& FCStringAnsi::Stricmp(SystemValues[i].Semantic, Semantic) == 0)
|
|
{
|
|
check(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Variable == NULL && Frequency == HSF_VertexShader)
|
|
{
|
|
const int PrefixLength = 15;
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_ClipDistance", PrefixLength) == 0
|
|
&& Semantic[PrefixLength] >= '0'
|
|
&& Semantic[PrefixLength] <= '9')
|
|
{
|
|
check(0);
|
|
}
|
|
}
|
|
|
|
if (Variable == NULL && Frequency == HSF_PixelShader)
|
|
{
|
|
const int PrefixLength = 9;
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_Target", PrefixLength) == 0
|
|
&& 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
|
|
);
|
|
}
|
|
}
|
|
|
|
// @todo Dead function?
|
|
check(0);
|
|
if (Variable == NULL && Frequency == HSF_HullShader)
|
|
{
|
|
const int PrefixLength = 13;
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_TessFactor", PrefixLength) == 0
|
|
&& 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_HullShader)
|
|
{
|
|
const int PrefixLength = 19;
|
|
if (FCStringAnsi::Strnicmp(Semantic, "SV_InsideTessFactor", PrefixLength) == 0
|
|
&& 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
|
|
);
|
|
}
|
|
else if (FCStringAnsi::Stricmp(Semantic, "SV_InsideTessFactor") == 0)
|
|
{
|
|
Variable = new(ParseState)ir_variable(
|
|
Type,
|
|
ralloc_asprintf(ParseState, "gl_TessLevelInner[0]"),
|
|
ir_var_out
|
|
);
|
|
}
|
|
}
|
|
|
|
if (Variable == NULL && ParseState->bGenerateES)
|
|
{
|
|
check(0);
|
|
// 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 = false;//OutputQualifier.Fields.bCentroid;
|
|
Variable->interpolation = false;//OutputQualifier.Fields.InterpolationMode;
|
|
Variable->is_patch_constant = false;// OutputQualifier.Fields.bIsPatchConstant;
|
|
ir_rvalue* VariableDeref = new(ParseState)ir_dereference_variable(Variable);
|
|
return VariableDeref;
|
|
}
|
|
|
|
if (Semantic && FCStringAnsi::Strnicmp(Semantic, "SV_", 3) == 0)
|
|
{
|
|
_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));
|
|
|
|
Variable = new(ParseState)ir_variable(VariableType, ralloc_asprintf(ParseState, "out_%s", Semantic), ir_var_out);
|
|
Variable->centroid = false;//OutputQualifier.Fields.bCentroid;
|
|
Variable->interpolation = false;//OutputQualifier.Fields.InterpolationMode;
|
|
Variable->is_interface_block = true;
|
|
Variable->is_patch_constant = false;//OutputQualifier.Fields.bIsPatchConstant;
|
|
|
|
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*/)
|
|
{
|
|
check(0); // @todo Still a dead function?
|
|
_mesa_glsl_warning(ParseState, "Dead function called: %s:%d\n", __FILE__, __LINE__);
|
|
//VariableDeref = new(ParseState)ir_dereference_array(VariableDeref, new(ParseState)ir_dereference_variable(ParseState->symbols->get_variable("SV_OutputControlPointID")));
|
|
}
|
|
|
|
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 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,
|
|
ir_dereference* OutputVariableDeref,
|
|
exec_list* DeclInstructions,
|
|
exec_list* PostCallInstructions,
|
|
int SemanticArraySize,
|
|
int SemanticArrayIndex
|
|
)
|
|
{
|
|
const glsl_type* OutputType = OutputVariableDeref->type;
|
|
if (OutputType->is_record())
|
|
{
|
|
check(0);
|
|
}
|
|
else if (OutputType->is_array())
|
|
{
|
|
check(0);
|
|
}
|
|
else
|
|
{
|
|
if (OutputSemantic)
|
|
{
|
|
YYLTYPE loc = {0};
|
|
ir_rvalue* Src = OutputVariableDeref->clone(ParseState, NULL);
|
|
const glsl_type* DestVariableType = NULL;
|
|
ir_rvalue* DestVariableDeref = GenShaderOutputSemantic(Frequency, ParseState, OutputSemantic,
|
|
OutputType, DeclInstructions, &DestVariableType);
|
|
|
|
apply_type_conversion(DestVariableType, Src, PostCallInstructions, ParseState, true, &loc);
|
|
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* GenerateShaderOutput(
|
|
EHlslShaderFrequency Frequency,
|
|
_mesa_glsl_parse_state* ParseState,
|
|
const char* OutputSemantic,
|
|
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,
|
|
TempVariableDeref,
|
|
DeclInstructions,
|
|
PostCallInstructions,
|
|
0,
|
|
0
|
|
);
|
|
return TempVariableDeref;
|
|
}
|
|
|
|
#define USE_DS_ATTRIBUTES 0 // @todo Unicorn: consider using this as it would be more elegant, but currently isn't complete.
|
|
|
|
void FMetalCodeBackend::PackInputsAndOutputs(exec_list* Instructions, _mesa_glsl_parse_state* ParseState, EHlslShaderFrequency Frequency, exec_list& InputVars)
|
|
{
|
|
ir_function_signature* EntryPointSig = GetMainFunction(Instructions);
|
|
check(EntryPointSig);
|
|
|
|
exec_list DeclInstructions;
|
|
exec_list PreCallInstructions;
|
|
exec_list ArgInstructions;
|
|
exec_list PostCallInstructions;
|
|
ParseState->symbols->push_scope();
|
|
|
|
// Set of variables packed into a struct
|
|
std::set<ir_variable*> VSStageInVariables;
|
|
std::set<ir_variable*> PSStageInVariables;
|
|
std::set<ir_variable*> VSOutVariables;
|
|
std::set<ir_variable*> PSOutVariables;
|
|
|
|
// Return var/struct
|
|
ir_variable* VSOut = nullptr;
|
|
ir_variable* PSOut = nullptr;
|
|
|
|
// Input stage variables
|
|
ir_variable* VSStageIn = nullptr;
|
|
std::map<FCustomStdString, glsl_struct_field> OriginalVSStageInMembers;
|
|
ir_variable* PSStageIn = nullptr;
|
|
|
|
// Extra arguments needed for input (VertexID, etc)
|
|
TIRVarList VSInputArguments;
|
|
TIRVarList PSInputArguments;
|
|
TIRVarList CSInputArguments;
|
|
|
|
std::set<ir_variable*> DSStageInVariables;
|
|
std::set<ir_variable*> DSOutVariables;
|
|
ir_variable* DSOut = nullptr;
|
|
ir_variable* DSStageIn = nullptr;
|
|
TIRVarList DSInputArguments;
|
|
|
|
#if USE_DS_ATTRIBUTES
|
|
#else // USE_DS_ATTRIBUTES
|
|
std::set<ir_variable*> DSPatchVariables;
|
|
ir_variable* DSPatch = nullptr;
|
|
#endif // USE_DS_ATTRIBUTES
|
|
|
|
ir_variable* internalPatchIDVar = nullptr;
|
|
|
|
if (Frequency == HSF_DomainShader)
|
|
{
|
|
// NOTE: possibly unused
|
|
// create and call GET_INTERNAL_PATCH_ID
|
|
{
|
|
ir_function *Function_GET_INTERNAL_PATCH_ID = NULL;
|
|
// create GET_INTERNAL_PATCH_ID
|
|
{
|
|
const glsl_type* retType = glsl_type::get_instance(GLSL_TYPE_UINT, 1, 1);
|
|
ir_function_signature* sig = new(ParseState)ir_function_signature(retType);
|
|
sig->is_builtin = true;
|
|
Function_GET_INTERNAL_PATCH_ID = new(ParseState)ir_function("GET_INTERNAL_PATCH_ID");
|
|
Function_GET_INTERNAL_PATCH_ID->add_signature(sig);
|
|
}
|
|
check(Function_GET_INTERNAL_PATCH_ID);
|
|
|
|
exec_list VoidParameter;
|
|
ir_function_signature * GetInternalPatchIDFunctionSig = Function_GET_INTERNAL_PATCH_ID->matching_signature(&VoidParameter);
|
|
|
|
internalPatchIDVar = new(ParseState) ir_variable(glsl_type::get_instance(GLSL_TYPE_UINT, 1, 1), nullptr, ir_var_temporary);
|
|
ir_dereference_variable* TempVariableDeref = new(ParseState) ir_dereference_variable(internalPatchIDVar);
|
|
PreCallInstructions.push_tail(internalPatchIDVar);
|
|
|
|
auto* Call = new(ParseState)ir_call(GetInternalPatchIDFunctionSig, TempVariableDeref, &VoidParameter);
|
|
PreCallInstructions.push_tail(Call);
|
|
}
|
|
}
|
|
|
|
if(bIsTessellationVSHS)
|
|
{
|
|
foreach_iter(exec_list_iterator, Iter, *Instructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* Variable = IR->as_variable();
|
|
if (Variable)
|
|
{
|
|
switch (Variable->mode)
|
|
{
|
|
case ir_var_out:
|
|
{
|
|
// do nothing here MovePackedUniformsToMain will move all these output arguments to the function signature
|
|
}
|
|
break;
|
|
|
|
case ir_var_in:
|
|
#if USE_VS_HS_ATTRIBUTES
|
|
{
|
|
// do nothing here MovePackedUniformsToMain will move all these input arguments to the function signature
|
|
}
|
|
#else // USE_VS_HS_ATTRIBUTES
|
|
// there should be no input attributes
|
|
check(0);
|
|
#endif // USE_VS_HS_ATTRIBUTES
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fill up InputVars so "// @Inputs" will have stuff
|
|
for (unsigned i = 0; i < ParseState->num_user_structures; i++)
|
|
{
|
|
const glsl_type *const s = ParseState->user_structures[i];
|
|
|
|
if (strcmp(s->name, "InputVertexType") == 0)
|
|
{
|
|
for (unsigned j = 0; j < s->length; j++)
|
|
{
|
|
InputVars.push_tail(new(ParseState)extern_var(new(ParseState)ir_variable(s->fields.structure[j].type, ralloc_strdup(ParseState, s->fields.structure[j].name), ir_var_in)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (Frequency == HSF_VertexShader)
|
|
{
|
|
// Vertex Fetch to Vertex connector
|
|
TArray<glsl_struct_field> VSStageInMembers;
|
|
|
|
// Vertex Output connector. Gather position semantic & other outputs into a struct
|
|
TArray<glsl_struct_field> VSOutMembers;
|
|
|
|
foreach_iter(exec_list_iterator, Iter, *Instructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* Variable = IR->as_variable();
|
|
if (Variable)
|
|
{
|
|
switch (Variable->mode)
|
|
{
|
|
case ir_var_out:
|
|
{
|
|
glsl_struct_field Member;
|
|
Member.type = Variable->type;
|
|
Member.name = ralloc_strdup(ParseState, Variable->name);
|
|
Member.semantic = ralloc_strdup(ParseState, Variable->semantic ? Variable->semantic : Variable->name);
|
|
VSOutMembers.Add(Member);
|
|
VSOutVariables.insert(Variable);
|
|
}
|
|
break;
|
|
|
|
case ir_var_in:
|
|
if (!ProcessStageInVariables(ParseState, bIsDesktop, Frequency, Variable, VSStageInMembers, VSStageInVariables, nullptr, VSInputArguments))
|
|
{
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (VSStageInMembers.Num())
|
|
{
|
|
check(Frequency == HSF_VertexShader);
|
|
|
|
//@todo-rco: Make me nice...
|
|
int AttributesUsedMask = 0;
|
|
for (auto& Member : VSStageInMembers)
|
|
{
|
|
int Index = GetAttributeIndex(Member.semantic);
|
|
if (Index >= 0 && Index < 16)
|
|
{
|
|
AttributesUsedMask |= (1 << Index);
|
|
}
|
|
InputVars.push_tail(new(ParseState)extern_var(new(ParseState)ir_variable(Member.type, ralloc_strdup(ParseState, Member.name), ir_var_in)));
|
|
}
|
|
|
|
if (bGenerateVSInputDummies)
|
|
{
|
|
int Bit = 0;
|
|
for (int i = 0; i < 16; ++i)
|
|
{
|
|
if ((AttributesUsedMask & (1 << i)) == 0)
|
|
{
|
|
glsl_struct_field NewMember;
|
|
NewMember.name = ralloc_asprintf(ParseState, "__dummy%d", i);
|
|
NewMember.semantic = ralloc_asprintf(ParseState, "ATTRIBUTE%d", i);
|
|
NewMember.type = glsl_type::get_instance(GLSL_TYPE_FLOAT, 4, 1);
|
|
VSStageInMembers.Add(NewMember);
|
|
}
|
|
}
|
|
}
|
|
|
|
VSStageInMembers.Sort(
|
|
[](glsl_struct_field const& A, glsl_struct_field const& B)
|
|
{
|
|
return GetAttributeIndex(A.semantic) < GetAttributeIndex(B.semantic);
|
|
});
|
|
|
|
// Convert all members to float4
|
|
if (bExpandVSInputsToFloat4)
|
|
{
|
|
for (auto& Member : VSStageInMembers)
|
|
{
|
|
OriginalVSStageInMembers[Member.name] = Member;
|
|
check(Member.type->matrix_columns == 1);
|
|
Member.type = glsl_type::get_instance(Member.type->base_type, 4, 1);
|
|
}
|
|
}
|
|
|
|
auto* Type = glsl_type::get_record_instance(&VSStageInMembers[0], (unsigned int)VSStageInMembers.Num(), "FVSStageIn");
|
|
VSStageIn = new(ParseState)ir_variable(Type, "__VSStageIn", ir_var_in);
|
|
// Hack: This way we tell we need to convert types from half to float
|
|
((glsl_type*)Type)->HlslName = "__STAGE_IN__";
|
|
ParseState->symbols->add_variable(VSStageIn);
|
|
|
|
if (!ParseState->AddUserStruct(Type))
|
|
{
|
|
YYLTYPE loc = {0};
|
|
_mesa_glsl_error(&loc, ParseState, "struct '%s' previously defined", Type->name);
|
|
}
|
|
}
|
|
|
|
if (VSOutMembers.Num() && bIsTessellationVSHS)
|
|
{
|
|
check(VSOutMembers.Num() == 1);
|
|
check(VSOutVariables.size() == 1);
|
|
VSOut = *VSOutVariables.begin();
|
|
VSOut->remove();
|
|
VSOut->mode = ir_var_temporary;
|
|
DeclInstructions.push_tail(VSOut);
|
|
}
|
|
else
|
|
if (VSOutMembers.Num())
|
|
{
|
|
auto* Type = glsl_type::get_record_instance(&VSOutMembers[0], (unsigned int)VSOutMembers.Num(), "FVSOut");
|
|
VSOut = new(ParseState)ir_variable(Type, "__VSOut", ir_var_temporary);
|
|
PostCallInstructions.push_tail(VSOut);
|
|
ParseState->symbols->add_variable(VSOut);
|
|
|
|
if (!ParseState->AddUserStruct(Type))
|
|
{
|
|
YYLTYPE loc = {0};
|
|
_mesa_glsl_error(&loc, ParseState, "struct '%s' previously defined", Type->name);
|
|
}
|
|
}
|
|
}
|
|
else if (Frequency == HSF_PixelShader)
|
|
{
|
|
// Vertex to Pixel connector
|
|
TArray<glsl_struct_field> PSStageInMembers;
|
|
|
|
// Pixel Output connector. Gather color & depth outputs into a struct
|
|
TArray<glsl_struct_field> PSOutMembers;
|
|
|
|
// Gather all inputs and generate the StageIn VS->PS connector
|
|
foreach_iter(exec_list_iterator, Iter, *Instructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* Variable = IR->as_variable();
|
|
if (Variable)
|
|
{
|
|
switch (Variable->mode)
|
|
{
|
|
case ir_var_out:
|
|
{
|
|
glsl_struct_field Member;
|
|
Member.type = Variable->type;
|
|
Member.name = ralloc_strdup(ParseState, Variable->name);
|
|
Member.semantic = ralloc_strdup(ParseState, Variable->semantic ? Variable->semantic : Variable->name);
|
|
PSOutMembers.Add(Member);
|
|
PSOutVariables.insert(Variable);
|
|
}
|
|
break;
|
|
|
|
case ir_var_in:
|
|
if (!ProcessStageInVariables(ParseState, bIsDesktop, Frequency, Variable, PSStageInMembers, PSStageInVariables, nullptr, PSInputArguments))
|
|
{
|
|
return;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (PSStageInMembers.Num())
|
|
{
|
|
auto* Type = glsl_type::get_record_instance(&PSStageInMembers[0], (unsigned int)PSStageInMembers.Num(), "FPSStageIn");
|
|
// Hack: This way we tell we need to convert types from half to float
|
|
((glsl_type*)Type)->HlslName = "__STAGE_IN__";
|
|
PSStageIn = new(ParseState)ir_variable(Type, "__PSStageIn", ir_var_in);
|
|
ParseState->symbols->add_variable(PSStageIn);
|
|
|
|
if (!ParseState->AddUserStruct(Type))
|
|
{
|
|
YYLTYPE loc = {0};
|
|
_mesa_glsl_error(&loc, ParseState, "struct '%s' previously defined", Type->name);
|
|
}
|
|
}
|
|
|
|
if (PSOutMembers.Num())
|
|
{
|
|
auto* Type = glsl_type::get_record_instance(&PSOutMembers[0], (unsigned int)PSOutMembers.Num(), "FPSOut");
|
|
PSOut = new(ParseState)ir_variable(Type, "__PSOut", ir_var_temporary);
|
|
PostCallInstructions.push_tail(PSOut);
|
|
ParseState->symbols->add_variable(PSOut);
|
|
|
|
if (!ParseState->AddUserStruct(Type))
|
|
{
|
|
YYLTYPE loc = {0};
|
|
_mesa_glsl_error(&loc, ParseState, "struct '%s' previously defined", Type->name);
|
|
}
|
|
}
|
|
}
|
|
else if (Frequency == HSF_ComputeShader)
|
|
{
|
|
YYLTYPE loc = {0};
|
|
|
|
foreach_iter(exec_list_iterator, Iter, *Instructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* Variable = IR->as_variable();
|
|
if (Variable)
|
|
{
|
|
switch (Variable->mode)
|
|
{
|
|
case ir_var_out:
|
|
{
|
|
_mesa_glsl_error(&loc, ParseState, "Compute/Kernel shaders do not support out variables ('%s')!", Variable->name);
|
|
return;
|
|
}
|
|
break;
|
|
|
|
case ir_var_in:
|
|
{
|
|
TArray<glsl_struct_field> CSStageInMembers;
|
|
TIRVarSet CSStageInVariables;
|
|
if (!ProcessStageInVariables(ParseState, bIsDesktop, Frequency, Variable, CSStageInMembers, CSStageInVariables, nullptr, CSInputArguments))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (CSStageInMembers.Num() != 0 || CSStageInVariables.size() != 0)
|
|
{
|
|
_mesa_glsl_error(&loc, ParseState, "Compute/Kernel shaders do not support out stage_in variables or vertex attributes ('%s')!", Variable->name);
|
|
return;
|
|
}
|
|
}
|
|
break;
|
|
|
|
case ir_var_shared:
|
|
{
|
|
// groupshared
|
|
Variable->remove();
|
|
DeclInstructions.push_head(Variable);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (Frequency == HSF_DomainShader)
|
|
{
|
|
// Vertex Fetch to Vertex connector
|
|
TArray<glsl_struct_field> DSStageInMembers;
|
|
#if USE_DS_ATTRIBUTES
|
|
#else // USE_DS_ATTRIBUTES
|
|
TArray<glsl_struct_field> DSPatchMembers;
|
|
#endif // USE_DS_ATTRIBUTES
|
|
|
|
// Vertex Output connector. Gather position semantic & other outputs into a struct
|
|
TArray<glsl_struct_field> DSOutMembers;
|
|
|
|
foreach_iter(exec_list_iterator, Iter, *Instructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* Variable = IR->as_variable();
|
|
if (Variable)
|
|
{
|
|
switch (Variable->mode)
|
|
{
|
|
case ir_var_out:
|
|
{
|
|
glsl_struct_field Member;
|
|
Member.type = Variable->type;
|
|
Member.name = ralloc_strdup(ParseState, Variable->name);
|
|
Member.semantic = ralloc_strdup(ParseState, Variable->semantic ? Variable->semantic : Variable->name);
|
|
DSOutMembers.Add(Member);
|
|
DSOutVariables.insert(Variable);
|
|
}
|
|
break;
|
|
|
|
case ir_var_in:
|
|
#if USE_DS_ATTRIBUTES
|
|
#else // USE_DS_ATTRIBUTES
|
|
if(Variable->type->is_patch())
|
|
{
|
|
glsl_struct_field Member;
|
|
Member.type = Variable->type;
|
|
Member.name = ralloc_strdup(ParseState, Variable->name);
|
|
Member.semantic = ralloc_strdup(ParseState, Variable->semantic ? Variable->semantic : Variable->name);
|
|
DSPatchMembers.Add(Member);
|
|
DSPatchVariables.insert(Variable);
|
|
}
|
|
else
|
|
#endif // USE_DS_ATTRIBUTES
|
|
if (!ProcessStageInVariables(ParseState, bIsDesktop, Frequency, Variable, DSStageInMembers, DSStageInVariables, nullptr, DSInputArguments))
|
|
{
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
#if USE_DS_ATTRIBUTES
|
|
#error add attribute(0..N) semantics...
|
|
if (DSStageInMembers.Num())
|
|
{
|
|
check(Frequency == HSF_DomainShader);
|
|
|
|
//@todo-rco: Make me nice...
|
|
for (auto& Member : DSStageInMembers)
|
|
{
|
|
InputVars.push_tail(new(ParseState)extern_var(new(ParseState)ir_variable(Member.type, ralloc_strdup(ParseState, Member.name), ir_var_in)));
|
|
}
|
|
|
|
DSStageInMembers.Sort(
|
|
[](glsl_struct_field const& A, glsl_struct_field const& B)
|
|
{
|
|
return GetAttributeIndex(A.semantic) < GetAttributeIndex(B.semantic);
|
|
});
|
|
|
|
auto* Type = glsl_type::get_record_instance(&DSStageInMembers[0], (unsigned int)DSStageInMembers.Num(), "FDSStageIn");
|
|
DSStageIn = new(ParseState)ir_variable(Type, "__DSStageIn", ir_var_in);
|
|
// Hack: This way we tell we need to convert types from half to float
|
|
((glsl_type*)Type)->HlslName = "__STAGE_IN__";
|
|
ParseState->symbols->add_variable(DSStageIn);
|
|
|
|
if (!ParseState->AddUserStruct(Type))
|
|
{
|
|
YYLTYPE loc = {0};
|
|
_mesa_glsl_error(&loc, ParseState, "struct '%s' previously defined", Type->name);
|
|
}
|
|
}
|
|
#else // USE_DS_ATTRIBUTES
|
|
|
|
// track attribute#s
|
|
int onAttribute = 0;
|
|
|
|
if (DSStageInMembers.Num())
|
|
{
|
|
check(Frequency == HSF_DomainShader);
|
|
|
|
for (auto& Member : DSStageInMembers)
|
|
{
|
|
// NOTE: DS structs do not have to match...
|
|
for(auto &Variable : DSStageInVariables)
|
|
{
|
|
if(strcmp(Member.name, Variable->name) == 0)
|
|
{
|
|
Variable->name = ralloc_asprintf(ParseState, "OUT_ATTRIBUTE%d_%s", onAttribute, Variable->name);
|
|
break;
|
|
}
|
|
}
|
|
Member.name = ralloc_asprintf(ParseState, "OUT_ATTRIBUTE%d_%s", onAttribute, Member.name);
|
|
Member.semantic = ralloc_asprintf(ParseState, "[[ attribute(%d) ]]", onAttribute);
|
|
onAttribute++;
|
|
}
|
|
|
|
auto Type = glsl_type::get_record_instance(&DSStageInMembers[0], (unsigned int)DSStageInMembers.Num(), "FDSStageIn");
|
|
auto InType = glsl_type::get_array_instance(Type, 1000); // the size is meaningless
|
|
DSStageIn = new(ParseState)ir_variable(InType, "__DSStageIn", ir_var_in);
|
|
DSStageIn->semantic = ralloc_asprintf(ParseState, ""); // empty attribute for a buffer pointer means that it will be automatically choosen
|
|
ParseState->symbols->add_variable(DSStageIn);
|
|
ParseState->AddUserStruct(Type);
|
|
Instructions->push_head(DSStageIn);
|
|
//PatchConstOutSize = glslTypeSize(Type);
|
|
|
|
// copy from DSStageIn
|
|
for(auto &Variable : DSStageInVariables)
|
|
{
|
|
Variable->remove();
|
|
Variable->mode = ir_var_temporary;
|
|
DeclInstructions.push_tail(Variable);
|
|
check(Variable->name);
|
|
ir_dereference* DeRefArray = new(ParseState)ir_dereference_array(DSStageIn, new(ParseState)ir_constant((unsigned)0));
|
|
ir_dereference* DeRefMember = new(ParseState)ir_dereference_record(DeRefArray, Variable->name);
|
|
auto* Assign = new(ParseState)ir_assignment(new(ParseState)ir_dereference_variable(Variable), DeRefMember);
|
|
PreCallInstructions.push_tail(Assign);
|
|
}
|
|
}
|
|
|
|
if(DSPatchMembers.Num())
|
|
{
|
|
check(DSPatchMembers.Num() == 1);
|
|
check(DSPatchMembers[0].type->is_patch());
|
|
|
|
// generate...
|
|
// MainDomainArg[0] = __DSPatch[0]
|
|
// MainDomainArg[1] = __DSPatch[1]
|
|
// MainDomainArg[2] = __DSPatch[2]
|
|
{
|
|
check(DSPatchVariables.size() == 1);
|
|
auto Variable = *DSPatchVariables.begin();
|
|
Variable->remove();
|
|
Variable->mode = ir_var_temporary;
|
|
DeclInstructions.push_tail(Variable);
|
|
check(Variable->type->is_outputpatch());
|
|
check(ParseState->tessellation.outputcontrolpoints == Variable->type->patch_length);
|
|
const glsl_type* Type = NULL;
|
|
const glsl_type* InType = NULL;
|
|
int origOnAttribute = onAttribute; // should not have to do this...
|
|
for (int OutputVertex = 0; OutputVertex < ParseState->tessellation.outputcontrolpoints; ++OutputVertex)
|
|
{
|
|
int InnerAttribute = origOnAttribute;
|
|
exec_list MainDomainDeclInstructions;
|
|
exec_list PreMainDomainTempDeclInstructions;
|
|
exec_list PreMainDomainCallInstructions;
|
|
|
|
FSemanticQualifier Qualifier;
|
|
|
|
// @todo there has to be a better way to handle this vs looping over GenerateInput...
|
|
auto deref = MetalUtils::GenerateInput(Frequency, bIsDesktop, ParseState, Variable->semantic, Variable->type->inner_type, &MainDomainDeclInstructions, &PreMainDomainCallInstructions);
|
|
|
|
// make a flat perControlPoint struct
|
|
ir_dereference_variable* OutputControlPointDeref = NULL;
|
|
{
|
|
std::set<ir_variable*> DSInVariables;
|
|
|
|
TArray<glsl_struct_field> DSInMembers;
|
|
|
|
foreach_iter(exec_list_iterator, Iter, MainDomainDeclInstructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* InnerVariable = IR->as_variable();
|
|
if (InnerVariable)
|
|
{
|
|
switch (InnerVariable->mode)
|
|
{
|
|
case ir_var_in:
|
|
{
|
|
check(!InnerVariable->type->is_array());
|
|
glsl_struct_field Member;
|
|
Member.type = InnerVariable->type;
|
|
InnerVariable->name = ralloc_asprintf(ParseState, "OUT_ATTRIBUTE%d_%s", InnerAttribute, InnerVariable->name);
|
|
Member.name = ralloc_strdup(ParseState, InnerVariable->name);
|
|
Member.semantic = ralloc_asprintf(ParseState, "[[ attribute(%d) ]]", InnerAttribute);
|
|
InnerAttribute++;
|
|
DSInMembers.Add(Member);
|
|
DSInVariables.insert(InnerVariable);
|
|
}
|
|
break;
|
|
default:
|
|
check(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (DSInMembers.Num())
|
|
{
|
|
if(OutputVertex == 0)
|
|
{
|
|
Type = glsl_type::get_record_instance(&DSInMembers[0], (unsigned int)DSInMembers.Num(), "PatchControlPointOut");
|
|
ParseState->AddUserStruct(Type);
|
|
InType = glsl_type::get_array_instance(Type, 1000); // the size is meaningless
|
|
}
|
|
|
|
auto OutputControlPointVar = new(ParseState)ir_variable(Type, nullptr, ir_var_temporary);
|
|
PreMainDomainTempDeclInstructions.push_tail(OutputControlPointVar);
|
|
OutputControlPointDeref = new(ParseState)ir_dereference_variable(OutputControlPointVar);
|
|
|
|
// copy to DSIn
|
|
for(auto &InnerVariable : DSInVariables)
|
|
{
|
|
InnerVariable->remove();
|
|
InnerVariable->mode = ir_var_temporary;
|
|
PreMainDomainTempDeclInstructions.push_tail(InnerVariable);
|
|
check(InnerVariable->name);
|
|
ir_dereference* DeRefMember = new(ParseState)ir_dereference_record(OutputControlPointVar, InnerVariable->name);
|
|
auto* Assign = new(ParseState)ir_assignment(new(ParseState)ir_dereference_variable(InnerVariable), DeRefMember);
|
|
PreMainDomainCallInstructions.push_head(Assign);
|
|
}
|
|
}
|
|
}
|
|
|
|
if(OutputVertex == 0)
|
|
{
|
|
DSPatch = new(ParseState)ir_variable(InType, "__DSPatch", ir_var_in);
|
|
DSPatch->semantic = ralloc_asprintf(ParseState, ""); // empty attribute for a buffer pointer means that it will be automatically choosen
|
|
ParseState->symbols->add_variable(DSPatch);
|
|
Instructions->push_head(DSPatch);
|
|
}
|
|
|
|
ir_dereference_array* DSPatchDeref = new(ParseState)ir_dereference_array(
|
|
DSPatch,
|
|
new(ParseState)ir_constant((unsigned)OutputVertex)
|
|
);
|
|
|
|
DeclInstructions.append_list(&MainDomainDeclInstructions); // should be empty
|
|
PreCallInstructions.append_list(&PreMainDomainTempDeclInstructions);
|
|
PreCallInstructions.push_tail(
|
|
new (ParseState)ir_assignment(
|
|
OutputControlPointDeref,
|
|
DSPatchDeref
|
|
)
|
|
);
|
|
PreCallInstructions.append_list(&PreMainDomainCallInstructions);
|
|
PreCallInstructions.push_tail(
|
|
new (ParseState)ir_assignment(
|
|
new(ParseState)ir_dereference_array(
|
|
Variable,
|
|
new(ParseState)ir_constant((unsigned)OutputVertex)
|
|
),
|
|
deref
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
#endif // USE_DS_ATTRIBUTES
|
|
|
|
if (DSOutMembers.Num())
|
|
{
|
|
auto* DSOutType = glsl_type::get_record_instance(&DSOutMembers[0], (unsigned int)DSOutMembers.Num(), "FDSOut");
|
|
DSOut = new(ParseState)ir_variable(DSOutType, "__DSOut", ir_var_temporary);
|
|
PostCallInstructions.push_tail(DSOut);
|
|
ParseState->symbols->add_variable(DSOut);
|
|
|
|
if (!ParseState->AddUserStruct(DSOutType))
|
|
{
|
|
YYLTYPE loc = {0};
|
|
_mesa_glsl_error(&loc, ParseState, "struct '%s' previously defined", DSOutType->name);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
check(0);
|
|
}
|
|
|
|
TIRVarList VarsToMoveToBody;
|
|
foreach_iter(exec_list_iterator, Iter, *Instructions)
|
|
{
|
|
ir_instruction* IR = (ir_instruction*)Iter.get();
|
|
auto* Variable = IR->as_variable();
|
|
if (Variable)
|
|
{
|
|
ir_dereference_variable* ArgVarDeref = NULL;
|
|
switch (Variable->mode)
|
|
{
|
|
case ir_var_in:
|
|
if (PSStageInVariables.find(Variable) != PSStageInVariables.end())
|
|
{
|
|
ir_dereference* DeRefMember = new(ParseState)ir_dereference_record(PSStageIn, Variable->name);
|
|
auto* Assign = new(ParseState)ir_assignment(new(ParseState)ir_dereference_variable(Variable), DeRefMember);
|
|
PreCallInstructions.push_tail(Assign);
|
|
VarsToMoveToBody.push_back(Variable);
|
|
}
|
|
else if (VSStageInVariables.find(Variable) != VSStageInVariables.end())
|
|
{
|
|
ir_rvalue* DeRefMember = new(ParseState)ir_dereference_record(VSStageIn, Variable->name);
|
|
unsigned int Mask = 0;
|
|
if (bExpandVSInputsToFloat4)
|
|
{
|
|
Mask = (1 << 4) - 1;
|
|
auto FoundMember = OriginalVSStageInMembers.find(Variable->name);
|
|
check(FoundMember != OriginalVSStageInMembers.end());
|
|
if (FoundMember->second.type)
|
|
{
|
|
check(FoundMember->second.type->vector_elements != 0);
|
|
Mask = (1 << FoundMember->second.type->vector_elements) - 1;
|
|
if (Mask != 15)
|
|
{
|
|
DeRefMember = new(ParseState)ir_swizzle(DeRefMember, 0, 1, 2, 3, FoundMember->second.type->vector_elements);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Mask = (1 << Variable->type->vector_elements) - 1;
|
|
}
|
|
auto* Assign = new(ParseState)ir_assignment(new(ParseState) ir_dereference_variable(Variable), DeRefMember, nullptr, Mask);
|
|
PreCallInstructions.push_tail(Assign);
|
|
VarsToMoveToBody.push_back(Variable);
|
|
}
|
|
else if(bIsTessellationVSHS)
|
|
{
|
|
#if USE_VS_HS_ATTRIBUTES
|
|
// see above...
|
|
// do nothing here MovePackedUniformsToMain will move all these output arguments to the function signature
|
|
#else // USE_VS_HS_ATTRIBUTES
|
|
// there should be no input attributes
|
|
check(0);
|
|
#endif // USE_VS_HS_ATTRIBUTES
|
|
}
|
|
#if USE_DS_ATTRIBUTES
|
|
else if (DSStageInVariables.find(Variable) != DSStageInVariables.end())
|
|
{
|
|
//if(Variable->type->is_outputpatch()) // not exactly what I want...
|
|
//{
|
|
// break; // skip for the outputpatch
|
|
//}
|
|
ir_dereference* DeRefMember = new(ParseState)ir_dereference_record(DSStageIn, Variable->name);
|
|
if(DeRefMember->type->is_outputpatch())
|
|
{
|
|
const unsigned ElementCount = DeRefMember->type->patch_length;
|
|
check(Variable->type->is_outputpatch());
|
|
check(ElementCount == Variable->type->patch_length);
|
|
for (unsigned i = 0; i < ElementCount; ++i)
|
|
{
|
|
ir_dereference_array* ArrayVariable = new(ParseState)ir_dereference_array(
|
|
new(ParseState) ir_dereference_variable(Variable),
|
|
new(ParseState) ir_constant((unsigned)i)
|
|
);
|
|
ir_dereference_array* ArrayDerefMember = new(ParseState)ir_dereference_array(
|
|
DeRefMember->clone(ParseState, NULL),
|
|
new(ParseState) ir_constant((unsigned)i)
|
|
);
|
|
auto* Assign = new(ParseState)ir_assignment(ArrayVariable, ArrayDerefMember);
|
|
PreCallInstructions.push_tail(Assign);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
auto* Assign = new(ParseState)ir_assignment(new(ParseState)ir_dereference_variable(Variable), DeRefMember);
|
|
PreCallInstructions.push_tail(Assign);
|
|
}
|
|
VarsToMoveToBody.push_back(Variable);
|
|
}
|
|
#else // USE_DS_ATTRIBUTES
|
|
else if (DSStageInVariables.find(Variable) != DSStageInVariables.end())
|
|
{
|
|
// TOOD could merge the code above down here...
|
|
}
|
|
else if (DSPatchVariables.find(Variable) != DSPatchVariables.end())
|
|
{
|
|
// TOOD could merge the code above down here...
|
|
}
|
|
#endif // USE_DS_ATTRIBUTES
|
|
else
|
|
{
|
|
// At this point this should be a built-in system value
|
|
check(Variable->semantic);
|
|
ArgVarDeref = GenerateShaderInput(
|
|
Frequency, bIsDesktop,
|
|
ParseState,
|
|
Variable->semantic,
|
|
Variable->type,
|
|
&DeclInstructions,
|
|
&PreCallInstructions
|
|
);
|
|
}
|
|
break;
|
|
|
|
case ir_var_out:
|
|
if (VSOutVariables.find(Variable) != VSOutVariables.end())
|
|
{
|
|
VarsToMoveToBody.push_back(Variable);
|
|
ir_dereference* DeRefMember = new(ParseState) ir_dereference_record(VSOut, Variable->name);
|
|
auto* Assign = new(ParseState) ir_assignment(DeRefMember, new(ParseState)ir_dereference_variable(Variable));
|
|
PostCallInstructions.push_tail(Assign);
|
|
}
|
|
else if (PSOutVariables.find(Variable) != PSOutVariables.end())
|
|
{
|
|
VarsToMoveToBody.push_back(Variable);
|
|
ir_dereference* DeRefMember = new(ParseState) ir_dereference_record(PSOut, Variable->name);
|
|
ir_rvalue* DeRefVar = new(ParseState) ir_dereference_variable(Variable);
|
|
auto* Assign = new(ParseState) ir_assignment(DeRefMember, DeRefVar);
|
|
PostCallInstructions.push_tail(Assign);
|
|
}
|
|
else if(bIsTessellationVSHS)
|
|
{
|
|
// see above...
|
|
// do nothing here MovePackedUniformsToMain will move all these output arguments to the function signature
|
|
}
|
|
else if (DSOutVariables.find(Variable) != DSOutVariables.end())
|
|
{
|
|
VarsToMoveToBody.push_back(Variable);
|
|
ir_dereference* DeRefMember = new(ParseState) ir_dereference_record(DSOut, Variable->name);
|
|
auto* Assign = new(ParseState) ir_assignment(DeRefMember, new(ParseState)ir_dereference_variable(Variable));
|
|
PostCallInstructions.push_tail(Assign);
|
|
}
|
|
else
|
|
{
|
|
ArgVarDeref = GenerateShaderOutput(
|
|
Frequency,
|
|
ParseState,
|
|
Variable->semantic,
|
|
Variable->type,
|
|
&DeclInstructions,
|
|
&PreCallInstructions,
|
|
&PostCallInstructions
|
|
);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
/*
|
|
_mesa_glsl_error(
|
|
ParseState,
|
|
"entry point parameter '%s' must be an input or output",
|
|
Variable->name
|
|
);
|
|
*/
|
|
}
|
|
if (ArgVarDeref)
|
|
{
|
|
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)
|
|
{
|
|
if (Frequency == HSF_PixelShader)
|
|
{
|
|
check(!PSOut);
|
|
PSOut = new(ParseState)ir_variable(EntryPointSig->return_type, "__PSOut", ir_var_temporary);
|
|
PreCallInstructions.push_tail(PSOut);
|
|
}
|
|
else if (Frequency == HSF_VertexShader)
|
|
{
|
|
check(!VSOut);
|
|
VSOut = new(ParseState)ir_variable(EntryPointSig->return_type, "__VSOut", ir_var_temporary);
|
|
PreCallInstructions.push_tail(VSOut);
|
|
}
|
|
else if(bIsTessellationVSHS)
|
|
{
|
|
check(0); // cannot get a return type here
|
|
}
|
|
else if (Frequency == HSF_DomainShader)
|
|
{
|
|
check(!DSOut);
|
|
DSOut = new(ParseState)ir_variable(EntryPointSig->return_type, "__DSOut", ir_var_temporary);
|
|
PreCallInstructions.push_tail(DSOut);
|
|
}
|
|
else
|
|
{
|
|
check(0);
|
|
}
|
|
}
|
|
|
|
ParseState->symbols->pop_scope();
|
|
|
|
// Build the void main() function for GLSL.
|
|
auto* ReturnType = glsl_type::void_type;
|
|
if (VSOut)
|
|
{
|
|
ReturnType = VSOut->type;
|
|
check(!EntryPointReturn);
|
|
EntryPointReturn = new(ParseState)ir_dereference_variable(VSOut);
|
|
PostCallInstructions.push_tail(new(ParseState)ir_return(new(ParseState)ir_dereference_variable(VSOut)));
|
|
EntryPointSig->return_type = ReturnType;
|
|
}
|
|
else if (PSOut)
|
|
{
|
|
ReturnType = PSOut->type;
|
|
check(!EntryPointReturn);
|
|
EntryPointReturn = new(ParseState)ir_dereference_variable(PSOut);
|
|
PostCallInstructions.push_tail(new(ParseState)ir_return(new(ParseState)ir_dereference_variable(PSOut)));
|
|
EntryPointSig->return_type = ReturnType;
|
|
}
|
|
else if (DSOut)
|
|
{
|
|
ReturnType = DSOut->type;
|
|
check(!EntryPointReturn);
|
|
EntryPointReturn = new(ParseState)ir_dereference_variable(DSOut);
|
|
PostCallInstructions.push_tail(new(ParseState)ir_return(new(ParseState)ir_dereference_variable(DSOut)));
|
|
EntryPointSig->return_type = ReturnType;
|
|
}
|
|
|
|
for (auto* Var : VarsToMoveToBody)
|
|
{
|
|
Var->remove();
|
|
if (Var->mode == ir_var_in || Var->mode == ir_var_out)
|
|
{
|
|
Var->mode = ir_var_temporary;
|
|
}
|
|
DeclInstructions.push_head(Var);
|
|
}
|
|
|
|
DeclInstructions.append_list(&PreCallInstructions);
|
|
DeclInstructions.append_list(&EntryPointSig->body);
|
|
DeclInstructions.append_list(&PostCallInstructions);
|
|
|
|
EntryPointSig->body.append_list(&DeclInstructions);
|
|
#if 0
|
|
Instructions->push_tail(MainFunction);
|
|
#endif // 0
|
|
|
|
// Now that we have a proper main(), move global setup to main().
|
|
if (VSStageIn)
|
|
{
|
|
EntryPointSig->parameters.push_tail(VSStageIn);
|
|
}
|
|
else if (PSStageIn)
|
|
{
|
|
EntryPointSig->parameters.push_tail(PSStageIn);
|
|
}
|
|
|
|
/*
|
|
MoveGlobalInstructionsToMain(Instructions);
|
|
*/
|
|
}
|
|
|
|
struct FConvertHalfToFloatUniformAndSamples : public ir_rvalue_visitor
|
|
{
|
|
struct FPair
|
|
{
|
|
ir_rvalue** RValuePtr;
|
|
ir_instruction* InsertPoint;
|
|
};
|
|
typedef std::map<ir_rvalue*, std::list<FPair>> TReplacedVarMap;
|
|
TReplacedVarMap ReplacedVars;
|
|
|
|
std::list<TReplacedVarMap> PendingReplacements;
|
|
TIRVarSet ReferencedUniforms;
|
|
|
|
_mesa_glsl_parse_state* State;
|
|
|
|
bool bIsMaster;
|
|
bool bConvertUniforms;
|
|
bool bConvertSamples;
|
|
|
|
FConvertHalfToFloatUniformAndSamples(_mesa_glsl_parse_state* InState, bool bInConvertUniforms, bool bInConvertSamples) :
|
|
State(InState),
|
|
bIsMaster(true),
|
|
bConvertUniforms(bInConvertUniforms),
|
|
bConvertSamples(bInConvertSamples)
|
|
{
|
|
}
|
|
|
|
void DoConvertOneMap(TReplacedVarMap& Map)
|
|
{
|
|
for (auto& TopIter : Map)
|
|
{
|
|
auto* RValue = TopIter.first;
|
|
auto& List = TopIter.second;
|
|
|
|
// Coerce this var into float
|
|
auto* OriginalVar = RValue->variable_referenced();
|
|
const auto* OriginalVarType = OriginalVar->type;
|
|
const auto* PromotedVarType = PromoteHalfToFloatType(State, OriginalVarType);
|
|
OriginalVar->type = PromotedVarType;
|
|
|
|
// Temp var and assignment
|
|
auto* NewVar = new(State)ir_variable(RValue->type, nullptr, ir_var_temporary);
|
|
RValue->type = PromoteHalfToFloatType(State, RValue->type);
|
|
exec_list NewAssignments;
|
|
CreateNewAssignmentsFloat2Half(State, NewAssignments, NewVar, RValue);
|
|
auto* BaseIR = List.front().InsertPoint;
|
|
|
|
// Store new instructions so we add a nice block in the asm
|
|
BaseIR->insert_before(NewVar);
|
|
BaseIR->insert_before(&NewAssignments);
|
|
|
|
for (auto& Iter : List)
|
|
{
|
|
*(Iter.RValuePtr) = new(State)ir_dereference_variable(NewVar);
|
|
}
|
|
}
|
|
|
|
// Go through all remaining parameters
|
|
for (auto& Var : ReferencedUniforms)
|
|
{
|
|
Var->type = PromoteHalfToFloatType(State, Var->type);
|
|
}
|
|
}
|
|
|
|
void DoConvert(exec_list* ir)
|
|
{
|
|
run(ir);
|
|
DoConvertOneMap(ReplacedVars);
|
|
|
|
if (bIsMaster)
|
|
{
|
|
for (auto& Map : PendingReplacements)
|
|
{
|
|
DoConvertOneMap(Map);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ConvertBlock(exec_list* instructions)
|
|
{
|
|
FConvertHalfToFloatUniformAndSamples Visitor(State, bConvertUniforms, bConvertSamples);
|
|
Visitor.bIsMaster = false;
|
|
Visitor.run(instructions);
|
|
PendingReplacements.push_back(TReplacedVarMap());
|
|
PendingReplacements.back().swap(Visitor.ReplacedVars);
|
|
for (auto& Var : Visitor.ReferencedUniforms)
|
|
{
|
|
ReferencedUniforms.insert(Var);
|
|
}
|
|
}
|
|
|
|
virtual ir_visitor_status visit_enter(ir_if* ir) override
|
|
{
|
|
ir->condition->accept(this);
|
|
handle_rvalue(&ir->condition);
|
|
|
|
ConvertBlock(&ir->then_instructions);
|
|
ConvertBlock(&ir->else_instructions);
|
|
|
|
/* already descended into the children. */
|
|
return visit_continue_with_parent;
|
|
}
|
|
|
|
ir_visitor_status visit_enter(ir_loop* ir)
|
|
{
|
|
ConvertBlock(&ir->body_instructions);
|
|
|
|
/* already descended into the children. */
|
|
return visit_continue_with_parent;
|
|
}
|
|
|
|
virtual void handle_rvalue(ir_rvalue** RValuePtr) override
|
|
{
|
|
if (!RValuePtr || !*RValuePtr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto* RValue = *RValuePtr;
|
|
if (bConvertSamples && RValue->as_texture())
|
|
{
|
|
auto* Texture = RValue->as_texture();
|
|
if (Texture->coordinate && Texture->coordinate->type->base_type == GLSL_TYPE_HALF)
|
|
{
|
|
// Promote to float
|
|
Texture->coordinate = new(State)ir_expression(ir_unop_h2f, Texture->coordinate);
|
|
}
|
|
else if (Texture->coordinate && Texture->coordinate->type->base_type == GLSL_TYPE_INT)
|
|
{
|
|
// convert int to uint32
|
|
Texture->coordinate = new(State)ir_expression(ir_unop_i2u, Texture->coordinate);
|
|
}
|
|
}
|
|
// Skip swizzles, textures, etc
|
|
else if (bConvertUniforms && RValue->as_dereference())
|
|
{
|
|
auto* Var = RValue->variable_referenced();
|
|
if (Var && Var->mode == ir_var_uniform)
|
|
{
|
|
ReferencedUniforms.insert(Var);
|
|
if (RValue->type->base_type == GLSL_TYPE_HALF)
|
|
{
|
|
// Save this RValue and prep for later change
|
|
FPair Pair = {RValuePtr, base_ir};
|
|
for (auto& Iter : ReplacedVars)
|
|
{
|
|
auto* TestRValue = Iter.first;
|
|
if (RValue->ir_type == TestRValue->ir_type && AreEquivalent(RValue, TestRValue))
|
|
{
|
|
Iter.second.push_back(Pair);
|
|
return;
|
|
}
|
|
}
|
|
|
|
ReplacedVars[RValue].push_back(Pair);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
void FMetalCodeBackend::ConvertHalfToFloatUniformsAndSamples(exec_list* ir, _mesa_glsl_parse_state* State, bool bConvertUniforms, bool bConvertSamples)
|
|
{
|
|
if (bConvertUniforms || bConvertSamples)
|
|
{
|
|
FConvertHalfToFloatUniformAndSamples ConvertHalfToFloatUniforms(State, bConvertUniforms, bConvertSamples);
|
|
ConvertHalfToFloatUniforms.DoConvert(ir);
|
|
}
|
|
}
|
|
|
|
struct FMetalBreakPrecisionChangesVisitor : public ir_rvalue_visitor
|
|
{
|
|
_mesa_glsl_parse_state* State;
|
|
|
|
std::map<ir_rvalue*, ir_variable*> ReplacedVars;
|
|
|
|
FMetalBreakPrecisionChangesVisitor(_mesa_glsl_parse_state* InState) : State(InState) {}
|
|
|
|
void ConvertBlock(exec_list* instructions)
|
|
{
|
|
FMetalBreakPrecisionChangesVisitor Visitor(State);
|
|
Visitor.run(instructions);
|
|
}
|
|
|
|
virtual ir_visitor_status visit_enter(ir_if* ir) override
|
|
{
|
|
ir->condition->accept(this);
|
|
handle_rvalue(&ir->condition);
|
|
|
|
ConvertBlock(&ir->then_instructions);
|
|
ConvertBlock(&ir->else_instructions);
|
|
|
|
/* already descended into the children. */
|
|
return visit_continue_with_parent;
|
|
}
|
|
|
|
ir_visitor_status visit_enter(ir_loop* ir)
|
|
{
|
|
ConvertBlock(&ir->body_instructions);
|
|
|
|
/* already descended into the children. */
|
|
return visit_continue_with_parent;
|
|
}
|
|
|
|
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();
|
|
auto* DeRef = RValue->as_dereference();
|
|
auto* DeRefImage = RValue->as_dereference_image();
|
|
if (Expression)
|
|
{
|
|
switch (Expression->operation)
|
|
{
|
|
case ir_unop_h2f:
|
|
case ir_unop_f2h:
|
|
if (!Expression->operands[0]->as_texture())
|
|
{
|
|
bGenerateNewVar = true;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else if (Constant)
|
|
{
|
|
if (Constant->type->base_type == GLSL_TYPE_HALF)
|
|
{
|
|
bGenerateNewVar = true;
|
|
}
|
|
}
|
|
else if (DeRefImage)
|
|
{
|
|
auto* Var = DeRef->variable_referenced();
|
|
if (!in_assignee && Var && Var->type && Var->type->is_image())
|
|
{
|
|
// RW indices have to be unsigned
|
|
if (DeRefImage->image_index->type && DeRefImage->image_index->type->base_type == GLSL_TYPE_INT)
|
|
{
|
|
auto* NewType = glsl_type::get_instance(GLSL_TYPE_UINT, DeRefImage->image_index->type->vector_elements, DeRefImage->image_index->type->matrix_columns);
|
|
auto* NewExpression = new(State) ir_expression(ir_unop_i2u, NewType, DeRefImage->image_index);
|
|
DeRefImage->image_index = NewExpression;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (bGenerateNewVar)
|
|
{
|
|
for (auto& Iter : ReplacedVars)
|
|
{
|
|
auto* TestRValue = Iter.first;
|
|
if (AreEquivalent(TestRValue, RValue))
|
|
{
|
|
*RValuePtr = new(State)ir_dereference_variable(Iter.second);
|
|
return;
|
|
}
|
|
}
|
|
|
|
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);
|
|
ReplacedVars[RValue] = NewVar;
|
|
base_ir->insert_before(NewVar);
|
|
base_ir->insert_before(NewAssignment);
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
void FMetalCodeBackend::BreakPrecisionChangesVisitor(exec_list* ir, _mesa_glsl_parse_state* State)
|
|
{
|
|
FMetalBreakPrecisionChangesVisitor Visitor(State);
|
|
Visitor.run(ir);
|
|
}
|
|
|
|
struct FDeReferencePackedVarsVisitor : public ir_rvalue_visitor
|
|
{
|
|
_mesa_glsl_parse_state* State;
|
|
int ExpressionDepth;
|
|
|
|
FDeReferencePackedVarsVisitor(_mesa_glsl_parse_state* InState)
|
|
: State(InState)
|
|
, ExpressionDepth(0)
|
|
{
|
|
}
|
|
|
|
virtual ir_visitor_status visit_enter(ir_expression* ir) override
|
|
{
|
|
++ExpressionDepth;
|
|
return ir_rvalue_visitor::visit_enter(ir);
|
|
}
|
|
|
|
virtual ir_visitor_status visit_leave(ir_expression* ir) override
|
|
{
|
|
for (uint32 i = 0; i < ir->get_num_operands(); ++i)
|
|
{
|
|
auto* Operand = ir->operands[i];
|
|
auto* DerefRecord = Operand->as_dereference_record();
|
|
if (DerefRecord)
|
|
{
|
|
handle_rvalue(&ir->operands[i]);
|
|
}
|
|
}
|
|
|
|
--ExpressionDepth;
|
|
return ir_rvalue_visitor::visit_leave(ir);
|
|
}
|
|
|
|
virtual void handle_rvalue(ir_rvalue** RValuePtr) override
|
|
{
|
|
if (!RValuePtr || !*RValuePtr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto* DeRefRecord = (*RValuePtr)->as_dereference_record();
|
|
auto* Swizzle = (*RValuePtr)->as_swizzle();
|
|
auto* SwizzleValDeRefRecord = Swizzle ? Swizzle->val->as_dereference_record() : nullptr;
|
|
if (SwizzleValDeRefRecord)
|
|
{
|
|
auto* StructVar = Swizzle->variable_referenced();
|
|
if (StructVar->type->HlslName && !strcmp(StructVar->type->HlslName, "__PACKED__"))
|
|
{
|
|
if (SwizzleValDeRefRecord->type->vector_elements > 1 && SwizzleValDeRefRecord->type->vector_elements < 4)
|
|
{
|
|
auto* Var = GetVar(SwizzleValDeRefRecord);
|
|
Swizzle->val = new(State)ir_dereference_variable(Var);
|
|
}
|
|
}
|
|
}
|
|
else if (DeRefRecord && ExpressionDepth > 0)
|
|
{
|
|
auto* StructVar = DeRefRecord->variable_referenced();
|
|
if (StructVar->type->HlslName && !strcmp(StructVar->type->HlslName, "__PACKED__"))
|
|
{
|
|
if (DeRefRecord->type->vector_elements > 1 && DeRefRecord->type->vector_elements < 4)
|
|
{
|
|
auto* Var = GetVar(DeRefRecord);
|
|
*RValuePtr = new(State)ir_dereference_variable(Var);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
std::map<ir_dereference_record*, ir_variable*> Replaced;
|
|
|
|
ir_variable* GetVar(ir_dereference_record* ir)
|
|
{
|
|
ir_variable* Var = nullptr;
|
|
for (auto& Pair : Replaced)
|
|
{
|
|
if (Pair.first->IsEquivalent(ir))
|
|
{
|
|
Var = Pair.second;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!Var)
|
|
{
|
|
Var = new(State)ir_variable(ir->type, nullptr, ir_var_temporary);
|
|
Replaced[ir] = Var;
|
|
}
|
|
return Var;
|
|
}
|
|
};
|
|
|
|
void FMetalCodeBackend::RemovePackedVarReferences(exec_list* ir, _mesa_glsl_parse_state* State)
|
|
{
|
|
FDeReferencePackedVarsVisitor Visitor(State);
|
|
Visitor.run(ir);
|
|
|
|
if (Visitor.Replaced.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
ir_function_signature* Main = GetMainFunction(ir);
|
|
for (auto& OuterPair : Visitor.Replaced)
|
|
{
|
|
auto* NewVar = OuterPair.second;
|
|
auto* DeRefRecord = OuterPair.first;
|
|
auto* NewAssignment = new(State)ir_assignment(new(State)ir_dereference_variable(NewVar), DeRefRecord);
|
|
Main->body.push_head(NewAssignment);
|
|
Main->body.push_head(NewVar);
|
|
}
|
|
}
|