Insanity is a defense in Texas to criminal conduct. If, at the time of the offense, the defendant did not know that his conduct was wrong then that is a legal defense that requires an acquittal. If someone is not competent to stand trial and they were not insane at the time of the offense, then they will be tried once they regain competency to stand trial and that is not a defense to the criminal conduct.
Competency to stand trial means that the defendant 1. has a rational and factual understanding of the nature of the proceedings against him and 2. is able to communicate with his lawyer and assist with his defense.
However, diminished capacity
is typically not a defense to criminal conduct in Texas. That means just because someone is not all there mentally or has some kind of tendency that makes them have the urge to commit a crime does not provide them with a legal defense except in very limited circumstances with respect to the intent element of the offense. In the DWI or intoxication manslaughter
context, that exception probably would not apply.
Texas does not recognize diminished capacity as an affirmative defense or any lesser form of the insanity affirmative defense according to the Jackson v. State court in 2005. In some situations, however, evidence of a mental disease or defect might be relevant to intent. In Mays v. State, the court held that the defendant may present evidence of mental impairment at guilt/innocence to show he did not have the requisite mens rea.