Then during the Permian, beginning about 300 million years ago, the North American continent collided with Gondwana Land (a supercontinent that later split apart into South America and Africa). This violent compression created two deep sub-basins, the Delaware and the Midland Basins. These filled with clastics (sediments like sands and gravels), and were surrounded by shallow shelves that precipitated carbonate rocks from reefs and shelled organisms of the shallow sea.
After that, the basins became slowly shut off from the ocean, intermittently flooding and evaporating for millions of years, precipitating thousands of feet of salt, some very pure and tight. The effect was a deep basin filled with marine sediments, capped by tight formations, in which the dead marine organisms were eventually pressed and cooked into oil and gas.