Skip to content

Commit

Permalink
Fix validation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
godlikepanos committed Jun 9, 2024
1 parent 2f1a26a commit d8df01f
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 79 deletions.
2 changes: 2 additions & 0 deletions AnKi/Gr/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ enum class TextureUsageBit : U32
| kTransferDestination | kGenerateMipmaps,
kAll = kAllRead | kAllWrite,
kAllShaderResource = kAllSampled | kAllStorage,
kAllSrv = (kAllSampled | kAllStorage) & kAllRead,
kAllUav = kAllStorage & kAllWrite,
};
ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(TextureUsageBit)

Expand Down
64 changes: 47 additions & 17 deletions AnKi/Gr/D3D/D3DGrManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// Use the Agility SDK
extern "C" {
__declspec(dllexport) extern const UINT D3D12SDKVersion = 613; // Number taken from the download page
__declspec(dllexport) extern const UINT D3D12SDKVersion = 614; // Number taken from the download page
__declspec(dllexport) extern const char* D3D12SDKPath = ".\\"; // The D3D12Core.dll should be in the same dir as the .exe
}

Expand All @@ -41,6 +41,7 @@ BoolCVar g_vsyncCVar(CVarSubsystem::kGr, "Vsync", false, "Enable or not vsync");
BoolCVar g_debugMarkersCVar(CVarSubsystem::kGr, "DebugMarkers", false, "Enable or not debug markers");
BoolCVar g_meshShadersCVar(CVarSubsystem::kGr, "MeshShaders", false, "Enable or not mesh shaders");
static NumericCVar<U8> g_deviceCVar(CVarSubsystem::kGr, "Device", 0, 0, 16, "Choose an available device. Devices are sorted by performance");
static BoolCVar g_rayTracingCVar(CVarSubsystem::kGr, "RayTracing", false, "Try enabling ray tracing");

static LONG NTAPI vexHandler(PEXCEPTION_POINTERS exceptionInfo)
{
Expand Down Expand Up @@ -407,7 +408,7 @@ Error GrManagerImpl::initInternal(const GrManagerInitInfo& init)

// Create device
ComPtr<ID3D12Device> dev;
ANKI_D3D_CHECK(D3D12CreateDevice(adapters[chosenPhysDevIdx].m_adapter.Get(), D3D_FEATURE_LEVEL_12_1, IID_PPV_ARGS(&dev)));
ANKI_D3D_CHECK(D3D12CreateDevice(adapters[chosenPhysDevIdx].m_adapter.Get(), D3D_FEATURE_LEVEL_12_2, IID_PPV_ARGS(&dev)));
ANKI_D3D_CHECK(dev->QueryInterface(IID_PPV_ARGS(&m_device)));

if(g_validationCVar.get())
Expand All @@ -426,17 +427,6 @@ Error GrManagerImpl::initInternal(const GrManagerInitInfo& init)
}
}

// Capabilities
{
D3D12_FEATURE_DATA_D3D12_OPTIONS16 options16;
ANKI_D3D_CHECK(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &options16, sizeof(options16)));
m_d3dCapabilities.m_rebar = options16.GPUUploadHeapSupported;
if(!m_d3dCapabilities.m_rebar)
{
ANKI_D3D_LOGW("ReBAR not supported");
}
}

// Create queues
{
D3D12_COMMAND_QUEUE_DESC queueDesc = {};
Expand All @@ -449,6 +439,43 @@ Error GrManagerImpl::initInternal(const GrManagerInitInfo& init)
ANKI_D3D_CHECK(m_queues[GpuQueueType::kGeneral]->GetTimestampFrequency(&m_timestampFrequency));
}

// Set device capabilities (taken from mesa's dozen driver)
{
D3D12_FEATURE_DATA_D3D12_OPTIONS16 options16;
ANKI_D3D_CHECK(m_device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &options16, sizeof(options16)));
D3D12_FEATURE_DATA_ARCHITECTURE architecture = {.NodeIndex = 0};
ANKI_D3D_CHECK(m_device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &architecture, sizeof(architecture)));

m_d3dCapabilities.m_rebar = options16.GPUUploadHeapSupported;
if(!m_d3dCapabilities.m_rebar)
{
ANKI_D3D_LOGW("ReBAR not supported");
}

