You should look up the specifics on what that state requires for gender marker changes.
For name changes, you need to go to court and attend a hearing. You may or may not be able to do that as a foreigner on a visa, depending on how long you've been living in that state and county, because you might not meet the residency requirements. But then also, if you're planning on going back to your home country, you'd need to see if that would even transfer over there.
A better idea would be to contact your local consulate and see what they'd advise, or an LGBT advocacy group who may be experienced with name/gender changes in that state.