diff options
Diffstat (limited to 'mesalib/src/mesa')
28 files changed, 1081 insertions, 36 deletions
diff --git a/mesalib/src/mesa/Makefile.sources b/mesalib/src/mesa/Makefile.sources index ff242b4ab..a84f8a788 100644 --- a/mesalib/src/mesa/Makefile.sources +++ b/mesalib/src/mesa/Makefile.sources @@ -108,6 +108,7 @@ MAIN_FILES = \ $(SRCDIR)main/uniforms.c \ $(SRCDIR)main/uniform_query.cpp \ $(SRCDIR)main/varray.c \ + $(SRCDIR)main/vdpau.c \ $(SRCDIR)main/version.c \ $(SRCDIR)main/viewport.c \ $(SRCDIR)main/vtxfmt.c \ @@ -248,7 +249,8 @@ STATETRACKER_FILES = \ $(SRCDIR)state_tracker/st_manager.c \ $(SRCDIR)state_tracker/st_mesa_to_tgsi.c \ $(SRCDIR)state_tracker/st_program.c \ - $(SRCDIR)state_tracker/st_texture.c + $(SRCDIR)state_tracker/st_texture.c \ + $(SRCDIR)state_tracker/st_vdpau.c PROGRAM_FILES = \ $(SRCDIR)program/arbprogparse.c \ diff --git a/mesalib/src/mesa/SConscript b/mesalib/src/mesa/SConscript index 9b7712faf..42134983c 100644 --- a/mesalib/src/mesa/SConscript +++ b/mesalib/src/mesa/SConscript @@ -140,6 +140,7 @@ main_sources = [ 'main/uniform_query.cpp', 'main/uniforms.c', 'main/varray.c', + 'main/vdpau.c', 'main/version.c', 'main/viewport.c', 'main/vtxfmt.c', @@ -287,6 +288,7 @@ statetracker_sources = [ 'state_tracker/st_mesa_to_tgsi.c', 'state_tracker/st_program.c', 'state_tracker/st_texture.c', + 'state_tracker/st_vdpau.c', ] env.Append(YACCFLAGS = '-d -p "_mesa_program_"') diff --git a/mesalib/src/mesa/drivers/dri/common/Makefile.am b/mesalib/src/mesa/drivers/dri/common/Makefile.am index 9f49ff3ae..7f87ed6f5 100644 --- a/mesalib/src/mesa/drivers/dri/common/Makefile.am +++ b/mesalib/src/mesa/drivers/dri/common/Makefile.am @@ -27,6 +27,7 @@ AM_CFLAGS = \ -I$(top_srcdir)/src/mapi \ -I$(top_srcdir)/src/mesa/ \ $(DEFINES) \ + $(EXPAT_CFLAGS) \ $(VISIBILITY_CFLAGS) noinst_LTLIBRARIES = \ diff --git a/mesalib/src/mesa/main/bufferobj.c b/mesalib/src/mesa/main/bufferobj.c index e5814e397..f8312bbb4 100644 --- a/mesalib/src/mesa/main/bufferobj.c +++ b/mesalib/src/mesa/main/bufferobj.c @@ -102,6 +102,11 @@ get_buffer_target(struct gl_context *ctx, GLenum target) return &ctx->UniformBuffer; } break; + case GL_ATOMIC_COUNTER_BUFFER: + if (ctx->Extensions.ARB_shader_atomic_counters) { + return &ctx->AtomicBuffer; + } + break; default: return NULL; } @@ -2119,6 +2124,51 @@ bind_buffer_base_uniform_buffer(struct gl_context *ctx, set_ubo_binding(ctx, index, bufObj, 0, 0, GL_TRUE); } +static void +set_atomic_buffer_binding(struct gl_context *ctx, + unsigned index, + struct gl_buffer_object *bufObj, + GLintptr offset, + GLsizeiptr size, + const char *name) +{ + struct gl_atomic_buffer_binding *binding; + + if (index >= ctx->Const.MaxAtomicBufferBindings) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%d)", name, index); + return; + } + + if (offset & (ATOMIC_COUNTER_SIZE - 1)) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(offset misalgned %d/%d)", name, (int) offset, + ATOMIC_COUNTER_SIZE); + return; + } + + _mesa_reference_buffer_object(ctx, &ctx->AtomicBuffer, bufObj); + + binding = &ctx->AtomicBufferBindings[index]; + if (binding->BufferObject == bufObj && + binding->Offset == offset && + binding->Size == size) { + return; + } + + FLUSH_VERTICES(ctx, 0); + ctx->NewDriverState |= ctx->DriverFlags.NewAtomicBuffer; + + _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj); + + if (bufObj == ctx->Shared->NullBufferObj) { + binding->Offset = -1; + binding->Size = -1; + } else { + binding->Offset = offset; + binding->Size = size; + } +} + void GLAPIENTRY _mesa_BindBufferRange(GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) @@ -2156,6 +2206,10 @@ _mesa_BindBufferRange(GLenum target, GLuint index, case GL_UNIFORM_BUFFER: bind_buffer_range_uniform_buffer(ctx, index, bufObj, offset, size); return; + case GL_ATOMIC_COUNTER_BUFFER: + set_atomic_buffer_binding(ctx, index, bufObj, offset, size, + "glBindBufferRange"); + return; default: _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferRange(target)"); return; @@ -2215,6 +2269,10 @@ _mesa_BindBufferBase(GLenum target, GLuint index, GLuint buffer) case GL_UNIFORM_BUFFER: bind_buffer_base_uniform_buffer(ctx, index, bufObj); return; + case GL_ATOMIC_COUNTER_BUFFER: + set_atomic_buffer_binding(ctx, index, bufObj, 0, 0, + "glBindBufferBase"); + return; default: _mesa_error(ctx, GL_INVALID_ENUM, "glBindBufferBase(target)"); return; diff --git a/mesalib/src/mesa/main/compiler.h b/mesalib/src/mesa/main/compiler.h index 0f27d5a66..d806d5b9d 100644 --- a/mesalib/src/mesa/main/compiler.h +++ b/mesalib/src/mesa/main/compiler.h @@ -444,7 +444,29 @@ do { \ #define Elements(x) (sizeof(x)/sizeof(*(x))) #endif - +#ifdef __cplusplus +/** + * Macro function that evaluates to true if T is a trivially + * destructible type -- that is, if its (non-virtual) destructor + * performs no action and all member variables and base classes are + * trivially destructible themselves. + */ +# if defined(__GNUC__) +# if ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))) +# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) +# endif +# elif (defined(__clang__) && defined(__has_feature)) +# if __has_feature(has_trivial_destructor) +# define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) +# endif +# endif +# ifndef HAS_TRIVIAL_DESTRUCTOR + /* It's always safe (if inefficient) to assume that a + * destructor is non-trivial. + */ +# define HAS_TRIVIAL_DESTRUCTOR(T) (false) +# endif +#endif #ifdef __cplusplus } diff --git a/mesalib/src/mesa/main/config.h b/mesalib/src/mesa/main/config.h index fcb8952ff..ebf99c24b 100644 --- a/mesalib/src/mesa/main/config.h +++ b/mesalib/src/mesa/main/config.h @@ -174,6 +174,11 @@ #define MAX_UNIFORM_BUFFERS 15 /* + 1 default uniform buffer */ /* 6 is for vertex, hull, domain, geometry, fragment, and compute shader. */ #define MAX_COMBINED_UNIFORM_BUFFERS (MAX_UNIFORM_BUFFERS * 6) +#define MAX_ATOMIC_COUNTERS 4096 +/* 6 is for vertex, hull, domain, geometry, fragment, and compute shader. */ +#define MAX_COMBINED_ATOMIC_BUFFERS (MAX_UNIFORM_BUFFERS * 6) +/* Size of an atomic counter in bytes according to ARB_shader_atomic_counters */ +#define ATOMIC_COUNTER_SIZE 4 /*@}*/ /** diff --git a/mesalib/src/mesa/main/context.c b/mesalib/src/mesa/main/context.c index 0d1f71c71..6cdeed19b 100644 --- a/mesalib/src/mesa/main/context.c +++ b/mesalib/src/mesa/main/context.c @@ -537,6 +537,9 @@ init_program_limits(struct gl_context *ctx, GLenum type, prog->MaxCombinedUniformComponents = (prog->MaxUniformComponents + ctx->Const.MaxUniformBlockSize / 4 * prog->MaxUniformBlocks); + + prog->MaxAtomicBuffers = 0; + prog->MaxAtomicCounters = 0; } @@ -669,6 +672,12 @@ _mesa_init_constants(struct gl_context *ctx) ctx->Const.MaxColorTextureSamples = 1; ctx->Const.MaxDepthTextureSamples = 1; ctx->Const.MaxIntegerSamples = 1; + + /* GL_ARB_shader_atomic_counters */ + ctx->Const.MaxAtomicBufferBindings = MAX_COMBINED_ATOMIC_BUFFERS; + ctx->Const.MaxAtomicBufferSize = MAX_ATOMIC_COUNTERS * ATOMIC_COUNTER_SIZE; + ctx->Const.MaxCombinedAtomicBuffers = MAX_COMBINED_ATOMIC_BUFFERS; + ctx->Const.MaxCombinedAtomicCounters = MAX_ATOMIC_COUNTERS; } diff --git a/mesalib/src/mesa/main/dd.h b/mesalib/src/mesa/main/dd.h index 29469ce33..501192199 100644 --- a/mesalib/src/mesa/main/dd.h +++ b/mesalib/src/mesa/main/dd.h @@ -868,6 +868,20 @@ struct dd_function_table { struct gl_framebuffer *fb, GLuint index, GLfloat *outValue); + + /** + * \name NV_vdpau_interop interface + */ + void (*VDPAUMapSurface)(struct gl_context *ctx, GLenum target, + GLenum access, GLboolean output, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + const GLvoid *vdpSurface, GLuint index); + void (*VDPAUUnmapSurface)(struct gl_context *ctx, GLenum target, + GLenum access, GLboolean output, + struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + const GLvoid *vdpSurface, GLuint index); }; diff --git a/mesalib/src/mesa/main/extensions.c b/mesalib/src/mesa/main/extensions.c index e8e0a20d8..285ec377c 100644 --- a/mesalib/src/mesa/main/extensions.c +++ b/mesalib/src/mesa/main/extensions.c @@ -120,6 +120,7 @@ static const struct extension extension_table[] = { { "GL_ARB_robustness", o(dummy_true), GL, 2010 }, { "GL_ARB_sampler_objects", o(dummy_true), GL, 2009 }, { "GL_ARB_seamless_cube_map", o(ARB_seamless_cube_map), GL, 2009 }, + { "GL_ARB_shader_atomic_counters", o(ARB_shader_atomic_counters), GL, 2011 }, { "GL_ARB_shader_bit_encoding", o(ARB_shader_bit_encoding), GL, 2010 }, { "GL_ARB_shader_objects", o(dummy_true), GL, 2002 }, { "GL_ARB_shader_stencil_export", o(ARB_shader_stencil_export), GL, 2009 }, @@ -335,6 +336,7 @@ static const struct extension extension_table[] = { { "GL_NV_texture_barrier", o(NV_texture_barrier), GL, 2009 }, { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), GLL, 1999 }, { "GL_NV_texture_rectangle", o(NV_texture_rectangle), GLL, 2000 }, + { "GL_NV_vdpau_interop", o(NV_vdpau_interop), GL, 2010 }, { "GL_S3_s3tc", o(ANGLE_texture_compression_dxt), GL, 1999 }, { "GL_SGIS_generate_mipmap", o(dummy_true), GLL, 1997 }, { "GL_SGIS_texture_border_clamp", o(ARB_texture_border_clamp), GLL, 1997 }, diff --git a/mesalib/src/mesa/main/get.c b/mesalib/src/mesa/main/get.c index 89b3bf09d..6e72ff5c2 100644 --- a/mesalib/src/mesa/main/get.c +++ b/mesalib/src/mesa/main/get.c @@ -143,6 +143,7 @@ enum value_extra { EXTRA_FLUSH_CURRENT, EXTRA_GLSL_130, EXTRA_EXT_UBO_GS4, + EXTRA_EXT_ATOMICS_GS4, }; #define NO_EXTRA NULL @@ -331,6 +332,11 @@ static const int extra_MESA_texture_array_es3[] = { EXTRA_END }; +static const int extra_ARB_shader_atomic_counters_and_geometry_shader[] = { + EXTRA_EXT_ATOMICS_GS4, + EXTRA_END +}; + EXTRA_EXT(ARB_texture_cube_map); EXTRA_EXT(MESA_texture_array); EXTRA_EXT(NV_fog_distance); @@ -367,6 +373,7 @@ EXTRA_EXT(ARB_texture_cube_map_array); EXTRA_EXT(ARB_texture_buffer_range); EXTRA_EXT(ARB_texture_multisample); EXTRA_EXT(ARB_texture_gather); +EXTRA_EXT(ARB_shader_atomic_counters); static const int extra_ARB_color_buffer_float_or_glcore[] = { @@ -894,6 +901,10 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu _mesa_problem(ctx, "driver doesn't implement GetTimestamp"); } break; + /* GL_ARB_shader_atomic_counters */ + case GL_ATOMIC_COUNTER_BUFFER_BINDING: + v->value_int = ctx->AtomicBuffer->Name; + break; } } @@ -999,6 +1010,11 @@ check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d api_found = (ctx->Extensions.ARB_uniform_buffer_object && _mesa_has_geometry_shaders(ctx)); break; + case EXTRA_EXT_ATOMICS_GS4: + api_check = GL_TRUE; + api_found = (ctx->Extensions.ARB_shader_atomic_counters && + _mesa_has_geometry_shaders(ctx)); + break; case EXTRA_END: break; default: /* *e is a offset into the extension struct */ @@ -1692,6 +1708,30 @@ find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v) goto invalid_enum; v->value_int = ctx->Multisample.SampleMaskValue; return TYPE_INT; + + case GL_ATOMIC_COUNTER_BUFFER_BINDING: + if (!ctx->Extensions.ARB_shader_atomic_counters) + goto invalid_enum; + if (index >= ctx->Const.MaxAtomicBufferBindings) + goto invalid_value; + v->value_int = ctx->AtomicBufferBindings[index].BufferObject->Name; + return TYPE_INT; + + case GL_ATOMIC_COUNTER_BUFFER_START: + if (!ctx->Extensions.ARB_shader_atomic_counters) + goto invalid_enum; + if (index >= ctx->Const.MaxAtomicBufferBindings) + goto invalid_value; + v->value_int64 = ctx->AtomicBufferBindings[index].Offset; + return TYPE_INT64; + + case GL_ATOMIC_COUNTER_BUFFER_SIZE: + if (!ctx->Extensions.ARB_shader_atomic_counters) + goto invalid_enum; + if (index >= ctx->Const.MaxAtomicBufferBindings) + goto invalid_value; + v->value_int64 = ctx->AtomicBufferBindings[index].Size; + return TYPE_INT64; } invalid_enum: diff --git a/mesalib/src/mesa/main/get_hash_params.py b/mesalib/src/mesa/main/get_hash_params.py index 9c54af094..9f79f3406 100644 --- a/mesalib/src/mesa/main/get_hash_params.py +++ b/mesalib/src/mesa/main/get_hash_params.py @@ -722,6 +722,18 @@ descriptor=[ [ "MAX_PROGRAM_TEXTURE_GATHER_OFFSET", "CONTEXT_INT(Const.MaxProgramTextureGatherOffset), extra_ARB_texture_gather"], [ "MAX_PROGRAM_TEXTURE_GATHER_COMPONENTS_ARB", "CONTEXT_INT(Const.MaxProgramTextureGatherComponents), extra_ARB_texture_gather"], +# GL_ARB_shader_atomic_counters + [ "ATOMIC_COUNTER_BUFFER_BINDING", "LOC_CUSTOM, TYPE_INT, 0, extra_ARB_shader_atomic_counters" ], + [ "MAX_ATOMIC_COUNTER_BUFFER_BINDINGS", "CONTEXT_INT(Const.MaxAtomicBufferBindings), extra_ARB_shader_atomic_counters" ], + [ "MAX_ATOMIC_COUNTER_BUFFER_SIZE", "CONTEXT_INT(Const.MaxAtomicBufferSize), extra_ARB_shader_atomic_counters" ], + [ "MAX_VERTEX_ATOMIC_COUNTER_BUFFERS", "CONTEXT_INT(Const.VertexProgram.MaxAtomicBuffers), extra_ARB_shader_atomic_counters" ], + [ "MAX_VERTEX_ATOMIC_COUNTERS", "CONTEXT_INT(Const.VertexProgram.MaxAtomicCounters), extra_ARB_shader_atomic_counters" ], + [ "MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS", "CONTEXT_INT(Const.FragmentProgram.MaxAtomicBuffers), extra_ARB_shader_atomic_counters" ], + [ "MAX_FRAGMENT_ATOMIC_COUNTERS", "CONTEXT_INT(Const.FragmentProgram.MaxAtomicCounters), extra_ARB_shader_atomic_counters" ], + [ "MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS", "CONTEXT_INT(Const.GeometryProgram.MaxAtomicBuffers), extra_ARB_shader_atomic_counters_and_geometry_shader" ], + [ "MAX_GEOMETRY_ATOMIC_COUNTERS", "CONTEXT_INT(Const.GeometryProgram.MaxAtomicCounters), extra_ARB_shader_atomic_counters_and_geometry_shader" ], + [ "MAX_COMBINED_ATOMIC_COUNTER_BUFFERS", "CONTEXT_INT(Const.MaxCombinedAtomicBuffers), extra_ARB_shader_atomic_counters" ], + [ "MAX_COMBINED_ATOMIC_COUNTERS", "CONTEXT_INT(Const.MaxCombinedAtomicCounters), extra_ARB_shader_atomic_counters" ], ]}, # Enums restricted to OpenGL Core profile diff --git a/mesalib/src/mesa/main/imports.h b/mesalib/src/mesa/main/imports.h index 53e40b445..d79e2a339 100644 --- a/mesalib/src/mesa/main/imports.h +++ b/mesalib/src/mesa/main/imports.h @@ -141,6 +141,7 @@ static inline float acoshf(float x) { return logf(x + sqrtf(x * x - 1.0f)); } static inline float atanhf(float x) { return (logf(1.0f + x) - logf(1.0f - x)) / 2.0f; } static inline int isblank(int ch) { return ch == ' ' || ch == '\t'; } #define strtoll(p, e, b) _strtoi64(p, e, b) +#define strcasecmp(s1, s2) _stricmp(s1, s2) #endif /*@}*/ diff --git a/mesalib/src/mesa/main/mtypes.h b/mesalib/src/mesa/main/mtypes.h index 97ed1bd6a..a1a5eb4bf 100644 --- a/mesalib/src/mesa/main/mtypes.h +++ b/mesalib/src/mesa/main/mtypes.h @@ -2375,6 +2375,25 @@ struct gl_uniform_block enum gl_uniform_block_packing _Packing; }; +/** + * Structure that represents a reference to an atomic buffer from some + * shader program. + */ +struct gl_active_atomic_buffer +{ + /** Uniform indices of the atomic counters declared within it. */ + GLuint *Uniforms; + GLuint NumUniforms; + + /** Binding point index associated with it. */ + GLuint Binding; + + /** Minimum reasonable size it is expected to have. */ + GLuint MinimumSize; + + /** Shader stages making use of it. */ + GLboolean StageReferences[MESA_SHADER_TYPES]; +}; /** * A GLSL program object. @@ -2523,6 +2542,9 @@ struct gl_shader_program */ struct string_to_uint_map *UniformHash; + struct gl_active_atomic_buffer *AtomicBuffers; + unsigned NumAtomicBuffers; + GLboolean LinkStatus; /**< GL_LINK_STATUS */ GLboolean Validated; GLboolean _Used; /**< Ever used for drawing? */ @@ -2960,6 +2982,9 @@ struct gl_program_constants GLuint MaxUniformBlocks; GLuint MaxCombinedUniformComponents; GLuint MaxTextureImageUnits; + /* GL_ARB_shader_atomic_counters */ + GLuint MaxAtomicBuffers; + GLuint MaxAtomicCounters; }; @@ -3166,6 +3191,12 @@ struct gl_constants GLint MaxColorTextureSamples; GLint MaxDepthTextureSamples; GLint MaxIntegerSamples; + + /** GL_ARB_shader_atomic_counters */ + GLuint MaxAtomicBufferBindings; + GLuint MaxAtomicBufferSize; + GLuint MaxCombinedAtomicBuffers; + GLuint MaxCombinedAtomicCounters; }; @@ -3209,6 +3240,7 @@ struct gl_extensions GLboolean ARB_occlusion_query2; GLboolean ARB_point_sprite; GLboolean ARB_seamless_cube_map; + GLboolean ARB_shader_atomic_counters; GLboolean ARB_shader_bit_encoding; GLboolean ARB_shader_stencil_export; GLboolean ARB_shader_texture_lod; @@ -3302,6 +3334,7 @@ struct gl_extensions GLboolean NV_texture_barrier; GLboolean NV_texture_env_combine4; GLboolean NV_texture_rectangle; + GLboolean NV_vdpau_interop; GLboolean TDFX_texture_compression_FXT1; GLboolean OES_EGL_image; GLboolean OES_draw_texture; @@ -3581,6 +3614,11 @@ struct gl_driver_flags * gl_shader_program::UniformBlocks */ GLbitfield NewUniformBuffer; + + /** + * gl_context::AtomicBufferBindings + */ + GLbitfield NewAtomicBuffer; }; struct gl_uniform_buffer_binding @@ -3598,6 +3636,16 @@ struct gl_uniform_buffer_binding }; /** + * Binding point for an atomic counter buffer object. + */ +struct gl_atomic_buffer_binding +{ + struct gl_buffer_object *BufferObject; + GLintptr Offset; + GLsizeiptr Size; +}; + +/** * Mesa rendering context. * * This is the central context data structure for Mesa. Almost all @@ -3765,6 +3813,18 @@ struct gl_context struct gl_uniform_buffer_binding UniformBufferBindings[MAX_COMBINED_UNIFORM_BUFFERS]; + /** + * Object currently associated with the GL_ATOMIC_COUNTER_BUFFER + * target. + */ + struct gl_buffer_object *AtomicBuffer; + + /** + * Array of atomic counter buffer binding points. + */ + struct gl_atomic_buffer_binding + AtomicBufferBindings[MAX_COMBINED_ATOMIC_BUFFERS]; + /*@}*/ struct gl_meta_state *Meta; /**< for "meta" operations */ @@ -3832,6 +3892,15 @@ struct gl_context struct st_context *st; void *aelt_context; /*@}*/ + + /** + * \name NV_vdpau_interop + */ + /*@{*/ + const void *vdpDevice; + const void *vdpGetProcAddress; + struct set *vdpSurfaces; + /*@}*/ }; diff --git a/mesalib/src/mesa/main/queryobj.c b/mesalib/src/mesa/main/queryobj.c index 414724747..b411eae50 100644 --- a/mesalib/src/mesa/main/queryobj.c +++ b/mesalib/src/mesa/main/queryobj.c @@ -202,13 +202,6 @@ _mesa_GenQueries(GLsizei n, GLuint *ids) return; } - /* No query objects can be active at this time! */ - if (ctx->Query.CurrentOcclusionObject || - ctx->Query.CurrentTimerObject) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glGenQueriesARB"); - return; - } - first = _mesa_HashFindFreeKeyBlock(ctx->Query.QueryObjects, n); if (first) { GLsizei i; @@ -241,18 +234,20 @@ _mesa_DeleteQueries(GLsizei n, const GLuint *ids) return; } - /* No query objects can be active at this time! */ - if (ctx->Query.CurrentOcclusionObject || - ctx->Query.CurrentTimerObject) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glDeleteQueriesARB"); - return; - } - for (i = 0; i < n; i++) { if (ids[i] > 0) { struct gl_query_object *q = _mesa_lookup_query_object(ctx, ids[i]); if (q) { - ASSERT(!q->Active); /* should be caught earlier */ + if (q->Active) { + struct gl_query_object **bindpt; + bindpt = get_query_binding_point(ctx, q->Target); + assert(bindpt); /* Should be non-null for active q. */ + if (bindpt) { + *bindpt = NULL; + } + q->Active = GL_FALSE; + ctx->Driver.EndQuery(ctx, q); + } _mesa_HashRemove(ctx->Query.QueryObjects, ids[i]); ctx->Driver.DeleteQuery(ctx, q); } diff --git a/mesalib/src/mesa/main/shaderapi.c b/mesalib/src/mesa/main/shaderapi.c index f5c04b9f3..7da860ddf 100644 --- a/mesalib/src/mesa/main/shaderapi.c +++ b/mesalib/src/mesa/main/shaderapi.c @@ -648,6 +648,12 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname, GLint *param case GL_PROGRAM_BINARY_LENGTH: *params = 0; return; + case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: + if (!ctx->Extensions.ARB_shader_atomic_counters) + break; + + *params = shProg->NumAtomicBuffers; + return; default: break; } @@ -926,7 +932,7 @@ _mesa_active_program(struct gl_context *ctx, struct gl_shader_program *shProg, /** */ -static bool +static void use_shader_program(struct gl_context *ctx, GLenum type, struct gl_shader_program *shProg) { @@ -955,7 +961,7 @@ use_shader_program(struct gl_context *ctx, GLenum type, } break; default: - return false; + return; } if (*target != shProg) { @@ -982,10 +988,8 @@ use_shader_program(struct gl_context *ctx, GLenum type, } _mesa_reference_shader_program(ctx, target, shProg); - return true; + return; } - - return false; } /** diff --git a/mesalib/src/mesa/main/texparam.c b/mesalib/src/mesa/main/texparam.c index c9d928f63..d56b7d9d7 100644 --- a/mesalib/src/mesa/main/texparam.c +++ b/mesalib/src/mesa/main/texparam.c @@ -23,7 +23,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -/** +/** * \file texparam.c * * glTexParameter-related functions @@ -52,7 +52,7 @@ * Check if a coordinate wrap mode is supported for the texture target. * \return GL_TRUE if legal, GL_FALSE otherwise */ -static GLboolean +static GLboolean validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap) { const struct gl_extensions * const e = & ctx->Extensions; @@ -91,7 +91,7 @@ validate_texture_wrap_mode(struct gl_context * ctx, GLenum target, GLenum wrap) break; case GL_MIRROR_CLAMP_TO_EDGE_EXT: - supported = is_desktop_gl + supported = is_desktop_gl && (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp || e->ARB_texture_mirror_clamp_to_edge) && (target != GL_TEXTURE_RECTANGLE_NV) && (target != GL_TEXTURE_EXTERNAL_OES); @@ -1787,7 +1787,7 @@ _mesa_GetTexParameterIiv(GLenum target, GLenum pname, GLint *params) texObj = get_texobj(ctx, target, GL_TRUE); if (!texObj) return; - + switch (pname) { case GL_TEXTURE_BORDER_COLOR: COPY_4V(params, texObj->Sampler.BorderColor.i); @@ -1808,7 +1808,7 @@ _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params) texObj = get_texobj(ctx, target, GL_TRUE); if (!texObj) return; - + switch (pname) { case GL_TEXTURE_BORDER_COLOR: COPY_4V(params, texObj->Sampler.BorderColor.i); @@ -1818,7 +1818,7 @@ _mesa_GetTexParameterIuiv(GLenum target, GLenum pname, GLuint *params) GLint ip[4]; _mesa_GetTexParameteriv(target, pname, ip); params[0] = ip[0]; - if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT || + if (pname == GL_TEXTURE_SWIZZLE_RGBA_EXT || pname == GL_TEXTURE_CROP_RECT_OES) { params[1] = ip[1]; params[2] = ip[2]; diff --git a/mesalib/src/mesa/main/uniform_query.cpp b/mesalib/src/mesa/main/uniform_query.cpp index 3c460042e..88ad476ac 100644 --- a/mesalib/src/mesa/main/uniform_query.cpp +++ b/mesalib/src/mesa/main/uniform_query.cpp @@ -154,11 +154,21 @@ _mesa_GetActiveUniformsiv(GLuint program, params[i] = uni->row_major; break; + case GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX: + if (!ctx->Extensions.ARB_shader_atomic_counters) + goto invalid_enum; + params[i] = uni->atomic_buffer_index; + break; + default: - _mesa_error(ctx, GL_INVALID_ENUM, "glGetActiveUniformsiv(pname)"); - return; + goto invalid_enum; } } + + return; + + invalid_enum: + _mesa_error(ctx, GL_INVALID_ENUM, "glGetActiveUniformsiv(pname)"); } static bool diff --git a/mesalib/src/mesa/main/uniforms.c b/mesalib/src/mesa/main/uniforms.c index 1e6f7f483..2e847fe31 100644 --- a/mesalib/src/mesa/main/uniforms.c +++ b/mesalib/src/mesa/main/uniforms.c @@ -535,7 +535,8 @@ _mesa_GetUniformLocation(GLhandleARB programObj, const GLcharARB *name) * with a named uniform block, or if <name> starts with the reserved * prefix "gl_"." */ - if (shProg->UniformStorage[index].block_index != -1) + if (shProg->UniformStorage[index].block_index != -1 || + shProg->UniformStorage[index].atomic_buffer_index != -1) return -1; return _mesa_uniform_merge_location_offset(shProg, index, offset); @@ -844,3 +845,68 @@ _mesa_get_uniform_name(const struct gl_uniform_storage *uni, *length += i; } } + +void GLAPIENTRY +_mesa_GetActiveAtomicCounterBufferiv(GLuint program, GLuint bufferIndex, + GLenum pname, GLint *params) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_shader_program *shProg; + struct gl_active_atomic_buffer *ab; + int i; + + if (!ctx->Extensions.ARB_shader_atomic_counters) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "glGetActiveAtomicCounterBufferiv"); + return; + } + + shProg = _mesa_lookup_shader_program_err(ctx, program, + "glGetActiveAtomicCounterBufferiv"); + if (!shProg) + return; + + if (bufferIndex >= shProg->NumAtomicBuffers) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetActiveAtomicCounterBufferiv(bufferIndex)"); + return; + } + + ab = &shProg->AtomicBuffers[bufferIndex]; + + switch (pname) { + case GL_ATOMIC_COUNTER_BUFFER_BINDING: + params[0] = ab->Binding; + return; + case GL_ATOMIC_COUNTER_BUFFER_DATA_SIZE: + params[0] = ab->MinimumSize; + return; + case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTERS: + params[0] = ab->NumUniforms; + return; + case GL_ATOMIC_COUNTER_BUFFER_ACTIVE_ATOMIC_COUNTER_INDICES: + for (i = 0; i < ab->NumUniforms; ++i) + params[i] = ab->Uniforms[i]; + return; + case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_VERTEX_SHADER: + params[0] = ab->StageReferences[MESA_SHADER_VERTEX]; + return; + case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_GEOMETRY_SHADER: + params[0] = ab->StageReferences[MESA_SHADER_GEOMETRY]; + return; + case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_FRAGMENT_SHADER: + params[0] = ab->StageReferences[MESA_SHADER_FRAGMENT]; + return; + case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_CONTROL_SHADER: + params[0] = GL_FALSE; + return; + case GL_ATOMIC_COUNTER_BUFFER_REFERENCED_BY_TESS_EVALUATION_SHADER: + params[0] = GL_FALSE; + return; + default: + _mesa_error(ctx, GL_INVALID_ENUM, + "glGetActiveAtomicCounterBufferiv(pname 0x%x (%s))", + pname, _mesa_lookup_enum_by_nr(pname)); + return; + } +} diff --git a/mesalib/src/mesa/main/uniforms.h b/mesalib/src/mesa/main/uniforms.h index 92239176e..f7cac6328 100644 --- a/mesalib/src/mesa/main/uniforms.h +++ b/mesalib/src/mesa/main/uniforms.h @@ -142,6 +142,9 @@ _mesa_UniformBlockBinding(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); void GLAPIENTRY +_mesa_GetActiveAtomicCounterBufferiv(GLuint program, GLuint bufferIndex, + GLenum pname, GLint *params); +void GLAPIENTRY _mesa_GetActiveUniformBlockiv(GLuint program, GLuint uniformBlockIndex, GLenum pname, diff --git a/mesalib/src/mesa/main/vdpau.c b/mesalib/src/mesa/main/vdpau.c new file mode 100644 index 000000000..e21a26b43 --- /dev/null +++ b/mesalib/src/mesa/main/vdpau.c @@ -0,0 +1,424 @@ +/************************************************************************** + * + * Copyright 2013 Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Authors: + * Christian König <christian.koenig@amd.com> + * + */ + +#include <stdbool.h> +#include "context.h" +#include "glformats.h" +#include "hash_table.h" +#include "set.h" +#include "texobj.h" +#include "teximage.h" +#include "vdpau.h" + +#define MAX_TEXTURES 4 + +struct vdp_surface +{ + GLenum target; + struct gl_texture_object *textures[MAX_TEXTURES]; + GLenum access, state; + GLboolean output; + const GLvoid *vdpSurface; +}; + +void GLAPIENTRY +_mesa_VDPAUInitNV(const GLvoid *vdpDevice, const GLvoid *getProcAddress) +{ + GET_CURRENT_CONTEXT(ctx); + + if (!vdpDevice) { + _mesa_error(ctx, GL_INVALID_VALUE, "vdpDevice"); + return; + } + + if (!getProcAddress) { + _mesa_error(ctx, GL_INVALID_VALUE, "getProcAddress"); + return; + } + + if (ctx->vdpDevice || ctx->vdpGetProcAddress || ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUInitNV"); + return; + } + + ctx->vdpDevice = vdpDevice; + ctx->vdpGetProcAddress = getProcAddress; + ctx->vdpSurfaces = _mesa_set_create(NULL, _mesa_key_pointer_equal); +} + +static void +unregister_surface(struct set_entry *entry) +{ + struct vdp_surface *surf = (struct vdp_surface *)entry->key; + GET_CURRENT_CONTEXT(ctx); + + if (surf->state == GL_SURFACE_MAPPED_NV) { + GLintptr surfaces[] = { (GLintptr)surf }; + _mesa_VDPAUUnmapSurfacesNV(1, surfaces); + } + + _mesa_set_remove(ctx->vdpSurfaces, entry); + FREE(surf); +} + +void GLAPIENTRY +_mesa_VDPAUFiniNV(void) +{ + GET_CURRENT_CONTEXT(ctx); + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUFiniNV"); + return; + } + + _mesa_set_destroy(ctx->vdpSurfaces, unregister_surface); + + ctx->vdpDevice = 0; + ctx->vdpGetProcAddress = 0; + ctx->vdpSurfaces = NULL; +} + +static GLintptr +register_surface(struct gl_context *ctx, GLboolean isOutput, + const GLvoid *vdpSurface, GLenum target, + GLsizei numTextureNames, const GLuint *textureNames) +{ + struct vdp_surface *surf; + int i; + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAURegisterSurfaceNV"); + return (GLintptr)NULL; + } + + if (target != GL_TEXTURE_2D && target != GL_TEXTURE_RECTANGLE) { + _mesa_error(ctx, GL_INVALID_ENUM, "VDPAURegisterSurfaceNV"); + return (GLintptr)NULL; + } + + if (target == GL_TEXTURE_RECTANGLE && !ctx->Extensions.NV_texture_rectangle) { + _mesa_error(ctx, GL_INVALID_ENUM, "VDPAURegisterSurfaceNV"); + return (GLintptr)NULL; + } + + surf = CALLOC_STRUCT( vdp_surface ); + surf->vdpSurface = vdpSurface; + surf->target = target; + surf->access = GL_READ_WRITE; + surf->state = GL_SURFACE_REGISTERED_NV; + surf->output = isOutput; + for (i = 0; i < numTextureNames; ++i) { + struct gl_texture_object *tex; + tex = _mesa_lookup_texture(ctx, textureNames[i]); + + _mesa_lock_texture(ctx, tex); + + if (tex->Immutable) { + _mesa_unlock_texture(ctx, tex); + FREE(surf); + _mesa_error(ctx, GL_INVALID_OPERATION, + "VDPAURegisterSurfaceNV(texture is immutable)"); + return (GLintptr)NULL; + } + + if (tex->Target == 0) + tex->Target = target; + else if (tex->Target != target) { + _mesa_unlock_texture(ctx, tex); + FREE(surf); + _mesa_error(ctx, GL_INVALID_OPERATION, + "VDPAURegisterSurfaceNV(target mismatch)"); + return (GLintptr)NULL; + } + + /* This will disallow respecifying the storage. */ + tex->Immutable = GL_TRUE; + _mesa_unlock_texture(ctx, tex); + + _mesa_reference_texobj(&surf->textures[i], tex); + } + + _mesa_set_add(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf); + + return (GLintptr)surf; +} + +GLintptr GLAPIENTRY +_mesa_VDPAURegisterVideoSurfaceNV(const GLvoid *vdpSurface, GLenum target, + GLsizei numTextureNames, + const GLuint *textureNames) +{ + GET_CURRENT_CONTEXT(ctx); + + if (numTextureNames != 4) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAURegisterVideoSurfaceNV"); + return (GLintptr)NULL; + } + + return register_surface(ctx, false, vdpSurface, target, + numTextureNames, textureNames); +} + +GLintptr GLAPIENTRY +_mesa_VDPAURegisterOutputSurfaceNV(const GLvoid *vdpSurface, GLenum target, + GLsizei numTextureNames, + const GLuint *textureNames) +{ + GET_CURRENT_CONTEXT(ctx); + + if (numTextureNames != 1) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAURegisterVideoSurfaceNV"); + return (GLintptr)NULL; + } + + return register_surface(ctx, true, vdpSurface, target, + numTextureNames, textureNames); +} + +void GLAPIENTRY +_mesa_VDPAUIsSurfaceNV(GLintptr surface) +{ + struct vdp_surface *surf = (struct vdp_surface *)surface; + GET_CURRENT_CONTEXT(ctx); + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUIsSurfaceNV"); + return; + } + + if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUIsSurfaceNV"); + return; + } +} + +void GLAPIENTRY +_mesa_VDPAUUnregisterSurfaceNV(GLintptr surface) +{ + struct vdp_surface *surf = (struct vdp_surface *)surface; + struct set_entry *entry; + int i; + GET_CURRENT_CONTEXT(ctx); + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUUnregisterSurfaceNV"); + return; + } + + /* according to the spec it's ok when this is zero */ + if (surface == 0) + return; + + entry = _mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf); + if (!entry) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUUnregisterSurfaceNV"); + return; + } + + for (i = 0; i < MAX_TEXTURES; i++) { + if (surf->textures[i]) { + surf->textures[i]->Immutable = GL_FALSE; + _mesa_reference_texobj(&surf->textures[i], NULL); + } + } + + _mesa_set_remove(ctx->vdpSurfaces, entry); + FREE(surf); +} + +void GLAPIENTRY +_mesa_VDPAUGetSurfaceivNV(GLintptr surface, GLenum pname, GLsizei bufSize, + GLsizei *length, GLint *values) +{ + struct vdp_surface *surf = (struct vdp_surface *)surface; + GET_CURRENT_CONTEXT(ctx); + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUGetSurfaceivNV"); + return; + } + + if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUGetSurfaceivNV"); + return; + } + + if (pname != GL_SURFACE_STATE_NV) { + _mesa_error(ctx, GL_INVALID_ENUM, "VDPAUGetSurfaceivNV"); + return; + } + + if (bufSize < 1) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUGetSurfaceivNV"); + return; + } + + values[0] = surf->state; + + if (length != NULL) + *length = 1; +} + +void GLAPIENTRY +_mesa_VDPAUSurfaceAccessNV(GLintptr surface, GLenum access) +{ + struct vdp_surface *surf = (struct vdp_surface *)surface; + GET_CURRENT_CONTEXT(ctx); + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUSurfaceAccessNV"); + return; + } + + if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV"); + return; + } + + if (access != GL_READ_ONLY && access != GL_WRITE_ONLY && + access != GL_READ_WRITE) { + + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV"); + return; + } + + if (surf->state == GL_SURFACE_MAPPED_NV) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUSurfaceAccessNV"); + return; + } + + surf->access = access; +} + +void GLAPIENTRY +_mesa_VDPAUMapSurfacesNV(GLsizei numSurfaces, const GLintptr *surfaces) +{ + GET_CURRENT_CONTEXT(ctx); + int i, j; + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUUnmapSurfacesNV"); + return; + } + + for (i = 0; i < numSurfaces; ++i) { + struct vdp_surface *surf = (struct vdp_surface *)surfaces[i]; + + if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV"); + return; + } + + if (surf->state == GL_SURFACE_MAPPED_NV) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUSurfaceAccessNV"); + return; + } + } + + for (i = 0; i < numSurfaces; ++i) { + struct vdp_surface *surf = (struct vdp_surface *)surfaces[i]; + unsigned numTextureNames = surf->output ? 1 : 4; + + for (j = 0; j < numTextureNames; ++j) { + struct gl_texture_object *tex = surf->textures[j]; + struct gl_texture_image *image; + + _mesa_lock_texture(ctx, tex); + image = _mesa_get_tex_image(ctx, tex, surf->target, 0); + if (!image) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "VDPAUMapSurfacesNV"); + _mesa_unlock_texture(ctx, tex); + return; + } + + ctx->Driver.FreeTextureImageBuffer(ctx, image); + + ctx->Driver.VDPAUMapSurface(ctx, surf->target, surf->access, + surf->output, tex, image, + surf->vdpSurface, j); + + _mesa_unlock_texture(ctx, tex); + } + surf->state = GL_SURFACE_MAPPED_NV; + } +} + +void GLAPIENTRY +_mesa_VDPAUUnmapSurfacesNV(GLsizei numSurfaces, const GLintptr *surfaces) +{ + GET_CURRENT_CONTEXT(ctx); + int i, j; + + if (!ctx->vdpDevice || !ctx->vdpGetProcAddress || !ctx->vdpSurfaces) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUUnmapSurfacesNV"); + return; + } + + for (i = 0; i < numSurfaces; ++i) { + struct vdp_surface *surf = (struct vdp_surface *)surfaces[i]; + + if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV"); + return; + } + + if (surf->state != GL_SURFACE_MAPPED_NV) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUSurfaceAccessNV"); + return; + } + } + + for (i = 0; i < numSurfaces; ++i) { + struct vdp_surface *surf = (struct vdp_surface *)surfaces[i]; + unsigned numTextureNames = surf->output ? 1 : 4; + + for (j = 0; j < numTextureNames; ++j) { + struct gl_texture_object *tex = surf->textures[j]; + struct gl_texture_image *image; + + _mesa_lock_texture(ctx, tex); + + image = _mesa_select_tex_image(ctx, tex, surf->target, 0); + + ctx->Driver.VDPAUUnmapSurface(ctx, surf->target, surf->access, + surf->output, tex, image, + surf->vdpSurface, j); + + if (image) + ctx->Driver.FreeTextureImageBuffer(ctx, image); + + _mesa_unlock_texture(ctx, tex); + } + surf->state = GL_SURFACE_REGISTERED_NV; + } +} diff --git a/mesalib/src/mesa/main/vdpau.h b/mesalib/src/mesa/main/vdpau.h new file mode 100644 index 000000000..f32d6dacb --- /dev/null +++ b/mesalib/src/mesa/main/vdpau.h @@ -0,0 +1,72 @@ +/************************************************************************** + * + * Copyright 2013 Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Authors: + * Christian König <christian.koenig@amd.com> + * + */ + +#ifndef VDPAU_H +#define VDPAU_H + +extern void GLAPIENTRY +_mesa_VDPAUInitNV(const GLvoid *vdpDevice, const GLvoid *getProcAddress); + +extern void GLAPIENTRY +_mesa_VDPAUFiniNV(void); + +extern GLintptr GLAPIENTRY +_mesa_VDPAURegisterVideoSurfaceNV(const GLvoid *vdpSurface, GLenum target, + GLsizei numTextureNames, + const GLuint *textureNames); + +extern GLintptr GLAPIENTRY +_mesa_VDPAURegisterOutputSurfaceNV(const GLvoid *vdpSurface, GLenum target, + GLsizei numTextureNames, + const GLuint *textureNames); + +extern void GLAPIENTRY +_mesa_VDPAUIsSurfaceNV(GLintptr surface); + +extern void GLAPIENTRY +_mesa_VDPAUUnregisterSurfaceNV(GLintptr surface); + +extern void GLAPIENTRY +_mesa_VDPAUGetSurfaceivNV(GLintptr surface, GLenum pname, GLsizei bufSize, + GLsizei *length, GLint *values); + +extern void GLAPIENTRY +_mesa_VDPAUSurfaceAccessNV(GLintptr surface, GLenum access); + +extern void GLAPIENTRY +_mesa_VDPAUMapSurfacesNV(GLsizei numSurfaces, const GLintptr *surfaces); + +extern void GLAPIENTRY +_mesa_VDPAUUnmapSurfacesNV(GLsizei numSurfaces, const GLintptr *surfaces); + +#endif /* VDPAU_H */ diff --git a/mesalib/src/mesa/program/ir_to_mesa.cpp b/mesalib/src/mesa/program/ir_to_mesa.cpp index cfad91bc4..c833a12f2 100644 --- a/mesalib/src/mesa/program/ir_to_mesa.cpp +++ b/mesalib/src/mesa/program/ir_to_mesa.cpp @@ -622,6 +622,7 @@ type_size(const struct glsl_type *type) * at link time. */ return 1; + case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_VOID: case GLSL_TYPE_ERROR: case GLSL_TYPE_INTERFACE: @@ -2601,6 +2602,7 @@ _mesa_associate_uniform_storage(struct gl_context *ctx, format = uniform_native; columns = 1; break; + case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_ARRAY: case GLSL_TYPE_VOID: case GLSL_TYPE_STRUCT: diff --git a/mesalib/src/mesa/state_tracker/st_context.c b/mesalib/src/mesa/state_tracker/st_context.c index 4e0d98cc3..2cc3567e0 100644 --- a/mesalib/src/mesa/state_tracker/st_context.c +++ b/mesalib/src/mesa/state_tracker/st_context.c @@ -65,6 +65,7 @@ #include "st_extensions.h" #include "st_gen_mipmap.h" #include "st_program.h" +#include "st_vdpau.h" #include "pipe/p_context.h" #include "util/u_inlines.h" #include "util/u_upload_mgr.h" @@ -360,5 +361,7 @@ void st_init_driver_functions(struct dd_function_table *functions) st_init_xformfb_functions(functions); st_init_syncobj_functions(functions); + st_init_vdpau_functions(functions); + functions->UpdateState = st_invalidate_state; } diff --git a/mesalib/src/mesa/state_tracker/st_draw.c b/mesalib/src/mesa/state_tracker/st_draw.c index c35723087..51bb23807 100644 --- a/mesalib/src/mesa/state_tracker/st_draw.c +++ b/mesalib/src/mesa/state_tracker/st_draw.c @@ -210,9 +210,6 @@ st_draw_vbo(struct gl_context *ctx, if (st->dirty.st || ctx->NewDriverState) { st_validate_state(st); - if (st->vertex_array_out_of_memory) - return; - #if 0 if (MESA_VERBOSE & VERBOSE_GLSL) { check_uniforms(ctx); @@ -222,6 +219,10 @@ st_draw_vbo(struct gl_context *ctx, #endif } + if (st->vertex_array_out_of_memory) { + return; + } + util_draw_init_info(&info); if (ib) { diff --git a/mesalib/src/mesa/state_tracker/st_extensions.c b/mesalib/src/mesa/state_tracker/st_extensions.c index 231bb395a..97c5d55e1 100644 --- a/mesalib/src/mesa/state_tracker/st_extensions.c +++ b/mesalib/src/mesa/state_tracker/st_extensions.c @@ -445,8 +445,7 @@ void st_init_extensions(struct st_context *st) { PIPE_FORMAT_Z32_FLOAT, PIPE_FORMAT_Z32_FLOAT_S8X24_UINT } }, - { { o(ARB_framebuffer_object), - o(EXT_packed_depth_stencil) }, + { { o(EXT_packed_depth_stencil) }, { PIPE_FORMAT_S8_UINT_Z24_UNORM, PIPE_FORMAT_Z24_UNORM_S8_UINT }, GL_TRUE }, /* at least one format must be supported */ @@ -565,6 +564,7 @@ void st_init_extensions(struct st_context *st) ctx->Extensions.NV_fog_distance = GL_TRUE; ctx->Extensions.NV_texture_env_combine4 = GL_TRUE; ctx->Extensions.NV_texture_rectangle = GL_TRUE; + ctx->Extensions.NV_vdpau_interop = GL_TRUE; ctx->Extensions.OES_EGL_image = GL_TRUE; ctx->Extensions.OES_EGL_image_external = GL_TRUE; @@ -760,6 +760,10 @@ void st_init_extensions(struct st_context *st) PIPE_BUFFER, PIPE_BIND_SAMPLER_VIEW); } + if (screen->get_param(screen, PIPE_CAP_MIXED_FRAMEBUFFER_SIZES) && + ctx->Extensions.EXT_packed_depth_stencil) { + ctx->Extensions.ARB_framebuffer_object = GL_TRUE; + } /* Unpacking a varying in the fragment shader costs 1 texture indirection. * If the number of available texture indirections is very limited, then we diff --git a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index 3e11cce24..0eaf7467b 100644 --- a/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/mesalib/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -993,6 +993,7 @@ type_size(const struct glsl_type *type) * at link time. */ return 1; + case GLSL_TYPE_ATOMIC_UINT: case GLSL_TYPE_INTERFACE: case GLSL_TYPE_VOID: case GLSL_TYPE_ERROR: diff --git a/mesalib/src/mesa/state_tracker/st_vdpau.c b/mesalib/src/mesa/state_tracker/st_vdpau.c new file mode 100644 index 000000000..9b165ee39 --- /dev/null +++ b/mesalib/src/mesa/state_tracker/st_vdpau.c @@ -0,0 +1,181 @@ +/************************************************************************** + * + * Copyright 2013 Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Authors: + * Christian König <christian.koenig@amd.com> + * + */ + +#include "main/texobj.h" +#include "main/teximage.h" +#include "main/errors.h" +#include "program/prog_instruction.h" + +#include "pipe/p_state.h" +#include "pipe/p_video_codec.h" + +#include "state_tracker/vdpau_interop.h" + +#include "util/u_inlines.h" + +#include "st_vdpau.h" +#include "st_context.h" +#include "st_texture.h" +#include "st_format.h" + +static void +st_vdpau_map_surface(struct gl_context *ctx, GLenum target, GLenum access, + GLboolean output, struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + const GLvoid *vdpSurface, GLuint index) +{ + int (*getProcAddr)(uint32_t device, uint32_t id, void **ptr); + uint32_t device = (uintptr_t)ctx->vdpDevice; + + struct st_context *st = st_context(ctx); + struct st_texture_object *stObj = st_texture_object(texObj); + struct st_texture_image *stImage = st_texture_image(texImage); + + struct pipe_resource *res; + struct pipe_sampler_view *sv, templ; + gl_format texFormat; + + getProcAddr = ctx->vdpGetProcAddress; + if (output) { + VdpOutputSurfaceGallium *f; + + if (getProcAddr(device, VDP_FUNC_ID_OUTPUT_SURFACE_GALLIUM, (void**)&f)) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + res = f((uintptr_t)vdpSurface); + + if (!res) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + } else { + VdpVideoSurfaceGallium *f; + + struct pipe_video_buffer *buffer; + struct pipe_sampler_view **samplers; + + if (getProcAddr(device, VDP_FUNC_ID_VIDEO_SURFACE_GALLIUM, (void**)&f)) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + buffer = f((uintptr_t)vdpSurface); + if (!buffer) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + samplers = buffer->get_sampler_view_planes(buffer); + if (!samplers) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + sv = samplers[index >> 1]; + if (!sv) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + res = sv->texture; + } + + if (!res) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + /* do we have different screen objects ? */ + if (res->screen != st->pipe->screen) { + _mesa_error(ctx, GL_INVALID_OPERATION, "VDPAUMapSurfacesNV"); + return; + } + + /* switch to surface based */ + if (!stObj->surface_based) { + _mesa_clear_texture_object(ctx, texObj); + stObj->surface_based = GL_TRUE; + } + + texFormat = st_pipe_format_to_mesa_format(res->format); + + _mesa_init_teximage_fields(ctx, texImage, + res->width0, res->height0, 1, 0, GL_RGBA, + texFormat); + + pipe_resource_reference(&stObj->pt, res); + pipe_sampler_view_reference(&stObj->sampler_view, NULL); + pipe_resource_reference(&stImage->pt, res); + + u_sampler_view_default_template(&templ, res, res->format); + templ.u.tex.first_layer = index & 1; + templ.u.tex.last_layer = index & 1; + templ.swizzle_r = GET_SWZ(stObj->base._Swizzle, 0); + templ.swizzle_g = GET_SWZ(stObj->base._Swizzle, 1); + templ.swizzle_b = GET_SWZ(stObj->base._Swizzle, 2); + templ.swizzle_a = GET_SWZ(stObj->base._Swizzle, 3); + stObj->sampler_view = st->pipe->create_sampler_view(st->pipe, res, &templ); + + stObj->width0 = res->width0; + stObj->height0 = res->height0; + stObj->depth0 = 1; + stObj->surface_format = res->format; + + _mesa_dirty_texobj(ctx, texObj); +} + +static void +st_vdpau_unmap_surface(struct gl_context *ctx, GLenum target, GLenum access, + GLboolean output, struct gl_texture_object *texObj, + struct gl_texture_image *texImage, + const GLvoid *vdpSurface, GLuint index) +{ + struct st_texture_object *stObj = st_texture_object(texObj); + struct st_texture_image *stImage = st_texture_image(texImage); + + pipe_resource_reference(&stObj->pt, NULL); + pipe_sampler_view_reference(&stObj->sampler_view, NULL); + pipe_resource_reference(&stImage->pt, NULL); + + _mesa_dirty_texobj(ctx, texObj); +} + +void +st_init_vdpau_functions(struct dd_function_table *functions) +{ + functions->VDPAUMapSurface = st_vdpau_map_surface; + functions->VDPAUUnmapSurface = st_vdpau_unmap_surface; +} diff --git a/mesalib/src/mesa/state_tracker/st_vdpau.h b/mesalib/src/mesa/state_tracker/st_vdpau.h new file mode 100644 index 000000000..59c744305 --- /dev/null +++ b/mesalib/src/mesa/state_tracker/st_vdpau.h @@ -0,0 +1,42 @@ +/************************************************************************** + * + * Copyright 2013 Advanced Micro Devices, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/* + * Authors: + * Christian König <christian.koenig@amd.com> + * + */ + +#ifndef ST_VDPAU_H +#define ST_VDPAU_H + +struct dd_function_table; + +extern void +st_init_vdpau_functions(struct dd_function_table *functions); + +#endif /* ST_VDPAU_H */ |