m_capabilities.m_uniformBufferBindOffsetAlignment = D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT;
m_capabilities.m_uniformBufferMaxRange = D3D12_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * D3D12_STANDARD_VECTOR_SIZE * sizeof(F32);
m_capabilities.m_storageBufferBindOffsetAlignment = D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT;
m_capabilities.m_storageBufferMaxRange = 1 << D3D12_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP;
m_capabilities.m_texelBufferBindOffsetAlignment = 32;
m_capabilities.m_textureBufferMaxRange = kMaxU32; // ?
m_capabilities.m_pushConstantsSize = kMaxPushConstantSize;
m_capabilities.m_computeSharedMemorySize = D3D12_CS_TGSM_REGISTER_COUNT * sizeof(F32);
m_capabilities.m_accelerationStructureBuildScratchOffsetAlignment = 32; // ?
m_capabilities.m_sbtRecordAlignment = 32; // ?
m_capabilities.m_maxDrawIndirectCount = kMaxU32;
m_capabilities.m_discreteGpu = !architecture.UMA;
m_capabilities.m_majorApiVersion = 12;
m_capabilities.m_rayTracingEnabled = g_rayTracingCVar.get();
m_capabilities.m_64bitAtomics = true;
m_capabilities.m_vrs = true;
m_capabilities.m_samplingFilterMinMax = true;
m_capabilities.m_unalignedBbpTextureFormats = false;
m_capabilities.m_dlss = false;
m_capabilities.m_meshShaders = true;
m_capabilities.m_pipelineQuery = true;
m_capabilities.m_barycentrics = true;
}

// Other systems
DescriptorFactory::allocateSingleton();
ANKI_CHECK(DescriptorFactory::getSingleton().init());
Expand Down Expand Up @@ -504,11 +531,14 @@ void GrManagerImpl::destroy()

void GrManagerImpl::waitAllQueues()
{
for(GpuQueueType queueType : EnumIterable<GpuQueueType>())
if(FenceFactory::isAllocated())
{
MicroFencePtr fence = FenceFactory::getSingleton().newInstance();
fence->gpuSignal(queueType);
fence->clientWait(kMaxSecond);
for(GpuQueueType queueType : EnumIterable<GpuQueueType>())
{
MicroFencePtr fence = FenceFactory::getSingleton().newInstance();
fence->gpuSignal(queueType);
fence->clientWait(kMaxSecond);
}
}
}

