Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MOVC translation with swizzle #33

Open
wants to merge 51 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b20c523
Fix MOVC translation with swizzle
MrShoor Sep 30, 2014
9f83393
Fix incorrect behavior GLSL compiler for ATI cards:
MrShoor Apr 8, 2015
8160436
Fix incorrect swizzling for ftoi instruction.
MrShoor Apr 8, 2015
d79f744
Fix translation LT instruction:
MrShoor Oct 30, 2015
8ada495
Added a little more flexibility when writing the "layout" qualifiers …
djewsbury Apr 9, 2016
4b7de53
Merge remote-tracking branch 'mrshoor/master'
djewsbury Apr 9, 2016
853f47f
Explicitly specifying matrix dimensions
djewsbury Apr 9, 2016
5cbc6c8
Added support for a few unsigned integer instruction that were missing
djewsbury Apr 13, 2016
eb520e4
Removed a line that write "subroutine void SubroutineType();" into al…
Apr 15, 2016
8420fdd
INEG instruction can now handle format conversions and swizzling prop…
Apr 18, 2016
9345ac3
RESINFO instruction now translates to imageSize when appropriate
Apr 18, 2016
81a07e3
Support for "GL_KHR_vulkan_glsl" extension
Apr 18, 2016
5ffcb6b
Using "TranslateTexCoord" for all variations of "GATHER" instructions
Apr 18, 2016
2408f08
Improved support for output variables from vertex shaders that have o…
Apr 18, 2016
3182d86
Fix for RESINFO instruction when using complex swizzle patterns on th…
Apr 18, 2016
017bf7f
Shader inputs are now correctly sized for the used components
Apr 18, 2016
cb719bd
typecast of gl_FrontFacing should match with type of destination Input
MrShoor Apr 22, 2016
fc0c9e6
New callback to allow the client to construct the rules for selecting…
Apr 25, 2016
fdf1201
Added support for separated texture and sampler objects (as defined b…
Apr 27, 2016
92f4e70
UAV objects can now have binding and set information
Apr 27, 2016
6ced4a1
Passing ResourceBinding information through to the "evaluate binding"…
Apr 27, 2016
cd2c8af
Fix for using textureSize() with separated textures and samplers
Apr 28, 2016
fdf08ed
Changed the naming conventions for RWStructuredBuffers to match Struc…
Apr 28, 2016
ea29040
More robust handling of swizzling for FTOI, FTOU, ITOF, UTOF and RESI…
May 2, 2016
816499d
Another fix to FTOU/UTOF swizzling
May 2, 2016
94b5bd6
Fix for binding information for StructuredBuffer types
May 2, 2016
9a74ca3
Better logic for selecting method for "vec1", "uvec1", etc
May 3, 2016
8a8bf5c
Fix for single intructions that load from multiple cbuffer variables
May 3, 2016
8444828
Support for shadow samplers when using separated samplers and textures
May 3, 2016
3f8370c
Fixes for geometry shader input variables
May 3, 2016
ca20f37
Minor change to the cmake config to make it easier to generate separa…
May 17, 2016
ce15153
Fix for linking error when calling WriteUniformLayout()
May 17, 2016
1ec4781
Using an "instance" name for all cbuffers when GL_KHR_vulkan_glsl is …
May 19, 2016
a8e1cea
Merge branch 'master' of https://github.com/djewsbury/HLSLCrossCompiler
MrShoor Aug 24, 2016
a4e0c8e
Merge branch 'master' of https://github.com/James-Jones/HLSLCrossComp…
MrShoor Aug 24, 2016
bd1096e
Domain shader input arrays now sized using gl_MaxPatchVertices (like …
MrShoor Aug 24, 2016
a601b5d
OPERAND_TYPE_INPUT_FORK_INSTANCE_ID should be presented as SVT_INT da…
MrShoor Aug 25, 2016
73e624d
fixes for no control point phase case
MrShoor Aug 26, 2016
6c9c801
barrier should be placed between control point stage and fork stage
MrShoor Aug 26, 2016
e64ed95
fixes fixes fixes for Hull Shader. Looks like working now.
MrShoor Aug 26, 2016
5522379
flag HLSLCC_FLAG_DISABLE_VULKAN_DUMMIES added
MrShoor Sep 29, 2016
0751d57
fix swizling case for vec1 inputs:
Dec 6, 2016
509c9b8
fix link error due optimization
Dec 6, 2016
bf33242
fix compilation error in Visual Studio
Jan 22, 2017
0e7c7bf
Merge commit 'bf332426c471bbf1809738cee25c2832ae3faca9'
May 31, 2018
c23bf2d
fix: scalar type cannot be swizzled in GLSL
MrShoor May 31, 2018
78c8d63
input declaration mapping fixed
MrShoor Jun 2, 2018
d70f910
fix swizzling at scalar types
MrShoor Jun 4, 2018
22a61ce
fix swizzling for scalar values
MrShoor Jul 27, 2018
2f57479
structs can't be used as input semantics
MrShoor Aug 30, 2018
0276f42
* structs can't be used as input semantics
MrShoor Sep 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions include/hlslcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct {
uint32_t ARB_explicit_attrib_location : 1;
uint32_t ARB_explicit_uniform_location : 1;
uint32_t ARB_shading_language_420pack : 1;
uint32_t GL_KHR_vulkan_glsl : 1;
}GlExtensions;

enum {MAX_SHADER_VEC4_OUTPUT = 512};
Expand Down Expand Up @@ -159,6 +160,11 @@ typedef enum REFLECT_RESOURCE_DIMENSION
REFLECT_RESOURCE_DIMENSION_BUFFEREX = 11,
} REFLECT_RESOURCE_DIMENSION;

typedef enum REFLECT_RESOURCE_FLAGS
{
REFLECT_RESOURCE_FLAGS_COMPARISON_SAMPLER = 0x2,
} REFLECT_RESOURCE_FLAGS;

typedef struct ResourceBinding_TAG
{
char Name[MAX_REFLECT_STRING_LENGTH];
Expand Down Expand Up @@ -324,6 +330,25 @@ typedef struct TextureSamplerInfo_TAG
TextureSamplerPair aTextureSamplerPair[MAX_RESOURCE_BINDINGS];
} TextureSamplerInfo;

typedef enum GLSL_BINDING_FLAGS
{
GLSL_BINDING_TYPE_PUSHCONSTANTS = 1<<0,
} GLSL_BINDING_FLAGS;

typedef struct GLSLResourceBinding_TAG {
uint32_t _locationIndex;
uint32_t _bindingIndex;
uint32_t _setIndex;
uint32_t _flags; // GLSL_BINDING_FLAGS
} GLSLResourceBinding;

typedef uint32_t (*EvaluateBindingFn)(
void* userData,
GLSLResourceBinding* dstBinding,
ResourceBinding* srcResBinding,
ConstantBuffer* srcCBBinding,
uint32_t bindPoint, uint32_t shaderStage);

typedef struct ShaderInfo_TAG
{
uint32_t ui32MajorVersion;
Expand Down Expand Up @@ -446,6 +471,9 @@ static const unsigned int HLSLCC_FLAG_DISABLE_EXPLICIT_LOCATIONS = 0x400;
//If set, global uniforms are not stored in a struct.
static const unsigned int HLSLCC_FLAG_DISABLE_GLOBALS_STRUCT = 0x800;

//If set, no dummy materials will generated for Vulkan
static const unsigned int HLSLCC_FLAG_DISABLE_VULKAN_DUMMIES = 0x1000;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -460,14 +488,17 @@ HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromFile(const char* filename,
GLLang language,
const GlExtensions *extensions,
GLSLCrossDependencyData* dependencies,
GLSLShader* result
);
EvaluateBindingFn evaluateBindingFn,
void* evaluateBindingData,
GLSLShader* result);

HLSLCC_API int HLSLCC_APIENTRY TranslateHLSLFromMem(const char* shader,
unsigned int flags,
GLLang language,
const GlExtensions *extensions,
GLSLCrossDependencyData* dependencies,
EvaluateBindingFn evaluateBindingFn,
void* evaluateBindingData,
GLSLShader* result);

HLSLCC_API void HLSLCC_APIENTRY FreeGLSLShader(GLSLShader*);
Expand Down
11 changes: 9 additions & 2 deletions mk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ IF( BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DHLSLCC_DYNLIB)
ENDIF( BUILD_SHARED_LIBS )

SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin" )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "../lib" )
OPTION(TARGET_32BIT "Target 32 bit architexture" OFF)

IF(TARGET_32BIT)
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin32" )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "../lib32" )
ELSE()
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin64" )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "../lib64" )
ENDIF()

#INCLUDE(TestBigEndian)

Expand Down
9 changes: 7 additions & 2 deletions offline/toGLSLStandalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "timer.h"

#if defined(_WIN32)
#define VALIDATE_OUTPUT
//#define VALIDATE_OUTPUT
#endif

#if defined(VALIDATE_OUTPUT)
Expand Down Expand Up @@ -605,7 +605,8 @@ int Run(const char* srcPath, const char* destPath, GLLang language, int flags, c
ext.ARB_explicit_attrib_location = 0;
ext.ARB_explicit_uniform_location = 0;
ext.ARB_shading_language_420pack = 0;
compiledOK = TranslateHLSLFromFile(srcPath, flags, language, &ext , dependencies, &result);
ext.GL_KHR_vulkan_glsl = 0;
compiledOK = TranslateHLSLFromFile(srcPath, flags, language, &ext , dependencies, NULL, NULL, &result);
crossCompileTime = ReadTimer(&timer);

if(compiledOK)
Expand Down Expand Up @@ -639,6 +640,10 @@ int Run(const char* srcPath, const char* destPath, GLLang language, int flags, c

FreeGLSLShader(&result);
}
else
{
printf("HLSLcc failed\n");
}

return compiledOK;
}
Expand Down
38 changes: 25 additions & 13 deletions src/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
#include "internal_includes/toGLSLOperand.h"

#define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24 ))
static enum {FOURCC_DXBC = FOURCC('D', 'X', 'B', 'C')}; //DirectX byte code
static enum {FOURCC_SHDR = FOURCC('S', 'H', 'D', 'R')}; //Shader model 4 code
static enum {FOURCC_SHEX = FOURCC('S', 'H', 'E', 'X')}; //Shader model 5 code
static enum {FOURCC_RDEF = FOURCC('R', 'D', 'E', 'F')}; //Resource definition (e.g. constant buffers)
static enum {FOURCC_ISGN = FOURCC('I', 'S', 'G', 'N')}; //Input signature
static enum {FOURCC_IFCE = FOURCC('I', 'F', 'C', 'E')}; //Interface (for dynamic linking)
static enum {FOURCC_OSGN = FOURCC('O', 'S', 'G', 'N')}; //Output signature
static enum {FOURCC_PSGN = FOURCC('P', 'C', 'S', 'G')}; //Patch-constant signature

static enum {FOURCC_ISG1 = FOURCC('I', 'S', 'G', '1')}; //Input signature with Stream and MinPrecision
static enum {FOURCC_OSG1 = FOURCC('O', 'S', 'G', '1')}; //Output signature with Stream and MinPrecision
static enum {FOURCC_OSG5 = FOURCC('O', 'S', 'G', '5')}; //Output signature with Stream
enum {FOURCC_DXBC = FOURCC('D', 'X', 'B', 'C')}; //DirectX byte code
enum {FOURCC_SHDR = FOURCC('S', 'H', 'D', 'R')}; //Shader model 4 code
enum {FOURCC_SHEX = FOURCC('S', 'H', 'E', 'X')}; //Shader model 5 code
enum {FOURCC_RDEF = FOURCC('R', 'D', 'E', 'F')}; //Resource definition (e.g. constant buffers)
enum {FOURCC_ISGN = FOURCC('I', 'S', 'G', 'N')}; //Input signature
enum {FOURCC_IFCE = FOURCC('I', 'F', 'C', 'E')}; //Interface (for dynamic linking)
enum {FOURCC_OSGN = FOURCC('O', 'S', 'G', 'N')}; //Output signature
enum {FOURCC_PSGN = FOURCC('P', 'C', 'S', 'G')}; //Patch-constant signature

enum {FOURCC_ISG1 = FOURCC('I', 'S', 'G', '1')}; //Input signature with Stream and MinPrecision
enum {FOURCC_OSG1 = FOURCC('O', 'S', 'G', '1')}; //Output signature with Stream and MinPrecision
enum {FOURCC_OSG5 = FOURCC('O', 'S', 'G', '5')}; //Output signature with Stream

typedef struct DXBCContainerHeaderTAG
{
Expand Down Expand Up @@ -269,6 +269,12 @@ uint32_t DecodeOperand (const uint32_t *pui32Tokens, Operand* psOperand)
psOperand->aeDataType[0] = SVT_UINT;
}

if (psOperand->eType == OPERAND_TYPE_INPUT_FORK_INSTANCE_ID)
{
eNumComponents = OPERAND_1_COMPONENT;
psOperand->aeDataType[0] = SVT_INT;
}

switch(eNumComponents)
{
case OPERAND_1_COMPONENT:
Expand Down Expand Up @@ -444,6 +450,8 @@ const uint32_t* DecodeDeclaration(Shader* psShader, const uint32_t* pui32Token,
}
case OPCODE_DCL_SAMPLER:
{
psDecl->ui32NumOperands = 1;
DecodeOperand(pui32Token+ui32OperandOffset, &psDecl->asOperands[0]);
break;
}
case OPCODE_DCL_INDEX_RANGE:
Expand Down Expand Up @@ -1023,8 +1031,10 @@ const uint32_t* DeocdeInstruction(const uint32_t* pui32Token, Instruction* psIns
//Intentional fall-through
}
case OPCODE_IMIN:
case OPCODE_UMIN:
case OPCODE_MIN:
case OPCODE_IMAX:
case OPCODE_UMAX:
case OPCODE_MAX:
case OPCODE_MUL:
case OPCODE_DIV:
Expand Down Expand Up @@ -1078,6 +1088,7 @@ const uint32_t* DeocdeInstruction(const uint32_t* pui32Token, Instruction* psIns
case OPCODE_MAD:
case OPCODE_MOVC:
case OPCODE_IMAD:
case OPCODE_UMAD:
case OPCODE_UDIV:
case OPCODE_LOD:
case OPCODE_SAMPLE:
Expand All @@ -1098,10 +1109,11 @@ const uint32_t* DeocdeInstruction(const uint32_t* pui32Token, Instruction* psIns
case OPCODE_DMOVC:
case OPCODE_DFMA:
case OPCODE_IMUL:
case OPCODE_UMUL:
{
psInst->ui32NumOperands = 4;

if(eOpcode == OPCODE_IMUL)
if(eOpcode == OPCODE_IMUL || eOpcode == OPCODE_UMUL)
{
psInst->ui32FirstSrc = 2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decodeDX9.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "internal_includes/hlslcc_malloc.h"

#define FOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24 ))
static enum {FOURCC_CTAB = FOURCC('C', 'T', 'A', 'B')}; //Constant table
enum {FOURCC_CTAB = FOURCC('C', 'T', 'A', 'B')}; //Constant table

#ifdef _DEBUG
static uint64_t operandID = 0;
Expand Down
48 changes: 48 additions & 0 deletions src/internal_includes/languages.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,25 @@ static int HaveUniformBindingsAndLocations(const GLLang eLang,const struct GlExt
return 0;
}

static int HaveBindingQualifier(const GLLang eLang, const struct GlExtensions *extensions, unsigned int flags)
{
return
(eLang >= LANG_420)
|| (extensions && ((GlExtensions*)extensions)->ARB_shading_language_420pack);
}

static int HaveSeparateTexturesAndSamplers(const GLLang eLang, const struct GlExtensions *extensions)
{
return extensions && ((GlExtensions*)extensions)->GL_KHR_vulkan_glsl;
}

static int HaveScalarSwizzle(const GLLang eLang, const struct GlExtensions *extensions)
{
return
(eLang >= LANG_420)
|| (extensions && ((GlExtensions*)extensions)->ARB_shading_language_420pack);
}

static int DualSourceBlendSupported(const GLLang eLang)
{
if(eLang >= LANG_330)
Expand All @@ -104,6 +123,35 @@ static int SubroutinesSupported(const GLLang eLang)
return 0;
}

static int HasImageSizeFunction(const GLLang eLang)
{
if(eLang >= LANG_430)
{
return 1;
}
return 0;
}

static int HasInterfaceComponentQualifier(const GLLang eLang)
{
// Allows for the use of "component" layout qualifier attached
// to interface components.
if (eLang >= LANG_440)
{
return 1;
}
return 0;
}

static int UseSPIRVNames(const GLLang eLang,const struct GlExtensions *extensions)
{
if(extensions && ((GlExtensions*)extensions)->GL_KHR_vulkan_glsl)
{
return 1;
}
return 0;
}

//Before 430, flat/smooth/centroid/noperspective must match
//between fragment and its previous stage.
//HLSL bytecode only tells us the interpolation in pixel shader.
Expand Down
2 changes: 1 addition & 1 deletion src/internal_includes/reflect.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void GetConstantBufferFromBindingPoint(const ResourceGroup eGroup, const uint32_

int GetInterfaceVarFromOffset(uint32_t ui32Offset, ShaderInfo* psShaderInfo, ShaderVar** ppsShaderVar);

int GetInputSignatureFromRegister(const uint32_t ui32Register, const ShaderInfo* psShaderInfo, InOutSignature** ppsOut);
int GetInputSignatureFromRegister(const uint32_t ui32Register, const int eSelMode, uint32_t ui32CompMask, const ShaderInfo* psShaderInfo, InOutSignature** ppsOut);
int GetOutputSignatureFromRegister(const uint32_t currentPhase,
const uint32_t ui32Register,
const uint32_t ui32Stream,
Expand Down
7 changes: 5 additions & 2 deletions src/internal_includes/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ enum {MAX_TEMP_VEC4 = 512};

enum {MAX_GROUPSHARED = 8};

static enum {MAX_DX9_IMMCONST = 256};
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};
enum{ NUM_PHASES = 5};

typedef struct ShaderPhase_TAG
{
Expand Down Expand Up @@ -222,6 +222,7 @@ typedef struct Shader_TAG
int aIndexedInputParents[MAX_SHADER_VEC4_INPUT];

RESOURCE_DIMENSION aeResourceDims[MAX_TEXTURES];
RESOURCE_DIMENSION aeUAVResourceDims[MAX_TEXTURES];

int aiInputDeclaredSize[MAX_SHADER_VEC4_INPUT];

Expand Down Expand Up @@ -257,6 +258,8 @@ typedef struct HLSLCrossCompilerContext_TAG
unsigned int flags;
Shader* psShader;
GLSLCrossDependencyData* psDependencies;
EvaluateBindingFn pEvaluateBindingFn;
void* pEvaluateBindingData;
} HLSLCrossCompilerContext;

#endif
1 change: 1 addition & 0 deletions src/internal_includes/toGLSLDeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ const char* GetDeclaredOutputName(const HLSLCrossCompilerContext* psContext, con
//Each phase has its own temps.
//Convert to global temps for GLSL.
void ConsolidateHullTempVars(Shader* psShader);
void TranslateDeclaration_HS_NoControlPointStage(HLSLCrossCompilerContext* psContext);

#endif
4 changes: 4 additions & 0 deletions src/internal_includes/toGLSLOperand.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ void TranslateOperandIndexMAD(HLSLCrossCompilerContext* psContext, const Operand
void TranslateOperandSwizzle(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
void TranslateOperandSwizzleWithMask(HLSLCrossCompilerContext* psContext, const Operand* psOperand, uint32_t ui32ComponentMask);

uint32_t GetNumberBitsSet(uint32_t a);
uint32_t GetNumSwizzleElements(const Operand* psOperand);
uint32_t GetNumSwizzleElementsWithMask(const Operand *psOperand, uint32_t ui32CompMask);
uint32_t GetOrderedSwizzleElements(const Operand *psOperand, uint32_t ui32CompMask, uint32_t result[4]);
void AddSwizzleUsingElementCount(HLSLCrossCompilerContext* psContext, uint32_t count);
void AddSwizzleUsingOrderedElements(HLSLCrossCompilerContext* psContext, const Operand *psOperand, uint32_t ui32CompMask);
void AddSwizzleUsingOrderedElementsDstMask(HLSLCrossCompilerContext* psContext, const Operand *psSrcOperand, const Operand *psMaskingOperand);
int GetFirstOperandSwizzle(HLSLCrossCompilerContext* psContext, const Operand* psOperand);
uint32_t IsSwizzleReplicated(const Operand* psOperand);

Expand Down
Loading