Merge remote branch 'origin/master' into nvc0-new

This commit is contained in:
Christoph Bumiller 2010-12-19 21:46:33 +01:00
commit 0f68236a24
875 changed files with 48915 additions and 41805 deletions

View file

@ -347,23 +347,19 @@ GALLIUM_FILES = \
DRI_FILES = \
$(DIRECTORY)/include/GL/internal/dri_interface.h \
$(DIRECTORY)/include/GL/internal/glcore.h \
$(DIRECTORY)/include/GL/internal/sarea.h \
$(DIRECTORY)/src/glx/Makefile \
$(DIRECTORY)/src/glx/Makefile \
$(DIRECTORY)/src/glx/*.[ch] \
$(DIRECTORY)/src/mesa/drivers/dri/Makefile \
$(DIRECTORY)/src/mesa/drivers/dri/Makefile.template \
$(DIRECTORY)/src/mesa/drivers/dri/dri.pc.in \
$(DIRECTORY)/src/mesa/drivers/dri/common/xmlpool/*.[ch] \
$(DIRECTORY)/src/mesa/drivers/dri/common/xmlpool/*.po \
$(DIRECTORY)/src/mesa/drivers/dri/*/*.[chS] \
$(DIRECTORY)/src/mesa/drivers/dri/*/*.cpp \
$(DIRECTORY)/src/mesa/drivers/dri/*/*/*.[chS] \
$(DIRECTORY)/src/mesa/drivers/dri/*/Makefile \
$(DIRECTORY)/src/mesa/drivers/dri/*/*/Makefile \
$(DIRECTORY)/src/mesa/drivers/dri/*/Doxyfile \
$(DIRECTORY)/src/mesa/drivers/dri/*/server/*.[ch]
$(DIRECTORY)/src/mesa/drivers/dri/*/Doxyfile
SGI_GLU_FILES = \
$(DIRECTORY)/src/glu/Makefile \

View file

@ -32,7 +32,6 @@ import common
opts = Variables('config.py')
common.AddOptions(opts)
opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
env = Environment(
options = opts,

View file

@ -91,3 +91,4 @@ def AddOptions(opts):
opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))

View file

@ -15,7 +15,7 @@ ARCH_FLAGS = -mmmx -msse -msse2 -mstackrealign
DEFINES += -DNDEBUG -DGALLIUM_LLVMPIPE -DHAVE_UDIS86
# override -std=c99
CFLAGS += -std=gnu99 -D__STDC_CONSTANT_MACROS
CFLAGS += -std=gnu99
LLVM_VERSION := $(shell llvm-config --version)
@ -30,7 +30,7 @@ else
endif
ifeq ($(MESA_LLVM),1)
# LLVM_CFLAGS=`llvm-config --cflags`
LLVM_CFLAGS=`llvm-config --cppflags`
LLVM_CXXFLAGS=`llvm-config --cxxflags backend bitreader engine ipo interpreter instrumentation` -Wno-long-long
LLVM_LDFLAGS = $(shell llvm-config --ldflags backend bitreader engine ipo interpreter instrumentation)
LLVM_LIBS = $(shell llvm-config --libs backend bitwriter bitreader engine ipo interpreter instrumentation)

View file

@ -1558,7 +1558,7 @@ AC_ARG_ENABLE([gallium-llvm],
if test "x$enable_gallium_llvm" = xyes; then
if test "x$LLVM_CONFIG" != xno; then
LLVM_VERSION=`$LLVM_CONFIG --version`
LLVM_CFLAGS=`$LLVM_CONFIG --cflags`
LLVM_CFLAGS=`$LLVM_CONFIG --cppflags`
LLVM_LIBS="`$LLVM_CONFIG --libs jit interpreter nativecodegen bitwriter` -lstdc++"
if test "x$HAS_UDIS86" != xno; then
@ -1708,6 +1708,19 @@ if test "x$enable_gallium_swrast" = xyes || test "x$enable_gallium_swrast" = xau
fi
fi
dnl
dnl Gallium noop configuration
dnl
AC_ARG_ENABLE([gallium-noop],
[AS_HELP_STRING([--enable-gallium-noop],
[build gallium radeon @<:@default=disabled@:>@])],
[enable_gallium_noop="$enableval"],
[enable_gallium_noop=auto])
if test "x$enable_gallium_noop" = xyes; then
GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS noop"
GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri-noop"
fi
dnl prepend CORE_DIRS to SRC_DIRS
SRC_DIRS="$CORE_DIRS $SRC_DIRS"

View file

@ -20,7 +20,7 @@ Float textures, renderbuffers some infrastructure done
Framebuffer objects (GL_EXT_framebuffer_object) DONE
Half-float some infrastructure done
Multisample blit DONE
Non-normalized Integer texture/framebuffer formats not started
Non-normalized Integer texture/framebuffer formats ~50% done
1D/2D Texture arrays core Mesa, swrast done
Packed depth/stencil formats DONE
Per-buffer blend and masks (GL_EXT_draw_buffers2) DONE
@ -31,10 +31,11 @@ Transform feedback (GL_EXT_transform_feedback) ~50% done
glBindBufferRange, glBindBufferBase commands
Vertex array objects (GL_APPLE_vertex_array_object) DONE
sRGB framebuffer format (GL_EXT_framebuffer_sRGB) not started
glClearBuffer commands DONE, except for dispatch
glGetStringi command DONE, except for dispatch
glTexParameterI, glGetTexParameterI commands DONE, except for dispatch
glVertexAttribI commands not started
glClearBuffer commands DONE
glGetStringi command DONE
glTexParameterI, glGetTexParameterI commands DONE
glVertexAttribI commands DONE (but converts int
values to floats)
GL 3.1:
@ -70,7 +71,7 @@ GL 3.3:
GLSL 3.30 not started
GL_ARB_blend_func_extended not started
GL_ARB_explicit_attrib_location DONE (swrast, i915, i965)
GL_ARB_occlusion_query2 not started
GL_ARB_occlusion_query2 DONE (swrast, gallium)
GL_ARB_sampler_objects not started
GL_ARB_texture_rgb10_a2ui not started
GL_ARB_texture_swizzle DONE (same as EXT version)
@ -93,6 +94,18 @@ GL_ARB_texture_buffer_object_rgb32 not started
GL_ARB_texture_cube_map_array not started
GL_ARB_texture_gather not started
GL_ARB_transform_feedback2 not started
GL_ARB_transform_feedback3 not started
GL 4.1:
GLSL 4.1 not started
GL_ARB_ES2_compatibility not started
GL_ARB_get_program_binary not started
GL_ARB_separate_shader_objects some infrastructure done
GL_ARB_shader_precision not started
GL_ARB_vertex_attrib_64bit not started
GL_ARB_viewport_array not started

View file

@ -83,7 +83,7 @@ Additions to the EGL 1.4 Specification:
EGLImageKHR eglCreateDRMImageMESA(EGLDisplay dpy,
const EGLint *attrib_list);
In the attribute list, pass EGL_WIDTH, EGL_EIGHT and format and
In the attribute list, pass EGL_WIDTH, EGL_HEIGHT and format and
use in the attrib list using EGL_DRM_BUFFER_FORMAT_MESA and
EGL_DRM_BUFFER_USE_MESA. The only format specified by this
extension is EGL_DRM_BUFFER_FORMAT_ARGB32_MESA, where each pixel

View file

@ -49,7 +49,7 @@ tbd
<h2>Changes</h2>
<ul>
<li>tbd</li>
<li>Upgraded glext.h to version 66</li>
</ul>
</body>

View file

@ -29,9 +29,9 @@ extern "C" {
*/
/* Header file version number, required by OpenGL ABI for Linux */
/* glext.h last updated $Date: 2010-08-03 01:30:25 -0700 (Tue, 03 Aug 2010) $ */
/* glext.h last updated $Date: 2010-11-03 18:59:30 -0700 (Wed, 03 Nov 2010) $ */
/* Current version at http://www.opengl.org/registry/ */
#define GL_GLEXT_VERSION 64
#define GL_GLEXT_VERSION 66
/* Function declaration macros - to move into glplatform.h */
#if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
@ -4840,7 +4840,7 @@ extern "C" {
#endif
#ifndef GL_AMD_seamless_cubemap_per_texture
/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS_ARB */
/* reuse GL_TEXTURE_CUBE_MAP_SEAMLESS */
#endif
#ifndef GL_AMD_conservative_depth
@ -4925,6 +4925,8 @@ extern "C" {
#define GL_MIN_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5B
#define GL_MAX_FRAGMENT_INTERPOLATION_OFFSET_NV 0x8E5C
#define GL_FRAGMENT_PROGRAM_INTERPOLATION_OFFSET_BITS_NV 0x8E5D
#define GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5E
#define GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET_NV 0x8E5F
#define GL_MAX_PROGRAM_SUBROUTINE_PARAMETERS_NV 0x8F44
#define GL_MAX_PROGRAM_SUBROUTINE_NUM_NV 0x8F45
#endif
@ -5019,6 +5021,11 @@ extern "C" {
#ifndef GL_AMD_transform_feedback3_lines_triangles
#endif
#ifndef GL_AMD_depth_clamp_separate
#define GL_DEPTH_CLAMP_NEAR_AMD 0x901E
#define GL_DEPTH_CLAMP_FAR_AMD 0x901F
#endif
/*************************************************************/
@ -8765,8 +8772,8 @@ GLAPI void APIENTRY glProgramParameter4dNV (GLenum target, GLuint index, GLdoubl
GLAPI void APIENTRY glProgramParameter4dvNV (GLenum target, GLuint index, const GLdouble *v);
GLAPI void APIENTRY glProgramParameter4fNV (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
GLAPI void APIENTRY glProgramParameter4fvNV (GLenum target, GLuint index, const GLfloat *v);
GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLuint count, const GLdouble *v);
GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLuint count, const GLfloat *v);
GLAPI void APIENTRY glProgramParameters4dvNV (GLenum target, GLuint index, GLsizei count, const GLdouble *v);
GLAPI void APIENTRY glProgramParameters4fvNV (GLenum target, GLuint index, GLsizei count, const GLfloat *v);
GLAPI void APIENTRY glRequestResidentProgramsNV (GLsizei n, const GLuint *programs);
GLAPI void APIENTRY glTrackMatrixNV (GLenum target, GLuint address, GLenum matrix, GLenum transform);
GLAPI void APIENTRY glVertexAttribPointerNV (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer);
@ -8830,8 +8837,8 @@ typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DNVPROC) (GLenum target, GLuint in
typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4DVNVPROC) (GLenum target, GLuint index, const GLdouble *v);
typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FNVPROC) (GLenum target, GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
typedef void (APIENTRYP PFNGLPROGRAMPARAMETER4FVNVPROC) (GLenum target, GLuint index, const GLfloat *v);
typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLuint count, const GLdouble *v);
typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLuint count, const GLfloat *v);
typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4DVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLdouble *v);
typedef void (APIENTRYP PFNGLPROGRAMPARAMETERS4FVNVPROC) (GLenum target, GLuint index, GLsizei count, const GLfloat *v);
typedef void (APIENTRYP PFNGLREQUESTRESIDENTPROGRAMSNVPROC) (GLsizei n, const GLuint *programs);
typedef void (APIENTRYP PFNGLTRACKMATRIXNVPROC) (GLenum target, GLuint address, GLenum matrix, GLenum transform);
typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERNVPROC) (GLuint index, GLint fsize, GLenum type, GLsizei stride, const GLvoid *pointer);
@ -11020,6 +11027,10 @@ typedef void (APIENTRYP PFNGLVDPAUUNMAPSURFACESNVPROC) (GLsizei numSurface, cons
#define GL_AMD_transform_feedback3_lines_triangles 1
#endif
#ifndef GL_AMD_depth_clamp_separate
#define GL_AMD_depth_clamp_separate 1
#endif
#ifdef __cplusplus
}

View file

@ -1,8 +1,8 @@
/* $Revision: 6822 $ on $Date:: 2008-10-30 05:14:19 -0400 #$ */
/* $Revision: 9203 $ on $Date:: 2009-10-07 02:21:52 -0700 #$ */
/*------------------------------------------------------------------------
*
* OpenVG 1.0.1 Reference Implementation
* OpenVG 1.1 Reference Implementation
* -------------------------------------
*
* Copyright (c) 2008 The Khronos Group Inc.
@ -28,7 +28,7 @@
*
*//**
* \file
* \brief OpenVG 1.0.1 API.
* \brief OpenVG 1.1 API.
*//*-------------------------------------------------------------------*/
#ifndef _OPENVG_H
@ -42,6 +42,7 @@ extern "C" {
#define OPENVG_VERSION_1_0 1
#define OPENVG_VERSION_1_0_1 1
#define OPENVG_VERSION_1_1 2
#ifndef VG_MAXSHORT
#define VG_MAXSHORT 0x7FFF
@ -55,10 +56,12 @@ extern "C" {
#define VG_MAX_ENUM 0x7FFFFFFF
#endif
typedef long VGHandle;
typedef VGuint VGHandle;
typedef VGHandle VGPath;
typedef VGHandle VGImage;
typedef VGHandle VGMaskLayer;
typedef VGHandle VGFont;
typedef VGHandle VGPaint;
#define VG_INVALID_HANDLE ((VGHandle)0)
@ -96,6 +99,10 @@ typedef enum {
/* Scissoring rectangles */
VG_SCISSOR_RECTS = 0x1106,
/* Color Transformation */
VG_COLOR_TRANSFORM = 0x1170,
VG_COLOR_TRANSFORM_VALUES = 0x1171,
/* Stroke parameters */
VG_STROKE_LINE_WIDTH = 0x1110,
VG_STROKE_CAP_STYLE = 0x1111,
@ -111,6 +118,9 @@ typedef enum {
/* Color for vgClear */
VG_CLEAR_COLOR = 0x1121,
/* Glyph origin */
VG_GLYPH_ORIGIN = 0x1122,
/* Enable/disable alpha masking and scissoring */
VG_MASKING = 0x1130,
VG_SCISSORING = 0x1131,
@ -165,6 +175,7 @@ typedef enum {
VG_MATRIX_IMAGE_USER_TO_SURFACE = 0x1401,
VG_MATRIX_FILL_PAINT_TO_USER = 0x1402,
VG_MATRIX_STROKE_PAINT_TO_USER = 0x1403,
VG_MATRIX_GLYPH_USER_TO_SURFACE = 0x1404,
VG_MATRIX_MODE_FORCE_SIZE = VG_MAX_ENUM
} VGMatrixMode;
@ -365,6 +376,8 @@ typedef enum {
VG_lL_8 = 10,
VG_A_8 = 11,
VG_BW_1 = 12,
VG_A_1 = 13,
VG_A_4 = 14,
/* {A,X}RGB channel ordering */
VG_sXRGB_8888 = 0 | (1 << 6),
@ -448,6 +461,12 @@ typedef enum {
VG_BLEND_MODE_FORCE_SIZE = VG_MAX_ENUM
} VGBlendMode;
typedef enum {
VG_FONT_NUM_GLYPHS = 0x2F00,
VG_FONT_PARAM_TYPE_FORCE_SIZE = VG_MAX_ENUM
} VGFontParamType;
typedef enum {
VG_IMAGE_FORMAT_QUERY = 0x2100,
VG_PATH_DATATYPE_QUERY = 0x2101,
@ -541,8 +560,22 @@ VG_API_CALL void VG_API_ENTRY vgShear(VGfloat shx, VGfloat shy) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgRotate(VGfloat angle) VG_API_EXIT;
/* Masking and Clearing */
VG_API_CALL void VG_API_ENTRY vgMask(VGImage mask, VGMaskOperation operation,
VGint x, VGint y, VGint width, VGint height) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgMask(VGHandle mask, VGMaskOperation operation,
VGint x, VGint y,
VGint width, VGint height) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgRenderToMask(VGPath path,
VGbitfield paintModes,
VGMaskOperation operation) VG_API_EXIT;
VG_API_CALL VGMaskLayer VG_API_ENTRY vgCreateMaskLayer(VGint width, VGint height) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgDestroyMaskLayer(VGMaskLayer maskLayer) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgFillMaskLayer(VGMaskLayer maskLayer,
VGint x, VGint y,
VGint width, VGint height,
VGfloat value) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgCopyMask(VGMaskLayer maskLayer,
VGint dx, VGint dy,
VGint sx, VGint sy,
VGint width, VGint height) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgClear(VGint x, VGint y, VGint width, VGint height) VG_API_EXIT;
/* Paths */
@ -636,6 +669,33 @@ VG_API_CALL void VG_API_ENTRY vgCopyPixels(VGint dx, VGint dy,
VGint sx, VGint sy,
VGint width, VGint height) VG_API_EXIT;
/* Text */
VG_API_CALL VGFont VG_API_ENTRY vgCreateFont(VGint glyphCapacityHint) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgDestroyFont(VGFont font) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgSetGlyphToPath(VGFont font,
VGuint glyphIndex,
VGPath path,
VGboolean isHinted,
const VGfloat glyphOrigin [2],
const VGfloat escapement[2]) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgSetGlyphToImage(VGFont font,
VGuint glyphIndex,
VGImage image,
const VGfloat glyphOrigin [2],
const VGfloat escapement[2]) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgClearGlyph(VGFont font,VGuint glyphIndex) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgDrawGlyph(VGFont font,
VGuint glyphIndex,
VGbitfield paintModes,
VGboolean allowAutoHinting) VG_API_EXIT;
VG_API_CALL void VG_API_ENTRY vgDrawGlyphs(VGFont font,
VGint glyphCount,
const VGuint *glyphIndices,
const VGfloat *adjustments_x,
const VGfloat *adjustments_y,
VGbitfield paintModes,
VGboolean allowAutoHinting) VG_API_EXIT;
/* Image Filters */
VG_API_CALL void VG_API_ENTRY vgColorMatrix(VGImage dst, VGImage src,
const VGfloat * matrix) VG_API_EXIT;

View file

@ -1,233 +1,233 @@
/* $Revision: 6810 $ on $Date:: 2008-10-29 10:31:37 -0400 #$ */
/*------------------------------------------------------------------------
*
* VG extensions Reference Implementation
* -------------------------------------
*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and /or associated documentation files
* (the "Materials "), to deal in the Materials without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Materials,
* and to permit persons to whom the Materials are furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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 MATERIALS OR
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
*
*//**
* \file
* \brief VG extensions
*//*-------------------------------------------------------------------*/
#ifndef _VGEXT_H
#define _VGEXT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <VG/openvg.h>
#include <VG/vgu.h>
#ifndef VG_API_ENTRYP
# define VG_API_ENTRYP VG_API_ENTRY*
#endif
#ifndef VGU_API_ENTRYP
# define VGU_API_ENTRYP VGU_API_ENTRY*
#endif
/*-------------------------------------------------------------------------------
* KHR extensions
*------------------------------------------------------------------------------*/
typedef enum {
#ifndef VG_KHR_iterative_average_blur
VG_MAX_AVERAGE_BLUR_DIMENSION_KHR = 0x116B,
VG_AVERAGE_BLUR_DIMENSION_RESOLUTION_KHR = 0x116C,
VG_MAX_AVERAGE_BLUR_ITERATIONS_KHR = 0x116D,
#endif
VG_PARAM_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM
} VGParamTypeKHR;
#ifndef VG_KHR_EGL_image
#define VG_KHR_EGL_image 1
/* VGEGLImageKHR is an opaque handle to an EGLImage */
typedef void* VGeglImageKHR;
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL VGImage VG_API_ENTRY vgCreateEGLImageTargetKHR(VGeglImageKHR image);
#endif
typedef VGImage (VG_API_ENTRYP PFNVGCREATEEGLIMAGETARGETKHRPROC) (VGeglImageKHR image);
#endif
#ifndef VG_KHR_iterative_average_blur
#define VG_KHR_iterative_average_blur 1
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL void vgIterativeAverageBlurKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode);
#endif
typedef void (VG_API_ENTRYP PFNVGITERATIVEAVERAGEBLURKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode);
#endif
#ifndef VG_KHR_advanced_blending
#define VG_KHR_advanced_blending 1
typedef enum {
VG_BLEND_OVERLAY_KHR = 0x2010,
VG_BLEND_HARDLIGHT_KHR = 0x2011,
VG_BLEND_SOFTLIGHT_SVG_KHR = 0x2012,
VG_BLEND_SOFTLIGHT_KHR = 0x2013,
VG_BLEND_COLORDODGE_KHR = 0x2014,
VG_BLEND_COLORBURN_KHR = 0x2015,
VG_BLEND_DIFFERENCE_KHR = 0x2016,
VG_BLEND_SUBTRACT_KHR = 0x2017,
VG_BLEND_INVERT_KHR = 0x2018,
VG_BLEND_EXCLUSION_KHR = 0x2019,
VG_BLEND_LINEARDODGE_KHR = 0x201a,
VG_BLEND_LINEARBURN_KHR = 0x201b,
VG_BLEND_VIVIDLIGHT_KHR = 0x201c,
VG_BLEND_LINEARLIGHT_KHR = 0x201d,
VG_BLEND_PINLIGHT_KHR = 0x201e,
VG_BLEND_HARDMIX_KHR = 0x201f,
VG_BLEND_CLEAR_KHR = 0x2020,
VG_BLEND_DST_KHR = 0x2021,
VG_BLEND_SRC_OUT_KHR = 0x2022,
VG_BLEND_DST_OUT_KHR = 0x2023,
VG_BLEND_SRC_ATOP_KHR = 0x2024,
VG_BLEND_DST_ATOP_KHR = 0x2025,
VG_BLEND_XOR_KHR = 0x2026,
VG_BLEND_MODE_KHR_FORCE_SIZE= VG_MAX_ENUM
} VGBlendModeKHR;
#endif
#ifndef VG_KHR_parametric_filter
#define VG_KHR_parametric_filter 1
typedef enum {
VG_PF_OBJECT_VISIBLE_FLAG_KHR = (1 << 0),
VG_PF_KNOCKOUT_FLAG_KHR = (1 << 1),
VG_PF_OUTER_FLAG_KHR = (1 << 2),
VG_PF_INNER_FLAG_KHR = (1 << 3),
VG_PF_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM
} VGPfTypeKHR;
typedef enum {
VGU_IMAGE_IN_USE_ERROR = 0xF010,
VGU_ERROR_CODE_KHR_FORCE_SIZE = VG_MAX_ENUM
} VGUErrorCodeKHR;
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL void VG_API_ENTRY vgParametricFilterKHR(VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguDropShadowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA) ;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops);
#endif
typedef void (VG_API_ENTRYP PFNVGPARAMETRICFILTERKHRPROC) (VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUDROPSHADOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops);
#endif
/*-------------------------------------------------------------------------------
* NDS extensions
*------------------------------------------------------------------------------*/
#ifndef VG_NDS_paint_generation
#define VG_NDS_paint_generation 1
typedef enum {
VG_PAINT_COLOR_RAMP_LINEAR_NDS = 0x1A10,
VG_COLOR_MATRIX_NDS = 0x1A11,
VG_PAINT_COLOR_TRANSFORM_LINEAR_NDS = 0x1A12,
VG_PAINT_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGPaintParamTypeNds;
typedef enum {
VG_DRAW_IMAGE_COLOR_MATRIX_NDS = 0x1F10,
VG_IMAGE_MODE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGImageModeNds;
#endif
#ifndef VG_NDS_projective_geometry
#define VG_NDS_projective_geometry 1
typedef enum {
VG_CLIP_MODE_NDS = 0x1180,
VG_CLIP_LINES_NDS = 0x1181,
VG_MAX_CLIP_LINES_NDS = 0x1182,
VG_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGParamTypeNds;
typedef enum {
VG_CLIPMODE_NONE_NDS = 0x3000,
VG_CLIPMODE_CLIP_CLOSED_NDS = 0x3001,
VG_CLIPMODE_CLIP_OPEN_NDS = 0x3002,
VG_CLIPMODE_CULL_NDS = 0x3003,
VG_CLIPMODE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGClipModeNds;
typedef enum {
VG_RQUAD_TO_NDS = ( 13 << 1 ),
VG_RCUBIC_TO_NDS = ( 14 << 1 ),
VG_PATH_SEGMENT_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGPathSegmentNds;
typedef enum {
VG_RQUAD_TO_ABS_NDS = (VG_RQUAD_TO_NDS | VG_ABSOLUTE),
VG_RQUAD_TO_REL_NDS = (VG_RQUAD_TO_NDS | VG_RELATIVE),
VG_RCUBIC_TO_ABS_NDS = (VG_RCUBIC_TO_NDS | VG_ABSOLUTE),
VG_RCUBIC_TO_REL_NDS = (VG_RCUBIC_TO_NDS | VG_RELATIVE),
VG_PATH_COMMAND_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGPathCommandNds;
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL void VG_API_ENTRY vgProjectiveMatrixNDS(VGboolean enable) ;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguTransformClipLineNDS(const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout);
#endif
typedef void (VG_API_ENTRYP PFNVGPROJECTIVEMATRIXNDSPROC) (VGboolean enable) ;
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUTRANSFORMCLIPLINENDSPROC) (const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _VGEXT_H */
/* $Revision: 6810 $ on $Date:: 2008-10-29 07:31:37 -0700 #$ */
/*------------------------------------------------------------------------
*
* VG extensions Reference Implementation
* -------------------------------------
*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and /or associated documentation files
* (the "Materials "), to deal in the Materials without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Materials,
* and to permit persons to whom the Materials are furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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 MATERIALS OR
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
*
*//**
* \file
* \brief VG extensions
*//*-------------------------------------------------------------------*/
#ifndef _VGEXT_H
#define _VGEXT_H
#ifdef __cplusplus
extern "C" {
#endif
#include <VG/openvg.h>
#include <VG/vgu.h>
#ifndef VG_API_ENTRYP
# define VG_API_ENTRYP VG_API_ENTRY*
#endif
#ifndef VGU_API_ENTRYP
# define VGU_API_ENTRYP VGU_API_ENTRY*
#endif
/*-------------------------------------------------------------------------------
* KHR extensions
*------------------------------------------------------------------------------*/
typedef enum {
#ifndef VG_KHR_iterative_average_blur
VG_MAX_AVERAGE_BLUR_DIMENSION_KHR = 0x116B,
VG_AVERAGE_BLUR_DIMENSION_RESOLUTION_KHR = 0x116C,
VG_MAX_AVERAGE_BLUR_ITERATIONS_KHR = 0x116D,
#endif
VG_PARAM_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM
} VGParamTypeKHR;
#ifndef VG_KHR_EGL_image
#define VG_KHR_EGL_image 1
/* VGEGLImageKHR is an opaque handle to an EGLImage */
typedef void* VGeglImageKHR;
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL VGImage VG_API_ENTRY vgCreateEGLImageTargetKHR(VGeglImageKHR image);
#endif
typedef VGImage (VG_API_ENTRYP PFNVGCREATEEGLIMAGETARGETKHRPROC) (VGeglImageKHR image);
#endif
#ifndef VG_KHR_iterative_average_blur
#define VG_KHR_iterative_average_blur 1
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL void vgIterativeAverageBlurKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode);
#endif
typedef void (VG_API_ENTRYP PFNVGITERATIVEAVERAGEBLURKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGTilingMode tilingMode);
#endif
#ifndef VG_KHR_advanced_blending
#define VG_KHR_advanced_blending 1
typedef enum {
VG_BLEND_OVERLAY_KHR = 0x2010,
VG_BLEND_HARDLIGHT_KHR = 0x2011,
VG_BLEND_SOFTLIGHT_SVG_KHR = 0x2012,
VG_BLEND_SOFTLIGHT_KHR = 0x2013,
VG_BLEND_COLORDODGE_KHR = 0x2014,
VG_BLEND_COLORBURN_KHR = 0x2015,
VG_BLEND_DIFFERENCE_KHR = 0x2016,
VG_BLEND_SUBTRACT_KHR = 0x2017,
VG_BLEND_INVERT_KHR = 0x2018,
VG_BLEND_EXCLUSION_KHR = 0x2019,
VG_BLEND_LINEARDODGE_KHR = 0x201a,
VG_BLEND_LINEARBURN_KHR = 0x201b,
VG_BLEND_VIVIDLIGHT_KHR = 0x201c,
VG_BLEND_LINEARLIGHT_KHR = 0x201d,
VG_BLEND_PINLIGHT_KHR = 0x201e,
VG_BLEND_HARDMIX_KHR = 0x201f,
VG_BLEND_CLEAR_KHR = 0x2020,
VG_BLEND_DST_KHR = 0x2021,
VG_BLEND_SRC_OUT_KHR = 0x2022,
VG_BLEND_DST_OUT_KHR = 0x2023,
VG_BLEND_SRC_ATOP_KHR = 0x2024,
VG_BLEND_DST_ATOP_KHR = 0x2025,
VG_BLEND_XOR_KHR = 0x2026,
VG_BLEND_MODE_KHR_FORCE_SIZE= VG_MAX_ENUM
} VGBlendModeKHR;
#endif
#ifndef VG_KHR_parametric_filter
#define VG_KHR_parametric_filter 1
typedef enum {
VG_PF_OBJECT_VISIBLE_FLAG_KHR = (1 << 0),
VG_PF_KNOCKOUT_FLAG_KHR = (1 << 1),
VG_PF_OUTER_FLAG_KHR = (1 << 2),
VG_PF_INNER_FLAG_KHR = (1 << 3),
VG_PF_TYPE_KHR_FORCE_SIZE = VG_MAX_ENUM
} VGPfTypeKHR;
typedef enum {
VGU_IMAGE_IN_USE_ERROR = 0xF010,
VGU_ERROR_CODE_KHR_FORCE_SIZE = VG_MAX_ENUM
} VGUErrorCodeKHR;
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL void VG_API_ENTRY vgParametricFilterKHR(VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguDropShadowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA) ;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientGlowKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops);
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguGradientBevelKHR(VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops);
#endif
typedef void (VG_API_ENTRYP PFNVGPARAMETRICFILTERKHRPROC) (VGImage dst,VGImage src,VGImage blur,VGfloat strength,VGfloat offsetX,VGfloat offsetY,VGbitfield filterFlags,VGPaint highlightPaint,VGPaint shadowPaint);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUDROPSHADOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint shadowColorRGBA);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint glowColorRGBA);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint highlightColorRGBA,VGuint shadowColorRGBA);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTGLOWKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* glowColorRampStops);
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUGRADIENTBEVELKHRPROC) (VGImage dst,VGImage src,VGfloat dimX,VGfloat dimY,VGuint iterative,VGfloat strength,VGfloat distance,VGfloat angle,VGbitfield filterFlags,VGbitfield allowedQuality,VGuint stopsCount,const VGfloat* bevelColorRampStops);
#endif
/*-------------------------------------------------------------------------------
* NDS extensions
*------------------------------------------------------------------------------*/
#ifndef VG_NDS_paint_generation
#define VG_NDS_paint_generation 1
typedef enum {
VG_PAINT_COLOR_RAMP_LINEAR_NDS = 0x1A10,
VG_COLOR_MATRIX_NDS = 0x1A11,
VG_PAINT_COLOR_TRANSFORM_LINEAR_NDS = 0x1A12,
VG_PAINT_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGPaintParamTypeNds;
typedef enum {
VG_DRAW_IMAGE_COLOR_MATRIX_NDS = 0x1F10,
VG_IMAGE_MODE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGImageModeNds;
#endif
#ifndef VG_NDS_projective_geometry
#define VG_NDS_projective_geometry 1
typedef enum {
VG_CLIP_MODE_NDS = 0x1180,
VG_CLIP_LINES_NDS = 0x1181,
VG_MAX_CLIP_LINES_NDS = 0x1182,
VG_PARAM_TYPE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGParamTypeNds;
typedef enum {
VG_CLIPMODE_NONE_NDS = 0x3000,
VG_CLIPMODE_CLIP_CLOSED_NDS = 0x3001,
VG_CLIPMODE_CLIP_OPEN_NDS = 0x3002,
VG_CLIPMODE_CULL_NDS = 0x3003,
VG_CLIPMODE_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGClipModeNds;
typedef enum {
VG_RQUAD_TO_NDS = ( 13 << 1 ),
VG_RCUBIC_TO_NDS = ( 14 << 1 ),
VG_PATH_SEGMENT_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGPathSegmentNds;
typedef enum {
VG_RQUAD_TO_ABS_NDS = (VG_RQUAD_TO_NDS | VG_ABSOLUTE),
VG_RQUAD_TO_REL_NDS = (VG_RQUAD_TO_NDS | VG_RELATIVE),
VG_RCUBIC_TO_ABS_NDS = (VG_RCUBIC_TO_NDS | VG_ABSOLUTE),
VG_RCUBIC_TO_REL_NDS = (VG_RCUBIC_TO_NDS | VG_RELATIVE),
VG_PATH_COMMAND_NDS_FORCE_SIZE = VG_MAX_ENUM
} VGPathCommandNds;
#ifdef VG_VGEXT_PROTOTYPES
VG_API_CALL void VG_API_ENTRY vgProjectiveMatrixNDS(VGboolean enable) ;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguTransformClipLineNDS(const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout);
#endif
typedef void (VG_API_ENTRYP PFNVGPROJECTIVEMATRIXNDSPROC) (VGboolean enable) ;
typedef VGUErrorCode (VGU_API_ENTRYP PFNVGUTRANSFORMCLIPLINENDSPROC) (const VGfloat Ain,const VGfloat Bin,const VGfloat Cin,const VGfloat* matrix,const VGboolean inverse,VGfloat* Aout,VGfloat* Bout,VGfloat* Cout);
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _VGEXT_H */

View file

@ -1,92 +1,92 @@
/* $Revision: 6810 $ on $Date:: 2008-10-29 10:31:37 -0400 #$ */
/*------------------------------------------------------------------------
*
* VG platform specific header Reference Implementation
* ----------------------------------------------------
*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and /or associated documentation files
* (the "Materials "), to deal in the Materials without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Materials,
* and to permit persons to whom the Materials are furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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 MATERIALS OR
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
*
*//**
* \file
* \brief VG platform specific header
*//*-------------------------------------------------------------------*/
#ifndef _VGPLATFORM_H
#define _VGPLATFORM_H
#include <KHR/khrplatform.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef VG_API_CALL
#if defined(OPENVG_STATIC_LIBRARY)
# define VG_API_CALL
#else
# define VG_API_CALL KHRONOS_APICALL
#endif /* defined OPENVG_STATIC_LIBRARY */
#endif /* ifndef VG_API_CALL */
#ifndef VGU_API_CALL
#if defined(OPENVG_STATIC_LIBRARY)
# define VGU_API_CALL
#else
# define VGU_API_CALL KHRONOS_APICALL
#endif /* defined OPENVG_STATIC_LIBRARY */
#endif /* ifndef VGU_API_CALL */
#ifndef VG_API_ENTRY
#define VG_API_ENTRY
#endif
#ifndef VG_API_EXIT
#define VG_API_EXIT
#endif
#ifndef VGU_API_ENTRY
#define VGU_API_ENTRY
#endif
#ifndef VGU_API_EXIT
#define VGU_API_EXIT
#endif
typedef float VGfloat;
typedef signed char VGbyte;
typedef unsigned char VGubyte;
typedef signed short VGshort;
typedef signed int VGint;
typedef unsigned int VGuint;
typedef unsigned int VGbitfield;
#ifndef VG_VGEXT_PROTOTYPES
#define VG_VGEXT_PROTOTYPES
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _VGPLATFORM_H */
/* $Revision: 6810 $ on $Date:: 2008-10-29 07:31:37 -0700 #$ */
/*------------------------------------------------------------------------
*
* VG platform specific header Reference Implementation
* ----------------------------------------------------
*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and /or associated documentation files
* (the "Materials "), to deal in the Materials without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Materials,
* and to permit persons to whom the Materials are furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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 MATERIALS OR
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
*
*//**
* \file
* \brief VG platform specific header
*//*-------------------------------------------------------------------*/
#ifndef _VGPLATFORM_H
#define _VGPLATFORM_H
#include <KHR/khrplatform.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef VG_API_CALL
#if defined(OPENVG_STATIC_LIBRARY)
# define VG_API_CALL
#else
# define VG_API_CALL KHRONOS_APICALL
#endif /* defined OPENVG_STATIC_LIBRARY */
#endif /* ifndef VG_API_CALL */
#ifndef VGU_API_CALL
#if defined(OPENVG_STATIC_LIBRARY)
# define VGU_API_CALL
#else
# define VGU_API_CALL KHRONOS_APICALL
#endif /* defined OPENVG_STATIC_LIBRARY */
#endif /* ifndef VGU_API_CALL */
#ifndef VG_API_ENTRY
#define VG_API_ENTRY
#endif
#ifndef VG_API_EXIT
#define VG_API_EXIT
#endif
#ifndef VGU_API_ENTRY
#define VGU_API_ENTRY
#endif
#ifndef VGU_API_EXIT
#define VGU_API_EXIT
#endif
typedef float VGfloat;
typedef signed char VGbyte;
typedef unsigned char VGubyte;
typedef signed short VGshort;
typedef signed int VGint;
typedef unsigned int VGuint;
typedef unsigned int VGbitfield;
#ifndef VG_VGEXT_PROTOTYPES
#define VG_VGEXT_PROTOTYPES
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* _VGPLATFORM_H */

View file

@ -1,130 +1,131 @@
/* $Revision: 6810 $ on $Date:: 2008-10-29 10:31:37 -0400 #$ */
/*------------------------------------------------------------------------
*
* VGU 1.0.1 Reference Implementation
* -------------------------------------
*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and /or associated documentation files
* (the "Materials "), to deal in the Materials without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Materials,
* and to permit persons to whom the Materials are furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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 MATERIALS OR
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
*
*//**
* \file
* \brief VGU 1.0.1 API.
*//*-------------------------------------------------------------------*/
#ifndef _VGU_H
#define _VGU_H
#ifdef __cplusplus
extern "C" {
#endif
#include <VG/openvg.h>
#define VGU_VERSION_1_0 1
#ifndef VGU_API_CALL
# error VGU_API_CALL must be defined
#endif
#ifndef VGU_API_ENTRY
# error VGU_API_ENTRY must be defined
#endif
#ifndef VGU_API_EXIT
# error VGU_API_EXIT must be defined
#endif
typedef enum {
VGU_NO_ERROR = 0,
VGU_BAD_HANDLE_ERROR = 0xF000,
VGU_ILLEGAL_ARGUMENT_ERROR = 0xF001,
VGU_OUT_OF_MEMORY_ERROR = 0xF002,
VGU_PATH_CAPABILITY_ERROR = 0xF003,
VGU_BAD_WARP_ERROR = 0xF004,
VGU_ERROR_CODE_FORCE_SIZE = VG_MAX_ENUM
} VGUErrorCode;
typedef enum {
VGU_ARC_OPEN = 0xF100,
VGU_ARC_CHORD = 0xF101,
VGU_ARC_PIE = 0xF102,
VGU_ARC_TYPE_FORCE_SIZE = VG_MAX_ENUM
} VGUArcType;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguLine(VGPath path,
VGfloat x0, VGfloat y0,
VGfloat x1, VGfloat y1) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguPolygon(VGPath path,
const VGfloat * points, VGint count,
VGboolean closed) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRect(VGPath path,
VGfloat x, VGfloat y,
VGfloat width, VGfloat height) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRoundRect(VGPath path,
VGfloat x, VGfloat y,
VGfloat width, VGfloat height,
VGfloat arcWidth, VGfloat arcHeight) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguEllipse(VGPath path,
VGfloat cx, VGfloat cy,
VGfloat width, VGfloat height) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguArc(VGPath path,
VGfloat x, VGfloat y,
VGfloat width, VGfloat height,
VGfloat startAngle, VGfloat angleExtent,
VGUArcType arcType) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0,
VGfloat sx1, VGfloat sy1,
VGfloat sx2, VGfloat sy2,
VGfloat sx3, VGfloat sy3,
VGfloat * matrix) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0,
VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2,
VGfloat dx3, VGfloat dy3,
VGfloat * matrix) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0,
VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2,
VGfloat dx3, VGfloat dy3,
VGfloat sx0, VGfloat sy0,
VGfloat sx1, VGfloat sy1,
VGfloat sx2, VGfloat sy2,
VGfloat sx3, VGfloat sy3,
VGfloat * matrix) VGU_API_EXIT;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* #ifndef _VGU_H */
/* $Revision: 6810 $ on $Date:: 2008-10-29 07:31:37 -0700 #$ */
/*------------------------------------------------------------------------
*
* VGU 1.1 Reference Implementation
* -------------------------------------
*
* Copyright (c) 2008 The Khronos Group Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and /or associated documentation files
* (the "Materials "), to deal in the Materials without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Materials,
* and to permit persons to whom the Materials are furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Materials.
*
* THE MATERIALS ARE 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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 MATERIALS OR
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
*
*//**
* \file
* \brief VGU 1.1 API.
*//*-------------------------------------------------------------------*/
#ifndef _VGU_H
#define _VGU_H
#ifdef __cplusplus
extern "C" {
#endif
#include <VG/openvg.h>
#define VGU_VERSION_1_0 1
#define VGU_VERSION_1_1 2
#ifndef VGU_API_CALL
# error VGU_API_CALL must be defined
#endif
#ifndef VGU_API_ENTRY
# error VGU_API_ENTRY must be defined
#endif
#ifndef VGU_API_EXIT
# error VGU_API_EXIT must be defined
#endif
typedef enum {
VGU_NO_ERROR = 0,
VGU_BAD_HANDLE_ERROR = 0xF000,
VGU_ILLEGAL_ARGUMENT_ERROR = 0xF001,
VGU_OUT_OF_MEMORY_ERROR = 0xF002,
VGU_PATH_CAPABILITY_ERROR = 0xF003,
VGU_BAD_WARP_ERROR = 0xF004,
VGU_ERROR_CODE_FORCE_SIZE = VG_MAX_ENUM
} VGUErrorCode;
typedef enum {
VGU_ARC_OPEN = 0xF100,
VGU_ARC_CHORD = 0xF101,
VGU_ARC_PIE = 0xF102,
VGU_ARC_TYPE_FORCE_SIZE = VG_MAX_ENUM
} VGUArcType;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguLine(VGPath path,
VGfloat x0, VGfloat y0,
VGfloat x1, VGfloat y1) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguPolygon(VGPath path,
const VGfloat * points, VGint count,
VGboolean closed) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRect(VGPath path,
VGfloat x, VGfloat y,
VGfloat width, VGfloat height) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguRoundRect(VGPath path,
VGfloat x, VGfloat y,
VGfloat width, VGfloat height,
VGfloat arcWidth, VGfloat arcHeight) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguEllipse(VGPath path,
VGfloat cx, VGfloat cy,
VGfloat width, VGfloat height) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguArc(VGPath path,
VGfloat x, VGfloat y,
VGfloat width, VGfloat height,
VGfloat startAngle, VGfloat angleExtent,
VGUArcType arcType) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToSquare(VGfloat sx0, VGfloat sy0,
VGfloat sx1, VGfloat sy1,
VGfloat sx2, VGfloat sy2,
VGfloat sx3, VGfloat sy3,
VGfloat * matrix) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpSquareToQuad(VGfloat dx0, VGfloat dy0,
VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2,
VGfloat dx3, VGfloat dy3,
VGfloat * matrix) VGU_API_EXIT;
VGU_API_CALL VGUErrorCode VGU_API_ENTRY vguComputeWarpQuadToQuad(VGfloat dx0, VGfloat dy0,
VGfloat dx1, VGfloat dy1,
VGfloat dx2, VGfloat dy2,
VGfloat dx3, VGfloat dy3,
VGfloat sx0, VGfloat sy0,
VGfloat sx1, VGfloat sy1,
VGfloat sx2, VGfloat sy2,
VGfloat sx3, VGfloat sy3,
VGfloat * matrix) VGU_API_EXIT;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* #ifndef _VGU_H */

View file

@ -899,10 +899,20 @@ const int i915_chip_ids[] = {
0x29b2, /* PCI_CHIP_Q35_G */
0x29c2, /* PCI_CHIP_G33_G */
0x29d2, /* PCI_CHIP_Q33_G */
0xa001, /* PCI_CHIP_IGD_G */
0xa011, /* Pineview */
};
const int i965_chip_ids[] = {
0x0042, /* PCI_CHIP_ILD_G */
0x0046, /* PCI_CHIP_ILM_G */
0x0102, /* PCI_CHIP_SANDYBRIDGE_GT1 */
0x0106, /* PCI_CHIP_SANDYBRIDGE_M_GT1 */
0x010a, /* PCI_CHIP_SANDYBRIDGE_S */
0x0112, /* PCI_CHIP_SANDYBRIDGE_GT2 */
0x0116, /* PCI_CHIP_SANDYBRIDGE_M_GT2 */
0x0122, /* PCI_CHIP_SANDYBRIDGE_GT2_PLUS */
0x0126, /* PCI_CHIP_SANDYBRIDGE_M_GT2_PLUS */
0x29a2, /* PCI_CHIP_I965_G */
0x2992, /* PCI_CHIP_I965_Q */
0x2982, /* PCI_CHIP_I965_G_1 */
@ -914,6 +924,8 @@ const int i965_chip_ids[] = {
0x2e12, /* PCI_CHIP_Q45_G */
0x2e22, /* PCI_CHIP_G45_G */
0x2e32, /* PCI_CHIP_G41_G */
0x2e42, /* PCI_CHIP_B43_G */
0x2e92, /* PCI_CHIP_B43_G1 */
};
const int r100_chip_ids[] = {
@ -1636,7 +1648,11 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
dri2_destroy_surface(drv, disp, old_dsurf);
dri2_destroy_surface(drv, disp, old_rsurf);
if (old_ctx) {
dri2_dpy->core->unbindContext(dri2_egl_context(old_ctx)->dri_context);
/* unbind the old context only when there is no new context bound */
if (!ctx) {
__DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
dri2_dpy->core->unbindContext(old_cctx);
}
/* no destroy? */
_eglPutContext(old_ctx);
}

View file

@ -118,38 +118,39 @@ _eglFindArray(_EGLArray *array, void *elem)
/**
* Filter an array and return the filtered data. The returned data pointer
* should be freed.
* Filter an array and return the number of filtered elements.
*/
void **
_eglFilterArray(_EGLArray *array, EGLint *size,
EGLint
_eglFilterArray(_EGLArray *array, void **data, EGLint size,
_EGLArrayForEach filter, void *filter_data)
{
void **data;
EGLint count = 0, i;
if (!array) {
*size = 0;
return malloc(0);
}
data = malloc(array->Size * sizeof(array->Elements[0]));
if (!data)
return NULL;
if (!array)
return 0;
if (filter) {
for (i = 0; i < array->Size; i++) {
if (filter(array->Elements[i], filter_data))
data[count++] = array->Elements[i];
if (filter(array->Elements[i], filter_data)) {
if (data && count < size)
data[count] = array->Elements[i];
count++;
}
if (data && count >= size)
break;
}
}
else {
memcpy(data, array->Elements, array->Size * sizeof(array->Elements[0]));
if (data) {
count = (size < array->Size) ? size : array->Size;
memcpy(data, array->Elements, count * sizeof(array->Elements[0]));
}
else {
count = array->Size;
}
}
*size = count;
return data;
return count;
}

View file

@ -37,8 +37,8 @@ void *
_eglFindArray(_EGLArray *array, void *elem);
PUBLIC void **
_eglFilterArray(_EGLArray *array, EGLint *size,
PUBLIC EGLint
_eglFilterArray(_EGLArray *array, void **data, EGLint size,
_EGLArrayForEach filter, void *filter_data);

View file

@ -697,11 +697,22 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list,
if (!_eglParseConfigAttribList(&criteria, disp, attrib_list))
return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
configList = (_EGLConfig **) _eglFilterArray(disp->Configs, &count,
/* get the number of matched configs */
count = _eglFilterArray(disp->Configs, NULL, 0,
(_EGLArrayForEach) _eglMatchConfig, (void *) &criteria);
if (!count) {
*num_configs = count;
return EGL_TRUE;
}
configList = malloc(sizeof(*configList) * count);
if (!configList)
return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)");
/* get the matched configs */
_eglFilterArray(disp->Configs, (void **) configList, count,
(_EGLArrayForEach) _eglMatchConfig, (void *) &criteria);
/* perform sorting of configs */
if (configs && count) {
_eglSortConfigs((const _EGLConfig **) configList, count,

View file

@ -186,11 +186,22 @@ _eglLoadModule(_EGLModule *mod)
static void
_eglUnloadModule(_EGLModule *mod)
{
#if defined(_EGL_OS_UNIX)
/* destroy the driver */
if (mod->Driver && mod->Driver->Unload)
mod->Driver->Unload(mod->Driver);
/*
* XXX At this point (atexit), the module might be the last reference to
* libEGL. Closing the module might unmap libEGL and give problems.
*/
#if 0
if (mod->Handle)
close_library(mod->Handle);
#endif
#elif defined(_EGL_OS_WINDOWS)
/* XXX Windows unloads DLLs before atexit */
#endif
mod->Driver = NULL;
mod->Handle = NULL;
@ -670,12 +681,7 @@ _eglUnloadDrivers(void)
{
/* this is called at atexit time */
if (_eglModules) {
#if defined(_EGL_OS_UNIX)
_eglDestroyArray(_eglModules, _eglFreeModule);
#elif defined(_EGL_OS_WINDOWS)
/* XXX Windows unloads DLLs before atexit */
_eglDestroyArray(_eglModules, NULL);
#endif
_eglModules = NULL;
}
}

View file

@ -128,12 +128,12 @@ C_SOURCES = \
util/u_linkage.c \
util/u_network.c \
util/u_math.c \
util/u_mempool.c \
util/u_mm.c \
util/u_rect.c \
util/u_ringbuffer.c \
util/u_sampler.c \
util/u_simple_shaders.c \
util/u_slab.c \
util/u_snprintf.c \
util/u_staging.c \
util/u_surface.c \
@ -142,8 +142,7 @@ C_SOURCES = \
util/u_tile.c \
util/u_transfer.c \
util/u_resource.c \
util/u_upload_mgr.c \
target-helpers/wrap_screen.c
util/u_upload_mgr.c
# Disabling until pipe-video branch gets merged in
#vl/vl_bitstream_parser.c \
@ -186,7 +185,7 @@ GALLIVM_SOURCES = \
draw/draw_pt_fetch_shade_pipeline_llvm.c
GALLIVM_CPP_SOURCES = \
gallivm/lp_bld_misc.cpp
gallivm/lp_bld_misc.cpp
GENERATED_SOURCES = \
indices/u_indices_gen.c \
@ -204,9 +203,6 @@ CPP_SOURCES += \
endif
LIBRARY_DEFINES += -D__STDC_CONSTANT_MACROS
include ../Makefile.template

View file

@ -175,13 +175,13 @@ source = [
'util/u_linkage.c',
'util/u_network.c',
'util/u_math.c',
'util/u_mempool.c',
'util/u_mm.c',
'util/u_rect.c',
'util/u_resource.c',
'util/u_ringbuffer.c',
'util/u_sampler.c',
'util/u_simple_shaders.c',
'util/u_slab.c',
'util/u_snprintf.c',
'util/u_staging.c',
'util/u_surface.c',
@ -196,7 +196,6 @@ source = [
#'vl/vl_compositor.c',
#'vl/vl_csc.c',
#'vl/vl_shader_build.c',
'target-helpers/wrap_screen.c',
]
if env['llvm']:

View file

@ -63,19 +63,32 @@ draw_get_option_use_llvm(void)
}
#endif
struct draw_context *draw_create( struct pipe_context *pipe )
/**
* Create new draw module context.
*/
struct draw_context *
draw_create(struct pipe_context *pipe)
{
return draw_create_gallivm(pipe, NULL);
}
/**
* Create new draw module context with gallivm state for LLVM JIT.
*/
struct draw_context *
draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm)
{
struct draw_context *draw = CALLOC_STRUCT( draw_context );
if (draw == NULL)
goto fail;
#if HAVE_LLVM
if(draw_get_option_use_llvm())
{
lp_build_init();
assert(lp_build_engine);
draw->engine = lp_build_engine;
draw->llvm = draw_llvm_create(draw);
if (draw_get_option_use_llvm() && gallivm) {
draw->llvm = draw_llvm_create(draw, gallivm);
}
#endif
@ -91,6 +104,8 @@ fail:
return NULL;
}
boolean draw_init(struct draw_context *draw)
{
/*

View file

@ -48,10 +48,15 @@ struct draw_vertex_shader;
struct draw_geometry_shader;
struct draw_fragment_shader;
struct tgsi_sampler;
struct gallivm_state;
struct draw_context *draw_create( struct pipe_context *pipe );
struct draw_context *
draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm);
void draw_destroy( struct draw_context *draw );
void draw_flush(struct draw_context *draw);

File diff suppressed because it is too large Load diff

View file

@ -103,41 +103,41 @@ struct draw_jit_context
};
#define draw_jit_context_vs_constants(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 0, "vs_constants")
#define draw_jit_context_vs_constants(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 0, "vs_constants")
#define draw_jit_context_gs_constants(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 1, "gs_constants")
#define draw_jit_context_gs_constants(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 1, "gs_constants")
#define draw_jit_context_planes(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 2, "planes")
#define draw_jit_context_planes(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 2, "planes")
#define draw_jit_context_viewport(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 3, "viewport")
#define draw_jit_context_viewport(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 3, "viewport")
#define DRAW_JIT_CTX_TEXTURES 4
#define draw_jit_context_textures(_builder, _ptr) \
lp_build_struct_get_ptr(_builder, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
#define draw_jit_context_textures(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
#define draw_jit_header_id(_builder, _ptr) \
lp_build_struct_get_ptr(_builder, _ptr, 0, "id")
#define draw_jit_header_id(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, 0, "id")
#define draw_jit_header_clip(_builder, _ptr) \
lp_build_struct_get_ptr(_builder, _ptr, 1, "clip")
#define draw_jit_header_clip(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, 1, "clip")
#define draw_jit_header_data(_builder, _ptr) \
lp_build_struct_get_ptr(_builder, _ptr, 2, "data")
#define draw_jit_header_data(_gallivm, _ptr) \
lp_build_struct_get_ptr(_gallivm, _ptr, 2, "data")
#define draw_jit_vbuffer_stride(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 0, "stride")
#define draw_jit_vbuffer_stride(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 0, "stride")
#define draw_jit_vbuffer_max_index(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 1, "max_index")
#define draw_jit_vbuffer_max_index(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 1, "max_index")
#define draw_jit_vbuffer_offset(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 2, "buffer_offset")
#define draw_jit_vbuffer_offset(_gallivm, _ptr) \
lp_build_struct_get(_gallivm, _ptr, 2, "buffer_offset")
typedef int
@ -229,7 +229,6 @@ struct draw_llvm_variant
/* key is variable-sized, must be last */
struct draw_llvm_variant_key key;
/* key is variable-sized, must be last */
};
struct llvm_vertex_shader {
@ -246,21 +245,19 @@ struct draw_llvm {
struct draw_jit_context jit_context;
struct gallivm_state *gallivm;
struct draw_llvm_variant_list_item vs_variants_list;
int nr_variants;
LLVMModuleRef module;
LLVMExecutionEngineRef engine;
LLVMModuleProviderRef provider;
LLVMTargetDataRef target;
LLVMPassManagerRef pass;
/* LLVM JIT builder types */
LLVMTypeRef context_ptr_type;
LLVMTypeRef vertex_header_ptr_type;
LLVMTypeRef buffer_ptr_type;
LLVMTypeRef vb_ptr_type;
LLVMTypeRef vertex_header_ptr_type;
};
static INLINE struct llvm_vertex_shader *
llvm_vertex_shader(struct draw_vertex_shader *vs)
{
@ -269,7 +266,7 @@ llvm_vertex_shader(struct draw_vertex_shader *vs)
struct draw_llvm *
draw_llvm_create(struct draw_context *draw);
draw_llvm_create(struct draw_context *draw, struct gallivm_state *gallivm);
void
draw_llvm_destroy(struct draw_llvm *llvm);
@ -286,7 +283,7 @@ struct draw_llvm_variant_key *
draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store);
LLVMValueRef
draw_llvm_translate_from(LLVMBuilderRef builder,
draw_llvm_translate_from(struct gallivm_state *gallivm,
LLVMValueRef vbuffer,
enum pipe_format from_format);

View file

@ -32,6 +32,7 @@
#include "pipe/p_defines.h"
#include "pipe/p_shader_tokens.h"
#include "gallivm/lp_bld_const.h"
#include "gallivm/lp_bld_debug.h"
#include "gallivm/lp_bld_type.h"
#include "gallivm/lp_bld_sample.h"
@ -84,12 +85,13 @@ struct draw_llvm_sampler_soa
*/
static LLVMValueRef
draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit,
unsigned member_index,
const char *member_name,
boolean emit_load)
{
LLVMBuilderRef builder = gallivm->builder;
struct draw_llvm_sampler_dynamic_state *state =
(struct draw_llvm_sampler_dynamic_state *)base;
LLVMValueRef indices[4];
@ -99,13 +101,13 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
debug_assert(unit < PIPE_MAX_VERTEX_SAMPLERS);
/* context[0] */
indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
indices[0] = lp_build_const_int32(gallivm, 0);
/* context[0].textures */
indices[1] = LLVMConstInt(LLVMInt32Type(), DRAW_JIT_CTX_TEXTURES, 0);
indices[1] = lp_build_const_int32(gallivm, DRAW_JIT_CTX_TEXTURES);
/* context[0].textures[unit] */
indices[2] = LLVMConstInt(LLVMInt32Type(), unit, 0);
indices[2] = lp_build_const_int32(gallivm, unit);
/* context[0].textures[unit].member */
indices[3] = LLVMConstInt(LLVMInt32Type(), member_index, 0);
indices[3] = lp_build_const_int32(gallivm, member_index);
ptr = LLVMBuildGEP(builder, state->context_ptr, indices, Elements(indices), "");
@ -132,10 +134,10 @@ draw_llvm_texture_member(const struct lp_sampler_dynamic_state *base,
#define DRAW_LLVM_TEXTURE_MEMBER(_name, _index, _emit_load) \
static LLVMValueRef \
draw_llvm_texture_##_name( const struct lp_sampler_dynamic_state *base, \
LLVMBuilderRef builder, \
struct gallivm_state *gallivm, \
unsigned unit) \
{ \
return draw_llvm_texture_member(base, builder, unit, _index, #_name, _emit_load ); \
return draw_llvm_texture_member(base, gallivm, unit, _index, #_name, _emit_load ); \
}
@ -165,7 +167,7 @@ draw_llvm_sampler_soa_destroy(struct lp_build_sampler_soa *sampler)
*/
static void
draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
struct lp_type type,
unsigned unit,
unsigned num_coords,
@ -180,7 +182,7 @@ draw_llvm_sampler_soa_emit_fetch_texel(const struct lp_build_sampler_soa *base,
assert(unit < PIPE_MAX_VERTEX_SAMPLERS);
lp_build_sample_soa(builder,
lp_build_sample_soa(gallivm,
&sampler->dynamic_state.static_state[unit],
&sampler->dynamic_state.base,
type,

View file

@ -3,6 +3,7 @@
#include "draw_llvm.h"
#include "gallivm/lp_bld_const.h"
#include "gallivm/lp_bld_struct.h"
#include "gallivm/lp_bld_format.h"
#include "gallivm/lp_bld_debug.h"
@ -16,272 +17,279 @@
#define DRAW_DBG 0
static LLVMValueRef
from_64_float(LLVMBuilderRef builder, LLVMValueRef val)
from_64_float(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMDoubleType(), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
return LLVMBuildFPTrunc(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMDoubleTypeInContext(gallivm->context), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
return LLVMBuildFPTrunc(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static LLVMValueRef
from_32_float(LLVMBuilderRef builder, LLVMValueRef val)
from_32_float(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMFloatType(), 0) , "");
return LLVMBuildLoad(builder, bc, "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0) , "");
return LLVMBuildLoad(gallivm->builder, bc, "");
}
static INLINE LLVMValueRef
from_8_uscaled(LLVMBuilderRef builder, LLVMValueRef val)
from_8_uscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef l = LLVMBuildLoad(builder, val, "");
return LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
from_16_uscaled(LLVMBuilderRef builder, LLVMValueRef val)
from_16_uscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
return LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
from_32_uscaled(LLVMBuilderRef builder, LLVMValueRef val)
from_32_uscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
return LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
return LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
from_8_sscaled(LLVMBuilderRef builder, LLVMValueRef val)
from_8_sscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef l = LLVMBuildLoad(builder, val, "");
return LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
from_16_sscaled(LLVMBuilderRef builder, LLVMValueRef val)
from_16_sscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
return LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
from_32_sscaled(LLVMBuilderRef builder, LLVMValueRef val)
from_32_sscaled(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
return LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
return LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
}
static INLINE LLVMValueRef
from_8_unorm(LLVMBuilderRef builder, LLVMValueRef val)
from_8_unorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef l = LLVMBuildLoad(builder, val, "");
LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
return LLVMBuildFDiv(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 255.), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
return LLVMBuildFDiv(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 255.), "");
}
static INLINE LLVMValueRef
from_16_unorm(LLVMBuilderRef builder, LLVMValueRef val)
from_16_unorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
return LLVMBuildFDiv(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 65535.), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
return LLVMBuildFDiv(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 65535.), "");
}
static INLINE LLVMValueRef
from_32_unorm(LLVMBuilderRef builder, LLVMValueRef val)
from_32_unorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
LLVMValueRef uscaled = LLVMBuildUIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
LLVMValueRef uscaled = LLVMBuildUIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
return LLVMBuildFDiv(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 4294967295.), "");
return LLVMBuildFDiv(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 4294967295.), "");
}
static INLINE LLVMValueRef
from_8_snorm(LLVMBuilderRef builder, LLVMValueRef val)
from_8_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef l = LLVMBuildLoad(builder, val, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
return LLVMBuildFDiv(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 127.0), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
return LLVMBuildFDiv(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 127.0), "");
}
static INLINE LLVMValueRef
from_16_snorm(LLVMBuilderRef builder, LLVMValueRef val)
from_16_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
return LLVMBuildFDiv(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 32767.0f), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 16), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
return LLVMBuildFDiv(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 32767.0f), "");
}
static INLINE LLVMValueRef
from_32_snorm(LLVMBuilderRef builder, LLVMValueRef val)
from_32_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
return LLVMBuildFDiv(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 2147483647.0), "");
return LLVMBuildFDiv(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 2147483647.0), "");
}
static INLINE LLVMValueRef
from_32_fixed(LLVMBuilderRef builder, LLVMValueRef val)
from_32_fixed(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef bc = LLVMBuildBitCast(builder, val,
LLVMPointerType(LLVMIntType(32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(builder, bc, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(builder, l, LLVMFloatType(), "");
LLVMValueRef bc = LLVMBuildBitCast(gallivm->builder, val,
LLVMPointerType(LLVMIntTypeInContext(gallivm->context, 32), 0) , "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, bc, "");
LLVMValueRef uscaled = LLVMBuildSIToFP(gallivm->builder, l, LLVMFloatTypeInContext(gallivm->context), "");
return LLVMBuildFDiv(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 65536.0), "");
return LLVMBuildFDiv(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 65536.0), "");
}
static LLVMValueRef
to_64_float(LLVMBuilderRef builder, LLVMValueRef fp)
to_64_float(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
return LLVMBuildFPExt(builder, l, LLVMDoubleType(), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
return LLVMBuildFPExt(gallivm->builder, l, LLVMDoubleTypeInContext(gallivm->context), "");
}
static LLVMValueRef
to_32_float(LLVMBuilderRef builder, LLVMValueRef fp)
to_32_float(struct gallivm_state *gallivm, LLVMValueRef fp)
{
return LLVMBuildLoad(builder, fp, "");
return LLVMBuildLoad(gallivm->builder, fp, "");
}
static INLINE LLVMValueRef
to_8_uscaled(LLVMBuilderRef builder, LLVMValueRef fp)
to_8_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
return LLVMBuildFPToUI(builder, l, LLVMIntType(8), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 8), "");
}
static INLINE LLVMValueRef
to_16_uscaled(LLVMBuilderRef builder, LLVMValueRef fp)
to_16_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
return LLVMBuildFPToUI(builder, l, LLVMIntType(16), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 16), "");
}
static INLINE LLVMValueRef
to_32_uscaled(LLVMBuilderRef builder, LLVMValueRef fp)
to_32_uscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
return LLVMBuildFPToUI(builder, l, LLVMIntType(32), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
return LLVMBuildFPToUI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 32), "");
}
static INLINE LLVMValueRef
to_8_sscaled(LLVMBuilderRef builder, LLVMValueRef fp)
to_8_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
return LLVMBuildFPToSI(builder, l, LLVMIntType(8), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 8), "");
}
static INLINE LLVMValueRef
to_16_sscaled(LLVMBuilderRef builder, LLVMValueRef fp)
to_16_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
return LLVMBuildFPToSI(builder, l, LLVMIntType(16), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 16), "");
}
static INLINE LLVMValueRef
to_32_sscaled(LLVMBuilderRef builder, LLVMValueRef fp)
to_32_sscaled(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
return LLVMBuildFPToSI(builder, l, LLVMIntType(32), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
return LLVMBuildFPToSI(gallivm->builder, l, LLVMIntTypeInContext(gallivm->context, 32), "");
}
static INLINE LLVMValueRef
to_8_unorm(LLVMBuilderRef builder, LLVMValueRef fp)
to_8_unorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(8), "");
return LLVMBuildFMul(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 255.), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l,
LLVMIntTypeInContext(gallivm->context, 8), "");
return LLVMBuildFMul(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 255.), "");
}
static INLINE LLVMValueRef
to_16_unorm(LLVMBuilderRef builder, LLVMValueRef fp)
to_16_unorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), "");
return LLVMBuildFMul(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 65535.), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l,
LLVMIntTypeInContext(gallivm->context, 32), "");
return LLVMBuildFMul(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 65535.), "");
}
static INLINE LLVMValueRef
to_32_unorm(LLVMBuilderRef builder, LLVMValueRef fp)
to_32_unorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToUI(builder, l, LLVMIntType(32), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToUI(gallivm->builder, l,
LLVMIntTypeInContext(gallivm->context, 32), "");
return LLVMBuildFMul(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 4294967295.), "");
return LLVMBuildFMul(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 4294967295.), "");
}
static INLINE LLVMValueRef
to_8_snorm(LLVMBuilderRef builder, LLVMValueRef val)
to_8_snorm(struct gallivm_state *gallivm, LLVMValueRef val)
{
LLVMValueRef l = LLVMBuildLoad(builder, val, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(8), "");
return LLVMBuildFMul(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 127.0), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, val, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
LLVMIntTypeInContext(gallivm->context, 8), "");
return LLVMBuildFMul(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 127.0), "");
}
static INLINE LLVMValueRef
to_16_snorm(LLVMBuilderRef builder, LLVMValueRef fp)
to_16_snorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(16), "");
return LLVMBuildFMul(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 32767.0f), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
LLVMIntTypeInContext(gallivm->context, 16), "");
return LLVMBuildFMul(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 32767.0f), "");
}
static INLINE LLVMValueRef
to_32_snorm(LLVMBuilderRef builder, LLVMValueRef fp)
to_32_snorm(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
LLVMIntTypeInContext(gallivm->context, 32), "");
return LLVMBuildFMul(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 2147483647.0), "");
return LLVMBuildFMul(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 2147483647.0), "");
}
static INLINE LLVMValueRef
to_32_fixed(LLVMBuilderRef builder, LLVMValueRef fp)
to_32_fixed(struct gallivm_state *gallivm, LLVMValueRef fp)
{
LLVMValueRef l = LLVMBuildLoad(builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(builder, l, LLVMIntType(32), "");
LLVMValueRef l = LLVMBuildLoad(gallivm->builder, fp, "");
LLVMValueRef uscaled = LLVMBuildFPToSI(gallivm->builder, l,
LLVMIntTypeInContext(gallivm->context, 32), "");
return LLVMBuildFMul(builder, uscaled,
LLVMConstReal(LLVMFloatType(), 65536.0), "");
return LLVMBuildFMul(gallivm->builder, uscaled,
lp_build_const_float(gallivm, 65536.0), "");
}
typedef LLVMValueRef (*from_func)(LLVMBuilderRef, LLVMValueRef);
typedef LLVMValueRef (*to_func)(LLVMBuilderRef, LLVMValueRef);
typedef LLVMValueRef (*from_func)(struct gallivm_state *, LLVMValueRef);
typedef LLVMValueRef (*to_func)(struct gallivm_state *, LLVMValueRef);
/* so that underneath can avoid function calls which are prohibited
* for static initialization we need this conversion */
@ -294,21 +302,21 @@ enum ll_type {
};
static INLINE LLVMTypeRef
ll_type_to_llvm(enum ll_type type)
ll_type_to_llvm(struct gallivm_state *gallivm, enum ll_type type)
{
switch (type) {
case LL_Double:
return LLVMDoubleType();
return LLVMDoubleTypeInContext(gallivm->context);
case LL_Float:
return LLVMFloatType();
return LLVMFloatTypeInContext(gallivm->context);
case LL_Int32:
return LLVMInt32Type();
return LLVMInt32TypeInContext(gallivm->context);
case LL_Int16:
return LLVMIntType(16);
return LLVMIntTypeInContext(gallivm->context, 16);
case LL_Int8:
return LLVMIntType(8);
return LLVMIntTypeInContext(gallivm->context, 8);
}
return LLVMIntType(8);
return LLVMIntTypeInContext(gallivm->context, 8);
}
static INLINE int
@ -414,42 +422,42 @@ struct draw_llvm_translate {
static LLVMValueRef
fetch(LLVMBuilderRef builder,
fetch(struct gallivm_state *gallivm,
LLVMValueRef ptr, int val_size, int nr_components,
from_func func)
{
int i;
int offset = 0;
LLVMValueRef res = LLVMConstNull(
LLVMVectorType(LLVMFloatType(), 4));
LLVMValueRef res =
LLVMConstNull(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4));
LLVMValueRef defaults[4];
defaults[0] = LLVMConstReal(LLVMFloatType(), 0);
defaults[1] = LLVMConstReal(LLVMFloatType(), 0);
defaults[2] = LLVMConstReal(LLVMFloatType(), 0);
defaults[3] = LLVMConstReal(LLVMFloatType(), 1);
defaults[0] =
defaults[1] =
defaults[2] = lp_build_const_float(gallivm, 0.0);
defaults[3] = lp_build_const_float(gallivm, 1.0);
for (i = 0; i < nr_components; ++i) {
LLVMValueRef src_index = LLVMConstInt(LLVMInt32Type(), offset, 0);
LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef src_index = lp_build_const_int32(gallivm, offset);
LLVMValueRef dst_index = lp_build_const_int32(gallivm, i);
LLVMValueRef src_tmp;
LLVMValueRef component;
src_tmp = LLVMBuildGEP(builder, ptr, &src_index, 1, "src_tmp");
src_tmp = LLVMBuildGEP(gallivm->builder, ptr, &src_index, 1, "src_tmp");
/* convert src_tmp to float */
component = func(builder, src_tmp);
component = func(gallivm, src_tmp);
/* vec.comp = component */
res = LLVMBuildInsertElement(builder,
res = LLVMBuildInsertElement(gallivm->builder,
res,
component,
dst_index, "");
offset += val_size;
}
for (; i < 4; ++i) {
LLVMValueRef dst_index = LLVMConstInt(LLVMInt32Type(), i, 0);
res = LLVMBuildInsertElement(builder,
LLVMValueRef dst_index = lp_build_const_int32(gallivm, i);
res = LLVMBuildInsertElement(gallivm->builder,
res,
defaults[i],
dst_index, "");
@ -459,7 +467,7 @@ fetch(LLVMBuilderRef builder,
LLVMValueRef
draw_llvm_translate_from(LLVMBuilderRef builder,
draw_llvm_translate_from(struct gallivm_state *gallivm,
LLVMValueRef vbuffer,
enum pipe_format from_format)
{
@ -476,7 +484,7 @@ draw_llvm_translate_from(LLVMBuilderRef builder,
for (i = 0; i < Elements(translates); ++i) {
if (translates[i].format == from_format) {
/*LLVMTypeRef type = ll_type_to_llvm(translates[i].type);*/
return fetch(builder,
return fetch(gallivm,
vbuffer,
ll_type_size(translates[i].type),
translates[i].num_components,
@ -493,6 +501,6 @@ draw_llvm_translate_from(LLVMBuilderRef builder,
*/
format_desc = util_format_description(from_format);
zero = LLVMConstNull(LLVMInt32Type());
return lp_build_fetch_rgba_aos(builder, format_desc, type, vbuffer, zero, zero, zero);
zero = LLVMConstNull(LLVMInt32TypeInContext(gallivm->context));
return lp_build_fetch_rgba_aos(gallivm, format_desc, type, vbuffer, zero, zero, zero);
}

View file

@ -406,6 +406,7 @@ aaline_create_texture(struct aaline_stage *aaline)
texTemp.width0 = 1 << MAX_TEXTURE_LEVEL;
texTemp.height0 = 1 << MAX_TEXTURE_LEVEL;
texTemp.depth0 = 1;
texTemp.array_size = 1;
texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
aaline->texture = screen->resource_create(screen, &texTemp);
@ -441,10 +442,10 @@ aaline_create_texture(struct aaline_stage *aaline)
/* This texture is new, no need to flush.
*/
transfer = pipe->get_transfer(pipe,
aaline->texture,
u_subresource(0, level),
PIPE_TRANSFER_WRITE,
&box);
aaline->texture,
level,
PIPE_TRANSFER_WRITE,
&box);
data = pipe->transfer_map(pipe, transfer);
if (data == NULL)

View file

@ -393,8 +393,8 @@ pstip_update_texture(struct pstip_stage *pstip)
*/
pipe->flush( pipe, PIPE_FLUSH_TEXTURE_CACHE, NULL );
transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0, 0,
PIPE_TRANSFER_WRITE, 0, 0, 32, 32);
transfer = pipe_get_transfer(pipe, pstip->texture, 0, 0,
PIPE_TRANSFER_WRITE, 0, 0, 32, 32);
data = pipe->transfer_map(pipe, transfer);
/*
@ -440,6 +440,7 @@ pstip_create_texture(struct pstip_stage *pstip)
texTemp.width0 = 32;
texTemp.height0 = 32;
texTemp.depth0 = 1;
texTemp.array_size = 1;
texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
pstip->texture = screen->resource_create(screen, &texTemp);

View file

@ -286,7 +286,6 @@ struct draw_context
#ifdef HAVE_LLVM
struct draw_llvm *llvm;
LLVMExecutionEngineRef engine;
#endif
struct pipe_sampler_view *sampler_views[PIPE_MAX_VERTEX_SAMPLERS];

View file

@ -58,8 +58,8 @@ struct fetch_shade_emit {
const ubyte *src[PIPE_MAX_ATTRIBS];
unsigned prim;
struct draw_vs_varient_key key;
struct draw_vs_varient *active;
struct draw_vs_variant_key key;
struct draw_vs_variant *active;
const struct vertex_info *vinfo;
@ -150,7 +150,7 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
}
fse->active = draw_vs_lookup_varient( draw->vs.vertex_shader,
fse->active = draw_vs_lookup_variant( draw->vs.vertex_shader,
&fse->key );
if (!fse->active) {

View file

@ -34,6 +34,7 @@
#include "draw/draw_pt.h"
#include "draw/draw_vs.h"
#include "draw/draw_llvm.h"
#include "gallivm/lp_bld_init.h"
struct llvm_middle_end {
@ -72,19 +73,18 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
struct draw_llvm_variant_list_item *li;
unsigned i;
unsigned instance_id_index = ~0;
unsigned out_prim = (draw->gs.geometry_shader ?
draw->gs.geometry_shader->output_primitive :
in_prim);
const unsigned out_prim = (draw->gs.geometry_shader ?
draw->gs.geometry_shader->output_primitive :
in_prim);
/* Add one to num_outputs because the pipeline occasionally tags on
* an additional texcoord, eg for AA lines.
*/
unsigned nr = MAX2( shader->base.info.num_inputs,
shader->base.info.num_outputs + 1 );
const unsigned nr = MAX2( shader->base.info.num_inputs,
shader->base.info.num_outputs + 1 );
/* Scan for instanceID system value.
* XXX but we never use instance_id_index?!
*/
for (i = 0; i < shader->base.info.num_inputs; i++) {
if (shader->base.info.input_semantic_name[i] == TGSI_SEMANTIC_INSTANCEID) {
@ -133,9 +133,10 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
key = draw_llvm_make_variant_key(fpme->llvm, store);
/* Search shader's list of variants for the key */
li = first_elem(&shader->variants);
while(!at_end(&shader->variants, li)) {
if(memcmp(&li->base->key, key, shader->variant_key_size) == 0) {
while (!at_end(&shader->variants, li)) {
if (memcmp(&li->base->key, key, shader->variant_key_size) == 0) {
variant = li->base;
break;
}
@ -143,10 +144,16 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
}
if (variant) {
/* found the variant, move to head of global list (for LRU) */
move_to_head(&fpme->llvm->vs_variants_list, &variant->list_item_global);
}
else {
/* Need to create new variant */
unsigned i;
/* First check if we've created too many variants. If so, free
* 25% of the LRU to avoid using too much memory.
*/
if (fpme->llvm->nr_variants >= DRAW_MAX_SHADER_VARIANTS) {
/*
* XXX: should we flush here ?
@ -422,7 +429,7 @@ draw_pt_fetch_pipeline_or_emit_llvm(struct draw_context *draw)
{
struct llvm_middle_end *fpme = 0;
if (!draw->engine)
if (!draw->llvm->gallivm->engine)
return NULL;
fpme = CALLOC_STRUCT( llvm_middle_end );

View file

@ -165,10 +165,10 @@ draw_delete_vertex_shader(struct draw_context *draw,
{
unsigned i;
for (i = 0; i < dvs->nr_varients; i++)
dvs->varient[i]->destroy( dvs->varient[i] );
for (i = 0; i < dvs->nr_variants; i++)
dvs->variant[i]->destroy( dvs->variant[i] );
dvs->nr_varients = 0;
dvs->nr_variants = 0;
dvs->delete( dvs );
}
@ -225,40 +225,40 @@ draw_vs_destroy( struct draw_context *draw )
}
struct draw_vs_varient *
draw_vs_lookup_varient( struct draw_vertex_shader *vs,
const struct draw_vs_varient_key *key )
struct draw_vs_variant *
draw_vs_lookup_variant( struct draw_vertex_shader *vs,
const struct draw_vs_variant_key *key )
{
struct draw_vs_varient *varient;
struct draw_vs_variant *variant;
unsigned i;
/* Lookup existing varient:
/* Lookup existing variant:
*/
for (i = 0; i < vs->nr_varients; i++)
if (draw_vs_varient_key_compare(key, &vs->varient[i]->key) == 0)
return vs->varient[i];
for (i = 0; i < vs->nr_variants; i++)
if (draw_vs_variant_key_compare(key, &vs->variant[i]->key) == 0)
return vs->variant[i];
/* Else have to create a new one:
*/
varient = vs->create_varient( vs, key );
if (varient == NULL)
variant = vs->create_variant( vs, key );
if (variant == NULL)
return NULL;
/* Add it to our list, could be smarter:
*/
if (vs->nr_varients < Elements(vs->varient)) {
vs->varient[vs->nr_varients++] = varient;
if (vs->nr_variants < Elements(vs->variant)) {
vs->variant[vs->nr_variants++] = variant;
}
else {
vs->last_varient++;
vs->last_varient %= Elements(vs->varient);
vs->varient[vs->last_varient]->destroy(vs->varient[vs->last_varient]);
vs->varient[vs->last_varient] = varient;
vs->last_variant++;
vs->last_variant %= Elements(vs->variant);
vs->variant[vs->last_variant]->destroy(vs->variant[vs->last_variant]);
vs->variant[vs->last_variant] = variant;
}
/* Done
*/
return varient;
return variant;
}

View file

@ -38,7 +38,7 @@
struct draw_context;
struct pipe_shader_state;
struct draw_varient_input
struct draw_variant_input
{
enum pipe_format format;
unsigned buffer;
@ -46,19 +46,19 @@ struct draw_varient_input
unsigned instance_divisor;
};
struct draw_varient_output
struct draw_variant_output
{
enum pipe_format format; /* output format */
unsigned vs_output:8; /* which vertex shader output is this? */
unsigned offset:24; /* offset into output vertex */
};
struct draw_varient_element {
struct draw_varient_input in;
struct draw_varient_output out;
struct draw_variant_element {
struct draw_variant_input in;
struct draw_variant_output out;
};
struct draw_vs_varient_key {
struct draw_vs_variant_key {
unsigned output_stride;
unsigned nr_elements:8; /* max2(nr_inputs, nr_outputs) */
unsigned nr_inputs:8;
@ -66,34 +66,34 @@ struct draw_vs_varient_key {
unsigned viewport:1;
unsigned clip:1;
unsigned const_vbuffers:5;
struct draw_varient_element element[PIPE_MAX_ATTRIBS];
struct draw_variant_element element[PIPE_MAX_ATTRIBS];
};
struct draw_vs_varient;
struct draw_vs_variant;
struct draw_vs_varient {
struct draw_vs_varient_key key;
struct draw_vs_variant {
struct draw_vs_variant_key key;
struct draw_vertex_shader *vs;
void (*set_buffer)( struct draw_vs_varient *,
void (*set_buffer)( struct draw_vs_variant *,
unsigned i,
const void *ptr,
unsigned stride,
unsigned max_stride );
void (PIPE_CDECL *run_linear)( struct draw_vs_varient *shader,
void (PIPE_CDECL *run_linear)( struct draw_vs_variant *shader,
unsigned start,
unsigned count,
void *output_buffer );
void (PIPE_CDECL *run_elts)( struct draw_vs_varient *shader,
void (PIPE_CDECL *run_elts)( struct draw_vs_variant *shader,
const unsigned *elts,
unsigned count,
void *output_buffer );
void (*destroy)( struct draw_vs_varient * );
void (*destroy)( struct draw_vs_variant * );
};
@ -117,11 +117,11 @@ struct draw_vertex_shader {
/*
*/
struct draw_vs_varient *varient[16];
unsigned nr_varients;
unsigned last_varient;
struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader,
const struct draw_vs_varient_key *key );
struct draw_vs_variant *variant[16];
unsigned nr_variants;
unsigned last_variant;
struct draw_vs_variant *(*create_variant)( struct draw_vertex_shader *shader,
const struct draw_vs_variant_key *key );
void (*prepare)( struct draw_vertex_shader *shader,
@ -144,9 +144,9 @@ struct draw_vertex_shader {
};
struct draw_vs_varient *
draw_vs_lookup_varient( struct draw_vertex_shader *base,
const struct draw_vs_varient_key *key );
struct draw_vs_variant *
draw_vs_lookup_variant( struct draw_vertex_shader *base,
const struct draw_vs_variant_key *key );
/********************************************************************************
@ -166,12 +166,12 @@ draw_create_vs_ppc(struct draw_context *draw,
const struct pipe_shader_state *templ);
struct draw_vs_varient_key;
struct draw_vs_variant_key;
struct draw_vertex_shader;
struct draw_vs_varient *
draw_vs_create_varient_aos_sse( struct draw_vertex_shader *vs,
const struct draw_vs_varient_key *key );
struct draw_vs_variant *
draw_vs_create_variant_aos_sse( struct draw_vertex_shader *vs,
const struct draw_vs_variant_key *key );
#if HAVE_LLVM
struct draw_vertex_shader *
@ -181,7 +181,7 @@ draw_create_vs_llvm(struct draw_context *draw,
/********************************************************************************
* Helpers for vs implementations that don't do their own fetch/emit varients.
* Helpers for vs implementations that don't do their own fetch/emit variants.
* Means these can be shared between shaders.
*/
struct translate;
@ -194,21 +194,21 @@ struct translate *draw_vs_get_fetch( struct draw_context *draw,
struct translate *draw_vs_get_emit( struct draw_context *draw,
struct translate_key *key );
struct draw_vs_varient *
draw_vs_create_varient_generic( struct draw_vertex_shader *vs,
const struct draw_vs_varient_key *key );
struct draw_vs_variant *
draw_vs_create_variant_generic( struct draw_vertex_shader *vs,
const struct draw_vs_variant_key *key );
static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key )
static INLINE int draw_vs_variant_keysize( const struct draw_vs_variant_key *key )
{
return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_varient_element);
return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_variant_element);
}
static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a,
const struct draw_vs_varient_key *b )
static INLINE int draw_vs_variant_key_compare( const struct draw_vs_variant_key *a,
const struct draw_vs_variant_key *b )
{
int keysize = draw_vs_varient_keysize(a);
int keysize = draw_vs_variant_keysize(a);
return memcmp(a, b, keysize);
}

View file

@ -1918,7 +1918,7 @@ static void find_last_write_outputs( struct aos_compilation *cp )
#define ARG_OUTBUF 4
static boolean build_vertex_program( struct draw_vs_varient_aos_sse *varient,
static boolean build_vertex_program( struct draw_vs_variant_aos_sse *variant,
boolean linear )
{
struct tgsi_parse_context parse;
@ -1927,14 +1927,14 @@ static boolean build_vertex_program( struct draw_vs_varient_aos_sse *varient,
util_init_math();
tgsi_parse_init( &parse, varient->base.vs->state.tokens );
tgsi_parse_init( &parse, variant->base.vs->state.tokens );
memset(&cp, 0, sizeof(cp));
cp.insn_counter = 1;
cp.vaos = varient;
cp.vaos = variant;
cp.have_sse2 = 1;
cp.func = &varient->func[ linear ? 0 : 1 ];
cp.func = &variant->func[ linear ? 0 : 1 ];
cp.tmp_EAX = x86_make_reg(file_REG32, reg_AX);
cp.idx_EBX = x86_make_reg(file_REG32, reg_BX);
@ -2090,20 +2090,20 @@ static boolean build_vertex_program( struct draw_vs_varient_aos_sse *varient,
/** cast wrapper */
static INLINE struct draw_vs_varient_aos_sse *
draw_vs_varient_aos_sse(struct draw_vs_varient *varient)
static INLINE struct draw_vs_variant_aos_sse *
draw_vs_variant_aos_sse(struct draw_vs_variant *variant)
{
return (struct draw_vs_varient_aos_sse *) varient;
return (struct draw_vs_variant_aos_sse *) variant;
}
static void vaos_set_buffer( struct draw_vs_varient *varient,
static void vaos_set_buffer( struct draw_vs_variant *variant,
unsigned buf,
const void *ptr,
unsigned stride,
unsigned max_stride)
{
struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
if (buf < vaos->nr_vb) {
vaos->buffer[buf].base_ptr = (char *)ptr;
@ -2115,12 +2115,12 @@ static void vaos_set_buffer( struct draw_vs_varient *varient,
static void PIPE_CDECL vaos_run_elts( struct draw_vs_varient *varient,
static void PIPE_CDECL vaos_run_elts( struct draw_vs_variant *variant,
const unsigned *elts,
unsigned count,
void *output_buffer )
{
struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
struct aos_machine *machine = vaos->draw->vs.aos_machine;
unsigned i;
@ -2139,12 +2139,12 @@ static void PIPE_CDECL vaos_run_elts( struct draw_vs_varient *varient,
output_buffer );
}
static void PIPE_CDECL vaos_run_linear( struct draw_vs_varient *varient,
static void PIPE_CDECL vaos_run_linear( struct draw_vs_variant *variant,
unsigned start,
unsigned count,
void *output_buffer )
{
struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
struct aos_machine *machine = vaos->draw->vs.aos_machine;
unsigned i;
@ -2171,9 +2171,9 @@ static void PIPE_CDECL vaos_run_linear( struct draw_vs_varient *varient,
static void vaos_destroy( struct draw_vs_varient *varient )
static void vaos_destroy( struct draw_vs_variant *variant )
{
struct draw_vs_varient_aos_sse *vaos = draw_vs_varient_aos_sse(varient);
struct draw_vs_variant_aos_sse *vaos = draw_vs_variant_aos_sse(variant);
FREE( vaos->buffer );
@ -2185,11 +2185,11 @@ static void vaos_destroy( struct draw_vs_varient *varient )
static struct draw_vs_varient *varient_aos_sse( struct draw_vertex_shader *vs,
const struct draw_vs_varient_key *key )
static struct draw_vs_variant *variant_aos_sse( struct draw_vertex_shader *vs,
const struct draw_vs_variant_key *key )
{
unsigned i;
struct draw_vs_varient_aos_sse *vaos = CALLOC_STRUCT(draw_vs_varient_aos_sse);
struct draw_vs_variant_aos_sse *vaos = CALLOC_STRUCT(draw_vs_variant_aos_sse);
if (!vaos)
goto fail;
@ -2249,17 +2249,17 @@ static struct draw_vs_varient *varient_aos_sse( struct draw_vertex_shader *vs,
}
struct draw_vs_varient *
draw_vs_create_varient_aos_sse( struct draw_vertex_shader *vs,
const struct draw_vs_varient_key *key )
struct draw_vs_variant *
draw_vs_create_variant_aos_sse( struct draw_vertex_shader *vs,
const struct draw_vs_variant_key *key )
{
struct draw_vs_varient *varient = varient_aos_sse( vs, key );
struct draw_vs_variant *variant = variant_aos_sse( vs, key );
if (varient == NULL) {
varient = draw_vs_create_varient_generic( vs, key );
if (variant == NULL) {
variant = draw_vs_create_variant_generic( vs, key );
}
return varient;
return variant;
}

View file

@ -98,9 +98,9 @@ struct aos_buffer {
/* This is the temporary storage used by all the aos_sse vs varients.
/* This is the temporary storage used by all the aos_sse vs variants.
* Create one per context and reuse by passing a pointer in at
* vs_varient creation??
* vs_variant creation??
*/
struct aos_machine {
float input [MAX_INPUTS ][4];
@ -134,7 +134,7 @@ struct aos_machine {
struct aos_compilation {
struct x86_function *func;
struct draw_vs_varient_aos_sse *vaos;
struct draw_vs_variant_aos_sse *vaos;
unsigned insn_counter;
unsigned num_immediates;
@ -234,8 +234,8 @@ typedef void (PIPE_CDECL *vaos_run_linear_func)( struct aos_machine *,
void *output_buffer);
struct draw_vs_varient_aos_sse {
struct draw_vs_varient base;
struct draw_vs_variant_aos_sse {
struct draw_vs_variant base;
struct draw_context *draw;
struct aos_buffer *buffer;

View file

@ -203,7 +203,7 @@ draw_create_vs_exec(struct draw_context *draw,
vs->base.prepare = vs_exec_prepare;
vs->base.run_linear = vs_exec_run_linear;
vs->base.delete = vs_exec_delete;
vs->base.create_varient = draw_vs_create_varient_generic;
vs->base.create_variant = draw_vs_create_variant_generic;
vs->machine = draw->vs.machine;
return &vs->base;

View file

@ -65,19 +65,7 @@ static void
vs_llvm_delete( struct draw_vertex_shader *dvs )
{
struct llvm_vertex_shader *shader = llvm_vertex_shader(dvs);
struct pipe_fence_handle *fence = NULL;
struct draw_llvm_variant_list_item *li;
struct pipe_context *pipe = dvs->draw->pipe;
/*
* XXX: This might be not neccessary at all.
*/
pipe->flush(pipe, 0, &fence);
if (fence) {
pipe->screen->fence_finish(pipe->screen, fence, 0);
pipe->screen->fence_reference(pipe->screen, &fence, NULL);
}
li = first_elem(&shader->variants);
while(!at_end(&shader->variants, li)) {
@ -119,7 +107,7 @@ draw_create_vs_llvm(struct draw_context *draw,
vs->base.prepare = vs_llvm_prepare;
vs->base.run_linear = vs_llvm_run_linear;
vs->base.delete = vs_llvm_delete;
vs->base.create_varient = draw_vs_create_varient_generic;
vs->base.create_variant = draw_vs_create_variant_generic;
make_empty_list(&vs->variants);

View file

@ -187,10 +187,10 @@ draw_create_vs_ppc(struct draw_context *draw,
vs->base.draw = draw;
#if 0
if (1)
vs->base.create_varient = draw_vs_varient_aos_ppc;
vs->base.create_variant = draw_vs_variant_aos_ppc;
else
#endif
vs->base.create_varient = draw_vs_create_varient_generic;
vs->base.create_variant = draw_vs_create_variant_generic;
vs->base.prepare = vs_ppc_prepare;
vs->base.run_linear = vs_ppc_run_linear;
vs->base.delete = vs_ppc_delete;

View file

@ -166,9 +166,9 @@ draw_create_vs_sse(struct draw_context *draw,
vs->base.draw = draw;
if (1)
vs->base.create_varient = draw_vs_create_varient_aos_sse;
vs->base.create_variant = draw_vs_create_variant_aos_sse;
else
vs->base.create_varient = draw_vs_create_varient_generic;
vs->base.create_variant = draw_vs_create_variant_generic;
vs->base.prepare = vs_sse_prepare;
vs->base.run_linear = vs_sse_run_linear;
vs->base.delete = vs_sse_delete;

View file

@ -41,8 +41,8 @@
/* A first pass at incorporating vertex fetch/emit functionality into
*/
struct draw_vs_varient_generic {
struct draw_vs_varient base;
struct draw_vs_variant_generic {
struct draw_vs_variant base;
struct draw_vertex_shader *shader;
struct draw_context *draw;
@ -63,13 +63,13 @@ struct draw_vs_varient_generic {
static void vsvg_set_buffer( struct draw_vs_varient *varient,
static void vsvg_set_buffer( struct draw_vs_variant *variant,
unsigned buffer,
const void *ptr,
unsigned stride,
unsigned max_index )
{
struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant;
vsvg->fetch->set_buffer(vsvg->fetch,
buffer,
@ -81,7 +81,7 @@ static void vsvg_set_buffer( struct draw_vs_varient *varient,
/* Mainly for debug at this stage:
*/
static void do_rhw_viewport( struct draw_vs_varient_generic *vsvg,
static void do_rhw_viewport( struct draw_vs_variant_generic *vsvg,
unsigned count,
void *output_buffer )
{
@ -104,7 +104,7 @@ static void do_rhw_viewport( struct draw_vs_varient_generic *vsvg,
}
}
static void do_viewport( struct draw_vs_varient_generic *vsvg,
static void do_viewport( struct draw_vs_variant_generic *vsvg,
unsigned count,
void *output_buffer )
{
@ -126,12 +126,12 @@ static void do_viewport( struct draw_vs_varient_generic *vsvg,
}
static void PIPE_CDECL vsvg_run_elts( struct draw_vs_varient *varient,
static void PIPE_CDECL vsvg_run_elts( struct draw_vs_variant *variant,
const unsigned *elts,
unsigned count,
void *output_buffer)
{
struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant;
unsigned temp_vertex_stride = vsvg->temp_vertex_stride;
void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride );
@ -193,12 +193,12 @@ static void PIPE_CDECL vsvg_run_elts( struct draw_vs_varient *varient,
}
static void PIPE_CDECL vsvg_run_linear( struct draw_vs_varient *varient,
static void PIPE_CDECL vsvg_run_linear( struct draw_vs_variant *variant,
unsigned start,
unsigned count,
void *output_buffer )
{
struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
struct draw_vs_variant_generic *vsvg = (struct draw_vs_variant_generic *)variant;
unsigned temp_vertex_stride = vsvg->temp_vertex_stride;
void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride );
@ -259,20 +259,20 @@ static void PIPE_CDECL vsvg_run_linear( struct draw_vs_varient *varient,
static void vsvg_destroy( struct draw_vs_varient *varient )
static void vsvg_destroy( struct draw_vs_variant *variant )
{
FREE(varient);
FREE(variant);
}
struct draw_vs_varient *
draw_vs_create_varient_generic( struct draw_vertex_shader *vs,
const struct draw_vs_varient_key *key )
struct draw_vs_variant *
draw_vs_create_variant_generic( struct draw_vertex_shader *vs,
const struct draw_vs_variant_key *key )
{
unsigned i;
struct translate_key fetch, emit;
struct draw_vs_varient_generic *vsvg = CALLOC_STRUCT( draw_vs_varient_generic );
struct draw_vs_variant_generic *vsvg = CALLOC_STRUCT( draw_vs_variant_generic );
if (vsvg == NULL)
return NULL;

View file

@ -55,4 +55,33 @@
#endif
/**
* Redefine these LLVM entrypoints as invalid macros to make sure we
* don't accidentally use them. We need to use the functions which
* take an explicit LLVMContextRef parameter.
*/
#define LLVMInt1Type ILLEGAL_LLVM_FUNCTION
#define LLVMInt8Type ILLEGAL_LLVM_FUNCTION
#define LLVMInt16Type ILLEGAL_LLVM_FUNCTION
#define LLVMInt32Type ILLEGAL_LLVM_FUNCTION
#define LLVMInt64Type ILLEGAL_LLVM_FUNCTION
#define LLVMIntType ILLEGAL_LLVM_FUNCTION
#define LLVMFloatType ILLEGAL_LLVM_FUNCTION
#define LLVMDoubleType ILLEGAL_LLVM_FUNCTION
#define LLVMX86FP80Type ILLEGAL_LLVM_FUNCTION
#define LLVMFP128Type ILLEGAL_LLVM_FUNCTION
#define LLVMPPCFP128Type ILLEGAL_LLVM_FUNCTION
#define LLVMStructType ILLEGAL_LLVM_FUNCTION
#define LLVMVoidType ILLEGAL_LLVM_FUNCTION
#define LLVMLabelType ILLEGAL_LLVM_FUNCTION
#define LLVMOpaqueType ILLEGAL_LLVM_FUNCTION
#define LLVMUnionType ILLEGAL_LLVM_FUNCTION
#define LLVMMDString ILLEGAL_LLVM_FUNCTION
#define LLVMMDNode ILLEGAL_LLVM_FUNCTION
#define LLVMConstString ILLEGAL_LLVM_FUNCTION
#define LLVMConstStruct ILLEGAL_LLVM_FUNCTION
#define LLVMAppendBasicBlock ILLEGAL_LLVM_FUNCTION
#define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION
#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION
#endif /* LP_BLD_H */

File diff suppressed because it is too large Load diff

View file

@ -56,20 +56,21 @@ lp_assert(int condition, const char *msg)
* \param msg a string to print if the assertion fails.
*/
LLVMValueRef
lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
lp_build_assert(struct gallivm_state *gallivm,
LLVMValueRef condition,
const char *msg)
{
LLVMModuleRef module;
LLVMBuilderRef builder = gallivm->builder;
LLVMContextRef context = gallivm->context;
LLVMModuleRef module = gallivm->module;
LLVMTypeRef arg_types[2];
LLVMValueRef msg_string, assert_func, params[2], r;
module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(
LLVMGetInsertBlock(builder)));
msg_string = lp_build_const_string_variable(module, context,
msg, strlen(msg) + 1);
msg_string = lp_build_const_string_variable(module, msg, strlen(msg) + 1);
arg_types[0] = LLVMInt32Type();
arg_types[1] = LLVMPointerType(LLVMInt8Type(), 0);
arg_types[0] = LLVMInt32TypeInContext(context);
arg_types[1] = LLVMPointerType(LLVMInt8TypeInContext(context), 0);
/* lookup the lp_assert function */
assert_func = LLVMGetNamedFunction(module, "lp_assert");
@ -77,12 +78,12 @@ lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
/* Create the assertion function if not found */
if (!assert_func) {
LLVMTypeRef func_type =
LLVMFunctionType(LLVMVoidType(), arg_types, 2, 0);
LLVMFunctionType(LLVMVoidTypeInContext(context), arg_types, 2, 0);
assert_func = LLVMAddFunction(module, "lp_assert", func_type);
LLVMSetFunctionCallConv(assert_func, LLVMCCallConv);
LLVMSetLinkage(assert_func, LLVMExternalLinkage);
LLVMAddGlobalMapping(lp_build_engine, assert_func,
LLVMAddGlobalMapping(gallivm->engine, assert_func,
func_to_pointer((func_pointer)lp_assert));
}
assert(assert_func);

View file

@ -30,10 +30,12 @@
#include "lp_bld.h"
#include "lp_bld_init.h"
LLVMValueRef
lp_build_assert(LLVMBuilderRef builder, LLVMValueRef condition,
lp_build_assert(struct gallivm_state *gallivm,
LLVMValueRef condition,
const char *msg);

View file

@ -40,6 +40,7 @@
LLVMValueRef
lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@ -48,14 +49,14 @@ lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
/* can't do bitwise ops on floating-point values */
if (type.floating) {
a = LLVMBuildBitCast(bld->builder, a, bld->int_vec_type, "");
b = LLVMBuildBitCast(bld->builder, b, bld->int_vec_type, "");
a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
}
res = LLVMBuildOr(bld->builder, a, b, "");
res = LLVMBuildOr(builder, a, b, "");
if (type.floating) {
res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
return res;
@ -68,6 +69,7 @@ lp_build_or(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@ -76,14 +78,14 @@ lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
/* can't do bitwise ops on floating-point values */
if (type.floating) {
a = LLVMBuildBitCast(bld->builder, a, bld->int_vec_type, "");
b = LLVMBuildBitCast(bld->builder, b, bld->int_vec_type, "");
a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
}
res = LLVMBuildAnd(bld->builder, a, b, "");
res = LLVMBuildAnd(builder, a, b, "");
if (type.floating) {
res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
return res;
@ -96,6 +98,7 @@ lp_build_and(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@ -104,15 +107,15 @@ lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
/* can't do bitwise ops on floating-point values */
if (type.floating) {
a = LLVMBuildBitCast(bld->builder, a, bld->int_vec_type, "");
b = LLVMBuildBitCast(bld->builder, b, bld->int_vec_type, "");
a = LLVMBuildBitCast(builder, a, bld->int_vec_type, "");
b = LLVMBuildBitCast(builder, b, bld->int_vec_type, "");
}
res = LLVMBuildNot(bld->builder, b, "");
res = LLVMBuildAnd(bld->builder, a, res, "");
res = LLVMBuildNot(builder, b, "");
res = LLVMBuildAnd(builder, a, res, "");
if (type.floating) {
res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
return res;
@ -125,6 +128,7 @@ lp_build_andnot(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@ -133,7 +137,7 @@ lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
assert(lp_check_value(type, a));
assert(lp_check_value(type, b));
res = LLVMBuildShl(bld->builder, a, b, "");
res = LLVMBuildShl(builder, a, b, "");
return res;
}
@ -145,6 +149,7 @@ lp_build_shl(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
LLVMValueRef res;
@ -154,9 +159,9 @@ lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
assert(lp_check_value(type, b));
if (type.sign) {
res = LLVMBuildAShr(bld->builder, a, b, "");
res = LLVMBuildAShr(builder, a, b, "");
} else {
res = LLVMBuildLShr(bld->builder, a, b, "");
res = LLVMBuildLShr(builder, a, b, "");
}
return res;
@ -169,7 +174,7 @@ lp_build_shr(struct lp_build_context *bld, LLVMValueRef a, LLVMValueRef b)
LLVMValueRef
lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
{
LLVMValueRef b = lp_build_const_int_vec(bld->type, imm);
LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
assert(imm <= bld->type.width);
return lp_build_shl(bld, a, b);
}
@ -181,7 +186,7 @@ lp_build_shl_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
LLVMValueRef
lp_build_shr_imm(struct lp_build_context *bld, LLVMValueRef a, unsigned imm)
{
LLVMValueRef b = lp_build_const_int_vec(bld->type, imm);
LLVMValueRef b = lp_build_const_int_vec(bld->gallivm, bld->type, imm);
assert(imm <= bld->type.width);
return lp_build_shr(bld, a, b);
}

View file

@ -39,6 +39,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
#include "lp_bld_init.h"
unsigned
@ -211,31 +212,31 @@ lp_const_eps(struct lp_type type)
LLVMValueRef
lp_build_undef(struct lp_type type)
lp_build_undef(struct gallivm_state *gallivm, struct lp_type type)
{
LLVMTypeRef vec_type = lp_build_vec_type(type);
LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
return LLVMGetUndef(vec_type);
}
LLVMValueRef
lp_build_zero(struct lp_type type)
lp_build_zero(struct gallivm_state *gallivm, struct lp_type type)
{
if (type.length == 1) {
if (type.floating)
return LLVMConstReal(LLVMFloatType(), 0.0);
return lp_build_const_float(gallivm, 0.0);
else
return LLVMConstInt(LLVMIntType(type.width), 0, 0);
return LLVMConstInt(LLVMIntTypeInContext(gallivm->context, type.width), 0, 0);
}
else {
LLVMTypeRef vec_type = lp_build_vec_type(type);
LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
return LLVMConstNull(vec_type);
}
}
LLVMValueRef
lp_build_one(struct lp_type type)
lp_build_one(struct gallivm_state *gallivm, struct lp_type type)
{
LLVMTypeRef elem_type;
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
@ -243,7 +244,7 @@ lp_build_one(struct lp_type type)
assert(type.length <= LP_MAX_VECTOR_LENGTH);
elem_type = lp_build_elem_type(type);
elem_type = lp_build_elem_type(gallivm, type);
if(type.floating)
elems[0] = LLVMConstReal(elem_type, 1.0);
@ -283,10 +284,11 @@ lp_build_one(struct lp_type type)
* Build constant-valued element from a scalar value.
*/
LLVMValueRef
lp_build_const_elem(struct lp_type type,
lp_build_const_elem(struct gallivm_state *gallivm,
struct lp_type type,
double val)
{
LLVMTypeRef elem_type = lp_build_elem_type(type);
LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type);
LLVMValueRef elem;
if(type.floating) {
@ -306,15 +308,15 @@ lp_build_const_elem(struct lp_type type,
* Build constant-valued vector from a scalar value.
*/
LLVMValueRef
lp_build_const_vec(struct lp_type type,
lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
double val)
{
if (type.length == 1) {
return lp_build_const_elem(type, val);
return lp_build_const_elem(gallivm, type, val);
} else {
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
elems[0] = lp_build_const_elem(type, val);
elems[0] = lp_build_const_elem(gallivm, type, val);
for(i = 1; i < type.length; ++i)
elems[i] = elems[0];
return LLVMConstVector(elems, type.length);
@ -323,10 +325,10 @@ lp_build_const_vec(struct lp_type type,
LLVMValueRef
lp_build_const_int_vec(struct lp_type type,
long long val)
lp_build_const_int_vec(struct gallivm_state *gallivm, struct lp_type type,
long long val)
{
LLVMTypeRef elem_type = lp_build_int_elem_type(type);
LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type);
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
@ -343,7 +345,8 @@ lp_build_const_int_vec(struct lp_type type,
LLVMValueRef
lp_build_const_aos(struct lp_type type,
lp_build_const_aos(struct gallivm_state *gallivm,
struct lp_type type,
double r, double g, double b, double a,
const unsigned char *swizzle)
{
@ -355,7 +358,7 @@ lp_build_const_aos(struct lp_type type,
assert(type.length % 4 == 0);
assert(type.length <= LP_MAX_VECTOR_LENGTH);
elem_type = lp_build_elem_type(type);
elem_type = lp_build_elem_type(gallivm, type);
if(swizzle == NULL)
swizzle = default_swizzle;
@ -386,10 +389,11 @@ lp_build_const_aos(struct lp_type type,
* @param mask TGSI_WRITEMASK_xxx
*/
LLVMValueRef
lp_build_const_mask_aos(struct lp_type type,
lp_build_const_mask_aos(struct gallivm_state *gallivm,
struct lp_type type,
unsigned mask)
{
LLVMTypeRef elem_type = LLVMIntType(type.width);
LLVMTypeRef elem_type = LLVMIntTypeInContext(gallivm->context, type.width);
LLVMValueRef masks[LP_MAX_VECTOR_LENGTH];
unsigned i, j;

View file

@ -39,6 +39,7 @@
#include "pipe/p_compiler.h"
#include "gallivm/lp_bld.h"
#include "gallivm/lp_bld_init.h"
@ -73,44 +74,71 @@ lp_const_eps(struct lp_type type);
LLVMValueRef
lp_build_undef(struct lp_type type);
lp_build_undef(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
lp_build_zero(struct lp_type type);
lp_build_zero(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
lp_build_one(struct lp_type type);
lp_build_one(struct gallivm_state *gallivm, struct lp_type type);
LLVMValueRef
lp_build_const_elem(struct lp_type type,
lp_build_const_elem(struct gallivm_state *gallivm, struct lp_type type,
double val);
LLVMValueRef
lp_build_const_vec(struct lp_type type, double val);
lp_build_const_vec(struct gallivm_state *gallivm, struct lp_type type,
double val);
LLVMValueRef
lp_build_const_int_vec(struct lp_type type, long long val);
lp_build_const_int_vec(struct gallivm_state *gallivm,
struct lp_type type, long long val);
LLVMValueRef
lp_build_const_aos(struct lp_type type,
lp_build_const_aos(struct gallivm_state *gallivm, struct lp_type type,
double r, double g, double b, double a,
const unsigned char *swizzle);
LLVMValueRef
lp_build_const_mask_aos(struct lp_type type,
lp_build_const_mask_aos(struct gallivm_state *gallivm,
struct lp_type type,
unsigned mask);
static INLINE LLVMValueRef
lp_build_const_int32(int i)
lp_build_const_int32(struct gallivm_state *gallivm, int i)
{
return LLVMConstInt(LLVMInt32Type(), i, 0);
return LLVMConstInt(LLVMInt32TypeInContext(gallivm->context), i, 0);
}
static INLINE LLVMValueRef
lp_build_const_float(struct gallivm_state *gallivm, float x)
{
return LLVMConstReal(LLVMFloatTypeInContext(gallivm->context), x);
}
/** Return constant-valued pointer to int */
static INLINE LLVMValueRef
lp_build_const_int_pointer(struct gallivm_state *gallivm, const void *ptr)
{
LLVMTypeRef int_type;
LLVMValueRef v;
/* int type large enough to hold a pointer */
int_type = LLVMIntTypeInContext(gallivm->context, 8 * sizeof(void *));
v = LLVMConstInt(int_type, (unsigned long long) ptr, 0);
v = LLVMBuildIntToPtr(gallivm->builder, v,
LLVMPointerType(int_type, 0),
"cast int to ptr");
return v;
}

View file

@ -89,12 +89,13 @@
* return { i32, i32, i32, i32 } where each value is in [0, 2^dst_width-1].
*/
LLVMValueRef
lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm,
struct lp_type src_type,
unsigned dst_width,
LLVMValueRef src)
{
LLVMTypeRef int_vec_type = lp_build_int_vec_type(src_type);
LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, src_type);
LLVMValueRef res;
unsigned mantissa;
@ -122,10 +123,11 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
scale = (double)mask/ubound;
bias = (double)(1ULL << (mantissa - dst_width));
res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
res = LLVMBuildFAdd(builder, res, lp_build_const_vec(src_type, bias), "");
res = LLVMBuildFMul(builder, src, lp_build_const_vec(gallivm, src_type, scale), "");
res = LLVMBuildFAdd(builder, res, lp_build_const_vec(gallivm, src_type, bias), "");
res = LLVMBuildBitCast(builder, res, int_vec_type, "");
res = LLVMBuildAnd(builder, res, lp_build_const_int_vec(src_type, mask), "");
res = LLVMBuildAnd(builder, res,
lp_build_const_int_vec(gallivm, src_type, mask), "");
}
else if (dst_width == (mantissa + 1)) {
/*
@ -138,7 +140,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
scale = (double)((1ULL << dst_width) - 1);
res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
res = LLVMBuildFMul(builder, src,
lp_build_const_vec(gallivm, src_type, scale), "");
res = LLVMBuildFPToSI(builder, res, int_vec_type, "");
}
else {
@ -166,7 +169,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
LLVMValueRef lshifted;
LLVMValueRef rshifted;
res = LLVMBuildFMul(builder, src, lp_build_const_vec(src_type, scale), "");
res = LLVMBuildFMul(builder, src,
lp_build_const_vec(gallivm, src_type, scale), "");
res = LLVMBuildFPToSI(builder, res, int_vec_type, "");
/*
@ -177,7 +181,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
*/
if (lshift) {
lshifted = LLVMBuildShl(builder, res,
lp_build_const_int_vec(src_type, lshift), "");
lp_build_const_int_vec(gallivm, src_type,
lshift), "");
} else {
lshifted = res;
}
@ -186,7 +191,8 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
* Align the most significant bit to the right.
*/
rshifted = LLVMBuildAShr(builder, res,
lp_build_const_int_vec(src_type, rshift), "");
lp_build_const_int_vec(gallivm, src_type, rshift),
"");
/*
* Subtract the MSB to the LSB, therefore re-scaling from
@ -206,13 +212,14 @@ lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
* return {float, float, float, float} with values in range [0, 1].
*/
LLVMValueRef
lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm,
unsigned src_width,
struct lp_type dst_type,
LLVMValueRef src)
{
LLVMTypeRef vec_type = lp_build_vec_type(dst_type);
LLVMTypeRef int_vec_type = lp_build_int_vec_type(dst_type);
LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef vec_type = lp_build_vec_type(gallivm, dst_type);
LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, dst_type);
LLVMValueRef bias_;
LLVMValueRef res;
unsigned mantissa;
@ -230,7 +237,8 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
if (src_width == 8) {
scale = 1.0/255.0;
res = LLVMBuildSIToFP(builder, src, vec_type, "");
res = LLVMBuildFMul(builder, res, lp_build_const_vec(dst_type, scale), "");
res = LLVMBuildFMul(builder, res,
lp_build_const_vec(gallivm, dst_type, scale), "");
return res;
}
@ -247,10 +255,11 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
if(src_width > mantissa) {
int shift = src_width - mantissa;
res = LLVMBuildLShr(builder, res, lp_build_const_int_vec(dst_type, shift), "");
res = LLVMBuildLShr(builder, res,
lp_build_const_int_vec(gallivm, dst_type, shift), "");
}
bias_ = lp_build_const_vec(dst_type, bias);
bias_ = lp_build_const_vec(gallivm, dst_type, bias);
res = LLVMBuildOr(builder,
res,
@ -259,7 +268,7 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
res = LLVMBuildBitCast(builder, res, vec_type, "");
res = LLVMBuildFSub(builder, res, bias_, "");
res = LLVMBuildFMul(builder, res, lp_build_const_vec(dst_type, scale), "");
res = LLVMBuildFMul(builder, res, lp_build_const_vec(gallivm, dst_type, scale), "");
return res;
}
@ -272,12 +281,13 @@ lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
* to the lp_type union.
*/
void
lp_build_conv(LLVMBuilderRef builder,
lp_build_conv(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
LLVMValueRef *dst, unsigned num_dsts)
{
LLVMBuilderRef builder = gallivm->builder;
struct lp_type tmp_type;
LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH];
unsigned num_tmps;
@ -342,12 +352,12 @@ lp_build_conv(LLVMBuilderRef builder,
int32_type.length /= 4;
int32_type.sign = 1;
src_vec_type = lp_build_vec_type(src_type);
dst_vec_type = lp_build_vec_type(dst_type);
int16_vec_type = lp_build_vec_type(int16_type);
int32_vec_type = lp_build_vec_type(int32_type);
src_vec_type = lp_build_vec_type(gallivm, src_type);
dst_vec_type = lp_build_vec_type(gallivm, dst_type);
int16_vec_type = lp_build_vec_type(gallivm, int16_type);
int32_vec_type = lp_build_vec_type(gallivm, int32_type);
const_255f = lp_build_const_vec(src_type, 255.0f);
const_255f = lp_build_const_vec(gallivm, src_type, 255.0f);
a = LLVMBuildFMul(builder, src[0], const_255f, "");
b = LLVMBuildFMul(builder, src[1], const_255f, "");
@ -357,14 +367,14 @@ lp_build_conv(LLVMBuilderRef builder,
{
struct lp_build_context bld;
bld.builder = builder;
bld.gallivm = gallivm;
bld.type = src_type;
bld.vec_type = src_vec_type;
bld.int_elem_type = lp_build_elem_type(int32_type);
bld.int_elem_type = lp_build_elem_type(gallivm, int32_type);
bld.int_vec_type = int32_vec_type;
bld.undef = lp_build_undef(src_type);
bld.zero = lp_build_zero(src_type);
bld.one = lp_build_one(src_type);
bld.undef = lp_build_undef(gallivm, src_type);
bld.zero = lp_build_zero(gallivm, src_type);
bld.one = lp_build_one(gallivm, src_type);
src_int0 = lp_build_iround(&bld, a);
src_int1 = lp_build_iround(&bld, b);
@ -372,9 +382,9 @@ lp_build_conv(LLVMBuilderRef builder,
src_int3 = lp_build_iround(&bld, d);
}
/* relying on clamping behavior of sse2 intrinsics here */
lo = lp_build_pack2(builder, int32_type, int16_type, src_int0, src_int1);
hi = lp_build_pack2(builder, int32_type, int16_type, src_int2, src_int3);
dst[i] = lp_build_pack2(builder, int16_type, dst_type, lo, hi);
lo = lp_build_pack2(gallivm, int32_type, int16_type, src_int0, src_int1);
hi = lp_build_pack2(gallivm, int32_type, int16_type, src_int2, src_int3);
dst[i] = lp_build_pack2(gallivm, int16_type, dst_type, lo, hi);
}
return;
}
@ -391,13 +401,13 @@ lp_build_conv(LLVMBuilderRef builder,
double dst_max = lp_const_max(dst_type);
LLVMValueRef thres;
lp_build_context_init(&bld, builder, tmp_type);
lp_build_context_init(&bld, gallivm, tmp_type);
if(src_min < dst_min) {
if(dst_min == 0.0)
thres = bld.zero;
else
thres = lp_build_const_vec(src_type, dst_min);
thres = lp_build_const_vec(gallivm, src_type, dst_min);
for(i = 0; i < num_tmps; ++i)
tmp[i] = lp_build_max(&bld, tmp[i], thres);
}
@ -406,7 +416,7 @@ lp_build_conv(LLVMBuilderRef builder,
if(dst_max == 1.0)
thres = bld.one;
else
thres = lp_build_const_vec(src_type, dst_max);
thres = lp_build_const_vec(gallivm, src_type, dst_max);
for(i = 0; i < num_tmps; ++i)
tmp[i] = lp_build_min(&bld, tmp[i], thres);
}
@ -422,7 +432,7 @@ lp_build_conv(LLVMBuilderRef builder,
else if(tmp_type.floating) {
if(!dst_type.fixed && !dst_type.sign && dst_type.norm) {
for(i = 0; i < num_tmps; ++i) {
tmp[i] = lp_build_clamped_float_to_unsigned_norm(builder,
tmp[i] = lp_build_clamped_float_to_unsigned_norm(gallivm,
tmp_type,
dst_type.width,
tmp[i]);
@ -434,14 +444,14 @@ lp_build_conv(LLVMBuilderRef builder,
LLVMTypeRef tmp_vec_type;
if (dst_scale != 1.0) {
LLVMValueRef scale = lp_build_const_vec(tmp_type, dst_scale);
LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, dst_scale);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, "");
}
/* Use an equally sized integer for intermediate computations */
tmp_type.floating = FALSE;
tmp_vec_type = lp_build_vec_type(tmp_type);
tmp_vec_type = lp_build_vec_type(gallivm, tmp_type);
for(i = 0; i < num_tmps; ++i) {
#if 0
if(dst_type.sign)
@ -461,7 +471,8 @@ lp_build_conv(LLVMBuilderRef builder,
/* FIXME: compensate different offsets too */
if(src_shift > dst_shift) {
LLVMValueRef shift = lp_build_const_int_vec(tmp_type, src_shift - dst_shift);
LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type,
src_shift - dst_shift);
for(i = 0; i < num_tmps; ++i)
if(src_type.sign)
tmp[i] = LLVMBuildAShr(builder, tmp[i], shift, "");
@ -485,7 +496,7 @@ lp_build_conv(LLVMBuilderRef builder,
new_type.width = dst_type.width;
new_type.length = dst_type.length;
lp_build_resize(builder, tmp_type, new_type, tmp, num_srcs, tmp, num_dsts);
lp_build_resize(gallivm, tmp_type, new_type, tmp, num_srcs, tmp, num_dsts);
tmp_type = new_type;
num_tmps = num_dsts;
@ -501,7 +512,7 @@ lp_build_conv(LLVMBuilderRef builder,
else if(!src_type.floating && dst_type.floating) {
if(!src_type.fixed && !src_type.sign && src_type.norm) {
for(i = 0; i < num_tmps; ++i) {
tmp[i] = lp_build_unsigned_norm_to_float(builder,
tmp[i] = lp_build_unsigned_norm_to_float(gallivm,
src_type.width,
dst_type,
tmp[i]);
@ -515,7 +526,7 @@ lp_build_conv(LLVMBuilderRef builder,
/* Use an equally sized integer for intermediate computations */
tmp_type.floating = TRUE;
tmp_type.sign = TRUE;
tmp_vec_type = lp_build_vec_type(tmp_type);
tmp_vec_type = lp_build_vec_type(gallivm, tmp_type);
for(i = 0; i < num_tmps; ++i) {
#if 0
if(dst_type.sign)
@ -529,7 +540,7 @@ lp_build_conv(LLVMBuilderRef builder,
}
if (src_scale != 1.0) {
LLVMValueRef scale = lp_build_const_vec(tmp_type, 1.0/src_scale);
LLVMValueRef scale = lp_build_const_vec(gallivm, tmp_type, 1.0/src_scale);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildFMul(builder, tmp[i], scale, "");
}
@ -541,7 +552,7 @@ lp_build_conv(LLVMBuilderRef builder,
/* FIXME: compensate different offsets too */
if(src_shift < dst_shift) {
LLVMValueRef shift = lp_build_const_int_vec(tmp_type, dst_shift - src_shift);
LLVMValueRef shift = lp_build_const_int_vec(gallivm, tmp_type, dst_shift - src_shift);
for(i = 0; i < num_tmps; ++i)
tmp[i] = LLVMBuildShl(builder, tmp[i], shift, "");
}
@ -565,7 +576,7 @@ lp_build_conv(LLVMBuilderRef builder,
* This is basically a very trimmed down version of lp_build_conv.
*/
void
lp_build_conv_mask(LLVMBuilderRef builder,
lp_build_conv_mask(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
@ -599,11 +610,11 @@ lp_build_conv_mask(LLVMBuilderRef builder,
if(src_type.width > dst_type.width) {
assert(num_dsts == 1);
dst[0] = lp_build_pack(builder, src_type, dst_type, TRUE, src, num_srcs);
dst[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs);
}
else if(src_type.width < dst_type.width) {
assert(num_srcs == 1);
lp_build_unpack(builder, src_type, dst_type, src[0], dst, num_dsts);
lp_build_unpack(gallivm, src_type, dst_type, src[0], dst, num_dsts);
}
else {
assert(num_srcs == num_dsts);

View file

@ -44,27 +44,27 @@ struct lp_type;
LLVMValueRef
lp_build_clamped_float_to_unsigned_norm(LLVMBuilderRef builder,
lp_build_clamped_float_to_unsigned_norm(struct gallivm_state *gallivm,
struct lp_type src_type,
unsigned dst_width,
LLVMValueRef src);
LLVMValueRef
lp_build_unsigned_norm_to_float(LLVMBuilderRef builder,
lp_build_unsigned_norm_to_float(struct gallivm_state *gallivm,
unsigned src_width,
struct lp_type dst_type,
LLVMValueRef src);
void
lp_build_conv(LLVMBuilderRef builder,
lp_build_conv(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *srcs, unsigned num_srcs,
LLVMValueRef *dsts, unsigned num_dsts);
void
lp_build_conv_mask(LLVMBuilderRef builder,
lp_build_conv_mask(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,

View file

@ -42,6 +42,7 @@
#define GALLIVM_DEBUG_NO_OPT (1 << 3)
#define GALLIVM_DEBUG_PERF (1 << 4)
#define GALLIVM_DEBUG_NO_BRILINEAR (1 << 5)
#define GALLIVM_DEBUG_GC (1 << 6)
#ifdef DEBUG

View file

@ -34,6 +34,7 @@
#include "util/u_debug.h"
#include "util/u_memory.h"
#include "lp_bld_init.h"
#include "lp_bld_type.h"
#include "lp_bld_flow.h"
@ -51,25 +52,25 @@
* be used elsewhere.
*/
LLVMBasicBlockRef
lp_build_insert_new_block(LLVMBuilderRef builder, const char *name)
lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name)
{
LLVMBasicBlockRef current_block;
LLVMBasicBlockRef next_block;
LLVMBasicBlockRef new_block;
/* get current basic block */
current_block = LLVMGetInsertBlock(builder);
current_block = LLVMGetInsertBlock(gallivm->builder);
/* check if there's another block after this one */
next_block = LLVMGetNextBasicBlock(current_block);
if (next_block) {
/* insert the new block before the next block */
new_block = LLVMInsertBasicBlock(next_block, name);
new_block = LLVMInsertBasicBlockInContext(gallivm->context, next_block, name);
}
else {
/* append new block after current block */
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
new_block = LLVMAppendBasicBlock(function, name);
new_block = LLVMAppendBasicBlockInContext(gallivm->context, function, name);
}
return new_block;
@ -82,12 +83,11 @@ lp_build_insert_new_block(LLVMBuilderRef builder, const char *name)
*/
void
lp_build_flow_skip_begin(struct lp_build_skip_context *skip,
LLVMBuilderRef builder)
struct gallivm_state *gallivm)
{
skip->builder = builder;
skip->gallivm = gallivm;
/* create new basic block */
skip->block = lp_build_insert_new_block(skip->builder, "skip");
skip->block = lp_build_insert_new_block(gallivm, "skip");
}
@ -101,12 +101,12 @@ lp_build_flow_skip_cond_break(struct lp_build_skip_context *skip,
{
LLVMBasicBlockRef new_block;
new_block = lp_build_insert_new_block(skip->builder, "");
new_block = lp_build_insert_new_block(skip->gallivm, "");
/* if cond is true, goto skip->block, else goto new_block */
LLVMBuildCondBr(skip->builder, cond, skip->block, new_block);
LLVMBuildCondBr(skip->gallivm->builder, cond, skip->block, new_block);
LLVMPositionBuilderAtEnd(skip->builder, new_block);
LLVMPositionBuilderAtEnd(skip->gallivm->builder, new_block);
}
@ -114,8 +114,8 @@ void
lp_build_flow_skip_end(struct lp_build_skip_context *skip)
{
/* goto block */
LLVMBuildBr(skip->builder, skip->block);
LLVMPositionBuilderAtEnd(skip->builder, skip->block);
LLVMBuildBr(skip->gallivm->builder, skip->block);
LLVMPositionBuilderAtEnd(skip->gallivm->builder, skip->block);
}
@ -125,7 +125,7 @@ lp_build_flow_skip_end(struct lp_build_skip_context *skip)
void
lp_build_mask_check(struct lp_build_mask_context *mask)
{
LLVMBuilderRef builder = mask->skip.builder;
LLVMBuilderRef builder = mask->skip.gallivm->builder;
LLVMValueRef value;
LLVMValueRef cond;
@ -152,27 +152,27 @@ lp_build_mask_check(struct lp_build_mask_context *mask)
*/
void
lp_build_mask_begin(struct lp_build_mask_context *mask,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef value)
{
memset(mask, 0, sizeof *mask);
mask->reg_type = LLVMIntType(type.width * type.length);
mask->var = lp_build_alloca(builder,
lp_build_int_vec_type(type),
mask->reg_type = LLVMIntTypeInContext(gallivm->context, type.width * type.length);
mask->var = lp_build_alloca(gallivm,
lp_build_int_vec_type(gallivm, type),
"execution_mask");
LLVMBuildStore(builder, value, mask->var);
LLVMBuildStore(gallivm->builder, value, mask->var);
lp_build_flow_skip_begin(&mask->skip, builder);
lp_build_flow_skip_begin(&mask->skip, gallivm);
}
LLVMValueRef
lp_build_mask_value(struct lp_build_mask_context *mask)
{
return LLVMBuildLoad(mask->skip.builder, mask->var, "");
return LLVMBuildLoad(mask->skip.gallivm->builder, mask->var, "");
}
@ -185,10 +185,10 @@ void
lp_build_mask_update(struct lp_build_mask_context *mask,
LLVMValueRef value)
{
value = LLVMBuildAnd(mask->skip.builder,
value = LLVMBuildAnd(mask->skip.gallivm->builder,
lp_build_mask_value(mask),
value, "");
LLVMBuildStore(mask->skip.builder, value, mask->var);
LLVMBuildStore(mask->skip.gallivm->builder, value, mask->var);
}
@ -205,13 +205,17 @@ lp_build_mask_end(struct lp_build_mask_context *mask)
void
lp_build_loop_begin(LLVMBuilderRef builder,
LLVMValueRef start,
struct lp_build_loop_state *state)
lp_build_loop_begin(struct lp_build_loop_state *state,
struct gallivm_state *gallivm,
LLVMValueRef start)
{
state->block = lp_build_insert_new_block(builder, "loop_begin");
LLVMBuilderRef builder = gallivm->builder;
state->counter_var = lp_build_alloca(builder, LLVMTypeOf(start), "loop_counter");
state->block = lp_build_insert_new_block(gallivm, "loop_begin");
state->counter_var = lp_build_alloca(gallivm, LLVMTypeOf(start), "loop_counter");
state->gallivm = gallivm;
LLVMBuildStore(builder, start, state->counter_var);
@ -224,12 +228,12 @@ lp_build_loop_begin(LLVMBuilderRef builder,
void
lp_build_loop_end_cond(LLVMBuilderRef builder,
lp_build_loop_end_cond(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
LLVMIntPredicate llvm_cond,
struct lp_build_loop_state *state)
LLVMIntPredicate llvm_cond)
{
LLVMBuilderRef builder = state->gallivm->builder;
LLVMValueRef next;
LLVMValueRef cond;
LLVMBasicBlockRef after_block;
@ -243,7 +247,7 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
cond = LLVMBuildICmp(builder, llvm_cond, next, end, "");
after_block = lp_build_insert_new_block(builder, "loop_end");
after_block = lp_build_insert_new_block(state->gallivm, "loop_end");
LLVMBuildCondBr(builder, cond, after_block, state->block);
@ -254,12 +258,11 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
void
lp_build_loop_end(LLVMBuilderRef builder,
lp_build_loop_end(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
struct lp_build_loop_state *state)
LLVMValueRef step)
{
lp_build_loop_end_cond(builder, end, step, LLVMIntNE, state);
lp_build_loop_end_cond(state, end, step, LLVMIntNE);
}
@ -296,24 +299,27 @@ lp_build_loop_end(LLVMBuilderRef builder,
*/
void
lp_build_if(struct lp_build_if_state *ifthen,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
LLVMValueRef condition)
{
LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
memset(ifthen, 0, sizeof *ifthen);
ifthen->builder = builder;
ifthen->gallivm = gallivm;
ifthen->condition = condition;
ifthen->entry_block = block;
/* create endif/merge basic block for the phi functions */
ifthen->merge_block = lp_build_insert_new_block(builder, "endif-block");
ifthen->merge_block = lp_build_insert_new_block(gallivm, "endif-block");
/* create/insert true_block before merge_block */
ifthen->true_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-true-block");
ifthen->true_block =
LLVMInsertBasicBlockInContext(gallivm->context,
ifthen->merge_block,
"if-true-block");
/* successive code goes into the true block */
LLVMPositionBuilderAtEnd(builder, ifthen->true_block);
LLVMPositionBuilderAtEnd(gallivm->builder, ifthen->true_block);
}
@ -323,14 +329,19 @@ lp_build_if(struct lp_build_if_state *ifthen,
void
lp_build_else(struct lp_build_if_state *ifthen)
{
LLVMBuilderRef builder = ifthen->gallivm->builder;
/* Append an unconditional Br(anch) instruction on the true_block */
LLVMBuildBr(ifthen->builder, ifthen->merge_block);
LLVMBuildBr(builder, ifthen->merge_block);
/* create/insert false_block before the merge block */
ifthen->false_block = LLVMInsertBasicBlock(ifthen->merge_block, "if-false-block");
ifthen->false_block =
LLVMInsertBasicBlockInContext(ifthen->gallivm->context,
ifthen->merge_block,
"if-false-block");
/* successive code goes into the else block */
LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->false_block);
LLVMPositionBuilderAtEnd(builder, ifthen->false_block);
}
@ -340,28 +351,30 @@ lp_build_else(struct lp_build_if_state *ifthen)
void
lp_build_endif(struct lp_build_if_state *ifthen)
{
LLVMBuilderRef builder = ifthen->gallivm->builder;
/* Insert branch to the merge block from current block */
LLVMBuildBr(ifthen->builder, ifthen->merge_block);
LLVMBuildBr(builder, ifthen->merge_block);
/*
* Now patch in the various branch instructions.
*/
/* Insert the conditional branch instruction at the end of entry_block */
LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->entry_block);
LLVMPositionBuilderAtEnd(builder, ifthen->entry_block);
if (ifthen->false_block) {
/* we have an else clause */
LLVMBuildCondBr(ifthen->builder, ifthen->condition,
LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->false_block);
}
else {
/* no else clause */
LLVMBuildCondBr(ifthen->builder, ifthen->condition,
LLVMBuildCondBr(builder, ifthen->condition,
ifthen->true_block, ifthen->merge_block);
}
/* Resume building code at end of the ifthen->merge_block */
LLVMPositionBuilderAtEnd(ifthen->builder, ifthen->merge_block);
LLVMPositionBuilderAtEnd(builder, ifthen->merge_block);
}
@ -381,15 +394,16 @@ lp_build_endif(struct lp_build_if_state *ifthen)
* - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory
*/
LLVMValueRef
lp_build_alloca(LLVMBuilderRef builder,
lp_build_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
const char *name)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
LLVMBuilderRef first_builder = LLVMCreateBuilder();
LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
LLVMValueRef res;
if (first_instr) {
@ -422,16 +436,17 @@ lp_build_alloca(LLVMBuilderRef builder,
* - http://www.llvm.org/docs/tutorial/OCamlLangImpl7.html#memory
*/
LLVMValueRef
lp_build_array_alloca(LLVMBuilderRef builder,
lp_build_array_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
LLVMValueRef count,
const char *name)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
LLVMBuilderRef first_builder = LLVMCreateBuilder();
LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
LLVMValueRef res;
if (first_instr) {

View file

@ -47,7 +47,7 @@ struct lp_type;
*/
struct lp_build_skip_context
{
LLVMBuilderRef builder;
struct gallivm_state *gallivm;
/** Block to skip to */
LLVMBasicBlockRef block;
@ -55,7 +55,7 @@ struct lp_build_skip_context
void
lp_build_flow_skip_begin(struct lp_build_skip_context *ctx,
LLVMBuilderRef builder);
struct gallivm_state *gallivm);
void
lp_build_flow_skip_cond_break(struct lp_build_skip_context *ctx,
@ -77,7 +77,7 @@ struct lp_build_mask_context
void
lp_build_mask_begin(struct lp_build_mask_context *mask,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef value);
@ -107,31 +107,28 @@ lp_build_mask_end(struct lp_build_mask_context *mask);
*/
struct lp_build_loop_state
{
LLVMBasicBlockRef block;
LLVMValueRef counter_var;
LLVMValueRef counter;
LLVMBasicBlockRef block;
LLVMValueRef counter_var;
LLVMValueRef counter;
struct gallivm_state *gallivm;
};
void
lp_build_loop_begin(LLVMBuilderRef builder,
LLVMValueRef start,
struct lp_build_loop_state *state);
lp_build_loop_begin(struct lp_build_loop_state *state,
struct gallivm_state *gallivm,
LLVMValueRef start);
void
lp_build_loop_end(LLVMBuilderRef builder,
lp_build_loop_end(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
struct lp_build_loop_state *state);
LLVMValueRef step);
void
lp_build_loop_end_cond(LLVMBuilderRef builder,
lp_build_loop_end_cond(struct lp_build_loop_state *state,
LLVMValueRef end,
LLVMValueRef step,
LLVMIntPredicate cond,
struct lp_build_loop_state *state);
LLVMIntPredicate cond);
@ -140,7 +137,7 @@ lp_build_loop_end_cond(LLVMBuilderRef builder,
*/
struct lp_build_if_state
{
LLVMBuilderRef builder;
struct gallivm_state *gallivm;
LLVMValueRef condition;
LLVMBasicBlockRef entry_block;
LLVMBasicBlockRef true_block;
@ -151,7 +148,7 @@ struct lp_build_if_state
void
lp_build_if(struct lp_build_if_state *ctx,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
LLVMValueRef condition);
void
@ -161,15 +158,15 @@ void
lp_build_endif(struct lp_build_if_state *ctx);
LLVMBasicBlockRef
lp_build_insert_new_block(LLVMBuilderRef builder, const char *name);
lp_build_insert_new_block(struct gallivm_state *gallivm, const char *name);
LLVMValueRef
lp_build_alloca(LLVMBuilderRef builder,
lp_build_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
const char *name);
LLVMValueRef
lp_build_array_alloca(LLVMBuilderRef builder,
lp_build_array_alloca(struct gallivm_state *gallivm,
LLVMTypeRef type,
LLVMValueRef count,
const char *name);

View file

@ -35,6 +35,7 @@
*/
#include "gallivm/lp_bld.h"
#include "gallivm/lp_bld_init.h"
#include "pipe/p_format.h"
@ -53,12 +54,12 @@ lp_build_format_swizzle_aos(const struct util_format_description *desc,
LLVMValueRef unswizzled);
LLVMValueRef
lp_build_pack_rgba_aos(LLVMBuilderRef builder,
lp_build_pack_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef rgba);
LLVMValueRef
lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@ -78,20 +79,20 @@ lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
LLVMValueRef swizzled_out[4]);
void
lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
lp_build_unpack_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef packed,
LLVMValueRef rgba_out[4]);
void
lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm,
struct lp_type dst_type,
LLVMValueRef packed,
LLVMValueRef *rgba);
void
lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
lp_build_fetch_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@ -106,7 +107,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
LLVMValueRef
lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
unsigned n,
LLVMValueRef base_ptr,

View file

@ -36,6 +36,7 @@
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_math.h"
#include "util/u_pointer.h"
#include "util/u_string.h"
#include "lp_bld_arit.h"
@ -145,10 +146,11 @@ format_matches_type(const struct util_format_description *desc,
* @return RGBA in a float[4] or ubyte[4] or ushort[4] vector.
*/
static INLINE LLVMValueRef
lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
lp_build_unpack_arith_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef packed)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef shifted, casted, scaled, masked;
LLVMValueRef shifts[4];
LLVMValueRef masks[4];
@ -167,21 +169,21 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
/* Do the intermediate integer computations with 32bit integers since it
* matches floating point size */
assert (LLVMTypeOf(packed) == LLVMInt32Type());
assert (LLVMTypeOf(packed) == LLVMInt32TypeInContext(gallivm->context));
/* Broadcast the packed value to all four channels
* before: packed = BGRA
* after: packed = {BGRA, BGRA, BGRA, BGRA}
*/
packed = LLVMBuildInsertElement(builder,
LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)),
LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
packed,
LLVMConstNull(LLVMInt32Type()),
LLVMConstNull(LLVMInt32TypeInContext(gallivm->context)),
"");
packed = LLVMBuildShuffleVector(builder,
packed,
LLVMGetUndef(LLVMVectorType(LLVMInt32Type(), 4)),
LLVMConstNull(LLVMVectorType(LLVMInt32Type(), 4)),
LLVMGetUndef(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
LLVMConstNull(LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4)),
"");
/* Initialize vector constants */
@ -194,9 +196,9 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
unsigned bits = desc->channel[i].size;
if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) {
shifts[i] = LLVMGetUndef(LLVMInt32Type());
masks[i] = LLVMConstNull(LLVMInt32Type());
scales[i] = LLVMConstNull(LLVMFloatType());
shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
masks[i] = LLVMConstNull(LLVMInt32TypeInContext(gallivm->context));
scales[i] = LLVMConstNull(LLVMFloatTypeInContext(gallivm->context));
}
else {
unsigned long long mask = (1ULL << bits) - 1;
@ -207,15 +209,15 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
needs_uitofp = TRUE;
}
shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0);
masks[i] = LLVMConstInt(LLVMInt32Type(), mask, 0);
shifts[i] = lp_build_const_int32(gallivm, shift);
masks[i] = lp_build_const_int32(gallivm, mask);
if (desc->channel[i].normalized) {
scales[i] = LLVMConstReal(LLVMFloatType(), 1.0/mask);
scales[i] = lp_build_const_float(gallivm, 1.0 / mask);
normalized = TRUE;
}
else
scales[i] = LLVMConstReal(LLVMFloatType(), 1.0);
scales[i] = lp_build_const_float(gallivm, 1.0);
}
shift += bits;
@ -230,9 +232,9 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
if (!needs_uitofp) {
/* UIToFP can't be expressed in SSE2 */
casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatType(), 4), "");
casted = LLVMBuildSIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), "");
} else {
casted = LLVMBuildUIToFP(builder, masked, LLVMVectorType(LLVMFloatType(), 4), "");
casted = LLVMBuildUIToFP(builder, masked, LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4), "");
}
/* At this point 'casted' may be a vector of floats such as
@ -258,10 +260,11 @@ lp_build_unpack_arith_rgba_aos(LLVMBuilderRef builder,
* a time is rarely if ever needed.
*/
LLVMValueRef
lp_build_pack_rgba_aos(LLVMBuilderRef builder,
lp_build_pack_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *desc,
LLVMValueRef rgba)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef type;
LLVMValueRef packed = NULL;
LLVMValueRef swizzles[4];
@ -276,7 +279,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
assert(desc->block.width == 1);
assert(desc->block.height == 1);
type = LLVMIntType(desc->block.bits);
type = LLVMIntTypeInContext(gallivm->context, desc->block.bits);
/* Unswizzle the color components into the source vector. */
for (i = 0; i < 4; ++i) {
@ -285,13 +288,13 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
break;
}
if (j < 4)
swizzles[i] = LLVMConstInt(LLVMInt32Type(), j, 0);
swizzles[i] = lp_build_const_int32(gallivm, j);
else
swizzles[i] = LLVMGetUndef(LLVMInt32Type());
swizzles[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
}
unswizzled = LLVMBuildShuffleVector(builder, rgba,
LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4)),
LLVMGetUndef(LLVMVectorType(LLVMFloatTypeInContext(gallivm->context), 4)),
LLVMConstVector(swizzles, 4), "");
normalized = FALSE;
@ -300,8 +303,8 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
unsigned bits = desc->channel[i].size;
if (desc->channel[i].type == UTIL_FORMAT_TYPE_VOID) {
shifts[i] = LLVMGetUndef(LLVMInt32Type());
scales[i] = LLVMGetUndef(LLVMFloatType());
shifts[i] = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
scales[i] = LLVMGetUndef(LLVMFloatTypeInContext(gallivm->context));
}
else {
unsigned mask = (1 << bits) - 1;
@ -309,14 +312,14 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
assert(desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED);
assert(bits < 32);
shifts[i] = LLVMConstInt(LLVMInt32Type(), shift, 0);
shifts[i] = lp_build_const_int32(gallivm, shift);
if (desc->channel[i].normalized) {
scales[i] = LLVMConstReal(LLVMFloatType(), mask);
scales[i] = lp_build_const_float(gallivm, mask);
normalized = TRUE;
}
else
scales[i] = LLVMConstReal(LLVMFloatType(), 1.0);
scales[i] = lp_build_const_float(gallivm, 1.0);
}
shift += bits;
@ -327,14 +330,15 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
else
scaled = unswizzled;
casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32Type(), 4), "");
casted = LLVMBuildFPToSI(builder, scaled, LLVMVectorType(LLVMInt32TypeInContext(gallivm->context), 4), "");
shifted = LLVMBuildShl(builder, casted, LLVMConstVector(shifts, 4), "");
/* Bitwise or all components */
for (i = 0; i < 4; ++i) {
if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED) {
LLVMValueRef component = LLVMBuildExtractElement(builder, shifted, LLVMConstInt(LLVMInt32Type(), i, 0), "");
LLVMValueRef component = LLVMBuildExtractElement(builder, shifted,
lp_build_const_int32(gallivm, i), "");
if (packed)
packed = LLVMBuildOr(builder, packed, component, "");
else
@ -343,7 +347,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
}
if (!packed)
packed = LLVMGetUndef(LLVMInt32Type());
packed = LLVMGetUndef(LLVMInt32TypeInContext(gallivm->context));
if (desc->block.bits < 32)
packed = LLVMBuildTrunc(builder, packed, type, "");
@ -364,7 +368,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
* \return a 4 element vector with the pixel's RGBA values.
*/
LLVMValueRef
lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
lp_build_fetch_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@ -372,13 +376,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef i,
LLVMValueRef j)
{
LLVMBuilderRef builder = gallivm->builder;
unsigned num_pixels = type.length / 4;
struct lp_build_context bld;
assert(type.length <= LP_MAX_VECTOR_LENGTH);
assert(type.length % 4 == 0);
lp_build_context_init(&bld, builder, type);
lp_build_context_init(&bld, gallivm, type);
/*
* Trivial case
@ -397,13 +402,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* scaling or converting.
*/
packed = lp_build_gather(builder, type.length/4,
packed = lp_build_gather(gallivm, type.length/4,
format_desc->block.bits, type.width*4,
base_ptr, offset);
assert(format_desc->block.bits <= type.width * type.length);
packed = LLVMBuildBitCast(builder, packed, lp_build_vec_type(type), "");
packed = LLVMBuildBitCast(gallivm->builder, packed,
lp_build_vec_type(gallivm, type), "");
return lp_build_format_swizzle_aos(format_desc, &bld, packed);
}
@ -435,11 +441,12 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
for (k = 0; k < num_pixels; ++k) {
LLVMValueRef packed;
packed = lp_build_gather_elem(builder, num_pixels,
packed = lp_build_gather_elem(gallivm, num_pixels,
format_desc->block.bits, 32,
base_ptr, offset, k);
tmps[k] = lp_build_unpack_arith_rgba_aos(builder, format_desc,
tmps[k] = lp_build_unpack_arith_rgba_aos(gallivm,
format_desc,
packed);
}
@ -455,7 +462,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
__FUNCTION__, format_desc->short_name);
}
lp_build_conv(builder,
lp_build_conv(gallivm,
lp_float32_vec4_type(),
type,
tmps, num_pixels, &res, 1);
@ -476,14 +483,14 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
tmp_type.length = num_pixels * 4;
tmp_type.norm = TRUE;
tmp = lp_build_fetch_subsampled_rgba_aos(builder,
tmp = lp_build_fetch_subsampled_rgba_aos(gallivm,
format_desc,
num_pixels,
base_ptr,
offset,
i, j);
lp_build_conv(builder,
lp_build_conv(gallivm,
tmp_type, type,
&tmp, 1, &tmp, 1);
@ -505,51 +512,52 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* or incentive to optimize.
*/
LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
char name[256];
LLVMTypeRef i8t = LLVMInt8Type();
LLVMTypeRef i8t = LLVMInt8TypeInContext(gallivm->context);
LLVMTypeRef pi8t = LLVMPointerType(i8t, 0);
LLVMTypeRef i32t = LLVMInt32Type();
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef function;
LLVMValueRef tmp_ptr;
LLVMValueRef tmp;
LLVMValueRef res;
unsigned k;
util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_8unorm",
format_desc->short_name);
if (gallivm_debug & GALLIVM_DEBUG_PERF) {
debug_printf("%s: falling back to %s\n", __FUNCTION__, name);
debug_printf("%s: falling back to util_format_%s_fetch_rgba_8unorm\n",
__FUNCTION__, format_desc->short_name);
}
/*
* Declare and bind format_desc->fetch_rgba_8unorm().
*/
function = LLVMGetNamedFunction(module, name);
if (!function) {
{
/*
* Function to call looks like:
* fetch(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
*/
LLVMTypeRef ret_type;
LLVMTypeRef arg_types[4];
LLVMTypeRef function_type;
ret_type = LLVMVoidType();
ret_type = LLVMVoidTypeInContext(gallivm->context);
arg_types[0] = pi8t;
arg_types[1] = pi8t;
arg_types[3] = arg_types[2] = LLVMIntType(sizeof(unsigned) * 8);
function_type = LLVMFunctionType(ret_type, arg_types, Elements(arg_types), 0);
function = LLVMAddFunction(module, name, function_type);
arg_types[2] = i32t;
arg_types[3] = i32t;
function_type = LLVMFunctionType(ret_type, arg_types,
Elements(arg_types), 0);
LLVMSetFunctionCallConv(function, LLVMCCallConv);
LLVMSetLinkage(function, LLVMExternalLinkage);
/* make const pointer for the C fetch_rgba_8unorm function */
function = lp_build_const_int_pointer(gallivm,
func_to_pointer((func_pointer) format_desc->fetch_rgba_8unorm));
assert(LLVMIsDeclaration(function));
LLVMAddGlobalMapping(lp_build_engine, function,
func_to_pointer((func_pointer)format_desc->fetch_rgba_8unorm));
/* cast the callee pointer to the function's type */
function = LLVMBuildBitCast(builder, function,
LLVMPointerType(function_type, 0),
"cast callee");
}
tmp_ptr = lp_build_alloca(builder, i32t, "");
tmp_ptr = lp_build_alloca(gallivm, i32t, "");
res = LLVMGetUndef(LLVMVectorType(i32t, num_pixels));
@ -559,11 +567,11 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
*/
for (k = 0; k < num_pixels; ++k) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, k);
LLVMValueRef args[4];
args[0] = LLVMBuildBitCast(builder, tmp_ptr, pi8t, "");
args[1] = lp_build_gather_elem_ptr(builder, num_pixels,
args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels,
base_ptr, offset, k);
if (num_pixels == 1) {
@ -608,51 +616,58 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
* or incentive to optimize.
*/
LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
char name[256];
LLVMTypeRef f32t = LLVMFloatType();
LLVMTypeRef f32t = LLVMFloatTypeInContext(gallivm->context);
LLVMTypeRef f32x4t = LLVMVectorType(f32t, 4);
LLVMTypeRef pf32t = LLVMPointerType(f32t, 0);
LLVMTypeRef pi8t = LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0);
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef function;
LLVMValueRef tmp_ptr;
LLVMValueRef tmps[LP_MAX_VECTOR_LENGTH/4];
LLVMValueRef res;
unsigned k;
util_snprintf(name, sizeof name, "util_format_%s_fetch_rgba_float",
format_desc->short_name);
if (gallivm_debug & GALLIVM_DEBUG_PERF) {
debug_printf("%s: falling back to %s\n", __FUNCTION__, name);
debug_printf("%s: falling back to util_format_%s_fetch_rgba_float\n",
__FUNCTION__, format_desc->short_name);
}
/*
* Declare and bind format_desc->fetch_rgba_float().
*/
function = LLVMGetNamedFunction(module, name);
if (!function) {
{
/*
* Function to call looks like:
* fetch(float *dst, const uint8_t *src, unsigned i, unsigned j)
*/
LLVMTypeRef ret_type;
LLVMTypeRef arg_types[4];
LLVMTypeRef function_type;
ret_type = LLVMVoidType();
ret_type = LLVMVoidTypeInContext(gallivm->context);
arg_types[0] = pf32t;
arg_types[1] = LLVMPointerType(LLVMInt8Type(), 0);
arg_types[3] = arg_types[2] = LLVMIntType(sizeof(unsigned) * 8);
function_type = LLVMFunctionType(ret_type, arg_types, Elements(arg_types), 0);
function = LLVMAddFunction(module, name, function_type);
arg_types[1] = pi8t;
arg_types[2] = i32t;
arg_types[3] = i32t;
function_type = LLVMFunctionType(ret_type, arg_types,
Elements(arg_types), 0);
LLVMSetFunctionCallConv(function, LLVMCCallConv);
LLVMSetLinkage(function, LLVMExternalLinkage);
/* Note: we're using this casting here instead of LLVMAddGlobalMapping()
* to work around a bug in LLVM 2.6, and for efficiency/simplicity.
*/
assert(LLVMIsDeclaration(function));
/* make const pointer for the C fetch_rgba_float function */
function = lp_build_const_int_pointer(gallivm,
func_to_pointer((func_pointer) format_desc->fetch_rgba_float));
LLVMAddGlobalMapping(lp_build_engine, function,
func_to_pointer((func_pointer)format_desc->fetch_rgba_float));
/* cast the callee pointer to the function's type */
function = LLVMBuildBitCast(builder, function,
LLVMPointerType(function_type, 0),
"cast callee");
}
tmp_ptr = lp_build_alloca(builder, f32x4t, "");
tmp_ptr = lp_build_alloca(gallivm, f32x4t, "");
/*
* Invoke format_desc->fetch_rgba_float() for each pixel and insert the result
@ -663,7 +678,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef args[4];
args[0] = LLVMBuildBitCast(builder, tmp_ptr, pf32t, "");
args[1] = lp_build_gather_elem_ptr(builder, num_pixels,
args[1] = lp_build_gather_elem_ptr(gallivm, num_pixels,
base_ptr, offset, k);
if (num_pixels == 1) {
@ -671,7 +686,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
args[3] = j;
}
else {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, k);
args[2] = LLVMBuildExtractElement(builder, i, index, "");
args[3] = LLVMBuildExtractElement(builder, j, index, "");
}
@ -681,7 +696,7 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
tmps[k] = LLVMBuildLoad(builder, tmp_ptr, "");
}
lp_build_conv(builder,
lp_build_conv(gallivm,
lp_float32_vec4_type(),
type,
tmps, num_pixels, &res, 1);
@ -690,5 +705,5 @@ lp_build_fetch_rgba_aos(LLVMBuilderRef builder,
}
assert(0);
return lp_build_undef(type);
return lp_build_undef(gallivm, type);
}

View file

@ -97,12 +97,13 @@ lp_build_format_swizzle_soa(const struct util_format_description *format_desc,
* \param rgba_out returns the SoA R,G,B,A vectors
*/
void
lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
lp_build_unpack_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef packed,
LLVMValueRef rgba_out[4])
{
LLVMBuilderRef builder = gallivm->builder;
struct lp_build_context bld;
LLVMValueRef inputs[4];
unsigned start;
@ -116,7 +117,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
assert(type.floating);
assert(type.width == 32);
lp_build_context_init(&bld, builder, type);
lp_build_context_init(&bld, gallivm, type);
/* Decode the input vector components */
start = 0;
@ -129,7 +130,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
switch(format_desc->channel[chan].type) {
case UTIL_FORMAT_TYPE_VOID:
input = lp_build_undef(type);
input = lp_build_undef(gallivm, type);
break;
case UTIL_FORMAT_TYPE_UNSIGNED:
@ -138,7 +139,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
*/
if (start) {
input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(type, start), "");
input = LLVMBuildLShr(builder, input, lp_build_const_int_vec(gallivm, type, start), "");
}
/*
@ -147,7 +148,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (stop < format_desc->block.bits) {
unsigned mask = ((unsigned long long)1 << width) - 1;
input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(type, mask), "");
input = LLVMBuildAnd(builder, input, lp_build_const_int_vec(gallivm, type, mask), "");
}
/*
@ -156,14 +157,15 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (type.floating) {
if(format_desc->channel[chan].normalized)
input = lp_build_unsigned_norm_to_float(builder, width, type, input);
input = lp_build_unsigned_norm_to_float(gallivm, width, type, input);
else
input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
input = LLVMBuildSIToFP(builder, input,
lp_build_vec_type(gallivm, type), "");
}
else {
/* FIXME */
assert(0);
input = lp_build_undef(type);
input = lp_build_undef(gallivm, type);
}
break;
@ -175,7 +177,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (stop < type.width) {
unsigned bits = type.width - stop;
LLVMValueRef bits_val = lp_build_const_int_vec(type, bits);
LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits);
input = LLVMBuildShl(builder, input, bits_val, "");
}
@ -185,7 +187,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
if (format_desc->channel[chan].size < type.width) {
unsigned bits = type.width - format_desc->channel[chan].size;
LLVMValueRef bits_val = lp_build_const_int_vec(type, bits);
LLVMValueRef bits_val = lp_build_const_int_vec(gallivm, type, bits);
input = LLVMBuildAShr(builder, input, bits_val, "");
}
@ -194,17 +196,17 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
*/
if (type.floating) {
input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), "");
if (format_desc->channel[chan].normalized) {
double scale = 1.0 / ((1 << (format_desc->channel[chan].size - 1)) - 1);
LLVMValueRef scale_val = lp_build_const_vec(type, scale);
LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale);
input = LLVMBuildFMul(builder, input, scale_val, "");
}
}
else {
/* FIXME */
assert(0);
input = lp_build_undef(type);
input = lp_build_undef(gallivm, type);
}
break;
@ -214,32 +216,32 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
assert(start == 0);
assert(stop == 32);
assert(type.width == 32);
input = LLVMBuildBitCast(builder, input, lp_build_vec_type(type), "");
input = LLVMBuildBitCast(builder, input, lp_build_vec_type(gallivm, type), "");
}
else {
/* FIXME */
assert(0);
input = lp_build_undef(type);
input = lp_build_undef(gallivm, type);
}
break;
case UTIL_FORMAT_TYPE_FIXED:
if (type.floating) {
double scale = 1.0 / ((1 << (format_desc->channel[chan].size/2)) - 1);
LLVMValueRef scale_val = lp_build_const_vec(type, scale);
input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(type), "");
LLVMValueRef scale_val = lp_build_const_vec(gallivm, type, scale);
input = LLVMBuildSIToFP(builder, input, lp_build_vec_type(gallivm, type), "");
input = LLVMBuildFMul(builder, input, scale_val, "");
}
else {
/* FIXME */
assert(0);
input = lp_build_undef(type);
input = lp_build_undef(gallivm, type);
}
break;
default:
assert(0);
input = lp_build_undef(type);
input = lp_build_undef(gallivm, type);
break;
}
@ -253,16 +255,17 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
void
lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
lp_build_rgba8_to_f32_soa(struct gallivm_state *gallivm,
struct lp_type dst_type,
LLVMValueRef packed,
LLVMValueRef *rgba)
{
LLVMValueRef mask = lp_build_const_int_vec(dst_type, 0xff);
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef mask = lp_build_const_int_vec(gallivm, dst_type, 0xff);
unsigned chan;
packed = LLVMBuildBitCast(builder, packed,
lp_build_int_vec_type(dst_type), "");
lp_build_int_vec_type(gallivm, dst_type), "");
/* Decode the input vector components */
for (chan = 0; chan < 4; ++chan) {
@ -274,12 +277,12 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
if (start)
input = LLVMBuildLShr(builder, input,
lp_build_const_int_vec(dst_type, start), "");
lp_build_const_int_vec(gallivm, dst_type, start), "");
if (stop < 32)
input = LLVMBuildAnd(builder, input, mask, "");
input = lp_build_unsigned_norm_to_float(builder, 8, dst_type, input);
input = lp_build_unsigned_norm_to_float(gallivm, 8, dst_type, input);
rgba[chan] = input;
}
@ -303,7 +306,7 @@ lp_build_rgba8_to_f32_soa(LLVMBuilderRef builder,
* be in [0, block_width-1] and j will be in [0, block_height-1].
*/
void
lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
lp_build_fetch_rgba_soa(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
struct lp_type type,
LLVMValueRef base_ptr,
@ -312,6 +315,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
LLVMValueRef j,
LLVMValueRef rgba_out[4])
{
LLVMBuilderRef builder = gallivm->builder;
if (format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN &&
(format_desc->colorspace == UTIL_FORMAT_COLORSPACE_RGB ||
@ -334,7 +338,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
* gather the texels from the texture
* Ex: packed = {BGRA, BGRA, BGRA, BGRA}.
*/
packed = lp_build_gather(builder,
packed = lp_build_gather(gallivm,
type.length,
format_desc->block.bits,
type.width,
@ -343,7 +347,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
/*
* convert texels to float rgba
*/
lp_build_unpack_rgba_soa(builder,
lp_build_unpack_rgba_soa(gallivm,
format_desc,
type,
packed, rgba_out);
@ -364,10 +368,10 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
tmp_type.length = type.length * 4;
tmp_type.norm = TRUE;
tmp = lp_build_fetch_rgba_aos(builder, format_desc, tmp_type,
tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type,
base_ptr, offset, i, j);
lp_build_rgba8_to_f32_soa(builder,
lp_build_rgba8_to_f32_soa(gallivm,
type,
tmp,
rgba_out);
@ -397,23 +401,24 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
tmp_type.length = 4;
for (chan = 0; chan < 4; ++chan) {
rgba_out[chan] = lp_build_undef(type);
rgba_out[chan] = lp_build_undef(gallivm, type);
}
/* loop over number of pixels */
for(k = 0; k < type.length; ++k) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), k, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, k);
LLVMValueRef offset_elem;
LLVMValueRef i_elem, j_elem;
LLVMValueRef tmp;
offset_elem = LLVMBuildExtractElement(builder, offset, index, "");
offset_elem = LLVMBuildExtractElement(builder, offset,
index, "");
i_elem = LLVMBuildExtractElement(builder, i, index, "");
j_elem = LLVMBuildExtractElement(builder, j, index, "");
/* Get a single float[4]={R,G,B,A} pixel */
tmp = lp_build_fetch_rgba_aos(builder, format_desc, tmp_type,
tmp = lp_build_fetch_rgba_aos(gallivm, format_desc, tmp_type,
base_ptr, offset_elem,
i_elem, j_elem);
@ -422,7 +427,7 @@ lp_build_fetch_rgba_soa(LLVMBuilderRef builder,
* position = 'index'.
*/
for (chan = 0; chan < 4; ++chan) {
LLVMValueRef chan_val = LLVMConstInt(LLVMInt32Type(), chan, 0),
LLVMValueRef chan_val = lp_build_const_int32(gallivm, chan),
tmp_chan = LLVMBuildExtractElement(builder, tmp, chan_val, "");
rgba_out[chan] = LLVMBuildInsertElement(builder, rgba_out[chan],
tmp_chan, index, "");

View file

@ -43,6 +43,7 @@
#include "lp_bld_conv.h"
#include "lp_bld_gather.h"
#include "lp_bld_format.h"
#include "lp_bld_init.h"
#include "lp_bld_logic.h"
/**
@ -51,7 +52,7 @@
* @param i is a <n x i32> vector with the x pixel coordinate (0 or 1)
*/
static void
uyvy_to_yuv_soa(LLVMBuilderRef builder,
uyvy_to_yuv_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i,
@ -59,6 +60,7 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef *u,
LLVMValueRef *v)
{
LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef mask;
@ -86,25 +88,25 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef sel, tmp, tmp2;
struct lp_build_context bld32;
lp_build_context_init(&bld32, builder, type);
lp_build_context_init(&bld32, gallivm, type);
tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 8), "");
tmp2 = LLVMBuildLShr(builder, tmp, lp_build_const_int_vec(type, 16), "");
sel = lp_build_compare(builder, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(type, 0));
tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), "");
tmp2 = LLVMBuildLShr(builder, tmp, lp_build_const_int_vec(gallivm, type, 16), "");
sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0));
*y = lp_build_select(&bld32, sel, tmp, tmp2);
} else
#endif
{
LLVMValueRef shift;
shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(type, 16), "");
shift = LLVMBuildAdd(builder, shift, lp_build_const_int_vec(type, 8), "");
shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), "");
shift = LLVMBuildAdd(builder, shift, lp_build_const_int_vec(gallivm, type, 8), "");
*y = LLVMBuildLShr(builder, packed, shift, "");
}
*u = packed;
*v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 16), "");
*v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), "");
mask = lp_build_const_int_vec(type, 0xff);
mask = lp_build_const_int_vec(gallivm, type, 0xff);
*y = LLVMBuildAnd(builder, *y, mask, "y");
*u = LLVMBuildAnd(builder, *u, mask, "u");
@ -118,7 +120,7 @@ uyvy_to_yuv_soa(LLVMBuilderRef builder,
* @param i is a <n x i32> vector with the x pixel coordinate (0 or 1)
*/
static void
yuyv_to_yuv_soa(LLVMBuilderRef builder,
yuyv_to_yuv_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i,
@ -126,6 +128,7 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef *u,
LLVMValueRef *v)
{
LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef mask;
@ -153,23 +156,23 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
LLVMValueRef sel, tmp;
struct lp_build_context bld32;
lp_build_context_init(&bld32, builder, type);
lp_build_context_init(&bld32, gallivm, type);
tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 16), "");
sel = lp_build_compare(builder, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(type, 0));
tmp = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 16), "");
sel = lp_build_compare(gallivm, type, PIPE_FUNC_EQUAL, i, lp_build_const_int_vec(gallivm, type, 0));
*y = lp_build_select(&bld32, sel, packed, tmp);
} else
#endif
{
LLVMValueRef shift;
shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(type, 16), "");
shift = LLVMBuildMul(builder, i, lp_build_const_int_vec(gallivm, type, 16), "");
*y = LLVMBuildLShr(builder, packed, shift, "");
}
*u = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 8), "");
*v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(type, 24), "");
*u = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 8), "");
*v = LLVMBuildLShr(builder, packed, lp_build_const_int_vec(gallivm, type, 24), "");
mask = lp_build_const_int_vec(type, 0xff);
mask = lp_build_const_int_vec(gallivm, type, 0xff);
*y = LLVMBuildAnd(builder, *y, mask, "y");
*u = LLVMBuildAnd(builder, *u, mask, "u");
@ -178,11 +181,12 @@ yuyv_to_yuv_soa(LLVMBuilderRef builder,
static INLINE void
yuv_to_rgb_soa(LLVMBuilderRef builder,
yuv_to_rgb_soa(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef y, LLVMValueRef u, LLVMValueRef v,
LLVMValueRef *r, LLVMValueRef *g, LLVMValueRef *b)
{
LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
struct lp_build_context bld;
@ -203,7 +207,7 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
type.width = 32;
type.length = n;
lp_build_context_init(&bld, builder, type);
lp_build_context_init(&bld, gallivm, type);
assert(lp_check_value(type, y));
assert(lp_check_value(type, u));
@ -213,17 +217,17 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
* Constants
*/
c0 = lp_build_const_int_vec(type, 0);
c8 = lp_build_const_int_vec(type, 8);
c16 = lp_build_const_int_vec(type, 16);
c128 = lp_build_const_int_vec(type, 128);
c255 = lp_build_const_int_vec(type, 255);
c0 = lp_build_const_int_vec(gallivm, type, 0);
c8 = lp_build_const_int_vec(gallivm, type, 8);
c16 = lp_build_const_int_vec(gallivm, type, 16);
c128 = lp_build_const_int_vec(gallivm, type, 128);
c255 = lp_build_const_int_vec(gallivm, type, 255);
cy = lp_build_const_int_vec(type, 298);
cug = lp_build_const_int_vec(type, -100);
cub = lp_build_const_int_vec(type, 516);
cvr = lp_build_const_int_vec(type, 409);
cvg = lp_build_const_int_vec(type, -208);
cy = lp_build_const_int_vec(gallivm, type, 298);
cug = lp_build_const_int_vec(gallivm, type, -100);
cub = lp_build_const_int_vec(gallivm, type, 516);
cvr = lp_build_const_int_vec(gallivm, type, 409);
cvg = lp_build_const_int_vec(gallivm, type, -208);
/*
* y -= 16;
@ -276,10 +280,11 @@ yuv_to_rgb_soa(LLVMBuilderRef builder,
static LLVMValueRef
rgb_to_rgba_aos(LLVMBuilderRef builder,
rgb_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef r, LLVMValueRef g, LLVMValueRef b)
{
LLVMBuilderRef builder = gallivm->builder;
struct lp_type type;
LLVMValueRef a;
LLVMValueRef rgba;
@ -298,9 +303,9 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
*/
r = r;
g = LLVMBuildShl(builder, g, lp_build_const_int_vec(type, 8), "");
b = LLVMBuildShl(builder, b, lp_build_const_int_vec(type, 16), "");
a = lp_build_const_int_vec(type, 0xff000000);
g = LLVMBuildShl(builder, g, lp_build_const_int_vec(gallivm, type, 8), "");
b = LLVMBuildShl(builder, b, lp_build_const_int_vec(gallivm, type, 16), "");
a = lp_build_const_int_vec(gallivm, type, 0xff000000);
rgba = r;
rgba = LLVMBuildOr(builder, rgba, g, "");
@ -308,7 +313,7 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
rgba = LLVMBuildOr(builder, rgba, a, "");
rgba = LLVMBuildBitCast(builder, rgba,
LLVMVectorType(LLVMInt8Type(), 4*n), "");
LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n), "");
return rgba;
}
@ -318,7 +323,7 @@ rgb_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed UYVY to <4n x i8> RGBA AoS
*/
static LLVMValueRef
uyvy_to_rgba_aos(LLVMBuilderRef builder,
uyvy_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@ -327,9 +332,9 @@ uyvy_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
uyvy_to_yuv_soa(builder, n, packed, i, &y, &u, &v);
yuv_to_rgb_soa(builder, n, y, u, v, &r, &g, &b);
rgba = rgb_to_rgba_aos(builder, n, r, g, b);
uyvy_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v);
yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@ -339,7 +344,7 @@ uyvy_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed YUYV to <4n x i8> RGBA AoS
*/
static LLVMValueRef
yuyv_to_rgba_aos(LLVMBuilderRef builder,
yuyv_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@ -348,9 +353,9 @@ yuyv_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
yuyv_to_yuv_soa(builder, n, packed, i, &y, &u, &v);
yuv_to_rgb_soa(builder, n, y, u, v, &r, &g, &b);
rgba = rgb_to_rgba_aos(builder, n, r, g, b);
yuyv_to_yuv_soa(gallivm, n, packed, i, &y, &u, &v);
yuv_to_rgb_soa(gallivm, n, y, u, v, &r, &g, &b);
rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@ -360,7 +365,7 @@ yuyv_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed RG_BG to <4n x i8> RGBA AoS
*/
static LLVMValueRef
rgbg_to_rgba_aos(LLVMBuilderRef builder,
rgbg_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@ -368,8 +373,8 @@ rgbg_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
uyvy_to_yuv_soa(builder, n, packed, i, &g, &r, &b);
rgba = rgb_to_rgba_aos(builder, n, r, g, b);
uyvy_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b);
rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@ -379,7 +384,7 @@ rgbg_to_rgba_aos(LLVMBuilderRef builder,
* Convert from <n x i32> packed GR_GB to <4n x i8> RGBA AoS
*/
static LLVMValueRef
grgb_to_rgba_aos(LLVMBuilderRef builder,
grgb_to_rgba_aos(struct gallivm_state *gallivm,
unsigned n,
LLVMValueRef packed,
LLVMValueRef i)
@ -387,8 +392,8 @@ grgb_to_rgba_aos(LLVMBuilderRef builder,
LLVMValueRef r, g, b;
LLVMValueRef rgba;
yuyv_to_yuv_soa(builder, n, packed, i, &g, &r, &b);
rgba = rgb_to_rgba_aos(builder, n, r, g, b);
yuyv_to_yuv_soa(gallivm, n, packed, i, &g, &r, &b);
rgba = rgb_to_rgba_aos(gallivm, n, r, g, b);
return rgba;
}
@ -401,7 +406,7 @@ grgb_to_rgba_aos(LLVMBuilderRef builder,
* @return a <4*n x i8> vector with the pixel RGBA values in AoS
*/
LLVMValueRef
lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
lp_build_fetch_subsampled_rgba_aos(struct gallivm_state *gallivm,
const struct util_format_description *format_desc,
unsigned n,
LLVMValueRef base_ptr,
@ -417,26 +422,26 @@ lp_build_fetch_subsampled_rgba_aos(LLVMBuilderRef builder,
assert(format_desc->block.width == 2);
assert(format_desc->block.height == 1);
packed = lp_build_gather(builder, n, 32, 32, base_ptr, offset);
packed = lp_build_gather(gallivm, n, 32, 32, base_ptr, offset);
(void)j;
switch (format_desc->format) {
case PIPE_FORMAT_UYVY:
rgba = uyvy_to_rgba_aos(builder, n, packed, i);
rgba = uyvy_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_YUYV:
rgba = yuyv_to_rgba_aos(builder, n, packed, i);
rgba = yuyv_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_R8G8_B8G8_UNORM:
rgba = rgbg_to_rgba_aos(builder, n, packed, i);
rgba = rgbg_to_rgba_aos(gallivm, n, packed, i);
break;
case PIPE_FORMAT_G8R8_G8B8_UNORM:
rgba = grgb_to_rgba_aos(builder, n, packed, i);
rgba = grgb_to_rgba_aos(gallivm, n, packed, i);
break;
default:
assert(0);
rgba = LLVMGetUndef(LLVMVectorType(LLVMInt8Type(), 4*n));
rgba = LLVMGetUndef(LLVMVectorType(LLVMInt8TypeInContext(gallivm->context), 4*n));
break;
}

View file

@ -31,6 +31,7 @@
#include "lp_bld_const.h"
#include "lp_bld_format.h"
#include "lp_bld_gather.h"
#include "lp_bld_init.h"
/**
@ -39,7 +40,7 @@
* @sa lp_build_gather()
*/
LLVMValueRef
lp_build_gather_elem_ptr(LLVMBuilderRef builder,
lp_build_gather_elem_ptr(struct gallivm_state *gallivm,
unsigned length,
LLVMValueRef base_ptr,
LLVMValueRef offsets,
@ -48,17 +49,17 @@ lp_build_gather_elem_ptr(LLVMBuilderRef builder,
LLVMValueRef offset;
LLVMValueRef ptr;
assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8Type(), 0));
assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0));
if (length == 1) {
assert(i == 0);
offset = offsets;
} else {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
offset = LLVMBuildExtractElement(builder, offsets, index, "");
LLVMValueRef index = lp_build_const_int32(gallivm, i);
offset = LLVMBuildExtractElement(gallivm->builder, offsets, index, "");
}
ptr = LLVMBuildGEP(builder, base_ptr, &offset, 1, "");
ptr = LLVMBuildGEP(gallivm->builder, base_ptr, &offset, 1, "");
return ptr;
}
@ -70,7 +71,7 @@ lp_build_gather_elem_ptr(LLVMBuilderRef builder,
* @sa lp_build_gather()
*/
LLVMValueRef
lp_build_gather_elem(LLVMBuilderRef builder,
lp_build_gather_elem(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@ -78,23 +79,23 @@ lp_build_gather_elem(LLVMBuilderRef builder,
LLVMValueRef offsets,
unsigned i)
{
LLVMTypeRef src_type = LLVMIntType(src_width);
LLVMTypeRef src_type = LLVMIntTypeInContext(gallivm->context, src_width);
LLVMTypeRef src_ptr_type = LLVMPointerType(src_type, 0);
LLVMTypeRef dst_elem_type = LLVMIntType(dst_width);
LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width);
LLVMValueRef ptr;
LLVMValueRef res;
assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8Type(), 0));
assert(LLVMTypeOf(base_ptr) == LLVMPointerType(LLVMInt8TypeInContext(gallivm->context), 0));
ptr = lp_build_gather_elem_ptr(builder, length, base_ptr, offsets, i);
ptr = LLVMBuildBitCast(builder, ptr, src_ptr_type, "");
res = LLVMBuildLoad(builder, ptr, "");
ptr = lp_build_gather_elem_ptr(gallivm, length, base_ptr, offsets, i);
ptr = LLVMBuildBitCast(gallivm->builder, ptr, src_ptr_type, "");
res = LLVMBuildLoad(gallivm->builder, ptr, "");
assert(src_width <= dst_width);
if (src_width > dst_width)
res = LLVMBuildTrunc(builder, res, dst_elem_type, "");
res = LLVMBuildTrunc(gallivm->builder, res, dst_elem_type, "");
if (src_width < dst_width)
res = LLVMBuildZExt(builder, res, dst_elem_type, "");
res = LLVMBuildZExt(gallivm->builder, res, dst_elem_type, "");
return res;
}
@ -112,7 +113,7 @@ lp_build_gather_elem(LLVMBuilderRef builder,
* @param offsets vector with offsets
*/
LLVMValueRef
lp_build_gather(LLVMBuilderRef builder,
lp_build_gather(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@ -123,24 +124,24 @@ lp_build_gather(LLVMBuilderRef builder,
if (length == 1) {
/* Scalar */
return lp_build_gather_elem(builder, length,
return lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, 0);
} else {
/* Vector */
LLVMTypeRef dst_elem_type = LLVMIntType(dst_width);
LLVMTypeRef dst_elem_type = LLVMIntTypeInContext(gallivm->context, dst_width);
LLVMTypeRef dst_vec_type = LLVMVectorType(dst_elem_type, length);
unsigned i;
res = LLVMGetUndef(dst_vec_type);
for (i = 0; i < length; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef elem;
elem = lp_build_gather_elem(builder, length,
elem = lp_build_gather_elem(gallivm, length,
src_width, dst_width,
base_ptr, offsets, i);
res = LLVMBuildInsertElement(builder, res, elem, index, "");
res = LLVMBuildInsertElement(gallivm->builder, res, elem, index, "");
}
}

View file

@ -34,14 +34,14 @@
LLVMValueRef
lp_build_gather_elem_ptr(LLVMBuilderRef builder,
lp_build_gather_elem_ptr(struct gallivm_state *gallivm,
unsigned length,
LLVMValueRef base_ptr,
LLVMValueRef offsets,
unsigned i);
LLVMValueRef
lp_build_gather_elem(LLVMBuilderRef builder,
lp_build_gather_elem(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,
@ -50,7 +50,7 @@ lp_build_gather_elem(LLVMBuilderRef builder,
unsigned i);
LLVMValueRef
lp_build_gather(LLVMBuilderRef builder,
lp_build_gather(struct gallivm_state *gallivm,
unsigned length,
unsigned src_width,
unsigned dst_width,

View file

@ -29,6 +29,8 @@
#include "pipe/p_compiler.h"
#include "util/u_cpu_detect.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
#include "util/u_simple_list.h"
#include "lp_bld_debug.h"
#include "lp_bld_init.h"
@ -45,6 +47,7 @@ static const struct debug_named_value lp_bld_debug_flags[] = {
{ "nopt", GALLIVM_DEBUG_NO_OPT, NULL },
{ "perf", GALLIVM_DEBUG_PERF, NULL },
{ "no_brilinear", GALLIVM_DEBUG_NO_BRILINEAR, NULL },
{ "gc", GALLIVM_DEBUG_GC, NULL },
DEBUG_NAMED_VALUE_END
};
@ -52,11 +55,7 @@ DEBUG_GET_ONCE_FLAGS_OPTION(gallivm_debug, "GALLIVM_DEBUG", lp_bld_debug_flags,
#endif
LLVMModuleRef lp_build_module = NULL;
LLVMExecutionEngineRef lp_build_engine = NULL;
LLVMModuleProviderRef lp_build_provider = NULL;
LLVMTargetDataRef lp_build_target = NULL;
LLVMPassManagerRef lp_build_pass = NULL;
static boolean gallivm_initialized = FALSE;
/*
@ -82,6 +81,19 @@ enum LLVM_CodeGenOpt_Level {
};
/**
* LLVM 2.6 permits only one ExecutionEngine to be created. This is it.
*/
static LLVMExecutionEngineRef GlobalEngine = NULL;
/**
* Same gallivm state shared by all contexts.
*/
static struct gallivm_state *GlobalGallivm = NULL;
extern void
lp_register_oprofile_jit_event_listener(LLVMExecutionEngineRef EE);
@ -89,6 +101,289 @@ extern void
lp_set_target_options(void);
/**
* Create the LLVM (optimization) pass manager and install
* relevant optimization passes.
* \return TRUE for success, FALSE for failure
*/
static boolean
create_pass_manager(struct gallivm_state *gallivm)
{
assert(!gallivm->passmgr);
gallivm->passmgr = LLVMCreateFunctionPassManager(gallivm->provider);
if (!gallivm->passmgr)
return FALSE;
LLVMAddTargetData(gallivm->target, gallivm->passmgr);
if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
/* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
* but there are more on SVN.
* TODO: Add more passes.
*/
LLVMAddCFGSimplificationPass(gallivm->passmgr);
if (HAVE_LLVM >= 0x207 && sizeof(void*) == 4) {
/* For LLVM >= 2.7 and 32-bit build, use this order of passes to
* avoid generating bad code.
* Test with piglit glsl-vs-sqrt-zero test.
*/
LLVMAddConstantPropagationPass(gallivm->passmgr);
LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
}
else {
LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
LLVMAddConstantPropagationPass(gallivm->passmgr);
}
if (util_cpu_caps.has_sse4_1) {
/* FIXME: There is a bug in this pass, whereby the combination
* of fptosi and sitofp (necessary for trunc/floor/ceil/round
* implementation) somehow becomes invalid code.
*/
LLVMAddInstructionCombiningPass(gallivm->passmgr);
}
LLVMAddGVNPass(gallivm->passmgr);
}
else {
/* We need at least this pass to prevent the backends to fail in
* unexpected ways.
*/
LLVMAddPromoteMemoryToRegisterPass(gallivm->passmgr);
}
return TRUE;
}
/**
* Free gallivm object's LLVM allocations, but not the gallivm object itself.
*/
static void
free_gallivm_state(struct gallivm_state *gallivm)
{
#if HAVE_LLVM >= 0x207 /* XXX or 0x208? */
/* This leads to crashes w/ some versions of LLVM */
LLVMModuleRef mod;
char *error;
if (gallivm->engine && gallivm->provider)
LLVMRemoveModuleProvider(gallivm->engine, gallivm->provider,
&mod, &error);
#endif
#if 0
/* XXX this seems to crash with all versions of LLVM */
if (gallivm->provider)
LLVMDisposeModuleProvider(gallivm->provider);
#endif
if (gallivm->passmgr)
LLVMDisposePassManager(gallivm->passmgr);
#if HAVE_LLVM >= 0x207
if (gallivm->module)
LLVMDisposeModule(gallivm->module);
#endif
#if 0
/* Don't free the exec engine, it's a global/singleton */
if (gallivm->engine)
LLVMDisposeExecutionEngine(gallivm->engine);
#endif
#if 0
/* Don't free the TargetData, it's owned by the exec engine */
LLVMDisposeTargetData(gallivm->target);
#endif
if (gallivm->context)
LLVMContextDispose(gallivm->context);
if (gallivm->builder)
LLVMDisposeBuilder(gallivm->builder);
gallivm->engine = NULL;
gallivm->target = NULL;
gallivm->module = NULL;
gallivm->provider = NULL;
gallivm->passmgr = NULL;
gallivm->context = NULL;
gallivm->builder = NULL;
}
/**
* Allocate gallivm LLVM objects.
* \return TRUE for success, FALSE for failure
*/
static boolean
init_gallivm_state(struct gallivm_state *gallivm)
{
assert(gallivm_initialized);
assert(!gallivm->context);
assert(!gallivm->module);
assert(!gallivm->provider);
gallivm->context = LLVMContextCreate();
if (!gallivm->context)
goto fail;
gallivm->module = LLVMModuleCreateWithNameInContext("gallivm",
gallivm->context);
if (!gallivm->module)
goto fail;
gallivm->provider =
LLVMCreateModuleProviderForExistingModule(gallivm->module);
if (!gallivm->provider)
goto fail;
if (!GlobalEngine) {
/* We can only create one LLVMExecutionEngine (w/ LLVM 2.6 anyway) */
enum LLVM_CodeGenOpt_Level optlevel;
char *error = NULL;
if (gallivm_debug & GALLIVM_DEBUG_NO_OPT) {
optlevel = None;
}
else {
optlevel = Default;
}
if (LLVMCreateJITCompiler(&GlobalEngine, gallivm->provider,
(unsigned) optlevel, &error)) {
_debug_printf("%s\n", error);
LLVMDisposeMessage(error);
goto fail;
}
#if defined(DEBUG) || defined(PROFILE)
lp_register_oprofile_jit_event_listener(GlobalEngine);
#endif
}
gallivm->engine = GlobalEngine;
LLVMAddModuleProvider(gallivm->engine, gallivm->provider);//new
gallivm->target = LLVMGetExecutionEngineTargetData(gallivm->engine);
if (!gallivm->target)
goto fail;
if (!create_pass_manager(gallivm))
goto fail;
gallivm->builder = LLVMCreateBuilderInContext(gallivm->context);
if (!gallivm->builder)
goto fail;
return TRUE;
fail:
free_gallivm_state(gallivm);
return FALSE;
}
struct callback
{
garbage_collect_callback_func func;
void *cb_data;
struct callback *prev, *next;
};
/** list of all garbage collector callbacks */
static struct callback callback_list = {NULL, NULL, NULL, NULL};
/**
* Register a function with gallivm which will be called when we
* do garbage collection.
*/
void
gallivm_register_garbage_collector_callback(garbage_collect_callback_func func,
void *cb_data)
{
struct callback *cb;
if (!callback_list.prev) {
make_empty_list(&callback_list);
}
/* see if already in list */
foreach(cb, &callback_list) {
if (cb->func == func && cb->cb_data == cb_data)
return;
}
/* add to list */
cb = CALLOC_STRUCT(callback);
if (cb) {
cb->func = func;
cb->cb_data = cb_data;
insert_at_head(&callback_list, cb);
}
}
/**
* Remove a callback.
*/
void
gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func,
void *cb_data)
{
struct callback *cb;
/* search list */
foreach(cb, &callback_list) {
if (cb->func == func && cb->cb_data == cb_data) {
/* found, remove it */
remove_from_list(cb);
return;
}
}
}
/**
* Call the callback functions (which are typically in the
* draw module and llvmpipe driver.
*/
static void
call_garbage_collector_callbacks(void)
{
struct callback *cb;
foreach(cb, &callback_list) {
cb->func(cb->cb_data);
}
}
/**
* Other gallium components using gallivm should call this periodically
* to let us do garbage collection (or at least try to free memory
* accumulated by the LLVM libraries).
*/
void
gallivm_garbage_collect(struct gallivm_state *gallivm)
{
if (gallivm->context) {
if (gallivm_debug & GALLIVM_DEBUG_GC)
debug_printf("***** Doing LLVM garbage collection\n");
call_garbage_collector_callbacks();
free_gallivm_state(gallivm);
init_gallivm_state(gallivm);
}
}
void
lp_build_init(void)
{
@ -102,60 +397,9 @@ lp_build_init(void)
LLVMLinkInJIT();
if (!lp_build_module)
lp_build_module = LLVMModuleCreateWithName("gallivm");
if (!lp_build_provider)
lp_build_provider = LLVMCreateModuleProviderForExistingModule(lp_build_module);
if (!lp_build_engine) {
enum LLVM_CodeGenOpt_Level optlevel;
char *error = NULL;
if (gallivm_debug & GALLIVM_DEBUG_NO_OPT) {
optlevel = None;
}
else {
optlevel = Default;
}
if (LLVMCreateJITCompiler(&lp_build_engine, lp_build_provider,
(unsigned)optlevel, &error)) {
_debug_printf("%s\n", error);
LLVMDisposeMessage(error);
assert(0);
}
#if defined(DEBUG) || defined(PROFILE)
lp_register_oprofile_jit_event_listener(lp_build_engine);
#endif
}
if (!lp_build_target)
lp_build_target = LLVMGetExecutionEngineTargetData(lp_build_engine);
if (!lp_build_pass) {
lp_build_pass = LLVMCreateFunctionPassManager(lp_build_provider);
LLVMAddTargetData(lp_build_target, lp_build_pass);
if ((gallivm_debug & GALLIVM_DEBUG_NO_OPT) == 0) {
/* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
* but there are more on SVN. */
/* TODO: Add more passes */
LLVMAddCFGSimplificationPass(lp_build_pass);
LLVMAddPromoteMemoryToRegisterPass(lp_build_pass);
LLVMAddConstantPropagationPass(lp_build_pass);
LLVMAddInstructionCombiningPass(lp_build_pass);
LLVMAddGVNPass(lp_build_pass);
} else {
/* We need at least this pass to prevent the backends to fail in
* unexpected ways.
*/
LLVMAddPromoteMemoryToRegisterPass(lp_build_pass);
}
}
util_cpu_detect();
gallivm_initialized = TRUE;
#if 0
/* For simulating less capable machines */
@ -166,6 +410,39 @@ lp_build_init(void)
}
/**
* Create a new gallivm_state object.
* Note that we return a singleton.
*/
struct gallivm_state *
gallivm_create(void)
{
if (!GlobalGallivm) {
GlobalGallivm = CALLOC_STRUCT(gallivm_state);
if (GlobalGallivm) {
if (!init_gallivm_state(GlobalGallivm)) {
FREE(GlobalGallivm);
GlobalGallivm = NULL;
}
}
}
return GlobalGallivm;
}
/**
* Destroy a gallivm_state object.
*/
void
gallivm_destroy(struct gallivm_state *gallivm)
{
/* No-op: don't destroy the singleton */
(void) gallivm;
}
/*
* Hack to allow the linking of release LLVM static libraries on a debug build.
*

View file

@ -30,24 +30,53 @@
#define LP_BLD_INIT_H
#include "pipe/p_compiler.h"
#include "lp_bld.h"
#include <llvm-c/ExecutionEngine.h>
extern LLVMModuleRef lp_build_module;
extern LLVMExecutionEngineRef lp_build_engine;
extern LLVMModuleProviderRef lp_build_provider;
extern LLVMTargetDataRef lp_build_target;
extern LLVMPassManagerRef lp_build_pass;
struct gallivm_state
{
LLVMModuleRef module;
LLVMExecutionEngineRef engine;
LLVMModuleProviderRef provider;
LLVMTargetDataRef target;
LLVMPassManagerRef passmgr;
LLVMContextRef context;
LLVMBuilderRef builder;
};
void
lp_build_init(void);
extern void
lp_func_delete_body(LLVMValueRef func);
void
gallivm_garbage_collect(struct gallivm_state *gallivm);
typedef void (*garbage_collect_callback_func)(void *cb_data);
void
gallivm_register_garbage_collector_callback(garbage_collect_callback_func func,
void *cb_data);
void
gallivm_remove_garbage_collector_callback(garbage_collect_callback_func func,
void *cb_data);
struct gallivm_state *
gallivm_create(void);
void
gallivm_destroy(struct gallivm_state *gallivm);
extern LLVMValueRef
lp_build_load_volatile(LLVMBuilderRef B, LLVMValueRef PointerVal,
const char *Name);

View file

@ -46,6 +46,7 @@
#include "util/u_debug.h"
#include "lp_bld_const.h"
#include "lp_bld_intr.h"
@ -136,12 +137,13 @@ lp_build_intrinsic_binary(LLVMBuilderRef builder,
LLVMValueRef
lp_build_intrinsic_map(LLVMBuilderRef builder,
lp_build_intrinsic_map(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef *args,
unsigned num_args)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef ret_elem_type = LLVMGetElementType(ret_type);
unsigned n = LLVMGetVectorSize(ret_type);
unsigned i, j;
@ -151,7 +153,7 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
res = LLVMGetUndef(ret_type);
for(i = 0; i < n; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef arg_elems[LP_MAX_FUNC_ARGS];
LLVMValueRef res_elem;
for(j = 0; j < num_args; ++j)
@ -165,17 +167,17 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
LLVMValueRef
lp_build_intrinsic_map_unary(LLVMBuilderRef builder,
lp_build_intrinsic_map_unary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a)
{
return lp_build_intrinsic_map(builder, name, ret_type, &a, 1);
return lp_build_intrinsic_map(gallivm, name, ret_type, &a, 1);
}
LLVMValueRef
lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
lp_build_intrinsic_map_binary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a,
@ -186,7 +188,7 @@ lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
args[0] = a;
args[1] = b;
return lp_build_intrinsic_map(builder, name, ret_type, args, 2);
return lp_build_intrinsic_map(gallivm, name, ret_type, args, 2);
}

View file

@ -38,6 +38,7 @@
#include "gallivm/lp_bld.h"
#include "gallivm/lp_bld_init.h"
/**
@ -77,7 +78,7 @@ lp_build_intrinsic_binary(LLVMBuilderRef builder,
LLVMValueRef
lp_build_intrinsic_map(LLVMBuilderRef builder,
lp_build_intrinsic_map(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef *args,
@ -85,14 +86,14 @@ lp_build_intrinsic_map(LLVMBuilderRef builder,
LLVMValueRef
lp_build_intrinsic_map_unary(LLVMBuilderRef builder,
lp_build_intrinsic_map_unary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a);
LLVMValueRef
lp_build_intrinsic_map_binary(LLVMBuilderRef builder,
lp_build_intrinsic_map_binary(struct gallivm_state *gallivm,
const char *name,
LLVMTypeRef ret_type,
LLVMValueRef a,

View file

@ -39,6 +39,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_debug.h"
#include "lp_bld_logic.h"
@ -70,13 +71,14 @@
* The result values will be 0 for false or ~0 for true.
*/
LLVMValueRef
lp_build_compare(LLVMBuilderRef builder,
lp_build_compare(struct gallivm_state *gallivm,
const struct lp_type type,
unsigned func,
LLVMValueRef a,
LLVMValueRef b)
{
LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
LLVMBuilderRef builder = gallivm->builder;
LLVMTypeRef int_vec_type = lp_build_int_vec_type(gallivm, type);
LLVMValueRef zeros = LLVMConstNull(int_vec_type);
LLVMValueRef ones = LLVMConstAllOnes(int_vec_type);
LLVMValueRef cond;
@ -115,7 +117,7 @@ lp_build_compare(LLVMBuilderRef builder,
if(type.width * type.length == 128) {
if(type.floating && util_cpu_caps.has_sse) {
/* float[4] comparison */
LLVMTypeRef vec_type = lp_build_vec_type(type);
LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
LLVMValueRef args[3];
unsigned cc;
boolean swap;
@ -144,7 +146,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
return lp_build_undef(type);
return lp_build_undef(gallivm, type);
}
if(swap) {
@ -156,7 +158,7 @@ lp_build_compare(LLVMBuilderRef builder,
args[1] = b;
}
args[2] = LLVMConstInt(LLVMInt8Type(), cc, 0);
args[2] = LLVMConstInt(LLVMInt8TypeInContext(gallivm->context), cc, 0);
res = lp_build_intrinsic(builder,
"llvm.x86.sse.cmp.ps",
vec_type,
@ -185,7 +187,7 @@ lp_build_compare(LLVMBuilderRef builder,
const char *pcmpgt;
LLVMValueRef args[2];
LLVMValueRef res;
LLVMTypeRef vec_type = lp_build_vec_type(type);
LLVMTypeRef vec_type = lp_build_vec_type(gallivm, type);
switch (type.width) {
case 8:
@ -202,14 +204,14 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
return lp_build_undef(type);
return lp_build_undef(gallivm, type);
}
/* There are no unsigned comparison instructions. So flip the sign bit
* so that the results match.
*/
if (table[func].gt && !type.sign) {
LLVMValueRef msb = lp_build_const_int_vec(type, (unsigned long long)1 << (type.width - 1));
LLVMValueRef msb = lp_build_const_int_vec(gallivm, type, (unsigned long long)1 << (type.width - 1));
a = LLVMBuildXor(builder, a, msb, "");
b = LLVMBuildXor(builder, b, msb, "");
}
@ -270,7 +272,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
return lp_build_undef(type);
return lp_build_undef(gallivm, type);
}
#if HAVE_LLVM >= 0x0207
@ -289,7 +291,7 @@ lp_build_compare(LLVMBuilderRef builder,
debug_printf("%s: warning: using slow element-wise float"
" vector comparison\n", __FUNCTION__);
for (i = 0; i < type.length; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, i);
cond = LLVMBuildFCmp(builder, op,
LLVMBuildExtractElement(builder, a, index, ""),
LLVMBuildExtractElement(builder, b, index, ""),
@ -326,7 +328,7 @@ lp_build_compare(LLVMBuilderRef builder,
break;
default:
assert(0);
return lp_build_undef(type);
return lp_build_undef(gallivm, type);
}
#if HAVE_LLVM >= 0x0207
@ -348,7 +350,7 @@ lp_build_compare(LLVMBuilderRef builder,
}
for(i = 0; i < type.length; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, i);
cond = LLVMBuildICmp(builder, op,
LLVMBuildExtractElement(builder, a, index, ""),
LLVMBuildExtractElement(builder, b, index, ""),
@ -379,7 +381,7 @@ lp_build_cmp(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
return lp_build_compare(bld->builder, bld->type, func, a, b);
return lp_build_compare(bld->gallivm, bld->type, func, a, b);
}
@ -392,6 +394,7 @@ lp_build_select_bitwise(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_type type = bld->type;
LLVMValueRef res;
@ -403,25 +406,25 @@ lp_build_select_bitwise(struct lp_build_context *bld,
}
if(type.floating) {
LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);
a = LLVMBuildBitCast(bld->builder, a, int_vec_type, "");
b = LLVMBuildBitCast(bld->builder, b, int_vec_type, "");
LLVMTypeRef int_vec_type = lp_build_int_vec_type(bld->gallivm, type);
a = LLVMBuildBitCast(builder, a, int_vec_type, "");
b = LLVMBuildBitCast(builder, b, int_vec_type, "");
}
a = LLVMBuildAnd(bld->builder, a, mask, "");
a = LLVMBuildAnd(builder, a, mask, "");
/* This often gets translated to PANDN, but sometimes the NOT is
* pre-computed and stored in another constant. The best strategy depends
* on available registers, so it is not a big deal -- hopefully LLVM does
* the right decision attending the rest of the program.
*/
b = LLVMBuildAnd(bld->builder, b, LLVMBuildNot(bld->builder, mask, ""), "");
b = LLVMBuildAnd(builder, b, LLVMBuildNot(builder, mask, ""), "");
res = LLVMBuildOr(bld->builder, a, b, "");
res = LLVMBuildOr(builder, a, b, "");
if(type.floating) {
LLVMTypeRef vec_type = lp_build_vec_type(type);
res = LLVMBuildBitCast(bld->builder, res, vec_type, "");
LLVMTypeRef vec_type = lp_build_vec_type(bld->gallivm, type);
res = LLVMBuildBitCast(builder, res, vec_type, "");
}
return res;
@ -440,6 +443,8 @@ lp_build_select(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMContextRef lc = bld->gallivm->context;
struct lp_type type = bld->type;
LLVMValueRef res;
@ -450,8 +455,8 @@ lp_build_select(struct lp_build_context *bld,
return a;
if (type.length == 1) {
mask = LLVMBuildTrunc(bld->builder, mask, LLVMInt1Type(), "");
res = LLVMBuildSelect(bld->builder, mask, a, b, "");
mask = LLVMBuildTrunc(builder, mask, LLVMInt1TypeInContext(lc), "");
res = LLVMBuildSelect(builder, mask, a, b, "");
}
else if (util_cpu_caps.has_sse4_1 &&
type.width * type.length == 128 &&
@ -465,34 +470,34 @@ lp_build_select(struct lp_build_context *bld,
if (type.floating &&
type.width == 64) {
intrinsic = "llvm.x86.sse41.blendvpd";
arg_type = LLVMVectorType(LLVMDoubleType(), 2);
arg_type = LLVMVectorType(LLVMDoubleTypeInContext(lc), 2);
} else if (type.floating &&
type.width == 32) {
intrinsic = "llvm.x86.sse41.blendvps";
arg_type = LLVMVectorType(LLVMFloatType(), 4);
arg_type = LLVMVectorType(LLVMFloatTypeInContext(lc), 4);
} else {
intrinsic = "llvm.x86.sse41.pblendvb";
arg_type = LLVMVectorType(LLVMInt8Type(), 16);
arg_type = LLVMVectorType(LLVMInt8TypeInContext(lc), 16);
}
if (arg_type != bld->int_vec_type) {
mask = LLVMBuildBitCast(bld->builder, mask, arg_type, "");
mask = LLVMBuildBitCast(builder, mask, arg_type, "");
}
if (arg_type != bld->vec_type) {
a = LLVMBuildBitCast(bld->builder, a, arg_type, "");
b = LLVMBuildBitCast(bld->builder, b, arg_type, "");
a = LLVMBuildBitCast(builder, a, arg_type, "");
b = LLVMBuildBitCast(builder, b, arg_type, "");
}
args[0] = b;
args[1] = a;
args[2] = mask;
res = lp_build_intrinsic(bld->builder, intrinsic,
res = lp_build_intrinsic(builder, intrinsic,
arg_type, args, Elements(args));
if (arg_type != bld->vec_type) {
res = LLVMBuildBitCast(bld->builder, res, bld->vec_type, "");
res = LLVMBuildBitCast(builder, res, bld->vec_type, "");
}
}
else {
@ -514,6 +519,7 @@ lp_build_select_aos(struct lp_build_context *bld,
LLVMValueRef a,
LLVMValueRef b)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
@ -544,7 +550,7 @@ lp_build_select_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
LLVMTypeRef elem_type = LLVMInt32Type();
LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += 4)
@ -553,7 +559,7 @@ lp_build_select_aos(struct lp_build_context *bld,
(mask & (1 << i) ? 0 : n) + j + i,
0);
return LLVMBuildShuffleVector(bld->builder, a, b, LLVMConstVector(shuffles, n), "");
return LLVMBuildShuffleVector(builder, a, b, LLVMConstVector(shuffles, n), "");
}
else {
#if 0
@ -567,9 +573,9 @@ lp_build_select_aos(struct lp_build_context *bld,
cond_vec[j + i] = LLVMConstInt(elem_type,
mask & (1 << i) ? 1 : 0, 0);
return LLVMBuildSelect(bld->builder, LLVMConstVector(cond_vec, n), a, b, "");
return LLVMBuildSelect(builder, LLVMConstVector(cond_vec, n), a, b, "");
#else
LLVMValueRef mask_vec = lp_build_const_mask_aos(type, mask);
LLVMValueRef mask_vec = lp_build_const_mask_aos(bld->gallivm, type, mask);
return lp_build_select(bld, mask_vec, a, b);
#endif
}

View file

@ -47,7 +47,7 @@ struct lp_build_context;
LLVMValueRef
lp_build_compare(LLVMBuilderRef builder,
lp_build_compare(struct gallivm_state *gallivm,
const struct lp_type type,
unsigned func,
LLVMValueRef a,

View file

@ -72,6 +72,7 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
#include "lp_bld_init.h"
#include "lp_bld_intr.h"
#include "lp_bld_arit.h"
#include "lp_bld_pack.h"
@ -81,7 +82,8 @@
* Build shuffle vectors that match PUNPCKLxx and PUNPCKHxx instructions.
*/
static LLVMValueRef
lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
lp_build_const_unpack_shuffle(struct gallivm_state *gallivm,
unsigned n, unsigned lo_hi)
{
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i, j;
@ -92,8 +94,8 @@ lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
/* TODO: cache results in a static table */
for(i = 0, j = lo_hi*n/2; i < n; i += 2, ++j) {
elems[i + 0] = LLVMConstInt(LLVMInt32Type(), 0 + j, 0);
elems[i + 1] = LLVMConstInt(LLVMInt32Type(), n + j, 0);
elems[i + 0] = lp_build_const_int32(gallivm, 0 + j);
elems[i + 1] = lp_build_const_int32(gallivm, n + j);
}
return LLVMConstVector(elems, n);
@ -104,7 +106,7 @@ lp_build_const_unpack_shuffle(unsigned n, unsigned lo_hi)
* Build shuffle vectors that match PACKxx instructions.
*/
static LLVMValueRef
lp_build_const_pack_shuffle(unsigned n)
lp_build_const_pack_shuffle(struct gallivm_state *gallivm, unsigned n)
{
LLVMValueRef elems[LP_MAX_VECTOR_LENGTH];
unsigned i;
@ -112,7 +114,7 @@ lp_build_const_pack_shuffle(unsigned n)
assert(n <= LP_MAX_VECTOR_LENGTH);
for(i = 0; i < n; ++i)
elems[i] = LLVMConstInt(LLVMInt32Type(), 2*i, 0);
elems[i] = lp_build_const_int32(gallivm, 2*i);
return LLVMConstVector(elems, n);
}
@ -124,7 +126,7 @@ lp_build_const_pack_shuffle(unsigned n)
* Matches the PUNPCKLxx and PUNPCKHxx SSE instructions.
*/
LLVMValueRef
lp_build_interleave2(LLVMBuilderRef builder,
lp_build_interleave2(struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef a,
LLVMValueRef b,
@ -132,9 +134,9 @@ lp_build_interleave2(LLVMBuilderRef builder,
{
LLVMValueRef shuffle;
shuffle = lp_build_const_unpack_shuffle(type.length, lo_hi);
shuffle = lp_build_const_unpack_shuffle(gallivm, type.length, lo_hi);
return LLVMBuildShuffleVector(builder, a, b, shuffle, "");
return LLVMBuildShuffleVector(gallivm->builder, a, b, shuffle, "");
}
@ -145,13 +147,14 @@ lp_build_interleave2(LLVMBuilderRef builder,
* values themselves.
*/
void
lp_build_unpack2(LLVMBuilderRef builder,
lp_build_unpack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
LLVMValueRef *dst_lo,
LLVMValueRef *dst_hi)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef msb;
LLVMTypeRef dst_vec_type;
@ -162,24 +165,24 @@ lp_build_unpack2(LLVMBuilderRef builder,
if(dst_type.sign && src_type.sign) {
/* Replicate the sign bit in the most significant bits */
msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(src_type, src_type.width - 1), "");
msb = LLVMBuildAShr(builder, src, lp_build_const_int_vec(gallivm, src_type, src_type.width - 1), "");
}
else
/* Most significant bits always zero */
msb = lp_build_zero(src_type);
msb = lp_build_zero(gallivm, src_type);
/* Interleave bits */
#ifdef PIPE_ARCH_LITTLE_ENDIAN
*dst_lo = lp_build_interleave2(builder, src_type, src, msb, 0);
*dst_hi = lp_build_interleave2(builder, src_type, src, msb, 1);
*dst_lo = lp_build_interleave2(gallivm, src_type, src, msb, 0);
*dst_hi = lp_build_interleave2(gallivm, src_type, src, msb, 1);
#else
*dst_lo = lp_build_interleave2(builder, src_type, msb, src, 0);
*dst_hi = lp_build_interleave2(builder, src_type, msb, src, 1);
*dst_lo = lp_build_interleave2(gallivm, src_type, msb, src, 0);
*dst_hi = lp_build_interleave2(gallivm, src_type, msb, src, 1);
#endif
/* Cast the result into the new type (twice as wide) */
dst_vec_type = lp_build_vec_type(dst_type);
dst_vec_type = lp_build_vec_type(gallivm, dst_type);
*dst_lo = LLVMBuildBitCast(builder, *dst_lo, dst_vec_type, "");
*dst_hi = LLVMBuildBitCast(builder, *dst_hi, dst_vec_type, "");
@ -193,7 +196,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
* values themselves.
*/
void
lp_build_unpack(LLVMBuilderRef builder,
lp_build_unpack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@ -218,7 +221,7 @@ lp_build_unpack(LLVMBuilderRef builder,
tmp_type.length /= 2;
for(i = num_tmps; i--; ) {
lp_build_unpack2(builder, src_type, tmp_type, dst[i], &dst[2*i + 0], &dst[2*i + 1]);
lp_build_unpack2(gallivm, src_type, tmp_type, dst[i], &dst[2*i + 0], &dst[2*i + 1]);
}
src_type = tmp_type;
@ -247,16 +250,17 @@ lp_build_unpack(LLVMBuilderRef builder,
* lp_build_packs2 instead.
*/
LLVMValueRef
lp_build_pack2(LLVMBuilderRef builder,
lp_build_pack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
LLVMValueRef hi)
{
LLVMBuilderRef builder = gallivm->builder;
#if HAVE_LLVM < 0x0207
LLVMTypeRef src_vec_type = lp_build_vec_type(src_type);
LLVMTypeRef src_vec_type = lp_build_vec_type(gallivm, src_type);
#endif
LLVMTypeRef dst_vec_type = lp_build_vec_type(dst_type);
LLVMTypeRef dst_vec_type = lp_build_vec_type(gallivm, dst_type);
LLVMValueRef shuffle;
LLVMValueRef res = NULL;
@ -318,7 +322,7 @@ lp_build_pack2(LLVMBuilderRef builder,
lo = LLVMBuildBitCast(builder, lo, dst_vec_type, "");
hi = LLVMBuildBitCast(builder, hi, dst_vec_type, "");
shuffle = lp_build_const_pack_shuffle(dst_type.length);
shuffle = lp_build_const_pack_shuffle(gallivm, dst_type.length);
res = LLVMBuildShuffleVector(builder, lo, hi, shuffle, "");
@ -334,7 +338,7 @@ lp_build_pack2(LLVMBuilderRef builder,
* destination type.
*/
LLVMValueRef
lp_build_packs2(LLVMBuilderRef builder,
lp_build_packs2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@ -360,14 +364,14 @@ lp_build_packs2(LLVMBuilderRef builder,
if(clamp) {
struct lp_build_context bld;
unsigned dst_bits = dst_type.sign ? dst_type.width - 1 : dst_type.width;
LLVMValueRef dst_max = lp_build_const_int_vec(src_type, ((unsigned long long)1 << dst_bits) - 1);
lp_build_context_init(&bld, builder, src_type);
LLVMValueRef dst_max = lp_build_const_int_vec(gallivm, src_type, ((unsigned long long)1 << dst_bits) - 1);
lp_build_context_init(&bld, gallivm, src_type);
lo = lp_build_min(&bld, lo, dst_max);
hi = lp_build_min(&bld, hi, dst_max);
/* FIXME: What about lower bound? */
}
return lp_build_pack2(builder, src_type, dst_type, lo, hi);
return lp_build_pack2(gallivm, src_type, dst_type, lo, hi);
}
@ -377,13 +381,13 @@ lp_build_packs2(LLVMBuilderRef builder,
* TODO: Handle saturation consistently.
*/
LLVMValueRef
lp_build_pack(LLVMBuilderRef builder,
lp_build_pack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
boolean clamped,
const LLVMValueRef *src, unsigned num_srcs)
{
LLVMValueRef (*pack2)(LLVMBuilderRef builder,
LLVMValueRef (*pack2)(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@ -419,7 +423,8 @@ lp_build_pack(LLVMBuilderRef builder,
num_srcs /= 2;
for(i = 0; i < num_srcs; ++i)
tmp[i] = pack2(builder, src_type, tmp_type, tmp[2*i + 0], tmp[2*i + 1]);
tmp[i] = pack2(gallivm, src_type, tmp_type,
tmp[2*i + 0], tmp[2*i + 1]);
src_type = tmp_type;
}
@ -437,12 +442,13 @@ lp_build_pack(LLVMBuilderRef builder,
* intrinsics that do saturation.
*/
void
lp_build_resize(LLVMBuilderRef builder,
lp_build_resize(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,
LLVMValueRef *dst, unsigned num_dsts)
{
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef tmp[LP_MAX_VECTOR_LENGTH];
unsigned i;
@ -482,7 +488,7 @@ lp_build_resize(LLVMBuilderRef builder,
* Register width remains constant -- use vector packing intrinsics
*/
tmp[0] = lp_build_pack(builder, src_type, dst_type, TRUE, src, num_srcs);
tmp[0] = lp_build_pack(gallivm, src_type, dst_type, TRUE, src, num_srcs);
}
else {
/*
@ -490,11 +496,11 @@ lp_build_resize(LLVMBuilderRef builder,
*/
assert(src_type.length == dst_type.length);
tmp[0] = lp_build_undef(dst_type);
tmp[0] = lp_build_undef(gallivm, dst_type);
for (i = 0; i < dst_type.length; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, "");
val = LLVMBuildTrunc(builder, val, lp_build_elem_type(dst_type), "");
val = LLVMBuildTrunc(builder, val, lp_build_elem_type(gallivm, dst_type), "");
tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, "");
}
}
@ -510,7 +516,7 @@ lp_build_resize(LLVMBuilderRef builder,
/*
* Register width remains constant -- use vector unpack intrinsics
*/
lp_build_unpack(builder, src_type, dst_type, src[0], tmp, num_dsts);
lp_build_unpack(gallivm, src_type, dst_type, src[0], tmp, num_dsts);
}
else {
/*
@ -518,15 +524,15 @@ lp_build_resize(LLVMBuilderRef builder,
*/
assert(src_type.length == dst_type.length);
tmp[0] = lp_build_undef(dst_type);
tmp[0] = lp_build_undef(gallivm, dst_type);
for (i = 0; i < dst_type.length; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef index = lp_build_const_int32(gallivm, i);
LLVMValueRef val = LLVMBuildExtractElement(builder, src[0], index, "");
if (src_type.sign && dst_type.sign) {
val = LLVMBuildSExt(builder, val, lp_build_elem_type(dst_type), "");
val = LLVMBuildSExt(builder, val, lp_build_elem_type(gallivm, dst_type), "");
} else {
val = LLVMBuildZExt(builder, val, lp_build_elem_type(dst_type), "");
val = LLVMBuildZExt(builder, val, lp_build_elem_type(gallivm, dst_type), "");
}
tmp[0] = LLVMBuildInsertElement(builder, tmp[0], val, index, "");
}

View file

@ -46,7 +46,7 @@ struct lp_type;
LLVMValueRef
lp_build_interleave2(LLVMBuilderRef builder,
lp_build_interleave2(struct gallivm_state *gallivm,
struct lp_type type,
LLVMValueRef a,
LLVMValueRef b,
@ -54,7 +54,7 @@ lp_build_interleave2(LLVMBuilderRef builder,
void
lp_build_unpack2(LLVMBuilderRef builder,
lp_build_unpack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@ -63,7 +63,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
void
lp_build_unpack(LLVMBuilderRef builder,
lp_build_unpack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef src,
@ -71,7 +71,7 @@ lp_build_unpack(LLVMBuilderRef builder,
LLVMValueRef
lp_build_packs2(LLVMBuilderRef builder,
lp_build_packs2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@ -79,7 +79,7 @@ lp_build_packs2(LLVMBuilderRef builder,
LLVMValueRef
lp_build_pack2(LLVMBuilderRef builder,
lp_build_pack2(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef lo,
@ -87,7 +87,7 @@ lp_build_pack2(LLVMBuilderRef builder,
LLVMValueRef
lp_build_pack(LLVMBuilderRef builder,
lp_build_pack(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
boolean clamped,
@ -95,7 +95,7 @@ lp_build_pack(LLVMBuilderRef builder,
void
lp_build_resize(LLVMBuilderRef builder,
lp_build_resize(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
const LLVMValueRef *src, unsigned num_srcs,

View file

@ -31,6 +31,8 @@
#include "util/u_memory.h"
#include "util/u_string.h"
#include "lp_bld_const.h"
#include "lp_bld_init.h"
#include "lp_bld_const.h"
#include "lp_bld_printf.h"
@ -65,12 +67,14 @@ lp_get_printf_arg_count(const char *fmt)
}
LLVMValueRef
lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len)
lp_build_const_string_variable(LLVMModuleRef module,
LLVMContextRef context,
const char *str, int len)
{
LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8Type(), len + 1), "");
LLVMValueRef string = LLVMAddGlobal(module, LLVMArrayType(LLVMInt8TypeInContext(context), len + 1), "");
LLVMSetGlobalConstant(string, TRUE);
LLVMSetLinkage(string, LLVMInternalLinkage);
LLVMSetInitializer(string, LLVMConstString(str, len + 1, TRUE));
LLVMSetInitializer(string, LLVMConstStringInContext(context, str, len + 1, TRUE));
return string;
}
@ -83,15 +87,18 @@ lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len)
* LLVMValueRef.
*/
LLVMValueRef
lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
lp_build_printf(struct gallivm_state *gallivm, const char *fmt, ...)
{
va_list arglist;
int i = 0;
int argcount = lp_get_printf_arg_count(fmt);
LLVMModuleRef module = LLVMGetGlobalParent(LLVMGetBasicBlockParent(LLVMGetInsertBlock(builder)));
LLVMBuilderRef builder = gallivm->builder;
LLVMContextRef context = gallivm->context;
LLVMModuleRef module = gallivm->module;
LLVMValueRef params[50];
LLVMValueRef fmtarg = lp_build_const_string_variable(module, fmt, strlen(fmt) + 1);
LLVMValueRef int0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
LLVMValueRef fmtarg = lp_build_const_string_variable(module, context,
fmt, strlen(fmt) + 1);
LLVMValueRef int0 = lp_build_const_int32(gallivm, 0);
LLVMValueRef index[2];
LLVMValueRef func_printf = LLVMGetNamedFunction(module, "printf");
@ -100,7 +107,7 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
index[0] = index[1] = int0;
if (!func_printf) {
LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntType(32), NULL, 0, 1);
LLVMTypeRef printf_type = LLVMFunctionType(LLVMIntTypeInContext(context, 32), NULL, 0, 1);
func_printf = LLVMAddFunction(module, "printf", printf_type);
}
@ -113,7 +120,7 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
/* printf wants doubles, so lets convert so that
* we can actually print them */
if (LLVMGetTypeKind(type) == LLVMFloatTypeKind)
val = LLVMBuildFPExt(builder, val, LLVMDoubleType(), "");
val = LLVMBuildFPExt(builder, val, LLVMDoubleTypeInContext(context), "");
params[i] = val;
}
va_end(arglist);
@ -127,16 +134,18 @@ lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...)
* Print a float[4] vector.
*/
LLVMValueRef
lp_build_print_vec4(LLVMBuilderRef builder, const char *msg, LLVMValueRef vec)
lp_build_print_vec4(struct gallivm_state *gallivm,
const char *msg, LLVMValueRef vec)
{
LLVMBuilderRef builder = gallivm->builder;
char format[1000];
LLVMValueRef x, y, z, w;
x = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(0), "");
y = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(1), "");
z = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(2), "");
w = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(3), "");
x = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 0), "");
y = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 1), "");
z = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 2), "");
w = LLVMBuildExtractElement(builder, vec, lp_build_const_int32(gallivm, 3), "");
util_snprintf(format, sizeof(format), "%s %%f %%f %%f %%f\n", msg);
return lp_build_printf(builder, format, x, y, z, w);
return lp_build_printf(gallivm, format, x, y, z, w);
}

View file

@ -31,12 +31,19 @@
#include "pipe/p_compiler.h"
#include "lp_bld.h"
#include "lp_bld_init.h"
LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module, const char *str, int len);
LLVMValueRef lp_build_printf(LLVMBuilderRef builder, const char *fmt, ...);
LLVMValueRef lp_build_const_string_variable(LLVMModuleRef module,
LLVMContextRef context,
const char *str, int len);
LLVMValueRef lp_build_printf(struct gallivm_state *gallivm,
const char *fmt, ...);
LLVMValueRef
lp_build_print_vec4(LLVMBuilderRef builder, const char *msg, LLVMValueRef vec);
lp_build_print_vec4(struct gallivm_state *gallivm,
const char *msg, LLVMValueRef vec);
#endif

View file

@ -28,6 +28,7 @@
#include "lp_bld_type.h"
#include "lp_bld_arit.h"
#include "lp_bld_const.h"
#include "lp_bld_swizzle.h"
#include "lp_bld_quad.h"
@ -81,15 +82,15 @@ LLVMValueRef
lp_build_scalar_ddx(struct lp_build_context *bld,
LLVMValueRef a)
{
LLVMTypeRef i32t = LLVMInt32Type();
LLVMValueRef idx_left = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_LEFT, 0);
LLVMValueRef idx_right = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_RIGHT, 0);
LLVMValueRef a_left = LLVMBuildExtractElement(bld->builder, a, idx_left, "left");
LLVMValueRef a_right = LLVMBuildExtractElement(bld->builder, a, idx_right, "right");
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef idx_left = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT);
LLVMValueRef idx_right = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_RIGHT);
LLVMValueRef a_left = LLVMBuildExtractElement(builder, a, idx_left, "left");
LLVMValueRef a_right = LLVMBuildExtractElement(builder, a, idx_right, "right");
if (bld->type.floating)
return LLVMBuildFSub(bld->builder, a_right, a_left, "ddx");
return LLVMBuildFSub(builder, a_right, a_left, "ddx");
else
return LLVMBuildSub(bld->builder, a_right, a_left, "ddx");
return LLVMBuildSub(builder, a_right, a_left, "ddx");
}
@ -97,13 +98,13 @@ LLVMValueRef
lp_build_scalar_ddy(struct lp_build_context *bld,
LLVMValueRef a)
{
LLVMTypeRef i32t = LLVMInt32Type();
LLVMValueRef idx_top = LLVMConstInt(i32t, LP_BLD_QUAD_TOP_LEFT, 0);
LLVMValueRef idx_bottom = LLVMConstInt(i32t, LP_BLD_QUAD_BOTTOM_LEFT, 0);
LLVMValueRef a_top = LLVMBuildExtractElement(bld->builder, a, idx_top, "top");
LLVMValueRef a_bottom = LLVMBuildExtractElement(bld->builder, a, idx_bottom, "bottom");
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef idx_top = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_TOP_LEFT);
LLVMValueRef idx_bottom = lp_build_const_int32(bld->gallivm, LP_BLD_QUAD_BOTTOM_LEFT);
LLVMValueRef a_top = LLVMBuildExtractElement(builder, a, idx_top, "top");
LLVMValueRef a_bottom = LLVMBuildExtractElement(builder, a, idx_bottom, "bottom");
if (bld->type.floating)
return LLVMBuildFSub(bld->builder, a_bottom, a_top, "ddy");
return LLVMBuildFSub(builder, a_bottom, a_top, "ddy");
else
return LLVMBuildSub(bld->builder, a_bottom, a_top, "ddy");
return LLVMBuildSub(builder, a_bottom, a_top, "ddy");
}

View file

@ -134,7 +134,7 @@ lp_sampler_static_state(struct lp_sampler_static_state *state,
state->min_img_filter = sampler->min_img_filter;
state->mag_img_filter = sampler->mag_img_filter;
if (view->last_level && sampler->max_lod > 0.0f) {
if (view->u.tex.last_level && sampler->max_lod > 0.0f) {
state->min_mip_filter = sampler->min_mip_filter;
} else {
state->min_mip_filter = PIPE_TEX_MIPFILTER_NONE;
@ -155,7 +155,7 @@ lp_sampler_static_state(struct lp_sampler_static_state *state,
state->apply_min_lod = 1;
}
if (sampler->max_lod < (float)view->last_level) {
if (sampler->max_lod < (float)view->u.tex.last_level) {
state->apply_max_lod = 1;
}
}
@ -190,7 +190,8 @@ lp_build_rho(struct lp_build_sample_context *bld,
struct lp_build_context *float_size_bld = &bld->float_size_bld;
struct lp_build_context *float_bld = &bld->float_bld;
const unsigned dims = bld->dims;
LLVMTypeRef i32t = LLVMInt32Type();
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0);
LLVMValueRef index1 = LLVMConstInt(i32t, 1, 0);
LLVMValueRef index2 = LLVMConstInt(i32t, 2, 0);
@ -211,21 +212,21 @@ lp_build_rho(struct lp_build_sample_context *bld,
rho_x = float_size_bld->undef;
rho_y = float_size_bld->undef;
rho_x = LLVMBuildInsertElement(bld->builder, rho_x, dsdx, index0, "");
rho_y = LLVMBuildInsertElement(bld->builder, rho_y, dsdy, index0, "");
rho_x = LLVMBuildInsertElement(builder, rho_x, dsdx, index0, "");
rho_y = LLVMBuildInsertElement(builder, rho_y, dsdy, index0, "");
dtdx = ddx[1];
dtdy = ddy[1];
rho_x = LLVMBuildInsertElement(bld->builder, rho_x, dtdx, index1, "");
rho_y = LLVMBuildInsertElement(bld->builder, rho_y, dtdy, index1, "");
rho_x = LLVMBuildInsertElement(builder, rho_x, dtdx, index1, "");
rho_y = LLVMBuildInsertElement(builder, rho_y, dtdy, index1, "");
if (dims >= 3) {
drdx = ddx[2];
drdy = ddy[2];
rho_x = LLVMBuildInsertElement(bld->builder, rho_x, drdx, index2, "");
rho_y = LLVMBuildInsertElement(bld->builder, rho_y, drdy, index2, "");
rho_x = LLVMBuildInsertElement(builder, rho_x, drdx, index2, "");
rho_y = LLVMBuildInsertElement(builder, rho_y, drdy, index2, "");
}
}
@ -245,13 +246,13 @@ lp_build_rho(struct lp_build_sample_context *bld,
if (dims >= 2) {
LLVMValueRef rho_s, rho_t, rho_r;
rho_s = LLVMBuildExtractElement(bld->builder, rho_vec, index0, "");
rho_t = LLVMBuildExtractElement(bld->builder, rho_vec, index1, "");
rho_s = LLVMBuildExtractElement(builder, rho_vec, index0, "");
rho_t = LLVMBuildExtractElement(builder, rho_vec, index1, "");
rho = lp_build_max(float_bld, rho_s, rho_t);
if (dims >= 3) {
rho_r = LLVMBuildExtractElement(bld->builder, rho_vec, index0, "");
rho_r = LLVMBuildExtractElement(builder, rho_vec, index0, "");
rho = lp_build_max(float_bld, rho, rho_r);
}
}
@ -304,19 +305,19 @@ lp_build_brilinear_lod(struct lp_build_context *bld,
double post_offset = 1 - factor;
if (0) {
lp_build_printf(bld->builder, "lod = %f\n", lod);
lp_build_printf(bld->gallivm, "lod = %f\n", lod);
}
lod = lp_build_add(bld, lod,
lp_build_const_vec(bld->type, pre_offset));
lp_build_const_vec(bld->gallivm, bld->type, pre_offset));
lp_build_ifloor_fract(bld, lod, out_lod_ipart, &lod_fpart);
lod_fpart = lp_build_mul(bld, lod_fpart,
lp_build_const_vec(bld->type, factor));
lp_build_const_vec(bld->gallivm, bld->type, factor));
lod_fpart = lp_build_add(bld, lod_fpart,
lp_build_const_vec(bld->type, post_offset));
lp_build_const_vec(bld->gallivm, bld->type, post_offset));
/*
* It's not necessary to clamp lod_fpart since:
@ -327,8 +328,8 @@ lp_build_brilinear_lod(struct lp_build_context *bld,
*out_lod_fpart = lod_fpart;
if (0) {
lp_build_printf(bld->builder, "lod_ipart = %i\n", *out_lod_ipart);
lp_build_printf(bld->builder, "lod_fpart = %f\n\n", *out_lod_fpart);
lp_build_printf(bld->gallivm, "lod_ipart = %i\n", *out_lod_ipart);
lp_build_printf(bld->gallivm, "lod_fpart = %f\n\n", *out_lod_fpart);
}
}
@ -363,7 +364,7 @@ lp_build_brilinear_rho(struct lp_build_context *bld,
* part will not need any post adjustments.
*/
rho = lp_build_mul(bld, rho,
lp_build_const_vec(bld->type, pre_factor));
lp_build_const_vec(bld->gallivm, bld->type, pre_factor));
/* ipart = ifloor(log2(rho)) */
lod_ipart = lp_build_extract_exponent(bld, rho, 0);
@ -372,10 +373,10 @@ lp_build_brilinear_rho(struct lp_build_context *bld,
lod_fpart = lp_build_extract_mantissa(bld, rho);
lod_fpart = lp_build_mul(bld, lod_fpart,
lp_build_const_vec(bld->type, factor));
lp_build_const_vec(bld->gallivm, bld->type, factor));
lod_fpart = lp_build_add(bld, lod_fpart,
lp_build_const_vec(bld->type, post_offset));
lp_build_const_vec(bld->gallivm, bld->type, post_offset));
/*
* Like lp_build_brilinear_lod, it's not necessary to clamp lod_fpart since:
@ -413,6 +414,7 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
LLVMValueRef *out_lod_fpart)
{
LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context *float_bld = &bld->float_bld;
LLVMValueRef lod;
@ -424,17 +426,17 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
* This is hit during mipmap generation.
*/
LLVMValueRef min_lod =
bld->dynamic_state->min_lod(bld->dynamic_state, bld->builder, unit);
bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit);
lod = min_lod;
}
else {
LLVMValueRef sampler_lod_bias =
bld->dynamic_state->lod_bias(bld->dynamic_state, bld->builder, unit);
LLVMValueRef index0 = LLVMConstInt(LLVMInt32Type(), 0, 0);
bld->dynamic_state->lod_bias(bld->dynamic_state, bld->gallivm, unit);
LLVMValueRef index0 = lp_build_const_int32(bld->gallivm, 0);
if (explicit_lod) {
lod = LLVMBuildExtractElement(bld->builder, explicit_lod,
lod = LLVMBuildExtractElement(builder, explicit_lod,
index0, "");
}
else {
@ -479,27 +481,27 @@ lp_build_lod_selector(struct lp_build_sample_context *bld,
/* add shader lod bias */
if (lod_bias) {
lod_bias = LLVMBuildExtractElement(bld->builder, lod_bias,
lod_bias = LLVMBuildExtractElement(builder, lod_bias,
index0, "");
lod = LLVMBuildFAdd(bld->builder, lod, lod_bias, "shader_lod_bias");
lod = LLVMBuildFAdd(builder, lod, lod_bias, "shader_lod_bias");
}
}
/* add sampler lod bias */
if (bld->static_state->lod_bias_non_zero)
lod = LLVMBuildFAdd(bld->builder, lod, sampler_lod_bias, "sampler_lod_bias");
lod = LLVMBuildFAdd(builder, lod, sampler_lod_bias, "sampler_lod_bias");
/* clamp lod */
if (bld->static_state->apply_max_lod) {
LLVMValueRef max_lod =
bld->dynamic_state->max_lod(bld->dynamic_state, bld->builder, unit);
bld->dynamic_state->max_lod(bld->dynamic_state, bld->gallivm, unit);
lod = lp_build_min(float_bld, lod, max_lod);
}
if (bld->static_state->apply_min_lod) {
LLVMValueRef min_lod =
bld->dynamic_state->min_lod(bld->dynamic_state, bld->builder, unit);
bld->dynamic_state->min_lod(bld->dynamic_state, bld->gallivm, unit);
lod = lp_build_max(float_bld, lod, min_lod);
}
@ -542,10 +544,10 @@ lp_build_nearest_mip_level(struct lp_build_sample_context *bld,
struct lp_build_context *int_bld = &bld->int_bld;
LLVMValueRef last_level, level;
LLVMValueRef zero = LLVMConstInt(LLVMInt32Type(), 0, 0);
LLVMValueRef zero = lp_build_const_int32(bld->gallivm, 0);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
bld->builder, unit);
bld->gallivm, unit);
/* convert float lod to integer */
level = lod_ipart;
@ -568,7 +570,7 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
LLVMValueRef *level0_out,
LLVMValueRef *level1_out)
{
LLVMBuilderRef builder = bld->builder;
LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context *int_bld = &bld->int_bld;
struct lp_build_context *float_bld = &bld->float_bld;
LLVMValueRef last_level;
@ -579,7 +581,7 @@ lp_build_linear_mip_levels(struct lp_build_sample_context *bld,
*level1_out = lp_build_add(int_bld, lod_ipart, int_bld->one);
last_level = bld->dynamic_state->last_level(bld->dynamic_state,
bld->builder, unit);
bld->gallivm, unit);
/*
* Clamp both lod_ipart and lod_ipart + 1 to [0, last_level], with the
@ -630,11 +632,13 @@ LLVMValueRef
lp_build_get_mipmap_level(struct lp_build_sample_context *bld,
LLVMValueRef level)
{
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef indexes[2], data_ptr;
indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
indexes[0] = lp_build_const_int32(bld->gallivm, 0);
indexes[1] = level;
data_ptr = LLVMBuildGEP(bld->builder, bld->data_array, indexes, 2, "");
data_ptr = LLVMBuildLoad(bld->builder, data_ptr, "");
data_ptr = LLVMBuildGEP(builder, bld->data_array, indexes, 2, "");
data_ptr = LLVMBuildLoad(builder, data_ptr, "");
return data_ptr;
}
@ -643,7 +647,7 @@ LLVMValueRef
lp_build_get_const_mipmap_level(struct lp_build_sample_context *bld,
int level)
{
LLVMValueRef lvl = LLVMConstInt(LLVMInt32Type(), level, 0);
LLVMValueRef lvl = lp_build_const_int32(bld->gallivm, level);
return lp_build_get_mipmap_level(bld, lvl);
}
@ -657,6 +661,7 @@ lp_build_minify(struct lp_build_context *bld,
LLVMValueRef base_size,
LLVMValueRef level)
{
LLVMBuilderRef builder = bld->gallivm->builder;
assert(lp_check_value(bld->type, base_size));
assert(lp_check_value(bld->type, level));
@ -666,7 +671,7 @@ lp_build_minify(struct lp_build_context *bld,
}
else {
LLVMValueRef size =
LLVMBuildLShr(bld->builder, base_size, level, "minify");
LLVMBuildLShr(builder, base_size, level, "minify");
assert(bld->type.sign);
size = lp_build_max(bld, size, bld->one);
return size;
@ -682,11 +687,12 @@ static LLVMValueRef
lp_build_get_level_stride_vec(struct lp_build_sample_context *bld,
LLVMValueRef stride_array, LLVMValueRef level)
{
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef indexes[2], stride;
indexes[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
indexes[0] = lp_build_const_int32(bld->gallivm, 0);
indexes[1] = level;
stride = LLVMBuildGEP(bld->builder, stride_array, indexes, 2, "");
stride = LLVMBuildLoad(bld->builder, stride, "");
stride = LLVMBuildGEP(builder, stride_array, indexes, 2, "");
stride = LLVMBuildLoad(builder, stride, "");
stride = lp_build_broadcast_scalar(&bld->int_coord_bld, stride);
return stride;
}
@ -747,21 +753,21 @@ lp_build_extract_image_sizes(struct lp_build_sample_context *bld,
LLVMValueRef *out_depth)
{
const unsigned dims = bld->dims;
LLVMTypeRef i32t = LLVMInt32Type();
LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
*out_width = lp_build_extract_broadcast(bld->builder,
*out_width = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
LLVMConstInt(i32t, 0, 0));
if (dims >= 2) {
*out_height = lp_build_extract_broadcast(bld->builder,
*out_height = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
LLVMConstInt(i32t, 1, 0));
if (dims == 3) {
*out_depth = lp_build_extract_broadcast(bld->builder,
*out_depth = lp_build_extract_broadcast(bld->gallivm,
size_type,
coord_type,
size,
@ -812,7 +818,7 @@ static LLVMValueRef
lp_build_cube_ima(struct lp_build_context *coord_bld, LLVMValueRef coord)
{
/* ima = -0.5 / abs(coord); */
LLVMValueRef negHalf = lp_build_const_vec(coord_bld->type, -0.5);
LLVMValueRef negHalf = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, -0.5);
LLVMValueRef absCoord = lp_build_abs(coord_bld, coord);
LLVMValueRef ima = lp_build_div(coord_bld, negHalf, absCoord);
return ima;
@ -831,7 +837,7 @@ lp_build_cube_coord(struct lp_build_context *coord_bld,
LLVMValueRef coord, LLVMValueRef ima)
{
/* return negate(coord) * ima * sign + 0.5; */
LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
LLVMValueRef half = lp_build_const_vec(coord_bld->gallivm, coord_bld->type, 0.5);
LLVMValueRef res;
assert(negate_coord == +1 || negate_coord == -1);
@ -859,12 +865,14 @@ lp_build_cube_face(struct lp_build_sample_context *bld,
LLVMValueRef major_coord,
unsigned pos_face, unsigned neg_face)
{
LLVMValueRef cmp = LLVMBuildFCmp(bld->builder, LLVMRealUGE,
struct gallivm_state *gallivm = bld->gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef cmp = LLVMBuildFCmp(builder, LLVMRealUGE,
major_coord,
bld->float_bld.zero, "");
LLVMValueRef pos = LLVMConstInt(LLVMInt32Type(), pos_face, 0);
LLVMValueRef neg = LLVMConstInt(LLVMInt32Type(), neg_face, 0);
LLVMValueRef res = LLVMBuildSelect(bld->builder, cmp, pos, neg, "");
LLVMValueRef pos = lp_build_const_int32(gallivm, pos_face);
LLVMValueRef neg = lp_build_const_int32(gallivm, neg_face);
LLVMValueRef res = LLVMBuildSelect(builder, cmp, pos, neg, "");
return res;
}
@ -884,9 +892,10 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
{
struct lp_build_context *float_bld = &bld->float_bld;
struct lp_build_context *coord_bld = &bld->coord_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef rx, ry, rz;
LLVMValueRef arx, ary, arz;
LLVMValueRef c25 = LLVMConstReal(LLVMFloatType(), 0.25);
LLVMValueRef c25 = lp_build_const_float(bld->gallivm, 0.25);
LLVMValueRef arx_ge_ary, arx_ge_arz;
LLVMValueRef ary_ge_arx, ary_ge_arz;
LLVMValueRef arx_ge_ary_arz, ary_ge_arx_arz;
@ -911,17 +920,17 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
/*
* Compare sign/magnitude of rx,ry,rz to determine face
*/
arx_ge_ary = LLVMBuildFCmp(bld->builder, LLVMRealUGE, arx, ary, "");
arx_ge_arz = LLVMBuildFCmp(bld->builder, LLVMRealUGE, arx, arz, "");
ary_ge_arx = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ary, arx, "");
ary_ge_arz = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ary, arz, "");
arx_ge_ary = LLVMBuildFCmp(builder, LLVMRealUGE, arx, ary, "");
arx_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, arx, arz, "");
ary_ge_arx = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arx, "");
ary_ge_arz = LLVMBuildFCmp(builder, LLVMRealUGE, ary, arz, "");
arx_ge_ary_arz = LLVMBuildAnd(bld->builder, arx_ge_ary, arx_ge_arz, "");
ary_ge_arx_arz = LLVMBuildAnd(bld->builder, ary_ge_arx, ary_ge_arz, "");
arx_ge_ary_arz = LLVMBuildAnd(builder, arx_ge_ary, arx_ge_arz, "");
ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, "");
rx_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, rx, float_bld->zero, "");
ry_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, ry, float_bld->zero, "");
rz_pos = LLVMBuildFCmp(bld->builder, LLVMRealUGE, rz, float_bld->zero, "");
rx_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rx, float_bld->zero, "");
ry_pos = LLVMBuildFCmp(builder, LLVMRealUGE, ry, float_bld->zero, "");
rz_pos = LLVMBuildFCmp(builder, LLVMRealUGE, rz, float_bld->zero, "");
{
struct lp_build_if_state if_ctx;
@ -929,11 +938,11 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
LLVMValueRef face_t_var;
LLVMValueRef face_var;
face_s_var = lp_build_alloca(bld->builder, bld->coord_bld.vec_type, "face_s_var");
face_t_var = lp_build_alloca(bld->builder, bld->coord_bld.vec_type, "face_t_var");
face_var = lp_build_alloca(bld->builder, bld->int_bld.vec_type, "face_var");
face_s_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_s_var");
face_t_var = lp_build_alloca(bld->gallivm, bld->coord_bld.vec_type, "face_t_var");
face_var = lp_build_alloca(bld->gallivm, bld->int_bld.vec_type, "face_var");
lp_build_if(&if_ctx, bld->builder, arx_ge_ary_arz);
lp_build_if(&if_ctx, bld->gallivm, arx_ge_ary_arz);
{
/* +/- X face */
LLVMValueRef sign = lp_build_sgn(float_bld, rx);
@ -943,17 +952,17 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, rx,
PIPE_TEX_FACE_POS_X,
PIPE_TEX_FACE_NEG_X);
LLVMBuildStore(bld->builder, *face_s, face_s_var);
LLVMBuildStore(bld->builder, *face_t, face_t_var);
LLVMBuildStore(bld->builder, *face, face_var);
LLVMBuildStore(builder, *face_s, face_s_var);
LLVMBuildStore(builder, *face_t, face_t_var);
LLVMBuildStore(builder, *face, face_var);
}
lp_build_else(&if_ctx);
{
struct lp_build_if_state if_ctx2;
ary_ge_arx_arz = LLVMBuildAnd(bld->builder, ary_ge_arx, ary_ge_arz, "");
ary_ge_arx_arz = LLVMBuildAnd(builder, ary_ge_arx, ary_ge_arz, "");
lp_build_if(&if_ctx2, bld->builder, ary_ge_arx_arz);
lp_build_if(&if_ctx2, bld->gallivm, ary_ge_arx_arz);
{
/* +/- Y face */
LLVMValueRef sign = lp_build_sgn(float_bld, ry);
@ -963,9 +972,9 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, ry,
PIPE_TEX_FACE_POS_Y,
PIPE_TEX_FACE_NEG_Y);
LLVMBuildStore(bld->builder, *face_s, face_s_var);
LLVMBuildStore(bld->builder, *face_t, face_t_var);
LLVMBuildStore(bld->builder, *face, face_var);
LLVMBuildStore(builder, *face_s, face_s_var);
LLVMBuildStore(builder, *face_t, face_t_var);
LLVMBuildStore(builder, *face, face_var);
}
lp_build_else(&if_ctx2);
{
@ -977,18 +986,18 @@ lp_build_cube_lookup(struct lp_build_sample_context *bld,
*face = lp_build_cube_face(bld, rz,
PIPE_TEX_FACE_POS_Z,
PIPE_TEX_FACE_NEG_Z);
LLVMBuildStore(bld->builder, *face_s, face_s_var);
LLVMBuildStore(bld->builder, *face_t, face_t_var);
LLVMBuildStore(bld->builder, *face, face_var);
LLVMBuildStore(builder, *face_s, face_s_var);
LLVMBuildStore(builder, *face_t, face_t_var);
LLVMBuildStore(builder, *face, face_var);
}
lp_build_endif(&if_ctx2);
}
lp_build_endif(&if_ctx);
*face_s = LLVMBuildLoad(bld->builder, face_s_var, "face_s");
*face_t = LLVMBuildLoad(bld->builder, face_t_var, "face_t");
*face = LLVMBuildLoad(bld->builder, face_var, "face");
*face_s = LLVMBuildLoad(builder, face_s_var, "face_s");
*face_t = LLVMBuildLoad(builder, face_t_var, "face_t");
*face = LLVMBuildLoad(builder, face_var, "face");
}
}
@ -1011,6 +1020,7 @@ lp_build_sample_partial_offset(struct lp_build_context *bld,
LLVMValueRef *out_offset,
LLVMValueRef *out_subcoord)
{
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef offset;
LLVMValueRef subcoord;
@ -1028,14 +1038,14 @@ lp_build_sample_partial_offset(struct lp_build_context *bld,
*/
#if 0
LLVMValueRef block_width = lp_build_const_int_vec(bld->type, block_length);
subcoord = LLVMBuildURem(bld->builder, coord, block_width, "");
coord = LLVMBuildUDiv(bld->builder, coord, block_width, "");
subcoord = LLVMBuildURem(builder, coord, block_width, "");
coord = LLVMBuildUDiv(builder, coord, block_width, "");
#else
unsigned logbase2 = util_unsigned_logbase2(block_length);
LLVMValueRef block_shift = lp_build_const_int_vec(bld->type, logbase2);
LLVMValueRef block_mask = lp_build_const_int_vec(bld->type, block_length - 1);
subcoord = LLVMBuildAnd(bld->builder, coord, block_mask, "");
coord = LLVMBuildLShr(bld->builder, coord, block_shift, "");
LLVMValueRef block_shift = lp_build_const_int_vec(bld->gallivm, bld->type, logbase2);
LLVMValueRef block_mask = lp_build_const_int_vec(bld->gallivm, bld->type, block_length - 1);
subcoord = LLVMBuildAnd(builder, coord, block_mask, "");
coord = LLVMBuildLShr(builder, coord, block_shift, "");
#endif
}
@ -1071,7 +1081,8 @@ lp_build_sample_offset(struct lp_build_context *bld,
LLVMValueRef x_stride;
LLVMValueRef offset;
x_stride = lp_build_const_vec(bld->type, format_desc->block.bits/8);
x_stride = lp_build_const_vec(bld->gallivm, bld->type,
format_desc->block.bits/8);
lp_build_sample_partial_offset(bld,
format_desc->block.width,

View file

@ -105,64 +105,64 @@ struct lp_sampler_dynamic_state
/** Obtain the base texture width (returns int32) */
LLVMValueRef
(*width)( const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the base texture height (returns int32) */
LLVMValueRef
(*height)( const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the base texture depth (returns int32) */
LLVMValueRef
(*depth)( const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit);
/** Obtain the number of mipmap levels minus one (returns int32) */
LLVMValueRef
(*last_level)( const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit);
/** Obtain stride in bytes between image rows/blocks (returns int32) */
LLVMValueRef
(*row_stride)( const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit);
/** Obtain stride in bytes between image slices (returns int32) */
LLVMValueRef
(*img_stride)( const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit);
/** Obtain pointer to array of pointers to mimpap levels */
LLVMValueRef
(*data_ptr)( const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
unsigned unit);
/** Obtain texture min lod (returns float) */
LLVMValueRef
(*min_lod)(const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder, unsigned unit);
struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture max lod (returns float) */
LLVMValueRef
(*max_lod)(const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder, unsigned unit);
struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture lod bias (returns float) */
LLVMValueRef
(*lod_bias)(const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder, unsigned unit);
struct gallivm_state *gallivm, unsigned unit);
/** Obtain texture border color (returns ptr to float[4]) */
LLVMValueRef
(*border_color)(const struct lp_sampler_dynamic_state *state,
LLVMBuilderRef builder, unsigned unit);
struct gallivm_state *gallivm, unsigned unit);
};
@ -171,7 +171,7 @@ struct lp_sampler_dynamic_state
*/
struct lp_build_sample_context
{
LLVMBuilderRef builder;
struct gallivm_state *gallivm;
const struct lp_sampler_static_state *static_state;
@ -385,7 +385,7 @@ lp_build_sample_offset(struct lp_build_context *bld,
void
lp_build_sample_soa(LLVMBuilderRef builder,
lp_build_sample_soa(struct gallivm_state *gallivm,
const struct lp_sampler_static_state *static_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type fp_type,
@ -399,7 +399,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
LLVMValueRef texel_out[4]);
void
lp_build_sample_nop(struct lp_type type,
lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type,
LLVMValueRef texel_out[4]);

View file

@ -52,6 +52,7 @@
#include "lp_bld_flow.h"
#include "lp_bld_gather.h"
#include "lp_bld_format.h"
#include "lp_bld_init.h"
#include "lp_bld_sample.h"
#include "lp_bld_sample_aos.h"
#include "lp_bld_quad.h"
@ -82,6 +83,7 @@ lp_build_sample_wrap_nearest_int(struct lp_build_sample_context *bld,
LLVMValueRef *out_i)
{
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one;
length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
@ -89,12 +91,12 @@ lp_build_sample_wrap_nearest_int(struct lp_build_sample_context *bld,
switch(wrap_mode) {
case PIPE_TEX_WRAP_REPEAT:
if(is_pot)
coord = LLVMBuildAnd(bld->builder, coord, length_minus_one, "");
coord = LLVMBuildAnd(builder, coord, length_minus_one, "");
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
coord = LLVMBuildAdd(bld->builder, coord, bias, "");
coord = LLVMBuildURem(bld->builder, coord, length, "");
coord = LLVMBuildAdd(builder, coord, bias, "");
coord = LLVMBuildURem(builder, coord, length, "");
}
break;
@ -147,6 +149,7 @@ lp_build_sample_wrap_linear_int(struct lp_build_sample_context *bld,
LLVMValueRef *i1)
{
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one;
LLVMValueRef lmask, umask, mask;
@ -195,39 +198,39 @@ lp_build_sample_wrap_linear_int(struct lp_build_sample_context *bld,
switch(wrap_mode) {
case PIPE_TEX_WRAP_REPEAT:
if (is_pot) {
coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, "");
}
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
coord0 = LLVMBuildAdd(bld->builder, coord0, bias, "");
coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
coord0 = LLVMBuildAdd(builder, coord0, bias, "");
coord0 = LLVMBuildURem(builder, coord0, length, "");
}
mask = lp_build_compare(bld->builder, int_coord_bld->type,
mask = lp_build_compare(bld->gallivm, int_coord_bld->type,
PIPE_FUNC_NOTEQUAL, coord0, length_minus_one);
*offset0 = lp_build_mul(int_coord_bld, coord0, stride);
*offset1 = LLVMBuildAnd(bld->builder,
*offset1 = LLVMBuildAnd(builder,
lp_build_add(int_coord_bld, *offset0, stride),
mask, "");
break;
case PIPE_TEX_WRAP_CLAMP_TO_EDGE:
lmask = lp_build_compare(int_coord_bld->builder, int_coord_bld->type,
lmask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type,
PIPE_FUNC_GEQUAL, coord0, int_coord_bld->zero);
umask = lp_build_compare(int_coord_bld->builder, int_coord_bld->type,
umask = lp_build_compare(int_coord_bld->gallivm, int_coord_bld->type,
PIPE_FUNC_LESS, coord0, length_minus_one);
coord0 = lp_build_select(int_coord_bld, lmask, coord0, int_coord_bld->zero);
coord0 = lp_build_select(int_coord_bld, umask, coord0, length_minus_one);
mask = LLVMBuildAnd(bld->builder, lmask, umask, "");
mask = LLVMBuildAnd(builder, lmask, umask, "");
*offset0 = lp_build_mul(int_coord_bld, coord0, stride);
*offset1 = lp_build_add(int_coord_bld,
*offset0,
LLVMBuildAnd(bld->builder, stride, mask, ""));
LLVMBuildAnd(builder, stride, mask, ""));
break;
case PIPE_TEX_WRAP_CLAMP:
@ -263,7 +266,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
LLVMValueRef *colors_hi)
{
const unsigned dims = bld->dims;
LLVMBuilderRef builder = bld->builder;
LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context i32, h16, u8n;
LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type;
LLVMValueRef i32_c8;
@ -273,13 +276,13 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
LLVMValueRef x_offset, offset;
LLVMValueRef x_subcoord, y_subcoord, z_subcoord;
lp_build_context_init(&i32, builder, lp_type_int_vec(32));
lp_build_context_init(&h16, builder, lp_type_ufixed(16));
lp_build_context_init(&u8n, builder, lp_type_unorm(8));
lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32));
lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16));
lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8));
i32_vec_type = lp_build_vec_type(i32.type);
h16_vec_type = lp_build_vec_type(h16.type);
u8n_vec_type = lp_build_vec_type(u8n.type);
i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type);
h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type);
u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type);
lp_build_extract_image_sizes(bld,
bld->int_size_type,
@ -317,7 +320,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
r = LLVMBuildFPToSI(builder, r, i32_vec_type, "");
/* compute floor (shift right 8) */
i32_c8 = lp_build_const_int_vec(i32.type, 8);
i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8);
s_ipart = LLVMBuildAShr(builder, s, i32_c8, "");
if (dims >= 2)
t_ipart = LLVMBuildAShr(builder, t, i32_c8, "");
@ -325,7 +328,8 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
r_ipart = LLVMBuildAShr(builder, r, i32_c8, "");
/* get pixel, row, image strides */
x_stride = lp_build_const_vec(bld->int_coord_bld.type,
x_stride = lp_build_const_vec(bld->gallivm,
bld->int_coord_bld.type,
bld->format_desc->block.bits/8);
/* Do texcoord wrapping, compute texel offset */
@ -387,7 +391,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
* Given the format is a rgba8, just read the pixels as is,
* without any swizzling. Swizzling will be done later.
*/
rgba8 = lp_build_gather(bld->builder,
rgba8 = lp_build_gather(bld->gallivm,
bld->texel_type.length,
bld->format_desc->block.bits,
bld->texel_type.width,
@ -396,7 +400,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, "");
}
else {
rgba8 = lp_build_fetch_rgba_aos(bld->builder,
rgba8 = lp_build_fetch_rgba_aos(bld->gallivm,
bld->format_desc,
u8n.type,
data_ptr, offset,
@ -405,7 +409,7 @@ lp_build_sample_image_nearest(struct lp_build_sample_context *bld,
}
/* Expand one 4*rgba8 to two 2*rgba16 */
lp_build_unpack2(builder, u8n.type, h16.type,
lp_build_unpack2(bld->gallivm, u8n.type, h16.type,
rgba8,
colors_lo, colors_hi);
}
@ -429,7 +433,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
LLVMValueRef *colors_hi)
{
const unsigned dims = bld->dims;
LLVMBuilderRef builder = bld->builder;
LLVMBuilderRef builder = bld->gallivm->builder;
struct lp_build_context i32, h16, u8n;
LLVMTypeRef i32_vec_type, h16_vec_type, u8n_vec_type;
LLVMValueRef i32_c8, i32_c128, i32_c255;
@ -450,13 +454,13 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
unsigned i, j, k;
unsigned numj, numk;
lp_build_context_init(&i32, builder, lp_type_int_vec(32));
lp_build_context_init(&h16, builder, lp_type_ufixed(16));
lp_build_context_init(&u8n, builder, lp_type_unorm(8));
lp_build_context_init(&i32, bld->gallivm, lp_type_int_vec(32));
lp_build_context_init(&h16, bld->gallivm, lp_type_ufixed(16));
lp_build_context_init(&u8n, bld->gallivm, lp_type_unorm(8));
i32_vec_type = lp_build_vec_type(i32.type);
h16_vec_type = lp_build_vec_type(h16.type);
u8n_vec_type = lp_build_vec_type(u8n.type);
i32_vec_type = lp_build_vec_type(bld->gallivm, i32.type);
h16_vec_type = lp_build_vec_type(bld->gallivm, h16.type);
u8n_vec_type = lp_build_vec_type(bld->gallivm, u8n.type);
lp_build_extract_image_sizes(bld,
bld->int_size_type,
@ -494,7 +498,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r = LLVMBuildFPToSI(builder, r, i32_vec_type, "");
/* subtract 0.5 (add -128) */
i32_c128 = lp_build_const_int_vec(i32.type, -128);
i32_c128 = lp_build_const_int_vec(bld->gallivm, i32.type, -128);
s = LLVMBuildAdd(builder, s, i32_c128, "");
if (dims >= 2) {
t = LLVMBuildAdd(builder, t, i32_c128, "");
@ -504,7 +508,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
}
/* compute floor (shift right 8) */
i32_c8 = lp_build_const_int_vec(i32.type, 8);
i32_c8 = lp_build_const_int_vec(bld->gallivm, i32.type, 8);
s_ipart = LLVMBuildAShr(builder, s, i32_c8, "");
if (dims >= 2)
t_ipart = LLVMBuildAShr(builder, t, i32_c8, "");
@ -512,7 +516,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_ipart = LLVMBuildAShr(builder, r, i32_c8, "");
/* compute fractional part (AND with 0xff) */
i32_c255 = lp_build_const_int_vec(i32.type, 255);
i32_c255 = lp_build_const_int_vec(bld->gallivm, i32.type, 255);
s_fpart = LLVMBuildAnd(builder, s, i32_c255, "");
if (dims >= 2)
t_fpart = LLVMBuildAnd(builder, t, i32_c255, "");
@ -520,7 +524,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_fpart = LLVMBuildAnd(builder, r, i32_c255, "");
/* get pixel, row and image strides */
x_stride = lp_build_const_vec(bld->int_coord_bld.type,
x_stride = lp_build_const_vec(bld->gallivm, bld->int_coord_bld.type,
bld->format_desc->block.bits/8);
y_stride = row_stride_vec;
z_stride = img_stride_vec;
@ -612,7 +616,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
r_fpart = LLVMBuildBitCast(builder, r_fpart, h16_vec_type, "");
{
LLVMTypeRef elem_type = LLVMInt32Type();
LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles_lo[LP_MAX_VECTOR_LENGTH];
LLVMValueRef shuffles_hi[LP_MAX_VECTOR_LENGTH];
LLVMValueRef shuffle_lo;
@ -685,7 +689,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
* Given the format is a rgba8, just read the pixels as is,
* without any swizzling. Swizzling will be done later.
*/
rgba8 = lp_build_gather(bld->builder,
rgba8 = lp_build_gather(bld->gallivm,
bld->texel_type.length,
bld->format_desc->block.bits,
bld->texel_type.width,
@ -694,7 +698,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
rgba8 = LLVMBuildBitCast(builder, rgba8, u8n_vec_type, "");
}
else {
rgba8 = lp_build_fetch_rgba_aos(bld->builder,
rgba8 = lp_build_fetch_rgba_aos(bld->gallivm,
bld->format_desc,
u8n.type,
data_ptr, offset[k][j][i],
@ -703,7 +707,7 @@ lp_build_sample_image_linear(struct lp_build_sample_context *bld,
}
/* Expand one 4*rgba8 to two 2*rgba16 */
lp_build_unpack2(builder, u8n.type, h16.type,
lp_build_unpack2(bld->gallivm, u8n.type, h16.type,
rgba8,
&neighbors_lo[k][j][i], &neighbors_hi[k][j][i]);
}
@ -790,7 +794,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef colors_lo_var,
LLVMValueRef colors_hi_var)
{
LLVMBuilderRef builder = bld->builder;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef size0;
LLVMValueRef size1;
LLVMValueRef row_stride0_vec;
@ -802,7 +806,6 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef colors0_lo, colors0_hi;
LLVMValueRef colors1_lo, colors1_hi;
/* sample the first mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel0,
&size0,
@ -829,8 +832,8 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMBuildStore(builder, colors0_hi, colors_hi_var);
if (mip_filter == PIPE_TEX_MIPFILTER_LINEAR) {
LLVMValueRef h16_scale = LLVMConstReal(LLVMFloatType(), 256.0);
LLVMTypeRef i32_type = LLVMIntType(32);
LLVMValueRef h16_scale = lp_build_const_float(bld->gallivm, 256.0);
LLVMTypeRef i32_type = LLVMIntTypeInContext(bld->gallivm->context, 32);
struct lp_build_if_state if_ctx;
LLVMValueRef need_lerp;
@ -842,11 +845,11 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
lod_fpart, LLVMConstNull(i32_type),
"need_lerp");
lp_build_if(&if_ctx, builder, need_lerp);
lp_build_if(&if_ctx, bld->gallivm, need_lerp);
{
struct lp_build_context h16_bld;
lp_build_context_init(&h16_bld, builder, lp_type_ufixed(16));
lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16));
/* sample the second mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel1,
@ -885,7 +888,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
int i;
assert(h16_bld.type.length <= Elements(shuffles));
for (i = 0; i < h16_bld.type.length; i++)
shuffles[i] = lp_build_const_int32(2 * (i & 1));
shuffles[i] = lp_build_const_int32(bld->gallivm, 2 * (i & 1));
shuffle = LLVMConstVector(shuffles, h16_bld.type.length);
lod_fpart = LLVMBuildShuffleVector(builder,
lod_fpart, lod_fpart,
@ -925,7 +928,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
LLVMValueRef texel_out[4])
{
struct lp_build_context *int_bld = &bld->int_bld;
LLVMBuilderRef builder = bld->builder;
LLVMBuilderRef builder = bld->gallivm->builder;
const unsigned mip_filter = bld->static_state->min_mip_filter;
const unsigned min_filter = bld->static_state->min_img_filter;
const unsigned mag_filter = bld->static_state->mag_img_filter;
@ -936,8 +939,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
LLVMValueRef unswizzled[4];
LLVMValueRef face_ddx[4], face_ddy[4];
struct lp_build_context h16_bld;
LLVMTypeRef i32t = LLVMInt32Type();
LLVMValueRef i32t_zero = LLVMConstInt(i32t, 0, 0);
LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
/* we only support the common/simple wrap modes at this time */
assert(lp_is_simple_wrap_mode(bld->static_state->wrap_s));
@ -948,7 +950,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
/* make 16-bit fixed-pt builder context */
lp_build_context_init(&h16_bld, builder, lp_type_ufixed(16));
lp_build_context_init(&h16_bld, bld->gallivm, lp_type_ufixed(16));
/* cube face selection, compute pre-face coords, etc. */
if (bld->static_state->target == PIPE_TEXTURE_CUBE) {
@ -1026,8 +1028,8 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
* Get/interpolate texture colors.
*/
packed_lo = lp_build_alloca(builder, h16_bld.vec_type, "packed_lo");
packed_hi = lp_build_alloca(builder, h16_bld.vec_type, "packed_hi");
packed_lo = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_lo");
packed_hi = lp_build_alloca(bld->gallivm, h16_bld.vec_type, "packed_hi");
if (min_filter == mag_filter) {
/* no need to distinquish between minification and magnification */
@ -1048,7 +1050,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
minify = LLVMBuildICmp(builder, LLVMIntSGE,
lod_ipart, int_bld->zero, "");
lp_build_if(&if_ctx, builder, minify);
lp_build_if(&if_ctx, bld->gallivm, minify);
{
/* Use the minification filter */
lp_build_sample_mipmap(bld,
@ -1073,7 +1075,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
* combine the values stored in 'packed_lo' and 'packed_hi' variables
* into 'packed'
*/
packed = lp_build_pack2(builder,
packed = lp_build_pack2(bld->gallivm,
h16_bld.type, lp_type_unorm(8),
LLVMBuildLoad(builder, packed_lo, ""),
LLVMBuildLoad(builder, packed_hi, ""));
@ -1081,7 +1083,7 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
/*
* Convert to SoA and swizzle.
*/
lp_build_rgba8_to_f32_soa(builder,
lp_build_rgba8_to_f32_soa(bld->gallivm,
bld->texel_type,
packed, unswizzled);
@ -1096,6 +1098,4 @@ lp_build_sample_aos(struct lp_build_sample_context *bld,
texel_out[2] = unswizzled[2];
texel_out[3] = unswizzled[3];
}
apply_sampler_swizzle(bld, texel_out);
}

View file

@ -84,6 +84,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
const struct lp_sampler_static_state *static_state = bld->static_state;
const unsigned dims = bld->dims;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef offset;
LLVMValueRef i, j;
LLVMValueRef use_border = NULL;
@ -95,7 +96,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
LLVMValueRef b1, b2;
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, x, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, x, width);
use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
if (dims >= 2 &&
@ -106,11 +107,11 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, y, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, y, height);
if (use_border) {
use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1");
use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2");
}
else {
use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
}
@ -122,11 +123,11 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
b1 = lp_build_cmp(int_coord_bld, PIPE_FUNC_LESS, z, int_coord_bld->zero);
b2 = lp_build_cmp(int_coord_bld, PIPE_FUNC_GEQUAL, z, depth);
if (use_border) {
use_border = LLVMBuildOr(bld->builder, use_border, b1, "ub_or_b1");
use_border = LLVMBuildOr(bld->builder, use_border, b2, "ub_or_b2");
use_border = LLVMBuildOr(builder, use_border, b1, "ub_or_b1");
use_border = LLVMBuildOr(builder, use_border, b2, "ub_or_b2");
}
else {
use_border = LLVMBuildOr(bld->builder, b1, b2, "b1_or_b2");
use_border = LLVMBuildOr(builder, b1, b2, "b1_or_b2");
}
}
@ -148,7 +149,7 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
offset = lp_build_andnot(&bld->int_coord_bld, offset, use_border);
}
lp_build_fetch_rgba_soa(bld->builder,
lp_build_fetch_rgba_soa(bld->gallivm,
bld->format_desc,
bld->texel_type,
data_ptr, offset,
@ -174,20 +175,18 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
/* select texel color or border color depending on use_border */
LLVMValueRef border_color_ptr =
bld->dynamic_state->border_color(bld->dynamic_state,
bld->builder, unit);
bld->gallivm, unit);
int chan;
for (chan = 0; chan < 4; chan++) {
LLVMValueRef border_chan =
lp_build_array_get(bld->builder, border_color_ptr,
lp_build_const_int32(chan));
lp_build_array_get(bld->gallivm, border_color_ptr,
lp_build_const_int32(bld->gallivm, chan));
LLVMValueRef border_chan_vec =
lp_build_broadcast_scalar(&bld->float_vec_bld, border_chan);
texel_out[chan] = lp_build_select(&bld->texel_bld, use_border,
border_chan_vec, texel_out[chan]);
}
}
apply_sampler_swizzle(bld, texel_out);
}
@ -205,7 +204,7 @@ lp_build_coord_mirror(struct lp_build_sample_context *bld,
lp_build_ifloor_fract(coord_bld, coord, &flr, &fract);
/* isOdd = flr & 1 */
isOdd = LLVMBuildAnd(bld->builder, flr, int_coord_bld->one, "");
isOdd = LLVMBuildAnd(bld->gallivm->builder, flr, int_coord_bld->one, "");
/* make coord positive or negative depending on isOdd */
coord = lp_build_set_sign(coord_bld, fract, isOdd);
@ -239,7 +238,8 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
{
struct lp_build_context *coord_bld = &bld->coord_bld;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
LLVMValueRef half = lp_build_const_vec(coord_bld->type, 0.5);
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef half = lp_build_const_vec(bld->gallivm, coord_bld->type, 0.5);
LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
LLVMValueRef coord0, coord1, weight;
@ -253,18 +253,18 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
/* repeat wrap */
if (is_pot) {
coord1 = lp_build_add(int_coord_bld, coord0, int_coord_bld->one);
coord0 = LLVMBuildAnd(bld->builder, coord0, length_minus_one, "");
coord1 = LLVMBuildAnd(bld->builder, coord1, length_minus_one, "");
coord0 = LLVMBuildAnd(builder, coord0, length_minus_one, "");
coord1 = LLVMBuildAnd(builder, coord1, length_minus_one, "");
}
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
LLVMValueRef mask;
coord0 = LLVMBuildAdd(bld->builder, coord0, bias, "");
coord0 = LLVMBuildURem(bld->builder, coord0, length, "");
mask = lp_build_compare(bld->builder, int_coord_bld->type,
coord0 = LLVMBuildAdd(builder, coord0, bias, "");
coord0 = LLVMBuildURem(builder, coord0, length, "");
mask = lp_build_compare(bld->gallivm, int_coord_bld->type,
PIPE_FUNC_NOTEQUAL, coord0, length_minus_one);
coord1 = LLVMBuildAnd(bld->builder,
coord1 = LLVMBuildAnd(builder,
lp_build_add(int_coord_bld, coord0, int_coord_bld->one),
mask, "");
}
@ -318,7 +318,7 @@ lp_build_sample_wrap_linear(struct lp_build_sample_context *bld,
}
/* was: clamp to [-0.5, length + 0.5], then sub 0.5 */
coord = lp_build_sub(coord_bld, coord, half);
min = lp_build_const_vec(coord_bld->type, -1.0F);
min = lp_build_const_vec(bld->gallivm, coord_bld->type, -1.0F);
coord = lp_build_clamp(coord_bld, coord, min, length_f);
/* convert to int, compute lerp weight */
lp_build_ifloor_fract(coord_bld, coord, &coord0, &weight);
@ -437,6 +437,7 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
{
struct lp_build_context *coord_bld = &bld->coord_bld;
struct lp_build_context *int_coord_bld = &bld->int_coord_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef length_minus_one = lp_build_sub(int_coord_bld, length, int_coord_bld->one);
LLVMValueRef icoord;
@ -445,12 +446,12 @@ lp_build_sample_wrap_nearest(struct lp_build_sample_context *bld,
coord = lp_build_mul(coord_bld, coord, length_f);
icoord = lp_build_ifloor(coord_bld, coord);
if (is_pot)
icoord = LLVMBuildAnd(bld->builder, icoord, length_minus_one, "");
icoord = LLVMBuildAnd(builder, icoord, length_minus_one, "");
else {
/* Add a bias to the texcoord to handle negative coords */
LLVMValueRef bias = lp_build_mul_imm(int_coord_bld, length, 1024);
icoord = LLVMBuildAdd(bld->builder, icoord, bias, "");
icoord = LLVMBuildURem(bld->builder, icoord, length, "");
icoord = LLVMBuildAdd(builder, icoord, bias, "");
icoord = LLVMBuildURem(builder, icoord, length, "");
}
break;
@ -830,7 +831,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
LLVMValueRef lod_fpart,
LLVMValueRef *colors_out)
{
LLVMBuilderRef builder = bld->builder;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef size0;
LLVMValueRef size1;
LLVMValueRef row_stride0_vec;
@ -878,7 +879,7 @@ lp_build_sample_mipmap(struct lp_build_sample_context *bld,
bld->float_bld.zero,
"need_lerp");
lp_build_if(&if_ctx, builder, need_lerp);
lp_build_if(&if_ctx, bld->gallivm, need_lerp);
{
/* sample the second mipmap level */
lp_build_mipmap_level_sizes(bld, ilevel1,
@ -934,7 +935,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
LLVMValueRef *colors_out)
{
struct lp_build_context *int_bld = &bld->int_bld;
LLVMBuilderRef builder = bld->builder;
LLVMBuilderRef builder = bld->gallivm->builder;
const unsigned mip_filter = bld->static_state->min_mip_filter;
const unsigned min_filter = bld->static_state->min_img_filter;
const unsigned mag_filter = bld->static_state->mag_img_filter;
@ -942,8 +943,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
LLVMValueRef ilevel0, ilevel1 = NULL;
LLVMValueRef face_ddx[4], face_ddy[4];
LLVMValueRef texels[4];
LLVMTypeRef i32t = LLVMInt32Type();
LLVMValueRef i32t_zero = LLVMConstInt(i32t, 0, 0);
LLVMValueRef i32t_zero = lp_build_const_int32(bld->gallivm, 0);
unsigned chan;
/*
@ -1030,7 +1030,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
*/
for (chan = 0; chan < 4; ++chan) {
texels[chan] = lp_build_alloca(builder, bld->texel_bld.vec_type, "");
texels[chan] = lp_build_alloca(bld->gallivm, bld->texel_bld.vec_type, "");
lp_build_name(texels[chan], "sampler%u_texel_%c_var", unit, "xyzw"[chan]);
}
@ -1053,7 +1053,7 @@ lp_build_sample_general(struct lp_build_sample_context *bld,
minify = LLVMBuildICmp(builder, LLVMIntSGE,
lod_ipart, int_bld->zero, "");
lp_build_if(&if_ctx, builder, minify);
lp_build_if(&if_ctx, bld->gallivm, minify);
{
/* Use the minification filter */
lp_build_sample_mipmap(bld, unit,
@ -1092,6 +1092,7 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
LLVMValueRef texel[4])
{
struct lp_build_context *texel_bld = &bld->texel_bld;
LLVMBuilderRef builder = bld->gallivm->builder;
LLVMValueRef res;
const unsigned chan = 0;
@ -1100,11 +1101,10 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
/* debug code */
if (0) {
LLVMValueRef indx = lp_build_const_int32(0);
LLVMValueRef coord = LLVMBuildExtractElement(bld->builder, p, indx, "");
LLVMValueRef tex = LLVMBuildExtractElement(bld->builder,
texel[chan], indx, "");
lp_build_printf(bld->builder, "shadow compare coord %f to texture %f\n",
LLVMValueRef indx = lp_build_const_int32(bld->gallivm, 0);
LLVMValueRef coord = LLVMBuildExtractElement(builder, p, indx, "");
LLVMValueRef tex = LLVMBuildExtractElement(builder, texel[chan], indx, "");
lp_build_printf(bld->gallivm, "shadow compare coord %f to texture %f\n",
coord, tex);
}
@ -1126,10 +1126,10 @@ lp_build_sample_compare(struct lp_build_sample_context *bld,
* For debugging.
*/
void
lp_build_sample_nop(struct lp_type type,
lp_build_sample_nop(struct gallivm_state *gallivm, struct lp_type type,
LLVMValueRef texel_out[4])
{
LLVMValueRef one = lp_build_one(type);
LLVMValueRef one = lp_build_one(gallivm, type);
unsigned chan;
for (chan = 0; chan < 4; chan++) {
@ -1147,7 +1147,7 @@ lp_build_sample_nop(struct lp_type type,
* \param ddy partial derivatives of (s,t,r,q) with respect to y
*/
void
lp_build_sample_soa(LLVMBuilderRef builder,
lp_build_sample_soa(struct gallivm_state *gallivm,
const struct lp_sampler_static_state *static_state,
struct lp_sampler_dynamic_state *dynamic_state,
struct lp_type type,
@ -1162,8 +1162,8 @@ lp_build_sample_soa(LLVMBuilderRef builder,
{
unsigned dims = texture_dims(static_state->target);
struct lp_build_sample_context bld;
LLVMTypeRef i32t = LLVMInt32Type();
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef s;
LLVMValueRef t;
LLVMValueRef r;
@ -1178,7 +1178,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
/* Setup our build context */
memset(&bld, 0, sizeof bld);
bld.builder = builder;
bld.gallivm = gallivm;
bld.static_state = static_state;
bld.dynamic_state = dynamic_state;
bld.format_desc = util_format_description(static_state->format);
@ -1195,22 +1195,22 @@ lp_build_sample_soa(LLVMBuilderRef builder,
float_vec_type = lp_type_float_vec(32);
lp_build_context_init(&bld.float_bld, builder, bld.float_type);
lp_build_context_init(&bld.float_vec_bld, builder, float_vec_type);
lp_build_context_init(&bld.int_bld, builder, bld.int_type);
lp_build_context_init(&bld.coord_bld, builder, bld.coord_type);
lp_build_context_init(&bld.int_coord_bld, builder, bld.int_coord_type);
lp_build_context_init(&bld.int_size_bld, builder, bld.int_size_type);
lp_build_context_init(&bld.float_size_bld, builder, bld.float_size_type);
lp_build_context_init(&bld.texel_bld, builder, bld.texel_type);
lp_build_context_init(&bld.float_bld, gallivm, bld.float_type);
lp_build_context_init(&bld.float_vec_bld, gallivm, float_vec_type);
lp_build_context_init(&bld.int_bld, gallivm, bld.int_type);
lp_build_context_init(&bld.coord_bld, gallivm, bld.coord_type);
lp_build_context_init(&bld.int_coord_bld, gallivm, bld.int_coord_type);
lp_build_context_init(&bld.int_size_bld, gallivm, bld.int_size_type);
lp_build_context_init(&bld.float_size_bld, gallivm, bld.float_size_type);
lp_build_context_init(&bld.texel_bld, gallivm, bld.texel_type);
/* Get the dynamic state */
bld.width = dynamic_state->width(dynamic_state, builder, unit);
bld.height = dynamic_state->height(dynamic_state, builder, unit);
bld.depth = dynamic_state->depth(dynamic_state, builder, unit);
bld.row_stride_array = dynamic_state->row_stride(dynamic_state, builder, unit);
bld.img_stride_array = dynamic_state->img_stride(dynamic_state, builder, unit);
bld.data_array = dynamic_state->data_ptr(dynamic_state, builder, unit);
bld.width = dynamic_state->width(dynamic_state, gallivm, unit);
bld.height = dynamic_state->height(dynamic_state, gallivm, unit);
bld.depth = dynamic_state->depth(dynamic_state, gallivm, unit);
bld.row_stride_array = dynamic_state->row_stride(dynamic_state, gallivm, unit);
bld.img_stride_array = dynamic_state->img_stride(dynamic_state, gallivm, unit);
bld.data_array = dynamic_state->data_ptr(dynamic_state, gallivm, unit);
/* Note that data_array is an array[level] of pointers to texture images */
s = coords[0];
@ -1236,7 +1236,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
if (0) {
/* For debug: no-op texture sampling */
lp_build_sample_nop(bld.texel_type, texel_out);
lp_build_sample_nop(gallivm, bld.texel_type, texel_out);
}
else if (util_format_fits_8unorm(bld.format_desc) &&
lp_is_simple_wrap_mode(static_state->wrap_s) &&
@ -1266,4 +1266,6 @@ lp_build_sample_soa(LLVMBuilderRef builder,
}
lp_build_sample_compare(&bld, r, texel_out);
apply_sampler_swizzle(&bld, texel_out);
}

View file

@ -37,12 +37,13 @@
#include "util/u_debug.h"
#include "util/u_memory.h"
#include "lp_bld_const.h"
#include "lp_bld_debug.h"
#include "lp_bld_struct.h"
LLVMValueRef
lp_build_struct_get_ptr(LLVMBuilderRef builder,
lp_build_struct_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
@ -51,16 +52,16 @@ lp_build_struct_get_ptr(LLVMBuilderRef builder,
LLVMValueRef member_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
indices[1] = LLVMConstInt(LLVMInt32Type(), member, 0);
member_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
indices[0] = lp_build_const_int32(gallivm, 0);
indices[1] = lp_build_const_int32(gallivm, member);
member_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), "");
lp_build_name(member_ptr, "%s.%s_ptr", LLVMGetValueName(ptr), name);
return member_ptr;
}
LLVMValueRef
lp_build_struct_get(LLVMBuilderRef builder,
lp_build_struct_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name)
@ -69,15 +70,15 @@ lp_build_struct_get(LLVMBuilderRef builder,
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMStructTypeKind);
member_ptr = lp_build_struct_get_ptr(builder, ptr, member, name);
res = LLVMBuildLoad(builder, member_ptr, "");
member_ptr = lp_build_struct_get_ptr(gallivm, ptr, member, name);
res = LLVMBuildLoad(gallivm->builder, member_ptr, "");
lp_build_name(res, "%s.%s", LLVMGetValueName(ptr), name);
return res;
}
LLVMValueRef
lp_build_array_get_ptr(LLVMBuilderRef builder,
lp_build_array_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index)
{
@ -85,9 +86,9 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
LLVMValueRef element_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
indices[0] = lp_build_const_int32(gallivm, 0);
indices[1] = index;
element_ptr = LLVMBuildGEP(builder, ptr, indices, Elements(indices), "");
element_ptr = LLVMBuildGEP(gallivm->builder, ptr, indices, Elements(indices), "");
#ifdef DEBUG
lp_build_name(element_ptr, "&%s[%s]",
LLVMGetValueName(ptr), LLVMGetValueName(index));
@ -97,7 +98,7 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
LLVMValueRef
lp_build_array_get(LLVMBuilderRef builder,
lp_build_array_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index)
{
@ -105,8 +106,8 @@ lp_build_array_get(LLVMBuilderRef builder,
LLVMValueRef res;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
element_ptr = lp_build_array_get_ptr(builder, ptr, index);
res = LLVMBuildLoad(builder, element_ptr, "");
element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
res = LLVMBuildLoad(gallivm->builder, element_ptr, "");
#ifdef DEBUG
lp_build_name(res, "%s[%s]", LLVMGetValueName(ptr), LLVMGetValueName(index));
#endif
@ -115,7 +116,7 @@ lp_build_array_get(LLVMBuilderRef builder,
void
lp_build_array_set(LLVMBuilderRef builder,
lp_build_array_set(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index,
LLVMValueRef value)
@ -123,8 +124,8 @@ lp_build_array_set(LLVMBuilderRef builder,
LLVMValueRef element_ptr;
assert(LLVMGetTypeKind(LLVMTypeOf(ptr)) == LLVMPointerTypeKind);
assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(ptr))) == LLVMArrayTypeKind);
element_ptr = lp_build_array_get_ptr(builder, ptr, index);
LLVMBuildStore(builder, value, element_ptr);
element_ptr = lp_build_array_get_ptr(gallivm, ptr, index);
LLVMBuildStore(gallivm->builder, value, element_ptr);
}

View file

@ -38,7 +38,7 @@
#include "gallivm/lp_bld.h"
#include <llvm-c/Target.h>
#include "gallivm/lp_bld_init.h"
#include "util/u_debug.h"
#include "util/u_memory.h"
@ -57,7 +57,7 @@
* Get value pointer to a structure member.
*/
LLVMValueRef
lp_build_struct_get_ptr(LLVMBuilderRef builder,
lp_build_struct_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name);
@ -66,7 +66,7 @@ lp_build_struct_get_ptr(LLVMBuilderRef builder,
* Get the value of a structure member.
*/
LLVMValueRef
lp_build_struct_get(LLVMBuilderRef builder,
lp_build_struct_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
unsigned member,
const char *name);
@ -75,7 +75,7 @@ lp_build_struct_get(LLVMBuilderRef builder,
* Get value pointer to an array element.
*/
LLVMValueRef
lp_build_array_get_ptr(LLVMBuilderRef builder,
lp_build_array_get_ptr(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index);
@ -83,7 +83,7 @@ lp_build_array_get_ptr(LLVMBuilderRef builder,
* Get the value of an array element.
*/
LLVMValueRef
lp_build_array_get(LLVMBuilderRef builder,
lp_build_array_get(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index);
@ -91,7 +91,7 @@ lp_build_array_get(LLVMBuilderRef builder,
* Set the value of an array element.
*/
void
lp_build_array_set(LLVMBuilderRef builder,
lp_build_array_set(struct gallivm_state *gallivm,
LLVMValueRef ptr,
LLVMValueRef index,
LLVMValueRef value);

View file

@ -37,12 +37,13 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
#include "lp_bld_init.h"
#include "lp_bld_logic.h"
#include "lp_bld_swizzle.h"
LLVMValueRef
lp_build_broadcast(LLVMBuilderRef builder,
lp_build_broadcast(struct gallivm_state *gallivm,
LLVMTypeRef vec_type,
LLVMValueRef scalar)
{
@ -52,8 +53,8 @@ lp_build_broadcast(LLVMBuilderRef builder,
res = LLVMGetUndef(vec_type);
for(i = 0; i < n; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
res = LLVMBuildInsertElement(builder, res, scalar, index, "");
LLVMValueRef index = lp_build_const_int32(gallivm, i);
res = LLVMBuildInsertElement(gallivm->builder, res, scalar, index, "");
}
return res;
@ -67,6 +68,7 @@ LLVMValueRef
lp_build_broadcast_scalar(struct lp_build_context *bld,
LLVMValueRef scalar)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
assert(lp_check_elem_type(type, LLVMTypeOf(scalar)));
@ -82,17 +84,17 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
struct lp_type i32_vec_type = lp_type_int_vec(32);
i32_vec_type.length = type.length;
res = LLVMBuildInsertElement(bld->builder, bld->undef, scalar,
LLVMConstInt(LLVMInt32Type(), 0, 0), "");
res = LLVMBuildShuffleVector(bld->builder, res, bld->undef,
lp_build_const_int_vec(i32_vec_type, 0), "");
res = LLVMBuildInsertElement(builder, bld->undef, scalar,
lp_build_const_int32(bld->gallivm, 0), "");
res = LLVMBuildShuffleVector(builder, res, bld->undef,
lp_build_const_int_vec(bld->gallivm, i32_vec_type, 0), "");
#else
/* XXX: The above path provokes a bug in LLVM 2.6 */
unsigned i;
res = bld->undef;
for(i = 0; i < type.length; ++i) {
LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0);
res = LLVMBuildInsertElement(bld->builder, res, scalar, index, "");
LLVMValueRef index = lp_build_const_int32(bld->gallivm, i);
res = LLVMBuildInsertElement(builder, res, scalar, index, "");
}
#endif
return res;
@ -104,13 +106,13 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
* Combined extract and broadcast (or a mere shuffle when the two types match)
*/
LLVMValueRef
lp_build_extract_broadcast(LLVMBuilderRef builder,
lp_build_extract_broadcast(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef vector,
LLVMValueRef index)
{
LLVMTypeRef i32t = LLVMInt32Type();
LLVMTypeRef i32t = LLVMInt32TypeInContext(gallivm->context);
LLVMValueRef res;
assert(src_type.floating == dst_type.floating);
@ -132,8 +134,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
* Broadcast scalar -> vector.
*/
res = lp_build_broadcast(builder,
lp_build_vec_type(dst_type),
res = lp_build_broadcast(gallivm,
lp_build_vec_type(gallivm, dst_type),
vector);
}
}
@ -144,16 +146,16 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
*/
LLVMValueRef shuffle;
shuffle = lp_build_broadcast(builder,
shuffle = lp_build_broadcast(gallivm,
LLVMVectorType(i32t, dst_type.length),
index);
res = LLVMBuildShuffleVector(builder, vector,
LLVMGetUndef(lp_build_vec_type(dst_type)),
res = LLVMBuildShuffleVector(gallivm->builder, vector,
LLVMGetUndef(lp_build_vec_type(gallivm, dst_type)),
shuffle, "");
}
else {
LLVMValueRef scalar;
scalar = LLVMBuildExtractElement(builder, vector, index, "");
scalar = LLVMBuildExtractElement(gallivm->builder, vector, index, "");
if (dst_type.length == 1) {
/*
* Trivial extract scalar from vector.
@ -166,8 +168,8 @@ lp_build_extract_broadcast(LLVMBuilderRef builder,
* General case of different sized vectors.
*/
res = lp_build_broadcast(builder,
lp_build_vec_type(dst_type),
res = lp_build_broadcast(gallivm,
lp_build_vec_type(gallivm, dst_type),
vector);
}
}
@ -185,6 +187,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
LLVMValueRef a,
unsigned channel)
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
@ -199,14 +202,14 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
LLVMTypeRef elem_type = LLVMInt32Type();
LLVMTypeRef elem_type = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
for(j = 0; j < n; j += 4)
for(i = 0; i < 4; ++i)
shuffles[j + i] = LLVMConstInt(elem_type, j + channel, 0);
return LLVMBuildShuffleVector(bld->builder, a, bld->undef, LLVMConstVector(shuffles, n), "");
return LLVMBuildShuffleVector(builder, a, bld->undef, LLVMConstVector(shuffles, n), "");
}
else {
/*
@ -226,8 +229,9 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
};
unsigned i;
a = LLVMBuildAnd(bld->builder, a,
lp_build_const_mask_aos(type, 1 << channel), "");
a = LLVMBuildAnd(builder, a,
lp_build_const_mask_aos(bld->gallivm,
type, 1 << channel), "");
/*
* Build a type where each element is an integer that cover the four
@ -239,7 +243,7 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
type4.width *= 4;
type4.length /= 4;
a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), "");
a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), "");
for(i = 0; i < 2; ++i) {
LLVMValueRef tmp = NULL;
@ -250,16 +254,16 @@ lp_build_swizzle_scalar_aos(struct lp_build_context *bld,
#endif
if(shift > 0)
tmp = LLVMBuildLShr(bld->builder, a, lp_build_const_int_vec(type4, shift*type.width), "");
tmp = LLVMBuildLShr(builder, a, lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), "");
if(shift < 0)
tmp = LLVMBuildShl(bld->builder, a, lp_build_const_int_vec(type4, -shift*type.width), "");
tmp = LLVMBuildShl(builder, a, lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), "");
assert(tmp);
if(tmp)
a = LLVMBuildOr(bld->builder, a, tmp, "");
a = LLVMBuildOr(builder, a, tmp, "");
}
return LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type), "");
return LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type), "");
}
}
@ -269,6 +273,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
LLVMValueRef a,
const unsigned char swizzles[4])
{
LLVMBuilderRef builder = bld->gallivm->builder;
const struct lp_type type = bld->type;
const unsigned n = type.length;
unsigned i, j;
@ -303,8 +308,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
/*
* Shuffle.
*/
LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(type));
LLVMTypeRef i32t = LLVMInt32Type();
LLVMValueRef undef = LLVMGetUndef(lp_build_elem_type(bld->gallivm, type));
LLVMTypeRef i32t = LLVMInt32TypeInContext(bld->gallivm->context);
LLVMValueRef shuffles[LP_MAX_VECTOR_LENGTH];
LLVMValueRef aux[LP_MAX_VECTOR_LENGTH];
@ -326,13 +331,13 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
case PIPE_SWIZZLE_ZERO:
shuffle = type.length + 0;
if (!aux[0]) {
aux[0] = lp_build_const_elem(type, 0.0);
aux[0] = lp_build_const_elem(bld->gallivm, type, 0.0);
}
break;
case PIPE_SWIZZLE_ONE:
shuffle = type.length + 1;
if (!aux[1]) {
aux[1] = lp_build_const_elem(type, 1.0);
aux[1] = lp_build_const_elem(bld->gallivm, type, 1.0);
}
break;
}
@ -346,7 +351,7 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
}
}
return LLVMBuildShuffleVector(bld->builder, a,
return LLVMBuildShuffleVector(builder, a,
LLVMConstVector(aux, n),
LLVMConstVector(shuffles, n), "");
} else {
@ -387,8 +392,8 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
type4.width *= 4;
type4.length /= 4;
a = LLVMBuildBitCast(bld->builder, a, lp_build_vec_type(type4), "");
res = LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type4), "");
a = LLVMBuildBitCast(builder, a, lp_build_vec_type(bld->gallivm, type4), "");
res = LLVMBuildBitCast(builder, res, lp_build_vec_type(bld->gallivm, type4), "");
/*
* Mask and shift the channels, trying to group as many channels in the
@ -414,23 +419,24 @@ lp_build_swizzle_aos(struct lp_build_context *bld,
if (0)
debug_printf("shift = %i, mask = 0x%08llx\n", shift, mask);
masked = LLVMBuildAnd(bld->builder, a,
lp_build_const_int_vec(type4, mask), "");
masked = LLVMBuildAnd(builder, a,
lp_build_const_int_vec(bld->gallivm, type4, mask), "");
if (shift > 0) {
shifted = LLVMBuildShl(bld->builder, masked,
lp_build_const_int_vec(type4, shift*type.width), "");
shifted = LLVMBuildShl(builder, masked,
lp_build_const_int_vec(bld->gallivm, type4, shift*type.width), "");
} else if (shift < 0) {
shifted = LLVMBuildLShr(bld->builder, masked,
lp_build_const_int_vec(type4, -shift*type.width), "");
shifted = LLVMBuildLShr(builder, masked,
lp_build_const_int_vec(bld->gallivm, type4, -shift*type.width), "");
} else {
shifted = masked;
}
res = LLVMBuildOr(bld->builder, res, shifted, "");
res = LLVMBuildOr(builder, res, shifted, "");
}
}
return LLVMBuildBitCast(bld->builder, res, lp_build_vec_type(type), "");
return LLVMBuildBitCast(builder, res,
lp_build_vec_type(bld->gallivm, type), "");
}
}

View file

@ -45,7 +45,7 @@ struct lp_build_context;
LLVMValueRef
lp_build_broadcast(LLVMBuilderRef builder,
lp_build_broadcast(struct gallivm_state *gallivm,
LLVMTypeRef vec_type,
LLVMValueRef scalar);
@ -56,7 +56,7 @@ lp_build_broadcast_scalar(struct lp_build_context *bld,
LLVMValueRef
lp_build_extract_broadcast(LLVMBuilderRef builder,
lp_build_extract_broadcast(struct gallivm_state *gallivm,
struct lp_type src_type,
struct lp_type dst_type,
LLVMValueRef vector,

View file

@ -46,6 +46,7 @@ struct tgsi_shader_info;
struct lp_type;
struct lp_build_context;
struct lp_build_mask_context;
struct gallivm_state;
enum lp_build_tex_modifier {
@ -141,7 +142,7 @@ struct lp_build_sampler_soa
void
(*emit_fetch_texel)( const struct lp_build_sampler_soa *sampler,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
struct lp_type type,
unsigned unit,
unsigned num_coords,
@ -174,7 +175,7 @@ lp_build_tgsi_info(const struct tgsi_token *tokens,
void
lp_build_tgsi_soa(LLVMBuilderRef builder,
lp_build_tgsi_soa(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
struct lp_build_mask_context *mask,
@ -187,7 +188,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
void
lp_build_tgsi_aos(LLVMBuilderRef builder,
lp_build_tgsi_aos(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
const unsigned char swizzles[4],

View file

@ -151,6 +151,7 @@ emit_fetch(
const struct tgsi_full_instruction *inst,
unsigned src_op)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
struct lp_type type = bld->base.type;
const struct tgsi_full_src_register *reg = &inst->Src[src_op];
LLVMValueRef res;
@ -175,14 +176,12 @@ emit_fetch(
LLVMValueRef scalar;
LLVMValueRef swizzle;
index = LLVMConstInt(LLVMInt32Type(),
reg->Register.Index*4 + chan,
0);
index = lp_build_const_int32(bld->base.gallivm, reg->Register.Index * 4 + chan);
scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->consts_ptr,
scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr,
&index, 1, "");
scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
scalar = LLVMBuildLoad(builder, scalar_ptr, "");
lp_build_name(scalar, "const[%u].%c", reg->Register.Index, "xyzw"[chan]);
@ -190,9 +189,9 @@ emit_fetch(
* NOTE: constants array is always assumed to be RGBA
*/
swizzle = LLVMConstInt(LLVMInt32Type(), chan, 0);
swizzle = lp_build_const_int32(bld->base.gallivm, chan);
res = LLVMBuildInsertElement(bld->base.builder, res, scalar, swizzle, "");
res = LLVMBuildInsertElement(builder, res, scalar, swizzle, "");
}
/*
@ -206,14 +205,14 @@ emit_fetch(
unsigned i;
for (chan = 0; chan < 4; ++chan) {
shuffles[chan] = LLVMConstInt(LLVMInt32Type(), chan, 0);
shuffles[chan] = lp_build_const_int32(bld->base.gallivm, chan);
}
for (i = 4; i < type.length; ++i) {
shuffles[i] = shuffles[i % 4];
}
res = LLVMBuildShuffleVector(bld->base.builder,
res = LLVMBuildShuffleVector(builder,
res, bld->base.undef,
LLVMConstVector(shuffles, type.length),
"");
@ -234,7 +233,7 @@ emit_fetch(
{
LLVMValueRef temp_ptr;
temp_ptr = bld->temps[reg->Register.Index];
res = LLVMBuildLoad(bld->base.builder, temp_ptr, "");
res = LLVMBuildLoad(builder, temp_ptr, "");
if (!res)
return bld->base.undef;
}
@ -281,6 +280,7 @@ emit_store(
unsigned index,
LLVMValueRef value)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
const struct tgsi_full_dst_register *reg = &inst->Dst[index];
LLVMValueRef mask = NULL;
LLVMValueRef ptr;
@ -299,7 +299,7 @@ emit_store(
break;
case TGSI_SAT_MINUS_PLUS_ONE:
value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0));
value = lp_build_min(&bld->base, value, bld->base.one);
break;
@ -344,20 +344,20 @@ emit_store(
assert(inst->Predicate.Index < LP_MAX_TGSI_PREDS);
pred = LLVMBuildLoad(bld->base.builder,
pred = LLVMBuildLoad(builder,
bld->preds[inst->Predicate.Index], "");
/*
* Convert the value to an integer mask.
*/
pred = lp_build_compare(bld->base.builder,
pred = lp_build_compare(bld->base.gallivm,
bld->base.type,
PIPE_FUNC_NOTEQUAL,
pred,
bld->base.zero);
if (inst->Predicate.Negate) {
pred = LLVMBuildNot(bld->base.builder, pred, "");
pred = LLVMBuildNot(builder, pred, "");
}
pred = swizzle_aos(bld, pred,
@ -367,7 +367,7 @@ emit_store(
inst->Predicate.SwizzleW);
if (mask) {
mask = LLVMBuildAnd(bld->base.builder, mask, pred, "");
mask = LLVMBuildAnd(builder, mask, pred, "");
} else {
mask = pred;
}
@ -380,10 +380,11 @@ emit_store(
if (reg->Register.WriteMask != TGSI_WRITEMASK_XYZW) {
LLVMValueRef writemask;
writemask = lp_build_const_mask_aos(bld->base.type, reg->Register.WriteMask);
writemask = lp_build_const_mask_aos(bld->base.gallivm, bld->base.type,
reg->Register.WriteMask);
if (mask) {
mask = LLVMBuildAnd(bld->base.builder, mask, writemask, "");
mask = LLVMBuildAnd(builder, mask, writemask, "");
} else {
mask = writemask;
}
@ -392,12 +393,12 @@ emit_store(
if (mask) {
LLVMValueRef orig_value;
orig_value = LLVMBuildLoad(bld->base.builder, ptr, "");
orig_value = LLVMBuildLoad(builder, ptr, "");
value = lp_build_select(&bld->base,
mask, value, orig_value);
}
LLVMBuildStore(bld->base.builder, value, ptr);
LLVMBuildStore(builder, value, ptr);
}
@ -454,7 +455,8 @@ emit_declaration(
struct lp_build_tgsi_aos_context *bld,
const struct tgsi_full_declaration *decl)
{
LLVMTypeRef vec_type = lp_build_vec_type(bld->base.type);
struct gallivm_state *gallivm = bld->base.gallivm;
LLVMTypeRef vec_type = lp_build_vec_type(bld->base.gallivm, bld->base.type);
unsigned first = decl->Range.First;
unsigned last = decl->Range.Last;
@ -465,31 +467,26 @@ emit_declaration(
case TGSI_FILE_TEMPORARY:
assert(idx < LP_MAX_TGSI_TEMPS);
if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
last + 1, 0);
bld->temps_array = lp_build_array_alloca(bld->base.builder,
LLVMValueRef array_size = lp_build_const_int32(gallivm, last + 1);
bld->temps_array = lp_build_array_alloca(bld->base.gallivm,
vec_type, array_size, "");
} else {
bld->temps[idx] = lp_build_alloca(bld->base.builder,
vec_type, "");
bld->temps[idx] = lp_build_alloca(gallivm, vec_type, "");
}
break;
case TGSI_FILE_OUTPUT:
bld->outputs[idx] = lp_build_alloca(bld->base.builder,
vec_type, "");
bld->outputs[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
case TGSI_FILE_ADDRESS:
assert(idx < LP_MAX_TGSI_ADDRS);
bld->addr[idx] = lp_build_alloca(bld->base.builder,
vec_type, "");
bld->addr[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
case TGSI_FILE_PREDICATE:
assert(idx < LP_MAX_TGSI_PREDS);
bld->preds[idx] = lp_build_alloca(bld->base.builder,
vec_type, "");
bld->preds[idx] = lp_build_alloca(gallivm, vec_type, "");
break;
default:
@ -644,7 +641,7 @@ emit_instruction(
src0 = emit_fetch(bld, inst, 0);
src1 = emit_fetch(bld, inst, 1);
src2 = emit_fetch(bld, inst, 2);
tmp1 = lp_build_const_vec(bld->base.type, 0.5);
tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5);
tmp0 = lp_build_cmp(&bld->base, PIPE_FUNC_GREATER, src2, tmp1);
dst0 = lp_build_select(&bld->base, tmp0, src0, src1);
break;
@ -1039,7 +1036,7 @@ emit_instruction(
void
lp_build_tgsi_aos(LLVMBuilderRef builder,
lp_build_tgsi_aos(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
const unsigned char swizzles[4],
@ -1058,8 +1055,8 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
/* Setup build context */
memset(&bld, 0, sizeof bld);
lp_build_context_init(&bld.base, builder, type);
lp_build_context_init(&bld.int_bld, builder, lp_int_type(type));
lp_build_context_init(&bld.base, gallivm, type);
lp_build_context_init(&bld.int_bld, gallivm, lp_int_type(type));
for (chan = 0; chan < 4; ++chan) {
bld.swizzles[chan] = swizzles[chan];
@ -1131,7 +1128,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
imm[swizzle] = parse.FullToken.FullImmediate.u[chan].Float;
}
bld.immediates[num_immediates] =
lp_build_const_aos(type,
lp_build_const_aos(gallivm, type,
imm[0], imm[1], imm[2], imm[3],
NULL);
num_immediates++;
@ -1156,7 +1153,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
}
if (0) {
LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
LLVMValueRef function = LLVMGetBasicBlockParent(block);
debug_printf("11111111111111111111111111111 \n");
tgsi_dump(tokens, 0);
@ -1167,7 +1164,7 @@ lp_build_tgsi_aos(LLVMBuilderRef builder,
if (0) {
LLVMModuleRef module = LLVMGetGlobalParent(
LLVMGetBasicBlockParent(LLVMGetInsertBlock(bld.base.builder)));
LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder)));
LLVMDumpModule(module);
}

View file

@ -51,6 +51,7 @@
#include "lp_bld_arit.h"
#include "lp_bld_bitarit.h"
#include "lp_bld_gather.h"
#include "lp_bld_init.h"
#include "lp_bld_logic.h"
#include "lp_bld_swizzle.h"
#include "lp_bld_flow.h"
@ -175,22 +176,24 @@ static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context
mask->loop_stack_size = 0;
mask->call_stack_size = 0;
mask->int_vec_type = lp_build_int_vec_type(mask->bld->type);
mask->int_vec_type = lp_build_int_vec_type(bld->gallivm, mask->bld->type);
mask->exec_mask = mask->ret_mask = mask->break_mask = mask->cont_mask = mask->cond_mask =
LLVMConstAllOnes(mask->int_vec_type);
}
static void lp_exec_mask_update(struct lp_exec_mask *mask)
{
LLVMBuilderRef builder = mask->bld->gallivm->builder;
if (mask->loop_stack_size) {
/*for loops we need to update the entire mask at runtime */
LLVMValueRef tmp;
assert(mask->break_mask);
tmp = LLVMBuildAnd(mask->bld->builder,
tmp = LLVMBuildAnd(builder,
mask->cont_mask,
mask->break_mask,
"maskcb");
mask->exec_mask = LLVMBuildAnd(mask->bld->builder,
mask->exec_mask = LLVMBuildAnd(builder,
mask->cond_mask,
tmp,
"maskfull");
@ -198,7 +201,7 @@ static void lp_exec_mask_update(struct lp_exec_mask *mask)
mask->exec_mask = mask->cond_mask;
if (mask->call_stack_size) {
mask->exec_mask = LLVMBuildAnd(mask->bld->builder,
mask->exec_mask = LLVMBuildAnd(builder,
mask->exec_mask,
mask->ret_mask,
"callmask");
@ -212,13 +215,15 @@ static void lp_exec_mask_update(struct lp_exec_mask *mask)
static void lp_exec_mask_cond_push(struct lp_exec_mask *mask,
LLVMValueRef val)
{
LLVMBuilderRef builder = mask->bld->gallivm->builder;
assert(mask->cond_stack_size < LP_MAX_TGSI_NESTING);
if (mask->cond_stack_size == 0) {
assert(mask->cond_mask == LLVMConstAllOnes(mask->int_vec_type));
}
mask->cond_stack[mask->cond_stack_size++] = mask->cond_mask;
assert(LLVMTypeOf(val) == mask->int_vec_type);
mask->cond_mask = LLVMBuildAnd(mask->bld->builder,
mask->cond_mask = LLVMBuildAnd(builder,
mask->cond_mask,
val,
"");
@ -227,6 +232,7 @@ static void lp_exec_mask_cond_push(struct lp_exec_mask *mask,
static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask)
{
LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMValueRef prev_mask;
LLVMValueRef inv_mask;
@ -236,9 +242,9 @@ static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask)
assert(prev_mask == LLVMConstAllOnes(mask->int_vec_type));
}
inv_mask = LLVMBuildNot(mask->bld->builder, mask->cond_mask, "");
inv_mask = LLVMBuildNot(builder, mask->cond_mask, "");
mask->cond_mask = LLVMBuildAnd(mask->bld->builder,
mask->cond_mask = LLVMBuildAnd(builder,
inv_mask,
prev_mask, "");
lp_exec_mask_update(mask);
@ -253,6 +259,8 @@ static void lp_exec_mask_cond_pop(struct lp_exec_mask *mask)
static void lp_exec_bgnloop(struct lp_exec_mask *mask)
{
LLVMBuilderRef builder = mask->bld->gallivm->builder;
if (mask->loop_stack_size == 0) {
assert(mask->loop_block == NULL);
assert(mask->cont_mask == LLVMConstAllOnes(mask->int_vec_type));
@ -268,25 +276,26 @@ static void lp_exec_bgnloop(struct lp_exec_mask *mask)
mask->loop_stack[mask->loop_stack_size].break_var = mask->break_var;
++mask->loop_stack_size;
mask->break_var = lp_build_alloca(mask->bld->builder, mask->int_vec_type, "");
LLVMBuildStore(mask->bld->builder, mask->break_mask, mask->break_var);
mask->break_var = lp_build_alloca(mask->bld->gallivm, mask->int_vec_type, "");
LLVMBuildStore(builder, mask->break_mask, mask->break_var);
mask->loop_block = lp_build_insert_new_block(mask->bld->builder, "bgnloop");
LLVMBuildBr(mask->bld->builder, mask->loop_block);
LLVMPositionBuilderAtEnd(mask->bld->builder, mask->loop_block);
mask->loop_block = lp_build_insert_new_block(mask->bld->gallivm, "bgnloop");
LLVMBuildBr(builder, mask->loop_block);
LLVMPositionBuilderAtEnd(builder, mask->loop_block);
mask->break_mask = LLVMBuildLoad(mask->bld->builder, mask->break_var, "");
mask->break_mask = LLVMBuildLoad(builder, mask->break_var, "");
lp_exec_mask_update(mask);
}
static void lp_exec_break(struct lp_exec_mask *mask)
{
LLVMValueRef exec_mask = LLVMBuildNot(mask->bld->builder,
LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMValueRef exec_mask = LLVMBuildNot(builder,
mask->exec_mask,
"break");
mask->break_mask = LLVMBuildAnd(mask->bld->builder,
mask->break_mask = LLVMBuildAnd(builder,
mask->break_mask,
exec_mask, "break_full");
@ -295,11 +304,12 @@ static void lp_exec_break(struct lp_exec_mask *mask)
static void lp_exec_continue(struct lp_exec_mask *mask)
{
LLVMValueRef exec_mask = LLVMBuildNot(mask->bld->builder,
LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMValueRef exec_mask = LLVMBuildNot(builder,
mask->exec_mask,
"");
mask->cont_mask = LLVMBuildAnd(mask->bld->builder,
mask->cont_mask = LLVMBuildAnd(builder,
mask->cont_mask,
exec_mask, "");
@ -307,11 +317,14 @@ static void lp_exec_continue(struct lp_exec_mask *mask)
}
static void lp_exec_endloop(struct lp_exec_mask *mask)
static void lp_exec_endloop(struct gallivm_state *gallivm,
struct lp_exec_mask *mask)
{
LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMBasicBlockRef endloop;
LLVMTypeRef reg_type = LLVMIntType(mask->bld->type.width*
mask->bld->type.length);
LLVMTypeRef reg_type = LLVMIntTypeInContext(gallivm->context,
mask->bld->type.width *
mask->bld->type.length);
LLVMValueRef i1cond;
assert(mask->break_mask);
@ -327,21 +340,21 @@ static void lp_exec_endloop(struct lp_exec_mask *mask)
* Unlike the continue mask, the break_mask must be preserved across loop
* iterations
*/
LLVMBuildStore(mask->bld->builder, mask->break_mask, mask->break_var);
LLVMBuildStore(builder, mask->break_mask, mask->break_var);
/* i1cond = (mask == 0) */
i1cond = LLVMBuildICmp(
mask->bld->builder,
builder,
LLVMIntNE,
LLVMBuildBitCast(mask->bld->builder, mask->exec_mask, reg_type, ""),
LLVMBuildBitCast(builder, mask->exec_mask, reg_type, ""),
LLVMConstNull(reg_type), "");
endloop = lp_build_insert_new_block(mask->bld->builder, "endloop");
endloop = lp_build_insert_new_block(mask->bld->gallivm, "endloop");
LLVMBuildCondBr(mask->bld->builder,
LLVMBuildCondBr(builder,
i1cond, mask->loop_block, endloop);
LLVMPositionBuilderAtEnd(mask->bld->builder, endloop);
LLVMPositionBuilderAtEnd(builder, endloop);
assert(mask->loop_stack_size);
--mask->loop_stack_size;
@ -363,10 +376,12 @@ static void lp_exec_mask_store(struct lp_exec_mask *mask,
LLVMValueRef val,
LLVMValueRef dst)
{
LLVMBuilderRef builder = mask->bld->gallivm->builder;
/* Mix the predicate and execution mask */
if (mask->has_mask) {
if (pred) {
pred = LLVMBuildAnd(mask->bld->builder, pred, mask->exec_mask, "");
pred = LLVMBuildAnd(builder, pred, mask->exec_mask, "");
} else {
pred = mask->exec_mask;
}
@ -375,14 +390,14 @@ static void lp_exec_mask_store(struct lp_exec_mask *mask,
if (pred) {
LLVMValueRef real_val, dst_val;
dst_val = LLVMBuildLoad(mask->bld->builder, dst, "");
dst_val = LLVMBuildLoad(builder, dst, "");
real_val = lp_build_select(mask->bld,
pred,
val, dst_val);
LLVMBuildStore(mask->bld->builder, real_val, dst);
LLVMBuildStore(builder, real_val, dst);
} else
LLVMBuildStore(mask->bld->builder, val, dst);
LLVMBuildStore(builder, val, dst);
}
static void lp_exec_mask_call(struct lp_exec_mask *mask,
@ -398,6 +413,7 @@ static void lp_exec_mask_call(struct lp_exec_mask *mask,
static void lp_exec_mask_ret(struct lp_exec_mask *mask, int *pc)
{
LLVMBuilderRef builder = mask->bld->gallivm->builder;
LLVMValueRef exec_mask;
if (mask->call_stack_size == 0) {
@ -405,11 +421,11 @@ static void lp_exec_mask_ret(struct lp_exec_mask *mask, int *pc)
*pc = -1;
return;
}
exec_mask = LLVMBuildNot(mask->bld->builder,
exec_mask = LLVMBuildNot(builder,
mask->exec_mask,
"ret");
mask->ret_mask = LLVMBuildAnd(mask->bld->builder,
mask->ret_mask = LLVMBuildAnd(builder,
mask->ret_mask,
exec_mask, "ret_full");
@ -441,10 +457,11 @@ get_temp_ptr(struct lp_build_tgsi_soa_context *bld,
unsigned index,
unsigned chan)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
assert(chan < 4);
if (bld->indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
return LLVMBuildGEP(bld->base.builder, bld->temps_array, &lindex, 1, "");
LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm, index * 4 + chan);
return LLVMBuildGEP(builder, bld->temps_array, &lindex, 1, "");
}
else {
return bld->temps[index][chan];
@ -462,10 +479,12 @@ get_output_ptr(struct lp_build_tgsi_soa_context *bld,
unsigned index,
unsigned chan)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
assert(chan < 4);
if (bld->indirect_files & (1 << TGSI_FILE_OUTPUT)) {
LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
return LLVMBuildGEP(bld->base.builder, bld->outputs_array, &lindex, 1, "");
LLVMValueRef lindex = lp_build_const_int32(bld->base.gallivm,
index * 4 + chan);
return LLVMBuildGEP(builder, bld->outputs_array, &lindex, 1, "");
}
else {
return bld->outputs[index][chan];
@ -482,6 +501,7 @@ build_gather(struct lp_build_tgsi_soa_context *bld,
LLVMValueRef base_ptr,
LLVMValueRef indexes)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
LLVMValueRef res = bld->base.undef;
unsigned i;
@ -489,14 +509,14 @@ build_gather(struct lp_build_tgsi_soa_context *bld,
* Loop over elements of index_vec, load scalar value, insert it into 'res'.
*/
for (i = 0; i < bld->base.type.length; i++) {
LLVMValueRef ii = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef index = LLVMBuildExtractElement(bld->base.builder,
LLVMValueRef ii = lp_build_const_int32(bld->base.gallivm, i);
LLVMValueRef index = LLVMBuildExtractElement(builder,
indexes, ii, "");
LLVMValueRef scalar_ptr = LLVMBuildGEP(bld->base.builder, base_ptr,
LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr,
&index, 1, "gather_ptr");
LLVMValueRef scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
LLVMValueRef scalar = LLVMBuildLoad(builder, scalar_ptr, "");
res = LLVMBuildInsertElement(bld->base.builder, res, scalar, ii, "");
res = LLVMBuildInsertElement(builder, res, scalar, ii, "");
}
return res;
@ -514,13 +534,14 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
struct lp_exec_mask *mask,
LLVMValueRef pred)
{
LLVMBuilderRef builder = bld->base.builder;
struct gallivm_state *gallivm = bld->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
unsigned i;
/* Mix the predicate and execution mask */
if (mask->has_mask) {
if (pred) {
pred = LLVMBuildAnd(mask->bld->builder, pred, mask->exec_mask, "");
pred = LLVMBuildAnd(builder, pred, mask->exec_mask, "");
}
else {
pred = mask->exec_mask;
@ -531,7 +552,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
* Loop over elements of index_vec, store scalar value.
*/
for (i = 0; i < bld->base.type.length; i++) {
LLVMValueRef ii = LLVMConstInt(LLVMInt32Type(), i, 0);
LLVMValueRef ii = lp_build_const_int32(gallivm, i);
LLVMValueRef index = LLVMBuildExtractElement(builder, indexes, ii, "");
LLVMValueRef scalar_ptr = LLVMBuildGEP(builder, base_ptr, &index, 1, "scatter_ptr");
LLVMValueRef val = LLVMBuildExtractElement(builder, values, ii, "scatter_val");
@ -539,7 +560,7 @@ emit_mask_scatter(struct lp_build_tgsi_soa_context *bld,
LLVMBuildExtractElement(builder, pred, ii, "scatter_pred") : NULL;
if (0)
lp_build_printf(builder, "scatter %d: val %f at %d %p\n",
lp_build_printf(gallivm, "scatter %d: val %f at %d %p\n",
ii, val, index, scalar_ptr);
if (scalar_pred) {
@ -566,6 +587,7 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld,
unsigned reg_file, unsigned reg_index,
const struct tgsi_src_register *indirect_reg)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
struct lp_build_context *uint_bld = &bld->uint_bld;
/* always use X component of address register */
unsigned swizzle = indirect_reg->SwizzleX;
@ -576,21 +598,22 @@ get_indirect_index(struct lp_build_tgsi_soa_context *bld,
assert(bld->indirect_files & (1 << reg_file));
base = lp_build_const_int_vec(uint_bld->type, reg_index);
base = lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, reg_index);
assert(swizzle < 4);
rel = LLVMBuildLoad(bld->base.builder,
rel = LLVMBuildLoad(builder,
bld->addr[indirect_reg->Index][swizzle],
"load addr reg");
/* for indexing we want integers */
rel = LLVMBuildFPToSI(bld->base.builder,
rel = LLVMBuildFPToSI(builder,
rel,
uint_bld->vec_type, "");
index = lp_build_add(uint_bld, base, rel);
max_index = lp_build_const_int_vec(uint_bld->type,
max_index = lp_build_const_int_vec(bld->base.gallivm,
uint_bld->type,
bld->info->file_max[reg_file]);
assert(!uint_bld->type.sign);
@ -610,6 +633,8 @@ emit_fetch(
unsigned src_op,
const unsigned chan_index )
{
struct gallivm_state *gallivm = bld->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
struct lp_build_context *uint_bld = &bld->uint_bld;
const struct tgsi_full_src_register *reg = &inst->Src[src_op];
const unsigned swizzle =
@ -635,7 +660,7 @@ emit_fetch(
case TGSI_FILE_CONSTANT:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
lp_build_const_int_vec(uint_bld->type, swizzle);
lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle);
LLVMValueRef index_vec; /* index into the const buffer */
/* index_vec = indirect_index * 4 + swizzle */
@ -649,11 +674,11 @@ emit_fetch(
LLVMValueRef index; /* index into the const buffer */
LLVMValueRef scalar, scalar_ptr;
index = lp_build_const_int32(reg->Register.Index*4 + swizzle);
index = lp_build_const_int32(gallivm, reg->Register.Index*4 + swizzle);
scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->consts_ptr,
scalar_ptr = LLVMBuildGEP(builder, bld->consts_ptr,
&index, 1, "");
scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
scalar = LLVMBuildLoad(builder, scalar_ptr, "");
res = lp_build_broadcast_scalar(&bld->base, scalar);
}
@ -667,9 +692,9 @@ emit_fetch(
case TGSI_FILE_INPUT:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
lp_build_const_int_vec(uint_bld->type, swizzle);
lp_build_const_int_vec(gallivm, uint_bld->type, swizzle);
LLVMValueRef length_vec =
lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length);
LLVMValueRef index_vec; /* index into the const buffer */
LLVMValueRef inputs_array;
LLVMTypeRef float4_ptr_type;
@ -680,18 +705,19 @@ emit_fetch(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
/* cast inputs_array pointer to float* */
float4_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
inputs_array = LLVMBuildBitCast(uint_bld->builder, bld->inputs_array,
float4_ptr_type, "");
float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
inputs_array = LLVMBuildBitCast(builder, bld->inputs_array,
float4_ptr_type, "");
/* Gather values from the temporary register array */
res = build_gather(bld, inputs_array, index_vec);
} else {
if (bld->indirect_files & (1 << TGSI_FILE_INPUT)) {
LLVMValueRef lindex = lp_build_const_int32(reg->Register.Index * 4 + swizzle);
LLVMValueRef input_ptr = LLVMBuildGEP(bld->base.builder,
LLVMValueRef lindex = lp_build_const_int32(gallivm,
reg->Register.Index * 4 + swizzle);
LLVMValueRef input_ptr = LLVMBuildGEP(builder,
bld->inputs_array, &lindex, 1, "");
res = LLVMBuildLoad(bld->base.builder, input_ptr, "");
res = LLVMBuildLoad(builder, input_ptr, "");
}
else {
res = bld->inputs[reg->Register.Index][swizzle];
@ -703,9 +729,10 @@ emit_fetch(
case TGSI_FILE_TEMPORARY:
if (reg->Register.Indirect) {
LLVMValueRef swizzle_vec =
lp_build_const_int_vec(uint_bld->type, swizzle);
lp_build_const_int_vec(bld->base.gallivm, uint_bld->type, swizzle);
LLVMValueRef length_vec =
lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
lp_build_const_int_vec(bld->base.gallivm, uint_bld->type,
bld->base.type.length);
LLVMValueRef index_vec; /* index into the const buffer */
LLVMValueRef temps_array;
LLVMTypeRef float4_ptr_type;
@ -716,8 +743,8 @@ emit_fetch(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
/* cast temps_array pointer to float* */
float4_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
temps_array = LLVMBuildBitCast(uint_bld->builder, bld->temps_array,
float4_ptr_type = LLVMPointerType(LLVMFloatTypeInContext(bld->base.gallivm->context), 0);
temps_array = LLVMBuildBitCast(builder, bld->temps_array,
float4_ptr_type, "");
/* Gather values from the temporary register array */
@ -726,7 +753,7 @@ emit_fetch(
else {
LLVMValueRef temp_ptr;
temp_ptr = get_temp_ptr(bld, reg->Register.Index, swizzle);
res = LLVMBuildLoad(bld->base.builder, temp_ptr, "");
res = LLVMBuildLoad(builder, temp_ptr, "");
if (!res)
return bld->base.undef;
}
@ -796,6 +823,7 @@ emit_fetch_predicate(
const struct tgsi_full_instruction *inst,
LLVMValueRef *pred)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
unsigned index;
unsigned char swizzles[4];
LLVMValueRef unswizzled[4] = {NULL, NULL, NULL, NULL};
@ -825,7 +853,7 @@ emit_fetch_predicate(
* in the swizzles
*/
if (!unswizzled[swizzle]) {
value = LLVMBuildLoad(bld->base.builder,
value = LLVMBuildLoad(builder,
bld->preds[index][swizzle], "");
/*
@ -835,13 +863,13 @@ emit_fetch_predicate(
* is needlessly causing two comparisons due to storing the intermediate
* result as float vector instead of an integer mask vector.
*/
value = lp_build_compare(bld->base.builder,
value = lp_build_compare(bld->base.gallivm,
bld->base.type,
PIPE_FUNC_NOTEQUAL,
value,
bld->base.zero);
if (inst->Predicate.Negate) {
value = LLVMBuildNot(bld->base.builder, value, "");
value = LLVMBuildNot(builder, value, "");
}
unswizzled[swizzle] = value;
@ -866,6 +894,8 @@ emit_store(
LLVMValueRef pred,
LLVMValueRef value)
{
struct gallivm_state *gallivm = bld->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
const struct tgsi_full_dst_register *reg = &inst->Dst[index];
struct lp_build_context *uint_bld = &bld->uint_bld;
LLVMValueRef indirect_index = NULL;
@ -880,7 +910,7 @@ emit_store(
break;
case TGSI_SAT_MINUS_PLUS_ONE:
value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.type, -1.0));
value = lp_build_max(&bld->base, value, lp_build_const_vec(bld->base.gallivm, bld->base.type, -1.0));
value = lp_build_min(&bld->base, value, bld->base.one);
break;
@ -900,11 +930,10 @@ emit_store(
switch( reg->Register.File ) {
case TGSI_FILE_OUTPUT:
if (reg->Register.Indirect) {
LLVMBuilderRef builder = bld->base.builder;
LLVMValueRef chan_vec =
lp_build_const_int_vec(uint_bld->type, chan_index);
lp_build_const_int_vec(gallivm, uint_bld->type, chan_index);
LLVMValueRef length_vec =
lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
lp_build_const_int_vec(gallivm, uint_bld->type, bld->base.type.length);
LLVMValueRef index_vec; /* indexes into the temp registers */
LLVMValueRef outputs_array;
LLVMValueRef pixel_offsets;
@ -914,7 +943,7 @@ emit_store(
/* build pixel offset vector: {0, 1, 2, 3, ...} */
pixel_offsets = uint_bld->undef;
for (i = 0; i < bld->base.type.length; i++) {
LLVMValueRef ii = lp_build_const_int32(i);
LLVMValueRef ii = lp_build_const_int32(gallivm, i);
pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets,
ii, ii, "");
}
@ -925,7 +954,8 @@ emit_store(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets);
float_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
float_ptr_type =
LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
outputs_array = LLVMBuildBitCast(builder, bld->outputs_array,
float_ptr_type, "");
@ -942,11 +972,11 @@ emit_store(
case TGSI_FILE_TEMPORARY:
if (reg->Register.Indirect) {
LLVMBuilderRef builder = bld->base.builder;
LLVMValueRef chan_vec =
lp_build_const_int_vec(uint_bld->type, chan_index);
lp_build_const_int_vec(gallivm, uint_bld->type, chan_index);
LLVMValueRef length_vec =
lp_build_const_int_vec(uint_bld->type, bld->base.type.length);
lp_build_const_int_vec(gallivm, uint_bld->type,
bld->base.type.length);
LLVMValueRef index_vec; /* indexes into the temp registers */
LLVMValueRef temps_array;
LLVMValueRef pixel_offsets;
@ -956,7 +986,7 @@ emit_store(
/* build pixel offset vector: {0, 1, 2, 3, ...} */
pixel_offsets = uint_bld->undef;
for (i = 0; i < bld->base.type.length; i++) {
LLVMValueRef ii = lp_build_const_int32(i);
LLVMValueRef ii = lp_build_const_int32(gallivm, i);
pixel_offsets = LLVMBuildInsertElement(builder, pixel_offsets,
ii, ii, "");
}
@ -967,7 +997,8 @@ emit_store(
index_vec = lp_build_mul(uint_bld, index_vec, length_vec);
index_vec = lp_build_add(uint_bld, index_vec, pixel_offsets);
float_ptr_type = LLVMPointerType(LLVMFloatType(), 0);
float_ptr_type =
LLVMPointerType(LLVMFloatTypeInContext(gallivm->context), 0);
temps_array = LLVMBuildBitCast(builder, bld->temps_array,
float_ptr_type, "");
@ -984,7 +1015,7 @@ emit_store(
case TGSI_FILE_ADDRESS:
lp_exec_mask_store(&bld->exec_mask, pred, value,
bld->addr[reg->Indirect.Index][chan_index]);
bld->addr[reg->Register.Index][chan_index]);
break;
case TGSI_FILE_PREDICATE:
@ -1008,6 +1039,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
enum lp_build_tex_modifier modifier,
LLVMValueRef *texel)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
unsigned unit;
LLVMValueRef lod_bias, explicit_lod;
LLVMValueRef oow = NULL;
@ -1073,13 +1105,12 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
}
if (modifier == LP_BLD_TEX_MODIFIER_EXPLICIT_DERIV) {
LLVMTypeRef i32t = LLVMInt32Type();
LLVMValueRef index0 = LLVMConstInt(i32t, 0, 0);
LLVMValueRef index0 = lp_build_const_int32(bld->base.gallivm, 0);
for (i = 0; i < num_coords; i++) {
LLVMValueRef src1 = emit_fetch( bld, inst, 1, i );
LLVMValueRef src2 = emit_fetch( bld, inst, 2, i );
ddx[i] = LLVMBuildExtractElement(bld->base.builder, src1, index0, "");
ddy[i] = LLVMBuildExtractElement(bld->base.builder, src2, index0, "");
ddx[i] = LLVMBuildExtractElement(builder, src1, index0, "");
ddy[i] = LLVMBuildExtractElement(builder, src2, index0, "");
}
unit = inst->Src[3].Register.Index;
} else {
@ -1095,7 +1126,7 @@ emit_tex( struct lp_build_tgsi_soa_context *bld,
}
bld->sampler->emit_fetch_texel(bld->sampler,
bld->base.builder,
bld->base.gallivm,
bld->base.type,
unit, num_coords, coords,
ddx, ddy,
@ -1150,6 +1181,7 @@ emit_kil(
const struct tgsi_full_instruction *inst,
int pc)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
const struct tgsi_full_src_register *reg = &inst->Src[0];
LLVMValueRef terms[NUM_CHANNELS];
LLVMValueRef mask;
@ -1181,7 +1213,7 @@ emit_kil(
chan_mask = lp_build_cmp(&bld->base, PIPE_FUNC_GEQUAL, terms[chan_index], bld->base.zero);
if(mask)
mask = LLVMBuildAnd(bld->base.builder, mask, chan_mask, "");
mask = LLVMBuildAnd(builder, mask, chan_mask, "");
else
mask = chan_mask;
}
@ -1207,13 +1239,14 @@ emit_kilp(struct lp_build_tgsi_soa_context *bld,
const struct tgsi_full_instruction *inst,
int pc)
{
LLVMBuilderRef builder = bld->base.gallivm->builder;
LLVMValueRef mask;
/* For those channels which are "alive", disable fragment shader
* execution.
*/
if (bld->exec_mask.has_mask) {
mask = LLVMBuildNot(bld->base.builder, bld->exec_mask.exec_mask, "kilp");
mask = LLVMBuildNot(builder, bld->exec_mask.exec_mask, "kilp");
}
else {
LLVMValueRef zero = LLVMConstNull(bld->base.int_vec_type);
@ -1234,38 +1267,39 @@ emit_kilp(struct lp_build_tgsi_soa_context *bld,
static void
emit_dump_temps(struct lp_build_tgsi_soa_context *bld)
{
LLVMBuilderRef builder = bld->base.builder;
struct gallivm_state *gallivm = bld->base.gallivm;
LLVMBuilderRef builder = gallivm->builder;
LLVMValueRef temp_ptr;
LLVMValueRef i0 = lp_build_const_int32(0);
LLVMValueRef i1 = lp_build_const_int32(1);
LLVMValueRef i2 = lp_build_const_int32(2);
LLVMValueRef i3 = lp_build_const_int32(3);
LLVMValueRef i0 = lp_build_const_int32(gallivm, 0);
LLVMValueRef i1 = lp_build_const_int32(gallivm, 1);
LLVMValueRef i2 = lp_build_const_int32(gallivm, 2);
LLVMValueRef i3 = lp_build_const_int32(gallivm, 3);
int index;
int n = bld->info->file_max[TGSI_FILE_TEMPORARY];
for (index = 0; index < n; index++) {
LLVMValueRef idx = lp_build_const_int32(index);
LLVMValueRef idx = lp_build_const_int32(gallivm, index);
LLVMValueRef v[4][4], res;
int chan;
lp_build_printf(builder, "TEMP[%d]:\n", idx);
lp_build_printf(gallivm, "TEMP[%d]:\n", idx);
for (chan = 0; chan < 4; chan++) {
temp_ptr = get_temp_ptr(bld, index, chan);
res = LLVMBuildLoad(bld->base.builder, temp_ptr, "");
res = LLVMBuildLoad(builder, temp_ptr, "");
v[chan][0] = LLVMBuildExtractElement(builder, res, i0, "");
v[chan][1] = LLVMBuildExtractElement(builder, res, i1, "");
v[chan][2] = LLVMBuildExtractElement(builder, res, i2, "");
v[chan][3] = LLVMBuildExtractElement(builder, res, i3, "");
}
lp_build_printf(builder, " X: %f %f %f %f\n",
lp_build_printf(gallivm, " X: %f %f %f %f\n",
v[0][0], v[0][1], v[0][2], v[0][3]);
lp_build_printf(builder, " Y: %f %f %f %f\n",
lp_build_printf(gallivm, " Y: %f %f %f %f\n",
v[1][0], v[1][1], v[1][2], v[1][3]);
lp_build_printf(builder, " Z: %f %f %f %f\n",
lp_build_printf(gallivm, " Z: %f %f %f %f\n",
v[2][0], v[2][1], v[2][2], v[2][3]);
lp_build_printf(builder, " W: %f %f %f %f\n",
lp_build_printf(gallivm, " W: %f %f %f %f\n",
v[3][0], v[3][1], v[3][2], v[3][3]);
}
}
@ -1277,6 +1311,7 @@ emit_declaration(
struct lp_build_tgsi_soa_context *bld,
const struct tgsi_full_declaration *decl)
{
struct gallivm_state *gallivm = bld->base.gallivm;
LLVMTypeRef vec_type = bld->base.vec_type;
const unsigned first = decl->Range.First;
const unsigned last = decl->Range.Last;
@ -1289,15 +1324,14 @@ emit_declaration(
assert(idx < LP_MAX_TGSI_TEMPS);
if (!(bld->indirect_files & (1 << TGSI_FILE_TEMPORARY))) {
for (i = 0; i < NUM_CHANNELS; i++)
bld->temps[idx][i] = lp_build_alloca(bld->base.builder,
vec_type, "temp");
bld->temps[idx][i] = lp_build_alloca(gallivm, vec_type, "temp");
}
break;
case TGSI_FILE_OUTPUT:
if (!(bld->indirect_files & (1 << TGSI_FILE_OUTPUT))) {
for (i = 0; i < NUM_CHANNELS; i++)
bld->outputs[idx][i] = lp_build_alloca(bld->base.builder,
bld->outputs[idx][i] = lp_build_alloca(gallivm,
vec_type, "output");
}
break;
@ -1305,15 +1339,14 @@ emit_declaration(
case TGSI_FILE_ADDRESS:
assert(idx < LP_MAX_TGSI_ADDRS);
for (i = 0; i < NUM_CHANNELS; i++)
bld->addr[idx][i] = lp_build_alloca(bld->base.builder,
vec_type, "addr");
bld->addr[idx][i] = lp_build_alloca(gallivm, vec_type, "addr");
break;
case TGSI_FILE_PREDICATE:
assert(idx < LP_MAX_TGSI_PREDS);
for (i = 0; i < NUM_CHANNELS; i++)
bld->preds[idx][i] = lp_build_alloca(bld->base.builder,
vec_type, "predicate");
bld->preds[idx][i] = lp_build_alloca(gallivm, vec_type,
"predicate");
break;
default:
@ -1639,7 +1672,7 @@ emit_instruction(
src0 = emit_fetch( bld, inst, 0, chan_index );
src1 = emit_fetch( bld, inst, 1, chan_index );
src2 = emit_fetch( bld, inst, 2, chan_index );
tmp1 = lp_build_const_vec(bld->base.type, 0.5);
tmp1 = lp_build_const_vec(bld->base.gallivm, bld->base.type, 0.5);
tmp0 = lp_build_cmp( &bld->base, PIPE_FUNC_GREATER, src2, tmp1);
dst0[chan_index] = lp_build_select( &bld->base, tmp0, src0, src1 );
}
@ -2151,7 +2184,7 @@ emit_instruction(
break;
case TGSI_OPCODE_ENDLOOP:
lp_exec_endloop(&bld->exec_mask);
lp_exec_endloop(bld->base.gallivm, &bld->exec_mask);
break;
case TGSI_OPCODE_ENDSUB:
@ -2284,7 +2317,7 @@ emit_instruction(
void
lp_build_tgsi_soa(LLVMBuilderRef builder,
lp_build_tgsi_soa(struct gallivm_state *gallivm,
const struct tgsi_token *tokens,
struct lp_type type,
struct lp_build_mask_context *mask,
@ -2312,9 +2345,9 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
/* Setup build context */
memset(&bld, 0, sizeof bld);
lp_build_context_init(&bld.base, builder, type);
lp_build_context_init(&bld.uint_bld, builder, lp_uint_type(type));
lp_build_context_init(&bld.elem_bld, builder, lp_elem_type(type));
lp_build_context_init(&bld.base, gallivm, type);
lp_build_context_init(&bld.uint_bld, gallivm, lp_uint_type(type));
lp_build_context_init(&bld.elem_bld, gallivm, lp_elem_type(type));
bld.mask = mask;
bld.pos = pos;
bld.inputs = inputs;
@ -2334,17 +2367,19 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
lp_exec_mask_init(&bld.exec_mask, &bld.base);
if (bld.indirect_files & (1 << TGSI_FILE_TEMPORARY)) {
LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
info->file_max[TGSI_FILE_TEMPORARY]*4 + 4, 0);
bld.temps_array = lp_build_array_alloca(bld.base.builder,
LLVMValueRef array_size =
lp_build_const_int32(gallivm,
info->file_max[TGSI_FILE_TEMPORARY] * 4 + 4);
bld.temps_array = lp_build_array_alloca(gallivm,
bld.base.vec_type, array_size,
"temp_array");
}
if (bld.indirect_files & (1 << TGSI_FILE_OUTPUT)) {
LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
info->file_max[TGSI_FILE_OUTPUT]*4 + 4, 0);
bld.outputs_array = lp_build_array_alloca(bld.base.builder,
LLVMValueRef array_size =
lp_build_const_int32(gallivm,
info->file_max[TGSI_FILE_OUTPUT] * 4 + 4);
bld.outputs_array = lp_build_array_alloca(gallivm,
bld.base.vec_type, array_size,
"output_array");
}
@ -2354,9 +2389,9 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
if (bld.indirect_files & (1 << TGSI_FILE_INPUT)) {
unsigned index, chan;
LLVMTypeRef vec_type = bld.base.vec_type;
LLVMValueRef array_size = LLVMConstInt(LLVMInt32Type(),
info->file_max[TGSI_FILE_INPUT]*4 + 4, 0);
bld.inputs_array = lp_build_array_alloca(bld.base.builder,
LLVMValueRef array_size =
lp_build_const_int32(gallivm, info->file_max[TGSI_FILE_INPUT]*4 + 4);
bld.inputs_array = lp_build_array_alloca(gallivm,
vec_type, array_size,
"input_array");
@ -2364,13 +2399,14 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
for (index = 0; index < info->num_inputs; ++index) {
for (chan = 0; chan < NUM_CHANNELS; ++chan) {
LLVMValueRef lindex = lp_build_const_int32(index * 4 + chan);
LLVMValueRef lindex =
lp_build_const_int32(gallivm, index * 4 + chan);
LLVMValueRef input_ptr =
LLVMBuildGEP(bld.base.builder, bld.inputs_array,
LLVMBuildGEP(gallivm->builder, bld.inputs_array,
&lindex, 1, "");
LLVMValueRef value = bld.inputs[index][chan];
if (value)
LLVMBuildStore(bld.base.builder, value, input_ptr);
LLVMBuildStore(gallivm->builder, value, input_ptr);
}
}
}
@ -2420,7 +2456,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
assert(num_immediates < LP_MAX_TGSI_IMMEDIATES);
for( i = 0; i < size; ++i )
bld.immediates[num_immediates][i] =
lp_build_const_vec(type, parse.FullToken.FullImmediate.u[i].Float);
lp_build_const_vec(gallivm, type, parse.FullToken.FullImmediate.u[i].Float);
for( i = size; i < 4; ++i )
bld.immediates[num_immediates][i] = bld.base.undef;
num_immediates++;
@ -2457,7 +2493,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
}
if (0) {
LLVMBasicBlockRef block = LLVMGetInsertBlock(builder);
LLVMBasicBlockRef block = LLVMGetInsertBlock(gallivm->builder);
LLVMValueRef function = LLVMGetBasicBlockParent(block);
debug_printf("11111111111111111111111111111 \n");
tgsi_dump(tokens, 0);
@ -2468,7 +2504,7 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
if (0) {
LLVMModuleRef module = LLVMGetGlobalParent(
LLVMGetBasicBlockParent(LLVMGetInsertBlock(bld.base.builder)));
LLVMGetBasicBlockParent(LLVMGetInsertBlock(gallivm->builder)));
LLVMDumpModule(module);
}

View file

@ -30,34 +30,35 @@
#include "lp_bld_type.h"
#include "lp_bld_const.h"
#include "lp_bld_init.h"
LLVMTypeRef
lp_build_elem_type(struct lp_type type)
lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type)
{
if (type.floating) {
switch(type.width) {
case 32:
return LLVMFloatType();
return LLVMFloatTypeInContext(gallivm->context);
break;
case 64:
return LLVMDoubleType();
return LLVMDoubleTypeInContext(gallivm->context);
break;
default:
assert(0);
return LLVMFloatType();
return LLVMFloatTypeInContext(gallivm->context);
}
}
else {
return LLVMIntType(type.width);
return LLVMIntTypeInContext(gallivm->context, type.width);
}
}
LLVMTypeRef
lp_build_vec_type(struct lp_type type)
lp_build_vec_type(struct gallivm_state *gallivm,struct lp_type type)
{
LLVMTypeRef elem_type = lp_build_elem_type(type);
LLVMTypeRef elem_type = lp_build_elem_type(gallivm, type);
if (type.length == 1)
return elem_type;
else
@ -149,16 +150,16 @@ lp_check_value(struct lp_type type, LLVMValueRef val)
LLVMTypeRef
lp_build_int_elem_type(struct lp_type type)
lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type)
{
return LLVMIntType(type.width);
return LLVMIntTypeInContext(gallivm->context, type.width);
}
LLVMTypeRef
lp_build_int_vec_type(struct lp_type type)
lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type)
{
LLVMTypeRef elem_type = lp_build_int_elem_type(type);
LLVMTypeRef elem_type = lp_build_int_elem_type(gallivm, type);
if (type.length == 1)
return elem_type;
else
@ -170,7 +171,7 @@ lp_build_int_vec_type(struct lp_type type)
* Build int32[4] vector type
*/
LLVMTypeRef
lp_build_int32_vec4_type(void)
lp_build_int32_vec4_type(struct gallivm_state *gallivm)
{
struct lp_type t;
LLVMTypeRef type;
@ -182,7 +183,7 @@ lp_build_int32_vec4_type(void)
t.width = 32; /* 32-bit int */
t.length = 4; /* 4 elements per vector */
type = lp_build_int_elem_type(t);
type = lp_build_int_elem_type(gallivm, t);
return LLVMVectorType(type, t.length);
}
@ -383,15 +384,15 @@ lp_dump_llvmtype(LLVMTypeRef t)
void
lp_build_context_init(struct lp_build_context *bld,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
struct lp_type type)
{
bld->builder = builder;
bld->gallivm = gallivm;
bld->type = type;
bld->int_elem_type = lp_build_int_elem_type(type);
bld->int_elem_type = lp_build_int_elem_type(gallivm, type);
if (type.floating)
bld->elem_type = lp_build_elem_type(type);
bld->elem_type = lp_build_elem_type(gallivm, type);
else
bld->elem_type = bld->int_elem_type;
@ -406,5 +407,5 @@ lp_build_context_init(struct lp_build_context *bld,
bld->undef = LLVMGetUndef(bld->vec_type);
bld->zero = LLVMConstNull(bld->vec_type);
bld->one = lp_build_one(type);
bld->one = lp_build_one(gallivm, type);
}

View file

@ -120,7 +120,7 @@ struct lp_type {
*/
struct lp_build_context
{
LLVMBuilderRef builder;
struct gallivm_state *gallivm;
/**
* This not only describes the input/output LLVM types, but also whether
@ -285,11 +285,11 @@ lp_type_ufixed(unsigned width)
LLVMTypeRef
lp_build_elem_type(struct lp_type type);
lp_build_elem_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
lp_build_vec_type(struct lp_type type);
lp_build_vec_type(struct gallivm_state *gallivm, struct lp_type type);
boolean
@ -305,15 +305,15 @@ lp_check_value(struct lp_type type, LLVMValueRef val);
LLVMTypeRef
lp_build_int_elem_type(struct lp_type type);
lp_build_int_elem_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
lp_build_int_vec_type(struct lp_type type);
lp_build_int_vec_type(struct gallivm_state *gallivm, struct lp_type type);
LLVMTypeRef
lp_build_int32_vec4_type(void);
lp_build_int32_vec4_type(struct gallivm_state *gallivm);
static INLINE struct lp_type
@ -394,7 +394,7 @@ lp_dump_llvmtype(LLVMTypeRef t);
void
lp_build_context_init(struct lp_build_context *bld,
LLVMBuilderRef builder,
struct gallivm_state *gallivm,
struct lp_type type);

View file

@ -1,68 +0,0 @@
/**************************************************************************
*
* Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
* 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 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 HOLDERS, AUTHORS AND/OR ITS SUPPLIERS 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.
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
*
**************************************************************************/
/*
* Authors:
* Keith Whitwell
*/
#include "target-helpers/wrap_screen.h"
#include "trace/tr_public.h"
#include "rbug/rbug_public.h"
#include "identity/id_public.h"
#include "util/u_debug.h"
/* Centralized code to inject common wrapping layers:
*/
struct pipe_screen *
gallium_wrap_screen( struct pipe_screen *screen )
{
/* Screen wrapping functions are required not to fail. If it is
* impossible to wrap a screen, the unwrapped screen should be
* returned instead. Any failure condition should be returned in
* an OUT argument.
*
* Otherwise it is really messy trying to clean up in this code.
*/
if (debug_get_bool_option("GALLIUM_WRAP", FALSE)) {
screen = identity_screen_create(screen);
}
/* Trace does its own checking if it should run */
screen = trace_screen_create(screen);
/* Rbug does its own checking if it should run */
screen = rbug_screen_create(screen);
return screen;
}

View file

@ -1,16 +0,0 @@
#ifndef WRAP_SCREEN_HELPER_H
#define WRAP_SCREEN_HELPER_H
#include "pipe/p_compiler.h"
struct pipe_screen;
/* Centralized code to inject common wrapping layers. Other layers
* can be introduced by specific targets, but these are the generally
* helpful ones we probably want everywhere.
*/
struct pipe_screen *
gallium_wrap_screen( struct pipe_screen *screen );
#endif

View file

@ -388,6 +388,8 @@ tgsi_exec_get_shader_param(enum pipe_shader_cap param)
case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
return 1;
case PIPE_SHADER_CAP_SUBROUTINES:
return 1;
default:
return 0;
}

View file

@ -136,7 +136,8 @@ tgsi_parse_token(
static INLINE unsigned
tgsi_num_tokens(const struct tgsi_token *tokens)
{
struct tgsi_header header = *(const struct tgsi_header *) tokens;
struct tgsi_header header;
memcpy(&header, tokens, sizeof(header));
return header.HeaderSize + header.BodySize;
}

View file

@ -1007,7 +1007,8 @@ static const char *semantic_names[TGSI_SEMANTIC_COUNT] =
"FACE",
"EDGEFLAG",
"PRIM_ID",
"INSTANCEID"
"INSTANCEID",
"STENCIL"
};
static const char *interpolate_names[TGSI_INTERPOLATE_COUNT] =

View file

@ -291,7 +291,7 @@ regions_overlap(int srcX0, int srcY0,
void
util_blit_pixels_writemask(struct blit_state *ctx,
struct pipe_resource *src_tex,
struct pipe_subresource srcsub,
unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ0,
@ -316,13 +316,12 @@ util_blit_pixels_writemask(struct blit_state *ctx,
assert(filter == PIPE_TEX_MIPFILTER_NEAREST ||
filter == PIPE_TEX_MIPFILTER_LINEAR);
assert(srcsub.level <= src_tex->last_level);
assert(src_level <= src_tex->last_level);
/* do the regions overlap? */
overlap = src_tex == dst->texture &&
dst->face == srcsub.face &&
dst->level == srcsub.level &&
dst->zslice == srcZ0 &&
dst->u.tex.level == src_level &&
dst->u.tex.first_layer == srcZ0 &&
regions_overlap(srcX0, srcY0, srcX1, srcY1,
dstX0, dstY0, dstX1, dstY1);
@ -339,16 +338,19 @@ util_blit_pixels_writemask(struct blit_state *ctx,
(dstX1 - dstX0) == (srcX1 - srcX0) &&
(dstY1 - dstY0) == (srcY1 - srcY0) &&
!overlap) {
struct pipe_subresource subdst;
subdst.face = dst->face;
subdst.level = dst->level;
struct pipe_box src_box;
src_box.x = srcX0;
src_box.y = srcY0;
src_box.z = srcZ0;
src_box.width = srcW;
src_box.height = srcH;
src_box.depth = 1;
pipe->resource_copy_region(pipe,
dst->texture, subdst,
dstX0, dstY0, dst->zslice,/* dest */
src_tex, srcsub,
srcX0, srcY0, srcZ0,/* src */
srcW, srcH); /* size */
return;
dst->texture, dst->u.tex.level,
dstX0, dstY0, dst->u.tex.first_layer,/* dest */
src_tex, src_level,
&src_box);
return;
}
/* Create a temporary texture when src and dest alias or when src
@ -359,16 +361,16 @@ util_blit_pixels_writemask(struct blit_state *ctx,
* This can still be improved upon.
*/
if ((src_tex == dst->texture &&
dst->face == srcsub.face &&
dst->level == srcsub.level &&
dst->zslice == srcZ0) ||
dst->u.tex.level == src_level &&
dst->u.tex.first_layer == srcZ0) ||
(src_tex->target != PIPE_TEXTURE_2D &&
src_tex->target != PIPE_TEXTURE_2D &&
src_tex->target != PIPE_TEXTURE_RECT))
{
struct pipe_resource texTemp;
struct pipe_resource *tex;
struct pipe_sampler_view sv_templ;
struct pipe_subresource texsub;
struct pipe_box src_box;
const int srcLeft = MIN2(srcX0, srcX1);
const int srcTop = MIN2(srcY0, srcY1);
@ -394,19 +396,23 @@ util_blit_pixels_writemask(struct blit_state *ctx,
texTemp.width0 = srcW;
texTemp.height0 = srcH;
texTemp.depth0 = 1;
texTemp.array_size = 1;
texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
tex = screen->resource_create(screen, &texTemp);
if (!tex)
return;
texsub.face = 0;
texsub.level = 0;
src_box.x = srcLeft;
src_box.y = srcTop;
src_box.z = srcZ0;
src_box.width = srcW;
src_box.height = srcH;
src_box.depth = 1;
/* load temp texture */
pipe->resource_copy_region(pipe,
tex, texsub, 0, 0, 0, /* dest */
src_tex, srcsub, srcLeft, srcTop, srcZ0, /* src */
srcW, srcH); /* size */
tex, 0, 0, 0, 0, /* dest */
src_tex, src_level, &src_box);
normalized = tex->target != PIPE_TEXTURE_RECT;
if(normalized) {
@ -433,7 +439,6 @@ util_blit_pixels_writemask(struct blit_state *ctx,
}
else {
u_sampler_view_default_template(&sv_templ, src_tex, src_tex->format);
sv_templ.first_level = sv_templ.last_level = srcsub.level;
sampler_view = pipe->create_sampler_view(pipe, src_tex, &sv_templ);
if (!sampler_view) {
@ -447,10 +452,10 @@ util_blit_pixels_writemask(struct blit_state *ctx,
normalized = sampler_view->texture->target != PIPE_TEXTURE_RECT;
if(normalized)
{
s0 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level));
s1 /= (float)(u_minify(sampler_view->texture->width0, srcsub.level));
t0 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level));
t1 /= (float)(u_minify(sampler_view->texture->height0, srcsub.level));
s0 /= (float)(u_minify(sampler_view->texture->width0, src_level));
s1 /= (float)(u_minify(sampler_view->texture->width0, src_level));
t0 /= (float)(u_minify(sampler_view->texture->height0, src_level));
t1 /= (float)(u_minify(sampler_view->texture->height0, src_level));
}
}
@ -489,9 +494,8 @@ util_blit_pixels_writemask(struct blit_state *ctx,
ctx->sampler.normalized_coords = normalized;
ctx->sampler.min_img_filter = filter;
ctx->sampler.mag_img_filter = filter;
/* we've limited this already with the sampler view but you never know... */
ctx->sampler.min_lod = srcsub.level;
ctx->sampler.max_lod = srcsub.level;
ctx->sampler.min_lod = src_level;
ctx->sampler.max_lod = src_level;
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
cso_single_sampler_done(ctx->cso);
@ -575,7 +579,7 @@ util_blit_pixels_writemask(struct blit_state *ctx,
void
util_blit_pixels(struct blit_state *ctx,
struct pipe_resource *src_tex,
struct pipe_subresource srcsub,
unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ,
@ -585,7 +589,7 @@ util_blit_pixels(struct blit_state *ctx,
float z, uint filter )
{
util_blit_pixels_writemask( ctx, src_tex,
srcsub,
src_level,
srcX0, srcY0,
srcX1, srcY1,
srcZ,
@ -662,6 +666,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_save_rasterizer(ctx->cso);
cso_save_samplers(ctx->cso);
cso_save_fragment_sampler_views(ctx->cso);
cso_save_viewport(ctx->cso);
cso_save_framebuffer(ctx->cso);
cso_save_fragment_shader(ctx->cso);
cso_save_vertex_shader(ctx->cso);
@ -729,6 +734,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_restore_rasterizer(ctx->cso);
cso_restore_samplers(ctx->cso);
cso_restore_fragment_sampler_views(ctx->cso);
cso_restore_viewport(ctx->cso);
cso_restore_framebuffer(ctx->cso);
cso_restore_fragment_shader(ctx->cso);
cso_restore_vertex_shader(ctx->cso);

View file

@ -42,7 +42,6 @@ struct cso_context;
struct pipe_context;
struct pipe_resource;
struct pipe_sampler_view;
struct pipe_subresource;
struct pipe_surface;
@ -55,7 +54,7 @@ util_destroy_blit(struct blit_state *ctx);
extern void
util_blit_pixels(struct blit_state *ctx,
struct pipe_resource *src_tex,
struct pipe_subresource srcsub,
unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ0,
@ -67,7 +66,7 @@ util_blit_pixels(struct blit_state *ctx,
void
util_blit_pixels_writemask(struct blit_state *ctx,
struct pipe_resource *src_tex,
struct pipe_subresource srcsub,
unsigned src_level,
int srcX0, int srcY0,
int srcX1, int srcY1,
int srcZ0,

View file

@ -63,8 +63,7 @@ struct blitter_context_priv
/* Constant state objects. */
/* Vertex shaders. */
void *vs_col; /**< Vertex shader which passes {pos, color} to the output */
void *vs_tex; /**< Vertex shader which passes {pos, texcoord} to the output.*/
void *vs; /**< Vertex shader which passes {pos, generic} to the output.*/
/* Fragment shaders. */
/* The shader at index i outputs color to color buffers 0,1,...,i-1. */
@ -211,20 +210,12 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
/* fragment shaders are created on-demand */
/* vertex shaders */
{
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_COLOR };
const uint semantic_indices[] = { 0, 0 };
ctx->vs_col =
util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
semantic_indices);
}
/* vertex shader */
{
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
TGSI_SEMANTIC_GENERIC };
const uint semantic_indices[] = { 0, 0 };
ctx->vs_tex =
ctx->vs =
util_make_vertex_passthrough_shader(pipe, 2, semantic_names,
semantic_indices);
}
@ -257,8 +248,7 @@ void util_blitter_destroy(struct blitter_context *blitter)
pipe->delete_depth_stencil_alpha_state(pipe, ctx->dsa_flush_depth_stencil);
pipe->delete_rasterizer_state(pipe, ctx->rs_state);
pipe->delete_vs_state(pipe, ctx->vs_col);
pipe->delete_vs_state(pipe, ctx->vs_tex);
pipe->delete_vs_state(pipe, ctx->vs);
pipe->delete_vertex_elements_state(pipe, ctx->velem_state);
for (i = 0; i < PIPE_MAX_TEXTURE_TYPES; i++) {
@ -419,17 +409,17 @@ static void blitter_set_clear_color(struct blitter_context_priv *ctx,
}
static void get_texcoords(struct pipe_resource *src,
struct pipe_subresource subsrc,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2,
boolean normalized, float out[4])
unsigned level,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2,
boolean normalized, float out[4])
{
if(normalized)
{
out[0] = x1 / (float)u_minify(src->width0, subsrc.level);
out[1] = y1 / (float)u_minify(src->height0, subsrc.level);
out[2] = x2 / (float)u_minify(src->width0, subsrc.level);
out[3] = y2 / (float)u_minify(src->height0, subsrc.level);
out[0] = x1 / (float)u_minify(src->width0, level);
out[1] = y1 / (float)u_minify(src->height0, level);
out[2] = x2 / (float)u_minify(src->width0, level);
out[3] = y2 / (float)u_minify(src->height0, level);
}
else
{
@ -458,14 +448,14 @@ static void set_texcoords_in_vertices(const float coord[4],
static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx,
struct pipe_resource *src,
struct pipe_subresource subsrc,
unsigned level,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2)
{
unsigned i;
float coord[4];
get_texcoords(src, subsrc, x1, y1, x2, y2, TRUE, coord);
get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord);
set_texcoords_in_vertices(coord, &ctx->vertices[0][1][0], 8);
for (i = 0; i < 4; i++) {
@ -476,15 +466,15 @@ static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx,
static void blitter_set_texcoords_3d(struct blitter_context_priv *ctx,
struct pipe_resource *src,
struct pipe_subresource subsrc,
unsigned level,
unsigned zslice,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2)
{
int i;
float r = zslice / (float)u_minify(src->depth0, subsrc.level);
float r = zslice / (float)u_minify(src->depth0, level);
blitter_set_texcoords_2d(ctx, src, subsrc, x1, y1, x2, y2);
blitter_set_texcoords_2d(ctx, src, level, x1, y1, x2, y2);
for (i = 0; i < 4; i++)
ctx->vertices[i][1][2] = r; /*r*/
@ -492,7 +482,7 @@ static void blitter_set_texcoords_3d(struct blitter_context_priv *ctx,
static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx,
struct pipe_resource *src,
struct pipe_subresource subsrc,
unsigned level, unsigned face,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2)
{
@ -500,10 +490,10 @@ static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx,
float coord[4];
float st[4][2];
get_texcoords(src, subsrc, x1, y1, x2, y2, TRUE, coord);
get_texcoords(src, level, x1, y1, x2, y2, TRUE, coord);
set_texcoords_in_vertices(coord, &st[0][0], 2);
util_map_texcoords2d_onto_cubemap(subsrc.face,
util_map_texcoords2d_onto_cubemap(face,
/* pointer, stride in floats */
&st[0][0], 2,
&ctx->vertices[0][1][0], 8);
@ -522,10 +512,13 @@ static void blitter_set_dst_dimensions(struct blitter_context_priv *ctx,
static void blitter_draw_quad(struct blitter_context_priv *ctx)
{
struct pipe_context *pipe = ctx->base.pipe;
struct pipe_box box;
/* write vertices and draw them */
pipe_buffer_write(pipe, ctx->vbuf,
0, sizeof(ctx->vertices), ctx->vertices);
u_box_1d(0, sizeof(ctx->vertices), &box);
pipe->transfer_inline_write(pipe, ctx->vbuf, 0,
PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD,
&box, ctx->vertices, sizeof(ctx->vertices), 0);
util_draw_vertex_buffer(pipe, ctx->vbuf, 0, PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
@ -566,7 +559,9 @@ void *blitter_get_fs_col(struct blitter_context_priv *ctx, unsigned num_cbufs)
if (!ctx->fs_col[num_cbufs])
ctx->fs_col[num_cbufs] =
util_make_fragment_clonecolor_shader(pipe, num_cbufs);
util_make_fragment_cloneinput_shader(pipe, num_cbufs,
TGSI_SEMANTIC_GENERIC,
TGSI_INTERPOLATE_LINEAR);
return ctx->fs_col[num_cbufs];
}
@ -697,7 +692,7 @@ void util_blitter_clear(struct blitter_context *blitter,
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, num_cbufs));
pipe->bind_vs_state(pipe, ctx->vs_col);
pipe->bind_vs_state(pipe, ctx->vs);
blitter_set_dst_dimensions(ctx, width, height);
blitter->draw_rectangle(blitter, 0, 0, width, height, depth,
@ -714,21 +709,22 @@ boolean is_overlap(unsigned sx1, unsigned sx2, unsigned sy1, unsigned sy2,
void util_blitter_copy_region(struct blitter_context *blitter,
struct pipe_resource *dst,
struct pipe_subresource subdst,
unsigned dstlevel,
unsigned dstx, unsigned dsty, unsigned dstz,
struct pipe_resource *src,
struct pipe_subresource subsrc,
unsigned srcx, unsigned srcy, unsigned srcz,
unsigned width, unsigned height,
unsigned srclevel,
const struct pipe_box *srcbox,
boolean ignore_stencil)
{
struct blitter_context_priv *ctx = (struct blitter_context_priv*)blitter;
struct pipe_context *pipe = ctx->base.pipe;
struct pipe_screen *screen = pipe->screen;
struct pipe_surface *dstsurf;
struct pipe_surface *dstsurf, surf_templ;
struct pipe_framebuffer_state fb_state;
struct pipe_sampler_view viewTempl, *view;
unsigned bind;
unsigned width = srcbox->width;
unsigned height = srcbox->height;
boolean is_stencil, is_depth;
boolean normalized;
@ -739,12 +735,15 @@ void util_blitter_copy_region(struct blitter_context *blitter,
/* Sanity checks. */
if (dst == src) {
assert(!is_overlap(srcx, srcx + width, srcy, srcy + height,
assert(!is_overlap(srcbox->x, srcbox->x + width, srcbox->y, srcbox->y + height,
dstx, dstx + width, dsty, dsty + height));
} else {
assert(dst->format == src->format);
assert(util_is_format_compatible(util_format_description(src->format),
util_format_description(dst->format)));
}
assert(src->target < PIPE_MAX_TEXTURE_TYPES);
/* XXX should handle 3d regions */
assert(srcbox->depth == 1);
/* Is this a ZS format? */
is_depth = util_format_get_component_bits(src->format, UTIL_FORMAT_COLORSPACE_ZS, 0) != 0;
@ -762,15 +761,18 @@ void util_blitter_copy_region(struct blitter_context *blitter,
dst->nr_samples, bind, 0) ||
!screen->is_format_supported(screen, src->format, src->target,
src->nr_samples, PIPE_BIND_SAMPLER_VIEW, 0)) {
util_resource_copy_region(pipe, dst, subdst, dstx, dsty, dstz,
src, subsrc, srcx, srcy, srcz, width, height);
util_resource_copy_region(pipe, dst, dstlevel, dstx, dsty, dstz,
src, srclevel, srcbox);
return;
}
/* Get surfaces. */
dstsurf = screen->get_tex_surface(screen, dst,
subdst.face, subdst.level, dstz,
bind);
/* Get surface. */
memset(&surf_templ, 0, sizeof(surf_templ));
u_surface_default_template(&surf_templ, dst, bind);
surf_templ.u.tex.level = dstlevel;
surf_templ.u.tex.first_layer = dstz;
surf_templ.u.tex.last_layer = dstz;
dstsurf = pipe->create_surface(pipe, dst, &surf_templ);
/* Check whether the states are properly saved. */
blitter_check_saved_CSOs(ctx);
@ -810,9 +812,9 @@ void util_blitter_copy_region(struct blitter_context *blitter,
/* Set rasterizer state, shaders, and textures. */
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_vs_state(pipe, ctx->vs_tex);
pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_fragment_sampler_states(pipe, 1,
blitter_get_sampler_state(ctx, subsrc.level, normalized));
blitter_get_sampler_state(ctx, srclevel, normalized));
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
pipe->set_fragment_sampler_views(pipe, 1, &view);
pipe->set_framebuffer_state(pipe, &fb_state);
@ -827,8 +829,8 @@ void util_blitter_copy_region(struct blitter_context *blitter,
{
/* Set texture coordinates. */
float coord[4];
get_texcoords(src, subsrc, srcx, srcy,
srcx+width, srcy+height, normalized, coord);
get_texcoords(src, srclevel, srcbox->x, srcbox->y,
srcbox->x+width, srcbox->y+height, normalized, coord);
/* Draw. */
blitter->draw_rectangle(blitter, dstx, dsty, dstx+width, dsty+height, 0,
@ -841,11 +843,13 @@ void util_blitter_copy_region(struct blitter_context *blitter,
case PIPE_TEXTURE_CUBE:
/* Set texture coordinates. */
if (src->target == PIPE_TEXTURE_3D)
blitter_set_texcoords_3d(ctx, src, subsrc, srcz,
srcx, srcy, srcx+width, srcy+height);
blitter_set_texcoords_3d(ctx, src, srclevel, srcbox->z,
srcbox->x, srcbox->y,
srcbox->x + width, srcbox->y + height);
else
blitter_set_texcoords_cube(ctx, src, subsrc,
srcx, srcy, srcx+width, srcy+height);
blitter_set_texcoords_cube(ctx, src, srclevel, srcbox->z,
srcbox->x, srcbox->y,
srcbox->x + width, srcbox->y + height);
/* Draw. */
blitter_set_rectangle(ctx, dstx, dsty, dstx+width, dsty+height, 0);
@ -887,7 +891,7 @@ void util_blitter_clear_render_target(struct blitter_context *blitter,
pipe->bind_depth_stencil_alpha_state(pipe, ctx->dsa_keep_depth_stencil);
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 1));
pipe->bind_vs_state(pipe, ctx->vs_col);
pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
@ -947,7 +951,7 @@ void util_blitter_clear_depth_stencil(struct blitter_context *blitter,
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0));
pipe->bind_vs_state(pipe, ctx->vs_col);
pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */
@ -988,7 +992,7 @@ void util_blitter_custom_depth_stencil(struct blitter_context *blitter,
pipe->bind_rasterizer_state(pipe, ctx->rs_state);
pipe->bind_fs_state(pipe, blitter_get_fs_col(ctx, 0));
pipe->bind_vs_state(pipe, ctx->vs_col);
pipe->bind_vs_state(pipe, ctx->vs);
pipe->bind_vertex_elements_state(pipe, ctx->velem_state);
/* set a framebuffer state */

View file

@ -164,12 +164,11 @@ void util_blitter_clear(struct blitter_context *blitter,
*/
void util_blitter_copy_region(struct blitter_context *blitter,
struct pipe_resource *dst,
struct pipe_subresource subdst,
unsigned dstlevel,
unsigned dstx, unsigned dsty, unsigned dstz,
struct pipe_resource *src,
struct pipe_subresource subsrc,
unsigned srcx, unsigned srcy, unsigned srcz,
unsigned width, unsigned height,
unsigned srclevel,
const struct pipe_box *srcbox,
boolean ignore_stencil);
/**

View file

@ -60,7 +60,6 @@ void u_box_2d_zslice( unsigned x,
box->depth = 1;
}
static INLINE
void u_box_3d( unsigned x,
unsigned y,
@ -78,15 +77,4 @@ void u_box_3d( unsigned x,
box->depth = d;
}
static INLINE
struct pipe_subresource u_subresource( unsigned face,
unsigned level )
{
struct pipe_subresource subresource;
subresource.face = face;
subresource.level = level;
return subresource;
}
#endif

View file

@ -40,7 +40,8 @@
#include "util/u_string.h"
#include "util/u_math.h"
#include "util/u_tile.h"
#include "util/u_prim.h"
#include "util/u_prim.h"
#include "util/u_surface.h"
#include <limits.h> /* CHAR_BIT */
@ -453,9 +454,10 @@ void debug_dump_image(const char *prefix,
#endif
}
/* FIXME: dump resources, not surfaces... */
void debug_dump_surface(struct pipe_context *pipe,
const char *prefix,
struct pipe_surface *surface)
const char *prefix,
struct pipe_surface *surface)
{
struct pipe_resource *texture;
struct pipe_transfer *transfer;
@ -472,23 +474,23 @@ void debug_dump_surface(struct pipe_context *pipe,
*/
texture = surface->texture;
transfer = pipe_get_transfer(pipe, texture, surface->face,
surface->level, surface->zslice,
PIPE_TRANSFER_READ, 0, 0, surface->width,
surface->height);
transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level,
surface->u.tex.first_layer,
PIPE_TRANSFER_READ,
0, 0, surface->width, surface->height);
data = pipe->transfer_map(pipe, transfer);
if(!data)
goto error;
debug_dump_image(prefix,
debug_dump_image(prefix,
texture->format,
util_format_get_blocksize(texture->format),
util_format_get_blocksize(texture->format),
util_format_get_nblocksx(texture->format, surface->width),
util_format_get_nblocksy(texture->format, surface->height),
transfer->stride,
data);
pipe->transfer_unmap(pipe, transfer);
error:
pipe->transfer_destroy(pipe, transfer);
@ -499,20 +501,18 @@ void debug_dump_texture(struct pipe_context *pipe,
const char *prefix,
struct pipe_resource *texture)
{
struct pipe_surface *surface;
struct pipe_screen *screen;
struct pipe_surface *surface, surf_tmpl;
if (!texture)
return;
screen = texture->screen;
/* XXX for now, just dump image for face=0, level=0 */
surface = screen->get_tex_surface(screen, texture, 0, 0, 0,
PIPE_BIND_SAMPLER_VIEW);
/* XXX for now, just dump image for layer=0, level=0 */
memset(&surf_tmpl, 0, sizeof(surf_tmpl));
u_surface_default_template(&surf_tmpl, texture, 0 /* no bind flag - not a surface */);
surface = pipe->create_surface(pipe, texture, &surf_tmpl);
if (surface) {
debug_dump_surface(pipe, prefix, surface);
screen->tex_surface_destroy(surface);
pipe->surface_destroy(pipe, surface);
}
}
@ -550,17 +550,16 @@ struct bmp_rgb_quad {
void
debug_dump_surface_bmp(struct pipe_context *pipe,
const char *filename,
const char *filename,
struct pipe_surface *surface)
{
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
struct pipe_transfer *transfer;
struct pipe_resource *texture = surface->texture;
transfer = pipe_get_transfer(pipe, texture, surface->face,
surface->level, surface->zslice,
PIPE_TRANSFER_READ, 0, 0, surface->width,
surface->height);
transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level,
surface->u.tex.first_layer, PIPE_TRANSFER_READ,
0, 0, surface->width, surface->height);
debug_dump_transfer_bmp(pipe, filename, transfer);

View file

@ -69,7 +69,7 @@ debug_describe_surface(char* buf, const struct pipe_surface *ptr)
{
char res[128];
debug_describe_resource(res, ptr->texture);
util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->face, ptr->level, ptr->zslice);
util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->u.tex.level, ptr->u.tex.first_layer, ptr->u.tex.last_layer);
}
void

View file

@ -48,7 +48,10 @@ debug_backtrace_capture(struct debug_stack_frame *backtrace,
if(!nr_frames)
return;
#if defined(PIPE_CC_GCC)
#if defined(PIPE_CC_GCC) && defined(PIPE_ARCH_X86)
__asm__ __volatile__("mov (%%ebp),%0": "=r" (frame_pointer));
frame_pointer = (const void **)frame_pointer[0];
#elif defined(PIPE_CC_GCC)
frame_pointer = ((const void **)__builtin_frame_address(1));
#elif defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
__asm {

View file

@ -40,7 +40,7 @@
#include "u_debug_symbol.h"
#include "u_hash_table.h"
#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86)
#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
#include <windows.h>
#include <stddef.h>
@ -165,7 +165,7 @@ debug_symbol_name_glibc(const void *addr, char* buf, unsigned size)
void
debug_symbol_name(const void *addr, char* buf, unsigned size)
{
#if defined(PIPE_SUBSYSTEM_WINDOWS_USER) && defined(PIPE_ARCH_X86)
#if defined(PIPE_CC_MSVC) && defined(PIPE_ARCH_X86)
debug_symbol_name_imagehlp(addr, buf, size);
if(buf[0])
return;

View file

@ -24,5 +24,9 @@
#define U_NEW_VERTEX_BUFFER 0x10000
#define U_NEW_QUERY 0x20000
#define U_NEW_DEPTH_STENCIL 0x40000
#define U_NEW_GS 0x80000
#define U_NEW_GS_CONSTANTS 0x100000
#define U_NEW_GS_SAMPLER_VIEW 0x200000
#define U_NEW_GS_SAMPLER_STATES 0x400000
#endif

View file

@ -77,7 +77,7 @@ util_dirty_surfaces_use_levels_for_sampling(struct pipe_context *pipe, struct ut
struct util_dirty_surface *ds = LIST_ENTRY(struct util_dirty_surface, p, dirty_list);
next = p->next;
if(ds->base.level >= first && ds->base.level <= last)
if(ds->base.u.tex.level >= first && ds->base.u.tex.level <= last)
flush(pipe, &ds->base);
}
}
@ -86,7 +86,8 @@ static INLINE void
util_dirty_surfaces_use_for_sampling_with(struct pipe_context *pipe, struct util_dirty_surfaces *dss, struct pipe_sampler_view *psv, struct pipe_sampler_state *pss, util_dirty_surface_flush_t flush)
{
if(!LIST_IS_EMPTY(&dss->dirty_list))
util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->first_level, MIN2((unsigned)ceilf(pss->max_lod) + psv->first_level, psv->last_level), flush);
util_dirty_surfaces_use_levels_for_sampling(pipe, dss, (unsigned)pss->min_lod + psv->u.tex.first_level,
MIN2((unsigned)ceilf(pss->max_lod) + psv->u.tex.first_level, psv->u.tex.last_level), flush);
}
static INLINE void

View file

@ -279,6 +279,10 @@ util_dump_template(struct os_stream *stream, const struct pipe_resource *templat
util_dump_uint(stream, templat->depth0);
util_dump_member_end(stream);
util_dump_member_begin(stream, "array_size");
util_dump_uint(stream, templat->array_size);
util_dump_member_end(stream);
util_dump_member(stream, uint, templat, last_level);
util_dump_member(stream, uint, templat, usage);
util_dump_member(stream, uint, templat, bind);
@ -633,14 +637,12 @@ util_dump_surface(struct os_stream *stream, const struct pipe_surface *state)
util_dump_member(stream, uint, state, width);
util_dump_member(stream, uint, state, height);
util_dump_member(stream, uint, state, layout);
util_dump_member(stream, uint, state, offset);
util_dump_member(stream, uint, state, usage);
util_dump_member(stream, ptr, state, texture);
util_dump_member(stream, uint, state, face);
util_dump_member(stream, uint, state, level);
util_dump_member(stream, uint, state, zslice);
util_dump_member(stream, uint, state, u.tex.level);
util_dump_member(stream, uint, state, u.tex.first_layer);
util_dump_member(stream, uint, state, u.tex.last_layer);
util_dump_struct_end(stream);
}
@ -660,7 +662,7 @@ util_dump_transfer(struct os_stream *stream, const struct pipe_transfer *state)
/*util_dump_member(stream, uint, state, box);*/
util_dump_member(stream, uint, state, stride);
util_dump_member(stream, uint, state, slice_stride);
util_dump_member(stream, uint, state, layer_stride);
/*util_dump_member(stream, ptr, state, data);*/

View file

@ -48,6 +48,8 @@
#include "util/u_simple_shaders.h"
#include "util/u_math.h"
#include "util/u_texture.h"
#include "util/u_half.h"
#include "util/u_surface.h"
#include "cso_cache/cso_context.h"
@ -65,7 +67,7 @@ struct gen_mipmap_state
struct pipe_vertex_element velem[2];
void *vs;
void *fs2d, *fsCube;
void *fs1d, *fs2d, *fs3d, *fsCube;
struct pipe_resource *vbuf; /**< quad vertices */
unsigned vbuf_slot;
@ -89,24 +91,7 @@ enum dtype
};
typedef ushort half_float;
static half_float
float_to_half(float f)
{
/* XXX fix this */
return 0;
}
static float
half_to_float(half_float h)
{
/* XXX fix this */
return 0.0f;
}
typedef uint16_t half_float;
/**
@ -145,7 +130,7 @@ half_to_float(half_float h)
rowC[j][e], rowC[k][e], \
rowD[j][e], rowD[k][e]); \
} while(0)
#define FILTER_F_3D(e) \
do { \
dst[i][e] = (rowA[j][e] + rowA[k][e] \
@ -156,15 +141,15 @@ half_to_float(half_float h)
#define FILTER_HF_3D(e) \
do { \
const float aj = half_to_float(rowA[j][e]); \
const float ak = half_to_float(rowA[k][e]); \
const float bj = half_to_float(rowB[j][e]); \
const float bk = half_to_float(rowB[k][e]); \
const float cj = half_to_float(rowC[j][e]); \
const float ck = half_to_float(rowC[k][e]); \
const float dj = half_to_float(rowD[j][e]); \
const float dk = half_to_float(rowD[k][e]); \
dst[i][e] = float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
const float aj = util_half_to_float(rowA[j][e]); \
const float ak = util_half_to_float(rowA[k][e]); \
const float bj = util_half_to_float(rowB[j][e]); \
const float bk = util_half_to_float(rowB[k][e]); \
const float cj = util_half_to_float(rowC[j][e]); \
const float ck = util_half_to_float(rowC[k][e]); \
const float dj = util_half_to_float(rowD[j][e]); \
const float dk = util_half_to_float(rowD[k][e]); \
dst[i][e] = util_float_to_half((aj + ak + bj + bk + cj + ck + dj + dk) \
* 0.125F); \
} while(0)
/*@}*/
@ -343,8 +328,7 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
}
}
#if 0
else if (datatype == HALF_DTYPE_FLOAT && comps == 4) {
else if (datatype == DTYPE_HALF_FLOAT && comps == 4) {
uint i, j, k, comp;
const half_float(*rowA)[4] = (const half_float(*)[4]) srcRowA;
const half_float(*rowB)[4] = (const half_float(*)[4]) srcRowB;
@ -353,11 +337,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
i++, j += colStride, k += colStride) {
for (comp = 0; comp < 4; comp++) {
float aj, ak, bj, bk;
aj = half_to_float(rowA[j][comp]);
ak = half_to_float(rowA[k][comp]);
bj = half_to_float(rowB[j][comp]);
bk = half_to_float(rowB[k][comp]);
dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F);
aj = util_half_to_float(rowA[j][comp]);
ak = util_half_to_float(rowA[k][comp]);
bj = util_half_to_float(rowB[j][comp]);
bk = util_half_to_float(rowB[k][comp]);
dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
}
@ -370,11 +354,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
i++, j += colStride, k += colStride) {
for (comp = 0; comp < 3; comp++) {
float aj, ak, bj, bk;
aj = half_to_float(rowA[j][comp]);
ak = half_to_float(rowA[k][comp]);
bj = half_to_float(rowB[j][comp]);
bk = half_to_float(rowB[k][comp]);
dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F);
aj = util_half_to_float(rowA[j][comp]);
ak = util_half_to_float(rowA[k][comp]);
bj = util_half_to_float(rowB[j][comp]);
bk = util_half_to_float(rowB[k][comp]);
dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
}
@ -387,11 +371,11 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
i++, j += colStride, k += colStride) {
for (comp = 0; comp < 2; comp++) {
float aj, ak, bj, bk;
aj = half_to_float(rowA[j][comp]);
ak = half_to_float(rowA[k][comp]);
bj = half_to_float(rowB[j][comp]);
bk = half_to_float(rowB[k][comp]);
dst[i][comp] = float_to_half((aj + ak + bj + bk) * 0.25F);
aj = util_half_to_float(rowA[j][comp]);
ak = util_half_to_float(rowA[k][comp]);
bj = util_half_to_float(rowB[j][comp]);
bk = util_half_to_float(rowB[k][comp]);
dst[i][comp] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
}
@ -403,14 +387,13 @@ do_row(enum dtype datatype, uint comps, int srcWidth,
for (i = j = 0, k = k0; i < (uint) dstWidth;
i++, j += colStride, k += colStride) {
float aj, ak, bj, bk;
aj = half_to_float(rowA[j]);
ak = half_to_float(rowA[k]);
bj = half_to_float(rowB[j]);
bk = half_to_float(rowB[k]);
dst[i] = float_to_half((aj + ak + bj + bk) * 0.25F);
aj = util_half_to_float(rowA[j]);
ak = util_half_to_float(rowA[k]);
bj = util_half_to_float(rowB[j]);
bk = util_half_to_float(rowB[k]);
dst[i] = util_float_to_half((aj + ak + bj + bk) * 0.25F);
}
}
#endif
else if (datatype == DTYPE_UINT && comps == 1) {
uint i, j, k;
@ -1036,32 +1019,34 @@ reduce_2d(enum pipe_format pformat,
static void
reduce_3d(enum pipe_format pformat,
int srcWidth, int srcHeight, int srcDepth,
int srcRowStride, const ubyte *srcPtr,
int srcRowStride, int srcImageStride, const ubyte *srcPtr,
int dstWidth, int dstHeight, int dstDepth,
int dstRowStride, ubyte *dstPtr)
int dstRowStride, int dstImageStride, ubyte *dstPtr)
{
const int bpt = util_format_get_blocksize(pformat);
const int border = 0;
int img, row;
int bytesPerSrcImage, bytesPerDstImage;
int bytesPerSrcRow, bytesPerDstRow;
int srcImageOffset, srcRowOffset;
enum dtype datatype;
uint comps;
format_to_type_comps(pformat, &datatype, &comps);
bytesPerSrcImage = srcWidth * srcHeight * bpt;
bytesPerDstImage = dstWidth * dstHeight * bpt;
/* XXX I think we should rather assert those strides */
if (!srcImageStride)
srcImageStride = srcWidth * srcHeight * bpt;
if (!dstImageStride)
dstImageStride = dstWidth * dstHeight * bpt;
bytesPerSrcRow = srcWidth * bpt;
bytesPerDstRow = dstWidth * bpt;
if (!srcRowStride)
srcRowStride = srcWidth * bpt;
if (!dstRowStride)
dstRowStride = dstWidth * bpt;
/* Offset between adjacent src images to be averaged together */
srcImageOffset = (srcDepth == dstDepth) ? 0 : bytesPerSrcImage;
srcImageOffset = (srcDepth == dstDepth) ? 0 : srcImageStride;
/* Offset between adjacent src rows to be averaged together */
srcRowOffset = (srcHeight == dstHeight) ? 0 : srcWidth * bpt;
srcRowOffset = (srcHeight == dstHeight) ? 0 : srcRowStride;
/*
* Need to average together up to 8 src pixels for each dest pixel.
@ -1077,16 +1062,13 @@ reduce_3d(enum pipe_format pformat,
*/
for (img = 0; img < dstDepth; img++) {
/* first source image pointer, skipping border */
/* first source image pointer */
const ubyte *imgSrcA = srcPtr
+ (bytesPerSrcImage + bytesPerSrcRow + border) * bpt * border
+ img * (bytesPerSrcImage + srcImageOffset);
/* second source image pointer, skipping border */
+ img * (srcImageStride + srcImageOffset);
/* second source image pointer */
const ubyte *imgSrcB = imgSrcA + srcImageOffset;
/* address of the dest image, skipping border */
ubyte *imgDst = dstPtr
+ (bytesPerDstImage + bytesPerDstRow + border) * bpt * border
+ img * bytesPerDstImage;
/* address of the dest image */
ubyte *imgDst = dstPtr + img * dstImageStride;
/* setup the four source row pointers and the dest row pointer */
const ubyte *srcImgARowA = imgSrcA;
@ -1102,11 +1084,11 @@ reduce_3d(enum pipe_format pformat,
dstWidth, dstImgRow);
/* advance to next rows */
srcImgARowA += bytesPerSrcRow + srcRowOffset;
srcImgARowB += bytesPerSrcRow + srcRowOffset;
srcImgBRowA += bytesPerSrcRow + srcRowOffset;
srcImgBRowB += bytesPerSrcRow + srcRowOffset;
dstImgRow += bytesPerDstRow;
srcImgARowA += srcRowStride + srcRowOffset;
srcImgARowB += srcRowStride + srcRowOffset;
srcImgBRowA += srcRowStride + srcRowOffset;
srcImgBRowB += srcRowStride + srcRowOffset;
dstImgRow += dstImageStride;
}
}
}
@ -1117,25 +1099,24 @@ reduce_3d(enum pipe_format pformat,
static void
make_1d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
uint layer, uint baseLevel, uint lastLevel)
{
struct pipe_context *pipe = ctx->pipe;
const uint zslice = 0;
uint dstLevel;
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
struct pipe_transfer *srcTrans, *dstTrans;
void *srcMap, *dstMap;
srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
PIPE_TRANSFER_READ, 0, 0,
u_minify(pt->width0, srcLevel),
u_minify(pt->height0, srcLevel));
dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
PIPE_TRANSFER_WRITE, 0, 0,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer,
PIPE_TRANSFER_READ, 0, 0,
u_minify(pt->width0, srcLevel),
u_minify(pt->height0, srcLevel));
dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer,
PIPE_TRANSFER_WRITE, 0, 0,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
@ -1156,12 +1137,11 @@ make_1d_mipmap(struct gen_mipmap_state *ctx,
static void
make_2d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
uint layer, uint baseLevel, uint lastLevel)
{
struct pipe_context *pipe = ctx->pipe;
const uint zslice = 0;
uint dstLevel;
assert(util_format_get_blockwidth(pt->format) == 1);
assert(util_format_get_blockheight(pt->format) == 1);
@ -1169,15 +1149,15 @@ make_2d_mipmap(struct gen_mipmap_state *ctx,
const uint srcLevel = dstLevel - 1;
struct pipe_transfer *srcTrans, *dstTrans;
ubyte *srcMap, *dstMap;
srcTrans = pipe_get_transfer(pipe, pt, face, srcLevel, zslice,
PIPE_TRANSFER_READ, 0, 0,
u_minify(pt->width0, srcLevel),
u_minify(pt->height0, srcLevel));
dstTrans = pipe_get_transfer(pipe, pt, face, dstLevel, zslice,
PIPE_TRANSFER_WRITE, 0, 0,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
srcTrans = pipe_get_transfer(pipe, pt, srcLevel, layer,
PIPE_TRANSFER_READ, 0, 0,
u_minify(pt->width0, srcLevel),
u_minify(pt->height0, srcLevel));
dstTrans = pipe_get_transfer(pipe, pt, dstLevel, layer,
PIPE_TRANSFER_WRITE, 0, 0,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
@ -1197,41 +1177,49 @@ make_2d_mipmap(struct gen_mipmap_state *ctx,
}
/* XXX looks a bit more like it could work now but need to test */
static void
make_3d_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
{
#if 0
struct pipe_context *pipe = ctx->pipe;
struct pipe_screen *screen = pipe->screen;
uint dstLevel, zslice = 0;
uint dstLevel;
struct pipe_box src_box, dst_box;
assert(util_format_get_blockwidth(pt->format) == 1);
assert(util_format_get_blockheight(pt->format) == 1);
src_box.x = src_box.y = src_box.z = 0;
dst_box.x = dst_box.y = dst_box.z = 0;
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
struct pipe_transfer *srcTrans, *dstTrans;
ubyte *srcMap, *dstMap;
srcTrans = pipe->get_transfer(pipe, pt, face, srcLevel, zslice,
PIPE_TRANSFER_READ, 0, 0,
u_minify(pt->width0, srcLevel),
u_minify(pt->height0, srcLevel));
dstTrans = pipe->get_transfer(pipe, pt, face, dstLevel, zslice,
PIPE_TRANSFER_WRITE, 0, 0,
u_minify(pt->width0, dstLevel),
u_minify(pt->height0, dstLevel));
struct pipe_box src_box, dst_box;
src_box.width = u_minify(pt->width0, srcLevel);
src_box.height = u_minify(pt->height0, srcLevel);
src_box.depth = u_minify(pt->depth0, srcLevel);
dst_box.width = u_minify(pt->width0, dstLevel);
dst_box.height = u_minify(pt->height0, dstLevel);
dst_box.depth = u_minify(pt->depth0, dstLevel);
srcTrans = pipe->get_transfer(pipe, pt, srcLevel,
PIPE_TRANSFER_READ,
&src_box);
dstTrans = pipe->get_transfer(pipe, pt, dstLevel,
PIPE_TRANSFER_WRITE,
&dst_box);
srcMap = (ubyte *) pipe->transfer_map(pipe, srcTrans);
dstMap = (ubyte *) pipe->transfer_map(pipe, dstTrans);
reduce_3d(pt->format,
srcTrans->width, srcTrans->height,
srcTrans->stride, srcMap,
dstTrans->width, dstTrans->height,
dstTrans->stride, dstMap);
srcTrans->box.width, srcTrans->box.height, srcTrans->box.depth,
srcTrans->stride, srcTrans->layer_stride, srcMap,
dstTrans->box.width, dstTrans->box.height, dstTrans->box.depth,
dstTrans->stride, dstTrans->layer_stride, dstMap);
pipe->transfer_unmap(pipe, srcTrans);
pipe->transfer_unmap(pipe, dstTrans);
@ -1239,28 +1227,25 @@ make_3d_mipmap(struct gen_mipmap_state *ctx,
pipe->transfer_destroy(pipe, srcTrans);
pipe->transfer_destroy(pipe, dstTrans);
}
#else
(void) reduce_3d;
#endif
}
static void
fallback_gen_mipmap(struct gen_mipmap_state *ctx,
struct pipe_resource *pt,
uint face, uint baseLevel, uint lastLevel)
uint layer, uint baseLevel, uint lastLevel)
{
switch (pt->target) {
case PIPE_TEXTURE_1D:
make_1d_mipmap(ctx, pt, face, baseLevel, lastLevel);
make_1d_mipmap(ctx, pt, layer, baseLevel, lastLevel);
break;
case PIPE_TEXTURE_2D:
case PIPE_TEXTURE_RECT:
case PIPE_TEXTURE_CUBE:
make_2d_mipmap(ctx, pt, face, baseLevel, lastLevel);
make_2d_mipmap(ctx, pt, layer, baseLevel, lastLevel);
break;
case PIPE_TEXTURE_3D:
make_3d_mipmap(ctx, pt, face, baseLevel, lastLevel);
make_3d_mipmap(ctx, pt, layer, baseLevel, lastLevel);
break;
default:
assert(0);
@ -1328,8 +1313,12 @@ util_create_gen_mipmap(struct pipe_context *pipe,
}
/* fragment shader */
ctx->fs1d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_1D,
TGSI_INTERPOLATE_LINEAR);
ctx->fs2d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_2D,
TGSI_INTERPOLATE_LINEAR);
ctx->fs3d = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_3D,
TGSI_INTERPOLATE_LINEAR);
ctx->fsCube = util_make_fragment_tex_shader(pipe, TGSI_TEXTURE_CUBE,
TGSI_INTERPOLATE_LINEAR);
@ -1371,7 +1360,7 @@ get_next_slot(struct gen_mipmap_state *ctx)
static unsigned
set_vertex_data(struct gen_mipmap_state *ctx,
enum pipe_texture_target tex_target,
uint face)
uint layer, float r)
{
unsigned offset;
@ -1397,26 +1386,26 @@ set_vertex_data(struct gen_mipmap_state *ctx,
{0.0f, 0.0f}, {1.0f, 0.0f}, {1.0f, 1.0f}, {0.0f, 1.0f}
};
util_map_texcoords2d_onto_cubemap(face, &st[0][0], 2,
util_map_texcoords2d_onto_cubemap(layer, &st[0][0], 2,
&ctx->vertices[0][1][0], 8);
}
else {
/* 1D/2D */
/* 1D/2D/3D */
ctx->vertices[0][1][0] = 0.0f; /*s*/
ctx->vertices[0][1][1] = 0.0f; /*t*/
ctx->vertices[0][1][2] = 0.0f; /*r*/
ctx->vertices[0][1][2] = r; /*r*/
ctx->vertices[1][1][0] = 1.0f;
ctx->vertices[1][1][1] = 0.0f;
ctx->vertices[1][1][2] = 0.0f;
ctx->vertices[1][1][2] = r;
ctx->vertices[2][1][0] = 1.0f;
ctx->vertices[2][1][1] = 1.0f;
ctx->vertices[2][1][2] = 0.0f;
ctx->vertices[2][1][2] = r;
ctx->vertices[3][1][0] = 0.0f;
ctx->vertices[3][1][1] = 1.0f;
ctx->vertices[3][1][2] = 0.0f;
ctx->vertices[3][1][2] = r;
}
offset = get_next_slot( ctx );
@ -1437,9 +1426,11 @@ util_destroy_gen_mipmap(struct gen_mipmap_state *ctx)
{
struct pipe_context *pipe = ctx->pipe;
pipe->delete_vs_state(pipe, ctx->vs);
pipe->delete_fs_state(pipe, ctx->fs2d);
pipe->delete_fs_state(pipe, ctx->fsCube);
pipe->delete_fs_state(pipe, ctx->fs3d);
pipe->delete_fs_state(pipe, ctx->fs2d);
pipe->delete_fs_state(pipe, ctx->fs1d);
pipe->delete_vs_state(pipe, ctx->vs);
pipe_resource_reference(&ctx->vbuf, NULL);
@ -1478,9 +1469,8 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
struct pipe_screen *screen = pipe->screen;
struct pipe_framebuffer_state fb;
struct pipe_resource *pt = psv->texture;
void *fs = (pt->target == PIPE_TEXTURE_CUBE) ? ctx->fsCube : ctx->fs2d;
void *fs;
uint dstLevel;
uint zslice = 0;
uint offset;
/* The texture object should have room for the levels which we're
@ -1494,8 +1484,28 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
assert(filter == PIPE_TEX_FILTER_LINEAR ||
filter == PIPE_TEX_FILTER_NEAREST);
switch (pt->target) {
case PIPE_TEXTURE_1D:
fs = ctx->fs1d;
break;
case PIPE_TEXTURE_2D:
fs = ctx->fs2d;
break;
case PIPE_TEXTURE_3D:
fs = ctx->fs3d;
break;
case PIPE_TEXTURE_CUBE:
fs = ctx->fsCube;
break;
case PIPE_TEXTURE_1D_ARRAY:
case PIPE_TEXTURE_2D_ARRAY:
default:
assert(0);
fs = ctx->fs2d;
}
/* check if we can render in the texture's format */
if (!screen->is_format_supported(screen, psv->format, PIPE_TEXTURE_2D,
if (!screen->is_format_supported(screen, psv->format, pt->target,
pt->nr_samples, PIPE_BIND_RENDER_TARGET, 0)) {
fallback_gen_mipmap(ctx, pt, face, baseLevel, lastLevel);
return;
@ -1539,60 +1549,85 @@ util_gen_mipmap(struct gen_mipmap_state *ctx,
for (dstLevel = baseLevel + 1; dstLevel <= lastLevel; dstLevel++) {
const uint srcLevel = dstLevel - 1;
struct pipe_viewport_state vp;
unsigned nr_layers, layer, i;
float rcoord = 0.0f;
struct pipe_surface *surf =
screen->get_tex_surface(screen, pt, face, dstLevel, zslice,
PIPE_BIND_RENDER_TARGET);
if (pt->target == PIPE_TEXTURE_3D)
nr_layers = u_minify(pt->depth0, dstLevel);
else
nr_layers = 1;
/*
* Setup framebuffer / dest surface
*/
fb.cbufs[0] = surf;
fb.width = u_minify(pt->width0, dstLevel);
fb.height = u_minify(pt->height0, dstLevel);
cso_set_framebuffer(ctx->cso, &fb);
for (i = 0; i < nr_layers; i++) {
struct pipe_surface *surf, surf_templ;
if (pt->target == PIPE_TEXTURE_3D) {
/* in theory with geom shaders and driver with full layer support
could do that in one go. */
layer = i;
offset = 1.0f / (float)(nr_layers * 2);
/* XXX hmm really? */
rcoord = (float)layer / (float)nr_layers + 1.0f / (float)(nr_layers * 2);
}
else
layer = face;
/* viewport */
vp.scale[0] = 0.5f * fb.width;
vp.scale[1] = 0.5f * fb.height;
vp.scale[2] = 1.0f;
vp.scale[3] = 1.0f;
vp.translate[0] = 0.5f * fb.width;
vp.translate[1] = 0.5f * fb.height;
vp.translate[2] = 0.0f;
vp.translate[3] = 0.0f;
cso_set_viewport(ctx->cso, &vp);
memset(&surf_templ, 0, sizeof(surf_templ));
u_surface_default_template(&surf_templ, pt, PIPE_BIND_RENDER_TARGET);
surf_templ.u.tex.level = dstLevel;
surf_templ.u.tex.first_layer = layer;
surf_templ.u.tex.last_layer = layer;
surf = pipe->create_surface(pipe, pt, &surf_templ);
/*
* Setup sampler state
* Note: we should only have to set the min/max LOD clamps to ensure
* we grab texels from the right mipmap level. But some hardware
* has trouble with min clamping so we also set the lod_bias to
* try to work around that.
*/
ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel;
ctx->sampler.lod_bias = (float) srcLevel;
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
cso_single_sampler_done(ctx->cso);
/*
* Setup framebuffer / dest surface
*/
fb.cbufs[0] = surf;
fb.width = u_minify(pt->width0, dstLevel);
fb.height = u_minify(pt->height0, dstLevel);
cso_set_framebuffer(ctx->cso, &fb);
cso_set_fragment_sampler_views(ctx->cso, 1, &psv);
/* viewport */
vp.scale[0] = 0.5f * fb.width;
vp.scale[1] = 0.5f * fb.height;
vp.scale[2] = 1.0f;
vp.scale[3] = 1.0f;
vp.translate[0] = 0.5f * fb.width;
vp.translate[1] = 0.5f * fb.height;
vp.translate[2] = 0.0f;
vp.translate[3] = 0.0f;
cso_set_viewport(ctx->cso, &vp);
/* quad coords in clip coords */
offset = set_vertex_data(ctx,
pt->target,
face);
/*
* Setup sampler state
* Note: we should only have to set the min/max LOD clamps to ensure
* we grab texels from the right mipmap level. But some hardware
* has trouble with min clamping so we also set the lod_bias to
* try to work around that.
*/
ctx->sampler.min_lod = ctx->sampler.max_lod = (float) srcLevel;
ctx->sampler.lod_bias = (float) srcLevel;
cso_single_sampler(ctx->cso, 0, &ctx->sampler);
cso_single_sampler_done(ctx->cso);
util_draw_vertex_buffer(ctx->pipe,
ctx->vbuf,
offset,
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
2); /* attribs/vert */
cso_set_fragment_sampler_views(ctx->cso, 1, &psv);
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
/* quad coords in clip coords */
offset = set_vertex_data(ctx,
pt->target,
face,
rcoord);
/* need to signal that the texture has changed _after_ rendering to it */
pipe_surface_reference( &surf, NULL );
util_draw_vertex_buffer(ctx->pipe,
ctx->vbuf,
offset,
PIPE_PRIM_TRIANGLE_FAN,
4, /* verts */
2); /* attribs/vert */
pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
/* need to signal that the texture has changed _after_ rendering to it */
pipe_surface_reference( &surf, NULL );
}
}
/* restore state we changed */

Some files were not shown because too many files have changed in this diff Show more