forge
Explore
Log in

Don't you dare go Hollow

Encode capabilities and the image upload path

Browse files at this commit

a1a1150ebccc052d3bf976fc505be069d3b1ffeaAhmet Kaan GümüşParent: a3e5dd1
  • feat
    • encode capabilities and the image upload path
Show full message
feat(va): encode capabilities and the image upload path

`CapEntry` now reports `VAConfigAttribEncPackedHeaders` and
`VAConfigAttribRateControl` alongside the RT formats, in the same round
trip. The packed-header mask is not decoration: a config created without
asking for those headers gets a driver that ignores the ones the
application writes, which on radeonsi means a stream with no parameter
sets in front of it.

`Surface::write_from` wraps `vaPutImage`, the encoder's upload path —
fill a standalone image with source pixels and let the driver detile and
convert on the way in.

`VA_ATTRIB_NOT_SUPPORTED` is reported as zero rather than as every bit
set: a decode entrypoint answers that for the encode-only attributes,
and "all capabilities" is not what it means.
crates/ec-va/src/caps.rsmodified+32 -8
@@ -157,6 +157,12 @@ pub struct CapEntry {
157 pub entrypoint: Entrypoint,157 pub entrypoint: Entrypoint,
158 /// `VAConfigAttribRTFormat` bitmask (`VA_RT_FORMAT_*`).158 /// `VAConfigAttribRTFormat` bitmask (`VA_RT_FORMAT_*`).
159 pub rt_formats: u32,159 pub rt_formats: u32,
160+ /// `VAConfigAttribEncPackedHeaders` bitmask (`VA_ENC_PACKED_HEADER_*`);
161+ /// zero for a decode entrypoint. An encoder has to ask for these in its
162+ /// config before the driver will use the headers it writes.
163+ pub packed_headers: u32,
164+ /// `VAConfigAttribRateControl` bitmask (`VA_RC_*`); zero for decode.
165+ pub rate_control: u32,
160 /// Surface geometry and pixel formats this config accepts, when the driver166 /// Surface geometry and pixel formats this config accepts, when the driver
161 /// reports them. `None` if `vaQuerySurfaceAttributes` refused the config.167 /// reports them. `None` if `vaQuerySurfaceAttributes` refused the config.
162 pub surfaces: Option<SurfaceCaps>,168 pub surfaces: Option<SurfaceCaps>,
@@ -224,7 +230,8 @@ fn probe_entries(display: &Arc<Display>) -> Result<Vec<CapEntry>> {
224 let mut entries = Vec::new();230 let mut entries = Vec::new();
225 for profile in query_profiles(display)? {231 for profile in query_profiles(display)? {
226 for entrypoint in query_entrypoints(display, profile)? {232 for entrypoint in query_entrypoints(display, profile)? {
227- let rt_formats = query_rt_formats(display, profile, entrypoint)?;233+ let [rt_formats, packed_headers, rate_control] =
234+ query_attribs(display, profile, entrypoint)?;
228 // Creating the config is also how the legal surface sizes are235 // Creating the config is also how the legal surface sizes are
229 // discovered: `vaQuerySurfaceAttributes` needs a config id. A236 // discovered: `vaQuerySurfaceAttributes` needs a config id. A
230 // driver may refuse a pair it just advertised (radeonsi does this237 // driver may refuse a pair it just advertised (radeonsi does this
@@ -238,6 +245,8 @@ fn probe_entries(display: &Arc<Display>) -> Result<Vec<CapEntry>> {
238 profile,245 profile,
239 entrypoint,246 entrypoint,
240 rt_formats,247 rt_formats,
248+ packed_headers,
249+ rate_control,
241 surfaces,250 surfaces,
242 });251 });
243 }252 }
@@ -282,15 +291,27 @@ fn query_entrypoints(display: &Arc<Display>, profile: Profile) -> Result<Vec<Ent
282 Ok(raw.into_iter().map(Entrypoint::from_raw).collect())291 Ok(raw.into_iter().map(Entrypoint::from_raw).collect())
283 }292 }
284 293
285-fn query_rt_formats(294+/// The three config attributes this family reads, in one round trip:
295+/// RT format, packed headers, rate control modes.
296+fn query_attribs(
286 display: &Arc<Display>,297 display: &Arc<Display>,
287 profile: Profile,298 profile: Profile,
288 entrypoint: Entrypoint,299 entrypoint: Entrypoint,
289-) -> Result<u32> {300+) -> Result<[u32; 3]> {
290- let mut attrs = [sys::VAConfigAttrib {301+ let mut attrs = [
291- type_: sys::VAConfigAttribRTFormat,302+ sys::VAConfigAttrib {
292- value: 0,303+ type_: sys::VAConfigAttribRTFormat,
293- }];304+ value: 0,
305+ },
306+ sys::VAConfigAttrib {
307+ type_: sys::VAConfigAttribEncPackedHeaders,
308+ value: 0,
309+ },
310+ sys::VAConfigAttrib {
311+ type_: sys::VAConfigAttribRateControl,
312+ value: 0,
313+ },
314+ ];
294 // SAFETY: `attrs` is a valid, initialized array of 1 VAConfigAttrib and the315 // SAFETY: `attrs` is a valid, initialized array of 1 VAConfigAttrib and the
295 // length passed matches. vaGetConfigAttributes writes only `value`.316 // length passed matches. vaGetConfigAttributes writes only `value`.
296 let status = unsafe {317 let status = unsafe {
@@ -303,7 +324,10 @@ fn query_rt_formats(
303 )324 )
304 };325 };
305 check("vaGetConfigAttributes", status)?;326 check("vaGetConfigAttributes", status)?;
306- Ok(attrs[0].value)327+ // VA_ATTRIB_NOT_SUPPORTED is 0xffffffff; a decode entrypoint answers that
328+ // for the encode-only attributes, and "all bits set" is not a capability.
329+ let value = |a: &sys::VAConfigAttrib| if a.value == u32::MAX { 0 } else { a.value };
330+ Ok([value(&attrs[0]), value(&attrs[1]), value(&attrs[2])])
307 }331 }
308 332
309 fn query_image_formats(display: &Arc<Display>) -> Result<Vec<u32>> {333 fn query_image_formats(display: &Arc<Display>) -> Result<Vec<u32>> {
crates/ec-va/src/surface.rsmodified+34 -0
@@ -232,6 +232,40 @@ impl Surface {
232 check("vaGetImage", status)232 check("vaGetImage", status)
233 }233 }
234 234
235+ /// Copy an [`Image`] into the surface (`vaPutImage`).
236+ ///
237+ /// The upload path an encoder needs: fill a standalone image with source
238+ /// pixels, then hand it to the driver, which detiles and converts on the
239+ /// way in. The region is `(0, 0, width, height)` on both sides — scaling
240+ /// during upload is a video-processing job, not an encoder's.
241+ pub fn write_from(&self, image: &Image, width: u32, height: u32) -> Result<()> {
242+ let (img_w, img_h) = image.size();
243+ if width > img_w || height > img_h {
244+ return Err(Error::Protocol(format!(
245+ "vaPutImage region {width}x{height} exceeds image {img_w}x{img_h}"
246+ )));
247+ }
248+ // SAFETY: valid display and surface id; `image.raw.image_id` is a live
249+ // image on the same display, and the region is bounded above by both
250+ // the image and the surface size (va.h:4860).
251+ let status = unsafe {
252+ sys::vaPutImage(
253+ self.display.handle(),
254+ self.id,
255+ image.raw.image_id,
256+ 0,
257+ 0,
258+ width,
259+ height,
260+ 0,
261+ 0,
262+ width,
263+ height,
264+ )
265+ };
266+ check("vaPutImage", status)
267+ }
268+
235 /// The surface id, for FFI-level callers (`ec-hw` picture parameters).269 /// The surface id, for FFI-level callers (`ec-hw` picture parameters).
236 pub fn id(&self) -> sys::VASurfaceID {270 pub fn id(&self) -> sys::VASurfaceID {
237 self.id271 self.id
crates/ec-va/src/sys.rsmodified+29 -0
@@ -98,6 +98,7 @@ pub const VAConfigAttribRTFormat: VAConfigAttribType = 0;
98 pub const VAConfigAttribRateControl: VAConfigAttribType = 5;98 pub const VAConfigAttribRateControl: VAConfigAttribType = 5;
99 pub const VAConfigAttribDecSliceMode: VAConfigAttribType = 6;99 pub const VAConfigAttribDecSliceMode: VAConfigAttribType = 6;
100 pub const VAConfigAttribEncPackedHeaders: VAConfigAttribType = 10;100 pub const VAConfigAttribEncPackedHeaders: VAConfigAttribType = 10;
101+pub const VAConfigAttribEncMaxRefFrames: VAConfigAttribType = 13;
101 102
102 // RT formats (`va.h:1073-1090`).103 // RT formats (`va.h:1073-1090`).
103 pub const VA_RT_FORMAT_YUV420: u32 = 0x0000_0001;104 pub const VA_RT_FORMAT_YUV420: u32 = 0x0000_0001;
@@ -149,6 +150,20 @@ pub const VAEncPackedHeaderParameterBufferType: VABufferType = 25;
149 pub const VAEncPackedHeaderDataBufferType: VABufferType = 26;150 pub const VAEncPackedHeaderDataBufferType: VABufferType = 26;
150 pub const VAEncMiscParameterBufferType: VABufferType = 27;151 pub const VAEncMiscParameterBufferType: VABufferType = 27;
151 152
153+// Packed header bits an encoder may take over (`va.h:1199-1231`).
154+pub const VA_ENC_PACKED_HEADER_NONE: u32 = 0x0000_0000;
155+pub const VA_ENC_PACKED_HEADER_SEQUENCE: u32 = 0x0000_0001;
156+pub const VA_ENC_PACKED_HEADER_PICTURE: u32 = 0x0000_0002;
157+pub const VA_ENC_PACKED_HEADER_SLICE: u32 = 0x0000_0004;
158+pub const VA_ENC_PACKED_HEADER_MISC: u32 = 0x0000_0008;
159+pub const VA_ENC_PACKED_HEADER_RAW_DATA: u32 = 0x0000_0010;
160+
161+// Rate control modes (`va.h:1108-1164`).
162+pub const VA_RC_NONE: u32 = 0x0000_0001;
163+pub const VA_RC_CBR: u32 = 0x0000_0002;
164+pub const VA_RC_VBR: u32 = 0x0000_0004;
165+pub const VA_RC_CQP: u32 = 0x0000_0010;
166+
152 /// `vaCreateContext` flag: sequence contains only progressive frames (`va.h:1919`).167 /// `vaCreateContext` flag: sequence contains only progressive frames (`va.h:1919`).
153 pub const VA_PROGRESSIVE: c_int = 0x1;168 pub const VA_PROGRESSIVE: c_int = 0x1;
154 169
@@ -480,6 +495,20 @@ unsafe extern "C" {
480 ) -> VAStatus;495 ) -> VAStatus;
481 /// `va.h:4888`. Zero-copy view of a surface, when the driver allows it.496 /// `va.h:4888`. Zero-copy view of a surface, when the driver allows it.
482 pub fn vaDeriveImage(dpy: VADisplay, surface: VASurfaceID, image: *mut VAImage) -> VAStatus;497 pub fn vaDeriveImage(dpy: VADisplay, surface: VASurfaceID, image: *mut VAImage) -> VAStatus;
498+ /// `va.h:4860`. Copies an image into a surface — the encoder upload path.
499+ pub fn vaPutImage(
500+ dpy: VADisplay,
501+ surface: VASurfaceID,
502+ image: VAImageID,
503+ src_x: c_int,
504+ src_y: c_int,
505+ src_width: c_uint,
506+ src_height: c_uint,
507+ dest_x: c_int,
508+ dest_y: c_int,
509+ dest_width: c_uint,
510+ dest_height: c_uint,
511+ ) -> VAStatus;
483 }512 }
484 513
485 #[link(name = "va-drm")]514 #[link(name = "va-drm")]