1 #include "nv40_context.h"
2 #include "nouveau/nouveau_util.h"
4 static struct pipe_buffer
*
5 nv40_surface_buffer(struct pipe_surface
*surface
)
7 struct nv40_miptree
*mt
= (struct nv40_miptree
*)surface
->texture
;
12 nv40_state_framebuffer_validate(struct nv40_context
*nv40
)
14 struct pipe_framebuffer_state
*fb
= &nv40
->framebuffer
;
15 struct pipe_surface
*rt
[4], *zeta
;
16 uint32_t rt_enable
, rt_format
;
17 int i
, colour_format
= 0, zeta_format
= 0;
18 struct nouveau_stateobj
*so
= so_new(64, 10);
19 unsigned rt_flags
= NOUVEAU_BO_RDWR
| NOUVEAU_BO_VRAM
;
20 unsigned w
= fb
->width
;
21 unsigned h
= fb
->height
;
24 for (i
= 0; i
< fb
->nr_cbufs
; i
++) {
26 assert(colour_format
== fb
->cbufs
[i
]->format
);
28 colour_format
= fb
->cbufs
[i
]->format
;
29 rt_enable
|= (NV40TCL_RT_ENABLE_COLOR0
<< i
);
34 if (rt_enable
& (NV40TCL_RT_ENABLE_COLOR1
| NV40TCL_RT_ENABLE_COLOR2
|
35 NV40TCL_RT_ENABLE_COLOR3
))
36 rt_enable
|= NV40TCL_RT_ENABLE_MRT
;
39 zeta_format
= fb
->zsbuf
->format
;
43 if (!(rt
[0]->texture
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
)) {
44 assert(!(fb
->width
& (fb
->width
- 1)) && !(fb
->height
& (fb
->height
- 1)));
45 for (i
= 1; i
< fb
->nr_cbufs
; i
++)
46 assert(!(rt
[i
]->texture
->tex_usage
& NOUVEAU_TEXTURE_USAGE_LINEAR
));
48 rt_format
= NV40TCL_RT_FORMAT_TYPE_SWIZZLED
|
49 log2i(fb
->width
) << NV40TCL_RT_FORMAT_LOG2_WIDTH_SHIFT
|
50 log2i(fb
->height
) << NV40TCL_RT_FORMAT_LOG2_HEIGHT_SHIFT
;
53 rt_format
= NV40TCL_RT_FORMAT_TYPE_LINEAR
;
55 switch (colour_format
) {
56 case PIPE_FORMAT_A8R8G8B8_UNORM
:
58 rt_format
|= NV40TCL_RT_FORMAT_COLOR_A8R8G8B8
;
60 case PIPE_FORMAT_R5G6B5_UNORM
:
61 rt_format
|= NV40TCL_RT_FORMAT_COLOR_R5G6B5
;
67 switch (zeta_format
) {
68 case PIPE_FORMAT_Z16_UNORM
:
69 rt_format
|= NV40TCL_RT_FORMAT_ZETA_Z16
;
71 case PIPE_FORMAT_Z24S8_UNORM
:
73 rt_format
|= NV40TCL_RT_FORMAT_ZETA_Z24S8
;
79 if (rt_enable
& NV40TCL_RT_ENABLE_COLOR0
) {
80 so_method(so
, nv40
->screen
->curie
, NV40TCL_DMA_COLOR0
, 1);
81 so_reloc (so
, nv40_surface_buffer(rt
[0]), 0, rt_flags
| NOUVEAU_BO_OR
,
82 nv40
->nvws
->channel
->vram
->handle
,
83 nv40
->nvws
->channel
->gart
->handle
);
84 so_method(so
, nv40
->screen
->curie
, NV40TCL_COLOR0_PITCH
, 2);
85 so_data (so
, rt
[0]->stride
);
86 so_reloc (so
, nv40_surface_buffer(rt
[0]), rt
[0]->offset
, rt_flags
|
87 NOUVEAU_BO_LOW
, 0, 0);
90 if (rt_enable
& NV40TCL_RT_ENABLE_COLOR1
) {
91 so_method(so
, nv40
->screen
->curie
, NV40TCL_DMA_COLOR1
, 1);
92 so_reloc (so
, nv40_surface_buffer(rt
[1]), 0, rt_flags
| NOUVEAU_BO_OR
,
93 nv40
->nvws
->channel
->vram
->handle
,
94 nv40
->nvws
->channel
->gart
->handle
);
95 so_method(so
, nv40
->screen
->curie
, NV40TCL_COLOR1_OFFSET
, 2);
96 so_reloc (so
, nv40_surface_buffer(rt
[1]), rt
[1]->offset
, rt_flags
|
97 NOUVEAU_BO_LOW
, 0, 0);
98 so_data (so
, rt
[1]->stride
);
101 if (rt_enable
& NV40TCL_RT_ENABLE_COLOR2
) {
102 so_method(so
, nv40
->screen
->curie
, NV40TCL_DMA_COLOR2
, 1);
103 so_reloc (so
, nv40_surface_buffer(rt
[2]), 0, rt_flags
| NOUVEAU_BO_OR
,
104 nv40
->nvws
->channel
->vram
->handle
,
105 nv40
->nvws
->channel
->gart
->handle
);
106 so_method(so
, nv40
->screen
->curie
, NV40TCL_COLOR2_OFFSET
, 1);
107 so_reloc (so
, nv40_surface_buffer(rt
[2]), rt
[2]->offset
, rt_flags
|
108 NOUVEAU_BO_LOW
, 0, 0);
109 so_method(so
, nv40
->screen
->curie
, NV40TCL_COLOR2_PITCH
, 1);
110 so_data (so
, rt
[2]->stride
);
113 if (rt_enable
& NV40TCL_RT_ENABLE_COLOR3
) {
114 so_method(so
, nv40
->screen
->curie
, NV40TCL_DMA_COLOR3
, 1);
115 so_reloc (so
, nv40_surface_buffer(rt
[3]), 0, rt_flags
| NOUVEAU_BO_OR
,
116 nv40
->nvws
->channel
->vram
->handle
,
117 nv40
->nvws
->channel
->gart
->handle
);
118 so_method(so
, nv40
->screen
->curie
, NV40TCL_COLOR3_OFFSET
, 1);
119 so_reloc (so
, nv40_surface_buffer(rt
[3]), rt
[3]->offset
, rt_flags
|
120 NOUVEAU_BO_LOW
, 0, 0);
121 so_method(so
, nv40
->screen
->curie
, NV40TCL_COLOR3_PITCH
, 1);
122 so_data (so
, rt
[3]->stride
);
126 so_method(so
, nv40
->screen
->curie
, NV40TCL_DMA_ZETA
, 1);
127 so_reloc (so
, nv40_surface_buffer(zeta
), 0, rt_flags
| NOUVEAU_BO_OR
,
128 nv40
->nvws
->channel
->vram
->handle
,
129 nv40
->nvws
->channel
->gart
->handle
);
130 so_method(so
, nv40
->screen
->curie
, NV40TCL_ZETA_OFFSET
, 1);
131 so_reloc (so
, nv40_surface_buffer(zeta
), zeta
->offset
, rt_flags
|
132 NOUVEAU_BO_LOW
, 0, 0);
133 so_method(so
, nv40
->screen
->curie
, NV40TCL_ZETA_PITCH
, 1);
134 so_data (so
, zeta
->stride
);
137 so_method(so
, nv40
->screen
->curie
, NV40TCL_RT_ENABLE
, 1);
138 so_data (so
, rt_enable
);
139 so_method(so
, nv40
->screen
->curie
, NV40TCL_RT_HORIZ
, 3);
140 so_data (so
, (w
<< 16) | 0);
141 so_data (so
, (h
<< 16) | 0);
142 so_data (so
, rt_format
);
143 so_method(so
, nv40
->screen
->curie
, NV40TCL_VIEWPORT_HORIZ
, 2);
144 so_data (so
, (w
<< 16) | 0);
145 so_data (so
, (h
<< 16) | 0);
146 so_method(so
, nv40
->screen
->curie
, NV40TCL_VIEWPORT_CLIP_HORIZ(0), 2);
147 so_data (so
, ((w
- 1) << 16) | 0);
148 so_data (so
, ((h
- 1) << 16) | 0);
149 so_method(so
, nv40
->screen
->curie
, 0x1d88, 1);
150 so_data (so
, (1 << 12) | h
);
152 so_ref(so
, &nv40
->state
.hw
[NV40_STATE_FB
]);
156 struct nv40_state_entry nv40_state_framebuffer
= {
157 .validate
= nv40_state_framebuffer_validate
,