@hwnd%

Discussions related to graphics (2D and 3D), animation and games programming
Ric
Posts: 310
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I have just typed that in to the SDL IDE and get a bad command error. I have v1.42 and notice you are using v1.44. is this the reason?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 665
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Tue 07 Apr 2026, 21:53 I have v1.42 and notice you are using v1.44. is this the reason?
Is that a serious question? You try to use a recently-added feature and you're surprised that it's not present in a version that's nearly a year old? :lol:

Normally you would be getting a pop-up reminder every day that your version of BBCSDL is out of date, but if you're using both the 32-bit and 64-bit versions it will only alert you if the newer of the two is out-of-date.
Ric
Posts: 310
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Thank you , now sorted
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 310
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I now have the latest version as stated, but im not sure it helps. As you know a lot of D3D and openGL use matrices for vertices positioning and therefore requres matrix multiplication. How do i perform these using the native array multiplication functions without converting to and from float32?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 665
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Wed 08 Apr 2026, 09:17 How do i perform these using the native array multiplication functions without converting to and from float32?
I don't really understand the question. If they are native (Direct3D) array multiplication functions then you do have to convert to (and possibly also from) float32. That's why *FLOAT 32 is useful, because it allows you to do that conversion in BBC BASIC more quickly than any other way, apart from using assembly language.

I compared using *FLOAT32 with FN_f4(), and for a million conversions to float32 there was more than an 8-fold speed improvement:

Time using FN_f4()  =        102
Time using *FLOAT32 =         12
Ric
Posts: 310
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

sorry for the long delay, I meant native to BBC basic, how do i create two matrices in 32bit float form and multiply them together. However this in not the most important problem right now, I have been diligently converting my D3D code to 64 bit with some success and some failure. All seems to work while not using depth buffers, but as soon as they are used rendering appears to stop? I have been going round in circles with AI and have checked every part of the code with it, nothing changes the fact it does not render(at all) with depth turned on. If i see AI say "this is the answer or this is the smoking gun" again it will be too soon. this is what it is now saying, can this be correct or is this another circle to go round?

Code: Select all

🚨 The most likely root cause (by far)
🔴 Constant buffer layout mismatch in 64-bit BBCSDL

In 32-bit:

your D3DXMATRIX{m%(3,3)} accidentally matches GPU expectations
padding/alignment happens to line up

In 64-bit:

structure alignment changes (8-byte vs 4-byte pointer rules in BBCSDL binding layer)
your matrix is now not actually 16-byte aligned per row
GPU reads garbage for the last column (W component)
Can anyone help?

I have also asked it if any of the structures look to have the wrong alignment , to which it has a field day, saying lots of unhelpful things including showing me where padding is "needed", which doesnt do a thing.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 665
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Thu 16 Apr 2026, 22:04 this is what it is now saying, can this be correct or is this another circle to go round?
It could be right. There are certainly (rare) circumstances when Windows functions have tougher alignment requirements than the regular 4-byte (DWORD) alignment that you get automatically from BBC BASIC, such as the 16-byte alignment that the AI mentions. I would say it's worth taking this possibility seriously, if only to eliminate it.

Fortunately it's not particularly difficult to force a structure to have some specific alignment, such as 16 bytes. You need to pad the structure at the end so that it has some safe space to be moved into, then you can simply move it up by the required amount:

Code: Select all

      DIM somestructure{members, as, required, pad&(14)}
      PTR(somestructure{}) = PTR(somestructure{}) + 15 AND -16
There's no comparably easy way to override the alignment of an array, so in that case put the array in a structure and use the above method.
Ric
Posts: 310
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

Thanks Richard, it would be fair to say that the list of things AI went through was exhaustive. Even if none of them seemed to be a problem. I'll let you know.
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Ric
Posts: 310
Joined: Tue 17 Apr 2018, 21:03

Re: @hwnd%

Post by Ric »

I have now tried evrything i think AI can offer. (It has got to the point where AI is telling me it has found suspicious code "which it has asked me to change earlier" and i am not sure it reaslly knows what it is doing.) Including setting all structures to lie on an 8byte boundary. I have narrowed the problem (i think) to the binding of the backBuffer (zBuffer) or the creation of the depthStencil. The two structures invloved are

Code: Select all

