diff options
| author | lucy96chen <47800040+lucy96chen@users.noreply.github.com> | 2022-06-07 11:20:17 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-07 11:20:17 -0700 |
| commit | 8c4a15c522861d2f30eacc9cd2b03ad793018639 (patch) | |
| tree | 68dc2e57a88e13d77172c791c53237c93e1c87d0 /tools/gfx-unit-test/gfx-test-texture-util.cpp | |
| parent | c4ed2385e98385b2459b93a151df9e6e7d7d3591 (diff) | |
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
Diffstat (limited to 'tools/gfx-unit-test/gfx-test-texture-util.cpp')
| -rw-r--r-- | tools/gfx-unit-test/gfx-test-texture-util.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
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 <slang-com-ptr.h> +#include <stdlib.h> +#include <stdio.h> + +#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<uint8_t> removePadding(ISlangBlob* pixels, GfxCount width, GfxCount height, Size rowPitch, Size pixelSize) + { + List<uint8_t> 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<uint8_t> 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; + } } |
