From 8c4a15c522861d2f30eacc9cd2b03ad793018639 Mon Sep 17 00:00:00 2001 From: lucy96chen <47800040+lucy96chen@users.noreply.github.com> Date: Tue, 7 Jun 2022 11:20:17 -0700 Subject: Add simple ray tracing test (#2261) * checkpoint commit * Simple ray tracing test works * Removed unnecessary shaders and code but image is completely black * Simple ray tracing test for a 2x2 texture working; Added new helper functions to gfx-test-texture-util for stripping padding from texture resource readback and dumping textures to disk * Renamed variables * Ignore test if ray tracing isn't supported --- tools/gfx-unit-test/gfx-test-texture-util.cpp | 51 +++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tools/gfx-unit-test/gfx-test-texture-util.cpp') diff --git a/tools/gfx-unit-test/gfx-test-texture-util.cpp b/tools/gfx-unit-test/gfx-test-texture-util.cpp index e9d884894..bf9a54dc0 100644 --- a/tools/gfx-unit-test/gfx-test-texture-util.cpp +++ b/tools/gfx-unit-test/gfx-test-texture-util.cpp @@ -4,6 +4,12 @@ #include +#include +#include + +#define STB_IMAGE_WRITE_IMPLEMENTATION +#include "external/stb/stb_image_write.h" + #define GFX_ENABLE_RENDERDOC_INTEGRATION 0 #if GFX_ENABLE_RENDERDOC_INTEGRATION @@ -196,4 +202,49 @@ namespace gfx_test } } } + + List removePadding(ISlangBlob* pixels, GfxCount width, GfxCount height, Size rowPitch, Size pixelSize) + { + List buffer; + buffer.setCount(height * rowPitch); + for (GfxIndex i = 0; i < height; ++i) + { + Offset srcOffset = i * rowPitch; + Offset dstOffset = i * width * pixelSize; + memcpy(buffer.getBuffer() + dstOffset, (char*)pixels->getBufferPointer() + srcOffset, width * pixelSize); + } + + return buffer; + } + + Slang::Result writeImage( + const char* filename, + ISlangBlob* pixels, + uint32_t width, + uint32_t height) + { + int stbResult = + stbi_write_hdr(filename, width, height, 4, (float*)pixels->getBufferPointer()); + + return stbResult ? SLANG_OK : SLANG_FAIL; + } + + Slang::Result writeImage( + const char* filename, + ISlangBlob* pixels, + uint32_t width, + uint32_t height, + uint32_t rowPitch, + uint32_t pixelSize) + { + if (rowPitch == width * pixelSize) + return writeImage(filename, pixels, width, height); + + List buffer = removePadding(pixels, width, height, rowPitch, pixelSize); + + int stbResult = + stbi_write_hdr(filename, width, height, 4, (float*)buffer.getBuffer()); + + return stbResult ? SLANG_OK : SLANG_FAIL; + } } -- cgit v1.2.3