mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[d3d12] fix size of buffer (#7310)
The buffer size was being aligned to `D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT` (256). The buffer size value is used as the binding size (when none is specified), causing `arrayLength()` to return values larger than what users of the API specified for the buffer size.
This commit is contained in:
parent
0386211b75
commit
9021d93b9f
@ -402,16 +402,17 @@ impl crate::Device for super::Device {
|
||||
&self,
|
||||
desc: &crate::BufferDescriptor,
|
||||
) -> Result<super::Buffer, crate::DeviceError> {
|
||||
let mut size = desc.size;
|
||||
if desc.usage.contains(wgt::BufferUses::UNIFORM) {
|
||||
let align_mask = Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT as u64 - 1;
|
||||
size = ((size - 1) | align_mask) + 1;
|
||||
}
|
||||
let alloc_size = if desc.usage.contains(wgt::BufferUses::UNIFORM) {
|
||||
desc.size
|
||||
.next_multiple_of(Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT.into())
|
||||
} else {
|
||||
desc.size
|
||||
};
|
||||
|
||||
let raw_desc = Direct3D12::D3D12_RESOURCE_DESC {
|
||||
Dimension: Direct3D12::D3D12_RESOURCE_DIMENSION_BUFFER,
|
||||
Alignment: 0,
|
||||
Width: size,
|
||||
Width: alloc_size,
|
||||
Height: 1,
|
||||
DepthOrArraySize: 1,
|
||||
MipLevels: 1,
|
||||
@ -436,7 +437,7 @@ impl crate::Device for super::Device {
|
||||
|
||||
Ok(super::Buffer {
|
||||
resource,
|
||||
size,
|
||||
size: desc.size,
|
||||
allocation,
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user