Skip to content

Commit

Permalink
Merge branch 'dev-3.0.3' into rel-3.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kyaoNV committed May 25, 2018
2 parents 0b561ca + 5ab1324 commit ca8c955
Show file tree
Hide file tree
Showing 34 changed files with 1,277 additions and 110 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
v3.0.3
------
- Added FXAA as an effect
- Support programmable sample position - `Fbo::setSamplePositions()` (DX only)
- Added RenderContext::resolveResource() and RenderContext::resolveSubresource() MSAA resolve functions
- Added support for setting shading model through fscene files and load flags. Also editable in Scene Editor

v3.0.2
------
- Various bug fixes
- Fixed Vulkan error spam seen when running Falcor's included samples
- Updated API abstraction interfaces to return const-ref where applicable
- Fixed crash when handling mouse/keyboard messages after the renderer has shut down

v3.0.1
------
- Added RenderContext::StateBindFlags, which allows the user to control which part of the `GraphicsState` will be bound to the pipeline
Expand Down
70 changes: 69 additions & 1 deletion Framework/Source/API/D3D12/D3D12RenderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,38 @@ namespace Falcor
}
}
}
ID3D12GraphicsCommandList* pCmdList = pCtx->getLowLevelData()->getCommandList().GetInterfacePtr();
pCmdList->OMSetRenderTargets(colorTargets, pRTV.data(), FALSE, &pDSV);
}

static void D3D12SetSamplePositions(ID3D12GraphicsCommandList* pList, const Fbo* pFbo)
{
if (!pFbo) return;
ID3D12GraphicsCommandList1* pList1;
pList->QueryInterface(IID_PPV_ARGS(&pList1));
const auto& samplePos = pFbo->getSamplePositions();

if (!pList1)
{
if (samplePos.size())
{
logError("The FBO specifies programmable sample positions, but the hardware doesn't support it");
}
}
else
{
static_assert(offsetof(Fbo::SamplePosition, xOffset) == offsetof(D3D12_SAMPLE_POSITION, X), "SamplePosition.X");
static_assert(offsetof(Fbo::SamplePosition, yOffset) == offsetof(D3D12_SAMPLE_POSITION, Y), "SamplePosition.Y");

pCtx->getLowLevelData()->getCommandList()->OMSetRenderTargets(colorTargets, pRTV.data(), FALSE, &pDSV);
if (samplePos.size())
{
pList1->SetSamplePositions(pFbo->getSampleCount(), pFbo->getSamplePositionsPixelCount(), (D3D12_SAMPLE_POSITION*)samplePos.data());
}
else
{
pList1->SetSamplePositions(0, 0, nullptr);
}
}
}

static void D3D12SetViewports(ID3D12GraphicsCommandList* pList, const GraphicsState::Viewport* vp)
Expand Down Expand Up @@ -258,6 +288,10 @@ namespace Falcor
{
D3D12SetFbo(this, mpGraphicsState->getFbo().get());
}
if (is_set(StateBindFlags::SamplePositions, mBindFlags))
{
D3D12SetSamplePositions(pList, mpGraphicsState->getFbo().get());
}
if (is_set(StateBindFlags::Viewports, mBindFlags))
{
D3D12SetViewports(pList, &mpGraphicsState->getViewport(0));
Expand All @@ -270,6 +304,13 @@ namespace Falcor
{
pList->SetPipelineState(mpGraphicsState->getGSO(mpGraphicsVars.get())->getApiHandle());
}
if (is_set(StateBindFlags::SamplePositions, mBindFlags))
{
if (mpGraphicsState->getFbo() && mpGraphicsState->getFbo()->getSamplePositions().size())
{
logWarning("The Vulkan backend doesn't support programmable sample positions");
}
}

BlendState::SharedPtr blendState = mpGraphicsState->getBlendState();
if (blendState != nullptr)
Expand Down Expand Up @@ -419,4 +460,31 @@ namespace Falcor
popGraphicsState();
popGraphicsVars();
}

