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>
13#include "pushbuffer.h"
15#include "texture_format.h"
16#include "texture_stage.h"
17#include "vertex_buffer.h"
18#include "xbox_math_types.h"
20using namespace XboxMath;
29constexpr uint32_t kNextSubchannel = NEXT_SUBCH;
31constexpr int32_t kNextContextChannel = 25;
33constexpr uint32_t kNoStrideOverride = 0xFFFFFFFF;
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))
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)))
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,
69 static constexpr uint32_t kDefaultVertexFields = POSITION | DIFFUSE | TEXCOORD0;
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,
123 enum CombinerSumMuxMode {
132 OP_SHIFT_LEFT_1_BIAS = 3,
134 OP_SHIFT_RIGHT_1 = 6,
137 enum CombinerMapping {
138 MAP_UNSIGNED_IDENTITY,
149 CombinerSource source;
151 CombinerMapping mapping;
174 mapping = MAP_UNSIGNED_IDENTITY;
182 mapping = MAP_EXPAND_NORMAL;
190 mapping = MAP_UNSIGNED_INVERT;
211 STAGE_BUMPENVMAP_LUMINANCE,
215 STAGE_DOT_REFLECT_DIFFUSE,
216 STAGE_DOT_REFLECT_SPECULAR,
222 STAGE_DOT_REFLECT_SPECULAR_CONST,
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,
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,
244 SCF_B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_B8,
245 SCF_G8B8 = NV097_SET_SURFACE_FORMAT_COLOR_LE_G8B8,
250 SZF_Z16 = NV097_SET_SURFACE_FORMAT_ZETA_Z16,
251 SZF_Z24S8 = NV097_SET_SURFACE_FORMAT_ZETA_Z24S8
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);
259 TextureStage &GetTextureStage(uint32_t stage) {
return texture_stage_[stage]; }
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);
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);
280 uint32_t height,
bool swizzle =
false, uint32_t clip_x = 0, uint32_t clip_y = 0,
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,
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:
312 ASSERT(!
"Invalid surface color format");
319 case SCF_X1R5G5B5_Z1R5G5B5:
320 case SCF_X1R5G5B5_O1R5G5B5:
325 case SCF_X8R8G8B8_Z8R8G8B8:
326 case SCF_X8R8G8B8_O8R8G8B8:
327 case SCF_X1A7R8G8B8_Z1A7R8G8B8:
328 case SCF_X1A7R8G8B8_O1A7R8G8B8:
336 ASSERT(!
"Invalid surface color format");
345 void CommitSurfaceFormat()
const;
363 return texture_memory_ + texture_stage_[stage].GetTextureOffset();
367 return reinterpret_cast<uint32_t *
>(texture_palette_memory_ + texture_stage_[stage].GetPaletteOffset());
389 void Clear(uint32_t argb = 0xFF000000, uint32_t depth_value = 0xFFFFFFFF, uint8_t stencil_value = 0x00)
const;
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;
403 void PrepareDraw(uint32_t argb = 0xFF000000, uint32_t depth_value = 0xFFFFFFFF, uint8_t stencil_value = 0x00);
405 void DrawArrays(uint32_t enabled_vertex_fields = kDefaultVertexFields,
DrawPrimitive primitive = PRIMITIVE_TRIANGLES);
406 void DrawInlineBuffer(uint32_t enabled_vertex_fields = kDefaultVertexFields,
410 void DrawInlineArray(uint32_t enabled_vertex_fields = kDefaultVertexFields,
414 void DrawInlineElements16(
const std::vector<uint32_t> &indices, uint32_t enabled_vertex_fields = kDefaultVertexFields,
418 void DrawInlineElements32(
const std::vector<uint32_t> &indices, uint32_t enabled_vertex_fields = kDefaultVertexFields,
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);
431 [[nodiscard]] std::shared_ptr<VertexShaderProgram>
GetShaderProgram()
const {
return vertex_shader_program_; }
434 static void BuildD3DModelViewMatrix(matrix4_t &matrix,
const vector_t &eye,
const vector_t &at,
const vector_t &up);
441 float z_near,
float z_far);
451 return fixed_function_inverse_composite_matrix_;
461 void ProjectPoint(vector_t &result,
const vector_t &world_point)
const;
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;
471 static void SetWindowClip(uint32_t right, uint32_t bottom, uint32_t left = 0, uint32_t top = 0, uint32_t region = 0);
473 static void SetViewportOffset(
float x,
float y,
float z,
float w);
474 static void SetViewportScale(
float x,
float y,
float z,
float w);
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_;
481 [[nodiscard]]
inline const matrix4_t &GetFixedFunctionProjectionMatrix()
const {
482 return fixed_function_projection_matrix_;
485 [[nodiscard]]
float GetWNear()
const {
return w_near_; }
486 [[nodiscard]]
float GetWFar()
const {
return w_far_; }
495 void SetVertex(
float x,
float y,
float z)
const;
497 void SetVertex(
float x,
float y,
float z,
float w)
const;
502 void DrawScreenQuad(
float left,
float top,
float right,
float bottom,
float world_z)
const {
503 Begin(PRIMITIVE_QUADS);
513 vector_t screen{x, y, world_z, 1.f};
521 vector_t screen{x, y, 0.f, 1.f};
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;
567 void SetBackDiffuse(
float r,
float g,
float b,
float a = 1.f)
const {
568 const float vals[]{r, g, b, a};
580 const float vals[]{r, g, b, a};
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;
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;
609 void SetAlphaFunc(
bool enable =
true, uint32_t func = NV097_SET_ALPHA_FUNC_V_ALWAYS)
const;
615 void SetCombinerControl(
int num_combiners = 1,
bool same_factor0 =
false,
bool same_factor1 =
false,
616 bool mux_msb =
false)
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);
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;
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);
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;
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;
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;
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,
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);
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);
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);
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;
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;
697 [[nodiscard]] std::pair<uint32_t, uint32_t> GetFinalCombinerState()
const {
698 return std::make_pair(last_specular_fog_cw0_, last_specular_fog_cw1_);
701 void RestoreFinalCombinerState(
const std::pair<uint32_t, uint32_t> &state);
712 void SetVertexBufferAttributes(uint32_t enabled_fields);
721 for (
auto i = 0; i < 16; ++i) {
727 void SetupControl0(
bool enable_stencil_write =
true,
bool w_buffered =
false,
728 bool texture_perspective_enable =
true)
const;
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;
787 uint32_t checker_size = 8);
791 bool swizzle =
false, uint32_t clip_x = 0, uint32_t clip_y = 0, uint32_t clip_width = 0,
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);
812 uint32_t framebuffer_width_;
813 uint32_t framebuffer_height_;
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};
822 bool surface_swizzle_{
false};
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};
834 std::shared_ptr<VertexShaderProgram> vertex_shader_program_{};
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};
841 enum FixedFunctionMatrixSetting {
842 MATRIX_MODE_DEFAULT_NXDK,
843 MATRIX_MODE_DEFAULT_XDK,
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_{};
855 bool save_results_{
true};
858 uint32_t last_specular_fog_cw0_{0};
860 uint32_t last_specular_fog_cw1_{0};
862 std::shared_ptr<FTPLogger> ftp_logger_;
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};
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 texture_format.h:8
Definition vertex_buffer.h:16