[dxvk] Cleaned up DxvkBufferSlice and added documentation

This commit is contained in:
Philip Rebohle 2018-01-18 18:50:44 +01:00
parent 6e6c290e01
commit 9334873188
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 73 additions and 40 deletions

View File

@ -684,7 +684,7 @@ namespace dxvk {
return; return;
if (((size == bufferSlice.length()) if (((size == bufferSlice.length())
&& (bufferSlice.memFlags() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))) { && (bufferSlice.buffer()->memFlags() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))) {
m_context->invalidateBuffer(bufferSlice.buffer()); m_context->invalidateBuffer(bufferSlice.buffer());
std::memcpy(bufferSlice.mapPtr(0), pSrcData, size); std::memcpy(bufferSlice.mapPtr(0), pSrcData, size);
} else { } else {

View File

@ -165,8 +165,16 @@ namespace dxvk {
* \brief Underlying buffer object * \brief Underlying buffer object
* \returns Underlying buffer object * \returns Underlying buffer object
*/ */
Rc<DxvkBuffer> buffer() const { const DxvkBufferCreateInfo& bufferInfo() const {
return m_buffer; return m_buffer->info();
}
/**
* \brief Backing resource
* \returns Backing resource
*/
Rc<DxvkResource> resource() const {
return m_buffer->resource();
} }
/** /**
@ -206,9 +214,6 @@ namespace dxvk {
DxvkBufferSlice() { } DxvkBufferSlice() { }
explicit DxvkBufferSlice(const Rc<DxvkBuffer>& buffer)
: DxvkBufferSlice(buffer, 0, buffer->info().size) { }
DxvkBufferSlice( DxvkBufferSlice(
const Rc<DxvkBuffer>& buffer, const Rc<DxvkBuffer>& buffer,
VkDeviceSize rangeOffset, VkDeviceSize rangeOffset,
@ -217,52 +222,80 @@ namespace dxvk {
m_offset(rangeOffset), m_offset(rangeOffset),
m_length(rangeLength) { } m_length(rangeLength) { }
bool defined() const { explicit DxvkBufferSlice(const Rc<DxvkBuffer>& buffer)
return m_buffer != nullptr; : DxvkBufferSlice(buffer, 0, buffer->info().size) { }
}
size_t offset() const { return m_offset; }
size_t length() const { return m_length; }
/**
* \brief Underlying buffer
* \returns The virtual buffer
*/
Rc<DxvkBuffer> buffer() const { Rc<DxvkBuffer> buffer() const {
return m_buffer; return m_buffer;
} }
Rc<DxvkResource> resource() const { /**
return m_buffer->resource(); * \brief Buffer info
*
* Retrieves the properties of the underlying
* virtual buffer. Should not be used directly
* by client APIs.
* \returns Buffer properties
*/
const DxvkBufferCreateInfo& bufferInfo() const {
return m_buffer->info();
} }
VkMemoryPropertyFlags memFlags() const { /**
return m_buffer != nullptr * \brief Checks whether the slice is valid
? m_buffer->memFlags() *
: 0; * A buffer slice that does not point to any virtual
} * buffer object is considered undefined and cannot
* be used for any operations.
size_t offset() const { * \returns \c true if the slice is defined
return m_offset; */
} bool defined() const {
return m_buffer != nullptr;
size_t length() const {
return m_length;
} }
/**
* \brief Physical slice
*
* Retrieves the physical slice that currently
* backs the virtual slice. This may change
* when the virtual buffer gets invalidated.
* \returns The physical buffer slice
*/
DxvkPhysicalBufferSlice physicalSlice() const { DxvkPhysicalBufferSlice physicalSlice() const {
return m_buffer->subSlice(m_offset, m_length); return m_buffer->subSlice(m_offset, m_length);
} }
/**
* \brief Pointer to mapped memory region
*
* \param [in] offset Offset into the slice
* \returns Pointer into mapped buffer memory
*/
void* mapPtr(VkDeviceSize offset) const { void* mapPtr(VkDeviceSize offset) const {
return m_buffer->mapPtr(m_offset + offset); return m_buffer->mapPtr(m_offset + offset);
} }
bool operator == (const DxvkBufferSlice& other) const { /**
* \brief Checks whether two slices are equal
*
* Two slices are considered equal if they point to
* the same memory region within the same buffer.
* \param [in] other The slice to compare to
* \returns \c true if the two slices are the same
*/
bool matches(const DxvkBufferSlice& other) const {
return this->m_buffer == other.m_buffer return this->m_buffer == other.m_buffer
&& this->m_offset == other.m_offset && this->m_offset == other.m_offset
&& this->m_length == other.m_length; && this->m_length == other.m_length;
} }
bool operator != (const DxvkBufferSlice& other) const {
return this->m_buffer != other.m_buffer
|| this->m_offset != other.m_offset
|| this->m_length != other.m_length;
}
private: private:
Rc<DxvkBuffer> m_buffer = nullptr; Rc<DxvkBuffer> m_buffer = nullptr;

View File

@ -65,8 +65,8 @@ namespace dxvk {
void DxvkContext::bindIndexBuffer( void DxvkContext::bindIndexBuffer(
const DxvkBufferSlice& buffer, const DxvkBufferSlice& buffer,
VkIndexType indexType) { VkIndexType indexType) {
if (m_state.vi.indexBuffer != buffer if (!m_state.vi.indexBuffer.matches(buffer)
|| m_state.vi.indexType != indexType) { || (m_state.vi.indexType != indexType)) {
m_state.vi.indexBuffer = buffer; m_state.vi.indexBuffer = buffer;
m_state.vi.indexType = indexType; m_state.vi.indexType = indexType;
@ -78,7 +78,7 @@ namespace dxvk {
void DxvkContext::bindResourceBuffer( void DxvkContext::bindResourceBuffer(
uint32_t slot, uint32_t slot,
const DxvkBufferSlice& buffer) { const DxvkBufferSlice& buffer) {
if (m_rc[slot].bufferSlice != buffer) { if (!m_rc[slot].bufferSlice.matches(buffer)) {
m_rc[slot].bufferSlice = buffer; m_rc[slot].bufferSlice = buffer;
m_flags.set( m_flags.set(
@ -164,7 +164,7 @@ namespace dxvk {
uint32_t binding, uint32_t binding,
const DxvkBufferSlice& buffer, const DxvkBufferSlice& buffer,
uint32_t stride) { uint32_t stride) {
if (m_state.vi.vertexBuffers[binding] != buffer) { if (!m_state.vi.vertexBuffers[binding].matches(buffer)) {
m_state.vi.vertexBuffers[binding] = buffer; m_state.vi.vertexBuffers[binding] = buffer;
m_flags.set(DxvkContextFlag::GpDirtyVertexBuffers); m_flags.set(DxvkContextFlag::GpDirtyVertexBuffers);
} }
@ -1126,7 +1126,7 @@ namespace dxvk {
m_descriptors[i].texelBuffer = res.bufferView->handle(); m_descriptors[i].texelBuffer = res.bufferView->handle();
m_cmd->trackResource(res.bufferView); m_cmd->trackResource(res.bufferView);
m_cmd->trackResource(res.bufferView->buffer()->resource()); m_cmd->trackResource(res.bufferView->resource());
} else { } else {
updatePipelineState |= bs.setUnbound(i); updatePipelineState |= bs.setUnbound(i);
} break; } break;
@ -1141,7 +1141,7 @@ namespace dxvk {
m_descriptors[i].buffer.offset = physicalSlice.offset(); m_descriptors[i].buffer.offset = physicalSlice.offset();
m_descriptors[i].buffer.range = physicalSlice.length(); m_descriptors[i].buffer.range = physicalSlice.length();
m_cmd->trackResource(res.bufferSlice.resource()); m_cmd->trackResource(physicalSlice.resource());
} else { } else {
updatePipelineState |= bs.setUnbound(i); updatePipelineState |= bs.setUnbound(i);
} break; } break;
@ -1299,16 +1299,16 @@ namespace dxvk {
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_READ_BIT |
VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_WRITE_BIT,
slot.bufferSlice.buffer()->info().stages, slot.bufferSlice.bufferInfo().stages,
slot.bufferSlice.buffer()->info().access); slot.bufferSlice.bufferInfo().access);
} else if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) { } else if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) {
m_barriers.accessBuffer( m_barriers.accessBuffer(
slot.bufferView->slice(), slot.bufferView->slice(),
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_READ_BIT |
VK_ACCESS_SHADER_WRITE_BIT, VK_ACCESS_SHADER_WRITE_BIT,
slot.bufferView->buffer()->info().stages, slot.bufferView->bufferInfo().stages,
slot.bufferView->buffer()->info().access); slot.bufferView->bufferInfo().access);
} else if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) { } else if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
m_barriers.accessImage( m_barriers.accessImage(
slot.imageView->image(), slot.imageView->image(),