P4 to Git Change 1530931 by gandryey@gera-w8 on 2018/03/22 16:38:47

SWDEV-79445 - OCL generic changes and code clean-up
	- Prepare the changes to remove resource rename feature. Resource rename can substitute a low level memory object in the current resource with a different one in order to avoid GPU stalls on frequent CPU updates, like constant buffers or staging buffers. Renaming was necessary due to CAL and old HW limitations to manage suballocations and has some inefficiency with tiny updates and staging buffers.
	- This change removes renames usage from the constant buffer management

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palconstbuf.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palconstbuf.hpp#4 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palkernel.cpp#45 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#78 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#43 edit


[ROCm/clr commit: db04b3b295]
This commit is contained in:
foreman
2018-03-22 16:51:43 -04:00
parent b55f919e5a
commit 06c6754f72
5 changed files with 95 additions and 81 deletions
@@ -9,64 +9,75 @@
namespace pal {
ConstBuffer::ConstBuffer(VirtualGPU& gpu, size_t size)
: Memory(const_cast<pal::Device&>(gpu.dev()), size * VectorSize),
gpu_(gpu),
size_(size * VectorSize),
wrtOffset_(0),
lastWrtSize_(0),
wrtAddress_(nullptr) {}
// ================================================================================================
ManagedBuffer::ManagedBuffer(VirtualGPU& gpu, uint32_t size)
: gpu_(gpu)
, buffers_(MaxNumberOfBuffers)
, activeBuffer_(0)
, size_(size)
, wrtOffset_(0)
, lastWrtSize_(0)
, wrtAddress_(nullptr) {}
ConstBuffer::~ConstBuffer() {
if (wrtAddress_ != nullptr) {
unmap(&gpu_);
// ================================================================================================
ManagedBuffer::~ManagedBuffer() {
for (auto it : buffers_) {
if (it->data() != nullptr) {
it->unmap(&gpu_);
}
delete it;
}
amd::AlignedMemory::deallocate(sysMemCopy_);
}
bool ConstBuffer::create() {
// Create sysmem copy for the constant buffer
sysMemCopy_ = reinterpret_cast<address>(amd::AlignedMemory::allocate(size_, 256));
if (sysMemCopy_ == nullptr) {
LogPrintfError(
"We couldn't allocate sysmem copy for constant buffer,\
size(%d)!",
size_);
return false;
}
memset(sysMemCopy_, 0, size_);
if (!Memory::create(Resource::RemoteUSWC)) {
LogPrintfError("We couldn't create HW constant buffer, size(%d)!", size_);
return false;
// ================================================================================================
bool ManagedBuffer::create(Resource::MemoryType type, bool constbuf) {
if (constbuf) {
// Create sysmem copy for the constant buffer
sysMemCopy_ = reinterpret_cast<address>(amd::AlignedMemory::allocate(
gpu_.dev().info().maxParameterSize_, 256));
if (sysMemCopy_ == nullptr) {
LogPrintfError("We couldn't allocate sysmem copy for constant buffer, size(%d)!", size_);
return false;
}
memset(sysMemCopy_, 0, gpu_.dev().info().maxParameterSize_);
}
// Constant buffer warm-up
warmUpRenames(gpu_);
wrtAddress_ = map(&gpu_, Resource::Discard);
if (wrtAddress_ == nullptr) {
LogPrintfError("We couldn't map HW constant buffer, size(%d)!", size_);
return false;
for (uint i = 0; i < buffers_.size(); ++i) {
buffers_[i] = new Memory(const_cast<pal::Device&>(gpu_.dev()), size_);
if (nullptr == buffers_[i] || !buffers_[i]->create(type)) {
LogPrintfError("We couldn't create HW constant buffer, size(%d)!", size_);
return false;
}
void* wrtAddress = buffers_[i]->map(&gpu_);
if (wrtAddress == nullptr) {
LogPrintfError("We couldn't map HW constant buffer, size(%d)!", size_);
return false;
}
// Make sure OCL touches every buffer in the queue to avoid delays on the first submit
uint dummy = 0;
static constexpr bool Wait = true;
// Write 0 for the buffer paging by VidMM
buffers_[i]->writeRawData(gpu_, 0, sizeof(dummy), &dummy, Wait);
}
wrtAddress_ = buffers_[activeBuffer_]->data();
return true;
}
bool ConstBuffer::uploadDataToHw(size_t size) {
static const size_t HwCbAlignment = 256;
// ================================================================================================
bool ManagedBuffer::uploadDataToHw(uint32_t size) {
static constexpr uint32_t HwCbAlignment = 256;
// Align copy size on the vector's boundary
size_t count = amd::alignUp(size, VectorSize);
uint32_t count = amd::alignUp(size, 16);
wrtOffset_ += lastWrtSize_;
// Check if CB has enough space for copy
if ((wrtOffset_ + count) > size_) {
if (wrtAddress_ != nullptr) {
unmap(&gpu_);
}
wrtAddress_ = map(&gpu_, Resource::Discard);
activeBuffer_ = (++activeBuffer_) % MaxNumberOfBuffers;
//! Make sure buffer isn't busy
buffers_[activeBuffer_]->wait(gpu_);
wrtAddress_ = buffers_[activeBuffer_]->data();
wrtOffset_ = 0;
lastWrtSize_ = 0;
}