Skip to content

Commit

Permalink
Merge branch 'dev-3.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
kyaoNV committed Jun 8, 2018
2 parents 86c2277 + 7277e92 commit cc62b5b
Show file tree
Hide file tree
Showing 19 changed files with 455 additions and 273 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
v3.0.4
------
- Updated Slang to 0.10.24
- Added an option to create a `Program` from a string
- Added `CopyContext::updateSubresourceData()` which allows updating a region of a subresource
- Added `Program::Desc` has a new function - `setShaderModel()`. It allows the user to request shader-model 6.x, which will use dxcompiler instead of FXC
- Added support for double-quotes when parsing command line arguments. Text surrounded by double-quotes will be considered a single argument.

v3.0.3
------
- Added FXAA as an effect
Expand Down
3 changes: 2 additions & 1 deletion Framework/BuildScripts/movedata.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ call %1\BuildScripts\moveprojectdata.bat %3 %DestinationDirectory% /r:0 >nul
rem copy or clear the DXR DLLs
if "%8%"=="FALCOR_DXR" (
robocopy %ExternalsSourceDirectory%\DXR\bin\x64 %DestinationDirectory% *.dll /r:0 >nul
del %DestinationDirectory%\dxil.dll >nul
) ELSE (
del %DestinationDirectory%\d3d12.dll >nul
del %DestinationDirectory%\d3d12SDKLayers.dll >nul
del %DestinationDirectory%\dxcompiler.dll >nul
del %DestinationDirectory%\dxgidebug.dll >nul
robocopy %ExternalsSourceDirectory%\dxcompiler\x64\ %DestinationDirectory% *.dll /r:0 >nul
)

rem robocopy sets the error level to something that is not zero even if the copy operation was successful. Set the error level to zero
Expand Down
30 changes: 17 additions & 13 deletions Framework/Source/API/CopyContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ namespace Falcor
mpLowLevelData->getFence()->syncCpu();
}
}

void CopyContext::updateTexture(const Texture* pTexture, const void* pData)
{
mCommandsPending = true;
uint32_t subresourceCount = pTexture->getArraySize() * pTexture->getMipCount();
if (pTexture->getType() == Texture::Type::TextureCube)
{
subresourceCount *= 6;
}
updateTextureSubresources(pTexture, 0, subresourceCount, pData);
}

CopyContext::ReadTextureTask::SharedPtr CopyContext::asyncReadTextureSubresource(const Texture* pTexture, uint32_t subresourceIndex)
{
Expand All @@ -80,8 +69,6 @@ namespace Falcor
return pTask->getData();
}



void CopyContext::resourceBarrier(const Resource* pResource, Resource::State newState, const ResourceViewInfo* pViewInfo)
{
const Texture* pTexture = dynamic_cast<const Texture*>(pResource);
Expand Down Expand Up @@ -141,4 +128,21 @@ namespace Falcor
}
if (setGlobal) pTexture->setGlobalState(newState);
}

void CopyContext::updateTextureData(const Texture* pTexture, const void* pData)
{
mCommandsPending = true;
uint32_t subresourceCount = pTexture->getArraySize() * pTexture->getMipCount();
if (pTexture->getType() == Texture::Type::TextureCube)
{
subresourceCount *= 6;
}
updateTextureSubresources(pTexture, 0, subresourceCount, pData);
}

void CopyContext::updateSubresourceData(const Texture* pDst, uint32_t subresource, const void* pData, const uvec3& offset, const uvec3& size)
{
mCommandsPending = true;
updateTextureSubresources(pDst, subresource, 1, pData, offset, size);
}
}
35 changes: 29 additions & 6 deletions Framework/Source/API/CopyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ namespace Falcor
};

static SharedPtr create(CommandQueueHandle queue);
void updateBuffer(const Buffer* pBuffer, const void* pData, size_t offset = 0, size_t numBytes = 0);
void updateTexture(const Texture* pTexture, const void* pData);
void updateTextureSubresource(const Texture* pTexture, uint32_t subresourceIndex, const void* pData);
void updateTextureSubresources(const Texture* pTexture, uint32_t firstSubresource, uint32_t subresourceCount, const void* pData);
ReadTextureTask::SharedPtr asyncReadTextureSubresource(const Texture* pTexture, uint32_t subresourceIndex);
std::vector<uint8> readTextureSubresource(const Texture* pTexture, uint32_t subresourceIndex);

