Skip to content

Commit

Permalink
Merge branch 'dev-3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kyaoNV committed May 8, 2018
2 parents 81afa17 + 17d3901 commit 237847c
Show file tree
Hide file tree
Showing 43 changed files with 1,003 additions and 246 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
v3.0.1
------
- Added RenderContext::StateBindFlags, which allows the user to control which part of the `GraphicsState` will be bound to the pipeline
- Added helper functions to initialize D3D12 state-objects descs (root-signature, GSO-desc)
- Added a function that creates a texture from an resource API handle
- Added a new sample: LightProbeViewer. Allows you to see how light probe images look after pre-integration with various sample counts and materials.
15 changes: 15 additions & 0 deletions Falcor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Raytracing", "Raytracing",
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloDXR", "Samples\Raytracing\HelloDXR\HelloDXR.vcxproj", "{71B60B71-89A2-4196-BFB9-4A848CF6C541}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LightProbeViewer", "Samples\Utils\LightProbeViewer\LightProbeViewer.vcxproj", "{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
DebugD3D12|x64 = DebugD3D12|x64
Expand Down Expand Up @@ -281,6 +283,18 @@ Global
{71B60B71-89A2-4196-BFB9-4A848CF6C541}.ReleaseDXR|x64.ActiveCfg = Release|x64
{71B60B71-89A2-4196-BFB9-4A848CF6C541}.ReleaseDXR|x64.Build.0 = Release|x64
{71B60B71-89A2-4196-BFB9-4A848CF6C541}.ReleaseVK|x64.ActiveCfg = Release|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.DebugD3D12|x64.ActiveCfg = Debug|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.DebugD3D12|x64.Build.0 = Debug|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.DebugDXR|x64.ActiveCfg = Debug|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.DebugDXR|x64.Build.0 = Debug|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.DebugVK|x64.ActiveCfg = Debug|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.DebugVK|x64.Build.0 = Debug|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.ReleaseD3D12|x64.ActiveCfg = Release|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.ReleaseD3D12|x64.Build.0 = Release|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.ReleaseDXR|x64.ActiveCfg = Release|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.ReleaseDXR|x64.Build.0 = Release|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.ReleaseVK|x64.ActiveCfg = Release|x64
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5}.ReleaseVK|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -308,6 +322,7 @@ Global
{0C3483E0-B6C1-41BC-B8F9-306F9BA5F287} = {6DCFDAD9-C58B-401F-9FAD-04E9D4A7CB28}
{6D4D8D4B-CFFB-455A-BFFC-9490C5583150} = {518F9E6D-D9DE-4557-94EC-F0F466354504}
{71B60B71-89A2-4196-BFB9-4A848CF6C541} = {6D4D8D4B-CFFB-455A-BFFC-9490C5583150}
{9D80D89D-D029-4E3E-BCA8-424ECC1F1DF5} = {152F0E49-0B22-4359-B8FB-BD76093D36DE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {357B2AE0-FE30-4AC6-8D41-B580232BC0DE}
Expand Down
1 change: 0 additions & 1 deletion Framework/BuildScripts/movedata.bat
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ robocopy %ExternalsSourceDirectory%\OptiX\bin64 %DestinationDirectory% *.dll /r
robocopy %ExternalsSourceDirectory%\openvr\bin\win64 %DestinationDirectory% openvr_api.dll /r:0 >nul
robocopy %ExternalsSourceDirectory%\Slang\bin\windows-x64\release %DestinationDirectory% *.dll /r:0 >nul
robocopy %ExternalsSourceDirectory%\GLFW\lib %DestinationDirectory% *.dll /r:0 >nul
echo %1
call %1\BuildScripts\moveprojectdata.bat %1\Source\ %DestinationDirectory%
call %1\BuildScripts\moveprojectdata.bat %3 %DestinationDirectory% /r:0 >nul

Expand Down
6 changes: 5 additions & 1 deletion Framework/Source/API/CopyContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ namespace Falcor
/** Override the low-level context data with a user provided object
*/
void setLowLevelContextData(LowLevelContextData::SharedPtr pLowLevelData) { mpLowLevelData = pLowLevelData; }
protected:

/** Bind the descriptor heaps from the device into the command-list
*/
void bindDescriptorHeaps();

protected:
void textureBarrier(const Texture* pTexture, Resource::State newState);
void bufferBarrier(const Buffer* pBuffer, Resource::State newState);
void subresourceBarriers(const Texture* pTexture, Resource::State newState, const ResourceViewInfo* pViewInfo);
Expand Down
46 changes: 5 additions & 41 deletions Framework/Source/API/D3D12/D3D12GraphicsStateObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,55 +101,19 @@ namespace Falcor

bool GraphicsStateObject::apiInit()
{
D3D12_GRAPHICS_PIPELINE_STATE_DESC desc = {};
assert(mDesc.mpProgram);
#define get_shader_handle(_type) mDesc.mpProgram->getShader(_type) ? mDesc.mpProgram->getShader(_type)->getApiHandle() : D3D12_SHADER_BYTECODE{}

desc.VS = get_shader_handle(ShaderType::Vertex);
desc.PS = get_shader_handle(ShaderType::Pixel);
desc.GS = get_shader_handle(ShaderType::Geometry);
desc.HS = get_shader_handle(ShaderType::Hull);
desc.DS = get_shader_handle(ShaderType::Domain);
#undef get_shader_handle

initD3D12BlendDesc(mDesc.mpBlendState.get(), desc.BlendState);
initD3D12RasterizerDesc(mDesc.mpRasterizerState.get(), desc.RasterizerState);
initD3DDepthStencilDesc(mDesc.mpDepthStencilState.get(), desc.DepthStencilState);

InputLayoutDesc layoutDesc;
if(mDesc.mpLayout)
{
initD3D12VertexLayout(mDesc.mpLayout.get(), layoutDesc);
desc.InputLayout.NumElements = (uint32_t)layoutDesc.elements.size();
desc.InputLayout.pInputElementDescs = layoutDesc.elements.data();
}
desc.SampleMask = mDesc.mSampleMask;
desc.pRootSignature = mDesc.mpRootSignature ? mDesc.mpRootSignature->getApiHandle() : nullptr;

uint32_t numRtvs = 0;
for (uint32_t rt = 0; rt < Fbo::getMaxColorTargetCount(); rt++)
{
desc.RTVFormats[rt] = getDxgiFormat(mDesc.mFboDesc.getColorTargetFormat(rt));
if (desc.RTVFormats[rt] != DXGI_FORMAT_UNKNOWN)
{
numRtvs = rt + 1;
}
}
desc.NumRenderTargets = numRtvs;
desc.DSVFormat = getDxgiFormat(mDesc.mFboDesc.getDepthStencilFormat());
desc.SampleDesc.Count = mDesc.mFboDesc.getSampleCount();

desc.PrimitiveTopologyType = getD3DPrimitiveType(mDesc.mPrimType);
D3D12_GRAPHICS_PIPELINE_STATE_DESC d3dDesc;
InputLayoutDesc inputDesc;
initD3D12GraphicsStateDesc(mDesc, d3dDesc, inputDesc);

if (getIsNvApiGraphicsPsoRequired(mDesc))
{
std::vector<NvApiPsoExDesc> nvApiDesc;
getNvApiGraphicsPsoDesc(mDesc, nvApiDesc);
mApiHandle = getNvApiGraphicsPsoHandle(nvApiDesc, desc);
mApiHandle = getNvApiGraphicsPsoHandle(nvApiDesc, d3dDesc);
}
else
{
d3d_call(gpDevice->getApiHandle()->CreateGraphicsPipelineState(&desc, IID_PPV_ARGS(&mApiHandle)));
d3d_call(gpDevice->getApiHandle()->CreateGraphicsPipelineState(&d3dDesc, IID_PPV_ARGS(&mApiHandle)));
}
return true;
}
Expand Down
48 changes: 35 additions & 13 deletions Framework/Source/API/D3D12/D3D12RenderContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,17 @@ namespace Falcor
// Vao must be valid so at least primitive topology is known
assert(mpGraphicsState->getVao().get());

// Apply the vars. Must be first because applyGraphicsVars() might cause a flush
if (mpGraphicsVars)
if (is_set(StateBindFlags::Vars, mBindFlags))
{
applyGraphicsVars();
}
else
{
mpLowLevelData->getCommandList()->SetGraphicsRootSignature(RootSignature::getEmpty()->getApiHandle());
// Apply the vars. Must be first because applyGraphicsVars() might cause a flush
if (mpGraphicsVars)
{
applyGraphicsVars();
}
else
{
mpLowLevelData->getCommandList()->SetGraphicsRootSignature(RootSignature::getEmpty()->getApiHandle());
}
}

#if _ENABLE_NVAPI
Expand All @@ -243,12 +246,31 @@ namespace Falcor
mBindGraphicsRootSig = false;

CommandListHandle pList = mpLowLevelData->getCommandList();
pList->IASetPrimitiveTopology(getD3DPrimitiveTopology(mpGraphicsState->getVao()->getPrimitiveTopology()));
D3D12SetVao(this, pList, mpGraphicsState->getVao().get());
D3D12SetFbo(this, mpGraphicsState->getFbo().get());
D3D12SetViewports(pList, &mpGraphicsState->getViewport(0));
D3D12SetScissors(pList, &mpGraphicsState->getScissors(0));
pList->SetPipelineState(mpGraphicsState->getGSO(mpGraphicsVars.get())->getApiHandle());
if (is_set(StateBindFlags::Topology, mBindFlags))
{
pList->IASetPrimitiveTopology(getD3DPrimitiveTopology(mpGraphicsState->getVao()->getPrimitiveTopology()));
}
if (is_set(StateBindFlags::Vao, mBindFlags))
{
D3D12SetVao(this, pList, mpGraphicsState->getVao().get());
}
if (is_set(StateBindFlags::Fbo, mBindFlags))
{
D3D12SetFbo(this, mpGraphicsState->getFbo().get());
}
if (is_set(StateBindFlags::Viewports, mBindFlags))
{
D3D12SetViewports(pList, &mpGraphicsState->getViewport(0));
}
if (is_set(StateBindFlags::Scissors, mBindFlags))
{
D3D12SetScissors(pList, &mpGraphicsState->getScissors(0));
}
if (is_set(StateBindFlags::PipelineState, mBindFlags))
{
pList->SetPipelineState(mpGraphicsState->getGSO(mpGraphicsVars.get())->getApiHandle());
}

BlendState::SharedPtr blendState = mpGraphicsState->getBlendState();
if (blendState != nullptr)
{
Expand Down
141 changes: 141 additions & 0 deletions Framework/Source/API/D3D12/D3D12State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,145 @@ namespace Falcor
const glm::vec4& borderColor = pSampler->getBorderColor();
memcpy(desc.BorderColor, glm::value_ptr(borderColor), sizeof(borderColor));
}

D3D12_SHADER_VISIBILITY getShaderVisibility(ShaderVisibility visibility)
{
// D3D12 doesn't support a combination of flags, it's either ALL or a single stage
if (isPowerOf2(visibility) == false)
{
return D3D12_SHADER_VISIBILITY_ALL;
}
else if ((visibility & ShaderVisibility::Vertex) != ShaderVisibility::None)
{
return D3D12_SHADER_VISIBILITY_VERTEX;
}
else if ((visibility & ShaderVisibility::Pixel) != ShaderVisibility::None)
{
return D3D12_SHADER_VISIBILITY_PIXEL;
}
else if ((visibility & ShaderVisibility::Geometry) != ShaderVisibility::None)
{
return D3D12_SHADER_VISIBILITY_GEOMETRY;
}
else if ((visibility & ShaderVisibility::Domain) != ShaderVisibility::None)
{
return D3D12_SHADER_VISIBILITY_DOMAIN;
}
else if ((visibility & ShaderVisibility::Hull) != ShaderVisibility::None)
{
return D3D12_SHADER_VISIBILITY_HULL;
}
// If it was compute, it can't be anything else and so the first `if` would have handled it
should_not_get_here();
return (D3D12_SHADER_VISIBILITY)-1;
}

D3D12_DESCRIPTOR_RANGE_TYPE getRootDescRangeType(RootSignature::DescType type)
{
switch (type)
{
case RootSignature::DescType::TextureSrv:
case RootSignature::DescType::TypedBufferSrv:
case RootSignature::DescType::StructuredBufferSrv:
return D3D12_DESCRIPTOR_RANGE_TYPE_SRV;
case RootSignature::DescType::TextureUav:
case RootSignature::DescType::TypedBufferUav:
case RootSignature::DescType::StructuredBufferUav:
return D3D12_DESCRIPTOR_RANGE_TYPE_UAV;
case RootSignature::DescType::Cbv:
return D3D12_DESCRIPTOR_RANGE_TYPE_CBV;
case RootSignature::DescType::Sampler:
return D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER;
default:
should_not_get_here();
return (D3D12_DESCRIPTOR_RANGE_TYPE)-1;
}
}

void convertRootCbvSet(const RootSignature::DescriptorSetLayout& set, D3D12_ROOT_PARAMETER& desc)
{
assert(set.getRangeCount() == 1);
const auto& range = set.getRange(0);
assert(range.type == RootSignature::DescType::Cbv && range.descCount == 1);

desc.ParameterType = D3D12_ROOT_PARAMETER_TYPE_CBV;
desc.Descriptor.RegisterSpace = range.regSpace;
desc.Descriptor.ShaderRegister = range.baseRegIndex;
desc.ShaderVisibility = getShaderVisibility(set.getVisibility());
}

void convertRootDescTable(const RootSignature::DescriptorSetLayout& falcorSet, D3D12_ROOT_PARAMETER& desc, std::vector<D3D12_DESCRIPTOR_RANGE>& d3dRange)
{
desc.ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
desc.ShaderVisibility = getShaderVisibility(falcorSet.getVisibility());
d3dRange.resize(falcorSet.getRangeCount());
desc.DescriptorTable.NumDescriptorRanges = (uint32_t)falcorSet.getRangeCount();
desc.DescriptorTable.pDescriptorRanges = d3dRange.data();

for (size_t i = 0; i < falcorSet.getRangeCount(); i++)
{
const auto& falcorRange = falcorSet.getRange(i);
d3dRange[i].BaseShaderRegister = falcorRange.baseRegIndex;
d3dRange[i].NumDescriptors = falcorRange.descCount;
d3dRange[i].OffsetInDescriptorsFromTableStart = D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND;
d3dRange[i].RangeType = getRootDescRangeType(falcorRange.type);
d3dRange[i].RegisterSpace = falcorRange.regSpace;
}
}

void initD3D12RootParams(const RootSignature::Desc& desc, RootSignatureParams& params)
{
params.signatureSizeInBytes = 0;
params.d3dRanges.resize(desc.getSetsCount());
params.rootParams.resize(desc.getSetsCount());
params.elementByteOffset.resize(desc.getSetsCount());
for (size_t i = 0; i < desc.getSetsCount(); i++)
{
const auto& set = desc.getSet(i);
convertRootDescTable(set, params.rootParams[i], params.d3dRanges[i]);
params.elementByteOffset[i] = params.signatureSizeInBytes;
params.signatureSizeInBytes += 8;
}
}

void initD3D12GraphicsStateDesc(const GraphicsStateObject::Desc& gsoDesc, D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc, InputLayoutDesc& layoutDesc)
{
desc = {};
assert(gsoDesc.getProgramVersion());
#define get_shader_handle(_type) gsoDesc.getProgramVersion()->getShader(_type) ? gsoDesc.getProgramVersion()->getShader(_type)->getApiHandle() : D3D12_SHADER_BYTECODE{}
desc.VS = get_shader_handle(ShaderType::Vertex);
desc.PS = get_shader_handle(ShaderType::Pixel);
desc.GS = get_shader_handle(ShaderType::Geometry);
desc.HS = get_shader_handle(ShaderType::Hull);
desc.DS = get_shader_handle(ShaderType::Domain);
#undef get_shader_handle

initD3D12BlendDesc(gsoDesc.getBlendState().get(), desc.BlendState);
initD3D12RasterizerDesc(gsoDesc.getRasterizerState().get(), desc.RasterizerState);
initD3DDepthStencilDesc(gsoDesc.getDepthStencilState().get(), desc.DepthStencilState);

if (gsoDesc.getVertexLayout())
{
initD3D12VertexLayout(gsoDesc.getVertexLayout().get(), layoutDesc);
desc.InputLayout.NumElements = (uint32_t)layoutDesc.elements.size();
desc.InputLayout.pInputElementDescs = layoutDesc.elements.data();
}
desc.SampleMask = gsoDesc.getSampleMask();
desc.pRootSignature = gsoDesc.getRootSignature() ? gsoDesc.getRootSignature()->getApiHandle() : nullptr;

uint32_t numRtvs = 0;
for (uint32_t rt = 0; rt < Fbo::getMaxColorTargetCount(); rt++)
{
desc.RTVFormats[rt] = getDxgiFormat(gsoDesc.getFboDesc().getColorTargetFormat(rt));
if (desc.RTVFormats[rt] != DXGI_FORMAT_UNKNOWN)
{
numRtvs = rt + 1;
}
}
desc.NumRenderTargets = numRtvs;
desc.DSVFormat = getDxgiFormat(gsoDesc.getFboDesc().getDepthStencilFormat());
desc.SampleDesc.Count = gsoDesc.getFboDesc().getSampleCount();

desc.PrimitiveTopologyType = getD3DPrimitiveType(gsoDesc.getPrimitiveType());
}
}
14 changes: 14 additions & 0 deletions Framework/Source/API/D3D12/D3D12State.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***************************************************************************/
#pragma once

