Skip to content

Commit

Permalink
Improvements:
Browse files Browse the repository at this point in the history
- NRI: exposed "isEnchancedBarrierSupported" in "DeviceDesc" (if "false", "Layout" is unsupported and not needed)
- D3D11: "byte address buffer" support (?)
- added clarifications
  • Loading branch information
dzhdanNV committed May 27, 2024
1 parent 5123bb7 commit c614b02
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions Include/Extensions/NRIDeviceCreation.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ NRI_STRUCT(CallbackInterface)
void* userArg;
};

// Use largest offset for the resource type planned to be used as unbounded array
NRI_STRUCT(SPIRVBindingOffsets)
{
uint32_t samplerOffset;
Expand Down
3 changes: 2 additions & 1 deletion Include/NRIDescs.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ NRI_STRUCT(TextureDesc)
NRI_STRUCT(BufferDesc)
{
uint64_t size;
uint32_t structureStride;
uint32_t structureStride; // use 4 to allow "byte address" (raw) views
NRI_NAME(BufferUsageBits) usageMask;
};

Expand Down Expand Up @@ -1566,6 +1566,7 @@ NRI_STRUCT(DeviceDesc)
uint32_t isDispatchRaysIndirectSupported : 1;
uint32_t isDrawMeshTasksIndirectSupported : 1;
uint32_t isMeshShaderPipelineStatsSupported : 1;
uint32_t isEnchancedBarrierSupported : 1; // aka - can "Layout" be ignored?

// Shader features
uint32_t isShaderNativeI16Supported : 1;
Expand Down
6 changes: 6 additions & 0 deletions Source/D3D11/BufferD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Result BufferD3D11::Create(const MemoryD3D11& memory) {
if (m_Desc.structureStride)
desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;

// D3D11/D3D12 backends do not use FLAG_RAW for descriptors. It seems to be unnecessary because VK doesn't have
// RAW functionality, but "byte adress buffers" in HLSL do work in VK if the underlying buffer is a structured
// buffer with stride = 4. Since "ALLOW_RAW_VIEWS" is needed only for D3D11, add it here.
if (m_Desc.structureStride == 4)
desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;

if (m_Desc.usageMask & BufferUsageBits::ARGUMENT_BUFFER)
desc.MiscFlags |= D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;

Expand Down
2 changes: 1 addition & 1 deletion Source/D3D12/CommandBufferD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ inline void CommandBufferD3D12::DispatchIndirect(const Buffer& buffer, uint64_t

inline void CommandBufferD3D12::Barrier(const BarrierGroupDesc& barrierGroupDesc) {
#ifdef NRI_USE_AGILITY_SDK
if (m_Device.AreEnhancedBarriersSupported()) { // Enhanced barriers
if (m_Device.GetDesc().isEnchancedBarrierSupported) { // Enhanced barriers
// Count
uint32_t barrierNum = barrierGroupDesc.globalNum + barrierGroupDesc.bufferNum + barrierGroupDesc.textureNum;
if (!barrierNum)
Expand Down
24 changes: 10 additions & 14 deletions Source/D3D12/DeviceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,21 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12Retu
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options12, sizeof(options12));
if (FAILED(hr))
REPORT_WARNING(this, "ID3D12Device::CheckFeatureSupport(options12) failed, result = 0x%08X!", hr);
m_AreEnhancedBarriersSupported = options12.EnhancedBarriersSupported;
m_Desc.isEnchancedBarrierSupported = options12.EnhancedBarriersSupported;

D3D12_FEATURE_DATA_D3D12_OPTIONS13 options13 = {};
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS13, &options13, sizeof(options13));
if (FAILED(hr))
REPORT_WARNING(this, "ID3D12Device::CheckFeatureSupport(options13) failed, result = 0x%08X!", hr);
m_Desc.uploadBufferTextureRowAlignment = options13.UnrestrictedBufferTextureCopyPitchSupported ? 1 : D3D12_TEXTURE_DATA_PITCH_ALIGNMENT;
m_Desc.uploadBufferTextureSliceAlignment = options13.UnrestrictedBufferTextureCopyPitchSupported ? 1 : D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;

// Minimum supported client: Agility SDK
D3D12_FEATURE_DATA_D3D12_OPTIONS14 options14 = {};
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS14, &options14, sizeof(options14));
if (FAILED(hr))
REPORT_WARNING(this, "ID3D12Device::CheckFeatureSupport(options14) failed, result = 0x%08X!", hr);
m_Desc.isIndependentFrontAndBackStencilReferenceAndMasksSupported = options14.IndependentFrontAndBackStencilRefMaskSupported ? true : false;

D3D12_FEATURE_DATA_D3D12_OPTIONS15 options15 = {};
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS15, &options15, sizeof(options15));
Expand All @@ -369,6 +372,7 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12Retu
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS16, &options16, sizeof(options16));
if (FAILED(hr))
REPORT_WARNING(this, "ID3D12Device::CheckFeatureSupport(options16) failed, result = 0x%08X!", hr);
m_Desc.deviceUploadHeapSize = options16.GPUUploadHeapSupported ? m_Desc.adapterDesc.videoMemorySize : 0;

D3D12_FEATURE_DATA_D3D12_OPTIONS17 options17 = {};
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS17, &options17, sizeof(options17));
Expand All @@ -394,6 +398,9 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12Retu
hr = m_Device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS21, &options21, sizeof(options21));
if (FAILED(hr))
REPORT_WARNING(this, "ID3D12Device::CheckFeatureSupport(options21) failed, result = 0x%08X!", hr);
#else
m_Desc.uploadBufferTextureRowAlignment = D3D12_TEXTURE_DATA_PITCH_ALIGNMENT;
m_Desc.uploadBufferTextureSliceAlignment = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
#endif

