Example #1
0
void BBox::Bind()
{
	if (!s_bbox_buffer)
	{
		return;
	}
	if (s_bbox_cpu_dirty)
	{
		s_bbox_stream_buffer->AllocateSpaceInBuffer(BBOX_BUFFER_SIZE, BBOX_BUFFER_SIZE);
		// Allocate temporary bytes in upload buffer, then copy to real buffer.
		memcpy(s_bbox_stream_buffer->GetCPUAddressOfCurrentAllocation(), s_bbox_shadow_copy, BBOX_BUFFER_SIZE);
		D3D::ResourceBarrier(D3D::current_command_list, s_bbox_buffer, s_current_bbox_state, D3D12_RESOURCE_STATE_COPY_DEST, 0);
		s_current_bbox_state = D3D12_RESOURCE_STATE_COPY_DEST;
		D3D::current_command_list->CopyBufferRegion(s_bbox_buffer, 0, s_bbox_stream_buffer->GetBuffer(), s_bbox_stream_buffer->GetOffsetOfCurrentAllocation(), BBOX_BUFFER_SIZE);
		s_bbox_cpu_dirty = false;
	}
	D3D::ResourceBarrier(D3D::current_command_list, s_bbox_buffer, s_current_bbox_state, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, 0);
	s_current_bbox_state = D3D12_RESOURCE_STATE_UNORDERED_ACCESS;
	D3D::current_command_list->SetGraphicsRootDescriptorTable(DESCRIPTOR_TABLE_PS_UAV, s_bbox_descriptor_handle);
	s_bbox_gpu_dirty = true;
}
Example #2
0
void BBox::Set(int index, int value)
{
	// If the buffer is currently mapped, compare the value, and update the staging buffer.
	if (s_bbox_staging_buffer_map)
	{
		int current_value;
		memcpy(&current_value, reinterpret_cast<u8*>(s_bbox_staging_buffer_map) + (index * sizeof(int)), sizeof(int));
		if (current_value == value)
		{
			// Value hasn't changed. So skip updating completely.
			return;
		}

		memcpy(reinterpret_cast<u8*>(s_bbox_staging_buffer_map) + (index * sizeof(int)), &value, sizeof(int));
	}

	s_bbox_stream_buffer->AllocateSpaceInBuffer(sizeof(int), sizeof(int));

	// Allocate temporary bytes in upload buffer, then copy to real buffer.
	memcpy(s_bbox_stream_buffer->GetCPUAddressOfCurrentAllocation(), &value, sizeof(int));
	D3D::ResourceBarrier(D3D::current_command_list, s_bbox_buffer, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_COPY_DEST, 0);
	D3D::current_command_list->CopyBufferRegion(s_bbox_buffer, index * sizeof(int), s_bbox_stream_buffer->GetBuffer(), s_bbox_stream_buffer->GetOffsetOfCurrentAllocation(), sizeof(int));
	D3D::ResourceBarrier(D3D::current_command_list, s_bbox_buffer, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, 0);
}