Skip to content

Commit

Permalink
Merge branch 'sultimt/fix-option' into 'main'
Browse files Browse the repository at this point in the history
[REMIX-2420] Strengthen checks to prevent crashes

See merge request lightspeedrtx/dxvk-remix-nv!604
  • Loading branch information
sultim-t-nv committed Dec 7, 2023
2 parents 946a48e + c0d6fed commit ac72ba2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 37 deletions.
78 changes: 42 additions & 36 deletions src/dxvk/rtx_render/rtx_bindless_resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ namespace dxvk {

assert(idx <= kMaxBindlessResources);

VkWriteDescriptorSet descWrites;
descWrites.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrites.pNext = nullptr;
descWrites.dstSet = 0;// This will be filled in by the BindlessTable
descWrites.dstBinding = 0;
descWrites.dstArrayElement = 0;
descWrites.descriptorCount = idx;
descWrites.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
descWrites.pImageInfo = &imageInfo[0];
descWrites.pBufferInfo = nullptr;
descWrites.pTexelBufferView = nullptr;
m_tables[Table::Textures][currentIdx()]->updateDescriptors(descWrites);
if (idx > 0) {
VkWriteDescriptorSet descWrites;
descWrites.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrites.pNext = nullptr;
descWrites.dstSet = 0;// This will be filled in by the BindlessTable
descWrites.dstBinding = 0;
descWrites.dstArrayElement = 0;
descWrites.descriptorCount = idx;
descWrites.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
descWrites.pImageInfo = &imageInfo[0];
descWrites.pBufferInfo = nullptr;
descWrites.pTexelBufferView = nullptr;
m_tables[Table::Textures][currentIdx()]->updateDescriptors(descWrites);
}
}

// Buffers
Expand All @@ -117,18 +119,20 @@ namespace dxvk {

assert(idx <= kMaxBindlessResources);

VkWriteDescriptorSet descWrites;
descWrites.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrites.pNext = nullptr;
descWrites.dstSet = 0;// This will be filled in by the BindlessTable
descWrites.dstBinding = 0;
descWrites.dstArrayElement = 0;
descWrites.descriptorCount = idx;
descWrites.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
descWrites.pImageInfo = nullptr;
descWrites.pBufferInfo = &bufferInfo[0];
descWrites.pTexelBufferView = nullptr;
m_tables[Table::Buffers][currentIdx()]->updateDescriptors(descWrites);
if (idx > 0) {
VkWriteDescriptorSet descWrites;
descWrites.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrites.pNext = nullptr;
descWrites.dstSet = 0;// This will be filled in by the BindlessTable
descWrites.dstBinding = 0;
descWrites.dstArrayElement = 0;
descWrites.descriptorCount = idx;
descWrites.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
descWrites.pImageInfo = nullptr;
descWrites.pBufferInfo = &bufferInfo[0];
descWrites.pTexelBufferView = nullptr;
m_tables[Table::Buffers][currentIdx()]->updateDescriptors(descWrites);
}
}

// Samplers
Expand All @@ -150,18 +154,20 @@ namespace dxvk {

assert(idx <= kMaxBindlessSamplers);

VkWriteDescriptorSet descWrites;
descWrites.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrites.pNext = nullptr;
descWrites.dstSet = 0;// This will be filled in by the BindlessTable
descWrites.dstBinding = 0;
descWrites.dstArrayElement = 0;
descWrites.descriptorCount = idx;
descWrites.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
descWrites.pImageInfo = &imageInfo[0];
descWrites.pBufferInfo = nullptr;
descWrites.pTexelBufferView = nullptr;
m_tables[Table::Samplers][currentIdx()]->updateDescriptors(descWrites);
if (idx > 0) {
VkWriteDescriptorSet descWrites;
descWrites.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrites.pNext = nullptr;
descWrites.dstSet = 0;// This will be filled in by the BindlessTable
descWrites.dstBinding = 0;
descWrites.dstArrayElement = 0;
descWrites.descriptorCount = idx;
descWrites.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
descWrites.pImageInfo = &imageInfo[0];
descWrites.pBufferInfo = nullptr;
descWrites.pTexelBufferView = nullptr;
m_tables[Table::Samplers][currentIdx()]->updateDescriptors(descWrites);
}
}

m_frameLastUpdated = m_device->getCurrentFrameId();
Expand Down
6 changes: 5 additions & 1 deletion src/dxvk/rtx_render/rtx_remix_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,10 @@ namespace {
const char* value) {
std::lock_guard lock { s_mutex };

if (!key || key[0] == '\0' || !value) {
return REMIXAPI_ERROR_CODE_WRONG_ARGUMENTS;
}

auto& globalRtxOptions = dxvk::RtxOptionImpl::getGlobalRtxOptionMap();

auto found = globalRtxOptions.find(key);
Expand All @@ -883,7 +887,7 @@ namespace {
}

dxvk::Config newSetting;
newSetting.setOption(key, value);
newSetting.setOption(key, std::string { value });
found->second->readOption(newSetting, dxvk::RtxOptionImpl::ValueType::Value);

// Make sure we dont step on required configs
Expand Down
2 changes: 2 additions & 0 deletions src/dxvk/rtx_render/rtx_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ namespace dxvk {
void Resources::createRaytracingOutput(Rc<DxvkContext>& ctx, const VkExtent3D& downscaledExtent, const VkExtent3D& targetExtent) {
ScopedCpuProfileZone();

assert(targetExtent.width > 0 && targetExtent.height > 0 && targetExtent.depth > 0);

if (m_downscaledExtent != downscaledExtent) {
m_downscaledExtent = downscaledExtent;

Expand Down
15 changes: 15 additions & 0 deletions src/dxvk/rtx_render/rtx_texture_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,21 @@ namespace dxvk {
return it->second;
}

{
VkFormatProperties properties = m_pDevice->adapter()->formatProperties(assetData->info().format);

if (!(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ||
!(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) {
std::ostringstream formatStr;
formatStr << assetData->info().format;

Logger::err(str::format(
"Ignoring replacement texture with unsupported format [", formatStr.str(), "]: ",
assetData->info().filename));
return {};
}
}

// Create managed texture
auto texture = TextureUtils::createTexture(assetData, colorSpace);

Expand Down
7 changes: 7 additions & 0 deletions src/util/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ namespace dxvk {
const Tristate& value);
// NV-DXVK end

// NV-DXVK start: setOption type safety
template< typename T >
void setOption(
const std::string& key,
const T& value) = delete;
// NV-DXVK end

/**
* \brief Sets an option
*
Expand Down

0 comments on commit ac72ba2

Please sign in to comment.