22
1

h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

  • Upload
    vanminh

  • View
    217

  • Download
    2

Embed Size (px)

Citation preview

Page 1: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

1  

Page 2: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

2  

Page 3: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528  

h%ps://twi%er.com/tom_forsyth/status/628751206492569601  

h%ps://twi%er.com/Tojiro/status/628664374408839169  

3  

Page 4: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

4  

Page 5: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

5  

Page 6: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

GfxDevice  (our  “graphics  plaMorm  abstracOon”)  implementaOon  sizes  in  Unity  right  now  (~5.3),  so  not  reflecOng  the  “iniOal  port”  state.  

OpenGL  +  ES  727kb  (does  all  GL/ES  versions,  and  this  includes  all  the  func8ons/extensions  loading  code)    

D3D11  474kb  (quite  some  related  to  WSA/WP8,  and  DX11  bytecode  massaging)  

D3D12  364kb  D3D9  231kb  Legacy  GL  231kb  (dekstop  GL  2.0-­‐2.1,  will  go  away  soon)    

Metal  132kb  

6  

Page 7: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

7  

Page 8: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

Our  current  messy  pipeline:  

•   HLSL  is  the  source  language    •   We  also  do  some  code  analysis  /  generaOon  (Unity  surface  shaders);  that  is  a  combinaOon  of  Cg  2.2  and  MojoShader.    

•   D3D9/11/12:  use  d3dcompiler_xx.dll    

•   GL2,  GLES2:  HLSL  -­‐>  (hlsl2glslfork)  -­‐>  GLSL  -­‐>  (glsl-­‐opOmizer)  -­‐>  GLSL    

•   GL3/4,  GLES3:  HLSL  -­‐>  (hlslcc)  -­‐>  GLSL    •   Metal:  HLSL  -­‐>  (hlsl2glslfork)  -­‐>  GLSL  -­‐>  (glsl-­‐opOmizer)  -­‐>  MetalSL    

•   Vulkan:  ???    

8  

Page 9: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

HLSL  is  not  ideal  shading  /  compute  language,  but  there’s  massive,  massive  amount  of  shader  code  wri%en  in  it  already.  

We’d  want  that  to  conOnue  working  :)  

Eventually  we’d  want  to  move  towards  something  like  MetalSL,  where  it’s  basically  a  C/C++  subset  (no  virtuals,  no  excep8ons  etc.),  but  extended  for  GPU  specific  things  with  various  annotaOons.  

9  

Page 10: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

10  

Page 11: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

11  

Page 12: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

12  

Page 13: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

13  

Page 14: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

14  

Page 15: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

15  

Page 16: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

16  

Page 17: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

17  

Page 18: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

18  

Page 19: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

19  

Page 20: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

20  

Page 21: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

Current  situaOon  (Unity  5.2  beta)  is  that  we  did  not  do  big  higher  level  changes  to  the  engine  code  yet.  i.e.  the  graphics  abstracOon  is  sOll  somewhere  between  “DX9  and  DX11  level”;  with  quite  many  decisions  done  late.  No  efficient  representaOon  of  constant  buffers,  no  efficient  representaOon  of  shader  binding  tables  that  never  change,  etc.  

Also,  all  the  command  buffer  creaOon  is  sOll  done  from  one  thread  (the  “main  thread  vs  render  thread”  split,  but  not  “all  cores  can  create  command  buffers”).  

This  is  somewhat  different  from  DX11,  where  even  to  the  app  it  looks  like  everything  is  on  one  thread,  most  (all?)  drivers  internally  will  create  addiOonal  threads  to  offload  some  of  the  “driver  work”  that  they  have  to  do.  It’s  possible  to  prevent  this  with  D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS  device  creaOon  flag,  which  is  what  the  “DX11NT”  (“no  driver  threads”)  column  represents.  

The  numbers  are  from  two  different  benchmark  scenes  we  have  (one  mostly  staOc;  another  where  a  lot  of  materials  animate  their  parameters).  Tests  were  done  on  3  PCs  with  different  hardware  configuraOons.  

21  

Page 22: h%ps://twi…aras-p.info/texts/files/201508-SIGGRAPH-PortingUnityToNewAPIs.pdf · h%ps://twi%er.com/TimSweeneyEpic/status/628713913094422528" h%ps://twi%er.com/tom_forsyth/status/628751206492569601"

QuesOon  you  might  have:  is  all  this  trouble  worth  it?  So  far  we’re  not  taking  advantage  of  the  new  APIs  to  full  extent  yet,  however  just  by  trying  to  make  it  be%er  we’ve  already  been  able  to  improve  quite  a  lot  of  things.  For  example,  part  of  cleanups  &  general  opOmizaOons  realdy  done  in  Unity  5.2:    

h%p://aras-­‐p.info/blog/2015/04/01/opOmizing-­‐unity-­‐renderer-­‐1-­‐intro/    

h%p://aras-­‐p.info/blog/2015/04/04/opOmizing-­‐unity-­‐renderer-­‐2-­‐cleanups/  

h%p://aras-­‐p.info/blog/2015/04/27/opOmizing-­‐unity-­‐renderer-­‐3-­‐fixed-­‐funcOon-­‐removal/  

…and  a  bit  more  that  I  haven’t  blogged  about  (yet?)  

22