Expand Down
83 changes: 71 additions & 12 deletions AnKi/Gr/D3D/D3DTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Error TextureImpl::initInternal(ID3D12Resource* external, const TextureInitInfo&
desc.SampleDesc.Count = 1;
desc.SampleDesc.Quality = 0;
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS;
desc.Flags = {};

if(!!(m_usage & TextureUsageBit::kAllFramebuffer) && m_aspect == DepthStencilAspectBit::kNone)
{
Expand Down Expand Up @@ -257,9 +257,49 @@ void TextureImpl::initView(const TextureSubresourceDescriptor& subresource, Text
{
const TextureView tview(this, subresource);

ANKI_ASSERT(tview.getSubresource().m_depthStencilAspect != DepthStencilAspectBit::kDepthStencil && "Can only create a single plane SRV");

D3D12_SHADER_RESOURCE_VIEW_DESC desc = {};

desc.Format = DXGI_FORMAT(m_format);
if(!m_aspect)
{
desc.Format = DXGI_FORMAT(m_format);
}
else
{
// D3D doesn't like depth formats as SRVs
switch(m_format)
{
case Format::kD16_Unorm:
desc.Format = DXGI_FORMAT(Format::kR16_Unorm);
break;
case Format::kD32_Sfloat:
desc.Format = DXGI_FORMAT(Format::kR32_Sfloat);
break;
case Format::kD24_Unorm_S8_Uint:
if(tview.getSubresource().m_depthStencilAspect == DepthStencilAspectBit::kDepth)
{
desc.Format = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;
}
else
{
desc.Format = DXGI_FORMAT_X24_TYPELESS_G8_UINT;
}
break;
case Format::kD32_Sfloat_S8_Uint:
if(tview.getSubresource().m_depthStencilAspect == DepthStencilAspectBit::kDepth)
{
desc.Format = DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS;
}
else
{
desc.Format = DXGI_FORMAT_R32G8X24_TYPELESS;
}
break;
default:
ANKI_ASSERT(0);
}
}

const U32 faceCount = textureTypeIsCube(m_texType) ? 6 : 1;
const U32 surfaceCount = faceCount * m_layerCount;
Expand Down Expand Up @@ -501,7 +541,16 @@ D3D12_TEXTURE_BARRIER TextureImpl::computeBarrierInfo(TextureUsageBit before, Te
barrier.Subresources.NumMipLevels = 1;
barrier.Subresources.FirstArraySlice = subresource.m_layer * faceCount + subresource.m_face;
barrier.Subresources.NumArraySlices = 1;
barrier.Subresources.FirstPlane = !!(subresource.m_depthStencilAspect & DepthStencilAspectBit::kDepth) ? 0 : 1;

if(!!(subresource.m_depthStencilAspect & DepthStencilAspectBit::kDepth) || subresource.m_depthStencilAspect == DepthStencilAspectBit::kNone)
{
barrier.Subresources.FirstPlane = 0;
}
else
{
barrier.Subresources.FirstPlane = 1;
}

barrier.Subresources.NumPlanes = (subresource.m_depthStencilAspect == DepthStencilAspectBit::kDepthStencil) ? 2 : 1;
}

Expand Down Expand Up @@ -638,36 +687,46 @@ D3D12_BARRIER_LAYOUT TextureImpl::computeLayout(TextureUsageBit usage) const
}
else if(depthStencil)
{
if(!(usage & ~(TextureUsageBit::kAllSampled | TextureUsageBit::kFramebufferRead)))
if((usage & TextureUsageBit::kAllSampled) == usage)
{
// Only depth tests and sampled
// Only sampled
out = D3D12_BARRIER_LAYOUT_SHADER_RESOURCE;
}
else if((usage & TextureUsageBit::kFramebufferRead) == usage)
{
// Only FB read
out = D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_READ;
}
else if((usage & (TextureUsageBit::kAllSampled | TextureUsageBit::kFramebufferRead)) == usage)
{
// Only depth tests and sampled
out = D3D12_BARRIER_LAYOUT_COMMON;
}
else
{
// Only attachment write, the rest (eg transfer) are not supported for now
ANKI_ASSERT(usage == TextureUsageBit::kFramebufferWrite || usage == TextureUsageBit::kAllFramebuffer);
ANKI_ASSERT(usage == TextureUsageBit::kAllFramebuffer || usage == TextureUsageBit::kFramebufferWrite);
out = D3D12_BARRIER_LAYOUT_DEPTH_STENCIL_WRITE;
}
}
else if(!(usage & ~TextureUsageBit::kAllFramebuffer))
else if((usage & TextureUsageBit::kAllFramebuffer) == usage)
{
// Color attachment
out = D3D12_BARRIER_LAYOUT_RENDER_TARGET;
}
else if(!(usage & ~TextureUsageBit::kFramebufferShadingRate))
else if((usage & TextureUsageBit::kFramebufferShadingRate) == usage)
{
// SRI
out = D3D12_BARRIER_LAYOUT_SHADING_RATE_SOURCE;
}
else if(!(usage & ~TextureUsageBit::kAllStorage))
else if((usage & TextureUsageBit::kAllUav) == usage)
{
// Only image load/store
// UAV
out = D3D12_BARRIER_LAYOUT_UNORDERED_ACCESS;
}
else if(!(usage & ~TextureUsageBit::kAllSampled))
else if((usage & TextureUsageBit::kAllSrv) == usage)
{
// Only sampled
// SRV
out = D3D12_BARRIER_LAYOUT_SHADER_RESOURCE;
}
else if(usage == TextureUsageBit::kGenerateMipmaps)
Expand Down
5 changes: 3 additions & 2 deletions AnKi/Renderer/Tonemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ Error Tonemapping::initInternal()
const TextureInitInfo texinit = getRenderer().create2DRenderTargetInitInfo(1, 1, Format::kR16G16_Sfloat, usage, "ExposureAndAvgLum1x1");
ClearValue clearValue;
clearValue.m_colorf = {0.5f, 0.5f, 0.5f, 0.5f};
m_exposureAndAvgLuminance1x1 = getRenderer().createAndClearRenderTarget(texinit, TextureUsageBit::kAllStorage, clearValue);
m_exposureAndAvgLuminance1x1 = getRenderer().createAndClearRenderTarget(texinit, TextureUsageBit::kStorageComputeRead, clearValue);

return Error::kNone;
}

void Tonemapping::importRenderTargets(RenderingContext& ctx)
{
// Just import it. It will not be used in resource tracking
m_runCtx.m_exposureLuminanceHandle = ctx.m_renderGraphDescr.importRenderTarget(m_exposureAndAvgLuminance1x1.get(), TextureUsageBit::kAllStorage);
m_runCtx.m_exposureLuminanceHandle =
ctx.m_renderGraphDescr.importRenderTarget(m_exposureAndAvgLuminance1x1.get(), TextureUsageBit::kStorageComputeRead);
}

void Tonemapping::populateRenderGraph(RenderingContext& ctx)
Expand Down
36 changes: 2 additions & 34 deletions ThirdParty/AgilitySdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,8 @@ The included licenses apply to the following files:

## Changelog

### Version 1.613.3

- Same as 1.613.2, with minor updates shown at the end of this list:
- Work Graphs
- Generic Programs in State objects
- Shader Model 6.8
- Work Graphs support
- Start Vertex/Instance Location
- Wave Size Range
- Expanded Comparison Sampling
- GPU Upload Heaps (requires preview or future OS)
- Incrementing Constants in ExecuteIndirect
- Minor updates for .3:
- Honor root signature associations added to export in collections when the export is imported into generic program in an executable state object.
- Propagate root signatures to exports that have bindings and no root signatures within the scope of a generic program, like what happens with PSOs
- Other ganeric programs releated bug fixes, additional validation and optimizations
- For state objectgs, minor fixes to subobject association logic in edge cases involving collections to more precisely match spec wording

### Version 1.613.2

- Same as 1.613.1, with minor updates shown at the end of this list:
- Work Graphs
- Generic Programs in State objects
- Shader Model 6.8
- Work Graphs support
- Start Vertex/Instance Location
- Wave Size Range
- Expanded Comparison Sampling
- GPU Upload Heaps (requires preview or future OS)
- Incrementing Constants in ExecuteIndirect
- Minor updates for .2:
- Close validation hole: Prevent use of features in incompatible state object types, such as defining generic program components (like rast state) in a raytracing pipeline.
- Debug layer fixes around lifetime management of program identifiers (e.g. the handles for the new generic programs)
- ExecuteIndirect validation was too strict: buffer size only needs to be big enough for the number of commands * stride, _minus the unused space at end of last command_
### Version 1.614.0
- Enabled R9G9B9E5_SHAREDEXP format for Render Target and Unordered Access Views

### Version 1.613.1

Expand Down
Binary file modified ThirdParty/AgilitySdk/bin/x64/D3D12Core.dll
Binary file not shown.
Binary file modified ThirdParty/AgilitySdk/bin/x64/D3D12Core.pdb
Binary file not shown.
Binary file modified ThirdParty/AgilitySdk/bin/x64/d3d12SDKLayers.dll
Binary file not shown.
Binary file modified ThirdParty/AgilitySdk/bin/x64/d3d12SDKLayers.pdb
Binary file not shown.
Binary file modified ThirdParty/AgilitySdk/bin/x64/d3dconfig.exe
Binary file not shown.
Binary file modified ThirdParty/AgilitySdk/bin/x64/d3dconfig.pdb
Binary file not shown.
4 changes: 2 additions & 2 deletions ThirdParty/AgilitySdk/include/d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ extern "C"{

#define D3D12_PIXEL_ADDRESS_RANGE_BIT_COUNT ( 15 )

#define D3D12_PREVIEW_SDK_VERSION ( 713 )
#define D3D12_PREVIEW_SDK_VERSION ( 714 )

#define D3D12_PRE_SCISSOR_PIXEL_ADDRESS_RANGE_BIT_COUNT ( 16 )

Expand Down Expand Up @@ -1235,7 +1235,7 @@ extern "C"{

#define D3D12_RS_SET_SHADING_RATE_COMBINER_COUNT ( 2 )

#define D3D12_SDK_VERSION ( 613 )
#define D3D12_SDK_VERSION ( 614 )

#define D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES ( 32 )

Expand Down
11 changes: 7 additions & 4 deletions ThirdParty/AgilitySdk/include/d3d12.idl
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ const UINT D3D12_OS_RESERVED_REGISTER_SPACE_VALUES_END = 0xffffffff;
const UINT D3D12_OS_RESERVED_REGISTER_SPACE_VALUES_START = 0xfffffff8;
const UINT D3D12_PACKED_TILE = 0xffffffff;
const UINT D3D12_PIXEL_ADDRESS_RANGE_BIT_COUNT = 15;
const UINT D3D12_PREVIEW_SDK_VERSION = 713;
const UINT D3D12_PREVIEW_SDK_VERSION = 714;
const UINT D3D12_PRE_SCISSOR_PIXEL_ADDRESS_RANGE_BIT_COUNT = 16;
const UINT D3D12_PS_CS_UAV_REGISTER_COMPONENTS = 1;
const UINT D3D12_PS_CS_UAV_REGISTER_COUNT = 8;
Expand Down Expand Up @@ -361,7 +361,7 @@ const UINT D3D12_REQ_TEXTURECUBE_DIMENSION = 16384;
const UINT D3D12_RESINFO_INSTRUCTION_MISSING_COMPONENT_RETVAL = 0;
const UINT D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES = 0xffffffff;
const UINT D3D12_RS_SET_SHADING_RATE_COMBINER_COUNT = 2;
const UINT D3D12_SDK_VERSION = 613;
const UINT D3D12_SDK_VERSION = 614;
const UINT D3D12_SHADER_IDENTIFIER_SIZE_IN_BYTES = 32;
const UINT D3D12_SHADER_MAJOR_VERSION = 5;
const UINT D3D12_SHADER_MAX_INSTANCES = 65535;
Expand Down Expand Up @@ -1030,7 +1030,7 @@ typedef enum D3D12_FEATURE
D3D12_FEATURE_PREDICATION = 50,
D3D12_FEATURE_PLACED_RESOURCE_SUPPORT_INFO = 51,
D3D12_FEATURE_HARDWARE_COPY = 52,
D3D12_FEATURE_D3D12_OPTIONS21 = 53
D3D12_FEATURE_D3D12_OPTIONS21 = 53,
} D3D12_FEATURE;

typedef enum D3D12_SHADER_MIN_PRECISION_SUPPORT
Expand Down Expand Up @@ -1621,6 +1621,7 @@ typedef struct D3D12_FEATURE_DATA_HARDWARE_COPY
[annotation("_Out_")] BOOL Supported;
} D3D12_FEATURE_DATA_HARDWARE_COPY;


typedef struct D3D12_RESOURCE_ALLOCATION_INFO
{
UINT64 SizeInBytes;
Expand Down Expand Up @@ -1779,6 +1780,7 @@ typedef struct D3D12_RESOURCE_DESC1
} D3D12_RESOURCE_DESC1;



typedef struct D3D12_DEPTH_STENCIL_VALUE
{
FLOAT Depth;
Expand Down Expand Up @@ -5430,6 +5432,7 @@ interface ID3D12Resource2
}



[uuid(572F7389-2168-49E3-9693-D6DF5871BF6D), object, local, pointer_default(unique)]
interface ID3D12Heap1
: ID3D12Heap
Expand Down Expand Up @@ -6063,6 +6066,7 @@ interface ID3D12Device14 : ID3D12Device13
[out, iid_is(riid), annotation("_COM_Outptr_")] void** ppvRootSignature);
};


[uuid(bc66d368-7373-4943-8757-fc87dc79e476), object, local, pointer_default(unique)]
interface ID3D12VirtualizationGuestDevice
: IUnknown
Expand All @@ -6089,7 +6093,6 @@ interface ID3D12Tools
}



typedef struct D3D12_SUBRESOURCE_DATA
{
const void* pData;
Expand Down
Loading

0 comments on commit d8df01f

Please sign in to comment.