diff options
Diffstat (limited to 'examples/autodiff-texture')
| -rw-r--r-- | examples/autodiff-texture/main.cpp | 42 | ||||
| -rw-r--r-- | examples/autodiff-texture/train.slang | 4 |
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); |
