🆕 Carry the GL renderer's private render state to the host

Apple's OpenGL renderer sets private state (SPI) on every render pipeline
descriptor. Measured on the Intel 630, macOS 26.7.1:
- openGLModeEnabled, a sample mask and the copy logic operation always;
- a GL logic operation (XOR is 10), sample mask or sample coverage as their
  properties;
- depthStencilWriteDisabled where the pipeline writes no depth or stencil.
The bundle dropped all of it, so a GL logic operation drew a copy and the sample
mask and coverage covered every sample.

Where the host offers PRIVATE_RENDER_STATE (FEATURES_LO bit 28) and the kext
takes it, each render pipeline create carries RGFX_RENDER_PIPELINE_PRIVATE_STATE
and an RgfxRenderPipelinePrivateState after its head. The bundle reads those
seven properties by key from the guest's descriptor. The Metal platform sets
them by their setters, and offers the bit where its descriptors answer them all.
The Vulkan platform fills metal2vulkan's PrivateRenderState, and drops
openGLModeEnabled until metal2vulkan says what it changes. A host without the
bit never sees the flag.
This commit is contained in:
Anees Iqbal committed 2026-11-07 12:11:27 -08:00
1 parent dc0370b964
commit 286e89cbd9
27 files changed
+812 -57

No files matched your search