/** Flush the command list. This doesn't reset the command allocator, just submits the commands
\param[in] wait If true, will block execution until the GPU finished processing the commands
Expand Down Expand Up @@ -103,6 +97,33 @@ namespace Falcor
*/
void copyBufferRegion(const Buffer* pDst, uint64_t dstOffset, const Buffer* pSrc, uint64_t srcOffset, uint64_t numBytes);

/** Copy a region of a subresource from one texture to another
`srcOffset`, `dstOffset` and `size` describe the source and destination regions. For any channel of `extent` that is -1, the source texture dimension will be used
*/
void copySubresourceRegion(const Texture* pDst, uint32_t dstSubresource, const Texture* pSrc, uint32_t srcSubresource, const uvec3& dstOffset = uvec3(0), const uvec3& srcOffset = uvec3(0), const uvec3& size = uvec3(-1));

/** Update a texture's subresource data
`offset` and `size` describe a region to update. For any channel of `extent` that is -1, the texture dimension will be used.
pData can't be null. The size of the pointed buffer must be equal to a single texel size times the size of the region we are updating
*/
void updateSubresourceData(const Texture* pDst, uint32_t subresource, const void* pData, const uvec3& offset = uvec3(0), const uvec3& size = uvec3(-1));

/** Update an entire texture
*/
void updateTextureData(const Texture* pTexture, const void* pData);

/** Update a buffer
*/
void updateBuffer(const Buffer* pBuffer, const void* pData, size_t offset = 0, size_t numBytes = 0);

/** Read texture data synchronously. Calling this command will flush the pipeline and wait for the GPU to finish execution
*/
std::vector<uint8> readTextureSubresource(const Texture* pTexture, uint32_t subresourceIndex);

/** Read texture data Asynchronously
*/
ReadTextureTask::SharedPtr asyncReadTextureSubresource(const Texture* pTexture, uint32_t subresourceIndex);

/** Get the low-level context data
*/
virtual const LowLevelContextData::SharedPtr& getLowLevelData() const { return mpLowLevelData; }
Expand All @@ -120,6 +141,8 @@ namespace Falcor
void bufferBarrier(const Buffer* pBuffer, Resource::State newState);
void subresourceBarriers(const Texture* pTexture, Resource::State newState, const ResourceViewInfo* pViewInfo);
void apiSubresourceBarrier(const Texture* pTexture, Resource::State newState, Resource::State oldState, uint32_t arraySlice, uint32_t mipLevel);
void updateTextureSubresources(const Texture* pTexture, uint32_t firstSubresource, uint32_t subresourceCount, const void* pData, const uvec3& offset = uvec3(0), const uvec3& size = uvec3(-1));

CopyContext() = default;
bool mCommandsPending = false;
LowLevelContextData::SharedPtr mpLowLevelData;
Expand Down
73 changes: 58 additions & 15 deletions Framework/Source/API/D3D12/D3D12CopyContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,50 @@ namespace Falcor
}
}

