Skip to content

Commit

Permalink
Follow up fixes:
Browse files Browse the repository at this point in the history
- NRI: added forgotten "MIRROR_CLAMP_TO_EDGE" address mode
- D3D11/D3D12: fixed some NVAPI calls and shading rate usage if unsupported
  • Loading branch information
dzhdanNV committed Sep 2, 2024
1 parent eb537ab commit a64fa4a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Include/NRIDescs.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,8 @@ NriEnum(AddressMode, uint8_t,
REPEAT,
MIRRORED_REPEAT,
CLAMP_TO_EDGE,
CLAMP_TO_BORDER
CLAMP_TO_BORDER,
MIRROR_CLAMP_TO_EDGE
);

NriStruct(AddressModes) {
Expand Down
2 changes: 1 addition & 1 deletion Source/D3D11/CommandBufferD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void CommandBufferD3D11::BeginRendering(const AttachmentsDesc& attachmentsDesc)

// Shading rate
#if NRI_USE_EXT_LIBS
if (m_Device.GetExt()->HasNVAPI()) {
if (m_Device.GetExt()->HasNVAPI() && m_Device.GetDesc().isAttachmentShadingRateSupported) {
ID3D11NvShadingRateResourceView* shadingRateImage = nullptr;
if (attachmentsDesc.shadingRate) {
const DescriptorD3D11& descriptor = *(DescriptorD3D11*)attachmentsDesc.shadingRate;
Expand Down
14 changes: 7 additions & 7 deletions Source/D3D11/DescriptorD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

using namespace nri;

inline D3D11_TEXTURE_ADDRESS_MODE GetD3D11AdressMode(AddressMode mode) {
static inline D3D11_TEXTURE_ADDRESS_MODE GetAddressMode(AddressMode mode) {
return (D3D11_TEXTURE_ADDRESS_MODE)(D3D11_TEXTURE_ADDRESS_WRAP + (uint32_t)mode);
}

inline D3D11_FILTER GetFilterIsotropic(Filter mip, Filter magnification, Filter minification, FilterExt filterExt, bool useComparison) {
static inline D3D11_FILTER GetFilterIsotropic(Filter mip, Filter magnification, Filter minification, FilterExt filterExt, bool useComparison) {
uint32_t combinedMask = mip == Filter::LINEAR ? 0x1 : 0;
combinedMask |= magnification == Filter::LINEAR ? 0x4 : 0;
combinedMask |= minification == Filter::LINEAR ? 0x10 : 0;
Expand All @@ -27,7 +27,7 @@ inline D3D11_FILTER GetFilterIsotropic(Filter mip, Filter magnification, Filter
return (D3D11_FILTER)combinedMask;
}

static DXGI_FORMAT GetShaderFormatForDepth(DXGI_FORMAT format) {
static inline DXGI_FORMAT GetShaderFormatForDepth(DXGI_FORMAT format) {
switch (format) {
case DXGI_FORMAT_D16_UNORM:
return DXGI_FORMAT_R16_UNORM;
Expand All @@ -42,7 +42,7 @@ static DXGI_FORMAT GetShaderFormatForDepth(DXGI_FORMAT format) {
}
}

D3D11_FILTER GetFilterAnisotropic(FilterExt filterExt, bool useComparison) {
static inline D3D11_FILTER GetFilterAnisotropic(FilterExt filterExt, bool useComparison) {
if (filterExt == FilterExt::MIN)
return D3D11_FILTER_MINIMUM_ANISOTROPIC;
else if (filterExt == FilterExt::MAX)
Expand Down Expand Up @@ -452,9 +452,9 @@ Result DescriptorD3D11::Create(const SamplerDesc& samplerDesc) {
bool isComparison = samplerDesc.compareFunc != CompareFunc::NONE;

D3D11_SAMPLER_DESC desc = {};
desc.AddressU = GetD3D11AdressMode(samplerDesc.addressModes.u);
desc.AddressV = GetD3D11AdressMode(samplerDesc.addressModes.v);
desc.AddressW = GetD3D11AdressMode(samplerDesc.addressModes.w);
desc.AddressU = GetAddressMode(samplerDesc.addressModes.u);
desc.AddressV = GetAddressMode(samplerDesc.addressModes.v);
desc.AddressW = GetAddressMode(samplerDesc.addressModes.w);
desc.MipLODBias = samplerDesc.mipBias;
desc.MaxAnisotropy = samplerDesc.anisotropy;
desc.ComparisonFunc = GetD3D11ComparisonFuncFromCompareFunc(samplerDesc.compareFunc);
Expand Down
13 changes: 7 additions & 6 deletions Source/D3D11/DeviceD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,15 @@ void DeviceD3D11::FillDesc() {
bool isShaderAtomicsF16Supported = false;
bool isShaderAtomicsF32Supported = false;
#if NRI_USE_EXT_LIBS
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported));

NV_D3D11_FEATURE_DATA_RASTERIZER_SUPPORT rasterizerFeatures = {};
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_CheckFeatureSupport(m_Device, NV_D3D11_FEATURE_RASTERIZER, &rasterizerFeatures, sizeof(rasterizerFeatures)));

NV_D3D1x_GRAPHICS_CAPS caps = {};
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D1x_GetGraphicsCapabilities(m_Device, NV_D3D1x_GRAPHICS_CAPS_VER, &caps));

if (m_Ext.HasNVAPI()) {
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D11_CheckFeatureSupport(m_Device, NV_D3D11_FEATURE_RASTERIZER, &rasterizerFeatures, sizeof(rasterizerFeatures)));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D1x_GetGraphicsCapabilities(m_Device, NV_D3D1x_GRAPHICS_CAPS_VER, &caps));
}

m_Desc.programmableSampleLocationsTier = rasterizerFeatures.ProgrammableSamplePositions ? 2 : 0;

Expand Down
10 changes: 6 additions & 4 deletions Source/D3D12/CommandBufferD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,13 @@ inline void CommandBufferD3D12::BeginRendering(const AttachmentsDesc& attachment
m_GraphicsCommandList->OMSetRenderTargets(m_RenderTargetNum, m_RenderTargets.data(), FALSE, m_DepthStencil.ptr ? &m_DepthStencil : nullptr);

// Shading rate
ID3D12Resource* shadingRateImage = nullptr;
if (attachmentsDesc.shadingRate)
shadingRateImage = *(DescriptorD3D12*)attachmentsDesc.shadingRate;
if (m_Device.GetDesc().isAttachmentShadingRateSupported) {
ID3D12Resource* shadingRateImage = nullptr;
if (attachmentsDesc.shadingRate)
shadingRateImage = *(DescriptorD3D12*)attachmentsDesc.shadingRate;

m_GraphicsCommandList->RSSetShadingRateImage(shadingRateImage);
m_GraphicsCommandList->RSSetShadingRateImage(shadingRateImage);
}
}

inline void CommandBufferD3D12::SetVertexBuffers(uint32_t baseSlot, uint32_t bufferNum, const Buffer* const* buffers, const uint64_t* offsets) {
Expand Down
6 changes: 4 additions & 2 deletions Source/D3D12/DeviceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,10 @@ void DeviceD3D12::FillDesc(const DeviceCreationDesc& deviceCreationDesc) {
bool isShaderAtomicsF16Supported = false;
bool isShaderAtomicsF32Supported = false;
#if NRI_USE_EXT_LIBS
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported));
if (m_Ext.HasNVAPI()) {
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP16_ATOMIC, &isShaderAtomicsF16Supported));
REPORT_ERROR_ON_BAD_STATUS(this, NvAPI_D3D12_IsNvShaderExtnOpCodeSupported(m_Device, NV_EXTN_OP_FP32_ATOMIC, &isShaderAtomicsF32Supported));
}
#endif

m_Desc.isShaderAtomicsF16Supported = isShaderAtomicsF16Supported;
Expand Down
9 changes: 1 addition & 8 deletions Source/D3D12/SharedD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,8 @@ D3D12_BLEND_OP nri::GetBlendOp(BlendFunc blendFunc) {
return BLEND_OPS[(size_t)blendFunc];
}

constexpr std::array<D3D12_TEXTURE_ADDRESS_MODE, (size_t)AddressMode::MAX_NUM> TEXTURE_ADDRESS_MODES = {
D3D12_TEXTURE_ADDRESS_MODE_WRAP, // REPEAT
D3D12_TEXTURE_ADDRESS_MODE_MIRROR, // MIRRORED_REPEAT
D3D12_TEXTURE_ADDRESS_MODE_CLAMP, // CLAMP_TO_EDGE
D3D12_TEXTURE_ADDRESS_MODE_BORDER // CLAMP_TO_BORDER
};

D3D12_TEXTURE_ADDRESS_MODE nri::GetAddressMode(AddressMode addressMode) {
return TEXTURE_ADDRESS_MODES[(size_t)addressMode];
return (D3D12_TEXTURE_ADDRESS_MODE)(D3D12_TEXTURE_ADDRESS_MODE_WRAP + (uint32_t)addressMode);
}

constexpr std::array<D3D12_HEAP_TYPE, (size_t)MemoryLocation::MAX_NUM> HEAP_TYPES = {
Expand Down
9 changes: 1 addition & 8 deletions Source/VK/ConversionVK.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,8 @@ constexpr VkSamplerMipmapMode GetSamplerMipmapMode(Filter filter) {
return SAMPLER_MIPMAP_MODE[(size_t)filter];
}

constexpr std::array<VkSamplerAddressMode, (size_t)AddressMode::MAX_NUM> SAMPLER_ADDRESS_MODE = {
VK_SAMPLER_ADDRESS_MODE_REPEAT, // REPEAT
VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT, // MIRRORED_REPEAT
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, // CLAMP_TO_EDGE
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER // CLAMP_TO_BORDER
};

constexpr VkSamplerAddressMode GetSamplerAddressMode(AddressMode addressMode) {
return SAMPLER_ADDRESS_MODE[(size_t)addressMode];
return (VkSamplerAddressMode)(VK_SAMPLER_ADDRESS_MODE_REPEAT + (uint32_t)addressMode);
}

constexpr std::array<VkImageViewType, (size_t)Texture1DViewType::MAX_NUM> IMAGE_VIEW_TYPE_1D = {
Expand Down

0 comments on commit a64fa4a

Please sign in to comment.