Added gl_PrimitiveID builtin for fragment shaders.

This commit is contained in:
Branimir Karadžić
2015-01-12 19:37:42 -08:00
parent 904f52ab91
commit 8d70a2abde
4 changed files with 31 additions and 3 deletions

View File

@@ -934,14 +934,14 @@ builtin_variable_generator::generate_fs_special_vars()
if (state->AMD_shader_stencil_export_warn)
var->enable_extension_warning("GL_AMD_shader_stencil_export");
}
if (state->EXT_frag_depth_enable) {
ir_variable *const var =
add_output(FRAG_RESULT_DEPTH, float_t, "gl_FragDepthEXT", glsl_precision_high);
if (state->EXT_frag_depth_warn)
var->enable_extension_warning("GL_EXT_frag_depth");
}
if (state->EXT_shader_framebuffer_fetch_enable) {
ir_variable *const var =
add_input(VARYING_SLOT_VAR0, array(vec4_t, state->Const.MaxDrawBuffers), "gl_LastFragData", glsl_precision_medium);
@@ -949,6 +949,12 @@ builtin_variable_generator::generate_fs_special_vars()
var->enable_extension_warning("GL_EXT_shader_framebuffer_fetch");
}
{
ir_variable *var;
var = add_output(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID", glsl_precision_high);
var->data.interpolation = INTERP_QUALIFIER_FLAT;
}
if (state->ARB_sample_shading_enable) {
add_system_value(SYSTEM_VALUE_SAMPLE_ID, int_t, "gl_SampleID", glsl_precision_high);
add_system_value(SYSTEM_VALUE_SAMPLE_POS, vec2_t, "gl_SamplePosition", glsl_precision_high);

View File

@@ -28,7 +28,7 @@ namespace bgfx
typedef void (*EGLPROC)(void);
typedef EGLPROC (EGLAPIENTRY* PFNEGLGETPROCADDRESSPROC)(const char *procname);
typedef EGLPROC (EGLAPIENTRY* PFNEGLGETPROCADDRESSPROC)(const char *procname);
typedef EGLBoolean (EGLAPIENTRY* PFNEGLSWAPINTERVALPROC)(EGLDisplay dpy, EGLint interval);
typedef EGLBoolean (EGLAPIENTRY* PFNEGLMAKECURRENTPROC)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
typedef EGLContext (EGLAPIENTRY* PFNEGLCREATECONTEXTPROC)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list);

View File

@@ -90,6 +90,10 @@ typedef uint64_t GLuint64;
#include "ovr.h"
#include "renderdoc.h"
#ifndef GL_LUMINANCE
# define GL_LUMINANCE 0x1909
#endif // GL_LUMINANCE
#ifndef GL_BGRA
# define GL_BGRA 0x80E1
#endif // GL_BGRA

View File

@@ -1437,6 +1437,8 @@ int main(int _argc, const char* _argv[])
const bool hasFragCoord = NULL != strstr(input, "gl_FragCoord") || hlsl > 3;
const bool hasFragDepth = NULL != strstr(input, "gl_FragDepth");
const bool hasFrontFacing = NULL != strstr(input, "gl_FrontFacing");
const bool hasPrimitiveId = NULL != strstr(input, "gl_PrimitiveID");
bool hasFragData[8] = {};
uint32_t numFragData = 0;
for (uint32_t ii = 0; ii < BX_COUNTOF(hasFragData); ++ii)
@@ -1517,6 +1519,22 @@ int main(int _argc, const char* _argv[])
);
}
if (hasPrimitiveId)
{
if (d3d > 9)
{
preprocessor.writef(
" \\\n\t%suint gl_PrimitiveID : SV_PrimitiveID"
, arg++ > 0 ? ", " : " "
);
}
else
{
fprintf(stderr, "PrimitiveID builtin is not supported by this D3D9 HLSL.\n");
return EXIT_FAILURE;
}
}
preprocessor.writef(
" \\\n\t)\n"
);