typedef struct D3D11_DEPTH_STENCIL_DESC {
  BOOL                       DepthEnable;
  D3D11_DEPTH_WRITE_MASK     DepthWriteMask;
  D3D11_COMPARISON_FUNC      DepthFunc;
  BOOL                       StencilEnable;
  UINT8                      StencilReadMask;
  UINT8                      StencilWriteMask;
  D3D11_DEPTH_STENCILOP_DESC FrontFace;
  D3D11_DEPTH_STENCILOP_DESC BackFace;
} D3D11_DEPTH_STENCIL_DESC;
and

Code: Select all

typedef struct D3D11_DEPTH_STENCIL_VIEW_DESC {
  DXGI_FORMAT         Format;
  D3D11_DSV_DIMENSION ViewDimension;
  UINT                Flags;
  union {
    D3D11_TEX1D_DSV         Texture1D;
    D3D11_TEX1D_ARRAY_DSV   Texture1DArray;
    D3D11_TEX2D_DSV         Texture2D;
    D3D11_TEX2D_ARRAY_DSV   Texture2DArray;
    D3D11_TEX2DMS_DSV       Texture2DMS;
    D3D11_TEX2DMS_ARRAY_DSV Texture2DMSArray;
  };
} D3D11_DEPTH_STENCIL_VIEW_DESC;
Their respective loading

Code: Select all

  160 depthStencilDesc.DepthEnable% = E%
  170 depthStencilDesc.DepthWriteMask% = D3D11_DEPTH_WRITE_MASK_ALL
  180 depthStencilDesc.DepthFunc% = D3D11_COMPARISON_LESS
  190 REM depthStencilDesc.DepthFunc% = D3D11_COMPARISON_GREATER
  200 REM depthStencilDesc.DepthFunc% = D3D11_COMPARISON_GREATER_EQUAL
  210 REM depthStencilDesc.DepthFunc% = D3D11_COMPARISON_ALWAYS
  220
  230 depthStencilDesc.StencilEnable% = D3DFALSE
  240 depthStencilDesc.StencilReadMask& = 0
  250 depthStencilDesc.StencilWriteMask& = 0
  260
  270 depthStencilDesc.FrontFace.StencilFailOp% = 21 : REM D3D11_STENCIL_OP_KEEP
  280 depthStencilDesc.FrontFace.StencilDepthFailOp% = 21 : REM D3D11_STENCIL_OP_KEEP
  290 depthStencilDesc.FrontFace.StencilPassOp% = 21 : REM D3D11_STENCIL_OP_KEEP
  300 depthStencilDesc.FrontFace.StencilFunc% = 21 : REM D3D11_COMPARISON_ALWAYS
  310
  320 depthStencilDesc.BackFace.StencilFailOp% = 21 : REM D3D11_STENCIL_OP_KEEP
  330 depthStencilDesc.BackFace.StencilDepthFailOp% = 21 : REM D3D11_STENCIL_OP_KEEP
  340 depthStencilDesc.BackFace.StencilPassOp% = 21 : REM D3D11_STENCIL_OP_KEEP
  350 depthStencilDesc.BackFace.StencilFunc% = 21 : REM D3D11_COMPARISON_ALWAYS
and

Code: Select all

      dsvd.Format%             = F%
  250 dsvd.ViewDimension%      = VD%
      dsvd.Flags%              = 0
      dsvd.Texture2D.MipSlice% = 0
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{}}
and

Code: Select all

      DIM D3D11_DEPTH_STENCIL_VIEW_DESC{Format%,ViewDimension%,Flags%, \
      \                            Texture2D{}=D3D11_TEX2D_DSV{}}
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.
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. When it comes to 64bit mode when the 2 extra bytes of padding are added this still leaves a DWORD missing to align the D3D11_DEPTH_STENCILOP_DESC, so i have tried the obvious and padded this with a DWORD. Unfortunately this still does not work. 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?

Can anyone shed any light?
Kind Regards Ric.

6502 back in the day, BB4W 2017 onwards, BBCSDL from 2023
Richard Russell
Posts: 665
Joined: Tue 18 Jun 2024, 09:32

Re: @hwnd%

Post by Richard Russell »

Ric wrote: Mon 20 Apr 2026, 19:24 Including setting all structures to lie on an 8byte boundary.
8 or 16? It's 16 you are likely to need, as discussed previously (16 is the alignment requirement of many SIMD operations).
The two structures involved are...
List the sizes of the individual members of the structures, please. I have no idea what the sizes of the various D3D11_* members are, and without that information I can't give any advice on the padding you might need. You can ask AI, but I'm not sure how reliable its answers will be.