mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-01 07:24:12 +01:00
[dxvk] Cleaned up DxvkBufferSlice and added documentation
This commit is contained in:
parent
6e6c290e01
commit
9334873188
@ -684,7 +684,7 @@ namespace dxvk {
|
||||
return;
|
||||
|
||||
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());
|
||||
std::memcpy(bufferSlice.mapPtr(0), pSrcData, size);
|
||||
} else {
|
||||
|
@ -165,8 +165,16 @@ namespace dxvk {
|
||||
* \brief Underlying buffer object
|
||||
* \returns Underlying buffer object
|
||||
*/
|
||||
Rc<DxvkBuffer> buffer() const {
|
||||
return m_buffer;
|
||||
const DxvkBufferCreateInfo& bufferInfo() const {
|
||||
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() { }
|
||||
|
||||
explicit DxvkBufferSlice(const Rc<DxvkBuffer>& buffer)
|
||||
: DxvkBufferSlice(buffer, 0, buffer->info().size) { }
|
||||
|
||||
DxvkBufferSlice(
|
||||
const Rc<DxvkBuffer>& buffer,
|
||||
VkDeviceSize rangeOffset,
|
||||
@ -217,52 +222,80 @@ namespace dxvk {
|
||||
m_offset(rangeOffset),
|
||||
m_length(rangeLength) { }
|
||||
|
||||
bool defined() const {
|
||||
return m_buffer != nullptr;
|
||||
}
|
||||
explicit DxvkBufferSlice(const Rc<DxvkBuffer>& buffer)
|
||||
: 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 {
|
||||
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
|
||||
? m_buffer->memFlags()
|
||||
: 0;
|
||||
}
|
||||
|
||||
size_t offset() const {
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
size_t length() const {
|
||||
return m_length;
|
||||
/**
|
||||
* \brief Checks whether the slice is valid
|
||||
*
|
||||
* A buffer slice that does not point to any virtual
|
||||
* buffer object is considered undefined and cannot
|
||||
* be used for any operations.
|
||||
* \returns \c true if the slice is defined
|
||||
*/
|
||||
bool defined() const {
|
||||
return m_buffer != nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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 {
|
||||
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 {
|
||||
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
|
||||
&& this->m_offset == other.m_offset
|
||||
&& 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:
|
||||
|
||||
Rc<DxvkBuffer> m_buffer = nullptr;
|
||||
|
@ -65,8 +65,8 @@ namespace dxvk {
|
||||
void DxvkContext::bindIndexBuffer(
|
||||
const DxvkBufferSlice& buffer,
|
||||
VkIndexType indexType) {
|
||||
if (m_state.vi.indexBuffer != buffer
|
||||
|| m_state.vi.indexType != indexType) {
|
||||
if (!m_state.vi.indexBuffer.matches(buffer)
|
||||
|| (m_state.vi.indexType != indexType)) {
|
||||
m_state.vi.indexBuffer = buffer;
|
||||
m_state.vi.indexType = indexType;
|
||||
|
||||
@ -78,7 +78,7 @@ namespace dxvk {
|
||||
void DxvkContext::bindResourceBuffer(
|
||||
uint32_t slot,
|
||||
const DxvkBufferSlice& buffer) {
|
||||
if (m_rc[slot].bufferSlice != buffer) {
|
||||
if (!m_rc[slot].bufferSlice.matches(buffer)) {
|
||||
m_rc[slot].bufferSlice = buffer;
|
||||
|
||||
m_flags.set(
|
||||
@ -164,7 +164,7 @@ namespace dxvk {
|
||||
uint32_t binding,
|
||||
const DxvkBufferSlice& buffer,
|
||||
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_flags.set(DxvkContextFlag::GpDirtyVertexBuffers);
|
||||
}
|
||||
@ -1126,7 +1126,7 @@ namespace dxvk {
|
||||
m_descriptors[i].texelBuffer = res.bufferView->handle();
|
||||
|
||||
m_cmd->trackResource(res.bufferView);
|
||||
m_cmd->trackResource(res.bufferView->buffer()->resource());
|
||||
m_cmd->trackResource(res.bufferView->resource());
|
||||
} else {
|
||||
updatePipelineState |= bs.setUnbound(i);
|
||||
} break;
|
||||
@ -1141,7 +1141,7 @@ namespace dxvk {
|
||||
m_descriptors[i].buffer.offset = physicalSlice.offset();
|
||||
m_descriptors[i].buffer.range = physicalSlice.length();
|
||||
|
||||
m_cmd->trackResource(res.bufferSlice.resource());
|
||||
m_cmd->trackResource(physicalSlice.resource());
|
||||
} else {
|
||||
updatePipelineState |= bs.setUnbound(i);
|
||||
} break;
|
||||
@ -1299,16 +1299,16 @@ namespace dxvk {
|
||||
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_SHADER_READ_BIT |
|
||||
VK_ACCESS_SHADER_WRITE_BIT,
|
||||
slot.bufferSlice.buffer()->info().stages,
|
||||
slot.bufferSlice.buffer()->info().access);
|
||||
slot.bufferSlice.bufferInfo().stages,
|
||||
slot.bufferSlice.bufferInfo().access);
|
||||
} else if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) {
|
||||
m_barriers.accessBuffer(
|
||||
slot.bufferView->slice(),
|
||||
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
VK_ACCESS_SHADER_READ_BIT |
|
||||
VK_ACCESS_SHADER_WRITE_BIT,
|
||||
slot.bufferView->buffer()->info().stages,
|
||||
slot.bufferView->buffer()->info().access);
|
||||
slot.bufferView->bufferInfo().stages,
|
||||
slot.bufferView->bufferInfo().access);
|
||||
} else if (binding.type == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) {
|
||||
m_barriers.accessImage(
|
||||
slot.imageView->image(),
|
||||
|
Loading…
Reference in New Issue
Block a user