nxdk_pgraph_tests
A collection of tests for the Xbox nv2a graphics processor
 
Loading...
Searching...
No Matches
test_host.h
1#ifndef NXDK_PGRAPH_TESTS_TEST_HOST_H
2#define NXDK_PGRAPH_TESTS_TEST_HOST_H
3
4#include <debug_output.h>
5#include <ftp_logger.h>
6#include <pbkit/pbkit.h>
7#include <printf/printf.h>
8
9#include <cstdint>
10#include <memory>
11
12#include "nxdk_ext.h"
13#include "pushbuffer.h"
14#include "string"
15#include "texture_format.h"
16#include "texture_stage.h"
17#include "vertex_buffer.h"
18#include "xbox_math_types.h"
19
20using namespace XboxMath;
21
23struct Vertex;
24class VertexBuffer;
25
29constexpr uint32_t kNextSubchannel = NEXT_SUBCH;
31constexpr int32_t kNextContextChannel = 25;
32
33constexpr uint32_t kNoStrideOverride = 0xFFFFFFFF;
34
36#define VRAM_MAX 0x07FFFFFF
38#define VRAM_ADDR(x) (reinterpret_cast<uint32_t>(x) & 0x03FFFFFF)
39#define SET_MASK(mask, val) (((val) << (__builtin_ffs(mask) - 1)) & (mask))
40
41#define TO_RGBA(float_vals) \
42 (((uint32_t)((float_vals)[3] * 255.0f) << 24) + ((uint32_t)((float_vals)[2] * 255.0f) << 16) + \
43 ((uint32_t)((float_vals)[1] * 255.0f) << 8) + ((uint32_t)((float_vals)[0] * 255.0f)))
44
48class TestHost {
49 public:
50 enum VertexAttribute {
51 POSITION = 1 << NV2A_VERTEX_ATTR_POSITION,
52 WEIGHT = 1 << NV2A_VERTEX_ATTR_WEIGHT,
53 NORMAL = 1 << NV2A_VERTEX_ATTR_NORMAL,
54 DIFFUSE = 1 << NV2A_VERTEX_ATTR_DIFFUSE,
55 SPECULAR = 1 << NV2A_VERTEX_ATTR_SPECULAR,
56 FOG_COORD = 1 << NV2A_VERTEX_ATTR_FOG_COORD,
57 POINT_SIZE = 1 << NV2A_VERTEX_ATTR_POINT_SIZE,
58 BACK_DIFFUSE = 1 << NV2A_VERTEX_ATTR_BACK_DIFFUSE,
59 BACK_SPECULAR = 1 << NV2A_VERTEX_ATTR_BACK_SPECULAR,
60 TEXCOORD0 = 1 << NV2A_VERTEX_ATTR_TEXTURE0,
61 TEXCOORD1 = 1 << NV2A_VERTEX_ATTR_TEXTURE1,
62 TEXCOORD2 = 1 << NV2A_VERTEX_ATTR_TEXTURE2,
63 TEXCOORD3 = 1 << NV2A_VERTEX_ATTR_TEXTURE3,
64 V13 = 1 << NV2A_VERTEX_ATTR_13,
65 V14 = 1 << NV2A_VERTEX_ATTR_14,
66 V15 = 1 << NV2A_VERTEX_ATTR_15,
67 };
68
69 static constexpr uint32_t kDefaultVertexFields = POSITION | DIFFUSE | TEXCOORD0;
70
73 PRIMITIVE_POINTS = NV097_SET_BEGIN_END_OP_POINTS,
74 PRIMITIVE_LINES = NV097_SET_BEGIN_END_OP_LINES,
75 PRIMITIVE_LINE_LOOP = NV097_SET_BEGIN_END_OP_LINE_LOOP,
76 PRIMITIVE_LINE_STRIP = NV097_SET_BEGIN_END_OP_LINE_STRIP,
77 PRIMITIVE_TRIANGLES = NV097_SET_BEGIN_END_OP_TRIANGLES,
78 PRIMITIVE_TRIANGLE_STRIP = NV097_SET_BEGIN_END_OP_TRIANGLE_STRIP,
79 PRIMITIVE_TRIANGLE_FAN = NV097_SET_BEGIN_END_OP_TRIANGLE_FAN,
80 PRIMITIVE_QUADS = NV097_SET_BEGIN_END_OP_QUADS,
81 PRIMITIVE_QUAD_STRIP = NV097_SET_BEGIN_END_OP_QUAD_STRIP,
82 PRIMITIVE_POLYGON = NV097_SET_BEGIN_END_OP_POLYGON,
83 };
84
85 enum CombinerSource {
86 SRC_ZERO = 0, // 0
87 SRC_C0, // Constant[0]
88 SRC_C1, // Constant[1]
89 SRC_FOG, // Fog coordinate
90 SRC_DIFFUSE, // Vertex diffuse
91 SRC_SPECULAR, // Vertex specular
92 SRC_6, // ?
93 SRC_7, // ?
94 SRC_TEX0, // Texcoord0
95 SRC_TEX1, // Texcoord1
96 SRC_TEX2, // Texcoord2
97 SRC_TEX3, // Texcoord3
98 SRC_R0, // R0 from the vertex shader
99 SRC_R1, // R1 from the vertex shader
100 SRC_SPEC_R0_SUM, // Specular + R0
101 SRC_EF_PROD, // Combiner param E * F
102 };
103
104 enum CombinerDest {
105 DST_DISCARD = 0, // Discard the calculation
106 DST_C0, // Constant[0]
107 DST_C1, // Constant[1]
108 DST_FOG, // Fog coordinate
109 DST_DIFFUSE, // Vertex diffuse
110 DST_SPECULAR, // Vertex specular
111 DST_6, // ?
112 DST_7, // ?
113 DST_TEX0, // Texcoord0
114 DST_TEX1, // Texcoord1
115 DST_TEX2, // Texcoord2
116 DST_TEX3, // Texcoord3
117 DST_R0, // R0 from the vertex shader
118 DST_R1, // R1 from the vertex shader
119 DST_SPEC_R0_SUM, // Specular + R0
120 DST_EF_PROD, // Combiner param E * F
121 };
122
123 enum CombinerSumMuxMode {
124 SM_SUM = 0, // ab + cd
125 SM_MUX = 1, // r0.a is used to select cd or ab
126 };
127
128 enum CombinerOutOp {
129 OP_IDENTITY = 0, // y = x
130 OP_BIAS = 1, // y = x - 0.5
131 OP_SHIFT_LEFT_1 = 2, // y = x*2
132 OP_SHIFT_LEFT_1_BIAS = 3, // y = (x - 0.5)*2
133 OP_SHIFT_LEFT_2 = 4, // y = x*4
134 OP_SHIFT_RIGHT_1 = 6, // y = x/2
135 };
136
137 enum CombinerMapping {
138 MAP_UNSIGNED_IDENTITY, // max(0,x) OK for final combiner
139 MAP_UNSIGNED_INVERT, // 1 - max(0,x) OK for final combiner
140 MAP_EXPAND_NORMAL, // 2*max(0,x) - 1 invalid for final combiner
141 MAP_EXPAND_NEGATE, // 1 - 2*max(0,x) invalid for final combiner
142 MAP_HALFBIAS_NORMAL, // max(0,x) - 1/2 invalid for final combiner
143 MAP_HALFBIAS_NEGATE, // 1/2 - max(0,x) invalid for final combiner
144 MAP_SIGNED_IDENTITY, // x invalid for final combiner
145 MAP_SIGNED_NEGATE, // -x invalid for final combiner
146 };
147
149 CombinerSource source;
150 bool alpha;
151 CombinerMapping mapping;
152 };
153
154 struct ColorInput : public CombinerInput {
155 explicit ColorInput(CombinerSource s, CombinerMapping m = MAP_UNSIGNED_IDENTITY) : CombinerInput() {
156 source = s;
157 alpha = false;
158 mapping = m;
159 }
160 };
161
162 struct AlphaInput : public CombinerInput {
163 explicit AlphaInput(CombinerSource s, CombinerMapping m = MAP_UNSIGNED_IDENTITY) : CombinerInput() {
164 source = s;
165 alpha = true;
166 mapping = m;
167 }
168 };
169
170 struct ZeroInput : public CombinerInput {
171 explicit ZeroInput() : CombinerInput() {
172 source = SRC_ZERO;
173 alpha = false;
174 mapping = MAP_UNSIGNED_IDENTITY;
175 }
176 };
177
179 explicit NegativeOneInput() : CombinerInput() {
180 source = SRC_ZERO;
181 alpha = false;
182 mapping = MAP_EXPAND_NORMAL;
183 }
184 };
185
186 struct OneInput : public CombinerInput {
187 explicit OneInput() : CombinerInput() {
188 source = SRC_ZERO;
189 alpha = false;
190 mapping = MAP_UNSIGNED_INVERT;
191 }
192 };
193
196 PALETTE_32 = 32,
197 PALETTE_64 = 64,
198 PALETTE_128 = 128,
199 PALETTE_256 = 256,
200 };
201
204 STAGE_NONE = 0,
205 STAGE_2D_PROJECTIVE,
206 STAGE_3D_PROJECTIVE,
207 STAGE_CUBE_MAP,
208 STAGE_PASS_THROUGH,
209 STAGE_CLIP_PLANE,
210 STAGE_BUMPENVMAP,
211 STAGE_BUMPENVMAP_LUMINANCE,
212 STAGE_BRDF,
213 STAGE_DOT_ST,
214 STAGE_DOT_ZW,
215 STAGE_DOT_REFLECT_DIFFUSE,
216 STAGE_DOT_REFLECT_SPECULAR,
217 STAGE_DOT_STR_3D,
218 STAGE_DOT_STR_CUBE,
219 STAGE_DEPENDENT_AR,
220 STAGE_DEPENDENT_GB,
221 STAGE_DOT_PRODUCT,
222 STAGE_DOT_REFLECT_SPECULAR_CONST,
223 };
224
227 AA_CENTER_1 = NV097_SET_SURFACE_FORMAT_ANTI_ALIASING_CENTER_1,
228 AA_CENTER_CORNER_2 = NV097_SET_SURFACE_FORMAT_ANTI_ALIASING_CENTER_CORNER_2,
229 AA_SQUARE_OFFSET_4 = NV097_SET_SURFACE_FORMAT_ANTI_ALIASING_SQUARE_OFFSET_4,
230 };
231
234 SCF_X1R5G5B5_Z1R5G5B5 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1R5G5B5_Z1R5G5B5,
235 SCF_X1R5G5B5_O1R5G5B5 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1R5G5B5_O1R5G5B5,
236 SCF_R5G6B5 = NV097_SET_SURFACE_FORMAT_COLOR_LE_R5G6B5,
237 SCF_X8R8G8B8_Z8R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X8R8G8B8_Z8R8G8B8,
238 SCF_X8R8G8B8_O8R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X8R8G8B8_O8R8G8B8,
239 SCF_X1A7R8G8B8_Z1A7R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1A7R8G8B8_Z1A7R8G8B8,
240 SCF_X1A7R8G8B8_O1A7R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1A7R8G8B8_O1A7R8G8B8,
241 SCF_A8R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_A8R8G8B8,
242
243 // NOTE: Failing to disable alpha blending on B8 and G8B8 will trigger a hardware exception.
244 SCF_B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_B8,
245 SCF_G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_G8B8,
246 };
247
250 SZF_Z16 = NV097_SET_SURFACE_FORMAT_ZETA_Z16,
251 SZF_Z24S8 = NV097_SET_SURFACE_FORMAT_ZETA_Z24S8
252 };
253
254 public:
255 TestHost(std::shared_ptr<FTPLogger> ftp_logger, uint32_t framebuffer_width, uint32_t framebuffer_height,
256 uint32_t max_texture_width, uint32_t max_texture_height, uint32_t max_texture_depth = 4);
257 ~TestHost();
258
259 TextureStage &GetTextureStage(uint32_t stage) { return texture_stage_[stage]; }
260 void SetTextureFormat(const TextureFormatInfo &fmt, uint32_t stage = 0);
261 void SetDefaultTextureParams(uint32_t stage = 0);
262 int SetTexture(SDL_Surface *surface, uint32_t stage = 0);
263 int SetVolumetricTexture(const SDL_Surface **surface, uint32_t depth, uint32_t stage = 0);
264 int SetRawTexture(const uint8_t *source, uint32_t width, uint32_t height, uint32_t depth, uint32_t pitch,
265 uint32_t bytes_per_pixel, bool swizzle, uint32_t stage = 0);
266
267 int SetPalette(const uint32_t *palette, PaletteSize size, uint32_t stage = 0);
268 void SetPaletteSize(PaletteSize size, uint32_t stage = 0);
269 void SetTextureStageEnabled(uint32_t stage, bool enabled = true);
270
271 // Set the surface format
272 // width and height are treated differently depending on whether swizzle is enabled or not.
273 // swizzle = true
274 // width and height must be a power of two
275 // swizzle = false
276 // width and height may be arbitrary positive values and will be used to set the clip dimensions
277 //
278 // Does not take effect until CommitSurfaceFormat is called.
279 void SetSurfaceFormat(SurfaceColorFormat color_format, SurfaceZetaFormat depth_format, uint32_t width,
280 uint32_t height, bool swizzle = false, uint32_t clip_x = 0, uint32_t clip_y = 0,
281 uint32_t clip_width = 0, uint32_t clip_height = 0, AntiAliasingSetting aa = AA_CENTER_1);
282
283 // Sets the surface format and commits it immediately.
284 void SetSurfaceFormatImmediate(SurfaceColorFormat color_format, SurfaceZetaFormat depth_format, uint32_t width,
285 uint32_t height, bool swizzle = false, uint32_t clip_x = 0, uint32_t clip_y = 0,
286 uint32_t clip_width = 0, uint32_t clip_height = 0,
287 AntiAliasingSetting aa = AA_CENTER_1);
288
290 [[nodiscard]] SurfaceColorFormat GetColorBufferFormat() const { return surface_color_format_; }
291
293 [[nodiscard]] SurfaceZetaFormat GetDepthBufferFormat() const { return depth_buffer_format_; }
294
295 [[nodiscard]] static bool SurfaceSupportsAlpha(SurfaceColorFormat fmt) {
296 switch (fmt) {
297 case SCF_X1R5G5B5_Z1R5G5B5:
298 case SCF_X1R5G5B5_O1R5G5B5:
299 case SCF_X8R8G8B8_Z8R8G8B8:
300 case SCF_X8R8G8B8_O8R8G8B8:
301 case SCF_X1A7R8G8B8_Z1A7R8G8B8:
302 case SCF_X1A7R8G8B8_O1A7R8G8B8:
303 case SCF_A8R8G8B8:
304 return true;
305
306 case SCF_R5G6B5:
307 case SCF_G8B8:
308 case SCF_B8:
309 return false;
310
311 default:
312 ASSERT(!"Invalid surface color format");
313 }
314 }
315
317 [[nodiscard]] static uint32_t GetSurfaceColorPitch(SurfaceColorFormat fmt, uint32_t width) {
318 switch (fmt) {
319 case SCF_X1R5G5B5_Z1R5G5B5:
320 case SCF_X1R5G5B5_O1R5G5B5:
321 case SCF_R5G6B5:
322 case SCF_G8B8:
323 return width << 1;
324
325 case SCF_X8R8G8B8_Z8R8G8B8:
326 case SCF_X8R8G8B8_O8R8G8B8:
327 case SCF_X1A7R8G8B8_Z1A7R8G8B8:
328 case SCF_X1A7R8G8B8_O1A7R8G8B8:
329 case SCF_A8R8G8B8:
330 return width << 2;
331
332 case SCF_B8:
333 return width;
334
335 default:
336 ASSERT(!"Invalid surface color format");
337 }
338 }
339
341 void SetDepthBufferFloatMode(bool enabled);
343 [[nodiscard]] bool GetDepthBufferFloatMode() const { return depth_buffer_mode_float_; }
344
345 void CommitSurfaceFormat() const;
346
348 [[nodiscard]] uint32_t GetMaxTextureWidth() const { return max_texture_width_; }
350 [[nodiscard]] uint32_t GetMaxTextureHeight() const { return max_texture_height_; }
352 [[nodiscard]] uint32_t GetMaxTextureDepth() const { return max_texture_depth_; }
354 [[nodiscard]] uint32_t GetMaxSingleTextureSize() const { return max_single_texture_size_; }
355
357 [[nodiscard]] uint8_t *GetTextureMemory() const { return texture_memory_; }
359 [[nodiscard]] uint32_t GetTextureMemorySize() const { return texture_memory_size_; }
360
362 [[nodiscard]] uint8_t *GetTextureMemoryForStage(uint32_t stage) const {
363 return texture_memory_ + texture_stage_[stage].GetTextureOffset();
364 }
366 [[nodiscard]] uint32_t *GetPaletteMemoryForStage(uint32_t stage) const {
367 return reinterpret_cast<uint32_t *>(texture_palette_memory_ + texture_stage_[stage].GetPaletteOffset());
368 }
369
371 [[nodiscard]] inline uint32_t GetFramebufferWidth() const { return framebuffer_width_; }
373 [[nodiscard]] inline uint32_t GetFramebufferHeight() const { return framebuffer_height_; }
375 [[nodiscard]] inline float GetFramebufferWidthF() const { return static_cast<float>(framebuffer_width_); }
377 [[nodiscard]] inline float GetFramebufferHeightF() const { return static_cast<float>(framebuffer_height_); }
378
380 std::shared_ptr<VertexBuffer> AllocateVertexBuffer(uint32_t num_vertices);
382 void SetVertexBuffer(std::shared_ptr<VertexBuffer> buffer);
384 std::shared_ptr<VertexBuffer> GetVertexBuffer() { return vertex_buffer_; }
386 void ClearVertexBuffer() { vertex_buffer_.reset(); }
387
389 void Clear(uint32_t argb = 0xFF000000, uint32_t depth_value = 0xFFFFFFFF, uint8_t stencil_value = 0x00) const;
391 void ClearDepthStencilRegion(uint32_t depth_value, uint8_t stencil_value, uint32_t left = 0, uint32_t top = 0,
392 uint32_t width = 0, uint32_t height = 0) const;
394 void ClearColorRegion(uint32_t argb, uint32_t left = 0, uint32_t top = 0, uint32_t width = 0,
395 uint32_t height = 0) const;
397 static void EraseText();
398
403 void PrepareDraw(uint32_t argb = 0xFF000000, uint32_t depth_value = 0xFFFFFFFF, uint8_t stencil_value = 0x00);
404
405 void DrawArrays(uint32_t enabled_vertex_fields = kDefaultVertexFields, DrawPrimitive primitive = PRIMITIVE_TRIANGLES);
406 void DrawInlineBuffer(uint32_t enabled_vertex_fields = kDefaultVertexFields,
407 DrawPrimitive primitive = PRIMITIVE_TRIANGLES);
408
410 void DrawInlineArray(uint32_t enabled_vertex_fields = kDefaultVertexFields,
411 DrawPrimitive primitive = PRIMITIVE_TRIANGLES);
412
414 void DrawInlineElements16(const std::vector<uint32_t> &indices, uint32_t enabled_vertex_fields = kDefaultVertexFields,
415 DrawPrimitive primitive = PRIMITIVE_TRIANGLES);
416
418 void DrawInlineElements32(const std::vector<uint32_t> &indices, uint32_t enabled_vertex_fields = kDefaultVertexFields,
419 DrawPrimitive primitive = PRIMITIVE_TRIANGLES);
420
422 void FinishDraw(bool allow_saving, const std::string &output_directory, const std::string &suite_name,
423 const std::string &name, bool save_zbuffer = false);
424
426 void SetDepthClip(float min, float max) const;
427
429 void SetVertexShaderProgram(std::shared_ptr<VertexShaderProgram> program);
431 [[nodiscard]] std::shared_ptr<VertexShaderProgram> GetShaderProgram() const { return vertex_shader_program_; }
432
434 static void BuildD3DModelViewMatrix(matrix4_t &matrix, const vector_t &eye, const vector_t &at, const vector_t &up);
435
437 void BuildD3DProjectionViewportMatrix(matrix4_t &result, float fov, float z_near, float z_far) const;
438
440 static void BuildD3DOrthographicProjectionMatrix(matrix4_t &result, float left, float right, float top, float bottom,
441 float z_near, float z_far);
442
445 static void BuildDefaultXDKModelViewMatrix(matrix4_t &matrix);
447 void BuildDefaultXDKProjectionMatrix(matrix4_t &matrix) const;
448
450 [[nodiscard]] const matrix4_t &GetFixedFunctionInverseCompositeMatrix() const {
451 return fixed_function_inverse_composite_matrix_;
452 }
453
456
459
461 void ProjectPoint(vector_t &result, const vector_t &world_point) const;
462
464 void UnprojectPoint(vector_t &result, const vector_t &screen_point) const;
466 void UnprojectPoint(vector_t &result, const vector_t &screen_point, float world_z) const;
467
469 static void SetWindowClipExclusive(bool exclusive);
471 static void SetWindowClip(uint32_t right, uint32_t bottom, uint32_t left = 0, uint32_t top = 0, uint32_t region = 0);
472
473 static void SetViewportOffset(float x, float y, float z, float w);
474 static void SetViewportScale(float x, float y, float z, float w);
475
476 void SetFixedFunctionModelViewMatrix(const matrix4_t &model_matrix);
477 void SetFixedFunctionProjectionMatrix(const matrix4_t &projection_matrix);
478 [[nodiscard]] inline const matrix4_t &GetFixedFunctionModelViewMatrix() const {
479 return fixed_function_model_view_matrix_;
480 }
481 [[nodiscard]] inline const matrix4_t &GetFixedFunctionProjectionMatrix() const {
482 return fixed_function_projection_matrix_;
483 }
484
485 [[nodiscard]] float GetWNear() const { return w_near_; }
486 [[nodiscard]] float GetWFar() const { return w_far_; }
487
490 void Begin(DrawPrimitive primitive) const;
492 void End() const;
493
495 void SetVertex(float x, float y, float z) const;
497 void SetVertex(float x, float y, float z, float w) const;
499 inline void SetVertex(const vector_t pt) const { SetVertex(pt[0], pt[1], pt[2], pt[3]); }
500
502 void DrawScreenQuad(float left, float top, float right, float bottom, float world_z) const {
503 Begin(PRIMITIVE_QUADS);
504 SetScreenVertex(left, top, world_z);
505 SetScreenVertex(right, top, world_z);
506 SetScreenVertex(right, bottom, world_z);
507 SetScreenVertex(left, bottom, world_z);
508 End();
509 }
510
512 void SetScreenVertex(float x, float y, float world_z) const {
513 vector_t screen{x, y, world_z, 1.f};
514 vector_t world;
515 UnprojectPoint(world, screen, world_z);
516 SetVertex(world);
517 }
518
520 void SetScreenVertex(float x, float y) const {
521 vector_t screen{x, y, 0.f, 1.f};
522 vector_t world;
523 UnprojectPoint(world, screen);
524 SetVertex(world);
525 }
526
527 void SetWeight(float w) const;
528 void SetWeight(float w1, float w2) const;
529 void SetWeight(float w1, float w2, float w3) const;
530 void SetWeight(float w1, float w2, float w3, float w4) const;
531 void SetNormal(float x, float y, float z) const;
532 void SetNormal(const float *vals) const;
533 void SetNormal3S(int x, int y, int z) const;
534 void SetDiffuse(const vector_t &color) const { SetDiffuse(color[0], color[1], color[2], color[3]); }
535 void SetDiffuse(float r, float g, float b, float a) const;
536 void SetDiffuse(float r, float g, float b) const;
537 void SetDiffuse(uint32_t rgba) const;
538 void SetSpecular(const vector_t &color) const { SetSpecular(color[0], color[1], color[2], color[3]); }
539 void SetSpecular(float r, float g, float b, float a) const;
540 void SetSpecular(float r, float g, float b) const;
541 void SetSpecular(uint32_t rgba) const;
542 void SetFogCoord(float fc) const;
543 void SetPointSize(float ps) const;
544 void SetTexCoord0(float u, float v) const;
545 void SetTexCoord0S(int u, int v) const;
546 void SetTexCoord0(float s, float t, float p, float q) const;
547 void SetTexCoord0S(int s, int t, int p, int q) const;
548 void SetTexCoord1(float u, float v) const;
549 void SetTexCoord1S(int u, int v) const;
550 void SetTexCoord1(float s, float t, float p, float q) const;
551 void SetTexCoord1S(int s, int t, int p, int q) const;
552 void SetTexCoord2(float u, float v) const;
553 void SetTexCoord2S(int u, int v) const;
554 void SetTexCoord2(float s, float t, float p, float q) const;
555 void SetTexCoord2S(int s, int t, int p, int q) const;
556 void SetTexCoord3(float u, float v) const;
557 void SetTexCoord3S(int u, int v) const;
558 void SetTexCoord3(float s, float t, float p, float q) const;
559 void SetTexCoord3S(int s, int t, int p, int q) const;
560
564 void SetBackDiffuse(uint32_t rgba) const;
565
566 void SetBackDiffuse(const float *vals) const { SetBackDiffuse(TO_RGBA(vals)); }
567 void SetBackDiffuse(float r, float g, float b, float a = 1.f) const {
568 const float vals[]{r, g, b, a};
569 SetBackDiffuse(TO_RGBA(vals));
570 }
571
575 void SetBackSpecular(uint32_t rgba) const;
576
577 void SetBackSpecular(const float *vals) const { SetBackSpecular(TO_RGBA(vals)); }
578
579 void SetBackSpecular(float r, float g, float b, float a = 1.f) const {
580 const float vals[]{r, g, b, a};
581 SetBackSpecular(TO_RGBA(vals));
582 }
583
585 static std::string GetPrimitiveName(DrawPrimitive primitive);
586
588 [[nodiscard]] bool GetSaveResults() const { return save_results_; }
590 void SetSaveResults(bool enable = true) { save_results_ = enable; }
591
593 void SetColorMask(uint32_t mask = NV097_SET_COLOR_MASK_BLUE_WRITE_ENABLE | NV097_SET_COLOR_MASK_GREEN_WRITE_ENABLE |
594 NV097_SET_COLOR_MASK_RED_WRITE_ENABLE |
595 NV097_SET_COLOR_MASK_ALPHA_WRITE_ENABLE) const;
596
598 void SetBlend(bool enable = true, uint32_t func = NV097_SET_BLEND_EQUATION_V_FUNC_ADD,
599 uint32_t sfactor = NV097_SET_BLEND_FUNC_SFACTOR_V_SRC_ALPHA,
600 uint32_t dfactor = NV097_SET_BLEND_FUNC_DFACTOR_V_ONE_MINUS_SRC_ALPHA) const;
601
603 void SetBlendColorConstant(uint32_t color) const;
604
606 void SetAlphaReference(uint32_t color) const;
607
609 void SetAlphaFunc(bool enable = true, uint32_t func = NV097_SET_ALPHA_FUNC_V_ALWAYS) const;
610
615 void SetCombinerControl(int num_combiners = 1, bool same_factor0 = false, bool same_factor1 = false,
616 bool mux_msb = false) const;
617
620 CombinerInput c = ZeroInput(), CombinerInput d = ZeroInput()) const {
621 SetInputColorCombiner(combiner, a.source, a.alpha, a.mapping, b.source, b.alpha, b.mapping, c.source, c.alpha,
622 c.mapping, d.source, d.alpha, d.mapping);
623 }
625 void SetInputColorCombiner(int combiner, CombinerSource a_source = SRC_ZERO, bool a_alpha = false,
626 CombinerMapping a_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource b_source = SRC_ZERO,
627 bool b_alpha = false, CombinerMapping b_mapping = MAP_UNSIGNED_IDENTITY,
628 CombinerSource c_source = SRC_ZERO, bool c_alpha = false,
629 CombinerMapping c_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource d_source = SRC_ZERO,
630 bool d_alpha = false, CombinerMapping d_mapping = MAP_UNSIGNED_IDENTITY) const;
631 void ClearInputColorCombiner(int combiner) const;
632 void ClearInputColorCombiners() const;
633
636 CombinerInput c = ZeroInput(), CombinerInput d = ZeroInput()) const {
637 SetInputAlphaCombiner(combiner, a.source, a.alpha, a.mapping, b.source, b.alpha, b.mapping, c.source, c.alpha,
638 c.mapping, d.source, d.alpha, d.mapping);
639 }
641 void SetInputAlphaCombiner(int combiner, CombinerSource a_source = SRC_ZERO, bool a_alpha = false,
642 CombinerMapping a_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource b_source = SRC_ZERO,
643 bool b_alpha = false, CombinerMapping b_mapping = MAP_UNSIGNED_IDENTITY,
644 CombinerSource c_source = SRC_ZERO, bool c_alpha = false,
645 CombinerMapping c_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource d_source = SRC_ZERO,
646 bool d_alpha = false, CombinerMapping d_mapping = MAP_UNSIGNED_IDENTITY) const;
647 void ClearInputAlphaColorCombiner(int combiner) const;
648 void ClearInputAlphaCombiners() const;
649
651 void SetOutputColorCombiner(int combiner, CombinerDest ab_dst = DST_DISCARD, CombinerDest cd_dst = DST_DISCARD,
652 CombinerDest sum_dst = DST_DISCARD, bool ab_dot_product = false,
653 bool cd_dot_product = false, CombinerSumMuxMode sum_or_mux = SM_SUM,
654 CombinerOutOp op = OP_IDENTITY, bool alpha_from_ab_blue = false,
655 bool alpha_from_cd_blue = false) const;
656 void ClearOutputColorCombiner(int combiner) const;
657 void ClearOutputColorCombiners() const;
658
660 void SetOutputAlphaCombiner(int combiner, CombinerDest ab_dst = DST_DISCARD, CombinerDest cd_dst = DST_DISCARD,
661 CombinerDest sum_dst = DST_DISCARD, bool ab_dot_product = false,
662 bool cd_dot_product = false, CombinerSumMuxMode sum_or_mux = SM_SUM,
663 CombinerOutOp op = OP_IDENTITY) const;
664 void ClearOutputAlphaColorCombiner(int combiner) const;
665 void ClearOutputAlphaCombiners() const;
666
667 void SetFinalCombiner0Just(CombinerSource d_source, bool d_alpha = false, bool d_invert = false) {
668 SetFinalCombiner0(SRC_ZERO, false, false, SRC_ZERO, false, false, SRC_ZERO, false, false, d_source, d_alpha,
669 d_invert);
670 }
672 void SetFinalCombiner0(CombinerSource a_source = SRC_ZERO, bool a_alpha = false, bool a_invert = false,
673 CombinerSource b_source = SRC_ZERO, bool b_alpha = false, bool b_invert = false,
674 CombinerSource c_source = SRC_ZERO, bool c_alpha = false, bool c_invert = false,
675 CombinerSource d_source = SRC_ZERO, bool d_alpha = false, bool d_invert = false);
676
677 void SetFinalCombiner1Just(CombinerSource g_source, bool g_alpha = false, bool g_invert = false) {
678 SetFinalCombiner1(SRC_ZERO, false, false, SRC_ZERO, false, false, g_source, g_alpha, g_invert);
679 }
681 void SetFinalCombiner1(CombinerSource e_source = SRC_ZERO, bool e_alpha = false, bool e_invert = false,
682 CombinerSource f_source = SRC_ZERO, bool f_alpha = false, bool f_invert = false,
683 CombinerSource g_source = SRC_ZERO, bool g_alpha = false, bool g_invert = false,
684 bool specular_add_invert_r0 = false, bool specular_add_invert_v1 = false,
685 bool specular_clamp = false);
686
687 void SetCombinerFactorC0(int combiner, uint32_t value) const;
688 void SetCombinerFactorC0(int combiner, float red, float green, float blue, float alpha) const;
689 void SetCombinerFactorC1(int combiner, uint32_t value) const;
690 void SetCombinerFactorC1(int combiner, float red, float green, float blue, float alpha) const;
691
692 void SetFinalCombinerFactorC0(uint32_t value) const;
693 void SetFinalCombinerFactorC0(float red, float green, float blue, float alpha) const;
694 void SetFinalCombinerFactorC1(uint32_t value) const;
695 void SetFinalCombinerFactorC1(float red, float green, float blue, float alpha) const;
696
697 [[nodiscard]] std::pair<uint32_t, uint32_t> GetFinalCombinerState() const {
698 return std::make_pair(last_specular_fog_cw0_, last_specular_fog_cw1_);
699 }
700
701 void RestoreFinalCombinerState(const std::pair<uint32_t, uint32_t> &state);
702
706 void SetShaderStageProgram(ShaderStageProgram stage_0, ShaderStageProgram stage_1 = STAGE_NONE,
707 ShaderStageProgram stage_2 = STAGE_NONE, ShaderStageProgram stage_3 = STAGE_NONE) const;
710 void SetShaderStageInput(uint32_t stage_2_input = 0, uint32_t stage_3_input = 0) const;
711
712 void SetVertexBufferAttributes(uint32_t enabled_fields);
713
716 void OverrideVertexAttributeStride(VertexAttribute attribute, uint32_t stride);
718 void ClearVertexAttributeStrideOverride(VertexAttribute attribute);
721 for (auto i = 0; i < 16; ++i) {
722 ClearVertexAttributeStrideOverride(static_cast<VertexAttribute>(1 << i));
723 }
724 }
725
727 void SetupControl0(bool enable_stencil_write = true, bool w_buffered = false,
728 bool texture_perspective_enable = true) const;
729
732 void SetupTextureStages() const;
733
735 static std::string SaveTexture(const std::string &output_directory, const std::string &name, const uint8_t *texture,
736 uint32_t width, uint32_t height, uint32_t pitch, uint32_t bits_per_pixel,
737 SDL_PixelFormatEnum format);
739 static std::string SaveRawTexture(const std::string &output_directory, const std::string &name,
740 const uint8_t *texture, uint32_t width, uint32_t height, uint32_t pitch,
741 uint32_t bits_per_pixel);
743 [[nodiscard]] std::string SaveZBuffer(const std::string &output_directory, const std::string &name) const;
744
746 static float MaxDepthBufferValue(uint32_t depth_buffer_format, bool float_mode);
747
749 [[nodiscard]] float GetMaxDepthBufferValue() const {
750 return MaxDepthBufferValue(depth_buffer_format_, depth_buffer_mode_float_);
751 }
752
754 static float NV2ARound(float input);
755
757 static void EnsureFolderExists(const std::string &folder_path);
758
760 static void WaitForGPU() {
762 Pushbuffer::Push(NV097_NO_OPERATION, 0);
763 Pushbuffer::Push(NV097_WAIT_FOR_IDLE, 0);
765 }
766
768 static void PBKitBusyWait() {
769 while (pb_busy()) {
770 /* Wait for completion... */
771 }
772 }
773
777 static void PBKitFlushPushbufer() {
779 pb_reset();
780 }
781
786 void DrawCheckerboardUnproject(uint32_t first_color = 0xFF00FFFF, uint32_t second_color = 0xFF000000,
787 uint32_t checker_size = 8);
788
790 void RenderToSurfaceStart(void *surface_address, SurfaceColorFormat color_format, uint32_t width, uint32_t height,
791 bool swizzle = false, uint32_t clip_x = 0, uint32_t clip_y = 0, uint32_t clip_width = 0,
792 uint32_t clip_height = 0, AntiAliasingSetting aa = AA_CENTER_1);
793
795 void RenderToSurfaceEnd();
796
797 private:
799 void HandleDepthBufferFormatChange();
800 [[nodiscard]] uint32_t MakeInputCombiner(CombinerSource a_source, bool a_alpha, CombinerMapping a_mapping,
801 CombinerSource b_source, bool b_alpha, CombinerMapping b_mapping,
802 CombinerSource c_source, bool c_alpha, CombinerMapping c_mapping,
803 CombinerSource d_source, bool d_alpha, CombinerMapping d_mapping) const;
804 [[nodiscard]] uint32_t MakeOutputCombiner(CombinerDest ab_dst, CombinerDest cd_dst, CombinerDest sum_dst,
805 bool ab_dot_product, bool cd_dot_product, CombinerSumMuxMode sum_or_mux,
806 CombinerOutOp op) const;
807 static std::string PrepareSaveFile(std::string output_directory, const std::string &filename,
808 const std::string &ext = ".png");
809 static std::string SaveBackBuffer(const std::string &output_directory, const std::string &name);
810
811 private:
812 uint32_t framebuffer_width_;
813 uint32_t framebuffer_height_;
814
815 uint32_t max_texture_width_;
816 uint32_t max_texture_height_;
817 uint32_t max_texture_depth_;
818 uint32_t max_single_texture_size_{0};
819
820 TextureStage texture_stage_[4];
821
822 bool surface_swizzle_{false};
823 SurfaceColorFormat surface_color_format_{SCF_A8R8G8B8};
824 SurfaceZetaFormat depth_buffer_format_{SZF_Z24S8};
825 bool depth_buffer_mode_float_{false};
826 uint32_t surface_clip_x_{0};
827 uint32_t surface_clip_y_{0};
828 uint32_t surface_clip_width_{640};
829 uint32_t surface_clip_height_{480};
830 uint32_t surface_width_{640};
831 uint32_t surface_height_{480};
832 AntiAliasingSetting antialiasing_setting_{AA_CENTER_1};
833
834 std::shared_ptr<VertexShaderProgram> vertex_shader_program_{};
835
836 std::shared_ptr<VertexBuffer> vertex_buffer_{};
837 uint8_t *texture_memory_{nullptr};
838 uint8_t *texture_palette_memory_{nullptr};
839 uint32_t texture_memory_size_{0};
840
841 enum FixedFunctionMatrixSetting {
842 MATRIX_MODE_DEFAULT_NXDK,
843 MATRIX_MODE_DEFAULT_XDK,
844 MATRIX_MODE_USER,
845 };
846 FixedFunctionMatrixSetting fixed_function_matrix_mode_{MATRIX_MODE_DEFAULT_NXDK};
847 matrix4_t fixed_function_model_view_matrix_{};
848 matrix4_t fixed_function_projection_matrix_{};
849 matrix4_t fixed_function_composite_matrix_{};
850 matrix4_t fixed_function_inverse_composite_matrix_{};
851
852 float w_near_{0.f};
853 float w_far_{0.f};
854
855 bool save_results_{true};
856
858 uint32_t last_specular_fog_cw0_{0};
860 uint32_t last_specular_fog_cw1_{0};
861
862 std::shared_ptr<FTPLogger> ftp_logger_;
863
864 uint32_t vertex_attribute_stride_override_[16]{
865 kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride,
866 kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride,
867 kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride};
868
870 SurfaceColorFormat framebuffer_surface_color_format_{SCF_A8R8G8B8};
871};
872
873#endif // NXDK_PGRAPH_TESTS_TEST_HOST_H
static void End(bool flush=false)
Commits any outstanding pushbuffer messages.
Definition pushbuffer.cpp:28
static void Push(uint32_t command, uint32_t param1)
Pushes the given command and param to the subchannel assigned for 3D operations.
Definition pushbuffer.cpp:118
static void Begin()
Starts a logical pushbuffer block.
Definition pushbuffer.cpp:20
Definition test_host.h:48
void SetDepthBufferFloatMode(bool enabled)
Changes the current depth buffer mode into float (true) or fixed integer (false).
Definition test_host.cpp:1000
void DrawCheckerboardUnproject(uint32_t first_color=0xFF00FFFF, uint32_t second_color=0xFF000000, uint32_t checker_size=8)
Definition test_host.cpp:1659
void SetScreenVertex(float x, float y, float world_z) const
Unprojects the given coordinates and calls SetVertex.
Definition test_host.h:512
std::shared_ptr< VertexBuffer > GetVertexBuffer()
Returns the active vertex buffer.
Definition test_host.h:384
static std::string SaveRawTexture(const std::string &output_directory, const std::string &name, const uint8_t *texture, uint32_t width, uint32_t height, uint32_t pitch, uint32_t bits_per_pixel)
Saves the given region of memory as a flat binary file.
Definition test_host.cpp:919
float GetMaxDepthBufferValue() const
Returns the maximum value for the current depth buffer format.
Definition test_host.h:749
static uint32_t GetSurfaceColorPitch(SurfaceColorFormat fmt, uint32_t width)
Returns the pitch (bytes per row) for the given format and width in pixels.
Definition test_host.h:317
bool GetSaveResults() const
Returns the current override flag to allow/prevent artifact saving.
Definition test_host.h:588
PaletteSize
Palette size for palettized surfaces.
Definition test_host.h:195
static void EnsureFolderExists(const std::string &folder_path)
Creates the given directory if it does not already exist.
Definition test_host.cpp:789
uint32_t GetFramebufferHeight() const
Returns the height of the screen, in pixels.
Definition test_host.h:373
static void BuildD3DOrthographicProjectionMatrix(matrix4_t &result, float left, float right, float top, float bottom, float z_near, float z_far)
Builds an orthographic projection matrix.
Definition test_host.cpp:1188
static void PBKitFlushPushbufer()
Definition test_host.h:777
uint32_t GetMaxSingleTextureSize() const
Returns the maximum size in bytes that any single texture can be.
Definition test_host.h:354
void DrawScreenQuad(float left, float top, float right, float bottom, float world_z) const
Draws a quad by unprojecting the given coordinates.
Definition test_host.h:502
static std::string SaveTexture(const std::string &output_directory, const std::string &name, const uint8_t *texture, uint32_t width, uint32_t height, uint32_t pitch, uint32_t bits_per_pixel, SDL_PixelFormatEnum format)
Saves the given texture to the filesystem as a PNG file.
Definition test_host.cpp:895
uint8_t * GetTextureMemory() const
Returns the base of texture memory.
Definition test_host.h:357
void UnprojectPoint(vector_t &result, const vector_t &screen_point) const
Unprojects a point in screenspace into 3D worldspace.
Definition test_host.cpp:1201
uint32_t GetMaxTextureHeight() const
Returns the maximum height for a texture.
Definition test_host.h:350
void SetupTextureStages() const
Definition test_host.cpp:966
DrawPrimitive
Enumerates the rendering primitives supported by the NV2A.
Definition test_host.h:72
static float NV2ARound(float input)
Rounds the given integer in the same way as nv2a hardware (only remainders >= 9/16th are rounded up).
Definition test_host.cpp:1628
void SetShaderStageProgram(ShaderStageProgram stage_0, ShaderStageProgram stage_1=STAGE_NONE, ShaderStageProgram stage_2=STAGE_NONE, ShaderStageProgram stage_3=STAGE_NONE) const
Definition test_host.cpp:1594
ShaderStageProgram
Texture unit modes.
Definition test_host.h:203
std::shared_ptr< VertexShaderProgram > GetShaderProgram() const
Returns the active vertex shader.
Definition test_host.h:431
void RenderToSurfaceStart(void *surface_address, SurfaceColorFormat color_format, uint32_t width, uint32_t height, bool swizzle=false, uint32_t clip_x=0, uint32_t clip_y=0, uint32_t clip_width=0, uint32_t clip_height=0, AntiAliasingSetting aa=AA_CENTER_1)
Sets up rendering to write to a non-framebuffer address.
Definition test_host.cpp:1713
static void SetWindowClip(uint32_t right, uint32_t bottom, uint32_t left=0, uint32_t top=0, uint32_t region=0)
Sets the window clipping region.
Definition test_host.cpp:1215
void ClearVertexBuffer()
Removes the active vertex buffer.
Definition test_host.h:386
float GetFramebufferHeightF() const
Returns the height of the screen in pixels as a float.
Definition test_host.h:377
void SetOutputColorCombiner(int combiner, CombinerDest ab_dst=DST_DISCARD, CombinerDest cd_dst=DST_DISCARD, CombinerDest sum_dst=DST_DISCARD, bool ab_dot_product=false, bool cd_dot_product=false, CombinerSumMuxMode sum_or_mux=SM_SUM, CombinerOutOp op=OP_IDENTITY, bool alpha_from_ab_blue=false, bool alpha_from_cd_blue=false) const
See https://github.com/abaire/nxdk_pgraph_tests/wiki/nv2a-pixel-shaders-(combiner-stages)
Definition test_host.cpp:1426
void SetOutputAlphaCombiner(int combiner, CombinerDest ab_dst=DST_DISCARD, CombinerDest cd_dst=DST_DISCARD, CombinerDest sum_dst=DST_DISCARD, bool ab_dot_product=false, bool cd_dot_product=false, CombinerSumMuxMode sum_or_mux=SM_SUM, CombinerOutOp op=OP_IDENTITY) const
See https://github.com/abaire/nxdk_pgraph_tests/wiki/nv2a-pixel-shaders-(combiner-stages)
Definition test_host.cpp:1456
void SetDepthClip(float min, float max) const
Sets the z clipping range.
Definition test_host.cpp:184
void SetupControl0(bool enable_stencil_write=true, bool w_buffered=false, bool texture_perspective_enable=true) const
Set up the control0 register, controlling stencil writing and depth buffer mode.
Definition test_host.cpp:945
float GetFramebufferWidthF() const
Returns the width of the screen in pixels as a float.
Definition test_host.h:375
void SetDefaultViewportAndFixedFunctionMatrices()
Set up the viewport and fixed function pipeline matrices to match the nxdk settings.
Definition test_host.cpp:1114
static float MaxDepthBufferValue(uint32_t depth_buffer_format, bool float_mode)
Returns the maximum possible value that can be stored in the depth surface for the given mode.
Definition test_host.cpp:191
void ClearColorRegion(uint32_t argb, uint32_t left=0, uint32_t top=0, uint32_t width=0, uint32_t height=0) const
Sets the color of a rect within the active surface.
Definition test_host.cpp:113
static void EraseText()
Erases the pb_text overlay.
Definition test_host.cpp:123
AntiAliasingSetting
Antialiasing settings for surfaces.
Definition test_host.h:226
void End() const
Triggers the rendering of the primitive specified by the previous call to Begin.
Definition test_host.cpp:331
static void BuildDefaultXDKModelViewMatrix(matrix4_t &matrix)
Definition test_host.cpp:1155
uint32_t GetMaxTextureDepth() const
Returns the maximum depth for a texture.
Definition test_host.h:352
void PrepareDraw(uint32_t argb=0xFF000000, uint32_t depth_value=0xFFFFFFFF, uint8_t stencil_value=0x00)
Definition test_host.cpp:212
void SetInputColorCombiner(int combiner, CombinerInput a, CombinerInput b=ZeroInput(), CombinerInput c=ZeroInput(), CombinerInput d=ZeroInput()) const
See https://github.com/abaire/nxdk_pgraph_tests/wiki/nv2a-pixel-shaders-(combiner-stages)
Definition test_host.h:619
void SetXDKDefaultViewportAndFixedFunctionMatrices()
Set up the viewport and fixed function pipeline matrices to match a default XDK project.
Definition test_host.cpp:1099
static std::string GetPrimitiveName(DrawPrimitive primitive)
Returns a human-friendly name for the given DrawPrimitive.
Definition test_host.cpp:1277
void SetInputAlphaCombiner(int combiner, CombinerInput a, CombinerInput b=ZeroInput(), CombinerInput c=ZeroInput(), CombinerInput d=ZeroInput()) const
See https://github.com/abaire/nxdk_pgraph_tests/wiki/nv2a-pixel-shaders-(combiner-stages)
Definition test_host.h:635
const matrix4_t & GetFixedFunctionInverseCompositeMatrix() const
Returns the inverse composite matrix for the fixed function pipeline.
Definition test_host.h:450
void SetVertexShaderProgram(std::shared_ptr< VertexShaderProgram > program)
Sets the active vertex shader. Pass nullptr to use the fixed function pipeline.
Definition test_host.cpp:1074
void SetFinalCombiner0(CombinerSource a_source=SRC_ZERO, bool a_alpha=false, bool a_invert=false, CombinerSource b_source=SRC_ZERO, bool b_alpha=false, bool b_invert=false, CombinerSource c_source=SRC_ZERO, bool c_alpha=false, bool c_invert=false, CombinerSource d_source=SRC_ZERO, bool d_alpha=false, bool d_invert=false)
See https://github.com/abaire/nxdk_pgraph_tests/wiki/nv2a-pixel-shaders-(combiner-stages)
Definition test_host.cpp:1496
uint8_t * GetTextureMemoryForStage(uint32_t stage) const
Returns the base of texture memory used by the given texture unit (stage).
Definition test_host.h:362
void ClearVertexAttributeStrideOverride(VertexAttribute attribute)
Clears any previously set vertex attribute stride override for the given attribute.
Definition test_host.cpp:1624
static void SetWindowClipExclusive(bool exclusive)
Toggles whether window clipping considers the rect as inclusive or exclusive.
Definition test_host.cpp:1209
void FinishDraw(bool allow_saving, const std::string &output_directory, const std::string &suite_name, const std::string &name, bool save_zbuffer=false)
Marks drawing as completed, potentially causing artifacts (framebuffer, z/stencil-buffer) to be saved...
Definition test_host.cpp:1035
void ProjectPoint(vector_t &result, const vector_t &world_point) const
Projects the given point (on the CPU), placing the resulting screen coordinates into result.
Definition test_host.cpp:1197
void SetColorMask(uint32_t mask=NV097_SET_COLOR_MASK_BLUE_WRITE_ENABLE|NV097_SET_COLOR_MASK_GREEN_WRITE_ENABLE|NV097_SET_COLOR_MASK_RED_WRITE_ENABLE|NV097_SET_COLOR_MASK_ALPHA_WRITE_ENABLE) const
Sets the mask used to enable modification of various color channels during rendering.
Definition test_host.cpp:1311
void SetSaveResults(bool enable=true)
Sets the override flag to prevent artifact saving during FinishDraw.
Definition test_host.h:590
void SetVertex(float x, float y, float z) const
Trigger creation of a vertex, applying the last set attributes.
Definition test_host.cpp:565
void SetBackDiffuse(uint32_t rgba) const
Definition test_host.cpp:669
void SetScreenVertex(float x, float y) const
Unprojects the given coordinates and calls SetVertex.
Definition test_host.h:520
void SetBlendColorConstant(uint32_t color) const
Sets the blend color (and alpha) used by the V_CONSTANT_COLOR and V_CONSTANT_ALPHA blend factors.
Definition test_host.cpp:1328
void SetBlend(bool enable=true, uint32_t func=NV097_SET_BLEND_EQUATION_V_FUNC_ADD, uint32_t sfactor=NV097_SET_BLEND_FUNC_SFACTOR_V_SRC_ALPHA, uint32_t dfactor=NV097_SET_BLEND_FUNC_DFACTOR_V_ONE_MINUS_SRC_ALPHA) const
Determines how pixels should be blended with existing pixels during rendering operations.
Definition test_host.cpp:1317
std::string SaveZBuffer(const std::string &output_directory, const std::string &name) const
Saves the Z/Stencil buffer to the filesystem/.
Definition test_host.cpp:882
void SetVertexBuffer(std::shared_ptr< VertexBuffer > buffer)
Sets the active vertex buffer.
Definition test_host.cpp:1097
void SetBackSpecular(uint32_t rgba) const
Definition test_host.cpp:675
void DrawInlineArray(uint32_t enabled_vertex_fields=kDefaultVertexFields, DrawPrimitive primitive=PRIMITIVE_TRIANGLES)
Sends vertices as an interleaved array of vertex fields. E.g., [POS_0,DIFFUSE_0,POS_1,...
Definition test_host.cpp:433
uint32_t GetTextureMemorySize() const
Returns the allocated size of the entire texture memory region.
Definition test_host.h:359
void DrawInlineElements32(const std::vector< uint32_t > &indices, uint32_t enabled_vertex_fields=kDefaultVertexFields, DrawPrimitive primitive=PRIMITIVE_TRIANGLES)
Sends vertices via an index array. Index values are unsigned integers.
Definition test_host.cpp:545
void BuildD3DProjectionViewportMatrix(matrix4_t &result, float fov, float z_near, float z_far) const
Gets a Direct3D-style matrix suitable for a projection + viewport transform.
Definition test_host.cpp:1166
void DrawInlineElements16(const std::vector< uint32_t > &indices, uint32_t enabled_vertex_fields=kDefaultVertexFields, DrawPrimitive primitive=PRIMITIVE_TRIANGLES)
Sends vertices via an index array. Index values must be < 0xFFFF and are sent two per command.
Definition test_host.cpp:512
void SetAlphaReference(uint32_t color) const
Sets the alpha reference value (NV097_SET_ALPHA_REF) used by NV097_SET_ALPHA_FUNC.
Definition test_host.cpp:1334
void SetFinalCombiner1(CombinerSource e_source=SRC_ZERO, bool e_alpha=false, bool e_invert=false, CombinerSource f_source=SRC_ZERO, bool f_alpha=false, bool f_invert=false, CombinerSource g_source=SRC_ZERO, bool g_alpha=false, bool g_invert=false, bool specular_add_invert_r0=false, bool specular_add_invert_v1=false, bool specular_clamp=false)
See https://github.com/abaire/nxdk_pgraph_tests/wiki/nv2a-pixel-shaders-(combiner-stages)
Definition test_host.cpp:1512
void RenderToSurfaceEnd()
Restores rendering to the backbuffer.
Definition test_host.cpp:1736
void SetCombinerControl(int num_combiners=1, bool same_factor0=false, bool same_factor1=false, bool mux_msb=false) const
Definition test_host.cpp:1347
void ClearDepthStencilRegion(uint32_t depth_value, uint8_t stencil_value, uint32_t left=0, uint32_t top=0, uint32_t width=0, uint32_t height=0) const
Sets the contents of a rect within the depth/stencil buffer.
Definition test_host.cpp:101
SurfaceColorFormat
Color formats for surfaces.
Definition test_host.h:233
bool GetDepthBufferFloatMode() const
Returns true if the current depth buffer mode is floating point.
Definition test_host.h:343
static void WaitForGPU()
Inserts a pushbuffer command to await idle.
Definition test_host.h:760
SurfaceColorFormat GetColorBufferFormat() const
Returns the current surface color format.
Definition test_host.h:290
void Begin(DrawPrimitive primitive) const
Definition test_host.cpp:325
uint32_t GetFramebufferWidth() const
Returns the width of the screen, in pixels.
Definition test_host.h:371
static void PBKitBusyWait()
Does a busywait.
Definition test_host.h:768
uint32_t * GetPaletteMemoryForStage(uint32_t stage) const
Returns the base of the palette memory for an indexed texture used by the given texture unit.
Definition test_host.h:366
SurfaceZetaFormat
Depth buffer formats for surfaces.
Definition test_host.h:249
static void BuildD3DModelViewMatrix(matrix4_t &matrix, const vector_t &eye, const vector_t &at, const vector_t &up)
Generates a Direct3D-style model view matrix.
Definition test_host.cpp:1162
uint32_t GetMaxTextureWidth() const
Returns the maximum width for a texture.
Definition test_host.h:348
void BuildDefaultXDKProjectionMatrix(matrix4_t &matrix) const
Gets a reasonable default projection matrix (fov = PI/4, near = 1, far = 200) similar to the one used...
Definition test_host.cpp:1193
void Clear(uint32_t argb=0xFF000000, uint32_t depth_value=0xFFFFFFFF, uint8_t stencil_value=0x00) const
Clears the active surface and pb_text overlay.
Definition test_host.cpp:125
void ClearAllVertexAttributeStrideOverrides()
Clears all vertex attribute stride overrides.
Definition test_host.h:720
void SetVertex(const vector_t pt) const
Trigger creation of a vertex, applying the last set attributes.
Definition test_host.h:499
std::shared_ptr< VertexBuffer > AllocateVertexBuffer(uint32_t num_vertices)
Allocates a VertexBuffer large enough to hold the given number of vertices.
Definition test_host.cpp:1091
void SetAlphaFunc(bool enable=true, uint32_t func=NV097_SET_ALPHA_FUNC_V_ALWAYS) const
Sets the alpha function used to mask writes based on alpha values.
Definition test_host.cpp:1340
void SetShaderStageInput(uint32_t stage_2_input=0, uint32_t stage_3_input=0) const
Definition test_host.cpp:1604
void OverrideVertexAttributeStride(VertexAttribute attribute, uint32_t stride)
Definition test_host.cpp:1613
SurfaceZetaFormat GetDepthBufferFormat() const
Returns the current depth buffer format.
Definition test_host.h:293
Definition texture_stage.h:13
Definition vertex_buffer.h:204
Definition vertex_shader_program.h:13
Definition test_host.h:162
Definition test_host.h:154
Definition test_host.h:148
Definition test_host.h:178
Definition test_host.h:186
Definition test_host.h:170
Definition texture_format.h:8
Definition vertex_buffer.h:16