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 ========================== MAJOR FEATURES + CHANGES ========================== Change 3292174 on 2017/02/08 by Nick.Shin HTML5 emscripten: wasm and webgl2 support - Linux toolchain #jira UEPLAT-1437 Switch [to] web assembly Change 3292193 on 2017/02/08 by Nick.Shin HTML5 emscripten: wasm and webgl2 support - ThirdParty libs compiled with new toolchain with wasm support #jira UEPLAT-1437 Switch [to] web assembly Change 3292215 on 2017/02/08 by Nick.Shin HTML5 emscripten: wasm and wbegl2 support - emscripten toolchain #jira UEPLAT-1437 Switch [to] web assembly Change 3292222 on 2017/02/08 by Nick.Shin HTML5 emscripten: wasm support - ENGINE changes (c# & cpp files) #jira UEPLAT-1437 Switch [to] web assembly Change 3292223 on 2017/02/08 by Nick.Shin HTML5 merge ThirdParty lib build scripts from Dev-Platform to Dev-Mobile Change 3292228 on 2017/02/08 by Nick.Shin HTML5 emscripten: webgl support - webgl patches - and a lot of UE4 patches to package HTML5 on LINUX - mostly from mozilla's jukka -- thx jukka! #jira UEPLAT-828 (4.16) Support ES3 / WebGL2 in HTML5 Change 3292285 on 2017/02/08 by Nick.Shin HTML5 emscripten: wasm and webgl2 support - Windows toolchain #jira UEPLAT-1437 Switch [to] web assembly Change 3293994 on 2017/02/09 by Nick.Shin HTML5 emscripten: wasm and webgl2 support - OSX toolchain #jira UEPLAT-1437 Switch [to] web assembly Change 3294391 on 2017/02/09 by Nick.Shin HTML5 "black box issues" revisited - jukka rewrote the window resize handler -- much cleaner and more straightforward #jira UE-36341 HTML5 - View is incorrectly drawn #jira UE-32311 Templates on Firefox/Chrome on HTML5 are not full screen during Launch On Change 3296421 on 2017/02/10 by Jack.Porter Fix landscape spline segment splitting placing when using streaming levels Change 3296587 on 2017/02/10 by Jack.Porter Additional fix for landscape spline segment splitting when using streaming levels Change 3301241 on 2017/02/14 by Mi.Wang Fixed DeviceProfileEditor bug for incorrect clamp the Texture Mip LOD size. #jira UE-36237 #rb jack.porter Change 3301387 on 2017/02/14 by Nick.Shin HTML5 emscripten: webgl support - webgl patches from mozilla's jukka + hardware instancing + glBlitFramebuffer + GL AlaphaBlendOperation #jira UEPLAT-828 (4.16) Support ES3 / WebGL2 in HTML5 Change 3301405 on 2017/02/14 by Nick.Shin HTML5 plugin fix when blueprint projects are promoted to code projects automatically. #jira UE-41710 HTML5 - Package Failure - Failed to Produce item ProjectName-OnlineSubsystemNull.bc Change 3302278 on 2017/02/14 by Omar.Rodriguez UE-36651: Mac Vulkan Android Projects crash on launch. * Glslang library has been built for Mac but flag was not updated * Set GlslangAvailable to true for Mac when building an Android project with vulkan #jira UE-36651 Change 3302773 on 2017/02/14 by Chris.Babcock Add a dropdown with some common console commands on Android (contributed by rafortis) #jira UE-40834 #PR #3143 #ue4 #android Change 3305604 on 2017/02/16 by Nick.Shin HTML5 webgl2 shader- turn on: instance static mesh vertex factory #jira UEPLAT-828 (4.16) Support ES3 / WebGL2 in HTML5 Change 3308154 on 2017/02/16 by Nick.Shin HTML5 GitHub PR #jira UE-42019 GitHub 3258 : Added suport for emscripten --pre-js and --post-js option when building for HTML5 Change 3308510 on 2017/02/16 by Nick.Shin HTML5 webgl2 shader fixes #jria UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3308971 on 2017/02/17 by Jack.Porter Fix for landscape painting when height<0 in the Ortho viewports Change 3309075 on 2017/02/17 by Allan.Bentham Include static subject meshes when masking out modulated shadow casters. #jira UE-41581 Change 3309531 on 2017/02/17 by Chris.Babcock Handle large OBB files in APK #jira UE-41443 #ue4 #android Change 3311320 on 2017/02/19 by Dmitriy.Dyomin Fixed: Particle Cutout Crashes On Mobile Devices That Don't Support Hardware Instancing (Mali-400 GPU) #jira UE-41970 Change 3311347 on 2017/02/20 by Dmitriy.Dyomin Fixed: Engine Crashes When Previewing ES3_1 With Material Using World Position Offset (Need Custom Stencil) #jira UE-41976 Change 3311398 on 2017/02/20 by Dmitriy.Dyomin Fixed: Landscapes do not render on PowerVR device #jira UE-35530 Change 3311428 on 2017/02/20 by Dmitriy.Dyomin Fixed: Exposure Is More Extreme In High-End Mobile Preview Modes #jira UE-42036 Change 3311448 on 2017/02/20 by Dmitriy.Dyomin Fixed: Packaged game Crashes on android after entering "Help" command twice #jira UE-41956 Change 3311587 on 2017/02/20 by Allan.Bentham ES2 GLSL - Silently swap all uint to ints #jira UE-41548 Change 3313930 on 2017/02/21 by Allan.Bentham Print literal uints as ints when generating ES2 code. #jira UE-41548 Change 3317924 on 2017/02/22 by Nick.Shin HTML5 emscripten: wasm & webgl2 support - RC1 - Linux toolchain #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3317929 on 2017/02/22 by Nick.Shin HTML5 emscripten: wasm & webgl2 support - RC1 - ThirdParty libs compiled with new toolchain with wasm and webgl2 support #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3317951 on 2017/02/22 by Nick.Shin HTML5 emscripten: wasm & webgl2 support - RC1 - emscripten toolchain WARNING: emscripten/incoming/source/include/libc/bit (the file) might need to be deleted first #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3318004 on 2017/02/22 by Nick.Shin HTML5 emscripten: wasm & webgl2 support - RC1 - windows toolchain #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3318669 on 2017/02/23 by Nick.Shin HTML5 emscripten: wasm & webgl2 support - RC1 - OSX toolchain #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3318672 on 2017/02/23 by Nick.Shin HTML5 webgl2 shader fixes #jria UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3318819 on 2017/02/23 by Dmitriy.Dyomin Fixed: Rendering artifacts with bloom on iPhone7 Metal #jira UE-40978 Change 3319702 on 2017/02/23 by Chris.Babcock Disable eglSwapInterval since it can cause issues with some drivers #ue4 #android Change 3320880 on 2017/02/24 by Dmitriy.Dyomin Added r.Mobile.TonemapperFilm cvar which can be used to enable/disable filmic tonemapper on mobile, independently from desktop (disabled by default) #jira UEMOB-195 Change 3321042 on 2017/02/24 by Jack.Porter Fixed incorrect sizeof in Vulkan pipleine cache pointed out here: http://coconutlizard.co.uk/blog/ue4/ue4-its-a-size-jim/ #code_review: rolando.caloca Change 3322383 on 2017/02/24 by Chris.Babcock Fix issue with ad banner on Android 7.0 devices #jira UE-42390 #ue4 #android Change 3322479 on 2017/02/24 by Omar.Rodriguez UEMOB-199 - WEX: Improved virtual keyboard for Android * Calculating the area covered by the virtual keyboard * Calling OnVirtualKeyboardShown and OnVirtualKeyboardHidden events * Passing the Rect of the area covered by the virtual keyboard OnVirtualKeyboardShown event #jira UEMOB-199 Change 3323353 on 2017/02/27 by Allan.Bentham Fix broken mobile scene captures when !mobileHDR and RHINeedsToSwitchVerticalAxis #jira UE-42191 Change 3323431 on 2017/02/27 by Allan.Bentham CIS fix Change 3323687 on 2017/02/27 by Allan.Bentham Disable GRHINeedsUnatlasedCSMDepthsWorkaround for mobile devices. #jira UE-42131 Change 3324652 on 2017/02/28 by Dmitriy.Dyomin Fixed: Canvas elements appear darker on iOS Metal Change 3324885 on 2017/02/28 by Jack.Porter Fixed "Minimum iOS Version" setting display name #jira UE-42270 Change 3324899 on 2017/02/28 by Jack.Porter GitHub 3063 : removed duplicate gc.MaxObjectsInGame setting in IOSEngine.ini #jira UE-40018 #3063 Change 3324932 on 2017/02/28 by Jack.Porter GitHub 3257 : iPhonePackager errors in output log when opening project settings on Windows #jira UE-41984 #3257 #codereview: Peter.Sauerbrei Change 3324956 on 2017/02/28 by Jack.Porter FOpenGLFrontend::GetMaxSamplers incorrect for IOS #jira UE-42038 #3264 Change 3325478 on 2017/02/28 by Allan.Bentham PR # 3188 : Fix far distance bug with cascaded shadows on mobile (Metal) and PC mobile preview (Contributed by ufna) #jira UE-41442 Change 3327300 on 2017/03/01 by Allan.Bentham PR #3175 : Fixes high quality reflection blending seams (Contributed by kallehamalainen) #jira UE-41257 Change 3328917 on 2017/03/02 by Nick.Shin HTML5 project settings expose ini settings to edtior HTML5 project settings panel #jira UE-42331 Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini #jira UE-41584 Editor locks up when adding an element for HTML5 devices on Mac #jira UE-41701 Editor freezes when setting browser filepath for inserted element in project settings Change 3329169 on 2017/03/02 by Allan.Bentham increase render thread timeout to 1 minute for suntemple / android. Prevents low end devices timing out during load. #jira UE-40696 Change 3330849 on 2017/03/02 by Nick.Shin HTML5 project settings expose ini settings to edtior HTML5 project settings panel #jira UE-42331 Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini Change 3331078 on 2017/03/03 by Dmitriy.Dyomin Fixed: Device output log partial lines integrated from WEX (3250488) Change 3331112 on 2017/03/03 by Dmitriy.Dyomin Reduced state setup for slate draw calls (saves about 4ms RT time on mobile) integrated from WEX (3256584) Change 3331117 on 2017/03/03 by Dmitriy.Dyomin Fixed redundant blend state changes in opengl integrated from WEX (3256586) Change 3331173 on 2017/03/03 by Dmitriy.Dyomin Slate pixel shaders will use half precision where possible on mobile integrated from WEX (3256656) Change 3332865 on 2017/03/06 by Dmitriy.Dyomin Better MobileContentScaleFactor defaults for iOS devices #jira UEMOB-330 Change3333129on 2017/03/06 by Peter.Sauerbrei move to Library/Caches instead of documents for saved files re-enable iterative deploy on TVOS #jira UEMOB-284 Change 3334692 on 2017/03/06 by Jack.Porter Allow r.MobileContentScaleFactor to be changed at runtime on Android #jira UEMOB-173 Change 3336255 on 2017/03/07 by Nick.Shin HTML5 project settings marking SIMD and multithreading as experimental - these do not play nice with WASM builds currently... #jira UE-42331 Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini Change 3337094 on 2017/03/08 by Nick.Shin HTML5 project settings marking SIMD and multithreading as experimental - these do not play nice with WASM builds currently... #jira UE-42331 Project Settings - HTML5 SDK - HTML Device population should be moved to an .ini Change 3338800 on 2017/03/08 by Chris.Babcock Update AAR handling to deal with versioning, subproject dependencies for resources, and scope #jira UE-42677 #ue4 #android Change 3338813 on 2017/03/08 by Chris.Babcock Pass build configuration to UPL for access during packaging as $S(Configuration) #jira UE-42678 #ue4 #android #ios Change 3339401 on 2017/03/09 by Alicia.Cano Android runtime permissions - Fix for WRITE_EXTERNAL_STORAGE if it is not granted at time of onCreate for non-shipping builds - Fix for Location Services - Fix for if target sdk is not set to 23+ #jira UE-38512 #android #rb: chris.babcock Change 3340736 on 2017/03/09 by Chris.Babcock Implement support for new controllers (Xbox Wireless, SteelSeries Stratus XL, PS4) (contributed by TRS-justing) #jira UE-41965 #PR #3254 #ue4 #android Change 3340744 on 2017/03/09 by Jack.Porter Expose Custom Depth to Foliage #jira UE-6061 Change 3340849 on 2017/03/09 by Dmitriy.Dyomin Fixed: iOS movie become laggy and crashes when played in iPhone 6/6s. #jira UE-42351 Change 3341268 on 2017/03/10 by Alicia.Cano PR #2894: Initial VoiceModuleAndroid support. (Contributed by devbm) #jira UE-37945 #android #rb: chris.babcock, jack.porter Change 3341303 on 2017/03/10 by Allan.Bentham Remove optimisation that prevents full specular occulsion on mobile. PR #3186 : Specular can't be blocked on high-end mobile. #jira UE-41393 Change 3342304 on 2017/03/10 by Alicia.Cano build fix #rb: chris.babcock Change 3343344 on 2017/03/13 by Alicia.Cano build fix #rb: chris.babcock Change 3343591 on 2017/03/13 by Brent.Pease iOS multiplayer fix part 1. Correct byte ordering. #jira UE-34875 Change 3343669 on 2017/03/13 by Chris.Babcock Update carefullyredist script version #jira UE-42832 Change 3344212 on 2017/03/13 by Will.Fissler Various compile fixes for Xcode 8.3. These fixes must also be added to //UE4/Release-4.15. #jira UE-41313 Change 3344396 on 2017/03/13 by Chris.Babcock Fix Java 1.5 obsolete warnings #jira UE-42851 #ue4 #android Change 3345132 on 2017/03/14 by Will.Fissler Added ifdef wrapper to check clang version for presentDrawable. Change 3345336 on 2017/03/14 by Will.Fissler Moved #if (__clang_major__ > 8) || (__clang_major__ == 8 && __clang_minor__ >= 1) check inside of the presentDrawable method. Change 3345460 on 2017/03/14 by Will.Fissler ifdef changes for presentDrawable. The last submission duped the changes, instead of merging. #rb none Change 3346046 on 2017/03/14 by Will.Fissler Fixed MetalCommandBuffer.cpp [again] after last submission duped changes instead of merging. Change 3346367 on 2017/03/14 by Chris.Babcock Fix issue with GoogleVR ARMv7 libraries included for other architectures in link #ue4 #android Change 3347682 on 2017/03/15 by Allan.Bentham Enable HW sRGB correction with retainer widget's render target. Use slate's gamma correction for mobile (where no such support exists) Render retainer box RT content with gamma correction. #jira UE-40967 Change 3348712 on 2017/03/15 by Nick.Shin HTML5 - upload to S3 updated to AWS "signature version 4" authentication #jira UE-42525 HTML5 Upload to Amazon S3 fails with Incorrect Configuration error Change 3349254 on 2017/03/16 by Jack.Porter Fix for crash using the mobile previewer when the LQ lightmap shader permutation is disabled. #jira UE-42971 Change 3349739 on 2017/03/16 by Nick.Shin HTML5 - upload to S3 better error message feedback on upload failures #jira UE-42525 HTML5 Upload to Amazon S3 fails with Incorrect Configuration error Change 3349765 on 2017/03/16 by Alicia.Cano Disable mouseover events in Mobile Previewer #jira UE-19903 #mobile #rb: Jack.Porter Change 3350049 on 2017/03/16 by Nick.Shin HTML5 - upload to S3 folder in bucket is optional #jira UE-42525 HTML5 Upload to Amazon S3 fails with Incorrect Configuration error Change 3350153 on 2017/03/16 by Nick.Shin HTML5 - upload to S3 updated S3 public link generator #jira UE-42525 HTML5 Upload to Amazon S3 fails with Incorrect Configuration error Change 3351582 on 2017/03/17 by Will.Fissler Reverting the attempted fix for Xcode 8.3: Result += " -mcpu=cortex-a9"; Currently we cannot build arm64 for iOS with this change. Change 3352085 on 2017/03/17 by Alicia.Cano iOS doesn't honor request to close the virtual keyboard leading to a crash #jira UE-36447 #ios #rb:Peter.Sauerbrei Change 3353313 on 2017/03/19 by Ben.Marsh Always allow large *.js files in Github. Change 3354444 on 2017/03/20 by Nick.Shin HTML5 - upload to S3 to help make it obvious that "upload to S3" checkbox is set/or not -- disable S3 details if checkbox for "uploading to S3" is not set #jira UE-42525 HTML5 Upload to Amazon S3 fails with Incorrect Configuration error Change 3355618 on 2017/03/20 by Nick.Shin HTML5 Save Game System - ripped out HTML5 code [from Engine's SaveGameSystem.h] and placed it in HTML5Platform.cpp - cleaned up HTML5PlatformFile.cpp (make it match as clost to linux's version) - created HTML5's own PlatformFeature & SaveGameSystem files -- and updated HTML5PlatformMisc to make use of the the new HTML5 SaveGame code #jira UE-42081 Remove heinous HTML5 code from engine Change 3355621 on 2017/03/20 by Nick.Shin remove temp debugging code #jira UE-42081 Remove heinous HTML5 code from engine Change 3356937 on 2017/03/21 by Chris.Babcock Add "stat vulkanrhi" to new console dropdown #jira UE-43149 #ue4 #android Change 3357652 on 2017/03/21 by Nick.Shin HTML5 performance speed ups added "use fixed timestep" setting option for HTML5 builds (this has been separated from Engine - General Settings - Framerate) - this is slightly different to smooth framerate and fixed framerate - thus, the timestep option was put in the HTML5 specific panel this option is based on the suggestions by jukka's post: - https://answers.unrealengine.com/questions/409629/smooth-frame-rate-and-use-fixed-frame-rate-should.html however, using this option will make the player "run faster" on (for example) thirdperson blueprint template -- but, it has no effect on other (for example) zen garden... #jira UE-30214 - Implement a warning message for fps settings Change 3360415 on 2017/03/23 by Allan.Bentham Fix crash that occurs when ES3.1 preview is used with r.MobileHDR32bppMode modes. Change 3360418 on 2017/03/23 by Allan.Bentham Disable filmic tonemapper if r.MobileHDR32bppMode is in use. #jira UE-40913 Change 3360557 on 2017/03/23 by Allan.Bentham Better fix for mobile CSM shadow flickering (UE-42131), now works for PC OpenGL based mobile preview. #jira UE-42131 Change 3362258 on 2017/03/23 by Dmitriy.Dyomin Fixed: Canvas texture element gamma issues on iOS Metal Change 3362321 on 2017/03/24 by Dmitriy.Dyomin GitHub 3173 : MaterialAO support for mobile rendering path (contributed by kallehamalainen) #3173 Change 3363550 on 2017/03/24 by Alicia.Cano build fix for devices < Android 5.0 #jira UE-43299 #android #rb: chris.babcock Change 3363687 on 2017/03/24 by Chris.Babcock Fix Android password hiding in input dialog #jira WEX-5159 #ue4 #android Change 3365280 on 2017/03/27 by Dmitriy.Dyomin Fix for GL_EXT_shader_framebuffer_fetch on Zenfone5. Use UE_EXT_shader_framebuffer_fetch define on all devices to enable extension Change 3365291 on 2017/03/27 by Dmitriy.Dyomin Copied form WEX CL# 3308653 Fixed: Enabling shader cache causes crash on NVIDIA Shield #jira UE-41639 Change 3365293 on 2017/03/27 by Dmitriy.Dyomin GitHub 3411 : Fix crash in patching utils mount method (contributed by nverenik) #jira UE-43247 #3411 Change 3365340 on 2017/03/27 by Dmitriy.Dyomin Fixed: Moving sublevel in world composition browser does not appear in Undo History #jira UE-35535 Change 3365564 on 2017/03/27 by Allan.Bentham SkyLightComponent now serializes IrradianceMap SH values. clicking Recapture sky button in mobile preview switches back to SM4/5 to update captures. Skylights that are dirty from load will trigger reflection capture update once shaders are rebuilt. #jira UE-42436 Change 3366282 on 2017/03/27 by Nick.Shin remove dead links these files to not exist anywhere in the make-3.81 subfolders #UDN-354501 #jira none Change 3366306 on 2017/03/27 by Nick.Shin HTML5 - disable multi-threading for wasm #jira UE-43219 - HTML5 disable multi-threading for wasm Change 3366307 on 2017/03/27 by Nick.Shin HTML5 packaging Shipping builds big cleanup / additions to *gz file support for amazon s3 * both, uploading to s3 * and allowing s3 to host the games there #jira UE-43002 HTML5 in Shipping fails downloading symbols files #jria UE-43001 HTML5 Shipping Projects fail looking for compressed files when "Compress files during shipping packaging" is not selected. Change 3367385 on 2017/03/28 by Allan.Bentham Display skylight serialization warning only when cooking for mobile platforms. #jira UE-42436 Change 3368583 on 2017/03/28 by Chris.Babcock Expose JAVA_HOME setting in Android SDK project settings on Mac #jira UE-43418 #ue4 #android Change 3368803 on 2017/03/28 by Chris.Babcock Fix features requested in manifest for "Daydream and Cardboard" mode #jira UE-43314 #ue4 #android Change 3369087 on 2017/03/28 by Jack.Porter Changed tooltip and added supported devices in paretheses for Android Mobile Deferred / ES31+AEP #jira UE-42438 Change 3369372 on 2017/03/29 by Allan.Bentham Fix disappearing meshes when r.mobile.allowdistancefieldshadows is disabled. #jira UE-43366 Change 3369381 on 2017/03/29 by Jack.Porter Show warnings when mobile shader permutations required for rendering are disbaled Made FReadOnlyCVARCache a singleton and added mobile CVars, used for MobileBasePassRendering. #jira UE-43050 Change 3369430 on 2017/03/29 by Allan.Bentham fix CIS build Change 3369740 on 2017/03/29 by Allan.Bentham Added Android option to enable builds with hidden symbol visbility by default. (bBuildWithHiddenSymbolVisibility) Android links with -gc-sections to remove unused code/data Add JNI_METHOD for java accessible native functions, fixed up existing JNI functions to use macro. Add support for map file generation with android. Add 'bBuildWithHiddenSymbolVisibility' to AndroidPlatform.HasDefaultBuildConfig() bBuildWithHiddenSymbolVisibility defaults to false in BaseEngine.ini #jira UEMOB-168 Change 3369975 on 2017/03/29 by Nick.Shin HTML5 - AWS S3 shareable link for shipping builds corrected #jira UE-43379 Amazon S3 Shareable link does not generate correct filepath. Change 3369998 on 2017/03/29 by Nick.Shin HTML5 python build scripts PR:1cb836d43c#jira none Change 3370214 on 2017/03/29 by Nick.Shin HTML5 - default bUseFixedTimeStep to false... #jira UE-43380 - Default HTML5 gamespeed is faster than equivalent platforms Change 3370762 on 2017/03/29 by Chris.Babcock Fixes to new keyboard for Android - Ensure the local scope ScreenRect passed into OnVirtualKeyboardShown in AndroidJNI is captured by value instead of by reference. - Moved ShowVirtualKeyboardInput's bKeyboardShowing early-out checks into the UI thread task. This allows the keyboard to continue showing when changing focus between multiple EditableTextBox widgets. #ue4 #android Change 3371344 on 2017/03/30 by Jack.Porter Fixed issue where Vulkan screenshot R/B channels were reversed on Android #jira UE-43479 Change 3372926 on 2017/03/30 by Peter.Sauerbrei start the process of sunsetting 32-bit and GLES2 on iOS #jira UE-42266 Change 3372970 on 2017/03/30 by Nick.Shin HTML5 - 1.37.9 emscripten: wasm & webgl2 support - windows toolchain #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rn Change 3372989 on 2017/03/30 by Peter.Sauerbrei fix for Xcode 8.3 build with 32-bit Change 3373007 on 2017/03/30 by Peter.Sauerbrei fix for crash when online subsystem is disabled on IOS Change 3373108 on 2017/03/30 by Nick.Shin HTML5 - 1.37.9 emscripten: wasm & webgl2 support - emscripten toolchain WARNING: emscripten/incoming/source/include/libc/bit (the file) might need to be deleted first #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rn Change 3373163 on 2017/03/30 by Nick.Shin HTML5 - 1.37.9 emscripten: wasm & webgl2 support - OSX toolchain #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rn Change 3373169 on 2017/03/30 by Nick.Shin HTML5 - 1.37.9 emscripten: wasm & webgl2 support license file updated #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rnx Change 3373287 on 2017/03/30 by Nick.Shin HTML5 - 1.36.11 emscripten - remove old SDK #jira none #rnx Change 3373289 on 2017/03/30 by Nick.Shin HTML5 - 1.37.9 emscripten: wasm & webgl2 support - Linux toolchain #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rn Change 3373595 on 2017/03/30 by Chris.Babcock Reenable GooglePlay for ARM64 now that it doesn't crash #jira UE-36198 #ue4 #android Change 3373606 on 2017/03/30 by Chris.Babcock Submitting Allan's shelved EXT_shader_framebuffer_fetch fix #ue4 #android Change 3375456 on 2017/03/31 by Chris.Babcock Add missing keycodes for Android keyboard (@ and #) #jira WEX-5777 #ue4 #android Change 3376309 on 2017/04/03 by Allan.Bentham Fix overflow issues with mobile DoF. Change 3377041 on 2017/04/03 by Will.Fissler Adding Testbed content for PlatformShowcase. Change 3377582 on 2017/04/03 by Alicia.Cano adding back in GET_ACCOUNTS permission as it is required for Reset Achievements #jira: UE-43265 #android #rb: Chris.Babcock Change 3377643 on 2017/04/03 by Peter.Sauerbrei fix for memory leak in MallocBinned #jira UE-43008 Change 3378033 on 2017/04/04 by Nick.Shin HTML5 - 1.37.9 emscripten: wasm & webgl2 support - ThirdParty libs compiled with new toolchain with wasm and webgl2 support #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 #rn Change 3378034 on 2017/04/04 by Nick.Shin HTML5 - 1.37.9 emscripten: wasm & webgl2 support - ThirdParty build scripts #jira UEMOB-263 Switch [to] web assembly #jira UEMOB-201 Support ES3 / WebGL2 in HTML5 Change 3378035 on 2017/04/04 by Nick.Shin HTML5 - Update GameX template to make it work with trunk Emscripten PRdc2b26f452 (commitcomment-21454978)#jira none #rn Change 3378044 on 2017/04/04 by Nick.Shin HTML5 harfbuzz - double checking recompiled with NO multithreading wasm currently does not support pthreads *** THIS IS STILL WIP *** checking in to match 3rd party libs compiled configuration #jira UE-28588 - Build HarfBuzz for HTML5 #rnx Change 3378264 on 2017/04/04 by Allan.Bentham Fix crash when using consolas font on android sdk 24 #jira UE-43464 Change 3379097 on 2017/04/04 by Nick.Shin CIS HTML5 build warning fix #jria none #rnx Change 3379333 on 2017/04/04 by Chris.Babcock Prevent inserting extra permissions into manifest multiple times #jira UE-43583 #ue4 #android Change 3380870 on 2017/04/05 by Chris.Babcock Fix merge issue Change 3380898 on 2017/04/05 by Chris.Babcock Fixed again Change 3381443 on 2017/04/05 by Chris.Babcock Fix for GearVR non-unity build #ue4 #android Change 3381941 on 2017/04/05 by Chris.Babcock Fix HTTPChunkInstaller texture format checks and missing #define warning #jira UE-43706 #ue4 #android Change 3382056 on 2017/04/05 by Chris.Babcock Updates to Android AARs needed for Facebook plugin Change 3382097 on 2017/04/05 by Chris.Babcock Disable java console cmd receiver only in shipping builds #jira UE-43710 #ue4 #android Change 3382497 on 2017/04/06 by Allan.Bentham Fix Fortnite Cooked Server crashes when joining game from lobby. #jira UE-43695 Change 3383227 on 2017/04/06 by Will.Fissler Reverted case sensitive change, from yesterday, and implemented a pragma instead. #jira UE-41313 [CL 3383473 by Jack Porter in Main branch]
1652 lines
52 KiB
C++
1652 lines
52 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
// .
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "HAL/FileManager.h"
|
|
#include "Misc/FileHelper.h"
|
|
#include "Misc/Paths.h"
|
|
#include "Serialization/MemoryWriter.h"
|
|
#include "ShaderFormatOpenGL.h"
|
|
|
|
#if PLATFORM_WINDOWS
|
|
#include "AllowWindowsPlatformTypes.h"
|
|
#include "Windows/PreWindowsApi.h"
|
|
#include <objbase.h>
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include "Windows/PostWindowsApi.h"
|
|
#include "Windows/MinWindows.h"
|
|
#include "HideWindowsPlatformTypes.h"
|
|
#endif
|
|
#include "ShaderCore.h"
|
|
#include "ShaderPreprocessor.h"
|
|
#include "ShaderCompilerCommon.h"
|
|
#include "GlslBackend.h"
|
|
#if PLATFORM_WINDOWS
|
|
#include "AllowWindowsPlatformTypes.h"
|
|
#include <GL/glcorearb.h>
|
|
#include <GL/glext.h>
|
|
#include <GL/wglext.h>
|
|
#include "HideWindowsPlatformTypes.h"
|
|
#elif PLATFORM_LINUX
|
|
#define GL_GLEXT_PROTOTYPES 1
|
|
#include <GL/glcorearb.h>
|
|
#include <GL/glext.h>
|
|
#include "SDL.h"
|
|
GLAPI GLuint APIENTRY glCreateShader (GLenum type);
|
|
GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar* const *string, const GLint *length);
|
|
typedef SDL_Window* SDL_HWindow;
|
|
typedef SDL_GLContext SDL_HGLContext;
|
|
struct FPlatformOpenGLContext
|
|
{
|
|
SDL_HWindow hWnd;
|
|
SDL_HGLContext hGLContext; // this is a (void*) pointer
|
|
};
|
|
#elif PLATFORM_MAC
|
|
#include <OpenGL/OpenGL.h>
|
|
#include <OpenGL/gl3.h>
|
|
#include <OpenGL/gl3ext.h>
|
|
#ifndef GL_COMPUTE_SHADER
|
|
#define GL_COMPUTE_SHADER 0x91B9
|
|
#endif
|
|
#ifndef GL_TESS_EVALUATION_SHADER
|
|
#define GL_TESS_EVALUATION_SHADER 0x8E87
|
|
#endif
|
|
#ifndef GL_TESS_CONTROL_SHADER
|
|
#define GL_TESS_CONTROL_SHADER 0x8E88
|
|
#endif
|
|
#endif
|
|
#include "OpenGLUtil.h"
|
|
#include "OpenGLShaderResources.h"
|
|
|
|
DEFINE_LOG_CATEGORY_STATIC(LogOpenGLShaderCompiler, Log, All);
|
|
|
|
|
|
#define VALIDATE_GLSL_WITH_DRIVER 0
|
|
#define ENABLE_IMAGINATION_COMPILER 1
|
|
|
|
|
|
static FORCEINLINE bool IsES2Platform(GLSLVersion Version)
|
|
{
|
|
return (Version == GLSL_ES2 || Version == GLSL_150_ES2 || Version == GLSL_ES2_WEBGL || Version == GLSL_ES2_IOS || Version == GLSL_150_ES2_NOUB);
|
|
}
|
|
|
|
static FORCEINLINE bool IsPCES2Platform(GLSLVersion Version)
|
|
{
|
|
return (Version == GLSL_150_ES2 || Version == GLSL_150_ES2_NOUB || Version == GLSL_150_ES3_1);
|
|
}
|
|
|
|
// This function should match OpenGLShaderPlatformSeparable
|
|
bool FOpenGLFrontend::SupportsSeparateShaderObjects(GLSLVersion Version)
|
|
{
|
|
// Only desktop shader platforms can use separable shaders for now,
|
|
// the generated code relies on macros supplied at runtime to determine whether
|
|
// shaders may be separable and/or linked.
|
|
return Version == GLSL_150 || Version == GLSL_150_MAC || Version == GLSL_150_ES2 || Version == GLSL_150_ES2_NOUB ||
|
|
Version == GLSL_150_ES3_1 || Version == GLSL_430;
|
|
}
|
|
|
|
/*------------------------------------------------------------------------------
|
|
Shader compiling.
|
|
------------------------------------------------------------------------------*/
|
|
|
|
#if PLATFORM_WINDOWS
|
|
/** List all OpenGL entry points needed for shader compilation. */
|
|
#define ENUM_GL_ENTRYPOINTS(EnumMacro) \
|
|
EnumMacro(PFNGLCOMPILESHADERPROC,glCompileShader) \
|
|
EnumMacro(PFNGLCREATESHADERPROC,glCreateShader) \
|
|
EnumMacro(PFNGLDELETESHADERPROC,glDeleteShader) \
|
|
EnumMacro(PFNGLGETSHADERIVPROC,glGetShaderiv) \
|
|
EnumMacro(PFNGLGETSHADERINFOLOGPROC,glGetShaderInfoLog) \
|
|
EnumMacro(PFNGLSHADERSOURCEPROC,glShaderSource) \
|
|
EnumMacro(PFNGLDELETEBUFFERSPROC,glDeleteBuffers)
|
|
|
|
/** Define all GL functions. */
|
|
#define DEFINE_GL_ENTRYPOINTS(Type,Func) static Type Func = NULL;
|
|
ENUM_GL_ENTRYPOINTS(DEFINE_GL_ENTRYPOINTS);
|
|
|
|
/** This function is handled separately because it is used to get a real context. */
|
|
static PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB;
|
|
|
|
/** Platform specific OpenGL context. */
|
|
struct FPlatformOpenGLContext
|
|
{
|
|
HWND WindowHandle;
|
|
HDC DeviceContext;
|
|
HGLRC OpenGLContext;
|
|
};
|
|
|
|
/**
|
|
* A dummy wndproc.
|
|
*/
|
|
static LRESULT CALLBACK PlatformDummyGLWndproc(HWND hWnd, uint32 Message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
return DefWindowProc(hWnd, Message, wParam, lParam);
|
|
}
|
|
|
|
/**
|
|
* Initialize a pixel format descriptor for the given window handle.
|
|
*/
|
|
static void PlatformInitPixelFormatForDevice(HDC DeviceContext)
|
|
{
|
|
// Pixel format descriptor for the context.
|
|
PIXELFORMATDESCRIPTOR PixelFormatDesc;
|
|
FMemory::Memzero(PixelFormatDesc);
|
|
PixelFormatDesc.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
|
PixelFormatDesc.nVersion = 1;
|
|
PixelFormatDesc.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
|
PixelFormatDesc.iPixelType = PFD_TYPE_RGBA;
|
|
PixelFormatDesc.cColorBits = 32;
|
|
PixelFormatDesc.cDepthBits = 0;
|
|
PixelFormatDesc.cStencilBits = 0;
|
|
PixelFormatDesc.iLayerType = PFD_MAIN_PLANE;
|
|
|
|
// Set the pixel format and create the context.
|
|
int32 PixelFormat = ChoosePixelFormat(DeviceContext, &PixelFormatDesc);
|
|
if (!PixelFormat || !SetPixelFormat(DeviceContext, PixelFormat, &PixelFormatDesc))
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal,TEXT("Failed to set pixel format for device context."));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Create a dummy window used to construct OpenGL contexts.
|
|
*/
|
|
static void PlatformCreateDummyGLWindow(FPlatformOpenGLContext* OutContext)
|
|
{
|
|
const TCHAR* WindowClassName = TEXT("DummyGLToolsWindow");
|
|
|
|
// Register a dummy window class.
|
|
static bool bInitializedWindowClass = false;
|
|
if (!bInitializedWindowClass)
|
|
{
|
|
WNDCLASS wc;
|
|
|
|
bInitializedWindowClass = true;
|
|
FMemory::Memzero(wc);
|
|
wc.style = CS_OWNDC;
|
|
wc.lpfnWndProc = PlatformDummyGLWndproc;
|
|
wc.cbClsExtra = 0;
|
|
wc.cbWndExtra = 0;
|
|
wc.hInstance = NULL;
|
|
wc.hIcon = NULL;
|
|
wc.hCursor = NULL;
|
|
wc.hbrBackground = (HBRUSH)(COLOR_MENUTEXT);
|
|
wc.lpszMenuName = NULL;
|
|
wc.lpszClassName = WindowClassName;
|
|
ATOM ClassAtom = ::RegisterClass(&wc);
|
|
check(ClassAtom);
|
|
}
|
|
|
|
// Create a dummy window.
|
|
OutContext->WindowHandle = CreateWindowEx(
|
|
WS_EX_WINDOWEDGE,
|
|
WindowClassName,
|
|
NULL,
|
|
WS_POPUP,
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
NULL, NULL, NULL, NULL);
|
|
check(OutContext->WindowHandle);
|
|
|
|
// Get the device context.
|
|
OutContext->DeviceContext = GetDC(OutContext->WindowHandle);
|
|
check(OutContext->DeviceContext);
|
|
PlatformInitPixelFormatForDevice(OutContext->DeviceContext);
|
|
}
|
|
|
|
/**
|
|
* Create a core profile OpenGL context.
|
|
*/
|
|
static void PlatformCreateOpenGLContextCore(FPlatformOpenGLContext* OutContext, int MajorVersion, int MinorVersion, HGLRC InParentContext)
|
|
{
|
|
check(wglCreateContextAttribsARB);
|
|
check(OutContext);
|
|
check(OutContext->DeviceContext);
|
|
|
|
int AttribList[] =
|
|
{
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, MajorVersion,
|
|
WGL_CONTEXT_MINOR_VERSION_ARB, MinorVersion,
|
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB | WGL_CONTEXT_DEBUG_BIT_ARB,
|
|
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
0
|
|
};
|
|
|
|
OutContext->OpenGLContext = wglCreateContextAttribsARB(OutContext->DeviceContext, InParentContext, AttribList);
|
|
check(OutContext->OpenGLContext);
|
|
}
|
|
|
|
/**
|
|
* Make the context current.
|
|
*/
|
|
static void PlatformMakeGLContextCurrent(FPlatformOpenGLContext* Context)
|
|
{
|
|
check(Context && Context->OpenGLContext && Context->DeviceContext);
|
|
wglMakeCurrent(Context->DeviceContext, Context->OpenGLContext);
|
|
}
|
|
|
|
/**
|
|
* Initialize an OpenGL context so that shaders can be compiled.
|
|
*/
|
|
static void PlatformInitOpenGL(void*& ContextPtr, void*& PrevContextPtr, int InMajorVersion, int InMinorVersion)
|
|
{
|
|
static FPlatformOpenGLContext ShaderCompileContext = {0};
|
|
|
|
ContextPtr = (void*)wglGetCurrentDC();
|
|
PrevContextPtr = (void*)wglGetCurrentContext();
|
|
|
|
if (ShaderCompileContext.OpenGLContext == NULL && InMajorVersion && InMinorVersion)
|
|
{
|
|
PlatformCreateDummyGLWindow(&ShaderCompileContext);
|
|
|
|
// Disable warning C4191: 'type cast' : unsafe conversion from 'PROC' to 'XXX' while getting GL entry points.
|
|
#pragma warning(push)
|
|
#pragma warning(disable:4191)
|
|
|
|
if (wglCreateContextAttribsARB == NULL)
|
|
{
|
|
// Create a dummy context so that wglCreateContextAttribsARB can be initialized.
|
|
ShaderCompileContext.OpenGLContext = wglCreateContext(ShaderCompileContext.DeviceContext);
|
|
check(ShaderCompileContext.OpenGLContext);
|
|
PlatformMakeGLContextCurrent(&ShaderCompileContext);
|
|
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
|
check(wglCreateContextAttribsARB);
|
|
wglDeleteContext(ShaderCompileContext.OpenGLContext);
|
|
}
|
|
|
|
// Create a context so that remaining GL function pointers can be initialized.
|
|
PlatformCreateOpenGLContextCore(&ShaderCompileContext, InMajorVersion, InMinorVersion, /*InParentContext=*/ NULL);
|
|
check(ShaderCompileContext.OpenGLContext);
|
|
PlatformMakeGLContextCurrent(&ShaderCompileContext);
|
|
|
|
if (glCreateShader == NULL)
|
|
{
|
|
// Initialize all entry points.
|
|
#define GET_GL_ENTRYPOINTS(Type,Func) Func = (Type)wglGetProcAddress(#Func);
|
|
ENUM_GL_ENTRYPOINTS(GET_GL_ENTRYPOINTS);
|
|
|
|
// Check that all of the entry points have been initialized.
|
|
bool bFoundAllEntryPoints = true;
|
|
#define CHECK_GL_ENTRYPOINTS(Type,Func) if (Func == NULL) { bFoundAllEntryPoints = false; UE_LOG(LogOpenGLShaderCompiler, Warning, TEXT("Failed to find entry point for %s"), TEXT(#Func)); }
|
|
ENUM_GL_ENTRYPOINTS(CHECK_GL_ENTRYPOINTS);
|
|
checkf(bFoundAllEntryPoints, TEXT("Failed to find all OpenGL entry points."));
|
|
}
|
|
|
|
// Restore warning C4191.
|
|
#pragma warning(pop)
|
|
}
|
|
PlatformMakeGLContextCurrent(&ShaderCompileContext);
|
|
}
|
|
static void PlatformReleaseOpenGL(void* ContextPtr, void* PrevContextPtr)
|
|
{
|
|
wglMakeCurrent((HDC)ContextPtr, (HGLRC)PrevContextPtr);
|
|
}
|
|
#elif PLATFORM_LINUX
|
|
static void _PlatformCreateDummyGLWindow(FPlatformOpenGLContext *OutContext)
|
|
{
|
|
static bool bInitializedWindowClass = false;
|
|
|
|
// Create a dummy window.
|
|
OutContext->hWnd = SDL_CreateWindow(NULL,
|
|
0, 0, 1, 1,
|
|
SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS | SDL_WINDOW_HIDDEN | SDL_WINDOW_SKIP_TASKBAR );
|
|
}
|
|
|
|
static void _PlatformCreateOpenGLContextCore(FPlatformOpenGLContext* OutContext)
|
|
{
|
|
check(OutContext);
|
|
SDL_HWindow PrevWindow = SDL_GL_GetCurrentWindow();
|
|
SDL_HGLContext PrevContext = SDL_GL_GetCurrentContext();
|
|
|
|
OutContext->hGLContext = SDL_GL_CreateContext(OutContext->hWnd);
|
|
SDL_GL_MakeCurrent(PrevWindow, PrevContext);
|
|
}
|
|
|
|
static void _ContextMakeCurrent(SDL_HWindow hWnd, SDL_HGLContext hGLDC)
|
|
{
|
|
GLint Result = SDL_GL_MakeCurrent( hWnd, hGLDC );
|
|
check(!Result);
|
|
}
|
|
|
|
static void PlatformInitOpenGL(void*& ContextPtr, void*& PrevContextPtr, int InMajorVersion, int InMinorVersion)
|
|
{
|
|
static bool bInitialized = (SDL_GL_GetCurrentWindow() != NULL) && (SDL_GL_GetCurrentContext() != NULL);
|
|
|
|
if (!bInitialized)
|
|
{
|
|
check(InMajorVersion > 3 || (InMajorVersion == 3 && InMinorVersion >= 2));
|
|
if (SDL_WasInit(0) == 0)
|
|
{
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
}
|
|
else
|
|
{
|
|
Uint32 InitializedSubsystemsMask = SDL_WasInit(SDL_INIT_EVERYTHING);
|
|
if ((InitializedSubsystemsMask & SDL_INIT_VIDEO) == 0)
|
|
{
|
|
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
|
}
|
|
}
|
|
|
|
if (SDL_GL_LoadLibrary(NULL))
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Unable to dynamically load libGL: %s"), ANSI_TO_TCHAR(SDL_GetError()));
|
|
}
|
|
|
|
if (SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, InMajorVersion))
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL major version: %s"), ANSI_TO_TCHAR(SDL_GetError()));
|
|
}
|
|
|
|
if (SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, InMinorVersion))
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL minor version: %s"), ANSI_TO_TCHAR(SDL_GetError()));
|
|
}
|
|
|
|
if (SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG))
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL flags: %s"), ANSI_TO_TCHAR(SDL_GetError()));
|
|
}
|
|
|
|
if (SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE))
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Failed to set GL mask/profile: %s"), ANSI_TO_TCHAR(SDL_GetError()));
|
|
}
|
|
|
|
// Create a dummy context to verify opengl support.
|
|
FPlatformOpenGLContext DummyContext;
|
|
_PlatformCreateDummyGLWindow(&DummyContext);
|
|
_PlatformCreateOpenGLContextCore(&DummyContext);
|
|
|
|
if (DummyContext.hGLContext)
|
|
{
|
|
_ContextMakeCurrent(DummyContext.hWnd, DummyContext.hGLContext);
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("OpenGL %d.%d not supported by driver"), InMajorVersion, InMinorVersion);
|
|
return;
|
|
}
|
|
|
|
PrevContextPtr = NULL;
|
|
ContextPtr = DummyContext.hGLContext;
|
|
bInitialized = true;
|
|
}
|
|
|
|
PrevContextPtr = reinterpret_cast<void*>(SDL_GL_GetCurrentContext());
|
|
SDL_HGLContext NewContext = SDL_GL_CreateContext(SDL_GL_GetCurrentWindow());
|
|
SDL_GL_MakeCurrent(SDL_GL_GetCurrentWindow(), NewContext);
|
|
ContextPtr = reinterpret_cast<void*>(NewContext);
|
|
}
|
|
|
|
static void PlatformReleaseOpenGL(void* ContextPtr, void* PrevContextPtr)
|
|
{
|
|
SDL_GL_MakeCurrent(SDL_GL_GetCurrentWindow(), reinterpret_cast<SDL_HGLContext>(PrevContextPtr));
|
|
SDL_GL_DeleteContext(reinterpret_cast<SDL_HGLContext>(ContextPtr));
|
|
}
|
|
#elif PLATFORM_MAC
|
|
static void PlatformInitOpenGL(void*& ContextPtr, void*& PrevContextPtr, int InMajorVersion, int InMinorVersion)
|
|
{
|
|
check(InMajorVersion > 3 || (InMajorVersion == 3 && InMinorVersion >= 2));
|
|
|
|
CGLPixelFormatAttribute AttribList[] =
|
|
{
|
|
kCGLPFANoRecovery,
|
|
kCGLPFAAccelerated,
|
|
kCGLPFAOpenGLProfile,
|
|
(CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core,
|
|
(CGLPixelFormatAttribute)0
|
|
};
|
|
|
|
CGLPixelFormatObj PixelFormat;
|
|
GLint NumFormats = 0;
|
|
CGLError Error = CGLChoosePixelFormat(AttribList, &PixelFormat, &NumFormats);
|
|
check(Error == kCGLNoError);
|
|
|
|
CGLContextObj ShaderCompileContext;
|
|
Error = CGLCreateContext(PixelFormat, NULL, &ShaderCompileContext);
|
|
check(Error == kCGLNoError);
|
|
|
|
Error = CGLDestroyPixelFormat(PixelFormat);
|
|
check(Error == kCGLNoError);
|
|
|
|
PrevContextPtr = (void*)CGLGetCurrentContext();
|
|
|
|
Error = CGLSetCurrentContext(ShaderCompileContext);
|
|
check(Error == kCGLNoError);
|
|
|
|
ContextPtr = (void*)ShaderCompileContext;
|
|
}
|
|
static void PlatformReleaseOpenGL(void* ContextPtr, void* PrevContextPtr)
|
|
{
|
|
CGLContextObj ShaderCompileContext = (CGLContextObj)ContextPtr;
|
|
CGLContextObj PreviousShaderCompileContext = (CGLContextObj)PrevContextPtr;
|
|
CGLError Error;
|
|
|
|
Error = CGLSetCurrentContext(PreviousShaderCompileContext);
|
|
check(Error == kCGLNoError);
|
|
|
|
Error = CGLDestroyContext(ShaderCompileContext);
|
|
check(Error == kCGLNoError);
|
|
}
|
|
#endif
|
|
|
|
/** Map shader frequency -> GL shader type. */
|
|
GLenum GLFrequencyTable[] =
|
|
{
|
|
GL_VERTEX_SHADER, // SF_Vertex
|
|
GL_TESS_CONTROL_SHADER, // SF_Hull
|
|
GL_TESS_EVALUATION_SHADER, // SF_Domain
|
|
GL_FRAGMENT_SHADER, // SF_Pixel
|
|
GL_GEOMETRY_SHADER, // SF_Geometry
|
|
GL_COMPUTE_SHADER, // SF_Compute
|
|
|
|
};
|
|
|
|
static_assert(ARRAY_COUNT(GLFrequencyTable) == SF_NumFrequencies, "Frequency table size mismatch.");
|
|
|
|
static inline bool IsDigit(TCHAR Char)
|
|
{
|
|
return Char >= '0' && Char <= '9';
|
|
}
|
|
|
|
/**
|
|
* Parse a GLSL error.
|
|
* @param OutErrors - Storage for shader compiler errors.
|
|
* @param InLine - A single line from the compile error log.
|
|
*/
|
|
void ParseGlslError(TArray<FShaderCompilerError>& OutErrors, const FString& InLine)
|
|
{
|
|
const TCHAR* ErrorPrefix = TEXT("error: 0:");
|
|
const TCHAR* p = *InLine;
|
|
if (FCString::Strnicmp(p, ErrorPrefix, 9) == 0)
|
|
{
|
|
FString ErrorMsg;
|
|
int32 LineNumber = 0;
|
|
p += FCString::Strlen(ErrorPrefix);
|
|
|
|
// Skip to a number, take that to be the line number.
|
|
while (*p && !IsDigit(*p)) { p++; }
|
|
while (*p && IsDigit(*p))
|
|
{
|
|
LineNumber = 10 * LineNumber + (*p++ - TEXT('0'));
|
|
}
|
|
|
|
// Skip to the next alphanumeric value, treat that as the error message.
|
|
while (*p && !FChar::IsAlnum(*p)) { p++; }
|
|
ErrorMsg = p;
|
|
|
|
// Generate a compiler error.
|
|
if (ErrorMsg.Len() > 0)
|
|
{
|
|
// Note that no mapping exists from the GLSL source to the original
|
|
// HLSL source.
|
|
FShaderCompilerError* CompilerError = new(OutErrors) FShaderCompilerError;
|
|
CompilerError->StrippedErrorMessage = FString::Printf(
|
|
TEXT("driver compile error(%d): %s"),
|
|
LineNumber,
|
|
*ErrorMsg
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
static TArray<ANSICHAR> ParseIdentifierANSI(const FString& Str)
|
|
{
|
|
TArray<ANSICHAR> Result;
|
|
Result.Reserve(Str.Len());
|
|
for (int32 Index = 0; Index < Str.Len(); ++Index)
|
|
{
|
|
Result.Add(FChar::ToLower((ANSICHAR)Str[Index]));
|
|
}
|
|
Result.Add('\0');
|
|
|
|
return Result;
|
|
}
|
|
|
|
static uint32 ParseNumber(const TCHAR* Str)
|
|
{
|
|
uint32 Num = 0;
|
|
while (*Str && IsDigit(*Str))
|
|
{
|
|
Num = Num * 10 + *Str++ - '0';
|
|
}
|
|
return Num;
|
|
}
|
|
|
|
|
|
static ANSICHAR TranslateFrequencyToCrossCompilerPrefix(int32 Frequency)
|
|
{
|
|
switch (Frequency)
|
|
{
|
|
case SF_Vertex: return 'v';
|
|
case SF_Pixel: return 'p';
|
|
case SF_Hull: return 'h';
|
|
case SF_Domain: return 'd';
|
|
case SF_Geometry: return 'g';
|
|
case SF_Compute: return 'c';
|
|
}
|
|
return '\0';
|
|
}
|
|
|
|
static TCHAR* SetIndex(TCHAR* Str, int32 Offset, int32 Index)
|
|
{
|
|
check(Index >= 0 && Index < 100);
|
|
|
|
Str += Offset;
|
|
if (Index >= 10)
|
|
{
|
|
*Str++ = '0' + (TCHAR)(Index / 10);
|
|
}
|
|
*Str++ = '0' + (TCHAR)(Index % 10);
|
|
*Str = '\0';
|
|
return Str;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Construct the final microcode from the compiled and verified shader source.
|
|
* @param ShaderOutput - Where to store the microcode and parameter map.
|
|
* @param InShaderSource - GLSL source with input/output signature.
|
|
* @param SourceLen - The length of the GLSL source code.
|
|
*/
|
|
void FOpenGLFrontend::BuildShaderOutput(
|
|
FShaderCompilerOutput& ShaderOutput,
|
|
const FShaderCompilerInput& ShaderInput,
|
|
const ANSICHAR* InShaderSource,
|
|
int32 SourceLen,
|
|
GLSLVersion Version
|
|
)
|
|
{
|
|
const ANSICHAR* USFSource = InShaderSource;
|
|
CrossCompiler::FHlslccHeader CCHeader;
|
|
if (!CCHeader.Read(USFSource, SourceLen))
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Error, TEXT("Bad hlslcc header found"));
|
|
}
|
|
|
|
if (*USFSource != '#')
|
|
{
|
|
UE_LOG(LogOpenGLShaderCompiler, Error, TEXT("Bad hlslcc header found! Missing '#'!"));
|
|
}
|
|
|
|
FOpenGLCodeHeader Header = {0};
|
|
FShaderParameterMap& ParameterMap = ShaderOutput.ParameterMap;
|
|
EShaderFrequency Frequency = (EShaderFrequency)ShaderOutput.Target.Frequency;
|
|
|
|
TBitArray<> UsedUniformBufferSlots;
|
|
UsedUniformBufferSlots.Init(false, 32);
|
|
|
|
// Write out the magic markers.
|
|
Header.GlslMarker = 0x474c534c;
|
|
switch (Frequency)
|
|
{
|
|
case SF_Vertex:
|
|
Header.FrequencyMarker = 0x5653;
|
|
break;
|
|
case SF_Pixel:
|
|
Header.FrequencyMarker = 0x5053;
|
|
break;
|
|
case SF_Geometry:
|
|
Header.FrequencyMarker = 0x4753;
|
|
break;
|
|
case SF_Hull:
|
|
Header.FrequencyMarker = 0x4853;
|
|
break;
|
|
case SF_Domain:
|
|
Header.FrequencyMarker = 0x4453;
|
|
break;
|
|
case SF_Compute:
|
|
Header.FrequencyMarker = 0x4353;
|
|
break;
|
|
default:
|
|
UE_LOG(LogOpenGLShaderCompiler, Fatal, TEXT("Invalid shader frequency: %d"), (int32)Frequency);
|
|
}
|
|
|
|
static const FString AttributePrefix = TEXT("in_ATTRIBUTE");
|
|
static const FString GL_Prefix = TEXT("gl_");
|
|
for (auto& Input : CCHeader.Inputs)
|
|
{
|
|
// Only process attributes for vertex shaders.
|
|
if (Frequency == SF_Vertex && Input.Name.StartsWith(AttributePrefix))
|
|
{
|
|
int32 AttributeIndex = ParseNumber(*Input.Name + AttributePrefix.Len());
|
|
Header.Bindings.InOutMask |= (1 << AttributeIndex);
|
|
}
|
|
// Record user-defined input varyings
|
|
else if (!Input.Name.StartsWith(GL_Prefix))
|
|
{
|
|
FOpenGLShaderVarying Var;
|
|
Var.Location = Input.Index;
|
|
Var.Varying = ParseIdentifierANSI(Input.Name);
|
|
Header.Bindings.InputVaryings.Add(Var);
|
|
}
|
|
}
|
|
|
|
// Generate vertex attribute remapping table.
|
|
// This is used on devices where GL_MAX_VERTEX_ATTRIBS < 16
|
|
if (Frequency == SF_Vertex)
|
|
{
|
|
uint32 AttributeMask = Header.Bindings.InOutMask;
|
|
int32 NextAttributeSlot = 0;
|
|
Header.Bindings.VertexRemappedMask = 0;
|
|
for (int32 AttributeIndex = 0; AttributeIndex < 16; AttributeIndex++, AttributeMask >>= 1)
|
|
{
|
|
if (AttributeMask & 0x1)
|
|
{
|
|
Header.Bindings.VertexRemappedMask |= (1 << NextAttributeSlot);
|
|
Header.Bindings.VertexAttributeRemap[AttributeIndex] = NextAttributeSlot++;
|
|
}
|
|
else
|
|
{
|
|
Header.Bindings.VertexAttributeRemap[AttributeIndex] = -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
static const FString TargetPrefix = "out_Target";
|
|
static const FString GL_FragDepth = "gl_FragDepth";
|
|
for (auto& Output : CCHeader.Outputs)
|
|
{
|
|
// Only targets for pixel shaders must be tracked.
|
|
if (Frequency == SF_Pixel && Output.Name.StartsWith(TargetPrefix))
|
|
{
|
|
uint8 TargetIndex = ParseNumber(*Output.Name + TargetPrefix.Len());
|
|
Header.Bindings.InOutMask |= (1 << TargetIndex);
|
|
}
|
|
// Only depth writes for pixel shaders must be tracked.
|
|
else if (Frequency == SF_Pixel && Output.Name.Equals(GL_FragDepth))
|
|
{
|
|
Header.Bindings.InOutMask |= 0x8000;
|
|
}
|
|
// Record user-defined output varyings
|
|
else if (!Output.Name.StartsWith(GL_Prefix))
|
|
{
|
|
FOpenGLShaderVarying Var;
|
|
Var.Location = Output.Index;
|
|
Var.Varying = ParseIdentifierANSI(Output.Name);
|
|
Header.Bindings.OutputVaryings.Add(Var);
|
|
}
|
|
}
|
|
|
|
// general purpose binding name
|
|
TCHAR BindingName[] = TEXT("XYZ\0\0\0\0\0\0\0\0");
|
|
BindingName[0] = TranslateFrequencyToCrossCompilerPrefix(Frequency);
|
|
|
|
TMap<FString, FString> BindingNameMap;
|
|
|
|
// Then 'normal' uniform buffers.
|
|
for (auto& UniformBlock : CCHeader.UniformBlocks)
|
|
{
|
|
uint16 UBIndex = UniformBlock.Index;
|
|
check(UBIndex == Header.Bindings.NumUniformBuffers);
|
|
UsedUniformBufferSlots[UBIndex] = true;
|
|
if (OutputTrueParameterNames())
|
|
{
|
|
// make the final name this will be in the shader
|
|
BindingName[1] = 'b';
|
|
SetIndex(BindingName, 2, UBIndex);
|
|
BindingNameMap.Add(BindingName, UniformBlock.Name);
|
|
}
|
|
else
|
|
{
|
|
ParameterMap.AddParameterAllocation(*UniformBlock.Name, Header.Bindings.NumUniformBuffers, 0, 0);
|
|
}
|
|
Header.Bindings.NumUniformBuffers++;
|
|
}
|
|
|
|
const uint16 BytesPerComponent = 4;
|
|
|
|
// Packed global uniforms
|
|
TMap<ANSICHAR, uint16> PackedGlobalArraySize;
|
|
for (auto& PackedGlobal : CCHeader.PackedGlobals)
|
|
{
|
|
ParameterMap.AddParameterAllocation(
|
|
*PackedGlobal.Name,
|
|
PackedGlobal.PackedType,
|
|
PackedGlobal.Offset * BytesPerComponent,
|
|
PackedGlobal.Count * BytesPerComponent
|
|
);
|
|
|
|
uint16& Size = PackedGlobalArraySize.FindOrAdd(PackedGlobal.PackedType);
|
|
Size = FMath::Max<uint16>(BytesPerComponent * (PackedGlobal.Offset + PackedGlobal.Count), Size);
|
|
}
|
|
|
|
// Packed Uniform Buffers
|
|
TMap<int, TMap<ANSICHAR, uint16> > PackedUniformBuffersSize;
|
|
for (auto& PackedUB : CCHeader.PackedUBs)
|
|
{
|
|
checkf(OutputTrueParameterNames() == false, TEXT("Unexpected Packed UBs used with a shader format that needs true parameter names - If this is hit, we need to figure out how to handle them"));
|
|
|
|
check(PackedUB.Attribute.Index == Header.Bindings.NumUniformBuffers);
|
|
UsedUniformBufferSlots[PackedUB.Attribute.Index] = true;
|
|
if (OutputTrueParameterNames())
|
|
{
|
|
BindingName[1] = 'b';
|
|
// ???
|
|
}
|
|
else
|
|
{
|
|
ParameterMap.AddParameterAllocation(*PackedUB.Attribute.Name, Header.Bindings.NumUniformBuffers, 0, 0);
|
|
}
|
|
Header.Bindings.NumUniformBuffers++;
|
|
|
|
// Nothing else...
|
|
//for (auto& Member : PackedUB.Members)
|
|
//{
|
|
//}
|
|
}
|
|
|
|
// Packed Uniform Buffers copy lists & setup sizes for each UB/Precision entry
|
|
enum EFlattenUBState
|
|
{
|
|
Unknown,
|
|
GroupedUBs,
|
|
FlattenedUBs,
|
|
};
|
|
EFlattenUBState UBState = Unknown;
|
|
for (auto& PackedUBCopy : CCHeader.PackedUBCopies)
|
|
{
|
|
CrossCompiler::FUniformBufferCopyInfo CopyInfo;
|
|
CopyInfo.SourceUBIndex = PackedUBCopy.SourceUB;
|
|
CopyInfo.SourceOffsetInFloats = PackedUBCopy.SourceOffset;
|
|
CopyInfo.DestUBIndex = PackedUBCopy.DestUB;
|
|
CopyInfo.DestUBTypeName = PackedUBCopy.DestPackedType;
|
|
CopyInfo.DestUBTypeIndex = CrossCompiler::PackedTypeNameToTypeIndex(CopyInfo.DestUBTypeName);
|
|
CopyInfo.DestOffsetInFloats = PackedUBCopy.DestOffset;
|
|
CopyInfo.SizeInFloats = PackedUBCopy.Count;
|
|
|
|
Header.UniformBuffersCopyInfo.Add(CopyInfo);
|
|
|
|
auto& UniformBufferSize = PackedUniformBuffersSize.FindOrAdd(CopyInfo.DestUBIndex);
|
|
uint16& Size = UniformBufferSize.FindOrAdd(CopyInfo.DestUBTypeName);
|
|
Size = FMath::Max<uint16>(BytesPerComponent * (CopyInfo.DestOffsetInFloats + CopyInfo.SizeInFloats), Size);
|
|
|
|
check(UBState == Unknown || UBState == GroupedUBs);
|
|
UBState = GroupedUBs;
|
|
}
|
|
|
|
for (auto& PackedUBCopy : CCHeader.PackedUBGlobalCopies)
|
|
{
|
|
CrossCompiler::FUniformBufferCopyInfo CopyInfo;
|
|
CopyInfo.SourceUBIndex = PackedUBCopy.SourceUB;
|
|
CopyInfo.SourceOffsetInFloats = PackedUBCopy.SourceOffset;
|
|
CopyInfo.DestUBIndex = PackedUBCopy.DestUB;
|
|
CopyInfo.DestUBTypeName = PackedUBCopy.DestPackedType;
|
|
CopyInfo.DestUBTypeIndex = CrossCompiler::PackedTypeNameToTypeIndex(CopyInfo.DestUBTypeName);
|
|
CopyInfo.DestOffsetInFloats = PackedUBCopy.DestOffset;
|
|
CopyInfo.SizeInFloats = PackedUBCopy.Count;
|
|
|
|
Header.UniformBuffersCopyInfo.Add(CopyInfo);
|
|
|
|
uint16& Size = PackedGlobalArraySize.FindOrAdd(CopyInfo.DestUBTypeName);
|
|
Size = FMath::Max<uint16>(BytesPerComponent * (CopyInfo.DestOffsetInFloats + CopyInfo.SizeInFloats), Size);
|
|
|
|
check(UBState == Unknown || UBState == FlattenedUBs);
|
|
UBState = FlattenedUBs;
|
|
}
|
|
|
|
Header.Bindings.bFlattenUB = (UBState == FlattenedUBs);
|
|
|
|
// Setup Packed Array info
|
|
Header.Bindings.PackedGlobalArrays.Reserve(PackedGlobalArraySize.Num());
|
|
for (auto Iterator = PackedGlobalArraySize.CreateIterator(); Iterator; ++Iterator)
|
|
{
|
|
ANSICHAR TypeName = Iterator.Key();
|
|
uint16 Size = Iterator.Value();
|
|
Size = (Size + 0xf) & (~0xf);
|
|
CrossCompiler::FPackedArrayInfo Info;
|
|
Info.Size = Size;
|
|
Info.TypeName = TypeName;
|
|
Info.TypeIndex = CrossCompiler::PackedTypeNameToTypeIndex(TypeName);
|
|
Header.Bindings.PackedGlobalArrays.Add(Info);
|
|
}
|
|
|
|
// Setup Packed Uniform Buffers info
|
|
Header.Bindings.PackedUniformBuffers.Reserve(PackedUniformBuffersSize.Num());
|
|
for (auto Iterator = PackedUniformBuffersSize.CreateIterator(); Iterator; ++Iterator)
|
|
{
|
|
int BufferIndex = Iterator.Key();
|
|
auto& ArraySizes = Iterator.Value();
|
|
TArray<CrossCompiler::FPackedArrayInfo> InfoArray;
|
|
InfoArray.Reserve(ArraySizes.Num());
|
|
for (auto IterSizes = ArraySizes.CreateIterator(); IterSizes; ++IterSizes)
|
|
{
|
|
ANSICHAR TypeName = IterSizes.Key();
|
|
uint16 Size = IterSizes.Value();
|
|
Size = (Size + 0xf) & (~0xf);
|
|
CrossCompiler::FPackedArrayInfo Info;
|
|
Info.Size = Size;
|
|
Info.TypeName = TypeName;
|
|
Info.TypeIndex = CrossCompiler::PackedTypeNameToTypeIndex(TypeName);
|
|
InfoArray.Add(Info);
|
|
}
|
|
|
|
Header.Bindings.PackedUniformBuffers.Add(InfoArray);
|
|
}
|
|
|
|
// Then samplers.
|
|
for (auto& Sampler : CCHeader.Samplers)
|
|
{
|
|
if (OutputTrueParameterNames())
|
|
{
|
|
BindingName[1] = 's';
|
|
SetIndex(BindingName, 2, Sampler.Offset);
|
|
BindingNameMap.Add(BindingName, Sampler.Name);
|
|
}
|
|
else
|
|
{
|
|
ParameterMap.AddParameterAllocation(
|
|
*Sampler.Name,
|
|
0,
|
|
Sampler.Offset,
|
|
Sampler.Count
|
|
);
|
|
}
|
|
|
|
Header.Bindings.NumSamplers = FMath::Max<uint8>(
|
|
Header.Bindings.NumSamplers,
|
|
Sampler.Offset + Sampler.Count
|
|
);
|
|
|
|
for (auto& SamplerState : Sampler.SamplerStates)
|
|
{
|
|
if (OutputTrueParameterNames())
|
|
{
|
|
// add an entry for the sampler parameter as well
|
|
BindingNameMap.Add(FString(BindingName) + TEXT("_samp"), SamplerState);
|
|
}
|
|
else
|
|
{
|
|
ParameterMap.AddParameterAllocation(
|
|
*SamplerState,
|
|
0,
|
|
Sampler.Offset,
|
|
Sampler.Count
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Then UAVs (images in GLSL)
|
|
for (auto& UAV : CCHeader.UAVs)
|
|
{
|
|
if (OutputTrueParameterNames())
|
|
{
|
|
// make the final name this will be in the shader
|
|
BindingName[1] = 'i';
|
|
SetIndex(BindingName, 2, UAV.Offset);
|
|
BindingNameMap.Add(BindingName, UAV.Name);
|
|
}
|
|
else
|
|
{
|
|
ParameterMap.AddParameterAllocation(
|
|
*UAV.Name,
|
|
0,
|
|
UAV.Offset,
|
|
UAV.Count
|
|
);
|
|
}
|
|
|
|
Header.Bindings.NumUAVs = FMath::Max<uint8>(
|
|
Header.Bindings.NumSamplers,
|
|
UAV.Offset + UAV.Count
|
|
);
|
|
}
|
|
|
|
Header.ShaderName = CCHeader.Name;
|
|
|
|
// perform any post processing this frontend class may need to do
|
|
ShaderOutput.bSucceeded = PostProcessShaderSource(Version, Frequency, USFSource, SourceLen + 1 - (USFSource - InShaderSource), ParameterMap, BindingNameMap, ShaderOutput.Errors);
|
|
|
|
// Build the SRT for this shader.
|
|
{
|
|
// Build the generic SRT for this shader.
|
|
FShaderCompilerResourceTable GenericSRT;
|
|
BuildResourceTableMapping(ShaderInput.Environment.ResourceTableMap, ShaderInput.Environment.ResourceTableLayoutHashes, UsedUniformBufferSlots, ShaderOutput.ParameterMap, GenericSRT);
|
|
|
|
// Copy over the bits indicating which resource tables are active.
|
|
Header.Bindings.ShaderResourceTable.ResourceTableBits = GenericSRT.ResourceTableBits;
|
|
|
|
Header.Bindings.ShaderResourceTable.ResourceTableLayoutHashes = GenericSRT.ResourceTableLayoutHashes;
|
|
|
|
// Now build our token streams.
|
|
BuildResourceTableTokenStream(GenericSRT.TextureMap, GenericSRT.MaxBoundResourceTable, Header.Bindings.ShaderResourceTable.TextureMap);
|
|
BuildResourceTableTokenStream(GenericSRT.ShaderResourceViewMap, GenericSRT.MaxBoundResourceTable, Header.Bindings.ShaderResourceTable.ShaderResourceViewMap);
|
|
BuildResourceTableTokenStream(GenericSRT.SamplerMap, GenericSRT.MaxBoundResourceTable, Header.Bindings.ShaderResourceTable.SamplerMap);
|
|
BuildResourceTableTokenStream(GenericSRT.UnorderedAccessViewMap, GenericSRT.MaxBoundResourceTable, Header.Bindings.ShaderResourceTable.UnorderedAccessViewMap);
|
|
}
|
|
|
|
const int32 MaxSamplers = GetMaxSamplers(Version);
|
|
|
|
if (Header.Bindings.NumSamplers > MaxSamplers)
|
|
{
|
|
ShaderOutput.bSucceeded = false;
|
|
FShaderCompilerError* NewError = new(ShaderOutput.Errors) FShaderCompilerError();
|
|
NewError->StrippedErrorMessage =
|
|
FString::Printf(TEXT("shader uses %d samplers exceeding the limit of %d"),
|
|
Header.Bindings.NumSamplers, MaxSamplers);
|
|
}
|
|
else if (ShaderOutput.bSucceeded)
|
|
{
|
|
// Write out the header
|
|
FMemoryWriter Ar(ShaderOutput.ShaderCode.GetWriteAccess(), true);
|
|
Ar << Header;
|
|
|
|
if (OptionalSerializeOutputAndReturnIfSerialized(Ar) == false)
|
|
{
|
|
Ar.Serialize((void*)USFSource, SourceLen + 1 - (USFSource - InShaderSource));
|
|
ShaderOutput.bSucceeded = true;
|
|
}
|
|
|
|
// store data we can pickup later with ShaderCode.FindOptionalData('n'), could be removed for shipping
|
|
// Daniel L: This GenerateShaderName does not generate a deterministic output among shaders as the shader code can be shared.
|
|
// uncommenting this will cause the project to have non deterministic materials and will hurt patch sizes
|
|
//ShaderOutput.ShaderCode.AddOptionalData('n', TCHAR_TO_UTF8(*ShaderInput.GenerateShaderName()));
|
|
|
|
ShaderOutput.NumInstructions = 0;
|
|
ShaderOutput.NumTextureSamplers = Header.Bindings.NumSamplers;
|
|
}
|
|
}
|
|
|
|
void FOpenGLFrontend::ConvertOpenGLVersionFromGLSLVersion(GLSLVersion InVersion, int& OutMajorVersion, int& OutMinorVersion)
|
|
{
|
|
switch(InVersion)
|
|
{
|
|
case GLSL_150:
|
|
case GLSL_150_MAC:
|
|
OutMajorVersion = 3;
|
|
OutMinorVersion = 2;
|
|
break;
|
|
case GLSL_310_ES_EXT:
|
|
case GLSL_430:
|
|
OutMajorVersion = 4;
|
|
OutMinorVersion = 3;
|
|
break;
|
|
case GLSL_150_ES2:
|
|
case GLSL_150_ES2_NOUB:
|
|
case GLSL_150_ES3_1:
|
|
OutMajorVersion = 3;
|
|
OutMinorVersion = 2;
|
|
break;
|
|
case GLSL_ES2_IOS:
|
|
case GLSL_ES2_WEBGL:
|
|
case GLSL_ES2:
|
|
case GLSL_ES3_1_ANDROID:
|
|
OutMajorVersion = 0;
|
|
OutMinorVersion = 0;
|
|
break;
|
|
default:
|
|
// Invalid enum
|
|
check(0);
|
|
OutMajorVersion = 0;
|
|
OutMinorVersion = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
static const TCHAR* GetGLSLES2CompilerExecutable(bool bNDACompiler)
|
|
{
|
|
// Unfortunately no env var is set to handle install path
|
|
return (bNDACompiler
|
|
? TEXT("C:\\Imagination\\PowerVR\\GraphicsSDK\\Compilers\\OGLES\\Windows_x86_32\\glslcompiler_sgx543_nda.exe")
|
|
: TEXT("C:\\Imagination\\PowerVR\\GraphicsSDK\\Compilers\\OGLES\\Windows_x86_32\\glslcompiler_sgx543.exe"));
|
|
}
|
|
|
|
static FString CreateGLSLES2CompilerArguments(const FString& ShaderFile, const FString& OutputFile, EHlslShaderFrequency Frequency, bool bNDACompiler)
|
|
{
|
|
const TCHAR* FrequencySwitch = TEXT("");
|
|
switch (Frequency)
|
|
{
|
|
case HSF_PixelShader:
|
|
FrequencySwitch = TEXT(" -f");
|
|
break;
|
|
|
|
case HSF_VertexShader:
|
|
FrequencySwitch = TEXT(" -v");
|
|
break;
|
|
|
|
default:
|
|
return TEXT("");
|
|
}
|
|
|
|
FString Arguments = FString::Printf(TEXT("%s %s %s -profile -perfsim"), *FPaths::GetCleanFilename(ShaderFile), *FPaths::GetCleanFilename(OutputFile), FrequencySwitch);
|
|
|
|
if (bNDACompiler)
|
|
{
|
|
Arguments += " -disasm";
|
|
}
|
|
|
|
return Arguments;
|
|
}
|
|
|
|
static FString CreateCommandLineGLSLES2(const FString& ShaderFile, const FString& OutputFile, GLSLVersion Version, EHlslShaderFrequency Frequency, bool bNDACompiler)
|
|
{
|
|
if (Version != GLSL_ES2 && Version != GLSL_ES2_WEBGL && Version != GLSL_ES2_IOS)
|
|
{
|
|
return TEXT("");
|
|
}
|
|
|
|
FString CmdLine = FString(GetGLSLES2CompilerExecutable(bNDACompiler)) + TEXT(" ") + CreateGLSLES2CompilerArguments(ShaderFile, OutputFile, Frequency, bNDACompiler);
|
|
CmdLine += FString(LINE_TERMINATOR) + TEXT("pause");
|
|
return CmdLine;
|
|
}
|
|
|
|
/** Precompile a glsl shader for ES2. */
|
|
void FOpenGLFrontend::PrecompileGLSLES2(FShaderCompilerOutput& ShaderOutput, const FShaderCompilerInput& ShaderInput, const ANSICHAR* ShaderSource, EHlslShaderFrequency Frequency)
|
|
{
|
|
const TCHAR* CompilerExecutableName = GetGLSLES2CompilerExecutable(false);
|
|
const int32 SourceLen = FCStringAnsi::Strlen(ShaderSource);
|
|
const bool bCompilerExecutableExists = FPaths::FileExists(CompilerExecutableName);
|
|
|
|
// Using the debug info path to write out the files to disk for the PVR shader compiler
|
|
if (ShaderInput.DumpDebugInfoPath != TEXT("") && bCompilerExecutableExists)
|
|
{
|
|
const FString GLSLSourceFile = (ShaderInput.DumpDebugInfoPath / TEXT("GLSLSource.txt"));
|
|
bool bSavedSuccessfully = false;
|
|
|
|
{
|
|
FArchive* Ar = IFileManager::Get().CreateFileWriter(*GLSLSourceFile, FILEWRITE_EvenIfReadOnly);
|
|
|
|
// Save the ansi file to disk so it can be used as input to the PVR shader compiler
|
|
if (Ar)
|
|
{
|
|
bSavedSuccessfully = true;
|
|
|
|
// @todo: Patch the code so that textureCubeLodEXT gets converted to textureCubeLod to workaround PowerVR issues
|
|
const ANSICHAR* VersionString = FCStringAnsi::Strifind(ShaderSource, "#version 100");
|
|
check(VersionString);
|
|
VersionString += 12; // strlen("# version 100");
|
|
Ar->Serialize((void*)ShaderSource, (VersionString - ShaderSource) * sizeof(ANSICHAR));
|
|
const char* PVRWorkaround = "\n#ifndef textureCubeLodEXT\n#define textureCubeLodEXT textureCubeLod\n#endif\n";
|
|
Ar->Serialize((void*)PVRWorkaround, FCStringAnsi::Strlen(PVRWorkaround));
|
|
Ar->Serialize((void*)VersionString, (SourceLen - (VersionString - ShaderSource)) * sizeof(ANSICHAR));
|
|
delete Ar;
|
|
}
|
|
}
|
|
|
|
if (bSavedSuccessfully && ENABLE_IMAGINATION_COMPILER)
|
|
{
|
|
const FString Arguments = CreateGLSLES2CompilerArguments(GLSLSourceFile, TEXT("ASM.txt"), Frequency, false);
|
|
|
|
FString StdOut;
|
|
FString StdErr;
|
|
int32 ReturnCode = 0;
|
|
|
|
// Run the PowerVR shader compiler and wait for completion
|
|
FPlatformProcess::ExecProcess(GetGLSLES2CompilerExecutable(false), *Arguments, &ReturnCode, &StdOut, &StdErr);
|
|
|
|
if (ReturnCode >= 0)
|
|
{
|
|
ShaderOutput.bSucceeded = true;
|
|
ShaderOutput.Target = ShaderInput.Target;
|
|
|
|
BuildShaderOutput(ShaderOutput, ShaderInput, ShaderSource, SourceLen, GLSL_ES2);
|
|
|
|
// Parse the cycle count
|
|
const int32 CycleCountStringLength = FPlatformString::Strlen(TEXT("Cycle count: "));
|
|
const int32 CycleCountIndex = StdOut.Find(TEXT("Cycle count: "));
|
|
|
|
if (CycleCountIndex != INDEX_NONE && CycleCountIndex + CycleCountStringLength < StdOut.Len())
|
|
{
|
|
const int32 CycleCountEndIndex = StdOut.Find(TEXT("\n"), ESearchCase::IgnoreCase, ESearchDir::FromStart, CycleCountIndex + CycleCountStringLength);
|
|
|
|
if (CycleCountEndIndex != INDEX_NONE)
|
|
{
|
|
const FString InstructionSubstring = StdOut.Mid(CycleCountIndex + CycleCountStringLength, CycleCountEndIndex - (CycleCountIndex + CycleCountStringLength));
|
|
ShaderOutput.NumInstructions = FCString::Atoi(*InstructionSubstring);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShaderOutput.bSucceeded = false;
|
|
|
|
FShaderCompilerError* NewError = new(ShaderOutput.Errors) FShaderCompilerError();
|
|
// Print the name of the generated glsl file so we can open it with a double click in the VS.Net output window
|
|
NewError->StrippedErrorMessage = FString::Printf(TEXT("%s \nPVR SDK glsl compiler for SGX543: %s"), *GLSLSourceFile, *StdOut);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShaderOutput.bSucceeded = true;
|
|
ShaderOutput.Target = ShaderInput.Target;
|
|
|
|
BuildShaderOutput(ShaderOutput, ShaderInput, ShaderSource, SourceLen, GLSL_ES2);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ShaderOutput.bSucceeded = true;
|
|
ShaderOutput.Target = ShaderInput.Target;
|
|
|
|
BuildShaderOutput(ShaderOutput, ShaderInput, ShaderSource, SourceLen, GLSL_ES2);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Precompile a GLSL shader.
|
|
* @param ShaderOutput - The precompiled shader.
|
|
* @param ShaderInput - The shader input.
|
|
* @param InPreprocessedShader - The preprocessed source code.
|
|
*/
|
|
void FOpenGLFrontend::PrecompileShader(FShaderCompilerOutput& ShaderOutput, const FShaderCompilerInput& ShaderInput, const ANSICHAR* ShaderSource, GLSLVersion Version, EHlslShaderFrequency Frequency)
|
|
{
|
|
check(ShaderInput.Target.Frequency < SF_NumFrequencies);
|
|
|
|
// Lookup the GL shader type.
|
|
GLenum GLFrequency = GLFrequencyTable[ShaderInput.Target.Frequency];
|
|
if (GLFrequency == GL_NONE)
|
|
{
|
|
ShaderOutput.bSucceeded = false;
|
|
FShaderCompilerError* NewError = new(ShaderOutput.Errors) FShaderCompilerError();
|
|
NewError->StrippedErrorMessage = FString::Printf(TEXT("%s shaders not supported for use in OpenGL."), CrossCompiler::GetFrequencyName((EShaderFrequency)ShaderInput.Target.Frequency));
|
|
return;
|
|
}
|
|
|
|
if (Version == GLSL_ES2 || Version == GLSL_ES2_WEBGL || Version == GLSL_ES2_IOS)
|
|
{
|
|
PrecompileGLSLES2(ShaderOutput, ShaderInput, ShaderSource, Frequency);
|
|
}
|
|
else
|
|
{
|
|
// Create the shader with the preprocessed source code.
|
|
void* ContextPtr;
|
|
void* PrevContextPtr;
|
|
int MajorVersion = 0;
|
|
int MinorVersion = 0;
|
|
ConvertOpenGLVersionFromGLSLVersion(Version, MajorVersion, MinorVersion);
|
|
PlatformInitOpenGL(ContextPtr, PrevContextPtr, MajorVersion, MinorVersion);
|
|
|
|
GLint SourceLen = FCStringAnsi::Strlen(ShaderSource);
|
|
GLuint Shader = glCreateShader(GLFrequency);
|
|
{
|
|
const GLchar* SourcePtr = ShaderSource;
|
|
glShaderSource(Shader, 1, &SourcePtr, &SourceLen);
|
|
}
|
|
|
|
// Compile and get results.
|
|
glCompileShader(Shader);
|
|
{
|
|
GLint CompileStatus;
|
|
glGetShaderiv(Shader, GL_COMPILE_STATUS, &CompileStatus);
|
|
if (CompileStatus == GL_TRUE)
|
|
{
|
|
ShaderOutput.Target = ShaderInput.Target;
|
|
BuildShaderOutput(
|
|
ShaderOutput,
|
|
ShaderInput,
|
|
ShaderSource,
|
|
(int32)SourceLen,
|
|
Version
|
|
);
|
|
}
|
|
else
|
|
{
|
|
GLint LogLength;
|
|
glGetShaderiv(Shader, GL_INFO_LOG_LENGTH, &LogLength);
|
|
if (LogLength > 1)
|
|
{
|
|
TArray<ANSICHAR> RawCompileLog;
|
|
FString CompileLog;
|
|
TArray<FString> LogLines;
|
|
|
|
RawCompileLog.Empty(LogLength);
|
|
RawCompileLog.AddZeroed(LogLength);
|
|
glGetShaderInfoLog(Shader, LogLength, /*OutLength=*/ NULL, RawCompileLog.GetData());
|
|
CompileLog = ANSI_TO_TCHAR(RawCompileLog.GetData());
|
|
CompileLog.ParseIntoArray(LogLines, TEXT("\n"), true);
|
|
|
|
for (int32 Line = 0; Line < LogLines.Num(); ++Line)
|
|
{
|
|
ParseGlslError(ShaderOutput.Errors, LogLines[Line]);
|
|
}
|
|
|
|
if (ShaderOutput.Errors.Num() == 0)
|
|
{
|
|
FShaderCompilerError* NewError = new(ShaderOutput.Errors) FShaderCompilerError();
|
|
NewError->StrippedErrorMessage = FString::Printf(
|
|
TEXT("GLSL source:\n%sGL compile log: %s\n"),
|
|
ANSI_TO_TCHAR(ShaderSource),
|
|
ANSI_TO_TCHAR(RawCompileLog.GetData())
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
FShaderCompilerError* NewError = new(ShaderOutput.Errors) FShaderCompilerError();
|
|
NewError->StrippedErrorMessage = TEXT("Shader compile failed without errors.");
|
|
}
|
|
|
|
ShaderOutput.bSucceeded = false;
|
|
}
|
|
}
|
|
glDeleteShader(Shader);
|
|
PlatformReleaseOpenGL(ContextPtr, PrevContextPtr);
|
|
}
|
|
}
|
|
|
|
/*------------------------------------------------------------------------------
|
|
External interface.
|
|
------------------------------------------------------------------------------*/
|
|
|
|
static FString CreateCrossCompilerBatchFile( const FString& ShaderFile, const FString& OutputFile, const FString& EntryPoint, EHlslShaderFrequency Frequency, GLSLVersion Version, uint32 CCFlags )
|
|
{
|
|
const TCHAR* VersionSwitch = TEXT("");
|
|
switch (Version)
|
|
{
|
|
case GLSL_150:
|
|
case GLSL_150_ES2:
|
|
case GLSL_150_ES3_1:
|
|
case GLSL_150_ES2_NOUB:
|
|
VersionSwitch = TEXT(" -gl3");
|
|
break;
|
|
|
|
case GLSL_150_MAC:
|
|
VersionSwitch = TEXT(" -gl3 -mac");
|
|
break;
|
|
|
|
case GLSL_ES3_1_ANDROID:
|
|
VersionSwitch = TEXT(" -es31");
|
|
break;
|
|
case GLSL_310_ES_EXT:
|
|
VersionSwitch = TEXT(" -es31ext");
|
|
break;
|
|
|
|
case GLSL_430:
|
|
VersionSwitch = TEXT(" -gl4");
|
|
break;
|
|
|
|
case GLSL_ES2:
|
|
case GLSL_ES2_WEBGL:
|
|
case GLSL_ES2_IOS:
|
|
VersionSwitch = TEXT(" -es2");
|
|
break;
|
|
|
|
default:
|
|
return TEXT("");
|
|
}
|
|
|
|
return CrossCompiler::CreateBatchFileContents(ShaderFile, OutputFile, Frequency, EntryPoint, VersionSwitch, CCFlags, TEXT(""));
|
|
}
|
|
|
|
|
|
|
|
void FOpenGLFrontend::SetupPerVersionCompilationEnvironment(GLSLVersion Version, FShaderCompilerDefinitions& AdditionalDefines, EHlslCompileTarget& HlslCompilerTarget)
|
|
{
|
|
switch (Version)
|
|
{
|
|
case GLSL_ES3_1_ANDROID:
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL_ES3_1"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("ES3_1_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelES3_1;
|
|
break;
|
|
|
|
case GLSL_310_ES_EXT:
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL_ES3_1_EXT"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("ESDEFERRED_PROFILE"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("GL4_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelES3_1Ext;
|
|
break;
|
|
|
|
case GLSL_430:
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("GL4_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelSM5;
|
|
break;
|
|
|
|
case GLSL_150:
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("GL3_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelSM4;
|
|
break;
|
|
|
|
case GLSL_150_MAC:
|
|
AdditionalDefines.SetDefine(TEXT("MAC"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("GL3_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelSM4;
|
|
break;
|
|
|
|
case GLSL_ES2_WEBGL:
|
|
AdditionalDefines.SetDefine(TEXT("WEBGL"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL_ES2"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("ES2_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelES2;
|
|
AdditionalDefines.SetDefine(TEXT("row_major"), TEXT(""));
|
|
break;
|
|
|
|
case GLSL_ES2_IOS:
|
|
AdditionalDefines.SetDefine(TEXT("IOS"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL_ES2"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("ES2_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelES2;
|
|
AdditionalDefines.SetDefine(TEXT("row_major"), TEXT(""));
|
|
AdditionalDefines.SetDefine(TEXT("noperspective"), TEXT(""));
|
|
|
|
break;
|
|
|
|
case GLSL_ES2:
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL_ES2"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("ES2_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelES2;
|
|
AdditionalDefines.SetDefine(TEXT("row_major"), TEXT(""));
|
|
break;
|
|
|
|
case GLSL_150_ES2:
|
|
case GLSL_150_ES2_NOUB:
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("ES2_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelSM4;
|
|
AdditionalDefines.SetDefine(TEXT("row_major"), TEXT(""));
|
|
break;
|
|
|
|
case GLSL_150_ES3_1:
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_GLSL"), 1);
|
|
AdditionalDefines.SetDefine(TEXT("ES3_1_PROFILE"), 1);
|
|
HlslCompilerTarget = HCT_FeatureLevelSM4;
|
|
AdditionalDefines.SetDefine(TEXT("row_major"), TEXT(""));
|
|
break;
|
|
|
|
default:
|
|
check(0);
|
|
}
|
|
}
|
|
|
|
uint32 FOpenGLFrontend::GetMaxSamplers(GLSLVersion Version)
|
|
{
|
|
switch (Version)
|
|
{
|
|
// Assume that GL4.3 targets support 32 samplers as we don't currently support separate sampler objects
|
|
case GLSL_430:
|
|
return 32;
|
|
|
|
// mimicing the old GetFeatureLevelMaxTextureSamplers for the rest
|
|
case GLSL_ES2:
|
|
case GLSL_ES2_IOS:
|
|
case GLSL_150_ES2:
|
|
case GLSL_150_ES2_NOUB:
|
|
return 8;
|
|
|
|
case GLSL_ES2_WEBGL:
|
|
// For WebGL 1 and 2, GL_MAX_TEXTURE_IMAGE_UNITS is generally much higher than on old GLES 2 Android
|
|
// devices, but we only know the limit at runtime. Assume a decent desktop default.
|
|
return 32;
|
|
|
|
default:
|
|
return 16;
|
|
}
|
|
}
|
|
|
|
uint32 FOpenGLFrontend::CalculateCrossCompilerFlags(GLSLVersion Version, bool bCompileES2With310, bool bUseFullPrecisionInPS)
|
|
{
|
|
uint32 CCFlags = HLSLCC_NoPreprocess | HLSLCC_PackUniforms | HLSLCC_DX11ClipSpace;
|
|
if (IsES2Platform(Version) && !IsPCES2Platform(Version))
|
|
{
|
|
CCFlags |= HLSLCC_FlattenUniformBuffers | HLSLCC_FlattenUniformBufferStructures;
|
|
// Currently only enabled for ES2, as there are still features to implement for SM4+ (atomics, global store, UAVs, etc)
|
|
CCFlags |= HLSLCC_ApplyCommonSubexpressionElimination;
|
|
}
|
|
|
|
if (bUseFullPrecisionInPS)
|
|
{
|
|
CCFlags |= HLSLCC_UseFullPrecisionInPS;
|
|
}
|
|
|
|
if (bCompileES2With310)
|
|
{
|
|
CCFlags |= HLSLCC_FlattenUniformBuffers | HLSLCC_FlattenUniformBufferStructures;
|
|
}
|
|
|
|
if (Version == GLSL_150_ES2_NOUB)
|
|
{
|
|
CCFlags |= HLSLCC_FlattenUniformBuffers | HLSLCC_FlattenUniformBufferStructures;
|
|
}
|
|
|
|
if (SupportsSeparateShaderObjects(Version))
|
|
{
|
|
CCFlags |= HLSLCC_SeparateShaderObjects;
|
|
}
|
|
|
|
return CCFlags;
|
|
}
|
|
|
|
FGlslCodeBackend* FOpenGLFrontend::CreateBackend(GLSLVersion Version, uint32 CCFlags, EHlslCompileTarget HlslCompilerTarget)
|
|
{
|
|
return new FGlslCodeBackend(CCFlags, HlslCompilerTarget);
|
|
}
|
|
|
|
FGlslLanguageSpec* FOpenGLFrontend::CreateLanguageSpec(GLSLVersion Version)
|
|
{
|
|
#if PLATFORM_HTML5_BROWSER
|
|
// For backwards compatibility when targeting WebGL 2 shaders,
|
|
// generate GLES2/WebGL 1 style shaders but with GLES3/WebGL 2
|
|
// constructs available.
|
|
return new FGlslLanguageSpec(true);
|
|
#else
|
|
return new FGlslLanguageSpec(IsES2Platform(Version) && !IsPCES2Platform(Version));
|
|
#endif
|
|
}
|
|
|
|
/**
|
|
* Compile a shader for OpenGL on Windows.
|
|
* @param Input - The input shader code and environment.
|
|
* @param Output - Contains shader compilation results upon return.
|
|
*/
|
|
void FOpenGLFrontend::CompileShader(const FShaderCompilerInput& Input,FShaderCompilerOutput& Output,const FString& WorkingDirectory, GLSLVersion Version)
|
|
{
|
|
FString PreprocessedShader;
|
|
FShaderCompilerDefinitions AdditionalDefines;
|
|
EHlslCompileTarget HlslCompilerTarget = HCT_InvalidTarget;
|
|
ECompilerFlags PlatformFlowControl = CFLAG_AvoidFlowControl;
|
|
|
|
const bool bCompileES2With310 = (Version == GLSL_ES2 && Input.Environment.CompilerFlags.Contains(CFLAG_FeatureLevelES31));
|
|
if (bCompileES2With310)
|
|
{
|
|
Version = GLSL_310_ES_EXT;
|
|
}
|
|
|
|
// set up compiler env based on version
|
|
SetupPerVersionCompilationEnvironment(Version, AdditionalDefines, HlslCompilerTarget);
|
|
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_HLSLCC"), 1);
|
|
|
|
const bool bDumpDebugInfo = (Input.DumpDebugInfoPath != TEXT("") && IFileManager::Get().DirectoryExists(*Input.DumpDebugInfoPath));
|
|
|
|
if(Input.Environment.CompilerFlags.Contains(CFLAG_AvoidFlowControl) || PlatformFlowControl == CFLAG_AvoidFlowControl)
|
|
{
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_SUPPORTS_ATTRIBUTES"), (uint32)1);
|
|
}
|
|
else
|
|
{
|
|
AdditionalDefines.SetDefine(TEXT("COMPILER_SUPPORTS_ATTRIBUTES"), (uint32)0);
|
|
}
|
|
|
|
const bool bUseFullPrecisionInPS = Input.Environment.CompilerFlags.Contains(CFLAG_UseFullPrecisionInPS);
|
|
if (bUseFullPrecisionInPS)
|
|
{
|
|
AdditionalDefines.SetDefine(TEXT("FORCE_FLOATS"), (uint32)1);
|
|
}
|
|
|
|
auto DoPreprocess = [&]() -> bool
|
|
{
|
|
if (Input.bSkipPreprocessedCache)
|
|
{
|
|
return FFileHelper::LoadFileToString(PreprocessedShader, *Input.SourceFilename);
|
|
}
|
|
else
|
|
{
|
|
return PreprocessShader(PreprocessedShader, Output, Input, AdditionalDefines);
|
|
}
|
|
};
|
|
|
|
if (DoPreprocess())
|
|
{
|
|
char* GlslShaderSource = NULL;
|
|
char* ErrorLog = NULL;
|
|
|
|
const bool bIsSM5 = IsSM5(Version);
|
|
|
|
const EHlslShaderFrequency FrequencyTable[] =
|
|
{
|
|
HSF_VertexShader,
|
|
bIsSM5 ? HSF_HullShader : HSF_InvalidFrequency,
|
|
bIsSM5 ? HSF_DomainShader : HSF_InvalidFrequency,
|
|
HSF_PixelShader,
|
|
IsES2Platform(Version) ? HSF_InvalidFrequency : HSF_GeometryShader,
|
|
bIsSM5 ? HSF_ComputeShader : HSF_InvalidFrequency
|
|
};
|
|
|
|
const EHlslShaderFrequency Frequency = FrequencyTable[Input.Target.Frequency];
|
|
if (Frequency == HSF_InvalidFrequency)
|
|
{
|
|
Output.bSucceeded = false;
|
|
FShaderCompilerError* NewError = new(Output.Errors) FShaderCompilerError();
|
|
NewError->StrippedErrorMessage = FString::Printf(
|
|
TEXT("%s shaders not supported for use in OpenGL."),
|
|
CrossCompiler::GetFrequencyName((EShaderFrequency)Input.Target.Frequency)
|
|
);
|
|
return;
|
|
}
|
|
|
|
// This requires removing the HLSLCC_NoPreprocess flag later on!
|
|
if (!RemoveUniformBuffersFromSource(PreprocessedShader))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Write out the preprocessed file and a batch file to compile it if requested (DumpDebugInfoPath is valid)
|
|
if (bDumpDebugInfo)
|
|
{
|
|
FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*(Input.DumpDebugInfoPath / Input.SourceFilename + TEXT(".usf")));
|
|
if (FileWriter)
|
|
{
|
|
auto AnsiSourceFile = StringCast<ANSICHAR>(*PreprocessedShader);
|
|
FileWriter->Serialize((ANSICHAR*)AnsiSourceFile.Get(), AnsiSourceFile.Length());
|
|
FileWriter->Close();
|
|
delete FileWriter;
|
|
}
|
|
|
|
if (Input.bGenerateDirectCompileFile)
|
|
{
|
|
FFileHelper::SaveStringToFile(CreateShaderCompilerWorkerDirectCommandLine(Input), *(Input.DumpDebugInfoPath / TEXT("DirectCompile.txt")));
|
|
}
|
|
}
|
|
|
|
uint32 CCFlags = CalculateCrossCompilerFlags(Version, bCompileES2With310, bUseFullPrecisionInPS);
|
|
|
|
if (bDumpDebugInfo)
|
|
{
|
|
const FString GLSLFile = (Input.DumpDebugInfoPath / TEXT("Output.glsl"));
|
|
const FString USFFile = (Input.DumpDebugInfoPath / Input.SourceFilename) + TEXT(".usf");
|
|
const FString CCBatchFileContents = CreateCrossCompilerBatchFile(USFFile, GLSLFile, *Input.EntryPointName, Frequency, Version, CCFlags);
|
|
if (!CCBatchFileContents.IsEmpty())
|
|
{
|
|
const TCHAR * ScriptName = PLATFORM_WINDOWS ? TEXT("CrossCompile.bat") : TEXT("CrossCompile.sh");
|
|
FFileHelper::SaveStringToFile(CCBatchFileContents, *(Input.DumpDebugInfoPath / ScriptName));
|
|
}
|
|
}
|
|
|
|
// Required as we added the RemoveUniformBuffersFromSource() function (the cross-compiler won't be able to interpret comments w/o a preprocessor)
|
|
CCFlags &= ~HLSLCC_NoPreprocess;
|
|
|
|
FGlslCodeBackend* BackEnd = CreateBackend(Version, CCFlags, HlslCompilerTarget);
|
|
FGlslLanguageSpec* LanguageSpec = CreateLanguageSpec(Version);
|
|
|
|
int32 Result = 0;
|
|
FHlslCrossCompilerContext CrossCompilerContext(CCFlags, Frequency, HlslCompilerTarget);
|
|
if (CrossCompilerContext.Init(TCHAR_TO_ANSI(*Input.SourceFilename), LanguageSpec))
|
|
{
|
|
Result = CrossCompilerContext.Run(
|
|
TCHAR_TO_ANSI(*PreprocessedShader),
|
|
TCHAR_TO_ANSI(*Input.EntryPointName),
|
|
BackEnd,
|
|
&GlslShaderSource,
|
|
&ErrorLog
|
|
) ? 1 : 0;
|
|
}
|
|
|
|
delete BackEnd;
|
|
delete LanguageSpec;
|
|
|
|
if (Result != 0)
|
|
{
|
|
int32 GlslSourceLen = GlslShaderSource ? FCStringAnsi::Strlen(GlslShaderSource) : 0;
|
|
if (bDumpDebugInfo)
|
|
{
|
|
const FString GLSLFile = (Input.DumpDebugInfoPath / TEXT("Output.glsl"));
|
|
const FString GLBatchFileContents = CreateCommandLineGLSLES2(GLSLFile, (Input.DumpDebugInfoPath / TEXT("Output.asm")), Version, Frequency, false);
|
|
if (!GLBatchFileContents.IsEmpty())
|
|
{
|
|
FFileHelper::SaveStringToFile(GLBatchFileContents, *(Input.DumpDebugInfoPath / TEXT("GLSLCompile.bat")));
|
|
}
|
|
|
|
const FString NDABatchFileContents = CreateCommandLineGLSLES2(GLSLFile, (Input.DumpDebugInfoPath / TEXT("Output.asm")), Version, Frequency, true);
|
|
if (!NDABatchFileContents.IsEmpty())
|
|
{
|
|
FFileHelper::SaveStringToFile(NDABatchFileContents, *(Input.DumpDebugInfoPath / TEXT("NDAGLSLCompile.bat")));
|
|
}
|
|
|
|
if (GlslSourceLen > 0)
|
|
{
|
|
uint32 Len = FCStringAnsi::Strlen(TCHAR_TO_ANSI(*Input.SourceFilename)) + FCStringAnsi::Strlen(TCHAR_TO_ANSI(*Input.EntryPointName)) + FCStringAnsi::Strlen(GlslShaderSource) + 20;
|
|
char* Dest = (char*)malloc(Len);
|
|
FCStringAnsi::Snprintf(Dest, Len, "// ! %s.usf:%s\n%s", (const char*)TCHAR_TO_ANSI(*Input.SourceFilename), (const char*)TCHAR_TO_ANSI(*Input.EntryPointName), (const char*)GlslShaderSource);
|
|
free(GlslShaderSource);
|
|
GlslShaderSource = Dest;
|
|
GlslSourceLen = FCStringAnsi::Strlen(GlslShaderSource);
|
|
|
|
FArchive* FileWriter = IFileManager::Get().CreateFileWriter(*(Input.DumpDebugInfoPath / Input.SourceFilename + TEXT(".glsl")));
|
|
if (FileWriter)
|
|
{
|
|
FileWriter->Serialize(GlslShaderSource,GlslSourceLen+1);
|
|
FileWriter->Close();
|
|
delete FileWriter;
|
|
}
|
|
}
|
|
}
|
|
|
|
#if VALIDATE_GLSL_WITH_DRIVER
|
|
PrecompileShader(Output, Input, GlslShaderSource, Version, Frequency);
|
|
#else // VALIDATE_GLSL_WITH_DRIVER
|
|
int32 SourceLen = FCStringAnsi::Strlen(GlslShaderSource);
|
|
Output.Target = Input.Target;
|
|
BuildShaderOutput(Output, Input, GlslShaderSource, SourceLen, Version);
|
|
#endif // VALIDATE_GLSL_WITH_DRIVER
|
|
}
|
|
else
|
|
{
|
|
if (bDumpDebugInfo)
|
|
{
|
|
// Generate the batch file to help track down cross-compiler issues if necessary
|
|
const FString GLSLFile = (Input.DumpDebugInfoPath / TEXT("Output.glsl"));
|
|
const FString GLBatchFileContents = CreateCommandLineGLSLES2(GLSLFile, (Input.DumpDebugInfoPath / TEXT("Output.asm")), Version, Frequency, false);
|
|
if (!GLBatchFileContents.IsEmpty())
|
|
{
|
|
FFileHelper::SaveStringToFile(GLBatchFileContents, *(Input.DumpDebugInfoPath / TEXT("GLSLCompile.bat")));
|
|
}
|
|
}
|
|
|
|
FString Tmp = ANSI_TO_TCHAR(ErrorLog);
|
|
TArray<FString> ErrorLines;
|
|
Tmp.ParseIntoArray(ErrorLines, TEXT("\n"), true);
|
|
for (int32 LineIndex = 0; LineIndex < ErrorLines.Num(); ++LineIndex)
|
|
{
|
|
const FString& Line = ErrorLines[LineIndex];
|
|
CrossCompiler::ParseHlslccError(Output.Errors, Line);
|
|
}
|
|
}
|
|
|
|
if (GlslShaderSource)
|
|
{
|
|
free(GlslShaderSource);
|
|
}
|
|
if (ErrorLog)
|
|
{
|
|
free(ErrorLog);
|
|
}
|
|
}
|
|
}
|