#include "util/u_cpu_detect.h"
#include "util/u_format_s3tc.h"
#include "util/u_string.h"
+#include "util/u_screen.h"
#include "state_tracker/sw_winsys.h"
-extern "C" {
-#include "gallivm/lp_bld_limits.h"
-}
-
#include "jit_api.h"
#include "memory/TilingFunctions.h"
#include <stdio.h>
#include <map>
-/* MSVC case instensitive compare */
-#if defined(PIPE_CC_MSVC)
- #define strcasecmp lstrcmpiA
-#endif
-
/*
* Max texture sizes
* XXX Check max texture size values against core and sampler.
*/
-#define SWR_MAX_TEXTURE_SIZE (4 * 1024 * 1024 * 1024ULL) /* 4GB */
-#define SWR_MAX_TEXTURE_2D_LEVELS 14 /* 8K x 8K for now */
+#define SWR_MAX_TEXTURE_SIZE (2 * 1024 * 1024 * 1024ULL) /* 2GB */
+#define SWR_MAX_TEXTURE_2D_SIZE 8192
#define SWR_MAX_TEXTURE_3D_LEVELS 12 /* 2K x 2K x 2K for now */
#define SWR_MAX_TEXTURE_CUBE_LEVELS 14 /* 8K x 8K for now */
#define SWR_MAX_TEXTURE_ARRAY_LAYERS 512 /* 8K x 512 / 8K x 8K x 512 */
+/* Default max client_copy_limit */
+#define SWR_CLIENT_COPY_LIMIT 8192
+
+/* Flag indicates creation of alternate surface, to prevent recursive loop
+ * in resource creation when msaa_force_enable is set. */
+#define SWR_RESOURCE_FLAG_ALT_SURFACE (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
+
+
static const char *
swr_get_name(struct pipe_screen *screen)
{
static char buf[100];
- util_snprintf(buf, sizeof(buf), "SWR (LLVM %u.%u, %u bits)",
- HAVE_LLVM >> 8, HAVE_LLVM & 0xff,
- lp_native_vector_width );
+ snprintf(buf, sizeof(buf), "SWR (LLVM " MESA_LLVM_VERSION_STRING ", %u bits)",
+ lp_native_vector_width);
return buf;
}
return "Intel Corporation";
}
-static boolean
-swr_is_format_supported(struct pipe_screen *screen,
+static bool
+swr_is_format_supported(struct pipe_screen *_screen,
enum pipe_format format,
enum pipe_texture_target target,
unsigned sample_count,
+ unsigned storage_sample_count,
unsigned bind)
{
- struct sw_winsys *winsys = swr_screen(screen)->winsys;
+ struct swr_screen *screen = swr_screen(_screen);
+ struct sw_winsys *winsys = screen->winsys;
const struct util_format_description *format_desc;
assert(target == PIPE_BUFFER || target == PIPE_TEXTURE_1D
|| target == PIPE_TEXTURE_CUBE
|| target == PIPE_TEXTURE_CUBE_ARRAY);
+ if (MAX2(1, sample_count) != MAX2(1, storage_sample_count))
+ return false;
+
format_desc = util_format_description(format);
if (!format_desc)
- return FALSE;
+ return false;
- if (sample_count > 1)
- return FALSE;
+ if ((sample_count > screen->msaa_max_count)
+ || !util_is_power_of_two_or_zero(sample_count))
+ return false;
- if (bind
- & (PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | PIPE_BIND_SHARED)) {
+ if (bind & PIPE_BIND_DISPLAY_TARGET) {
if (!winsys->is_displaytarget_format_supported(winsys, bind, format))
- return FALSE;
+ return false;
}
if (bind & PIPE_BIND_RENDER_TARGET) {
if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
- return FALSE;
+ return false;
if (mesa_to_swr_format(format) == (SWR_FORMAT)-1)
- return FALSE;
+ return false;
/*
* Although possible, it is unnatural to render into compressed or YUV
* inside the state trackers.
*/
if (format_desc->block.width != 1 || format_desc->block.height != 1)
- return FALSE;
+ return false;
}
if (bind & PIPE_BIND_DEPTH_STENCIL) {
if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
- return FALSE;
+ return false;
if (mesa_to_swr_format(format) == (SWR_FORMAT)-1)
- return FALSE;
+ return false;
}
if (format_desc->layout == UTIL_FORMAT_LAYOUT_BPTC ||
format_desc->layout == UTIL_FORMAT_LAYOUT_ASTC) {
- return FALSE;
+ return false;
}
if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
format != PIPE_FORMAT_ETC1_RGB8) {
- return FALSE;
+ return false;
}
- if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
- return util_format_s3tc_enabled;
+ if ((bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW)) &&
+ ((bind & PIPE_BIND_DISPLAY_TARGET) == 0)) {
+ /* Disable all 3-channel formats, where channel size != 32 bits.
+ * In some cases we run into crashes (in generate_unswizzled_blend()),
+ * for 3-channel RGB16 variants, there was an apparent LLVM bug.
+ * In any case, disabling the shallower 3-channel formats avoids a
+ * number of issues with GL_ARB_copy_image support.
+ */
+ if (format_desc->is_array &&
+ format_desc->nr_channels == 3 &&
+ format_desc->block.bits != 96) {
+ return false;
+ }
}
return TRUE;
/* limits */
case PIPE_CAP_MAX_RENDER_TARGETS:
return PIPE_MAX_COLOR_BUFS;
- case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
- return SWR_MAX_TEXTURE_2D_LEVELS;
+ case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
+ return SWR_MAX_TEXTURE_2D_SIZE;
case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
return SWR_MAX_TEXTURE_3D_LEVELS;
case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
return 2048;
case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS:
return SWR_MAX_TEXTURE_ARRAY_LAYERS;
+ case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
case PIPE_CAP_MIN_TEXEL_OFFSET:
return -8;
+ case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
case PIPE_CAP_MAX_TEXEL_OFFSET:
return 7;
+ case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
+ return 4;
case PIPE_CAP_GLSL_FEATURE_LEVEL:
return 330;
+ case PIPE_CAP_GLSL_FEATURE_LEVEL_COMPATIBILITY:
+ return 140;
case PIPE_CAP_CONSTANT_BUFFER_OFFSET_ALIGNMENT:
return 16;
case PIPE_CAP_MIN_MAP_BUFFER_ALIGNMENT:
case PIPE_CAP_MAX_TEXTURE_BUFFER_SIZE:
return 65536;
case PIPE_CAP_TEXTURE_BUFFER_OFFSET_ALIGNMENT:
- return 0;
- case PIPE_CAP_MAX_VIEWPORTS:
return 1;
+ case PIPE_CAP_MAX_VIEWPORTS:
+ return KNOB_NUM_VIEWPORTS_SCISSORS;
case PIPE_CAP_ENDIANNESS:
return PIPE_ENDIAN_NATIVE;
- case PIPE_CAP_MIN_TEXTURE_GATHER_OFFSET:
- case PIPE_CAP_MAX_TEXTURE_GATHER_OFFSET:
+ case PIPE_CAP_DEPTH_CLIP_DISABLE_SEPARATE:
return 0;
/* supported features */
case PIPE_CAP_NPOT_TEXTURES:
case PIPE_CAP_MIXED_FRAMEBUFFER_SIZES:
case PIPE_CAP_MIXED_COLOR_DEPTH_BITS:
- case PIPE_CAP_TWO_SIDED_STENCIL:
- case PIPE_CAP_SM3:
+ case PIPE_CAP_FRAGMENT_SHADER_TEXTURE_LOD:
+ case PIPE_CAP_FRAGMENT_SHADER_DERIVATIVES:
+ case PIPE_CAP_VERTEX_SHADER_SATURATE:
case PIPE_CAP_POINT_SPRITE:
case PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS:
case PIPE_CAP_OCCLUSION_QUERY:
case PIPE_CAP_QUERY_TIME_ELAPSED:
case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
- case PIPE_CAP_TEXTURE_SHADOW_MAP:
+ case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
case PIPE_CAP_TEXTURE_SWIZZLE:
case PIPE_CAP_BLEND_EQUATION_SEPARATE:
case PIPE_CAP_INDEP_BLEND_ENABLE:
case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
case PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION:
case PIPE_CAP_USER_VERTEX_BUFFERS:
- case PIPE_CAP_USER_INDEX_BUFFERS:
- case PIPE_CAP_USER_CONSTANT_BUFFERS:
case PIPE_CAP_STREAM_OUTPUT_INTERLEAVE_BUFFERS:
case PIPE_CAP_QUERY_TIMESTAMP:
case PIPE_CAP_TEXTURE_BUFFER_OBJECTS:
case PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT:
- case PIPE_CAP_FAKE_SW_MSAA:
case PIPE_CAP_DRAW_INDIRECT:
case PIPE_CAP_UMA:
case PIPE_CAP_CONDITIONAL_RENDER_INVERTED:
case PIPE_CAP_CLIP_HALFZ:
case PIPE_CAP_POLYGON_OFFSET_CLAMP:
case PIPE_CAP_DEPTH_BOUNDS_TEST:
+ case PIPE_CAP_CLEAR_TEXTURE:
case PIPE_CAP_TEXTURE_FLOAT_LINEAR:
case PIPE_CAP_TEXTURE_HALF_FLOAT_LINEAR:
case PIPE_CAP_CULL_DISTANCE:
case PIPE_CAP_CUBE_MAP_ARRAY:
+ case PIPE_CAP_DOUBLES:
+ case PIPE_CAP_TEXTURE_QUERY_LOD:
+ case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
+ return 1;
+
+ /* MSAA support
+ * If user has explicitly set max_sample_count = 1 (via SWR_MSAA_MAX_COUNT)
+ * then disable all MSAA support and go back to old (FAKE_SW_MSAA) caps. */
+ case PIPE_CAP_TEXTURE_MULTISAMPLE:
+ case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
+ return (swr_screen(screen)->msaa_max_count > 1) ? 1 : 0;
+ case PIPE_CAP_FAKE_SW_MSAA:
+ return (swr_screen(screen)->msaa_max_count > 1) ? 0 : 1;
+
+ /* fetch jit change for 2-4GB buffers requires alignment */
+ case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
+ case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
+ case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
return 1;
/* unsupported features */
case PIPE_CAP_COMPUTE:
case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS:
- case PIPE_CAP_VERTEX_BUFFER_OFFSET_4BYTE_ALIGNED_ONLY:
- case PIPE_CAP_VERTEX_BUFFER_STRIDE_4BYTE_ALIGNED_ONLY:
- case PIPE_CAP_VERTEX_ELEMENT_SRC_OFFSET_4BYTE_ALIGNED_ONLY:
- case PIPE_CAP_TEXTURE_MULTISAMPLE:
case PIPE_CAP_TGSI_TEXCOORD:
case PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER:
- case PIPE_CAP_MAX_TEXTURE_GATHER_COMPONENTS:
case PIPE_CAP_TEXTURE_GATHER_SM5:
- case PIPE_CAP_TEXTURE_QUERY_LOD:
case PIPE_CAP_SAMPLE_SHADING:
case PIPE_CAP_TEXTURE_GATHER_OFFSETS:
case PIPE_CAP_TGSI_VS_WINDOW_SPACE_POSITION:
case PIPE_CAP_TGSI_FS_FINE_DERIVATIVE:
case PIPE_CAP_SAMPLER_VIEW_TARGET:
case PIPE_CAP_VERTEXID_NOBASE:
- case PIPE_CAP_MULTISAMPLE_Z_RESOLVE:
case PIPE_CAP_RESOURCE_FROM_USER_MEMORY:
case PIPE_CAP_DEVICE_RESET_STATUS_QUERY:
case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
case PIPE_CAP_TGSI_TXQS:
case PIPE_CAP_FORCE_PERSAMPLE_INTERP:
case PIPE_CAP_SHAREABLE_SHADERS:
- case PIPE_CAP_COPY_BETWEEN_COMPRESSED_AND_PLAIN_FORMATS:
- case PIPE_CAP_CLEAR_TEXTURE:
case PIPE_CAP_DRAW_PARAMETERS:
case PIPE_CAP_TGSI_PACK_HALF_FLOAT:
case PIPE_CAP_MULTI_DRAW_INDIRECT:
case PIPE_CAP_TGSI_ARRAY_COMPONENTS:
case PIPE_CAP_TGSI_CAN_READ_OUTPUTS:
case PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME:
+ case PIPE_CAP_NATIVE_FENCE_FD:
+ case PIPE_CAP_GLSL_OPTIMIZE_CONSERVATIVELY:
+ case PIPE_CAP_FBFETCH:
+ case PIPE_CAP_TGSI_MUL_ZERO_WINS:
+ case PIPE_CAP_INT64:
+ case PIPE_CAP_INT64_DIVMOD:
+ case PIPE_CAP_TGSI_TEX_TXF_LZ:
+ case PIPE_CAP_TGSI_CLOCK:
+ case PIPE_CAP_POLYGON_MODE_FILL_RECTANGLE:
+ case PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE:
+ case PIPE_CAP_TGSI_BALLOT:
+ case PIPE_CAP_TGSI_TES_LAYER_VIEWPORT:
+ case PIPE_CAP_CAN_BIND_CONST_BUFFER_AS_VERTEX:
+ case PIPE_CAP_ALLOW_MAPPED_BUFFERS_DURING_EXECUTION:
+ case PIPE_CAP_POST_DEPTH_COVERAGE:
+ case PIPE_CAP_BINDLESS_TEXTURE:
+ case PIPE_CAP_NIR_SAMPLERS_AS_DEREF:
+ case PIPE_CAP_QUERY_SO_OVERFLOW:
+ case PIPE_CAP_MEMOBJ:
+ case PIPE_CAP_LOAD_CONSTBUF:
+ case PIPE_CAP_TGSI_ANY_REG_AS_ADDRESS:
+ case PIPE_CAP_TILE_RASTER_ORDER:
+ case PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
+ case PIPE_CAP_FRAMEBUFFER_MSAA_CONSTRAINTS:
+ case PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET:
+ case PIPE_CAP_CONTEXT_PRIORITY_MASK:
+ case PIPE_CAP_FENCE_SIGNAL:
+ case PIPE_CAP_CONSTBUF0_FLAGS:
+ case PIPE_CAP_PACKED_UNIFORMS:
+ case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_TRIANGLES:
+ case PIPE_CAP_CONSERVATIVE_RASTER_POST_SNAP_POINTS_LINES:
+ case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_TRIANGLES:
+ case PIPE_CAP_CONSERVATIVE_RASTER_PRE_SNAP_POINTS_LINES:
+ case PIPE_CAP_CONSERVATIVE_RASTER_POST_DEPTH_COVERAGE:
+ case PIPE_CAP_MAX_CONSERVATIVE_RASTER_SUBPIXEL_PRECISION_BIAS:
+ case PIPE_CAP_PROGRAMMABLE_SAMPLE_LOCATIONS:
+ case PIPE_CAP_MAX_TEXTURE_UPLOAD_MEMORY_BUDGET:
+ case PIPE_CAP_IMAGE_LOAD_FORMATTED:
+ case PIPE_CAP_TGSI_ATOMINC_WRAP:
return 0;
+ case PIPE_CAP_MAX_GS_INVOCATIONS:
+ return 32;
+ case PIPE_CAP_MAX_SHADER_BUFFER_SIZE:
+ return 1 << 27;
+ case PIPE_CAP_MAX_VARYINGS:
+ return 32;
case PIPE_CAP_VENDOR_ID:
return 0xFFFFFFFF;
return (int)(system_memory >> 20);
}
+ default:
+ return u_pipe_screen_get_param_defaults(screen, param);
}
-
- /* should only get here on unhandled cases */
- debug_printf("Unexpected PIPE_CAP %d query\n", param);
- return 0;
}
static int
swr_get_shader_param(struct pipe_screen *screen,
- unsigned shader,
+ enum pipe_shader_type shader,
enum pipe_shader_cap param)
{
- if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_FRAGMENT)
+ if (shader == PIPE_SHADER_VERTEX ||
+ shader == PIPE_SHADER_FRAGMENT ||
+ shader == PIPE_SHADER_GEOMETRY)
return gallivm_get_shader_param(param);
- // Todo: geometry, tesselation, compute
+ // Todo: tesselation, compute
return 0;
}
return 0.0;
case PIPE_CAPF_MAX_TEXTURE_LOD_BIAS:
return 16.0; /* arbitrary */
- case PIPE_CAPF_GUARD_BAND_LEFT:
- case PIPE_CAPF_GUARD_BAND_TOP:
- case PIPE_CAPF_GUARD_BAND_RIGHT:
- case PIPE_CAPF_GUARD_BAND_BOTTOM:
- return 0.0;
+ case PIPE_CAPF_MIN_CONSERVATIVE_RASTER_DILATE:
+ case PIPE_CAPF_MAX_CONSERVATIVE_RASTER_DILATE:
+ case PIPE_CAPF_CONSERVATIVE_RASTER_DILATE_GRANULARITY:
+ return 0.0f;
}
/* should only get here on unhandled cases */
debug_printf("Unexpected PIPE_CAPF %d query\n", param);
{PIPE_FORMAT_R8G8B8_SINT, R8G8B8_SINT},
{PIPE_FORMAT_R8G8B8A8_SINT, R8G8B8A8_SINT},
+ /* These formats are valid for vertex data, but should not be used
+ * for render targets.
+ */
+
+ {PIPE_FORMAT_R32_FIXED, R32_SFIXED},
+ {PIPE_FORMAT_R32G32_FIXED, R32G32_SFIXED},
+ {PIPE_FORMAT_R32G32B32_FIXED, R32G32B32_SFIXED},
+ {PIPE_FORMAT_R32G32B32A32_FIXED, R32G32B32A32_SFIXED},
+
+ {PIPE_FORMAT_R64_FLOAT, R64_FLOAT},
+ {PIPE_FORMAT_R64G64_FLOAT, R64G64_FLOAT},
+ {PIPE_FORMAT_R64G64B64_FLOAT, R64G64B64_FLOAT},
+ {PIPE_FORMAT_R64G64B64A64_FLOAT, R64G64B64A64_FLOAT},
+
/* These formats have entries in SWR but don't have Load/StoreTile
* implementations. That means these aren't renderable, and thus having
* a mapping entry here is detrimental.
return it->second;
}
-static boolean
+static bool
swr_displaytarget_layout(struct swr_screen *screen, struct swr_resource *res)
{
struct sw_winsys *winsys = screen->winsys;
&stride);
if (dt == NULL)
- return FALSE;
+ return false;
void *map = winsys->displaytarget_map(winsys, dt, 0);
res->display_target = dt;
- res->swr.pBaseAddress = (uint8_t*) map;
+ res->swr.xpBaseAddress = (gfxptr_t)map;
/* Clear the display target surface */
if (map)
winsys->displaytarget_unmap(winsys, dt);
- return TRUE;
+ return true;
}
static bool
swr_texture_layout(struct swr_screen *screen,
struct swr_resource *res,
- boolean allocate)
+ bool allocate)
{
struct pipe_resource *pt = &res->base;
if (pt->bind & (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL)) {
res->swr.halign = KNOB_MACROTILE_X_DIM;
res->swr.valign = KNOB_MACROTILE_Y_DIM;
+
+ /* If SWR_MSAA_FORCE_ENABLE is set, turn on MSAA and override requested
+ * surface sample count. */
+ if (screen->msaa_force_enable) {
+ res->swr.numSamples = screen->msaa_max_count;
+ fprintf(stderr,"swr_texture_layout: forcing sample count: %d\n",
+ res->swr.numSamples);
+ }
} else {
res->swr.halign = 1;
res->swr.valign = 1;
ComputeSurfaceOffset<false>(0, 0, 0, 0, 0, level, &res->swr);
}
- size_t total_size =
- (size_t)res->swr.depth * res->swr.qpitch * res->swr.pitch;
- if (total_size > SWR_MAX_TEXTURE_SIZE)
+ size_t total_size = (uint64_t)res->swr.depth * res->swr.qpitch *
+ res->swr.pitch * res->swr.numSamples;
+
+ // Let non-sampled textures (e.g. buffer objects) bypass the size limit
+ if (swr_resource_is_texture(&res->base) && total_size > SWR_MAX_TEXTURE_SIZE)
return false;
if (allocate) {
- res->swr.pBaseAddress = (uint8_t *)AlignedMalloc(total_size, 64);
+ res->swr.xpBaseAddress = (gfxptr_t)AlignedMalloc(total_size, 64);
+ if (!res->swr.xpBaseAddress)
+ return false;
if (res->has_depth && res->has_stencil) {
res->secondary = res->swr;
ComputeSurfaceOffset<false>(0, 0, 0, 0, 0, level, &res->secondary);
}
- res->secondary.pBaseAddress = (uint8_t *)AlignedMalloc(
- res->secondary.depth * res->secondary.qpitch *
- res->secondary.pitch, 64);
+ total_size = res->secondary.depth * res->secondary.qpitch *
+ res->secondary.pitch * res->secondary.numSamples;
+
+ res->secondary.xpBaseAddress = (gfxptr_t) AlignedMalloc(total_size, 64);
+ if (!res->secondary.xpBaseAddress) {
+ AlignedFree((void *)res->swr.xpBaseAddress);
+ return false;
+ }
}
}
return true;
}
-static boolean
+static bool
swr_can_create_resource(struct pipe_screen *screen,
const struct pipe_resource *templat)
{
return swr_texture_layout(swr_screen(screen), &res, false);
}
+/* Helper function that conditionally creates a single-sample resolve resource
+ * and attaches it to main multisample resource. */
+static bool
+swr_create_resolve_resource(struct pipe_screen *_screen,
+ struct swr_resource *msaa_res)
+{
+ struct swr_screen *screen = swr_screen(_screen);
+
+ /* If resource is multisample, create a single-sample resolve resource */
+ if (msaa_res->base.nr_samples > 1 || (screen->msaa_force_enable &&
+ !(msaa_res->base.flags & SWR_RESOURCE_FLAG_ALT_SURFACE))) {
+
+ /* Create a single-sample copy of the resource. Copy the original
+ * resource parameters and set flag to prevent recursion when re-calling
+ * resource_create */
+ struct pipe_resource alt_template = msaa_res->base;
+ alt_template.nr_samples = 0;
+ alt_template.flags |= SWR_RESOURCE_FLAG_ALT_SURFACE;
+
+ /* Note: Display_target is a special single-sample resource, only the
+ * display_target has been created already. */
+ if (msaa_res->base.bind & (PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT
+ | PIPE_BIND_SHARED)) {
+ /* Allocate the multisample buffers. */
+ if (!swr_texture_layout(screen, msaa_res, true))
+ return false;
+
+ /* Alt resource will only be bound as PIPE_BIND_RENDER_TARGET
+ * remove the DISPLAY_TARGET, SCANOUT, and SHARED bindings */
+ alt_template.bind = PIPE_BIND_RENDER_TARGET;
+ }
+
+ /* Allocate single-sample resolve surface */
+ struct pipe_resource *alt;
+ alt = _screen->resource_create(_screen, &alt_template);
+ if (!alt)
+ return false;
+
+ /* Attach it to the multisample resource */
+ msaa_res->resolve_target = alt;
+
+ /* Hang resolve surface state off the multisample surface state to so
+ * StoreTiles knows where to resolve the surface. */
+ msaa_res->swr.xpAuxBaseAddress = (gfxptr_t)&swr_resource(alt)->swr;
+ }
+
+ return true; /* success */
+}
+
static struct pipe_resource *
swr_resource_create(struct pipe_screen *_screen,
const struct pipe_resource *templat)
| PIPE_BIND_SHARED)) {
/* displayable surface
* first call swr_texture_layout without allocating to finish
- * filling out the SWR_SURFAE_STATE in res */
+ * filling out the SWR_SURFACE_STATE in res */
swr_texture_layout(screen, res, false);
if (!swr_displaytarget_layout(screen, res))
goto fail;
if (!swr_texture_layout(screen, res, true))
goto fail;
}
+
+ /* If resource was multisample, create resolve resource and attach
+ * it to multisample resource. */
+ if (!swr_create_resolve_resource(_screen, res))
+ goto fail;
+
} else {
/* other data (vertex buffer, const buffer, etc) */
assert(util_format_get_blocksize(templat->format) == 1);
assert(templat->last_level == 0);
/* Easiest to just call swr_texture_layout, as it sets up
- * SWR_SURFAE_STATE in res */
+ * SWR_SURFACE_STATE in res */
if (!swr_texture_layout(screen, res, true))
goto fail;
}
{
struct swr_screen *screen = swr_screen(p_screen);
struct swr_resource *spr = swr_resource(pt);
- struct pipe_context *pipe = screen->pipe;
-
- /* Only wait on fence if the resource is being used */
- if (pipe && spr->status) {
- /* But, if there's no fence pending, submit one.
- * XXX: Remove once draw timestamps are implmented. */
- if (!swr_is_fence_pending(screen->flush_fence))
- swr_fence_submit(swr_context(pipe), screen->flush_fence);
+ if (spr->display_target) {
+ /* If resource is display target, winsys manages the buffer and will
+ * free it on displaytarget_destroy. */
swr_fence_finish(p_screen, NULL, screen->flush_fence, 0);
- swr_resource_unused(pt);
- }
- /*
- * Free resource primary surface. If resource is display target, winsys
- * manages the buffer and will free it on displaytarget_destroy.
- */
- if (spr->display_target) {
- /* display target */
struct sw_winsys *winsys = screen->winsys;
winsys->displaytarget_destroy(winsys, spr->display_target);
- } else
- AlignedFree(spr->swr.pBaseAddress);
- AlignedFree(spr->secondary.pBaseAddress);
+ if (spr->swr.numSamples > 1) {
+ /* Free an attached resolve resource */
+ struct swr_resource *alt = swr_resource(spr->resolve_target);
+ swr_fence_work_free(screen->flush_fence, (void*)(alt->swr.xpBaseAddress), true);
+
+ /* Free multisample buffer */
+ swr_fence_work_free(screen->flush_fence, (void*)(spr->swr.xpBaseAddress), true);
+ }
+ } else {
+ /* For regular resources, defer deletion */
+ swr_resource_unused(pt);
+
+ if (spr->swr.numSamples > 1) {
+ /* Free an attached resolve resource */
+ struct swr_resource *alt = swr_resource(spr->resolve_target);
+ swr_fence_work_free(screen->flush_fence, (void*)(alt->swr.xpBaseAddress), true);
+ }
+
+ swr_fence_work_free(screen->flush_fence, (void*)(spr->swr.xpBaseAddress), true);
+ swr_fence_work_free(screen->flush_fence,
+ (void*)(spr->secondary.xpBaseAddress), true);
+
+ /* If work queue grows too large, submit a fence to force queue to
+ * drain. This is mainly to decrease the amount of memory used by the
+ * piglit streaming-texture-leak test */
+ if (screen->pipe && swr_fence(screen->flush_fence)->work.count > 64)
+ swr_fence_submit(swr_context(screen->pipe), screen->flush_fence);
+ }
FREE(spr);
}
struct sw_winsys *winsys = screen->winsys;
struct swr_resource *spr = swr_resource(resource);
struct pipe_context *pipe = screen->pipe;
+ struct swr_context *ctx = swr_context(pipe);
if (pipe) {
swr_fence_finish(p_screen, NULL, screen->flush_fence, 0);
swr_resource_unused(resource);
- SwrEndFrame(swr_context(pipe)->swrContext);
+ ctx->api.pfnSwrEndFrame(ctx->swrContext);
+ }
+
+ /* Multisample resolved into resolve_target at flush with store_resource */
+ if (pipe && spr->swr.numSamples > 1) {
+ struct pipe_resource *resolve_target = spr->resolve_target;
+
+ /* Once resolved, copy into display target */
+ SWR_SURFACE_STATE *resolve = &swr_resource(resolve_target)->swr;
+
+ void *map = winsys->displaytarget_map(winsys, spr->display_target,
+ PIPE_TRANSFER_WRITE);
+ memcpy(map, (void*)(resolve->xpBaseAddress), resolve->pitch * resolve->height);
+ winsys->displaytarget_unmap(winsys, spr->display_target);
}
debug_assert(spr->display_target);
}
+void
+swr_destroy_screen_internal(struct swr_screen **screen)
+{
+ struct pipe_screen *p_screen = &(*screen)->base;
+
+ swr_fence_finish(p_screen, NULL, (*screen)->flush_fence, 0);
+ swr_fence_reference(p_screen, &(*screen)->flush_fence, NULL);
+
+ JitDestroyContext((*screen)->hJitMgr);
+
+ if ((*screen)->pLibrary)
+ util_dl_close((*screen)->pLibrary);
+
+ FREE(*screen);
+ *screen = NULL;
+}
+
+
static void
swr_destroy_screen(struct pipe_screen *p_screen)
{
fprintf(stderr, "SWR destroy screen!\n");
- swr_fence_finish(p_screen, NULL, screen->flush_fence, 0);
- swr_fence_reference(p_screen, &screen->flush_fence, NULL);
-
- JitDestroyContext(screen->hJitMgr);
-
if (winsys->destroy)
winsys->destroy(winsys);
- FREE(screen);
+ swr_destroy_screen_internal(&screen);
}
-PUBLIC
+
+static void
+swr_validate_env_options(struct swr_screen *screen)
+{
+ /* The client_copy_limit sets a maximum on the amount of user-buffer memory
+ * copied to scratch space on a draw. Past this, the draw will access
+ * user-buffer directly and then block. This is faster than queuing many
+ * large client draws. */
+ screen->client_copy_limit = SWR_CLIENT_COPY_LIMIT;
+ int client_copy_limit =
+ debug_get_num_option("SWR_CLIENT_COPY_LIMIT", SWR_CLIENT_COPY_LIMIT);
+ if (client_copy_limit > 0)
+ screen->client_copy_limit = client_copy_limit;
+
+ /* XXX msaa under development, disable by default for now */
+ screen->msaa_max_count = 1; /* was SWR_MAX_NUM_MULTISAMPLES; */
+
+ /* validate env override values, within range and power of 2 */
+ int msaa_max_count = debug_get_num_option("SWR_MSAA_MAX_COUNT", 1);
+ if (msaa_max_count != 1) {
+ if ((msaa_max_count < 1) || (msaa_max_count > SWR_MAX_NUM_MULTISAMPLES)
+ || !util_is_power_of_two_or_zero(msaa_max_count)) {
+ fprintf(stderr, "SWR_MSAA_MAX_COUNT invalid: %d\n", msaa_max_count);
+ fprintf(stderr, "must be power of 2 between 1 and %d" \
+ " (or 1 to disable msaa)\n",
+ SWR_MAX_NUM_MULTISAMPLES);
+ msaa_max_count = 1;
+ }
+
+ fprintf(stderr, "SWR_MSAA_MAX_COUNT: %d\n", msaa_max_count);
+ if (msaa_max_count == 1)
+ fprintf(stderr, "(msaa disabled)\n");
+
+ screen->msaa_max_count = msaa_max_count;
+ }
+
+ screen->msaa_force_enable = debug_get_bool_option(
+ "SWR_MSAA_FORCE_ENABLE", false);
+ if (screen->msaa_force_enable)
+ fprintf(stderr, "SWR_MSAA_FORCE_ENABLE: true\n");
+}
+
+
struct pipe_screen *
swr_create_screen_internal(struct sw_winsys *winsys)
{
if (!screen)
return NULL;
- if (!getenv("KNOB_MAX_PRIMS_PER_DRAW")) {
- g_GlobalKnobs.MAX_PRIMS_PER_DRAW.Value(49152);
- }
-
if (!lp_build_init()) {
FREE(screen);
return NULL;
screen->base.flush_frontbuffer = swr_flush_frontbuffer;
- screen->hJitMgr = JitCreateContext(KNOB_SIMD_WIDTH, KNOB_ARCH_STR, "swr");
+ // Pass in "" for architecture for run-time determination
+ screen->hJitMgr = JitCreateContext(KNOB_SIMD_WIDTH, "", "swr");
swr_fence_init(&screen->base);
- util_format_s3tc_init();
+ swr_validate_env_options(screen);
return &screen->base;
}
-