Fix Stream API issues

This commit is contained in:
Luke Street 2022-03-14 01:47:25 -04:00
parent 40a3d361dc
commit 69d0ad1fd9
5 changed files with 16 additions and 11 deletions

View File

@ -28,7 +28,7 @@ struct STexState {
struct SGXState { struct SGXState {
std::array<void*, 12> x0_arrayPtrs{}; std::array<void*, 12> x0_arrayPtrs{};
std::array<u16, 2> x30_prevChanCtrls{}; std::array<u16, 2> x30_prevChanCtrls{};
std::array<u16, 2> x34_chanCtrls{}; std::array<u16, 2> x34_chanCtrls{0x4000, 0x4000};
std::array<GXColor, 2> x38_chanAmbColors; std::array<GXColor, 2> x38_chanAmbColors;
std::array<GXColor, 2> x40_chanMatColors; std::array<GXColor, 2> x40_chanMatColors;
GX::VtxDescList* x48_descList = nullptr; GX::VtxDescList* x48_descList = nullptr;
@ -150,6 +150,9 @@ static inline void SetChanAmbColor(EChannelId id, const GXColor& color) noexcept
static inline void SetChanCtrl(EChannelId id, GXBool enable, GX::ColorSrc ambSrc, GX::ColorSrc matSrc, static inline void SetChanCtrl(EChannelId id, GXBool enable, GX::ColorSrc ambSrc, GX::ColorSrc matSrc,
GX::LightMask lights, GX::DiffuseFn diffFn, GX::AttnFn attnFn) noexcept { GX::LightMask lights, GX::DiffuseFn diffFn, GX::AttnFn attnFn) noexcept {
const auto idx = std::underlying_type_t<EChannelId>(id); const auto idx = std::underlying_type_t<EChannelId>(id);
if (lights.none()) {
enable = false;
}
const u32 flags = (attnFn & 3) << 13 | (diffFn & 3) << 11 | (lights.to_ulong() & 0xFF) << 3 | (matSrc & 1) << 2 | const u32 flags = (attnFn & 3) << 13 | (diffFn & 3) << 11 | (lights.to_ulong() & 0xFF) << 3 | (matSrc & 1) << 2 |
(ambSrc & 1) << 1 | (u8(enable) & 1); (ambSrc & 1) << 1 | (u8(enable) & 1);
sGXState.x34_chanCtrls[idx] = flags; sGXState.x34_chanCtrls[idx] = flags;

View File

@ -589,22 +589,22 @@ void CGraphics::DrawPrimitive(GX::Primitive primitive, const zeus::CVector3f* po
void CGraphics::SetTevStates(EStreamFlags flags) noexcept { void CGraphics::SetTevStates(EStreamFlags flags) noexcept {
if (flags & EStreamFlagBits::fHasTexture) { if (flags & EStreamFlagBits::fHasTexture) {
CGX::SetNumChans(1);
CGX::SetNumTexGens(0); CGX::SetNumTexGens(0);
CGX::SetNumTevStages(1); CGX::SetNumTevStages(1);
CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD0, GX::TEXMAP0, GX::COLOR0A0); CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD0, GX::TEXMAP0, GX::COLOR0A0);
CGX::SetTevOrder(GX::TEVSTAGE1, GX::TEXCOORD1, GX::TEXMAP1, GX::COLOR0A0); CGX::SetTevOrder(GX::TEVSTAGE1, GX::TEXCOORD1, GX::TEXMAP1, GX::COLOR0A0);
} else /* if (flags < 8) ? */ { } else /* if (flags < 8) ? */ {
CGX::SetNumChans(1);
CGX::SetNumTexGens(2); // sTextureUsed & 3? CGX::SetNumTexGens(2); // sTextureUsed & 3?
CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD_NULL, GX::TEXMAP_NULL, GX::COLOR0A0); CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD_NULL, GX::TEXMAP_NULL, GX::COLOR0A0);
CGX::SetTevOrder(GX::TEVSTAGE1, GX::TEXCOORD_NULL, GX::TEXMAP_NULL, GX::COLOR0A0); CGX::SetTevOrder(GX::TEVSTAGE1, GX::TEXCOORD_NULL, GX::TEXMAP_NULL, GX::COLOR0A0);
} }
CGX::SetNumChans(1);
CGX::SetNumIndStages(0); CGX::SetNumIndStages(0);
// TODO load TCGs // TODO load TCGs
const bool hasLights = g_LightActive.any(); const bool hasLights = g_LightActive.any();
CGX::SetChanCtrl(CGX::EChannelId::Channel0, hasLights, GX::SRC_REG, CGX::SetChanCtrl(CGX::EChannelId::Channel0, hasLights, GX::SRC_REG,
flags & EStreamFlagBits::fHasColor ? GX::SRC_VTX : GX::SRC_REG, g_LightActive, flags & EStreamFlagBits::fHasColor ? GX::SRC_VTX : GX::SRC_REG, g_LightActive,
hasLights ? GX::DF_CLAMP : GX::DF_NONE, hasLights ? GX::AF_SPOT : GX::AF_NONE); hasLights ? GX::DF_CLAMP : GX::DF_NONE, hasLights ? GX::AF_SPOT : GX::AF_NONE);
CGX::FlushState(); // normally would be handled in FullRender TODO
} }
} // namespace metaforce } // namespace metaforce

View File

@ -146,7 +146,6 @@ void update_projection(const zeus::CMatrix4f& proj) noexcept;
void update_fog_state(const metaforce::CFogState& state) noexcept; void update_fog_state(const metaforce::CFogState& state) noexcept;
void load_light(GX::LightID id, const Light& light) noexcept; void load_light(GX::LightID id, const Light& light) noexcept;
void load_light_ambient(GX::LightID id, const zeus::CColor& ambient) noexcept; void load_light_ambient(GX::LightID id, const zeus::CColor& ambient) noexcept;
void set_light_state(GX::LightMask bits) noexcept;
void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept; void set_viewport(const zeus::CRectangle& rect, float znear, float zfar) noexcept;
void set_scissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h) noexcept; void set_scissor(uint32_t x, uint32_t y, uint32_t w, uint32_t h) noexcept;

