summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-01-17 22:00:49 -0800
committerGitHub <noreply@github.com>2021-01-17 22:00:49 -0800
commit1296c7bb55b14db24308f31cacdda7f7a71fc937 (patch)
tree935ebf1e829361a17f98f5ead3460998719acf42 /tools
parent2a5d5b32348c33aac7ca62aa9a4c2bb7cff8e08a (diff)
Make `gfx` compile to a DLL. (#1660)
* Make `gfx` compile to a DLL. * Fix cuda * Fix cuda build * Bug gl screen capture bug.
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx-util/shader-cursor.cpp (renamed from tools/gfx/shader-cursor.cpp)0
-rw-r--r--tools/gfx-util/shader-cursor.h (renamed from tools/gfx/shader-cursor.h)0
-rw-r--r--tools/gfx/cuda/render-cuda.cpp10
-rw-r--r--tools/gfx/d3d11/render-d3d11.cpp75
-rw-r--r--tools/gfx/d3d12/render-d3d12.cpp40
-rw-r--r--tools/gfx/open-gl/render-gl.cpp39
-rw-r--r--tools/gfx/render.h5
-rw-r--r--tools/gfx/slang-gfx-helper.cpp6
-rw-r--r--tools/gfx/slang-gfx-helper.h9
-rw-r--r--tools/gfx/vulkan/render-vk.cpp39
-rw-r--r--tools/render-test/render-test-main.cpp19
-rw-r--r--tools/render-test/surface.cpp (renamed from tools/gfx/surface.cpp)0
-rw-r--r--tools/render-test/surface.h (renamed from tools/gfx/surface.h)0
13 files changed, 173 insertions, 69 deletions
diff --git a/tools/gfx/shader-cursor.cpp b/tools/gfx-util/shader-cursor.cpp
index 65cf2f8ac..65cf2f8ac 100644
--- a/tools/gfx/shader-cursor.cpp
+++ b/tools/gfx-util/shader-cursor.cpp
diff --git a/tools/gfx/shader-cursor.h b/tools/gfx-util/shader-cursor.h
index 82794be9a..82794be9a 100644
--- a/tools/gfx/shader-cursor.h
+++ b/tools/gfx-util/shader-cursor.h
diff --git a/tools/gfx/cuda/render-cuda.cpp b/tools/gfx/cuda/render-cuda.cpp
index bf316546e..0e4ee6c13 100644
--- a/tools/gfx/cuda/render-cuda.cpp
+++ b/tools/gfx/cuda/render-cuda.cpp
@@ -1493,10 +1493,14 @@ public:
SLANG_UNUSED(outState);
return SLANG_E_NOT_AVAILABLE;
}
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- captureScreenSurface(Surface& surfaceOut) override
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override
{
- SLANG_UNUSED(surfaceOut);
+ SLANG_UNUSED(buffer);
+ SLANG_UNUSED(inOutBufferSize);
+ SLANG_UNUSED(outRowPitch);
+ SLANG_UNUSED(outPixelSize);
+
return SLANG_E_NOT_AVAILABLE;
}
virtual SLANG_NO_THROW void SLANG_MCALL
diff --git a/tools/gfx/d3d11/render-d3d11.cpp b/tools/gfx/d3d11/render-d3d11.cpp
index 8bf11c39d..4ac90f47f 100644
--- a/tools/gfx/d3d11/render-d3d11.cpp
+++ b/tools/gfx/d3d11/render-d3d11.cpp
@@ -11,8 +11,6 @@
#include "../d3d/d3d-util.h"
#include "../nvapi/nvapi-util.h"
-#include "../surface.h"
-
// In order to use the Slang API, we need to include its header
//#include <slang.h>
@@ -106,8 +104,8 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- captureScreenSurface(Surface& surfaceOut) override;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override;
virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) override;
virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) override;
@@ -491,7 +489,14 @@ public:
};
/// Capture a texture to a file
- static HRESULT captureTextureToSurface(ID3D11Device* device, ID3D11DeviceContext* context, ID3D11Texture2D* texture, Surface& surfaceOut);
+ static HRESULT captureTextureToSurface(
+ ID3D11Device* device,
+ ID3D11DeviceContext* context,
+ TextureResourceImpl* texture,
+ void* buffer,
+ size_t* inOutBufferSize,
+ size_t* outRowPitch,
+ size_t* outPixelSize);
void _flushGraphicsState();
void _flushComputeState();
@@ -569,27 +574,50 @@ D3D11Renderer::ScopeNVAPI::~ScopeNVAPI()
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!D3D11Renderer !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-/* static */HRESULT D3D11Renderer::captureTextureToSurface(ID3D11Device* device, ID3D11DeviceContext* context, ID3D11Texture2D* texture, Surface& surfaceOut)
+/* static */ HRESULT D3D11Renderer::captureTextureToSurface(
+ ID3D11Device* device,
+ ID3D11DeviceContext* context,
+ TextureResourceImpl* texture,
+ void* buffer,
+ size_t* inOutBufferSize,
+ size_t* outRowPitch,
+ size_t* outPixelSize)
{
if (!context) return E_INVALIDARG;
if (!texture) return E_INVALIDARG;
- D3D11_TEXTURE2D_DESC textureDesc;
- texture->GetDesc(&textureDesc);
-
// Don't bother supporting MSAA for right now
- if (textureDesc.SampleDesc.Count > 1)
+ if (texture->getDesc()->sampleDesc.numSamples > 1)
{
fprintf(stderr, "ERROR: cannot capture multi-sample texture\n");
return E_INVALIDARG;
}
+ size_t bytesPerPixel = sizeof(uint32_t);
+ size_t rowPitch = int(texture->getDesc()->size.width) * bytesPerPixel;
+ size_t bufferSize = rowPitch * int(texture->getDesc()->size.height);
+ if (outRowPitch)
+ *outRowPitch = rowPitch;
+ if (outPixelSize)
+ *outPixelSize = bytesPerPixel;
+ if (!buffer || *inOutBufferSize == 0)
+ {
+ *inOutBufferSize = bufferSize;
+ return S_OK;
+ }
+ if (*inOutBufferSize < bufferSize)
+ return SLANG_ERROR_INSUFFICIENT_BUFFER;
+
+ D3D11_TEXTURE2D_DESC textureDesc;
+ auto d3d11Texture = ((ID3D11Texture2D*)texture->m_resource.get());
+ d3d11Texture->GetDesc(&textureDesc);
+
HRESULT hr = S_OK;
ComPtr<ID3D11Texture2D> stagingTexture;
if (textureDesc.Usage == D3D11_USAGE_STAGING && (textureDesc.CPUAccessFlags & D3D11_CPU_ACCESS_READ))
{
- stagingTexture = texture;
+ stagingTexture = d3d11Texture;
}
else
{
@@ -606,7 +634,7 @@ D3D11Renderer::ScopeNVAPI::~ScopeNVAPI()
return hr;
}
- context->CopyResource(stagingTexture, texture);
+ context->CopyResource(stagingTexture, d3d11Texture);
}
// Now just read back texels from the staging textures
@@ -614,11 +642,16 @@ D3D11Renderer::ScopeNVAPI::~ScopeNVAPI()
D3D11_MAPPED_SUBRESOURCE mappedResource;
SLANG_RETURN_ON_FAIL(context->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mappedResource));
- Result res = surfaceOut.set(textureDesc.Width, textureDesc.Height, Format::RGBA_Unorm_UInt8, mappedResource.RowPitch, mappedResource.pData, SurfaceAllocator::getMallocAllocator());
-
+ for (size_t y = 0; y < textureDesc.Height; y++)
+ {
+ memcpy(
+ (char*)buffer + y * (*outRowPitch),
+ (char*)mappedResource.pData + y * mappedResource.RowPitch,
+ *outRowPitch);
+ }
// Make sure to unmap
context->Unmap(stagingTexture, 0);
- return res;
+ return SLANG_OK;
}
}
@@ -891,9 +924,17 @@ TextureResource::Desc D3D11Renderer::getSwapChainTextureDesc()
return desc;
}
-SlangResult D3D11Renderer::captureScreenSurface(Surface& surfaceOut)
+SlangResult D3D11Renderer::captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize)
{
- return captureTextureToSurface(m_device, m_immediateContext, (ID3D11Texture2D*) m_primaryRenderTargetTexture->m_resource.get(), surfaceOut);
+ return captureTextureToSurface(
+ m_device,
+ m_immediateContext,
+ m_primaryRenderTargetTexture.Ptr(),
+ buffer,
+ inOutBufferSize,
+ outRowPitch,
+ outPixelSize);
}
static D3D11_BIND_FLAG _calcResourceFlag(IResource::BindFlag::Enum bindFlag)
diff --git a/tools/gfx/d3d12/render-d3d12.cpp b/tools/gfx/d3d12/render-d3d12.cpp
index 6b66c5403..3db93df50 100644
--- a/tools/gfx/d3d12/render-d3d12.cpp
+++ b/tools/gfx/d3d12/render-d3d12.cpp
@@ -7,7 +7,6 @@
#include "../renderer-shared.h"
#include "../render-graphics-common.h"
-#include "../surface.h"
#include "core/slang-basic.h"
// In order to use the Slang API, we need to include its header
@@ -112,8 +111,8 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- captureScreenSurface(Surface& surfaceOut) override;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override;
virtual SLANG_NO_THROW void* SLANG_MCALL
map(IBufferResource* buffer, MapFlavor flavor) override;
@@ -648,7 +647,12 @@ protected:
void submitGpuWorkAndWait();
void _resetCommandList();
- Result captureTextureToSurface(D3D12Resource& resource, Surface& surfaceOut);
+ Result captureTextureToSurface(
+ D3D12Resource& resource,
+ void* buffer,
+ size_t* inOutBufferSize,
+ size_t* outRowPitch,
+ size_t* outPixelSize);
FrameInfo& getFrame() { return m_frameInfos[m_frameIndex]; }
const FrameInfo& getFrame() const { return m_frameInfos[m_frameIndex]; }
@@ -1063,7 +1067,12 @@ void D3D12Renderer::submitGpuWorkAndWait()
waitForGpu();
}
-Result D3D12Renderer::captureTextureToSurface(D3D12Resource& resource, Surface& surfaceOut)
+Result D3D12Renderer::captureTextureToSurface(
+ D3D12Resource& resource,
+ void* buffer,
+ size_t* inOutBufferSize,
+ size_t* outRowPitch,
+ size_t* outPixelSize)
{
const D3D12_RESOURCE_STATES initialState = resource.getState();
@@ -1079,7 +1088,17 @@ Result D3D12Renderer::captureTextureToSurface(D3D12Resource& resource, Surface&
size_t bytesPerPixel = sizeof(uint32_t);
size_t rowPitch = int(desc.Width) * bytesPerPixel;
size_t bufferSize = rowPitch * int(desc.Height);
-
+ if (outRowPitch)
+ *outRowPitch = rowPitch;
+ if (outPixelSize)
+ *outPixelSize = bytesPerPixel;
+ if (!buffer || *inOutBufferSize == 0)
+ {
+ *inOutBufferSize = bufferSize;
+ return SLANG_OK;
+ }
+ if (*inOutBufferSize < bufferSize)
+ return SLANG_ERROR_INSUFFICIENT_BUFFER;
D3D12Resource stagingResource;
{
D3D12_RESOURCE_DESC stagingDesc;
@@ -1136,10 +1155,10 @@ Result D3D12Renderer::captureTextureToSurface(D3D12Resource& resource, Surface&
SLANG_RETURN_ON_FAIL(dxResource->Map(0, &readRange, reinterpret_cast<void**>(&data)));
- Result res = surfaceOut.set(int(desc.Width), int(desc.Height), Format::RGBA_Unorm_UInt8, int(rowPitch), data, SurfaceAllocator::getMallocAllocator());
+ memcpy(buffer, data, bufferSize);
dxResource->Unmap(0, nullptr);
- return res;
+ return SLANG_OK;
}
}
@@ -1800,9 +1819,10 @@ TextureResource::Desc D3D12Renderer::getSwapChainTextureDesc()
return desc;
}
-SlangResult D3D12Renderer::captureScreenSurface(Surface& surfaceOut)
+SlangResult D3D12Renderer::captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize)
{
- return captureTextureToSurface(*m_renderTargets[m_renderTargetIndex], surfaceOut);
+ return captureTextureToSurface(*m_renderTargets[m_renderTargetIndex], buffer, inOutBufferSize, outRowPitch, outPixelSize);
}
static D3D12_RESOURCE_STATES _calcResourceState(IResource::Usage usage)
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index 826192e8d..7ee73366b 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -13,8 +13,6 @@
#include "core/slang-secure-crt.h"
#include "external/stb/stb_image_write.h"
-#include "../surface.h"
-
// TODO(tfoley): eventually we should be able to run these
// tests on non-Windows targets to confirm that cross-compilation
// at least *works* on those platforms...
@@ -125,8 +123,8 @@ public:
virtual SLANG_NO_THROW Result SLANG_MCALL createComputePipelineState(
const ComputePipelineStateDesc& desc, IPipelineState** outState) override;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL
- captureScreenSurface(Surface& surfaceOut) override;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override;
virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) override;
virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) override;
@@ -882,11 +880,36 @@ SLANG_NO_THROW TextureResource::Desc SLANG_MCALL GLRenderer::getSwapChainTexture
return desc;
}
-SLANG_NO_THROW Result SLANG_MCALL GLRenderer::captureScreenSurface(Surface& surfaceOut)
+SLANG_NO_THROW Result SLANG_MCALL GLRenderer::captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize)
{
- SLANG_RETURN_ON_FAIL(surfaceOut.allocate(m_desc.width, m_desc.height, Format::RGBA_Unorm_UInt8, 1, SurfaceAllocator::getMallocAllocator()));
- glReadPixels(0, 0, m_desc.width, m_desc.height, GL_RGBA, GL_UNSIGNED_BYTE, surfaceOut.m_data);
- surfaceOut.flipInplaceVertically();
+ size_t requiredSize = m_desc.width * m_desc.height * sizeof(uint32_t);
+ if (outRowPitch)
+ *outRowPitch = m_desc.width * sizeof(uint32_t);
+ if (outPixelSize)
+ *outPixelSize = sizeof(uint32_t);
+
+ if (!buffer || *inOutBufferSize == 0)
+ {
+ *inOutBufferSize = requiredSize;
+ return SLANG_OK;
+ }
+ if (*inOutBufferSize < requiredSize)
+ return SLANG_ERROR_INSUFFICIENT_BUFFER;
+
+ glReadPixels(0, 0, m_desc.width, m_desc.height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+
+ // Flip pixels vertically in-place.
+ for (int y = 0; y < m_desc.height / 2; y++)
+ {
+ for (int x = 0; x < m_desc.width; x++)
+ {
+ std::swap(
+ *((uint32_t*)buffer + y * m_desc.width + x),
+ *((uint32_t*)buffer + (m_desc.height - y - 1) * m_desc.width + x));
+ }
+ }
+
return SLANG_OK;
}
diff --git a/tools/gfx/render.h b/tools/gfx/render.h
index 0bc8692eb..8e1a5d665 100644
--- a/tools/gfx/render.h
+++ b/tools/gfx/render.h
@@ -38,9 +38,6 @@ typedef SlangResult Result;
typedef SlangInt Int;
typedef SlangUInt UInt;
-// pre declare types
-class Surface;
-
// Declare opaque type
class IInputLayout: public ISlangUnknown
{
@@ -1281,7 +1278,7 @@ public:
}
/// Captures the back buffer and stores the result in surfaceOut. If the surface contains data - it will either be overwritten (if same size and format), or freed and a re-allocated.
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(Surface& surfaceOut) = 0;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(void* buffer, size_t *inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) = 0;
virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) = 0;
virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) = 0;
diff --git a/tools/gfx/slang-gfx-helper.cpp b/tools/gfx/slang-gfx-helper.cpp
deleted file mode 100644
index 499e462b0..000000000
--- a/tools/gfx/slang-gfx-helper.cpp
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "slang-gfx-helper.h"
-#include "renderer-shared.h"
-
-namespace gfx
-{
-} // namespace gfx
diff --git a/tools/gfx/slang-gfx-helper.h b/tools/gfx/slang-gfx-helper.h
deleted file mode 100644
index 1cd3fe64c..000000000
--- a/tools/gfx/slang-gfx-helper.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-
-#include "render.h"
-
-namespace gfx
-{
-
-
-}
diff --git a/tools/gfx/vulkan/render-vk.cpp b/tools/gfx/vulkan/render-vk.cpp
index c2a1e36bf..382f12f85 100644
--- a/tools/gfx/vulkan/render-vk.cpp
+++ b/tools/gfx/vulkan/render-vk.cpp
@@ -12,8 +12,6 @@
#include "vk-device-queue.h"
#include "vk-swap-chain.h"
-#include "../surface.h"
-
// Vulkan has a different coordinate system to ogl
// http://anki3d.org/vulkan-coordinate-system/
@@ -88,7 +86,8 @@ public:
const ComputePipelineStateDesc& desc,
IPipelineState** outState) override;
- virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(Surface& surface) override;
+ virtual SLANG_NO_THROW SlangResult SLANG_MCALL captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize) override;
virtual SLANG_NO_THROW void* SLANG_MCALL map(IBufferResource* buffer, MapFlavor flavor) override;
virtual SLANG_NO_THROW void SLANG_MCALL unmap(IBufferResource* buffer) override;
@@ -1439,8 +1438,13 @@ TextureResource::Desc VKRenderer::getSwapChainTextureDesc()
return desc;
}
-SlangResult VKRenderer::captureScreenSurface(Surface& surfaceOut)
+SlangResult VKRenderer::captureScreenSurface(
+ void* buffer, size_t* inOutBufferSize, size_t* outRowPitch, size_t* outPixelSize)
{
+ SLANG_UNUSED(buffer);
+ SLANG_UNUSED(inOutBufferSize);
+ SLANG_UNUSED(outRowPitch);
+ SLANG_UNUSED(outPixelSize);
return SLANG_FAIL;
}
@@ -1594,6 +1598,21 @@ void VKRenderer::_transitionImageLayout(VkImage image, VkFormat format, const Te
m_api.vkCmdPipelineBarrier(commandBuffer, sourceStage, destinationStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
}
+size_t calcRowSize(Format format, int width)
+{
+ size_t pixelSize = gfxGetFormatSize(format);
+ if (pixelSize == 0)
+ {
+ return 0;
+ }
+ return size_t(pixelSize * width);
+}
+
+size_t calcNumRows(Format format, int height)
+{
+ return (size_t)height;
+}
+
Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const ITextureResource::Desc& descIn, const ITextureResource::Data* initData, ITextureResource** outResource)
{
TextureResource::Desc desc(descIn);
@@ -1704,8 +1723,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT
{
const TextureResource::Size mipSize = desc.size.calcMipSize(j);
- const int rowSizeInBytes = Surface::calcRowSize(desc.format, mipSize.width);
- const int numRows = Surface::calcNumRows(desc.format, mipSize.height);
+ const int rowSizeInBytes = calcRowSize(desc.format, mipSize.width);
+ const int numRows = calcNumRows(desc.format, mipSize.height);
mipSizes.add(mipSize);
@@ -1735,8 +1754,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT
const auto& mipSize = mipSizes[j];
const ptrdiff_t srcRowStride = initData->mipRowStrides[j];
- const int dstRowSizeInBytes = Surface::calcRowSize(desc.format, mipSize.width);
- const int numRows = Surface::calcNumRows(desc.format, mipSize.height);
+ const int dstRowSizeInBytes = calcRowSize(desc.format, mipSize.width);
+ const int numRows = calcNumRows(desc.format, mipSize.height);
for (int k = 0; k < mipSize.depth; k++)
{
@@ -1768,8 +1787,8 @@ Result VKRenderer::createTextureResource(IResource::Usage initialUsage, const IT
{
const auto& mipSize = mipSizes[j];
- const int rowSizeInBytes = Surface::calcRowSize(desc.format, mipSize.width);
- const int numRows = Surface::calcNumRows(desc.format, mipSize.height);
+ const int rowSizeInBytes = calcRowSize(desc.format, mipSize.width);
+ const int numRows = calcNumRows(desc.format, mipSize.height);
// https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkBufferImageCopy.html
// bufferRowLength and bufferImageHeight specify the data in buffer memory as a subregion of a larger two- or three-dimensional image,
diff --git a/tools/render-test/render-test-main.cpp b/tools/render-test/render-test-main.cpp
index 89bb25871..184373f0c 100644
--- a/tools/render-test/render-test-main.cpp
+++ b/tools/render-test/render-test-main.cpp
@@ -4,7 +4,7 @@
#include "options.h"
#include "render.h"
-#include "shader-cursor.h"
+#include "tools/gfx-util/shader-cursor.h"
#include "slang-support.h"
#include "surface.h"
#include "png-serialize-util.h"
@@ -827,8 +827,23 @@ Result ShaderObjectRenderTestApp::writeBindingOutput(BindRoot* bindRoot, const c
Result RenderTestApp::writeScreen(const char* filename)
{
+ size_t rowPitch, bufferSize, pixelSize;
+ List<uint8_t> buffer;
+
+ SLANG_RETURN_ON_FAIL(m_renderer->captureScreenSurface(nullptr, &bufferSize, &rowPitch, &pixelSize));
+ buffer.setCount(bufferSize);
+ SLANG_RETURN_ON_FAIL(
+ m_renderer->captureScreenSurface(buffer.getBuffer(), &bufferSize, &rowPitch, &pixelSize));
+
Surface surface;
- SLANG_RETURN_ON_FAIL(m_renderer->captureScreenSurface(surface));
+ size_t width = rowPitch / pixelSize;
+ size_t height = bufferSize / rowPitch;
+ surface.setUnowned(
+ width,
+ height,
+ gfx::Format::RGBA_Unorm_UInt8,
+ rowPitch,
+ buffer.getBuffer());
return PngSerializeUtil::write(filename, surface);
}
diff --git a/tools/gfx/surface.cpp b/tools/render-test/surface.cpp
index 636881fca..636881fca 100644
--- a/tools/gfx/surface.cpp
+++ b/tools/render-test/surface.cpp
diff --git a/tools/gfx/surface.h b/tools/render-test/surface.h
index 3e0f6f0aa..3e0f6f0aa 100644
--- a/tools/gfx/surface.h
+++ b/tools/render-test/surface.h