commit 86ef32e79653bdb8af707af9cbe25de24085abfb
parent 220c39678afdbfaf1f41e31b7e26d417fb06955b
Author: anon <anon@example.com>
Date: Tue, 13 Oct 2026 08:33:56 +0000
Create Device7 and surface contracts for client-target browser startup
Diffstat:
1 file changed, 75 insertions(+), 0 deletions(-)
diff --git a/docs/browser-porting.md b/docs/browser-porting.md
@@ -853,3 +853,78 @@ creates the clipper, `0xbb333` binds HWND through clipper slot 8, and
The caller then releases its clipper reference at `0xbb34b`; the surface
must retain its own reference. Binding the window and owning this object
does not by itself implement GetClipList or arbitrary region clipping.
+
+### Device7 startup and default textures
+
+These observations use `client-target/bbr.dll` from the pinned 13.2 image
+set, SHA256 `0c61958075bb39a1848736aa515d81fd0830dfab706c2896d99d5d6ded45823d`.
+The translator reads every image from `client-target` and rejects hash
+mismatches before translating. Compact runtime addresses are assigned by the
+linker; the RVAs below remain relative to the original DLL.
+
+After attaching the depth surface to the color render target, Randy's
+initializer calls Direct3D7 CreateDevice. The resulting device owns references
+to its Direct3D interface and render target. BBR's capability object constructor
+at RVA `0xbcbf0` queries DirectDraw7 GetCaps, then Device7 GetCaps at `0xbcca6`.
+Surface attachments likewise retain the attached surface until the parent
+releases it.
+
+Device7 GetCaps receives a **236-byte D3DDEVICEDESC7 without a size prefix**.
+BBR reads line RasterCaps at +0x0c and triangle RasterCaps at +0x44. Only when
+both contain WBUFFER (`0x40000`) does it select ZENABLE=2; otherwise it uses
+ordinary ZENABLE=1. TextureFilterCaps is at +0x60, simultaneous texture count
+is a WORD at +0xba, and the device GUID starts at +0xc4. Texture dimension
+limits occupy DWORDs +0x7c through +0x88. These offsets were checked against
+the local x86 DirectX SDK headers and the pinned constructor assembly
+(REA evidence `ev_c970d015303eb1c3808378ddb1cd58777ae184b899e6fe882c9984eb3446e328`).
+
+Initial render-state assignments include CULLMODE=3, ZENABLE=1,
+ZWRITEENABLE=1, ZFUNC=4, SRCBLEND=5 and DESTBLEND=6. The cache constructor
+at `0xdb600` then queries many render states and texture stage states 1-24
+on stages 0-7. Getter outputs must be written and preserve previous setters;
+returning a successful HRESULT without output is insufficient.
+
+The next operation creates a 16x16 default texture. EnumTextureFormats invokes
+BBR callback RVA `0xb5680`, stdcall `(DDPIXELFORMAT*, context)`, returning with
+eight argument bytes removed. This callback compares all 32 descriptor bytes.
+The requested format 10 is ARGB4444; ARGB8888 is an accepted preferred fallback
+with DWORDs `[32, 0x41, 0, 32, 0xff0000, 0xff00, 0xff, 0xff000000]`.
+Skipping enumeration leaves the selected format zero and fails with `0xc8770bdb`.
+
+Texture creation obtains Direct3D through Device7 GetDirect3D, queries its
+DirectDraw7 interface, and stores a 20-byte D3DX record with surface
+SetPrivateData under GUID `684b06f3-ebae-11d2-81f4-00c04f68f299`.
+The record contains size, flags, original width, original height and mip count.
+Surface7 Lock receives a 124-byte descriptor; writable pixel storage is returned
+at +0x24. The client writes white texels and calls Unlock(null). The observed
+startup then queries the render target descriptor and issues a rectangular clear.
+OOR's display vtable at RVA `0x5214` contains thirteen six-byte import thunks
+at `0x41c0` through `0x4208`. In particular, `0x41d2` forwards to
+`D3DDisplaySystem_t::Clear(ARect const*, int, DisplaySystem_t::CopyFlag_e)`.
+These remain indirect translation entry points even though their targets
+are native imports already resolved by the linker.
+Later startup locks a rectangular surface region. The returned pixel pointer
+must advance by `top * pitch + left * bytes_per_pixel`, while the descriptor
+keeps the full surface pitch and dimensions. Unlock takes the matching RECT
+pointer, rather than the pixel pointer used by older surface interfaces.
+See [DirectDraw7 Lock](https://learn.microsoft.com/en-us/windows/win32/api/ddraw/nf-ddraw-idirectdrawsurface7-lock),
+[Unlock](https://learn.microsoft.com/en-us/windows/win32/api/ddraw/nf-ddraw-idirectdrawsurface7-unlock)
+and the compatible descriptor behavior in
+[Wine surface_lock](https://github.com/wine-mirror/wine/blob/master/dlls/ddraw/surface.c).
+
+The browser bridge renders in a worker-owned WebGL2 OffscreenCanvas. D3D row
+vector matrices upload as transposes; clip depth 0..w becomes -w..w. Readback
+rows must flip from bottom-up to top-down before writing DirectDraw pixels,
+and ARGB8888 surfaces require red/blue conversion from WebGL RGBA bytes.
+Clear rectangles use top-left D3D coordinates, unlike WebGL scissor coordinates.
+DirectDraw presentation is opaque: a D3D clear color with zero alpha must
+still display its RGB value. Guest alpha bytes remain available to texture
+operations, but the final canvas copy must not apply source-over alpha blending.
+
+The current Device7 drawing path is still a diagnostic: triangle lists with
+FVF `0x112` (XYZ, normal, UV; 32-byte stride), UV coloring, and depth testing.
+Textures, lighting, general render-state application and complete initial
+Direct3D state defaults remain unfinished. State setters retain values for
+the native startup cache; unset states currently read as zero. Unsupported
+device operations fail explicitly. Passing this startup boundary is not yet
+evidence of a playable AO scene.