Re: [Mesa-dev] [PATCH 1/2] radeonsi/ac: move vertex export remove to common code.
On Thu, 2017-04-27 at 20:42 +1000, Dave Airlie wrote: > On 27 April 2017 at 20:17, Marek Olšák wrote: > > > > > > On Apr 27, 2017 10:50 AM, "Juan A. Suarez Romero" > > wrote: > > > > On Wed, 2017-04-26 at 09:12 +1000, Dave Airlie wrote: > > > From: Dave Airlie > > > > > > This code can be shared by radv, we bump the max to > > > VARYING_SLOT_MAX here, but that shouldn't have too > > > much fallout. > > > > > > Signed-off-by: Dave Airlie > > > --- > > > src/amd/common/ac_exp_param.h | 40 ++ > > > src/amd/common/ac_llvm_build.c | 156 > > > +++- > > > src/amd/common/ac_llvm_build.h | 6 + > > > src/amd/common/ac_llvm_helper.cpp | 20 +++ > > > src/amd/common/ac_llvm_util.h | 2 + > > > src/gallium/drivers/radeonsi/si_shader.c| 152 > > > ++- > > > src/gallium/drivers/radeonsi/si_shader.h| 12 -- > > > src/gallium/drivers/radeonsi/si_state_shaders.c | 13 +- > > > 8 files changed, 237 insertions(+), 164 deletions(-) > > > create mode 100644 src/amd/common/ac_exp_param.h > > > > > > diff --git a/src/amd/common/ac_exp_param.h b/src/amd/common/ac_exp_param.h > > > new file mode 100644 > > > index 000..b97ce81 > > > --- /dev/null > > > +++ b/src/amd/common/ac_exp_param.h > > > @@ -0,0 +1,40 @@ > > > +/* > > > + * Copyright 2014 Advanced Micro Devices, Inc. > > > + * > > > + * Permission is hereby granted, free of charge, to any person obtaining > > > a > > > + * copy of this software and associated documentation files (the > > > + * "Software"), to deal in the Software without restriction, including > > > + * without limitation the rights to use, copy, modify, merge, publish, > > > + * distribute, sub license, and/or sell copies of the Software, and to > > > + * permit persons to whom the Software is furnished to do so, subject to > > > + * the following conditions: > > > + * > > > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > > > EXPRESS OR > > > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > > > MERCHANTABILITY, > > > + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT > > > SHALL > > > + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY > > > CLAIM, > > > + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR > > > + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR > > > THE > > > + * USE OR OTHER DEALINGS IN THE SOFTWARE. > > > + * > > > + * The above copyright notice and this permission notice (including the > > > + * next paragraph) shall be included in all copies or substantial > > > portions > > > + * of the Software. > > > + * > > > + */ > > > +#ifndef AC_EXP_PARAM_H > > > +#define AC_EXP_PARAM_H > > > + > > > +enum { > > > + /* SPI_PS_INPUT_CNTL_i.OFFSET[0:4] */ > > > + AC_EXP_PARAM_OFFSET_0 = 0, > > > + AC_EXP_PARAM_OFFSET_31 = 31, > > > + /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL[0:1] */ > > > + AC_EXP_PARAM_DEFAULT_VAL_ = 64, > > > + AC_EXP_PARAM_DEFAULT_VAL_0001, > > > + AC_EXP_PARAM_DEFAULT_VAL_1110, > > > + AC_EXP_PARAM_DEFAULT_VAL_, > > > + AC_EXP_PARAM_UNDEFINED = 255, > > > +}; > > > + > > > +#endif > > > diff --git a/src/amd/common/ac_llvm_build.c > > > b/src/amd/common/ac_llvm_build.c > > > index d45094c..f452f3e 100644 > > > --- a/src/amd/common/ac_llvm_build.c > > > +++ b/src/amd/common/ac_llvm_build.c > > > @@ -33,11 +33,13 @@ > > > #include > > > > > > #include "ac_llvm_util.h" > > > - > > > +#include "ac_exp_param.h" > > > #include "util/bitscan.h" > > > #include "util/macros.h" > > > #include "sid.h" > > > > > > +#include "shader_enums.h" > > > + > > > /* Initialize module-independent parts of the context. > > > * > > > * The caller is responsible for initializing ctx::module and > > > ctx::builder. > > > @@ -1244,3 +1246,155 @@ void ac_get_image_intr_name(const char *base_name, > > > data_type_name, coords_type_name, > > > rsrc_type_name); > > > } > > > } > > > + > > > +#define AC_EXP_TARGET (HAVE_LLVM >= 0x0500 ? 0 : 3) > > > +#define AC_EXP_OUT0 (HAVE_LLVM >= 0x0500 ? 2 : 5) > > > + > > > +/* Return true if the PARAM export has been eliminated. */ > > > +static bool ac_eliminate_const_output(uint8_t *vs_output_param_offset, > > > + uint32_t num_outputs, > > > + LLVMValueRef inst, unsigned offset) > > > +{ > > > + unsigned i, default_val; /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL */ > > > + bool is_zero[4] = {}, is_one[4] = {}; > > > + > > > + for (i = 0; i < 4; i++) { > > > + LLVMBool loses_info; > > > + LLVMValueRef p = LLVMGetOperand(inst, AC_EXP_OUT0 + i); > > > + > > > + /* It's a constant expression. Undef outputs are eliminated > > > too. */ > > > + if (LLVMIsUndef(p)) { > > > +
Re: [Mesa-dev] [PATCH 1/2] radeonsi/ac: move vertex export remove to common code.
On 27 April 2017 at 20:17, Marek Olšák wrote: > > > On Apr 27, 2017 10:50 AM, "Juan A. Suarez Romero" > wrote: > > On Wed, 2017-04-26 at 09:12 +1000, Dave Airlie wrote: >> From: Dave Airlie >> >> This code can be shared by radv, we bump the max to >> VARYING_SLOT_MAX here, but that shouldn't have too >> much fallout. >> >> Signed-off-by: Dave Airlie >> --- >> src/amd/common/ac_exp_param.h | 40 ++ >> src/amd/common/ac_llvm_build.c | 156 >> +++- >> src/amd/common/ac_llvm_build.h | 6 + >> src/amd/common/ac_llvm_helper.cpp | 20 +++ >> src/amd/common/ac_llvm_util.h | 2 + >> src/gallium/drivers/radeonsi/si_shader.c| 152 >> ++- >> src/gallium/drivers/radeonsi/si_shader.h| 12 -- >> src/gallium/drivers/radeonsi/si_state_shaders.c | 13 +- >> 8 files changed, 237 insertions(+), 164 deletions(-) >> create mode 100644 src/amd/common/ac_exp_param.h >> >> diff --git a/src/amd/common/ac_exp_param.h b/src/amd/common/ac_exp_param.h >> new file mode 100644 >> index 000..b97ce81 >> --- /dev/null >> +++ b/src/amd/common/ac_exp_param.h >> @@ -0,0 +1,40 @@ >> +/* >> + * Copyright 2014 Advanced Micro Devices, Inc. >> + * >> + * Permission is hereby granted, free of charge, to any person obtaining >> a >> + * copy of this software and associated documentation files (the >> + * "Software"), to deal in the Software without restriction, including >> + * without limitation the rights to use, copy, modify, merge, publish, >> + * distribute, sub license, and/or sell copies of the Software, and to >> + * permit persons to whom the Software is furnished to do so, subject to >> + * the following conditions: >> + * >> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, >> EXPRESS OR >> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF >> MERCHANTABILITY, >> + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT >> SHALL >> + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY >> CLAIM, >> + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR >> + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR >> THE >> + * USE OR OTHER DEALINGS IN THE SOFTWARE. >> + * >> + * The above copyright notice and this permission notice (including the >> + * next paragraph) shall be included in all copies or substantial >> portions >> + * of the Software. >> + * >> + */ >> +#ifndef AC_EXP_PARAM_H >> +#define AC_EXP_PARAM_H >> + >> +enum { >> + /* SPI_PS_INPUT_CNTL_i.OFFSET[0:4] */ >> + AC_EXP_PARAM_OFFSET_0 = 0, >> + AC_EXP_PARAM_OFFSET_31 = 31, >> + /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL[0:1] */ >> + AC_EXP_PARAM_DEFAULT_VAL_ = 64, >> + AC_EXP_PARAM_DEFAULT_VAL_0001, >> + AC_EXP_PARAM_DEFAULT_VAL_1110, >> + AC_EXP_PARAM_DEFAULT_VAL_, >> + AC_EXP_PARAM_UNDEFINED = 255, >> +}; >> + >> +#endif >> diff --git a/src/amd/common/ac_llvm_build.c >> b/src/amd/common/ac_llvm_build.c >> index d45094c..f452f3e 100644 >> --- a/src/amd/common/ac_llvm_build.c >> +++ b/src/amd/common/ac_llvm_build.c >> @@ -33,11 +33,13 @@ >> #include >> >> #include "ac_llvm_util.h" >> - >> +#include "ac_exp_param.h" >> #include "util/bitscan.h" >> #include "util/macros.h" >> #include "sid.h" >> >> +#include "shader_enums.h" >> + >> /* Initialize module-independent parts of the context. >> * >> * The caller is responsible for initializing ctx::module and >> ctx::builder. >> @@ -1244,3 +1246,155 @@ void ac_get_image_intr_name(const char *base_name, >> data_type_name, coords_type_name, >> rsrc_type_name); >> } >> } >> + >> +#define AC_EXP_TARGET (HAVE_LLVM >= 0x0500 ? 0 : 3) >> +#define AC_EXP_OUT0 (HAVE_LLVM >= 0x0500 ? 2 : 5) >> + >> +/* Return true if the PARAM export has been eliminated. */ >> +static bool ac_eliminate_const_output(uint8_t *vs_output_param_offset, >> + uint32_t num_outputs, >> + LLVMValueRef inst, unsigned offset) >> +{ >> + unsigned i, default_val; /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL */ >> + bool is_zero[4] = {}, is_one[4] = {}; >> + >> + for (i = 0; i < 4; i++) { >> + LLVMBool loses_info; >> + LLVMValueRef p = LLVMGetOperand(inst, AC_EXP_OUT0 + i); >> + >> + /* It's a constant expression. Undef outputs are eliminated >> too. */ >> + if (LLVMIsUndef(p)) { >> + is_zero[i] = true; >> + is_one[i] = true; >> + } else if (LLVMIsAConstantFP(p)) { >> + double a = LLVMConstRealGetDouble(p, &loses_info); >> + >> + if (a == 0) >> + is_zero[i] = true; >> + else if (a == 1) >> + is_one[i] = true; >> + else >> +
Re: [Mesa-dev] [PATCH 1/2] radeonsi/ac: move vertex export remove to common code.
On Apr 27, 2017 10:50 AM, "Juan A. Suarez Romero" wrote: On Wed, 2017-04-26 at 09:12 +1000, Dave Airlie wrote: > From: Dave Airlie > > This code can be shared by radv, we bump the max to > VARYING_SLOT_MAX here, but that shouldn't have too > much fallout. > > Signed-off-by: Dave Airlie > --- > src/amd/common/ac_exp_param.h | 40 ++ > src/amd/common/ac_llvm_build.c | 156 +++- > src/amd/common/ac_llvm_build.h | 6 + > src/amd/common/ac_llvm_helper.cpp | 20 +++ > src/amd/common/ac_llvm_util.h | 2 + > src/gallium/drivers/radeonsi/si_shader.c| 152 ++- > src/gallium/drivers/radeonsi/si_shader.h| 12 -- > src/gallium/drivers/radeonsi/si_state_shaders.c | 13 +- > 8 files changed, 237 insertions(+), 164 deletions(-) > create mode 100644 src/amd/common/ac_exp_param.h > > diff --git a/src/amd/common/ac_exp_param.h b/src/amd/common/ac_exp_param.h > new file mode 100644 > index 000..b97ce81 > --- /dev/null > +++ b/src/amd/common/ac_exp_param.h > @@ -0,0 +1,40 @@ > +/* > + * Copyright 2014 Advanced Micro Devices, Inc. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > + * copy of this software and associated documentation files (the > + * "Software"), to deal in the Software without restriction, including > + * without limitation the rights to use, copy, modify, merge, publish, > + * distribute, sub license, and/or sell copies of the Software, and to > + * permit persons to whom the Software is furnished to do so, subject to > + * the following conditions: > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL > + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, > + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR > + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE > + * USE OR OTHER DEALINGS IN THE SOFTWARE. > + * > + * The above copyright notice and this permission notice (including the > + * next paragraph) shall be included in all copies or substantial portions > + * of the Software. > + * > + */ > +#ifndef AC_EXP_PARAM_H > +#define AC_EXP_PARAM_H > + > +enum { > + /* SPI_PS_INPUT_CNTL_i.OFFSET[0:4] */ > + AC_EXP_PARAM_OFFSET_0 = 0, > + AC_EXP_PARAM_OFFSET_31 = 31, > + /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL[0:1] */ > + AC_EXP_PARAM_DEFAULT_VAL_ = 64, > + AC_EXP_PARAM_DEFAULT_VAL_0001, > + AC_EXP_PARAM_DEFAULT_VAL_1110, > + AC_EXP_PARAM_DEFAULT_VAL_, > + AC_EXP_PARAM_UNDEFINED = 255, > +}; > + > +#endif > diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_ build.c > index d45094c..f452f3e 100644 > --- a/src/amd/common/ac_llvm_build.c > +++ b/src/amd/common/ac_llvm_build.c > @@ -33,11 +33,13 @@ > #include > > #include "ac_llvm_util.h" > - > +#include "ac_exp_param.h" > #include "util/bitscan.h" > #include "util/macros.h" > #include "sid.h" > > +#include "shader_enums.h" > + > /* Initialize module-independent parts of the context. > * > * The caller is responsible for initializing ctx::module and ctx::builder. > @@ -1244,3 +1246,155 @@ void ac_get_image_intr_name(const char *base_name, > data_type_name, coords_type_name, rsrc_type_name); > } > } > + > +#define AC_EXP_TARGET (HAVE_LLVM >= 0x0500 ? 0 : 3) > +#define AC_EXP_OUT0 (HAVE_LLVM >= 0x0500 ? 2 : 5) > + > +/* Return true if the PARAM export has been eliminated. */ > +static bool ac_eliminate_const_output(uint8_t *vs_output_param_offset, > + uint32_t num_outputs, > + LLVMValueRef inst, unsigned offset) > +{ > + unsigned i, default_val; /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL */ > + bool is_zero[4] = {}, is_one[4] = {}; > + > + for (i = 0; i < 4; i++) { > + LLVMBool loses_info; > + LLVMValueRef p = LLVMGetOperand(inst, AC_EXP_OUT0 + i); > + > + /* It's a constant expression. Undef outputs are eliminated too. */ > + if (LLVMIsUndef(p)) { > + is_zero[i] = true; > + is_one[i] = true; > + } else if (LLVMIsAConstantFP(p)) { > + double a = LLVMConstRealGetDouble(p, &loses_info); > + > + if (a == 0) > + is_zero[i] = true; > + else if (a == 1) > + is_one[i] = true; > + else > + return false; /* other constant */ > + } else > + return false; > + } > + > + /* Only certain combinations of 0 and 1 can be eliminated. */ > + if (is_zero
Re: [Mesa-dev] [PATCH 1/2] radeonsi/ac: move vertex export remove to common code.
On Wed, 2017-04-26 at 09:12 +1000, Dave Airlie wrote: > From: Dave Airlie > > This code can be shared by radv, we bump the max to > VARYING_SLOT_MAX here, but that shouldn't have too > much fallout. > > Signed-off-by: Dave Airlie > --- > src/amd/common/ac_exp_param.h | 40 ++ > src/amd/common/ac_llvm_build.c | 156 > +++- > src/amd/common/ac_llvm_build.h | 6 + > src/amd/common/ac_llvm_helper.cpp | 20 +++ > src/amd/common/ac_llvm_util.h | 2 + > src/gallium/drivers/radeonsi/si_shader.c| 152 ++- > src/gallium/drivers/radeonsi/si_shader.h| 12 -- > src/gallium/drivers/radeonsi/si_state_shaders.c | 13 +- > 8 files changed, 237 insertions(+), 164 deletions(-) > create mode 100644 src/amd/common/ac_exp_param.h > > diff --git a/src/amd/common/ac_exp_param.h b/src/amd/common/ac_exp_param.h > new file mode 100644 > index 000..b97ce81 > --- /dev/null > +++ b/src/amd/common/ac_exp_param.h > @@ -0,0 +1,40 @@ > +/* > + * Copyright 2014 Advanced Micro Devices, Inc. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > + * copy of this software and associated documentation files (the > + * "Software"), to deal in the Software without restriction, including > + * without limitation the rights to use, copy, modify, merge, publish, > + * distribute, sub license, and/or sell copies of the Software, and to > + * permit persons to whom the Software is furnished to do so, subject to > + * the following conditions: > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL > + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY > CLAIM, > + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR > + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE > + * USE OR OTHER DEALINGS IN THE SOFTWARE. > + * > + * The above copyright notice and this permission notice (including the > + * next paragraph) shall be included in all copies or substantial portions > + * of the Software. > + * > + */ > +#ifndef AC_EXP_PARAM_H > +#define AC_EXP_PARAM_H > + > +enum { > + /* SPI_PS_INPUT_CNTL_i.OFFSET[0:4] */ > + AC_EXP_PARAM_OFFSET_0 = 0, > + AC_EXP_PARAM_OFFSET_31 = 31, > + /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL[0:1] */ > + AC_EXP_PARAM_DEFAULT_VAL_ = 64, > + AC_EXP_PARAM_DEFAULT_VAL_0001, > + AC_EXP_PARAM_DEFAULT_VAL_1110, > + AC_EXP_PARAM_DEFAULT_VAL_, > + AC_EXP_PARAM_UNDEFINED = 255, > +}; > + > +#endif > diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c > index d45094c..f452f3e 100644 > --- a/src/amd/common/ac_llvm_build.c > +++ b/src/amd/common/ac_llvm_build.c > @@ -33,11 +33,13 @@ > #include > > #include "ac_llvm_util.h" > - > +#include "ac_exp_param.h" > #include "util/bitscan.h" > #include "util/macros.h" > #include "sid.h" > > +#include "shader_enums.h" > + > /* Initialize module-independent parts of the context. > * > * The caller is responsible for initializing ctx::module and ctx::builder. > @@ -1244,3 +1246,155 @@ void ac_get_image_intr_name(const char *base_name, > data_type_name, coords_type_name, rsrc_type_name); > } > } > + > +#define AC_EXP_TARGET (HAVE_LLVM >= 0x0500 ? 0 : 3) > +#define AC_EXP_OUT0 (HAVE_LLVM >= 0x0500 ? 2 : 5) > + > +/* Return true if the PARAM export has been eliminated. */ > +static bool ac_eliminate_const_output(uint8_t *vs_output_param_offset, > + uint32_t num_outputs, > + LLVMValueRef inst, unsigned offset) > +{ > + unsigned i, default_val; /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL */ > + bool is_zero[4] = {}, is_one[4] = {}; > + > + for (i = 0; i < 4; i++) { > + LLVMBool loses_info; > + LLVMValueRef p = LLVMGetOperand(inst, AC_EXP_OUT0 + i); > + > + /* It's a constant expression. Undef outputs are eliminated > too. */ > + if (LLVMIsUndef(p)) { > + is_zero[i] = true; > + is_one[i] = true; > + } else if (LLVMIsAConstantFP(p)) { > + double a = LLVMConstRealGetDouble(p, &loses_info); > + > + if (a == 0) > + is_zero[i] = true; > + else if (a == 1) > + is_one[i] = true; > + else > + return false; /* other constant */ > + } else > + return false; > + } > + > + /* Only certain combinations of 0 and 1 can be eliminated. */ > + if (is_zero[0] && is_zero[1] && is_zero[2]) > +
Re: [Mesa-dev] [PATCH 1/2] radeonsi/ac: move vertex export remove to common code.
On Wed, Apr 26, 2017 at 1:12 AM, Dave Airlie wrote: > From: Dave Airlie > > This code can be shared by radv, we bump the max to > VARYING_SLOT_MAX here, but that shouldn't have too > much fallout. > > Signed-off-by: Dave Airlie > --- > src/amd/common/ac_exp_param.h | 40 ++ > src/amd/common/ac_llvm_build.c | 156 > +++- > src/amd/common/ac_llvm_build.h | 6 + > src/amd/common/ac_llvm_helper.cpp | 20 +++ > src/amd/common/ac_llvm_util.h | 2 + > src/gallium/drivers/radeonsi/si_shader.c| 152 ++- > src/gallium/drivers/radeonsi/si_shader.h| 12 -- > src/gallium/drivers/radeonsi/si_state_shaders.c | 13 +- > 8 files changed, 237 insertions(+), 164 deletions(-) > create mode 100644 src/amd/common/ac_exp_param.h > > diff --git a/src/amd/common/ac_exp_param.h b/src/amd/common/ac_exp_param.h > new file mode 100644 > index 000..b97ce81 > --- /dev/null > +++ b/src/amd/common/ac_exp_param.h > @@ -0,0 +1,40 @@ > +/* > + * Copyright 2014 Advanced Micro Devices, Inc. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > + * copy of this software and associated documentation files (the > + * "Software"), to deal in the Software without restriction, including > + * without limitation the rights to use, copy, modify, merge, publish, > + * distribute, sub license, and/or sell copies of the Software, and to > + * permit persons to whom the Software is furnished to do so, subject to > + * the following conditions: > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL > + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY > CLAIM, > + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR > + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE > + * USE OR OTHER DEALINGS IN THE SOFTWARE. > + * > + * The above copyright notice and this permission notice (including the > + * next paragraph) shall be included in all copies or substantial portions > + * of the Software. > + * > + */ > +#ifndef AC_EXP_PARAM_H > +#define AC_EXP_PARAM_H > + > +enum { > + /* SPI_PS_INPUT_CNTL_i.OFFSET[0:4] */ > + AC_EXP_PARAM_OFFSET_0 = 0, > + AC_EXP_PARAM_OFFSET_31 = 31, > + /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL[0:1] */ > + AC_EXP_PARAM_DEFAULT_VAL_ = 64, > + AC_EXP_PARAM_DEFAULT_VAL_0001, > + AC_EXP_PARAM_DEFAULT_VAL_1110, > + AC_EXP_PARAM_DEFAULT_VAL_, > + AC_EXP_PARAM_UNDEFINED = 255, > +}; > + > +#endif > diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c > index d45094c..f452f3e 100644 > --- a/src/amd/common/ac_llvm_build.c > +++ b/src/amd/common/ac_llvm_build.c > @@ -33,11 +33,13 @@ > #include > > #include "ac_llvm_util.h" > - > +#include "ac_exp_param.h" > #include "util/bitscan.h" > #include "util/macros.h" > #include "sid.h" > > +#include "shader_enums.h" > + > /* Initialize module-independent parts of the context. > * > * The caller is responsible for initializing ctx::module and ctx::builder. > @@ -1244,3 +1246,155 @@ void ac_get_image_intr_name(const char *base_name, > data_type_name, coords_type_name, rsrc_type_name); > } > } > + > +#define AC_EXP_TARGET (HAVE_LLVM >= 0x0500 ? 0 : 3) > +#define AC_EXP_OUT0 (HAVE_LLVM >= 0x0500 ? 2 : 5) > + > +/* Return true if the PARAM export has been eliminated. */ > +static bool ac_eliminate_const_output(uint8_t *vs_output_param_offset, > + uint32_t num_outputs, > + LLVMValueRef inst, unsigned offset) > +{ > + unsigned i, default_val; /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL */ > + bool is_zero[4] = {}, is_one[4] = {}; > + > + for (i = 0; i < 4; i++) { > + LLVMBool loses_info; > + LLVMValueRef p = LLVMGetOperand(inst, AC_EXP_OUT0 + i); > + > + /* It's a constant expression. Undef outputs are eliminated > too. */ > + if (LLVMIsUndef(p)) { > + is_zero[i] = true; > + is_one[i] = true; > + } else if (LLVMIsAConstantFP(p)) { > + double a = LLVMConstRealGetDouble(p, &loses_info); > + > + if (a == 0) > + is_zero[i] = true; > + else if (a == 1) > + is_one[i] = true; > + else > + return false; /* other constant */ > + } else > + return false; > + } > + > + /* Only certain combinations of 0 and 1 can be eliminated. */ > +
Re: [Mesa-dev] [PATCH 1/2] radeonsi/ac: move vertex export remove to common code.
On 26.04.2017 01:12, Dave Airlie wrote: From: Dave Airlie This code can be shared by radv, we bump the max to VARYING_SLOT_MAX here, but that shouldn't have too much fallout. Signed-off-by: Dave Airlie Reviewed-by: Nicolai Hähnle --- src/amd/common/ac_exp_param.h | 40 ++ src/amd/common/ac_llvm_build.c | 156 +++- src/amd/common/ac_llvm_build.h | 6 + src/amd/common/ac_llvm_helper.cpp | 20 +++ src/amd/common/ac_llvm_util.h | 2 + src/gallium/drivers/radeonsi/si_shader.c| 152 ++- src/gallium/drivers/radeonsi/si_shader.h| 12 -- src/gallium/drivers/radeonsi/si_state_shaders.c | 13 +- 8 files changed, 237 insertions(+), 164 deletions(-) create mode 100644 src/amd/common/ac_exp_param.h diff --git a/src/amd/common/ac_exp_param.h b/src/amd/common/ac_exp_param.h new file mode 100644 index 000..b97ce81 --- /dev/null +++ b/src/amd/common/ac_exp_param.h @@ -0,0 +1,40 @@ +/* + * Copyright 2014 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + */ +#ifndef AC_EXP_PARAM_H +#define AC_EXP_PARAM_H + +enum { + /* SPI_PS_INPUT_CNTL_i.OFFSET[0:4] */ + AC_EXP_PARAM_OFFSET_0 = 0, + AC_EXP_PARAM_OFFSET_31 = 31, + /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL[0:1] */ + AC_EXP_PARAM_DEFAULT_VAL_ = 64, + AC_EXP_PARAM_DEFAULT_VAL_0001, + AC_EXP_PARAM_DEFAULT_VAL_1110, + AC_EXP_PARAM_DEFAULT_VAL_, + AC_EXP_PARAM_UNDEFINED = 255, +}; + +#endif diff --git a/src/amd/common/ac_llvm_build.c b/src/amd/common/ac_llvm_build.c index d45094c..f452f3e 100644 --- a/src/amd/common/ac_llvm_build.c +++ b/src/amd/common/ac_llvm_build.c @@ -33,11 +33,13 @@ #include #include "ac_llvm_util.h" - +#include "ac_exp_param.h" #include "util/bitscan.h" #include "util/macros.h" #include "sid.h" +#include "shader_enums.h" + /* Initialize module-independent parts of the context. * * The caller is responsible for initializing ctx::module and ctx::builder. @@ -1244,3 +1246,155 @@ void ac_get_image_intr_name(const char *base_name, data_type_name, coords_type_name, rsrc_type_name); } } + +#define AC_EXP_TARGET (HAVE_LLVM >= 0x0500 ? 0 : 3) +#define AC_EXP_OUT0 (HAVE_LLVM >= 0x0500 ? 2 : 5) + +/* Return true if the PARAM export has been eliminated. */ +static bool ac_eliminate_const_output(uint8_t *vs_output_param_offset, + uint32_t num_outputs, + LLVMValueRef inst, unsigned offset) +{ + unsigned i, default_val; /* SPI_PS_INPUT_CNTL_i.DEFAULT_VAL */ + bool is_zero[4] = {}, is_one[4] = {}; + + for (i = 0; i < 4; i++) { + LLVMBool loses_info; + LLVMValueRef p = LLVMGetOperand(inst, AC_EXP_OUT0 + i); + + /* It's a constant expression. Undef outputs are eliminated too. */ + if (LLVMIsUndef(p)) { + is_zero[i] = true; + is_one[i] = true; + } else if (LLVMIsAConstantFP(p)) { + double a = LLVMConstRealGetDouble(p, &loses_info); + + if (a == 0) + is_zero[i] = true; + else if (a == 1) + is_one[i] = true; + else + return false; /* other constant */ + } else + return false; + } + + /* Only certain combinations of 0 and 1 can be eliminated. */ + if (is_zero[0] && is_zero[1] && is_zero[2]) + default_val = is_zero[3] ? 0 : 1; + else if (is_one[0] && is_one[1] && is_one[2]) + default_val = is_zero[3] ? 2 : 3; + else +