Skip to content

Commit

Permalink
Further work on hull shader phases (issue #32)
Browse files Browse the repository at this point in the history
Previous code was limited to a single join phase and no more than two
fork phases. Support for input and output patch constants is still
incomplete.
  • Loading branch information
James-Jones committed Sep 18, 2014
1 parent fad84e9 commit 8734c8a
Show file tree
Hide file tree
Showing 12 changed files with 3,150 additions and 434 deletions.
308 changes: 104 additions & 204 deletions src/decode.c

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/decodeDX9.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,11 @@ Shader* DecodeDX9BC(const uint32_t* pui32Tokens)
}

psInst = hlslcc_malloc(sizeof(Instruction) * ui32NumInstructions);
psShader->psInst = psInst;
psShader->ui32InstCount = ui32NumInstructions;
psShader->asPhase[MAIN_PHASE].ui32InstanceCount = 1;
psShader->asPhase[MAIN_PHASE].ppsInst = hlslcc_malloc(sizeof(Instruction*));
psShader->asPhase[MAIN_PHASE].ppsInst[0] = psInst;
psShader->asPhase[MAIN_PHASE].pui32InstCount = hlslcc_malloc(sizeof(uint32_t));
psShader->asPhase[MAIN_PHASE].pui32InstCount[0] = ui32NumInstructions;

if(psShader->eShaderType == VERTEX_SHADER)
{
Expand All @@ -691,8 +694,10 @@ Shader* DecodeDX9BC(const uint32_t* pui32Tokens)
ui32NumDeclarations++;

psDecl = hlslcc_malloc(sizeof(Declaration) * ui32NumDeclarations);
psShader->psDecl = psDecl;
psShader->ui32DeclCount = ui32NumDeclarations;
psShader->asPhase[MAIN_PHASE].ppsDecl = hlslcc_malloc(sizeof(Declaration*));
psShader->asPhase[MAIN_PHASE].ppsDecl[0] = psDecl;
psShader->asPhase[MAIN_PHASE].pui32DeclCount = hlslcc_malloc(sizeof(uint32_t));
psShader->asPhase[MAIN_PHASE].pui32DeclCount[0] = ui32NumDeclarations;

pui32CurrentToken = pui32Tokens + 1;

Expand Down
1 change: 0 additions & 1 deletion src/internal_includes/shaderLimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
static enum {MAX_SHADER_VEC4_OUTPUT = 512};
static enum {MAX_SHADER_VEC4_INPUT = 512};
static enum {MAX_TEXTURES = 128};
static enum {MAX_FORK_PHASES = 2};
static enum {MAX_FUNCTION_BODIES = 1024};
static enum {MAX_CLASS_TYPES = 1024};
static enum {MAX_FUNCTION_POINTERS = 128};
Expand Down
56 changes: 20 additions & 36 deletions src/internal_includes/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,25 @@ enum {MAX_GROUPSHARED = 8};

static enum {MAX_DX9_IMMCONST = 256};

static const uint32_t MAIN_PHASE = 0;
static const uint32_t HS_GLOBAL_DECL = 1;
static const uint32_t HS_CTRL_POINT_PHASE = 2;
static const uint32_t HS_FORK_PHASE = 3;
static const uint32_t HS_JOIN_PHASE = 4;
static enum{ NUM_PHASES = 5};

typedef struct ShaderPhase_TAG
{
//How many instances of this phase type are there?
uint32_t ui32InstanceCount;

uint32_t* pui32DeclCount;
Declaration** ppsDecl;

uint32_t* pui32InstCount;
Instruction** ppsInst;
} ShaderPhase;

typedef struct Shader_TAG
{
uint32_t ui32MajorVersion;
Expand All @@ -173,9 +192,6 @@ typedef struct Shader_TAG
//DWORDs in program code, including version and length tokens.
uint32_t ui32ShaderLength;

uint32_t ui32DeclCount;
Declaration* psDecl;

//Instruction* functions;//non-main subroutines

uint32_t aui32FuncTableToFuncPointer[MAX_FUNCTION_TABLES];//FIXME dynamic alloc
Expand All @@ -192,35 +208,9 @@ typedef struct Shader_TAG

uint32_t ui32NextClassFuncName[MAX_CLASS_TYPES];

uint32_t ui32InstCount;
Instruction* psInst;

const uint32_t* pui32FirstToken;//Reference for calculating current position in token stream.

//Hull shader declarations and instructions.
//psDecl, psInst are null for hull shaders.
uint32_t ui32HSDeclCount;
Declaration* psHSDecl;

uint32_t ui32HSControlPointDeclCount;
Declaration* psHSControlPointPhaseDecl;

uint32_t ui32HSControlPointInstrCount;
Instruction* psHSControlPointPhaseInstr;

uint32_t ui32ForkPhaseCount;

uint32_t aui32HSForkDeclCount[MAX_FORK_PHASES];
Declaration* apsHSForkPhaseDecl[MAX_FORK_PHASES];

uint32_t aui32HSForkInstrCount[MAX_FORK_PHASES];
Instruction* apsHSForkPhaseInstr[MAX_FORK_PHASES];

uint32_t ui32HSJoinDeclCount;
Declaration* psHSJoinPhaseDecl;

uint32_t ui32HSJoinInstrCount;
Instruction* psHSJoinPhaseInstr;
ShaderPhase asPhase[NUM_PHASES];

ShaderInfo sInfo;

Expand Down Expand Up @@ -252,12 +242,6 @@ typedef struct Shader_TAG
TextureSamplerInfo textureSamplerInfo;
} Shader;

static const uint32_t MAIN_PHASE = 0;
static const uint32_t HS_FORK_PHASE = 1;
static const uint32_t HS_CTRL_POINT_PHASE = 2;
static const uint32_t HS_JOIN_PHASE = 3;
static enum{ NUM_PHASES = 4};

typedef struct HLSLCrossCompilerContext_TAG
{
bstring glsl;
Expand Down
2 changes: 1 addition & 1 deletion src/reflect.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ int GetOutputSignatureFromRegister(const uint32_t currentPhase,
{
uint32_t i;

if(currentPhase == HS_JOIN_PHASE)
if(currentPhase == HS_JOIN_PHASE || currentPhase == HS_FORK_PHASE)
{
const uint32_t ui32NumVars = psShaderInfo->ui32NumPatchConstantSignatures;

Expand Down
Loading

0 comments on commit 8734c8a

Please sign in to comment.