Restrictions on function parameters · Issue #1139 - GitHub
文章推薦指數: 80 %
Regarding pointer arguments: In SPIR-V for Vulkan, a pointer operand to a function must be into one of the following storage classes: ...
Skiptocontent
{{message}}
gpuweb
/
gpuweb
Public
Notifications
Fork
231
Star
3.1k
Code
Issues
346
Pullrequests
44
Discussions
Actions
Wiki
Security
Insights
More
Code
Issues
Pullrequests
Discussions
Actions
Wiki
Security
Insights
Newissue
Haveaquestionaboutthisproject?SignupforafreeGitHubaccounttoopenanissueandcontactitsmaintainersandthecommunity.
Pickausername
EmailAddress
Password
SignupforGitHub
Byclicking“SignupforGitHub”,youagreetoourtermsofserviceand
privacystatement.We’lloccasionallysendyouaccountrelatedemails.
AlreadyonGitHub?
Signin
toyouraccount
Jumptobottom
Restrictionsonfunctionparameters
#1139
Closed
dneto0openedthisissue
Oct7,2020
·14comments
Closed
Restrictionsonfunctionparameters
#1139
dneto0openedthisissue
Oct7,2020
·14comments
Assignees
Labels
wgsl
WebGPUShadingLanguageIssues
Projects
WGSL
Comments
Copylink
Contributor
dneto0
commented
Oct7,2020
Whataretherestrictionsonfunctionparameters?
Wecanhavedifferentrulesbetweenbuiltinfunctionsanduser-writtenfunctions.
Regardingpointerarguments:
InSPIR-VforVulkan,apointeroperandtoafunctionmustbeintooneofthefollowingstorageclasses:UniformConstant,Function,Private,Workgroup.SonoUBOorSSBOpointersareallowed.
Inrecentdiscussion@kvarkrecalledthatwehadalreadydecidedtodisallowpassingtexturesandsamplersasfunctionparameters(andalsopointers-to-these-things).
GLSLallowsopaquetypestobe"in"parameterstofunctions.However,I'vefoundsomeconcerningbehaviour(a.k.a.abug?)forpassingaformattedwrite-onlystorageimageintoauser-definedhelperfunction.SeeKhronosGroup/glslang#2415
Iwanttoavoidanyworkaroundthatrequiresinliningthecalledfunction.
SoIwouldmuchpreferforWGSLtodisallowtexturesandsamplers(orpointerstothem)tobepassedintouser-definedfunctions.
Thetextwasupdatedsuccessfully,buttheseerrorswereencountered:
Allreactions
dneto0
added
the
wgsl
WebGPUShadingLanguageIssues
label
Oct7,2020
Copylink
johnkslang
commented
Oct7,2020
Thewrite-onlyimage-without-formatthingislike.01%ofwhatisimportantforpassingtextures/samplerstouserfunctions,sothatonecornercaseshouldprobablynotbedecidingwhattodofortherestofthe99.99%ofthisspace.
Areyoureallysuggestinguserscannotwriteafunctiontooperateonatexture/image/samplerchosenatacallsite?That'squiteastepbackwardinfunctionalitythat'sexistedsince2003inGLSL.MaybeI'mnotunderstanding.
Allreactions
Sorry,somethingwentwrong.
Copylink
Contributor
Author
dneto0
commented
Oct8,2020
FYI@johnkslangpointedmeatKhronosGroup/GLSL#57whichcoversthisformatted-vs-unformatedissueprettythoroughlyfromtheGLSLspecperspective.
Areyoureallysuggestinguserscannotwriteafunctiontooperateonatexture/image/samplerchosenatacallsite?That'squiteastepbackwardinfunctionalitythat'sexistedsince2003inGLSL.MaybeI'mnotunderstanding.
Thatwouldbetheconservativechoice.I'mnotclaimingthat'sagreatsolution.
Workingthroughthissomemore,inaslightlydifferentcontext:SPIR-VforVulkandoespermitpointer-to-texture/samplertobepassedintohelperfunctions.Inthiscasetheformat(includingUnknown)ispartoftheparametertype.Ifthedriversupportsitwell,thenwe'redone.Ifnot,thenthebrowsercanmodifytheSPIR-Vtoinlinetheoffendingfunctionsasneeded.
Now,inpastwe'vehadaprincipleofnotrequiringinliningforshadertranslationsfromWGSLtounderlyingplatformshaderlanguages.Sothispathcomesclosetothatline:theinliningisonlyrequiredifthedriverhasabug,essentially.
Allreactions
Sorry,somethingwentwrong.
Copylink
Contributor
Author
dneto0
commented
Oct8,2020
Steppingbackalittlebit:
Ihaveassumedsofarthattheformalparametertypemustbethesameastheformalargumenttype(moduloWGSLtypealiasing).Thatis,noimplicitconversionsareperformedatfunctioncallboundary.
Also,Iassumethatforstoragetextures,thestoragetexturetypeisparameterizedbythetexelformat.(E.g.whenyouhaveadifferenttexelformat,thenyouhaveadifferenttype.)(ThisisthecaseforSPIR-V,butnotthecaseforGLSL.)
Thatsaid,forSPIR-VandVulkan,forpointerarguments:
apointer-to-storage-textureisokasafunctionparameter,asarguedabove.
apointer-to-sampled-textureisokasafunctionparameter:SampledimagestypesinSPIR-Varenotparameterizedbyatexelformat.Theyareparameterizedbythesampledtype,oneoff32,i32,oru32.AndasJohnKsaidthisisfunctionalitythathaslongsupport
assumingbasefunctionality,wedon'thaveVariablePointersorVariablePointerStorageBuffercapability,andsoallpointersare"logicalpointers",andfromuniversalvalidationruleswehave:
apointeroperandtoafunctioncallmustbeinoneoftheUniformConstant(handle),Function,Private,Workgroupstorageclasses.(AtomicCounterdoesn'texistinVulkan;it'sforOpenGL)NotethismeansnofunctionparametersthatarepointerstoUBOorSSBO.(Note!)
apointeroperandtoafunctioncallmustbeeither:
-a"memoryobjectdeclaration",i.e.thepointerforthebaseofavariable,orafunctionparameterthatitselfisapointervalue.
-orthepointertoanelementofanarrayoftexturesorsamplers,wherethebasepointerofthearrayitselfisamemoryobjectdeclaration.WGSLdoesn'tyethavearraysoftexturesorsamplers,butIexpectthiswillcomeinthefuture.
Allreactions
Sorry,somethingwentwrong.
grorg
addedthistoUnderDiscussion
inWGSL
Oct13,2020
grorg
movedthisfromUnderDiscussion
toForNextMeeting
inWGSL
Oct13,2020
grorg
changedthetitle
restrictionsonfunctionparameters
Restrictionsonfunctionparameters
Oct13,2020
Copylink
Contributor
grorg
commented
Oct19,2020
Discussedatthe2020-10-19VirtualF2F
Allreactions
Sorry,somethingwentwrong.
Copylink
Contributor
grorg
commented
Oct19,2020
•
edited
Currentresolutionistoallowtextureparameterstofunctionsviaptr<>,assumingthatMicrosoftisokwithit(i.e.isitsupportedinHLSL?).@pow2clk@RafaelCintron
Allreactions
Sorry,somethingwentwrong.
Copylink
Contributor
kvark
commented
Oct19,2020
Idon'tthinkptr<>iseitherhelpfulornecessarythere,fwiw.Ibelieve@litherumexpressedasimilarconcern.
Allreactions
Sorry,somethingwentwrong.
Copylink
Contributor
Author
dneto0
commented
Oct19,2020
Discussion,andresolutionsofar.
SPIR-V/Vulkanallowspointer-to-textureandpointer-to-samplerasfunctionarguments.Otherstorageclassesdon'thavethatfreedom(e.g.pointertoSSBOandpointertoUBOarenotpermittedasfunctionparameters.)
Don'tknowifHLSLpermitsthis.NeedMicrosoft'sinput.
Discussionaboutwhatthetexture+samplerparameterslooklike.InSPIR-Vtheparameterispointer-to-andtheloadisdoneatthepointofuseinthetexturebuiltin/instruction.
Keepthedecisionthattexture/samplerresourcesaredeclaredatmodulescope.
Allreactions
Sorry,somethingwentwrong.
Copylink
Contributor
pow2clk
commented
Oct19,2020
Texturesandsamplerscanbepassedintouserfunctions.Averycommonwaytoenableold-styleHLSLcodethatusesTex2Distodefineauserfunctionforit:
float4Tex2D(Texture2D
延伸文章資訊
- 1Attributes in Clang — Clang 15.0.0git documentation
Use __attribute__((alloc_align(<alignment>)) on a function declaration to specify that the return...
- 2dcl_interface (sm5 - asm) - Win32 apps | Microsoft Docs
Declare function table pointers (interfaces). ... In the HLSL virtual inlining model it's always ...
- 3Advanced HLSL using closures and function pointers - code4k
Hacking function pointers in HLSL. The principle is very simple: Instead of using interface and c...
- 4Restrictions on function parameters · Issue #1139 - GitHub
Regarding pointer arguments: In SPIR-V for Vulkan, a pointer operand to a function must be into o...
- 5Example of VK_KHR_buffer_device_address? : r/vulkan - Reddit
I know this was probably added mainly to support raytracing shaders, but is there a good example ...