mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 08:13:27 +00:00
Merge #3
3: Add struct for descriptor binding r=grovesNL a=msiglreith A bit more safety for API users to pass the correct values. Co-authored-by: msiglreith <m.siglreith@gmail.com>
This commit is contained in:
commit
4097a10997
@ -7,6 +7,11 @@ use {Blob, D3DResult, Error, TextureAddressMode};
|
|||||||
pub type CpuDescriptor = d3d12::D3D12_CPU_DESCRIPTOR_HANDLE;
|
pub type CpuDescriptor = d3d12::D3D12_CPU_DESCRIPTOR_HANDLE;
|
||||||
pub type GpuDescriptor = d3d12::D3D12_GPU_DESCRIPTOR_HANDLE;
|
pub type GpuDescriptor = d3d12::D3D12_GPU_DESCRIPTOR_HANDLE;
|
||||||
|
|
||||||
|
pub struct Binding {
|
||||||
|
pub register: u32,
|
||||||
|
pub space: u32,
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub enum HeapType {
|
pub enum HeapType {
|
||||||
@ -57,18 +62,12 @@ pub enum DescriptorRangeType {
|
|||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct DescriptorRange(d3d12::D3D12_DESCRIPTOR_RANGE);
|
pub struct DescriptorRange(d3d12::D3D12_DESCRIPTOR_RANGE);
|
||||||
impl DescriptorRange {
|
impl DescriptorRange {
|
||||||
pub fn new(
|
pub fn new(ty: DescriptorRangeType, count: u32, base_binding: Binding, offset: u32) -> Self {
|
||||||
ty: DescriptorRangeType,
|
|
||||||
count: u32,
|
|
||||||
base_register: u32,
|
|
||||||
register_space: u32,
|
|
||||||
offset: u32,
|
|
||||||
) -> Self {
|
|
||||||
DescriptorRange(d3d12::D3D12_DESCRIPTOR_RANGE {
|
DescriptorRange(d3d12::D3D12_DESCRIPTOR_RANGE {
|
||||||
RangeType: ty as _,
|
RangeType: ty as _,
|
||||||
NumDescriptors: count,
|
NumDescriptors: count,
|
||||||
BaseShaderRegister: base_register,
|
BaseShaderRegister: base_binding.register,
|
||||||
RegisterSpace: register_space,
|
RegisterSpace: base_binding.space,
|
||||||
OffsetInDescriptorsFromTableStart: offset,
|
OffsetInDescriptorsFromTableStart: offset,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -93,12 +92,7 @@ impl RootParameter {
|
|||||||
RootParameter(param)
|
RootParameter(param)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn constants(
|
pub fn constants(visibility: ShaderVisibility, binding: Binding, num: u32) -> Self {
|
||||||
visibility: ShaderVisibility,
|
|
||||||
register: u32,
|
|
||||||
register_space: u32,
|
|
||||||
num: u32,
|
|
||||||
) -> Self {
|
|
||||||
let mut param = d3d12::D3D12_ROOT_PARAMETER {
|
let mut param = d3d12::D3D12_ROOT_PARAMETER {
|
||||||
ParameterType: d3d12::D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS,
|
ParameterType: d3d12::D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS,
|
||||||
ShaderVisibility: visibility as _,
|
ShaderVisibility: visibility as _,
|
||||||
@ -106,8 +100,8 @@ impl RootParameter {
|
|||||||
};
|
};
|
||||||
|
|
||||||
*unsafe { param.u.Constants_mut() } = d3d12::D3D12_ROOT_CONSTANTS {
|
*unsafe { param.u.Constants_mut() } = d3d12::D3D12_ROOT_CONSTANTS {
|
||||||
ShaderRegister: register,
|
ShaderRegister: binding.register,
|
||||||
RegisterSpace: register_space,
|
RegisterSpace: binding.space,
|
||||||
Num32BitValues: num,
|
Num32BitValues: num,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -127,8 +121,7 @@ pub struct StaticSampler(d3d12::D3D12_STATIC_SAMPLER_DESC);
|
|||||||
impl StaticSampler {
|
impl StaticSampler {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
visibility: ShaderVisibility,
|
visibility: ShaderVisibility,
|
||||||
register: u32,
|
binding: Binding,
|
||||||
register_space: u32,
|
|
||||||
|
|
||||||
filter: d3d12::D3D12_FILTER,
|
filter: d3d12::D3D12_FILTER,
|
||||||
address_mode: TextureAddressMode,
|
address_mode: TextureAddressMode,
|
||||||
@ -149,8 +142,8 @@ impl StaticSampler {
|
|||||||
BorderColor: border_color as _,
|
BorderColor: border_color as _,
|
||||||
MinLOD: lod.start,
|
MinLOD: lod.start,
|
||||||
MaxLOD: lod.end,
|
MaxLOD: lod.end,
|
||||||
ShaderRegister: register,
|
ShaderRegister: binding.register,
|
||||||
RegisterSpace: register_space,
|
RegisterSpace: binding.space,
|
||||||
ShaderVisibility: visibility as _,
|
ShaderVisibility: visibility as _,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user