Adds ability to use unix style fallback path.

This commit is contained in:
Erik Abair 2022-04-11 15:23:28 -07:00
parent 59028a1c30
commit fb1d1f5999
7 changed files with 188 additions and 10 deletions

View File

@ -42,6 +42,7 @@ SRCS = \
$(SRCDIR)/tests/texgen_matrix_tests.cpp \
$(SRCDIR)/tests/texgen_tests.cpp \
$(SRCDIR)/tests/texture_border_tests.cpp \
$(SRCDIR)/tests/texture_depth_source_tests.cpp \
$(SRCDIR)/tests/texture_format_tests.cpp \
$(SRCDIR)/tests/texture_framebuffer_blit_tests.cpp \
$(SRCDIR)/tests/texture_matrix_tests.cpp \

View File

@ -40,6 +40,7 @@
#include "tests/texgen_matrix_tests.h"
#include "tests/texgen_tests.h"
#include "tests/texture_border_tests.h"
#include "tests/texture_depth_source_tests.h"
#include "tests/texture_format_tests.h"
#include "tests/texture_framebuffer_blit_tests.h"
#include "tests/texture_matrix_tests.h"
@ -159,6 +160,8 @@ static bool get_writable_output_directory(std::string& xbe_root_directory) {
debugPrint("Running from readonly media, using default path for test output.\n");
xbe_root_directory = FALLBACK_OUTPUT_ROOT_PATH;
std::replace(xbe_root_directory.begin(), xbe_root_directory.end(), '/', '\\');
return ensure_drive_mounted(xbe_root_directory.front());
}
@ -170,7 +173,8 @@ static bool get_test_output_path(std::string& test_output_directory) {
if (!get_writable_output_directory(test_output_directory)) {
return false;
}
if (test_output_directory.back() == '\\') {
char last_char = test_output_directory.back();
if (last_char == '\\' || last_char == '/') {
test_output_directory.pop_back();
}
test_output_directory += "\\nxdk_pgraph_tests";
@ -328,6 +332,10 @@ static void register_suites(TestHost& host, std::vector<std::shared_ptr<TestSuit
auto suite = std::make_shared<TextureBorderTests>(host, output_directory);
test_suites.push_back(std::dynamic_pointer_cast<TestSuite>(suite));
}
{
auto suite = std::make_shared<TextureDepthSourceTests>(host, output_directory);
test_suites.push_back(std::dynamic_pointer_cast<TestSuite>(suite));
}
{
auto suite = std::make_shared<TexgenMatrixTests>(host, output_directory);
test_suites.push_back(std::dynamic_pointer_cast<TestSuite>(suite));

View File

@ -1116,13 +1116,13 @@ std::string TestHost::GetPrimitiveName(TestHost::DrawPrimitive primitive) {
}
}
void TestHost::SetAlphaBlendEnabled(bool enable) const {
void TestHost::SetAlphaBlendEnabled(bool enable, uint32_t func, uint32_t sfactor, uint32_t dfactor) const {
auto p = pb_begin();
p = pb_push1(p, NV097_SET_BLEND_ENABLE, enable);
if (enable) {
p = pb_push1(p, NV097_SET_BLEND_EQUATION, NV097_SET_BLEND_EQUATION_V_FUNC_ADD);
p = pb_push1(p, NV097_SET_BLEND_FUNC_SFACTOR, NV097_SET_BLEND_FUNC_SFACTOR_V_SRC_ALPHA);
p = pb_push1(p, NV097_SET_BLEND_FUNC_DFACTOR, NV097_SET_BLEND_FUNC_DFACTOR_V_ONE_MINUS_SRC_ALPHA);
p = pb_push1(p, NV097_SET_BLEND_EQUATION, func);
p = pb_push1(p, NV097_SET_BLEND_FUNC_SFACTOR, sfactor);
p = pb_push1(p, NV097_SET_BLEND_FUNC_DFACTOR, dfactor);
}
pb_end(p);
}

View File

@ -255,6 +255,8 @@ class TestHost {
uint32_t GetFramebufferWidth() const { return framebuffer_width_; }
uint32_t GetFramebufferHeight() const { return framebuffer_height_; }
float GetFramebufferWidthF() const { return static_cast<float>(framebuffer_width_); }
float GetFramebufferHeightF() const { return static_cast<float>(framebuffer_height_); }
std::shared_ptr<VertexBuffer> AllocateVertexBuffer(uint32_t num_vertices);
void SetVertexBuffer(std::shared_ptr<VertexBuffer> buffer);
@ -369,7 +371,9 @@ class TestHost {
bool GetSaveResults() const { return save_results_; }
void SetSaveResults(bool enable = true) { save_results_ = enable; }
void SetAlphaBlendEnabled(bool enable = true) const;
void SetAlphaBlendEnabled(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;
// Sets up the number of enabled color combiners and behavior flags.
//

View File

@ -66,10 +66,6 @@ void TestSuite::Initialize() {
p = pb_push1(p, NV097_SET_COLOR_MATERIAL, NV097_SET_COLOR_MATERIAL_ALL_FROM_MATERIAL);
p = pb_push1f(p, NV097_SET_MATERIAL_ALPHA, 1.0f);
p = pb_push1(p, NV097_SET_BLEND_ENABLE, true);
p = pb_push1(p, NV097_SET_BLEND_EQUATION, NV097_SET_BLEND_EQUATION_V_FUNC_ADD);
p = pb_push1(p, NV097_SET_BLEND_FUNC_SFACTOR, NV097_SET_BLEND_FUNC_SFACTOR_V_SRC_ALPHA);
p = pb_push1(p, NV097_SET_BLEND_FUNC_DFACTOR, NV097_SET_BLEND_FUNC_DFACTOR_V_ONE_MINUS_SRC_ALPHA);
p = pb_push1(p, NV20_TCL_PRIMITIVE_3D_LIGHT_MODEL_TWO_SIDE_ENABLE, 0);
p = pb_push1(p, NV097_SET_FRONT_POLYGON_MODE, NV097_SET_FRONT_POLYGON_MODE_V_FILL);
p = pb_push1(p, NV097_SET_BACK_POLYGON_MODE, NV097_SET_FRONT_POLYGON_MODE_V_FILL);
@ -84,6 +80,8 @@ void TestSuite::Initialize() {
pb_end(p);
host_.SetAlphaBlendEnabled();
host_.ClearInputColorCombiners();
host_.ClearInputAlphaCombiners();
host_.ClearOutputColorCombiners();

View File

@ -0,0 +1,140 @@
#include "texture_depth_source_tests.h"
#include <pbkit/pbkit.h>
#include <utility>
#include "debug_output.h"
#include "pbkit_ext.h"
#include "test_host.h"
#define SET_MASK(mask, val) (((val) << (__builtin_ffs(mask) - 1)) & (mask))
// NV097_SET_CONTEXT_DMA_ZETA is set to channel 10 by default.
const uint32_t kDefaultDMAZetaChannel = 10;
static constexpr char kD16TestName[] = "D16_Y16";
static constexpr float kLeft = -2.75f;
static constexpr float kRight = 2.75f;
static constexpr float kTop = 1.75f;
static constexpr float kBottom = -1.75f;
TextureDepthSourceTests::TextureDepthSourceTests(TestHost &host, std::string output_dir)
: TestSuite(host, std::move(output_dir), "Texture depth source") {
tests_[kD16TestName] = [this]() { TestD16(); };
}
void TextureDepthSourceTests::Initialize() {
TestSuite::Initialize();
CreateGeometry();
host_.SetXDKDefaultViewportAndFixedFunctionMatrices();
// TODO: Provide a mechanism to find the next unused channel.
auto channel = kNextContextChannel;
pb_create_dma_ctx(channel++, DMA_CLASS_3D, 0, MAXRAM, &texture_target_ctx_);
pb_bind_channel(&texture_target_ctx_);
host_.SetAlphaBlendEnabled(false);
}
void TextureDepthSourceTests::CreateGeometry() {
constexpr int kNumTriangles = 4;
auto buffer = host_.AllocateVertexBuffer(kNumTriangles * 3);
int index = 0;
{
float one[] = {-1.5f, -1.5f, 0.0f};
float two[] = {-2.5f, 0.6f, 0.0f};
float three[] = {-0.5f, 0.6f, 0.0f};
buffer->DefineTriangle(index++, one, two, three);
}
{
float one[] = {0.0f, -1.5f, 5.0f};
float two[] = {-1.0f, 0.75f, 10.0f};
float three[] = {2.0f, 0.75f, 20.0f};
buffer->DefineTriangle(index++, one, two, three);
}
{
float one[] = {5.0f, -2.0f, 30};
float two[] = {3.0f, 2.0f, 40};
float three[] = {12.0f, 2.0f, 70};
buffer->DefineTriangle(index++, one, two, three);
}
{
float one[] = {20.0f, -10.0f, 50};
float two[] = {12.0f, 10.0f, 125};
float three[] = {80.0f, 10.0f, 200};
buffer->DefineTriangle(index++, one, two, three);
}
}
void TextureDepthSourceTests::TestD16() {
host_.SetDepthBufferFormat(NV097_SET_SURFACE_FORMAT_ZETA_Z16);
auto p = pb_begin();
p = pb_push1(p, NV097_SET_CONTEXT_DMA_ZETA, texture_target_ctx_.ChannelID);
p = pb_push1(p, NV097_SET_SURFACE_ZETA_OFFSET, reinterpret_cast<uint32_t>(host_.GetTextureMemory()) & 0x03FFFFFF);
pb_end(p);
host_.PrepareDraw(0xFE112233);
// Render some geometry using texture memory as the zeta buffer.
{
host_.SetTextureStageEnabled(0, false);
host_.SetShaderStageProgram(TestHost::STAGE_NONE);
host_.SetupTextureStages();
host_.SetFinalCombiner0Just(TestHost::SRC_DIFFUSE);
host_.SetFinalCombiner1Just(TestHost::SRC_DIFFUSE, true);
host_.DrawArrays();
}
p = pb_begin();
p = pb_push1(p, NV097_SET_SURFACE_ZETA_OFFSET, 0);
p = pb_push1(p, NV097_SET_CONTEXT_DMA_ZETA, kDefaultDMAZetaChannel);
pb_end(p);
// host_.Clear(0xF0333333);
// // Render a quad with the zeta buffer as the texture.
// host_.SetFinalCombiner0Just(TestHost::SRC_TEX0);
// host_.SetFinalCombiner1Just(TestHost::SRC_ZERO, true, true);
//
// auto& stage = host_.GetTextureStage(0);
// stage.SetFormat(GetTextureFormatInfo(NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_DEPTH_Y16_FIXED));
//// stage.SetFormat(GetTextureFormatInfo(NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_Y16));
//// stage.SetFormat(GetTextureFormatInfo(NV097_SET_TEXTURE_FORMAT_COLOR_LU_IMAGE_A8R8G8B8));
// stage.SetTextureDimensions(1, 1, 1);
// stage.SetImageDimensions(host_.GetFramebufferWidth(), host_.GetFramebufferHeight());
// host_.SetTextureStageEnabled(0, true);
// host_.SetShaderStageProgram(TestHost::STAGE_2D_PROJECTIVE);
// host_.SetupTextureStages();
//
// {
// const float z = 1.5f;
// host_.Begin(TestHost::PRIMITIVE_QUADS);
// host_.SetDiffuse(0xFFFF00FF);
// host_.SetTexCoord0(0.0, 0.0);
// host_.SetVertex(kLeft, kTop, z, 1.0f);
//
// host_.SetTexCoord0(host_.GetFramebufferWidthF(), 0.0);
// host_.SetVertex(kRight, kTop, z, 1.0f);
//
// host_.SetTexCoord0(host_.GetFramebufferWidthF(), host_.GetFramebufferHeightF());
// host_.SetVertex(kRight, kBottom, z, 1.0f);
//
// host_.SetTexCoord0(0.0, host_.GetFramebufferHeightF());
// host_.SetVertex(kLeft, kBottom, z, 1.0f);
// host_.End();
// }
std::string z_name = "Z";
z_name += kD16TestName;
host_.FinishDraw(allow_saving_, output_dir_, kD16TestName, z_name);
}

View File

@ -0,0 +1,27 @@
#ifndef NXDK_PGRAPH_TESTS_TEXTURE_DEPTH_SOURCE_TESTS_H
#define NXDK_PGRAPH_TESTS_TEXTURE_DEPTH_SOURCE_TESTS_H
#include <memory>
#include <string>
#include "test_host.h"
#include "test_suite.h"
struct TextureFormatInfo;
class VertexBuffer;
class TextureDepthSourceTests : public TestSuite {
public:
TextureDepthSourceTests(TestHost &host, std::string output_dir);
void Initialize() override;
private:
void CreateGeometry();
void TestD16();
private:
struct s_CtxDma texture_target_ctx_ {};
};
#endif // NXDK_PGRAPH_TESTS_TEXTURE_DEPTH_SOURCE_TESTS_H