40
40
#include "util/u_format.h"
41
41
#include "util/u_math.h"
42
42
#include "util/u_memory.h"
43
#include "util/u_sampler.h"
44
45
#include "tgsi/tgsi_transform.h"
45
46
#include "tgsi/tgsi_dump.h"
112
114
void (*driver_bind_sampler_states)(struct pipe_context *, unsigned,
114
void (*driver_set_sampler_textures)(struct pipe_context *, unsigned,
115
struct pipe_texture **);
117
void (*driver_set_sampler_views)(struct pipe_context *,
119
struct pipe_sampler_view **);
393
397
struct pipe_context *pipe = aaline->stage.draw->pipe;
394
398
struct pipe_screen *screen = pipe->screen;
395
struct pipe_texture texTemp;
399
struct pipe_resource texTemp;
400
struct pipe_sampler_view viewTempl;
398
403
memset(&texTemp, 0, sizeof(texTemp));
402
407
texTemp.width0 = 1 << MAX_TEXTURE_LEVEL;
403
408
texTemp.height0 = 1 << MAX_TEXTURE_LEVEL;
404
409
texTemp.depth0 = 1;
410
texTemp.bind = PIPE_BIND_SAMPLER_VIEW;
406
aaline->texture = screen->texture_create(screen, &texTemp);
412
aaline->texture = screen->resource_create(screen, &texTemp);
407
413
if (!aaline->texture)
416
u_sampler_view_default_template(&viewTempl,
418
aaline->texture->format);
419
aaline->sampler_view = pipe->create_sampler_view(pipe,
422
if (!aaline->sampler_view) {
410
426
/* Fill in mipmap images.
411
427
* Basically each level is solid opaque, except for the outermost
412
* texels which are zero. Special case the 1x1 and 2x2 levels.
428
* texels which are zero. Special case the 1x1 and 2x2 levels
429
* (though, those levels shouldn't be used - see the max_lod setting).
414
431
for (level = 0; level <= MAX_TEXTURE_LEVEL; level++) {
415
432
struct pipe_transfer *transfer;
416
434
const uint size = u_minify(aaline->texture->width0, level);
420
438
assert(aaline->texture->width0 == aaline->texture->height0);
440
u_box_origin_2d( size, size, &box );
422
442
/* This texture is new, no need to flush.
424
transfer = screen->get_tex_transfer(screen, aaline->texture, 0, level, 0,
425
PIPE_TRANSFER_WRITE, 0, 0, size, size);
426
data = screen->transfer_map(screen, transfer);
444
transfer = pipe->get_transfer(pipe,
446
u_subresource(0, level),
450
data = pipe->transfer_map(pipe, transfer);
427
451
if (data == NULL)
450
screen->transfer_unmap(screen, transfer);
451
screen->tex_transfer_destroy(transfer);
474
pipe->transfer_unmap(pipe, transfer);
475
pipe->transfer_destroy(pipe, transfer);
474
498
sampler.mag_img_filter = PIPE_TEX_FILTER_LINEAR;
475
499
sampler.normalized_coords = 1;
476
500
sampler.min_lod = 0.0f;
477
sampler.max_lod = MAX_TEXTURE_LEVEL;
501
/* avoid using the 1x1 and 2x2 mipmap levels */
502
sampler.max_lod = MAX_TEXTURE_LEVEL - 2;
479
504
aaline->sampler_cso = pipe->create_sampler_state(pipe, &sampler);
480
505
if (aaline->sampler_cso == NULL)
647
672
assert(draw->rasterizer->line_smooth);
649
if (draw->rasterizer->line_width <= 3.0)
650
aaline->half_line_width = 1.5f;
674
if (draw->rasterizer->line_width <= 2.2)
675
aaline->half_line_width = 1.1f;
652
677
aaline->half_line_width = 0.5f * draw->rasterizer->line_width;
672
697
/* how many samplers? */
673
698
/* we'll use sampler/texture[pstip->sampler_unit] for the stipple */
674
num_samplers = MAX2(aaline->num_textures, aaline->num_samplers);
699
num_samplers = MAX2(aaline->num_sampler_views, aaline->num_samplers);
675
700
num_samplers = MAX2(num_samplers, aaline->fs->sampler_unit + 1);
677
702
aaline->state.sampler[aaline->fs->sampler_unit] = aaline->sampler_cso;
678
pipe_texture_reference(&aaline->state.texture[aaline->fs->sampler_unit],
703
pipe_sampler_view_reference(&aaline->state.sampler_views[aaline->fs->sampler_unit],
704
aaline->sampler_view);
681
706
draw->suspend_flushing = TRUE;
682
707
aaline->driver_bind_sampler_states(pipe, num_samplers, aaline->state.sampler);
683
aaline->driver_set_sampler_textures(pipe, num_samplers, aaline->state.texture);
708
aaline->driver_set_sampler_views(pipe, num_samplers, aaline->state.sampler_views);
685
710
/* Disable triangle culling, stippling, unfilled mode etc. */
686
711
r = draw_get_rasterizer_no_cull(draw, rast->scissor, rast->flatshade);
709
734
aaline->driver_bind_fs_state(pipe, aaline->fs->driver_fs);
710
735
aaline->driver_bind_sampler_states(pipe, aaline->num_samplers,
711
736
aaline->state.sampler);
712
aaline->driver_set_sampler_textures(pipe, aaline->num_textures,
713
aaline->state.texture);
737
aaline->driver_set_sampler_views(pipe,
738
aaline->num_sampler_views,
739
aaline->state.sampler_views);
715
741
/* restore original rasterizer state */
716
742
if (draw->rast_handle) {
740
766
for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
741
pipe_texture_reference(&aaline->state.texture[i], NULL);
767
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
744
770
if (aaline->sampler_cso)
745
771
pipe->delete_sampler_state(pipe, aaline->sampler_cso);
747
773
if (aaline->texture)
748
pipe_texture_reference(&aaline->texture, NULL);
774
pipe_resource_reference(&aaline->texture, NULL);
776
if (aaline->sampler_view) {
777
pipe_sampler_view_reference(&aaline->sampler_view, NULL);
750
780
draw_free_temp_verts( stage );
760
790
if (aaline == NULL)
763
if (!draw_alloc_temp_verts( &aaline->stage, 8 ))
766
793
aaline->stage.draw = draw;
767
794
aaline->stage.name = "aaline";
768
795
aaline->stage.next = NULL;
773
800
aaline->stage.reset_stipple_counter = aaline_reset_stipple_counter;
774
801
aaline->stage.destroy = aaline_destroy;
803
if (!draw_alloc_temp_verts( &aaline->stage, 8 ))
780
aaline_destroy(&aaline->stage);
810
aaline->stage.destroy(&aaline->stage);
862
aaline_set_sampler_textures(struct pipe_context *pipe,
863
unsigned num, struct pipe_texture **texture)
892
aaline_set_sampler_views(struct pipe_context *pipe,
894
struct pipe_sampler_view **views)
865
896
struct aaline_stage *aaline = aaline_stage_from_pipe(pipe);
868
899
/* save current */
869
900
for (i = 0; i < num; i++) {
870
pipe_texture_reference(&aaline->state.texture[i], texture[i]);
901
pipe_sampler_view_reference(&aaline->state.sampler_views[i], views[i]);
872
903
for ( ; i < PIPE_MAX_SAMPLERS; i++) {
873
pipe_texture_reference(&aaline->state.texture[i], NULL);
904
pipe_sampler_view_reference(&aaline->state.sampler_views[i], NULL);
875
aaline->num_textures = num;
906
aaline->num_sampler_views = num;
877
908
/* pass-through */
878
aaline->driver_set_sampler_textures(pipe, num, texture);
909
aaline->driver_set_sampler_views(pipe, num, views);
911
942
aaline->driver_delete_fs_state = pipe->delete_fs_state;
913
944
aaline->driver_bind_sampler_states = pipe->bind_fragment_sampler_states;
914
aaline->driver_set_sampler_textures = pipe->set_fragment_sampler_textures;
945
aaline->driver_set_sampler_views = pipe->set_fragment_sampler_views;
916
947
/* override the driver's functions */
917
948
pipe->create_fs_state = aaline_create_fs_state;
919
950
pipe->delete_fs_state = aaline_delete_fs_state;
921
952
pipe->bind_fragment_sampler_states = aaline_bind_sampler_states;
922
pipe->set_fragment_sampler_textures = aaline_set_sampler_textures;
953
pipe->set_fragment_sampler_views = aaline_set_sampler_views;
924
955
/* Install once everything is known to be OK: