summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-08-10 10:04:06 -0400
committerGitHub <noreply@github.com>2022-08-10 10:04:06 -0400
commit1378fffd9da094beb41b2db89b96f556c23ab6cb (patch)
treee0558c031bd4b1a013dc56b75c4caa3ff5442021 /tools
parent89083c4b50af8e48e70b25b63cc62aca21ab706c (diff)
Artifact and ICastable (#2351)
* #include an absolute path didn't work - because paths were taken to always be relative. * WIP with hierarchical enums. * Some small fixes and improvements around artifact desc related types. * Improvements around hierarchical enum. * Fixes to get Artifact types refactor to be able to execute tests. * Attempt to better categorize PTX. * Work around for potentially unused function warning. * Typo fix. * Simplify Artifact header. * Small improvements around Artifact kind/payload/style. * Added IDestroyable/ICastable * Add IArtifactList. * First impl of IArtifactUtil. * Use the ICastable interface for IArtifactRepresentation. * Added IArtifactRepresentation & IArtifactAssociated. * Add SLANG_OVERRIDE to avoid gcc/clang warning. * Fix calling convention issue on win32. * Fix missing SLANG_OVERRIDE. * First attempt at file abstraction around Artifact. * Added creation of lock file. * Move functionality for determining file paths to the IArtifactUtil. Add casting to ICastable. * Added some casting/finding mechanisms. * Simplify IArtifact interface, and use Items for file reps. * Fix problem with libraries on DXIL. * Split out ArtifactRepresentation. * Move ArtifactDesc functionality to ArtifactDescUtil. ArtifactInfoUtil becomes ArtifactDescUtil. * Split implementations from the interfaces for Artifact. * Use TypeTextUtil for target name outputting. * Add artifact impls. * Add ICastableList * Added UnknownCastableAdapter * Make ISlangSharedLibrary derive from ICastable, and remain backwards compatible with slang-llvm. * Refactor Representation on Artifact. * Make our ISlangBlobs also derive from ICastable. Make ISlangBlob atomic ref counted. * Fix typo.
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx/cuda/cuda-device.cpp21
-rw-r--r--tools/gfx/d3d11/d3d11-device.cpp11
-rw-r--r--tools/gfx/d3d12/d3d12-device.cpp22
-rw-r--r--tools/gfx/immediate-renderer-base.cpp10
-rw-r--r--tools/gfx/open-gl/render-gl.cpp9
-rw-r--r--tools/gfx/vulkan/vk-device.cpp21
6 files changed, 63 insertions, 31 deletions
diff --git a/tools/gfx/cuda/cuda-device.cpp b/tools/gfx/cuda/cuda-device.cpp
index 1a4a142d0..be5dbbc96 100644
--- a/tools/gfx/cuda/cuda-device.cpp
+++ b/tools/gfx/cuda/cuda-device.cpp
@@ -1061,7 +1061,8 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::readTextureResource(
size_t* outPixelSize)
{
auto textureImpl = static_cast<TextureResourceImpl*>(texture);
- RefPtr<ListBlob> blob = new ListBlob();
+
+ List<uint8_t> blobData;
auto desc = textureImpl->getDesc();
auto width = desc->size.width;
@@ -1071,7 +1072,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::readTextureResource(
size_t pixelSize = sizeInfo.blockSizeInBytes / sizeInfo.pixelsPerBlock;
size_t rowPitch = width * pixelSize;
size_t size = height * rowPitch;
- blob->m_data.setCount((Index)size);
+ blobData.setCount((Index)size);
CUDA_MEMCPY2D copyParam;
memset(&copyParam, 0, sizeof(copyParam));
@@ -1080,7 +1081,7 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::readTextureResource(
copyParam.srcArray = textureImpl->m_cudaArray;
copyParam.dstMemoryType = CU_MEMORYTYPE_HOST;
- copyParam.dstHost = blob->m_data.getBuffer();
+ copyParam.dstHost = blobData.getBuffer();
copyParam.dstPitch = rowPitch;
copyParam.WidthInBytes = copyParam.dstPitch;
copyParam.Height = height;
@@ -1088,6 +1089,9 @@ SLANG_NO_THROW SlangResult SLANG_MCALL DeviceImpl::readTextureResource(
*outRowPitch = rowPitch;
*outPixelSize = pixelSize;
+
+ auto blob = ListBlob::moveCreate(blobData);
+
returnComPtr(outBlob, blob);
return SLANG_OK;
}
@@ -1099,13 +1103,18 @@ SLANG_NO_THROW Result SLANG_MCALL DeviceImpl::readBufferResource(
ISlangBlob** outBlob)
{
auto bufferImpl = static_cast<BufferResourceImpl*>(buffer);
- RefPtr<ListBlob> blob = new ListBlob();
- blob->m_data.setCount((Index)size);
+
+ List<uint8_t> blobData;
+
+ blobData.setCount((Index)size);
cudaMemcpy(
- blob->m_data.getBuffer(),
+ blobData.getBuffer(),
(uint8_t*)bufferImpl->m_cudaMemory + offset,
size,
cudaMemcpyDefault);
+
+ auto blob = ListBlob::moveCreate(blobData);
+
returnComPtr(outBlob, blob);
return SLANG_OK;
}
diff --git a/tools/gfx/d3d11/d3d11-device.cpp b/tools/gfx/d3d11/d3d11-device.cpp
index 1b2f6ec1d..aa665ebd4 100644
--- a/tools/gfx/d3d11/d3d11-device.cpp
+++ b/tools/gfx/d3d11/d3d11-device.cpp
@@ -371,9 +371,11 @@ SlangResult DeviceImpl::readTextureResource(
{
D3D11_MAPPED_SUBRESOURCE mappedResource;
SLANG_RETURN_ON_FAIL(m_immediateContext->Map(stagingTexture, 0, D3D11_MAP_READ, 0, &mappedResource));
- RefPtr<ListBlob> blob = new ListBlob();
- blob->m_data.setCount(bufferSize);
- char* buffer = (char*)blob->m_data.begin();
+
+ List<uint8_t> data;
+
+ data.setCount(bufferSize);
+ char* buffer = (char*)data.begin();
for (size_t y = 0; y < textureDesc.Height; y++)
{
memcpy(
@@ -383,6 +385,9 @@ SlangResult DeviceImpl::readTextureResource(
}
// Make sure to unmap
m_immediateContext->Unmap(stagingTexture, 0);
+
+ ComPtr<ISlangBlob> blob = ListBlob::moveCreate(data);
+
returnComPtr(outBlob, blob);
return SLANG_OK;
}
diff --git a/tools/gfx/d3d12/d3d12-device.cpp b/tools/gfx/d3d12/d3d12-device.cpp
index 3578729d9..f5c457809 100644
--- a/tools/gfx/d3d12/d3d12-device.cpp
+++ b/tools/gfx/d3d12/d3d12-device.cpp
@@ -231,10 +231,14 @@ Result DeviceImpl::captureTextureToSurface(
SLANG_RETURN_ON_FAIL(dxResource->Map(0, &readRange, reinterpret_cast<void**>(&data)));
- RefPtr<Slang::ListBlob> resultBlob = new Slang::ListBlob();
- resultBlob->m_data.setCount(bufferSize);
- memcpy(resultBlob->m_data.getBuffer(), data, bufferSize);
+ List<uint8_t> blobData;
+
+ blobData.setCount(bufferSize);
+ memcpy(blobData.getBuffer(), data, bufferSize);
dxResource->Unmap(0, nullptr);
+
+ auto resultBlob = Slang::ListBlob::moveCreate(blobData);
+
returnComPtr(outBlob, resultBlob);
return SLANG_OK;
}
@@ -1748,7 +1752,7 @@ Result DeviceImpl::readBufferResource(
buffer->getDesc()->memoryType != MemoryType::ReadBack ? stageBuf : resource;
// Map and copy
- RefPtr<ListBlob> blob = new ListBlob();
+ List<uint8_t> blobData;
{
UINT8* data;
D3D12_RANGE readRange = { 0, size };
@@ -1757,11 +1761,12 @@ Result DeviceImpl::readBufferResource(
stageBufRef.getResource()->Map(0, &readRange, reinterpret_cast<void**>(&data)));
// Copy to memory buffer
- blob->m_data.setCount(size);
- ::memcpy(blob->m_data.getBuffer(), data, size);
+ blobData.setCount(size);
+ ::memcpy(blobData.getBuffer(), data, size);
stageBufRef.getResource()->Unmap(0, nullptr);
}
+ auto blob = ListBlob::moveCreate(blobData);
returnComPtr(outBlob, blob);
return SLANG_OK;
}
@@ -1782,8 +1787,9 @@ Result DeviceImpl::createProgram(
{
if (outDiagnosticBlob && d3dDiagnosticBlob)
{
- RefPtr<StringBlob> diagnosticBlob =
- new StringBlob(String((const char*)d3dDiagnosticBlob->GetBufferPointer()));
+ String diagnostic((const char*)d3dDiagnosticBlob->GetBufferPointer());
+ auto diagnosticBlob = StringBlob::create(diagnostic);
+
returnComPtr(outDiagnosticBlob, diagnosticBlob);
}
return rootShaderLayoutResult;
diff --git a/tools/gfx/immediate-renderer-base.cpp b/tools/gfx/immediate-renderer-base.cpp
index c598a3a67..611741c46 100644
--- a/tools/gfx/immediate-renderer-base.cpp
+++ b/tools/gfx/immediate-renderer-base.cpp
@@ -711,13 +711,17 @@ SLANG_NO_THROW SlangResult SLANG_MCALL ImmediateRendererBase::readBufferResource
size_t size,
ISlangBlob** outBlob)
{
- RefPtr<ListBlob> blob = new ListBlob();
- blob->m_data.setCount((Index)size);
+ List<uint8_t> blobData;
+
+ blobData.setCount((Index)size);
auto content = (uint8_t*)map(buffer, gfx::MapFlavor::HostRead);
if (!content)
return SLANG_FAIL;
- memcpy(blob->m_data.getBuffer(), content + offset, size);
+ memcpy(blobData.getBuffer(), content + offset, size);
unmap(buffer, offset, size);
+
+ auto blob = ListBlob::moveCreate(blobData);
+
returnComPtr(outBlob, blob);
return SLANG_OK;
}
diff --git a/tools/gfx/open-gl/render-gl.cpp b/tools/gfx/open-gl/render-gl.cpp
index 0cf05e665..7daf577ef 100644
--- a/tools/gfx/open-gl/render-gl.cpp
+++ b/tools/gfx/open-gl/render-gl.cpp
@@ -2246,9 +2246,10 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::readTextureResource(
if (outPixelSize)
*outPixelSize = sizeof(uint32_t);
- RefPtr<ListBlob> blob = new ListBlob();
- blob->m_data.setCount(requiredSize);
- auto buffer = blob->m_data.begin();
+ List<uint8_t> blobData;
+
+ blobData.setCount(requiredSize);
+ auto buffer = blobData.begin();
glBindTexture(resource->m_target, resource->m_handle);
glGetTexImage(resource->m_target, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
@@ -2263,8 +2264,8 @@ SLANG_NO_THROW Result SLANG_MCALL GLDevice::readTextureResource(
}
}
+ auto blob = ListBlob::moveCreate(blobData);
returnComPtr(outBlob, blob);
-
return SLANG_OK;
}
diff --git a/tools/gfx/vulkan/vk-device.cpp b/tools/gfx/vulkan/vk-device.cpp
index d62734394..c2d82f8a7 100644
--- a/tools/gfx/vulkan/vk-device.cpp
+++ b/tools/gfx/vulkan/vk-device.cpp
@@ -797,8 +797,9 @@ SlangResult DeviceImpl::readTextureResource(
Size* outPixelSize)
{
auto textureImpl = static_cast<TextureResourceImpl*>(texture);
- RefPtr<ListBlob> blob = new ListBlob();
+ List<uint8_t> blobData;
+
auto desc = textureImpl->getDesc();
auto width = desc->size.width;
auto height = desc->size.height;
@@ -828,8 +829,8 @@ SlangResult DeviceImpl::readTextureResource(
}
// Calculate the total size taking into account the array
bufferSize *= arraySize;
- // TODO: Change Index to Count?
- blob->m_data.setCount(Index(bufferSize));
+
+ blobData.setCount(Count(bufferSize));
VKBufferHandleRAII staging;
SLANG_RETURN_ON_FAIL(staging.init(
@@ -880,11 +881,14 @@ SlangResult DeviceImpl::readTextureResource(
SLANG_RETURN_ON_FAIL(
m_api.vkMapMemory(m_device, staging.m_memory, 0, bufferSize, 0, &mappedData));
- ::memcpy(blob->m_data.getBuffer(), mappedData, bufferSize);
+ ::memcpy(blobData.getBuffer(), mappedData, bufferSize);
m_api.vkUnmapMemory(m_device, staging.m_memory);
*outPixelSize = pixelSize;
*outRowPitch = rowPitch;
+
+ auto blob = ListBlob::moveCreate(blobData);
+
returnComPtr(outBlob, blob);
return SLANG_OK;
}
@@ -894,8 +898,9 @@ SlangResult DeviceImpl::readBufferResource(
{
BufferResourceImpl* buffer = static_cast<BufferResourceImpl*>(inBuffer);
- RefPtr<ListBlob> blob = new ListBlob();
- blob->m_data.setCount(size);
+ List<uint8_t> blobData;
+
+ blobData.setCount(size);
// create staging buffer
VKBufferHandleRAII staging;
@@ -920,9 +925,11 @@ SlangResult DeviceImpl::readBufferResource(
void* mappedData = nullptr;
SLANG_RETURN_ON_FAIL(m_api.vkMapMemory(m_device, staging.m_memory, 0, size, 0, &mappedData));
- ::memcpy(blob->m_data.getBuffer(), mappedData, size);
+ ::memcpy(blobData.getBuffer(), mappedData, size);
m_api.vkUnmapMemory(m_device, staging.m_memory);
+ auto blob = ListBlob::moveCreate(blobData);
+
returnComPtr(outBlob, blob);
return SLANG_OK;
}