[D3D12] Nicer DeferredCommandList uintmax_t alignment
This commit is contained in:
@@ -20,22 +20,22 @@ namespace d3d12 {
|
||||
DeferredCommandList::DeferredCommandList(
|
||||
D3D12CommandProcessor& command_processor, size_t initial_size)
|
||||
: command_processor_(command_processor) {
|
||||
command_stream_.reserve(initial_size);
|
||||
command_stream_.reserve(initial_size / sizeof(uintmax_t));
|
||||
}
|
||||
|
||||
void DeferredCommandList::Reset() { command_stream_.clear(); }
|
||||
|
||||
void DeferredCommandList::Execute(ID3D12GraphicsCommandList* command_list,
|
||||
ID3D12GraphicsCommandList1* command_list_1) {
|
||||
const uint8_t* stream = command_stream_.data();
|
||||
const uintmax_t* stream = command_stream_.data();
|
||||
size_t stream_remaining = command_stream_.size();
|
||||
ID3D12PipelineState* current_pipeline_state = nullptr;
|
||||
while (stream_remaining != 0) {
|
||||
const uint32_t* header = reinterpret_cast<const uint32_t*>(stream);
|
||||
const size_t header_size = xe::align(2 * sizeof(uint32_t), kAlignment);
|
||||
stream += header_size;
|
||||
stream_remaining -= header_size;
|
||||
switch (Command(header[0])) {
|
||||
const CommandHeader& header =
|
||||
*reinterpret_cast<const CommandHeader*>(stream);
|
||||
stream += kCommandHeaderSizeElements;
|
||||
stream_remaining -= kCommandHeaderSizeElements;
|
||||
switch (header.command) {
|
||||
case Command::kD3DClearUnorderedAccessViewUint: {
|
||||
auto& args =
|
||||
*reinterpret_cast<const ClearUnorderedAccessViewHeader*>(stream);
|
||||
@@ -121,7 +121,7 @@ void DeferredCommandList::Execute(ID3D12GraphicsCommandList* command_list,
|
||||
command_list->ResourceBarrier(
|
||||
*reinterpret_cast<const UINT*>(stream),
|
||||
reinterpret_cast<const D3D12_RESOURCE_BARRIER*>(
|
||||
stream +
|
||||
reinterpret_cast<const uint8_t*>(stream) +
|
||||
xe::align(sizeof(UINT), alignof(D3D12_RESOURCE_BARRIER))));
|
||||
} break;
|
||||
case Command::kRSSetScissorRect: {
|
||||
@@ -221,25 +221,26 @@ void DeferredCommandList::Execute(ID3D12GraphicsCommandList* command_list,
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
assert_unhandled_case(Command(header[0]));
|
||||
assert_unhandled_case(header.command);
|
||||
break;
|
||||
}
|
||||
stream += header[1];
|
||||
stream_remaining -= header[1];
|
||||
stream += header.arguments_size_elements;
|
||||
stream_remaining -= header.arguments_size_elements;
|
||||
}
|
||||
}
|
||||
|
||||
void* DeferredCommandList::WriteCommand(Command command,
|
||||
size_t arguments_size) {
|
||||
arguments_size = xe::align(arguments_size, kAlignment);
|
||||
const size_t header_size = xe::align(2 * sizeof(uint32_t), kAlignment);
|
||||
size_t arguments_size_bytes) {
|
||||
size_t arguments_size_elements =
|
||||
(arguments_size_bytes + sizeof(uintmax_t) - 1) / sizeof(uintmax_t);
|
||||
size_t offset = command_stream_.size();
|
||||
command_stream_.resize(offset + header_size + arguments_size);
|
||||
uint32_t* header =
|
||||
reinterpret_cast<uint32_t*>(command_stream_.data() + offset);
|
||||
header[0] = uint32_t(command);
|
||||
header[1] = uint32_t(arguments_size);
|
||||
return command_stream_.data() + (offset + header_size);
|
||||
command_stream_.resize(offset + kCommandHeaderSizeElements +
|
||||
arguments_size_elements);
|
||||
CommandHeader& header =
|
||||
*reinterpret_cast<CommandHeader*>(command_stream_.data() + offset);
|
||||
header.command = command;
|
||||
header.arguments_size_elements = uint32_t(arguments_size_elements);
|
||||
return command_stream_.data() + (offset + kCommandHeaderSizeElements);
|
||||
}
|
||||
|
||||
} // namespace d3d12
|
||||
|
||||
Reference in New Issue
Block a user