@@ -53,140 +53,6 @@ static int elemSize(ComponentType CT) {
5353 }
5454}
5555
56- // / Create a ShaderOp for a compute shader dispatch.
57- static std::unique_ptr<st::ShaderOp>
58- createComputeOp (const char *Source, const char *Target, const char *RootSig,
59- const char *Args = nullptr , UINT DispatchX = 1 ,
60- UINT DispatchY = 1 , UINT DispatchZ = 1 ) {
61- auto Op = std::make_unique<st::ShaderOp>();
62- LPCSTR CSName = Op->Strings .insert (" CS" );
63- Op->Name = CSName;
64- Op->CS = CSName;
65- Op->RootSignature = Op->Strings .insert (RootSig);
66- Op->DispatchX = DispatchX;
67- Op->DispatchY = DispatchY;
68- Op->DispatchZ = DispatchZ;
69- Op->UseWarpDevice = true ;
70-
71- st::ShaderOpShader Shader = {};
72- Shader.Name = CSName;
73- Shader.Target = Op->Strings .insert (Target);
74- Shader.EntryPoint = Op->Strings .insert (" main" );
75- Shader.Text = Op->Strings .insert (Source);
76- Shader.Arguments = Args ? Op->Strings .insert (Args) : nullptr ;
77- Shader.Compiled = FALSE ;
78- Shader.Callback = FALSE ;
79- Op->Shaders .push_back (Shader);
80-
81- return Op;
82- }
83-
84- // / Add a UAV buffer resource to a ShaderOp.
85- static void addUAVBuffer (st::ShaderOp *Op, const char *Name, UINT64 Width,
86- bool ReadBack, const char *Init = " zero" ) {
87- st::ShaderOpResource Res = {};
88- Res.Name = Op->Strings .insert (Name);
89- Res.Init = Op->Strings .insert (Init);
90- Res.ReadBack = ReadBack ? TRUE : FALSE ;
91-
92- Res.HeapProperties .Type = D3D12_HEAP_TYPE_DEFAULT;
93- Res.HeapFlags = D3D12_HEAP_FLAG_NONE;
94- Res.Desc .Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
95- Res.Desc .Width = Width;
96- Res.Desc .Height = 1 ;
97- Res.Desc .DepthOrArraySize = 1 ;
98- Res.Desc .MipLevels = 1 ;
99- Res.Desc .SampleDesc .Count = 1 ;
100- Res.Desc .Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
101- Res.Desc .Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
102- Res.InitialResourceState = D3D12_RESOURCE_STATE_COPY_DEST;
103- Res.TransitionTo = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
104-
105- Op->Resources .push_back (Res);
106- }
107-
108- // / Bind a resource to a root UAV parameter by index.
109- static void addRootUAV (st::ShaderOp *Op, UINT Index, const char *ResName) {
110- st::ShaderOpRootValue RV = {};
111- RV.ResName = Op->Strings .insert (ResName);
112- RV.HeapName = nullptr ;
113- RV.Index = Index;
114- Op->RootValues .push_back (RV);
115- }
116-
117- // / Run a programmatically-built ShaderOp and return the result.
118- static std::shared_ptr<st::ShaderOpTestResult>
119- runShaderOp (ID3D12Device *Device, dxc::SpecificDllLoader &DxcSupport,
120- std::unique_ptr<st::ShaderOp> Op,
121- st::ShaderOpTest::TInitCallbackFn InitCallback = nullptr ) {
122- auto OpSet = std::make_shared<st::ShaderOpSet>();
123- OpSet->ShaderOps .push_back (std::move (Op));
124-
125- return st::RunShaderOpTestAfterParse (
126- Device, DxcSupport, nullptr , std::move (InitCallback), std::move (OpSet));
127- }
128-
129- // / Compiles an HLSL shader using the DXC API to verify it is well-formed.
130- // / Fails the test on compile error.
131- static void compileShader (dxc::SpecificDllLoader &DxcSupport,
132- const char *Source, const char *Target,
133- const std::string &Args) {
134- CComPtr<IDxcCompiler3> Compiler;
135- VERIFY_SUCCEEDED (DxcSupport.CreateInstance (CLSID_DxcCompiler, &Compiler));
136-
137- CComPtr<IDxcUtils> Utils;
138- VERIFY_SUCCEEDED (DxcSupport.CreateInstance (CLSID_DxcUtils, &Utils));
139-
140- CComPtr<IDxcBlobEncoding> SourceBlob;
141- VERIFY_SUCCEEDED (Utils->CreateBlobFromPinned (
142- Source, static_cast <UINT32>(strlen (Source)), DXC_CP_UTF8, &SourceBlob));
143-
144- // Build wide-string argument list: -T <target> -E main <extra args>.
145- std::vector<std::wstring> WArgStorage;
146- WArgStorage.push_back (L" -T" );
147- WArgStorage.push_back (std::wstring (Target, Target + strlen (Target)));
148- WArgStorage.push_back (L" -E" );
149- WArgStorage.push_back (L" main" );
150-
151- // Tokenize the additional arguments string.
152- std::istringstream SS (Args);
153- std::string Tok;
154- while (SS >> Tok)
155- WArgStorage.push_back (std::wstring (Tok.begin (), Tok.end ()));
156-
157- std::vector<LPCWSTR> WArgPtrs;
158- std::wstringstream LogFlags;
159- LogFlags << L" Compiling with flags:" ;
160- for (const auto &A : WArgStorage) {
161- WArgPtrs.push_back (A.c_str ());
162- LogFlags << L" " << A;
163- }
164-
165- DxcBuffer Buf = {};
166- Buf.Ptr = SourceBlob->GetBufferPointer ();
167- Buf.Size = SourceBlob->GetBufferSize ();
168- Buf.Encoding = DXC_CP_UTF8;
169-
170- hlsl_test::LogCommentFmt (LogFlags.str ().c_str ());
171-
172- CComPtr<IDxcResult> Result;
173- VERIFY_SUCCEEDED (Compiler->Compile (&Buf, WArgPtrs.data (),
174- static_cast <UINT32>(WArgPtrs.size ()),
175- nullptr , IID_PPV_ARGS (&Result)));
176-
177- HRESULT HR;
178- VERIFY_SUCCEEDED (Result->GetStatus (&HR));
179-
180- if (FAILED (HR)) {
181- CComPtr<IDxcBlobUtf8> Errors;
182- Result->GetOutput (DXC_OUT_ERRORS, IID_PPV_ARGS (&Errors), nullptr );
183- if (Errors && Errors->GetStringLength () > 0 )
184- hlsl_test::LogErrorFmt (L" Shader compilation failed:\n %S" ,
185- Errors->GetStringPointer ());
186- VERIFY_SUCCEEDED (HR);
187- }
188- }
189-
19056struct MatrixParams {
19157 ComponentType CompType;
19258 int M;
0 commit comments