diff options
| author | Yong He <yonghe@outlook.com> | 2021-03-04 16:25:58 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-04 16:25:58 -0800 |
| commit | a5ac4999b4dea546a7ef824669ab1809224b6448 (patch) | |
| tree | 15bb22eb98a94f7f81489deef55396461501d3dc /tools/gfx/d3d | |
| parent | 13ff0bd345990c0fdfb7b52ebd5339cddb04889e (diff) | |
Refactor `gfx` to surface `CommandBuffer` interface. (#1735)
* Refactor `gfx` to surface `CommandBuffer` interface.
* Fixes.
* Fix code review issues, and make vulkan runnable on devices without VK_EXT_extended_dynamic_states.
* Update solution files
* Move out-of-date examples to examples/experimental
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tools/gfx/d3d')
| -rw-r--r-- | tools/gfx/d3d/d3d-util.cpp | 114 | ||||
| -rw-r--r-- | tools/gfx/d3d/d3d-util.h | 9 |
2 files changed, 122 insertions, 1 deletions
diff --git a/tools/gfx/d3d/d3d-util.cpp b/tools/gfx/d3d/d3d-util.cpp index cb96c6211..a9686ab7d 100644 --- a/tools/gfx/d3d/d3d-util.cpp +++ b/tools/gfx/d3d/d3d-util.cpp @@ -1,8 +1,8 @@ // d3d-util.cpp #include "d3d-util.h" +#include <d3d12.h> #include <d3dcompiler.h> - #include <dxgi1_4.h> // We will use the C standard library just for printing error messages. @@ -26,6 +26,84 @@ using namespace Slang; return D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED; } +D3D12_PRIMITIVE_TOPOLOGY_TYPE D3DUtil::getPrimitiveType(PrimitiveType type) +{ + switch (type) + { + case PrimitiveType::Point: + return D3D12_PRIMITIVE_TOPOLOGY_TYPE_POINT; + case PrimitiveType::Line: + return D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE; + case PrimitiveType::Triangle: + return D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; + case PrimitiveType::Patch: + return D3D12_PRIMITIVE_TOPOLOGY_TYPE_PATCH; + default: + break; + } + return D3D12_PRIMITIVE_TOPOLOGY_TYPE_UNDEFINED; +} + +D3D12_COMPARISON_FUNC D3DUtil::getComparisonFunc(ComparisonFunc func) +{ + switch (func) + { + case gfx::ComparisonFunc::Never: + return D3D12_COMPARISON_FUNC_NEVER; + case gfx::ComparisonFunc::Less: + return D3D12_COMPARISON_FUNC_LESS; + case gfx::ComparisonFunc::Equal: + return D3D12_COMPARISON_FUNC_EQUAL; + case gfx::ComparisonFunc::LessEqual: + return D3D12_COMPARISON_FUNC_LESS_EQUAL; + case gfx::ComparisonFunc::Greater: + return D3D12_COMPARISON_FUNC_GREATER; + case gfx::ComparisonFunc::NotEqual: + return D3D12_COMPARISON_FUNC_NOT_EQUAL; + case gfx::ComparisonFunc::GreaterEqual: + return D3D12_COMPARISON_FUNC_GREATER_EQUAL; + case gfx::ComparisonFunc::Always: + return D3D12_COMPARISON_FUNC_ALWAYS; + default: + return D3D12_COMPARISON_FUNC_NEVER; + } +} + +static D3D12_STENCIL_OP translateStencilOp(StencilOp op) +{ + switch (op) + { + case gfx::StencilOp::Keep: + return D3D12_STENCIL_OP_KEEP; + case gfx::StencilOp::Zero: + return D3D12_STENCIL_OP_ZERO; + case gfx::StencilOp::Replace: + return D3D12_STENCIL_OP_REPLACE; + case gfx::StencilOp::IncrementSaturate: + return D3D12_STENCIL_OP_INCR_SAT; + case gfx::StencilOp::DecrementSaturate: + return D3D12_STENCIL_OP_DECR_SAT; + case gfx::StencilOp::Invert: + return D3D12_STENCIL_OP_INVERT; + case gfx::StencilOp::IncrementWrap: + return D3D12_STENCIL_OP_INCR; + case gfx::StencilOp::DecrementWrap: + return D3D12_STENCIL_OP_DECR; + default: + return D3D12_STENCIL_OP_KEEP; + } +} + +D3D12_DEPTH_STENCILOP_DESC D3DUtil::translateStencilOpDesc(DepthStencilOpDesc desc) +{ + D3D12_DEPTH_STENCILOP_DESC rs; + rs.StencilDepthFailOp = translateStencilOp(desc.stencilDepthFailOp); + rs.StencilFailOp = translateStencilOp(desc.stencilFailOp); + rs.StencilFunc = getComparisonFunc(desc.stencilFunc); + rs.StencilPassOp = translateStencilOp(desc.stencilPassOp); + return rs; +} + /* static */DXGI_FORMAT D3DUtil::getMapFormat(Format format) { switch (format) @@ -47,6 +125,40 @@ using namespace Slang; } } +D3D12_RESOURCE_STATES D3DUtil::translateResourceState(ResourceState state) +{ + switch (state) + { + case gfx::ResourceState::Undefined: + return D3D12_RESOURCE_STATE_COMMON; + case gfx::ResourceState::ShaderResource: + return D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | + D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; + case gfx::ResourceState::UnorderedAccess: + return D3D12_RESOURCE_STATE_UNORDERED_ACCESS | D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE | + D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE; + case gfx::ResourceState::RenderTarget: + return D3D12_RESOURCE_STATE_RENDER_TARGET; + case gfx::ResourceState::DepthRead: + return D3D12_RESOURCE_STATE_DEPTH_READ; + case gfx::ResourceState::DepthWrite: + return D3D12_RESOURCE_STATE_DEPTH_WRITE; + case gfx::ResourceState::Present: + return D3D12_RESOURCE_STATE_PRESENT; + case gfx::ResourceState::CopySource: + return D3D12_RESOURCE_STATE_COPY_SOURCE; + case gfx::ResourceState::CopyDestination: + return D3D12_RESOURCE_STATE_COPY_DEST; + case gfx::ResourceState::ResolveSource: + return D3D12_RESOURCE_STATE_RESOLVE_SOURCE; + case gfx::ResourceState::ResolveDestination: + return D3D12_RESOURCE_STATE_RESOLVE_DEST; + default: + return D3D12_RESOURCE_STATE_COMMON; + } +} + + /* static */DXGI_FORMAT D3DUtil::calcResourceFormat(UsageType usage, Int usageFlags, DXGI_FORMAT format) { SLANG_UNUSED(usage); diff --git a/tools/gfx/d3d/d3d-util.h b/tools/gfx/d3d/d3d-util.h index 63a897206..4cbdcb61b 100644 --- a/tools/gfx/d3d/d3d-util.h +++ b/tools/gfx/d3d/d3d-util.h @@ -15,6 +15,7 @@ #include <D3Dcommon.h> #include <DXGIFormat.h> #include <dxgi.h> +#include <d3d12.h> namespace gfx { @@ -38,6 +39,12 @@ class D3DUtil /// Get primitive topology as D3D primitive topology static D3D_PRIMITIVE_TOPOLOGY getPrimitiveTopology(PrimitiveTopology prim); + static D3D12_PRIMITIVE_TOPOLOGY_TYPE getPrimitiveType(PrimitiveType type); + + static D3D12_COMPARISON_FUNC getComparisonFunc(ComparisonFunc func); + + static D3D12_DEPTH_STENCILOP_DESC translateStencilOpDesc(DepthStencilOpDesc desc); + /// Calculate size taking into account alignment. Alignment must be a power of 2 static UInt calcAligned(UInt size, UInt alignment) { return (size + alignment - 1) & ~(alignment - 1); } @@ -47,6 +54,8 @@ class D3DUtil /// Given a slang pixel format returns the equivalent DXGI_ pixel format. If the format is not known, will return DXGI_FORMAT_UNKNOWN static DXGI_FORMAT getMapFormat(Format format); + static D3D12_RESOURCE_STATES translateResourceState(ResourceState state); + /// Given the usage, flags, and format will return the most suitable format. Will return DXGI_UNKNOWN if combination is not possible static DXGI_FORMAT calcFormat(UsageType usage, DXGI_FORMAT format); /// Calculate appropriate format for creating a buffer for usage and flags |
