WARSAW, July 20— Roman Polanski returned to Poland recently to direct and co-star in a production of Peter Shaffer's ''Amadeus.'' It seemed like a straightforward artistic proposition, but he found himself in the center of a controversy that shows that the political convulsions in Poland are affecting its cultural life.

Mr. Polanski, who began his acting career here at the age of 14, returned to the stage in the role of Mozart. The part of Antonio Salieri was played by one of Poland's leading actors and directors, Tadeusz Lomnicki, whose repertory company filled the other parts.

Mr. Lomnicki's theater, in the traditionally working-class district of Wola, was the former cultural center of the Kasprzak transistor factory, which used it as a movie house. Six years ago the district's officials offered the theater to Mr. Lomnicki, a member of the Central Committee. Now the Solidarity trade-union chapter of the Kasprzak factory has demanded that the building be returned to the workers. Negotiations had just begun when Mr. Polanski arrived to direct ''Amadeus.''

''Amadeus'' ran for 13 performances to standing-room-only crowds at the Na Woli Theater. Mr. Polanski, who has acted in movies as well as producing and directing them, was warmly received by Warsaw critics and audiences. His dressing room was filled with flowers and his curtain calls were warm. He blew kisses to the audience and fell on his knees to kiss the hand of Mr. Lomnicki, whose Salieri was critically acclaimed and compared favorably by foreign journalists and diplomats with Paul Scofield's performance in London. 'Animated by Desire'

Mr. Polanski struck up a friendly relationship with the cast. On opening night an actress stepped forward at the curtain call to read a poem of welcome on behalf of the entire cast, and on closing night the same actress read a poem of farewell. The audience gave him a 10-minute standing ovation and people climbed onto the stage to give him flowers.

Long lines formed outside the theater at every performance on the off-chance that some tickets would become available. Cast members were so captivated by Mr. Polanski that they agreed to several roundthe-clock rehearsals, stopping only for dinner and continuing until 6 o'clock in the morning.

''He is a man who is animated by desire, like a child'' Mr. Lomnicki said. ''Not for a moment does he forget what he wants. He has perfect pitch for what rings true. He liberates inner freedom in his actors, but at the same time he frames them. There is a simultaneous freedom and control. I've never experienced it before. He also concentrates on a problem until he solves it. It is strange because he is internally chaotic, but in this way he is totally disciplined, both as director and actor.'' He Bought Rights to Play

''Salieri says of Mozart that prodigies become stale with years,'' Mr. Lomnicki continued, ''but this is not true of Polanski. He is still fresh. It is hard to withstand all the ideas he is always bringing in. Sometimes he kept the audience waiting to enter the theater because he had a new idea.''

Mr. Polanski said he had been thinking of doing a play in Poland for a long time and that he had chosen ''Amadeus'' simply because he liked it so much. He bought the rights to the play himself. Paying hard currency for foreign rights has become a serious problem for Poles. Mr. Polanski himself was paid a standard salary in Polish zlotys.

About a year ago he approached Mr. Lomnicki with the proposition that he play Salieri. Mr. Lomnicki suggested that the director take the part of Mozart himself.

Mr. Polanski played the part with sympathy and depth. His Mozart was a child of genius, but a charming naughty child struggling against the constraints and hypocrisy of his surroundings. He downplayed the shrieks, giggles and salacious behavior called for in the script, emphasizing the rebellion and naivete. Salieri's intrigues against this helpless innocent become all the more tragic. 'A Great Shame'

After a short break the play is reopening with a young actor in the title role. But at the moment the fate of the production hangs very much on the decision of the workers in the Kasprzak factory.

''This is a complicated problem, but also a great shame,'' Mr. Polanski said. Mr. Lomnicki, he added, ''has built a great theater, and they want to turn it into a recreation hall. They hold it against him that he is a member of the Central Committee. He is, but he is still a great actor.''

Mr. Lomnicki, a Central Committee member for eight years and a member of the Communist Party for 30, had a ''dialectical'' explanation: ''The grievances are too profound. They feel it was taken away from them without really asking them - they were never offered a substitute. This is a question of principles. We are only a very small casualty of a mass movement - a kind of revolution. sometimes unfortunate positions are taken that appear wrong at the time but that may have within them the seeds of a new birth. the movement that is causing the takeover of the theater may also produce a new law to reduce censorship. That will mean that we will have better plays written in Poland and ultimately that will bring a stronger theater than we have now.'' Other Troupes' Conflicts

The conflict is not an isolated incident. In other theaters around Poland different disputes point to the same trend: the democratization and leveling of society being wrought from the bottom up by Poland's workers have cultural repercussions that are not always in the immediate interests of higher art.

In Cracow, the famous Stary Theater, one of the best in Poland, removed its theater manager, Jan Pawel Gawlik, when the company voted to replace him. In Warsaw, a well known director has threatened to resign if his repertory company goes through with plans to decide by vote on what the company's repertory should be and who plays what part.

A company member pointed out that in the early stages of the Russian Revolution theater companies also underwent upheavals. ''In this kind of cultural earthquake,'' Mr. Lomnicki added, ''often second-class artists, usually toward the bottom, are thrown to the top. But Solidarity or the party are not magic pills for talent. They don't automatically give success. authentic artistic values remain, and the public still demands them. Proof of this is the success of Polanski's 'Amadeus.' ''

''Maybe 'Amadeus' will be the golden nail in our coffin,'' Mr. Lomnicki continued, smiling wanly. He does not seem optimistic. He has already signed a contract, to begin in October, as an actor with another Warsaw theater.

Illustrations: Photo of Roman Polanski