#include <vector>
#include "API/RenderContext.h"
#include "API/GraphicsStateObject.h"
Expand All @@ -49,6 +51,18 @@ namespace Falcor
void initD3DDepthStencilDesc(const DepthStencilState* pState, D3D12_DEPTH_STENCIL_DESC& desc);
void initD3D12VertexLayout(const VertexLayout* pLayout, InputLayoutDesc& inputDesc);
void initD3D12SamplerDesc(const Sampler* pSampler, D3D12_SAMPLER_DESC& desc);
void initD3D12GraphicsStateDesc(const GraphicsStateObject::Desc& gsoDesc, D3D12_GRAPHICS_PIPELINE_STATE_DESC& desc, InputLayoutDesc& layoutDesc);

struct RootSignatureParams
{
using RootParameterVec = std::vector<D3D12_ROOT_PARAMETER>;
RootParameterVec rootParams;
std::vector<std::vector<D3D12_DESCRIPTOR_RANGE>> d3dRanges;
uint32_t signatureSizeInBytes;
std::vector<uint32_t> elementByteOffset;
};

void initD3D12RootParams(const RootSignature::Desc& desc, RootSignatureParams& params);

inline D3D_PRIMITIVE_TOPOLOGY getD3DPrimitiveTopology(Vao::Topology topology)
{
Expand Down
Loading

0 comments on commit 237847c

Please sign in to comment.