EffectVariable.inl 190 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967
  1. //--------------------------------------------------------------------------------------
  2. // File: EffectVariable.inl
  3. //
  4. // Direct3D 11 Effects Variable reflection template
  5. // These templates define the many Effect variable types.
  6. //
  7. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  8. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  9. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  10. // PARTICULAR PURPOSE.
  11. //
  12. // Copyright (c) Microsoft Corporation. All rights reserved.
  13. //
  14. // http://go.microsoft.com/fwlink/p/?LinkId=271568
  15. //--------------------------------------------------------------------------------------
  16. #pragma warning(push)
  17. #pragma warning(disable : 4127)
  18. //////////////////////////////////////////////////////////////////////////
  19. // Invalid variable forward defines
  20. //////////////////////////////////////////////////////////////////////////
  21. struct SEffectInvalidScalarVariable;
  22. struct SEffectInvalidVectorVariable;
  23. struct SEffectInvalidMatrixVariable;
  24. struct SEffectInvalidStringVariable;
  25. struct SEffectInvalidClassInstanceVariable;
  26. struct SEffectInvalidInterfaceVariable;
  27. struct SEffectInvalidShaderResourceVariable;
  28. struct SEffectInvalidUnorderedAccessViewVariable;
  29. struct SEffectInvalidRenderTargetViewVariable;
  30. struct SEffectInvalidDepthStencilViewVariable;
  31. struct SEffectInvalidConstantBuffer;
  32. struct SEffectInvalidShaderVariable;
  33. struct SEffectInvalidBlendVariable;
  34. struct SEffectInvalidDepthStencilVariable;
  35. struct SEffectInvalidRasterizerVariable;
  36. struct SEffectInvalidSamplerVariable;
  37. struct SEffectInvalidTechnique;
  38. struct SEffectInvalidPass;
  39. struct SEffectInvalidType;
  40. extern SEffectInvalidScalarVariable g_InvalidScalarVariable;
  41. extern SEffectInvalidVectorVariable g_InvalidVectorVariable;
  42. extern SEffectInvalidMatrixVariable g_InvalidMatrixVariable;
  43. extern SEffectInvalidStringVariable g_InvalidStringVariable;
  44. extern SEffectInvalidClassInstanceVariable g_InvalidClassInstanceVariable;
  45. extern SEffectInvalidInterfaceVariable g_InvalidInterfaceVariable;
  46. extern SEffectInvalidShaderResourceVariable g_InvalidShaderResourceVariable;
  47. extern SEffectInvalidUnorderedAccessViewVariable g_InvalidUnorderedAccessViewVariable;
  48. extern SEffectInvalidRenderTargetViewVariable g_InvalidRenderTargetViewVariable;
  49. extern SEffectInvalidDepthStencilViewVariable g_InvalidDepthStencilViewVariable;
  50. extern SEffectInvalidConstantBuffer g_InvalidConstantBuffer;
  51. extern SEffectInvalidShaderVariable g_InvalidShaderVariable;
  52. extern SEffectInvalidBlendVariable g_InvalidBlendVariable;
  53. extern SEffectInvalidDepthStencilVariable g_InvalidDepthStencilVariable;
  54. extern SEffectInvalidRasterizerVariable g_InvalidRasterizerVariable;
  55. extern SEffectInvalidSamplerVariable g_InvalidSamplerVariable;
  56. extern SEffectInvalidTechnique g_InvalidTechnique;
  57. extern SEffectInvalidPass g_InvalidPass;
  58. extern SEffectInvalidType g_InvalidType;
  59. enum ETemplateVarType
  60. {
  61. ETVT_Bool,
  62. ETVT_Int,
  63. ETVT_Float,
  64. ETVT_bool
  65. };
  66. //////////////////////////////////////////////////////////////////////////
  67. // Invalid effect variable struct definitions
  68. //////////////////////////////////////////////////////////////////////////
  69. struct SEffectInvalidType : public ID3DX11EffectType
  70. {
  71. STDMETHOD_(bool, IsValid)() override { return false; }
  72. STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_TYPE_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  73. STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidType; }
  74. STDMETHOD_(ID3DX11EffectType*, GetMemberTypeByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidType; }
  75. STDMETHOD_(ID3DX11EffectType*, GetMemberTypeBySemantic)(_In_z_ LPCSTR Semantic) override { UNREFERENCED_PARAMETER(Semantic); return &g_InvalidType; }
  76. STDMETHOD_(LPCSTR, GetMemberName)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return nullptr; }
  77. STDMETHOD_(LPCSTR, GetMemberSemantic)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return nullptr; }
  78. IUNKNOWN_IMP(SEffectInvalidType, ID3DX11EffectType, IUnknown);
  79. };
  80. template<typename IBaseInterface>
  81. struct TEffectInvalidVariable : public IBaseInterface
  82. {
  83. public:
  84. STDMETHOD_(bool, IsValid)() override { return false; }
  85. STDMETHOD_(ID3DX11EffectType*, GetType)() override { return &g_InvalidType; }
  86. STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  87. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
  88. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
  89. STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
  90. STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
  91. STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic) override { UNREFERENCED_PARAMETER(Semantic); return &g_InvalidScalarVariable; }
  92. STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
  93. STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override { return &g_InvalidConstantBuffer; }
  94. STDMETHOD_(ID3DX11EffectScalarVariable*, AsScalar)() override { return &g_InvalidScalarVariable; }
  95. STDMETHOD_(ID3DX11EffectVectorVariable*, AsVector)() override { return &g_InvalidVectorVariable; }
  96. STDMETHOD_(ID3DX11EffectMatrixVariable*, AsMatrix)() override { return &g_InvalidMatrixVariable; }
  97. STDMETHOD_(ID3DX11EffectStringVariable*, AsString)() override { return &g_InvalidStringVariable; }
  98. STDMETHOD_(ID3DX11EffectClassInstanceVariable*, AsClassInstance)() override { return &g_InvalidClassInstanceVariable; }
  99. STDMETHOD_(ID3DX11EffectInterfaceVariable*, AsInterface)() override { return &g_InvalidInterfaceVariable; }
  100. STDMETHOD_(ID3DX11EffectShaderResourceVariable*, AsShaderResource)() override { return &g_InvalidShaderResourceVariable; }
  101. STDMETHOD_(ID3DX11EffectUnorderedAccessViewVariable*, AsUnorderedAccessView)() override { return &g_InvalidUnorderedAccessViewVariable; }
  102. STDMETHOD_(ID3DX11EffectRenderTargetViewVariable*, AsRenderTargetView)() override { return &g_InvalidRenderTargetViewVariable; }
  103. STDMETHOD_(ID3DX11EffectDepthStencilViewVariable*, AsDepthStencilView)() override { return &g_InvalidDepthStencilViewVariable; }
  104. STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)() override { return &g_InvalidConstantBuffer; }
  105. STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)() override { return &g_InvalidShaderVariable; }
  106. STDMETHOD_(ID3DX11EffectBlendVariable*, AsBlend)() override { return &g_InvalidBlendVariable; }
  107. STDMETHOD_(ID3DX11EffectDepthStencilVariable*, AsDepthStencil)() override { return &g_InvalidDepthStencilVariable; }
  108. STDMETHOD_(ID3DX11EffectRasterizerVariable*, AsRasterizer)() override { return &g_InvalidRasterizerVariable; }
  109. STDMETHOD_(ID3DX11EffectSamplerVariable*, AsSampler)() override { return &g_InvalidSamplerVariable; }
  110. STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  111. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  112. STDMETHOD(GetRawValue)(_Out_writes_bytes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  113. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  114. };
  115. struct SEffectInvalidScalarVariable : public TEffectInvalidVariable<ID3DX11EffectScalarVariable>
  116. {
  117. public:
  118. STDMETHOD(SetFloat)(_In_ const float Value) override { UNREFERENCED_PARAMETER(Value); return E_FAIL; }
  119. STDMETHOD(GetFloat)(_Out_ float *pValue) override { UNREFERENCED_PARAMETER(pValue); return E_FAIL; }
  120. STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  121. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  122. STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  123. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  124. STDMETHOD(SetInt)(_In_ const int Value) override { UNREFERENCED_PARAMETER(Value); return E_FAIL; }
  125. STDMETHOD(GetInt)(_Out_ int *pValue) override { UNREFERENCED_PARAMETER(pValue); return E_FAIL; }
  126. STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  127. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  128. STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  129. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  130. STDMETHOD(SetBool)(_In_ const bool Value) override { UNREFERENCED_PARAMETER(Value); return E_FAIL; }
  131. STDMETHOD(GetBool)(_Out_ bool *pValue) override { UNREFERENCED_PARAMETER(pValue); return E_FAIL; }
  132. STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  133. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  134. STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  135. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  136. IUNKNOWN_IMP(SEffectInvalidScalarVariable, ID3DX11EffectScalarVariable, ID3DX11EffectVariable);
  137. };
  138. struct SEffectInvalidVectorVariable : public TEffectInvalidVariable<ID3DX11EffectVectorVariable>
  139. {
  140. public:
  141. STDMETHOD(SetFloatVector)(_In_reads_(4) const float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
  142. STDMETHOD(SetIntVector)(_In_reads_(4) const int *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
  143. STDMETHOD(SetBoolVector)(_In_reads_(4) const bool *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
  144. STDMETHOD(GetFloatVector)(_Out_writes_(4) float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
  145. STDMETHOD(GetIntVector)(_Out_writes_(4) int *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
  146. STDMETHOD(GetBoolVector)(_Out_writes_(4) bool *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; };
  147. STDMETHOD(SetBoolVectorArray) (_In_reads_(4*Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  148. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
  149. STDMETHOD(SetIntVectorArray) (_In_reads_(4*Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  150. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
  151. STDMETHOD(SetFloatVectorArray)(_In_reads_(4*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  152. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
  153. STDMETHOD(GetBoolVectorArray) (_Out_writes_(4*Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  154. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
  155. STDMETHOD(GetIntVectorArray) (_Out_writes_(4*Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  156. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
  157. STDMETHOD(GetFloatVectorArray)(_Out_writes_(4*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  158. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; };
  159. IUNKNOWN_IMP(SEffectInvalidVectorVariable, ID3DX11EffectVectorVariable, ID3DX11EffectVariable);
  160. };
  161. struct SEffectInvalidMatrixVariable : public TEffectInvalidVariable<ID3DX11EffectMatrixVariable>
  162. {
  163. public:
  164. STDMETHOD(SetMatrix)(_In_reads_(16) const float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
  165. STDMETHOD(GetMatrix)(_Out_writes_(16) float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
  166. STDMETHOD(SetMatrixArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  167. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  168. STDMETHOD(GetMatrixArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  169. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  170. STDMETHOD(SetMatrixPointerArray)(_In_reads_(16*Count) const float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  171. { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  172. STDMETHOD(GetMatrixPointerArray)(_Out_writes_(16*Count) float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  173. { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  174. STDMETHOD(SetMatrixTranspose)(_In_reads_(16) const float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
  175. STDMETHOD(GetMatrixTranspose)(_Out_writes_(16) float *pData) override { UNREFERENCED_PARAMETER(pData); return E_FAIL; }
  176. STDMETHOD(SetMatrixTransposeArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  177. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  178. STDMETHOD(GetMatrixTransposeArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  179. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  180. STDMETHOD(SetMatrixTransposePointerArray)(_In_reads_(16*Count) const float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  181. { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  182. STDMETHOD(GetMatrixTransposePointerArray)(_Out_writes_(16*Count) float **ppData, _In_ uint32_t Offset, _In_ uint32_t Count) override
  183. { UNREFERENCED_PARAMETER(ppData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  184. IUNKNOWN_IMP(SEffectInvalidMatrixVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable);
  185. };
  186. struct SEffectInvalidStringVariable : public TEffectInvalidVariable<ID3DX11EffectStringVariable>
  187. {
  188. public:
  189. STDMETHOD(GetString)(_Outptr_result_z_ LPCSTR *ppString) override { UNREFERENCED_PARAMETER(ppString); return E_FAIL; }
  190. STDMETHOD(GetStringArray)(_Out_writes_(Count) LPCSTR *ppStrings, _In_ uint32_t Offset, _In_ uint32_t Count) override
  191. { UNREFERENCED_PARAMETER(ppStrings); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  192. IUNKNOWN_IMP(SEffectInvalidStringVariable, ID3DX11EffectStringVariable, ID3DX11EffectVariable);
  193. };
  194. struct SEffectInvalidClassInstanceVariable : public TEffectInvalidVariable<ID3DX11EffectClassInstanceVariable>
  195. {
  196. public:
  197. STDMETHOD(GetClassInstance)(_Outptr_ ID3D11ClassInstance **ppClassInstance) override { UNREFERENCED_PARAMETER(ppClassInstance); return E_FAIL; }
  198. IUNKNOWN_IMP(SEffectInvalidClassInstanceVariable, ID3DX11EffectClassInstanceVariable, ID3DX11EffectVariable);
  199. };
  200. struct SEffectInvalidInterfaceVariable : public TEffectInvalidVariable<ID3DX11EffectInterfaceVariable>
  201. {
  202. public:
  203. STDMETHOD(SetClassInstance)(_In_ ID3DX11EffectClassInstanceVariable *pEffectClassInstance) override
  204. { UNREFERENCED_PARAMETER(pEffectClassInstance); return E_FAIL; }
  205. STDMETHOD(GetClassInstance)(_Outptr_ ID3DX11EffectClassInstanceVariable **ppEffectClassInstance) override
  206. { UNREFERENCED_PARAMETER(ppEffectClassInstance); return E_FAIL; }
  207. IUNKNOWN_IMP(SEffectInvalidInterfaceVariable, ID3DX11EffectInterfaceVariable, ID3DX11EffectVariable);
  208. };
  209. struct SEffectInvalidShaderResourceVariable : public TEffectInvalidVariable<ID3DX11EffectShaderResourceVariable>
  210. {
  211. public:
  212. STDMETHOD(SetResource)(_In_ ID3D11ShaderResourceView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
  213. STDMETHOD(GetResource)(_Outptr_ ID3D11ShaderResourceView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
  214. STDMETHOD(SetResourceArray)(_In_reads_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  215. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  216. STDMETHOD(GetResourceArray)(_Out_writes_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  217. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  218. IUNKNOWN_IMP(SEffectInvalidShaderResourceVariable, ID3DX11EffectShaderResourceVariable, ID3DX11EffectVariable);
  219. };
  220. struct SEffectInvalidUnorderedAccessViewVariable : public TEffectInvalidVariable<ID3DX11EffectUnorderedAccessViewVariable>
  221. {
  222. public:
  223. STDMETHOD(SetUnorderedAccessView)(_In_ ID3D11UnorderedAccessView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
  224. STDMETHOD(GetUnorderedAccessView)(_Outptr_ ID3D11UnorderedAccessView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
  225. STDMETHOD(SetUnorderedAccessViewArray)(_In_reads_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  226. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  227. STDMETHOD(GetUnorderedAccessViewArray)(_Out_writes_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  228. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  229. IUNKNOWN_IMP(SEffectInvalidUnorderedAccessViewVariable, ID3DX11EffectUnorderedAccessViewVariable, ID3DX11EffectVariable);
  230. };
  231. struct SEffectInvalidRenderTargetViewVariable : public TEffectInvalidVariable<ID3DX11EffectRenderTargetViewVariable>
  232. {
  233. public:
  234. STDMETHOD(SetRenderTarget)(_In_ ID3D11RenderTargetView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
  235. STDMETHOD(GetRenderTarget)(_Outptr_ ID3D11RenderTargetView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
  236. STDMETHOD(SetRenderTargetArray)(_In_reads_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  237. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  238. STDMETHOD(GetRenderTargetArray)(_Out_writes_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  239. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  240. IUNKNOWN_IMP(SEffectInvalidRenderTargetViewVariable, ID3DX11EffectRenderTargetViewVariable, ID3DX11EffectVariable);
  241. };
  242. struct SEffectInvalidDepthStencilViewVariable : public TEffectInvalidVariable<ID3DX11EffectDepthStencilViewVariable>
  243. {
  244. public:
  245. STDMETHOD(SetDepthStencil)(_In_ ID3D11DepthStencilView *pResource) override { UNREFERENCED_PARAMETER(pResource); return E_FAIL; }
  246. STDMETHOD(GetDepthStencil)(_Outptr_ ID3D11DepthStencilView **ppResource) override { UNREFERENCED_PARAMETER(ppResource); return E_FAIL; }
  247. STDMETHOD(SetDepthStencilArray)(_In_reads_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  248. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  249. STDMETHOD(GetDepthStencilArray)(_Out_writes_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override
  250. { UNREFERENCED_PARAMETER(ppResources); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return E_FAIL; }
  251. IUNKNOWN_IMP(SEffectInvalidDepthStencilViewVariable, ID3DX11EffectDepthStencilViewVariable, ID3DX11EffectVariable);
  252. };
  253. struct SEffectInvalidConstantBuffer : public TEffectInvalidVariable<ID3DX11EffectConstantBuffer>
  254. {
  255. public:
  256. STDMETHOD(SetConstantBuffer)(_In_ ID3D11Buffer *pConstantBuffer) override { UNREFERENCED_PARAMETER(pConstantBuffer); return E_FAIL; }
  257. STDMETHOD(GetConstantBuffer)(_Outptr_ ID3D11Buffer **ppConstantBuffer) override { UNREFERENCED_PARAMETER(ppConstantBuffer); return E_FAIL; }
  258. STDMETHOD(UndoSetConstantBuffer)() override { return E_FAIL; }
  259. STDMETHOD(SetTextureBuffer)(_In_ ID3D11ShaderResourceView *pTextureBuffer) override { UNREFERENCED_PARAMETER(pTextureBuffer); return E_FAIL; }
  260. STDMETHOD(GetTextureBuffer)(_Outptr_ ID3D11ShaderResourceView **ppTextureBuffer) override { UNREFERENCED_PARAMETER(ppTextureBuffer); return E_FAIL; }
  261. STDMETHOD(UndoSetTextureBuffer)() override { return E_FAIL; }
  262. IUNKNOWN_IMP(SEffectInvalidConstantBuffer, ID3DX11EffectConstantBuffer, ID3DX11EffectVariable);
  263. };
  264. struct SEffectInvalidShaderVariable : public TEffectInvalidVariable<ID3DX11EffectShaderVariable>
  265. {
  266. public:
  267. STDMETHOD(GetShaderDesc)(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc) override
  268. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  269. STDMETHOD(GetVertexShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11VertexShader **ppVS) override
  270. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppVS); return E_FAIL; }
  271. STDMETHOD(GetGeometryShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11GeometryShader **ppGS) override
  272. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppGS); return E_FAIL; }
  273. STDMETHOD(GetPixelShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11PixelShader **ppPS) override
  274. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppPS); return E_FAIL; }
  275. STDMETHOD(GetHullShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11HullShader **ppHS) override
  276. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppHS); return E_FAIL; }
  277. STDMETHOD(GetDomainShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11DomainShader **ppDS) override
  278. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppDS); return E_FAIL; }
  279. STDMETHOD(GetComputeShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11ComputeShader **ppCS) override
  280. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(ppCS); return E_FAIL; }
  281. STDMETHOD(GetInputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override
  282. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(Element); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  283. STDMETHOD(GetOutputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override
  284. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(Element); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  285. STDMETHOD(GetPatchConstantSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override
  286. { UNREFERENCED_PARAMETER(ShaderIndex); UNREFERENCED_PARAMETER(Element); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  287. IUNKNOWN_IMP(SEffectInvalidShaderVariable, ID3DX11EffectShaderVariable, ID3DX11EffectVariable);
  288. };
  289. struct SEffectInvalidBlendVariable : public TEffectInvalidVariable<ID3DX11EffectBlendVariable>
  290. {
  291. public:
  292. STDMETHOD(GetBlendState)(_In_ uint32_t Index, _Outptr_ ID3D11BlendState **ppState) override
  293. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppState); return E_FAIL; }
  294. STDMETHOD(SetBlendState)(_In_ uint32_t Index, _In_ ID3D11BlendState *pState) override
  295. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pState); return E_FAIL; }
  296. STDMETHOD(UndoSetBlendState)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
  297. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_BLEND_DESC *pDesc) override
  298. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  299. IUNKNOWN_IMP(SEffectInvalidBlendVariable, ID3DX11EffectBlendVariable, ID3DX11EffectVariable);
  300. };
  301. struct SEffectInvalidDepthStencilVariable : public TEffectInvalidVariable<ID3DX11EffectDepthStencilVariable>
  302. {
  303. public:
  304. STDMETHOD(GetDepthStencilState)(_In_ uint32_t Index, _Outptr_ ID3D11DepthStencilState **ppState) override
  305. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppState); return E_FAIL; }
  306. STDMETHOD(SetDepthStencilState)(_In_ uint32_t Index, _In_ ID3D11DepthStencilState *pState) override
  307. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pState); return E_FAIL; }
  308. STDMETHOD(UndoSetDepthStencilState)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
  309. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_DEPTH_STENCIL_DESC *pDesc) override
  310. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  311. IUNKNOWN_IMP(SEffectInvalidDepthStencilVariable, ID3DX11EffectDepthStencilVariable, ID3DX11EffectVariable);
  312. };
  313. struct SEffectInvalidRasterizerVariable : public TEffectInvalidVariable<ID3DX11EffectRasterizerVariable>
  314. {
  315. public:
  316. STDMETHOD(GetRasterizerState)(_In_ uint32_t Index, _Outptr_ ID3D11RasterizerState **ppState) override
  317. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppState); return E_FAIL; }
  318. STDMETHOD(SetRasterizerState)(_In_ uint32_t Index, _In_ ID3D11RasterizerState *pState) override
  319. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pState); return E_FAIL; }
  320. STDMETHOD(UndoSetRasterizerState)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
  321. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_RASTERIZER_DESC *pDesc) override
  322. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  323. IUNKNOWN_IMP(SEffectInvalidRasterizerVariable, ID3DX11EffectRasterizerVariable, ID3DX11EffectVariable);
  324. };
  325. struct SEffectInvalidSamplerVariable : public TEffectInvalidVariable<ID3DX11EffectSamplerVariable>
  326. {
  327. public:
  328. STDMETHOD(GetSampler)(_In_ uint32_t Index, _Outptr_ ID3D11SamplerState **ppSampler) override
  329. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(ppSampler); return E_FAIL; }
  330. STDMETHOD(SetSampler)(_In_ uint32_t Index, _In_ ID3D11SamplerState *pSampler) override
  331. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pSampler); return E_FAIL; }
  332. STDMETHOD(UndoSetSampler)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return E_FAIL; }
  333. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_SAMPLER_DESC *pDesc) override
  334. { UNREFERENCED_PARAMETER(Index); UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  335. IUNKNOWN_IMP(SEffectInvalidSamplerVariable, ID3DX11EffectSamplerVariable, ID3DX11EffectVariable);
  336. };
  337. struct SEffectInvalidPass : public ID3DX11EffectPass
  338. {
  339. public:
  340. STDMETHOD_(bool, IsValid)() override { return false; }
  341. STDMETHOD(GetDesc)(_Out_ D3DX11_PASS_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  342. STDMETHOD(GetVertexShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  343. STDMETHOD(GetGeometryShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  344. STDMETHOD(GetPixelShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  345. STDMETHOD(GetHullShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  346. STDMETHOD(GetDomainShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  347. STDMETHOD(GetComputeShaderDesc)(_Out_ D3DX11_PASS_SHADER_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  348. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
  349. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
  350. STDMETHOD(Apply)(_In_ uint32_t Flags, _In_ ID3D11DeviceContext* pContext) override
  351. { UNREFERENCED_PARAMETER(Flags); UNREFERENCED_PARAMETER(pContext); return E_FAIL; }
  352. STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override { UNREFERENCED_PARAMETER(pStateBlockMask); return E_FAIL; }
  353. IUNKNOWN_IMP(SEffectInvalidPass, ID3DX11EffectPass, IUnknown);
  354. };
  355. struct SEffectInvalidTechnique : public ID3DX11EffectTechnique
  356. {
  357. public:
  358. STDMETHOD_(bool, IsValid)() override { return false; }
  359. STDMETHOD(GetDesc)(_Out_ D3DX11_TECHNIQUE_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  360. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
  361. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
  362. STDMETHOD_(ID3DX11EffectPass*, GetPassByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidPass; }
  363. STDMETHOD_(ID3DX11EffectPass*, GetPassByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidPass; }
  364. STDMETHOD(ComputeStateBlockMask)(_Inout_ D3DX11_STATE_BLOCK_MASK *pStateBlockMask) override { UNREFERENCED_PARAMETER(pStateBlockMask); return E_FAIL; }
  365. IUNKNOWN_IMP(SEffectInvalidTechnique, ID3DX11EffectTechnique, IUnknown);
  366. };
  367. struct SEffectInvalidGroup : public ID3DX11EffectGroup
  368. {
  369. public:
  370. STDMETHOD_(bool, IsValid)() override { return false; }
  371. STDMETHOD(GetDesc)(_Out_ D3DX11_GROUP_DESC *pDesc) override { UNREFERENCED_PARAMETER(pDesc); return E_FAIL; }
  372. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidScalarVariable; }
  373. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidScalarVariable; }
  374. STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByIndex)(_In_ uint32_t Index) override { UNREFERENCED_PARAMETER(Index); return &g_InvalidTechnique; }
  375. STDMETHOD_(ID3DX11EffectTechnique*, GetTechniqueByName)(_In_z_ LPCSTR Name) override { UNREFERENCED_PARAMETER(Name); return &g_InvalidTechnique; }
  376. IUNKNOWN_IMP(SEffectInvalidGroup, ID3DX11EffectGroup, IUnknown);
  377. };
  378. //////////////////////////////////////////////////////////////////////////
  379. // Helper routines
  380. //////////////////////////////////////////////////////////////////////////
  381. // This is an annoying warning that pops up in retail builds because
  382. // the code that jumps to "lExit" is conditionally not compiled.
  383. // The only alternative is more #ifdefs in every function
  384. #pragma warning( disable : 4102 ) // 'label' : unreferenced label
  385. #define VERIFYPARAMETER(x) \
  386. { if (!(x)) { DPF(0, "%s: Parameter " #x " was nullptr.", pFuncName); \
  387. __BREAK_ON_FAIL; hr = E_INVALIDARG; goto lExit; } }
  388. static HRESULT AnnotationInvalidSetCall(LPCSTR pFuncName)
  389. {
  390. DPF(0, "%s: Annotations are readonly", pFuncName);
  391. return D3DERR_INVALIDCALL;
  392. }
  393. static HRESULT ObjectSetRawValue()
  394. {
  395. DPF(0, "ID3DX11EffectVariable::SetRawValue: Objects do not support ths call; please use the specific object accessors instead.");
  396. return D3DERR_INVALIDCALL;
  397. }
  398. static HRESULT ObjectGetRawValue()
  399. {
  400. DPF(0, "ID3DX11EffectVariable::GetRawValue: Objects do not support ths call; please use the specific object accessors instead.");
  401. return D3DERR_INVALIDCALL;
  402. }
  403. ID3DX11EffectConstantBuffer * NoParentCB();
  404. ID3DX11EffectVariable * GetAnnotationByIndexHelper(_In_z_ const char *pClassName, _In_ uint32_t Index,
  405. _In_ uint32_t AnnotationCount, _In_reads_(AnnotationCount) SAnnotation *pAnnotations);
  406. ID3DX11EffectVariable * GetAnnotationByNameHelper(_In_z_ const char *pClassName, _In_z_ LPCSTR Name,
  407. _In_ uint32_t AnnotationCount, _In_reads_(AnnotationCount) SAnnotation *pAnnotations);
  408. template<typename SVarType>
  409. _Success_(return)
  410. bool GetVariableByIndexHelper(_In_ uint32_t Index, _In_ uint32_t VariableCount, _In_reads_(VariableCount) SVarType *pVariables,
  411. _In_opt_ uint8_t *pBaseAddress, _Outptr_ SVarType **ppMember, _Outptr_ void **ppDataPtr)
  412. {
  413. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetMemberByIndex";
  414. if (Index >= VariableCount)
  415. {
  416. DPF(0, "%s: Invalid index (%u, total: %u)", pFuncName, Index, VariableCount);
  417. return false;
  418. }
  419. *ppMember = pVariables + Index;
  420. *ppDataPtr = pBaseAddress + (*ppMember)->Data.Offset;
  421. return true;
  422. }
  423. template<typename SVarType>
  424. _Success_(return)
  425. bool GetVariableByNameHelper(_In_z_ LPCSTR Name, _In_ uint32_t VariableCount, _In_reads_(VariableCount) SVarType *pVariables,
  426. _In_opt_ uint8_t *pBaseAddress, _Outptr_ SVarType **ppMember, _Outptr_ void **ppDataPtr, _Out_ uint32_t* pIndex)
  427. {
  428. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetMemberByName";
  429. if (nullptr == Name)
  430. {
  431. DPF(0, "%s: Parameter Name was nullptr.", pFuncName);
  432. return false;
  433. }
  434. bool bHasSuper = false;
  435. for (uint32_t i = 0; i < VariableCount; ++ i)
  436. {
  437. *ppMember = pVariables + i;
  438. assert((*ppMember)->pName != 0);
  439. _Analysis_assume_((*ppMember)->pName != 0);
  440. if (strcmp((*ppMember)->pName, Name) == 0)
  441. {
  442. *ppDataPtr = pBaseAddress + (*ppMember)->Data.Offset;
  443. *pIndex = i;
  444. return true;
  445. }
  446. else if (i == 0 &&
  447. (*ppMember)->pName[0] == '$' &&
  448. strcmp((*ppMember)->pName, "$super") == 0)
  449. {
  450. bHasSuper = true;
  451. }
  452. }
  453. if (bHasSuper)
  454. {
  455. SVarType* pSuper = pVariables;
  456. return GetVariableByNameHelper<SVarType>(Name,
  457. pSuper->pType->StructType.Members,
  458. (SVarType*)pSuper->pType->StructType.pMembers,
  459. pBaseAddress + pSuper->Data.Offset,
  460. ppMember,
  461. ppDataPtr,
  462. pIndex);
  463. }
  464. DPF(0, "%s: Variable [%s] not found", pFuncName, Name);
  465. return false;
  466. }
  467. template<typename SVarType>
  468. _Success_(return)
  469. bool GetVariableBySemanticHelper(_In_z_ LPCSTR Semantic, _In_ uint32_t VariableCount, _In_reads_(VariableCount) SVarType *pVariables,
  470. _In_opt_ uint8_t *pBaseAddress, _Outptr_ SVarType **ppMember, _Outptr_ void **ppDataPtr, _Out_ uint32_t* pIndex)
  471. {
  472. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetMemberBySemantic";
  473. if (nullptr == Semantic)
  474. {
  475. DPF(0, "%s: Parameter Semantic was nullptr.", pFuncName);
  476. return false;
  477. }
  478. for (uint32_t i = 0; i < VariableCount; ++ i)
  479. {
  480. *ppMember = pVariables + i;
  481. if (nullptr != (*ppMember)->pSemantic &&
  482. _stricmp((*ppMember)->pSemantic, Semantic) == 0)
  483. {
  484. *ppDataPtr = pBaseAddress + (*ppMember)->Data.Offset;
  485. *pIndex = i;
  486. return true;
  487. }
  488. }
  489. DPF(0, "%s: Variable with semantic [%s] not found", pFuncName, Semantic);
  490. return false;
  491. }
  492. inline bool AreBoundsValid(_In_ uint32_t Offset, _In_ uint32_t Count, _In_ const void *pData, _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize)
  493. {
  494. if (Count == 0) return true;
  495. uint32_t singleElementSize = pType->GetTotalUnpackedSize(true);
  496. assert(singleElementSize <= pType->Stride);
  497. return ((Offset + Count >= Offset) &&
  498. ((Offset + Count) < ((uint32_t)-1) / pType->Stride) &&
  499. (Count * pType->Stride + (uint8_t*)pData >= (uint8_t*)pData) &&
  500. ((Offset + Count - 1) * pType->Stride + singleElementSize <= TotalUnpackedSize));
  501. }
  502. // Note that the branches in this code is based on template parameters and will be compiled out
  503. template<ETemplateVarType SourceType, ETemplateVarType DestType, typename SRC_TYPE, bool ValidatePtr>
  504. __forceinline HRESULT CopyScalarValue(_In_ SRC_TYPE SrcValue, _Out_ void *pDest, _In_z_ const char *pFuncName)
  505. {
  506. HRESULT hr = S_OK;
  507. #ifdef _DEBUG
  508. if (ValidatePtr)
  509. VERIFYPARAMETER(pDest);
  510. #else
  511. UNREFERENCED_PARAMETER(pFuncName);
  512. #endif
  513. switch (SourceType)
  514. {
  515. case ETVT_Bool:
  516. switch (DestType)
  517. {
  518. case ETVT_Bool:
  519. *(int*)pDest = (SrcValue != 0) ? -1 : 0;
  520. break;
  521. case ETVT_Int:
  522. *(int*)pDest = SrcValue ? 1 : 0;
  523. break;
  524. case ETVT_Float:
  525. *(float*)pDest = SrcValue ? 1.0f : 0.0f;
  526. break;
  527. case ETVT_bool:
  528. *(bool*)pDest = (SrcValue != 0) ? true : false;
  529. break;
  530. default:
  531. assert(0);
  532. }
  533. break;
  534. case ETVT_Int:
  535. switch (DestType)
  536. {
  537. case ETVT_Bool:
  538. *(int*)pDest = (SrcValue != 0) ? -1 : 0;
  539. break;
  540. case ETVT_Int:
  541. *(int*)pDest = (int) SrcValue;
  542. break;
  543. case ETVT_Float:
  544. *(float*)pDest = (float)(SrcValue);
  545. break;
  546. case ETVT_bool:
  547. *(bool*)pDest = (SrcValue != 0) ? true : false;
  548. break;
  549. default:
  550. assert(0);
  551. }
  552. break;
  553. case ETVT_Float:
  554. switch (DestType)
  555. {
  556. case ETVT_Bool:
  557. *(int*)pDest = (SrcValue != 0.0f) ? -1 : 0;
  558. break;
  559. case ETVT_Int:
  560. *(int*)pDest = (int) (SrcValue);
  561. break;
  562. case ETVT_Float:
  563. *(float*)pDest = (float) SrcValue;
  564. break;
  565. case ETVT_bool:
  566. *(bool*)pDest = (SrcValue != 0.0f) ? true : false;
  567. break;
  568. default:
  569. assert(0);
  570. }
  571. break;
  572. case ETVT_bool:
  573. switch (DestType)
  574. {
  575. case ETVT_Bool:
  576. *(int*)pDest = SrcValue ? -1 : 0;
  577. break;
  578. case ETVT_Int:
  579. *(int*)pDest = SrcValue ? 1 : 0;
  580. break;
  581. case ETVT_Float:
  582. *(float*)pDest = SrcValue ? 1.0f : 0.0f;
  583. break;
  584. case ETVT_bool:
  585. *(bool*)pDest = (SrcValue != 0) ? true : false;
  586. break;
  587. default:
  588. assert(0);
  589. }
  590. break;
  591. default:
  592. assert(0);
  593. }
  594. lExit:
  595. return hr;
  596. }
  597. #pragma warning(push)
  598. #pragma warning( disable : 6103 )
  599. template<ETemplateVarType SourceType, ETemplateVarType DestType, typename SRC_TYPE, typename DEST_TYPE>
  600. inline HRESULT SetScalarArray(_In_reads_(Count) const SRC_TYPE *pSrcValues, _Out_writes_(Count) DEST_TYPE *pDestValues,
  601. _In_ uint32_t Offset, _In_ uint32_t Count,
  602. _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize, _In_z_ const char *pFuncName)
  603. {
  604. HRESULT hr = S_OK;
  605. #ifdef _DEBUG
  606. VERIFYPARAMETER(pSrcValues);
  607. #pragma warning( suppress : 6001 )
  608. if (!AreBoundsValid(Offset, Count, pSrcValues, pType, TotalUnpackedSize))
  609. {
  610. DPF(0, "%s: Invalid range specified", pFuncName);
  611. VH(E_INVALIDARG);
  612. }
  613. #else
  614. UNREFERENCED_PARAMETER(TotalUnpackedSize);
  615. UNREFERENCED_PARAMETER(pFuncName);
  616. #endif
  617. uint32_t i, j, delta = pType->NumericType.IsPackedArray ? 1 : SType::c_ScalarsPerRegister;
  618. pDestValues += Offset * delta;
  619. for (i = 0, j = 0; j < Count; i += delta, ++ j)
  620. {
  621. // pDestValues[i] = (DEST_TYPE)pSrcValues[j];
  622. CopyScalarValue<SourceType, DestType, SRC_TYPE, false>(pSrcValues[j], &pDestValues[i], "SetScalarArray");
  623. }
  624. lExit:
  625. return hr;
  626. }
  627. #pragma warning(pop)
  628. #pragma warning( disable : 6103 )
  629. template<ETemplateVarType SourceType, ETemplateVarType DestType, typename SRC_TYPE, typename DEST_TYPE>
  630. inline HRESULT GetScalarArray(_In_reads_(Count) SRC_TYPE *pSrcValues, _Out_writes_(Count) DEST_TYPE *pDestValues,
  631. _In_ uint32_t Offset, _In_ uint32_t Count,
  632. _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize, _In_z_ const char *pFuncName)
  633. {
  634. HRESULT hr = S_OK;
  635. #ifdef _DEBUG
  636. VERIFYPARAMETER(pDestValues);
  637. #pragma warning( suppress : 6001 )
  638. if (!AreBoundsValid(Offset, Count, pDestValues, pType, TotalUnpackedSize))
  639. {
  640. DPF(0, "%s: Invalid range specified", pFuncName);
  641. VH(E_INVALIDARG);
  642. }
  643. #else
  644. UNREFERENCED_PARAMETER(TotalUnpackedSize);
  645. UNREFERENCED_PARAMETER(pFuncName);
  646. #endif
  647. uint32_t i, j, delta = pType->NumericType.IsPackedArray ? 1 : SType::c_ScalarsPerRegister;
  648. pSrcValues += Offset * delta;
  649. for (i = 0, j = 0; j < Count; i += delta, ++ j)
  650. {
  651. // pDestValues[j] = (DEST_TYPE)pSrcValues[i];
  652. CopyScalarValue<SourceType, DestType, SRC_TYPE, false>(pSrcValues[i], &pDestValues[j], "GetScalarArray");
  653. }
  654. lExit:
  655. return hr;
  656. }
  657. //////////////////////////////////////////////////////////////////////////
  658. // TVariable - implements type casting and member/element retrieval
  659. //////////////////////////////////////////////////////////////////////////
  660. // requires that IBaseInterface contain SVariable's fields and support ID3DX11EffectVariable
  661. template<typename IBaseInterface>
  662. struct TVariable : public IBaseInterface
  663. {
  664. STDMETHOD_(bool, IsValid)() override { return true; }
  665. STDMETHOD_(ID3DX11EffectVariable*, GetMemberByIndex)(_In_ uint32_t Index)
  666. {
  667. SVariable *pMember;
  668. UDataPointer dataPtr;
  669. TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
  670. if (((ID3DX11Effect*)pTopLevelEntity2->pEffect)->IsOptimized())
  671. {
  672. DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Cannot get members; effect has been Optimize()'ed");
  673. return &g_InvalidScalarVariable;
  674. }
  675. if (pType->VarType != EVT_Struct)
  676. {
  677. DPF(0, "ID3DX11EffectVariable::GetMemberByIndex: Variable is not a structure");
  678. return &g_InvalidScalarVariable;
  679. }
  680. if (!GetVariableByIndexHelper<SVariable>(Index, pType->StructType.Members, pType->StructType.pMembers,
  681. Data.pNumeric, &pMember, &dataPtr.pGeneric))
  682. {
  683. return &g_InvalidScalarVariable;
  684. }
  685. return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, pMember, dataPtr, false, Index);
  686. }
  687. STDMETHOD_(ID3DX11EffectVariable*, GetMemberByName)(_In_z_ LPCSTR Name)
  688. {
  689. SVariable *pMember;
  690. UDataPointer dataPtr;
  691. uint32_t index;
  692. TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
  693. if (pTopLevelEntity2->pEffect->IsOptimized())
  694. {
  695. DPF(0, "ID3DX11EffectVariable::GetMemberByName: Cannot get members; effect has been Optimize()'ed");
  696. return &g_InvalidScalarVariable;
  697. }
  698. if (pType->VarType != EVT_Struct)
  699. {
  700. DPF(0, "ID3DX11EffectVariable::GetMemberByName: Variable is not a structure");
  701. return &g_InvalidScalarVariable;
  702. }
  703. if (!GetVariableByNameHelper<SVariable>(Name, pType->StructType.Members, pType->StructType.pMembers,
  704. Data.pNumeric, &pMember, &dataPtr.pGeneric, &index))
  705. {
  706. return &g_InvalidScalarVariable;
  707. }
  708. return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, pMember, dataPtr, false, index);
  709. }
  710. STDMETHOD_(ID3DX11EffectVariable*, GetMemberBySemantic)(_In_z_ LPCSTR Semantic)
  711. {
  712. SVariable *pMember;
  713. UDataPointer dataPtr;
  714. uint32_t index;
  715. TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
  716. if (pTopLevelEntity2->pEffect->IsOptimized())
  717. {
  718. DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Cannot get members; effect has been Optimize()'ed");
  719. return &g_InvalidScalarVariable;
  720. }
  721. if (pType->VarType != EVT_Struct)
  722. {
  723. DPF(0, "ID3DX11EffectVariable::GetMemberBySemantic: Variable is not a structure");
  724. return &g_InvalidScalarVariable;
  725. }
  726. if (!GetVariableBySemanticHelper<SVariable>(Semantic, pType->StructType.Members, pType->StructType.pMembers,
  727. Data.pNumeric, &pMember, &dataPtr.pGeneric, &index))
  728. {
  729. return &g_InvalidScalarVariable;
  730. }
  731. return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, pMember, dataPtr, false, index);
  732. }
  733. STDMETHOD_(ID3DX11EffectVariable*, GetElement)(_In_ uint32_t Index)
  734. {
  735. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetElement";
  736. TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity2 = GetTopLevelEntity();
  737. UDataPointer dataPtr;
  738. if (pTopLevelEntity2->pEffect->IsOptimized())
  739. {
  740. DPF(0, "ID3DX11EffectVariable::GetElement: Cannot get element; effect has been Optimize()'ed");
  741. return &g_InvalidScalarVariable;
  742. }
  743. if (!IsArray())
  744. {
  745. DPF(0, "%s: This interface does not refer to an array", pFuncName);
  746. return &g_InvalidScalarVariable;
  747. }
  748. if (Index >= pType->Elements)
  749. {
  750. DPF(0, "%s: Invalid element index (%u, total: %u)", pFuncName, Index, pType->Elements);
  751. return &g_InvalidScalarVariable;
  752. }
  753. if (pType->BelongsInConstantBuffer())
  754. {
  755. dataPtr.pGeneric = Data.pNumeric + pType->Stride * Index;
  756. }
  757. else
  758. {
  759. dataPtr.pGeneric = GetBlockByIndex(pType->VarType, pType->ObjectType, Data.pGeneric, Index);
  760. if (nullptr == dataPtr.pGeneric)
  761. {
  762. DPF(0, "%s: Internal error", pFuncName);
  763. return &g_InvalidScalarVariable;
  764. }
  765. }
  766. return pTopLevelEntity2->pEffect->CreatePooledVariableMemberInterface(pTopLevelEntity2, (SVariable *) this, dataPtr, true, Index);
  767. }
  768. STDMETHOD_(ID3DX11EffectScalarVariable*, AsScalar)()
  769. {
  770. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsScalar";
  771. if (pType->VarType != EVT_Numeric ||
  772. pType->NumericType.NumericLayout != ENL_Scalar)
  773. {
  774. DPF(0, "%s: Invalid typecast", pFuncName);
  775. return &g_InvalidScalarVariable;
  776. }
  777. return (ID3DX11EffectScalarVariable *) this;
  778. }
  779. STDMETHOD_(ID3DX11EffectVectorVariable*, AsVector)()
  780. {
  781. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsVector";
  782. if (pType->VarType != EVT_Numeric ||
  783. pType->NumericType.NumericLayout != ENL_Vector)
  784. {
  785. DPF(0, "%s: Invalid typecast", pFuncName);
  786. return &g_InvalidVectorVariable;
  787. }
  788. return (ID3DX11EffectVectorVariable *) this;
  789. }
  790. STDMETHOD_(ID3DX11EffectMatrixVariable*, AsMatrix)()
  791. {
  792. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsMatrix";
  793. if (pType->VarType != EVT_Numeric ||
  794. pType->NumericType.NumericLayout != ENL_Matrix)
  795. {
  796. DPF(0, "%s: Invalid typecast", pFuncName);
  797. return &g_InvalidMatrixVariable;
  798. }
  799. return (ID3DX11EffectMatrixVariable *) this;
  800. }
  801. STDMETHOD_(ID3DX11EffectStringVariable*, AsString)()
  802. {
  803. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsString";
  804. if (!pType->IsObjectType(EOT_String))
  805. {
  806. DPF(0, "%s: Invalid typecast", pFuncName);
  807. return &g_InvalidStringVariable;
  808. }
  809. return (ID3DX11EffectStringVariable *) this;
  810. }
  811. STDMETHOD_(ID3DX11EffectClassInstanceVariable*, AsClassInstance)()
  812. {
  813. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsClassInstance";
  814. if (!pType->IsClassInstance() )
  815. {
  816. DPF(0, "%s: Invalid typecast", pFuncName);
  817. return &g_InvalidClassInstanceVariable;
  818. }
  819. else if( pMemberData == nullptr )
  820. {
  821. DPF(0, "%s: Non-global class instance variables (members of structs or classes) and class instances "
  822. "inside tbuffers are not supported.", pFuncName );
  823. return &g_InvalidClassInstanceVariable;
  824. }
  825. return (ID3DX11EffectClassInstanceVariable *) this;
  826. }
  827. STDMETHOD_(ID3DX11EffectInterfaceVariable*, AsInterface)()
  828. {
  829. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsInterface";
  830. if (!pType->IsInterface())
  831. {
  832. DPF(0, "%s: Invalid typecast", pFuncName);
  833. return &g_InvalidInterfaceVariable;
  834. }
  835. return (ID3DX11EffectInterfaceVariable *) this;
  836. }
  837. STDMETHOD_(ID3DX11EffectShaderResourceVariable*, AsShaderResource)()
  838. {
  839. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShaderResource";
  840. if (!pType->IsShaderResource())
  841. {
  842. DPF(0, "%s: Invalid typecast", pFuncName);
  843. return &g_InvalidShaderResourceVariable;
  844. }
  845. return (ID3DX11EffectShaderResourceVariable *) this;
  846. }
  847. STDMETHOD_(ID3DX11EffectUnorderedAccessViewVariable*, AsUnorderedAccessView)()
  848. {
  849. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsUnorderedAccessView";
  850. if (!pType->IsUnorderedAccessView())
  851. {
  852. DPF(0, "%s: Invalid typecast", pFuncName);
  853. return &g_InvalidUnorderedAccessViewVariable;
  854. }
  855. return (ID3DX11EffectUnorderedAccessViewVariable *) this;
  856. }
  857. STDMETHOD_(ID3DX11EffectRenderTargetViewVariable*, AsRenderTargetView)()
  858. {
  859. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRenderTargetView";
  860. if (!pType->IsRenderTargetView())
  861. {
  862. DPF(0, "%s: Invalid typecast", pFuncName);
  863. return &g_InvalidRenderTargetViewVariable;
  864. }
  865. return (ID3DX11EffectRenderTargetViewVariable *) this;
  866. }
  867. STDMETHOD_(ID3DX11EffectDepthStencilViewVariable*, AsDepthStencilView)()
  868. {
  869. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencilView";
  870. if (!pType->IsDepthStencilView())
  871. {
  872. DPF(0, "%s: Invalid typecast", pFuncName);
  873. return &g_InvalidDepthStencilViewVariable;
  874. }
  875. return (ID3DX11EffectDepthStencilViewVariable *) this;
  876. }
  877. STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)()
  878. {
  879. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsConstantBuffer";
  880. DPF(0, "%s: Invalid typecast", pFuncName);
  881. return &g_InvalidConstantBuffer;
  882. }
  883. STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)()
  884. {
  885. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShader";
  886. if (!pType->IsShader())
  887. {
  888. DPF(0, "%s: Invalid typecast", pFuncName);
  889. return &g_InvalidShaderVariable;
  890. }
  891. return (ID3DX11EffectShaderVariable *) this;
  892. }
  893. STDMETHOD_(ID3DX11EffectBlendVariable*, AsBlend)()
  894. {
  895. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsBlend";
  896. if (!pType->IsObjectType(EOT_Blend))
  897. {
  898. DPF(0, "%s: Invalid typecast", pFuncName);
  899. return &g_InvalidBlendVariable;
  900. }
  901. return (ID3DX11EffectBlendVariable *) this;
  902. }
  903. STDMETHOD_(ID3DX11EffectDepthStencilVariable*, AsDepthStencil)()
  904. {
  905. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencil";
  906. if (!pType->IsObjectType(EOT_DepthStencil))
  907. {
  908. DPF(0, "%s: Invalid typecast", pFuncName);
  909. return &g_InvalidDepthStencilVariable;
  910. }
  911. return (ID3DX11EffectDepthStencilVariable *) this;
  912. }
  913. STDMETHOD_(ID3DX11EffectRasterizerVariable*, AsRasterizer)()
  914. {
  915. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRasterizer";
  916. if (!pType->IsObjectType(EOT_Rasterizer))
  917. {
  918. DPF(0, "%s: Invalid typecast", pFuncName);
  919. return &g_InvalidRasterizerVariable;
  920. }
  921. return (ID3DX11EffectRasterizerVariable *) this;
  922. }
  923. STDMETHOD_(ID3DX11EffectSamplerVariable*, AsSampler)()
  924. {
  925. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsSampler";
  926. if (!pType->IsSampler())
  927. {
  928. DPF(0, "%s: Invalid typecast", pFuncName);
  929. return &g_InvalidSamplerVariable;
  930. }
  931. return (ID3DX11EffectSamplerVariable *) this;
  932. }
  933. // Numeric variables should override this
  934. STDMETHOD(SetRawValue)(_In_reads_bytes_(Count) const void *pData, _In_ uint32_t Offset, _In_ uint32_t Count)
  935. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return ObjectSetRawValue(); }
  936. STDMETHOD(GetRawValue)(_Out_writes_(Count) void *pData, _In_ uint32_t Offset, _In_ uint32_t Count)
  937. { UNREFERENCED_PARAMETER(pData); UNREFERENCED_PARAMETER(Offset); UNREFERENCED_PARAMETER(Count); return ObjectGetRawValue(); }
  938. };
  939. //////////////////////////////////////////////////////////////////////////
  940. // TTopLevelVariable - functionality for annotations and global variables
  941. //////////////////////////////////////////////////////////////////////////
  942. template<typename IBaseInterface>
  943. struct TTopLevelVariable : public SVariable, public IBaseInterface
  944. {
  945. // Required to create member/element variable interfaces
  946. CEffect *pEffect;
  947. CEffect* GetEffect()
  948. {
  949. return pEffect;
  950. }
  951. TTopLevelVariable() : pEffect (nullptr)
  952. {
  953. }
  954. uint32_t GetTotalUnpackedSize()
  955. {
  956. return ((SType*)pType)->GetTotalUnpackedSize(false);
  957. }
  958. STDMETHOD_(ID3DX11EffectType*, GetType)()
  959. {
  960. return (ID3DX11EffectType*)(SType*)pType;
  961. }
  962. TTopLevelVariable<ID3DX11EffectVariable> * GetTopLevelEntity()
  963. {
  964. return (TTopLevelVariable<ID3DX11EffectVariable> *)this;
  965. }
  966. bool IsArray()
  967. {
  968. return (pType->Elements > 0);
  969. }
  970. };
  971. //////////////////////////////////////////////////////////////////////////
  972. // TMember - functionality for structure/array members of other variables
  973. //////////////////////////////////////////////////////////////////////////
  974. template<typename IBaseInterface>
  975. struct TMember : public SVariable, public IBaseInterface
  976. {
  977. // Indicates that this is a single element of a containing array
  978. uint32_t IsSingleElement : 1;
  979. // Required to create member/element variable interfaces
  980. TTopLevelVariable<ID3DX11EffectVariable> *pTopLevelEntity;
  981. TMember()
  982. {
  983. IsSingleElement = false;
  984. pTopLevelEntity = nullptr;
  985. }
  986. CEffect* GetEffect()
  987. {
  988. return pTopLevelEntity->pEffect;
  989. }
  990. uint32_t GetTotalUnpackedSize()
  991. {
  992. return pType->GetTotalUnpackedSize(IsSingleElement);
  993. }
  994. STDMETHOD_(ID3DX11EffectType*, GetType)() override
  995. {
  996. if (IsSingleElement)
  997. {
  998. return pTopLevelEntity->pEffect->CreatePooledSingleElementTypeInterface( pType );
  999. }
  1000. else
  1001. {
  1002. return (ID3DX11EffectType*) pType;
  1003. }
  1004. }
  1005. STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override
  1006. {
  1007. HRESULT hr = S_OK;
  1008. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetDesc";
  1009. VERIFYPARAMETER(pDesc != nullptr);
  1010. pDesc->Name = pName;
  1011. pDesc->Semantic = pSemantic;
  1012. pDesc->Flags = 0;
  1013. if (pTopLevelEntity->pEffect->IsReflectionData(pTopLevelEntity))
  1014. {
  1015. // Is part of an annotation
  1016. assert(pTopLevelEntity->pEffect->IsReflectionData(Data.pGeneric));
  1017. pDesc->Annotations = 0;
  1018. pDesc->BufferOffset = 0;
  1019. pDesc->Flags |= D3DX11_EFFECT_VARIABLE_ANNOTATION;
  1020. }
  1021. else
  1022. {
  1023. // Is part of a global variable
  1024. assert(pTopLevelEntity->pEffect->IsRuntimeData(pTopLevelEntity));
  1025. if (!pTopLevelEntity->pType->IsObjectType(EOT_String))
  1026. {
  1027. // strings are funny; their data is reflection data, so ignore those
  1028. assert(pTopLevelEntity->pEffect->IsRuntimeData(Data.pGeneric));
  1029. }
  1030. pDesc->Annotations = ((TGlobalVariable<ID3DX11Effect>*)pTopLevelEntity)->AnnotationCount;
  1031. SConstantBuffer *pCB = ((TGlobalVariable<ID3DX11Effect>*)pTopLevelEntity)->pCB;
  1032. if (pType->BelongsInConstantBuffer())
  1033. {
  1034. assert(pCB != 0);
  1035. _Analysis_assume_(pCB != 0);
  1036. UINT_PTR offset = Data.pNumeric - pCB->pBackingStore;
  1037. assert(offset == (uint32_t)offset);
  1038. pDesc->BufferOffset = (uint32_t)offset;
  1039. assert(pDesc->BufferOffset >= 0 && pDesc->BufferOffset + GetTotalUnpackedSize() <= pCB->Size);
  1040. }
  1041. else
  1042. {
  1043. assert(pCB == nullptr);
  1044. pDesc->BufferOffset = 0;
  1045. }
  1046. }
  1047. lExit:
  1048. return hr;
  1049. }
  1050. TTopLevelVariable<ID3DX11EffectVariable> * GetTopLevelEntity()
  1051. {
  1052. return pTopLevelEntity;
  1053. }
  1054. bool IsArray()
  1055. {
  1056. return (pType->Elements > 0 && !IsSingleElement);
  1057. }
  1058. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override
  1059. { return pTopLevelEntity->GetAnnotationByIndex(Index); }
  1060. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override
  1061. { return pTopLevelEntity->GetAnnotationByName(Name); }
  1062. STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override
  1063. { return pTopLevelEntity->GetParentConstantBuffer(); }
  1064. // Annotations should never be able to go down this codepath
  1065. void DirtyVariable()
  1066. {
  1067. // make sure to call the global variable's version of dirty variable
  1068. ((TGlobalVariable<ID3DX11EffectVariable>*)pTopLevelEntity)->DirtyVariable();
  1069. }
  1070. };
  1071. //////////////////////////////////////////////////////////////////////////
  1072. // TAnnotation - functionality for top level annotations
  1073. //////////////////////////////////////////////////////////////////////////
  1074. template<typename IBaseInterface>
  1075. struct TAnnotation : public TVariable<TTopLevelVariable<IBaseInterface> >
  1076. {
  1077. STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc) override
  1078. {
  1079. HRESULT hr = S_OK;
  1080. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetDesc";
  1081. VERIFYPARAMETER(pDesc != nullptr);
  1082. pDesc->Name = pName;
  1083. pDesc->Semantic = pSemantic;
  1084. pDesc->Flags = D3DX11_EFFECT_VARIABLE_ANNOTATION;
  1085. pDesc->Annotations = 0;
  1086. pDesc->BufferOffset = 0;
  1087. pDesc->ExplicitBindPoint = 0;
  1088. lExit:
  1089. return hr;
  1090. }
  1091. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index) override
  1092. {
  1093. UNREFERENCED_PARAMETER(Index);
  1094. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetAnnotationByIndex";
  1095. DPF(0, "%s: Only variables may have annotations", pFuncName);
  1096. return &g_InvalidScalarVariable;
  1097. }
  1098. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name) override
  1099. {
  1100. UNREFERENCED_PARAMETER(Name);
  1101. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetAnnotationByName";
  1102. DPF(0, "%s: Only variables may have annotations", pFuncName);
  1103. return &g_InvalidScalarVariable;
  1104. }
  1105. STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)() override
  1106. { return NoParentCB(); }
  1107. void DirtyVariable()
  1108. {
  1109. assert(0);
  1110. }
  1111. };
  1112. //////////////////////////////////////////////////////////////////////////
  1113. // TGlobalVariable - functionality for top level global variables
  1114. //////////////////////////////////////////////////////////////////////////
  1115. template<typename IBaseInterface>
  1116. struct TGlobalVariable : public TVariable<TTopLevelVariable<IBaseInterface> >
  1117. {
  1118. Timer LastModifiedTime;
  1119. // if numeric, pointer to the constant buffer where this variable lives
  1120. SConstantBuffer *pCB;
  1121. uint32_t AnnotationCount;
  1122. SAnnotation *pAnnotations;
  1123. TGlobalVariable() :
  1124. LastModifiedTime(0),
  1125. pCB(nullptr),
  1126. AnnotationCount(0),
  1127. pAnnotations(nullptr)
  1128. {
  1129. }
  1130. STDMETHOD(GetDesc)(_Out_ D3DX11_EFFECT_VARIABLE_DESC *pDesc)
  1131. {
  1132. HRESULT hr = S_OK;
  1133. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetDesc";
  1134. VERIFYPARAMETER(pDesc != nullptr);
  1135. pDesc->Name = pName;
  1136. pDesc->Semantic = pSemantic;
  1137. pDesc->Flags = 0;
  1138. pDesc->Annotations = AnnotationCount;
  1139. if (pType->BelongsInConstantBuffer())
  1140. {
  1141. assert(pCB != 0);
  1142. _Analysis_assume_(pCB != 0);
  1143. UINT_PTR offset = Data.pNumeric - pCB->pBackingStore;
  1144. assert(offset == (uint32_t)offset);
  1145. pDesc->BufferOffset = (uint32_t)offset;
  1146. assert(pDesc->BufferOffset >= 0 && pDesc->BufferOffset + GetTotalUnpackedSize() <= pCB->Size );
  1147. }
  1148. else
  1149. {
  1150. assert(pCB == nullptr);
  1151. pDesc->BufferOffset = 0;
  1152. }
  1153. if (ExplicitBindPoint != -1)
  1154. {
  1155. pDesc->ExplicitBindPoint = ExplicitBindPoint;
  1156. pDesc->Flags |= D3DX11_EFFECT_VARIABLE_EXPLICIT_BIND_POINT;
  1157. }
  1158. else
  1159. {
  1160. pDesc->ExplicitBindPoint = 0;
  1161. }
  1162. lExit:
  1163. return hr;
  1164. }
  1165. // these are all well defined for global vars
  1166. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByIndex)(_In_ uint32_t Index)
  1167. {
  1168. return GetAnnotationByIndexHelper("ID3DX11EffectVariable", Index, AnnotationCount, pAnnotations);
  1169. }
  1170. STDMETHOD_(ID3DX11EffectVariable*, GetAnnotationByName)(_In_z_ LPCSTR Name)
  1171. {
  1172. return GetAnnotationByNameHelper("ID3DX11EffectVariable", Name, AnnotationCount, pAnnotations);
  1173. }
  1174. STDMETHOD_(ID3DX11EffectConstantBuffer*, GetParentConstantBuffer)()
  1175. {
  1176. if (nullptr != pCB)
  1177. {
  1178. assert(pType->BelongsInConstantBuffer());
  1179. return (ID3DX11EffectConstantBuffer*)pCB;
  1180. }
  1181. else
  1182. {
  1183. assert(!pType->BelongsInConstantBuffer());
  1184. return &g_InvalidConstantBuffer;
  1185. }
  1186. }
  1187. inline void DirtyVariable()
  1188. {
  1189. assert(pCB != 0);
  1190. _Analysis_assume_(pCB != 0);
  1191. pCB->IsDirty = true;
  1192. LastModifiedTime = pEffect->GetCurrentTime();
  1193. }
  1194. };
  1195. //////////////////////////////////////////////////////////////////////////
  1196. // TNumericVariable - implements raw set/get functionality
  1197. //////////////////////////////////////////////////////////////////////////
  1198. // IMPORTANT NOTE: All of these numeric & object aspect classes MUST NOT
  1199. // add data members to the base variable classes. Otherwise type sizes
  1200. // will disagree between object & numeric variables and we cannot eaily
  1201. // create arrays of global variables using SGlobalVariable
  1202. // Requires that IBaseInterface have SVariable's members, GetTotalUnpackedSize() and DirtyVariable()
  1203. template<typename IBaseInterface, bool IsAnnotation>
  1204. struct TNumericVariable : public IBaseInterface
  1205. {
  1206. STDMETHOD(SetRawValue)(_In_reads_bytes_(ByteCount) const void *pData, _In_ uint32_t ByteOffset, _In_ uint32_t ByteCount) override
  1207. {
  1208. if (IsAnnotation)
  1209. {
  1210. return AnnotationInvalidSetCall("ID3DX11EffectVariable::SetRawValue");
  1211. }
  1212. else
  1213. {
  1214. HRESULT hr = S_OK;
  1215. #ifdef _DEBUG
  1216. static LPCSTR pFuncName = "ID3DX11EffectVariable::SetRawValue";
  1217. VERIFYPARAMETER(pData);
  1218. if ((ByteOffset + ByteCount < ByteOffset) ||
  1219. (ByteCount + (uint8_t*)pData < (uint8_t*)pData) ||
  1220. ((ByteOffset + ByteCount) > GetTotalUnpackedSize()))
  1221. {
  1222. // overflow of some kind
  1223. DPF(0, "%s: Invalid range specified", pFuncName);
  1224. VH(E_INVALIDARG);
  1225. }
  1226. #endif
  1227. DirtyVariable();
  1228. memcpy(Data.pNumeric + ByteOffset, pData, ByteCount);
  1229. lExit:
  1230. return hr;
  1231. }
  1232. }
  1233. STDMETHOD(GetRawValue)(_Out_writes_bytes_(ByteCount) void *pData, _In_ uint32_t ByteOffset, _In_ uint32_t ByteCount) override
  1234. {
  1235. HRESULT hr = S_OK;
  1236. #ifdef _DEBUG
  1237. static LPCSTR pFuncName = "ID3DX11EffectVariable::GetRawValue";
  1238. VERIFYPARAMETER(pData);
  1239. if ((ByteOffset + ByteCount < ByteOffset) ||
  1240. (ByteCount + (uint8_t*)pData < (uint8_t*)pData) ||
  1241. ((ByteOffset + ByteCount) > GetTotalUnpackedSize()))
  1242. {
  1243. // overflow of some kind
  1244. DPF(0, "%s: Invalid range specified", pFuncName);
  1245. VH(E_INVALIDARG);
  1246. }
  1247. #endif
  1248. memcpy(pData, Data.pNumeric + ByteOffset, ByteCount);
  1249. lExit:
  1250. return hr;
  1251. }
  1252. };
  1253. //////////////////////////////////////////////////////////////////////////
  1254. // ID3DX11EffectScalarVariable (TFloatScalarVariable implementation)
  1255. //////////////////////////////////////////////////////////////////////////
  1256. template<typename IBaseInterface, bool IsAnnotation>
  1257. struct TFloatScalarVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
  1258. {
  1259. STDMETHOD(SetFloat)(_In_ const float Value) override;
  1260. STDMETHOD(GetFloat)(_Out_ float *pValue) override;
  1261. STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1262. STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1263. STDMETHOD(SetInt)(_In_ const int Value) override;
  1264. STDMETHOD(GetInt)(_Out_ int *pValue) override;
  1265. STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1266. STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1267. STDMETHOD(SetBool)(_In_ const bool Value) override;
  1268. STDMETHOD(GetBool)(_Out_ bool *pValue) override;
  1269. STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1270. STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1271. };
  1272. template<typename IBaseInterface, bool IsAnnotation>
  1273. _Use_decl_annotations_
  1274. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
  1275. {
  1276. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
  1277. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1278. DirtyVariable();
  1279. return CopyScalarValue<ETVT_Float, ETVT_Float, float, false>(Value, Data.pNumericFloat, pFuncName);
  1280. }
  1281. template<typename IBaseInterface, bool IsAnnotation>
  1282. _Use_decl_annotations_
  1283. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetFloat(float *pValue)
  1284. {
  1285. return CopyScalarValue<ETVT_Float, ETVT_Float, float, true>(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetFloat");
  1286. }
  1287. template<typename IBaseInterface, bool IsAnnotation>
  1288. _Use_decl_annotations_
  1289. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count)
  1290. {
  1291. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray";
  1292. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1293. DirtyVariable();
  1294. return SetScalarArray<ETVT_Float, ETVT_Float, float, float>(pData, Data.pNumericFloat, Offset, Count,
  1295. pType, GetTotalUnpackedSize(), pFuncName);
  1296. }
  1297. template<typename IBaseInterface, bool IsAnnotation>
  1298. _Use_decl_annotations_
  1299. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count)
  1300. {
  1301. return GetScalarArray<ETVT_Float, ETVT_Float, float, float>(Data.pNumericFloat, pData, Offset, Count,
  1302. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray");
  1303. }
  1304. template<typename IBaseInterface, bool IsAnnotation>
  1305. _Use_decl_annotations_
  1306. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetInt(const int Value)
  1307. {
  1308. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt";
  1309. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1310. DirtyVariable();
  1311. return CopyScalarValue<ETVT_Int, ETVT_Float, int, false>(Value, Data.pNumericFloat, pFuncName);
  1312. }
  1313. template<typename IBaseInterface, bool IsAnnotation>
  1314. _Use_decl_annotations_
  1315. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetInt(int *pValue)
  1316. {
  1317. return CopyScalarValue<ETVT_Float, ETVT_Int, float, true>(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetInt");
  1318. }
  1319. template<typename IBaseInterface, bool IsAnnotation>
  1320. _Use_decl_annotations_
  1321. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count)
  1322. {
  1323. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray";
  1324. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1325. DirtyVariable();
  1326. return SetScalarArray<ETVT_Int, ETVT_Float, int, float>(pData, Data.pNumericFloat, Offset, Count,
  1327. pType, GetTotalUnpackedSize(), pFuncName);
  1328. }
  1329. template<typename IBaseInterface, bool IsAnnotation>
  1330. _Use_decl_annotations_
  1331. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetIntArray(int *pData, uint32_t Offset, uint32_t Count)
  1332. {
  1333. return GetScalarArray<ETVT_Float, ETVT_Int, float, int>(Data.pNumericFloat, pData, Offset, Count,
  1334. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray");
  1335. }
  1336. template<typename IBaseInterface, bool IsAnnotation>
  1337. _Use_decl_annotations_
  1338. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetBool(const bool Value)
  1339. {
  1340. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool";
  1341. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1342. DirtyVariable();
  1343. return CopyScalarValue<ETVT_bool, ETVT_Float, bool, false>(Value, Data.pNumericFloat, pFuncName);
  1344. }
  1345. template<typename IBaseInterface, bool IsAnnotation>
  1346. _Use_decl_annotations_
  1347. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetBool(bool *pValue)
  1348. {
  1349. return CopyScalarValue<ETVT_Float, ETVT_bool, float, true>(*Data.pNumericFloat, pValue, "ID3DX11EffectScalarVariable::GetBool");
  1350. }
  1351. template<typename IBaseInterface, bool IsAnnotation>
  1352. _Use_decl_annotations_
  1353. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count)
  1354. {
  1355. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray";
  1356. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1357. DirtyVariable();
  1358. return SetScalarArray<ETVT_bool, ETVT_Float, bool, float>(pData, Data.pNumericFloat, Offset, Count,
  1359. pType, GetTotalUnpackedSize(), pFuncName);
  1360. }
  1361. template<typename IBaseInterface, bool IsAnnotation>
  1362. _Use_decl_annotations_
  1363. HRESULT TFloatScalarVariable<IBaseInterface, IsAnnotation>::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count)
  1364. {
  1365. return GetScalarArray<ETVT_Float, ETVT_bool, float, bool>(Data.pNumericFloat, pData, Offset, Count,
  1366. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray");
  1367. }
  1368. //////////////////////////////////////////////////////////////////////////
  1369. // ID3DX11EffectScalarVariable (TIntScalarVariable implementation)
  1370. //////////////////////////////////////////////////////////////////////////
  1371. template<typename IBaseInterface, bool IsAnnotation>
  1372. struct TIntScalarVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
  1373. {
  1374. STDMETHOD(SetFloat)(_In_ const float Value) override;
  1375. STDMETHOD(GetFloat)(_Out_ float *pValue) override;
  1376. STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1377. STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1378. STDMETHOD(SetInt)(_In_ const int Value) override;
  1379. STDMETHOD(GetInt)(_Out_ int *pValue) override;
  1380. STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1381. STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1382. STDMETHOD(SetBool)(_In_ const bool Value) override;
  1383. STDMETHOD(GetBool)(_Out_ bool *pValue) override;
  1384. STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1385. STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1386. };
  1387. template<typename IBaseInterface, bool IsAnnotation>
  1388. _Use_decl_annotations_
  1389. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
  1390. {
  1391. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
  1392. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1393. DirtyVariable();
  1394. return CopyScalarValue<ETVT_Float, ETVT_Int, float, false>(Value, Data.pNumericInt, pFuncName);
  1395. }
  1396. template<typename IBaseInterface, bool IsAnnotation>
  1397. _Use_decl_annotations_
  1398. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetFloat(float *pValue)
  1399. {
  1400. return CopyScalarValue<ETVT_Int, ETVT_Float, int, true>(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetFloat");
  1401. }
  1402. template<typename IBaseInterface, bool IsAnnotation>
  1403. _Use_decl_annotations_
  1404. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count)
  1405. {
  1406. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray";
  1407. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1408. DirtyVariable();
  1409. return SetScalarArray<ETVT_Float, ETVT_Int, float, int>(pData, Data.pNumericInt, Offset, Count,
  1410. pType, GetTotalUnpackedSize(), pFuncName);
  1411. }
  1412. template<typename IBaseInterface, bool IsAnnotation>
  1413. _Use_decl_annotations_
  1414. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count)
  1415. {
  1416. return GetScalarArray<ETVT_Int, ETVT_Float, int, float>(Data.pNumericInt, pData, Offset, Count,
  1417. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray");
  1418. }
  1419. template<typename IBaseInterface, bool IsAnnotation>
  1420. _Use_decl_annotations_
  1421. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetInt(const int Value)
  1422. {
  1423. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt";
  1424. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1425. DirtyVariable();
  1426. return CopyScalarValue<ETVT_Int, ETVT_Int, int, false>(Value, Data.pNumericInt, pFuncName);
  1427. }
  1428. template<typename IBaseInterface, bool IsAnnotation>
  1429. _Use_decl_annotations_
  1430. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetInt(int *pValue)
  1431. {
  1432. return CopyScalarValue<ETVT_Int, ETVT_Int, int, true>(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetInt");
  1433. }
  1434. template<typename IBaseInterface, bool IsAnnotation>
  1435. _Use_decl_annotations_
  1436. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count)
  1437. {
  1438. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray";
  1439. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1440. DirtyVariable();
  1441. return SetScalarArray<ETVT_Int, ETVT_Int, int, int>(pData, Data.pNumericInt, Offset, Count,
  1442. pType, GetTotalUnpackedSize(), pFuncName);
  1443. }
  1444. template<typename IBaseInterface, bool IsAnnotation>
  1445. _Use_decl_annotations_
  1446. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetIntArray(int *pData, uint32_t Offset, uint32_t Count)
  1447. {
  1448. return GetScalarArray<ETVT_Int, ETVT_Int, int, int>(Data.pNumericInt, pData, Offset, Count,
  1449. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray");
  1450. }
  1451. template<typename IBaseInterface, bool IsAnnotation>
  1452. _Use_decl_annotations_
  1453. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetBool(const bool Value)
  1454. {
  1455. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool";
  1456. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1457. DirtyVariable();
  1458. return CopyScalarValue<ETVT_bool, ETVT_Int, bool, false>(Value, Data.pNumericInt, pFuncName);
  1459. }
  1460. template<typename IBaseInterface, bool IsAnnotation>
  1461. _Use_decl_annotations_
  1462. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetBool(bool *pValue)
  1463. {
  1464. return CopyScalarValue<ETVT_Int, ETVT_bool, int, true>(*Data.pNumericInt, pValue, "ID3DX11EffectScalarVariable::GetBool");
  1465. }
  1466. template<typename IBaseInterface, bool IsAnnotation>
  1467. _Use_decl_annotations_
  1468. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count)
  1469. {
  1470. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray";
  1471. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1472. DirtyVariable();
  1473. return SetScalarArray<ETVT_bool, ETVT_Int, bool, int>(pData, Data.pNumericInt, Offset, Count,
  1474. pType, GetTotalUnpackedSize(), pFuncName);
  1475. }
  1476. template<typename IBaseInterface, bool IsAnnotation>
  1477. _Use_decl_annotations_
  1478. HRESULT TIntScalarVariable<IBaseInterface, IsAnnotation>::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count)
  1479. {
  1480. return GetScalarArray<ETVT_Int, ETVT_bool, int, bool>(Data.pNumericInt, pData, Offset, Count,
  1481. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray");
  1482. }
  1483. //////////////////////////////////////////////////////////////////////////
  1484. // ID3DX11EffectScalarVariable (TBoolScalarVariable implementation)
  1485. //////////////////////////////////////////////////////////////////////////
  1486. template<typename IBaseInterface, bool IsAnnotation>
  1487. struct TBoolScalarVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
  1488. {
  1489. STDMETHOD(SetFloat)(_In_ const float Value) override;
  1490. STDMETHOD(GetFloat)(_Out_ float *pValue) override;
  1491. STDMETHOD(SetFloatArray)(_In_reads_(Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1492. STDMETHOD(GetFloatArray)(_Out_writes_(Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1493. STDMETHOD(SetInt)(_In_ const int Value) override;
  1494. STDMETHOD(GetInt)(_Out_ int *pValue) override;
  1495. STDMETHOD(SetIntArray)(_In_reads_(Count) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1496. STDMETHOD(GetIntArray)(_Out_writes_(Count) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1497. STDMETHOD(SetBool)(_In_ const bool Value) override;
  1498. STDMETHOD(GetBool)(_Out_ bool *pValue) override;
  1499. STDMETHOD(SetBoolArray)(_In_reads_(Count) const bool *pData, uint32_t Offset, _In_ uint32_t Count) override;
  1500. STDMETHOD(GetBoolArray)(_Out_writes_(Count) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1501. };
  1502. template<typename IBaseInterface, bool IsAnnotation>
  1503. _Use_decl_annotations_
  1504. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetFloat(float Value)
  1505. {
  1506. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloat";
  1507. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1508. DirtyVariable();
  1509. return CopyScalarValue<ETVT_Float, ETVT_Bool, float, false>(Value, Data.pNumericBool, pFuncName);
  1510. }
  1511. template<typename IBaseInterface, bool IsAnnotation>
  1512. _Use_decl_annotations_
  1513. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetFloat(float *pValue)
  1514. {
  1515. return CopyScalarValue<ETVT_Bool, ETVT_Float, BOOL, true>(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetFloat");
  1516. }
  1517. template<typename IBaseInterface, bool IsAnnotation>
  1518. _Use_decl_annotations_
  1519. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetFloatArray(const float *pData, uint32_t Offset, uint32_t Count)
  1520. {
  1521. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetFloatArray";
  1522. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1523. DirtyVariable();
  1524. return SetScalarArray<ETVT_Float, ETVT_Bool, float, BOOL>(pData, Data.pNumericBool, Offset, Count,
  1525. pType, GetTotalUnpackedSize(), pFuncName);
  1526. }
  1527. template<typename IBaseInterface, bool IsAnnotation>
  1528. _Use_decl_annotations_
  1529. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetFloatArray(float *pData, uint32_t Offset, uint32_t Count)
  1530. {
  1531. return GetScalarArray<ETVT_Bool, ETVT_Float, BOOL, float>(Data.pNumericBool, pData, Offset, Count,
  1532. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetFloatArray");
  1533. }
  1534. template<typename IBaseInterface, bool IsAnnotation>
  1535. _Use_decl_annotations_
  1536. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetInt(const int Value)
  1537. {
  1538. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetInt";
  1539. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1540. DirtyVariable();
  1541. return CopyScalarValue<ETVT_Int, ETVT_Bool, int, false>(Value, Data.pNumericBool, pFuncName);
  1542. }
  1543. template<typename IBaseInterface, bool IsAnnotation>
  1544. _Use_decl_annotations_
  1545. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetInt(int *pValue)
  1546. {
  1547. return CopyScalarValue<ETVT_Bool, ETVT_Int, BOOL, true>(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetInt");
  1548. }
  1549. template<typename IBaseInterface, bool IsAnnotation>
  1550. _Use_decl_annotations_
  1551. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetIntArray(const int *pData, uint32_t Offset, uint32_t Count)
  1552. {
  1553. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetIntArray";
  1554. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1555. DirtyVariable();
  1556. return SetScalarArray<ETVT_Int, ETVT_Bool, int, BOOL>(pData, Data.pNumericBool, Offset, Count,
  1557. pType, GetTotalUnpackedSize(), pFuncName);
  1558. }
  1559. template<typename IBaseInterface, bool IsAnnotation>
  1560. _Use_decl_annotations_
  1561. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetIntArray(int *pData, uint32_t Offset, uint32_t Count)
  1562. {
  1563. return GetScalarArray<ETVT_Bool, ETVT_Int, BOOL, int>(Data.pNumericBool, pData, Offset, Count,
  1564. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetIntArray");
  1565. }
  1566. template<typename IBaseInterface, bool IsAnnotation>
  1567. _Use_decl_annotations_
  1568. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetBool(const bool Value)
  1569. {
  1570. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBool";
  1571. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1572. DirtyVariable();
  1573. return CopyScalarValue<ETVT_bool, ETVT_Bool, bool, false>(Value, Data.pNumericBool, pFuncName);
  1574. }
  1575. template<typename IBaseInterface, bool IsAnnotation>
  1576. _Use_decl_annotations_
  1577. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetBool(bool *pValue)
  1578. {
  1579. return CopyScalarValue<ETVT_Bool, ETVT_bool, BOOL, true>(*Data.pNumericBool, pValue, "ID3DX11EffectScalarVariable::GetBool");
  1580. }
  1581. template<typename IBaseInterface, bool IsAnnotation>
  1582. _Use_decl_annotations_
  1583. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::SetBoolArray(const bool *pData, uint32_t Offset, uint32_t Count)
  1584. {
  1585. static LPCSTR pFuncName = "ID3DX11EffectScalarVariable::SetBoolArray";
  1586. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1587. DirtyVariable();
  1588. return SetScalarArray<ETVT_bool, ETVT_Bool, bool, BOOL>(pData, Data.pNumericBool, Offset, Count,
  1589. pType, GetTotalUnpackedSize(), pFuncName);
  1590. }
  1591. template<typename IBaseInterface, bool IsAnnotation>
  1592. _Use_decl_annotations_
  1593. HRESULT TBoolScalarVariable<IBaseInterface, IsAnnotation>::GetBoolArray(bool *pData, uint32_t Offset, uint32_t Count)
  1594. {
  1595. return GetScalarArray<ETVT_Bool, ETVT_bool, BOOL, bool>(Data.pNumericBool, pData, Offset, Count,
  1596. pType, GetTotalUnpackedSize(), "ID3DX11EffectScalarVariable::GetBoolArray");
  1597. }
  1598. //////////////////////////////////////////////////////////////////////////
  1599. // ID3DX11EffectVectorVariable (TVectorVariable implementation)
  1600. //////////////////////////////////////////////////////////////////////////
  1601. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType >
  1602. struct TVectorVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
  1603. {
  1604. STDMETHOD(SetBoolVector) (_In_reads_(4) const bool *pData) override;
  1605. STDMETHOD(SetIntVector) (_In_reads_(4) const int *pData) override;
  1606. STDMETHOD(SetFloatVector)(_In_reads_(4) const float *pData) override;
  1607. STDMETHOD(GetBoolVector) (_Out_writes_(4) bool *pData) override;
  1608. STDMETHOD(GetIntVector) (_Out_writes_(4) int *pData) override;
  1609. STDMETHOD(GetFloatVector)(_Out_writes_(4) float *pData) override;
  1610. STDMETHOD(SetBoolVectorArray) (_In_reads_(Count*4) const bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1611. STDMETHOD(SetIntVectorArray) (_In_reads_(Count*4) const int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1612. STDMETHOD(SetFloatVectorArray)(_In_reads_(Count*4) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1613. STDMETHOD(GetBoolVectorArray) (_Out_writes_(Count*4) bool *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1614. STDMETHOD(GetIntVectorArray) (_Out_writes_(Count*4) int *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1615. STDMETHOD(GetFloatVectorArray)(_Out_writes_(Count*4) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  1616. };
  1617. // Note that branches in this code is based on template parameters and will be compiled out
  1618. #pragma warning (push)
  1619. #pragma warning (disable : 6101)
  1620. template <ETemplateVarType DestType, ETemplateVarType SourceType>
  1621. void __forceinline CopyDataWithTypeConversion(_Out_ void *pDest,
  1622. _In_ const void *pSource,
  1623. _In_ size_t dstVecSize, _In_ size_t srcVecSize,
  1624. _In_ size_t elementCount, _In_ size_t vecCount)
  1625. {
  1626. switch (SourceType)
  1627. {
  1628. case ETVT_Bool:
  1629. switch (DestType)
  1630. {
  1631. case ETVT_Bool:
  1632. for (size_t j=0; j<vecCount; j++)
  1633. {
  1634. memcpy(pDest, pSource, elementCount * SType::c_ScalarSize);
  1635. pDest = ((float*) pDest) + dstVecSize;
  1636. pSource = ((float*) pSource) + srcVecSize;
  1637. }
  1638. break;
  1639. case ETVT_Int:
  1640. for (size_t j=0; j<vecCount; j++)
  1641. {
  1642. for (size_t i=0; i<elementCount; i++)
  1643. ((int*)pDest)[i] = ((bool*)pSource)[i] ? -1 : 0;
  1644. pDest = ((float*) pDest) + dstVecSize;
  1645. pSource = ((float*) pSource) + srcVecSize;
  1646. }
  1647. break;
  1648. case ETVT_Float:
  1649. for (size_t j=0; j<vecCount; j++)
  1650. {
  1651. for (size_t i=0; i<elementCount; i++)
  1652. ((float*)pDest)[i] = ((bool*)pSource)[i] ? -1.0f : 0.0f;
  1653. pDest = ((float*) pDest) + dstVecSize;
  1654. pSource = ((float*) pSource) + srcVecSize;
  1655. }
  1656. break;
  1657. case ETVT_bool:
  1658. for (size_t j=0; j<vecCount; j++)
  1659. {
  1660. for (size_t i=0; i<elementCount; i++)
  1661. ((bool*)pDest)[i] = (((int*)pSource)[i] != 0) ? true : false;
  1662. pDest = ((bool*) pDest) + dstVecSize;
  1663. pSource = ((float*) pSource) + srcVecSize;
  1664. }
  1665. break;
  1666. default:
  1667. assert(0);
  1668. }
  1669. break;
  1670. case ETVT_Int:
  1671. switch (DestType)
  1672. {
  1673. case ETVT_Bool:
  1674. for (size_t j=0; j<vecCount; j++)
  1675. {
  1676. for (size_t i=0; i<elementCount; i++)
  1677. ((int*)pDest)[i] = (((int*)pSource)[i] != 0) ? -1 : 0;
  1678. pDest = ((float*) pDest) + dstVecSize;
  1679. pSource = ((float*) pSource) + srcVecSize;
  1680. }
  1681. break;
  1682. case ETVT_Int:
  1683. for (size_t j=0; j<vecCount; j++)
  1684. {
  1685. memcpy(pDest, pSource, elementCount * SType::c_ScalarSize);
  1686. pDest = ((float*) pDest) + dstVecSize;
  1687. pSource = ((float*) pSource) + srcVecSize;
  1688. }
  1689. break;
  1690. case ETVT_Float:
  1691. for (size_t j=0; j<vecCount; j++)
  1692. {
  1693. for (size_t i=0; i<elementCount; i++)
  1694. ((float*)pDest)[i] = (float)(((int*)pSource)[i]);
  1695. pDest = ((float*) pDest) + dstVecSize;
  1696. pSource = ((float*) pSource) + srcVecSize;
  1697. }
  1698. break;
  1699. case ETVT_bool:
  1700. for (size_t j=0; j<vecCount; j++)
  1701. {
  1702. for (size_t i=0; i<elementCount; i++)
  1703. ((bool*)pDest)[i] = (((int*)pSource)[i] != 0) ? true : false;
  1704. pDest = ((bool*) pDest) + dstVecSize;
  1705. pSource = ((float*) pSource) + srcVecSize;
  1706. }
  1707. break;
  1708. default:
  1709. assert(0);
  1710. }
  1711. break;
  1712. case ETVT_Float:
  1713. switch (DestType)
  1714. {
  1715. case ETVT_Bool:
  1716. for (size_t j=0; j<vecCount; j++)
  1717. {
  1718. for (size_t i=0; i<elementCount; i++)
  1719. ((int*)pDest)[i] = (((float*)pSource)[i] != 0.0f) ? -1 : 0;
  1720. pDest = ((float*) pDest) + dstVecSize;
  1721. pSource = ((float*) pSource) + srcVecSize;
  1722. }
  1723. break;
  1724. case ETVT_Int:
  1725. for (size_t j=0; j<vecCount; j++)
  1726. {
  1727. for (size_t i=0; i<elementCount; i++)
  1728. ((int*)pDest)[i] = (int)((float*)pSource)[i];
  1729. pDest = ((float*) pDest) + dstVecSize;
  1730. pSource = ((float*) pSource) + srcVecSize;
  1731. }
  1732. break;
  1733. case ETVT_Float:
  1734. for (size_t i=0; i<vecCount; i++)
  1735. {
  1736. memcpy( pDest, pSource, elementCount * SType::c_ScalarSize);
  1737. pDest = ((float*) pDest) + dstVecSize;
  1738. pSource = ((float*) pSource) + srcVecSize;
  1739. }
  1740. break;
  1741. case ETVT_bool:
  1742. for (size_t j=0; j<vecCount; j++)
  1743. {
  1744. for (size_t i=0; i<elementCount; i++)
  1745. ((bool*)pDest)[i] = (((float*)pSource)[i] != 0.0f) ? true : false;
  1746. pDest = ((bool*) pDest) + dstVecSize;
  1747. pSource = ((float*) pSource) + srcVecSize;
  1748. }
  1749. break;
  1750. default:
  1751. assert(0);
  1752. }
  1753. break;
  1754. case ETVT_bool:
  1755. switch (DestType)
  1756. {
  1757. case ETVT_Bool:
  1758. for (size_t j=0; j<vecCount; j++)
  1759. {
  1760. for (size_t i=0; i<elementCount; i++)
  1761. reinterpret_cast<int*>(pDest)[i] = reinterpret_cast<const bool*>(pSource)[i] ? -1 : 0;
  1762. pDest = ((float*) pDest) + dstVecSize;
  1763. pSource = ((bool*) pSource) + srcVecSize;
  1764. }
  1765. break;
  1766. case ETVT_Int:
  1767. for (size_t j=0; j<vecCount; j++)
  1768. {
  1769. for (size_t i=0; i<elementCount; i++)
  1770. reinterpret_cast<int*>(pDest)[i] = reinterpret_cast<const bool*>(pSource)[i] ? -1 : 0;
  1771. pDest = ((float*) pDest) + dstVecSize;
  1772. pSource = ((bool*) pSource) + srcVecSize;
  1773. }
  1774. break;
  1775. case ETVT_Float:
  1776. for (size_t j=0; j<vecCount; j++)
  1777. {
  1778. for (size_t i=0; i<elementCount; i++)
  1779. reinterpret_cast<float*>(pDest)[i] = reinterpret_cast<const bool*>(pSource)[i] ? -1.0f : 0.0f;
  1780. pDest = ((float*) pDest) + dstVecSize;
  1781. pSource = ((bool*) pSource) + srcVecSize;
  1782. }
  1783. break;
  1784. case ETVT_bool:
  1785. for (size_t j=0; j<vecCount; j++)
  1786. {
  1787. memcpy(pDest, pSource, elementCount);
  1788. pDest = ((bool*) pDest) + dstVecSize;
  1789. pSource = ((bool*) pSource) + srcVecSize;
  1790. }
  1791. break;
  1792. default:
  1793. assert(0);
  1794. }
  1795. break;
  1796. default:
  1797. assert(0);
  1798. }
  1799. }
  1800. #pragma warning (pop)
  1801. // Float Vector
  1802. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1803. _Use_decl_annotations_
  1804. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType >::SetFloatVector(const float *pData)
  1805. {
  1806. HRESULT hr = S_OK;
  1807. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVector";
  1808. #ifdef _DEBUG
  1809. VERIFYPARAMETER(pData);
  1810. #endif
  1811. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1812. DirtyVariable();
  1813. CopyDataWithTypeConversion<BaseType, ETVT_Float>(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1);
  1814. lExit:
  1815. return hr;
  1816. }
  1817. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1818. _Use_decl_annotations_
  1819. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetFloatVector(float *pData)
  1820. {
  1821. HRESULT hr = S_OK;
  1822. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVector";
  1823. #ifdef _DEBUG
  1824. VERIFYPARAMETER(pData);
  1825. #endif
  1826. CopyDataWithTypeConversion<ETVT_Float, BaseType>(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1);
  1827. lExit:
  1828. return hr;
  1829. }
  1830. // Int Vector
  1831. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1832. _Use_decl_annotations_
  1833. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType >::SetIntVector(const int *pData)
  1834. {
  1835. HRESULT hr = S_OK;
  1836. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetIntVector";
  1837. #ifdef _DEBUG
  1838. VERIFYPARAMETER(pData);
  1839. #endif
  1840. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1841. DirtyVariable();
  1842. CopyDataWithTypeConversion<BaseType, ETVT_Int>(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1);
  1843. lExit:
  1844. return hr;
  1845. }
  1846. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1847. _Use_decl_annotations_
  1848. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetIntVector(int *pData)
  1849. {
  1850. HRESULT hr = S_OK;
  1851. #ifdef _DEBUG
  1852. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetIntVector";
  1853. VERIFYPARAMETER(pData);
  1854. #endif
  1855. CopyDataWithTypeConversion<ETVT_Int, BaseType>(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1);
  1856. lExit:
  1857. return hr;
  1858. }
  1859. // Bool Vector
  1860. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1861. _Use_decl_annotations_
  1862. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType >::SetBoolVector(const bool *pData)
  1863. {
  1864. HRESULT hr = S_OK;
  1865. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetBoolVector";
  1866. #ifdef _DEBUG
  1867. VERIFYPARAMETER(pData);
  1868. #endif
  1869. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1870. DirtyVariable();
  1871. CopyDataWithTypeConversion<BaseType, ETVT_bool>(Data.pVector, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, 1);
  1872. lExit:
  1873. return hr;
  1874. }
  1875. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1876. _Use_decl_annotations_
  1877. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetBoolVector(bool *pData)
  1878. {
  1879. HRESULT hr = S_OK;
  1880. #ifdef _DEBUG
  1881. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetBoolVector";
  1882. VERIFYPARAMETER(pData);
  1883. #endif
  1884. CopyDataWithTypeConversion<ETVT_bool, BaseType>(pData, Data.pVector, pType->NumericType.Columns, 4, pType->NumericType.Columns, 1);
  1885. lExit:
  1886. return hr;
  1887. }
  1888. // Vector Arrays /////////////////////////////////////////////////////////
  1889. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1890. _Use_decl_annotations_
  1891. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::SetFloatVectorArray(const float *pData, uint32_t Offset, uint32_t Count)
  1892. {
  1893. HRESULT hr = S_OK;
  1894. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVectorArray";
  1895. #ifdef _DEBUG
  1896. #pragma warning( suppress : 6001 )
  1897. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  1898. {
  1899. DPF(0, "%s: Invalid range specified", pFuncName);
  1900. VH(E_INVALIDARG);
  1901. }
  1902. #endif
  1903. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1904. DirtyVariable();
  1905. // ensure we don't write over the padding at the end of the vector array
  1906. CopyDataWithTypeConversion<BaseType, ETVT_Float>(Data.pVector + Offset, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
  1907. lExit:
  1908. return hr;
  1909. }
  1910. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1911. _Use_decl_annotations_
  1912. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetFloatVectorArray(float *pData, uint32_t Offset, uint32_t Count)
  1913. {
  1914. HRESULT hr = S_OK;
  1915. #ifdef _DEBUG
  1916. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVectorArray";
  1917. #pragma warning( suppress : 6001 )
  1918. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  1919. {
  1920. DPF(0, "%s: Invalid range specified", pFuncName);
  1921. VH(E_INVALIDARG);
  1922. }
  1923. #endif
  1924. // ensure we don't read past the end of the vector array
  1925. CopyDataWithTypeConversion<ETVT_Float, BaseType>(pData, Data.pVector + Offset, pType->NumericType.Columns, 4, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
  1926. lExit:
  1927. return hr;
  1928. }
  1929. // int
  1930. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1931. _Use_decl_annotations_
  1932. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::SetIntVectorArray(const int *pData, uint32_t Offset, uint32_t Count)
  1933. {
  1934. HRESULT hr = S_OK;
  1935. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetIntVectorArray";
  1936. #ifdef _DEBUG
  1937. #pragma warning( suppress : 6001 )
  1938. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  1939. {
  1940. DPF(0, "%s: Invalid range specified", pFuncName);
  1941. VH(E_INVALIDARG);
  1942. }
  1943. #endif
  1944. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1945. DirtyVariable();
  1946. // ensure we don't write over the padding at the end of the vector array
  1947. CopyDataWithTypeConversion<BaseType, ETVT_Int>(Data.pVector + Offset, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
  1948. lExit:
  1949. return hr;
  1950. }
  1951. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1952. _Use_decl_annotations_
  1953. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetIntVectorArray(int *pData, uint32_t Offset, uint32_t Count)
  1954. {
  1955. HRESULT hr = S_OK;
  1956. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetIntVectorArray";
  1957. #ifdef _DEBUG
  1958. #pragma warning( suppress : 6001 )
  1959. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  1960. {
  1961. DPF(0, "%s: Invalid range specified", pFuncName);
  1962. VH(E_INVALIDARG);
  1963. }
  1964. #endif
  1965. // ensure we don't read past the end of the vector array
  1966. CopyDataWithTypeConversion<ETVT_Int, BaseType>(pData, Data.pVector + Offset, pType->NumericType.Columns, 4, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
  1967. lExit:
  1968. return hr;
  1969. }
  1970. // bool
  1971. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1972. _Use_decl_annotations_
  1973. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::SetBoolVectorArray(const bool *pData, uint32_t Offset, uint32_t Count)
  1974. {
  1975. HRESULT hr = S_OK;
  1976. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetBoolVectorArray";
  1977. #ifdef _DEBUG
  1978. #pragma warning( suppress : 6001 )
  1979. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  1980. {
  1981. DPF(0, "%s: Invalid range specified", pFuncName);
  1982. VH(E_INVALIDARG);
  1983. }
  1984. #endif
  1985. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  1986. DirtyVariable();
  1987. // ensure we don't write over the padding at the end of the vector array
  1988. CopyDataWithTypeConversion<BaseType, ETVT_bool>(Data.pVector + Offset, pData, 4, pType->NumericType.Columns, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
  1989. lExit:
  1990. return hr;
  1991. }
  1992. template<typename IBaseInterface, bool IsAnnotation, ETemplateVarType BaseType>
  1993. _Use_decl_annotations_
  1994. HRESULT TVectorVariable<IBaseInterface, IsAnnotation, BaseType>::GetBoolVectorArray(bool *pData, uint32_t Offset, uint32_t Count)
  1995. {
  1996. HRESULT hr = S_OK;
  1997. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetBoolVectorArray";
  1998. #ifdef _DEBUG
  1999. #pragma warning( suppress : 6001 )
  2000. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  2001. {
  2002. DPF(0, "%s: Invalid range specified", pFuncName);
  2003. VH(E_INVALIDARG);
  2004. }
  2005. #endif
  2006. // ensure we don't read past the end of the vector array
  2007. CopyDataWithTypeConversion<ETVT_bool, BaseType>(pData, Data.pVector + Offset, pType->NumericType.Columns, 4, pType->NumericType.Columns, std::max(std::min((int)Count, (int)pType->Elements - (int)Offset), 0));
  2008. lExit:
  2009. return hr;
  2010. }
  2011. //////////////////////////////////////////////////////////////////////////
  2012. // ID3DX11EffectVector4Variable (TVectorVariable implementation) [OPTIMIZED]
  2013. //////////////////////////////////////////////////////////////////////////
  2014. template<typename IBaseInterface>
  2015. struct TVector4Variable : public TVectorVariable<IBaseInterface, false, ETVT_Float>
  2016. {
  2017. STDMETHOD(SetFloatVector)(_In_reads_(4) const float *pData) override;
  2018. STDMETHOD(GetFloatVector)(_Out_writes_(4) float *pData) override;
  2019. STDMETHOD(SetFloatVectorArray)(_In_reads_(Count*4) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2020. STDMETHOD(GetFloatVectorArray)(_Out_writes_(Count*4) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2021. };
  2022. template<typename IBaseInterface>
  2023. _Use_decl_annotations_
  2024. HRESULT TVector4Variable<IBaseInterface>::SetFloatVector(const float *pData)
  2025. {
  2026. HRESULT hr = S_OK;
  2027. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVector";
  2028. #ifdef _DEBUG
  2029. VERIFYPARAMETER(pData);
  2030. #endif
  2031. DirtyVariable();
  2032. Data.pVector[0] = ((CEffectVector4*) pData)[0];
  2033. lExit:
  2034. return hr;
  2035. }
  2036. template<typename IBaseInterface>
  2037. _Use_decl_annotations_
  2038. HRESULT TVector4Variable<IBaseInterface>::GetFloatVector(float *pData)
  2039. {
  2040. HRESULT hr = S_OK;
  2041. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVector";
  2042. #ifdef _DEBUG
  2043. VERIFYPARAMETER(pData);
  2044. #endif
  2045. memcpy(pData, Data.pVector, pType->NumericType.Columns * SType::c_ScalarSize);
  2046. lExit:
  2047. return hr;
  2048. }
  2049. template<typename IBaseInterface>
  2050. _Use_decl_annotations_
  2051. HRESULT TVector4Variable<IBaseInterface>::SetFloatVectorArray(const float *pData, uint32_t Offset, uint32_t Count)
  2052. {
  2053. HRESULT hr = S_OK;
  2054. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::SetFloatVectorArray";
  2055. #ifdef _DEBUG
  2056. #pragma warning( suppress : 6001 )
  2057. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  2058. {
  2059. DPF(0, "%s: Invalid range specified", pFuncName);
  2060. VH(E_INVALIDARG);
  2061. }
  2062. #endif
  2063. DirtyVariable();
  2064. // ensure we don't write over the padding at the end of the vector array
  2065. memcpy(Data.pVector + Offset, pData,
  2066. std::min<size_t>(Count * sizeof(CEffectVector4), pType->TotalSize - (Offset * sizeof(CEffectVector4))));
  2067. lExit:
  2068. return hr;
  2069. }
  2070. template<typename IBaseInterface>
  2071. _Use_decl_annotations_
  2072. HRESULT TVector4Variable<IBaseInterface>::GetFloatVectorArray(float *pData, uint32_t Offset, uint32_t Count)
  2073. {
  2074. HRESULT hr = S_OK;
  2075. static LPCSTR pFuncName = "ID3DX11EffectVectorVariable::GetFloatVectorArray";
  2076. #ifdef _DEBUG
  2077. #pragma warning( suppress : 6001 )
  2078. if (!AreBoundsValid(Offset, Count, pData, pType, GetTotalUnpackedSize()))
  2079. {
  2080. DPF(0, "%s: Invalid range specified", pFuncName);
  2081. VH(E_INVALIDARG);
  2082. }
  2083. #endif
  2084. // ensure we don't read past the end of the vector array
  2085. memcpy(pData, Data.pVector + Offset,
  2086. std::min<size_t>(Count * sizeof(CEffectVector4), pType->TotalSize - (Offset * sizeof(CEffectVector4))));
  2087. lExit:
  2088. return hr;
  2089. }
  2090. //////////////////////////////////////////////////////////////////////////
  2091. // ID3DX11EffectMatrixVariable (TMatrixVariable implementation)
  2092. //////////////////////////////////////////////////////////////////////////
  2093. template<typename IBaseInterface, bool IsAnnotation>
  2094. struct TMatrixVariable : public TNumericVariable<IBaseInterface, IsAnnotation>
  2095. {
  2096. STDMETHOD(SetMatrix)(_In_reads_(16) const float *pData) override;
  2097. STDMETHOD(GetMatrix)(_Out_writes_(16) float *pData) override;
  2098. STDMETHOD(SetMatrixArray)(_In_reads_(Count*16) const float *pData, uint32_t Offset, uint32_t Count) override;
  2099. STDMETHOD(GetMatrixArray)(_Out_writes_(Count*16) float *pData, uint32_t Offset, uint32_t Count) override;
  2100. STDMETHOD(SetMatrixPointerArray)(_In_reads_(Count*16) const float **ppData, uint32_t Offset, uint32_t Count) override;
  2101. STDMETHOD(GetMatrixPointerArray)(_Out_writes_(Count*16) float **ppData, uint32_t Offset, uint32_t Count) override;
  2102. STDMETHOD(SetMatrixTranspose)(_In_reads_(16) const float *pData) override;
  2103. STDMETHOD(GetMatrixTranspose)(_Out_writes_(16) float *pData) override;
  2104. STDMETHOD(SetMatrixTransposeArray)(_In_reads_(Count*16) const float *pData, uint32_t Offset, uint32_t Count) override;
  2105. STDMETHOD(GetMatrixTransposeArray)(_Out_writes_(Count*16) float *pData, uint32_t Offset, uint32_t Count) override;
  2106. STDMETHOD(SetMatrixTransposePointerArray)(_In_reads_(Count*16) const float **ppData, uint32_t Offset, uint32_t Count) override;
  2107. STDMETHOD(GetMatrixTransposePointerArray)(_Out_writes_(Count*16) float **ppData, uint32_t Offset, uint32_t Count) override;
  2108. };
  2109. #pragma warning (push)
  2110. #pragma warning (disable : 6101)
  2111. template<bool Transpose>
  2112. static void SetMatrixTransposeHelper(_In_ const SType *pType, _Out_writes_bytes_(64) uint8_t *pDestData, _In_reads_(16) const float* pMatrix)
  2113. {
  2114. uint32_t registers, entries;
  2115. if (Transpose)
  2116. {
  2117. // row major
  2118. registers = pType->NumericType.Rows;
  2119. entries = pType->NumericType.Columns;
  2120. }
  2121. else
  2122. {
  2123. // column major
  2124. registers = pType->NumericType.Columns;
  2125. entries = pType->NumericType.Rows;
  2126. }
  2127. _Analysis_assume_( registers <= 4 );
  2128. _Analysis_assume_( entries <= 4 );
  2129. for (size_t i = 0; i < registers; ++ i)
  2130. {
  2131. for (size_t j = 0; j < entries; ++ j)
  2132. {
  2133. #pragma prefast(suppress:__WARNING_UNRELATED_LOOP_TERMINATION, "regs / entries <= 4")
  2134. ((float*)pDestData)[j] = ((float*)pMatrix)[j * 4 + i];
  2135. }
  2136. pDestData += SType::c_RegisterSize;
  2137. }
  2138. }
  2139. template<bool Transpose>
  2140. static void GetMatrixTransposeHelper(_In_ const SType *pType, _In_reads_bytes_(64) uint8_t *pSrcData, _Out_writes_(16) float* pMatrix)
  2141. {
  2142. uint32_t registers, entries;
  2143. if (Transpose)
  2144. {
  2145. // row major
  2146. registers = pType->NumericType.Rows;
  2147. entries = pType->NumericType.Columns;
  2148. }
  2149. else
  2150. {
  2151. // column major
  2152. registers = pType->NumericType.Columns;
  2153. entries = pType->NumericType.Rows;
  2154. }
  2155. _Analysis_assume_( registers <= 4 );
  2156. _Analysis_assume_( entries <= 4 );
  2157. for (size_t i = 0; i < registers; ++ i)
  2158. {
  2159. for (size_t j = 0; j < entries; ++ j)
  2160. {
  2161. ((float*)pMatrix)[j * 4 + i] = ((float*)pSrcData)[j];
  2162. }
  2163. pSrcData += SType::c_RegisterSize;
  2164. }
  2165. }
  2166. template<bool Transpose, bool IsSetting, bool ExtraIndirection>
  2167. HRESULT DoMatrixArrayInternal(_In_ const SType *pType, _In_ uint32_t TotalUnpackedSize,
  2168. _Out_ uint8_t *pEffectData,
  2169. void *pMatrixData,
  2170. _In_ uint32_t Offset, _In_ uint32_t Count, _In_z_ LPCSTR pFuncName)
  2171. {
  2172. HRESULT hr = S_OK;
  2173. #ifdef _DEBUG
  2174. #pragma warning( suppress : 6001 )
  2175. if (!AreBoundsValid(Offset, Count, pMatrixData, pType, TotalUnpackedSize))
  2176. {
  2177. DPF(0, "%s: Invalid range specified", pFuncName);
  2178. VH(E_INVALIDARG);
  2179. }
  2180. #else
  2181. UNREFERENCED_PARAMETER(TotalUnpackedSize);
  2182. UNREFERENCED_PARAMETER(pFuncName);
  2183. #endif
  2184. if ((pType->NumericType.IsColumnMajor && Transpose) || (!pType->NumericType.IsColumnMajor && !Transpose))
  2185. {
  2186. // fast path
  2187. uint32_t dataSize;
  2188. if (Transpose)
  2189. {
  2190. dataSize = ((pType->NumericType.Columns - 1) * 4 + pType->NumericType.Rows) * SType::c_ScalarSize;
  2191. }
  2192. else
  2193. {
  2194. dataSize = ((pType->NumericType.Rows - 1) * 4 + pType->NumericType.Columns) * SType::c_ScalarSize;
  2195. }
  2196. for (size_t i = 0; i < Count; ++ i)
  2197. {
  2198. CEffectMatrix *pMatrix;
  2199. if (ExtraIndirection)
  2200. {
  2201. pMatrix = ((CEffectMatrix **)pMatrixData)[i];
  2202. if (!pMatrix)
  2203. {
  2204. continue;
  2205. }
  2206. }
  2207. else
  2208. {
  2209. pMatrix = ((CEffectMatrix *)pMatrixData) + i;
  2210. }
  2211. if (IsSetting)
  2212. {
  2213. memcpy(pEffectData + pType->Stride * (i + Offset), pMatrix, dataSize);
  2214. }
  2215. else
  2216. {
  2217. memcpy(pMatrix, pEffectData + pType->Stride * (i + Offset), dataSize);
  2218. }
  2219. }
  2220. }
  2221. else
  2222. {
  2223. // slow path
  2224. for (size_t i = 0; i < Count; ++ i)
  2225. {
  2226. CEffectMatrix *pMatrix;
  2227. if (ExtraIndirection)
  2228. {
  2229. pMatrix = ((CEffectMatrix **)pMatrixData)[i];
  2230. if (!pMatrix)
  2231. {
  2232. continue;
  2233. }
  2234. }
  2235. else
  2236. {
  2237. pMatrix = ((CEffectMatrix *)pMatrixData) + i;
  2238. }
  2239. if (IsSetting)
  2240. {
  2241. SetMatrixTransposeHelper<Transpose>(pType, pEffectData + pType->Stride * (i + Offset), (float*) pMatrix);
  2242. }
  2243. else
  2244. {
  2245. GetMatrixTransposeHelper<Transpose>(pType, pEffectData + pType->Stride * (i + Offset), (float*) pMatrix);
  2246. }
  2247. }
  2248. }
  2249. lExit:
  2250. return hr;
  2251. }
  2252. #pragma warning (pop)
  2253. template<typename IBaseInterface, bool IsAnnotation>
  2254. _Use_decl_annotations_
  2255. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrix(const float *pData)
  2256. {
  2257. static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrix";
  2258. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  2259. DirtyVariable();
  2260. return DoMatrixArrayInternal<false, true, false>(pType, GetTotalUnpackedSize(),
  2261. Data.pNumeric, const_cast<float*>(pData), 0, 1, pFuncName);
  2262. }
  2263. template<typename IBaseInterface, bool IsAnnotation>
  2264. _Use_decl_annotations_
  2265. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrix(float *pData)
  2266. {
  2267. return DoMatrixArrayInternal<false, false, false>(pType, GetTotalUnpackedSize(),
  2268. Data.pNumeric, pData, 0, 1, "ID3DX11EffectMatrixVariable::GetMatrix");
  2269. }
  2270. template<typename IBaseInterface, bool IsAnnotation>
  2271. _Use_decl_annotations_
  2272. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixArray(const float *pData, uint32_t Offset, uint32_t Count)
  2273. {
  2274. static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixArray";
  2275. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  2276. DirtyVariable();
  2277. return DoMatrixArrayInternal<false, true, false>(pType, GetTotalUnpackedSize(),
  2278. Data.pNumeric, const_cast<float*>(pData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixArray");
  2279. }
  2280. template<typename IBaseInterface, bool IsAnnotation>
  2281. _Use_decl_annotations_
  2282. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixArray(float *pData, uint32_t Offset, uint32_t Count)
  2283. {
  2284. return DoMatrixArrayInternal<false, false, false>(pType, GetTotalUnpackedSize(),
  2285. Data.pNumeric, pData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixArray");
  2286. }
  2287. template<typename IBaseInterface, bool IsAnnotation>
  2288. _Use_decl_annotations_
  2289. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixPointerArray(const float **ppData, uint32_t Offset, uint32_t Count)
  2290. {
  2291. static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixPointerArray";
  2292. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  2293. DirtyVariable();
  2294. return DoMatrixArrayInternal<false, true, true>(pType, GetTotalUnpackedSize(),
  2295. Data.pNumeric, const_cast<float**>(ppData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixPointerArray");
  2296. }
  2297. template<typename IBaseInterface, bool IsAnnotation>
  2298. _Use_decl_annotations_
  2299. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixPointerArray(float **ppData, uint32_t Offset, uint32_t Count)
  2300. {
  2301. return DoMatrixArrayInternal<false, false, true>(pType, GetTotalUnpackedSize(),
  2302. Data.pNumeric, ppData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixPointerArray");
  2303. }
  2304. template<typename IBaseInterface, bool IsAnnotation>
  2305. _Use_decl_annotations_
  2306. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixTranspose(const float *pData)
  2307. {
  2308. static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTranspose";
  2309. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  2310. DirtyVariable();
  2311. return DoMatrixArrayInternal<true, true, false>(pType, GetTotalUnpackedSize(),
  2312. Data.pNumeric, const_cast<float*>(pData), 0, 1, "ID3DX11EffectMatrixVariable::SetMatrixTranspose");
  2313. }
  2314. template<typename IBaseInterface, bool IsAnnotation>
  2315. _Use_decl_annotations_
  2316. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixTranspose(float *pData)
  2317. {
  2318. return DoMatrixArrayInternal<true, false, false>(pType, GetTotalUnpackedSize(),
  2319. Data.pNumeric, pData, 0, 1, "ID3DX11EffectMatrixVariable::GetMatrixTranspose");
  2320. }
  2321. template<typename IBaseInterface, bool IsAnnotation>
  2322. _Use_decl_annotations_
  2323. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixTransposeArray(const float *pData, uint32_t Offset, uint32_t Count)
  2324. {
  2325. static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray";
  2326. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  2327. DirtyVariable();
  2328. return DoMatrixArrayInternal<true, true, false>(pType, GetTotalUnpackedSize(),
  2329. Data.pNumeric, const_cast<float*>(pData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray");
  2330. }
  2331. template<typename IBaseInterface, bool IsAnnotation>
  2332. _Use_decl_annotations_
  2333. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixTransposeArray(float *pData, uint32_t Offset, uint32_t Count)
  2334. {
  2335. return DoMatrixArrayInternal<true, false, false>(pType, GetTotalUnpackedSize(),
  2336. Data.pNumeric, pData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixTransposeArray");
  2337. }
  2338. template<typename IBaseInterface, bool IsAnnotation>
  2339. _Use_decl_annotations_
  2340. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::SetMatrixTransposePointerArray(const float **ppData, uint32_t Offset, uint32_t Count)
  2341. {
  2342. static LPCSTR pFuncName = "ID3DX11EffectMatrixVariable::SetMatrixTransposePointerArray";
  2343. if (IsAnnotation) return AnnotationInvalidSetCall(pFuncName);
  2344. DirtyVariable();
  2345. return DoMatrixArrayInternal<true, true, true>(pType, GetTotalUnpackedSize(),
  2346. Data.pNumeric, const_cast<float**>(ppData), Offset, Count, "ID3DX11EffectMatrixVariable::SetMatrixTransposePointerArray");
  2347. }
  2348. template<typename IBaseInterface, bool IsAnnotation>
  2349. _Use_decl_annotations_
  2350. HRESULT TMatrixVariable<IBaseInterface, IsAnnotation>::GetMatrixTransposePointerArray(float **ppData, uint32_t Offset, uint32_t Count)
  2351. {
  2352. return DoMatrixArrayInternal<true, false, true>(pType, GetTotalUnpackedSize(),
  2353. Data.pNumeric, ppData, Offset, Count, "ID3DX11EffectMatrixVariable::GetMatrixTransposePointerArray");
  2354. }
  2355. // Optimize commonly used fast paths
  2356. // (non-annotations only!)
  2357. template<typename IBaseInterface, bool IsColumnMajor>
  2358. struct TMatrix4x4Variable : public TMatrixVariable<IBaseInterface, false>
  2359. {
  2360. STDMETHOD(SetMatrix)(_In_reads_(16) const float *pData) override;
  2361. STDMETHOD(GetMatrix)(_Out_writes_(16) float *pData) override;
  2362. STDMETHOD(SetMatrixArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2363. STDMETHOD(GetMatrixArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2364. STDMETHOD(SetMatrixTranspose)(_In_reads_(16) const float *pData) override;
  2365. STDMETHOD(GetMatrixTranspose)(_Out_writes_(16) float *pData) override;
  2366. STDMETHOD(SetMatrixTransposeArray)(_In_reads_(16*Count) const float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2367. STDMETHOD(GetMatrixTransposeArray)(_Out_writes_(16*Count) float *pData, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2368. };
  2369. inline static void Matrix4x4TransposeHelper(_In_reads_bytes_(64) const void *pSrc, _Out_writes_bytes_(64) void *pDst)
  2370. {
  2371. uint8_t *pDestData = (uint8_t*)pDst;
  2372. uint32_t *pMatrix = (uint32_t*)pSrc;
  2373. ((uint32_t*)pDestData)[0 * 4 + 0] = pMatrix[0 * 4 + 0];
  2374. ((uint32_t*)pDestData)[0 * 4 + 1] = pMatrix[1 * 4 + 0];
  2375. ((uint32_t*)pDestData)[0 * 4 + 2] = pMatrix[2 * 4 + 0];
  2376. ((uint32_t*)pDestData)[0 * 4 + 3] = pMatrix[3 * 4 + 0];
  2377. ((uint32_t*)pDestData)[1 * 4 + 0] = pMatrix[0 * 4 + 1];
  2378. ((uint32_t*)pDestData)[1 * 4 + 1] = pMatrix[1 * 4 + 1];
  2379. ((uint32_t*)pDestData)[1 * 4 + 2] = pMatrix[2 * 4 + 1];
  2380. ((uint32_t*)pDestData)[1 * 4 + 3] = pMatrix[3 * 4 + 1];
  2381. ((uint32_t*)pDestData)[2 * 4 + 0] = pMatrix[0 * 4 + 2];
  2382. ((uint32_t*)pDestData)[2 * 4 + 1] = pMatrix[1 * 4 + 2];
  2383. ((uint32_t*)pDestData)[2 * 4 + 2] = pMatrix[2 * 4 + 2];
  2384. ((uint32_t*)pDestData)[2 * 4 + 3] = pMatrix[3 * 4 + 2];
  2385. ((uint32_t*)pDestData)[3 * 4 + 0] = pMatrix[0 * 4 + 3];
  2386. ((uint32_t*)pDestData)[3 * 4 + 1] = pMatrix[1 * 4 + 3];
  2387. ((uint32_t*)pDestData)[3 * 4 + 2] = pMatrix[2 * 4 + 3];
  2388. ((uint32_t*)pDestData)[3 * 4 + 3] = pMatrix[3 * 4 + 3];
  2389. }
  2390. inline static void Matrix4x4Copy(_In_reads_bytes_(64) const void *pSrc, _Out_writes_bytes_(64) void *pDst)
  2391. {
  2392. #if 1
  2393. // In tests, this path ended up generating faster code both on x86 and x64
  2394. // T1 - Matrix4x4Copy - this path
  2395. // T2 - Matrix4x4Transpose
  2396. // T1: 1.88 T2: 1.92 - with 32 bit copies
  2397. // T1: 1.85 T2: 1.80 - with 64 bit copies
  2398. uint64_t *pDestData = (uint64_t*)pDst;
  2399. uint64_t *pMatrix = (uint64_t*)pSrc;
  2400. pDestData[0 * 4 + 0] = pMatrix[0 * 4 + 0];
  2401. pDestData[0 * 4 + 1] = pMatrix[0 * 4 + 1];
  2402. pDestData[0 * 4 + 2] = pMatrix[0 * 4 + 2];
  2403. pDestData[0 * 4 + 3] = pMatrix[0 * 4 + 3];
  2404. pDestData[1 * 4 + 0] = pMatrix[1 * 4 + 0];
  2405. pDestData[1 * 4 + 1] = pMatrix[1 * 4 + 1];
  2406. pDestData[1 * 4 + 2] = pMatrix[1 * 4 + 2];
  2407. pDestData[1 * 4 + 3] = pMatrix[1 * 4 + 3];
  2408. #else
  2409. uint32_t *pDestData = (uint32_t*)pDst;
  2410. uint32_t *pMatrix = (uint32_t*)pSrc;
  2411. pDestData[0 * 4 + 0] = pMatrix[0 * 4 + 0];
  2412. pDestData[0 * 4 + 1] = pMatrix[0 * 4 + 1];
  2413. pDestData[0 * 4 + 2] = pMatrix[0 * 4 + 2];
  2414. pDestData[0 * 4 + 3] = pMatrix[0 * 4 + 3];
  2415. pDestData[1 * 4 + 0] = pMatrix[1 * 4 + 0];
  2416. pDestData[1 * 4 + 1] = pMatrix[1 * 4 + 1];
  2417. pDestData[1 * 4 + 2] = pMatrix[1 * 4 + 2];
  2418. pDestData[1 * 4 + 3] = pMatrix[1 * 4 + 3];
  2419. pDestData[2 * 4 + 0] = pMatrix[2 * 4 + 0];
  2420. pDestData[2 * 4 + 1] = pMatrix[2 * 4 + 1];
  2421. pDestData[2 * 4 + 2] = pMatrix[2 * 4 + 2];
  2422. pDestData[2 * 4 + 3] = pMatrix[2 * 4 + 3];
  2423. pDestData[3 * 4 + 0] = pMatrix[3 * 4 + 0];
  2424. pDestData[3 * 4 + 1] = pMatrix[3 * 4 + 1];
  2425. pDestData[3 * 4 + 2] = pMatrix[3 * 4 + 2];
  2426. pDestData[3 * 4 + 3] = pMatrix[3 * 4 + 3];
  2427. #endif
  2428. }
  2429. // Note that branches in this code is based on template parameters and will be compiled out
  2430. #pragma warning (push)
  2431. #pragma warning (disable : 6101)
  2432. template<bool IsColumnMajor, bool Transpose, bool IsSetting>
  2433. inline HRESULT DoMatrix4x4ArrayInternal(_In_ uint8_t *pEffectData,
  2434. _When_(IsSetting, _In_reads_bytes_(64 * Count))
  2435. _When_(!IsSetting, _Out_writes_bytes_(64 * Count))
  2436. void *pMatrixData,
  2437. _In_ uint32_t Offset, _In_ uint32_t Count
  2438. #ifdef _DEBUG
  2439. , _In_ const SType *pType, _In_ uint32_t TotalUnpackedSize, _In_z_ LPCSTR pFuncName
  2440. #endif
  2441. )
  2442. {
  2443. HRESULT hr = S_OK;
  2444. #ifdef _DEBUG
  2445. #pragma warning( suppress : 6001 )
  2446. if (!AreBoundsValid(Offset, Count, pMatrixData, pType, TotalUnpackedSize))
  2447. {
  2448. DPF(0, "%s: Invalid range specified", pFuncName);
  2449. VH(E_INVALIDARG);
  2450. }
  2451. assert(pType->NumericType.IsColumnMajor == IsColumnMajor && pType->Stride == (4 * SType::c_RegisterSize));
  2452. #endif
  2453. if ((IsColumnMajor && Transpose) || (!IsColumnMajor && !Transpose))
  2454. {
  2455. // fast path
  2456. for (size_t i = 0; i < Count; ++ i)
  2457. {
  2458. CEffectMatrix *pMatrix = ((CEffectMatrix *)pMatrixData) + i;
  2459. if (IsSetting)
  2460. {
  2461. Matrix4x4Copy(pMatrix, pEffectData + 4 * SType::c_RegisterSize * (i + Offset));
  2462. }
  2463. else
  2464. {
  2465. Matrix4x4Copy(pEffectData + 4 * SType::c_RegisterSize * (i + Offset), pMatrix);
  2466. }
  2467. }
  2468. }
  2469. else
  2470. {
  2471. // slow path
  2472. for (size_t i = 0; i < Count; ++ i)
  2473. {
  2474. CEffectMatrix *pMatrix = ((CEffectMatrix *)pMatrixData) + i;
  2475. if (IsSetting)
  2476. {
  2477. Matrix4x4TransposeHelper((float*) pMatrix, pEffectData + 4 * SType::c_RegisterSize * (i + Offset));
  2478. }
  2479. else
  2480. {
  2481. Matrix4x4TransposeHelper(pEffectData + 4 * SType::c_RegisterSize * (i + Offset), (float*) pMatrix);
  2482. }
  2483. }
  2484. }
  2485. lExit:
  2486. return hr;
  2487. }
  2488. #pragma warning (pop)
  2489. template<typename IBaseInterface, bool IsColumnMajor>
  2490. _Use_decl_annotations_
  2491. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrix(const float *pData)
  2492. {
  2493. DirtyVariable();
  2494. return DoMatrix4x4ArrayInternal<IsColumnMajor, false, true>(Data.pNumeric, const_cast<float*>(pData), 0, 1
  2495. #ifdef _DEBUG
  2496. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrix");
  2497. #else
  2498. );
  2499. #endif
  2500. }
  2501. template<typename IBaseInterface, bool IsColumnMajor>
  2502. _Use_decl_annotations_
  2503. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrix(float *pData)
  2504. {
  2505. return DoMatrix4x4ArrayInternal<IsColumnMajor, false, false>(Data.pNumeric, pData, 0, 1
  2506. #ifdef _DEBUG
  2507. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrix");
  2508. #else
  2509. );
  2510. #endif
  2511. }
  2512. template<typename IBaseInterface, bool IsColumnMajor>
  2513. _Use_decl_annotations_
  2514. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrixArray(const float *pData, uint32_t Offset, uint32_t Count)
  2515. {
  2516. DirtyVariable();
  2517. return DoMatrix4x4ArrayInternal<IsColumnMajor, false, true>(Data.pNumeric, const_cast<float*>(pData), Offset, Count
  2518. #ifdef _DEBUG
  2519. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixArray");
  2520. #else
  2521. );
  2522. #endif
  2523. }
  2524. template<typename IBaseInterface, bool IsColumnMajor>
  2525. _Use_decl_annotations_
  2526. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrixArray(float *pData, uint32_t Offset, uint32_t Count)
  2527. {
  2528. return DoMatrix4x4ArrayInternal<IsColumnMajor, false, false>(Data.pNumeric, pData, Offset, Count
  2529. #ifdef _DEBUG
  2530. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixArray");
  2531. #else
  2532. );
  2533. #endif
  2534. }
  2535. template<typename IBaseInterface, bool IsColumnMajor>
  2536. _Use_decl_annotations_
  2537. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrixTranspose(const float *pData)
  2538. {
  2539. DirtyVariable();
  2540. return DoMatrix4x4ArrayInternal<IsColumnMajor, true, true>(Data.pNumeric, const_cast<float*>(pData), 0, 1
  2541. #ifdef _DEBUG
  2542. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixTranspose");
  2543. #else
  2544. );
  2545. #endif
  2546. }
  2547. template<typename IBaseInterface, bool IsColumnMajor>
  2548. _Use_decl_annotations_
  2549. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrixTranspose(float *pData)
  2550. {
  2551. return DoMatrix4x4ArrayInternal<IsColumnMajor, true, false>(Data.pNumeric, pData, 0, 1
  2552. #ifdef _DEBUG
  2553. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixTranspose");
  2554. #else
  2555. );
  2556. #endif
  2557. }
  2558. template<typename IBaseInterface, bool IsColumnMajor>
  2559. _Use_decl_annotations_
  2560. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::SetMatrixTransposeArray(const float *pData, uint32_t Offset, uint32_t Count)
  2561. {
  2562. DirtyVariable();
  2563. return DoMatrix4x4ArrayInternal<IsColumnMajor, true, true>(Data.pNumeric, const_cast<float*>(pData), Offset, Count
  2564. #ifdef _DEBUG
  2565. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::SetMatrixTransposeArray");
  2566. #else
  2567. );
  2568. #endif
  2569. }
  2570. template<typename IBaseInterface, bool IsColumnMajor>
  2571. _Use_decl_annotations_
  2572. HRESULT TMatrix4x4Variable<IBaseInterface, IsColumnMajor>::GetMatrixTransposeArray(float *pData, uint32_t Offset, uint32_t Count)
  2573. {
  2574. return DoMatrix4x4ArrayInternal<IsColumnMajor, true, false>(Data.pNumeric, pData, Offset, Count
  2575. #ifdef _DEBUG
  2576. , pType, GetTotalUnpackedSize(), "ID3DX11EffectMatrixVariable::GetMatrixTransposeArray");
  2577. #else
  2578. );
  2579. #endif
  2580. }
  2581. #ifdef _DEBUG
  2582. // Useful object macro to check bounds and parameters
  2583. #define CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, Pointer) \
  2584. HRESULT hr = S_OK; \
  2585. VERIFYPARAMETER(Pointer) \
  2586. uint32_t elements = IsArray() ? pType->Elements : 1; \
  2587. \
  2588. if ((Offset + Count < Offset) || (elements < Offset + Count)) \
  2589. { \
  2590. DPF(0, "%s: Invalid range specified", pFuncName); \
  2591. VH(E_INVALIDARG); \
  2592. } \
  2593. #define CHECK_OBJECT_SCALAR_BOUNDS(Index, Pointer) \
  2594. HRESULT hr = S_OK; \
  2595. VERIFYPARAMETER(Pointer) \
  2596. uint32_t elements = IsArray() ? pType->Elements : 1; \
  2597. \
  2598. if (Index >= elements) \
  2599. { \
  2600. DPF(0, "%s: Invalid index specified", pFuncName); \
  2601. VH(E_INVALIDARG); \
  2602. } \
  2603. #define CHECK_SCALAR_BOUNDS(Index) \
  2604. HRESULT hr = S_OK; \
  2605. uint32_t elements = IsArray() ? pType->Elements : 1; \
  2606. \
  2607. if (Index >= elements) \
  2608. { \
  2609. DPF(0, "%s: Invalid index specified", pFuncName); \
  2610. VH(E_INVALIDARG); \
  2611. } \
  2612. #else // _DEBUG
  2613. #define CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, Pointer) \
  2614. HRESULT hr = S_OK; \
  2615. #define CHECK_OBJECT_SCALAR_BOUNDS(Index, Pointer) \
  2616. HRESULT hr = S_OK; \
  2617. #define CHECK_SCALAR_BOUNDS(Index) \
  2618. HRESULT hr = S_OK; \
  2619. #endif // _DEBUG
  2620. //////////////////////////////////////////////////////////////////////////
  2621. // ID3DX11EffectStringVariable (TStringVariable implementation)
  2622. //////////////////////////////////////////////////////////////////////////
  2623. template<typename IBaseInterface, bool IsAnnotation>
  2624. struct TStringVariable : public IBaseInterface
  2625. {
  2626. STDMETHOD(GetString)(_Outptr_result_z_ LPCSTR *ppString) override;
  2627. STDMETHOD(GetStringArray)( _Out_writes_(Count) LPCSTR *ppStrings, _In_ uint32_t Offset, _In_ uint32_t Count ) override;
  2628. };
  2629. template<typename IBaseInterface, bool IsAnnotation>
  2630. _Use_decl_annotations_
  2631. HRESULT TStringVariable<IBaseInterface, IsAnnotation>::GetString(LPCSTR *ppString)
  2632. {
  2633. HRESULT hr = S_OK;
  2634. static LPCSTR pFuncName = "ID3DX11EffectStringVariable::GetString";
  2635. VERIFYPARAMETER(ppString);
  2636. if (GetTopLevelEntity()->pEffect->IsOptimized())
  2637. {
  2638. DPF(0, "%s: Effect has been Optimize()'ed; all string/reflection data has been deleted", pFuncName);
  2639. return D3DERR_INVALIDCALL;
  2640. }
  2641. assert(Data.pString != 0);
  2642. _Analysis_assume_(Data.pString != 0);
  2643. *ppString = Data.pString->pString;
  2644. lExit:
  2645. return hr;
  2646. }
  2647. template<typename IBaseInterface, bool IsAnnotation>
  2648. _Use_decl_annotations_
  2649. #pragma warning(suppress : 6054)
  2650. HRESULT TStringVariable<IBaseInterface, IsAnnotation>::GetStringArray( LPCSTR *ppStrings, uint32_t Offset, uint32_t Count)
  2651. {
  2652. static LPCSTR pFuncName = "ID3DX11EffectStringVariable::GetStringArray";
  2653. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppStrings);
  2654. if (GetTopLevelEntity()->pEffect->IsOptimized())
  2655. {
  2656. DPF(0, "%s: Effect has been Optimize()'ed; all string/reflection data has been deleted", pFuncName);
  2657. return D3DERR_INVALIDCALL;
  2658. }
  2659. assert(Data.pString != 0);
  2660. _Analysis_assume_(Data.pString != 0);
  2661. for (size_t i = 0; i < Count; ++ i)
  2662. {
  2663. ppStrings[i] = (Data.pString + Offset + i)->pString;
  2664. }
  2665. lExit:
  2666. return hr;
  2667. }
  2668. //////////////////////////////////////////////////////////////////////////
  2669. // ID3DX11EffectClassInstanceVariable (TClassInstanceVariable implementation)
  2670. //////////////////////////////////////////////////////////////////////////
  2671. template<typename IBaseInterface>
  2672. struct TClassInstanceVariable : public IBaseInterface
  2673. {
  2674. STDMETHOD(GetClassInstance)(_Outptr_ ID3D11ClassInstance **ppClassInstance) override;
  2675. };
  2676. template<typename IBaseClassInstance>
  2677. HRESULT TClassInstanceVariable<IBaseClassInstance>::GetClassInstance(_Outptr_ ID3D11ClassInstance** ppClassInstance)
  2678. {
  2679. HRESULT hr = S_OK;
  2680. static LPCSTR pFuncName = "ID3DX11EffectClassInstanceVariable::GetClassInstance";
  2681. assert( pMemberData != 0 && pMemberData->Data.pD3DClassInstance != 0);
  2682. _Analysis_assume_( pMemberData != 0 && pMemberData->Data.pD3DClassInstance != 0);
  2683. *ppClassInstance = pMemberData->Data.pD3DClassInstance;
  2684. SAFE_ADDREF(*ppClassInstance);
  2685. lExit:
  2686. return hr;
  2687. }
  2688. //////////////////////////////////////////////////////////////////////////
  2689. // ID3DX11EffectInterfaceeVariable (TInterfaceVariable implementation)
  2690. //////////////////////////////////////////////////////////////////////////
  2691. template<typename IBaseInterface>
  2692. struct TInterfaceVariable : public IBaseInterface
  2693. {
  2694. STDMETHOD(SetClassInstance)(_In_ ID3DX11EffectClassInstanceVariable *pEffectClassInstance) override;
  2695. STDMETHOD(GetClassInstance)(_Outptr_ ID3DX11EffectClassInstanceVariable **ppEffectClassInstance) override;
  2696. };
  2697. template<typename IBaseInterface>
  2698. HRESULT TInterfaceVariable<IBaseInterface>::SetClassInstance(_In_ ID3DX11EffectClassInstanceVariable *pEffectClassInstance)
  2699. {
  2700. HRESULT hr = S_OK;
  2701. static LPCSTR pFuncName = "ID3DX11EffectInterfaceVariable::SetClassInstance";
  2702. // Note that we don't check if the types are compatible. The debug layer will complain if it is.
  2703. // IsValid() will not catch type mismatches.
  2704. SClassInstanceGlobalVariable* pCI = (SClassInstanceGlobalVariable*)pEffectClassInstance;
  2705. Data.pInterface->pClassInstance = pCI;
  2706. lExit:
  2707. return hr;
  2708. }
  2709. template<typename IBaseInterface>
  2710. HRESULT TInterfaceVariable<IBaseInterface>::GetClassInstance(_Outptr_ ID3DX11EffectClassInstanceVariable **ppEffectClassInstance)
  2711. {
  2712. HRESULT hr = S_OK;
  2713. static LPCSTR pFuncName = "ID3DX11EffectInterfaceVariable::GetClassInstance";
  2714. #ifdef _DEBUG
  2715. VERIFYPARAMETER(ppEffectClassInstance);
  2716. #endif
  2717. *ppEffectClassInstance = Data.pInterface->pClassInstance;
  2718. lExit:
  2719. return hr;
  2720. }
  2721. //////////////////////////////////////////////////////////////////////////
  2722. // ID3DX11EffectShaderResourceVariable (TShaderResourceVariable implementation)
  2723. //////////////////////////////////////////////////////////////////////////
  2724. template<typename IBaseInterface>
  2725. struct TShaderResourceVariable : public IBaseInterface
  2726. {
  2727. STDMETHOD(SetResource)(_In_ ID3D11ShaderResourceView *pResource) override;
  2728. STDMETHOD(GetResource)(_Outptr_ ID3D11ShaderResourceView **ppResource) override;
  2729. STDMETHOD(SetResourceArray)(_In_reads_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2730. STDMETHOD(GetResourceArray)(_Out_writes_(Count) ID3D11ShaderResourceView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  2731. };
  2732. static LPCSTR GetTextureTypeNameFromEnum(_In_ EObjectType ObjectType)
  2733. {
  2734. switch (ObjectType)
  2735. {
  2736. case EOT_Buffer:
  2737. return "Buffer";
  2738. case EOT_Texture:
  2739. return "texture";
  2740. case EOT_Texture1D:
  2741. case EOT_Texture1DArray:
  2742. return "Texture1D";
  2743. case EOT_Texture2DMS:
  2744. case EOT_Texture2DMSArray:
  2745. return "Texture2DMS";
  2746. case EOT_Texture2D:
  2747. case EOT_Texture2DArray:
  2748. return "Texture2D";
  2749. case EOT_Texture3D:
  2750. return "Texture3D";
  2751. case EOT_TextureCube:
  2752. return "TextureCube";
  2753. case EOT_TextureCubeArray:
  2754. return "TextureCubeArray";
  2755. case EOT_RWTexture1D:
  2756. case EOT_RWTexture1DArray:
  2757. return "RWTexture1D";
  2758. case EOT_RWTexture2D:
  2759. case EOT_RWTexture2DArray:
  2760. return "RWTexture2D";
  2761. case EOT_RWTexture3D:
  2762. return "RWTexture3D";
  2763. case EOT_RWBuffer:
  2764. return "RWBuffer";
  2765. case EOT_ByteAddressBuffer:
  2766. return "ByteAddressBuffer";
  2767. case EOT_RWByteAddressBuffer:
  2768. return "RWByteAddressBuffer";
  2769. case EOT_StructuredBuffer:
  2770. return "StructuredBuffe";
  2771. case EOT_RWStructuredBuffer:
  2772. return "RWStructuredBuffer";
  2773. case EOT_RWStructuredBufferAlloc:
  2774. return "RWStructuredBufferAlloc";
  2775. case EOT_RWStructuredBufferConsume:
  2776. return "RWStructuredBufferConsume";
  2777. case EOT_AppendStructuredBuffer:
  2778. return "AppendStructuredBuffer";
  2779. case EOT_ConsumeStructuredBuffer:
  2780. return "ConsumeStructuredBuffer";
  2781. }
  2782. return "<unknown texture format>";
  2783. }
  2784. static LPCSTR GetResourceDimensionNameFromEnum(_In_ D3D11_RESOURCE_DIMENSION ResourceDimension)
  2785. {
  2786. switch (ResourceDimension)
  2787. {
  2788. case D3D11_RESOURCE_DIMENSION_BUFFER:
  2789. return "Buffer";
  2790. case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
  2791. return "Texture1D";
  2792. case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
  2793. return "Texture2D";
  2794. case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
  2795. return "Texture3D";
  2796. }
  2797. return "<unknown texture format>";
  2798. }
  2799. static LPCSTR GetSRVDimensionNameFromEnum(_In_ D3D11_SRV_DIMENSION ViewDimension)
  2800. {
  2801. switch (ViewDimension)
  2802. {
  2803. case D3D11_SRV_DIMENSION_BUFFER:
  2804. case D3D11_SRV_DIMENSION_BUFFEREX:
  2805. return "Buffer";
  2806. case D3D11_SRV_DIMENSION_TEXTURE1D:
  2807. return "Texture1D";
  2808. case D3D11_SRV_DIMENSION_TEXTURE1DARRAY:
  2809. return "Texture1DArray";
  2810. case D3D11_SRV_DIMENSION_TEXTURE2D:
  2811. return "Texture2D";
  2812. case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
  2813. return "Texture2DArray";
  2814. case D3D11_SRV_DIMENSION_TEXTURE2DMS:
  2815. return "Texture2DMS";
  2816. case D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY:
  2817. return "Texture2DMSArray";
  2818. case D3D11_SRV_DIMENSION_TEXTURE3D:
  2819. return "Texture3D";
  2820. case D3D11_SRV_DIMENSION_TEXTURECUBE:
  2821. return "TextureCube";
  2822. }
  2823. return "<unknown texture format>";
  2824. }
  2825. static LPCSTR GetUAVDimensionNameFromEnum(_In_ D3D11_UAV_DIMENSION ViewDimension)
  2826. {
  2827. switch (ViewDimension)
  2828. {
  2829. case D3D11_UAV_DIMENSION_BUFFER:
  2830. return "Buffer";
  2831. case D3D11_UAV_DIMENSION_TEXTURE1D:
  2832. return "RWTexture1D";
  2833. case D3D11_UAV_DIMENSION_TEXTURE1DARRAY:
  2834. return "RWTexture1DArray";
  2835. case D3D11_UAV_DIMENSION_TEXTURE2D:
  2836. return "RWTexture2D";
  2837. case D3D11_UAV_DIMENSION_TEXTURE2DARRAY:
  2838. return "RWTexture2DArray";
  2839. case D3D11_UAV_DIMENSION_TEXTURE3D:
  2840. return "RWTexture3D";
  2841. }
  2842. return "<unknown texture format>";
  2843. }
  2844. static LPCSTR GetRTVDimensionNameFromEnum(_In_ D3D11_RTV_DIMENSION ViewDimension)
  2845. {
  2846. switch (ViewDimension)
  2847. {
  2848. case D3D11_RTV_DIMENSION_BUFFER:
  2849. return "Buffer";
  2850. case D3D11_RTV_DIMENSION_TEXTURE1D:
  2851. return "Texture1D";
  2852. case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
  2853. return "Texture1DArray";
  2854. case D3D11_RTV_DIMENSION_TEXTURE2D:
  2855. return "Texture2D";
  2856. case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
  2857. return "Texture2DArray";
  2858. case D3D11_RTV_DIMENSION_TEXTURE2DMS:
  2859. return "Texture2DMS";
  2860. case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
  2861. return "Texture2DMSArray";
  2862. case D3D11_RTV_DIMENSION_TEXTURE3D:
  2863. return "Texture3D";
  2864. }
  2865. return "<unknown texture format>";
  2866. }
  2867. static LPCSTR GetDSVDimensionNameFromEnum(_In_ D3D11_DSV_DIMENSION ViewDimension)
  2868. {
  2869. switch (ViewDimension)
  2870. {
  2871. case D3D11_DSV_DIMENSION_TEXTURE1D:
  2872. return "Texture1D";
  2873. case D3D11_DSV_DIMENSION_TEXTURE1DARRAY:
  2874. return "Texture1DArray";
  2875. case D3D11_DSV_DIMENSION_TEXTURE2D:
  2876. return "Texture2D";
  2877. case D3D11_DSV_DIMENSION_TEXTURE2DARRAY:
  2878. return "Texture2DArray";
  2879. case D3D11_DSV_DIMENSION_TEXTURE2DMS:
  2880. return "Texture2DMS";
  2881. case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY:
  2882. return "Texture2DMSArray";
  2883. }
  2884. return "<unknown texture format>";
  2885. }
  2886. static HRESULT ValidateTextureType(_In_ ID3D11ShaderResourceView *pView, _In_ EObjectType ObjectType, _In_z_ LPCSTR pFuncName)
  2887. {
  2888. if (nullptr != pView)
  2889. {
  2890. D3D11_SHADER_RESOURCE_VIEW_DESC desc;
  2891. pView->GetDesc(&desc);
  2892. switch (ObjectType)
  2893. {
  2894. case EOT_Texture:
  2895. if (desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFER && desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX)
  2896. return S_OK;
  2897. break;
  2898. case EOT_Buffer:
  2899. if (desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFER && desc.ViewDimension != D3D11_SRV_DIMENSION_BUFFEREX)
  2900. break;
  2901. if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFEREX && (desc.BufferEx.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW))
  2902. {
  2903. DPF(0, "%s: Resource type mismatch; %s expected, ByteAddressBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  2904. return E_INVALIDARG;
  2905. }
  2906. else
  2907. {
  2908. ID3D11Buffer* pBuffer = nullptr;
  2909. pView->GetResource( (ID3D11Resource**)&pBuffer );
  2910. assert( pBuffer != nullptr );
  2911. D3D11_BUFFER_DESC BufDesc;
  2912. pBuffer->GetDesc( &BufDesc );
  2913. SAFE_RELEASE( pBuffer );
  2914. if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
  2915. {
  2916. DPF(0, "%s: Resource type mismatch; %s expected, StructuredBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  2917. return E_INVALIDARG;
  2918. }
  2919. else
  2920. {
  2921. return S_OK;
  2922. }
  2923. }
  2924. break;
  2925. case EOT_Texture1D:
  2926. case EOT_Texture1DArray:
  2927. if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE1D ||
  2928. desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
  2929. return S_OK;
  2930. break;
  2931. case EOT_Texture2D:
  2932. case EOT_Texture2DArray:
  2933. if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D ||
  2934. desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
  2935. return S_OK;
  2936. break;
  2937. case EOT_Texture2DMS:
  2938. case EOT_Texture2DMSArray:
  2939. if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMS ||
  2940. desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
  2941. return S_OK;
  2942. break;
  2943. case EOT_Texture3D:
  2944. if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
  2945. return S_OK;
  2946. break;
  2947. case EOT_TextureCube:
  2948. case EOT_TextureCubeArray:
  2949. if (desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE ||
  2950. desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
  2951. return S_OK;
  2952. break;
  2953. case EOT_ByteAddressBuffer:
  2954. if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFEREX && (desc.BufferEx.Flags & D3D11_BUFFEREX_SRV_FLAG_RAW))
  2955. return S_OK;
  2956. break;
  2957. case EOT_StructuredBuffer:
  2958. if (desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFEREX || desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER)
  2959. {
  2960. ID3D11Buffer* pBuffer = nullptr;
  2961. pView->GetResource( (ID3D11Resource**)&pBuffer );
  2962. assert( pBuffer != nullptr );
  2963. D3D11_BUFFER_DESC BufDesc;
  2964. pBuffer->GetDesc( &BufDesc );
  2965. SAFE_RELEASE( pBuffer );
  2966. if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
  2967. {
  2968. return S_OK;
  2969. }
  2970. else
  2971. {
  2972. DPF(0, "%s: Resource type mismatch; %s expected, non-structured Buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  2973. return E_INVALIDARG;
  2974. }
  2975. }
  2976. break;
  2977. default:
  2978. assert(0); // internal error, should never get here
  2979. return E_FAIL;
  2980. }
  2981. DPF(0, "%s: Resource type mismatch; %s expected, %s provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType), GetSRVDimensionNameFromEnum(desc.ViewDimension));
  2982. return E_INVALIDARG;
  2983. }
  2984. return S_OK;
  2985. }
  2986. template<typename IBaseInterface>
  2987. _Use_decl_annotations_
  2988. HRESULT TShaderResourceVariable<IBaseInterface>::SetResource(ID3D11ShaderResourceView *pResource)
  2989. {
  2990. HRESULT hr = S_OK;
  2991. #ifdef _DEBUG
  2992. static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::SetResource";
  2993. VH(ValidateTextureType(pResource, pType->ObjectType, pFuncName));
  2994. #endif
  2995. // Texture variables don't need to be dirtied.
  2996. SAFE_ADDREF(pResource);
  2997. SAFE_RELEASE(Data.pShaderResource->pShaderResource);
  2998. Data.pShaderResource->pShaderResource = pResource;
  2999. lExit:
  3000. return hr;
  3001. }
  3002. template<typename IBaseInterface>
  3003. _Use_decl_annotations_
  3004. HRESULT TShaderResourceVariable<IBaseInterface>::GetResource(ID3D11ShaderResourceView **ppResource)
  3005. {
  3006. HRESULT hr = S_OK;
  3007. #ifdef _DEBUG
  3008. static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::GetResource";
  3009. VERIFYPARAMETER(ppResource);
  3010. #endif
  3011. assert(Data.pShaderResource != 0 && Data.pShaderResource->pShaderResource != 0);
  3012. _Analysis_assume_(Data.pShaderResource != 0 && Data.pShaderResource->pShaderResource != 0);
  3013. *ppResource = Data.pShaderResource->pShaderResource;
  3014. SAFE_ADDREF(*ppResource);
  3015. lExit:
  3016. return hr;
  3017. }
  3018. template<typename IBaseInterface>
  3019. _Use_decl_annotations_
  3020. HRESULT TShaderResourceVariable<IBaseInterface>::SetResourceArray(ID3D11ShaderResourceView **ppResources, uint32_t Offset, uint32_t Count)
  3021. {
  3022. static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::SetResourceArray";
  3023. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3024. #ifdef _DEBUG
  3025. for (size_t i = 0; i < Count; ++ i)
  3026. {
  3027. VH(ValidateTextureType(ppResources[i], pType->ObjectType, pFuncName));
  3028. }
  3029. #endif
  3030. // Texture variables don't need to be dirtied.
  3031. for (size_t i = 0; i < Count; ++ i)
  3032. {
  3033. SShaderResource *pResourceBlock = Data.pShaderResource + Offset + i;
  3034. SAFE_ADDREF(ppResources[i]);
  3035. SAFE_RELEASE(pResourceBlock->pShaderResource);
  3036. pResourceBlock->pShaderResource = ppResources[i];
  3037. }
  3038. lExit:
  3039. return hr;
  3040. }
  3041. template<typename IBaseInterface>
  3042. _Use_decl_annotations_
  3043. HRESULT TShaderResourceVariable<IBaseInterface>::GetResourceArray(ID3D11ShaderResourceView **ppResources, uint32_t Offset, uint32_t Count)
  3044. {
  3045. static LPCSTR pFuncName = "ID3DX11EffectShaderResourceVariable::GetResourceArray";
  3046. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3047. for (size_t i = 0; i < Count; ++ i)
  3048. {
  3049. ppResources[i] = (Data.pShaderResource + Offset + i)->pShaderResource;
  3050. SAFE_ADDREF(ppResources[i]);
  3051. }
  3052. lExit:
  3053. return hr;
  3054. }
  3055. //////////////////////////////////////////////////////////////////////////
  3056. // ID3DX11EffectUnorderedAccessViewVariable (TUnorderedAccessViewVariable implementation)
  3057. //////////////////////////////////////////////////////////////////////////
  3058. template<typename IBaseInterface>
  3059. struct TUnorderedAccessViewVariable : public IBaseInterface
  3060. {
  3061. STDMETHOD(SetUnorderedAccessView)(_In_ ID3D11UnorderedAccessView *pResource) override;
  3062. STDMETHOD(GetUnorderedAccessView)(_Outptr_ ID3D11UnorderedAccessView **ppResource) override;
  3063. STDMETHOD(SetUnorderedAccessViewArray)(_In_reads_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  3064. STDMETHOD(GetUnorderedAccessViewArray)(_Out_writes_(Count) ID3D11UnorderedAccessView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  3065. };
  3066. static HRESULT ValidateTextureType(_In_ ID3D11UnorderedAccessView *pView, _In_ EObjectType ObjectType, _In_z_ LPCSTR pFuncName)
  3067. {
  3068. if (nullptr != pView)
  3069. {
  3070. D3D11_UNORDERED_ACCESS_VIEW_DESC desc;
  3071. pView->GetDesc(&desc);
  3072. switch (ObjectType)
  3073. {
  3074. case EOT_RWBuffer:
  3075. if (desc.ViewDimension != D3D11_UAV_DIMENSION_BUFFER)
  3076. break;
  3077. if (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_RAW)
  3078. {
  3079. DPF(0, "%s: Resource type mismatch; %s expected, RWByteAddressBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  3080. return E_INVALIDARG;
  3081. }
  3082. else
  3083. {
  3084. ID3D11Buffer* pBuffer = nullptr;
  3085. pView->GetResource( (ID3D11Resource**)&pBuffer );
  3086. assert( pBuffer != nullptr );
  3087. D3D11_BUFFER_DESC BufDesc;
  3088. pBuffer->GetDesc( &BufDesc );
  3089. SAFE_RELEASE( pBuffer );
  3090. if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
  3091. {
  3092. DPF(0, "%s: Resource type mismatch; %s expected, an RWStructuredBuffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  3093. return E_INVALIDARG;
  3094. }
  3095. else
  3096. {
  3097. return S_OK;
  3098. }
  3099. }
  3100. break;
  3101. case EOT_RWTexture1D:
  3102. case EOT_RWTexture1DArray:
  3103. if (desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE1D ||
  3104. desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
  3105. return S_OK;
  3106. break;
  3107. case EOT_RWTexture2D:
  3108. case EOT_RWTexture2DArray:
  3109. if (desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D ||
  3110. desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
  3111. return S_OK;
  3112. break;
  3113. case EOT_RWTexture3D:
  3114. if (desc.ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
  3115. return S_OK;
  3116. break;
  3117. case EOT_RWByteAddressBuffer:
  3118. if (desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER && (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_RAW))
  3119. return S_OK;
  3120. break;
  3121. case EOT_RWStructuredBuffer:
  3122. if (desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER)
  3123. {
  3124. ID3D11Buffer* pBuffer = nullptr;
  3125. pView->GetResource( (ID3D11Resource**)&pBuffer );
  3126. assert( pBuffer != nullptr );
  3127. D3D11_BUFFER_DESC BufDesc;
  3128. pBuffer->GetDesc( &BufDesc );
  3129. SAFE_RELEASE( pBuffer );
  3130. if( BufDesc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED )
  3131. {
  3132. return S_OK;
  3133. }
  3134. else
  3135. {
  3136. DPF(0, "%s: Resource type mismatch; %s expected, non-structured Buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  3137. return E_INVALIDARG;
  3138. }
  3139. }
  3140. break;
  3141. case EOT_RWStructuredBufferAlloc:
  3142. case EOT_RWStructuredBufferConsume:
  3143. if (desc.ViewDimension != D3D11_UAV_DIMENSION_BUFFER)
  3144. break;
  3145. if (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_COUNTER)
  3146. {
  3147. return S_OK;
  3148. }
  3149. else
  3150. {
  3151. DPF(0, "%s: Resource type mismatch; %s expected, non-Counter buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  3152. return E_INVALIDARG;
  3153. }
  3154. break;
  3155. case EOT_AppendStructuredBuffer:
  3156. case EOT_ConsumeStructuredBuffer:
  3157. if (desc.ViewDimension != D3D11_UAV_DIMENSION_BUFFER)
  3158. break;
  3159. if (desc.Buffer.Flags & D3D11_BUFFER_UAV_FLAG_APPEND)
  3160. {
  3161. return S_OK;
  3162. }
  3163. else
  3164. {
  3165. DPF(0, "%s: Resource type mismatch; %s expected, non-Append buffer provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType));
  3166. return E_INVALIDARG;
  3167. }
  3168. break;
  3169. default:
  3170. assert(0); // internal error, should never get here
  3171. return E_FAIL;
  3172. }
  3173. DPF(0, "%s: Resource type mismatch; %s expected, %s provided.", pFuncName, GetTextureTypeNameFromEnum(ObjectType), GetUAVDimensionNameFromEnum(desc.ViewDimension));
  3174. return E_INVALIDARG;
  3175. }
  3176. return S_OK;
  3177. }
  3178. template<typename IBaseInterface>
  3179. _Use_decl_annotations_
  3180. HRESULT TUnorderedAccessViewVariable<IBaseInterface>::SetUnorderedAccessView(ID3D11UnorderedAccessView *pResource)
  3181. {
  3182. HRESULT hr = S_OK;
  3183. #ifdef _DEBUG
  3184. static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::SetUnorderedAccessView";
  3185. VH(ValidateTextureType(pResource, pType->ObjectType, pFuncName));
  3186. #endif
  3187. // UAV variables don't need to be dirtied.
  3188. SAFE_ADDREF(pResource);
  3189. SAFE_RELEASE(Data.pUnorderedAccessView->pUnorderedAccessView);
  3190. Data.pUnorderedAccessView->pUnorderedAccessView = pResource;
  3191. lExit:
  3192. return hr;
  3193. }
  3194. template<typename IBaseInterface>
  3195. _Use_decl_annotations_
  3196. HRESULT TUnorderedAccessViewVariable<IBaseInterface>::GetUnorderedAccessView(ID3D11UnorderedAccessView **ppResource)
  3197. {
  3198. HRESULT hr = S_OK;
  3199. #ifdef _DEBUG
  3200. static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::GetUnorderedAccessView";
  3201. VERIFYPARAMETER(ppResource);
  3202. #endif
  3203. assert(Data.pUnorderedAccessView != 0 && Data.pUnorderedAccessView->pUnorderedAccessView != 0);
  3204. _Analysis_assume_(Data.pUnorderedAccessView != 0 && Data.pUnorderedAccessView->pUnorderedAccessView != 0);
  3205. *ppResource = Data.pUnorderedAccessView->pUnorderedAccessView;
  3206. SAFE_ADDREF(*ppResource);
  3207. lExit:
  3208. return hr;
  3209. }
  3210. template<typename IBaseInterface>
  3211. _Use_decl_annotations_
  3212. HRESULT TUnorderedAccessViewVariable<IBaseInterface>::SetUnorderedAccessViewArray(ID3D11UnorderedAccessView **ppResources, uint32_t Offset, uint32_t Count)
  3213. {
  3214. static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::SetUnorderedAccessViewArray";
  3215. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3216. #ifdef _DEBUG
  3217. for (size_t i = 0; i < Count; ++ i)
  3218. {
  3219. VH(ValidateTextureType(ppResources[i], pType->ObjectType, pFuncName));
  3220. }
  3221. #endif
  3222. // Texture variables don't need to be dirtied.
  3223. for (size_t i = 0; i < Count; ++ i)
  3224. {
  3225. SUnorderedAccessView *pResourceBlock = Data.pUnorderedAccessView + Offset + i;
  3226. SAFE_ADDREF(ppResources[i]);
  3227. SAFE_RELEASE(pResourceBlock->pUnorderedAccessView);
  3228. pResourceBlock->pUnorderedAccessView = ppResources[i];
  3229. }
  3230. lExit:
  3231. return hr;
  3232. }
  3233. template<typename IBaseInterface>
  3234. _Use_decl_annotations_
  3235. HRESULT TUnorderedAccessViewVariable<IBaseInterface>::GetUnorderedAccessViewArray(ID3D11UnorderedAccessView **ppResources, uint32_t Offset, uint32_t Count)
  3236. {
  3237. static LPCSTR pFuncName = "ID3DX11EffectUnorderedAccessViewVariable::GetUnorderedAccessViewArray";
  3238. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3239. for (size_t i = 0; i < Count; ++ i)
  3240. {
  3241. ppResources[i] = (Data.pUnorderedAccessView + Offset + i)->pUnorderedAccessView;
  3242. SAFE_ADDREF(ppResources[i]);
  3243. }
  3244. lExit:
  3245. return hr;
  3246. }
  3247. //////////////////////////////////////////////////////////////////////////
  3248. // ID3DX11EffectRenderTargetViewVariable (TRenderTargetViewVariable implementation)
  3249. //////////////////////////////////////////////////////////////////////////
  3250. template<typename IBaseInterface>
  3251. struct TRenderTargetViewVariable : public IBaseInterface
  3252. {
  3253. STDMETHOD(SetRenderTarget)(_In_ ID3D11RenderTargetView *pResource) override;
  3254. STDMETHOD(GetRenderTarget)(_Outptr_ ID3D11RenderTargetView **ppResource) override;
  3255. STDMETHOD(SetRenderTargetArray)(_In_reads_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  3256. STDMETHOD(GetRenderTargetArray)(_Out_writes_(Count) ID3D11RenderTargetView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  3257. };
  3258. template<typename IBaseInterface>
  3259. _Use_decl_annotations_
  3260. HRESULT TRenderTargetViewVariable<IBaseInterface>::SetRenderTarget(ID3D11RenderTargetView *pResource)
  3261. {
  3262. HRESULT hr = S_OK;
  3263. #ifdef _DEBUG
  3264. static LPCSTR pFuncName = "ID3DX11EffectRenderTargetVariable::SetRenderTarget";
  3265. #endif
  3266. // Texture variables don't need to be dirtied.
  3267. SAFE_ADDREF(pResource);
  3268. SAFE_RELEASE(Data.pRenderTargetView->pRenderTargetView);
  3269. Data.pRenderTargetView->pRenderTargetView = pResource;
  3270. lExit:
  3271. return hr;
  3272. }
  3273. template<typename IBaseInterface>
  3274. _Use_decl_annotations_
  3275. HRESULT TRenderTargetViewVariable<IBaseInterface>::GetRenderTarget(ID3D11RenderTargetView **ppResource)
  3276. {
  3277. HRESULT hr = S_OK;
  3278. assert(Data.pRenderTargetView->pRenderTargetView != 0);
  3279. _Analysis_assume_(Data.pRenderTargetView->pRenderTargetView != 0);
  3280. *ppResource = Data.pRenderTargetView->pRenderTargetView;
  3281. SAFE_ADDREF(*ppResource);
  3282. lExit:
  3283. return hr;
  3284. }
  3285. template<typename IBaseInterface>
  3286. _Use_decl_annotations_
  3287. HRESULT TRenderTargetViewVariable<IBaseInterface>::SetRenderTargetArray(ID3D11RenderTargetView **ppResources, uint32_t Offset, uint32_t Count)
  3288. {
  3289. static LPCSTR pFuncName = "ID3DX11EffectRenderTargetVariable::SetRenderTargetArray";
  3290. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3291. // Texture variables don't need to be dirtied.
  3292. for (size_t i = 0; i < Count; ++ i)
  3293. {
  3294. SRenderTargetView *pResourceBlock = Data.pRenderTargetView + Offset + i;
  3295. SAFE_ADDREF(ppResources[i]);
  3296. SAFE_RELEASE(pResourceBlock->pRenderTargetView);
  3297. pResourceBlock->pRenderTargetView = ppResources[i];
  3298. }
  3299. lExit:
  3300. return hr;
  3301. }
  3302. template<typename IBaseInterface>
  3303. _Use_decl_annotations_
  3304. HRESULT TRenderTargetViewVariable<IBaseInterface>::GetRenderTargetArray(ID3D11RenderTargetView **ppResources, uint32_t Offset, uint32_t Count)
  3305. {
  3306. static LPCSTR pFuncName = "ID3DX11EffectRenderTargetVariable::GetRenderTargetArray";
  3307. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3308. for (size_t i = 0; i < Count; ++ i)
  3309. {
  3310. ppResources[i] = (Data.pRenderTargetView + Offset + i)->pRenderTargetView;
  3311. SAFE_ADDREF(ppResources[i]);
  3312. }
  3313. lExit:
  3314. return hr;
  3315. }
  3316. //////////////////////////////////////////////////////////////////////////
  3317. // ID3DX11EffectDepthStencilViewVariable (TDepthStencilViewVariable implementation)
  3318. //////////////////////////////////////////////////////////////////////////
  3319. template<typename IBaseInterface>
  3320. struct TDepthStencilViewVariable : public IBaseInterface
  3321. {
  3322. STDMETHOD(SetDepthStencil)(_In_ ID3D11DepthStencilView *pResource) override;
  3323. STDMETHOD(GetDepthStencil)(_Outptr_ ID3D11DepthStencilView **ppResource) override;
  3324. STDMETHOD(SetDepthStencilArray)(_In_reads_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  3325. STDMETHOD(GetDepthStencilArray)(_Out_writes_(Count) ID3D11DepthStencilView **ppResources, _In_ uint32_t Offset, _In_ uint32_t Count) override;
  3326. };
  3327. template<typename IBaseInterface>
  3328. _Use_decl_annotations_
  3329. HRESULT TDepthStencilViewVariable<IBaseInterface>::SetDepthStencil(ID3D11DepthStencilView *pResource)
  3330. {
  3331. HRESULT hr = S_OK;
  3332. #ifdef _DEBUG
  3333. static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::SetDepthStencil";
  3334. #endif
  3335. // Texture variables don't need to be dirtied.
  3336. SAFE_ADDREF(pResource);
  3337. SAFE_RELEASE(Data.pDepthStencilView->pDepthStencilView);
  3338. Data.pDepthStencilView->pDepthStencilView = pResource;
  3339. lExit:
  3340. return hr;
  3341. }
  3342. template<typename IBaseInterface>
  3343. _Use_decl_annotations_
  3344. HRESULT TDepthStencilViewVariable<IBaseInterface>::GetDepthStencil(ID3D11DepthStencilView **ppResource)
  3345. {
  3346. HRESULT hr = S_OK;
  3347. #ifdef _DEBUG
  3348. static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::GetDepthStencil";
  3349. VERIFYPARAMETER(ppResource);
  3350. #endif
  3351. assert(Data.pDepthStencilView->pDepthStencilView != 0);
  3352. _Analysis_assume_(Data.pDepthStencilView->pDepthStencilView != 0);
  3353. *ppResource = Data.pDepthStencilView->pDepthStencilView;
  3354. SAFE_ADDREF(*ppResource);
  3355. lExit:
  3356. return hr;
  3357. }
  3358. template<typename IBaseInterface>
  3359. _Use_decl_annotations_
  3360. HRESULT TDepthStencilViewVariable<IBaseInterface>::SetDepthStencilArray(ID3D11DepthStencilView **ppResources, uint32_t Offset, uint32_t Count)
  3361. {
  3362. static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::SetDepthStencilArray";
  3363. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3364. // Texture variables don't need to be dirtied.
  3365. for (size_t i = 0; i < Count; ++ i)
  3366. {
  3367. SDepthStencilView *pResourceBlock = Data.pDepthStencilView + Offset + i;
  3368. SAFE_ADDREF(ppResources[i]);
  3369. SAFE_RELEASE(pResourceBlock->pDepthStencilView);
  3370. pResourceBlock->pDepthStencilView = ppResources[i];
  3371. }
  3372. lExit:
  3373. return hr;
  3374. }
  3375. template<typename IBaseInterface>
  3376. _Use_decl_annotations_
  3377. HRESULT TDepthStencilViewVariable<IBaseInterface>::GetDepthStencilArray(ID3D11DepthStencilView **ppResources, uint32_t Offset, uint32_t Count)
  3378. {
  3379. static LPCSTR pFuncName = "ID3D11DepthStencilViewVariable::GetDepthStencilArray";
  3380. CHECK_OBJECT_ARRAY_BOUNDS(Offset, Count, ppResources);
  3381. for (size_t i = 0; i < Count; ++ i)
  3382. {
  3383. ppResources[i] = (Data.pDepthStencilView + Offset + i)->pDepthStencilView;
  3384. SAFE_ADDREF(ppResources[i]);
  3385. }
  3386. lExit:
  3387. return hr;
  3388. }
  3389. ////////////////////////////////////////////////////////////////////////////////
  3390. // ID3DX11EffectShaderVariable (TShaderVariable implementation)
  3391. ////////////////////////////////////////////////////////////////////////////////
  3392. template<typename IBaseInterface>
  3393. struct TShaderVariable : public IBaseInterface
  3394. {
  3395. STDMETHOD(GetShaderDesc)(_In_ uint32_t ShaderIndex, _Out_ D3DX11_EFFECT_SHADER_DESC *pDesc) override;
  3396. STDMETHOD(GetVertexShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11VertexShader **ppVS) override;
  3397. STDMETHOD(GetGeometryShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11GeometryShader **ppGS) override;
  3398. STDMETHOD(GetPixelShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11PixelShader **ppPS) override;
  3399. STDMETHOD(GetHullShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11HullShader **ppHS) override;
  3400. STDMETHOD(GetDomainShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11DomainShader **ppDS) override;
  3401. STDMETHOD(GetComputeShader)(_In_ uint32_t ShaderIndex, _Outptr_ ID3D11ComputeShader **ppCS) override;
  3402. STDMETHOD(GetInputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
  3403. STDMETHOD(GetOutputSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
  3404. STDMETHOD(GetPatchConstantSignatureElementDesc)(_In_ uint32_t ShaderIndex, _In_ uint32_t Element, _Out_ D3D11_SIGNATURE_PARAMETER_DESC *pDesc) override;
  3405. STDMETHOD_(bool, IsValid)();
  3406. };
  3407. template<typename IBaseInterface>
  3408. _Use_decl_annotations_
  3409. HRESULT TShaderVariable<IBaseInterface>::GetShaderDesc(uint32_t ShaderIndex, D3DX11_EFFECT_SHADER_DESC *pDesc)
  3410. {
  3411. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetShaderDesc";
  3412. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
  3413. hr = Data.pShader[ShaderIndex].GetShaderDesc(pDesc, false);
  3414. lExit:
  3415. return hr;
  3416. }
  3417. template<typename IBaseInterface>
  3418. _Use_decl_annotations_
  3419. HRESULT TShaderVariable<IBaseInterface>::GetVertexShader(uint32_t ShaderIndex, ID3D11VertexShader **ppVS)
  3420. {
  3421. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetVertexShader";
  3422. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppVS);
  3423. VH( Data.pShader[ShaderIndex].GetVertexShader(ppVS) );
  3424. lExit:
  3425. return hr;
  3426. }
  3427. template<typename IBaseInterface>
  3428. _Use_decl_annotations_
  3429. HRESULT TShaderVariable<IBaseInterface>::GetGeometryShader(uint32_t ShaderIndex, ID3D11GeometryShader **ppGS)
  3430. {
  3431. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetGeometryShader";
  3432. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppGS);
  3433. VH( Data.pShader[ShaderIndex].GetGeometryShader(ppGS) );
  3434. lExit:
  3435. return hr;
  3436. }
  3437. template<typename IBaseInterface>
  3438. _Use_decl_annotations_
  3439. HRESULT TShaderVariable<IBaseInterface>::GetPixelShader(uint32_t ShaderIndex, ID3D11PixelShader **ppPS)
  3440. {
  3441. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetPixelShader";
  3442. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppPS);
  3443. VH( Data.pShader[ShaderIndex].GetPixelShader(ppPS) );
  3444. lExit:
  3445. return hr;
  3446. }
  3447. template<typename IBaseInterface>
  3448. _Use_decl_annotations_
  3449. HRESULT TShaderVariable<IBaseInterface>::GetHullShader(uint32_t ShaderIndex, ID3D11HullShader **ppHS)
  3450. {
  3451. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetHullShader";
  3452. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppHS);
  3453. VH( Data.pShader[ShaderIndex].GetHullShader(ppHS) );
  3454. lExit:
  3455. return hr;
  3456. }
  3457. template<typename IBaseInterface>
  3458. _Use_decl_annotations_
  3459. HRESULT TShaderVariable<IBaseInterface>::GetDomainShader(uint32_t ShaderIndex, ID3D11DomainShader **ppDS)
  3460. {
  3461. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetDomainShader";
  3462. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppDS);
  3463. VH( Data.pShader[ShaderIndex].GetDomainShader(ppDS) );
  3464. lExit:
  3465. return hr;
  3466. }
  3467. template<typename IBaseInterface>
  3468. _Use_decl_annotations_
  3469. HRESULT TShaderVariable<IBaseInterface>::GetComputeShader(uint32_t ShaderIndex, ID3D11ComputeShader **ppCS)
  3470. {
  3471. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetComputeShader";
  3472. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, ppCS);
  3473. VH( Data.pShader[ShaderIndex].GetComputeShader(ppCS) );
  3474. lExit:
  3475. return hr;
  3476. }
  3477. template<typename IBaseInterface>
  3478. _Use_decl_annotations_
  3479. HRESULT TShaderVariable<IBaseInterface>::GetInputSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
  3480. {
  3481. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetInputSignatureElementDesc";
  3482. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
  3483. VH( Data.pShader[ShaderIndex].GetSignatureElementDesc(SShaderBlock::ST_Input, Element, pDesc) );
  3484. lExit:
  3485. return hr;
  3486. }
  3487. template<typename IBaseInterface>
  3488. _Use_decl_annotations_
  3489. HRESULT TShaderVariable<IBaseInterface>::GetOutputSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
  3490. {
  3491. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetOutputSignatureElementDesc";
  3492. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
  3493. VH( Data.pShader[ShaderIndex].GetSignatureElementDesc(SShaderBlock::ST_Output, Element, pDesc) );
  3494. lExit:
  3495. return hr;
  3496. }
  3497. template<typename IBaseInterface>
  3498. _Use_decl_annotations_
  3499. HRESULT TShaderVariable<IBaseInterface>::GetPatchConstantSignatureElementDesc(uint32_t ShaderIndex, uint32_t Element, D3D11_SIGNATURE_PARAMETER_DESC *pDesc)
  3500. {
  3501. static LPCSTR pFuncName = "ID3DX11EffectShaderVariable::GetPatchConstantSignatureElementDesc";
  3502. CHECK_OBJECT_SCALAR_BOUNDS(ShaderIndex, pDesc);
  3503. VH( Data.pShader[ShaderIndex].GetSignatureElementDesc(SShaderBlock::ST_PatchConstant, Element, pDesc) );
  3504. lExit:
  3505. return hr;
  3506. }
  3507. template<typename IBaseInterface>
  3508. bool TShaderVariable<IBaseInterface>::IsValid()
  3509. {
  3510. uint32_t numElements = IsArray()? pType->Elements : 1;
  3511. bool valid = true;
  3512. while( numElements > 0 && ( valid = Data.pShader[ numElements-1 ].IsValid ) )
  3513. numElements--;
  3514. return valid;
  3515. }
  3516. ////////////////////////////////////////////////////////////////////////////////
  3517. // ID3DX11EffectBlendVariable (TBlendVariable implementation)
  3518. ////////////////////////////////////////////////////////////////////////////////
  3519. template<typename IBaseInterface>
  3520. struct TBlendVariable : public IBaseInterface
  3521. {
  3522. public:
  3523. STDMETHOD(GetBlendState)(_In_ uint32_t Index, _Outptr_ ID3D11BlendState **ppState) override;
  3524. STDMETHOD(SetBlendState)(_In_ uint32_t Index, _In_ ID3D11BlendState *pState) override;
  3525. STDMETHOD(UndoSetBlendState)(_In_ uint32_t Index) override;
  3526. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_BLEND_DESC *pDesc) override;
  3527. STDMETHOD_(bool, IsValid)() override;
  3528. };
  3529. template<typename IBaseInterface>
  3530. _Use_decl_annotations_
  3531. HRESULT TBlendVariable<IBaseInterface>::GetBlendState(uint32_t Index, ID3D11BlendState **ppState)
  3532. {
  3533. static LPCSTR pFuncName = "ID3DX11EffectBlendVariable::GetBlendState";
  3534. CHECK_OBJECT_SCALAR_BOUNDS(Index, ppState);
  3535. assert(Data.pBlend[Index].pBlendObject != 0);
  3536. _Analysis_assume_(Data.pBlend[Index].pBlendObject != 0);
  3537. *ppState = Data.pBlend[Index].pBlendObject;
  3538. SAFE_ADDREF(*ppState);
  3539. lExit:
  3540. return hr;
  3541. }
  3542. template<typename IBaseInterface>
  3543. _Use_decl_annotations_
  3544. HRESULT TBlendVariable<IBaseInterface>::SetBlendState(uint32_t Index, ID3D11BlendState *pState)
  3545. {
  3546. static LPCSTR pFuncName = "ID3DX11EffectBlendState::SetBlendState";
  3547. CHECK_SCALAR_BOUNDS(Index);
  3548. if( !Data.pBlend[Index].IsUserManaged )
  3549. {
  3550. // Save original state object in case we UndoSet
  3551. assert( pMemberData[Index].Type == MDT_BlendState );
  3552. VB( pMemberData[Index].Data.pD3DEffectsManagedBlendState == nullptr );
  3553. pMemberData[Index].Data.pD3DEffectsManagedBlendState = Data.pBlend[Index].pBlendObject;
  3554. Data.pBlend[Index].pBlendObject = nullptr;
  3555. Data.pBlend[Index].IsUserManaged = true;
  3556. }
  3557. SAFE_ADDREF( pState );
  3558. SAFE_RELEASE( Data.pBlend[Index].pBlendObject );
  3559. Data.pBlend[Index].pBlendObject = pState;
  3560. Data.pBlend[Index].IsValid = true;
  3561. lExit:
  3562. return hr;
  3563. }
  3564. template<typename IBaseInterface>
  3565. _Use_decl_annotations_
  3566. HRESULT TBlendVariable<IBaseInterface>::UndoSetBlendState(uint32_t Index)
  3567. {
  3568. static LPCSTR pFuncName = "ID3DX11EffectBlendState::UndoSetBlendState";
  3569. CHECK_SCALAR_BOUNDS(Index);
  3570. if( !Data.pBlend[Index].IsUserManaged )
  3571. {
  3572. return S_FALSE;
  3573. }
  3574. // Revert to original state object
  3575. SAFE_RELEASE( Data.pBlend[Index].pBlendObject );
  3576. Data.pBlend[Index].pBlendObject = pMemberData[Index].Data.pD3DEffectsManagedBlendState;
  3577. pMemberData[Index].Data.pD3DEffectsManagedBlendState = nullptr;
  3578. Data.pBlend[Index].IsUserManaged = false;
  3579. lExit:
  3580. return hr;
  3581. }
  3582. template<typename IBaseInterface>
  3583. _Use_decl_annotations_
  3584. HRESULT TBlendVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_BLEND_DESC *pBlendDesc)
  3585. {
  3586. static LPCSTR pFuncName = "ID3DX11EffectBlendVariable::GetBackingStore";
  3587. CHECK_OBJECT_SCALAR_BOUNDS(Index, pBlendDesc);
  3588. if( Data.pBlend[Index].IsUserManaged )
  3589. {
  3590. if( Data.pBlend[Index].pBlendObject )
  3591. {
  3592. Data.pBlend[Index].pBlendObject->GetDesc( pBlendDesc );
  3593. }
  3594. else
  3595. {
  3596. *pBlendDesc = CD3D11_BLEND_DESC( D3D11_DEFAULT );
  3597. }
  3598. }
  3599. else
  3600. {
  3601. SBlendBlock *pBlock = Data.pBlend + Index;
  3602. if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
  3603. {
  3604. pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
  3605. }
  3606. memcpy( pBlendDesc, &pBlock->BackingStore, sizeof(D3D11_BLEND_DESC) );
  3607. }
  3608. lExit:
  3609. return hr;
  3610. }
  3611. template<typename IBaseInterface>
  3612. bool TBlendVariable<IBaseInterface>::IsValid()
  3613. {
  3614. uint32_t numElements = IsArray()? pType->Elements : 1;
  3615. bool valid = true;
  3616. while( numElements > 0 && ( valid = Data.pBlend[ numElements-1 ].IsValid ) )
  3617. numElements--;
  3618. return valid;
  3619. }
  3620. ////////////////////////////////////////////////////////////////////////////////
  3621. // ID3DX11EffectDepthStencilVariable (TDepthStencilVariable implementation)
  3622. ////////////////////////////////////////////////////////////////////////////////
  3623. template<typename IBaseInterface>
  3624. struct TDepthStencilVariable : public IBaseInterface
  3625. {
  3626. public:
  3627. STDMETHOD(GetDepthStencilState)(_In_ uint32_t Index, _Outptr_ ID3D11DepthStencilState **ppState) override;
  3628. STDMETHOD(SetDepthStencilState)(_In_ uint32_t Index, _In_ ID3D11DepthStencilState *pState) override;
  3629. STDMETHOD(UndoSetDepthStencilState)(_In_ uint32_t Index) override;
  3630. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_DEPTH_STENCIL_DESC *pDesc) override;
  3631. STDMETHOD_(bool, IsValid)() override;
  3632. };
  3633. template<typename IBaseInterface>
  3634. _Use_decl_annotations_
  3635. HRESULT TDepthStencilVariable<IBaseInterface>::GetDepthStencilState(uint32_t Index, ID3D11DepthStencilState **ppState)
  3636. {
  3637. static LPCSTR pFuncName = "ID3DX11EffectDepthStencilVariable::GetDepthStencilState";
  3638. CHECK_OBJECT_SCALAR_BOUNDS(Index, ppState);
  3639. assert(Data.pDepthStencil[Index].pDSObject != 0);
  3640. _Analysis_assume_(Data.pDepthStencil[Index].pDSObject != 0);
  3641. *ppState = Data.pDepthStencil[Index].pDSObject;
  3642. SAFE_ADDREF(*ppState);
  3643. lExit:
  3644. return hr;
  3645. }
  3646. template<typename IBaseInterface>
  3647. _Use_decl_annotations_
  3648. HRESULT TDepthStencilVariable<IBaseInterface>::SetDepthStencilState(uint32_t Index, ID3D11DepthStencilState *pState)
  3649. {
  3650. static LPCSTR pFuncName = "ID3DX11EffectDepthStencilState::SetDepthStencilState";
  3651. CHECK_SCALAR_BOUNDS(Index);
  3652. if( !Data.pDepthStencil[Index].IsUserManaged )
  3653. {
  3654. // Save original state object in case we UndoSet
  3655. assert( pMemberData[Index].Type == MDT_DepthStencilState );
  3656. VB( pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState == nullptr );
  3657. pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState = Data.pDepthStencil[Index].pDSObject;
  3658. Data.pDepthStencil[Index].pDSObject = nullptr;
  3659. Data.pDepthStencil[Index].IsUserManaged = true;
  3660. }
  3661. SAFE_ADDREF( pState );
  3662. SAFE_RELEASE( Data.pDepthStencil[Index].pDSObject );
  3663. Data.pDepthStencil[Index].pDSObject = pState;
  3664. Data.pDepthStencil[Index].IsValid = true;
  3665. lExit:
  3666. return hr;
  3667. }
  3668. template<typename IBaseInterface>
  3669. HRESULT TDepthStencilVariable<IBaseInterface>::UndoSetDepthStencilState(_In_ uint32_t Index)
  3670. {
  3671. static LPCSTR pFuncName = "ID3DX11EffectDepthStencilState::UndoSetDepthStencilState";
  3672. CHECK_SCALAR_BOUNDS(Index);
  3673. if( !Data.pDepthStencil[Index].IsUserManaged )
  3674. {
  3675. return S_FALSE;
  3676. }
  3677. // Revert to original state object
  3678. SAFE_RELEASE( Data.pDepthStencil[Index].pDSObject );
  3679. Data.pDepthStencil[Index].pDSObject = pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState;
  3680. pMemberData[Index].Data.pD3DEffectsManagedDepthStencilState = nullptr;
  3681. Data.pDepthStencil[Index].IsUserManaged = false;
  3682. lExit:
  3683. return hr;
  3684. }
  3685. template<typename IBaseInterface>
  3686. _Use_decl_annotations_
  3687. HRESULT TDepthStencilVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_DEPTH_STENCIL_DESC *pDepthStencilDesc)
  3688. {
  3689. static LPCSTR pFuncName = "ID3DX11EffectDepthStencilVariable::GetBackingStore";
  3690. CHECK_OBJECT_SCALAR_BOUNDS(Index, pDepthStencilDesc);
  3691. if( Data.pDepthStencil[Index].IsUserManaged )
  3692. {
  3693. if( Data.pDepthStencil[Index].pDSObject )
  3694. {
  3695. Data.pDepthStencil[Index].pDSObject->GetDesc( pDepthStencilDesc );
  3696. }
  3697. else
  3698. {
  3699. *pDepthStencilDesc = CD3D11_DEPTH_STENCIL_DESC( D3D11_DEFAULT );
  3700. }
  3701. }
  3702. else
  3703. {
  3704. SDepthStencilBlock *pBlock = Data.pDepthStencil + Index;
  3705. if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
  3706. {
  3707. pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
  3708. }
  3709. memcpy(pDepthStencilDesc, &pBlock->BackingStore, sizeof(D3D11_DEPTH_STENCIL_DESC));
  3710. }
  3711. lExit:
  3712. return hr;
  3713. }
  3714. template<typename IBaseInterface>
  3715. bool TDepthStencilVariable<IBaseInterface>::IsValid()
  3716. {
  3717. uint32_t numElements = IsArray()? pType->Elements : 1;
  3718. bool valid = true;
  3719. while( numElements > 0 && ( valid = Data.pDepthStencil[ numElements-1 ].IsValid ) )
  3720. numElements--;
  3721. return valid;
  3722. }
  3723. ////////////////////////////////////////////////////////////////////////////////
  3724. // ID3DX11EffectRasterizerVariable (TRasterizerVariable implementation)
  3725. ////////////////////////////////////////////////////////////////////////////////
  3726. template<typename IBaseInterface>
  3727. struct TRasterizerVariable : public IBaseInterface
  3728. {
  3729. public:
  3730. STDMETHOD(GetRasterizerState)(_In_ uint32_t Index, _Outptr_ ID3D11RasterizerState **ppState) override;
  3731. STDMETHOD(SetRasterizerState)(_In_ uint32_t Index, _In_ ID3D11RasterizerState *pState) override;
  3732. STDMETHOD(UndoSetRasterizerState)(_In_ uint32_t Index) override;
  3733. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_RASTERIZER_DESC *pDesc) override;
  3734. STDMETHOD_(bool, IsValid)() override;
  3735. };
  3736. template<typename IBaseInterface>
  3737. _Use_decl_annotations_
  3738. HRESULT TRasterizerVariable<IBaseInterface>::GetRasterizerState(uint32_t Index, ID3D11RasterizerState **ppState)
  3739. {
  3740. static LPCSTR pFuncName = "ID3DX11EffectRasterizerVariable::GetRasterizerState";
  3741. CHECK_OBJECT_SCALAR_BOUNDS(Index, ppState);
  3742. assert(Data.pRasterizer[Index].pRasterizerObject != 0);
  3743. _Analysis_assume_(Data.pRasterizer[Index].pRasterizerObject != 0);
  3744. *ppState = Data.pRasterizer[Index].pRasterizerObject;
  3745. SAFE_ADDREF(*ppState);
  3746. lExit:
  3747. return hr;
  3748. }
  3749. template<typename IBaseInterface>
  3750. _Use_decl_annotations_
  3751. HRESULT TRasterizerVariable<IBaseInterface>::SetRasterizerState(uint32_t Index, ID3D11RasterizerState *pState)
  3752. {
  3753. static LPCSTR pFuncName = "ID3DX11EffectRasterizerState::SetRasterizerState";
  3754. CHECK_SCALAR_BOUNDS(Index);
  3755. if( !Data.pRasterizer[Index].IsUserManaged )
  3756. {
  3757. // Save original state object in case we UndoSet
  3758. assert( pMemberData[Index].Type == MDT_RasterizerState );
  3759. VB( pMemberData[Index].Data.pD3DEffectsManagedRasterizerState == nullptr );
  3760. pMemberData[Index].Data.pD3DEffectsManagedRasterizerState = Data.pRasterizer[Index].pRasterizerObject;
  3761. Data.pRasterizer[Index].pRasterizerObject = nullptr;
  3762. Data.pRasterizer[Index].IsUserManaged = true;
  3763. }
  3764. SAFE_ADDREF( pState );
  3765. SAFE_RELEASE( Data.pRasterizer[Index].pRasterizerObject );
  3766. Data.pRasterizer[Index].pRasterizerObject = pState;
  3767. Data.pRasterizer[Index].IsValid = true;
  3768. lExit:
  3769. return hr;
  3770. }
  3771. template<typename IBaseInterface>
  3772. _Use_decl_annotations_
  3773. HRESULT TRasterizerVariable<IBaseInterface>::UndoSetRasterizerState(uint32_t Index)
  3774. {
  3775. static LPCSTR pFuncName = "ID3DX11EffectRasterizerState::UndoSetRasterizerState";
  3776. CHECK_SCALAR_BOUNDS(Index);
  3777. if( !Data.pRasterizer[Index].IsUserManaged )
  3778. {
  3779. return S_FALSE;
  3780. }
  3781. // Revert to original state object
  3782. SAFE_RELEASE( Data.pRasterizer[Index].pRasterizerObject );
  3783. Data.pRasterizer[Index].pRasterizerObject = pMemberData[Index].Data.pD3DEffectsManagedRasterizerState;
  3784. pMemberData[Index].Data.pD3DEffectsManagedRasterizerState = nullptr;
  3785. Data.pRasterizer[Index].IsUserManaged = false;
  3786. lExit:
  3787. return hr;
  3788. }
  3789. template<typename IBaseInterface>
  3790. _Use_decl_annotations_
  3791. HRESULT TRasterizerVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_RASTERIZER_DESC *pRasterizerDesc)
  3792. {
  3793. static LPCSTR pFuncName = "ID3DX11EffectRasterizerVariable::GetBackingStore";
  3794. CHECK_OBJECT_SCALAR_BOUNDS(Index, pRasterizerDesc);
  3795. if( Data.pRasterizer[Index].IsUserManaged )
  3796. {
  3797. if( Data.pRasterizer[Index].pRasterizerObject )
  3798. {
  3799. Data.pRasterizer[Index].pRasterizerObject->GetDesc( pRasterizerDesc );
  3800. }
  3801. else
  3802. {
  3803. *pRasterizerDesc = CD3D11_RASTERIZER_DESC( D3D11_DEFAULT );
  3804. }
  3805. }
  3806. else
  3807. {
  3808. SRasterizerBlock *pBlock = Data.pRasterizer + Index;
  3809. if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
  3810. {
  3811. pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
  3812. }
  3813. memcpy(pRasterizerDesc, &pBlock->BackingStore, sizeof(D3D11_RASTERIZER_DESC));
  3814. }
  3815. lExit:
  3816. return hr;
  3817. }
  3818. template<typename IBaseInterface>
  3819. bool TRasterizerVariable<IBaseInterface>::IsValid()
  3820. {
  3821. uint32_t numElements = IsArray()? pType->Elements : 1;
  3822. bool valid = true;
  3823. while( numElements > 0 && ( valid = Data.pRasterizer[ numElements-1 ].IsValid ) )
  3824. numElements--;
  3825. return valid;
  3826. }
  3827. ////////////////////////////////////////////////////////////////////////////////
  3828. // ID3DX11EffectSamplerVariable (TSamplerVariable implementation)
  3829. ////////////////////////////////////////////////////////////////////////////////
  3830. template<typename IBaseInterface>
  3831. struct TSamplerVariable : public IBaseInterface
  3832. {
  3833. public:
  3834. STDMETHOD(GetSampler)(_In_ uint32_t Index, _Outptr_ ID3D11SamplerState **ppSampler) override;
  3835. STDMETHOD(SetSampler)(_In_ uint32_t Index, _In_ ID3D11SamplerState *pSampler) override;
  3836. STDMETHOD(UndoSetSampler)(_In_ uint32_t Index) override;
  3837. STDMETHOD(GetBackingStore)(_In_ uint32_t Index, _Out_ D3D11_SAMPLER_DESC *pDesc) override;
  3838. };
  3839. template<typename IBaseInterface>
  3840. _Use_decl_annotations_
  3841. HRESULT TSamplerVariable<IBaseInterface>::GetSampler(uint32_t Index, ID3D11SamplerState **ppSampler)
  3842. {
  3843. static LPCSTR pFuncName = "ID3DX11EffectSamplerVariable::GetSampler";
  3844. CHECK_OBJECT_SCALAR_BOUNDS(Index, ppSampler);
  3845. _Analysis_assume_( Data.pSampler[Index].pD3DObject != 0 );
  3846. *ppSampler = Data.pSampler[Index].pD3DObject;
  3847. SAFE_ADDREF(*ppSampler);
  3848. lExit:
  3849. return hr;
  3850. }
  3851. template<typename IBaseInterface>
  3852. _Use_decl_annotations_
  3853. HRESULT TSamplerVariable<IBaseInterface>::SetSampler(uint32_t Index, ID3D11SamplerState *pSampler)
  3854. {
  3855. static LPCSTR pFuncName = "ID3DX11EffectSamplerState::SetSampler";
  3856. CHECK_SCALAR_BOUNDS(Index);
  3857. // Replace all references to the old shader block with this one
  3858. GetEffect()->ReplaceSamplerReference(&Data.pSampler[Index], pSampler);
  3859. if( !Data.pSampler[Index].IsUserManaged )
  3860. {
  3861. // Save original state object in case we UndoSet
  3862. assert( pMemberData[Index].Type == MDT_SamplerState );
  3863. VB( pMemberData[Index].Data.pD3DEffectsManagedSamplerState == nullptr );
  3864. pMemberData[Index].Data.pD3DEffectsManagedSamplerState = Data.pSampler[Index].pD3DObject;
  3865. Data.pSampler[Index].pD3DObject = nullptr;
  3866. Data.pSampler[Index].IsUserManaged = true;
  3867. }
  3868. SAFE_ADDREF( pSampler );
  3869. SAFE_RELEASE( Data.pSampler[Index].pD3DObject );
  3870. Data.pSampler[Index].pD3DObject = pSampler;
  3871. lExit:
  3872. return hr;
  3873. }
  3874. template<typename IBaseInterface>
  3875. HRESULT TSamplerVariable<IBaseInterface>::UndoSetSampler(_In_ uint32_t Index)
  3876. {
  3877. static LPCSTR pFuncName = "ID3DX11EffectSamplerState::UndoSetSampler";
  3878. CHECK_SCALAR_BOUNDS(Index);
  3879. if( !Data.pSampler[Index].IsUserManaged )
  3880. {
  3881. return S_FALSE;
  3882. }
  3883. // Replace all references to the old shader block with this one
  3884. GetEffect()->ReplaceSamplerReference(&Data.pSampler[Index], pMemberData[Index].Data.pD3DEffectsManagedSamplerState);
  3885. // Revert to original state object
  3886. SAFE_RELEASE( Data.pSampler[Index].pD3DObject );
  3887. Data.pSampler[Index].pD3DObject = pMemberData[Index].Data.pD3DEffectsManagedSamplerState;
  3888. pMemberData[Index].Data.pD3DEffectsManagedSamplerState = nullptr;
  3889. Data.pSampler[Index].IsUserManaged = false;
  3890. lExit:
  3891. return hr;
  3892. }
  3893. template<typename IBaseInterface>
  3894. _Use_decl_annotations_
  3895. HRESULT TSamplerVariable<IBaseInterface>::GetBackingStore(uint32_t Index, D3D11_SAMPLER_DESC *pDesc)
  3896. {
  3897. static LPCSTR pFuncName = "ID3DX11EffectSamplerVariable::GetBackingStore";
  3898. CHECK_OBJECT_SCALAR_BOUNDS(Index, pDesc);
  3899. if( Data.pSampler[Index].IsUserManaged )
  3900. {
  3901. if( Data.pSampler[Index].pD3DObject )
  3902. {
  3903. Data.pSampler[Index].pD3DObject->GetDesc( pDesc );
  3904. }
  3905. else
  3906. {
  3907. *pDesc = CD3D11_SAMPLER_DESC( D3D11_DEFAULT );
  3908. }
  3909. }
  3910. else
  3911. {
  3912. SSamplerBlock *pBlock = Data.pSampler + Index;
  3913. if (pBlock->ApplyAssignments(GetTopLevelEntity()->pEffect))
  3914. {
  3915. pBlock->pAssignments[0].LastRecomputedTime = 0; // Force a recreate of this block the next time ApplyRenderStateBlock is called
  3916. }
  3917. memcpy(pDesc, &pBlock->BackingStore.SamplerDesc, sizeof(D3D11_SAMPLER_DESC));
  3918. }
  3919. lExit:
  3920. return hr;
  3921. }
  3922. ////////////////////////////////////////////////////////////////////////////////
  3923. // TUncastableVariable
  3924. ////////////////////////////////////////////////////////////////////////////////
  3925. template<typename IBaseInterface>
  3926. struct TUncastableVariable : public IBaseInterface
  3927. {
  3928. STDMETHOD_(ID3DX11EffectScalarVariable*, AsScalar)() override;
  3929. STDMETHOD_(ID3DX11EffectVectorVariable*, AsVector)() override;
  3930. STDMETHOD_(ID3DX11EffectMatrixVariable*, AsMatrix)() override;
  3931. STDMETHOD_(ID3DX11EffectStringVariable*, AsString)() override;
  3932. STDMETHOD_(ID3DX11EffectClassInstanceVariable*, AsClassInstance)() override;
  3933. STDMETHOD_(ID3DX11EffectInterfaceVariable*, AsInterface)() override;
  3934. STDMETHOD_(ID3DX11EffectShaderResourceVariable*, AsShaderResource)() override;
  3935. STDMETHOD_(ID3DX11EffectUnorderedAccessViewVariable*, AsUnorderedAccessView)() override;
  3936. STDMETHOD_(ID3DX11EffectRenderTargetViewVariable*, AsRenderTargetView)() override;
  3937. STDMETHOD_(ID3DX11EffectDepthStencilViewVariable*, AsDepthStencilView)() override;
  3938. STDMETHOD_(ID3DX11EffectConstantBuffer*, AsConstantBuffer)() override;
  3939. STDMETHOD_(ID3DX11EffectShaderVariable*, AsShader)() override;
  3940. STDMETHOD_(ID3DX11EffectBlendVariable*, AsBlend)() override;
  3941. STDMETHOD_(ID3DX11EffectDepthStencilVariable*, AsDepthStencil)() override;
  3942. STDMETHOD_(ID3DX11EffectRasterizerVariable*, AsRasterizer)() override;
  3943. STDMETHOD_(ID3DX11EffectSamplerVariable*, AsSampler)() override;
  3944. };
  3945. template<typename IBaseInterface>
  3946. ID3DX11EffectScalarVariable * TUncastableVariable<IBaseInterface>::AsScalar()
  3947. {
  3948. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsScalar";
  3949. DPF(0, "%s: Invalid typecast", pFuncName);
  3950. return &g_InvalidScalarVariable;
  3951. }
  3952. template<typename IBaseInterface>
  3953. ID3DX11EffectVectorVariable * TUncastableVariable<IBaseInterface>::AsVector()
  3954. {
  3955. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsVector";
  3956. DPF(0, "%s: Invalid typecast", pFuncName);
  3957. return &g_InvalidVectorVariable;
  3958. }
  3959. template<typename IBaseInterface>
  3960. ID3DX11EffectMatrixVariable * TUncastableVariable<IBaseInterface>::AsMatrix()
  3961. {
  3962. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsMatrix";
  3963. DPF(0, "%s: Invalid typecast", pFuncName);
  3964. return &g_InvalidMatrixVariable;
  3965. }
  3966. template<typename IBaseInterface>
  3967. ID3DX11EffectStringVariable * TUncastableVariable<IBaseInterface>::AsString()
  3968. {
  3969. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsString";
  3970. DPF(0, "%s: Invalid typecast", pFuncName);
  3971. return &g_InvalidStringVariable;
  3972. }
  3973. template<typename IBaseClassInstance>
  3974. ID3DX11EffectClassInstanceVariable * TUncastableVariable<IBaseClassInstance>::AsClassInstance()
  3975. {
  3976. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsClassInstance";
  3977. DPF(0, "%s: Invalid typecast", pFuncName);
  3978. return &g_InvalidClassInstanceVariable;
  3979. }
  3980. template<typename IBaseInterface>
  3981. ID3DX11EffectInterfaceVariable * TUncastableVariable<IBaseInterface>::AsInterface()
  3982. {
  3983. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsInterface";
  3984. DPF(0, "%s: Invalid typecast", pFuncName);
  3985. return &g_InvalidInterfaceVariable;
  3986. }
  3987. template<typename IBaseInterface>
  3988. ID3DX11EffectShaderResourceVariable * TUncastableVariable<IBaseInterface>::AsShaderResource()
  3989. {
  3990. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShaderResource";
  3991. DPF(0, "%s: Invalid typecast", pFuncName);
  3992. return &g_InvalidShaderResourceVariable;
  3993. }
  3994. template<typename IBaseInterface>
  3995. ID3DX11EffectUnorderedAccessViewVariable * TUncastableVariable<IBaseInterface>::AsUnorderedAccessView()
  3996. {
  3997. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsUnorderedAccessView";
  3998. DPF(0, "%s: Invalid typecast", pFuncName);
  3999. return &g_InvalidUnorderedAccessViewVariable;
  4000. }
  4001. template<typename IBaseInterface>
  4002. ID3DX11EffectRenderTargetViewVariable * TUncastableVariable<IBaseInterface>::AsRenderTargetView()
  4003. {
  4004. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRenderTargetView";
  4005. DPF(0, "%s: Invalid typecast", pFuncName);
  4006. return &g_InvalidRenderTargetViewVariable;
  4007. }
  4008. template<typename IBaseInterface>
  4009. ID3DX11EffectDepthStencilViewVariable * TUncastableVariable<IBaseInterface>::AsDepthStencilView()
  4010. {
  4011. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencilView";
  4012. DPF(0, "%s: Invalid typecast", pFuncName);
  4013. return &g_InvalidDepthStencilViewVariable;
  4014. }
  4015. template<typename IBaseInterface>
  4016. ID3DX11EffectConstantBuffer * TUncastableVariable<IBaseInterface>::AsConstantBuffer()
  4017. {
  4018. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsConstantBuffer";
  4019. DPF(0, "%s: Invalid typecast", pFuncName);
  4020. return &g_InvalidConstantBuffer;
  4021. }
  4022. template<typename IBaseInterface>
  4023. ID3DX11EffectShaderVariable * TUncastableVariable<IBaseInterface>::AsShader()
  4024. {
  4025. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsShader";
  4026. DPF(0, "%s: Invalid typecast", pFuncName);
  4027. return &g_InvalidShaderVariable;
  4028. }
  4029. template<typename IBaseInterface>
  4030. ID3DX11EffectBlendVariable * TUncastableVariable<IBaseInterface>::AsBlend()
  4031. {
  4032. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsBlend";
  4033. DPF(0, "%s: Invalid typecast", pFuncName);
  4034. return &g_InvalidBlendVariable;
  4035. }
  4036. template<typename IBaseInterface>
  4037. ID3DX11EffectDepthStencilVariable * TUncastableVariable<IBaseInterface>::AsDepthStencil()
  4038. {
  4039. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsDepthStencil";
  4040. DPF(0, "%s: Invalid typecast", pFuncName);
  4041. return &g_InvalidDepthStencilVariable;
  4042. }
  4043. template<typename IBaseInterface>
  4044. ID3DX11EffectRasterizerVariable * TUncastableVariable<IBaseInterface>::AsRasterizer()
  4045. {
  4046. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsRasterizer";
  4047. DPF(0, "%s: Invalid typecast", pFuncName);
  4048. return &g_InvalidRasterizerVariable;
  4049. }
  4050. template<typename IBaseInterface>
  4051. ID3DX11EffectSamplerVariable * TUncastableVariable<IBaseInterface>::AsSampler()
  4052. {
  4053. static LPCSTR pFuncName = "ID3DX11EffectVariable::AsSampler";
  4054. DPF(0, "%s: Invalid typecast", pFuncName);
  4055. return &g_InvalidSamplerVariable;
  4056. }
  4057. ////////////////////////////////////////////////////////////////////////////////
  4058. // Macros to instantiate the myriad templates
  4059. ////////////////////////////////////////////////////////////////////////////////
  4060. // generates a global variable, annotation, global variable member, and annotation member of each struct type
  4061. #define GenerateReflectionClasses(Type, BaseInterface) \
  4062. struct S##Type##GlobalVariable : public T##Type##Variable<TGlobalVariable<BaseInterface>, false> { IUNKNOWN_IMP(S##Type##GlobalVariable, BaseInterface, ID3DX11EffectVariable); }; \
  4063. struct S##Type##Annotation : public T##Type##Variable<TAnnotation<BaseInterface>, true> { IUNKNOWN_IMP(S##Type##Annotation, BaseInterface, ID3DX11EffectVariable);}; \
  4064. struct S##Type##GlobalVariableMember : public T##Type##Variable<TVariable<TMember<BaseInterface> >, false> { IUNKNOWN_IMP(S##Type##GlobalVariableMember, BaseInterface, ID3DX11EffectVariable); }; \
  4065. struct S##Type##AnnotationMember : public T##Type##Variable<TVariable<TMember<BaseInterface> >, true> { IUNKNOWN_IMP(S##Type##AnnotationMember, BaseInterface, ID3DX11EffectVariable); };
  4066. #define GenerateVectorReflectionClasses(Type, BaseType, BaseInterface) \
  4067. struct S##Type##GlobalVariable : public TVectorVariable<TGlobalVariable<BaseInterface>, false, BaseType> { IUNKNOWN_IMP(S##Type##GlobalVariable, BaseInterface, ID3DX11EffectVariable); }; \
  4068. struct S##Type##Annotation : public TVectorVariable<TAnnotation<BaseInterface>, true, BaseType> { IUNKNOWN_IMP(S##Type##Annotation, BaseInterface, ID3DX11EffectVariable);}; \
  4069. struct S##Type##GlobalVariableMember : public TVectorVariable<TVariable<TMember<BaseInterface> >, false, BaseType> { IUNKNOWN_IMP(S##Type##GlobalVariableMember, BaseInterface, ID3DX11EffectVariable);}; \
  4070. struct S##Type##AnnotationMember : public TVectorVariable<TVariable<TMember<BaseInterface> >, true, BaseType> { IUNKNOWN_IMP(S##Type##AnnotationMember, BaseInterface, ID3DX11EffectVariable);};
  4071. #define GenerateReflectionGlobalOnlyClasses(Type) \
  4072. struct S##Type##GlobalVariable : public T##Type##Variable<TGlobalVariable<ID3DX11Effect##Type##Variable> > { IUNKNOWN_IMP(S##Type##GlobalVariable, ID3DX11Effect##Type##Variable, ID3DX11EffectVariable); }; \
  4073. struct S##Type##GlobalVariableMember : public T##Type##Variable<TVariable<TMember<ID3DX11Effect##Type##Variable> > > { IUNKNOWN_IMP(S##Type##GlobalVariableMember, ID3DX11Effect##Type##Variable, ID3DX11EffectVariable); }; \
  4074. GenerateReflectionClasses(Numeric, ID3DX11EffectVariable);
  4075. GenerateReflectionClasses(FloatScalar, ID3DX11EffectScalarVariable);
  4076. GenerateReflectionClasses(IntScalar, ID3DX11EffectScalarVariable);
  4077. GenerateReflectionClasses(BoolScalar, ID3DX11EffectScalarVariable);
  4078. GenerateVectorReflectionClasses(FloatVector, ETVT_Float, ID3DX11EffectVectorVariable);
  4079. GenerateVectorReflectionClasses(BoolVector, ETVT_Bool, ID3DX11EffectVectorVariable);
  4080. GenerateVectorReflectionClasses(IntVector, ETVT_Int, ID3DX11EffectVectorVariable);
  4081. GenerateReflectionClasses(Matrix, ID3DX11EffectMatrixVariable);
  4082. GenerateReflectionClasses(String, ID3DX11EffectStringVariable);
  4083. GenerateReflectionGlobalOnlyClasses(ClassInstance);
  4084. GenerateReflectionGlobalOnlyClasses(Interface);
  4085. GenerateReflectionGlobalOnlyClasses(ShaderResource);
  4086. GenerateReflectionGlobalOnlyClasses(UnorderedAccessView);
  4087. GenerateReflectionGlobalOnlyClasses(RenderTargetView);
  4088. GenerateReflectionGlobalOnlyClasses(DepthStencilView);
  4089. GenerateReflectionGlobalOnlyClasses(Shader);
  4090. GenerateReflectionGlobalOnlyClasses(Blend);
  4091. GenerateReflectionGlobalOnlyClasses(DepthStencil);
  4092. GenerateReflectionGlobalOnlyClasses(Rasterizer);
  4093. GenerateReflectionGlobalOnlyClasses(Sampler);
  4094. // Optimized matrix classes
  4095. struct SMatrix4x4ColumnMajorGlobalVariable : public TMatrix4x4Variable<TGlobalVariable<ID3DX11EffectMatrixVariable>, true> { IUNKNOWN_IMP(SMatrix4x4ColumnMajorGlobalVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
  4096. struct SMatrix4x4RowMajorGlobalVariable : public TMatrix4x4Variable<TGlobalVariable<ID3DX11EffectMatrixVariable>, false> { IUNKNOWN_IMP(SMatrix4x4RowMajorGlobalVariable, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
  4097. struct SMatrix4x4ColumnMajorGlobalVariableMember : public TMatrix4x4Variable<TVariable<TMember<ID3DX11EffectMatrixVariable> >, true> { IUNKNOWN_IMP(SMatrix4x4ColumnMajorGlobalVariableMember, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
  4098. struct SMatrix4x4RowMajorGlobalVariableMember : public TMatrix4x4Variable<TVariable<TMember<ID3DX11EffectMatrixVariable> >, false> { IUNKNOWN_IMP(SMatrix4x4RowMajorGlobalVariableMember, ID3DX11EffectMatrixVariable, ID3DX11EffectVariable); };
  4099. // Optimized vector classes
  4100. struct SFloatVector4GlobalVariable : public TVector4Variable<TGlobalVariable<ID3DX11EffectVectorVariable> > { IUNKNOWN_IMP(SFloatVector4GlobalVariable, ID3DX11EffectVectorVariable, ID3DX11EffectVariable); };
  4101. struct SFloatVector4GlobalVariableMember : public TVector4Variable<TVariable<TMember<ID3DX11EffectVectorVariable> > > { IUNKNOWN_IMP(SFloatVector4GlobalVariableMember, ID3DX11EffectVectorVariable, ID3DX11EffectVariable); };
  4102. // These 3 classes should never be used directly
  4103. // The "base" global variable struct (all global variables should be the same size in bytes,
  4104. // but we pick this as the default).
  4105. struct SGlobalVariable : public TGlobalVariable<ID3DX11EffectVariable>
  4106. {
  4107. };
  4108. // The "base" annotation struct (all annotations should be the same size in bytes,
  4109. // but we pick this as the default).
  4110. struct SAnnotation : public TAnnotation<ID3DX11EffectVariable>
  4111. {
  4112. };
  4113. // The "base" variable member struct (all annotation/global variable members should be the
  4114. // same size in bytes, but we pick this as the default).
  4115. struct SMember : public TVariable<TMember<ID3DX11EffectVariable> >
  4116. {
  4117. };
  4118. // creates a new variable of the appropriate polymorphic type where pVar was
  4119. HRESULT PlacementNewVariable(_In_ void *pVar, _In_ SType *pType, _In_ bool IsAnnotation);
  4120. SMember * CreateNewMember(_In_ SType *pType, _In_ bool IsAnnotation);
  4121. #pragma warning(pop)