const std::array<D3D_FEATURE_LEVEL, 5> levelsList = {
Expand Down Expand Up @@ -446,15 +453,6 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12Retu
m_Desc.textureArrayMaxDim = D3D12_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION;
m_Desc.texelBufferMaxDim = (1 << D3D12_REQ_BUFFER_RESOURCE_TEXEL_COUNT_2_TO_EXP) - 1;

#ifdef NRI_USE_AGILITY_SDK
m_Desc.deviceUploadHeapSize = options16.GPUUploadHeapSupported ? m_Desc.adapterDesc.videoMemorySize : 0;
m_Desc.uploadBufferTextureRowAlignment = options13.UnrestrictedBufferTextureCopyPitchSupported ? 1 : D3D12_TEXTURE_DATA_PITCH_ALIGNMENT;
m_Desc.uploadBufferTextureSliceAlignment = options13.UnrestrictedBufferTextureCopyPitchSupported ? 1 : D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
#else
m_Desc.uploadBufferTextureRowAlignment = D3D12_TEXTURE_DATA_PITCH_ALIGNMENT;
m_Desc.uploadBufferTextureSliceAlignment = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
#endif

m_Desc.memoryAllocationMaxNum = 0xFFFFFFFF;
m_Desc.samplerAllocationMaxNum = D3D12_REQ_SAMPLER_OBJECT_COUNT_PER_DEVICE;
m_Desc.typedBufferOffsetAlignment = D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT;
Expand Down Expand Up @@ -560,11 +558,7 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12Retu
m_Desc.isComputeQueueSupported = true;
m_Desc.isCopyQueueSupported = true;
m_Desc.isDrawIndirectCountSupported = true;
#ifdef NRI_USE_AGILITY_SDK
m_Desc.isIndependentFrontAndBackStencilReferenceAndMasksSupported = options14.IndependentFrontAndBackStencilRefMaskSupported ? true : false;
#endif
m_Desc.isLineSmoothingSupported = true;
m_Desc.isDrawParametersEmulationEnabled = enableDrawParametersEmulation && shaderModel.HighestShaderModel <= D3D_SHADER_MODEL_6_7;

m_Desc.isShaderNativeI16Supported = options4.Native16BitShaderOpsSupported;
m_Desc.isShaderNativeF16Supported = options4.Native16BitShaderOpsSupported;
Expand Down Expand Up @@ -592,6 +586,8 @@ void DeviceD3D12::FillDesc(bool enableDrawParametersEmulation, const AGSDX12Retu
m_Desc.isShaderAtomicsI64Supported = isShaderAtomicsI64Supported || agsParams.extensionsSupported.intrinsics19;
#endif

m_Desc.isDrawParametersEmulationEnabled = enableDrawParametersEmulation && shaderModel.HighestShaderModel <= D3D_SHADER_MODEL_6_7;

m_Desc.isSwapChainSupported = HasOutput();
m_Desc.isLowLatencySupported = m_Ext.HasNVAPI();
}
Expand Down
5 changes: 0 additions & 5 deletions Source/D3D12/DeviceD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ struct DeviceD3D12 final : public DeviceBase {
return m_Adapter;
}

inline bool AreEnhancedBarriersSupported() const {
return m_AreEnhancedBarriersSupported;
}

inline const CoreInterface& GetCoreInterface() const {
return m_CoreInterface;
}
Expand Down Expand Up @@ -171,7 +167,6 @@ struct DeviceD3D12 final : public DeviceBase {
ComPtr<ID3D12CommandSignature> m_DispatchRaysCommandSignature;
CoreInterface m_CoreInterface = {};
uint8_t m_Version = 0;
bool m_AreEnhancedBarriersSupported = false;
bool m_IsWrapped = false;
std::array<Lock, DESCRIPTOR_HEAP_TYPE_NUM> m_FreeDescriptorLocks;
Lock m_DescriptorHeapLock;
Expand Down

0 comments on commit c614b02

Please sign in to comment.