void RenderContext::resolveSubresource(const Texture* pSrc, uint32_t srcSubresource, const Texture* pDst, uint32_t dstSubresource)
{
DXGI_FORMAT format = getDxgiFormat(pDst->getFormat());
mpLowLevelData->getCommandList()->ResolveSubresource(pDst->getApiHandle(), dstSubresource, pSrc->getApiHandle(), srcSubresource, format);
mCommandsPending = true;
}

void RenderContext::resolveResource(const Texture* pSrc, const Texture* pDst)
{
bool match = true;
match = match && (pSrc->getMipCount() == pDst->getMipCount());
match = match && (pSrc->getArraySize() == pDst->getArraySize());
if (!match)
{
logWarning("Can't resolve a resource. The src and dst textures have a different array-size or mip-count");
}

resourceBarrier(pSrc, Resource::State::ResolveSource);
resourceBarrier(pDst, Resource::State::ResolveDest);

uint32_t subresourceCount = pSrc->getMipCount() * pSrc->getArraySize();
for (uint32_t s = 0; s < subresourceCount; s++)
{
resolveSubresource(pSrc, s, pDst, s);
}
}
}
18 changes: 16 additions & 2 deletions Framework/Source/API/D3D12/LowLevel/D3D12LowLevelContextData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ namespace Falcor
return pAllocator;
}

template<typename ApiType>
ApiType createCommandList(ID3D12Device* pDevice, D3D12_COMMAND_LIST_TYPE type, CommandAllocatorHandle allocator)
{
ApiType pList;
HRESULT hr = pDevice->CreateCommandList(0, type, allocator, nullptr, IID_PPV_ARGS(&pList));
return (FAILED(hr)) ? nullptr : pList;
}

LowLevelContextData::SharedPtr LowLevelContextData::create(CommandQueueType type, CommandQueueHandle queue)
{
SharedPtr pThis = SharedPtr(new LowLevelContextData);
Expand All @@ -69,9 +77,15 @@ namespace Falcor
}
pThis->mpAllocator = pThis->mpApiData->pAllocatorPool->newObject();

// Create a command list
// Create a command list. Try to create the latest version the device supports
ID3D12Device* pDevice = gpDevice->getApiHandle().GetInterfacePtr();
if (FAILED(pDevice->CreateCommandList(0, cmdListType, pThis->mpAllocator, nullptr, IID_PPV_ARGS(&pThis->mpList))))
#ifdef FALCOR_DXR
pThis->mpList = createCommandList<ID3D12GraphicsCommandList2*>(pDevice, cmdListType, pThis->mpAllocator);
#endif
if (!pThis->mpList) pThis->mpList = createCommandList<ID3D12GraphicsCommandList1*>(pDevice, cmdListType, pThis->mpAllocator);
if (!pThis->mpList) pThis->mpList = createCommandList<ID3D12GraphicsCommandList*>(pDevice, cmdListType, pThis->mpAllocator);

if (pThis->mpList == nullptr)
{
logError("Failed to create command list for LowLevelContextData");
return nullptr;
Expand Down
25 changes: 25 additions & 0 deletions Framework/Source/API/FBO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ namespace Falcor
// Check depth
if (verifyAttachment(mDepthStencil) == false) return false;

// In case there are sample positions, make sure they are valid
if (mSamplePositions.size())
{
uint32_t expectedCount = mSamplePositionsPixelCount * mTempDesc.getSampleCount();
if (expectedCount != mSamplePositions.size())
{
logError("Error when validating FBO. The sample-positions array-size has the wrong size.\n");
return false;
}
}

// Insert the attachment into the static array and initialize the address
mpDesc = &(*(sDescs.insert(mTempDesc).first));

Expand Down Expand Up @@ -303,4 +314,18 @@ namespace Falcor
}
return true;
}

