Changeset 99816 in vbox for trunk/src/VBox/Additions/WINNT/Graphics
- Timestamp:
- May 16, 2023 6:29:28 PM (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/gallium/test/d3d11render.cpp
r98103 r99816 28 28 #include "d3d11render.h" 29 29 30 31 #if 0 32 // 33 // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 34 // 35 // 36 // fxc /Fhd3d11color.hlsl.vs.h /Evs_color /Tvs_4_0 d3d11color.hlsl 37 // 38 // 39 // 40 // Input signature: 41 // 42 // Name Index Mask Register SysValue Format Used 43 // -------------------- ----- ------ -------- -------- ------ ------ 44 // POSITION 0 xyz 0 NONE float xyz 45 // COLOR 0 xyzw 1 NONE float xyzw 46 // 47 // 48 // Output signature: 49 // 50 // Name Index Mask Register SysValue Format Used 51 // -------------------- ----- ------ -------- -------- ------ ------ 52 // SV_POSITION 0 xyzw 0 POS float xyzw 53 // COLOR 0 xyzw 1 NONE float xyzw 54 // 55 vs_4_0 56 dcl_input v0.xyz 57 dcl_input v1.xyzw 58 dcl_output_siv o0.xyzw, position 59 dcl_output o1.xyzw 60 mov o0.xyz, v0.xyzx 61 mov o0.w, l(1.000000) 62 mov o1.xyzw, v1.xyzw 63 ret 64 // Approximately 4 instruction slots used 65 #endif 66 67 static BYTE const g_vs_color[] = 68 { 69 68, 88, 66, 67, 109, 138, 105, 83, 86, 190, 83, 125, 72, 102, 194, 136, 46, 69, 70 17, 121, 1, 0, 0, 0, 48, 2, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0, 71 140, 0, 0, 0, 220, 0, 0, 0, 48, 1, 0, 0, 180, 1, 0, 0, 82, 68, 72 69, 70, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 73 28, 0, 0, 0, 0, 4, 254, 255, 0, 1, 0, 0, 28, 0, 0, 0, 77, 105, 74 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 75 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 57, 46, 50, 76 57, 46, 57, 53, 50, 46, 51, 49, 49, 49, 0, 171, 171, 171, 73, 83, 71, 78, 77 72, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 78 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 79 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 80 0, 0, 15, 15, 0, 0, 80, 79, 83, 73, 84, 73, 79, 78, 0, 67, 79, 76, 81 79, 82, 0, 171, 79, 83, 71, 78, 76, 0, 0, 0, 2, 0, 0, 0, 8, 0, 82 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 83 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 80, 85 79, 83, 73, 84, 73, 79, 78, 0, 67, 79, 76, 79, 82, 0, 171, 171, 83, 72, 86 68, 82, 124, 0, 0, 0, 64, 0, 1, 0, 31, 0, 0, 0, 95, 0, 0, 3, 87 114, 16, 16, 0, 0, 0, 0, 0, 95, 0, 0, 3, 242, 16, 16, 0, 1, 0, 88 0, 0, 103, 0, 0, 4, 242, 32, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 89 101, 0, 0, 3, 242, 32, 16, 0, 1, 0, 0, 0, 54, 0, 0, 5, 114, 32, 90 16, 0, 0, 0, 0, 0, 70, 18, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 91 130, 32, 16, 0, 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 54, 0, 92 0, 5, 242, 32, 16, 0, 1, 0, 0, 0, 70, 30, 16, 0, 1, 0, 0, 0, 93 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 4, 0, 0, 0, 0, 0, 94 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100 0, 0 101 }; 102 103 #if 0 104 // 105 // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111 106 // 107 // 108 // fxc /Fhd3d11color.hlsl.ps.h /Eps_color /Tps_4_0 d3d11color.hlsl 109 // 110 // 111 // 112 // Input signature: 113 // 114 // Name Index Mask Register SysValue Format Used 115 // -------------------- ----- ------ -------- -------- ------ ------ 116 // SV_POSITION 0 xyzw 0 POS float 117 // COLOR 0 xyzw 1 NONE float xyzw 118 // 119 // 120 // Output signature: 121 // 122 // Name Index Mask Register SysValue Format Used 123 // -------------------- ----- ------ -------- -------- ------ ------ 124 // SV_TARGET 0 xyzw 0 TARGET float xyzw 125 // 126 ps_4_0 127 dcl_input_ps linear v1.xyzw 128 dcl_output o0.xyzw 129 mov o0.xyzw, v1.xyzw 130 ret 131 // Approximately 2 instruction slots used 132 #endif 133 134 static BYTE const g_ps_color[] = 135 { 136 68, 88, 66, 67, 206, 120, 117, 238, 118, 127, 10, 87, 80, 75, 114, 198, 95, 2, 137 120, 102, 1, 0, 0, 0, 208, 1, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0, 138 140, 0, 0, 0, 224, 0, 0, 0, 20, 1, 0, 0, 84, 1, 0, 0, 82, 68, 139 69, 70, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 140 28, 0, 0, 0, 0, 4, 255, 255, 0, 1, 0, 0, 28, 0, 0, 0, 77, 105, 141 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 142 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 57, 46, 50, 143 57, 46, 57, 53, 50, 46, 51, 49, 49, 49, 0, 171, 171, 171, 73, 83, 71, 78, 144 76, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 145 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 146 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 147 0, 0, 15, 15, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 148 67, 79, 76, 79, 82, 0, 171, 171, 79, 83, 71, 78, 44, 0, 0, 0, 1, 0, 149 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 150 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 151 71, 69, 84, 0, 171, 171, 83, 72, 68, 82, 56, 0, 0, 0, 64, 0, 0, 0, 152 14, 0, 0, 0, 98, 16, 0, 3, 242, 16, 16, 0, 1, 0, 0, 0, 101, 0, 153 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 242, 32, 16, 0, 154 0, 0, 0, 0, 70, 30, 16, 0, 1, 0, 0, 0, 62, 0, 0, 1, 83, 84, 155 65, 84, 116, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 156 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 158 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 159 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 160 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 161 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 162 }; 163 30 164 /* 31 165 * Clear the backbuffer and display it. … … 108 242 }; 109 243 110 #if 0111 //112 // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111113 //114 //115 // fxc /Fhd3d11color.hlsl.vs.h /Evs_color /Tvs_4_0 d3d11color.hlsl116 //117 //118 //119 // Input signature:120 //121 // Name Index Mask Register SysValue Format Used122 // -------------------- ----- ------ -------- -------- ------ ------123 // POSITION 0 xyz 0 NONE float xyz124 // COLOR 0 xyzw 1 NONE float xyzw125 //126 //127 // Output signature:128 //129 // Name Index Mask Register SysValue Format Used130 // -------------------- ----- ------ -------- -------- ------ ------131 // SV_POSITION 0 xyzw 0 POS float xyzw132 // COLOR 0 xyzw 1 NONE float xyzw133 //134 vs_4_0135 dcl_input v0.xyz136 dcl_input v1.xyzw137 dcl_output_siv o0.xyzw, position138 dcl_output o1.xyzw139 mov o0.xyz, v0.xyzx140 mov o0.w, l(1.000000)141 mov o1.xyzw, v1.xyzw142 ret143 // Approximately 4 instruction slots used144 #endif145 146 static BYTE const g_vs_color[] =147 {148 68, 88, 66, 67, 109, 138, 105, 83, 86, 190, 83, 125, 72, 102, 194, 136, 46, 69,149 17, 121, 1, 0, 0, 0, 48, 2, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0,150 140, 0, 0, 0, 220, 0, 0, 0, 48, 1, 0, 0, 180, 1, 0, 0, 82, 68,151 69, 70, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,152 28, 0, 0, 0, 0, 4, 254, 255, 0, 1, 0, 0, 28, 0, 0, 0, 77, 105,153 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83,154 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 57, 46, 50,155 57, 46, 57, 53, 50, 46, 51, 49, 49, 49, 0, 171, 171, 171, 73, 83, 71, 78,156 72, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0,157 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0,158 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0,159 0, 0, 15, 15, 0, 0, 80, 79, 83, 73, 84, 73, 79, 78, 0, 67, 79, 76,160 79, 82, 0, 171, 79, 83, 71, 78, 76, 0, 0, 0, 2, 0, 0, 0, 8, 0,161 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0,162 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0,163 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 80,164 79, 83, 73, 84, 73, 79, 78, 0, 67, 79, 76, 79, 82, 0, 171, 171, 83, 72,165 68, 82, 124, 0, 0, 0, 64, 0, 1, 0, 31, 0, 0, 0, 95, 0, 0, 3,166 114, 16, 16, 0, 0, 0, 0, 0, 95, 0, 0, 3, 242, 16, 16, 0, 1, 0,167 0, 0, 103, 0, 0, 4, 242, 32, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0,168 101, 0, 0, 3, 242, 32, 16, 0, 1, 0, 0, 0, 54, 0, 0, 5, 114, 32,169 16, 0, 0, 0, 0, 0, 70, 18, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5,170 130, 32, 16, 0, 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 54, 0,171 0, 5, 242, 32, 16, 0, 1, 0, 0, 0, 70, 30, 16, 0, 1, 0, 0, 0,172 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 4, 0, 0, 0, 0, 0,173 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,174 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,175 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,176 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0,177 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,178 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,179 0, 0180 };181 182 #if 0183 //184 // Generated by Microsoft (R) HLSL Shader Compiler 9.29.952.3111185 //186 //187 // fxc /Fhd3d11color.hlsl.ps.h /Eps_color /Tps_4_0 d3d11color.hlsl188 //189 //190 //191 // Input signature:192 //193 // Name Index Mask Register SysValue Format Used194 // -------------------- ----- ------ -------- -------- ------ ------195 // SV_POSITION 0 xyzw 0 POS float196 // COLOR 0 xyzw 1 NONE float xyzw197 //198 //199 // Output signature:200 //201 // Name Index Mask Register SysValue Format Used202 // -------------------- ----- ------ -------- -------- ------ ------203 // SV_TARGET 0 xyzw 0 TARGET float xyzw204 //205 ps_4_0206 dcl_input_ps linear v1.xyzw207 dcl_output o0.xyzw208 mov o0.xyzw, v1.xyzw209 ret210 // Approximately 2 instruction slots used211 #endif212 213 static BYTE const g_ps_color[] =214 {215 68, 88, 66, 67, 206, 120, 117, 238, 118, 127, 10, 87, 80, 75, 114, 198, 95, 2,216 120, 102, 1, 0, 0, 0, 208, 1, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0,217 140, 0, 0, 0, 224, 0, 0, 0, 20, 1, 0, 0, 84, 1, 0, 0, 82, 68,218 69, 70, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,219 28, 0, 0, 0, 0, 4, 255, 255, 0, 1, 0, 0, 28, 0, 0, 0, 77, 105,220 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83,221 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 57, 46, 50,222 57, 46, 57, 53, 50, 46, 51, 49, 49, 49, 0, 171, 171, 171, 73, 83, 71, 78,223 76, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0,224 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0,225 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0,226 0, 0, 15, 15, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0,227 67, 79, 76, 79, 82, 0, 171, 171, 79, 83, 71, 78, 44, 0, 0, 0, 1, 0,228 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,229 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82,230 71, 69, 84, 0, 171, 171, 83, 72, 68, 82, 56, 0, 0, 0, 64, 0, 0, 0,231 14, 0, 0, 0, 98, 16, 0, 3, 242, 16, 16, 0, 1, 0, 0, 0, 101, 0,232 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 242, 32, 16, 0,233 0, 0, 0, 0, 70, 30, 16, 0, 1, 0, 0, 0, 62, 0, 0, 1, 83, 84,234 65, 84, 116, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,235 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,236 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,237 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,239 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0241 };242 243 244 static Vertex const aVertices[] = 244 245 { … … 308 309 } 309 310 311 312 313 /* 314 * Two vertex streams from either a single vertex buffer or two vertex buffers. 315 */ 316 317 class D3D11RenderDoubleVB: public D3D11Render 318 { 319 public: 320 D3D11RenderDoubleVB(bool fUseSameBuffer); 321 virtual ~D3D11RenderDoubleVB(); 322 virtual HRESULT InitRender(D3D11DeviceProvider *pDP); 323 virtual HRESULT DoRender(D3D11DeviceProvider *pDP); 324 private: 325 bool mfUseSameBuffer; 326 327 ID3D11InputLayout *mpInputLayout; 328 ID3D11VertexShader *mpVS; 329 ID3D11PixelShader *mpPS; 330 ID3D11Buffer *mapVB[2]; 331 332 static const size_t mcbGap; 333 334 struct Vertex1 335 { 336 float position[3]; 337 }; 338 339 struct Vertex2 340 { 341 float color[4]; 342 }; 343 }; 344 345 const size_t D3D11RenderDoubleVB::mcbGap = 16; 346 347 D3D11RenderDoubleVB::D3D11RenderDoubleVB(bool fUseSameBuffer) 348 : mfUseSameBuffer(fUseSameBuffer) 349 , mpInputLayout(0) 350 , mpVS(0) 351 , mpPS(0) 352 { 353 RT_ZERO(mapVB); 354 } 355 356 D3D11RenderDoubleVB::~D3D11RenderDoubleVB() 357 { 358 D3D_RELEASE(mpInputLayout); 359 D3D_RELEASE(mpVS); 360 D3D_RELEASE(mpPS); 361 D3D_RELEASE(mapVB[0]); 362 D3D_RELEASE(mapVB[1]); 363 } 364 365 HRESULT D3D11RenderDoubleVB::InitRender(D3D11DeviceProvider *pDP) 366 { 367 ID3D11Device *pDevice = pDP->Device(); 368 369 static D3D11_INPUT_ELEMENT_DESC const aVertexDesc[] = 370 { 371 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, 372 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0} 373 }; 374 375 static Vertex1 const aVertices1[] = 376 { 377 { { -0.5f, -0.5f, 0.0f } }, 378 { { 0.0f, 0.5f, 0.0f } }, 379 { { 0.5f, -0.5f, 0.0f } }, 380 }; 381 382 static Vertex2 const aVertices2[] = 383 { 384 { { 0.0f, 0.0f, 1.0f, 1.0f } }, 385 { { 0.0f, 1.0f, 0.0f, 1.0f } }, 386 { { 1.0f, 0.0f, 0.0f, 1.0f } }, 387 }; 388 389 HRESULT hr = S_OK; 390 391 HTEST(pDevice->CreateInputLayout(aVertexDesc, RT_ELEMENTS(aVertexDesc), 392 &g_vs_color[0], sizeof(g_vs_color), 393 &mpInputLayout)); 394 HTEST(pDevice->CreateVertexShader(g_vs_color, sizeof(g_vs_color), NULL, &mpVS)); 395 HTEST(pDevice->CreatePixelShader(g_ps_color, sizeof(g_ps_color), NULL, &mpPS)); 396 397 D3D11_BUFFER_DESC vbd; 398 D3D11_SUBRESOURCE_DATA vinitData; 399 if (mfUseSameBuffer) 400 { 401 RT_ZERO(vbd); 402 vbd.Usage = D3D11_USAGE_IMMUTABLE; 403 vbd.ByteWidth = sizeof(aVertices1) + sizeof(aVertices2); 404 vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; 405 vbd.CPUAccessFlags = 0; 406 vbd.MiscFlags = 0; 407 vbd.StructureByteStride = 0; 408 409 unsigned char au8TmpInitData[sizeof(aVertices1) + mcbGap + sizeof(aVertices2)]; 410 memcpy(&au8TmpInitData[0], aVertices1, sizeof(aVertices1)); 411 memset(&au8TmpInitData[sizeof(aVertices1)], 0, mcbGap); 412 memcpy(&au8TmpInitData[sizeof(aVertices1) + mcbGap], aVertices2, sizeof(aVertices2)); 413 414 RT_ZERO(vinitData); 415 vinitData.pSysMem = au8TmpInitData; 416 417 HTEST(pDevice->CreateBuffer(&vbd, &vinitData, &mapVB[0])); 418 419 mapVB[1] = mapVB[0]; 420 mapVB[1]->AddRef(); 421 } 422 else 423 { 424 RT_ZERO(vbd); 425 vbd.Usage = D3D11_USAGE_IMMUTABLE; 426 vbd.ByteWidth = sizeof(aVertices1); 427 vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; 428 vbd.CPUAccessFlags = 0; 429 vbd.MiscFlags = 0; 430 vbd.StructureByteStride = 0; 431 432 RT_ZERO(vinitData); 433 vinitData.pSysMem = aVertices1; 434 435 HTEST(pDevice->CreateBuffer(&vbd, &vinitData, &mapVB[0])); 436 437 RT_ZERO(vbd); 438 vbd.Usage = D3D11_USAGE_IMMUTABLE; 439 vbd.ByteWidth = sizeof(aVertices2); 440 vbd.BindFlags = D3D11_BIND_VERTEX_BUFFER; 441 vbd.CPUAccessFlags = 0; 442 vbd.MiscFlags = 0; 443 vbd.StructureByteStride = 0; 444 445 RT_ZERO(vinitData); 446 vinitData.pSysMem = aVertices2; 447 448 HTEST(pDevice->CreateBuffer(&vbd, &vinitData, &mapVB[1])); 449 } 450 451 return hr; 452 } 453 454 HRESULT D3D11RenderDoubleVB::DoRender(D3D11DeviceProvider *pDP) 455 { 456 ID3D11DeviceContext *pImmediateContext = pDP->ImmediateContext(); 457 458 FLOAT aColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; 459 pImmediateContext->ClearRenderTargetView(pDP->RenderTargetView(), aColor); 460 if (pDP->DepthStencilView()) 461 pImmediateContext->ClearDepthStencilView(pDP->DepthStencilView(), 462 D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); 463 464 pImmediateContext->IASetInputLayout(mpInputLayout); 465 pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 466 467 if (mfUseSameBuffer) 468 { 469 UINT aStrides[] = { sizeof(Vertex1), sizeof(Vertex2) }; 470 UINT aOffsets[] = { 0 , 3 * sizeof(Vertex1) + mcbGap }; 471 pImmediateContext->IASetVertexBuffers(0, 2, mapVB, aStrides, aOffsets); 472 } 473 else 474 { 475 UINT aStrides[] = { sizeof(Vertex1), sizeof(Vertex2) }; 476 UINT aOffsets[] = { 0 , 0 }; 477 pImmediateContext->IASetVertexBuffers(0, 2, mapVB, aStrides, aOffsets); 478 } 479 480 pImmediateContext->VSSetShader(mpVS, NULL, 0); 481 pImmediateContext->PSSetShader(mpPS, NULL, 0); 482 483 D3D11_VIEWPORT Viewport; 484 Viewport.TopLeftX = 0.0f; 485 Viewport.TopLeftY = 0.0f; 486 Viewport.Width = (float)800; 487 Viewport.Height = (float)600; 488 Viewport.MinDepth = 0.0f; 489 Viewport.MaxDepth = 1.0f; 490 pImmediateContext->RSSetViewports(1, &Viewport); 491 492 pImmediateContext->Draw(3, 0); 493 494 return S_OK; 495 } 496 497 498 /* 499 * DrawIndexed with various StartIndexLocation, BaseVertexLocation and index buffer offset. 500 */ 501 502 class D3D11RenderDrawIndexed: public D3D11Render 503 { 504 public: 505 D3D11RenderDrawIndexed(); 506 virtual ~D3D11RenderDrawIndexed(); 507 virtual HRESULT InitRender(D3D11DeviceProvider *pDP); 508 virtual HRESULT DoRender(D3D11DeviceProvider *pDP); 509 private: 510 ID3D11InputLayout *mpInputLayout; 511 ID3D11VertexShader *mpVS; 512 ID3D11PixelShader *mpPS; 513 ID3D11Buffer *mpVB; 514 ID3D11Buffer *mpIB; 515 516 struct Vertex 517 { 518 float position[3]; 519 float color[4]; 520 }; 521 }; 522 523 524 D3D11RenderDrawIndexed::D3D11RenderDrawIndexed() 525 : mpInputLayout(0) 526 , mpVS(0) 527 , mpPS(0) 528 , mpVB(0) 529 , mpIB(0) 530 { 531 } 532 533 D3D11RenderDrawIndexed::~D3D11RenderDrawIndexed() 534 { 535 D3D_RELEASE(mpInputLayout); 536 D3D_RELEASE(mpVS); 537 D3D_RELEASE(mpPS); 538 D3D_RELEASE(mpVB); 539 D3D_RELEASE(mpIB); 540 } 541 542 HRESULT D3D11RenderDrawIndexed::InitRender(D3D11DeviceProvider *pDP) 543 { 544 ID3D11Device *pDevice = pDP->Device(); 545 546 static D3D11_INPUT_ELEMENT_DESC const aVertexDesc[] = 547 { 548 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, 549 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0} 550 }; 551 552 /* A triangle in each quadrant. Need 5 points. */ 553 static Vertex const aVertices[] = 554 { 555 { { 0.0f, 0.0f, 0.5f }, { 0.0f, 0.0f, 0.0f, 1.0f }, }, // 0: center 556 { { -0.8f, 0.0f, 0.5f }, { 1.0f, 0.0f, 0.0f, 1.0f }, }, // 1: left 557 { { 0.0f, 0.8f, 0.5f }, { 0.0f, 1.0f, 0.0f, 1.0f }, }, // 2: top 558 { { 0.8f, 0.0f, 0.5f }, { 0.0f, 0.0f, 1.0f, 1.0f }, }, // 3: right 559 { { 0.0f, -0.8f, 0.5f }, { 0.5f, 0.5f, 0.5f, 1.0f }, }, // 4: bottom 560 561 /* A smaller copy to use BaseVertexLocation. */ 562 { { 0.0f, 0.0f, 0.0f }, { 0.5f, 0.5f, 0.5f, 1.0f }, }, // 0: center 563 { { -0.2f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f }, }, // 1: left 564 { { 0.0f, 0.2f, 0.0f }, { 0.0f, 1.0f, 1.0f, 1.0f }, }, // 2: top 565 { { 0.2f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f, 1.0f }, }, // 3: right 566 { { 0.0f, -0.2f, 0.0f }, { 1.0f, 0.0f, 1.0f, 1.0f }, }, // 4: bottom 567 }; 568 569 /* Four triangles. Indices for each triangle will be accessed using different 570 * StartIndexLocation and index buffer offset values. 571 */ 572 static uint16_t const aIndices[] = 573 { 574 /* Bottom left: left, center, bottom. */ 1, 0, 4, 575 /* Top left: top, center, left. */ 2, 0, 1, 576 /* Top right: right, center, top. */ 3, 0, 2, 577 /* Bottom right: bottom, center, right. */ 4, 0, 3, 578 }; 579 580 HRESULT hr = S_OK; 581 582 HTEST(pDevice->CreateInputLayout(aVertexDesc, RT_ELEMENTS(aVertexDesc), 583 &g_vs_color[0], sizeof(g_vs_color), 584 &mpInputLayout)); 585 HTEST(pDevice->CreateVertexShader(g_vs_color, sizeof(g_vs_color), NULL, &mpVS)); 586 HTEST(pDevice->CreatePixelShader(g_ps_color, sizeof(g_ps_color), NULL, &mpPS)); 587 588 D3D11_BUFFER_DESC bd; 589 RT_ZERO(bd); 590 bd.Usage = D3D11_USAGE_IMMUTABLE; 591 bd.ByteWidth = sizeof(aVertices); 592 bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; 593 bd.CPUAccessFlags = 0; 594 bd.MiscFlags = 0; 595 bd.StructureByteStride = 0; 596 597 D3D11_SUBRESOURCE_DATA initData; 598 RT_ZERO(initData); 599 initData.pSysMem = aVertices; 600 601 HTEST(pDevice->CreateBuffer(&bd, &initData, &mpVB)); 602 603 RT_ZERO(bd); 604 bd.Usage = D3D11_USAGE_IMMUTABLE; 605 bd.ByteWidth = sizeof(aIndices); 606 bd.BindFlags = D3D11_BIND_INDEX_BUFFER; 607 bd.CPUAccessFlags = 0; 608 bd.MiscFlags = 0; 609 bd.StructureByteStride = 0; 610 611 RT_ZERO(initData); 612 initData.pSysMem = aIndices; 613 614 HTEST(pDevice->CreateBuffer(&bd, &initData, &mpIB)); 615 616 return hr; 617 } 618 619 static void drawRectangles(ID3D11DeviceContext *pImmediateContext, ID3D11Buffer *pIB, INT const BaseVertexLocation) 620 { 621 /* Draw each triangle separately. */ 622 UINT offset; 623 UINT StartIndexLocation; 624 625 /* Bottom left. */ 626 offset = 0; 627 StartIndexLocation = 0; 628 pImmediateContext->IASetIndexBuffer(pIB, DXGI_FORMAT_R16_UINT, offset); 629 pImmediateContext->DrawIndexed(3, StartIndexLocation, BaseVertexLocation); 630 631 /* Top left. */ 632 offset = 0; 633 StartIndexLocation = 3; 634 pImmediateContext->IASetIndexBuffer(pIB, DXGI_FORMAT_R16_UINT, offset); 635 pImmediateContext->DrawIndexed(3, StartIndexLocation, BaseVertexLocation); 636 637 /* Top right. */ 638 offset = 6 * sizeof(uint16_t); 639 StartIndexLocation = 0; 640 pImmediateContext->IASetIndexBuffer(pIB, DXGI_FORMAT_R16_UINT, offset); 641 pImmediateContext->DrawIndexed(3, StartIndexLocation, BaseVertexLocation); 642 643 /* Bottom right. */ 644 offset = 6 * sizeof(uint16_t); 645 StartIndexLocation = 3; 646 pImmediateContext->IASetIndexBuffer(pIB, DXGI_FORMAT_R16_UINT, offset); 647 pImmediateContext->DrawIndexed(3, StartIndexLocation, BaseVertexLocation); 648 } 649 650 HRESULT D3D11RenderDrawIndexed::DoRender(D3D11DeviceProvider *pDP) 651 { 652 ID3D11DeviceContext *pImmediateContext = pDP->ImmediateContext(); 653 654 FLOAT aColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; 655 pImmediateContext->ClearRenderTargetView(pDP->RenderTargetView(), aColor); 656 if (pDP->DepthStencilView()) 657 pImmediateContext->ClearDepthStencilView(pDP->DepthStencilView(), 658 D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); 659 660 pImmediateContext->IASetInputLayout(mpInputLayout); 661 pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); 662 663 UINT stride = sizeof(Vertex); 664 UINT offset = 0; 665 pImmediateContext->IASetVertexBuffers(0, 1, &mpVB, &stride, &offset); 666 667 pImmediateContext->VSSetShader(mpVS, NULL, 0); 668 pImmediateContext->PSSetShader(mpPS, NULL, 0); 669 670 INT BaseVertexLocation; 671 BaseVertexLocation = 0; 672 drawRectangles(pImmediateContext, mpIB, BaseVertexLocation); 673 BaseVertexLocation = 5; 674 drawRectangles(pImmediateContext, mpIB, BaseVertexLocation); 675 676 return S_OK; 677 } 678 679 310 680 /* 311 681 * "Public" interface. … … 320 690 case 1: 321 691 return new D3D11RenderTriangleShader(); 692 case 2: 693 return new D3D11RenderDoubleVB(false); 694 case 3: 695 return new D3D11RenderDoubleVB(true); 696 case 4: 697 return new D3D11RenderDrawIndexed(); 322 698 default: 323 699 break;
Note:
See TracChangeset
for help on using the changeset viewer.