st/nine: Fix volumetexture dtor on ctor failure
[mesa.git] / src / gallium / state_trackers / nine / pixelshader9.c
index 9e280321e457f009a6a93ead5315ffbc7cf9df66..5d79019a1bcd7a991ba62e9564849fdc85e29d2f 100644 (file)
@@ -37,6 +37,7 @@ NinePixelShader9_ctor( struct NinePixelShader9 *This,
 {
     struct NineDevice9 *device;
     struct nine_shader_info info;
+    struct pipe_context *pipe;
     HRESULT hr;
 
     DBG("This=%p pParams=%p pFunction=%p cso=%p\n", This, pParams, pFunction, cso);
@@ -61,7 +62,9 @@ NinePixelShader9_ctor( struct NinePixelShader9 *This,
     info.projected = 0;
     info.process_vertices = false;
 
-    hr = nine_translate_shader(device, &info);
+    pipe = nine_context_get_pipe_acquire(device);
+    hr = nine_translate_shader(device, &info, pipe);
+    nine_context_get_pipe_release(device);
     if (FAILED(hr))
         return hr;
     This->byte_code.version = info.version;
@@ -92,12 +95,12 @@ NinePixelShader9_dtor( struct NinePixelShader9 *This )
     DBG("This=%p\n", This);
 
     if (This->base.device) {
-        struct pipe_context *pipe = This->base.device->pipe;
+        struct pipe_context *pipe = nine_context_get_pipe_multithread(This->base.device);
         struct nine_shader_variant *var = &This->variant;
 
         do {
             if (var->cso) {
-                if (This->base.device->state.cso.ps == var->cso)
+                if (This->base.device->context.cso_shader.ps == var->cso)
                     pipe->bind_fs_state(pipe, NULL);
                 pipe->delete_fs_state(pipe, var->cso);
             }
@@ -105,7 +108,7 @@ NinePixelShader9_dtor( struct NinePixelShader9 *This )
         } while (var);
 
         if (This->ff_cso) {
-            if (This->ff_cso == This->base.device->state.cso.ps)
+            if (This->ff_cso == This->base.device->context.cso_shader.ps)
                 pipe->bind_fs_state(pipe, NULL);
             pipe->delete_fs_state(pipe, This->ff_cso);
         }
@@ -140,6 +143,9 @@ NinePixelShader9_GetFunction( struct NinePixelShader9 *This,
 void *
 NinePixelShader9_GetVariant( struct NinePixelShader9 *This )
 {
+    /* GetVariant is called from nine_context, thus we can
+     * get pipe directly */
+    struct pipe_context *pipe = This->base.device->context.pipe;
     void *cso;
     uint64_t key;
 
@@ -158,14 +164,14 @@ NinePixelShader9_GetVariant( struct NinePixelShader9 *This )
         info.const_b_base = NINE_CONST_B_BASE(device->max_ps_const_f) / 16;
         info.byte_code = This->byte_code.tokens;
         info.sampler_mask_shadow = key & 0xffff;
-        info.sampler_ps1xtypes = key;
-        info.fog_enable = device->state.rs[D3DRS_FOGENABLE];
-        info.fog_mode = device->state.rs[D3DRS_FOGTABLEMODE];
+        info.sampler_ps1xtypes = (key >> 16) & 0xffff;
+        info.fog_enable = device->context.rs[D3DRS_FOGENABLE];
+        info.fog_mode = device->context.rs[D3DRS_FOGTABLEMODE];
         info.force_color_in_centroid = key >> 34 & 1;
         info.projected = (key >> 48) & 0xffff;
         info.process_vertices = false;
 
-        hr = nine_translate_shader(This->base.device, &info);
+        hr = nine_translate_shader(This->base.device, &info, pipe);
         if (FAILED(hr))
             return NULL;
         nine_shader_variant_add(&This->variant, key, info.cso);
@@ -197,5 +203,9 @@ NinePixelShader9_new( struct NineDevice9 *pDevice,
                       struct NinePixelShader9 **ppOut,
                       const DWORD *pFunction, void *cso )
 {
-    NINE_DEVICE_CHILD_NEW(PixelShader9, ppOut, pDevice, pFunction, cso);
+    if (cso) { /* ff shader. Needs to start with bind count */
+        NINE_DEVICE_CHILD_BIND_NEW(PixelShader9, ppOut, pDevice, pFunction, cso);
+    } else {
+        NINE_DEVICE_CHILD_NEW(PixelShader9, ppOut, pDevice, pFunction, cso);
+    }
 }