void CopyContext::updateTextureSubresources(const Texture* pTexture, uint32_t firstSubresource, uint32_t subresourceCount, const void* pData)
void CopyContext::updateTextureSubresources(const Texture* pTexture, uint32_t firstSubresource, uint32_t subresourceCount, const void* pData, const uvec3& offset, const uvec3& size)
{
bool copyRegion = (offset != uvec3(0)) || (size != uvec3(-1));
assert(subresourceCount == 1 || (copyRegion == false));

mCommandsPending = true;

uint32_t arraySize = (pTexture->getType() == Texture::Type::TextureCube) ? pTexture->getArraySize() * 6 : pTexture->getArraySize();
assert(firstSubresource + subresourceCount <= arraySize * pTexture->getMipCount());

ID3D12Device* pDevice = gpDevice->getApiHandle();

// Get the footprint
D3D12_RESOURCE_DESC texDesc = pTexture->getApiHandle()->GetDesc();
std::vector<D3D12_PLACED_SUBRESOURCE_FOOTPRINT> footprint(subresourceCount);
std::vector<uint32_t> rowCount(subresourceCount);
std::vector<uint64_t> rowSize(subresourceCount);
uint64_t size;
pDevice->GetCopyableFootprints(&texDesc, firstSubresource, subresourceCount, 0, footprint.data(), rowCount.data(), rowSize.data(), &size);
uint64_t bufferSize;

if (copyRegion)
{
footprint[0].Offset = 0;
footprint[0].Footprint.Format = getDxgiFormat(pTexture->getFormat());
uint32_t mipLevel = pTexture->getSubresourceMipLevel(firstSubresource);
footprint[0].Footprint.Width = (size.x == -1) ? pTexture->getWidth(mipLevel) - offset.x : size.x;
footprint[0].Footprint.Height = (size.y == -1) ? pTexture->getHeight(mipLevel) - offset.y : size.y;
footprint[0].Footprint.Depth = (size.z == -1) ? pTexture->getDepth(mipLevel) - offset.z : size.z;
footprint[0].Footprint.RowPitch = footprint[0].Footprint.Width * getFormatBytesPerBlock(pTexture->getFormat());
rowCount[0] = footprint[0].Footprint.Height;
rowSize[0] = footprint[0].Footprint.RowPitch;
bufferSize = rowSize[0] * rowCount[0] * footprint[0].Footprint.Depth;
}
else
{
ID3D12Device* pDevice = gpDevice->getApiHandle();
pDevice->GetCopyableFootprints(&texDesc, firstSubresource, subresourceCount, 0, footprint.data(), rowCount.data(), rowSize.data(), &bufferSize);
}

// Allocate a buffer on the upload heap
Buffer::SharedPtr pBuffer = Buffer::create(size, Buffer::BindFlags::None, Buffer::CpuAccess::Write, nullptr);
Buffer::SharedPtr pBuffer = Buffer::create(bufferSize, Buffer::BindFlags::None, Buffer::CpuAccess::Write, nullptr);
// Map the buffer
uint8_t* pDst = (uint8_t*)pBuffer->map(Buffer::MapType::WriteDiscard);
ID3D12ResourcePtr pResource = pBuffer->getApiHandle();

// Get the offset from the beginning of the resource
uint64_t offset = pBuffer->getGpuAddressOffset();
uint64_t vaOffset = pBuffer->getGpuAddressOffset();
resourceBarrier(pTexture, Resource::State::CopyDest);

const uint8_t* pSrc = (uint8_t*)pData;
Expand All @@ -113,22 +132,17 @@ namespace Falcor
pSrc = (uint8_t*)pSrc + footprint[s].Footprint.Depth * src.SlicePitch;

// Dispatch a command
footprint[s].Offset += offset;
footprint[s].Offset += vaOffset;
uint32_t subresource = s + firstSubresource;
D3D12_TEXTURE_COPY_LOCATION dstLoc = { pTexture->getApiHandle(), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, subresource };
D3D12_TEXTURE_COPY_LOCATION srcLoc = { pResource, D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT, footprint[s] };
mpLowLevelData->getCommandList()->CopyTextureRegion(&dstLoc, 0, 0, 0, &srcLoc, nullptr);

mpLowLevelData->getCommandList()->CopyTextureRegion(&dstLoc, offset.x, offset.y, offset.z, &srcLoc, nullptr);
}

pBuffer->unmap();
}

void CopyContext::updateTextureSubresource(const Texture* pTexture, uint32_t subresourceIndex, const void* pData)
{
mCommandsPending = true;
updateTextureSubresources(pTexture, subresourceIndex, 1, pData);
}

CopyContext::ReadTextureTask::SharedPtr CopyContext::ReadTextureTask::create(CopyContext::SharedPtr pCtx, const Texture* pTexture, uint32_t subresourceIndex)
{
SharedPtr pThis = SharedPtr(new ReadTextureTask);
Expand Down Expand Up @@ -278,4 +292,33 @@ namespace Falcor
mpLowLevelData->getCommandList()->CopyBufferRegion(pDst->getApiHandle(), dstOffset, pSrc->getApiHandle(), pSrc->getGpuAddressOffset() + srcOffset, numBytes);
mCommandsPending = true;
}

void CopyContext::copySubresourceRegion(const Texture* pDst, uint32_t dstSubresource, const Texture* pSrc, uint32_t srcSubresource, const uvec3& dstOffset, const uvec3& srcOffset, const uvec3& size)
{
resourceBarrier(pDst, Resource::State::CopyDest);
resourceBarrier(pSrc, Resource::State::CopySource);

D3D12_TEXTURE_COPY_LOCATION dstLoc = {};
dstLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
dstLoc.SubresourceIndex = dstSubresource;
dstLoc.pResource = pDst->getApiHandle();

D3D12_TEXTURE_COPY_LOCATION srcLoc = {};
srcLoc.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;
srcLoc.SubresourceIndex = srcSubresource;
srcLoc.pResource = pSrc->getApiHandle();

D3D12_BOX box;
box.left = srcOffset.x;
box.top = srcOffset.y;
box.front = srcOffset.z;
uint32_t mipLevel = pSrc->getSubresourceMipLevel(dstSubresource);
box.right = (size.x == -1) ? pSrc->getWidth(mipLevel) - box.left : size.x;
box.bottom = (size.y == -1) ? pSrc->getHeight(mipLevel) - box.top : size.y;
box.back = (size.z == -1) ? pSrc->getDepth(mipLevel) - box.front : size.z;

mpLowLevelData->getCommandList()->CopyTextureRegion(&dstLoc, dstOffset.x, dstOffset.y, dstOffset.z, &srcLoc, &box);

mCommandsPending = true;
}
}
80 changes: 40 additions & 40 deletions Framework/Source/API/D3D12/D3DShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ namespace Falcor
ID3DBlobPtr pBlob;
};

