summaryrefslogtreecommitdiffstats
path: root/examples/autodiff-texture
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-08-28 19:36:31 -0500
committerGitHub <noreply@github.com>2024-08-28 17:36:31 -0700
commitefda04f3cc784dde42bd15fd1d33edeea0f3cd92 (patch)
tree25f9785309efbe97cd1ba2384411e1b332159c89 /examples/autodiff-texture
parentd3a5a4723e0ba0f90ac3a0df3dd841d1f0c69782 (diff)
Migrate 3 more examples to slang-unit-test (#4927)
* Convert 'ray-tracing-pipeline' example into slang-test * Convert model-view and 'autodiff-texture' examples to slang-test * Add more error message in RecordReplay test * Fix a shader issue in autodiff-texture
Diffstat (limited to 'examples/autodiff-texture')
-rw-r--r--examples/autodiff-texture/main.cpp42
-rw-r--r--examples/autodiff-texture/train.slang4
2 files changed, 36 insertions, 10 deletions
diff --git a/examples/autodiff-texture/main.cpp b/examples/autodiff-texture/main.cpp
index 01cad6fe4..8bffadd84 100644
--- a/examples/autodiff-texture/main.cpp
+++ b/examples/autodiff-texture/main.cpp
@@ -78,6 +78,11 @@ struct AutoDiffTexture : public WindowedAppBase
diagnoseIfNeeded(diagnosticsBlob);
SLANG_RETURN_ON_FAIL(result);
+ if (isTestMode())
+ {
+ printEntrypointHashes(componentTypes.getCount() - 1, 1, linkedProgram);
+ }
+
gfx::IShaderProgram::Desc programDesc = {};
programDesc.slangGlobalScope = linkedProgram;
SLANG_RETURN_ON_FAIL(device->createProgram(programDesc, outProgram));
@@ -114,6 +119,11 @@ struct AutoDiffTexture : public WindowedAppBase
diagnoseIfNeeded(diagnosticsBlob);
SLANG_RETURN_ON_FAIL(result);
+ if (isTestMode())
+ {
+ printEntrypointHashes(componentTypes.getCount() - 1, 1, linkedProgram);
+ }
+
gfx::IShaderProgram::Desc programDesc = {};
programDesc.slangGlobalScope = linkedProgram;
SLANG_RETURN_ON_FAIL(device->createProgram(programDesc, outProgram));
@@ -266,18 +276,31 @@ struct AutoDiffTexture : public WindowedAppBase
initializeBase("autodiff-texture", 1024, 768);
srand(20421);
- gWindow->events.keyPress = [this](platform::KeyEventArgs& e)
+ if (!isTestMode())
{
- if (e.keyChar == 'R' || e.keyChar == 'r')
- resetLearntTexture = true;
- };
+ gWindow->events.keyPress = [this](platform::KeyEventArgs& e)
+ {
+ if (e.keyChar == 'R' || e.keyChar == 'r')
+ resetLearntTexture = true;
+ };
+ }
kClearValue.color.floatValues[0] = 0.3f;
kClearValue.color.floatValues[1] = 0.5f;
kClearValue.color.floatValues[2] = 0.7f;
kClearValue.color.floatValues[3] = 1.0f;
- auto clientRect = gWindow->getClientRect();
+ platform::Rect clientRect{};
+ if (isTestMode())
+ {
+ clientRect.width = 1024;
+ clientRect.height = 768;
+ }
+ else
+ {
+ clientRect = getWindow()->getClientRect();
+ }
+
windowWidth = clientRect.width;
windowHeight = clientRect.height;
@@ -321,7 +344,7 @@ struct AutoDiffTexture : public WindowedAppBase
}
{
ComPtr<IShaderProgram> shaderProgram;
- SLANG_RETURN_ON_FAIL(loadComputeProgram(gDevice, "convert", shaderProgram.writeRef()));
+ SLANG_RETURN_ON_FAIL(loadComputeProgram(gDevice, "convert.slang", shaderProgram.writeRef()));
gConvertPipelineState = createComputePipelineState(shaderProgram);
}
{
@@ -619,7 +642,7 @@ struct AutoDiffTexture : public WindowedAppBase
commandBuffer->close();
gQueue->executeCommandBuffer(commandBuffer);
}
-
+
// Draw currently learnt texture.
{
ComPtr<ICommandBuffer> commandBuffer =
@@ -635,7 +658,10 @@ struct AutoDiffTexture : public WindowedAppBase
gQueue->executeCommandBuffer(commandBuffer);
}
- gSwapchain->present();
+ if (!isTestMode())
+ {
+ gSwapchain->present();
+ }
}
void drawTexturedQuad(IRenderCommandEncoder* renderEncoder, int x, int y, int w, int h, IResourceView* srv)
diff --git a/examples/autodiff-texture/train.slang b/examples/autodiff-texture/train.slang
index c6a819d2f..7126cbde9 100644
--- a/examples/autodiff-texture/train.slang
+++ b/examples/autodiff-texture/train.slang
@@ -15,12 +15,12 @@ struct DifferentiableTexture
float minLOD;
[BackwardDerivative(bwd_LoadTexel)]
- float4 LoadTexel(int3 location, int2 offset, uint dLayerW, uint dMipOffset)
+ float4 LoadTexel(int3 location, constexpr int2 offset, uint dLayerW, uint dMipOffset)
{
return texture.Load(location, offset);
}
- void bwd_LoadTexel(int3 location, int2 offset, uint dLayerW, uint dMipOffset, float4 val)
+ void bwd_LoadTexel(int3 location, constexpr int2 offset, uint dLayerW, uint dMipOffset, float4 val)
{
// Ignore alpha dimension for this example..
int4 uval = int4(int3(val.xyz * 65536), 1);