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,
|
&self,
|
||||||
desc: &crate::BufferDescriptor,
|
desc: &crate::BufferDescriptor,
|
||||||
) -> Result<super::Buffer, crate::DeviceError> {
|
) -> Result<super::Buffer, crate::DeviceError> {
|
||||||
let mut size = desc.size;
|
let alloc_size = if desc.usage.contains(wgt::BufferUses::UNIFORM) {
|
||||||
if desc.usage.contains(wgt::BufferUses::UNIFORM) {
|
desc.size
|
||||||
let align_mask = Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT as u64 - 1;
|
.next_multiple_of(Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT.into())
|
||||||
size = ((size - 1) | align_mask) + 1;
|
} else {
|
||||||
}
|
desc.size
|
||||||
|
};
|
||||||
|
|
||||||
let raw_desc = Direct3D12::D3D12_RESOURCE_DESC {
|
let raw_desc = Direct3D12::D3D12_RESOURCE_DESC {
|
||||||
Dimension: Direct3D12::D3D12_RESOURCE_DIMENSION_BUFFER,
|
Dimension: Direct3D12::D3D12_RESOURCE_DIMENSION_BUFFER,
|
||||||
Alignment: 0,
|
Alignment: 0,
|
||||||
Width: size,
|
Width: alloc_size,
|
||||||
Height: 1,
|
Height: 1,
|
||||||
DepthOrArraySize: 1,
|
DepthOrArraySize: 1,
|
||||||
MipLevels: 1,
|
MipLevels: 1,
|
||||||
@ -436,7 +437,7 @@ impl crate::Device for super::Device {
|
|||||||
|
|
||||||
Ok(super::Buffer {
|
Ok(super::Buffer {
|
||||||
resource,
|
resource,
|
||||||
size,
|
size: desc.size,
|
||||||
allocation,
|
allocation,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user