Skip to content

Commit

Permalink
Merge branch 'dev' into brad-promote-d3d12-convert-to-default
Browse files Browse the repository at this point in the history
  • Loading branch information
bradgrantham-lunarg authored Aug 29, 2024
2 parents 1b250df + 3f9f91b commit 1fbde9a
Show file tree
Hide file tree
Showing 30 changed files with 475 additions and 233 deletions.
1 change: 1 addition & 0 deletions cmake/toolchain/linux_x86_32.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
6 changes: 3 additions & 3 deletions framework/decode/dx12_dump_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ void DefaultDx12DumpResourcesDelegate::WriteBlockEnd()
// Dominates profiling (2/2):
const std::string block =
json_data_.dump(json_options_.format == util::JsonFormat::JSONL ? -1 : util::kJsonIndentWidth);
util::platform::FileWriteNoLock(block.data(), sizeof(std::string::value_type), block.length(), json_file_handle_);
util::platform::FileWriteNoLock(block.data(), block.length() * sizeof(std::string::value_type), json_file_handle_);
util::platform::FileFlush(json_file_handle_); /// @todo Implement a FileFlushNoLock() for all platforms.
}

Expand All @@ -1743,9 +1743,9 @@ bool DefaultDx12DumpResourcesDelegate::WriteBinaryFile(const std::string&
FILE* file_output = nullptr;
if (util::platform::FileOpen(&file_output, filename.c_str(), "wb") == 0)
{
util::platform::FileWrite(data.data() + offset, size, 1, file_output);
bool success = util::platform::FileWrite(data.data() + offset, size, file_output);
util::platform::FileClose(file_output);
return true;
return success;
}
return false;
}
Expand Down
100 changes: 92 additions & 8 deletions framework/decode/dx12_resource_value_mapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,18 @@ void Dx12ResourceValueMapper::PostProcessBuildRaytracingAccelerationStructure(

format::HandleId resource_id = format::kNullHandleId;
bool found = false;
reverse_gpu_va_map_.Map(build_desc->Inputs.InstanceDescs,
&resource_id,
&found,
build_desc->Inputs.InstanceDescs +
build_desc->Inputs.NumDescs * sizeof(D3D12_RAYTRACING_INSTANCE_DESC));

auto min_end_gpu_va = build_desc->Inputs.InstanceDescs;
if (build_desc->Inputs.DescsLayout == D3D12_ELEMENTS_LAYOUT_ARRAY)
{
min_end_gpu_va += build_desc->Inputs.NumDescs * sizeof(D3D12_RAYTRACING_INSTANCE_DESC);
}
else
{
min_end_gpu_va += build_desc->Inputs.NumDescs * sizeof(D3D12_GPU_VIRTUAL_ADDRESS);
}

reverse_gpu_va_map_.Map(build_desc->Inputs.InstanceDescs, &resource_id, &found, min_end_gpu_va);

if (resource_id != format::kNullHandleId)
{
Expand Down Expand Up @@ -514,11 +521,22 @@ void Dx12ResourceValueMapper::PostProcessBuildRaytracingAccelerationStructure(
{ nullptr, nullptr, 0 } });
}
}
else if (build_desc->Inputs.DescsLayout == D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS)
{
constexpr auto instance_desc_pointer_stride = sizeof(D3D12_GPU_VIRTUAL_ADDRESS);
for (UINT i = 0; i < build_desc->Inputs.NumDescs; ++i)
{
resource_value_infos.insert({ offset_to_instance_descs_start + instance_desc_pointer_stride * i,
ResourceValueType::kRaytracingInstanceDescPointer,
sizeof(D3D12_GPU_VIRTUAL_ADDRESS),
nullptr,
{ nullptr, nullptr, 0 } });
}
}
else
{
// TODO: Support D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS.
GFXRECON_LOG_WARNING("Application built acceleration structure with unsupported layout: "
"D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS");
GFXRECON_LOG_ERROR("Unknown BuildRaytracingAccelerationStructure DescsLayout: %d",
static_cast<int>(build_desc->Inputs.DescsLayout));
}
}
else
Expand Down Expand Up @@ -1290,6 +1308,72 @@ bool Dx12ResourceValueMapper::MapValue(const ResourceValueInfo& value_info,
}
return false;
}
else if (value_info.type == ResourceValueType::kRaytracingInstanceDescPointer)
{
GFXRECON_ASSERT(value_info.size == sizeof(D3D12_GPU_VIRTUAL_ADDRESS));

// Map the GPU_VA in the array of instance desc pointers.
ResourceValueInfo rvi = value_info;
rvi.type = ResourceValueType::kGpuVirtualAddress;
MapValue(rvi, result_data, resource_id, resource_info, indirect_values_map);

// Read instance desc GPU_VA from the array of pointers.
D3D12_GPU_VIRTUAL_ADDRESS instance_desc_gpu_va = 0;
util::platform::MemoryCopy(&instance_desc_gpu_va,
sizeof(instance_desc_gpu_va),
result_data.data() + value_info.offset,
sizeof(instance_desc_gpu_va));

GFXRECON_ASSERT(value_info.offset == final_offset);

// Insert new RV infos for instance desc's AccelerationStructure, which will queue it for mapping.
if (instance_desc_gpu_va != 0)
{
// The spec requires that instance descs are aligned to D3D12_RAYTRACING_INSTANCE_DESCS_BYTE_ALIGNMENT. If
// the instance descs are not aligned behavior may be undefined.
GFXRECON_ASSERT((instance_desc_gpu_va % D3D12_RAYTRACING_INSTANCE_DESCS_BYTE_ALIGNMENT) == 0);

// Find the resource that contains the address referenced by instance_desc_gpu_va.
format::HandleId instance_desc_resource_id = format::kNullHandleId;
bool found = false;
reverse_gpu_va_map_.Map(instance_desc_gpu_va,
&instance_desc_resource_id,
&found,
instance_desc_gpu_va + sizeof(D3D12_RAYTRACING_INSTANCE_DESC));

if (instance_desc_resource_id != format::kNullHandleId)
{
GFXRECON_ASSERT(found);

auto resource_object_info = get_object_info_func_(instance_desc_resource_id);
GFXRECON_ASSERT(resource_object_info != nullptr);
GFXRECON_ASSERT(resource_object_info->object != nullptr);

auto instance_desc_resource = static_cast<ID3D12Resource*>(resource_object_info->object);
GFXRECON_ASSERT(instance_desc_gpu_va >= instance_desc_resource->GetGPUVirtualAddress());
auto offset_to_instance_desc_start =
instance_desc_gpu_va - instance_desc_resource->GetGPUVirtualAddress();

constexpr auto accel_struct_gpu_va_offset =
offsetof(D3D12_RAYTRACING_INSTANCE_DESC, AccelerationStructure);

auto& resource_value_infos = indirect_values_map[resource_object_info];
resource_value_infos.insert({ offset_to_instance_desc_start + accel_struct_gpu_va_offset,
ResourceValueType::kGpuVirtualAddress,
sizeof(D3D12_GPU_VIRTUAL_ADDRESS),
nullptr,
{ nullptr, nullptr, 0 } });
}
else
{
GFXRECON_LOG_ERROR("Failed to find the resource containing the D3D12_GPU_VIRTUAL_ADDRESS (%" PRIu64
") of InstanceDescs in call to BuildRaytracingAccelerationStructure. GPU addresses "
"pointed to by InstanceDescs may be incorrect.",
instance_desc_gpu_va);
}
}
return true;
}
else
{
GFXRECON_ASSERT(false && "Unrecognized resource value type.");
Expand Down
9 changes: 6 additions & 3 deletions framework/decode/file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,12 @@ bool FileProcessor::ReadCompressedParameterBuffer(size_t compressed_buffer_size

bool FileProcessor::ReadBytes(void* buffer, size_t buffer_size)
{
size_t bytes_read = util::platform::FileRead(buffer, 1, buffer_size, file_descriptor_);
bytes_read_ += bytes_read;
return (bytes_read == buffer_size);
if (util::platform::FileRead(buffer, buffer_size, file_descriptor_))
{
bytes_read_ += buffer_size;
return true;
}
return false;
}

bool FileProcessor::SkipBytes(size_t skip_size)
Expand Down
18 changes: 12 additions & 6 deletions framework/decode/file_transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,22 @@ bool FileTransformer::ReadCompressedParameterBuffer(size_t compressed_buffer_si

bool FileTransformer::ReadBytes(void* buffer, size_t buffer_size)
{
size_t bytes_read = util::platform::FileRead(buffer, 1, buffer_size, input_file_);
bytes_read_ += bytes_read;
return (bytes_read == buffer_size);
if (util::platform::FileRead(buffer, buffer_size, input_file_))
{
bytes_read_ += buffer_size;
return true;
}
return false;
}

bool FileTransformer::WriteBytes(const void* buffer, size_t buffer_size)
{
size_t bytes_written = util::platform::FileWrite(buffer, 1, buffer_size, output_file_);
bytes_written_ += bytes_written;
return (bytes_written == buffer_size);
if (util::platform::FileWrite(buffer, buffer_size, output_file_))
{
bytes_written_ += buffer_size;
return true;
}
return false;
}

bool FileTransformer::SkipBytes(uint64_t skip_size)
Expand Down
4 changes: 2 additions & 2 deletions framework/decode/json_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ bool JsonWriter::WriteBinaryFile(const std::string& filename, uint64_t data_size
FILE* file_output = nullptr;
if (util::platform::FileOpen(&file_output, filename.c_str(), "wb") == 0)
{
util::platform::FileWrite(data, static_cast<size_t>(data_size), 1, file_output);
bool success = util::platform::FileWrite(data, static_cast<size_t>(data_size), file_output);
util::platform::FileClose(file_output);
return true;
return success;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion framework/decode/preload_file_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ bool PreloadFileProcessor::ReadBytes(void* buffer, size_t buffer_size)
}
else
{
bytes_read = util::platform::FileRead(buffer, 1, buffer_size, file_descriptor_);
bytes_read = util::platform::FileRead(buffer, buffer_size, file_descriptor_);
bytes_read_ += bytes_read;
}
return bytes_read == buffer_size;
Expand Down
3 changes: 1 addition & 2 deletions framework/decode/vulkan_cpp_util_datapack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ void DataFilePacker::WriteContentsToFile(const std::string& file_path,

util::platform::FileSeek(fp, fileOffset, util::platform::FileSeekCurrent);

size_t written_size = util::platform::FileWrite(data, sizeof(uint8_t), size, fp);
if (written_size != size)
if (!util::platform::FileWrite(data, size, fp))
{
fprintf(stderr, "Error while saving data into %s\n", file_path.c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion framework/decode/vulkan_replay_consumer_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5641,7 +5641,7 @@ VkResult VulkanReplayConsumerBase::OverrideCreateShaderModule(
size_t file_size = static_cast<size_t>(util::platform::FileTell(fp));
file_code = std::make_unique<char[]>(file_size);
util::platform::FileSeek(fp, 0L, util::platform::FileSeekSet);
util::platform::FileRead(file_code.get(), sizeof(char), file_size, fp);
util::platform::FileRead(file_code.get(), file_size, fp);
override_info.pCode = (uint32_t*)file_code.get();
override_info.codeSize = file_size;
GFXRECON_LOG_INFO("Replacement shader found: %s", file_path.c_str());
Expand Down
8 changes: 4 additions & 4 deletions framework/decode/vulkan_replay_dump_resources_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ bool VulkanReplayDumpResourcesJson::InitializeFile(const std::string& filename)
return false;
}

util::platform::FileWrite("[\n", 2, 1, file_);
util::platform::FileWrite("[\n", 2, file_);

BlockStart();
json_data_["header"] = header_;
Expand Down Expand Up @@ -110,7 +110,7 @@ void VulkanReplayDumpResourcesJson::Close()
{
if (file_ != nullptr)
{
util::platform::FileWrite("]", 1, 1, file_);
util::platform::FileWrite("]", 1, file_);
gfxrecon::util::platform::FileClose(file_);
file_ = nullptr;
}
Expand All @@ -130,13 +130,13 @@ void VulkanReplayDumpResourcesJson::BlockEnd()

if (!first_block_)
{
util::platform::FileWrite(",\n", 2, 1, file_);
util::platform::FileWrite(",\n", 2, file_);
}

first_block_ = false;

const std::string block = json_data_.dump(util::kJsonIndentWidth);
util::platform::FileWrite(block.c_str(), block.size(), 1, file_);
util::platform::FileWrite(block.c_str(), block.size(), file_);
}

nlohmann::ordered_json& VulkanReplayDumpResourcesJson::InsertSubEntry(const std::string& entry_name)
Expand Down
30 changes: 28 additions & 2 deletions framework/encode/dx12_object_wrapper_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ struct DxAccelerationStructureBuildInfo
std::vector<D3D12_RAYTRACING_GEOMETRY_DESC> inputs_geometry_descs;

uint64_t input_data_size{ 0 };
uint64_t input_data_header_size{ 0 };
graphics::dx12::ID3D12ResourceComPtr input_data_resource{ nullptr };

// Copy state.
Expand All @@ -199,6 +200,8 @@ struct DxAccelerationStructureBuildInfo
D3D12_RAYTRACING_ACCELERATION_STRUCTURE_COPY_MODE
copy_mode{}; ///< Copy mode used to create this acceleration structure
bool was_copy_source{ false }; ///< Was this acceleration structure copied to another?

bool is_tlas_with_array_of_pointers{ false };
};

struct IDXGIKeyedMutexInfo : public DxgiWrapperInfo
Expand Down Expand Up @@ -290,12 +293,35 @@ struct ID3D12QueryHeapInfo : public DxWrapperInfo
struct ID3D12CommandSignatureInfo : public DxWrapperInfo
{};

struct AccelerationStructureBuildTrackingObjects
{
AccelerationStructureBuildTrackingObjects(
graphics::dx12::ID3D12ResourceComPtr _resource,
graphics::dx12::ID3D12CommandAllocatorComPtr _post_build_copy_cmd_allocator,
graphics::dx12::ID3D12GraphicsCommandList4ComPtr _post_build_copy_cmd_list) :
resource(_resource),
post_build_copy_cmd_allocator(_post_build_copy_cmd_allocator),
post_build_copy_cmd_list(_post_build_copy_cmd_list)
{}

// Target resource for build inputs.
graphics::dx12::ID3D12ResourceComPtr resource = nullptr;

// Objects used to copy inputs for TLAS builds that use D3D12_ELEMENTS_LAYOUT_ARRAY_OF_POINTERS for DescLayout.
graphics::dx12::ID3D12CommandAllocatorComPtr post_build_copy_cmd_allocator = nullptr;
graphics::dx12::ID3D12GraphicsCommandList4ComPtr post_build_copy_cmd_list = nullptr;
};

struct ID3D12CommandQueueInfo : public DxWrapperInfo
{
//// Begin state tracking members

graphics::dx12::ID3D12FenceComPtr acceleration_structure_build_fence;
std::map<uint64_t, graphics::dx12::ID3D12ResourceComPtr> pending_acceleration_structure_build_resources;
// Fence that is signalled on the queue after AS builds.
graphics::dx12::ID3D12FenceComPtr acceleration_structure_build_tracking_fence;

// Objects that need to be kept alive until the associated AS build has completed on the GPU. Key of the map is the
// fence signal value to indicate the AS build is complete.
std::map<uint64_t, AccelerationStructureBuildTrackingObjects> acceleration_structure_build_tracking_objects;
};

struct ID3D12PipelineLibraryInfo : public DxWrapperInfo
Expand Down
Loading

0 comments on commit 1fbde9a

Please sign in to comment.