void Fbo::setSamplePositions(uint32_t samplesPerPixel, uint32_t pixelCount, const SamplePosition positions[])
{
if (positions)
{
mSamplePositions = std::vector<SamplePosition>(positions, positions + (samplesPerPixel * pixelCount));
mSamplePositionsPixelCount = pixelCount;
}
else
{
mSamplePositionsPixelCount = 0;
mSamplePositions.clear();
}
}
}
26 changes: 26 additions & 0 deletions Framework/Source/API/FBO.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,29 @@ namespace Falcor
*/
RenderTargetView::SharedPtr getRenderTargetView(uint32_t rtIndex) const;


struct SamplePosition
{
int8 xOffset = 0;
int8 yOffset = 0;
};

/** Configure the sample positions used by multi-sampled buffers.
\param[in] samplesPerPixel The number of samples-per-pixel. This value has to match the FBO's sample count
\param[in] pixelCount the number if pixels the sample pattern is specified for
\param[in] positions The sample positions. (0,0) is a pixel's center. The size of this array should be samplesPerPixel*pixelCount
To reset the positions to their original location pass `nullptr` for positions
*/
void setSamplePositions(uint32_t samplesPerPixel, uint32_t pixelCount, const SamplePosition positions[]);

/** Get the sample positions
*/
const std::vector<SamplePosition> getSamplePositions() const { return mSamplePositions; }

/** Get the number of pixels the sample positions are configured for
*/
uint32_t getSamplePositionsPixelCount() const { return mSamplePositionsPixelCount; }

struct Attachment
{
Texture::SharedPtr pTexture = nullptr;
Expand All @@ -215,6 +238,9 @@ namespace Falcor

Fbo();
std::vector<Attachment> mColorAttachments;
std::vector<SamplePosition> mSamplePositions;
uint32_t mSamplePositionsPixelCount = 0;

Attachment mDepthStencil;

mutable Desc mTempDesc;
Expand Down
1 change: 1 addition & 0 deletions Framework/Source/API/RenderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ namespace Falcor
mBindGraphicsRootSig = true;
}
}

11 changes: 11 additions & 0 deletions Framework/Source/API/RenderContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace Falcor
Viewports = 0x10, ///<Bind Viewport
Scissors = 0x20, ///<Bind scissors
PipelineState = 0x40, ///<Bind Pipeline State Object
SamplePositions = 0x80, ///<Set the programmable sample positions
All = uint32_t(-1)
};

Expand Down Expand Up @@ -188,11 +189,21 @@ namespace Falcor
*/
void setBindFlags(StateBindFlags flags) { mBindFlags = flags; }

/** Resolve an entire multi-sampled resource. The dst and src resources must have the same dimensions, array-size, mip-count and format.
If any of these properties don't match, you'll have to use `resolveSubresource`
*/
void resolveResource(const Texture* pSrc, const Texture* pDst);

/** Resolve a multi-sampled sub-resource
*/
void resolveSubresource(const Texture* pSrc, uint32_t srcSubresource, const Texture* pDst, uint32_t dstSubresource);

#ifdef FALCOR_DXR
/** Submit a raytrace command. This function doesn't change the state of the render-context. Graphics/compute vars and state will stay the same
*/
void raytrace(std::shared_ptr<RtProgramVars> pVars, std::shared_ptr<RtState> pState, uint32_t width, uint32_t height);
#endif

private:
RenderContext();
GraphicsVars::SharedPtr mpGraphicsVars;
Expand Down
12 changes: 5 additions & 7 deletions Framework/Source/API/Vulkan/VKCopyContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace Falcor
return size;
}