const char* getTargetString(ShaderType type)
std::string getTargetString(ShaderType type, const std::string& shaderModel)
{
switch (type)
{
case ShaderType::Vertex:
return "vs_5_1";
return "vs_" + shaderModel;
case ShaderType::Pixel:
return "ps_5_1";
return "ps_" + shaderModel;
case ShaderType::Hull:
return "hs_5_1";
return "hs_" + shaderModel;
case ShaderType::Domain:
return "ds_5_1";
return "ds_" + shaderModel;
case ShaderType::Geometry:
return "gs_5_1";
return "gs_" + shaderModel;
case ShaderType::Compute:
return "cs_5_1";
return "cs_" + shaderModel;
default:
should_not_get_here();
return "";
Expand All @@ -60,13 +60,11 @@ namespace Falcor

struct SlangBlob : ID3DBlob
{
void* buffer;
size_t bufferSize;
std::vector<uint8_t> data;
size_t refCount;

SlangBlob(void* buffer, size_t bufferSize)
: buffer(buffer)
, bufferSize(bufferSize)
SlangBlob(const void* buffer, size_t bufferSize)
: data((uint8_t*)buffer, ((uint8_t*)buffer) + bufferSize)
, refCount(1)
{}

Expand Down Expand Up @@ -100,12 +98,12 @@ namespace Falcor

virtual LPVOID STDMETHODCALLTYPE GetBufferPointer() override
{
return buffer;
return data.data();
}

virtual SIZE_T STDMETHODCALLTYPE GetBufferSize() override
{
return bufferSize;
return data.size();
}
};

Expand All @@ -122,29 +120,36 @@ namespace Falcor

ID3DBlobPtr Shader::compile(const Blob& blob, const std::string& entryPointName, CompilerFlags flags, std::string& errorLog)
{
ID3DBlob* pCode;
ID3DBlobPtr pErrors;

UINT d3dFlags = getD3dCompilerFlags(flags);

HRESULT hr = D3DCompile(
blob.data.data(),
blob.data.size(),
nullptr,
nullptr,
nullptr,
entryPointName.c_str(),
getTargetString(mType),
d3dFlags,
0,
&pCode,
&pErrors);
if(FAILED(hr))
ID3DBlob* pCode = nullptr;

if (blob.type == Blob::Type::String)
{
errorLog = convertBlobToString(pErrors.GetInterfacePtr());
return nullptr;
ID3DBlobPtr pErrors;
UINT d3dFlags = getD3dCompilerFlags(flags);

HRESULT hr = D3DCompile(
blob.data.data(),
blob.data.size(),
nullptr,
nullptr,
nullptr,
entryPointName.c_str(),
getTargetString(mType, blob.shaderModel).c_str(),
d3dFlags,
0,
&pCode,
&pErrors);
if (FAILED(hr))
{
errorLog = convertBlobToString(pErrors.GetInterfacePtr());
return nullptr;
}
}
else
{
assert(blob.type == Blob::Type::Bytecode);
pCode = new SlangBlob(blob.data.data(), blob.data.size());
}

return pCode;
}

Expand All @@ -161,11 +166,6 @@ namespace Falcor

bool Shader::init(const Blob& shaderBlob, const std::string& entryPointName, CompilerFlags flags, std::string& log)
{
if (shaderBlob.type != Blob::Type::String)
{
logError("D3D shader compilation only supports string inputs");
return false;
}
// Compile the shader
ShaderData* pData = (ShaderData*)mpPrivateData;
pData->pBlob = compile(shaderBlob, entryPointName, flags, log);
Expand Down
1 change: 1 addition & 0 deletions Framework/Source/API/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace Falcor
};
std::vector<uint8_t> data;
Type type = Type::Undefined;
std::string shaderModel;
};

enum class CompilerFlags
Expand Down
Loading

0 comments on commit cc62b5b

Please sign in to comment.