1 /****************************************************************************
2 * Copyright (C) 2015 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 ***************************************************************************/
24 #include "JitManager.h"
26 #include "state_llvm.h"
29 #include "llvm-c/Core.h"
30 #include "llvm/Support/CBindingWrapping.h"
32 #include "tgsi/tgsi_strings.h"
33 #include "gallivm/lp_bld_init.h"
34 #include "gallivm/lp_bld_flow.h"
35 #include "gallivm/lp_bld_struct.h"
36 #include "gallivm/lp_bld_tgsi.h"
38 #include "swr_context.h"
39 #include "swr_context_llvm.h"
40 #include "swr_state.h"
41 #include "swr_screen.h"
43 bool operator==(const swr_jit_fs_key
&lhs
, const swr_jit_fs_key
&rhs
)
45 return !memcmp(&lhs
, &rhs
, sizeof(lhs
));
48 bool operator==(const swr_jit_vs_key
&lhs
, const swr_jit_vs_key
&rhs
)
50 return !memcmp(&lhs
, &rhs
, sizeof(lhs
));
54 swr_generate_sampler_key(const struct lp_tgsi_info
&info
,
55 struct swr_context
*ctx
,
57 struct swr_jit_sampler_key
&key
)
59 key
.nr_samplers
= info
.base
.file_max
[TGSI_FILE_SAMPLER
] + 1;
61 for (unsigned i
= 0; i
< key
.nr_samplers
; i
++) {
62 if (info
.base
.file_mask
[TGSI_FILE_SAMPLER
] & (1 << i
)) {
63 lp_sampler_static_sampler_state(
64 &key
.sampler
[i
].sampler_state
,
65 ctx
->samplers
[shader_type
][i
]);
70 * XXX If TGSI_FILE_SAMPLER_VIEW exists assume all texture opcodes
71 * are dx10-style? Can't really have mixed opcodes, at least not
72 * if we want to skip the holes here (without rescanning tgsi).
74 if (info
.base
.file_max
[TGSI_FILE_SAMPLER_VIEW
] != -1) {
75 key
.nr_sampler_views
=
76 info
.base
.file_max
[TGSI_FILE_SAMPLER_VIEW
] + 1;
77 for (unsigned i
= 0; i
< key
.nr_sampler_views
; i
++) {
78 if (info
.base
.file_mask
[TGSI_FILE_SAMPLER_VIEW
] & (1 << i
)) {
79 lp_sampler_static_texture_state(
80 &key
.sampler
[i
].texture_state
,
81 ctx
->sampler_views
[shader_type
][i
]);
85 key
.nr_sampler_views
= key
.nr_samplers
;
86 for (unsigned i
= 0; i
< key
.nr_sampler_views
; i
++) {
87 if (info
.base
.file_mask
[TGSI_FILE_SAMPLER
] & (1 << i
)) {
88 lp_sampler_static_texture_state(
89 &key
.sampler
[i
].texture_state
,
90 ctx
->sampler_views
[shader_type
][i
]);
97 swr_generate_fs_key(struct swr_jit_fs_key
&key
,
98 struct swr_context
*ctx
,
99 swr_fragment_shader
*swr_fs
)
101 memset(&key
, 0, sizeof(key
));
103 key
.nr_cbufs
= ctx
->framebuffer
.nr_cbufs
;
104 key
.light_twoside
= ctx
->rasterizer
->light_twoside
;
105 key
.flatshade
= ctx
->rasterizer
->flatshade
;
106 memcpy(&key
.vs_output_semantic_name
,
107 &ctx
->vs
->info
.base
.output_semantic_name
,
108 sizeof(key
.vs_output_semantic_name
));
109 memcpy(&key
.vs_output_semantic_idx
,
110 &ctx
->vs
->info
.base
.output_semantic_index
,
111 sizeof(key
.vs_output_semantic_idx
));
113 swr_generate_sampler_key(swr_fs
->info
, ctx
, PIPE_SHADER_FRAGMENT
, key
);
117 swr_generate_vs_key(struct swr_jit_vs_key
&key
,
118 struct swr_context
*ctx
,
119 swr_vertex_shader
*swr_vs
)
121 memset(&key
, 0, sizeof(key
));
123 swr_generate_sampler_key(swr_vs
->info
, ctx
, PIPE_SHADER_VERTEX
, key
);
126 struct BuilderSWR
: public Builder
{
127 BuilderSWR(JitManager
*pJitMgr
, const char *pName
)
130 pJitMgr
->SetupNewModule();
131 gallivm
= gallivm_create(pName
, wrap(&JM()->mContext
));
132 pJitMgr
->mpCurrentModule
= unwrap(gallivm
->module
);
136 gallivm_free_ir(gallivm
);
139 struct gallivm_state
*gallivm
;
140 PFN_VERTEX_FUNC
CompileVS(struct swr_context
*ctx
, swr_jit_vs_key
&key
);
141 PFN_PIXEL_KERNEL
CompileFS(struct swr_context
*ctx
, swr_jit_fs_key
&key
);
145 BuilderSWR::CompileVS(struct swr_context
*ctx
, swr_jit_vs_key
&key
)
147 struct swr_vertex_shader
*swr_vs
= ctx
->vs
;
149 swr_vs
->linkageMask
= 0;
151 for (unsigned i
= 0; i
< swr_vs
->info
.base
.num_outputs
; i
++) {
152 switch (swr_vs
->info
.base
.output_semantic_name
[i
]) {
153 case TGSI_SEMANTIC_POSITION
:
156 swr_vs
->linkageMask
|= (1 << i
);
161 LLVMValueRef inputs
[PIPE_MAX_SHADER_INPUTS
][TGSI_NUM_CHANNELS
];
162 LLVMValueRef outputs
[PIPE_MAX_SHADER_OUTPUTS
][TGSI_NUM_CHANNELS
];
164 memset(outputs
, 0, sizeof(outputs
));
166 AttrBuilder attrBuilder
;
167 attrBuilder
.addStackAlignmentAttr(JM()->mVWidth
* sizeof(float));
168 AttributeSet attrSet
= AttributeSet::get(
169 JM()->mContext
, AttributeSet::FunctionIndex
, attrBuilder
);
171 std::vector
<Type
*> vsArgs
{PointerType::get(Gen_swr_draw_context(JM()), 0),
172 PointerType::get(Gen_SWR_VS_CONTEXT(JM()), 0)};
173 FunctionType
*vsFuncType
=
174 FunctionType::get(Type::getVoidTy(JM()->mContext
), vsArgs
, false);
176 // create new vertex shader function
177 auto pFunction
= Function::Create(vsFuncType
,
178 GlobalValue::ExternalLinkage
,
180 JM()->mpCurrentModule
);
181 pFunction
->addAttributes(AttributeSet::FunctionIndex
, attrSet
);
183 BasicBlock
*block
= BasicBlock::Create(JM()->mContext
, "entry", pFunction
);
184 IRB()->SetInsertPoint(block
);
185 LLVMPositionBuilderAtEnd(gallivm
->builder
, wrap(block
));
187 auto argitr
= pFunction
->arg_begin();
188 Value
*hPrivateData
= &*argitr
++;
189 hPrivateData
->setName("hPrivateData");
190 Value
*pVsCtx
= &*argitr
++;
191 pVsCtx
->setName("vsCtx");
193 Value
*consts_ptr
= GEP(hPrivateData
, {C(0), C(swr_draw_context_constantVS
)});
195 consts_ptr
->setName("vs_constants");
196 Value
*const_sizes_ptr
=
197 GEP(hPrivateData
, {0, swr_draw_context_num_constantsVS
});
198 const_sizes_ptr
->setName("num_vs_constants");
200 Value
*vtxInput
= LOAD(pVsCtx
, {0, SWR_VS_CONTEXT_pVin
});
202 for (uint32_t attrib
= 0; attrib
< PIPE_MAX_SHADER_INPUTS
; attrib
++) {
203 const unsigned mask
= swr_vs
->info
.base
.input_usage_mask
[attrib
];
204 for (uint32_t channel
= 0; channel
< TGSI_NUM_CHANNELS
; channel
++) {
205 if (mask
& (1 << channel
)) {
206 inputs
[attrib
][channel
] =
207 wrap(LOAD(vtxInput
, {0, 0, attrib
, channel
}));
212 struct lp_build_sampler_soa
*sampler
=
213 swr_sampler_soa_create(key
.sampler
, PIPE_SHADER_VERTEX
);
215 struct lp_bld_tgsi_system_values system_values
;
216 memset(&system_values
, 0, sizeof(system_values
));
217 system_values
.instance_id
= wrap(LOAD(pVsCtx
, {0, SWR_VS_CONTEXT_InstanceID
}));
218 system_values
.vertex_id
= wrap(LOAD(pVsCtx
, {0, SWR_VS_CONTEXT_VertexID
}));
220 lp_build_tgsi_soa(gallivm
,
222 lp_type_float_vec(32, 32 * 8),
225 wrap(const_sizes_ptr
),
229 wrap(hPrivateData
), // (sampler context)
233 NULL
); // geometry shader face
235 sampler
->destroy(sampler
);
237 IRB()->SetInsertPoint(unwrap(LLVMGetInsertBlock(gallivm
->builder
)));
239 Value
*vtxOutput
= LOAD(pVsCtx
, {0, SWR_VS_CONTEXT_pVout
});
241 for (uint32_t channel
= 0; channel
< TGSI_NUM_CHANNELS
; channel
++) {
242 for (uint32_t attrib
= 0; attrib
< PIPE_MAX_SHADER_OUTPUTS
; attrib
++) {
243 if (!outputs
[attrib
][channel
])
246 Value
*val
= LOAD(unwrap(outputs
[attrib
][channel
]));
248 uint32_t outSlot
= attrib
;
249 if (swr_vs
->info
.base
.output_semantic_name
[attrib
] == TGSI_SEMANTIC_PSIZE
)
250 outSlot
= VERTEX_POINT_SIZE_SLOT
;
251 STORE(val
, vtxOutput
, {0, 0, outSlot
, channel
});
257 gallivm_verify_function(gallivm
, wrap(pFunction
));
258 gallivm_compile_module(gallivm
);
260 // lp_debug_dump_value(func);
262 PFN_VERTEX_FUNC pFunc
=
263 (PFN_VERTEX_FUNC
)gallivm_jit_function(gallivm
, wrap(pFunction
));
265 debug_printf("vert shader %p\n", pFunc
);
266 assert(pFunc
&& "Error: VertShader = NULL");
268 #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 5)
269 JM()->mIsModuleFinalized
= true;
276 swr_compile_vs(struct swr_context
*ctx
, swr_jit_vs_key
&key
)
279 reinterpret_cast<JitManager
*>(swr_screen(ctx
->pipe
.screen
)->hJitMgr
),
281 PFN_VERTEX_FUNC func
= builder
.CompileVS(ctx
, key
);
283 ctx
->vs
->map
.insert(std::make_pair(key
, make_unique
<VariantVS
>(builder
.gallivm
, func
)));
288 locate_linkage(ubyte name
, ubyte index
, struct tgsi_shader_info
*info
)
290 for (int i
= 0; i
< PIPE_MAX_SHADER_OUTPUTS
; i
++) {
291 if ((info
->output_semantic_name
[i
] == name
)
292 && (info
->output_semantic_index
[i
] == index
)) {
293 return i
- 1; // position is not part of the linkage
297 if (name
== TGSI_SEMANTIC_COLOR
) { // BCOLOR fallback
298 for (int i
= 0; i
< PIPE_MAX_SHADER_OUTPUTS
; i
++) {
299 if ((info
->output_semantic_name
[i
] == TGSI_SEMANTIC_BCOLOR
)
300 && (info
->output_semantic_index
[i
] == index
)) {
301 return i
- 1; // position is not part of the linkage
310 BuilderSWR::CompileFS(struct swr_context
*ctx
, swr_jit_fs_key
&key
)
312 struct swr_fragment_shader
*swr_fs
= ctx
->fs
;
314 LLVMValueRef inputs
[PIPE_MAX_SHADER_INPUTS
][TGSI_NUM_CHANNELS
];
315 LLVMValueRef outputs
[PIPE_MAX_SHADER_OUTPUTS
][TGSI_NUM_CHANNELS
];
317 memset(inputs
, 0, sizeof(inputs
));
318 memset(outputs
, 0, sizeof(outputs
));
320 struct lp_build_sampler_soa
*sampler
= NULL
;
322 AttrBuilder attrBuilder
;
323 attrBuilder
.addStackAlignmentAttr(JM()->mVWidth
* sizeof(float));
324 AttributeSet attrSet
= AttributeSet::get(
325 JM()->mContext
, AttributeSet::FunctionIndex
, attrBuilder
);
327 std::vector
<Type
*> fsArgs
{PointerType::get(Gen_swr_draw_context(JM()), 0),
328 PointerType::get(Gen_SWR_PS_CONTEXT(JM()), 0)};
329 FunctionType
*funcType
=
330 FunctionType::get(Type::getVoidTy(JM()->mContext
), fsArgs
, false);
332 auto pFunction
= Function::Create(funcType
,
333 GlobalValue::ExternalLinkage
,
335 JM()->mpCurrentModule
);
336 pFunction
->addAttributes(AttributeSet::FunctionIndex
, attrSet
);
338 BasicBlock
*block
= BasicBlock::Create(JM()->mContext
, "entry", pFunction
);
339 IRB()->SetInsertPoint(block
);
340 LLVMPositionBuilderAtEnd(gallivm
->builder
, wrap(block
));
342 auto args
= pFunction
->arg_begin();
343 Value
*hPrivateData
= &*args
++;
344 hPrivateData
->setName("hPrivateData");
345 Value
*pPS
= &*args
++;
346 pPS
->setName("psCtx");
348 Value
*consts_ptr
= GEP(hPrivateData
, {0, swr_draw_context_constantFS
});
349 consts_ptr
->setName("fs_constants");
350 Value
*const_sizes_ptr
=
351 GEP(hPrivateData
, {0, swr_draw_context_num_constantsFS
});
352 const_sizes_ptr
->setName("num_fs_constants");
354 // xxx should check for flat shading versus interpolation
357 // load *pAttribs, *pPerspAttribs
358 Value
*pRawAttribs
= LOAD(pPS
, {0, SWR_PS_CONTEXT_pAttribs
}, "pRawAttribs");
359 Value
*pPerspAttribs
=
360 LOAD(pPS
, {0, SWR_PS_CONTEXT_pPerspAttribs
}, "pPerspAttribs");
362 swr_fs
->constantMask
= 0;
363 swr_fs
->pointSpriteMask
= 0;
365 for (int attrib
= 0; attrib
< PIPE_MAX_SHADER_INPUTS
; attrib
++) {
366 const unsigned mask
= swr_fs
->info
.base
.input_usage_mask
[attrib
];
367 const unsigned interpMode
= swr_fs
->info
.base
.input_interpolate
[attrib
];
368 const unsigned interpLoc
= swr_fs
->info
.base
.input_interpolate_loc
[attrib
];
374 Value
*vi
= nullptr, *vj
= nullptr;
376 case TGSI_INTERPOLATE_LOC_CENTER
:
377 vi
= LOAD(pPS
, {0, SWR_PS_CONTEXT_vI
, PixelPositions_center
}, "i");
378 vj
= LOAD(pPS
, {0, SWR_PS_CONTEXT_vJ
, PixelPositions_center
}, "j");
380 case TGSI_INTERPOLATE_LOC_CENTROID
:
381 vi
= LOAD(pPS
, {0, SWR_PS_CONTEXT_vI
, PixelPositions_centroid
}, "i");
382 vj
= LOAD(pPS
, {0, SWR_PS_CONTEXT_vJ
, PixelPositions_centroid
}, "j");
384 case TGSI_INTERPOLATE_LOC_SAMPLE
:
385 vi
= LOAD(pPS
, {0, SWR_PS_CONTEXT_vI
, PixelPositions_sample
}, "i");
386 vj
= LOAD(pPS
, {0, SWR_PS_CONTEXT_vJ
, PixelPositions_sample
}, "j");
391 Value
*vw
= nullptr, *pAttribs
;
392 if (interpMode
== TGSI_INTERPOLATE_PERSPECTIVE
) {
393 pAttribs
= pPerspAttribs
;
395 case TGSI_INTERPOLATE_LOC_CENTER
:
396 vw
= VRCP(LOAD(pPS
, {0, SWR_PS_CONTEXT_vOneOverW
, PixelPositions_center
}));
398 case TGSI_INTERPOLATE_LOC_CENTROID
:
399 vw
= VRCP(LOAD(pPS
, {0, SWR_PS_CONTEXT_vOneOverW
, PixelPositions_centroid
}));
401 case TGSI_INTERPOLATE_LOC_SAMPLE
:
402 vw
= VRCP(LOAD(pPS
, {0, SWR_PS_CONTEXT_vOneOverW
, PixelPositions_sample
}));
406 pAttribs
= pRawAttribs
;
412 ubyte semantic_name
= swr_fs
->info
.base
.input_semantic_name
[attrib
];
413 ubyte semantic_idx
= swr_fs
->info
.base
.input_semantic_index
[attrib
];
415 if (semantic_name
== TGSI_SEMANTIC_FACE
) {
417 UI_TO_FP(LOAD(pPS
, {0, SWR_PS_CONTEXT_frontFace
}), mFP32Ty
);
418 ff
= FSUB(FMUL(ff
, C(2.0f
)), C(1.0f
));
419 ff
= VECTOR_SPLAT(JM()->mVWidth
, ff
, "vFrontFace");
421 inputs
[attrib
][0] = wrap(ff
);
422 inputs
[attrib
][1] = wrap(VIMMED1(0.0f
));
423 inputs
[attrib
][2] = wrap(VIMMED1(0.0f
));
424 inputs
[attrib
][3] = wrap(VIMMED1(1.0f
));
426 } else if (semantic_name
== TGSI_SEMANTIC_POSITION
) { // gl_FragCoord
427 inputs
[attrib
][0] = wrap(LOAD(pPS
, {0, SWR_PS_CONTEXT_vX
, PixelPositions_center
}, "vX"));
428 inputs
[attrib
][1] = wrap(LOAD(pPS
, {0, SWR_PS_CONTEXT_vY
, PixelPositions_center
}, "vY"));
429 inputs
[attrib
][2] = wrap(LOAD(pPS
, {0, SWR_PS_CONTEXT_vZ
}, "vZ"));
431 wrap(LOAD(pPS
, {0, SWR_PS_CONTEXT_vOneOverW
, PixelPositions_center
}, "vOneOverW"));
433 } else if (semantic_name
== TGSI_SEMANTIC_PRIMID
) {
434 Value
*primID
= LOAD(pPS
, {0, SWR_PS_CONTEXT_primID
}, "primID");
435 inputs
[attrib
][0] = wrap(VECTOR_SPLAT(JM()->mVWidth
, primID
));
436 inputs
[attrib
][1] = wrap(VIMMED1(0));
437 inputs
[attrib
][2] = wrap(VIMMED1(0));
438 inputs
[attrib
][3] = wrap(VIMMED1(0));
442 unsigned linkedAttrib
=
443 locate_linkage(semantic_name
, semantic_idx
, &ctx
->vs
->info
.base
);
444 if (linkedAttrib
== 0xFFFFFFFF) {
445 // not found - check for point sprite
446 if (ctx
->rasterizer
->sprite_coord_enable
) {
447 linkedAttrib
= ctx
->vs
->info
.base
.num_outputs
- 1;
448 swr_fs
->pointSpriteMask
|= (1 << linkedAttrib
);
452 tgsi_semantic_names
[semantic_name
],
454 assert(0 && "attribute linkage not found");
458 if (interpMode
== TGSI_INTERPOLATE_CONSTANT
) {
459 swr_fs
->constantMask
|= 1 << linkedAttrib
;
462 for (int channel
= 0; channel
< TGSI_NUM_CHANNELS
; channel
++) {
463 if (mask
& (1 << channel
)) {
464 Value
*indexA
= C(linkedAttrib
* 12 + channel
);
465 Value
*indexB
= C(linkedAttrib
* 12 + channel
+ 4);
466 Value
*indexC
= C(linkedAttrib
* 12 + channel
+ 8);
468 if ((semantic_name
== TGSI_SEMANTIC_COLOR
)
469 && ctx
->rasterizer
->light_twoside
) {
470 unsigned bcolorAttrib
= locate_linkage(
471 TGSI_SEMANTIC_BCOLOR
, semantic_idx
, &ctx
->vs
->info
.base
);
473 unsigned diff
= 12 * (bcolorAttrib
- linkedAttrib
);
476 XOR(C(1), LOAD(pPS
, {0, SWR_PS_CONTEXT_frontFace
}), "backFace");
478 Value
*offset
= MUL(back
, C(diff
));
479 offset
->setName("offset");
481 indexA
= ADD(indexA
, offset
);
482 indexB
= ADD(indexB
, offset
);
483 indexC
= ADD(indexC
, offset
);
485 if (interpMode
== TGSI_INTERPOLATE_CONSTANT
) {
486 swr_fs
->constantMask
|= 1 << bcolorAttrib
;
490 Value
*va
= VBROADCAST(LOAD(GEP(pAttribs
, indexA
)));
491 Value
*vb
= VBROADCAST(LOAD(GEP(pAttribs
, indexB
)));
492 Value
*vc
= VBROADCAST(LOAD(GEP(pAttribs
, indexC
)));
494 if (interpMode
== TGSI_INTERPOLATE_CONSTANT
) {
495 inputs
[attrib
][channel
] = wrap(va
);
496 } else if ((interpMode
== TGSI_INTERPOLATE_COLOR
) &&
497 (key
.flatshade
== true)) {
498 inputs
[attrib
][channel
] = wrap(vc
);
500 Value
*vk
= FSUB(FSUB(VIMMED1(1.0f
), vi
), vj
);
504 Value
*interp
= FMUL(va
, vi
);
505 Value
*interp1
= FMUL(vb
, vj
);
506 interp
= FADD(interp
, interp1
);
507 interp
= FADD(interp
, vc
);
508 if (interpMode
== TGSI_INTERPOLATE_PERSPECTIVE
)
509 interp
= FMUL(interp
, vw
);
510 inputs
[attrib
][channel
] = wrap(interp
);
516 sampler
= swr_sampler_soa_create(key
.sampler
, PIPE_SHADER_FRAGMENT
);
518 struct lp_bld_tgsi_system_values system_values
;
519 memset(&system_values
, 0, sizeof(system_values
));
521 struct lp_build_mask_context mask
;
523 if (swr_fs
->info
.base
.uses_kill
) {
524 Value
*mask_val
= LOAD(pPS
, {0, SWR_PS_CONTEXT_activeMask
}, "activeMask");
526 &mask
, gallivm
, lp_type_float_vec(32, 32 * 8), wrap(mask_val
));
529 lp_build_tgsi_soa(gallivm
,
531 lp_type_float_vec(32, 32 * 8),
532 swr_fs
->info
.base
.uses_kill
? &mask
: NULL
, // mask
534 wrap(const_sizes_ptr
),
542 NULL
); // geometry shader face
544 sampler
->destroy(sampler
);
546 IRB()->SetInsertPoint(unwrap(LLVMGetInsertBlock(gallivm
->builder
)));
548 for (uint32_t attrib
= 0; attrib
< swr_fs
->info
.base
.num_outputs
;
550 switch (swr_fs
->info
.base
.output_semantic_name
[attrib
]) {
551 case TGSI_SEMANTIC_POSITION
: {
554 LLVMBuildLoad(gallivm
->builder
, outputs
[attrib
][2], "");
555 STORE(unwrap(outZ
), pPS
, {0, SWR_PS_CONTEXT_vZ
});
558 case TGSI_SEMANTIC_COLOR
: {
559 for (uint32_t channel
= 0; channel
< TGSI_NUM_CHANNELS
; channel
++) {
560 if (!outputs
[attrib
][channel
])
564 LLVMBuildLoad(gallivm
->builder
, outputs
[attrib
][channel
], "");
565 if (swr_fs
->info
.base
.properties
[TGSI_PROPERTY_FS_COLOR0_WRITES_ALL_CBUFS
]) {
566 for (uint32_t rt
= 0; rt
< key
.nr_cbufs
; rt
++) {
569 {0, SWR_PS_CONTEXT_shaded
, rt
, channel
});
575 SWR_PS_CONTEXT_shaded
,
576 swr_fs
->info
.base
.output_semantic_index
[attrib
],
584 "unknown output from FS %s[%d]\n",
585 tgsi_semantic_names
[swr_fs
->info
.base
586 .output_semantic_name
[attrib
]],
587 swr_fs
->info
.base
.output_semantic_index
[attrib
]);
593 LLVMValueRef mask_result
= 0;
594 if (swr_fs
->info
.base
.uses_kill
) {
595 mask_result
= lp_build_mask_end(&mask
);
598 IRB()->SetInsertPoint(unwrap(LLVMGetInsertBlock(gallivm
->builder
)));
600 if (swr_fs
->info
.base
.uses_kill
) {
601 STORE(unwrap(mask_result
), pPS
, {0, SWR_PS_CONTEXT_activeMask
});
606 gallivm_verify_function(gallivm
, wrap(pFunction
));
608 gallivm_compile_module(gallivm
);
610 PFN_PIXEL_KERNEL kernel
=
611 (PFN_PIXEL_KERNEL
)gallivm_jit_function(gallivm
, wrap(pFunction
));
612 debug_printf("frag shader %p\n", kernel
);
613 assert(kernel
&& "Error: FragShader = NULL");
615 #if (LLVM_VERSION_MAJOR == 3) && (LLVM_VERSION_MINOR >= 5)
616 JM()->mIsModuleFinalized
= true;
623 swr_compile_fs(struct swr_context
*ctx
, swr_jit_fs_key
&key
)
626 reinterpret_cast<JitManager
*>(swr_screen(ctx
->pipe
.screen
)->hJitMgr
),
628 PFN_PIXEL_KERNEL func
= builder
.CompileFS(ctx
, key
);
630 ctx
->fs
->map
.insert(std::make_pair(key
, make_unique
<VariantFS
>(builder
.gallivm
, func
)));