Skip to content

Instantly share code, notes, and snippets.

@Pokechu22
Last active April 17, 2021 04:33
Show Gist options
  • Save Pokechu22/ed98ef84daab800cc5e3026d2b70fcbf to your computer and use it in GitHub Desktop.
Save Pokechu22/ed98ef84daab800cc5e3026d2b70fcbf to your computer and use it in GitHub Desktop.
build/
indtest.elf
*.dff

Adapted from my normalize test case, in turn adapted from libogc texturetest.

Video of the results on hardware. Also see screenshots: Hardware, OpenGL without UberShaders, OpenGL with UberShaders, software renderer.

Ident_256x256_Greyer_1TG is OK between hardware and OGL. Dolphin is consistently incorrect when the number of tex gens is not right. The first rendered image (Luigi_160x160_Normal_1TG in this case) shows garbage data that changes on each frame (this isn't specific to that one; if I do the identity matrix first then that one has (much less visible) changing garbage data). This only happens the first time 1 tex gen is used; although in this test 2 tex gens are used right after 1 is used, if 1 is used each time then the next image does not have changing garbage data. With 0 tex gens (also not in this test), I got a black screen on console, while I got somewhat random colors for the whole square in Dolphin. Since this causes issues for both the base texture and the indirect texture, I don't think it's worth worrying about.

The previous test failed because GX_SetIndTexMatrix adds 17 to the scale, so the values I was taking from a fifolog were WAY too big (for my attempt at reimplementing Luigi's Mansion's test case, instead of 18, the scale was 35) and that massively overflowed the result. Since the scale factor works for powers of 2, this meant that the offsets were 217 = 131072 times larger than they should have been. There's a comment that the matrix multiply can overflow, but it notes that it doesn't matter since only the lower 24 bits are used. But that's not necessarily safe for textures that aren't powers of 2, since 4 + 16 = 20 ≡ 4 (modulo 16), but for a 12-wide texture, 20 ≡ 8 ≢ 4 (modulo 12). That's what caused weird results for textures that weren't powers of two in Dolphin, but not on console; on console presumably the coordinates wrapped around in a safer manner and the offset always ended up being effectively 0. With this new test case, the results for non-power of 2 textures seem fine, so Dolphin isn't broken there. I don't think large scale factors are an issue for actual games.

I did some dumb hackery to try and display a console at the top of the screen; this was done by manually copying into the XFB. Apparently what I'm doing doesn't work on console, as only a few characters show up (and those that do get cut off vertically). The numbers are TBIMFF, where T is the number of tex gens (1 or 2), B is the base texture (0 = 160 by 160, 1 = 256 by 256), I is the indirect texture (0 = normal, 1 = greyer, 2 = transparent), M is the matrix (1 = luigi's mansion, 0 = identity), and FF is the frame counter (0-59). They iterate in the order of num tex gens, base, indirect, and lastly matrix, with matrix staring at 1 and then changing to 0 later (to better demonstrate the garbage data changing).

#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
.SECONDARY:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif
include $(DEVKITPPC)/wii_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := .
DATA :=
TEXTURES := .
INCLUDES :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -logc -lm
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) \
$(foreach dir,$(TEXTURES),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
SCFFILES := $(foreach dir,$(TEXTURES),$(notdir $(wildcard $(dir)/*.scf)))
TPLFILES := $(SCFFILES:.scf=.tpl)
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) $(addsuffix .o,$(TPLFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(addsuffix .h,$(subst .,_,$(TPLFILES)))
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC)
#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \
-L$(LIBOGC_LIB)
export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)
$(OFILES_SOURCES) : $(HFILES)
#---------------------------------------------------------------------------------
# This rule links in binary data with the .bin extension
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
%.tpl.o %_tpl.h : %.tpl
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
#---------------------------------------------------------------------------------
run:
wiiload $(TARGET).dol
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

This file has been truncated, but you can view the full file.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment