1#ifndef NXDK_PGRAPH_TESTS_TEST_HOST_H
2#define NXDK_PGRAPH_TESTS_TEST_HOST_H
4#include <debug_output.h>
6#include <pbkit/pbkit.h>
7#include <printf/printf.h>
14#include "texture_format.h"
15#include "texture_stage.h"
16#include "vertex_buffer.h"
17#include "xbox_math_types.h"
19using namespace XboxMath;
28constexpr uint32_t kNextSubchannel = NEXT_SUBCH;
30constexpr int32_t kNextContextChannel = 25;
32constexpr uint32_t kNoStrideOverride = 0xFFFFFFFF;
35#define VRAM_MAX 0x07FFFFFF
37#define VRAM_ADDR(x) (reinterpret_cast<uint32_t>(x) & 0x03FFFFFF)
38#define SET_MASK(mask, val) (((val) << (__builtin_ffs(mask) - 1)) & (mask))
40#define TO_RGBA(float_vals) \
41 (((uint32_t)((float_vals)[3] * 255.0f) << 24) + ((uint32_t)((float_vals)[2] * 255.0f) << 16) + \
42 ((uint32_t)((float_vals)[1] * 255.0f) << 8) + ((uint32_t)((float_vals)[0] * 255.0f)))
49 enum VertexAttribute {
50 POSITION = 1 << NV2A_VERTEX_ATTR_POSITION,
51 WEIGHT = 1 << NV2A_VERTEX_ATTR_WEIGHT,
52 NORMAL = 1 << NV2A_VERTEX_ATTR_NORMAL,
53 DIFFUSE = 1 << NV2A_VERTEX_ATTR_DIFFUSE,
54 SPECULAR = 1 << NV2A_VERTEX_ATTR_SPECULAR,
55 FOG_COORD = 1 << NV2A_VERTEX_ATTR_FOG_COORD,
56 POINT_SIZE = 1 << NV2A_VERTEX_ATTR_POINT_SIZE,
57 BACK_DIFFUSE = 1 << NV2A_VERTEX_ATTR_BACK_DIFFUSE,
58 BACK_SPECULAR = 1 << NV2A_VERTEX_ATTR_BACK_SPECULAR,
59 TEXCOORD0 = 1 << NV2A_VERTEX_ATTR_TEXTURE0,
60 TEXCOORD1 = 1 << NV2A_VERTEX_ATTR_TEXTURE1,
61 TEXCOORD2 = 1 << NV2A_VERTEX_ATTR_TEXTURE2,
62 TEXCOORD3 = 1 << NV2A_VERTEX_ATTR_TEXTURE3,
63 V13 = 1 << NV2A_VERTEX_ATTR_13,
64 V14 = 1 << NV2A_VERTEX_ATTR_14,
65 V15 = 1 << NV2A_VERTEX_ATTR_15,
68 static constexpr uint32_t kDefaultVertexFields = POSITION | DIFFUSE | TEXCOORD0;
72 PRIMITIVE_POINTS = NV097_SET_BEGIN_END_OP_POINTS,
73 PRIMITIVE_LINES = NV097_SET_BEGIN_END_OP_LINES,
74 PRIMITIVE_LINE_LOOP = NV097_SET_BEGIN_END_OP_LINE_LOOP,
75 PRIMITIVE_LINE_STRIP = NV097_SET_BEGIN_END_OP_LINE_STRIP,
76 PRIMITIVE_TRIANGLES = NV097_SET_BEGIN_END_OP_TRIANGLES,
77 PRIMITIVE_TRIANGLE_STRIP = NV097_SET_BEGIN_END_OP_TRIANGLE_STRIP,
78 PRIMITIVE_TRIANGLE_FAN = NV097_SET_BEGIN_END_OP_TRIANGLE_FAN,
79 PRIMITIVE_QUADS = NV097_SET_BEGIN_END_OP_QUADS,
80 PRIMITIVE_QUAD_STRIP = NV097_SET_BEGIN_END_OP_QUAD_STRIP,
81 PRIMITIVE_POLYGON = NV097_SET_BEGIN_END_OP_POLYGON,
122 enum CombinerSumMuxMode {
131 OP_SHIFT_LEFT_1_BIAS = 3,
133 OP_SHIFT_RIGHT_1 = 6,
136 enum CombinerMapping {
137 MAP_UNSIGNED_IDENTITY,
148 CombinerSource source;
150 CombinerMapping mapping;
173 mapping = MAP_UNSIGNED_IDENTITY;
181 mapping = MAP_EXPAND_NORMAL;
189 mapping = MAP_UNSIGNED_INVERT;
210 STAGE_BUMPENVMAP_LUMINANCE,
214 STAGE_DOT_REFLECT_DIFFUSE,
215 STAGE_DOT_REFLECT_SPECULAR,
221 STAGE_DOT_REFLECT_SPECULAR_CONST,
226 AA_CENTER_1 = NV097_SET_SURFACE_FORMAT_ANTI_ALIASING_CENTER_1,
227 AA_CENTER_CORNER_2 = NV097_SET_SURFACE_FORMAT_ANTI_ALIASING_CENTER_CORNER_2,
228 AA_SQUARE_OFFSET_4 = NV097_SET_SURFACE_FORMAT_ANTI_ALIASING_SQUARE_OFFSET_4,
233 SCF_X1R5G5B5_Z1R5G5B5 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1R5G5B5_Z1R5G5B5,
234 SCF_X1R5G5B5_O1R5G5B5 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1R5G5B5_O1R5G5B5,
235 SCF_R5G6B5 = NV097_SET_SURFACE_FORMAT_COLOR_LE_R5G6B5,
236 SCF_X8R8G8B8_Z8R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X8R8G8B8_Z8R8G8B8,
237 SCF_X8R8G8B8_O8R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X8R8G8B8_O8R8G8B8,
238 SCF_X1A7R8G8B8_Z1A7R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1A7R8G8B8_Z1A7R8G8B8,
239 SCF_X1A7R8G8B8_O1A7R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_X1A7R8G8B8_O1A7R8G8B8,
240 SCF_A8R8G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_A8R8G8B8,
243 SCF_B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_B8,
244 SCF_G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_G8B8,
249 SZF_Z16 = NV097_SET_SURFACE_FORMAT_ZETA_Z16,
250 SZF_Z24S8 = NV097_SET_SURFACE_FORMAT_ZETA_Z24S8
254 TestHost(std::shared_ptr<FTPLogger> ftp_logger, uint32_t framebuffer_width, uint32_t framebuffer_height,
255 uint32_t max_texture_width, uint32_t max_texture_height, uint32_t max_texture_depth = 4);
258 TextureStage &GetTextureStage(uint32_t stage) {
return texture_stage_[stage]; }
260 void SetDefaultTextureParams(uint32_t stage = 0);
261 int SetTexture(SDL_Surface *surface, uint32_t stage = 0);
262 int SetVolumetricTexture(
const SDL_Surface **surface, uint32_t depth, uint32_t stage = 0);
263 int SetRawTexture(
const uint8_t *source, uint32_t width, uint32_t height, uint32_t depth, uint32_t pitch,
264 uint32_t bytes_per_pixel,
bool swizzle, uint32_t stage = 0);
266 int SetPalette(
const uint32_t *palette,
PaletteSize size, uint32_t stage = 0);
267 void SetPaletteSize(
PaletteSize size, uint32_t stage = 0);
268 void SetTextureStageEnabled(uint32_t stage,
bool enabled =
true);
279 uint32_t height,
bool swizzle =
false, uint32_t clip_x = 0, uint32_t clip_y = 0,
284 uint32_t height,
bool swizzle =
false, uint32_t clip_x = 0, uint32_t clip_y = 0,
285 uint32_t clip_width = 0, uint32_t clip_height = 0,
296 case SCF_X1R5G5B5_Z1R5G5B5:
297 case SCF_X1R5G5B5_O1R5G5B5:
298 case SCF_X8R8G8B8_Z8R8G8B8:
299 case SCF_X8R8G8B8_O8R8G8B8:
300 case SCF_X1A7R8G8B8_Z1A7R8G8B8:
301 case SCF_X1A7R8G8B8_O1A7R8G8B8:
311 ASSERT(!
"Invalid surface color format");
318 case SCF_X1R5G5B5_Z1R5G5B5:
319 case SCF_X1R5G5B5_O1R5G5B5:
324 case SCF_X8R8G8B8_Z8R8G8B8:
325 case SCF_X8R8G8B8_O8R8G8B8:
326 case SCF_X1A7R8G8B8_Z1A7R8G8B8:
327 case SCF_X1A7R8G8B8_O1A7R8G8B8:
335 ASSERT(!
"Invalid surface color format");
344 void CommitSurfaceFormat()
const;
362 return texture_memory_ + texture_stage_[stage].GetTextureOffset();
366 return reinterpret_cast<uint32_t *
>(texture_palette_memory_ + texture_stage_[stage].GetPaletteOffset());
388 void Clear(uint32_t argb = 0xFF000000, uint32_t depth_value = 0xFFFFFFFF, uint8_t stencil_value = 0x00)
const;
391 uint32_t width = 0, uint32_t height = 0)
const;
393 void ClearColorRegion(uint32_t argb, uint32_t left = 0, uint32_t top = 0, uint32_t width = 0,
394 uint32_t height = 0)
const;
402 void PrepareDraw(uint32_t argb = 0xFF000000, uint32_t depth_value = 0xFFFFFFFF, uint8_t stencil_value = 0x00);
404 void DrawArrays(uint32_t enabled_vertex_fields = kDefaultVertexFields,
DrawPrimitive primitive = PRIMITIVE_TRIANGLES);
405 void DrawInlineBuffer(uint32_t enabled_vertex_fields = kDefaultVertexFields,
409 void DrawInlineArray(uint32_t enabled_vertex_fields = kDefaultVertexFields,
413 void DrawInlineElements16(
const std::vector<uint32_t> &indices, uint32_t enabled_vertex_fields = kDefaultVertexFields,
417 void DrawInlineElements32(
const std::vector<uint32_t> &indices, uint32_t enabled_vertex_fields = kDefaultVertexFields,
421 void FinishDraw(
bool allow_saving,
const std::string &output_directory,
const std::string &suite_name,
422 const std::string &name,
bool save_zbuffer =
false);
430 [[nodiscard]] std::shared_ptr<VertexShaderProgram>
GetShaderProgram()
const {
return vertex_shader_program_; }
433 static void BuildD3DModelViewMatrix(matrix4_t &matrix,
const vector_t &eye,
const vector_t &at,
const vector_t &up);
440 float z_near,
float z_far);
450 return fixed_function_inverse_composite_matrix_;
460 void ProjectPoint(vector_t &result,
const vector_t &world_point)
const;
463 void UnprojectPoint(vector_t &result,
const vector_t &screen_point)
const;
465 void UnprojectPoint(vector_t &result,
const vector_t &screen_point,
float world_z)
const;
470 static void SetWindowClip(uint32_t right, uint32_t bottom, uint32_t left = 0, uint32_t top = 0, uint32_t region = 0);
472 static void SetViewportOffset(
float x,
float y,
float z,
float w);
473 static void SetViewportScale(
float x,
float y,
float z,
float w);
475 void SetFixedFunctionModelViewMatrix(
const matrix4_t &model_matrix);
476 void SetFixedFunctionProjectionMatrix(
const matrix4_t &projection_matrix);
477 [[nodiscard]]
inline const matrix4_t &GetFixedFunctionModelViewMatrix()
const {
478 return fixed_function_model_view_matrix_;
480 [[nodiscard]]
inline const matrix4_t &GetFixedFunctionProjectionMatrix()
const {
481 return fixed_function_projection_matrix_;
484 [[nodiscard]]
float GetWNear()
const {
return w_near_; }
485 [[nodiscard]]
float GetWFar()
const {
return w_far_; }
494 void SetVertex(
float x,
float y,
float z)
const;
496 void SetVertex(
float x,
float y,
float z,
float w)
const;
502 vector_t screen{x, y, screen_z, 1.f};
510 vector_t screen{x, y, 0.f, 1.f};
516 void SetWeight(
float w)
const;
517 void SetWeight(
float w1,
float w2)
const;
518 void SetWeight(
float w1,
float w2,
float w3)
const;
519 void SetWeight(
float w1,
float w2,
float w3,
float w4)
const;
520 void SetNormal(
float x,
float y,
float z)
const;
521 void SetNormal(
const float *vals)
const;
522 void SetNormal3S(
int x,
int y,
int z)
const;
523 void SetDiffuse(
const vector_t &color)
const { SetDiffuse(color[0], color[1], color[2], color[3]); }
524 void SetDiffuse(
float r,
float g,
float b,
float a)
const;
525 void SetDiffuse(
float r,
float g,
float b)
const;
526 void SetDiffuse(uint32_t rgba)
const;
527 void SetSpecular(
const vector_t &color)
const { SetSpecular(color[0], color[1], color[2], color[3]); }
528 void SetSpecular(
float r,
float g,
float b,
float a)
const;
529 void SetSpecular(
float r,
float g,
float b)
const;
530 void SetSpecular(uint32_t rgba)
const;
531 void SetFogCoord(
float fc)
const;
532 void SetPointSize(
float ps)
const;
533 void SetTexCoord0(
float u,
float v)
const;
534 void SetTexCoord0S(
int u,
int v)
const;
535 void SetTexCoord0(
float s,
float t,
float p,
float q)
const;
536 void SetTexCoord0S(
int s,
int t,
int p,
int q)
const;
537 void SetTexCoord1(
float u,
float v)
const;
538 void SetTexCoord1S(
int u,
int v)
const;
539 void SetTexCoord1(
float s,
float t,
float p,
float q)
const;
540 void SetTexCoord1S(
int s,
int t,
int p,
int q)
const;
541 void SetTexCoord2(
float u,
float v)
const;
542 void SetTexCoord2S(
int u,
int v)
const;
543 void SetTexCoord2(
float s,
float t,
float p,
float q)
const;
544 void SetTexCoord2S(
int s,
int t,
int p,
int q)
const;
545 void SetTexCoord3(
float u,
float v)
const;
546 void SetTexCoord3S(
int u,
int v)
const;
547 void SetTexCoord3(
float s,
float t,
float p,
float q)
const;
548 void SetTexCoord3S(
int s,
int t,
int p,
int q)
const;
556 void SetBackDiffuse(
float r,
float g,
float b,
float a = 1.f)
const {
557 const float vals[]{r, g, b, a};
569 const float vals[]{r, g, b, a};
582 void SetColorMask(uint32_t mask = NV097_SET_COLOR_MASK_BLUE_WRITE_ENABLE | NV097_SET_COLOR_MASK_GREEN_WRITE_ENABLE |
583 NV097_SET_COLOR_MASK_RED_WRITE_ENABLE |
584 NV097_SET_COLOR_MASK_ALPHA_WRITE_ENABLE)
const;
587 void SetBlend(
bool enable =
true, uint32_t func = NV097_SET_BLEND_EQUATION_V_FUNC_ADD,
588 uint32_t sfactor = NV097_SET_BLEND_FUNC_SFACTOR_V_SRC_ALPHA,
589 uint32_t dfactor = NV097_SET_BLEND_FUNC_DFACTOR_V_ONE_MINUS_SRC_ALPHA)
const;
598 void SetAlphaFunc(
bool enable =
true, uint32_t func = NV097_SET_ALPHA_FUNC_V_ALWAYS)
const;
604 void SetCombinerControl(
int num_combiners = 1,
bool same_factor0 =
false,
bool same_factor1 =
false,
605 bool mux_msb =
false)
const;
610 SetInputColorCombiner(combiner, a.source, a.alpha, a.mapping, b.source, b.alpha, b.mapping, c.source, c.alpha,
611 c.mapping, d.source, d.alpha, d.mapping);
615 CombinerMapping a_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource b_source = SRC_ZERO,
616 bool b_alpha =
false, CombinerMapping b_mapping = MAP_UNSIGNED_IDENTITY,
617 CombinerSource c_source = SRC_ZERO,
bool c_alpha =
false,
618 CombinerMapping c_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource d_source = SRC_ZERO,
619 bool d_alpha =
false, CombinerMapping d_mapping = MAP_UNSIGNED_IDENTITY)
const;
620 void ClearInputColorCombiner(
int combiner)
const;
621 void ClearInputColorCombiners()
const;
626 SetInputAlphaCombiner(combiner, a.source, a.alpha, a.mapping, b.source, b.alpha, b.mapping, c.source, c.alpha,
627 c.mapping, d.source, d.alpha, d.mapping);
631 CombinerMapping a_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource b_source = SRC_ZERO,
632 bool b_alpha =
false, CombinerMapping b_mapping = MAP_UNSIGNED_IDENTITY,
633 CombinerSource c_source = SRC_ZERO,
bool c_alpha =
false,
634 CombinerMapping c_mapping = MAP_UNSIGNED_IDENTITY, CombinerSource d_source = SRC_ZERO,
635 bool d_alpha =
false, CombinerMapping d_mapping = MAP_UNSIGNED_IDENTITY)
const;
636 void ClearInputAlphaColorCombiner(
int combiner)
const;
637 void ClearInputAlphaCombiners()
const;
640 void SetOutputColorCombiner(
int combiner, CombinerDest ab_dst = DST_DISCARD, CombinerDest cd_dst = DST_DISCARD,
641 CombinerDest sum_dst = DST_DISCARD,
bool ab_dot_product =
false,
642 bool cd_dot_product =
false, CombinerSumMuxMode sum_or_mux = SM_SUM,
643 CombinerOutOp op = OP_IDENTITY,
bool alpha_from_ab_blue =
false,
644 bool alpha_from_cd_blue =
false)
const;
645 void ClearOutputColorCombiner(
int combiner)
const;
646 void ClearOutputColorCombiners()
const;
649 void SetOutputAlphaCombiner(
int combiner, CombinerDest ab_dst = DST_DISCARD, CombinerDest cd_dst = DST_DISCARD,
650 CombinerDest sum_dst = DST_DISCARD,
bool ab_dot_product =
false,
651 bool cd_dot_product =
false, CombinerSumMuxMode sum_or_mux = SM_SUM,
652 CombinerOutOp op = OP_IDENTITY)
const;
653 void ClearOutputAlphaColorCombiner(
int combiner)
const;
654 void ClearOutputAlphaCombiners()
const;
656 void SetFinalCombiner0Just(CombinerSource d_source,
bool d_alpha =
false,
bool d_invert =
false) {
657 SetFinalCombiner0(SRC_ZERO,
false,
false, SRC_ZERO,
false,
false, SRC_ZERO,
false,
false, d_source, d_alpha,
661 void SetFinalCombiner0(CombinerSource a_source = SRC_ZERO,
bool a_alpha =
false,
bool a_invert =
false,
662 CombinerSource b_source = SRC_ZERO,
bool b_alpha =
false,
bool b_invert =
false,
663 CombinerSource c_source = SRC_ZERO,
bool c_alpha =
false,
bool c_invert =
false,
664 CombinerSource d_source = SRC_ZERO,
bool d_alpha =
false,
bool d_invert =
false);
666 void SetFinalCombiner1Just(CombinerSource g_source,
bool g_alpha =
false,
bool g_invert =
false) {
667 SetFinalCombiner1(SRC_ZERO,
false,
false, SRC_ZERO,
false,
false, g_source, g_alpha, g_invert);
670 void SetFinalCombiner1(CombinerSource e_source = SRC_ZERO,
bool e_alpha =
false,
bool e_invert =
false,
671 CombinerSource f_source = SRC_ZERO,
bool f_alpha =
false,
bool f_invert =
false,
672 CombinerSource g_source = SRC_ZERO,
bool g_alpha =
false,
bool g_invert =
false,
673 bool specular_add_invert_r0 =
false,
bool specular_add_invert_v1 =
false,
674 bool specular_clamp =
false);
676 void SetCombinerFactorC0(
int combiner, uint32_t value)
const;
677 void SetCombinerFactorC0(
int combiner,
float red,
float green,
float blue,
float alpha)
const;
678 void SetCombinerFactorC1(
int combiner, uint32_t value)
const;
679 void SetCombinerFactorC1(
int combiner,
float red,
float green,
float blue,
float alpha)
const;
681 void SetFinalCombinerFactorC0(uint32_t value)
const;
682 void SetFinalCombinerFactorC0(
float red,
float green,
float blue,
float alpha)
const;
683 void SetFinalCombinerFactorC1(uint32_t value)
const;
684 void SetFinalCombinerFactorC1(
float red,
float green,
float blue,
float alpha)
const;
686 [[nodiscard]] std::pair<uint32_t, uint32_t> GetFinalCombinerState()
const {
687 return std::make_pair(last_specular_fog_cw0_, last_specular_fog_cw1_);
690 void RestoreFinalCombinerState(
const std::pair<uint32_t, uint32_t> &state);
701 void SetVertexBufferAttributes(uint32_t enabled_fields);
710 for (
auto i = 0; i < 16; ++i) {
716 void SetupControl0(
bool enable_stencil_write =
true,
bool w_buffered =
false,
717 bool texture_perspective_enable =
true)
const;
724 static std::string
SaveTexture(
const std::string &output_directory,
const std::string &name,
const uint8_t *texture,
725 uint32_t width, uint32_t height, uint32_t pitch, uint32_t bits_per_pixel,
726 SDL_PixelFormatEnum format);
728 static std::string
SaveRawTexture(
const std::string &output_directory,
const std::string &name,
729 const uint8_t *texture, uint32_t width, uint32_t height, uint32_t pitch,
730 uint32_t bits_per_pixel);
732 [[nodiscard]] std::string
SaveZBuffer(
const std::string &output_directory,
const std::string &name)
const;
751 p = pb_push1(p, NV097_NO_OPERATION, 0);
752 p = pb_push1(p, NV097_WAIT_FOR_IDLE, 0);
776 uint32_t checker_size = 8);
780 void HandleDepthBufferFormatChange();
781 [[nodiscard]] uint32_t MakeInputCombiner(CombinerSource a_source,
bool a_alpha, CombinerMapping a_mapping,
782 CombinerSource b_source,
bool b_alpha, CombinerMapping b_mapping,
783 CombinerSource c_source,
bool c_alpha, CombinerMapping c_mapping,
784 CombinerSource d_source,
bool d_alpha, CombinerMapping d_mapping)
const;
785 [[nodiscard]] uint32_t MakeOutputCombiner(CombinerDest ab_dst, CombinerDest cd_dst, CombinerDest sum_dst,
786 bool ab_dot_product,
bool cd_dot_product, CombinerSumMuxMode sum_or_mux,
787 CombinerOutOp op)
const;
788 static std::string PrepareSaveFile(std::string output_directory,
const std::string &filename,
789 const std::string &ext =
".png");
790 static std::string SaveBackBuffer(
const std::string &output_directory,
const std::string &name);
793 uint32_t framebuffer_width_;
794 uint32_t framebuffer_height_;
796 uint32_t max_texture_width_;
797 uint32_t max_texture_height_;
798 uint32_t max_texture_depth_;
799 uint32_t max_single_texture_size_{0};
803 bool surface_swizzle_{
false};
806 bool depth_buffer_mode_float_{
false};
807 uint32_t surface_clip_x_{0};
808 uint32_t surface_clip_y_{0};
809 uint32_t surface_clip_width_{640};
810 uint32_t surface_clip_height_{480};
811 uint32_t surface_width_{640};
812 uint32_t surface_height_{480};
815 std::shared_ptr<VertexShaderProgram> vertex_shader_program_{};
817 std::shared_ptr<VertexBuffer> vertex_buffer_{};
818 uint8_t *texture_memory_{
nullptr};
819 uint8_t *texture_palette_memory_{
nullptr};
820 uint32_t texture_memory_size_{0};
822 enum FixedFunctionMatrixSetting {
823 MATRIX_MODE_DEFAULT_NXDK,
824 MATRIX_MODE_DEFAULT_XDK,
827 FixedFunctionMatrixSetting fixed_function_matrix_mode_{MATRIX_MODE_DEFAULT_NXDK};
828 matrix4_t fixed_function_model_view_matrix_{};
829 matrix4_t fixed_function_projection_matrix_{};
830 matrix4_t fixed_function_composite_matrix_{};
831 matrix4_t fixed_function_inverse_composite_matrix_{};
836 bool save_results_{
true};
839 uint32_t last_specular_fog_cw0_{0};
841 uint32_t last_specular_fog_cw1_{0};
843 std::shared_ptr<FTPLogger> ftp_logger_;
845 uint32_t vertex_attribute_stride_override_[16]{
846 kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride,
847 kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride,
848 kNoStrideOverride, kNoStrideOverride, kNoStrideOverride, kNoStrideOverride};
Definition test_host.h:47
void SetDepthBufferFloatMode(bool enabled)
Changes the current depth buffer mode into float (true) or fixed integer (false).
Definition test_host.cpp:1044
void DrawCheckerboardUnproject(uint32_t first_color=0xFF00FFFF, uint32_t second_color=0xFF000000, uint32_t checker_size=8)
Definition test_host.cpp:1733
std::shared_ptr< VertexBuffer > GetVertexBuffer()
Returns the active vertex buffer.
Definition test_host.h:383
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:963
float GetMaxDepthBufferValue() const
Returns the maximum value for the current depth buffer format.
Definition test_host.h:738
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:316
void SetScreenVertex(float x, float y, float screen_z) const
Unprojects the given coordinates and calls SetVertex.
Definition test_host.h:501
bool GetSaveResults() const
Returns the current override flag to allow/prevent artifact saving.
Definition test_host.h:577
PaletteSize
Palette size for palettized surfaces.
Definition test_host.h:194
static void EnsureFolderExists(const std::string &folder_path)
Creates the given directory if it does not already exist.
Definition test_host.cpp:833
uint32_t GetFramebufferHeight() const
Returns the height of the screen, in pixels.
Definition test_host.h:372
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:1234
static void PBKitFlushPushbufer()
Definition test_host.h:766
uint32_t GetMaxSingleTextureSize() const
Returns the maximum size in bytes that any single texture can be.
Definition test_host.h:353
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:939
uint8_t * GetTextureMemory() const
Returns the base of texture memory.
Definition test_host.h:356
void UnprojectPoint(vector_t &result, const vector_t &screen_point) const
Unprojects a point in screenspace into 3D worldspace.
Definition test_host.cpp:1247
uint32_t GetMaxTextureHeight() const
Returns the maximum height for a texture.
Definition test_host.h:349
void SetupTextureStages() const
Definition test_host.cpp:1010
DrawPrimitive
Enumerates the rendering primitives supported by the NV2A.
Definition test_host.h:71
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:1702
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:1668
ShaderStageProgram
Texture unit modes.
Definition test_host.h:202
std::shared_ptr< VertexShaderProgram > GetShaderProgram() const
Returns the active vertex shader.
Definition test_host.h:430
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:1261
void ClearVertexBuffer()
Removes the active vertex buffer.
Definition test_host.h:385
float GetFramebufferHeightF() const
Returns the height of the screen in pixels as a float.
Definition test_host.h:376
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:1486
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:1523
void SetDepthClip(float min, float max) const
Sets the z clipping range.
Definition test_host.cpp:176
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:989
float GetFramebufferWidthF() const
Returns the width of the screen in pixels as a float.
Definition test_host.h:374
void SetDefaultViewportAndFixedFunctionMatrices()
Set up the viewport and fixed function pipeline matrices to match the nxdk settings.
Definition test_host.cpp:1160
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:183
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:105
static void EraseText()
Erases the pb_text overlay.
Definition test_host.cpp:115
AntiAliasingSetting
Antialiasing settings for surfaces.
Definition test_host.h:225
void End() const
Triggers the rendering of the primitive specified by the previous call to Begin.
Definition test_host.cpp:332
static void BuildDefaultXDKModelViewMatrix(matrix4_t &matrix)
Definition test_host.cpp:1201
uint32_t GetMaxTextureDepth() const
Returns the maximum depth for a texture.
Definition test_host.h:351
void PrepareDraw(uint32_t argb=0xFF000000, uint32_t depth_value=0xFFFFFFFF, uint8_t stencil_value=0x00)
Definition test_host.cpp:204
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:608
void SetXDKDefaultViewportAndFixedFunctionMatrices()
Set up the viewport and fixed function pipeline matrices to match a default XDK project.
Definition test_host.cpp:1145
static std::string GetPrimitiveName(DrawPrimitive primitive)
Returns a human-friendly name for the given DrawPrimitive.
Definition test_host.cpp:1323
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:624
const matrix4_t & GetFixedFunctionInverseCompositeMatrix() const
Returns the inverse composite matrix for the fixed function pipeline.
Definition test_host.h:449
void SetVertexShaderProgram(std::shared_ptr< VertexShaderProgram > program)
Sets the active vertex shader. Pass nullptr to use the fixed function pipeline.
Definition test_host.cpp:1120
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:1570
uint8_t * GetTextureMemoryForStage(uint32_t stage) const
Returns the base of texture memory used by the given texture unit (stage).
Definition test_host.h:361
void ClearVertexAttributeStrideOverride(VertexAttribute attribute)
Clears any previously set vertex attribute stride override for the given attribute.
Definition test_host.cpp:1698
static void SetWindowClipExclusive(bool exclusive)
Toggles whether window clipping considers the rect as inclusive or exclusive.
Definition test_host.cpp:1255
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:1079
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:1243
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:1357
void SetSaveResults(bool enable=true)
Sets the override flag to prevent artifact saving during FinishDraw.
Definition test_host.h:579
void SetVertex(float x, float y, float z) const
Trigger creation of a vertex, applying the last set attributes.
Definition test_host.cpp:609
void SetBackDiffuse(uint32_t rgba) const
Definition test_host.cpp:713
void SetScreenVertex(float x, float y) const
Unprojects the given coordinates and calls SetVertex.
Definition test_host.h:509
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:1374
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:1363
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:926
void SetVertexBuffer(std::shared_ptr< VertexBuffer > buffer)
Sets the active vertex buffer.
Definition test_host.cpp:1143
void SetBackSpecular(uint32_t rgba) const
Definition test_host.cpp:719
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:434
uint32_t GetTextureMemorySize() const
Returns the allocated size of the entire texture memory region.
Definition test_host.h:358
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:578
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:1212
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:535
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:1380
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:1586
void SetCombinerControl(int num_combiners=1, bool same_factor0=false, bool same_factor1=false, bool mux_msb=false) const
Definition test_host.cpp:1393
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:93
SurfaceColorFormat
Color formats for surfaces.
Definition test_host.h:232
bool GetDepthBufferFloatMode() const
Returns true if the current depth buffer mode is floating point.
Definition test_host.h:342
static void WaitForGPU()
Inserts a pushbuffer command to await idle.
Definition test_host.h:749
SurfaceColorFormat GetColorBufferFormat() const
Returns the current surface color format.
Definition test_host.h:289
void Begin(DrawPrimitive primitive) const
Definition test_host.cpp:326
uint32_t GetFramebufferWidth() const
Returns the width of the screen, in pixels.
Definition test_host.h:370
static void PBKitBusyWait()
Does a busywait.
Definition test_host.h:757
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:365
SurfaceZetaFormat
Depth buffer formats for surfaces.
Definition test_host.h:248
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:1208
uint32_t GetMaxTextureWidth() const
Returns the maximum width for a texture.
Definition test_host.h:347
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:1239
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:117
void ClearAllVertexAttributeStrideOverrides()
Clears all vertex attribute stride overrides.
Definition test_host.h:709
void SetVertex(const vector_t pt) const
Trigger creation of a vertex, applying the last set attributes.
Definition test_host.h:498
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:1137
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:1386
void SetShaderStageInput(uint32_t stage_2_input=0, uint32_t stage_3_input=0) const
Definition test_host.cpp:1678
void OverrideVertexAttributeStride(VertexAttribute attribute, uint32_t stride)
Definition test_host.cpp:1687
SurfaceZetaFormat GetDepthBufferFormat() const
Returns the current depth buffer format.
Definition test_host.h:292
Definition texture_stage.h:13
Definition vertex_buffer.h:204
Definition vertex_shader_program.h:13
Definition texture_format.h:8
Definition vertex_buffer.h:16