;DX11 funcii use double name ! If net gVal1(mozet bit gdeto v code)
;we do DX11NewBuffer 0,Val1,gVal1
macro Vec3Trans chOut,chVec,chMat {
		mov edx,chMat
		movups	xmm4, [edx]
		movups	xmm5, [edx+0x10]
		movups	xmm6, [edx+0x20]
		movups	xmm7, [edx+0x30]
		movups	xmm0, [chVec]
		xorps		xmm2, xmm2
		movups	xmm1, xmm0
		shufps	xmm1, xmm1, 0x00
		mulps		xmm1, xmm4
		addps		xmm2, xmm1
		movups	xmm1, xmm0
		shufps	xmm1, xmm1, 0x55
		mulps		xmm1, xmm5
		addps		xmm2, xmm1
		movups	xmm1, xmm0
		shufps	xmm1, xmm1, 0xAA
		mulps		xmm1, xmm6
		addps		xmm2, xmm1
		movups	xmm1, xmm0
		shufps	xmm1, xmm1, 0xFF
		mulps		xmm1, xmm7
		addps		xmm2, xmm1
		movups	[chOut], xmm2
		}
macro MyMatrixRotationAxis chMat,chVec,chAngl { local Vvec,l1
			jmp	  l1
			Vvec	  dd 0,0,0,0
		   l1:
		    ;D3DXVec3Normalize(&v,pv); Vec3 v;
			movss	  xmm3,  [chVec+12]
			mov	  dword  [chVec+12],0.0
			movups	  xmm0,  [chVec]
			movaps	  xmm1,  xmm0
			mulps	  xmm1,  xmm1
			movhlps   xmm2,  xmm1
			addps	  xmm1,  xmm2
			movss	  xmm2,  xmm1
			shufps	  xmm1,  xmm1, 00000001b
			addss	  xmm1,  xmm2
			rsqrtss   xmm1,  xmm1
			shufps	  xmm1,  xmm1, 00000000b
			mulps	  xmm0,  xmm1  ;xmm0 = v
			movups	  dqword [Vvec],xmm0
		    ;pout->m[0][0] = (1.0f - cos(angle)) * v.x * v.x + cos(angle);
			fld	dword [chAngl]
			fsincos
			fstp	dword [Rcos]
			fstp	dword [Rsin]
		    ;xmm1 = (1-cos(chAngl))
			mov	eax,1.0
			movd	xmm1,eax
			subss	xmm1,[Rcos]
		    ; * v.x * v.x + cos(chAngl)
			movss xmm3,[Vvec]
			mulss xmm3,xmm3
			mulss xmm3,xmm1
			addss xmm3,[Rcos]
			movss [chMat+D3DXMATRIX._11],xmm3
		    ;pout->m[1][0] = (1.0f - cos(angle)) * v.x * v.y - sin(angle) * v.z;
			movss xmm3,[Vvec]
			mulss xmm3,[Vvec+4]
			mulss xmm3,xmm1
			subss xmm3,[Rsin]
			mulss xmm3,[Vvec+8]
			movss [chMat+D3DXMATRIX._21],xmm3
		    ;pout->m[2][0] = (1.0f - cos(angle)) * v.x * v.z + sin(angle) * v.y;
			movss xmm3,[Vvec]
			mulss xmm3,[Vvec+8]
			mulss xmm3,xmm1
			addss xmm3,[Rsin]
			mulss xmm3,[Vvec+4]
			movss [chMat+D3DXMATRIX._31],xmm3
		    ;pout->m[0][1] = (1.0f - cos(angle)) * v.y * v.x + sin(angle) * v.z;
			movss xmm3,[Vvec]
			mulss xmm3,[Vvec+4]
			mulss xmm3,xmm1
			addss xmm3,[Rsin]
			mulss xmm3,[Vvec+8]
			movss [chMat+D3DXMATRIX._12],xmm3
		    ;pout->m[1][1] = (1.0f - cos(angle)) * v.y * v.y + cos(angle);
			movss xmm3,[Vvec+4]
			mulss xmm3,xmm3
			mulss xmm3,xmm1
			addss xmm3,[Rcos]
			movss [chMat+D3DXMATRIX._22],xmm3
		    ;pout->m[2][1] = (1.0f - cos(angle)) * v.y * v.z - sin(angle) * v.x;
			movss xmm3,[Vvec+4]
			mulss xmm3,[Vvec+8]
			mulss xmm3,xmm1
			subss xmm3,[Rsin]
			mulss xmm3,[Vvec]
			movss [chMat+D3DXMATRIX._32],xmm3
		    ;pout->m[0][2] = (1.0f - cos(angle)) * v.z * v.x - sin(angle) * v.y;
			movss xmm3,[Vvec]
			mulss xmm3,[Vvec+8]
			mulss xmm3,xmm1
			subss xmm3,[Rsin]
			mulss xmm3,[Vvec+4]
			movss [chMat+D3DXMATRIX._13],xmm3
		    ;pout->m[1][2] = (1.0f - cos(angle)) * v.z * v.y + sin(angle) * v.x;
			movss xmm3,[Vvec+8]
			mulss xmm3,[Vvec+4]
			mulss xmm3,xmm1
			addss xmm3,[Rsin]
			mulss xmm3,[Vvec]
			movss [chMat+D3DXMATRIX._23],xmm3
		    ;pout->m[2][2] = (1.0f - cos(angle)) * v.z * v.z + cos(angle);
			movss xmm3,[Vvec+8]
			mulss xmm3,xmm3
			mulss xmm3,xmm1
			addss xmm3,[Rcos]
			movss [chMat+D3DXMATRIX._33],xmm3
		    ;m[3][3]
			mov [chMat+D3DXMATRIX._44],1.0

			     }
