123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579 |
- ///////////////////////////////////////////////////////////////////////////////
- // //
- // ExecutionTest.cpp //
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- // This file is distributed under the University of Illinois Open Source //
- // License. See LICENSE.TXT for details. //
- // //
- // These tests run by executing compiled programs, and thus involve more //
- // moving parts, like the runtime and drivers. //
- // //
- ///////////////////////////////////////////////////////////////////////////////
- #include <algorithm>
- #include <memory>
- #include <vector>
- #include <string>
- #include <map>
- #include <unordered_set>
- #include <strstream>
- #include <iomanip>
- #include "CompilationResult.h"
- #include "HLSLTestData.h"
- #include <Shlwapi.h>
- #include <atlcoll.h>
- #include <locale>
- #include <algorithm>
- #undef _read
- #include "WexTestClass.h"
- #include "HlslTestUtils.h"
- #include "DxcTestUtils.h"
- #include "dxc/Support/Global.h"
- #include "dxc/Support/WinIncludes.h"
- #include "dxc/Support/FileIOHelper.h"
- #include "dxc/Support/Unicode.h"
- //
- // d3d12.h and dxgi1_4.h are included in the Windows 10 SDK
- // https://msdn.microsoft.com/en-us/library/windows/desktop/dn899120(v=vs.85).aspx
- // https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk
- //
- #include <d3d12.h>
- #include <dxgi1_4.h>
- #include <DXGIDebug.h>
- #include <D3dx12.h>
- #include <DirectXMath.h>
- #include <strsafe.h>
- #include <d3dcompiler.h>
- #include <wincodec.h>
- #include "ShaderOpTest.h"
- #pragma comment(lib, "d3dcompiler.lib")
- #pragma comment(lib, "windowscodecs.lib")
- #pragma comment(lib, "dxguid.lib")
- // A more recent Windows SDK than currently required is needed for these.
- typedef HRESULT(WINAPI *D3D12EnableExperimentalFeaturesFn)(
- UINT NumFeatures,
- __in_ecount(NumFeatures) const IID* pIIDs,
- __in_ecount_opt(NumFeatures) void* pConfigurationStructs,
- __in_ecount_opt(NumFeatures) UINT* pConfigurationStructSizes);
- static const GUID D3D12ExperimentalShaderModelsID = { /* 76f5573e-f13a-40f5-b297-81ce9e18933f */
- 0x76f5573e,
- 0xf13a,
- 0x40f5,
- { 0xb2, 0x97, 0x81, 0xce, 0x9e, 0x18, 0x93, 0x3f }
- };
- using namespace DirectX;
- using namespace hlsl_test;
- template <typename TSequence, typename T>
- static bool contains(TSequence s, const T &val) {
- return std::cend(s) != std::find(std::cbegin(s), std::cend(s), val);
- }
- template <typename InputIterator, typename T>
- static bool contains(InputIterator b, InputIterator e, const T &val) {
- return e != std::find(b, e, val);
- }
- static HRESULT EnableExperimentalShaderModels() {
- HMODULE hRuntime = LoadLibraryW(L"d3d12.dll");
- if (hRuntime == NULL) {
- return HRESULT_FROM_WIN32(GetLastError());
- }
- D3D12EnableExperimentalFeaturesFn pD3D12EnableExperimentalFeatures =
- (D3D12EnableExperimentalFeaturesFn)GetProcAddress(hRuntime, "D3D12EnableExperimentalFeatures");
- if (pD3D12EnableExperimentalFeatures == nullptr) {
- FreeLibrary(hRuntime);
- return HRESULT_FROM_WIN32(GetLastError());
- }
- HRESULT hr = pD3D12EnableExperimentalFeatures(1, &D3D12ExperimentalShaderModelsID, nullptr, nullptr);
- FreeLibrary(hRuntime);
- return hr;
- }
- static HRESULT ReportLiveObjects() {
- CComPtr<IDXGIDebug1> pDebug;
- IFR(DXGIGetDebugInterface1(0, IID_PPV_ARGS(&pDebug)));
- IFR(pDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_ALL));
- return S_OK;
- }
- static void WriteInfoQueueMessages(void *pStrCtx, st::OutputStringFn pOutputStrFn, ID3D12InfoQueue *pInfoQueue) {
- bool allMessagesOK = true;
- UINT64 count = pInfoQueue->GetNumStoredMessages();
- CAtlArray<BYTE> message;
- for (UINT64 i = 0; i < count; ++i) {
- // 'GetMessageA' rather than 'GetMessage' is an artifact of user32 headers.
- SIZE_T msgLen = 0;
- if (FAILED(pInfoQueue->GetMessageA(i, nullptr, &msgLen))) {
- allMessagesOK = false;
- continue;
- }
- if (message.GetCount() < msgLen) {
- if (!message.SetCount(msgLen)) {
- allMessagesOK = false;
- continue;
- }
- }
- D3D12_MESSAGE *pMessage = (D3D12_MESSAGE *)message.GetData();
- if (FAILED(pInfoQueue->GetMessageA(i, pMessage, &msgLen))) {
- allMessagesOK = false;
- continue;
- }
- CA2W msgW(pMessage->pDescription, CP_ACP);
- pOutputStrFn(pStrCtx, msgW.m_psz);
- pOutputStrFn(pStrCtx, L"\r\n");
- }
- if (!allMessagesOK) {
- pOutputStrFn(pStrCtx, L"Failed to retrieve some messages.\r\n");
- }
- }
- class CComContext {
- private:
- bool m_init;
- public:
- CComContext() : m_init(false) {}
- ~CComContext() { Dispose(); }
- void Dispose() { if (!m_init) return; m_init = false; CoUninitialize(); }
- HRESULT Init() { HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED); if (SUCCEEDED(hr)) { m_init = true; } return hr; }
- };
- static void SavePixelsToFile(LPCVOID pPixels, DXGI_FORMAT format, UINT32 m_width, UINT32 m_height, LPCWSTR pFileName) {
- CComContext ctx;
- CComPtr<IWICImagingFactory> pFactory;
- CComPtr<IWICBitmap> pBitmap;
- CComPtr<IWICBitmapEncoder> pEncoder;
- CComPtr<IWICBitmapFrameEncode> pFrameEncode;
- CComPtr<hlsl::AbstractMemoryStream> pStream;
- CComPtr<IMalloc> pMalloc;
- struct PF {
- DXGI_FORMAT Format;
- GUID PixelFormat;
- UINT32 PixelSize;
- bool operator==(DXGI_FORMAT F) const {
- return F == Format;
- }
- } Vals[] = {
- // Add more pixel format mappings as needed.
- { DXGI_FORMAT_R8G8B8A8_UNORM, GUID_WICPixelFormat32bppRGBA, 4 }
- };
- PF *pFormat = std::find(Vals, Vals + _countof(Vals), format);
- VERIFY_SUCCEEDED(ctx.Init());
- VERIFY_SUCCEEDED(CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&pFactory));
- VERIFY_SUCCEEDED(CoGetMalloc(1, &pMalloc));
- VERIFY_SUCCEEDED(hlsl::CreateMemoryStream(pMalloc, &pStream));
- VERIFY_ARE_NOT_EQUAL(pFormat, Vals + _countof(Vals));
- VERIFY_SUCCEEDED(pFactory->CreateBitmapFromMemory(m_width, m_height, pFormat->PixelFormat, m_width * pFormat->PixelSize, m_width * m_height * pFormat->PixelSize, (BYTE *)pPixels, &pBitmap));
- VERIFY_SUCCEEDED(pFactory->CreateEncoder(GUID_ContainerFormatBmp, nullptr, &pEncoder));
- VERIFY_SUCCEEDED(pEncoder->Initialize(pStream, WICBitmapEncoderNoCache));
- VERIFY_SUCCEEDED(pEncoder->CreateNewFrame(&pFrameEncode, nullptr));
- VERIFY_SUCCEEDED(pFrameEncode->Initialize(nullptr));
- VERIFY_SUCCEEDED(pFrameEncode->WriteSource(pBitmap, nullptr));
- VERIFY_SUCCEEDED(pFrameEncode->Commit());
- VERIFY_SUCCEEDED(pEncoder->Commit());
- hlsl::WriteBinaryFile(pFileName, pStream->GetPtr(), pStream->GetPtrSize());
- }
- class ExecutionTest {
- public:
- // By default, ignore these tests, which require a recent build to run properly.
- BEGIN_TEST_CLASS(ExecutionTest)
- TEST_CLASS_PROPERTY(L"Ignore", L"true")
- TEST_METHOD_PROPERTY(L"Priority", L"0")
- END_TEST_CLASS()
- TEST_CLASS_SETUP(ExecutionTestClassSetup)
- TEST_METHOD(BasicComputeTest);
- TEST_METHOD(BasicTriangleTest);
- TEST_METHOD(BasicTriangleOpTest);
- TEST_METHOD(OutOfBoundsTest);
- TEST_METHOD(SaturateTest);
- TEST_METHOD(SignTest);
- TEST_METHOD(Int64Test);
- TEST_METHOD(WaveIntrinsicsTest);
- TEST_METHOD(WaveIntrinsicsInPSTest);
- // TAEF data-driven tests.
- BEGIN_TEST_METHOD(UnaryFloatOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryFloatOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(BinaryFloatOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryFloatOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(TertiaryFloatOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryFloatOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(UnaryIntOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryIntOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(BinaryIntOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryIntOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(TertiaryIntOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryIntOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(UnaryUintOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#UnaryUintOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(BinaryUintOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#BinaryUintOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(TertiaryUintOpTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#TertiaryUintOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(DotTest)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#DotOpTable")
- END_TEST_METHOD()
- BEGIN_TEST_METHOD(Msad4Test)
- TEST_METHOD_PROPERTY(L"DataSource", L"Table:ShaderOpArithTable.xml#Msad4Table")
- END_TEST_METHOD()
- dxc::DxcDllSupport m_support;
- bool m_ExperimentalModeEnabled = false;
- static const float ClearColor[4];
- bool UseDxbc() {
- return GetTestParamBool(L"DXBC");
- }
- bool UseDebugIfaces() {
- return true;
- }
- bool SaveImages() {
- return GetTestParamBool(L"SaveImages");
- }
- void CompileFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
- VERIFY_SUCCEEDED(m_support.Initialize());
- CComPtr<IDxcCompiler> pCompiler;
- CComPtr<IDxcLibrary> pLibrary;
- CComPtr<IDxcBlobEncoding> pTextBlob;
- CComPtr<IDxcOperationResult> pResult;
- HRESULT resultCode;
- VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcCompiler, &pCompiler));
- VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
- VERIFY_SUCCEEDED(pLibrary->CreateBlobWithEncodingFromPinned((LPBYTE)pText, strlen(pText), CP_UTF8, &pTextBlob));
- VERIFY_SUCCEEDED(pCompiler->Compile(pTextBlob, L"hlsl.hlsl", pEntryPoint, pTargetProfile, nullptr, 0, nullptr, 0, nullptr, &pResult));
- VERIFY_SUCCEEDED(pResult->GetStatus(&resultCode));
- if (FAILED(resultCode)) {
- CComPtr<IDxcBlobEncoding> errors;
- VERIFY_SUCCEEDED(pResult->GetErrorBuffer(&errors));
- LogCommentFmt(L"Failed to compile shader: %s", BlobToUtf16(errors).data());
- }
- VERIFY_SUCCEEDED(resultCode);
- VERIFY_SUCCEEDED(pResult->GetResult((IDxcBlob **)ppBlob));
- }
- void CreateComputeCommandQueue(ID3D12Device *pDevice, LPCWSTR pName, ID3D12CommandQueue **ppCommandQueue) {
- D3D12_COMMAND_QUEUE_DESC queueDesc = {};
- queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
- queueDesc.Type = D3D12_COMMAND_LIST_TYPE_COMPUTE;
- VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
- VERIFY_SUCCEEDED((*ppCommandQueue)->SetName(pName));
- }
- void CreateComputePSO(ID3D12Device *pDevice, ID3D12RootSignature *pRootSignature, LPCSTR pShader, ID3D12PipelineState **ppComputeState) {
- CComPtr<ID3DBlob> pComputeShader;
- // Load and compile shaders.
- if (UseDxbc()) {
- DXBCFromText(pShader, L"main", L"cs_6_0", &pComputeShader);
- }
- else {
- CompileFromText(pShader, L"main", L"cs_6_0", &pComputeShader);
- }
- // Describe and create the compute pipeline state object (PSO).
- D3D12_COMPUTE_PIPELINE_STATE_DESC computePsoDesc = {};
- computePsoDesc.pRootSignature = pRootSignature;
- computePsoDesc.CS = CD3DX12_SHADER_BYTECODE(pComputeShader);
- VERIFY_SUCCEEDED(pDevice->CreateComputePipelineState(&computePsoDesc, IID_PPV_ARGS(ppComputeState)));
- }
- bool CreateDevice(_COM_Outptr_ ID3D12Device **ppDevice) {
- const D3D_FEATURE_LEVEL FeatureLevelRequired = D3D_FEATURE_LEVEL_11_0;
- CComPtr<IDXGIFactory4> factory;
- CComPtr<ID3D12Device> pDevice;
- *ppDevice = nullptr;
- VERIFY_SUCCEEDED(CreateDXGIFactory1(IID_PPV_ARGS(&factory)));
- if (GetTestParamUseWARP(true)) {
- CComPtr<IDXGIAdapter> warpAdapter;
- VERIFY_SUCCEEDED(factory->EnumWarpAdapter(IID_PPV_ARGS(&warpAdapter)));
- HRESULT createHR = D3D12CreateDevice(warpAdapter, FeatureLevelRequired,
- IID_PPV_ARGS(&pDevice));
- if (FAILED(createHR)) {
- LogCommentFmt(L"The available version of WARP does not support d3d12.");
- WEX::Logging::Log::Result(WEX::Logging::TestResults::Blocked);
- return false;
- }
- } else {
- CComPtr<IDXGIAdapter1> hardwareAdapter;
- WEX::Common::String AdapterValue;
- IFT(WEX::TestExecution::RuntimeParameters::TryGetValue(L"Adapter",
- AdapterValue));
- GetHardwareAdapter(factory, AdapterValue, &hardwareAdapter);
- if (hardwareAdapter == nullptr) {
- WEX::Logging::Log::Error(
- L"Unable to find hardware adapter with D3D12 support.");
- return false;
- }
- VERIFY_SUCCEEDED(D3D12CreateDevice(hardwareAdapter, FeatureLevelRequired,
- IID_PPV_ARGS(&pDevice)));
- DXGI_ADAPTER_DESC1 AdapterDesc;
- VERIFY_SUCCEEDED(hardwareAdapter->GetDesc1(&AdapterDesc));
- LogCommentFmt(L"Using Adapter: %s", AdapterDesc.Description);
- }
- if (pDevice == nullptr)
- return false;
- if (!UseDxbc()) {
- // Check for DXIL support.
- // This is defined in d3d.h for Windows 10 Anniversary Edition SDK, but we only
- // require the Windows 10 SDK.
- typedef enum D3D_SHADER_MODEL {
- D3D_SHADER_MODEL_5_1 = 0x51,
- D3D_SHADER_MODEL_6_0 = 0x60
- } D3D_SHADER_MODEL;
- typedef struct D3D12_FEATURE_DATA_SHADER_MODEL {
- _Inout_ D3D_SHADER_MODEL HighestShaderModel;
- } D3D12_FEATURE_DATA_SHADER_MODEL;
- const UINT D3D12_FEATURE_SHADER_MODEL = 7;
- D3D12_FEATURE_DATA_SHADER_MODEL SMData;
- SMData.HighestShaderModel = D3D_SHADER_MODEL_6_0;
- VERIFY_SUCCEEDED(pDevice->CheckFeatureSupport(
- (D3D12_FEATURE)D3D12_FEATURE_SHADER_MODEL, &SMData, sizeof(SMData)));
- if (SMData.HighestShaderModel != D3D_SHADER_MODEL_6_0) {
- LogCommentFmt(L"The selected device does not support "
- L"shader model 6 (required for DXIL).");
- WEX::Logging::Log::Result(WEX::Logging::TestResults::Blocked);
- return false;
- }
- }
- if (UseDebugIfaces()) {
- CComPtr<ID3D12InfoQueue> pInfoQueue;
- if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
- pInfoQueue->SetMuteDebugOutput(FALSE);
- }
- }
- *ppDevice = pDevice.Detach();
- return true;
- }
- void CreateGraphicsCommandQueue(ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue) {
- D3D12_COMMAND_QUEUE_DESC queueDesc = {};
- queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
- queueDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;;
- VERIFY_SUCCEEDED(pDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(ppCommandQueue)));
- }
- void CreateGraphicsCommandQueueAndList(
- ID3D12Device *pDevice, ID3D12CommandQueue **ppCommandQueue,
- ID3D12CommandAllocator **ppAllocator,
- ID3D12GraphicsCommandList **ppCommandList, ID3D12PipelineState *pPSO) {
- CreateGraphicsCommandQueue(pDevice, ppCommandQueue);
- VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(
- D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(ppAllocator)));
- VERIFY_SUCCEEDED(pDevice->CreateCommandList(
- 0, D3D12_COMMAND_LIST_TYPE_DIRECT, *ppAllocator, pPSO,
- IID_PPV_ARGS(ppCommandList)));
- }
- void CreateGraphicsPSO(ID3D12Device *pDevice,
- D3D12_INPUT_LAYOUT_DESC *pInputLayout,
- ID3D12RootSignature *pRootSignature, LPCSTR pShaders,
- ID3D12PipelineState **ppPSO) {
- CComPtr<ID3DBlob> vertexShader;
- CComPtr<ID3DBlob> pixelShader;
- if (UseDxbc()) {
- DXBCFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
- DXBCFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
- } else {
- CompileFromText(pShaders, L"VSMain", L"vs_6_0", &vertexShader);
- CompileFromText(pShaders, L"PSMain", L"ps_6_0", &pixelShader);
- }
- // Describe and create the graphics pipeline state object (PSO).
- D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};
- psoDesc.InputLayout = *pInputLayout;
- psoDesc.pRootSignature = pRootSignature;
- psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader);
- psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader);
- psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
- psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
- psoDesc.DepthStencilState.DepthEnable = FALSE;
- psoDesc.DepthStencilState.StencilEnable = FALSE;
- psoDesc.SampleMask = UINT_MAX;
- psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
- psoDesc.NumRenderTargets = 1;
- psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
- psoDesc.SampleDesc.Count = 1;
- VERIFY_SUCCEEDED(
- pDevice->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(ppPSO)));
- }
- void CreateRenderTargetAndReadback(ID3D12Device *pDevice,
- ID3D12DescriptorHeap *pHeap, UINT width,
- UINT height,
- ID3D12Resource **ppRenderTarget,
- ID3D12Resource **ppBuffer) {
- const DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
- const size_t formatElementSize = 4;
- CComPtr<ID3D12Resource> pRenderTarget;
- CComPtr<ID3D12Resource> pBuffer;
- CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(
- pHeap->GetCPUDescriptorHandleForHeapStart());
- CD3DX12_HEAP_PROPERTIES rtHeap(D3D12_HEAP_TYPE_DEFAULT);
- CD3DX12_RESOURCE_DESC rtDesc(
- CD3DX12_RESOURCE_DESC::Tex2D(format, width, height));
- CD3DX12_CLEAR_VALUE rtClearVal(format, ClearColor);
- rtDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
- VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
- &rtHeap, D3D12_HEAP_FLAG_NONE, &rtDesc, D3D12_RESOURCE_STATE_COPY_DEST,
- &rtClearVal, IID_PPV_ARGS(&pRenderTarget)));
- pDevice->CreateRenderTargetView(pRenderTarget, nullptr, rtvHandle);
- // rtvHandle.Offset(1, rtvDescriptorSize); // Not needed for a single
- // resource.
- CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
- CD3DX12_RESOURCE_DESC readDesc(
- CD3DX12_RESOURCE_DESC::Buffer(width * height * formatElementSize));
- VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
- &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
- D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pBuffer)));
- *ppRenderTarget = pRenderTarget.Detach();
- *ppBuffer = pBuffer.Detach();
- }
- void CreateRootSignatureFromDesc(ID3D12Device *pDevice,
- const D3D12_ROOT_SIGNATURE_DESC *pDesc,
- ID3D12RootSignature **pRootSig) {
- CComPtr<ID3DBlob> signature;
- CComPtr<ID3DBlob> error;
- VERIFY_SUCCEEDED(D3D12SerializeRootSignature(pDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
- VERIFY_SUCCEEDED(pDevice->CreateRootSignature(
- 0, signature->GetBufferPointer(), signature->GetBufferSize(),
- IID_PPV_ARGS(pRootSig)));
- }
- void CreateRtvDescriptorHeap(ID3D12Device *pDevice, UINT numDescriptors,
- ID3D12DescriptorHeap **pRtvHeap, UINT *rtvDescriptorSize) {
- D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc = {};
- rtvHeapDesc.NumDescriptors = numDescriptors;
- rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
- rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
- VERIFY_SUCCEEDED(
- pDevice->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(pRtvHeap)));
- if (rtvDescriptorSize != nullptr) {
- *rtvDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(
- D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
- }
- }
- void CreateTestUavs(ID3D12Device *pDevice,
- ID3D12GraphicsCommandList *pCommandList, LPCVOID values,
- UINT32 valueSizeInBytes, ID3D12Resource **ppUavResource,
- ID3D12Resource **ppReadBuffer,
- ID3D12Resource **ppUploadResource) {
- CComPtr<ID3D12Resource> pUavResource;
- CComPtr<ID3D12Resource> pReadBuffer;
- CComPtr<ID3D12Resource> pUploadResource;
- D3D12_SUBRESOURCE_DATA transferData;
- D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);
- D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);
- D3D12_RESOURCE_DESC bufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
- D3D12_RESOURCE_DESC uploadBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes);
- CD3DX12_HEAP_PROPERTIES readHeap(D3D12_HEAP_TYPE_READBACK);
- CD3DX12_RESOURCE_DESC readDesc(CD3DX12_RESOURCE_DESC::Buffer(valueSizeInBytes));
- VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
- &defaultHeapProperties,
- D3D12_HEAP_FLAG_NONE,
- &bufferDesc,
- D3D12_RESOURCE_STATE_COPY_DEST,
- nullptr,
- IID_PPV_ARGS(&pUavResource)));
- VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
- &uploadHeapProperties,
- D3D12_HEAP_FLAG_NONE,
- &uploadBufferDesc,
- D3D12_RESOURCE_STATE_GENERIC_READ,
- nullptr,
- IID_PPV_ARGS(&pUploadResource)));
- VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
- &readHeap, D3D12_HEAP_FLAG_NONE, &readDesc,
- D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&pReadBuffer)));
- transferData.pData = values;
- transferData.RowPitch = valueSizeInBytes;
- transferData.SlicePitch = transferData.RowPitch;
- UpdateSubresources<1>(pCommandList, pUavResource.p, pUploadResource.p, 0, 0, 1, &transferData);
- RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS);
- *ppUavResource = pUavResource.Detach();
- *ppReadBuffer = pReadBuffer.Detach();
- *ppUploadResource = pUploadResource.Detach();
- }
- template <typename TVertex, int len>
- void CreateVertexBuffer(ID3D12Device *pDevice, TVertex(&vertices)[len],
- ID3D12Resource **ppVertexBuffer,
- D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView) {
- size_t vertexBufferSize = sizeof(vertices);
- CComPtr<ID3D12Resource> pVertexBuffer;
- CD3DX12_HEAP_PROPERTIES heapProps(D3D12_HEAP_TYPE_UPLOAD);
- CD3DX12_RESOURCE_DESC bufferDesc(
- CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize));
- VERIFY_SUCCEEDED(pDevice->CreateCommittedResource(
- &heapProps, D3D12_HEAP_FLAG_NONE, &bufferDesc,
- D3D12_RESOURCE_STATE_GENERIC_READ, nullptr,
- IID_PPV_ARGS(&pVertexBuffer)));
- UINT8 *pVertexDataBegin;
- CD3DX12_RANGE readRange(0, 0);
- VERIFY_SUCCEEDED(pVertexBuffer->Map(
- 0, &readRange, reinterpret_cast<void **>(&pVertexDataBegin)));
- memcpy(pVertexDataBegin, vertices, vertexBufferSize);
- pVertexBuffer->Unmap(0, nullptr);
- // Initialize the vertex buffer view.
- pVertexBufferView->BufferLocation = pVertexBuffer->GetGPUVirtualAddress();
- pVertexBufferView->StrideInBytes = sizeof(TVertex);
- pVertexBufferView->SizeInBytes = vertexBufferSize;
- *ppVertexBuffer = pVertexBuffer.Detach();
- }
- // Requires Anniversary Edition headers, so simplifying things for current setup.
- const UINT D3D12_FEATURE_D3D12_OPTIONS1 = 8;
- struct D3D12_FEATURE_DATA_D3D12_OPTIONS1 {
- BOOL WaveOps;
- UINT WaveLaneCountMin;
- UINT WaveLaneCountMax;
- UINT TotalLaneCount;
- BOOL ExpandedComputeResourceStates;
- BOOL Int64ShaderOps;
- };
- bool DoesDeviceSupportInt64(ID3D12Device *pDevice) {
- D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
- if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
- return false;
- return O.Int64ShaderOps != FALSE;
- }
- bool DoesDeviceSupportWaveOps(ID3D12Device *pDevice) {
- D3D12_FEATURE_DATA_D3D12_OPTIONS1 O;
- if (FAILED(pDevice->CheckFeatureSupport((D3D12_FEATURE)D3D12_FEATURE_D3D12_OPTIONS1, &O, sizeof(O))))
- return false;
- return O.WaveOps != FALSE;
- }
- void DXBCFromText(LPCSTR pText, LPCWSTR pEntryPoint, LPCWSTR pTargetProfile, ID3DBlob **ppBlob) {
- CW2A pEntryPointA(pEntryPoint, CP_UTF8);
- CW2A pTargetProfileA(pTargetProfile, CP_UTF8);
- CComPtr<ID3DBlob> pErrors;
- D3D_SHADER_MACRO d3dMacro[2];
- ZeroMemory(d3dMacro, sizeof(d3dMacro));
- d3dMacro[0].Definition = "1";
- d3dMacro[0].Name = "USING_DXBC";
- HRESULT hr = D3DCompile(pText, strlen(pText), "hlsl.hlsl", d3dMacro, nullptr, pEntryPointA, pTargetProfileA, 0, 0, ppBlob, &pErrors);
- if (pErrors != nullptr) {
- CA2W errors((char *)pErrors->GetBufferPointer(), CP_ACP);
- LogCommentFmt(L"Compilation failure: %s", errors.m_szBuffer);
- }
- VERIFY_SUCCEEDED(hr);
- }
- HRESULT EnableDebugLayer() {
- // The debug layer does net yet validate DXIL programs that require rewriting,
- // but basic logging should work properly.
- HRESULT hr = S_FALSE;
- if (UseDebugIfaces()) {
- CComPtr<ID3D12Debug> debugController;
- hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debugController));
- if (SUCCEEDED(hr)) {
- debugController->EnableDebugLayer();
- hr = S_OK;
- }
- }
- return hr;
- }
- HRESULT EnableExperimentalMode() {
- if (m_ExperimentalModeEnabled) {
- return S_OK;
- }
- if (!GetTestParamBool(L"ExperimentalShaders")) {
- return S_FALSE;
- }
- HRESULT hr = EnableExperimentalShaderModels();
- if (SUCCEEDED(hr)) {
- m_ExperimentalModeEnabled = true;
- }
- return hr;
- }
- struct FenceObj {
- HANDLE m_fenceEvent = NULL;
- CComPtr<ID3D12Fence> m_fence;
- UINT64 m_fenceValue;
- ~FenceObj() {
- if (m_fenceEvent) CloseHandle(m_fenceEvent);
- }
- };
- void InitFenceObj(ID3D12Device *pDevice, FenceObj *pObj) {
- pObj->m_fenceValue = 1;
- VERIFY_SUCCEEDED(pDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE,
- IID_PPV_ARGS(&pObj->m_fence)));
- // Create an event handle to use for frame synchronization.
- pObj->m_fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
- if (pObj->m_fenceEvent == nullptr) {
- VERIFY_SUCCEEDED(HRESULT_FROM_WIN32(GetLastError()));
- }
- }
- void ReadHlslDataIntoNewStream(LPCWSTR relativePath, IStream **ppStream) {
- VERIFY_SUCCEEDED(m_support.Initialize());
- CComPtr<IDxcLibrary> pLibrary;
- CComPtr<IDxcBlobEncoding> pBlob;
- CComPtr<IStream> pStream;
- std::wstring path = GetPathToHlslDataFile(relativePath);
- VERIFY_SUCCEEDED(m_support.CreateInstance(CLSID_DxcLibrary, &pLibrary));
- VERIFY_SUCCEEDED(pLibrary->CreateBlobFromFile(path.c_str(), nullptr, &pBlob));
- VERIFY_SUCCEEDED(pLibrary->CreateStreamFromBlobReadOnly(pBlob, &pStream));
- *ppStream = pStream.Detach();
- }
- void RecordRenderAndReadback(ID3D12GraphicsCommandList *pList,
- ID3D12DescriptorHeap *pRtvHeap,
- UINT rtvDescriptorSize,
- UINT instanceCount,
- D3D12_VERTEX_BUFFER_VIEW *pVertexBufferView,
- ID3D12RootSignature *pRootSig,
- ID3D12Resource *pRenderTarget,
- ID3D12Resource *pReadBuffer) {
- D3D12_RESOURCE_DESC rtDesc = pRenderTarget->GetDesc();
- D3D12_VIEWPORT viewport;
- D3D12_RECT scissorRect;
- memset(&viewport, 0, sizeof(viewport));
- viewport.Height = rtDesc.Height;
- viewport.Width = rtDesc.Width;
- viewport.MaxDepth = 1.0f;
- memset(&scissorRect, 0, sizeof(scissorRect));
- scissorRect.right = rtDesc.Width;
- scissorRect.bottom = rtDesc.Height;
- if (pRootSig != nullptr) {
- pList->SetGraphicsRootSignature(pRootSig);
- }
- pList->RSSetViewports(1, &viewport);
- pList->RSSetScissorRects(1, &scissorRect);
- // Indicate that the buffer will be used as a render target.
- RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_RENDER_TARGET);
- CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHandle(pRtvHeap->GetCPUDescriptorHandleForHeapStart(), 0, rtvDescriptorSize);
- pList->OMSetRenderTargets(1, &rtvHandle, FALSE, nullptr);
- pList->ClearRenderTargetView(rtvHandle, ClearColor, 0, nullptr);
- pList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- pList->IASetVertexBuffers(0, 1, pVertexBufferView);
- pList->DrawInstanced(3, instanceCount, 0, 0);
- // Transition to copy source and copy into read-back buffer.
- RecordTransitionBarrier(pList, pRenderTarget, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE);
- // Copy into read-back buffer.
- UINT rowPitch = rtDesc.Width * 4;
- if (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT)
- rowPitch += D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - (rowPitch % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
- D3D12_PLACED_SUBRESOURCE_FOOTPRINT Footprint;
- Footprint.Offset = 0;
- Footprint.Footprint = CD3DX12_SUBRESOURCE_FOOTPRINT(DXGI_FORMAT_R8G8B8A8_UNORM, rtDesc.Width, rtDesc.Height, 1, rowPitch);
- CD3DX12_TEXTURE_COPY_LOCATION DstLoc(pReadBuffer, Footprint);
- CD3DX12_TEXTURE_COPY_LOCATION SrcLoc(pRenderTarget, 0);
- pList->CopyTextureRegion(&DstLoc, 0, 0, 0, &SrcLoc, nullptr);
- }
- void RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR shader, std::vector<uint32_t> &values);
- void SetDescriptorHeap(ID3D12GraphicsCommandList *pCommandList, ID3D12DescriptorHeap *pHeap) {
- ID3D12DescriptorHeap *const pHeaps[1] = { pHeap };
- pCommandList->SetDescriptorHeaps(1, pHeaps);
- }
- void WaitForSignal(ID3D12CommandQueue *pCQ, FenceObj &FO) {
- ::WaitForSignal(pCQ, FO.m_fence, FO.m_fenceEvent, FO.m_fenceValue++);
- }
- };
- const float ExecutionTest::ClearColor[4] = { 0.0f, 0.2f, 0.4f, 1.0f };
- #define WAVE_INTRINSIC_DXBC_GUARD \
- "#ifdef USING_DXBC\r\n" \
- "uint WaveGetLaneIndex() { return 1; }\r\n" \
- "uint WaveReadLaneFirst(uint u) { return u; }\r\n" \
- "bool WaveIsFirstLane() { return true; }\r\n" \
- "uint WaveGetLaneCount() { return 1; }\r\n" \
- "uint WaveReadLaneAt(uint n, uint u) { return u; }\r\n" \
- "bool WaveActiveAnyTrue(bool b) { return b; }\r\n" \
- "bool WaveActiveAllTrue(bool b) { return false; }\r\n" \
- "uint WaveActiveAllEqual(uint u) { return u; }\r\n" \
- "uint4 WaveActiveBallot(bool b) { return 1; }\r\n" \
- "uint WaveActiveCountBits(uint u) { return 1; }\r\n" \
- "uint WaveActiveSum(uint u) { return 1; }\r\n" \
- "uint WaveActiveProduct(uint u) { return 1; }\r\n" \
- "uint WaveActiveBitAnd(uint u) { return 1; }\r\n" \
- "uint WaveActiveBitOr(uint u) { return 1; }\r\n" \
- "uint WaveActiveBitXor(uint u) { return 1; }\r\n" \
- "uint WaveActiveMin(uint u) { return 1; }\r\n" \
- "uint WaveActiveMax(uint u) { return 1; }\r\n" \
- "uint WavePrefixCountBits(uint u) { return 1; }\r\n" \
- "uint WavePrefixSum(uint u) { return 1; }\r\n" \
- "uint WavePrefixProduct(uint u) { return 1; }\r\n" \
- "uint QuadReadLaneAt(uint a, uint u) { return 1; }\r\n" \
- "uint QuadReadAcrossX(uint u) { return 1; }\r\n" \
- "uint QuadReadAcrossY(uint u) { return 1; }\r\n" \
- "uint QuadReadAcrossDiagonal(uint u) { return 1; }\r\n" \
- "#endif\r\n"
- static void SetupComputeValuePattern(std::vector<uint32_t> &values, size_t count) {
- values.resize(count); // one element per dispatch group, in bytes
- for (size_t i = 0; i < count; ++i) {
- values[i] = i;
- }
- }
- bool ExecutionTest::ExecutionTestClassSetup() {
- HRESULT hr = EnableExperimentalMode();
- if (FAILED(hr)) {
- LogCommentFmt(L"Unable to enable shader experimental mode - 0x%08x.", hr);
- }
- else if (hr == S_FALSE) {
- LogCommentFmt(L"Experimental mode not enabled.");
- }
- else {
- LogCommentFmt(L"Experimental mode enabled.");
- }
- hr = EnableDebugLayer();
- if (FAILED(hr)) {
- LogCommentFmt(L"Unable to enable debug layer - 0x%08x.", hr);
- }
- else {
- LogCommentFmt(L"Debug layer enabled.");
- }
- return true;
- }
- void ExecutionTest::RunRWByteBufferComputeTest(ID3D12Device *pDevice, LPCSTR pShader, std::vector<uint32_t> &values) {
- static const int DispatchGroupX = 1;
- static const int DispatchGroupY = 1;
- static const int DispatchGroupZ = 1;
- CComPtr<ID3D12GraphicsCommandList> pCommandList;
- CComPtr<ID3D12CommandQueue> pCommandQueue;
- CComPtr<ID3D12DescriptorHeap> pUavHeap;
- CComPtr<ID3D12CommandAllocator> pCommandAllocator;
- UINT uavDescriptorSize;
- FenceObj FO;
- const size_t valueSizeInBytes = values.size() * sizeof(uint32_t);
- CreateComputeCommandQueue(pDevice, L"RunRWByteBufferComputeTest Command Queue", &pCommandQueue);
- InitFenceObj(pDevice, &FO);
- // Describe and create a UAV descriptor heap.
- D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
- heapDesc.NumDescriptors = 1;
- heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
- heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
- VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
- uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
- // Create root signature.
- CComPtr<ID3D12RootSignature> pRootSignature;
- {
- CD3DX12_DESCRIPTOR_RANGE ranges[1];
- ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
- CD3DX12_ROOT_PARAMETER rootParameters[1];
- rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
- CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
- rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
- CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
- }
- // Create pipeline state object.
- CComPtr<ID3D12PipelineState> pComputeState;
- CreateComputePSO(pDevice, pRootSignature, pShader, &pComputeState);
- // Create a command allocator and list for compute.
- VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
- VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
- pCommandList->SetName(L"ExecutionTest::RunRWByteButterComputeTest Command List");
- // Set up UAV resource.
- CComPtr<ID3D12Resource> pUavResource;
- CComPtr<ID3D12Resource> pReadBuffer;
- CComPtr<ID3D12Resource> pUploadResource;
- CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pReadBuffer, &pUploadResource);
- VERIFY_SUCCEEDED(pUavResource->SetName(L"RunRWByteBufferComputeText UAV"));
- VERIFY_SUCCEEDED(pReadBuffer->SetName(L"RunRWByteBufferComputeText UAV Read Buffer"));
- VERIFY_SUCCEEDED(pUploadResource->SetName(L"RunRWByteBufferComputeText UAV Upload Buffer"));
- // Close the command list and execute it to perform the GPU setup.
- pCommandList->Close();
- ExecuteCommandList(pCommandQueue, pCommandList);
- WaitForSignal(pCommandQueue, FO);
- VERIFY_SUCCEEDED(pCommandAllocator->Reset());
- VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
- // Run the compute shader and copy the results back to readable memory.
- {
- D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.Format = DXGI_FORMAT_R32_TYPELESS;
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
- uavDesc.Buffer.FirstElement = 0;
- uavDesc.Buffer.NumElements = values.size();
- uavDesc.Buffer.StructureByteStride = 0;
- uavDesc.Buffer.CounterOffsetInBytes = 0;
- uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW;
- CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
- CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
- pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
- SetDescriptorHeap(pCommandList, pUavHeap);
- pCommandList->SetComputeRootSignature(pRootSignature);
- pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
- }
- pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
- RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
- pCommandList->CopyResource(pReadBuffer, pUavResource);
- pCommandList->Close();
- ExecuteCommandList(pCommandQueue, pCommandList);
- WaitForSignal(pCommandQueue, FO);
- {
- MappedData mappedData(pReadBuffer, valueSizeInBytes);
- uint32_t *pData = (uint32_t *)mappedData.data();
- memcpy(values.data(), pData, valueSizeInBytes);
- }
- WaitForSignal(pCommandQueue, FO);
- }
- TEST_F(ExecutionTest, BasicComputeTest) {
- //
- // BasicComputeTest is a simple compute shader that can be used as the basis
- // for more interesting compute execution tests.
- // The HLSL is compatible with shader models <=5.1 to allow using the DXBC
- // rendering code paths for comparison.
- //
- static const char pShader[] =
- "RWByteAddressBuffer g_bab : register(u0);\r\n"
- "[numthreads(8,8,1)]\r\n"
- "void main(uint GI : SV_GroupIndex) {"
- " uint addr = GI * 4;\r\n"
- " uint val = g_bab.Load(addr);\r\n"
- " DeviceMemoryBarrierWithGroupSync();\r\n"
- " g_bab.Store(addr, val + 1);\r\n"
- "}";
- static const int NumtheadsX = 8;
- static const int NumtheadsY = 8;
- static const int NumtheadsZ = 1;
- static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
- static const int DispatchGroupCount = 1;
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice))
- return;
- std::vector<uint32_t> values;
- SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
- VERIFY_ARE_EQUAL(values[0], 0);
- RunRWByteBufferComputeTest(pDevice, pShader, values);
- VERIFY_ARE_EQUAL(values[0], 1);
- }
- TEST_F(ExecutionTest, BasicTriangleTest) {
- static const UINT FrameCount = 2;
- static const UINT m_width = 320;
- static const UINT m_height = 200;
- static const float m_aspectRatio = static_cast<float>(m_width) / static_cast<float>(m_height);
- struct Vertex {
- XMFLOAT3 position;
- XMFLOAT4 color;
- };
- // Pipeline objects.
- CComPtr<ID3D12Device> pDevice;
- CComPtr<ID3D12Resource> pRenderTarget;
- CComPtr<ID3D12CommandAllocator> pCommandAllocator;
- CComPtr<ID3D12CommandQueue> pCommandQueue;
- CComPtr<ID3D12RootSignature> pRootSig;
- CComPtr<ID3D12DescriptorHeap> pRtvHeap;
- CComPtr<ID3D12PipelineState> pPipelineState;
- CComPtr<ID3D12GraphicsCommandList> pCommandList;
- CComPtr<ID3D12Resource> pReadBuffer;
- UINT rtvDescriptorSize;
- CComPtr<ID3D12Resource> pVertexBuffer;
- D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
- // Synchronization objects.
- FenceObj FO;
- // Shaders.
- static const char pShaders[] =
- "struct PSInput {\r\n"
- " float4 position : SV_POSITION;\r\n"
- " float4 color : COLOR;\r\n"
- "};\r\n\r\n"
- "PSInput VSMain(float4 position : POSITION, float4 color : COLOR) {\r\n"
- " PSInput result;\r\n"
- "\r\n"
- " result.position = position;\r\n"
- " result.color = color;\r\n"
- " return result;\r\n"
- "}\r\n\r\n"
- "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
- " return 1; //input.color;\r\n"
- "};\r\n";
- if (!CreateDevice(&pDevice))
- return;
- struct BasicTestChecker {
- CComPtr<ID3D12Device> m_pDevice;
- CComPtr<ID3D12InfoQueue> m_pInfoQueue;
- bool m_OK = false;
- void SetOK(bool value) { m_OK = value; }
- BasicTestChecker(ID3D12Device *pDevice) : m_pDevice(pDevice) {
- if (FAILED(m_pDevice.QueryInterface(&m_pInfoQueue)))
- return;
- m_pInfoQueue->PushEmptyStorageFilter();
- m_pInfoQueue->PushEmptyRetrievalFilter();
- }
- ~BasicTestChecker() {
- if (!m_OK && m_pInfoQueue != nullptr) {
- UINT64 count = m_pInfoQueue->GetNumStoredMessages();
- bool invalidBytecodeFound = false;
- CAtlArray<BYTE> m_pBytes;
- for (UINT64 i = 0; i < count; ++i) {
- SIZE_T len = 0;
- if (FAILED(m_pInfoQueue->GetMessageA(i, nullptr, &len)))
- continue;
- if (m_pBytes.GetCount() < len && !m_pBytes.SetCount(len))
- continue;
- D3D12_MESSAGE *pMsg = (D3D12_MESSAGE *)m_pBytes.GetData();
- if (FAILED(m_pInfoQueue->GetMessageA(i, pMsg, &len)))
- continue;
- if (pMsg->ID == D3D12_MESSAGE_ID_CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ||
- pMsg->ID == D3D12_MESSAGE_ID_CREATEPIXELSHADER_INVALIDSHADERBYTECODE) {
- invalidBytecodeFound = true;
- break;
- }
- }
- if (invalidBytecodeFound) {
- LogCommentFmt(L"%s", L"Found an invalid bytecode message. This "
- L"typically indicates that experimental mode "
- L"is not set up properly.");
- if (!GetTestParamBool(L"ExperimentalShaders")) {
- LogCommentFmt(L"Note that the ExperimentalShaders test parameter isn't set.");
- }
- }
- else {
- LogCommentFmt(L"Did not find corrupt pixel or vertex shaders in "
- L"queue - dumping complete queue.");
- WriteInfoQueueMessages(nullptr, OutputFn, m_pInfoQueue);
- }
- }
- }
- static void __stdcall OutputFn(void *pCtx, const wchar_t *pMsg) {
- LogCommentFmt(L"%s", pMsg);
- }
- };
- BasicTestChecker BTC(pDevice);
- {
- InitFenceObj(pDevice, &FO);
- CreateRtvDescriptorHeap(pDevice, FrameCount, &pRtvHeap, &rtvDescriptorSize);
- CreateRenderTargetAndReadback(pDevice, pRtvHeap, m_width, m_height, &pRenderTarget, &pReadBuffer);
- // Create an empty root signature.
- CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
- rootSignatureDesc.Init(
- 0, nullptr, 0, nullptr,
- D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
- CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSig);
- // Create the pipeline state, which includes compiling and loading shaders.
- // Define the vertex input layout.
- D3D12_INPUT_ELEMENT_DESC inputElementDescs[] = {
- {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
- D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0},
- {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12,
- D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
- D3D12_INPUT_LAYOUT_DESC InputLayout = { inputElementDescs, _countof(inputElementDescs) };
- CreateGraphicsPSO(pDevice, &InputLayout, pRootSig, pShaders, &pPipelineState);
- CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue,
- &pCommandAllocator, &pCommandList,
- pPipelineState);
- // Define the geometry for a triangle.
- Vertex triangleVertices[] = {
- { { 0.0f, 0.25f * m_aspectRatio, 0.0f },{ 1.0f, 0.0f, 0.0f, 1.0f } },
- { { 0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 1.0f, 0.0f, 1.0f } },
- { { -0.25f, -0.25f * m_aspectRatio, 0.0f },{ 0.0f, 0.0f, 1.0f, 1.0f } } };
- CreateVertexBuffer(pDevice, triangleVertices, &pVertexBuffer, &vertexBufferView);
- WaitForSignal(pCommandQueue, FO);
- }
- // Render and execute the command list.
- RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, 1,
- &vertexBufferView, pRootSig, pRenderTarget,
- pReadBuffer);
- VERIFY_SUCCEEDED(pCommandList->Close());
- ExecuteCommandList(pCommandQueue, pCommandList);
- // Wait for previous frame.
- WaitForSignal(pCommandQueue, FO);
- // At this point, we've verified that execution succeeded with DXIL.
- BTC.SetOK(true);
- // Read back to CPU and examine contents.
- {
- MappedData data(pReadBuffer, m_width * m_height * 4);
- const uint32_t *pPixels = (uint32_t *)data.data();
- if (SaveImages()) {
- SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, m_width, m_height, L"basic.bmp");
- }
- uint32_t top = pPixels[m_width / 2]; // Top center.
- uint32_t mid = pPixels[m_width / 2 + m_width * (m_height / 2)]; // Middle center.
- VERIFY_ARE_EQUAL(0xff663300, top); // clear color
- VERIFY_ARE_EQUAL(0xffffffff, mid); // white
- }
- }
- TEST_F(ExecutionTest, Int64Test) {
- static const char pShader[] =
- "RWByteAddressBuffer g_bab : register(u0);\r\n"
- "[numthreads(8,8,1)]\r\n"
- "void main(uint GI : SV_GroupIndex) {"
- " uint addr = GI * 4;\r\n"
- " uint val = g_bab.Load(addr);\r\n"
- " uint64_t u64 = val;\r\n"
- " u64 *= val;\r\n"
- " g_bab.Store(addr, (uint)(u64 >> 32));\r\n"
- "}";
- static const int NumtheadsX = 8;
- static const int NumtheadsY = 8;
- static const int NumtheadsZ = 1;
- static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
- static const int DispatchGroupCount = 1;
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice))
- return;
- if (!DoesDeviceSupportInt64(pDevice)) {
- // Optional feature, so it's correct to not support it if declared as such.
- WEX::Logging::Log::Comment(L"Device does not support int64 operations.");
- return;
- }
- std::vector<uint32_t> values;
- SetupComputeValuePattern(values, ThreadsPerGroup * DispatchGroupCount);
- VERIFY_ARE_EQUAL(values[0], 0);
- RunRWByteBufferComputeTest(pDevice, pShader, values);
- VERIFY_ARE_EQUAL(values[0], 0);
- }
- TEST_F(ExecutionTest, SignTest) {
- static const char pShader[] =
- "RWByteAddressBuffer g_bab : register(u0);\r\n"
- "[numthreads(8,1,1)]\r\n"
- "void main(uint GI : SV_GroupIndex) {"
- " uint addr = GI * 4;\r\n"
- " int val = g_bab.Load(addr);\r\n"
- " g_bab.Store(addr, (uint)(sign(val)));\r\n"
- "}";
- static const int NumtheadsX = 8;
- static const int NumtheadsY = 1;
- static const int NumtheadsZ = 1;
- static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
- static const int DispatchGroupCount = 1;
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice))
- return;
- std::vector<uint32_t> values = { (uint32_t)-3, (uint32_t)-2, (uint32_t)-1, 0, 1, 2, 3, 4};
- RunRWByteBufferComputeTest(pDevice, pShader, values);
- VERIFY_ARE_EQUAL(values[0], -1);
- VERIFY_ARE_EQUAL(values[1], -1);
- VERIFY_ARE_EQUAL(values[2], -1);
- VERIFY_ARE_EQUAL(values[3], 0);
- VERIFY_ARE_EQUAL(values[4], 1);
- VERIFY_ARE_EQUAL(values[5], 1);
- VERIFY_ARE_EQUAL(values[6], 1);
- VERIFY_ARE_EQUAL(values[7], 1);
- }
- TEST_F(ExecutionTest, WaveIntrinsicsTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- struct PerThreadData {
- uint32_t id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;
- uint32_t allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;
- uint32_t pfBC, pfSum, pfProd;
- uint32_t ballot[4];
- uint32_t diver; // divergent value, used in calculation
- int32_t i_diver; // divergent value, used in calculation
- int32_t i_allMax, i_allMin, i_allSum, i_allProd;
- int32_t i_pfSum, i_pfProd;
- };
- static const char pShader[] =
- WAVE_INTRINSIC_DXBC_GUARD
- "struct PerThreadData {\r\n"
- " uint id, flags, laneIndex, laneCount, firstLaneId, preds, firstlaneX, lane1X;\r\n"
- " uint allBC, allSum, allProd, allAND, allOR, allXOR, allMin, allMax;\r\n"
- " uint pfBC, pfSum, pfProd;\r\n"
- " uint4 ballot;\r\n"
- " uint diver;\r\n"
- " int i_diver;\r\n"
- " int i_allMax, i_allMin, i_allSum, i_allProd;\r\n"
- " int i_pfSum, i_pfProd;\r\n"
- "};\r\n"
- "RWStructuredBuffer<PerThreadData> g_sb : register(u0);\r\n"
- "[numthreads(8,8,1)]\r\n"
- "void main(uint GI : SV_GroupIndex, uint3 GTID : SV_GroupThreadID) {"
- " PerThreadData pts = g_sb[GI];\r\n"
- " uint diver = GTID.x + 2;\r\n"
- " pts.diver = diver;\r\n"
- " pts.flags = 0;\r\n"
- " pts.preds = 0;\r\n"
- " if (WaveIsFirstLane()) pts.flags |= 1;\r\n"
- " pts.laneIndex = WaveGetLaneIndex();\r\n"
- " pts.laneCount = WaveGetLaneCount();\r\n"
- " pts.firstLaneId = WaveReadLaneFirst(pts.id);\r\n"
- " pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);\r\n"
- " pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);\r\n"
- " pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);\r\n"
- " pts.preds |= ((WaveActiveAllEqual(GTID.z) ? 1 : 0) << 3);\r\n"
- " pts.preds |= ((WaveActiveAllEqual(WaveReadLaneFirst(diver)) ? 1 : 0) << 4);\r\n"
- " pts.ballot = WaveActiveBallot(diver > 3);\r\n"
- " pts.firstlaneX = WaveReadLaneFirst(GTID.x);\r\n"
- " pts.lane1X = WaveReadLaneAt(GTID.x, 1);\r\n"
- "\r\n"
- " pts.allBC = WaveActiveCountBits(diver > 3);\r\n"
- " pts.allSum = WaveActiveSum(diver);\r\n"
- " pts.allProd = WaveActiveProduct(diver);\r\n"
- " pts.allAND = WaveActiveBitAnd(diver);\r\n"
- " pts.allOR = WaveActiveBitOr(diver);\r\n"
- " pts.allXOR = WaveActiveBitXor(diver);\r\n"
- " pts.allMin = WaveActiveMin(diver);\r\n"
- " pts.allMax = WaveActiveMax(diver);\r\n"
- "\r\n"
- " pts.pfBC = WavePrefixCountBits(diver > 3);\r\n"
- " pts.pfSum = WavePrefixSum(diver);\r\n"
- " pts.pfProd = WavePrefixProduct(diver);\r\n"
- "\r\n"
- " int i_diver = pts.i_diver;\r\n"
- " pts.i_allMax = WaveActiveMax(i_diver);\r\n"
- " pts.i_allMin = WaveActiveMin(i_diver);\r\n"
- " pts.i_allSum = WaveActiveSum(i_diver);\r\n"
- " pts.i_allProd = WaveActiveProduct(i_diver);\r\n"
- " pts.i_pfSum = WavePrefixSum(i_diver);\r\n"
- " pts.i_pfProd = WavePrefixProduct(i_diver);\r\n"
- "\r\n"
- " g_sb[GI] = pts;\r\n"
- "}";
- static const int NumtheadsX = 8;
- static const int NumtheadsY = 8;
- static const int NumtheadsZ = 1;
- static const int ThreadsPerGroup = NumtheadsX * NumtheadsY * NumtheadsZ;
- static const int DispatchGroupCount = 1;
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice))
- return;
- if (!DoesDeviceSupportWaveOps(pDevice)) {
- // Optional feature, so it's correct to not support it if declared as such.
- WEX::Logging::Log::Comment(L"Device does not support wave operations.");
- return;
- }
- std::vector<PerThreadData> values;
- values.resize(ThreadsPerGroup * DispatchGroupCount);
- for (size_t i = 0; i < values.size(); ++i) {
- memset(&values[i], 0, sizeof(PerThreadData));
- values[i].id = i;
- values[i].i_diver = (int)i;
- values[i].i_diver *= (i % 2) ? 1 : -1;
- }
- static const int DispatchGroupX = 1;
- static const int DispatchGroupY = 1;
- static const int DispatchGroupZ = 1;
- CComPtr<ID3D12GraphicsCommandList> pCommandList;
- CComPtr<ID3D12CommandQueue> pCommandQueue;
- CComPtr<ID3D12DescriptorHeap> pUavHeap;
- CComPtr<ID3D12CommandAllocator> pCommandAllocator;
- UINT uavDescriptorSize;
- FenceObj FO;
- bool dxbc = UseDxbc();
- const size_t valueSizeInBytes = values.size() * sizeof(PerThreadData);
- CreateComputeCommandQueue(pDevice, L"WaveIntrinsicsTest Command Queue", &pCommandQueue);
- InitFenceObj(pDevice, &FO);
- // Describe and create a UAV descriptor heap.
- D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
- heapDesc.NumDescriptors = 1;
- heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
- heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
- VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
- uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
- // Create root signature.
- CComPtr<ID3D12RootSignature> pRootSignature;
- {
- CD3DX12_DESCRIPTOR_RANGE ranges[1];
- ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, 0);
- CD3DX12_ROOT_PARAMETER rootParameters[1];
- rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
- CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
- rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_NONE);
- CComPtr<ID3DBlob> signature;
- CComPtr<ID3DBlob> error;
- VERIFY_SUCCEEDED(D3D12SerializeRootSignature(&rootSignatureDesc, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &error));
- VERIFY_SUCCEEDED(pDevice->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&pRootSignature)));
- }
- // Create pipeline state object.
- CComPtr<ID3D12PipelineState> pComputeState;
- CreateComputePSO(pDevice, pRootSignature, pShader, &pComputeState);
- // Create a command allocator and list for compute.
- VERIFY_SUCCEEDED(pDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COMPUTE, IID_PPV_ARGS(&pCommandAllocator)));
- VERIFY_SUCCEEDED(pDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COMPUTE, pCommandAllocator, pComputeState, IID_PPV_ARGS(&pCommandList)));
- // Set up UAV resource.
- CComPtr<ID3D12Resource> pUavResource;
- CComPtr<ID3D12Resource> pReadBuffer;
- CComPtr<ID3D12Resource> pUploadResource;
- CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pReadBuffer, &pUploadResource);
- // Close the command list and execute it to perform the GPU setup.
- pCommandList->Close();
- ExecuteCommandList(pCommandQueue, pCommandList);
- WaitForSignal(pCommandQueue, FO);
- VERIFY_SUCCEEDED(pCommandAllocator->Reset());
- VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pComputeState));
- // Run the compute shader and copy the results back to readable memory.
- {
- D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.Format = DXGI_FORMAT_UNKNOWN;
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
- uavDesc.Buffer.FirstElement = 0;
- uavDesc.Buffer.NumElements = values.size();
- uavDesc.Buffer.StructureByteStride = sizeof(PerThreadData);
- uavDesc.Buffer.CounterOffsetInBytes = 0;
- uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
- CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
- CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
- pDevice->CreateUnorderedAccessView(pUavResource, nullptr, &uavDesc, uavHandle);
- SetDescriptorHeap(pCommandList, pUavHeap);
- pCommandList->SetComputeRootSignature(pRootSignature);
- pCommandList->SetComputeRootDescriptorTable(0, uavHandleGpu);
- }
- pCommandList->Dispatch(DispatchGroupX, DispatchGroupY, DispatchGroupZ);
- RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
- pCommandList->CopyResource(pReadBuffer, pUavResource);
- pCommandList->Close();
- ExecuteCommandList(pCommandQueue, pCommandList);
- WaitForSignal(pCommandQueue, FO);
- {
- MappedData mappedData(pReadBuffer, valueSizeInBytes);
- PerThreadData *pData = (PerThreadData *)mappedData.data();
- memcpy(values.data(), pData, valueSizeInBytes);
- // Gather some general data.
- // The 'firstLaneId' captures a unique number per first-lane per wave.
- // Counting the number distinct firstLaneIds gives us the number of waves.
- std::vector<uint32_t> firstLaneIds;
- for (size_t i = 0; i < values.size(); ++i) {
- PerThreadData &pts = values[i];
- uint32_t firstLaneId = pts.firstLaneId;
- if (!contains(firstLaneIds, firstLaneId)) {
- firstLaneIds.push_back(firstLaneId);
- }
- }
- // Waves should cover 4 threads or more.
- LogCommentFmt(L"Found %u distinct lane ids: %u", firstLaneIds.size());
- if (!dxbc) {
- VERIFY_IS_GREATER_THAN_OR_EQUAL(values.size() / 4, firstLaneIds.size());
- }
- // Now, group threads into waves.
- std::map<uint32_t, std::unique_ptr<std::vector<PerThreadData *> > > waves;
- for (size_t i = 0; i < firstLaneIds.size(); ++i) {
- waves[firstLaneIds[i]] = std::make_unique<std::vector<PerThreadData *> >();
- }
- for (size_t i = 0; i < values.size(); ++i) {
- PerThreadData &pts = values[i];
- std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
- wave->push_back(&pts);
- }
- // Verify that all the wave values are coherent across the wave.
- for (size_t i = 0; i < values.size(); ++i) {
- PerThreadData &pts = values[i];
- std::unique_ptr<std::vector<PerThreadData *> > &wave = waves[pts.firstLaneId];
- // Sort the lanes by increasing lane ID.
- struct LaneIdOrderPred {
- bool operator()(PerThreadData *a, PerThreadData *b) {
- return a->laneIndex < b->laneIndex;
- }
- };
- std::sort(wave.get()->begin(), wave.get()->end(), LaneIdOrderPred());
- // Verify some interesting properties of the first lane.
- uint32_t pfBC, pfSum, pfProd;
- int32_t i_pfSum, i_pfProd;
- int32_t i_allMax, i_allMin;
- {
- PerThreadData *ptdFirst = wave->front();
- VERIFY_IS_TRUE(0 != (ptdFirst->flags & 1)); // FirstLane sets this bit.
- VERIFY_IS_TRUE(0 == ptdFirst->pfBC);
- VERIFY_IS_TRUE(0 == ptdFirst->pfSum);
- VERIFY_IS_TRUE(1 == ptdFirst->pfProd);
- VERIFY_IS_TRUE(0 == ptdFirst->i_pfSum);
- VERIFY_IS_TRUE(1 == ptdFirst->i_pfProd);
- pfBC = (ptdFirst->diver > 3) ? 1 : 0;
- pfSum = ptdFirst->diver;
- pfProd = ptdFirst->diver;
- i_pfSum = ptdFirst->i_diver;
- i_pfProd = ptdFirst->i_diver;
- i_allMax = i_allMin = ptdFirst->i_diver;
- }
- // Calculate values which take into consideration all lanes.
- uint32_t preds = 0;
- preds |= 1 << 1; // AllTrue starts true, switches to false if needed.
- preds |= 1 << 2; // AllEqual starts true, switches to false if needed.
- preds |= 1 << 3; // WaveActiveAllEqual(GTID.z) is always true
- preds |= 1 << 4; // (WaveActiveAllEqual(WaveReadLaneFirst(diver)) is always true
- uint32_t ballot[4] = { 0, 0, 0, 0 };
- int32_t i_allSum = 0, i_allProd = 1;
- for (size_t n = 0; n < wave->size(); ++n) {
- std::vector<PerThreadData *> &lanes = *wave.get();
- // pts.preds |= ((WaveActiveAnyTrue(diver == 1) ? 1 : 0) << 0);
- if (lanes[n]->diver == 1) preds |= (1 << 0);
- // pts.preds |= ((WaveActiveAllTrue(diver == 1) ? 1 : 0) << 1);
- if (lanes[n]->diver != 1) preds &= ~(1 << 1);
- // pts.preds |= ((WaveActiveAllEqual(diver) ? 1 : 0) << 2);
- if (lanes[0]->diver != lanes[n]->diver) preds &= ~(1 << 2);
- // pts.ballot = WaveActiveBallot(diver > 3);\r\n"
- if (lanes[n]->diver > 3) {
- // This is the uint4 result layout:
- // .x -> bits 0 .. 31
- // .y -> bits 32 .. 63
- // .z -> bits 64 .. 95
- // .w -> bits 96 ..127
- uint32_t component = lanes[n]->laneIndex / 32;
- uint32_t bit = lanes[n]->laneIndex % 32;
- ballot[component] |= 1 << bit;
- }
- i_allMax = std::max(lanes[n]->i_diver, i_allMax);
- i_allMin = std::min(lanes[n]->i_diver, i_allMin);
- i_allProd *= lanes[n]->i_diver;
- i_allSum += lanes[n]->i_diver;
- }
- for (size_t n = 1; n < wave->size(); ++n) {
- // 'All' operations are uniform across the wave.
- std::vector<PerThreadData *> &lanes = *wave.get();
- VERIFY_IS_TRUE(0 == (lanes[n]->flags & 1)); // non-firstlanes do not set this bit
- VERIFY_ARE_EQUAL(lanes[0]->allBC, lanes[n]->allBC);
- VERIFY_ARE_EQUAL(lanes[0]->allSum, lanes[n]->allSum);
- VERIFY_ARE_EQUAL(lanes[0]->allProd, lanes[n]->allProd);
- VERIFY_ARE_EQUAL(lanes[0]->allAND, lanes[n]->allAND);
- VERIFY_ARE_EQUAL(lanes[0]->allOR, lanes[n]->allOR);
- VERIFY_ARE_EQUAL(lanes[0]->allXOR, lanes[n]->allXOR);
- VERIFY_ARE_EQUAL(lanes[0]->allMin, lanes[n]->allMin);
- VERIFY_ARE_EQUAL(lanes[0]->allMax, lanes[n]->allMax);
- VERIFY_ARE_EQUAL(i_allMax, lanes[n]->i_allMax);
- VERIFY_ARE_EQUAL(i_allMin, lanes[n]->i_allMin);
- VERIFY_ARE_EQUAL(i_allProd, lanes[n]->i_allProd);
- VERIFY_ARE_EQUAL(i_allSum, lanes[n]->i_allSum);
- // first-lane reads and uniform reads are uniform across the wave.
- VERIFY_ARE_EQUAL(lanes[0]->firstlaneX, lanes[n]->firstlaneX);
- VERIFY_ARE_EQUAL(lanes[0]->lane1X, lanes[n]->lane1X);
- // the lane count is uniform across the wave.
- VERIFY_ARE_EQUAL(lanes[0]->laneCount, lanes[n]->laneCount);
- // The predicates are uniform across the wave.
- VERIFY_ARE_EQUAL(lanes[n]->preds, preds);
- // the lane index is distinct per thread.
- for (size_t prior = 0; prior < n; ++prior) {
- VERIFY_ARE_NOT_EQUAL(lanes[prior]->laneIndex, lanes[n]->laneIndex);
- }
- // Ballot results are uniform across the wave.
- VERIFY_ARE_EQUAL(0, memcmp(ballot, lanes[n]->ballot, sizeof(ballot)));
- // Keep running total of prefix calculation. Prefix values are exclusive to
- // the executing lane.
- VERIFY_ARE_EQUAL(pfBC, lanes[n]->pfBC);
- VERIFY_ARE_EQUAL(pfSum, lanes[n]->pfSum);
- VERIFY_ARE_EQUAL(pfProd, lanes[n]->pfProd);
- VERIFY_ARE_EQUAL(i_pfSum, lanes[n]->i_pfSum);
- VERIFY_ARE_EQUAL(i_pfProd, lanes[n]->i_pfProd);
- pfBC += (lanes[n]->diver > 3) ? 1 : 0;
- pfSum += lanes[n]->diver;
- pfProd *= lanes[n]->diver;
- i_pfSum += lanes[n]->i_diver;
- i_pfProd *= lanes[n]->i_diver;
- }
- // TODO: add divergent branching and verify that the otherwise uniform values properly diverge
- }
- // Compare each value of each per-thread element.
- for (size_t i = 0; i < values.size(); ++i) {
- PerThreadData &pts = values[i];
- VERIFY_ARE_EQUAL(i, pts.id); // ID is unchanged.
- }
- }
- }
- TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- struct Vertex {
- XMFLOAT3 position;
- };
- struct PerPixelData {
- XMFLOAT4 position;
- uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;
- uint32_t id0, id1, id2, id3;
- uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;
- };
- const UINT RTWidth = 128;
- const UINT RTHeight = 128;
- // Shaders.
- static const char pShaders[] =
- WAVE_INTRINSIC_DXBC_GUARD
- "struct PSInput {\r\n"
- " float4 position : SV_POSITION;\r\n"
- "};\r\n\r\n"
- "PSInput VSMain(float4 position : POSITION) {\r\n"
- " PSInput result;\r\n"
- "\r\n"
- " result.position = position;\r\n"
- " return result;\r\n"
- "}\r\n\r\n"
- "typedef uint uint32_t;\r\n"
- "uint pos_to_id(float4 pos) { return pos.x * 128 + pos.y; }\r\n"
- "struct PerPixelData {\r\n"
- " float4 position;\r\n"
- " uint32_t id, flags, laneIndex, laneCount, firstLaneId, sum1;\r\n"
- " uint32_t id0, id1, id2, id3;\r\n"
- " uint32_t acrossX, acrossY, acrossDiag, quadActiveCount;\r\n"
- "};\r\n"
- "AppendStructuredBuffer<PerPixelData> g_sb : register(u1);\r\n"
- "float4 PSMain(PSInput input) : SV_TARGET {\r\n"
- " uint one = 1;\r\n"
- " PerPixelData d;\r\n"
- " d.position = input.position;\r\n"
- " d.id = pos_to_id(input.position);\r\n"
- " d.flags = 0;\r\n"
- " if (WaveIsFirstLane()) d.flags |= 1;\r\n"
- " d.laneIndex = WaveGetLaneIndex();\r\n"
- " d.laneCount = WaveGetLaneCount();\r\n"
- " d.firstLaneId = WaveReadLaneFirst(d.id);\r\n"
- " d.sum1 = WaveActiveSum(one);\r\n"
- " d.id0 = QuadReadLaneAt(d.id, 0);\r\n"
- " d.id1 = QuadReadLaneAt(d.id, 1);\r\n"
- " d.id2 = QuadReadLaneAt(d.id, 2);\r\n"
- " d.id3 = QuadReadLaneAt(d.id, 3);\r\n"
- " d.acrossX = QuadReadAcrossX(d.id);\r\n"
- " d.acrossY = QuadReadAcrossY(d.id);\r\n"
- " d.acrossDiag = QuadReadAcrossDiagonal(d.id);\r\n"
- " d.quadActiveCount = one + QuadReadAcrossX(one) + QuadReadAcrossY(one) + QuadReadAcrossDiagonal(one);\r\n"
- " g_sb.Append(d);\r\n"
- " return 1;\r\n"
- "};\r\n";
- CComPtr<ID3D12Device> pDevice;
- CComPtr<ID3D12CommandQueue> pCommandQueue;
- CComPtr<ID3D12DescriptorHeap> pUavHeap, pRtvHeap;
- CComPtr<ID3D12CommandAllocator> pCommandAllocator;
- CComPtr<ID3D12GraphicsCommandList> pCommandList;
- CComPtr<ID3D12PipelineState> pPSO;
- CComPtr<ID3D12Resource> pRenderTarget, pReadBuffer;
- UINT uavDescriptorSize, rtvDescriptorSize;
- CComPtr<ID3D12Resource> pVertexBuffer;
- D3D12_VERTEX_BUFFER_VIEW vertexBufferView;
- if (!CreateDevice(&pDevice))
- return;
- if (!DoesDeviceSupportWaveOps(pDevice)) {
- // Optional feature, so it's correct to not support it if declared as such.
- WEX::Logging::Log::Comment(L"Device does not support wave operations.");
- return;
- }
- FenceObj FO;
- InitFenceObj(pDevice, &FO);
- // Describe and create a UAV descriptor heap.
- D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
- heapDesc.NumDescriptors = 1;
- heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
- heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
- VERIFY_SUCCEEDED(pDevice->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&pUavHeap)));
- uavDescriptorSize = pDevice->GetDescriptorHandleIncrementSize(heapDesc.Type);
- CreateRtvDescriptorHeap(pDevice, 1, &pRtvHeap, &rtvDescriptorSize);
- CreateRenderTargetAndReadback(pDevice, pRtvHeap, RTHeight, RTWidth, &pRenderTarget, &pReadBuffer);
- // Create root signature: one UAV.
- CComPtr<ID3D12RootSignature> pRootSignature;
- {
- CD3DX12_DESCRIPTOR_RANGE ranges[1];
- ranges[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 1, 0, 0);
- CD3DX12_ROOT_PARAMETER rootParameters[1];
- rootParameters[0].InitAsDescriptorTable(1, &ranges[0], D3D12_SHADER_VISIBILITY_ALL);
- CD3DX12_ROOT_SIGNATURE_DESC rootSignatureDesc;
- rootSignatureDesc.Init(_countof(rootParameters), rootParameters, 0, nullptr, D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT);
- CreateRootSignatureFromDesc(pDevice, &rootSignatureDesc, &pRootSignature);
- }
- D3D12_INPUT_ELEMENT_DESC elementDesc[] = {
- {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
- D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, 0}};
- D3D12_INPUT_LAYOUT_DESC InputLayout = {elementDesc, _countof(elementDesc)};
- CreateGraphicsPSO(pDevice, &InputLayout, pRootSignature, pShaders, &pPSO);
- CreateGraphicsCommandQueueAndList(pDevice, &pCommandQueue, &pCommandAllocator,
- &pCommandList, pPSO);
- // Single triangle covering half the target.
- Vertex vertices[] = {
- { { -1.0f, 1.0f, 0.0f } },
- { { 1.0f, 1.0f, 0.0f } },
- { { -1.0f, -1.0f, 0.0f } } };
- const UINT TriangleCount = _countof(vertices) / 3;
- CreateVertexBuffer(pDevice, vertices, &pVertexBuffer, &vertexBufferView);
- bool dxbc = UseDxbc();
- // Set up UAV resource.
- std::vector<PerPixelData> values;
- values.resize(RTWidth * RTHeight * 2);
- UINT valueSizeInBytes = values.size() * sizeof(PerPixelData);
- memset(values.data(), 0, valueSizeInBytes);
- CComPtr<ID3D12Resource> pUavResource;
- CComPtr<ID3D12Resource> pUavReadBuffer;
- CComPtr<ID3D12Resource> pUploadResource;
- CreateTestUavs(pDevice, pCommandList, values.data(), valueSizeInBytes, &pUavResource, &pUavReadBuffer, &pUploadResource);
- // Set up the append counter resource.
- CComPtr<ID3D12Resource> pUavCounterResource;
- CComPtr<ID3D12Resource> pReadCounterBuffer;
- CComPtr<ID3D12Resource> pUploadCounterResource;
- BYTE zero[sizeof(UINT)] = { 0 };
- CreateTestUavs(pDevice, pCommandList, zero, sizeof(zero), &pUavCounterResource, &pReadCounterBuffer, &pUploadCounterResource);
- // Close the command list and execute it to perform the GPU setup.
- pCommandList->Close();
- ExecuteCommandList(pCommandQueue, pCommandList);
- WaitForSignal(pCommandQueue, FO);
- VERIFY_SUCCEEDED(pCommandAllocator->Reset());
- VERIFY_SUCCEEDED(pCommandList->Reset(pCommandAllocator, pPSO));
- pCommandList->SetGraphicsRootSignature(pRootSignature);
- SetDescriptorHeap(pCommandList, pUavHeap);
- {
- D3D12_UNORDERED_ACCESS_VIEW_DESC uavDesc = {};
- uavDesc.Format = DXGI_FORMAT_UNKNOWN;
- uavDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;
- uavDesc.Buffer.FirstElement = 0;
- uavDesc.Buffer.NumElements = values.size();
- uavDesc.Buffer.StructureByteStride = sizeof(PerPixelData);
- uavDesc.Buffer.CounterOffsetInBytes = 0;
- uavDesc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_NONE;
- CD3DX12_CPU_DESCRIPTOR_HANDLE uavHandle(pUavHeap->GetCPUDescriptorHandleForHeapStart());
- CD3DX12_GPU_DESCRIPTOR_HANDLE uavHandleGpu(pUavHeap->GetGPUDescriptorHandleForHeapStart());
- pDevice->CreateUnorderedAccessView(pUavResource, pUavCounterResource, &uavDesc, uavHandle);
- pCommandList->SetGraphicsRootDescriptorTable(0, uavHandleGpu);
- }
- RecordRenderAndReadback(pCommandList, pRtvHeap, rtvDescriptorSize, TriangleCount, &vertexBufferView, nullptr, pRenderTarget, pReadBuffer);
- RecordTransitionBarrier(pCommandList, pUavResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
- RecordTransitionBarrier(pCommandList, pUavCounterResource, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_SOURCE);
- pCommandList->CopyResource(pUavReadBuffer, pUavResource);
- pCommandList->CopyResource(pReadCounterBuffer, pUavCounterResource);
- VERIFY_SUCCEEDED(pCommandList->Close());
- LogCommentFmt(L"Rendering to %u by %u", RTWidth, RTHeight);
- ExecuteCommandList(pCommandQueue, pCommandList);
- WaitForSignal(pCommandQueue, FO);
- {
- MappedData data(pReadBuffer, RTWidth * RTHeight * 4);
- const uint32_t *pPixels = (uint32_t *)data.data();
- if (SaveImages()) {
- SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, RTWidth, RTHeight, L"psintrin.bmp");
- }
- }
- uint32_t appendCount;
- {
- MappedData mappedData(pReadCounterBuffer, sizeof(uint32_t));
- appendCount = *((uint32_t *)mappedData.data());
- LogCommentFmt(L"%u elements in append buffer", appendCount);
- }
- {
- MappedData mappedData(pUavReadBuffer, values.size());
- PerPixelData *pData = (PerPixelData *)mappedData.data();
- memcpy(values.data(), pData, valueSizeInBytes);
- // DXBC is handy to test pipeline setup, but interesting functions are
- // stubbed out, so there is no point in further validation.
- if (dxbc)
- return;
- uint32_t maxActiveLaneCount = 0;
- uint32_t maxLaneCount = 0;
- for (uint32_t i = 0; i < appendCount; ++i) {
- maxActiveLaneCount = std::max(maxActiveLaneCount, values[i].sum1);
- maxLaneCount = std::max(maxLaneCount, values[i].laneCount);
- }
- uint32_t peerOfHelperLanes = 0;
- for (uint32_t i = 0; i < appendCount; ++i) {
- if (values[i].sum1 != maxActiveLaneCount) {
- ++peerOfHelperLanes;
- }
- }
- LogCommentFmt(
- L"Found: %u threads. Waves reported up to %u total lanes, up "
- L"to %u active lanes, and %u threads had helper/inactive lanes.",
- appendCount, maxLaneCount, maxActiveLaneCount, peerOfHelperLanes);
- // Group threads into quad invocations.
- uint32_t singlePixelCount = 0;
- uint32_t multiPixelCount = 0;
- std::unordered_set<uint32_t> ids;
- std::multimap<uint32_t, PerPixelData *> idGroups;
- std::multimap<uint32_t, PerPixelData *> firstIdGroups;
- for (uint32_t i = 0; i < appendCount; ++i) {
- ids.insert(values[i].id);
- idGroups.insert(std::make_pair(values[i].id, &values[i]));
- firstIdGroups.insert(std::make_pair(values[i].firstLaneId, &values[i]));
- }
- for (uint32_t id : ids) {
- if (idGroups.count(id) == 1)
- ++singlePixelCount;
- else
- ++multiPixelCount;
- }
- LogCommentFmt(L"%u pixels were processed by a single thread. %u invocations were for shared pixels.",
- singlePixelCount, multiPixelCount);
- // Multiple threads may have tried to shade the same pixel.
- // Where every pixel is distinct, it's very straightforward to validate.
- {
- auto cur = firstIdGroups.begin(), end = firstIdGroups.end();
- while (cur != end) {
- bool simpleWave = true;
- uint32_t firstId = (*cur).first;
- auto groupEnd = cur;
- while (groupEnd != end && (*groupEnd).first == firstId) {
- if (idGroups.count((*groupEnd).second->id) > 1)
- simpleWave = false;
- ++groupEnd;
- }
- if (simpleWave) {
- // Break the wave into quads.
- struct QuadData {
- unsigned count;
- PerPixelData *data[4];
- };
- std::map<uint32_t, QuadData> quads;
- for (auto i = cur; i != groupEnd; ++i) {
- uint32_t quadId = (*i).second->id0;
- auto match = quads.find(quadId);
- if (match == quads.end()) {
- QuadData qdata;
- qdata.count = 1;
- qdata.data[0] = (*i).second;
- quads.insert(std::make_pair(quadId, qdata));
- }
- else {
- VERIFY_IS_TRUE((*match).second.count < 4);
- (*match).second.data[(*match).second.count++] = (*i).second;
- }
- }
- for (auto quadPair : quads) {
- unsigned count = quadPair.second.count;
- if (count < 2) continue;
- PerPixelData **data = quadPair.second.data;
- bool isTop[4];
- bool isLeft[4];
- PerPixelData helperData;
- memset(&helperData, sizeof(helperData), 0);
- PerPixelData *layout[4]; // tl,tr,bl,br
- memset(layout, sizeof(layout), 0);
- auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
- int idx = top ? 0 : 2;
- idx += left ? 0 : 1;
- return &layout[idx];
- };
- auto fnToLayoutData = [&](bool top, bool left) -> PerPixelData * {
- PerPixelData **pResult = fnToLayout(top, left);
- if (*pResult == nullptr) return &helperData;
- return *pResult;
- };
- VERIFY_IS_TRUE(count <= 4);
- if (count == 2) {
- isTop[0] = data[0]->position.y < data[1]->position.y;
- isTop[1] = (data[0]->position.y == data[1]->position.y) ? isTop[0] : !isTop[0];
- isLeft[0] = data[0]->position.x < data[1]->position.x;
- isLeft[1] = (data[0]->position.x == data[1]->position.x) ? isLeft[0] : !isLeft[0];
- }
- else {
- // with at least three samples, we have distinct x and y coordinates.
- float left = std::min(data[0]->position.x, data[1]->position.x);
- left = std::min(data[2]->position.x, left);
- float top = std::min(data[0]->position.y, data[1]->position.y);
- top = std::min(data[2]->position.y, top);
- for (unsigned i = 0; i < count; ++i) {
- isTop[i] = data[i]->position.y == top;
- isLeft[i] = data[i]->position.x == left;
- }
- }
- for (unsigned i = 0; i < count; ++i) {
- *(fnToLayout(isTop[i], isLeft[i])) = data[i];
- }
- // Finally, we have a proper quad reconstructed. Validate.
- for (unsigned i = 0; i < count; ++i) {
- PerPixelData *d = data[i];
- VERIFY_ARE_EQUAL(d->id0, fnToLayoutData(true, true)->id);
- VERIFY_ARE_EQUAL(d->id1, fnToLayoutData(true, false)->id);
- VERIFY_ARE_EQUAL(d->id2, fnToLayoutData(false, true)->id);
- VERIFY_ARE_EQUAL(d->id3, fnToLayoutData(false, false)->id);
- VERIFY_ARE_EQUAL(d->acrossX, fnToLayoutData(isTop[i], !isLeft[i])->id);
- VERIFY_ARE_EQUAL(d->acrossY, fnToLayoutData(!isTop[i], isLeft[i])->id);
- VERIFY_ARE_EQUAL(d->acrossDiag, fnToLayoutData(!isTop[i], !isLeft[i])->id);
- VERIFY_ARE_EQUAL(d->quadActiveCount, count);
- }
- }
- }
- cur = groupEnd;
- }
- }
- // TODO: provide validation for quads where the same pixel was shaded multiple times
- //
- // Consider: for pixels that were shaded multiple times, check whether
- // some grouping of threads into quads satisfies all value requirements.
- }
- }
- struct ShaderOpTestResult {
- st::ShaderOp *ShaderOp;
- std::shared_ptr<st::ShaderOpSet> ShaderOpSet;
- std::shared_ptr<st::ShaderOpTest> Test;
- };
- struct SPrimitives {
- float f_float;
- float f_float2;
- float f_float_o;
- float f_float2_o;
- };
- static float g_SinCosFloats[] = {
- -(INFINITY),
- -1.0f,
- -(FLT_MIN/2),
- -0.0f,
- 0.0f,
- FLT_MIN / 2,
- 1.0f,
- INFINITY,
- NAN
- };
- std::shared_ptr<ShaderOpTestResult>
- RunShaderOpTest(ID3D12Device *pDevice, dxc::DxcDllSupport &support,
- IStream *pStream, LPCSTR pName,
- st::ShaderOpTest::TInitCallbackFn pInitCallback) {
- DXASSERT_NOMSG(pStream != nullptr);
- std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
- std::make_shared<st::ShaderOpSet>();
- st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
- st::ShaderOp *pShaderOp;
- if (pName == nullptr) {
- if (ShaderOpSet->ShaderOps.size() != 1) {
- VERIFY_FAIL(L"Expected a single shader operation.");
- }
- pShaderOp = ShaderOpSet->ShaderOps[0].get();
- }
- else {
- pShaderOp = ShaderOpSet->GetShaderOp(pName);
- }
- if (pShaderOp == nullptr) {
- std::string msg = "Unable to find shader op ";
- msg += pName;
- msg += "; available ops";
- const char sep = ':';
- for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
- msg += sep;
- msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
- }
- CA2W msgWide(msg.c_str());
- VERIFY_FAIL(msgWide.m_psz);
- }
- // This won't actually be used since we're supplying the device,
- // but let's make it consistent.
- pShaderOp->UseWarpDevice = GetTestParamUseWARP(true);
- std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
- test->SetDxcSupport(&support);
- test->SetInitCallback(pInitCallback);
- test->SetDevice(pDevice);
- test->RunShaderOp(pShaderOp);
- std::shared_ptr<ShaderOpTestResult> result =
- std::make_shared<ShaderOpTestResult>();
- result->ShaderOpSet = ShaderOpSet;
- result->Test = test;
- result->ShaderOp = pShaderOp;
- return result;
- }
- static bool isdenorm(float f) {
- return FP_SUBNORMAL == fpclassify(f);
- }
- static bool isdenorm(double d) {
- return FP_SUBNORMAL == fpclassify(d);
- }
- static float ifdenorm_flushf(float a) {
- return isdenorm(a) ? copysign(0.0f, a) : a;
- }
- static bool ifdenorm_flushf_eq(float a, float b) {
- return ifdenorm_flushf(a) == ifdenorm_flushf(b);
- }
- static bool ifdenorm_flushf_eq_or_nans(float a, float b) {
- if (isnan(a) && isnan(b)) return true;
- return ifdenorm_flushf(a) == ifdenorm_flushf(b);
- }
- TEST_F(ExecutionTest, OutOfBoundsTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- // Single operation test at the moment.
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice))
- return;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "OOB", nullptr);
- MappedData data;
- // Read back to CPU and examine contents - should get pure red.
- {
- MappedData data;
- test->Test->GetReadBackData("RTarget", &data);
- const uint32_t *pPixels = (uint32_t *)data.data();
- uint32_t first = *pPixels;
- VERIFY_ARE_EQUAL(0xff0000ff, first); // pure red - only first component is read
- }
- }
- TEST_F(ExecutionTest, SaturateTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- // Single operation test at the moment.
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice))
- return;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Saturate", nullptr);
- MappedData data;
- test->Test->GetReadBackData("U0", &data);
- const float *pValues = (float *)data.data();
- // Everything is zero except for 1.5f and +Inf, which saturate to 1.0f
- const float ExpectedCases[9] = {
- 0.0f, 0.0f, 0.0f, 0.0f, // -inf, -1.5, -denorm, -0
- 0.0f, 0.0f, 1.0f, 1.0f, // 0, denorm, 1.5f, inf
- 0.0f // nan
- };
- for (size_t i = 0; i < _countof(ExpectedCases); ++i) {
- VERIFY_ARE_EQUAL(*pValues, ExpectedCases[i]);
- ++pValues;
- }
- }
- TEST_F(ExecutionTest, BasicTriangleOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- // Single operation test at the moment.
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice))
- return;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(pDevice, m_support, pStream, "Triangle", nullptr);
- MappedData data;
- D3D12_RESOURCE_DESC &D = test->ShaderOp->GetResourceByName("RTarget")->Desc;
- UINT width = (UINT64)D.Width;
- UINT height = (UINT64)D.Height;
- test->Test->GetReadBackData("RTarget", &data);
- const uint32_t *pPixels = (uint32_t *)data.data();
- if (SaveImages()) {
- SavePixelsToFile(pPixels, DXGI_FORMAT_R8G8B8A8_UNORM, 320, 200, L"basic.bmp");
- }
- uint32_t top = pPixels[width / 2]; // Top center.
- uint32_t mid = pPixels[width / 2 + width * (height / 2)]; // Middle center.
- VERIFY_ARE_EQUAL(0xff663300, top); // clear color
- VERIFY_ARE_EQUAL(0xffffffff, mid); // white
- // This is the basic validation test for shader operations, so it's good to
- // check this here at least for this one test case.
- data.reset();
- test.reset();
- ReportLiveObjects();
- }
- // Resource structure for data-driven tests.
- struct SUnaryFPOp {
- float input;
- float output;
- };
- struct SBinaryFPOp {
- float input1;
- float input2;
- float output1;
- float output2;
- };
- struct STertiaryFPOp {
- float input1;
- float input2;
- float input3;
- float output;
- };
- struct SUnaryIntOp {
- int input;
- int output;
- };
- struct SUnaryUintOp {
- unsigned int input;
- unsigned int output;
- };
- struct SBinaryIntOp {
- int input1;
- int input2;
- int output1;
- int output2;
- };
- struct STertiaryIntOp {
- int input1;
- int input2;
- int input3;
- int output;
- };
- struct SBinaryUintOp {
- unsigned int input1;
- unsigned int input2;
- unsigned int output1;
- unsigned int output2;
- };
- struct STertiaryUintOp {
- unsigned int input1;
- unsigned int input2;
- unsigned int input3;
- unsigned int output;
- };
- // representation for HLSL float vectors
- struct float2 {
- float x;
- float y;
- };
- struct float3 {
- float x;
- float y;
- float z;
- };
- struct float4 {
- float x;
- float y;
- float z;
- float w;
- };
- struct SDotOp {
- float4 input1;
- float4 input2;
- float o_dot2;
- float o_dot3;
- float o_dot4;
- };
- // HLSL representation for unsigned int vectors
- struct uint2 {
- unsigned int x;
- unsigned int y;
- };
- struct uint3 {
- unsigned int x;
- unsigned int y;
- unsigned int z;
- };
- struct uint4 {
- unsigned int x;
- unsigned int y;
- unsigned int z;
- unsigned int w;
- };
- struct SMsad4 {
- unsigned int ref;
- uint2 src;
- uint4 accum;
- uint4 result;
- };
- // Parameter representation for taef data-driven tests
- struct TableParameter {
- LPCWSTR m_name;
- enum TableParameterType {
- INT,
- UINT,
- DOUBLE,
- STRING,
- BOOL,
- INT_TABLE,
- DOUBLE_TABLE,
- STRING_TABLE,
- UINT_TABLE
- };
- TableParameterType m_type;
- bool m_required; // required parameter
- int m_int;
- unsigned int m_uint;
- double m_double;
- bool m_bool;
- WEX::Common::String m_str;
- WEX::TestExecution::TestDataArray<int> m_intTable;
- WEX::TestExecution::TestDataArray<unsigned int> m_uintTable;
- WEX::TestExecution::TestDataArray<double> m_doubleTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> m_StringTable;
- };
- static TableParameter UnaryFPOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input", TableParameter::STRING_TABLE, true },
- { L"Validation.Expected", TableParameter::STRING_TABLE, true },
- { L"Validation.Type", TableParameter::STRING, true },
- { L"Validation.Tolerance", TableParameter::DOUBLE, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter BinaryFPOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input1", TableParameter::STRING_TABLE, true },
- { L"Validation.Input2", TableParameter::STRING_TABLE, true },
- { L"Validation.Expected1", TableParameter::STRING_TABLE, true },
- { L"Validation.Expected2", TableParameter::STRING_TABLE, true },
- { L"Validation.Type", TableParameter::STRING, true },
- { L"Validation.Tolerance", TableParameter::DOUBLE, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter TertiaryFPOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input1", TableParameter::STRING_TABLE, true },
- { L"Validation.Input2", TableParameter::STRING_TABLE, true },
- { L"Validation.Input3", TableParameter::STRING_TABLE, true },
- { L"Validation.Expected", TableParameter::STRING_TABLE, true },
- { L"Validation.Type", TableParameter::STRING, true },
- { L"Validation.Tolerance", TableParameter::DOUBLE, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter UnaryIntOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input", TableParameter::INT_TABLE, true },
- { L"Validation.Expected", TableParameter::INT_TABLE, true },
- { L"Validation.Tolerance", TableParameter::INT, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter UnaryUintOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input", TableParameter::UINT_TABLE, true },
- { L"Validation.Expected", TableParameter::UINT_TABLE, true },
- { L"Validation.Tolerance", TableParameter::INT, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter BinaryIntOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.NumExpected", TableParameter::INT, true },
- { L"Validation.Input1", TableParameter::INT_TABLE, true },
- { L"Validation.Input2", TableParameter::INT_TABLE, true },
- { L"Validation.Expected1", TableParameter::INT_TABLE, true },
- { L"Validation.Expected2", TableParameter::INT_TABLE, false },
- { L"Validation.Tolerance", TableParameter::INT, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter TertiaryIntOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input1", TableParameter::INT_TABLE, true },
- { L"Validation.Input2", TableParameter::INT_TABLE, true },
- { L"Validation.Input3", TableParameter::INT_TABLE, true },
- { L"Validation.Expected", TableParameter::INT_TABLE, true },
- { L"Validation.Tolerance", TableParameter::INT, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter BinaryUintOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.NumExpected", TableParameter::INT, true },
- { L"Validation.Input1", TableParameter::UINT_TABLE, true },
- { L"Validation.Input2", TableParameter::UINT_TABLE, true },
- { L"Validation.Expected1", TableParameter::UINT_TABLE, true },
- { L"Validation.Expected2", TableParameter::UINT_TABLE, false },
- { L"Validation.Tolerance", TableParameter::INT, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter TertiaryUintOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input1", TableParameter::UINT_TABLE, true },
- { L"Validation.Input2", TableParameter::UINT_TABLE, true },
- { L"Validation.Input3", TableParameter::UINT_TABLE, true },
- { L"Validation.Expected", TableParameter::UINT_TABLE, true },
- { L"Validation.Tolerance", TableParameter::INT, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter DotOpParameters[] = {
- { L"ShaderOp.Name", TableParameter::STRING, true },
- { L"ShaderOp.Target", TableParameter::STRING, true },
- { L"ShaderOp.EntryPoint", TableParameter::STRING, true },
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Input1", TableParameter::STRING_TABLE, true },
- { L"Validation.Input2", TableParameter::STRING_TABLE, true },
- { L"Validation.dot2", TableParameter::STRING_TABLE, true },
- { L"Validation.dot3", TableParameter::STRING_TABLE, true },
- { L"Validation.dot4", TableParameter::STRING_TABLE, true },
- { L"Validation.Type", TableParameter::STRING, true },
- { L"Validation.Tolerance", TableParameter::DOUBLE, true },
- { L"Validation.NumInput", TableParameter::UINT, true }
- };
- static TableParameter Msad4OpParameters[] = {
- { L"ShaderOp.Text", TableParameter::STRING, true },
- { L"Validation.Tolerance", TableParameter::DOUBLE, true },
- { L"Validation.NumInput", TableParameter::UINT, true },
- { L"Validation.Reference", TableParameter::UINT_TABLE, true},
- { L"Validation.Source", TableParameter::STRING_TABLE, true },
- { L"Validation.Accum", TableParameter::STRING_TABLE, true },
- { L"Validation.Expected", TableParameter::STRING_TABLE, true }
- };
- static HRESULT ParseDataToFloat(PCWSTR str, float &value) {
- std::wstring wString(str);
- wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
- PCWSTR wstr = wString.data();
- if (_wcsicmp(wstr, L"NaN") == 0) {
- value = NAN;
- } else if (_wcsicmp(wstr, L"-inf") == 0) {
- value = -(INFINITY);
- } else if (_wcsicmp(wstr, L"inf") == 0) {
- value = INFINITY;
- } else if (_wcsicmp(wstr, L"-denorm") == 0) {
- value = -(FLT_MIN / 2);
- } else if (_wcsicmp(wstr, L"denorm") == 0) {
- value = FLT_MIN / 2;
- } else if (_wcsicmp(wstr, L"-0.0f") == 0 || _wcsicmp(wstr, L"-0.0") == 0 ||
- _wcsicmp(wstr, L"-0") == 0) {
- value = -0.0f;
- } else if (_wcsicmp(wstr, L"0.0f") == 0 || _wcsicmp(wstr, L"0.0") == 0 ||
- _wcsicmp(wstr, L"0") == 0) {
- value = 0.0f;
- } else {
- // evaluate the expression of wstring
- double val = _wtof(wstr);
- if (val == 0) {
- LogErrorFmt(L"Failed to parse parameter %s to float", wstr);
- return E_FAIL;
- }
- value = val;
- }
- return S_OK;
- }
- static HRESULT ParseDataToInt(PCWSTR str, int &value) {
- std::wstring wString(str);
- wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
- PCWSTR wstr = wString.data();
- // evaluate the expression of string
- if (_wcsicmp(wstr, L"0.0") == 0 || _wcsicmp(wstr, L"0") == 0) {
- value = 0;
- return S_OK;
- }
- int val = _wtoi(wstr);
- if (val == 0) {
- LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
- return E_FAIL;
- }
- value = val;
- return S_OK;
- }
- static HRESULT ParseDataToUint(PCWSTR str, unsigned int &value) {
- std::wstring wString(str);
- wString.erase(std::remove(wString.begin(), wString.end(), L' '), wString.end());
- PCWSTR wstr = wString.data();
- // evaluate the expression of string
- if (_wcsicmp(wstr, L"0") == 0 || _wcsicmp(wstr, L"0x00000000") == 0) {
- value = 0;
- return S_OK;
- }
- wchar_t *end;
- unsigned int val = std::wcstoul(wstr, &end, 0);
- if (val == 0) {
- LogErrorFmt(L"Failed to parse parameter %s to int", wstr);
- return E_FAIL;
- }
- value = val;
- return S_OK;
- }
- static HRESULT ParseDataToVectorFloat(PCWSTR str, float *ptr, size_t count) {
- std::wstring wstr(str);
- size_t curPosition = 0;
- // parse a string of dot product separated by commas
- for (size_t i = 0; i < count; ++i) {
- size_t nextPosition = wstr.find(L",", curPosition);
- if (FAILED(ParseDataToFloat(
- wstr.substr(curPosition, nextPosition - curPosition).data(),
- *(ptr + i)))) {
- return E_FAIL;
- }
- curPosition = nextPosition + 1;
- }
- return S_OK;
- }
- static HRESULT ParseDataToVectorUint(PCWSTR str, unsigned int *ptr, size_t count) {
- std::wstring wstr(str);
- size_t curPosition = 0;
- // parse a string of dot product separated by commas
- for (size_t i = 0; i < count; ++i) {
- size_t nextPosition = wstr.find(L",", curPosition);
- if (FAILED(ParseDataToUint(
- wstr.substr(curPosition, nextPosition - curPosition).data(),
- *(ptr + i)))) {
- return E_FAIL;
- }
- curPosition = nextPosition + 1;
- }
- return S_OK;
- }
- static HRESULT ParseTableRow(TableParameter *table, unsigned int size) {
- for (unsigned int i = 0; i < size; ++i) {
- switch (table[i].m_type) {
- case TableParameter::INT:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
- table[i].m_int)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::UINT:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
- table[i].m_uint)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::DOUBLE:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(
- table[i].m_name, table[i].m_double)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::STRING:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
- table[i].m_str)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::BOOL:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(table[i].m_name,
- table[i].m_str)) && table[i].m_bool) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::INT_TABLE:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(
- table[i].m_name, table[i].m_intTable)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::UINT_TABLE:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(
- table[i].m_name, table[i].m_uintTable)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::DOUBLE_TABLE:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(
- table[i].m_name, table[i].m_doubleTable)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- case TableParameter::STRING_TABLE:
- if (FAILED(WEX::TestExecution::TestData::TryGetValue(
- table[i].m_name, table[i].m_StringTable)) && table[i].m_required) {
- LogErrorFmt(L"Failed to get %s", table[i].m_name);
- return E_FAIL;
- }
- break;
- default:
- DXASSERT_NOMSG("Invalid Parameter Type");
- }
- }
- return S_OK;
- }
- static void VerifyOutputWithExpectedValueInt(int output, int ref, int tolerance) {
- VERIFY_IS_TRUE(output - ref <= tolerance && ref - output <= tolerance);
- }
- static void VerifyOutputWithExpectedValueFloat(float output, float ref, LPCWSTR type, double tolerance) {
- if (_wcsicmp(type, L"Relative") == 0) {
- VERIFY_IS_TRUE(CompareFloatRelativeEpsilon(output, ref, tolerance));
- }
- else if (_wcsicmp(type, L"Epsilon") == 0) {
- VERIFY_IS_TRUE(CompareFloatEpsilon(output, ref, tolerance));
- }
- else if (_wcsicmp(type, L"ULP") == 0) {
- VERIFY_IS_TRUE(CompareFloatULP(output, ref, (int)tolerance));
- }
- else {
- LogErrorFmt(L"Failed to read comparison type %S", type);
- }
- }
- TEST_F(ExecutionTest, UnaryFloatOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(ParseTableRow(UnaryFPOpParameters, sizeof(UnaryFPOpParameters)/sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(UnaryFPOpParameters[0].m_str);
- CW2A Target(UnaryFPOpParameters[1].m_str);
- CW2A EntryPoint(UnaryFPOpParameters[2].m_str);
- CW2A Text(UnaryFPOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input =
- &(UnaryFPOpParameters[4].m_StringTable);
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Expected =
- &(UnaryFPOpParameters[5].m_StringTable);
- LPCWSTR Validation_Type = UnaryFPOpParameters[6].m_str;
- double Validation_Tolerance = UnaryFPOpParameters[7].m_double;
- size_t count = UnaryFPOpParameters[8].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "UnaryFPOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryFPOp"));
- size_t size = sizeof(SUnaryFPOp) * count;
- Data.resize(size);
- SUnaryFPOp *pPrimitives = (SUnaryFPOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SUnaryFPOp *p = &pPrimitives[i];
- PCWSTR str = (*Validation_Input)[i % Validation_Input->GetSize()];
- float val;
- VERIFY_SUCCEEDED(ParseDataToFloat(str, val));
- p->input = val;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("SUnaryFPOp", &data);
- SUnaryFPOp *pPrimitives = (SUnaryFPOp*)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (unsigned i = 0; i < count; ++i) {
- SUnaryFPOp *p = &pPrimitives[i];
- LPCWSTR str = (*Validation_Expected)[i % Validation_Expected->GetSize()];
- float val;
- VERIFY_SUCCEEDED(ParseDataToFloat(str, val));
- LogCommentFmt(
- L"element #%u, input = %10f, output = %10f, expected = %10f", i,
- p->input, p->output, val);
- VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type, Validation_Tolerance);
- }
- }
- TEST_F(ExecutionTest, BinaryFloatOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(ParseTableRow(BinaryFPOpParameters, sizeof(BinaryFPOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(BinaryFPOpParameters[0].m_str);
- CW2A Target(BinaryFPOpParameters[1].m_str);
- CW2A EntryPoint(BinaryFPOpParameters[2].m_str);
- CW2A Text(BinaryFPOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input1 =
- &(BinaryFPOpParameters[4].m_StringTable);
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input2 =
- &(BinaryFPOpParameters[5].m_StringTable);
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Expected1 =
- &(BinaryFPOpParameters[6].m_StringTable);
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Expected2 =
- &(BinaryFPOpParameters[7].m_StringTable);
- LPCWSTR Validation_Type = BinaryFPOpParameters[8].m_str;
- double Validation_Tolerance = BinaryFPOpParameters[9].m_double;
- size_t count = BinaryFPOpParameters[10].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "BinaryFPOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryFPOp"));
- size_t size = sizeof(SBinaryFPOp) * count;
- Data.resize(size);
- SBinaryFPOp *pPrimitives = (SBinaryFPOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SBinaryFPOp *p = &pPrimitives[i];
- PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->GetSize()];
- PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->GetSize()];
- float val1, val2;
- VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
- VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
- p->input1 = val1;
- p->input2 = val2;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("SBinaryFPOp", &data);
- SBinaryFPOp *pPrimitives = (SBinaryFPOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (unsigned i = 0; i < count; ++i) {
- SBinaryFPOp *p = &pPrimitives[i];
- LPCWSTR str1 = (*Validation_Expected1)[i % Validation_Expected1->GetSize()];
- LPCWSTR str2 = (*Validation_Expected2)[i % Validation_Expected2->GetSize()];
- float val1, val2;
- VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
- VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
- LogCommentFmt(L"element #%u, input1 = %10f, input2 = %10f, output1 = "
- L"%10f, expected1 = %10f, output2 = %10f, expected2 = %10f",
- i, p->input1, p->input2, p->output1, val1, p->output2,
- val2);
- VerifyOutputWithExpectedValueFloat(p->output1, val1, Validation_Type,
- Validation_Tolerance);
- VerifyOutputWithExpectedValueFloat(p->output2, val2, Validation_Type,
- Validation_Tolerance);
- }
- }
- TEST_F(ExecutionTest, TertiaryFloatOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(ParseTableRow(TertiaryFPOpParameters, sizeof(TertiaryFPOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(TertiaryFPOpParameters[0].m_str);
- CW2A Target(TertiaryFPOpParameters[1].m_str);
- CW2A EntryPoint(TertiaryFPOpParameters[2].m_str);
- CW2A Text(TertiaryFPOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input1 =
- &(TertiaryFPOpParameters[4].m_StringTable);
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input2 =
- &(TertiaryFPOpParameters[5].m_StringTable);
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input3 =
- &(TertiaryFPOpParameters[6].m_StringTable);
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Expected =
- &(TertiaryFPOpParameters[7].m_StringTable);
- LPCWSTR Validation_Type = TertiaryFPOpParameters[8].m_str;
- double Validation_Tolerance = TertiaryFPOpParameters[9].m_double;
- size_t count = TertiaryFPOpParameters[10].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "TertiaryFPOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryFPOp"));
- size_t size = sizeof(STertiaryFPOp) * count;
- Data.resize(size);
- STertiaryFPOp *pPrimitives = (STertiaryFPOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- STertiaryFPOp *p = &pPrimitives[i];
- PCWSTR str1 = (*Validation_Input1)[i % Validation_Input1->GetSize()];
- PCWSTR str2 = (*Validation_Input2)[i % Validation_Input2->GetSize()];
- PCWSTR str3 = (*Validation_Input3)[i % Validation_Input3->GetSize()];
- float val1, val2, val3;
- VERIFY_SUCCEEDED(ParseDataToFloat(str1, val1));
- VERIFY_SUCCEEDED(ParseDataToFloat(str2, val2));
- VERIFY_SUCCEEDED(ParseDataToFloat(str3, val3));
- p->input1 = val1;
- p->input2 = val2;
- p->input3 = val3;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("STertiaryFPOp", &data);
- STertiaryFPOp *pPrimitives = (STertiaryFPOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (unsigned i = 0; i < count; ++i) {
- STertiaryFPOp *p = &pPrimitives[i];
- LPCWSTR str = (*Validation_Expected)[i % Validation_Expected->GetSize()];
- float val;
- VERIFY_SUCCEEDED(ParseDataToFloat(str, val));
- LogCommentFmt(L"element #%u, input1 = %10f, input2 = %10f, input3 = %10f, output1 = "
- L"%10f, expected = %10f",
- i, p->input1, p->input2, p->input3, p->output, val);
- VerifyOutputWithExpectedValueFloat(p->output, val, Validation_Type,
- Validation_Tolerance);
- }
- }
- TEST_F(ExecutionTest, UnaryIntOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(ParseTableRow(UnaryIntOpParameters,
- sizeof(UnaryIntOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(UnaryIntOpParameters[0].m_str);
- CW2A Target(UnaryIntOpParameters[1].m_str);
- CW2A EntryPoint(UnaryIntOpParameters[2].m_str);
- CW2A Text(UnaryIntOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<int> *Validation_Input =
- &UnaryIntOpParameters[4].m_intTable;
- WEX::TestExecution::TestDataArray<int> *Validation_Expected =
- &UnaryIntOpParameters[5].m_intTable;
- int Validation_Tolerance = UnaryIntOpParameters[6].m_int;
- size_t count = UnaryIntOpParameters[7].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "UnaryIntOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryIntOp"));
- size_t size = sizeof(SUnaryIntOp) * count;
- Data.resize(size);
- SUnaryIntOp *pPrimitives = (SUnaryIntOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SUnaryIntOp *p = &pPrimitives[i];
- int val = (*Validation_Input)[i % Validation_Input->GetSize()];
- p->input = val;
- }
- // use shader data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("SUnaryIntOp", &data);
- SUnaryIntOp *pPrimitives = (SUnaryIntOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (unsigned i = 0; i < count; ++i) {
- SUnaryIntOp *p = &pPrimitives[i];
- int val = (*Validation_Expected)[i % Validation_Expected->GetSize()];
- LogCommentFmt(L"element #%u, input = %11i(0x%08x), output = %11i(0x%08x), "
- L"expected = %11i(0x%08x)",
- i, p->input, p->input, p->output, p->output, val, val);
- VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
- }
- }
- TEST_F(ExecutionTest, UnaryUintOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(ParseTableRow(UnaryUintOpParameters,
- sizeof(UnaryUintOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(UnaryUintOpParameters[0].m_str);
- CW2A Target(UnaryUintOpParameters[1].m_str);
- CW2A EntryPoint(UnaryUintOpParameters[2].m_str);
- CW2A Text(UnaryUintOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Input =
- &UnaryUintOpParameters[4].m_uintTable;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Expected =
- &UnaryUintOpParameters[5].m_uintTable;
- int Validation_Tolerance = UnaryUintOpParameters[6].m_int;
- size_t count = UnaryUintOpParameters[7].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "UnaryUintOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SUnaryUintOp"));
- size_t size = sizeof(SUnaryUintOp) * count;
- Data.resize(size);
- SUnaryUintOp *pPrimitives = (SUnaryUintOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SUnaryUintOp *p = &pPrimitives[i];
- unsigned int val = (*Validation_Input)[i % Validation_Input->GetSize()];
- p->input = val;
- }
- // use shader data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("SUnaryUintOp", &data);
- SUnaryUintOp *pPrimitives = (SUnaryUintOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (unsigned i = 0; i < count; ++i) {
- SUnaryUintOp *p = &pPrimitives[i];
- unsigned int val = (*Validation_Expected)[i % Validation_Expected->GetSize()];
- LogCommentFmt(L"element #%u, input = %11u(0x%08x), output = %11u(0x%08x), "
- L"expected = %11u(0x%08x)",
- i, p->input, p->input, p->output, p->output, val, val);
- VerifyOutputWithExpectedValueInt(p->output, val, Validation_Tolerance);
- }
- }
- TEST_F(ExecutionTest, BinaryIntOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(
- ParseTableRow(BinaryIntOpParameters,
- sizeof(BinaryIntOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(BinaryIntOpParameters[0].m_str);
- CW2A Target(BinaryIntOpParameters[1].m_str);
- CW2A EntryPoint(BinaryIntOpParameters[2].m_str);
- CW2A Text(BinaryIntOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- int numExpected = BinaryIntOpParameters[4].m_int;
- WEX::TestExecution::TestDataArray<int> *Validation_Input1 =
- &BinaryIntOpParameters[5].m_intTable;
- WEX::TestExecution::TestDataArray<int> *Validation_Input2 =
- &BinaryIntOpParameters[6].m_intTable;
- WEX::TestExecution::TestDataArray<int> *Validation_Expected1 =
- &BinaryIntOpParameters[7].m_intTable;
- WEX::TestExecution::TestDataArray<int> *Validation_Expected2 =
- &BinaryIntOpParameters[8].m_intTable;
- int Validation_Tolerance = BinaryIntOpParameters[9].m_int;
- size_t count = BinaryIntOpParameters[10].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "BinaryIntOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryIntOp"));
- size_t size = sizeof(SBinaryIntOp) * count;
- Data.resize(size);
- SBinaryIntOp *pPrimitives = (SBinaryIntOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SBinaryIntOp *p = &pPrimitives[i];
- int val1 = (*Validation_Input1)[i % Validation_Input1->GetSize()];
- int val2 = (*Validation_Input2)[i % Validation_Input2->GetSize()];
- p->input1 = val1;
- p->input2 = val2;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("SBinaryIntOp", &data);
- SBinaryIntOp *pPrimitives = (SBinaryIntOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- if (numExpected == 2) {
- for (unsigned i = 0; i < count; ++i) {
- SBinaryIntOp *p = &pPrimitives[i];
- int val1 = (*Validation_Expected1)[i % Validation_Expected1->GetSize()];
- int val2 = (*Validation_Expected2)[i % Validation_Expected2->GetSize()];
- LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
- L"%11i(0x%08x), output1 = "
- L"%11i(0x%08x), expected1 = %11i(0x%08x), output2 = "
- L"%11i(0x%08x), expected2 = %11i(0x%08x)",
- i, p->input1, p->input1, p->input2, p->input2, p->output1,
- p->output1, val1, val1, p->output2, p->output2, val2,
- val2);
- VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
- VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
- }
- }
- else if (numExpected == 1) {
- for (unsigned i = 0; i < count; ++i) {
- SBinaryIntOp *p = &pPrimitives[i];
- int val1 = (*Validation_Expected1)[i % Validation_Expected1->GetSize()];
- LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
- L"%11i(0x%08x), output = "
- L"%11i(0x%08x), expected = %11i(0x%08x)", i,
- p->input1, p->input1, p->input2, p->input2,
- p->output1, p->output1, val1, val1);
- VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
- }
- }
- else {
- LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
- }
- }
- TEST_F(ExecutionTest, TertiaryIntOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(
- ParseTableRow(TertiaryIntOpParameters,
- sizeof(TertiaryIntOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(TertiaryIntOpParameters[0].m_str);
- CW2A Target(TertiaryIntOpParameters[1].m_str);
- CW2A EntryPoint(TertiaryIntOpParameters[2].m_str);
- CW2A Text(TertiaryIntOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<int> *Validation_Input1 =
- &TertiaryIntOpParameters[4].m_intTable;
- WEX::TestExecution::TestDataArray<int> *Validation_Input2 =
- &TertiaryIntOpParameters[5].m_intTable;
- WEX::TestExecution::TestDataArray<int> *Validation_Input3 =
- &TertiaryIntOpParameters[6].m_intTable;
- WEX::TestExecution::TestDataArray<int> *Validation_Expected =
- &TertiaryIntOpParameters[7].m_intTable;
- int Validation_Tolerance = TertiaryIntOpParameters[8].m_int;
- size_t count = TertiaryIntOpParameters[9].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "TertiaryIntOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryIntOp"));
- size_t size = sizeof(STertiaryIntOp) * count;
- Data.resize(size);
- STertiaryIntOp *pPrimitives = (STertiaryIntOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- STertiaryIntOp *p = &pPrimitives[i];
- int val1 = (*Validation_Input1)[i % Validation_Input1->GetSize()];
- int val2 = (*Validation_Input2)[i % Validation_Input2->GetSize()];
- int val3 = (*Validation_Input3)[i % Validation_Input3->GetSize()];
- p->input1 = val1;
- p->input2 = val2;
- p->input3 = val3;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("STertiaryIntOp", &data);
- STertiaryIntOp *pPrimitives = (STertiaryIntOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (unsigned i = 0; i < count; ++i) {
- STertiaryIntOp *p = &pPrimitives[i];
- int val1 = (*Validation_Expected)[i % Validation_Expected->GetSize()];
- LogCommentFmt(L"element #%u, input1 = %11i(0x%08x), input2 = "
- L"%11i(0x%08x), input3= %11i(0x%08x), output = "
- L"%11i(0x%08x), expected = %11i(0x%08x)",
- i, p->input1, p->input1, p->input2, p->input2,
- p->input3, p->input3, p->output, p->output, val1,
- val1);
- VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
- }
- }
- TEST_F(ExecutionTest, BinaryUintOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(
- ParseTableRow(BinaryUintOpParameters,
- sizeof(BinaryUintOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(BinaryUintOpParameters[0].m_str);
- CW2A Target(BinaryUintOpParameters[1].m_str);
- CW2A EntryPoint(BinaryUintOpParameters[2].m_str);
- CW2A Text(BinaryUintOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- int numExpected = BinaryUintOpParameters[4].m_int;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Input1 =
- &BinaryUintOpParameters[5].m_uintTable;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Input2 =
- &BinaryUintOpParameters[6].m_uintTable;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Expected1 =
- &BinaryUintOpParameters[7].m_uintTable;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Expected2 =
- &BinaryUintOpParameters[8].m_uintTable;
- int Validation_Tolerance = BinaryUintOpParameters[9].m_int;
- size_t count = BinaryUintOpParameters[10].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "BinaryUintOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SBinaryUintOp"));
- size_t size = sizeof(SBinaryUintOp) * count;
- Data.resize(size);
- SBinaryUintOp *pPrimitives = (SBinaryUintOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SBinaryUintOp *p = &pPrimitives[i];
- unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->GetSize()];
- unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->GetSize()];
- p->input1 = val1;
- p->input2 = val2;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("SBinaryUintOp", &data);
- SBinaryUintOp *pPrimitives = (SBinaryUintOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- if (numExpected == 2) {
- for (unsigned i = 0; i < count; ++i) {
- SBinaryUintOp *p = &pPrimitives[i];
- unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->GetSize()];
- unsigned int val2 = (*Validation_Expected2)[i % Validation_Expected2->GetSize()];
- LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
- L"%11u(0x%08x), output1 = "
- L"%11u(0x%08x), expected1 = %11u(0x%08x), output2 = "
- L"%11u(0x%08x), expected2 = %11u(0x%08x)",
- i, p->input1, p->input1, p->input2, p->input2, p->output1,
- p->output1, val1, val1, p->output2, p->output2, val2,
- val2);
- VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
- VerifyOutputWithExpectedValueInt(p->output2, val2, Validation_Tolerance);
- }
- }
- else if (numExpected == 1) {
- for (unsigned i = 0; i < count; ++i) {
- SBinaryUintOp *p = &pPrimitives[i];
- unsigned int val1 = (*Validation_Expected1)[i % Validation_Expected1->GetSize()];
- LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
- L"%11u(0x%08x), output = "
- L"%11u(0x%08x), expected = %11u(0x%08x)", i,
- p->input1, p->input1, p->input2, p->input2,
- p->output1, p->output1, val1, val1);
- VerifyOutputWithExpectedValueInt(p->output1, val1, Validation_Tolerance);
- }
- }
- else {
- LogErrorFmt(L"Unexpected number of expected values for operation %i", numExpected);
- }
- }
- TEST_F(ExecutionTest, TertiaryUintOpTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- // Read data from the table
- VERIFY_SUCCEEDED(
- ParseTableRow(TertiaryUintOpParameters,
- sizeof(TertiaryUintOpParameters) / sizeof(TableParameter)));
- st::ShaderOpShader shader;
- CW2A Name(TertiaryUintOpParameters[0].m_str);
- CW2A Target(TertiaryUintOpParameters[1].m_str);
- CW2A EntryPoint(TertiaryUintOpParameters[2].m_str);
- CW2A Text(TertiaryUintOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Input1 =
- &TertiaryUintOpParameters[4].m_uintTable;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Input2 =
- &TertiaryUintOpParameters[5].m_uintTable;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Input3 =
- &TertiaryUintOpParameters[6].m_uintTable;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Expected =
- &TertiaryUintOpParameters[7].m_uintTable;
- int Validation_Tolerance = TertiaryUintOpParameters[8].m_int;
- size_t count = TertiaryUintOpParameters[9].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "TertiaryUintOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "STertiaryUintOp"));
- size_t size = sizeof(STertiaryUintOp) * count;
- Data.resize(size);
- STertiaryUintOp *pPrimitives = (STertiaryUintOp *)Data.data();
- for (size_t i = 0; i < count; ++i) {
- STertiaryUintOp *p = &pPrimitives[i];
- unsigned int val1 = (*Validation_Input1)[i % Validation_Input1->GetSize()];
- unsigned int val2 = (*Validation_Input2)[i % Validation_Input2->GetSize()];
- unsigned int val3 = (*Validation_Input3)[i % Validation_Input3->GetSize()];
- p->input1 = val1;
- p->input2 = val2;
- p->input3 = val3;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("STertiaryUintOp", &data);
- STertiaryUintOp *pPrimitives = (STertiaryUintOp *)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (unsigned i = 0; i < count; ++i) {
- STertiaryUintOp *p = &pPrimitives[i];
- unsigned int val1 = (*Validation_Expected)[i % Validation_Expected->GetSize()];
- LogCommentFmt(L"element #%u, input1 = %11u(0x%08x), input2 = "
- L"%11u(0x%08x), input3 = %11u(0x%08x), output = "
- L"%11u(0x%08x), expected = %11u(0x%08x)", i,
- p->input1, p->input1, p->input2, p->input2, p->input3, p->input3,
- p->output, p->output, val1, val1);
- VerifyOutputWithExpectedValueInt(p->output, val1, Validation_Tolerance);
- }
- }
- TEST_F(ExecutionTest, DotTest) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- VERIFY_SUCCEEDED(ParseTableRow(
- DotOpParameters, sizeof(DotOpParameters) / sizeof(DotOpParameters[0])));
- st::ShaderOpShader shader;
- CW2A Name(DotOpParameters[0].m_str);
- CW2A Target(DotOpParameters[1].m_str);
- CW2A EntryPoint(DotOpParameters[2].m_str);
- CW2A Text(DotOpParameters[3].m_str);
- shader.Name = Name.m_psz;
- shader.Target = Target.m_psz;
- shader.EntryPoint = EntryPoint.m_psz;
- shader.Text = Text.m_psz;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input1 =
- &DotOpParameters[4].m_StringTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Input2 =
- &DotOpParameters[5].m_StringTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_dot2 =
- &DotOpParameters[6].m_StringTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_dot3 =
- &DotOpParameters[7].m_StringTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_dot4 =
- &DotOpParameters[8].m_StringTable;
- PCWSTR Validation_type = DotOpParameters[9].m_str;
- double tolerance = DotOpParameters[10].m_double;
- unsigned int count = DotOpParameters[11].m_uint;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "DotOp",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SDotOp"));
- size_t size = sizeof(SDotOp) * count;
- Data.resize(size);
- SDotOp *pPrimitives = (SDotOp*)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SDotOp *p = &pPrimitives[i];
- float4 val1,val2;
- VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input1)[i],
- (float *)&val1, 4));
- VERIFY_SUCCEEDED(ParseDataToVectorFloat((*Validation_Input2)[i],
- (float *)&val2, 4));
- p->input1 = val1;
- p->input2 = val2;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = shader.Text;
- });
- MappedData data;
- test->Test->GetReadBackData("SDotOp", &data);
- SDotOp *pPrimitives = (SDotOp*)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (size_t i = 0; i < count; ++i) {
- SDotOp *p = &pPrimitives[i];
- float dot2, dot3, dot4;
- VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot2)[i], dot2));
- VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot3)[i], dot3));
- VERIFY_SUCCEEDED(ParseDataToFloat((*Validation_dot4)[i], dot4));
- LogCommentFmt(
- L"element #%u, input1 = (%f, %f, %f, %f), input2 = (%f, %f, "
- L"%f, %f), \n dot2 = %f, dot2_expected = %f, dot3 = %f, "
- L"dot3_expected = %f, dot4 = %f, dot4_expected = %f",
- i, p->input1.x, p->input1.y, p->input1.z, p->input1.w, p->input2.x,
- p->input2.y, p->input2.z, p->input2.w, p->o_dot2, dot2, p->o_dot3, dot3,
- p->o_dot4, dot4);
- VerifyOutputWithExpectedValueFloat(p->o_dot2, dot2, Validation_type,
- tolerance);
- VerifyOutputWithExpectedValueFloat(p->o_dot3, dot3, Validation_type,
- tolerance);
- VerifyOutputWithExpectedValueFloat(p->o_dot4, dot4, Validation_type,
- tolerance);
- }
- }
- TEST_F(ExecutionTest, Msad4Test) {
- WEX::TestExecution::SetVerifyOutput verifySettings(
- WEX::TestExecution::VerifyOutputSettings::LogOnlyFailures);
- CComPtr<IStream> pStream;
- ReadHlslDataIntoNewStream(L"ShaderOpArith.xml", &pStream);
- CComPtr<ID3D12Device> pDevice;
- if (!CreateDevice(&pDevice)) {
- return;
- }
- VERIFY_SUCCEEDED(ParseTableRow(
- Msad4OpParameters, sizeof(Msad4OpParameters) / sizeof(Msad4OpParameters[0])));
- CW2A Text(Msad4OpParameters[0].m_str);
- double tolerance = Msad4OpParameters[1].m_double;
- unsigned int count = Msad4OpParameters[2].m_uint;
- WEX::TestExecution::TestDataArray<unsigned int> *Validation_Reference =
- &Msad4OpParameters[3].m_uintTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Source =
- &Msad4OpParameters[4].m_StringTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Accum =
- &Msad4OpParameters[5].m_StringTable;
- WEX::TestExecution::TestDataArray<WEX::Common::String> *Validation_Expected =
- &Msad4OpParameters[6].m_StringTable;
- std::shared_ptr<ShaderOpTestResult> test = RunShaderOpTest(
- pDevice, m_support, pStream, "Msad4",
- // this callbacked is called when the test
- // is creating the resource to run the test
- [&](LPCSTR Name, std::vector<BYTE> &Data, st::ShaderOp *pShaderOp) {
- VERIFY_IS_TRUE(0 == _stricmp(Name, "SMsad4"));
- size_t size = sizeof(SMsad4) * count;
- Data.resize(size);
- SMsad4 *pPrimitives = (SMsad4*)Data.data();
- for (size_t i = 0; i < count; ++i) {
- SMsad4 *p = &pPrimitives[i];
- uint2 src;
- uint4 accum;
- VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Source)[i], (unsigned int*)&src, 2));
- VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Accum)[i], (unsigned int*)&accum, 4));
- p->ref = (*Validation_Reference)[i];
- p->src = src;
- p->accum = accum;
- }
- // use shader from data table
- pShaderOp->Shaders.at(0).Text = Text.m_psz;
- });
- MappedData data;
- test->Test->GetReadBackData("SMsad4", &data);
- SMsad4 *pPrimitives = (SMsad4*)data.data();
- WEX::TestExecution::DisableVerifyExceptions dve;
- for (size_t i = 0; i < count; ++i) {
- SMsad4 *p = &pPrimitives[i];
- uint4 result;
- VERIFY_SUCCEEDED(ParseDataToVectorUint((*Validation_Expected)[i],
- (unsigned int *)&result, 4));
- LogCommentFmt(
- L"element #%u, ref = %u(0x%08x), src = %u(0x%08x), %u(0x%08x), "
- L"accum = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
- L"result = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x),\n"
- L"expected = %u(0x%08x), %u(0x%08x), %u(0x%08x), %u(0x%08x)", i,
- p->ref, p->ref, p->src.x, p->src.x, p->src.y, p->src.y, p->accum.x,
- p->accum.x, p->accum.y, p->accum.y, p->accum.z, p->accum.z,
- p->accum.w, p->accum.w, p->result.x, p->result.x, p->result.y,
- p->result.y, p->result.z, p->result.z, p->result.w, p->result.w,
- result.x, result.x, result.y, result.y, result.z, result.z,
- result.w, result.w);
- VerifyOutputWithExpectedValueInt(p->result.x, result.x, tolerance);
- VerifyOutputWithExpectedValueInt(p->result.y, result.y, tolerance);
- VerifyOutputWithExpectedValueInt(p->result.z, result.z, tolerance);
- VerifyOutputWithExpectedValueInt(p->result.w, result.w, tolerance);
- }
- }
- static void WriteReadBackDump(st::ShaderOp *pShaderOp, st::ShaderOpTest *pTest,
- char **pReadBackDump) {
- std::stringstream str;
- unsigned count = 0;
- for (auto &R : pShaderOp->Resources) {
- if (!R.ReadBack)
- continue;
- ++count;
- str << "Resource: " << R.Name << "\r\n";
- // Find a descriptor that can tell us how to dump this resource.
- bool found = false;
- for (auto &Heaps : pShaderOp->DescriptorHeaps) {
- for (auto &D : Heaps.Descriptors) {
- if (_stricmp(D.ResName, R.Name) != 0) {
- continue;
- }
- found = true;
- if (_stricmp(D.Kind, "UAV") != 0) {
- str << "Resource dump for kind " << D.Kind << " not implemented yet.\r\n";
- break;
- }
- if (D.UavDesc.ViewDimension != D3D12_UAV_DIMENSION_BUFFER) {
- str << "Resource dump for this kind of view dimension not implemented yet.\r\n";
- break;
- }
- // We can map back to the structure if a structured buffer via the shader, but
- // we'll keep this simple and simply dump out 32-bit uint/float representations.
- MappedData data;
- pTest->GetReadBackData(R.Name, &data);
- uint32_t *pData = (uint32_t *)data.data();
- size_t u32_count = R.Desc.Width / sizeof(uint32_t);
- for (size_t i = 0; i < u32_count; ++i) {
- float f = *(float *)pData;
- str << i << ": 0n" << *pData << " 0x" << std::hex << *pData
- << std::dec << " " << f << "\r\n";
- ++pData;
- }
- break;
- }
- if (found) break;
- }
- if (!found) {
- str << "Unable to find a view for the resource.\r\n";
- }
- }
- str << "Resources read back: " << count << "\r\n";
- std::string s(str.str());
- CComHeapPtr<char> pDump;
- if (!pDump.Allocate(s.size() + 1))
- throw std::bad_alloc();
- memcpy(pDump.m_pData, s.data(), s.size());
- pDump.m_pData[s.size()] = '\0';
- *pReadBackDump = pDump.Detach();
- }
- // This is the exported interface by use from HLSLHost.exe.
- // It's exclusive with the use of the DLL as a TAEF target.
- extern "C" {
- __declspec(dllexport) HRESULT WINAPI InitializeOpTests(void *pStrCtx, st::OutputStringFn pOutputStrFn) {
- HRESULT hr = EnableExperimentalShaderModels();
- if (FAILED(hr)) {
- pOutputStrFn(pStrCtx, L"Unable to enable experimental shader models.\r\n.");
- }
- return S_OK;
- }
- __declspec(dllexport) HRESULT WINAPI
- RunOpTest(void *pStrCtx, st::OutputStringFn pOutputStrFn, LPCSTR pText,
- ID3D12Device *pDevice, ID3D12CommandQueue *pCommandQueue,
- ID3D12Resource *pRenderTarget, char **pReadBackDump) {
- HRESULT hr;
- if (pReadBackDump) *pReadBackDump = nullptr;
- st::SetOutputFn(pStrCtx, pOutputStrFn);
- CComPtr<ID3D12InfoQueue> pInfoQueue;
- CComHeapPtr<char> pDump;
- bool FilterCreation = false;
- if (SUCCEEDED(pDevice->QueryInterface(&pInfoQueue))) {
- // Creation is largely driven by inputs, so don't log create/destroy messages.
- pInfoQueue->PushEmptyStorageFilter();
- pInfoQueue->PushEmptyRetrievalFilter();
- if (FilterCreation) {
- D3D12_INFO_QUEUE_FILTER filter;
- D3D12_MESSAGE_CATEGORY denyCategories[] = { D3D12_MESSAGE_CATEGORY_STATE_CREATION };
- ZeroMemory(&filter, sizeof(filter));
- filter.DenyList.NumCategories = _countof(denyCategories);
- filter.DenyList.pCategoryList = denyCategories;
- pInfoQueue->PushStorageFilter(&filter);
- }
- }
- else {
- pOutputStrFn(pStrCtx, L"Unable to enable info queue for D3D.\r\n.");
- }
- try {
- dxc::DxcDllSupport m_support;
- m_support.Initialize();
- const char *pName = nullptr;
- CComPtr<IStream> pStream = SHCreateMemStream((BYTE *)pText, strlen(pText));
- std::shared_ptr<st::ShaderOpSet> ShaderOpSet =
- std::make_shared<st::ShaderOpSet>();
- st::ParseShaderOpSetFromStream(pStream, ShaderOpSet.get());
- st::ShaderOp *pShaderOp;
- if (pName == nullptr) {
- if (ShaderOpSet->ShaderOps.size() != 1) {
- pOutputStrFn(pStrCtx, L"Expected a single shader operation.\r\n");
- return E_FAIL;
- }
- pShaderOp = ShaderOpSet->ShaderOps[0].get();
- }
- else {
- pShaderOp = ShaderOpSet->GetShaderOp(pName);
- }
- if (pShaderOp == nullptr) {
- std::string msg = "Unable to find shader op ";
- msg += pName;
- msg += "; available ops";
- const char sep = ':';
- for (auto &pAvailOp : ShaderOpSet->ShaderOps) {
- msg += sep;
- msg += pAvailOp->Name ? pAvailOp->Name : "[n/a]";
- }
- CA2W msgWide(msg.c_str());
- pOutputStrFn(pStrCtx, msgWide);
- return E_FAIL;
- }
- std::shared_ptr<st::ShaderOpTest> test = std::make_shared<st::ShaderOpTest>();
- test->SetupRenderTarget(pShaderOp, pDevice, pCommandQueue, pRenderTarget);
- test->SetDxcSupport(&m_support);
- test->RunShaderOp(pShaderOp);
- test->PresentRenderTarget(pShaderOp, pCommandQueue, pRenderTarget);
- pOutputStrFn(pStrCtx, L"Rendering complete.\r\n");
- if (!pShaderOp->IsCompute()) {
- D3D12_QUERY_DATA_PIPELINE_STATISTICS stats;
- test->GetPipelineStats(&stats);
- wchar_t statsText[400];
- StringCchPrintfW(statsText, _countof(statsText),
- L"Vertices/primitives read by input assembler: %I64u/%I64u\r\n"
- L"Vertex shader invocations: %I64u\r\n"
- L"Geometry shader invocations/output primitive: %I64u/%I64u\r\n"
- L"Primitives sent to rasterizer/rendered: %I64u/%I64u\r\n"
- L"PS/HS/DS/CS invocations: %I64u/%I64u/%I64u/%I64u\r\n",
- stats.IAVertices, stats.IAPrimitives, stats.VSInvocations,
- stats.GSInvocations, stats.GSPrimitives, stats.CInvocations,
- stats.CPrimitives, stats.PSInvocations, stats.HSInvocations,
- stats.DSInvocations, stats.CSInvocations);
- pOutputStrFn(pStrCtx, statsText);
- }
- if (pReadBackDump) {
- WriteReadBackDump(pShaderOp, test.get(), &pDump);
- }
- hr = S_OK;
- }
- catch (const CAtlException &E)
- {
- hr = E.m_hr;
- }
- catch (const std::bad_alloc &)
- {
- hr = E_OUTOFMEMORY;
- }
- catch (const std::exception &)
- {
- hr = E_FAIL;
- }
- // Drain the device message queue if available.
- if (pInfoQueue != nullptr) {
- wchar_t buf[200];
- StringCchPrintfW(buf, _countof(buf),
- L"NumStoredMessages=%u limit/discarded by limit=%u/%u "
- L"allowed/denied by storage filter=%u/%u "
- L"NumStoredMessagesAllowedByRetrievalFilter=%u\r\n",
- (unsigned)pInfoQueue->GetNumStoredMessages(),
- (unsigned)pInfoQueue->GetMessageCountLimit(),
- (unsigned)pInfoQueue->GetNumMessagesDiscardedByMessageCountLimit(),
- (unsigned)pInfoQueue->GetNumMessagesAllowedByStorageFilter(),
- (unsigned)pInfoQueue->GetNumMessagesDeniedByStorageFilter(),
- (unsigned)pInfoQueue->GetNumStoredMessagesAllowedByRetrievalFilter());
- pOutputStrFn(pStrCtx, buf);
- WriteInfoQueueMessages(pStrCtx, pOutputStrFn, pInfoQueue);
- pInfoQueue->ClearStoredMessages();
- pInfoQueue->PopRetrievalFilter();
- pInfoQueue->PopStorageFilter();
- if (FilterCreation) {
- pInfoQueue->PopStorageFilter();
- }
- }
- if (pReadBackDump) *pReadBackDump = pDump.Detach();
- return hr;
- }
- }
|