forked from LuisaGroup/LuisaCompute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use batch to optimize sparse heap map
- Loading branch information
1 parent
acaf825
commit 501e047
Showing
8 changed files
with
123 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "UpdateTileTracker.h" | ||
|
||
namespace lc::dx { | ||
void UpdateTileTracker::record( | ||
ID3D12Heap *heap, | ||
ID3D12Resource *resource, | ||
D3D12_TILED_RESOURCE_COORDINATE const &ResourceRegionStartCoordinate, | ||
D3D12_TILE_REGION_SIZE const &ResourceRegionSize, | ||
D3D12_TILE_RANGE_FLAGS RangeFlag, | ||
UINT HeapRangeStartOffset, | ||
UINT RangeTileCount) { | ||
std::pair<ID3D12Heap *, ID3D12Resource *> key{ | ||
heap, | ||
resource}; | ||
auto iter = map.emplace(key); | ||
auto &v = iter.value(); | ||
v.ResourceRegionStartCoordinates.emplace_back(ResourceRegionStartCoordinate); | ||
v.ResourceRegionSizes.emplace_back(ResourceRegionSize); | ||
v.RangeFlags.emplace_back(RangeFlag); | ||
v.HeapRangeStartOffsets.emplace_back(HeapRangeStartOffset); | ||
v.RangeTileCounts.emplace_back(RangeTileCount); | ||
} | ||
void UpdateTileTracker::update( | ||
ID3D12CommandQueue *queue, | ||
D3D12_TILE_MAPPING_FLAGS Flags) { | ||
for (auto &kv : map) { | ||
queue->UpdateTileMappings( | ||
kv.first.second, | ||
kv.second.ResourceRegionStartCoordinates.size(), | ||
kv.second.ResourceRegionStartCoordinates.data(), | ||
kv.second.ResourceRegionSizes.data(), | ||
kv.first.first, kv.second.RangeFlags.size(), | ||
kv.second.RangeFlags.data(), | ||
kv.second.HeapRangeStartOffsets.data(), | ||
kv.second.RangeTileCounts.data(), | ||
Flags); | ||
} | ||
for (auto &kv : disp_map) { | ||
queue->UpdateTileMappings( | ||
kv.first, | ||
kv.second.ResourceRegionStartCoordinates.size(), | ||
kv.second.ResourceRegionStartCoordinates.data(), | ||
kv.second.ResourceRegionSizes.data(), | ||
nullptr, | ||
1, | ||
vstd::get_rval_ptr(D3D12_TILE_RANGE_FLAG_NULL), | ||
nullptr, | ||
nullptr, | ||
Flags); | ||
} | ||
map.clear(); | ||
disp_map.clear(); | ||
} | ||
void UpdateTileTracker::deallocate( | ||
ID3D12Resource *resource, | ||
D3D12_TILED_RESOURCE_COORDINATE const &ResourceRegionStartCoordinate, | ||
D3D12_TILE_REGION_SIZE const &ResourceRegionSize) { | ||
auto iter = disp_map.emplace(resource); | ||
auto &v = iter.value(); | ||
v.ResourceRegionStartCoordinates.emplace_back(ResourceRegionStartCoordinate); | ||
v.ResourceRegionSizes.emplace_back(ResourceRegionSize); | ||
} | ||
}// namespace lc::dx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
#include <d3d12.h> | ||
#include <luisa/vstl/common.h> | ||
namespace lc::dx { | ||
class UpdateTileTracker { | ||
struct UpdateTileCommand { | ||
vstd::fixed_vector<D3D12_TILED_RESOURCE_COORDINATE, 4>ResourceRegionStartCoordinates; | ||
vstd::fixed_vector<D3D12_TILE_REGION_SIZE, 4>ResourceRegionSizes; | ||
vstd::fixed_vector<D3D12_TILE_RANGE_FLAGS, 4>RangeFlags; | ||
vstd::fixed_vector<UINT, 4>HeapRangeStartOffsets; | ||
vstd::fixed_vector<UINT, 4>RangeTileCounts; | ||
}; | ||
struct DisposeTileTracker { | ||
vstd::fixed_vector<D3D12_TILED_RESOURCE_COORDINATE, 4>ResourceRegionStartCoordinates; | ||
vstd::fixed_vector<D3D12_TILE_REGION_SIZE, 4>ResourceRegionSizes; | ||
}; | ||
vstd::HashMap<std::pair<ID3D12Heap *, ID3D12Resource *>, UpdateTileCommand> map; | ||
vstd::HashMap<ID3D12Resource *, DisposeTileTracker> disp_map; | ||
public: | ||
void record( | ||
ID3D12Heap *heap, | ||
ID3D12Resource *resource, | ||
D3D12_TILED_RESOURCE_COORDINATE const &ResourceRegionStartCoordinate, | ||
D3D12_TILE_REGION_SIZE const &ResourceRegionSize, | ||
D3D12_TILE_RANGE_FLAGS RangeFlag, | ||
UINT HeapRangeStartOffset, | ||
UINT RangeTileCount); | ||
void deallocate( | ||
ID3D12Resource *resource, | ||
D3D12_TILED_RESOURCE_COORDINATE const &ResourceRegionStartCoordinate, | ||
D3D12_TILE_REGION_SIZE const &ResourceRegionSize); | ||
void update( | ||
ID3D12CommandQueue *queue, | ||
D3D12_TILE_MAPPING_FLAGS Flags); | ||
}; | ||
}// namespace lcdx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters