Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | #include "main/mtypes.h" |
2 | #include "main/macros.h" |
||
3 | #include "main/samplerobj.h" |
||
4 | #include "main/texobj.h" |
||
5 | |||
6 | #include "brw_context.h" |
||
7 | #include "intel_mipmap_tree.h" |
||
8 | #include "intel_blit.h" |
||
9 | #include "intel_tex.h" |
||
10 | |||
11 | #define FILE_DEBUG_FLAG DEBUG_TEXTURE |
||
12 | |||
13 | /** |
||
14 | * When validating, we only care about the texture images that could |
||
15 | * be seen, so for non-mipmapped modes we want to ignore everything |
||
16 | * but BaseLevel. |
||
17 | */ |
||
18 | static void |
||
19 | intel_update_max_level(struct intel_texture_object *intelObj, |
||
20 | struct gl_sampler_object *sampler) |
||
21 | { |
||
22 | struct gl_texture_object *tObj = &intelObj->base; |
||
23 | int maxlevel; |
||
24 | |||
25 | if (sampler->MinFilter == GL_NEAREST || |
||
26 | sampler->MinFilter == GL_LINEAR) { |
||
27 | maxlevel = tObj->BaseLevel; |
||
28 | } else { |
||
29 | maxlevel = tObj->_MaxLevel; |
||
30 | } |
||
31 | |||
32 | if (intelObj->_MaxLevel != maxlevel) { |
||
33 | intelObj->_MaxLevel = maxlevel; |
||
34 | intelObj->needs_validate = true; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | /* |
||
39 | */ |
||
40 | GLuint |
||
41 | intel_finalize_mipmap_tree(struct brw_context *brw, GLuint unit) |
||
42 | { |
||
43 | struct gl_context *ctx = &brw->ctx; |
||
44 | struct gl_texture_object *tObj = ctx->Texture.Unit[unit]._Current; |
||
45 | struct intel_texture_object *intelObj = intel_texture_object(tObj); |
||
46 | struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit); |
||
47 | GLuint face, i; |
||
48 | GLuint nr_faces = 0; |
||
49 | struct intel_texture_image *firstImage; |
||
50 | int width, height, depth; |
||
51 | |||
52 | /* TBOs require no validation -- they always just point to their BO. */ |
||
53 | if (tObj->Target == GL_TEXTURE_BUFFER) |
||
54 | return true; |
||
55 | |||
56 | /* We know/require this is true by now: |
||
57 | */ |
||
58 | assert(intelObj->base._BaseComplete); |
||
59 | |||
60 | /* What levels must the tree include at a minimum? |
||
61 | */ |
||
62 | intel_update_max_level(intelObj, sampler); |
||
63 | if (intelObj->mt && intelObj->mt->first_level != tObj->BaseLevel) |
||
64 | intelObj->needs_validate = true; |
||
65 | |||
66 | if (!intelObj->needs_validate) |
||
67 | return true; |
||
68 | |||
69 | firstImage = intel_texture_image(tObj->Image[0][tObj->BaseLevel]); |
||
70 | |||
71 | /* Check tree can hold all active levels. Check tree matches |
||
72 | * target, imageFormat, etc. |
||
73 | * |
||
74 | * For pre-gen4, we have to match first_level == tObj->BaseLevel, |
||
75 | * because we don't have the control that gen4 does to make min/mag |
||
76 | * determination happen at a nonzero (hardware) baselevel. Because |
||
77 | * of that, we just always relayout on baselevel change. |
||
78 | */ |
||
79 | if (intelObj->mt && |
||
80 | (!intel_miptree_match_image(intelObj->mt, &firstImage->base.Base) || |
||
81 | intelObj->mt->first_level != tObj->BaseLevel || |
||
82 | intelObj->mt->last_level < intelObj->_MaxLevel)) { |
||
83 | intel_miptree_release(&intelObj->mt); |
||
84 | } |
||
85 | |||
86 | |||
87 | /* May need to create a new tree: |
||
88 | */ |
||
89 | if (!intelObj->mt) { |
||
90 | intel_miptree_get_dimensions_for_image(&firstImage->base.Base, |
||
91 | &width, &height, &depth); |
||
92 | |||
93 | perf_debug("Creating new %s %dx%dx%d %d..%d miptree to handle finalized " |
||
94 | "texture miptree.\n", |
||
95 | _mesa_get_format_name(firstImage->base.Base.TexFormat), |
||
96 | width, height, depth, tObj->BaseLevel, intelObj->_MaxLevel); |
||
97 | |||
98 | intelObj->mt = intel_miptree_create(brw, |
||
99 | intelObj->base.Target, |
||
100 | firstImage->base.Base.TexFormat, |
||
101 | tObj->BaseLevel, |
||
102 | intelObj->_MaxLevel, |
||
103 | width, |
||
104 | height, |
||
105 | depth, |
||
106 | true, |
||
107 | |||
108 | INTEL_MIPTREE_TILING_ANY); |
||
109 | if (!intelObj->mt) |
||
110 | return false; |
||
111 | } |
||
112 | |||
113 | /* Pull in any images not in the object's tree: |
||
114 | */ |
||
115 | nr_faces = _mesa_num_tex_faces(intelObj->base.Target); |
||
116 | for (face = 0; face < nr_faces; face++) { |
||
117 | for (i = tObj->BaseLevel; i <= intelObj->_MaxLevel; i++) { |
||
118 | struct intel_texture_image *intelImage = |
||
119 | intel_texture_image(intelObj->base.Image[face][i]); |
||
120 | /* skip too small size mipmap */ |
||
121 | if (intelImage == NULL) |
||
122 | break; |
||
123 | |||
124 | if (intelObj->mt != intelImage->mt) { |
||
125 | intel_miptree_copy_teximage(brw, intelImage, intelObj->mt, |
||
126 | false /* invalidate */); |
||
127 | } |
||
128 | |||
129 | /* After we're done, we'd better agree that our layout is |
||
130 | * appropriate, or we'll end up hitting this function again on the |
||
131 | * next draw |
||
132 | */ |
||
133 | assert(intel_miptree_match_image(intelObj->mt, &intelImage->base.Base)); |
||
134 | } |
||
135 | } |
||
136 | |||
137 | intelObj->needs_validate = false; |
||
138 | |||
139 | return true; |
||
140 | }=>>> |