Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions include/hlslcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ static const unsigned int HLSLCC_FLAG_VULKAN_SPECIALIZATION_CONSTANTS = 0x200000
// If set, this shader uses the GLSL extension EXT_shader_framebuffer_fetch
static const unsigned int HLSLCC_FLAG_SHADER_FRAMEBUFFER_FETCH = 0x400000;

// If set, UBO members get explicit offset locations to match HLSL offsets.
// Requires ARB_enhanced_layouts
static const unsigned int HLSLCC_FLAG_UBO_MEMBER_OFFSETS = 0x800000;


#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 3 additions & 0 deletions src/toGLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ static void AddVersionDependentCode(HLSLCrossCompilerContext* psContext)
bcatcstr(glsl, "precision highp int;\n");
}

if (psContext->flags & HLSLCC_FLAG_UBO_MEMBER_OFFSETS)
bcatcstr(extensions,"#extension GL_ARB_enhanced_layouts : require\n");

if(psContext->psShader->eShaderType == PIXEL_SHADER && psContext->psShader->eTargetLanguage >= LANG_150)
{
if(psContext->flags & HLSLCC_FLAG_ORIGIN_UPPER_LEFT)
Expand Down
3 changes: 3 additions & 0 deletions src/toGLSLDeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ static void DeclareUBOConstants(HLSLCrossCompilerContext* psContext, const uint3
{
if(skipUnused && !psCBuf->asVars[i].sType.m_IsUsed)
continue;

if (psContext->flags & HLSLCC_FLAG_UBO_MEMBER_OFFSETS)
bformata(glsl, "\tlayout(offset=%d) ", psCBuf->asVars[i].ui32StartOffset);

DeclareConstBufferShaderVariable(psContext,
psCBuf->asVars[i].name.c_str(),
Expand Down