Implement alpha test pipeline state

This commit is contained in:
Billy Laws 2022-10-09 13:49:26 +01:00
parent c86ad638c4
commit 2163f8cde6
5 changed files with 37 additions and 8 deletions

View File

@ -331,6 +331,15 @@ namespace skyline::gpu::interconnect::maxwell3d {
return convertedVaryings;
}
void PackedPipelineState::SetAlphaFunc(engine::CompareFunc func) {
alphaFunc = ConvertCompareFunc(func);
}
Shader::CompareFunction PackedPipelineState::GetAlphaFunc() const {
// Vulkan enum values match 1-1 with hades
return static_cast<Shader::CompareFunction>(alphaFunc);
}
}
#pragma clang diagnostic pop

View File

@ -55,9 +55,12 @@ namespace skyline::gpu::interconnect::maxwell3d {
bool apiMandatedEarlyZ : 1;
bool openGlNdc : 1;
bool transformFeedbackEnable : 1;
u8 alphaFunc : 3; //!< Use {Set,Get}AlphaFunc
bool alphaTestEnable : 1;
};
u32 patchSize;
float alphaRef;
float pointSize;
std::array<engine::VertexAttribute, engine::VertexAttributeCount> vertexAttributes;
std::array<u8, engine::ColorTargetCount> colorRenderTargetFormats; //!< Use {Set, Get}ColorRenderTargetFormat
@ -134,6 +137,10 @@ namespace skyline::gpu::interconnect::maxwell3d {
std::vector<Shader::TransformFeedbackVarying> GetTransformFeedbackVaryings() const;
void SetAlphaFunc(engine::CompareFunc func);
Shader::CompareFunction GetAlphaFunc() const;
bool operator==(const PackedPipelineState &other) const {
// Only hash transform feedback state if it's enabled
if (other.transformFeedbackEnable && transformFeedbackEnable)

View File

@ -129,9 +129,11 @@ namespace skyline::gpu::interconnect::maxwell3d {
info.convert_depth_mode = packedState.openGlNdc;
break;
case Shader::Stage::Fragment:
// info.alpha_test_func = MaxwellToCompareFunction(
// key.state.UnpackComparisonOp(key.state.alpha_test_func.Value()));
// info.alpha_test_reference = Common::BitCast<float>(key.state.alpha_test_ref);
if (packedState.alphaTestEnable) {
info.alpha_test_func = packedState.GetAlphaFunc();
info.alpha_test_reference = packedState.alphaRef;
}
break;
default:
break;

View File

@ -411,7 +411,7 @@ namespace skyline::gpu::interconnect::maxwell3d {
/* Depth Stencil State */
void DepthStencilState::EngineRegisters::DirtyBind(DirtyManager &manager, dirty::Handle handle) const {
manager.Bind(handle, depthTestEnable, depthWriteEnable, depthFunc, depthBoundsTestEnable, stencilTestEnable, twoSidedStencilTestEnable, stencilOps, stencilBack);
manager.Bind(handle, depthTestEnable, depthWriteEnable, depthFunc, depthBoundsTestEnable, stencilTestEnable, twoSidedStencilTestEnable, stencilOps, stencilBack, alphaTestEnable, alphaFunc, alphaRef);
}
DepthStencilState::DepthStencilState(dirty::Handle dirtyHandle, DirtyManager &manager, const EngineRegisters &engine) : engine{manager, dirtyHandle, engine} {}
@ -419,12 +419,20 @@ namespace skyline::gpu::interconnect::maxwell3d {
void DepthStencilState::Flush(PackedPipelineState &packedState) {
packedState.depthTestEnable = engine->depthTestEnable;
packedState.depthWriteEnable = engine->depthWriteEnable;
packedState.SetDepthFunc(engine->depthFunc);
packedState.SetDepthFunc(engine->depthTestEnable ? engine->depthFunc : engine::CompareFunc::OglAlways);
packedState.depthBoundsTestEnable = engine->depthBoundsTestEnable;
packedState.stencilTestEnable = engine->stencilTestEnable;
auto stencilBack{engine->twoSidedStencilTestEnable ? engine->stencilBack : engine->stencilOps};
packedState.SetStencilOps(engine->stencilOps, engine->stencilOps);
packedState.stencilTestEnable = engine->stencilTestEnable;
if (packedState.stencilTestEnable) {
auto stencilBack{engine->twoSidedStencilTestEnable ? engine->stencilBack : engine->stencilOps};
packedState.SetStencilOps(engine->stencilOps, stencilBack);
} else {
packedState.SetStencilOps({ .func = engine::CompareFunc::OglAlways }, { .func = engine::CompareFunc::OglAlways });
}
packedState.alphaTestEnable = engine->alphaTestEnable;
packedState.SetAlphaFunc(engine->alphaTestEnable ? engine->alphaFunc : engine::CompareFunc::OglAlways);
packedState.alphaRef = engine->alphaTestEnable ? engine->alphaRef : 0;
};
/* Color Blend State */

View File

@ -214,6 +214,9 @@ namespace skyline::gpu::interconnect::maxwell3d {
const u32 &twoSidedStencilTestEnable;
const engine::StencilOps &stencilOps;
const engine::StencilOps &stencilBack;
const u32 &alphaTestEnable;
const engine::CompareFunc &alphaFunc;
const float &alphaRef;
void DirtyBind(DirtyManager &manager, dirty::Handle handle) const;
};