Ric wrote: ↑Mon 20 Apr 2026, 19:24
... and definitions
Code: Select all
DIM D3D11_DEPTH_STENCILOP_DESC{StencilFailOp%,StencilDepthFailOp%, \
\ StencilPassOp%,StencilFunc%}
DIM D3D11_DEPTH_STENCIL_DESC{DepthEnable%,DepthWriteMask%,DepthFunc%, \
\ StencilEnable%,StencilReadMask&,StencilWriteMask&, \
\ FrontFace{}=D3D11_DEPTH_STENCILOP_DESC{}, \
\ BackFace{}=D3D11_DEPTH_STENCILOP_DESC{}}
If i use these in 32bit mode all works fine so i can presume that the variable/enumerations are correct and the alignment of the structures is incorrect.
How can something "work fine" but have "alignment ... incorrect"?
Ric wrote: ↑Mon 20 Apr 2026, 19:24
The obvious bit that stands out are the 2 single byte elements in the DEPTH_STENCIL_DESC, these are coded by the compiler in 32bit mode which ads the padding automatically(so AI says), I have tried adding pading and all is fine.
Do you mean eg:
Code: Select all
DIM D3D11_DEPTH_STENCIL_DESC {DepthEnable%,DepthWriteMask%,DepthFunc%, \
\ StencilEnable%,StencilReadMask&,StencilWriteMask&, \
\ Fill1&, Fill2&, \
\ FrontFace{}=D3D11_DEPTH_STENCILOP_DESC{}, \
\ BackFace{}=D3D11_DEPTH_STENCILOP_DESC{}}
Ric wrote: ↑Mon 20 Apr 2026, 19:24
When it comes to 64bit mode when the 2 extra bytes of padding are added this still leaves a DWORD missing
How do you KNOW? What precisely do you mean by "missing"?
I wrote a reply to this several days ago and it never appeared; in the course of that I googled for terms like:
alignment in D3D11_DEPTH_STENCIL_DESC
and I just did so again but not (I suspect) with the exact-same terms. THIS TIME googling for
field alignment in D3D11_DEPTH_STENCIL_DESC
showed (in the AI-generated summary) something odd (not what I remember from last time):
The D3D11_DEPTH_STENCIL_DESC structure is used to define the depth-stencil state in Direct3D 11 via the ID3D11Device::CreateDepthStencilState method. It controls how the output-merger stage performs depth and stencil testing.
Field Breakdown and Structure Alignment
The structure is defined in d3d11.h and generally follows standard C++ padding rules for 32-bit and 64-bit systems.
BOOL DepthEnable (4 bytes): Enables depth testing.
D3D11_DEPTH_WRITE_MASK DepthWriteMask (4 bytes): Enumeration (0 or 1).
D3D11_COMPARISON_FUNC DepthFunc (4 bytes): Enumeration (comparison function).
BOOL StencilEnable (4 bytes): Enables stencil testing.
UINT8 StencilReadMask (1 byte): Identifies portion of depth-stencil buffer for reading stencil data.
UINT8 StencilWriteMask (1 byte): Identifies portion of depth-stencil buffer for writing stencil data.
Padding (2 bytes): Implicit padding to align the next 4-byte member.
D3D11_DEPTH_STENCILOP_DESC FrontFace (8 bytes): Structure (2 x D3D11_STENCIL_OP, 1 x D3D11_COMPARISON_FUNC = 3 x 4-byte enums, however, D3D11_DEPTH_STENCILOP_DESC is typically packed tightly).
D3D11_DEPTH_STENCILOP_DESC BackFace (8 bytes): Structure (same as above)
I added the colour.
I thought I recalled "D3D11_DEPTH_STENCILOP_DESC" being 4 x 4 bytes not the 8 bytes that the text above says. And note it also says that those 8 bytes are madeup of 3 x 4 bytes ... packed tightly. I think that's AI fiction ... especially as when I asked:
D3D11_DEPTH_STENCILOP_DESC alignment
I got:
Structure Breakdown (32-bit/64-bit alignment)
StencilFailOp (D3D11_STENCIL_OP): 4 bytes (Enum)
StencilDepthFailOp (D3D11_STENCIL_OP): 4 bytes (Enum)
StencilPassOp (D3D11_STENCIL_OP): 4 bytes (Enum)
StencilFunc (D3D11_COMPARISON_FUNC): 4 bytes (Enum)
Total size: 16 bytes.
Key Alignment and Usage Considerations
Alignment: The structure is packed tightly. On modern 64-bit Windows systems, the structure remains 16 bytes due to the 4-byte enum size.
I also googled for: D3D11_DEPTH_STENCIL_DESC alignment
and got (I think) rubbish:
The D3D11_DEPTH_STENCIL_DESC structure is used in Direct3D 11 to define the depth-stencil state via the ID3D11Device::CreateDepthStencilState method.
Alignment and Structure Details:
Alignment: The structure consists of boolean (BOOL), enumeration (D3D11_DEPTH_WRITE_MASK, D3D11_COMPARISON_FUNC), and 8-bit integer (UINT8) types. It adheres to standard C++ structure alignment rules, with members typically aligned on 4-byte boundaries.
Size: The structure is relatively small, consisting of two bools, two enums, two D3D11_DEPTH_STENCILOP_DESC structs (which contain 4 bytes each), and a UINT8 mask.
My colouring again... I keep getting different answers!
Ric wrote: ↑Mon 20 Apr 2026, 19:24
... so i have tried the obvious and padded this with a DWORD. Unfortunately this still does not work.
Do you mean you followed Fill1& and FIll2& with Fill3% ? It seems unlikely (to me) that if all the fields inside D3D11_DEPTH_STENCILOP_DESC are 4 bytes long that that would be needed.
Ric wrote: ↑Mon 20 Apr 2026, 19:24
Another slightly annoying feature is that all parts of my code create successfully flagging no errors and returning addresses where it should and hRESULT = 0 where it should?
If you're defining data layouts incorrectly it very likely just means that the called functions are still seeing values for things just not those you intended. There's a lot of BOOLs & enums with low values so a lot of the bytes in some structures will just have zeros in them.