macro MatrixRotationY chMat,chAngl{
				fld dword [chAngl]
				fsincos
				fstp dword [Rcos]
				fstp dword [Rsin]
				movss xmm1,[Rcos]
				movss xmm2,[Rsin]
				xorps xmm4,xmm4
				movups dqword [chMat#._11],xmm4
			       ; movups dqword [chMat#._21],xmm4
				mov   dword [chMat#._22],1.0
				movups dqword[chMat#._31],xmm4
				movss [chMat#._11],xmm1
				movss [chMat#._31],xmm2
				movss [chMat#._33],xmm1
				mulss xmm2,[Min78]
				movss [chMat#._13],xmm2
		}
macro . arg { common
     DONE equ xxNO
     match dst==[src], arg
     \{ 
	mov eax,dword [src]
	mov dword [dst],eax
	DONE equ xxYES 
     \}
      match =xxNO dst==src, DONE arg
     \{
	mov dword [dst],src
	DONE equ xxYES 
     \}
     match =xxNO, DONE
     \{ 
       must be ". var= reg or num or [mem or reg]" 
     \}
    }
macro DX11MyTxt2 chCB,chX,chY,chTxt,chClrR,chClrG,chClrB,chClrA { local ll,l2
	pushd chTxt
	pop esi
	mov edi,chCB
	mov ecx,10
	sub eax,eax
 ll:	mov al,[esi]
	test al,al
	jz   l2
	sub al,'!'
	cvtsi2ss xmm0,eax
	mov   dword [edi],chX
	mov   dword [edi+4],chY
	movss dword [edi+8],xmm0
	mov   dword [edi+16],chClrR
	mov   dword [edi+20],chClrG
	mov   dword [edi+24],chClrB
	mov   dword [edi+28],chClrA
	inc esi
	add edi,32
	jmp ll
       ; dec ecx
       ; jnz ll
l2:
	}
macro DX11MyTxt3 chCB,chX,chY,chTxt,chClrR,chClrG,chClrB,chClrA { local ll,l2

     if chCB > 0
       mov edi,chCB
     end if
	pushd chTxt
	pop esi
	;mov edi,chCB
	mov ecx,10
	sub eax,eax
 ll:	mov al,[esi]
	test al,al
	jz   l2
	sub al,'!'
	cvtsi2ss xmm0,eax
	mov   dword [edi],chX
	mov   dword [edi+4],chY
	movss dword [edi+8],xmm0
	mov   dword [edi+16],chClrR
	mov   dword [edi+20],chClrG
	mov   dword [edi+24],chClrB
	mov   dword [edi+28],chClrA
	inc esi
	add edi,32
	jmp ll

l2:
	}

macro DX11MyTxt chX,chY,chScl,chTxt,chClrR,chClrG,chClrB,chClrA,Addr
{  local ll,l2
  match any , Addr \{ mov edi, Addr \}
	mov   dword [edi+16],chClrR
	mov   dword [edi+20],chClrG
	mov   dword [edi+24],chClrB
	mov   dword [edi+28],chClrA
	movaps xmm1,[edi+16]
	pushd chTxt
	pop esi
       ; mov eax,21.0
	;movd xmm0,eax
	;mov eax,chScl
	movss xmm2,[txt_ZnakXOt] ;otstup
	;mulss xmm2,xmm0
	mov eax,chX
	movd xmm3,eax
	sub eax,eax
 ll:	mov al,[esi]
	test al,al
	jz   l2
	sub al,'!'
	cvtsi2ss xmm0,eax
	;mov   dword [edi],chX
	movss dword [edi],xmm3
	addss	xmm3,xmm2
	mov   dword [edi+12],chScl
	mov   dword [edi+4],chY
	movss dword [edi+8],xmm0
       ; mov   dword [edi+16],chClrR
       ; mov   dword [edi+20],chClrG
       ; mov   dword [edi+24],chClrB
       ; mov   dword [edi+28],chClrA
	movaps dqword [edi+16],xmm1
	inc esi
	add edi,32
	jmp ll
l2:
}

macro VarCom chN {
       chN EQU Intrfc_offs
       Intrfc_offs EQU Intrfc_offs+SzComBits
       }
macro VarComs chN,chNum {
   rept chNum n:1  \{
       chN\#n EQU Intrfc_offs
       Intrfc_offs EQU Intrfc_offs+SzComBits
       \}
       }
macro DX11FileImg chDev,chName,chA,chB {
      VarCom  chA
      invoke	D3DX11CreateShaderResourceViewFromFile,[chDev], chName, 0,0, chA,0
      chB EQU chA
      }
macro  DX11SetTexture chContx,ch1,ch2,ch3{
com2  chContx,ID3D11DeviceContext.PSSetShaderResources, ch1, ch2,ch3
}
macro DX11SetLayout chContx,chL {
      com2 chContx,ID3D11DeviceContext.IASetInputLayout,dword [chL]
      }
macro DX11SetVS chContx,chSdr {
      com2 chContx,ID3D11DeviceContext.VSSetShader, [chSdr], 0,0
      }
macro DX11SetPS chContx,chSdr {
      com2 chContx,ID3D11DeviceContext.PSSetShader, [chSdr], 0,0
      }
macro DX11SetIndex chContx,chIndxBuf {
com2 chContx,ID3D11DeviceContext.IASetIndexBuffer,[chIndxBuf], DXGI_FORMAT_R32_UINT,dword 0
}
macro DX11SetVertex chContx,chVrtxBuf,chStride {
com2 chContx,ID3D11DeviceContext.IASetVertexBuffers,0, 1, chVrtxBuf,chStride,offsetTang
     }
macro DX11Present chSwap,chVsnc { com2 chSwap,IDXGISwapChain.Present, chVsnc,0 }
macro DX11ClearRTV chContx,chRTV,chColr {
 com2  chContx,ID3D11DeviceContext.ClearRenderTargetView, [chRTV],chColr
	}
macro DX11ClearDepth chContx,chDpth {
	com2  chContx,ID3D11DeviceContext.ClearDepthStencilView,[chDpth],D3D11_CLEAR_DEPTH or D3D11_CLEAR_STENCIL,1.0,0.0
}
macro DX11CreatShader  ch1,ch2
{
VarCom	  ch2
com2  pd3dDevice11,dv11#.#ch1,[BPointerVSBlob],[BSizeVSBlob] , NULL, ch2
mov	  dword [Status],eax
DX11Call  ppBlobOut,Release
mov	  eax,dword [Status]
}
macro DX11NewBufferA chDev,chDt,chOut,chNm2 {
      VarCom	  chOut
      chNm2 EQU   chOut
      com2 chDev,dv11#.CreateBuffer,bd, chDt, chOut
      ErrorMsg	`chOut#" CreateBuffer Error !",Exiting
      }
macro DX11NewBuffer chDt,chOut,chNm2,chDev {
      ntequzerr equ pd3dDevice11
      match any , chDev \{ ntequzerr equ chDev \}
      VarCom	  chOut
      chNm2 EQU   chOut
      com2 ntequzerr,dv11#.CreateBuffer,bd, chDt, chOut
      ErrorMsg	`chOut#" CreateBuffer Error !",Exiting
      }
macro DX11NewDepth chDsc,chOut,chNm2 {
      VarCom	  chOut
      chNm2 EQU   chOut
      com2 pd3dDevice11,dv11#.CreateDepthStencilState,chDsc, chOut
      ErrorMsg	`chOut#" DepthStencilState Error !",Exiting
      }
macro DX11NewBlend chDsc,chOut,chNm2 {
      VarCom	  chOut
      chNm2 EQU   chOut
      com2 pd3dDevice11,dv11#.CreateBlendState,chDsc, chOut
      ErrorMsg	`chOut#" CreateBlendState Error !",Exiting
      }
;vse interfaci have +8 Release ! Tak chto ne vazen tip interfaca !
;DX11Rls podoidet dla lubogo DX11 interfeica !
macro DX11Rls chObj { local zza
      cmp dword [chObj],0
      jz  zza
      com2 chObj,dv11#.Release
 zza:
      }
macro DX11Sampler chF,chA,chSmpl,chNm2 {
      VarCom	  chSmpl
      chNm2 EQU   chSmpl
	mov eax,chF
	Set	  sampDesc.Filter,eax ;D3D11_FILTER_ANISOTROPIC ;D3D11_FILTER_MIN_MAG_MIP_LINEAR
	mov eax,chA
	Set	  sampDesc.MaxAnisotropy,eax		;From 0 to 16
		;Set	   sampDesc.AddressU , D3D11_TEXTURE_ADDRESS_WRAP
		;Set	   sampDesc.AddressV , D3D11_TEXTURE_ADDRESS_WRAP
		;Set	   sampDesc.AddressW , D3D11_TEXTURE_ADDRESS_WRAP
		;Set	   sampDesc.ComparisonFunc , D3D11_COMPARISON_NEVER
	       ; Set	   sampDesc.MinLOD , 0
	       ; Set	   sampDesc.MaxLOD , D3D11_FLOAT32_MAX
		com2  pd3dDevice11,dv11#.CreateSamplerState,sampDesc, chSmpl
		ErrorMsg  `chSmpl#" CreateSamplerState Error !",Exiting
      }
;D3D11_BUFFER_DESC {
;  UINT        ByteWidth;
;  D3D11_USAGE Usage;
;  UINT        BindFlags;
;  UINT        CPUAccessFlags;
;  UINT        MiscFlags;
;  UINT        StructureByteStride;
 macro SetBD [arg] {
       common
  local i
  i = 0
 forward
  mov dword[bd + i], arg
  i = i + 4
       }
 macro com2 handle,interface,[arg]
 {
 common
    if ~ arg eq
   reverse
     pushd dword arg
   common
    end if
     mov eax,dword [handle]
     push eax
     mov eax,[eax]
    call dword [eax+interface]
    }
