Skip to content

Commit 271ae71

Browse files
Fix several silently failing tests (shader-slang#2767)
* Add missing expected.txt for test * Diagnostics -> StdWriters in render test * Allow specifying several test prefixes to run `slang-test -- tests/foo tests/bar` * Squash warnings in some tests * Enable gfx debug layer in gfx test util Makes this issue present consistently: shader-slang#2766 * Allow DebugDevice to return interfaces instantiated by the debugged object * Check that we actaully have a shader cache for shader cache tests --------- Co-authored-by: Yong He <yonghe@outlook.com>
1 parent d7ba60c commit 271ae71

12 files changed

+49
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type: float
2+
192.000000
3+
0.000000
4+
0.000000
5+
0.000000

tests/bugs/generic-groupshared.slang

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct S<let n : int>
1717
int doSomething()
1818
{
1919
table<M>(0) = M;
20-
return table<M>(0);
20+
return int(table<M>(0));
2121
}
2222
}
2323

tests/compute/half-rw-texture-simple.slang

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RWStructuredBuffer<float> outputBuffer;
2525
[numthreads(4, 1, 1)]
2626
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
2727
{
28-
int idx = dispatchThreadID.x;
28+
uint idx = dispatchThreadID.x;
2929

3030
float val = 0.0f;
3131

tests/compute/half-texture-simple.slang

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ RWStructuredBuffer<float> outputBuffer;
3535
[numthreads(4, 1, 1)]
3636
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
3737
{
38-
int idx = dispatchThreadID.x;
38+
uint idx = dispatchThreadID.x;
3939
float u = idx * (1.0f / 4);
4040

4141
float val = 0.0f;

tools/gfx-unit-test/gfx-test-util.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ namespace gfx_test
239239
void* extDescPtr = &extDesc;
240240
deviceDesc.extendedDescs = &extDescPtr;
241241

242+
// TODO: We should also set the debug callback
243+
// (And in general reduce the differences (and duplication) between
244+
// here and render-test-main.cpp)
245+
#ifdef _DEBUG
246+
gfx::gfxEnableDebugLayer();
247+
#endif
248+
242249
auto createDeviceResult = gfxCreateDevice(&deviceDesc, device.writeRef());
243250
if (SLANG_FAILED(createDeviceResult))
244251
{

tools/gfx-unit-test/shader-cache-tests.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ namespace gfx_test
141141
[this, func] (IDevice* device, UnitTestContext* ctx)
142142
{
143143
this->device = device;
144-
device->queryInterface(SLANG_UUID_IShaderCache, (void**)this->shaderCache.writeRef());
144+
SLANG_CHECK_ABORT(SLANG_SUCCEEDED(
145+
device->queryInterface(SLANG_UUID_IShaderCache, (void**)this->shaderCache.writeRef())));
145146
func();
146147
this->device = nullptr;
147148
this->shaderCache = nullptr;

tools/gfx/debug-layer/debug-device.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ using namespace Slang;
2626
namespace debug
2727
{
2828

29+
SlangResult DebugDevice::queryInterface(SlangUUID const& uuid, void** outObject) noexcept
30+
{
31+
void* intf = getInterface(uuid);
32+
if (intf)
33+
{
34+
addRef();
35+
*outObject = intf;
36+
return SLANG_OK;
37+
}
38+
39+
// Fallback to trying to get the interface from the debugged object
40+
return baseObject->queryInterface(uuid, outObject);
41+
}
42+
2943
Result DebugDevice::getNativeDeviceHandles(InteropHandles* outHandles)
3044
{
3145
return baseObject->getNativeDeviceHandles(outHandles);

tools/gfx/debug-layer/debug-device.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ namespace debug
1212
class DebugDevice : public DebugObject<IDevice>
1313
{
1414
public:
15-
SLANG_COM_OBJECT_IUNKNOWN_ALL;
15+
SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) noexcept override;
16+
SLANG_COM_OBJECT_IUNKNOWN_ADD_REF;
17+
SLANG_COM_OBJECT_IUNKNOWN_RELEASE;
1618

1719
public:
1820
DebugDevice();

tools/render-test/slang-support.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stdio.h>
1111

1212
#include "../../source/core/slang-string-util.h"
13+
#include "../../source/core/slang-test-tool-util.h"
1314

1415
namespace renderer_test {
1516
using namespace Slang;
@@ -199,7 +200,7 @@ void ShaderCompilerUtil::Output::reset()
199200

200201
if (auto diagnostics = spGetDiagnosticOutput(slangRequest))
201202
{
202-
fprintf(stderr, "%s", diagnostics);
203+
StdWriters::getError().print("%s", diagnostics);
203204
}
204205

205206
SLANG_RETURN_ON_FAIL(res);

tools/slang-test/options.cpp

+1-12
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,7 @@ static bool _isSubCommand(const char* arg)
310310

311311

312312
// first positional argument is source shader path
313-
if (positionalArgs.getCount())
314-
{
315-
optionsOut->testPrefix = positionalArgs[0];
316-
positionalArgs.removeAt(0);
317-
}
318-
319-
// any remaining arguments represent an error
320-
if (positionalArgs.getCount() != 0)
321-
{
322-
stdError.print("unexpected arguments\n");
323-
return SLANG_FAIL;
324-
}
313+
optionsOut->testPrefixes = std::move(positionalArgs);
325314

326315
if (optionsOut->binDir.getLength() == 0)
327316
{

tools/slang-test/options.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ struct Options
5252
// Directory to use when looking for binaries to run. If empty it's not set.
5353
Slang::String binDir;
5454

55-
// only run test cases with names that have this prefix.
56-
char const* testPrefix = nullptr;
55+
// only run test cases with names have one of these prefixes.
56+
Slang::List<const char *> testPrefixes;
5757

5858
// generate extra output (notably: command lines we run)
5959
bool shouldBeVerbose = false;

tools/slang-test/slang-test-main.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -3900,15 +3900,20 @@ static bool shouldRunTest(
39003900
if(!endsWithAllowedExtension(context, filePath))
39013901
return false;
39023902

3903-
if( context->options.testPrefix )
3903+
if(!context->options.testPrefixes.getCount())
39043904
{
3905-
if( strncmp(context->options.testPrefix, filePath.begin(), strlen(context->options.testPrefix)) != 0 )
3905+
return true;
3906+
}
3907+
3908+
// If we have prefixes, it has to match one of them
3909+
for(auto& p : context->options.testPrefixes)
3910+
{
3911+
if(filePath.startsWith(p))
39063912
{
3907-
return false;
3913+
return true;
39083914
}
39093915
}
3910-
3911-
return true;
3916+
return false;
39123917
}
39133918

39143919
void getFilesInDirectory(String directoryPath, List<String>& files)

0 commit comments

Comments
 (0)