Changeset 100054 in vbox
- Timestamp:
- Jun 2, 2023 3:27:16 PM (18 months ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/dx/VBoxDXDDI.cpp
r98103 r100054 103 103 { 104 104 /* The host does not support DX. */ 105 return E_FAIL;105 AssertFailedReturn(E_FAIL); 106 106 } 107 107 … … 298 298 PVBOXDX_DEVICE pDevice = (PVBOXDX_DEVICE)hDevice.pDrvPrivate; 299 299 LogFlowFunc(("pDevice = %p, VertexCount = %u, StartVertexLocation = %u\n", pDevice, VertexCount, StartVertexLocation)); 300 301 if (VertexCount == 0) 302 return; 300 303 301 304 vboxDXDraw(pDevice, VertexCount, StartVertexLocation); … … 3808 3811 } 3809 3812 3810 HRESULT APIENTRY vboxDXGIGetGammaCaps(DXGI_DDI_ARG_GET_GAMMA_CONTROL_CAPS *) 3811 { 3812 DEBUG_BREAKPOINT_TEST(); 3813 LogFlowFuncEnter(); 3813 static HRESULT APIENTRY dxgiGetGammaCaps(DXGI_DDI_ARG_GET_GAMMA_CONTROL_CAPS *pGammaArg) 3814 { 3815 //DEBUG_BREAKPOINT_TEST(); 3816 PVBOXDX_DEVICE pDevice = (PVBOXDX_DEVICE)pGammaArg->hDevice; 3817 LogFlowFunc(("pDevice 0x%p\n", pDevice)); 3818 RT_NOREF(pDevice); 3819 3820 pGammaArg->pGammaCapabilities->ScaleAndOffsetSupported = FALSE; 3821 pGammaArg->pGammaCapabilities->MaxConvertedValue = 0.0f; 3822 pGammaArg->pGammaCapabilities->MinConvertedValue = 0.0f; 3823 pGammaArg->pGammaCapabilities->NumGammaControlPoints = 0; 3824 RT_ZERO(pGammaArg->pGammaCapabilities->ControlPointPositions); 3825 3814 3826 return S_OK; 3815 3827 } … … 4659 4671 DXGI1_2_DDI_BASE_FUNCTIONS *pDXGIFuncs = pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions3; 4660 4672 pDXGIFuncs->pfnPresent = dxgiPresent; 4661 pDXGIFuncs->pfnGetGammaCaps = vboxDXGIGetGammaCaps;4673 pDXGIFuncs->pfnGetGammaCaps = dxgiGetGammaCaps; 4662 4674 pDXGIFuncs->pfnSetDisplayMode = dxgiSetDisplayMode; 4663 4675 pDXGIFuncs->pfnSetResourcePriority = vboxDXGISetResourcePriority; … … 4679 4691 DXGI1_1_DDI_BASE_FUNCTIONS *pDXGIFuncs = pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions2; 4680 4692 pDXGIFuncs->pfnPresent = dxgiPresent; 4681 pDXGIFuncs->pfnGetGammaCaps = vboxDXGIGetGammaCaps;4693 pDXGIFuncs->pfnGetGammaCaps = dxgiGetGammaCaps; 4682 4694 pDXGIFuncs->pfnSetDisplayMode = dxgiSetDisplayMode; 4683 4695 pDXGIFuncs->pfnSetResourcePriority = vboxDXGISetResourcePriority; … … 4691 4703 DXGI_DDI_BASE_FUNCTIONS *pDXGIFuncs = pCreateData->DXGIBaseDDI.pDXGIDDIBaseFunctions; 4692 4704 pDXGIFuncs->pfnPresent = dxgiPresent; 4693 pDXGIFuncs->pfnGetGammaCaps = vboxDXGIGetGammaCaps;4705 pDXGIFuncs->pfnGetGammaCaps = dxgiGetGammaCaps; 4694 4706 pDXGIFuncs->pfnSetDisplayMode = dxgiSetDisplayMode; 4695 4707 pDXGIFuncs->pfnSetResourcePriority = vboxDXGISetResourcePriority; -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/Makefile.kmk
r98138 r100054 48 48 PROGRAMS += VBoxD3D11 49 49 VBoxD3D11_TEMPLATE = VBoxR3Static 50 VBoxD3D11_CXXFLAGS += -wd4 458 -wd4668 -wd4838 -wd5029 -wd503950 VBoxD3D11_CXXFLAGS += -wd4305 -wd4458 -wd4668 -wd4838 -wd5029 -wd5039 51 51 VBoxD3D11_INCS += $(PATH_ROOT)/src/VBox/Devices/Graphics/shaders 52 52 VBoxD3D11_LIBS = d3d11.lib -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11main.cpp
r98138 r100054 738 738 * Use the shared texture from the render device. 739 739 */ 740 mRender.pImmediateContext->OMSetRenderTargets(1, &mRender.pRenderTargetView, mRender.pDepthStencilView);740 mRender.pImmediateContext->OMSetRenderTargets(1, &mRender.pRenderTargetView, NULL /*mRender.pDepthStencilView*/); 741 741 mpRender->DoRender(this); 742 742 } -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11render.cpp
r99816 r100054 28 28 #include "d3d11render.h" 29 29 30 #include <iprt/file.h> 31 #include <iprt/formats/bmp.h> 30 32 31 33 #if 0 … … 162 164 }; 163 165 166 typedef enum { 167 SVGA3D_BLENDOP_INVALID = 0, 168 SVGA3D_BLENDOP_MIN = 1, 169 SVGA3D_BLENDOP_ZERO = 1, 170 SVGA3D_BLENDOP_ONE = 2, 171 SVGA3D_BLENDOP_SRCCOLOR = 3, 172 SVGA3D_BLENDOP_INVSRCCOLOR = 4, 173 SVGA3D_BLENDOP_SRCALPHA = 5, 174 SVGA3D_BLENDOP_INVSRCALPHA = 6, 175 SVGA3D_BLENDOP_DESTALPHA = 7, 176 SVGA3D_BLENDOP_INVDESTALPHA = 8, 177 SVGA3D_BLENDOP_DESTCOLOR = 9, 178 SVGA3D_BLENDOP_INVDESTCOLOR = 10, 179 SVGA3D_BLENDOP_SRCALPHASAT = 11, 180 SVGA3D_BLENDOP_BLENDFACTOR = 12, 181 SVGA3D_BLENDOP_INVBLENDFACTOR = 13, 182 SVGA3D_BLENDOP_SRC1COLOR = 14, 183 SVGA3D_BLENDOP_INVSRC1COLOR = 15, 184 SVGA3D_BLENDOP_SRC1ALPHA = 16, 185 SVGA3D_BLENDOP_INVSRC1ALPHA = 17, 186 SVGA3D_BLENDOP_BLENDFACTORALPHA = 18, 187 SVGA3D_BLENDOP_INVBLENDFACTORALPHA = 19, 188 SVGA3D_BLENDOP_MAX 189 } SVGA3dBlendOp; 190 191 static D3D11_BLEND dxBlendFactorAlpha(uint8_t svgaBlend) 192 { 193 /* "Blend options that end in _COLOR are not allowed." but the guest sometimes sends them. */ 194 switch (svgaBlend) 195 { 196 case SVGA3D_BLENDOP_ZERO: return D3D11_BLEND_ZERO; 197 case SVGA3D_BLENDOP_ONE: return D3D11_BLEND_ONE; 198 case SVGA3D_BLENDOP_SRCCOLOR: return D3D11_BLEND_SRC_ALPHA; 199 case SVGA3D_BLENDOP_INVSRCCOLOR: return D3D11_BLEND_INV_SRC_ALPHA; 200 case SVGA3D_BLENDOP_SRCALPHA: return D3D11_BLEND_SRC_ALPHA; 201 case SVGA3D_BLENDOP_INVSRCALPHA: return D3D11_BLEND_INV_SRC_ALPHA; 202 case SVGA3D_BLENDOP_DESTALPHA: return D3D11_BLEND_DEST_ALPHA; 203 case SVGA3D_BLENDOP_INVDESTALPHA: return D3D11_BLEND_INV_DEST_ALPHA; 204 case SVGA3D_BLENDOP_DESTCOLOR: return D3D11_BLEND_DEST_ALPHA; 205 case SVGA3D_BLENDOP_INVDESTCOLOR: return D3D11_BLEND_INV_DEST_ALPHA; 206 case SVGA3D_BLENDOP_SRCALPHASAT: return D3D11_BLEND_SRC_ALPHA_SAT; 207 case SVGA3D_BLENDOP_BLENDFACTOR: return D3D11_BLEND_BLEND_FACTOR; 208 case SVGA3D_BLENDOP_INVBLENDFACTOR: return D3D11_BLEND_INV_BLEND_FACTOR; 209 case SVGA3D_BLENDOP_SRC1COLOR: return D3D11_BLEND_SRC1_ALPHA; 210 case SVGA3D_BLENDOP_INVSRC1COLOR: return D3D11_BLEND_INV_SRC1_ALPHA; 211 case SVGA3D_BLENDOP_SRC1ALPHA: return D3D11_BLEND_SRC1_ALPHA; 212 case SVGA3D_BLENDOP_INVSRC1ALPHA: return D3D11_BLEND_INV_SRC1_ALPHA; 213 case SVGA3D_BLENDOP_BLENDFACTORALPHA: return D3D11_BLEND_BLEND_FACTOR; 214 case SVGA3D_BLENDOP_INVBLENDFACTORALPHA: return D3D11_BLEND_INV_BLEND_FACTOR; 215 default: 216 break; 217 } 218 return D3D11_BLEND_ZERO; 219 } 220 221 222 static D3D11_BLEND dxBlendFactorColor(uint8_t svgaBlend) 223 { 224 switch (svgaBlend) 225 { 226 case SVGA3D_BLENDOP_ZERO: return D3D11_BLEND_ZERO; 227 case SVGA3D_BLENDOP_ONE: return D3D11_BLEND_ONE; 228 case SVGA3D_BLENDOP_SRCCOLOR: return D3D11_BLEND_SRC_COLOR; 229 case SVGA3D_BLENDOP_INVSRCCOLOR: return D3D11_BLEND_INV_SRC_COLOR; 230 case SVGA3D_BLENDOP_SRCALPHA: return D3D11_BLEND_SRC_ALPHA; 231 case SVGA3D_BLENDOP_INVSRCALPHA: return D3D11_BLEND_INV_SRC_ALPHA; 232 case SVGA3D_BLENDOP_DESTALPHA: return D3D11_BLEND_DEST_ALPHA; 233 case SVGA3D_BLENDOP_INVDESTALPHA: return D3D11_BLEND_INV_DEST_ALPHA; 234 case SVGA3D_BLENDOP_DESTCOLOR: return D3D11_BLEND_DEST_COLOR; 235 case SVGA3D_BLENDOP_INVDESTCOLOR: return D3D11_BLEND_INV_DEST_COLOR; 236 case SVGA3D_BLENDOP_SRCALPHASAT: return D3D11_BLEND_SRC_ALPHA_SAT; 237 case SVGA3D_BLENDOP_BLENDFACTOR: return D3D11_BLEND_BLEND_FACTOR; 238 case SVGA3D_BLENDOP_INVBLENDFACTOR: return D3D11_BLEND_INV_BLEND_FACTOR; 239 case SVGA3D_BLENDOP_SRC1COLOR: return D3D11_BLEND_SRC1_COLOR; 240 case SVGA3D_BLENDOP_INVSRC1COLOR: return D3D11_BLEND_INV_SRC1_COLOR; 241 case SVGA3D_BLENDOP_SRC1ALPHA: return D3D11_BLEND_SRC1_ALPHA; 242 case SVGA3D_BLENDOP_INVSRC1ALPHA: return D3D11_BLEND_INV_SRC1_ALPHA; 243 case SVGA3D_BLENDOP_BLENDFACTORALPHA: return D3D11_BLEND_BLEND_FACTOR; 244 case SVGA3D_BLENDOP_INVBLENDFACTORALPHA: return D3D11_BLEND_INV_BLEND_FACTOR; 245 default: 246 break; 247 } 248 return D3D11_BLEND_ZERO; 249 } 250 251 static D3D11_BLEND_OP dxBlendOp(uint8_t svgaBlendEq) 252 { 253 return (D3D11_BLEND_OP)svgaBlendEq; 254 } 255 256 typedef enum { 257 SVGA3D_FILLMODE_INVALID = 0, 258 SVGA3D_FILLMODE_MIN = 1, 259 SVGA3D_FILLMODE_POINT = 1, 260 SVGA3D_FILLMODE_LINE = 2, 261 SVGA3D_FILLMODE_FILL = 3, 262 SVGA3D_FILLMODE_MAX 263 } SVGA3dFillModeType; 264 265 static D3D11_FILL_MODE dxFillMode(uint8_t svgaFillMode) 266 { 267 if (svgaFillMode == SVGA3D_FILLMODE_POINT) 268 return D3D11_FILL_WIREFRAME; 269 return (D3D11_FILL_MODE)svgaFillMode; 270 } 271 164 272 /* 165 273 * Clear the backbuffer and display it. … … 679 787 680 788 /* 789 * Test a draw from guest. 790 */ 791 792 static unsigned char const dxbc_vs_8_shid_0[] = 793 { 794 0x44, 0x58, 0x42, 0x43, 0x3c, 0x4b, 0x22, 0x00, 0x8d, 0x54, 0x9d, 0xfc, 0x24, 0x3c, 0xdb, 0xe9, 795 0x65, 0x0c, 0xf7, 0x39, 0x01, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 796 0x2c, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 797 0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 798 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 799 0x03, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 800 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x41, 0x54, 0x54, 0x52, 801 0x49, 0x42, 0x00, 0x00, 0x4f, 0x53, 0x47, 0x4e, 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 802 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 804 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 805 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 806 0x41, 0x54, 0x54, 0x52, 0x49, 0x42, 0x00, 0x00, 0x53, 0x48, 0x44, 0x52, 0xf0, 0x00, 0x00, 0x00, 807 0x40, 0x00, 0x01, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x01, 0x01, 0x59, 0x00, 0x00, 0x04, 808 0x46, 0x8e, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x59, 0x08, 0x00, 0x04, 809 0x46, 0x8e, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 810 0x32, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x03, 0x12, 0x10, 0x10, 0x00, 811 0x01, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x04, 0xf2, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 812 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x04, 0xf2, 0x20, 0x10, 0x80, 0x01, 0x80, 0x00, 0x00, 813 0x01, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0b, 814 0x32, 0x20, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 815 0x86, 0x80, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd6, 0x85, 0x20, 0x00, 816 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, 0xc2, 0x20, 0x10, 0x00, 817 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 818 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x80, 0x3f, 0x36, 0x00, 0x00, 0x05, 0x12, 0x00, 0x10, 0x00, 819 0x00, 0x00, 0x00, 0x00, 0x0a, 0x10, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x08, 820 0xf2, 0x20, 0x10, 0x80, 0x01, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x46, 0x8e, 0x20, 0x04, 821 0x01, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01 822 }; 823 static unsigned char const dxbc_ps_8_shid_1[] = 824 { 825 0x44, 0x58, 0x42, 0x43, 0x32, 0x53, 0xc9, 0xda, 0xb6, 0x69, 0x0f, 0x34, 0xae, 0xf8, 0x2a, 0x09, 826 0xe0, 0x03, 0x77, 0x0b, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 827 0x2c, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x49, 0x53, 0x47, 0x4e, 828 0x4c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 829 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 830 0x0f, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 831 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x50, 832 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x41, 0x54, 0x54, 0x52, 0x49, 0x42, 0x00, 0x00, 833 0x4f, 0x53, 0x47, 0x4e, 0x2c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 834 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 835 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x53, 0x56, 0x5f, 0x54, 0x41, 0x52, 0x47, 0x45, 836 0x54, 0x00, 0x00, 0x00, 0x53, 0x48, 0x44, 0x52, 0x4c, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 837 0x13, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x01, 0x01, 0x62, 0x10, 0x00, 0x04, 0xf2, 0x10, 0x10, 0x80, 838 0x01, 0x80, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x04, 0xf2, 0x20, 0x10, 0x80, 839 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x07, 0xf2, 0x20, 0x10, 0x80, 840 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x1e, 0x10, 0x80, 0x01, 0x80, 0x00, 0x00, 841 0x01, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01 842 }; 843 844 static uint8_t *readBmpFile(char const *pszFilename, uint32_t *pWidth, uint32_t *pHeight, uint32_t *pcbData) 845 { 846 uint8_t *pu8Data = NULL; 847 848 RTFILE f = NIL_RTFILE; 849 int rc = RTFileOpen(&f, pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); 850 if (RT_SUCCESS(rc)) 851 { 852 BMPFILEHDR fileHdr; 853 rc = RTFileRead(f, &fileHdr, sizeof(fileHdr), NULL); 854 if (RT_SUCCESS(rc)) 855 { 856 *pcbData = (fileHdr.cbFileSize - fileHdr.offBits) / 4; // < /4 hack because writing was wrong 857 uint32_t const cbHdr = fileHdr.offBits - sizeof(fileHdr); 858 if (cbHdr == sizeof(BITMAPV4HEADER)) 859 { 860 BITMAPV4HEADER hdrV4; 861 rc = RTFileRead(f, &hdrV4, sizeof(hdrV4), NULL); 862 if (RT_SUCCESS(rc)) 863 { 864 *pWidth = hdrV4.bV4Width; 865 *pHeight = (uint32_t)-hdrV4.bV4Height; 866 } 867 } 868 else if (cbHdr == sizeof(BMPWIN3XINFOHDR)) 869 { 870 BMPWIN3XINFOHDR coreHdr; 871 rc = RTFileRead(f, &coreHdr, sizeof(coreHdr), NULL); 872 if (RT_SUCCESS(rc)) 873 { 874 *pWidth = coreHdr.uWidth; 875 *pHeight = (uint32_t)(-(int32_t)coreHdr.uHeight); 876 } 877 } 878 if (RT_SUCCESS(rc)) 879 { 880 pu8Data = (uint8_t *)RTMemAlloc(*pcbData); 881 if (pu8Data) 882 rc = RTFileRead(f, pu8Data, *pcbData, NULL); 883 } 884 } 885 886 RTFileClose(f); 887 } 888 889 if (RT_FAILURE(rc)) 890 { 891 RTMemFree(pu8Data); 892 pu8Data = NULL; 893 } 894 895 return pu8Data; 896 } 897 898 class D3D11RenderTest: public D3D11Render 899 { 900 public: 901 D3D11RenderTest(); 902 virtual ~D3D11RenderTest(); 903 virtual HRESULT InitRender(D3D11DeviceProvider *pDP); 904 virtual HRESULT DoRender(D3D11DeviceProvider *pDP); 905 private: 906 ID3D11InputLayout *mpInputLayout; 907 ID3D11VertexShader *mpVS; 908 ID3D11PixelShader *mpPS; 909 ID3D11Buffer *mpIB; 910 ID3D11Buffer *mpVB; 911 ID3D11Buffer *mpVBInstanceData; 912 ID3D11Buffer *mpCB_VS0; 913 ID3D11Buffer *mpCB_VS1; 914 ID3D11Buffer *mpCB_PS; 915 ID3D11Buffer *mpSR_0; 916 ID3D11Texture2D *mpSR_1; 917 ID3D11ShaderResourceView *mpSRV_0; 918 ID3D11ShaderResourceView *mpSRV_1; 919 ID3D11SamplerState *mpSampler; 920 ID3D11BlendState *mpBlend; 921 ID3D11RasterizerState *mpRasterizerState; 922 ID3D11DepthStencilState *mpDepthStencilState; 923 ID3D11UnorderedAccessView *mpUnorderedAccessView; 924 925 struct Vertex 926 { 927 float e0[2]; 928 short e1[2]; 929 }; 930 #if 0 931 struct InstanceData 932 { 933 short e1[2]; 934 short e2[2]; 935 short e3[2]; 936 int32_t e4[1]; 937 }; 938 #endif 939 }; 940 941 942 D3D11RenderTest::D3D11RenderTest() 943 : mpInputLayout(0) 944 , mpVS(0) 945 , mpPS(0) 946 , mpIB(0) 947 , mpVB(0) 948 , mpVBInstanceData(0) 949 , mpCB_VS0(0) 950 , mpCB_VS1(0) 951 , mpCB_PS(0) 952 , mpSR_0(0) 953 , mpSR_1(0) 954 , mpSRV_0(0) 955 , mpSRV_1(0) 956 , mpSampler(0) 957 , mpBlend(0) 958 , mpRasterizerState(0) 959 , mpDepthStencilState(0) 960 , mpUnorderedAccessView(0) 961 { 962 } 963 964 D3D11RenderTest::~D3D11RenderTest() 965 { 966 D3D_RELEASE(mpInputLayout); 967 D3D_RELEASE(mpVS); 968 D3D_RELEASE(mpPS); 969 D3D_RELEASE(mpIB); 970 D3D_RELEASE(mpVB); 971 D3D_RELEASE(mpVBInstanceData); 972 D3D_RELEASE(mpCB_VS0); 973 D3D_RELEASE(mpCB_VS1); 974 D3D_RELEASE(mpCB_PS); 975 D3D_RELEASE(mpSR_0); 976 D3D_RELEASE(mpSR_1); 977 D3D_RELEASE(mpSRV_0); 978 D3D_RELEASE(mpSRV_1); 979 D3D_RELEASE(mpSampler); 980 D3D_RELEASE(mpBlend); 981 D3D_RELEASE(mpRasterizerState); 982 D3D_RELEASE(mpDepthStencilState); 983 D3D_RELEASE(mpUnorderedAccessView); 984 } 985 986 HRESULT D3D11RenderTest::InitRender(D3D11DeviceProvider *pDP) 987 { 988 ID3D11Device *pDevice = pDP->Device(); 989 990 static D3D11_INPUT_ELEMENT_DESC const aVertexDesc[] = 991 { 992 {"ATTRIB", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, 993 {"ATTRIB", 1, DXGI_FORMAT_R16G16_SINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, 994 }; 995 996 static Vertex const aVertices[] = 997 { 998 { { 0.000000, 0.000000 },{ 0, 256 }, }, 999 { { 0.000000, 0.000000 },{ 0, 256 }, }, 1000 { { 0.000000, 409.000000 },{ 0, 256 }, }, 1001 { { 756.000000, 0.000000 },{ 0, 256 }, }, 1002 { { 756.000000, 409.000000 },{ 0, 256 }, }, 1003 { { 756.000000, 409.000000 },{ 0, 256 }, }, 1004 { { 0.000000, 34.000000 },{ 1, 256 }, }, 1005 { { 0.000000, 34.000000 },{ 1, 256 }, }, 1006 { { 0.000000, 409.000000 },{ 1, 256 }, }, 1007 { { 756.000000, 34.000000 },{ 1, 256 }, }, 1008 { { 756.000000, 409.000000 },{ 1, 256 }, }, 1009 { { 756.000000, 409.000000 },{ 1, 256 }, }, 1010 }; 1011 1012 #if 0 1013 static uint16_t const aIndices[] = 1014 { 1015 { 0 }, 1016 { 1 }, 1017 { 2 }, 1018 { 0 }, 1019 { 2 }, 1020 { 3 }, 1021 }; 1022 1023 static InstanceData const aInstanceData[] = 1024 { 1025 { { 16, 23 },{ 24, 30 },{ 0, 7 },{ 0 } }, 1026 }; 1027 #endif 1028 1029 HRESULT hr = S_OK; 1030 1031 HTEST(pDevice->CreateInputLayout(aVertexDesc, RT_ELEMENTS(aVertexDesc), 1032 &dxbc_vs_8_shid_0[0], sizeof(dxbc_vs_8_shid_0), 1033 &mpInputLayout)); 1034 HTEST(pDevice->CreateVertexShader(dxbc_vs_8_shid_0, sizeof(dxbc_vs_8_shid_0), NULL, &mpVS)); 1035 HTEST(pDevice->CreatePixelShader(dxbc_ps_8_shid_1, sizeof(dxbc_ps_8_shid_1), NULL, &mpPS)); 1036 1037 D3D11_BUFFER_DESC bd; 1038 RT_ZERO(bd); 1039 bd.Usage = D3D11_USAGE_IMMUTABLE; 1040 bd.ByteWidth = sizeof(aVertices); 1041 bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; 1042 bd.CPUAccessFlags = 0; 1043 bd.MiscFlags = 0; 1044 bd.StructureByteStride = 0; 1045 1046 D3D11_SUBRESOURCE_DATA vinitData; 1047 RT_ZERO(vinitData); 1048 vinitData.pSysMem = aVertices; 1049 1050 HTEST(pDevice->CreateBuffer(&bd, &vinitData, &mpVB)); 1051 1052 #if 0 1053 RT_ZERO(bd); 1054 bd.Usage = D3D11_USAGE_IMMUTABLE; 1055 bd.ByteWidth = sizeof(aInstanceData); 1056 bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; 1057 bd.CPUAccessFlags = 0; 1058 bd.MiscFlags = 0; 1059 bd.StructureByteStride = 0; 1060 1061 RT_ZERO(vinitData); 1062 vinitData.pSysMem = aInstanceData; 1063 1064 HTEST(pDevice->CreateBuffer(&bd, &vinitData, &mpVBInstanceData)); 1065 1066 RT_ZERO(bd); 1067 bd.Usage = D3D11_USAGE_IMMUTABLE; 1068 bd.ByteWidth = sizeof(aIndices); 1069 bd.BindFlags = D3D11_BIND_INDEX_BUFFER; 1070 bd.CPUAccessFlags = 0; 1071 bd.MiscFlags = 0; 1072 bd.StructureByteStride = 0; 1073 1074 RT_ZERO(vinitData); 1075 vinitData.pSysMem = aIndices; 1076 1077 HTEST(pDevice->CreateBuffer(&bd, &vinitData, &mpIB)); 1078 #endif 1079 1080 float aCB_VS0[] = 1081 { 1082 0.002645, -1.000000, -0.004889, 1.000000, 1083 1.000000, 0.000000, 0.000000, 0.000000, 1084 1.000000, 0.000000, 0.000000, 0.000000, 1085 }; 1086 1087 RT_ZERO(bd); 1088 bd.Usage = D3D11_USAGE_IMMUTABLE; 1089 bd.ByteWidth = sizeof(aCB_VS0); 1090 bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 1091 bd.CPUAccessFlags = 0; 1092 bd.MiscFlags = 0; 1093 bd.StructureByteStride = 0; 1094 1095 RT_ZERO(vinitData); 1096 vinitData.pSysMem = aCB_VS0; 1097 1098 HTEST(pDevice->CreateBuffer(&bd, &vinitData, &mpCB_VS0)); 1099 1100 float aCB_VS1[250 * 4] = 1101 { 1102 0.976470, 0.976470, 0.976470, 1.000000, 1103 0.976470, 0.976470, 0.976470, 1.000000, 1104 }; 1105 1106 RT_ZERO(bd); 1107 bd.Usage = D3D11_USAGE_IMMUTABLE; 1108 bd.ByteWidth = sizeof(aCB_VS1); 1109 bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 1110 bd.CPUAccessFlags = 0; 1111 bd.MiscFlags = 0; 1112 bd.StructureByteStride = 0; 1113 1114 RT_ZERO(vinitData); 1115 vinitData.pSysMem = aCB_VS1; 1116 1117 HTEST(pDevice->CreateBuffer(&bd, &vinitData, &mpCB_VS1)); 1118 1119 static float const aCB_PS[] = 1120 { 1121 0.000000, 1.000000, 1.399999, 1.000000, 1122 }; 1123 1124 RT_ZERO(bd); 1125 bd.Usage = D3D11_USAGE_IMMUTABLE; 1126 bd.ByteWidth = sizeof(aCB_PS); 1127 bd.BindFlags = D3D11_BIND_CONSTANT_BUFFER; 1128 bd.CPUAccessFlags = 0; 1129 bd.MiscFlags = 0; 1130 bd.StructureByteStride = 0; 1131 1132 RT_ZERO(vinitData); 1133 vinitData.pSysMem = aCB_PS; 1134 1135 HTEST(pDevice->CreateBuffer(&bd, &vinitData, &mpCB_PS)); 1136 1137 #if 0 1138 const char *pszSR; 1139 uint8_t *pu8Data; 1140 uint32_t w, h, cbData; 1141 1142 pszSR = "C:\\Develop\\vbox\\trunk\\out\\win.amd64\\debug\\bin\\bmp\\sr-6691.bmp"; 1143 pu8Data = readBmpFile(pszSR, &w, &h, &cbData); 1144 if (pu8Data) 1145 { 1146 RT_ZERO(bd); 1147 bd.Usage = D3D11_USAGE_IMMUTABLE; 1148 bd.ByteWidth = cbData; 1149 bd.BindFlags = D3D11_BIND_SHADER_RESOURCE; 1150 bd.CPUAccessFlags = 0; 1151 bd.MiscFlags = 0; 1152 bd.StructureByteStride = 0; 1153 1154 RT_ZERO(vinitData); 1155 vinitData.pSysMem = pu8Data; 1156 1157 HTEST(pDevice->CreateBuffer(&bd, &vinitData, &mpSR_0)); 1158 1159 RTMemFree(pu8Data); 1160 1161 D3D11_SHADER_RESOURCE_VIEW_DESC desc; 1162 RT_ZERO(desc); 1163 desc.Format = DXGI_FORMAT_R8_UINT; 1164 desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER; 1165 desc.Buffer.FirstElement = 0; 1166 desc.Buffer.NumElements = w; 1167 HTEST(pDevice->CreateShaderResourceView(mpSR_0, &desc, &mpSRV_0)); 1168 } 1169 1170 pszSR = "C:\\Develop\\vbox\\trunk\\out\\win.amd64\\debug\\bin\\bmp\\sr-6692.bmp"; 1171 pu8Data = readBmpFile(pszSR, &w, &h, &cbData); 1172 if (pu8Data) 1173 { 1174 D3D11_TEXTURE2D_DESC td; 1175 RT_ZERO(td); 1176 td.Width = w; 1177 td.Height = h; 1178 td.MipLevels = 1; 1179 td.ArraySize = 1; 1180 td.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 1181 td.SampleDesc.Count = 1; 1182 td.SampleDesc.Quality = 0; 1183 td.Usage = D3D11_USAGE_DEFAULT; 1184 td.BindFlags = D3D11_BIND_SHADER_RESOURCE; 1185 td.CPUAccessFlags = 0; 1186 td.MiscFlags = 0; 1187 1188 D3D11_SUBRESOURCE_DATA initData; 1189 initData.pSysMem = pu8Data; 1190 initData.SysMemPitch = w * 4; 1191 initData.SysMemSlicePitch = 0; 1192 1193 HTEST(pDevice->CreateTexture2D(&td, &initData, &mpSR_1)); 1194 1195 D3D11_SHADER_RESOURCE_VIEW_DESC desc; 1196 RT_ZERO(desc); 1197 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; 1198 desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; 1199 desc.Texture2D.MostDetailedMip = 0; 1200 desc.Texture2D.MipLevels = 1; 1201 1202 HTEST(pDevice->CreateShaderResourceView(mpSR_1, &desc, &mpSRV_1)); 1203 1204 RTMemFree(pu8Data); 1205 } 1206 1207 D3D11_SAMPLER_DESC desc; 1208 desc.Filter = (D3D11_FILTER)0; 1209 desc.AddressU = (D3D11_TEXTURE_ADDRESS_MODE)3; 1210 desc.AddressV = (D3D11_TEXTURE_ADDRESS_MODE)3; 1211 desc.AddressW = (D3D11_TEXTURE_ADDRESS_MODE)3; 1212 desc.MipLODBias = 0.0; 1213 desc.MaxAnisotropy = 0; 1214 desc.ComparisonFunc = (D3D11_COMPARISON_FUNC)1; 1215 desc.BorderColor[0] = 0.0; 1216 desc.BorderColor[1] = 0.0; 1217 desc.BorderColor[2] = 0.0; 1218 desc.BorderColor[3] = 0.0; 1219 desc.MinLOD = 0.0; 1220 desc.MaxLOD = 0.0; 1221 1222 HTEST(pDevice->CreateSamplerState(&desc, &mpSampler)); 1223 #endif 1224 1225 #if 1 1226 D3D11_BLEND_DESC BlendDesc; 1227 RT_ZERO(BlendDesc); 1228 BlendDesc.AlphaToCoverageEnable = FALSE; 1229 BlendDesc.IndependentBlendEnable = FALSE; 1230 for (int i = 0; i < 8; ++i) 1231 { 1232 BlendDesc.RenderTarget[i].BlendEnable = FALSE; 1233 // BlendDesc.RenderTarget[i].SrcBlend = dxBlendFactorColor(12); 1234 // BlendDesc.RenderTarget[i].DestBlend = dxBlendFactorColor(4); 1235 // BlendDesc.RenderTarget[i].BlendOp = dxBlendOp (1); 1236 // BlendDesc.RenderTarget[i].SrcBlendAlpha = dxBlendFactorAlpha(12); 1237 // BlendDesc.RenderTarget[i].DestBlendAlpha = dxBlendFactorAlpha(4); 1238 // BlendDesc.RenderTarget[i].BlendOpAlpha = dxBlendOp (1); 1239 BlendDesc.RenderTarget[i].RenderTargetWriteMask = 7; 1240 /** @todo logicOpEnable and logicOp */ 1241 } 1242 1243 HTEST(pDevice->CreateBlendState(&BlendDesc, &mpBlend)); 1244 #endif 1245 1246 #if 1 1247 D3D11_RASTERIZER_DESC rs; 1248 rs.FillMode = dxFillMode(3); 1249 rs.CullMode = D3D11_CULL_BACK; 1250 rs.FrontCounterClockwise = FALSE; 1251 rs.DepthBias = 0; 1252 rs.DepthBiasClamp = 0.0; 1253 rs.SlopeScaledDepthBias = 0.0; 1254 rs.DepthClipEnable = TRUE; 1255 rs.ScissorEnable = TRUE; 1256 rs.MultisampleEnable = FALSE; 1257 rs.AntialiasedLineEnable = FALSE; 1258 1259 HTEST(pDevice->CreateRasterizerState(&rs, &mpRasterizerState)); 1260 #endif 1261 1262 D3D11_DEPTH_STENCIL_DESC ds; 1263 ds.DepthEnable = FALSE; 1264 ds.DepthWriteMask = (D3D11_DEPTH_WRITE_MASK)1; 1265 ds.DepthFunc = (D3D11_COMPARISON_FUNC)2; 1266 ds.StencilEnable = FALSE; 1267 ds.StencilReadMask = 0; 1268 ds.StencilWriteMask = 0; 1269 ds.FrontFace.StencilFailOp = (D3D11_STENCIL_OP)1; 1270 ds.FrontFace.StencilDepthFailOp = (D3D11_STENCIL_OP)1; 1271 ds.FrontFace.StencilPassOp = (D3D11_STENCIL_OP)1; 1272 ds.FrontFace.StencilFunc = (D3D11_COMPARISON_FUNC)8; 1273 ds.BackFace.StencilFailOp = (D3D11_STENCIL_OP)1; 1274 ds.BackFace.StencilDepthFailOp = (D3D11_STENCIL_OP)1; 1275 ds.BackFace.StencilPassOp = (D3D11_STENCIL_OP)1; 1276 ds.BackFace.StencilFunc = (D3D11_COMPARISON_FUNC)8; 1277 1278 HTEST(pDevice->CreateDepthStencilState(&ds, &mpDepthStencilState)); 1279 1280 return hr; 1281 } 1282 1283 /* 1284 - constant buffers 1285 ;- samplers 1286 - shaders 1287 ;- shader resources 1288 ;- UA views 1289 ;- index buffer 1290 - input layout 1291 - primitive topology 1292 - vertex buffers 1293 - blend state 1294 - depth stencil state 1295 - render targets and UA views 1296 - scissor rects 1297 - rasterizer state 1298 - viewports 1299 - predication 1300 - min LOD 1301 - SO targets 1302 */ 1303 1304 1305 HRESULT D3D11RenderTest::DoRender(D3D11DeviceProvider *pDP) 1306 { 1307 ID3D11DeviceContext *pImmediateContext = pDP->ImmediateContext(); 1308 1309 FLOAT aColor[4] = { 0.0f, 0.0f, 1.0f, 0.0f }; 1310 pImmediateContext->ClearRenderTargetView(pDP->RenderTargetView(), aColor); 1311 if (pDP->DepthStencilView()) 1312 pImmediateContext->ClearDepthStencilView(pDP->DepthStencilView(), 1313 D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); 1314 1315 pImmediateContext->IASetInputLayout(mpInputLayout); 1316 pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); 1317 1318 ID3D11Buffer *apVB[1] = { mpVB }; 1319 UINT aStride[1] = { sizeof(Vertex) }; 1320 UINT aOffset[1] = { 0 }; 1321 pImmediateContext->IASetVertexBuffers(0, 1, apVB, aStride, aOffset); 1322 1323 // pImmediateContext->IASetIndexBuffer(mpIB, DXGI_FORMAT_R16_UINT, 0); 1324 1325 // ID3D11ShaderResourceView *apShaderResourceView[] = { mpSRV_0, mpSRV_1 }; 1326 // pImmediateContext->PSSetShaderResources(0, 2, apShaderResourceView); 1327 1328 // ID3D11SamplerState *apSampler[] = { mpSampler, mpSampler }; 1329 // pImmediateContext->PSSetSamplers(0, 2, apSampler); 1330 1331 float const blendFactor[4] = { 1.000000, 1.000000, -0.000000, -0.000000 }; 1332 pImmediateContext->OMSetBlendState(mpBlend, blendFactor, 0xFFFFFFFF); 1333 1334 pImmediateContext->RSSetState(mpRasterizerState); 1335 1336 pImmediateContext->OMSetDepthStencilState(mpDepthStencilState, 0); 1337 1338 ID3D11Buffer *apCB_VS[2] = { mpCB_VS0, mpCB_VS1 }; 1339 pImmediateContext->VSSetConstantBuffers(0, RT_ELEMENTS(apCB_VS), apCB_VS); 1340 pImmediateContext->PSSetConstantBuffers(0, 1, &mpCB_PS); 1341 1342 pImmediateContext->VSSetShader(mpVS, NULL, 0); 1343 pImmediateContext->PSSetShader(mpPS, NULL, 0); 1344 1345 pImmediateContext->Draw(12, 0); 1346 1347 return S_OK; 1348 } 1349 1350 1351 /* 681 1352 * "Public" interface. 682 1353 */ … … 696 1367 case 4: 697 1368 return new D3D11RenderDrawIndexed(); 1369 case 5: 1370 return new D3D11RenderTest(); 698 1371 default: 699 1372 break;
Note:
See TracChangeset
for help on using the changeset viewer.