gpu : added vsh support to makefile + some code. need to setup AEMSTROPATH variable for it to work.

This commit is contained in:
smea 2014-03-11 16:17:05 +01:00
parent 0761e6db1e
commit dacda01d3f
3 changed files with 89 additions and 5 deletions

View File

@ -1,29 +1,50 @@
CC = arm-none-eabi-gcc CC = arm-none-eabi-gcc
LINK = arm-none-eabi-ld LINK = arm-none-eabi-gcc
AS = arm-none-eabi-as
OBJCOPY = arm-none-eabi-objcopy OBJCOPY = arm-none-eabi-objcopy
CTRULIB = "../libctru" CTRULIB = "../libctru"
AEMSTROPATH = "../../aemstro"
CFLAGS += -Wall -std=c99 -march=armv6 -O3 -I"$(CTRULIB)/include" -I$(DEVKITPRO)/libnds/include CFLAGS += -Wall -std=c99 -march=armv6 -O3 -I"$(CTRULIB)/include" -I$(DEVKITPRO)/libnds/include
LDFLAGS += --script=ccd00.ld -L"$(DEVKITARM)/arm-none-eabi/lib" -L"$(CTRULIB)/lib" # LDFLAGS += --script=ccd00.ld -L"$(DEVKITARM)/arm-none-eabi/lib" -L"$(DEVKITARM)/lib/gcc/arm-none-eabi/4.7.1" -L"$(CTRULIB)/lib"
# LDFLAGS += --script=ccd00.ld -L"$(DEVKITARM)/arm-none-eabi/lib" -L"$(CTRULIB)/lib"
LDFLAGS += -nostartfiles --specs=ccd00.specs -L"$(DEVKITARM)/arm-none-eabi/lib" -L"$(CTRULIB)/lib"
CFILES = $(wildcard source/*.c) CFILES = $(wildcard source/*.c)
OFILES = $(CFILES:source/%.c=build/%.o) VSHFILES = $(wildcard source/*.vsh)
VSHBINFILES = $(VSHFILES:source/%.vsh=data/%.vsh.bin)
BINFILES = $(wildcard data/*.bin)
BINFILES += $(VSHBINFILES)
OFILES = $(BINFILES:data/%.bin=build/%.bin.o)
OFILES += $(CFILES:source/%.c=build/%.o)
DFILES = $(CFILES:source/%.c=build/%.d) DFILES = $(CFILES:source/%.c=build/%.d)
SFILES = $(wildcard source/*.s) SFILES = $(wildcard source/*.s)
OFILES += $(SFILES:source/%.s=build/%.o) OFILES += $(SFILES:source/%.s=build/%.o)
PROJECTNAME = ${shell basename "$(CURDIR)"} PROJECTNAME = ${shell basename "$(CURDIR)"}
#---------------------------------------------------------------------------------
# canned command sequence for binary data, taken from devkitARM
#---------------------------------------------------------------------------------
define bin2o
bin2s $< | $(AS) -o $(@)
echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > source/`(echo $(<F) | tr . _)`.h
echo "extern const u8" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> source/`(echo $(<F) | tr . _)`.h
echo "extern const u32" `(echo $(<F) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> source/`(echo $(<F) | tr . _)`.h
endef
.PHONY:=all dir .PHONY:=all dir
all: dir $(PROJECTNAME).bin all: dir $(PROJECTNAME).bin
dir: dir:
@mkdir -p build @mkdir -p build
@mkdir -p data
$(PROJECTNAME).bin: $(PROJECTNAME).elf $(PROJECTNAME).bin: $(PROJECTNAME).elf
$(OBJCOPY) -O binary $< $@ $(OBJCOPY) -O binary $< $@
$(PROJECTNAME).elf: $(OFILES) $(PROJECTNAME).elf: $(VSHBINFILES) $(OFILES)
$(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(filter-out build/crt0.o, $(OFILES)) -lctru -lc # $(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(filter-out build/crt0.o, $(OFILES)) -lctru -lc -lgcc
$(LINK) $(LDFLAGS) -o $(PROJECTNAME).elf $(filter-out build/crt0.o, $(OFILES)) -g -lctru -lm -lc -lg
clean: clean:
@rm -f build/*.o build/*.d @rm -f build/*.o build/*.d
@ -32,6 +53,9 @@ clean:
-include $(DFILES) -include $(DFILES)
data/%.vsh.bin: source/%.vsh
@python $(AEMSTROPATH)/aemstro_as.py $< $@
build/%.o: source/%.c build/%.o: source/%.c
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
@$(CC) -MM $< > build/$*.d @$(CC) -MM $< > build/$*.d
@ -39,3 +63,7 @@ build/%.o: source/%.c
build/%.o: source/%.s build/%.o: source/%.s
$(CC) $(CFLAGS) -c $< -o $@ $(CC) $(CFLAGS) -c $< -o $@
@$(CC) -MM $< > build/$*.d @$(CC) -MM $< > build/$*.d
build/%.bin.o: data/%.bin
@echo $(notdir $<)
@$(bin2o)

View File

@ -8,13 +8,17 @@
#include <ctr/GX.h> #include <ctr/GX.h>
#include <ctr/GPU.h> #include <ctr/GPU.h>
#include <ctr/HID.h> #include <ctr/HID.h>
#include <ctr/SHDR.h>
#include <ctr/svc.h> #include <ctr/svc.h>
#include "costable.h" #include "costable.h"
#include "test_vsh_bin.h"
u8* gspHeap; u8* gspHeap;
u32* gxCmdBuf; u32* gxCmdBuf;
u8 currentBuffer; u8 currentBuffer;
u8* topLeftFramebuffers[2];
u8* topLeftFramebuffersPA[2];
Handle gspEvent, gspSharedMemHandle; Handle gspEvent, gspSharedMemHandle;
@ -29,6 +33,13 @@ void gspGpuInit()
u32 regData=0x01FF0000; u32 regData=0x01FF0000;
GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4); GSPGPU_WriteHWRegs(NULL, 0x202A04, &regData, 4);
//grab main left screen framebuffer addresses
GSPGPU_ReadHWRegs(NULL, 0x400468, (u32*)&topLeftFramebuffersPA, 8);
//convert PA to VA (assuming FB in VRAM)
topLeftFramebuffers[0]=topLeftFramebuffersPA[0]+0x7000000;
topLeftFramebuffers[1]=topLeftFramebuffersPA[1]+0x7000000;
//setup our gsp shared mem section //setup our gsp shared mem section
u8 threadID; u8 threadID;
svc_createEvent(&gspEvent, 0x0); svc_createEvent(&gspEvent, 0x0);
@ -88,6 +99,8 @@ int main()
u32* gpuCmd=(u32*)gspHeap; u32* gpuCmd=(u32*)gspHeap;
u32 gpuCmdSize=0x10000; u32 gpuCmdSize=0x10000;
DVLB_s* shader=SHDR_ParseSHBIN((u32*)test_vsh_bin,test_vsh_bin_size);
APP_STATUS status; APP_STATUS status;
while((status=aptGetStatus())!=APP_EXITING) while((status=aptGetStatus())!=APP_EXITING)
{ {

43
gpu/source/test.vsh Normal file
View File

@ -0,0 +1,43 @@
; setup constants
.const 5, 0.0, 1.0, 2.0, 3.0
; setup outmap
.out o0, result.position
.out o1, result.color
.out o2, result.texcoord0
.out o3, result.texcoord1
.out o4, result.texcoord2
; setup uniform map (not required)
.uniform 0x10, 0x13, mdlvMtx
.uniform 0x14, 0x17, projMtx
;code
main:
; result.pos = mdlvMtx * in.pos
dp4 d40, d40, d00 (0x0)
dp4 d40, d41, d00 (0x1)
dp4 d40, d42, d00 (0x2)
mov d40, d25 (0x4)
; result.pos = projMtx * in.pos
dp4 d00, d44, d40 (0x0)
dp4 d00, d45, d40 (0x1)
dp4 d00, d46, d40 (0x2)
dp4 d00, d47, d40 (0x3)
; result.color = in.pos
mov d04, d25 (0x5)
; result.texcoord = const
mov d08, d25 (0x5)
mov d0C, d25 (0x5)
mov d10, d25 (0x5)
flush
end
endmain:
;operand descriptors
.opdesc x___, xyzw, xyzw ; 0x0
.opdesc _y__, xyzw, xyzw ; 0x1
.opdesc __z_, xyzw, xyzw ; 0x2
.opdesc ___w, xyzw, xyzw ; 0x3
.opdesc ___w, yyyy, xyzw ; 0x4
.opdesc xyzw, xyzw, xyzw ; 0x5