gfx.odin 198 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262
  1. // machine generated, do not edit
  2. package sokol_gfx
  3. /*
  4. sokol_gfx.h -- simple 3D API wrapper
  5. Project URL: https://github.com/floooh/sokol
  6. Example code: https://github.com/floooh/sokol-samples
  7. Do this:
  8. #define SOKOL_IMPL or
  9. #define SOKOL_GFX_IMPL
  10. before you include this file in *one* C or C++ file to create the
  11. implementation.
  12. In the same place define one of the following to select the rendering
  13. backend:
  14. #define SOKOL_GLCORE
  15. #define SOKOL_GLES3
  16. #define SOKOL_D3D11
  17. #define SOKOL_METAL
  18. #define SOKOL_WGPU
  19. #define SOKOL_VULKAN
  20. #define SOKOL_DUMMY_BACKEND
  21. I.e. for the desktop GL it should look like this:
  22. #include ...
  23. #include ...
  24. #define SOKOL_IMPL
  25. #define SOKOL_GLCORE
  26. #include "sokol_gfx.h"
  27. The dummy backend replaces the platform-specific backend code with empty
  28. stub functions. This is useful for writing tests that need to run on the
  29. command line.
  30. Optionally provide the following defines with your own implementations:
  31. SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
  32. SOKOL_UNREACHABLE() - a guard macro for unreachable code (default: assert(false))
  33. SOKOL_GFX_API_DECL - public function declaration prefix (default: extern)
  34. SOKOL_API_DECL - same as SOKOL_GFX_API_DECL
  35. SOKOL_API_IMPL - public function implementation prefix (default: -)
  36. SOKOL_TRACE_HOOKS - enable trace hook callbacks (search below for TRACE HOOKS)
  37. SOKOL_EXTERNAL_GL_LOADER - indicates that you're using your own GL loader, in this case
  38. sokol_gfx.h will not include any platform GL headers and disable
  39. the integrated Win32 GL loader
  40. If sokol_gfx.h is compiled as a DLL, define the following before
  41. including the declaration or implementation:
  42. SOKOL_DLL
  43. On Windows, SOKOL_DLL will define SOKOL_GFX_API_DECL as __declspec(dllexport)
  44. or __declspec(dllimport) as needed.
  45. Optionally define the following to force debug checks and validations
  46. even in release mode:
  47. SOKOL_DEBUG - by default this is defined if NDEBUG is not defined
  48. Link with the following system libraries (note that sokol_app.h has
  49. additional linker requirements):
  50. - on macOS/iOS with Metal: Metal
  51. - on macOS with GL: OpenGL
  52. - on iOS with GL: OpenGLES
  53. - on Linux with EGL: GL or GLESv2
  54. - on Linux with GLX: GL
  55. - on Android: GLESv3, log, android
  56. - on Windows with the MSVC or Clang toolchains: no action needed, libs are defined in-source via pragma-comment-lib
  57. - on Windows with MINGW/MSYS2 gcc: compile with '-mwin32' so that _WIN32 is defined
  58. - with the D3D11 backend: -ld3d11
  59. On macOS and iOS, the implementation must be compiled as Objective-C.
  60. On Emscripten:
  61. - for WebGL2: add the linker option `-s USE_WEBGL2=1`
  62. - for WebGPU: compile and link with `--use-port=emdawnwebgpu`
  63. (for more exotic situations, read: https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/pkg/README.md)
  64. sokol_gfx DOES NOT:
  65. ===================
  66. - create a window, swapchain or the 3D-API context/device, you must do this
  67. before sokol_gfx is initialized, and pass any required information
  68. (like 3D device pointers) to the sokol_gfx initialization call
  69. - present the rendered frame, how this is done exactly usually depends
  70. on how the window and 3D-API context/device was created
  71. - provide a unified shader language, instead 3D-API-specific shader
  72. source-code or shader-bytecode must be provided (for the "official"
  73. offline shader cross-compiler / code-generator, see here:
  74. https://github.com/floooh/sokol-tools/blob/master/docs/sokol-shdc.md)
  75. STEP BY STEP
  76. ============
  77. --- to initialize sokol_gfx, after creating a window and a 3D-API
  78. context/device, call:
  79. sg_setup(const sg_desc*)
  80. Depending on the selected 3D backend, sokol-gfx requires some
  81. information about its runtime environment, like a GPU device pointer,
  82. default swapchain pixel formats and so on. If you are using sokol_app.h
  83. for the window system glue, you can use a helper function provided in
  84. the sokol_glue.h header:
  85. #include "sokol_gfx.h"
  86. #include "sokol_app.h"
  87. #include "sokol_glue.h"
  88. //...
  89. sg_setup(&(sg_desc){
  90. .environment = sglue_environment(),
  91. });
  92. To get any logging output for errors and from the validation layer, you
  93. need to provide a logging callback. Easiest way is through sokol_log.h:
  94. #include "sokol_log.h"
  95. //...
  96. sg_setup(&(sg_desc){
  97. //...
  98. .logger.func = slog_func,
  99. });
  100. --- create resource objects (buffers, images, views, samplers, shaders
  101. and pipeline objects)
  102. sg_buffer sg_make_buffer(const sg_buffer_desc*)
  103. sg_image sg_make_image(const sg_image_desc*)
  104. sg_view sg_make_view(const sg_view_desc*)
  105. sg_sampler sg_make_sampler(const sg_sampler_desc*)
  106. sg_shader sg_make_shader(const sg_shader_desc*)
  107. sg_pipeline sg_make_pipeline(const sg_pipeline_desc*)
  108. --- start a render- or compute-pass:
  109. sg_begin_pass(const sg_pass* pass);
  110. Typically, render passes render into an externally provided swapchain which
  111. presents the rendering result on the display. Such a 'swapchain pass'
  112. is started like this:
  113. sg_begin_pass(&(sg_pass){ .action = { ... }, .swapchain = sglue_swapchain() })
  114. ...where .action is an sg_pass_action struct containing actions to be performed
  115. at the start and end of a render pass (such as clearing the render surfaces to
  116. a specific color), and .swapchain is an sg_swapchain struct with all the required
  117. information to render into the swapchain's surfaces.
  118. To start an 'offscreen render pass' into sokol-gfx image objects, populate
  119. the sg_pass.attachments nested struct with attachment view objects
  120. (1..4 color-attachment-views for to render into, a depth-stencil-attachment-view
  121. to provide the depth-stencil-buffer, and optionally 1..4 resolve-attachment-views
  122. for an MSAA-resolve operation:
  123. sg_begin_pass(&(sg_pass){
  124. .action = { ... },
  125. .attachments = {
  126. .colors[0] = color_attachment_view,
  127. .resolves[0] = optional_resolve_attachment_view,
  128. .depth_stencil = depth_stencil_attachment_view,
  129. },
  130. });
  131. To start a compute-pass, just set the .compute item to true:
  132. sg_begin_pass(&(sg_pass){ .compute = true });
  133. --- set the pipeline state for the next draw call with:
  134. sg_apply_pipeline(sg_pipeline pip)
  135. --- fill an sg_bindings struct with the resource bindings for the next
  136. draw- or dispatch-call (0..N vertex buffers, 0 or 1 index buffer, 0..N views,
  137. 0..N samplers), and call
  138. sg_apply_bindings(const sg_bindings* bindings)
  139. ...to update the resource bindings. Note that in a compute pass, no vertex-
  140. or index-buffer bindings can be used, and in render passes, no storage-image bindings
  141. are allowed. Those restrictions will be checked by the sokol-gfx validation layer.
  142. --- optionally update shader uniform data with:
  143. sg_apply_uniforms(int ub_slot, const sg_range* data)
  144. Read the section 'UNIFORM DATA LAYOUT' to learn about the expected memory layout
  145. of the uniform data passed into sg_apply_uniforms().
  146. --- kick off a draw call with:
  147. sg_draw(int base_element, int num_elements, int num_instances)
  148. The sg_draw() function unifies all the different ways to render primitives
  149. in a single call (indexed vs non-indexed rendering, and instanced vs non-instanced
  150. rendering). In case of indexed rendering, base_element and num_element specify
  151. indices in the currently bound index buffer. In case of non-indexed rendering
  152. base_element and num_elements specify vertices in the currently bound
  153. vertex-buffer(s). To perform instanced rendering, the rendering pipeline
  154. must be setup for instancing (see sg_pipeline_desc below), a separate vertex buffer
  155. containing per-instance data must be bound, and the num_instances parameter
  156. must be > 1.
  157. Alternatively, call:
  158. sg_draw_ex(...)
  159. to provide a base-vertex and/or base-instance which allows to render
  160. from different sections of a vertex buffer without rebinding the
  161. vertex buffer with a different offset. Note that the `sg_draw_ex()`
  162. only has limited portability on OpenGL, check the sg_limits struct
  163. members .draw_base_vertex and .draw_base_instance for runtime support,
  164. those are generally true on non-GL-backends, and on GL the feature
  165. flags are set according to the GL version:
  166. - on GL base_instance != 0 is only supported since GL 4.2
  167. - on GLES3.x, base_instance != 0 is not supported
  168. - on GLES3.x, base_vertex is only supported since GLES3.2
  169. (e.g. not supported on WebGL2)
  170. --- ...or kick of a dispatch call to invoke a compute shader workload:
  171. sg_dispatch(int num_groups_x, int num_groups_y, int num_groups_z)
  172. The dispatch args define the number of 'compute workgroups' processed
  173. by the currently applied compute shader.
  174. --- finish the current pass with:
  175. sg_end_pass()
  176. --- when done with the current frame, call
  177. sg_commit()
  178. --- at the end of your program, shutdown sokol_gfx with:
  179. sg_shutdown()
  180. --- if you need to destroy resources before sg_shutdown(), call:
  181. sg_destroy_buffer(sg_buffer buf)
  182. sg_destroy_image(sg_image img)
  183. sg_destroy_sampler(sg_sampler smp)
  184. sg_destroy_shader(sg_shader shd)
  185. sg_destroy_pipeline(sg_pipeline pip)
  186. sg_destroy_view(sg_view view)
  187. --- to set a new viewport rectangle, call:
  188. sg_apply_viewport(int x, int y, int width, int height, bool origin_top_left)
  189. ...or if you want to specify the viewport rectangle with float values:
  190. sg_apply_viewportf(float x, float y, float width, float height, bool origin_top_left)
  191. --- to set a new scissor rect, call:
  192. sg_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left)
  193. ...or with float values:
  194. sg_apply_scissor_rectf(float x, float y, float width, float height, bool origin_top_left)
  195. Both sg_apply_viewport() and sg_apply_scissor_rect() must be called
  196. inside a rendering pass (e.g. not in a compute pass, or outside a pass)
  197. Note that sg_begin_pass() will reset both the viewport and scissor
  198. rectangles to cover the entire framebuffer.
  199. --- to update (overwrite) the content of buffer and image resources, call:
  200. sg_update_buffer(sg_buffer buf, const sg_range* data)
  201. sg_update_image(sg_image img, const sg_image_data* data)
  202. Buffers and images to be updated must have been created with
  203. sg_buffer_desc.usage.dynamic_update or .stream_update.
  204. Only one update per frame is allowed for buffer and image resources when
  205. using the sg_update_*() functions. The rationale is to have a simple
  206. protection from the CPU scribbling over data the GPU is currently
  207. using, or the CPU having to wait for the GPU
  208. Buffer and image updates can be partial, as long as a rendering
  209. operation only references the valid (updated) data in the
  210. buffer or image.
  211. --- to append a chunk of data to a buffer resource, call:
  212. int sg_append_buffer(sg_buffer buf, const sg_range* data)
  213. The difference to sg_update_buffer() is that sg_append_buffer()
  214. can be called multiple times per frame to append new data to the
  215. buffer piece by piece, optionally interleaved with draw calls referencing
  216. the previously written data.
  217. sg_append_buffer() returns a byte offset to the start of the
  218. written data, this offset can be assigned to
  219. sg_bindings.vertex_buffer_offsets[n] or
  220. sg_bindings.index_buffer_offset
  221. Code example:
  222. for (...) {
  223. const void* data = ...;
  224. const int num_bytes = ...;
  225. int offset = sg_append_buffer(buf, &(sg_range) { .ptr=data, .size=num_bytes });
  226. bindings.vertex_buffer_offsets[0] = offset;
  227. sg_apply_pipeline(pip);
  228. sg_apply_bindings(&bindings);
  229. sg_apply_uniforms(...);
  230. sg_draw(...);
  231. }
  232. A buffer to be used with sg_append_buffer() must have been created
  233. with sg_buffer_desc.usage.dynamic_update or .stream_update.
  234. If the application appends more data to the buffer then fits into
  235. the buffer, the buffer will go into the "overflow" state for the
  236. rest of the frame.
  237. Any draw calls attempting to render an overflown buffer will be
  238. silently dropped (in debug mode this will also result in a
  239. validation error).
  240. You can also check manually if a buffer is in overflow-state by calling
  241. bool sg_query_buffer_overflow(sg_buffer buf)
  242. You can manually check to see if an overflow would occur before adding
  243. any data to a buffer by calling
  244. bool sg_query_buffer_will_overflow(sg_buffer buf, size_t size)
  245. NOTE: Due to restrictions in underlying 3D-APIs, appended chunks of
  246. data will be 4-byte aligned in the destination buffer. This means
  247. that there will be gaps in index buffers containing 16-bit indices
  248. when the number of indices in a call to sg_append_buffer() is
  249. odd. This isn't a problem when each call to sg_append_buffer()
  250. is associated with one draw call, but will be problematic when
  251. a single indexed draw call spans several appended chunks of indices.
  252. --- to check at runtime for optional features, limits and pixelformat support,
  253. call:
  254. sg_features sg_query_features()
  255. sg_limits sg_query_limits()
  256. sg_pixelformat_info sg_query_pixelformat(sg_pixel_format fmt)
  257. --- if you need to call into the underlying 3D-API directly, you must call:
  258. sg_reset_state_cache()
  259. ...before calling sokol_gfx functions again
  260. --- you can inspect the original sg_desc structure handed to sg_setup()
  261. by calling sg_query_desc(). This will return an sg_desc struct with
  262. the default values patched in instead of any zero-initialized values
  263. --- you can get a desc struct matching the creation attributes of a
  264. specific resource object via:
  265. sg_buffer_desc sg_query_buffer_desc(sg_buffer buf)
  266. sg_image_desc sg_query_image_desc(sg_image img)
  267. sg_sampler_desc sg_query_sampler_desc(sg_sampler smp)
  268. sg_shader_desc sq_query_shader_desc(sg_shader shd)
  269. sg_pipeline_desc sg_query_pipeline_desc(sg_pipeline pip)
  270. sg_view_desc sg_query_view_desc(sg_view view)
  271. ...but NOTE that the returned desc structs may be incomplete, only
  272. creation attributes that are kept around internally after resource
  273. creation will be filled in, and in some cases (like shaders) that's
  274. very little. Any missing attributes will be set to zero. The returned
  275. desc structs might still be useful as partial blueprint for creating
  276. similar resources if filled up with the missing attributes.
  277. Calling the query-desc functions on an invalid resource will return
  278. completely zeroed structs (it makes sense to check the resource state
  279. with sg_query_*_state() first)
  280. --- you can query the default resource creation parameters through the functions
  281. sg_buffer_desc sg_query_buffer_defaults(const sg_buffer_desc* desc)
  282. sg_image_desc sg_query_image_defaults(const sg_image_desc* desc)
  283. sg_sampler_desc sg_query_sampler_defaults(const sg_sampler_desc* desc)
  284. sg_shader_desc sg_query_shader_defaults(const sg_shader_desc* desc)
  285. sg_pipeline_desc sg_query_pipeline_defaults(const sg_pipeline_desc* desc)
  286. sg_view_desc sg_query_view_defaults(const sg_view_desc* desc)
  287. These functions take a pointer to a desc structure which may contain
  288. zero-initialized items for default values. These zero-init values
  289. will be replaced with their concrete values in the returned desc
  290. struct.
  291. --- you can inspect various internal resource runtime values via:
  292. sg_buffer_info sg_query_buffer_info(sg_buffer buf)
  293. sg_image_info sg_query_image_info(sg_image img)
  294. sg_sampler_info sg_query_sampler_info(sg_sampler smp)
  295. sg_shader_info sg_query_shader_info(sg_shader shd)
  296. sg_pipeline_info sg_query_pipeline_info(sg_pipeline pip)
  297. sg_view_info sg_query_view_info(sg_view view)
  298. ...please note that the returned info-structs are tied quite closely
  299. to sokol_gfx.h internals, and may change more often than other
  300. public API functions and structs.
  301. -- you can query the type/flavour and parent resource of a view:
  302. sg_view_type sg_query_view_type(sg_view view)
  303. sg_image sg_query_view_image(sg_view view)
  304. sg_buffer sg_query_view_buffer(sg_view view)
  305. --- you can query stats and control stats collection via:
  306. sg_query_stats()
  307. sg_enable_stats()
  308. sg_disable_stats()
  309. sg_stats_enabled()
  310. --- you can ask at runtime what backend sokol_gfx.h has been compiled for:
  311. sg_backend sg_query_backend(void)
  312. --- call the following helper functions to compute the number of
  313. bytes in a texture row or surface for a specific pixel format.
  314. These functions might be helpful when preparing image data for consumption
  315. by sg_make_image() or sg_update_image():
  316. int sg_query_row_pitch(sg_pixel_format fmt, int width, int int row_align_bytes);
  317. int sg_query_surface_pitch(sg_pixel_format fmt, int width, int height, int row_align_bytes);
  318. Width and height are generally in number pixels, but note that 'row' has different meaning
  319. for uncompressed vs compressed pixel formats: for uncompressed formats, a row is identical
  320. with a single line if pixels, while in compressed formats, one row is a line of *compression blocks*.
  321. This is why calling sg_query_surface_pitch() for a compressed pixel format and height
  322. N, N+1, N+2, ... may return the same result.
  323. The row_align_bytes parameter is for added flexibility. For image data that goes into
  324. the sg_make_image() or sg_update_image() this should generally be 1, because these
  325. functions take tightly packed image data as input no matter what alignment restrictions
  326. exist in the backend 3D APIs.
  327. ON INITIALIZATION:
  328. ==================
  329. When calling sg_setup(), a pointer to an sg_desc struct must be provided
  330. which contains initialization options. These options provide two types
  331. of information to sokol-gfx:
  332. (1) upper bounds and limits needed to allocate various internal
  333. data structures:
  334. - the max number of resources of each type that can
  335. be alive at the same time, this is used for allocating
  336. internal pools
  337. - the max overall size of uniform data that can be
  338. updated per frame, including a worst-case alignment
  339. per uniform update (this worst-case alignment is 256 bytes)
  340. - the max size of all dynamic resource updates (sg_update_buffer,
  341. sg_append_buffer and sg_update_image) per frame
  342. - the max number of compute-dispatch calls in a compute pass
  343. Not all of those limit values are used by all backends, but it is
  344. good practice to provide them none-the-less.
  345. (2) 3D backend "environment information" in a nested sg_environment struct:
  346. - pointers to backend-specific context- or device-objects (for instance
  347. the D3D11, WebGPU or Metal device objects)
  348. - defaults for external swapchain pixel formats and sample counts,
  349. these will be used as default values in image and pipeline objects,
  350. and the sg_swapchain struct passed into sg_begin_pass()
  351. Usually you provide a complete sg_environment struct through
  352. a helper function, as an example look at the sglue_environment()
  353. function in the sokol_glue.h header.
  354. See the documentation block of the sg_desc struct below for more information.
  355. ON RENDER PASSES
  356. ================
  357. Relevant samples:
  358. - https://floooh.github.io/sokol-html5/offscreen-sapp.html
  359. - https://floooh.github.io/sokol-html5/offscreen-msaa-sapp.html
  360. - https://floooh.github.io/sokol-html5/mrt-sapp.html
  361. - https://floooh.github.io/sokol-html5/mrt-pixelformats-sapp.html
  362. A render pass groups rendering commands into a set of render target images
  363. (called 'render pass attachments'). Render target images can be used in subsequent
  364. passes as textures (it is invalid to use the same image both as render target
  365. and as texture in the same pass).
  366. The following sokol-gfx functions must only be called inside a render-pass:
  367. sg_apply_viewport[f]
  368. sg_apply_scissor_rect[f]
  369. sg_draw
  370. The following function may be called inside a render- or compute-pass, but
  371. not outside a pass:
  372. sg_apply_pipeline
  373. sg_apply_bindings
  374. sg_apply_uniforms
  375. A frame must have at least one 'swapchain render pass' which renders into an
  376. externally provided swapchain provided as an sg_swapchain struct to the
  377. sg_begin_pass() function. If you use sokol_gfx.h together with sokol_app.h,
  378. just call the sglue_swapchain() helper function in sokol_glue.h to
  379. provide the swapchain information. Otherwise the following information
  380. must be provided:
  381. - the color pixel-format of the swapchain's render surface
  382. - an optional depth/stencil pixel format if the swapchain
  383. has a depth/stencil buffer
  384. - an optional sample-count for MSAA rendering
  385. - NOTE: the above three values can be zero-initialized, in that
  386. case the defaults from the sg_environment struct will be used that
  387. had been passed to the sg_setup() function.
  388. - a number of backend specific objects:
  389. - GL/GLES3: just a GL framebuffer handle
  390. - D3D11:
  391. - an ID3D11RenderTargetView for the rendering surface
  392. - if MSAA is used, an ID3D11RenderTargetView as
  393. MSAA resolve-target
  394. - an optional ID3D11DepthStencilView for the
  395. depth/stencil buffer
  396. - WebGPU
  397. - a WGPUTextureView object for the rendering surface
  398. - if MSAA is used, a WGPUTextureView object as MSAA resolve target
  399. - an optional WGPUTextureView for the
  400. - Metal (NOTE that the roles of provided surfaces is slightly
  401. different in Metal than in D3D11 or WebGPU, notably, the
  402. CAMetalDrawable is either rendered to directly, or serves
  403. as MSAA resolve target):
  404. - a CAMetalDrawable object which is either rendered
  405. into directly, or in case of MSAA rendering, serves
  406. as MSAA-resolve-target
  407. - if MSAA is used, an multisampled MTLTexture where
  408. rendering goes into
  409. - an optional MTLTexture for the depth/stencil buffer
  410. It's recommended that you create a helper function which returns an
  411. initialized sg_swapchain struct by value. This can then be directly plugged
  412. into the sg_begin_pass function like this:
  413. sg_begin_pass(&(sg_pass){ .swapchain = sglue_swapchain() });
  414. As an example for such a helper function check out the function sglue_swapchain()
  415. in the sokol_glue.h header.
  416. For offscreen render passes, the render target images used in a render pass
  417. must be provided as sg_view objects specialized for the specific pass-attachment
  418. types:
  419. - color-attachment-views for color-rendering
  420. - depth-stencil-attachment-views for the depth-stencil-buffer surface
  421. - resolve-attachment-views for MSAA-resolve operations
  422. For a simple offscreen scenario with one color-, one depth-stencil-render
  423. target and without multisampling, setting up the required image-
  424. and view-objects looks like this:
  425. First create two render target images, one with a color pixel format,
  426. and one with the depth- or depth-stencil pixel format. Both images
  427. must have the same dimensions. Also not the usage flags:
  428. const sg_image color_img = sg_make_image(&(sg_image_desc){
  429. .usage.color_attachment = true,
  430. .width = 256,
  431. .height = 256,
  432. .pixel_format = SG_PIXELFORMAT_RGBA8,
  433. .sample_count = 1,
  434. });
  435. const sg_image depth_img = sg_make_image(&(sg_image_desc){
  436. .usage.depth_stencil_attachment = true,
  437. .width = 256,
  438. .height = 256,
  439. .pixel_format = SG_PIXELFORMAT_DEPTH,
  440. .sample_count = 1,
  441. });
  442. NOTE: when creating render target images, have in mind that some default values
  443. are aligned with the default environment attributes in the sg_environment struct
  444. that was passed into the sg_setup() call:
  445. - the default value for sg_image_desc.pixel_format is taken from
  446. sg_environment.defaults.color_format
  447. - the default value for sg_image_desc.sample_count is taken from
  448. sg_environment.defaults.sample_count
  449. - the default value for sg_image_desc.num_mipmaps is always 1
  450. Next, create two view objects, one color-attachment-view and one
  451. depth-stencil-attachment view:
  452. const sg_view color_att_view = sg_make_view(&(sg_view_desc){
  453. .color_attachment.image = color_img,
  454. });
  455. const sg_view depth_att_view = sg_make_view(&(sg_view_desc){
  456. .depth_stencil_attachment.image = depth_img,
  457. });
  458. You'll typically also want to create a texture-view on the color image
  459. to sample the color attachment image as texture in a later pass:
  460. const sg_view tex_view = sg_make_view(&(sg_view_desc){
  461. .texture.image = color_img,
  462. });
  463. The attachment-view objects are then passed into the sg_begin_pass function in
  464. place of the nested swapchain struct:
  465. sg_begin_pass(&(sg_pass){
  466. .attachments = {
  467. .colors[0] = color_att_view,
  468. .depth_stencil = depth_att_view,
  469. },
  470. });
  471. ...in a later pass when you want to sample the color attachment image as
  472. texture, use the texture view in the sg_apply_bindings() call:
  473. sg_apply_bindings(&(sg_bindings){
  474. .vertex_buffers[0] = ...,
  475. .index_buffer = ...,
  476. .views[VIEW_tex] = tex_view,
  477. .samplers[SMP_smp] = smp,
  478. });
  479. Swapchain and offscreen passes form dependency trees with a swapchain
  480. pass at the root, offscreen passes as nodes, and attachment images as
  481. dependencies between passes.
  482. sg_pass_action structs are used to define actions that should happen at the
  483. start and end of render passes (such as clearing pass attachments to a
  484. specific color or depth-value, or performing an MSAA resolve operation at
  485. the end of a pass).
  486. A typical sg_pass_action object which clears the color attachment to black
  487. might look like this:
  488. const sg_pass_action = {
  489. .colors[0] = {
  490. .load_action = SG_LOADACTION_CLEAR,
  491. .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f }
  492. }
  493. };
  494. This omits the defaults for the color attachment store action, and
  495. the depth-stencil-attachments actions. The same pass action with the
  496. defaults explicitly filled in would look like this:
  497. const sg_pass_action pass_action = {
  498. .colors[0] = {
  499. .load_action = SG_LOADACTION_CLEAR,
  500. .store_action = SG_STOREACTION_STORE,
  501. .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f }
  502. },
  503. .depth = = {
  504. .load_action = SG_LOADACTION_CLEAR,
  505. .store_action = SG_STOREACTION_DONTCARE,
  506. .clear_value = 1.0f,
  507. },
  508. .stencil = {
  509. .load_action = SG_LOADACTION_CLEAR,
  510. .store_action = SG_STOREACTION_DONTCARE,
  511. .clear_value = 0
  512. }
  513. };
  514. With the sg_pass object and sg_pass_action struct in place everything
  515. is ready now for the actual render pass:
  516. Using such this prepared sg_pass_action in a swapchain pass looks like
  517. this:
  518. sg_begin_pass(&(sg_pass){
  519. .action = pass_action,
  520. .swapchain = sglue_swapchain()
  521. });
  522. ...
  523. sg_end_pass();
  524. ...of alternatively in one offscreen pass:
  525. sg_begin_pass(&(sg_pass){
  526. .action = pass_action,
  527. .attachments = {
  528. .colors[0] = color_att_view,
  529. .depth_stencil = ds_att_view,
  530. },
  531. });
  532. ...
  533. sg_end_pass();
  534. Offscreen rendering can also go into a mipmap, or a slice/face of
  535. a cube-, array- or 3d-image (which some restrictions, for instance
  536. it's not possible to create a 3D image with a depth/stencil pixel format,
  537. these exceptions are generally caught by the sokol-gfx validation layer).
  538. The mipmap/slice selection is baked into the attachment-view objects, for
  539. instance to create a color-attachment-view for rendering into mip-level
  540. 2 and slice 3 of an array texture:
  541. const sg_view color_att_view = sg_make_view(&(sg_view_desc){
  542. .color_attachment = {
  543. .image = color_img,
  544. .mip_level = 2,
  545. .slice = 3,
  546. },
  547. });
  548. If MSAA offscreen rendering is desired, the multi-sample rendering result
  549. must be 'resolved' into a separate 'resolve image', before that image can
  550. be used as texture.
  551. Setting up MSAA offscreen 3D rendering requires three image objects
  552. (one color-attachment image with a sample count > 1), a resolve-attachment
  553. image with a sample count of 1, and a depth-stencil-attachment image
  554. with the same sample count as the color-attachment image:
  555. const sg_image color_img = sg_make_image(&(sg_image_desc){
  556. .usage.color_attachment = true,
  557. .width = 256,
  558. .height = 256,
  559. .pixel_format = SG_PIXELFORMAT_RGBA8,
  560. .sample_count = 4,
  561. });
  562. const sg_image resolve_img = sg_make_image(&(sg_image_desc){
  563. .usage.resolve_attachment = true,
  564. .width = 256,
  565. .height = 256,
  566. .pixel_format = SG_PIXELFORMAT_RGBA8,
  567. .sample_count = 1,
  568. });
  569. const sg_image depth_img = sg_make_image(&(sg_image_desc){
  570. .usage.depth_stencil_attachment = true,
  571. .width = 256,
  572. .height = 256,
  573. .pixel_format = SG_PIXELFORMAT_DEPTH,
  574. .sample_count = 4,
  575. });
  576. Next you'll need the corresponding attachment-view objects:
  577. const sg_view color_att_view = sg_make_view(&(sg_view_desc){
  578. .color_attachment.image = color_img,
  579. });
  580. const sg_view resolve_att_view = sg_make_view(&(sg_view_desc){
  581. .resolve_attachment.image = resolve_img,
  582. });
  583. const sg_view depth_att_view = sg_make_view(&(sg_view_desc){
  584. .depth_stencil_attachment.image = depth_img,
  585. });
  586. To sample the rendered image as a texture in a later pass you'll also
  587. need a texture-view on the resolve-attachment-image (not the color-attachment-image!):
  588. const sg_view tex_view = sg_make_view(&(sg_view_desc){
  589. .texture.image = resolve_img,
  590. });
  591. Next start the render pass with all attachment-views, as soon as a
  592. resolve-attachment-view is provided, an MSAA resolve operation will happen
  593. at the end of the pass. Also note that the content of the MSAA color-attachment-image
  594. doesn't need to be preserved, since it's only needed until the MSAA-resolve
  595. at the end of the pass, so the .store_action should be set to "don't care":
  596. sg_begin_pass(&(sg_pass){
  597. .attachments = {
  598. .colors[0] = color_att_view,
  599. .resolves[0] = resolve_att_view,
  600. .depth_stencil = depth_att_view,
  601. },
  602. .action = {
  603. .colors[0] = {
  604. .load_action = SG_LOADACTION_CLEAR,
  605. .store_action = SG_STOREACTION_DONTCARE,
  606. .clear_value = { 0.0f, 0.0f, 0.0f, 1.0f },
  607. }
  608. },
  609. });
  610. ...in a later pass, use the texture-view that had been created on the
  611. resolve-image to use the rendering result as texture:
  612. sg_apply_bindings(&(sg_bindings){
  613. .vertex_buffers[0] = ...,
  614. .index_buffer = ...,
  615. .views[VIEW_tex] = tex_view,
  616. .samplers[SMP_smp] = smp,
  617. });
  618. ON COMPUTE PASSES
  619. =================
  620. Compute passes are used to update the content of storage buffers and
  621. storage images by running compute shader code on
  622. the GPU. Updating storage resources with a compute shader will almost always
  623. be more efficient than computing the same data on the CPU and then uploading
  624. it via `sg_update_buffer()` or `sg_update_image()`.
  625. NOTE: compute passes are only supported on the following platforms and
  626. backends:
  627. - macOS and iOS with Metal
  628. - Windows with D3D11 and OpenGL
  629. - Linux with OpenGL or GLES3.1+
  630. - Web with WebGPU
  631. - Android with GLES3.1+
  632. ...this means compute shaders can't be used on the following platform/backend
  633. combos (the same restrictions apply to using storage buffers without compute
  634. shaders):
  635. - macOS with GL
  636. - iOS with GLES3
  637. - Web with WebGL2
  638. A compute pass is started with:
  639. sg_begin_pass(&(sg_pass){ .compute = true });
  640. ...and finished with a regular:
  641. sg_end_pass();
  642. Typically the following functions will be called inside a compute pass:
  643. sg_apply_pipeline()
  644. sg_apply_bindings()
  645. sg_apply_uniforms()
  646. sg_dispatch()
  647. The following functions are disallowed inside a compute pass
  648. and will cause validation layer errors:
  649. sg_apply_viewport[f]()
  650. sg_apply_scissor_rect[f]()
  651. sg_draw()
  652. Only special 'compute shaders' and 'compute pipelines' can be used in
  653. compute passes. A compute shader only has a compute-function instead
  654. of a vertex- and fragment-function pair, and it doesn't accept vertex-
  655. and index-buffers as bindings, only storage-buffer-views (readable
  656. and writable), storage-image-views (read/write or writeonly) and
  657. texture-views (read-only).
  658. A compute pipeline is created by providing a compute shader object,
  659. setting the .compute creation parameter to true and not defining any
  660. 'render state':
  661. sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){
  662. .compute = true,
  663. .shader = compute_shader,
  664. });
  665. The sg_apply_bindings and sg_apply_uniforms calls are the same as in
  666. render passes, with the exception that no vertex- and index-buffers
  667. can be bound in the sg_apply_bindings call.
  668. Finally to kick off a compute workload, call sg_dispatch with the
  669. number of workgroups in the x, y and z-dimension:
  670. sg_dispatch(int num_groups_x, int num_groups_y, int num_groups_z)
  671. Also see the following compute-shader samples:
  672. - https://floooh.github.io/sokol-webgpu/instancing-compute-sapp.html
  673. - https://floooh.github.io/sokol-webgpu/computeboids-sapp.html
  674. - https://floooh.github.io/sokol-webgpu/imageblur-sapp.html
  675. ON SHADER CREATION
  676. ==================
  677. sokol-gfx doesn't come with an integrated shader cross-compiler, instead
  678. backend-specific shader sources or binary blobs need to be provided when
  679. creating a shader object, along with reflection information about the
  680. shader resource binding interface needed to bind sokol-gfx resources to the
  681. proper shader inputs.
  682. The easiest way to provide all this shader creation data is to use the
  683. sokol-shdc shader compiler tool to compile shaders from a common
  684. GLSL syntax into backend-specific sources or binary blobs, along with
  685. shader interface information and uniform blocks and storage buffer array items
  686. mapped to C structs.
  687. To create a shader using a C header which has been code-generated by sokol-shdc:
  688. // include the C header code-generated by sokol-shdc:
  689. #include "myshader.glsl.h"
  690. ...
  691. // create shader using a code-generated helper function from the C header:
  692. sg_shader shd = sg_make_shader(myshader_shader_desc(sg_query_backend()));
  693. The samples in the 'sapp' subdirectory of the sokol-samples project
  694. also use the sokol-shdc approach:
  695. https://github.com/floooh/sokol-samples/tree/master/sapp
  696. If you're planning to use sokol-shdc, you can stop reading here, instead
  697. continue with the sokol-shdc documentation:
  698. https://github.com/floooh/sokol-tools/blob/master/docs/sokol-shdc.md
  699. To create shaders with backend-specific shader code or binary blobs,
  700. the sg_make_shader() function requires the following information:
  701. - Shader code or shader binary blobs for the vertex- and fragment-, or the
  702. compute-shader-stage:
  703. - for the desktop GL backend, source code can be provided in '#version 410' or
  704. '#version 430', version 430 is required when using storage buffers and
  705. compute shaders, but note that this is not available on macOS
  706. - for the GLES3 backend, source code must be provided in '#version 300 es' or
  707. '#version 310 es' syntax (version 310 is required for storage buffer and
  708. compute shader support, but note that this is not supported on WebGL2)
  709. - for the D3D11 backend, shaders can be provided as source or binary
  710. blobs, the source code should be in HLSL4.0 (for compatibility with old
  711. low-end GPUs) or preferably in HLSL5.0 syntax, note that when
  712. shader source code is provided for the D3D11 backend, sokol-gfx will
  713. dynamically load 'd3dcompiler_47.dll'
  714. - for the Metal backends, shaders can be provided as source or binary blobs, the
  715. MSL version should be in 'metal-1.1' (other versions may work but are not tested)
  716. - for the WebGPU backend, shaders must be provided as WGSL source code
  717. - optionally the following shader-code related attributes can be provided:
  718. - an entry function name (only on D3D11 or Metal, but not OpenGL)
  719. - on D3D11 only, a compilation target (default is "vs_4_0" and "ps_4_0")
  720. - Information about the input vertex attributes used by the vertex shader,
  721. most of that backend-specific:
  722. - An optional 'base type' (float, signed-/unsigned-int) for each vertex
  723. attribute. When provided, this is used by the validation layer to check
  724. that the CPU-side input vertex format is compatible with the input
  725. vertex declaration of the vertex shader.
  726. - Metal: no location information needed since vertex attributes are always bound
  727. by their attribute location defined in the shader via '[[attribute(N)]]'
  728. - WebGPU: no location information needed since vertex attributes are always
  729. bound by their attribute location defined in the shader via `@location(N)`
  730. - GLSL: vertex attribute names can be optionally provided, in that case their
  731. location will be looked up by name, otherwise, the vertex attribute location
  732. can be defined with 'layout(location = N)'
  733. - D3D11: a 'semantic name' and 'semantic index' must be provided for each vertex
  734. attribute, e.g. if the vertex attribute is defined as 'TEXCOORD1' in the shader,
  735. the semantic name would be 'TEXCOORD', and the semantic index would be '1'
  736. NOTE that vertex attributes currently must not have gaps. This requirement
  737. may be relaxed in the future.
  738. - Specifically for Metal compute shaders, the 'number of threads per threadgroup'
  739. must be provided. Normally this is extracted by sokol-shdc from the GLSL
  740. shader source code. For instance the following statement in the input
  741. GLSL:
  742. layout(local_size_x=64, local_size_y=1, local_size_z=1) in;
  743. ...will be communicated to the sokol-gfx Metal backend in the
  744. code-generated sg_shader_desc struct:
  745. (sg_shader_desc){
  746. .mtl_threads_per_threadgroup = { .x = 64, .y = 1, .z = 1 },
  747. }
  748. - Information about each uniform block binding used in the shader:
  749. - the shader stage of the uniform block (vertex, fragment or compute)
  750. - the size of the uniform block in number of bytes
  751. - a memory layout hint (currently 'native' or 'std140') where 'native' defines a
  752. backend-specific memory layout which shouldn't be used for cross-platform code.
  753. Only std140 guarantees a backend-agnostic memory layout.
  754. - a backend-specific bind slot:
  755. - D3D11/HLSL: the buffer register N (`register(bN)`) where N is 0..7
  756. - Metal/MSL: the buffer bind slot N (`[[buffer(N)]]`) where N is 0..7
  757. - WebGPU: the binding N in `@group(0) @binding(N)` where N is 0..15
  758. - For GLSL only: a description of the internal uniform block layout, which maps
  759. member types and their offsets on the CPU side to uniform variable names
  760. in the GLSL shader
  761. - please also NOTE the documentation sections about UNIFORM DATA LAYOUT
  762. and CROSS-BACKEND COMMON UNIFORM DATA LAYOUT below!
  763. - A description of each resource binding (texture-, storage-buffer-
  764. and storage-image-bindings) which directly map to the sg_bindings.view[]
  765. array slots.
  766. Each resource binding slot comes in three flavours:
  767. 1. Texture bindings with the following properties:
  768. - the shader stage of the texture (vertex, fragment or compute)
  769. - the expected image type:
  770. - SG_IMAGETYPE_2D
  771. - SG_IMAGETYPE_CUBE
  772. - SG_IMAGETYPE_3D
  773. - SG_IMAGETYPE_ARRAY
  774. - the expected 'image sample type':
  775. - SG_IMAGESAMPLETYPE_FLOAT
  776. - SG_IMAGESAMPLETYPE_DEPTH
  777. - SG_IMAGESAMPLETYPE_SINT
  778. - SG_IMAGESAMPLETYPE_UINT
  779. - SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT
  780. - a flag whether the texture is expected to be multisampled
  781. - a backend-specific bind slot:
  782. - D3D11/HLSL: the texture register N (`register(tN)`) where N is 0..31
  783. (in HLSL, readonly storage buffers and texture share the same bind space)
  784. - Metal/MSL: the texture bind slot N (`[[texture(N)]]`) where N is 0..31
  785. (the bind slot must not collide with storage image bindings on the same stage)
  786. - WebGPU/WGSL: the binding N in `@group(0) @binding(N)` where N is 0..127
  787. 2. Storage buffer bindings with the following properties:
  788. - the shader stage of the storage buffer
  789. - a boolean 'readonly' flag, this is used for validation and hazard
  790. tracking in some 3D backends. Note that in render passes, only
  791. readonly storage buffer bindings are allowed. In compute passes, any
  792. read/write storage buffer binding is assumed to be written to by the
  793. compute shader.
  794. - a backend-specific bind slot:
  795. - D3D11/HLSL:
  796. - for readonly storage buffer bindings: the texture register N
  797. (`register(tN)`) where N is 0..31 (in HLSL, readonly storage
  798. buffers and textures share the same bind space for
  799. 'shader resource views')
  800. - for read/write storage buffer buffer bindings: the UAV register N
  801. (`register(uN)`) where N is 0..31 (in HLSL, readwrite storage
  802. buffers use their own bind space for 'unordered access views')
  803. - Metal/MSL: the buffer bind slot N (`[[buffer(N)]]`) where N is 8..23
  804. - WebGPU/WGSL: the binding N in `@group(0) @binding(N)` where N is 0..127
  805. - GL/GLSL: the buffer binding N in `layout(binding=N)`
  806. where N is 0..sg_limits.max_storage_buffer_bindings_per_stage
  807. - note that storage buffer bindings are not supported on all backends
  808. and platforms
  809. 3. Storage image bindings with the following properties:
  810. - the shader stage (*must* be compute)
  811. - the expected image type:
  812. - SG_IMAGETYPE_2D
  813. - SG_IMAGETYPE_CUBE
  814. - SG_IMAGETYPE_3D
  815. - SG_IMAGETYPE_ARRAY
  816. - the 'access pixel format', this is currently limited to:
  817. - SG_PIXELFORMAT_RGBA8
  818. - SG_PIXELFORMAT_RGBA8SN/UI/SI
  819. - SG_PIXELFORMAT_RGBA16UI/SI/F
  820. - SG_PIXELFORMAT_R32UIUI/SI/F
  821. - SG_PIXELFORMAT_RG32UI/SI/F
  822. - SG_PIXELFORMAT_RGBA32UI/SI/F
  823. - the access type (readwrite or writeonly)
  824. - a backend-specific bind slot:
  825. - D3D11/HLSL: the UAV register N (`register(uN)` where N is 0..31, the
  826. bind slot must not collide with UAV storage buffer bindings
  827. - Metal/MSL: the texture bind slot N (`[[texture(N)]])` where N is 0..31,
  828. the bind slot must not collide with other texture bindings on the same
  829. stage
  830. - WebGPU/WGSL: the binding N in `@group(1) @binding(N)` where N is 0..127
  831. - GL/GLSL: the buffer binding N in `layout(binding=N)`
  832. where N is 0.._sg.max_storage_image_bindings_per_stage
  833. - note that storage image bindings are not supported on all backends and platforms
  834. - A description of each sampler used in the shader:
  835. - the shader stage of the sampler (vertex, fragment or compute)
  836. - the expected sampler type:
  837. - SG_SAMPLERTYPE_FILTERING,
  838. - SG_SAMPLERTYPE_NONFILTERING,
  839. - SG_SAMPLERTYPE_COMPARISON,
  840. - a backend-specific bind slot:
  841. - D3D11/HLSL: the sampler register N (`register(sN)`) where N is 0..SG_MAX_SAMPLER_BINDINGS
  842. - Metal/MSL: the sampler bind slot N (`[[sampler(N)]]`) where N is 0..SG_MAX_SAMPLER_BINDINGS
  843. - WebGPU/WGSL: the binding N in `@group(0) @binding(N)` where N is 0..127
  844. - An array of 'texture-sampler-pairs' used by the shader to sample textures,
  845. for D3D11, Metal and WebGPU this is used for validation purposes to check
  846. whether the texture and sampler are compatible with each other (especially
  847. WebGPU is very picky about combining the correct
  848. texture-sample-type with the correct sampler-type). For GLSL an
  849. additional 'combined-image-sampler name' must be provided because 'OpenGL
  850. style GLSL' cannot handle separate texture and sampler objects, but still
  851. groups them into a traditional GLSL 'sampler object'.
  852. Compatibility rules for image-sample-type vs sampler-type are as follows:
  853. - SG_IMAGESAMPLETYPE_FLOAT => (SG_SAMPLERTYPE_FILTERING or SG_SAMPLERTYPE_NONFILTERING)
  854. - SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT => SG_SAMPLERTYPE_NONFILTERING
  855. - SG_IMAGESAMPLETYPE_SINT => SG_SAMPLERTYPE_NONFILTERING
  856. - SG_IMAGESAMPLETYPE_UINT => SG_SAMPLERTYPE_NONFILTERING
  857. - SG_IMAGESAMPLETYPE_DEPTH => SG_SAMPLERTYPE_COMPARISON
  858. Backend-specific bindslot ranges (not relevant when using sokol-shdc):
  859. - D3D11/HLSL:
  860. - separate bindslot space per shader stage
  861. - uniform block bindings (as cbuffer): `register(b0..b7)`
  862. - texture- and readonly storage buffer bindings: `register(t0..t31)`
  863. - read/write storage buffer and storage image bindings: `register(u0..u31)`
  864. - samplers: `register(s0..s11)`
  865. - Metal/MSL:
  866. - separate bindslot space per shader stage
  867. - uniform blocks: `[[buffer(0..7)]]`
  868. - storage buffers: `[[buffer(8..23)]]`
  869. - textures and storage image bindings: `[[texture(0..31)]]`
  870. - samplers: `[[sampler(0..11)]]`
  871. - WebGPU/WGSL:
  872. - common bindslot space across shader stages
  873. - uniform blocks: `@group(0) @binding(0..15)`
  874. - textures, storage-images, storage-buffers and sampler: `@group(1) @binding(0..127)`
  875. - GL/GLSL:
  876. - uniforms and image-samplers are bound by name
  877. - storage buffer bindings: `layout(std430, binding=0..sg_limits.max_storage_buffer_bindings_per_stage` (common
  878. bindslot space across shader stages)
  879. - storage image bindings: `layout(binding=0..sg_limits.max_storage_image_bindings_per_stage, [access_format])`
  880. For example code of how to create backend-specific shader objects,
  881. please refer to the following samples:
  882. - for D3D11: https://github.com/floooh/sokol-samples/tree/master/d3d11
  883. - for Metal: https://github.com/floooh/sokol-samples/tree/master/metal
  884. - for OpenGL: https://github.com/floooh/sokol-samples/tree/master/glfw
  885. - for GLES3: https://github.com/floooh/sokol-samples/tree/master/html5
  886. - for WebGPU: https://github.com/floooh/sokol-samples/tree/master/wgpu
  887. ON SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT AND SG_SAMPLERTYPE_NONFILTERING
  888. ========================================================================
  889. The WebGPU backend introduces the concept of 'unfilterable-float' textures,
  890. which can only be combined with 'nonfiltering' samplers (this is a restriction
  891. specific to WebGPU, but since the same sokol-gfx code should work across
  892. all backend, the sokol-gfx validation layer also enforces this restriction
  893. - the alternative would be undefined behaviour in some backend APIs on
  894. some devices).
  895. The background is that some mobile devices (most notably iOS devices) can
  896. not perform linear filtering when sampling textures with certain pixel
  897. formats, most notable the 32F formats:
  898. - SG_PIXELFORMAT_R32F
  899. - SG_PIXELFORMAT_RG32F
  900. - SG_PIXELFORMAT_RGBA32F
  901. The information of whether a shader is going to be used with such an
  902. unfilterable-float texture must already be provided in the sg_shader_desc
  903. struct when creating the shader (see the above section "ON SHADER CREATION").
  904. If you are using the sokol-shdc shader compiler, the information whether a
  905. texture/sampler binding expects an 'unfilterable-float/nonfiltering'
  906. texture/sampler combination cannot be inferred from the shader source
  907. alone, you'll need to provide this hint via annotation-tags. For instance
  908. here is an example from the ozz-skin-sapp.c sample shader which samples an
  909. RGBA32F texture with skinning matrices in the vertex shader:
  910. ```glsl
  911. @image_sample_type joint_tex unfilterable_float
  912. uniform texture2D joint_tex;
  913. @sampler_type smp nonfiltering
  914. uniform sampler smp;
  915. ```
  916. This will result in SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT and
  917. SG_SAMPLERTYPE_NONFILTERING being written to the code-generated
  918. sg_shader_desc struct.
  919. ON VERTEX FORMATS
  920. =================
  921. Sokol-gfx implements the same strict mapping rules from CPU-side
  922. vertex component formats to GPU-side vertex input data types:
  923. - float and packed normalized CPU-side formats must be used as
  924. floating point base type in the vertex shader
  925. - packed signed-integer CPU-side formats must be used as signed
  926. integer base type in the vertex shader
  927. - packed unsigned-integer CPU-side formats must be used as unsigned
  928. integer base type in the vertex shader
  929. These mapping rules are enforced by the sokol-gfx validation layer,
  930. but only when sufficient reflection information is provided in
  931. `sg_shader_desc.attrs[].base_type`. This is the case when sokol-shdc
  932. is used, otherwise the default base_type will be SG_SHADERATTRBASETYPE_UNDEFINED
  933. which causes the sokol-gfx validation check to be skipped (of course you
  934. can also provide the per-attribute base type information manually when
  935. not using sokol-shdc).
  936. The detailed mapping rules from SG_VERTEXFORMAT_* to GLSL data types
  937. are as follows:
  938. - FLOAT[*] => float, vec*
  939. - BYTE4N => vec* (scaled to -1.0 .. +1.0)
  940. - UBYTE4N => vec* (scaled to 0.0 .. +1.0)
  941. - SHORT[*]N => vec* (scaled to -1.0 .. +1.0)
  942. - USHORT[*]N => vec* (scaled to 0.0 .. +1.0)
  943. - INT[*] => int, ivec*
  944. - UINT[*] => uint, uvec*
  945. - BYTE4 => int*
  946. - UBYTE4 => uint*
  947. - SHORT[*] => int*
  948. - USHORT[*] => uint*
  949. NOTE that sokol-gfx only provides vertex formats with sizes of a multiple
  950. of 4 (e.g. BYTE4N but not BYTE2N). This is because vertex components must
  951. be 4-byte aligned anyway.
  952. UNIFORM DATA LAYOUT:
  953. ====================
  954. NOTE: if you use the sokol-shdc shader compiler tool, you don't need to worry
  955. about the following details.
  956. The data that's passed into the sg_apply_uniforms() function must adhere to
  957. specific layout rules so that the GPU shader finds the uniform block
  958. items at the right offset.
  959. For the D3D11 and Metal backends, sokol-gfx only cares about the size of uniform
  960. blocks, but not about the internal layout. The data will just be copied into
  961. a uniform/constant buffer in a single operation and it's up you to arrange the
  962. CPU-side layout so that it matches the GPU side layout. This also means that with
  963. the D3D11 and Metal backends you are not limited to a 'cross-platform' subset
  964. of uniform variable types.
  965. If you ever only use one of the D3D11, Metal *or* WebGPU backend, you can stop reading here.
  966. For the GL backends, the internal layout of uniform blocks matters though,
  967. and you are limited to a small number of uniform variable types. This is
  968. because sokol-gfx must be able to locate the uniform block members in order
  969. to upload them to the GPU with glUniformXXX() calls.
  970. To describe the uniform block layout to sokol-gfx, the following information
  971. must be passed to the sg_make_shader() call in the sg_shader_desc struct:
  972. - a hint about the used packing rule (either SG_UNIFORMLAYOUT_NATIVE or
  973. SG_UNIFORMLAYOUT_STD140)
  974. - a list of the uniform block members types in the correct order they
  975. appear on the CPU side
  976. For example if the GLSL shader has the following uniform declarations:
  977. uniform mat4 mvp;
  978. uniform vec2 offset0;
  979. uniform vec2 offset1;
  980. uniform vec2 offset2;
  981. ...and on the CPU side, there's a similar C struct:
  982. typedef struct {
  983. float mvp[16];
  984. float offset0[2];
  985. float offset1[2];
  986. float offset2[2];
  987. } params_t;
  988. ...the uniform block description in the sg_shader_desc must look like this:
  989. sg_shader_desc desc = {
  990. .vs.uniform_blocks[0] = {
  991. .size = sizeof(params_t),
  992. .layout = SG_UNIFORMLAYOUT_NATIVE, // this is the default and can be omitted
  993. .uniforms = {
  994. // order must be the same as in 'params_t':
  995. [0] = { .name = "mvp", .type = SG_UNIFORMTYPE_MAT4 },
  996. [1] = { .name = "offset0", .type = SG_UNIFORMTYPE_VEC2 },
  997. [2] = { .name = "offset1", .type = SG_UNIFORMTYPE_VEC2 },
  998. [3] = { .name = "offset2", .type = SG_UNIFORMTYPE_VEC2 },
  999. }
  1000. }
  1001. };
  1002. With this information sokol-gfx can now compute the correct offsets of the data items
  1003. within the uniform block struct.
  1004. The SG_UNIFORMLAYOUT_NATIVE packing rule works fine if only the GL backends are used,
  1005. but for proper D3D11/Metal/GL a subset of the std140 layout must be used which is
  1006. described in the next section:
  1007. CROSS-BACKEND COMMON UNIFORM DATA LAYOUT
  1008. ========================================
  1009. For cross-platform / cross-3D-backend code it is important that the same uniform block
  1010. layout on the CPU side can be used for all sokol-gfx backends. To achieve this,
  1011. a common subset of the std140 layout must be used:
  1012. - The uniform block layout hint in sg_shader_desc must be explicitly set to
  1013. SG_UNIFORMLAYOUT_STD140.
  1014. - Only the following GLSL uniform types can be used (with their associated sokol-gfx enums):
  1015. - float => SG_UNIFORMTYPE_FLOAT
  1016. - vec2 => SG_UNIFORMTYPE_FLOAT2
  1017. - vec3 => SG_UNIFORMTYPE_FLOAT3
  1018. - vec4 => SG_UNIFORMTYPE_FLOAT4
  1019. - int => SG_UNIFORMTYPE_INT
  1020. - ivec2 => SG_UNIFORMTYPE_INT2
  1021. - ivec3 => SG_UNIFORMTYPE_INT3
  1022. - ivec4 => SG_UNIFORMTYPE_INT4
  1023. - mat4 => SG_UNIFORMTYPE_MAT4
  1024. - Alignment for those types must be as follows (in bytes):
  1025. - float => 4
  1026. - vec2 => 8
  1027. - vec3 => 16
  1028. - vec4 => 16
  1029. - int => 4
  1030. - ivec2 => 8
  1031. - ivec3 => 16
  1032. - ivec4 => 16
  1033. - mat4 => 16
  1034. - Arrays are only allowed for the following types: vec4, int4, mat4.
  1035. Note that the HLSL cbuffer layout rules are slightly different from the
  1036. std140 layout rules, this means that the cbuffer declarations in HLSL code
  1037. must be tweaked so that the layout is compatible with std140.
  1038. The by far easiest way to tackle the common uniform block layout problem is
  1039. to use the sokol-shdc shader cross-compiler tool!
  1040. ON STORAGE BUFFERS
  1041. ==================
  1042. The two main purpose of storage buffers are:
  1043. - to be populated by compute shaders with dynamically generated data
  1044. - for providing random-access data to all shader stages
  1045. Storage buffers can be used to pass large amounts of random access structured
  1046. data from the CPU side to the shaders. They are similar to data textures, but are
  1047. more convenient to use both on the CPU and shader side since they can be accessed
  1048. in shaders as as a 1-dimensional array of struct items.
  1049. Storage buffers are *NOT* supported on the following platform/backend combos:
  1050. - macOS+GL (because storage buffers require GL 4.3, while macOS only goes up to GL 4.1)
  1051. - platforms which only support a GLES3.0 context (WebGL2 and iOS)
  1052. To use storage buffers, the following steps are required:
  1053. - write a shader which uses storage buffers (vertex- and fragment-shaders
  1054. can only read from storage buffers, while compute-shaders can both read
  1055. and write storage buffers)
  1056. - create one or more storage buffers via sg_make_buffer() with the
  1057. `.usage.storage_buffer = true`
  1058. - when creating a shader via sg_make_shader(), populate the sg_shader_desc
  1059. struct with binding info (when using sokol-shdc, this step will be taken care
  1060. of automatically)
  1061. - which storage buffer bind slots on the vertex-, fragment- or compute-stage
  1062. are occupied
  1063. - whether the storage buffer on that bind slot is readonly (readonly
  1064. bindings are required for vertex- and fragment-shaders, and in compute
  1065. shaders the readonly flag is used to control hazard tracking in some
  1066. 3D backends)
  1067. - when calling sg_apply_bindings(), apply the matching bind slots with the previously
  1068. created storage buffers
  1069. - ...and that's it.
  1070. For more details, see the following backend-agnostic sokol samples:
  1071. - simple vertex pulling from a storage buffer:
  1072. - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/vertexpull-sapp.c
  1073. - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/vertexpull-sapp.glsl
  1074. - instanced rendering via storage buffers (vertex- and instance-pulling):
  1075. - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-pull-sapp.c
  1076. - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-pull-sapp.glsl
  1077. - storage buffers both on the vertex- and fragment-stage:
  1078. - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/sbuftex-sapp.c
  1079. - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/sbuftex-sapp.glsl
  1080. - the Ozz animation sample rewritten to pull all rendering data from storage buffers:
  1081. - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/ozz-storagebuffer-sapp.cc
  1082. - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/ozz-storagebuffer-sapp.glsl
  1083. - the instancing sample modified to use compute shaders:
  1084. - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-compute-sapp.c
  1085. - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/instancing-compute-sapp.glsl
  1086. - the Compute Boids sample ported to sokol-gfx:
  1087. - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/computeboids-sapp.c
  1088. - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/computeboids-sapp.glsl
  1089. ...also see the following backend-specific vertex pulling samples (those also don't use sokol-shdc):
  1090. - D3D11: https://github.com/floooh/sokol-samples/blob/master/d3d11/vertexpulling-d3d11.c
  1091. - desktop GL: https://github.com/floooh/sokol-samples/blob/master/glfw/vertexpulling-glfw.c
  1092. - Metal: https://github.com/floooh/sokol-samples/blob/master/metal/vertexpulling-metal.c
  1093. - WebGPU: https://github.com/floooh/sokol-samples/blob/master/wgpu/vertexpulling-wgpu.c
  1094. ...and the backend specific compute shader samples:
  1095. - D3D11: https://github.com/floooh/sokol-samples/blob/master/d3d11/instancing-compute-d3d11.c
  1096. - desktop GL: https://github.com/floooh/sokol-samples/blob/master/glfw/instancing-compute-glfw.c
  1097. - Metal: https://github.com/floooh/sokol-samples/blob/master/metal/instancing-compute-metal.c
  1098. - WebGPU: https://github.com/floooh/sokol-samples/blob/master/wgpu/instancing-compute-wgpu.c
  1099. Storage buffer shader authoring caveats when using sokol-shdc:
  1100. - declare a read-only storage buffer interface block with `layout(binding=N) readonly buffer [name] { ... }`
  1101. (where 'N' is the index in `sg_bindings.storage_buffers[N]`)
  1102. - ...or a read/write storage buffer interface block with `layout(binding=N) buffer [name] { ... }`
  1103. - declare a struct which describes a single array item in the storage buffer interface block
  1104. - only put a single flexible array member into the storage buffer interface block
  1105. E.g. a complete example in 'sokol-shdc GLSL':
  1106. ```glsl
  1107. @vs
  1108. // declare a struct:
  1109. struct sb_vertex {
  1110. vec3 pos;
  1111. vec4 color;
  1112. }
  1113. // declare a buffer interface block with a single flexible struct array:
  1114. layout(binding=0) readonly buffer vertices {
  1115. sb_vertex vtx[];
  1116. }
  1117. // in the shader function, access the storage buffer like this:
  1118. void main() {
  1119. vec3 pos = vtx[gl_VertexIndex].pos;
  1120. ...
  1121. }
  1122. @end
  1123. ```
  1124. In a compute shader you can read and write the same item in the same
  1125. storage buffer (but you'll have to be careful for random access since
  1126. many threads of the same compute function run in parallel):
  1127. @cs
  1128. struct sb_item {
  1129. vec3 pos;
  1130. vec3 vel;
  1131. }
  1132. layout(binding=0) buffer items_ssbo {
  1133. sb_item items[];
  1134. }
  1135. layout(local_size_x=64, local_size_y=1, local_size_z=1) in;
  1136. void main() {
  1137. uint idx = gl_GlobalInvocationID.x;
  1138. vec3 pos = items[idx].pos;
  1139. ...
  1140. items[idx].pos = pos;
  1141. }
  1142. @end
  1143. Backend-specific storage-buffer caveats (not relevant when using sokol-shdc):
  1144. D3D11:
  1145. - storage buffers are created as 'raw' Byte Address Buffers
  1146. (https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-intro#raw-views-of-buffers)
  1147. - in HLSL, use a ByteAddressBuffer for readonly access of the buffer content:
  1148. (https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-byteaddressbuffer)
  1149. - ...or RWByteAddressBuffer for read/write access:
  1150. (https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwbyteaddressbuffer)
  1151. - readonly-storage buffers and textures are both bound as 'shader-resource-view' and
  1152. share the same bind slots (declared as `register(tN)` in HLSL), where N must be in the range 0..23)
  1153. - read/write storage buffers and storage images are bound as 'unordered-access-view'
  1154. (declared as `register(uN)` in HLSL where N is in the range 0..11)
  1155. Metal:
  1156. - in Metal there is no internal difference between vertex-, uniform- and
  1157. storage-buffers, all are bound to the same 'buffer bind slots' with the
  1158. following reserved ranges:
  1159. - vertex shader stage:
  1160. - uniform buffers: slots 0..7
  1161. - storage buffers: slots 8..15
  1162. - vertex buffers: slots 15..23
  1163. - fragment shader stage:
  1164. - uniform buffers: slots 0..7
  1165. - storage buffers: slots 8..15
  1166. - this means in MSL, storage buffer bindings start at [[buffer(8)]] both in
  1167. the vertex and fragment stage
  1168. GL:
  1169. - the GL backend doesn't use name-lookup to find storage buffer bindings, this
  1170. means you must annotate buffers with `layout(std430, binding=N)` in GLSL
  1171. - ...where N is 0..sg_limits.max_storage_buffer_bindings_per_stage.
  1172. WebGPU:
  1173. - in WGSL, textures, samplers and storage buffers all use a shared
  1174. bindspace across all shader stages on bindgroup 1:
  1175. `@group(1) @binding(0..127)
  1176. ON STORAGE IMAGES:
  1177. ==================
  1178. To write pixel data to texture objects in compute shaders, first an image
  1179. object must be created with `storage_image usage`:
  1180. sg_image storage_image = sg_make_image(&(sg_image_desc){
  1181. .usage.storage_image = true,
  1182. },
  1183. .width = ...,
  1184. .height = ...,
  1185. .pixel_format = ...,
  1186. });
  1187. Next a storage-image-view object is required which also allows to pick
  1188. a specific mip-level or slice for the compute-shader to access:
  1189. sg_view simg_view = sg_make_view(&(sg_view_desc){
  1190. .storage_image = {
  1191. .image = storage_image,
  1192. .mip_level = ...,
  1193. .slice = ...
  1194. },
  1195. });
  1196. Finally 'bind' the storage-image-view via a regular sg_apply_bindings() call
  1197. inside a compute pass:
  1198. sg_begin_pass(&(sg_pass){ .compute = true });
  1199. sg_apply_pipeline(...);
  1200. sg_apply_bindings(&(sg_bindings){
  1201. .views[VIEW_simg] = simg_view,
  1202. });
  1203. sg_dispatch(...);
  1204. sg_end_pass();
  1205. Currently, storage images can only be used with `readwrite` or `writeonly` access in
  1206. shaders. For readonly access use a regular texture binding instead.
  1207. For an example of using storage images in compute shaders see imageblur-sapp:
  1208. - C code: https://github.com/floooh/sokol-samples/blob/master/sapp/imageblur-sapp.c
  1209. - shader: https://github.com/floooh/sokol-samples/blob/master/sapp/imageblur-sapp.glsl
  1210. TRACE HOOKS:
  1211. ============
  1212. sokol_gfx.h optionally allows to install "trace hook" callbacks for
  1213. each public API functions. When a public API function is called, and
  1214. a trace hook callback has been installed for this function, the
  1215. callback will be invoked with the parameters and result of the function.
  1216. This is useful for things like debugging- and profiling-tools, or
  1217. keeping track of resource creation and destruction.
  1218. To use the trace hook feature:
  1219. --- Define SOKOL_TRACE_HOOKS before including the implementation.
  1220. --- Setup an sg_trace_hooks structure with your callback function
  1221. pointers (keep all function pointers you're not interested
  1222. in zero-initialized), optionally set the user_data member
  1223. in the sg_trace_hooks struct.
  1224. --- Install the trace hooks by calling sg_install_trace_hooks(),
  1225. the return value of this function is another sg_trace_hooks
  1226. struct which contains the previously set of trace hooks.
  1227. You should keep this struct around, and call those previous
  1228. functions pointers from your own trace callbacks for proper
  1229. chaining.
  1230. As an example of how trace hooks are used, have a look at the
  1231. imgui/sokol_gfx_imgui.h header which implements a realtime
  1232. debugging UI for sokol_gfx.h on top of Dear ImGui.
  1233. MEMORY ALLOCATION OVERRIDE
  1234. ==========================
  1235. You can override the memory allocation functions at initialization time
  1236. like this:
  1237. void* my_alloc(size_t size, void* user_data) {
  1238. return malloc(size);
  1239. }
  1240. void my_free(void* ptr, void* user_data) {
  1241. free(ptr);
  1242. }
  1243. ...
  1244. sg_setup(&(sg_desc){
  1245. // ...
  1246. .allocator = {
  1247. .alloc_fn = my_alloc,
  1248. .free_fn = my_free,
  1249. .user_data = ...,
  1250. }
  1251. });
  1252. ...
  1253. If no overrides are provided, malloc and free will be used.
  1254. This only affects memory allocation calls done by sokol_gfx.h
  1255. itself though, not any allocations in OS libraries.
  1256. ERROR REPORTING AND LOGGING
  1257. ===========================
  1258. To get any logging information at all you need to provide a logging callback in the setup call
  1259. the easiest way is to use sokol_log.h:
  1260. #include "sokol_log.h"
  1261. sg_setup(&(sg_desc){ .logger.func = slog_func });
  1262. To override logging with your own callback, first write a logging function like this:
  1263. void my_log(const char* tag, // e.g. 'sg'
  1264. uint32_t log_level, // 0=panic, 1=error, 2=warn, 3=info
  1265. uint32_t log_item_id, // SG_LOGITEM_*
  1266. const char* message_or_null, // a message string, may be nullptr in release mode
  1267. uint32_t line_nr, // line number in sokol_gfx.h
  1268. const char* filename_or_null, // source filename, may be nullptr in release mode
  1269. void* user_data)
  1270. {
  1271. ...
  1272. }
  1273. ...and then setup sokol-gfx like this:
  1274. sg_setup(&(sg_desc){
  1275. .logger = {
  1276. .func = my_log,
  1277. .user_data = my_user_data,
  1278. }
  1279. });
  1280. The provided logging function must be reentrant (e.g. be callable from
  1281. different threads).
  1282. If you don't want to provide your own custom logger it is highly recommended to use
  1283. the standard logger in sokol_log.h instead, otherwise you won't see any warnings or
  1284. errors.
  1285. COMMIT LISTENERS
  1286. ================
  1287. It's possible to hook callback functions into sokol-gfx which are called from
  1288. inside sg_commit() in unspecified order. This is mainly useful for libraries
  1289. that build on top of sokol_gfx.h to be notified about the end/start of a frame.
  1290. To add a commit listener, call:
  1291. static void my_commit_listener(void* user_data) {
  1292. ...
  1293. }
  1294. bool success = sg_add_commit_listener((sg_commit_listener){
  1295. .func = my_commit_listener,
  1296. .user_data = ...,
  1297. });
  1298. The function returns false if the internal array of commit listeners is full,
  1299. or the same commit listener had already been added.
  1300. If the function returns true, my_commit_listener() will be called each frame
  1301. from inside sg_commit().
  1302. By default, 1024 distinct commit listeners can be added, but this number
  1303. can be tweaked in the sg_setup() call:
  1304. sg_setup(&(sg_desc){
  1305. .max_commit_listeners = 2048,
  1306. });
  1307. An sg_commit_listener item is equal to another if both the function
  1308. pointer and user_data field are equal.
  1309. To remove a commit listener:
  1310. bool success = sg_remove_commit_listener((sg_commit_listener){
  1311. .func = my_commit_listener,
  1312. .user_data = ...,
  1313. });
  1314. ...where the .func and .user_data field are equal to a previous
  1315. sg_add_commit_listener() call. The function returns true if the commit
  1316. listener item was found and removed, and false otherwise.
  1317. RESOURCE CREATION AND DESTRUCTION IN DETAIL
  1318. ===========================================
  1319. The 'vanilla' way to create resource objects is with the 'make functions':
  1320. sg_buffer sg_make_buffer(const sg_buffer_desc* desc)
  1321. sg_image sg_make_image(const sg_image_desc* desc)
  1322. sg_sampler sg_make_sampler(const sg_sampler_desc* desc)
  1323. sg_shader sg_make_shader(const sg_shader_desc* desc)
  1324. sg_pipeline sg_make_pipeline(const sg_pipeline_desc* desc)
  1325. sg_view sg_make_view(const sg_view_desc* desc)
  1326. This will result in one of three cases:
  1327. 1. The returned handle is invalid. This happens when there are no more
  1328. free slots in the resource pool for this resource type. An invalid
  1329. handle is associated with the INVALID resource state, for instance:
  1330. sg_buffer buf = sg_make_buffer(...)
  1331. if (sg_query_buffer_state(buf) == SG_RESOURCESTATE_INVALID) {
  1332. // buffer pool is exhausted
  1333. }
  1334. 2. The returned handle is valid, but creating the underlying resource
  1335. has failed for some reason. This results in a resource object in the
  1336. FAILED state. The reason *why* resource creation has failed differ
  1337. by resource type. Look for log messages with more details. A failed
  1338. resource state can be checked with:
  1339. sg_buffer buf = sg_make_buffer(...)
  1340. if (sg_query_buffer_state(buf) == SG_RESOURCESTATE_FAILED) {
  1341. // creating the resource has failed
  1342. }
  1343. 3. And finally, if everything goes right, the returned resource is
  1344. in resource state VALID and ready to use. This can be checked
  1345. with:
  1346. sg_buffer buf = sg_make_buffer(...)
  1347. if (sg_query_buffer_state(buf) == SG_RESOURCESTATE_VALID) {
  1348. // creating the resource has failed
  1349. }
  1350. When calling the 'make functions', the created resource goes through a number
  1351. of states:
  1352. - INITIAL: the resource slot associated with the new resource is currently
  1353. free (technically, there is no resource yet, just an empty pool slot)
  1354. - ALLOC: a handle for the new resource has been allocated, this just means
  1355. a pool slot has been reserved.
  1356. - VALID or FAILED: in VALID state any 3D API backend resource objects have
  1357. been successfully created, otherwise if anything went wrong, the resource
  1358. will be in FAILED state.
  1359. Sometimes it makes sense to first grab a handle, but initialize the
  1360. underlying resource at a later time. For instance when loading data
  1361. asynchronously from a slow data source, you may know what buffers and
  1362. textures are needed at an early stage of the loading process, but actually
  1363. loading the buffer or texture content can only be completed at a later time.
  1364. For such situations, sokol-gfx resource objects can be created in two steps.
  1365. You can allocate a handle upfront with one of the 'alloc functions':
  1366. sg_buffer sg_alloc_buffer(void)
  1367. sg_image sg_alloc_image(void)
  1368. sg_sampler sg_alloc_sampler(void)
  1369. sg_shader sg_alloc_shader(void)
  1370. sg_pipeline sg_alloc_pipeline(void)
  1371. sg_view sg_alloc_view(void)
  1372. This will return a handle with the underlying resource object in the
  1373. ALLOC state:
  1374. sg_image img = sg_alloc_image();
  1375. if (sg_query_image_state(img) == SG_RESOURCESTATE_ALLOC) {
  1376. // allocating an image handle has succeeded, otherwise
  1377. // the image pool is full
  1378. }
  1379. Such an 'incomplete' handle can be used in most sokol-gfx rendering functions
  1380. without doing any harm, sokol-gfx will simply skip any rendering operation
  1381. that involve resources which are not in VALID state.
  1382. At a later time (for instance once the texture has completed loading
  1383. asynchronously), the resource creation can be completed by calling one of
  1384. the 'init functions', those functions take an existing resource handle and
  1385. 'desc struct':
  1386. void sg_init_buffer(sg_buffer buf, const sg_buffer_desc* desc)
  1387. void sg_init_image(sg_image img, const sg_image_desc* desc)
  1388. void sg_init_sampler(sg_sampler smp, const sg_sampler_desc* desc)
  1389. void sg_init_shader(sg_shader shd, const sg_shader_desc* desc)
  1390. void sg_init_pipeline(sg_pipeline pip, const sg_pipeline_desc* desc)
  1391. void sg_init_view(sg_view view, const sg_view_desc* desc)
  1392. The init functions expect a resource in ALLOC state, and after the function
  1393. returns, the resource will be either in VALID or FAILED state. Calling
  1394. an 'alloc function' followed by the matching 'init function' is fully
  1395. equivalent with calling the 'make function' alone.
  1396. Destruction can also happen as a two-step process. The 'uninit functions'
  1397. will put a resource object from the VALID or FAILED state back into the
  1398. ALLOC state:
  1399. void sg_uninit_buffer(sg_buffer buf)
  1400. void sg_uninit_image(sg_image img)
  1401. void sg_uninit_sampler(sg_sampler smp)
  1402. void sg_uninit_shader(sg_shader shd)
  1403. void sg_uninit_pipeline(sg_pipeline pip)
  1404. void sg_uninit_view(sg_view view)
  1405. Calling the 'uninit functions' with a resource that is not in the VALID or
  1406. FAILED state is a no-op.
  1407. To finally free the pool slot for recycling call the 'dealloc functions':
  1408. void sg_dealloc_buffer(sg_buffer buf)
  1409. void sg_dealloc_image(sg_image img)
  1410. void sg_dealloc_sampler(sg_sampler smp)
  1411. void sg_dealloc_shader(sg_shader shd)
  1412. void sg_dealloc_pipeline(sg_pipeline pip)
  1413. void sg_dealloc_view(sg_view view)
  1414. Calling the 'dealloc functions' on a resource that's not in ALLOC state is
  1415. a no-op, but will generate a warning log message.
  1416. Calling an 'uninit function' and 'dealloc function' in sequence is equivalent
  1417. with calling the associated 'destroy function':
  1418. void sg_destroy_buffer(sg_buffer buf)
  1419. void sg_destroy_image(sg_image img)
  1420. void sg_destroy_sampler(sg_sampler smp)
  1421. void sg_destroy_shader(sg_shader shd)
  1422. void sg_destroy_pipeline(sg_pipeline pip)
  1423. void sg_destroy_view(sg_view view)
  1424. The 'destroy functions' can be called on resources in any state and generally
  1425. do the right thing (for instance if the resource is in ALLOC state, the destroy
  1426. function will be equivalent to the 'dealloc function' and skip the 'uninit part').
  1427. And finally to close the circle, the 'fail functions' can be called to manually
  1428. put a resource in ALLOC state into the FAILED state:
  1429. sg_fail_buffer(sg_buffer buf)
  1430. sg_fail_image(sg_image img)
  1431. sg_fail_sampler(sg_sampler smp)
  1432. sg_fail_shader(sg_shader shd)
  1433. sg_fail_pipeline(sg_pipeline pip)
  1434. sg_fail_view(sg_view view)
  1435. This is recommended if anything went wrong outside of sokol-gfx during asynchronous
  1436. resource setup (for instance a file loading operation failed). In this case,
  1437. the 'fail function' should be called instead of the 'init function'.
  1438. Calling a 'fail function' on a resource that's not in ALLOC state is a no-op,
  1439. but will generate a warning log message.
  1440. NOTE: that two-step resource creation usually only makes sense for buffers,
  1441. images and views, but not for samplers, shaders or pipelines. Most notably, trying
  1442. to create a pipeline object with a shader that's not in VALID state will
  1443. trigger a validation layer error, or if the validation layer is disabled,
  1444. result in a pipeline object in FAILED state.
  1445. WEBGPU CAVEATS
  1446. ==============
  1447. For a general overview and design notes of the WebGPU backend see:
  1448. https://floooh.github.io/2023/10/16/sokol-webgpu.html
  1449. In general, don't expect an automatic speedup when switching from the WebGL2
  1450. backend to the WebGPU backend. Some WebGPU functions currently actually
  1451. have a higher CPU overhead than similar WebGL2 functions, leading to the
  1452. paradoxical situation that some WebGPU code may be slower than similar WebGL2
  1453. code.
  1454. - when writing WGSL shader code by hand, a specific bind-slot convention
  1455. must be used:
  1456. All uniform block structs must use `@group(0)` and bindings in the
  1457. range 0..15
  1458. @group(0) @binding(0..15)
  1459. All textures, samplers, storage-buffers and storage-images must use `@group(1)`
  1460. and bindings must be in the range 0..127:
  1461. @group(1) @binding(0..127)
  1462. Note that the number of texture, sampler, storage-buffer storage-image bindings
  1463. is still limited despite the large bind range:
  1464. - up to 16 textures and sampler across all shader stages
  1465. - up to 8 storage buffers across all shader stages
  1466. - up to 4 storage images on the compute shader stage
  1467. If you use sokol-shdc to generate WGSL shader code, you don't need to worry
  1468. about the above binding conventions since sokol-shdc will allocate
  1469. the WGSL bindslots).
  1470. - The sokol-gfx WebGPU backend uses the sg_desc.uniform_buffer_size item
  1471. to allocate a single per-frame uniform buffer which must be big enough
  1472. to hold all data written by sg_apply_uniforms() during a single frame,
  1473. including a worst-case 256-byte alignment (e.g. each sg_apply_uniform
  1474. call will cost at least 256 bytes of uniform buffer size). The default size
  1475. is 4 MB, which is enough for 16384 sg_apply_uniform() calls per
  1476. frame (assuming the uniform data 'payload' is less than 256 bytes
  1477. per call). These rules are the same as for the Metal backend, so if
  1478. you are already using the Metal backend you'll be fine.
  1479. - sg_apply_bindings(): the sokol-gfx WebGPU backend implements a bindgroup
  1480. cache to prevent excessive creation and destruction of BindGroup objects
  1481. when calling sg_apply_bindings(). The number of slots in the bindgroups
  1482. cache is defined in sg_desc.wgpu.bindgroups_cache_size when calling
  1483. sg_setup. The cache size must be a power-of-2 number, with the default being
  1484. 1024. The bindgroups cache behaviour can be observed by calling the new
  1485. function sg_query_stats(), where the following struct items are
  1486. of interest:
  1487. .wgpu.num_bindgroup_cache_hits
  1488. .wgpu.num_bindgroup_cache_misses
  1489. .wgpu.num_bindgroup_cache_collisions
  1490. .wgpu_num_bindgroup_cache_invalidates
  1491. .wgpu.num_bindgroup_cache_vs_hash_key_mismatch
  1492. The value to pay attention to is `.wgpu.num_bindgroup_cache_collisions`,
  1493. if this number is consistently higher than a few percent of the
  1494. .wgpu.num_set_bindgroup value, it might be a good idea to bump the
  1495. bindgroups cache size to the next power-of-2.
  1496. - sg_apply_viewport(): WebGPU currently has a unique restriction that viewport
  1497. rectangles must be contained entirely within the framebuffer. As a shitty
  1498. workaround sokol_gfx.h will clip incoming viewport rectangles against
  1499. the framebuffer, but this will distort the clipspace-to-screenspace mapping.
  1500. There's no proper way to handle this inside sokol_gfx.h, this must be fixed
  1501. in a future WebGPU update (see: https://github.com/gpuweb/gpuweb/issues/373
  1502. and https://github.com/gpuweb/gpuweb/pull/5025)
  1503. - The sokol shader compiler generally adds `diagnostic(off, derivative_uniformity);`
  1504. into the WGSL output. Currently only the Chrome WebGPU implementation seems
  1505. to recognize this.
  1506. - Likewise, the following sokol-gfx pixel formats are not supported in WebGPU:
  1507. R16, R16SN, RG16, RG16SN, RGBA16, RGBA16SN.
  1508. Unlike unsupported vertex formats, unsupported pixel formats can be queried
  1509. in cross-backend code via sg_query_pixelformat() though.
  1510. - The Emscripten WebGPU shim currently doesn't support the Closure minification
  1511. post-link-step (e.g. currently the emcc argument '--closure 1' or '--closure 2'
  1512. will generate broken Javascript code.
  1513. - sokol-gfx requires the WebGPU device feature `depth32float-stencil8` to be enabled
  1514. (this should be widely supported)
  1515. - sokol-gfx expects that the WebGPU device feature `float32-filterable` to *not* be
  1516. enabled (since this would exclude all iOS devices)
  1517. LICENSE
  1518. =======
  1519. zlib/libpng license
  1520. Copyright (c) 2018 Andre Weissflog
  1521. This software is provided 'as-is', without any express or implied warranty.
  1522. In no event will the authors be held liable for any damages arising from the
  1523. use of this software.
  1524. Permission is granted to anyone to use this software for any purpose,
  1525. including commercial applications, and to alter it and redistribute it
  1526. freely, subject to the following restrictions:
  1527. 1. The origin of this software must not be misrepresented; you must not
  1528. claim that you wrote the original software. If you use this software in a
  1529. product, an acknowledgment in the product documentation would be
  1530. appreciated but is not required.
  1531. 2. Altered source versions must be plainly marked as such, and must not
  1532. be misrepresented as being the original software.
  1533. 3. This notice may not be removed or altered from any source
  1534. distribution.
  1535. */
  1536. import "core:c"
  1537. _ :: c
  1538. SOKOL_DEBUG :: #config(SOKOL_DEBUG, ODIN_DEBUG)
  1539. DEBUG :: #config(SOKOL_GFX_DEBUG, SOKOL_DEBUG)
  1540. USE_GL :: #config(SOKOL_USE_GL, false)
  1541. USE_DLL :: #config(SOKOL_DLL, false)
  1542. when ODIN_OS == .Windows {
  1543. when USE_DLL {
  1544. when USE_GL {
  1545. when DEBUG { foreign import sokol_gfx_clib { "../sokol_dll_windows_x64_gl_debug.lib" } }
  1546. else { foreign import sokol_gfx_clib { "../sokol_dll_windows_x64_gl_release.lib" } }
  1547. } else {
  1548. when DEBUG { foreign import sokol_gfx_clib { "../sokol_dll_windows_x64_d3d11_debug.lib" } }
  1549. else { foreign import sokol_gfx_clib { "../sokol_dll_windows_x64_d3d11_release.lib" } }
  1550. }
  1551. } else {
  1552. when USE_GL {
  1553. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_windows_x64_gl_debug.lib" } }
  1554. else { foreign import sokol_gfx_clib { "sokol_gfx_windows_x64_gl_release.lib" } }
  1555. } else {
  1556. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_windows_x64_d3d11_debug.lib" } }
  1557. else { foreign import sokol_gfx_clib { "sokol_gfx_windows_x64_d3d11_release.lib" } }
  1558. }
  1559. }
  1560. } else when ODIN_OS == .Darwin {
  1561. when USE_DLL {
  1562. when USE_GL && ODIN_ARCH == .arm64 && DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_arm64_gl_debug.dylib" } }
  1563. else when USE_GL && ODIN_ARCH == .arm64 && !DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_arm64_gl_release.dylib" } }
  1564. else when USE_GL && ODIN_ARCH == .amd64 && DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_x64_gl_debug.dylib" } }
  1565. else when USE_GL && ODIN_ARCH == .amd64 && !DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_x64_gl_release.dylib" } }
  1566. else when !USE_GL && ODIN_ARCH == .arm64 && DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_arm64_metal_debug.dylib" } }
  1567. else when !USE_GL && ODIN_ARCH == .arm64 && !DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_arm64_metal_release.dylib" } }
  1568. else when !USE_GL && ODIN_ARCH == .amd64 && DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_x64_metal_debug.dylib" } }
  1569. else when !USE_GL && ODIN_ARCH == .amd64 && !DEBUG { foreign import sokol_gfx_clib { "../dylib/sokol_dylib_macos_x64_metal_release.dylib" } }
  1570. } else {
  1571. when USE_GL {
  1572. when ODIN_ARCH == .arm64 {
  1573. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_macos_arm64_gl_debug.a", "system:Cocoa.framework","system:QuartzCore.framework","system:OpenGL.framework" } }
  1574. else { foreign import sokol_gfx_clib { "sokol_gfx_macos_arm64_gl_release.a", "system:Cocoa.framework","system:QuartzCore.framework","system:OpenGL.framework" } }
  1575. } else {
  1576. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_macos_x64_gl_debug.a", "system:Cocoa.framework","system:QuartzCore.framework","system:OpenGL.framework" } }
  1577. else { foreign import sokol_gfx_clib { "sokol_gfx_macos_x64_gl_release.a", "system:Cocoa.framework","system:QuartzCore.framework","system:OpenGL.framework" } }
  1578. }
  1579. } else {
  1580. when ODIN_ARCH == .arm64 {
  1581. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_macos_arm64_metal_debug.a", "system:Cocoa.framework","system:QuartzCore.framework","system:Metal.framework","system:MetalKit.framework" } }
  1582. else { foreign import sokol_gfx_clib { "sokol_gfx_macos_arm64_metal_release.a", "system:Cocoa.framework","system:QuartzCore.framework","system:Metal.framework","system:MetalKit.framework" } }
  1583. } else {
  1584. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_macos_x64_metal_debug.a", "system:Cocoa.framework","system:QuartzCore.framework","system:Metal.framework","system:MetalKit.framework" } }
  1585. else { foreign import sokol_gfx_clib { "sokol_gfx_macos_x64_metal_release.a", "system:Cocoa.framework","system:QuartzCore.framework","system:Metal.framework","system:MetalKit.framework" } }
  1586. }
  1587. }
  1588. }
  1589. } else when ODIN_OS == .Linux {
  1590. when USE_DLL {
  1591. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_linux_x64_gl_debug.so", "system:GL", "system:dl", "system:pthread" } }
  1592. else { foreign import sokol_gfx_clib { "sokol_gfx_linux_x64_gl_release.so", "system:GL", "system:dl", "system:pthread" } }
  1593. } else {
  1594. when DEBUG { foreign import sokol_gfx_clib { "sokol_gfx_linux_x64_gl_debug.a", "system:GL", "system:dl", "system:pthread" } }
  1595. else { foreign import sokol_gfx_clib { "sokol_gfx_linux_x64_gl_release.a", "system:GL", "system:dl", "system:pthread" } }
  1596. }
  1597. } else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 {
  1598. // Feed sokol_gfx_wasm_gl_debug.a or sokol_gfx_wasm_gl_release.a into emscripten compiler.
  1599. foreign import sokol_gfx_clib { "env.o" }
  1600. } else {
  1601. #panic("This OS is currently not supported")
  1602. }
  1603. @(default_calling_convention="c", link_prefix="sg_")
  1604. foreign sokol_gfx_clib {
  1605. // setup and misc functions
  1606. setup :: proc(#by_ptr desc: Desc) ---
  1607. shutdown :: proc() ---
  1608. isvalid :: proc() -> bool ---
  1609. reset_state_cache :: proc() ---
  1610. push_debug_group :: proc(name: cstring) ---
  1611. pop_debug_group :: proc() ---
  1612. add_commit_listener :: proc(listener: Commit_Listener) -> bool ---
  1613. remove_commit_listener :: proc(listener: Commit_Listener) -> bool ---
  1614. // resource creation, destruction and updating
  1615. make_buffer :: proc(#by_ptr desc: Buffer_Desc) -> Buffer ---
  1616. make_image :: proc(#by_ptr desc: Image_Desc) -> Image ---
  1617. make_sampler :: proc(#by_ptr desc: Sampler_Desc) -> Sampler ---
  1618. make_shader :: proc(#by_ptr desc: Shader_Desc) -> Shader ---
  1619. make_pipeline :: proc(#by_ptr desc: Pipeline_Desc) -> Pipeline ---
  1620. make_view :: proc(#by_ptr desc: View_Desc) -> View ---
  1621. destroy_buffer :: proc(buf: Buffer) ---
  1622. destroy_image :: proc(img: Image) ---
  1623. destroy_sampler :: proc(smp: Sampler) ---
  1624. destroy_shader :: proc(shd: Shader) ---
  1625. destroy_pipeline :: proc(pip: Pipeline) ---
  1626. destroy_view :: proc(view: View) ---
  1627. update_buffer :: proc(buf: Buffer, #by_ptr data: Range) ---
  1628. update_image :: proc(img: Image, #by_ptr data: Image_Data) ---
  1629. append_buffer :: proc(buf: Buffer, #by_ptr data: Range) -> c.int ---
  1630. query_buffer_overflow :: proc(buf: Buffer) -> bool ---
  1631. query_buffer_will_overflow :: proc(buf: Buffer, size: c.size_t) -> bool ---
  1632. // render and compute functions
  1633. begin_pass :: proc(#by_ptr pass: Pass) ---
  1634. apply_viewport :: proc(#any_int x: c.int, #any_int y: c.int, #any_int width: c.int, #any_int height: c.int, origin_top_left: bool) ---
  1635. apply_viewportf :: proc(x: f32, y: f32, width: f32, height: f32, origin_top_left: bool) ---
  1636. apply_scissor_rect :: proc(#any_int x: c.int, #any_int y: c.int, #any_int width: c.int, #any_int height: c.int, origin_top_left: bool) ---
  1637. apply_scissor_rectf :: proc(x: f32, y: f32, width: f32, height: f32, origin_top_left: bool) ---
  1638. apply_pipeline :: proc(pip: Pipeline) ---
  1639. apply_bindings :: proc(#by_ptr bindings: Bindings) ---
  1640. apply_uniforms :: proc(#any_int ub_slot: c.int, #by_ptr data: Range) ---
  1641. draw :: proc(#any_int base_element: c.int, #any_int num_elements: c.int, #any_int num_instances: c.int) ---
  1642. draw_ex :: proc(#any_int base_element: c.int, #any_int num_elements: c.int, #any_int num_instances: c.int, #any_int base_vertex: c.int, #any_int base_instance: c.int) ---
  1643. dispatch :: proc(#any_int num_groups_x: c.int, #any_int num_groups_y: c.int, #any_int num_groups_z: c.int) ---
  1644. end_pass :: proc() ---
  1645. commit :: proc() ---
  1646. // getting information
  1647. query_desc :: proc() -> Desc ---
  1648. query_backend :: proc() -> Backend ---
  1649. query_features :: proc() -> Features ---
  1650. query_limits :: proc() -> Limits ---
  1651. query_pixelformat :: proc(fmt: Pixel_Format) -> Pixelformat_Info ---
  1652. query_row_pitch :: proc(fmt: Pixel_Format, #any_int width: c.int, #any_int row_align_bytes: c.int) -> c.int ---
  1653. query_surface_pitch :: proc(fmt: Pixel_Format, #any_int width: c.int, #any_int height: c.int, #any_int row_align_bytes: c.int) -> c.int ---
  1654. // get current state of a resource (INITIAL, ALLOC, VALID, FAILED, INVALID)
  1655. query_buffer_state :: proc(buf: Buffer) -> Resource_State ---
  1656. query_image_state :: proc(img: Image) -> Resource_State ---
  1657. query_sampler_state :: proc(smp: Sampler) -> Resource_State ---
  1658. query_shader_state :: proc(shd: Shader) -> Resource_State ---
  1659. query_pipeline_state :: proc(pip: Pipeline) -> Resource_State ---
  1660. query_view_state :: proc(view: View) -> Resource_State ---
  1661. // get runtime information about a resource
  1662. query_buffer_info :: proc(buf: Buffer) -> Buffer_Info ---
  1663. query_image_info :: proc(img: Image) -> Image_Info ---
  1664. query_sampler_info :: proc(smp: Sampler) -> Sampler_Info ---
  1665. query_shader_info :: proc(shd: Shader) -> Shader_Info ---
  1666. query_pipeline_info :: proc(pip: Pipeline) -> Pipeline_Info ---
  1667. query_view_info :: proc(view: View) -> View_Info ---
  1668. // get desc structs matching a specific resource (NOTE that not all creation attributes may be provided)
  1669. query_buffer_desc :: proc(buf: Buffer) -> Buffer_Desc ---
  1670. query_image_desc :: proc(img: Image) -> Image_Desc ---
  1671. query_sampler_desc :: proc(smp: Sampler) -> Sampler_Desc ---
  1672. query_shader_desc :: proc(shd: Shader) -> Shader_Desc ---
  1673. query_pipeline_desc :: proc(pip: Pipeline) -> Pipeline_Desc ---
  1674. query_view_desc :: proc(view: View) -> View_Desc ---
  1675. // get resource creation desc struct with their default values replaced
  1676. query_buffer_defaults :: proc(#by_ptr desc: Buffer_Desc) -> Buffer_Desc ---
  1677. query_image_defaults :: proc(#by_ptr desc: Image_Desc) -> Image_Desc ---
  1678. query_sampler_defaults :: proc(#by_ptr desc: Sampler_Desc) -> Sampler_Desc ---
  1679. query_shader_defaults :: proc(#by_ptr desc: Shader_Desc) -> Shader_Desc ---
  1680. query_pipeline_defaults :: proc(#by_ptr desc: Pipeline_Desc) -> Pipeline_Desc ---
  1681. query_view_defaults :: proc(#by_ptr desc: View_Desc) -> View_Desc ---
  1682. // assorted query functions
  1683. query_buffer_size :: proc(buf: Buffer) -> c.size_t ---
  1684. query_buffer_usage :: proc(buf: Buffer) -> Buffer_Usage ---
  1685. query_image_type :: proc(img: Image) -> Image_Type ---
  1686. query_image_width :: proc(img: Image) -> c.int ---
  1687. query_image_height :: proc(img: Image) -> c.int ---
  1688. query_image_num_slices :: proc(img: Image) -> c.int ---
  1689. query_image_num_mipmaps :: proc(img: Image) -> c.int ---
  1690. query_image_pixelformat :: proc(img: Image) -> Pixel_Format ---
  1691. query_image_usage :: proc(img: Image) -> Image_Usage ---
  1692. query_image_sample_count :: proc(img: Image) -> c.int ---
  1693. query_view_type :: proc(view: View) -> View_Type ---
  1694. query_view_image :: proc(view: View) -> Image ---
  1695. query_view_buffer :: proc(view: View) -> Buffer ---
  1696. // separate resource allocation and initialization (for async setup)
  1697. alloc_buffer :: proc() -> Buffer ---
  1698. alloc_image :: proc() -> Image ---
  1699. alloc_sampler :: proc() -> Sampler ---
  1700. alloc_shader :: proc() -> Shader ---
  1701. alloc_pipeline :: proc() -> Pipeline ---
  1702. alloc_view :: proc() -> View ---
  1703. dealloc_buffer :: proc(buf: Buffer) ---
  1704. dealloc_image :: proc(img: Image) ---
  1705. dealloc_sampler :: proc(smp: Sampler) ---
  1706. dealloc_shader :: proc(shd: Shader) ---
  1707. dealloc_pipeline :: proc(pip: Pipeline) ---
  1708. dealloc_view :: proc(view: View) ---
  1709. init_buffer :: proc(buf: Buffer, #by_ptr desc: Buffer_Desc) ---
  1710. init_image :: proc(img: Image, #by_ptr desc: Image_Desc) ---
  1711. init_sampler :: proc(smg: Sampler, #by_ptr desc: Sampler_Desc) ---
  1712. init_shader :: proc(shd: Shader, #by_ptr desc: Shader_Desc) ---
  1713. init_pipeline :: proc(pip: Pipeline, #by_ptr desc: Pipeline_Desc) ---
  1714. init_view :: proc(view: View, #by_ptr desc: View_Desc) ---
  1715. uninit_buffer :: proc(buf: Buffer) ---
  1716. uninit_image :: proc(img: Image) ---
  1717. uninit_sampler :: proc(smp: Sampler) ---
  1718. uninit_shader :: proc(shd: Shader) ---
  1719. uninit_pipeline :: proc(pip: Pipeline) ---
  1720. uninit_view :: proc(view: View) ---
  1721. fail_buffer :: proc(buf: Buffer) ---
  1722. fail_image :: proc(img: Image) ---
  1723. fail_sampler :: proc(smp: Sampler) ---
  1724. fail_shader :: proc(shd: Shader) ---
  1725. fail_pipeline :: proc(pip: Pipeline) ---
  1726. fail_view :: proc(view: View) ---
  1727. // frame and total stats
  1728. enable_stats :: proc() ---
  1729. disable_stats :: proc() ---
  1730. stats_enabled :: proc() -> bool ---
  1731. query_stats :: proc() -> Stats ---
  1732. // D3D11: return ID3D11Device
  1733. d3d11_device :: proc() -> rawptr ---
  1734. // D3D11: return ID3D11DeviceContext
  1735. d3d11_device_context :: proc() -> rawptr ---
  1736. // D3D11: get internal buffer resource objects
  1737. d3d11_query_buffer_info :: proc(buf: Buffer) -> D3d11_Buffer_Info ---
  1738. // D3D11: get internal image resource objects
  1739. d3d11_query_image_info :: proc(img: Image) -> D3d11_Image_Info ---
  1740. // D3D11: get internal sampler resource objects
  1741. d3d11_query_sampler_info :: proc(smp: Sampler) -> D3d11_Sampler_Info ---
  1742. // D3D11: get internal shader resource objects
  1743. d3d11_query_shader_info :: proc(shd: Shader) -> D3d11_Shader_Info ---
  1744. // D3D11: get internal pipeline resource objects
  1745. d3d11_query_pipeline_info :: proc(pip: Pipeline) -> D3d11_Pipeline_Info ---
  1746. // D3D11: get internal view resource objects
  1747. d3d11_query_view_info :: proc(view: View) -> D3d11_View_Info ---
  1748. // Metal: return __bridge-casted MTLDevice
  1749. mtl_device :: proc() -> rawptr ---
  1750. // Metal: return __bridge-casted MTLRenderCommandEncoder when inside render pass (otherwise zero)
  1751. mtl_render_command_encoder :: proc() -> rawptr ---
  1752. // Metal: return __bridge-casted MTLComputeCommandEncoder when inside compute pass (otherwise zero)
  1753. mtl_compute_command_encoder :: proc() -> rawptr ---
  1754. // Metal: get internal __bridge-casted buffer resource objects
  1755. mtl_query_buffer_info :: proc(buf: Buffer) -> Mtl_Buffer_Info ---
  1756. // Metal: get internal __bridge-casted image resource objects
  1757. mtl_query_image_info :: proc(img: Image) -> Mtl_Image_Info ---
  1758. // Metal: get internal __bridge-casted sampler resource objects
  1759. mtl_query_sampler_info :: proc(smp: Sampler) -> Mtl_Sampler_Info ---
  1760. // Metal: get internal __bridge-casted shader resource objects
  1761. mtl_query_shader_info :: proc(shd: Shader) -> Mtl_Shader_Info ---
  1762. // Metal: get internal __bridge-casted pipeline resource objects
  1763. mtl_query_pipeline_info :: proc(pip: Pipeline) -> Mtl_Pipeline_Info ---
  1764. // WebGPU: return WGPUDevice object
  1765. wgpu_device :: proc() -> rawptr ---
  1766. // WebGPU: return WGPUQueue object
  1767. wgpu_queue :: proc() -> rawptr ---
  1768. // WebGPU: return this frame's WGPUCommandEncoder
  1769. wgpu_command_encoder :: proc() -> rawptr ---
  1770. // WebGPU: return WGPURenderPassEncoder of current pass (returns 0 when outside pass or in a compute pass)
  1771. wgpu_render_pass_encoder :: proc() -> rawptr ---
  1772. // WebGPU: return WGPUComputePassEncoder of current pass (returns 0 when outside pass or in a render pass)
  1773. wgpu_compute_pass_encoder :: proc() -> rawptr ---
  1774. // WebGPU: get internal buffer resource objects
  1775. wgpu_query_buffer_info :: proc(buf: Buffer) -> Wgpu_Buffer_Info ---
  1776. // WebGPU: get internal image resource objects
  1777. wgpu_query_image_info :: proc(img: Image) -> Wgpu_Image_Info ---
  1778. // WebGPU: get internal sampler resource objects
  1779. wgpu_query_sampler_info :: proc(smp: Sampler) -> Wgpu_Sampler_Info ---
  1780. // WebGPU: get internal shader resource objects
  1781. wgpu_query_shader_info :: proc(shd: Shader) -> Wgpu_Shader_Info ---
  1782. // WebGPU: get internal pipeline resource objects
  1783. wgpu_query_pipeline_info :: proc(pip: Pipeline) -> Wgpu_Pipeline_Info ---
  1784. // WebGPU: get internal view resource objects
  1785. wgpu_query_view_info :: proc(view: View) -> Wgpu_View_Info ---
  1786. // GL: get internal buffer resource objects
  1787. gl_query_buffer_info :: proc(buf: Buffer) -> Gl_Buffer_Info ---
  1788. // GL: get internal image resource objects
  1789. gl_query_image_info :: proc(img: Image) -> Gl_Image_Info ---
  1790. // GL: get internal sampler resource objects
  1791. gl_query_sampler_info :: proc(smp: Sampler) -> Gl_Sampler_Info ---
  1792. // GL: get internal shader resource objects
  1793. gl_query_shader_info :: proc(shd: Shader) -> Gl_Shader_Info ---
  1794. // GL: get internal view resource objects
  1795. gl_query_view_info :: proc(view: View) -> Gl_View_Info ---
  1796. }
  1797. /*
  1798. Resource id typedefs:
  1799. sg_buffer: vertex- and index-buffers
  1800. sg_image: images used as textures and render-pass attachments
  1801. sg_sampler sampler objects describing how a texture is sampled in a shader
  1802. sg_shader: vertex- and fragment-shaders and shader interface information
  1803. sg_pipeline: associated shader and vertex-layouts, and render states
  1804. sg_view: a resource view object used for bindings and render-pass attachments
  1805. Instead of pointers, resource creation functions return a 32-bit
  1806. handle which uniquely identifies the resource object.
  1807. The 32-bit resource id is split into a 16-bit pool index in the lower bits,
  1808. and a 16-bit 'generation counter' in the upper bits. The index allows fast
  1809. pool lookups, and combined with the generation-counter it allows to detect
  1810. 'dangling accesses' (trying to use an object which no longer exists, and
  1811. its pool slot has been reused for a new object)
  1812. The resource ids are wrapped into a strongly-typed struct so that
  1813. trying to pass an incompatible resource id is a compile error.
  1814. */
  1815. Buffer :: struct {
  1816. id : u32,
  1817. }
  1818. Image :: struct {
  1819. id : u32,
  1820. }
  1821. Sampler :: struct {
  1822. id : u32,
  1823. }
  1824. Shader :: struct {
  1825. id : u32,
  1826. }
  1827. Pipeline :: struct {
  1828. id : u32,
  1829. }
  1830. View :: struct {
  1831. id : u32,
  1832. }
  1833. /*
  1834. sg_range is a pointer-size-pair struct used to pass memory blobs into
  1835. sokol-gfx. When initialized from a value type (array or struct), you can
  1836. use the SG_RANGE() macro to build an sg_range struct. For functions which
  1837. take either a sg_range pointer, or a (C++) sg_range reference, use the
  1838. SG_RANGE_REF macro as a solution which compiles both in C and C++.
  1839. */
  1840. Range :: struct {
  1841. ptr : rawptr,
  1842. size : c.size_t,
  1843. }
  1844. // various compile-time constants in the public API
  1845. INVALID_ID :: 0
  1846. NUM_INFLIGHT_FRAMES :: 2
  1847. MAX_COLOR_ATTACHMENTS :: 8
  1848. MAX_UNIFORMBLOCK_MEMBERS :: 16
  1849. MAX_VERTEX_ATTRIBUTES :: 16
  1850. MAX_MIPMAPS :: 16
  1851. MAX_VERTEXBUFFER_BINDSLOTS :: 8
  1852. MAX_UNIFORMBLOCK_BINDSLOTS :: 8
  1853. MAX_VIEW_BINDSLOTS :: 32
  1854. MAX_SAMPLER_BINDSLOTS :: 12
  1855. MAX_TEXTURE_SAMPLER_PAIRS :: 32
  1856. MAX_PORTABLE_COLOR_ATTACHMENTS :: 4
  1857. MAX_PORTABLE_TEXTURE_BINDINGS_PER_STAGE :: 16
  1858. MAX_PORTABLE_STORAGEBUFFER_BINDINGS_PER_STAGE :: 8
  1859. MAX_PORTABLE_STORAGEIMAGE_BINDINGS_PER_STAGE :: 4
  1860. /*
  1861. sg_color
  1862. An RGBA color value.
  1863. */
  1864. Color :: struct {
  1865. r : f32,
  1866. g : f32,
  1867. b : f32,
  1868. a : f32,
  1869. }
  1870. /*
  1871. sg_backend
  1872. The active 3D-API backend, use the function sg_query_backend()
  1873. to get the currently active backend.
  1874. */
  1875. Backend :: enum i32 {
  1876. GLCORE,
  1877. GLES3,
  1878. D3D11,
  1879. METAL_IOS,
  1880. METAL_MACOS,
  1881. METAL_SIMULATOR,
  1882. WGPU,
  1883. VULKAN,
  1884. DUMMY,
  1885. }
  1886. /*
  1887. sg_pixel_format
  1888. sokol_gfx.h basically uses the same pixel formats as WebGPU, since these
  1889. are supported on most newer GPUs.
  1890. A pixelformat name consist of three parts:
  1891. - components (R, RG, RGB or RGBA)
  1892. - bit width per component (8, 16 or 32)
  1893. - component data type:
  1894. - unsigned normalized (no postfix)
  1895. - signed normalized (SN postfix)
  1896. - unsigned integer (UI postfix)
  1897. - signed integer (SI postfix)
  1898. - float (F postfix)
  1899. Not all pixel formats can be used for everything, call sg_query_pixelformat()
  1900. to inspect the capabilities of a given pixelformat. The function returns
  1901. an sg_pixelformat_info struct with the following members:
  1902. - sample: the pixelformat can be sampled as texture at least with
  1903. nearest filtering
  1904. - filter: the pixelformat can be sampled as texture with linear
  1905. filtering
  1906. - render: the pixelformat can be used as render-pass attachment
  1907. - blend: blending is supported when used as render-pass attachment
  1908. - msaa: multisample-antialiasing is supported when used
  1909. as render-pass attachment
  1910. - depth: the pixelformat can be used for depth-stencil attachments
  1911. - compressed: this is a block-compressed format
  1912. - bytes_per_pixel: the numbers of bytes in a pixel (0 for compressed formats)
  1913. The default pixel format for texture images is SG_PIXELFORMAT_RGBA8.
  1914. The default pixel format for render target images is platform-dependent
  1915. and taken from the sg_environment struct passed into sg_setup(). Typically
  1916. the default formats are:
  1917. - for the Metal, D3D11 and WebGPU backends: SG_PIXELFORMAT_BGRA8
  1918. - for GL backends: SG_PIXELFORMAT_RGBA8
  1919. */
  1920. Pixel_Format :: enum i32 {
  1921. DEFAULT,
  1922. NONE,
  1923. R8,
  1924. R8SN,
  1925. R8UI,
  1926. R8SI,
  1927. R16,
  1928. R16SN,
  1929. R16UI,
  1930. R16SI,
  1931. R16F,
  1932. RG8,
  1933. RG8SN,
  1934. RG8UI,
  1935. RG8SI,
  1936. R32UI,
  1937. R32SI,
  1938. R32F,
  1939. RG16,
  1940. RG16SN,
  1941. RG16UI,
  1942. RG16SI,
  1943. RG16F,
  1944. RGBA8,
  1945. SRGB8A8,
  1946. RGBA8SN,
  1947. RGBA8UI,
  1948. RGBA8SI,
  1949. BGRA8,
  1950. RGB10A2,
  1951. RG11B10F,
  1952. RGB9E5,
  1953. RG32UI,
  1954. RG32SI,
  1955. RG32F,
  1956. RGBA16,
  1957. RGBA16SN,
  1958. RGBA16UI,
  1959. RGBA16SI,
  1960. RGBA16F,
  1961. RGBA32UI,
  1962. RGBA32SI,
  1963. RGBA32F,
  1964. DEPTH,
  1965. DEPTH_STENCIL,
  1966. BC1_RGBA,
  1967. BC2_RGBA,
  1968. BC3_RGBA,
  1969. BC3_SRGBA,
  1970. BC4_R,
  1971. BC4_RSN,
  1972. BC5_RG,
  1973. BC5_RGSN,
  1974. BC6H_RGBF,
  1975. BC6H_RGBUF,
  1976. BC7_RGBA,
  1977. BC7_SRGBA,
  1978. ETC2_RGB8,
  1979. ETC2_SRGB8,
  1980. ETC2_RGB8A1,
  1981. ETC2_RGBA8,
  1982. ETC2_SRGB8A8,
  1983. EAC_R11,
  1984. EAC_R11SN,
  1985. EAC_RG11,
  1986. EAC_RG11SN,
  1987. ASTC_4x4_RGBA,
  1988. ASTC_4x4_SRGBA,
  1989. }
  1990. // Runtime information about a pixel format, returned by sg_query_pixelformat().
  1991. Pixelformat_Info :: struct {
  1992. sample : bool,
  1993. filter : bool,
  1994. render : bool,
  1995. blend : bool,
  1996. msaa : bool,
  1997. depth : bool,
  1998. compressed : bool,
  1999. read : bool,
  2000. write : bool,
  2001. bytes_per_pixel : c.int,
  2002. }
  2003. // Runtime information about available optional features, returned by sg_query_features()
  2004. Features :: struct {
  2005. origin_top_left : bool,
  2006. image_clamp_to_border : bool,
  2007. mrt_independent_blend_state : bool,
  2008. mrt_independent_write_mask : bool,
  2009. compute : bool,
  2010. msaa_texture_bindings : bool,
  2011. separate_buffer_types : bool,
  2012. draw_base_vertex : bool,
  2013. draw_base_instance : bool,
  2014. gl_texture_views : bool,
  2015. }
  2016. // Runtime information about resource limits, returned by sg_query_limit()
  2017. Limits :: struct {
  2018. max_image_size_2d : c.int,
  2019. max_image_size_cube : c.int,
  2020. max_image_size_3d : c.int,
  2021. max_image_size_array : c.int,
  2022. max_image_array_layers : c.int,
  2023. max_vertex_attrs : c.int,
  2024. max_color_attachments : c.int,
  2025. max_texture_bindings_per_stage : c.int,
  2026. max_storage_buffer_bindings_per_stage : c.int,
  2027. max_storage_image_bindings_per_stage : c.int,
  2028. gl_max_vertex_uniform_components : c.int,
  2029. gl_max_combined_texture_image_units : c.int,
  2030. d3d11_max_unordered_access_views : c.int,
  2031. vk_min_uniform_buffer_offset_alignment : c.int,
  2032. }
  2033. /*
  2034. sg_resource_state
  2035. The current state of a resource in its resource pool.
  2036. Resources start in the INITIAL state, which means the
  2037. pool slot is unoccupied and can be allocated. When a resource is
  2038. created, first an id is allocated, and the resource pool slot
  2039. is set to state ALLOC. After allocation, the resource is
  2040. initialized, which may result in the VALID or FAILED state. The
  2041. reason why allocation and initialization are separate is because
  2042. some resource types (e.g. buffers and images) might be asynchronously
  2043. initialized by the user application. If a resource which is not
  2044. in the VALID state is attempted to be used for rendering, rendering
  2045. operations will silently be dropped.
  2046. The special INVALID state is returned in sg_query_xxx_state() if no
  2047. resource object exists for the provided resource id.
  2048. */
  2049. Resource_State :: enum i32 {
  2050. INITIAL,
  2051. ALLOC,
  2052. VALID,
  2053. FAILED,
  2054. INVALID,
  2055. }
  2056. /*
  2057. sg_index_type
  2058. Indicates whether indexed rendering (fetching vertex-indices from an
  2059. index buffer) is used, and if yes, the index data type (16- or 32-bits).
  2060. This is used in the sg_pipeline_desc.index_type member when creating a
  2061. pipeline object.
  2062. The default index type is SG_INDEXTYPE_NONE.
  2063. */
  2064. Index_Type :: enum i32 {
  2065. DEFAULT,
  2066. NONE,
  2067. UINT16,
  2068. UINT32,
  2069. }
  2070. /*
  2071. sg_image_type
  2072. Indicates the basic type of an image object (2D-texture, cubemap,
  2073. 3D-texture or 2D-array-texture). Used in the sg_image_desc.type member when
  2074. creating an image, and in sg_shader_image_desc to describe a sampled texture
  2075. in the shader (both must match and will be checked in the validation layer
  2076. when calling sg_apply_bindings).
  2077. The default image type when creating an image is SG_IMAGETYPE_2D.
  2078. */
  2079. Image_Type :: enum i32 {
  2080. DEFAULT,
  2081. _2D,
  2082. CUBE,
  2083. _3D,
  2084. ARRAY,
  2085. }
  2086. /*
  2087. sg_image_sample_type
  2088. The basic data type of a texture sample as expected by a shader.
  2089. Must be provided in sg_shader_image and used by the validation
  2090. layer in sg_apply_bindings() to check if the provided image object
  2091. is compatible with what the shader expects. Apart from the sokol-gfx
  2092. validation layer, WebGPU is the only backend API which actually requires
  2093. matching texture and sampler type to be provided upfront for validation
  2094. (other 3D APIs treat texture/sampler type mismatches as undefined behaviour).
  2095. NOTE that the following texture pixel formats require the use
  2096. of SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT, combined with a sampler
  2097. of type SG_SAMPLERTYPE_NONFILTERING:
  2098. - SG_PIXELFORMAT_R32F
  2099. - SG_PIXELFORMAT_RG32F
  2100. - SG_PIXELFORMAT_RGBA32F
  2101. (when using sokol-shdc, also check out the meta tags `@image_sample_type`
  2102. and `@sampler_type`)
  2103. */
  2104. Image_Sample_Type :: enum i32 {
  2105. DEFAULT,
  2106. FLOAT,
  2107. DEPTH,
  2108. SINT,
  2109. UINT,
  2110. UNFILTERABLE_FLOAT,
  2111. }
  2112. /*
  2113. sg_sampler_type
  2114. The basic type of a texture sampler (sampling vs comparison) as
  2115. defined in a shader. Must be provided in sg_shader_sampler_desc.
  2116. sg_image_sample_type and sg_sampler_type for a texture/sampler
  2117. pair must be compatible with each other, specifically only
  2118. the following pairs are allowed:
  2119. - SG_IMAGESAMPLETYPE_FLOAT => (SG_SAMPLERTYPE_FILTERING or SG_SAMPLERTYPE_NONFILTERING)
  2120. - SG_IMAGESAMPLETYPE_UNFILTERABLE_FLOAT => SG_SAMPLERTYPE_NONFILTERING
  2121. - SG_IMAGESAMPLETYPE_SINT => SG_SAMPLERTYPE_NONFILTERING
  2122. - SG_IMAGESAMPLETYPE_UINT => SG_SAMPLERTYPE_NONFILTERING
  2123. - SG_IMAGESAMPLETYPE_DEPTH => SG_SAMPLERTYPE_COMPARISON
  2124. */
  2125. Sampler_Type :: enum i32 {
  2126. DEFAULT,
  2127. FILTERING,
  2128. NONFILTERING,
  2129. COMPARISON,
  2130. }
  2131. /*
  2132. sg_primitive_type
  2133. This is the common subset of 3D primitive types supported across all 3D
  2134. APIs. This is used in the sg_pipeline_desc.primitive_type member when
  2135. creating a pipeline object.
  2136. The default primitive type is SG_PRIMITIVETYPE_TRIANGLES.
  2137. */
  2138. Primitive_Type :: enum i32 {
  2139. DEFAULT,
  2140. POINTS,
  2141. LINES,
  2142. LINE_STRIP,
  2143. TRIANGLES,
  2144. TRIANGLE_STRIP,
  2145. }
  2146. /*
  2147. sg_filter
  2148. The filtering mode when sampling a texture image. This is
  2149. used in the sg_sampler_desc.min_filter, sg_sampler_desc.mag_filter
  2150. and sg_sampler_desc.mipmap_filter members when creating a sampler object.
  2151. For the default is SG_FILTER_NEAREST.
  2152. */
  2153. Filter :: enum i32 {
  2154. DEFAULT,
  2155. NEAREST,
  2156. LINEAR,
  2157. }
  2158. /*
  2159. sg_wrap
  2160. The texture coordinates wrapping mode when sampling a texture
  2161. image. This is used in the sg_image_desc.wrap_u, .wrap_v
  2162. and .wrap_w members when creating an image.
  2163. The default wrap mode is SG_WRAP_REPEAT.
  2164. NOTE: SG_WRAP_CLAMP_TO_BORDER is not supported on all backends
  2165. and platforms. To check for support, call sg_query_features()
  2166. and check the "clamp_to_border" boolean in the returned
  2167. sg_features struct.
  2168. Platforms which don't support SG_WRAP_CLAMP_TO_BORDER will silently fall back
  2169. to SG_WRAP_CLAMP_TO_EDGE without a validation error.
  2170. */
  2171. Wrap :: enum i32 {
  2172. DEFAULT,
  2173. REPEAT,
  2174. CLAMP_TO_EDGE,
  2175. CLAMP_TO_BORDER,
  2176. MIRRORED_REPEAT,
  2177. }
  2178. /*
  2179. sg_border_color
  2180. The border color to use when sampling a texture, and the UV wrap
  2181. mode is SG_WRAP_CLAMP_TO_BORDER.
  2182. The default border color is SG_BORDERCOLOR_OPAQUE_BLACK
  2183. */
  2184. Border_Color :: enum i32 {
  2185. DEFAULT,
  2186. TRANSPARENT_BLACK,
  2187. OPAQUE_BLACK,
  2188. OPAQUE_WHITE,
  2189. }
  2190. /*
  2191. sg_vertex_format
  2192. The data type of a vertex component. This is used to describe
  2193. the layout of input vertex data when creating a pipeline object.
  2194. NOTE that specific mapping rules exist from the CPU-side vertex
  2195. formats to the vertex attribute base type in the vertex shader code
  2196. (see doc header section 'ON VERTEX FORMATS').
  2197. */
  2198. Vertex_Format :: enum i32 {
  2199. INVALID,
  2200. FLOAT,
  2201. FLOAT2,
  2202. FLOAT3,
  2203. FLOAT4,
  2204. INT,
  2205. INT2,
  2206. INT3,
  2207. INT4,
  2208. UINT,
  2209. UINT2,
  2210. UINT3,
  2211. UINT4,
  2212. BYTE4,
  2213. BYTE4N,
  2214. UBYTE4,
  2215. UBYTE4N,
  2216. SHORT2,
  2217. SHORT2N,
  2218. USHORT2,
  2219. USHORT2N,
  2220. SHORT4,
  2221. SHORT4N,
  2222. USHORT4,
  2223. USHORT4N,
  2224. UINT10_N2,
  2225. HALF2,
  2226. HALF4,
  2227. }
  2228. /*
  2229. sg_vertex_step
  2230. Defines whether the input pointer of a vertex input stream is advanced
  2231. 'per vertex' or 'per instance'. The default step-func is
  2232. SG_VERTEXSTEP_PER_VERTEX. SG_VERTEXSTEP_PER_INSTANCE is used with
  2233. instanced-rendering.
  2234. The vertex-step is part of the vertex-layout definition
  2235. when creating pipeline objects.
  2236. */
  2237. Vertex_Step :: enum i32 {
  2238. DEFAULT,
  2239. PER_VERTEX,
  2240. PER_INSTANCE,
  2241. }
  2242. /*
  2243. sg_uniform_type
  2244. The data type of a uniform block member. This is used to
  2245. describe the internal layout of uniform blocks when creating
  2246. a shader object. This is only required for the GL backend, all
  2247. other backends will ignore the interior layout of uniform blocks.
  2248. */
  2249. Uniform_Type :: enum i32 {
  2250. INVALID,
  2251. FLOAT,
  2252. FLOAT2,
  2253. FLOAT3,
  2254. FLOAT4,
  2255. INT,
  2256. INT2,
  2257. INT3,
  2258. INT4,
  2259. MAT4,
  2260. }
  2261. /*
  2262. sg_uniform_layout
  2263. A hint for the interior memory layout of uniform blocks. This is
  2264. only relevant for the GL backend where the internal layout
  2265. of uniform blocks must be known to sokol-gfx. For all other backends the
  2266. internal memory layout of uniform blocks doesn't matter, sokol-gfx
  2267. will just pass uniform data as an opaque memory blob to the
  2268. 3D backend.
  2269. SG_UNIFORMLAYOUT_NATIVE (default)
  2270. Native layout means that a 'backend-native' memory layout
  2271. is used. For the GL backend this means that uniforms
  2272. are packed tightly in memory (e.g. there are no padding
  2273. bytes).
  2274. SG_UNIFORMLAYOUT_STD140
  2275. The memory layout is a subset of std140. Arrays are only
  2276. allowed for the FLOAT4, INT4 and MAT4. Alignment is as
  2277. is as follows:
  2278. FLOAT, INT: 4 byte alignment
  2279. FLOAT2, INT2: 8 byte alignment
  2280. FLOAT3, INT3: 16 byte alignment(!)
  2281. FLOAT4, INT4: 16 byte alignment
  2282. MAT4: 16 byte alignment
  2283. FLOAT4[], INT4[]: 16 byte alignment
  2284. The overall size of the uniform block must be a multiple
  2285. of 16.
  2286. For more information search for 'UNIFORM DATA LAYOUT' in the documentation block
  2287. at the start of the header.
  2288. */
  2289. Uniform_Layout :: enum i32 {
  2290. DEFAULT,
  2291. NATIVE,
  2292. STD140,
  2293. }
  2294. /*
  2295. sg_cull_mode
  2296. The face-culling mode, this is used in the
  2297. sg_pipeline_desc.cull_mode member when creating a
  2298. pipeline object.
  2299. The default cull mode is SG_CULLMODE_NONE
  2300. */
  2301. Cull_Mode :: enum i32 {
  2302. DEFAULT,
  2303. NONE,
  2304. FRONT,
  2305. BACK,
  2306. }
  2307. /*
  2308. sg_face_winding
  2309. The vertex-winding rule that determines a front-facing primitive. This
  2310. is used in the member sg_pipeline_desc.face_winding
  2311. when creating a pipeline object.
  2312. The default winding is SG_FACEWINDING_CW (clockwise)
  2313. */
  2314. Face_Winding :: enum i32 {
  2315. DEFAULT,
  2316. CCW,
  2317. CW,
  2318. }
  2319. /*
  2320. sg_compare_func
  2321. The compare-function for configuring depth- and stencil-ref tests
  2322. in pipeline objects, and for texture samplers which perform a comparison
  2323. instead of regular sampling operation.
  2324. Used in the following structs:
  2325. sg_pipeline_desc
  2326. .depth
  2327. .compare
  2328. .stencil
  2329. .front.compare
  2330. .back.compare
  2331. sg_sampler_desc
  2332. .compare
  2333. The default compare func for depth- and stencil-tests is
  2334. SG_COMPAREFUNC_ALWAYS.
  2335. The default compare func for samplers is SG_COMPAREFUNC_NEVER.
  2336. */
  2337. Compare_Func :: enum i32 {
  2338. DEFAULT,
  2339. NEVER,
  2340. LESS,
  2341. EQUAL,
  2342. LESS_EQUAL,
  2343. GREATER,
  2344. NOT_EQUAL,
  2345. GREATER_EQUAL,
  2346. ALWAYS,
  2347. }
  2348. /*
  2349. sg_stencil_op
  2350. The operation performed on a currently stored stencil-value when a
  2351. comparison test passes or fails. This is used when creating a pipeline
  2352. object in the following sg_pipeline_desc struct items:
  2353. sg_pipeline_desc
  2354. .stencil
  2355. .front
  2356. .fail_op
  2357. .depth_fail_op
  2358. .pass_op
  2359. .back
  2360. .fail_op
  2361. .depth_fail_op
  2362. .pass_op
  2363. The default value is SG_STENCILOP_KEEP.
  2364. */
  2365. Stencil_Op :: enum i32 {
  2366. DEFAULT,
  2367. KEEP,
  2368. ZERO,
  2369. REPLACE,
  2370. INCR_CLAMP,
  2371. DECR_CLAMP,
  2372. INVERT,
  2373. INCR_WRAP,
  2374. DECR_WRAP,
  2375. }
  2376. /*
  2377. sg_blend_factor
  2378. The source and destination factors in blending operations.
  2379. This is used in the following members when creating a pipeline object:
  2380. sg_pipeline_desc
  2381. .colors[i]
  2382. .blend
  2383. .src_factor_rgb
  2384. .dst_factor_rgb
  2385. .src_factor_alpha
  2386. .dst_factor_alpha
  2387. The default value is SG_BLENDFACTOR_ONE for source
  2388. factors, and for the destination SG_BLENDFACTOR_ZERO if the associated
  2389. blend-op is ADD, SUBTRACT or REVERSE_SUBTRACT or SG_BLENDFACTOR_ONE
  2390. if the associated blend-op is MIN or MAX.
  2391. */
  2392. Blend_Factor :: enum i32 {
  2393. DEFAULT,
  2394. ZERO,
  2395. ONE,
  2396. SRC_COLOR,
  2397. ONE_MINUS_SRC_COLOR,
  2398. SRC_ALPHA,
  2399. ONE_MINUS_SRC_ALPHA,
  2400. DST_COLOR,
  2401. ONE_MINUS_DST_COLOR,
  2402. DST_ALPHA,
  2403. ONE_MINUS_DST_ALPHA,
  2404. SRC_ALPHA_SATURATED,
  2405. BLEND_COLOR,
  2406. ONE_MINUS_BLEND_COLOR,
  2407. BLEND_ALPHA,
  2408. ONE_MINUS_BLEND_ALPHA,
  2409. }
  2410. /*
  2411. sg_blend_op
  2412. Describes how the source and destination values are combined in the
  2413. fragment blending operation. It is used in the following struct items
  2414. when creating a pipeline object:
  2415. sg_pipeline_desc
  2416. .colors[i]
  2417. .blend
  2418. .op_rgb
  2419. .op_alpha
  2420. The default value is SG_BLENDOP_ADD.
  2421. */
  2422. Blend_Op :: enum i32 {
  2423. DEFAULT,
  2424. ADD,
  2425. SUBTRACT,
  2426. REVERSE_SUBTRACT,
  2427. MIN,
  2428. MAX,
  2429. }
  2430. /*
  2431. sg_color_mask
  2432. Selects the active color channels when writing a fragment color to the
  2433. framebuffer. This is used in the members
  2434. sg_pipeline_desc.colors[i].write_mask when creating a pipeline object.
  2435. The default colormask is SG_COLORMASK_RGBA (write all colors channels)
  2436. NOTE: since the color mask value 0 is reserved for the default value
  2437. (SG_COLORMASK_RGBA), use SG_COLORMASK_NONE if all color channels
  2438. should be disabled.
  2439. */
  2440. Color_Mask :: enum i32 {
  2441. DEFAULT = 0,
  2442. NONE = 16,
  2443. R = 1,
  2444. G = 2,
  2445. RG = 3,
  2446. B = 4,
  2447. RB = 5,
  2448. GB = 6,
  2449. RGB = 7,
  2450. A = 8,
  2451. RA = 9,
  2452. GA = 10,
  2453. RGA = 11,
  2454. BA = 12,
  2455. RBA = 13,
  2456. GBA = 14,
  2457. RGBA = 15,
  2458. }
  2459. /*
  2460. sg_load_action
  2461. Defines the load action that should be performed at the start of a render pass:
  2462. SG_LOADACTION_CLEAR: clear the render target
  2463. SG_LOADACTION_LOAD: load the previous content of the render target
  2464. SG_LOADACTION_DONTCARE: leave the render target in an undefined state
  2465. This is used in the sg_pass_action structure.
  2466. The default load action for all pass attachments is SG_LOADACTION_CLEAR,
  2467. with the values rgba = { 0.5f, 0.5f, 0.5f, 1.0f }, depth=1.0f and stencil=0.
  2468. If you want to override the default behaviour, it is important to not
  2469. only set the clear color, but the 'action' field as well (as long as this
  2470. is _SG_LOADACTION_DEFAULT, the value fields will be ignored).
  2471. */
  2472. Load_Action :: enum i32 {
  2473. DEFAULT,
  2474. CLEAR,
  2475. LOAD,
  2476. DONTCARE,
  2477. }
  2478. /*
  2479. sg_store_action
  2480. Defines the store action that should be performed at the end of a render pass:
  2481. SG_STOREACTION_STORE: store the rendered content to the color attachment image
  2482. SG_STOREACTION_DONTCARE: allows the GPU to discard the rendered content
  2483. */
  2484. Store_Action :: enum i32 {
  2485. DEFAULT,
  2486. STORE,
  2487. DONTCARE,
  2488. }
  2489. /*
  2490. sg_pass_action
  2491. The sg_pass_action struct defines the actions to be performed
  2492. at the start and end of a render pass.
  2493. - at the start of the pass: whether the render attachments should be cleared,
  2494. loaded with their previous content, or start in an undefined state
  2495. - for clear operations: the clear value (color, depth, or stencil values)
  2496. - at the end of the pass: whether the rendering result should be
  2497. stored back into the render attachment or discarded
  2498. */
  2499. Color_Attachment_Action :: struct {
  2500. load_action : Load_Action,
  2501. store_action : Store_Action,
  2502. clear_value : Color,
  2503. }
  2504. Depth_Attachment_Action :: struct {
  2505. load_action : Load_Action,
  2506. store_action : Store_Action,
  2507. clear_value : f32,
  2508. }
  2509. Stencil_Attachment_Action :: struct {
  2510. load_action : Load_Action,
  2511. store_action : Store_Action,
  2512. clear_value : u8,
  2513. }
  2514. Pass_Action :: struct {
  2515. colors : [8]Color_Attachment_Action,
  2516. depth : Depth_Attachment_Action,
  2517. stencil : Stencil_Attachment_Action,
  2518. }
  2519. /*
  2520. sg_swapchain
  2521. Used in sg_begin_pass() to provide details about an external swapchain
  2522. (pixel formats, sample count and backend-API specific render surface objects).
  2523. The following information must be provided:
  2524. - the width and height of the swapchain surfaces in number of pixels,
  2525. - the pixel format of the render- and optional msaa-resolve-surface
  2526. - the pixel format of the optional depth- or depth-stencil-surface
  2527. - the MSAA sample count for the render and depth-stencil surface
  2528. If the pixel formats and MSAA sample counts are left zero-initialized,
  2529. their defaults are taken from the sg_environment struct provided in the
  2530. sg_setup() call.
  2531. The width and height *must* be > 0.
  2532. Additionally the following backend API specific objects must be passed in
  2533. as 'type erased' void pointers:
  2534. GL:
  2535. - on all GL backends, a GL framebuffer object must be provided. This
  2536. can be zero for the default framebuffer.
  2537. D3D11:
  2538. - an ID3D11RenderTargetView for the rendering surface, without
  2539. MSAA rendering this surface will also be displayed
  2540. - an optional ID3D11DepthStencilView for the depth- or depth/stencil
  2541. buffer surface
  2542. - when MSAA rendering is used, another ID3D11RenderTargetView
  2543. which serves as MSAA resolve target and will be displayed
  2544. WebGPU (same as D3D11, except different types)
  2545. - a WGPUTextureView for the rendering surface, without
  2546. MSAA rendering this surface will also be displayed
  2547. - an optional WGPUTextureView for the depth- or depth/stencil
  2548. buffer surface
  2549. - when MSAA rendering is used, another WGPUTextureView
  2550. which serves as MSAA resolve target and will be displayed
  2551. Metal (NOTE that the roles of provided surfaces is slightly different
  2552. than on D3D11 or WebGPU in case of MSAA vs non-MSAA rendering):
  2553. - A current CAMetalDrawable (NOT an MTLDrawable!) which will be presented.
  2554. This will either be rendered to directly (if no MSAA is used), or serve
  2555. as MSAA-resolve target.
  2556. - an optional MTLTexture for the depth- or depth-stencil buffer
  2557. - an optional multisampled MTLTexture which serves as intermediate
  2558. rendering surface which will then be resolved into the
  2559. CAMetalDrawable.
  2560. NOTE that for Metal you must use an ObjC __bridge cast to
  2561. properly tunnel the ObjC object id through a C void*, e.g.:
  2562. swapchain.metal.current_drawable = (__bridge const void*) [mtkView currentDrawable];
  2563. On all other backends you shouldn't need to mess with the reference count.
  2564. It's a good practice to write a helper function which returns an initialized
  2565. sg_swapchain struct, which can then be plugged directly into
  2566. sg_pass.swapchain. Look at the function sglue_swapchain() in the sokol_glue.h
  2567. as an example.
  2568. */
  2569. Metal_Swapchain :: struct {
  2570. current_drawable : rawptr,
  2571. depth_stencil_texture : rawptr,
  2572. msaa_color_texture : rawptr,
  2573. }
  2574. D3d11_Swapchain :: struct {
  2575. render_view : rawptr,
  2576. resolve_view : rawptr,
  2577. depth_stencil_view : rawptr,
  2578. }
  2579. Wgpu_Swapchain :: struct {
  2580. render_view : rawptr,
  2581. resolve_view : rawptr,
  2582. depth_stencil_view : rawptr,
  2583. }
  2584. Vulkan_Swapchain :: struct {
  2585. render_image : rawptr,
  2586. render_view : rawptr,
  2587. resolve_image : rawptr,
  2588. resolve_view : rawptr,
  2589. depth_stencil_image : rawptr,
  2590. depth_stencil_view : rawptr,
  2591. render_finished_semaphore : rawptr,
  2592. present_complete_semaphore : rawptr,
  2593. }
  2594. Gl_Swapchain :: struct {
  2595. framebuffer : u32,
  2596. }
  2597. Swapchain :: struct {
  2598. width : c.int,
  2599. height : c.int,
  2600. sample_count : c.int,
  2601. color_format : Pixel_Format,
  2602. depth_format : Pixel_Format,
  2603. metal : Metal_Swapchain,
  2604. d3d11 : D3d11_Swapchain,
  2605. wgpu : Wgpu_Swapchain,
  2606. vulkan : Vulkan_Swapchain,
  2607. gl : Gl_Swapchain,
  2608. }
  2609. /*
  2610. sg_attachments
  2611. Used in sg_pass to provide render pass attachment views. Each
  2612. type of pass attachment has it corresponding view type:
  2613. sg_attachments.colors[]:
  2614. populate with color-attachment views, e.g.:
  2615. sg_make_view(&(sg_view_desc){
  2616. .color_attachment = { ... },
  2617. });
  2618. sg_attachments.resolves[]:
  2619. populate with resolve-attachment views, e.g.:
  2620. sg_make_view(&(sg_view_desc){
  2621. .resolve_attachment = { ... },
  2622. });
  2623. sg_attachments.depth_stencil:
  2624. populate with depth-stencil-attachment views, e.g.:
  2625. sg_make_view(&(sg_view_desc){
  2626. .depth_stencil_attachment = { ... },
  2627. });
  2628. */
  2629. Attachments :: struct {
  2630. colors : [8]View,
  2631. resolves : [8]View,
  2632. depth_stencil : View,
  2633. }
  2634. /*
  2635. sg_pass
  2636. The sg_pass structure is passed as argument into the sg_begin_pass()
  2637. function.
  2638. For a swapchain render pass, provide an sg_pass_action and sg_swapchain
  2639. struct (for instance via the sglue_swapchain() helper function from
  2640. sokol_glue.h):
  2641. sg_begin_pass(&(sg_pass){
  2642. .action = { ... },
  2643. .swapchain = sglue_swapchain(),
  2644. });
  2645. For an offscreen render pass, provide an sg_pass_action struct with
  2646. attachment view objects:
  2647. sg_begin_pass(&(sg_pass){
  2648. .action = { ... },
  2649. .attachments = {
  2650. .colors = { ... },
  2651. .resolves = { ... },
  2652. .depth_stencil = ...,
  2653. },
  2654. });
  2655. You can also omit the .action object to get default pass action behaviour
  2656. (clear to color=grey, depth=1 and stencil=0).
  2657. For a compute pass, just set the sg_pass.compute boolean to true:
  2658. sg_begin_pass(&(sg_pass){ .compute = true });
  2659. */
  2660. Pass :: struct {
  2661. _ : u32,
  2662. compute : bool,
  2663. action : Pass_Action,
  2664. attachments : Attachments,
  2665. swapchain : Swapchain,
  2666. label : cstring,
  2667. _ : u32,
  2668. }
  2669. /*
  2670. sg_bindings
  2671. The sg_bindings structure defines the resource bindings for
  2672. the next draw call.
  2673. To update the resource bindings, call sg_apply_bindings() with
  2674. a pointer to a populated sg_bindings struct. Note that
  2675. sg_apply_bindings() must be called after sg_apply_pipeline()
  2676. and that bindings are not preserved across sg_apply_pipeline()
  2677. calls, even when the new pipeline uses the same 'bindings layout'.
  2678. A resource binding struct contains:
  2679. - 1..N vertex buffers
  2680. - 1..N vertex buffer offsets
  2681. - 0..1 index buffer
  2682. - 0..1 index buffer offset
  2683. - 0..N resource views (texture-, storage-image, storage-buffer-views)
  2684. - 0..N samplers
  2685. Where 'N' is defined in the following constants:
  2686. - SG_MAX_VERTEXBUFFER_BINDSLOTS
  2687. - SG_MAX_VIEW_BINDSLOTS
  2688. - SG_MAX_SAMPLER_BINDSLOTS
  2689. Note that inside compute passes vertex- and index-buffer-bindings are
  2690. disallowed.
  2691. When using sokol-shdc for shader authoring, the `layout(binding=N)`
  2692. for texture-, storage-image- and storage-buffer-bindings directly
  2693. maps to the views-array index, for instance the following vertex-
  2694. and fragment-shader interface for sokol-shdc:
  2695. @vs vs
  2696. layout(binding=0) uniform vs_params { ... };
  2697. layout(binding=0) readonly buffer ssbo { ... };
  2698. layout(binding=1) uniform texture2D vs_tex;
  2699. layout(binding=0) uniform sampler vs_smp;
  2700. ...
  2701. @end
  2702. @fs fs
  2703. layout(binding=1) uniform fs_params { ... };
  2704. layout(binding=2) uniform texture2D fs_tex;
  2705. layout(binding=1) uniform sampler fs_smp;
  2706. ...
  2707. @end
  2708. ...would map to the following sg_bindings struct:
  2709. const sg_bindings bnd = {
  2710. .vertex_buffers[0] = ...,
  2711. .views[0] = ssbo_view,
  2712. .views[1] = vs_tex_view,
  2713. .views[2] = fs_tex_view,
  2714. .samplers[0] = vs_smp,
  2715. .samplers[1] = fs_smp,
  2716. };
  2717. ...alternatively you can use code-generated slot indices:
  2718. const sg_bindings bnd = {
  2719. .vertex_buffers[0] = ...,
  2720. .views[VIEW_ssbo] = ssbo_view,
  2721. .views[VIEW_vs_tex] = vs_tex_view,
  2722. .views[VIEW_fs_tex] = fs_tex_view,
  2723. .samplers[SMP_vs_smp] = vs_smp,
  2724. .samplers[SMP_fs_smp] = fs_smp,
  2725. };
  2726. Resource bindslots for a specific shader/pipeline may have gaps, and an
  2727. sg_bindings struct may have populated bind slots which are not used by a
  2728. specific shader. This allows to use the same sg_bindings struct across
  2729. different shader variants.
  2730. When not using sokol-shdc, the bindslot indices in the sg_bindings
  2731. struct need to match the per-binding reflection info slot indices
  2732. in the sg_shader_desc struct (for details about that see the
  2733. sg_shader_desc struct documentation).
  2734. The optional buffer offsets can be used to put different unrelated
  2735. chunks of vertex- and/or index-data into the same buffer objects.
  2736. */
  2737. Bindings :: struct {
  2738. _ : u32,
  2739. vertex_buffers : [8]Buffer,
  2740. vertex_buffer_offsets : [8]c.int,
  2741. index_buffer : Buffer,
  2742. index_buffer_offset : c.int,
  2743. views : [32]View,
  2744. samplers : [12]Sampler,
  2745. _ : u32,
  2746. }
  2747. /*
  2748. sg_buffer_usage
  2749. Describes how a buffer object is going to be used:
  2750. .vertex_buffer (default: true)
  2751. the buffer will be bound as vertex buffer via sg_bindings.vertex_buffers[]
  2752. .index_buffer (default: false)
  2753. the buffer will be bound as index buffer via sg_bindings.index_buffer
  2754. .storage_buffer (default: false)
  2755. the buffer will be bound as storage buffer via storage-buffer-view
  2756. in sg_bindings.views[]
  2757. .immutable (default: true)
  2758. the buffer content will never be updated from the CPU side (but
  2759. may be written to by a compute shader)
  2760. .dynamic_update (default: false)
  2761. the buffer content will be infrequently updated from the CPU side
  2762. .stream_upate (default: false)
  2763. the buffer content will be updated each frame from the CPU side
  2764. */
  2765. Buffer_Usage :: struct {
  2766. vertex_buffer : bool,
  2767. index_buffer : bool,
  2768. storage_buffer : bool,
  2769. immutable : bool,
  2770. dynamic_update : bool,
  2771. stream_update : bool,
  2772. }
  2773. /*
  2774. sg_buffer_desc
  2775. Creation parameters for sg_buffer objects, used in the sg_make_buffer() call.
  2776. The default configuration is:
  2777. .size: 0 (*must* be >0 for buffers without data)
  2778. .usage { .vertex_buffer = true, .immutable = true }
  2779. .data.ptr 0 (*must* be valid for immutable buffers without storage buffer usage)
  2780. .data.size 0 (*must* be > 0 for immutable buffers without storage buffer usage)
  2781. .label 0 (optional string label)
  2782. For immutable buffers which are initialized with initial data,
  2783. keep the .size item zero-initialized, and set the size together with the
  2784. pointer to the initial data in the .data item.
  2785. For immutable or mutable buffers without initial data, keep the .data item
  2786. zero-initialized, and set the buffer size in the .size item instead.
  2787. You can also set both size values, but currently both size values must
  2788. be identical (this may change in the future when the dynamic resource
  2789. management may become more flexible).
  2790. NOTE: Immutable buffers without storage-buffer-usage *must* be created
  2791. with initial content, this restriction doesn't apply to storage buffer usage,
  2792. because storage buffers may also get their initial content by running
  2793. a compute shader on them.
  2794. NOTE: Buffers without initial data will have undefined content, e.g.
  2795. do *not* expect the buffer to be zero-initialized!
  2796. ADVANCED TOPIC: Injecting native 3D-API buffers:
  2797. The following struct members allow to inject your own GL, Metal
  2798. or D3D11 buffers into sokol_gfx:
  2799. .gl_buffers[SG_NUM_INFLIGHT_FRAMES]
  2800. .mtl_buffers[SG_NUM_INFLIGHT_FRAMES]
  2801. .d3d11_buffer
  2802. You must still provide all other struct items except the .data item, and
  2803. these must match the creation parameters of the native buffers you provide.
  2804. For sg_buffer_desc.usage.immutable buffers, only provide a single native
  2805. 3D-API buffer, otherwise you need to provide SG_NUM_INFLIGHT_FRAMES buffers
  2806. (only for GL and Metal, not D3D11). Providing multiple buffers for GL and
  2807. Metal is necessary because sokol_gfx will rotate through them when calling
  2808. sg_update_buffer() to prevent lock-stalls.
  2809. Note that it is expected that immutable injected buffer have already been
  2810. initialized with content, and the .content member must be 0!
  2811. Also you need to call sg_reset_state_cache() after calling native 3D-API
  2812. functions, and before calling any sokol_gfx function.
  2813. */
  2814. Buffer_Desc :: struct {
  2815. _ : u32,
  2816. size : c.size_t,
  2817. usage : Buffer_Usage,
  2818. data : Range,
  2819. label : cstring,
  2820. gl_buffers : [2]u32,
  2821. mtl_buffers : [2]rawptr,
  2822. d3d11_buffer : rawptr,
  2823. wgpu_buffer : rawptr,
  2824. _ : u32,
  2825. }
  2826. /*
  2827. sg_image_usage
  2828. Describes the intended usage of an image object:
  2829. .storage_image (default: false)
  2830. the image can be used as parent resource of a storage-image-view,
  2831. which allows compute shaders to write to the image in a compute
  2832. pass (for read-only access in compute shaders bind the image
  2833. via a texture view instead
  2834. .color_attachment (default: false)
  2835. the image can be used as parent resource of a color-attachment-view,
  2836. which is then passed into sg_begin_pass via sg_pass.attachments.colors[]
  2837. so that fragment shaders can render into the image
  2838. .resolve_attachment (default: false)
  2839. the image can be used as parent resource of a resolve-attachment-view,
  2840. which is then passed into sg_begin_pass via sg_pass.attachments.resolves[]
  2841. as target for an MSAA-resolve operation in sg_end_pass()
  2842. .depth_stencil_attachment (default: false)
  2843. the image can be used as parent resource of a depth-stencil-attachmnet-view
  2844. which is then passes into sg_begin_pass via sg_pass.attachments.depth_stencil
  2845. as depth-stencil-buffer
  2846. .immutable (default: true)
  2847. the image content cannot be updated from the CPU side
  2848. (but may be updated by the GPU in a render- or compute-pass)
  2849. .dynamic_update (default: false)
  2850. the image content is updated infrequently by the CPU
  2851. .stream_update (default: false)
  2852. the image content is updated each frame by the CPU via
  2853. Note that creating a texture view from the image to be used for
  2854. texture-sampling in vertex-, fragment- or compute-shaders
  2855. is always implicitly allowed.
  2856. */
  2857. Image_Usage :: struct {
  2858. storage_image : bool,
  2859. color_attachment : bool,
  2860. resolve_attachment : bool,
  2861. depth_stencil_attachment : bool,
  2862. immutable : bool,
  2863. dynamic_update : bool,
  2864. stream_update : bool,
  2865. }
  2866. /*
  2867. sg_view_type
  2868. Allows to query the type of a view object via the function sg_query_view_type()
  2869. */
  2870. View_Type :: enum i32 {
  2871. INVALID,
  2872. STORAGEBUFFER,
  2873. STORAGEIMAGE,
  2874. TEXTURE,
  2875. COLORATTACHMENT,
  2876. RESOLVEATTACHMENT,
  2877. DEPTHSTENCILATTACHMENT,
  2878. }
  2879. /*
  2880. sg_image_data
  2881. Defines the content of an image through an array of sg_range structs, each
  2882. range pointing to the pixel data for one mip-level. For array-, cubemap- and
  2883. 3D-images each mip-level contains all slice-surfaces for that mip-level in a
  2884. single tightly packed memory block.
  2885. The size of a single surface in a mip-level for a regular 2D texture
  2886. can be computed via:
  2887. sg_query_surface_pitch(pixel_format, mip_width, mip_height, 1);
  2888. For array- and 3d-images the size of a single miplevel is:
  2889. num_slices * sg_query_surface_pitch(pixel_format, mip_width, mip_height, 1);
  2890. For cubemap-images the size of a single mip-level is:
  2891. 6 * sg_query_surface_pitch(pixel_format, mip_width, mip_height, 1);
  2892. The order of cubemap-faces is in a mip-level data chunk is:
  2893. [0] => +X
  2894. [1] => -X
  2895. [2] => +Y
  2896. [3] => -Y
  2897. [4] => +Z
  2898. [5] => -Z
  2899. */
  2900. Image_Data :: struct {
  2901. mip_levels : [16]Range,
  2902. }
  2903. /*
  2904. sg_image_desc
  2905. Creation parameters for sg_image objects, used in the sg_make_image() call.
  2906. The default configuration is:
  2907. .type SG_IMAGETYPE_2D
  2908. .usage .immutable = true
  2909. .width 0 (must be set to >0)
  2910. .height 0 (must be set to >0)
  2911. .num_slices 1 (3D textures: depth; array textures: number of layers)
  2912. .num_mipmaps 1
  2913. .pixel_format SG_PIXELFORMAT_RGBA8 for textures, or sg_desc.environment.defaults.color_format for render targets
  2914. .sample_count 1 for textures, or sg_desc.environment.defaults.sample_count for render targets
  2915. .data an sg_image_data struct to define the initial content
  2916. .label 0 (optional string label for trace hooks)
  2917. Q: Why is the default sample_count for render targets identical with the
  2918. "default sample count" from sg_desc.environment.defaults.sample_count?
  2919. A: So that it matches the default sample count in pipeline objects. Even
  2920. though it is a bit strange/confusing that offscreen render targets by default
  2921. get the same sample count as 'default swapchains', but it's better that
  2922. an offscreen render target created with default parameters matches
  2923. a pipeline object created with default parameters.
  2924. NOTE:
  2925. Regular images used as texture binding with usage.immutable must be fully
  2926. initialized by providing a valid .data member which points to initialization
  2927. data.
  2928. Images with usage.*_attachment or usage.storage_image must
  2929. *not* be created with initial content. Be aware that the initial
  2930. content of pass attachment and storage images is undefined
  2931. (not guaranteed to be zeroed).
  2932. ADVANCED TOPIC: Injecting native 3D-API textures:
  2933. The following struct members allow to inject your own GL, Metal or D3D11
  2934. textures into sokol_gfx:
  2935. .gl_textures[SG_NUM_INFLIGHT_FRAMES]
  2936. .mtl_textures[SG_NUM_INFLIGHT_FRAMES]
  2937. .d3d11_texture
  2938. .wgpu_texture
  2939. For GL, you can also specify the texture target or leave it empty to use
  2940. the default texture target for the image type (GL_TEXTURE_2D for
  2941. SG_IMAGETYPE_2D etc)
  2942. The same rules apply as for injecting native buffers (see sg_buffer_desc
  2943. documentation for more details).
  2944. */
  2945. Image_Desc :: struct {
  2946. _ : u32,
  2947. type : Image_Type,
  2948. usage : Image_Usage,
  2949. width : c.int,
  2950. height : c.int,
  2951. num_slices : c.int,
  2952. num_mipmaps : c.int,
  2953. pixel_format : Pixel_Format,
  2954. sample_count : c.int,
  2955. data : Image_Data,
  2956. label : cstring,
  2957. gl_textures : [2]u32,
  2958. gl_texture_target : u32,
  2959. mtl_textures : [2]rawptr,
  2960. d3d11_texture : rawptr,
  2961. wgpu_texture : rawptr,
  2962. _ : u32,
  2963. }
  2964. /*
  2965. sg_sampler_desc
  2966. Creation parameters for sg_sampler objects, used in the sg_make_sampler() call
  2967. .min_filter: SG_FILTER_NEAREST
  2968. .mag_filter: SG_FILTER_NEAREST
  2969. .mipmap_filter SG_FILTER_NEAREST
  2970. .wrap_u: SG_WRAP_REPEAT
  2971. .wrap_v: SG_WRAP_REPEAT
  2972. .wrap_w: SG_WRAP_REPEAT (only SG_IMAGETYPE_3D)
  2973. .min_lod 0.0f
  2974. .max_lod FLT_MAX
  2975. .border_color SG_BORDERCOLOR_OPAQUE_BLACK
  2976. .compare SG_COMPAREFUNC_NEVER
  2977. .max_anisotropy 1 (must be 1..16)
  2978. */
  2979. Sampler_Desc :: struct {
  2980. _ : u32,
  2981. min_filter : Filter,
  2982. mag_filter : Filter,
  2983. mipmap_filter : Filter,
  2984. wrap_u : Wrap,
  2985. wrap_v : Wrap,
  2986. wrap_w : Wrap,
  2987. min_lod : f32,
  2988. max_lod : f32,
  2989. border_color : Border_Color,
  2990. compare : Compare_Func,
  2991. max_anisotropy : u32,
  2992. label : cstring,
  2993. gl_sampler : u32,
  2994. mtl_sampler : rawptr,
  2995. d3d11_sampler : rawptr,
  2996. wgpu_sampler : rawptr,
  2997. _ : u32,
  2998. }
  2999. /*
  3000. sg_shader_desc
  3001. Used as parameter of sg_make_shader() to create a shader object which
  3002. communicates shader source or bytecode and shader interface
  3003. reflection information to sokol-gfx.
  3004. If you use sokol-shdc you can ignore the following information since
  3005. the sg_shader_desc struct will be code-generated.
  3006. Otherwise you need to provide the following information to the
  3007. sg_make_shader() call:
  3008. - a vertex- and fragment-shader function:
  3009. - the shader source or bytecode
  3010. - an optional entry point name
  3011. - for D3D11: an optional compile target when source code is provided
  3012. (the defaults are "vs_4_0" and "ps_4_0")
  3013. - ...or alternatively, a compute function:
  3014. - the shader source or bytecode
  3015. - an optional entry point name
  3016. - for D3D11: an optional compile target when source code is provided
  3017. (the default is "cs_5_0")
  3018. - vertex attributes required by some backends (not for compute shaders):
  3019. - the vertex attribute base type (undefined, float, signed int, unsigned int),
  3020. this information is only used in the validation layer to check that the
  3021. pipeline object vertex formats are compatible with the input vertex attribute
  3022. type used in the vertex shader. NOTE that the default base type
  3023. 'undefined' skips the validation layer check.
  3024. - for the GL backend: optional vertex attribute names used for name lookup
  3025. - for the D3D11 backend: semantic names and indices
  3026. - only for compute shaders on the Metal backend:
  3027. - the workgroup size aka 'threads per thread-group'
  3028. In other 3D APIs this is declared in the shader code:
  3029. - GLSL: `layout(local_size_x=x, local_size_y=y, local_size_y=z) in;`
  3030. - HLSL: `[numthreads(x, y, z)]`
  3031. - WGSL: `@workgroup_size(x, y, z)`
  3032. ...but in Metal the workgroup size is declared on the CPU side
  3033. - reflection information for each uniform block binding used by the shader:
  3034. - the shader stage the uniform block appears in (SG_SHADERSTAGE_*)
  3035. - the size in bytes of the uniform block
  3036. - backend-specific bindslots:
  3037. - HLSL: the constant buffer register `register(b0..7)`
  3038. - MSL: the buffer attribute `[[buffer(0..7)]]`
  3039. - WGSL: the binding in `@group(0) @binding(0..15)`
  3040. - GLSL only: a description of the uniform block interior
  3041. - the memory layout standard (SG_UNIFORMLAYOUT_*)
  3042. - for each member in the uniform block:
  3043. - the member type (SG_UNIFORM_*)
  3044. - if the member is an array, the array count
  3045. - the member name
  3046. - reflection information for each texture-, storage-buffer and
  3047. storage-image bindings by the shader, each with an associated
  3048. view type:
  3049. - texture bindings => texture views
  3050. - storage-buffer bindings => storage-buffer views
  3051. - storage-image bindings => storage-image views
  3052. - texture bindings must provide the following information:
  3053. - the shader stage the texture binding appears in (SG_SHADERSTAGE_*)
  3054. - the image type (SG_IMAGETYPE_*)
  3055. - the image-sample type (SG_IMAGESAMPLETYPE_*)
  3056. - whether the texture is multisampled
  3057. - backend specific bindslots:
  3058. - HLSL: the texture register `register(t0..31)`
  3059. - MSL: the texture attribute `[[texture(0..31)]]`
  3060. - WGSL: the binding in `@group(1) @binding(0..127)`
  3061. - storage-buffer bindings must provide the following information:
  3062. - the shader stage the storage buffer appears in (SG_SHADERSTAGE_*)
  3063. - whether the storage buffer is readonly
  3064. - backend specific bindslots:
  3065. - HLSL:
  3066. - for storage buffer bindings: `register(t0..31)`
  3067. - for read/write storage buffer bindings: `register(u0..31)`
  3068. - MSL: the buffer attribute `[[buffer(8..23)]]`
  3069. - WGSL: the binding in `@group(1) @binding(0..127)`
  3070. - GL: the binding in `layout(binding=0..sg_limits.max_storage_buffer_bindings_per_stage)`
  3071. - storage-image bindings must provide the following information:
  3072. - the shader stage (*must* be SG_SHADERSTAGE_COMPUTE)
  3073. - whether the storage image is writeonly or readwrite (for readonly
  3074. access use a regular texture binding instead)
  3075. - the image type expected by the shader (SG_IMAGETYPE_*)
  3076. - the access pixel format expected by the shader (SG_PIXELFORMAT_*),
  3077. note that only a subset of pixel formats is allowed for storage image
  3078. bindings
  3079. - backend specific bindslots:
  3080. - HLSL: the UAV register `register(u0..31)`
  3081. - MSL: the texture attribute `[[texture(0..31)]]`
  3082. - WGSL: the binding in `@group(1) @binding(0..127)`
  3083. - GLSL: the binding in `layout(binding=0..sg_imits.max_storage_buffer_bindings_per_stage, [access_format])`
  3084. - reflection information for each sampler used by the shader:
  3085. - the shader stage the sampler appears in (SG_SHADERSTAGE_*)
  3086. - the sampler type (SG_SAMPLERTYPE_*)
  3087. - backend specific bindslots:
  3088. - HLSL: the sampler register `register(s0..11)`
  3089. - MSL: the sampler attribute `[[sampler(0..11)]]`
  3090. - WGSL: the binding in `@group(0) @binding(0..127)`
  3091. - reflection information for each texture-sampler pair used by
  3092. the shader:
  3093. - the shader stage (SG_SHADERSTAGE_*)
  3094. - the texture's array index in the sg_shader_desc.views[] array
  3095. - the sampler's array index in the sg_shader_desc.samplers[] array
  3096. - GLSL only: the name of the combined image-sampler object
  3097. The number and order of items in the sg_shader_desc.attrs[]
  3098. array corresponds to the items in sg_pipeline_desc.layout.attrs.
  3099. - sg_shader_desc.attrs[N] => sg_pipeline_desc.layout.attrs[N]
  3100. NOTE that vertex attribute indices currently cannot have gaps.
  3101. The items index in the sg_shader_desc.uniform_blocks[] array corresponds
  3102. to the ub_slot arg in sg_apply_uniforms():
  3103. - sg_shader_desc.uniform_blocks[N] => sg_apply_uniforms(N, ...)
  3104. The items in the sg_shader_desc.views[] array directly map to
  3105. the views in the sg_bindings.views[] array!
  3106. For all GL backends, shader source-code must be provided. For D3D11 and Metal,
  3107. either shader source-code or byte-code can be provided.
  3108. NOTE that the uniform-block, view and sampler arrays may have gaps. This
  3109. allows to use the same sg_bindings struct for different but related
  3110. shader variations.
  3111. For D3D11, if source code is provided, the d3dcompiler_47.dll will be loaded
  3112. on demand. If this fails, shader creation will fail. When compiling HLSL
  3113. source code, you can provide an optional target string via
  3114. sg_shader_stage_desc.d3d11_target, the default target is "vs_4_0" for the
  3115. vertex shader stage and "ps_4_0" for the pixel shader stage.
  3116. You may optionally provide the file path to enable the default #include handler
  3117. behavior when compiling source code.
  3118. */
  3119. Shader_Stage :: enum i32 {
  3120. NONE,
  3121. VERTEX,
  3122. FRAGMENT,
  3123. COMPUTE,
  3124. }
  3125. Shader_Function :: struct {
  3126. source : cstring,
  3127. bytecode : Range,
  3128. entry : cstring,
  3129. d3d11_target : cstring,
  3130. d3d11_filepath : cstring,
  3131. }
  3132. Shader_Attr_Base_Type :: enum i32 {
  3133. UNDEFINED,
  3134. FLOAT,
  3135. SINT,
  3136. UINT,
  3137. }
  3138. Shader_Vertex_Attr :: struct {
  3139. base_type : Shader_Attr_Base_Type,
  3140. glsl_name : cstring,
  3141. hlsl_sem_name : cstring,
  3142. hlsl_sem_index : u8,
  3143. }
  3144. Glsl_Shader_Uniform :: struct {
  3145. type : Uniform_Type,
  3146. array_count : u16,
  3147. glsl_name : cstring,
  3148. }
  3149. Shader_Uniform_Block :: struct {
  3150. stage : Shader_Stage,
  3151. size : u32,
  3152. hlsl_register_b_n : u8,
  3153. msl_buffer_n : u8,
  3154. wgsl_group0_binding_n : u8,
  3155. spirv_set0_binding_n : u8,
  3156. layout : Uniform_Layout,
  3157. glsl_uniforms : [16]Glsl_Shader_Uniform,
  3158. }
  3159. Shader_Texture_View :: struct {
  3160. stage : Shader_Stage,
  3161. image_type : Image_Type,
  3162. sample_type : Image_Sample_Type,
  3163. multisampled : bool,
  3164. hlsl_register_t_n : u8,
  3165. msl_texture_n : u8,
  3166. wgsl_group1_binding_n : u8,
  3167. spirv_set1_binding_n : u8,
  3168. }
  3169. Shader_Storage_Buffer_View :: struct {
  3170. stage : Shader_Stage,
  3171. readonly : bool,
  3172. hlsl_register_t_n : u8,
  3173. hlsl_register_u_n : u8,
  3174. msl_buffer_n : u8,
  3175. wgsl_group1_binding_n : u8,
  3176. spirv_set1_binding_n : u8,
  3177. glsl_binding_n : u8,
  3178. }
  3179. Shader_Storage_Image_View :: struct {
  3180. stage : Shader_Stage,
  3181. image_type : Image_Type,
  3182. access_format : Pixel_Format,
  3183. writeonly : bool,
  3184. hlsl_register_u_n : u8,
  3185. msl_texture_n : u8,
  3186. wgsl_group1_binding_n : u8,
  3187. spirv_set1_binding_n : u8,
  3188. glsl_binding_n : u8,
  3189. }
  3190. Shader_View :: struct {
  3191. texture : Shader_Texture_View,
  3192. storage_buffer : Shader_Storage_Buffer_View,
  3193. storage_image : Shader_Storage_Image_View,
  3194. }
  3195. Shader_Sampler :: struct {
  3196. stage : Shader_Stage,
  3197. sampler_type : Sampler_Type,
  3198. hlsl_register_s_n : u8,
  3199. msl_sampler_n : u8,
  3200. wgsl_group1_binding_n : u8,
  3201. spirv_set1_binding_n : u8,
  3202. }
  3203. Shader_Texture_Sampler_Pair :: struct {
  3204. stage : Shader_Stage,
  3205. view_slot : u8,
  3206. sampler_slot : u8,
  3207. glsl_name : cstring,
  3208. }
  3209. Mtl_Shader_Threads_Per_Threadgroup :: struct {
  3210. x : c.int,
  3211. y : c.int,
  3212. z : c.int,
  3213. }
  3214. Shader_Desc :: struct {
  3215. _ : u32,
  3216. vertex_func : Shader_Function,
  3217. fragment_func : Shader_Function,
  3218. compute_func : Shader_Function,
  3219. attrs : [16]Shader_Vertex_Attr,
  3220. uniform_blocks : [8]Shader_Uniform_Block,
  3221. views : [32]Shader_View,
  3222. samplers : [12]Shader_Sampler,
  3223. texture_sampler_pairs : [32]Shader_Texture_Sampler_Pair,
  3224. mtl_threads_per_threadgroup : Mtl_Shader_Threads_Per_Threadgroup,
  3225. label : cstring,
  3226. _ : u32,
  3227. }
  3228. /*
  3229. sg_pipeline_desc
  3230. The sg_pipeline_desc struct defines all creation parameters for an
  3231. sg_pipeline object, used as argument to the sg_make_pipeline() function:
  3232. Pipeline objects come in two flavours:
  3233. - render pipelines for use in render passes
  3234. - compute pipelines for use in compute passes
  3235. A compute pipeline only requires a compute shader object but no
  3236. 'render state', while a render pipeline requires a vertex/fragment shader
  3237. object and additional render state declarations:
  3238. - the vertex layout for all input vertex buffers
  3239. - a shader object
  3240. - the 3D primitive type (points, lines, triangles, ...)
  3241. - the index type (none, 16- or 32-bit)
  3242. - all the fixed-function-pipeline state (depth-, stencil-, blend-state, etc...)
  3243. If the vertex data has no gaps between vertex components, you can omit
  3244. the .layout.buffers[].stride and layout.attrs[].offset items (leave them
  3245. default-initialized to 0), sokol-gfx will then compute the offsets and
  3246. strides from the vertex component formats (.layout.attrs[].format).
  3247. Please note that ALL vertex attribute offsets must be 0 in order for the
  3248. automatic offset computation to kick in.
  3249. Note that if you use vertex-pulling from storage buffers instead of
  3250. fixed-function vertex input you can simply omit the entire nested .layout
  3251. struct.
  3252. The default configuration is as follows:
  3253. .compute: false (must be set to true for a compute pipeline)
  3254. .shader: 0 (must be initialized with a valid sg_shader id!)
  3255. .layout:
  3256. .buffers[]: vertex buffer layouts
  3257. .stride: 0 (if no stride is given it will be computed)
  3258. .step_func SG_VERTEXSTEP_PER_VERTEX
  3259. .step_rate 1
  3260. .attrs[]: vertex attribute declarations
  3261. .buffer_index 0 the vertex buffer bind slot
  3262. .offset 0 (offsets can be omitted if the vertex layout has no gaps)
  3263. .format SG_VERTEXFORMAT_INVALID (must be initialized!)
  3264. .depth:
  3265. .pixel_format: sg_desc.context.depth_format
  3266. .compare: SG_COMPAREFUNC_ALWAYS
  3267. .write_enabled: false
  3268. .bias: 0.0f
  3269. .bias_slope_scale: 0.0f
  3270. .bias_clamp: 0.0f
  3271. .stencil:
  3272. .enabled: false
  3273. .front/back:
  3274. .compare: SG_COMPAREFUNC_ALWAYS
  3275. .fail_op: SG_STENCILOP_KEEP
  3276. .depth_fail_op: SG_STENCILOP_KEEP
  3277. .pass_op: SG_STENCILOP_KEEP
  3278. .read_mask: 0
  3279. .write_mask: 0
  3280. .ref: 0
  3281. .color_count 1
  3282. .colors[0..color_count]
  3283. .pixel_format sg_desc.context.color_format
  3284. .write_mask: SG_COLORMASK_RGBA
  3285. .blend:
  3286. .enabled: false
  3287. .src_factor_rgb: SG_BLENDFACTOR_ONE
  3288. .dst_factor_rgb: SG_BLENDFACTOR_ZERO
  3289. .op_rgb: SG_BLENDOP_ADD
  3290. .src_factor_alpha: SG_BLENDFACTOR_ONE
  3291. .dst_factor_alpha: SG_BLENDFACTOR_ZERO
  3292. .op_alpha: SG_BLENDOP_ADD
  3293. .primitive_type: SG_PRIMITIVETYPE_TRIANGLES
  3294. .index_type: SG_INDEXTYPE_NONE
  3295. .cull_mode: SG_CULLMODE_NONE
  3296. .face_winding: SG_FACEWINDING_CW
  3297. .sample_count: sg_desc.context.sample_count
  3298. .blend_color: (sg_color) { 0.0f, 0.0f, 0.0f, 0.0f }
  3299. .alpha_to_coverage_enabled: false
  3300. .label 0 (optional string label for trace hooks)
  3301. */
  3302. Vertex_Buffer_Layout_State :: struct {
  3303. stride : c.int,
  3304. step_func : Vertex_Step,
  3305. step_rate : c.int,
  3306. }
  3307. Vertex_Attr_State :: struct {
  3308. buffer_index : c.int,
  3309. offset : c.int,
  3310. format : Vertex_Format,
  3311. }
  3312. Vertex_Layout_State :: struct {
  3313. buffers : [8]Vertex_Buffer_Layout_State,
  3314. attrs : [16]Vertex_Attr_State,
  3315. }
  3316. Stencil_Face_State :: struct {
  3317. compare : Compare_Func,
  3318. fail_op : Stencil_Op,
  3319. depth_fail_op : Stencil_Op,
  3320. pass_op : Stencil_Op,
  3321. }
  3322. Stencil_State :: struct {
  3323. enabled : bool,
  3324. front : Stencil_Face_State,
  3325. back : Stencil_Face_State,
  3326. read_mask : u8,
  3327. write_mask : u8,
  3328. ref : u8,
  3329. }
  3330. Depth_State :: struct {
  3331. pixel_format : Pixel_Format,
  3332. compare : Compare_Func,
  3333. write_enabled : bool,
  3334. bias : f32,
  3335. bias_slope_scale : f32,
  3336. bias_clamp : f32,
  3337. }
  3338. Blend_State :: struct {
  3339. enabled : bool,
  3340. src_factor_rgb : Blend_Factor,
  3341. dst_factor_rgb : Blend_Factor,
  3342. op_rgb : Blend_Op,
  3343. src_factor_alpha : Blend_Factor,
  3344. dst_factor_alpha : Blend_Factor,
  3345. op_alpha : Blend_Op,
  3346. }
  3347. Color_Target_State :: struct {
  3348. pixel_format : Pixel_Format,
  3349. write_mask : Color_Mask,
  3350. blend : Blend_State,
  3351. }
  3352. Pipeline_Desc :: struct {
  3353. _ : u32,
  3354. compute : bool,
  3355. shader : Shader,
  3356. layout : Vertex_Layout_State,
  3357. depth : Depth_State,
  3358. stencil : Stencil_State,
  3359. color_count : c.int,
  3360. colors : [8]Color_Target_State,
  3361. primitive_type : Primitive_Type,
  3362. index_type : Index_Type,
  3363. cull_mode : Cull_Mode,
  3364. face_winding : Face_Winding,
  3365. sample_count : c.int,
  3366. blend_color : Color,
  3367. alpha_to_coverage_enabled : bool,
  3368. label : cstring,
  3369. _ : u32,
  3370. }
  3371. /*
  3372. sg_view_desc
  3373. Creation params for sg_view objects, passed into sg_make_view() calls.
  3374. View objects are passed into sg_apply_bindings() (for texture-, storage-buffer-
  3375. and storage-image views), and sg_begin_pass() (for color-, resolve-
  3376. and depth-stencil-attachment views).
  3377. The view type is determined by initializing one of the sub-structs of
  3378. sg_view_desc:
  3379. .texture a texture-view object will be created
  3380. .image the sg_image parent resource
  3381. .mip_levels optional mip-level range, keep zero-initialized for the
  3382. entire mipmap chain
  3383. .base the first mip level
  3384. .count number of mip levels, keeping this zero-initialized means
  3385. 'all remaining mip levels'
  3386. .slices optional slice range, keep zero-initialized to include
  3387. all slices
  3388. .base the first slice
  3389. .count number of slices, keeping this zero-initializied means 'all remaining slices'
  3390. .storage_buffer a storage-buffer-view object will be created
  3391. .buffer the sg_buffer parent resource, must have been created
  3392. with `sg_buffer_desc.usage.storage_buffer = true`
  3393. .offset optional 256-byte aligned byte-offset into the buffer
  3394. .storage_image a storage-image-view object will be created
  3395. .image the sg_image parent resource, must have been created
  3396. with `sg_image_desc.usage.storage_image = true`
  3397. .mip_level selects the mip-level for the compute shader to write
  3398. .slice selects the slice for the compute shader to write
  3399. .color_attachment a color-attachment-view object will be created
  3400. .image the sg_image parent resource, must have been created
  3401. with `sg_image_desc.usage.color_attachment = true`
  3402. .mip_level selects the mip-level to render into
  3403. .slice selects the slice to render into
  3404. .resolve_attachment a resolve-attachment-view object will be created
  3405. .image the sg_image parent resource, must have been created
  3406. with `sg_image_desc.usage.resolve_attachment = true`
  3407. .mip_level selects the mip-level to msaa-resolve into
  3408. .slice selects the slice to msaa-resolve into
  3409. .depth_stencil_attachment a depth-stencil-attachment-view object will be created
  3410. .image the sg_image parent resource, must have been created
  3411. with `sg_image_desc.usage.depth_stencil_attachment = true`
  3412. .mip_level selects the mip-level to render into
  3413. .slice selects the slice to render into
  3414. */
  3415. Buffer_View_Desc :: struct {
  3416. buffer : Buffer,
  3417. offset : c.int,
  3418. }
  3419. Image_View_Desc :: struct {
  3420. image : Image,
  3421. mip_level : c.int,
  3422. slice : c.int,
  3423. }
  3424. Texture_View_Range :: struct {
  3425. base : c.int,
  3426. count : c.int,
  3427. }
  3428. Texture_View_Desc :: struct {
  3429. image : Image,
  3430. mip_levels : Texture_View_Range,
  3431. slices : Texture_View_Range,
  3432. }
  3433. View_Desc :: struct {
  3434. _ : u32,
  3435. texture : Texture_View_Desc,
  3436. storage_buffer : Buffer_View_Desc,
  3437. storage_image : Image_View_Desc,
  3438. color_attachment : Image_View_Desc,
  3439. resolve_attachment : Image_View_Desc,
  3440. depth_stencil_attachment : Image_View_Desc,
  3441. label : cstring,
  3442. _ : u32,
  3443. }
  3444. /*
  3445. sg_buffer_info
  3446. sg_image_info
  3447. sg_sampler_info
  3448. sg_shader_info
  3449. sg_pipeline_info
  3450. sg_view_info
  3451. These structs contain various internal resource attributes which
  3452. might be useful for debug-inspection. Please don't rely on the
  3453. actual content of those structs too much, as they are quite closely
  3454. tied to sokol_gfx.h internals and may change more frequently than
  3455. the other public API elements.
  3456. The *_info structs are used as the return values of the following functions:
  3457. sg_query_buffer_info()
  3458. sg_query_image_info()
  3459. sg_query_sampler_info()
  3460. sg_query_shader_info()
  3461. sg_query_pipeline_info()
  3462. sg_query_view_info()
  3463. */
  3464. Slot_Info :: struct {
  3465. state : Resource_State,
  3466. res_id : u32,
  3467. uninit_count : u32,
  3468. }
  3469. Buffer_Info :: struct {
  3470. slot : Slot_Info,
  3471. update_frame_index : u32,
  3472. append_frame_index : u32,
  3473. append_pos : c.int,
  3474. append_overflow : bool,
  3475. num_slots : c.int,
  3476. active_slot : c.int,
  3477. }
  3478. Image_Info :: struct {
  3479. slot : Slot_Info,
  3480. upd_frame_index : u32,
  3481. num_slots : c.int,
  3482. active_slot : c.int,
  3483. }
  3484. Sampler_Info :: struct {
  3485. slot : Slot_Info,
  3486. }
  3487. Shader_Info :: struct {
  3488. slot : Slot_Info,
  3489. }
  3490. Pipeline_Info :: struct {
  3491. slot : Slot_Info,
  3492. }
  3493. View_Info :: struct {
  3494. slot : Slot_Info,
  3495. }
  3496. /*
  3497. sg_stats
  3498. Allows to track generic and backend-specific rendering stats,
  3499. obtained via sg_query_stats().
  3500. */
  3501. Frame_Stats_Gl :: struct {
  3502. num_bind_buffer : u32,
  3503. num_active_texture : u32,
  3504. num_bind_texture : u32,
  3505. num_bind_sampler : u32,
  3506. num_bind_image_texture : u32,
  3507. num_use_program : u32,
  3508. num_render_state : u32,
  3509. num_vertex_attrib_pointer : u32,
  3510. num_vertex_attrib_divisor : u32,
  3511. num_enable_vertex_attrib_array : u32,
  3512. num_disable_vertex_attrib_array : u32,
  3513. num_uniform : u32,
  3514. num_memory_barriers : u32,
  3515. }
  3516. Frame_Stats_D3d11_Pass :: struct {
  3517. num_om_set_render_targets : u32,
  3518. num_clear_render_target_view : u32,
  3519. num_clear_depth_stencil_view : u32,
  3520. num_resolve_subresource : u32,
  3521. }
  3522. Frame_Stats_D3d11_Pipeline :: struct {
  3523. num_rs_set_state : u32,
  3524. num_om_set_depth_stencil_state : u32,
  3525. num_om_set_blend_state : u32,
  3526. num_ia_set_primitive_topology : u32,
  3527. num_ia_set_input_layout : u32,
  3528. num_vs_set_shader : u32,
  3529. num_vs_set_constant_buffers : u32,
  3530. num_ps_set_shader : u32,
  3531. num_ps_set_constant_buffers : u32,
  3532. num_cs_set_shader : u32,
  3533. num_cs_set_constant_buffers : u32,
  3534. }
  3535. Frame_Stats_D3d11_Bindings :: struct {
  3536. num_ia_set_vertex_buffers : u32,
  3537. num_ia_set_index_buffer : u32,
  3538. num_vs_set_shader_resources : u32,
  3539. num_vs_set_samplers : u32,
  3540. num_ps_set_shader_resources : u32,
  3541. num_ps_set_samplers : u32,
  3542. num_cs_set_shader_resources : u32,
  3543. num_cs_set_samplers : u32,
  3544. num_cs_set_unordered_access_views : u32,
  3545. }
  3546. Frame_Stats_D3d11_Uniforms :: struct {
  3547. num_update_subresource : u32,
  3548. }
  3549. Frame_Stats_D3d11_Draw :: struct {
  3550. num_draw_indexed_instanced : u32,
  3551. num_draw_indexed : u32,
  3552. num_draw_instanced : u32,
  3553. num_draw : u32,
  3554. }
  3555. Frame_Stats_D3d11 :: struct {
  3556. pass : Frame_Stats_D3d11_Pass,
  3557. pipeline : Frame_Stats_D3d11_Pipeline,
  3558. bindings : Frame_Stats_D3d11_Bindings,
  3559. uniforms : Frame_Stats_D3d11_Uniforms,
  3560. draw : Frame_Stats_D3d11_Draw,
  3561. num_map : u32,
  3562. num_unmap : u32,
  3563. }
  3564. Frame_Stats_Metal_Idpool :: struct {
  3565. num_added : u32,
  3566. num_released : u32,
  3567. num_garbage_collected : u32,
  3568. }
  3569. Frame_Stats_Metal_Pipeline :: struct {
  3570. num_set_blend_color : u32,
  3571. num_set_cull_mode : u32,
  3572. num_set_front_facing_winding : u32,
  3573. num_set_stencil_reference_value : u32,
  3574. num_set_depth_bias : u32,
  3575. num_set_render_pipeline_state : u32,
  3576. num_set_depth_stencil_state : u32,
  3577. }
  3578. Frame_Stats_Metal_Bindings :: struct {
  3579. num_set_vertex_buffer : u32,
  3580. num_set_vertex_buffer_offset : u32,
  3581. num_skip_redundant_vertex_buffer : u32,
  3582. num_set_vertex_texture : u32,
  3583. num_skip_redundant_vertex_texture : u32,
  3584. num_set_vertex_sampler_state : u32,
  3585. num_skip_redundant_vertex_sampler_state : u32,
  3586. num_set_fragment_buffer : u32,
  3587. num_set_fragment_buffer_offset : u32,
  3588. num_skip_redundant_fragment_buffer : u32,
  3589. num_set_fragment_texture : u32,
  3590. num_skip_redundant_fragment_texture : u32,
  3591. num_set_fragment_sampler_state : u32,
  3592. num_skip_redundant_fragment_sampler_state : u32,
  3593. num_set_compute_buffer : u32,
  3594. num_set_compute_buffer_offset : u32,
  3595. num_skip_redundant_compute_buffer : u32,
  3596. num_set_compute_texture : u32,
  3597. num_skip_redundant_compute_texture : u32,
  3598. num_set_compute_sampler_state : u32,
  3599. num_skip_redundant_compute_sampler_state : u32,
  3600. }
  3601. Frame_Stats_Metal_Uniforms :: struct {
  3602. num_set_vertex_buffer_offset : u32,
  3603. num_set_fragment_buffer_offset : u32,
  3604. num_set_compute_buffer_offset : u32,
  3605. }
  3606. Frame_Stats_Metal :: struct {
  3607. idpool : Frame_Stats_Metal_Idpool,
  3608. pipeline : Frame_Stats_Metal_Pipeline,
  3609. bindings : Frame_Stats_Metal_Bindings,
  3610. uniforms : Frame_Stats_Metal_Uniforms,
  3611. }
  3612. Frame_Stats_Wgpu_Uniforms :: struct {
  3613. num_set_bindgroup : u32,
  3614. size_write_buffer : u32,
  3615. }
  3616. Frame_Stats_Wgpu_Bindings :: struct {
  3617. num_set_vertex_buffer : u32,
  3618. num_skip_redundant_vertex_buffer : u32,
  3619. num_set_index_buffer : u32,
  3620. num_skip_redundant_index_buffer : u32,
  3621. num_create_bindgroup : u32,
  3622. num_discard_bindgroup : u32,
  3623. num_set_bindgroup : u32,
  3624. num_skip_redundant_bindgroup : u32,
  3625. num_bindgroup_cache_hits : u32,
  3626. num_bindgroup_cache_misses : u32,
  3627. num_bindgroup_cache_collisions : u32,
  3628. num_bindgroup_cache_invalidates : u32,
  3629. num_bindgroup_cache_hash_vs_key_mismatch : u32,
  3630. }
  3631. Frame_Stats_Wgpu :: struct {
  3632. uniforms : Frame_Stats_Wgpu_Uniforms,
  3633. bindings : Frame_Stats_Wgpu_Bindings,
  3634. }
  3635. Frame_Stats_Vk :: struct {
  3636. num_cmd_pipeline_barrier : u32,
  3637. num_allocate_memory : u32,
  3638. num_free_memory : u32,
  3639. size_allocate_memory : u32,
  3640. num_delete_queue_added : u32,
  3641. num_delete_queue_collected : u32,
  3642. num_cmd_copy_buffer : u32,
  3643. num_cmd_copy_buffer_to_image : u32,
  3644. num_cmd_set_descriptor_buffer_offsets : u32,
  3645. size_descriptor_buffer_writes : u32,
  3646. }
  3647. Frame_Resource_Stats :: struct {
  3648. allocated : u32,
  3649. deallocated : u32,
  3650. inited : u32,
  3651. uninited : u32,
  3652. }
  3653. Total_Resource_Stats :: struct {
  3654. alive : u32,
  3655. free : u32,
  3656. allocated : u32,
  3657. deallocated : u32,
  3658. inited : u32,
  3659. uninited : u32,
  3660. }
  3661. Total_Stats :: struct {
  3662. buffers : Total_Resource_Stats,
  3663. images : Total_Resource_Stats,
  3664. samplers : Total_Resource_Stats,
  3665. views : Total_Resource_Stats,
  3666. shaders : Total_Resource_Stats,
  3667. pipelines : Total_Resource_Stats,
  3668. }
  3669. Frame_Stats :: struct {
  3670. frame_index : u32,
  3671. num_passes : u32,
  3672. num_apply_viewport : u32,
  3673. num_apply_scissor_rect : u32,
  3674. num_apply_pipeline : u32,
  3675. num_apply_bindings : u32,
  3676. num_apply_uniforms : u32,
  3677. num_draw : u32,
  3678. num_draw_ex : u32,
  3679. num_dispatch : u32,
  3680. num_update_buffer : u32,
  3681. num_append_buffer : u32,
  3682. num_update_image : u32,
  3683. size_apply_uniforms : u32,
  3684. size_update_buffer : u32,
  3685. size_append_buffer : u32,
  3686. size_update_image : u32,
  3687. buffers : Frame_Resource_Stats,
  3688. images : Frame_Resource_Stats,
  3689. samplers : Frame_Resource_Stats,
  3690. views : Frame_Resource_Stats,
  3691. shaders : Frame_Resource_Stats,
  3692. pipelines : Frame_Resource_Stats,
  3693. gl : Frame_Stats_Gl,
  3694. d3d11 : Frame_Stats_D3d11,
  3695. metal : Frame_Stats_Metal,
  3696. wgpu : Frame_Stats_Wgpu,
  3697. vk : Frame_Stats_Vk,
  3698. }
  3699. Stats :: struct {
  3700. prev_frame : Frame_Stats,
  3701. cur_frame : Frame_Stats,
  3702. total : Total_Stats,
  3703. }
  3704. Log_Item :: enum i32 {
  3705. OK,
  3706. MALLOC_FAILED,
  3707. GL_TEXTURE_FORMAT_NOT_SUPPORTED,
  3708. GL_3D_TEXTURES_NOT_SUPPORTED,
  3709. GL_ARRAY_TEXTURES_NOT_SUPPORTED,
  3710. GL_STORAGEBUFFER_GLSL_BINDING_OUT_OF_RANGE,
  3711. GL_STORAGEIMAGE_GLSL_BINDING_OUT_OF_RANGE,
  3712. GL_SHADER_COMPILATION_FAILED,
  3713. GL_SHADER_LINKING_FAILED,
  3714. GL_VERTEX_ATTRIBUTE_NOT_FOUND_IN_SHADER,
  3715. GL_UNIFORMBLOCK_NAME_NOT_FOUND_IN_SHADER,
  3716. GL_IMAGE_SAMPLER_NAME_NOT_FOUND_IN_SHADER,
  3717. GL_FRAMEBUFFER_STATUS_UNDEFINED,
  3718. GL_FRAMEBUFFER_STATUS_INCOMPLETE_ATTACHMENT,
  3719. GL_FRAMEBUFFER_STATUS_INCOMPLETE_MISSING_ATTACHMENT,
  3720. GL_FRAMEBUFFER_STATUS_UNSUPPORTED,
  3721. GL_FRAMEBUFFER_STATUS_INCOMPLETE_MULTISAMPLE,
  3722. GL_FRAMEBUFFER_STATUS_UNKNOWN,
  3723. D3D11_FEATURE_LEVEL_0_DETECTED,
  3724. D3D11_CREATE_BUFFER_FAILED,
  3725. D3D11_CREATE_BUFFER_SRV_FAILED,
  3726. D3D11_CREATE_BUFFER_UAV_FAILED,
  3727. D3D11_CREATE_DEPTH_TEXTURE_UNSUPPORTED_PIXEL_FORMAT,
  3728. D3D11_CREATE_DEPTH_TEXTURE_FAILED,
  3729. D3D11_CREATE_2D_TEXTURE_UNSUPPORTED_PIXEL_FORMAT,
  3730. D3D11_CREATE_2D_TEXTURE_FAILED,
  3731. D3D11_CREATE_2D_SRV_FAILED,
  3732. D3D11_CREATE_3D_TEXTURE_UNSUPPORTED_PIXEL_FORMAT,
  3733. D3D11_CREATE_3D_TEXTURE_FAILED,
  3734. D3D11_CREATE_3D_SRV_FAILED,
  3735. D3D11_CREATE_MSAA_TEXTURE_FAILED,
  3736. D3D11_CREATE_SAMPLER_STATE_FAILED,
  3737. D3D11_UNIFORMBLOCK_HLSL_REGISTER_B_OUT_OF_RANGE,
  3738. D3D11_STORAGEBUFFER_HLSL_REGISTER_T_OUT_OF_RANGE,
  3739. D3D11_STORAGEBUFFER_HLSL_REGISTER_U_OUT_OF_RANGE,
  3740. D3D11_IMAGE_HLSL_REGISTER_T_OUT_OF_RANGE,
  3741. D3D11_STORAGEIMAGE_HLSL_REGISTER_U_OUT_OF_RANGE,
  3742. D3D11_SAMPLER_HLSL_REGISTER_S_OUT_OF_RANGE,
  3743. D3D11_LOAD_D3DCOMPILER_47_DLL_FAILED,
  3744. D3D11_SHADER_COMPILATION_FAILED,
  3745. D3D11_SHADER_COMPILATION_OUTPUT,
  3746. D3D11_CREATE_CONSTANT_BUFFER_FAILED,
  3747. D3D11_CREATE_INPUT_LAYOUT_FAILED,
  3748. D3D11_CREATE_RASTERIZER_STATE_FAILED,
  3749. D3D11_CREATE_DEPTH_STENCIL_STATE_FAILED,
  3750. D3D11_CREATE_BLEND_STATE_FAILED,
  3751. D3D11_CREATE_RTV_FAILED,
  3752. D3D11_CREATE_DSV_FAILED,
  3753. D3D11_CREATE_UAV_FAILED,
  3754. D3D11_MAP_FOR_UPDATE_BUFFER_FAILED,
  3755. D3D11_MAP_FOR_APPEND_BUFFER_FAILED,
  3756. D3D11_MAP_FOR_UPDATE_IMAGE_FAILED,
  3757. METAL_CREATE_BUFFER_FAILED,
  3758. METAL_TEXTURE_FORMAT_NOT_SUPPORTED,
  3759. METAL_CREATE_TEXTURE_FAILED,
  3760. METAL_CREATE_SAMPLER_FAILED,
  3761. METAL_SHADER_COMPILATION_FAILED,
  3762. METAL_SHADER_CREATION_FAILED,
  3763. METAL_SHADER_COMPILATION_OUTPUT,
  3764. METAL_SHADER_ENTRY_NOT_FOUND,
  3765. METAL_UNIFORMBLOCK_MSL_BUFFER_SLOT_OUT_OF_RANGE,
  3766. METAL_STORAGEBUFFER_MSL_BUFFER_SLOT_OUT_OF_RANGE,
  3767. METAL_STORAGEIMAGE_MSL_TEXTURE_SLOT_OUT_OF_RANGE,
  3768. METAL_IMAGE_MSL_TEXTURE_SLOT_OUT_OF_RANGE,
  3769. METAL_SAMPLER_MSL_SAMPLER_SLOT_OUT_OF_RANGE,
  3770. METAL_CREATE_CPS_FAILED,
  3771. METAL_CREATE_CPS_OUTPUT,
  3772. METAL_CREATE_RPS_FAILED,
  3773. METAL_CREATE_RPS_OUTPUT,
  3774. METAL_CREATE_DSS_FAILED,
  3775. WGPU_BINDGROUPS_POOL_EXHAUSTED,
  3776. WGPU_BINDGROUPSCACHE_SIZE_GREATER_ONE,
  3777. WGPU_BINDGROUPSCACHE_SIZE_POW2,
  3778. WGPU_CREATEBINDGROUP_FAILED,
  3779. WGPU_CREATE_BUFFER_FAILED,
  3780. WGPU_CREATE_TEXTURE_FAILED,
  3781. WGPU_CREATE_TEXTURE_VIEW_FAILED,
  3782. WGPU_CREATE_SAMPLER_FAILED,
  3783. WGPU_CREATE_SHADER_MODULE_FAILED,
  3784. WGPU_SHADER_CREATE_BINDGROUP_LAYOUT_FAILED,
  3785. WGPU_UNIFORMBLOCK_WGSL_GROUP0_BINDING_OUT_OF_RANGE,
  3786. WGPU_TEXTURE_WGSL_GROUP1_BINDING_OUT_OF_RANGE,
  3787. WGPU_STORAGEBUFFER_WGSL_GROUP1_BINDING_OUT_OF_RANGE,
  3788. WGPU_STORAGEIMAGE_WGSL_GROUP1_BINDING_OUT_OF_RANGE,
  3789. WGPU_SAMPLER_WGSL_GROUP1_BINDING_OUT_OF_RANGE,
  3790. WGPU_CREATE_PIPELINE_LAYOUT_FAILED,
  3791. WGPU_CREATE_RENDER_PIPELINE_FAILED,
  3792. WGPU_CREATE_COMPUTE_PIPELINE_FAILED,
  3793. VULKAN_REQUIRED_EXTENSION_FUNCTION_MISSING,
  3794. VULKAN_ALLOC_DEVICE_MEMORY_NO_SUITABLE_MEMORY_TYPE,
  3795. VULKAN_ALLOCATE_MEMORY_FAILED,
  3796. VULKAN_ALLOC_BUFFER_DEVICE_MEMORY_FAILED,
  3797. VULKAN_ALLOC_IMAGE_DEVICE_MEMORY_FAILED,
  3798. VULKAN_DELETE_QUEUE_EXHAUSTED,
  3799. VULKAN_STAGING_CREATE_BUFFER_FAILED,
  3800. VULKAN_STAGING_ALLOCATE_MEMORY_FAILED,
  3801. VULKAN_STAGING_BIND_BUFFER_MEMORY_FAILED,
  3802. VULKAN_STAGING_STREAM_BUFFER_OVERFLOW,
  3803. VULKAN_CREATE_SHARED_BUFFER_FAILED,
  3804. VULKAN_ALLOCATE_SHARED_BUFFER_MEMORY_FAILED,
  3805. VULKAN_BIND_SHARED_BUFFER_MEMORY_FAILED,
  3806. VULKAN_MAP_SHARED_BUFFER_MEMORY_FAILED,
  3807. VULKAN_CREATE_BUFFER_FAILED,
  3808. VULKAN_BIND_BUFFER_MEMORY_FAILED,
  3809. VULKAN_CREATE_IMAGE_FAILED,
  3810. VULKAN_BIND_IMAGE_MEMORY_FAILED,
  3811. VULKAN_CREATE_SHADER_MODULE_FAILED,
  3812. VULKAN_UNIFORMBLOCK_SPIRV_SET0_BINDING_OUT_OF_RANGE,
  3813. VULKAN_TEXTURE_SPIRV_SET1_BINDING_OUT_OF_RANGE,
  3814. VULKAN_STORAGEBUFFER_SPIRV_SET1_BINDING_OUT_OF_RANGE,
  3815. VULKAN_STORAGEIMAGE_SPIRV_SET1_BINDING_OUT_OF_RANGE,
  3816. VULKAN_SAMPLER_SPIRV_SET1_BINDING_OUT_OF_RANGE,
  3817. VULKAN_CREATE_DESCRIPTOR_SET_LAYOUT_FAILED,
  3818. VULKAN_CREATE_PIPELINE_LAYOUT_FAILED,
  3819. VULKAN_CREATE_GRAPHICS_PIPELINE_FAILED,
  3820. VULKAN_CREATE_COMPUTE_PIPELINE_FAILED,
  3821. VULKAN_CREATE_IMAGE_VIEW_FAILED,
  3822. VULKAN_VIEW_MAX_DESCRIPTOR_SIZE,
  3823. VULKAN_CREATE_SAMPLER_FAILED,
  3824. VULKAN_SAMPLER_MAX_DESCRIPTOR_SIZE,
  3825. VULKAN_WAIT_FOR_FENCE_FAILED,
  3826. VULKAN_UNIFORM_BUFFER_OVERFLOW,
  3827. VULKAN_DESCRIPTOR_BUFFER_OVERFLOW,
  3828. IDENTICAL_COMMIT_LISTENER,
  3829. COMMIT_LISTENER_ARRAY_FULL,
  3830. TRACE_HOOKS_NOT_ENABLED,
  3831. DEALLOC_BUFFER_INVALID_STATE,
  3832. DEALLOC_IMAGE_INVALID_STATE,
  3833. DEALLOC_SAMPLER_INVALID_STATE,
  3834. DEALLOC_SHADER_INVALID_STATE,
  3835. DEALLOC_PIPELINE_INVALID_STATE,
  3836. DEALLOC_VIEW_INVALID_STATE,
  3837. INIT_BUFFER_INVALID_STATE,
  3838. INIT_IMAGE_INVALID_STATE,
  3839. INIT_SAMPLER_INVALID_STATE,
  3840. INIT_SHADER_INVALID_STATE,
  3841. INIT_PIPELINE_INVALID_STATE,
  3842. INIT_VIEW_INVALID_STATE,
  3843. UNINIT_BUFFER_INVALID_STATE,
  3844. UNINIT_IMAGE_INVALID_STATE,
  3845. UNINIT_SAMPLER_INVALID_STATE,
  3846. UNINIT_SHADER_INVALID_STATE,
  3847. UNINIT_PIPELINE_INVALID_STATE,
  3848. UNINIT_VIEW_INVALID_STATE,
  3849. FAIL_BUFFER_INVALID_STATE,
  3850. FAIL_IMAGE_INVALID_STATE,
  3851. FAIL_SAMPLER_INVALID_STATE,
  3852. FAIL_SHADER_INVALID_STATE,
  3853. FAIL_PIPELINE_INVALID_STATE,
  3854. FAIL_VIEW_INVALID_STATE,
  3855. BUFFER_POOL_EXHAUSTED,
  3856. IMAGE_POOL_EXHAUSTED,
  3857. SAMPLER_POOL_EXHAUSTED,
  3858. SHADER_POOL_EXHAUSTED,
  3859. PIPELINE_POOL_EXHAUSTED,
  3860. VIEW_POOL_EXHAUSTED,
  3861. BEGINPASS_TOO_MANY_COLOR_ATTACHMENTS,
  3862. BEGINPASS_TOO_MANY_RESOLVE_ATTACHMENTS,
  3863. BEGINPASS_ATTACHMENTS_ALIVE,
  3864. DRAW_WITHOUT_BINDINGS,
  3865. SHADERDESC_TOO_MANY_VERTEXSTAGE_TEXTURES,
  3866. SHADERDESC_TOO_MANY_FRAGMENTSTAGE_TEXTURES,
  3867. SHADERDESC_TOO_MANY_COMPUTESTAGE_TEXTURES,
  3868. SHADERDESC_TOO_MANY_VERTEXSTAGE_STORAGEBUFFERS,
  3869. SHADERDESC_TOO_MANY_FRAGMENTSTAGE_STORAGEBUFFERS,
  3870. SHADERDESC_TOO_MANY_COMPUTESTAGE_STORAGEBUFFERS,
  3871. SHADERDESC_TOO_MANY_VERTEXSTAGE_STORAGEIMAGES,
  3872. SHADERDESC_TOO_MANY_FRAGMENTSTAGE_STORAGEIMAGES,
  3873. SHADERDESC_TOO_MANY_COMPUTESTAGE_STORAGEIMAGES,
  3874. SHADERDESC_TOO_MANY_VERTEXSTAGE_TEXTURESAMPLERPAIRS,
  3875. SHADERDESC_TOO_MANY_FRAGMENTSTAGE_TEXTURESAMPLERPAIRS,
  3876. SHADERDESC_TOO_MANY_COMPUTESTAGE_TEXTURESAMPLERPAIRS,
  3877. VALIDATE_BUFFERDESC_CANARY,
  3878. VALIDATE_BUFFERDESC_IMMUTABLE_DYNAMIC_STREAM,
  3879. VALIDATE_BUFFERDESC_SEPARATE_BUFFER_TYPES,
  3880. VALIDATE_BUFFERDESC_EXPECT_NONZERO_SIZE,
  3881. VALIDATE_BUFFERDESC_EXPECT_MATCHING_DATA_SIZE,
  3882. VALIDATE_BUFFERDESC_EXPECT_ZERO_DATA_SIZE,
  3883. VALIDATE_BUFFERDESC_EXPECT_NO_DATA,
  3884. VALIDATE_BUFFERDESC_EXPECT_DATA,
  3885. VALIDATE_BUFFERDESC_STORAGEBUFFER_SUPPORTED,
  3886. VALIDATE_BUFFERDESC_STORAGEBUFFER_SIZE_MULTIPLE_4,
  3887. VALIDATE_IMAGEDATA_NODATA,
  3888. VALIDATE_IMAGEDATA_DATA_SIZE,
  3889. VALIDATE_IMAGEDESC_CANARY,
  3890. VALIDATE_IMAGEDESC_IMMUTABLE_DYNAMIC_STREAM,
  3891. VALIDATE_IMAGEDESC_IMAGETYPE_2D_NUMSLICES,
  3892. VALIDATE_IMAGEDESC_IMAGETYPE_CUBE_NUMSLICES,
  3893. VALIDATE_IMAGEDESC_IMAGETYPE_ARRAY_NUMSLICES,
  3894. VALIDATE_IMAGEDESC_IMAGETYPE_3D_NUMSLICES,
  3895. VALIDATE_IMAGEDESC_NUMSLICES,
  3896. VALIDATE_IMAGEDESC_WIDTH,
  3897. VALIDATE_IMAGEDESC_HEIGHT,
  3898. VALIDATE_IMAGEDESC_NONRT_PIXELFORMAT,
  3899. VALIDATE_IMAGEDESC_MSAA_BUT_NO_ATTACHMENT,
  3900. VALIDATE_IMAGEDESC_DEPTH_3D_IMAGE,
  3901. VALIDATE_IMAGEDESC_ATTACHMENT_EXPECT_IMMUTABLE,
  3902. VALIDATE_IMAGEDESC_ATTACHMENT_EXPECT_NO_DATA,
  3903. VALIDATE_IMAGEDESC_ATTACHMENT_PIXELFORMAT,
  3904. VALIDATE_IMAGEDESC_ATTACHMENT_RESOLVE_EXPECT_NO_MSAA,
  3905. VALIDATE_IMAGEDESC_ATTACHMENT_NO_MSAA_SUPPORT,
  3906. VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_NUM_MIPMAPS,
  3907. VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_3D_IMAGE,
  3908. VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_CUBE_IMAGE,
  3909. VALIDATE_IMAGEDESC_ATTACHMENT_MSAA_ARRAY_IMAGE,
  3910. VALIDATE_IMAGEDESC_STORAGEIMAGE_PIXELFORMAT,
  3911. VALIDATE_IMAGEDESC_STORAGEIMAGE_EXPECT_NO_MSAA,
  3912. VALIDATE_IMAGEDESC_INJECTED_NO_DATA,
  3913. VALIDATE_IMAGEDESC_DYNAMIC_NO_DATA,
  3914. VALIDATE_IMAGEDESC_COMPRESSED_IMMUTABLE,
  3915. VALIDATE_SAMPLERDESC_CANARY,
  3916. VALIDATE_SAMPLERDESC_ANISTROPIC_REQUIRES_LINEAR_FILTERING,
  3917. VALIDATE_SHADERDESC_CANARY,
  3918. VALIDATE_SHADERDESC_VERTEX_SOURCE,
  3919. VALIDATE_SHADERDESC_FRAGMENT_SOURCE,
  3920. VALIDATE_SHADERDESC_COMPUTE_SOURCE,
  3921. VALIDATE_SHADERDESC_VERTEX_SOURCE_OR_BYTECODE,
  3922. VALIDATE_SHADERDESC_FRAGMENT_SOURCE_OR_BYTECODE,
  3923. VALIDATE_SHADERDESC_COMPUTE_SOURCE_OR_BYTECODE,
  3924. VALIDATE_SHADERDESC_INVALID_SHADER_COMBO,
  3925. VALIDATE_SHADERDESC_NO_BYTECODE_SIZE,
  3926. VALIDATE_SHADERDESC_METAL_THREADS_PER_THREADGROUP_INITIALIZED,
  3927. VALIDATE_SHADERDESC_METAL_THREADS_PER_THREADGROUP_MULTIPLE_32,
  3928. VALIDATE_SHADERDESC_UNIFORMBLOCK_NO_CONT_MEMBERS,
  3929. VALIDATE_SHADERDESC_UNIFORMBLOCK_SIZE_IS_ZERO,
  3930. VALIDATE_SHADERDESC_UNIFORMBLOCK_METAL_BUFFER_SLOT_COLLISION,
  3931. VALIDATE_SHADERDESC_UNIFORMBLOCK_HLSL_REGISTER_B_COLLISION,
  3932. VALIDATE_SHADERDESC_UNIFORMBLOCK_WGSL_GROUP0_BINDING_COLLISION,
  3933. VALIDATE_SHADERDESC_UNIFORMBLOCK_SPIRV_SET0_BINDING_COLLISION,
  3934. VALIDATE_SHADERDESC_UNIFORMBLOCK_NO_MEMBERS,
  3935. VALIDATE_SHADERDESC_UNIFORMBLOCK_UNIFORM_GLSL_NAME,
  3936. VALIDATE_SHADERDESC_UNIFORMBLOCK_SIZE_MISMATCH,
  3937. VALIDATE_SHADERDESC_UNIFORMBLOCK_ARRAY_COUNT,
  3938. VALIDATE_SHADERDESC_UNIFORMBLOCK_STD140_ARRAY_TYPE,
  3939. VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_METAL_BUFFER_SLOT_COLLISION,
  3940. VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_HLSL_REGISTER_T_COLLISION,
  3941. VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_HLSL_REGISTER_U_COLLISION,
  3942. VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_GLSL_BINDING_COLLISION,
  3943. VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_WGSL_GROUP1_BINDING_COLLISION,
  3944. VALIDATE_SHADERDESC_VIEW_STORAGEBUFFER_SPIRV_SET1_BINDING_COLLISION,
  3945. VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_EXPECT_COMPUTE_STAGE,
  3946. VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_METAL_TEXTURE_SLOT_COLLISION,
  3947. VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_HLSL_REGISTER_U_COLLISION,
  3948. VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_GLSL_BINDING_COLLISION,
  3949. VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_WGSL_GROUP1_BINDING_COLLISION,
  3950. VALIDATE_SHADERDESC_VIEW_STORAGEIMAGE_SPIRV_SET1_BINDING_COLLISION,
  3951. VALIDATE_SHADERDESC_VIEW_TEXTURE_METAL_TEXTURE_SLOT_COLLISION,
  3952. VALIDATE_SHADERDESC_VIEW_TEXTURE_HLSL_REGISTER_T_COLLISION,
  3953. VALIDATE_SHADERDESC_VIEW_TEXTURE_WGSL_GROUP1_BINDING_COLLISION,
  3954. VALIDATE_SHADERDESC_VIEW_TEXTURE_SPIRV_SET1_BINDING_COLLISION,
  3955. VALIDATE_SHADERDESC_SAMPLER_METAL_SAMPLER_SLOT_COLLISION,
  3956. VALIDATE_SHADERDESC_SAMPLER_HLSL_REGISTER_S_COLLISION,
  3957. VALIDATE_SHADERDESC_SAMPLER_WGSL_GROUP1_BINDING_COLLISION,
  3958. VALIDATE_SHADERDESC_SAMPLER_SPIRV_SET1_BINDING_COLLISION,
  3959. VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_VIEW_SLOT_OUT_OF_RANGE,
  3960. VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_SAMPLER_SLOT_OUT_OF_RANGE,
  3961. VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_TEXTURE_STAGE_MISMATCH,
  3962. VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_EXPECT_TEXTURE_VIEW,
  3963. VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_SAMPLER_STAGE_MISMATCH,
  3964. VALIDATE_SHADERDESC_TEXTURE_SAMPLER_PAIR_GLSL_NAME,
  3965. VALIDATE_SHADERDESC_NONFILTERING_SAMPLER_REQUIRED,
  3966. VALIDATE_SHADERDESC_COMPARISON_SAMPLER_REQUIRED,
  3967. VALIDATE_SHADERDESC_TEXVIEW_NOT_REFERENCED_BY_TEXTURE_SAMPLER_PAIRS,
  3968. VALIDATE_SHADERDESC_SAMPLER_NOT_REFERENCED_BY_TEXTURE_SAMPLER_PAIRS,
  3969. VALIDATE_SHADERDESC_ATTR_STRING_TOO_LONG,
  3970. VALIDATE_PIPELINEDESC_CANARY,
  3971. VALIDATE_PIPELINEDESC_SHADER,
  3972. VALIDATE_PIPELINEDESC_COMPUTE_SHADER_EXPECTED,
  3973. VALIDATE_PIPELINEDESC_NO_COMPUTE_SHADER_EXPECTED,
  3974. VALIDATE_PIPELINEDESC_NO_CONT_ATTRS,
  3975. VALIDATE_PIPELINEDESC_ATTR_BASETYPE_MISMATCH,
  3976. VALIDATE_PIPELINEDESC_LAYOUT_STRIDE4,
  3977. VALIDATE_PIPELINEDESC_ATTR_SEMANTICS,
  3978. VALIDATE_PIPELINEDESC_SHADER_READONLY_STORAGEBUFFERS,
  3979. VALIDATE_PIPELINEDESC_BLENDOP_MINMAX_REQUIRES_BLENDFACTOR_ONE,
  3980. VALIDATE_VIEWDESC_CANARY,
  3981. VALIDATE_VIEWDESC_UNIQUE_VIEWTYPE,
  3982. VALIDATE_VIEWDESC_ANY_VIEWTYPE,
  3983. VALIDATE_VIEWDESC_RESOURCE_ALIVE,
  3984. VALIDATE_VIEWDESC_RESOURCE_FAILED,
  3985. VALIDATE_VIEWDESC_STORAGEBUFFER_OFFSET_VS_BUFFER_SIZE,
  3986. VALIDATE_VIEWDESC_STORAGEBUFFER_OFFSET_MULTIPLE_256,
  3987. VALIDATE_VIEWDESC_STORAGEBUFFER_USAGE,
  3988. VALIDATE_VIEWDESC_STORAGEIMAGE_USAGE,
  3989. VALIDATE_VIEWDESC_COLORATTACHMENT_USAGE,
  3990. VALIDATE_VIEWDESC_RESOLVEATTACHMENT_USAGE,
  3991. VALIDATE_VIEWDESC_DEPTHSTENCILATTACHMENT_USAGE,
  3992. VALIDATE_VIEWDESC_IMAGE_MIPLEVEL,
  3993. VALIDATE_VIEWDESC_IMAGE_2D_SLICE,
  3994. VALIDATE_VIEWDESC_IMAGE_CUBEMAP_SLICE,
  3995. VALIDATE_VIEWDESC_IMAGE_ARRAY_SLICE,
  3996. VALIDATE_VIEWDESC_IMAGE_3D_SLICE,
  3997. VALIDATE_VIEWDESC_TEXTURE_EXPECT_NO_MSAA,
  3998. VALIDATE_VIEWDESC_TEXTURE_MIPLEVELS,
  3999. VALIDATE_VIEWDESC_TEXTURE_2D_SLICES,
  4000. VALIDATE_VIEWDESC_TEXTURE_CUBEMAP_SLICES,
  4001. VALIDATE_VIEWDESC_TEXTURE_ARRAY_SLICES,
  4002. VALIDATE_VIEWDESC_TEXTURE_3D_SLICES,
  4003. VALIDATE_VIEWDESC_STORAGEIMAGE_PIXELFORMAT,
  4004. VALIDATE_VIEWDESC_COLORATTACHMENT_PIXELFORMAT,
  4005. VALIDATE_VIEWDESC_DEPTHSTENCILATTACHMENT_PIXELFORMAT,
  4006. VALIDATE_VIEWDESC_RESOLVEATTACHMENT_SAMPLECOUNT,
  4007. VALIDATE_BEGINPASS_CANARY,
  4008. VALIDATE_BEGINPASS_COMPUTEPASS_EXPECT_NO_ATTACHMENTS,
  4009. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_WIDTH,
  4010. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_WIDTH_NOTSET,
  4011. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_HEIGHT,
  4012. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_HEIGHT_NOTSET,
  4013. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_SAMPLECOUNT,
  4014. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_SAMPLECOUNT_NOTSET,
  4015. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_COLORFORMAT,
  4016. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_COLORFORMAT_NOTSET,
  4017. VALIDATE_BEGINPASS_SWAPCHAIN_EXPECT_DEPTHFORMAT_NOTSET,
  4018. VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_CURRENTDRAWABLE,
  4019. VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_CURRENTDRAWABLE_NOTSET,
  4020. VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_DEPTHSTENCILTEXTURE,
  4021. VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_DEPTHSTENCILTEXTURE_NOTSET,
  4022. VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_MSAACOLORTEXTURE,
  4023. VALIDATE_BEGINPASS_SWAPCHAIN_METAL_EXPECT_MSAACOLORTEXTURE_NOTSET,
  4024. VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RENDERVIEW,
  4025. VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RENDERVIEW_NOTSET,
  4026. VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RESOLVEVIEW,
  4027. VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_RESOLVEVIEW_NOTSET,
  4028. VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_DEPTHSTENCILVIEW,
  4029. VALIDATE_BEGINPASS_SWAPCHAIN_D3D11_EXPECT_DEPTHSTENCILVIEW_NOTSET,
  4030. VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RENDERVIEW,
  4031. VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RENDERVIEW_NOTSET,
  4032. VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RESOLVEVIEW,
  4033. VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_RESOLVEVIEW_NOTSET,
  4034. VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_DEPTHSTENCILVIEW,
  4035. VALIDATE_BEGINPASS_SWAPCHAIN_WGPU_EXPECT_DEPTHSTENCILVIEW_NOTSET,
  4036. VALIDATE_BEGINPASS_SWAPCHAIN_GL_EXPECT_FRAMEBUFFER_NOTSET,
  4037. VALIDATE_BEGINPASS_COLORATTACHMENTVIEWS_CONTINUOUS,
  4038. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_ALIVE,
  4039. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_VALID,
  4040. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_TYPE,
  4041. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_IMAGE_ALIVE,
  4042. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_IMAGE_VALID,
  4043. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SIZES,
  4044. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SAMPLECOUNT,
  4045. VALIDATE_BEGINPASS_COLORATTACHMENTVIEW_SAMPLECOUNTS_EQUAL,
  4046. VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_NO_COLORATTACHMENTVIEW,
  4047. VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_ALIVE,
  4048. VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_VALID,
  4049. VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_TYPE,
  4050. VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_IMAGE_ALIVE,
  4051. VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_IMAGE_VALID,
  4052. VALIDATE_BEGINPASS_RESOLVEATTACHMENTVIEW_SIZES,
  4053. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEWS_CONTINUOUS,
  4054. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_ALIVE,
  4055. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_VALID,
  4056. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_TYPE,
  4057. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_IMAGE_ALIVE,
  4058. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_IMAGE_VALID,
  4059. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_SIZES,
  4060. VALIDATE_BEGINPASS_DEPTHSTENCILATTACHMENTVIEW_SAMPLECOUNT,
  4061. VALIDATE_BEGINPASS_ATTACHMENTS_EXPECTED,
  4062. VALIDATE_AVP_RENDERPASS_EXPECTED,
  4063. VALIDATE_ASR_RENDERPASS_EXPECTED,
  4064. VALIDATE_APIP_PIPELINE_VALID_ID,
  4065. VALIDATE_APIP_PIPELINE_EXISTS,
  4066. VALIDATE_APIP_PIPELINE_VALID,
  4067. VALIDATE_APIP_PASS_EXPECTED,
  4068. VALIDATE_APIP_PIPELINE_SHADER_ALIVE,
  4069. VALIDATE_APIP_PIPELINE_SHADER_VALID,
  4070. VALIDATE_APIP_COMPUTEPASS_EXPECTED,
  4071. VALIDATE_APIP_RENDERPASS_EXPECTED,
  4072. VALIDATE_APIP_SWAPCHAIN_COLOR_COUNT,
  4073. VALIDATE_APIP_SWAPCHAIN_COLOR_FORMAT,
  4074. VALIDATE_APIP_SWAPCHAIN_DEPTH_FORMAT,
  4075. VALIDATE_APIP_SWAPCHAIN_SAMPLE_COUNT,
  4076. VALIDATE_APIP_ATTACHMENTS_ALIVE,
  4077. VALIDATE_APIP_COLORATTACHMENTS_COUNT,
  4078. VALIDATE_APIP_COLORATTACHMENTS_VIEW_VALID,
  4079. VALIDATE_APIP_COLORATTACHMENTS_IMAGE_VALID,
  4080. VALIDATE_APIP_COLORATTACHMENTS_FORMAT,
  4081. VALIDATE_APIP_DEPTHSTENCILATTACHMENT_VIEW_VALID,
  4082. VALIDATE_APIP_DEPTHSTENCILATTACHMENT_IMAGE_VALID,
  4083. VALIDATE_APIP_DEPTHSTENCILATTACHMENT_FORMAT,
  4084. VALIDATE_APIP_ATTACHMENT_SAMPLE_COUNT,
  4085. VALIDATE_ABND_PASS_EXPECTED,
  4086. VALIDATE_ABND_EMPTY_BINDINGS,
  4087. VALIDATE_ABND_NO_PIPELINE,
  4088. VALIDATE_ABND_PIPELINE_ALIVE,
  4089. VALIDATE_ABND_PIPELINE_VALID,
  4090. VALIDATE_ABND_PIPELINE_SHADER_ALIVE,
  4091. VALIDATE_ABND_PIPELINE_SHADER_VALID,
  4092. VALIDATE_ABND_COMPUTE_EXPECTED_NO_VBUFS,
  4093. VALIDATE_ABND_COMPUTE_EXPECTED_NO_IBUF,
  4094. VALIDATE_ABND_EXPECTED_VBUF,
  4095. VALIDATE_ABND_VBUF_ALIVE,
  4096. VALIDATE_ABND_VBUF_USAGE,
  4097. VALIDATE_ABND_VBUF_OVERFLOW,
  4098. VALIDATE_ABND_EXPECTED_NO_IBUF,
  4099. VALIDATE_ABND_EXPECTED_IBUF,
  4100. VALIDATE_ABND_IBUF_ALIVE,
  4101. VALIDATE_ABND_IBUF_USAGE,
  4102. VALIDATE_ABND_IBUF_OVERFLOW,
  4103. VALIDATE_ABND_EXPECTED_VIEW_BINDING,
  4104. VALIDATE_ABND_VIEW_ALIVE,
  4105. VALIDATE_ABND_EXPECT_TEXVIEW,
  4106. VALIDATE_ABND_EXPECT_SBVIEW,
  4107. VALIDATE_ABND_EXPECT_SIMGVIEW,
  4108. VALIDATE_ABND_TEXVIEW_IMAGETYPE_MISMATCH,
  4109. VALIDATE_ABND_TEXVIEW_EXPECTED_MULTISAMPLED_IMAGE,
  4110. VALIDATE_ABND_TEXVIEW_EXPECTED_NON_MULTISAMPLED_IMAGE,
  4111. VALIDATE_ABND_TEXVIEW_EXPECTED_FILTERABLE_IMAGE,
  4112. VALIDATE_ABND_TEXVIEW_EXPECTED_DEPTH_IMAGE,
  4113. VALIDATE_ABND_SBVIEW_READWRITE_IMMUTABLE,
  4114. VALIDATE_ABND_SIMGVIEW_COMPUTE_PASS_EXPECTED,
  4115. VALIDATE_ABND_SIMGVIEW_IMAGETYPE_MISMATCH,
  4116. VALIDATE_ABND_SIMGVIEW_ACCESSFORMAT,
  4117. VALIDATE_ABND_EXPECTED_SAMPLER_BINDING,
  4118. VALIDATE_ABND_UNEXPECTED_SAMPLER_COMPARE_NEVER,
  4119. VALIDATE_ABND_EXPECTED_SAMPLER_COMPARE_NEVER,
  4120. VALIDATE_ABND_EXPECTED_NONFILTERING_SAMPLER,
  4121. VALIDATE_ABND_SAMPLER_ALIVE,
  4122. VALIDATE_ABND_SAMPLER_VALID,
  4123. VALIDATE_ABND_TEXTURE_BINDING_VS_DEPTHSTENCIL_ATTACHMENT,
  4124. VALIDATE_ABND_TEXTURE_BINDING_VS_COLOR_ATTACHMENT,
  4125. VALIDATE_ABND_TEXTURE_BINDING_VS_RESOLVE_ATTACHMENT,
  4126. VALIDATE_ABND_TEXTURE_VS_STORAGEIMAGE_BINDING,
  4127. VALIDATE_AU_PASS_EXPECTED,
  4128. VALIDATE_AU_NO_PIPELINE,
  4129. VALIDATE_AU_PIPELINE_ALIVE,
  4130. VALIDATE_AU_PIPELINE_VALID,
  4131. VALIDATE_AU_PIPELINE_SHADER_ALIVE,
  4132. VALIDATE_AU_PIPELINE_SHADER_VALID,
  4133. VALIDATE_AU_NO_UNIFORMBLOCK_AT_SLOT,
  4134. VALIDATE_AU_SIZE,
  4135. VALIDATE_DRAW_RENDERPASS_EXPECTED,
  4136. VALIDATE_DRAW_BASEELEMENT_GE_ZERO,
  4137. VALIDATE_DRAW_NUMELEMENTS_GE_ZERO,
  4138. VALIDATE_DRAW_NUMINSTANCES_GE_ZERO,
  4139. VALIDATE_DRAW_EX_RENDERPASS_EXPECTED,
  4140. VALIDATE_DRAW_EX_BASEELEMENT_GE_ZERO,
  4141. VALIDATE_DRAW_EX_NUMELEMENTS_GE_ZERO,
  4142. VALIDATE_DRAW_EX_NUMINSTANCES_GE_ZERO,
  4143. VALIDATE_DRAW_EX_BASEINSTANCE_GE_ZERO,
  4144. VALIDATE_DRAW_EX_BASEVERTEX_VS_INDEXED,
  4145. VALIDATE_DRAW_EX_BASEINSTANCE_VS_INSTANCED,
  4146. VALIDATE_DRAW_EX_BASEVERTEX_NOT_SUPPORTED,
  4147. VALIDATE_DRAW_EX_BASEINSTANCE_NOT_SUPPORTED,
  4148. VALIDATE_DRAW_REQUIRED_BINDINGS_OR_UNIFORMS_MISSING,
  4149. VALIDATE_DISPATCH_COMPUTEPASS_EXPECTED,
  4150. VALIDATE_DISPATCH_NUMGROUPSX,
  4151. VALIDATE_DISPATCH_NUMGROUPSY,
  4152. VALIDATE_DISPATCH_NUMGROUPSZ,
  4153. VALIDATE_DISPATCH_REQUIRED_BINDINGS_OR_UNIFORMS_MISSING,
  4154. VALIDATE_UPDATEBUF_USAGE,
  4155. VALIDATE_UPDATEBUF_SIZE,
  4156. VALIDATE_UPDATEBUF_ONCE,
  4157. VALIDATE_UPDATEBUF_APPEND,
  4158. VALIDATE_APPENDBUF_USAGE,
  4159. VALIDATE_APPENDBUF_SIZE,
  4160. VALIDATE_APPENDBUF_UPDATE,
  4161. VALIDATE_UPDIMG_USAGE,
  4162. VALIDATE_UPDIMG_ONCE,
  4163. VALIDATION_FAILED,
  4164. }
  4165. /*
  4166. sg_desc
  4167. The sg_desc struct contains configuration values for sokol_gfx,
  4168. it is used as parameter to the sg_setup() call.
  4169. The default configuration is:
  4170. .buffer_pool_size 128
  4171. .image_pool_size 128
  4172. .sampler_pool_size 64
  4173. .shader_pool_size 32
  4174. .pipeline_pool_size 64
  4175. .view_pool_size 256
  4176. .uniform_buffer_size 4 MB (4*1024*1024)
  4177. .max_commit_listeners 1024
  4178. .disable_validation false
  4179. .metal.force_managed_storage_mode false
  4180. .metal.use_command_buffer_with_retained_references false
  4181. .wgpu.disable_bindgroups_cache false
  4182. .wgpu.bindgroups_cache_size 1024
  4183. .vulkan.copy_staging_buffer_size 4 MB
  4184. .vulkan.stream_staging_buffer_size 16 MB
  4185. .vulkan.descriptor_buffer_size 16 MB
  4186. .allocator.alloc_fn 0 (in this case, malloc() will be called)
  4187. .allocator.free_fn 0 (in this case, free() will be called)
  4188. .allocator.user_data 0
  4189. .environment.defaults.color_format: default value depends on selected backend:
  4190. all GL backends: SG_PIXELFORMAT_RGBA8
  4191. Metal and D3D11: SG_PIXELFORMAT_BGRA8
  4192. WebGPU: *no default* (must be queried from WebGPU swapchain object)
  4193. .environment.defaults.depth_format: SG_PIXELFORMAT_DEPTH_STENCIL
  4194. .environment.defaults.sample_count: 1
  4195. Metal specific:
  4196. (NOTE: All Objective-C object references are transferred through
  4197. a bridged cast (__bridge const void*) to sokol_gfx, which will use an
  4198. unretained bridged cast (__bridge id<xxx>) to retrieve the Objective-C
  4199. references back. Since the bridge cast is unretained, the caller
  4200. must hold a strong reference to the Objective-C object until sg_setup()
  4201. returns.
  4202. .metal.force_managed_storage_mode
  4203. when enabled, Metal buffers and texture resources are created in managed storage
  4204. mode, otherwise sokol-gfx will decide whether to create buffers and
  4205. textures in managed or shared storage mode (this is mainly a debugging option)
  4206. .metal.use_command_buffer_with_retained_references
  4207. when true, the sokol-gfx Metal backend will use Metal command buffers which
  4208. bump the reference count of resource objects as long as they are inflight,
  4209. this is slower than the default command-buffer-with-unretained-references
  4210. method, this may be a workaround when confronted with lifetime validation
  4211. errors from the Metal validation layer until a proper fix has been implemented
  4212. .environment.metal.device
  4213. a pointer to the MTLDevice object
  4214. D3D11 specific:
  4215. .environment.d3d11.device
  4216. a pointer to the ID3D11Device object, this must have been created
  4217. before sg_setup() is called
  4218. .environment.d3d11.device_context
  4219. a pointer to the ID3D11DeviceContext object
  4220. .d3d11.shader_debugging
  4221. set this to true to compile shaders which are provided as HLSL source
  4222. code with debug information and without optimization, this allows
  4223. shader debugging in tools like RenderDoc, to output source code
  4224. instead of byte code from sokol-shdc, omit the `--binary` cmdline
  4225. option
  4226. WebGPU specific:
  4227. .wgpu.disable_bindgroups_cache
  4228. When this is true, the WebGPU backend will create and immediately
  4229. release a BindGroup object in the sg_apply_bindings() call, only
  4230. use this for debugging purposes.
  4231. .wgpu.bindgroups_cache_size
  4232. The size of the bindgroups cache for re-using BindGroup objects
  4233. between sg_apply_bindings() calls. The smaller the cache size,
  4234. the more likely are cache slot collisions which will cause
  4235. a BindGroups object to be destroyed and a new one created.
  4236. Use the information returned by sg_query_stats() to check
  4237. if this is a frequent occurrence, and increase the cache size as
  4238. needed (the default is 1024).
  4239. NOTE: wgpu_bindgroups_cache_size must be a power-of-2 number!
  4240. .environment.wgpu.device
  4241. a WGPUDevice handle
  4242. Vulkan specific:
  4243. .vulkan.copy_staging_buffer_size
  4244. Size of the staging buffer in bytes for uploading the initial
  4245. content of buffers and images, and for updating
  4246. .usage.dynamic_update resources. The default is 4 MB,
  4247. bigger resource updates are split into multiple chunks
  4248. of the staging buffer size
  4249. .vulkan.stream_staging_buffer_size
  4250. Size of the staging buffer in bytes for updating .usage.stream_update
  4251. resources. The default is 16 MB. The size must be big enough
  4252. to accomodate all update into .usage.stream_update resources.
  4253. Any additional data will cause an error log message and
  4254. incomplete rendering. Note that the actually allocated size
  4255. will be twice as much because the stream-staging-buffer is
  4256. double-buffered.
  4257. .vulkan.descriptor_buffer_size
  4258. Size of the descriptor-upload buffer in bytes. The default
  4259. size is 16 bytes. The size must be big enough to accomodate
  4260. all unifrom-block, view- and sampler-bindings in a single
  4261. frame (assume a worst-case of 256 bytes per binding). Note
  4262. that the actually allocated size will be twice as much
  4263. because the descriptor-buffer is double-buffered.
  4264. When using sokol_gfx.h and sokol_app.h together, consider using the
  4265. helper function sglue_environment() in the sokol_glue.h header to
  4266. initialize the sg_desc.environment nested struct. sglue_environment() returns
  4267. a completely initialized sg_environment struct with information
  4268. provided by sokol_app.h.
  4269. */
  4270. Environment_Defaults :: struct {
  4271. color_format : Pixel_Format,
  4272. depth_format : Pixel_Format,
  4273. sample_count : c.int,
  4274. }
  4275. Metal_Environment :: struct {
  4276. device : rawptr,
  4277. }
  4278. D3d11_Environment :: struct {
  4279. device : rawptr,
  4280. device_context : rawptr,
  4281. }
  4282. Wgpu_Environment :: struct {
  4283. device : rawptr,
  4284. }
  4285. Vulkan_Environment :: struct {
  4286. physical_device : rawptr,
  4287. device : rawptr,
  4288. queue : rawptr,
  4289. queue_family_index : u32,
  4290. }
  4291. Environment :: struct {
  4292. defaults : Environment_Defaults,
  4293. metal : Metal_Environment,
  4294. d3d11 : D3d11_Environment,
  4295. wgpu : Wgpu_Environment,
  4296. vulkan : Vulkan_Environment,
  4297. }
  4298. /*
  4299. sg_commit_listener
  4300. Used with function sg_add_commit_listener() to add a callback
  4301. which will be called in sg_commit(). This is useful for libraries
  4302. building on top of sokol-gfx to be notified about when a frame
  4303. ends (instead of having to guess, or add a manual 'new-frame'
  4304. function.
  4305. */
  4306. Commit_Listener :: struct {
  4307. func : proc "c" (a0: rawptr),
  4308. user_data : rawptr,
  4309. }
  4310. /*
  4311. sg_allocator
  4312. Used in sg_desc to provide custom memory-alloc and -free functions
  4313. to sokol_gfx.h. If memory management should be overridden, both the
  4314. alloc_fn and free_fn function must be provided (e.g. it's not valid to
  4315. override one function but not the other).
  4316. */
  4317. Allocator :: struct {
  4318. alloc_fn : proc "c" (a0: c.size_t, a1: rawptr) -> rawptr,
  4319. free_fn : proc "c" (a0: rawptr, a1: rawptr),
  4320. user_data : rawptr,
  4321. }
  4322. /*
  4323. sg_logger
  4324. Used in sg_desc to provide a logging function. Please be aware
  4325. that without logging function, sokol-gfx will be completely
  4326. silent, e.g. it will not report errors, warnings and
  4327. validation layer messages. For maximum error verbosity,
  4328. compile in debug mode (e.g. NDEBUG *not* defined) and provide a
  4329. compatible logger function in the sg_setup() call
  4330. (for instance the standard logging function from sokol_log.h).
  4331. */
  4332. Logger :: struct {
  4333. func : proc "c" (a0: cstring, a1: u32, a2: u32, a3: cstring, a4: u32, a5: cstring, a6: rawptr),
  4334. user_data : rawptr,
  4335. }
  4336. D3d11_Desc :: struct {
  4337. shader_debugging : bool,
  4338. }
  4339. Metal_Desc :: struct {
  4340. force_managed_storage_mode : bool,
  4341. use_command_buffer_with_retained_references : bool,
  4342. }
  4343. Wgpu_Desc :: struct {
  4344. disable_bindgroups_cache : bool,
  4345. bindgroups_cache_size : c.int,
  4346. }
  4347. Vulkan_Desc :: struct {
  4348. copy_staging_buffer_size : c.int,
  4349. stream_staging_buffer_size : c.int,
  4350. descriptor_buffer_size : c.int,
  4351. }
  4352. Desc :: struct {
  4353. _ : u32,
  4354. buffer_pool_size : c.int,
  4355. image_pool_size : c.int,
  4356. sampler_pool_size : c.int,
  4357. shader_pool_size : c.int,
  4358. pipeline_pool_size : c.int,
  4359. view_pool_size : c.int,
  4360. uniform_buffer_size : c.int,
  4361. max_commit_listeners : c.int,
  4362. disable_validation : bool,
  4363. enforce_portable_limits : bool,
  4364. d3d11 : D3d11_Desc,
  4365. metal : Metal_Desc,
  4366. wgpu : Wgpu_Desc,
  4367. vulkan : Vulkan_Desc,
  4368. allocator : Allocator,
  4369. logger : Logger,
  4370. environment : Environment,
  4371. _ : u32,
  4372. }
  4373. /*
  4374. Backend-specific structs and functions, these may come in handy for mixing
  4375. sokol-gfx rendering with 'native backend' rendering functions.
  4376. This group of functions will be expanded as needed.
  4377. */
  4378. D3d11_Buffer_Info :: struct {
  4379. buf : rawptr,
  4380. }
  4381. D3d11_Image_Info :: struct {
  4382. tex2d : rawptr,
  4383. tex3d : rawptr,
  4384. res : rawptr,
  4385. }
  4386. D3d11_Sampler_Info :: struct {
  4387. smp : rawptr,
  4388. }
  4389. D3d11_Shader_Info :: struct {
  4390. cbufs : [8]rawptr,
  4391. vs : rawptr,
  4392. fs : rawptr,
  4393. }
  4394. D3d11_Pipeline_Info :: struct {
  4395. il : rawptr,
  4396. rs : rawptr,
  4397. dss : rawptr,
  4398. bs : rawptr,
  4399. }
  4400. D3d11_View_Info :: struct {
  4401. srv : rawptr,
  4402. uav : rawptr,
  4403. rtv : rawptr,
  4404. dsv : rawptr,
  4405. }
  4406. Mtl_Buffer_Info :: struct {
  4407. buf : [2]rawptr,
  4408. active_slot : c.int,
  4409. }
  4410. Mtl_Image_Info :: struct {
  4411. tex : [2]rawptr,
  4412. active_slot : c.int,
  4413. }
  4414. Mtl_Sampler_Info :: struct {
  4415. smp : rawptr,
  4416. }
  4417. Mtl_Shader_Info :: struct {
  4418. vertex_lib : rawptr,
  4419. fragment_lib : rawptr,
  4420. vertex_func : rawptr,
  4421. fragment_func : rawptr,
  4422. }
  4423. Mtl_Pipeline_Info :: struct {
  4424. rps : rawptr,
  4425. dss : rawptr,
  4426. }
  4427. Wgpu_Buffer_Info :: struct {
  4428. buf : rawptr,
  4429. }
  4430. Wgpu_Image_Info :: struct {
  4431. tex : rawptr,
  4432. }
  4433. Wgpu_Sampler_Info :: struct {
  4434. smp : rawptr,
  4435. }
  4436. Wgpu_Shader_Info :: struct {
  4437. vs_mod : rawptr,
  4438. fs_mod : rawptr,
  4439. bgl : rawptr,
  4440. }
  4441. Wgpu_Pipeline_Info :: struct {
  4442. render_pipeline : rawptr,
  4443. compute_pipeline : rawptr,
  4444. }
  4445. Wgpu_View_Info :: struct {
  4446. view : rawptr,
  4447. }
  4448. Gl_Buffer_Info :: struct {
  4449. buf : [2]u32,
  4450. active_slot : c.int,
  4451. }
  4452. Gl_Image_Info :: struct {
  4453. tex : [2]u32,
  4454. tex_target : u32,
  4455. active_slot : c.int,
  4456. }
  4457. Gl_Sampler_Info :: struct {
  4458. smp : u32,
  4459. }
  4460. Gl_Shader_Info :: struct {
  4461. prog : u32,
  4462. }
  4463. Gl_View_Info :: struct {
  4464. tex_view : [2]u32,
  4465. msaa_render_buffer : u32,
  4466. msaa_resolve_frame_buffer : u32,
  4467. }