View File

@ -332,10 +332,12 @@ wgpu::RenderPipeline build_pipeline(const PipelineConfig& config, const ShaderIn
ShaderInfo populate_pipeline_config(PipelineConfig& config, GX::Primitive primitive, ShaderInfo populate_pipeline_config(PipelineConfig& config, GX::Primitive primitive,
const BindGroupRanges& ranges) noexcept { const BindGroupRanges& ranges) noexcept {
for (size_t i = 0; i < g_gxState.numTevStages; ++i) { for (u8 i = 0; i < g_gxState.numTevStages; ++i) {
config.shaderConfig.tevStages[i] = g_gxState.tevStages[i]; config.shaderConfig.tevStages[i] = g_gxState.tevStages[i];
} }
config.shaderConfig.colorChannels = g_gxState.colorChannelConfig; for (u8 i = 0; i < g_gxState.numChans; ++i) {
config.shaderConfig.colorChannels[i] = g_gxState.colorChannelConfig[i];
}
config.shaderConfig.alphaDiscard = g_gxState.alphaDiscard; config.shaderConfig.alphaDiscard = g_gxState.alphaDiscard;
config = { config = {
.shaderConfig = config.shaderConfig, .shaderConfig = config.shaderConfig,

View File

@ -527,6 +527,11 @@ var<storage, read> v_packed_uvs: Vec2Block;
uniBufAttrs += fmt::format(FMT_STRING("\n cc{0}_mat: vec4<f32>;"), i); uniBufAttrs += fmt::format(FMT_STRING("\n cc{0}_mat: vec4<f32>;"), i);
info.uniformSize += 32; info.uniformSize += 32;
if (config.denormalizedVertexAttributes && !info.usesVtxColor) {
vtxInAttrs += fmt::format(FMT_STRING("\n , @location({}) in_clr: vec4<f32>"), ++locIdx);
info.usesVtxColor = true;
}
if (config.colorChannels[i].lightingEnabled) { if (config.colorChannels[i].lightingEnabled) {
if (!addedLightStruct) { if (!addedLightStruct) {
uniformPre += uniformPre +=
@ -570,16 +575,12 @@ var<storage, read> v_packed_uvs: Vec2Block;
fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = in.cc{0};"), i); fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = in.cc{0};"), i);
} else if (config.colorChannels[i].matSrc == GX::SRC_VTX) { } else if (config.colorChannels[i].matSrc == GX::SRC_VTX) {
if (config.denormalizedVertexAttributes) { if (config.denormalizedVertexAttributes) {
if (!info.usesVtxColor) { vtxOutAttrs += fmt::format(FMT_STRING("\n @location({}) cc{}: vec4<f32>;"), locIdx - 1, i);
vtxInAttrs += fmt::format(FMT_STRING("\n , @location({}) in_clr: vec4<f32>"), locIdx);
}
vtxOutAttrs += fmt::format(FMT_STRING("\n @location({}) cc{}: vec4<f32>;"), locIdx++, i);
vtxXfrAttrs += fmt::format(FMT_STRING("\n out.cc{} = in_clr;"), i); vtxXfrAttrs += fmt::format(FMT_STRING("\n out.cc{} = in_clr;"), i);
fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = in.cc{0};"), i); fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = in.cc{0};"), i);
} else { } else {
Log.report(logvisor::Fatal, FMT_STRING("SRC_VTX unsupported with normalized vertex attributes")); Log.report(logvisor::Fatal, FMT_STRING("SRC_VTX unsupported with normalized vertex attributes"));
} }
info.usesVtxColor = true;
} else { } else {
fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = ubuf.cc{0}_mat;"), i); fragmentFnPre += fmt::format(FMT_STRING("\n var rast{0} = ubuf.cc{0}_mat;"), i);
} }