This commit is contained in:
Junkui Zhang 2025-07-15 23:28:25 +08:00
parent 34d5926ebd
commit a1c00ed87f
2 changed files with 24 additions and 72 deletions

View file

@ -58,7 +58,6 @@ struct DirectXGlobalElements {
global_params_buffer: [Option<ID3D11Buffer>; 1],
sampler: [Option<ID3D11SamplerState>; 1],
blend_state: ID3D11BlendState,
blend_state_for_pr: ID3D11BlendState,
}
#[repr(C)]
@ -601,13 +600,11 @@ impl DirectXGlobalElements {
};
let blend_state = create_blend_state(device)?;
let blend_state_for_pr = create_blend_state_for_path_raster(device)?;
Ok(Self {
global_params_buffer,
sampler,
blend_state,
blend_state_for_pr,
})
}
}
@ -849,7 +846,7 @@ fn set_rasterizer_state(device: &ID3D11Device, device_context: &ID3D11DeviceCont
let desc = D3D11_RASTERIZER_DESC {
FillMode: D3D11_FILL_SOLID,
CullMode: D3D11_CULL_NONE,
// CullMode: D3D11_CULL_BACK,
// FrontCounterClockwise: true.into(),
FrontCounterClockwise: false.into(),
DepthBias: 0,
DepthBiasClamp: 0.0,
@ -888,25 +885,6 @@ fn create_blend_state(device: &ID3D11Device) -> Result<ID3D11BlendState> {
}
}
fn create_blend_state_for_path_raster(device: &ID3D11Device) -> Result<ID3D11BlendState> {
// If the feature level is set to greater than D3D_FEATURE_LEVEL_9_3, the display
// device performs the blend in linear space, which is ideal.
let mut desc = D3D11_BLEND_DESC::default();
desc.RenderTarget[0].BlendEnable = true.into();
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
desc.RenderTarget[0].DestBlend = D3D11_BLEND_ONE;
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ONE;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL.0 as u8;
unsafe {
let mut state = None;
device.CreateBlendState(&desc, Some(&mut state))?;
Ok(state.unwrap())
}
}
fn create_pipieline(
device: &ID3D11Device,
vertex_entry: &str,
@ -989,13 +967,6 @@ fn create_buffer_view(
}
fn create_indirect_draw_buffer(device: &ID3D11Device, buffer_size: u32) -> Result<ID3D11Buffer> {
// let desc = D3D11_BUFFER_DESC {
// ByteWidth: std::mem::size_of::<DrawInstancedIndirectArgs>() as u32 * buffer_size,
// Usage: D3D11_USAGE_DYNAMIC,
// BindFlags: D3D11_BIND_INDIRECT_DRAW.0 as u32,
// MiscFlags: D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS.0 as u32,
// ..Default::default()
// };
let desc = D3D11_BUFFER_DESC {
ByteWidth: std::mem::size_of::<DrawInstancedIndirectArgs>() as u32 * buffer_size,
Usage: D3D11_USAGE_DYNAMIC,
@ -1173,20 +1144,6 @@ fn update_buffer<T>(
Ok(())
}
fn update_indirect_buffer(
device_context: &ID3D11DeviceContext,
buffer: &ID3D11Buffer,
data: &[DrawInstancedIndirectArgs],
) -> Result<()> {
unsafe {
let mut dest = std::mem::zeroed();
device_context.Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, Some(&mut dest))?;
std::ptr::copy_nonoverlapping(data.as_ptr(), dest.pData as _, data.len());
device_context.Unmap(buffer, 0);
}
Ok(())
}
fn prepare_indirect_draws(
device_context: &ID3D11DeviceContext,
pipeline: &PathsPipelineState,
@ -1314,7 +1271,6 @@ mod shader_resources {
&mut compile_blob,
Some(&mut error_blob),
);
println!("Shader compile result: {:?}", ret);
if ret.is_err() {
let Some(error_blob) = error_blob else {
return Err(anyhow::anyhow!("{ret:?}"));
@ -1325,8 +1281,8 @@ mod shader_resources {
string_len,
string_len,
);
let error_string = String::from_utf8_lossy(&error_string_encode);
println!("Shader compile error: {}", error_string);
let error_string = String::from_utf8_lossy(&error_string_encode).to_string();
log::error!("Shader compile error: {}", error_string);
return Err(anyhow::anyhow!("Compile error: {}", error_string));
}
Ok(compile_blob.unwrap())

View file

@ -461,9 +461,9 @@ struct Quad {
};
struct QuadVertexOutput {
nointerpolation uint quad_id: TEXCOORD0;
float4 position: SV_Position;
nointerpolation float4 border_color: COLOR0;
nointerpolation uint quad_id: TEXCOORD0;
nointerpolation float4 background_solid: COLOR1;
nointerpolation float4 background_color0: COLOR2;
nointerpolation float4 background_color1: COLOR3;
@ -512,9 +512,9 @@ float4 quad_fragment(QuadFragmentInput input): SV_Target {
input.background_solid, input.background_color0, input.background_color1);
bool unrounded = quad.corner_radii.top_left == 0.0 &&
quad.corner_radii.bottom_left == 0.0 &&
quad.corner_radii.top_right == 0.0 &&
quad.corner_radii.bottom_right == 0.0;
quad.corner_radii.top_right == 0.0 &&
quad.corner_radii.bottom_left == 0.0 &&
quad.corner_radii.bottom_right == 0.0;
// Fast path when the quad is not rounded and doesn't have any border
if (quad.border_widths.top == 0.0 &&
@ -796,19 +796,6 @@ float4 quad_fragment(QuadFragmentInput input): SV_Target {
**
*/
struct ShadowVertexOutput {
float4 position: SV_Position;
nointerpolation float4 color: COLOR;
nointerpolation uint shadow_id: TEXCOORD0;
float4 clip_distance: SV_ClipDistance;
};
struct ShadowFragmentInput {
float4 position: SV_Position;
float4 color: COLOR;
nointerpolation uint shadow_id: TEXCOORD0;
};
struct Shadow {
uint order;
float blur_radius;
@ -818,6 +805,19 @@ struct Shadow {
Hsla color;
};
struct ShadowVertexOutput {
nointerpolation uint shadow_id: TEXCOORD0;
float4 position: SV_Position;
nointerpolation float4 color: COLOR;
float4 clip_distance: SV_ClipDistance;
};
struct ShadowFragmentInput {
nointerpolation uint shadow_id: TEXCOORD0;
float4 position: SV_Position;
nointerpolation float4 color: COLOR;
};
StructuredBuffer<Shadow> shadows: register(t1);
ShadowVertexOutput shadow_vertex(uint vertex_id: SV_VertexID, uint shadow_id: SV_InstanceID) {
@ -950,16 +950,16 @@ struct Underline {
};
struct UnderlineVertexOutput {
nointerpolation uint underline_id: TEXCOORD0;
float4 position: SV_Position;
nointerpolation float4 color: COLOR;
nointerpolation uint underline_id: TEXCOORD0;
float4 clip_distance: SV_ClipDistance;
};
struct UnderlineFragmentInput {
nointerpolation uint underline_id: TEXCOORD0;
float4 position: SV_Position;
nointerpolation float4 color: COLOR;
nointerpolation uint underline_id: TEXCOORD0;
};
StructuredBuffer<Underline> underlines: register(t1);
@ -1075,16 +1075,16 @@ struct PolychromeSprite {
};
struct PolychromeSpriteVertexOutput {
nointerpolation uint sprite_id: TEXCOORD0;
float4 position: SV_Position;
float2 tile_position: POSITION;
nointerpolation uint sprite_id: TEXCOORD0;
float4 clip_distance: SV_ClipDistance;
};
struct PolychromeSpriteFragmentInput {
nointerpolation uint sprite_id: TEXCOORD0;
float4 position: SV_Position;
float2 tile_position: POSITION;
nointerpolation uint sprite_id: TEXCOORD0;
};
StructuredBuffer<PolychromeSprite> poly_sprites: register(t1);
@ -1115,10 +1115,6 @@ float4 polychrome_sprite_fragment(PolychromeSpriteFragmentInput input): SV_Targe
float3 grayscale = dot(color.rgb, GRAYSCALE_FACTORS);
color = float4(grayscale, sample.a);
}
// if ((sprite.grayscale & 0xFFu) != 0u) {
// float3 grayscale = dot(color.rgb, GRAYSCALE_FACTORS);
// color = float4(grayscale, sample.a);
// }
color.a *= sprite.opacity * saturate(0.5 - distance);
return color;
}