static VkImageLayout getImageLayout(Resource::State state)
VkImageLayout getImageLayout(Resource::State state)
{
switch (state)
{
Expand All @@ -76,15 +76,15 @@ namespace Falcor
case Resource::State::UnorderedAccess:
return VK_IMAGE_LAYOUT_GENERAL;
case Resource::State::RenderTarget:
case Resource::State::ResolveDest:
return VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
case Resource::State::DepthStencil:
return VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
case Resource::State::ShaderResource:
case Resource::State::ResolveSource:
return VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
case Resource::State::ResolveDest:
case Resource::State::CopyDest:
return VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
case Resource::State::ResolveSource:
case Resource::State::CopySource:
return VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
break;
Expand Down Expand Up @@ -121,14 +121,12 @@ namespace Falcor
return VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
case Resource::State::IndirectArg:
return VK_ACCESS_INDIRECT_COMMAND_READ_BIT;
case Resource::State::ResolveDest:
case Resource::State::CopyDest:
return VK_ACCESS_TRANSFER_WRITE_BIT;
case Resource::State::ResolveSource:
case Resource::State::CopySource:
return VK_ACCESS_TRANSFER_READ_BIT;
case Resource::State::ResolveDest:
return VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
case Resource::State::ResolveSource:
return VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
default:
should_not_get_here();
return VkAccessFlagBits(-1);
Expand Down
3 changes: 2 additions & 1 deletion Framework/Source/API/Vulkan/VKGpuTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace Falcor
{
void GpuTimer::apiBegin()
{
vkCmdResetQueryPool(mpLowLevelData->getCommandList(), mpHeap, mStart, 2);
vkCmdWriteTimestamp(mpLowLevelData->getCommandList(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, mpHeap, mStart);
}

Expand All @@ -43,6 +44,6 @@ namespace Falcor

void GpuTimer::apiResolve(uint64_t result[2])
{
vk_call(vkGetQueryPoolResults(gpDevice->getApiHandle(), mpHeap, mStart, 2, sizeof(uint64_t)*2, result, sizeof(result[0]), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT));
vk_call(vkGetQueryPoolResults(gpDevice->getApiHandle(), mpHeap, mStart, 2, sizeof(uint64_t) * 2, result, sizeof(result[0]), VK_QUERY_RESULT_64_BIT | VK_QUERY_RESULT_WAIT_BIT));
}
}
23 changes: 22 additions & 1 deletion Framework/Source/API/Vulkan/VKRenderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
namespace Falcor
{
VkImageAspectFlags getAspectFlagsFromFormat(ResourceFormat format);

VkImageLayout getImageLayout(Resource::State state);

RenderContext::SharedPtr RenderContext::create(CommandQueueHandle queue)
{
SharedPtr pCtx = SharedPtr(new RenderContext());
Expand Down Expand Up @@ -319,5 +320,25 @@ namespace Falcor
VkFilter vkFilter = isDepthStencilFormat(pTexture->getFormat()) ? VK_FILTER_NEAREST : getVkFilter(filter);
vkCmdBlitImage(mpLowLevelData->getCommandList(), pSrc->getResource()->getApiHandle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, pDst->getResource()->getApiHandle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blt, vkFilter);
}
mCommandsPending = true;
}

void RenderContext::resolveResource(const Texture* pSrc, const Texture* pDst)
{
// Just blit. It will work
blit(pSrc->getSRV(), pDst->getRTV());
}

void RenderContext::resolveSubresource(const Texture* pSrc, uint32_t srcSubresource, const Texture* pDst, uint32_t dstSubresource)
{
uint32_t srcArray = pSrc->getSubresourceArraySlice(srcSubresource);
uint32_t srcMip = pSrc->getSubresourceMipLevel(srcSubresource);
const auto& pSrcSrv = pSrc->getSRV(srcMip, 1, srcArray, 1);

uint32_t dstArray = pDst->getSubresourceArraySlice(dstSubresource);
uint32_t dstMip = pDst->getSubresourceMipLevel(dstSubresource);
const auto& pDstRtv = pDst->getRTV(dstMip, dstArray, 1);

blit(pSrcSrv, pDstRtv);
}
}
Loading

0 comments on commit ca8c955

Please sign in to comment.