Skip to content

Commit

Permalink
Merge branch 'branch-2' into 'release/v0.4'
Browse files Browse the repository at this point in the history
Picking critical fixes for 0.4

See merge request lightspeedrtx/dxvk-remix-nv!663
  • Loading branch information
nsubtil committed Jan 17, 2024
2 parents b2b0b34 + 73dcb3a commit db39ef9
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 143 deletions.
2 changes: 1 addition & 1 deletion packman-external.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<package name="rtx-remix-nv_usd" version="5" />
</dependency>
<dependency name="omni_core_materials" linkPath="external/omni_core_materials">
<package name="rtx-remix-omni_core_materials" version="9" />
<package name="rtx-remix-omni_core_materials" version="11" />
</dependency>
<dependency name="reflex" linkPath="external/reflex">
<package name="rtx-remix-reflex" version="1" />
Expand Down
18 changes: 12 additions & 6 deletions src/d3d9/d3d9_rtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,10 @@ namespace dxvk {
}

if (triggerRtxInjection) {
const auto currentReflexFrameId = GetReflexFrameId();

// Bind all resources required for this drawcall to context first (i.e. render targets)
m_parent->PrepareDraw(drawContext.PrimitiveType);
m_parent->EmitCs([currentReflexFrameId](DxvkContext* ctx) {
static_cast<RtxContext*>(ctx)->injectRTX(currentReflexFrameId);
});

m_parent->FlushCsChunk();
triggerInjectRTX();

m_rtxInjectTriggered = true;
return { true, false };
Expand Down Expand Up @@ -643,6 +639,16 @@ namespace dxvk {
return { preserveOriginalDraw, true };
}

void D3D9Rtx::triggerInjectRTX() {
// Flush any pending game and RTX work
m_parent->Flush();

// Send command to inject RTX
m_parent->EmitCs([cReflexFrameId = GetReflexFrameId()](DxvkContext* ctx) {
static_cast<RtxContext*>(ctx)->injectRTX(cReflexFrameId);
});
}

void D3D9Rtx::CommitGeometryToRT(const DrawContext& drawContext) {
ScopedCpuProfileZone();
auto drawInfo = m_parent->GenerateDrawInfo(drawContext.PrimitiveType, drawContext.PrimitiveCount, m_parent->GetInstanceCount());
Expand Down
5 changes: 4 additions & 1 deletion src/d3d9/d3d9_rtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ namespace dxvk {
bool processTextures();

PrepareDrawType internalPrepareDraw(const IndexContext& indexContext, const VertexContext vertexContext[caps::MaxStreams], const DrawContext& drawContext);


void triggerInjectRTX();


struct DrawCallType {
RtxGeometryStatus status;
bool triggerRtxInjection;
Expand Down
5 changes: 3 additions & 2 deletions src/dxvk/rtx_render/rtx_asset_data_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,11 @@ namespace dxvk {
const bool isSupported = isDDS;

if (!isSupported) {
const char* message = "Unsupported image file format, use the RTX-Remix toolkit and ingest the following asset: ";
if (RtxOptions::Automation::suppressAssetLoadingErrors()) {
Logger::warn(str::format("Unsupported image file format, please convert to DDS using Remix Export: ", filename));
Logger::warn(str::format(message, filename));
} else {
Logger::err(str::format("Unsupported image file format, please convert to DDS using Remix Export: ", filename));
Logger::err(str::format(message, filename));
}
return nullptr;
}
Expand Down
165 changes: 65 additions & 100 deletions src/dxvk/rtx_render/rtx_bindless_resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,121 +54,86 @@ namespace dxvk {
return m_tables[type][currentIdx()]->bindlessDescSet;
}

void BindlessResourceManager::prepareSceneData(const Rc<DxvkContext> ctx, const std::vector<TextureRef>& rtTextures, const std::vector<RaytraceBuffer>& rtBuffers, const std::vector<Rc<DxvkSampler>>& samplers) {
ScopedCpuProfileZone();
if (m_frameLastUpdated == m_device->getCurrentFrameId()) {
Logger::debug("Updating bindless tables multiple times per frame...");
return;
}

// Increment
m_globalBindlessDescSetIdx = nextIdx();
template<VkDescriptorType Type, typename T, typename U>
void BindlessResourceManager::createDescriptorSet(const Rc<DxvkContext>& ctx, const std::vector<U>& engineObjects, const T& dummyDescriptor) {
const size_t numDescriptors = std::max((size_t) 1, engineObjects.size()); // Must always leave 1 to have a valid binding set
assert(numDescriptors <= kMaxBindlessResources);

// Textures
{
std::vector<VkDescriptorImageInfo> imageInfo(rtTextures.size());
std::vector<T> descriptorInfos(numDescriptors);
descriptorInfos[0] = dummyDescriptor; // we set the first descriptor to be a dummy (size is always at least 1) and overwrite it if there are valid engine objects

uint32_t idx = 0;
for (auto&& texRef : rtTextures) {
DxvkImageView* imageView = texRef.getImageView();
uint32_t idx = 0;
for (auto&& engineObject : engineObjects) {
descriptorInfos[idx] = dummyDescriptor;

if constexpr (Type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) {
DxvkImageView* imageView = engineObject.getImageView();
if (imageView != nullptr) {
imageInfo[idx].sampler = nullptr;
imageInfo[idx].imageView = imageView->handle();
imageInfo[idx].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
descriptorInfos[idx].sampler = nullptr;
descriptorInfos[idx].imageView = imageView->handle();
descriptorInfos[idx].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
ctx->getCommandList()->trackResource<DxvkAccess::Read>(imageView);
} else {
imageInfo[idx] = m_device->getCommon()->dummyResources().imageViewDescriptor(VK_IMAGE_VIEW_TYPE_2D, true);
}

++idx;
} else if constexpr (Type == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) {
if (engineObject.defined()) {
descriptorInfos[idx] = engineObject.getDescriptor().buffer;
ctx->getCommandList()->trackResource<DxvkAccess::Read>(engineObject.buffer());
}
} else if constexpr (Type == VK_DESCRIPTOR_TYPE_SAMPLER) {
if (engineObject != nullptr) {
descriptorInfos[idx].sampler = engineObject->handle();
descriptorInfos[idx].imageView = nullptr;
}
} else {
static_assert(Type != VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE || Type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER || Type != VK_DESCRIPTOR_TYPE_SAMPLER, "Support for this descriptor type has not been implemented yet.");
return;
}

assert(idx <= kMaxBindlessResources);

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);
}
++idx;
}

// Buffers
{
uint32_t idx = 0;
std::vector<VkDescriptorBufferInfo> bufferInfo(rtBuffers.size());
for (auto&& bufRef : rtBuffers) {
if (bufRef.defined()) {
bufferInfo[idx] = bufRef.getDescriptor().buffer;
ctx->getCommandList()->trackResource<DxvkAccess::Read>(bufRef.buffer());
} else {
bufferInfo[idx] = m_device->getCommon()->dummyResources().bufferDescriptor();
}
VkWriteDescriptorSet descWrites;
memset(&descWrites, 0, sizeof(descWrites));
descWrites.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descWrites.descriptorCount = numDescriptors;
descWrites.descriptorType = Type;

++idx;
}
if constexpr (std::is_same_v<T, VkDescriptorImageInfo>) {
descWrites.pImageInfo = &descriptorInfos[0];
} else if constexpr (std::is_same_v<T, VkDescriptorBufferInfo>) {
descWrites.pBufferInfo = &descriptorInfos[0];
}

assert(idx <= kMaxBindlessResources);

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);
}
switch (Type) {
case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
m_tables[Table::Textures][currentIdx()]->updateDescriptors(descWrites);
break;
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
m_tables[Table::Buffers][currentIdx()]->updateDescriptors(descWrites);
break;
case VK_DESCRIPTOR_TYPE_SAMPLER:
m_tables[Table::Samplers][currentIdx()]->updateDescriptors(descWrites);
break;
}
}

// Samplers
{
std::vector<VkDescriptorImageInfo> imageInfo(samplers.size());

uint32_t idx = 0;
for (auto&& sampler : samplers) {
if (sampler != nullptr) {
imageInfo[idx].sampler = sampler->handle();
imageInfo[idx].imageView = nullptr;
ctx->getCommandList()->trackResource<DxvkAccess::Read>(sampler);
} else {
imageInfo[idx] = m_device->getCommon()->dummyResources().samplerDescriptor();
}
void BindlessResourceManager::prepareSceneData(const Rc<DxvkContext> ctx, const std::vector<TextureRef>& rtTextures, const std::vector<RaytraceBuffer>& rtBuffers, const std::vector<Rc<DxvkSampler>>& samplers) {
ScopedCpuProfileZone();
if (m_frameLastUpdated == m_device->getCurrentFrameId()) {
Logger::debug("Updating bindless tables multiple times per frame...");
return;
}

++idx;
}
// Increment
m_globalBindlessDescSetIdx = nextIdx();

assert(idx <= kMaxBindlessSamplers);

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);
}
}
const VkDescriptorImageInfo dummyImage = m_device->getCommon()->dummyResources().imageViewDescriptor(VK_IMAGE_VIEW_TYPE_2D, true);
const VkDescriptorBufferInfo dummyBuffer = m_device->getCommon()->dummyResources().bufferDescriptor();
const VkDescriptorImageInfo dummySampler = m_device->getCommon()->dummyResources().samplerDescriptor();

createDescriptorSet<VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE>(ctx, rtTextures, dummyImage);
createDescriptorSet<VK_DESCRIPTOR_TYPE_STORAGE_BUFFER>(ctx, rtBuffers, dummyBuffer);
createDescriptorSet<VK_DESCRIPTOR_TYPE_SAMPLER>(ctx, samplers, dummySampler);

m_frameLastUpdated = m_device->getCurrentFrameId();
}
Expand Down Expand Up @@ -212,7 +177,7 @@ namespace dxvk {
throw DxvkError("BindlessTable: Failed to create descriptor set layout");
}

void BindlessResourceManager::BindlessTable::updateDescriptors(VkWriteDescriptorSet& set) {
void BindlessResourceManager::BindlessTable::updateDescriptors(VkWriteDescriptorSet set) {
if (bindlessDescSet == nullptr) {
// Allocate the descriptor set
bindlessDescSet = m_pManager->m_globalBindlessPool[m_pManager->currentIdx()]->alloc(layout, "bindless descriptor set");
Expand Down
5 changes: 4 additions & 1 deletion src/dxvk/rtx_render/rtx_bindless_resource_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace dxvk {
VkDescriptorSet bindlessDescSet = VK_NULL_HANDLE;

void createLayout(const VkDescriptorType type);
void updateDescriptors(VkWriteDescriptorSet& set);
void updateDescriptors(VkWriteDescriptorSet set);

private:
const Rc<vk::DeviceFn> vkd() const;
Expand All @@ -92,5 +92,8 @@ namespace dxvk {
}

void createGlobalBindlessDescPool();

template<VkDescriptorType Type, typename T, typename U>
void createDescriptorSet(const Rc<DxvkContext>& ctx, const std::vector<U>& engineObjects, const T& dummyDescriptor);
};
} // namespace dxvk
2 changes: 0 additions & 2 deletions src/dxvk/rtx_render/rtx_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ namespace dxvk {

m_execBarriers.recordCommands(m_cmd);

flushCommandList();

ScopedGpuProfileZone(this, "InjectRTX");

// Signal Reflex rendering start
Expand Down
9 changes: 5 additions & 4 deletions src/dxvk/rtx_render/rtx_geometry_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ namespace dxvk {
}

void RtxGeometryUtils::dispatchSkinning(const DrawCallState& drawCallState,
const RaytraceGeometry& geo) const {
const Rc<DxvkContext> ctx = m_skinningContext;
const RaytraceGeometry& geo) {
const Rc<DxvkContext>& ctx = m_skinningContext;
// Create command list for the initial skinning dispatch (e.g. The first frame we get skinning mesh draw calls)
if (ctx->getCommandList() == nullptr) {
ctx->beginRecording(ctx->getDevice()->createCommandList());
Expand Down Expand Up @@ -210,7 +210,7 @@ namespace dxvk {

DxvkBufferSlice cb = m_pCbData->alloc(alignment, sizeof(SkinningArgs));
memcpy(cb.mapPtr(0), &params, sizeof(SkinningArgs));
m_skinningContext->getCommandList()->trackResource<DxvkAccess::Write>(cb.buffer());
ctx->getCommandList()->trackResource<DxvkAccess::Write>(cb.buffer());

ctx->bindResourceBuffer(BINDING_SKINNING_CONSTANTS, cb);
ctx->bindResourceBuffer(BINDING_POSITION_OUTPUT, geo.positionBuffer);
Expand All @@ -226,7 +226,7 @@ namespace dxvk {

const VkExtent3D workgroups = util::computeBlockCount(VkExtent3D { params.numVertices, 1, 1 }, VkExtent3D { 128, 1, 1 });
ctx->dispatch(workgroups.width, workgroups.height, workgroups.depth);
m_skinningContext->getCommandList()->trackResource<DxvkAccess::Read>(cb.buffer());
ctx->getCommandList()->trackResource<DxvkAccess::Read>(cb.buffer());
} else {
const float* srcPosition = reinterpret_cast<float*>(drawCallState.getGeometryData().positionBuffer.mapPtr(0));
const float* srcNormal = reinterpret_cast<float*>(drawCallState.getGeometryData().normalBuffer.mapPtr(0));
Expand All @@ -249,6 +249,7 @@ namespace dxvk {
ctx->writeToBuffer(geo.normalBuffer.buffer(), geo.normalBuffer.offsetFromSlice() + idx * geo.normalBuffer.stride(), sizeof(dstNormal), &dstNormal[0], true);
}
}
++m_skinningCommands;
}

void RtxGeometryUtils::dispatchViewModelCorrection(
Expand Down
5 changes: 3 additions & 2 deletions src/dxvk/rtx_render/rtx_geometry_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace dxvk {
class RtxGeometryUtils : public CommonDeviceObject {
std::unique_ptr<DxvkStagingDataAlloc> m_pCbData;
Rc<DxvkContext> m_skinningContext;
uint32_t m_skinningCommands = 0;

public:
explicit RtxGeometryUtils(DxvkDevice* pDevice);
Expand All @@ -68,7 +69,7 @@ namespace dxvk {
/**
* \brief Execute a compute shader to perform skinning
*/
void dispatchSkinning(const DrawCallState& drawCallState, const RaytraceGeometry& geo) const;
void dispatchSkinning(const DrawCallState& drawCallState, const RaytraceGeometry& geo);

/**
* \brief Execute a compute shader to perform view model perspective correction
Expand Down Expand Up @@ -170,7 +171,7 @@ namespace dxvk {
InterleavedGeometryDescriptor& output) const;

inline void flushCommandList() {
if (m_skinningContext->getCommandList() != nullptr) {
if (m_skinningContext->getCommandList() != nullptr && m_skinningCommands > 0) {
m_skinningContext->flushCommandList();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/dxvk/rtx_render/rtx_material_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
X(SubsurfaceSingleScatteringAlbedo, subsurface_single_scattering_albedo, Vector3, Vector3(0.f), Vector3(1.f), Vector3(0.5f, 0.5f, 0.5f)) \
X(SubsurfaceVolumetricAnisotropy, subsurface_volumetric_anisotropy, float, -1.f, 1.f, 0.f) \
/* Sampler State */ \
X(FilterMode, filter_mode, uint8_t, lss::Mdl::Filter::Nearest, lss::Mdl::Filter::Linear, lss::Mdl::Filter::Nearest) \
X(FilterMode, filter_mode, uint8_t, lss::Mdl::Filter::Nearest, lss::Mdl::Filter::Linear, lss::Mdl::Filter::Linear) \
X(WrapModeU, wrap_mode_u, uint8_t, lss::Mdl::WrapMode::Clamp, lss::Mdl::WrapMode::Clip, lss::Mdl::WrapMode::Repeat) \
X(WrapModeV, wrap_mode_v, uint8_t, lss::Mdl::WrapMode::Clamp, lss::Mdl::WrapMode::Clip, lss::Mdl::WrapMode::Repeat)

Expand Down Expand Up @@ -116,7 +116,7 @@
X(ThinWallThickness, thin_wall_thickness, float, .001f, 65504.0f, .001f) \
X(EnableDiffuseLayer, use_diffuse_layer, bool, false, true, false) \
/* Sampler State */ \
X(FilterMode, filter_mode, uint8_t, lss::Mdl::Filter::Nearest, lss::Mdl::Filter::Linear, lss::Mdl::Filter::Nearest) \
X(FilterMode, filter_mode, uint8_t, lss::Mdl::Filter::Nearest, lss::Mdl::Filter::Linear, lss::Mdl::Filter::Linear) \
X(WrapModeU, wrap_mode_u, uint8_t, lss::Mdl::WrapMode::Clamp, lss::Mdl::WrapMode::Clip, lss::Mdl::WrapMode::Repeat) \
X(WrapModeV, wrap_mode_v, uint8_t, lss::Mdl::WrapMode::Clamp, lss::Mdl::WrapMode::Clip, lss::Mdl::WrapMode::Repeat)

Expand All @@ -140,7 +140,7 @@
X(EnableEmission, enable_emission, bool, false, true, false) \
X(EmissiveIntensity, emissive_intensity, float, 0.f, 65504.0f, 40.f) \
/* Sampler State */ \
X(FilterMode, filter_mode, uint8_t, lss::Mdl::Filter::Nearest, lss::Mdl::Filter::Linear, lss::Mdl::Filter::Nearest) \
X(FilterMode, filter_mode, uint8_t, lss::Mdl::Filter::Nearest, lss::Mdl::Filter::Linear, lss::Mdl::Filter::Linear) \
X(WrapModeU, wrap_mode_u, uint8_t, lss::Mdl::WrapMode::Clamp, lss::Mdl::WrapMode::Clip, lss::Mdl::WrapMode::Repeat) \
X(WrapModeV, wrap_mode_v, uint8_t, lss::Mdl::WrapMode::Clamp, lss::Mdl::WrapMode::Clip, lss::Mdl::WrapMode::Repeat)

Expand Down
Loading

0 comments on commit db39ef9

Please sign in to comment.