+1
View File
@@ -276,6 +276,7 @@ include = [
"RgfxRenderPassStencilAttachment",
"RgfxRenderPassVisibility",
"RgfxRenderPipelineCreate",
"RgfxRenderPipelinePrivateState",
"RgfxResourceBinding",
"RgfxResourceIdChunk",
"RgfxRingHeader",
@@ -948,8 +948,8 @@
// [`RGFX_FEATURE_SURFACE_DEFERRED`], [`RGFX_FEATURE_HOST_TIME`],
// [`RGFX_FEATURE_MANAGED_TEXTURE_SLABS`], [`RGFX_FEATURE_MANAGED_BUFFER_SLABS`],
// [`RGFX_FEATURE_SMALL_ID_CHUNKS`], [`RGFX_FEATURE_DISPLAY_COLOR`],
// [`RGFX_FEATURE_MESH_PIPELINES`] and [`RGFX_FEATURE_SHARED_EVENT_NAMES`]). Bits 9 and 10 are
// reserved.
// [`RGFX_FEATURE_MESH_PIPELINES`], [`RGFX_FEATURE_SHARED_EVENT_NAMES`] and
// [`RGFX_FEATURE_PRIVATE_RENDER_STATE`]). Bits 9 and 10 are reserved.
#define RGFX_REG_FEATURES_LO 8
// `FEATURES_HI`, RO: feature bits 32 to 63.
@@ -1138,6 +1138,15 @@
// ([`RgfxSharedEventName::listen_queue_obj_id`]).
#define RGFX_FEATURE_SHARED_EVENT_NAMES (1 << 26)
// `FEATURES_LO` bit 28, `PRIVATE_RENDER_STATE`, which the guest takes through
// [`RGFX_REG_DRIVER_FEATURES_LO`]: a [`RgfxRenderPipelineCreate`] may carry
// [`RGFX_RENDER_PIPELINE_PRIVATE_STATE`] and, after its head, the
// [`RgfxRenderPipelinePrivateState`] of the guest's descriptor: the private state (Apple SPI)
// Apple's OpenGL renderer sets, which the host's platform makes the pipeline with. A host offers
// it only where its platform takes that state. A host without it reads the flag as no flag and
// the record as tail no offset names, so the guest sends them only where it took the bit.
#define RGFX_FEATURE_PRIVATE_RENDER_STATE (1 << 28)
// `STATUS`, RW: writing [`RGFX_STATUS_RESET`] resets the device; the guest writes
// [`RGFX_STATUS_DRIVER_READY`] once it has read the rings' headers.
#define RGFX_REG_STATUS 16
@@ -2223,6 +2232,23 @@
// [`RgfxRenderPipelineCreate`] `flags`: `supportIndirectCommandBuffers`.
#define RGFX_RENDER_PIPELINE_SUPPORT_ICB (1 << 3)
// [`RgfxRenderPipelineCreate`] `flags`: an [`RgfxRenderPipelinePrivateState`] follows the
// create's head, where the guest took [`RGFX_FEATURE_PRIVATE_RENDER_STATE`]. Bits 4 and 5 are
// the mesh create's.
#define RGFX_RENDER_PIPELINE_PRIVATE_STATE (1 << 6)
// [`RgfxRenderPipelinePrivateState`] `flags`: `openGLModeEnabled`.
#define RGFX_PRIVATE_RENDER_OPENGL_MODE (1 << 0)
// [`RgfxRenderPipelinePrivateState`] `flags`: `sampleCoverageInvert`.
#define RGFX_PRIVATE_RENDER_SAMPLE_COVERAGE_INVERT (1 << 1)
// [`RgfxRenderPipelinePrivateState`] `flags`: `logicOperationEnabled`.
#define RGFX_PRIVATE_RENDER_LOGIC_OPERATION (1 << 2)
// [`RgfxRenderPipelinePrivateState`] `flags`: `depthStencilWriteDisabled`.
#define RGFX_PRIVATE_RENDER_DEPTH_STENCIL_WRITE_DISABLED (1 << 3)
// [`RgfxMeshRenderPipelineCreate`] `flags`, beside the `RGFX_RENDER_PIPELINE_*` ones:
// `objectThreadgroupSizeIsMultipleOfThreadExecutionWidth`.
#define RGFX_MESH_PIPELINE_OBJECT_TG_MULTIPLE_OF_EXEC_WIDTH (1 << 4)
@@ -5842,8 +5868,10 @@ typedef struct {
// [`RgfxColorAttachmentDesc`] in use. The vertex and fragment stages' linked
// functions (`vertexLinkedFunctions`, `fragmentLinkedFunctions`) are runs of
// [`RgfxLinkedFunction`] in the tail. The optional pipeline `label` is tail
// bytes (`label_len` 0 for none). The whole message's `size` is the fixed head
// plus the tail, rounded up to a multiple of 8.
// bytes (`label_len` 0 for none). With [`RGFX_RENDER_PIPELINE_PRIVATE_STATE`] in
// `flags`, an [`RgfxRenderPipelinePrivateState`] follows the head, ahead of the
// tail. The whole message's `size` is the fixed head plus the tail, rounded up
// to a multiple of 8.
typedef struct {
// [`RGFX_CMD_RENDER_PIPELINE_CREATE`].
RgfxMsgHeader header;
@@ -5910,6 +5938,26 @@ typedef struct {
uint32_t fragment_linked_count;
} RgfxRenderPipelineCreate;
// A render pipeline descriptor's private state (Apple SPI), as Apple's OpenGL renderer sets it,
// after an [`RgfxRenderPipelineCreate`]'s head where its `flags` carry
// [`RGFX_RENDER_PIPELINE_PRIVATE_STATE`]: each field the guest's descriptor's value. Measured on
// the Intel 630 (macOS 26.7.1): every pipeline of the renderer sets `openGLModeEnabled`, a
// `sampleMask` of `0xffffffff` (or the GL sample mask) and a `logicOperation` of copy (2); a GL
// logic operation sets `logicOperationEnabled` and its operation, GL's sample coverage
// `sampleCoverage`, and a pipeline that writes no depth or stencil `depthStencilWriteDisabled`.
typedef struct {
// `sampleMask`.
uint64_t sample_mask;
// `sampleCoverage`, its `f32` bits.
uint32_t sample_coverage;
// `logicOperation`, the raw value (GL's copy is 2 and its XOR 10, measured).
uint32_t logic_operation;
// The `RGFX_PRIVATE_RENDER_*` flags.
uint32_t flags;
// Pads to a multiple of 8; 0.
uint32_t reserved_14;
} RgfxRenderPipelinePrivateState;
// One element of a resource array ([`RgfxOpUseResources`] and the like): a resource
// (0 = nil) and its [kind](RGFX_RESOURCE_KIND_BUFFER), which says how the host
// resolves it.
+3 -2
View File
@@ -246,7 +246,7 @@ impl Room {
const MIN_QUEUE_RING_DATA: u64 = 4096;
/// The feature bits whose meaning the host knows, which a `DRIVER_FEATURES` write may take:
/// `RGFX_FEATURE_*`, bits 0 to 8 and 11 to 26.
/// `RGFX_FEATURE_*`, bits 0 to 8, 11 to 26 and 28.
const KNOWN_FEATURES: u64 = (RGFX_FEATURE_SURFACE_PAGES
| RGFX_FEATURE_SURFACE_CACHE
| RGFX_FEATURE_CB_SUBMITTED
@@ -271,7 +271,8 @@ const KNOWN_FEATURES: u64 = (RGFX_FEATURE_SURFACE_PAGES
| RGFX_FEATURE_SMALL_ID_CHUNKS
| RGFX_FEATURE_DISPLAY_COLOR
| RGFX_FEATURE_MESH_PIPELINES
| RGFX_FEATURE_SHARED_EVENT_NAMES) as u64;
| RGFX_FEATURE_SHARED_EVENT_NAMES
| RGFX_FEATURE_PRIVATE_RENDER_STATE) as u64;
/// The `RGFX_QUEUE_*` flags the host carries out, each with the feature the guest's driver must
/// take for a `QUEUE_CREATE` to ask for it: [`RGFX_QUEUE_UNSHARED`] alone, so a create that asks
+27
View File
@@ -2530,6 +2530,33 @@ fn the_deferred_budget_reads_as_the_host_gives_it() {
assert_eq!(budget(), (0x2345_6000, 1));
}
/// A host that offers `PRIVATE_RENDER_STATE` lets the driver take it: the driver's write reads
/// back
#[test]
fn the_driver_takes_private_render_state_where_offered() {
struct Private;
impl Host for Private {
fn raise_interrupt(&self, _vector: u32) {}
fn scanout_written(&self, _offset: u64, _length: u64) -> bool {
false
}
fn features(&self) -> u64 {
u64::from(RGFX_FEATURE_PRIVATE_RENDER_STATE)
}
}
let rig = Rig::with_host(Box::new(Private));
rig.device
.mmio_write(RGFX_REG_STATUS.into(), RGFX_STATUS_RESET);
rig.device.mmio_write(
RGFX_REG_DRIVER_FEATURES_LO.into(),
RGFX_FEATURE_PRIVATE_RENDER_STATE,
);
assert_eq!(
rig.device.mmio_read(RGFX_REG_DRIVER_FEATURES_LO.into()),
RGFX_FEATURE_PRIVATE_RENDER_STATE
);
}
/// `HOST_TIME_LO` and `_HI` read the host's monotonic clock, the one each `VBLANK` is stamped on,
/// once the driver took `HOST_TIME`: a read of `HI`, `LO` and `HI` again lies between two of the
/// host's own. They read 0 before the driver took it, and again after a reset
+51 -4
View File
@@ -63,8 +63,8 @@ pub const RGFX_REG_VERSION: u32 = 0x004;
/// [`RGFX_FEATURE_SURFACE_DEFERRED`], [`RGFX_FEATURE_HOST_TIME`],
/// [`RGFX_FEATURE_MANAGED_TEXTURE_SLABS`], [`RGFX_FEATURE_MANAGED_BUFFER_SLABS`],
/// [`RGFX_FEATURE_SMALL_ID_CHUNKS`], [`RGFX_FEATURE_DISPLAY_COLOR`],
/// [`RGFX_FEATURE_MESH_PIPELINES`] and [`RGFX_FEATURE_SHARED_EVENT_NAMES`]). Bits 9 and 10 are
/// reserved.
/// [`RGFX_FEATURE_MESH_PIPELINES`], [`RGFX_FEATURE_SHARED_EVENT_NAMES`] and
/// [`RGFX_FEATURE_PRIVATE_RENDER_STATE`]). Bits 9 and 10 are reserved.
pub const RGFX_REG_FEATURES_LO: u32 = 0x008;
/// `FEATURES_HI`, RO: feature bits 32 to 63.
pub const RGFX_REG_FEATURES_HI: u32 = 0x00c;
@@ -226,6 +226,14 @@ pub const RGFX_FEATURE_MESH_PIPELINES: u32 = 1 << 25;
/// one holder's buffers and CPU give it are posted to every other holder
/// ([`RgfxSharedEventName::listen_queue_obj_id`]).
pub const RGFX_FEATURE_SHARED_EVENT_NAMES: u32 = 1 << 26;
/// `FEATURES_LO` bit 28, `PRIVATE_RENDER_STATE`, which the guest takes through
/// [`RGFX_REG_DRIVER_FEATURES_LO`]: a [`RgfxRenderPipelineCreate`] may carry
/// [`RGFX_RENDER_PIPELINE_PRIVATE_STATE`] and, after its head, the
/// [`RgfxRenderPipelinePrivateState`] of the guest's descriptor: the private state (Apple SPI)
/// Apple's OpenGL renderer sets, which the host's platform makes the pipeline with. A host offers
/// it only where its platform takes that state. A host without it reads the flag as no flag and
/// the record as tail no offset names, so the guest sends them only where it took the bit.
pub const RGFX_FEATURE_PRIVATE_RENDER_STATE: u32 = 1 << 28;
/// `STATUS`, RW: writing [`RGFX_STATUS_RESET`] resets the device; the guest writes
/// [`RGFX_STATUS_DRIVER_READY`] once it has read the rings' headers.
pub const RGFX_REG_STATUS: u32 = 0x010;
@@ -3265,6 +3273,19 @@ pub const RGFX_RENDER_PIPELINE_ALPHA_TO_ONE: u32 = 1 << 1;
pub const RGFX_RENDER_PIPELINE_RASTERIZATION_ENABLED: u32 = 1 << 2;
/// [`RgfxRenderPipelineCreate`] `flags`: `supportIndirectCommandBuffers`.
pub const RGFX_RENDER_PIPELINE_SUPPORT_ICB: u32 = 1 << 3;
/// [`RgfxRenderPipelineCreate`] `flags`: an [`RgfxRenderPipelinePrivateState`] follows the
/// create's head, where the guest took [`RGFX_FEATURE_PRIVATE_RENDER_STATE`]. Bits 4 and 5 are
/// the mesh create's.
pub const RGFX_RENDER_PIPELINE_PRIVATE_STATE: u32 = 1 << 6;
/// [`RgfxRenderPipelinePrivateState`] `flags`: `openGLModeEnabled`.
pub const RGFX_PRIVATE_RENDER_OPENGL_MODE: u32 = 1 << 0;
/// [`RgfxRenderPipelinePrivateState`] `flags`: `sampleCoverageInvert`.
pub const RGFX_PRIVATE_RENDER_SAMPLE_COVERAGE_INVERT: u32 = 1 << 1;
/// [`RgfxRenderPipelinePrivateState`] `flags`: `logicOperationEnabled`.
pub const RGFX_PRIVATE_RENDER_LOGIC_OPERATION: u32 = 1 << 2;
/// [`RgfxRenderPipelinePrivateState`] `flags`: `depthStencilWriteDisabled`.
pub const RGFX_PRIVATE_RENDER_DEPTH_STENCIL_WRITE_DISABLED: u32 = 1 << 3;
/// [`RgfxMeshRenderPipelineCreate`] `flags`, beside the `RGFX_RENDER_PIPELINE_*` ones:
/// `objectThreadgroupSizeIsMultipleOfThreadExecutionWidth`.
@@ -3430,8 +3451,10 @@ pub struct RgfxLinkedFunction {
/// [`RgfxColorAttachmentDesc`] in use. The vertex and fragment stages' linked
/// functions (`vertexLinkedFunctions`, `fragmentLinkedFunctions`) are runs of
/// [`RgfxLinkedFunction`] in the tail. The optional pipeline `label` is tail
/// bytes (`label_len` 0 for none). The whole message's `size` is the fixed head
/// plus the tail, rounded up to a multiple of 8.
/// bytes (`label_len` 0 for none). With [`RGFX_RENDER_PIPELINE_PRIVATE_STATE`] in
/// `flags`, an [`RgfxRenderPipelinePrivateState`] follows the head, ahead of the
/// tail. The whole message's `size` is the fixed head plus the tail, rounded up
/// to a multiple of 8.
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, PartialEq, Eq, FromBytes, IntoBytes, Immutable, KnownLayout,
@@ -3502,6 +3525,30 @@ pub struct RgfxRenderPipelineCreate {
pub fragment_linked_count: u32,
}
/// A render pipeline descriptor's private state (Apple SPI), as Apple's OpenGL renderer sets it,
/// after an [`RgfxRenderPipelineCreate`]'s head where its `flags` carry
/// [`RGFX_RENDER_PIPELINE_PRIVATE_STATE`]: each field the guest's descriptor's value. Measured on
/// the Intel 630 (macOS 26.7.1): every pipeline of the renderer sets `openGLModeEnabled`, a
/// `sampleMask` of `0xffffffff` (or the GL sample mask) and a `logicOperation` of copy (2); a GL
/// logic operation sets `logicOperationEnabled` and its operation, GL's sample coverage
/// `sampleCoverage`, and a pipeline that writes no depth or stencil `depthStencilWriteDisabled`.
#[repr(C)]
#[derive(
Clone, Copy, Debug, Default, PartialEq, Eq, FromBytes, IntoBytes, Immutable, KnownLayout,
)]
pub struct RgfxRenderPipelinePrivateState {
/// `sampleMask`.
pub sample_mask: u64,
/// `sampleCoverage`, its `f32` bits.
pub sample_coverage: u32,
/// `logicOperation`, the raw value (GL's copy is 2 and its XOR 10, measured).
pub logic_operation: u32,
/// The `RGFX_PRIVATE_RENDER_*` flags.
pub flags: u32,
/// Pads to a multiple of 8; 0.
pub reserved_14: u32,
}
/// `COMPUTE_PIPELINE_CREATE`: a compute pipeline from a function, answered by
/// [`RgfxPipelineReflection`] with this create's `seqno`. The compute function is
/// named by `function_library_obj_id` and an entry-point name in the tail
+7
View File
@@ -186,6 +186,13 @@ CHECK(RGFX_FEATURE_SURFACE_ORDER == (1 << 11));
CHECK(RGFX_FEATURE_SUBMIT_ROOM == (1 << 16));
CHECK(RGFX_EVT_SUBMIT_ROOM == 0x408);
CHECK(RGFX_FEATURE_SHARED_EVENT_NAMES == (1 << 26));
CHECK(RGFX_FEATURE_PRIVATE_RENDER_STATE == (1 << 28));
CHECK(RGFX_RENDER_PIPELINE_PRIVATE_STATE == (1 << 6));
CHECK(sizeof(RgfxRenderPipelinePrivateState) == 24);
CHECK(offsetof(RgfxRenderPipelinePrivateState, sample_coverage) == 8);
CHECK(offsetof(RgfxRenderPipelinePrivateState, logic_operation) == 12);
CHECK(offsetof(RgfxRenderPipelinePrivateState, flags) == 16);
CHECK(sizeof(RgfxRenderPipelineCreate) % 8 == 0);
CHECK(RGFX_CMD_SHARED_EVENT_NAME == 0x22f);
CHECK(RGFX_CMD_SHARED_EVENT_IMPORT == 0x230);
CHECK(RGFX_CMD_SHARED_EVENT_UNNAME == 0x231);
@@ -272,6 +272,11 @@ pub trait GpuDevice<P: Platform>: Handle {
/// family and feature set of the SDK, and the identity and capability getters. Read on each
/// call; only the graphics lane asks it, once per device.
fn identity_caps(&self) -> IdentityCaps;
/// Whether the device makes render pipelines with the private state Apple's OpenGL renderer
/// sets ([`FullRenderPipelineDesc::private_state`]): on the Metal platform, where Metal's
/// render pipeline descriptors answer each of its setters (SPI); on the Vulkan platform,
/// always. The graphics lane offers `PRIVATE_RENDER_STATE` where it does.
fn takes_private_render_state(&self) -> bool;
/// The bytes of the GPU's own memory the process may hold, as the platform answers at the
/// call: Metal's `recommendedMaxWorkingSetSize`; on the Vulkan platform the budget of the
/// device-local heaps (`VK_EXT_memory_budget`) where the device has the extension, else their
+39 -2
View File
@@ -398,8 +398,8 @@ impl<P: Platform> fmt::Debug for LinkedFunctionsDesc<P> {
/// value. Order: label, the vertex and fragment functions, the vertex descriptor, the colour
/// attachments at their indices, the depth and stencil formats, the raster sample count,
/// alpha-to-coverage, alpha-to-one, rasterization, the input primitive topology, the maximum
/// vertex amplification count, indirect command buffer support, then the vertex and fragment
/// stages' linked functions where they link any.
/// vertex amplification count, indirect command buffer support, the vertex and fragment stages'
/// linked functions where they link any, then the private state where the guest gave it.
pub struct FullRenderPipelineDesc<'a, P: Platform> {
/// `setLabel:`, when set.
pub label: Option<&'a str>,
@@ -433,6 +433,42 @@ pub struct FullRenderPipelineDesc<'a, P: Platform> {
pub vertex_linked: LinkedFunctionsDesc<P>,
/// `setFragmentLinkedFunctions:`, where the stage links any.
pub fragment_linked: LinkedFunctionsDesc<P>,
/// The private state Apple's OpenGL renderer sets, where the guest gave it; `None` leaves
/// Metal's. Only a device that answers [`takes_private_render_state`] is given it.
///
/// [`takes_private_render_state`]: super::device::GpuDevice::takes_private_render_state
pub private_state: Option<PrivateRenderDesc>,
}
/// The private state (Apple SPI) of an `MTLRenderPipelineDescriptor` that Apple's OpenGL renderer
/// sets on every pipeline, as a value: each field its setter's argument, the guest's raw value.
/// Order: `setOpenGLModeEnabled:`, `setSampleMask:`, `setSampleCoverage:`,
/// `setSampleCoverageInvert:`, `setLogicOperationEnabled:`, `setLogicOperation:`, then
/// `setDepthStencilWriteDisabled:`. [`Default`] gives Metal's defaults.
#[derive(Debug, Clone, Copy, PartialEq)]
#[allow(missing_docs)] // each field is its setter's argument, named after it
pub struct PrivateRenderDesc {
pub open_gl_mode_enabled: bool,
pub sample_mask: u64,
pub sample_coverage: f32,
pub sample_coverage_invert: bool,
pub logic_operation_enabled: bool,
pub logic_operation: u64,
pub depth_stencil_write_disabled: bool,
}
impl Default for PrivateRenderDesc {
fn default() -> Self {
PrivateRenderDesc {
open_gl_mode_enabled: false,
sample_mask: u64::MAX,
sample_coverage: 1.0,
sample_coverage_invert: false,
logic_operation_enabled: false,
logic_operation: 0,
depth_stencil_write_disabled: false,
}
}
}
impl<P: Platform> fmt::Debug for FullRenderPipelineDesc<'_, P> {
@@ -460,6 +496,7 @@ impl<P: Platform> fmt::Debug for FullRenderPipelineDesc<'_, P> {
)
.field("vertex_linked", &self.vertex_linked)
.field("fragment_linked", &self.fragment_linked)
.field("private_state", &self.private_state)
.finish()
}
}
@@ -593,6 +593,11 @@ impl GpuDevice<FakePlatform> for Fk<kind::Device> {
fake_identity_caps()
}
/// No: the fake device takes no private render state, unlogged.
fn takes_private_render_state(&self) -> bool {
false
}
/// The identity's working set ([`FAKE_OWN_MEMORY`]), unlogged.
fn own_memory_budget(&self) -> u64 {
FAKE_OWN_MEMORY
+74 -6
View File
@@ -38,8 +38,8 @@ use reims_vgpu_core::platform::values::{
AttachmentState, BufferDeallocator, BufferDesc, ColorAttachmentDesc, ColorAttachmentSet,
ComputePassDesc, DepthAttachmentSet, DepthStencilDesc, FullComputePipelineDesc,
FullMeshRenderPipelineDesc, FullRenderPipelineDesc, HeapDesc, IcbDesc, LinkedFunctionsDesc,
OptionSet, PassSet, RenderPipelineDesc, SamplerDesc, StageInputDesc, StencilAttachmentSet,
StencilDesc, TextureDesc, VertexDesc,
OptionSet, PassSet, PrivateRenderDesc, RenderPipelineDesc, SamplerDesc, StageInputDesc,
StencilAttachmentSet, StencilDesc, TextureDesc, VertexDesc,
};
use reims_vgpu_core::raise::{OnFault, RaiseResult};
use reims_vgpu_core::sync::Mutex;
@@ -52,7 +52,8 @@ use crate::platform::{MetalPlatform, Obj};
use crate::spi::classes::MTLBufferDescriptor;
use crate::spi::methods::{
AttachmentArraySpi, ForceResourceIndexSpi, HeapDescriptorSpi, IcbDescriptorSpi,
RenderPassDescriptorSpi, ResourceIndexDescriptorSpi, TextureDescriptorSpi,
RENDER_PIPELINE_PRIVATE_SETTERS, RenderPassDescriptorSpi, RenderPipelineDescriptorSpi,
ResourceIndexDescriptorSpi, TextureDescriptorSpi,
};
/// A sub-object getter's `+0` result as a handle, retained.
@@ -804,6 +805,51 @@ pub fn apply_full_render_pipeline(
o.setFragmentLinkedFunctions(Some(&linked))
});
}
if let Some(p) = &desc.private_state {
apply_private_render_state(p, o);
}
}
/// The private render state `p` onto the render pipeline descriptor `o`, in the value's order
/// ([`PrivateRenderDesc`]): each setter's SPI, which only a device that answers
/// [`private_render_state_available`] is sent.
fn apply_private_render_state(p: &PrivateRenderDesc, o: &MTLRenderPipelineDescriptor) {
msg::get("setOpenGLModeEnabled:", || {
o.setOpenGLModeEnabled(p.open_gl_mode_enabled)
});
msg::get("setSampleMask:", || o.setSampleMask(p.sample_mask));
msg::get("setSampleCoverage:", || {
o.setSampleCoverage(p.sample_coverage)
});
msg::get("setSampleCoverageInvert:", || {
o.setSampleCoverageInvert(p.sample_coverage_invert)
});
msg::get("setLogicOperationEnabled:", || {
o.setLogicOperationEnabled(p.logic_operation_enabled)
});
msg::get("setLogicOperation:", || {
o.setLogicOperation(p.logic_operation)
});
msg::get("setDepthStencilWriteDisabled:", || {
o.setDepthStencilWriteDisabled(p.depth_stencil_write_disabled)
});
}
/// Whether this Metal's render pipeline descriptors answer every setter of the private render
/// state Apple's OpenGL renderer sets ([`RENDER_PIPELINE_PRIVATE_SETTERS`]). Read once.
pub fn private_render_state_available() -> bool {
static AVAILABLE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*AVAILABLE.get_or_init(|| {
let d = msg::get("new", MTLRenderPipelineDescriptor::new);
RENDER_PIPELINE_PRIVATE_SETTERS.iter().all(|name| {
msg::get("respondsToSelector:", || {
objc2_foundation::NSObjectProtocol::respondsToSelector(
&*d,
objc2::runtime::Sel::register(name),
)
})
})
})
}
/// Applies the whole mesh render pipeline value `desc` to the fresh descriptor `d`, in the
@@ -1831,9 +1877,9 @@ mod tests {
/// The whole render value reaches the descriptor: every colour attachment it sets with its
/// blend state and write mask, the vertex descriptor's layouts and attributes, the depth and
/// stencil formats, the sample count, the flags, the topology, the amplification count and
/// each stage's linked functions in their lists; with no fragment function the descriptor's
/// is nil
/// stencil formats, the sample count, the flags, the topology, the amplification count,
/// each stage's linked functions in their lists and the private state; with no fragment
/// function the descriptor's is nil
#[test]
fn a_whole_render_value_reaches_the_descriptor() {
use reims_vgpu_core::platform::values::{AttributeDesc, BufferLayoutDesc};
@@ -1892,11 +1938,33 @@ mod tests {
private_functions: vec![k.function.clone_ref()],
..LinkedFunctionsDesc::default()
},
private_state: Some(PrivateRenderDesc {
open_gl_mode_enabled: true,
sample_mask: 3,
sample_coverage: 0.5,
sample_coverage_invert: true,
logic_operation_enabled: true,
logic_operation: 10,
depth_stencil_write_disabled: true,
}),
},
&x,
);
let o = x.get();
assert!(o.fragmentFunction().is_none());
// The private state, read back by key.
assert!(private_render_state_available());
let value = |key: &str| -> Retained<objc2_foundation::NSNumber> {
// SAFETY: key-value coding of a property the descriptor declares, a number.
unsafe { objc2::msg_send![o, valueForKey: &*NSString::from_str(key)] }
};
assert!(value("openGLModeEnabled").boolValue());
assert_eq!(value("sampleMask").unsignedLongLongValue(), 3);
assert_eq!(value("sampleCoverage").floatValue(), 0.5);
assert!(value("sampleCoverageInvert").boolValue());
assert!(value("logicOperationEnabled").boolValue());
assert_eq!(value("logicOperation").unsignedLongLongValue(), 10);
assert!(value("depthStencilWriteDisabled").boolValue());
let (v, f) = (o.vertexLinkedFunctions(), o.fragmentLinkedFunctions());
let count = |a: Option<Retained<NSArray<ProtocolObject<dyn MTLFunction>>>>| {
a.map_or(0, |a| a.count())
+137
View File
@@ -780,6 +780,12 @@ impl GpuDevice<MetalPlatform> for MetalDevice {
read_identity_caps(self)
}
/// Where Metal's render pipeline descriptors answer every setter of the private state Apple's
/// OpenGL renderer sets (SPI; measured on the Intel 630 on macOS 26.7.1 through the renderer).
fn takes_private_render_state(&self) -> bool {
crate::gpu::desc::private_render_state_available()
}
fn own_memory_budget(&self) -> u64 {
let d = self.get();
msg::get("recommendedMaxWorkingSetSize", || {
@@ -2106,6 +2112,137 @@ vertex float4 vmain(uint v [[vertex_id]]) { return float4(0, 0, 0, 1); }
);
}
use reims_vgpu_core::num::ToU64;
use reims_vgpu_core::platform::values::{ColorAttachmentDesc, PrivateRenderDesc};
/// A full-screen triangle whose fragment writes (1, 1, 0, 0).
const PRIVATE_STATE_SOURCE: &str = "#include <metal_stdlib>
using namespace metal;
vertex float4 vmain(uint v [[vertex_id]]) {
return float4(v == 1 ? 3.0 : -1.0, v == 2 ? 3.0 : -1.0, 0.5, 1.0);
}
fragment float4 fmain() { return float4(1.0, 1.0, 0.0, 0.0); }
";
/// What a draw of [`PRIVATE_STATE_SOURCE`] by a pipeline of the private state `private`
/// leaves in an RGBA8 texel cleared to (64, 128, 191, 255).
fn drawn_with(private: Option<PrivateRenderDesc>) -> [u8; 4] {
use objc2_metal::{
MTLClearColor, MTLCommandBuffer as _, MTLCommandEncoder as _, MTLDevice as _,
MTLLoadAction, MTLOrigin, MTLPrimitiveType, MTLRegion, MTLRenderCommandEncoder as _,
MTLRenderPassDescriptor, MTLStoreAction, MTLTextureUsage,
};
let d = dev();
let library = Obj::from_retained(
objc2_metal::MTLDevice::newLibraryWithSource_options_error(
d.get(),
&NSString::from_str(PRIVATE_STATE_SOURCE),
None,
)
.expect("the functions compile"),
);
let (v, f) = (function(&library, "vmain"), function(&library, "fmain"));
let color = ColorAttachmentDesc {
pixel_format: MTLPixelFormat::RGBA8Unorm.0.to_u64(),
write_mask: 0xf,
..ColorAttachmentDesc::default()
};
let state = d
.new_render_pipeline_state_full(&FullRenderPipelineDesc {
label: None,
vertex: &v,
fragment: Some(&f),
vertex_descriptor: None,
colors: vec![(0, color)],
depth_pixel_format: 0,
stencil_pixel_format: 0,
raster_sample_count: 1,
alpha_to_coverage: false,
alpha_to_one: false,
rasterization_enabled: true,
input_primitive_topology: 0,
max_vertex_amplification_count: 1,
support_indirect_command_buffers: false,
vertex_linked: Default::default(),
fragment_linked: Default::default(),
private_state: private,
})
.unwrap()
.expect("a render pipeline");
let td = texture_descriptor(4, 4, MTLStorageMode::Shared);
td.get().setPixelFormat(MTLPixelFormat::RGBA8Unorm);
td.get().setUsage(MTLTextureUsage::RenderTarget);
let texture = d.get().newTextureWithDescriptor(td.get()).unwrap();
let pass = MTLRenderPassDescriptor::new();
// SAFETY: index 0 of the colour attachments.
let a = unsafe { pass.colorAttachments().objectAtIndexedSubscript(0) };
a.setTexture(Some(&texture));
a.setLoadAction(MTLLoadAction::Clear);
a.setStoreAction(MTLStoreAction::Store);
a.setClearColor(MTLClearColor {
red: 64.0 / 255.0,
green: 128.0 / 255.0,
blue: 191.0 / 255.0,
alpha: 1.0,
});
let queue = d.get().newCommandQueue().unwrap();
let cb = queue.commandBuffer().unwrap();
let e = cb.renderCommandEncoderWithDescriptor(&pass).unwrap();
e.setRenderPipelineState(state.get());
// SAFETY: three vertices of a function that reads no buffer.
unsafe { e.drawPrimitives_vertexStart_vertexCount(MTLPrimitiveType::Triangle, 0, 3) };
e.endEncoding();
cb.commit();
cb.waitUntilCompleted();
let mut texel = [0u8; 4];
// SAFETY: one texel of a Shared RGBA8 texture the GPU is done with, into 4 bytes.
unsafe {
texture.getBytes_bytesPerRow_fromRegion_mipmapLevel(
std::ptr::NonNull::from(&mut texel).cast(),
16,
MTLRegion {
origin: MTLOrigin { x: 1, y: 1, z: 0 },
size: MtlSizeObjc {
width: 1,
height: 1,
depth: 1,
},
},
0,
);
}
texel
}
/// A render pipeline of the private state Apple's OpenGL renderer sets draws as Metal draws
/// it: at the renderer's defaults (OpenGL mode, a sample mask of `0xffffffff`, copy, no depth
/// or stencil writes) the fragment's colour, under GL's XOR the codes XORed into the clear's,
/// and under a sample mask of 0 nothing
#[test]
fn private_render_state_draws_as_metal_draws() {
assert!(dev().takes_private_render_state());
let renderer = PrivateRenderDesc {
open_gl_mode_enabled: true,
sample_mask: 0xffff_ffff,
logic_operation: 2,
depth_stencil_write_disabled: true,
..PrivateRenderDesc::default()
};
assert_eq!(drawn_with(None), [255, 255, 0, 0]);
assert_eq!(drawn_with(Some(renderer)), [255, 255, 0, 0]);
let xor = PrivateRenderDesc {
logic_operation_enabled: true,
logic_operation: 10,
..renderer
};
assert_eq!(drawn_with(Some(xor)), [191, 127, 191, 255]);
let masked = PrivateRenderDesc {
sample_mask: 0,
..renderer
};
assert_eq!(drawn_with(Some(masked)), [64, 128, 191, 255]);
}
fn render_descriptor(lib: &MetalLibrary) -> MetalRenderPipelineDescriptor {
let rd = MTLRenderPipelineDescriptor::new();
rd.setVertexFunction(Some(function(lib, "displayPresentVertex").get()));
@@ -1396,6 +1396,50 @@ pub unsafe trait RenderPassDescriptorSpi: Message {
// SAFETY: an `MTLRenderPassDescriptor`.
unsafe impl RenderPassDescriptorSpi for MTLRenderPassDescriptor {}
/// The private render state of `MTLRenderPipelineDescriptor` (SPI) that Apple's OpenGL renderer
/// sets, where the descriptor answers each setter ([`RENDER_PIPELINE_PRIVATE_SETTERS`]).
///
/// # Safety
/// The implementor is an `MTLRenderPipelineDescriptor`.
pub unsafe trait RenderPipelineDescriptorSpi: Message {
fn setOpenGLModeEnabled(&self, enabled: bool) {
unsafe { msg_send![self, setOpenGLModeEnabled: enabled] }
}
fn setSampleMask(&self, mask: u64) {
unsafe { msg_send![self, setSampleMask: mask] }
}
fn setSampleCoverage(&self, coverage: f32) {
unsafe { msg_send![self, setSampleCoverage: coverage] }
}
fn setSampleCoverageInvert(&self, invert: bool) {
unsafe { msg_send![self, setSampleCoverageInvert: invert] }
}
fn setLogicOperationEnabled(&self, enabled: bool) {
unsafe { msg_send![self, setLogicOperationEnabled: enabled] }
}
fn setLogicOperation(&self, operation: u64) {
unsafe { msg_send![self, setLogicOperation: operation] }
}
fn setDepthStencilWriteDisabled(&self, disabled: bool) {
unsafe { msg_send![self, setDepthStencilWriteDisabled: disabled] }
}
}
/// The setters of [`RenderPipelineDescriptorSpi`], each of which a descriptor must answer for
/// the platform to take the private render state.
pub const RENDER_PIPELINE_PRIVATE_SETTERS: [&std::ffi::CStr; 7] = [
c"setOpenGLModeEnabled:",
c"setSampleMask:",
c"setSampleCoverage:",
c"setSampleCoverageInvert:",
c"setLogicOperationEnabled:",
c"setLogicOperation:",
c"setDepthStencilWriteDisabled:",
];
// SAFETY: an `MTLRenderPipelineDescriptor`.
unsafe impl RenderPipelineDescriptorSpi for MTLRenderPipelineDescriptor {}
/// `MTLIndirectCommandBufferDescriptorSPI`.
///
/// # Safety
@@ -1711,6 +1711,12 @@ impl GpuDevice<VulkanPlatform> for VulkanDevice {
crate::gpu::identity::read(&self.raw, &self.caps())
}
/// Always: the runtime's render pipeline descriptors hold the private state, but
/// `openGLModeEnabled` (`states::new_render_pipeline_state_full`).
fn takes_private_render_state(&self) -> bool {
true
}
fn own_memory_budget(&self) -> u64 {
crate::gpu::identity::device_local_budget(&self.raw)
}
@@ -215,6 +215,7 @@ impl Frame {
support_indirect_command_buffers: false,
vertex_linked: LinkedFunctionsDesc::default(),
fragment_linked: LinkedFunctionsDesc::default(),
private_state: None,
})
.unwrap()
.unwrap()
+56 -5
View File
@@ -162,8 +162,8 @@ use reims_vgpu_core::platform::resource::RenderPipeline as _;
use reims_vgpu_core::platform::types::{MtlSize, NsErrorText};
use reims_vgpu_core::platform::values::{
ColorAttachmentDesc, DepthStencilDesc, FullComputePipelineDesc, FullMeshRenderPipelineDesc,
FullRenderPipelineDesc, LinkedFunctionsDesc, RenderPipelineDesc, SamplerDesc, StageInputDesc,
StencilDesc, VertexDesc,
FullRenderPipelineDesc, LinkedFunctionsDesc, PrivateRenderDesc, RenderPipelineDesc,
SamplerDesc, StageInputDesc, StencilDesc, VertexDesc,
};
use reims_vgpu_core::raise::RaiseResult;
use reims_vgpu_core::sync::Mutex;
@@ -531,9 +531,11 @@ pub(crate) fn new_render_pipeline_state(
}
/// `newRenderPipelineStateWithDescriptor:error:` of the whole value `desc`, the graphics lane's:
/// every field the value carries is the runtime descriptor's own. A raw value the runtime has no
/// enumerator of dies at the send ([`metal_value`]); so does the compile's refusal where Metal
/// answers no `NSError` ([`made`]). The lane calls it inside its refusal scope.
/// every field the value carries is the runtime descriptor's own, the private state its
/// [`PrivateRenderState`](metal2vulkan::pipeline::PrivateRenderState) but `openGLModeEnabled`
/// ([`private_state`]). A raw value the runtime has no enumerator of dies at the send
/// ([`metal_value`]); so does the compile's refusal where Metal answers no `NSError` ([`made`]).
/// The lane calls it inside its refusal scope.
pub(crate) fn new_render_pipeline_state_full(
device: &VulkanDevice,
desc: &FullRenderPipelineDesc<'_, VulkanPlatform>,
@@ -578,6 +580,9 @@ pub(crate) fn new_render_pipeline_state_full(
desc.max_vertex_amplification_count,
);
d.support_indirect_command_buffers = desc.support_indirect_command_buffers;
if let Some(p) = &desc.private_state {
private_state(&mut d.private, p);
}
let mut options = rt::PipelineOptions::default();
options.label = desc.label.map(str::to_owned);
timing::creation(
@@ -867,6 +872,23 @@ fn linked_functions(l: &LinkedFunctionsDesc<VulkanPlatform>) -> LinkedFunctions
out
}
/// The private state `p` (the graphics wire's, as Apple's OpenGL renderer sets it) into the
/// runtime's `private`: the sample mask and coverage, the coverage inversion, the logic operation
/// and its switch, and the depth-stencil write switch, each the guest's raw value.
///
/// `openGLModeEnabled`, which the renderer sets on every pipeline, the runtime has no field for:
/// it is dropped here, an interim divergence from Metal, which makes the pipeline with it, until
/// metal2vulkan measures what it changes on Apple's Metal and gives it a field and rule or calls
/// it inert.
fn private_state(private: &mut metal2vulkan::pipeline::PrivateRenderState, p: &PrivateRenderDesc) {
private.sample_mask = p.sample_mask;
private.sample_coverage = p.sample_coverage;
private.sample_coverage_invert = p.sample_coverage_invert;
private.logic_operation_enabled = p.logic_operation_enabled;
private.logic_operation = p.logic_operation;
private.depth_stencil_write_disabled = p.depth_stencil_write_disabled;
}
/// The runtime's colour attachment of a whole value's: none for `MTLPixelFormatInvalid`.
fn full_color_attachment(
sel: &'static str,
@@ -1409,6 +1431,7 @@ mod tests {
support_indirect_command_buffers: false,
vertex_linked: LinkedFunctionsDesc::default(),
fragment_linked: LinkedFunctionsDesc::default(),
private_state: None,
}
}
@@ -1783,6 +1806,7 @@ mod tests {
functions: vec![linked.clone_ref()],
..LinkedFunctionsDesc::default()
},
private_state: None,
})
.ok()??;
let out = d
@@ -2468,6 +2492,33 @@ mod tests {
);
}
/// The graphics wire's private render state fills the runtime's, each field the guest's value
/// but `openGLModeEnabled`, which it has no field for; the rest stay Metal's defaults
#[test]
fn the_private_render_state_fills_the_runtimes() {
let mut private = metal2vulkan::pipeline::PrivateRenderState::new();
private_state(
&mut private,
&PrivateRenderDesc {
open_gl_mode_enabled: true,
sample_mask: 3,
sample_coverage: 0.5,
sample_coverage_invert: true,
logic_operation_enabled: true,
logic_operation: 10,
depth_stencil_write_disabled: true,
},
);
let mut want = metal2vulkan::pipeline::PrivateRenderState::new();
want.sample_mask = 3;
want.sample_coverage = 0.5;
want.sample_coverage_invert = true;
want.logic_operation_enabled = true;
want.logic_operation = 10;
want.depth_stencil_write_disabled = true;
assert_eq!(private, want);
}
#[cfg(target_os = "macos")]
mod metal_tests;
}
@@ -1605,6 +1605,7 @@ fn linked_answers<P: reims_vgpu_core::platform::Platform>(
support_indirect_command_buffers: false,
vertex_linked,
fragment_linked,
private_state: None,
})
.map(|state| state.map(drop))
}))
+18 -10
View File
@@ -54,15 +54,16 @@ use reims_graphics::wire::{
RGFX_FEATURE_HOST_TIME, RGFX_FEATURE_ICB_SLOTS, RGFX_FEATURE_INDIRECT_COMMAND_BUFFERS,
RGFX_FEATURE_MANAGED_AT_OFFSET, RGFX_FEATURE_MANAGED_BUFFER_SLABS,
RGFX_FEATURE_MANAGED_TEXTURE_SLABS, RGFX_FEATURE_MESH_PIPELINES, RGFX_FEATURE_PAGES_BUFFERS,
RGFX_FEATURE_SHARED_EVENT_NAMES, RGFX_FEATURE_SMALL_ID_CHUNKS, RGFX_FEATURE_SUBMIT_ROOM,
RGFX_FEATURE_SURFACE_CACHE, RGFX_FEATURE_SURFACE_DEFERRED, RGFX_FEATURE_SURFACE_ORDER,
RGFX_FEATURE_SURFACE_PAGES, RGFX_FEATURE_UNSHARED_QUEUES, RGFX_RESOURCE_ID_CHUNK,
RGFX_RESOURCE_ID_CHUNKS, RGFX_STATUS_INVALID_ARGUMENT, RGFX_STATUS_OK, RGFX_STATUS_REFUSED,
RGFX_VIDEO_CAPS_CODECS, RGFX_VIDEO_CAPS_OFFSET, RGFX_VIDEO_CAPS_OUTPUT_CACHED,
RGFX_VIDEO_CAPS_VERSION, RgfxBlockGrant, RgfxBlockRelease, RgfxBufferOverPages, RgfxCbComplete,
RgfxCbScheduled, RgfxCbSubmitted, RgfxColorEntry, RgfxDisplayColor, RgfxEventSignalled,
RgfxHeapOverPages, RgfxIcbState, RgfxLibraryLookup, RgfxMsgHeader, RgfxPageRun,
RgfxSamplerState, RgfxSharedEventName, RgfxSurfacePages, RgfxVideoCaps,
RGFX_FEATURE_PRIVATE_RENDER_STATE, RGFX_FEATURE_SHARED_EVENT_NAMES,
RGFX_FEATURE_SMALL_ID_CHUNKS, RGFX_FEATURE_SUBMIT_ROOM, RGFX_FEATURE_SURFACE_CACHE,
RGFX_FEATURE_SURFACE_DEFERRED, RGFX_FEATURE_SURFACE_ORDER, RGFX_FEATURE_SURFACE_PAGES,
RGFX_FEATURE_UNSHARED_QUEUES, RGFX_RESOURCE_ID_CHUNK, RGFX_RESOURCE_ID_CHUNKS,
RGFX_STATUS_INVALID_ARGUMENT, RGFX_STATUS_OK, RGFX_STATUS_REFUSED, RGFX_VIDEO_CAPS_CODECS,
RGFX_VIDEO_CAPS_OFFSET, RGFX_VIDEO_CAPS_OUTPUT_CACHED, RGFX_VIDEO_CAPS_VERSION, RgfxBlockGrant,
RgfxBlockRelease, RgfxBufferOverPages, RgfxCbComplete, RgfxCbScheduled, RgfxCbSubmitted,
RgfxColorEntry, RgfxDisplayColor, RgfxEventSignalled, RgfxHeapOverPages, RgfxIcbState,
RgfxLibraryLookup, RgfxMsgHeader, RgfxPageRun, RgfxSamplerState, RgfxSharedEventName,
RgfxSurfacePages, RgfxVideoCaps,
};
use reims_graphics::{
CompleteAnswer, CompletionPoster, CursorImage, Host, Mode, PresentAnswer, QueueClaim, Scanout,
@@ -301,7 +302,9 @@ impl<P: ApiPlatform> GraphicsDevice<P> {
// (`HEAP_OVER_PAGES`). Every host carries the display pipe's colour out
// (`DISPLAY_COLOR`), its window drawing through it, and names the shared events one
// process hands another (`SHARED_EVENT_NAMES`). A host whose GPU answers Metal3
// makes mesh render pipelines and draws them (`MESH_PIPELINES`).
// makes mesh render pipelines and draws them (`MESH_PIPELINES`). A host whose device
// takes the private render state Apple's OpenGL renderer sets makes the guest's
// render pipelines with it (`PRIVATE_RENDER_STATE`).
let in_place = u64::from(RGFX_FEATURE_SURFACE_PAGES)
| u64::from(RGFX_FEATURE_PAGES_BUFFERS)
| u64::from(RGFX_FEATURE_HEAP_OVER_PAGES);
@@ -318,6 +321,11 @@ impl<P: ApiPlatform> GraphicsDevice<P> {
| u64::from(RGFX_FEATURE_SMALL_ID_CHUNKS)
| u64::from(RGFX_FEATURE_DISPLAY_COLOR)
| u64::from(RGFX_FEATURE_SHARED_EVENT_NAMES)
| if gpu_device.takes_private_render_state() {
u64::from(RGFX_FEATURE_PRIVATE_RENDER_STATE)
} else {
0
}
| if meshes {
u64::from(RGFX_FEATURE_MESH_PIPELINES)
} else {
@@ -205,6 +205,7 @@ impl<P: ApiPlatform> Bench<P> {
support_indirect_command_buffers: true,
vertex_linked: LinkedFunctionsDesc::default(),
fragment_linked: LinkedFunctionsDesc::default(),
private_state: None,
})
.unwrap()
.unwrap();
+117 -14
View File
@@ -106,11 +106,14 @@ use reims_graphics::wire::{
RGFX_MESH_PIPELINE_OBJECT_TG_MULTIPLE_OF_EXEC_WIDTH, RGFX_PIPELINE_KIND_COMPUTE,
RGFX_PIPELINE_KIND_MESH, RGFX_PIPELINE_KIND_RENDER, RGFX_PIPELINE_OK,
RGFX_PIPELINE_REFLECT_SUPPORT_ICB, RGFX_PIPELINE_REFLECT_THREADGROUP_MATCHES_TILE,
RGFX_PIPELINE_REFUSED, RGFX_RENDER_PIPELINE_ALPHA_TO_COVERAGE,
RGFX_RENDER_PIPELINE_ALPHA_TO_ONE, RGFX_RENDER_PIPELINE_RASTERIZATION_ENABLED,
RGFX_RENDER_PIPELINE_SUPPORT_ICB, RGFX_RESOURCE_ID_CHUNK, RGFX_RESOURCE_ID_LIMIT,
RGFX_RESOURCE_ID_SMALL_CHUNK, RGFX_RESOURCE_ID_SMALL_CHUNKS, RGFX_STATUS_INVALID_ARGUMENT,
RGFX_STATUS_OK, RGFX_STATUS_REFUSED, RGFX_SURFACE_FACTS_OFFSET, RGFX_SURFACE_NO_WRITERS,
RGFX_PIPELINE_REFUSED, RGFX_PRIVATE_RENDER_DEPTH_STENCIL_WRITE_DISABLED,
RGFX_PRIVATE_RENDER_LOGIC_OPERATION, RGFX_PRIVATE_RENDER_OPENGL_MODE,
RGFX_PRIVATE_RENDER_SAMPLE_COVERAGE_INVERT, RGFX_RENDER_PIPELINE_ALPHA_TO_COVERAGE,
RGFX_RENDER_PIPELINE_ALPHA_TO_ONE, RGFX_RENDER_PIPELINE_PRIVATE_STATE,
RGFX_RENDER_PIPELINE_RASTERIZATION_ENABLED, RGFX_RENDER_PIPELINE_SUPPORT_ICB,
RGFX_RESOURCE_ID_CHUNK, RGFX_RESOURCE_ID_LIMIT, RGFX_RESOURCE_ID_SMALL_CHUNK,
RGFX_RESOURCE_ID_SMALL_CHUNKS, RGFX_STATUS_INVALID_ARGUMENT, RGFX_STATUS_OK,
RGFX_STATUS_REFUSED, RGFX_SURFACE_FACTS_OFFSET, RGFX_SURFACE_NO_WRITERS,
RGFX_SURFACE_PAGES_ATTACH, RGFX_SURFACE_PAGES_CACHED, RGFX_SURFACE_PAGES_DEFERRED,
RGFX_SURFACE_PAGES_PRIVATE, RGFX_YCBCR_MATRIX_DCI_P3, RGFX_YCBCR_MATRIX_ITU_R_601_4,
RGFX_YCBCR_MATRIX_ITU_R_709_2, RGFX_YCBCR_MATRIX_ITU_R_2020, RGFX_YCBCR_MATRIX_NONE,
@@ -121,11 +124,12 @@ use reims_graphics::wire::{
RgfxHeapCreate, RgfxHeapOverHostMemory, RgfxHeapOverPages, RgfxHeapTextureSizeAndAlign,
RgfxLinearTextureFromBuffer, RgfxLinkedFunction, RgfxMeshPipelineReflection,
RgfxMeshRenderPipelineCreate, RgfxMsgHeader, RgfxObjectCreate, RgfxObjectDestroy, RgfxPageRun,
RgfxPipelineReflection, RgfxQueueCreate, RgfxRenderPipelineCreate, RgfxResourceIdChunk,
RgfxSamplerCreate, RgfxSamplerState, RgfxSharedEventCreate, RgfxSharedEventSetValue,
RgfxSizeAndAlign, RgfxStencilDescriptor, RgfxSurfaceFacts, RgfxSurfacePages, RgfxSurfaceWriter,
RgfxSurfaceWriters, RgfxTextureCreate, RgfxTextureDescriptor, RgfxTextureFromBuffer,
RgfxTextureFromIOSurface, RgfxVertexAttribute, RgfxVertexBufferLayout, RgfxVideoSessionCreate,
RgfxPipelineReflection, RgfxQueueCreate, RgfxRenderPipelineCreate,
RgfxRenderPipelinePrivateState, RgfxResourceIdChunk, RgfxSamplerCreate, RgfxSamplerState,
RgfxSharedEventCreate, RgfxSharedEventSetValue, RgfxSizeAndAlign, RgfxStencilDescriptor,
RgfxSurfaceFacts, RgfxSurfacePages, RgfxSurfaceWriter, RgfxSurfaceWriters, RgfxTextureCreate,
RgfxTextureDescriptor, RgfxTextureFromBuffer, RgfxTextureFromIOSurface, RgfxVertexAttribute,
RgfxVertexBufferLayout, RgfxVideoSessionCreate,
};
use reims_vgpu_core::host::HostPtr;
use reims_vgpu_core::memory::map::MemoryMap;
@@ -140,8 +144,8 @@ use reims_vgpu_core::platform::types::{MtlSize, Swizzle};
use reims_vgpu_core::platform::values::{
AttributeDesc, BufferDesc, BufferLayoutDesc, ColorAttachmentDesc, DepthStencilDesc,
FullComputePipelineDesc, FullMeshRenderPipelineDesc, FullRenderPipelineDesc, HeapDesc,
LinkedFunctionsDesc, OptionSet, SamplerDesc, StageInputDesc, StencilDesc, SurfaceFacts,
SurfaceMatrix, SurfacePlane, TextureDesc, VertexDesc,
LinkedFunctionsDesc, OptionSet, PrivateRenderDesc, SamplerDesc, StageInputDesc, StencilDesc,
SurfaceFacts, SurfaceMatrix, SurfacePlane, TextureDesc, VertexDesc,
};
use reims_vgpu_core::platform::{Handle, HostRange, Platform};
use reims_vgpu_core::raise::{OnFault, Raise, RaiseResult, refusals};
@@ -3819,7 +3823,7 @@ enum LinkedList {
/// A render pipeline create's descriptor past its functions and label, owned: the fields of
/// [`FullRenderPipelineDesc`] the compile hands the platform with them.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq)]
struct RenderFields {
vertex_descriptor: Option<VertexDesc>,
colors: Vec<(u64, ColorAttachmentDesc)>,
@@ -3832,6 +3836,7 @@ struct RenderFields {
input_primitive_topology: u64,
max_vertex_amplification_count: u64,
support_indirect_command_buffers: bool,
private_state: Option<PrivateRenderDesc>,
}
/// A compute pipeline create's descriptor past its function and linked functions: the fields of
@@ -3873,7 +3878,8 @@ const LAST_VERTEX_INDEX: u32 = 30;
/// A render create's descriptor fields ([`RenderFields`]): the colour attachments in use, the
/// vertex descriptor's runs from the tail (none where it carries neither layouts nor
/// attributes), and the rest from the head.
/// attributes), the private state after the head where its flags carry
/// [`RGFX_RENDER_PIPELINE_PRIVATE_STATE`], and the rest from the head.
fn render_fields(
message: &[u8],
m: &RgfxRenderPipelineCreate,
@@ -3908,6 +3914,32 @@ fn render_fields(
input_primitive_topology: m.input_primitive_topology.into(),
max_vertex_amplification_count: m.max_vertex_amplification_count.into(),
support_indirect_command_buffers: m.flags & RGFX_RENDER_PIPELINE_SUPPORT_ICB != 0,
private_state: if m.flags & RGFX_RENDER_PIPELINE_PRIVATE_STATE != 0 {
Some(private_render_state(message)?)
} else {
None
},
})
}
/// The [`RgfxRenderPipelinePrivateState`] after a render create's head, as the platform's value:
/// each field the guest's raw value. A message too short to hold it is
/// [`DecodeError::Malformed`].
fn private_render_state(message: &[u8]) -> Result<PrivateRenderDesc, DecodeError> {
let at = size_of::<RgfxRenderPipelineCreate>();
let s = message
.get(at..)
.and_then(read::<RgfxRenderPipelinePrivateState>)
.ok_or(DecodeError::Malformed)?;
Ok(PrivateRenderDesc {
open_gl_mode_enabled: s.flags & RGFX_PRIVATE_RENDER_OPENGL_MODE != 0,
sample_mask: s.sample_mask,
sample_coverage: f32::from_bits(s.sample_coverage),
sample_coverage_invert: s.flags & RGFX_PRIVATE_RENDER_SAMPLE_COVERAGE_INVERT != 0,
logic_operation_enabled: s.flags & RGFX_PRIVATE_RENDER_LOGIC_OPERATION != 0,
logic_operation: s.logic_operation.into(),
depth_stencil_write_disabled: s.flags & RGFX_PRIVATE_RENDER_DEPTH_STENCIL_WRITE_DISABLED
!= 0,
})
}
@@ -4276,6 +4308,7 @@ pub(crate) fn compile_pipeline<P: Platform>(
support_indirect_command_buffers: fields.support_indirect_command_buffers,
vertex_linked,
fragment_linked,
private_state: fields.private_state,
};
// A nil state or an `NSError` refuses; a refusal Metal answers with none dies at the
// send, inside the caller's refusal scope.
@@ -7608,9 +7641,79 @@ mod tests {
input_primitive_topology: 3,
max_vertex_amplification_count: 2,
support_indirect_command_buffers: true,
private_state: None,
}
}
/// A render create with the private state after its head reaches the platform's creator with
/// it, each field the guest's raw value, and the tail past the record read as before; a
/// message that ends inside the record is malformed
#[test]
fn a_render_create_carries_its_private_state() {
let head = size_of::<RgfxRenderPipelineCreate>();
let state = RgfxRenderPipelinePrivateState {
sample_mask: 3,
sample_coverage: 0.5f32.to_bits(),
logic_operation: 10,
flags: RGFX_PRIVATE_RENDER_OPENGL_MODE
| RGFX_PRIVATE_RENDER_LOGIC_OPERATION
| RGFX_PRIVATE_RENDER_DEPTH_STENCIL_WRITE_DISABLED,
reserved_14: 0,
};
let name = b"vmain";
let name_at = head + size_of_val(&state);
let total = (name_at + name.len()).next_multiple_of(8);
let m = RgfxRenderPipelineCreate {
header: RgfxMsgHeader {
r#type: RGFX_CMD_RENDER_PIPELINE_CREATE,
size: total as u32,
seqno: 9,
},
obj_id: 100,
vertex_library_obj_id: 1,
vertex_name_offset: name_at as u32,
vertex_name_len: name.len() as u32,
raster_sample_count: 1,
flags: RGFX_RENDER_PIPELINE_PRIVATE_STATE,
..RgfxRenderPipelineCreate::default()
};
let mut message = m.as_bytes().to_vec();
message.extend_from_slice(state.as_bytes());
message.extend_from_slice(name);
message.resize(total, 0);
let want = PrivateRenderDesc {
open_gl_mode_enabled: true,
sample_mask: 3,
sample_coverage: 0.5,
sample_coverage_invert: false,
logic_operation_enabled: true,
logic_operation: 10,
depth_stencil_write_disabled: true,
};
assert_eq!(
render_fields(&message, &m).map(|f| f.private_state),
Ok(Some(want))
);
let (p, mut dec, replies) = pipeline_decoder();
let device = p.device();
assert_eq!(dec.decode(&device, &message).unwrap(), Ok(()));
assert_eq!(replies.lock()[0].status, RGFX_PIPELINE_OK);
let calls = p
.call_log()
.calls_to("newRenderPipelineStateWithDescriptor:error:");
let Arg::Val(logged) = &calls[0].args[0] else {
panic!("{:?}", calls[0].args);
};
assert!(
logged.contains(&format!("private_state: {:?}", Some(want))),
"{logged}"
);
assert_eq!(
render_fields(&message[..head + 8], &m).map(|f| f.private_state),
Err(DecodeError::Malformed)
);
}
/// Every field of a render create reaches the platform's creator, read from the wire as the
/// value holds it: the colour attachments in use with their blend state and write masks, the
/// vertex descriptor's layouts and attributes, the depth and stencil formats, the sample
+17
View File
@@ -866,6 +866,23 @@ only where no negotiation can carry it.
shared events one process hands another, and the host posts the values one
holder gives the event to the others' listen queues ("Shared events across
processes", below). Every host offers it, and the kext takes it.
- Bit 28 is `PRIVATE_RENDER_STATE`: a `RENDER_PIPELINE_CREATE` may carry
`RGFX_RENDER_PIPELINE_PRIVATE_STATE` (flag bit 6), and then an
`RgfxRenderPipelinePrivateState` (24 bytes) follows its head, ahead of the
tail. It holds the descriptor's private state that Apple's OpenGL renderer
sets: `openGLModeEnabled`, `sampleMask`, `sampleCoverage`,
`sampleCoverageInvert`, `logicOperationEnabled`, `logicOperation` and
`depthStencilWriteDisabled`, each the guest's raw value. The bundle reads
them by key from every render pipeline descriptor where the kext took the
bit. Measured on the Intel 630 (macOS 26.7.1), the renderer sets
`openGLModeEnabled`, a sample mask and copy (2) on every pipeline. It sets
a GL logic operation, sample mask or sample coverage as their properties.
It sets `depthStencilWriteDisabled` on a pipeline that writes no depth or
stencil. It does alpha test, two-sided colour and the point sprite origin
in its shaders. A host offers it where its platform takes that state. The
Metal platform does where its descriptors answer every setter. The Vulkan
platform always does, filling metal2vulkan's `PrivateRenderState` and
dropping `openGLModeEnabled`, which that state has no field for yet.
**BAR2: the region.** A 64-bit prefetchable BAR over host memory (1 GiB),
mapped write-back by the guest. The device places the control rings at fixed
+2
View File
@@ -742,6 +742,8 @@ RGFX_LOG_UNRECOGNIZED
_serializer->setQueueOpener(&rgfxKextQueueOpener, connContext);
_serializer->setQueueCloser(&rgfxKextQueueCloser, connContext);
_serializer->setAsker(&rgfxKextAsk, connContext);
_serializer->setCarriesPrivateRenderState((_caps.features() & RGFX_FEATURE_PRIVATE_RENDER_STATE) !=
0);
// Shared events cross processes through the kext's ports where the kext makes them and the
// host took the feature that names their events (RgfxUserClientABI.hpp,
// kRgfxSharedEventUserClientType).
+47 -2
View File
@@ -1,11 +1,12 @@
/*
* RgfxRenderPipelineState: see RgfxRenderPipelineState.h. Our own ObjC++; no Apple
* private SPI.
* RgfxRenderPipelineState: see RgfxRenderPipelineState.h. Our own ObjC++. Of Apple's private
* SPI it reads only the descriptor's private render state, by key, where the host takes it.
*/
#import "RgfxRenderPipelineState.h"
#import "RgfxUnsupported.h"
#include <cstring>
#include <vector>
#import "RgfxFunction.h"
@@ -186,6 +187,45 @@ void fillSize(uint32_t (&out)[3], MTLSize size)
out[2] = wire32(size.depth);
}
// The descriptor's value of its private property `key` (Apple SPI), read by key-value coding
// where the descriptor answers its getter (`key` or `is<Key>`); nil where it answers neither.
NSNumber *privateValue(MTLRenderPipelineDescriptor *d, NSString *key)
{
NSString *is = [NSString stringWithFormat:@"is%@%@", [key substringToIndex:1].uppercaseString,
[key substringFromIndex:1]];
if (![d respondsToSelector:NSSelectorFromString(key)] &&
![d respondsToSelector:NSSelectorFromString(is)])
return nil;
id v = [d valueForKey:key];
return [v isKindOfClass:[NSNumber class]] ? v : nil;
}
// The private state of `d` that Apple's OpenGL renderer sets (RgfxRenderPipelinePrivateState),
// each property Metal's default where the descriptor does not answer it: a sample mask of all
// ones, a coverage of 1, logic operation 0 and the flags off.
RgfxRenderPipelinePrivateState privateStateOf(MTLRenderPipelineDescriptor *d)
{
RgfxRenderPipelinePrivateState s = {};
NSNumber *v = privateValue(d, @"sampleMask");
s.sample_mask = v != nil ? v.unsignedLongLongValue : UINT64_MAX;
const float coverage = (v = privateValue(d, @"sampleCoverage")) != nil ? v.floatValue : 1.0f;
std::memcpy(&s.sample_coverage, &coverage, sizeof(coverage));
s.logic_operation = (v = privateValue(d, @"logicOperation")) != nil ? wire32(v.unsignedLongValue) : 0;
const struct {
NSString *key;
uint32_t flag;
} flags[] = {
{@"openGLModeEnabled", RGFX_PRIVATE_RENDER_OPENGL_MODE},
{@"sampleCoverageInvert", RGFX_PRIVATE_RENDER_SAMPLE_COVERAGE_INVERT},
{@"logicOperationEnabled", RGFX_PRIVATE_RENDER_LOGIC_OPERATION},
{@"depthStencilWriteDisabled", RGFX_PRIVATE_RENDER_DEPTH_STENCIL_WRITE_DISABLED},
};
for (const auto &f : flags)
if (privateValue(d, f.key).boolValue)
s.flags |= f.flag;
return s;
}
} // namespace
@implementation RgfxRenderPipelineState {
@@ -321,6 +361,11 @@ void fillSize(uint32_t (&out)[3], MTLSize size)
p.input_primitive_topology = static_cast<uint32_t>(descriptor.inputPrimitiveTopology);
p.max_vertex_amplification_count =
static_cast<uint32_t>(descriptor.maxVertexAmplificationCount);
RgfxRenderPipelinePrivateState privateState = {};
if (serializer->carriesPrivateRenderState()) {
privateState = privateStateOf(descriptor);
p.private_state = &privateState;
}
// Vertex descriptor (optional): scan for the in-use layouts and attributes.
std::vector<RgfxVertexBufferLayout> layouts;
+4 -1
View File
@@ -1035,6 +1035,9 @@ RgfxCreated RgfxSerializer::createRenderPipeline(const RgfxRenderPipelineParams
msg.obj_id = out.obj_id;
msg.vertex_library_obj_id = p.vertex.library;
msg.fragment_library_obj_id = p.fragment.library;
// The private state, where the create carries it, follows the head first of all.
if (p.private_state != nullptr)
(void)append(p.private_state, sizeof(*p.private_state));
uint32_t vlen = nameLen(p.vertex.entry_point);
msg.vertex_name_offset = append(p.vertex.entry_point, vlen);
@@ -1070,7 +1073,7 @@ RgfxCreated RgfxSerializer::createRenderPipeline(const RgfxRenderPipelineParams
msg.colors[i] = p.colors[i];
msg.depth_pixel_format = p.depth_pixel_format;
msg.stencil_pixel_format = p.stencil_pixel_format;
msg.flags = p.flags;
msg.flags = p.flags | (p.private_state != nullptr ? RGFX_RENDER_PIPELINE_PRIVATE_STATE : 0);
msg.input_primitive_topology = p.input_primitive_topology;
msg.max_vertex_amplification_count = p.max_vertex_amplification_count;
+8
View File
@@ -122,6 +122,9 @@ struct RgfxRenderPipelineParams {
uint32_t vertex_linked_count;
const RgfxLinkedFunctionRef *fragment_linked;
uint32_t fragment_linked_count;
/// The descriptor's private state, sent after the head with RGFX_RENDER_PIPELINE_PRIVATE_STATE;
/// null for none.
const RgfxRenderPipelinePrivateState *private_state;
};
/// A mesh render pipeline's descriptor, as MTLMeshRenderPipelineDescriptor gives it, in plain
@@ -279,6 +282,10 @@ public:
void setEventSharer(EventShareFn share, EventTakeFn take, void *context);
/// Whether events cross processes here: a sharer is set.
bool sharesEvents() const { return m_eventShare != nullptr; }
/// Whether render pipeline creates carry their descriptors' private state: the host took
/// RGFX_FEATURE_PRIVATE_RENDER_STATE. Set once, before the first create; off by default.
void setCarriesPrivateRenderState(bool carries) { m_privateRenderState = carries; }
bool carriesPrivateRenderState() const { return m_privateRenderState; }
/// Names shared event `event` for other processes: its port, 0 where none was given.
uint32_t shareEvent(RgfxObjId event);
/// The process's new shared event made of the one `port` names: its id in `obj_id` and the
@@ -609,6 +616,7 @@ private:
void *m_askContext = nullptr;
EventShareFn m_eventShare = nullptr;
EventTakeFn m_eventTake = nullptr;
bool m_privateRenderState = false;
void *m_eventContext = nullptr;
// heapTextureSizeAndAlign's answers, by the shape's bytes, under m_sizesLock.
+73
View File
@@ -3210,6 +3210,78 @@ void test_render_pipeline_routing()
CHECK(err2 != nil);
}
// A render pipeline create carries its descriptor's private state, as Apple's OpenGL renderer sets
// it, after its head where the host took RGFX_FEATURE_PRIVATE_RENDER_STATE, and not elsewhere: the
// state's properties at their values, Metal's defaults for the ones left alone.
void test_render_pipeline_private_state()
{
Fixture fx;
const uint8_t libBytes[] = {1, 2, 3, 4};
uint32_t libStatus = 0;
RgfxLibrary *lib = [RgfxLibrary libraryWithData:libBytes
length:sizeof(libBytes)
key:nullptr
device:nil
serializer:&fx.ser
status:&libStatus];
(void)nextMessage(fx.ring, RGFX_CMD_LIBRARY_CREATE);
MTLRenderPipelineDescriptor *desc = [[MTLRenderPipelineDescriptor alloc] init];
desc.vertexFunction = [lib newFunctionWithName:@"vmain"];
desc.fragmentFunction = [lib newFunctionWithName:@"fmain"];
desc.colorAttachments[0].pixelFormat = MTLPixelFormatRGBA8Unorm;
auto create = [&]() {
NSError *err = nil;
RgfxRenderPipelineState *ps =
[RgfxRenderPipelineState renderPipelineStateWithDescriptor:desc
device:nil
serializer:&fx.ser
error:&err];
CHECK(ps != nil && err == nil);
return nextMessage(fx.ring, RGFX_CMD_RENDER_PIPELINE_CREATE);
};
RgfxRenderPipelineCreate head;
RgfxRenderPipelinePrivateState state;
// Not carried: no flag, and the tail starts at the head's end.
auto bytes = create();
std::memcpy(&head, bytes.data(), sizeof(head));
CHECK((head.flags & RGFX_RENDER_PIPELINE_PRIVATE_STATE) == 0);
CHECK(head.vertex_name_offset == sizeof(head));
// Carried, at Metal's defaults.
fx.ser.setCarriesPrivateRenderState(true);
bytes = create();
std::memcpy(&head, bytes.data(), sizeof(head));
CHECK((head.flags & RGFX_RENDER_PIPELINE_PRIVATE_STATE) != 0);
CHECK(head.vertex_name_offset == sizeof(head) + sizeof(state));
CHECK(std::memcmp(bytes.data() + head.vertex_name_offset, "vmain", 5) == 0);
std::memcpy(&state, bytes.data() + sizeof(head), sizeof(state));
float coverage = 0;
std::memcpy(&coverage, &state.sample_coverage, sizeof(coverage));
CHECK(state.sample_mask == UINT64_MAX);
CHECK(coverage == 1.0f);
CHECK(state.logic_operation == 0 && state.flags == 0 && state.reserved_14 == 0);
// Carried, as the renderer sets it for an XOR logic operation, a sample mask and coverage.
[desc setValue:@YES forKey:@"openGLModeEnabled"];
[desc setValue:@3 forKey:@"sampleMask"];
[desc setValue:@0.5f forKey:@"sampleCoverage"];
[desc setValue:@YES forKey:@"sampleCoverageInvert"];
[desc setValue:@YES forKey:@"logicOperationEnabled"];
[desc setValue:@10 forKey:@"logicOperation"];
[desc setValue:@YES forKey:@"depthStencilWriteDisabled"];
bytes = create();
std::memcpy(&head, bytes.data(), sizeof(head));
std::memcpy(&state, bytes.data() + sizeof(head), sizeof(state));
std::memcpy(&coverage, &state.sample_coverage, sizeof(coverage));
CHECK(state.sample_mask == 3);
CHECK(coverage == 0.5f);
CHECK(state.logic_operation == 10);
CHECK(state.flags == (RGFX_PRIVATE_RENDER_OPENGL_MODE | RGFX_PRIVATE_RENDER_SAMPLE_COVERAGE_INVERT |
RGFX_PRIVATE_RENDER_LOGIC_OPERATION |
RGFX_PRIVATE_RENDER_DEPTH_STENCIL_WRITE_DISABLED));
}
// A mesh render pipeline create maps the MTLMeshRenderPipelineDescriptor into the wire: its three
// functions and label in the tail, its colours, flags, maxima, payload and required sizes in its
// head. Its answer's mesh limits are what the state answers, NSUIntegerMax for the wire's highest
@@ -15351,6 +15423,7 @@ int main(int argc, char **argv)
test_library_and_function_routing();
test_libraries_of_one_key_share_their_function_table();
test_render_pipeline_routing();
test_render_pipeline_private_state();
test_mesh_pipeline_routing();
test_mesh_pipeline_refusals();
test_invalid_mesh_descriptors_end_the_process();
+6 -3
View File
@@ -7,7 +7,7 @@
// DRIVER_FEATURES_LO and _HI after its reset and before DRIVER_READY with the bits the kext and its
// bundle carry out, masked by the offer, and reads back the ones the host took. A host older than
// the registers reads them as 0, so nothing from bit 3 is taken there. Of those bits the kext and
// its bundle carry out fifteen:
// its bundle carry out these:
// - PAGES_BUFFERS (bit 7): the kext makes pages blocks over a process's own memory
// (kRgfxAccelMethodPagesBlock), and the bundle lays its no-copy buffers over them
// (BUFFER_OVER_PAGES);
@@ -66,7 +66,9 @@
// - SHARED_EVENT_NAMES (bit 26): a process hands its shared event to another through a port of
// the kext's (RgfxSharedEventUserClient.hpp), for which the kext posts SHARED_EVENT_NAME,
// SHARED_EVENT_IMPORT and SHARED_EVENT_UNNAME, and the bundle's events take the values other
// holders give them on a queue of their own.
// holders give them on a queue of their own;
// - PRIVATE_RENDER_STATE (bit 28): the bundle's render pipeline creates carry their descriptors'
// private state (RGFX_RENDER_PIPELINE_PRIVATE_STATE), which needs nothing of the kext.
//
// The accelerator answers the bundle's Features call with the feature word (rgfxFeatureWord), and
// grants a queue's flags (kRgfxAccelMethodQueueCreate's seventh input) only where their feature
@@ -95,7 +97,8 @@ constexpr uint64_t kRgfxCarriedFeatures =
RGFX_FEATURE_ICB_SLOTS | RGFX_FEATURE_COMMIT_ORDER | RGFX_FEATURE_SURFACE_DEFERRED |
RGFX_FEATURE_HOST_TIME | RGFX_FEATURE_MANAGED_TEXTURE_SLABS |
RGFX_FEATURE_MANAGED_BUFFER_SLABS | RGFX_FEATURE_SMALL_ID_CHUNKS | RGFX_FEATURE_DISPLAY_COLOR |
RGFX_FEATURE_MESH_PIPELINES | RGFX_FEATURE_SHARED_EVENT_NAMES;
RGFX_FEATURE_MESH_PIPELINES | RGFX_FEATURE_SHARED_EVENT_NAMES |
RGFX_FEATURE_PRIVATE_RENDER_STATE;
// What the framebuffer writes to DRIVER_FEATURES, given the host's offer.
inline uint64_t rgfxDriverFeatures(uint64_t offered)
+10 -4
View File
@@ -69,9 +69,10 @@ constexpr uint64_t kSmallIds = RGFX_FEATURE_SMALL_ID_CHUNKS;
constexpr uint64_t kColor = RGFX_FEATURE_DISPLAY_COLOR;
constexpr uint64_t kMesh = RGFX_FEATURE_MESH_PIPELINES;
constexpr uint64_t kShares = RGFX_FEATURE_SHARED_EVENT_NAMES;
constexpr uint64_t kPrivate = RGFX_FEATURE_PRIVATE_RENDER_STATE;
constexpr uint64_t kCarried = kPages | kOrder | kIcb | kUnshared | kManaged | kHeaps | kRoom |
kSlots | kCommits | kDeferred | kTime | kTextureSlabs |
kBufferSlabs | kSmallIds | kColor | kMesh | kShares;
kBufferSlabs | kSmallIds | kColor | kMesh | kShares | kPrivate;
// Every bit the wire names from bit 3.
constexpr uint64_t kNew = kNotCarried | kCarried;
} // namespace
@@ -81,13 +82,13 @@ int main()
// Of the bits from 3 the kext carries out PAGES_BUFFERS, SURFACE_ORDER,
// INDIRECT_COMMAND_BUFFERS, UNSHARED_QUEUES, MANAGED_AT_OFFSET, HEAP_OVER_PAGES, SUBMIT_ROOM,
// ICB_SLOTS, COMMIT_ORDER, SURFACE_DEFERRED, HOST_TIME, MANAGED_TEXTURE_SLABS,
// MANAGED_BUFFER_SLABS, SMALL_ID_CHUNKS, DISPLAY_COLOR, MESH_PIPELINES and
// SHARED_EVENT_NAMES, and writes each only where offered.
// MANAGED_BUFFER_SLABS, SMALL_ID_CHUNKS, DISPLAY_COLOR, MESH_PIPELINES,
// SHARED_EVENT_NAMES and PRIVATE_RENDER_STATE, and writes each only where offered.
check(kRgfxCarriedFeatures == kCarried,
"the kext takes PAGES_BUFFERS, SURFACE_ORDER, ICBs, UNSHARED_QUEUES, MANAGED_AT_OFFSET, "
"HEAP_OVER_PAGES, SUBMIT_ROOM, ICB slots, COMMIT_ORDER, SURFACE_DEFERRED, HOST_TIME, "
"MANAGED_TEXTURE_SLABS, MANAGED_BUFFER_SLABS, SMALL_ID_CHUNKS, DISPLAY_COLOR, "
"MESH_PIPELINES and SHARED_EVENT_NAMES from bit 3");
"MESH_PIPELINES, SHARED_EVENT_NAMES and PRIVATE_RENDER_STATE from bit 3");
check(RGFX_FEATURE_PAGES_BUFFERS == (1u << 7), "PAGES_BUFFERS is bit 7");
check(RGFX_FEATURE_SURFACE_ORDER == (1u << 11), "SURFACE_ORDER is bit 11");
check(RGFX_FEATURE_INDIRECT_COMMAND_BUFFERS == (1u << 12), "INDIRECT_COMMAND_BUFFERS is bit 12");
@@ -148,6 +149,11 @@ int main()
"SHARED_EVENT_NAMES offered, written");
check(rgfxFeatureWord(kRgfxOfferedFeatures | kShares, 0) == kRgfxOfferedFeatures,
"SHARED_EVENT_NAMES offered but not taken is not in the word");
check(RGFX_FEATURE_PRIVATE_RENDER_STATE == (1u << 28), "PRIVATE_RENDER_STATE is bit 28");
check(rgfxDriverFeatures(kRgfxOfferedFeatures | kNotCarried | kPrivate) == kPrivate,
"PRIVATE_RENDER_STATE offered, written");
check(rgfxFeatureWord(kRgfxOfferedFeatures | kPrivate, 0) == kRgfxOfferedFeatures,
"PRIVATE_RENDER_STATE offered but not taken is not in the word");
check(rgfxDriverFeatures(0) == 0, "nothing offered, nothing written");
check(rgfxDriverFeatures(kRgfxOfferedFeatures | kNotCarried | (1ull << 40)) == 0,
"every other bit offered, none written");