summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Barbieri <luca@luca-barbieri.com>2010-08-26 18:27:38 +0200
committerLuca Barbieri <luca@luca-barbieri.com>2010-09-05 18:11:23 +0200
commitfed3486a7ca0683b403913604a26ee49a3ef48c7 (patch)
treec41cf5829925c88c1b28c135b25eca5d83a05eee
parentef0efe9f3d1d0f9b40ebab78940491d2154277a9 (diff)
draw_llvm: respect vertex color clamp
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c35
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h5
2 files changed, 35 insertions, 5 deletions
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index 8759c38cab..e86534c03d 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -323,7 +323,8 @@ generate_vs(struct draw_llvm *llvm,
LLVMValueRef (*outputs)[NUM_CHANNELS],
const LLVMValueRef (*inputs)[NUM_CHANNELS],
LLVMValueRef context_ptr,
- struct lp_build_sampler_soa *draw_sampler)
+ struct lp_build_sampler_soa *draw_sampler,
+ boolean clamp_vertex_color)
{
const struct tgsi_token *tokens = llvm->draw->vs.vertex_shader->state.tokens;
struct lp_type vs_type;
@@ -358,6 +359,30 @@ generate_vs(struct draw_llvm *llvm,
outputs,
sampler,
&llvm->draw->vs.vertex_shader->info);
+
+ if(clamp_vertex_color)
+ {
+ LLVMValueRef out;
+ unsigned chan, attrib;
+ struct lp_build_context bld;
+ struct tgsi_shader_info* info = &llvm->draw->vs.vertex_shader->info;
+ lp_build_context_init(&bld, builder, vs_type);
+
+ for (attrib = 0; attrib < info->num_outputs; ++attrib) {
+ for(chan = 0; chan < NUM_CHANNELS; ++chan) {
+ if(outputs[attrib][chan]) {
+ switch (info->output_semantic_name[attrib]) {
+ case TGSI_SEMANTIC_COLOR:
+ case TGSI_SEMANTIC_BCOLOR:
+ out = LLVMBuildLoad(builder, outputs[attrib][chan], "");
+ out = lp_build_clamp(&bld, out, bld.zero, bld.one);
+ LLVMBuildStore(builder, out, outputs[attrib][chan]);
+ break;
+ }
+ }
+ }
+ }
+ }
}
#if DEBUG_STORE
@@ -786,7 +811,8 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
outputs,
ptr_aos,
context_ptr,
- sampler);
+ sampler,
+ variant->key.clamp_vertex_color);
convert_to_aos(builder, io, outputs,
draw->vs.vertex_shader->info.num_outputs,
@@ -960,7 +986,8 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
outputs,
ptr_aos,
context_ptr,
- sampler);
+ sampler,
+ variant->key.clamp_vertex_color);
convert_to_aos(builder, io, outputs,
draw->vs.vertex_shader->info.num_outputs,
@@ -1015,6 +1042,8 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store)
key = (struct draw_llvm_variant_key *)store;
+ key->clamp_vertex_color = llvm->draw->rasterizer->clamp_vertex_color; /**/
+
/* Presumably all variants of the shader should have the same
* number of vertex elements - ie the number of shader inputs.
*/
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index 6196b2f983..a463f54c14 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -151,8 +151,9 @@ typedef void
struct draw_llvm_variant_key
{
- unsigned nr_vertex_elements:16;
- unsigned nr_samplers:16;
+ unsigned nr_vertex_elements:8;
+ unsigned nr_samplers:8;
+ unsigned clamp_vertex_color:8;
/* Variable number of vertex elements:
*/