Compare commits
20 commits
main
...
v0.196.4-p
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5deb404135 | ||
![]() |
619282a8ed | ||
![]() |
3f32020785 | ||
![]() |
ce0de10147 | ||
![]() |
c9b9b3194e | ||
![]() |
eeb9e242b4 | ||
![]() |
f9c498318d | ||
![]() |
cb40bb755e | ||
![]() |
991887a3ea | ||
![]() |
f249ee481d | ||
![]() |
484e39dcba | ||
![]() |
ec7d6631a4 | ||
![]() |
27691613c1 | ||
![]() |
5f11e09a4b | ||
![]() |
34e63f9e55 | ||
![]() |
cbdca4e090 | ||
![]() |
92105e92c3 | ||
![]() |
632f09efd6 | ||
![]() |
192e0e32dd | ||
![]() |
30cc8bd824 |
36 changed files with 1831 additions and 759 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -2148,7 +2148,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blade-graphics"
|
name = "blade-graphics"
|
||||||
version = "0.6.0"
|
version = "0.6.0"
|
||||||
source = "git+https://github.com/kvark/blade?rev=416375211bb0b5826b3584dccdb6a43369e499ad#416375211bb0b5826b3584dccdb6a43369e499ad"
|
source = "git+https://github.com/kvark/blade?rev=e0ec4e720957edd51b945b64dd85605ea54bcfe5#e0ec4e720957edd51b945b64dd85605ea54bcfe5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ash",
|
"ash",
|
||||||
"ash-window",
|
"ash-window",
|
||||||
|
@ -2181,7 +2181,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blade-macros"
|
name = "blade-macros"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/kvark/blade?rev=416375211bb0b5826b3584dccdb6a43369e499ad#416375211bb0b5826b3584dccdb6a43369e499ad"
|
source = "git+https://github.com/kvark/blade?rev=e0ec4e720957edd51b945b64dd85605ea54bcfe5#e0ec4e720957edd51b945b64dd85605ea54bcfe5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -2191,7 +2191,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blade-util"
|
name = "blade-util"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
source = "git+https://github.com/kvark/blade?rev=416375211bb0b5826b3584dccdb6a43369e499ad#416375211bb0b5826b3584dccdb6a43369e499ad"
|
source = "git+https://github.com/kvark/blade?rev=e0ec4e720957edd51b945b64dd85605ea54bcfe5#e0ec4e720957edd51b945b64dd85605ea54bcfe5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"blade-graphics",
|
"blade-graphics",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
@ -14720,6 +14720,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"settings",
|
"settings",
|
||||||
|
"telemetry",
|
||||||
"theme",
|
"theme",
|
||||||
"tree-sitter-json",
|
"tree-sitter-json",
|
||||||
"tree-sitter-rust",
|
"tree-sitter-rust",
|
||||||
|
@ -16451,6 +16452,7 @@ dependencies = [
|
||||||
"schemars",
|
"schemars",
|
||||||
"serde",
|
"serde",
|
||||||
"settings",
|
"settings",
|
||||||
|
"settings_ui",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"story",
|
"story",
|
||||||
"telemetry",
|
"telemetry",
|
||||||
|
@ -20095,7 +20097,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.196.0"
|
version = "0.196.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activity_indicator",
|
"activity_indicator",
|
||||||
"agent",
|
"agent",
|
||||||
|
|
12
Cargo.toml
12
Cargo.toml
|
@ -434,9 +434,9 @@ aws-smithy-runtime-api = { version = "1.7.4", features = ["http-1x", "client"] }
|
||||||
aws-smithy-types = { version = "1.3.0", features = ["http-body-1-x"] }
|
aws-smithy-types = { version = "1.3.0", features = ["http-body-1-x"] }
|
||||||
base64 = "0.22"
|
base64 = "0.22"
|
||||||
bitflags = "2.6.0"
|
bitflags = "2.6.0"
|
||||||
blade-graphics = { git = "https://github.com/kvark/blade", rev = "416375211bb0b5826b3584dccdb6a43369e499ad" }
|
blade-graphics = { git = "https://github.com/kvark/blade", rev = "e0ec4e720957edd51b945b64dd85605ea54bcfe5" }
|
||||||
blade-macros = { git = "https://github.com/kvark/blade", rev = "416375211bb0b5826b3584dccdb6a43369e499ad" }
|
blade-macros = { git = "https://github.com/kvark/blade", rev = "e0ec4e720957edd51b945b64dd85605ea54bcfe5" }
|
||||||
blade-util = { git = "https://github.com/kvark/blade", rev = "416375211bb0b5826b3584dccdb6a43369e499ad" }
|
blade-util = { git = "https://github.com/kvark/blade", rev = "e0ec4e720957edd51b945b64dd85605ea54bcfe5" }
|
||||||
blake3 = "1.5.3"
|
blake3 = "1.5.3"
|
||||||
bytes = "1.0"
|
bytes = "1.0"
|
||||||
cargo_metadata = "0.19"
|
cargo_metadata = "0.19"
|
||||||
|
@ -489,7 +489,7 @@ json_dotpath = "1.1"
|
||||||
jsonschema = "0.30.0"
|
jsonschema = "0.30.0"
|
||||||
jsonwebtoken = "9.3"
|
jsonwebtoken = "9.3"
|
||||||
jupyter-protocol = { git = "https://github.com/ConradIrwin/runtimed", rev = "7130c804216b6914355d15d0b91ea91f6babd734" }
|
jupyter-protocol = { git = "https://github.com/ConradIrwin/runtimed", rev = "7130c804216b6914355d15d0b91ea91f6babd734" }
|
||||||
jupyter-websocket-client = { git = "https://github.com/ConradIrwin/runtimed", rev = "7130c804216b6914355d15d0b91ea91f6babd734" }
|
jupyter-websocket-client = { git = "https://github.com/ConradIrwin/runtimed" ,rev = "7130c804216b6914355d15d0b91ea91f6babd734" }
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
|
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
|
||||||
linkify = "0.10.0"
|
linkify = "0.10.0"
|
||||||
|
@ -500,7 +500,7 @@ metal = "0.29"
|
||||||
moka = { version = "0.12.10", features = ["sync"] }
|
moka = { version = "0.12.10", features = ["sync"] }
|
||||||
naga = { version = "25.0", features = ["wgsl-in"] }
|
naga = { version = "25.0", features = ["wgsl-in"] }
|
||||||
nanoid = "0.4"
|
nanoid = "0.4"
|
||||||
nbformat = { git = "https://github.com/ConradIrwin/runtimed", rev = "7130c804216b6914355d15d0b91ea91f6babd734" }
|
nbformat = { git = "https://github.com/ConradIrwin/runtimed", rev = "7130c804216b6914355d15d0b91ea91f6babd734" }
|
||||||
nix = "0.29"
|
nix = "0.29"
|
||||||
num-format = "0.4.4"
|
num-format = "0.4.4"
|
||||||
objc = "0.2"
|
objc = "0.2"
|
||||||
|
@ -541,7 +541,7 @@ reqwest = { git = "https://github.com/zed-industries/reqwest.git", rev = "951c77
|
||||||
"stream",
|
"stream",
|
||||||
] }
|
] }
|
||||||
rsa = "0.9.6"
|
rsa = "0.9.6"
|
||||||
runtimelib = { git = "https://github.com/ConradIrwin/runtimed", rev = "7130c804216b6914355d15d0b91ea91f6babd734", default-features = false, features = [
|
runtimelib = { git = "https://github.com/ConradIrwin/runtimed", rev = "7130c804216b6914355d15d0b91ea91f6babd734", default-features = false, features = [
|
||||||
"async-dispatcher-runtime",
|
"async-dispatcher-runtime",
|
||||||
] }
|
] }
|
||||||
rust-embed = { version = "8.4", features = ["include-exclude"] }
|
rust-embed = { version = "8.4", features = ["include-exclude"] }
|
||||||
|
|
|
@ -1118,7 +1118,9 @@
|
||||||
"ctrl-f": "search::FocusSearch",
|
"ctrl-f": "search::FocusSearch",
|
||||||
"alt-find": "keymap_editor::ToggleKeystrokeSearch",
|
"alt-find": "keymap_editor::ToggleKeystrokeSearch",
|
||||||
"alt-ctrl-f": "keymap_editor::ToggleKeystrokeSearch",
|
"alt-ctrl-f": "keymap_editor::ToggleKeystrokeSearch",
|
||||||
"alt-c": "keymap_editor::ToggleConflictFilter"
|
"alt-c": "keymap_editor::ToggleConflictFilter",
|
||||||
|
"enter": "keymap_editor::EditBinding",
|
||||||
|
"alt-enter": "keymap_editor::CreateBinding"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -1217,7 +1217,9 @@
|
||||||
"use_key_equivalents": true,
|
"use_key_equivalents": true,
|
||||||
"bindings": {
|
"bindings": {
|
||||||
"cmd-alt-f": "keymap_editor::ToggleKeystrokeSearch",
|
"cmd-alt-f": "keymap_editor::ToggleKeystrokeSearch",
|
||||||
"cmd-alt-c": "keymap_editor::ToggleConflictFilter"
|
"cmd-alt-c": "keymap_editor::ToggleConflictFilter",
|
||||||
|
"enter": "keymap_editor::EditBinding",
|
||||||
|
"alt-enter": "keymap_editor::CreateBinding"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -817,7 +817,7 @@
|
||||||
"edit_file": true,
|
"edit_file": true,
|
||||||
"fetch": true,
|
"fetch": true,
|
||||||
"list_directory": true,
|
"list_directory": true,
|
||||||
"project_notifications": true,
|
"project_notifications": false,
|
||||||
"move_path": true,
|
"move_path": true,
|
||||||
"now": true,
|
"now": true,
|
||||||
"find_path": true,
|
"find_path": true,
|
||||||
|
@ -837,7 +837,7 @@
|
||||||
"diagnostics": true,
|
"diagnostics": true,
|
||||||
"fetch": true,
|
"fetch": true,
|
||||||
"list_directory": true,
|
"list_directory": true,
|
||||||
"project_notifications": true,
|
"project_notifications": false,
|
||||||
"now": true,
|
"now": true,
|
||||||
"find_path": true,
|
"find_path": true,
|
||||||
"read_file": true,
|
"read_file": true,
|
||||||
|
|
|
@ -396,6 +396,7 @@ pub struct Thread {
|
||||||
remaining_turns: u32,
|
remaining_turns: u32,
|
||||||
configured_model: Option<ConfiguredModel>,
|
configured_model: Option<ConfiguredModel>,
|
||||||
profile: AgentProfile,
|
profile: AgentProfile,
|
||||||
|
last_error_context: Option<(Arc<dyn LanguageModel>, CompletionIntent)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -489,10 +490,11 @@ impl Thread {
|
||||||
retry_state: None,
|
retry_state: None,
|
||||||
message_feedback: HashMap::default(),
|
message_feedback: HashMap::default(),
|
||||||
last_auto_capture_at: None,
|
last_auto_capture_at: None,
|
||||||
|
last_error_context: None,
|
||||||
last_received_chunk_at: None,
|
last_received_chunk_at: None,
|
||||||
request_callback: None,
|
request_callback: None,
|
||||||
remaining_turns: u32::MAX,
|
remaining_turns: u32::MAX,
|
||||||
configured_model,
|
configured_model: configured_model.clone(),
|
||||||
profile: AgentProfile::new(profile_id, tools),
|
profile: AgentProfile::new(profile_id, tools),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -613,6 +615,7 @@ impl Thread {
|
||||||
feedback: None,
|
feedback: None,
|
||||||
message_feedback: HashMap::default(),
|
message_feedback: HashMap::default(),
|
||||||
last_auto_capture_at: None,
|
last_auto_capture_at: None,
|
||||||
|
last_error_context: None,
|
||||||
last_received_chunk_at: None,
|
last_received_chunk_at: None,
|
||||||
request_callback: None,
|
request_callback: None,
|
||||||
remaining_turns: u32::MAX,
|
remaining_turns: u32::MAX,
|
||||||
|
@ -1264,9 +1267,58 @@ impl Thread {
|
||||||
|
|
||||||
self.flush_notifications(model.clone(), intent, cx);
|
self.flush_notifications(model.clone(), intent, cx);
|
||||||
|
|
||||||
let request = self.to_completion_request(model.clone(), intent, cx);
|
let _checkpoint = self.finalize_pending_checkpoint(cx);
|
||||||
|
self.stream_completion(
|
||||||
|
self.to_completion_request(model.clone(), intent, cx),
|
||||||
|
model,
|
||||||
|
intent,
|
||||||
|
window,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
self.stream_completion(request, model, intent, window, cx);
|
pub fn retry_last_completion(
|
||||||
|
&mut self,
|
||||||
|
window: Option<AnyWindowHandle>,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
// Clear any existing error state
|
||||||
|
self.retry_state = None;
|
||||||
|
|
||||||
|
// Use the last error context if available, otherwise fall back to configured model
|
||||||
|
let (model, intent) = if let Some((model, intent)) = self.last_error_context.take() {
|
||||||
|
(model, intent)
|
||||||
|
} else if let Some(configured_model) = self.configured_model.as_ref() {
|
||||||
|
let model = configured_model.model.clone();
|
||||||
|
let intent = if self.has_pending_tool_uses() {
|
||||||
|
CompletionIntent::ToolResults
|
||||||
|
} else {
|
||||||
|
CompletionIntent::UserPrompt
|
||||||
|
};
|
||||||
|
(model, intent)
|
||||||
|
} else if let Some(configured_model) = self.get_or_init_configured_model(cx) {
|
||||||
|
let model = configured_model.model.clone();
|
||||||
|
let intent = if self.has_pending_tool_uses() {
|
||||||
|
CompletionIntent::ToolResults
|
||||||
|
} else {
|
||||||
|
CompletionIntent::UserPrompt
|
||||||
|
};
|
||||||
|
(model, intent)
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
self.send_to_model(model, intent, window, cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn enable_burn_mode_and_retry(
|
||||||
|
&mut self,
|
||||||
|
window: Option<AnyWindowHandle>,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) {
|
||||||
|
self.completion_mode = CompletionMode::Burn;
|
||||||
|
cx.emit(ThreadEvent::ProfileChanged);
|
||||||
|
self.retry_last_completion(window, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn used_tools_since_last_user_message(&self) -> bool {
|
pub fn used_tools_since_last_user_message(&self) -> bool {
|
||||||
|
@ -2146,6 +2198,35 @@ impl Thread {
|
||||||
max_attempts: MAX_RETRY_ATTEMPTS,
|
max_attempts: MAX_RETRY_ATTEMPTS,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
UpstreamProviderError {
|
||||||
|
status,
|
||||||
|
retry_after,
|
||||||
|
..
|
||||||
|
} => match *status {
|
||||||
|
StatusCode::TOO_MANY_REQUESTS | StatusCode::SERVICE_UNAVAILABLE => {
|
||||||
|
Some(RetryStrategy::Fixed {
|
||||||
|
delay: retry_after.unwrap_or(BASE_RETRY_DELAY),
|
||||||
|
max_attempts: MAX_RETRY_ATTEMPTS,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR => Some(RetryStrategy::Fixed {
|
||||||
|
delay: retry_after.unwrap_or(BASE_RETRY_DELAY),
|
||||||
|
// Internal Server Error could be anything, so only retry once.
|
||||||
|
max_attempts: 1,
|
||||||
|
}),
|
||||||
|
status => {
|
||||||
|
// There is no StatusCode variant for the unofficial HTTP 529 ("The service is overloaded"),
|
||||||
|
// but we frequently get them in practice. See https://http.dev/529
|
||||||
|
if status.as_u16() == 529 {
|
||||||
|
Some(RetryStrategy::Fixed {
|
||||||
|
delay: retry_after.unwrap_or(BASE_RETRY_DELAY),
|
||||||
|
max_attempts: MAX_RETRY_ATTEMPTS,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
ApiInternalServerError { .. } => Some(RetryStrategy::Fixed {
|
ApiInternalServerError { .. } => Some(RetryStrategy::Fixed {
|
||||||
delay: BASE_RETRY_DELAY,
|
delay: BASE_RETRY_DELAY,
|
||||||
max_attempts: 1,
|
max_attempts: 1,
|
||||||
|
@ -2193,6 +2274,23 @@ impl Thread {
|
||||||
window: Option<AnyWindowHandle>,
|
window: Option<AnyWindowHandle>,
|
||||||
cx: &mut Context<Self>,
|
cx: &mut Context<Self>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
|
// Store context for the Retry button
|
||||||
|
self.last_error_context = Some((model.clone(), intent));
|
||||||
|
|
||||||
|
// Only auto-retry if Burn Mode is enabled
|
||||||
|
if self.completion_mode != CompletionMode::Burn {
|
||||||
|
// Show error with retry options
|
||||||
|
cx.emit(ThreadEvent::ShowError(ThreadError::RetryableError {
|
||||||
|
message: format!(
|
||||||
|
"{}\n\nTo automatically retry when similar errors happen, enable Burn Mode.",
|
||||||
|
error
|
||||||
|
)
|
||||||
|
.into(),
|
||||||
|
can_enable_burn_mode: true,
|
||||||
|
}));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
let Some(strategy) = strategy.or_else(|| Self::get_retry_strategy(error)) else {
|
let Some(strategy) = strategy.or_else(|| Self::get_retry_strategy(error)) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -2273,6 +2371,13 @@ impl Thread {
|
||||||
// Stop generating since we're giving up on retrying.
|
// Stop generating since we're giving up on retrying.
|
||||||
self.pending_completions.clear();
|
self.pending_completions.clear();
|
||||||
|
|
||||||
|
// Show error alongside a Retry button, but no
|
||||||
|
// Enable Burn Mode button (since it's already enabled)
|
||||||
|
cx.emit(ThreadEvent::ShowError(ThreadError::RetryableError {
|
||||||
|
message: format!("Failed after retrying: {}", error).into(),
|
||||||
|
can_enable_burn_mode: false,
|
||||||
|
}));
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3183,6 +3288,11 @@ pub enum ThreadError {
|
||||||
header: SharedString,
|
header: SharedString,
|
||||||
message: SharedString,
|
message: SharedString,
|
||||||
},
|
},
|
||||||
|
#[error("Retryable error: {message}")]
|
||||||
|
RetryableError {
|
||||||
|
message: SharedString,
|
||||||
|
can_enable_burn_mode: bool,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -3583,6 +3693,7 @@ fn main() {{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
|
#[ignore] // turn this test on when project_notifications tool is re-enabled
|
||||||
async fn test_stale_buffer_notification(cx: &mut TestAppContext) {
|
async fn test_stale_buffer_notification(cx: &mut TestAppContext) {
|
||||||
init_test_settings(cx);
|
init_test_settings(cx);
|
||||||
|
|
||||||
|
@ -4137,6 +4248,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// Create model that returns overloaded error
|
// Create model that returns overloaded error
|
||||||
let model = Arc::new(ErrorInjector::new(TestError::Overloaded));
|
let model = Arc::new(ErrorInjector::new(TestError::Overloaded));
|
||||||
|
|
||||||
|
@ -4210,6 +4326,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// Create model that returns internal server error
|
// Create model that returns internal server error
|
||||||
let model = Arc::new(ErrorInjector::new(TestError::InternalServerError));
|
let model = Arc::new(ErrorInjector::new(TestError::InternalServerError));
|
||||||
|
|
||||||
|
@ -4286,6 +4407,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// Create model that returns internal server error
|
// Create model that returns internal server error
|
||||||
let model = Arc::new(ErrorInjector::new(TestError::InternalServerError));
|
let model = Arc::new(ErrorInjector::new(TestError::InternalServerError));
|
||||||
|
|
||||||
|
@ -4393,6 +4519,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// Create model that returns overloaded error
|
// Create model that returns overloaded error
|
||||||
let model = Arc::new(ErrorInjector::new(TestError::Overloaded));
|
let model = Arc::new(ErrorInjector::new(TestError::Overloaded));
|
||||||
|
|
||||||
|
@ -4479,6 +4610,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// We'll use a wrapper to switch behavior after first failure
|
// We'll use a wrapper to switch behavior after first failure
|
||||||
struct RetryTestModel {
|
struct RetryTestModel {
|
||||||
inner: Arc<FakeLanguageModel>,
|
inner: Arc<FakeLanguageModel>,
|
||||||
|
@ -4647,6 +4783,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// Create a model that fails once then succeeds
|
// Create a model that fails once then succeeds
|
||||||
struct FailOnceModel {
|
struct FailOnceModel {
|
||||||
inner: Arc<FakeLanguageModel>,
|
inner: Arc<FakeLanguageModel>,
|
||||||
|
@ -4808,6 +4949,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// Create a model that returns rate limit error with retry_after
|
// Create a model that returns rate limit error with retry_after
|
||||||
struct RateLimitModel {
|
struct RateLimitModel {
|
||||||
inner: Arc<FakeLanguageModel>,
|
inner: Arc<FakeLanguageModel>,
|
||||||
|
@ -5081,6 +5227,79 @@ fn main() {{
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_no_retry_without_burn_mode(cx: &mut TestAppContext) {
|
||||||
|
init_test_settings(cx);
|
||||||
|
|
||||||
|
let project = create_test_project(cx, json!({})).await;
|
||||||
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Ensure we're in Normal mode (not Burn mode)
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Normal);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Track error events
|
||||||
|
let error_events = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
let error_events_clone = error_events.clone();
|
||||||
|
|
||||||
|
let _subscription = thread.update(cx, |_, cx| {
|
||||||
|
cx.subscribe(&thread, move |_, _, event: &ThreadEvent, _| {
|
||||||
|
if let ThreadEvent::ShowError(error) = event {
|
||||||
|
error_events_clone.lock().push(error.clone());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create model that returns overloaded error
|
||||||
|
let model = Arc::new(ErrorInjector::new(TestError::Overloaded));
|
||||||
|
|
||||||
|
// Insert a user message
|
||||||
|
thread.update(cx, |thread, cx| {
|
||||||
|
thread.insert_user_message("Hello!", ContextLoadResult::default(), None, vec![], cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start completion
|
||||||
|
thread.update(cx, |thread, cx| {
|
||||||
|
thread.send_to_model(model.clone(), CompletionIntent::UserPrompt, None, cx);
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
// Verify no retry state was created
|
||||||
|
thread.read_with(cx, |thread, _| {
|
||||||
|
assert!(
|
||||||
|
thread.retry_state.is_none(),
|
||||||
|
"Should not have retry state in Normal mode"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check that a retryable error was reported
|
||||||
|
let errors = error_events.lock();
|
||||||
|
assert!(!errors.is_empty(), "Should have received an error event");
|
||||||
|
|
||||||
|
if let ThreadError::RetryableError {
|
||||||
|
message: _,
|
||||||
|
can_enable_burn_mode,
|
||||||
|
} = &errors[0]
|
||||||
|
{
|
||||||
|
assert!(
|
||||||
|
*can_enable_burn_mode,
|
||||||
|
"Error should indicate burn mode can be enabled"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
panic!("Expected RetryableError, got {:?}", errors[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify the thread is no longer generating
|
||||||
|
thread.read_with(cx, |thread, _| {
|
||||||
|
assert!(
|
||||||
|
!thread.is_generating(),
|
||||||
|
"Should not be generating after error without retry"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_retry_cancelled_on_stop(cx: &mut TestAppContext) {
|
async fn test_retry_cancelled_on_stop(cx: &mut TestAppContext) {
|
||||||
init_test_settings(cx);
|
init_test_settings(cx);
|
||||||
|
@ -5088,6 +5307,11 @@ fn main() {{
|
||||||
let project = create_test_project(cx, json!({})).await;
|
let project = create_test_project(cx, json!({})).await;
|
||||||
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
let (_, _, thread, _, _base_model) = setup_test_environment(cx, project.clone()).await;
|
||||||
|
|
||||||
|
// Enable Burn Mode to allow retries
|
||||||
|
thread.update(cx, |thread, _| {
|
||||||
|
thread.set_completion_mode(CompletionMode::Burn);
|
||||||
|
});
|
||||||
|
|
||||||
// Create model that returns overloaded error
|
// Create model that returns overloaded error
|
||||||
let model = Arc::new(ErrorInjector::new(TestError::Overloaded));
|
let model = Arc::new(ErrorInjector::new(TestError::Overloaded));
|
||||||
|
|
||||||
|
|
|
@ -1036,7 +1036,7 @@ impl ActiveThread {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n");
|
.join("\n");
|
||||||
self.last_error = Some(ThreadError::Message {
|
self.last_error = Some(ThreadError::Message {
|
||||||
header: "Error interacting with language model".into(),
|
header: "Error".into(),
|
||||||
message: error_message.into(),
|
message: error_message.into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,8 +64,9 @@ use theme::ThemeSettings;
|
||||||
use time::UtcOffset;
|
use time::UtcOffset;
|
||||||
use ui::utils::WithRemSize;
|
use ui::utils::WithRemSize;
|
||||||
use ui::{
|
use ui::{
|
||||||
Banner, Callout, CheckboxWithLabel, ContextMenu, ElevationIndex, KeyBinding, PopoverMenu,
|
Banner, Button, Callout, CheckboxWithLabel, ContextMenu, ElevationIndex, IconPosition,
|
||||||
PopoverMenuHandle, ProgressBar, Tab, Tooltip, Vector, VectorName, prelude::*,
|
KeyBinding, PopoverMenu, PopoverMenuHandle, ProgressBar, Tab, Tooltip, Vector, VectorName,
|
||||||
|
prelude::*,
|
||||||
};
|
};
|
||||||
use util::ResultExt as _;
|
use util::ResultExt as _;
|
||||||
use workspace::{
|
use workspace::{
|
||||||
|
@ -2913,6 +2914,21 @@ impl AgentPanel {
|
||||||
.size(IconSize::Small)
|
.size(IconSize::Small)
|
||||||
.color(Color::Error);
|
.color(Color::Error);
|
||||||
|
|
||||||
|
let retry_button = Button::new("retry", "Retry")
|
||||||
|
.icon(IconName::RotateCw)
|
||||||
|
.icon_position(IconPosition::Start)
|
||||||
|
.on_click({
|
||||||
|
let thread = thread.clone();
|
||||||
|
move |_, window, cx| {
|
||||||
|
thread.update(cx, |thread, cx| {
|
||||||
|
thread.clear_last_error();
|
||||||
|
thread.thread().update(cx, |thread, cx| {
|
||||||
|
thread.retry_last_completion(Some(window.window_handle()), cx);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
div()
|
div()
|
||||||
.border_t_1()
|
.border_t_1()
|
||||||
.border_color(cx.theme().colors().border)
|
.border_color(cx.theme().colors().border)
|
||||||
|
@ -2921,13 +2937,72 @@ impl AgentPanel {
|
||||||
.icon(icon)
|
.icon(icon)
|
||||||
.title(header)
|
.title(header)
|
||||||
.description(message.clone())
|
.description(message.clone())
|
||||||
.primary_action(self.dismiss_error_button(thread, cx))
|
.primary_action(retry_button)
|
||||||
.secondary_action(self.create_copy_button(message_with_header))
|
.secondary_action(self.dismiss_error_button(thread, cx))
|
||||||
|
.tertiary_action(self.create_copy_button(message_with_header))
|
||||||
.bg_color(self.error_callout_bg(cx)),
|
.bg_color(self.error_callout_bg(cx)),
|
||||||
)
|
)
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_retryable_error(
|
||||||
|
&self,
|
||||||
|
message: SharedString,
|
||||||
|
can_enable_burn_mode: bool,
|
||||||
|
thread: &Entity<ActiveThread>,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) -> AnyElement {
|
||||||
|
let icon = Icon::new(IconName::XCircle)
|
||||||
|
.size(IconSize::Small)
|
||||||
|
.color(Color::Error);
|
||||||
|
|
||||||
|
let retry_button = Button::new("retry", "Retry")
|
||||||
|
.icon(IconName::RotateCw)
|
||||||
|
.icon_position(IconPosition::Start)
|
||||||
|
.on_click({
|
||||||
|
let thread = thread.clone();
|
||||||
|
move |_, window, cx| {
|
||||||
|
thread.update(cx, |thread, cx| {
|
||||||
|
thread.clear_last_error();
|
||||||
|
thread.thread().update(cx, |thread, cx| {
|
||||||
|
thread.retry_last_completion(Some(window.window_handle()), cx);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut callout = Callout::new()
|
||||||
|
.icon(icon)
|
||||||
|
.title("Error")
|
||||||
|
.description(message.clone())
|
||||||
|
.bg_color(self.error_callout_bg(cx))
|
||||||
|
.primary_action(retry_button);
|
||||||
|
|
||||||
|
if can_enable_burn_mode {
|
||||||
|
let burn_mode_button = Button::new("enable_burn_retry", "Enable Burn Mode and Retry")
|
||||||
|
.icon(IconName::ZedBurnMode)
|
||||||
|
.icon_position(IconPosition::Start)
|
||||||
|
.on_click({
|
||||||
|
let thread = thread.clone();
|
||||||
|
move |_, window, cx| {
|
||||||
|
thread.update(cx, |thread, cx| {
|
||||||
|
thread.clear_last_error();
|
||||||
|
thread.thread().update(cx, |thread, cx| {
|
||||||
|
thread.enable_burn_mode_and_retry(Some(window.window_handle()), cx);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
callout = callout.secondary_action(burn_mode_button);
|
||||||
|
}
|
||||||
|
|
||||||
|
div()
|
||||||
|
.border_t_1()
|
||||||
|
.border_color(cx.theme().colors().border)
|
||||||
|
.child(callout)
|
||||||
|
.into_any_element()
|
||||||
|
}
|
||||||
|
|
||||||
fn render_prompt_editor(
|
fn render_prompt_editor(
|
||||||
&self,
|
&self,
|
||||||
context_editor: &Entity<TextThreadEditor>,
|
context_editor: &Entity<TextThreadEditor>,
|
||||||
|
@ -3169,6 +3244,15 @@ impl Render for AgentPanel {
|
||||||
ThreadError::Message { header, message } => {
|
ThreadError::Message { header, message } => {
|
||||||
self.render_error_message(header, message, thread, cx)
|
self.render_error_message(header, message, thread, cx)
|
||||||
}
|
}
|
||||||
|
ThreadError::RetryableError {
|
||||||
|
message,
|
||||||
|
can_enable_burn_mode,
|
||||||
|
} => self.render_retryable_error(
|
||||||
|
message,
|
||||||
|
can_enable_burn_mode,
|
||||||
|
thread,
|
||||||
|
cx,
|
||||||
|
),
|
||||||
})
|
})
|
||||||
.into_any(),
|
.into_any(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,6 +12,7 @@ use collections::HashMap;
|
||||||
use fs::FakeFs;
|
use fs::FakeFs;
|
||||||
use futures::{FutureExt, future::LocalBoxFuture};
|
use futures::{FutureExt, future::LocalBoxFuture};
|
||||||
use gpui::{AppContext, TestAppContext, Timer};
|
use gpui::{AppContext, TestAppContext, Timer};
|
||||||
|
use http_client::StatusCode;
|
||||||
use indoc::{formatdoc, indoc};
|
use indoc::{formatdoc, indoc};
|
||||||
use language_model::{
|
use language_model::{
|
||||||
LanguageModelRegistry, LanguageModelRequestTool, LanguageModelToolResult,
|
LanguageModelRegistry, LanguageModelRequestTool, LanguageModelToolResult,
|
||||||
|
@ -1675,6 +1676,30 @@ async fn retry_on_rate_limit<R>(mut request: impl AsyncFnMut() -> Result<R>) ->
|
||||||
Timer::after(retry_after + jitter).await;
|
Timer::after(retry_after + jitter).await;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
LanguageModelCompletionError::UpstreamProviderError {
|
||||||
|
status,
|
||||||
|
retry_after,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
// Only retry for specific status codes
|
||||||
|
let should_retry = matches!(
|
||||||
|
*status,
|
||||||
|
StatusCode::TOO_MANY_REQUESTS | StatusCode::SERVICE_UNAVAILABLE
|
||||||
|
) || status.as_u16() == 529;
|
||||||
|
|
||||||
|
if !should_retry {
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use server-provided retry_after if available, otherwise use default
|
||||||
|
let retry_after = retry_after.unwrap_or(Duration::from_secs(5));
|
||||||
|
let jitter = retry_after.mul_f64(rand::thread_rng().gen_range(0.0..1.0));
|
||||||
|
eprintln!(
|
||||||
|
"Attempt #{attempt}: {err}. Retry after {retry_after:?} + jitter of {jitter:?}"
|
||||||
|
);
|
||||||
|
Timer::after(retry_after + jitter).await;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ => return Err(err.into()),
|
_ => return Err(err.into()),
|
||||||
},
|
},
|
||||||
Err(err) => return Err(err),
|
Err(err) => return Err(err),
|
||||||
|
|
|
@ -126,7 +126,7 @@ mod macos {
|
||||||
"ContentMask".into(),
|
"ContentMask".into(),
|
||||||
"Uniforms".into(),
|
"Uniforms".into(),
|
||||||
"AtlasTile".into(),
|
"AtlasTile".into(),
|
||||||
"PathInputIndex".into(),
|
"PathRasterizationInputIndex".into(),
|
||||||
"PathVertex_ScaledPixels".into(),
|
"PathVertex_ScaledPixels".into(),
|
||||||
"ShadowInputIndex".into(),
|
"ShadowInputIndex".into(),
|
||||||
"Shadow".into(),
|
"Shadow".into(),
|
||||||
|
|
|
@ -1,13 +1,9 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
Application, Background, Bounds, ColorSpace, Context, MouseDownEvent, Path, PathBuilder,
|
Application, Background, Bounds, ColorSpace, Context, MouseDownEvent, Path, PathBuilder,
|
||||||
PathStyle, Pixels, Point, Render, SharedString, StrokeOptions, Window, WindowBounds,
|
PathStyle, Pixels, Point, Render, SharedString, StrokeOptions, Window, WindowOptions, canvas,
|
||||||
WindowOptions, canvas, div, linear_color_stop, linear_gradient, point, prelude::*, px, rgb,
|
div, linear_color_stop, linear_gradient, point, prelude::*, px, rgb, size,
|
||||||
size,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const DEFAULT_WINDOW_WIDTH: Pixels = px(1024.0);
|
|
||||||
const DEFAULT_WINDOW_HEIGHT: Pixels = px(768.0);
|
|
||||||
|
|
||||||
struct PaintingViewer {
|
struct PaintingViewer {
|
||||||
default_lines: Vec<(Path<Pixels>, Background)>,
|
default_lines: Vec<(Path<Pixels>, Background)>,
|
||||||
lines: Vec<Vec<Point<Pixels>>>,
|
lines: Vec<Vec<Point<Pixels>>>,
|
||||||
|
@ -151,6 +147,8 @@ impl PaintingViewer {
|
||||||
px(320.0 + (i as f32 * 10.0).sin() * 40.0),
|
px(320.0 + (i as f32 * 10.0).sin() * 40.0),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
let path = builder.build().unwrap();
|
||||||
|
lines.push((path, gpui::green().into()));
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
default_lines: lines.clone(),
|
default_lines: lines.clone(),
|
||||||
|
@ -185,13 +183,9 @@ fn button(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Render for PaintingViewer {
|
impl Render for PaintingViewer {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
window.request_animation_frame();
|
|
||||||
|
|
||||||
let default_lines = self.default_lines.clone();
|
let default_lines = self.default_lines.clone();
|
||||||
let lines = self.lines.clone();
|
let lines = self.lines.clone();
|
||||||
let window_size = window.bounds().size;
|
|
||||||
let scale = window_size.width / DEFAULT_WINDOW_WIDTH;
|
|
||||||
let dashed = self.dashed;
|
let dashed = self.dashed;
|
||||||
|
|
||||||
div()
|
div()
|
||||||
|
@ -228,7 +222,7 @@ impl Render for PaintingViewer {
|
||||||
move |_, _, _| {},
|
move |_, _, _| {},
|
||||||
move |_, _, window, _| {
|
move |_, _, window, _| {
|
||||||
for (path, color) in default_lines {
|
for (path, color) in default_lines {
|
||||||
window.paint_path(path.clone().scale(scale), color);
|
window.paint_path(path, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
for points in lines {
|
for points in lines {
|
||||||
|
@ -304,11 +298,6 @@ fn main() {
|
||||||
cx.open_window(
|
cx.open_window(
|
||||||
WindowOptions {
|
WindowOptions {
|
||||||
focus: true,
|
focus: true,
|
||||||
window_bounds: Some(WindowBounds::Windowed(Bounds::centered(
|
|
||||||
None,
|
|
||||||
size(DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT),
|
|
||||||
cx,
|
|
||||||
))),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|window, cx| cx.new(|cx| PaintingViewer::new(window, cx)),
|
|window, cx| cx.new(|cx| PaintingViewer::new(window, cx)),
|
||||||
|
|
|
@ -336,7 +336,10 @@ impl PathBuilder {
|
||||||
let v1 = buf.vertices[i1];
|
let v1 = buf.vertices[i1];
|
||||||
let v2 = buf.vertices[i2];
|
let v2 = buf.vertices[i2];
|
||||||
|
|
||||||
path.push_triangle((v0.into(), v1.into(), v2.into()));
|
path.push_triangle(
|
||||||
|
(v0.into(), v1.into(), v2.into()),
|
||||||
|
(point(0., 1.), point(0., 1.), point(0., 1.)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
path
|
path
|
||||||
|
|
|
@ -794,6 +794,7 @@ pub(crate) struct AtlasTextureId {
|
||||||
pub(crate) enum AtlasTextureKind {
|
pub(crate) enum AtlasTextureKind {
|
||||||
Monochrome = 0,
|
Monochrome = 0,
|
||||||
Polychrome = 1,
|
Polychrome = 1,
|
||||||
|
Path = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
|
|
@ -10,6 +10,8 @@ use etagere::BucketedAtlasAllocator;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::{borrow::Cow, ops, sync::Arc};
|
use std::{borrow::Cow, ops, sync::Arc};
|
||||||
|
|
||||||
|
pub(crate) const PATH_TEXTURE_FORMAT: gpu::TextureFormat = gpu::TextureFormat::R16Float;
|
||||||
|
|
||||||
pub(crate) struct BladeAtlas(Mutex<BladeAtlasState>);
|
pub(crate) struct BladeAtlas(Mutex<BladeAtlasState>);
|
||||||
|
|
||||||
struct PendingUpload {
|
struct PendingUpload {
|
||||||
|
@ -25,6 +27,7 @@ struct BladeAtlasState {
|
||||||
tiles_by_key: FxHashMap<AtlasKey, AtlasTile>,
|
tiles_by_key: FxHashMap<AtlasKey, AtlasTile>,
|
||||||
initializations: Vec<AtlasTextureId>,
|
initializations: Vec<AtlasTextureId>,
|
||||||
uploads: Vec<PendingUpload>,
|
uploads: Vec<PendingUpload>,
|
||||||
|
path_sample_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(gles)]
|
#[cfg(gles)]
|
||||||
|
@ -38,13 +41,13 @@ impl BladeAtlasState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BladeTextureInfo {
|
pub struct BladeTextureInfo {
|
||||||
#[allow(dead_code)]
|
|
||||||
pub size: gpu::Extent,
|
pub size: gpu::Extent,
|
||||||
pub raw_view: gpu::TextureView,
|
pub raw_view: gpu::TextureView,
|
||||||
|
pub msaa_view: Option<gpu::TextureView>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BladeAtlas {
|
impl BladeAtlas {
|
||||||
pub(crate) fn new(gpu: &Arc<gpu::Context>) -> Self {
|
pub(crate) fn new(gpu: &Arc<gpu::Context>, path_sample_count: u32) -> Self {
|
||||||
BladeAtlas(Mutex::new(BladeAtlasState {
|
BladeAtlas(Mutex::new(BladeAtlasState {
|
||||||
gpu: Arc::clone(gpu),
|
gpu: Arc::clone(gpu),
|
||||||
upload_belt: BufferBelt::new(BufferBeltDescriptor {
|
upload_belt: BufferBelt::new(BufferBeltDescriptor {
|
||||||
|
@ -56,6 +59,7 @@ impl BladeAtlas {
|
||||||
tiles_by_key: Default::default(),
|
tiles_by_key: Default::default(),
|
||||||
initializations: Vec::new(),
|
initializations: Vec::new(),
|
||||||
uploads: Vec::new(),
|
uploads: Vec::new(),
|
||||||
|
path_sample_count,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +67,6 @@ impl BladeAtlas {
|
||||||
self.0.lock().destroy();
|
self.0.lock().destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn clear_textures(&self, texture_kind: AtlasTextureKind) {
|
pub(crate) fn clear_textures(&self, texture_kind: AtlasTextureKind) {
|
||||||
let mut lock = self.0.lock();
|
let mut lock = self.0.lock();
|
||||||
let textures = &mut lock.storage[texture_kind];
|
let textures = &mut lock.storage[texture_kind];
|
||||||
|
@ -72,6 +75,19 @@ impl BladeAtlas {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allocate a rectangle and make it available for rendering immediately (without waiting for `before_frame`)
|
||||||
|
pub fn allocate_for_rendering(
|
||||||
|
&self,
|
||||||
|
size: Size<DevicePixels>,
|
||||||
|
texture_kind: AtlasTextureKind,
|
||||||
|
gpu_encoder: &mut gpu::CommandEncoder,
|
||||||
|
) -> AtlasTile {
|
||||||
|
let mut lock = self.0.lock();
|
||||||
|
let tile = lock.allocate(size, texture_kind);
|
||||||
|
lock.flush_initializations(gpu_encoder);
|
||||||
|
tile
|
||||||
|
}
|
||||||
|
|
||||||
pub fn before_frame(&self, gpu_encoder: &mut gpu::CommandEncoder) {
|
pub fn before_frame(&self, gpu_encoder: &mut gpu::CommandEncoder) {
|
||||||
let mut lock = self.0.lock();
|
let mut lock = self.0.lock();
|
||||||
lock.flush(gpu_encoder);
|
lock.flush(gpu_encoder);
|
||||||
|
@ -93,6 +109,7 @@ impl BladeAtlas {
|
||||||
depth: 1,
|
depth: 1,
|
||||||
},
|
},
|
||||||
raw_view: texture.raw_view,
|
raw_view: texture.raw_view,
|
||||||
|
msaa_view: texture.msaa_view,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,8 +200,48 @@ impl BladeAtlasState {
|
||||||
format = gpu::TextureFormat::Bgra8UnormSrgb;
|
format = gpu::TextureFormat::Bgra8UnormSrgb;
|
||||||
usage = gpu::TextureUsage::COPY | gpu::TextureUsage::RESOURCE;
|
usage = gpu::TextureUsage::COPY | gpu::TextureUsage::RESOURCE;
|
||||||
}
|
}
|
||||||
|
AtlasTextureKind::Path => {
|
||||||
|
format = PATH_TEXTURE_FORMAT;
|
||||||
|
usage = gpu::TextureUsage::COPY
|
||||||
|
| gpu::TextureUsage::RESOURCE
|
||||||
|
| gpu::TextureUsage::TARGET;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We currently only enable MSAA for path textures.
|
||||||
|
let (msaa, msaa_view) = if self.path_sample_count > 1 && kind == AtlasTextureKind::Path {
|
||||||
|
let msaa = self.gpu.create_texture(gpu::TextureDesc {
|
||||||
|
name: "msaa path texture",
|
||||||
|
format,
|
||||||
|
size: gpu::Extent {
|
||||||
|
width: size.width.into(),
|
||||||
|
height: size.height.into(),
|
||||||
|
depth: 1,
|
||||||
|
},
|
||||||
|
array_layer_count: 1,
|
||||||
|
mip_level_count: 1,
|
||||||
|
sample_count: self.path_sample_count,
|
||||||
|
dimension: gpu::TextureDimension::D2,
|
||||||
|
usage: gpu::TextureUsage::TARGET,
|
||||||
|
external: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
(
|
||||||
|
Some(msaa),
|
||||||
|
Some(self.gpu.create_texture_view(
|
||||||
|
msaa,
|
||||||
|
gpu::TextureViewDesc {
|
||||||
|
name: "msaa texture view",
|
||||||
|
format,
|
||||||
|
dimension: gpu::ViewDimension::D2,
|
||||||
|
subresources: &Default::default(),
|
||||||
|
},
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(None, None)
|
||||||
|
};
|
||||||
|
|
||||||
let raw = self.gpu.create_texture(gpu::TextureDesc {
|
let raw = self.gpu.create_texture(gpu::TextureDesc {
|
||||||
name: "atlas",
|
name: "atlas",
|
||||||
format,
|
format,
|
||||||
|
@ -222,6 +279,8 @@ impl BladeAtlasState {
|
||||||
format,
|
format,
|
||||||
raw,
|
raw,
|
||||||
raw_view,
|
raw_view,
|
||||||
|
msaa,
|
||||||
|
msaa_view,
|
||||||
live_atlas_keys: 0,
|
live_atlas_keys: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -281,6 +340,7 @@ impl BladeAtlasState {
|
||||||
struct BladeAtlasStorage {
|
struct BladeAtlasStorage {
|
||||||
monochrome_textures: AtlasTextureList<BladeAtlasTexture>,
|
monochrome_textures: AtlasTextureList<BladeAtlasTexture>,
|
||||||
polychrome_textures: AtlasTextureList<BladeAtlasTexture>,
|
polychrome_textures: AtlasTextureList<BladeAtlasTexture>,
|
||||||
|
path_textures: AtlasTextureList<BladeAtlasTexture>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ops::Index<AtlasTextureKind> for BladeAtlasStorage {
|
impl ops::Index<AtlasTextureKind> for BladeAtlasStorage {
|
||||||
|
@ -289,6 +349,7 @@ impl ops::Index<AtlasTextureKind> for BladeAtlasStorage {
|
||||||
match kind {
|
match kind {
|
||||||
crate::AtlasTextureKind::Monochrome => &self.monochrome_textures,
|
crate::AtlasTextureKind::Monochrome => &self.monochrome_textures,
|
||||||
crate::AtlasTextureKind::Polychrome => &self.polychrome_textures,
|
crate::AtlasTextureKind::Polychrome => &self.polychrome_textures,
|
||||||
|
crate::AtlasTextureKind::Path => &self.path_textures,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +359,7 @@ impl ops::IndexMut<AtlasTextureKind> for BladeAtlasStorage {
|
||||||
match kind {
|
match kind {
|
||||||
crate::AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
|
crate::AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
|
||||||
crate::AtlasTextureKind::Polychrome => &mut self.polychrome_textures,
|
crate::AtlasTextureKind::Polychrome => &mut self.polychrome_textures,
|
||||||
|
crate::AtlasTextureKind::Path => &mut self.path_textures,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -308,6 +370,7 @@ impl ops::Index<AtlasTextureId> for BladeAtlasStorage {
|
||||||
let textures = match id.kind {
|
let textures = match id.kind {
|
||||||
crate::AtlasTextureKind::Monochrome => &self.monochrome_textures,
|
crate::AtlasTextureKind::Monochrome => &self.monochrome_textures,
|
||||||
crate::AtlasTextureKind::Polychrome => &self.polychrome_textures,
|
crate::AtlasTextureKind::Polychrome => &self.polychrome_textures,
|
||||||
|
crate::AtlasTextureKind::Path => &self.path_textures,
|
||||||
};
|
};
|
||||||
textures[id.index as usize].as_ref().unwrap()
|
textures[id.index as usize].as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -321,6 +384,9 @@ impl BladeAtlasStorage {
|
||||||
for mut texture in self.polychrome_textures.drain().flatten() {
|
for mut texture in self.polychrome_textures.drain().flatten() {
|
||||||
texture.destroy(gpu);
|
texture.destroy(gpu);
|
||||||
}
|
}
|
||||||
|
for mut texture in self.path_textures.drain().flatten() {
|
||||||
|
texture.destroy(gpu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,6 +395,8 @@ struct BladeAtlasTexture {
|
||||||
allocator: BucketedAtlasAllocator,
|
allocator: BucketedAtlasAllocator,
|
||||||
raw: gpu::Texture,
|
raw: gpu::Texture,
|
||||||
raw_view: gpu::TextureView,
|
raw_view: gpu::TextureView,
|
||||||
|
msaa: Option<gpu::Texture>,
|
||||||
|
msaa_view: Option<gpu::TextureView>,
|
||||||
format: gpu::TextureFormat,
|
format: gpu::TextureFormat,
|
||||||
live_atlas_keys: u32,
|
live_atlas_keys: u32,
|
||||||
}
|
}
|
||||||
|
@ -356,6 +424,12 @@ impl BladeAtlasTexture {
|
||||||
fn destroy(&mut self, gpu: &gpu::Context) {
|
fn destroy(&mut self, gpu: &gpu::Context) {
|
||||||
gpu.destroy_texture(self.raw);
|
gpu.destroy_texture(self.raw);
|
||||||
gpu.destroy_texture_view(self.raw_view);
|
gpu.destroy_texture_view(self.raw_view);
|
||||||
|
if let Some(msaa) = self.msaa {
|
||||||
|
gpu.destroy_texture(msaa);
|
||||||
|
}
|
||||||
|
if let Some(msaa_view) = self.msaa_view {
|
||||||
|
gpu.destroy_texture_view(msaa_view);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bytes_per_pixel(&self) -> u8 {
|
fn bytes_per_pixel(&self) -> u8 {
|
||||||
|
|
|
@ -1,19 +1,24 @@
|
||||||
// Doing `if let` gives you nice scoping with passes/encoders
|
// Doing `if let` gives you nice scoping with passes/encoders
|
||||||
#![allow(irrefutable_let_patterns)]
|
#![allow(irrefutable_let_patterns)]
|
||||||
|
|
||||||
use super::{BladeAtlas, BladeContext};
|
use super::{BladeAtlas, BladeContext, PATH_TEXTURE_FORMAT};
|
||||||
use crate::{
|
use crate::{
|
||||||
Background, Bounds, ContentMask, DevicePixels, GpuSpecs, MonochromeSprite, PathVertex,
|
AtlasTextureKind, AtlasTile, Background, Bounds, ContentMask, DevicePixels, GpuSpecs,
|
||||||
PolychromeSprite, PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Size, Underline,
|
MonochromeSprite, Path, PathId, PathVertex, PolychromeSprite, PrimitiveBatch, Quad,
|
||||||
|
ScaledPixels, Scene, Shadow, Size, Underline,
|
||||||
};
|
};
|
||||||
use blade_graphics::{self as gpu};
|
use blade_graphics as gpu;
|
||||||
use blade_util::{BufferBelt, BufferBeltDescriptor};
|
use blade_util::{BufferBelt, BufferBeltDescriptor};
|
||||||
use bytemuck::{Pod, Zeroable};
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
use collections::HashMap;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use media::core_video::CVMetalTextureCache;
|
use media::core_video::CVMetalTextureCache;
|
||||||
use std::{mem, sync::Arc};
|
use std::{mem, sync::Arc};
|
||||||
|
|
||||||
const MAX_FRAME_TIME_MS: u32 = 10000;
|
const MAX_FRAME_TIME_MS: u32 = 10000;
|
||||||
|
// Use 4x MSAA, all devices support it.
|
||||||
|
// https://developer.apple.com/documentation/metal/mtldevice/1433355-supportstexturesamplecount
|
||||||
|
const DEFAULT_PATH_SAMPLE_COUNT: u32 = 4;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||||
|
@ -61,9 +66,16 @@ struct ShaderShadowsData {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(blade_macros::ShaderData)]
|
#[derive(blade_macros::ShaderData)]
|
||||||
struct ShaderPathsData {
|
struct ShaderPathRasterizationData {
|
||||||
globals: GlobalParams,
|
globals: GlobalParams,
|
||||||
b_path_vertices: gpu::BufferPiece,
|
b_path_vertices: gpu::BufferPiece,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(blade_macros::ShaderData)]
|
||||||
|
struct ShaderPathsData {
|
||||||
|
globals: GlobalParams,
|
||||||
|
t_sprite: gpu::TextureView,
|
||||||
|
s_sprite: gpu::Sampler,
|
||||||
b_path_sprites: gpu::BufferPiece,
|
b_path_sprites: gpu::BufferPiece,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,27 +115,13 @@ struct ShaderSurfacesData {
|
||||||
struct PathSprite {
|
struct PathSprite {
|
||||||
bounds: Bounds<ScaledPixels>,
|
bounds: Bounds<ScaledPixels>,
|
||||||
color: Background,
|
color: Background,
|
||||||
}
|
tile: AtlasTile,
|
||||||
|
|
||||||
/// Argument buffer layout for `draw_indirect` commands.
|
|
||||||
#[repr(C)]
|
|
||||||
#[derive(Copy, Clone, Debug, Default, Pod, Zeroable)]
|
|
||||||
pub struct DrawIndirectArgs {
|
|
||||||
/// The number of vertices to draw.
|
|
||||||
pub vertex_count: u32,
|
|
||||||
/// The number of instances to draw.
|
|
||||||
pub instance_count: u32,
|
|
||||||
/// The Index of the first vertex to draw.
|
|
||||||
pub first_vertex: u32,
|
|
||||||
/// The instance ID of the first instance to draw.
|
|
||||||
///
|
|
||||||
/// Has to be 0, unless [`Features::INDIRECT_FIRST_INSTANCE`](crate::Features::INDIRECT_FIRST_INSTANCE) is enabled.
|
|
||||||
pub first_instance: u32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BladePipelines {
|
struct BladePipelines {
|
||||||
quads: gpu::RenderPipeline,
|
quads: gpu::RenderPipeline,
|
||||||
shadows: gpu::RenderPipeline,
|
shadows: gpu::RenderPipeline,
|
||||||
|
path_rasterization: gpu::RenderPipeline,
|
||||||
paths: gpu::RenderPipeline,
|
paths: gpu::RenderPipeline,
|
||||||
underlines: gpu::RenderPipeline,
|
underlines: gpu::RenderPipeline,
|
||||||
mono_sprites: gpu::RenderPipeline,
|
mono_sprites: gpu::RenderPipeline,
|
||||||
|
@ -132,7 +130,7 @@ struct BladePipelines {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BladePipelines {
|
impl BladePipelines {
|
||||||
fn new(gpu: &gpu::Context, surface_info: gpu::SurfaceInfo, sample_count: u32) -> Self {
|
fn new(gpu: &gpu::Context, surface_info: gpu::SurfaceInfo, path_sample_count: u32) -> Self {
|
||||||
use gpu::ShaderData as _;
|
use gpu::ShaderData as _;
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
@ -180,10 +178,7 @@ impl BladePipelines {
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
fragment: Some(shader.at("fs_quad")),
|
fragment: Some(shader.at("fs_quad")),
|
||||||
color_targets,
|
color_targets,
|
||||||
multisample_state: gpu::MultisampleState {
|
multisample_state: gpu::MultisampleState::default(),
|
||||||
sample_count,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
shadows: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
shadows: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
||||||
name: "shadows",
|
name: "shadows",
|
||||||
|
@ -197,8 +192,26 @@ impl BladePipelines {
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
fragment: Some(shader.at("fs_shadow")),
|
fragment: Some(shader.at("fs_shadow")),
|
||||||
color_targets,
|
color_targets,
|
||||||
|
multisample_state: gpu::MultisampleState::default(),
|
||||||
|
}),
|
||||||
|
path_rasterization: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
||||||
|
name: "path_rasterization",
|
||||||
|
data_layouts: &[&ShaderPathRasterizationData::layout()],
|
||||||
|
vertex: shader.at("vs_path_rasterization"),
|
||||||
|
vertex_fetches: &[],
|
||||||
|
primitive: gpu::PrimitiveState {
|
||||||
|
topology: gpu::PrimitiveTopology::TriangleList,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
depth_stencil: None,
|
||||||
|
fragment: Some(shader.at("fs_path_rasterization")),
|
||||||
|
color_targets: &[gpu::ColorTargetState {
|
||||||
|
format: PATH_TEXTURE_FORMAT,
|
||||||
|
blend: Some(gpu::BlendState::ADDITIVE),
|
||||||
|
write_mask: gpu::ColorWrites::default(),
|
||||||
|
}],
|
||||||
multisample_state: gpu::MultisampleState {
|
multisample_state: gpu::MultisampleState {
|
||||||
sample_count,
|
sample_count: path_sample_count,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
@ -208,16 +221,13 @@ impl BladePipelines {
|
||||||
vertex: shader.at("vs_path"),
|
vertex: shader.at("vs_path"),
|
||||||
vertex_fetches: &[],
|
vertex_fetches: &[],
|
||||||
primitive: gpu::PrimitiveState {
|
primitive: gpu::PrimitiveState {
|
||||||
topology: gpu::PrimitiveTopology::TriangleList,
|
topology: gpu::PrimitiveTopology::TriangleStrip,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
fragment: Some(shader.at("fs_path")),
|
fragment: Some(shader.at("fs_path")),
|
||||||
color_targets,
|
color_targets,
|
||||||
multisample_state: gpu::MultisampleState {
|
multisample_state: gpu::MultisampleState::default(),
|
||||||
sample_count,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
underlines: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
underlines: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
||||||
name: "underlines",
|
name: "underlines",
|
||||||
|
@ -231,10 +241,7 @@ impl BladePipelines {
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
fragment: Some(shader.at("fs_underline")),
|
fragment: Some(shader.at("fs_underline")),
|
||||||
color_targets,
|
color_targets,
|
||||||
multisample_state: gpu::MultisampleState {
|
multisample_state: gpu::MultisampleState::default(),
|
||||||
sample_count,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
mono_sprites: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
mono_sprites: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
||||||
name: "mono-sprites",
|
name: "mono-sprites",
|
||||||
|
@ -248,10 +255,7 @@ impl BladePipelines {
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
fragment: Some(shader.at("fs_mono_sprite")),
|
fragment: Some(shader.at("fs_mono_sprite")),
|
||||||
color_targets,
|
color_targets,
|
||||||
multisample_state: gpu::MultisampleState {
|
multisample_state: gpu::MultisampleState::default(),
|
||||||
sample_count,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
poly_sprites: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
poly_sprites: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
||||||
name: "poly-sprites",
|
name: "poly-sprites",
|
||||||
|
@ -265,10 +269,7 @@ impl BladePipelines {
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
fragment: Some(shader.at("fs_poly_sprite")),
|
fragment: Some(shader.at("fs_poly_sprite")),
|
||||||
color_targets,
|
color_targets,
|
||||||
multisample_state: gpu::MultisampleState {
|
multisample_state: gpu::MultisampleState::default(),
|
||||||
sample_count,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
surfaces: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
surfaces: gpu.create_render_pipeline(gpu::RenderPipelineDesc {
|
||||||
name: "surfaces",
|
name: "surfaces",
|
||||||
|
@ -282,10 +283,7 @@ impl BladePipelines {
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
fragment: Some(shader.at("fs_surface")),
|
fragment: Some(shader.at("fs_surface")),
|
||||||
color_targets,
|
color_targets,
|
||||||
multisample_state: gpu::MultisampleState {
|
multisample_state: gpu::MultisampleState::default(),
|
||||||
sample_count,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,6 +291,7 @@ impl BladePipelines {
|
||||||
fn destroy(&mut self, gpu: &gpu::Context) {
|
fn destroy(&mut self, gpu: &gpu::Context) {
|
||||||
gpu.destroy_render_pipeline(&mut self.quads);
|
gpu.destroy_render_pipeline(&mut self.quads);
|
||||||
gpu.destroy_render_pipeline(&mut self.shadows);
|
gpu.destroy_render_pipeline(&mut self.shadows);
|
||||||
|
gpu.destroy_render_pipeline(&mut self.path_rasterization);
|
||||||
gpu.destroy_render_pipeline(&mut self.paths);
|
gpu.destroy_render_pipeline(&mut self.paths);
|
||||||
gpu.destroy_render_pipeline(&mut self.underlines);
|
gpu.destroy_render_pipeline(&mut self.underlines);
|
||||||
gpu.destroy_render_pipeline(&mut self.mono_sprites);
|
gpu.destroy_render_pipeline(&mut self.mono_sprites);
|
||||||
|
@ -318,13 +317,12 @@ pub struct BladeRenderer {
|
||||||
last_sync_point: Option<gpu::SyncPoint>,
|
last_sync_point: Option<gpu::SyncPoint>,
|
||||||
pipelines: BladePipelines,
|
pipelines: BladePipelines,
|
||||||
instance_belt: BufferBelt,
|
instance_belt: BufferBelt,
|
||||||
|
path_tiles: HashMap<PathId, AtlasTile>,
|
||||||
atlas: Arc<BladeAtlas>,
|
atlas: Arc<BladeAtlas>,
|
||||||
atlas_sampler: gpu::Sampler,
|
atlas_sampler: gpu::Sampler,
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
core_video_texture_cache: CVMetalTextureCache,
|
core_video_texture_cache: CVMetalTextureCache,
|
||||||
sample_count: u32,
|
path_sample_count: u32,
|
||||||
texture_msaa: Option<gpu::Texture>,
|
|
||||||
texture_view_msaa: Option<gpu::TextureView>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BladeRenderer {
|
impl BladeRenderer {
|
||||||
|
@ -333,18 +331,6 @@ impl BladeRenderer {
|
||||||
window: &I,
|
window: &I,
|
||||||
config: BladeSurfaceConfig,
|
config: BladeSurfaceConfig,
|
||||||
) -> anyhow::Result<Self> {
|
) -> anyhow::Result<Self> {
|
||||||
// workaround for https://github.com/zed-industries/zed/issues/26143
|
|
||||||
let sample_count = std::env::var("ZED_SAMPLE_COUNT")
|
|
||||||
.ok()
|
|
||||||
.or_else(|| std::env::var("ZED_PATH_SAMPLE_COUNT").ok())
|
|
||||||
.and_then(|v| v.parse().ok())
|
|
||||||
.or_else(|| {
|
|
||||||
[4, 2, 1]
|
|
||||||
.into_iter()
|
|
||||||
.find(|count| context.gpu.supports_texture_sample_count(*count))
|
|
||||||
})
|
|
||||||
.unwrap_or(1);
|
|
||||||
|
|
||||||
let surface_config = gpu::SurfaceConfig {
|
let surface_config = gpu::SurfaceConfig {
|
||||||
size: config.size,
|
size: config.size,
|
||||||
usage: gpu::TextureUsage::TARGET,
|
usage: gpu::TextureUsage::TARGET,
|
||||||
|
@ -358,27 +344,22 @@ impl BladeRenderer {
|
||||||
.create_surface_configured(window, surface_config)
|
.create_surface_configured(window, surface_config)
|
||||||
.map_err(|err| anyhow::anyhow!("Failed to create surface: {err:?}"))?;
|
.map_err(|err| anyhow::anyhow!("Failed to create surface: {err:?}"))?;
|
||||||
|
|
||||||
let (texture_msaa, texture_view_msaa) = create_msaa_texture_if_needed(
|
|
||||||
&context.gpu,
|
|
||||||
surface.info().format,
|
|
||||||
config.size.width,
|
|
||||||
config.size.height,
|
|
||||||
sample_count,
|
|
||||||
)
|
|
||||||
.unzip();
|
|
||||||
|
|
||||||
let command_encoder = context.gpu.create_command_encoder(gpu::CommandEncoderDesc {
|
let command_encoder = context.gpu.create_command_encoder(gpu::CommandEncoderDesc {
|
||||||
name: "main",
|
name: "main",
|
||||||
buffer_count: 2,
|
buffer_count: 2,
|
||||||
});
|
});
|
||||||
|
// workaround for https://github.com/zed-industries/zed/issues/26143
|
||||||
let pipelines = BladePipelines::new(&context.gpu, surface.info(), sample_count);
|
let path_sample_count = std::env::var("ZED_PATH_SAMPLE_COUNT")
|
||||||
|
.ok()
|
||||||
|
.and_then(|v| v.parse().ok())
|
||||||
|
.unwrap_or(DEFAULT_PATH_SAMPLE_COUNT);
|
||||||
|
let pipelines = BladePipelines::new(&context.gpu, surface.info(), path_sample_count);
|
||||||
let instance_belt = BufferBelt::new(BufferBeltDescriptor {
|
let instance_belt = BufferBelt::new(BufferBeltDescriptor {
|
||||||
memory: gpu::Memory::Shared,
|
memory: gpu::Memory::Shared,
|
||||||
min_chunk_size: 0x1000,
|
min_chunk_size: 0x1000,
|
||||||
alignment: 0x40, // Vulkan `minStorageBufferOffsetAlignment` on Intel Xe
|
alignment: 0x40, // Vulkan `minStorageBufferOffsetAlignment` on Intel Xe
|
||||||
});
|
});
|
||||||
let atlas = Arc::new(BladeAtlas::new(&context.gpu));
|
let atlas = Arc::new(BladeAtlas::new(&context.gpu, path_sample_count));
|
||||||
let atlas_sampler = context.gpu.create_sampler(gpu::SamplerDesc {
|
let atlas_sampler = context.gpu.create_sampler(gpu::SamplerDesc {
|
||||||
name: "atlas",
|
name: "atlas",
|
||||||
mag_filter: gpu::FilterMode::Linear,
|
mag_filter: gpu::FilterMode::Linear,
|
||||||
|
@ -402,13 +383,12 @@ impl BladeRenderer {
|
||||||
last_sync_point: None,
|
last_sync_point: None,
|
||||||
pipelines,
|
pipelines,
|
||||||
instance_belt,
|
instance_belt,
|
||||||
|
path_tiles: HashMap::default(),
|
||||||
atlas,
|
atlas,
|
||||||
atlas_sampler,
|
atlas_sampler,
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
core_video_texture_cache,
|
core_video_texture_cache,
|
||||||
sample_count,
|
path_sample_count,
|
||||||
texture_msaa,
|
|
||||||
texture_view_msaa,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -461,24 +441,6 @@ impl BladeRenderer {
|
||||||
self.surface_config.size = gpu_size;
|
self.surface_config.size = gpu_size;
|
||||||
self.gpu
|
self.gpu
|
||||||
.reconfigure_surface(&mut self.surface, self.surface_config);
|
.reconfigure_surface(&mut self.surface, self.surface_config);
|
||||||
|
|
||||||
if let Some(texture_msaa) = self.texture_msaa {
|
|
||||||
self.gpu.destroy_texture(texture_msaa);
|
|
||||||
}
|
|
||||||
if let Some(texture_view_msaa) = self.texture_view_msaa {
|
|
||||||
self.gpu.destroy_texture_view(texture_view_msaa);
|
|
||||||
}
|
|
||||||
|
|
||||||
let (texture_msaa, texture_view_msaa) = create_msaa_texture_if_needed(
|
|
||||||
&self.gpu,
|
|
||||||
self.surface.info().format,
|
|
||||||
gpu_size.width,
|
|
||||||
gpu_size.height,
|
|
||||||
self.sample_count,
|
|
||||||
)
|
|
||||||
.unzip();
|
|
||||||
self.texture_msaa = texture_msaa;
|
|
||||||
self.texture_view_msaa = texture_view_msaa;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -489,7 +451,8 @@ impl BladeRenderer {
|
||||||
self.gpu
|
self.gpu
|
||||||
.reconfigure_surface(&mut self.surface, self.surface_config);
|
.reconfigure_surface(&mut self.surface, self.surface_config);
|
||||||
self.pipelines.destroy(&self.gpu);
|
self.pipelines.destroy(&self.gpu);
|
||||||
self.pipelines = BladePipelines::new(&self.gpu, self.surface.info(), self.sample_count);
|
self.pipelines =
|
||||||
|
BladePipelines::new(&self.gpu, self.surface.info(), self.path_sample_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,6 +490,80 @@ impl BladeRenderer {
|
||||||
objc2::rc::Retained::as_ptr(&self.surface.metal_layer()) as *mut _
|
objc2::rc::Retained::as_ptr(&self.surface.metal_layer()) as *mut _
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[profiling::function]
|
||||||
|
fn rasterize_paths(&mut self, paths: &[Path<ScaledPixels>]) {
|
||||||
|
self.path_tiles.clear();
|
||||||
|
let mut vertices_by_texture_id = HashMap::default();
|
||||||
|
|
||||||
|
for path in paths {
|
||||||
|
let clipped_bounds = path
|
||||||
|
.bounds
|
||||||
|
.intersect(&path.content_mask.bounds)
|
||||||
|
.map_origin(|origin| origin.floor())
|
||||||
|
.map_size(|size| size.ceil());
|
||||||
|
let tile = self.atlas.allocate_for_rendering(
|
||||||
|
clipped_bounds.size.map(Into::into),
|
||||||
|
AtlasTextureKind::Path,
|
||||||
|
&mut self.command_encoder,
|
||||||
|
);
|
||||||
|
vertices_by_texture_id
|
||||||
|
.entry(tile.texture_id)
|
||||||
|
.or_insert(Vec::new())
|
||||||
|
.extend(path.vertices.iter().map(|vertex| PathVertex {
|
||||||
|
xy_position: vertex.xy_position - clipped_bounds.origin
|
||||||
|
+ tile.bounds.origin.map(Into::into),
|
||||||
|
st_position: vertex.st_position,
|
||||||
|
content_mask: ContentMask {
|
||||||
|
bounds: tile.bounds.map(Into::into),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
self.path_tiles.insert(path.id, tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (texture_id, vertices) in vertices_by_texture_id {
|
||||||
|
let tex_info = self.atlas.get_texture_info(texture_id);
|
||||||
|
let globals = GlobalParams {
|
||||||
|
viewport_size: [tex_info.size.width as f32, tex_info.size.height as f32],
|
||||||
|
premultiplied_alpha: 0,
|
||||||
|
pad: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
let vertex_buf = unsafe { self.instance_belt.alloc_typed(&vertices, &self.gpu) };
|
||||||
|
let frame_view = tex_info.raw_view;
|
||||||
|
let color_target = if let Some(msaa_view) = tex_info.msaa_view {
|
||||||
|
gpu::RenderTarget {
|
||||||
|
view: msaa_view,
|
||||||
|
init_op: gpu::InitOp::Clear(gpu::TextureColor::OpaqueBlack),
|
||||||
|
finish_op: gpu::FinishOp::ResolveTo(frame_view),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gpu::RenderTarget {
|
||||||
|
view: frame_view,
|
||||||
|
init_op: gpu::InitOp::Clear(gpu::TextureColor::OpaqueBlack),
|
||||||
|
finish_op: gpu::FinishOp::Store,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let mut pass = self.command_encoder.render(
|
||||||
|
"paths",
|
||||||
|
gpu::RenderTargetSet {
|
||||||
|
colors: &[color_target],
|
||||||
|
depth_stencil: None,
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
let mut encoder = pass.with(&self.pipelines.path_rasterization);
|
||||||
|
encoder.bind(
|
||||||
|
0,
|
||||||
|
&ShaderPathRasterizationData {
|
||||||
|
globals,
|
||||||
|
b_path_vertices: vertex_buf,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
encoder.draw(0, vertices.len() as u32, 0, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn destroy(&mut self) {
|
pub fn destroy(&mut self) {
|
||||||
self.wait_for_gpu();
|
self.wait_for_gpu();
|
||||||
self.atlas.destroy();
|
self.atlas.destroy();
|
||||||
|
@ -535,26 +572,17 @@ impl BladeRenderer {
|
||||||
self.gpu.destroy_command_encoder(&mut self.command_encoder);
|
self.gpu.destroy_command_encoder(&mut self.command_encoder);
|
||||||
self.pipelines.destroy(&self.gpu);
|
self.pipelines.destroy(&self.gpu);
|
||||||
self.gpu.destroy_surface(&mut self.surface);
|
self.gpu.destroy_surface(&mut self.surface);
|
||||||
if let Some(texture_msaa) = self.texture_msaa {
|
|
||||||
self.gpu.destroy_texture(texture_msaa);
|
|
||||||
}
|
|
||||||
if let Some(texture_view_msaa) = self.texture_view_msaa {
|
|
||||||
self.gpu.destroy_texture_view(texture_view_msaa);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&mut self, scene: &Scene) {
|
pub fn draw(&mut self, scene: &Scene) {
|
||||||
self.command_encoder.start();
|
self.command_encoder.start();
|
||||||
self.atlas.before_frame(&mut self.command_encoder);
|
self.atlas.before_frame(&mut self.command_encoder);
|
||||||
|
self.rasterize_paths(scene.paths());
|
||||||
|
|
||||||
let frame = {
|
let frame = {
|
||||||
profiling::scope!("acquire frame");
|
profiling::scope!("acquire frame");
|
||||||
self.surface.acquire_frame()
|
self.surface.acquire_frame()
|
||||||
};
|
};
|
||||||
let frame_view = frame.texture_view();
|
|
||||||
if let Some(texture_msaa) = self.texture_msaa {
|
|
||||||
self.command_encoder.init_texture(texture_msaa);
|
|
||||||
}
|
|
||||||
self.command_encoder.init_texture(frame.texture());
|
self.command_encoder.init_texture(frame.texture());
|
||||||
|
|
||||||
let globals = GlobalParams {
|
let globals = GlobalParams {
|
||||||
|
@ -569,25 +597,14 @@ impl BladeRenderer {
|
||||||
pad: 0,
|
pad: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let target = if let Some(texture_view_msaa) = self.texture_view_msaa {
|
|
||||||
gpu::RenderTarget {
|
|
||||||
view: texture_view_msaa,
|
|
||||||
init_op: gpu::InitOp::Clear(gpu::TextureColor::TransparentBlack),
|
|
||||||
finish_op: gpu::FinishOp::ResolveTo(frame_view),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
gpu::RenderTarget {
|
|
||||||
view: frame_view,
|
|
||||||
init_op: gpu::InitOp::Clear(gpu::TextureColor::TransparentBlack),
|
|
||||||
finish_op: gpu::FinishOp::Store,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// draw to the target texture
|
|
||||||
if let mut pass = self.command_encoder.render(
|
if let mut pass = self.command_encoder.render(
|
||||||
"main",
|
"main",
|
||||||
gpu::RenderTargetSet {
|
gpu::RenderTargetSet {
|
||||||
colors: &[target],
|
colors: &[gpu::RenderTarget {
|
||||||
|
view: frame.texture_view(),
|
||||||
|
init_op: gpu::InitOp::Clear(gpu::TextureColor::TransparentBlack),
|
||||||
|
finish_op: gpu::FinishOp::Store,
|
||||||
|
}],
|
||||||
depth_stencil: None,
|
depth_stencil: None,
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
@ -622,55 +639,32 @@ impl BladeRenderer {
|
||||||
}
|
}
|
||||||
PrimitiveBatch::Paths(paths) => {
|
PrimitiveBatch::Paths(paths) => {
|
||||||
let mut encoder = pass.with(&self.pipelines.paths);
|
let mut encoder = pass.with(&self.pipelines.paths);
|
||||||
|
// todo(linux): group by texture ID
|
||||||
let mut vertices = Vec::new();
|
for path in paths {
|
||||||
let mut sprites = Vec::with_capacity(paths.len());
|
let tile = &self.path_tiles[&path.id];
|
||||||
let mut draw_indirect_commands = Vec::with_capacity(paths.len());
|
let tex_info = self.atlas.get_texture_info(tile.texture_id);
|
||||||
let mut first_vertex = 0;
|
let origin = path.bounds.intersect(&path.content_mask.bounds).origin;
|
||||||
|
let sprites = [PathSprite {
|
||||||
for (i, path) in paths.iter().enumerate() {
|
bounds: Bounds {
|
||||||
draw_indirect_commands.push(DrawIndirectArgs {
|
origin: origin.map(|p| p.floor()),
|
||||||
vertex_count: path.vertices.len() as u32,
|
size: tile.bounds.size.map(Into::into),
|
||||||
instance_count: 1,
|
|
||||||
first_vertex,
|
|
||||||
first_instance: i as u32,
|
|
||||||
});
|
|
||||||
first_vertex += path.vertices.len() as u32;
|
|
||||||
|
|
||||||
vertices.extend(path.vertices.iter().map(|v| PathVertex {
|
|
||||||
xy_position: v.xy_position,
|
|
||||||
content_mask: ContentMask {
|
|
||||||
bounds: path.content_mask.bounds,
|
|
||||||
},
|
},
|
||||||
}));
|
|
||||||
|
|
||||||
sprites.push(PathSprite {
|
|
||||||
bounds: path.bounds,
|
|
||||||
color: path.color,
|
color: path.color,
|
||||||
});
|
tile: (*tile).clone(),
|
||||||
}
|
}];
|
||||||
|
|
||||||
let b_path_vertices =
|
let instance_buf =
|
||||||
unsafe { self.instance_belt.alloc_typed(&vertices, &self.gpu) };
|
unsafe { self.instance_belt.alloc_typed(&sprites, &self.gpu) };
|
||||||
let instance_buf =
|
encoder.bind(
|
||||||
unsafe { self.instance_belt.alloc_typed(&sprites, &self.gpu) };
|
0,
|
||||||
let indirect_buf = unsafe {
|
&ShaderPathsData {
|
||||||
self.instance_belt
|
globals,
|
||||||
.alloc_typed(&draw_indirect_commands, &self.gpu)
|
t_sprite: tex_info.raw_view,
|
||||||
};
|
s_sprite: self.atlas_sampler,
|
||||||
|
b_path_sprites: instance_buf,
|
||||||
encoder.bind(
|
},
|
||||||
0,
|
);
|
||||||
&ShaderPathsData {
|
encoder.draw(0, 4, 0, sprites.len() as u32);
|
||||||
globals,
|
|
||||||
b_path_vertices,
|
|
||||||
b_path_sprites: instance_buf,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
for i in 0..paths.len() {
|
|
||||||
encoder.draw_indirect(indirect_buf.buffer.at(indirect_buf.offset
|
|
||||||
+ (i * mem::size_of::<DrawIndirectArgs>()) as u64));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PrimitiveBatch::Underlines(underlines) => {
|
PrimitiveBatch::Underlines(underlines) => {
|
||||||
|
@ -823,47 +817,9 @@ impl BladeRenderer {
|
||||||
profiling::scope!("finish");
|
profiling::scope!("finish");
|
||||||
self.instance_belt.flush(&sync_point);
|
self.instance_belt.flush(&sync_point);
|
||||||
self.atlas.after_frame(&sync_point);
|
self.atlas.after_frame(&sync_point);
|
||||||
|
self.atlas.clear_textures(AtlasTextureKind::Path);
|
||||||
|
|
||||||
self.wait_for_gpu();
|
self.wait_for_gpu();
|
||||||
self.last_sync_point = Some(sync_point);
|
self.last_sync_point = Some(sync_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_msaa_texture_if_needed(
|
|
||||||
gpu: &gpu::Context,
|
|
||||||
format: gpu::TextureFormat,
|
|
||||||
width: u32,
|
|
||||||
height: u32,
|
|
||||||
sample_count: u32,
|
|
||||||
) -> Option<(gpu::Texture, gpu::TextureView)> {
|
|
||||||
if sample_count <= 1 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let texture_msaa = gpu.create_texture(gpu::TextureDesc {
|
|
||||||
name: "msaa",
|
|
||||||
format,
|
|
||||||
size: gpu::Extent {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
depth: 1,
|
|
||||||
},
|
|
||||||
array_layer_count: 1,
|
|
||||||
mip_level_count: 1,
|
|
||||||
sample_count,
|
|
||||||
dimension: gpu::TextureDimension::D2,
|
|
||||||
usage: gpu::TextureUsage::TARGET,
|
|
||||||
external: None,
|
|
||||||
});
|
|
||||||
let texture_view_msaa = gpu.create_texture_view(
|
|
||||||
texture_msaa,
|
|
||||||
gpu::TextureViewDesc {
|
|
||||||
name: "msaa view",
|
|
||||||
format,
|
|
||||||
dimension: gpu::ViewDimension::D2,
|
|
||||||
subresources: &Default::default(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
Some((texture_msaa, texture_view_msaa))
|
|
||||||
}
|
|
||||||
|
|
|
@ -922,23 +922,59 @@ fn fs_shadow(input: ShadowVarying) -> @location(0) vec4<f32> {
|
||||||
return blend_color(input.color, alpha);
|
return blend_color(input.color, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- paths --- //
|
// --- path rasterization --- //
|
||||||
|
|
||||||
struct PathVertex {
|
struct PathVertex {
|
||||||
xy_position: vec2<f32>,
|
xy_position: vec2<f32>,
|
||||||
|
st_position: vec2<f32>,
|
||||||
content_mask: Bounds,
|
content_mask: Bounds,
|
||||||
}
|
}
|
||||||
|
var<storage, read> b_path_vertices: array<PathVertex>;
|
||||||
|
|
||||||
|
struct PathRasterizationVarying {
|
||||||
|
@builtin(position) position: vec4<f32>,
|
||||||
|
@location(0) st_position: vec2<f32>,
|
||||||
|
//TODO: use `clip_distance` once Naga supports it
|
||||||
|
@location(3) clip_distances: vec4<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
@vertex
|
||||||
|
fn vs_path_rasterization(@builtin(vertex_index) vertex_id: u32) -> PathRasterizationVarying {
|
||||||
|
let v = b_path_vertices[vertex_id];
|
||||||
|
|
||||||
|
var out = PathRasterizationVarying();
|
||||||
|
out.position = to_device_position_impl(v.xy_position);
|
||||||
|
out.st_position = v.st_position;
|
||||||
|
out.clip_distances = distance_from_clip_rect_impl(v.xy_position, v.content_mask);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
@fragment
|
||||||
|
fn fs_path_rasterization(input: PathRasterizationVarying) -> @location(0) f32 {
|
||||||
|
let dx = dpdx(input.st_position);
|
||||||
|
let dy = dpdy(input.st_position);
|
||||||
|
if (any(input.clip_distances < vec4<f32>(0.0))) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let gradient = 2.0 * input.st_position.xx * vec2<f32>(dx.x, dy.x) - vec2<f32>(dx.y, dy.y);
|
||||||
|
let f = input.st_position.x * input.st_position.x - input.st_position.y;
|
||||||
|
let distance = f / length(gradient);
|
||||||
|
return saturate(0.5 - distance);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- paths --- //
|
||||||
|
|
||||||
struct PathSprite {
|
struct PathSprite {
|
||||||
bounds: Bounds,
|
bounds: Bounds,
|
||||||
color: Background,
|
color: Background,
|
||||||
|
tile: AtlasTile,
|
||||||
}
|
}
|
||||||
var<storage, read> b_path_vertices: array<PathVertex>;
|
|
||||||
var<storage, read> b_path_sprites: array<PathSprite>;
|
var<storage, read> b_path_sprites: array<PathSprite>;
|
||||||
|
|
||||||
struct PathVarying {
|
struct PathVarying {
|
||||||
@builtin(position) position: vec4<f32>,
|
@builtin(position) position: vec4<f32>,
|
||||||
@location(0) clip_distances: vec4<f32>,
|
@location(0) tile_position: vec2<f32>,
|
||||||
@location(1) @interpolate(flat) instance_id: u32,
|
@location(1) @interpolate(flat) instance_id: u32,
|
||||||
@location(2) @interpolate(flat) color_solid: vec4<f32>,
|
@location(2) @interpolate(flat) color_solid: vec4<f32>,
|
||||||
@location(3) @interpolate(flat) color0: vec4<f32>,
|
@location(3) @interpolate(flat) color0: vec4<f32>,
|
||||||
|
@ -947,12 +983,13 @@ struct PathVarying {
|
||||||
|
|
||||||
@vertex
|
@vertex
|
||||||
fn vs_path(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> PathVarying {
|
fn vs_path(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) instance_id: u32) -> PathVarying {
|
||||||
let v = b_path_vertices[vertex_id];
|
let unit_vertex = vec2<f32>(f32(vertex_id & 1u), 0.5 * f32(vertex_id & 2u));
|
||||||
let sprite = b_path_sprites[instance_id];
|
let sprite = b_path_sprites[instance_id];
|
||||||
|
// Don't apply content mask because it was already accounted for when rasterizing the path.
|
||||||
|
|
||||||
var out = PathVarying();
|
var out = PathVarying();
|
||||||
out.position = to_device_position_impl(v.xy_position);
|
out.position = to_device_position(unit_vertex, sprite.bounds);
|
||||||
out.clip_distances = distance_from_clip_rect_impl(v.xy_position, v.content_mask);
|
out.tile_position = to_tile_position(unit_vertex, sprite.tile);
|
||||||
out.instance_id = instance_id;
|
out.instance_id = instance_id;
|
||||||
|
|
||||||
let gradient = prepare_gradient_color(
|
let gradient = prepare_gradient_color(
|
||||||
|
@ -969,15 +1006,13 @@ fn vs_path(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index) insta
|
||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn fs_path(input: PathVarying) -> @location(0) vec4<f32> {
|
fn fs_path(input: PathVarying) -> @location(0) vec4<f32> {
|
||||||
if any(input.clip_distances < vec4<f32>(0.0)) {
|
let sample = textureSample(t_sprite, s_sprite, input.tile_position).r;
|
||||||
return vec4<f32>(0.0);
|
let mask = 1.0 - abs(1.0 - sample % 2.0);
|
||||||
}
|
|
||||||
|
|
||||||
let sprite = b_path_sprites[input.instance_id];
|
let sprite = b_path_sprites[input.instance_id];
|
||||||
let background = sprite.color;
|
let background = sprite.color;
|
||||||
let color = gradient_color(background, input.position.xy, sprite.bounds,
|
let color = gradient_color(background, input.position.xy, sprite.bounds,
|
||||||
input.color_solid, input.color0, input.color1);
|
input.color_solid, input.color0, input.color1);
|
||||||
return blend_color(color, 1.0);
|
return blend_color(color, mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- underlines --- //
|
// --- underlines --- //
|
||||||
|
|
|
@ -822,11 +822,28 @@ impl crate::Keystroke {
|
||||||
Keysym::underscore => "_".to_owned(),
|
Keysym::underscore => "_".to_owned(),
|
||||||
Keysym::equal => "=".to_owned(),
|
Keysym::equal => "=".to_owned(),
|
||||||
Keysym::plus => "+".to_owned(),
|
Keysym::plus => "+".to_owned(),
|
||||||
|
Keysym::space => "space".to_owned(),
|
||||||
|
Keysym::BackSpace => "backspace".to_owned(),
|
||||||
|
Keysym::Tab => "tab".to_owned(),
|
||||||
|
Keysym::Delete => "delete".to_owned(),
|
||||||
|
Keysym::Escape => "escape".to_owned(),
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
let name = xkb::keysym_get_name(key_sym).to_lowercase();
|
let name = xkb::keysym_get_name(key_sym).to_lowercase();
|
||||||
if key_sym.is_keypad_key() {
|
if key_sym.is_keypad_key() {
|
||||||
name.replace("kp_", "")
|
name.replace("kp_", "")
|
||||||
|
} else if let Some(key) = key_utf8.chars().next()
|
||||||
|
&& key_utf8.len() == 1
|
||||||
|
&& key.is_ascii()
|
||||||
|
{
|
||||||
|
if key.is_ascii_graphic() {
|
||||||
|
key_utf8.to_lowercase()
|
||||||
|
// map ctrl-a to a
|
||||||
|
} else if key_utf32 <= 0x1f {
|
||||||
|
((key_utf32 as u8 + 0x60) as char).to_string()
|
||||||
|
} else {
|
||||||
|
name
|
||||||
|
}
|
||||||
} else if let Some(key_en) = guess_ascii(keycode, modifiers.shift) {
|
} else if let Some(key_en) = guess_ascii(keycode, modifiers.shift) {
|
||||||
String::from(key_en)
|
String::from(key_en)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,12 +13,14 @@ use std::borrow::Cow;
|
||||||
pub(crate) struct MetalAtlas(Mutex<MetalAtlasState>);
|
pub(crate) struct MetalAtlas(Mutex<MetalAtlasState>);
|
||||||
|
|
||||||
impl MetalAtlas {
|
impl MetalAtlas {
|
||||||
pub(crate) fn new(device: Device) -> Self {
|
pub(crate) fn new(device: Device, path_sample_count: u32) -> Self {
|
||||||
MetalAtlas(Mutex::new(MetalAtlasState {
|
MetalAtlas(Mutex::new(MetalAtlasState {
|
||||||
device: AssertSend(device),
|
device: AssertSend(device),
|
||||||
monochrome_textures: Default::default(),
|
monochrome_textures: Default::default(),
|
||||||
polychrome_textures: Default::default(),
|
polychrome_textures: Default::default(),
|
||||||
|
path_textures: Default::default(),
|
||||||
tiles_by_key: Default::default(),
|
tiles_by_key: Default::default(),
|
||||||
|
path_sample_count,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +28,10 @@ impl MetalAtlas {
|
||||||
self.0.lock().texture(id).metal_texture.clone()
|
self.0.lock().texture(id).metal_texture.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
pub(crate) fn msaa_texture(&self, id: AtlasTextureId) -> Option<metal::Texture> {
|
||||||
|
self.0.lock().texture(id).msaa_texture.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn allocate(
|
pub(crate) fn allocate(
|
||||||
&self,
|
&self,
|
||||||
size: Size<DevicePixels>,
|
size: Size<DevicePixels>,
|
||||||
|
@ -35,12 +40,12 @@ impl MetalAtlas {
|
||||||
self.0.lock().allocate(size, texture_kind)
|
self.0.lock().allocate(size, texture_kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub(crate) fn clear_textures(&self, texture_kind: AtlasTextureKind) {
|
pub(crate) fn clear_textures(&self, texture_kind: AtlasTextureKind) {
|
||||||
let mut lock = self.0.lock();
|
let mut lock = self.0.lock();
|
||||||
let textures = match texture_kind {
|
let textures = match texture_kind {
|
||||||
AtlasTextureKind::Monochrome => &mut lock.monochrome_textures,
|
AtlasTextureKind::Monochrome => &mut lock.monochrome_textures,
|
||||||
AtlasTextureKind::Polychrome => &mut lock.polychrome_textures,
|
AtlasTextureKind::Polychrome => &mut lock.polychrome_textures,
|
||||||
|
AtlasTextureKind::Path => &mut lock.path_textures,
|
||||||
};
|
};
|
||||||
for texture in textures.iter_mut() {
|
for texture in textures.iter_mut() {
|
||||||
texture.clear();
|
texture.clear();
|
||||||
|
@ -52,7 +57,9 @@ struct MetalAtlasState {
|
||||||
device: AssertSend<Device>,
|
device: AssertSend<Device>,
|
||||||
monochrome_textures: AtlasTextureList<MetalAtlasTexture>,
|
monochrome_textures: AtlasTextureList<MetalAtlasTexture>,
|
||||||
polychrome_textures: AtlasTextureList<MetalAtlasTexture>,
|
polychrome_textures: AtlasTextureList<MetalAtlasTexture>,
|
||||||
|
path_textures: AtlasTextureList<MetalAtlasTexture>,
|
||||||
tiles_by_key: FxHashMap<AtlasKey, AtlasTile>,
|
tiles_by_key: FxHashMap<AtlasKey, AtlasTile>,
|
||||||
|
path_sample_count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlatformAtlas for MetalAtlas {
|
impl PlatformAtlas for MetalAtlas {
|
||||||
|
@ -87,6 +94,7 @@ impl PlatformAtlas for MetalAtlas {
|
||||||
let textures = match id.kind {
|
let textures = match id.kind {
|
||||||
AtlasTextureKind::Monochrome => &mut lock.monochrome_textures,
|
AtlasTextureKind::Monochrome => &mut lock.monochrome_textures,
|
||||||
AtlasTextureKind::Polychrome => &mut lock.polychrome_textures,
|
AtlasTextureKind::Polychrome => &mut lock.polychrome_textures,
|
||||||
|
AtlasTextureKind::Path => &mut lock.polychrome_textures,
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(texture_slot) = textures
|
let Some(texture_slot) = textures
|
||||||
|
@ -120,6 +128,7 @@ impl MetalAtlasState {
|
||||||
let textures = match texture_kind {
|
let textures = match texture_kind {
|
||||||
AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
|
AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
|
||||||
AtlasTextureKind::Polychrome => &mut self.polychrome_textures,
|
AtlasTextureKind::Polychrome => &mut self.polychrome_textures,
|
||||||
|
AtlasTextureKind::Path => &mut self.path_textures,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(tile) = textures
|
if let Some(tile) = textures
|
||||||
|
@ -164,14 +173,31 @@ impl MetalAtlasState {
|
||||||
pixel_format = metal::MTLPixelFormat::BGRA8Unorm;
|
pixel_format = metal::MTLPixelFormat::BGRA8Unorm;
|
||||||
usage = metal::MTLTextureUsage::ShaderRead;
|
usage = metal::MTLTextureUsage::ShaderRead;
|
||||||
}
|
}
|
||||||
|
AtlasTextureKind::Path => {
|
||||||
|
pixel_format = metal::MTLPixelFormat::R16Float;
|
||||||
|
usage = metal::MTLTextureUsage::RenderTarget | metal::MTLTextureUsage::ShaderRead;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
texture_descriptor.set_pixel_format(pixel_format);
|
texture_descriptor.set_pixel_format(pixel_format);
|
||||||
texture_descriptor.set_usage(usage);
|
texture_descriptor.set_usage(usage);
|
||||||
let metal_texture = self.device.new_texture(&texture_descriptor);
|
let metal_texture = self.device.new_texture(&texture_descriptor);
|
||||||
|
|
||||||
|
// We currently only enable MSAA for path textures.
|
||||||
|
let msaa_texture = if self.path_sample_count > 1 && kind == AtlasTextureKind::Path {
|
||||||
|
let mut descriptor = texture_descriptor.clone();
|
||||||
|
descriptor.set_texture_type(metal::MTLTextureType::D2Multisample);
|
||||||
|
descriptor.set_storage_mode(metal::MTLStorageMode::Private);
|
||||||
|
descriptor.set_sample_count(self.path_sample_count as _);
|
||||||
|
let msaa_texture = self.device.new_texture(&descriptor);
|
||||||
|
Some(msaa_texture)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let texture_list = match kind {
|
let texture_list = match kind {
|
||||||
AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
|
AtlasTextureKind::Monochrome => &mut self.monochrome_textures,
|
||||||
AtlasTextureKind::Polychrome => &mut self.polychrome_textures,
|
AtlasTextureKind::Polychrome => &mut self.polychrome_textures,
|
||||||
|
AtlasTextureKind::Path => &mut self.path_textures,
|
||||||
};
|
};
|
||||||
|
|
||||||
let index = texture_list.free_list.pop();
|
let index = texture_list.free_list.pop();
|
||||||
|
@ -183,6 +209,7 @@ impl MetalAtlasState {
|
||||||
},
|
},
|
||||||
allocator: etagere::BucketedAtlasAllocator::new(size.into()),
|
allocator: etagere::BucketedAtlasAllocator::new(size.into()),
|
||||||
metal_texture: AssertSend(metal_texture),
|
metal_texture: AssertSend(metal_texture),
|
||||||
|
msaa_texture: AssertSend(msaa_texture),
|
||||||
live_atlas_keys: 0,
|
live_atlas_keys: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -199,6 +226,7 @@ impl MetalAtlasState {
|
||||||
let textures = match id.kind {
|
let textures = match id.kind {
|
||||||
crate::AtlasTextureKind::Monochrome => &self.monochrome_textures,
|
crate::AtlasTextureKind::Monochrome => &self.monochrome_textures,
|
||||||
crate::AtlasTextureKind::Polychrome => &self.polychrome_textures,
|
crate::AtlasTextureKind::Polychrome => &self.polychrome_textures,
|
||||||
|
crate::AtlasTextureKind::Path => &self.path_textures,
|
||||||
};
|
};
|
||||||
textures[id.index as usize].as_ref().unwrap()
|
textures[id.index as usize].as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
@ -208,6 +236,7 @@ struct MetalAtlasTexture {
|
||||||
id: AtlasTextureId,
|
id: AtlasTextureId,
|
||||||
allocator: BucketedAtlasAllocator,
|
allocator: BucketedAtlasAllocator,
|
||||||
metal_texture: AssertSend<metal::Texture>,
|
metal_texture: AssertSend<metal::Texture>,
|
||||||
|
msaa_texture: AssertSend<Option<metal::Texture>>,
|
||||||
live_atlas_keys: u32,
|
live_atlas_keys: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,27 @@
|
||||||
use super::metal_atlas::MetalAtlas;
|
use super::metal_atlas::MetalAtlas;
|
||||||
use crate::{
|
use crate::{
|
||||||
AtlasTextureId, Background, Bounds, ContentMask, DevicePixels, MonochromeSprite, PaintSurface,
|
AtlasTextureId, AtlasTextureKind, AtlasTile, Background, Bounds, ContentMask, DevicePixels,
|
||||||
Path, PathVertex, PolychromeSprite, PrimitiveBatch, Quad, ScaledPixels, Scene, Shadow, Size,
|
MonochromeSprite, PaintSurface, Path, PathId, PathVertex, PolychromeSprite, PrimitiveBatch,
|
||||||
Surface, Underline, point, size,
|
Quad, ScaledPixels, Scene, Shadow, Size, Surface, Underline, point, size,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::{Context as _, Result};
|
||||||
use block::ConcreteBlock;
|
use block::ConcreteBlock;
|
||||||
use cocoa::{
|
use cocoa::{
|
||||||
base::{NO, YES},
|
base::{NO, YES},
|
||||||
foundation::{NSSize, NSUInteger},
|
foundation::{NSSize, NSUInteger},
|
||||||
quartzcore::AutoresizingMask,
|
quartzcore::AutoresizingMask,
|
||||||
};
|
};
|
||||||
|
use collections::HashMap;
|
||||||
use core_foundation::base::TCFType;
|
use core_foundation::base::TCFType;
|
||||||
use core_video::{
|
use core_video::{
|
||||||
metal_texture::CVMetalTextureGetTexture, metal_texture_cache::CVMetalTextureCache,
|
metal_texture::CVMetalTextureGetTexture, metal_texture_cache::CVMetalTextureCache,
|
||||||
pixel_buffer::kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
|
pixel_buffer::kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
|
||||||
};
|
};
|
||||||
use foreign_types::{ForeignType, ForeignTypeRef};
|
use foreign_types::{ForeignType, ForeignTypeRef};
|
||||||
use metal::{
|
use metal::{CAMetalLayer, CommandQueue, MTLPixelFormat, MTLResourceOptions, NSRange};
|
||||||
CAMetalLayer, CommandQueue, MTLDrawPrimitivesIndirectArguments, MTLPixelFormat,
|
|
||||||
MTLResourceOptions, NSRange,
|
|
||||||
};
|
|
||||||
use objc::{self, msg_send, sel, sel_impl};
|
use objc::{self, msg_send, sel, sel_impl};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
use smallvec::SmallVec;
|
||||||
use std::{cell::Cell, ffi::c_void, mem, ptr, sync::Arc};
|
use std::{cell::Cell, ffi::c_void, mem, ptr, sync::Arc};
|
||||||
|
|
||||||
// Exported to metal
|
// Exported to metal
|
||||||
|
@ -32,6 +31,9 @@ pub(crate) type PointF = crate::Point<f32>;
|
||||||
const SHADERS_METALLIB: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/shaders.metallib"));
|
const SHADERS_METALLIB: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/shaders.metallib"));
|
||||||
#[cfg(feature = "runtime_shaders")]
|
#[cfg(feature = "runtime_shaders")]
|
||||||
const SHADERS_SOURCE_FILE: &str = include_str!(concat!(env!("OUT_DIR"), "/stitched_shaders.metal"));
|
const SHADERS_SOURCE_FILE: &str = include_str!(concat!(env!("OUT_DIR"), "/stitched_shaders.metal"));
|
||||||
|
// Use 4x MSAA, all devices support it.
|
||||||
|
// https://developer.apple.com/documentation/metal/mtldevice/1433355-supportstexturesamplecount
|
||||||
|
const PATH_SAMPLE_COUNT: u32 = 4;
|
||||||
|
|
||||||
pub type Context = Arc<Mutex<InstanceBufferPool>>;
|
pub type Context = Arc<Mutex<InstanceBufferPool>>;
|
||||||
pub type Renderer = MetalRenderer;
|
pub type Renderer = MetalRenderer;
|
||||||
|
@ -96,7 +98,8 @@ pub(crate) struct MetalRenderer {
|
||||||
layer: metal::MetalLayer,
|
layer: metal::MetalLayer,
|
||||||
presents_with_transaction: bool,
|
presents_with_transaction: bool,
|
||||||
command_queue: CommandQueue,
|
command_queue: CommandQueue,
|
||||||
path_pipeline_state: metal::RenderPipelineState,
|
paths_rasterization_pipeline_state: metal::RenderPipelineState,
|
||||||
|
path_sprites_pipeline_state: metal::RenderPipelineState,
|
||||||
shadows_pipeline_state: metal::RenderPipelineState,
|
shadows_pipeline_state: metal::RenderPipelineState,
|
||||||
quads_pipeline_state: metal::RenderPipelineState,
|
quads_pipeline_state: metal::RenderPipelineState,
|
||||||
underlines_pipeline_state: metal::RenderPipelineState,
|
underlines_pipeline_state: metal::RenderPipelineState,
|
||||||
|
@ -108,8 +111,6 @@ pub(crate) struct MetalRenderer {
|
||||||
instance_buffer_pool: Arc<Mutex<InstanceBufferPool>>,
|
instance_buffer_pool: Arc<Mutex<InstanceBufferPool>>,
|
||||||
sprite_atlas: Arc<MetalAtlas>,
|
sprite_atlas: Arc<MetalAtlas>,
|
||||||
core_video_texture_cache: core_video::metal_texture_cache::CVMetalTextureCache,
|
core_video_texture_cache: core_video::metal_texture_cache::CVMetalTextureCache,
|
||||||
sample_count: u64,
|
|
||||||
msaa_texture: Option<metal::Texture>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetalRenderer {
|
impl MetalRenderer {
|
||||||
|
@ -168,19 +169,22 @@ impl MetalRenderer {
|
||||||
MTLResourceOptions::StorageModeManaged,
|
MTLResourceOptions::StorageModeManaged,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sample_count = [4, 2, 1]
|
let paths_rasterization_pipeline_state = build_path_rasterization_pipeline_state(
|
||||||
.into_iter()
|
|
||||||
.find(|count| device.supports_texture_sample_count(*count))
|
|
||||||
.unwrap_or(1);
|
|
||||||
|
|
||||||
let path_pipeline_state = build_pipeline_state(
|
|
||||||
&device,
|
&device,
|
||||||
&library,
|
&library,
|
||||||
"paths",
|
"paths_rasterization",
|
||||||
"path_vertex",
|
"path_rasterization_vertex",
|
||||||
"path_fragment",
|
"path_rasterization_fragment",
|
||||||
|
MTLPixelFormat::R16Float,
|
||||||
|
PATH_SAMPLE_COUNT,
|
||||||
|
);
|
||||||
|
let path_sprites_pipeline_state = build_pipeline_state(
|
||||||
|
&device,
|
||||||
|
&library,
|
||||||
|
"path_sprites",
|
||||||
|
"path_sprite_vertex",
|
||||||
|
"path_sprite_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::BGRA8Unorm,
|
||||||
sample_count,
|
|
||||||
);
|
);
|
||||||
let shadows_pipeline_state = build_pipeline_state(
|
let shadows_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
|
@ -189,7 +193,6 @@ impl MetalRenderer {
|
||||||
"shadow_vertex",
|
"shadow_vertex",
|
||||||
"shadow_fragment",
|
"shadow_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::BGRA8Unorm,
|
||||||
sample_count,
|
|
||||||
);
|
);
|
||||||
let quads_pipeline_state = build_pipeline_state(
|
let quads_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
|
@ -198,7 +201,6 @@ impl MetalRenderer {
|
||||||
"quad_vertex",
|
"quad_vertex",
|
||||||
"quad_fragment",
|
"quad_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::BGRA8Unorm,
|
||||||
sample_count,
|
|
||||||
);
|
);
|
||||||
let underlines_pipeline_state = build_pipeline_state(
|
let underlines_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
|
@ -207,7 +209,6 @@ impl MetalRenderer {
|
||||||
"underline_vertex",
|
"underline_vertex",
|
||||||
"underline_fragment",
|
"underline_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::BGRA8Unorm,
|
||||||
sample_count,
|
|
||||||
);
|
);
|
||||||
let monochrome_sprites_pipeline_state = build_pipeline_state(
|
let monochrome_sprites_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
|
@ -216,7 +217,6 @@ impl MetalRenderer {
|
||||||
"monochrome_sprite_vertex",
|
"monochrome_sprite_vertex",
|
||||||
"monochrome_sprite_fragment",
|
"monochrome_sprite_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::BGRA8Unorm,
|
||||||
sample_count,
|
|
||||||
);
|
);
|
||||||
let polychrome_sprites_pipeline_state = build_pipeline_state(
|
let polychrome_sprites_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
|
@ -225,7 +225,6 @@ impl MetalRenderer {
|
||||||
"polychrome_sprite_vertex",
|
"polychrome_sprite_vertex",
|
||||||
"polychrome_sprite_fragment",
|
"polychrome_sprite_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::BGRA8Unorm,
|
||||||
sample_count,
|
|
||||||
);
|
);
|
||||||
let surfaces_pipeline_state = build_pipeline_state(
|
let surfaces_pipeline_state = build_pipeline_state(
|
||||||
&device,
|
&device,
|
||||||
|
@ -234,21 +233,20 @@ impl MetalRenderer {
|
||||||
"surface_vertex",
|
"surface_vertex",
|
||||||
"surface_fragment",
|
"surface_fragment",
|
||||||
MTLPixelFormat::BGRA8Unorm,
|
MTLPixelFormat::BGRA8Unorm,
|
||||||
sample_count,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let command_queue = device.new_command_queue();
|
let command_queue = device.new_command_queue();
|
||||||
let sprite_atlas = Arc::new(MetalAtlas::new(device.clone()));
|
let sprite_atlas = Arc::new(MetalAtlas::new(device.clone(), PATH_SAMPLE_COUNT));
|
||||||
let core_video_texture_cache =
|
let core_video_texture_cache =
|
||||||
CVMetalTextureCache::new(None, device.clone(), None).unwrap();
|
CVMetalTextureCache::new(None, device.clone(), None).unwrap();
|
||||||
let msaa_texture = create_msaa_texture(&device, &layer, sample_count);
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
device,
|
device,
|
||||||
layer,
|
layer,
|
||||||
presents_with_transaction: false,
|
presents_with_transaction: false,
|
||||||
command_queue,
|
command_queue,
|
||||||
path_pipeline_state,
|
paths_rasterization_pipeline_state,
|
||||||
|
path_sprites_pipeline_state,
|
||||||
shadows_pipeline_state,
|
shadows_pipeline_state,
|
||||||
quads_pipeline_state,
|
quads_pipeline_state,
|
||||||
underlines_pipeline_state,
|
underlines_pipeline_state,
|
||||||
|
@ -259,8 +257,6 @@ impl MetalRenderer {
|
||||||
instance_buffer_pool,
|
instance_buffer_pool,
|
||||||
sprite_atlas,
|
sprite_atlas,
|
||||||
core_video_texture_cache,
|
core_video_texture_cache,
|
||||||
sample_count,
|
|
||||||
msaa_texture,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,8 +289,6 @@ impl MetalRenderer {
|
||||||
setDrawableSize: size
|
setDrawableSize: size
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
self.msaa_texture = create_msaa_texture(&self.device, &self.layer, self.sample_count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_transparency(&self, _transparent: bool) {
|
pub fn update_transparency(&self, _transparent: bool) {
|
||||||
|
@ -381,23 +375,25 @@ impl MetalRenderer {
|
||||||
let command_queue = self.command_queue.clone();
|
let command_queue = self.command_queue.clone();
|
||||||
let command_buffer = command_queue.new_command_buffer();
|
let command_buffer = command_queue.new_command_buffer();
|
||||||
let mut instance_offset = 0;
|
let mut instance_offset = 0;
|
||||||
|
|
||||||
|
let path_tiles = self
|
||||||
|
.rasterize_paths(
|
||||||
|
scene.paths(),
|
||||||
|
instance_buffer,
|
||||||
|
&mut instance_offset,
|
||||||
|
command_buffer,
|
||||||
|
)
|
||||||
|
.with_context(|| format!("rasterizing {} paths", scene.paths().len()))?;
|
||||||
|
|
||||||
let render_pass_descriptor = metal::RenderPassDescriptor::new();
|
let render_pass_descriptor = metal::RenderPassDescriptor::new();
|
||||||
let color_attachment = render_pass_descriptor
|
let color_attachment = render_pass_descriptor
|
||||||
.color_attachments()
|
.color_attachments()
|
||||||
.object_at(0)
|
.object_at(0)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if let Some(msaa_texture_ref) = self.msaa_texture.as_deref() {
|
color_attachment.set_texture(Some(drawable.texture()));
|
||||||
color_attachment.set_texture(Some(msaa_texture_ref));
|
color_attachment.set_load_action(metal::MTLLoadAction::Clear);
|
||||||
color_attachment.set_load_action(metal::MTLLoadAction::Clear);
|
color_attachment.set_store_action(metal::MTLStoreAction::Store);
|
||||||
color_attachment.set_store_action(metal::MTLStoreAction::MultisampleResolve);
|
|
||||||
color_attachment.set_resolve_texture(Some(drawable.texture()));
|
|
||||||
} else {
|
|
||||||
color_attachment.set_load_action(metal::MTLLoadAction::Clear);
|
|
||||||
color_attachment.set_texture(Some(drawable.texture()));
|
|
||||||
color_attachment.set_store_action(metal::MTLStoreAction::Store);
|
|
||||||
}
|
|
||||||
|
|
||||||
let alpha = if self.layer.is_opaque() { 1. } else { 0. };
|
let alpha = if self.layer.is_opaque() { 1. } else { 0. };
|
||||||
color_attachment.set_clear_color(metal::MTLClearColor::new(0., 0., 0., alpha));
|
color_attachment.set_clear_color(metal::MTLClearColor::new(0., 0., 0., alpha));
|
||||||
let command_encoder = command_buffer.new_render_command_encoder(render_pass_descriptor);
|
let command_encoder = command_buffer.new_render_command_encoder(render_pass_descriptor);
|
||||||
|
@ -429,6 +425,7 @@ impl MetalRenderer {
|
||||||
),
|
),
|
||||||
PrimitiveBatch::Paths(paths) => self.draw_paths(
|
PrimitiveBatch::Paths(paths) => self.draw_paths(
|
||||||
paths,
|
paths,
|
||||||
|
&path_tiles,
|
||||||
instance_buffer,
|
instance_buffer,
|
||||||
&mut instance_offset,
|
&mut instance_offset,
|
||||||
viewport_size,
|
viewport_size,
|
||||||
|
@ -496,6 +493,106 @@ impl MetalRenderer {
|
||||||
Ok(command_buffer.to_owned())
|
Ok(command_buffer.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rasterize_paths(
|
||||||
|
&self,
|
||||||
|
paths: &[Path<ScaledPixels>],
|
||||||
|
instance_buffer: &mut InstanceBuffer,
|
||||||
|
instance_offset: &mut usize,
|
||||||
|
command_buffer: &metal::CommandBufferRef,
|
||||||
|
) -> Option<HashMap<PathId, AtlasTile>> {
|
||||||
|
self.sprite_atlas.clear_textures(AtlasTextureKind::Path);
|
||||||
|
|
||||||
|
let mut tiles = HashMap::default();
|
||||||
|
let mut vertices_by_texture_id = HashMap::default();
|
||||||
|
for path in paths {
|
||||||
|
let clipped_bounds = path.bounds.intersect(&path.content_mask.bounds);
|
||||||
|
|
||||||
|
let tile = self
|
||||||
|
.sprite_atlas
|
||||||
|
.allocate(clipped_bounds.size.map(Into::into), AtlasTextureKind::Path)?;
|
||||||
|
vertices_by_texture_id
|
||||||
|
.entry(tile.texture_id)
|
||||||
|
.or_insert(Vec::new())
|
||||||
|
.extend(path.vertices.iter().map(|vertex| PathVertex {
|
||||||
|
xy_position: vertex.xy_position - clipped_bounds.origin
|
||||||
|
+ tile.bounds.origin.map(Into::into),
|
||||||
|
st_position: vertex.st_position,
|
||||||
|
content_mask: ContentMask {
|
||||||
|
bounds: tile.bounds.map(Into::into),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
tiles.insert(path.id, tile);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (texture_id, vertices) in vertices_by_texture_id {
|
||||||
|
align_offset(instance_offset);
|
||||||
|
let vertices_bytes_len = mem::size_of_val(vertices.as_slice());
|
||||||
|
let next_offset = *instance_offset + vertices_bytes_len;
|
||||||
|
if next_offset > instance_buffer.size {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let render_pass_descriptor = metal::RenderPassDescriptor::new();
|
||||||
|
let color_attachment = render_pass_descriptor
|
||||||
|
.color_attachments()
|
||||||
|
.object_at(0)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let texture = self.sprite_atlas.metal_texture(texture_id);
|
||||||
|
let msaa_texture = self.sprite_atlas.msaa_texture(texture_id);
|
||||||
|
|
||||||
|
if let Some(msaa_texture) = msaa_texture {
|
||||||
|
color_attachment.set_texture(Some(&msaa_texture));
|
||||||
|
color_attachment.set_resolve_texture(Some(&texture));
|
||||||
|
color_attachment.set_load_action(metal::MTLLoadAction::Clear);
|
||||||
|
color_attachment.set_store_action(metal::MTLStoreAction::MultisampleResolve);
|
||||||
|
} else {
|
||||||
|
color_attachment.set_texture(Some(&texture));
|
||||||
|
color_attachment.set_load_action(metal::MTLLoadAction::Clear);
|
||||||
|
color_attachment.set_store_action(metal::MTLStoreAction::Store);
|
||||||
|
}
|
||||||
|
color_attachment.set_clear_color(metal::MTLClearColor::new(0., 0., 0., 1.));
|
||||||
|
|
||||||
|
let command_encoder = command_buffer.new_render_command_encoder(render_pass_descriptor);
|
||||||
|
command_encoder.set_render_pipeline_state(&self.paths_rasterization_pipeline_state);
|
||||||
|
command_encoder.set_vertex_buffer(
|
||||||
|
PathRasterizationInputIndex::Vertices as u64,
|
||||||
|
Some(&instance_buffer.metal_buffer),
|
||||||
|
*instance_offset as u64,
|
||||||
|
);
|
||||||
|
let texture_size = Size {
|
||||||
|
width: DevicePixels::from(texture.width()),
|
||||||
|
height: DevicePixels::from(texture.height()),
|
||||||
|
};
|
||||||
|
command_encoder.set_vertex_bytes(
|
||||||
|
PathRasterizationInputIndex::AtlasTextureSize as u64,
|
||||||
|
mem::size_of_val(&texture_size) as u64,
|
||||||
|
&texture_size as *const Size<DevicePixels> as *const _,
|
||||||
|
);
|
||||||
|
|
||||||
|
let buffer_contents = unsafe {
|
||||||
|
(instance_buffer.metal_buffer.contents() as *mut u8).add(*instance_offset)
|
||||||
|
};
|
||||||
|
unsafe {
|
||||||
|
ptr::copy_nonoverlapping(
|
||||||
|
vertices.as_ptr() as *const u8,
|
||||||
|
buffer_contents,
|
||||||
|
vertices_bytes_len,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
command_encoder.draw_primitives(
|
||||||
|
metal::MTLPrimitiveType::Triangle,
|
||||||
|
0,
|
||||||
|
vertices.len() as u64,
|
||||||
|
);
|
||||||
|
command_encoder.end_encoding();
|
||||||
|
*instance_offset = next_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(tiles)
|
||||||
|
}
|
||||||
|
|
||||||
fn draw_shadows(
|
fn draw_shadows(
|
||||||
&self,
|
&self,
|
||||||
shadows: &[Shadow],
|
shadows: &[Shadow],
|
||||||
|
@ -621,6 +718,7 @@ impl MetalRenderer {
|
||||||
fn draw_paths(
|
fn draw_paths(
|
||||||
&self,
|
&self,
|
||||||
paths: &[Path<ScaledPixels>],
|
paths: &[Path<ScaledPixels>],
|
||||||
|
tiles_by_path_id: &HashMap<PathId, AtlasTile>,
|
||||||
instance_buffer: &mut InstanceBuffer,
|
instance_buffer: &mut InstanceBuffer,
|
||||||
instance_offset: &mut usize,
|
instance_offset: &mut usize,
|
||||||
viewport_size: Size<DevicePixels>,
|
viewport_size: Size<DevicePixels>,
|
||||||
|
@ -630,108 +728,100 @@ impl MetalRenderer {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
command_encoder.set_render_pipeline_state(&self.path_pipeline_state);
|
command_encoder.set_render_pipeline_state(&self.path_sprites_pipeline_state);
|
||||||
|
command_encoder.set_vertex_buffer(
|
||||||
|
SpriteInputIndex::Vertices as u64,
|
||||||
|
Some(&self.unit_vertices),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
command_encoder.set_vertex_bytes(
|
||||||
|
SpriteInputIndex::ViewportSize as u64,
|
||||||
|
mem::size_of_val(&viewport_size) as u64,
|
||||||
|
&viewport_size as *const Size<DevicePixels> as *const _,
|
||||||
|
);
|
||||||
|
|
||||||
unsafe {
|
let mut prev_texture_id = None;
|
||||||
let base_addr = instance_buffer.metal_buffer.contents();
|
let mut sprites = SmallVec::<[_; 1]>::new();
|
||||||
let mut p = (base_addr as *mut u8).add(*instance_offset);
|
let mut paths_and_tiles = paths
|
||||||
let mut draw_indirect_commands = Vec::with_capacity(paths.len());
|
.iter()
|
||||||
|
.map(|path| (path, tiles_by_path_id.get(&path.id).unwrap()))
|
||||||
|
.peekable();
|
||||||
|
|
||||||
// copy vertices
|
loop {
|
||||||
let vertices_offset = (p as usize) - (base_addr as usize);
|
if let Some((path, tile)) = paths_and_tiles.peek() {
|
||||||
let mut first_vertex = 0;
|
if prev_texture_id.map_or(true, |texture_id| texture_id == tile.texture_id) {
|
||||||
for (i, path) in paths.iter().enumerate() {
|
prev_texture_id = Some(tile.texture_id);
|
||||||
if (p as usize) - (base_addr as usize)
|
let origin = path.bounds.intersect(&path.content_mask.bounds).origin;
|
||||||
+ (mem::size_of::<PathVertex<ScaledPixels>>() * path.vertices.len())
|
sprites.push(PathSprite {
|
||||||
> instance_buffer.size
|
bounds: Bounds {
|
||||||
{
|
origin: origin.map(|p| p.floor()),
|
||||||
|
size: tile.bounds.size.map(Into::into),
|
||||||
|
},
|
||||||
|
color: path.color,
|
||||||
|
tile: (*tile).clone(),
|
||||||
|
});
|
||||||
|
paths_and_tiles.next();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if sprites.is_empty() {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
align_offset(instance_offset);
|
||||||
|
let texture_id = prev_texture_id.take().unwrap();
|
||||||
|
let texture: metal::Texture = self.sprite_atlas.metal_texture(texture_id);
|
||||||
|
let texture_size = size(
|
||||||
|
DevicePixels(texture.width() as i32),
|
||||||
|
DevicePixels(texture.height() as i32),
|
||||||
|
);
|
||||||
|
|
||||||
|
command_encoder.set_vertex_buffer(
|
||||||
|
SpriteInputIndex::Sprites as u64,
|
||||||
|
Some(&instance_buffer.metal_buffer),
|
||||||
|
*instance_offset as u64,
|
||||||
|
);
|
||||||
|
command_encoder.set_vertex_bytes(
|
||||||
|
SpriteInputIndex::AtlasTextureSize as u64,
|
||||||
|
mem::size_of_val(&texture_size) as u64,
|
||||||
|
&texture_size as *const Size<DevicePixels> as *const _,
|
||||||
|
);
|
||||||
|
command_encoder.set_fragment_buffer(
|
||||||
|
SpriteInputIndex::Sprites as u64,
|
||||||
|
Some(&instance_buffer.metal_buffer),
|
||||||
|
*instance_offset as u64,
|
||||||
|
);
|
||||||
|
command_encoder
|
||||||
|
.set_fragment_texture(SpriteInputIndex::AtlasTexture as u64, Some(&texture));
|
||||||
|
|
||||||
|
let sprite_bytes_len = mem::size_of_val(sprites.as_slice());
|
||||||
|
let next_offset = *instance_offset + sprite_bytes_len;
|
||||||
|
if next_offset > instance_buffer.size {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for v in &path.vertices {
|
let buffer_contents = unsafe {
|
||||||
*(p as *mut PathVertex<ScaledPixels>) = PathVertex {
|
(instance_buffer.metal_buffer.contents() as *mut u8).add(*instance_offset)
|
||||||
xy_position: v.xy_position,
|
};
|
||||||
content_mask: ContentMask {
|
|
||||||
bounds: path.content_mask.bounds,
|
unsafe {
|
||||||
},
|
ptr::copy_nonoverlapping(
|
||||||
};
|
sprites.as_ptr() as *const u8,
|
||||||
p = p.add(mem::size_of::<PathVertex<ScaledPixels>>());
|
buffer_contents,
|
||||||
|
sprite_bytes_len,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_indirect_commands.push(MTLDrawPrimitivesIndirectArguments {
|
command_encoder.draw_primitives_instanced(
|
||||||
vertexCount: path.vertices.len() as u32,
|
|
||||||
instanceCount: 1,
|
|
||||||
vertexStart: first_vertex,
|
|
||||||
baseInstance: i as u32,
|
|
||||||
});
|
|
||||||
first_vertex += path.vertices.len() as u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy sprites
|
|
||||||
let sprites_offset = (p as u64) - (base_addr as u64);
|
|
||||||
if (p as usize) - (base_addr as usize) + (mem::size_of::<PathSprite>() * paths.len())
|
|
||||||
> instance_buffer.size
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for path in paths {
|
|
||||||
*(p as *mut PathSprite) = PathSprite {
|
|
||||||
bounds: path.bounds,
|
|
||||||
color: path.color,
|
|
||||||
};
|
|
||||||
p = p.add(mem::size_of::<PathSprite>());
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy indirect commands
|
|
||||||
let icb_bytes_len = mem::size_of_val(draw_indirect_commands.as_slice());
|
|
||||||
let icb_offset = (p as u64) - (base_addr as u64);
|
|
||||||
if (p as usize) - (base_addr as usize) + icb_bytes_len > instance_buffer.size {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ptr::copy_nonoverlapping(
|
|
||||||
draw_indirect_commands.as_ptr() as *const u8,
|
|
||||||
p,
|
|
||||||
icb_bytes_len,
|
|
||||||
);
|
|
||||||
p = p.add(icb_bytes_len);
|
|
||||||
|
|
||||||
// draw path
|
|
||||||
command_encoder.set_vertex_buffer(
|
|
||||||
PathInputIndex::Vertices as u64,
|
|
||||||
Some(&instance_buffer.metal_buffer),
|
|
||||||
vertices_offset as u64,
|
|
||||||
);
|
|
||||||
|
|
||||||
command_encoder.set_vertex_bytes(
|
|
||||||
PathInputIndex::ViewportSize as u64,
|
|
||||||
mem::size_of_val(&viewport_size) as u64,
|
|
||||||
&viewport_size as *const Size<DevicePixels> as *const _,
|
|
||||||
);
|
|
||||||
|
|
||||||
command_encoder.set_vertex_buffer(
|
|
||||||
PathInputIndex::Sprites as u64,
|
|
||||||
Some(&instance_buffer.metal_buffer),
|
|
||||||
sprites_offset,
|
|
||||||
);
|
|
||||||
|
|
||||||
command_encoder.set_fragment_buffer(
|
|
||||||
PathInputIndex::Sprites as u64,
|
|
||||||
Some(&instance_buffer.metal_buffer),
|
|
||||||
sprites_offset,
|
|
||||||
);
|
|
||||||
|
|
||||||
for i in 0..paths.len() {
|
|
||||||
command_encoder.draw_primitives_indirect(
|
|
||||||
metal::MTLPrimitiveType::Triangle,
|
metal::MTLPrimitiveType::Triangle,
|
||||||
&instance_buffer.metal_buffer,
|
0,
|
||||||
icb_offset
|
6,
|
||||||
+ (i * std::mem::size_of::<MTLDrawPrimitivesIndirectArguments>()) as u64,
|
sprites.len() as u64,
|
||||||
);
|
);
|
||||||
|
*instance_offset = next_offset;
|
||||||
|
sprites.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
*instance_offset = (p as usize) - (base_addr as usize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1053,7 +1143,6 @@ fn build_pipeline_state(
|
||||||
vertex_fn_name: &str,
|
vertex_fn_name: &str,
|
||||||
fragment_fn_name: &str,
|
fragment_fn_name: &str,
|
||||||
pixel_format: metal::MTLPixelFormat,
|
pixel_format: metal::MTLPixelFormat,
|
||||||
sample_count: u64,
|
|
||||||
) -> metal::RenderPipelineState {
|
) -> metal::RenderPipelineState {
|
||||||
let vertex_fn = library
|
let vertex_fn = library
|
||||||
.get_function(vertex_fn_name, None)
|
.get_function(vertex_fn_name, None)
|
||||||
|
@ -1066,7 +1155,6 @@ fn build_pipeline_state(
|
||||||
descriptor.set_label(label);
|
descriptor.set_label(label);
|
||||||
descriptor.set_vertex_function(Some(vertex_fn.as_ref()));
|
descriptor.set_vertex_function(Some(vertex_fn.as_ref()));
|
||||||
descriptor.set_fragment_function(Some(fragment_fn.as_ref()));
|
descriptor.set_fragment_function(Some(fragment_fn.as_ref()));
|
||||||
descriptor.set_sample_count(sample_count);
|
|
||||||
let color_attachment = descriptor.color_attachments().object_at(0).unwrap();
|
let color_attachment = descriptor.color_attachments().object_at(0).unwrap();
|
||||||
color_attachment.set_pixel_format(pixel_format);
|
color_attachment.set_pixel_format(pixel_format);
|
||||||
color_attachment.set_blending_enabled(true);
|
color_attachment.set_blending_enabled(true);
|
||||||
|
@ -1082,45 +1170,50 @@ fn build_pipeline_state(
|
||||||
.expect("could not create render pipeline state")
|
.expect("could not create render pipeline state")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn build_path_rasterization_pipeline_state(
|
||||||
|
device: &metal::DeviceRef,
|
||||||
|
library: &metal::LibraryRef,
|
||||||
|
label: &str,
|
||||||
|
vertex_fn_name: &str,
|
||||||
|
fragment_fn_name: &str,
|
||||||
|
pixel_format: metal::MTLPixelFormat,
|
||||||
|
path_sample_count: u32,
|
||||||
|
) -> metal::RenderPipelineState {
|
||||||
|
let vertex_fn = library
|
||||||
|
.get_function(vertex_fn_name, None)
|
||||||
|
.expect("error locating vertex function");
|
||||||
|
let fragment_fn = library
|
||||||
|
.get_function(fragment_fn_name, None)
|
||||||
|
.expect("error locating fragment function");
|
||||||
|
|
||||||
|
let descriptor = metal::RenderPipelineDescriptor::new();
|
||||||
|
descriptor.set_label(label);
|
||||||
|
descriptor.set_vertex_function(Some(vertex_fn.as_ref()));
|
||||||
|
descriptor.set_fragment_function(Some(fragment_fn.as_ref()));
|
||||||
|
if path_sample_count > 1 {
|
||||||
|
descriptor.set_raster_sample_count(path_sample_count as _);
|
||||||
|
descriptor.set_alpha_to_coverage_enabled(true);
|
||||||
|
}
|
||||||
|
let color_attachment = descriptor.color_attachments().object_at(0).unwrap();
|
||||||
|
color_attachment.set_pixel_format(pixel_format);
|
||||||
|
color_attachment.set_blending_enabled(true);
|
||||||
|
color_attachment.set_rgb_blend_operation(metal::MTLBlendOperation::Add);
|
||||||
|
color_attachment.set_alpha_blend_operation(metal::MTLBlendOperation::Add);
|
||||||
|
color_attachment.set_source_rgb_blend_factor(metal::MTLBlendFactor::One);
|
||||||
|
color_attachment.set_source_alpha_blend_factor(metal::MTLBlendFactor::One);
|
||||||
|
color_attachment.set_destination_rgb_blend_factor(metal::MTLBlendFactor::One);
|
||||||
|
color_attachment.set_destination_alpha_blend_factor(metal::MTLBlendFactor::One);
|
||||||
|
|
||||||
|
device
|
||||||
|
.new_render_pipeline_state(&descriptor)
|
||||||
|
.expect("could not create render pipeline state")
|
||||||
|
}
|
||||||
|
|
||||||
// Align to multiples of 256 make Metal happy.
|
// Align to multiples of 256 make Metal happy.
|
||||||
fn align_offset(offset: &mut usize) {
|
fn align_offset(offset: &mut usize) {
|
||||||
*offset = (*offset).div_ceil(256) * 256;
|
*offset = (*offset).div_ceil(256) * 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_msaa_texture(
|
|
||||||
device: &metal::Device,
|
|
||||||
layer: &metal::MetalLayer,
|
|
||||||
sample_count: u64,
|
|
||||||
) -> Option<metal::Texture> {
|
|
||||||
let viewport_size = layer.drawable_size();
|
|
||||||
let width = viewport_size.width.ceil() as u64;
|
|
||||||
let height = viewport_size.height.ceil() as u64;
|
|
||||||
|
|
||||||
if width == 0 || height == 0 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
if sample_count <= 1 {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let texture_descriptor = metal::TextureDescriptor::new();
|
|
||||||
texture_descriptor.set_texture_type(metal::MTLTextureType::D2Multisample);
|
|
||||||
|
|
||||||
// MTLStorageMode default is `shared` only for Apple silicon GPUs. Use `private` for Apple and Intel GPUs both.
|
|
||||||
// Reference: https://developer.apple.com/documentation/metal/choosing-a-resource-storage-mode-for-apple-gpus
|
|
||||||
texture_descriptor.set_storage_mode(metal::MTLStorageMode::Private);
|
|
||||||
|
|
||||||
texture_descriptor.set_width(width);
|
|
||||||
texture_descriptor.set_height(height);
|
|
||||||
texture_descriptor.set_pixel_format(layer.pixel_format());
|
|
||||||
texture_descriptor.set_usage(metal::MTLTextureUsage::RenderTarget);
|
|
||||||
texture_descriptor.set_sample_count(sample_count);
|
|
||||||
|
|
||||||
let metal_texture = device.new_texture(&texture_descriptor);
|
|
||||||
Some(metal_texture)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
enum ShadowInputIndex {
|
enum ShadowInputIndex {
|
||||||
Vertices = 0,
|
Vertices = 0,
|
||||||
|
@ -1162,10 +1255,9 @@ enum SurfaceInputIndex {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
enum PathInputIndex {
|
enum PathRasterizationInputIndex {
|
||||||
Vertices = 0,
|
Vertices = 0,
|
||||||
ViewportSize = 1,
|
AtlasTextureSize = 1,
|
||||||
Sprites = 2,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
@ -1173,6 +1265,7 @@ enum PathInputIndex {
|
||||||
pub struct PathSprite {
|
pub struct PathSprite {
|
||||||
pub bounds: Bounds<ScaledPixels>,
|
pub bounds: Bounds<ScaledPixels>,
|
||||||
pub color: Background,
|
pub color: Background,
|
||||||
|
pub tile: AtlasTile,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
|
|
@ -698,27 +698,76 @@ fragment float4 polychrome_sprite_fragment(
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PathVertexOutput {
|
struct PathRasterizationVertexOutput {
|
||||||
float4 position [[position]];
|
float4 position [[position]];
|
||||||
|
float2 st_position;
|
||||||
|
float clip_rect_distance [[clip_distance]][4];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PathRasterizationFragmentInput {
|
||||||
|
float4 position [[position]];
|
||||||
|
float2 st_position;
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex PathRasterizationVertexOutput path_rasterization_vertex(
|
||||||
|
uint vertex_id [[vertex_id]],
|
||||||
|
constant PathVertex_ScaledPixels *vertices
|
||||||
|
[[buffer(PathRasterizationInputIndex_Vertices)]],
|
||||||
|
constant Size_DevicePixels *atlas_size
|
||||||
|
[[buffer(PathRasterizationInputIndex_AtlasTextureSize)]]) {
|
||||||
|
PathVertex_ScaledPixels v = vertices[vertex_id];
|
||||||
|
float2 vertex_position = float2(v.xy_position.x, v.xy_position.y);
|
||||||
|
float2 viewport_size = float2(atlas_size->width, atlas_size->height);
|
||||||
|
return PathRasterizationVertexOutput{
|
||||||
|
float4(vertex_position / viewport_size * float2(2., -2.) +
|
||||||
|
float2(-1., 1.),
|
||||||
|
0., 1.),
|
||||||
|
float2(v.st_position.x, v.st_position.y),
|
||||||
|
{v.xy_position.x - v.content_mask.bounds.origin.x,
|
||||||
|
v.content_mask.bounds.origin.x + v.content_mask.bounds.size.width -
|
||||||
|
v.xy_position.x,
|
||||||
|
v.xy_position.y - v.content_mask.bounds.origin.y,
|
||||||
|
v.content_mask.bounds.origin.y + v.content_mask.bounds.size.height -
|
||||||
|
v.xy_position.y}};
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment float4 path_rasterization_fragment(PathRasterizationFragmentInput input
|
||||||
|
[[stage_in]]) {
|
||||||
|
float2 dx = dfdx(input.st_position);
|
||||||
|
float2 dy = dfdy(input.st_position);
|
||||||
|
float2 gradient = float2((2. * input.st_position.x) * dx.x - dx.y,
|
||||||
|
(2. * input.st_position.x) * dy.x - dy.y);
|
||||||
|
float f = (input.st_position.x * input.st_position.x) - input.st_position.y;
|
||||||
|
float distance = f / length(gradient);
|
||||||
|
float alpha = saturate(0.5 - distance);
|
||||||
|
return float4(alpha, 0., 0., 1.);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PathSpriteVertexOutput {
|
||||||
|
float4 position [[position]];
|
||||||
|
float2 tile_position;
|
||||||
uint sprite_id [[flat]];
|
uint sprite_id [[flat]];
|
||||||
float4 solid_color [[flat]];
|
float4 solid_color [[flat]];
|
||||||
float4 color0 [[flat]];
|
float4 color0 [[flat]];
|
||||||
float4 color1 [[flat]];
|
float4 color1 [[flat]];
|
||||||
float4 clip_distance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
vertex PathVertexOutput path_vertex(
|
vertex PathSpriteVertexOutput path_sprite_vertex(
|
||||||
uint vertex_id [[vertex_id]],
|
uint unit_vertex_id [[vertex_id]], uint sprite_id [[instance_id]],
|
||||||
constant PathVertex_ScaledPixels *vertices [[buffer(PathInputIndex_Vertices)]],
|
constant float2 *unit_vertices [[buffer(SpriteInputIndex_Vertices)]],
|
||||||
uint sprite_id [[instance_id]],
|
constant PathSprite *sprites [[buffer(SpriteInputIndex_Sprites)]],
|
||||||
constant PathSprite *sprites [[buffer(PathInputIndex_Sprites)]],
|
constant Size_DevicePixels *viewport_size
|
||||||
constant Size_DevicePixels *input_viewport_size [[buffer(PathInputIndex_ViewportSize)]]) {
|
[[buffer(SpriteInputIndex_ViewportSize)]],
|
||||||
PathVertex_ScaledPixels v = vertices[vertex_id];
|
constant Size_DevicePixels *atlas_size
|
||||||
float2 vertex_position = float2(v.xy_position.x, v.xy_position.y);
|
[[buffer(SpriteInputIndex_AtlasTextureSize)]]) {
|
||||||
float2 viewport_size = float2((float)input_viewport_size->width,
|
|
||||||
(float)input_viewport_size->height);
|
float2 unit_vertex = unit_vertices[unit_vertex_id];
|
||||||
PathSprite sprite = sprites[sprite_id];
|
PathSprite sprite = sprites[sprite_id];
|
||||||
float4 device_position = float4(vertex_position / viewport_size * float2(2., -2.) + float2(-1., 1.), 0., 1.);
|
// Don't apply content mask because it was already accounted for when
|
||||||
|
// rasterizing the path.
|
||||||
|
float4 device_position =
|
||||||
|
to_device_position(unit_vertex, sprite.bounds, viewport_size);
|
||||||
|
float2 tile_position = to_tile_position(unit_vertex, sprite.tile, atlas_size);
|
||||||
|
|
||||||
GradientColor gradient = prepare_fill_color(
|
GradientColor gradient = prepare_fill_color(
|
||||||
sprite.color.tag,
|
sprite.color.tag,
|
||||||
|
@ -728,32 +777,30 @@ vertex PathVertexOutput path_vertex(
|
||||||
sprite.color.colors[1].color
|
sprite.color.colors[1].color
|
||||||
);
|
);
|
||||||
|
|
||||||
return PathVertexOutput{
|
return PathSpriteVertexOutput{
|
||||||
device_position,
|
device_position,
|
||||||
|
tile_position,
|
||||||
sprite_id,
|
sprite_id,
|
||||||
gradient.solid,
|
gradient.solid,
|
||||||
gradient.color0,
|
gradient.color0,
|
||||||
gradient.color1,
|
gradient.color1
|
||||||
{v.xy_position.x - v.content_mask.bounds.origin.x,
|
|
||||||
v.content_mask.bounds.origin.x + v.content_mask.bounds.size.width -
|
|
||||||
v.xy_position.x,
|
|
||||||
v.xy_position.y - v.content_mask.bounds.origin.y,
|
|
||||||
v.content_mask.bounds.origin.y + v.content_mask.bounds.size.height -
|
|
||||||
v.xy_position.y}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment float4 path_fragment(
|
fragment float4 path_sprite_fragment(
|
||||||
PathVertexOutput input [[stage_in]],
|
PathSpriteVertexOutput input [[stage_in]],
|
||||||
constant PathSprite *sprites [[buffer(PathInputIndex_Sprites)]]) {
|
constant PathSprite *sprites [[buffer(SpriteInputIndex_Sprites)]],
|
||||||
if (any(input.clip_distance < float4(0.0))) {
|
texture2d<float> atlas_texture [[texture(SpriteInputIndex_AtlasTexture)]]) {
|
||||||
return float4(0.0);
|
constexpr sampler atlas_texture_sampler(mag_filter::linear,
|
||||||
}
|
min_filter::linear);
|
||||||
|
float4 sample =
|
||||||
|
atlas_texture.sample(atlas_texture_sampler, input.tile_position);
|
||||||
|
float mask = 1. - abs(1. - fmod(sample.r, 2.));
|
||||||
PathSprite sprite = sprites[input.sprite_id];
|
PathSprite sprite = sprites[input.sprite_id];
|
||||||
Background background = sprite.color;
|
Background background = sprite.color;
|
||||||
float4 color = fill_color(background, input.position.xy, sprite.bounds,
|
float4 color = fill_color(background, input.position.xy, sprite.bounds,
|
||||||
input.solid_color, input.color0, input.color1);
|
input.solid_color, input.color0, input.color1);
|
||||||
|
color.a *= mask;
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -341,7 +341,7 @@ impl PlatformAtlas for TestAtlas {
|
||||||
crate::AtlasTile {
|
crate::AtlasTile {
|
||||||
texture_id: AtlasTextureId {
|
texture_id: AtlasTextureId {
|
||||||
index: texture_id,
|
index: texture_id,
|
||||||
kind: crate::AtlasTextureKind::Polychrome,
|
kind: crate::AtlasTextureKind::Path,
|
||||||
},
|
},
|
||||||
tile_id: TileId(tile_id),
|
tile_id: TileId(tile_id),
|
||||||
padding: 0,
|
padding: 0,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
AtlasTextureId, AtlasTile, Background, Bounds, ContentMask, Corners, Edges, Hsla, Pixels,
|
AtlasTextureId, AtlasTile, Background, Bounds, ContentMask, Corners, Edges, Hsla, Pixels,
|
||||||
Point, Radians, ScaledPixels, Size, bounds_tree::BoundsTree,
|
Point, Radians, ScaledPixels, Size, bounds_tree::BoundsTree, point,
|
||||||
};
|
};
|
||||||
use std::{fmt::Debug, iter::Peekable, ops::Range, slice};
|
use std::{fmt::Debug, iter::Peekable, ops::Range, slice};
|
||||||
|
|
||||||
|
@ -43,7 +43,13 @@ impl Scene {
|
||||||
self.surfaces.clear();
|
self.surfaces.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[cfg_attr(
|
||||||
|
all(
|
||||||
|
any(target_os = "linux", target_os = "freebsd"),
|
||||||
|
not(any(feature = "x11", feature = "wayland"))
|
||||||
|
),
|
||||||
|
allow(dead_code)
|
||||||
|
)]
|
||||||
pub fn paths(&self) -> &[Path<ScaledPixels>] {
|
pub fn paths(&self) -> &[Path<ScaledPixels>] {
|
||||||
&self.paths
|
&self.paths
|
||||||
}
|
}
|
||||||
|
@ -683,7 +689,6 @@ pub struct Path<P: Clone + Debug + Default + PartialEq> {
|
||||||
start: Point<P>,
|
start: Point<P>,
|
||||||
current: Point<P>,
|
current: Point<P>,
|
||||||
contour_count: usize,
|
contour_count: usize,
|
||||||
base_scale: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Path<Pixels> {
|
impl Path<Pixels> {
|
||||||
|
@ -702,35 +707,25 @@ impl Path<Pixels> {
|
||||||
content_mask: Default::default(),
|
content_mask: Default::default(),
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
contour_count: 0,
|
contour_count: 0,
|
||||||
base_scale: 1.0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the base scale of the path.
|
/// Scale this path by the given factor.
|
||||||
pub fn scale(mut self, factor: f32) -> Self {
|
pub fn scale(&self, factor: f32) -> Path<ScaledPixels> {
|
||||||
self.base_scale = factor;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Apply a scale to the path.
|
|
||||||
pub(crate) fn apply_scale(&self, factor: f32) -> Path<ScaledPixels> {
|
|
||||||
Path {
|
Path {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
order: self.order,
|
order: self.order,
|
||||||
bounds: self.bounds.scale(self.base_scale * factor),
|
bounds: self.bounds.scale(factor),
|
||||||
content_mask: self.content_mask.scale(self.base_scale * factor),
|
content_mask: self.content_mask.scale(factor),
|
||||||
vertices: self
|
vertices: self
|
||||||
.vertices
|
.vertices
|
||||||
.iter()
|
.iter()
|
||||||
.map(|vertex| vertex.scale(self.base_scale * factor))
|
.map(|vertex| vertex.scale(factor))
|
||||||
.collect(),
|
.collect(),
|
||||||
start: self
|
start: self.start.map(|start| start.scale(factor)),
|
||||||
.start
|
current: self.current.scale(factor),
|
||||||
.map(|start| start.scale(self.base_scale * factor)),
|
|
||||||
current: self.current.scale(self.base_scale * factor),
|
|
||||||
contour_count: self.contour_count,
|
contour_count: self.contour_count,
|
||||||
color: self.color,
|
color: self.color,
|
||||||
base_scale: 1.0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -745,7 +740,10 @@ impl Path<Pixels> {
|
||||||
pub fn line_to(&mut self, to: Point<Pixels>) {
|
pub fn line_to(&mut self, to: Point<Pixels>) {
|
||||||
self.contour_count += 1;
|
self.contour_count += 1;
|
||||||
if self.contour_count > 1 {
|
if self.contour_count > 1 {
|
||||||
self.push_triangle((self.start, self.current, to));
|
self.push_triangle(
|
||||||
|
(self.start, self.current, to),
|
||||||
|
(point(0., 1.), point(0., 1.), point(0., 1.)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
self.current = to;
|
self.current = to;
|
||||||
}
|
}
|
||||||
|
@ -754,15 +752,25 @@ impl Path<Pixels> {
|
||||||
pub fn curve_to(&mut self, to: Point<Pixels>, ctrl: Point<Pixels>) {
|
pub fn curve_to(&mut self, to: Point<Pixels>, ctrl: Point<Pixels>) {
|
||||||
self.contour_count += 1;
|
self.contour_count += 1;
|
||||||
if self.contour_count > 1 {
|
if self.contour_count > 1 {
|
||||||
self.push_triangle((self.start, self.current, to));
|
self.push_triangle(
|
||||||
|
(self.start, self.current, to),
|
||||||
|
(point(0., 1.), point(0., 1.), point(0., 1.)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.push_triangle((self.current, ctrl, to));
|
self.push_triangle(
|
||||||
|
(self.current, ctrl, to),
|
||||||
|
(point(0., 0.), point(0.5, 0.), point(1., 1.)),
|
||||||
|
);
|
||||||
self.current = to;
|
self.current = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Push a triangle to the Path.
|
/// Push a triangle to the Path.
|
||||||
pub fn push_triangle(&mut self, xy: (Point<Pixels>, Point<Pixels>, Point<Pixels>)) {
|
pub fn push_triangle(
|
||||||
|
&mut self,
|
||||||
|
xy: (Point<Pixels>, Point<Pixels>, Point<Pixels>),
|
||||||
|
st: (Point<f32>, Point<f32>, Point<f32>),
|
||||||
|
) {
|
||||||
self.bounds = self
|
self.bounds = self
|
||||||
.bounds
|
.bounds
|
||||||
.union(&Bounds {
|
.union(&Bounds {
|
||||||
|
@ -780,14 +788,17 @@ impl Path<Pixels> {
|
||||||
|
|
||||||
self.vertices.push(PathVertex {
|
self.vertices.push(PathVertex {
|
||||||
xy_position: xy.0,
|
xy_position: xy.0,
|
||||||
|
st_position: st.0,
|
||||||
content_mask: Default::default(),
|
content_mask: Default::default(),
|
||||||
});
|
});
|
||||||
self.vertices.push(PathVertex {
|
self.vertices.push(PathVertex {
|
||||||
xy_position: xy.1,
|
xy_position: xy.1,
|
||||||
|
st_position: st.1,
|
||||||
content_mask: Default::default(),
|
content_mask: Default::default(),
|
||||||
});
|
});
|
||||||
self.vertices.push(PathVertex {
|
self.vertices.push(PathVertex {
|
||||||
xy_position: xy.2,
|
xy_position: xy.2,
|
||||||
|
st_position: st.2,
|
||||||
content_mask: Default::default(),
|
content_mask: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -803,6 +814,7 @@ impl From<Path<ScaledPixels>> for Primitive {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub(crate) struct PathVertex<P: Clone + Debug + Default + PartialEq> {
|
pub(crate) struct PathVertex<P: Clone + Debug + Default + PartialEq> {
|
||||||
pub(crate) xy_position: Point<P>,
|
pub(crate) xy_position: Point<P>,
|
||||||
|
pub(crate) st_position: Point<f32>,
|
||||||
pub(crate) content_mask: ContentMask<P>,
|
pub(crate) content_mask: ContentMask<P>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -810,6 +822,7 @@ impl PathVertex<Pixels> {
|
||||||
pub fn scale(&self, factor: f32) -> PathVertex<ScaledPixels> {
|
pub fn scale(&self, factor: f32) -> PathVertex<ScaledPixels> {
|
||||||
PathVertex {
|
PathVertex {
|
||||||
xy_position: self.xy_position.scale(factor),
|
xy_position: self.xy_position.scale(factor),
|
||||||
|
st_position: self.st_position,
|
||||||
content_mask: self.content_mask.scale(factor),
|
content_mask: self.content_mask.scale(factor),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2658,7 +2658,7 @@ impl Window {
|
||||||
path.color = color.opacity(opacity);
|
path.color = color.opacity(opacity);
|
||||||
self.next_frame
|
self.next_frame
|
||||||
.scene
|
.scene
|
||||||
.insert_primitive(path.apply_scale(scale_factor));
|
.insert_primitive(path.scale(scale_factor));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paint an underline into the scene for the next frame at the current z-index.
|
/// Paint an underline into the scene for the next frame at the current z-index.
|
||||||
|
|
|
@ -116,6 +116,12 @@ pub enum LanguageModelCompletionError {
|
||||||
provider: LanguageModelProviderName,
|
provider: LanguageModelProviderName,
|
||||||
message: String,
|
message: String,
|
||||||
},
|
},
|
||||||
|
#[error("{message}")]
|
||||||
|
UpstreamProviderError {
|
||||||
|
message: String,
|
||||||
|
status: StatusCode,
|
||||||
|
retry_after: Option<Duration>,
|
||||||
|
},
|
||||||
#[error("HTTP response error from {provider}'s API: status {status_code} - {message:?}")]
|
#[error("HTTP response error from {provider}'s API: status {status_code} - {message:?}")]
|
||||||
HttpResponseError {
|
HttpResponseError {
|
||||||
provider: LanguageModelProviderName,
|
provider: LanguageModelProviderName,
|
||||||
|
|
|
@ -644,8 +644,62 @@ struct ApiError {
|
||||||
headers: HeaderMap<HeaderValue>,
|
headers: HeaderMap<HeaderValue>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents error responses from Zed's cloud API.
|
||||||
|
///
|
||||||
|
/// Example JSON for an upstream HTTP error:
|
||||||
|
/// ```json
|
||||||
|
/// {
|
||||||
|
/// "code": "upstream_http_error",
|
||||||
|
/// "message": "Received an error from the Anthropic API: upstream connect error or disconnect/reset before headers, reset reason: connection timeout",
|
||||||
|
/// "upstream_status": 503
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
struct CloudApiError {
|
||||||
|
code: String,
|
||||||
|
message: String,
|
||||||
|
#[serde(default)]
|
||||||
|
#[serde(deserialize_with = "deserialize_optional_status_code")]
|
||||||
|
upstream_status: Option<StatusCode>,
|
||||||
|
#[serde(default)]
|
||||||
|
retry_after: Option<f64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_optional_status_code<'de, D>(deserializer: D) -> Result<Option<StatusCode>, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let opt: Option<u16> = Option::deserialize(deserializer)?;
|
||||||
|
Ok(opt.and_then(|code| StatusCode::from_u16(code).ok()))
|
||||||
|
}
|
||||||
|
|
||||||
impl From<ApiError> for LanguageModelCompletionError {
|
impl From<ApiError> for LanguageModelCompletionError {
|
||||||
fn from(error: ApiError) -> Self {
|
fn from(error: ApiError) -> Self {
|
||||||
|
if let Ok(cloud_error) = serde_json::from_str::<CloudApiError>(&error.body) {
|
||||||
|
if cloud_error.code.starts_with("upstream_http_") {
|
||||||
|
let status = if let Some(status) = cloud_error.upstream_status {
|
||||||
|
status
|
||||||
|
} else if cloud_error.code.ends_with("_error") {
|
||||||
|
error.status
|
||||||
|
} else {
|
||||||
|
// If there's a status code in the code string (e.g. "upstream_http_429")
|
||||||
|
// then use that; otherwise, see if the JSON contains a status code.
|
||||||
|
cloud_error
|
||||||
|
.code
|
||||||
|
.strip_prefix("upstream_http_")
|
||||||
|
.and_then(|code_str| code_str.parse::<u16>().ok())
|
||||||
|
.and_then(|code| StatusCode::from_u16(code).ok())
|
||||||
|
.unwrap_or(error.status)
|
||||||
|
};
|
||||||
|
|
||||||
|
return LanguageModelCompletionError::UpstreamProviderError {
|
||||||
|
message: cloud_error.message,
|
||||||
|
status,
|
||||||
|
retry_after: cloud_error.retry_after.map(Duration::from_secs_f64),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let retry_after = None;
|
let retry_after = None;
|
||||||
LanguageModelCompletionError::from_http_status(
|
LanguageModelCompletionError::from_http_status(
|
||||||
PROVIDER_NAME,
|
PROVIDER_NAME,
|
||||||
|
@ -1279,3 +1333,155 @@ impl Component for ZedAiConfiguration {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use http_client::http::{HeaderMap, StatusCode};
|
||||||
|
use language_model::LanguageModelCompletionError;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_api_error_conversion_with_upstream_http_error() {
|
||||||
|
// upstream_http_error with 503 status should become ServerOverloaded
|
||||||
|
let error_body = r#"{"code":"upstream_http_error","message":"Received an error from the Anthropic API: upstream connect error or disconnect/reset before headers, reset reason: connection timeout","upstream_status":503}"#;
|
||||||
|
|
||||||
|
let api_error = ApiError {
|
||||||
|
status: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
body: error_body.to_string(),
|
||||||
|
headers: HeaderMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let completion_error: LanguageModelCompletionError = api_error.into();
|
||||||
|
|
||||||
|
match completion_error {
|
||||||
|
LanguageModelCompletionError::UpstreamProviderError { message, .. } => {
|
||||||
|
assert_eq!(
|
||||||
|
message,
|
||||||
|
"Received an error from the Anthropic API: upstream connect error or disconnect/reset before headers, reset reason: connection timeout"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => panic!(
|
||||||
|
"Expected UpstreamProviderError for upstream 503, got: {:?}",
|
||||||
|
completion_error
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
// upstream_http_error with 500 status should become ApiInternalServerError
|
||||||
|
let error_body = r#"{"code":"upstream_http_error","message":"Received an error from the OpenAI API: internal server error","upstream_status":500}"#;
|
||||||
|
|
||||||
|
let api_error = ApiError {
|
||||||
|
status: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
body: error_body.to_string(),
|
||||||
|
headers: HeaderMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let completion_error: LanguageModelCompletionError = api_error.into();
|
||||||
|
|
||||||
|
match completion_error {
|
||||||
|
LanguageModelCompletionError::UpstreamProviderError { message, .. } => {
|
||||||
|
assert_eq!(
|
||||||
|
message,
|
||||||
|
"Received an error from the OpenAI API: internal server error"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => panic!(
|
||||||
|
"Expected UpstreamProviderError for upstream 500, got: {:?}",
|
||||||
|
completion_error
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
// upstream_http_error with 429 status should become RateLimitExceeded
|
||||||
|
let error_body = r#"{"code":"upstream_http_error","message":"Received an error from the Google API: rate limit exceeded","upstream_status":429}"#;
|
||||||
|
|
||||||
|
let api_error = ApiError {
|
||||||
|
status: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
body: error_body.to_string(),
|
||||||
|
headers: HeaderMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let completion_error: LanguageModelCompletionError = api_error.into();
|
||||||
|
|
||||||
|
match completion_error {
|
||||||
|
LanguageModelCompletionError::UpstreamProviderError { message, .. } => {
|
||||||
|
assert_eq!(
|
||||||
|
message,
|
||||||
|
"Received an error from the Google API: rate limit exceeded"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
_ => panic!(
|
||||||
|
"Expected UpstreamProviderError for upstream 429, got: {:?}",
|
||||||
|
completion_error
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regular 500 error without upstream_http_error should remain ApiInternalServerError for Zed
|
||||||
|
let error_body = "Regular internal server error";
|
||||||
|
|
||||||
|
let api_error = ApiError {
|
||||||
|
status: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
body: error_body.to_string(),
|
||||||
|
headers: HeaderMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let completion_error: LanguageModelCompletionError = api_error.into();
|
||||||
|
|
||||||
|
match completion_error {
|
||||||
|
LanguageModelCompletionError::ApiInternalServerError { provider, message } => {
|
||||||
|
assert_eq!(provider, PROVIDER_NAME);
|
||||||
|
assert_eq!(message, "Regular internal server error");
|
||||||
|
}
|
||||||
|
_ => panic!(
|
||||||
|
"Expected ApiInternalServerError for regular 500, got: {:?}",
|
||||||
|
completion_error
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
// upstream_http_429 format should be converted to UpstreamProviderError
|
||||||
|
let error_body = r#"{"code":"upstream_http_429","message":"Upstream Anthropic rate limit exceeded.","retry_after":30.5}"#;
|
||||||
|
|
||||||
|
let api_error = ApiError {
|
||||||
|
status: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
body: error_body.to_string(),
|
||||||
|
headers: HeaderMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let completion_error: LanguageModelCompletionError = api_error.into();
|
||||||
|
|
||||||
|
match completion_error {
|
||||||
|
LanguageModelCompletionError::UpstreamProviderError {
|
||||||
|
message,
|
||||||
|
status,
|
||||||
|
retry_after,
|
||||||
|
} => {
|
||||||
|
assert_eq!(message, "Upstream Anthropic rate limit exceeded.");
|
||||||
|
assert_eq!(status, StatusCode::TOO_MANY_REQUESTS);
|
||||||
|
assert_eq!(retry_after, Some(Duration::from_secs_f64(30.5)));
|
||||||
|
}
|
||||||
|
_ => panic!(
|
||||||
|
"Expected UpstreamProviderError for upstream_http_429, got: {:?}",
|
||||||
|
completion_error
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalid JSON in error body should fall back to regular error handling
|
||||||
|
let error_body = "Not JSON at all";
|
||||||
|
|
||||||
|
let api_error = ApiError {
|
||||||
|
status: StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
body: error_body.to_string(),
|
||||||
|
headers: HeaderMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let completion_error: LanguageModelCompletionError = api_error.into();
|
||||||
|
|
||||||
|
match completion_error {
|
||||||
|
LanguageModelCompletionError::ApiInternalServerError { provider, .. } => {
|
||||||
|
assert_eq!(provider, PROVIDER_NAME);
|
||||||
|
}
|
||||||
|
_ => panic!(
|
||||||
|
"Expected ApiInternalServerError for invalid JSON, got: {:?}",
|
||||||
|
completion_error
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -847,6 +847,7 @@ impl KeymapFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum KeybindUpdateOperation<'a> {
|
pub enum KeybindUpdateOperation<'a> {
|
||||||
Replace {
|
Replace {
|
||||||
/// Describes the keybind to create
|
/// Describes the keybind to create
|
||||||
|
@ -865,6 +866,47 @@ pub enum KeybindUpdateOperation<'a> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl KeybindUpdateOperation<'_> {
|
||||||
|
pub fn generate_telemetry(
|
||||||
|
&self,
|
||||||
|
) -> (
|
||||||
|
// The keybind that is created
|
||||||
|
String,
|
||||||
|
// The keybinding that was removed
|
||||||
|
String,
|
||||||
|
// The source of the keybinding
|
||||||
|
String,
|
||||||
|
) {
|
||||||
|
let (new_binding, removed_binding, source) = match &self {
|
||||||
|
KeybindUpdateOperation::Replace {
|
||||||
|
source,
|
||||||
|
target,
|
||||||
|
target_keybind_source,
|
||||||
|
} => (Some(source), Some(target), Some(*target_keybind_source)),
|
||||||
|
KeybindUpdateOperation::Add { source, .. } => (Some(source), None, None),
|
||||||
|
KeybindUpdateOperation::Remove {
|
||||||
|
target,
|
||||||
|
target_keybind_source,
|
||||||
|
} => (None, Some(target), Some(*target_keybind_source)),
|
||||||
|
};
|
||||||
|
|
||||||
|
let new_binding = new_binding
|
||||||
|
.map(KeybindUpdateTarget::telemetry_string)
|
||||||
|
.unwrap_or("null".to_owned());
|
||||||
|
let removed_binding = removed_binding
|
||||||
|
.map(KeybindUpdateTarget::telemetry_string)
|
||||||
|
.unwrap_or("null".to_owned());
|
||||||
|
|
||||||
|
let source = source
|
||||||
|
.as_ref()
|
||||||
|
.map(KeybindSource::name)
|
||||||
|
.map(ToOwned::to_owned)
|
||||||
|
.unwrap_or("null".to_owned());
|
||||||
|
|
||||||
|
(new_binding, removed_binding, source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> KeybindUpdateOperation<'a> {
|
impl<'a> KeybindUpdateOperation<'a> {
|
||||||
pub fn add(source: KeybindUpdateTarget<'a>) -> Self {
|
pub fn add(source: KeybindUpdateTarget<'a>) -> Self {
|
||||||
Self::Add { source, from: None }
|
Self::Add { source, from: None }
|
||||||
|
@ -905,6 +947,16 @@ impl<'a> KeybindUpdateTarget<'a> {
|
||||||
keystrokes.pop();
|
keystrokes.pop();
|
||||||
keystrokes
|
keystrokes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn telemetry_string(&self) -> String {
|
||||||
|
format!(
|
||||||
|
"action_name: {}, context: {}, action_arguments: {}, keystrokes: {}",
|
||||||
|
self.action_name,
|
||||||
|
self.context.unwrap_or("global"),
|
||||||
|
self.action_arguments.unwrap_or("none"),
|
||||||
|
self.keystrokes_unparsed()
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||||
|
@ -940,13 +992,17 @@ impl KeybindSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_meta(index: KeyBindingMetaIndex) -> Self {
|
pub fn from_meta(index: KeyBindingMetaIndex) -> Self {
|
||||||
match index {
|
Self::try_from_meta(index).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn try_from_meta(index: KeyBindingMetaIndex) -> Result<Self> {
|
||||||
|
Ok(match index {
|
||||||
Self::USER => KeybindSource::User,
|
Self::USER => KeybindSource::User,
|
||||||
Self::BASE => KeybindSource::Base,
|
Self::BASE => KeybindSource::Base,
|
||||||
Self::DEFAULT => KeybindSource::Default,
|
Self::DEFAULT => KeybindSource::Default,
|
||||||
Self::VIM => KeybindSource::Vim,
|
Self::VIM => KeybindSource::Vim,
|
||||||
_ => unreachable!(),
|
_ => anyhow::bail!("Invalid keybind source {:?}", index),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ search.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
|
telemetry.workspace = true
|
||||||
theme.workspace = true
|
theme.workspace = true
|
||||||
tree-sitter-json.workspace = true
|
tree-sitter-json.workspace = true
|
||||||
tree-sitter-rust.workspace = true
|
tree-sitter-rust.workspace = true
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -40,6 +40,10 @@ impl<const COLS: usize> TableContents<COLS> {
|
||||||
TableContents::UniformList(data) => data.row_count,
|
TableContents::UniformList(data) => data.row_count,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_empty(&self) -> bool {
|
||||||
|
self.len() == 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct TableInteractionState {
|
pub struct TableInteractionState {
|
||||||
|
@ -375,6 +379,7 @@ pub struct Table<const COLS: usize = 3> {
|
||||||
interaction_state: Option<WeakEntity<TableInteractionState>>,
|
interaction_state: Option<WeakEntity<TableInteractionState>>,
|
||||||
column_widths: Option<[Length; COLS]>,
|
column_widths: Option<[Length; COLS]>,
|
||||||
map_row: Option<Rc<dyn Fn((usize, Div), &mut Window, &mut App) -> AnyElement>>,
|
map_row: Option<Rc<dyn Fn((usize, Div), &mut Window, &mut App) -> AnyElement>>,
|
||||||
|
empty_table_callback: Option<Rc<dyn Fn(&mut Window, &mut App) -> AnyElement>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const COLS: usize> Table<COLS> {
|
impl<const COLS: usize> Table<COLS> {
|
||||||
|
@ -388,6 +393,7 @@ impl<const COLS: usize> Table<COLS> {
|
||||||
interaction_state: None,
|
interaction_state: None,
|
||||||
column_widths: None,
|
column_widths: None,
|
||||||
map_row: None,
|
map_row: None,
|
||||||
|
empty_table_callback: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,6 +466,15 @@ impl<const COLS: usize> Table<COLS> {
|
||||||
self.map_row = Some(Rc::new(callback));
|
self.map_row = Some(Rc::new(callback));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Provide a callback that is invoked when the table is rendered without any rows
|
||||||
|
pub fn empty_table_callback(
|
||||||
|
mut self,
|
||||||
|
callback: impl Fn(&mut Window, &mut App) -> AnyElement + 'static,
|
||||||
|
) -> Self {
|
||||||
|
self.empty_table_callback = Some(Rc::new(callback));
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn base_cell_style(width: Option<Length>, cx: &App) -> Div {
|
fn base_cell_style(width: Option<Length>, cx: &App) -> Div {
|
||||||
|
@ -582,6 +597,7 @@ impl<const COLS: usize> RenderOnce for Table<COLS> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let width = self.width;
|
let width = self.width;
|
||||||
|
let no_rows_rendered = self.rows.is_empty();
|
||||||
|
|
||||||
let table = div()
|
let table = div()
|
||||||
.when_some(width, |this, width| this.w(width))
|
.when_some(width, |this, width| this.w(width))
|
||||||
|
@ -662,6 +678,21 @@ impl<const COLS: usize> RenderOnce for Table<COLS> {
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
.when_some(
|
||||||
|
no_rows_rendered
|
||||||
|
.then_some(self.empty_table_callback)
|
||||||
|
.flatten(),
|
||||||
|
|this, callback| {
|
||||||
|
this.child(
|
||||||
|
h_flex()
|
||||||
|
.size_full()
|
||||||
|
.p_3()
|
||||||
|
.items_start()
|
||||||
|
.justify_center()
|
||||||
|
.child(callback(window, cx)),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
.when_some(
|
.when_some(
|
||||||
width.and(interaction_state.as_ref()),
|
width.and(interaction_state.as_ref()),
|
||||||
|this, interaction_state| {
|
|this, interaction_state| {
|
||||||
|
|
|
@ -40,6 +40,7 @@ rpc.workspace = true
|
||||||
schemars.workspace = true
|
schemars.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
settings.workspace = true
|
settings.workspace = true
|
||||||
|
settings_ui.workspace = true
|
||||||
smallvec.workspace = true
|
smallvec.workspace = true
|
||||||
story = { workspace = true, optional = true }
|
story = { workspace = true, optional = true }
|
||||||
telemetry.workspace = true
|
telemetry.workspace = true
|
||||||
|
|
|
@ -30,6 +30,7 @@ use onboarding_banner::OnboardingBanner;
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use rpc::proto;
|
use rpc::proto;
|
||||||
use settings::Settings as _;
|
use settings::Settings as _;
|
||||||
|
use settings_ui::keybindings;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use theme::ActiveTheme;
|
use theme::ActiveTheme;
|
||||||
use title_bar_settings::TitleBarSettings;
|
use title_bar_settings::TitleBarSettings;
|
||||||
|
@ -683,7 +684,7 @@ impl TitleBar {
|
||||||
)
|
)
|
||||||
.separator()
|
.separator()
|
||||||
.action("Settings", zed_actions::OpenSettings.boxed_clone())
|
.action("Settings", zed_actions::OpenSettings.boxed_clone())
|
||||||
.action("Key Bindings", Box::new(zed_actions::OpenKeymap))
|
.action("Key Bindings", Box::new(keybindings::OpenKeymapEditor))
|
||||||
.action(
|
.action(
|
||||||
"Themes…",
|
"Themes…",
|
||||||
zed_actions::theme_selector::Toggle::default().boxed_clone(),
|
zed_actions::theme_selector::Toggle::default().boxed_clone(),
|
||||||
|
@ -727,7 +728,7 @@ impl TitleBar {
|
||||||
.menu(|window, cx| {
|
.menu(|window, cx| {
|
||||||
ContextMenu::build(window, cx, |menu, _, _| {
|
ContextMenu::build(window, cx, |menu, _, _| {
|
||||||
menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
|
menu.action("Settings", zed_actions::OpenSettings.boxed_clone())
|
||||||
.action("Key Bindings", Box::new(zed_actions::OpenKeymap))
|
.action("Key Bindings", Box::new(keybindings::OpenKeymapEditor))
|
||||||
.action(
|
.action(
|
||||||
"Themes…",
|
"Themes…",
|
||||||
zed_actions::theme_selector::Toggle::default().boxed_clone(),
|
zed_actions::theme_selector::Toggle::default().boxed_clone(),
|
||||||
|
|
|
@ -972,12 +972,10 @@ impl ContextMenu {
|
||||||
.children(action.as_ref().and_then(|action| {
|
.children(action.as_ref().and_then(|action| {
|
||||||
self.action_context
|
self.action_context
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|focus| {
|
.and_then(|focus| {
|
||||||
KeyBinding::for_action_in(&**action, focus, window, cx)
|
KeyBinding::for_action_in(&**action, focus, window, cx)
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| {
|
.or_else(|| KeyBinding::for_action(&**action, window, cx))
|
||||||
KeyBinding::for_action(&**action, window, cx)
|
|
||||||
})
|
|
||||||
.map(|binding| {
|
.map(|binding| {
|
||||||
div().ml_4().child(binding.disabled(*disabled)).when(
|
div().ml_4().child(binding.disabled(*disabled)).when(
|
||||||
*disabled && documentation_aside.is_some(),
|
*disabled && documentation_aside.is_some(),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
description = "The fast, collaborative code editor."
|
description = "The fast, collaborative code editor."
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.196.0"
|
version = "0.196.4"
|
||||||
publish.workspace = true
|
publish.workspace = true
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
authors = ["Zed Team <hi@zed.dev>"]
|
authors = ["Zed Team <hi@zed.dev>"]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
dev
|
preview
|
|
@ -1,5 +1,6 @@
|
||||||
use collab_ui::collab_panel;
|
use collab_ui::collab_panel;
|
||||||
use gpui::{Menu, MenuItem, OsAction};
|
use gpui::{Menu, MenuItem, OsAction};
|
||||||
|
use settings_ui::keybindings;
|
||||||
use terminal_view::terminal_panel;
|
use terminal_view::terminal_panel;
|
||||||
|
|
||||||
pub fn app_menus() -> Vec<Menu> {
|
pub fn app_menus() -> Vec<Menu> {
|
||||||
|
@ -16,7 +17,7 @@ pub fn app_menus() -> Vec<Menu> {
|
||||||
name: "Settings".into(),
|
name: "Settings".into(),
|
||||||
items: vec)
|
If you're using an AMD GPU and Zed crashes when selecting long lines, try setting the `ZED_PATH_SAMPLE_COUNT=0` environment variable. (See [#26143](https://github.com/zed-industries/zed/issues/26143))
|
||||||
|
|
||||||
If you're using an AMD GPU, you might get a 'Broken Pipe' error. Try using the RADV or Mesa drivers. (See [#13880](https://github.com/zed-industries/zed/issues/13880))
|
If you're using an AMD GPU, you might get a 'Broken Pipe' error. Try using the RADV or Mesa drivers. (See [#13880](https://github.com/zed-industries/zed/issues/13880))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue